@innovatorved/code-lab 0.7.0 → 0.7.2

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 (159) hide show
  1. package/ARCHITECTURE.md +2 -2
  2. package/CHANGELOG.md +30 -0
  3. package/README.md +6 -6
  4. package/dist/code-lab-sql.esm.js +19 -19
  5. package/dist/code-lab-sql.umd.js +20 -20
  6. package/dist/code-lab.css +1 -1
  7. package/dist/code-lab.d.ts +47 -38
  8. package/dist/code-lab.esm.js +1183 -1909
  9. package/dist/code-lab.js +1182 -1906
  10. package/dist/extensions/cpp.esm.js +132 -8760
  11. package/dist/extensions/cpp.js +124 -8770
  12. package/dist/extensions/guided-lab.esm.js +33 -6836
  13. package/dist/extensions/guided-lab.js +33 -6854
  14. package/dist/extensions/javascript.esm.js +1 -36
  15. package/dist/extensions/javascript.js +1 -58
  16. package/dist/extensions/python.esm.js +113 -8122
  17. package/dist/extensions/python.js +113 -8140
  18. package/dist/extensions/typescript.esm.js +1 -55
  19. package/dist/extensions/typescript.js +1 -77
  20. package/dist/index.d.ts +1 -1
  21. package/dist/logger.d.ts +4 -20
  22. package/dist/modular-kernel.d.ts +0 -5
  23. package/dist/packages/core/src/errors.d.ts +5 -1
  24. package/dist/packages/fs/src/backends.d.ts +0 -27
  25. package/dist/packages/fs/src/index.d.ts +1 -1
  26. package/dist/packages/ui/src/html.d.ts +1 -0
  27. package/dist/packages/ui/src/index.d.ts +1 -0
  28. package/dist/{apps/web/src/index.d.ts → packages/ui/src/kernel.d.ts} +3 -11
  29. package/dist/packages/ui/src/observability.d.ts +1 -1
  30. package/dist/packages/ui/src/settings-dialog.d.ts +0 -1
  31. package/dist/preview-sw.js +1 -1
  32. package/dist/runtime.d.ts +3 -0
  33. package/dist/runtime.esm.js +78 -78
  34. package/dist/runtime.js +78 -78
  35. package/dist/schemas.d.ts +10 -1
  36. package/dist/schemas.esm.js +33 -6815
  37. package/dist/schemas.js +33 -6831
  38. package/dist/shell.esm.js +277 -285
  39. package/dist/shell.js +277 -285
  40. package/dist/terminal.esm.js +9 -7
  41. package/dist/terminal.js +7 -7
  42. package/dist/workbench/command-palette.d.ts +0 -4
  43. package/dist/workbench/editor.d.ts +0 -4
  44. package/dist/workbench/index.d.ts +0 -22
  45. package/dist/workbench/intellisense.d.ts +1 -8
  46. package/dist/workbench/xterm-adapter.d.ts +0 -1
  47. package/package.json +4 -13
  48. package/dist/code-lab.umd.js +0 -6117
  49. package/dist/packages/editor/src/index.d.ts +0 -118
  50. package/dist/packages/preview/src/index.d.ts +0 -34
  51. package/dist/packages/runtime/src/index.d.ts +0 -47
  52. package/dist/packages/terminal/src/index.d.ts +0 -54
  53. package/dist/workbench/drawer.d.ts +0 -18
  54. package/dist/workbench/file-tree.d.ts +0 -11
  55. package/dist/workbench/guided-pane.d.ts +0 -11
  56. package/dist/workbench/styles.d.ts +0 -4
  57. package/dist/workbench/toolbar.d.ts +0 -17
  58. package/packages/commands/README.md +0 -7
  59. package/packages/commands/package.json +0 -16
  60. package/packages/commands/src/index.ts +0 -467
  61. package/packages/commands/tsconfig.json +0 -22
  62. package/packages/core/README.md +0 -12
  63. package/packages/core/package.json +0 -13
  64. package/packages/core/src/di.ts +0 -147
  65. package/packages/core/src/disposable.ts +0 -112
  66. package/packages/core/src/errors.ts +0 -205
  67. package/packages/core/src/events.ts +0 -157
  68. package/packages/core/src/index.ts +0 -49
  69. package/packages/core/src/path.ts +0 -118
  70. package/packages/core/src/registry.ts +0 -61
  71. package/packages/core/tsconfig.json +0 -19
  72. package/packages/editor/README.md +0 -9
  73. package/packages/editor/package.json +0 -18
  74. package/packages/editor/src/index.ts +0 -344
  75. package/packages/editor/tsconfig.json +0 -24
  76. package/packages/fs/README.md +0 -7
  77. package/packages/fs/package.json +0 -16
  78. package/packages/fs/src/backends.ts +0 -301
  79. package/packages/fs/src/index.ts +0 -18
  80. package/packages/fs/src/types.ts +0 -44
  81. package/packages/fs/src/vfs-service.ts +0 -257
  82. package/packages/fs/tsconfig.json +0 -22
  83. package/packages/preview/README.md +0 -3
  84. package/packages/preview/package.json +0 -16
  85. package/packages/preview/src/index.ts +0 -125
  86. package/packages/preview/tsconfig.json +0 -22
  87. package/packages/runtime/README.md +0 -3
  88. package/packages/runtime/package.json +0 -17
  89. package/packages/runtime/src/index.ts +0 -134
  90. package/packages/runtime/tsconfig.json +0 -23
  91. package/packages/settings/README.md +0 -7
  92. package/packages/settings/package.json +0 -16
  93. package/packages/settings/src/builtin-schemas.ts +0 -262
  94. package/packages/settings/src/configuration-service.ts +0 -609
  95. package/packages/settings/src/index.ts +0 -38
  96. package/packages/settings/src/jsonc.ts +0 -189
  97. package/packages/settings/src/schema.ts +0 -164
  98. package/packages/settings/tsconfig.json +0 -22
  99. package/packages/sql/README.md +0 -12
  100. package/packages/sql/package.json +0 -13
  101. package/packages/sql/src/completions.ts +0 -359
  102. package/packages/sql/src/diagnostics.ts +0 -200
  103. package/packages/sql/src/formatter.ts +0 -271
  104. package/packages/sql/src/index.ts +0 -54
  105. package/packages/sql/src/sql-editor.ts +0 -802
  106. package/packages/sql/src/styles.ts +0 -524
  107. package/packages/sql/src/tokenizer.ts +0 -457
  108. package/packages/sql/src/types.ts +0 -148
  109. package/packages/sql/tsconfig.json +0 -19
  110. package/packages/terminal/README.md +0 -3
  111. package/packages/terminal/package.json +0 -16
  112. package/packages/terminal/src/index.ts +0 -183
  113. package/packages/terminal/tsconfig.json +0 -22
  114. package/packages/ui/README.md +0 -8
  115. package/packages/ui/package.json +0 -18
  116. package/packages/ui/src/index.ts +0 -40
  117. package/packages/ui/src/observability.ts +0 -173
  118. package/packages/ui/src/plugin-registry.ts +0 -289
  119. package/packages/ui/src/settings-dialog.ts +0 -939
  120. package/packages/ui/src/themes.ts +0 -333
  121. package/packages/ui/tsconfig.json +0 -24
  122. package/src/code-lab.css +0 -8584
  123. package/src/csp.ts +0 -590
  124. package/src/diagnostics.ts +0 -287
  125. package/src/extensions/cpp.ts +0 -2389
  126. package/src/extensions/guided-lab.ts +0 -64
  127. package/src/extensions/javascript.ts +0 -54
  128. package/src/extensions/python.ts +0 -1737
  129. package/src/extensions/typescript.ts +0 -85
  130. package/src/extensions/umbrella.ts +0 -5
  131. package/src/html.ts +0 -88
  132. package/src/index.ts +0 -129
  133. package/src/logger.ts +0 -139
  134. package/src/modular-kernel.ts +0 -11
  135. package/src/preview-sw.js +0 -296
  136. package/src/runtime/test-harness.ts +0 -57
  137. package/src/runtime.ts +0 -10480
  138. package/src/sample.html +0 -304
  139. package/src/schemas.ts +0 -366
  140. package/src/scm.ts +0 -2453
  141. package/src/search.ts +0 -433
  142. package/src/shell.ts +0 -10987
  143. package/src/storage.ts +0 -773
  144. package/src/terminal.ts +0 -1400
  145. package/src/workbench/command-palette.ts +0 -381
  146. package/src/workbench/diff-editor.ts +0 -470
  147. package/src/workbench/drawer.ts +0 -157
  148. package/src/workbench/editor.ts +0 -49
  149. package/src/workbench/file-tree.ts +0 -51
  150. package/src/workbench/guided-pane.ts +0 -43
  151. package/src/workbench/icons.ts +0 -255
  152. package/src/workbench/index.ts +0 -44
  153. package/src/workbench/intellisense.ts +0 -1871
  154. package/src/workbench/share.ts +0 -128
  155. package/src/workbench/styles.ts +0 -211
  156. package/src/workbench/toolbar.ts +0 -182
  157. package/src/workbench/xterm-adapter.ts +0 -1571
  158. package/src/workbench.ts +0 -22132
  159. package/src/zip.ts +0 -348
package/src/sample.html DELETED
@@ -1,304 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en" data-theme="dark">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
- <title>@innovatorved/code-lab — Standalone IDE Workbench</title>
7
- <link rel="stylesheet" href="./code-lab.css" />
8
- <style>
9
- *, *::before, *::after {
10
- box-sizing: border-box;
11
- }
12
- html, body {
13
- margin: 0;
14
- padding: 0;
15
- width: 100%;
16
- height: 100%;
17
- overflow: hidden;
18
- background: #000000;
19
- color: #ffffff;
20
- font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
21
- }
22
- #app {
23
- width: 100vw;
24
- height: 100vh;
25
- display: flex;
26
- flex-direction: column;
27
- }
28
- #app .codelab {
29
- height: 100%;
30
- max-height: 100%;
31
- border: none;
32
- border-radius: 0;
33
- }
34
- #app .codelab,
35
- #app .codelab-workbench {
36
- width: 100%;
37
- height: 100%;
38
- min-height: 100%;
39
- max-height: 100%;
40
- border-radius: 0;
41
- border: none;
42
- }
43
- </style>
44
- </head>
45
- <body>
46
- <!-- Standalone sample UI embedding the <code-lab> workbench -->
47
- <div id="app"></div>
48
-
49
- <script src="./code-lab.js"></script>
50
- <script>
51
- (function () {
52
- const limiterCode = [
53
- "/**",
54
- " * Sliding Window Log Rate Limiter",
55
- " * Tracks request timestamps within a sliding time window.",
56
- " */",
57
- "class SlidingWindowLimiter {",
58
- " constructor(limit = 5, windowMs = 10000) {",
59
- " this.limit = limit;",
60
- " this.windowMs = windowMs;",
61
- " this.logs = [];",
62
- " }",
63
- "",
64
- " allowRequest(now = Date.now()) {",
65
- " const windowStart = now - this.windowMs;",
66
- " // Evict timestamps outside the current sliding window",
67
- " this.logs = this.logs.filter(timestamp => timestamp > windowStart);",
68
- "",
69
- " if (this.logs.length < this.limit) {",
70
- " this.logs.push(now);",
71
- " return {",
72
- " allowed: true,",
73
- " remaining: this.limit - this.logs.length,",
74
- " limit: this.limit,",
75
- " resetMs: this.logs.length > 0 ? Math.max(0, (this.logs[0] + this.windowMs) - now) : this.windowMs",
76
- " };",
77
- " }",
78
- "",
79
- " const oldest = this.logs[0];",
80
- " const retryAfterMs = Math.max(0, (oldest + this.windowMs) - now);",
81
- " return {",
82
- " allowed: false,",
83
- " remaining: 0,",
84
- " limit: this.limit,",
85
- " retryAfterMs",
86
- " };",
87
- " }",
88
- "",
89
- " reset() {",
90
- " this.logs = [];",
91
- " }",
92
- "}",
93
- "",
94
- "module.exports = { SlidingWindowLimiter, RateLimiter: SlidingWindowLimiter };"
95
- ].join('\n');
96
-
97
- const serverCode = [
98
- "const http = require('node:http');",
99
- "const { SlidingWindowLimiter } = require('./limiter');",
100
- "",
101
- "const limiters = new Map();",
102
- "",
103
- "function getLimiter(clientKey) {",
104
- " if (!limiters.has(clientKey)) {",
105
- " // 5 requests per 10-second sliding window",
106
- " limiters.set(clientKey, new SlidingWindowLimiter(5, 10000));",
107
- " }",
108
- " return limiters.get(clientKey);",
109
- "}",
110
- "",
111
- "const server = http.createServer((req, res) => {",
112
- " const url = new URL(req.url, 'http://localhost:3000');",
113
- " const clientKey = url.searchParams.get('client') || 'anonymous';",
114
- " const limiter = getLimiter(clientKey);",
115
- " const decision = limiter.allowRequest();",
116
- "",
117
- " if (url.pathname === '/health') {",
118
- " res.writeHead(200, { 'Content-Type': 'application/json' });",
119
- " res.end(JSON.stringify({ status: 'ok', uptime: process.uptime() }));",
120
- " return;",
121
- " }",
122
- "",
123
- " if (decision.allowed) {",
124
- " res.writeHead(200, {",
125
- " 'Content-Type': 'application/json',",
126
- " 'X-RateLimit-Limit': String(decision.limit),",
127
- " 'X-RateLimit-Remaining': String(decision.remaining)",
128
- " });",
129
- " res.end(JSON.stringify({",
130
- " status: 'success',",
131
- " client: clientKey,",
132
- " message: 'Request allowed by sliding window limiter',",
133
- " remaining: decision.remaining",
134
- " }, null, 2));",
135
- " } else {",
136
- " res.writeHead(429, {",
137
- " 'Content-Type': 'application/json',",
138
- " 'Retry-After': String(Math.ceil(decision.retryAfterMs / 1000)),",
139
- " 'X-RateLimit-Limit': String(decision.limit),",
140
- " 'X-RateLimit-Remaining': '0'",
141
- " });",
142
- " res.end(JSON.stringify({",
143
- " status: 'rate_limited',",
144
- " client: clientKey,",
145
- " error: 'Too Many Requests',",
146
- " retryAfterMs: decision.retryAfterMs",
147
- " }, null, 2));",
148
- " }",
149
- "});",
150
- "",
151
- "server.listen(3000, () => {",
152
- " console.log('Sliding Window Rate Limiter HTTP Server listening on http://localhost:3000');",
153
- " console.log('Available endpoints:');",
154
- " console.log(' curl http://localhost:3000/');",
155
- " console.log(' curl \"http://localhost:3000/?client=user_1\"');",
156
- " console.log(' curl http://localhost:3000/health');",
157
- "});"
158
- ].join('\n');
159
-
160
- const demoCode = [
161
- "const { SlidingWindowLimiter } = require('./limiter');",
162
- "",
163
- "console.log('=== Sliding Window Rate Limiter Demo ===\\n');",
164
- "",
165
- "const limiter = new SlidingWindowLimiter(3, 2000); // 3 requests per 2-second window",
166
- "const baseTime = 10000;",
167
- "",
168
- "console.log('Configuration: Limit = 3 requests per 2000ms window\\n');",
169
- "",
170
- "for (let i = 1; i <= 5; i++) {",
171
- " const now = baseTime + (i * 100);",
172
- " const decision = limiter.allowRequest(now);",
173
- " const status = decision.allowed",
174
- " ? ('ALLOWED (remaining: ' + decision.remaining + ')')",
175
- " : ('BLOCKED (retryAfter: ' + decision.retryAfterMs + 'ms)');",
176
- " console.log('[Req #' + i + '] t = ' + now + 'ms -> ' + status);",
177
- "}",
178
- "",
179
- "console.log('\\n--- Advancing time past window expiration (+2500ms) ---');",
180
- "const afterExpiry = limiter.allowRequest(baseTime + 2500);",
181
- "console.log('[Req #6] t = ' + (baseTime + 2500) + 'ms -> ' + (afterExpiry.allowed ? ('ALLOWED (remaining: ' + afterExpiry.remaining + ')') : 'BLOCKED'));",
182
- "",
183
- "console.log('\\nDemo completed successfully. Run unit tests with `npm test` or start HTTP server with `node server.js &`.');"
184
- ].join('\n');
185
-
186
- const testCode = [
187
- "const { test, describe } = require('node:test');",
188
- "const assert = require('node:assert/strict');",
189
- "const { SlidingWindowLimiter } = require('./limiter');",
190
- "",
191
- "describe('SlidingWindowLimiter', () => {",
192
- " test('allows requests up to capacity limit', () => {",
193
- " const limiter = new SlidingWindowLimiter(3, 5000);",
194
- " const t0 = 1000;",
195
- " assert.equal(limiter.allowRequest(t0).allowed, true);",
196
- " assert.equal(limiter.allowRequest(t0 + 100).allowed, true);",
197
- " assert.equal(limiter.allowRequest(t0 + 200).allowed, true);",
198
- " });",
199
- "",
200
- " test('rejects requests when limit is exceeded within the same window', () => {",
201
- " const limiter = new SlidingWindowLimiter(2, 5000);",
202
- " const t0 = 1000;",
203
- " assert.equal(limiter.allowRequest(t0).allowed, true);",
204
- " assert.equal(limiter.allowRequest(t0 + 10).allowed, true);",
205
- " const rejected = limiter.allowRequest(t0 + 20);",
206
- " assert.equal(rejected.allowed, false);",
207
- " assert.equal(rejected.remaining, 0);",
208
- " assert.ok(rejected.retryAfterMs > 0);",
209
- " });",
210
- "",
211
- " test('slides window and re-allows requests as oldest timestamps expire', () => {",
212
- " const limiter = new SlidingWindowLimiter(2, 1000);",
213
- " const t0 = 1000;",
214
- " assert.equal(limiter.allowRequest(t0).allowed, true);",
215
- " assert.equal(limiter.allowRequest(t0 + 200).allowed, true);",
216
- " assert.equal(limiter.allowRequest(t0 + 400).allowed, false);",
217
- "",
218
- " // Oldest request at t0 expires at t0 + 1000 = 2000. At 2050, 1 slot is free.",
219
- " const res = limiter.allowRequest(2050);",
220
- " assert.equal(res.allowed, true);",
221
- " assert.equal(res.remaining, 0);",
222
- " });",
223
- "",
224
- " test('reset clears internal timestamp log', () => {",
225
- " const limiter = new SlidingWindowLimiter(1, 5000);",
226
- " limiter.allowRequest(1000);",
227
- " assert.equal(limiter.allowRequest(1001).allowed, false);",
228
- " limiter.reset();",
229
- " assert.equal(limiter.allowRequest(1002).allowed, true);",
230
- " });",
231
- "});"
232
- ].join('\n');
233
-
234
- const readmeContent = [
235
- "# Sliding Window Rate Limiter & Virtual HTTP Gateway",
236
- "",
237
- "This standalone interactive IDE runs entirely inside your browser using `@innovatorved/code-lab` with zero remote asset dependencies.",
238
- "",
239
- "## Architecture",
240
- "- **In-Memory POSIX Web Worker**: Full VFS and Node.js-compatible execution context.",
241
- "- **PTY Terminal Emulator**: Interactive shell with ANSI colors, command history, and piping.",
242
- "- **Virtual HTTP Loopback**: In-memory TCP/HTTP socket routing and real-time Port inspection.",
243
- "",
244
- "## Quick Start",
245
- "1. Click **Run Demo** in the top toolbar or run:",
246
- " ```bash",
247
- " node demo.js",
248
- " ```",
249
- "2. Run automated unit tests with **Run Tests** or run:",
250
- " ```bash",
251
- " node test.js",
252
- " ```",
253
- "3. Start the virtual HTTP server in the background:",
254
- " ```bash",
255
- " node server.js &",
256
- " ```",
257
- "4. Query the server via curl or test rate limiting:",
258
- " ```bash",
259
- " curl http://localhost:3000/",
260
- " curl \"http://localhost:3000/?client=alice\"",
261
- " curl http://localhost:3000/health",
262
- " ```",
263
- "5. Switch to the **Ports** tab in the bottom drawer to view open listening ports and send requests using the built-in Mini HTTP Client."
264
- ].join('\n');
265
-
266
- const packageJsonContent = JSON.stringify({
267
- name: "sliding-window-rate-limiter",
268
- version: "1.0.0",
269
- description: "Sliding window rate limiter with virtual HTTP server",
270
- main: "server.js",
271
- scripts: {
272
- start: "node server.js",
273
- demo: "node demo.js",
274
- test: "node --test test.js"
275
- }
276
- }, null, 2);
277
-
278
- const workbench = CodeLab.mount('#app', {
279
- id: 'code-lab-standalone-sample',
280
- title: '@innovatorved/code-lab — Standalone IDE',
281
- summary: 'Interactive in-browser IDE with virtual POSIX shell, Web Worker runtime, and HTTP loopback.',
282
- mode: 'sandbox',
283
- language: 'js',
284
- entry: 'demo.js',
285
- testEntry: 'test.js',
286
- files: {
287
- 'limiter.js': limiterCode,
288
- 'server.js': serverCode,
289
- 'demo.js': demoCode,
290
- 'test.js': testCode,
291
- 'README.md': readmeContent,
292
- 'package.json': packageJsonContent
293
- }
294
- });
295
-
296
- if (workbench && typeof workbench.switchDrawerTab === 'function') {
297
- workbench.switchDrawerTab('terminal');
298
- }
299
-
300
- window.workbench = workbench;
301
- })();
302
- </script>
303
- </body>
304
- </html>
package/src/schemas.ts DELETED
@@ -1,366 +0,0 @@
1
- import * as z from 'zod';
2
-
3
- /**
4
- * Zod Schemas and Inferred TypeScript Types for code-lab v0.7.0
5
- */
6
-
7
- // ── 1. Guided Step ──────────────────────────────────────────────────────────
8
-
9
- export const GuidedStepSchema = z.object({
10
- id: z.string().min(1),
11
- title: z.string().min(1),
12
- concept: z.string().optional(),
13
- targetFile: z.string().optional(),
14
- targetSymbol: z.string().optional(),
15
- symbol: z.string().optional(), // alias for targetSymbol
16
- instructions: z.union([z.string(), z.array(z.string())]),
17
- hint: z.string().optional(),
18
- testNames: z.array(z.string()).optional()
19
- });
20
-
21
- export type GuidedStep = z.infer<typeof GuidedStepSchema>;
22
-
23
- // ── 2. Language Bundle ──────────────────────────────────────────────────────
24
-
25
- export const LanguageIdSchema = z.enum(['js', 'ts', 'cpp', 'py']);
26
- export type LanguageId = z.infer<typeof LanguageIdSchema>;
27
- export const LanguageEnum = LanguageIdSchema;
28
-
29
- export const LanguageBundleSchema = z.object({
30
- language: LanguageIdSchema.default('js'),
31
- files: z.record(z.string(), z.string()).default({}),
32
- starterFiles: z.record(z.string(), z.string()).optional(),
33
- solutionFiles: z.record(z.string(), z.string()).optional(),
34
- entry: z.string().optional(),
35
- testEntry: z.string().optional()
36
- });
37
-
38
- export type LanguageBundle = z.infer<typeof LanguageBundleSchema>;
39
-
40
- // ── 3. Guided Lab Extension Options ─────────────────────────────────────────
41
-
42
- export const GuidedLabExtensionOptionsSchema = z.object({
43
- steps: z.array(GuidedStepSchema).default([]),
44
- stepIndex: z.number().int().nonnegative().default(0),
45
- mode: z.enum(['guided', 'sandbox']).default('guided'),
46
- language: LanguageIdSchema.optional(),
47
- lang: LanguageIdSchema.optional(),
48
- starterFiles: z.record(z.string(), z.string()).optional(),
49
- solutionFiles: z.record(z.string(), z.string()).optional(),
50
- tsStarterFiles: z.record(z.string(), z.string()).optional(),
51
- tsSolutionFiles: z.record(z.string(), z.string()).optional(),
52
- tsFiles: z.record(z.string(), z.string()).optional(),
53
- cppStarterFiles: z.record(z.string(), z.string()).optional(),
54
- cppSolutionFiles: z.record(z.string(), z.string()).optional(),
55
- cppFiles: z.record(z.string(), z.string()).optional(),
56
- pyStarterFiles: z.record(z.string(), z.string()).optional(),
57
- pySolutionFiles: z.record(z.string(), z.string()).optional(),
58
- pyFiles: z.record(z.string(), z.string()).optional(),
59
- pyEntry: z.string().optional(),
60
- pyTestEntry: z.string().optional(),
61
- pyTestCode: z.string().optional(),
62
- summary: z.string().optional(),
63
- onStepComplete: z.function({ input: [GuidedStepSchema, z.number()], output: z.void() }).optional(),
64
- onLabComplete: z.function({ input: [z.string()], output: z.void() }).optional()
65
- });
66
-
67
- export type GuidedLabExtensionOptions = z.input<typeof GuidedLabExtensionOptionsSchema>;
68
-
69
- export const CppToolchainProgressSchema = z.object({
70
- stage: z.enum(['downloading', 'caching', 'extracting', 'compiling', 'linking', 'ready', 'error']),
71
- loadedBytes: z.number().optional(),
72
- totalBytes: z.number().optional(),
73
- percent: z.number().optional(),
74
- message: z.string().optional()
75
- });
76
-
77
- export type CppToolchainProgress = z.infer<typeof CppToolchainProgressSchema>;
78
-
79
- export const CppExtensionOptionsSchema = z.object({
80
- toolchainUrl: z.string().optional(),
81
- clangWasmUrl: z.string().optional(),
82
- clangUrl: z.string().optional(),
83
- lldWasmUrl: z.string().optional(),
84
- lldUrl: z.string().optional(),
85
- sysrootTarUrl: z.string().optional(),
86
- sysrootUrl: z.string().optional(),
87
- cacheInIndexedDB: z.boolean().default(true),
88
- preload: z.boolean().default(false),
89
- std: z.enum(['c++17', 'c++20', 'c++23']).default('c++20'),
90
- optLevel: z.enum(['-O0', '-O1', '-O2', '-O3']).default('-O2'),
91
- flags: z.array(z.string()).default(['-O2', '-Wall', '-Wextra']),
92
- headers: z.record(z.string(), z.string()).optional(),
93
- extraHeaders: z.record(z.string(), z.string()).optional(),
94
- files: z.record(z.string(), z.string()).optional(),
95
- starterFiles: z.record(z.string(), z.string()).optional(),
96
- solutionFiles: z.record(z.string(), z.string()).optional(),
97
- onProgress: z.function({ input: [z.any()], output: z.void() }).optional()
98
- });
99
-
100
- export type CppExtensionOptions = z.input<typeof CppExtensionOptionsSchema>;
101
-
102
- export const PythonToolchainProgressSchema = z.object({
103
- stage: z.enum(['downloading', 'caching', 'extracting', 'initializing', 'ready']),
104
- loadedBytes: z.number().optional(),
105
- totalBytes: z.number().optional(),
106
- percent: z.number().optional(),
107
- message: z.string().optional()
108
- });
109
-
110
- export type PythonToolchainProgress = z.infer<typeof PythonToolchainProgressSchema>;
111
-
112
- export const PythonExtensionOptionsSchema = z.object({
113
- cdnBaseUrl: z.string().optional(),
114
- indexUrl: z.string().optional(),
115
- pyodideIndexUrl: z.string().optional(),
116
- cacheInIndexedDB: z.boolean().default(true),
117
- preload: z.boolean().default(false),
118
- activate: z.boolean().optional(),
119
- entry: z.string().default('main.py'),
120
- testEntry: z.string().default('test.py'),
121
- packages: z.array(z.string()).optional(),
122
- preloadPackages: z.array(z.string()).optional(),
123
- compilerMemoryLimitMb: z.number().optional(),
124
- files: z.record(z.string(), z.string()).optional(),
125
- starterFiles: z.record(z.string(), z.string()).optional(),
126
- solutionFiles: z.record(z.string(), z.string()).optional(),
127
- onProgress: z.function({ input: [z.any()], output: z.void() }).optional()
128
- });
129
-
130
- export type PythonExtensionOptions = z.input<typeof PythonExtensionOptionsSchema>;
131
-
132
- // ── 4. GitHub Clone Options & Progress ──────────────────────────────────────
133
-
134
- export const CloneProgressPhaseSchema = z.enum([
135
- 'connecting',
136
- 'metadata',
137
- 'downloading',
138
- 'mounting',
139
- 'ready',
140
- 'error'
141
- ]);
142
-
143
- export type CloneProgressPhase = z.infer<typeof CloneProgressPhaseSchema>;
144
-
145
- export const CloneProgressEventSchema = z.object({
146
- phase: CloneProgressPhaseSchema,
147
- message: z.string(),
148
- loaded: z.number().optional(),
149
- total: z.number().optional()
150
- });
151
-
152
- export type CloneProgressEvent = z.infer<typeof CloneProgressEventSchema>;
153
-
154
- export const GitHubCloneOptionsSchema = z.object({
155
- intoRoot: z.boolean().default(true),
156
- targetDir: z.string().default('/workspace'),
157
- branch: z.string().optional(),
158
- depth: z.number().int().positive().optional(),
159
- maxFiles: z.number().int().positive().default(2000),
160
- maxFileSize: z.number().int().positive().default(5 * 1024 * 1024),
161
- concurrency: z.number().int().positive().default(8),
162
- clearExisting: z.boolean().default(false),
163
- onProgress: z.function({ input: [z.any()], output: z.void() }).optional(),
164
- fetchImpl: z.any().optional()
165
- });
166
-
167
- export type GitHubCloneOptions = z.input<typeof GitHubCloneOptionsSchema>;
168
-
169
- // ── 5. Runtime Execution Options ────────────────────────────────────────────
170
-
171
- export const RuntimeExecuteOptionsSchema = z.object({
172
- files: z.record(z.string(), z.string()).optional(),
173
- entry: z.string().optional(),
174
- mode: z.enum(['run', 'test', 'repl']).default('run'),
175
- replCode: z.string().optional(),
176
- printReplResult: z.boolean().optional(),
177
- testFilter: z.union([z.string(), z.array(z.string()), z.null()]).optional(),
178
- timeoutMs: z.number().positive().default(30000),
179
- maxOutputBytes: z.number().positive().default(256 * 1024),
180
- maxConsoleCalls: z.number().positive().default(5000),
181
- instanceId: z.string().optional(),
182
- concurrent: z.boolean().optional(),
183
- argv: z.union([z.array(z.string()), z.null()]).optional(),
184
- pid: z.number().int().optional(),
185
- isBackground: z.boolean().optional(),
186
- vfs: z.any().optional(),
187
- activePortTable: z.any().optional(),
188
- packages: z.record(z.string(), z.any()).optional(),
189
- npmModules: z.record(z.string(), z.any()).optional(),
190
- onStdout: z.function({ input: [z.string()], output: z.void() }).optional(),
191
- onStderr: z.function({ input: [z.string()], output: z.void() }).optional(),
192
- onTestResult: z.function({ input: [z.any()], output: z.void() }).optional()
193
- });
194
-
195
- export type RuntimeExecuteOptions = z.input<typeof RuntimeExecuteOptionsSchema>;
196
-
197
- // ── 6. Workspace Snapshot ───────────────────────────────────────────────────
198
-
199
- export const WorkspaceSnapshotSchema = z.object({
200
- version: z.number().default(1),
201
- timestamp: z.number().optional(),
202
- files: z.record(z.string(), z.string()),
203
- openTabs: z.array(z.string()).default([]),
204
- activeFile: z.string().nullable().optional(),
205
- mode: z.enum(['guided', 'sandbox']).optional(),
206
- lang: LanguageIdSchema.optional(),
207
- labId: z.string().optional()
208
- });
209
-
210
- export type WorkspaceSnapshot = z.infer<typeof WorkspaceSnapshotSchema>;
211
-
212
- // ── 7. Workbench Options ────────────────────────────────────────────────────
213
-
214
- export const WorkbenchOptionsSchema = z.object({
215
- id: z.string().optional(),
216
- labId: z.string().optional(),
217
- buildId: z.string().optional(),
218
- title: z.string().default('code-lab'),
219
- summary: z.string().optional(),
220
- theme: z.enum(['dark', 'light', 'high-contrast', 'auto']).default('auto'),
221
- persistState: z.boolean().default(true),
222
- repo: z.string().optional(),
223
- githubRepo: z.string().optional(),
224
- branch: z.string().optional(),
225
- files: z.record(z.string(), z.string()).default({}),
226
- entry: z.string().default('demo.js'),
227
- testEntry: z.string().default('test.js'),
228
- testFile: z.string().optional(),
229
- backLabel: z.string().default('Back'),
230
- monacoUrl: z.string().optional(),
231
- previewOrigin: z.string().optional(),
232
- logger: z.any().optional(),
233
- debug: z.boolean().optional(),
234
- onClose: z.function({ input: [], output: z.void() }).optional(),
235
- onRun: z.function({ input: [z.any()], output: z.void() }).optional(),
236
- onTestResult: z.function({ input: [z.any()], output: z.void() }).optional(),
237
- onCodeChange: z.function({ input: [z.string(), z.string()], output: z.void() }).optional(),
238
- plugins: z.array(z.any()).optional(),
239
- extensions: z.array(z.any()).optional(),
240
- // Backward-compatible guided lab properties:
241
- steps: z.array(GuidedStepSchema).optional(),
242
- starterFiles: z.record(z.string(), z.string()).optional(),
243
- solutionFiles: z.record(z.string(), z.string()).optional(),
244
- tsFiles: z.record(z.string(), z.string()).optional(),
245
- tsStarterFiles: z.record(z.string(), z.string()).optional(),
246
- tsSolutionFiles: z.record(z.string(), z.string()).optional(),
247
- cppFiles: z.record(z.string(), z.string()).optional(),
248
- cppStarterFiles: z.record(z.string(), z.string()).optional(),
249
- cppSolutionFiles: z.record(z.string(), z.string()).optional(),
250
- pyFiles: z.record(z.string(), z.string()).optional(),
251
- pyStarterFiles: z.record(z.string(), z.string()).optional(),
252
- pySolutionFiles: z.record(z.string(), z.string()).optional(),
253
- pyEntry: z.string().optional().default('main.py'),
254
- pyTestEntry: z.string().optional().default('test.py'),
255
- pyTestCode: z.string().optional(),
256
- showWebPreview: z.boolean().optional(),
257
- stdin: z.string().optional(),
258
- guided: z.any().optional(),
259
- mode: z.enum(['guided', 'sandbox']).optional(),
260
- language: LanguageIdSchema.optional(),
261
- lang: LanguageIdSchema.optional(),
262
- showLanguageSelector: z.boolean().optional(),
263
- sqlDialect: z.enum(['postgres', 'sqlite']).optional(),
264
- sqlFiles: z.record(z.string(), z.string()).optional(),
265
- settings: z.record(z.string(), z.any()).optional(),
266
- userSettings: z.record(z.string(), z.any()).optional(),
267
- defaultSettings: z.record(z.string(), z.any()).optional(),
268
- config: z.record(z.string(), z.any()).optional(),
269
- overrides: z.record(z.string(), z.any()).optional(),
270
- lockSettings: z.boolean().optional(),
271
- stepIndex: z.number().int().optional(),
272
- onStepComplete: z.function({ input: [z.any(), z.number()], output: z.void() }).optional(),
273
- onLabComplete: z.function({ input: [z.string()], output: z.void() }).optional()
274
- });
275
-
276
- export type WorkbenchOptions = z.input<typeof WorkbenchOptionsSchema>;
277
-
278
- // ── 8. Search Options & Match Results ────────────────────────────────────────
279
-
280
- export const SearchOptionsSchema = z.object({
281
- query: z.string().default(''),
282
- caseSensitive: z.boolean().optional().default(false),
283
- wholeWord: z.boolean().optional().default(false),
284
- regex: z.boolean().optional().default(false),
285
- isRegex: z.boolean().optional().default(false),
286
- include: z.string().optional(),
287
- includeGlob: z.string().optional(),
288
- includePattern: z.union([z.string(), z.array(z.string())]).optional(),
289
- exclude: z.string().optional(),
290
- excludeGlob: z.string().optional(),
291
- excludePattern: z.union([z.string(), z.array(z.string())]).optional(),
292
- maxMatches: z.number().int().positive().optional(),
293
- maxMatchesPerFile: z.number().int().positive().optional()
294
- });
295
-
296
- export type SearchOptions = z.input<typeof SearchOptionsSchema>;
297
-
298
- // ── 9. Diagnostic Item & Problems ───────────────────────────────────────────
299
-
300
- export const DiagnosticSeveritySchema = z.enum(['error', 'warning', 'info', 'hint']);
301
- export type DiagnosticSeverity = z.infer<typeof DiagnosticSeveritySchema>;
302
-
303
- export const DiagnosticItemSchema = z.object({
304
- id: z.string(),
305
- file: z.string(),
306
- line: z.number().int(),
307
- col: z.number().int().optional(),
308
- column: z.number().int().optional(),
309
- endLine: z.number().int().optional(),
310
- endCol: z.number().int().optional(),
311
- endColumn: z.number().int().optional(),
312
- message: z.string(),
313
- severity: DiagnosticSeveritySchema,
314
- source: z.string().optional(),
315
- code: z.union([z.string(), z.number()]).optional(),
316
- tags: z.array(z.string()).optional()
317
- });
318
-
319
- export type DiagnosticItem = z.infer<typeof DiagnosticItemSchema>;
320
-
321
- // ── 10. Stored Project ──────────────────────────────────────────────────────
322
-
323
- export const StoredProjectSchema = z.object({
324
- id: z.string(),
325
- name: z.string(),
326
- files: z.record(z.string(), z.string()),
327
- updatedAt: z.number(),
328
- createdAt: z.number().optional(),
329
- entry: z.string().optional(),
330
- testEntry: z.string().optional(),
331
- version: z.number().optional()
332
- });
333
-
334
- export type StoredProject = z.infer<typeof StoredProjectSchema>;
335
-
336
- // ── 11. Git File Status & SCM Summary ───────────────────────────────────────
337
-
338
- export const GitFileChangeTypeSchema = z.enum(['modified', 'added', 'deleted', 'untracked']);
339
- export type GitFileChangeType = z.infer<typeof GitFileChangeTypeSchema>;
340
-
341
- export const GitFileStatusSchema = z.object({
342
- path: z.string(),
343
- status: GitFileChangeTypeSchema,
344
- staged: z.boolean(),
345
- oldContent: z.string().optional(),
346
- newContent: z.string().optional()
347
- });
348
-
349
- export type GitFileStatus = z.infer<typeof GitFileStatusSchema>;
350
-
351
- export const GitStateSummarySchema = z.object({
352
- branch: z.string().default('main'),
353
- headCommit: z.string().optional(),
354
- branches: z.array(z.string()).default(['main']),
355
- staged: z.array(GitFileStatusSchema).default([]),
356
- unstaged: z.array(GitFileStatusSchema).default([]),
357
- untracked: z.array(GitFileStatusSchema).default([]),
358
- modified: z.array(GitFileStatusSchema).optional(),
359
- deleted: z.array(GitFileStatusSchema).optional(),
360
- hasChanges: z.boolean().default(false),
361
- isClean: z.boolean().default(true),
362
- ahead: z.number().int().default(0),
363
- behind: z.number().int().default(0)
364
- });
365
-
366
- export type GitStateSummary = z.infer<typeof GitStateSummarySchema>;