mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
feat: implement session tracking via Claude hooks
Adds a dedicated hook server infrastructure to receive Claude SessionStart notifications. This allows the CLI to track session ID changes (new sessions, resume, compact, fork, etc.) without relying on file watchers. Changes: - Add SessionFound callback system to AgentSessionBase for session tracking - Create hook server that listens for POST requests from Claude's hooks - Generate temporary settings files with hook command configuration - Implement session hook forwarder CLI command to relay hook data - Integrate hook server into runClaude with proper cleanup - Pass hookSettingsPath through local and remote execution paths - Update SDK query builder to support --settings flag
This commit is contained in:
@@ -29,6 +29,7 @@ export class AgentSessionBase<Mode> {
|
||||
mode: 'local' | 'remote' = 'local';
|
||||
thinking: boolean = false;
|
||||
|
||||
private sessionFoundCallbacks: ((sessionId: string) => void)[] = [];
|
||||
private readonly applySessionIdToMetadata: (metadata: Metadata, sessionId: string) => Metadata;
|
||||
private readonly sessionLabel: string;
|
||||
private readonly sessionIdLabel: string;
|
||||
@@ -68,6 +69,21 @@ export class AgentSessionBase<Mode> {
|
||||
this.sessionId = sessionId;
|
||||
this.client.updateMetadata((metadata) => this.applySessionIdToMetadata(metadata, sessionId));
|
||||
logger.debug(`[${this.sessionLabel}] ${this.sessionIdLabel} session ID ${sessionId} added to metadata`);
|
||||
|
||||
for (const callback of this.sessionFoundCallbacks) {
|
||||
callback(sessionId);
|
||||
}
|
||||
};
|
||||
|
||||
addSessionFoundCallback = (callback: (sessionId: string) => void): void => {
|
||||
this.sessionFoundCallbacks.push(callback);
|
||||
};
|
||||
|
||||
removeSessionFoundCallback = (callback: (sessionId: string) => void): void => {
|
||||
const index = this.sessionFoundCallbacks.indexOf(callback);
|
||||
if (index !== -1) {
|
||||
this.sessionFoundCallbacks.splice(index, 1);
|
||||
}
|
||||
};
|
||||
|
||||
stopKeepAlive = (): void => {
|
||||
|
||||
Reference in New Issue
Block a user