feat: let the owner skip review for change-free explanation answers
The owner may end a TASK_DONE answer with "리뷰 불필요: <reason>". The host treats it as a request and honors it only when every guard holds: - workspace content equals the task base (hasCodeChangesSinceRef), the working tree is clean, and HEAD did not move during the owner run - the run used no file-mutating tool (Edit/Write/MultiEdit/NotebookEdit), no subagent (Agent/Task) and no state-changing or unknown MCP tool - every Bash command is classified read-only by a conservative quote-aware classifier (src/bash-command-classifier.ts); anything unknown counts as mutating - tool usage was reported and not truncated (agent-runner now reports tool names and Bash commands as toolUsage on its terminal output) - the user did not ask for a review in this task When honored the task completes as review_skipped with no reviewer or finalize turn; the answer is delivered with the marker line removed and a small "-# 검토 생략 …" note. Otherwise the marker is stripped and the normal review runs. A bare "검토해줘"-style message right after a review-skipped answer reopens that task for the reviewer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -27,6 +27,7 @@ import {
|
||||
buildTaskProgressOutput,
|
||||
buildTaskStartedOutput,
|
||||
} from './task-progress-mapping.js';
|
||||
import { ToolUsageRecorder, type RunnerToolUsage } from './tool-usage.js';
|
||||
|
||||
export interface ClaudeQueryPaths {
|
||||
groupDir: string;
|
||||
@@ -56,11 +57,13 @@ export interface ClaudeQueryResult {
|
||||
closedDuringQuery: boolean;
|
||||
terminalResultObserved: boolean;
|
||||
compaction?: RunnerCompaction;
|
||||
toolUsage: RunnerToolUsage;
|
||||
}
|
||||
|
||||
class ClaudeQueryRunner {
|
||||
private readonly stream: MessageStream;
|
||||
private readonly trackedAgentTasks = new TopLevelAgentTaskTracker();
|
||||
private readonly toolUsage = new ToolUsageRecorder();
|
||||
private readonly extraDirs: string[] = [];
|
||||
private readonly effectiveCwd: string;
|
||||
private ipcPolling = true;
|
||||
@@ -119,6 +122,7 @@ class ClaudeQueryRunner {
|
||||
closedDuringQuery: this.closedDuringQuery,
|
||||
terminalResultObserved: this.terminalResultObserved,
|
||||
compaction: this.compaction,
|
||||
toolUsage: this.toolUsage.snapshot(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -154,6 +158,7 @@ class ClaudeQueryRunner {
|
||||
status: 'success',
|
||||
...normalizeStructuredOutput(this.pendingProgressText),
|
||||
newSessionId: this.newSessionId,
|
||||
toolUsage: this.toolUsage.snapshot(),
|
||||
});
|
||||
this.pendingProgressText = null;
|
||||
this.terminalResultObserved = true;
|
||||
@@ -523,11 +528,13 @@ class ClaudeQueryRunner {
|
||||
...normalizeStructuredOutput(textResult || null),
|
||||
newSessionId: this.newSessionId,
|
||||
...buildCompactionOutput(this.compaction),
|
||||
toolUsage: this.toolUsage.snapshot(),
|
||||
});
|
||||
}
|
||||
|
||||
private handleAssistantMessage(message: unknown): boolean {
|
||||
this.trackedAgentTasks.rememberAssistantMessage(message);
|
||||
this.toolUsage.recordAssistantMessage(message);
|
||||
const stopReason = (message as { stop_reason?: string }).stop_reason;
|
||||
const textResult = extractAssistantText(message);
|
||||
if (textResult || stopReason === 'end_turn') {
|
||||
@@ -545,6 +552,7 @@ class ClaudeQueryRunner {
|
||||
...normalizeStructuredOutput(textResult),
|
||||
newSessionId: this.newSessionId,
|
||||
...buildCompactionOutput(this.compaction),
|
||||
toolUsage: this.toolUsage.snapshot(),
|
||||
});
|
||||
this.terminalResultObserved = true;
|
||||
this.ipcPolling = false;
|
||||
@@ -582,6 +590,7 @@ class ClaudeQueryRunner {
|
||||
...normalizeStructuredOutput(this.pendingProgressText),
|
||||
newSessionId: this.newSessionId,
|
||||
...buildCompactionOutput(this.compaction),
|
||||
toolUsage: this.toolUsage.snapshot(),
|
||||
});
|
||||
this.terminalResultObserved = true;
|
||||
this.resultCount++;
|
||||
|
||||
@@ -168,6 +168,7 @@ async function main(): Promise<void> {
|
||||
result: null,
|
||||
newSessionId: sessionId,
|
||||
...buildCompactionOutput(queryResult.compaction),
|
||||
toolUsage: queryResult.toolUsage,
|
||||
});
|
||||
} else if (queryResult.terminalResultObserved) {
|
||||
log('Terminal result already emitted, exiting single-turn runtime');
|
||||
|
||||
@@ -12,6 +12,8 @@ import {
|
||||
writeProtocolOutput,
|
||||
} from 'ejclaw-runners-shared';
|
||||
|
||||
import type { RunnerToolUsage } from './tool-usage.js';
|
||||
|
||||
export interface RunnerOutput {
|
||||
status: 'success' | 'error';
|
||||
phase?: 'progress' | 'final' | 'tool-activity' | 'intermediate';
|
||||
@@ -26,6 +28,7 @@ export interface RunnerOutput {
|
||||
completed: boolean;
|
||||
trigger?: string | null;
|
||||
};
|
||||
toolUsage?: RunnerToolUsage;
|
||||
}
|
||||
|
||||
export type RunnerCompaction = NonNullable<RunnerOutput['compaction']>;
|
||||
|
||||
69
runners/agent-runner/src/tool-usage.ts
Normal file
69
runners/agent-runner/src/tool-usage.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Records which tools an agent run called, so the host can tell whether an
|
||||
* owner turn could have changed anything (see src/review-skip.ts). The shape
|
||||
* mirrors the host's AgentToolUsage.
|
||||
*/
|
||||
export interface RunnerToolUsage {
|
||||
tools: string[];
|
||||
bashCommands: string[];
|
||||
truncated?: boolean;
|
||||
}
|
||||
|
||||
const MAX_TOOL_ENTRIES = 500;
|
||||
const MAX_BASH_COMMANDS = 200;
|
||||
const MAX_BASH_COMMAND_CHARS = 4000;
|
||||
|
||||
type ToolUseBlock = {
|
||||
type?: unknown;
|
||||
name?: unknown;
|
||||
input?: { command?: unknown } | null;
|
||||
};
|
||||
|
||||
export class ToolUsageRecorder {
|
||||
private readonly tools: string[] = [];
|
||||
private readonly bashCommands: string[] = [];
|
||||
private truncated = false;
|
||||
|
||||
/** Record every tool_use block of an SDK assistant message. */
|
||||
recordAssistantMessage(message: unknown): void {
|
||||
const blocks = (message as { message?: { content?: unknown } }).message
|
||||
?.content;
|
||||
if (!Array.isArray(blocks)) return;
|
||||
for (const block of blocks as ToolUseBlock[]) {
|
||||
if (block?.type !== 'tool_use' || typeof block.name !== 'string') {
|
||||
continue;
|
||||
}
|
||||
this.recordTool(block.name, block.input?.command);
|
||||
}
|
||||
}
|
||||
|
||||
private recordTool(name: string, command: unknown): void {
|
||||
if (this.tools.length >= MAX_TOOL_ENTRIES) {
|
||||
this.truncated = true;
|
||||
} else {
|
||||
this.tools.push(name);
|
||||
}
|
||||
if (name !== 'Bash') return;
|
||||
if (typeof command !== 'string') {
|
||||
// A Bash call whose command cannot be read must not look read-only.
|
||||
this.truncated = true;
|
||||
return;
|
||||
}
|
||||
if (
|
||||
this.bashCommands.length >= MAX_BASH_COMMANDS ||
|
||||
command.length > MAX_BASH_COMMAND_CHARS
|
||||
) {
|
||||
this.truncated = true;
|
||||
return;
|
||||
}
|
||||
this.bashCommands.push(command);
|
||||
}
|
||||
|
||||
snapshot(): RunnerToolUsage {
|
||||
return {
|
||||
tools: [...this.tools],
|
||||
bashCommands: [...this.bashCommands],
|
||||
...(this.truncated ? { truncated: true } : {}),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user