feat(observer): parallel_session +OR pre-flight git fetch heuristic (Task 13 PIVOT)

Closes brain-retro 2026-05-20 #13 PIVOT — additive to F1 (parallel
session sessions session). F1 narrowed parallel_session to tool_result-only
to fix live FP. This Task adds OR-clause: Bash command containing
'git fetch && git log HEAD..origin/...' (Pravila §15.2 pre-flight)
is a strong signal that the operator expects parallel sessions.

Does NOT overwrite F1 — both signals coexist via OR.

4 new vitest tests, 319/319 GREEN.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Дмитрий
2026-05-20 13:22:16 +03:00
parent ef4cc825bf
commit 5d3e29669b
2 changed files with 73 additions and 3 deletions
+23 -3
View File
@@ -207,13 +207,33 @@ export function extractEnvironment(allEntries, turnStartIdx) {
// Scope NARROWED to tool_result content (real command output / Bash stderr): prose
// mentions in user prompts / assistant text — including analysis text that
// references collision phrases — must not trigger. Fixes live FP (episode line 20).
const parallel_session = /чужой staged|foreign git index|index\.lock|another git process/i.test(
collectToolResultText(turn)
);
const parallel_session =
/чужой staged|foreign git index|index\.lock|another git process/i.test(collectToolResultText(turn))
|| hasPreFlightFetch(turn);
return { economy_level, model, post_compaction, session_turn, parallel_session };
}
/**
* Pravila §15.2 pre-flight signal (Task 13 PIVOT): Bash-команда turn'а
* содержит `git fetch ... && git log HEAD..origin/main ...` — это hard-rule
* pre-flight sync перед правкой нормативки в параллельных сессиях. Сильный
* сигнал «заказчик ожидает параллельных сессий», аддитивный к F1 collision
* detector (parallel_session). Не overwrite — OR-clause.
*/
function hasPreFlightFetch(turn) {
for (const e of turn || []) {
const content = e && e.message && Array.isArray(e.message.content) ? e.message.content : [];
for (const b of content) {
if (b && b.type === 'tool_use' && b.name === 'Bash' && b.input) {
const cmd = String(b.input.command || '');
if (/git\s+fetch[^|&;]*&&[^|&;]*git\s+log\s+HEAD\.\.origin\//i.test(cmd)) return true;
}
}
}
return false;
}
/**
* Collect text content from tool_result blocks in the turn — the only surface
* trusted for parallel_session collision evidence (see extractEnvironment).