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,277 @@
1
+ import { hashText, init_fast_hash } from './chunk-HEMJHRHZ.js';
2
+ import { __export, __esm } from './chunk-NAQKA54E.js';
3
+ import { execSync } from 'child_process';
4
+ import { existsSync, mkdirSync } from 'fs';
5
+ import { homedir } from 'os';
6
+ import { join } from 'path';
7
+
8
+ // src/shared/storage-paths.ts
9
+ var storage_paths_exports = {};
10
+ __export(storage_paths_exports, {
11
+ DEFAULT_BRANCH: () => DEFAULT_BRANCH,
12
+ ensureDataDir: () => ensureDataDir,
13
+ ensureGlobalDbDir: () => ensureGlobalDbDir,
14
+ ensureProjectDir: () => ensureProjectDir,
15
+ getASTCacheDir: () => getASTCacheDir,
16
+ getBranchPaths: () => getBranchPaths,
17
+ getCacheDir: () => getCacheDir,
18
+ getConfigDir: () => getConfigDir,
19
+ getConfigPath: () => getConfigPath,
20
+ getCoreLockPath: () => getCoreLockPath,
21
+ getCorePidPath: () => getCorePidPath,
22
+ getCurrentGitBranch: () => getCurrentGitBranch,
23
+ getCurrentGitBranchOrDefault: () => getCurrentGitBranchOrDefault,
24
+ getDataDir: () => getDataDir,
25
+ getFaissHotBufferPath: () => getFaissHotBufferPath,
26
+ getFaissIdMapPath: () => getFaissIdMapPath,
27
+ getFaissIndexPath: () => getFaissIndexPath,
28
+ getFaissIndexPathByHash: () => getFaissIndexPathByHash,
29
+ getGlobalDbPaths: () => getGlobalDbPaths,
30
+ getIPCSocketPath: () => getIPCSocketPath,
31
+ getLogsDir: () => getLogsDir,
32
+ getModelsDir: () => getModelsDir,
33
+ getMultiDbPaths: () => getMultiDbPaths,
34
+ getProjectDir: () => getProjectDir,
35
+ getProjectHash: () => getProjectHash,
36
+ getProjectPaths: () => getProjectPaths,
37
+ getProjectsDir: () => getProjectsDir,
38
+ getSemanticConfigPath: () => getSemanticConfigPath,
39
+ getTreeSitterCacheDir: () => getTreeSitterCacheDir,
40
+ hashProjectPath: () => hashProjectPath,
41
+ initializeStorageDirs: () => initializeStorageDirs,
42
+ isBaseBranch: () => isBaseBranch,
43
+ normalizeBranchName: () => normalizeBranchName
44
+ });
45
+ function getDataDir() {
46
+ let baseDir;
47
+ switch (process.platform) {
48
+ case "win32":
49
+ baseDir = process.env["LOCALAPPDATA"] || join(homedir(), "AppData", "Local");
50
+ break;
51
+ case "darwin":
52
+ baseDir = join(homedir(), "Library", "Application Support");
53
+ break;
54
+ default:
55
+ baseDir = process.env["XDG_DATA_HOME"] || join(homedir(), ".local", "share");
56
+ }
57
+ return join(baseDir, "UltraCode");
58
+ }
59
+ function ensureDataDir() {
60
+ const dir = getDataDir();
61
+ if (!existsSync(dir)) {
62
+ mkdirSync(dir, { recursive: true });
63
+ }
64
+ return dir;
65
+ }
66
+ function getIPCSocketPath() {
67
+ if (process.platform === "win32") {
68
+ return "\\\\.\\pipe\\ultracode-core";
69
+ }
70
+ return "/tmp/ultracode-core.sock";
71
+ }
72
+ function getLogsDir() {
73
+ return join(getDataDir(), "logs");
74
+ }
75
+ function getCacheDir() {
76
+ return join(getDataDir(), "cache");
77
+ }
78
+ function getProjectsDir() {
79
+ return join(getDataDir(), "projects");
80
+ }
81
+ function getModelsDir() {
82
+ return join(getDataDir(), "models");
83
+ }
84
+ function getConfigDir() {
85
+ return join(getDataDir(), "config");
86
+ }
87
+ function getConfigPath() {
88
+ return join(getDataDir(), "config.yaml");
89
+ }
90
+ function getSemanticConfigPath() {
91
+ return join(getConfigDir(), "semantic-config.json");
92
+ }
93
+ function getCorePidPath() {
94
+ return join(getDataDir(), "core.pid");
95
+ }
96
+ function getCoreLockPath() {
97
+ return join(getDataDir(), "core.lock");
98
+ }
99
+ function hashProjectPath(projectPath) {
100
+ if (!projectPath) {
101
+ throw new Error(
102
+ `hashProjectPath: projectPath must not be empty (got ${JSON.stringify(projectPath)}). Ensure projectPath is provided in tool args or resolved from session/context.`
103
+ );
104
+ }
105
+ const normalized = projectPath.toLowerCase().replace(/\\/g, "/").replace(/\/$/, "");
106
+ return hashText(normalized);
107
+ }
108
+ function getProjectDir(projectPath) {
109
+ const hash = hashProjectPath(projectPath);
110
+ return join(getProjectsDir(), hash);
111
+ }
112
+ function getProjectPaths(projectPath) {
113
+ const projectDir = getProjectDir(projectPath);
114
+ return {
115
+ dir: projectDir,
116
+ metaPath: join(projectDir, "meta.json"),
117
+ graphDbPath: join(projectDir, "graph.db"),
118
+ vectorsDbPath: join(projectDir, "vectors.db"),
119
+ branchesDir: join(projectDir, "branches"),
120
+ // Cache persistence paths
121
+ parserCachePath: join(projectDir, "parser-cache.json"),
122
+ semanticCachePath: join(projectDir, "semantic-cache.json")
123
+ };
124
+ }
125
+ function getGlobalDbPaths() {
126
+ const dataDir = getDataDir();
127
+ return {
128
+ dir: dataDir,
129
+ /** @deprecated Use multi-db paths instead */
130
+ graphDbPath: join(dataDir, "graph.db"),
131
+ /** @deprecated FAISS is used for vectors, not SQLite */
132
+ vectorsDbPath: join(dataDir, "graph.db"),
133
+ /** @deprecated Use getMultiDbPaths() instead */
134
+ unifiedDbPath: join(dataDir, "graph.db"),
135
+ metaPath: join(dataDir, "global-meta.json"),
136
+ cacheDir: getCacheDir(),
137
+ projectsDir: getProjectsDir()
138
+ };
139
+ }
140
+ function getMultiDbPaths(basePath) {
141
+ const dir = basePath ?? getDataDir();
142
+ return {
143
+ graph: join(dir, "graph.db"),
144
+ semantic: join(dir, "semantic.db"),
145
+ versioning: join(dir, "versioning.db"),
146
+ cache: join(dir, "cache.db")
147
+ };
148
+ }
149
+ function getProjectHash(projectPath) {
150
+ return hashProjectPath(projectPath);
151
+ }
152
+ function normalizeBranchName(branchName) {
153
+ return branchName.toLowerCase().replace(/[<>:"/\\|?*]/g, "_");
154
+ }
155
+ function isBaseBranch(branchName) {
156
+ if (!branchName) return false;
157
+ const normalized = branchName.toLowerCase();
158
+ return BASE_BRANCH_CANDIDATES.includes(normalized);
159
+ }
160
+ function getCurrentGitBranch(projectPath) {
161
+ if (!projectPath) {
162
+ return null;
163
+ }
164
+ try {
165
+ const gitDir = join(projectPath, ".git");
166
+ if (!existsSync(gitDir)) {
167
+ return null;
168
+ }
169
+ const branch = execSync("git symbolic-ref --short HEAD", {
170
+ cwd: projectPath,
171
+ encoding: "utf-8",
172
+ stdio: ["pipe", "pipe", "ignore"],
173
+ windowsHide: true
174
+ }).trim();
175
+ return branch || null;
176
+ } catch {
177
+ try {
178
+ const ref = execSync("git rev-parse --abbrev-ref HEAD", {
179
+ cwd: projectPath,
180
+ encoding: "utf-8",
181
+ stdio: ["pipe", "pipe", "ignore"],
182
+ windowsHide: true
183
+ }).trim();
184
+ if (ref === "HEAD") {
185
+ const hash = execSync("git rev-parse --short HEAD", {
186
+ cwd: projectPath,
187
+ encoding: "utf-8",
188
+ stdio: ["pipe", "pipe", "ignore"],
189
+ windowsHide: true
190
+ }).trim();
191
+ return hash ? `detached-${hash}` : null;
192
+ }
193
+ return ref || null;
194
+ } catch {
195
+ return null;
196
+ }
197
+ }
198
+ }
199
+ function getCurrentGitBranchOrDefault(projectPath) {
200
+ return getCurrentGitBranch(projectPath) || DEFAULT_BRANCH;
201
+ }
202
+ function ensureProjectDir(projectPath) {
203
+ const paths = getProjectPaths(projectPath);
204
+ if (!existsSync(paths.dir)) {
205
+ mkdirSync(paths.dir, { recursive: true });
206
+ }
207
+ return paths.dir;
208
+ }
209
+ function ensureGlobalDbDir() {
210
+ const paths = getGlobalDbPaths();
211
+ if (!existsSync(paths.dir)) {
212
+ mkdirSync(paths.dir, { recursive: true });
213
+ }
214
+ return paths.dir;
215
+ }
216
+ function getBranchPaths(projectPath, branchName) {
217
+ const { branchesDir } = getProjectPaths(projectPath);
218
+ const safeBranchName = branchName.replace(/[<>:"/\\|?*]/g, "_");
219
+ const branchDir = join(branchesDir, safeBranchName);
220
+ return {
221
+ dir: branchDir,
222
+ graphDbPath: join(branchDir, "graph.db"),
223
+ vectorsDbPath: join(branchDir, "vectors.db")
224
+ };
225
+ }
226
+ function getFaissIndexPath(projectPath, branchName) {
227
+ const projectDir = getProjectDir(projectPath);
228
+ const safeBranch = normalizeBranchName(branchName);
229
+ if (!existsSync(projectDir)) {
230
+ mkdirSync(projectDir, { recursive: true });
231
+ }
232
+ return join(projectDir, `faiss-${safeBranch}.bin`);
233
+ }
234
+ function getFaissIndexPathByHash(projectHash, branchName) {
235
+ const projectDir = join(getProjectsDir(), projectHash);
236
+ const safeBranch = normalizeBranchName(branchName);
237
+ if (!existsSync(projectDir)) {
238
+ mkdirSync(projectDir, { recursive: true });
239
+ }
240
+ return join(projectDir, `faiss-${safeBranch}.bin`);
241
+ }
242
+ function getFaissIdMapPath(projectPath, branchName) {
243
+ const projectDir = getProjectDir(projectPath);
244
+ const safeBranch = normalizeBranchName(branchName);
245
+ return join(projectDir, `faiss-${safeBranch}.idmap.json`);
246
+ }
247
+ function getFaissHotBufferPath(projectPath, branchName) {
248
+ const projectDir = getProjectDir(projectPath);
249
+ const safeBranch = normalizeBranchName(branchName);
250
+ return join(projectDir, `faiss-${safeBranch}-hot.bin`);
251
+ }
252
+ function getTreeSitterCacheDir() {
253
+ return join(getCacheDir(), "tree-sitter");
254
+ }
255
+ function getASTCacheDir() {
256
+ return join(getCacheDir(), "ast");
257
+ }
258
+ function initializeStorageDirs() {
259
+ const dirs = [getDataDir(), getLogsDir(), getProjectsDir(), getModelsDir(), getConfigDir()];
260
+ for (const dir of dirs) {
261
+ if (!existsSync(dir)) {
262
+ mkdirSync(dir, { recursive: true });
263
+ }
264
+ }
265
+ }
266
+ var DEFAULT_BRANCH, BASE_BRANCH_CANDIDATES;
267
+ var init_storage_paths = __esm({
268
+ "src/shared/storage-paths.ts"() {
269
+ init_fast_hash();
270
+ DEFAULT_BRANCH = "main";
271
+ BASE_BRANCH_CANDIDATES = ["main", "master", "dev", "develop", "trunk"];
272
+ }
273
+ });
274
+
275
+ export { DEFAULT_BRANCH, ensureDataDir, ensureGlobalDbDir, ensureProjectDir, getASTCacheDir, getBranchPaths, getCacheDir, getConfigDir, getConfigPath, getCoreLockPath, getCorePidPath, getCurrentGitBranch, getCurrentGitBranchOrDefault, getDataDir, getFaissHotBufferPath, getFaissIdMapPath, getFaissIndexPath, getFaissIndexPathByHash, getGlobalDbPaths, getIPCSocketPath, getLogsDir, getModelsDir, getMultiDbPaths, getProjectDir, getProjectHash, getProjectPaths, getProjectsDir, getSemanticConfigPath, getTreeSitterCacheDir, hashProjectPath, init_storage_paths, initializeStorageDirs, isBaseBranch, normalizeBranchName, storage_paths_exports };
276
+ //# sourceMappingURL=chunk-TVOTA7EE.js.map
277
+ //# sourceMappingURL=chunk-TVOTA7EE.js.map
@@ -0,0 +1,337 @@
1
+ import { getProjectContext } from './chunk-TUWE6FCW.js';
2
+ import { init_logging, log } from './chunk-VCCBEJQ5.js';
3
+
4
+ // src/tools/response-limits.ts
5
+ var MAX_RESPONSE_SIZE_BYTES = 5e4;
6
+ var DEFAULT_PAGE_SIZE = 50;
7
+ var MAX_PAGE_SIZE = 200;
8
+ var SAFE_LIMITS = {
9
+ entities: 100,
10
+ relationships: 100,
11
+ clones: 30,
12
+ searchResults: 20,
13
+ hotspots: 20,
14
+ graphNodes: 200,
15
+ taintVulnerabilities: 20
16
+ };
17
+ function paginate(items, offset = 0, limit = DEFAULT_PAGE_SIZE) {
18
+ const safeLimit = Math.min(limit, MAX_PAGE_SIZE);
19
+ const safeOffset = Math.max(0, offset);
20
+ const total = items.length;
21
+ const data = items.slice(safeOffset, safeOffset + safeLimit);
22
+ const hasMore = safeOffset + safeLimit < total;
23
+ return {
24
+ data,
25
+ pagination: {
26
+ offset: safeOffset,
27
+ limit: safeLimit,
28
+ total,
29
+ hasMore,
30
+ ...hasMore && { nextOffset: safeOffset + safeLimit }
31
+ }
32
+ };
33
+ }
34
+ function truncateResponse(data, maxSize = MAX_RESPONSE_SIZE_BYTES) {
35
+ const jsonText = JSON.stringify(data, null, 2);
36
+ const originalSize = Buffer.byteLength(jsonText, "utf8");
37
+ if (originalSize <= maxSize) {
38
+ return {
39
+ text: jsonText,
40
+ wasTruncated: false,
41
+ originalSize,
42
+ truncatedSize: originalSize
43
+ };
44
+ }
45
+ const truncatedData = truncateData(data, maxSize);
46
+ const truncatedJson = JSON.stringify(truncatedData, null, 2);
47
+ return {
48
+ text: truncatedJson,
49
+ wasTruncated: true,
50
+ originalSize,
51
+ truncatedSize: Buffer.byteLength(truncatedJson, "utf8")
52
+ };
53
+ }
54
+ function truncateData(data, maxSize, depth = 0) {
55
+ if (depth > 5) return "[nested data omitted]";
56
+ if (data === null || data === void 0) return data;
57
+ if (typeof data !== "object") return data;
58
+ if (Array.isArray(data)) {
59
+ return truncateArray(data, maxSize);
60
+ }
61
+ return truncateObject(data, maxSize, depth);
62
+ }
63
+ function truncateArray(arr, maxSize) {
64
+ let items = arr;
65
+ let estimatedSize = JSON.stringify(items).length;
66
+ while (estimatedSize > maxSize * 0.8 && items.length > 1) {
67
+ const newLength = Math.max(1, Math.floor(items.length / 2));
68
+ items = arr.slice(0, newLength);
69
+ estimatedSize = JSON.stringify(items).length;
70
+ }
71
+ const truncated = items.length < arr.length;
72
+ if (truncated) {
73
+ return {
74
+ _truncated: true,
75
+ _message: `Response truncated. Showing ${items.length} of ${arr.length} items. Use 'offset' parameter to paginate.`,
76
+ _total: arr.length,
77
+ _showing: items.length,
78
+ items
79
+ };
80
+ }
81
+ return items;
82
+ }
83
+ function truncateObject(obj, maxSize, depth = 0) {
84
+ const result = {};
85
+ const priorityFields = ["id", "name", "type", "count", "total", "pagination", "error", "success"];
86
+ const arrayFields = [];
87
+ for (const key of Object.keys(obj)) {
88
+ if (priorityFields.includes(key)) {
89
+ result[key] = obj[key];
90
+ } else if (Array.isArray(obj[key])) {
91
+ arrayFields.push(key);
92
+ }
93
+ }
94
+ for (const key of Object.keys(obj)) {
95
+ if (!priorityFields.includes(key) && !Array.isArray(obj[key])) {
96
+ const value = obj[key];
97
+ if (typeof value === "string" && value.length > maxSize * 0.2) {
98
+ result[key] = value.slice(0, Math.floor(maxSize * 0.2)) + "... [truncated]";
99
+ } else if (typeof value === "object" && value !== null) {
100
+ const remainingSize = maxSize - JSON.stringify(result).length;
101
+ if (remainingSize > 100) {
102
+ result[key] = truncateData(value, remainingSize * 0.8, depth + 1);
103
+ } else {
104
+ result[key] = "[object omitted \u2014 response too large]";
105
+ }
106
+ } else {
107
+ result[key] = value;
108
+ }
109
+ }
110
+ }
111
+ for (const key of arrayFields) {
112
+ const arr = obj[key];
113
+ const remainingSize = maxSize - JSON.stringify(result).length;
114
+ result[key] = truncateArray(arr, remainingSize * 0.8);
115
+ }
116
+ return result;
117
+ }
118
+
119
+ // src/tools/base-tool-handler.ts
120
+ init_logging();
121
+ var BaseToolHandler = class {
122
+ constructor(context) {
123
+ this.context = context;
124
+ }
125
+ /** Maximum response size in bytes. Override in subclass if needed. */
126
+ maxResponseSize = MAX_RESPONSE_SIZE_BYTES;
127
+ // ==========================================================================
128
+ // PROJECT CONTEXT HELPERS (v5: session-aware)
129
+ // ==========================================================================
130
+ /**
131
+ * Get the ProjectContextManager singleton.
132
+ * @deprecated Use context.session or context.projectPath instead for isolation.
133
+ */
134
+ getProjectContext() {
135
+ return getProjectContext();
136
+ }
137
+ /**
138
+ * v5: Resolve project path using session-aware logic.
139
+ *
140
+ * Priority:
141
+ * 1. Explicit path from args (if provided)
142
+ * 2. context.projectPath (set from session or startup)
143
+ * 3. Fallback to global singleton (legacy mode)
144
+ */
145
+ resolveProjectPath(args) {
146
+ if (args.projectPath) {
147
+ return this.context.session?.resolvePath(args.projectPath) ?? args.projectPath;
148
+ }
149
+ if (args.directory) {
150
+ return this.context.session?.resolvePath(args.directory) ?? args.directory;
151
+ }
152
+ if (this.context.session) {
153
+ return this.context.session.projectPath;
154
+ }
155
+ if (this.context.projectPath) {
156
+ return this.context.projectPath;
157
+ }
158
+ const current = getProjectContext().getCurrentProject();
159
+ if (current) {
160
+ return current;
161
+ }
162
+ return process.cwd();
163
+ }
164
+ /**
165
+ * Get storage paths for a project
166
+ */
167
+ getProjectStoragePaths(projectPath) {
168
+ const resolved = this.resolveProjectPath({ projectPath });
169
+ return getProjectContext().getStoragePaths(resolved);
170
+ }
171
+ /**
172
+ * Check if project is indexed
173
+ */
174
+ isProjectIndexed(projectPath) {
175
+ const resolved = this.resolveProjectPath({ projectPath });
176
+ return getProjectContext().isProjectIndexed(resolved);
177
+ }
178
+ /**
179
+ * v5: Get GraphStorage with project context automatically set.
180
+ * Uses session-aware project resolution.
181
+ */
182
+ async ensureGraphStorageForProject(projectPath) {
183
+ const resolved = this.resolveProjectPath({ projectPath });
184
+ log.d("BASETOOL", "ensure_storage", { resolved, hasSession: !!this.context.session });
185
+ const storage = await this.context.getGraphStorage();
186
+ storage.setProject(resolved);
187
+ log.d("BASETOOL", "storage_set", { resolved });
188
+ return storage;
189
+ }
190
+ /**
191
+ * v5: Ensure SemanticAgent is initialized for the correct project.
192
+ * Uses session-aware project resolution.
193
+ */
194
+ async ensureSemanticAgentForProject(projectPath) {
195
+ const resolved = this.resolveProjectPath({ projectPath });
196
+ const semanticAgent = await this.context.getSemanticAgent();
197
+ const vectorStore = semanticAgent?.getVectorStore?.();
198
+ const currentContext = vectorStore?.getProjectContext?.();
199
+ log.d("BASETOOL", "semantic_ctx", {
200
+ resolved,
201
+ hasSession: !!this.context.session,
202
+ ctx: JSON.stringify(currentContext)
203
+ });
204
+ if (semanticAgent && typeof semanticAgent.reinitializeForProject === "function") {
205
+ log.d("BASETOOL", "reinit_proj", { resolved });
206
+ await semanticAgent.reinitializeForProject(resolved);
207
+ const newContext = semanticAgent.getVectorStore?.()?.getProjectContext?.();
208
+ log.d("BASETOOL", "ctx_switched", { ctx: JSON.stringify(newContext) });
209
+ }
210
+ return semanticAgent;
211
+ }
212
+ /**
213
+ * Apply response size limits and truncation if needed
214
+ */
215
+ applyResponseLimits(result) {
216
+ if (!result.content || result.content.length === 0) {
217
+ return result;
218
+ }
219
+ const newContent = result.content.map((item) => {
220
+ if (item.type !== "text") return item;
221
+ const size = Buffer.byteLength(item.text, "utf8");
222
+ if (size <= this.maxResponseSize) {
223
+ return item;
224
+ }
225
+ let newItem;
226
+ try {
227
+ const data = JSON.parse(item.text);
228
+ const truncated = truncateResponse(data, this.maxResponseSize);
229
+ if (truncated.wasTruncated) {
230
+ const parsed = JSON.parse(truncated.text);
231
+ parsed._responseMeta = {
232
+ truncated: true,
233
+ originalSizeBytes: truncated.originalSize,
234
+ truncatedSizeBytes: truncated.truncatedSize,
235
+ hint: "Response was truncated. Use 'offset' and 'limit' parameters for pagination."
236
+ };
237
+ newItem = {
238
+ type: "text",
239
+ text: JSON.stringify(parsed, null, 2)
240
+ };
241
+ } else {
242
+ newItem = { type: "text", text: truncated.text };
243
+ }
244
+ } catch {
245
+ const truncatedText = item.text.slice(0, this.maxResponseSize);
246
+ newItem = {
247
+ type: "text",
248
+ text: truncatedText + "\n\n[RESPONSE TRUNCATED - original size: " + size + " bytes]"
249
+ };
250
+ }
251
+ const finalSize = Buffer.byteLength(newItem.text, "utf8");
252
+ if (finalSize > this.maxResponseSize) {
253
+ const sliced = newItem.text.slice(0, this.maxResponseSize - 200);
254
+ return {
255
+ type: "text",
256
+ text: sliced + "\n\n[RESPONSE TRUNCATED \u2014 hard cap at " + this.maxResponseSize + " bytes. Original: " + finalSize + " bytes. Use 'offset'/'limit' for pagination.]"
257
+ };
258
+ }
259
+ return newItem;
260
+ });
261
+ return { content: newContent };
262
+ }
263
+ /**
264
+ * Summarize tool args for logging (truncate large values)
265
+ */
266
+ summarizeArgs(args) {
267
+ if (!args || typeof args !== "object") return {};
268
+ const summary = {};
269
+ for (const [key, value] of Object.entries(args)) {
270
+ if (value === void 0 || value === null) continue;
271
+ if (typeof value === "string") {
272
+ summary[key] = value.length > 80 ? value.slice(0, 80) + "..." : value;
273
+ } else if (Array.isArray(value)) {
274
+ summary[key] = `[${value.length}]`;
275
+ } else {
276
+ summary[key] = value;
277
+ }
278
+ }
279
+ return summary;
280
+ }
281
+ /**
282
+ * Calculate response size in bytes
283
+ */
284
+ responseSize(result) {
285
+ let size = 0;
286
+ for (const item of result.content) {
287
+ size += item.text.length;
288
+ }
289
+ return size;
290
+ }
291
+ /**
292
+ * Main entry point for tool execution
293
+ */
294
+ async handle(args) {
295
+ const startTime = Date.now();
296
+ const toolName = this.constructor.name.replace("ToolHandler", "").toLowerCase();
297
+ try {
298
+ const parsedArgs = this.parseArgs(args);
299
+ const result = await this.execute(parsedArgs);
300
+ const limitedResult = this.applyResponseLimits(result);
301
+ const duration = Date.now() - startTime;
302
+ const respSize = this.responseSize(limitedResult);
303
+ log.i("BASETOOL", "mcp_response", {
304
+ tool: toolName,
305
+ durationMs: duration,
306
+ respBytes: respSize,
307
+ args: this.summarizeArgs(args),
308
+ reqId: this.context.requestId
309
+ });
310
+ return limitedResult;
311
+ } catch (error) {
312
+ const duration = Date.now() - startTime;
313
+ log.e("BASETOOL", "exec_failed", {
314
+ tool: toolName,
315
+ durationMs: duration,
316
+ err: error.message,
317
+ args: this.summarizeArgs(args),
318
+ reqId: this.context.requestId
319
+ });
320
+ return {
321
+ content: [
322
+ {
323
+ type: "text",
324
+ text: JSON.stringify({
325
+ success: false,
326
+ error: error.message
327
+ })
328
+ }
329
+ ]
330
+ };
331
+ }
332
+ }
333
+ };
334
+
335
+ export { BaseToolHandler, DEFAULT_PAGE_SIZE, MAX_PAGE_SIZE, MAX_RESPONSE_SIZE_BYTES, SAFE_LIMITS, paginate, truncateResponse };
336
+ //# sourceMappingURL=chunk-VS44D772.js.map
337
+ //# sourceMappingURL=chunk-VS44D772.js.map