From 2edf2bd4b16dbbba2996fbc9eb02471120584347 Mon Sep 17 00:00:00 2001 From: jnjpng Date: Mon, 26 Jan 2026 17:41:51 -0800 Subject: [PATCH] feat: add basic prompt submit hook (#694) --- hooks/prompt-instructions.sh | 11 +++++++++++ src/cli/App.tsx | 9 ++++++++- src/hooks/executor.ts | 13 +++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100755 hooks/prompt-instructions.sh diff --git a/hooks/prompt-instructions.sh b/hooks/prompt-instructions.sh new file mode 100755 index 0000000..3b6ce28 --- /dev/null +++ b/hooks/prompt-instructions.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# UserPromptSubmit hook - adds instructions to every prompt +# Reads JSON from stdin, outputs instructions to stdout, exits 0 + +# Consume stdin (required for hook protocol) +cat > /dev/null + +# Output instructions that will be injected into agent context +echo "Be specific. Double check your work. Ask clarifying questions." + +exit 0 diff --git a/src/cli/App.tsx b/src/cli/App.tsx index 2fc304c..3bac7a1 100644 --- a/src/cli/App.tsx +++ b/src/cli/App.tsx @@ -4522,6 +4522,12 @@ export default function App({ return { submitted: false }; } + // Capture successful hook feedback to inject into agent context + const userPromptSubmitHookFeedback = + hookResult.feedback.length > 0 + ? `${SYSTEM_REMINDER_OPEN}\n${hookResult.feedback.join("\n")}\n${SYSTEM_REMINDER_CLOSE}` + : ""; + // Capture the generation at submission time, BEFORE any async work. // This allows detecting if ESC was pressed during async operations. const submissionGeneration = conversationGenerationRef.current; @@ -6433,7 +6439,7 @@ ${SYSTEM_REMINDER_CLOSE} lastNotifiedModeRef.current = currentMode; } - // Combine reminders with content (session context first, then permission mode, then plan mode, then ralph mode, then skill unload, then bash commands, then memory reminder) + // Combine reminders with content (session context first, then permission mode, then plan mode, then ralph mode, then skill unload, then bash commands, then hook feedback, then memory reminder) const allReminders = sessionContextReminder + permissionModeAlert + @@ -6441,6 +6447,7 @@ ${SYSTEM_REMINDER_CLOSE} ralphModeReminder + skillUnloadReminder + bashCommandPrefix + + userPromptSubmitHookFeedback + memoryReminderContent; const messageContent = allReminders && typeof contentParts === "string" diff --git a/src/hooks/executor.ts b/src/hooks/executor.ts index 9dadbe7..0334e7c 100644 --- a/src/hooks/executor.ts +++ b/src/hooks/executor.ts @@ -275,6 +275,19 @@ export async function executeHooks( const result = await executeHookCommand(hook, input, workingDirectory); results.push(result); + // Collect feedback from stdout when hook succeeds (exit 0) + // Only for UserPromptSubmit and SessionStart hooks + if (result.exitCode === HookExitCode.ALLOW) { + if ( + result.stdout?.trim() && + (input.event_type === "UserPromptSubmit" || + input.event_type === "SessionStart") + ) { + feedback.push(result.stdout.trim()); + } + continue; + } + // Collect feedback from stderr when hook blocks // Format: [command]: {stderr} per spec if (result.exitCode === HookExitCode.BLOCK) {