@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,383 +0,0 @@
1
- /**
2
- * @module status-helper
3
- *
4
- * Pure status inspection helpers and pending `.ib.*.md` comment metadata detection.
5
- */
6
-
7
- import path from 'node:path';
8
- import fs from 'node:fs/promises';
9
- import { Dirent } from 'node:fs';
10
- import crypto from 'node:crypto';
11
-
12
- import { B2tFSItemIbGib_V1, B2TFS_CHILD_ITEM_REL8N_NAME } from '../item/item-types.mjs';
13
- import { getIbGibWithMetaspaceFallback } from '../item/item-helper.mjs';
14
- import { B2tFSBranchIbGib_V1 } from '../branch/branch-types.mjs';
15
- import { isPathFiltered, parseFilterFileContent } from '../filter/glob-helper.mjs';
16
- import { getB2tFSIndexIbGib } from '../index/index-helper.mjs';
17
- import { B2tFSStagedItemRecord } from '../index/index-types.mjs';
18
- import { getOrCreateBranchSpace } from '../branch/branch-space-helper.mjs';
19
- import { resolveContextualBranchName } from '../branch/branch-helper.mjs';
20
-
21
- export interface VcsStatusItem {
22
- path: string;
23
- fsType: 'file' | 'folder';
24
- status: 'untracked' | 'modified' | 'deleted' | 'staged';
25
- }
26
-
27
- export interface PendingCommentInfo {
28
- /** Relative path of the companion file, e.g. "src/.ib.index.mts.md" or ".ib.architecture.md" */
29
- commentRelPath: string;
30
- /** Full disk path of the companion file */
31
- commentFullPath: string;
32
- /** Target relative path this comment attaches to, e.g. "src/index.mts" or "src" (folder) or "" (root) */
33
- targetRelPath: string;
34
- /** 'file' if .ib.<filename>.md matches a file, or 'folder' */
35
- targetType: 'file' | 'folder';
36
- /** The topic name (the * in .ib.*.md) or filename */
37
- topicName: string;
38
- /** Raw text content of the markdown comment file */
39
- content: string;
40
- }
41
-
42
- export interface RepoStatusResult {
43
- branchName: string;
44
- activeWorktreeDir: string;
45
- staged: VcsStatusItem[];
46
- modified: VcsStatusItem[];
47
- deleted: VcsStatusItem[];
48
- untracked: VcsStatusItem[];
49
- pendingComments: PendingCommentInfo[];
50
- }
51
-
52
- /**
53
- * Returns true if filename is a `.ib.*.md` comment metadata file.
54
- */
55
- export function isCommentMetadataFilename(filename: string): boolean {
56
- return filename.startsWith('.ib.') && filename.endsWith('.md') && filename.length > '.ib..md'.length;
57
- }
58
-
59
- /**
60
- * Extracts the inner topic / filename from `.ib.<topic>.md`.
61
- */
62
- export function extractCommentTopicName(filename: string): string {
63
- if (!isCommentMetadataFilename(filename)) { return ''; }
64
- return filename.slice(4, -3); // strips leading '.ib.' and trailing '.md'
65
- }
66
-
67
- /**
68
- * Pure helper to walk the branch graph items.
69
- */
70
- export async function walkBranchGraph({
71
- item,
72
- space,
73
- metaspace,
74
- currentRelPath,
75
- outMap,
76
- }: {
77
- item: B2tFSItemIbGib_V1;
78
- space: any;
79
- metaspace?: any;
80
- currentRelPath: string;
81
- outMap: Map<string, { relPath: string; fileHash?: string; fsType: 'file' | 'folder' }>;
82
- }): Promise<void> {
83
- if (!item || !item.data) { return; }
84
-
85
- const { fsType, fileHash } = item.data;
86
- if (currentRelPath) {
87
- outMap.set(currentRelPath, { relPath: currentRelPath, fileHash, fsType });
88
- }
89
-
90
- if (fsType === 'folder') {
91
- const childAddrs = item.rel8ns?.[B2TFS_CHILD_ITEM_REL8N_NAME] || [];
92
- for (const childAddr of childAddrs) {
93
- const childItem = await getIbGibWithMetaspaceFallback({
94
- addr: childAddr,
95
- space,
96
- metaspace,
97
- }) as B2tFSItemIbGib_V1;
98
- if (childItem && childItem.data) {
99
- const childRelPath = currentRelPath
100
- ? `${currentRelPath}/${childItem.data.name}`
101
- : childItem.data.name;
102
- await walkBranchGraph({
103
- item: childItem,
104
- space,
105
- metaspace,
106
- currentRelPath: childRelPath,
107
- outMap,
108
- });
109
- }
110
- }
111
- }
112
- }
113
-
114
- /**
115
- * Pure helper to scan physical workspace, separating source files from `.ib.*.md` comment files.
116
- */
117
- export async function scanPhysicalWorkspace({
118
- dirPath,
119
- baseDir,
120
- vcsFolderName,
121
- filterPatterns,
122
- outSourceMap,
123
- outCommentFiles,
124
- }: {
125
- dirPath: string;
126
- baseDir: string;
127
- vcsFolderName: string;
128
- filterPatterns: string[];
129
- outSourceMap: Map<string, { relPath: string; fullPath: string; isDirectory: boolean; fileHash?: string }>;
130
- outCommentFiles: Array<{ relPath: string; fullPath: string; parentRelPath: string; filename: string }>;
131
- }): Promise<void> {
132
- let entries: Dirent[] = [];
133
- try {
134
- entries = await fs.readdir(dirPath, { withFileTypes: true });
135
- } catch {
136
- return;
137
- }
138
-
139
- for (const entry of entries) {
140
- const fullEntryPath = path.join(dirPath, entry.name);
141
- const relPath = path.relative(baseDir, fullEntryPath).replace(/\\/g, '/');
142
-
143
- // Ignore vcs storage folder, .git, and worktrees folder b
144
- if (
145
- relPath === vcsFolderName || relPath.startsWith(vcsFolderName + '/') ||
146
- relPath === '.git' || relPath.startsWith('.git/') ||
147
- relPath === 'b' || relPath.startsWith('b/')
148
- ) {
149
- continue;
150
- }
151
-
152
- if (isPathFiltered({ relativePath: relPath, isDirectory: entry.isDirectory(), filterPatterns })) {
153
- continue;
154
- }
155
-
156
- if (entry.isDirectory()) {
157
- outSourceMap.set(relPath, { relPath, fullPath: fullEntryPath, isDirectory: true });
158
- await scanPhysicalWorkspace({
159
- dirPath: fullEntryPath,
160
- baseDir,
161
- vcsFolderName,
162
- filterPatterns,
163
- outSourceMap,
164
- outCommentFiles,
165
- });
166
- } else if (entry.isFile()) {
167
- if (isCommentMetadataFilename(entry.name)) {
168
- const parentRelPath = path.relative(baseDir, dirPath).replace(/\\/g, '/');
169
- outCommentFiles.push({
170
- relPath,
171
- fullPath: fullEntryPath,
172
- parentRelPath: parentRelPath === '.' ? '' : parentRelPath,
173
- filename: entry.name,
174
- });
175
- } else {
176
- let fileHash: string | undefined;
177
- try {
178
- const fileData = await fs.readFile(fullEntryPath);
179
- fileHash = crypto.createHash('sha256').update(fileData).digest('hex');
180
- } catch {
181
- // File unreadable
182
- }
183
- outSourceMap.set(relPath, { relPath, fullPath: fullEntryPath, isDirectory: false, fileHash });
184
- }
185
- }
186
- }
187
- }
188
-
189
- /**
190
- * Computes complete repository status, including staged, modified, deleted, untracked,
191
- * and mapped pending `.ib.*.md` comment files.
192
- */
193
- export async function getRepoStatus({
194
- metaspace,
195
- localSpace,
196
- vcsPath,
197
- repoRoot,
198
- targetDir = repoRoot,
199
- vcsFolderName = '.vcsgib',
200
- }: {
201
- metaspace: any;
202
- localSpace: any;
203
- vcsPath: string;
204
- repoRoot: string;
205
- targetDir?: string;
206
- vcsFolderName?: string;
207
- }): Promise<RepoStatusResult> {
208
- const indexIbGib = await getB2tFSIndexIbGib({ space: localSpace, vcsPath });
209
- const branchName = resolveContextualBranchName({ targetDir, repoRoot, indexIbGib });
210
- const activeWorktreeDir = branchName === 'main' ? repoRoot : path.join(repoRoot, 'b', branchName);
211
-
212
- const { space: activeBranchSpace } = await getOrCreateBranchSpace({
213
- metaspace,
214
- vcsPath,
215
- branchName,
216
- });
217
-
218
- const stagedMap = new Map<string, B2tFSStagedItemRecord>();
219
- const indexStagedPaths = indexIbGib?.data?.stagedPaths || {};
220
- for (const [relPath, itemRec] of Object.entries(indexStagedPaths)) {
221
- stagedMap.set(relPath, itemRec);
222
- }
223
-
224
- let rootItemAddr: string | undefined;
225
- const branchAddrs = [
226
- ...(indexIbGib?.rel8ns?.branch || []),
227
- ...(indexIbGib?.rel8ns?.branch_tjp || []),
228
- ];
229
-
230
- if (branchAddrs.length > 0) {
231
- let branchIbGibs: B2tFSBranchIbGib_V1[] = [];
232
- for (const bAddr of branchAddrs) {
233
- const bIbGib = await getIbGibWithMetaspaceFallback({
234
- addr: bAddr,
235
- space: activeBranchSpace,
236
- metaspace,
237
- });
238
- if (bIbGib) {
239
- branchIbGibs.push(bIbGib as B2tFSBranchIbGib_V1);
240
- }
241
- }
242
-
243
- const activeBranchIbGib = branchIbGibs.find(
244
- (b) => (b as B2tFSBranchIbGib_V1)?.data?.name === branchName,
245
- ) as B2tFSBranchIbGib_V1 || (branchIbGibs.at(0) as B2tFSBranchIbGib_V1);
246
-
247
- rootItemAddr = activeBranchIbGib?.rel8ns?.b2tFS_item?.at(0) || activeBranchIbGib?.rel8ns?.b2tfs_item?.at(0);
248
- }
249
-
250
- let filterPatterns: string[] = [];
251
- const ignorePath = path.join(activeWorktreeDir, '.ibgibignore');
252
- try {
253
- const ignoreContent = await fs.readFile(ignorePath, 'utf8');
254
- filterPatterns = parseFilterFileContent(ignoreContent);
255
- } catch {
256
- // Ignore file missing is fine
257
- }
258
-
259
- const branchItemsMap = new Map<string, { relPath: string; fileHash?: string; fsType: 'file' | 'folder' }>();
260
- if (rootItemAddr) {
261
- const rootItem = await getIbGibWithMetaspaceFallback({
262
- addr: rootItemAddr,
263
- space: activeBranchSpace,
264
- metaspace,
265
- }) as B2tFSItemIbGib_V1;
266
-
267
- if (rootItem) {
268
- await walkBranchGraph({
269
- item: rootItem,
270
- space: activeBranchSpace,
271
- metaspace,
272
- currentRelPath: '',
273
- outMap: branchItemsMap,
274
- });
275
- }
276
- }
277
-
278
- const physicalItemsMap = new Map<string, { relPath: string; fullPath: string; isDirectory: boolean; fileHash?: string }>();
279
- const rawCommentFiles: Array<{ relPath: string; fullPath: string; parentRelPath: string; filename: string }> = [];
280
-
281
- await scanPhysicalWorkspace({
282
- dirPath: activeWorktreeDir,
283
- baseDir: activeWorktreeDir,
284
- vcsFolderName,
285
- filterPatterns,
286
- outSourceMap: physicalItemsMap,
287
- outCommentFiles: rawCommentFiles,
288
- });
289
-
290
- const staged: VcsStatusItem[] = [];
291
- const modified: VcsStatusItem[] = [];
292
- const deleted: VcsStatusItem[] = [];
293
- const untracked: VcsStatusItem[] = [];
294
-
295
- for (const [relPath, stagedRec] of stagedMap.entries()) {
296
- staged.push({
297
- path: relPath,
298
- fsType: stagedRec.fsType || 'file',
299
- status: 'staged',
300
- });
301
- }
302
-
303
- for (const [relPath, physItem] of physicalItemsMap.entries()) {
304
- if (stagedMap.has(relPath)) {
305
- continue;
306
- }
307
-
308
- const branchItem = branchItemsMap.get(relPath);
309
- if (!branchItem) {
310
- untracked.push({
311
- path: relPath,
312
- fsType: physItem.isDirectory ? 'folder' : 'file',
313
- status: 'untracked',
314
- });
315
- } else {
316
- if (!physItem.isDirectory && physItem.fileHash && branchItem.fileHash && physItem.fileHash !== branchItem.fileHash) {
317
- modified.push({
318
- path: relPath,
319
- fsType: 'file',
320
- status: 'modified',
321
- });
322
- }
323
- }
324
- }
325
-
326
- for (const [relPath, branchItem] of branchItemsMap.entries()) {
327
- if (!relPath || relPath === '.' || relPath === '') { continue; }
328
- if (!physicalItemsMap.has(relPath) && !stagedMap.has(relPath)) {
329
- deleted.push({
330
- path: relPath,
331
- fsType: branchItem.fsType,
332
- status: 'deleted',
333
- });
334
- }
335
- }
336
-
337
- // Map raw comment files to targets (file or folder)
338
- const pendingComments: PendingCommentInfo[] = [];
339
- for (const raw of rawCommentFiles) {
340
- const topicName = extractCommentTopicName(raw.filename);
341
- const candidateFileRelPath = raw.parentRelPath ? `${raw.parentRelPath}/${topicName}` : topicName;
342
-
343
- let targetType: 'file' | 'folder' = 'folder';
344
- let targetRelPath = raw.parentRelPath;
345
-
346
- if (physicalItemsMap.has(candidateFileRelPath) && !physicalItemsMap.get(candidateFileRelPath)?.isDirectory) {
347
- targetType = 'file';
348
- targetRelPath = candidateFileRelPath;
349
- } else if (branchItemsMap.has(candidateFileRelPath) && branchItemsMap.get(candidateFileRelPath)?.fsType === 'file') {
350
- targetType = 'file';
351
- targetRelPath = candidateFileRelPath;
352
- } else if (stagedMap.has(candidateFileRelPath)) {
353
- targetType = 'file';
354
- targetRelPath = candidateFileRelPath;
355
- }
356
-
357
- let content = '';
358
- try {
359
- content = await fs.readFile(raw.fullPath, 'utf8');
360
- } catch {
361
- // Unreadable comment file
362
- }
363
-
364
- pendingComments.push({
365
- commentRelPath: raw.relPath,
366
- commentFullPath: raw.fullPath,
367
- targetRelPath,
368
- targetType,
369
- topicName,
370
- content,
371
- });
372
- }
373
-
374
- return {
375
- branchName,
376
- activeWorktreeDir,
377
- staged,
378
- modified,
379
- deleted,
380
- untracked,
381
- pendingComments,
382
- };
383
- }