Skip to content

Commit a655048

Browse files
committed
Use approved denial text and deduplicated stderr summaries
1 parent d9e2d1e commit a655048

4 files changed

Lines changed: 22 additions & 5 deletions

File tree

‎src/core/agent/InstructionRunner.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { summarizeUnattendedApprovals } from '../../permissions/unattended.js';
1+
import { describeUnattendedApproval, summarizeUnattendedApprovals } from '../../permissions/unattended.js';
22
/**
33
* @license
44
* Copyright 2025 Autohand AI LLC
@@ -473,7 +473,9 @@ export class InstructionRunner {
473473
const recordIncompleteLoop = (result: Extract<ReactLoopResult, { status: 'incomplete' }>): false => {
474474
success = false;
475475
if (result.reason === 'approval_required') {
476-
console.error(summarizeUnattendedApprovals(host.toolManager?.getUnattendedDenials?.() ?? []));
476+
const denied = host.toolManager?.getUnattendedDenials?.() ?? [];
477+
for (const tool of new Set(denied)) console.error(describeUnattendedApproval(tool));
478+
console.error(summarizeUnattendedApprovals(denied));
477479
}
478480
recordReflectionFailure('incomplete', INCOMPLETE_LOOP_REASONS[result.reason]);
479481
host.stopUI(true);

‎src/permissions/unattended.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
export const UNATTENDED_APPROVAL_EXIT_CODE = 77;
22

33
export function describeUnattendedApproval(tool: string): string {
4-
return `${tool} needs approval and this run can't ask: rerun with --yes or --allowed-tools ${tool}.`;
4+
return `${tool} needs approval, and this run can't ask for it. Rerun with --yes, or with --allowed-tools ${tool}.`;
55
}
66

77
export function summarizeUnattendedApprovals(tools: readonly string[]): string {
8-
return `Run stopped: ${[...new Set(tools)].map(describeUnattendedApproval).join('\n')}`;
8+
const denied = [...new Set(tools)];
9+
return `Denied (this run can't ask for approval): ${denied.join(', ')}. Rerun with --yes, or with --allowed-tools ${denied.join(',')}.`;
910
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { describe, expect, it } from 'vitest';
2+
import { describeUnattendedApproval, summarizeUnattendedApprovals } from '../../src/permissions/unattended.js';
3+
4+
describe('approved unattended approval diagnostics', () => {
5+
it('uses the real tool name in the two-sentence denial', () => {
6+
expect(describeUnattendedApproval('write_file')).toBe("write_file needs approval, and this run can't ask for it. Rerun with --yes, or with --allowed-tools write_file.");
7+
});
8+
it('lists every denied tool once in one stderr summary line', () => {
9+
const summary = summarizeUnattendedApprovals(['write_file', 'run_command', 'write_file']);
10+
expect(summary).toBe("Denied (this run can't ask for approval): write_file, run_command. Rerun with --yes, or with --allowed-tools write_file,run_command.");
11+
expect(summary.split('\n')).toHaveLength(1);
12+
});
13+
});

‎tests/tuistory/unattended-approval.tuistory.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ describe('unattended approval boundary', () => {
1818
expect(result.exitCode, result.stdout + result.stderr).toBe(77);
1919
expect(result.elapsedMs).toBeLessThan(20_000);
2020
expect(result.stderr).toContain('--allowed-tools write_file');
21-
expect(result.stderr).toContain('--yes');
21+
expect(result.stderr).toContain("write_file needs approval, and this run can't ask for it. Rerun with --yes, or with --allowed-tools write_file.");
22+
expect(result.stderr.split('\n').filter(line => line.startsWith('Denied ('))).toEqual(["Denied (this run can't ask for approval): write_file. Rerun with --yes, or with --allowed-tools write_file."]);
2223
} else {
2324
const session = await launchBuiltAutohand(args, { autohandHome: state.autohandHome, cwd: state.workspaceRoot });
2425
try {

0 commit comments

Comments
 (0)