Ship MicroPython stubs from repo lib/ and seed workspace lib on startup

Move machine.py and neopixel.py into a tracked /lib/ at the repo root and
auto-copy them into WORKSPACE_ROOT/lib whenever files are missing, so empty
volumes and fresh per-user workspaces always have the read-only stubs
available to Jedi and Pyodide. Allow all users to browse lib/ in the UI
(writes still gated by the API), and add tests covering initial seeding
and re-population after the dir is wiped.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-05-10 02:59:34 +12:00
parent f7892dd31b
commit a2318f2244
14 changed files with 146 additions and 181 deletions

View File

@@ -293,9 +293,6 @@ class TextEditor {
return;
}
for (const path of session.openTabPaths) {
if (!this.isSuperuser && typeof path === 'string' && path.startsWith('lib/')) {
continue;
}
await this.openFile(path);
}
if (session.activeTabPath && this.findTab(session.activeTabPath)) {
@@ -338,7 +335,8 @@ class TextEditor {
}
getVisibleTopLevelNames() {
return this.isSuperuser ? new Set(['code', 'lib']) : new Set(['code']);
/* lib is shared read-only for everyone; browsing is allowed, saves are blocked in API/UI. */
return new Set(['code', 'lib']);
}
getDefaultEditableRoot() {
@@ -352,10 +350,7 @@ class TextEditor {
this.selectedIsDirectory = true;
this.expandedDirs.add('code');
await this.loadDirectory('code', { suppressError: true });
if (this.isSuperuser) {
await this.ensureFolderExists('lib');
await this.loadDirectory('lib', { suppressError: true });
}
await this.loadDirectory('lib', { suppressError: true });
this.renderFileTree();
}