@ibgib/vcs-gib 0.0.30 → 0.0.33

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 (216) 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.d.mts.map +1 -1
  4. package/dist/bootstrap/node-bootstrap.mjs +7 -21
  5. package/dist/bootstrap/node-bootstrap.mjs.map +1 -1
  6. package/dist/cli/commands/{add-cmd.d.mts → cli-add-cmd.d.mts} +3 -4
  7. package/dist/cli/commands/cli-add-cmd.d.mts.map +1 -0
  8. package/dist/cli/commands/cli-add-cmd.mjs +45 -0
  9. package/dist/cli/commands/cli-add-cmd.mjs.map +1 -0
  10. package/dist/cli/commands/{branch-cmd.d.mts → cli-branch-cmd.d.mts} +9 -9
  11. package/dist/cli/commands/cli-branch-cmd.d.mts.map +1 -0
  12. package/dist/cli/commands/cli-branch-cmd.mjs +59 -0
  13. package/dist/cli/commands/cli-branch-cmd.mjs.map +1 -0
  14. package/dist/cli/commands/cli-checkout-cmd.d.mts +20 -0
  15. package/dist/cli/commands/cli-checkout-cmd.d.mts.map +1 -0
  16. package/dist/cli/commands/cli-checkout-cmd.mjs +50 -0
  17. package/dist/cli/commands/cli-checkout-cmd.mjs.map +1 -0
  18. package/dist/cli/commands/cli-commit-cmd.d.mts +23 -0
  19. package/dist/cli/commands/cli-commit-cmd.d.mts.map +1 -0
  20. package/dist/cli/commands/cli-commit-cmd.mjs +52 -0
  21. package/dist/cli/commands/cli-commit-cmd.mjs.map +1 -0
  22. package/dist/cli/commands/{generate-comment-cmd.d.mts → cli-generate-comment-cmd.d.mts} +1 -1
  23. package/dist/cli/commands/cli-generate-comment-cmd.d.mts.map +1 -0
  24. package/dist/cli/commands/{generate-comment-cmd.mjs → cli-generate-comment-cmd.mjs} +11 -6
  25. package/dist/cli/commands/cli-generate-comment-cmd.mjs.map +1 -0
  26. package/dist/cli/commands/{init-cmd.d.mts → cli-init-cmd.d.mts} +3 -3
  27. package/dist/cli/commands/cli-init-cmd.d.mts.map +1 -0
  28. package/dist/cli/commands/cli-init-cmd.mjs +47 -0
  29. package/dist/cli/commands/cli-init-cmd.mjs.map +1 -0
  30. package/dist/cli/commands/{log-cmd.d.mts → cli-log-cmd.d.mts} +3 -4
  31. package/dist/cli/commands/cli-log-cmd.d.mts.map +1 -0
  32. package/dist/cli/commands/cli-log-cmd.mjs +90 -0
  33. package/dist/cli/commands/cli-log-cmd.mjs.map +1 -0
  34. package/dist/cli/commands/cli-merge-cmd.d.mts +22 -0
  35. package/dist/cli/commands/cli-merge-cmd.d.mts.map +1 -0
  36. package/dist/cli/commands/cli-merge-cmd.mjs +66 -0
  37. package/dist/cli/commands/cli-merge-cmd.mjs.map +1 -0
  38. package/dist/cli/commands/{reset-cmd.d.mts → cli-reset-cmd.d.mts} +2 -2
  39. package/dist/cli/commands/cli-reset-cmd.d.mts.map +1 -0
  40. package/dist/cli/commands/cli-reset-cmd.mjs +63 -0
  41. package/dist/cli/commands/cli-reset-cmd.mjs.map +1 -0
  42. package/dist/cli/commands/cli-restore-cmd.d.mts +23 -0
  43. package/dist/cli/commands/cli-restore-cmd.d.mts.map +1 -0
  44. package/dist/cli/commands/cli-restore-cmd.mjs +55 -0
  45. package/dist/cli/commands/cli-restore-cmd.mjs.map +1 -0
  46. package/dist/cli/commands/{status-cmd.d.mts → cli-status-cmd.d.mts} +3 -3
  47. package/dist/cli/commands/cli-status-cmd.d.mts.map +1 -0
  48. package/dist/cli/commands/cli-status-cmd.mjs +96 -0
  49. package/dist/cli/commands/cli-status-cmd.mjs.map +1 -0
  50. package/dist/cli/vcs-cli-main.d.mts.map +1 -1
  51. package/dist/cli/vcs-cli-main.mjs +18 -15
  52. package/dist/cli/vcs-cli-main.mjs.map +1 -1
  53. package/dist/cli/vcs-projection-helper.d.mts +23 -0
  54. package/dist/cli/vcs-projection-helper.d.mts.map +1 -0
  55. package/dist/cli/vcs-projection-helper.mjs +91 -0
  56. package/dist/cli/vcs-projection-helper.mjs.map +1 -0
  57. package/dist/cli/vcs-repo-helper.d.mts +19 -0
  58. package/dist/cli/vcs-repo-helper.d.mts.map +1 -0
  59. package/dist/cli/vcs-repo-helper.mjs +74 -0
  60. package/dist/cli/vcs-repo-helper.mjs.map +1 -0
  61. package/dist/test/test-helpers.d.mts +11 -2
  62. package/dist/test/test-helpers.d.mts.map +1 -1
  63. package/dist/test/test-helpers.mjs +35 -0
  64. package/dist/test/test-helpers.mjs.map +1 -1
  65. package/package.json +6 -6
  66. package/src/AUTO-GENERATED-version.mts +1 -1
  67. package/src/bootstrap/node-bootstrap.mts +7 -21
  68. package/src/bootstrap/node-bootstrap.respec.mts +2 -2
  69. package/src/cli/cli-arg-parser.respec.mts +2 -2
  70. package/src/cli/cli-e2e.respec.mts +12 -12
  71. package/src/cli/commands/branch-checkout-cmd.respec.mts +426 -412
  72. package/src/cli/commands/cli-add-cmd.mts +65 -0
  73. package/src/cli/commands/cli-branch-cmd.mts +87 -0
  74. package/src/cli/commands/cli-checkout-cmd.mts +72 -0
  75. package/src/cli/commands/cli-commit-cmd.mts +77 -0
  76. package/src/cli/commands/{generate-comment-cmd.mts → cli-generate-comment-cmd.mts} +12 -6
  77. package/src/cli/commands/cli-init-cmd.mts +78 -0
  78. package/src/cli/commands/cli-log-cmd.mts +126 -0
  79. package/src/cli/commands/cli-merge-cmd.mts +99 -0
  80. package/src/cli/commands/cli-reset-cmd.mts +94 -0
  81. package/src/cli/commands/cli-restore-cmd.mts +87 -0
  82. package/src/cli/commands/cli-status-cmd.mts +131 -0
  83. package/src/cli/commands/commit-log-cmd.respec.mts +85 -28
  84. package/src/cli/commands/init-cmd.respec.mts +3 -3
  85. package/src/cli/commands/reset-restore-cmd.respec.mts +9 -9
  86. package/src/cli/commands/status-add-cmd.respec.mts +21 -17
  87. package/src/cli/vcs-cli-main.mts +18 -15
  88. package/src/cli/vcs-projection-helper.mts +112 -0
  89. package/src/cli/vcs-repo-helper.mts +99 -0
  90. package/src/engine/branch/branch-space.respec.mts +23 -21
  91. package/src/engine/merge/b2tfs-sync-comments.respec.mts +11 -11
  92. package/src/test/test-helpers.mts +50 -2
  93. package/src/vcs-gib.respec.mts +25 -16
  94. package/tsconfig.test.tsbuildinfo +1 -1
  95. package/tsconfig.tsbuildinfo +1 -1
  96. package/vcs-gib_test_output.md +58 -0
  97. package/dist/cli/commands/add-cmd.d.mts.map +0 -1
  98. package/dist/cli/commands/add-cmd.mjs +0 -346
  99. package/dist/cli/commands/add-cmd.mjs.map +0 -1
  100. package/dist/cli/commands/branch-cmd.d.mts.map +0 -1
  101. package/dist/cli/commands/branch-cmd.mjs +0 -238
  102. package/dist/cli/commands/branch-cmd.mjs.map +0 -1
  103. package/dist/cli/commands/checkout-cmd.d.mts +0 -21
  104. package/dist/cli/commands/checkout-cmd.d.mts.map +0 -1
  105. package/dist/cli/commands/checkout-cmd.mjs +0 -174
  106. package/dist/cli/commands/checkout-cmd.mjs.map +0 -1
  107. package/dist/cli/commands/commit-cmd.d.mts +0 -24
  108. package/dist/cli/commands/commit-cmd.d.mts.map +0 -1
  109. package/dist/cli/commands/commit-cmd.mjs +0 -449
  110. package/dist/cli/commands/commit-cmd.mjs.map +0 -1
  111. package/dist/cli/commands/generate-comment-cmd.d.mts.map +0 -1
  112. package/dist/cli/commands/generate-comment-cmd.mjs.map +0 -1
  113. package/dist/cli/commands/init-cmd.d.mts.map +0 -1
  114. package/dist/cli/commands/init-cmd.mjs +0 -119
  115. package/dist/cli/commands/init-cmd.mjs.map +0 -1
  116. package/dist/cli/commands/log-cmd.d.mts.map +0 -1
  117. package/dist/cli/commands/log-cmd.mjs +0 -349
  118. package/dist/cli/commands/log-cmd.mjs.map +0 -1
  119. package/dist/cli/commands/merge-cmd.d.mts +0 -36
  120. package/dist/cli/commands/merge-cmd.d.mts.map +0 -1
  121. package/dist/cli/commands/merge-cmd.mjs +0 -292
  122. package/dist/cli/commands/merge-cmd.mjs.map +0 -1
  123. package/dist/cli/commands/reset-cmd.d.mts.map +0 -1
  124. package/dist/cli/commands/reset-cmd.mjs +0 -93
  125. package/dist/cli/commands/reset-cmd.mjs.map +0 -1
  126. package/dist/cli/commands/restore-cmd.d.mts +0 -22
  127. package/dist/cli/commands/restore-cmd.d.mts.map +0 -1
  128. package/dist/cli/commands/restore-cmd.mjs +0 -115
  129. package/dist/cli/commands/restore-cmd.mjs.map +0 -1
  130. package/dist/cli/commands/status-cmd.d.mts.map +0 -1
  131. package/dist/cli/commands/status-cmd.mjs +0 -132
  132. package/dist/cli/commands/status-cmd.mjs.map +0 -1
  133. package/dist/engine/branch/branch-graph-helper.d.mts +0 -28
  134. package/dist/engine/branch/branch-graph-helper.d.mts.map +0 -1
  135. package/dist/engine/branch/branch-graph-helper.mjs +0 -81
  136. package/dist/engine/branch/branch-graph-helper.mjs.map +0 -1
  137. package/dist/engine/branch/branch-helper.d.mts +0 -40
  138. package/dist/engine/branch/branch-helper.d.mts.map +0 -1
  139. package/dist/engine/branch/branch-helper.mjs +0 -78
  140. package/dist/engine/branch/branch-helper.mjs.map +0 -1
  141. package/dist/engine/branch/branch-space-helper.d.mts +0 -23
  142. package/dist/engine/branch/branch-space-helper.d.mts.map +0 -1
  143. package/dist/engine/branch/branch-space-helper.mjs +0 -78
  144. package/dist/engine/branch/branch-space-helper.mjs.map +0 -1
  145. package/dist/engine/branch/branch-types.d.mts +0 -26
  146. package/dist/engine/branch/branch-types.d.mts.map +0 -1
  147. package/dist/engine/branch/branch-types.mjs +0 -7
  148. package/dist/engine/branch/branch-types.mjs.map +0 -1
  149. package/dist/engine/diff/line-diff-helper.d.mts +0 -76
  150. package/dist/engine/diff/line-diff-helper.d.mts.map +0 -1
  151. package/dist/engine/diff/line-diff-helper.mjs +0 -144
  152. package/dist/engine/diff/line-diff-helper.mjs.map +0 -1
  153. package/dist/engine/filter/glob-helper.d.mts +0 -51
  154. package/dist/engine/filter/glob-helper.d.mts.map +0 -1
  155. package/dist/engine/filter/glob-helper.mjs +0 -132
  156. package/dist/engine/filter/glob-helper.mjs.map +0 -1
  157. package/dist/engine/index/index-helper.d.mts +0 -113
  158. package/dist/engine/index/index-helper.d.mts.map +0 -1
  159. package/dist/engine/index/index-helper.mjs +0 -533
  160. package/dist/engine/index/index-helper.mjs.map +0 -1
  161. package/dist/engine/index/index-types.d.mts +0 -63
  162. package/dist/engine/index/index-types.d.mts.map +0 -1
  163. package/dist/engine/index/index-types.mjs +0 -7
  164. package/dist/engine/index/index-types.mjs.map +0 -1
  165. package/dist/engine/item/item-atom-helper.d.mts +0 -20
  166. package/dist/engine/item/item-atom-helper.d.mts.map +0 -1
  167. package/dist/engine/item/item-atom-helper.mjs +0 -30
  168. package/dist/engine/item/item-atom-helper.mjs.map +0 -1
  169. package/dist/engine/item/item-helper.d.mts +0 -94
  170. package/dist/engine/item/item-helper.d.mts.map +0 -1
  171. package/dist/engine/item/item-helper.mjs +0 -424
  172. package/dist/engine/item/item-helper.mjs.map +0 -1
  173. package/dist/engine/item/item-types.d.mts +0 -128
  174. package/dist/engine/item/item-types.d.mts.map +0 -1
  175. package/dist/engine/item/item-types.mjs +0 -16
  176. package/dist/engine/item/item-types.mjs.map +0 -1
  177. package/dist/engine/merge/b2tfs-3way-graft-strategy.d.mts +0 -74
  178. package/dist/engine/merge/b2tfs-3way-graft-strategy.d.mts.map +0 -1
  179. package/dist/engine/merge/b2tfs-3way-graft-strategy.mjs +0 -570
  180. package/dist/engine/merge/b2tfs-3way-graft-strategy.mjs.map +0 -1
  181. package/dist/engine/merge/b2tfs-3way-graft-types.d.mts +0 -34
  182. package/dist/engine/merge/b2tfs-3way-graft-types.d.mts.map +0 -1
  183. package/dist/engine/merge/b2tfs-3way-graft-types.mjs +0 -2
  184. package/dist/engine/merge/b2tfs-3way-graft-types.mjs.map +0 -1
  185. package/dist/engine/status/status-helper.d.mts +0 -90
  186. package/dist/engine/status/status-helper.d.mts.map +0 -1
  187. package/dist/engine/status/status-helper.mjs +0 -286
  188. package/dist/engine/status/status-helper.mjs.map +0 -1
  189. package/src/cli/commands/add-cmd.mts +0 -435
  190. package/src/cli/commands/branch-cmd.mts +0 -311
  191. package/src/cli/commands/checkout-cmd.mts +0 -227
  192. package/src/cli/commands/commit-cmd.mts +0 -557
  193. package/src/cli/commands/init-cmd.mts +0 -152
  194. package/src/cli/commands/log-cmd.mts +0 -449
  195. package/src/cli/commands/merge-cmd.mts +0 -363
  196. package/src/cli/commands/reset-cmd.mts +0 -128
  197. package/src/cli/commands/restore-cmd.mts +0 -155
  198. package/src/cli/commands/status-cmd.mts +0 -168
  199. package/src/engine/branch/branch-graph-helper.mts +0 -117
  200. package/src/engine/branch/branch-helper.mts +0 -112
  201. package/src/engine/branch/branch-space-helper.mts +0 -110
  202. package/src/engine/branch/branch-types.mts +0 -29
  203. package/src/engine/diff/line-diff-helper.mts +0 -210
  204. package/src/engine/diff/line-diff-helper.respec.mts +0 -84
  205. package/src/engine/filter/glob-helper.mts +0 -165
  206. package/src/engine/filter/glob-helper.respec.mts +0 -94
  207. package/src/engine/index/index-helper.mts +0 -705
  208. package/src/engine/index/index-types.mts +0 -66
  209. package/src/engine/item/item-atom-helper.mts +0 -30
  210. package/src/engine/item/item-helper.mts +0 -544
  211. package/src/engine/item/item-types.mts +0 -137
  212. package/src/engine/item/item.respec.mts +0 -92
  213. package/src/engine/merge/b2tfs-3way-graft-strategy.mts +0 -630
  214. package/src/engine/merge/b2tfs-3way-graft-strategy.respec.mts +0 -346
  215. package/src/engine/merge/b2tfs-3way-graft-types.mts +0 -34
  216. package/src/engine/status/status-helper.mts +0 -383
@@ -1,435 +0,0 @@
1
- /**
2
- * @module add-cmd
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.
7
- */
8
-
9
- import path from 'node:path';
10
- import fs from 'node:fs/promises';
11
- import crypto from 'node:crypto';
12
-
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';
20
-
21
- 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';
34
- import { GLOBAL_LOG_A_LOT } from '../../vcs-gib-constants.mjs';
35
-
36
- const lcFile = `[add-cmd]`;
37
- const logalot = GLOBAL_LOG_A_LOT;
38
-
39
- export interface AddCmdOpts {
40
- paths?: string[];
41
- targetDir?: string;
42
- vcsFolderName?: string;
43
- all?: boolean;
44
- quiet?: boolean;
45
- }
46
-
47
- export interface AddCmdResult {
48
- stagedPaths: string[];
49
- stagedCount: number;
50
- }
51
-
52
- export async function executeAddCmd({
53
- paths = [],
54
- targetDir = process.cwd(),
55
- vcsFolderName = '.vcsgib',
56
- all = false,
57
- quiet = false,
58
- }: AddCmdOpts = {}): Promise<AddCmdResult> {
59
- const lc = `${lcFile}[${executeAddCmd.name}]`;
60
- try {
61
- if (logalot) { console.log(`${lc} starting... (I: 1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d)`); }
62
-
63
- const absTargetDir = path.resolve(targetDir);
64
-
65
- const { metaspace, localSpace, vcsPath, repoRoot } = await bootstrapVcsMetaspace({
66
- repoPath: absTargetDir,
67
- vcsFolderName,
68
- });
69
-
70
- // Verify repo exists
71
- try {
72
- await fs.access(vcsPath);
73
- } catch {
74
- throw new Error(`Not an ibgib repository (directory ${vcsPath} does not exist) (E: 2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d)`);
75
- }
76
-
77
- // Retrieve authoritative B2tFSIndexIbGib_V1 from space
78
- const indexIbGib = await getB2tFSIndexIbGib({ space: localSpace, vcsPath });
79
- if (!indexIbGib) {
80
- throw new Error(`Repository not initialized. Run 'vcs init' first. (E: 2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e)`);
81
- }
82
-
83
- const activeBranch = resolveContextualBranchName({
84
- targetDir: absTargetDir,
85
- repoRoot,
86
- indexIbGib,
87
- });
88
- const activeWorktreeDir = activeBranch === 'main' ? repoRoot : path.join(repoRoot, 'b', activeBranch);
89
-
90
- // Target active branch space b2s_<activeBranch>
91
- const { space: activeSpace } = await getOrCreateBranchSpace({
92
- metaspace,
93
- vcsPath,
94
- branchName: activeBranch,
95
- });
96
-
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
- }
312
-
313
- // 3. Update B2tFSIndexIbGib_V1 in activeSpace & localSpace
314
- const updatedIndex = await updateB2tFSIndexIbGib({
315
- space: activeSpace,
316
- metaspace,
317
- indexIbGib,
318
- dataToUpdate: {
319
- stagedPaths: stagedPathsMap,
320
- staged_item: stagedItemAddrs,
321
- },
322
- vcsPath,
323
- });
324
-
325
- if (localSpace !== activeSpace) {
326
- await putInSpace({ space: localSpace, ibGib: updatedIndex });
327
- }
328
-
329
- return {
330
- stagedPaths: newlyStagedPaths,
331
- stagedCount: newlyStagedPaths.length,
332
- };
333
- } catch (error) {
334
- console.error(`${lc} ${extractErrorMsg(error)} (E: 3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f)`);
335
- throw error;
336
- } finally {
337
- if (logalot) { console.log(`${lc} complete. (I: 4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a)`); }
338
- }
339
- }
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