/** * The workflow authority behind `/work`. * * A separate adapter beside the jobs and subagents projections, for one reason: * its ownership rule is different. `ctx.jobs` answers per caller and the * subagent lifecycle edges are scoped to the delegating parent, but raw * `workflow/*` events carry only `{ id, meta }` — a run's identity, never the * Session that asked for it. Subscribing to them alone would show another * window's orchestration inside this one. * * So ownership comes from the durable side. `dsh-tool-workflow` appends * `tool-workflow/run-start` / `agent-start` / `agent-end` / `run-end` into the * PARENT Session of a top-level run, and nowhere else — a nested run started * inside a subagent records nothing. A run whose `run-start` reached the * attached session's own log is therefore provably this window's, and every * member fact this view shows is one of those records. Live `workflow/*` events * are accepted only for a run already proven owned, and only as enrichment: * the description, the current phase, the newest log line, and the terminal * stop reason. * * Reconstruction is deliberately live-feed only. A `run-start` left in an old * log by a process that died is not evidence that a script is executing now, * and `/work` is a live operational surface; durable workflow history belongs * to the transcript, which replays those records where they were written. * @module dshline/work/workflows */ import type { Session, SessionEvent } from '@deepseek-ai/dsh-session'; import type { WorkflowMeta, WorkflowStopReason } from '@deepseek-ai/dsh-workflow/types'; import type { SubagentWorkItem, WorkflowWorkItem } from './model.ts'; /** One live `workflow/*` event, reduced to the enrichment Work presents. */ export type WorkflowObservation = /** Any event whose only useful contribution is the run's validated meta. */ { readonly kind: 'meta'; } /** A `phase(title)` call. */ | { readonly kind: 'phase'; readonly title: string; } /** A `log(message)` call. */ | { readonly kind: 'log'; readonly message: string; } /** The run settled. */ | { readonly kind: 'end'; readonly stopReason: WorkflowStopReason; readonly agentsStarted: number; }; /** Services and feeds the workflow projection consumes. */ export interface WorkflowCapabilities { /** The attached parent Session, and the only ownership authority. */ readonly session: Session; /** The process-wide session feed; the projection filters it by exact Session. */ readonly onSessionEvent: (listener: (session: Session, event: SessionEvent) => void) => () => void; /** * Live `workflow/*` enrichment, already folded into one callback. Absent when * the profile mounts no workflow engine, which costs only the enrichment. */ readonly onWorkflowObservation?: (listener: (runId: string, meta: WorkflowMeta, observation: WorkflowObservation) => void) => () => void; /** Redraw the live region after a record or an enrichment changed. */ readonly invalidate: () => void; } /** * Project the workflow runs the attached session owns. * * Holds no run handle and offers no control: `ctx.workflowEngine` publishes * `start()` and nothing a UI could use to reach a run it did not start, so * Work observes workflows and stops there. */ export declare class HarnessWorkflows { private readonly capabilities; private readonly runs; private readonly disposers; /** * @param capabilities - the session feed, optional live enrichment, and redraw. */ constructor(capabilities: WorkflowCapabilities); /** Stop observing; nothing observed afterwards can repaint this projection. */ dispose(): void; /** * How the owned runs divide a status line's three counts. * * The two facts a footer segment needs, derived from the same records and the * same rule {@link items} applies when it joins a member to its child — an * UNSETTLED member whose child session still has an open lifecycle epoch claims * that child, and nothing else does — without building a run, a member, or the * child rows they would join to. * * Deliberately NOT gated on the run's live state. `state` is 'running' only * until the live `workflow/end` observation lands, and that observation is * enrichment, whereas membership and a member's outcome are durable records. * Upstream keeps member listeners alive through `dispose()` because child * endings can be SYNTHESIZED while a run reaches quiescence, so a run that has * reported its result can still owe a member's ending — and a child still live * under such a member is presented by the workflow's own row, which is what * makes it claimed rather than loose. The durable `tool-workflow/run-end` * record is what takes the run out of this map. * * `live` is the set of child ids with an open lifecycle epoch, passed IN rather * than read here: joining a member to a child is the subagent projection's * authority, and taking the set from it is what keeps this a count of the same * children the rows are built from. It is why `claimed` can never exceed the * number of live epochs it is subtracted from. * @param live - durable child ids with an open lifecycle epoch right now. * @returns the owned run count, and how many live children a run presents. */ counts(live: ReadonlySet): { readonly runs: number; readonly claimed: number; }; /** * Read the owned workflow runs, joined to their live children. * @param subagents - every active subagent epoch, for the `childId` join. * @returns one row per owned run, members in record order. */ items(subagents: readonly SubagentWorkItem[]): WorkflowWorkItem[]; /** * Fold one durable record of the attached session. * @param event - one event from this session's own feed. * @returns whether the projection changed and a redraw is owed. */ private foldRecord; } //# sourceMappingURL=workflows.d.ts.map