@triedotdev/mcp 1.0.136 → 1.0.138
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 +6 -6
- package/dist/{autonomy-config-QA6ATWLJ.js → autonomy-config-TZ6HF4FA.js} +3 -3
- package/dist/{chat-store-HFOOWZYN.js → chat-store-OJLJCJFI.js} +3 -3
- package/dist/{chunk-DFPVUMVE.js → chunk-23RJT5WT.js} +5 -4
- package/dist/chunk-23RJT5WT.js.map +1 -0
- package/dist/{chunk-4YJ6KLGI.js → chunk-3MUCUZ46.js} +8 -8
- package/dist/chunk-3MUCUZ46.js.map +1 -0
- package/dist/{chunk-6VIMBFUZ.js → chunk-3RRXWX3V.js} +21 -17
- package/dist/chunk-3RRXWX3V.js.map +1 -0
- package/dist/{chunk-WHIQAGB7.js → chunk-4C67GV3O.js} +2 -2
- package/dist/{chunk-WS6OA7H6.js → chunk-4MJ52WBH.js} +2 -3
- package/dist/chunk-4MJ52WBH.js.map +1 -0
- package/dist/{chunk-AJ34GCMD.js → chunk-67GSG2ST.js} +41 -38
- package/dist/chunk-67GSG2ST.js.map +1 -0
- package/dist/{chunk-UHX4462X.js → chunk-6LLH3TBZ.js} +24 -25
- package/dist/chunk-6LLH3TBZ.js.map +1 -0
- package/dist/{chunk-DFHMB44X.js → chunk-D3AS5LY7.js} +6 -10
- package/dist/chunk-D3AS5LY7.js.map +1 -0
- package/dist/{chunk-6OUWNVLX.js → chunk-EDDT4ZIH.js} +8 -8
- package/dist/chunk-EDDT4ZIH.js.map +1 -0
- package/dist/{chunk-Z4DN527J.js → chunk-FG467PDD.js} +156 -39
- package/dist/chunk-FG467PDD.js.map +1 -0
- package/dist/{chunk-T4THB2OR.js → chunk-FOCXXIXY.js} +49 -28
- package/dist/chunk-FOCXXIXY.js.map +1 -0
- package/dist/{goal-validator-PDKYZSNP.js → chunk-GFFUDJMK.js} +97 -40
- package/dist/chunk-GFFUDJMK.js.map +1 -0
- package/dist/{chunk-ZEXMMTIQ.js → chunk-J5EMP4XW.js} +2 -2
- package/dist/{chunk-UHMMANC2.js → chunk-LT6VUZG2.js} +21 -18
- package/dist/chunk-LT6VUZG2.js.map +1 -0
- package/dist/{chunk-55CBWOEZ.js → chunk-QSWUPSLK.js} +2 -2
- package/dist/{chunk-45Y5TLQZ.js → chunk-SH7H3WRU.js} +3 -6
- package/dist/chunk-SH7H3WRU.js.map +1 -0
- package/dist/{chunk-VRLMTOB6.js → chunk-TIMIKBY2.js} +1 -1
- package/dist/chunk-TIMIKBY2.js.map +1 -0
- package/dist/{chunk-POHBQUG7.js → chunk-X3F5QDER.js} +1224 -448
- package/dist/chunk-X3F5QDER.js.map +1 -0
- package/dist/{chunk-O6OTJI3W.js → chunk-Y32FM3MR.js} +2 -2
- package/dist/{chunk-G5PRBQIQ.js → chunk-YOKQ25IW.js} +102 -82
- package/dist/chunk-YOKQ25IW.js.map +1 -0
- package/dist/{chunk-JAKMZI5S.js → chunk-Z2P4WST6.js} +291 -180
- package/dist/chunk-Z2P4WST6.js.map +1 -0
- package/dist/cli/create-agent.js +1 -1
- package/dist/cli/main.js +113 -86
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/yolo-daemon.js +19 -19
- package/dist/cli/yolo-daemon.js.map +1 -1
- package/dist/{client-BZHI675W.js → client-JTU5TRLB.js} +3 -3
- package/dist/{codebase-index-CR6Q2HEI.js → codebase-index-FNJ4GCBE.js} +3 -3
- package/dist/{goal-manager-FAK7H4RR.js → goal-manager-6BJQ36AH.js} +7 -8
- package/dist/goal-validator-GISXYANK.js +22 -0
- package/dist/{graph-PAUZ5EMP.js → graph-X2FMRQLG.js} +3 -3
- package/dist/{hypothesis-L5446W36.js → hypothesis-K3KQJOXJ.js} +7 -8
- package/dist/{incident-index-ZCDSJ42L.js → incident-index-BWW2UEY7.js} +3 -3
- package/dist/index.js +343 -288
- package/dist/index.js.map +1 -1
- package/dist/{insight-store-F5KDBY5Y.js → insight-store-A5XXMFD6.js} +6 -6
- package/dist/issue-store-BO5OWLJW.js +32 -0
- package/dist/{output-manager-BOTMXSND.js → output-manager-DZO5LGSG.js} +2 -2
- package/dist/{tiered-storage-QW2G7GSG.js → tiered-storage-VZL7KK64.js} +3 -3
- package/dist/trie-agent-XMSGMD7E.js +26 -0
- package/dist/trie-agent-XMSGMD7E.js.map +1 -0
- package/dist/ui/chat.html +260 -67
- package/dist/ui/goals.html +246 -3
- package/dist/ui/hypotheses.html +248 -5
- package/dist/ui/ledger.html +252 -9
- package/dist/ui/nudges.html +244 -1
- package/package.json +1 -1
- package/dist/chunk-45Y5TLQZ.js.map +0 -1
- package/dist/chunk-4YJ6KLGI.js.map +0 -1
- package/dist/chunk-6OUWNVLX.js.map +0 -1
- package/dist/chunk-6VIMBFUZ.js.map +0 -1
- package/dist/chunk-AJ34GCMD.js.map +0 -1
- package/dist/chunk-DFHMB44X.js.map +0 -1
- package/dist/chunk-DFPVUMVE.js.map +0 -1
- package/dist/chunk-G5PRBQIQ.js.map +0 -1
- package/dist/chunk-JAKMZI5S.js.map +0 -1
- package/dist/chunk-PEJEYWVR.js +0 -135
- package/dist/chunk-PEJEYWVR.js.map +0 -1
- package/dist/chunk-POHBQUG7.js.map +0 -1
- package/dist/chunk-T4THB2OR.js.map +0 -1
- package/dist/chunk-UHMMANC2.js.map +0 -1
- package/dist/chunk-UHX4462X.js.map +0 -1
- package/dist/chunk-VRLMTOB6.js.map +0 -1
- package/dist/chunk-WS6OA7H6.js.map +0 -1
- package/dist/chunk-Z4DN527J.js.map +0 -1
- package/dist/goal-validator-PDKYZSNP.js.map +0 -1
- package/dist/guardian-agent-4RHGIXUD.js +0 -27
- package/dist/ledger-WKVJWHBX.js +0 -17
- /package/dist/{autonomy-config-QA6ATWLJ.js.map → autonomy-config-TZ6HF4FA.js.map} +0 -0
- /package/dist/{chat-store-HFOOWZYN.js.map → chat-store-OJLJCJFI.js.map} +0 -0
- /package/dist/{chunk-WHIQAGB7.js.map → chunk-4C67GV3O.js.map} +0 -0
- /package/dist/{chunk-ZEXMMTIQ.js.map → chunk-J5EMP4XW.js.map} +0 -0
- /package/dist/{chunk-55CBWOEZ.js.map → chunk-QSWUPSLK.js.map} +0 -0
- /package/dist/{chunk-O6OTJI3W.js.map → chunk-Y32FM3MR.js.map} +0 -0
- /package/dist/{client-BZHI675W.js.map → client-JTU5TRLB.js.map} +0 -0
- /package/dist/{codebase-index-CR6Q2HEI.js.map → codebase-index-FNJ4GCBE.js.map} +0 -0
- /package/dist/{goal-manager-FAK7H4RR.js.map → goal-manager-6BJQ36AH.js.map} +0 -0
- /package/dist/{graph-PAUZ5EMP.js.map → goal-validator-GISXYANK.js.map} +0 -0
- /package/dist/{guardian-agent-4RHGIXUD.js.map → graph-X2FMRQLG.js.map} +0 -0
- /package/dist/{hypothesis-L5446W36.js.map → hypothesis-K3KQJOXJ.js.map} +0 -0
- /package/dist/{incident-index-ZCDSJ42L.js.map → incident-index-BWW2UEY7.js.map} +0 -0
- /package/dist/{insight-store-F5KDBY5Y.js.map → insight-store-A5XXMFD6.js.map} +0 -0
- /package/dist/{ledger-WKVJWHBX.js.map → issue-store-BO5OWLJW.js.map} +0 -0
- /package/dist/{output-manager-BOTMXSND.js.map → output-manager-DZO5LGSG.js.map} +0 -0
- /package/dist/{tiered-storage-QW2G7GSG.js.map → tiered-storage-VZL7KK64.js.map} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli/checkpoint.ts","../src/utils/trie-init.ts","../src/context/sync.ts","../src/utils/errors.ts","../src/skills/audit-logger.ts","../src/agent/git.ts","../src/utils/command-runner.ts","../src/agent/confidence.ts","../src/agent/learning.ts","../src/guardian/learning-engine.ts","../src/agent/perceive.ts","../src/agent/diff-analyzer.ts","../src/agent/risk-scorer.ts","../src/agent/pattern-matcher.ts","../src/orchestrator/triager.ts","../src/utils/parallel-executor.ts","../src/utils/cache-manager.ts","../src/orchestrator/executor.ts","../src/agent/reason.ts"],"sourcesContent":["/**\n * Checkpoint CLI\n * \n * Save your work context to .trie/ without running a full scan.\n * Think of it as a quick save - captures what you're working on.\n */\n\nimport { existsSync } from 'fs';\nimport { mkdir, writeFile, readFile } from 'fs/promises';\nimport { join } from 'path';\nimport { getWorkingDirectory, getTrieDirectory } from '../utils/workspace.js';\n\nexport interface Checkpoint {\n id: string;\n timestamp: string;\n message?: string;\n files: string[];\n notes?: string;\n createdBy: 'cli' | 'mcp';\n}\n\nexport interface CheckpointLog {\n checkpoints: Checkpoint[];\n lastCheckpoint?: string;\n}\n\n/**\n * Save a checkpoint\n */\nexport async function saveCheckpoint(options: {\n message?: string;\n files?: string[];\n notes?: string;\n workDir?: string;\n createdBy?: 'cli' | 'mcp';\n}): Promise<Checkpoint> {\n const workDir = options.workDir || getWorkingDirectory(undefined, true);\n const trieDir = getTrieDirectory(workDir);\n const checkpointPath = join(trieDir, 'checkpoints.json');\n \n await mkdir(trieDir, { recursive: true });\n \n // Load existing checkpoints\n let log: CheckpointLog = { checkpoints: [] };\n try {\n if (existsSync(checkpointPath)) {\n log = JSON.parse(await readFile(checkpointPath, 'utf-8'));\n }\n } catch {\n log = { checkpoints: [] };\n }\n \n // Create new checkpoint\n const checkpoint: Checkpoint = {\n id: `cp-${Date.now().toString(36)}`,\n timestamp: new Date().toISOString(),\n files: options.files || [],\n createdBy: options.createdBy || 'cli',\n };\n if (options.message) checkpoint.message = options.message;\n if (options.notes) checkpoint.notes = options.notes;\n \n // Add to log\n log.checkpoints.push(checkpoint);\n log.lastCheckpoint = checkpoint.id;\n \n // Keep last 50 checkpoints\n if (log.checkpoints.length > 50) {\n log.checkpoints = log.checkpoints.slice(-50);\n }\n \n // Save\n await writeFile(checkpointPath, JSON.stringify(log, null, 2));\n \n // Also update AGENTS.md with checkpoint note\n await updateAgentsMdWithCheckpoint(checkpoint, workDir);\n \n return checkpoint;\n}\n\n/**\n * List checkpoints\n */\nexport async function listCheckpoints(workDir?: string): Promise<Checkpoint[]> {\n const dir = workDir || getWorkingDirectory(undefined, true);\n const checkpointPath = join(getTrieDirectory(dir), 'checkpoints.json');\n \n try {\n if (existsSync(checkpointPath)) {\n const log: CheckpointLog = JSON.parse(await readFile(checkpointPath, 'utf-8'));\n return log.checkpoints;\n }\n } catch {\n // File doesn't exist or is corrupted\n }\n \n return [];\n}\n\n/**\n * Get the last checkpoint\n */\nexport async function getLastCheckpoint(workDir?: string): Promise<Checkpoint | null> {\n const checkpoints = await listCheckpoints(workDir);\n const last = checkpoints[checkpoints.length - 1];\n return last ?? null;\n}\n\n/**\n * Update AGENTS.md with checkpoint info\n */\nasync function updateAgentsMdWithCheckpoint(checkpoint: Checkpoint, workDir: string): Promise<void> {\n const agentsPath = join(getTrieDirectory(workDir), 'AGENTS.md');\n \n let content = '';\n try {\n if (existsSync(agentsPath)) {\n content = await readFile(agentsPath, 'utf-8');\n }\n } catch {\n content = '';\n }\n \n // Find or create checkpoint section\n const checkpointSection = `\n## Last Checkpoint\n\n- **ID:** ${checkpoint.id}\n- **Time:** ${checkpoint.timestamp}\n${checkpoint.message ? `- **Message:** ${checkpoint.message}` : ''}\n${checkpoint.files.length > 0 ? `- **Files:** ${checkpoint.files.length} files` : ''}\n${checkpoint.notes ? `- **Notes:** ${checkpoint.notes}` : ''}\n`;\n \n // Replace existing checkpoint section or append\n const checkpointRegex = /## Last Checkpoint[\\s\\S]*?(?=\\n## |\\n---|\\Z)/;\n if (checkpointRegex.test(content)) {\n content = content.replace(checkpointRegex, checkpointSection.trim());\n } else {\n content = content.trim() + '\\n\\n' + checkpointSection.trim() + '\\n';\n }\n \n await writeFile(agentsPath, content);\n}\n\n/**\n * CLI handler for checkpoint command\n */\nexport async function handleCheckpointCommand(args: string[]): Promise<void> {\n const subcommand = args[0] || 'save';\n \n switch (subcommand) {\n case 'save': {\n // Parse options\n let message: string | undefined;\n let notes: string | undefined;\n const files: string[] = [];\n \n for (let i = 1; i < args.length; i++) {\n const arg = args[i];\n if (arg === '-m' || arg === '--message') {\n message = args[++i] ?? '';\n } else if (arg === '-n' || arg === '--notes') {\n notes = args[++i] ?? '';\n } else if (arg === '-f' || arg === '--file') {\n const file = args[++i];\n if (file) files.push(file);\n } else if (arg && !arg.startsWith('-')) {\n // Treat as message if no flag\n message = arg;\n }\n }\n \n const opts: { message?: string; files?: string[]; notes?: string } = { files };\n if (message) opts.message = message;\n if (notes) opts.notes = notes;\n const checkpoint = await saveCheckpoint(opts);\n \n console.log('\\n Checkpoint saved\\n');\n console.log(` ID: ${checkpoint.id}`);\n console.log(` Time: ${checkpoint.timestamp}`);\n if (checkpoint.message) {\n console.log(` Message: ${checkpoint.message}`);\n }\n if (checkpoint.files.length > 0) {\n console.log(` Files: ${checkpoint.files.join(', ')}`);\n }\n console.log('\\n Context saved to .trie/\\n');\n break;\n }\n \n case 'list': {\n const checkpoints = await listCheckpoints();\n \n if (checkpoints.length === 0) {\n console.log('\\n No checkpoints yet. Run `trie checkpoint` to save one.\\n');\n return;\n }\n \n console.log('\\n Checkpoints:\\n');\n for (const cp of checkpoints.slice(-10).reverse()) {\n const date = new Date(cp.timestamp).toLocaleString();\n console.log(` ${cp.id} ${date} ${cp.message || '(no message)'}`);\n }\n console.log('');\n break;\n }\n \n case 'last': {\n const checkpoint = await getLastCheckpoint();\n \n if (!checkpoint) {\n console.log('\\n No checkpoints yet. Run `trie checkpoint` to save one.\\n');\n return;\n }\n \n console.log('\\n Last Checkpoint:\\n');\n console.log(` ID: ${checkpoint.id}`);\n console.log(` Time: ${new Date(checkpoint.timestamp).toLocaleString()}`);\n if (checkpoint.message) {\n console.log(` Message: ${checkpoint.message}`);\n }\n if (checkpoint.notes) {\n console.log(` Notes: ${checkpoint.notes}`);\n }\n if (checkpoint.files.length > 0) {\n console.log(` Files: ${checkpoint.files.join(', ')}`);\n }\n console.log('');\n break;\n }\n \n default:\n console.log(`\n Usage: trie checkpoint [command] [options]\n\n Commands:\n save [message] Save a checkpoint (default)\n list List recent checkpoints\n last Show the last checkpoint\n\n Options:\n -m, --message Checkpoint message\n -n, --notes Additional notes\n -f, --file File to include (can be repeated)\n\n Examples:\n trie checkpoint \"finished auth flow\"\n trie checkpoint save -m \"WIP: payment integration\" -n \"needs testing\"\n trie checkpoint list\n`);\n }\n}\n","import { existsSync } from 'fs';\nimport { join } from 'path';\nimport { getWorkingDirectory, getTrieDirectory } from './workspace.js';\n\nconst INIT_MARKERS = [\n 'PROJECT.md',\n 'RULES.md',\n 'TEAM.md',\n 'BOOTSTRAP.md',\n 'AGENTS.md',\n 'config.json',\n];\n\nexport function isTrieInitialized(workDir?: string): boolean {\n const dir = workDir || getWorkingDirectory(undefined, true);\n const trieDir = getTrieDirectory(dir);\n return INIT_MARKERS.some((marker) => existsSync(join(trieDir, marker)));\n}\n","import fs from 'node:fs/promises';\nimport path from 'node:path';\nimport { getTrieDirectory } from '../utils/workspace.js';\n\nimport { ContextGraph } from './graph.js';\nimport type { ContextSnapshot } from './types.js';\n\nconst DEFAULT_JSON_NAME = 'context.json';\n\nexport async function exportToJson(graph: ContextGraph, targetPath?: string): Promise<string> {\n const snapshot = await graph.getSnapshot();\n const json = JSON.stringify(snapshot, null, 2);\n\n const outputPath = targetPath ?? path.join(getTrieDirectory(graph.projectRoot), DEFAULT_JSON_NAME);\n await fs.mkdir(path.dirname(outputPath), { recursive: true });\n await fs.writeFile(outputPath, json, 'utf8');\n\n return json;\n}\n\nexport async function importFromJson(\n graph: ContextGraph,\n json: string,\n sourcePath?: string\n): Promise<void> {\n const payload =\n json.trim().length > 0\n ? json\n : await fs.readFile(sourcePath ?? path.join(getTrieDirectory(graph.projectRoot), DEFAULT_JSON_NAME), 'utf8');\n\n const snapshot = JSON.parse(payload) as ContextSnapshot;\n await graph.applySnapshot(snapshot);\n}\n","export class TrieError extends Error {\n code: string;\n recoverable: boolean;\n userMessage: string;\n\n constructor(message: string, code: string, userMessage: string, recoverable = true) {\n super(message);\n this.code = code;\n this.recoverable = recoverable;\n this.userMessage = userMessage;\n }\n}\n\nexport class GraphError extends TrieError {\n constructor(message: string) {\n super(\n message,\n 'GRAPH_ERROR',\n 'Trie had trouble accessing its memory. Try again or re-run trie reconcile.',\n true\n );\n }\n}\n\nexport class GitError extends TrieError {\n constructor(message: string) {\n super(\n message,\n 'GIT_ERROR',\n 'Git info is unavailable. Is this a git repo? Commit once, or pass --files to trie check.',\n true\n );\n }\n}\n\nexport class NetworkError extends TrieError {\n constructor(message: string) {\n super(\n message,\n 'NETWORK_ERROR',\n 'Network unavailable. Running in offline mode; AI calls skipped.',\n true\n );\n }\n}\n\nexport class MissingAPIKeyError extends TrieError {\n constructor(message = 'Missing ANTHROPIC_API_KEY') {\n super(\n message,\n 'MISSING_API_KEY',\n 'No API key detected. Set ANTHROPIC_API_KEY for AI-powered analysis (deeper issue detection, smarter fixes). Running in pattern-only mode.',\n true\n );\n }\n}\n\nexport function formatFriendlyError(error: unknown): { userMessage: string; code: string } {\n if (error instanceof TrieError) {\n return { userMessage: error.userMessage, code: error.code };\n }\n return {\n userMessage: 'Something went wrong. Try again or run with --offline.',\n code: 'UNKNOWN'\n };\n}\n","/**\n * Audit logger stub\n * Audit functionality has been integrated into decision ledger\n */\n\nexport interface AuditStatistics {\n totalScans: number;\n totalIssues: number;\n criticalCount: number;\n seriousCount: number;\n moderateCount: number;\n lowCount: number;\n totalExecutions: number;\n successfulExecutions: number;\n failedExecutions: number;\n uniqueSkills: number;\n totalCommands: number;\n blockedCommands: number;\n totalNetworkCalls: number;\n blockedNetworkCalls: number;\n}\n\nexport interface AuditEntry {\n id: string;\n timestamp: string;\n command: string;\n status: string;\n commands?: ExecutedCommand[];\n}\n\nexport interface ExecutedCommand {\n command: string;\n timestamp: string;\n exitCode?: number;\n duration?: number;\n stdout?: string;\n stderr?: string;\n}\n\nexport interface SkillExecution {\n skillName: string;\n skillSource: string;\n triggeredBy: 'scan' | 'mcp' | 'cli' | 'watch' | 'manual';\n targetPath: string;\n startedAt: string;\n completedAt?: string;\n success?: boolean;\n error?: string;\n commands?: ExecutedCommand[];\n}\n\nexport function formatAuditLog(_entry: AuditEntry): string {\n return 'Audit logging has been integrated into the decision ledger';\n}\n\nexport function getAuditStatistics(): AuditStatistics {\n return {\n totalScans: 0,\n totalIssues: 0,\n criticalCount: 0,\n seriousCount: 0,\n moderateCount: 0,\n lowCount: 0,\n totalExecutions: 0,\n successfulExecutions: 0,\n failedExecutions: 0,\n uniqueSkills: 0,\n totalCommands: 0,\n blockedCommands: 0,\n totalNetworkCalls: 0,\n blockedNetworkCalls: 0,\n };\n}\n\nexport function createAuditEntry(\n skillName: string, \n skillSource: string, \n triggeredBy: SkillExecution['triggeredBy'], \n targetPath: string\n): SkillExecution {\n return {\n skillName,\n skillSource,\n triggeredBy,\n targetPath,\n startedAt: new Date().toISOString(),\n commands: [],\n };\n}\n\nexport function completeAuditEntry(\n entry: SkillExecution, \n success: boolean, \n error?: string\n): SkillExecution {\n const result: SkillExecution = {\n ...entry,\n completedAt: new Date().toISOString(),\n success,\n };\n if (error !== undefined) {\n result.error = error;\n }\n return result;\n}\n\nexport async function logSkillExecution(_execution: SkillExecution): Promise<void> {\n // Stub - no-op\n}\n\nexport async function getRecentAuditLogs(_limit: number = 10): Promise<AuditEntry[]> {\n return [];\n}\n\nexport async function getSkillAuditLogs(_skillName: string): Promise<AuditEntry[]> {\n return [];\n}\n","import { existsSync } from 'node:fs';\nimport path from 'node:path';\nimport { runExecFile } from '../utils/command-runner.js';\n\nexport interface Commit {\n hash: string;\n author: string;\n date: string;\n message: string;\n}\n\nexport interface Change {\n path: string;\n status: string;\n oldPath?: string;\n}\n\nasync function execGit(args: string[], cwd: string): Promise<string | null> {\n try {\n const { stdout } = await runExecFile(\n 'git',\n ['-C', cwd, ...args],\n { actor: 'internal:git', triggeredBy: 'manual', targetPath: cwd },\n { maxBuffer: 10 * 1024 * 1024, captureOutput: false }\n );\n return stdout.trim();\n } catch (error: any) {\n const stderr: string | undefined = error?.stderr?.toString();\n // Gracefully handle non-git directories and repos with no commits\n if (stderr?.includes('not a git repository') || stderr?.includes('does not have any commits')) {\n return null;\n }\n throw error;\n }\n}\n\nasync function ensureRepo(projectPath: string): Promise<boolean> {\n const result = await execGit(['rev-parse', '--is-inside-work-tree'], projectPath);\n return result === 'true';\n}\n\nfunction parseNameStatus(output: string): Change[] {\n return output\n .split('\\n')\n .map((line) => line.trim())\n .filter(Boolean)\n .map((line) => {\n const parts = line.split('\\t');\n const status = parts[0] ?? '';\n const filePath = parts[1] ?? '';\n const oldPath = parts[2];\n const change: Change = { status, path: filePath };\n if (oldPath) change.oldPath = oldPath;\n return change;\n })\n .filter((entry) => entry.path.length > 0);\n}\n\nexport async function getRecentCommits(projectPath: string, limit: number): Promise<Commit[]> {\n const isRepo = await ensureRepo(projectPath);\n if (!isRepo) return [];\n\n const output = await execGit(\n ['log', `-n`, String(limit), '--pretty=format:%H%x09%an%x09%ad%x09%s', '--date=iso'],\n projectPath\n );\n\n if (!output) return [];\n\n return output.split('\\n').map((line) => {\n const [hash, author, date, message] = line.split('\\t');\n return { hash, author, date, message } as Commit;\n });\n}\n\nexport async function getLastCommit(projectPath: string): Promise<Commit | null> {\n const commits = await getRecentCommits(projectPath, 1);\n return commits[0] ?? null;\n}\n\nexport async function getStagedChanges(projectPath: string): Promise<Change[]> {\n const isRepo = await ensureRepo(projectPath);\n if (!isRepo) return [];\n\n const output = await execGit(['diff', '--cached', '--name-status'], projectPath);\n if (!output) return [];\n return parseNameStatus(output);\n}\n\nexport async function getUncommittedChanges(projectPath: string): Promise<Change[]> {\n const isRepo = await ensureRepo(projectPath);\n if (!isRepo) return [];\n\n const changes: Change[] = [];\n\n const unstaged = await execGit(['diff', '--name-status'], projectPath);\n if (unstaged) {\n changes.push(...parseNameStatus(unstaged));\n }\n\n const untracked = await execGit(['ls-files', '--others', '--exclude-standard'], projectPath);\n if (untracked) {\n changes.push(\n ...untracked\n .split('\\n')\n .map((p) => p.trim())\n .filter(Boolean)\n .map((p) => ({ status: '??', path: p }))\n );\n }\n\n return changes;\n}\n\n/**\n * Get a flat list of changed file paths in the working tree.\n * Convenience helper used by tooling (e.g. cache invalidation).\n *\n * Returns null if not a git repository.\n */\nexport async function getGitChangedFiles(projectPath: string): Promise<string[] | null> {\n const isRepo = await ensureRepo(projectPath);\n if (!isRepo) return null;\n\n const [staged, uncommitted] = await Promise.all([\n getStagedChanges(projectPath).catch(() => []),\n getUncommittedChanges(projectPath).catch(() => []),\n ]);\n\n const paths = new Set<string>();\n for (const change of [...staged, ...uncommitted]) {\n if (change.path) paths.add(change.path);\n if (change.oldPath) paths.add(change.oldPath);\n }\n\n return [...paths];\n}\n\nexport async function getDiff(projectPath: string, commitHash: string): Promise<string> {\n const isRepo = await ensureRepo(projectPath);\n if (!isRepo) return '';\n\n const diff = await execGit(['show', commitHash, '--unified=3', '--no-color'], projectPath);\n return diff ?? '';\n}\n\nexport async function getWorkingTreeDiff(projectPath: string, stagedOnly = false): Promise<string> {\n const isRepo = await ensureRepo(projectPath);\n if (!isRepo) return '';\n\n const args = stagedOnly ? ['diff', '--cached', '--unified=3', '--no-color'] : ['diff', '--unified=3', '--no-color'];\n const diff = await execGit(args, projectPath);\n return diff ?? '';\n}\n\nexport async function getUnpushedCommits(projectPath: string): Promise<Commit[]> {\n const isRepo = await ensureRepo(projectPath);\n if (!isRepo) return [];\n\n // Handles detached HEAD by falling back to HEAD if upstream missing\n const upstream = await execGit(['rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{u}'], projectPath);\n if (!upstream) {\n return getRecentCommits(projectPath, 10);\n }\n\n const output = await execGit(['log', `${upstream}..HEAD`, '--pretty=format:%H%x09%an%x09%ad%x09%s', '--date=iso'], projectPath);\n if (!output) return [];\n\n return output.split('\\n').filter(Boolean).map((line) => {\n const [hash, author, date, message] = line.split('\\t');\n return { hash, author, date, message } as Commit;\n });\n}\n\nexport function resolveRepoPath(projectPath: string): string {\n const gitDir = path.join(projectPath, '.git');\n if (existsSync(gitDir)) return projectPath;\n return projectPath;\n}\n\n/**\n * Check if the given path is inside a git repository\n */\nexport async function isGitRepo(projectPath: string): Promise<boolean> {\n const result = await execGit(['rev-parse', '--is-inside-work-tree'], projectPath);\n return result === 'true';\n}\n\n/**\n * Get files changed since a given timestamp\n * Uses git log to find commits after timestamp, then gets affected files\n * Returns null if not a git repo or on error\n */\nexport async function getChangedFilesSinceTimestamp(\n projectPath: string,\n timestamp: number\n): Promise<string[] | null> {\n const isRepo = await isGitRepo(projectPath);\n if (!isRepo) return null;\n\n try {\n // Convert timestamp to ISO date for git\n const sinceDate = new Date(timestamp).toISOString();\n \n // Set timeout for git operations (5 seconds total)\n const GIT_TIMEOUT_MS = 5000;\n const startTime = Date.now();\n \n // Get all files that changed in commits since the timestamp\n // Use Promise.race to timeout if git operations take too long\n const committedChangesPromise = execGit(\n ['log', `--since=${sinceDate}`, '--name-only', '--pretty=format:'],\n projectPath\n );\n const committedChangesTimeout = new Promise<string | null>((resolve) => {\n setTimeout(() => resolve(null), GIT_TIMEOUT_MS);\n });\n const committedChanges = await Promise.race([committedChangesPromise, committedChangesTimeout]);\n\n // Check if we've exceeded timeout\n if (Date.now() - startTime > GIT_TIMEOUT_MS) {\n return null;\n }\n\n // Get currently modified files (staged + unstaged) - run in parallel with timeout\n const stagedPromise = execGit(['diff', '--cached', '--name-only'], projectPath);\n const unstagedPromise = execGit(['diff', '--name-only'], projectPath);\n const untrackedPromise = execGit(\n ['ls-files', '--others', '--exclude-standard'],\n projectPath\n );\n \n const timeoutPromise = new Promise<null>((resolve) => {\n setTimeout(() => resolve(null), Math.max(0, GIT_TIMEOUT_MS - (Date.now() - startTime)));\n });\n \n const [stagedChanges, unstagedChanges, untrackedFiles] = await Promise.race([\n Promise.all([stagedPromise, unstagedPromise, untrackedPromise]),\n timeoutPromise.then(() => [null, null, null] as const)\n ]);\n\n // Combine all changed files\n const changedFiles = new Set<string>();\n \n const addFiles = (output: string | null) => {\n if (output) {\n output.split('\\n')\n .map(f => f.trim())\n .filter(Boolean)\n .forEach(f => changedFiles.add(path.join(projectPath, f)));\n }\n };\n\n addFiles(committedChanges);\n addFiles(stagedChanges);\n addFiles(unstagedChanges);\n addFiles(untrackedFiles);\n\n return Array.from(changedFiles);\n } catch {\n return null;\n }\n}\n","/**\n * Command Runner (with audit logging)\n *\n * Goal: Whenever Trie runs a shell command, record:\n * - command string\n * - exit code\n * - duration\n * - optional (redacted) stdout/stderr\n */\nimport { exec, execFile, execSync, type ExecException } from 'node:child_process';\nimport { promisify } from 'node:util';\n\nimport {\n createAuditEntry,\n completeAuditEntry,\n logSkillExecution,\n type ExecutedCommand,\n type SkillExecution,\n} from '../skills/audit-logger.js';\n\nconst execAsync = promisify(exec);\nconst execFileAsync = promisify(execFile);\n\nexport type { ExecutedCommand, SkillExecution };\nexport type AuditTriggeredBy = SkillExecution['triggeredBy'];\n\nexport interface CommandAuditContext {\n /** Shown as `skillName` in audit logs; use something like `tool:pr-review` */\n actor: string;\n /** Where this came from in the product flow */\n triggeredBy: AuditTriggeredBy;\n /** Usually the working directory / repo path */\n targetPath: string;\n /** Optional string for `skillSource` */\n source?: string;\n}\n\nexport interface RunCommandOptions {\n cwd?: string;\n timeoutMs?: number;\n maxBuffer?: number;\n\n /** Capture stdout/stderr in the audit log */\n captureOutput?: boolean;\n /** Redact obvious secrets from captured output */\n redactOutput?: boolean;\n /** Max chars to keep per output stream */\n maxOutputChars?: number;\n}\n\nfunction redact(text: string): string {\n // Keep this conservative to avoid false redaction and avoid expensive processing.\n return text\n // Common key=value secrets\n .replace(/\\b(AWS|ANTHROPIC|OPENAI|GITHUB)_[A-Z0-9_]*\\s*=\\s*([^\\s\"'`]+)/gi, '$1_<REDACTED>=<REDACTED>')\n // Bearer tokens\n .replace(/\\bBearer\\s+[A-Za-z0-9\\-._~+/]+=*\\b/g, 'Bearer <REDACTED>')\n // GitHub tokens / generic tokens\n .replace(/\\bghp_[A-Za-z0-9]{20,}\\b/g, 'ghp_<REDACTED>')\n .replace(/\\b(?:xox[baprs]-)[A-Za-z0-9-]{10,}\\b/g, '<REDACTED_SLACK_TOKEN>')\n // AWS access key id (best-effort)\n .replace(/\\bAKIA[0-9A-Z]{16}\\b/g, 'AKIA<REDACTED>');\n}\n\nfunction clampOutput(text: string, maxChars: number): string {\n if (text.length <= maxChars) return text;\n return text.slice(0, maxChars) + `\\n…(truncated ${text.length - maxChars} chars)`;\n}\n\nfunction buildCommandRecord(command: string): ExecutedCommand {\n return {\n command,\n timestamp: new Date().toISOString(),\n };\n}\n\nasync function finalizeAndWrite(\n entry: SkillExecution,\n cmd: ExecutedCommand,\n outcome: { success: boolean; exitCode?: number; stdout?: string; stderr?: string; error?: string; startedAt: number },\n options?: Pick<RunCommandOptions, 'captureOutput' | 'redactOutput' | 'maxOutputChars'>\n): Promise<void> {\n const duration = Date.now() - outcome.startedAt;\n cmd.duration = duration;\n if (outcome.exitCode !== undefined) {\n cmd.exitCode = outcome.exitCode;\n }\n\n const captureOutput = options?.captureOutput ?? false;\n const redactOutput = options?.redactOutput ?? true;\n const maxOutputChars = options?.maxOutputChars ?? 2000;\n\n if (captureOutput) {\n const out = outcome.stdout ?? '';\n const err = outcome.stderr ?? '';\n cmd.stdout = redactOutput ? redact(clampOutput(out, maxOutputChars)) : clampOutput(out, maxOutputChars);\n cmd.stderr = redactOutput ? redact(clampOutput(err, maxOutputChars)) : clampOutput(err, maxOutputChars);\n }\n\n const completed = completeAuditEntry(entry, outcome.success, outcome.error);\n await logSkillExecution(completed);\n}\n\nexport async function runShellCommand(\n command: string,\n audit: CommandAuditContext,\n options?: RunCommandOptions\n): Promise<{ stdout: string; stderr: string; exitCode: number }> {\n const startedAt = Date.now();\n const entry = createAuditEntry(audit.actor, audit.source ?? 'trie', audit.triggeredBy, audit.targetPath);\n const cmd = buildCommandRecord(command);\n entry.commands?.push(cmd);\n\n try {\n const { stdout, stderr } = await execAsync(command, {\n cwd: options?.cwd,\n timeout: options?.timeoutMs,\n maxBuffer: options?.maxBuffer,\n });\n\n await finalizeAndWrite(entry, cmd, { success: true, exitCode: 0, stdout, stderr, startedAt }, options);\n return { stdout: stdout ?? '', stderr: stderr ?? '', exitCode: 0 };\n } catch (e) {\n const err = e as ExecException & { stdout?: unknown; stderr?: unknown; code?: unknown };\n const stdout = typeof err.stdout === 'string' ? err.stdout : '';\n const stderr = typeof err.stderr === 'string' ? err.stderr : '';\n const exitCode = typeof err.code === 'number' ? err.code : 1;\n\n await finalizeAndWrite(\n entry,\n cmd,\n { success: false, exitCode, stdout, stderr, error: err.message, startedAt },\n // Capture output for failures by default (so audits are useful)\n { ...options, captureOutput: options?.captureOutput ?? true }\n );\n\n return { stdout, stderr, exitCode };\n }\n}\n\nexport function runShellCommandSync(\n command: string,\n audit: CommandAuditContext,\n options?: Omit<RunCommandOptions, 'timeoutMs'> & { timeoutMs?: number }\n): { stdout: string; exitCode: number } {\n const startedAt = Date.now();\n const entry = createAuditEntry(audit.actor, audit.source ?? 'trie', audit.triggeredBy, audit.targetPath);\n const cmd = buildCommandRecord(command);\n entry.commands?.push(cmd);\n\n try {\n const stdout = execSync(command, {\n cwd: options?.cwd,\n timeout: options?.timeoutMs,\n maxBuffer: options?.maxBuffer,\n encoding: 'utf-8',\n stdio: ['pipe', 'pipe', 'pipe'],\n });\n\n // Fire-and-forget write; sync APIs can’t await.\n void finalizeAndWrite(entry, cmd, { success: true, exitCode: 0, stdout, stderr: '', startedAt }, options);\n return { stdout: stdout ?? '', exitCode: 0 };\n } catch (e) {\n const err = e as ExecException & { stdout?: unknown; stderr?: unknown; status?: unknown };\n const stdout = typeof err.stdout === 'string' ? err.stdout : '';\n const stderr = typeof err.stderr === 'string' ? err.stderr : '';\n const exitCode = typeof err.status === 'number' ? err.status : 1;\n\n void finalizeAndWrite(\n entry,\n cmd,\n { success: false, exitCode, stdout, stderr, error: err.message, startedAt },\n { ...options, captureOutput: options?.captureOutput ?? true }\n );\n\n return { stdout, exitCode };\n }\n}\n\nexport async function runExecFile(\n file: string,\n args: string[],\n audit: CommandAuditContext,\n options?: Omit<RunCommandOptions, 'timeoutMs'> & { timeoutMs?: number }\n): Promise<{ stdout: string; stderr: string; exitCode: number }> {\n const startedAt = Date.now();\n const command = [file, ...args].join(' ');\n const entry = createAuditEntry(audit.actor, audit.source ?? 'trie', audit.triggeredBy, audit.targetPath);\n const cmd = buildCommandRecord(command);\n entry.commands?.push(cmd);\n\n try {\n const { stdout, stderr } = await execFileAsync(file, args, {\n cwd: options?.cwd,\n timeout: options?.timeoutMs,\n maxBuffer: options?.maxBuffer,\n });\n\n await finalizeAndWrite(entry, cmd, { success: true, exitCode: 0, stdout: String(stdout ?? ''), stderr: String(stderr ?? ''), startedAt }, options);\n return { stdout: String(stdout ?? ''), stderr: String(stderr ?? ''), exitCode: 0 };\n } catch (e) {\n const err = e as ExecException & { stdout?: unknown; stderr?: unknown; code?: unknown };\n const stdout = typeof err.stdout === 'string' ? err.stdout : '';\n const stderr = typeof err.stderr === 'string' ? err.stderr : '';\n const exitCode = typeof err.code === 'number' ? err.code : 1;\n\n await finalizeAndWrite(\n entry,\n cmd,\n { success: false, exitCode, stdout, stderr, error: err.message, startedAt },\n { ...options, captureOutput: options?.captureOutput ?? true }\n );\n return { stdout, stderr, exitCode };\n }\n}\n\n","/**\n * Lightweight Bayesian-style confidence updater.\n * Treats confidence as probability in [0,1].\n */\n\nexport function bayesianUpdate(prior: number, evidence: number, weight = 1): number {\n const p = clamp(prior);\n const e = clamp(evidence);\n const w = Math.max(0, weight);\n // Blend prior with evidence weighted by w\n const posterior = (p * (1 - w)) + (e * w);\n return clamp(posterior);\n}\n\nexport function adjustConfidence(current: number, outcome: 'positive' | 'negative', step = 0.1): number {\n const delta = outcome === 'positive' ? step : -step;\n return clamp(current + delta);\n}\n\nfunction clamp(value: number): number {\n if (Number.isNaN(value)) return 0.5;\n return Math.min(1, Math.max(0, value));\n}\n","import { ContextGraph } from '../context/graph.js';\nimport type { IncidentNode, PatternNode } from '../context/nodes.js';\nimport { IncidentIndex } from '../context/incident-index.js';\nimport { adjustConfidence } from './confidence.js';\nimport { TriePatternDiscovery } from './pattern-discovery.js';\n\nexport class LearningSystem {\n private incidentIndex: IncidentIndex;\n private discovery: TriePatternDiscovery;\n\n constructor(private graph: ContextGraph, projectPath: string) {\n this.incidentIndex = new IncidentIndex(graph, projectPath);\n this.discovery = new TriePatternDiscovery(graph, this.incidentIndex);\n }\n\n async onWarningHeeded(files: string[]): Promise<void> {\n await this.adjustPatterns(files, 'positive');\n }\n\n async onWarningIgnored(files: string[]): Promise<void> {\n await this.adjustPatterns(files, 'negative');\n }\n\n async onIncidentReported(incidentId: string, files: string[]): Promise<void> {\n const incident = await this.graph.getNode('incident', incidentId);\n if (incident && incident.type === 'incident') {\n this.incidentIndex.addIncidentToTrie(incident as IncidentNode, files);\n }\n await this.discoverAndStorePatterns();\n }\n\n async onFeedback(helpful: boolean, files: string[] = []): Promise<void> {\n await this.adjustPatterns(files, helpful ? 'positive' : 'negative');\n }\n\n private async adjustPatterns(files: string[], outcome: 'positive' | 'negative'): Promise<void> {\n if (!files.length) return;\n for (const file of files) {\n const patterns = await this.graph.getPatternsForFile(file);\n await Promise.all(patterns.map((p) => this.updatePatternConfidence(p, outcome)));\n }\n }\n\n private async updatePatternConfidence(pattern: PatternNode, outcome: 'positive' | 'negative'): Promise<void> {\n const current = pattern.data.confidence ?? 0.5;\n const updated = adjustConfidence(current, outcome, 0.05);\n await this.graph.updateNode('pattern', pattern.id, { confidence: updated, lastSeen: new Date().toISOString() });\n }\n\n private async discoverAndStorePatterns(): Promise<void> {\n const hotPatterns = this.discovery.discoverHotPatterns();\n for (const hot of hotPatterns) {\n await this.graph.addNode('pattern', {\n description: `${hot.type === 'directory' ? 'Directory' : 'File'} hot zone: ${hot.path}`,\n appliesTo: [hot.path],\n confidence: hot.confidence,\n occurrences: hot.incidentCount,\n firstSeen: new Date().toISOString(),\n lastSeen: new Date().toISOString(),\n isAntiPattern: true,\n source: 'local'\n });\n }\n }\n}\n","import { getRecentCommits, getDiff } from '../agent/git.js';\nimport { storeIssues } from '../memory/issue-store.js';\nimport { scanForVulnerabilities } from '../trie/vulnerability-signatures.js';\nimport { scanForVibeCodeIssues } from '../trie/vibe-code-signatures.js';\nimport type { Issue } from '../types/index.js';\nimport { ContextGraph } from '../context/graph.js';\nimport type { DecisionNodeData } from '../context/nodes.js';\nimport { LearningSystem } from '../agent/learning.js';\nimport path from 'node:path';\n\nexport interface LearningResult {\n learned: number;\n source: 'git-history' | 'manual-feedback';\n}\n\nexport class LearningEngine {\n private readonly projectPath: string;\n private readonly graph: ContextGraph;\n private readonly learningSystem: LearningSystem;\n\n constructor(projectPath: string, graph?: ContextGraph) {\n this.projectPath = projectPath;\n this.graph = graph || new ContextGraph(projectPath);\n this.learningSystem = new LearningSystem(this.graph, projectPath);\n }\n\n /**\n * Unified learning method: Scans history AND processes manual feedback\n */\n async learn(options: { \n limit?: number; \n manualFeedback?: { helpful: boolean; files: string[]; note?: string } \n } = {}): Promise<LearningResult[]> {\n const results: LearningResult[] = [];\n\n // 1. Implicit Learning from Git History\n if (!options.manualFeedback) {\n const implicitCount = await this.learnFromHistory(options.limit || 20);\n results.push({ learned: implicitCount, source: 'git-history' });\n }\n\n // 2. Manual Feedback Learning\n if (options.manualFeedback) {\n await this.recordManualFeedback(\n options.manualFeedback.helpful, \n options.manualFeedback.files, \n options.manualFeedback.note\n );\n results.push({ learned: options.manualFeedback.files.length || 1, source: 'manual-feedback' });\n }\n\n return results;\n }\n\n /**\n * Scan recent commits for implicit failure signals (reverts, fixes)\n */\n private async learnFromHistory(limit: number = 20): Promise<number> {\n const commits = await getRecentCommits(this.projectPath, limit);\n const issuesToStore: Issue[] = [];\n\n for (const commit of commits) {\n const isRevert = commit.message.toLowerCase().includes('revert') || commit.message.startsWith('Revert \"');\n const isFix = /fix(es|ed)?\\s+#\\d+/i.test(commit.message) || commit.message.toLowerCase().includes('bugfix');\n\n if (isRevert || isFix) {\n const type = isRevert ? 'revert' : 'fix';\n const diff = await getDiff(this.projectPath, commit.hash);\n const files = this.extractFilesFromDiff(diff);\n \n for (const file of files) {\n const learnedIssues = await this.extractIssuesFromDiff(diff, file, type, commit.message);\n issuesToStore.push(...learnedIssues);\n }\n }\n }\n\n if (issuesToStore.length > 0) {\n const result = await storeIssues(issuesToStore, path.basename(this.projectPath), this.projectPath);\n return result.stored;\n }\n\n return 0;\n }\n\n /**\n * Record manual feedback (trie ok/bad) and adjust pattern confidence\n */\n private async recordManualFeedback(helpful: boolean, files: string[], note?: string): Promise<void> {\n const context = files[0] ?? 'unspecified';\n const decision = await this.graph.addNode('decision', {\n context,\n decision: helpful ? 'helpful' : 'not helpful',\n reasoning: note ?? null,\n outcome: helpful ? 'good' : 'bad',\n timestamp: new Date().toISOString(),\n } satisfies DecisionNodeData);\n\n if (files.length > 0) {\n for (const file of files) {\n const fileNode = await this.graph.getNode('file', file);\n if (fileNode) {\n await this.graph.addEdge(decision.id, fileNode.id, 'affects');\n }\n }\n await this.learningSystem.onFeedback(helpful, files);\n }\n }\n\n private extractFilesFromDiff(diff: string): string[] {\n const files = new Set<string>();\n const lines = diff.split('\\n');\n for (const line of lines) {\n if (line.startsWith('+++ b/')) {\n files.add(line.slice(6));\n }\n }\n return Array.from(files);\n }\n\n private async extractIssuesFromDiff(diff: string, file: string, type: 'revert' | 'fix', message: string): Promise<Issue[]> {\n const issues: Issue[] = [];\n const badLines = this.getBadLinesFromDiff(diff, file, type);\n const content = badLines.join('\\n');\n\n if (!content) return [];\n\n const vulnerabilities = await scanForVulnerabilities(content, file);\n const vibeIssues = await scanForVibeCodeIssues(content, file);\n\n const allMatches = [...vulnerabilities, ...vibeIssues];\n\n for (const match of allMatches) {\n issues.push({\n id: `implicit-${type}-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`,\n severity: 'serious',\n issue: `Implicit failure detected via ${type}: ${message}. Linked to pattern: ${match.category}`,\n fix: `Review the ${type} commit and avoid this pattern in ${file}.`,\n file: file,\n confidence: 0.7,\n autoFixable: false,\n agent: 'implicit-learning',\n category: match.category\n });\n }\n\n if (issues.length === 0) {\n issues.push({\n id: `implicit-${type}-${Date.now()}`,\n severity: 'moderate',\n issue: `Historical ${type} detected: ${message}`,\n fix: `Review the changes in ${file} from this commit to avoid regression.`,\n file: file,\n confidence: 0.5,\n autoFixable: false,\n agent: 'implicit-learning'\n });\n }\n\n return issues;\n }\n\n private getBadLinesFromDiff(diff: string, file: string, type: 'revert' | 'fix'): string[] {\n const badLines: string[] = [];\n const lines = diff.split('\\n');\n let inTargetFile = false;\n\n for (const line of lines) {\n if (line.startsWith('+++ b/') || line.startsWith('--- a/')) {\n inTargetFile = line.includes(file);\n continue;\n }\n\n if (!inTargetFile) continue;\n\n if (type === 'fix' && line.startsWith('-') && !line.startsWith('---')) {\n badLines.push(line.slice(1));\n } else if (type === 'revert' && line.startsWith('+') && !line.startsWith('+++')) {\n badLines.push(line.slice(1));\n }\n }\n\n return badLines;\n }\n}\n","import path from 'node:path';\n\nimport { analyzeDiff, type DiffSummary } from './diff-analyzer.js';\nimport {\n getStagedChanges,\n getUncommittedChanges,\n getWorkingTreeDiff,\n type Change\n} from './git.js';\nimport { ContextGraph } from '../context/graph.js';\nimport type { FileNode, FileNodeData } from '../context/nodes.js';\n\nexport interface PerceptionResult {\n staged: Change[];\n unstaged: Change[];\n diffSummary: DiffSummary;\n changeNodeId?: string;\n}\n\nexport async function perceiveCurrentChanges(\n projectPath: string,\n graph?: ContextGraph\n): Promise<PerceptionResult> {\n const ctxGraph = graph ?? new ContextGraph(projectPath);\n\n const [staged, unstaged] = await Promise.all([\n getStagedChanges(projectPath),\n getUncommittedChanges(projectPath)\n ]);\n\n const stagedDiff = await getWorkingTreeDiff(projectPath, true);\n const unstagedDiff = await getWorkingTreeDiff(projectPath, false);\n const combinedDiff = [stagedDiff, unstagedDiff].filter(Boolean).join('\\n');\n const diffSummary = analyzeDiff(combinedDiff);\n\n const filesTouched = new Set<string>();\n staged.forEach((c) => filesTouched.add(c.path));\n unstaged.forEach((c) => filesTouched.add(c.path));\n diffSummary.files.forEach((f) => filesTouched.add(f.filePath));\n\n const changeId = await upsertWorkingChange(ctxGraph, Array.from(filesTouched), projectPath);\n\n const result: PerceptionResult = {\n staged,\n unstaged,\n diffSummary\n };\n if (changeId) result.changeNodeId = changeId;\n return result;\n}\n\nasync function upsertWorkingChange(\n graph: ContextGraph,\n files: string[],\n projectPath: string\n): Promise<string | undefined> {\n if (files.length === 0) return undefined;\n\n const now = new Date().toISOString();\n const change = await graph.addNode('change', {\n commitHash: null,\n files,\n message: 'workspace changes',\n diff: null,\n author: null,\n timestamp: now,\n outcome: 'unknown'\n });\n\n for (const filePath of files) {\n const fileNode = await ensureFileNode(graph, filePath, projectPath);\n await graph.addEdge(change.id, fileNode.id, 'affects');\n }\n\n return change.id;\n}\n\nasync function ensureFileNode(\n graph: ContextGraph,\n filePath: string,\n projectPath: string\n): Promise<FileNode> {\n const normalized = path.resolve(projectPath, filePath);\n const existing = await graph.getNode('file', normalized);\n\n const now = new Date().toISOString();\n if (existing) {\n const data = existing.data as FileNodeData;\n await graph.updateNode('file', existing.id, {\n changeCount: (data.changeCount ?? 0) + 1,\n lastChanged: now\n });\n return (await graph.getNode('file', existing.id)) as FileNode;\n }\n\n const data: FileNodeData = {\n path: filePath,\n extension: path.extname(filePath),\n purpose: '',\n riskLevel: 'medium',\n whyRisky: null,\n changeCount: 1,\n lastChanged: now,\n incidentCount: 0,\n createdAt: now\n };\n\n return (await graph.addNode('file', data)) as FileNode;\n}\n","export interface DiffFileSummary {\n filePath: string;\n added: number;\n removed: number;\n functionsModified: string[];\n riskyPatterns: string[];\n}\n\nexport interface DiffSummary {\n files: DiffFileSummary[];\n totalAdded: number;\n totalRemoved: number;\n riskyFiles: string[];\n}\n\nconst RISKY_PATTERNS = [/auth/i, /token/i, /password/i, /secret/i, /validate/i, /sanitize/i];\n\nexport function analyzeDiff(diff: string): DiffSummary {\n const files: DiffFileSummary[] = [];\n let current: DiffFileSummary | null = null;\n\n const lines = diff.split('\\n');\n\n for (const line of lines) {\n if (line.startsWith('+++ b/')) {\n const filePath = line.replace('+++ b/', '').trim();\n current = {\n filePath,\n added: 0,\n removed: 0,\n functionsModified: [],\n riskyPatterns: []\n };\n files.push(current);\n continue;\n }\n\n if (!current) {\n continue;\n }\n\n if (line.startsWith('@@')) {\n // Capture function names or signatures in hunk headers\n const match = line.match(/@@.*?(function\\s+([\\w$]+)|class\\s+([\\w$]+)|([\\w$]+\\s*\\())/i);\n const fnName = match?.[2] || match?.[3] || match?.[4];\n if (fnName) {\n current.functionsModified.push(fnName.replace('(', '').trim());\n }\n continue;\n }\n\n if (line.startsWith('+') && !line.startsWith('+++')) {\n current.added += 1;\n markRisk(line, current);\n } else if (line.startsWith('-') && !line.startsWith('---')) {\n current.removed += 1;\n markRisk(line, current);\n }\n }\n\n const totalAdded = files.reduce((acc, f) => acc + f.added, 0);\n const totalRemoved = files.reduce((acc, f) => acc + f.removed, 0);\n const riskyFiles = files.filter((f) => f.riskyPatterns.length > 0).map((f) => f.filePath);\n\n return {\n files,\n totalAdded,\n totalRemoved,\n riskyFiles\n };\n}\n\nfunction markRisk(line: string, file: DiffFileSummary): void {\n for (const pattern of RISKY_PATTERNS) {\n if (pattern.test(line)) {\n const label = pattern.toString();\n if (!file.riskyPatterns.includes(label)) {\n file.riskyPatterns.push(label);\n }\n }\n }\n}\n","import path from 'node:path';\n\nimport type { RiskLevel } from '../types/index.js';\nimport type { PatternNode } from '../context/types.js';\nimport type { ContextGraph } from '../context/graph.js';\nimport type { FileNodeData, IncidentNode } from '../context/nodes.js';\n\nexport interface FileRiskResult {\n file: string;\n score: number;\n level: RiskLevel;\n reasons: string[];\n incidents: IncidentNode[];\n matchedPatterns: PatternNode[];\n}\n\nexport interface ChangeRiskResult {\n files: FileRiskResult[];\n overall: RiskLevel;\n score: number;\n shouldEscalate: boolean;\n}\n\nconst BASE_RISK: Record<RiskLevel, number> = {\n low: 10,\n medium: 35,\n high: 65,\n critical: 85\n};\n\nconst SENSITIVE_PATHS: { pattern: RegExp; weight: number; reason: string }[] = [\n { pattern: /auth|login|token|session/i, weight: 20, reason: 'touches authentication' },\n { pattern: /payment|billing|stripe|paypal|checkout/i, weight: 25, reason: 'touches payments' },\n { pattern: /secret|credential|env|config\\/security/i, weight: 15, reason: 'touches secrets/security config' },\n];\n\nfunction levelFromScore(score: number): RiskLevel {\n if (score >= 90) return 'critical';\n if (score >= 65) return 'high';\n if (score >= 40) return 'medium';\n return 'low';\n}\n\nexport async function scoreFile(\n graph: ContextGraph,\n filePath: string,\n matchedPatterns: PatternNode[] = []\n): Promise<FileRiskResult> {\n const reasons: string[] = [];\n const normalized = path.resolve(graph.projectRoot, filePath);\n const node = await graph.getNode('file', normalized);\n const incidents = await graph.getIncidentsForFile(filePath);\n\n let score = 10;\n const data = node?.data as FileNodeData | undefined;\n\n if (data) {\n score = BASE_RISK[data.riskLevel] ?? score;\n reasons.push(`baseline ${data.riskLevel}`);\n\n if (data.incidentCount > 0) {\n const incBoost = Math.min(data.incidentCount * 12, 36);\n score += incBoost;\n reasons.push(`historical incidents (+${incBoost})`);\n }\n\n if (data.changeCount > 5) {\n const changeBoost = Math.min((data.changeCount - 5) * 2, 12);\n score += changeBoost;\n reasons.push(`frequent changes (+${changeBoost})`);\n }\n\n if (data.lastChanged) {\n const lastChanged = new Date(data.lastChanged).getTime();\n const days = (Date.now() - lastChanged) / (1000 * 60 * 60 * 24);\n if (days > 60 && data.incidentCount === 0) {\n score -= 5;\n reasons.push('stable for 60d (-5)');\n }\n }\n }\n\n for (const { pattern, weight, reason } of SENSITIVE_PATHS) {\n if (pattern.test(filePath)) {\n score += weight;\n reasons.push(reason);\n }\n }\n\n if (matchedPatterns.length > 0) {\n const patternBoost = Math.min(\n matchedPatterns.reduce((acc, p) => acc + (p.data.confidence ?? 50) / 10, 0),\n 20\n );\n score += patternBoost;\n reasons.push(`pattern match (+${Math.round(patternBoost)})`);\n }\n\n if (incidents.length > 0) {\n const timestamps = incidents\n .map((i) => new Date(i.data.timestamp).getTime())\n .sort((a, b) => b - a);\n const recent = timestamps[0]!;\n const daysSince = (Date.now() - recent) / (1000 * 60 * 60 * 24);\n if (daysSince > 90) {\n score -= 5;\n reasons.push('no incidents in 90d (-5)');\n } else {\n score += 8;\n reasons.push('recent incident (+8)');\n }\n }\n\n const level = levelFromScore(score);\n return {\n file: filePath,\n score,\n level,\n reasons,\n incidents,\n matchedPatterns\n };\n}\n\nexport async function scoreChangeSet(\n graph: ContextGraph,\n files: string[],\n patternMatches: Record<string, PatternNode[]> = {}\n): Promise<ChangeRiskResult> {\n const fileResults: FileRiskResult[] = [];\n\n for (const file of files) {\n const patterns = patternMatches[file] ?? [];\n fileResults.push(await scoreFile(graph, file, patterns));\n }\n\n // Aggregate: use max file score, but boost if many files touched\n const maxScore = Math.max(...fileResults.map((f) => f.score), 10);\n const spreadBoost = files.length > 5 ? Math.min((files.length - 5) * 2, 10) : 0;\n const overallScore = maxScore + spreadBoost;\n const overall = levelFromScore(overallScore);\n\n const shouldEscalate = overall === 'critical' || overall === 'high';\n\n return {\n files: fileResults,\n overall,\n score: overallScore,\n shouldEscalate\n };\n}\n","import { ContextGraph } from '../context/graph.js';\nimport type { PatternNode } from '../context/nodes.js';\n\nexport interface PatternMatch {\n file: string;\n pattern: PatternNode;\n confidence: number;\n isAntiPattern: boolean;\n}\n\nexport async function matchPatternsForFiles(\n graph: ContextGraph,\n files: string[]\n): Promise<{ matches: PatternMatch[]; byFile: Record<string, PatternNode[]> }> {\n const matches: PatternMatch[] = [];\n const byFile: Record<string, PatternNode[]> = {};\n\n for (const file of files) {\n const patterns = await graph.getPatternsForFile(file);\n if (patterns.length === 0) continue;\n\n byFile[file] = patterns;\n\n for (const pattern of patterns) {\n matches.push({\n file,\n pattern,\n confidence: pattern.data.confidence,\n isAntiPattern: pattern.data.isAntiPattern\n });\n }\n }\n\n return { matches, byFile };\n}\n","import type { CodeContext, Agent, TriagingConfig } from '../types/index.js';\n\nexport class Triager {\n constructor(_config?: Partial<TriagingConfig>) {\n // Config no longer used - Trie is now purely a decision ledger\n }\n\n /**\n * Triage a change to select appropriate agents\n * Note: Skills/agents have been removed - Trie is now purely a decision ledger\n */\n async triage(\n _context: CodeContext,\n _forceAgents?: string[]\n ): Promise<Agent[]> {\n // No skills to triage - return empty array\n // Trie now focuses on decision ledger and learning from incidents\n return [];\n }\n\n /**\n * Get all available agent names (deprecated - returns empty array)\n */\n getAvailableAgents(): string[] {\n return [];\n }\n}\n","import { Worker } from 'worker_threads';\nimport { cpus } from 'os';\nimport { existsSync } from 'fs';\nimport { fileURLToPath } from 'url';\nimport type { Agent, AgentResult, ScanContext } from '../types/index.js';\nimport { StreamingManager } from './streaming.js';\nimport { CacheManager } from './cache-manager.js';\nimport { isInteractiveMode } from './progress.js';\n\ninterface ParallelTask {\n agent: Agent;\n files: string[];\n context: ScanContext;\n priority: number;\n timeoutMs: number;\n}\n\ninterface ParallelResult {\n agent: string;\n result: AgentResult;\n fromCache: boolean;\n executionTime: number;\n}\n\n/**\n * Parallel execution engine for Trie agents\n *\n * Features:\n * - True parallel execution using worker threads\n * - Intelligent scheduling based on agent priority\n * - Result caching and cache-aware scheduling\n * - Real-time progress streaming\n * - Dynamic resource management\n */\nexport class ParallelExecutor {\n private maxWorkers: number;\n private cache: CacheManager | null;\n private streaming?: StreamingManager;\n private activeWorkers: Set<Worker> = new Set();\n private cacheEnabled: boolean = true;\n private useWorkerThreads: boolean = false;\n private workerAvailable: boolean | null = null;\n private warnedWorkerFallback: boolean = false;\n\n constructor(\n cacheManager: CacheManager | null,\n maxWorkers: number = Math.max(2, Math.min(cpus().length - 1, 8)),\n options?: { cacheEnabled?: boolean; useWorkerThreads?: boolean }\n ) {\n this.maxWorkers = maxWorkers;\n this.cache = cacheManager;\n this.cacheEnabled = options?.cacheEnabled ?? true;\n this.useWorkerThreads = options?.useWorkerThreads ?? false;\n }\n\n /**\n * Set streaming manager for real-time updates\n */\n setStreaming(streaming: StreamingManager): void {\n this.streaming = streaming;\n }\n\n /**\n * Execute agents in parallel with intelligent scheduling\n */\n async executeAgents(\n agents: Agent[],\n files: string[],\n context: ScanContext\n ): Promise<Map<string, AgentResult>> {\n if (agents.length === 0) {\n return new Map();\n }\n\n // Initialize streaming\n if (this.streaming && this.streaming.getProgress().totalFiles === 0) {\n this.streaming.startScan(files.length);\n }\n\n // Check cache for existing results\n const cacheResults = new Map<string, AgentResult>();\n const uncachedTasks: ParallelTask[] = [];\n\n for (const agent of agents) {\n const cached = await this.checkAgentCache(agent, files);\n if (cached) {\n cacheResults.set(agent.name, cached);\n this.streaming?.completeAgent(agent.name, cached.issues);\n } else {\n uncachedTasks.push({\n agent,\n files,\n context,\n priority: agent.priority?.tier || 2,\n timeoutMs: context?.config?.timeoutMs || 120000\n });\n }\n }\n\n // Sort tasks by priority (tier 1 = highest priority)\n uncachedTasks.sort((a, b) => a.priority - b.priority);\n\n // Execute uncached tasks in parallel\n const parallelResults = await this.executeTasksParallel(uncachedTasks);\n\n // Cache new results\n await this.cacheResults(parallelResults);\n\n // Combine cached and new results\n const allResults = new Map<string, AgentResult>();\n\n // Add cached results\n for (const [agent, result] of cacheResults) {\n allResults.set(agent, result);\n }\n\n // Add new results\n for (const result of parallelResults) {\n allResults.set(result.agent, result.result);\n }\n\n // Complete streaming\n const allIssues = Array.from(allResults.values()).flatMap(r => r.issues);\n this.streaming?.completeScan(allIssues);\n\n return allResults;\n }\n\n /**\n * Check if agent has cached results for given files\n */\n private async checkAgentCache(agent: Agent, files: string[]): Promise<AgentResult | null> {\n if (!this.cacheEnabled || !this.cache) {\n return null;\n }\n\n const cachedIssues = await this.cache.getCachedBatch(files, agent.name);\n\n // Only use cache if we have results for ALL files\n if (cachedIssues.size === files.length) {\n const allIssues = Array.from(cachedIssues.values()).flat();\n return {\n agent: agent.name,\n issues: allIssues,\n executionTime: 0, // Cached\n success: true,\n metadata: {\n filesAnalyzed: files.length,\n linesAnalyzed: 0\n }\n };\n }\n\n return null;\n }\n\n /**\n * Execute tasks in parallel batches\n */\n private async executeTasksParallel(tasks: ParallelTask[]): Promise<ParallelResult[]> {\n if (tasks.length === 0) {\n return [];\n }\n\n const results: ParallelResult[] = [];\n const batches = this.createBatches(tasks, this.maxWorkers);\n\n for (const batch of batches) {\n const batchResults = await Promise.all(\n batch.map(task => this.executeTask(task))\n );\n results.push(...batchResults);\n }\n\n return results;\n }\n\n /**\n * Create batches for parallel execution\n */\n private createBatches(tasks: ParallelTask[], batchSize: number): ParallelTask[][] {\n const batches: ParallelTask[][] = [];\n\n for (let i = 0; i < tasks.length; i += batchSize) {\n batches.push(tasks.slice(i, i + batchSize));\n }\n\n return batches;\n }\n\n /**\n * Execute a single task\n */\n private async executeTask(task: ParallelTask): Promise<ParallelResult> {\n const startTime = Date.now();\n\n this.streaming?.startAgent(task.agent.name);\n\n try {\n const result = this.canUseWorkers()\n ? await this.executeTaskInWorker(task)\n : await task.agent.scan(task.files, task.context);\n const executionTime = Date.now() - startTime;\n\n this.streaming?.completeAgent(task.agent.name, result.issues);\n\n return {\n agent: task.agent.name,\n result,\n fromCache: false,\n executionTime\n };\n } catch (error) {\n const executionTime = Date.now() - startTime;\n const errorMessage = error instanceof Error ? error.message : String(error);\n\n this.streaming?.reportError(new Error(errorMessage), `Agent: ${task.agent.name}`);\n\n return {\n agent: task.agent.name,\n result: {\n agent: task.agent.name,\n issues: [],\n executionTime,\n success: false,\n error: errorMessage\n },\n fromCache: false,\n executionTime\n };\n }\n }\n\n private canUseWorkers(): boolean {\n if (!this.useWorkerThreads) {\n return false;\n }\n if (this.workerAvailable !== null) {\n return this.workerAvailable;\n }\n const workerUrl = this.getWorkerUrl();\n this.workerAvailable = existsSync(fileURLToPath(workerUrl));\n if (!this.workerAvailable && !this.warnedWorkerFallback && !isInteractiveMode()) {\n console.error('Worker threads unavailable; falling back to in-process agents.');\n this.warnedWorkerFallback = true;\n }\n return this.workerAvailable;\n }\n\n private getWorkerUrl(): URL {\n const distDir = new URL('.', import.meta.url);\n return new URL('workers/agent-worker.js', distDir);\n }\n\n private async executeTaskInWorker(task: ParallelTask): Promise<AgentResult> {\n // Use dirname to get the dist folder, then resolve to workers subfolder\n // This works whether the code is bundled into chunks or in utils/ folder\n const workerUrl = this.getWorkerUrl();\n\n return new Promise((resolve, reject) => {\n const worker = new Worker(workerUrl, {\n workerData: {\n agentName: task.agent.name,\n files: task.files,\n context: task.context\n }\n } as ConstructorParameters<typeof Worker>[1]);\n\n this.activeWorkers.add(worker);\n\n const timeout = setTimeout(() => {\n worker.terminate().catch(() => undefined);\n reject(new Error(`Agent ${task.agent.name} timed out after ${task.timeoutMs}ms`));\n }, task.timeoutMs);\n\n worker.on('message', (message) => {\n if (message?.type === 'result') {\n clearTimeout(timeout);\n resolve(message.result as AgentResult);\n } else if (message?.type === 'error') {\n clearTimeout(timeout);\n reject(new Error(message.error));\n }\n });\n\n worker.on('error', (error) => {\n clearTimeout(timeout);\n reject(error);\n });\n\n worker.on('exit', (code) => {\n this.activeWorkers.delete(worker);\n if (code !== 0) {\n clearTimeout(timeout);\n reject(new Error(`Worker stopped with exit code ${code}`));\n }\n });\n });\n }\n\n /**\n * Cache results for future use\n */\n private async cacheResults(results: ParallelResult[]): Promise<void> {\n if (!this.cacheEnabled || !this.cache) {\n return;\n }\n\n const cachePromises = results\n .filter(r => r.result.success && !r.fromCache)\n .map(r => {\n const issuesByFile = this.groupIssuesByFile(r.result.issues);\n const perFilePromises = Object.entries(issuesByFile).map(([file, issues]) =>\n this.cache!.setCached(file, r.agent, issues, r.executionTime)\n );\n return Promise.all(perFilePromises);\n });\n\n await Promise.allSettled(cachePromises);\n }\n\n /**\n * Cleanup resources\n */\n async cleanup(): Promise<void> {\n // Terminate any active workers\n const terminationPromises = Array.from(this.activeWorkers).map(worker =>\n worker.terminate()\n );\n\n await Promise.allSettled(terminationPromises);\n this.activeWorkers.clear();\n }\n\n private groupIssuesByFile(issues: AgentResult['issues']): Record<string, AgentResult['issues']> {\n const grouped: Record<string, AgentResult['issues']> = {};\n\n for (const issue of issues) {\n if (!grouped[issue.file]) {\n grouped[issue.file] = [];\n }\n grouped[issue.file]!.push(issue);\n }\n\n return grouped;\n }\n}\n\n/**\n * Smart agent prioritization based on dependencies and execution characteristics\n */\nexport function prioritizeAgents(agents: Agent[]): Agent[] {\n const prioritized = [...agents];\n\n // Sort by priority tier, then by estimated execution time\n prioritized.sort((a, b) => {\n const aTier = a.priority?.tier || 2;\n const bTier = b.priority?.tier || 2;\n\n if (aTier !== bTier) {\n return aTier - bTier; // Lower tier = higher priority\n }\n\n // Within same tier, prioritize faster agents\n const aTime = a.priority?.estimatedTimeMs || 1000;\n const bTime = b.priority?.estimatedTimeMs || 1000;\n\n return aTime - bTime;\n });\n\n return prioritized;\n}\n\n/**\n * Calculate optimal concurrency based on system resources and agent characteristics\n */\nexport function calculateOptimalConcurrency(): number {\n const numCPUs = cpus().length;\n const availableMemoryGB = process.memoryUsage().rss / 1024 / 1024 / 1024;\n\n // Conservative concurrency for stability\n let optimal = Math.max(2, Math.min(numCPUs - 1, 8));\n\n // Reduce concurrency if low memory\n if (availableMemoryGB < 2) {\n optimal = Math.max(2, Math.floor(optimal / 2));\n }\n\n // Increase slightly for systems with lots of CPU cores\n if (numCPUs > 8) {\n optimal = Math.min(optimal + 2, 12);\n }\n\n return optimal;\n}","import { readFile, writeFile, mkdir, stat } from 'fs/promises';\nimport { join } from 'path';\nimport { createHash } from 'crypto';\nimport type { Issue } from '../types/index.js';\nimport { isInteractiveMode } from './progress.js';\nimport { getTrieDirectory } from './workspace.js';\n\ninterface CacheEntry {\n version: string;\n timestamp: number;\n fileHash: string;\n fileSize: number;\n agent: string;\n issues: Issue[];\n executionTime: number;\n}\n\ninterface CacheIndex {\n version: string;\n created: number;\n entries: Record<string, CacheEntry>;\n}\n\nexport class CacheManager {\n private cacheDir: string;\n private indexPath: string;\n private readonly VERSION = '1.0.0';\n private readonly MAX_AGE_MS = 24 * 60 * 60 * 1000; // 24 hours\n private readonly MAX_ENTRIES = 1000;\n\n constructor(baseDir: string) {\n this.cacheDir = join(getTrieDirectory(baseDir), 'cache');\n this.indexPath = join(this.cacheDir, 'index.json');\n }\n\n /**\n * Generate cache key for a file and agent combination\n */\n private generateCacheKey(filePath: string, agent: string, fileHash: string): string {\n const key = `${filePath}:${agent}:${fileHash}`;\n return createHash('sha256').update(key).digest('hex').slice(0, 16);\n }\n\n /**\n * Get file hash for cache validation\n */\n private async getFileHash(filePath: string): Promise<{ hash: string; size: number; mtime: number }> {\n try {\n const content = await readFile(filePath, 'utf-8');\n const stats = await stat(filePath);\n const hash = createHash('sha256').update(content).digest('hex').slice(0, 16);\n return {\n hash,\n size: stats.size,\n mtime: stats.mtime.getTime()\n };\n } catch {\n return { hash: '', size: 0, mtime: 0 };\n }\n }\n\n /**\n * Load cache index\n */\n private async loadIndex(): Promise<CacheIndex> {\n try {\n const content = await readFile(this.indexPath, 'utf-8');\n return JSON.parse(content);\n } catch {\n return {\n version: this.VERSION,\n created: Date.now(),\n entries: {}\n };\n }\n }\n\n /**\n * Save cache index\n */\n private async saveIndex(index: CacheIndex): Promise<void> {\n try {\n await mkdir(this.cacheDir, { recursive: true });\n await writeFile(this.indexPath, JSON.stringify(index, null, 2));\n } catch (error) {\n if (!isInteractiveMode()) {\n console.warn('Failed to save cache index:', error);\n }\n }\n }\n\n /**\n * Clean up expired entries\n */\n private cleanupExpired(index: CacheIndex): CacheIndex {\n const now = Date.now();\n const validEntries: Record<string, CacheEntry> = {};\n\n for (const [key, entry] of Object.entries(index.entries)) {\n if (now - entry.timestamp < this.MAX_AGE_MS) {\n validEntries[key] = entry;\n }\n }\n\n // If still too many, keep the most recent ones\n const entries = Object.entries(validEntries);\n if (entries.length > this.MAX_ENTRIES) {\n entries.sort((a, b) => b[1].timestamp - a[1].timestamp);\n const limited = entries.slice(0, this.MAX_ENTRIES);\n return {\n ...index,\n entries: Object.fromEntries(limited)\n };\n }\n\n return {\n ...index,\n entries: validEntries\n };\n }\n\n /**\n * Get cached result for a file and agent\n * \n * Cache automatically invalidates when files change:\n * - Cache key includes file hash: hash(filePath:agent:fileHash)\n * - When file changes, hash changes, so cache key changes\n * - Old cache entry won't be found (different key)\n * - File is automatically rescanned\n * \n * This means cache auto-updates when Claude fixes code - no manual invalidation needed!\n */\n async getCached(filePath: string, agent: string): Promise<Issue[] | null> {\n try {\n const { hash, size: _size, mtime: _mtime } = await this.getFileHash(filePath);\n if (!hash) return null;\n\n const index = await this.loadIndex();\n const cacheKey = this.generateCacheKey(filePath, agent, hash);\n const entry = index.entries[cacheKey];\n\n if (!entry) return null;\n\n // Validate entry is still fresh\n // Double-check hash matches (defense in depth)\n const isValid = entry.fileHash === hash &&\n entry.version === this.VERSION &&\n (Date.now() - entry.timestamp) < this.MAX_AGE_MS;\n\n if (!isValid) {\n delete index.entries[cacheKey];\n await this.saveIndex(index);\n return null;\n }\n\n return entry.issues;\n } catch {\n return null;\n }\n }\n\n /**\n * Cache result for a file and agent\n */\n async setCached(\n filePath: string,\n agent: string,\n issues: Issue[],\n executionTime: number\n ): Promise<void> {\n try {\n const { hash, size } = await this.getFileHash(filePath);\n if (!hash) return;\n\n const index = await this.loadIndex();\n const cacheKey = this.generateCacheKey(filePath, agent, hash);\n\n index.entries[cacheKey] = {\n version: this.VERSION,\n timestamp: Date.now(),\n fileHash: hash,\n fileSize: size,\n agent,\n issues,\n executionTime\n };\n\n // Clean up old entries\n const cleanedIndex = this.cleanupExpired(index);\n await this.saveIndex(cleanedIndex);\n } catch (error) {\n if (!isInteractiveMode()) {\n console.warn('Failed to cache result:', error);\n }\n }\n }\n\n /**\n * Check if multiple files have cached results\n */\n async getCachedBatch(files: string[], agent: string): Promise<Map<string, Issue[]>> {\n const results = new Map<string, Issue[]>();\n\n await Promise.all(\n files.map(async (file) => {\n const cached = await this.getCached(file, agent);\n if (cached) {\n results.set(file, cached);\n }\n })\n );\n\n return results;\n }\n\n /**\n * Get cache statistics\n */\n async getStats(): Promise<{\n totalEntries: number;\n totalSizeKB: number;\n oldestEntry: number | null;\n newestEntry: number | null;\n agents: string[];\n hitRate?: number;\n }> {\n try {\n const index = await this.loadIndex();\n const entries = Object.values(index.entries);\n\n const totalSizeKB = entries.reduce((acc, entry) => acc + entry.fileSize, 0) / 1024;\n const timestamps = entries.map(e => e.timestamp);\n const agents = [...new Set(entries.map(e => e.agent))];\n\n return {\n totalEntries: entries.length,\n totalSizeKB: Math.round(totalSizeKB),\n oldestEntry: timestamps.length > 0 ? Math.min(...timestamps) : null,\n newestEntry: timestamps.length > 0 ? Math.max(...timestamps) : null,\n agents\n };\n } catch {\n return {\n totalEntries: 0,\n totalSizeKB: 0,\n oldestEntry: null,\n newestEntry: null,\n agents: []\n };\n }\n }\n\n /**\n * Clean up stale cache entries by verifying file hashes\n * This removes entries where files have changed or no longer exist\n * Called periodically to keep cache clean\n * \n * Note: Since cache keys are hashed, we can't easily reverse-engineer file paths.\n * However, when getCached() is called, it naturally invalidates stale entries\n * by checking if the current file hash matches the cached hash. This method\n * proactively cleans up entries for known changed files.\n */\n async cleanupStaleEntries(filePaths?: string[]): Promise<number> {\n try {\n const index = await this.loadIndex();\n let removedCount = 0;\n const keysToRemove: string[] = [];\n\n // If specific files provided, check those files against all cache entries\n // We can't perfectly match entries to files without storing paths, but we can\n // try to identify likely matches by checking if regenerating keys matches\n if (filePaths && filePaths.length > 0) {\n // Get all unique agents from cache entries\n const agents = new Set<string>();\n for (const entry of Object.values(index.entries)) {\n agents.add(entry.agent);\n }\n\n // For each file+agent combination, check if cache entry is stale\n for (const filePath of filePaths) {\n try {\n const { hash: currentHash } = await this.getFileHash(filePath);\n if (!currentHash) {\n // File doesn't exist - can't clean up without knowing which entries are for it\n continue;\n }\n\n // Check each agent's potential cache entries for this file\n for (const agent of agents) {\n // Check all entries to find ones that might be for this file\n for (const [key, entry] of Object.entries(index.entries)) {\n if (entry.agent !== agent) continue;\n \n // If entry hash doesn't match current hash, it might be stale\n if (entry.fileHash !== currentHash) {\n // Check if this key was generated with the old hash for this file\n const oldKey = this.generateCacheKey(filePath, agent, entry.fileHash);\n if (oldKey === key) {\n // This entry is for this file but hash doesn't match - stale!\n keysToRemove.push(key);\n removedCount++;\n }\n }\n }\n }\n } catch {\n // File doesn't exist or can't be read - skip\n continue;\n }\n }\n }\n\n // Remove stale entries (avoid duplicates)\n const uniqueKeys = [...new Set(keysToRemove)];\n for (const key of uniqueKeys) {\n delete index.entries[key];\n }\n\n if (removedCount > 0) {\n await this.saveIndex(index);\n }\n\n return removedCount;\n } catch (error) {\n if (!isInteractiveMode()) {\n console.warn('Failed to cleanup stale cache entries:', error);\n }\n return 0;\n }\n }\n\n /**\n * Clear all cache\n */\n async clear(): Promise<void> {\n try {\n const emptyIndex: CacheIndex = {\n version: this.VERSION,\n created: Date.now(),\n entries: {}\n };\n await this.saveIndex(emptyIndex);\n } catch (error) {\n if (!isInteractiveMode()) {\n console.warn('Failed to clear cache:', error);\n }\n }\n }\n}","import type { Agent, AgentResult, ScanContext } from '../types/index.js';\nimport { ParallelExecutor, calculateOptimalConcurrency } from '../utils/parallel-executor.js';\nimport { CacheManager } from '../utils/cache-manager.js';\nimport type { StreamingManager } from '../utils/streaming.js';\nimport { isInteractiveMode } from '../utils/progress.js';\n\nexport class Executor {\n async executeAgents(\n agents: Agent[],\n files: string[],\n context: ScanContext,\n options?: {\n streaming?: StreamingManager;\n parallel?: boolean;\n cacheEnabled?: boolean;\n maxConcurrency?: number;\n useWorkerThreads?: boolean;\n timeoutMs?: number;\n }\n ): Promise<AgentResult[]> {\n const parallel = options?.parallel ?? true;\n const cacheEnabled = options?.cacheEnabled ?? true;\n const maxConcurrency = options?.maxConcurrency ?? calculateOptimalConcurrency();\n const useWorkerThreads = options?.useWorkerThreads ?? false;\n\n if (!isInteractiveMode()) {\n console.error(`Executing ${agents.length} scouts ${parallel ? 'in parallel' : 'sequentially'}...`);\n }\n\n if (parallel) {\n const cacheManager = cacheEnabled ? new CacheManager(context.workingDir) : null;\n const executor = new ParallelExecutor(cacheManager, maxConcurrency, {\n cacheEnabled,\n useWorkerThreads\n });\n\n if (options?.streaming) {\n executor.setStreaming(options.streaming);\n }\n\n const results = await executor.executeAgents(agents, files, {\n ...context,\n config: { timeoutMs: options?.timeoutMs ?? 120000 }\n });\n\n return agents.map(agent => results.get(agent.name)!).filter(Boolean);\n }\n\n // Execute scouts in parallel with timeout\n const promises = agents.map(agent =>\n this.executeAgentWithTimeout(agent, files, context, options?.timeoutMs ?? 30000)\n );\n\n try {\n const results = await Promise.allSettled(promises);\n return results.map((result, index) => {\n if (result.status === 'fulfilled') {\n if (!isInteractiveMode()) {\n console.error(`${agents[index]!.name} completed in ${result.value.executionTime}ms`);\n }\n return result.value;\n } else {\n if (!isInteractiveMode()) {\n console.error(`${agents[index]!.name} failed:`, result.reason);\n }\n return {\n agent: agents[index]!.name,\n issues: [],\n executionTime: 0,\n success: false,\n error: result.reason instanceof Error ? result.reason.message : String(result.reason)\n };\n }\n });\n } catch (error) {\n if (!isInteractiveMode()) {\n console.error('Executor error:', error);\n }\n return agents.map(agent => ({\n agent: agent.name,\n issues: [],\n executionTime: 0,\n success: false,\n error: 'Execution failed'\n }));\n }\n }\n\n private async executeAgentWithTimeout(\n agent: Agent,\n files: string[],\n context: ScanContext,\n timeoutMs: number = 30000 // 30 second timeout\n ): Promise<AgentResult> {\n return new Promise(async (resolve, reject) => {\n const timeout = setTimeout(() => {\n reject(new Error(`Agent ${agent.name} timed out after ${timeoutMs}ms`));\n }, timeoutMs);\n\n try {\n const result = await agent.scan(files, context);\n clearTimeout(timeout);\n resolve(result);\n } catch (error) {\n clearTimeout(timeout);\n reject(error);\n }\n });\n }\n}","import { ContextGraph } from '../context/graph.js';\nimport type { IncidentNode, PatternNode } from '../context/nodes.js';\nimport type { RiskLevel, AgentResult, CodeContext, ScanContext } from '../types/index.js';\nimport { scoreChangeSet, type ChangeRiskResult, type FileRiskResult } from './risk-scorer.js';\nimport { matchPatternsForFiles } from './pattern-matcher.js';\nimport { Triager } from '../orchestrator/triager.js';\nimport { Executor } from '../orchestrator/executor.js';\n\nexport interface Reasoning {\n riskLevel: RiskLevel;\n shouldBlock: boolean;\n explanation: string;\n relevantIncidents: IncidentNode[];\n matchedPatterns: PatternNode[];\n recommendation: string;\n files: FileRiskResult[];\n agentResults?: AgentResult[];\n}\n\nexport interface ReasonOptions {\n runAgents?: boolean;\n codeContext?: CodeContext;\n scanContext?: Partial<ScanContext>;\n}\n\nfunction buildDefaultCodeContext(): CodeContext {\n return {\n changeType: 'general',\n isNewFeature: false,\n touchesUserData: false,\n touchesAuth: false,\n touchesPayments: false,\n touchesDatabase: false,\n touchesAPI: false,\n touchesUI: false,\n touchesHealthData: false,\n touchesSecurityConfig: false,\n linesChanged: 50,\n filePatterns: [],\n framework: 'unknown',\n language: 'typescript',\n touchesCrypto: false,\n touchesFileSystem: false,\n touchesThirdPartyAPI: false,\n touchesLogging: false,\n touchesErrorHandling: false,\n hasTests: false,\n complexity: 'medium',\n patterns: {\n hasAsyncCode: false,\n hasFormHandling: false,\n hasFileUploads: false,\n hasEmailHandling: false,\n hasRateLimiting: false,\n hasWebSockets: false,\n hasCaching: false,\n hasQueue: false\n }\n };\n}\n\nfunction buildExplanation(result: ChangeRiskResult): string {\n const top = [...result.files].sort((a, b) => b.score - a.score)[0];\n if (!top) return `Risk level ${result.overall} (no files provided)`;\n return `Risk level ${result.overall} because ${top.file} ${top.reasons.join(', ')}`;\n}\n\nfunction buildRecommendation(risk: RiskLevel, hasAntiPattern: boolean): string {\n if (hasAntiPattern || risk === 'critical') {\n return 'Block until reviewed: address anti-patterns and rerun targeted tests.';\n }\n if (risk === 'high') {\n return 'Require senior review and run full test suite before merge.';\n }\n if (risk === 'medium') {\n return 'Proceed with caution; run impacted tests and sanity checks.';\n }\n return 'Low risk; proceed but keep an eye on recent changes.';\n}\n\nexport async function reasonAboutChanges(\n projectPath: string,\n files: string[],\n options: ReasonOptions = {}\n): Promise<Reasoning> {\n const graph = new ContextGraph(projectPath);\n const { matches, byFile } = await matchPatternsForFiles(graph, files);\n const changeRisk = await scoreChangeSet(graph, files, byFile);\n\n const incidents: IncidentNode[] = [];\n for (const file of files) {\n const fileIncidents = await graph.getIncidentsForFile(file);\n incidents.push(...fileIncidents);\n }\n\n const hasAntiPattern = matches.some((m) => m.isAntiPattern);\n const riskLevel: RiskLevel = hasAntiPattern ? 'critical' : changeRisk.overall;\n const shouldBlock = hasAntiPattern || riskLevel === 'critical' || riskLevel === 'high';\n\n const reasoning: Reasoning = {\n riskLevel,\n shouldBlock,\n explanation: buildExplanation(changeRisk),\n relevantIncidents: incidents,\n matchedPatterns: matches.map((m) => m.pattern),\n recommendation: buildRecommendation(riskLevel, hasAntiPattern),\n files: changeRisk.files\n };\n\n if (options.runAgents) {\n const codeContext = options.codeContext ?? buildDefaultCodeContext();\n const triager = new Triager();\n // Skills removed - decision ledger now handles risk analysis\n const agents = await triager.triage(codeContext);\n\n if (agents.length > 0) {\n const executor = new Executor();\n const scanContext: ScanContext = {\n workingDir: projectPath,\n ...options.scanContext\n };\n if (codeContext.framework) scanContext.framework = codeContext.framework;\n if (codeContext.language) scanContext.language = codeContext.language;\n\n reasoning.agentResults = await executor.executeAgents(agents, files, scanContext, {\n parallel: true,\n timeoutMs: options.scanContext?.config?.timeoutMs ?? 60000\n });\n } else {\n reasoning.agentResults = [];\n }\n }\n\n return reasoning;\n}\n\n// Convenience wrapper to keep future CLI/MCP integration simple\nexport async function reasonAboutChangesHumanReadable(\n projectPath: string,\n files: string[],\n options: ReasonOptions = {}\n) {\n const reasoning = await reasonAboutChanges(projectPath, files, options);\n const { humanizeReasoning } = await import('../comprehension/index.js');\n return humanizeReasoning(reasoning);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,SAAS,kBAAkB;AAC3B,SAAS,OAAO,WAAW,gBAAgB;AAC3C,SAAS,YAAY;AAoBrB,eAAsB,eAAe,SAMb;AACtB,QAAM,UAAU,QAAQ,WAAW,oBAAoB,QAAW,IAAI;AACtE,QAAM,UAAU,iBAAiB,OAAO;AACxC,QAAM,iBAAiB,KAAK,SAAS,kBAA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AA,IACA,aAAa,iBAAiB,UAAU;AAAA,IACxC,mBAAmB;AAAA,IACnB,iBAAiB,QAAQ,IAAI,CAAC,MAAM,EAAE,OAAO;AAAA,IAC7C,gBAAgB,oBAAoB,WAAW,cAAc;AAAA,IAC7D,OAAO,WAAW;AAAA,EACpB;AAEA,MAAI,QAAQ,WAAW;AACrB,UAAM,cAAc,QAAQ,eAAe,wBAAwB;AACnE,UAAM,UAAU,IAAI,QAAQ;AAE5B,UAAM,SAAS,MAAM,QAAQ,OAAO,WAAW;AAE/C,QAAI,OAAO,SAAS,GAAG;AACrB,YAAM,WAAW,IAAI,SAAS;AAC9B,YAAM,cAA2B;AAAA,QAC/B,YAAY;AAAA,QACZ,GAAG,QAAQ;AAAA,MACb;AACA,UAAI,YAAY,UAAW,aAAY,YAAY,YAAY;AAC/D,UAAI,YAAY,SAAU,aAAY,WAAW,YAAY;AAE7D,gBAAU,eAAe,MAAM,SAAS,cAAc,QAAQ,OAAO,aAAa;AAAA,QAChF,UAAU;AAAA,QACV,WAAW,QAAQ,aAAa,QAAQ,aAAa;AAAA,MACvD,CAAC;AAAA,IACH,OAAO;AACL,gBAAU,eAAe,CAAC;AAAA,IAC5B;AAAA,EACF;AAEA,SAAO;AACT;AAGA,eAAsB,gCACpB,aACA,OACA,UAAyB,CAAC,GAC1B;AACA,QAAM,YAAY,MAAM,mBAAmB,aAAa,OAAO,OAAO;AACtE,QAAM,EAAE,kBAAkB,IAAI,MAAM,OAAO,6BAA2B;AACtE,SAAO,kBAAkB,SAAS;AACpC;","names":["existsSync","join","existsSync","join","existsSync","path","path","path","path","path","data","path","existsSync","existsSync","readFile","writeFile","mkdir","join","join","readFile","mkdir","writeFile"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/context/codebase-index.ts"],"sourcesContent":["/**\n * Codebase Index - Fast file indexing for goal violation detection\n * \n * Uses Trie structure for efficient file lookup and caching to avoid\n * re-scanning unchanged files.\n * \n * For large codebases, this dramatically improves goal check performance:\n * - Indexes file hashes to detect changes\n * - Caches AI analysis results\n * - Uses Trie for O(m) lookups where m = path length\n * - Stores file metadata (size, type, last modified, etc.)\n */\n\nimport { readFile, stat } from 'fs/promises';\nimport { createHash } from 'crypto';\nimport { join } from 'path';\nimport { existsSync } from 'fs';\nimport { Trie } from '../trie/trie.js';\nimport { getTrieDirectory } from '../utils/workspace.js';\nimport { atomicWriteJSON } from '../utils/atomic-write.js';\n\nexport interface FileMetadata {\n path: string;\n hash: string; // SHA-256 of content\n size: number;\n lastModified: number;\n type: string; // Extension\n lastScanned?: number; // Timestamp of last AI scan\n violations?: {\n goalId: string;\n goalDescription: string;\n found: boolean;\n details?: string;\n confidence?: number;\n timestamp: number;\n }[];\n}\n\nexport interface CodebaseIndexData {\n version: number;\n lastUpdated: string;\n fileCount: number;\n trie: any; // Serialized Trie\n}\n\nexport class CodebaseIndex {\n private trie: Trie<FileMetadata> = new Trie();\n private projectPath: string;\n private indexPath: string;\n\n constructor(projectPath: string) {\n this.projectPath = projectPath;\n this.indexPath = join(getTrieDirectory(projectPath), 'codebase-index.json');\n this.load();\n }\n\n /**\n * Load index from disk if it exists\n */\n private load(): void {\n if (!existsSync(this.indexPath)) return;\n\n try {\n const raw = JSON.parse(require('fs').readFileSync(this.indexPath, 'utf-8'));\n if (raw.trie) {\n this.trie = Trie.fromJSON<FileMetadata>(raw.trie);\n }\n } catch (error) {\n console.error('Failed to load codebase index:', error);\n }\n }\n\n /**\n * Save index to disk\n */\n async save(): Promise<void> {\n const data: CodebaseIndexData = {\n version: 1,\n lastUpdated: new Date().toISOString(),\n fileCount: this.trie.getWithPrefix('').length,\n trie: this.trie.toJSON(),\n };\n\n await atomicWriteJSON(this.indexPath, data);\n }\n\n /**\n * Add or update a file in the index\n * Returns null if the file doesn't exist or can't be read\n */\n async indexFile(filePath: string): Promise<FileMetadata | null> {\n // Safety check: if filePath is already absolute and doesn't start with projectPath,\n // this is likely a bug (stale cache entry from different project)\n if (filePath.startsWith('/')) {\n // Already absolute - check if it's within our project\n if (!filePath.toLowerCase().startsWith(this.projectPath.toLowerCase())) {\n return null; // Wrong project, skip silently\n }\n // It's absolute but within our project - use as-is\n }\n \n // Build absolute path: if filePath is relative, join with projectPath\n // If filePath is absolute (and within project), use it directly\n const absolutePath = filePath.startsWith('/') ? filePath : join(this.projectPath, filePath);\n \n try {\n const content = await readFile(absolutePath, 'utf-8');\n const stats = await stat(absolutePath);\n const hash = createHash('sha256').update(content).digest('hex');\n\n const metadata: FileMetadata = {\n path: filePath,\n hash,\n size: stats.size,\n lastModified: stats.mtimeMs,\n type: filePath.split('.').pop() || '',\n };\n\n // Check if file exists in index\n const existing = this.trie.search(filePath);\n if (existing.found && existing.value) {\n // File exists - preserve violations if hash matches\n if (existing.value.hash === hash) {\n metadata.violations = existing.value.violations;\n metadata.lastScanned = existing.value.lastScanned;\n }\n }\n\n this.trie.insert(filePath, metadata);\n return metadata;\n } catch (error) {\n // File doesn't exist, was deleted, or can't be read - return null\n return null;\n }\n }\n\n /**\n * Get file metadata from index\n */\n getFile(filePath: string): FileMetadata | null {\n const result = this.trie.search(filePath);\n return result.found && result.value ? result.value : null;\n }\n\n /**\n * Check if file has changed since last index\n */\n async hasChanged(filePath: string): Promise<boolean> {\n // Safety check for absolute paths from wrong project\n if (filePath.startsWith('/') && !filePath.toLowerCase().startsWith(this.projectPath.toLowerCase())) {\n return true; // Wrong project, treat as changed (will be skipped later)\n }\n \n const metadata = this.getFile(filePath);\n if (!metadata) return true; // Not indexed = changed\n\n // Build absolute path correctly\n const absolutePath = filePath.startsWith('/') ? filePath : join(this.projectPath, filePath);\n try {\n const stats = await stat(absolutePath);\n if (stats.mtimeMs !== metadata.lastModified) return true;\n\n // Double-check with hash for certainty\n const content = await readFile(absolutePath, 'utf-8');\n const hash = createHash('sha256').update(content).digest('hex');\n return hash !== metadata.hash;\n } catch {\n return true; // Error = assume changed\n }\n }\n\n /**\n * Get files in a directory\n */\n getDirectoryFiles(directoryPath: string): FileMetadata[] {\n const prefix = directoryPath.endsWith('/') ? directoryPath : `${directoryPath}/`;\n const matches = this.trie.getWithPrefix(prefix);\n return matches.map(m => m.value).filter((v): v is FileMetadata => v !== null);\n }\n\n /**\n * Get files that match a pattern (uses Trie prefix matching)\n */\n getFilesWithPrefix(prefix: string): FileMetadata[] {\n const matches = this.trie.getWithPrefix(prefix);\n return matches.map(m => m.value).filter((v): v is FileMetadata => v !== null);\n }\n\n /**\n * Get files by type (extension)\n */\n getFilesByType(type: string): FileMetadata[] {\n const allFiles = this.trie.getWithPrefix('');\n return allFiles\n .map(m => m.value)\n .filter((v): v is FileMetadata => v !== null && v.type === type);\n }\n\n /**\n * Record goal violation scan result for a file\n */\n recordViolation(\n filePath: string,\n goalId: string,\n goalDescription: string,\n found: boolean,\n details?: string,\n confidence?: number\n ): void {\n const metadata = this.getFile(filePath);\n if (!metadata) return;\n\n metadata.lastScanned = Date.now();\n if (!metadata.violations) metadata.violations = [];\n\n // Remove existing violation for this goal\n metadata.violations = metadata.violations.filter(v => v.goalId !== goalId);\n\n // Add new violation result\n metadata.violations.push({\n goalId,\n goalDescription,\n found,\n details,\n confidence,\n timestamp: Date.now(),\n });\n\n this.trie.insert(filePath, metadata);\n }\n\n /**\n * Get cached violation results for a file\n */\n getCachedViolations(filePath: string, goalId?: string): FileMetadata['violations'] {\n const metadata = this.getFile(filePath);\n if (!metadata || !metadata.violations) return undefined;\n\n if (goalId) {\n return metadata.violations.filter(v => v.goalId === goalId);\n }\n\n return metadata.violations;\n }\n\n /**\n * Check if the index is empty (needs initial indexing)\n */\n isEmpty(): boolean {\n return this.trie.getWithPrefix('').length === 0;\n }\n\n /**\n * Get statistics about the index\n */\n getStats(): {\n totalFiles: number;\n totalSize: number;\n filesByType: Record<string, number>;\n scannedFiles: number;\n filesWithViolations: number;\n } {\n const allFiles = this.trie.getWithPrefix('').map(m => m.value).filter((v): v is FileMetadata => v !== null);\n\n const stats = {\n totalFiles: allFiles.length,\n totalSize: allFiles.reduce((sum, f) => sum + f.size, 0),\n filesByType: {} as Record<string, number>,\n scannedFiles: allFiles.filter(f => f.lastScanned).length,\n filesWithViolations: allFiles.filter(f => f.violations && f.violations.some(v => v.found)).length,\n };\n\n for (const file of allFiles) {\n stats.filesByType[file.type] = (stats.filesByType[file.type] || 0) + 1;\n }\n\n return stats;\n }\n\n /**\n * Clear stale cached results (older than maxAgeMs)\n */\n clearStaleCache(maxAgeMs: number = 7 * 24 * 60 * 60 * 1000): number {\n const allFiles = this.trie.getWithPrefix('').map(m => m.value).filter((v): v is FileMetadata => v !== null);\n const cutoff = Date.now() - maxAgeMs;\n let cleared = 0;\n\n for (const file of allFiles) {\n if (file.violations) {\n const before = file.violations.length;\n file.violations = file.violations.filter(v => v.timestamp > cutoff);\n cleared += before - file.violations.length;\n if (file.violations.length === 0) {\n file.lastScanned = undefined;\n }\n this.trie.insert(file.path, file);\n }\n }\n\n return cleared;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAaA,SAAS,UAAU,YAAY;AAC/B,SAAS,kBAAkB;AAC3B,SAAS,YAAY;AACrB,SAAS,kBAAkB;AA6BpB,IAAM,gBAAN,MAAoB;AAAA,EACjB,OAA2B,IAAI,KAAK;AAAA,EACpC;AAAA,EACA;AAAA,EAER,YAAY,aAAqB;AAC/B,SAAK,cAAc;AACnB,SAAK,YAAY,KAAK,iBAAiB,WAAW,GAAG,qBAAqB;AAC1E,SAAK,KAAK;AAAA,EACZ;AAAA;AAAA;AAAA;AAAA,EAKQ,OAAa;AACnB,QAAI,CAAC,WAAW,KAAK,SAAS,EAAG;AAEjC,QAAI;AACF,YAAM,MAAM,KAAK,MAAM,UAAQ,IAAI,EAAE,aAAa,KAAK,WAAW,OAAO,CAAC;AAC1E,UAAI,IAAI,MAAM;AACZ,aAAK,OAAO,KAAK,SAAuB,IAAI,IAAI;AAAA,MAClD;AAAA,IACF,SAAS,OAAO;AACd,cAAQ,MAAM,kCAAkC,KAAK;AAAA,IACvD;AAAA,EACF;A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qBAAqB,SAAS,OAAO,OAAK,EAAE,cAAc,EAAE,WAAW,KAAK,OAAK,EAAE,KAAK,CAAC,EAAE;AAAA,IAC7F;AAEA,eAAW,QAAQ,UAAU;AAC3B,YAAM,YAAY,KAAK,IAAI,KAAK,MAAM,YAAY,KAAK,IAAI,KAAK,KAAK;AAAA,IACvE;AAEA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,gBAAgB,WAAmB,IAAI,KAAK,KAAK,KAAK,KAAc;AAClE,UAAM,WAAW,KAAK,KAAK,cAAc,EAAE,EAAE,IAAI,OAAK,EAAE,KAAK,EAAE,OAAO,CAAC,MAAyB,MAAM,IAAI;AAC1G,UAAM,SAAS,KAAK,IAAI,IAAI;AAC5B,QAAI,UAAU;AAEd,eAAW,QAAQ,UAAU;AAC3B,UAAI,KAAK,YAAY;AACnB,cAAM,SAAS,KAAK,WAAW;AAC/B,aAAK,aAAa,KAAK,WAAW,OAAO,OAAK,EAAE,YAAY,MAAM;AAClE,mBAAW,SAAS,KAAK,WAAW;AACpC,YAAI,KAAK,WAAW,WAAW,GAAG;AAChC,eAAK,cAAc;AAAA,QACrB;AACA,aAAK,KAAK,OAAO,KAAK,MAAM,IAAI;AAAA,MAClC;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/guardian/hypothesis.ts"],"sourcesContent":["/**\n * Hypothesis System - Self-improving hypothesis generation and validation\n * \n * Phase 3 of Guardian Agency Plan: Predictive Intelligence\n * \n * Features:\n * - Generate hypotheses from patterns\n * - Track evidence for/against hypotheses\n * - Auto-validate/invalidate based on evidence\n * - Adjust confidence over time\n * - Learn from hypothesis outcomes\n */\n\nimport type { Hypothesis } from './guardian-state.js';\nimport { getGuardianState } from './guardian-state.js';\nimport { getInsightStore, type GuardianInsight } from './insight-store.js';\nimport { searchIssues } from '../memory/issue-store.js';\nimport { dirname } from 'path';\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/**\n * Hypothesis template for auto-generation\n */\nexport interface HypothesisTemplate {\n category: 'timing' | 'pattern' | 'team' | 'code' | 'general';\n statement: string;\n testCriteria: string;\n minConfidence: number;\n dataRequired: string[];\n}\n\n/**\n * Evidence for a hypothesis\n */\nexport interface HypothesisEvidence {\n type: 'supporting' | 'contradicting';\n description: string;\n weight: number; // 0-1\n timestamp: string;\n}\n\n/**\n * Hypothesis analysis result\n */\nexport interface HypothesisAnalysis {\n hypothesis: Hypothesis;\n recentEvidence: HypothesisEvidence[];\n confidenceChange: number;\n statusChange?: 'validated' | 'invalidated';\n actionRequired: boolean;\n}\n\n// ============================================================================\n// Hypothesis Templates\n// ============================================================================\n\nconst HYPOTHESIS_TEMPLATES: HypothesisTemplate[] = [\n {\n category: 'timing',\n statement: 'Issues spike after weekend deployments',\n testCriteria: 'Compare Monday issue counts to other days',\n minConfidence: 0.3,\n dataRequired: ['issue_timestamps', 'deployment_data'],\n },\n {\n category: 'timing',\n statement: 'Code quality declines on Fridays',\n testCriteria: 'Compare Friday issue introduction rate to weekly average',\n minConfidence: 0.3,\n dataRequired: ['issue_timestamps'],\n },\n {\n category: 'pattern',\n statement: 'Auth-related code has the highest incident rate',\n testCriteria: 'Compare auth/ issue count to other directories',\n minConfidence: 0.4,\n dataRequired: ['issue_files'],\n },\n {\n category: 'pattern',\n statement: 'Security issues cluster in specific directories',\n testCriteria: 'Check if security issues are concentrated (>50% in <3 dirs)',\n minConfidence: 0.4,\n dataRequired: ['issue_files', 'issue_agents'],\n },\n {\n category: 'code',\n statement: 'Files with multiple authors have more issues',\n testCriteria: 'Correlate file author count with issue count',\n minConfidence: 0.4,\n dataRequired: ['issue_files', 'git_blame'],\n },\n {\n category: 'code',\n statement: 'Recently modified files are more likely to have issues',\n testCriteria: 'Compare issue rate for recent vs old files',\n minConfidence: 0.3,\n dataRequired: ['issue_timestamps', 'file_modification_times'],\n },\n {\n category: 'pattern',\n statement: 'Critical issues often come in clusters',\n testCriteria: 'Check temporal clustering of critical issues',\n minConfidence: 0.3,\n dataRequired: ['issue_timestamps', 'issue_severities'],\n },\n];\n\n// ============================================================================\n// HypothesisEngine Class\n// ============================================================================\n\n/**\n * Engine for generating and validating hypotheses\n */\nexport class HypothesisEngine {\n private projectPath: string;\n private guardianState;\n private insightStore;\n \n constructor(projectPath: string) {\n this.projectPath = projectPath;\n this.guardianState = getGuardianState(projectPath);\n this.insightStore = getInsightStore(projectPath);\n }\n \n /**\n * Create a new hypothesis\n */\n async createHypothesis(statement: string, options?: {\n category?: Hypothesis['category'];\n testCriteria?: string;\n initialConfidence?: number;\n }): Promise<Hypothesis> {\n const hypothesis: Hypothesis = {\n id: `hyp-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,\n statement,\n confidence: options?.initialConfidence ?? 0.5,\n status: 'proposed',\n evidence: [],\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n testCriteria: options?.testCriteria,\n category: options?.category ?? 'general',\n };\n \n await this.guardianState.addHypothesis(hypothesis);\n \n return hypothesis;\n }\n \n /**\n * Auto-generate hypotheses based on detected patterns\n */\n async autoGenerateHypotheses(): Promise<Hypothesis[]> {\n const generated: Hypothesis[] = [];\n \n try {\n // Get existing hypotheses to avoid duplicates\n await this.guardianState.load();\n const existing = this.guardianState.getAllHypotheses();\n const existingStatements = new Set(existing.map(h => h.statement.toLowerCase()));\n \n // Get data for pattern detection\n const issues = await searchIssues('', {\n workDir: this.projectPath,\n limit: 500,\n includeResolved: true,\n });\n \n if (issues.length < 10) {\n return generated; // Not enough data\n }\n \n // Check each template for applicability\n for (const template of HYPOTHESIS_TEMPLATES) {\n // Skip if already have similar hypothesis\n if (existingStatements.has(template.statement.toLowerCase())) {\n continue;\n }\n \n // Check if we have enough evidence to propose this hypothesis\n const evidence = await this.gatherInitialEvidence(template, issues);\n \n if (evidence.length > 0 && evidence[0]!.weight >= template.minConfidence) {\n const hypothesis = await this.createHypothesis(template.statement, {\n category: template.category,\n testCriteria: template.testCriteria,\n initialConfidence: evidence[0]!.weight,\n });\n \n // Add initial evidence\n for (const e of evidence) {\n await this.guardianState.addEvidence(hypothesis.id, e);\n }\n \n generated.push(hypothesis);\n \n // Limit to 2 new hypotheses per run\n if (generated.length >= 2) break;\n }\n }\n \n } catch (error) {\n console.error('Failed to auto-generate hypotheses:', error);\n }\n \n return generated;\n }\n \n /**\n * Use Claude AI to generate novel hypotheses from observed patterns\n * This enables fully agentic hypothesis creation based on actual codebase observations\n */\n async generateHypothesesWithAI(context: {\n recentIssues?: any[];\n patterns?: string[];\n observations?: string[];\n }): Promise<Hypothesis[]> {\n const { isAIAvailable, runAIAnalysis } = await import('../ai/client.js');\n \n if (!isAIAvailable()) {\n return []; // Fall back to template-based generation\n }\n \n const generated: Hypothesis[] = [];\n \n try {\n // Get existing hypotheses to avoid duplicates\n await this.guardianState.load();\n const existing = this.guardianState.getAllHypotheses();\n const existingStatements = existing.map(h => h.statement);\n \n // Get recent issue data\n const issues = context.recentIssues || await searchIssues('', {\n workDir: this.projectPath,\n limit: 100,\n includeResolved: true,\n });\n \n if (issues.length < 5) {\n return generated; // Not enough data for AI\n }\n \n // Build context for Claude\n const issuesSummary = this.summarizeIssuesForAI(issues);\n const patternsSummary = context.patterns?.join('\\n') || 'No explicit patterns provided';\n const observationsSummary = context.observations?.join('\\n') || 'No explicit observations provided';\n \n const prompt = `You are an AI agent observing a codebase over time. Based on the patterns below, generate 1-3 testable hypotheses about this codebase's quality patterns.\n\n## Recent Issues Summary\n${issuesSummary}\n\n## Observed Patterns\n${patternsSummary}\n\n## Additional Observations\n${observationsSummary}\n\n## Existing Hypotheses (avoid duplicates)\n${existingStatements.length > 0 ? existingStatements.map(s => `- ${s}`).join('\\n') : 'None yet'}\n\nGenerate hypotheses that are:\n1. Specific and testable (can be validated with data)\n2. Actionable (if validated, can guide improvements)\n3. Novel (not duplicates of existing hypotheses)\n4. Based on real patterns in the data above\n\nReturn ONLY a JSON array of hypotheses. Each hypothesis must have:\n- \"statement\": Clear, concise hypothesis statement\n- \"category\": One of: \"timing\", \"pattern\", \"team\", \"code\", \"general\"\n- \"testCriteria\": How to test this hypothesis\n- \"confidence\": Initial confidence (0-1)\n- \"reasoning\": Why you think this hypothesis is worth testing\n\nExample format:\n[\n {\n \"statement\": \"Authentication code changes correlate with security issues\",\n \"category\": \"pattern\",\n \"testCriteria\": \"Track auth file changes and subsequent security issue rates\",\n \"confidence\": 0.6,\n \"reasoning\": \"65% of security issues occur in files modified in the past week\"\n }\n]\n\nReturn empty array [] if no novel hypotheses can be generated from the data.`;\n \n const result = await runAIAnalysis({\n systemPrompt: 'You are an expert code quality analyst who identifies patterns and generates testable hypotheses.',\n userPrompt: prompt,\n maxTokens: 1024,\n temperature: 0.7, // Higher temperature for creative hypothesis generation\n });\n \n if (!result.success || !result.content.trim()) {\n return generated;\n }\n \n // Parse AI response\n let aiHypotheses: Array<{\n statement: string;\n category: Hypothesis['category'];\n testCriteria: string;\n confidence: number;\n reasoning: string;\n }> = [];\n \n try {\n const cleaned = result.content.replace(/```json?\\n?|\\n?```/g, '').trim();\n aiHypotheses = JSON.parse(cleaned);\n if (!Array.isArray(aiHypotheses)) aiHypotheses = [];\n } catch {\n return generated; // AI response wasn't valid JSON\n }\n \n // Create hypotheses from AI suggestions\n for (const aiHypo of aiHypotheses.slice(0, 3)) {\n // Check for duplicates\n const isDuplicate = existingStatements.some(existing => \n existing.toLowerCase().includes(aiHypo.statement.toLowerCase().slice(0, 30))\n );\n \n if (isDuplicate) continue;\n \n const hypothesis = await this.createHypothesis(aiHypo.statement, {\n category: aiHypo.category,\n testCriteria: aiHypo.testCriteria,\n initialConfidence: Math.max(0.3, Math.min(0.7, aiHypo.confidence)),\n });\n \n // Add AI reasoning as initial evidence\n await this.guardianState.addEvidence(hypothesis.id, {\n type: 'supporting',\n description: `AI observed: ${aiHypo.reasoning}`,\n weight: aiHypo.confidence,\n });\n \n generated.push(hypothesis);\n }\n \n } catch (error) {\n console.error('Failed to generate hypotheses with AI:', error);\n }\n \n return generated;\n }\n \n /**\n * Summarize issues for AI context\n */\n private summarizeIssuesForAI(issues: Array<{ issue: any; score: number }>): string {\n const totalIssues = issues.length;\n \n // Severity breakdown\n const severityCounts: Record<string, number> = {};\n for (const { issue } of issues) {\n severityCounts[issue.severity] = (severityCounts[issue.severity] || 0) + 1;\n }\n \n // Agent breakdown\n const agentCounts: Record<string, number> = {};\n for (const { issue } of issues) {\n agentCounts[issue.agent] = (agentCounts[issue.agent] || 0) + 1;\n }\n \n // File/directory patterns\n const fileCounts: Record<string, number> = {};\n for (const { issue } of issues) {\n const dir = dirname(issue.file);\n fileCounts[dir] = (fileCounts[dir] || 0) + 1;\n }\n \n // Time patterns\n const dayOfWeekCounts: Record<number, number> = {};\n for (const { issue } of issues) {\n const date = new Date(issue.timestamp);\n const day = date.getDay();\n dayOfWeekCounts[day] = (dayOfWeekCounts[day] || 0) + 1;\n }\n \n const dayNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];\n const dayDistribution = Object.entries(dayOfWeekCounts)\n .sort(([a], [b]) => Number(a) - Number(b))\n .map(([day, count]) => `${dayNames[Number(day)]}: ${count}`)\n .join(', ');\n \n const topDirs = Object.entries(fileCounts)\n .sort(([, a], [, b]) => b - a)\n .slice(0, 5)\n .map(([dir, count]) => `${dir}: ${count}`)\n .join(', ');\n \n const topAgents = Object.entries(agentCounts)\n .sort(([, a], [, b]) => b - a)\n .slice(0, 5)\n .map(([agent, count]) => `${agent}: ${count}`)\n .join(', ');\n \n return `Total Issues: ${totalIssues}\nSeverities: ${Object.entries(severityCounts).map(([s, c]) => `${s}=${c}`).join(', ')}\nTop Agents: ${topAgents}\nTop Directories: ${topDirs}\nDay Distribution: ${dayDistribution}`;\n }\n \n /**\n * Gather initial evidence for a hypothesis template\n */\n private async gatherInitialEvidence(\n template: HypothesisTemplate,\n issues: Array<{ issue: any; score: number }>\n ): Promise<HypothesisEvidence[]> {\n const evidence: HypothesisEvidence[] = [];\n \n switch (template.category) {\n case 'timing':\n evidence.push(...this.analyzeTimingPatterns(template, issues));\n break;\n case 'pattern':\n evidence.push(...this.analyzeLocationPatterns(template, issues));\n break;\n case 'code':\n evidence.push(...this.analyzeCodePatterns(template, issues));\n break;\n }\n \n return evidence;\n }\n \n /**\n * Analyze timing patterns in issues\n */\n private analyzeTimingPatterns(\n template: HypothesisTemplate,\n issues: Array<{ issue: any; score: number }>\n ): HypothesisEvidence[] {\n const evidence: HypothesisEvidence[] = [];\n \n // Analyze day-of-week patterns\n const dayOfWeekCounts: Record<number, number> = {};\n for (const { issue } of issues) {\n const date = new Date(issue.timestamp);\n const day = date.getDay();\n dayOfWeekCounts[day] = (dayOfWeekCounts[day] || 0) + 1;\n }\n \n // Check for Friday pattern\n if (template.statement.includes('Friday')) {\n const fridayCount = dayOfWeekCounts[5] || 0;\n const avgOtherDays = (Object.values(dayOfWeekCounts).reduce((a, b) => a + b, 0) - fridayCount) / 4;\n \n if (fridayCount > avgOtherDays * 1.5) {\n evidence.push({\n type: 'supporting',\n description: `Friday has ${((fridayCount / avgOtherDays - 1) * 100).toFixed(0)}% more issues than average`,\n weight: Math.min(0.8, 0.3 + (fridayCount / avgOtherDays - 1) * 0.2),\n timestamp: new Date().toISOString(),\n });\n } else {\n evidence.push({\n type: 'contradicting',\n description: 'Friday issue count is not significantly higher',\n weight: 0.3,\n timestamp: new Date().toISOString(),\n });\n }\n }\n \n // Check for Monday/weekend pattern\n if (template.statement.includes('weekend') || template.statement.includes('Monday')) {\n const mondayCount = dayOfWeekCounts[1] || 0;\n const avgOtherDays = (Object.values(dayOfWeekCounts).reduce((a, b) => a + b, 0) - mondayCount) / 4;\n \n if (mondayCount > avgOtherDays * 1.5) {\n evidence.push({\n type: 'supporting',\n description: `Monday has ${((mondayCount / avgOtherDays - 1) * 100).toFixed(0)}% more issues than average`,\n weight: Math.min(0.8, 0.3 + (mondayCount / avgOtherDays - 1) * 0.2),\n timestamp: new Date().toISOString(),\n });\n }\n }\n \n return evidence;\n }\n \n /**\n * Analyze location patterns in issues\n */\n private analyzeLocationPatterns(\n template: HypothesisTemplate,\n issues: Array<{ issue: any; score: number }>\n ): HypothesisEvidence[] {\n const evidence: HypothesisEvidence[] = [];\n \n // Analyze directory distribution\n const dirCounts: Record<string, number> = {};\n for (const { issue } of issues) {\n const dir = dirname(issue.file);\n dirCounts[dir] = (dirCounts[dir] || 0) + 1;\n }\n \n const sortedDirs = Object.entries(dirCounts)\n .sort(([, a], [, b]) => b - a);\n \n // Check for auth pattern\n if (template.statement.includes('Auth')) {\n const authDirs = sortedDirs.filter(([dir]) => \n dir.toLowerCase().includes('auth') || \n dir.toLowerCase().includes('login') ||\n dir.toLowerCase().includes('session')\n );\n \n const authCount = authDirs.reduce((sum, [, count]) => sum + count, 0);\n const percentage = (authCount / issues.length) * 100;\n \n if (percentage >= 20) {\n evidence.push({\n type: 'supporting',\n description: `Auth-related code has ${percentage.toFixed(0)}% of issues`,\n weight: Math.min(0.85, 0.4 + percentage / 100),\n timestamp: new Date().toISOString(),\n });\n }\n }\n \n // Check for clustering pattern\n if (template.statement.includes('cluster')) {\n const topThreeDirs = sortedDirs.slice(0, 3);\n const topThreeCount = topThreeDirs.reduce((sum, [, count]) => sum + count, 0);\n const percentage = (topThreeCount / issues.length) * 100;\n \n if (percentage >= 50) {\n evidence.push({\n type: 'supporting',\n description: `Top 3 directories have ${percentage.toFixed(0)}% of issues`,\n weight: Math.min(0.8, 0.3 + percentage / 100),\n timestamp: new Date().toISOString(),\n });\n }\n }\n \n return evidence;\n }\n \n /**\n * Analyze code patterns\n */\n private analyzeCodePatterns(\n template: HypothesisTemplate,\n issues: Array<{ issue: any; score: number }>\n ): HypothesisEvidence[] {\n const evidence: HypothesisEvidence[] = [];\n \n // Analyze temporal clustering (critical issues in bursts)\n if (template.statement.includes('cluster')) {\n const criticalIssues = issues.filter(r => r.issue.severity === 'critical');\n \n if (criticalIssues.length >= 3) {\n // Check if critical issues are clustered in time\n const timestamps = criticalIssues\n .map(r => new Date(r.issue.timestamp).getTime())\n .sort((a, b) => a - b);\n \n let clusteredCount = 0;\n for (let i = 1; i < timestamps.length; i++) {\n // If within 24 hours of previous\n if (timestamps[i]! - timestamps[i - 1]! < 24 * 60 * 60 * 1000) {\n clusteredCount++;\n }\n }\n \n const clusterRatio = clusteredCount / (timestamps.length - 1);\n \n if (clusterRatio >= 0.5) {\n evidence.push({\n type: 'supporting',\n description: `${(clusterRatio * 100).toFixed(0)}% of critical issues occur within 24h of another`,\n weight: Math.min(0.75, 0.3 + clusterRatio * 0.4),\n timestamp: new Date().toISOString(),\n });\n }\n }\n }\n \n return evidence;\n }\n \n /**\n * Update confidence scores based on new data\n */\n async updateConfidenceFromOutcomes(): Promise<HypothesisAnalysis[]> {\n const analyses: HypothesisAnalysis[] = [];\n \n try {\n await this.guardianState.load();\n const activeHypotheses = this.guardianState.getActiveHypotheses();\n \n for (const hypothesis of activeHypotheses) {\n const analysis = await this.analyzeHypothesis(hypothesis);\n analyses.push(analysis);\n \n // Create insight if hypothesis was validated or invalidated\n if (analysis.statusChange && this.insightStore.canCreateInsight('hypothesis-update')) {\n const insight = this.createHypothesisInsight(analysis);\n await this.insightStore.addInsight(insight);\n await this.insightStore.markInsightCreated('hypothesis-update');\n }\n }\n \n // Update hypothesis accuracy metric\n await this.guardianState.updateHypothesisAccuracy();\n \n } catch (error) {\n console.error('Failed to update hypothesis confidence:', error);\n }\n \n return analyses;\n }\n \n /**\n * Analyze a single hypothesis\n */\n private async analyzeHypothesis(hypothesis: Hypothesis): Promise<HypothesisAnalysis> {\n // Get recent issues for new evidence\n const issues = await searchIssues('', {\n workDir: this.projectPath,\n limit: 100,\n includeResolved: false,\n });\n \n // Find the matching template\n const template = HYPOTHESIS_TEMPLATES.find(t => \n t.statement.toLowerCase() === hypothesis.statement.toLowerCase()\n );\n \n const recentEvidence: HypothesisEvidence[] = [];\n \n if (template) {\n recentEvidence.push(...await this.gatherInitialEvidence(template, issues));\n } else {\n // For user-created hypotheses, use semantic evidence gathering\n recentEvidence.push(...this.gatherSemanticEvidence(hypothesis, issues));\n }\n \n // Calculate confidence change\n const oldConfidence = hypothesis.confidence;\n let newConfidence = oldConfidence;\n \n for (const evidence of recentEvidence) {\n if (evidence.type === 'supporting') {\n newConfidence = Math.min(1, newConfidence + evidence.weight * 0.1);\n } else {\n newConfidence = Math.max(0, newConfidence - evidence.weight * 0.1);\n }\n }\n \n // Determine status change\n let statusChange: 'validated' | 'invalidated' | undefined;\n \n if (newConfidence >= 0.8 && hypothesis.evidence.length >= 3) {\n statusChange = 'validated';\n await this.guardianState.updateHypothesis(hypothesis.id, {\n status: 'validated',\n confidence: newConfidence,\n validatedAt: new Date().toISOString(),\n });\n } else if (newConfidence <= 0.2 && hypothesis.evidence.length >= 3) {\n statusChange = 'invalidated';\n await this.guardianState.updateHypothesis(hypothesis.id, {\n status: 'invalidated',\n confidence: newConfidence,\n });\n } else {\n // Just update confidence\n await this.guardianState.updateHypothesis(hypothesis.id, {\n confidence: newConfidence,\n });\n }\n \n // Add new evidence\n for (const evidence of recentEvidence) {\n await this.guardianState.addEvidence(hypothesis.id, evidence);\n }\n \n const analysis: HypothesisAnalysis = {\n hypothesis: { ...hypothesis, confidence: newConfidence },\n recentEvidence,\n confidenceChange: newConfidence - oldConfidence,\n actionRequired: statusChange !== undefined,\n };\n \n if (statusChange) {\n analysis.statusChange = statusChange;\n }\n \n return analysis;\n }\n \n /**\n * Gather evidence for user-created hypotheses using semantic matching\n * \n * This enables agentic tracking for natural language hypotheses like:\n * - \"Mondays have more bugs than Fridays\"\n * - \"Code reviews reduce bug rate\"\n * - \"Security issues cluster in auth code\"\n */\n private gatherSemanticEvidence(\n hypothesis: Hypothesis,\n issues: Array<{ issue: any; score: number }>\n ): HypothesisEvidence[] {\n const evidence: HypothesisEvidence[] = [];\n const stmt = hypothesis.statement.toLowerCase();\n \n // Time-based hypotheses (days of week patterns)\n if (stmt.includes('monday') || stmt.includes('friday') || stmt.includes('weekend') ||\n stmt.includes('morning') || stmt.includes('afternoon')) {\n const dayNames = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];\n const dayOfWeekCounts: Record<number, number> = { 0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0 };\n \n for (const { issue } of issues) {\n const date = new Date(issue.timestamp);\n const day = date.getDay();\n dayOfWeekCounts[day] = (dayOfWeekCounts[day] || 0) + 1;\n }\n \n const totalIssues = Object.values(dayOfWeekCounts).reduce((a, b) => a + b, 0);\n const avgPerDay = totalIssues / 7;\n \n // Check each day mentioned\n for (let dayIdx = 0; dayIdx < 7; dayIdx++) {\n const dayName = dayNames[dayIdx]!;\n if (stmt.includes(dayName)) {\n const dayCount = dayOfWeekCounts[dayIdx] || 0;\n \n if (stmt.includes('more') || stmt.includes('higher') || stmt.includes('spike')) {\n // Testing if this day has MORE issues\n if (dayCount > avgPerDay * 1.3) {\n evidence.push({\n type: 'supporting',\n description: `${dayName.charAt(0).toUpperCase() + dayName.slice(1)} has ${dayCount} issues (${((dayCount/avgPerDay - 1) * 100).toFixed(0)}% above average)`,\n weight: Math.min(0.7, 0.3 + (dayCount / avgPerDay - 1) * 0.3),\n timestamp: new Date().toISOString(),\n });\n } else {\n evidence.push({\n type: 'contradicting',\n description: `${dayName.charAt(0).toUpperCase() + dayName.slice(1)} has average or below average issue count`,\n weight: 0.3,\n timestamp: new Date().toISOString(),\n });\n }\n } else if (stmt.includes('fewer') || stmt.includes('less') || stmt.includes('reduce')) {\n // Testing if this day has FEWER issues\n if (dayCount < avgPerDay * 0.7) {\n evidence.push({\n type: 'supporting',\n description: `${dayName.charAt(0).toUpperCase() + dayName.slice(1)} has ${dayCount} issues (${((1 - dayCount/avgPerDay) * 100).toFixed(0)}% below average)`,\n weight: Math.min(0.7, 0.3 + (1 - dayCount / avgPerDay) * 0.3),\n timestamp: new Date().toISOString(),\n });\n }\n }\n }\n }\n }\n \n // Code review hypotheses\n if (stmt.includes('review') || stmt.includes('pr') || stmt.includes('pull request')) {\n // Look for patterns in reviewed vs unreviewed code (approximated by commit patterns)\n const recentIssues = issues.slice(0, 30); // Most recent\n const olderIssues = issues.slice(30); // Older\n \n if (recentIssues.length >= 10 && olderIssues.length >= 10) {\n const recentRate = recentIssues.length;\n const olderRate = olderIssues.length;\n \n if (stmt.includes('reduce') || stmt.includes('fewer') || stmt.includes('less')) {\n if (recentRate < olderRate) {\n evidence.push({\n type: 'supporting',\n description: `Recent period has ${((1 - recentRate/olderRate) * 100).toFixed(0)}% fewer issues`,\n weight: Math.min(0.6, 0.3 + (1 - recentRate/olderRate) * 0.3),\n timestamp: new Date().toISOString(),\n });\n } else {\n evidence.push({\n type: 'contradicting',\n description: `Issue rate has not decreased recently`,\n weight: 0.2,\n timestamp: new Date().toISOString(),\n });\n }\n }\n }\n }\n \n // Directory/location clustering hypotheses\n if (stmt.includes('cluster') || stmt.includes('concentrate') || stmt.includes('auth') ||\n stmt.includes('specific') || stmt.includes('certain files')) {\n const dirCounts: Record<string, number> = {};\n for (const { issue } of issues) {\n const dir = dirname(issue.file);\n dirCounts[dir] = (dirCounts[dir] || 0) + 1;\n }\n \n const sortedDirs = Object.entries(dirCounts).sort(([, a], [, b]) => b - a);\n const topThreeCount = sortedDirs.slice(0, 3).reduce((sum, [, count]) => sum + count, 0);\n const totalCount = issues.length;\n const concentration = topThreeCount / totalCount;\n \n if (concentration >= 0.5) {\n evidence.push({\n type: 'supporting',\n description: `Top 3 directories have ${(concentration * 100).toFixed(0)}% of issues (concentrated)`,\n weight: Math.min(0.7, 0.3 + concentration * 0.4),\n timestamp: new Date().toISOString(),\n });\n } else {\n evidence.push({\n type: 'contradicting',\n description: `Issues are distributed across many directories`,\n weight: 0.3,\n timestamp: new Date().toISOString(),\n });\n }\n }\n \n // Severity trend hypotheses\n if (stmt.includes('critical') || stmt.includes('security') || stmt.includes('severity')) {\n const criticalCount = issues.filter(r => r.issue.severity === 'critical').length;\n const seriousCount = issues.filter(r => r.issue.severity === 'serious').length;\n const highSeverityRatio = (criticalCount + seriousCount) / issues.length;\n \n if (stmt.includes('increase') || stmt.includes('more') || stmt.includes('rise')) {\n if (highSeverityRatio > 0.3) {\n evidence.push({\n type: 'supporting',\n description: `${(highSeverityRatio * 100).toFixed(0)}% of issues are high severity`,\n weight: Math.min(0.7, 0.3 + highSeverityRatio),\n timestamp: new Date().toISOString(),\n });\n }\n } else if (stmt.includes('decrease') || stmt.includes('fewer') || stmt.includes('reduce')) {\n if (highSeverityRatio < 0.2) {\n evidence.push({\n type: 'supporting',\n description: `Only ${(highSeverityRatio * 100).toFixed(0)}% of issues are high severity`,\n weight: 0.5,\n timestamp: new Date().toISOString(),\n });\n }\n }\n }\n \n // Agent/skill specific hypotheses\n const agents = ['security', 'performance', 'accessibility', 'test', 'typecheck', 'bug-finding'];\n for (const agent of agents) {\n if (stmt.includes(agent) || stmt.includes(agent.replace('-', ' '))) {\n const agentIssues = issues.filter(r => r.issue.agent === agent);\n const agentRatio = agentIssues.length / issues.length;\n \n if (stmt.includes('most') || stmt.includes('majority') || stmt.includes('main')) {\n if (agentRatio > 0.4) {\n evidence.push({\n type: 'supporting',\n description: `${agent} accounts for ${(agentRatio * 100).toFixed(0)}% of issues`,\n weight: Math.min(0.7, 0.3 + agentRatio),\n timestamp: new Date().toISOString(),\n });\n } else {\n evidence.push({\n type: 'contradicting',\n description: `${agent} only accounts for ${(agentRatio * 100).toFixed(0)}% of issues`,\n weight: 0.3,\n timestamp: new Date().toISOString(),\n });\n }\n }\n }\n }\n \n return evidence;\n }\n \n /**\n * Create an insight for hypothesis status change\n */\n private createHypothesisInsight(analysis: HypothesisAnalysis): GuardianInsight {\n const isValidated = analysis.statusChange === 'validated';\n \n return {\n id: `insight-hyp-${analysis.hypothesis.id}`,\n type: isValidated ? 'celebration' : 'observation',\n message: isValidated\n ? `Hypothesis confirmed: \"${analysis.hypothesis.statement}\"`\n : `Hypothesis disproven: \"${analysis.hypothesis.statement}\"`,\n context: `Confidence: ${(analysis.hypothesis.confidence * 100).toFixed(0)}%. ${analysis.recentEvidence.length} evidence points analyzed.`,\n relatedIssues: [],\n priority: 5,\n timestamp: Date.now(),\n dismissed: false,\n category: 'pattern',\n details: {\n examples: analysis.recentEvidence.map(e => `${e.type}: ${e.description}`),\n },\n };\n }\n \n /**\n * Get hypothesis by ID\n */\n async getHypothesis(hypothesisId: string): Promise<Hypothesis | undefined> {\n await this.guardianState.load();\n return this.guardianState.getHypothesis(hypothesisId);\n }\n \n /**\n * Get all hypotheses\n */\n async getAllHypotheses(): Promise<Hypothesis[]> {\n await this.guardianState.load();\n return this.guardianState.getAllHypotheses();\n }\n \n /**\n * Get validated hypotheses\n */\n async getValidatedHypotheses(): Promise<Hypothesis[]> {\n await this.guardianState.load();\n return this.guardianState.getValidatedHypotheses();\n }\n \n /**\n * Get hypothesis accuracy stats\n */\n getAccuracy(): number {\n const metrics = this.guardianState.getMetrics();\n return metrics.hypothesisAccuracy;\n }\n}\n\n// ============================================================================\n// Singleton Management\n// ============================================================================\n\nconst hypothesisEngines: Map<string, HypothesisEngine> = new Map();\n\n/**\n * Get the HypothesisEngine for a project (singleton per project)\n */\nexport function getHypothesisEngine(projectPath: string): HypothesisEngine {\n let engine = hypothesisEngines.get(projectPath);\n if (!engine) {\n engine = new HypothesisEngine(projectPath);\n hypothesisEngines.set(projectPath, engine);\n }\n return engine;\n}\n\n/**\n * Clear all HypothesisEngine instances (for testing)\n */\nexport function clearHypothesisEngines(): void {\n hypothesisEngines.clear();\n}\n\n/**\n * Gather evidence for a specific hypothesis (manual check from UI)\n */\nexport async function gatherEvidenceForHypothesis(\n hypothesisId: string,\n projectPath: string\n): Promise<Array<{ supports: boolean; description: string; weight: number }>> {\n const engine = getHypothesisEngine(projectPath);\n const guardianState = getGuardianState(projectPath);\n await guardianState.load();\n \n const hypothesis = guardianState.getAllHypotheses().find(h => h.id === hypothesisId);\n if (!hypothesis) {\n throw new Error(`Hypothesis ${hypothesisId} not found`);\n }\n \n // Get the analysis - access private method via bracket notation\n const analysis = await (engine as any).analyzeHypothesis(hypothesis);\n \n // Convert evidence to simpler format\n return analysis.recentEvidence.map((e: HypothesisEvidence) => ({\n supports: e.type === 'supporting',\n description: e.description,\n weight: e.weight,\n }));\n}\n"],"mappings":";;;;;;;;;;;AAiBA,SAAS,eAAe;AA0CxB,IAAM,uBAA6C;AAAA,EACjD;AAAA,IACE,UAAU;AAAA,IACV,WAAW;AAAA,IACX,cAAc;AAAA,IACd,eAAe;AAAA,IACf,cAAc,CAAC,oBAAoB,iBAAiB;AAAA,EACtD;AAAA,EACA;AAAA,IACE,UAAU;AAAA,IACV,WAAW;AAAA,IACX,cAAc;AAAA,IACd,eAAe;AAAA,IACf,cAAc,CAAC,kBAAkB;AAAA,EACnC;AAAA,EACA;AAAA,IACE,UAAU;AAAA,IACV,WAAW;AAAA,IACX,cAAc;AAAA,IACd,eAAe;AAAA,IACf,cAAc,CAAC,aAAa;AAAA,EAC9B;AAAA,EACA;AAAA,IACE,UAAU;AAAA,IACV,WAAW;AAAA,IACX,cAAc;AAAA,IACd,eAAe;AAAA,IACf,cAAc,CAAC,eAAe,cAAc;AAAA,EAC9C;AAAA,EACA;AAAA,IACE,UAAU;AAAA,IACV,WAAW;AAAA,IACX,cAAc;AAAA,IACd,eAAe;AAAA,IACf,cAAc,CAAC,eAAe,WAAW;AAAA,EAC3C;AAAA,EACA;AAAA,IACE,UAAU;AAAA,IACV,WAAW;AAAA,IACX,cAAc;AAAA,IACd,eAAe;AAAA,IACf,cAAc,CAAC,oBAAoB,yBAAyB;AAAA,EAC9D;AAAA,EACA;AAAA,IACE,UAAU;AAAA,IACV,WAAW;AAAA,IACX,cAAc;AAAA,IACd,eAAe;AAAA,IACf,cAAc,CAAC,oBAAoB,kBAAkB;AAAA,EACvD;AACF;AASO,IAAM,mBAAN,MAAuB;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EAER,YAAY,aAAqB;AAC/B,SAAK,cAAc;AACnB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