export type SkillPresenceMode = 'full-auto' | 'assisted' | 'swarm' | 'strict'; export declare const VALID_SKILL_PRESENCE_MODES: ReadonlyArray; export declare function isSkillPresenceMode(value: string): value is SkillPresenceMode; export type SkillPresence = { skill: string; mode?: SkillPresenceMode; gate?: string; sessionId?: string; /** * Identifier of the *outer* session — the Claude Code / Cursor / * VSCode-plugin / other harness session that is currently driving * the LLM. Sourced from the `PEAKS_OUTER_SESSION_ID` environment * variable when set, with `CLAUDE_CODE_SESSION_ID` as a fallback for * Claude Code. Stamped onto the presence file so the status line * can tell whether the recorded skill belongs to the live outer * session (show it) or a previous one (render idle), and so * `setSkillPresence` can detect a session swap and AskUserQuestion * the user about rolling a new peaks session. */ outerSessionId?: string; /** * Set by `setSkillPresence` when the outer session id changed * between the last presence write and this one AND the bound * peaks session has a different (or no) recorded outer session id. * * As of slice 018 (auto-roll on outer-mismatch), the field is * informational only — it tells the statusline and any log / * observability consumer that an outer-session swap was observed * on the previous heartbeat. The actual binding rotation is * performed by `ensureSessionWithRotation` (slice 018), not by * `setSkillPresence`. `peaks-solo`'s Step 0 used to read this * field and turn it into an AskUserQuestion; that ask is no * longer needed because the rotation already happened by the time * the skill is invoked. */ outerSessionMismatch?: { previous?: string; current: string; boundSessionId: string; boundOuterSessionId?: string; }; setAt: string; lastHeartbeat?: string; }; /** * Resolve the active peaks session id from * `.peaks/_runtime/session.json` (legacy: `.peaks/.session.json`). * Returns `null` when no session is bound. * * Public export: callers like `peaks sub-agent dispatch` use this * to auto-resolve `--session-id` when the LLM driver forgets to * pass the flag, so dispatch records land in the right * `.peaks/_sub_agents//` tree instead of an `unknown-sid` * fallback (slice 2026-06-26-unknown-sid-fallback-fix). */ export declare function getCurrentSessionId(projectRootOverride?: string): string | null; export declare function exportSkillPresence(projectRootOverride?: string): string; /** * Write the per-caller active-skill marker to * `.peaks/_runtime//active-skill-.json` (D6). Returns * the written presence with the `callerId` field set. * * The caller is responsible for resolving the `callerId` (via * `resolveCallerId` from `src/services/session/resolve-caller-id.ts`) * and the `peakSessionId` (via `getCallerBinding` then reading * `peakSessionId`, OR via `ensureSession` for the first-time case). */ export declare function setSkillPresenceForCaller(projectRootOverride: string, callerId: string, peakSessionId: string, skill: string, mode?: string, gate?: string): SkillPresence; export declare function setSkillPresence(skill: string, mode?: string, gate?: string, projectRootOverride?: string): SkillPresence; export declare function getSkillPresence(projectRootOverride?: string): SkillPresence | null; /** * Slice 002 (v2.15.0) — presence staleness detection (AC-1). * * Compare the *outer* session id stamped onto the current presence * marker against the *current* outer session id (from * `PEAKS_OUTER_SESSION_ID` / `CLAUDE_CODE_SESSION_ID`). * * Stale reasons (in priority order): * * - `'outer-session-mismatch'` — the presence was stamped by a * different outer (Claude / harness) session than the one that * is now driving peaks. Most common cause: the LLM closed the * previous Claude session, the next session boots and finds a * presence leftover from the old one. peaks-solo Step 1 must * AskUserQuestion to confirm the user wants the old mode. * * - `'no-presence'` — there is no presence file on disk. * Not strictly "stale", but callers (peaks-solo Step 1, `peaks * solo should-pause --step step-1-mode-select`) want to treat * this case as "no opinion yet — must ask". Surfaced as * `stale: true` with reason `'no-presence'` so the ask path is * uniform. * * - `null` — the presence exists AND its outer * session id matches the current outer session id. Not stale. * Caller may safely reuse the recorded mode. * * Pure read-only: never deletes the presence file (the rotation * auto-clear path is a separate concern; see * `clearStalePresenceOnRotation`). Test seam: `--current-outer` lets * tests inject a deterministic current outer id without touching env * vars. */ export type StaleReason = 'outer-session-mismatch' | 'no-presence'; export type StalenessCheck = { stale: boolean; reason: StaleReason | null; /** What was on disk; null when no presence was found. */ presence: SkillPresence | null; /** Current outer session id (env-driven). Undefined when no signal. */ currentOuterSessionId: string | undefined; /** Outer session id recorded on the presence marker. Undefined when no signal. */ recordedOuterSessionId: string | undefined; }; export declare function checkStalePresence(opts?: { projectRootOverride?: string | undefined; /** * Override the *current* outer session id. Test seam only. * - `undefined` (omitted): read from `PEAKS_OUTER_SESSION_ID` / * `CLAUDE_CODE_SESSION_ID` env vars. * - explicit `string`: use the value verbatim (empty string means * "no signal", same as a missing env var). */ currentOuter?: string | undefined; }): StalenessCheck; /** * Slice 002 (v2.15.0) — auto-clear stale presence on session * rotation (AC-1). * * Called from `peaks workspace init` immediately after a successful * `outer-session-mismatch` rotation. When the previous session's * presence is still on disk under the OLD outer session id, * clearing it prevents peaks-solo Step 1 from picking up a stale * `mode` field that the user never explicitly chose. * * Only clears when: * - the recorded outer session id does NOT match the current outer * session id (i.e. the presence IS stale), AND * - the recorded outer session id matches the just-rotated-out * session id (i.e. we're clearing exactly the old binding, not a * user-explicitly-set mode from another live outer session). * * Returns `{ cleared, reason }` so callers can surface the outcome * in the JSON envelope and audit log. Pure: no env-var reads, all * inputs are passed explicitly so the call site (init command) can * decide what the "rotated-out" id was. */ export declare function clearStalePresenceOnRotation(opts: { projectRootOverride?: string; currentOuterSessionId: string | undefined; rotatedOutSessionId: string | null; }): { cleared: boolean; reason: string | null; recordedOuter?: string; }; export declare function touchSkillHeartbeat(projectRootOverride?: string): SkillPresence | null; export declare function clearSkillPresence(projectRootOverride?: string): boolean;