Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/claude-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ function handleClaudeHookLocked(input, { projectDir, packageRoot }) {
appendTrace(traces, decision.trace);
if (decision.block) return { decision: 'block', reason: decision.message };
if (decision.trace?.receipt?.anti_lockup_downgrade) return { systemMessage: decision.message };
if (engine.mode === 'advisory' && decision.message) return { systemMessage: decision.message };
return {};
}

Expand Down
32 changes: 32 additions & 0 deletions test/claude-code.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,38 @@ test('advisory PostToolUse feedback never blocks the Claude loop', () => {
assert.match(feedback.hookSpecificOutput.additionalContext, /Receipt failed/);
});

test('advisory Stop surfaces an unmet obligation without blocking', () => {
const target = project();
installClaudeCode({ projectDir: target, packageRoot: root, mode: 'advisory' });
handleClaudeHook(event(target, 'UserPromptSubmit', { prompt: 'Who calls performSync?' }), { projectDir: target, packageRoot: root });

const stopped = handleClaudeHook(event(target, 'Stop', {
stop_hook_active: false, last_assistant_message: 'Done.',
}), { projectDir: target, packageRoot: root });

assert.equal(stopped.decision, undefined);
assert.equal(stopped.hookSpecificOutput, undefined);
assert.match(stopped.systemMessage, /Unmet obligation/);
});

test('advisory Stop stays quiet when every obligation is satisfied', () => {
const target = project();
installClaudeCode({ projectDir: target, packageRoot: root, mode: 'advisory' });
handleClaudeHook(event(target, 'UserPromptSubmit', { prompt: 'Who calls performSync?' }), { projectDir: target, packageRoot: root });
const graphInput = event(target, 'PreToolUse', {
tool_name: 'mcp__gbrain__code_callers', tool_input: { symbol: 'performSync' }, tool_use_id: 'tool-right',
});
handleClaudeHook(graphInput, { projectDir: target, packageRoot: root });
handleClaudeHook(event(target, 'PostToolUse', {
tool_name: 'mcp__gbrain__code_callers', tool_input: { symbol: 'performSync' },
tool_response: { callers: ['runSync calls performSync'] }, tool_use_id: 'tool-right',
}), { projectDir: target, packageRoot: root });

assert.deepEqual(handleClaudeHook(event(target, 'Stop', {
stop_hook_active: false, last_assistant_message: 'Verified callers.',
}), { projectDir: target, packageRoot: root }), {});
});

test('UserPromptSubmit injects a compact route block and stays silent without obligations', () => {
const target = project();
installClaudeCode({ projectDir: target, packageRoot: root, mode: 'enforce' });
Expand Down
Loading