feat(ms-ai-architect): session-start hook reads kb-update-status for failure surfacing [skip-docs]

This commit is contained in:
Kjell Tore Guttormsen 2026-05-05 11:12:37 +02:00
commit 7848d113de
2 changed files with 192 additions and 0 deletions

View file

@ -6,6 +6,7 @@
import { readdirSync, readFileSync, existsSync } from 'node:fs';
import { join, relative } from 'node:path';
import { spawn } from 'node:child_process';
import { getCacheDir } from '../../scripts/kb-update/lib/cross-platform-paths.mjs';
const pluginRoot = process.env.CLAUDE_PLUGIN_ROOT || join(process.cwd());
const cwd = process.cwd();
@ -130,6 +131,25 @@ if (staleLevels.critical > 0) staleEntries.push(`${staleLevels.critical} critica
if (staleLevels.high > 0) staleEntries.push(`${staleLevels.high} high`);
if (staleLevels.medium > 0) staleEntries.push(`${staleLevels.medium} medium`);
// KB-update auto-cron status (written by scripts/kb-update/weekly-kb-cron.mjs).
// Surfaced BEFORE the staleness-poll block because cron failure is a higher-
// signal event (something the user actively configured stopped working) than
// the slower-moving "files are getting old" signal that follows.
try {
const kbStatusPath = join(getCacheDir('ms-ai-architect'), 'kb-update-status.json');
if (existsSync(kbStatusPath)) {
const kbStatus = JSON.parse(readFileSync(kbStatusPath, 'utf8'));
const surfaceStatuses = new Set(['failure', 'partial', 'budget_exceeded']);
if (kbStatus && surfaceStatuses.has(kbStatus.last_run_status)) {
parts.push(
`KB-update: ${kbStatus.last_run_status} (${kbStatus.last_run_ts}, log: ${kbStatus.log_file})`
);
}
}
} catch {
// Never block session start — silent on read or parse failure.
}
if (staleEntries.length > 0) {
const pollAge = lastPollDaysAgo < Infinity ? ` (pollet ${Math.floor(lastPollDaysAgo)}d siden)` : '';
parts.push(`KB: ${staleEntries.join(', ')} needs update${pollAge}`);