@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,662 +0,0 @@
1
- import {
2
- getInsightStore
3
- } from "./chunk-T63OHG4Q.js";
4
- import {
5
- getMemoryStats,
6
- searchIssues
7
- } from "./chunk-XE6KQRKZ.js";
8
- import {
9
- getProjectState
10
- } from "./chunk-GTKYBOXL.js";
11
-
12
- // src/agent/goal-manager.ts
13
- import { basename } from "path";
14
- var DEFAULT_CONFIG = {
15
- minConfidence: 0.6,
16
- maxActiveGoals: 3,
17
- goalDurationDays: 14,
18
- reductionTargetPercent: 50
19
- };
20
- var GoalManager = class {
21
- projectPath;
22
- config;
23
- projectState;
24
- insightStore;
25
- constructor(projectPath, config = {}) {
26
- this.projectPath = projectPath;
27
- this.config = { ...DEFAULT_CONFIG, ...config };
28
- this.projectState = getProjectState(projectPath);
29
- this.insightStore = getInsightStore(projectPath);
30
- }
31
- /**
32
- * Analyze incident patterns from memory
33
- */
34
- async analyzeIncidentPatterns() {
35
- const patterns = [];
36
- try {
37
- const stats = await getMemoryStats(this.projectPath);
38
- const recentIssues = await searchIssues("", {
39
- workDir: this.projectPath,
40
- limit: 500,
41
- includeResolved: true
42
- });
43
- if (recentIssues.length < 5) {
44
- return patterns;
45
- }
46
- const fileIssueCount = /* @__PURE__ */ new Map();
47
- for (const { issue } of recentIssues) {
48
- const file = issue.file;
49
- fileIssueCount.set(file, (fileIssueCount.get(file) || 0) + 1);
50
- }
51
- const sortedFiles = [...fileIssueCount.entries()].sort((a, b) => b[1] - a[1]);
52
- const dirIssueCount = /* @__PURE__ */ new Map();
53
- for (const [file, count] of sortedFiles) {
54
- const parts = file.split("/");
55
- if (parts.length > 1) {
56
- const dir = parts.slice(0, -1).join("/");
57
- dirIssueCount.set(dir, (dirIssueCount.get(dir) || 0) + count);
58
- }
59
- }
60
- const sortedDirs = [...dirIssueCount.entries()].sort((a, b) => b[1] - a[1]);
61
- if (sortedDirs.length > 0) {
62
- const topDirEntry = sortedDirs[0];
63
- if (!topDirEntry) return patterns;
64
- const [topDir, topDirCount] = topDirEntry;
65
- const totalIssues = recentIssues.length;
66
- const percentage = topDirCount / totalIssues * 100;
67
- if (percentage >= 30) {
68
- patterns.push({
69
- type: "file-cluster",
70
- description: `${basename(topDir)}/ has ${percentage.toFixed(0)}% of issues`,
71
- metric: `${topDir}_issues`,
72
- currentValue: topDirCount,
73
- suggestedTarget: Math.floor(topDirCount * (1 - this.config.reductionTargetPercent / 100)),
74
- confidence: Math.min(0.9, percentage / 100 + 0.3),
75
- evidence: [
76
- `${topDirCount} issues in ${topDir}/`,
77
- `${percentage.toFixed(0)}% of total issues`,
78
- `Top files: ${sortedFiles.filter(([f]) => f.startsWith(topDir)).slice(0, 3).map(([f]) => basename(f)).join(", ")}`
79
- ],
80
- category: "quality"
81
- });
82
- }
83
- }
84
- const criticalCount = recentIssues.filter((r) => r.issue.severity === "critical").length;
85
- const seriousCount = recentIssues.filter((r) => r.issue.severity === "serious").length;
86
- if (criticalCount >= 3) {
87
- patterns.push({
88
- type: "severity-trend",
89
- description: `${criticalCount} critical issues need attention`,
90
- metric: "critical_issues",
91
- currentValue: criticalCount,
92
- suggestedTarget: 0,
93
- confidence: Math.min(0.95, 0.5 + criticalCount * 0.1),
94
- evidence: [
95
- `${criticalCount} critical severity issues`,
96
- `${seriousCount} serious severity issues`,
97
- "Critical issues should be zero for production safety"
98
- ],
99
- category: "security"
100
- });
101
- }
102
- const agentIssueCount = /* @__PURE__ */ new Map();
103
- for (const { issue } of recentIssues) {
104
- agentIssueCount.set(issue.agent, (agentIssueCount.get(issue.agent) || 0) + 1);
105
- }
106
- const sortedAgents = [...agentIssueCount.entries()].sort((a, b) => b[1] - a[1]);
107
- if (sortedAgents.length > 0) {
108
- const topAgentEntry = sortedAgents[0];
109
- if (!topAgentEntry) return patterns;
110
- const [topAgent, topAgentCount] = topAgentEntry;
111
- const percentage = topAgentCount / recentIssues.length * 100;
112
- if (percentage >= 40 && topAgentCount >= 5) {
113
- const category = this.agentToCategory(topAgent);
114
- patterns.push({
115
- type: "agent-concentration",
116
- description: `${topAgent} skill finds ${percentage.toFixed(0)}% of issues`,
117
- metric: `${topAgent}_issues`,
118
- currentValue: topAgentCount,
119
- suggestedTarget: Math.floor(topAgentCount * 0.5),
120
- confidence: Math.min(0.85, percentage / 100 + 0.2),
121
- evidence: [
122
- `${topAgentCount} issues from ${topAgent}`,
123
- `${percentage.toFixed(0)}% of all issues`,
124
- `Suggests focused improvement in ${category} area`
125
- ],
126
- category
127
- });
128
- }
129
- }
130
- if (stats.improvementTrend === "improving") {
131
- patterns.push({
132
- type: "time-pattern",
133
- description: "Quality is improving - maintain the streak",
134
- metric: "clean_scans",
135
- currentValue: 0,
136
- suggestedTarget: 5,
137
- confidence: 0.7,
138
- evidence: [
139
- "Historical trend shows improvement",
140
- "Momentum is positive",
141
- "Streak goal can maintain motivation"
142
- ],
143
- category: "quality"
144
- });
145
- }
146
- } catch (error) {
147
- console.error("Failed to analyze incident patterns:", error);
148
- }
149
- return patterns;
150
- }
151
- /**
152
- * Convert agent name to category
153
- */
154
- agentToCategory(agent) {
155
- const categoryMap = {
156
- "security": "security",
157
- "soc2": "security",
158
- "performance": "performance",
159
- "accessibility": "quality",
160
- "test": "coverage",
161
- "typecheck": "quality",
162
- "bug-finding": "quality"
163
- };
164
- return categoryMap[agent] || "general";
165
- }
166
- /**
167
- * Generate goal opportunities from patterns
168
- */
169
- async generateGoalOpportunities() {
170
- const patterns = await this.analyzeIncidentPatterns();
171
- const opportunities = [];
172
- const validPatterns = patterns.filter((p) => p.confidence >= this.config.minConfidence);
173
- await this.projectState.load();
174
- const activeGoals = this.projectState.getActiveGoals();
175
- const slotsAvailable = this.config.maxActiveGoals - activeGoals.length;
176
- if (slotsAvailable <= 0) {
177
- return opportunities;
178
- }
179
- for (const pattern of validPatterns.slice(0, slotsAvailable)) {
180
- const goalType = pattern.type === "time-pattern" ? "streak" : "reduction";
181
- const deadline = /* @__PURE__ */ new Date();
182
- deadline.setDate(deadline.getDate() + this.config.goalDurationDays);
183
- opportunities.push({
184
- pattern,
185
- goal: {
186
- description: this.generateGoalDescription(pattern),
187
- type: goalType,
188
- metric: pattern.metric,
189
- target: pattern.suggestedTarget,
190
- currentValue: pattern.currentValue,
191
- startValue: pattern.currentValue,
192
- status: "active",
193
- autoGenerated: true,
194
- confidence: pattern.confidence,
195
- deadline: deadline.toISOString(),
196
- category: pattern.category,
197
- evidence: pattern.evidence
198
- },
199
- reasoning: this.generateGoalReasoning(pattern)
200
- });
201
- }
202
- return opportunities;
203
- }
204
- /**
205
- * Generate a human-readable goal description
206
- */
207
- generateGoalDescription(pattern) {
208
- switch (pattern.type) {
209
- case "file-cluster":
210
- return `Reduce issues in ${pattern.description.split(" ")[0]} by ${this.config.reductionTargetPercent}%`;
211
- case "severity-trend":
212
- return "Eliminate all critical issues";
213
- case "agent-concentration":
214
- return `Reduce ${pattern.description.split(" ")[0]} issues by 50%`;
215
- case "time-pattern":
216
- return "Achieve 5 consecutive clean scans";
217
- default:
218
- return pattern.description;
219
- }
220
- }
221
- /**
222
- * Generate reasoning for why this goal was suggested
223
- */
224
- generateGoalReasoning(pattern) {
225
- const evidence = pattern.evidence.join(". ");
226
- return `Based on analysis: ${evidence}. Confidence: ${(pattern.confidence * 100).toFixed(0)}%`;
227
- }
228
- /**
229
- * Auto-generate goals and create them (with auto-generated status)
230
- *
231
- * Returns goals that need user acceptance.
232
- */
233
- async autoGenerateGoals() {
234
- const opportunities = await this.generateGoalOpportunities();
235
- const createdGoals = [];
236
- for (const opportunity of opportunities) {
237
- const goal = {
238
- id: `goal-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
239
- ...opportunity.goal,
240
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
241
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
242
- };
243
- await this.projectState.addGoal(goal);
244
- createdGoals.push(goal);
245
- if (this.insightStore.canCreateInsight("goal-suggestion")) {
246
- const insight = {
247
- id: `insight-goal-${goal.id}`,
248
- type: "suggestion",
249
- message: `New goal suggested: ${goal.description}`,
250
- context: opportunity.reasoning,
251
- suggestedAction: "Review and accept/reject this goal",
252
- relatedIssues: [],
253
- priority: 6,
254
- timestamp: Date.now(),
255
- dismissed: false,
256
- category: "progress",
257
- details: {
258
- examples: opportunity.pattern.evidence
259
- }
260
- };
261
- await this.insightStore.addInsight(insight);
262
- await this.insightStore.markInsightCreated("goal-suggestion");
263
- }
264
- }
265
- return createdGoals;
266
- }
267
- /**
268
- * Update goal progress based on current state
269
- */
270
- async updateGoalProgress() {
271
- await this.projectState.load();
272
- const activeGoals = this.projectState.getActiveGoals();
273
- for (const goal of activeGoals) {
274
- const currentValue = await this.measureGoalMetric(goal);
275
- await this.projectState.updateGoal(goal.id, { currentValue });
276
- if (!goal.autoGenerated) {
277
- console.debug(`[GoalManager] Skipping auto-achieve for user goal: "${goal.description.substring(0, 50)}..." (autoGenerated=${goal.autoGenerated})`);
278
- continue;
279
- }
280
- if (goal.autoGenerated !== true) {
281
- console.warn(`[GoalManager] SAFETY: Blocking auto-achieve for ambiguous goal: "${goal.description.substring(0, 50)}..." (autoGenerated=${goal.autoGenerated})`);
282
- continue;
283
- }
284
- if (this.isGoalAchieved(goal, currentValue)) {
285
- console.debug(`[GoalManager] Auto-achieving AI goal: "${goal.description.substring(0, 50)}..."`);
286
- await this.projectState.updateGoal(goal.id, {
287
- status: "achieved",
288
- achievedAt: (/* @__PURE__ */ new Date()).toISOString(),
289
- achievedBy: "agent",
290
- currentValue
291
- });
292
- try {
293
- const { getStorage } = await import("./tiered-storage-Z3YCR465.js");
294
- const storage = getStorage(this.projectPath);
295
- await storage.initialize();
296
- const resolved = await storage.resolveNudgesForGoal(goal.description);
297
- if (resolved > 0) {
298
- console.debug(`[GoalManager] Auto-resolved ${resolved} nudge(s) for achieved goal`);
299
- }
300
- } catch (e) {
301
- console.debug("[GoalManager] Failed to resolve nudges for achieved goal:", e);
302
- }
303
- await this.celebrateGoalAchievement(goal);
304
- }
305
- if (goal.deadline) {
306
- const deadline = new Date(goal.deadline);
307
- if (Date.now() > deadline.getTime() && !this.isGoalAchieved(goal, currentValue)) {
308
- await this.projectState.updateGoal(goal.id, {
309
- status: "failed",
310
- currentValue
311
- });
312
- }
313
- }
314
- }
315
- }
316
- /**
317
- * Measure the current value of a goal's metric
318
- *
319
- * Supports both structured metrics and semantic/natural language goals.
320
- * For custom goals, counts goal-violation issues that match this goal's description.
321
- */
322
- async measureGoalMetric(goal) {
323
- try {
324
- const issues = await searchIssues("", {
325
- workDir: this.projectPath,
326
- limit: 1e3,
327
- includeResolved: false
328
- });
329
- const goalViolations = issues.filter(
330
- (r) => r.issue.agent === "goal-violation" && r.issue.issue.includes(`Goal "${goal.description}"`)
331
- );
332
- if (goalViolations.length > 0) {
333
- return goalViolations.length;
334
- }
335
- if (goal.metric.endsWith("_issues")) {
336
- const prefix = goal.metric.replace("_issues", "");
337
- if (prefix.includes("/")) {
338
- return issues.filter((r) => r.issue.file.startsWith(prefix)).length;
339
- }
340
- return issues.filter((r) => r.issue.agent === prefix).length;
341
- }
342
- if (goal.metric === "critical_issues") {
343
- return issues.filter((r) => r.issue.severity === "critical").length;
344
- }
345
- const desc = goal.description.toLowerCase();
346
- const dirMatch = goal.description.match(/in\s+(?:the\s+)?(\S+?)(?:\s+(?:module|folder|directory|dir))?(?:\s|$)/i);
347
- if (dirMatch && dirMatch[1]) {
348
- const dirName = dirMatch[1].toLowerCase().replace(/[/\\]$/, "");
349
- const matchingIssues = issues.filter((r) => {
350
- const filePath = r.issue.file.toLowerCase();
351
- return filePath.includes(`/${dirName}/`) || filePath.includes(`\\${dirName}\\`) || filePath.startsWith(`${dirName}/`) || filePath.startsWith(`${dirName}\\`);
352
- });
353
- if (matchingIssues.length > 0 || desc.includes(dirName)) {
354
- return matchingIssues.length;
355
- }
356
- }
357
- if (desc.includes("dead code") || desc.includes("unused") || desc.includes("remove unused")) {
358
- const deadCodeIssues = issues.filter((r) => {
359
- const msg = r.issue.issue.toLowerCase();
360
- return msg.includes("unused") || msg.includes("dead code") || msg.includes("never used") || msg.includes("unreachable") || msg.includes("no-unused") || msg.includes("defined but never");
361
- });
362
- return deadCodeIssues.length;
363
- }
364
- if (desc.includes("security") || desc.includes("vulnerab") || desc.includes("fix security")) {
365
- const securityIssues = issues.filter(
366
- (r) => r.issue.agent === "security" || r.issue.severity === "critical"
367
- );
368
- return securityIssues.length;
369
- }
370
- if (desc.includes("type") || desc.includes("typescript") || desc.includes("any type")) {
371
- const typeIssues = issues.filter(
372
- (r) => r.issue.agent === "typecheck" || r.issue.issue.toLowerCase().includes("type") || r.issue.issue.toLowerCase().includes("any")
373
- );
374
- return typeIssues.length;
375
- }
376
- if (desc.includes("test") || desc.includes("coverage")) {
377
- const testIssues = issues.filter(
378
- (r) => r.issue.agent === "test" || r.issue.issue.toLowerCase().includes("test") || r.issue.issue.toLowerCase().includes("coverage")
379
- );
380
- return testIssues.length;
381
- }
382
- if (desc.includes("performance") || desc.includes("slow") || desc.includes("optimize")) {
383
- const perfIssues = issues.filter(
384
- (r) => r.issue.agent === "performance" || r.issue.issue.toLowerCase().includes("performance") || r.issue.issue.toLowerCase().includes("slow")
385
- );
386
- return perfIssues.length;
387
- }
388
- if (desc.includes("accessibility") || desc.includes("a11y") || desc.includes("accessible")) {
389
- const a11yIssues = issues.filter(
390
- (r) => r.issue.agent === "accessibility" || r.issue.issue.toLowerCase().includes("accessibility")
391
- );
392
- return a11yIssues.length;
393
- }
394
- if (desc.includes("bug") || desc.includes("fix") || desc.includes("error")) {
395
- const bugIssues = issues.filter(
396
- (r) => r.issue.agent === "bug-finding" || r.issue.severity === "critical" || r.issue.severity === "serious"
397
- );
398
- return bugIssues.length;
399
- }
400
- if (desc.includes("quality") || desc.includes("clean") || desc.includes("improve")) {
401
- return issues.length;
402
- }
403
- return issues.length;
404
- } catch {
405
- return goal.currentValue;
406
- }
407
- }
408
- /**
409
- * Check if a goal has been achieved
410
- */
411
- isGoalAchieved(goal, currentValue) {
412
- switch (goal.type) {
413
- case "reduction":
414
- return currentValue <= goal.target;
415
- case "score":
416
- return currentValue >= goal.target;
417
- case "streak":
418
- return currentValue >= goal.target;
419
- default:
420
- return currentValue <= goal.target;
421
- }
422
- }
423
- /**
424
- * Create a celebration insight for goal achievement
425
- */
426
- async celebrateGoalAchievement(goal) {
427
- const resolvedDetails = await this.getResolvedIssuesForGoal(goal);
428
- if (goal.startValue === void 0 || goal.startValue === null) {
429
- throw new Error(`Goal ${goal.id} missing startValue`);
430
- }
431
- if (goal.currentValue === void 0 || goal.currentValue === null) {
432
- throw new Error(`Goal ${goal.id} missing currentValue`);
433
- }
434
- if (goal.target === void 0 || goal.target === null) {
435
- throw new Error(`Goal ${goal.id} missing target`);
436
- }
437
- for (let i = 0; i < resolvedDetails.length; i++) {
438
- const issue = resolvedDetails[i];
439
- if (!issue) {
440
- throw new Error(`Resolved issue at index ${i} is null/undefined`);
441
- }
442
- if (!issue.file) {
443
- throw new Error(`Resolved issue at index ${i} missing file field`);
444
- }
445
- if (!issue.issue) {
446
- throw new Error(`Resolved issue at index ${i} missing issue description`);
447
- }
448
- if (!issue.agent) {
449
- throw new Error(`Resolved issue at index ${i} missing agent field`);
450
- }
451
- }
452
- const insight = {
453
- id: `insight-achieved-${goal.id}`,
454
- type: "celebration",
455
- message: `Goal achieved: ${goal.description}!`,
456
- context: `Started at ${goal.startValue}, now at ${goal.currentValue}. Target was ${goal.target}.`,
457
- relatedIssues: [],
458
- priority: 8,
459
- timestamp: Date.now(),
460
- dismissed: false,
461
- category: "progress",
462
- details: {
463
- resolvedCount: resolvedDetails.length,
464
- resolvedIssues: resolvedDetails.slice(0, 20).map((issue) => ({
465
- file: issue.file,
466
- line: issue.line,
467
- issue: issue.issue,
468
- agent: issue.agent,
469
- resolvedAt: issue.resolvedAt
470
- })),
471
- summary: resolvedDetails.length > 0 ? `Resolved ${resolvedDetails.length} issue${resolvedDetails.length > 1 ? "s" : ""} matching this goal` : "Progress tracked via metric reduction"
472
- }
473
- };
474
- if (!insight.details) {
475
- throw new Error("Failed to create details object for goal achievement insight");
476
- }
477
- if (insight.details.resolvedCount === void 0) {
478
- throw new Error("resolvedCount is undefined in goal achievement insight");
479
- }
480
- if (insight.details.resolvedCount > 0 && (!insight.details.resolvedIssues || insight.details.resolvedIssues.length === 0)) {
481
- throw new Error(`resolvedCount is ${insight.details.resolvedCount} but resolvedIssues array is empty`);
482
- }
483
- if (insight.details.resolvedCount !== insight.details.resolvedIssues?.length) {
484
- throw new Error(`resolvedCount (${insight.details.resolvedCount}) doesn't match resolvedIssues length (${insight.details.resolvedIssues?.length})`);
485
- }
486
- await this.insightStore.addInsight(insight);
487
- }
488
- /**
489
- * Get resolved issues that match a goal's metric pattern
490
- */
491
- async getResolvedIssuesForGoal(goal) {
492
- try {
493
- const allResolved = await searchIssues("", {
494
- workDir: this.projectPath,
495
- limit: 1e3,
496
- includeResolved: true
497
- });
498
- const resolved = allResolved.map((r) => r.issue).filter((issue) => issue.resolved === true);
499
- const desc = goal.description.toLowerCase();
500
- const metric = goal.metric.toLowerCase();
501
- let matchingResolved = resolved;
502
- if (metric.endsWith("_issues")) {
503
- const prefix = metric.replace("_issues", "");
504
- if (prefix.includes("/")) {
505
- matchingResolved = resolved.filter((i) => i.file.startsWith(prefix));
506
- } else {
507
- matchingResolved = resolved.filter((i) => i.agent === prefix);
508
- }
509
- } else if (metric === "critical_issues") {
510
- matchingResolved = resolved.filter((i) => i.severity === "critical");
511
- } else {
512
- if (desc.includes("dead code") || desc.includes("unused") || desc.includes("remove unused")) {
513
- matchingResolved = resolved.filter((i) => {
514
- const msg = i.issue.toLowerCase();
515
- return msg.includes("unused") || msg.includes("dead code") || msg.includes("never used") || msg.includes("unreachable") || msg.includes("no-unused") || msg.includes("defined but never");
516
- });
517
- } else if (desc.includes("security") || desc.includes("vulnerab") || desc.includes("fix security")) {
518
- matchingResolved = resolved.filter(
519
- (i) => i.agent === "security" || i.severity === "critical"
520
- );
521
- } else if (desc.includes("type") || desc.includes("typescript") || desc.includes("any type")) {
522
- matchingResolved = resolved.filter(
523
- (i) => i.agent === "typecheck" || i.issue.toLowerCase().includes("type") || i.issue.toLowerCase().includes("any")
524
- );
525
- } else if (desc.includes("test") || desc.includes("coverage")) {
526
- matchingResolved = resolved.filter(
527
- (i) => i.agent === "test" || i.issue.toLowerCase().includes("test") || i.issue.toLowerCase().includes("coverage")
528
- );
529
- } else if (desc.includes("performance") || desc.includes("slow") || desc.includes("optimize")) {
530
- matchingResolved = resolved.filter(
531
- (i) => i.agent === "performance" || i.issue.toLowerCase().includes("performance") || i.issue.toLowerCase().includes("slow")
532
- );
533
- } else if (desc.includes("accessibility") || desc.includes("a11y") || desc.includes("accessible")) {
534
- matchingResolved = resolved.filter(
535
- (i) => i.agent === "accessibility" || i.issue.toLowerCase().includes("accessibility")
536
- );
537
- } else if (desc.includes("bug") || desc.includes("fix") || desc.includes("error")) {
538
- matchingResolved = resolved.filter(
539
- (i) => i.agent === "bug-finding" || i.severity === "critical" || i.severity === "serious"
540
- );
541
- }
542
- }
543
- const goalCreatedAt = new Date(goal.createdAt).getTime();
544
- const goalAchievedAt = goal.achievedAt ? new Date(goal.achievedAt).getTime() : Date.now();
545
- return matchingResolved.filter((issue) => {
546
- if (!issue.resolvedAt) return false;
547
- const resolvedAt = new Date(issue.resolvedAt).getTime();
548
- return resolvedAt >= goalCreatedAt && resolvedAt <= goalAchievedAt;
549
- }).sort((a, b) => {
550
- const aTime = a.resolvedAt ? new Date(a.resolvedAt).getTime() : 0;
551
- const bTime = b.resolvedAt ? new Date(b.resolvedAt).getTime() : 0;
552
- return bTime - aTime;
553
- });
554
- } catch {
555
- return [];
556
- }
557
- }
558
- /**
559
- * Accept an auto-generated goal
560
- */
561
- async acceptGoal(goalId) {
562
- return this.projectState.respondToGoal(goalId, true);
563
- }
564
- /**
565
- * Reject an auto-generated goal
566
- */
567
- async rejectGoal(goalId) {
568
- return this.projectState.respondToGoal(goalId, false);
569
- }
570
- /**
571
- * Get pending auto-generated goals (awaiting acceptance)
572
- */
573
- getPendingGoals() {
574
- return this.projectState.getAutoGeneratedGoals().filter((g) => g.status === "active");
575
- }
576
- /**
577
- * Get goal progress summary
578
- */
579
- getGoalProgressSummary() {
580
- const goals = this.projectState.getAllGoals();
581
- return {
582
- active: goals.filter((g) => g.status === "active").length,
583
- achieved: goals.filter((g) => g.status === "achieved").length,
584
- failed: goals.filter((g) => g.status === "failed").length,
585
- pending: goals.filter((g) => g.autoGenerated && g.status === "active").length
586
- };
587
- }
588
- };
589
- async function calculateAdaptiveScanFrequency(projectPath) {
590
- const projectState = getProjectState(projectPath);
591
- await projectState.load();
592
- try {
593
- const stats = await getMemoryStats(projectPath);
594
- const issues = await searchIssues("", {
595
- workDir: projectPath,
596
- limit: 100,
597
- includeResolved: false
598
- });
599
- const criticalCount = issues.filter((r) => r.issue.severity === "critical").length;
600
- const seriousCount = issues.filter((r) => r.issue.severity === "serious").length;
601
- if (criticalCount >= 3) {
602
- return {
603
- frequencyMs: 6e4,
604
- reason: `${criticalCount} critical issues detected - scanning frequently`
605
- };
606
- }
607
- if (criticalCount > 0 || seriousCount >= 5) {
608
- return {
609
- frequencyMs: 12e4,
610
- reason: `Critical or many serious issues - elevated scan frequency`
611
- };
612
- }
613
- if (seriousCount > 0) {
614
- return {
615
- frequencyMs: 18e4,
616
- reason: `${seriousCount} serious issues - moderate scan frequency`
617
- };
618
- }
619
- if (stats.totalIssues > 10) {
620
- return {
621
- frequencyMs: 3e5,
622
- reason: "Some issues present - standard scan frequency"
623
- };
624
- }
625
- return {
626
- frequencyMs: 6e5,
627
- reason: "Code looks good - relaxed scan frequency"
628
- };
629
- } catch {
630
- return {
631
- frequencyMs: 3e5,
632
- reason: "Default scan frequency (5 min)"
633
- };
634
- }
635
- }
636
- async function adaptScanFrequency(projectPath) {
637
- const projectState = getProjectState(projectPath);
638
- const { frequencyMs } = await calculateAdaptiveScanFrequency(projectPath);
639
- await projectState.setScanFrequency(frequencyMs);
640
- return frequencyMs;
641
- }
642
- var goalManagers = /* @__PURE__ */ new Map();
643
- function getGoalManager(projectPath) {
644
- let manager = goalManagers.get(projectPath);
645
- if (!manager) {
646
- manager = new GoalManager(projectPath);
647
- goalManagers.set(projectPath, manager);
648
- }
649
- return manager;
650
- }
651
- function clearGoalManagers() {
652
- goalManagers.clear();
653
- }
654
-
655
- export {
656
- GoalManager,
657
- calculateAdaptiveScanFrequency,
658
- adaptScanFrequency,
659
- getGoalManager,
660
- clearGoalManagers
661
- };
662
- //# sourceMappingURL=chunk-MRHKX5M5.js.map