refactor: update hooks to handle missing input and provide usage instructions
This commit is contained in:
+13
-1
@@ -13,8 +13,20 @@ export interface UserPromptSubmitInput {
|
|||||||
* New Hook - UserPromptSubmit
|
* New Hook - UserPromptSubmit
|
||||||
* Initializes SDK memory session in background
|
* Initializes SDK memory session in background
|
||||||
*/
|
*/
|
||||||
export function newHook(input: UserPromptSubmitInput): void {
|
export function newHook(input?: UserPromptSubmitInput): void {
|
||||||
try {
|
try {
|
||||||
|
// Handle standalone execution (no input provided)
|
||||||
|
if (!input) {
|
||||||
|
console.log('No input provided - this script is designed to run as a Claude Code UserPromptSubmit hook');
|
||||||
|
console.log('\nExpected input format:');
|
||||||
|
console.log(JSON.stringify({
|
||||||
|
session_id: "string",
|
||||||
|
cwd: "string",
|
||||||
|
prompt: "string"
|
||||||
|
}, null, 2));
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
const { session_id, cwd, prompt } = input;
|
const { session_id, cwd, prompt } = input;
|
||||||
|
|
||||||
// Extract project from cwd
|
// Extract project from cwd
|
||||||
|
|||||||
+15
-1
@@ -21,8 +21,22 @@ const SKIP_TOOLS = new Set([
|
|||||||
* Save Hook - PostToolUse
|
* Save Hook - PostToolUse
|
||||||
* Sends tool observations to worker via Unix socket
|
* Sends tool observations to worker via Unix socket
|
||||||
*/
|
*/
|
||||||
export function saveHook(input: PostToolUseInput): void {
|
export function saveHook(input?: PostToolUseInput): void {
|
||||||
try {
|
try {
|
||||||
|
// Handle standalone execution (no input provided)
|
||||||
|
if (!input) {
|
||||||
|
console.log('No input provided - this script is designed to run as a Claude Code PostToolUse hook');
|
||||||
|
console.log('\nExpected input format:');
|
||||||
|
console.log(JSON.stringify({
|
||||||
|
session_id: "string",
|
||||||
|
cwd: "string",
|
||||||
|
tool_name: "string",
|
||||||
|
tool_input: {},
|
||||||
|
tool_output: {}
|
||||||
|
}, null, 2));
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
const { session_id, tool_name, tool_input, tool_output } = input;
|
const { session_id, tool_name, tool_input, tool_output } = input;
|
||||||
|
|
||||||
// Skip certain tools
|
// Skip certain tools
|
||||||
|
|||||||
+12
-1
@@ -12,8 +12,19 @@ export interface StopInput {
|
|||||||
* Summary Hook - Stop
|
* Summary Hook - Stop
|
||||||
* Sends FINALIZE message to worker via Unix socket
|
* Sends FINALIZE message to worker via Unix socket
|
||||||
*/
|
*/
|
||||||
export function summaryHook(input: StopInput): void {
|
export function summaryHook(input?: StopInput): void {
|
||||||
try {
|
try {
|
||||||
|
// Handle standalone execution (no input provided)
|
||||||
|
if (!input) {
|
||||||
|
console.log('No input provided - this script is designed to run as a Claude Code Stop hook');
|
||||||
|
console.log('\nExpected input format:');
|
||||||
|
console.log(JSON.stringify({
|
||||||
|
session_id: "string",
|
||||||
|
cwd: "string"
|
||||||
|
}, null, 2));
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
const { session_id } = input;
|
const { session_id } = input;
|
||||||
|
|
||||||
// Find active SDK session
|
// Find active SDK session
|
||||||
|
|||||||
Reference in New Issue
Block a user