@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,737 +0,0 @@
1
- import {
2
- getTrieDirectory
3
- } from "./chunk-VVITXIHN.js";
4
-
5
- // src/storage/tiered-storage.ts
6
- import { writeFile, mkdir } from "fs/promises";
7
- import { join } from "path";
8
- import { createHash } from "crypto";
9
- import Database from "better-sqlite3";
10
- var TieredStorage = class {
11
- workDir;
12
- hotCache = /* @__PURE__ */ new Map();
13
- warmDb = null;
14
- constructor(workDir) {
15
- this.workDir = workDir;
16
- }
17
- /**
18
- * Initialize storage directories and database
19
- */
20
- async initialize() {
21
- const trieDir = getTrieDirectory(this.workDir);
22
- await mkdir(join(trieDir, "hot"), { recursive: true });
23
- await mkdir(join(trieDir, "warm"), { recursive: true });
24
- await mkdir(join(trieDir, "cold"), { recursive: true });
25
- const dbPath = join(trieDir, "warm", "governance.db");
26
- this.warmDb = new Database(dbPath);
27
- this.warmDb.exec(`
28
- CREATE TABLE IF NOT EXISTS governance (
29
- id TEXT PRIMARY KEY,
30
- decision TEXT NOT NULL,
31
- context TEXT NOT NULL,
32
- reasoning TEXT,
33
- timestamp TEXT NOT NULL,
34
- who TEXT,
35
- files TEXT NOT NULL, -- JSON array
36
- tags TEXT NOT NULL, -- JSON array
37
- expandedTags TEXT, -- JSON array (with synonyms)
38
- relatedTo TEXT, -- JSON array
39
- tradeoffs TEXT, -- JSON array
40
- status TEXT NOT NULL,
41
- supersededBy TEXT,
42
- hash TEXT, -- SHA-256 fingerprint (first 16 hex chars)
43
- dependencies TEXT, -- JSON array (npm packages, services)
44
- codebaseArea TEXT, -- JSON array (frontend, backend, auth, etc.)
45
- domain TEXT, -- JSON array (payments, compliance, etc.)
46
- lastAccessed TEXT NOT NULL,
47
- accessCount INTEGER DEFAULT 0
48
- );
49
-
50
- CREATE TABLE IF NOT EXISTS facts (
51
- id TEXT PRIMARY KEY,
52
- fact TEXT NOT NULL,
53
- source TEXT NOT NULL,
54
- timestamp TEXT NOT NULL,
55
- tags TEXT NOT NULL, -- JSON array
56
- expandedTags TEXT, -- JSON array (with synonyms)
57
- relatedGovernance TEXT, -- JSON array
58
- confidence REAL NOT NULL,
59
- lastAccessed TEXT NOT NULL,
60
- accessCount INTEGER DEFAULT 0
61
- );
62
-
63
- CREATE TABLE IF NOT EXISTS blockers (
64
- id TEXT PRIMARY KEY,
65
- blocker TEXT NOT NULL,
66
- impact TEXT NOT NULL,
67
- affectedAreas TEXT NOT NULL, -- JSON array
68
- timestamp TEXT NOT NULL,
69
- resolvedAt TEXT,
70
- resolution TEXT,
71
- tags TEXT NOT NULL, -- JSON array
72
- expandedTags TEXT, -- JSON array (with synonyms)
73
- lastAccessed TEXT NOT NULL,
74
- accessCount INTEGER DEFAULT 0
75
- );
76
-
77
- CREATE TABLE IF NOT EXISTS questions (
78
- id TEXT PRIMARY KEY,
79
- question TEXT NOT NULL,
80
- context TEXT NOT NULL,
81
- timestamp TEXT NOT NULL,
82
- answeredAt TEXT,
83
- answer TEXT,
84
- relatedGovernance TEXT, -- JSON array
85
- tags TEXT NOT NULL, -- JSON array
86
- expandedTags TEXT, -- JSON array (with synonyms)
87
- lastAccessed TEXT NOT NULL,
88
- accessCount INTEGER DEFAULT 0
89
- );
90
-
91
- CREATE TABLE IF NOT EXISTS nudges (
92
- id TEXT PRIMARY KEY,
93
- message TEXT NOT NULL,
94
- severity TEXT NOT NULL, -- 'critical', 'high', 'warning', 'info'
95
- file TEXT,
96
- category TEXT, -- 'quality', 'security', 'performance', etc.
97
- goalId TEXT, -- Related goal ID if this is a goal violation
98
- timestamp TEXT NOT NULL,
99
- resolved BOOLEAN NOT NULL DEFAULT 0,
100
- resolvedAt TEXT,
101
- resolution TEXT, -- How it was resolved: 'dismissed', 'fixed', 'auto-fixed'
102
- dismissed BOOLEAN NOT NULL DEFAULT 0,
103
- priority INTEGER DEFAULT 5, -- 1-10 priority score
104
- suggestedAction TEXT,
105
- relatedIssues TEXT, -- JSON array
106
- metadata TEXT -- JSON object for additional data
107
- );
108
-
109
- CREATE TABLE IF NOT EXISTS gotchas (
110
- id TEXT PRIMARY KEY,
111
- message TEXT NOT NULL,
112
- confidence REAL NOT NULL, -- 0-1 confidence score
113
- riskLevel TEXT NOT NULL, -- 'low', 'medium', 'high', 'critical'
114
- recommendation TEXT NOT NULL,
115
- file TEXT,
116
- timestamp TEXT NOT NULL,
117
- precedentId TEXT, -- ID of related historical incident/governance record
118
- tags TEXT NOT NULL, -- JSON array
119
- evidence TEXT NOT NULL, -- JSON object with pastIncidents, matchingPatterns, relatedTickets
120
- resolved BOOLEAN NOT NULL DEFAULT 0,
121
- resolvedAt TEXT,
122
- resolution TEXT -- 'confirmed', 'false-positive', 'dismissed'
123
- );
124
-
125
- CREATE INDEX IF NOT EXISTS idx_governance_tags ON governance(tags);
126
- CREATE INDEX IF NOT EXISTS idx_governance_expanded ON governance(expandedTags);
127
- CREATE INDEX IF NOT EXISTS idx_governance_timestamp ON governance(timestamp);
128
- CREATE INDEX IF NOT EXISTS idx_governance_status ON governance(status);
129
- CREATE INDEX IF NOT EXISTS idx_governance_area ON governance(codebaseArea);
130
- CREATE INDEX IF NOT EXISTS idx_governance_domain ON governance(domain);
131
- CREATE INDEX IF NOT EXISTS idx_facts_tags ON facts(tags);
132
- CREATE INDEX IF NOT EXISTS idx_facts_expanded ON facts(expandedTags);
133
- CREATE INDEX IF NOT EXISTS idx_blockers_impact ON blockers(impact);
134
- CREATE INDEX IF NOT EXISTS idx_blockers_resolved ON blockers(resolvedAt);
135
- CREATE INDEX IF NOT EXISTS idx_nudges_timestamp ON nudges(timestamp);
136
- CREATE INDEX IF NOT EXISTS idx_nudges_resolved ON nudges(resolved);
137
- CREATE INDEX IF NOT EXISTS idx_nudges_severity ON nudges(severity);
138
- CREATE INDEX IF NOT EXISTS idx_nudges_file ON nudges(file);
139
- CREATE INDEX IF NOT EXISTS idx_gotchas_timestamp ON gotchas(timestamp);
140
- CREATE INDEX IF NOT EXISTS idx_gotchas_resolved ON gotchas(resolved);
141
- CREATE INDEX IF NOT EXISTS idx_gotchas_riskLevel ON gotchas(riskLevel);
142
- CREATE INDEX IF NOT EXISTS idx_gotchas_file ON gotchas(file);
143
- CREATE INDEX IF NOT EXISTS idx_gotchas_tags ON gotchas(tags);
144
- `);
145
- }
146
- /**
147
- * Store extracted signal with enriched metadata in warm storage
148
- */
149
- async storeSignal(signal, metadata) {
150
- if (!this.warmDb) await this.initialize();
151
- if (!this.warmDb) throw new Error("Database not initialized");
152
- const now = (/* @__PURE__ */ new Date()).toISOString();
153
- const totalSignals = signal.governance.length + signal.facts.length + signal.blockers.length + signal.questions.length;
154
- if (totalSignals > 0) {
155
- console.debug(`[Storage] Storing ${totalSignals} signals: ${signal.governance.length}g, ${signal.facts.length}f, ${signal.blockers.length}b, ${signal.questions.length}q`);
156
- }
157
- const governanceStmt = this.warmDb.prepare(`
158
- INSERT OR REPLACE INTO governance
159
- (id, decision, context, reasoning, timestamp, who, files, tags, expandedTags, relatedTo, tradeoffs, status, supersededBy, hash, dependencies, codebaseArea, domain, lastAccessed, accessCount)
160
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0)
161
- `);
162
- const governanceRecords = signal.governance;
163
- for (const gov of governanceRecords) {
164
- const hash = gov.hash || createHash("sha256").update(`${gov.decision}|${gov.context}|${gov.when}`).digest("hex").slice(0, 16);
165
- governanceStmt.run(
166
- gov.id,
167
- gov.decision,
168
- gov.context,
169
- gov.reasoning || null,
170
- gov.when,
171
- gov.who || null,
172
- JSON.stringify(gov.files),
173
- JSON.stringify(gov.tags),
174
- JSON.stringify(metadata?.expandedTags || []),
175
- JSON.stringify(gov.relatedTo || []),
176
- JSON.stringify(gov.tradeoffs || []),
177
- gov.status,
178
- gov.supersededBy || null,
179
- hash,
180
- JSON.stringify(metadata?.dependencies || []),
181
- JSON.stringify(metadata?.codebaseArea || []),
182
- JSON.stringify(metadata?.domain || []),
183
- now
184
- );
185
- }
186
- const factStmt = this.warmDb.prepare(`
187
- INSERT OR REPLACE INTO facts
188
- (id, fact, source, timestamp, tags, expandedTags, relatedGovernance, confidence, lastAccessed, accessCount)
189
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 0)
190
- `);
191
- for (const fact of signal.facts) {
192
- factStmt.run(
193
- fact.id,
194
- fact.fact,
195
- fact.source,
196
- fact.when,
197
- JSON.stringify(fact.tags),
198
- JSON.stringify(metadata?.expandedTags || []),
199
- JSON.stringify(fact.relatedGovernance || []),
200
- fact.confidence,
201
- now
202
- );
203
- }
204
- const blockerStmt = this.warmDb.prepare(`
205
- INSERT OR REPLACE INTO blockers
206
- (id, blocker, impact, affectedAreas, timestamp, resolvedAt, resolution, tags, expandedTags, lastAccessed, accessCount)
207
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0)
208
- `);
209
- for (const blocker of signal.blockers) {
210
- blockerStmt.run(
211
- blocker.id,
212
- blocker.blocker,
213
- blocker.impact,
214
- JSON.stringify(blocker.affectedAreas),
215
- blocker.when,
216
- blocker.resolvedAt || null,
217
- blocker.resolution || null,
218
- JSON.stringify(blocker.tags),
219
- JSON.stringify(metadata?.expandedTags || []),
220
- now
221
- );
222
- }
223
- const questionStmt = this.warmDb.prepare(`
224
- INSERT OR REPLACE INTO questions
225
- (id, question, context, timestamp, answeredAt, answer, relatedGovernance, tags, expandedTags, lastAccessed, accessCount)
226
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0)
227
- `);
228
- for (const q of signal.questions) {
229
- questionStmt.run(
230
- q.id,
231
- q.question,
232
- q.context,
233
- q.when,
234
- q.answeredAt || null,
235
- q.answer || null,
236
- JSON.stringify(q.relatedGovernance || []),
237
- JSON.stringify(q.tags),
238
- JSON.stringify(metadata?.expandedTags || []),
239
- now
240
- );
241
- }
242
- if (signal.gotchas && signal.gotchas.length > 0) {
243
- const gotchaStmt = this.warmDb.prepare(`
244
- INSERT OR REPLACE INTO gotchas
245
- (id, message, confidence, riskLevel, recommendation, file, timestamp, precedentId, tags, evidence, resolved, resolvedAt, resolution)
246
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
247
- `);
248
- for (const g of signal.gotchas) {
249
- gotchaStmt.run(
250
- g.id,
251
- g.message,
252
- g.confidence,
253
- g.riskLevel,
254
- g.recommendation,
255
- g.file || null,
256
- g.timestamp,
257
- g.precedentId || null,
258
- JSON.stringify(g.tags || []),
259
- JSON.stringify(g.evidence || { pastIncidents: [], matchingPatterns: [], relatedTickets: [] }),
260
- g.resolved ? 1 : 0,
261
- g.resolvedAt || null,
262
- g.resolution || null
263
- );
264
- }
265
- }
266
- const storedCount = signal.governance.length + signal.facts.length + signal.blockers.length + signal.questions.length + (signal.gotchas?.length || 0);
267
- if (storedCount > 0) {
268
- console.debug(`[Storage] \u2713 Successfully stored ${storedCount} signals to governance.db`);
269
- }
270
- }
271
- /**
272
- * Query governance records from warm storage with expanded tag matching
273
- */
274
- async queryGovernance(query) {
275
- if (!this.warmDb) await this.initialize();
276
- if (!this.warmDb) throw new Error("Database not initialized");
277
- let sql = "SELECT * FROM governance WHERE status = ?";
278
- const params = ["active"];
279
- if (query.tags && query.tags.length > 0) {
280
- sql += " AND (" + query.tags.map(() => "(tags LIKE ? OR expandedTags LIKE ?)").join(" OR ") + ")";
281
- for (const tag of query.tags) {
282
- params.push(`%"${tag}"%`, `%"${tag}"%`);
283
- }
284
- }
285
- if (query.filters?.codebaseArea) {
286
- sql += " AND codebaseArea LIKE ?";
287
- params.push(`%"${query.filters.codebaseArea}"%`);
288
- }
289
- if (query.filters?.domain) {
290
- sql += " AND domain LIKE ?";
291
- params.push(`%"${query.filters.domain}"%`);
292
- }
293
- if (query.timeWindow) {
294
- if (query.timeWindow.start) {
295
- sql += " AND timestamp >= ?";
296
- params.push(query.timeWindow.start);
297
- }
298
- if (query.timeWindow.end) {
299
- sql += " AND timestamp <= ?";
300
- params.push(query.timeWindow.end);
301
- }
302
- }
303
- sql += " ORDER BY timestamp DESC";
304
- if (query.limit) {
305
- sql += " LIMIT ?";
306
- params.push(query.limit);
307
- }
308
- const rows = this.warmDb.prepare(sql).all(...params);
309
- return rows.map((row) => ({
310
- id: row.id,
311
- decision: row.decision,
312
- context: row.context,
313
- reasoning: row.reasoning,
314
- when: row.timestamp || row.when,
315
- who: row.who,
316
- files: JSON.parse(row.files),
317
- tags: JSON.parse(row.tags),
318
- relatedTo: JSON.parse(row.relatedTo || "[]"),
319
- tradeoffs: JSON.parse(row.tradeoffs || "[]"),
320
- status: row.status,
321
- supersededBy: row.supersededBy,
322
- hash: row.hash || void 0
323
- }));
324
- }
325
- /**
326
- * Query facts from warm storage (for Learned Signals display)
327
- */
328
- async queryFacts(query = {}) {
329
- if (!this.warmDb) await this.initialize();
330
- if (!this.warmDb) throw new Error("Database not initialized");
331
- const limit = query.limit ?? 20;
332
- const rows = this.warmDb.prepare("SELECT * FROM facts ORDER BY timestamp DESC LIMIT ?").all(limit);
333
- return rows.map((row) => ({
334
- id: row.id,
335
- fact: row.fact,
336
- source: row.source,
337
- when: row.timestamp || row.when,
338
- tags: JSON.parse(row.tags || "[]"),
339
- confidence: row.confidence ?? 0.8
340
- }));
341
- }
342
- /**
343
- * Query blockers from warm storage with expanded tag matching
344
- */
345
- async queryBlockers(query) {
346
- if (!this.warmDb) await this.initialize();
347
- if (!this.warmDb) throw new Error("Database not initialized");
348
- let sql = "SELECT * FROM blockers WHERE resolvedAt IS NULL";
349
- const params = [];
350
- if (query.tags && query.tags.length > 0) {
351
- sql += " AND (" + query.tags.map(() => "(tags LIKE ? OR expandedTags LIKE ?)").join(" OR ") + ")";
352
- for (const tag of query.tags) {
353
- params.push(`%"${tag}"%`, `%"${tag}"%`);
354
- }
355
- }
356
- sql += " ORDER BY CASE impact WHEN 'critical' THEN 1 WHEN 'high' THEN 2 WHEN 'medium' THEN 3 ELSE 4 END, timestamp DESC";
357
- if (query.limit) {
358
- sql += " LIMIT ?";
359
- params.push(query.limit);
360
- }
361
- const rows = this.warmDb.prepare(sql).all(...params);
362
- return rows.map((row) => ({
363
- id: row.id,
364
- blocker: row.blocker,
365
- impact: row.impact,
366
- affectedAreas: JSON.parse(row.affectedAreas),
367
- when: row.when,
368
- resolvedAt: row.resolvedAt,
369
- resolution: row.resolution,
370
- tags: JSON.parse(row.tags)
371
- }));
372
- }
373
- /**
374
- * Get hot cache item
375
- */
376
- getHot(key) {
377
- return this.hotCache.get(key);
378
- }
379
- /**
380
- * Set hot cache item
381
- */
382
- setHot(key, value) {
383
- this.hotCache.set(key, value);
384
- }
385
- /**
386
- * Clear hot cache
387
- */
388
- clearHot() {
389
- this.hotCache.clear();
390
- }
391
- /**
392
- * Store a nudge in warm storage
393
- */
394
- async storeNudge(nudge) {
395
- if (!this.warmDb) await this.initialize();
396
- if (!this.warmDb) throw new Error("Database not initialized");
397
- const stmt = this.warmDb.prepare(`
398
- INSERT OR REPLACE INTO nudges
399
- (id, message, severity, file, category, goalId, timestamp, resolved, resolvedAt, resolution, dismissed, priority, suggestedAction, relatedIssues, metadata)
400
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
401
- `);
402
- stmt.run(
403
- nudge.id,
404
- nudge.message,
405
- nudge.severity,
406
- nudge.file || null,
407
- nudge.category || null,
408
- nudge.goalId || null,
409
- nudge.timestamp,
410
- nudge.resolved ? 1 : 0,
411
- nudge.resolvedAt || null,
412
- nudge.resolution || null,
413
- nudge.dismissed ? 1 : 0,
414
- nudge.priority,
415
- nudge.suggestedAction || null,
416
- JSON.stringify(nudge.relatedIssues || []),
417
- JSON.stringify(nudge.metadata || {})
418
- );
419
- }
420
- /**
421
- * Query nudges from warm storage
422
- */
423
- async queryNudges(filters) {
424
- if (!this.warmDb) await this.initialize();
425
- if (!this.warmDb) throw new Error("Database not initialized");
426
- let sql = "SELECT * FROM nudges WHERE 1=1";
427
- const params = [];
428
- if (filters?.resolved !== void 0) {
429
- sql += " AND resolved = ?";
430
- params.push(filters.resolved ? 1 : 0);
431
- }
432
- if (filters?.severity) {
433
- sql += " AND severity = ?";
434
- params.push(filters.severity);
435
- }
436
- if (filters?.file) {
437
- sql += " AND file = ?";
438
- params.push(filters.file);
439
- }
440
- if (filters?.category) {
441
- sql += " AND category = ?";
442
- params.push(filters.category);
443
- }
444
- if (filters?.goalId) {
445
- sql += " AND goalId = ?";
446
- params.push(filters.goalId);
447
- }
448
- sql += " ORDER BY timestamp DESC";
449
- if (filters?.limit) {
450
- sql += " LIMIT ?";
451
- params.push(filters.limit);
452
- }
453
- const rows = this.warmDb.prepare(sql).all(...params);
454
- return rows.map((row) => ({
455
- id: row.id,
456
- message: row.message,
457
- severity: row.severity,
458
- file: row.file || void 0,
459
- category: row.category || void 0,
460
- goalId: row.goalId || void 0,
461
- timestamp: row.timestamp,
462
- resolved: Boolean(row.resolved),
463
- resolvedAt: row.resolvedAt || void 0,
464
- resolution: row.resolution || void 0,
465
- dismissed: Boolean(row.dismissed),
466
- priority: row.priority,
467
- suggestedAction: row.suggestedAction || void 0,
468
- relatedIssues: JSON.parse(row.relatedIssues || "[]"),
469
- metadata: JSON.parse(row.metadata || "{}")
470
- }));
471
- }
472
- /**
473
- * Mark a nudge as resolved
474
- */
475
- async resolveNudge(nudgeId, resolution) {
476
- if (!this.warmDb) await this.initialize();
477
- if (!this.warmDb) throw new Error("Database not initialized");
478
- const now = (/* @__PURE__ */ new Date()).toISOString();
479
- this.warmDb.prepare(`
480
- UPDATE nudges
481
- SET resolved = 1, resolvedAt = ?, resolution = ?, dismissed = ?
482
- WHERE id = ?
483
- `).run(now, resolution, resolution === "dismissed" ? 1 : 0, nudgeId);
484
- }
485
- /**
486
- * Mark a nudge as dismissed
487
- */
488
- async dismissNudge(nudgeId) {
489
- await this.resolveNudge(nudgeId, "dismissed");
490
- }
491
- /**
492
- * Mark a nudge as fixed (automatically called when issues are resolved)
493
- */
494
- async markNudgeFixed(nudgeId) {
495
- await this.resolveNudge(nudgeId, "fixed");
496
- }
497
- /**
498
- * Clear all nudges (mark all as resolved)
499
- */
500
- async clearAllNudges() {
501
- if (!this.warmDb) await this.initialize();
502
- if (!this.warmDb) throw new Error("Database not initialized");
503
- const now = (/* @__PURE__ */ new Date()).toISOString();
504
- this.warmDb.prepare(`
505
- UPDATE nudges
506
- SET resolved = 1, resolvedAt = ?, resolution = 'dismissed'
507
- WHERE resolved = 0
508
- `).run(now);
509
- }
510
- /**
511
- * Resolve nudges for a goal violation that was fixed in a specific file.
512
- * Called when a file is rescanned and no longer has violations for that goal.
513
- */
514
- async resolveNudgesForGoalViolation(file, goalDescription, _workDir) {
515
- if (!this.warmDb) await this.initialize();
516
- if (!this.warmDb) throw new Error("Database not initialized");
517
- const goalPattern = `%Goal "${goalDescription.replace(/"/g, '""')}"%`;
518
- const fileAlt = file.replace(/\\/g, "/");
519
- const rows = this.warmDb.prepare(`
520
- SELECT id FROM nudges
521
- WHERE resolved = 0
522
- AND (file = ? OR file = ?)
523
- AND message LIKE ?
524
- `).all(file, fileAlt, goalPattern);
525
- const now = (/* @__PURE__ */ new Date()).toISOString();
526
- let resolved = 0;
527
- for (const row of rows) {
528
- this.warmDb.prepare(`
529
- UPDATE nudges SET resolved = 1, resolvedAt = ?, resolution = 'auto-fixed'
530
- WHERE id = ?
531
- `).run(now, row.id);
532
- resolved++;
533
- }
534
- return resolved;
535
- }
536
- /**
537
- * Resolve all nudges for a specific goal (used when goal is achieved or deleted)
538
- */
539
- async resolveNudgesForGoal(goalDescription) {
540
- if (!this.warmDb) await this.initialize();
541
- if (!this.warmDb) throw new Error("Database not initialized");
542
- const goalPattern = `%Goal "${goalDescription.replace(/"/g, '""')}"%`;
543
- const now = (/* @__PURE__ */ new Date()).toISOString();
544
- const result = this.warmDb.prepare(`
545
- UPDATE nudges
546
- SET resolved = 1, resolvedAt = ?, resolution = 'goal-achieved'
547
- WHERE resolved = 0 AND message LIKE ?
548
- `).run(now, goalPattern);
549
- return result.changes;
550
- }
551
- /**
552
- * Resolve nudges for files that no longer exist
553
- */
554
- async resolveNudgesForMissingFiles() {
555
- if (!this.warmDb) await this.initialize();
556
- if (!this.warmDb) throw new Error("Database not initialized");
557
- const { existsSync } = await import("fs");
558
- const rows = this.warmDb.prepare(`
559
- SELECT id, file FROM nudges WHERE resolved = 0 AND file IS NOT NULL
560
- `).all();
561
- const now = (/* @__PURE__ */ new Date()).toISOString();
562
- let resolved = 0;
563
- for (const row of rows) {
564
- if (row.file && !existsSync(row.file)) {
565
- this.warmDb.prepare(`
566
- UPDATE nudges SET resolved = 1, resolvedAt = ?, resolution = 'file-deleted'
567
- WHERE id = ?
568
- `).run(now, row.id);
569
- resolved++;
570
- }
571
- }
572
- return resolved;
573
- }
574
- /**
575
- * Resolve nudges matching a pattern in the message (for type error clearing, etc.)
576
- */
577
- async resolveNudgesByPattern(messagePattern, resolution = "auto-fixed") {
578
- if (!this.warmDb) await this.initialize();
579
- if (!this.warmDb) throw new Error("Database not initialized");
580
- const now = (/* @__PURE__ */ new Date()).toISOString();
581
- const result = this.warmDb.prepare(`
582
- UPDATE nudges
583
- SET resolved = 1, resolvedAt = ?, resolution = ?
584
- WHERE resolved = 0 AND message LIKE ?
585
- `).run(now, resolution, `%${messagePattern}%`);
586
- return result.changes;
587
- }
588
- /**
589
- * Auto-resolve nudges that match fixed issues
590
- * Called after a scan to mark nudges as fixed if their related issues are resolved
591
- */
592
- async autoResolveFixedNudges(resolvedIssueIds) {
593
- if (!this.warmDb) await this.initialize();
594
- if (!this.warmDb) throw new Error("Database not initialized");
595
- if (resolvedIssueIds.length === 0) return 0;
596
- const now = (/* @__PURE__ */ new Date()).toISOString();
597
- let resolved = 0;
598
- for (const issueId of resolvedIssueIds) {
599
- const result = this.warmDb.prepare(`
600
- UPDATE nudges
601
- SET resolved = 1, resolvedAt = ?, resolution = 'auto-fixed'
602
- WHERE resolved = 0
603
- AND (
604
- relatedIssues LIKE ?
605
- OR id = ?
606
- )
607
- `).run(now, `%"${issueId}"%`, issueId);
608
- resolved += result.changes;
609
- }
610
- return resolved;
611
- }
612
- /**
613
- * Store a gotcha in warm storage
614
- */
615
- async storeGotcha(gotcha) {
616
- if (!this.warmDb) await this.initialize();
617
- if (!this.warmDb) throw new Error("Database not initialized");
618
- const stmt = this.warmDb.prepare(`
619
- INSERT OR REPLACE INTO gotchas
620
- (id, message, confidence, riskLevel, recommendation, file, timestamp, precedentId, tags, evidence, resolved, resolvedAt, resolution)
621
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
622
- `);
623
- stmt.run(
624
- gotcha.id,
625
- gotcha.message,
626
- gotcha.confidence,
627
- gotcha.riskLevel,
628
- gotcha.recommendation,
629
- gotcha.file || null,
630
- gotcha.timestamp,
631
- gotcha.precedentId || null,
632
- JSON.stringify(gotcha.tags || []),
633
- JSON.stringify(gotcha.evidence || { pastIncidents: [], matchingPatterns: [], relatedTickets: [] }),
634
- gotcha.resolved ? 1 : 0,
635
- gotcha.resolvedAt || null,
636
- gotcha.resolution || null
637
- );
638
- }
639
- /**
640
- * Query gotchas from warm storage
641
- */
642
- async queryGotchas(filters) {
643
- if (!this.warmDb) await this.initialize();
644
- if (!this.warmDb) throw new Error("Database not initialized");
645
- let sql = "SELECT * FROM gotchas WHERE 1=1";
646
- const params = [];
647
- if (filters?.resolved !== void 0) {
648
- sql += " AND resolved = ?";
649
- params.push(filters.resolved ? 1 : 0);
650
- }
651
- if (filters?.riskLevel) {
652
- sql += " AND riskLevel = ?";
653
- params.push(filters.riskLevel);
654
- }
655
- if (filters?.file) {
656
- sql += " AND file = ?";
657
- params.push(filters.file);
658
- }
659
- sql += " ORDER BY timestamp DESC";
660
- if (filters?.limit) {
661
- sql += " LIMIT ?";
662
- params.push(filters.limit);
663
- }
664
- const rows = this.warmDb.prepare(sql).all(...params);
665
- return rows.map((row) => ({
666
- id: row.id,
667
- message: row.message,
668
- confidence: row.confidence,
669
- riskLevel: row.riskLevel,
670
- recommendation: row.recommendation,
671
- file: row.file || void 0,
672
- timestamp: row.timestamp,
673
- precedentId: row.precedentId || void 0,
674
- tags: JSON.parse(row.tags || "[]"),
675
- evidence: JSON.parse(row.evidence || '{"pastIncidents":[],"matchingPatterns":[],"relatedTickets":[]}'),
676
- resolved: Boolean(row.resolved),
677
- resolvedAt: row.resolvedAt || void 0,
678
- resolution: row.resolution || void 0
679
- }));
680
- }
681
- /**
682
- * Get unresolved nudges count
683
- */
684
- async getUnresolvedNudgesCount() {
685
- if (!this.warmDb) await this.initialize();
686
- if (!this.warmDb) throw new Error("Database not initialized");
687
- const result = this.warmDb.prepare("SELECT COUNT(*) as count FROM nudges WHERE resolved = 0").get();
688
- return result.count;
689
- }
690
- /**
691
- * Archive old data to cold storage
692
- */
693
- async archiveToCold(olderThanDays = 90) {
694
- if (!this.warmDb) await this.initialize();
695
- if (!this.warmDb) throw new Error("Database not initialized");
696
- const cutoffDate = /* @__PURE__ */ new Date();
697
- cutoffDate.setDate(cutoffDate.getDate() - olderThanDays);
698
- const cutoff = cutoffDate.toISOString();
699
- const coldDir = join(getTrieDirectory(this.workDir), "cold");
700
- const archivePath = join(coldDir, `archive-${Date.now()}.json`);
701
- const governance = this.warmDb.prepare("SELECT * FROM governance WHERE timestamp < ? AND accessCount < 3").all(cutoff);
702
- const facts = this.warmDb.prepare("SELECT * FROM facts WHERE timestamp < ? AND accessCount < 3").all(cutoff);
703
- const blockers = this.warmDb.prepare("SELECT * FROM blockers WHERE timestamp < ? AND resolvedAt IS NOT NULL").all(cutoff);
704
- const questions = this.warmDb.prepare("SELECT * FROM questions WHERE timestamp < ? AND answeredAt IS NOT NULL").all(cutoff);
705
- const nudges = this.warmDb.prepare("SELECT * FROM nudges WHERE timestamp < ? AND resolved = 1").all(cutoff);
706
- const gotchas = this.warmDb.prepare("SELECT * FROM gotchas WHERE timestamp < ? AND resolved = 1").all(cutoff);
707
- await writeFile(archivePath, JSON.stringify({ governance, facts, blockers, questions, nudges, gotchas }, null, 2));
708
- this.warmDb.prepare("DELETE FROM governance WHERE timestamp < ? AND accessCount < 3").run(cutoff);
709
- this.warmDb.prepare("DELETE FROM facts WHERE timestamp < ? AND accessCount < 3").run(cutoff);
710
- this.warmDb.prepare("DELETE FROM blockers WHERE timestamp < ? AND resolvedAt IS NOT NULL").run(cutoff);
711
- this.warmDb.prepare("DELETE FROM questions WHERE timestamp < ? AND answeredAt IS NOT NULL").run(cutoff);
712
- this.warmDb.prepare("DELETE FROM nudges WHERE timestamp < ? AND resolved = 1").run(cutoff);
713
- this.warmDb.prepare("DELETE FROM gotchas WHERE timestamp < ? AND resolved = 1").run(cutoff);
714
- }
715
- /**
716
- * Close database connection
717
- */
718
- close() {
719
- if (this.warmDb) {
720
- this.warmDb.close();
721
- this.warmDb = null;
722
- }
723
- }
724
- };
725
- var storageInstances = /* @__PURE__ */ new Map();
726
- function getStorage(workDir) {
727
- if (!storageInstances.has(workDir)) {
728
- storageInstances.set(workDir, new TieredStorage(workDir));
729
- }
730
- return storageInstances.get(workDir);
731
- }
732
-
733
- export {
734
- TieredStorage,
735
- getStorage
736
- };
737
- //# sourceMappingURL=chunk-575YT2SD.js.map