import { type ConsoleFactory, Job, type JobRunner } from './types.ts'; export declare class JobTable { private readonly jobs; private nextId; private readonly consoleFactory; private factoryConsoles; private disowned; /** * @param consoleFactory builds each new job's console from its job * id; null means an in-memory console per job. A factory must hand * every job a fresh backing: ids restart at 1 when the table * empties (GNU numbering), so a store keyed on the id alone gets * reused, and a reused stream replays the previous job's chunks, * ending chunk included. The table tracks what the factory builds * and closeConsoles() releases it at workspace teardown, because a * config-provisioned store (a Redis client per job) is invisible * to the embedder; a console still outlives its table entry, so * reap() never closes one. */ constructor(consoleFactory?: ConsoleFactory | null); /** * Register a job and start it. * * The table creates the task itself so the runner is handed a job that * already has a console. Building the task first would leave a window * in which output could arrive with nowhere to go. */ submit(init: { command: string; run: JobRunner; abort: AbortController; cwd: string; agent?: string; sessionId?: string; }): Job; loadJob(job: Job): void; get(jobId: number): Job | null; listJobs(): Job[]; runningJobs(): Job[]; /** * Stop a job and record it as killed. * * The job is settled here rather than by waiting for the aborted * runner to unwind. The signal is only observed where someone checks * it, which today is the executor between nodes and the commands that * take it, so a job sitting inside one long command would not notice * until it finished on its own. Joining would hang the shell on * exactly the runaway job the caller is trying to stop. * * The console's own guards make the early ending safe: emits after the * ending chunk are dropped, so a runner still unwinding cannot append * past its own death, and `settle` returns early once the job is no * longer RUNNING so it cannot relabel it. */ kill(jobId: number): Promise; /** * Drop a job from the table without stopping it (`disown`): the job * keeps running, `jobs` no longer lists it and `wait` no longer knows * it. It stays on a side list so `killAll` at teardown reaches its * task. */ disown(jobId: number): boolean; /** Stop every running job, returning the ones that were running. * Disowned jobs are stopped too: the shell forgot them, the workspace * did not, and a teardown that left them running would leak tasks. */ killAll(): Promise; /** * Close every console the factory built, releasing its store. * * Called by workspace teardown after killAll(). Only tracked, * factory-built consoles are closed: the default in-memory ones hold * nothing, while a factory-provisioned store keeps a client open per * job, and in Node an open client holds the process alive. Closing * also releases any reader still parked on one. */ closeConsoles(): Promise; /** * Block until a job ends, then return it. * * Joined on the console's ending chunk, never on the status field: * kill() and settle() both flip the status before their final * appends, and every await yields a microtask, so a status-based * return could let the caller snapshot and reap the job before * `Killed` or the ending chunk is persisted. A restored job has no * task and its console already holds the ending chunk, so it * returns without waiting. */ wait(jobId: number): Promise; /** * Join every job in the table, returning the ones still running. * * Every job, not only the running ones: a killed job's `Killed` * marker can still be in flight (see wait()), and bare `wait` * snapshots each console right after this returns. Joining a * finished job costs one read. */ waitAll(): Promise; /** * Remove one job from the table. * * What a targeted `wait`/`fg` does after adopting the job's output, * matching GNU bash, where a job waited on by id is deleted from the * job list. Leaving it would let a later bare `wait` snapshot the * same console and print the output twice. */ reap(jobId: number): void; /** * Return completed/killed jobs and remove them from the table. * * A reader holding a job's console keeps reading it: the console * outlives its table entry and dies with its last reader. */ popCompleted(): Job[]; } //# sourceMappingURL=table.d.ts.map