@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,557 +0,0 @@
1
- /**
2
- * @module commit-cmd
3
- *
4
- * Command handler for `vcs commit -m "message"`.
5
- * Ingests staged items and co-located .ib.*.md comment metadata files,
6
- * attaches comments to corresponding file and folder b2tfs_items,
7
- * attaches overall commit message to root b2tfs_item, evolves root item,
8
- * advances B2tFSBranchIbGib_V1 with committedPaths, and clears index staging area.
9
- */
10
-
11
- import path from 'node:path';
12
- import fs from 'node:fs/promises';
13
- import { Dirent } from 'node:fs';
14
- import crypto from 'node:crypto';
15
-
16
- import { getUUID, extractErrorMsg, delay } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
17
- import { Factory_V1 } from '@ibgib/ts-gib/dist/V1/factory.mjs';
18
- import { ROOT } from '@ibgib/ts-gib/dist/V1/constants.mjs';
19
- import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs';
20
- import { putInSpace, persistTransformResult } from '@ibgib/core-gib/dist/witness/space/space-helper.mjs';
21
- import { createCommentIbGib } from '@ibgib/core-gib/dist/common/comment/comment-helper.mjs';
22
- import { CommentIbGib_V1 } from '@ibgib/core-gib/dist/common/comment/comment-types.mjs';
23
-
24
- import { bootstrapVcsMetaspace } from '../../bootstrap/node-bootstrap.mjs';
25
- import { getOrCreateBranchSpace } from '../../engine/branch/branch-space-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 { getB2tFSBranchSpaceName, resolveContextualBranchName } from '../../engine/branch/branch-helper.mjs';
29
- import { B2tFSBranchIbGib_V1 } from '../../engine/branch/branch-types.mjs';
30
- import { getB2tFSIndexIbGib, updateB2tFSIndexIbGib, getSpaceQualifiedIbGibAddr } from '../../engine/index/index-helper.mjs';
31
- import { B2tFSStagedItemRecord } from '../../engine/index/index-types.mjs';
32
- import { isCommentMetadataFilename, extractCommentTopicName } from '../../engine/status/status-helper.mjs';
33
- import { TransformResult } from '@ibgib/ts-gib/dist/types.mjs';
34
- import { IbGib_V1 } from '@ibgib/ts-gib/dist/V1/types.mjs';
35
- import { GLOBAL_LOG_A_LOT } from '../../vcs-gib-constants.mjs';
36
-
37
- const lcFile = `[commit-cmd]`;
38
- const logalot = GLOBAL_LOG_A_LOT;
39
-
40
- export interface CommitCmdOpts {
41
- message?: string;
42
- targetDir?: string;
43
- vcsFolderName?: string;
44
- quiet?: boolean;
45
- }
46
-
47
- export interface CommitCmdResult {
48
- commitAddr: string;
49
- commentAddr?: string;
50
- branchName: string;
51
- committedPaths: string[];
52
- rootItemAddr: string;
53
- }
54
-
55
- export async function executeCommitCmd({
56
- message = '',
57
- targetDir = process.cwd(),
58
- vcsFolderName = '.vcsgib',
59
- quiet = false,
60
- }: CommitCmdOpts = {}): Promise<CommitCmdResult> {
61
- const lc = `${lcFile}[${executeCommitCmd.name}]`;
62
-
63
- try {
64
- if (logalot) {
65
- console.log(`${lc} starting executeCommitCmd (I: 9a8b7c6d5e4f3a2b1c0d9e8f7a6b5c4d)`);
66
- }
67
-
68
- const absTargetDir = path.resolve(targetDir);
69
-
70
- const { metaspace, localSpace, vcsPath, repoRoot } = await bootstrapVcsMetaspace({
71
- repoPath: absTargetDir,
72
- vcsFolderName,
73
- });
74
-
75
- // Verify repo exists
76
- try {
77
- await fs.access(vcsPath);
78
- } catch {
79
- throw new Error(`Not an ibgib repository (directory ${vcsPath} does not exist) (E: 1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d)`);
80
- }
81
-
82
- // Fetch authoritative repository index from localSpace
83
- const indexIbGib = await getB2tFSIndexIbGib({ space: localSpace, vcsPath });
84
- if (!indexIbGib) {
85
- throw new Error(`Repository index B2tFSIndexIbGib_V1 not found in localSpace (E: 3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f)`);
86
- }
87
-
88
- const branchName = resolveContextualBranchName({
89
- targetDir: absTargetDir,
90
- repoRoot,
91
- indexIbGib,
92
- });
93
- const activeWorktreeDir = branchName === 'main' ? repoRoot : path.join(repoRoot, 'b', branchName);
94
-
95
- // Target active branch space b2s_<activeBranch>
96
- const { space: activeSpace } = await getOrCreateBranchSpace({
97
- metaspace,
98
- vcsPath,
99
- branchName,
100
- });
101
-
102
- // Verify there are staged items
103
- const stagedPathsMap: { [relPath: string]: B2tFSStagedItemRecord } = { ...(indexIbGib.data?.stagedPaths || {}) };
104
- const committedPaths = Object.keys(stagedPathsMap);
105
- if (committedPaths.length === 0) {
106
- throw new Error(`Nothing to commit (no staged items found in index) (E: 4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a)`);
107
- }
108
-
109
- // Find active branch node
110
- let currentBranchIbGib: B2tFSBranchIbGib_V1 | undefined;
111
- let currentBranchAddr: string | undefined;
112
-
113
- const branchAddrs = [
114
- ...(indexIbGib.rel8ns?.branch || []),
115
- ...(indexIbGib.rel8ns?.branch_tjp || []),
116
- ];
117
-
118
- if (branchAddrs.length > 0) {
119
- let branchIbGibs: B2tFSBranchIbGib_V1[] = [];
120
- for (const bAddr of branchAddrs) {
121
- const bIbGib = await getIbGibWithMetaspaceFallback({
122
- addr: bAddr,
123
- space: activeSpace,
124
- metaspace,
125
- });
126
- if (bIbGib) {
127
- branchIbGibs.push(bIbGib as B2tFSBranchIbGib_V1);
128
- }
129
- }
130
-
131
- currentBranchIbGib = branchIbGibs.findLast(
132
- (b) => (b as B2tFSBranchIbGib_V1)?.data?.name === branchName,
133
- ) as B2tFSBranchIbGib_V1 || (branchIbGibs.at(-1) as B2tFSBranchIbGib_V1);
134
-
135
- if (currentBranchIbGib) {
136
- currentBranchAddr = getIbGibAddr({ ibGib: currentBranchIbGib });
137
- }
138
- }
139
-
140
- const currentRootAddr = currentBranchIbGib?.rel8ns?.b2tFS_item?.at(-1) || currentBranchIbGib?.rel8ns?.b2tfs_item?.at(-1);
141
-
142
- // 1. Evolve root item graph with staged items and ingest co-located .ib.*.md comment files
143
- const repoName = path.basename(repoRoot) || 'root';
144
- let { newRootItem, newRootAddr, ingestedCommentCount } = await commitCmd_buildEvolvedRootItem({
145
- currentRootAddr,
146
- stagedPathsMap,
147
- space: activeSpace,
148
- metaspace,
149
- repoName,
150
- worktreeDir: activeWorktreeDir,
151
- });
152
-
153
- if ((!message || message.trim().length === 0) && ingestedCommentCount === 0) {
154
- throw new Error(`Commit message is required (-m "message" or companion comment files) (E: 2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e)`);
155
- }
156
-
157
- // 2. If CLI message is provided, attach CommentIbGib to the root b2tfs item
158
- let commentAddr: string | undefined;
159
- if (message && message.trim().length > 0) {
160
- const commentRes = await createCommentIbGib({
161
- text: message.trim(),
162
- saveInSpace: true,
163
- space: activeSpace,
164
- });
165
- const commentIbGib = commentRes.newIbGib as CommentIbGib_V1;
166
- commentAddr = getIbGibAddr({ ibGib: commentIbGib });
167
- await metaspace.registerNewIbGib({ ibGib: commentIbGib, space: activeSpace });
168
-
169
- const existingComments = newRootItem.rel8ns?.comment || [];
170
- const evolveRootRes = await evolveB2tFSItemIbGib({
171
- existingItem: newRootItem,
172
- rel8nsToUpdate: {
173
- comment: [...existingComments, commentAddr],
174
- },
175
- });
176
- await persistTransformResult({ resTransform: evolveRootRes, space: activeSpace });
177
- await metaspace.registerNewIbGib({ ibGib: evolveRootRes.newIbGib, space: activeSpace });
178
-
179
- newRootItem = evolveRootRes.newIbGib as B2tFSItemIbGib_V1;
180
- newRootAddr = getIbGibAddr({ ibGib: newRootItem });
181
- }
182
-
183
- // 3. Advance B2tFSBranchIbGib_V1 node inside activeSpace
184
- const branchUuid = currentBranchIbGib?.data?.uuid || (await getUUID());
185
- const newBranchRes = await Factory_V1.firstGen({
186
- parentIbGib: currentBranchIbGib || ROOT,
187
- ib: `b2tfs_branch ${branchName} v1 ${branchUuid}`,
188
- data: {
189
- ...(currentBranchIbGib?.data || {}),
190
- name: branchName,
191
- uuid: branchUuid,
192
- classname: 'B2tFSBranchIbGib_V1',
193
- committedAt: new Date().toISOString(),
194
- committedPaths,
195
- },
196
- rel8ns: {
197
- b2tfs_item: [newRootAddr],
198
- ...(commentAddr ? { comment: [commentAddr] } : {}),
199
- },
200
- });
201
-
202
- const newBranchIbGib = newBranchRes.newIbGib as B2tFSBranchIbGib_V1;
203
- const newBranchAddr = getIbGibAddr({ ibGib: newBranchIbGib });
204
- await persistTransformResult({ resTransform: newBranchRes, space: activeSpace });
205
- await metaspace.registerNewIbGib({ ibGib: newBranchIbGib, space: activeSpace });
206
-
207
- const sqBranchAddr = getSpaceQualifiedIbGibAddr({
208
- spaceId: activeSpace.data?.spaceSubPath || activeSpace.data?.name || getB2tFSBranchSpaceName(branchName),
209
- ibGibAddr: newBranchAddr,
210
- });
211
-
212
- // 4. Update B2tFSIndexIbGib_V1 in activeSpace & localSpace
213
- const updatedIndex = await updateB2tFSIndexIbGib({
214
- space: activeSpace,
215
- metaspace,
216
- indexIbGib,
217
- dataToUpdate: {
218
- stagedPaths: {},
219
- staged_item: [],
220
- },
221
- rel8nsToUpdate: {
222
- branch: [sqBranchAddr],
223
- branch_tjp: [sqBranchAddr],
224
- },
225
- vcsPath,
226
- });
227
-
228
- if (localSpace !== activeSpace) {
229
- await putInSpace({ space: localSpace, ibGib: updatedIndex });
230
- }
231
-
232
- if (!quiet) {
233
- const shortGib = newBranchIbGib.gib ? newBranchIbGib.gib.slice(0, 7) : 'commit';
234
- const logMsg = message ? message.trim() : '(committed)';
235
- console.log(`[${branchName} ${shortGib}] ${logMsg} (I: 5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b)`);
236
- console.log(` ${committedPaths.length} file(s) changed`);
237
- }
238
-
239
- return {
240
- commitAddr: newBranchAddr,
241
- commentAddr,
242
- branchName,
243
- committedPaths,
244
- rootItemAddr: newRootAddr,
245
- };
246
- } catch (error) {
247
- console.error(`${lc} ${extractErrorMsg(error)} (E: 6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c)`);
248
- throw error;
249
- } finally {
250
- await delay(50);
251
- if (logalot) {
252
- console.log(`${lc} complete. (I: 7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d)`);
253
- }
254
- }
255
- }
256
-
257
- // #region commitCmd_buildEvolvedRootItem
258
- async function commitCmd_buildEvolvedRootItem({
259
- currentRootAddr,
260
- stagedPathsMap,
261
- space,
262
- metaspace,
263
- repoName,
264
- worktreeDir,
265
- }: {
266
- currentRootAddr?: string;
267
- stagedPathsMap: { [relPath: string]: B2tFSStagedItemRecord };
268
- space: any;
269
- metaspace: any;
270
- repoName: string;
271
- worktreeDir: string;
272
- }): Promise<{ newRootItem: B2tFSItemIbGib_V1; newRootAddr: string; ingestedCommentCount: number }> {
273
- let ingestedCommentCount = 0;
274
- const itemsByRelPath = new Map<string, { itemAddr: string; fsType: 'file' | 'folder'; item?: B2tFSItemIbGib_V1 }>();
275
-
276
- if (currentRootAddr) {
277
- const currentRootItem = await getIbGibWithMetaspaceFallback({
278
- addr: currentRootAddr,
279
- space,
280
- metaspace,
281
- }) as B2tFSItemIbGib_V1;
282
-
283
- if (currentRootItem) {
284
- await commitCmd_walkBranchGraph({
285
- item: currentRootItem,
286
- space,
287
- metaspace,
288
- currentRelPath: '',
289
- outMap: itemsByRelPath,
290
- });
291
- }
292
- }
293
-
294
- // Overlay staged items
295
- for (const [relPath, stagedRec] of Object.entries(stagedPathsMap)) {
296
- itemsByRelPath.set(relPath, {
297
- itemAddr: stagedRec.itemAddr,
298
- fsType: stagedRec.fsType || 'file',
299
- });
300
- }
301
-
302
- // 1. Ingest co-located .ib.<filename>.md comment files for staged files
303
- for (const [relPath, itemRec] of itemsByRelPath.entries()) {
304
- if (itemRec.fsType !== 'file') { continue; }
305
-
306
- const dir = path.dirname(relPath);
307
- const base = path.basename(relPath);
308
- const commentDir = dir === '.' ? worktreeDir : path.join(worktreeDir, dir);
309
- const commentFullPath = path.join(commentDir, `.ib.${base}.md`);
310
-
311
- let commentText = '';
312
- try {
313
- commentText = await fs.readFile(commentFullPath, 'utf8');
314
- } catch {
315
- // No comment file for this file
316
- continue;
317
- }
318
-
319
- if (commentText.trim().length > 0) {
320
- const commentRes = await createCommentIbGib({
321
- text: commentText.trim(),
322
- saveInSpace: true,
323
- space,
324
- });
325
- const commentIbGib = commentRes.newIbGib as CommentIbGib_V1;
326
- const commentAddr = getIbGibAddr({ ibGib: commentIbGib });
327
- await metaspace.registerNewIbGib({ ibGib: commentIbGib, space });
328
- ingestedCommentCount++;
329
-
330
- const currentItem = itemRec.item || (await getIbGibWithMetaspaceFallback({
331
- addr: itemRec.itemAddr,
332
- space,
333
- metaspace,
334
- }) as B2tFSItemIbGib_V1);
335
-
336
- if (currentItem) {
337
- const existingComments = currentItem.rel8ns?.comment || [];
338
- const evolvedItemRes = await evolveB2tFSItemIbGib({
339
- existingItem: currentItem,
340
- rel8nsToUpdate: {
341
- comment: [...existingComments, commentAddr],
342
- },
343
- });
344
- await persistTransformResult({ resTransform: evolvedItemRes, space });
345
- await metaspace.registerNewIbGib({ ibGib: evolvedItemRes.newIbGib, space });
346
-
347
- itemRec.itemAddr = getIbGibAddr({ ibGib: evolvedItemRes.newIbGib });
348
- itemRec.item = evolvedItemRes.newIbGib as B2tFSItemIbGib_V1;
349
- }
350
-
351
- try {
352
- await fs.unlink(commentFullPath);
353
- } catch {
354
- // Delete failed / ignore
355
- }
356
- }
357
- }
358
-
359
- // Ensure parent folder entries exist for all items
360
- const allRelPaths = Array.from(itemsByRelPath.keys());
361
- for (const relPath of allRelPaths) {
362
- const parts = relPath.split('/');
363
- parts.pop(); // Remove file/folder name to get parent path
364
- let currentFolderRel = '';
365
- for (const part of parts) {
366
- currentFolderRel = currentFolderRel ? `${currentFolderRel}/${part}` : part;
367
- if (!itemsByRelPath.has(currentFolderRel)) {
368
- itemsByRelPath.set(currentFolderRel, { itemAddr: '', fsType: 'folder' });
369
- }
370
- }
371
- }
372
-
373
- // Collect all folder paths (including root '')
374
- const folderPathsSet = new Set<string>();
375
- folderPathsSet.add('');
376
- for (const [relPath, itemRec] of itemsByRelPath.entries()) {
377
- if (itemRec.fsType === 'folder' || relPath === '') {
378
- folderPathsSet.add(relPath);
379
- }
380
- }
381
-
382
- // Sort folders deepest path first so children folders are built before parents
383
- const sortedFolders = Array.from(folderPathsSet).sort((a, b) => {
384
- const depthA = a ? a.split('/').length : 0;
385
- const depthB = b ? b.split('/').length : 0;
386
- return depthB - depthA;
387
- });
388
-
389
- const createdFolderAddrs = new Map<string, string>();
390
- let rootFolderItem: B2tFSItemIbGib_V1 | undefined;
391
- let rootFolderAddr: string = '';
392
-
393
- for (const folderRelPath of sortedFolders) {
394
- const childAddrs: string[] = [];
395
- for (const [itemRelPath, itemRec] of itemsByRelPath.entries()) {
396
- if (!itemRelPath || itemRelPath === folderRelPath) {
397
- continue;
398
- }
399
- const parentRelPath = commitCmd_getParentRelPath(itemRelPath);
400
- if (parentRelPath === folderRelPath) {
401
- if (itemRec.fsType === 'folder') {
402
- const folderAddr = createdFolderAddrs.get(itemRelPath);
403
- if (folderAddr && !childAddrs.includes(folderAddr)) {
404
- childAddrs.push(folderAddr);
405
- }
406
- } else {
407
- if (itemRec.itemAddr && !childAddrs.includes(itemRec.itemAddr)) {
408
- childAddrs.push(itemRec.itemAddr);
409
- }
410
- }
411
- }
412
- }
413
-
414
- // Check for folder-level .ib.<topic>.md files in this folder
415
- const folderDiskPath = folderRelPath ? path.join(worktreeDir, folderRelPath) : worktreeDir;
416
- const folderCommentAddrs: string[] = [];
417
-
418
- try {
419
- const dirents = await fs.readdir(folderDiskPath, { withFileTypes: true });
420
- for (const dirent of dirents) {
421
- if (dirent.isFile() && isCommentMetadataFilename(dirent.name)) {
422
- const topicName = extractCommentTopicName(dirent.name);
423
- const isCoLocatedFileComment = itemsByRelPath.has(folderRelPath ? `${folderRelPath}/${topicName}` : topicName);
424
-
425
- if (!isCoLocatedFileComment) {
426
- const fullCommentPath = path.join(folderDiskPath, dirent.name);
427
- const commentContent = await fs.readFile(fullCommentPath, 'utf8');
428
-
429
- if (commentContent.trim().length > 0) {
430
- const commentRes = await createCommentIbGib({
431
- text: commentContent.trim(),
432
- saveInSpace: true,
433
- space,
434
- });
435
- const commentIbGib = commentRes.newIbGib as CommentIbGib_V1;
436
- const cAddr = getIbGibAddr({ ibGib: commentIbGib });
437
- await metaspace.registerNewIbGib({ ibGib: commentIbGib, space });
438
- folderCommentAddrs.push(cAddr);
439
- ingestedCommentCount++;
440
- }
441
-
442
- try {
443
- await fs.unlink(fullCommentPath);
444
- } catch {
445
- // ignore delete error
446
- }
447
- }
448
- }
449
- }
450
- } catch {
451
- // Folder may not exist on disk
452
- }
453
-
454
- const folderName = folderRelPath ? path.basename(folderRelPath) : repoName;
455
- const nameHash = crypto.createHash('sha256').update(folderName).digest('hex');
456
-
457
- const existingFolderRec = itemsByRelPath.get(folderRelPath);
458
-
459
- let folderRes: TransformResult<IbGib_V1>;
460
-
461
- if (existingFolderRec && existingFolderRec.item) {
462
- const oldChildAddrs = existingFolderRec.item.rel8ns?.[B2TFS_CHILD_ITEM_REL8N_NAME] || [];
463
- const toRemoveChildAddrs = oldChildAddrs.filter(a => !childAddrs.includes(a));
464
- const existingComments = existingFolderRec.item.rel8ns?.comment || [];
465
-
466
- folderRes = await evolveB2tFSItemIbGib({
467
- existingItem: existingFolderRec.item,
468
- dataToUpdate: {
469
- nameHash,
470
- },
471
- rel8nsToUpdate: {
472
- ...(childAddrs.length > 0 ? { [B2TFS_CHILD_ITEM_REL8N_NAME]: childAddrs } : {}),
473
- ...(folderCommentAddrs.length > 0 ? { comment: [...existingComments, ...folderCommentAddrs] } : {}),
474
- },
475
- rel8nsToRemove: toRemoveChildAddrs.length > 0 ? { [B2TFS_CHILD_ITEM_REL8N_NAME]: toRemoveChildAddrs } : undefined,
476
- });
477
- } else {
478
- folderRes = await createB2tFSItemIbGib({
479
- fsType: 'folder',
480
- name: folderName,
481
- data: {
482
- nameHash,
483
- },
484
- rel8ns: {
485
- ...(childAddrs.length > 0 ? { [B2TFS_CHILD_ITEM_REL8N_NAME]: childAddrs } : {}),
486
- ...(folderCommentAddrs.length > 0 ? { comment: folderCommentAddrs } : {}),
487
- },
488
- });
489
- }
490
-
491
- const folderItem = folderRes.newIbGib as B2tFSItemIbGib_V1;
492
- const folderAddr = getIbGibAddr({ ibGib: folderItem });
493
- await persistTransformResult({ resTransform: folderRes, space });
494
- await metaspace.registerNewIbGib({ ibGib: folderItem, space });
495
-
496
- createdFolderAddrs.set(folderRelPath, folderAddr);
497
-
498
- if (folderRelPath === '') {
499
- rootFolderItem = folderItem;
500
- rootFolderAddr = folderAddr;
501
- }
502
- }
503
-
504
- return { newRootItem: rootFolderItem!, newRootAddr: rootFolderAddr, ingestedCommentCount };
505
- }
506
-
507
- function commitCmd_getParentRelPath(relPath: string): string {
508
- const parts = relPath.split('/');
509
- parts.pop();
510
- return parts.join('/');
511
- }
512
-
513
- async function commitCmd_walkBranchGraph({
514
- item,
515
- space,
516
- metaspace,
517
- currentRelPath,
518
- outMap,
519
- }: {
520
- item: B2tFSItemIbGib_V1;
521
- space: any;
522
- metaspace?: any;
523
- currentRelPath: string;
524
- outMap: Map<string, { itemAddr: string; fsType: 'file' | 'folder'; item?: B2tFSItemIbGib_V1 }>;
525
- }): Promise<void> {
526
- if (!item || !item.data) { return; }
527
-
528
- const { fsType } = item.data;
529
- const itemAddr = getIbGibAddr({ ibGib: item });
530
-
531
- outMap.set(currentRelPath, { itemAddr, fsType, item });
532
-
533
- if (fsType === 'folder') {
534
- const childAddrs = item.rel8ns?.[B2TFS_CHILD_ITEM_REL8N_NAME] || [];
535
- for (const childAddr of childAddrs) {
536
- const childItem = await getIbGibWithMetaspaceFallback({
537
- addr: childAddr,
538
- space,
539
- metaspace,
540
- }) as B2tFSItemIbGib_V1;
541
-
542
- if (childItem && childItem.data) {
543
- const childRelPath = currentRelPath
544
- ? `${currentRelPath}/${childItem.data.name}`
545
- : childItem.data.name;
546
- await commitCmd_walkBranchGraph({
547
- item: childItem,
548
- space,
549
- metaspace,
550
- currentRelPath: childRelPath,
551
- outMap,
552
- });
553
- }
554
- }
555
- }
556
- }
557
- // #endregion commitCmd_buildEvolvedRootItem