@innovatorved/code-lab 0.3.1 → 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 (171) hide show
  1. package/ARCHITECTURE.md +8 -4
  2. package/CHANGELOG.md +45 -0
  3. package/README.md +70 -158
  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 +298 -2
  10. package/dist/code-lab.d.ts +110 -15
  11. package/dist/code-lab.esm.js +35284 -18253
  12. package/dist/code-lab.js +40434 -23431
  13. package/dist/code-lab.umd.js +65502 -0
  14. package/dist/diagnostics.d.ts +5 -0
  15. package/dist/extensions/cpp.esm.js +19532 -3772
  16. package/dist/extensions/cpp.js +19529 -3769
  17. package/dist/extensions/guided-lab.esm.js +19401 -3725
  18. package/dist/extensions/guided-lab.js +19400 -3724
  19. package/dist/extensions/python.d.ts +1 -0
  20. package/dist/extensions/python.esm.js +19666 -3843
  21. package/dist/extensions/python.js +19668 -3845
  22. package/dist/extensions/umbrella.d.ts +5 -0
  23. package/dist/index.d.ts +1 -1
  24. package/dist/modular-kernel.d.ts +11 -0
  25. package/dist/packages/commands/src/index.d.ts +96 -0
  26. package/dist/packages/core/src/di.d.ts +36 -0
  27. package/dist/packages/core/src/disposable.d.ts +27 -0
  28. package/dist/packages/core/src/errors.d.ts +69 -0
  29. package/dist/packages/core/src/events.d.ts +38 -0
  30. package/dist/packages/core/src/index.d.ts +6 -0
  31. package/dist/packages/core/src/path.d.ts +14 -0
  32. package/dist/packages/core/src/registry.d.ts +23 -0
  33. package/dist/packages/editor/src/index.d.ts +118 -0
  34. package/dist/packages/fs/src/backends.d.ts +37 -0
  35. package/dist/packages/fs/src/index.d.ts +3 -0
  36. package/dist/packages/fs/src/types.d.ts +40 -0
  37. package/dist/packages/fs/src/vfs-service.d.ts +33 -0
  38. package/dist/packages/preview/src/index.d.ts +34 -0
  39. package/dist/packages/runtime/src/index.d.ts +47 -0
  40. package/dist/packages/settings/src/builtin-schemas.d.ts +15 -0
  41. package/dist/packages/settings/src/configuration-service.d.ts +100 -0
  42. package/dist/packages/settings/src/index.d.ts +4 -0
  43. package/dist/packages/settings/src/jsonc.d.ts +20 -0
  44. package/dist/packages/settings/src/schema.d.ts +28 -0
  45. package/dist/packages/sql/src/completions.d.ts +8 -0
  46. package/dist/packages/sql/src/diagnostics.d.ts +2 -0
  47. package/dist/packages/sql/src/formatter.d.ts +2 -0
  48. package/dist/packages/sql/src/index.d.ts +7 -0
  49. package/dist/packages/sql/src/sql-editor.d.ts +2 -0
  50. package/dist/packages/sql/src/styles.d.ts +2 -0
  51. package/dist/packages/sql/src/tokenizer.d.ts +13 -0
  52. package/dist/packages/sql/src/types.d.ts +130 -0
  53. package/dist/packages/terminal/src/index.d.ts +54 -0
  54. package/dist/packages/ui/src/index.d.ts +4 -0
  55. package/dist/packages/ui/src/observability.d.ts +22 -0
  56. package/dist/packages/ui/src/plugin-registry.d.ts +89 -0
  57. package/dist/packages/ui/src/settings-dialog.d.ts +25 -0
  58. package/dist/packages/ui/src/themes.d.ts +35 -0
  59. package/dist/preview-sw.js +82 -24
  60. package/dist/runtime.d.ts +3 -3
  61. package/dist/runtime.esm.js +503 -73
  62. package/dist/runtime.js +501 -73
  63. package/dist/schemas.d.ts +234 -814
  64. package/dist/schemas.esm.js +19401 -3725
  65. package/dist/schemas.js +19404 -3728
  66. package/dist/scm.d.ts +13 -2
  67. package/dist/search.d.ts +5 -1
  68. package/dist/shell.d.ts +1 -1
  69. package/dist/shell.esm.js +435 -54
  70. package/dist/shell.js +435 -54
  71. package/dist/terminal.esm.js +242 -54
  72. package/dist/terminal.js +242 -54
  73. package/dist/workbench/diff-editor.d.ts +1 -0
  74. package/dist/workbench/index.d.ts +1 -1
  75. package/dist/workbench/styles.d.ts +1 -1
  76. package/dist/zip.d.ts +4 -3
  77. package/package.json +37 -8
  78. package/packages/commands/README.md +7 -0
  79. package/packages/commands/package.json +16 -0
  80. package/packages/commands/src/index.ts +467 -0
  81. package/packages/commands/tsconfig.json +22 -0
  82. package/packages/core/README.md +12 -0
  83. package/packages/core/package.json +13 -0
  84. package/packages/core/src/di.ts +147 -0
  85. package/packages/core/src/disposable.ts +112 -0
  86. package/packages/core/src/errors.ts +205 -0
  87. package/packages/core/src/events.ts +157 -0
  88. package/packages/core/src/index.ts +49 -0
  89. package/packages/core/src/path.ts +118 -0
  90. package/packages/core/src/registry.ts +61 -0
  91. package/packages/core/tsconfig.json +19 -0
  92. package/packages/editor/README.md +9 -0
  93. package/packages/editor/package.json +18 -0
  94. package/packages/editor/src/index.ts +344 -0
  95. package/packages/editor/tsconfig.json +24 -0
  96. package/packages/fs/README.md +7 -0
  97. package/packages/fs/package.json +16 -0
  98. package/packages/fs/src/backends.ts +301 -0
  99. package/packages/fs/src/index.ts +18 -0
  100. package/packages/fs/src/types.ts +44 -0
  101. package/packages/fs/src/vfs-service.ts +257 -0
  102. package/packages/fs/tsconfig.json +22 -0
  103. package/packages/preview/README.md +3 -0
  104. package/packages/preview/package.json +16 -0
  105. package/packages/preview/src/index.ts +125 -0
  106. package/packages/preview/tsconfig.json +22 -0
  107. package/packages/runtime/README.md +3 -0
  108. package/packages/runtime/package.json +17 -0
  109. package/packages/runtime/src/index.ts +134 -0
  110. package/packages/runtime/tsconfig.json +23 -0
  111. package/packages/settings/README.md +7 -0
  112. package/packages/settings/package.json +16 -0
  113. package/packages/settings/src/builtin-schemas.ts +235 -0
  114. package/packages/settings/src/configuration-service.ts +543 -0
  115. package/packages/settings/src/index.ts +37 -0
  116. package/packages/settings/src/jsonc.ts +189 -0
  117. package/packages/settings/src/schema.ts +164 -0
  118. package/packages/settings/tsconfig.json +22 -0
  119. package/packages/sql/README.md +12 -0
  120. package/packages/sql/package.json +13 -0
  121. package/packages/sql/src/completions.ts +359 -0
  122. package/packages/sql/src/diagnostics.ts +200 -0
  123. package/packages/sql/src/formatter.ts +271 -0
  124. package/packages/sql/src/index.ts +54 -0
  125. package/packages/sql/src/sql-editor.ts +802 -0
  126. package/packages/sql/src/styles.ts +501 -0
  127. package/packages/sql/src/tokenizer.ts +457 -0
  128. package/packages/sql/src/types.ts +148 -0
  129. package/packages/sql/tsconfig.json +19 -0
  130. package/packages/terminal/README.md +3 -0
  131. package/packages/terminal/package.json +16 -0
  132. package/packages/terminal/src/index.ts +183 -0
  133. package/packages/terminal/tsconfig.json +22 -0
  134. package/packages/ui/README.md +8 -0
  135. package/packages/ui/package.json +18 -0
  136. package/packages/ui/src/index.ts +36 -0
  137. package/packages/ui/src/observability.ts +175 -0
  138. package/packages/ui/src/plugin-registry.ts +274 -0
  139. package/packages/ui/src/settings-dialog.ts +293 -0
  140. package/packages/ui/src/themes.ts +174 -0
  141. package/packages/ui/tsconfig.json +24 -0
  142. package/src/code-lab.css +298 -2
  143. package/src/csp.ts +7 -10
  144. package/src/diagnostics.ts +42 -3
  145. package/src/extensions/cpp.ts +105 -24
  146. package/src/extensions/python.ts +260 -116
  147. package/src/extensions/umbrella.ts +5 -0
  148. package/src/index.ts +1 -1
  149. package/src/modular-kernel.ts +11 -0
  150. package/src/preview-sw.js +73 -12
  151. package/src/runtime.ts +501 -74
  152. package/src/schemas.ts +62 -62
  153. package/src/scm.ts +106 -19
  154. package/src/search.ts +71 -27
  155. package/src/shell.ts +433 -53
  156. package/src/terminal.ts +239 -52
  157. package/src/workbench/diff-editor.ts +106 -18
  158. package/src/workbench/drawer.ts +17 -4
  159. package/src/workbench/guided-pane.ts +12 -2
  160. package/src/workbench/icons.ts +5 -2
  161. package/src/workbench/share.ts +37 -8
  162. package/src/workbench/styles.ts +2 -1
  163. package/src/workbench/toolbar.ts +15 -4
  164. package/src/workbench.ts +2877 -284
  165. package/src/zip.ts +29 -7
  166. package/dist/runtime/index.d.ts +0 -4
  167. package/dist/shell/coreutils/compilers-cli.d.ts +0 -24
  168. package/dist/shell/index.d.ts +0 -4
  169. package/src/runtime/index.ts +0 -5
  170. package/src/shell/coreutils/compilers-cli.ts +0 -103
  171. package/src/shell/index.ts +0 -5
package/src/schemas.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { z } from 'zod';
2
2
 
3
3
  /**
4
- * Zod Schemas and Inferred TypeScript Types for code-lab v0.2.0
4
+ * Zod Schemas and Inferred TypeScript Types for code-lab v0.4.0
5
5
  */
6
6
 
7
7
  // ── 1. Guided Step ──────────────────────────────────────────────────────────
@@ -28,9 +28,9 @@ export const LanguageEnum = LanguageIdSchema;
28
28
 
29
29
  export const LanguageBundleSchema = z.object({
30
30
  language: LanguageIdSchema.default('js'),
31
- files: z.record(z.string()).default({}),
32
- starterFiles: z.record(z.string()).optional(),
33
- solutionFiles: z.record(z.string()).optional(),
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
34
  entry: z.string().optional(),
35
35
  testEntry: z.string().optional()
36
36
  });
@@ -45,26 +45,26 @@ export const GuidedLabExtensionOptionsSchema = z.object({
45
45
  mode: z.enum(['guided', 'sandbox']).default('guided'),
46
46
  language: LanguageIdSchema.optional(),
47
47
  lang: LanguageIdSchema.optional(),
48
- starterFiles: z.record(z.string()).optional(),
49
- solutionFiles: z.record(z.string()).optional(),
50
- tsStarterFiles: z.record(z.string()).optional(),
51
- tsSolutionFiles: z.record(z.string()).optional(),
52
- tsFiles: z.record(z.string()).optional(),
53
- cppStarterFiles: z.record(z.string()).optional(),
54
- cppSolutionFiles: z.record(z.string()).optional(),
55
- cppFiles: z.record(z.string()).optional(),
56
- pyStarterFiles: z.record(z.string()).optional(),
57
- pySolutionFiles: z.record(z.string()).optional(),
58
- pyFiles: z.record(z.string()).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
59
  pyEntry: z.string().optional(),
60
60
  pyTestEntry: z.string().optional(),
61
61
  pyTestCode: z.string().optional(),
62
62
  summary: z.string().optional(),
63
- onStepComplete: z.function().args(GuidedStepSchema, z.number()).returns(z.void()).optional(),
64
- onLabComplete: z.function().args(z.string()).returns(z.void()).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
65
  });
66
66
 
67
- export type GuidedLabExtensionOptions = z.infer<typeof GuidedLabExtensionOptionsSchema>;
67
+ export type GuidedLabExtensionOptions = z.input<typeof GuidedLabExtensionOptionsSchema>;
68
68
 
69
69
  export const CppToolchainProgressSchema = z.object({
70
70
  stage: z.enum(['downloading', 'caching', 'extracting', 'compiling', 'linking', 'ready', 'error']),
@@ -89,15 +89,15 @@ export const CppExtensionOptionsSchema = z.object({
89
89
  std: z.enum(['c++17', 'c++20', 'c++23']).default('c++20'),
90
90
  optLevel: z.enum(['-O0', '-O1', '-O2', '-O3']).default('-O2'),
91
91
  flags: z.array(z.string()).default(['-O2', '-Wall', '-Wextra']),
92
- headers: z.record(z.string()).optional(),
93
- extraHeaders: z.record(z.string()).optional(),
94
- files: z.record(z.string()).optional(),
95
- starterFiles: z.record(z.string()).optional(),
96
- solutionFiles: z.record(z.string()).optional(),
97
- onProgress: z.function().args(z.any()).returns(z.void()).optional()
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
98
  });
99
99
 
100
- export type CppExtensionOptions = z.infer<typeof CppExtensionOptionsSchema>;
100
+ export type CppExtensionOptions = z.input<typeof CppExtensionOptionsSchema>;
101
101
 
102
102
  export const PythonToolchainProgressSchema = z.object({
103
103
  stage: z.enum(['downloading', 'caching', 'extracting', 'initializing', 'ready']),
@@ -121,13 +121,13 @@ export const PythonExtensionOptionsSchema = z.object({
121
121
  packages: z.array(z.string()).optional(),
122
122
  preloadPackages: z.array(z.string()).optional(),
123
123
  compilerMemoryLimitMb: z.number().optional(),
124
- files: z.record(z.string()).optional(),
125
- starterFiles: z.record(z.string()).optional(),
126
- solutionFiles: z.record(z.string()).optional(),
127
- onProgress: z.function().args(z.any()).returns(z.void()).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
128
  });
129
129
 
130
- export type PythonExtensionOptions = z.infer<typeof PythonExtensionOptionsSchema>;
130
+ export type PythonExtensionOptions = z.input<typeof PythonExtensionOptionsSchema>;
131
131
 
132
132
  // ── 4. GitHub Clone Options & Progress ──────────────────────────────────────
133
133
 
@@ -160,16 +160,16 @@ export const GitHubCloneOptionsSchema = z.object({
160
160
  maxFileSize: z.number().int().positive().default(5 * 1024 * 1024),
161
161
  concurrency: z.number().int().positive().default(8),
162
162
  clearExisting: z.boolean().default(false),
163
- onProgress: z.function().args(z.any()).returns(z.void()).optional(),
163
+ onProgress: z.function({ input: [z.any()], output: z.void() }).optional(),
164
164
  fetchImpl: z.any().optional()
165
165
  });
166
166
 
167
- export type GitHubCloneOptions = z.infer<typeof GitHubCloneOptionsSchema>;
167
+ export type GitHubCloneOptions = z.input<typeof GitHubCloneOptionsSchema>;
168
168
 
169
169
  // ── 5. Runtime Execution Options ────────────────────────────────────────────
170
170
 
171
171
  export const RuntimeExecuteOptionsSchema = z.object({
172
- files: z.record(z.string()).optional(),
172
+ files: z.record(z.string(), z.string()).optional(),
173
173
  entry: z.string().optional(),
174
174
  mode: z.enum(['run', 'test', 'repl']).default('run'),
175
175
  replCode: z.string().optional(),
@@ -185,21 +185,21 @@ export const RuntimeExecuteOptionsSchema = z.object({
185
185
  isBackground: z.boolean().optional(),
186
186
  vfs: z.any().optional(),
187
187
  activePortTable: z.any().optional(),
188
- packages: z.record(z.any()).optional(),
189
- npmModules: z.record(z.any()).optional(),
190
- onStdout: z.function().args(z.string()).returns(z.void()).optional(),
191
- onStderr: z.function().args(z.string()).returns(z.void()).optional(),
192
- onTestResult: z.function().args(z.any()).returns(z.void()).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
193
  });
194
194
 
195
- export type RuntimeExecuteOptions = z.infer<typeof RuntimeExecuteOptionsSchema>;
195
+ export type RuntimeExecuteOptions = z.input<typeof RuntimeExecuteOptionsSchema>;
196
196
 
197
197
  // ── 6. Workspace Snapshot ───────────────────────────────────────────────────
198
198
 
199
199
  export const WorkspaceSnapshotSchema = z.object({
200
200
  version: z.number().default(1),
201
201
  timestamp: z.number().optional(),
202
- files: z.record(z.string()),
202
+ files: z.record(z.string(), z.string()),
203
203
  openTabs: z.array(z.string()).default([]),
204
204
  activeFile: z.string().nullable().optional(),
205
205
  mode: z.enum(['guided', 'sandbox']).optional(),
@@ -217,12 +217,12 @@ export const WorkbenchOptionsSchema = z.object({
217
217
  buildId: z.string().optional(),
218
218
  title: z.string().default('code-lab'),
219
219
  summary: z.string().optional(),
220
- theme: z.enum(['dark', 'light', 'auto']).default('auto'),
220
+ theme: z.enum(['dark', 'light', 'high-contrast', 'auto']).default('auto'),
221
221
  persistState: z.boolean().default(true),
222
222
  repo: z.string().optional(),
223
223
  githubRepo: z.string().optional(),
224
224
  branch: z.string().optional(),
225
- files: z.record(z.string()).default({}),
225
+ files: z.record(z.string(), z.string()).default({}),
226
226
  entry: z.string().default('demo.js'),
227
227
  testEntry: z.string().default('test.js'),
228
228
  testFile: z.string().optional(),
@@ -231,25 +231,25 @@ export const WorkbenchOptionsSchema = z.object({
231
231
  previewOrigin: z.string().optional(),
232
232
  logger: z.any().optional(),
233
233
  debug: z.boolean().optional(),
234
- onClose: z.function().returns(z.void()).optional(),
235
- onRun: z.function().args(z.any()).returns(z.void()).optional(),
236
- onTestResult: z.function().args(z.any()).returns(z.void()).optional(),
237
- onCodeChange: z.function().args(z.string(), z.string()).returns(z.void()).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
238
  plugins: z.array(z.any()).optional(),
239
239
  extensions: z.array(z.any()).optional(),
240
240
  // Backward-compatible guided lab properties:
241
241
  steps: z.array(GuidedStepSchema).optional(),
242
- starterFiles: z.record(z.string()).optional(),
243
- solutionFiles: z.record(z.string()).optional(),
244
- tsFiles: z.record(z.string()).optional(),
245
- tsStarterFiles: z.record(z.string()).optional(),
246
- tsSolutionFiles: z.record(z.string()).optional(),
247
- cppFiles: z.record(z.string()).optional(),
248
- cppStarterFiles: z.record(z.string()).optional(),
249
- cppSolutionFiles: z.record(z.string()).optional(),
250
- pyFiles: z.record(z.string()).optional(),
251
- pyStarterFiles: z.record(z.string()).optional(),
252
- pySolutionFiles: z.record(z.string()).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
253
  pyEntry: z.string().optional().default('main.py'),
254
254
  pyTestEntry: z.string().optional().default('test.py'),
255
255
  pyTestCode: z.string().optional(),
@@ -260,11 +260,11 @@ export const WorkbenchOptionsSchema = z.object({
260
260
  language: LanguageIdSchema.optional(),
261
261
  lang: LanguageIdSchema.optional(),
262
262
  stepIndex: z.number().int().optional(),
263
- onStepComplete: z.function().args(z.any(), z.number()).returns(z.void()).optional(),
264
- onLabComplete: z.function().args(z.string()).returns(z.void()).optional()
263
+ onStepComplete: z.function({ input: [z.any(), z.number()], output: z.void() }).optional(),
264
+ onLabComplete: z.function({ input: [z.string()], output: z.void() }).optional()
265
265
  });
266
266
 
267
- export type WorkbenchOptions = z.infer<typeof WorkbenchOptionsSchema>;
267
+ export type WorkbenchOptions = z.input<typeof WorkbenchOptionsSchema>;
268
268
 
269
269
  // ── 8. Search Options & Match Results ────────────────────────────────────────
270
270
 
@@ -284,7 +284,7 @@ export const SearchOptionsSchema = z.object({
284
284
  maxMatchesPerFile: z.number().int().positive().optional()
285
285
  });
286
286
 
287
- export type SearchOptions = z.infer<typeof SearchOptionsSchema>;
287
+ export type SearchOptions = z.input<typeof SearchOptionsSchema>;
288
288
 
289
289
  // ── 9. Diagnostic Item & Problems ───────────────────────────────────────────
290
290
 
@@ -314,7 +314,7 @@ export type DiagnosticItem = z.infer<typeof DiagnosticItemSchema>;
314
314
  export const StoredProjectSchema = z.object({
315
315
  id: z.string(),
316
316
  name: z.string(),
317
- files: z.record(z.string()),
317
+ files: z.record(z.string(), z.string()),
318
318
  updatedAt: z.number(),
319
319
  createdAt: z.number().optional(),
320
320
  entry: z.string().optional(),
package/src/scm.ts CHANGED
@@ -31,10 +31,19 @@ export interface GitState {
31
31
  branches?: string[];
32
32
  headCommit: string;
33
33
  headFiles: Record<string, string>;
34
- staged: Map<string, string | null>;
34
+ headSnapshot?: Record<string, string>;
35
+ staged: Map<string, string | null> | Set<string>;
35
36
  commits: GitCommitRecord[];
36
37
  }
37
38
 
39
+ export interface GitStatusEntry {
40
+ path: string;
41
+ status: GitFileChangeType;
42
+ staged: boolean;
43
+ index: string;
44
+ worktree: string;
45
+ }
46
+
38
47
  export interface GitStatusResult {
39
48
  branch: string;
40
49
  headCommit: string;
@@ -43,6 +52,7 @@ export interface GitStatusResult {
43
52
  deleted: GitFileStatus[];
44
53
  staged: GitFileStatus[];
45
54
  unstaged: GitFileStatus[];
55
+ entries: GitStatusEntry[];
46
56
  hasChanges: boolean;
47
57
  isClean: boolean;
48
58
  }
@@ -92,15 +102,41 @@ export function createGitState(
92
102
 
93
103
  /**
94
104
  * Computes working-tree and staging-area Git status against `gitState`.
105
+ * Supports both `computeGitStatus(vfsFiles, repoRoot, gitState)` and
106
+ * `computeGitStatus(gitState, vfsFiles)` calling conventions.
95
107
  */
96
108
  export function computeGitStatus(
97
- vfsFiles: Record<string, string>,
98
- _repoRoot = '/workspace',
109
+ arg1: Record<string, string> | GitState,
110
+ arg2: string | Record<string, string> = '/workspace',
99
111
  gitState?: GitState
100
112
  ): GitStatusResult {
101
- const state = gitState || createGitState({});
102
- const headFiles = state.headFiles || {};
103
- const currentStaged = state.staged instanceof Map ? state.staged : new Map<string, string | null>();
113
+ let vfsFiles: Record<string, string>;
114
+ let state: GitState;
115
+
116
+ if (
117
+ arg1 &&
118
+ typeof arg1 === 'object' &&
119
+ ('headFiles' in arg1 || 'headSnapshot' in arg1 || 'staged' in arg1 || 'commits' in arg1)
120
+ ) {
121
+ state = arg1 as GitState;
122
+ vfsFiles = (arg2 && typeof arg2 === 'object' ? arg2 : {}) as Record<string, string>;
123
+ } else {
124
+ vfsFiles = (arg1 && typeof arg1 === 'object' ? arg1 : {}) as Record<string, string>;
125
+ state = gitState || createGitState({});
126
+ }
127
+
128
+ const headFiles: Record<string, string> = state.headFiles || state.headSnapshot || {};
129
+ const currentStaged = new Map<string, string | null>();
130
+ if (state.staged instanceof Map) {
131
+ for (const [k, v] of state.staged.entries()) {
132
+ currentStaged.set(k, v);
133
+ }
134
+ } else if (state.staged instanceof Set) {
135
+ for (const k of state.staged.values()) {
136
+ const existsInVfs = Object.prototype.hasOwnProperty.call(vfsFiles, k);
137
+ currentStaged.set(k, existsInVfs ? vfsFiles[k] : null);
138
+ }
139
+ }
104
140
 
105
141
  const untracked: GitFileStatus[] = [];
106
142
  const modified: GitFileStatus[] = [];
@@ -110,12 +146,14 @@ export function computeGitStatus(
110
146
  for (const [filePath, stagedContent] of currentStaged.entries()) {
111
147
  const inHead = Object.prototype.hasOwnProperty.call(headFiles, filePath);
112
148
  if (stagedContent === null) {
113
- staged.push({
114
- path: filePath,
115
- status: 'deleted',
116
- staged: true,
117
- oldContent: headFiles[filePath]
118
- });
149
+ if (inHead) {
150
+ staged.push({
151
+ path: filePath,
152
+ status: 'deleted',
153
+ staged: true,
154
+ oldContent: headFiles[filePath]
155
+ });
156
+ }
119
157
  } else {
120
158
  staged.push({
121
159
  path: filePath,
@@ -174,6 +212,36 @@ export function computeGitStatus(
174
212
  }
175
213
 
176
214
  const unstaged: GitFileStatus[] = [...modified, ...deleted];
215
+ const entries: GitStatusEntry[] = [
216
+ ...staged.map((s) => ({
217
+ path: s.path,
218
+ status: s.status,
219
+ staged: true,
220
+ index: s.status === 'added' ? 'A' : s.status === 'deleted' ? 'D' : 'M',
221
+ worktree: ' '
222
+ })),
223
+ ...modified.map((m) => ({
224
+ path: m.path,
225
+ status: m.status,
226
+ staged: false,
227
+ index: ' ',
228
+ worktree: 'M'
229
+ })),
230
+ ...deleted.map((d) => ({
231
+ path: d.path,
232
+ status: d.status,
233
+ staged: false,
234
+ index: ' ',
235
+ worktree: 'D'
236
+ })),
237
+ ...untracked.map((u) => ({
238
+ path: u.path,
239
+ status: u.status,
240
+ staged: false,
241
+ index: '?',
242
+ worktree: '?'
243
+ }))
244
+ ];
177
245
  const isClean =
178
246
  untracked.length === 0 &&
179
247
  modified.length === 0 &&
@@ -188,6 +256,7 @@ export function computeGitStatus(
188
256
  deleted,
189
257
  staged,
190
258
  unstaged,
259
+ entries,
191
260
  hasChanges: !isClean,
192
261
  isClean
193
262
  };
@@ -205,15 +274,28 @@ export function stageFile(
205
274
  if (!(gitState.staged instanceof Map)) {
206
275
  gitState.staged = new Map<string, string | null>();
207
276
  }
208
- gitState.staged.set(relativePath, currentContent === undefined ? null : currentContent);
277
+ const normalizedContent = currentContent === undefined ? null : currentContent;
278
+ const headFiles = gitState.headFiles || gitState.headSnapshot || {};
279
+ if (
280
+ normalizedContent === null &&
281
+ !Object.prototype.hasOwnProperty.call(headFiles, relativePath) &&
282
+ !gitState.staged.has(relativePath)
283
+ ) {
284
+ return;
285
+ }
286
+ gitState.staged.set(relativePath, normalizedContent);
209
287
  }
210
288
 
211
289
  /**
212
290
  * Removes a file from the staging index.
213
291
  */
214
292
  export function unstageFile(gitState: GitState, relativePath: string): void {
215
- if (!gitState || !(gitState.staged instanceof Map)) return;
216
- gitState.staged.delete(relativePath);
293
+ if (!gitState) return;
294
+ if (gitState.staged instanceof Map) {
295
+ gitState.staged.delete(relativePath);
296
+ } else if (gitState.staged instanceof Set) {
297
+ gitState.staged.delete(relativePath);
298
+ }
217
299
  }
218
300
 
219
301
  /**
@@ -229,8 +311,10 @@ export function commitChanges(gitState: GitState, message: string): string {
229
311
  throw new Error('Nothing to commit (staging area is empty)');
230
312
  }
231
313
 
232
- const newHeadFiles: Record<string, string> = { ...(gitState.headFiles || {}) };
314
+ const newHeadFiles: Record<string, string> = { ...(gitState.headFiles || gitState.headSnapshot || {}) };
315
+ const diffSummaryParts: string[] = [];
233
316
  for (const [filePath, content] of gitState.staged.entries()) {
317
+ diffSummaryParts.push(`${filePath}:${content === null ? '<DEL>' : content}`);
234
318
  if (content === null) {
235
319
  delete newHeadFiles[filePath];
236
320
  } else {
@@ -239,12 +323,15 @@ export function commitChanges(gitState: GitState, message: string): string {
239
323
  }
240
324
 
241
325
  const timestamp = Date.now();
242
- const hash = computeShortCommitHash(`${gitState.headCommit}:${trimmed}:${timestamp}`);
326
+ const commitSeq = Array.isArray(gitState.commits) ? gitState.commits.length : 0;
327
+ const hash = computeShortCommitHash(
328
+ `${gitState.headCommit}:${trimmed}:${timestamp}:${commitSeq}:${diffSummaryParts.join('|')}`
329
+ );
243
330
  const commit: GitCommitRecord = {
244
331
  hash,
245
332
  message: trimmed,
246
333
  timestamp,
247
- files: newHeadFiles
334
+ files: { ...newHeadFiles }
248
335
  };
249
336
 
250
337
  if (!Array.isArray(gitState.commits)) {
@@ -252,7 +339,7 @@ export function commitChanges(gitState: GitState, message: string): string {
252
339
  }
253
340
  gitState.commits.push(commit);
254
341
  gitState.headCommit = hash;
255
- gitState.headFiles = newHeadFiles;
342
+ gitState.headFiles = { ...newHeadFiles };
256
343
  gitState.staged.clear();
257
344
 
258
345
  return hash;
package/src/search.ts CHANGED
@@ -10,6 +10,7 @@
10
10
 
11
11
  export interface SearchOptions {
12
12
  query?: string;
13
+ replacement?: string;
13
14
  caseSensitive?: boolean;
14
15
  wholeWord?: boolean;
15
16
  regex?: boolean;
@@ -55,8 +56,10 @@ export interface SearchResult extends Array<SearchMatchGroup> {
55
56
 
56
57
  export interface ReplaceResult {
57
58
  updatedFiles: Record<string, string>;
59
+ files: Record<string, string>;
58
60
  replacedCount: number;
59
61
  filesAffected: string[];
62
+ filesModified: number;
60
63
  }
61
64
 
62
65
  /**
@@ -82,11 +85,22 @@ export function normalizeSearchPath(filePath: string): string {
82
85
 
83
86
  /**
84
87
  * Matches a file path against a glob or literal substring filter.
88
+ * Supports comma-separated patterns (e.g. `*.ts, *.js`).
85
89
  */
86
90
  export function matchesGlob(filePath: string, pattern: string): boolean {
87
91
  if (!pattern || pattern === '*' || pattern === '**') return true;
92
+ if (pattern.includes(',')) {
93
+ const subPatterns = pattern
94
+ .split(',')
95
+ .map((s) => s.trim())
96
+ .filter(Boolean);
97
+ if (subPatterns.length > 1) {
98
+ return subPatterns.some((sub) => matchesGlob(filePath, sub));
99
+ }
100
+ }
101
+
88
102
  const normPath = normalizeSearchPath(filePath);
89
- const normPattern = normalizeSearchPath(pattern);
103
+ const normPattern = normalizeSearchPath(pattern.trim());
90
104
 
91
105
  if (normPattern === normPath) return true;
92
106
 
@@ -102,10 +116,13 @@ export function matchesGlob(filePath: string, pattern: string): boolean {
102
116
  const c = normPattern[i];
103
117
  if (c === '*') {
104
118
  if (normPattern[i + 1] === '*') {
105
- regexStr += '.*';
106
119
  i += 2;
107
120
  if (normPattern[i] === '/') {
121
+ // `/**/` or leading `**/` matches zero or more directory segments
122
+ regexStr += '(?:.*/)?';
108
123
  i++;
124
+ } else {
125
+ regexStr += '.*';
109
126
  }
110
127
  continue;
111
128
  } else {
@@ -130,7 +147,13 @@ export function matchesGlob(filePath: string, pattern: string): boolean {
130
147
 
131
148
  try {
132
149
  const re = new RegExp(regexStr);
133
- return re.test(normPath);
150
+ if (re.test(normPath)) return true;
151
+ // Also allow basename match when pattern has no directory separator (e.g. `*.ts` matching `src/app.ts`)
152
+ if (!normPattern.includes('/')) {
153
+ const baseName = normPath.split('/').pop() || normPath;
154
+ if (re.test(baseName)) return true;
155
+ }
156
+ return false;
134
157
  } catch (err) {
135
158
  void err;
136
159
  return normPath.includes(normPattern.replace(/[*?]/g, ''));
@@ -286,11 +309,11 @@ export function searchInFiles(
286
309
  export function replaceInFiles(
287
310
  files: Record<string, string>,
288
311
  arg2: string | SearchOptions,
289
- arg3: string,
312
+ arg3?: string,
290
313
  arg4?: SearchOptions | string[]
291
314
  ): ReplaceResult {
292
315
  let query = '';
293
- const replacement = typeof arg3 === 'string' ? arg3 : '';
316
+ let replacement = typeof arg3 === 'string' ? arg3 : '';
294
317
  let opts: SearchOptions = {};
295
318
  let targetFiles: string[] | undefined = undefined;
296
319
 
@@ -305,6 +328,9 @@ export function replaceInFiles(
305
328
  } else if (arg2 && typeof arg2 === 'object') {
306
329
  opts = arg2;
307
330
  query = opts.query || '';
331
+ if (typeof arg3 !== 'string' && typeof opts.replacement === 'string') {
332
+ replacement = opts.replacement;
333
+ }
308
334
  if (Array.isArray(arg4)) {
309
335
  targetFiles = arg4;
310
336
  } else {
@@ -313,10 +339,13 @@ export function replaceInFiles(
313
339
  }
314
340
 
315
341
  if (!query) {
342
+ const copy = { ...files };
316
343
  return {
317
- updatedFiles: { ...files },
344
+ updatedFiles: copy,
345
+ files: copy,
318
346
  replacedCount: 0,
319
- filesAffected: []
347
+ filesAffected: [],
348
+ filesModified: 0
320
349
  };
321
350
  }
322
351
 
@@ -337,10 +366,13 @@ export function replaceInFiles(
337
366
  regex = new RegExp(patternStr, isCaseSensitive ? 'g' : 'gi');
338
367
  } catch (err) {
339
368
  void err;
369
+ const copy = { ...files };
340
370
  return {
341
- updatedFiles: { ...files },
371
+ updatedFiles: copy,
372
+ files: copy,
342
373
  replacedCount: 0,
343
- filesAffected: []
374
+ filesAffected: [],
375
+ filesModified: 0
344
376
  };
345
377
  }
346
378
 
@@ -353,29 +385,39 @@ export function replaceInFiles(
353
385
  if (includeFilter && !checkFilter(filePath, includeFilter)) continue;
354
386
  if (excludeFilter && checkFilter(filePath, excludeFilter)) continue;
355
387
 
356
- // Count matches safely
357
- regex.lastIndex = 0;
388
+ const lines = content.split('\n');
358
389
  let countInFile = 0;
359
- let m: RegExpExecArray | null;
360
- while ((m = regex.exec(content)) !== null) {
361
- countInFile++;
362
- if (m[0].length === 0) {
363
- regex.lastIndex++;
364
- if (regex.lastIndex > content.length) {
365
- break;
390
+ const newLines: string[] = [];
391
+
392
+ for (let lineIdx = 0; lineIdx < lines.length; lineIdx++) {
393
+ const lineText = lines[lineIdx];
394
+ regex.lastIndex = 0;
395
+ let lineMatches = 0;
396
+ let m: RegExpExecArray | null;
397
+ while ((m = regex.exec(lineText)) !== null) {
398
+ lineMatches++;
399
+ if (m[0].length === 0) {
400
+ regex.lastIndex++;
401
+ if (regex.lastIndex > lineText.length) {
402
+ break;
403
+ }
404
+ }
405
+ }
406
+ if (lineMatches > 0) {
407
+ countInFile += lineMatches;
408
+ regex.lastIndex = 0;
409
+ if (isRegex) {
410
+ newLines.push(lineText.replace(regex, replacement));
411
+ } else {
412
+ newLines.push(lineText.replace(regex, () => replacement));
366
413
  }
414
+ } else {
415
+ newLines.push(lineText);
367
416
  }
368
417
  }
369
418
 
370
419
  if (countInFile > 0) {
371
- regex.lastIndex = 0;
372
- let newContent: string;
373
- if (isRegex) {
374
- newContent = content.replace(regex, replacement);
375
- } else {
376
- newContent = content.replace(regex, () => replacement);
377
- }
378
- updatedFiles[filePath] = newContent;
420
+ updatedFiles[filePath] = newLines.join('\n');
379
421
  filesAffected.push(filePath);
380
422
  replacedCount += countInFile;
381
423
  }
@@ -383,7 +425,9 @@ export function replaceInFiles(
383
425
 
384
426
  return {
385
427
  updatedFiles,
428
+ files: updatedFiles,
386
429
  replacedCount,
387
- filesAffected
430
+ filesAffected,
431
+ filesModified: filesAffected.length
388
432
  };
389
433
  }