/** * Writes HARNESS_CONTEXT_FILE (`.sapiom/harness-context.json`) in a * session's cwd — the coding-agent-legible mirror of this workspace's UI * state: which agent (if any) the session is bound to, every agent the * registry currently knows about, and the session's own identity. Called * strictly from `SessionManager.create()` so the file exists for every * session regardless of entry point (REST, `autoCreateSession`), through * schema-aware preparation from `SessionManager.resume()`, on * every `PATCH /api/sessions/:id/workflow`, and whenever the workflow * registry changes (scan/connect) — see server/index.ts's * `writeSessionContext`/`scanWorkflowsAndBroadcast` for how those call * sites are wired, and both of which can legitimately fire concurrent * writes to the *same* destination (a scan's rewrite-all-open-sessions step * racing a user's live bind click, for instance) — see `withPerPathQueue`. * Unbinding writes `boundAgent: null` rather than deleting the file, so a * concurrent read from the coding agent never races a momentary ENOENT. */ import { type HarnessKind, type WorkflowInfo } from "../shared/types.js"; export interface WorkspaceContextSession { id: string; cwd: string; harness: HarnessKind; } /** * Atomically writes `/.sapiom/harness-context.json`. * Best-effort: a session's cwd could in principle be unwritable * (permissions, deleted out from under the session) — that must never fail * the caller that triggered it, so errors are logged, not thrown. * * `agents` is sorted by path before writing (deterministic, independent * of registry scan/insertion order) so a coding agent re-reading the file * across turns can diff it cheaply instead of re-parsing a reordered blob * every time. */ export declare function writeHarnessContext(session: WorkspaceContextSession, boundWorkflow: WorkflowInfo | null, workflows: WorkflowInfo[], isCurrent?: () => boolean): Promise; /** * The strict form used in SessionManager.create()'s pre-spawn window. A write * failure rejects creation so a coding agent can never receive the new prompt * while an old or missing context contract remains on disk. Registry and bind * refreshes use the best-effort wrapper above because a later refresh failure * must not terminate an already-running session. */ export declare function writeHarnessContextForLaunch(session: WorkspaceContextSession, boundWorkflow: WorkflowInfo | null, workflows: WorkflowInfo[], isCurrent?: () => boolean): Promise; export interface StagedHarnessContext { readonly filePath: string; /** Synchronous by design: a publisher commits every staged context and its * accepted cache/event snapshot without yielding between visible renames. */ commit(): void; discard(): void; } /** * Prepares a context replacement without exposing it at HARNESS_CONTEXT_FILE. * Registry publication stages every active session asynchronously, rechecks * its generation/session projection, then calls commit() for all successful * stages in one non-yielding acceptance turn. */ export declare function stageHarnessContextForPublication(session: WorkspaceContextSession, boundWorkflow: WorkflowInfo | null, workflows: WorkflowInfo[], isCurrent: () => boolean): Promise; export type HarnessContextResumePreparation = "current" | "migrated" | "rewritten"; /** * Makes HARNESS_CONTEXT_FILE safe for a resumed coding agent before its new * Agent Studio prompt can reach the process. A valid current-schema file is * byte-for-byte untouched; a valid legacy file keeps its values and only * renames the two public keys; anything missing, malformed, mixed, or * incomplete is rebuilt from the live session and registry. * * Unlike ordinary registry/bind refreshes, this is strict: an unreadable file * or failed atomic replacement rejects resume so the prompt and on-disk * contract can never disagree during a launch. */ export declare function prepareHarnessContextForResume(session: WorkspaceContextSession, boundWorkflow: WorkflowInfo | null, workflows: WorkflowInfo[]): Promise; //# sourceMappingURL=workspace-context.d.ts.map