@triedotdev/mcp 1.0.113 → 1.0.115
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/dist/auto-fix-apply-PCAHWLXF.js +10 -0
- package/dist/autonomy-config-JXB7WCZ2.js +30 -0
- package/dist/chunk-2GIAROBF.js +173 -0
- package/dist/chunk-2GIAROBF.js.map +1 -0
- package/dist/{chunk-33WL3D7A.js → chunk-2SIFK7OW.js} +7 -419
- package/dist/chunk-2SIFK7OW.js.map +1 -0
- package/dist/chunk-43X6JBEM.js +36 -0
- package/dist/chunk-43X6JBEM.js.map +1 -0
- package/dist/chunk-55DOQNHJ.js +772 -0
- package/dist/chunk-55DOQNHJ.js.map +1 -0
- package/dist/chunk-6LXSA2OZ.js +425 -0
- package/dist/chunk-6LXSA2OZ.js.map +1 -0
- package/dist/{chunk-SDS3UVFY.js → chunk-AOFYU6T3.js} +113 -559
- package/dist/chunk-AOFYU6T3.js.map +1 -0
- package/dist/{chunk-6QR6QZIX.js → chunk-D3EXBJE2.js} +25 -658
- package/dist/chunk-D3EXBJE2.js.map +1 -0
- package/dist/chunk-DJ2YAGHK.js +50 -0
- package/dist/chunk-DJ2YAGHK.js.map +1 -0
- package/dist/chunk-DZREHOGW.js +706 -0
- package/dist/chunk-DZREHOGW.js.map +1 -0
- package/dist/chunk-I2GFI3AM.js +340 -0
- package/dist/chunk-I2GFI3AM.js.map +1 -0
- package/dist/chunk-KRH642MT.js +947 -0
- package/dist/chunk-KRH642MT.js.map +1 -0
- package/dist/{chunk-QYOACM2C.js → chunk-MVNJPJBK.js} +22 -252
- package/dist/chunk-MVNJPJBK.js.map +1 -0
- package/dist/chunk-NS2MSZMB.js +394 -0
- package/dist/chunk-NS2MSZMB.js.map +1 -0
- package/dist/chunk-SWSK7ANT.js +340 -0
- package/dist/chunk-SWSK7ANT.js.map +1 -0
- package/dist/chunk-VRLMTOB6.js +566 -0
- package/dist/chunk-VRLMTOB6.js.map +1 -0
- package/dist/chunk-YR4BMGYO.js +130 -0
- package/dist/chunk-YR4BMGYO.js.map +1 -0
- package/dist/chunk-ZV2K6M7T.js +74 -0
- package/dist/chunk-ZV2K6M7T.js.map +1 -0
- package/dist/{chunk-2764KZZQ.js → chunk-ZYKEILVK.js} +451 -1069
- package/dist/chunk-ZYKEILVK.js.map +1 -0
- package/dist/cli/main.js +107 -375
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/yolo-daemon.js +18 -8
- package/dist/cli/yolo-daemon.js.map +1 -1
- package/dist/client-7XZHCMD3.js +28 -0
- package/dist/client-7XZHCMD3.js.map +1 -0
- package/dist/{goal-manager-AP4LTE6U.js → goal-manager-LMS6ZJB7.js} +7 -3
- package/dist/goal-manager-LMS6ZJB7.js.map +1 -0
- package/dist/goal-validator-T5HEYBC5.js +186 -0
- package/dist/goal-validator-T5HEYBC5.js.map +1 -0
- package/dist/graph-U5JWSAB5.js +10 -0
- package/dist/graph-U5JWSAB5.js.map +1 -0
- package/dist/guardian-agent-EXP7APLC.js +25 -0
- package/dist/guardian-agent-EXP7APLC.js.map +1 -0
- package/dist/hypothesis-KGC3P54C.js +19 -0
- package/dist/hypothesis-KGC3P54C.js.map +1 -0
- package/dist/incident-index-PNIVT47T.js +11 -0
- package/dist/incident-index-PNIVT47T.js.map +1 -0
- package/dist/index.js +369 -43
- package/dist/index.js.map +1 -1
- package/dist/ledger-SR6OEBLO.js +15 -0
- package/dist/ledger-SR6OEBLO.js.map +1 -0
- package/dist/output-manager-BOTMXSND.js +13 -0
- package/dist/output-manager-BOTMXSND.js.map +1 -0
- package/dist/pattern-discovery-F7LU5K6E.js +8 -0
- package/dist/pattern-discovery-F7LU5K6E.js.map +1 -0
- package/package.json +1 -1
- package/dist/chunk-2764KZZQ.js.map +0 -1
- package/dist/chunk-33WL3D7A.js.map +0 -1
- package/dist/chunk-6JPPYG7F.js +0 -1813
- package/dist/chunk-6JPPYG7F.js.map +0 -1
- package/dist/chunk-6QR6QZIX.js.map +0 -1
- package/dist/chunk-QYOACM2C.js.map +0 -1
- package/dist/chunk-SDS3UVFY.js.map +0 -1
- package/dist/guardian-agent-XEYNG7RH.js +0 -18
- /package/dist/{goal-manager-AP4LTE6U.js.map → auto-fix-apply-PCAHWLXF.js.map} +0 -0
- /package/dist/{guardian-agent-XEYNG7RH.js.map → autonomy-config-JXB7WCZ2.js.map} +0 -0
|
@@ -0,0 +1,947 @@
|
|
|
1
|
+
import {
|
|
2
|
+
atomicWriteJSON
|
|
3
|
+
} from "./chunk-43X6JBEM.js";
|
|
4
|
+
import {
|
|
5
|
+
getTrieDirectory
|
|
6
|
+
} from "./chunk-R4AAPFXC.js";
|
|
7
|
+
|
|
8
|
+
// src/guardian/guardian-state.ts
|
|
9
|
+
import { mkdir, readFile as readFile2 } from "fs/promises";
|
|
10
|
+
import { existsSync as existsSync2 } from "fs";
|
|
11
|
+
import { join as join2 } from "path";
|
|
12
|
+
import { z as z2 } from "zod";
|
|
13
|
+
|
|
14
|
+
// src/utils/backup-manager.ts
|
|
15
|
+
import { copyFile, readdir, unlink, readFile, stat } from "fs/promises";
|
|
16
|
+
import { existsSync } from "fs";
|
|
17
|
+
import { dirname, basename, join } from "path";
|
|
18
|
+
var BackupManager = class {
|
|
19
|
+
filePath;
|
|
20
|
+
maxBackups;
|
|
21
|
+
validator;
|
|
22
|
+
backupDir;
|
|
23
|
+
baseFileName;
|
|
24
|
+
constructor(filePath, options = {}) {
|
|
25
|
+
this.filePath = filePath;
|
|
26
|
+
this.maxBackups = options.maxBackups ?? 5;
|
|
27
|
+
this.validator = options.validator;
|
|
28
|
+
this.backupDir = dirname(filePath);
|
|
29
|
+
this.baseFileName = basename(filePath);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Create a backup of the current file
|
|
33
|
+
*
|
|
34
|
+
* @returns The backup file path, or null if source doesn't exist
|
|
35
|
+
*/
|
|
36
|
+
async createBackup() {
|
|
37
|
+
if (!existsSync(this.filePath)) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
const timestamp = Date.now();
|
|
41
|
+
const backupPath = this.getBackupPath(timestamp);
|
|
42
|
+
await copyFile(this.filePath, backupPath);
|
|
43
|
+
await this.pruneOldBackups();
|
|
44
|
+
return backupPath;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* List all backups sorted by timestamp (newest first)
|
|
48
|
+
*/
|
|
49
|
+
async listBackups() {
|
|
50
|
+
if (!existsSync(this.backupDir)) {
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
const files = await readdir(this.backupDir);
|
|
54
|
+
const backupPattern = new RegExp(
|
|
55
|
+
`^${this.escapeRegex(this.baseFileName)}\\.backup\\.(\\d+)$`
|
|
56
|
+
);
|
|
57
|
+
const backups = [];
|
|
58
|
+
for (const file of files) {
|
|
59
|
+
const match = file.match(backupPattern);
|
|
60
|
+
if (match) {
|
|
61
|
+
const timestamp = parseInt(match[1], 10);
|
|
62
|
+
const backupPath = join(this.backupDir, file);
|
|
63
|
+
try {
|
|
64
|
+
const stats = await stat(backupPath);
|
|
65
|
+
backups.push({
|
|
66
|
+
path: backupPath,
|
|
67
|
+
timestamp,
|
|
68
|
+
size: stats.size
|
|
69
|
+
});
|
|
70
|
+
} catch {
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return backups.sort((a, b) => b.timestamp - a.timestamp);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Find the first valid backup
|
|
78
|
+
*
|
|
79
|
+
* Iterates through backups from newest to oldest,
|
|
80
|
+
* returning the first one that passes validation.
|
|
81
|
+
*
|
|
82
|
+
* @returns Path to valid backup, or null if none found
|
|
83
|
+
*/
|
|
84
|
+
async findValidBackup() {
|
|
85
|
+
const backups = await this.listBackups();
|
|
86
|
+
for (const backup of backups) {
|
|
87
|
+
if (await this.validateBackup(backup.path)) {
|
|
88
|
+
return backup.path;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Validate a backup file
|
|
95
|
+
*
|
|
96
|
+
* If a custom validator was provided, uses that.
|
|
97
|
+
* Otherwise, attempts JSON parse for .json files.
|
|
98
|
+
*
|
|
99
|
+
* @returns true if backup is valid
|
|
100
|
+
*/
|
|
101
|
+
async validateBackup(backupPath) {
|
|
102
|
+
try {
|
|
103
|
+
const content = await readFile(backupPath, "utf-8");
|
|
104
|
+
if (this.validator) {
|
|
105
|
+
return this.validator(content);
|
|
106
|
+
}
|
|
107
|
+
if (this.filePath.endsWith(".json")) {
|
|
108
|
+
JSON.parse(content);
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
return content.length > 0;
|
|
112
|
+
} catch {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Recover from the most recent valid backup
|
|
118
|
+
*
|
|
119
|
+
* @returns true if recovery was successful
|
|
120
|
+
*/
|
|
121
|
+
async recoverFromBackup() {
|
|
122
|
+
const validBackup = await this.findValidBackup();
|
|
123
|
+
if (!validBackup) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
await copyFile(validBackup, this.filePath);
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Remove old backups beyond the max limit
|
|
131
|
+
*/
|
|
132
|
+
async pruneOldBackups() {
|
|
133
|
+
const backups = await this.listBackups();
|
|
134
|
+
const toRemove = backups.slice(this.maxBackups);
|
|
135
|
+
for (const backup of toRemove) {
|
|
136
|
+
try {
|
|
137
|
+
await unlink(backup.path);
|
|
138
|
+
} catch {
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Get the backup path for a given timestamp
|
|
144
|
+
*/
|
|
145
|
+
getBackupPath(timestamp) {
|
|
146
|
+
return join(this.backupDir, `${this.baseFileName}.backup.${timestamp}`);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Escape special regex characters in a string
|
|
150
|
+
*/
|
|
151
|
+
escapeRegex(str) {
|
|
152
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Get the number of existing backups
|
|
156
|
+
*/
|
|
157
|
+
async getBackupCount() {
|
|
158
|
+
const backups = await this.listBackups();
|
|
159
|
+
return backups.length;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Get the most recent backup timestamp
|
|
163
|
+
*/
|
|
164
|
+
async getLatestBackupTime() {
|
|
165
|
+
const backups = await this.listBackups();
|
|
166
|
+
return backups[0]?.timestamp ?? null;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Delete all backups
|
|
170
|
+
*/
|
|
171
|
+
async clearBackups() {
|
|
172
|
+
const backups = await this.listBackups();
|
|
173
|
+
let deleted = 0;
|
|
174
|
+
for (const backup of backups) {
|
|
175
|
+
try {
|
|
176
|
+
await unlink(backup.path);
|
|
177
|
+
deleted++;
|
|
178
|
+
} catch {
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return deleted;
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
// src/memory/validation.ts
|
|
186
|
+
import { z } from "zod";
|
|
187
|
+
var StoredIssueSchema = z.object({
|
|
188
|
+
id: z.string(),
|
|
189
|
+
hash: z.string(),
|
|
190
|
+
severity: z.string(),
|
|
191
|
+
issue: z.string(),
|
|
192
|
+
fix: z.string(),
|
|
193
|
+
file: z.string(),
|
|
194
|
+
line: z.number().optional(),
|
|
195
|
+
agent: z.string(),
|
|
196
|
+
category: z.string().optional(),
|
|
197
|
+
timestamp: z.string(),
|
|
198
|
+
project: z.string(),
|
|
199
|
+
resolved: z.boolean().optional(),
|
|
200
|
+
resolvedAt: z.string().optional()
|
|
201
|
+
});
|
|
202
|
+
var IssueIndexSchema = z.array(StoredIssueSchema);
|
|
203
|
+
var FixAppliedSchema = z.object({
|
|
204
|
+
project: z.string(),
|
|
205
|
+
timestamp: z.string(),
|
|
206
|
+
fix: z.string()
|
|
207
|
+
});
|
|
208
|
+
var GlobalPatternSchema = z.object({
|
|
209
|
+
id: z.string(),
|
|
210
|
+
pattern: z.string(),
|
|
211
|
+
description: z.string(),
|
|
212
|
+
severity: z.string(),
|
|
213
|
+
agent: z.string(),
|
|
214
|
+
occurrences: z.number(),
|
|
215
|
+
projects: z.array(z.string()),
|
|
216
|
+
firstSeen: z.string(),
|
|
217
|
+
lastSeen: z.string(),
|
|
218
|
+
fixApplied: FixAppliedSchema.optional()
|
|
219
|
+
});
|
|
220
|
+
var GlobalPatternsIndexSchema = z.array(GlobalPatternSchema);
|
|
221
|
+
var ProjectSummarySchema = z.object({
|
|
222
|
+
name: z.string(),
|
|
223
|
+
path: z.string(),
|
|
224
|
+
lastScan: z.string(),
|
|
225
|
+
healthScore: z.number(),
|
|
226
|
+
totalIssues: z.number(),
|
|
227
|
+
patterns: z.array(z.string())
|
|
228
|
+
});
|
|
229
|
+
var PatternSummarySchema = z.object({
|
|
230
|
+
pattern: z.string(),
|
|
231
|
+
count: z.number(),
|
|
232
|
+
severity: z.string(),
|
|
233
|
+
agent: z.string(),
|
|
234
|
+
exampleFix: z.string()
|
|
235
|
+
});
|
|
236
|
+
var HotFileSchema = z.object({
|
|
237
|
+
file: z.string(),
|
|
238
|
+
count: z.number()
|
|
239
|
+
});
|
|
240
|
+
var CompactedSummarySchema = z.object({
|
|
241
|
+
period: z.string(),
|
|
242
|
+
startDate: z.string(),
|
|
243
|
+
endDate: z.string(),
|
|
244
|
+
totalIssues: z.number(),
|
|
245
|
+
resolvedCount: z.number(),
|
|
246
|
+
bySeverity: z.record(z.string(), z.number()),
|
|
247
|
+
byAgent: z.record(z.string(), z.number()),
|
|
248
|
+
topPatterns: z.array(PatternSummarySchema),
|
|
249
|
+
hotFiles: z.array(HotFileSchema),
|
|
250
|
+
compactedAt: z.string()
|
|
251
|
+
});
|
|
252
|
+
var CompactedSummariesIndexSchema = z.array(CompactedSummarySchema);
|
|
253
|
+
function safeParseAndValidate(content, schema) {
|
|
254
|
+
try {
|
|
255
|
+
const parsed = JSON.parse(content);
|
|
256
|
+
const result = schema.safeParse(parsed);
|
|
257
|
+
if (result.success) {
|
|
258
|
+
return { success: true, data: result.data };
|
|
259
|
+
}
|
|
260
|
+
return {
|
|
261
|
+
success: false,
|
|
262
|
+
error: `Validation failed: ${result.error.issues[0]?.message || "Unknown error"}`
|
|
263
|
+
};
|
|
264
|
+
} catch (error) {
|
|
265
|
+
return {
|
|
266
|
+
success: false,
|
|
267
|
+
error: `JSON parse failed: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// src/guardian/guardian-state.ts
|
|
273
|
+
var GoalSchema = z2.object({
|
|
274
|
+
id: z2.string(),
|
|
275
|
+
description: z2.string(),
|
|
276
|
+
type: z2.enum(["streak", "reduction", "score", "custom"]),
|
|
277
|
+
metric: z2.string(),
|
|
278
|
+
target: z2.number(),
|
|
279
|
+
currentValue: z2.number(),
|
|
280
|
+
startValue: z2.number().optional(),
|
|
281
|
+
status: z2.enum(["active", "achieved", "failed", "paused", "rejected"]),
|
|
282
|
+
autoGenerated: z2.boolean(),
|
|
283
|
+
confidence: z2.number().min(0).max(1).optional(),
|
|
284
|
+
// For auto-generated goals
|
|
285
|
+
createdAt: z2.string(),
|
|
286
|
+
updatedAt: z2.string(),
|
|
287
|
+
achievedAt: z2.string().optional(),
|
|
288
|
+
deadline: z2.string().optional(),
|
|
289
|
+
category: z2.enum(["security", "quality", "performance", "coverage", "general"]).optional(),
|
|
290
|
+
evidence: z2.array(z2.string()).optional(),
|
|
291
|
+
// Why this goal was generated
|
|
292
|
+
metadata: z2.record(z2.any()).optional()
|
|
293
|
+
// Track caught/fixed counts and other metadata
|
|
294
|
+
});
|
|
295
|
+
var HypothesisSchema = z2.object({
|
|
296
|
+
id: z2.string(),
|
|
297
|
+
statement: z2.string(),
|
|
298
|
+
confidence: z2.number().min(0).max(1),
|
|
299
|
+
// 0-1, adjusts based on validation
|
|
300
|
+
status: z2.enum(["proposed", "testing", "validated", "invalidated", "retired"]),
|
|
301
|
+
evidence: z2.array(z2.object({
|
|
302
|
+
type: z2.enum(["supporting", "contradicting"]),
|
|
303
|
+
description: z2.string(),
|
|
304
|
+
timestamp: z2.string(),
|
|
305
|
+
weight: z2.number().min(0).max(1).optional()
|
|
306
|
+
})),
|
|
307
|
+
createdAt: z2.string(),
|
|
308
|
+
updatedAt: z2.string(),
|
|
309
|
+
validatedAt: z2.string().optional(),
|
|
310
|
+
testCriteria: z2.string().optional(),
|
|
311
|
+
category: z2.enum(["timing", "pattern", "team", "code", "general"]).optional()
|
|
312
|
+
});
|
|
313
|
+
var RiskBudgetSchema = z2.object({
|
|
314
|
+
daily: z2.number(),
|
|
315
|
+
weekly: z2.number(),
|
|
316
|
+
usedToday: z2.number(),
|
|
317
|
+
usedThisWeek: z2.number(),
|
|
318
|
+
lastResetDay: z2.string(),
|
|
319
|
+
// ISO date (YYYY-MM-DD)
|
|
320
|
+
lastResetWeek: z2.string()
|
|
321
|
+
// ISO week (YYYY-WNN)
|
|
322
|
+
});
|
|
323
|
+
var AgentMetricsSchema = z2.object({
|
|
324
|
+
predictiveAccuracy: z2.number().min(0).max(1),
|
|
325
|
+
falsePositiveRate: z2.number().min(0).max(1),
|
|
326
|
+
userSatisfaction: z2.number().min(0).max(1),
|
|
327
|
+
hypothesisAccuracy: z2.number().min(0).max(1),
|
|
328
|
+
totalPredictions: z2.number(),
|
|
329
|
+
correctPredictions: z2.number(),
|
|
330
|
+
totalInsights: z2.number(),
|
|
331
|
+
helpfulInsights: z2.number(),
|
|
332
|
+
dismissedInsights: z2.number(),
|
|
333
|
+
actedOnInsights: z2.number()
|
|
334
|
+
});
|
|
335
|
+
var TimingContextSchema = z2.object({
|
|
336
|
+
quietHoursStart: z2.number().min(0).max(23),
|
|
337
|
+
// Hour of day (0-23)
|
|
338
|
+
quietHoursEnd: z2.number().min(0).max(23),
|
|
339
|
+
quietHoursEnabled: z2.boolean(),
|
|
340
|
+
workDays: z2.array(z2.number().min(0).max(6)),
|
|
341
|
+
// 0 = Sunday
|
|
342
|
+
lastActiveTimestamp: z2.number(),
|
|
343
|
+
timezone: z2.string().optional(),
|
|
344
|
+
crunchMode: z2.boolean(),
|
|
345
|
+
// During crunch, defer low-priority items
|
|
346
|
+
crunchModeUntil: z2.string().optional()
|
|
347
|
+
});
|
|
348
|
+
var GuardianStateDataSchema = z2.object({
|
|
349
|
+
version: z2.literal(1),
|
|
350
|
+
goals: z2.array(GoalSchema),
|
|
351
|
+
hypotheses: z2.array(HypothesisSchema),
|
|
352
|
+
riskBudget: RiskBudgetSchema,
|
|
353
|
+
metrics: AgentMetricsSchema,
|
|
354
|
+
timing: TimingContextSchema,
|
|
355
|
+
scanFrequencyMs: z2.number(),
|
|
356
|
+
// Current scan frequency
|
|
357
|
+
lastScanTimestamp: z2.number().optional(),
|
|
358
|
+
lastUpdated: z2.string()
|
|
359
|
+
});
|
|
360
|
+
var GuardianState = class {
|
|
361
|
+
projectPath;
|
|
362
|
+
data;
|
|
363
|
+
loaded = false;
|
|
364
|
+
dirty = false;
|
|
365
|
+
constructor(projectPath) {
|
|
366
|
+
this.projectPath = projectPath;
|
|
367
|
+
this.data = this.createDefaultState();
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Get the storage file path
|
|
371
|
+
*/
|
|
372
|
+
getStorePath() {
|
|
373
|
+
return join2(getTrieDirectory(this.projectPath), "memory", "guardian-state.json");
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Create default state
|
|
377
|
+
*/
|
|
378
|
+
createDefaultState() {
|
|
379
|
+
const now = /* @__PURE__ */ new Date();
|
|
380
|
+
const today = now.toISOString().split("T")[0];
|
|
381
|
+
const week = this.getISOWeek(now);
|
|
382
|
+
return {
|
|
383
|
+
version: 1,
|
|
384
|
+
goals: [],
|
|
385
|
+
hypotheses: [],
|
|
386
|
+
riskBudget: {
|
|
387
|
+
daily: 10,
|
|
388
|
+
weekly: 50,
|
|
389
|
+
usedToday: 0,
|
|
390
|
+
usedThisWeek: 0,
|
|
391
|
+
lastResetDay: today,
|
|
392
|
+
lastResetWeek: week
|
|
393
|
+
},
|
|
394
|
+
metrics: {
|
|
395
|
+
predictiveAccuracy: 0.5,
|
|
396
|
+
// Start neutral
|
|
397
|
+
falsePositiveRate: 0.5,
|
|
398
|
+
userSatisfaction: 0.5,
|
|
399
|
+
hypothesisAccuracy: 0.5,
|
|
400
|
+
totalPredictions: 0,
|
|
401
|
+
correctPredictions: 0,
|
|
402
|
+
totalInsights: 0,
|
|
403
|
+
helpfulInsights: 0,
|
|
404
|
+
dismissedInsights: 0,
|
|
405
|
+
actedOnInsights: 0
|
|
406
|
+
},
|
|
407
|
+
timing: {
|
|
408
|
+
quietHoursStart: 21,
|
|
409
|
+
// 9 PM
|
|
410
|
+
quietHoursEnd: 8,
|
|
411
|
+
// 8 AM
|
|
412
|
+
quietHoursEnabled: true,
|
|
413
|
+
workDays: [1, 2, 3, 4, 5],
|
|
414
|
+
// Mon-Fri
|
|
415
|
+
lastActiveTimestamp: Date.now(),
|
|
416
|
+
crunchMode: false
|
|
417
|
+
},
|
|
418
|
+
scanFrequencyMs: 3e5,
|
|
419
|
+
// 5 minutes default
|
|
420
|
+
lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Get ISO week string (YYYY-WNN)
|
|
425
|
+
*/
|
|
426
|
+
getISOWeek(date) {
|
|
427
|
+
const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
|
|
428
|
+
const dayNum = d.getUTCDay() || 7;
|
|
429
|
+
d.setUTCDate(d.getUTCDate() + 4 - dayNum);
|
|
430
|
+
const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
|
|
431
|
+
const weekNo = Math.ceil(((d.getTime() - yearStart.getTime()) / 864e5 + 1) / 7);
|
|
432
|
+
return `${d.getUTCFullYear()}-W${weekNo.toString().padStart(2, "0")}`;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Load state from disk
|
|
436
|
+
*/
|
|
437
|
+
async load() {
|
|
438
|
+
if (this.loaded) {
|
|
439
|
+
return this.data;
|
|
440
|
+
}
|
|
441
|
+
const storePath = this.getStorePath();
|
|
442
|
+
try {
|
|
443
|
+
if (existsSync2(storePath)) {
|
|
444
|
+
const content = await readFile2(storePath, "utf-8");
|
|
445
|
+
const result = safeParseAndValidate(content, GuardianStateDataSchema);
|
|
446
|
+
if (result.success) {
|
|
447
|
+
this.data = result.data;
|
|
448
|
+
this.loaded = true;
|
|
449
|
+
await this.checkAndResetBudgets();
|
|
450
|
+
return this.data;
|
|
451
|
+
}
|
|
452
|
+
console.error(` Guardian state corrupted: ${result.error}`);
|
|
453
|
+
const backupManager = new BackupManager(storePath);
|
|
454
|
+
if (await backupManager.recoverFromBackup()) {
|
|
455
|
+
console.error(" \u2705 Recovered from backup");
|
|
456
|
+
const recovered = await readFile2(storePath, "utf-8");
|
|
457
|
+
const recoveredResult = safeParseAndValidate(recovered, GuardianStateDataSchema);
|
|
458
|
+
if (recoveredResult.success) {
|
|
459
|
+
this.data = recoveredResult.data;
|
|
460
|
+
this.loaded = true;
|
|
461
|
+
return this.data;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
console.error(" No valid backup found, starting fresh");
|
|
465
|
+
}
|
|
466
|
+
} catch (error) {
|
|
467
|
+
console.error(` Could not load guardian state: ${error}`);
|
|
468
|
+
}
|
|
469
|
+
this.data = this.createDefaultState();
|
|
470
|
+
this.loaded = true;
|
|
471
|
+
return this.data;
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Save state to disk
|
|
475
|
+
*/
|
|
476
|
+
async save() {
|
|
477
|
+
if (!this.dirty && this.loaded) {
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
const storePath = this.getStorePath();
|
|
481
|
+
const memoryDir = join2(getTrieDirectory(this.projectPath), "memory");
|
|
482
|
+
await mkdir(memoryDir, { recursive: true });
|
|
483
|
+
const backupManager = new BackupManager(storePath);
|
|
484
|
+
await backupManager.createBackup();
|
|
485
|
+
this.data.lastUpdated = (/* @__PURE__ */ new Date()).toISOString();
|
|
486
|
+
await atomicWriteJSON(storePath, this.data);
|
|
487
|
+
this.dirty = false;
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Check and reset daily/weekly budgets if needed
|
|
491
|
+
*/
|
|
492
|
+
async checkAndResetBudgets() {
|
|
493
|
+
const now = /* @__PURE__ */ new Date();
|
|
494
|
+
const today = now.toISOString().split("T")[0];
|
|
495
|
+
const week = this.getISOWeek(now);
|
|
496
|
+
let needsSave = false;
|
|
497
|
+
if (this.data.riskBudget.lastResetDay !== today) {
|
|
498
|
+
this.data.riskBudget.usedToday = 0;
|
|
499
|
+
this.data.riskBudget.lastResetDay = today;
|
|
500
|
+
needsSave = true;
|
|
501
|
+
}
|
|
502
|
+
if (this.data.riskBudget.lastResetWeek !== week) {
|
|
503
|
+
this.data.riskBudget.usedThisWeek = 0;
|
|
504
|
+
this.data.riskBudget.lastResetWeek = week;
|
|
505
|
+
needsSave = true;
|
|
506
|
+
}
|
|
507
|
+
if (needsSave) {
|
|
508
|
+
this.dirty = true;
|
|
509
|
+
await this.save();
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
// ========================================================================
|
|
513
|
+
// Goals
|
|
514
|
+
// ========================================================================
|
|
515
|
+
/**
|
|
516
|
+
* Add a goal
|
|
517
|
+
*/
|
|
518
|
+
async addGoal(goal) {
|
|
519
|
+
await this.load();
|
|
520
|
+
if (this.data.goals.some((g) => g.id === goal.id)) {
|
|
521
|
+
return false;
|
|
522
|
+
}
|
|
523
|
+
this.data.goals.push(goal);
|
|
524
|
+
this.dirty = true;
|
|
525
|
+
await this.save();
|
|
526
|
+
return true;
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Update a goal
|
|
530
|
+
*/
|
|
531
|
+
async updateGoal(goalId, updates) {
|
|
532
|
+
await this.load();
|
|
533
|
+
const goal = this.data.goals.find((g) => g.id === goalId);
|
|
534
|
+
if (!goal) {
|
|
535
|
+
return false;
|
|
536
|
+
}
|
|
537
|
+
Object.assign(goal, updates, { updatedAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
538
|
+
this.dirty = true;
|
|
539
|
+
await this.save();
|
|
540
|
+
return true;
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Get active goals
|
|
544
|
+
*/
|
|
545
|
+
getActiveGoals() {
|
|
546
|
+
return this.data.goals.filter((g) => g.status === "active");
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Get all goals
|
|
550
|
+
*/
|
|
551
|
+
getAllGoals() {
|
|
552
|
+
return [...this.data.goals];
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* Get goal by ID
|
|
556
|
+
*/
|
|
557
|
+
getGoal(goalId) {
|
|
558
|
+
return this.data.goals.find((g) => g.id === goalId);
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Remove a goal
|
|
562
|
+
*/
|
|
563
|
+
async removeGoal(goalId) {
|
|
564
|
+
await this.load();
|
|
565
|
+
const index = this.data.goals.findIndex((g) => g.id === goalId);
|
|
566
|
+
if (index === -1) {
|
|
567
|
+
return false;
|
|
568
|
+
}
|
|
569
|
+
this.data.goals.splice(index, 1);
|
|
570
|
+
this.dirty = true;
|
|
571
|
+
await this.save();
|
|
572
|
+
return true;
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* Get auto-generated goals
|
|
576
|
+
*/
|
|
577
|
+
getAutoGeneratedGoals() {
|
|
578
|
+
return this.data.goals.filter((g) => g.autoGenerated);
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Accept or reject an auto-generated goal
|
|
582
|
+
*/
|
|
583
|
+
async respondToGoal(goalId, accept) {
|
|
584
|
+
return this.updateGoal(goalId, {
|
|
585
|
+
status: accept ? "active" : "rejected"
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
// ========================================================================
|
|
589
|
+
// Hypotheses
|
|
590
|
+
// ========================================================================
|
|
591
|
+
/**
|
|
592
|
+
* Add a hypothesis
|
|
593
|
+
*/
|
|
594
|
+
async addHypothesis(hypothesis) {
|
|
595
|
+
await this.load();
|
|
596
|
+
if (this.data.hypotheses.some((h) => h.id === hypothesis.id)) {
|
|
597
|
+
return false;
|
|
598
|
+
}
|
|
599
|
+
this.data.hypotheses.push(hypothesis);
|
|
600
|
+
this.dirty = true;
|
|
601
|
+
await this.save();
|
|
602
|
+
return true;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Update a hypothesis
|
|
606
|
+
*/
|
|
607
|
+
async updateHypothesis(hypothesisId, updates) {
|
|
608
|
+
await this.load();
|
|
609
|
+
const hypothesis = this.data.hypotheses.find((h) => h.id === hypothesisId);
|
|
610
|
+
if (!hypothesis) {
|
|
611
|
+
return false;
|
|
612
|
+
}
|
|
613
|
+
Object.assign(hypothesis, updates, { updatedAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
614
|
+
this.dirty = true;
|
|
615
|
+
await this.save();
|
|
616
|
+
return true;
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* Add evidence to a hypothesis
|
|
620
|
+
*/
|
|
621
|
+
async addEvidence(hypothesisId, evidence) {
|
|
622
|
+
await this.load();
|
|
623
|
+
const hypothesis = this.data.hypotheses.find((h) => h.id === hypothesisId);
|
|
624
|
+
if (!hypothesis) {
|
|
625
|
+
return false;
|
|
626
|
+
}
|
|
627
|
+
hypothesis.evidence.push({
|
|
628
|
+
...evidence,
|
|
629
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
630
|
+
});
|
|
631
|
+
if (hypothesis.status === "proposed" && hypothesis.evidence.length === 1) {
|
|
632
|
+
hypothesis.status = "testing";
|
|
633
|
+
}
|
|
634
|
+
const supportingCount = hypothesis.evidence.filter((e) => e.type === "supporting").length;
|
|
635
|
+
const contradictingCount = hypothesis.evidence.filter((e) => e.type === "contradicting").length;
|
|
636
|
+
const total = supportingCount + contradictingCount;
|
|
637
|
+
if (total > 0) {
|
|
638
|
+
hypothesis.confidence = supportingCount / total;
|
|
639
|
+
if (hypothesis.status === "testing") {
|
|
640
|
+
if (hypothesis.confidence > 0.8 && supportingCount >= 3) {
|
|
641
|
+
hypothesis.status = "validated";
|
|
642
|
+
hypothesis.validatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
643
|
+
} else if (hypothesis.confidence < 0.2 && contradictingCount >= 3) {
|
|
644
|
+
hypothesis.status = "invalidated";
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
hypothesis.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
649
|
+
this.dirty = true;
|
|
650
|
+
await this.save();
|
|
651
|
+
return true;
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* Get active hypotheses
|
|
655
|
+
*/
|
|
656
|
+
getActiveHypotheses() {
|
|
657
|
+
return this.data.hypotheses.filter(
|
|
658
|
+
(h) => h.status === "proposed" || h.status === "testing"
|
|
659
|
+
);
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* Get validated hypotheses
|
|
663
|
+
*/
|
|
664
|
+
getValidatedHypotheses() {
|
|
665
|
+
return this.data.hypotheses.filter((h) => h.status === "validated");
|
|
666
|
+
}
|
|
667
|
+
/**
|
|
668
|
+
* Get all hypotheses
|
|
669
|
+
*/
|
|
670
|
+
getAllHypotheses() {
|
|
671
|
+
return [...this.data.hypotheses];
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
* Get hypothesis by ID
|
|
675
|
+
*/
|
|
676
|
+
getHypothesis(hypothesisId) {
|
|
677
|
+
return this.data.hypotheses.find((h) => h.id === hypothesisId);
|
|
678
|
+
}
|
|
679
|
+
// ========================================================================
|
|
680
|
+
// Risk Budget
|
|
681
|
+
// ========================================================================
|
|
682
|
+
/**
|
|
683
|
+
* Get current risk budget
|
|
684
|
+
*/
|
|
685
|
+
getRiskBudget() {
|
|
686
|
+
return { ...this.data.riskBudget };
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* Use risk budget
|
|
690
|
+
*/
|
|
691
|
+
async useRiskBudget(amount) {
|
|
692
|
+
await this.load();
|
|
693
|
+
await this.checkAndResetBudgets();
|
|
694
|
+
if (this.data.riskBudget.usedToday + amount > this.data.riskBudget.daily) {
|
|
695
|
+
return false;
|
|
696
|
+
}
|
|
697
|
+
if (this.data.riskBudget.usedThisWeek + amount > this.data.riskBudget.weekly) {
|
|
698
|
+
return false;
|
|
699
|
+
}
|
|
700
|
+
this.data.riskBudget.usedToday += amount;
|
|
701
|
+
this.data.riskBudget.usedThisWeek += amount;
|
|
702
|
+
this.dirty = true;
|
|
703
|
+
await this.save();
|
|
704
|
+
return true;
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* Check if risk budget is available
|
|
708
|
+
*/
|
|
709
|
+
hasRiskBudget(amount = 1) {
|
|
710
|
+
return this.data.riskBudget.usedToday + amount <= this.data.riskBudget.daily && this.data.riskBudget.usedThisWeek + amount <= this.data.riskBudget.weekly;
|
|
711
|
+
}
|
|
712
|
+
/**
|
|
713
|
+
* Update risk budget limits
|
|
714
|
+
*/
|
|
715
|
+
async setRiskBudget(daily, weekly) {
|
|
716
|
+
await this.load();
|
|
717
|
+
this.data.riskBudget.daily = daily;
|
|
718
|
+
this.data.riskBudget.weekly = weekly;
|
|
719
|
+
this.dirty = true;
|
|
720
|
+
await this.save();
|
|
721
|
+
}
|
|
722
|
+
// ========================================================================
|
|
723
|
+
// Metrics
|
|
724
|
+
// ========================================================================
|
|
725
|
+
/**
|
|
726
|
+
* Get agent metrics
|
|
727
|
+
*/
|
|
728
|
+
getMetrics() {
|
|
729
|
+
return { ...this.data.metrics };
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* Record a prediction outcome
|
|
733
|
+
*/
|
|
734
|
+
async recordPrediction(correct) {
|
|
735
|
+
await this.load();
|
|
736
|
+
this.data.metrics.totalPredictions++;
|
|
737
|
+
if (correct) {
|
|
738
|
+
this.data.metrics.correctPredictions++;
|
|
739
|
+
}
|
|
740
|
+
this.data.metrics.predictiveAccuracy = this.data.metrics.correctPredictions / this.data.metrics.totalPredictions;
|
|
741
|
+
this.dirty = true;
|
|
742
|
+
await this.save();
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* Record user feedback on an insight
|
|
746
|
+
*/
|
|
747
|
+
async recordInsightFeedback(feedback) {
|
|
748
|
+
await this.load();
|
|
749
|
+
this.data.metrics.totalInsights++;
|
|
750
|
+
switch (feedback) {
|
|
751
|
+
case "helpful":
|
|
752
|
+
this.data.metrics.helpfulInsights++;
|
|
753
|
+
break;
|
|
754
|
+
case "dismissed":
|
|
755
|
+
this.data.metrics.dismissedInsights++;
|
|
756
|
+
break;
|
|
757
|
+
case "acted":
|
|
758
|
+
this.data.metrics.actedOnInsights++;
|
|
759
|
+
this.data.metrics.helpfulInsights++;
|
|
760
|
+
break;
|
|
761
|
+
}
|
|
762
|
+
if (this.data.metrics.totalInsights > 0) {
|
|
763
|
+
this.data.metrics.userSatisfaction = this.data.metrics.helpfulInsights / this.data.metrics.totalInsights;
|
|
764
|
+
this.data.metrics.falsePositiveRate = this.data.metrics.dismissedInsights / this.data.metrics.totalInsights;
|
|
765
|
+
}
|
|
766
|
+
this.dirty = true;
|
|
767
|
+
await this.save();
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* Update hypothesis accuracy
|
|
771
|
+
*/
|
|
772
|
+
async updateHypothesisAccuracy() {
|
|
773
|
+
await this.load();
|
|
774
|
+
const validated = this.data.hypotheses.filter((h) => h.status === "validated").length;
|
|
775
|
+
const invalidated = this.data.hypotheses.filter((h) => h.status === "invalidated").length;
|
|
776
|
+
const total = validated + invalidated;
|
|
777
|
+
if (total > 0) {
|
|
778
|
+
this.data.metrics.hypothesisAccuracy = validated / total;
|
|
779
|
+
this.dirty = true;
|
|
780
|
+
await this.save();
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
// ========================================================================
|
|
784
|
+
// Timing Context
|
|
785
|
+
// ========================================================================
|
|
786
|
+
/**
|
|
787
|
+
* Get timing context
|
|
788
|
+
*/
|
|
789
|
+
getTimingContext() {
|
|
790
|
+
return { ...this.data.timing };
|
|
791
|
+
}
|
|
792
|
+
/**
|
|
793
|
+
* Check if currently in quiet hours
|
|
794
|
+
*/
|
|
795
|
+
isQuietHours() {
|
|
796
|
+
if (!this.data.timing.quietHoursEnabled) {
|
|
797
|
+
return false;
|
|
798
|
+
}
|
|
799
|
+
const now = /* @__PURE__ */ new Date();
|
|
800
|
+
const hour = now.getHours();
|
|
801
|
+
const start = this.data.timing.quietHoursStart;
|
|
802
|
+
const end = this.data.timing.quietHoursEnd;
|
|
803
|
+
if (start > end) {
|
|
804
|
+
return hour >= start || hour < end;
|
|
805
|
+
}
|
|
806
|
+
return hour >= start && hour < end;
|
|
807
|
+
}
|
|
808
|
+
/**
|
|
809
|
+
* Check if today is a work day
|
|
810
|
+
*/
|
|
811
|
+
isWorkDay() {
|
|
812
|
+
const dayOfWeek = (/* @__PURE__ */ new Date()).getDay();
|
|
813
|
+
return this.data.timing.workDays.includes(dayOfWeek);
|
|
814
|
+
}
|
|
815
|
+
/**
|
|
816
|
+
* Check if in crunch mode
|
|
817
|
+
*/
|
|
818
|
+
isInCrunchMode() {
|
|
819
|
+
if (!this.data.timing.crunchMode) {
|
|
820
|
+
return false;
|
|
821
|
+
}
|
|
822
|
+
if (this.data.timing.crunchModeUntil) {
|
|
823
|
+
const until = new Date(this.data.timing.crunchModeUntil);
|
|
824
|
+
if (Date.now() > until.getTime()) {
|
|
825
|
+
this.data.timing.crunchMode = false;
|
|
826
|
+
this.data.timing.crunchModeUntil = void 0;
|
|
827
|
+
this.dirty = true;
|
|
828
|
+
return false;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
return true;
|
|
832
|
+
}
|
|
833
|
+
/**
|
|
834
|
+
* Enable crunch mode
|
|
835
|
+
*/
|
|
836
|
+
async setCrunchMode(enabled, until) {
|
|
837
|
+
await this.load();
|
|
838
|
+
this.data.timing.crunchMode = enabled;
|
|
839
|
+
this.data.timing.crunchModeUntil = until?.toISOString();
|
|
840
|
+
this.dirty = true;
|
|
841
|
+
await this.save();
|
|
842
|
+
}
|
|
843
|
+
/**
|
|
844
|
+
* Update quiet hours settings
|
|
845
|
+
*/
|
|
846
|
+
async setQuietHours(start, end, enabled = true) {
|
|
847
|
+
await this.load();
|
|
848
|
+
this.data.timing.quietHoursStart = start;
|
|
849
|
+
this.data.timing.quietHoursEnd = end;
|
|
850
|
+
this.data.timing.quietHoursEnabled = enabled;
|
|
851
|
+
this.dirty = true;
|
|
852
|
+
await this.save();
|
|
853
|
+
}
|
|
854
|
+
/**
|
|
855
|
+
* Update work days
|
|
856
|
+
*/
|
|
857
|
+
async setWorkDays(days) {
|
|
858
|
+
await this.load();
|
|
859
|
+
this.data.timing.workDays = days;
|
|
860
|
+
this.dirty = true;
|
|
861
|
+
await this.save();
|
|
862
|
+
}
|
|
863
|
+
/**
|
|
864
|
+
* Update last active timestamp
|
|
865
|
+
*/
|
|
866
|
+
async touchActive() {
|
|
867
|
+
await this.load();
|
|
868
|
+
this.data.timing.lastActiveTimestamp = Date.now();
|
|
869
|
+
this.dirty = true;
|
|
870
|
+
await this.save();
|
|
871
|
+
}
|
|
872
|
+
// ========================================================================
|
|
873
|
+
// Scan Frequency
|
|
874
|
+
// ========================================================================
|
|
875
|
+
/**
|
|
876
|
+
* Get current scan frequency in milliseconds
|
|
877
|
+
*/
|
|
878
|
+
getScanFrequencyMs() {
|
|
879
|
+
return this.data.scanFrequencyMs;
|
|
880
|
+
}
|
|
881
|
+
/**
|
|
882
|
+
* Set scan frequency
|
|
883
|
+
*/
|
|
884
|
+
async setScanFrequency(ms) {
|
|
885
|
+
await this.load();
|
|
886
|
+
this.data.scanFrequencyMs = Math.max(1e4, ms);
|
|
887
|
+
this.dirty = true;
|
|
888
|
+
await this.save();
|
|
889
|
+
}
|
|
890
|
+
/**
|
|
891
|
+
* Record a scan timestamp
|
|
892
|
+
*/
|
|
893
|
+
async recordScan() {
|
|
894
|
+
await this.load();
|
|
895
|
+
this.data.lastScanTimestamp = Date.now();
|
|
896
|
+
this.dirty = true;
|
|
897
|
+
await this.save();
|
|
898
|
+
}
|
|
899
|
+
/**
|
|
900
|
+
* Get last scan timestamp
|
|
901
|
+
*/
|
|
902
|
+
getLastScanTimestamp() {
|
|
903
|
+
return this.data.lastScanTimestamp;
|
|
904
|
+
}
|
|
905
|
+
// ========================================================================
|
|
906
|
+
// Utility
|
|
907
|
+
// ========================================================================
|
|
908
|
+
/**
|
|
909
|
+
* Get full state data
|
|
910
|
+
*/
|
|
911
|
+
getData() {
|
|
912
|
+
return { ...this.data };
|
|
913
|
+
}
|
|
914
|
+
/**
|
|
915
|
+
* Force reload from disk
|
|
916
|
+
*/
|
|
917
|
+
async reload() {
|
|
918
|
+
this.loaded = false;
|
|
919
|
+
this.dirty = false;
|
|
920
|
+
return this.load();
|
|
921
|
+
}
|
|
922
|
+
/**
|
|
923
|
+
* Check if loaded
|
|
924
|
+
*/
|
|
925
|
+
isLoaded() {
|
|
926
|
+
return this.loaded;
|
|
927
|
+
}
|
|
928
|
+
};
|
|
929
|
+
var guardianStates = /* @__PURE__ */ new Map();
|
|
930
|
+
function getGuardianState(projectPath) {
|
|
931
|
+
let state = guardianStates.get(projectPath);
|
|
932
|
+
if (!state) {
|
|
933
|
+
state = new GuardianState(projectPath);
|
|
934
|
+
guardianStates.set(projectPath, state);
|
|
935
|
+
}
|
|
936
|
+
return state;
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
export {
|
|
940
|
+
BackupManager,
|
|
941
|
+
IssueIndexSchema,
|
|
942
|
+
GlobalPatternsIndexSchema,
|
|
943
|
+
CompactedSummariesIndexSchema,
|
|
944
|
+
safeParseAndValidate,
|
|
945
|
+
getGuardianState
|
|
946
|
+
};
|
|
947
|
+
//# sourceMappingURL=chunk-KRH642MT.js.map
|