fix(hooks): emit PostToolUse additional context

This commit is contained in:
KumamuKuma
2026-07-28 11:08:03 +08:00
parent 20f88686e4
commit 10842f1168
2 changed files with 25 additions and 7 deletions
+13 -3
View File
@@ -41,13 +41,23 @@ function runHook({
}
describe('PostToolUse auto-update hook', () => {
it('emits the auto-update instruction after a git commit', () => {
it('injects the auto-update instruction as PostToolUse additional context', () => {
const result = runHook();
const output = JSON.parse(result.stdout);
expect(result.status).toBe(0);
expect(result.stderr).toBe('');
expect(result.stdout).toContain('[understand-anything] Commit detected');
expect(result.stdout).toContain(`${result.pluginRoot}/hooks/auto-update-prompt.md`);
expect(output).toEqual({
hookSpecificOutput: {
hookEventName: 'PostToolUse',
additionalContext: expect.stringContaining(
'[understand-anything] Commit detected',
),
},
});
expect(output.hookSpecificOutput.additionalContext).toContain(
`${result.pluginRoot}/hooks/auto-update-prompt.md`,
);
});
it('stays silent for unrelated Bash commands', () => {
@@ -38,11 +38,19 @@ async function main() {
if (!existsSync(`${dataDir}/knowledge-graph.json`)) return;
const pluginRoot = process.env.CLAUDE_PLUGIN_ROOT ?? '';
process.stdout.write(
const additionalContext =
`[understand-anything] Commit detected with auto-update enabled. ` +
`You MUST read the file at ${pluginRoot}/hooks/auto-update-prompt.md ` +
'and execute its instructions to incrementally update the knowledge graph. ' +
'Do not ask the user for confirmation — just do it.',
`You MUST read the file at ${pluginRoot}/hooks/auto-update-prompt.md ` +
'and execute its instructions to incrementally update the knowledge graph. ' +
'Do not ask the user for confirmation — just do it.';
process.stdout.write(
JSON.stringify({
hookSpecificOutput: {
hookEventName: 'PostToolUse',
additionalContext,
},
}),
);
}