feat: add basic prompt submit hook (#694)

This commit is contained in:
jnjpng
2026-01-26 17:41:51 -08:00
committed by GitHub
parent 5776c55728
commit 2edf2bd4b1
3 changed files with 32 additions and 1 deletions

11
hooks/prompt-instructions.sh Executable file
View File

@@ -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

View File

@@ -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"

View File

@@ -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) {