@innovatorved/code-lab 0.3.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/ARCHITECTURE.md +5 -3
  2. package/CHANGELOG.md +20 -0
  3. package/README.md +70 -168
  4. package/dist/apps/web/src/index.d.ts +34 -0
  5. package/dist/code-lab-sql.css +482 -0
  6. package/dist/code-lab-sql.d.ts +179 -0
  7. package/dist/code-lab-sql.esm.js +542 -0
  8. package/dist/code-lab-sql.umd.js +531 -0
  9. package/dist/code-lab.css +246 -0
  10. package/dist/code-lab.d.ts +110 -15
  11. package/dist/code-lab.esm.js +34265 -18104
  12. package/dist/code-lab.js +33186 -17053
  13. package/dist/code-lab.umd.js +65502 -0
  14. package/dist/extensions/cpp.esm.js +19478 -3760
  15. package/dist/extensions/cpp.js +19475 -3757
  16. package/dist/extensions/guided-lab.esm.js +19401 -3725
  17. package/dist/extensions/guided-lab.js +19400 -3724
  18. package/dist/extensions/python.d.ts +1 -0
  19. package/dist/extensions/python.esm.js +19576 -3766
  20. package/dist/extensions/python.js +19576 -3766
  21. package/dist/extensions/umbrella.d.ts +5 -0
  22. package/dist/index.d.ts +1 -1
  23. package/dist/modular-kernel.d.ts +11 -0
  24. package/dist/packages/commands/src/index.d.ts +96 -0
  25. package/dist/packages/core/src/di.d.ts +36 -0
  26. package/dist/packages/core/src/disposable.d.ts +27 -0
  27. package/dist/packages/core/src/errors.d.ts +69 -0
  28. package/dist/packages/core/src/events.d.ts +38 -0
  29. package/dist/packages/core/src/index.d.ts +6 -0
  30. package/dist/packages/core/src/path.d.ts +14 -0
  31. package/dist/packages/core/src/registry.d.ts +23 -0
  32. package/dist/packages/editor/src/index.d.ts +118 -0
  33. package/dist/packages/fs/src/backends.d.ts +37 -0
  34. package/dist/packages/fs/src/index.d.ts +3 -0
  35. package/dist/packages/fs/src/types.d.ts +40 -0
  36. package/dist/packages/fs/src/vfs-service.d.ts +33 -0
  37. package/dist/packages/preview/src/index.d.ts +34 -0
  38. package/dist/packages/runtime/src/index.d.ts +47 -0
  39. package/dist/packages/settings/src/builtin-schemas.d.ts +15 -0
  40. package/dist/packages/settings/src/configuration-service.d.ts +100 -0
  41. package/dist/packages/settings/src/index.d.ts +4 -0
  42. package/dist/packages/settings/src/jsonc.d.ts +20 -0
  43. package/dist/packages/settings/src/schema.d.ts +28 -0
  44. package/dist/packages/sql/src/completions.d.ts +8 -0
  45. package/dist/packages/sql/src/diagnostics.d.ts +2 -0
  46. package/dist/packages/sql/src/formatter.d.ts +2 -0
  47. package/dist/packages/sql/src/index.d.ts +7 -0
  48. package/dist/packages/sql/src/sql-editor.d.ts +2 -0
  49. package/dist/packages/sql/src/styles.d.ts +2 -0
  50. package/dist/packages/sql/src/tokenizer.d.ts +13 -0
  51. package/dist/packages/sql/src/types.d.ts +130 -0
  52. package/dist/packages/terminal/src/index.d.ts +54 -0
  53. package/dist/packages/ui/src/index.d.ts +4 -0
  54. package/dist/packages/ui/src/observability.d.ts +22 -0
  55. package/dist/packages/ui/src/plugin-registry.d.ts +89 -0
  56. package/dist/packages/ui/src/settings-dialog.d.ts +25 -0
  57. package/dist/packages/ui/src/themes.d.ts +35 -0
  58. package/dist/preview-sw.js +53 -12
  59. package/dist/runtime.d.ts +3 -3
  60. package/dist/runtime.esm.js +467 -44
  61. package/dist/runtime.js +465 -44
  62. package/dist/schemas.d.ts +234 -814
  63. package/dist/schemas.esm.js +19401 -3725
  64. package/dist/schemas.js +19404 -3728
  65. package/dist/shell.d.ts +1 -1
  66. package/dist/shell.esm.js +364 -39
  67. package/dist/shell.js +364 -39
  68. package/dist/terminal.esm.js +62 -3
  69. package/dist/terminal.js +62 -3
  70. package/dist/workbench/diff-editor.d.ts +1 -0
  71. package/package.json +37 -8
  72. package/packages/commands/README.md +7 -0
  73. package/packages/commands/package.json +16 -0
  74. package/packages/commands/src/index.ts +467 -0
  75. package/packages/commands/tsconfig.json +22 -0
  76. package/packages/core/README.md +12 -0
  77. package/packages/core/package.json +13 -0
  78. package/packages/core/src/di.ts +147 -0
  79. package/packages/core/src/disposable.ts +112 -0
  80. package/packages/core/src/errors.ts +205 -0
  81. package/packages/core/src/events.ts +157 -0
  82. package/packages/core/src/index.ts +49 -0
  83. package/packages/core/src/path.ts +118 -0
  84. package/packages/core/src/registry.ts +61 -0
  85. package/packages/core/tsconfig.json +19 -0
  86. package/packages/editor/README.md +9 -0
  87. package/packages/editor/package.json +18 -0
  88. package/packages/editor/src/index.ts +344 -0
  89. package/packages/editor/tsconfig.json +24 -0
  90. package/packages/fs/README.md +7 -0
  91. package/packages/fs/package.json +16 -0
  92. package/packages/fs/src/backends.ts +301 -0
  93. package/packages/fs/src/index.ts +18 -0
  94. package/packages/fs/src/types.ts +44 -0
  95. package/packages/fs/src/vfs-service.ts +257 -0
  96. package/packages/fs/tsconfig.json +22 -0
  97. package/packages/preview/README.md +3 -0
  98. package/packages/preview/package.json +16 -0
  99. package/packages/preview/src/index.ts +125 -0
  100. package/packages/preview/tsconfig.json +22 -0
  101. package/packages/runtime/README.md +3 -0
  102. package/packages/runtime/package.json +17 -0
  103. package/packages/runtime/src/index.ts +134 -0
  104. package/packages/runtime/tsconfig.json +23 -0
  105. package/packages/settings/README.md +7 -0
  106. package/packages/settings/package.json +16 -0
  107. package/packages/settings/src/builtin-schemas.ts +235 -0
  108. package/packages/settings/src/configuration-service.ts +543 -0
  109. package/packages/settings/src/index.ts +37 -0
  110. package/packages/settings/src/jsonc.ts +189 -0
  111. package/packages/settings/src/schema.ts +164 -0
  112. package/packages/settings/tsconfig.json +22 -0
  113. package/packages/sql/README.md +12 -0
  114. package/packages/sql/package.json +13 -0
  115. package/packages/sql/src/completions.ts +359 -0
  116. package/packages/sql/src/diagnostics.ts +200 -0
  117. package/packages/sql/src/formatter.ts +271 -0
  118. package/packages/sql/src/index.ts +54 -0
  119. package/packages/sql/src/sql-editor.ts +802 -0
  120. package/packages/sql/src/styles.ts +501 -0
  121. package/packages/sql/src/tokenizer.ts +457 -0
  122. package/packages/sql/src/types.ts +148 -0
  123. package/packages/sql/tsconfig.json +19 -0
  124. package/packages/terminal/README.md +3 -0
  125. package/packages/terminal/package.json +16 -0
  126. package/packages/terminal/src/index.ts +183 -0
  127. package/packages/terminal/tsconfig.json +22 -0
  128. package/packages/ui/README.md +8 -0
  129. package/packages/ui/package.json +18 -0
  130. package/packages/ui/src/index.ts +36 -0
  131. package/packages/ui/src/observability.ts +175 -0
  132. package/packages/ui/src/plugin-registry.ts +274 -0
  133. package/packages/ui/src/settings-dialog.ts +293 -0
  134. package/packages/ui/src/themes.ts +174 -0
  135. package/packages/ui/tsconfig.json +24 -0
  136. package/src/code-lab.css +246 -0
  137. package/src/extensions/cpp.ts +58 -15
  138. package/src/extensions/python.ts +156 -24
  139. package/src/extensions/umbrella.ts +5 -0
  140. package/src/index.ts +1 -1
  141. package/src/modular-kernel.ts +11 -0
  142. package/src/preview-sw.js +52 -11
  143. package/src/runtime.ts +466 -46
  144. package/src/schemas.ts +62 -62
  145. package/src/shell.ts +363 -39
  146. package/src/terminal.ts +60 -2
  147. package/src/workbench/diff-editor.ts +66 -6
  148. package/src/workbench/icons.ts +5 -2
  149. package/src/workbench.ts +2410 -220
  150. package/dist/runtime/index.d.ts +0 -4
  151. package/dist/shell/coreutils/compilers-cli.d.ts +0 -24
  152. package/dist/shell/index.d.ts +0 -4
  153. package/src/runtime/index.ts +0 -5
  154. package/src/shell/coreutils/compilers-cli.ts +0 -103
  155. package/src/shell/index.ts +0 -5
package/ARCHITECTURE.md CHANGED
@@ -1,6 +1,8 @@
1
- # `@innovatorved/code-lab` Architecture (v0.3.2)
1
+ # `@innovatorved/code-lab` Architecture (v0.4.0)
2
2
 
3
- `@innovatorved/code-lab` is an embeddable, browser-native Node.js v22 + Bun v1.1 + WASI C++20 + Python 3.12 IDE, POSIX shell, PTY terminal, and virtual execution sandbox with self-contained browser bundles (zero runtime dependencies in `dist/*`; Zod schemas available under `@innovatorved/code-lab/schemas`; modular extensions under `@innovatorved/code-lab/extensions/{guided-lab,javascript,typescript,cpp,python}`).
3
+ `@innovatorved/code-lab` is an embeddable, browser-native Node.js v22 + Bun v1.1 + WASI C++20 + Python 3.12 IDE, first-class SQL playground (`@innovatorved/code-lab/sql`), POSIX shell, PTY terminal, and virtual execution sandbox with self-contained browser bundles (zero runtime dependencies in `dist/*`; Zod schemas available under `@innovatorved/code-lab/schemas`; modular extensions under `@innovatorved/code-lab/extensions/{guided-lab,javascript,typescript,cpp,python}`).
4
+
5
+ > **Deep-Dive Monorepo Guide**: See [`docs/ARCHITECTURE.md`](./docs/ARCHITECTURE.md) for the 4-layer workspace DAG (`@code-lab/core` → `@code-lab/{fs,settings,commands}` → `@code-lab/{sql,editor,runtime,terminal,preview}` → `@code-lab/ui` → `apps/web`), DI container, `.codelab/*` configuration cascade, and [`docs/PLUGINS.md`](./docs/PLUGINS.md) for the declarative plugin system.
4
6
 
5
7
  It is designed around two strictly decoupled layers that can be used together (`dist/code-lab.js`) or independently (`dist/runtime.js`, `dist/shell.js`, `dist/terminal.js` for headless or modular execution):
6
8
 
@@ -135,6 +137,6 @@ Running `bun run build` (`bun run tools/bundle.js`) produces:
135
137
  | **Visual Source Control (SCM)** | Staging, unstaging, diffing, and commit history | `src/scm.ts` (`createGitState`, `computeGitStatus`, `stageFile`, `unstageFile`, `commitChanges`, `computeShortCommitHash`) — Pure TypeScript SCM state machine synced with the POSIX shell `git` command |
136
138
  | **Live Preview & Error Overlay** | Hot/debounced reload, console bridge, runtime error overlay | `src/csp.ts` (`buildPreviewShims`) + `src/workbench.ts` — 300ms debounced VFS-synced auto-reload, `codelab:preview-console` forwarding to terminal logs, and `codelab:preview-error` in-frame overlay |
137
139
 
138
- All 43 test suites (`bun run test:all` and `node tests/run-all.js`) and the Playwright Chromium E2E suite (`bun run test:browser`) verify these modules and end-to-end workbench flows against the built `dist/*` artifacts.
140
+ All 45 test suites (`bun run test:all` and `node tests/run-all.js`) and the Playwright Chromium E2E suite (`bun run test:browser`) verify these modules and end-to-end workbench flows against the built `dist/*` artifacts.
139
141
 
140
142
 
package/CHANGELOG.md CHANGED
@@ -4,6 +4,26 @@ All notable changes to `@innovatorved/code-lab` are documented in this file.
4
4
 
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.4.0] - 2026-11-13
8
+
9
+ ### Added
10
+ - **4-Layer Modular Workspace Monorepo (`packages/*`, `apps/web`, `tools/check-boundaries.js`)**:
11
+ - Split core capabilities into 11 strict-TypeScript Bun workspaces: `@code-lab/core` (DI `ServiceContainer` with cycle detection, `DisposableStore`, `Emitter`, typed `CodeLabError`, structured `Logger`), `@code-lab/fs` (pluggable `MemoryBackend`, `IndexedDbBackend`, `OpfsBackend`), `@code-lab/settings` (JSONC parser, JSON Schema validator, 4-scope `ConfigurationService`), `@code-lab/commands` (`ContextKeyService` `when`-expression evaluator, `CommandRegistry`, `KeybindingService` with `-command` unbinding), `@code-lab/sql`, `@code-lab/editor`, `@code-lab/runtime`, `@code-lab/terminal`, `@code-lab/preview`, `@code-lab/ui`, and `apps/web` (`createCodeLabKernel`).
12
+ - Added `tools/check-boundaries.js` (`bun run check:boundaries`) enforcing one-way layer imports, public `src/index.ts` encapsulation, zero circular dependencies (Tarjan SCC), and zero DOM globals in `@code-lab/core`.
13
+ - **First-Class SQL Playground & Inline Editor (`@innovatorved/code-lab/sql`)**:
14
+ - New lightweight standalone entrypoint (`dist/code-lab-sql.{umd.js,esm.js,css,d.ts}`) at **`~16.5 KB` gzipped** (JS + CSS combined, `< 35 KB` budget enforced by `bun run check:size`) with zero WASM boot of its own.
15
+ - Full `PostgreSQL 18` (`::type`, `$1`, `$$` dollar strings, `ILIKE`, `LATERAL`, `RETURNING`, `FILTER (WHERE ...)`, JSONB `->`/`->>`/`@>`) and `SQLite 3` (`PRAGMA`, `WITHOUT ROWID`, `ON CONFLICT DO UPDATE`, `GLOB`, backtick/`[bracket]` identifiers) tokenizer and syntax highlighter.
16
+ - Zero-dependency SQL formatter (`formatSql`), schema-aware table-alias & CTE autocomplete (`completeSql`, resolving `SELECT o.` to `orders` columns with `PK`/`FK` badges), engine error parser (`parseSqlEngineError`), WCAG 2.1 AA keyboard escape (`Esc` → `Tab`), and 3 mount modes (`inline`, `playground`, and Guided Lab `workbench` with pluggable `sqlRunner` + built-in SQLite fallback).
17
+ - **VS Code-Style Settings UI, `.codelab/*` Workspace Protocol, Themes & Plugins (`src/workbench.ts`, `@code-lab/ui`)**:
18
+ - Searchable native `<dialog closedby="any">` Settings modal (`openSettings()` / `Cmd+,`) with category navigation, Reset to Default, Profile Export/Import, URL `?settings=` sharing, and live bidirectional sync with `.codelab/{settings,keybindings,tasks,extensions}.json`.
19
+ - Built-in Dark, Light, and High-Contrast themes plus custom JSON theme registration (`ThemeService`).
20
+ - Declarative `PluginRegistry` (`CodeLab.use(manifest)`, `workbench.registerPlugin(manifest)`) supporting lazy `activationEvents` and `contributes.{commands,settings,keybindings,themes,panels,languages}`, plus a live **Observability** drawer tab and `WorkbenchErrorBoundary`.
21
+
22
+ ### Fixed
23
+ - **All 26 Phase 1 Self-Audit Findings (`6 P0`, `14 P1`, `6 P2`)**:
24
+ - Patched all root and `examples/cloud-ide` dependency CVEs (`zod@4.6.7`, `esbuild@0.28.2`, `astro@7.4.11` — `bun audit` 0 vulnerabilities).
25
+ - Hardened `preview-sw.js` CSP/nosniff/302-navigate isolation, removed `allow-same-origin` from HTTP client response previews, fixed Worker VFS binary sync & timeout stream preservation, fixed inline Explorer create/rename (`F2`), and added comprehensive unit, regression, and Playwright Chromium E2E suites (47 Node/Bun suites + 30 Playwright Chromium tests).
26
+
7
27
  ## [0.3.2] - 2026-10-26
8
28
 
9
29
  ### Added
package/README.md CHANGED
@@ -1,45 +1,18 @@
1
1
  # @innovatorved/code-lab
2
2
 
3
- > **Note:** This project is in active development. APIs and sandbox internals are stable for production use.
3
+ Modular browser-native IDE workbench (`v0.4.0`), Web Worker runtime for Node.js, Bun, TypeScript, C++20 WebAssembly, and Python 3.12 WebAssembly, POSIX shell with 71 UNIX coreutils, and lightweight SQL playground built with strict TypeScript and Zod schemas — zero backend servers or cross-origin isolation headers required.
4
4
 
5
- Browser-native code IDE workbench, modular guided challenge engine (`@innovatorved/code-lab/extensions/guided-lab`), modular language extensions (`javascript`, `typescript`, real WebAssembly `cpp`, and WebAssembly `python`), POSIX shell with 71 UNIX coreutils, public GitHub repository cloner (`git clone`), and Web Worker execution runtime for **Node.js**, **Bun** (JavaScript & TypeScript), **C++20 (Clang/LLVM + WASI)**, and **Python 3.12 (CPython WASI)** with Zod type safety and zero backend server dependencies.
6
-
7
- - **Live Cloud IDE & GitHub Repo Explorer**: **[https://code-lab-3dr.pages.dev](https://code-lab-3dr.pages.dev)** — Enter any public GitHub repository (`owner/repo` or URL) to clone and run it directly in your browser.
8
- - **Built for**: [System Design In Depth](https://system-design-in-depth.vedgupta.in) & Data Structures & Algorithms (DSA) In Depth
5
+ **Live Cloud IDE:** [code-lab-3dr.pages.dev](https://code-lab-3dr.pages.dev) · **Documentation Wiki:** [github.com/innovatorved/code-lab/wiki](https://github.com/innovatorved/code-lab/wiki)
9
6
 
10
7
  ---
11
8
 
12
- ## Features
13
-
14
- - **Modular Architecture (`v0.3.2`)**: Pure, general-purpose browser IDE (`code-lab`) by default with File Explorer, Monaco Editor, PTY Terminal, and zero-dependency **JavaScript + Node.js/Bun** execution out of the box. Additional languages (`@innovatorved/code-lab/extensions/typescript`, `@innovatorved/code-lab/extensions/cpp`, and `@innovatorved/code-lab/extensions/python`) and curriculum features (`@innovatorved/code-lab/extensions/guided-lab`) are opt-in modular extensions.
15
- - **Real C++20 in WebAssembly (`@innovatorved/code-lab/extensions/cpp`)**: Compile and run real C++17/C++20/C++23 code natively in the browser via a WebAssembly Clang/LLVM + LLD (`wasm-ld`) + WASI `libc++` sysroot toolchain (~35 MB downloaded on demand only when the C++ extension is used and cached in `IndexedDB`). Features rich VS Code-style Monaco IntelliSense with auto-completions, header hovers, debounced static AST linting (`analyzeCppSource`), and live Clang compiler stderr error-squiggles (`applyClangStderrDiagnostics`). Includes `<bits/stdc++.h>`, `<codelab/dsa.hpp>` (`ListNode`, `TreeNode`, `buildLinkedList`, `buildBinaryTree`), and `<codelab/test.hpp>` (`DESCRIBE`, `TEST`, `ASSERT_EQ`) wired directly into the Test Suite drawer and Guided Lab step verification.
16
- - **Python 3.12 WebAssembly Extension (`@innovatorved/code-lab/extensions/python`)**: Run pure CPython 3.12 WebAssembly via Pyodide with lazy-loaded CDN binaries and IndexedDB caching. Features bidirectional VFS sync, pre-seeded `/usr/lib/python/` standard DSA helpers (`codelab_dsa.py` with `ListNode`, `TreeNode`, `MinHeap`, `MaxHeap`) and structured test framework (`codelab_test.py` with `describe`, `it`, `assert_equal`), Monaco completion/hover intelligence, traceback-to-squiggle mapping (`applyPythonTracebackDiagnostics`), static linting (`analyzePythonSource`), and formatting (`formatPythonSource`).
17
- - **Contextual Execution UI & Smooth Workbench**: Guided Challenge mode features a prominent primary `[✓ Verify Step (⌘↵)]` button with the `Test Suite` drawer tab visible by default. Normal/Sandbox mode provides a clean VS Code-style split button `[▶ Run Code (⌘↵) | ▾]` with dropdown options (`Run Entry`, `Run Active File`, `Run Tests`, `Configure Stdin`), with the drawer defaulting to `Terminal & REPL`. The topbar `Web Preview` globe button and bottom `Web Preview` drawer tab are contextual and stay neatly hidden unless the project contains web files or an active HTTP server.
18
- - **High-Impact IDE Power Features**:
19
- - **Problems Drawer Tab**: Dedicated `⚠ Problems (N)` tab aggregating JS/TS, C++, and Python diagnostics with live counter badge and 1-click cursor jump to line and column.
20
- - **Execution Time & Peak Memory HUD Badge**: High-resolution performance telemetry pill (`⏱ 12.4 ms · 🧠 1.8 MB`) displayed in the drawer header and status bar across Node, Bun, WASI C++, and Pyodide.
21
- - **Collapsible Stdin / Custom Input Panel**: Monospace textarea in the drawer for passing competitive-programming / DSA input directly into `std::cin`, `sys.stdin`, and `process.stdin`.
22
- - **Native Monaco Side-by-Side Diff Editor**: Compare `Starter ↔ Current` and `Current ↔ Solution` with 1-click "Revert" and "Apply Solution" actions directly in Monaco.
23
- - **Visible Command Palette Pill & Format Document**: Clickable topbar `🔍 Command Palette (⇧⌘P)` pill trigger + `Format Document` (`⇧⌥F`) across all languages.
24
- - **Zero-Backend URL Workspace Snapshot**: URL hash snapshot compression (`#codelab=<base64url>`) powered by `CompressionStream('deflate-raw')` for instant zero-server workspace sharing.
25
- - **End-to-End TypeScript & Zod Type Safety**: Written in TypeScript with strict runtime schemas and inferred types (`z.infer<typeof ...>`) for workbench options, guided labs, C++ toolchain options, runtime execution, and git cloning.
26
- - **Public GitHub Repository Cloning (`git clone`)**: Clone any public GitHub repository (`git clone https://github.com/owner/repo` or `git clone owner/repo --branch main` in the terminal, or `await lab.cloneRepo('owner/repo')` via the SDK) directly into `/workspace` with zero authentication required (automatic GitHub Trees API + jsDelivr unlimited fallback). Clone progress (`remote: Enumerating objects…`, `Receiving objects: n%…`) streams into the terminal in real time as it downloads.
27
- - **Interactive IDE Workbench**: Multi-file Monaco editor, collapsible hierarchical file tree with drag-and-drop, a workspace **folder switcher** (breadcrumb dropdown that scopes the explorer to any subfolder), decoupled editor tabs, Command Palette (`Cmd+Shift+P`), Quick Open (`Cmd+P`), breadcrumbs, and line-by-line solution diff viewer.
28
- - **Interactive PTY Terminal & Multi-Session Tabs**: Real-time streaming stdout/stderr with **foreground command locking** (hiding the active prompt and blocking concurrent input until the running foreground command finishes or is interrupted via `Ctrl+C`), isolated background jobs (`cmd &`) that survive foreground `SIGINT`, multi-session terminal tabs (`createTerminalSession`, `switchTerminalSession`, `closeTerminalSession`), inline prompt (`codelab:/workspace$ `), cursor navigation (`ArrowLeft`/`ArrowRight`/`Home`/`End`), history (`Up`/`Down`), `Ctrl+R` reverse-i-search, `Tab` auto-completion, `Ctrl+L` clear, and 256-color / TrueColor ANSI support.
29
- - **Interactive Workspace Search, Git SCM & ZIP Export/Import**:
30
- - **Workspace Search & Replace Modal (`Cmd+Shift+F`)**: Live regex/literal search across all workspace files with 1-click **Replace All** (`replaceInWorkspace`) and instant line/column navigation.
31
- - **Interactive Git Source Control Modal**: View modified/staged/untracked files (`getGitStatus`), stage/unstage individual files or **Stage All** (`stageGitFile`, `unstageGitFile`, `stageAllGitFiles`), and create commits (`commitGitChanges`) directly from the UI or POSIX `git` CLI.
32
- - **ZIP Archive & IndexedDB Persistence**: Export and import full workspaces as standard `.zip` archives (`exportZip`, `importZip`) with ZIP-bomb guards, and persist projects in `IndexedDB` (`saveProjectToStorage`, `loadProjectFromStorage`).
33
- - **POSIX Shell & 71 Coreutils**: Full pure-JS AST interpreter supporting pipelines (`|`), redirects (`>`, `>>`, `<`, `2>&1`, `<<<`, `<<EOF`), control flow (`if`/`for`/`while`/`case`), functions, arithmetic `$((...))`, brace expansion `{1..5}`, and 71 UNIX commands (`g++`, `clang++`, `c++`, `python`, `python3`, `pytest`, `pip`, `git`, `ls`, `cat`, `grep`, `find`, `sed`, `awk`, `jq`, `tar`, `curl`, `hey`, `ab`, `wrk`, `chaos`, `sqlite3`, `redis-cli`, `nc`, `lsof`, `tsc`, etc.) plus direct `./a.out` WASI binary execution.
34
- - **Dual Runtime Engines (Node.js v22 & Bun v1.1)**:
35
- - **Node.js**: 50 built-in modules (`fs`, `fs/promises`, `http`, `https`, `net`, `stream`, `events`, `crypto`, `zlib`, `vm`, `worker_threads`, `readline`, `module`, `node:test`, `assert`, etc.) with full Node.js built-ins support.
36
- - **Bun**: Native `.ts` transpilation, `Bun.serve()`, `Bun.file()`, `Bun.write()`, `Bun.spawn()`, `Bun.password`, `Bun.hash()`, `bun:test`, and VFS-backed `bun:sqlite`.
37
- - **Persistent HTTP/TCP Servers & Dual Web Preview**: Start background servers (`node server.js &` or `bun run server.ts &`), query them with `curl http://localhost:3000` or global `fetch()`, and view live responses in the Ports table, an embedded **Web Preview** tab (URL bar, back/forward, device frames), or a popped-out browser tab backed by a virtual-loopback Service Worker (`/__preview/:port/*`). Public URLs (e.g. `https://example.com`) entered in the preview URL bar open in a real browser tab instead of the virtual frame.
38
- - **Built-in Preview Server (`serve`) & Toolbar *Run & Preview***: Render a real app in the browser with no bundler — `serve [dir] [--port]`, the toolbar globe button, or `npm run dev` all start a static server that transpiles `.ts` / `.tsx` / `.jsx` to browser-native ESM, resolves extensionless relative imports, and injects a jsDelivr `+esm` **import map** for bare specifiers (`react`, `react-dom/client`, `@angular/core`, …). Vite/`ng`/Astro/Next scripts that need native binaries transparently fall back to it.
39
- - **GitHub-Flavored Markdown Engine**: Zero-dependency GFM renderer (tables with column alignment, `[!NOTE]` / `[!TIP]` / `[!IMPORTANT]` / `[!WARNING]` / `[!CAUTION]` callout alerts, task-list checkboxes, and syntax-highlighted code blocks with one-click copy) powering the Guide tab, hints, and `.md` file previews.
40
- - **NPM, pnpm & Bun Package Management**: `npm i <pkg>` / `pnpm add <pkg>` / `bun add <pkg>` / `bun install` fetch the real package (and its transitive dependencies, honouring `exports` maps, subpaths and peer deps) from the jsDelivr CDN into virtual `/workspace/node_modules/<pkg>` and update `package.json` (`-D` / `--save-dev` writes to `devDependencies`); packages stay `require()`-able from `node`/`bun run`, with a bundled offline fallback for common demo packages. Framework JSX/TSX (`React.createElement`, custom `@jsx` pragmas) and ESM (including minified bundles) are handled by the runtime transpiler.
41
- - **Guided Step-by-Step Challenges**: TutorialKit / Codedamn-style curriculum extension with targeted instructions, hints, automated test verification per step, and reference solutions.
42
- - **Headless Runtime**: Programmatic execution engine (`@innovatorved/code-lab/runtime`) for grading, testing, or automated evaluation with zero UI.
9
+ ## Highlights
10
+
11
+ - **Layered Modular Core**: Four-layer workspace architecture with dependency injection, workspace settings and custom keybindings, a visual Settings dialog, Dark, Light, and High-Contrast themes, and lazy-loaded plugins.
12
+ - **SQL Editor & Playground (~16.5 KB gzipped)**: Standalone PostgreSQL 18 and SQLite 3 editor supporting inline lesson blocks, split-pane query studios, SQL formatting, schema-aware alias autocomplete, inline wavy diagnostics, and accessible keyboard navigation.
13
+ - **Node.js, Bun & WebAssembly Toolchains**: Built-in JavaScript and JSX runtime with 50 built-in modules (50 Node.js built-ins) and native Bun APIs, plus opt-in TypeScript, Clang/LLVM C++20 WebAssembly, and Pyodide Python 3.12 extensions.
14
+ - **POSIX Shell & 71 Coreutils**: Multi-session terminal with pipelines, stream redirection, background servers, public GitHub repository cloning, package installation, HTTP load testing, and 71 UNIX commands.
15
+ - **Guided Labs & Headless Grading**: Step-by-step coding and SQL challenges with progressive hints, side-by-side solution diffs, and zero-UI headless worker execution.
43
16
 
44
17
  ---
45
18
 
@@ -51,175 +24,104 @@ bun add @innovatorved/code-lab
51
24
  npm install @innovatorved/code-lab
52
25
  ```
53
26
 
54
- Or load from a static script tag via CDN:
27
+ Or load via CDN with zero build tools:
55
28
 
56
29
  ```html
30
+ <!-- Full IDE Workbench -->
57
31
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@innovatorved/code-lab/dist/code-lab.css" />
58
32
  <script src="https://cdn.jsdelivr.net/npm/@innovatorved/code-lab/dist/code-lab.js"></script>
33
+
34
+ <!-- Standalone SQL Pack (~16.5 KB gzipped JS + CSS) -->
35
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@innovatorved/code-lab/dist/code-lab-sql.css" />
36
+ <script src="https://cdn.jsdelivr.net/npm/@innovatorved/code-lab/dist/code-lab-sql.umd.js"></script>
59
37
  ```
60
38
 
61
39
  ---
62
40
 
63
- ## Usage
41
+ ## Quick Start
64
42
 
65
- ### 1. Mount Workbench in DOM
43
+ ### Browser IDE Workbench
66
44
 
67
- ```js
45
+ ```ts
68
46
  import CodeLab from '@innovatorved/code-lab';
69
47
  import '@innovatorved/code-lab/code-lab.css';
70
48
 
71
49
  const lab = CodeLab.mount('#editor', {
72
- id: 'rate-limiter',
73
- title: 'Token Bucket Rate Limiter',
74
- mode: 'guided',
75
- language: 'js',
76
- entry: 'demo.js',
77
- testEntry: 'test.js',
78
- starterFiles: {
79
- 'limiter.js': 'class TokenBucket {\n allow() { return false; }\n}\nmodule.exports = { TokenBucket };\n',
80
- 'demo.js': 'const { TokenBucket } = require("./limiter");\nconsole.log(new TokenBucket().allow());\n',
81
- 'test.js': 'const { test } = require("node:test");\nconst assert = require("node:assert/strict");\nconst { TokenBucket } = require("./limiter");\n\ntest("allows request", () => {\n assert.equal(new TokenBucket().allow(), true);\n});\n'
82
- },
83
- steps: [
84
- {
85
- id: 'step-1',
86
- title: 'Allow requests within capacity',
87
- targetFile: 'limiter.js',
88
- targetSymbol: 'allow',
89
- instructions: 'Return `true` when tokens are available.',
90
- testNames: ['allows request']
91
- }
92
- ]
50
+ id: 'http-demo',
51
+ title: 'Bun HTTP Server',
52
+ entry: 'server.ts',
53
+ files: {
54
+ 'server.ts': 'Bun.serve({ port: 3000, fetch: () => Response.json({ ok: true }) });\n'
55
+ }
93
56
  });
94
57
  ```
95
58
 
96
- ### 2. `<code-lab>` Custom Element
59
+ ### Lightweight SQL Inline Editor & Playground
97
60
 
98
- ```html
99
- <code-lab mode="sandbox" language="ts" style="height: 600px;">
100
- <script type="application/json">
101
- {
102
- "id": "demo-lab",
103
- "title": "Bun HTTP Demo",
104
- "entry": "server.ts",
105
- "files": {
106
- "server.ts": "Bun.serve({ port: 3000, fetch: () => Response.json({ ok: true }) }); console.log('Listening on :3000');"
107
- }
108
- }
109
- </script>
110
- </code-lab>
111
- ```
112
-
113
- ### 3. Headless Runtime (No UI)
114
-
115
- ```js
116
- import { executeInWorker } from '@innovatorved/code-lab/runtime';
61
+ ```ts
62
+ import { createSqlEditor } from '@innovatorved/code-lab/sql';
63
+ import '@innovatorved/code-lab/sql.css';
117
64
 
118
- const res = await executeInWorker({
119
- mode: 'test',
120
- entry: 'test.js',
121
- files: {
122
- 'math.js': 'module.exports = { add: (a, b) => a + b };',
123
- 'test.js': 'const { test } = require("node:test");\nconst assert = require("node:assert/strict");\nconst { add } = require("./math");\ntest("adds numbers", () => assert.equal(add(2, 3), 5));'
65
+ const sql = createSqlEditor(document.getElementById('sql')!, {
66
+ mode: 'inline',
67
+ dialect: 'postgres',
68
+ value: 'SELECT id, email FROM customers ORDER BY id LIMIT 10;',
69
+ async onRun({ effectiveSql }) {
70
+ console.log('Execute SQL:', effectiveSql);
124
71
  }
125
72
  });
126
-
127
- console.log(res.ok, res.testResults);
128
73
  ```
129
74
 
130
- ### 4. Modular Language Extensions (TypeScript, Real C++20 & Python 3.12 in WebAssembly)
131
-
132
- JavaScript (`node` and `bun` zero-dependency browser runtime) is enabled out of the box. You can opt into TypeScript (`@innovatorved/code-lab/extensions/typescript`), Real C++20 in WebAssembly (`@innovatorved/code-lab/extensions/cpp`), and/or Python 3.12 in WebAssembly (`@innovatorved/code-lab/extensions/python`):
133
-
134
- ```js
135
- import CodeLab from '@innovatorved/code-lab';
136
- import { typescriptExtension } from '@innovatorved/code-lab/extensions/typescript';
137
- import { cppExtension } from '@innovatorved/code-lab/extensions/cpp';
138
- import { pythonExtension } from '@innovatorved/code-lab/extensions/python';
139
- import { guidedLabExtension } from '@innovatorved/code-lab/extensions/guided-lab';
75
+ ---
140
76
 
141
- const lab = CodeLab.mount('#editor', {
142
- id: 'dsa-binary-search',
143
- title: 'Binary Search (JS / TS / C++20 / Python 3.12)',
144
- language: 'cpp'
145
- })
146
- .use(typescriptExtension)
147
- .use((wb) => cppExtension(wb, { std: 'c++20', cacheInIndexedDB: true }))
148
- .use((wb) => pythonExtension(wb, { cacheInIndexedDB: true }))
149
- .use((wb) =>
150
- guidedLabExtension(wb, {
151
- starterFiles: { 'src/solution.js': 'module.exports = { search: () => -1 };\n' },
152
- tsStarterFiles: { 'src/solution.ts': 'export const search = (nums: number[], target: number): number => -1;\n' },
153
- cppStarterFiles: {
154
- 'src/solution.hpp': '#pragma once\n#include <bits/stdc++.h>\nint search(const std::vector<int>& nums, int target) { return -1; }\n',
155
- 'src/test.cpp': '#include <codelab/test.hpp>\n#include "solution.hpp"\nint main() {\n DESCRIBE("Binary Search", {\n TEST("finds target", {\n ASSERT_EQ(search({-1, 0, 3, 5, 9, 12}, 9), 4);\n });\n });\n return CODELAB_TEST_EXIT_CODE();\n}\n'
156
- },
157
- pyStarterFiles: {
158
- 'src/solution.py': 'def search(nums: list[int], target: int) -> int:\n return -1\n',
159
- 'src/test_solution.py': 'from codelab_test import describe, it, assert_equal\nfrom solution import search\n\nwith describe("Binary Search"):\n with it("finds target"):\n assert_equal(search([-1, 0, 3, 5, 9, 12], 9), 4)\n'
160
- },
161
- steps: [
162
- {
163
- id: 'step-1',
164
- title: 'Implement O(log N) binary search',
165
- targetFile: 'src/solution.hpp',
166
- instructions: 'Return the index of `target` in `nums`, or `-1` if not found.',
167
- testNames: ['finds target']
168
- }
169
- ]
170
- })
171
- );
172
- ```
77
+ ## Package Entrypoints
78
+
79
+ | Import Path | Purpose |
80
+ | :--- | :--- |
81
+ | `@innovatorved/code-lab` | Full multi-file IDE workbench, POSIX terminal, Settings UI, plugins, and Web Preview |
82
+ | `@innovatorved/code-lab/code-lab.css` | Main workbench stylesheet |
83
+ | `@innovatorved/code-lab/sql` | Zero-dependency PostgreSQL 18 and SQLite 3 inline and playground editor (~16.5 KB gzipped) |
84
+ | `@innovatorved/code-lab/sql.css` | Standalone SQL editor stylesheet |
85
+ | `@innovatorved/code-lab/runtime` | Headless Web Worker runtime for programmatic code and test execution |
86
+ | `@innovatorved/code-lab/shell` | Pure-JavaScript POSIX shell interpreter and 71 UNIX utilities |
87
+ | `@innovatorved/code-lab/terminal` | 256-color PTY terminal emulator engine |
88
+ | `@innovatorved/code-lab/schemas` | Zod runtime validation schemas and TypeScript types |
89
+ | `@innovatorved/code-lab/extensions/*` | Opt-in extensions for Guided Labs, TypeScript, C++20 WebAssembly, and Python 3.12 WebAssembly |
90
+ | `@innovatorved/code-lab/preview-sw.js` | Virtual loopback Service Worker for standalone browser preview tabs |
173
91
 
174
92
  ---
175
93
 
176
- ## Documentation
94
+ ## Documentation (GitHub Wiki)
177
95
 
178
- Complete documentation is published on the [GitHub Wiki](https://github.com/innovatorved/code-lab/wiki):
96
+ Full guides and API references live on the **[GitHub Wiki](https://github.com/innovatorved/code-lab/wiki)**:
179
97
 
180
- - **[Quick Start](https://github.com/innovatorved/code-lab/wiki/Quick-Start)**: Setup, CDN, and quick examples.
181
- - **[Integration Guide](https://github.com/innovatorved/code-lab/wiki/Integration-Guide)**: Embedding in React, Next.js, Vite, and HTML.
182
- - **[Workbench Configuration](https://github.com/innovatorved/code-lab/wiki/Workbench-Configuration)**: Complete reference of options, methods, events, and shortcuts.
183
- - **[POSIX Shell & Coreutils](https://github.com/innovatorved/code-lab/wiki/POSIX-Shell-and-Coreutils)**: Pipelines, redirects, background jobs, and 71 UNIX commands.
184
- - **[Runtime APIs (Node & Bun)](https://github.com/innovatorved/code-lab/wiki/Runtime-APIs)**: 50 Node.js built-ins, Bun APIs, `bun:test`, `bun:sqlite`, and npm install.
185
- - **[HTTP Servers & Networking](https://github.com/innovatorved/code-lab/wiki/HTTP-Servers-and-Networking)**: Virtual port table, background servers, `curl`, and Port Preview.
186
- - **[Headless Runtime](https://github.com/innovatorved/code-lab/wiki/Headless-Runtime)**: Run code and tests programmatically with zero UI.
187
- - **[Authoring Guided Labs](https://github.com/innovatorved/code-lab/wiki/Authoring-Guided-Labs)**: Schema and invariants for creating interactive coding challenges.
188
- - **[Plugin System & Custom Extensions](https://github.com/innovatorved/code-lab/wiki/Plugin-System)**: Extend CodeLab with `.use(plugin)` and `.on()` event hooks.
98
+ - **[Home](https://github.com/innovatorved/code-lab/wiki)** — Overview and architecture diagram
99
+ - **[Quick Start](https://github.com/innovatorved/code-lab/wiki/Quick-Start)** — Package installation, custom HTML element, and CDN setup
100
+ - **[SQL Playground & Inline Editor](https://github.com/innovatorved/code-lab/wiki/SQL-Playground-and-Inline-Editor)** — Inline blocks, playgrounds, PostgreSQL and SQLite dialects, and autocomplete
101
+ - **[Integration Guide](https://github.com/innovatorved/code-lab/wiki/Integration-Guide)** — React, Next.js App Router, and Vite integration recipes
102
+ - **[Workbench Configuration](https://github.com/innovatorved/code-lab/wiki/Workbench-Configuration)** — Mount options, workspace settings, methods, and keyboard shortcuts
103
+ - **[Runtime APIs](https://github.com/innovatorved/code-lab/wiki/Runtime-APIs)** — Node.js v22, Bun v1.1, C++20 WebAssembly, and Python 3.12 WebAssembly
104
+ - **[POSIX Shell & Coreutils](https://github.com/innovatorved/code-lab/wiki/POSIX-Shell-and-Coreutils)** — Shell syntax and all 71 built-in UNIX commands
105
+ - **[HTTP Servers & Networking](https://github.com/innovatorved/code-lab/wiki/HTTP-Servers-and-Networking)** — Loopback port table, background servers, load testing, and Web Preview
106
+ - **[Headless Runtime](https://github.com/innovatorved/code-lab/wiki/Headless-Runtime)** — Zero-UI grading and programmatic test execution
107
+ - **[Authoring Guided Labs](https://github.com/innovatorved/code-lab/wiki/Authoring-Guided-Labs)** — Step-by-step challenges across JavaScript, TypeScript, C++20, Python 3.12, and SQL
108
+ - **[Plugin System](https://github.com/innovatorved/code-lab/wiki/Plugin-System)** — Declarative plugins, language packs, and lifecycle hooks
109
+ - **[Architecture & Monorepo](https://github.com/innovatorved/code-lab/wiki/Architecture-and-Monorepo)** — Workspace layers, dependency injection, and virtual filesystem backends
189
110
 
190
111
  ---
191
112
 
192
- ## Local Development & Testing
113
+ ## Development
193
114
 
194
115
  ```bash
195
- # Install dependencies with Bun
196
116
  bun install
197
-
198
- # Rebuild all distribution bundles
199
- bun run build
200
-
201
- # Run the complete test suite
202
- bun run test:all
203
- bun run tests/test-all-builds.js # 15/15 builds & 226 unit tests
204
- bun run tests/test-runtime-advanced.js # Advanced runtime, VFS, HTTP/TCP
205
- bun run tests/test-option1-shell-bun-http.js # Shell AST, Bun runtime, curl, ports, npm/pnpm
206
- bun run tests/test-frameworks.js # React/Preact/Vue/Angular support + browser preview server
207
- bun run tests/test-coreutils-adversarial.js # Adversarial stress tests on 71 coreutils
208
- bun run tests/test-stress-shell.js # Deep pipelines, redirections, large stdout
209
- bun run tests/test-workbench-ui.js # Workbench tabs, explorer, shortcuts
210
- bun run tests/test-cpp-extension.js # Real C++20 WASI runtime, g++, and language extensions
211
- bun run tests/test-python-extension.js # Python 3.12 WebAssembly runtime, pytest, and language service
212
- ```
213
-
214
- Individual suites also run under Node 20, 22 and 24 — CI exercises all three:
215
-
216
- ```bash
217
- bun run build && node tests/run-all.js # same 43 suites, Node runtime
117
+ bun run build # Build all ESM, CJS, UMD bundles and TypeScript declarations
118
+ bun run check:boundaries # Verify 4-layer package boundaries and zero circular imports
119
+ bun run check:size # Enforce gzip bundle size budgets
120
+ bun run test:all # Run all 47 suites plus Playwright browser tests
121
+ node tests/run-all.js # Run the same 47 suites under Node 20, 22, and 24
218
122
  ```
219
123
 
220
- Suites load the built bundles from `dist/` (never raw TypeScript from `src/`), so
221
- `dist/` must exist and be newer than `src/`. `tests/run-all.js` exits with code 2
222
- and a "dist/ is stale" message otherwise; run `bun run build` first.
124
+ See [CONTRIBUTING.md](./CONTRIBUTING.md) for contribution guidelines.
223
125
 
224
126
  ---
225
127
 
@@ -0,0 +1,34 @@
1
+ import { type ICommandRegistry, type IContextKeyService, type IKeybindingService } from '@code-lab/commands';
2
+ import { ServiceContainer, type EventTraceRecord, type IDisposable, type ILogger } from '@code-lab/core';
3
+ import { type IEditorService } from '@code-lab/editor';
4
+ import { type IFsBackend, type IFileSystemService } from '@code-lab/fs';
5
+ import { type IPreviewService } from '@code-lab/preview';
6
+ import { type IRuntimeService, type RuntimeExecutorDelegate } from '@code-lab/runtime';
7
+ import { type IConfigurationService } from '@code-lab/settings';
8
+ import { type ITerminalService } from '@code-lab/terminal';
9
+ import { type IPluginRegistry, type IThemeService } from '@code-lab/ui';
10
+ export interface CodeLabKernelOptions {
11
+ readonly instanceId?: string;
12
+ readonly fsBackend?: 'memory' | 'indexeddb' | 'opfs' | IFsBackend;
13
+ readonly initialFiles?: Readonly<Record<string, string>>;
14
+ readonly runtimeDelegate?: RuntimeExecutorDelegate;
15
+ readonly logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'silent';
16
+ }
17
+ export interface CodeLabKernel extends IDisposable {
18
+ readonly instanceId: string;
19
+ readonly container: ServiceContainer;
20
+ readonly logger: ILogger;
21
+ readonly fs: IFileSystemService;
22
+ readonly configuration: IConfigurationService;
23
+ readonly contextKeys: IContextKeyService;
24
+ readonly commands: ICommandRegistry;
25
+ readonly keybindings: IKeybindingService;
26
+ readonly editor: IEditorService;
27
+ readonly runtime: IRuntimeService;
28
+ readonly terminal: ITerminalService;
29
+ readonly preview: IPreviewService;
30
+ readonly themes: IThemeService;
31
+ readonly plugins: IPluginRegistry;
32
+ getRecentEvents(): readonly EventTraceRecord[];
33
+ }
34
+ export declare function createCodeLabKernel(options?: CodeLabKernelOptions): CodeLabKernel;