ultracode 5.4.0 → 5.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/dist/chunks/analysis-tool-handlers-GH5FDEWW.js +817 -0
  2. package/dist/chunks/analysis-tool-handlers-IXP4MWZX.js +817 -0
  3. package/dist/chunks/analysis-tool-handlers-LC2BTQYK.js +13 -0
  4. package/dist/chunks/analysis-tool-handlers-QYFKQPFL.js +817 -0
  5. package/dist/chunks/autodoc-tool-handlers-2HF6ERYN.js +1112 -0
  6. package/dist/chunks/autodoc-tool-handlers-4OGQJ7C3.js +1112 -0
  7. package/dist/chunks/autodoc-tool-handlers-N736CB56.js +138 -0
  8. package/dist/chunks/autodoc-tool-handlers-NQYBY6U4.js +1112 -0
  9. package/dist/chunks/branch-tool-handlers-KW3H4FJK.js +276 -0
  10. package/dist/chunks/branch-tool-handlers-QOUDZKJ2.js +276 -0
  11. package/dist/chunks/branch-tool-handlers-RB2U36KI.js +2 -0
  12. package/dist/chunks/branch-tool-handlers-ZHJM6PDK.js +276 -0
  13. package/dist/chunks/chunk-2Z6OQPYC.js +656 -0
  14. package/dist/chunks/chunk-3MQ7LRPN.js +322 -0
  15. package/dist/chunks/chunk-4W6QYGXZ.js +10 -0
  16. package/dist/chunks/chunk-533NFGUG.js +1 -0
  17. package/dist/chunks/chunk-5NUPOPWM.js +1 -0
  18. package/dist/chunks/chunk-AK4HIPA2.js +322 -0
  19. package/dist/chunks/chunk-B3H5NS3I.js +656 -0
  20. package/dist/chunks/chunk-DPTZHDST.js +4 -0
  21. package/dist/chunks/chunk-E5HQWLU5.js +322 -0
  22. package/dist/chunks/chunk-EOH25B5P.js +572 -0
  23. package/dist/chunks/chunk-ESV6F6E3.js +3179 -0
  24. package/dist/chunks/chunk-FPELPFER.js +924 -0
  25. package/dist/chunks/chunk-G6J42I55.js +161 -0
  26. package/dist/chunks/chunk-GCQE7ZYW.js +1 -0
  27. package/dist/chunks/chunk-GTIF6MOX.js +1 -0
  28. package/dist/chunks/chunk-I6STSSAK.js +2 -0
  29. package/dist/chunks/chunk-J2WBGTK2.js +4697 -0
  30. package/dist/chunks/chunk-KAYOX5EB.js +4697 -0
  31. package/dist/chunks/chunk-KPMTACOT.js +656 -0
  32. package/dist/chunks/chunk-L376GZ44.js +3179 -0
  33. package/dist/chunks/chunk-LCTOTHDA.js +15 -0
  34. package/dist/chunks/chunk-LEDJ7GVQ.js +316 -0
  35. package/dist/chunks/chunk-LH4OUKNZ.js +277 -0
  36. package/dist/chunks/chunk-O6IE2MEZ.js +161 -0
  37. package/dist/chunks/chunk-OEXPCY3F.js +316 -0
  38. package/dist/chunks/chunk-OMXOLFDN.js +924 -0
  39. package/dist/chunks/chunk-PLPBXWOU.js +3179 -0
  40. package/dist/chunks/chunk-PWLE5DN2.js +572 -0
  41. package/dist/chunks/chunk-PY43JPWL.js +447 -0
  42. package/dist/chunks/chunk-Q3B4EB7A.js +15 -0
  43. package/dist/chunks/chunk-Q5LPVLXA.js +337 -0
  44. package/dist/chunks/chunk-QIRZHZK2.js +5 -0
  45. package/dist/chunks/chunk-ROQ27LSL.js +924 -0
  46. package/dist/chunks/chunk-S5Q7BD6J.js +572 -0
  47. package/dist/chunks/chunk-SAMX3HJQ.js +337 -0
  48. package/dist/chunks/chunk-SV3WKUNV.js +1 -0
  49. package/dist/chunks/chunk-TCHCDCDO.js +167 -0
  50. package/dist/chunks/chunk-TR3HS7U6.js +316 -0
  51. package/dist/chunks/chunk-TUWE6FCW.js +167 -0
  52. package/dist/chunks/chunk-TVOTA7EE.js +277 -0
  53. package/dist/chunks/chunk-VS44D772.js +337 -0
  54. package/dist/chunks/chunk-WIE3G5ES.js +167 -0
  55. package/dist/chunks/chunk-XG3ACLWR.js +5 -0
  56. package/dist/chunks/chunk-XJ2Z5QQO.js +1 -0
  57. package/dist/chunks/chunk-XK2NY7RB.js +277 -0
  58. package/dist/chunks/chunk-Y4F7NZFZ.js +4700 -0
  59. package/dist/chunks/chunk-YS75L3ZS.js +161 -0
  60. package/dist/chunks/chunk-ZVG5HHI3.js +15 -0
  61. package/dist/chunks/dev-agent-DDDIVWOF.js +1 -0
  62. package/dist/chunks/dev-agent-E2VCFKXN.js +1624 -0
  63. package/dist/chunks/dev-agent-KJNSU5KQ.js +1624 -0
  64. package/dist/chunks/dev-agent-NDERYIPV.js +1624 -0
  65. package/dist/chunks/faiss-provider-7R4BQDIV.js +12 -0
  66. package/dist/chunks/faiss-provider-7ZFRSDN5.js +12 -0
  67. package/dist/chunks/faiss-provider-SXB7FTLB.js +1 -0
  68. package/dist/chunks/faiss-provider-TKLBEUSH.js +12 -0
  69. package/dist/chunks/file-tool-handlers-5DODQXGF.js +1027 -0
  70. package/dist/chunks/file-tool-handlers-KGHLE4KR.js +1027 -0
  71. package/dist/chunks/file-tool-handlers-KTOQ4NFS.js +12 -0
  72. package/dist/chunks/file-tool-handlers-V4SFUDQB.js +1027 -0
  73. package/dist/chunks/graph-metrics-tool-handlers-3AV4X4ZY.js +65 -0
  74. package/dist/chunks/graph-metrics-tool-handlers-3VMDQHJ6.js +65 -0
  75. package/dist/chunks/graph-metrics-tool-handlers-BZ6E6YHF.js +1 -0
  76. package/dist/chunks/graph-metrics-tool-handlers-IYBGSXL7.js +65 -0
  77. package/dist/chunks/graph-storage-factory-2CQ2RPDV.js +13 -0
  78. package/dist/chunks/graph-storage-factory-C5SMMYL6.js +13 -0
  79. package/dist/chunks/graph-storage-factory-EEO2V3GJ.js +1 -0
  80. package/dist/chunks/graph-storage-factory-WBCTXP34.js +13 -0
  81. package/dist/chunks/history-tool-handlers-AS7OQFZI.js +1 -0
  82. package/dist/chunks/history-tool-handlers-FSNJYXV2.js +208 -0
  83. package/dist/chunks/history-tool-handlers-JZAH4EIQ.js +208 -0
  84. package/dist/chunks/history-tool-handlers-KCSCXZ7T.js +208 -0
  85. package/dist/chunks/incremental-updater-A2EL4QXU.js +14 -0
  86. package/dist/chunks/incremental-updater-EQIKBVY2.js +14 -0
  87. package/dist/chunks/incremental-updater-JFGRPH3B.js +14 -0
  88. package/dist/chunks/incremental-updater-S5BAAGHP.js +1 -0
  89. package/dist/chunks/indexer-agent-ASKY7JPG.js +1 -0
  90. package/dist/chunks/indexer-agent-NKAOF323.js +21 -0
  91. package/dist/chunks/indexer-agent-PJN5IOKQ.js +21 -0
  92. package/dist/chunks/indexer-agent-WRJFWKZX.js +21 -0
  93. package/dist/chunks/indexing-pipeline-D4P2O72Z.js +249 -0
  94. package/dist/chunks/indexing-pipeline-L7C543N4.js +1 -0
  95. package/dist/chunks/indexing-pipeline-NHPRN3AB.js +249 -0
  96. package/dist/chunks/indexing-pipeline-ZAXCZU22.js +249 -0
  97. package/dist/chunks/layered-faiss-provider-62CNW54X.js +1 -0
  98. package/dist/chunks/layered-faiss-provider-O7L77GFX.js +12 -0
  99. package/dist/chunks/layered-faiss-provider-RVHLHLPK.js +12 -0
  100. package/dist/chunks/layered-faiss-provider-YT7EDIJI.js +12 -0
  101. package/dist/chunks/merge-agent-3RF7VFF5.js +2481 -0
  102. package/dist/chunks/merge-agent-JCKTCBCE.js +2481 -0
  103. package/dist/chunks/merge-agent-VCL7OXPN.js +2481 -0
  104. package/dist/chunks/merge-agent-ZGK24WVF.js +11 -0
  105. package/dist/chunks/merge-tool-handlers-GV2LOIKU.js +277 -0
  106. package/dist/chunks/merge-tool-handlers-TYDWU5X2.js +277 -0
  107. package/dist/chunks/merge-tool-handlers-U7X2ZO2M.js +1 -0
  108. package/dist/chunks/merge-tool-handlers-YH62ZLPJ.js +277 -0
  109. package/dist/chunks/pattern-tool-handlers-76NF5JDS.js +13 -0
  110. package/dist/chunks/pattern-tool-handlers-IJAGEIVD.js +1549 -0
  111. package/dist/chunks/pattern-tool-handlers-VA5WYA62.js +1549 -0
  112. package/dist/chunks/pattern-tool-handlers-WQ6UBMJS.js +1549 -0
  113. package/dist/chunks/query-agent-36ADGCFZ.js +1 -0
  114. package/dist/chunks/query-agent-H22CR5N5.js +191 -0
  115. package/dist/chunks/query-agent-K2UGZS4M.js +191 -0
  116. package/dist/chunks/query-agent-YJCEHOXD.js +191 -0
  117. package/dist/chunks/semantic-agent-AC7CBEDE.js +6381 -0
  118. package/dist/chunks/semantic-agent-HK5X6CKU.js +6381 -0
  119. package/dist/chunks/semantic-agent-KONIKEGW.js +6381 -0
  120. package/dist/chunks/semantic-agent-LH6IZ2L7.js +137 -0
  121. package/dist/chunks/semantic-tool-handlers-5LMSH2U7.js +3 -0
  122. package/dist/chunks/semantic-tool-handlers-735UMO7Y.js +817 -0
  123. package/dist/chunks/semantic-tool-handlers-BNUYPP7X.js +817 -0
  124. package/dist/chunks/semantic-tool-handlers-MYZPEUD2.js +817 -0
  125. package/dist/chunks/snapshot-tool-handlers-6SIHZT2F.js +201 -0
  126. package/dist/chunks/snapshot-tool-handlers-DS4P3KOT.js +201 -0
  127. package/dist/chunks/snapshot-tool-handlers-JYHRFPC7.js +201 -0
  128. package/dist/chunks/snapshot-tool-handlers-YEHMAT3L.js +1 -0
  129. package/dist/chunks/storage-paths-A3C7WHHG.js +8 -0
  130. package/dist/chunks/storage-paths-HDYH7WPM.js +1 -0
  131. package/dist/chunks/storage-paths-IMFRHBWF.js +8 -0
  132. package/dist/chunks/storage-paths-P3PUSMUD.js +8 -0
  133. package/dist/chunks/taint-tool-handlers-CWESOOMQ.js +68 -0
  134. package/dist/chunks/taint-tool-handlers-OG3NVVP3.js +1 -0
  135. package/dist/chunks/taint-tool-handlers-ON3G3FA7.js +68 -0
  136. package/dist/chunks/taint-tool-handlers-P4P5J6DB.js +68 -0
  137. package/dist/chunks/tracing-tool-handlers-4BDCXTZZ.js +3935 -0
  138. package/dist/chunks/tracing-tool-handlers-6FPNM7HX.js +3935 -0
  139. package/dist/chunks/tracing-tool-handlers-LQTQ5SKK.js +89 -0
  140. package/dist/chunks/tracing-tool-handlers-XRQX2DTS.js +3935 -0
  141. package/dist/chunks/validation-tool-handlers-DZUG7KYY.js +2 -0
  142. package/dist/chunks/validation-tool-handlers-O6TGFSH5.js +555 -0
  143. package/dist/chunks/validation-tool-handlers-RREUYKIR.js +555 -0
  144. package/dist/chunks/validation-tool-handlers-XPWSMS37.js +555 -0
  145. package/dist/index.js +13 -13
  146. package/dist/roslyn-addon/.build-hash +1 -1
  147. package/dist/roslyn-addon/ILGPU.Algorithms.dll +0 -0
  148. package/dist/roslyn-addon/ILGPU.dll +0 -0
  149. package/dist/roslyn-addon/UltraCode.CSharp.deps.json +35 -0
  150. package/dist/roslyn-addon/UltraCode.CSharp.dll +0 -0
  151. package/package.json +1 -1
@@ -0,0 +1,316 @@
1
+ import { getGraphStorage } from './chunk-Y4F7NZFZ.js';
2
+ import { existsSync, readFileSync, writeFileSync } from 'fs';
3
+ import path from 'path';
4
+
5
+ function extractReferences(content) {
6
+ const refs = [];
7
+ const fileLinePattern = /(?:`([^`]+\.(?:ts|js|tsx|jsx|py|go|rs|java|kt|swift|cpp|c|h)):(\d+)`|([a-zA-Z0-9_\-/.]+\.(?:ts|js|tsx|jsx|py|go|rs|java|kt|swift|cpp|c|h)):(\d+))/g;
8
+ let match;
9
+ while ((match = fileLinePattern.exec(content)) !== null) {
10
+ const filePath = match[1] || match[3];
11
+ const lineNum = match[2] || match[4];
12
+ if (filePath && lineNum) {
13
+ refs.push({
14
+ original: match[0],
15
+ filePath,
16
+ lineNumber: parseInt(lineNum, 10),
17
+ startIndex: match.index,
18
+ endIndex: match.index + match[0].length
19
+ });
20
+ }
21
+ }
22
+ const mdLinkPattern = /\[([^\]]+)\]\(([^)]+\.(?:ts|js|tsx|jsx|py|go|rs|java|kt|swift|cpp|c|h))(?:#L(\d+))?\)/g;
23
+ while ((match = mdLinkPattern.exec(content)) !== null) {
24
+ const mdFilePath = match[2];
25
+ if (mdFilePath) {
26
+ refs.push({
27
+ original: match[0],
28
+ filePath: mdFilePath,
29
+ lineNumber: match[3] ? parseInt(match[3], 10) : void 0,
30
+ startIndex: match.index,
31
+ endIndex: match.index + match[0].length
32
+ });
33
+ }
34
+ }
35
+ return refs;
36
+ }
37
+ function extractSections(content) {
38
+ const lines = content.split("\n");
39
+ const sections = [];
40
+ let currentSection = null;
41
+ let contentLines = [];
42
+ for (let i = 0; i < lines.length; i++) {
43
+ const line = lines[i] ?? "";
44
+ const headerMatch = line.match(/^(#{1,6})\s+(.+)$/);
45
+ if (headerMatch?.[2]) {
46
+ if (currentSection) {
47
+ currentSection.content = contentLines.join("\n");
48
+ currentSection.endLine = i - 1;
49
+ sections.push(currentSection);
50
+ }
51
+ currentSection = {
52
+ title: headerMatch[2],
53
+ content: "",
54
+ startLine: i,
55
+ endLine: i,
56
+ relatedEntities: []
57
+ };
58
+ contentLines = [];
59
+ } else if (currentSection) {
60
+ contentLines.push(line);
61
+ const entityRefs = line.match(/`([A-Z][a-zA-Z0-9_]+)`/g);
62
+ if (entityRefs) {
63
+ for (const ref of entityRefs) {
64
+ const name = ref.slice(1, -1);
65
+ if (!currentSection.relatedEntities.includes(name)) {
66
+ currentSection.relatedEntities.push(name);
67
+ }
68
+ }
69
+ }
70
+ }
71
+ }
72
+ if (currentSection) {
73
+ currentSection.content = contentLines.join("\n");
74
+ currentSection.endLine = lines.length - 1;
75
+ sections.push(currentSection);
76
+ }
77
+ return sections;
78
+ }
79
+ async function detectChanges(modulePath, existingDoc, currentEntities) {
80
+ const changes = [];
81
+ const refs = extractReferences(existingDoc);
82
+ const sections = extractSections(existingDoc);
83
+ const documentedEntities = /* @__PURE__ */ new Set();
84
+ for (const section of sections) {
85
+ for (const entity of section.relatedEntities) {
86
+ documentedEntities.add(entity);
87
+ }
88
+ }
89
+ const entityPattern = /`([A-Z][a-zA-Z0-9_]+)`/g;
90
+ let match;
91
+ while ((match = entityPattern.exec(existingDoc)) !== null) {
92
+ if (match[1]) {
93
+ documentedEntities.add(match[1]);
94
+ }
95
+ }
96
+ for (const entity of currentEntities) {
97
+ if (!documentedEntities.has(entity.name)) {
98
+ changes.push({
99
+ type: "added",
100
+ entityId: entity.id,
101
+ entityName: entity.name,
102
+ entityType: entity.type,
103
+ filePath: entity.filePath,
104
+ newLineNumber: entity.location?.start?.line,
105
+ timestamp: /* @__PURE__ */ new Date()
106
+ });
107
+ }
108
+ }
109
+ const currentEntityNames = new Set(currentEntities.map((e) => e.name));
110
+ for (const docEntity of documentedEntities) {
111
+ if (!currentEntityNames.has(docEntity)) {
112
+ changes.push({
113
+ type: "deleted",
114
+ entityName: docEntity,
115
+ entityType: "unknown",
116
+ filePath: modulePath,
117
+ timestamp: /* @__PURE__ */ new Date()
118
+ });
119
+ }
120
+ }
121
+ for (const ref of refs) {
122
+ if (ref.lineNumber && ref.entityName) {
123
+ const entity = currentEntities.find((e) => e.name === ref.entityName);
124
+ if (entity && entity.location?.start?.line !== ref.lineNumber) {
125
+ changes.push({
126
+ type: "moved",
127
+ entityId: entity.id,
128
+ entityName: entity.name,
129
+ entityType: entity.type,
130
+ filePath: entity.filePath,
131
+ oldLineNumber: ref.lineNumber,
132
+ newLineNumber: entity.location?.start?.line,
133
+ timestamp: /* @__PURE__ */ new Date()
134
+ });
135
+ }
136
+ }
137
+ }
138
+ return changes;
139
+ }
140
+ function updateReferences(content, changes) {
141
+ let updated = content;
142
+ const lineUpdates = /* @__PURE__ */ new Map();
143
+ for (const change of changes) {
144
+ if (change.type === "moved" && change.oldLineNumber && change.newLineNumber) {
145
+ const key = `${change.filePath}:${change.oldLineNumber}`;
146
+ lineUpdates.set(key, { old: change.oldLineNumber, new: change.newLineNumber });
147
+ }
148
+ }
149
+ const fileLinePattern = /(`[^`]+\.(?:ts|js|tsx|jsx)):(\d+)`/g;
150
+ updated = updated.replace(fileLinePattern, (match, filePart, lineNum) => {
151
+ const line = parseInt(lineNum, 10);
152
+ for (const [key, update] of lineUpdates) {
153
+ if (key.endsWith(`:${line}`)) {
154
+ return `${filePart}:${update.new}\``;
155
+ }
156
+ }
157
+ return match;
158
+ });
159
+ const mdLinkPattern = /(\[[^\]]+\]\([^)]+\.(?:ts|js|tsx|jsx))#L(\d+)\)/g;
160
+ updated = updated.replace(mdLinkPattern, (match, linkPart, lineNum) => {
161
+ const line = parseInt(lineNum, 10);
162
+ for (const [key, update] of lineUpdates) {
163
+ if (key.endsWith(`:${line}`)) {
164
+ return `${linkPart}#L${update.new})`;
165
+ }
166
+ }
167
+ return match;
168
+ });
169
+ return updated;
170
+ }
171
+ function mergeWithExisting(existingContent, newContent, changes) {
172
+ const existingSections = extractSections(existingContent);
173
+ const newSections = extractSections(newContent);
174
+ const result = [];
175
+ const processedNewSections = /* @__PURE__ */ new Set();
176
+ for (const existingSection of existingSections) {
177
+ const newSection = newSections.find((s) => s.title === existingSection.title);
178
+ if (newSection) {
179
+ processedNewSections.add(newSection.title);
180
+ const addedEntities = changes.filter((c) => c.type === "added").map((c) => c.entityName);
181
+ if (addedEntities.length > 0 && existingSection.title.toLowerCase().includes("export")) {
182
+ result.push(`## ${existingSection.title}`);
183
+ result.push(existingSection.content);
184
+ result.push("");
185
+ result.push("### Added");
186
+ result.push("");
187
+ for (const entity of addedEntities) {
188
+ result.push(`- \`${entity}\` *(added ${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]})*`);
189
+ }
190
+ result.push("");
191
+ } else {
192
+ result.push(`## ${existingSection.title}`);
193
+ result.push(existingSection.content);
194
+ }
195
+ } else {
196
+ result.push(`## ${existingSection.title}`);
197
+ result.push(existingSection.content);
198
+ }
199
+ }
200
+ for (const newSection of newSections) {
201
+ if (!processedNewSections.has(newSection.title)) {
202
+ const existsInOriginal = existingSections.some((s) => s.title === newSection.title);
203
+ if (!existsInOriginal) {
204
+ result.push("");
205
+ result.push(`## ${newSection.title}`);
206
+ result.push(newSection.content);
207
+ }
208
+ }
209
+ }
210
+ return result.join("\n");
211
+ }
212
+ function markDeleted(content, deletedEntities) {
213
+ if (deletedEntities.length === 0) return content;
214
+ let updated = content;
215
+ if (!updated.includes("## Deprecated") && !updated.includes("## Deleted")) {
216
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
217
+ const deletedSection = ["", "## Deleted", "", "*The following items were removed from the codebase:*", ""];
218
+ for (const deleted of deletedEntities) {
219
+ deletedSection.push(`- ~~\`${deleted.entityName}\`~~ *(removed ${timestamp})*`);
220
+ }
221
+ deletedSection.push("");
222
+ updated += deletedSection.join("\n");
223
+ } else {
224
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
225
+ const insertPoint = updated.indexOf("## Deleted");
226
+ if (insertPoint !== -1) {
227
+ const afterHeader = updated.indexOf("\n\n", insertPoint) + 2;
228
+ const newItems = deletedEntities.map((d) => `- ~~\`${d.entityName}\`~~ *(removed ${timestamp})*`).join("\n");
229
+ updated = updated.slice(0, afterHeader) + newItems + "\n" + updated.slice(afterHeader);
230
+ }
231
+ }
232
+ for (const deleted of deletedEntities) {
233
+ const pattern = new RegExp(`\`${deleted.entityName}\`(?![^~]*~~)`, "g");
234
+ updated = updated.replace(pattern, `~~\`${deleted.entityName}\`~~`);
235
+ }
236
+ return updated;
237
+ }
238
+ async function updateModuleDoc(modulePath, docPath, newContent, options = {}) {
239
+ const result = {
240
+ docPath,
241
+ updated: false,
242
+ changes: []
243
+ };
244
+ const docExists = existsSync(docPath);
245
+ if (!docExists) {
246
+ result.updated = true;
247
+ result.newContent = newContent;
248
+ result.changes.push({
249
+ type: "created_new",
250
+ description: "Created new documentation file"
251
+ });
252
+ return result;
253
+ }
254
+ const existingContent = readFileSync(docPath, "utf-8");
255
+ const storage = await getGraphStorage();
256
+ const currentEntities = await storage.searchEntitiesInDirectory(modulePath);
257
+ const changes = await detectChanges(modulePath, existingContent, currentEntities);
258
+ if (changes.length === 0) {
259
+ return result;
260
+ }
261
+ let updatedContent = existingContent;
262
+ const movedChanges = changes.filter((c) => c.type === "moved");
263
+ if (movedChanges.length > 0) {
264
+ updatedContent = updateReferences(updatedContent, movedChanges);
265
+ result.changes.push({
266
+ type: "reference_updated",
267
+ description: `Updated ${movedChanges.length} line/file references`
268
+ });
269
+ }
270
+ const addedChanges = changes.filter((c) => c.type === "added");
271
+ if (addedChanges.length > 0) {
272
+ updatedContent = mergeWithExisting(updatedContent, newContent, addedChanges);
273
+ result.changes.push({
274
+ type: "content_added",
275
+ description: `Added documentation for ${addedChanges.length} new entities: ${addedChanges.map((c) => c.entityName).join(", ")}`
276
+ });
277
+ }
278
+ const deletedChanges = changes.filter((c) => c.type === "deleted");
279
+ if (deletedChanges.length > 0) {
280
+ updatedContent = markDeleted(updatedContent, deletedChanges);
281
+ result.changes.push({
282
+ type: "content_marked_deleted",
283
+ description: `Marked ${deletedChanges.length} deleted entities: ${deletedChanges.map((c) => c.entityName).join(", ")}`
284
+ });
285
+ }
286
+ if (options.useLlm && options.llmEnhancer && addedChanges.length > 0) {
287
+ updatedContent = await options.llmEnhancer(updatedContent, addedChanges);
288
+ }
289
+ if (updatedContent !== existingContent) {
290
+ result.updated = true;
291
+ result.newContent = updatedContent;
292
+ }
293
+ return result;
294
+ }
295
+ async function updateAllModuleDocs(rootDir, options = {}) {
296
+ const results = [];
297
+ const { scanModules, generateModuleReadme } = await import('./doc-generator-RMUSNK3G.js');
298
+ const modules = await scanModules(rootDir);
299
+ for (const mod of modules) {
300
+ const docPath = path.join(mod.path, "AUTODOC.md");
301
+ const newContent = generateModuleReadme(mod);
302
+ const result = await updateModuleDoc(mod.path, docPath, newContent, {
303
+ useLlm: options.useLlm,
304
+ llmEnhancer: options.llmEnhancer
305
+ });
306
+ if (result.updated && !options.preview && result.newContent) {
307
+ writeFileSync(docPath, result.newContent, "utf-8");
308
+ }
309
+ results.push(result);
310
+ }
311
+ return results;
312
+ }
313
+
314
+ export { detectChanges, extractReferences, extractSections, markDeleted, mergeWithExisting, updateAllModuleDocs, updateModuleDoc, updateReferences };
315
+ //# sourceMappingURL=chunk-TR3HS7U6.js.map
316
+ //# sourceMappingURL=chunk-TR3HS7U6.js.map
@@ -0,0 +1,167 @@
1
+ import { init_storage_paths, getProjectPaths, getProjectDir, ensureProjectDir } from './chunk-TVOTA7EE.js';
2
+ import { init_logging, log } from './chunk-VCCBEJQ5.js';
3
+ import { __require } from './chunk-NAQKA54E.js';
4
+ import { existsSync } from 'fs';
5
+ import { resolve } from 'path';
6
+
7
+ // src/shared/project-context.ts
8
+ init_logging();
9
+ init_storage_paths();
10
+ var ProjectContextManager = class {
11
+ state;
12
+ constructor() {
13
+ const cwd = process.cwd();
14
+ log.i("PROJCTX", `[ProjectContextManager] Initializing with cwd: ${cwd}`);
15
+ this.state = {
16
+ currentProject: cwd,
17
+ previousProject: null
18
+ };
19
+ }
20
+ indexingInProgress = /* @__PURE__ */ new Set();
21
+ onProjectChangeCallbacks = [];
22
+ /**
23
+ * Get current project path
24
+ */
25
+ getCurrentProject() {
26
+ return this.state.currentProject;
27
+ }
28
+ /**
29
+ * Resolve and normalize project path
30
+ * - If absolute path provided, use it
31
+ * - If relative path, resolve from CWD
32
+ * - If undefined/null, use current project
33
+ */
34
+ resolveProjectPath(projectPath) {
35
+ if (!projectPath) {
36
+ return this.state.currentProject;
37
+ }
38
+ const resolved = resolve(projectPath);
39
+ return resolved;
40
+ }
41
+ /**
42
+ * Get project info including indexing status
43
+ */
44
+ getProjectInfo(projectPath) {
45
+ const path = this.resolveProjectPath(projectPath);
46
+ const paths = getProjectPaths(path);
47
+ const projectDir = getProjectDir(path);
48
+ const hash = projectDir.split(/[/\\]/).pop() || "";
49
+ const hasGraphDb = existsSync(paths.graphDbPath);
50
+ const hasVectorsDb = existsSync(paths.vectorsDbPath);
51
+ const isIndexed = hasGraphDb;
52
+ let lastIndexedAt;
53
+ if (existsSync(paths.metaPath)) {
54
+ try {
55
+ const meta = JSON.parse(__require("fs").readFileSync(paths.metaPath, "utf-8"));
56
+ lastIndexedAt = meta.lastIndexedAt;
57
+ } catch {
58
+ }
59
+ }
60
+ return {
61
+ path,
62
+ hash,
63
+ isIndexed,
64
+ hasGraphDb,
65
+ hasVectorsDb,
66
+ lastIndexedAt
67
+ };
68
+ }
69
+ /**
70
+ * Check if project is indexed
71
+ */
72
+ isProjectIndexed(projectPath) {
73
+ const info = this.getProjectInfo(projectPath);
74
+ return info.isIndexed;
75
+ }
76
+ /**
77
+ * Switch to a different project context
78
+ * Returns true if switch was successful
79
+ */
80
+ async switchProject(projectPath) {
81
+ const resolved = this.resolveProjectPath(projectPath);
82
+ if (resolved === this.state.currentProject) {
83
+ return true;
84
+ }
85
+ ensureProjectDir(resolved);
86
+ this.state.previousProject = this.state.currentProject;
87
+ this.state.currentProject = resolved;
88
+ log.i("PROJCTX", `[ProjectContext] Switched project: ${this.state.previousProject} -> ${resolved}`);
89
+ for (const callback of this.onProjectChangeCallbacks) {
90
+ try {
91
+ callback(resolved, this.state.previousProject);
92
+ } catch (error) {
93
+ log.e("PROJCTX", "callback_error", { err: String(error) });
94
+ }
95
+ }
96
+ return true;
97
+ }
98
+ /**
99
+ * Get storage paths for current or specified project
100
+ */
101
+ getStoragePaths(projectPath) {
102
+ const resolved = this.resolveProjectPath(projectPath);
103
+ return getProjectPaths(resolved);
104
+ }
105
+ /**
106
+ * Check if indexing is in progress for a project
107
+ */
108
+ isIndexingInProgress(projectPath) {
109
+ const resolved = this.resolveProjectPath(projectPath);
110
+ return this.indexingInProgress.has(resolved);
111
+ }
112
+ /**
113
+ * Mark indexing as started for a project
114
+ */
115
+ startIndexing(projectPath) {
116
+ const resolved = this.resolveProjectPath(projectPath);
117
+ this.indexingInProgress.add(resolved);
118
+ log.i("PROJCTX", `[ProjectContext] Indexing started for: ${resolved}`);
119
+ }
120
+ /**
121
+ * Mark indexing as completed for a project
122
+ */
123
+ finishIndexing(projectPath) {
124
+ const resolved = this.resolveProjectPath(projectPath);
125
+ this.indexingInProgress.delete(resolved);
126
+ log.i("PROJCTX", `[ProjectContext] Indexing completed for: ${resolved}`);
127
+ }
128
+ /**
129
+ * Register callback for project changes
130
+ */
131
+ onProjectChange(callback) {
132
+ this.onProjectChangeCallbacks.push(callback);
133
+ }
134
+ /**
135
+ * Get status summary for debugging
136
+ */
137
+ getStatus() {
138
+ return {
139
+ currentProject: this.state.currentProject,
140
+ previousProject: this.state.previousProject,
141
+ isIndexed: this.isProjectIndexed(),
142
+ indexingInProgress: Array.from(this.indexingInProgress)
143
+ };
144
+ }
145
+ /**
146
+ * Reset to default state (mainly for testing)
147
+ */
148
+ reset() {
149
+ this.state = {
150
+ currentProject: process.cwd(),
151
+ previousProject: null
152
+ };
153
+ this.indexingInProgress.clear();
154
+ this.onProjectChangeCallbacks = [];
155
+ }
156
+ };
157
+ var instance = null;
158
+ function getProjectContext() {
159
+ if (!instance) {
160
+ instance = new ProjectContextManager();
161
+ }
162
+ return instance;
163
+ }
164
+
165
+ export { getProjectContext };
166
+ //# sourceMappingURL=chunk-TUWE6FCW.js.map
167
+ //# sourceMappingURL=chunk-TUWE6FCW.js.map