- Extract atlas/ into 15 focused modules (hook, event handler, tool policies, types, etc.) - Split auto-update-checker into checker/ and hook/ subdirectories with single-purpose files - Decompose session-recovery into separate recovery strategy files per error type - Extract todo-continuation-enforcer from monolith to directory with dedicated modules - Split background-task/tools.ts into individual tool creator files - Extract command-executor, tmux-utils into focused sub-modules - Split config/schema.ts into domain-specific schema files - Decompose cli/config-manager.ts into focused modules - Rollback skill-mcp-manager, model-availability, index.ts splits that broke tests - Fix all import path depths for moved files (../../ -> ../../../) - Add explicit type annotations to resolve TS7006 implicit any errors Typecheck: 0 errors Tests: 2359 pass, 5 fail (all pre-existing)
75 lines
2.4 KiB
TypeScript
75 lines
2.4 KiB
TypeScript
import { log } from "../../shared/logger"
|
|
|
|
import { COUNTDOWN_GRACE_PERIOD_MS, HOOK_NAME } from "./constants"
|
|
import type { SessionStateStore } from "./session-state"
|
|
|
|
export function handleNonIdleEvent(args: {
|
|
eventType: string
|
|
properties: Record<string, unknown> | undefined
|
|
sessionStateStore: SessionStateStore
|
|
}): void {
|
|
const { eventType, properties, sessionStateStore } = args
|
|
|
|
if (eventType === "message.updated") {
|
|
const info = properties?.info as Record<string, unknown> | undefined
|
|
const sessionID = info?.sessionID as string | undefined
|
|
const role = info?.role as string | undefined
|
|
if (!sessionID) return
|
|
|
|
if (role === "user") {
|
|
const state = sessionStateStore.getExistingState(sessionID)
|
|
if (state?.countdownStartedAt) {
|
|
const elapsed = Date.now() - state.countdownStartedAt
|
|
if (elapsed < COUNTDOWN_GRACE_PERIOD_MS) {
|
|
log(`[${HOOK_NAME}] Ignoring user message in grace period`, { sessionID, elapsed })
|
|
return
|
|
}
|
|
}
|
|
if (state) state.abortDetectedAt = undefined
|
|
sessionStateStore.cancelCountdown(sessionID)
|
|
return
|
|
}
|
|
|
|
if (role === "assistant") {
|
|
const state = sessionStateStore.getExistingState(sessionID)
|
|
if (state) state.abortDetectedAt = undefined
|
|
sessionStateStore.cancelCountdown(sessionID)
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
if (eventType === "message.part.updated") {
|
|
const info = properties?.info as Record<string, unknown> | undefined
|
|
const sessionID = info?.sessionID as string | undefined
|
|
const role = info?.role as string | undefined
|
|
|
|
if (sessionID && role === "assistant") {
|
|
const state = sessionStateStore.getExistingState(sessionID)
|
|
if (state) state.abortDetectedAt = undefined
|
|
sessionStateStore.cancelCountdown(sessionID)
|
|
}
|
|
return
|
|
}
|
|
|
|
if (eventType === "tool.execute.before" || eventType === "tool.execute.after") {
|
|
const sessionID = properties?.sessionID as string | undefined
|
|
if (sessionID) {
|
|
const state = sessionStateStore.getExistingState(sessionID)
|
|
if (state) state.abortDetectedAt = undefined
|
|
sessionStateStore.cancelCountdown(sessionID)
|
|
}
|
|
return
|
|
}
|
|
|
|
if (eventType === "session.deleted") {
|
|
const sessionInfo = properties?.info as { id?: string } | undefined
|
|
if (sessionInfo?.id) {
|
|
sessionStateStore.cleanup(sessionInfo.id)
|
|
log(`[${HOOK_NAME}] Session deleted: cleaned up`, { sessionID: sessionInfo.id })
|
|
}
|
|
return
|
|
}
|
|
}
|