feat(brain): surface router-gate v4 signals into episode + factor axes

Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com
This commit is contained in:
Дмитрий
2026-05-31 19:05:20 +03:00
parent 2f59541d4b
commit c55e14b626
18 changed files with 979 additions and 16 deletions
+15 -2
View File
@@ -28,6 +28,8 @@ import { buildHookMap, resolveScriptCounts } from './observer-hook-resolver.mjs'
// для слепого fallback на heuristic recommended_node — убрано 2026-05-26
// (brain-retro #6 follow-up). Импорты сняты как dead code.
import { loadRegistry } from './registry-load.mjs';
import { extractV4Signals } from './observer-v4-signals.mjs';
import { JUDGE_PER_CALL_USD } from './cost-pricing.mjs';
const __dirname = dirname(fileURLToPath(import.meta.url));
@@ -847,6 +849,12 @@ export function parseTranscript(transcriptText, fallbackSessionId = null, option
const ended_at = stamps[stamps.length - 1] || started_at;
const durationMs = new Date(ended_at) - new Date(started_at);
const _v4 = extractV4Signals(sessionId, {
startMs: new Date(started_at).getTime(),
endMs: new Date(ended_at).getTime(),
baseDir: options.runtimeBaseDir || routerStateBaseDir,
});
const { skills, counts, errors } = collectToolUse(turn);
const events = [];
@@ -887,7 +895,7 @@ export function parseTranscript(transcriptText, fallbackSessionId = null, option
return {
schema_version: 4,
schema_minor: 3,
schema_minor: 4,
task_id: sessionId,
task_ref: sessionId,
timestamps: { started_at, ended_at },
@@ -910,7 +918,12 @@ export function parseTranscript(transcriptText, fallbackSessionId = null, option
// NB: routerState (line 855) honours routerStateBaseDir option; _state at line 898
// does not (always default dir). Use routerState here so tests with custom temp dir
// see the merged values.
task_cost: { ...extractTokenUsage(turn), ...((routerState && routerState.task_cost) || {}) },
task_cost: {
...extractTokenUsage(turn),
...((routerState && routerState.task_cost) || {}),
judge_spend_usd: _v4.judge_calls * JUDGE_PER_CALL_USD,
},
v4_signals: _v4,
// Pass 3 — dynamics meta-block (project-brain-factor-analysis-4passes).
// prompt_length_chars: strlen of first user prompt (engagement / clarity proxy).
// mcp_servers_used: unique mcp__<server>__* fingerprints in this turn.