@ibgib/vcs-gib 0.0.30 → 0.0.32

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 (151) hide show
  1. package/dist/AUTO-GENERATED-version.d.mts +1 -1
  2. package/dist/AUTO-GENERATED-version.mjs +1 -1
  3. package/dist/bootstrap/node-bootstrap.mjs +1 -1
  4. package/dist/bootstrap/node-bootstrap.mjs.map +1 -1
  5. package/dist/cli/commands/add-cmd.d.mts +2 -3
  6. package/dist/cli/commands/add-cmd.d.mts.map +1 -1
  7. package/dist/cli/commands/add-cmd.mjs +30 -283
  8. package/dist/cli/commands/add-cmd.mjs.map +1 -1
  9. package/dist/cli/commands/branch-cmd.d.mts +8 -8
  10. package/dist/cli/commands/branch-cmd.d.mts.map +1 -1
  11. package/dist/cli/commands/branch-cmd.mjs +45 -176
  12. package/dist/cli/commands/branch-cmd.mjs.map +1 -1
  13. package/dist/cli/commands/checkout-cmd.d.mts +2 -4
  14. package/dist/cli/commands/checkout-cmd.d.mts.map +1 -1
  15. package/dist/cli/commands/checkout-cmd.mjs +31 -110
  16. package/dist/cli/commands/checkout-cmd.mjs.map +1 -1
  17. package/dist/cli/commands/commit-cmd.d.mts +7 -8
  18. package/dist/cli/commands/commit-cmd.d.mts.map +1 -1
  19. package/dist/cli/commands/commit-cmd.mjs +40 -390
  20. package/dist/cli/commands/commit-cmd.mjs.map +1 -1
  21. package/dist/cli/commands/generate-comment-cmd.d.mts.map +1 -1
  22. package/dist/cli/commands/generate-comment-cmd.mjs +5 -2
  23. package/dist/cli/commands/generate-comment-cmd.mjs.map +1 -1
  24. package/dist/cli/commands/init-cmd.d.mts +2 -2
  25. package/dist/cli/commands/init-cmd.d.mts.map +1 -1
  26. package/dist/cli/commands/init-cmd.mjs +20 -70
  27. package/dist/cli/commands/init-cmd.mjs.map +1 -1
  28. package/dist/cli/commands/log-cmd.d.mts +2 -3
  29. package/dist/cli/commands/log-cmd.d.mts.map +1 -1
  30. package/dist/cli/commands/log-cmd.mjs +42 -271
  31. package/dist/cli/commands/log-cmd.mjs.map +1 -1
  32. package/dist/cli/commands/merge-cmd.d.mts +3 -17
  33. package/dist/cli/commands/merge-cmd.d.mts.map +1 -1
  34. package/dist/cli/commands/merge-cmd.mjs +32 -218
  35. package/dist/cli/commands/merge-cmd.mjs.map +1 -1
  36. package/dist/cli/commands/reset-cmd.d.mts +1 -1
  37. package/dist/cli/commands/reset-cmd.d.mts.map +1 -1
  38. package/dist/cli/commands/reset-cmd.mjs +17 -19
  39. package/dist/cli/commands/reset-cmd.mjs.map +1 -1
  40. package/dist/cli/commands/restore-cmd.d.mts +8 -7
  41. package/dist/cli/commands/restore-cmd.d.mts.map +1 -1
  42. package/dist/cli/commands/restore-cmd.mjs +44 -62
  43. package/dist/cli/commands/restore-cmd.mjs.map +1 -1
  44. package/dist/cli/commands/status-cmd.d.mts +2 -2
  45. package/dist/cli/commands/status-cmd.d.mts.map +1 -1
  46. package/dist/cli/commands/status-cmd.mjs +63 -62
  47. package/dist/cli/commands/status-cmd.mjs.map +1 -1
  48. package/dist/cli/vcs-projection-helper.d.mts +23 -0
  49. package/dist/cli/vcs-projection-helper.d.mts.map +1 -0
  50. package/dist/cli/vcs-projection-helper.mjs +91 -0
  51. package/dist/cli/vcs-projection-helper.mjs.map +1 -0
  52. package/dist/test/test-helpers.d.mts +2 -2
  53. package/dist/test/test-helpers.d.mts.map +1 -1
  54. package/package.json +3 -3
  55. package/src/AUTO-GENERATED-version.mts +1 -1
  56. package/src/bootstrap/node-bootstrap.mts +1 -1
  57. package/src/cli/cli-e2e.respec.mts +4 -4
  58. package/src/cli/commands/add-cmd.mts +32 -347
  59. package/src/cli/commands/branch-cmd.mts +56 -225
  60. package/src/cli/commands/checkout-cmd.mts +34 -138
  61. package/src/cli/commands/commit-cmd.mts +46 -473
  62. package/src/cli/commands/commit-log-cmd.respec.mts +11 -7
  63. package/src/cli/commands/generate-comment-cmd.mts +6 -2
  64. package/src/cli/commands/init-cmd.mts +20 -73
  65. package/src/cli/commands/log-cmd.mts +41 -331
  66. package/src/cli/commands/merge-cmd.mts +32 -252
  67. package/src/cli/commands/reset-cmd.mts +17 -19
  68. package/src/cli/commands/restore-cmd.mts +52 -72
  69. package/src/cli/commands/status-add-cmd.respec.mts +3 -3
  70. package/src/cli/commands/status-cmd.mts +68 -63
  71. package/src/cli/vcs-projection-helper.mts +112 -0
  72. package/src/engine/branch/branch-space.respec.mts +5 -5
  73. package/src/engine/merge/b2tfs-sync-comments.respec.mts +4 -4
  74. package/src/test/test-helpers.mts +2 -2
  75. package/src/vcs-gib.respec.mts +11 -8
  76. package/tsconfig.test.tsbuildinfo +1 -1
  77. package/tsconfig.tsbuildinfo +1 -1
  78. package/dist/engine/branch/branch-graph-helper.d.mts +0 -28
  79. package/dist/engine/branch/branch-graph-helper.d.mts.map +0 -1
  80. package/dist/engine/branch/branch-graph-helper.mjs +0 -81
  81. package/dist/engine/branch/branch-graph-helper.mjs.map +0 -1
  82. package/dist/engine/branch/branch-helper.d.mts +0 -40
  83. package/dist/engine/branch/branch-helper.d.mts.map +0 -1
  84. package/dist/engine/branch/branch-helper.mjs +0 -78
  85. package/dist/engine/branch/branch-helper.mjs.map +0 -1
  86. package/dist/engine/branch/branch-space-helper.d.mts +0 -23
  87. package/dist/engine/branch/branch-space-helper.d.mts.map +0 -1
  88. package/dist/engine/branch/branch-space-helper.mjs +0 -78
  89. package/dist/engine/branch/branch-space-helper.mjs.map +0 -1
  90. package/dist/engine/branch/branch-types.d.mts +0 -26
  91. package/dist/engine/branch/branch-types.d.mts.map +0 -1
  92. package/dist/engine/branch/branch-types.mjs +0 -7
  93. package/dist/engine/branch/branch-types.mjs.map +0 -1
  94. package/dist/engine/diff/line-diff-helper.d.mts +0 -76
  95. package/dist/engine/diff/line-diff-helper.d.mts.map +0 -1
  96. package/dist/engine/diff/line-diff-helper.mjs +0 -144
  97. package/dist/engine/diff/line-diff-helper.mjs.map +0 -1
  98. package/dist/engine/filter/glob-helper.d.mts +0 -51
  99. package/dist/engine/filter/glob-helper.d.mts.map +0 -1
  100. package/dist/engine/filter/glob-helper.mjs +0 -132
  101. package/dist/engine/filter/glob-helper.mjs.map +0 -1
  102. package/dist/engine/index/index-helper.d.mts +0 -113
  103. package/dist/engine/index/index-helper.d.mts.map +0 -1
  104. package/dist/engine/index/index-helper.mjs +0 -533
  105. package/dist/engine/index/index-helper.mjs.map +0 -1
  106. package/dist/engine/index/index-types.d.mts +0 -63
  107. package/dist/engine/index/index-types.d.mts.map +0 -1
  108. package/dist/engine/index/index-types.mjs +0 -7
  109. package/dist/engine/index/index-types.mjs.map +0 -1
  110. package/dist/engine/item/item-atom-helper.d.mts +0 -20
  111. package/dist/engine/item/item-atom-helper.d.mts.map +0 -1
  112. package/dist/engine/item/item-atom-helper.mjs +0 -30
  113. package/dist/engine/item/item-atom-helper.mjs.map +0 -1
  114. package/dist/engine/item/item-helper.d.mts +0 -94
  115. package/dist/engine/item/item-helper.d.mts.map +0 -1
  116. package/dist/engine/item/item-helper.mjs +0 -424
  117. package/dist/engine/item/item-helper.mjs.map +0 -1
  118. package/dist/engine/item/item-types.d.mts +0 -128
  119. package/dist/engine/item/item-types.d.mts.map +0 -1
  120. package/dist/engine/item/item-types.mjs +0 -16
  121. package/dist/engine/item/item-types.mjs.map +0 -1
  122. package/dist/engine/merge/b2tfs-3way-graft-strategy.d.mts +0 -74
  123. package/dist/engine/merge/b2tfs-3way-graft-strategy.d.mts.map +0 -1
  124. package/dist/engine/merge/b2tfs-3way-graft-strategy.mjs +0 -570
  125. package/dist/engine/merge/b2tfs-3way-graft-strategy.mjs.map +0 -1
  126. package/dist/engine/merge/b2tfs-3way-graft-types.d.mts +0 -34
  127. package/dist/engine/merge/b2tfs-3way-graft-types.d.mts.map +0 -1
  128. package/dist/engine/merge/b2tfs-3way-graft-types.mjs +0 -2
  129. package/dist/engine/merge/b2tfs-3way-graft-types.mjs.map +0 -1
  130. package/dist/engine/status/status-helper.d.mts +0 -90
  131. package/dist/engine/status/status-helper.d.mts.map +0 -1
  132. package/dist/engine/status/status-helper.mjs +0 -286
  133. package/dist/engine/status/status-helper.mjs.map +0 -1
  134. package/src/engine/branch/branch-graph-helper.mts +0 -117
  135. package/src/engine/branch/branch-helper.mts +0 -112
  136. package/src/engine/branch/branch-space-helper.mts +0 -110
  137. package/src/engine/branch/branch-types.mts +0 -29
  138. package/src/engine/diff/line-diff-helper.mts +0 -210
  139. package/src/engine/diff/line-diff-helper.respec.mts +0 -84
  140. package/src/engine/filter/glob-helper.mts +0 -165
  141. package/src/engine/filter/glob-helper.respec.mts +0 -94
  142. package/src/engine/index/index-helper.mts +0 -705
  143. package/src/engine/index/index-types.mts +0 -66
  144. package/src/engine/item/item-atom-helper.mts +0 -30
  145. package/src/engine/item/item-helper.mts +0 -544
  146. package/src/engine/item/item-types.mts +0 -137
  147. package/src/engine/item/item.respec.mts +0 -92
  148. package/src/engine/merge/b2tfs-3way-graft-strategy.mts +0 -630
  149. package/src/engine/merge/b2tfs-3way-graft-strategy.respec.mts +0 -346
  150. package/src/engine/merge/b2tfs-3way-graft-types.mts +0 -34
  151. package/src/engine/status/status-helper.mts +0 -383
@@ -1,36 +1,21 @@
1
1
  /**
2
2
  * @module add-cmd
3
3
  *
4
- * Command handler for `vcs add <path...>`.
5
- * Stages files and directories into candidate B2tFSItemIbGib_V1 and BinIbGib_V1 graph nodes
6
- * and updates B2tFSIndexIbGib_V1 in localSpace.
4
+ * CLI command handler for `vcs add <path...>`.
5
+ * Bootstraps workspace projection space and delegates to executeVcsAdd.
7
6
  */
8
7
 
9
8
  import path from 'node:path';
10
9
  import fs from 'node:fs/promises';
11
- import crypto from 'node:crypto';
12
10
 
13
- import { extractErrorMsg, getUUID } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
14
- import { Factory_V1 } from '@ibgib/ts-gib/dist/V1/factory.mjs';
15
- import { ROOT } from '@ibgib/ts-gib/dist/V1/constants.mjs';
16
- import { getGib } from '@ibgib/ts-gib/dist/V1/transforms/transform-helper.mjs';
17
- import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs';
18
- import { BinIbGib_V1 } from '@ibgib/core-gib/dist/common/bin/bin-types.mjs';
19
- import { putInSpace, persistTransformResult } from '@ibgib/core-gib/dist/witness/space/space-helper.mjs';
11
+ import { extractErrorMsg } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
12
+ import { executeVcsAdd } from '@ibgib/core-gib/dist/vcs/commands/add-cmd.mjs';
13
+ import { resolveContextualBranchName } from '@ibgib/core-gib/dist/vcs/branch/branch-helper.mjs';
20
14
 
21
15
  import { bootstrapVcsMetaspace } from '../../bootstrap/node-bootstrap.mjs';
22
- import { getOrCreateBranchSpace } from '../../engine/branch/branch-space-helper.mjs';
23
- import { resolveContextualBranchName } from '../../engine/branch/branch-helper.mjs';
24
- import { isCommentMetadataFilename } from '../../engine/status/status-helper.mjs';
25
- import { getB2tFSItemIb } from '../../engine/item/item-atom-helper.mjs';
26
- import { B2tFSItemIbGib_V1, B2TFS_CHILD_ITEM_REL8N_NAME } from '../../engine/item/item-types.mjs';
27
- import { getIbGibWithMetaspaceFallback, createB2tFSItemIbGib, evolveB2tFSItemIbGib } from '../../engine/item/item-helper.mjs';
28
- import { B2tFSBranchIbGib_V1 } from '../../engine/branch/branch-types.mjs';
29
- import { isPathFiltered, parseFilterFileContent, globToRegExp } from '../../engine/filter/glob-helper.mjs';
30
- import { getB2tFSIndexIbGib, updateB2tFSIndexIbGib } from '../../engine/index/index-helper.mjs';
31
- import { B2tFSStagedItemRecord } from '../../engine/index/index-types.mjs';
32
- import { TransformResult } from '@ibgib/ts-gib/dist/types.mjs';
33
- import { IbGib_V1 } from '@ibgib/ts-gib/dist/V1/types.mjs';
16
+ import { getOrCreateBranchSpace } from '@ibgib/node-gib/dist/vcs/branch-space-helper.mjs';
17
+ import { getOrCreateWorkspaceProjectionSpace } from '@ibgib/node-gib/dist/vcs/workspace-space-helper.mjs';
18
+ import { readVcsIndexProjectionFromDisk, writeVcsIndexProjectionToDisk } from '../vcs-projection-helper.mjs';
34
19
  import { GLOBAL_LOG_A_LOT } from '../../vcs-gib-constants.mjs';
35
20
 
36
21
  const lcFile = `[add-cmd]`;
@@ -75,7 +60,7 @@ export async function executeAddCmd({
75
60
  }
76
61
 
77
62
  // Retrieve authoritative B2tFSIndexIbGib_V1 from space
78
- const indexIbGib = await getB2tFSIndexIbGib({ space: localSpace, vcsPath });
63
+ const indexIbGib = await readVcsIndexProjectionFromDisk({ vcsPath, space: localSpace });
79
64
  if (!indexIbGib) {
80
65
  throw new Error(`Repository not initialized. Run 'vcs init' first. (E: 2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e)`);
81
66
  }
@@ -94,241 +79,37 @@ export async function executeAddCmd({
94
79
  branchName: activeBranch,
95
80
  });
96
81
 
97
- // Read .ibgibignore if present in active worktree
98
- let filterPatterns: string[] = [];
99
- const ignorePath = path.join(activeWorktreeDir, '.ibgibignore');
100
- try {
101
- const ignoreContent = await fs.readFile(ignorePath, 'utf8');
102
- filterPatterns = parseFilterFileContent(ignoreContent);
103
- } catch {
104
- // Ignore file not found is fine
105
- }
106
-
107
- // Walk active branch graph items to find committed files in snapshot
108
- const committedBranchItemsMap = new Map<string, { relPath: string; fileHash?: string; fsType: 'file' | 'folder'; item?: B2tFSItemIbGib_V1 }>();
109
- const branchAddrs = [
110
- ...(indexIbGib?.rel8ns?.branch || []),
111
- ...(indexIbGib?.rel8ns?.branch_tjp || []),
112
- ];
113
-
114
- if (branchAddrs.length > 0) {
115
- let branchIbGibs: B2tFSBranchIbGib_V1[] = [];
116
- for (const bAddr of branchAddrs) {
117
- const bIbGib = await getIbGibWithMetaspaceFallback({
118
- addr: bAddr,
119
- space: activeSpace,
120
- metaspace,
121
- });
122
- if (bIbGib) {
123
- branchIbGibs.push(bIbGib as B2tFSBranchIbGib_V1);
124
- }
125
- }
126
-
127
- const activeBranchIbGib = branchIbGibs.findLast(
128
- (b) => (b as B2tFSBranchIbGib_V1)?.data?.name === activeBranch,
129
- ) as B2tFSBranchIbGib_V1 || (branchIbGibs.at(-1) as B2tFSBranchIbGib_V1);
130
-
131
-
132
- const rootItemAddr = activeBranchIbGib?.rel8ns?.b2tfs_item?.at(-1);
133
-
134
- if (rootItemAddr) {
135
- const rootItem = await getIbGibWithMetaspaceFallback({
136
- addr: rootItemAddr,
137
- space: activeSpace,
138
- metaspace,
139
- }) as B2tFSItemIbGib_V1;
140
-
141
- if (rootItem) {
142
- await addCmd_walkBranchGraph({
143
- item: rootItem,
144
- space: activeSpace,
145
- metaspace,
146
- currentRelPath: '',
147
- outMap: committedBranchItemsMap,
148
- });
149
- }
150
- }
151
- }
152
-
153
- // Determine candidate file paths to stage
154
- const targetFilePaths: string[] = [];
155
-
156
- if (all || paths.length === 0 || (paths.length === 1 && paths[0] === '.')) {
157
- await addCmd_collectFilesRecursively({
158
- dirPath: activeWorktreeDir,
159
- baseDir: activeWorktreeDir,
160
- vcsFolderName,
161
- filterPatterns,
162
- outFiles: targetFilePaths,
163
- });
164
- } else {
165
- for (const relOrAbs of paths) {
166
- if (relOrAbs.includes('*') || relOrAbs.includes('?')) {
167
- const rx = globToRegExp(relOrAbs);
168
-
169
- const candidateFiles: string[] = [];
170
- await addCmd_collectFilesRecursively({
171
- dirPath: activeWorktreeDir,
172
- baseDir: activeWorktreeDir,
173
- vcsFolderName,
174
- filterPatterns,
175
- outFiles: candidateFiles,
176
- });
177
-
178
- let matchedCount = 0;
179
- for (const candidateAbsPath of candidateFiles) {
180
- const candidateRelPath = path.relative(activeWorktreeDir, candidateAbsPath).replace(/\\/g, '/');
181
- const pathBasename = candidateRelPath.split('/').pop() || candidateRelPath;
182
-
183
- if (rx.test(candidateRelPath) || rx.test(pathBasename)) {
184
- if (!targetFilePaths.includes(candidateAbsPath)) {
185
- targetFilePaths.push(candidateAbsPath);
186
- }
187
- matchedCount++;
188
- }
189
- }
190
-
191
- if (matchedCount === 0) {
192
- throw new Error(`No files matched glob pattern: ${relOrAbs} (E: e23d4c5f6a7b8c9d0e1f2a3b4c5d6e7f)`);
193
- }
194
- } else {
195
- const fullPath = path.isAbsolute(relOrAbs) ? relOrAbs : path.resolve(absTargetDir, relOrAbs);
196
- let stat;
197
- try {
198
- stat = await fs.stat(fullPath);
199
- } catch {
200
- throw new Error(`Path does not exist: ${relOrAbs} (E: 10c11d12e13f14a15b16c17d18e19f20)`);
201
- }
202
-
203
- const relPath = path.relative(activeWorktreeDir, fullPath).replace(/\\/g, '/');
204
- if (relPath.startsWith('..') || path.isAbsolute(relPath)) {
205
- throw new Error(`Path '${relOrAbs}' is outside of active worktree repository (E: 7c8d9e0f1a2b3c4d5e6f7a8b9c0d1e2f)`);
206
- }
207
-
208
- if (isPathFiltered({ relativePath: relPath, isDirectory: stat.isDirectory(), filterPatterns })) {
209
- continue;
210
- }
211
-
212
- if (stat.isDirectory()) {
213
- await addCmd_collectFilesRecursively({
214
- dirPath: fullPath,
215
- baseDir: activeWorktreeDir,
216
- vcsFolderName,
217
- filterPatterns,
218
- outFiles: targetFilePaths,
219
- });
220
- } else if (stat.isFile()) {
221
- if (!targetFilePaths.includes(fullPath)) {
222
- targetFilePaths.push(fullPath);
223
- }
224
- }
225
- }
226
- }
227
- }
228
-
229
- const stagedItemAddrs: string[] = [...(indexIbGib.data?.staged_item || [])];
230
- const stagedPathsMap: { [relPath: string]: B2tFSStagedItemRecord } = { ...(indexIbGib.data?.stagedPaths || {}) };
231
- const newlyStagedPaths: string[] = [];
232
-
233
- for (const absFilePath of targetFilePaths) {
234
- const relPath = path.relative(activeWorktreeDir, absFilePath).replace(/\\/g, '/');
235
-
236
- // Read file data & compute hash
237
- const fileData = await fs.readFile(absFilePath);
238
- const fileHash = crypto.createHash('sha256').update(fileData).digest('hex');
239
-
240
- // Skip staging if candidate file matches active branch committed snapshot
241
- const committedItem = committedBranchItemsMap.get(relPath);
242
- if (committedItem && committedItem.fileHash && committedItem.fileHash === fileHash) {
243
- continue;
244
- }
245
-
246
- // 1. Create BinIbGib_V1 graph node as Uint8Array
247
- const binData = new Uint8Array(fileData);
248
- const binIb = `bin ${fileHash}`;
249
- const binGib = await getGib({ ibGib: { ib: binIb, data: binData as any } });
250
- const binIbGib: BinIbGib_V1 = {
251
- ib: binIb,
252
- gib: binGib,
253
- data: binData as any,
254
- };
255
- const binAddr = getIbGibAddr({ ibGib: binIbGib });
256
- await putInSpace({ ibGib: binIbGib, space: activeSpace });
257
- await metaspace.registerNewIbGib({ ibGib: binIbGib, space: activeSpace });
258
-
259
- // 2. Create or Evolve B2tFSItemIbGib_V1 candidate graph node
260
- const fileName = path.basename(absFilePath);
261
- const nameHash = crypto.createHash('sha256').update(fileName).digest('hex');
262
-
263
- let itemRes: TransformResult<IbGib_V1>;
264
- if (committedItem && committedItem.item) {
265
- itemRes = await evolveB2tFSItemIbGib({
266
- existingItem: committedItem.item,
267
- dataToUpdate: {
268
- fileHash,
269
- },
270
- rel8nsToUpdate: {
271
- bin: [binAddr],
272
- },
273
- });
274
- } else {
275
- itemRes = await createB2tFSItemIbGib({
276
- fsType: 'file',
277
- name: fileName,
278
- data: {
279
- nameHash,
280
- fileHash,
281
- fileEncoding: 'utf8',
282
- },
283
- rel8ns: {
284
- bin: [binAddr],
285
- },
286
- });
287
- }
288
-
289
- const itemIbGib = itemRes.newIbGib as B2tFSItemIbGib_V1;
290
- const itemAddr = getIbGibAddr({ ibGib: itemIbGib });
291
- await persistTransformResult({ resTransform: itemRes, space: activeSpace });
292
- await metaspace.registerNewIbGib({ ibGib: itemIbGib, space: activeSpace });
293
-
294
- if (!stagedItemAddrs.includes(itemAddr)) {
295
- stagedItemAddrs.push(itemAddr);
296
- }
297
-
298
- stagedPathsMap[relPath] = {
299
- itemAddr,
300
- binAddr,
301
- fileHash,
302
- fsType: 'file',
303
- stagedAt: new Date().toISOString(),
304
- };
305
-
306
- newlyStagedPaths.push(relPath);
307
-
308
- if (!quiet) {
309
- console.log(`staged: ${relPath}`);
310
- }
311
- }
82
+ const { space: workspaceSpace } = await getOrCreateWorkspaceProjectionSpace({
83
+ metaspace,
84
+ workspaceRoot: activeWorktreeDir,
85
+ vcsFolderName,
86
+ backingSpace: activeSpace,
87
+ });
312
88
 
313
- // 3. Update B2tFSIndexIbGib_V1 in activeSpace & localSpace
314
- const updatedIndex = await updateB2tFSIndexIbGib({
315
- space: activeSpace,
89
+ const addRes = await executeVcsAdd({
316
90
  metaspace,
91
+ localSpace,
92
+ activeBranchSpace: activeSpace,
93
+ workspaceSpace,
317
94
  indexIbGib,
318
- dataToUpdate: {
319
- stagedPaths: stagedPathsMap,
320
- staged_item: stagedItemAddrs,
321
- },
322
- vcsPath,
95
+ paths,
96
+ all,
97
+ repoRoot,
98
+ targetDir: absTargetDir,
99
+ vcsFolderName,
323
100
  });
324
101
 
325
- if (localSpace !== activeSpace) {
326
- await putInSpace({ space: localSpace, ibGib: updatedIndex });
102
+ await writeVcsIndexProjectionToDisk({ vcsPath, indexIbGib: addRes.updatedIndex });
103
+
104
+ if (!quiet) {
105
+ for (const stagedPath of addRes.stagedPaths) {
106
+ console.log(`staged: ${stagedPath}`);
107
+ }
327
108
  }
328
109
 
329
110
  return {
330
- stagedPaths: newlyStagedPaths,
331
- stagedCount: newlyStagedPaths.length,
111
+ stagedPaths: addRes.stagedPaths,
112
+ stagedCount: addRes.stagedCount,
332
113
  };
333
114
  } catch (error) {
334
115
  console.error(`${lc} ${extractErrorMsg(error)} (E: 3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f)`);
@@ -337,99 +118,3 @@ export async function executeAddCmd({
337
118
  if (logalot) { console.log(`${lc} complete. (I: 4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a)`); }
338
119
  }
339
120
  }
340
-
341
- // #region addCmd_walkBranchGraph
342
- async function addCmd_walkBranchGraph({
343
- item,
344
- space,
345
- metaspace,
346
- currentRelPath,
347
- outMap,
348
- }: {
349
- item: B2tFSItemIbGib_V1;
350
- space: any;
351
- metaspace?: any;
352
- currentRelPath: string;
353
- outMap: Map<string, { relPath: string; fileHash?: string; fsType: 'file' | 'folder'; item?: B2tFSItemIbGib_V1 }>;
354
- }): Promise<void> {
355
- if (!item || !item.data) { return; }
356
-
357
- const { fsType, fileHash } = item.data;
358
- if (currentRelPath) {
359
- outMap.set(currentRelPath, { relPath: currentRelPath, fileHash, fsType, item });
360
- }
361
-
362
- if (fsType === 'folder') {
363
- const childAddrs = item.rel8ns?.[B2TFS_CHILD_ITEM_REL8N_NAME] || [];
364
- for (const childAddr of childAddrs) {
365
- const childItem = await getIbGibWithMetaspaceFallback({
366
- addr: childAddr,
367
- space,
368
- metaspace,
369
- }) as B2tFSItemIbGib_V1;
370
- if (childItem && childItem.data) {
371
- const childRelPath = currentRelPath
372
- ? `${currentRelPath}/${childItem.data.name}`
373
- : childItem.data.name;
374
- await addCmd_walkBranchGraph({
375
- item: childItem,
376
- space,
377
- metaspace,
378
- currentRelPath: childRelPath,
379
- outMap,
380
- });
381
- }
382
- }
383
- }
384
- }
385
- // #endregion addCmd_walkBranchGraph
386
-
387
- // #region addCmd_collectFilesRecursively
388
- async function addCmd_collectFilesRecursively({
389
- dirPath,
390
- baseDir,
391
- vcsFolderName,
392
- filterPatterns,
393
- outFiles,
394
- }: {
395
- dirPath: string;
396
- baseDir: string;
397
- vcsFolderName: string;
398
- filterPatterns: string[];
399
- outFiles: string[];
400
- }): Promise<void> {
401
- const entries = await fs.readdir(dirPath, { withFileTypes: true });
402
-
403
- for (const entry of entries) {
404
- const fullPath = path.join(dirPath, entry.name);
405
- const relPath = path.relative(baseDir, fullPath).replace(/\\/g, '/');
406
-
407
- // Ignore vcs storage folder, .git, and worktrees folder b
408
- if (
409
- relPath === vcsFolderName || relPath.startsWith(vcsFolderName + '/') ||
410
- relPath === '.git' || relPath.startsWith('.git/') ||
411
- relPath === 'b' || relPath.startsWith('b/')
412
- ) {
413
- continue;
414
- }
415
-
416
- if (isPathFiltered({ relativePath: relPath, isDirectory: entry.isDirectory(), filterPatterns })) {
417
- continue;
418
- }
419
-
420
- if (entry.isDirectory()) {
421
- await addCmd_collectFilesRecursively({
422
- dirPath: fullPath,
423
- baseDir,
424
- vcsFolderName,
425
- filterPatterns,
426
- outFiles,
427
- });
428
- } else if (entry.isFile()) {
429
- if (!isCommentMetadataFilename(entry.name)) {
430
- outFiles.push(fullPath);
431
- }
432
- }
433
- }
434
- }
435
- // #endregion addCmd_collectFilesRecursively