/** * Optional adapters for the Harness jobs and subagents seams. * * The class retains only lifecycle edges that Harness publishes and re-reads * snapshots/discovery from the services. It is intentionally not a second job * or subagent runtime. * @module dshline/work */ import type { Context } from '@deepseek-ai/cordis'; import type { Agent, AgentRegistry } from '@deepseek-ai/dsh-agent'; import type { JobRegistry } from '@deepseek-ai/dsh-jobs'; import type { SessionProjectionRegistry } from '@deepseek-ai/dsh-session-projection'; import type { SubagentRunEndInfo, SubagentRunInfo, SubagentRuntime } from '@deepseek-ai/dsh-subagent'; import type { ToolDefinition } from '@deepseek-ai/dsh-tools'; import type { WorkflowCapabilities } from './workflows.ts'; import type { JobOutputObservation } from './jobs.ts'; import type { JobWorkItem, SubagentWorkItem, WorkflowWorkItem, WorkInterruptResult, WorkSnapshot } from './model.ts'; /** Services and lifecycle observers the work projection consumes. */ export interface WorkCapabilities { /** The current agent owns job reads and interruption authorization. */ readonly agent: Agent; /** Optional generic background-job registry. */ readonly jobs?: JobRegistry; /** Optional generic subagent runtime. */ readonly subagents?: SubagentRuntime; /** * Optional live Agent registry, used to resolve an in-process child and fold * its semantic activity. A profile or provider without it gets no invented * activity — only the lifecycle row. */ readonly agents?: Pick; /** Optional tool definition resolution, for the child's own presentation. */ readonly resolveTool?: (name: string, agent: Agent) => ToolDefinition | undefined; /** * Optional session-projection registry, read ONLY for a resolved live child. * `snapshot()` is the cheap watermark-cached cut the seam exists to serve; * `tokenMeter.measure()` is O(surface) and belongs to `/context`, never to a * Work frame. */ readonly projections?: Pick; /** Ask the scoped parent context for lifecycle starts. */ readonly onSubagentStart?: (listener: (info: SubagentRunInfo) => void) => () => void; /** Ask the scoped parent context for lifecycle ends. */ readonly onSubagentEnd?: (listener: (info: SubagentRunEndInfo) => void) => () => void; /** * Optional workflow projection. Owned here so consumers keep one snapshot and * one disposal, while the ownership rule that makes it safe stays in its own * module: workflow events name a run, never the session that started it. */ readonly workflows?: WorkflowCapabilities; /** Redraw the live region after a capability projection changes. */ readonly invalidate: () => void; } /** * Projects optional Harness work capabilities for terminal views. * * The only retained subagent state is the open lifecycle edge. Labels, mode, * residency, and child presence are repeatedly read from the parent-relative * `listDescendants()` catalog, while jobs are read directly from `list()` and * never through the consuming `read()` API. Live activity is an optional * enrichment: a resolved in-process child Agent is observed with the same * event-driven fold the main status uses, and everything disposes with the * epoch or with this projection. */ export declare class HarnessWork { private readonly capabilities; private readonly liveSubagents; private readonly discovered; private readonly disposers; /** * Job output observations handed out and not yet disposed. * * The overlay owns the handle it is given and disposes it on every path out * of a Job detail; this set exists so {@link dispose} can contain a * still-live one. It is emptied as handles are released, so it reads as "what * a teardown mistake would leak", not as a second owner. */ private readonly jobObservations; private readonly workflows; private listingGeneration; /** * The descendant walk in flight, or undefined when none is. * * Present only for the duration of the walk, and the reason a second lifecycle * edge does not start another one: the key is the projection, so there is * nothing to distinguish two equivalent reads by. Cleared when the walk settles * — on failure as well as success — so a rejected walk leaves the next edge free * to ask again. */ private listing; /** Whether a lifecycle edge asked for a read while one was already in flight. */ private listingAgain; /** The signal of the walk in flight, for a teardown that abandons it. */ private listingAbort; /** Whether {@link HarnessWork.dispose} has run, so no walk may start after it. */ private disposed; constructor(capabilities: WorkCapabilities); /** Stop listening to capability changes and release every child observer. */ dispose(): void; /** * Read the current capability-owned work records. * @returns active jobs and observed active subagent lifecycle epochs. */ snapshot(): WorkSnapshot; /** * Read the status line's work segment, counting without building a row. * * The same three counts `workSummary` takes off a full snapshot, taken from * the same authorities and formatted by the same `formatWorkCounts` — so * `/work` and the footer cannot disagree, and the footer gets them without the * enrichment only an overlay has columns for. For every live subagent that * means no activity fold, no `requestHeader()` route read, no child projection * cut, and no `inheritedEventCount`; for every owned run, no member sort and no * child join; for every job, no row object. * * Live by construction: each call reads the current registry list, the current * lifecycle epochs, and the current durable workflow records, so a permission * change, a job settling, a subagent starting or ending, and a workflow member * moving all show on the very next paint. Nothing is remembered between calls, * which is the point — a count that could go stale would be a second lifecycle * model next to the three authorities it counts. * @returns a whole-segment status label, or undefined when there is no work. */ summary(): string | undefined; /** * Interrupt a subagent only where the owning generic seam exposes authority. * * The operation is Harness `interrupt()` on a live continuable child: it * cancels the current turn, keeps the Activation, inbox, and descendants, and * is a fire-and-return signal rather than a deletion of the durable child. A * Job stop is deliberately NOT this method — see {@link stopJob} — and a * workflow run has no authority here at all, because `ctx.workflowEngine` * publishes `start()` alone. * @param item - the selected subagent row. * @returns the outcome as one short user-facing sentence. */ interruptSubagent(item: SubagentWorkItem | WorkflowWorkItem): WorkInterruptResult; /** * Ask Harness to stop one running Job, on a human's behalf. * * This is the generic registry cancellation, and it is safe for a HUMAN to * call in a way an older generation's registry was not. That generation kept * a "reported" bit on the record: calling `kill()` from anywhere meant the * model would never be told the Job had stopped, which is a correct * optimization for the ONE caller that existed — the model's own `job_kill`, * whose tool result already says what it did — and a stale world model for * anyone else. The adopted generation separates the two: the registry owns * cancellation, and `dsh-tool-jobs` owns a private ledger of the jobs its own * tool already delivered. A human stop enters no such ledger, so Harness * settlement and the completion reporter deliver the ordinary outcome to the * owning agent, with the reason merged into its detail. dshline's own * responsibility is therefore narrow and exactly what this method does: call * the registry, with this session as the fenced caller, and claim nothing * about delivery. * * Every Job kind the registry holds gains the control at once, because the * call names an id and never a kind, a provider, or a subprocess. * @param item - the inspected Job row. * @returns the outcome as one short user-facing sentence. */ stopJob(item: JobWorkItem): WorkInterruptResult; /** * Begin observing one Job's retained output, non-consumingly. * * Demand-driven by construction: nothing here runs until a Job detail stage is * actually opened, the `/work` overview does exactly zero output reads, and * the handle is dead the moment the stage closes. The read is `readAt`, never * the consuming `read`, so a human watching a Job's output cannot take a * single byte from the model's own cursor. * * The caller OWNS the returned handle and must dispose it. This projection * keeps a containment set so {@link dispose} can catch a leaked one. * @param id - the exact Job id to inspect. * @returns an open observation, or undefined when the Job is not observable. */ observeJob(id: string): JobOutputObservation | undefined; /** * Resolve this epoch's in-process child Agent and start observing it. * * The Agent is captured by exact object identity, so a later same-id * replacement can never fold into this epoch — and holding it, rather than * re-resolving an id per frame, is what lets the row read the child's own * route and projections from the same instance the activity fold is watching. */ private attachChild; /** * Read labels, mode, residency, and child presence from direct-child discovery. * * The recursive catalog is the only seam that publishes those four as one * row: `listChildren` answers with the flat parent catalog, which carries no * session-store residency, no lineage, and no branch diagnostic, so a row * built from it could never name a durable conversation to open. Depth one * is this parent's direct child; the traversal reads deeper only because the * seam publishes no direct-children-only form of these rows. * * One walk at a time, and at most one more behind it. A burst of lifecycle * edges used to start a walk per edge, every one but the last running to * completion to be thrown away — on a slow or remote catalog that is the whole * cost of the burst, spent on results nobody reads. So a request arriving * while a walk is in flight records that a read is owed rather than starting a * second, and the settled walk starts exactly one. A burst of N edges now * costs two walks, and the walk that is APPLIED is still the one that began * after the last edge, because {@link listingGeneration} counts requests * rather than starts. */ private refreshSubagents; /** * Walk the descendant catalog, applying it only if it answers the newest request. * * The generation is read BEFORE the call and compared after it, which is the * whole of what keeps a superseded walk from being applied; nothing is cached * beyond the walk in flight, and the next edge asks again. * @param subagents - the runtime whose catalog is the authority for these facts. */ private startListing; /** * Store only discovery facts the service explicitly returned. * * `activity` is session-store residency — a live or persisted record slot, * not a model turn in flight — so it is mapped to residency wording rather * than presented as progress. */ private remember; /** Turn the active registry views into the rows the overlay presents. */ private jobItems; /** * The ACTIVE jobs, as the registry publishes them, never consuming a producer's * output cursor. * * The active filter is the product's own decision and is not a limitation of * the seam: the registry keeps a settled record listed until its owner is * disposed, precisely so a caller that collected the terminal state can still * read it, and `/work` deliberately does not. A Job that settles disappears * here, takes its row with it, and takes its open detail stage with it too. */ private activeJobViews; /** How many jobs the registry currently reports as active. */ private activeJobCount; /** * Read the two child projection units, for a live local child only. * * Deliberately keyed off the resolved Agent rather than the child's session * id: a provider-managed child may well have a durable session somewhere, * and reading projections off it by id would let `/work` publish telemetry * about a worker whose computation it cannot observe. The projection cut is * the seam's cheap read face — a watermark-cached snapshot narrowed to the * two keys — not `tokenMeter.measure()`. */ private childProjections; /** Convert a published lifecycle edge, enriching it only with discovery data. */ private subagentItem; } /** * Connect the work projection to this runner's optional services and scoped * parent lifecycle events. * @param ctx - host context holding optional generic services. * @param agent - session agent whose work the view may present. * @param invalidate - redraw request for projection changes. * @returns the internal work integration. */ export declare function createHarnessWork(ctx: Context, agent: Agent, invalidate: () => void): HarnessWork; //# sourceMappingURL=index.d.ts.map