fix: make paired evidence loss visible (#202)
This commit is contained in:
@@ -8,6 +8,33 @@ import {
|
||||
} from './db/paired-turn-outputs.js';
|
||||
|
||||
describe('paired turn output attachments', () => {
|
||||
it('marks truncated output text so reviewers know evidence was clipped', () => {
|
||||
const database = new Database(':memory:');
|
||||
try {
|
||||
applyBaseSchema(database);
|
||||
|
||||
insertPairedTurnOutputInDatabase(
|
||||
database,
|
||||
'paired-task-turn-output-truncated',
|
||||
1,
|
||||
'owner',
|
||||
'x'.repeat(60_000),
|
||||
);
|
||||
|
||||
const [output] = getPairedTurnOutputsFromDatabase(
|
||||
database,
|
||||
'paired-task-turn-output-truncated',
|
||||
);
|
||||
|
||||
expect(output.output_text).toHaveLength(50_000);
|
||||
expect(output.output_text).toMatch(
|
||||
/\[Output truncated: 60000 > 50000 chars\]/,
|
||||
);
|
||||
} finally {
|
||||
database.close();
|
||||
}
|
||||
});
|
||||
|
||||
it('preserves attachments for reviewer evidence prompts', () => {
|
||||
const database = new Database(':memory:');
|
||||
try {
|
||||
|
||||
@@ -14,6 +14,15 @@ import {
|
||||
|
||||
const MAX_TURN_OUTPUT_CHARS = 50_000;
|
||||
|
||||
function storedOutputText(outputText: string): string {
|
||||
if (outputText.length <= MAX_TURN_OUTPUT_CHARS) {
|
||||
return outputText;
|
||||
}
|
||||
|
||||
const notice = `\n\n[Output truncated: ${outputText.length} > ${MAX_TURN_OUTPUT_CHARS} chars]`;
|
||||
return `${outputText.slice(0, MAX_TURN_OUTPUT_CHARS - notice.length)}${notice}`;
|
||||
}
|
||||
|
||||
export function insertPairedTurnOutputInDatabase(
|
||||
database: Database,
|
||||
taskId: string,
|
||||
@@ -48,7 +57,7 @@ export function insertPairedTurnOutputInDatabase(
|
||||
taskId,
|
||||
turnNumber,
|
||||
role,
|
||||
outputText.slice(0, MAX_TURN_OUTPUT_CHARS),
|
||||
storedOutputText(outputText),
|
||||
serializeAttachmentPayload(options.attachments),
|
||||
parseVisibleVerdict(outputText),
|
||||
options.createdAt ?? new Date().toISOString(),
|
||||
|
||||
@@ -33,11 +33,11 @@ const log = {
|
||||
warn: vi.fn(),
|
||||
};
|
||||
|
||||
describe('createPairedExecutionLifecycle', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('createPairedExecutionLifecycle output persistence', () => {
|
||||
it('stores final output attachments with the paired turn output', () => {
|
||||
const lifecycle = createPairedExecutionLifecycle({
|
||||
pairedExecutionContext: {
|
||||
@@ -101,7 +101,67 @@ describe('createPairedExecutionLifecycle', () => {
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('createPairedExecutionLifecycle verdict routing', () => {
|
||||
it('uses the full final output for paired verdict routing', () => {
|
||||
const lifecycle = createPairedExecutionLifecycle({
|
||||
pairedExecutionContext: {
|
||||
task: {
|
||||
id: 'paired-task-long-final',
|
||||
chat_jid: 'group@test',
|
||||
group_folder: 'test-group',
|
||||
owner_service_id: 'codex-main',
|
||||
reviewer_service_id: 'claude',
|
||||
title: null,
|
||||
source_ref: 'HEAD',
|
||||
plan_notes: null,
|
||||
round_trip_count: 0,
|
||||
review_requested_at: null,
|
||||
status: 'active',
|
||||
arbiter_verdict: null,
|
||||
arbiter_requested_at: null,
|
||||
completion_reason: null,
|
||||
created_at: '2026-04-09T00:00:00.000Z',
|
||||
updated_at: '2026-04-09T00:00:00.000Z',
|
||||
},
|
||||
workspace: null,
|
||||
envOverrides: {},
|
||||
},
|
||||
pairedTurnIdentity: {
|
||||
turnId: 'paired-task-long-final:2026-04-09T00:00:00.000Z:owner-turn',
|
||||
taskId: 'paired-task-long-final',
|
||||
taskUpdatedAt: '2026-04-09T00:00:00.000Z',
|
||||
intentKind: 'owner-turn',
|
||||
role: 'owner',
|
||||
},
|
||||
completedRole: 'owner',
|
||||
chatJid: 'group@test',
|
||||
runId: 'run-long-final',
|
||||
enqueueMessageCheck: vi.fn(),
|
||||
log,
|
||||
});
|
||||
const longPreface = '검증 증거 '.repeat(100);
|
||||
const finalOutput = `${longPreface}\nTASK_DONE\n뒤쪽 상태줄도 라우팅에 반영되어야 합니다.`;
|
||||
|
||||
lifecycle.recordFinalOutputBeforeDelivery(finalOutput);
|
||||
|
||||
expect(
|
||||
pairedExecutionContextModule.completePairedExecutionContext,
|
||||
).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
taskId: 'paired-task-long-final',
|
||||
role: 'owner',
|
||||
status: 'succeeded',
|
||||
runId: 'run-long-final',
|
||||
summary: finalOutput,
|
||||
}),
|
||||
);
|
||||
expect(finalOutput.indexOf('TASK_DONE')).toBeGreaterThan(500);
|
||||
});
|
||||
});
|
||||
|
||||
describe('createPairedExecutionLifecycle completion handling', () => {
|
||||
it('does not emit a second public notification after arbiter ESCALATE', async () => {
|
||||
const outputs: AgentOutput[] = [];
|
||||
|
||||
|
||||
@@ -422,7 +422,7 @@ class PairedExecutionLifecycleController implements PairedExecutionLifecycle {
|
||||
this.pairedFinalAttachments = attachments;
|
||||
}
|
||||
if (!this.pairedSummaryLocked) {
|
||||
this.pairedExecutionSummary = outputText.slice(0, 500);
|
||||
this.pairedExecutionSummary = outputText;
|
||||
this.pairedSummaryLocked = true;
|
||||
}
|
||||
this.pairedSawOutput = true;
|
||||
@@ -451,7 +451,7 @@ class PairedExecutionLifecycleController implements PairedExecutionLifecycle {
|
||||
'Adopted direct terminal delivery as paired final output',
|
||||
);
|
||||
} else if (!this.pairedSummaryLocked) {
|
||||
this.pairedExecutionSummary = this.pairedFinalOutput.slice(0, 500);
|
||||
this.pairedExecutionSummary = this.pairedFinalOutput;
|
||||
this.pairedSummaryLocked = true;
|
||||
}
|
||||
return outputText;
|
||||
|
||||
@@ -323,6 +323,9 @@ describe('message-runtime-prompts arbiter output context', () => {
|
||||
|
||||
expect(prompt).not.toContain('arbiter-context-output-01');
|
||||
expect(prompt).not.toContain('arbiter-context-output-02');
|
||||
expect(prompt).toContain(
|
||||
'[Earlier paired turn outputs omitted: 2 older outputs not shown]',
|
||||
);
|
||||
expect(prompt).toContain('arbiter-context-output-03');
|
||||
expect(prompt).toContain('arbiter-context-output-08');
|
||||
expect(prompt).not.toContain('예전 유저 지시');
|
||||
@@ -362,6 +365,9 @@ describe('message-runtime-prompts arbiter output context', () => {
|
||||
expect(prompt).not.toContain('이전 작업의 유저 지시');
|
||||
expect(prompt).not.toContain('arbiter-context-output-01');
|
||||
expect(prompt).not.toContain('arbiter-context-output-02');
|
||||
expect(prompt).toContain(
|
||||
'[Earlier paired turn outputs omitted: 2 older outputs not shown]',
|
||||
);
|
||||
expect(prompt).toContain('arbiter-context-output-03');
|
||||
expect(prompt).toContain('arbiter-context-output-08');
|
||||
});
|
||||
|
||||
@@ -60,6 +60,45 @@ function turnOutputsToMessages(
|
||||
}));
|
||||
}
|
||||
|
||||
function omittedTurnOutputsMessage(args: {
|
||||
chatJid: string;
|
||||
omittedCount: number;
|
||||
firstVisibleOutput?: PairedTurnOutput;
|
||||
}): NewMessage {
|
||||
return {
|
||||
id: `turn-output-omitted-${args.firstVisibleOutput?.task_id ?? 'unknown'}-${args.omittedCount}`,
|
||||
chat_jid: args.chatJid,
|
||||
sender: 'system',
|
||||
sender_name: 'system',
|
||||
content: `[Earlier paired turn outputs omitted: ${args.omittedCount} older outputs not shown]`,
|
||||
timestamp:
|
||||
args.firstVisibleOutput?.created_at ?? '1970-01-01T00:00:00.000Z',
|
||||
is_bot_message: true as const,
|
||||
is_from_me: false as const,
|
||||
};
|
||||
}
|
||||
|
||||
function latestTurnOutputMessagesWithOmissionMarker(
|
||||
outputs: PairedTurnOutput[],
|
||||
chatJid: string,
|
||||
limit: number,
|
||||
): NewMessage[] {
|
||||
const latestOutputs = latestTurnOutputs(outputs, limit);
|
||||
const messages = turnOutputsToMessages(latestOutputs, chatJid);
|
||||
const omittedCount = outputs.length - latestOutputs.length;
|
||||
if (omittedCount <= 0) {
|
||||
return messages;
|
||||
}
|
||||
return [
|
||||
omittedTurnOutputsMessage({
|
||||
chatJid,
|
||||
omittedCount,
|
||||
firstVisibleOutput: latestOutputs[0],
|
||||
}),
|
||||
...messages,
|
||||
];
|
||||
}
|
||||
|
||||
function mergeHumanAndTurnOutputMessages(
|
||||
chatJid: string,
|
||||
humanMessages: NewMessage[],
|
||||
@@ -221,12 +260,10 @@ export function buildArbiterPromptForTask(args: {
|
||||
args.turnOutputs.length > 0
|
||||
? [
|
||||
...taskHumanMessages,
|
||||
...turnOutputsToMessages(
|
||||
latestTurnOutputs(
|
||||
args.turnOutputs,
|
||||
ARBITER_TURN_OUTPUT_CONTEXT_LIMIT,
|
||||
),
|
||||
...latestTurnOutputMessagesWithOmissionMarker(
|
||||
args.turnOutputs,
|
||||
args.chatJid,
|
||||
ARBITER_TURN_OUTPUT_CONTEXT_LIMIT,
|
||||
),
|
||||
]
|
||||
: args.labeledRecentMessages;
|
||||
|
||||
@@ -113,22 +113,17 @@ export function handleArbiterCompletion(args: {
|
||||
transitionPairedTaskStatus({
|
||||
taskId,
|
||||
currentStatus: 'in_arbitration',
|
||||
nextStatus: 'review_ready',
|
||||
nextStatus: 'completed',
|
||||
expectedUpdatedAt: task.updated_at,
|
||||
updatedAt: now,
|
||||
patch: {
|
||||
round_trip_count: ARBITER_RESOLUTION_ROUND_TRIP_COUNT,
|
||||
owner_failure_count: 0,
|
||||
owner_step_done_streak: 0,
|
||||
finalize_step_done_count: 0,
|
||||
empty_step_done_streak: 0,
|
||||
arbiter_verdict: 'unknown',
|
||||
arbiter_requested_at: null,
|
||||
completion_reason: 'arbiter_escalated',
|
||||
},
|
||||
});
|
||||
logger.warn(
|
||||
{ taskId, summary: summary?.slice(0, 200) },
|
||||
'Arbiter verdict unrecognized — returning task to reviewer as proceed fallback',
|
||||
'Arbiter verdict unrecognized — escalating instead of treating it as approval',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
164
src/paired-execution-context-carry-forward.test.ts
Normal file
164
src/paired-execution-context-carry-forward.test.ts
Normal file
@@ -0,0 +1,164 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
vi.mock('./config.js', async () => {
|
||||
const actual =
|
||||
await vi.importActual<typeof import('./config.js')>('./config.js');
|
||||
return {
|
||||
...actual,
|
||||
PAIRED_CARRY_FORWARD_LATEST_OWNER_FINAL: true,
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock('./db.js', () => {
|
||||
const updatePairedTask = vi.fn();
|
||||
return {
|
||||
cancelPairedTurn: vi.fn(),
|
||||
createPairedTask: vi.fn(),
|
||||
getLatestPairedTaskForChat: vi.fn(),
|
||||
getLatestOpenPairedTaskForChat: vi.fn(),
|
||||
getPairedTaskById: vi.fn(),
|
||||
getPairedTurnById: vi.fn(),
|
||||
getPairedTurnOutputs: vi.fn(() => []),
|
||||
getPairedWorkspace: vi.fn(),
|
||||
insertPairedTurnOutput: vi.fn(),
|
||||
updatePairedTask,
|
||||
updatePairedTaskIfUnchanged: vi.fn((id, _expectedUpdatedAt, updates) => {
|
||||
updatePairedTask(id, updates);
|
||||
return true;
|
||||
}),
|
||||
upsertPairedProject: vi.fn(),
|
||||
hasActiveCiWatcherForChat: vi.fn(() => false),
|
||||
releasePairedTaskExecutionLease: vi.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock('./paired-workspace-manager.js', () => ({
|
||||
isOwnerWorkspaceRepairNeededError: vi.fn(() => false),
|
||||
markPairedTaskReviewReady: vi.fn(),
|
||||
prepareReviewerWorkspaceForExecution: vi.fn(() => ({
|
||||
workspace: null,
|
||||
autoRefreshed: false,
|
||||
})),
|
||||
provisionOwnerWorkspaceForPairedTask: vi.fn(() => ({
|
||||
id: 'task-new:owner',
|
||||
task_id: 'task-new',
|
||||
role: 'owner',
|
||||
workspace_dir: '/tmp/paired/task-new/owner',
|
||||
snapshot_source_dir: null,
|
||||
snapshot_ref: null,
|
||||
status: 'ready',
|
||||
snapshot_refreshed_at: null,
|
||||
created_at: '2026-03-28T00:00:00.000Z',
|
||||
updated_at: '2026-03-28T00:00:00.000Z',
|
||||
})),
|
||||
}));
|
||||
|
||||
vi.mock('./logger.js', () => ({
|
||||
logger: {
|
||||
debug: vi.fn(),
|
||||
info: vi.fn(),
|
||||
warn: vi.fn(),
|
||||
error: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
import * as db from './db.js';
|
||||
import { resolveOwnerTaskForHumanMessage } from './paired-execution-context.js';
|
||||
import type { PairedTask, RegisteredGroup, RoomRoleContext } from './types.js';
|
||||
|
||||
const group: RegisteredGroup = {
|
||||
name: 'Paired Room',
|
||||
folder: 'paired-room',
|
||||
trigger: '@codex',
|
||||
added_at: '2026-03-28T00:00:00.000Z',
|
||||
agentType: 'codex',
|
||||
workDir: '/repo/canonical',
|
||||
};
|
||||
|
||||
const ownerContext: RoomRoleContext = {
|
||||
serviceId: 'codex-main',
|
||||
role: 'owner',
|
||||
ownerServiceId: 'codex-main',
|
||||
reviewerServiceId: 'claude-review',
|
||||
failoverOwner: false,
|
||||
};
|
||||
|
||||
function buildTask(overrides: Partial<PairedTask> = {}): PairedTask {
|
||||
return {
|
||||
id: 'task-superseded',
|
||||
chat_jid: 'dc:test',
|
||||
group_folder: group.folder,
|
||||
owner_service_id: 'codex-main',
|
||||
reviewer_service_id: 'claude-review',
|
||||
owner_agent_type: 'codex',
|
||||
reviewer_agent_type: 'claude-code',
|
||||
arbiter_agent_type: 'codex',
|
||||
title: null,
|
||||
source_ref: 'HEAD',
|
||||
plan_notes: null,
|
||||
review_requested_at: null,
|
||||
round_trip_count: 0,
|
||||
owner_failure_count: 0,
|
||||
owner_step_done_streak: 0,
|
||||
finalize_step_done_count: 0,
|
||||
task_done_then_user_reopen_count: 0,
|
||||
empty_step_done_streak: 0,
|
||||
status: 'merge_ready',
|
||||
arbiter_verdict: null,
|
||||
arbiter_requested_at: null,
|
||||
completion_reason: null,
|
||||
created_at: '2026-03-28T00:00:00.000Z',
|
||||
updated_at: '2026-03-28T00:05:00.000Z',
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe('paired execution carry-forward attachments', () => {
|
||||
it('preserves latest owner final attachments when carrying context into a superseding task', () => {
|
||||
const supersededTask = buildTask();
|
||||
const attachments = [
|
||||
{
|
||||
path: '/data/attachments/paired-turn-outputs/task/1/owner/result.png',
|
||||
name: 'result.png',
|
||||
mime: 'image/png',
|
||||
},
|
||||
];
|
||||
vi.mocked(db.getPairedTurnOutputs).mockReturnValue([
|
||||
{
|
||||
id: 1,
|
||||
task_id: supersededTask.id,
|
||||
turn_number: 1,
|
||||
role: 'owner',
|
||||
output_text: 'TASK_DONE\n새 렌더 이미지입니다.',
|
||||
attachments,
|
||||
created_at: '2026-03-28T00:01:00.000Z',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
task_id: supersededTask.id,
|
||||
turn_number: 2,
|
||||
role: 'reviewer',
|
||||
output_text: 'TASK_DONE\nreview approved',
|
||||
created_at: '2026-03-28T00:02:00.000Z',
|
||||
},
|
||||
]);
|
||||
|
||||
resolveOwnerTaskForHumanMessage({
|
||||
group,
|
||||
chatJid: 'dc:test',
|
||||
roomRoleContext: ownerContext,
|
||||
existingTask: supersededTask,
|
||||
});
|
||||
|
||||
expect(db.insertPairedTurnOutput).toHaveBeenCalledWith(
|
||||
expect.any(String),
|
||||
0,
|
||||
'owner',
|
||||
expect.stringContaining('TASK_DONE\n새 렌더 이미지입니다.'),
|
||||
{
|
||||
createdAt: '2026-03-28T00:01:00.000Z',
|
||||
attachments,
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -169,7 +169,7 @@ describe('paired execution routing loop guards', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('routes unknown arbiter verdicts to reviewer as a proceed fallback', () => {
|
||||
it('escalates unknown arbiter verdicts instead of treating them as approval', () => {
|
||||
vi.mocked(db.getPairedTaskById).mockReturnValue(
|
||||
buildPairedTask({
|
||||
status: 'in_arbitration',
|
||||
@@ -190,12 +190,9 @@ describe('paired execution routing loop guards', () => {
|
||||
expect(db.updatePairedTask).toHaveBeenCalledWith(
|
||||
'task-1',
|
||||
expect.objectContaining({
|
||||
status: 'review_ready',
|
||||
round_trip_count: 0,
|
||||
owner_step_done_streak: 0,
|
||||
empty_step_done_streak: 0,
|
||||
status: 'completed',
|
||||
arbiter_verdict: 'unknown',
|
||||
arbiter_requested_at: null,
|
||||
completion_reason: 'arbiter_escalated',
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -259,13 +259,17 @@ function carryForwardLatestOwnerFinal(args: {
|
||||
0,
|
||||
'owner',
|
||||
`[Carried forward context from the previous task: latest owner final]\n${latestOwnerFinal.output_text}`,
|
||||
latestOwnerFinal.created_at,
|
||||
{
|
||||
createdAt: latestOwnerFinal.created_at,
|
||||
attachments: latestOwnerFinal.attachments,
|
||||
},
|
||||
);
|
||||
logger.info(
|
||||
{
|
||||
sourceTaskId: args.sourceTask.id,
|
||||
targetTaskId: args.targetTask.id,
|
||||
carriedChars: latestOwnerFinal.output_text.length,
|
||||
attachmentCount: latestOwnerFinal.attachments?.length ?? 0,
|
||||
},
|
||||
'Carried forward latest owner final into superseding paired task',
|
||||
);
|
||||
|
||||
@@ -43,7 +43,7 @@ describe('paired verdict parser', () => {
|
||||
).toBe('continue');
|
||||
});
|
||||
|
||||
it('does not scan beyond the leading visible line window', () => {
|
||||
it('accepts status tokens after a longer evidence preface', () => {
|
||||
expect(
|
||||
parseVisibleVerdict(
|
||||
[
|
||||
@@ -55,14 +55,41 @@ describe('paired verdict parser', () => {
|
||||
'TASK_DONE',
|
||||
].join('\n'),
|
||||
),
|
||||
).toBe('task_done');
|
||||
});
|
||||
|
||||
it('does not scan beyond the leading visible line window', () => {
|
||||
expect(
|
||||
parseVisibleVerdict(
|
||||
[
|
||||
'01',
|
||||
'02',
|
||||
'03',
|
||||
'04',
|
||||
'05',
|
||||
'06',
|
||||
'07',
|
||||
'08',
|
||||
'09',
|
||||
'10',
|
||||
'11',
|
||||
'12',
|
||||
'TASK_DONE',
|
||||
].join('\n'),
|
||||
),
|
||||
).toBe('continue');
|
||||
});
|
||||
|
||||
it('classifies arbiter verdicts from the first visible line', () => {
|
||||
it('classifies arbiter verdicts from leading visible lines', () => {
|
||||
expect(classifyArbiterVerdict('PROCEED\ncontinue')).toBe('proceed');
|
||||
expect(classifyArbiterVerdict('**VERDICT: REVISE**\nfix it')).toBe(
|
||||
'revise',
|
||||
);
|
||||
expect(
|
||||
classifyArbiterVerdict(
|
||||
['중재 판단을 정리합니다.', 'VERDICT: REVISE', 'fix it'].join('\n'),
|
||||
),
|
||||
).toBe('revise');
|
||||
expect(
|
||||
classifyArbiterVerdict(
|
||||
'<internal>private notes</internal>\nVERDICT — RESET\nrestart',
|
||||
|
||||
@@ -11,7 +11,8 @@ export type VisibleVerdict =
|
||||
|
||||
export type ArbiterVerdictResult = ArbiterVerdict | 'unknown';
|
||||
|
||||
const VISIBLE_VERDICT_SCAN_LINE_LIMIT = 5;
|
||||
const VISIBLE_VERDICT_SCAN_LINE_LIMIT = 12;
|
||||
const ARBITER_VERDICT_SCAN_LINE_LIMIT = 12;
|
||||
|
||||
function leadingVisibleLines(text: string, limit: number): string[] {
|
||||
const lines: string[] = [];
|
||||
@@ -35,6 +36,10 @@ function leadingVisibleLines(text: string, limit: number): string[] {
|
||||
return lines;
|
||||
}
|
||||
|
||||
function stripInternalBlocks(text: string): string {
|
||||
return text.replace(/<internal>[\s\S]*?(?:<\/internal>|$)/g, '');
|
||||
}
|
||||
|
||||
function parseVisibleVerdictLine(line: string): VisibleVerdict | null {
|
||||
if (/^\*{0,2}BLOCKED(?:\*{0,2})?\b/i.test(line)) return 'blocked';
|
||||
if (/^\*{0,2}NEEDS_CONTEXT(?:\*{0,2})?\b/i.test(line)) return 'needs_context';
|
||||
@@ -52,7 +57,7 @@ export function parseVisibleVerdict(
|
||||
summary: string | null | undefined,
|
||||
): VisibleVerdict {
|
||||
if (!summary) return 'continue';
|
||||
const cleaned = summary.replace(/<internal>[\s\S]*?<\/internal>/g, '').trim();
|
||||
const cleaned = stripInternalBlocks(summary).trim();
|
||||
if (!cleaned) return 'continue';
|
||||
for (const line of leadingVisibleLines(
|
||||
cleaned,
|
||||
@@ -68,17 +73,21 @@ export function classifyArbiterVerdict(
|
||||
summary: string | null | undefined,
|
||||
): ArbiterVerdictResult {
|
||||
if (!summary) return 'unknown';
|
||||
const cleaned = summary.replace(/<internal>[\s\S]*?<\/internal>/g, '').trim();
|
||||
const cleaned = stripInternalBlocks(summary).trim();
|
||||
if (!cleaned) return 'unknown';
|
||||
const firstLine = cleaned.split('\n')[0].trim();
|
||||
const verdictMatch = firstLine.match(
|
||||
/\*{0,2}(?:VERDICT\s*[:—-]\s*)?(PROCEED|REVISE|RESET|ESCALATE|CONTINUE)\*{0,2}/i,
|
||||
);
|
||||
if (verdictMatch) {
|
||||
const normalized = verdictMatch[1].toLowerCase();
|
||||
return normalized === 'continue'
|
||||
? 'proceed'
|
||||
: (normalized as ArbiterVerdict);
|
||||
for (const line of leadingVisibleLines(
|
||||
cleaned,
|
||||
ARBITER_VERDICT_SCAN_LINE_LIMIT,
|
||||
)) {
|
||||
const verdictMatch = line.match(
|
||||
/\*{0,2}(?:VERDICT\s*[:—-]\s*)?(PROCEED|REVISE|RESET|ESCALATE|CONTINUE)\*{0,2}/i,
|
||||
);
|
||||
if (verdictMatch) {
|
||||
const normalized = verdictMatch[1].toLowerCase();
|
||||
return normalized === 'continue'
|
||||
? 'proceed'
|
||||
: (normalized as ArbiterVerdict);
|
||||
}
|
||||
}
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user