@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,700 +0,0 @@
1
- import {
2
- BackupManager,
3
- safeParseAndValidate
4
- } from "./chunk-EFWVF6TI.js";
5
- import {
6
- atomicWriteJSON
7
- } from "./chunk-43X6JBEM.js";
8
- import {
9
- getTrieDirectory
10
- } from "./chunk-VVITXIHN.js";
11
-
12
- // src/agent/project-state.ts
13
- import { mkdir, readFile } from "fs/promises";
14
- import { existsSync } from "fs";
15
- import { join } from "path";
16
- import { z } from "zod";
17
- var GoalSchema = z.object({
18
- id: z.string(),
19
- description: z.string(),
20
- type: z.enum(["streak", "reduction", "score", "custom"]),
21
- metric: z.string(),
22
- target: z.number(),
23
- currentValue: z.number(),
24
- startValue: z.number().optional(),
25
- status: z.enum(["active", "achieved", "failed", "paused", "rejected"]),
26
- autoGenerated: z.boolean(),
27
- confidence: z.number().min(0).max(1).optional(),
28
- // For auto-generated goals
29
- createdAt: z.string(),
30
- updatedAt: z.string(),
31
- achievedAt: z.string().optional(),
32
- achievedBy: z.enum(["user", "agent"]).optional(),
33
- deadline: z.string().optional(),
34
- category: z.enum(["security", "quality", "performance", "coverage", "general"]).optional(),
35
- evidence: z.array(z.string()).optional(),
36
- // Why this goal was generated
37
- metadata: z.record(z.any()).optional()
38
- // Track caught/fixed counts and other metadata
39
- });
40
- var HypothesisSchema = z.object({
41
- id: z.string(),
42
- statement: z.string(),
43
- confidence: z.number().min(0).max(1),
44
- // 0-1, adjusts based on validation
45
- status: z.enum(["proposed", "testing", "validated", "invalidated", "retired"]),
46
- evidence: z.array(z.object({
47
- type: z.enum(["supporting", "contradicting"]),
48
- description: z.string(),
49
- timestamp: z.string(),
50
- weight: z.number().min(0).max(1).optional()
51
- })),
52
- createdAt: z.string(),
53
- updatedAt: z.string(),
54
- validatedAt: z.string().optional(),
55
- validatedBy: z.enum(["user", "agent"]).optional(),
56
- testCriteria: z.string().optional(),
57
- category: z.enum(["timing", "pattern", "team", "code", "general"]).optional(),
58
- autoGenerated: z.boolean().optional()
59
- });
60
- var RiskBudgetSchema = z.object({
61
- daily: z.number(),
62
- weekly: z.number(),
63
- usedToday: z.number(),
64
- usedThisWeek: z.number(),
65
- lastResetDay: z.string(),
66
- // ISO date (YYYY-MM-DD)
67
- lastResetWeek: z.string()
68
- // ISO week (YYYY-WNN)
69
- });
70
- var AgentMetricsSchema = z.object({
71
- predictiveAccuracy: z.number().min(0).max(1),
72
- falsePositiveRate: z.number().min(0).max(1),
73
- userSatisfaction: z.number().min(0).max(1),
74
- hypothesisAccuracy: z.number().min(0).max(1),
75
- totalPredictions: z.number(),
76
- correctPredictions: z.number(),
77
- totalInsights: z.number(),
78
- helpfulInsights: z.number(),
79
- dismissedInsights: z.number(),
80
- actedOnInsights: z.number()
81
- });
82
- var TimingContextSchema = z.object({
83
- quietHoursStart: z.number().min(0).max(23),
84
- // Hour of day (0-23)
85
- quietHoursEnd: z.number().min(0).max(23),
86
- quietHoursEnabled: z.boolean(),
87
- workDays: z.array(z.number().min(0).max(6)),
88
- // 0 = Sunday
89
- lastActiveTimestamp: z.number(),
90
- timezone: z.string().optional(),
91
- crunchMode: z.boolean(),
92
- // During crunch, defer low-priority items
93
- crunchModeUntil: z.string().optional()
94
- });
95
- var ProjectStateDataSchema = z.object({
96
- version: z.literal(1),
97
- goals: z.array(GoalSchema),
98
- hypotheses: z.array(HypothesisSchema),
99
- riskBudget: RiskBudgetSchema,
100
- metrics: AgentMetricsSchema,
101
- timing: TimingContextSchema,
102
- scanFrequencyMs: z.number(),
103
- // Current scan frequency
104
- lastScanTimestamp: z.number().optional(),
105
- lastUpdated: z.string()
106
- });
107
- var ProjectState = class {
108
- projectPath;
109
- data;
110
- loaded = false;
111
- dirty = false;
112
- constructor(projectPath) {
113
- this.projectPath = projectPath;
114
- this.data = this.createDefaultState();
115
- }
116
- /**
117
- * Get the storage file path
118
- */
119
- getStorePath() {
120
- return join(getTrieDirectory(this.projectPath), "memory", "state.json");
121
- }
122
- /**
123
- * Create default state
124
- */
125
- createDefaultState() {
126
- const now = /* @__PURE__ */ new Date();
127
- const today = now.toISOString().split("T")[0];
128
- const week = this.getISOWeek(now);
129
- return {
130
- version: 1,
131
- goals: [],
132
- hypotheses: [],
133
- riskBudget: {
134
- daily: 10,
135
- weekly: 50,
136
- usedToday: 0,
137
- usedThisWeek: 0,
138
- lastResetDay: today,
139
- lastResetWeek: week
140
- },
141
- metrics: {
142
- predictiveAccuracy: 0.5,
143
- // Start neutral
144
- falsePositiveRate: 0.5,
145
- userSatisfaction: 0.5,
146
- hypothesisAccuracy: 0.5,
147
- totalPredictions: 0,
148
- correctPredictions: 0,
149
- totalInsights: 0,
150
- helpfulInsights: 0,
151
- dismissedInsights: 0,
152
- actedOnInsights: 0
153
- },
154
- timing: {
155
- quietHoursStart: 21,
156
- // 9 PM
157
- quietHoursEnd: 8,
158
- // 8 AM
159
- quietHoursEnabled: true,
160
- workDays: [1, 2, 3, 4, 5],
161
- // Mon-Fri
162
- lastActiveTimestamp: Date.now(),
163
- crunchMode: false
164
- },
165
- scanFrequencyMs: 3e5,
166
- // 5 minutes default
167
- lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
168
- };
169
- }
170
- /**
171
- * Get ISO week string (YYYY-WNN)
172
- */
173
- getISOWeek(date) {
174
- const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
175
- const dayNum = d.getUTCDay() || 7;
176
- d.setUTCDate(d.getUTCDate() + 4 - dayNum);
177
- const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
178
- const weekNo = Math.ceil(((d.getTime() - yearStart.getTime()) / 864e5 + 1) / 7);
179
- return `${d.getUTCFullYear()}-W${weekNo.toString().padStart(2, "0")}`;
180
- }
181
- /**
182
- * Load state from disk
183
- */
184
- async load() {
185
- if (this.loaded) {
186
- return this.data;
187
- }
188
- const storePath = this.getStorePath();
189
- try {
190
- if (existsSync(storePath)) {
191
- const content = await readFile(storePath, "utf-8");
192
- const result = safeParseAndValidate(content, ProjectStateDataSchema);
193
- if (result.success) {
194
- this.data = result.data;
195
- this.loaded = true;
196
- await this.checkAndResetBudgets();
197
- return this.data;
198
- }
199
- console.error(` State corrupted: ${result.error}`);
200
- const backupManager = new BackupManager(storePath);
201
- if (await backupManager.recoverFromBackup()) {
202
- console.error(" \u2705 Recovered from backup");
203
- const recovered = await readFile(storePath, "utf-8");
204
- const recoveredResult = safeParseAndValidate(recovered, ProjectStateDataSchema);
205
- if (recoveredResult.success) {
206
- this.data = recoveredResult.data;
207
- this.loaded = true;
208
- return this.data;
209
- }
210
- }
211
- console.error(" No valid backup found, starting fresh");
212
- }
213
- } catch (error) {
214
- console.error(` Could not load state: ${error}`);
215
- }
216
- this.data = this.createDefaultState();
217
- this.loaded = true;
218
- return this.data;
219
- }
220
- /**
221
- * Save state to disk
222
- */
223
- async save() {
224
- if (!this.dirty && this.loaded) {
225
- return;
226
- }
227
- const storePath = this.getStorePath();
228
- const memoryDir = join(getTrieDirectory(this.projectPath), "memory");
229
- await mkdir(memoryDir, { recursive: true });
230
- const backupManager = new BackupManager(storePath);
231
- await backupManager.createBackup();
232
- this.data.lastUpdated = (/* @__PURE__ */ new Date()).toISOString();
233
- await atomicWriteJSON(storePath, this.data);
234
- this.dirty = false;
235
- }
236
- /**
237
- * Check and reset daily/weekly budgets if needed
238
- */
239
- async checkAndResetBudgets() {
240
- const now = /* @__PURE__ */ new Date();
241
- const today = now.toISOString().split("T")[0];
242
- const week = this.getISOWeek(now);
243
- let needsSave = false;
244
- if (this.data.riskBudget.lastResetDay !== today) {
245
- this.data.riskBudget.usedToday = 0;
246
- this.data.riskBudget.lastResetDay = today;
247
- needsSave = true;
248
- }
249
- if (this.data.riskBudget.lastResetWeek !== week) {
250
- this.data.riskBudget.usedThisWeek = 0;
251
- this.data.riskBudget.lastResetWeek = week;
252
- needsSave = true;
253
- }
254
- if (needsSave) {
255
- this.dirty = true;
256
- await this.save();
257
- }
258
- }
259
- // ========================================================================
260
- // Goals
261
- // ========================================================================
262
- /**
263
- * Add a goal
264
- */
265
- async addGoal(goal) {
266
- await this.load();
267
- if (this.data.goals.some((g) => g.id === goal.id)) {
268
- return false;
269
- }
270
- this.data.goals.push(goal);
271
- this.dirty = true;
272
- await this.save();
273
- return true;
274
- }
275
- /**
276
- * Update a goal
277
- */
278
- async updateGoal(goalId, updates) {
279
- await this.load();
280
- const goal = this.data.goals.find((g) => g.id === goalId);
281
- if (!goal) {
282
- return false;
283
- }
284
- Object.assign(goal, updates, { updatedAt: (/* @__PURE__ */ new Date()).toISOString() });
285
- this.dirty = true;
286
- await this.save();
287
- return true;
288
- }
289
- /**
290
- * Get active goals
291
- */
292
- getActiveGoals() {
293
- return this.data.goals.filter((g) => g.status === "active");
294
- }
295
- /**
296
- * Get all goals
297
- */
298
- getAllGoals() {
299
- return [...this.data.goals];
300
- }
301
- /**
302
- * Get goal by ID
303
- */
304
- getGoal(goalId) {
305
- return this.data.goals.find((g) => g.id === goalId);
306
- }
307
- /**
308
- * Remove a goal
309
- */
310
- async removeGoal(goalId) {
311
- await this.load();
312
- const index = this.data.goals.findIndex((g) => g.id === goalId);
313
- if (index === -1) {
314
- return false;
315
- }
316
- this.data.goals.splice(index, 1);
317
- this.dirty = true;
318
- await this.save();
319
- return true;
320
- }
321
- /**
322
- * Get auto-generated goals
323
- */
324
- getAutoGeneratedGoals() {
325
- return this.data.goals.filter((g) => g.autoGenerated);
326
- }
327
- /**
328
- * Accept or reject an auto-generated goal
329
- */
330
- async respondToGoal(goalId, accept) {
331
- return this.updateGoal(goalId, {
332
- status: accept ? "active" : "rejected"
333
- });
334
- }
335
- // ========================================================================
336
- // Hypotheses
337
- // ========================================================================
338
- /**
339
- * Add a hypothesis
340
- */
341
- async addHypothesis(hypothesis) {
342
- await this.load();
343
- if (this.data.hypotheses.some((h) => h.id === hypothesis.id)) {
344
- return false;
345
- }
346
- this.data.hypotheses.push(hypothesis);
347
- this.dirty = true;
348
- await this.save();
349
- return true;
350
- }
351
- /**
352
- * Update a hypothesis
353
- */
354
- async updateHypothesis(hypothesisId, updates) {
355
- await this.load();
356
- const hypothesis = this.data.hypotheses.find((h) => h.id === hypothesisId);
357
- if (!hypothesis) {
358
- return false;
359
- }
360
- Object.assign(hypothesis, updates, { updatedAt: (/* @__PURE__ */ new Date()).toISOString() });
361
- this.dirty = true;
362
- await this.save();
363
- return true;
364
- }
365
- /**
366
- * Add evidence to a hypothesis
367
- */
368
- async addEvidence(hypothesisId, evidence) {
369
- await this.load();
370
- const hypothesis = this.data.hypotheses.find((h) => h.id === hypothesisId);
371
- if (!hypothesis) {
372
- return false;
373
- }
374
- hypothesis.evidence.push({
375
- ...evidence,
376
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
377
- });
378
- if (hypothesis.status === "proposed" && hypothesis.evidence.length === 1) {
379
- hypothesis.status = "testing";
380
- }
381
- const supportingCount = hypothesis.evidence.filter((e) => e.type === "supporting").length;
382
- const contradictingCount = hypothesis.evidence.filter((e) => e.type === "contradicting").length;
383
- const total = supportingCount + contradictingCount;
384
- if (total > 0) {
385
- hypothesis.confidence = supportingCount / total;
386
- if (hypothesis.status === "testing") {
387
- if (hypothesis.confidence > 0.8 && supportingCount >= 3) {
388
- hypothesis.status = "validated";
389
- hypothesis.validatedAt = (/* @__PURE__ */ new Date()).toISOString();
390
- } else if (hypothesis.confidence < 0.2 && contradictingCount >= 3) {
391
- hypothesis.status = "invalidated";
392
- }
393
- }
394
- }
395
- hypothesis.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
396
- this.dirty = true;
397
- await this.save();
398
- return true;
399
- }
400
- /**
401
- * Get active hypotheses
402
- */
403
- getActiveHypotheses() {
404
- return this.data.hypotheses.filter(
405
- (h) => h.status === "proposed" || h.status === "testing"
406
- );
407
- }
408
- /**
409
- * Get validated hypotheses
410
- */
411
- getValidatedHypotheses() {
412
- return this.data.hypotheses.filter((h) => h.status === "validated");
413
- }
414
- /**
415
- * Get all hypotheses
416
- */
417
- getAllHypotheses() {
418
- return [...this.data.hypotheses];
419
- }
420
- /**
421
- * Get hypothesis by ID
422
- */
423
- getHypothesis(hypothesisId) {
424
- return this.data.hypotheses.find((h) => h.id === hypothesisId);
425
- }
426
- // ========================================================================
427
- // Risk Budget
428
- // ========================================================================
429
- /**
430
- * Get current risk budget
431
- */
432
- getRiskBudget() {
433
- return { ...this.data.riskBudget };
434
- }
435
- /**
436
- * Use risk budget
437
- */
438
- async useRiskBudget(amount) {
439
- await this.load();
440
- await this.checkAndResetBudgets();
441
- if (this.data.riskBudget.usedToday + amount > this.data.riskBudget.daily) {
442
- return false;
443
- }
444
- if (this.data.riskBudget.usedThisWeek + amount > this.data.riskBudget.weekly) {
445
- return false;
446
- }
447
- this.data.riskBudget.usedToday += amount;
448
- this.data.riskBudget.usedThisWeek += amount;
449
- this.dirty = true;
450
- await this.save();
451
- return true;
452
- }
453
- /**
454
- * Check if risk budget is available
455
- */
456
- hasRiskBudget(amount = 1) {
457
- return this.data.riskBudget.usedToday + amount <= this.data.riskBudget.daily && this.data.riskBudget.usedThisWeek + amount <= this.data.riskBudget.weekly;
458
- }
459
- /**
460
- * Update risk budget limits
461
- */
462
- async setRiskBudget(daily, weekly) {
463
- await this.load();
464
- this.data.riskBudget.daily = daily;
465
- this.data.riskBudget.weekly = weekly;
466
- this.dirty = true;
467
- await this.save();
468
- }
469
- // ========================================================================
470
- // Metrics
471
- // ========================================================================
472
- /**
473
- * Get agent metrics
474
- */
475
- getMetrics() {
476
- return { ...this.data.metrics };
477
- }
478
- /**
479
- * Record a prediction outcome
480
- */
481
- async recordPrediction(correct) {
482
- await this.load();
483
- this.data.metrics.totalPredictions++;
484
- if (correct) {
485
- this.data.metrics.correctPredictions++;
486
- }
487
- this.data.metrics.predictiveAccuracy = this.data.metrics.correctPredictions / this.data.metrics.totalPredictions;
488
- this.dirty = true;
489
- await this.save();
490
- }
491
- /**
492
- * Record user feedback on an insight
493
- */
494
- async recordInsightFeedback(feedback) {
495
- await this.load();
496
- this.data.metrics.totalInsights++;
497
- switch (feedback) {
498
- case "helpful":
499
- this.data.metrics.helpfulInsights++;
500
- break;
501
- case "dismissed":
502
- this.data.metrics.dismissedInsights++;
503
- break;
504
- case "acted":
505
- this.data.metrics.actedOnInsights++;
506
- this.data.metrics.helpfulInsights++;
507
- break;
508
- }
509
- if (this.data.metrics.totalInsights > 0) {
510
- this.data.metrics.userSatisfaction = this.data.metrics.helpfulInsights / this.data.metrics.totalInsights;
511
- this.data.metrics.falsePositiveRate = this.data.metrics.dismissedInsights / this.data.metrics.totalInsights;
512
- }
513
- this.dirty = true;
514
- await this.save();
515
- }
516
- /**
517
- * Update hypothesis accuracy
518
- */
519
- async updateHypothesisAccuracy() {
520
- await this.load();
521
- const validated = this.data.hypotheses.filter((h) => h.status === "validated").length;
522
- const invalidated = this.data.hypotheses.filter((h) => h.status === "invalidated").length;
523
- const total = validated + invalidated;
524
- if (total > 0) {
525
- this.data.metrics.hypothesisAccuracy = validated / total;
526
- this.dirty = true;
527
- await this.save();
528
- }
529
- }
530
- // ========================================================================
531
- // Timing Context
532
- // ========================================================================
533
- /**
534
- * Get timing context
535
- */
536
- getTimingContext() {
537
- return { ...this.data.timing };
538
- }
539
- /**
540
- * Check if currently in quiet hours
541
- */
542
- isQuietHours() {
543
- if (!this.data.timing.quietHoursEnabled) {
544
- return false;
545
- }
546
- const now = /* @__PURE__ */ new Date();
547
- const hour = now.getHours();
548
- const start = this.data.timing.quietHoursStart;
549
- const end = this.data.timing.quietHoursEnd;
550
- if (start > end) {
551
- return hour >= start || hour < end;
552
- }
553
- return hour >= start && hour < end;
554
- }
555
- /**
556
- * Check if today is a work day
557
- */
558
- isWorkDay() {
559
- const dayOfWeek = (/* @__PURE__ */ new Date()).getDay();
560
- return this.data.timing.workDays.includes(dayOfWeek);
561
- }
562
- /**
563
- * Check if in crunch mode
564
- */
565
- isInCrunchMode() {
566
- if (!this.data.timing.crunchMode) {
567
- return false;
568
- }
569
- if (this.data.timing.crunchModeUntil) {
570
- const until = new Date(this.data.timing.crunchModeUntil);
571
- if (Date.now() > until.getTime()) {
572
- this.data.timing.crunchMode = false;
573
- this.data.timing.crunchModeUntil = void 0;
574
- this.dirty = true;
575
- return false;
576
- }
577
- }
578
- return true;
579
- }
580
- /**
581
- * Enable crunch mode
582
- */
583
- async setCrunchMode(enabled, until) {
584
- await this.load();
585
- this.data.timing.crunchMode = enabled;
586
- this.data.timing.crunchModeUntil = until?.toISOString();
587
- this.dirty = true;
588
- await this.save();
589
- }
590
- /**
591
- * Update quiet hours settings
592
- */
593
- async setQuietHours(start, end, enabled = true) {
594
- await this.load();
595
- this.data.timing.quietHoursStart = start;
596
- this.data.timing.quietHoursEnd = end;
597
- this.data.timing.quietHoursEnabled = enabled;
598
- this.dirty = true;
599
- await this.save();
600
- }
601
- /**
602
- * Update work days
603
- */
604
- async setWorkDays(days) {
605
- await this.load();
606
- this.data.timing.workDays = days;
607
- this.dirty = true;
608
- await this.save();
609
- }
610
- /**
611
- * Update last active timestamp
612
- */
613
- async touchActive() {
614
- await this.load();
615
- this.data.timing.lastActiveTimestamp = Date.now();
616
- this.dirty = true;
617
- await this.save();
618
- }
619
- // ========================================================================
620
- // Scan Frequency
621
- // ========================================================================
622
- /**
623
- * Get current scan frequency in milliseconds
624
- */
625
- getScanFrequencyMs() {
626
- return this.data.scanFrequencyMs;
627
- }
628
- /**
629
- * Set scan frequency
630
- */
631
- async setScanFrequency(ms) {
632
- await this.load();
633
- this.data.scanFrequencyMs = Math.max(1e4, ms);
634
- this.dirty = true;
635
- await this.save();
636
- }
637
- /**
638
- * Record a scan timestamp
639
- */
640
- async recordScan() {
641
- await this.load();
642
- this.data.lastScanTimestamp = Date.now();
643
- this.dirty = true;
644
- await this.save();
645
- }
646
- /**
647
- * Get last scan timestamp
648
- */
649
- getLastScanTimestamp() {
650
- return this.data.lastScanTimestamp;
651
- }
652
- // ========================================================================
653
- // Utility
654
- // ========================================================================
655
- /**
656
- * Get full state data
657
- */
658
- getData() {
659
- return { ...this.data };
660
- }
661
- /**
662
- * Force reload from disk
663
- */
664
- async reload() {
665
- this.loaded = false;
666
- this.dirty = false;
667
- return this.load();
668
- }
669
- /**
670
- * Check if loaded
671
- */
672
- isLoaded() {
673
- return this.loaded;
674
- }
675
- };
676
- var projectStates = /* @__PURE__ */ new Map();
677
- function getProjectState(projectPath) {
678
- let state = projectStates.get(projectPath);
679
- if (!state) {
680
- state = new ProjectState(projectPath);
681
- projectStates.set(projectPath, state);
682
- }
683
- return state;
684
- }
685
- function clearProjectStates() {
686
- projectStates.clear();
687
- }
688
-
689
- export {
690
- GoalSchema,
691
- HypothesisSchema,
692
- RiskBudgetSchema,
693
- AgentMetricsSchema,
694
- TimingContextSchema,
695
- ProjectStateDataSchema,
696
- ProjectState,
697
- getProjectState,
698
- clearProjectStates
699
- };
700
- //# sourceMappingURL=chunk-GTKYBOXL.js.map