@triedotdev/mcp 1.0.125 → 1.0.127
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/chunk-6VIMBFUZ.js +216 -0
- package/dist/chunk-6VIMBFUZ.js.map +1 -0
- package/dist/{chunk-BNVH2LY7.js → chunk-WBNYLTW6.js} +164 -56
- package/dist/chunk-WBNYLTW6.js.map +1 -0
- package/dist/cli/yolo-daemon.js +1 -1
- package/dist/codebase-index-CR6Q2HEI.js +12 -0
- package/dist/codebase-index-CR6Q2HEI.js.map +1 -0
- package/dist/goal-validator-NLOJJ7FF.js +291 -0
- package/dist/goal-validator-NLOJJ7FF.js.map +1 -0
- package/dist/index.js +157 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-BNVH2LY7.js.map +0 -1
- package/dist/goal-validator-CKFKJ46J.js +0 -188
- package/dist/goal-validator-CKFKJ46J.js.map +0 -1
package/dist/cli/yolo-daemon.js
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CodebaseIndex
|
|
3
|
+
} from "./chunk-6VIMBFUZ.js";
|
|
4
|
+
import "./chunk-6NLHFIYA.js";
|
|
5
|
+
import "./chunk-43X6JBEM.js";
|
|
6
|
+
import "./chunk-45Y5TLQZ.js";
|
|
7
|
+
import "./chunk-APMV77PU.js";
|
|
8
|
+
import "./chunk-DGUM43GV.js";
|
|
9
|
+
export {
|
|
10
|
+
CodebaseIndex
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=codebase-index-CR6Q2HEI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getGuardianState
|
|
3
|
+
} from "./chunk-UHMMANC2.js";
|
|
4
|
+
import "./chunk-WS6OA7H6.js";
|
|
5
|
+
import "./chunk-43X6JBEM.js";
|
|
6
|
+
import "./chunk-45Y5TLQZ.js";
|
|
7
|
+
import "./chunk-APMV77PU.js";
|
|
8
|
+
import "./chunk-DGUM43GV.js";
|
|
9
|
+
|
|
10
|
+
// src/guardian/goal-validator.ts
|
|
11
|
+
async function getActiveGoals(projectPath) {
|
|
12
|
+
const guardianState = getGuardianState(projectPath);
|
|
13
|
+
await guardianState.load();
|
|
14
|
+
return guardianState.getAllGoals().filter((g) => g.status === "active");
|
|
15
|
+
}
|
|
16
|
+
async function recordGoalViolationCaught(goal, file, projectPath) {
|
|
17
|
+
const guardianState = getGuardianState(projectPath);
|
|
18
|
+
await guardianState.load();
|
|
19
|
+
const metadata = goal.metadata || {};
|
|
20
|
+
const caughtCount = (metadata.caughtCount || 0) + 1;
|
|
21
|
+
await guardianState.updateGoal(goal.id, {
|
|
22
|
+
metadata: {
|
|
23
|
+
...metadata,
|
|
24
|
+
caughtCount,
|
|
25
|
+
lastCaught: (/* @__PURE__ */ new Date()).toISOString(),
|
|
26
|
+
lastCaughtFile: file
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async function recordGoalViolationFixed(goal, file, projectPath) {
|
|
31
|
+
const guardianState = getGuardianState(projectPath);
|
|
32
|
+
await guardianState.load();
|
|
33
|
+
const metadata = goal.metadata || {};
|
|
34
|
+
const caughtCount = (metadata.caughtCount || 0) + 1;
|
|
35
|
+
const fixedCount = (metadata.fixedCount || 0) + 1;
|
|
36
|
+
await guardianState.updateGoal(goal.id, {
|
|
37
|
+
metadata: {
|
|
38
|
+
...metadata,
|
|
39
|
+
caughtCount,
|
|
40
|
+
fixedCount,
|
|
41
|
+
lastFixed: (/* @__PURE__ */ new Date()).toISOString(),
|
|
42
|
+
lastFixedFile: file
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
if (goal.type === "reduction") {
|
|
46
|
+
const newValue = Math.max(0, goal.currentValue - 1);
|
|
47
|
+
await guardianState.updateGoal(goal.id, {
|
|
48
|
+
currentValue: newValue
|
|
49
|
+
});
|
|
50
|
+
if (newValue <= goal.target) {
|
|
51
|
+
await guardianState.updateGoal(goal.id, {
|
|
52
|
+
status: "achieved",
|
|
53
|
+
achievedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async function checkFilesForGoalViolations(goals, projectPath, filesToCheck) {
|
|
59
|
+
const { isAIAvailable, runAIAnalysis } = await import("./client-EWP4SIG3.js");
|
|
60
|
+
const { CodebaseIndex } = await import("./codebase-index-CR6Q2HEI.js");
|
|
61
|
+
if (!isAIAvailable()) {
|
|
62
|
+
throw new Error("AI not available - ANTHROPIC_API_KEY not set");
|
|
63
|
+
}
|
|
64
|
+
const codebaseIndex = new CodebaseIndex(projectPath);
|
|
65
|
+
if (codebaseIndex.isEmpty()) {
|
|
66
|
+
console.error("[Goal Check] Codebase index is empty - building index first...");
|
|
67
|
+
console.error("[Goal Check] This is a one-time operation. Future checks will be much faster.");
|
|
68
|
+
const { glob } = await import("glob");
|
|
69
|
+
const indexPattern = `${projectPath}/**/*.{ts,tsx,js,jsx,mjs,vue,svelte,astro,py,go,rs,java,c,cpp,h,hpp,cs,rb,php,css,scss,html}`;
|
|
70
|
+
const indexFiles = await glob(indexPattern, {
|
|
71
|
+
ignore: ["**/node_modules/**", "**/dist/**", "**/build/**", "**/.git/**", "**/.trie/**", "**/coverage/**"],
|
|
72
|
+
nodir: true
|
|
73
|
+
});
|
|
74
|
+
let indexed = 0;
|
|
75
|
+
const total = Math.min(indexFiles.length, 500);
|
|
76
|
+
for (const filePath of indexFiles.slice(0, 500)) {
|
|
77
|
+
let relativePath = filePath;
|
|
78
|
+
if (filePath.toLowerCase().startsWith(projectPath.toLowerCase() + "/")) {
|
|
79
|
+
relativePath = filePath.slice(projectPath.length + 1);
|
|
80
|
+
}
|
|
81
|
+
const result = await codebaseIndex.indexFile(relativePath);
|
|
82
|
+
if (result) indexed++;
|
|
83
|
+
if (indexed % 50 === 0) {
|
|
84
|
+
console.error(`[Goal Check] Indexed ${indexed}/${total} files...`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
await codebaseIndex.save();
|
|
88
|
+
console.error(`[Goal Check] Index built: ${indexed} files indexed`);
|
|
89
|
+
}
|
|
90
|
+
let files = [];
|
|
91
|
+
if (filesToCheck && filesToCheck.length > 0) {
|
|
92
|
+
files = filesToCheck;
|
|
93
|
+
} else {
|
|
94
|
+
const { glob } = await import("glob");
|
|
95
|
+
const pattern = `${projectPath}/**/*.{ts,tsx,js,jsx,py,go,rs,java,c,cpp,h,hpp,cs,rb,php,css,scss,html,vue,svelte}`;
|
|
96
|
+
const allFiles = await glob(pattern, {
|
|
97
|
+
ignore: ["**/node_modules/**", "**/dist/**", "**/build/**", "**/.git/**", "**/.trie/**", "**/coverage/**"],
|
|
98
|
+
nodir: true
|
|
99
|
+
});
|
|
100
|
+
const { stat } = await import("fs/promises");
|
|
101
|
+
const withStats = await Promise.all(
|
|
102
|
+
allFiles.map(async (f) => {
|
|
103
|
+
try {
|
|
104
|
+
const stats = await stat(f);
|
|
105
|
+
return { file: f, mtime: stats.mtime.getTime() };
|
|
106
|
+
} catch {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
);
|
|
111
|
+
files = withStats.filter((f) => f !== null).sort((a, b) => b.mtime - a.mtime).slice(0, 100).map((f) => f.file);
|
|
112
|
+
}
|
|
113
|
+
if (files.length === 0) {
|
|
114
|
+
throw new Error("No files found to check");
|
|
115
|
+
}
|
|
116
|
+
const filesToScan = [];
|
|
117
|
+
const cachedViolations = [];
|
|
118
|
+
for (const filePath of files) {
|
|
119
|
+
let relativePath = filePath;
|
|
120
|
+
if (filePath.toLowerCase().startsWith(projectPath.toLowerCase() + "/")) {
|
|
121
|
+
relativePath = filePath.slice(projectPath.length + 1);
|
|
122
|
+
} else if (filePath.startsWith("/")) {
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
const hasChanged = await codebaseIndex.hasChanged(relativePath);
|
|
126
|
+
if (hasChanged) {
|
|
127
|
+
const indexed = await codebaseIndex.indexFile(relativePath);
|
|
128
|
+
if (indexed) {
|
|
129
|
+
filesToScan.push(filePath);
|
|
130
|
+
}
|
|
131
|
+
} else {
|
|
132
|
+
for (const goal of goals) {
|
|
133
|
+
const cached = codebaseIndex.getCachedViolations(relativePath, goal.id);
|
|
134
|
+
if (cached && cached.length > 0) {
|
|
135
|
+
const violation = cached[0];
|
|
136
|
+
if (violation && violation.found) {
|
|
137
|
+
cachedViolations.push({
|
|
138
|
+
file: relativePath,
|
|
139
|
+
message: `Goal "${goal.description}" violated in ${relativePath}: ${violation.details || "Violation found"} [${violation.confidence || 90}% confidence] (cached)`,
|
|
140
|
+
severity: "warning"
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
} else {
|
|
144
|
+
if (!filesToScan.includes(filePath)) {
|
|
145
|
+
filesToScan.push(filePath);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
console.error(`[Goal Check] ${files.length} files total, ${filesToScan.length} need scanning, ${files.length - filesToScan.length} using cache`);
|
|
152
|
+
const allViolations = [...cachedViolations];
|
|
153
|
+
if (filesToScan.length === 0) {
|
|
154
|
+
await codebaseIndex.save();
|
|
155
|
+
return allViolations;
|
|
156
|
+
}
|
|
157
|
+
const BATCH_SIZE = 25;
|
|
158
|
+
for (let batchStart = 0; batchStart < filesToScan.length; batchStart += BATCH_SIZE) {
|
|
159
|
+
const batchFiles = filesToScan.slice(batchStart, batchStart + BATCH_SIZE);
|
|
160
|
+
const { readFile } = await import("fs/promises");
|
|
161
|
+
const fileContents = await Promise.all(
|
|
162
|
+
batchFiles.map(async (filePath) => {
|
|
163
|
+
try {
|
|
164
|
+
const content = await readFile(filePath, "utf-8");
|
|
165
|
+
const relativePath = filePath.replace(projectPath + "/", "");
|
|
166
|
+
return {
|
|
167
|
+
path: relativePath,
|
|
168
|
+
content: content.slice(0, 1e4)
|
|
169
|
+
// Increased limit for manual checks
|
|
170
|
+
};
|
|
171
|
+
} catch {
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
})
|
|
175
|
+
);
|
|
176
|
+
const validFiles = fileContents.filter((f) => f !== null);
|
|
177
|
+
if (validFiles.length === 0) continue;
|
|
178
|
+
const filesBlock = validFiles.map((f) => `--- ${f.path} ---
|
|
179
|
+
${f.content}`).join("\n\n");
|
|
180
|
+
const goalsSection = `
|
|
181
|
+
USER-DEFINED GOALS (check EVERY file against ALL goals):
|
|
182
|
+
${goals.map((g, i) => ` ${i + 1}. "${g.description}"`).join("\n")}
|
|
183
|
+
|
|
184
|
+
This is a MANUAL CHECK requested by the user. Report ALL goal violations you find.
|
|
185
|
+
For emoji detection, look for Unicode emoji characters.
|
|
186
|
+
`;
|
|
187
|
+
const result = await runAIAnalysis({
|
|
188
|
+
systemPrompt: `You are checking code for GOAL VIOLATIONS ONLY.
|
|
189
|
+
${goalsSection}
|
|
190
|
+
Reply ONLY with a JSON array. Each element must have:
|
|
191
|
+
- "file": relative file path
|
|
192
|
+
- "severity": "critical" | "major" | "minor"
|
|
193
|
+
- "description": 1-sentence description of the goal violation with specific examples
|
|
194
|
+
- "confidence": number 0-100, how confident you are this is a violation
|
|
195
|
+
- "isGoalViolation": true (always true for this scan)
|
|
196
|
+
- "goalIndex": 0-based index of the violated goal
|
|
197
|
+
|
|
198
|
+
CRITICAL DETECTION RULES:
|
|
199
|
+
|
|
200
|
+
**EMOJIS**: Any Unicode emoji characters including but not limited to:
|
|
201
|
+
- Emoticons: \u{1F600}\u{1F603}\u{1F604}\u{1F60A}\u{1F642}\u{1F643}\u{1F609}\u{1F607}\u{1F970}\u{1F60D}\u{1F929}\u{1F618}\u{1F617}\u263A\uFE0F\u{1F61A}\u{1F619}\u{1F972}
|
|
202
|
+
- Symbols: \u26A1\uFE0F\u26A0\uFE0F\u2705\u274C\u279C\u2192\u2190\u2191\u2193\u25BA\u25C4\u25B2\u25BC\u2605\u2606\u25CF\u25CB\u25C6\u25C7\u25A0\u25A1\u25AA\uFE0F\u25AB\uFE0F
|
|
203
|
+
- Objects: \u{1F4CA}\u{1F4C8}\u{1F4C9}\u{1F4BB}\u{1F5A5}\uFE0F\u{1F4F1}\u2328\uFE0F\u{1F5B1}\uFE0F\u{1F4BE}\u{1F4BF}\u{1F4C0}\u{1F527}\u{1F528}\u2699\uFE0F\u{1F6E0}\uFE0F
|
|
204
|
+
- Actions: \u{1F525}\u{1F4AA}\u{1F44D}\u{1F44E}\u{1F44F}\u{1F64C}\u{1F91D}\u270A\u{1F44A}\u{1F3AF}\u{1F389}\u{1F38A}\u{1F680}
|
|
205
|
+
- Weather: \u2600\uFE0F\u{1F324}\uFE0F\u26C5\u2601\uFE0F\u{1F326}\uFE0F\u{1F327}\uFE0F\u26C8\uFE0F\u{1F329}\uFE0F\u{1F328}\uFE0F\u2744\uFE0F
|
|
206
|
+
- ALL OTHER Unicode emoji in ranges U+1F300-U+1F9FF, U+2600-U+27BF, U+2B00-U+2BFF
|
|
207
|
+
|
|
208
|
+
**COLORS**: For "purple" or "gradient" goals, check:
|
|
209
|
+
- CSS: purple, #purple, hsl(purple), rgb(purple), violet, #8B00FF, #9B59D6, etc.
|
|
210
|
+
- Gradients: linear-gradient, radial-gradient, conic-gradient, background-image with gradients
|
|
211
|
+
- Tailwind: purple-*, violet-*, bg-gradient-*
|
|
212
|
+
- Styled components or CSS-in-JS with purple/violet/gradient
|
|
213
|
+
|
|
214
|
+
Be EXTREMELY thorough. Check:
|
|
215
|
+
1. String literals and template literals
|
|
216
|
+
2. JSX/HTML content
|
|
217
|
+
3. CSS files and style blocks
|
|
218
|
+
4. Comments (emojis in comments still violate "no emojis")
|
|
219
|
+
5. console.log statements
|
|
220
|
+
6. Component names, variable names (if they contain emojis)
|
|
221
|
+
|
|
222
|
+
If a goal says "no emojis" and you see ANY emoji ANYWHERE in the file, report it.
|
|
223
|
+
If a goal says "no console.log" and you see console.log ANYWHERE, report it.
|
|
224
|
+
If a goal says "no purple/gradient" and you see ANY purple color or gradient, report it.
|
|
225
|
+
|
|
226
|
+
If no violations found, reply with: []
|
|
227
|
+
Output ONLY the JSON array, no markdown fences, no commentary.`,
|
|
228
|
+
userPrompt: `Check these ${validFiles.length} files for goal violations:
|
|
229
|
+
|
|
230
|
+
${filesBlock}`,
|
|
231
|
+
maxTokens: 8192,
|
|
232
|
+
// Increased for larger codebases
|
|
233
|
+
temperature: 0.1
|
|
234
|
+
});
|
|
235
|
+
let issues = [];
|
|
236
|
+
try {
|
|
237
|
+
const cleaned = result.content.replace(/```json?\n?|\n?```/g, "").trim();
|
|
238
|
+
issues = JSON.parse(cleaned);
|
|
239
|
+
if (!Array.isArray(issues)) issues = [];
|
|
240
|
+
} catch {
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
for (const issue of issues) {
|
|
244
|
+
if (!issue.isGoalViolation || issue.confidence < 50) continue;
|
|
245
|
+
if (issue.goalIndex == null || issue.goalIndex < 0 || issue.goalIndex >= goals.length) continue;
|
|
246
|
+
const goal = goals[issue.goalIndex];
|
|
247
|
+
const severity = issue.severity === "critical" ? "critical" : "warning";
|
|
248
|
+
const message = `Goal "${goal.description}" violated in ${issue.file}: ${issue.description} [${issue.confidence}% confidence]`;
|
|
249
|
+
allViolations.push({
|
|
250
|
+
file: issue.file,
|
|
251
|
+
message,
|
|
252
|
+
severity
|
|
253
|
+
});
|
|
254
|
+
codebaseIndex.recordViolation(
|
|
255
|
+
issue.file,
|
|
256
|
+
goal.id,
|
|
257
|
+
goal.description,
|
|
258
|
+
true,
|
|
259
|
+
// found
|
|
260
|
+
issue.description,
|
|
261
|
+
issue.confidence
|
|
262
|
+
);
|
|
263
|
+
await recordGoalViolationCaught(goal, issue.file, projectPath);
|
|
264
|
+
}
|
|
265
|
+
for (const file of validFiles) {
|
|
266
|
+
for (const goal of goals) {
|
|
267
|
+
const hasViolation = issues.some((i) => i.file === file.path && i.goalIndex === goals.indexOf(goal));
|
|
268
|
+
if (!hasViolation) {
|
|
269
|
+
codebaseIndex.recordViolation(
|
|
270
|
+
file.path,
|
|
271
|
+
goal.id,
|
|
272
|
+
goal.description,
|
|
273
|
+
false,
|
|
274
|
+
// not found
|
|
275
|
+
void 0,
|
|
276
|
+
100
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
await codebaseIndex.save();
|
|
283
|
+
return allViolations;
|
|
284
|
+
}
|
|
285
|
+
export {
|
|
286
|
+
checkFilesForGoalViolations,
|
|
287
|
+
getActiveGoals,
|
|
288
|
+
recordGoalViolationCaught,
|
|
289
|
+
recordGoalViolationFixed
|
|
290
|
+
};
|
|
291
|
+
//# sourceMappingURL=goal-validator-NLOJJ7FF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/guardian/goal-validator.ts"],"sourcesContent":["/**\n * Goal Validator - Helpers for goal tracking\n * \n * Goal detection is handled entirely by the AI watcher in watch.ts.\n * The AI (Anthropic) checks every changed file against user-defined goals,\n * using the Trie's priority scoring for cost control.\n * \n * This module provides:\n * - getActiveGoals: loads active goals for the AI prompt\n * - recordGoalViolationCaught: tracks when a violation is detected\n * - recordGoalViolationFixed: tracks when a violation is auto-fixed\n */\n\nimport type { Goal } from './guardian-state.js';\nimport { getGuardianState } from './guardian-state.js';\n\n/**\n * Get active goals for a project (used by the AI watcher)\n */\nexport async function getActiveGoals(projectPath: string): Promise<Goal[]> {\n const guardianState = getGuardianState(projectPath);\n await guardianState.load();\n return guardianState.getAllGoals().filter(g => g.status === 'active');\n}\n\nexport async function recordGoalViolationCaught(\n goal: Goal,\n file: string,\n projectPath: string\n): Promise<void> {\n const guardianState = getGuardianState(projectPath);\n await guardianState.load();\n \n const metadata = goal.metadata || {};\n const caughtCount = (metadata.caughtCount || 0) + 1;\n \n await guardianState.updateGoal(goal.id, {\n metadata: {\n ...metadata,\n caughtCount,\n lastCaught: new Date().toISOString(),\n lastCaughtFile: file,\n },\n });\n}\n\nexport async function recordGoalViolationFixed(\n goal: Goal,\n file: string,\n projectPath: string\n): Promise<void> {\n const guardianState = getGuardianState(projectPath);\n await guardianState.load();\n \n const metadata = goal.metadata || {};\n const caughtCount = (metadata.caughtCount || 0) + 1;\n const fixedCount = (metadata.fixedCount || 0) + 1;\n \n await guardianState.updateGoal(goal.id, {\n metadata: {\n ...metadata,\n caughtCount,\n fixedCount,\n lastFixed: new Date().toISOString(),\n lastFixedFile: file,\n },\n });\n \n if (goal.type === 'reduction') {\n const newValue = Math.max(0, goal.currentValue - 1);\n await guardianState.updateGoal(goal.id, {\n currentValue: newValue,\n });\n \n if (newValue <= goal.target) {\n await guardianState.updateGoal(goal.id, {\n status: 'achieved',\n achievedAt: new Date().toISOString(),\n });\n }\n }\n}\n\n/**\n * Manually check files against goals\n * Returns violations found\n * \n * NOW WITH CACHING: Uses CodebaseIndex to avoid re-scanning unchanged files\n */\nexport async function checkFilesForGoalViolations(\n goals: Goal[],\n projectPath: string,\n filesToCheck?: string[]\n): Promise<Array<{ file: string; message: string; severity: 'critical' | 'warning' | 'info' }>> {\n // Import AI client and codebase index\n const { isAIAvailable, runAIAnalysis } = await import('../ai/client.js');\n const { CodebaseIndex } = await import('../context/codebase-index.js');\n \n if (!isAIAvailable()) {\n throw new Error('AI not available - ANTHROPIC_API_KEY not set');\n }\n \n // Initialize codebase index for caching\n const codebaseIndex = new CodebaseIndex(projectPath);\n \n // Check if index needs to be built\n if (codebaseIndex.isEmpty()) {\n console.error('[Goal Check] Codebase index is empty - building index first...');\n console.error('[Goal Check] This is a one-time operation. Future checks will be much faster.');\n \n // Auto-index the codebase\n const { glob } = await import('glob');\n const indexPattern = `${projectPath}/**/*.{ts,tsx,js,jsx,mjs,vue,svelte,astro,py,go,rs,java,c,cpp,h,hpp,cs,rb,php,css,scss,html}`;\n const indexFiles = await glob(indexPattern, {\n ignore: ['**/node_modules/**', '**/dist/**', '**/build/**', '**/.git/**', '**/.trie/**', '**/coverage/**'],\n nodir: true,\n });\n \n let indexed = 0;\n const total = Math.min(indexFiles.length, 500); // Cap at 500 files for initial index\n for (const filePath of indexFiles.slice(0, 500)) {\n let relativePath = filePath;\n if (filePath.toLowerCase().startsWith(projectPath.toLowerCase() + '/')) {\n relativePath = filePath.slice(projectPath.length + 1);\n }\n const result = await codebaseIndex.indexFile(relativePath);\n if (result) indexed++;\n \n // Progress indicator every 50 files\n if (indexed % 50 === 0) {\n console.error(`[Goal Check] Indexed ${indexed}/${total} files...`);\n }\n }\n \n await codebaseIndex.save();\n console.error(`[Goal Check] Index built: ${indexed} files indexed`);\n }\n \n // Get files to check\n let files: string[] = [];\n if (filesToCheck && filesToCheck.length > 0) {\n files = filesToCheck;\n } else {\n // MANUAL CHECK MODE: Scan ALL relevant files, not just recently modified\n const { glob } = await import('glob');\n \n const pattern = `${projectPath}/**/*.{ts,tsx,js,jsx,py,go,rs,java,c,cpp,h,hpp,cs,rb,php,css,scss,html,vue,svelte}`;\n const allFiles = await glob(pattern, {\n ignore: ['**/node_modules/**', '**/dist/**', '**/build/**', '**/.git/**', '**/.trie/**', '**/coverage/**'],\n nodir: true,\n });\n \n // For manual checks, use more files but still reasonable limit\n // Sort by modification time to prioritize recently modified\n const { stat } = await import('fs/promises');\n const withStats = await Promise.all(\n allFiles.map(async (f) => {\n try {\n const stats = await stat(f);\n return { file: f, mtime: stats.mtime.getTime() };\n } catch {\n return null;\n }\n })\n );\n \n files = withStats\n .filter((f): f is { file: string; mtime: number } => f !== null)\n .sort((a, b) => b.mtime - a.mtime)\n .slice(0, 100) // Check up to 100 files for manual scans\n .map(f => f.file);\n }\n \n if (files.length === 0) {\n throw new Error('No files found to check');\n }\n \n // Check which files need scanning vs can use cached results\n const filesToScan: string[] = [];\n const cachedViolations: Array<{ file: string; message: string; severity: 'critical' | 'warning' | 'info' }> = [];\n \n for (const filePath of files) {\n // Handle case-insensitive filesystems (macOS) and ensure we get a proper relative path\n let relativePath = filePath;\n if (filePath.toLowerCase().startsWith(projectPath.toLowerCase() + '/')) {\n relativePath = filePath.slice(projectPath.length + 1);\n } else if (filePath.startsWith('/')) {\n // Already absolute but doesn't match projectPath - skip this file\n // This can happen with stale cache entries from different projects\n continue;\n }\n const hasChanged = await codebaseIndex.hasChanged(relativePath);\n \n if (hasChanged) {\n // File changed or not indexed - needs scanning\n // Try to index the file first; skip if it doesn't exist\n const indexed = await codebaseIndex.indexFile(relativePath);\n if (indexed) {\n filesToScan.push(filePath);\n }\n // If indexFile returns null, file doesn't exist - skip it silently\n } else {\n // File unchanged - check cache for each goal\n for (const goal of goals) {\n const cached = codebaseIndex.getCachedViolations(relativePath, goal.id);\n if (cached && cached.length > 0) {\n const violation = cached[0];\n if (violation && violation.found) {\n cachedViolations.push({\n file: relativePath,\n message: `Goal \"${goal.description}\" violated in ${relativePath}: ${violation.details || 'Violation found'} [${violation.confidence || 90}% confidence] (cached)`,\n severity: 'warning',\n });\n }\n } else {\n // No cache for this goal - needs scanning\n if (!filesToScan.includes(filePath)) {\n filesToScan.push(filePath);\n }\n }\n }\n }\n }\n \n console.error(`[Goal Check] ${files.length} files total, ${filesToScan.length} need scanning, ${files.length - filesToScan.length} using cache`);\n \n // Process files that need scanning in batches\n const allViolations: Array<{ file: string; message: string; severity: 'critical' | 'warning' | 'info' }> = [...cachedViolations];\n \n if (filesToScan.length === 0) {\n // All results from cache!\n await codebaseIndex.save();\n return allViolations;\n }\n \n // For large file sets, process in batches to avoid token limits\n const BATCH_SIZE = 25; // Process 25 files at a time\n \n for (let batchStart = 0; batchStart < filesToScan.length; batchStart += BATCH_SIZE) {\n const batchFiles = filesToScan.slice(batchStart, batchStart + BATCH_SIZE);\n \n // Read file contents for this batch\n const { readFile } = await import('fs/promises');\n const fileContents = await Promise.all(\n batchFiles.map(async (filePath) => {\n try {\n const content = await readFile(filePath, 'utf-8');\n const relativePath = filePath.replace(projectPath + '/', '');\n return {\n path: relativePath,\n content: content.slice(0, 10000), // Increased limit for manual checks\n };\n } catch {\n return null;\n }\n })\n );\n \n const validFiles = fileContents.filter((f): f is { path: string; content: string } => f !== null);\n \n if (validFiles.length === 0) continue;\n \n // Build files block for AI\n const filesBlock = validFiles\n .map(f => `--- ${f.path} ---\\n${f.content}`)\n .join('\\n\\n');\n \n // Build goals section\n const goalsSection = `\nUSER-DEFINED GOALS (check EVERY file against ALL goals):\n${goals.map((g, i) => ` ${i + 1}. \"${g.description}\"`).join('\\n')}\n\nThis is a MANUAL CHECK requested by the user. Report ALL goal violations you find.\nFor emoji detection, look for Unicode emoji characters.\n`;\n \n // Run AI analysis\n const result = await runAIAnalysis({\n systemPrompt: `You are checking code for GOAL VIOLATIONS ONLY.\n${goalsSection}\nReply ONLY with a JSON array. Each element must have:\n- \"file\": relative file path\n- \"severity\": \"critical\" | \"major\" | \"minor\"\n- \"description\": 1-sentence description of the goal violation with specific examples\n- \"confidence\": number 0-100, how confident you are this is a violation\n- \"isGoalViolation\": true (always true for this scan)\n- \"goalIndex\": 0-based index of the violated goal\n\nCRITICAL DETECTION RULES:\n\n**EMOJIS**: Any Unicode emoji characters including but not limited to:\n- Emoticons: 😀😃😄😊🙂🙃😉😇🥰😍🤩😘😗☺️😚😙🥲\n- Symbols: ⚡️⚠️✅❌➜→←↑↓►◄▲▼★☆●○◆◇■□▪️▫️\n- Objects: 📊📈📉💻🖥️📱⌨️🖱️💾💿📀🔧🔨⚙️🛠️\n- Actions: 🔥💪👍👎👏🙌🤝✊👊🎯🎉🎊🚀\n- Weather: ☀️🌤️⛅☁️🌦️🌧️⛈️🌩️🌨️❄️\n- ALL OTHER Unicode emoji in ranges U+1F300-U+1F9FF, U+2600-U+27BF, U+2B00-U+2BFF\n\n**COLORS**: For \"purple\" or \"gradient\" goals, check:\n- CSS: purple, #purple, hsl(purple), rgb(purple), violet, #8B00FF, #9B59D6, etc.\n- Gradients: linear-gradient, radial-gradient, conic-gradient, background-image with gradients\n- Tailwind: purple-*, violet-*, bg-gradient-*\n- Styled components or CSS-in-JS with purple/violet/gradient\n\nBe EXTREMELY thorough. Check:\n1. String literals and template literals\n2. JSX/HTML content\n3. CSS files and style blocks\n4. Comments (emojis in comments still violate \"no emojis\")\n5. console.log statements\n6. Component names, variable names (if they contain emojis)\n\nIf a goal says \"no emojis\" and you see ANY emoji ANYWHERE in the file, report it.\nIf a goal says \"no console.log\" and you see console.log ANYWHERE, report it.\nIf a goal says \"no purple/gradient\" and you see ANY purple color or gradient, report it.\n\nIf no violations found, reply with: []\nOutput ONLY the JSON array, no markdown fences, no commentary.`,\n userPrompt: `Check these ${validFiles.length} files for goal violations:\\n\\n${filesBlock}`,\n maxTokens: 8192, // Increased for larger codebases\n temperature: 0.1,\n });\n \n // Parse response\n let issues: Array<{\n file: string;\n severity: 'critical' | 'major' | 'minor';\n description: string;\n confidence: number;\n isGoalViolation: boolean;\n goalIndex?: number;\n }> = [];\n \n try {\n const cleaned = result.content.replace(/```json?\\n?|\\n?```/g, '').trim();\n issues = JSON.parse(cleaned);\n if (!Array.isArray(issues)) issues = [];\n } catch {\n // Parse failed - continue to next batch\n continue;\n }\n \n // Convert to violation format and record\n for (const issue of issues) {\n if (!issue.isGoalViolation || issue.confidence < 50) continue;\n if (issue.goalIndex == null || issue.goalIndex < 0 || issue.goalIndex >= goals.length) continue;\n \n const goal = goals[issue.goalIndex]!;\n const severity = issue.severity === 'critical' ? 'critical' : 'warning';\n const message = `Goal \"${goal.description}\" violated in ${issue.file}: ${issue.description} [${issue.confidence}% confidence]`;\n \n allViolations.push({\n file: issue.file,\n message,\n severity,\n });\n \n // Cache the result in codebase index\n codebaseIndex.recordViolation(\n issue.file,\n goal.id,\n goal.description,\n true, // found\n issue.description,\n issue.confidence\n );\n \n // Record violation\n await recordGoalViolationCaught(goal, issue.file, projectPath);\n }\n \n // Also record \"no violation\" for scanned files\n for (const file of validFiles) {\n for (const goal of goals) {\n const hasViolation = issues.some(i => i.file === file.path && i.goalIndex === goals.indexOf(goal));\n if (!hasViolation) {\n codebaseIndex.recordViolation(\n file.path,\n goal.id,\n goal.description,\n false, // not found\n undefined,\n 100\n );\n }\n }\n }\n }\n \n // Save updated index\n await codebaseIndex.save();\n \n return allViolations;\n}\n"],"mappings":";;;;;;;;;;AAmBA,eAAsB,eAAe,aAAsC;AACzE,QAAM,gBAAgB,iBAAiB,WAAW;AAClD,QAAM,cAAc,KAAK;AACzB,SAAO,cAAc,YAAY,EAAE,OAAO,OAAK,EAAE,WAAW,QAAQ;AACtE;AAEA,eAAsB,0BACpB,MACA,MACA,aACe;AACf,QAAM,gBAAgB,iBAAiB,WAAW;AAClD,QAAM,cAAc,KAAK;AAEzB,QAAM,WAAW,KAAK,YAAY,CAAC;AACnC,QAAM,eAAe,SAAS,eAAe,KAAK;AAElD,QAAM,cAAc,WAAW,KAAK,IAAI;AAAA,IACtC,UAAU;AAAA,MACR,GAAG;AAAA,MACH;AAAA,MACA,aAAY,oBAAI,KAAK,GAAE,YAAY;AAAA,MACnC,gBAAgB;AAAA,IAClB;AAAA,EACF,CAAC;AACH;AAEA,eAAsB,yBACpB,MACA,MACA,aACe;AACf,QAAM,gBAAgB,iBAAiB,WAAW;AAClD,QAAM,cAAc,KAAK;AAEzB,QAAM,WAAW,KAAK,YAAY,CAAC;AACnC,QAAM,eAAe,SAAS,eAAe,KAAK;AAClD,QAAM,cAAc,SAAS,cAAc,KAAK;AAEhD,QAAM,cAAc,WAAW,KAAK,IAAI;AAAA,IACtC,UAAU;AAAA,MACR,GAAG;AAAA,MACH;AAAA,MACA;AAAA,MACA,YAAW,oBAAI,KAAK,GAAE,YAAY;AAAA,MAClC,eAAe;AAAA,IACjB;AAAA,EACF,CAAC;AAED,MAAI,KAAK,SAAS,aAAa;AAC7B,UAAM,WAAW,KAAK,IAAI,GAAG,KAAK,eAAe,CAAC;AAClD,UAAM,cAAc,WAAW,KAAK,IAAI;AAAA,MACtC,cAAc;A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AAQ;AAEvF,YAAM,OAAO,MAAM,MAAM,SAAS;AAClC,YAAM,WAAW,MAAM,aAAa,aAAa,aAAa;AAC9D,YAAM,UAAU,SAAS,KAAK,WAAW,iBAAiB,MAAM,IAAI,KAAK,MAAM,WAAW,KAAK,MAAM,UAAU;AAE/G,oBAAc,KAAK;AAAA,QACjB,MAAM,MAAM;AAAA,QACZ;AAAA,QACA;AAAA,MACF,CAAC;AAGD,oBAAc;AAAA,QACZ,MAAM;AAAA,QACN,KAAK;AAAA,QACL,KAAK;AAAA,QACL;AAAA;AAAA,QACA,MAAM;AAAA,QACN,MAAM;AAAA,MACR;AAGA,YAAM,0BAA0B,MAAM,MAAM,MAAM,WAAW;AAAA,IAC/D;AAGA,eAAW,QAAQ,YAAY;AAC7B,iBAAW,QAAQ,OAAO;AACxB,cAAM,eAAe,OAAO,KAAK,OAAK,EAAE,SAAS,KAAK,QAAQ,EAAE,cAAc,MAAM,QAAQ,IAAI,CAAC;AACjG,YAAI,CAAC,cAAc;AACjB,wBAAc;AAAA,YACZ,KAAK;AAAA,YACL,KAAK;AAAA,YACL,KAAK;AAAA,YACL;AAAA;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAGA,QAAM,cAAc,KAAK;AAEzB,SAAO;AACT;","names":[]}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
CodebaseIndex
|
|
4
|
+
} from "./chunk-6VIMBFUZ.js";
|
|
2
5
|
import {
|
|
3
6
|
LinearIngester,
|
|
4
7
|
appendToSection,
|
|
@@ -38,7 +41,7 @@ import {
|
|
|
38
41
|
getPrompt,
|
|
39
42
|
getSystemPrompt,
|
|
40
43
|
handleCheckpointTool
|
|
41
|
-
} from "./chunk-
|
|
44
|
+
} from "./chunk-WBNYLTW6.js";
|
|
42
45
|
import "./chunk-D2CGMX7K.js";
|
|
43
46
|
import "./chunk-DFPVUMVE.js";
|
|
44
47
|
import "./chunk-TRIJC5MW.js";
|
|
@@ -1141,6 +1144,7 @@ var SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
|
1141
1144
|
var TrieWatchTool = class _TrieWatchTool {
|
|
1142
1145
|
extractionPipeline = null;
|
|
1143
1146
|
watchedDirectory = "";
|
|
1147
|
+
codebaseIndex = null;
|
|
1144
1148
|
state = {
|
|
1145
1149
|
isRunning: false,
|
|
1146
1150
|
lastScan: /* @__PURE__ */ new Map(),
|
|
@@ -1173,7 +1177,7 @@ var TrieWatchTool = class _TrieWatchTool {
|
|
|
1173
1177
|
case "start":
|
|
1174
1178
|
return this.startWatching(getWorkingDirectory(directory), debounceMs);
|
|
1175
1179
|
case "stop":
|
|
1176
|
-
return this.stopWatching();
|
|
1180
|
+
return await this.stopWatching();
|
|
1177
1181
|
case "status":
|
|
1178
1182
|
return await this.getStatus();
|
|
1179
1183
|
case "issues":
|
|
@@ -1214,6 +1218,7 @@ var TrieWatchTool = class _TrieWatchTool {
|
|
|
1214
1218
|
});
|
|
1215
1219
|
await this.extractionPipeline.initialize();
|
|
1216
1220
|
}
|
|
1221
|
+
this.codebaseIndex = new CodebaseIndex(directory);
|
|
1217
1222
|
this.state.isRunning = true;
|
|
1218
1223
|
this.watchedDirectory = directory;
|
|
1219
1224
|
this.state.issueCache.clear();
|
|
@@ -1255,6 +1260,7 @@ var TrieWatchTool = class _TrieWatchTool {
|
|
|
1255
1260
|
void this.initialGoalComplianceScan();
|
|
1256
1261
|
void this.initialHypothesisGeneration();
|
|
1257
1262
|
}, 1e3);
|
|
1263
|
+
const indexStatus = this.codebaseIndex?.isEmpty() ? "BUILDING (one-time, speeds up goal checks)" : "READY";
|
|
1258
1264
|
return {
|
|
1259
1265
|
content: [{
|
|
1260
1266
|
type: "text",
|
|
@@ -1265,6 +1271,7 @@ Your Trie agent is now autonomously watching and learning from your codebase.
|
|
|
1265
1271
|
**Watching:** \`${directory}\`
|
|
1266
1272
|
**Debounce:** ${debounceMs}ms (waits for you to stop typing)
|
|
1267
1273
|
**Signal Extraction:** ${process.env.ANTHROPIC_API_KEY ? "ENABLED" : "LIMITED (set ANTHROPIC_API_KEY for full extraction)"}
|
|
1274
|
+
**Codebase Index:** ${indexStatus}
|
|
1268
1275
|
|
|
1269
1276
|
### How the agent works:
|
|
1270
1277
|
1. You write/edit code
|
|
@@ -1280,7 +1287,8 @@ Your Trie agent is now autonomously watching and learning from your codebase.
|
|
|
1280
1287
|
|
|
1281
1288
|
### Commands:
|
|
1282
1289
|
- \`trie_watch status\` - See agent status
|
|
1283
|
-
- \`trie_watch stop\` - Stop the agent
|
|
1290
|
+
- \`trie_watch stop\` - Stop the agent
|
|
1291
|
+
- \`trie_index status\` - Check codebase index`
|
|
1284
1292
|
}]
|
|
1285
1293
|
};
|
|
1286
1294
|
}
|
|
@@ -1403,6 +1411,12 @@ ${f.content.slice(0, 1e3)}`
|
|
|
1403
1411
|
this.state.filesScanned += files.length;
|
|
1404
1412
|
for (const file of files) {
|
|
1405
1413
|
this.state.lastScan.set(file, Date.now());
|
|
1414
|
+
if (this.codebaseIndex) {
|
|
1415
|
+
const relativePath = file.replace(projectPath + "/", "");
|
|
1416
|
+
void this.codebaseIndex.indexFile(relativePath).then(() => {
|
|
1417
|
+
void this.codebaseIndex?.save();
|
|
1418
|
+
});
|
|
1419
|
+
}
|
|
1406
1420
|
}
|
|
1407
1421
|
} catch (error) {
|
|
1408
1422
|
if (!isInteractiveMode()) {
|
|
@@ -1638,7 +1652,7 @@ ${f.content.slice(0, 1e3)}`
|
|
|
1638
1652
|
this.state.lastAutoScan = now;
|
|
1639
1653
|
try {
|
|
1640
1654
|
const graph = new ContextGraph(projectPath);
|
|
1641
|
-
const { getActiveGoals, recordGoalViolationCaught } = await import("./goal-validator-
|
|
1655
|
+
const { getActiveGoals, recordGoalViolationCaught } = await import("./goal-validator-NLOJJ7FF.js");
|
|
1642
1656
|
const { appendIssuesToLedger } = await import("./ledger-JMPGJGLB.js");
|
|
1643
1657
|
console.debug("[AI Watcher] Loading active goals...");
|
|
1644
1658
|
const activeGoals = await getActiveGoals(projectPath);
|
|
@@ -1945,7 +1959,7 @@ ${filesBlock}`,
|
|
|
1945
1959
|
const projectPath = this.watchedDirectory || getWorkingDirectory(void 0, true);
|
|
1946
1960
|
console.debug("[Initial Scan] Starting initial goal compliance scan", { projectPath });
|
|
1947
1961
|
try {
|
|
1948
|
-
const { getActiveGoals, recordGoalViolationCaught } = await import("./goal-validator-
|
|
1962
|
+
const { getActiveGoals, recordGoalViolationCaught } = await import("./goal-validator-NLOJJ7FF.js");
|
|
1949
1963
|
const activeGoals = await getActiveGoals(projectPath);
|
|
1950
1964
|
console.debug("[Initial Scan] Loaded goals for initial scan:", {
|
|
1951
1965
|
goalCount: activeGoals.length,
|
|
@@ -2091,7 +2105,7 @@ ${filesBlock}`,
|
|
|
2091
2105
|
}
|
|
2092
2106
|
}
|
|
2093
2107
|
}
|
|
2094
|
-
stopWatching() {
|
|
2108
|
+
async stopWatching() {
|
|
2095
2109
|
if (!this.state.isRunning) {
|
|
2096
2110
|
return {
|
|
2097
2111
|
content: [{
|
|
@@ -2108,6 +2122,10 @@ ${filesBlock}`,
|
|
|
2108
2122
|
this.extractionPipeline.close();
|
|
2109
2123
|
this.extractionPipeline = null;
|
|
2110
2124
|
}
|
|
2125
|
+
if (this.codebaseIndex) {
|
|
2126
|
+
await this.codebaseIndex.save();
|
|
2127
|
+
this.codebaseIndex = null;
|
|
2128
|
+
}
|
|
2111
2129
|
if (this.state.scanDebounceTimer) {
|
|
2112
2130
|
clearTimeout(this.state.scanDebounceTimer);
|
|
2113
2131
|
}
|
|
@@ -3372,6 +3390,120 @@ var LinearSyncTool = class {
|
|
|
3372
3390
|
}
|
|
3373
3391
|
};
|
|
3374
3392
|
|
|
3393
|
+
// src/tools/index-codebase.ts
|
|
3394
|
+
import { glob } from "glob";
|
|
3395
|
+
var INDEXABLE_EXTENSIONS = [
|
|
3396
|
+
"ts",
|
|
3397
|
+
"tsx",
|
|
3398
|
+
"js",
|
|
3399
|
+
"jsx",
|
|
3400
|
+
"mjs",
|
|
3401
|
+
"vue",
|
|
3402
|
+
"svelte",
|
|
3403
|
+
"astro",
|
|
3404
|
+
"py",
|
|
3405
|
+
"go",
|
|
3406
|
+
"rs",
|
|
3407
|
+
"java",
|
|
3408
|
+
"c",
|
|
3409
|
+
"cpp",
|
|
3410
|
+
"h",
|
|
3411
|
+
"hpp",
|
|
3412
|
+
"cs",
|
|
3413
|
+
"rb",
|
|
3414
|
+
"php",
|
|
3415
|
+
"css",
|
|
3416
|
+
"scss",
|
|
3417
|
+
"html"
|
|
3418
|
+
];
|
|
3419
|
+
var TrieIndexTool = class {
|
|
3420
|
+
async execute(params) {
|
|
3421
|
+
const action = params.action || "full";
|
|
3422
|
+
const workDir = getWorkingDirectory(params.directory, true);
|
|
3423
|
+
if (!isTrieInitialized(workDir)) {
|
|
3424
|
+
return "Trie is not initialized for this project. Run `trie init` first.";
|
|
3425
|
+
}
|
|
3426
|
+
const codebaseIndex = new CodebaseIndex(workDir);
|
|
3427
|
+
if (action === "status") {
|
|
3428
|
+
const stats2 = codebaseIndex.getStats();
|
|
3429
|
+
return [
|
|
3430
|
+
"# Codebase Index Status",
|
|
3431
|
+
"",
|
|
3432
|
+
`**Total files indexed:** ${stats2.totalFiles}`,
|
|
3433
|
+
`**Total size:** ${(stats2.totalSize / 1024 / 1024).toFixed(2)} MB`,
|
|
3434
|
+
`**Files scanned for goals:** ${stats2.scannedFiles}`,
|
|
3435
|
+
`**Files with violations:** ${stats2.filesWithViolations}`,
|
|
3436
|
+
"",
|
|
3437
|
+
"## Files by Type",
|
|
3438
|
+
"",
|
|
3439
|
+
...Object.entries(stats2.filesByType).sort(([, a], [, b]) => b - a).slice(0, 10).map(([type, count]) => `- .${type}: ${count} files`),
|
|
3440
|
+
"",
|
|
3441
|
+
"---",
|
|
3442
|
+
"",
|
|
3443
|
+
'Run `trie_index` with action="full" to re-index the codebase.',
|
|
3444
|
+
'Run `trie_index` with action="clear" to clear stale cache entries.'
|
|
3445
|
+
].join("\n");
|
|
3446
|
+
}
|
|
3447
|
+
if (action === "clear") {
|
|
3448
|
+
const cleared = codebaseIndex.clearStaleCache();
|
|
3449
|
+
await codebaseIndex.save();
|
|
3450
|
+
return `Cleared ${cleared} stale cache entries.`;
|
|
3451
|
+
}
|
|
3452
|
+
const pattern = `${workDir}/**/*.{${INDEXABLE_EXTENSIONS.join(",")}}`;
|
|
3453
|
+
const allFiles = await glob(pattern, {
|
|
3454
|
+
ignore: ["**/node_modules/**", "**/dist/**", "**/build/**", "**/.git/**", "**/.trie/**", "**/coverage/**"],
|
|
3455
|
+
nodir: true
|
|
3456
|
+
});
|
|
3457
|
+
let indexed = 0;
|
|
3458
|
+
let failed = 0;
|
|
3459
|
+
const startTime = Date.now();
|
|
3460
|
+
const BATCH_SIZE = 50;
|
|
3461
|
+
for (let i = 0; i < allFiles.length; i += BATCH_SIZE) {
|
|
3462
|
+
const batch = allFiles.slice(i, i + BATCH_SIZE);
|
|
3463
|
+
await Promise.all(batch.map(async (filePath) => {
|
|
3464
|
+
try {
|
|
3465
|
+
let relativePath = filePath;
|
|
3466
|
+
if (filePath.toLowerCase().startsWith(workDir.toLowerCase() + "/")) {
|
|
3467
|
+
relativePath = filePath.slice(workDir.length + 1);
|
|
3468
|
+
}
|
|
3469
|
+
const result = await codebaseIndex.indexFile(relativePath);
|
|
3470
|
+
if (result) {
|
|
3471
|
+
indexed++;
|
|
3472
|
+
} else {
|
|
3473
|
+
failed++;
|
|
3474
|
+
}
|
|
3475
|
+
} catch {
|
|
3476
|
+
failed++;
|
|
3477
|
+
}
|
|
3478
|
+
}));
|
|
3479
|
+
}
|
|
3480
|
+
await codebaseIndex.save();
|
|
3481
|
+
const duration = ((Date.now() - startTime) / 1e3).toFixed(1);
|
|
3482
|
+
const stats = codebaseIndex.getStats();
|
|
3483
|
+
return [
|
|
3484
|
+
"# Codebase Indexing Complete",
|
|
3485
|
+
"",
|
|
3486
|
+
`**Files indexed:** ${indexed}`,
|
|
3487
|
+
`**Files failed:** ${failed}`,
|
|
3488
|
+
`**Duration:** ${duration}s`,
|
|
3489
|
+
"",
|
|
3490
|
+
"## Index Statistics",
|
|
3491
|
+
"",
|
|
3492
|
+
`- Total files: ${stats.totalFiles}`,
|
|
3493
|
+
`- Total size: ${(stats.totalSize / 1024 / 1024).toFixed(2)} MB`,
|
|
3494
|
+
"",
|
|
3495
|
+
"## Files by Type",
|
|
3496
|
+
"",
|
|
3497
|
+
...Object.entries(stats.filesByType).sort(([, a], [, b]) => b - a).slice(0, 10).map(([type, count]) => `- .${type}: ${count} files`),
|
|
3498
|
+
"",
|
|
3499
|
+
"---",
|
|
3500
|
+
"",
|
|
3501
|
+
"The index will be automatically updated when files change during watch mode.",
|
|
3502
|
+
"Goal checks will now use cached results for unchanged files."
|
|
3503
|
+
].join("\n");
|
|
3504
|
+
}
|
|
3505
|
+
};
|
|
3506
|
+
|
|
3375
3507
|
// src/server/tool-registry.ts
|
|
3376
3508
|
var TrieCheckpointTool = class {
|
|
3377
3509
|
async execute(input) {
|
|
@@ -3410,6 +3542,7 @@ var ToolRegistry = class {
|
|
|
3410
3542
|
this.tools.set("ok", new TrieFeedbackTool());
|
|
3411
3543
|
this.tools.set("bad", new TrieFeedbackTool());
|
|
3412
3544
|
this.tools.set("linear_sync", new LinearSyncTool());
|
|
3545
|
+
this.tools.set("index", new TrieIndexTool());
|
|
3413
3546
|
this.tools.set("get_decisions", new TrieGetDecisionsTool());
|
|
3414
3547
|
this.tools.set("get_blockers", new TrieGetBlockersTool());
|
|
3415
3548
|
this.tools.set("get_related_decisions", new TrieGetRelatedDecisionsTool());
|
|
@@ -3816,6 +3949,24 @@ var ToolRegistry = class {
|
|
|
3816
3949
|
required: ["action"]
|
|
3817
3950
|
}
|
|
3818
3951
|
},
|
|
3952
|
+
{
|
|
3953
|
+
name: "trie_index",
|
|
3954
|
+
description: "Index codebase for fast goal checking and file lookups. Index is auto-updated during watch mode. Use this for initial indexing or to rebuild the index.",
|
|
3955
|
+
inputSchema: {
|
|
3956
|
+
type: "object",
|
|
3957
|
+
properties: {
|
|
3958
|
+
action: {
|
|
3959
|
+
type: "string",
|
|
3960
|
+
enum: ["full", "status", "clear"],
|
|
3961
|
+
description: "Action: full (index all files), status (show index stats), clear (remove stale cache)"
|
|
3962
|
+
},
|
|
3963
|
+
directory: {
|
|
3964
|
+
type: "string",
|
|
3965
|
+
description: "Project directory (defaults to current workspace)"
|
|
3966
|
+
}
|
|
3967
|
+
}
|
|
3968
|
+
}
|
|
3969
|
+
},
|
|
3819
3970
|
// Add remaining tool definitions...
|
|
3820
3971
|
this.createSpecialAgentDefinitions()
|
|
3821
3972
|
].flat();
|