feat: add basic prompt submit hook (#694)
This commit is contained in:
11
hooks/prompt-instructions.sh
Executable file
11
hooks/prompt-instructions.sh
Executable 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
|
||||||
@@ -4522,6 +4522,12 @@ export default function App({
|
|||||||
return { submitted: false };
|
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.
|
// Capture the generation at submission time, BEFORE any async work.
|
||||||
// This allows detecting if ESC was pressed during async operations.
|
// This allows detecting if ESC was pressed during async operations.
|
||||||
const submissionGeneration = conversationGenerationRef.current;
|
const submissionGeneration = conversationGenerationRef.current;
|
||||||
@@ -6433,7 +6439,7 @@ ${SYSTEM_REMINDER_CLOSE}
|
|||||||
lastNotifiedModeRef.current = currentMode;
|
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 =
|
const allReminders =
|
||||||
sessionContextReminder +
|
sessionContextReminder +
|
||||||
permissionModeAlert +
|
permissionModeAlert +
|
||||||
@@ -6441,6 +6447,7 @@ ${SYSTEM_REMINDER_CLOSE}
|
|||||||
ralphModeReminder +
|
ralphModeReminder +
|
||||||
skillUnloadReminder +
|
skillUnloadReminder +
|
||||||
bashCommandPrefix +
|
bashCommandPrefix +
|
||||||
|
userPromptSubmitHookFeedback +
|
||||||
memoryReminderContent;
|
memoryReminderContent;
|
||||||
const messageContent =
|
const messageContent =
|
||||||
allReminders && typeof contentParts === "string"
|
allReminders && typeof contentParts === "string"
|
||||||
|
|||||||
@@ -275,6 +275,19 @@ export async function executeHooks(
|
|||||||
const result = await executeHookCommand(hook, input, workingDirectory);
|
const result = await executeHookCommand(hook, input, workingDirectory);
|
||||||
results.push(result);
|
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
|
// Collect feedback from stderr when hook blocks
|
||||||
// Format: [command]: {stderr} per spec
|
// Format: [command]: {stderr} per spec
|
||||||
if (result.exitCode === HookExitCode.BLOCK) {
|
if (result.exitCode === HookExitCode.BLOCK) {
|
||||||
|
|||||||
Reference in New Issue
Block a user