import type { CortexStore, SessionRow } from '../db/store.js'; import { type GitScopeIdentity } from './git.js'; export interface ScopeSessionOptions { resolveScope?: (cwd: string) => GitScopeIdentity; /** Host-provided subagent id. Present → resolve a child session (AD-9). */ agentId?: string; /** Host-provided subagent type, recorded on the child session. */ agentType?: string; } export declare function syncBranchSnapshotForSession(store: CortexStore, sessionId: string): void; /** * Resolve the session a spooled entry belongs to, given the primary session the * batch is being flushed into. Deliberately keyed off the *recorded* primary * rather than whatever is active now: a batch can be replayed long after its * turn, and the work belongs to the session that produced it. * * Returns `primarySessionId` unchanged when the primary row is gone, so a * flush degrades to today's attribution instead of failing (AD-12). */ export declare function resolveAgentSessionId(store: CortexStore, primarySessionId: string, agentId: string, agentType?: string): string; /** * First time this scope saw a `SubagentStart` fire. Written once and never * moved, so `doctor` can tell "this path has never run" from "no subagent has * run since" — two states a latest-timestamp would conflate. */ export declare const SUBAGENT_START_KEY = "subagent_start_first_seen"; /** * How many times the `SubagentStart` path has fired since * {@link SUBAGENT_START_KEY} was set. `doctor` compares it against the child * sessions created in the same window: fewer fires than children means * subagents ran that the hook never saw — the "wired, running, dead" state a * lone timestamp cannot distinguish from a quiet week. * * Both keys live here rather than in `transports/` because `query/doctor.ts` * reads them and AD-1 forbids a query importing a transport. */ export declare const SUBAGENT_START_COUNT_KEY = "subagent_start_count"; /** * Record that the `SubagentStart` path ran. Advisory: the session is the * deliverable, so a failed marker write must never cost the attribution that * already succeeded (AD-12). */ export declare function recordSubagentStart(store: CortexStore): void; /** * First time this scope captured a dispatch at `PreToolUse` on the `Agent` tool * (FR-18, Story 5.2). Same write-once discipline as {@link SUBAGENT_START_KEY}, * and for the same reason: `doctor` must be able to tell "the capture path has * never run here" from "nothing has been dispatched lately", and a store that * accumulated subagent history BEFORE this feature shipped must not be warned * about on day one. That day-one flap is the failure `command-outcomes` had to * be repaired for and Story 5.1 was built to avoid. */ export declare const SUBAGENT_DISPATCH_KEY = "subagent_dispatch_first_seen"; /** Dispatches captured since {@link SUBAGENT_DISPATCH_KEY} was set. */ export declare const SUBAGENT_DISPATCH_COUNT_KEY = "subagent_dispatch_count"; /** * Captures successfully paired with a `SubagentStart`. Captured-but-never-paired * is the wired-but-dead state that nothing else can see: the dispatch hook fires, * the start hook fires, `doctor` reports both healthy, and no subagent is ever * briefed. */ export declare const SUBAGENT_PAIRED_COUNT_KEY = "subagent_paired_count"; /** * Starts REFUSED because more than one capture matched the key. * * The story shipped FIFO-on-ambiguity and justified it with "refusing would * silence exactly the fan-out case, which is where briefing is worth most". * **Review proved that premise false.** Under the MEASURED host ordering — * `PreToolUse(a) → SubagentStart(a) → PreToolUse(b) → SubagentStart(b)`, strictly * interleaved — a genuine same-message fan-out never has more than one capture * pending, so it was booking ZERO. What FIFO actually resolved was the broken * cases: an `Agent` call the user denied leaves an orphan capture, the assistant * re-dispatches in the SAME turn, and FIFO hands the real subagent the orphan. * Reproduced: a subagent sent to audit the read ledger was told its most relevant * memory was `Decision [kafka pipeline]` — SM-C3, from an ordinary user action. * * Ruling (ShuromiU, 2026-08-07): SAY NOTHING WHEN UNSURE. So this counts refusals, * and it is REPORTED, never warned on — the refusal is the safe outcome, and * silence is this feature's documented default. A climbing count means murky * dispatch shapes are common here, which is a design signal, not a fault. */ export declare const SUBAGENT_AMBIGUOUS_COUNT_KEY = "subagent_ambiguous_count"; /** Pairings that actually emitted a brief. Silence is the default (N-1). */ export declare const SUBAGENT_BRIEFED_COUNT_KEY = "subagent_briefed_count"; /** * Pairings this build was ABLE to check against the host's own record * (FR-19, Story 5.3). * * Exists so the mispairing count below can never be read alone. The sidecar is * host-internal, undocumented and reached by a derived path: it can be absent * for reasons that say nothing about Cortex, and an absent audit is not a failed * audit. Reporting `mispaired: 0` without saying how many were checked reads as * "verified correct" when the honest statement is "never verified" — the * silent-coverage lie AD-12 is about, arriving through a counter instead of a * missing hook. */ export declare const SUBAGENT_AUDITED_COUNT_KEY = "subagent_audited_count"; /** * Audited pairings where the sidecar's `toolUseId` did NOT match the capture * Story 5.2 handed that subagent. * * **The one counter in this epic that genuinely should warn, and the reason is * worth stating next to the one that must not.** `SUBAGENT_AMBIGUOUS_COUNT_KEY` * counts refusals — the design working exactly as ruled, where silence is the * correct outcome — so warning on it would be the cries-wolf half of AD-12. A * mispairing is the opposite: it means a subagent was briefed from somebody * else's dispatch and told something untrue about its own task (SM-C3), which is * the worst failure this product can produce, and it is invisible without this * number. Nothing else can see it: the brief was emitted, the counters all * incremented, and every `doctor` row reads green. */ export declare const SUBAGENT_MISPAIRED_COUNT_KEY = "subagent_mispaired_count"; /** * Record that a dispatch was captured. Advisory, like * {@link recordSubagentStart}: the capture row is the deliverable and a failed * counter must never cost it (AD-12). */ export declare function recordSubagentDispatch(store: CortexStore): void; /** * Record that a capture was claimed. * * Called IMMEDIATELY after the claim, before the brief is built. Booking it * afterwards meant a brief that threw left the capture consumed and `paired` * un-incremented — reproduced in review with retrieval stubbed to throw: four * consumed rows, `paired` unset, and `doctor` then warning "no dispatch has ever * paired" with a named fix wrong for that cause. */ export declare function recordSubagentPairing(store: CortexStore): void; /** Record that a start was refused because more than one capture matched. */ export declare function recordSubagentAmbiguity(store: CortexStore): void; /** * Times the memory guard actually refused a subagent (FR-19 AC #3). * * **Cortex's first blocking hook shipped with no observability at all**, which * review caught: every other surface in this epic got a counter and a * conditional `doctor` row, and the one that can BLOCK THE USER'S WORK got * neither. `doctor`'s `guard-matcher` row checks that the wiring exists, never * that it acts — and that is precisely the distinction AD-12 draws. Without * this number, over-blocking (the worst outcome this guard can produce) and a * route going dark (the second worst) are both invisible from every surface. * * REPORTED, never warned on. A denial is the design working: it means a * subagent tried to retire earlier work and was stopped. What a reader needs is * the rate, so an unexpected climb is visible — the same rule the refusal count * carries, for the same reason. */ export declare const MEMORY_GUARD_DENIED_COUNT_KEY = "memory_guard_denied_count"; /** First denial, so a store predating the guard is not read as "never fires". */ export declare const MEMORY_GUARD_KEY = "memory_guard_first_seen"; /** Record that the memory guard refused a call. Advisory; never costs the denial. */ export declare function recordMemoryGuardDenial(store: CortexStore): void; /** * Record the outcome of one pairing audit (FR-19, Story 5.3). * * Both counters move together, so `mispaired / audited` is always a ratio over * the same population. Call it only when the sidecar was actually read — an * unreadable sidecar records NOTHING, because conflating "could not check" with * "checked and fine" is how a diagnostic starts lying. */ export declare function recordSubagentAudit(store: CortexStore, matched: boolean): void; /** Record that a claimed capture actually produced a brief. */ export declare function recordSubagentBriefed(store: CortexStore): void; export declare function ensureScopedSession(store: CortexStore, cwd: string, options?: ScopeSessionOptions): SessionRow; //# sourceMappingURL=runtime.d.ts.map