Add standalone hook entry points for context, new, save, summary, and worker
- Implemented context-hook.ts for handling session start events. - Created new-hook.ts for user prompt submission events. - Developed save-hook.ts for post tool use events. - Added summary-hook.ts for handling stop events. - Introduced worker.ts as a standalone background process for the SDK agent. - Each hook reads input from stdin, processes it, and handles errors gracefully.
This commit is contained in:
+19
-5
@@ -48,11 +48,25 @@ export function newHook(input?: UserPromptSubmitInput): void {
|
||||
db.close();
|
||||
|
||||
// Start SDK worker in background as detached process
|
||||
// Use 'claude-mem worker' CLI command which is always available
|
||||
const child = spawn('claude-mem', ['worker', sessionId.toString()], {
|
||||
detached: true,
|
||||
stdio: 'ignore'
|
||||
});
|
||||
// In plugin mode, use bundled worker; otherwise use global CLI
|
||||
const pluginRoot = process.env.CLAUDE_PLUGIN_ROOT;
|
||||
let child;
|
||||
|
||||
if (pluginRoot) {
|
||||
// Plugin mode: use bundled worker
|
||||
const workerPath = path.join(pluginRoot, 'scripts', 'hooks', 'worker.js');
|
||||
child = spawn('bun', [workerPath, sessionId.toString()], {
|
||||
detached: true,
|
||||
stdio: 'ignore'
|
||||
});
|
||||
} else {
|
||||
// Traditional mode: use global CLI
|
||||
child = spawn('claude-mem', ['worker', sessionId.toString()], {
|
||||
detached: true,
|
||||
stdio: 'ignore'
|
||||
});
|
||||
}
|
||||
|
||||
child.unref();
|
||||
|
||||
// Output hook response
|
||||
|
||||
Reference in New Issue
Block a user