@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,152 +0,0 @@
1
- /**
2
- * @module init-cmd
3
- *
4
- * Command handler for `vcs init [targetDir]`.
5
- * Initializes local repository space, root B2tFS folder item, default branch, and in-band space index.
6
- */
7
-
8
- import path from 'node:path';
9
- import fs from 'node:fs/promises';
10
-
11
- import { extractErrorMsg, getUUID } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
12
- import { Factory_V1 } from '@ibgib/ts-gib/dist/V1/factory.mjs';
13
- import { ROOT } from '@ibgib/ts-gib/dist/V1/constants.mjs';
14
- import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs';
15
- import { putInSpace, persistTransformResult } from '@ibgib/core-gib/dist/witness/space/space-helper.mjs';
16
-
17
- import { bootstrapVcsMetaspace } from '../../bootstrap/node-bootstrap.mjs';
18
- import { getB2tFSItemIb } from '../../engine/item/item-atom-helper.mjs';
19
- import { B2tFSItemIbGib_V1 } from '../../engine/item/item-types.mjs';
20
- import { createB2tFSBranchIbGib, getB2tFSBranchSpaceName } from '../../engine/branch/branch-helper.mjs';
21
- import { getOrCreateBranchSpace } from '../../engine/branch/branch-space-helper.mjs';
22
- import { createB2tFSIndexIbGib, writeVcsIndexProjection } from '../../engine/index/index-helper.mjs';
23
- import { GLOBAL_LOG_A_LOT } from '../../vcs-gib-constants.mjs';
24
-
25
- const lcFile = `[init-cmd]`;
26
- const logalot = GLOBAL_LOG_A_LOT;
27
-
28
- export interface InitCmdOpts {
29
- targetDir?: string;
30
- vcsFolderName?: string;
31
- defaultBranchName?: string;
32
- quiet?: boolean;
33
- }
34
-
35
- export interface InitCmdResult {
36
- vcsPath: string;
37
- spaceId: string;
38
- branchName: string;
39
- rootItemIb: string;
40
- }
41
-
42
- export async function executeInitCmd({
43
- targetDir = process.cwd(),
44
- vcsFolderName = '.vcsgib',
45
- defaultBranchName = 'main',
46
- quiet = false,
47
- }: InitCmdOpts = {}): Promise<InitCmdResult> {
48
- const lc = `${lcFile}[${executeInitCmd.name}]`;
49
- try {
50
- if (logalot) {
51
- console.log(`${lc} starting... (I: 8a9b10c11d12e13f14a15b16c17d18e1)`);
52
- }
53
-
54
- const absTargetDir = path.resolve(targetDir);
55
- const vcsPath = path.join(absTargetDir, vcsFolderName);
56
-
57
- // Create target repository folder if it doesn't exist
58
- await fs.mkdir(absTargetDir, { recursive: true });
59
-
60
- // Bootstrap Metaspace
61
- const { metaspace } = await bootstrapVcsMetaspace({
62
- repoPath: absTargetDir,
63
- vcsFolderName,
64
- defaultSpaceName: `vcs_${path.basename(absTargetDir).replace(/[^a-zA-Z0-9_\-]/g, '_')}`,
65
- });
66
-
67
- // Initialize b2s_main branch space
68
- const { space: branchSpace, spaceId } = await getOrCreateBranchSpace({
69
- metaspace,
70
- vcsPath,
71
- branchName: defaultBranchName,
72
- });
73
-
74
- const folderName = path.basename(absTargetDir) || 'root';
75
- const rootNameHash = await getUUID();
76
-
77
- // 1. Create root folder B2tFS item inside b2s_main space
78
- const rootItemRes = await Factory_V1.firstGen({
79
- parentIbGib: ROOT,
80
- ib: getB2tFSItemIb('folder', folderName, rootNameHash),
81
- data: {
82
- name: folderName,
83
- nameHash: rootNameHash,
84
- fsType: 'folder',
85
- diffTransactionId: await getUUID(),
86
- uuid: await getUUID(),
87
- classname: 'B2tFSItemIbGib_V1',
88
- },
89
- });
90
-
91
- const rootItem = rootItemRes.newIbGib as B2tFSItemIbGib_V1;
92
- await persistTransformResult({ resTransform: rootItemRes, space: branchSpace });
93
- await metaspace.registerNewIbGib({ ibGib: rootItem, space: branchSpace });
94
-
95
- // 2. Create default branch pointing to root folder inside b2s_main space
96
- const branchIbGib = await createB2tFSBranchIbGib({
97
- branchName: defaultBranchName,
98
- rootItem,
99
- space: branchSpace,
100
- metaspace,
101
- });
102
- const branchAddr = getIbGibAddr({ ibGib: branchIbGib });
103
-
104
- // 3. Create space index meta object stored inside b2s_main space
105
- const indexIbGib = await createB2tFSIndexIbGib({
106
- spaceId,
107
- activeSpaceId: getB2tFSBranchSpaceName(defaultBranchName),
108
- activeBranch: defaultBranchName,
109
- space: branchSpace,
110
- metaspace,
111
- branchAddr,
112
- });
113
-
114
- // 4. Write read-only projection file in .vcsgib/
115
- await writeVcsIndexProjection({
116
- vcsPath,
117
- indexIbGib,
118
- });
119
-
120
- // Clean up legacy out-of-band state files if present
121
- try {
122
- await fs.rm(path.join(vcsPath, 'vcs_state.json'), { force: true });
123
- } catch {
124
- // Ignore if missing
125
- }
126
- try {
127
- await fs.rm(path.join(vcsPath, 'staging.json'), { force: true });
128
- } catch {
129
- // Ignore if missing
130
- }
131
-
132
- if (!quiet) {
133
- console.log(`Initialized empty ibgib repository in ${vcsPath} (I: 6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f)`);
134
- console.log(` Branch: ${defaultBranchName}`);
135
- console.log(` Root Item: ${rootItem.ib}`);
136
- }
137
-
138
- return {
139
- vcsPath,
140
- spaceId,
141
- branchName: defaultBranchName,
142
- rootItemIb: rootItem.ib,
143
- };
144
- } catch (error) {
145
- console.error(`${lc} ${extractErrorMsg(error)} (E: 9b10c11d12e13f14a15b16c17d18e19f)`);
146
- throw error;
147
- } finally {
148
- if (logalot) {
149
- console.log(`${lc} complete. (I: 0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d)`);
150
- }
151
- }
152
- }
@@ -1,449 +0,0 @@
1
- /**
2
- * @module log-cmd
3
- *
4
- * Command handler for `vcs log`.
5
- * Reads active branch timeline from B2tFSIndexIbGib_V1 in localSpace,
6
- * walks branch or item timeline history backward, and displays formatted commit and comment history.
7
- */
8
-
9
- import path from 'node:path';
10
- import fs from 'node:fs/promises';
11
-
12
- import { extractErrorMsg } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
13
- import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs';
14
- import { CommentIbGib_V1 } from '@ibgib/core-gib/dist/common/comment/comment-types.mjs';
15
-
16
- import { bootstrapVcsMetaspace } from '../../bootstrap/node-bootstrap.mjs';
17
- import { getOrCreateBranchSpace } from '../../engine/branch/branch-space-helper.mjs';
18
- import { resolveContextualBranchName } from '../../engine/branch/branch-helper.mjs';
19
- import { getIbGibWithMetaspaceFallback } from '../../engine/item/item-helper.mjs';
20
- import { B2tFSItemIbGib_V1, B2TFS_CHILD_ITEM_REL8N_NAME } from '../../engine/item/item-types.mjs';
21
- import { B2tFSBranchIbGib_V1 } from '../../engine/branch/branch-types.mjs';
22
- import { getB2tFSIndexIbGib, extractBranchNameFromAddr } from '../../engine/index/index-helper.mjs';
23
- import { GLOBAL_LOG_A_LOT } from '../../vcs-gib-constants.mjs';
24
-
25
- const lcFile = `[log-cmd]`;
26
- const logalot = GLOBAL_LOG_A_LOT;
27
-
28
- export interface VcsLogItem {
29
- branchAddr?: string;
30
- commitAddr: string;
31
- commentAddr?: string;
32
- message: string;
33
- timestamp: string;
34
- author: string;
35
- rootItemAddr?: string;
36
- committedPaths?: string[];
37
- itemComments?: Array<{ path: string; name?: string; message: string }>;
38
- }
39
-
40
- export interface LogCmdOpts {
41
- targetDir?: string;
42
- vcsFolderName?: string;
43
- filePath?: string;
44
- allComments?: boolean;
45
- quiet?: boolean;
46
- }
47
-
48
- export interface LogCmdResult {
49
- branchName: string;
50
- targetPath?: string;
51
- commits: VcsLogItem[];
52
- }
53
-
54
- export async function executeLogCmd({
55
- targetDir = process.cwd(),
56
- vcsFolderName = '.vcsgib',
57
- filePath,
58
- allComments = false,
59
- quiet = false,
60
- }: LogCmdOpts = {}): Promise<LogCmdResult> {
61
- const lc = `${lcFile}[${executeLogCmd.name}]`;
62
-
63
- try {
64
- if (logalot) {
65
- console.log(`${lc} starting executeLogCmd (I: 1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e)`);
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: 2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f)`);
80
- }
81
-
82
- // 1. Fetch authoritative B2tFSIndexIbGib_V1 directly 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: 3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a)`);
86
- }
87
-
88
- const branchName = resolveContextualBranchName({
89
- targetDir: absTargetDir,
90
- repoRoot,
91
- indexIbGib,
92
- });
93
-
94
- // Target active branch space b2s_<activeBranch>
95
- const { space: activeSpace } = await getOrCreateBranchSpace({
96
- metaspace,
97
- vcsPath,
98
- branchName,
99
- });
100
-
101
- // 2. Fetch active branch node address matching active branchName
102
- const branchAddrs = indexIbGib.rel8ns?.branch || indexIbGib.rel8ns?.branch_tjp || [];
103
-
104
- let currBranchAddr: string | undefined;
105
- if (branchAddrs.length > 0) {
106
- let branchIbGibs: B2tFSBranchIbGib_V1[] = [];
107
- for (const bAddr of branchAddrs) {
108
- const bIbGib = await getIbGibWithMetaspaceFallback({
109
- addr: bAddr,
110
- space: activeSpace,
111
- metaspace,
112
- });
113
- if (bIbGib) {
114
- branchIbGibs.push(bIbGib as B2tFSBranchIbGib_V1);
115
- }
116
- }
117
-
118
- const matchingBranches = branchIbGibs.filter(b => b?.data?.name === branchName);
119
- const activeBranchIbGib = matchingBranches.sort((a, b) => (b.data?.n || 0) - (a.data?.n || 0))[0]
120
- || branchIbGibs.at(-1);
121
-
122
- if (activeBranchIbGib) {
123
- currBranchAddr = getIbGibAddr({ ibGib: activeBranchIbGib });
124
- }
125
- }
126
-
127
- const commits: VcsLogItem[] = [];
128
-
129
- // #region File-Specific Log Mode (vcs log <filePath>)
130
- if (filePath) {
131
- const normalizedRelPath = path.relative(repoRoot, path.resolve(absTargetDir, filePath)).replace(/\\/g, '/');
132
-
133
- // Find current root item
134
- const branchIbGib = currBranchAddr
135
- ? await getIbGibWithMetaspaceFallback({ addr: currBranchAddr, space: activeSpace, metaspace }) as B2tFSBranchIbGib_V1
136
- : undefined;
137
- const rootItemAddr = branchIbGib?.rel8ns?.b2tFS_item?.at(-1) || branchIbGib?.rel8ns?.b2tfs_item?.at(-1);
138
-
139
- if (!rootItemAddr) {
140
- throw new Error(`No root item found on branch ${branchName} (E: 4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b)`);
141
- }
142
-
143
- const targetItem = await logCmd_findItemByPath({
144
- rootItemAddr,
145
- targetRelPath: normalizedRelPath,
146
- space: activeSpace,
147
- metaspace,
148
- });
149
-
150
- if (!targetItem) {
151
- throw new Error(`Path '${normalizedRelPath}' not found in active branch snapshot (E: 5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c)`);
152
- }
153
-
154
- // Walk target item timeline history backward
155
- const visitedItemAddrs = new Set<string>();
156
- let currItem: B2tFSItemIbGib_V1 | undefined = targetItem;
157
-
158
- while (currItem) {
159
- const itemAddr = getIbGibAddr({ ibGib: currItem });
160
- if (visitedItemAddrs.has(itemAddr)) { break; }
161
- visitedItemAddrs.add(itemAddr);
162
-
163
- const commentAddrs = currItem.rel8ns?.comment || [];
164
- for (const cAddr of commentAddrs) {
165
- const commentIbGib = await getIbGibWithMetaspaceFallback({
166
- addr: cAddr,
167
- space: activeSpace,
168
- metaspace,
169
- }) as CommentIbGib_V1;
170
-
171
- if (commentIbGib) {
172
- commits.push({
173
- commitAddr: itemAddr,
174
- commentAddr: cAddr,
175
- message: commentIbGib.data?.text || '',
176
- timestamp: commentIbGib.data?.textTimestamp || commentIbGib.data?.timestamp || '',
177
- author: 'vcs-user',
178
- });
179
- }
180
- }
181
-
182
- const pastAddr = currItem.rel8ns?.past?.at(0) || currItem.rel8ns?.ancestor?.at(0);
183
- if (pastAddr) {
184
- currItem = await getIbGibWithMetaspaceFallback({
185
- addr: pastAddr,
186
- space: activeSpace,
187
- metaspace,
188
- }) as B2tFSItemIbGib_V1;
189
- } else {
190
- currItem = undefined;
191
- }
192
- }
193
-
194
- if (!quiet) {
195
- console.log(`File: ${normalizedRelPath} (branch: ${branchName}) (I: 6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d)`);
196
- if (commits.length === 0) {
197
- console.log('No comments found for this file.');
198
- } else {
199
- for (const commit of commits) {
200
- console.log(`\nitem ${commit.commitAddr}`);
201
- if (commit.timestamp) { console.log(`Date: ${commit.timestamp}`); }
202
- console.log(`\n ${commit.message}\n`);
203
- }
204
- }
205
- }
206
-
207
- return {
208
- branchName,
209
- targetPath: normalizedRelPath,
210
- commits,
211
- };
212
- }
213
- // #endregion File-Specific Log Mode
214
-
215
- // #region Standard Branch Log Mode
216
- const visitedAddrs = new Set<string>();
217
-
218
- while (currBranchAddr && !visitedAddrs.has(currBranchAddr)) {
219
- visitedAddrs.add(currBranchAddr);
220
-
221
- const branchIbGib = await getIbGibWithMetaspaceFallback({
222
- addr: currBranchAddr,
223
- space: activeSpace,
224
- metaspace,
225
- }) as B2tFSBranchIbGib_V1;
226
-
227
- if (!branchIbGib) {
228
- break;
229
- }
230
-
231
- const rootItemAddr = branchIbGib.rel8ns?.b2tFS_item?.at(-1) || branchIbGib.rel8ns?.b2tfs_item?.at(-1);
232
-
233
- let rootItem: B2tFSItemIbGib_V1 | undefined;
234
- if (rootItemAddr) {
235
- rootItem = await getIbGibWithMetaspaceFallback({
236
- addr: rootItemAddr,
237
- space: activeSpace,
238
- metaspace,
239
- }) as B2tFSItemIbGib_V1;
240
- }
241
-
242
- let commentAddrs = [
243
- ...(branchIbGib.rel8ns?.comment || []),
244
- ...(rootItem?.rel8ns?.comment || []),
245
- ];
246
- // Deduplicate
247
- commentAddrs = Array.from(new Set(commentAddrs));
248
-
249
- let message = '';
250
- let timestamp = branchIbGib.data?.committedAt || '';
251
- // If branch has a direct comment, use that first, otherwise use the last added comment on root item
252
- let primaryCommentAddr = branchIbGib.rel8ns?.comment?.at(-1) || rootItem?.rel8ns?.comment?.at(-1) || commentAddrs.at(0);
253
-
254
- if (primaryCommentAddr) {
255
- const commentIbGib = await getIbGibWithMetaspaceFallback({
256
- addr: primaryCommentAddr,
257
- space: activeSpace,
258
- metaspace,
259
- }) as CommentIbGib_V1;
260
-
261
- if (commentIbGib?.data?.text) {
262
- message = commentIbGib.data.text;
263
- }
264
- if (commentIbGib?.data?.textTimestamp || commentIbGib?.data?.timestamp) {
265
- timestamp = commentIbGib.data.textTimestamp || commentIbGib.data.timestamp || timestamp;
266
- }
267
- }
268
-
269
- const committedPaths = branchIbGib.data?.committedPaths || [];
270
- const itemComments: Array<{ path: string; name?: string; message: string }> = [];
271
-
272
- if (allComments && rootItem) {
273
- await logCmd_collectAllItemComments({
274
- item: rootItem,
275
- space: activeSpace,
276
- metaspace,
277
- currentRelPath: '',
278
- outComments: itemComments,
279
- });
280
- }
281
-
282
- if (message || primaryCommentAddr || (committedPaths && committedPaths.length > 0)) {
283
- commits.push({
284
- branchAddr: currBranchAddr,
285
- commitAddr: currBranchAddr,
286
- commentAddr: primaryCommentAddr,
287
- message: message || '(no commit message)',
288
- timestamp,
289
- author: 'vcs-user',
290
- rootItemAddr,
291
- committedPaths,
292
- itemComments: itemComments.length > 0 ? itemComments : undefined,
293
- });
294
- }
295
-
296
- // Move to previous branch node in timeline
297
- currBranchAddr = branchIbGib.rel8ns?.past?.at(0) || branchIbGib.rel8ns?.ancestor?.at(0);
298
- }
299
-
300
- if (!quiet) {
301
- console.log(`Branch: ${branchName} (I: 4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b)`);
302
- if (commits.length === 0) {
303
- console.log('No commits yet.');
304
- } else {
305
- for (const commit of commits) {
306
- console.log(`\ncommit ${commit.commitAddr}`);
307
- console.log(`Author: ${commit.author}`);
308
- console.log(`Date: ${commit.timestamp}`);
309
- console.log(`\n ${commit.message}\n`);
310
- if (commit.committedPaths && commit.committedPaths.length > 0) {
311
- console.log(`Changed: ${commit.committedPaths.join(', ')}`);
312
- }
313
- if (commit.itemComments && commit.itemComments.length > 0) {
314
- console.log('Item Comments:');
315
- for (const ic of commit.itemComments) {
316
- const label = ic.name ? `${ic.path} (${ic.name})` : ic.path;
317
- console.log(` * [${label}]: ${ic.message}`);
318
- }
319
- }
320
- }
321
- }
322
- }
323
-
324
- return {
325
- branchName,
326
- commits,
327
- };
328
- // #endregion Standard Branch Log Mode
329
- } catch (error) {
330
- console.error(`${lc} ${extractErrorMsg(error)} (E: 5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c)`);
331
- throw error;
332
- } finally {
333
- if (logalot) {
334
- console.log(`${lc} complete. (I: 6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d)`);
335
- }
336
- }
337
- }
338
-
339
- async function logCmd_findItemByPath({
340
- rootItemAddr,
341
- targetRelPath,
342
- space,
343
- metaspace,
344
- }: {
345
- rootItemAddr: string;
346
- targetRelPath: string;
347
- space: any;
348
- metaspace?: any;
349
- }): Promise<B2tFSItemIbGib_V1 | undefined> {
350
- const rootItem = await getIbGibWithMetaspaceFallback({
351
- addr: rootItemAddr,
352
- space,
353
- metaspace,
354
- }) as B2tFSItemIbGib_V1;
355
-
356
- if (!rootItem) { return undefined; }
357
- if (!targetRelPath || targetRelPath === '.' || targetRelPath === '') {
358
- return rootItem;
359
- }
360
-
361
- const segments = targetRelPath.split('/');
362
- let currentItem: B2tFSItemIbGib_V1 = rootItem;
363
-
364
- for (const segment of segments) {
365
- if (currentItem.data?.fsType !== 'folder') {
366
- return undefined;
367
- }
368
-
369
- const childAddrs = currentItem.rel8ns?.[B2TFS_CHILD_ITEM_REL8N_NAME] || [];
370
- let nextItem: B2tFSItemIbGib_V1 | undefined;
371
-
372
- for (const cAddr of childAddrs) {
373
- const child = await getIbGibWithMetaspaceFallback({
374
- addr: cAddr,
375
- space,
376
- metaspace,
377
- }) as B2tFSItemIbGib_V1;
378
-
379
- if (child && child.data?.name === segment) {
380
- nextItem = child;
381
- break;
382
- }
383
- }
384
-
385
- if (!nextItem) {
386
- return undefined;
387
- }
388
- currentItem = nextItem;
389
- }
390
-
391
- return currentItem;
392
- }
393
-
394
- async function logCmd_collectAllItemComments({
395
- item,
396
- space,
397
- metaspace,
398
- currentRelPath,
399
- outComments,
400
- }: {
401
- item: B2tFSItemIbGib_V1;
402
- space: any;
403
- metaspace?: any;
404
- currentRelPath: string;
405
- outComments: Array<{ path: string; name?: string; message: string }>;
406
- }): Promise<void> {
407
- if (!item || !item.data) { return; }
408
-
409
- const itemComments = item.rel8ns?.comment || [];
410
- for (const cAddr of itemComments) {
411
- const commentIbGib = await getIbGibWithMetaspaceFallback({
412
- addr: cAddr,
413
- space,
414
- metaspace,
415
- }) as CommentIbGib_V1;
416
-
417
- if (commentIbGib && commentIbGib.data?.text) {
418
- outComments.push({
419
- path: currentRelPath || '(root)',
420
- name: (commentIbGib.data as any)?.name,
421
- message: commentIbGib.data.text,
422
- });
423
- }
424
- }
425
-
426
- if (item.data.fsType === 'folder') {
427
- const childAddrs = item.rel8ns?.[B2TFS_CHILD_ITEM_REL8N_NAME] || [];
428
- for (const childAddr of childAddrs) {
429
- const childItem = await getIbGibWithMetaspaceFallback({
430
- addr: childAddr,
431
- space,
432
- metaspace,
433
- }) as B2tFSItemIbGib_V1;
434
-
435
- if (childItem && childItem.data) {
436
- const childRel = currentRelPath
437
- ? `${currentRelPath}/${childItem.data.name}`
438
- : childItem.data.name;
439
- await logCmd_collectAllItemComments({
440
- item: childItem,
441
- space,
442
- metaspace,
443
- currentRelPath: childRel,
444
- outComments,
445
- });
446
- }
447
- }
448
- }
449
- }