UNPKG

@phren/cli

Version:

Knowledge layer for AI agents - CLI, MCP server, and data layer

259 lines (258 loc) • 10.2 kB
import { z } from "zod"; import { type Json } from "./protocol.js"; /** * Which pane is this computer's conductor, as the Hook keeps it * (docs/conductor-sets.md). The role follows the pane: server, pane id and * terminal id. When the agent in that pane restarts or logs in again, the * role stays and the new session is recorded. The Herdr agent name or tmux * `@phren_agent` is only a label, read once to migrate a conductor that * predates this file. */ declare const recordSchema: z.ZodObject<{ server: z.ZodString; pane: z.ZodString; terminal: z.ZodOptional<z.ZodString>; workspace: z.ZodOptional<z.ZodString>; tab: z.ZodOptional<z.ZodString>; source: z.ZodOptional<z.ZodEnum<{ claude: "claude"; codex: "codex"; copilot: "copilot"; opencode: "opencode"; phren: "phren"; }>>; session: z.ZodOptional<z.ZodString>; since: z.ZodString; by: z.ZodEnum<{ launch: "launch"; migrated: "migrated"; owner: "owner"; }>; }, z.core.$strip>; export type ConductorRecord = z.infer<typeof recordSchema>; /** A cleared name keeps its time (`name: null`), so an older name arriving later does not return. */ declare const setNameSchema: z.ZodObject<{ name: z.ZodNullable<z.ZodString>; namedAt: z.ZodString; }, z.core.$strip>; export type SetName = z.infer<typeof setNameSchema>; /** `conductor` absent is legacy mode: nothing has decided the role yet, so a * conductor is still recognized by its mux name. `null` is no conductor. */ export declare const successionSchema: z.ZodObject<{ id: z.ZodString; generation: z.ZodString; side: z.ZodEnum<{ origin: "origin"; successor: "successor"; }>; phase: z.ZodEnum<{ aborted: "aborted"; committed: "committed"; prepared: "prepared"; preparing: "preparing"; }>; originId: z.ZodString; destinationId: z.ZodString; previous: z.ZodObject<{ server: z.ZodString; pane: z.ZodString; terminal: z.ZodOptional<z.ZodString>; workspace: z.ZodOptional<z.ZodString>; tab: z.ZodOptional<z.ZodString>; source: z.ZodOptional<z.ZodEnum<{ claude: "claude"; codex: "codex"; copilot: "copilot"; opencode: "opencode"; phren: "phren"; }>>; session: z.ZodOptional<z.ZodString>; since: z.ZodString; by: z.ZodEnum<{ launch: "launch"; migrated: "migrated"; owner: "owner"; }>; }, z.core.$strip>; from: z.ZodObject<{ server: z.ZodString; workspace: z.ZodString; tab: z.ZodString; pane: z.ZodString; source: z.ZodEnum<{ claude: "claude"; codex: "codex"; copilot: "copilot"; opencode: "opencode"; phren: "phren"; }>; session: z.ZodUnion<readonly [z.ZodString, z.ZodString]>; }, z.core.$strip>; connection: z.ZodObject<{ name: z.ZodString; server: z.ZodString; fingerprint: z.ZodString; id: z.ZodString; }, z.core.$strict>; workers: z.ZodOptional<z.ZodArray<z.ZodObject<{ id: z.ZodString; fingerprint: z.ZodOptional<z.ZodString>; }, z.core.$strict>>>; revoked: z.ZodOptional<z.ZodBoolean>; activated: z.ZodOptional<z.ZodBoolean>; target: z.ZodOptional<z.ZodObject<{ server: z.ZodString; workspace: z.ZodString; tab: z.ZodString; pane: z.ZodString; source: z.ZodEnum<{ claude: "claude"; codex: "codex"; copilot: "copilot"; opencode: "opencode"; phren: "phren"; }>; session: z.ZodUnion<readonly [z.ZodString, z.ZodString]>; }, z.core.$strip>>; resume: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>; }, z.core.$strict>; export type ConductorSuccession = z.infer<typeof successionSchema>; declare const stateSchema: z.ZodObject<{ version: z.ZodLiteral<1>; conductor: z.ZodOptional<z.ZodNullable<z.ZodObject<{ server: z.ZodString; pane: z.ZodString; terminal: z.ZodOptional<z.ZodString>; workspace: z.ZodOptional<z.ZodString>; tab: z.ZodOptional<z.ZodString>; source: z.ZodOptional<z.ZodEnum<{ claude: "claude"; codex: "codex"; copilot: "copilot"; opencode: "opencode"; phren: "phren"; }>>; session: z.ZodOptional<z.ZodString>; since: z.ZodString; by: z.ZodEnum<{ launch: "launch"; migrated: "migrated"; owner: "owner"; }>; }, z.core.$strip>>>; set: z.ZodOptional<z.ZodObject<{ name: z.ZodNullable<z.ZodString>; namedAt: z.ZodString; }, z.core.$strip>>; succession: z.ZodOptional<z.ZodObject<{ id: z.ZodString; generation: z.ZodString; side: z.ZodEnum<{ origin: "origin"; successor: "successor"; }>; phase: z.ZodEnum<{ aborted: "aborted"; committed: "committed"; prepared: "prepared"; preparing: "preparing"; }>; originId: z.ZodString; destinationId: z.ZodString; previous: z.ZodObject<{ server: z.ZodString; pane: z.ZodString; terminal: z.ZodOptional<z.ZodString>; workspace: z.ZodOptional<z.ZodString>; tab: z.ZodOptional<z.ZodString>; source: z.ZodOptional<z.ZodEnum<{ claude: "claude"; codex: "codex"; copilot: "copilot"; opencode: "opencode"; phren: "phren"; }>>; session: z.ZodOptional<z.ZodString>; since: z.ZodString; by: z.ZodEnum<{ launch: "launch"; migrated: "migrated"; owner: "owner"; }>; }, z.core.$strip>; from: z.ZodObject<{ server: z.ZodString; workspace: z.ZodString; tab: z.ZodString; pane: z.ZodString; source: z.ZodEnum<{ claude: "claude"; codex: "codex"; copilot: "copilot"; opencode: "opencode"; phren: "phren"; }>; session: z.ZodUnion<readonly [z.ZodString, z.ZodString]>; }, z.core.$strip>; connection: z.ZodObject<{ name: z.ZodString; server: z.ZodString; fingerprint: z.ZodString; id: z.ZodString; }, z.core.$strict>; workers: z.ZodOptional<z.ZodArray<z.ZodObject<{ id: z.ZodString; fingerprint: z.ZodOptional<z.ZodString>; }, z.core.$strict>>>; revoked: z.ZodOptional<z.ZodBoolean>; activated: z.ZodOptional<z.ZodBoolean>; target: z.ZodOptional<z.ZodObject<{ server: z.ZodString; workspace: z.ZodString; tab: z.ZodString; pane: z.ZodString; source: z.ZodEnum<{ claude: "claude"; codex: "codex"; copilot: "copilot"; opencode: "opencode"; phren: "phren"; }>; session: z.ZodUnion<readonly [z.ZodString, z.ZodString]>; }, z.core.$strip>>; resume: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>; }, z.core.$strict>>; }, z.core.$strip>; export type RoleState = z.infer<typeof stateSchema>; /** The saved state; undefined before the file exists. */ export declare function readRoleState(root?: string): Promise<RoleState | undefined>; /** Uses the same serialization as every local role writer. */ export declare function updateConductorAuthority(root: string, change: (state: RoleState) => Promise<RoleState>): Promise<RoleState>; export declare function assertRoleMutable(state: RoleState | undefined): void; /** For tests: forget the cached state. */ export declare function resetRoleState(): void; /** A pane running an agent the Hook can talk to. */ export declare const runsAgent: (pane: Json | undefined) => pane is Json; /** * The conductor's pane on `server`, from a snapshot of it, whether or not an * agent runs there right now. A recorded pane gone from the snapshot ends the * role. In legacy mode a live pane with a conductor name is adopted and saved. */ export declare function conductorPane(server: string, s: Json, root?: string): Promise<Json | undefined>; /** The recorded conductor, whatever its server; undefined in legacy mode or with none. */ export declare function recordedConductor(): Promise<ConductorRecord | undefined>; /** Makes `pane` on `server` this computer's conductor, replacing any record. */ export declare function recordConductor(server: string, pane: Json, by: ConductorRecord["by"], session?: string): Promise<ConductorRecord>; /** Move only the captured role. The optional hand-over holds the receipt * writer's queue while preparing routing and committing this role; it must * roll routing back if commit fails. No role writer can interleave here. */ export declare function transferConductor(expected: ConductorRecord, server: string, pane: Json, session?: string, handOver?: (commit: () => Promise<void>) => Promise<void>): Promise<ConductorRecord>; /** The session now running in the conductor's pane: a restart or new login reattaches here. */ export declare function noteConductorSession(server: string, pane: string, session: string): Promise<void>; /** Ends the role. With `pane`, only when that pane holds it. Returns what was stopped. */ export declare function clearConductor(pane?: string): Promise<ConductorRecord | undefined>; /** The set name this Hook holds. */ export declare function readSetName(): Promise<SetName | undefined>; /** Keeps `name` when it is newer than the one held; `null` clears. Returns whether it changed. */ export declare function saveSetName(name: string | null, namedAt: string): Promise<boolean>; export {};