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
+50
View File
@@ -1433,3 +1433,53 @@ describe('parseTranscript — subagent_invoked events (Task 12)', () => {
expect(subs[0].model).toBe('haiku');
});
});
describe('parallel_session — pre-flight OR clause (Task 13 PIVOT)', () => {
it('is true when Bash ran "git fetch && git log HEAD..origin/main"', () => {
const transcript = [
JSON.stringify({ sessionId: 's' }),
JSON.stringify({ type: 'user', message: { role: 'user', content: 'pre-flight' }, uuid: 'u1', timestamp: '2026-05-20T00:00:00Z' }),
JSON.stringify({ type: 'assistant', message: { role: 'assistant', content: [
{ type: 'tool_use', id: 't1', name: 'Bash', input: { command: 'git fetch && git log HEAD..origin/main --oneline' } }
] }, uuid: 'u2', timestamp: '2026-05-20T00:00:01Z' }),
].join('\n');
const ep = parseTranscript(transcript);
expect(ep.environment.parallel_session).toBe(true);
});
it('is true with origin/<other-branch> via HEAD..origin/feat', () => {
const transcript = [
JSON.stringify({ sessionId: 's' }),
JSON.stringify({ type: 'user', message: { role: 'user', content: 'sync' }, uuid: 'u1', timestamp: '2026-05-20T00:00:00Z' }),
JSON.stringify({ type: 'assistant', message: { role: 'assistant', content: [
{ type: 'tool_use', id: 't1', name: 'Bash', input: { command: 'git fetch origin && git log HEAD..origin/feat/x --oneline' } }
] }, uuid: 'u2', timestamp: '2026-05-20T00:00:01Z' }),
].join('\n');
const ep = parseTranscript(transcript);
expect(ep.environment.parallel_session).toBe(true);
});
it('F1 still works — collision text in tool_result triggers', () => {
const transcript = [
JSON.stringify({ sessionId: 's' }),
JSON.stringify({ type: 'user', message: { role: 'user', content: 'go' }, uuid: 'u1', timestamp: '2026-05-20T00:00:00Z' }),
JSON.stringify({ type: 'assistant', message: { role: 'assistant', content: [
{ type: 'tool_use', id: 't1', name: 'Bash', input: { command: 'git commit -am ok' } }
] }, uuid: 'u2', timestamp: '2026-05-20T00:00:01Z' }),
JSON.stringify({ type: 'user', message: { role: 'user', content: [
{ type: 'tool_result', tool_use_id: 't1', content: 'fatal: index.lock exists' }
] }, uuid: 'u3', timestamp: '2026-05-20T00:00:02Z' }),
].join('\n');
const ep = parseTranscript(transcript);
expect(ep.environment.parallel_session).toBe(true);
});
it('false on regular Bash without pre-flight or collision', () => {
const transcript = [
JSON.stringify({ sessionId: 's' }),
JSON.stringify({ type: 'user', message: { role: 'user', content: 'go' }, uuid: 'u1', timestamp: '2026-05-20T00:00:00Z' }),
JSON.stringify({ type: 'assistant', message: { role: 'assistant', content: [
{ type: 'tool_use', id: 't1', name: 'Bash', input: { command: 'npm run test:tools' } }
] }, uuid: 'u2', timestamp: '2026-05-20T00:00:01Z' }),
].join('\n');
const ep = parseTranscript(transcript);
expect(ep.environment.parallel_session).toBe(false);
});
});