@triedotdev/mcp 1.0.168 → 1.0.170

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 (149) hide show
  1. package/README.md +54 -500
  2. package/dist/chunk-2YXOBNKW.js +619 -0
  3. package/dist/chunk-2YXOBNKW.js.map +1 -0
  4. package/dist/chunk-QR64Y5TI.js +363 -0
  5. package/dist/chunk-QR64Y5TI.js.map +1 -0
  6. package/dist/cli/main.d.ts +0 -15
  7. package/dist/cli/main.js +356 -3100
  8. package/dist/cli/main.js.map +1 -1
  9. package/dist/index.js +2 -36
  10. package/dist/index.js.map +1 -1
  11. package/dist/server/mcp-server.js +2 -36
  12. package/package.json +8 -31
  13. package/dist/autonomy-config-FSERX3O3.js +0 -30
  14. package/dist/autonomy-config-FSERX3O3.js.map +0 -1
  15. package/dist/chat-store-JNGNTDSN.js +0 -15
  16. package/dist/chat-store-JNGNTDSN.js.map +0 -1
  17. package/dist/chunk-2HF65EHQ.js +0 -311
  18. package/dist/chunk-2HF65EHQ.js.map +0 -1
  19. package/dist/chunk-43X6JBEM.js +0 -36
  20. package/dist/chunk-43X6JBEM.js.map +0 -1
  21. package/dist/chunk-4MXH2ZPT.js +0 -1827
  22. package/dist/chunk-4MXH2ZPT.js.map +0 -1
  23. package/dist/chunk-575YT2SD.js +0 -737
  24. package/dist/chunk-575YT2SD.js.map +0 -1
  25. package/dist/chunk-5BRRRTN6.js +0 -354
  26. package/dist/chunk-5BRRRTN6.js.map +0 -1
  27. package/dist/chunk-6NLHFIYA.js +0 -344
  28. package/dist/chunk-6NLHFIYA.js.map +0 -1
  29. package/dist/chunk-7WITSO22.js +0 -824
  30. package/dist/chunk-7WITSO22.js.map +0 -1
  31. package/dist/chunk-DGUM43GV.js +0 -11
  32. package/dist/chunk-DGUM43GV.js.map +0 -1
  33. package/dist/chunk-EFWVF6TI.js +0 -267
  34. package/dist/chunk-EFWVF6TI.js.map +0 -1
  35. package/dist/chunk-F6WFNUAY.js +0 -216
  36. package/dist/chunk-F6WFNUAY.js.map +0 -1
  37. package/dist/chunk-FQ45QP5A.js +0 -361
  38. package/dist/chunk-FQ45QP5A.js.map +0 -1
  39. package/dist/chunk-G2TGF6TR.js +0 -573
  40. package/dist/chunk-G2TGF6TR.js.map +0 -1
  41. package/dist/chunk-GTKYBOXL.js +0 -700
  42. package/dist/chunk-GTKYBOXL.js.map +0 -1
  43. package/dist/chunk-HVCDY3AK.js +0 -850
  44. package/dist/chunk-HVCDY3AK.js.map +0 -1
  45. package/dist/chunk-JVMBCWKS.js +0 -348
  46. package/dist/chunk-JVMBCWKS.js.map +0 -1
  47. package/dist/chunk-KDHN2ZQE.js +0 -313
  48. package/dist/chunk-KDHN2ZQE.js.map +0 -1
  49. package/dist/chunk-LQIMKE3P.js +0 -12524
  50. package/dist/chunk-LQIMKE3P.js.map +0 -1
  51. package/dist/chunk-ME2OERF5.js +0 -345
  52. package/dist/chunk-ME2OERF5.js.map +0 -1
  53. package/dist/chunk-MRHKX5M5.js +0 -662
  54. package/dist/chunk-MRHKX5M5.js.map +0 -1
  55. package/dist/chunk-OBQ74FOU.js +0 -27
  56. package/dist/chunk-OBQ74FOU.js.map +0 -1
  57. package/dist/chunk-OMR4YCBS.js +0 -987
  58. package/dist/chunk-OMR4YCBS.js.map +0 -1
  59. package/dist/chunk-Q5EKA5YA.js +0 -254
  60. package/dist/chunk-Q5EKA5YA.js.map +0 -1
  61. package/dist/chunk-Q63FFI6D.js +0 -132
  62. package/dist/chunk-Q63FFI6D.js.map +0 -1
  63. package/dist/chunk-SY6KQG44.js +0 -983
  64. package/dist/chunk-SY6KQG44.js.map +0 -1
  65. package/dist/chunk-T63OHG4Q.js +0 -440
  66. package/dist/chunk-T63OHG4Q.js.map +0 -1
  67. package/dist/chunk-TN5WEKWI.js +0 -173
  68. package/dist/chunk-TN5WEKWI.js.map +0 -1
  69. package/dist/chunk-VUL52BQL.js +0 -402
  70. package/dist/chunk-VUL52BQL.js.map +0 -1
  71. package/dist/chunk-VVITXIHN.js +0 -189
  72. package/dist/chunk-VVITXIHN.js.map +0 -1
  73. package/dist/chunk-WCN7S3EI.js +0 -14
  74. package/dist/chunk-WCN7S3EI.js.map +0 -1
  75. package/dist/chunk-XE6KQRKZ.js +0 -816
  76. package/dist/chunk-XE6KQRKZ.js.map +0 -1
  77. package/dist/chunk-XPZZFPBZ.js +0 -491
  78. package/dist/chunk-XPZZFPBZ.js.map +0 -1
  79. package/dist/chunk-XTFWT2XM.js +0 -727
  80. package/dist/chunk-XTFWT2XM.js.map +0 -1
  81. package/dist/chunk-YDHUCDHM.js +0 -4011
  82. package/dist/chunk-YDHUCDHM.js.map +0 -1
  83. package/dist/chunk-YZ6Y2H3P.js +0 -1289
  84. package/dist/chunk-YZ6Y2H3P.js.map +0 -1
  85. package/dist/chunk-ZJF5FTBX.js +0 -1396
  86. package/dist/chunk-ZJF5FTBX.js.map +0 -1
  87. package/dist/chunk-ZV2K6M7T.js +0 -74
  88. package/dist/chunk-ZV2K6M7T.js.map +0 -1
  89. package/dist/cli/create-agent.d.ts +0 -1
  90. package/dist/cli/create-agent.js +0 -1050
  91. package/dist/cli/create-agent.js.map +0 -1
  92. package/dist/cli/yolo-daemon.d.ts +0 -1
  93. package/dist/cli/yolo-daemon.js +0 -423
  94. package/dist/cli/yolo-daemon.js.map +0 -1
  95. package/dist/client-NJPZE5JT.js +0 -28
  96. package/dist/client-NJPZE5JT.js.map +0 -1
  97. package/dist/codebase-index-VAPF32XX.js +0 -12
  98. package/dist/codebase-index-VAPF32XX.js.map +0 -1
  99. package/dist/fast-analyzer-XXYMOXRK.js +0 -216
  100. package/dist/fast-analyzer-XXYMOXRK.js.map +0 -1
  101. package/dist/git-EO5SRFMN.js +0 -28
  102. package/dist/git-EO5SRFMN.js.map +0 -1
  103. package/dist/github-ingester-ZOKK6GRS.js +0 -11
  104. package/dist/github-ingester-ZOKK6GRS.js.map +0 -1
  105. package/dist/goal-manager-YOB7VWK7.js +0 -25
  106. package/dist/goal-manager-YOB7VWK7.js.map +0 -1
  107. package/dist/goal-validator-ULKIBDPX.js +0 -24
  108. package/dist/goal-validator-ULKIBDPX.js.map +0 -1
  109. package/dist/graph-B3NA4S7I.js +0 -10
  110. package/dist/graph-B3NA4S7I.js.map +0 -1
  111. package/dist/hypothesis-7BFFT5JY.js +0 -23
  112. package/dist/hypothesis-7BFFT5JY.js.map +0 -1
  113. package/dist/incident-index-EFNUSGWL.js +0 -11
  114. package/dist/incident-index-EFNUSGWL.js.map +0 -1
  115. package/dist/insight-store-EC4PLSAW.js +0 -22
  116. package/dist/insight-store-EC4PLSAW.js.map +0 -1
  117. package/dist/issue-store-ZIRP23EP.js +0 -36
  118. package/dist/issue-store-ZIRP23EP.js.map +0 -1
  119. package/dist/ledger-TWZTGDFA.js +0 -58
  120. package/dist/ledger-TWZTGDFA.js.map +0 -1
  121. package/dist/linear-ingester-XXPAZZRW.js +0 -11
  122. package/dist/linear-ingester-XXPAZZRW.js.map +0 -1
  123. package/dist/output-manager-RVJ37XKA.js +0 -13
  124. package/dist/output-manager-RVJ37XKA.js.map +0 -1
  125. package/dist/parse-goal-violation-SACGFG3C.js +0 -8
  126. package/dist/parse-goal-violation-SACGFG3C.js.map +0 -1
  127. package/dist/pattern-discovery-F7LU5K6E.js +0 -8
  128. package/dist/pattern-discovery-F7LU5K6E.js.map +0 -1
  129. package/dist/progress-SRQ2V3BP.js +0 -18
  130. package/dist/progress-SRQ2V3BP.js.map +0 -1
  131. package/dist/project-state-AHPA77SM.js +0 -28
  132. package/dist/project-state-AHPA77SM.js.map +0 -1
  133. package/dist/sync-M2FSWPBC.js +0 -12
  134. package/dist/sync-M2FSWPBC.js.map +0 -1
  135. package/dist/terminal-spawn-5YXDMUCF.js +0 -157
  136. package/dist/terminal-spawn-5YXDMUCF.js.map +0 -1
  137. package/dist/tiered-storage-Z3YCR465.js +0 -12
  138. package/dist/tiered-storage-Z3YCR465.js.map +0 -1
  139. package/dist/trie-agent-3YDPEGHJ.js +0 -28
  140. package/dist/trie-agent-3YDPEGHJ.js.map +0 -1
  141. package/dist/ui/chat.html +0 -1014
  142. package/dist/ui/goals.html +0 -967
  143. package/dist/ui/hypotheses.html +0 -1011
  144. package/dist/ui/ledger.html +0 -954
  145. package/dist/ui/nudges.html +0 -995
  146. package/dist/vibe-code-signatures-F6URTBW3.js +0 -16
  147. package/dist/vibe-code-signatures-F6URTBW3.js.map +0 -1
  148. package/dist/vulnerability-signatures-T7SKHORW.js +0 -18
  149. package/dist/vulnerability-signatures-T7SKHORW.js.map +0 -1
@@ -1,816 +0,0 @@
1
- import {
2
- appendIssuesToLedger,
3
- withFileLock
4
- } from "./chunk-ZJF5FTBX.js";
5
- import {
6
- BackupManager,
7
- CompactedSummariesIndexSchema,
8
- IssueIndexSchema,
9
- safeParseAndValidate
10
- } from "./chunk-EFWVF6TI.js";
11
- import {
12
- atomicWriteJSON
13
- } from "./chunk-43X6JBEM.js";
14
- import {
15
- getTrieDirectory,
16
- getWorkingDirectory
17
- } from "./chunk-VVITXIHN.js";
18
-
19
- // src/memory/issue-store.ts
20
- import { mkdir as mkdir2, readFile as readFile2, readdir } from "fs/promises";
21
- import { createHash } from "crypto";
22
- import { existsSync as existsSync2 } from "fs";
23
- import { join as join2 } from "path";
24
-
25
- // src/memory/bm25.ts
26
- var BM25Index = class _BM25Index {
27
- documents = /* @__PURE__ */ new Map();
28
- termFrequencies = /* @__PURE__ */ new Map();
29
- documentFrequencies = /* @__PURE__ */ new Map();
30
- documentLengths = /* @__PURE__ */ new Map();
31
- avgDocLength = 0;
32
- k1 = 1.5;
33
- b = 0.75;
34
- /**
35
- * Add a document to the index
36
- */
37
- addDocument(doc) {
38
- const tokens = this.tokenize(doc.text);
39
- this.documents.set(doc.id, doc);
40
- this.documentLengths.set(doc.id, tokens.length);
41
- const termFreq = /* @__PURE__ */ new Map();
42
- const seenTerms = /* @__PURE__ */ new Set();
43
- for (const token of tokens) {
44
- termFreq.set(token, (termFreq.get(token) || 0) + 1);
45
- if (!seenTerms.has(token)) {
46
- seenTerms.add(token);
47
- this.documentFrequencies.set(token, (this.documentFrequencies.get(token) || 0) + 1);
48
- }
49
- }
50
- this.termFrequencies.set(doc.id, termFreq);
51
- this.updateAvgDocLength();
52
- }
53
- /**
54
- * Add multiple documents
55
- */
56
- addDocuments(docs) {
57
- for (const doc of docs) {
58
- this.addDocument(doc);
59
- }
60
- }
61
- /**
62
- * Search the index
63
- */
64
- search(query, limit = 10) {
65
- const queryTokens = this.tokenize(query);
66
- const scores = /* @__PURE__ */ new Map();
67
- const N = this.documents.size;
68
- for (const [docId] of this.documents) {
69
- let score = 0;
70
- const docLength = this.documentLengths.get(docId) || 0;
71
- const termFreqs = this.termFrequencies.get(docId);
72
- if (!termFreqs) continue;
73
- for (const term of queryTokens) {
74
- const tf = termFreqs.get(term) || 0;
75
- if (tf === 0) continue;
76
- const df = this.documentFrequencies.get(term) || 0;
77
- const idf = Math.log((N - df + 0.5) / (df + 0.5) + 1);
78
- const numerator = tf * (this.k1 + 1);
79
- const denominator = tf + this.k1 * (1 - this.b + this.b * (docLength / this.avgDocLength));
80
- score += idf * (numerator / denominator);
81
- }
82
- if (score > 0) {
83
- scores.set(docId, score);
84
- }
85
- }
86
- return Array.from(scores.entries()).sort((a, b) => b[1] - a[1]).slice(0, limit).map(([id, score]) => {
87
- const metadata = this.documents.get(id)?.metadata;
88
- const result = { id, score };
89
- if (metadata !== void 0) {
90
- result.metadata = metadata;
91
- }
92
- return result;
93
- });
94
- }
95
- /**
96
- * Get document count
97
- */
98
- get size() {
99
- return this.documents.size;
100
- }
101
- /**
102
- * Clear the index
103
- */
104
- clear() {
105
- this.documents.clear();
106
- this.termFrequencies.clear();
107
- this.documentFrequencies.clear();
108
- this.documentLengths.clear();
109
- this.avgDocLength = 0;
110
- }
111
- /**
112
- * Serialize the index to JSON
113
- */
114
- serialize() {
115
- return JSON.stringify({
116
- documents: Array.from(this.documents.entries()),
117
- termFrequencies: Array.from(this.termFrequencies.entries()).map(([k, v]) => [k, Array.from(v.entries())]),
118
- documentFrequencies: Array.from(this.documentFrequencies.entries()),
119
- documentLengths: Array.from(this.documentLengths.entries()),
120
- avgDocLength: this.avgDocLength
121
- });
122
- }
123
- /**
124
- * Load from serialized JSON
125
- */
126
- static deserialize(json) {
127
- const data = JSON.parse(json);
128
- const index = new _BM25Index();
129
- index.documents = new Map(data.documents);
130
- index.termFrequencies = new Map(data.termFrequencies.map(([k, v]) => [k, new Map(v)]));
131
- index.documentFrequencies = new Map(data.documentFrequencies);
132
- index.documentLengths = new Map(data.documentLengths);
133
- index.avgDocLength = data.avgDocLength;
134
- return index;
135
- }
136
- tokenize(text) {
137
- return text.toLowerCase().replace(/[^\w\s]/g, " ").split(/\s+/).filter((token) => token.length > 2 && !this.isStopWord(token));
138
- }
139
- isStopWord(word) {
140
- const stopWords = /* @__PURE__ */ new Set([
141
- "the",
142
- "be",
143
- "to",
144
- "of",
145
- "and",
146
- "a",
147
- "in",
148
- "that",
149
- "have",
150
- "i",
151
- "it",
152
- "for",
153
- "not",
154
- "on",
155
- "with",
156
- "he",
157
- "as",
158
- "you",
159
- "do",
160
- "at",
161
- "this",
162
- "but",
163
- "his",
164
- "by",
165
- "from",
166
- "they",
167
- "we",
168
- "say",
169
- "her",
170
- "she",
171
- "or",
172
- "an",
173
- "will",
174
- "my",
175
- "one",
176
- "all",
177
- "would",
178
- "there",
179
- "their",
180
- "what",
181
- "so",
182
- "up",
183
- "out",
184
- "if",
185
- "about",
186
- "who",
187
- "get",
188
- "which",
189
- "go",
190
- "me",
191
- "when",
192
- "make",
193
- "can",
194
- "like",
195
- "time",
196
- "no",
197
- "just",
198
- "him",
199
- "know",
200
- "take",
201
- "into",
202
- "year",
203
- "your",
204
- "some",
205
- "could",
206
- "them",
207
- "see",
208
- "other",
209
- "than",
210
- "then",
211
- "now",
212
- "look",
213
- "only",
214
- "come",
215
- "its",
216
- "over",
217
- "also",
218
- "back",
219
- "after",
220
- "use",
221
- "two",
222
- "how",
223
- "our",
224
- "first",
225
- "way",
226
- "even",
227
- "new",
228
- "want",
229
- "because",
230
- "any",
231
- "these",
232
- "give",
233
- "day",
234
- "most",
235
- "us",
236
- "should",
237
- "been",
238
- "has",
239
- "was",
240
- "are"
241
- ]);
242
- return stopWords.has(word);
243
- }
244
- updateAvgDocLength() {
245
- if (this.documentLengths.size === 0) {
246
- this.avgDocLength = 0;
247
- return;
248
- }
249
- const total = Array.from(this.documentLengths.values()).reduce((a, b) => a + b, 0);
250
- this.avgDocLength = total / this.documentLengths.size;
251
- }
252
- };
253
-
254
- // src/memory/compactor.ts
255
- import { mkdir, readFile } from "fs/promises";
256
- import { existsSync } from "fs";
257
- import { join } from "path";
258
- async function compactOldIssues(issues, options = {}) {
259
- const keepDays = options.keepDays ?? 30;
260
- const minIssues = options.minIssuesToCompact ?? 100;
261
- const cutoffDate = /* @__PURE__ */ new Date();
262
- cutoffDate.setDate(cutoffDate.getDate() - keepDays);
263
- const oldIssues = issues.filter((i) => new Date(i.timestamp) < cutoffDate);
264
- const recentIssues = issues.filter((i) => new Date(i.timestamp) >= cutoffDate);
265
- if (oldIssues.length < minIssues) {
266
- return { summary: null, remaining: issues };
267
- }
268
- const summary = buildSummary(oldIssues);
269
- return { summary, remaining: recentIssues };
270
- }
271
- function buildSummary(issues) {
272
- const sorted = issues.sort(
273
- (a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime()
274
- );
275
- const bySeverity = {};
276
- const byAgent = {};
277
- const patternMap = /* @__PURE__ */ new Map();
278
- const fileCount = /* @__PURE__ */ new Map();
279
- for (const issue of issues) {
280
- bySeverity[issue.severity] = (bySeverity[issue.severity] || 0) + 1;
281
- byAgent[issue.agent] = (byAgent[issue.agent] || 0) + 1;
282
- const patternKey = normalizePattern(issue.issue);
283
- const existing = patternMap.get(patternKey);
284
- if (existing) {
285
- existing.count++;
286
- } else {
287
- patternMap.set(patternKey, { count: 1, issue });
288
- }
289
- const fileName = issue.file.split("/").pop() || issue.file;
290
- fileCount.set(fileName, (fileCount.get(fileName) || 0) + 1);
291
- }
292
- const topPatterns = Array.from(patternMap.entries()).sort((a, b) => b[1].count - a[1].count).slice(0, 10).map(([pattern, data]) => ({
293
- pattern: pattern.slice(0, 100),
294
- count: data.count,
295
- severity: data.issue.severity,
296
- agent: data.issue.agent,
297
- exampleFix: data.issue.fix.slice(0, 200)
298
- }));
299
- const hotFiles = Array.from(fileCount.entries()).sort((a, b) => b[1] - a[1]).slice(0, 10).map(([file, count]) => ({ file, count }));
300
- return {
301
- period: `${sorted[0]?.timestamp.split("T")[0]} to ${sorted[sorted.length - 1]?.timestamp.split("T")[0]}`,
302
- startDate: sorted[0]?.timestamp || "",
303
- endDate: sorted[sorted.length - 1]?.timestamp || "",
304
- totalIssues: issues.length,
305
- resolvedCount: issues.filter((i) => i.resolved).length,
306
- bySeverity,
307
- byAgent,
308
- topPatterns,
309
- hotFiles,
310
- compactedAt: (/* @__PURE__ */ new Date()).toISOString()
311
- };
312
- }
313
- function normalizePattern(text) {
314
- return text.toLowerCase().replace(/`[^`]+`/g, "CODE").replace(/\b\d+\b/g, "N").replace(/["']/g, "").replace(/\s+/g, " ").trim().slice(0, 150);
315
- }
316
- async function saveCompactedSummary(summary, projectDir) {
317
- const memoryDir = join(getTrieDirectory(projectDir), "memory");
318
- await mkdir(memoryDir, { recursive: true });
319
- const summaryPath = join(memoryDir, "compacted-summaries.json");
320
- let summaries = [];
321
- try {
322
- if (existsSync(summaryPath)) {
323
- const content = await readFile(summaryPath, "utf-8");
324
- const result = safeParseAndValidate(content, CompactedSummariesIndexSchema);
325
- if (result.success) {
326
- summaries = result.data;
327
- }
328
- }
329
- } catch {
330
- summaries = [];
331
- }
332
- summaries.push(summary);
333
- if (summaries.length > 12) {
334
- summaries = summaries.slice(-12);
335
- }
336
- const backupManager = new BackupManager(summaryPath);
337
- await backupManager.createBackup();
338
- await atomicWriteJSON(summaryPath, summaries);
339
- }
340
- async function loadCompactedSummaries(projectDir) {
341
- const summaryPath = join(getTrieDirectory(projectDir), "memory", "compacted-summaries.json");
342
- try {
343
- if (existsSync(summaryPath)) {
344
- const content = await readFile(summaryPath, "utf-8");
345
- const result = safeParseAndValidate(content, CompactedSummariesIndexSchema);
346
- if (result.success) {
347
- return result.data;
348
- }
349
- const backupManager = new BackupManager(summaryPath);
350
- if (await backupManager.recoverFromBackup()) {
351
- const recovered = await readFile(summaryPath, "utf-8");
352
- const recoveredResult = safeParseAndValidate(recovered, CompactedSummariesIndexSchema);
353
- if (recoveredResult.success) {
354
- return recoveredResult.data;
355
- }
356
- }
357
- }
358
- } catch {
359
- }
360
- return [];
361
- }
362
- async function getHistoricalInsights(projectDir) {
363
- const summaries = await loadCompactedSummaries(projectDir);
364
- if (summaries.length === 0) {
365
- return {
366
- totalHistoricalIssues: 0,
367
- recurringPatterns: [],
368
- improvementTrend: "unknown"
369
- };
370
- }
371
- const totalHistoricalIssues = summaries.reduce((sum, s) => sum + s.totalIssues, 0);
372
- const patternCounts = /* @__PURE__ */ new Map();
373
- for (const summary of summaries) {
374
- for (const pattern of summary.topPatterns) {
375
- const key = pattern.pattern;
376
- const existing = patternCounts.get(key);
377
- if (existing) {
378
- existing.count += pattern.count;
379
- existing.appearances++;
380
- } else {
381
- patternCounts.set(key, { ...pattern, appearances: 1 });
382
- }
383
- }
384
- }
385
- const recurringPatterns = Array.from(patternCounts.values()).filter((p) => p.appearances >= 2).sort((a, b) => b.count - a.count).slice(0, 5);
386
- let improvementTrend = "unknown";
387
- if (summaries.length >= 2) {
388
- const recent = summaries.slice(-2);
389
- const olderCount = recent[0]?.totalIssues || 0;
390
- const newerCount = recent[1]?.totalIssues || 0;
391
- if (newerCount < olderCount * 0.8) {
392
- improvementTrend = "improving";
393
- } else if (newerCount > olderCount * 1.2) {
394
- improvementTrend = "declining";
395
- } else {
396
- improvementTrend = "stable";
397
- }
398
- }
399
- return {
400
- totalHistoricalIssues,
401
- recurringPatterns,
402
- improvementTrend
403
- };
404
- }
405
-
406
- // src/memory/issue-store.ts
407
- async function storeIssues(issues, project, workDir) {
408
- const projectDir = workDir || getWorkingDirectory(void 0, true);
409
- const memoryDir = join2(getTrieDirectory(projectDir), "memory");
410
- await mkdir2(memoryDir, { recursive: true });
411
- const stored = [];
412
- const now = (/* @__PURE__ */ new Date()).toISOString();
413
- const seenHashes = /* @__PURE__ */ new Set();
414
- let duplicates = 0;
415
- for (const issue of issues) {
416
- const hash = hashIssue(issue);
417
- if (seenHashes.has(hash)) {
418
- duplicates++;
419
- continue;
420
- }
421
- seenHashes.add(hash);
422
- const storedIssue = {
423
- id: issue.id,
424
- hash,
425
- severity: issue.severity,
426
- issue: issue.issue,
427
- fix: issue.fix,
428
- file: issue.file,
429
- line: issue.line,
430
- agent: issue.agent,
431
- category: issue.category,
432
- timestamp: now,
433
- project,
434
- resolved: false,
435
- resolvedAt: void 0,
436
- ...issue.ledgerBlockHash && { ledgerBlockHash: issue.ledgerBlockHash }
437
- };
438
- stored.push(storedIssue);
439
- }
440
- const ledgerBlock = await appendIssuesToLedger(stored, projectDir);
441
- if (ledgerBlock) {
442
- for (const issue of stored) {
443
- issue.ledgerBlockHash = ledgerBlock.blockHash;
444
- }
445
- }
446
- const dedupedCount = await updateIssueIndex(stored, projectDir);
447
- return { stored: dedupedCount, duplicates: duplicates + (stored.length - dedupedCount) };
448
- }
449
- async function searchIssues(query, options = {}) {
450
- const projectDir = options.workDir || getWorkingDirectory(void 0, true);
451
- const limit = options.limit || 10;
452
- const allIssues = await loadIssueIndex(projectDir);
453
- if (allIssues.length === 0) {
454
- return [];
455
- }
456
- const filteredIssues = allIssues.filter((issue) => {
457
- if (options.project && issue.project !== options.project) return false;
458
- if (options.severity && !options.severity.includes(issue.severity)) return false;
459
- if (options.agent && issue.agent !== options.agent) return false;
460
- if (!options.includeResolved && issue.resolved) return false;
461
- return true;
462
- });
463
- if (filteredIssues.length === 0) {
464
- return [];
465
- }
466
- const bm25 = new BM25Index();
467
- const issueMap = /* @__PURE__ */ new Map();
468
- for (const issue of filteredIssues) {
469
- const searchText = `${issue.issue} ${issue.fix} ${issue.file} ${issue.agent} ${issue.category || ""} ${issue.severity}`;
470
- bm25.addDocument({
471
- id: issue.id,
472
- text: searchText
473
- });
474
- issueMap.set(issue.id, issue);
475
- }
476
- const bm25Results = bm25.search(query, limit);
477
- return bm25Results.map((result) => ({
478
- issue: issueMap.get(result.id),
479
- score: result.score,
480
- matchType: "bm25"
481
- }));
482
- }
483
- async function findSimilarIssues(issue, options = {}) {
484
- const query = `${issue.issue} ${issue.fix} ${issue.agent}`;
485
- const searchOptions = {
486
- limit: (options.limit || 5) + 5,
487
- // Get extra to account for filtering
488
- includeResolved: true
489
- };
490
- if (options.workDir !== void 0) {
491
- searchOptions.workDir = options.workDir;
492
- }
493
- const results = await searchIssues(query, searchOptions);
494
- let filtered = results.filter((r) => r.issue.id !== issue.id);
495
- if (options.excludeSameFile) {
496
- filtered = filtered.filter((r) => r.issue.file !== issue.file);
497
- }
498
- return filtered.slice(0, options.limit || 5);
499
- }
500
- async function markIssueResolved(issueId, workDir) {
501
- const projectDir = workDir || getWorkingDirectory(void 0, true);
502
- const memoryDir = join2(getTrieDirectory(projectDir), "memory");
503
- const indexPath = join2(memoryDir, "issues.json");
504
- return withFileLock(indexPath, async () => {
505
- const index = await loadIssueIndex(projectDir);
506
- const issue = index.find((i) => i.id === issueId);
507
- if (!issue) return false;
508
- issue.resolved = true;
509
- issue.resolvedAt = (/* @__PURE__ */ new Date()).toISOString();
510
- await saveIssueIndexInternal(index, projectDir);
511
- return true;
512
- }, { timeout: 1e4 });
513
- }
514
- async function autoResolveIssues(newIssueHashes, scannedFiles, workDir) {
515
- const projectDir = workDir || getWorkingDirectory(void 0, true);
516
- const memoryDir = join2(getTrieDirectory(projectDir), "memory");
517
- const indexPath = join2(memoryDir, "issues.json");
518
- return withFileLock(indexPath, async () => {
519
- const index = await loadIssueIndex(projectDir);
520
- const scannedFileSet = new Set(scannedFiles.map((f) => f.replace(/\\/g, "/")));
521
- const now = (/* @__PURE__ */ new Date()).toISOString();
522
- let resolvedCount = 0;
523
- let stillActiveCount = 0;
524
- for (const issue of index) {
525
- if (issue.resolved) continue;
526
- const normalizedFile = issue.file.replace(/\\/g, "/");
527
- if (!scannedFileSet.has(normalizedFile)) {
528
- stillActiveCount++;
529
- continue;
530
- }
531
- if (!newIssueHashes.has(issue.hash)) {
532
- issue.resolved = true;
533
- issue.resolvedAt = now;
534
- resolvedCount++;
535
- } else {
536
- stillActiveCount++;
537
- }
538
- }
539
- if (resolvedCount > 0) {
540
- await saveIssueIndexInternal(index, projectDir);
541
- }
542
- return { resolved: resolvedCount, stillActive: stillActiveCount };
543
- }, { timeout: 15e3 });
544
- }
545
- async function resolveGoalViolation(file, goalDescription, workDir) {
546
- const projectDir = workDir || getWorkingDirectory(void 0, true);
547
- const memoryDir = join2(getTrieDirectory(projectDir), "memory");
548
- const indexPath = join2(memoryDir, "issues.json");
549
- let resolvedCount = await withFileLock(indexPath, async () => {
550
- const index = await loadIssueIndex(projectDir);
551
- const now = (/* @__PURE__ */ new Date()).toISOString();
552
- let count = 0;
553
- for (const issue of index) {
554
- if (issue.resolved) continue;
555
- if (issue.agent !== "goal-violation") continue;
556
- const normalizedFile = issue.file.replace(/\\/g, "/");
557
- const normalizedTarget = file.replace(/\\/g, "/");
558
- if (normalizedFile === normalizedTarget && issue.issue.includes(`Goal "${goalDescription}"`)) {
559
- issue.resolved = true;
560
- issue.resolvedAt = now;
561
- count++;
562
- }
563
- }
564
- if (count > 0) {
565
- await saveIssueIndexInternal(index, projectDir);
566
- }
567
- return count;
568
- }, { timeout: 1e4 });
569
- try {
570
- const { getStorage } = await import("./tiered-storage-Z3YCR465.js");
571
- const storage = getStorage(projectDir);
572
- await storage.initialize();
573
- const nudgeResolved = await storage.resolveNudgesForGoalViolation(file, goalDescription, workDir);
574
- if (nudgeResolved > 0) {
575
- console.debug(`[IssueStore] Auto-resolved ${nudgeResolved} nudge(s) for fixed goal violation`);
576
- resolvedCount += nudgeResolved;
577
- }
578
- } catch (e) {
579
- console.debug("[IssueStore] Nudge resolution failed (non-fatal):", e);
580
- }
581
- return resolvedCount;
582
- }
583
- function getIssueHash(issue) {
584
- return hashIssue(issue);
585
- }
586
- async function getMemoryStats(workDir) {
587
- const projectDir = workDir || getWorkingDirectory(void 0, true);
588
- const index = await loadIssueIndex(projectDir);
589
- const historical = await getHistoricalInsights(projectDir);
590
- const MAX_ISSUES = 1e4;
591
- const uniqueHashes = new Set(index.map((i) => i.hash));
592
- const stats = {
593
- totalIssues: index.length,
594
- activeIssues: 0,
595
- issuesByAgent: {},
596
- issuesBySeverity: {},
597
- activeIssuesBySeverity: {},
598
- oldestIssue: void 0,
599
- newestIssue: void 0,
600
- resolvedCount: 0,
601
- historicalIssues: historical.totalHistoricalIssues,
602
- improvementTrend: historical.improvementTrend,
603
- capacityInfo: {
604
- current: index.length,
605
- max: MAX_ISSUES,
606
- percentFull: Math.round(index.length / MAX_ISSUES * 100),
607
- isAtCap: index.length >= MAX_ISSUES
608
- },
609
- deduplicationStats: {
610
- duplicatesAvoided: index.length - uniqueHashes.size,
611
- uniquePatterns: uniqueHashes.size
612
- }
613
- };
614
- for (const issue of index) {
615
- stats.issuesByAgent[issue.agent] = (stats.issuesByAgent[issue.agent] || 0) + 1;
616
- stats.issuesBySeverity[issue.severity] = (stats.issuesBySeverity[issue.severity] || 0) + 1;
617
- if (issue.resolved) {
618
- stats.resolvedCount++;
619
- } else {
620
- stats.activeIssues++;
621
- stats.activeIssuesBySeverity[issue.severity] = (stats.activeIssuesBySeverity[issue.severity] || 0) + 1;
622
- }
623
- }
624
- if (index.length > 0) {
625
- const sorted = [...index].sort(
626
- (a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime()
627
- );
628
- const oldest = sorted[0]?.timestamp;
629
- const newest = sorted[sorted.length - 1]?.timestamp;
630
- if (oldest !== void 0) {
631
- stats.oldestIssue = oldest;
632
- }
633
- if (newest !== void 0) {
634
- stats.newestIssue = newest;
635
- }
636
- }
637
- return stats;
638
- }
639
- async function getRecentIssues(options = {}) {
640
- const projectDir = options.workDir || getWorkingDirectory(void 0, true);
641
- const index = await loadIssueIndex(projectDir);
642
- const limit = options.limit || 20;
643
- const daysBack = options.daysBack || 7;
644
- const includeResolved = options.includeResolved ?? false;
645
- const cutoff = /* @__PURE__ */ new Date();
646
- cutoff.setDate(cutoff.getDate() - daysBack);
647
- return index.filter((i) => {
648
- if (new Date(i.timestamp) < cutoff) return false;
649
- if (!includeResolved && i.resolved) return false;
650
- return true;
651
- }).sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime()).slice(0, limit);
652
- }
653
- async function purgeIssues(strategy, options = {}) {
654
- const projectDir = options.workDir || getWorkingDirectory(void 0, true);
655
- const memoryDir = join2(getTrieDirectory(projectDir), "memory");
656
- const indexPath = join2(memoryDir, "issues.json");
657
- return withFileLock(indexPath, async () => {
658
- const index = await loadIssueIndex(projectDir);
659
- const originalCount = index.length;
660
- let remaining = [];
661
- switch (strategy) {
662
- case "smart":
663
- const thirtyDaysAgo = /* @__PURE__ */ new Date();
664
- thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);
665
- remaining = index.filter((i) => {
666
- const isRecent = new Date(i.timestamp) >= thirtyDaysAgo;
667
- const isImportant = ["critical", "high"].includes(i.severity);
668
- const isUnresolved = !i.resolved;
669
- return isRecent || isImportant || isUnresolved;
670
- });
671
- break;
672
- case "resolved":
673
- remaining = index.filter((i) => !i.resolved);
674
- break;
675
- case "old":
676
- const daysOld = options.daysOld || 90;
677
- const cutoffDate = /* @__PURE__ */ new Date();
678
- cutoffDate.setDate(cutoffDate.getDate() - daysOld);
679
- remaining = index.filter((i) => new Date(i.timestamp) >= cutoffDate);
680
- break;
681
- case "all":
682
- remaining = [];
683
- break;
684
- }
685
- await saveIssueIndexInternal(remaining, projectDir);
686
- return {
687
- removed: originalCount - remaining.length,
688
- remaining: remaining.length,
689
- strategy
690
- };
691
- }, { timeout: 1e4 });
692
- }
693
- async function getDailyLogs(workDir) {
694
- const projectDir = workDir || getWorkingDirectory(void 0, true);
695
- const memoryDir = join2(getTrieDirectory(projectDir), "memory");
696
- try {
697
- if (!existsSync2(memoryDir)) return [];
698
- const files = await readdir(memoryDir);
699
- return files.filter((f) => /^\d{4}-\d{2}-\d{2}\.md$/.test(f)).sort().reverse();
700
- } catch {
701
- return [];
702
- }
703
- }
704
- async function getIssueLedgerEntry(issue, workDir) {
705
- if (!issue.ledgerBlockHash) return null;
706
- const projectDir = workDir || getWorkingDirectory(void 0, true);
707
- const { getLedgerBlocks } = await import("./ledger-TWZTGDFA.js");
708
- const blocks = await getLedgerBlocks(projectDir);
709
- const block = blocks.find((b) => b.blockHash === issue.ledgerBlockHash);
710
- if (!block) return null;
711
- const entry = block.entries.find((e) => e.hash === issue.hash);
712
- if (!entry) return null;
713
- return { block, entry };
714
- }
715
- async function loadIssueIndex(projectDir) {
716
- const indexPath = join2(getTrieDirectory(projectDir), "memory", "issues.json");
717
- try {
718
- if (existsSync2(indexPath)) {
719
- const content = await readFile2(indexPath, "utf-8");
720
- const result = safeParseAndValidate(content, IssueIndexSchema);
721
- if (result.success) {
722
- return result.data;
723
- }
724
- const errorMsg = "success" in result && !result.success ? result.error : "Unknown validation error";
725
- console.error(` Issue index corrupted: ${errorMsg}`);
726
- const backupManager = new BackupManager(indexPath);
727
- if (await backupManager.recoverFromBackup()) {
728
- console.error(" \u2705 Recovered from backup");
729
- const recovered = await readFile2(indexPath, "utf-8");
730
- const recoveredResult = safeParseAndValidate(recovered, IssueIndexSchema);
731
- if (recoveredResult.success) {
732
- return recoveredResult.data;
733
- }
734
- }
735
- console.error(" No valid backup found, starting fresh");
736
- }
737
- } catch {
738
- }
739
- return [];
740
- }
741
- async function updateIssueIndex(newIssues, projectDir) {
742
- const memoryDir = join2(getTrieDirectory(projectDir), "memory");
743
- await mkdir2(memoryDir, { recursive: true });
744
- const indexPath = join2(memoryDir, "issues.json");
745
- return withFileLock(indexPath, async () => {
746
- let existing = await loadIssueIndex(projectDir);
747
- const hashSet = new Set(existing.map((i) => i.hash));
748
- const toAdd = newIssues.filter((i) => !hashSet.has(i.hash));
749
- const dedupedCount = toAdd.length;
750
- existing = [...existing, ...toAdd];
751
- if (existing.length > 500) {
752
- const { summary, remaining } = await compactOldIssues(existing, {
753
- keepDays: 30,
754
- minIssuesToCompact: 100
755
- });
756
- if (summary) {
757
- await saveCompactedSummary(summary, projectDir);
758
- existing = remaining;
759
- }
760
- }
761
- if (existing.length > 1e4) {
762
- existing = intelligentPrune(existing, 1e4);
763
- }
764
- await saveIssueIndexInternal(existing, projectDir);
765
- return dedupedCount;
766
- }, { timeout: 15e3 });
767
- }
768
- function intelligentPrune(issues, targetCount) {
769
- const severityWeight = {
770
- critical: 100,
771
- high: 50,
772
- moderate: 20,
773
- low: 10,
774
- info: 5
775
- };
776
- const scored = issues.map((issue) => {
777
- const ageInDays = (Date.now() - new Date(issue.timestamp).getTime()) / (1e3 * 60 * 60 * 24);
778
- const recencyScore = Math.max(0, 100 - ageInDays * 2);
779
- const severityScore = severityWeight[issue.severity] || 10;
780
- const resolvedPenalty = issue.resolved ? -50 : 0;
781
- return {
782
- issue,
783
- score: recencyScore + severityScore + resolvedPenalty
784
- };
785
- });
786
- return scored.sort((a, b) => b.score - a.score).slice(0, targetCount).map((s) => s.issue);
787
- }
788
- async function saveIssueIndexInternal(issues, projectDir) {
789
- const memoryDir = join2(getTrieDirectory(projectDir), "memory");
790
- await mkdir2(memoryDir, { recursive: true });
791
- const indexPath = join2(memoryDir, "issues.json");
792
- const backupManager = new BackupManager(indexPath);
793
- await backupManager.createBackup();
794
- await atomicWriteJSON(indexPath, issues);
795
- }
796
- function hashIssue(issue) {
797
- const content = `${issue.issue}|${issue.file}|${issue.severity}|${issue.agent}`;
798
- return createHash("sha256").update(content).digest("hex").slice(0, 16);
799
- }
800
-
801
- export {
802
- getHistoricalInsights,
803
- storeIssues,
804
- searchIssues,
805
- findSimilarIssues,
806
- markIssueResolved,
807
- autoResolveIssues,
808
- resolveGoalViolation,
809
- getIssueHash,
810
- getMemoryStats,
811
- getRecentIssues,
812
- purgeIssues,
813
- getDailyLogs,
814
- getIssueLedgerEntry
815
- };
816
- //# sourceMappingURL=chunk-XE6KQRKZ.js.map