@innovatorved/code-lab 0.5.0 → 0.6.1

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 (76) hide show
  1. package/ARCHITECTURE.md +3 -3
  2. package/CHANGELOG.md +23 -0
  3. package/README.md +3 -3
  4. package/dist/code-lab-sql.css +87 -64
  5. package/dist/code-lab-sql.esm.js +109 -86
  6. package/dist/code-lab-sql.umd.js +110 -87
  7. package/dist/code-lab.css +32 -7273
  8. package/dist/code-lab.d.ts +1 -1
  9. package/dist/code-lab.esm.js +4966 -74622
  10. package/dist/code-lab.js +4974 -74631
  11. package/dist/code-lab.umd.js +4974 -74631
  12. package/dist/extensions/cpp.d.ts +2 -2
  13. package/dist/extensions/cpp.esm.js +1788 -14707
  14. package/dist/extensions/cpp.js +1788 -14707
  15. package/dist/extensions/guided-lab.esm.js +2938 -16127
  16. package/dist/extensions/guided-lab.js +2938 -16127
  17. package/dist/extensions/python.d.ts +2 -2
  18. package/dist/extensions/python.esm.js +1769 -14701
  19. package/dist/extensions/python.js +1769 -14701
  20. package/dist/index.d.ts +1 -1
  21. package/dist/packages/sql/src/styles.d.ts +1 -1
  22. package/dist/packages/ui/src/settings-dialog.d.ts +2 -0
  23. package/dist/preview-sw.js +4 -188
  24. package/dist/runtime.esm.js +109 -10284
  25. package/dist/runtime.js +107 -10284
  26. package/dist/schemas.d.ts +2 -2
  27. package/dist/schemas.esm.js +2938 -16127
  28. package/dist/schemas.js +2941 -16130
  29. package/dist/scm.d.ts +221 -20
  30. package/dist/shell.esm.js +811 -10002
  31. package/dist/shell.js +811 -10002
  32. package/dist/storage.d.ts +9 -0
  33. package/dist/terminal.esm.js +20 -1347
  34. package/dist/terminal.js +20 -1347
  35. package/dist/workbench/command-palette.d.ts +16 -1
  36. package/dist/workbench/diff-editor.d.ts +27 -1
  37. package/dist/workbench/icons.d.ts +6 -2
  38. package/dist/workbench/index.d.ts +33 -1
  39. package/dist/workbench/intellisense.d.ts +194 -0
  40. package/dist/workbench/styles.d.ts +1 -1
  41. package/dist/workbench/xterm-adapter.d.ts +122 -0
  42. package/package.json +7 -1
  43. package/packages/commands/package.json +1 -1
  44. package/packages/core/package.json +1 -1
  45. package/packages/editor/package.json +1 -1
  46. package/packages/fs/package.json +1 -1
  47. package/packages/preview/package.json +1 -1
  48. package/packages/runtime/package.json +1 -1
  49. package/packages/settings/package.json +1 -1
  50. package/packages/sql/package.json +1 -1
  51. package/packages/sql/src/styles.ts +87 -64
  52. package/packages/terminal/package.json +1 -1
  53. package/packages/ui/package.json +1 -1
  54. package/packages/ui/src/observability.ts +12 -14
  55. package/packages/ui/src/settings-dialog.ts +383 -47
  56. package/packages/ui/src/themes.ts +89 -23
  57. package/src/code-lab.css +1883 -578
  58. package/src/extensions/cpp.ts +304 -38
  59. package/src/extensions/python.ts +342 -43
  60. package/src/index.ts +1 -1
  61. package/src/runtime.ts +272 -43
  62. package/src/schemas.ts +2 -2
  63. package/src/scm.ts +1467 -92
  64. package/src/shell.ts +1075 -93
  65. package/src/storage.ts +66 -3
  66. package/src/terminal.ts +148 -12
  67. package/src/workbench/command-palette.ts +289 -48
  68. package/src/workbench/diff-editor.ts +244 -78
  69. package/src/workbench/drawer.ts +5 -5
  70. package/src/workbench/icons.ts +250 -53
  71. package/src/workbench/index.ts +7 -1
  72. package/src/workbench/intellisense.ts +1871 -0
  73. package/src/workbench/styles.ts +58 -54
  74. package/src/workbench/toolbar.ts +1 -1
  75. package/src/workbench/xterm-adapter.ts +1571 -0
  76. package/src/workbench.ts +1699 -324
package/dist/scm.d.ts CHANGED
@@ -1,12 +1,14 @@
1
1
  /**
2
2
  * @innovatorved/code-lab — Interactive Git Source Control (SCM) Engine
3
3
  * ============================================================================
4
- * Pure TypeScript in-browser Git status, staging, unstaging, discard, and
5
- * commit engine backed by workspace VFS state. Powers both the interactive
6
- * Source Control UI and shell/CLI Git operations with a unified GitState schema.
4
+ * Browser-native Git engine combining synchronous deterministic VFS/SCM state
5
+ * with `isomorphic-git` `.git/` object-store synchronization, Myers O(ND)
6
+ * 3-line hunk diffs, `.gitignore` pattern matching, real branch file checkout,
7
+ * stash, reset (`--soft`/`--mixed`/`--hard` `HEAD~N`), merge, tags, show & blame.
7
8
  *
8
9
  * Strict leaf module: fully typed, zero explicit any, zero empty catches.
9
10
  */
11
+ import { init as isoInit, add as isoAdd, commit as isoCommit, currentBranch as isoCurrentBranch, listBranches as isoListBranches, log as isoLog } from 'isomorphic-git';
10
12
  export type GitFileChangeType = 'modified' | 'added' | 'deleted' | 'untracked';
11
13
  export interface GitFileStatus {
12
14
  path: string;
@@ -15,22 +17,34 @@ export interface GitFileStatus {
15
17
  oldContent?: string;
16
18
  newContent?: string;
17
19
  }
20
+ export interface GitStatLike {
21
+ size?: number;
22
+ mtimeMs?: number;
23
+ mode?: number;
24
+ isDirectory(): boolean;
25
+ isFile?(): boolean;
26
+ isSymbolicLink?(): boolean;
27
+ }
18
28
  export interface GitVfsLike {
19
29
  existsSync?(path: string): boolean;
20
- statSync?(path: string): {
21
- isDirectory(): boolean;
22
- };
30
+ statSync?(path: string): GitStatLike;
31
+ lstatSync?(path: string): GitStatLike;
23
32
  readdirSync?(path: string): string[];
24
33
  readFileSync?(path: string, encoding?: string): string | Uint8Array;
25
- writeFileSync?(path: string, data: string): void;
34
+ writeFileSync?(path: string, data: string | Uint8Array): void;
26
35
  mkdirSync?(path: string, options?: {
27
36
  recursive?: boolean;
28
37
  }): unknown;
38
+ rmdirSync?(path: string, options?: {
39
+ recursive?: boolean;
40
+ }): void;
29
41
  unlinkSync?(path: string): void;
30
42
  rmSync?(path: string, options?: {
31
43
  recursive?: boolean;
32
44
  force?: boolean;
33
45
  }): void;
46
+ symlinkSync?(target: string, path: string): void;
47
+ readlinkSync?(path: string): string;
34
48
  files?: Map<string, unknown>;
35
49
  }
36
50
  export interface GitShellLike {
@@ -46,12 +60,31 @@ export interface GitCommitRecord {
46
60
  author?: string;
47
61
  date?: string;
48
62
  files?: Record<string, string>;
63
+ parents?: string[];
64
+ }
65
+ export interface GitBranchTip {
66
+ headCommit: string;
67
+ headFiles: Record<string, string>;
68
+ commits: GitCommitRecord[];
69
+ }
70
+ export interface GitStashEntry {
71
+ id: number;
72
+ branch: string;
73
+ headCommit: string;
74
+ message: string;
75
+ timestamp: number;
76
+ worktreeFiles: Record<string, string>;
77
+ stagedEntries: Array<[string, string | null]>;
78
+ untrackedFiles: Record<string, string>;
49
79
  }
50
80
  export interface GitState {
51
81
  initialized?: boolean;
52
82
  repoRoot?: string;
53
83
  branch: string;
54
84
  branches?: string[] | Set<string>;
85
+ branchHeads?: Record<string, GitBranchTip>;
86
+ tags?: Record<string, string>;
87
+ stashes?: GitStashEntry[];
55
88
  remoteUrl?: string | null;
56
89
  remotes?: Record<string, string>;
57
90
  headCommit: string;
@@ -90,11 +123,42 @@ export interface InitRepositoryOptions {
90
123
  snapshotExisting?: boolean;
91
124
  initialFiles?: Record<string, string>;
92
125
  }
126
+ export interface DiscardChangesOptions {
127
+ keepStaged?: boolean;
128
+ }
129
+ export interface DiffLineOp {
130
+ type: 'common' | 'added' | 'removed';
131
+ line: string;
132
+ oldLineNumber?: number;
133
+ newLineNumber?: number;
134
+ }
135
+ export interface GitGutterRange {
136
+ line: number;
137
+ endLine: number;
138
+ kind: 'added' | 'modified' | 'deleted';
139
+ }
140
+ export interface GitIgnoreRule {
141
+ negated: boolean;
142
+ dirOnly: boolean;
143
+ regex: RegExp;
144
+ }
145
+ export interface BlameLineEntry {
146
+ lineNumber: number;
147
+ hash: string;
148
+ author: string;
149
+ timestamp: number;
150
+ content: string;
151
+ }
93
152
  /**
94
153
  * Computes a deterministic 7-character short hash for a commit payload.
95
154
  */
96
155
  export declare function computeShortCommitHash(input: string): string;
97
- export declare function isIgnoredScmPath(relPath: string): boolean;
156
+ /**
157
+ * Compiles `.gitignore` text into ordered glob/negation match rules.
158
+ */
159
+ export declare function parseGitignoreRules(gitignoreContent: string | undefined): GitIgnoreRule[];
160
+ export declare function isIgnoredByRules(relPath: string, rules: ReadonlyArray<GitIgnoreRule>): boolean;
161
+ export declare function isIgnoredScmPath(relPath: string, gitignoreRules?: ReadonlyArray<GitIgnoreRule>): boolean;
98
162
  export declare function normalizeScmRelPath(rawPath: string, repoRoot?: string): string;
99
163
  export declare function isUnbornGitHead(gitState: GitState | null | undefined): boolean;
100
164
  export declare function isEffectiveStagedChange(gitState: GitState | null | undefined, relPath: string, stagedVal: string | null | undefined, resolvedHeadFiles?: Record<string, string>): boolean;
@@ -103,11 +167,13 @@ export declare function isEffectiveStagedChange(gitState: GitState | null | unde
103
167
  * properties reference the exact same clean `Record<string, string>` object.
104
168
  */
105
169
  export declare function syncGitHead(gitState: GitState, nextHead?: Record<string, string>): Record<string, string>;
170
+ export declare function saveBranchTip(gitState: GitState, branchName?: string): void;
106
171
  /**
107
172
  * Initializes an in-memory Git repository state from initial VFS files,
108
173
  * keeping `headFiles` / `headSnapshot` and `staged` / `stagedFiles` synchronized.
109
174
  */
110
175
  export declare function createGitState(initialFiles?: Record<string, string>, branch?: string, options?: CreateGitStateOptions): GitState;
176
+ export declare function readVfsTree(vfs: GitVfsLike, rootDir: string): Record<string, string>;
111
177
  /**
112
178
  * Initializes a Git repository on a `PosixShell` (writing `.git/HEAD` & `.git/config`)
113
179
  * or directly on a `GitState` object. Defaults `snapshotExisting` to `false` so
@@ -115,9 +181,8 @@ export declare function createGitState(initialFiles?: Record<string, string>, br
115
181
  */
116
182
  export declare function initRepository(target: GitShellLike | GitState, options?: InitRepositoryOptions): GitState;
117
183
  /**
118
- * Computes working-tree and staging-area Git status against `gitState`.
119
- * Supports both `computeGitStatus(vfsFiles, repoRoot, gitState)` and
120
- * `computeGitStatus(gitState, vfsFiles)` calling conventions.
184
+ * Computes working-tree and staging-area Git status against `gitState`,
185
+ * honoring `.gitignore` rules for untracked files while keeping tracked files visible.
121
186
  */
122
187
  export declare function computeGitStatus(arg1: Record<string, string> | GitState, arg2?: string | Record<string, string>, gitState?: GitState): GitStatusResult;
123
188
  /**
@@ -125,7 +190,7 @@ export declare function computeGitStatus(arg1: Record<string, string> | GitState
125
190
  */
126
191
  export declare function stageFile(gitState: GitState, relativePath: string, currentContent: string | null): void;
127
192
  /**
128
- * Stages all modified, untracked (non-ignored), and deleted tracked files.
193
+ * Stages all modified, untracked (non-gitignored), and deleted tracked files.
129
194
  */
130
195
  export declare function stageAll(gitState: GitState, vfsFiles: Record<string, string>, repoRoot?: string): void;
131
196
  /**
@@ -137,26 +202,140 @@ export declare function unstageFile(gitState: GitState, relativePath: string): v
137
202
  */
138
203
  export declare function unstageAll(gitState: GitState): void;
139
204
  /**
140
- * Commits all staged changes to `gitState`, advancing `headCommit` and
141
- * synchronizing `headFiles` & `headSnapshot`, prepending the new commit record,
142
- * and clearing the staging area. Throws if message or staging area is empty.
205
+ * Commits all staged changes to `gitState`, advancing `headCommit`, updating
206
+ * `branchHeads[branch]`, synchronizing `headFiles` & `headSnapshot`, and clearing staging.
143
207
  */
144
208
  export declare function commitChanges(gitState: GitState, message: string, author?: string): string;
145
209
  /**
146
- * Discards working-tree (and staged) changes for `filePath`:
147
- * - If tracked in `HEAD`, restores `headFiles[relPath]` to `shell.vfs` (creating
148
- * parent directories first) and optional `workspaceFiles`.
149
- * - If untracked, deletes the file from `shell.vfs` and optional `workspaceFiles`.
210
+ * Discards working-tree changes for `filePath`.
211
+ * - When `options?.keepStaged === true` and `filePath` has a staged snapshot (`MM` / `AM`),
212
+ * restores the working tree to the staged index snapshot without unstaging!
213
+ * - Otherwise restores `headFiles[relPath]` (if tracked) or deletes the untracked file,
214
+ * and unstages `relPath`.
215
+ */
216
+ export declare function discardChanges(shell: GitShellLike, filePath: string, workspaceFiles?: Record<string, string>, options?: DiscardChangesOptions): boolean;
217
+ export declare function computeMyersDiffOps(oldText: string, newText: string): DiffLineOp[];
218
+ export declare function computeUnifiedHunkDiff(file1Name: string, file2Name: string, oldText: string, newText: string, contextLines?: number): string;
219
+ export declare function computeGitGutterChanges(headContent: string | undefined, liveContent: string): GitGutterRange[];
220
+ export interface CheckoutBranchOptions {
221
+ create?: boolean;
222
+ force?: boolean;
223
+ workspaceFiles?: Record<string, string>;
224
+ }
225
+ export declare function checkoutBranch(target: GitShellLike | GitState, branchName: string, options?: CheckoutBranchOptions): {
226
+ ok: boolean;
227
+ created: boolean;
228
+ error?: string;
229
+ };
230
+ export declare function resolveCommitRef(gitState: GitState, refSpec?: string): {
231
+ commit: GitCommitRecord | null;
232
+ index: number;
233
+ };
234
+ export declare function resetToRef(shell: GitShellLike, refSpec?: string, mode?: 'soft' | 'mixed' | 'hard', workspaceFiles?: Record<string, string>): {
235
+ ok: boolean;
236
+ headCommit: string;
237
+ message?: string;
238
+ error?: string;
239
+ };
240
+ export declare function stashPush(shell: GitShellLike, message?: string, includeUntracked?: boolean, workspaceFiles?: Record<string, string>): {
241
+ ok: boolean;
242
+ created: boolean;
243
+ label: string;
244
+ };
245
+ export declare function stashApply(shell: GitShellLike, stashIndex?: number, dropAfter?: boolean, workspaceFiles?: Record<string, string>): {
246
+ ok: boolean;
247
+ error?: string;
248
+ message?: string;
249
+ };
250
+ export declare function mergeBranch(shell: GitShellLike, sourceBranch: string, workspaceFiles?: Record<string, string>): {
251
+ ok: boolean;
252
+ fastForward: boolean;
253
+ conflicts: string[];
254
+ commitHash?: string;
255
+ message: string;
256
+ };
257
+ export declare function showCommit(gitState: GitState, refSpec?: string): {
258
+ ok: boolean;
259
+ output: string;
260
+ };
261
+ export declare function blameFile(gitState: GitState, relPath: string, liveContent?: string): {
262
+ ok: boolean;
263
+ entries: BlameLineEntry[];
264
+ output: string;
265
+ };
266
+ export declare function createIsoGitFsAdapter(vfs: GitVfsLike): {
267
+ promises: {
268
+ readFile: (p: string, opts?: {
269
+ encoding?: string;
270
+ } | string) => Promise<Uint8Array | string>;
271
+ writeFile: (p: string, data: Uint8Array | string) => Promise<void>;
272
+ unlink: (p: string) => Promise<void>;
273
+ readdir: (p: string) => Promise<string[]>;
274
+ mkdir: (p: string) => Promise<void>;
275
+ rmdir: (p: string) => Promise<void>;
276
+ stat: (p: string) => Promise<{
277
+ type: 'file' | 'dir';
278
+ mode: number;
279
+ size: number;
280
+ ino: number;
281
+ mtimeMs: number;
282
+ ctimeMs: number;
283
+ uid: number;
284
+ gid: number;
285
+ dev: number;
286
+ isFile: () => boolean;
287
+ isDirectory: () => boolean;
288
+ isSymbolicLink: () => boolean;
289
+ }>;
290
+ lstat: (p: string) => Promise<{
291
+ type: 'file' | 'dir';
292
+ mode: number;
293
+ size: number;
294
+ ino: number;
295
+ mtimeMs: number;
296
+ ctimeMs: number;
297
+ uid: number;
298
+ gid: number;
299
+ dev: number;
300
+ isFile: () => boolean;
301
+ isDirectory: () => boolean;
302
+ isSymbolicLink: () => boolean;
303
+ }>;
304
+ readlink: (p: string) => Promise<string>;
305
+ symlink: (target: string, p: string) => Promise<void>;
306
+ };
307
+ };
308
+ /**
309
+ * Mirrors `gitState` branch & HEAD state into a real `isomorphic-git` `.git/`
310
+ * directory inside `vfs` so real Git objects/refs/HEAD live on disk for IndexedDB persistence.
311
+ */
312
+ export declare function syncToIsoGitRepo(vfs: GitVfsLike, gitState: GitState): Promise<void>;
313
+ /**
314
+ * Hydrates a `GitState` from an existing `isomorphic-git` `.git/` object store
315
+ * in `vfs` (for example after restoring `.git/**` from IndexedDB).
150
316
  */
151
- export declare function discardChanges(shell: GitShellLike, filePath: string, workspaceFiles?: Record<string, string>): boolean;
317
+ export declare function hydrateFromIsoGitRepo(vfs: GitVfsLike, repoRoot?: string): Promise<GitState | null>;
318
+ declare const isoGit: {
319
+ init: typeof isoInit;
320
+ add: typeof isoAdd;
321
+ commit: typeof isoCommit;
322
+ currentBranch: typeof isoCurrentBranch;
323
+ listBranches: typeof isoListBranches;
324
+ log: typeof isoLog;
325
+ };
326
+ export { isoGit };
152
327
  declare const _default: {
153
328
  computeShortCommitHash: typeof computeShortCommitHash;
329
+ parseGitignoreRules: typeof parseGitignoreRules;
330
+ isIgnoredByRules: typeof isIgnoredByRules;
154
331
  isIgnoredScmPath: typeof isIgnoredScmPath;
155
332
  normalizeScmRelPath: typeof normalizeScmRelPath;
156
333
  isUnbornGitHead: typeof isUnbornGitHead;
157
334
  isEffectiveStagedChange: typeof isEffectiveStagedChange;
158
335
  syncGitHead: typeof syncGitHead;
336
+ saveBranchTip: typeof saveBranchTip;
159
337
  createGitState: typeof createGitState;
338
+ readVfsTree: typeof readVfsTree;
160
339
  initRepository: typeof initRepository;
161
340
  computeGitStatus: typeof computeGitStatus;
162
341
  stageFile: typeof stageFile;
@@ -165,5 +344,27 @@ declare const _default: {
165
344
  unstageAll: typeof unstageAll;
166
345
  commitChanges: typeof commitChanges;
167
346
  discardChanges: typeof discardChanges;
347
+ computeMyersDiffOps: typeof computeMyersDiffOps;
348
+ computeUnifiedHunkDiff: typeof computeUnifiedHunkDiff;
349
+ computeGitGutterChanges: typeof computeGitGutterChanges;
350
+ checkoutBranch: typeof checkoutBranch;
351
+ resolveCommitRef: typeof resolveCommitRef;
352
+ resetToRef: typeof resetToRef;
353
+ stashPush: typeof stashPush;
354
+ stashApply: typeof stashApply;
355
+ mergeBranch: typeof mergeBranch;
356
+ showCommit: typeof showCommit;
357
+ blameFile: typeof blameFile;
358
+ createIsoGitFsAdapter: typeof createIsoGitFsAdapter;
359
+ syncToIsoGitRepo: typeof syncToIsoGitRepo;
360
+ hydrateFromIsoGitRepo: typeof hydrateFromIsoGitRepo;
361
+ isoGit: {
362
+ init: typeof isoInit;
363
+ add: typeof isoAdd;
364
+ commit: typeof isoCommit;
365
+ currentBranch: typeof isoCurrentBranch;
366
+ listBranches: typeof isoListBranches;
367
+ log: typeof isoLog;
368
+ };
168
369
  };
169
370
  export default _default;