/** * session-state.ts * * Per-Claude-session active-project marker files. * Located in ~/.hmem/sessions/.json and keyed by the session_id * that Claude Code passes in every hook's stdin JSON. */ export interface SessionMarker { sessionId: string; projectId: string | null; hmemPath: string; updatedAt: string; pid: number; /** Written by 'hmem deactivate' after /clear — distinguishes explicit deactivation from default null */ deactivated?: boolean; /** L2 O-sub-node ID for this session (e.g. "O0048.114"). Set by Stop-Hook after first exchange. */ oSessionId?: string | null; } export interface SessionMarkerInput { projectId?: string | null; hmemPath?: string; deactivated?: boolean; oSessionId?: string | null; } export declare function sessionMarkerDir(): string; export declare function writeSessionMarker(sessionId: string, input: SessionMarkerInput): void; export declare function readSessionMarker(sessionId: string): SessionMarker | null; export declare function clearSessionMarker(sessionId: string): void; export declare function purgeStaleSessionMarkers(maxAgeDays: number): number; export interface PpidMapping { sessionId: string; hmemPath: string; updatedAt: string; } /** * Write a mapping from a parent process id to a session id + hmem path. * Used as a bridge between hooks (which know the session id) and MCP servers * (which don't, but share the same parent pid = Claude Code's pid). */ export declare function writePpidMapping(ppid: number, sessionId: string, hmemPath: string): void; export declare function readPpidMapping(ppid: number): PpidMapping | null; /** * Resolve the current session id by chaining: env var > ppid-bridge file. * Caches the result in process.env.HMEM_SESSION_ID so repeated calls are cheap. * * Linux/macOS: process.ppid is the Claude Code PID shared between the hook and * MCP server, so the ppid-bridge file written by the hook is readable here. * Windows: process.ppid may be unavailable in older Node versions — in that case * currentSessionId() returns undefined and the system falls through to legacy * DB-flag behavior. */ export declare function currentSessionId(): string | undefined; export declare function activeProjectFilePath(claudePid: number): string; export declare function writeActiveProjectFile(claudePid: number, projectId: string): void; export declare function readActiveProjectFile(claudePid: number): string | null; /** * Read the PPID of any process from /proc (Linux only). * Returns null on non-Linux or if the file cannot be read. */ export declare function getParentPid(pid: number): number | null; /** * Find the active project for the current process, walking up the process * tree to handle the bash-intermediary case: * Claude Code → bash → this process * File key = Claude Code PID = grandparent PID of this process */ export declare function readActiveProjectForCurrentProcess(): string | null; export declare function getActiveDevice(): string | null; export declare function setActiveDevice(id: string): void;