/** * Product direction, declared so the rest of the contract leaves room for it. * Nothing in this module is implemented yet. * * - Agents connect from a terminal (or run inside the platform), work in their * own branch, and stream their reasoning so humans can watch live. * - Every commit, thought and decision is a node in a code graph; agents can be started * from any node, and humans resolve agent work by deciding, not by rewriting it. */ import type { AgentIdentity, Attribution } from "./actor.ts"; import type { Id, Outcome, Page, PageRequest, Timestamp } from "./common.ts"; import type { Refs } from "./handles.ts"; import type { PersonRef } from "./views.ts"; export type SessionStatus = "running" | "waiting" | "finished" | "failed" | "stale"; export interface AgentSessionSummary { readonly id: Id; readonly agent: AgentIdentity; readonly onBehalfOf: PersonRef; readonly repo: string; /** Agents push only to their own branch, never to the default branch. */ readonly branch: string; readonly status: SessionStatus; readonly startedAt: Timestamp; readonly endedAt: Timestamp | null; } export type TraceKind = "thought" | "tool" | "message" | "commit" | "resolution"; export interface TraceNode { readonly id: Id; readonly parent: Id | null; readonly kind: TraceKind; readonly body: string; readonly commit: string | null; readonly at: Timestamp; readonly by: Attribution; } export interface StartSession { readonly runtime: string; readonly repo: string; /** Start from a branch, or from any node in the code graph. */ readonly from: { readonly ref: string } | { readonly node: Id }; } export interface AgentSessions { /** `token` lets the agent push to its branch and stream its trace; it is scoped to this one session. */ start(input: StartSession): Promise>; list(filter: { readonly branch?: string; readonly status?: SessionStatus }): Promise; session(id: Id): Promise; } export interface AgentSession { readonly summary: AgentSessionSummary; trace(page?: PageRequest): Promise>; /** Live updates while the session runs. */ watch(): Promise>; /** Only the session's own agent may append to its trace. */ emit(nodes: readonly Omit[]): Promise; end(outcome: "finished" | "failed"): Promise; } export type Verdict = | { readonly kind: "approve" } | { readonly kind: "reject"; readonly reason: string } | { readonly kind: "redirect"; readonly instruction: string }; export interface Review { readonly session: AgentSessionSummary; /** Approving lands the agent's branch; redirecting starts a new session from the same point with the instruction. */ decide(verdict: Verdict): Promise; } export type GraphNodeKind = "commit" | "trace" | "decision"; export interface GraphNode { readonly id: Id; readonly kind: GraphNodeKind; readonly summary: string; readonly by: Attribution; readonly at: Timestamp; readonly parents: readonly Id[]; } export interface Graph { node(id: Id): Promise; around(commit: string, depth?: number): Promise<{ readonly nodes: readonly GraphNode[]; readonly focus: Id }>; } /** * Capabilities only a human holds. An agent can read the graph and work in its session, * but it can never start other agents or decide on agent work, its own included. */ export interface HumanRefs extends Refs { readonly agents: AgentSessions; review(session: Id): Promise; graph(repo: string): Promise; } /** Narrows a handle to its human capabilities, or returns null for agents and anonymous actors. */ export type AsHuman = (refs: Refs) => HumanRefs | null;