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