-
Notifications
You must be signed in to change notification settings - Fork 181
Feat/session hook tracking #99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Add dedicated HTTP server (startHookServer.ts) for receiving Claude session hooks - Generate temporary settings file with SessionStart hook configuration - Pass --settings flag to Claude CLI for hook integration - Update Session class with callback mechanism for session ID changes - Connect scanner to session callbacks for real-time session file tracking
src/claude/claudeLocal.ts
Outdated
| } | ||
|
|
||
| // Add hook settings for session tracking | ||
| if (opts.hookSettingsPath) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we just pass this always? update opts to must include this - less branching == better
| logger.debug(`[START] Session hook received: ${sessionId}`, data); | ||
|
|
||
| // Update session ID in the Session instance | ||
| if (currentSession) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm how is this going to work? What if we don't have a session?
Also dynamic import - lets not do that for the type above :D
|
|
||
| /** | ||
| * Consume one-time Claude flags from claudeArgs after Claude spawn | ||
| * Currently handles: --resume (with or without session ID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
elaborate on what the responsibility of this code is
- hookSettingsPath now required (less branching) - Static import instead of dynamic for Session type - JSDoc for onSessionFound callback - Remove fake session ID generation - Add control flow docs in startHookServer.ts
Summary: Integrates PR slopus#99 (hook-based session tracking) and PR slopus#98 (Gemini/ACP integration) while preserving all offline mode and robustness features from the feature branch, plus DRY improvements. What changed: - Session hook server system for reliable Claude session ID capture - Gemini backend as alternative to Claude/Codex with ACP integration - Fixed memory leak in session.ts (stored interval reference + cleanup()) - Added socket connection check in apiSession.ts - Created shared offlineSessionStub.ts utility (DRY refactor) - Added gemini to profile compatibility validation - Preserved: offline mode, 5xx handling, profile system, tmux integration Files affected: - src/claude/runClaude.ts: Hook server + offline fallback integration - src/claude/session.ts: RAII cleanup, callback system, hookSettingsPath - src/claude/loop.ts: hookSettingsPath threading - src/claude/claudeLocal.ts: Hook parameters - src/claude/claudeRemote.ts: mapToClaudeMode() preserved - src/api/api.ts: Graceful 5xx handling preserved - src/api/apiSession.ts: Socket check restored - src/daemon/run.ts: Gemini added to agent selection - src/persistence.ts: Added gemini to ProfileCompatibilitySchema - src/utils/offlineSessionStub.ts: New shared DRY utility - src/codex/runCodex.ts: Updated to use shared offline stub - src/gemini/runGemini.ts: Added offline mode with shared stub - src/agent/*, src/gemini/*: New from main (no conflicts) - scripts/session_hook_forwarder.cjs: Hook forwarder from main Testable: npm test (266 pass, 8 fail - baseline unchanged)
Session Hook Tracking
Reliable Claude session ID tracking via native hooks.
How It Works
SessionStarthook pointing to the server--settings <path>flag and fires hook on session startFiles
src/claude/utils/startHookServer.tssrc/claude/utils/generateHookSettings.tsscripts/session_hook_forwarder.cjsWhy
Claude changes session ID on
--resume,--continue, and/compact. Previously Happy lost track of the active session. Now Claude notifies Happy directly via hooks.