@innovatorved/code-lab 0.1.13 → 0.2.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.
- package/ARCHITECTURE.md +7 -7
- package/CHANGELOG.md +107 -0
- package/README.md +48 -8
- package/dist/code-lab.d.ts +19 -7
- package/dist/code-lab.esm.js +11085 -84
- package/dist/code-lab.js +11078 -80
- package/dist/extensions/cpp.d.ts +119 -0
- package/dist/extensions/cpp.esm.js +5193 -0
- package/dist/extensions/cpp.js +5212 -0
- package/dist/extensions/guided-lab.esm.js +48 -6
- package/dist/extensions/guided-lab.js +49 -6
- package/dist/extensions/javascript.d.ts +24 -0
- package/dist/extensions/javascript.esm.js +36 -0
- package/dist/extensions/javascript.js +59 -0
- package/dist/extensions/typescript.d.ts +36 -0
- package/dist/extensions/typescript.esm.js +55 -0
- package/dist/extensions/typescript.js +78 -0
- package/dist/index.d.ts +5 -2
- package/dist/preview-sw.js +1 -1
- package/dist/runtime.d.ts +6 -0
- package/dist/runtime.esm.js +888 -15
- package/dist/runtime.js +882 -15
- package/dist/schemas.d.ts +122 -23
- package/dist/schemas.esm.js +43 -6
- package/dist/schemas.js +43 -6
- package/dist/shell.esm.js +177 -4
- package/dist/shell.js +177 -4
- package/dist/terminal.esm.js +1 -1
- package/dist/terminal.js +1 -1
- package/package.json +27 -3
- package/src/extensions/cpp.ts +1081 -0
- package/src/extensions/guided-lab.ts +10 -0
- package/src/extensions/javascript.ts +54 -0
- package/src/extensions/typescript.ts +85 -0
- package/src/index.ts +33 -2
- package/src/runtime.ts +883 -14
- package/src/schemas.ts +49 -7
- package/src/shell.ts +176 -3
- package/src/workbench.ts +298 -45
package/ARCHITECTURE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# `@innovatorved/code-lab` Architecture (v0.
|
|
1
|
+
# `@innovatorved/code-lab` Architecture (v0.2.0)
|
|
2
2
|
|
|
3
|
-
`@innovatorved/code-lab` is an embeddable, browser-native Node.js v22 + Bun v1.1 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`).
|
|
3
|
+
`@innovatorved/code-lab` is an embeddable, browser-native Node.js v22 + Bun v1.1 + WASI C++20 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}`).
|
|
4
4
|
|
|
5
5
|
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
6
|
|
|
@@ -27,9 +27,9 @@ It is designed around two strictly decoupled layers that can be used together (`
|
|
|
27
27
|
│ src/terminal.ts) │ │ (src/runtime.ts) │
|
|
28
28
|
│ • Recursive-descent AST parser │ │ • Web Worker pool + preemption │
|
|
29
29
|
│ • Pipes (|), redirects (>, >>, 2>&1) │ │ • In-memory POSIX VFS (/tmp, …) │
|
|
30
|
-
│ •
|
|
30
|
+
│ • 67 POSIX coreutils + git + jq │ │ • Node.js v22 (50 built-in mods)│
|
|
31
31
|
│ • Interactive PTY ANSI/256-color │ │ • Bun v1.1 (serve, sqlite, test)│
|
|
32
|
-
│ • Job table (ps, jobs, fg, bg, kill) │ │ •
|
|
32
|
+
│ • Job table (ps, jobs, fg, bg, kill) │ │ • WASI Preview 1 + C++20 Clang │
|
|
33
33
|
└───────────────────────────────────────┘ └──────────────────────────────────┘
|
|
34
34
|
```
|
|
35
35
|
|
|
@@ -69,11 +69,11 @@ It is designed around two strictly decoupled layers that can be used together (`
|
|
|
69
69
|
|
|
70
70
|
`createPosixShell` implements a complete POSIX shell interpreter inside the browser:
|
|
71
71
|
- **Lexer & Recursive-Descent AST Parser**: Supports single/double quotes, escape sequences, pipelines (`cmd1 | cmd2 | cmd3`), logical operators (`&&`, `||`, `;`), background execution (`&`), I/O redirection (`>`, `>>`, `<`, `<<<`, `2>`, `2>&1`, `&>`), environment variable expansion (`$VAR`, `${VAR:-default}`, `${VAR:=default}`, `${#VAR}`, `$?`, `$$`), command substitution (`$(...)`), arithmetic expansion (`$((...))`), brace expansion (`{a,b,c}`, `{1..5}`), and globbing (`*`, `?`, `**`).
|
|
72
|
-
- **
|
|
72
|
+
- **67 Built-in Coreutils**:
|
|
73
73
|
- File & Directory: `ls`, `cat`, `head`, `tail`, `wc`, `cp`, `mv`, `rm`, `mkdir`, `rmdir`, `touch`, `ln`, `pwd`, `cd`, `find`, `tree`, `stat`, `file`, `du`, `df`, `chmod`, `chown`, `mktemp`, `basename`, `dirname`, `realpath`.
|
|
74
74
|
- Text & Data Processing: `grep`, `sed`, `awk`, `sort`, `uniq`, `cut`, `tr`, `tee`, `xargs`, `diff`, `jq`, `xxd`, `hexdump`, `base64`, `md5sum`, `sha256sum`.
|
|
75
75
|
- Networking, Load Testing, Chaos & Databases: `curl`, `hey` (`ab`, `wrk`), `chaos`, `sqlite3`, `redis-cli`, `nc`, `ping`, `dig`, `nslookup`, `lsof`, `netstat`, `ss`, `ps`, `top`, `kill`, `jobs`, `fg`, `bg`, `tar`, `gzip`, `gunzip`.
|
|
76
|
-
- Developer Toolchains: `node`, `bun`, `npm`, `pnpm`, `npx`, `bunx`, `tsc`, `git` (`init`, `status`, `add`, `commit`, `log`, `diff`, `branch`, `checkout`, `clone`).
|
|
76
|
+
- Developer Toolchains: `node`, `bun`, `npm`, `pnpm`, `npx`, `bunx`, `tsc`, `g++`, `clang++`, `c++`, `git` (`init`, `status`, `add`, `commit`, `log`, `diff`, `branch`, `checkout`, `clone`).
|
|
77
77
|
- Web Preview: `serve` (built-in static dev server that transpiles TS/TSX/JSX to browser-native ESM and injects a jsDelivr `+esm` import map for bare specifiers).
|
|
78
78
|
|
|
79
79
|
---
|
|
@@ -128,6 +128,6 @@ Running `bun run build` (`bun run tools/bundle.js`) produces:
|
|
|
128
128
|
| **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 |
|
|
129
129
|
| **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 |
|
|
130
130
|
|
|
131
|
-
All
|
|
131
|
+
All 41 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.
|
|
132
132
|
|
|
133
133
|
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `@innovatorved/code-lab` are documented in this file.
|
|
4
|
+
|
|
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
|
+
|
|
7
|
+
## [0.2.0] - 2026-10-24
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- **Real C++20 in WebAssembly Extension (`@innovatorved/code-lab/extensions/cpp`, `src/extensions/cpp.ts`)**:
|
|
11
|
+
- Real ~35 MB Clang/LLVM + LLD (`wasm-ld`) + WASI C++20 Sysroot (`libc` + `libc++`) toolchain downloaded on demand only when `cppExtension` is used and cached persistently in `IndexedDB` (`codelab_cpp_toolchain_v1`).
|
|
12
|
+
- Built-in Competitive Programming & DSA headers seeded into `/usr/include`: `<bits/stdc++.h>`, `<codelab/dsa.hpp>` (`ListNode`, `TreeNode`, `buildLinkedList`, `buildBinaryTree`, `printMatrix`, `BenchmarkTimer`), and `<codelab/test.hpp>` (`DESCRIBE`, `TEST`, `IT`, `ASSERT_EQ`, `ASSERT_NE`, `ASSERT_TRUE`, `ASSERT_FALSE`) emitting structured `__CODELAB_TEST__:{json}` markers to `code-lab`'s Test Suite drawer and Guided Lab `Verify Step`.
|
|
13
|
+
- Pure TypeScript POSIX UStar `.tar` extractor and generator (`extractTarToVfs`, `createTarArchive`).
|
|
14
|
+
- **WASI Preview 1 Syscall Layer (`src/runtime.ts`)**:
|
|
15
|
+
- Added `createVirtualWasi` (`wasi_snapshot_preview1`) and `executeWasiModule` backed by `VirtualFS` (`fd_read`, `fd_write`, `fd_seek`, `fd_close`, `path_open`, `path_create_directory`, `path_unlink_file`, `args_get`, `environ_get`, `clock_time_get`, `random_get`, `proc_exit` via `WasiExitSignal`).
|
|
16
|
+
- `executeInVirtualRuntime` now supports `.wasm` and `.cpp` entrypoints directly and parses `__CODELAB_TEST__:{json}` lines into `testResults`.
|
|
17
|
+
- **POSIX Shell C++ Compiler & WASI Binary Execution (`src/shell.ts`)**:
|
|
18
|
+
- Added `g++`, `clang++`, and `c++` commands (`67` total POSIX coreutils) plus direct `./<binary>` (`.wasm` magic byte `0x00 0x61 0x73 0x6d`) execution with `< input.txt` stdin and `> output.txt` / `>>` stdout redirection.
|
|
19
|
+
- **Modular Language Extensions (`@innovatorved/code-lab/extensions/{javascript,typescript,cpp}`)**:
|
|
20
|
+
- **JavaScript (`javascriptExtension`)**: Enabled **by default out-of-the-box** using the browser's native JS engine and `code-lab`'s zero-dependency `node` & `bun` virtual runtime.
|
|
21
|
+
- **TypeScript (`typescriptExtension`)**: Opt-in zero-dependency browser extension using `code-lab`'s built-in `transpileTS` + virtual `node`/`bun` runtime.
|
|
22
|
+
- **C++ (`cppExtension`)**: Opt-in WebAssembly Clang/LLVM + WASI C++20 extension.
|
|
23
|
+
- **3-Way Language Switcher (`JS | TS | C++`) & Multi-Language Guided Labs (`src/workbench.ts`, `src/schemas.ts`)**:
|
|
24
|
+
- Added `cppStarterFiles`, `cppSolutionFiles`, and `cppFiles` to `GuidedLabExtensionOptionsSchema` and `WorkbenchOptionsSchema`.
|
|
25
|
+
- Workbench language switcher dynamically renders pills for the enabled languages (`wb.enabledLanguages`).
|
|
26
|
+
|
|
27
|
+
### Breaking Changes & Migration Guide (`v0.1.x` $\rightarrow$ `v0.2.0`)
|
|
28
|
+
1. **Default Workbench Language Surface (`['js']` by default)**:
|
|
29
|
+
- **Before (`v0.1.x`)**: Mounting a standalone workbench without language extensions exposed only JavaScript unless `guidedLabExtension` was configured with `ts*` files.
|
|
30
|
+
- **Now (`v0.2.0`)**: JavaScript (`javascriptExtension`) + zero-dependency virtual `node` and `bun` remains enabled by default (`0 MB` extra download). To enable TypeScript or C++ in the workbench toolbar switcher (`JS | TS | C++`), register `typescriptExtension` and/or `cppExtension` via `.use()` or `extensions: [...]`:
|
|
31
|
+
```ts
|
|
32
|
+
import CodeLab, {
|
|
33
|
+
typescriptExtension,
|
|
34
|
+
cppExtension,
|
|
35
|
+
guidedLabExtension
|
|
36
|
+
} from '@innovatorved/code-lab';
|
|
37
|
+
|
|
38
|
+
const lab = CodeLab.mount('#editor', {
|
|
39
|
+
id: 'dsa-binary-search',
|
|
40
|
+
title: 'Binary Search in Depth',
|
|
41
|
+
language: 'cpp'
|
|
42
|
+
})
|
|
43
|
+
.use(typescriptExtension)
|
|
44
|
+
.use((wb) => cppExtension(wb, { std: 'c++20' }))
|
|
45
|
+
.use((wb) =>
|
|
46
|
+
guidedLabExtension(wb, {
|
|
47
|
+
starterFiles: { 'src/solution.js': '...' },
|
|
48
|
+
tsStarterFiles: { 'src/solution.ts': '...' },
|
|
49
|
+
cppStarterFiles: { 'src/solution.cpp': '...' },
|
|
50
|
+
steps: [...]
|
|
51
|
+
})
|
|
52
|
+
);
|
|
53
|
+
```
|
|
54
|
+
- **Backward Compatibility**: Existing `guidedLabExtension(wb, { tsStarterFiles })` or `cppStarterFiles` configs automatically add `'ts'` / `'cpp'` to `wb.enabledLanguages`.
|
|
55
|
+
2. **`LanguageIdSchema` Enum Widened**:
|
|
56
|
+
- `LanguageIdSchema` (`@innovatorved/code-lab/schemas`) is now `z.enum(['js', 'ts', 'cpp'])` (previously `z.enum(['js', 'ts'])`). TypeScript consumers switching exhaustively on `LanguageId` should handle `'cpp'`.
|
|
57
|
+
|
|
58
|
+
## [0.1.13] - 2026-10-23
|
|
59
|
+
|
|
60
|
+
### Added
|
|
61
|
+
- **System Design Chaos Engine & Port Telemetry (`src/runtime.ts`)**: Extended `VirtualPortTable` with per-port fault injection (`setChaos`, `getChaos`, `clearChaos`: latency/jitter injection, HTTP 503 error rate, and partitioned/down nodes) and rolling 60-second SLO telemetry (`recordMetric`, `getMetrics`, `getAllMetrics`: live RPS, `p50`/`p95`/`p99` latency, error rate, and upstream call graph edges).
|
|
62
|
+
- **4 System Design POSIX Coreutils (`src/shell.ts`)**: Added `hey` / `ab` / `wrk` (concurrent HTTP load generator with ASCII latency histograms and `p50`/`p90`/`p95`/`p99` percentiles), `chaos` (CLI fault injector for port latency, error rate, and partitions), `sqlite3` (interactive CLI with `.tables`, `.schema`, and `EXPLAIN QUERY PLAN`), and `redis-cli` (in-memory + VFS-persisted Redis server/CLI supporting strings, TTLs, atomic counters, lists, hashes, sets, and sorted sets).
|
|
63
|
+
- **VFS-Persisted SQLite with Secondary Indexes & Query Planner (`src/runtime.ts`)**: Added file-backed persistence (`/workspace/*.db`), `CREATE INDEX` / `DROP INDEX`, `PRAGMA index_list`, and `EXPLAIN QUERY PLAN` (`SCAN TABLE` vs `SEARCH TABLE ... USING INDEX`) to `bun:sqlite`.
|
|
64
|
+
- **Workbench SLO Telemetry Bar, Live Topology Graph & 1-Click Chaos Pills (`src/workbench.ts`, `src/code-lab.css`)**: Added live RPS/`p50`/`p95`/`p99`/Error% telemetry bar, interactive ASCII/SVG topology trace (`Client -> LB :3000 -> Worker :3001`), and 1-click Chaos pills (`+200ms Latency`, `25% HTTP 503`, `Kill Node`, `Run hey Load Test`) to the Ports & Networking panel.
|
|
65
|
+
- **Distributed System Cluster Presets (`examples/cloud-ide/src/pages/index.astro`)**: Added `Distributed Cluster & Chaos Lab` (`sd-cluster`) and `High-Scale URL Shortener` (`sd-shortener`) templates to the Cloud IDE.
|
|
66
|
+
|
|
67
|
+
## [0.1.10] - 2026-10-22
|
|
68
|
+
|
|
69
|
+
### Fixed
|
|
70
|
+
- **Live Browser Preview CSP & React ESM Deduplication (`src/csp.ts`, `src/shell.ts`)**: Added `data:` to `script-src` in `buildPreviewPolicy` so local `.ts`/`.tsx` modules mapped via import maps execute under the preview CSP, and deduplicated the React ESM URL in `buildHtmlPreviewResponse` so `react-dom/client` and local TSX modules share a single React instance.
|
|
71
|
+
- **Right Split-Pane Preview Grid & Drawer Layout Polish (`src/code-lab.css`, `src/workbench.ts`)**: Added `.codelab-workspace.has-preview-split` 5-column grid layout, preserved preview toolbar visibility in the bottom drawer (`min-height: 0` + scroll reset), widened the split-pane URL input, and refined the `.codelab-ports-panel` column ratios.
|
|
72
|
+
|
|
73
|
+
## [0.1.9] - 2026-10-22
|
|
74
|
+
|
|
75
|
+
### Added
|
|
76
|
+
- **StackBlitz-Grade Web Preview Engine & Split-Pane Dock (`src/csp.ts`, `src/shell.ts`, `src/workbench.ts`, `src/code-lab.css`)**: Right-hand split-pane preview dock (`#cl-preview-split`, `#cl-splitter-preview`), maximize toggle, inline collapsible preview console, dynamic HTML/React/TSX bundler and local asset inliner, and sandboxed iframe loopback bridge (`fetch()`, relative `<a href>` navigation, SPA `history.pushState`/`replaceState` URL sync).
|
|
77
|
+
- **Ports Manager, Mini HTTP Client & Network Inspector UI (`src/code-lab.css`, `src/workbench.ts`)**: Complete 2-column grid layout and styling for `.codelab-ports-panel`, `.codelab-http-client`, and `.codelab-network-panel`, plus fixed event handlers for HTTP header editing and network request filtering/selection.
|
|
78
|
+
- **Durable Browser Auto-Save & Page-Refresh State Persistence (`src/workbench.ts`, `examples/cloud-ide/src/pages/index.astro`)**: Added `hasSnapshot` tracking and IndexedDB mirroring so user edits, newly created files, and deleted default files persist across page reloads, with immediate state flushing on `visibilitychange`.
|
|
79
|
+
|
|
80
|
+
## [0.1.8] - 2026-10-22
|
|
81
|
+
|
|
82
|
+
### Added
|
|
83
|
+
- **Project ZIP Export & Import (`src/zip.ts`)**: Pure TypeScript IEEE 802.3 CRC-32 + PKWARE ZIP v2.0 archive generator/extractor (`createZip`, `extractZip`, `wb.exportProjectZip()`, `wb.importProjectZip()`) with Zip-Slip path sanitization.
|
|
84
|
+
- **Cascading Workspace Storage (`src/storage.ts`)**: Durable multi-project workspace persistence cascading `IndexedDB` $\rightarrow$ `localStorage` $\rightarrow$ in-memory fallback (`WorkspaceStorage`, `createWorkspaceStorage`) with automatic quota-exceeded recovery.
|
|
85
|
+
- **Workspace-Wide Search & Replace (`src/search.ts`)**: Regex, case-sensitive, whole-word, and glob-filtered search/replace (`searchInFiles`, `replaceInFiles`, `wb.searchWorkspace()`, `wb.replaceInWorkspace()`, `wb.showSearchModal()`, `⇧⌘F`).
|
|
86
|
+
- **Diagnostics & Problems Panel (`src/diagnostics.ts`)**: Structured workspace diagnostics store (`DiagnosticsStore`, `createDiagnosticsStore`, `wb.getDiagnostics()`, `wb.showProblemsModal()`).
|
|
87
|
+
- **Source Control (SCM) Engine (`src/scm.ts`)**: Porcelain Git status, staging, unstaging, and commit creation (`createGitState`, `computeGitStatus`, `stageFile`, `unstageFile`, `commitChanges`, `wb.getGitStatus()`, `wb.showScmModal()`).
|
|
88
|
+
- **Live Preview Console Bridge, Error Overlay & Debounced Auto-Reload**: In-preview runtime error overlay (`#codelab-preview-error-overlay`), console/error `postMessage` bridge (`codelab:preview-console`, `codelab:preview-error`), 300ms debounced preview reload on editor edits, and multi-port server selector.
|
|
89
|
+
- **Multi-Session Terminal & Multi-CDN Package Fallback**: Multi-session terminal management (`createTerminalSession`, `switchTerminalSession`, `closeTerminalSession`, `listTerminalSessions`), cascading npm CDN resolution (`jsDelivr` $\rightarrow$ `unpkg` $\rightarrow$ `esm.sh`), and deterministic `/workspace/package-lock.json` v3 generation.
|
|
90
|
+
- **Shared Preview CSP Builder (`src/csp.ts`)**: Added `buildPreviewCsp`, `injectCspMeta`, `resolvePreviewCspMode`, and the `previewCsp` workbench option / `preview-csp` HTML attribute supporting `'strict'`, `'balanced'` (new default), `'permissive'`, or a custom CSP policy string across both the embedded `srcdoc` iframe and `preview-sw.js`.
|
|
91
|
+
- **Preview CSP Violation Reporting**: Injected a `securitypolicyviolation` listener into the preview bridge that forwards blocked resource details (`blockedURI`, `violatedDirective`, `effectiveDirective`, `sourceFile`, `lineNumber`) to the host workbench (`csp-violation` event and structured logger warning).
|
|
92
|
+
- **Structured Diagnostics & Error Taxonomy (`src/logger.ts`)**: Added `CodeLabError` (`code`, `context`, `cause`), `isCodeLabError`, `createLogger`, and the `logLevel` workbench option (`'silent' | 'error' | 'warn' | 'info' | 'debug'`).
|
|
93
|
+
- **Save-State Events & Quota Indicator**: Emits `save-state` (`{ state: 'saving' | 'saved' | 'failed', status, labId, error }`) and `error` (`CodeLabError('E_SAVE', ...)`) when `localStorage` persistence fails, updating `#cl-status-save` to `⚠ Save failed (session-only)` instead of falsely displaying `Saved`.
|
|
94
|
+
- **Strict SafeHtml Template Tag (`src/html.ts`)**: Added `SafeHtml`, `html`, `raw`, `isSafeHtml`, and `escapeHtml` with `Symbol.for('codelab.SafeHtml')` branding to prevent accidental unescaped DOM interpolation.
|
|
95
|
+
- **Strict TypeScript Ratchet & Empty-Catch Lint Gate**: Added `tsconfig.strict.json` (`bun run typecheck:strict`) covering all 8 strict leaf modules (`src/csp.ts`, `src/logger.ts`, `src/html.ts`, `src/zip.ts`, `src/storage.ts`, `src/search.ts`, `src/diagnostics.ts`, `src/scm.ts`), plus `tools/lint.js` (`bun run lint`) enforcing zero empty `catch` blocks and strict module coverage in CI.
|
|
96
|
+
- **Repository Governance**: Added `SECURITY.md`, `CONTRIBUTING.md`, `CHANGELOG.md`, `.github/dependabot.yml`, and `.github/workflows/release.yml` (tag-triggered npm provenance publishing).
|
|
97
|
+
|
|
98
|
+
### Fixed
|
|
99
|
+
- **Markdown Balanced-Parenthesis Link Parsing**: `renderInlineFormatting` in `src/workbench.ts` now parses balanced parentheses inside Markdown `[text](url)` destinations (e.g., Wikipedia URLs like `https://en.wikipedia.org/wiki/B-tree_(data_structure)`) and blocks `javascript:alert(1)` links without leaving trailing `)` characters in the output.
|
|
100
|
+
- **Portable Bundle-First Test Suites**: All 39 test suites now load built artifacts from `dist/` via `tests/helpers/load.js` (`assertFresh()`) and run identically under Bun and Node 20/22/24.
|
|
101
|
+
- **Documentation Capability Counts**: Synchronized `README.md` and `ARCHITECTURE.md` counts (`58` POSIX coreutils, `50` Node.js built-in modules, `39` test suites, `6-Tab Bottom Drawer`) with automated regression checks in `tests/test-version-sync.js`.
|
|
102
|
+
|
|
103
|
+
## [0.1.7] - 2026-04-19
|
|
104
|
+
|
|
105
|
+
### Added
|
|
106
|
+
- Consolidated TypeScript source tree under `src/*.ts` with deterministic single-source version injection from `package.json` (`tools/bundle.js`).
|
|
107
|
+
- Added headless runtime, POSIX shell (58 coreutils, streaming `git clone`), PTY terminal engine, and 6-tab IDE workbench with embedded and Service Worker pop-out Web Preview.
|
package/README.md
CHANGED
|
@@ -2,21 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
> **Note:** This project is in active development. APIs and sandbox internals are stable for production use.
|
|
4
4
|
|
|
5
|
-
Browser-native code IDE workbench, modular guided challenge engine (`@innovatorved/code-lab/extensions/guided-lab`), POSIX shell with
|
|
5
|
+
Browser-native code IDE workbench, modular guided challenge engine (`@innovatorved/code-lab/extensions/guided-lab`), modular language extensions (`javascript`, `typescript`, and real WebAssembly `cpp`), POSIX shell with 67 UNIX coreutils, public GitHub repository cloner (`git clone`), and Web Worker execution runtime for **Node.js**, **Bun** (JavaScript & TypeScript), and **C++20 (Clang/LLVM + WASI)** with Zod type safety and zero backend server dependencies.
|
|
6
6
|
|
|
7
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)
|
|
8
|
+
- **Built for**: [System Design In Depth](https://system-design-in-depth.vedgupta.in) & Data Structures & Algorithms (DSA) In Depth
|
|
9
9
|
|
|
10
10
|
---
|
|
11
11
|
|
|
12
12
|
## Features
|
|
13
13
|
|
|
14
|
-
- **Modular Architecture (`v0.
|
|
15
|
-
- **
|
|
14
|
+
- **Modular Architecture (`v0.2.0`)**: 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` and `@innovatorved/code-lab/extensions/cpp`) 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`). 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
|
+
- **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.
|
|
16
17
|
- **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.
|
|
17
18
|
- **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.
|
|
18
19
|
- **Interactive PTY Terminal**: Inline prompt (`codelab:/workspace$ `), cursor navigation, history (`Up`/`Down`), `Ctrl+R` reverse-i-search, `Tab` auto-completion, `Ctrl+C` interrupt, `Ctrl+L` clear, and 256-color / TrueColor ANSI support.
|
|
19
|
-
- **POSIX Shell &
|
|
20
|
+
- **POSIX Shell & 67 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 67 UNIX commands (`g++`, `clang++`, `c++`, `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.
|
|
20
21
|
- **Dual Runtime Engines (Node.js v22 & Bun v1.1)**:
|
|
21
22
|
- **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.).
|
|
22
23
|
- **Bun**: Native `.ts` transpilation, `Bun.serve()`, `Bun.file()`, `Bun.write()`, `Bun.spawn()`, `Bun.password`, `Bun.hash()`, `bun:test`, and VFS-backed `bun:sqlite`.
|
|
@@ -113,6 +114,44 @@ const res = await executeInWorker({
|
|
|
113
114
|
console.log(res.ok, res.testResults);
|
|
114
115
|
```
|
|
115
116
|
|
|
117
|
+
### 4. Modular Language Extensions (TypeScript & Real C++20 in WebAssembly)
|
|
118
|
+
|
|
119
|
+
JavaScript (`node` and `bun` zero-dependency browser runtime) is enabled out of the box. You can opt into TypeScript (`@innovatorved/code-lab/extensions/typescript`) and/or Real C++20 in WebAssembly (`@innovatorved/code-lab/extensions/cpp`):
|
|
120
|
+
|
|
121
|
+
```js
|
|
122
|
+
import CodeLab from '@innovatorved/code-lab';
|
|
123
|
+
import { typescriptExtension } from '@innovatorved/code-lab/extensions/typescript';
|
|
124
|
+
import { cppExtension } from '@innovatorved/code-lab/extensions/cpp';
|
|
125
|
+
import { guidedLabExtension } from '@innovatorved/code-lab/extensions/guided-lab';
|
|
126
|
+
|
|
127
|
+
const lab = CodeLab.mount('#editor', {
|
|
128
|
+
id: 'dsa-binary-search',
|
|
129
|
+
title: 'Binary Search (JS / TS / C++20)',
|
|
130
|
+
language: 'cpp'
|
|
131
|
+
})
|
|
132
|
+
.use(typescriptExtension)
|
|
133
|
+
.use((wb) => cppExtension(wb, { std: 'c++20', cacheInIndexedDB: true }))
|
|
134
|
+
.use((wb) =>
|
|
135
|
+
guidedLabExtension(wb, {
|
|
136
|
+
starterFiles: { 'src/solution.js': 'module.exports = { search: () => -1 };\n' },
|
|
137
|
+
tsStarterFiles: { 'src/solution.ts': 'export const search = (nums: number[], target: number): number => -1;\n' },
|
|
138
|
+
cppStarterFiles: {
|
|
139
|
+
'src/solution.hpp': '#pragma once\n#include <bits/stdc++.h>\nint search(const std::vector<int>& nums, int target) { return -1; }\n',
|
|
140
|
+
'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'
|
|
141
|
+
},
|
|
142
|
+
steps: [
|
|
143
|
+
{
|
|
144
|
+
id: 'step-1',
|
|
145
|
+
title: 'Implement O(log N) binary search',
|
|
146
|
+
targetFile: 'src/solution.hpp',
|
|
147
|
+
instructions: 'Return the index of `target` in `nums`, or `-1` if not found.',
|
|
148
|
+
testNames: ['finds target']
|
|
149
|
+
}
|
|
150
|
+
]
|
|
151
|
+
})
|
|
152
|
+
);
|
|
153
|
+
```
|
|
154
|
+
|
|
116
155
|
---
|
|
117
156
|
|
|
118
157
|
## Documentation
|
|
@@ -122,7 +161,7 @@ Complete documentation is published on the [GitHub Wiki](https://github.com/inno
|
|
|
122
161
|
- **[Quick Start](https://github.com/innovatorved/code-lab/wiki/Quick-Start)**: Setup, CDN, and quick examples.
|
|
123
162
|
- **[Integration Guide](https://github.com/innovatorved/code-lab/wiki/Integration-Guide)**: Embedding in React, Next.js, Vite, and HTML.
|
|
124
163
|
- **[Workbench Configuration](https://github.com/innovatorved/code-lab/wiki/Workbench-Configuration)**: Complete reference of options, methods, events, and shortcuts.
|
|
125
|
-
- **[POSIX Shell & Coreutils](https://github.com/innovatorved/code-lab/wiki/POSIX-Shell-and-Coreutils)**: Pipelines, redirects, background jobs, and
|
|
164
|
+
- **[POSIX Shell & Coreutils](https://github.com/innovatorved/code-lab/wiki/POSIX-Shell-and-Coreutils)**: Pipelines, redirects, background jobs, and 67 UNIX commands.
|
|
126
165
|
- **[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.
|
|
127
166
|
- **[HTTP Servers & Networking](https://github.com/innovatorved/code-lab/wiki/HTTP-Servers-and-Networking)**: Virtual port table, background servers, `curl`, and Port Preview.
|
|
128
167
|
- **[Headless Runtime](https://github.com/innovatorved/code-lab/wiki/Headless-Runtime)**: Run code and tests programmatically with zero UI.
|
|
@@ -146,15 +185,16 @@ bun run tests/test-all-builds.js # 15/15 builds & 226 unit tests
|
|
|
146
185
|
bun run tests/test-runtime-advanced.js # Advanced runtime, VFS, HTTP/TCP
|
|
147
186
|
bun run tests/test-option1-shell-bun-http.js # Shell AST, Bun runtime, curl, ports, npm/pnpm
|
|
148
187
|
bun run tests/test-frameworks.js # React/Preact/Vue/Angular support + browser preview server
|
|
149
|
-
bun run tests/test-coreutils-adversarial.js # Adversarial stress tests on
|
|
188
|
+
bun run tests/test-coreutils-adversarial.js # Adversarial stress tests on 67 coreutils
|
|
150
189
|
bun run tests/test-stress-shell.js # Deep pipelines, redirections, large stdout
|
|
151
190
|
bun run tests/test-workbench-ui.js # Workbench tabs, explorer, shortcuts
|
|
191
|
+
bun run tests/test-cpp-extension.js # Real C++20 WASI runtime, g++, and language extensions
|
|
152
192
|
```
|
|
153
193
|
|
|
154
194
|
Individual suites also run under Node 20, 22 and 24 — CI exercises all three:
|
|
155
195
|
|
|
156
196
|
```bash
|
|
157
|
-
bun run build && node tests/run-all.js # same
|
|
197
|
+
bun run build && node tests/run-all.js # same 41 suites, Node runtime
|
|
158
198
|
```
|
|
159
199
|
|
|
160
200
|
Suites load the built bundles from `dist/` (never raw TypeScript from `src/`), so
|
package/dist/code-lab.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* TypeScript Definitions for @innovatorved/code-lab v0.
|
|
2
|
+
* TypeScript Definitions for @innovatorved/code-lab v0.2.0
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
export interface CodeLabStep {
|
|
@@ -334,9 +334,11 @@ export interface CodeLabOptions {
|
|
|
334
334
|
previewOrigin?: string;
|
|
335
335
|
/** Initial workbench mode ('guided' | 'sandbox') */
|
|
336
336
|
mode?: 'guided' | 'sandbox';
|
|
337
|
-
/** Initial workspace language ('js' | 'ts') */
|
|
338
|
-
language?: 'js' | 'ts';
|
|
339
|
-
lang?: 'js' | 'ts';
|
|
337
|
+
/** Initial workspace language ('js' | 'ts' | 'cpp') */
|
|
338
|
+
language?: 'js' | 'ts' | 'cpp';
|
|
339
|
+
lang?: 'js' | 'ts' | 'cpp';
|
|
340
|
+
/** Enabled languages in the language switcher */
|
|
341
|
+
languages?: Array<'js' | 'ts' | 'cpp'>;
|
|
340
342
|
/** Explicit theme override ('dark' | 'light' | 'auto') */
|
|
341
343
|
theme?: 'dark' | 'light' | 'auto';
|
|
342
344
|
/** Set to false to disable localStorage persistence and use in-memory state only */
|
|
@@ -361,12 +363,21 @@ export interface CodeLabOptions {
|
|
|
361
363
|
tsSolutionFiles?: Record<string, string>;
|
|
362
364
|
/** Explicit TypeScript starter files map for guided mode */
|
|
363
365
|
tsStarterFiles?: Record<string, string>;
|
|
366
|
+
/** Explicit C++ files map for sandbox mode */
|
|
367
|
+
cppFiles?: Record<string, string>;
|
|
368
|
+
cppSolutionFiles?: Record<string, string>;
|
|
369
|
+
/** Explicit C++ starter files map for guided mode */
|
|
370
|
+
cppStarterFiles?: Record<string, string>;
|
|
371
|
+
/** Modular extensions or plugins to install on mount */
|
|
372
|
+
extensions?: Array<any>;
|
|
373
|
+
plugins?: Array<any>;
|
|
364
374
|
/** Ordered guided steps */
|
|
365
375
|
steps?: CodeLabStep[];
|
|
366
376
|
/** Guided configuration object */
|
|
367
377
|
guided?: {
|
|
368
378
|
starterFiles?: Record<string, string>;
|
|
369
379
|
tsStarterFiles?: Record<string, string>;
|
|
380
|
+
cppStarterFiles?: Record<string, string>;
|
|
370
381
|
steps?: CodeLabStep[];
|
|
371
382
|
};
|
|
372
383
|
/** Initial active step index (0-based) */
|
|
@@ -405,7 +416,8 @@ export declare class CodeLabWorkbench {
|
|
|
405
416
|
openTabs: string[];
|
|
406
417
|
activeFile: string | null;
|
|
407
418
|
mode: 'guided' | 'sandbox';
|
|
408
|
-
lang: 'js' | 'ts';
|
|
419
|
+
lang: 'js' | 'ts' | 'cpp';
|
|
420
|
+
enabledLanguages: Set<'js' | 'ts' | 'cpp'>;
|
|
409
421
|
activeStepIndex: number;
|
|
410
422
|
completedSteps: Set<string>;
|
|
411
423
|
steps: CodeLabStep[];
|
|
@@ -437,9 +449,9 @@ export declare class CodeLabWorkbench {
|
|
|
437
449
|
deleteFile(filename: string): boolean;
|
|
438
450
|
deleteFolder(folderPrefix: string): boolean;
|
|
439
451
|
setMode(newMode: 'guided' | 'sandbox'): void;
|
|
440
|
-
setLanguage(newLang: 'js' | 'ts'): void;
|
|
452
|
+
setLanguage(newLang: 'js' | 'ts' | 'cpp'): void;
|
|
441
453
|
switchDrawerTab(tabName: 'tests' | 'terminal' | 'ports' | 'network' | 'inspector'): void;
|
|
442
|
-
configure(opts?: { mode?: 'guided' | 'sandbox'; lang?: 'js' | 'ts'; stepIndex?: number }): void;
|
|
454
|
+
configure(opts?: { mode?: 'guided' | 'sandbox'; lang?: 'js' | 'ts' | 'cpp'; stepIndex?: number }): void;
|
|
443
455
|
openCommandPalette(mode?: 'commands' | 'files'): void;
|
|
444
456
|
closeCommandPalette(): void;
|
|
445
457
|
openContextMenu(x: number, y: number, items: Array<{ label?: string; action?: () => void; danger?: boolean; separator?: boolean }>): void;
|