/** * Per-project engine state and cross-project run routing. * * A WorkflowManager's cwd keys its whole persistence store (workflowProjectKey), so a server * that serves more than one project holds one manager per project directory — all sharing a * single AgentRunner, whose agent sessions carry their own cwd. `run` calls select their * project explicitly (the tool's `projectDir` argument); `status`/`stop`/`resume` * route by locating the runId: first across live contexts, then by scanning the on-disk * project stores, whose `project.json` manifests (written by the engine) map the one-way * store key back to its project directory. */ import type { AgentRunner, RunEventLogRecord } from "@automatalabs/shared-types"; import { WorkflowManager, type WorkflowRunResult } from "@automatalabs/workflows"; import { WorkflowNotificationClaims } from "./workflow-notifications.js"; export declare const MAX_ACTIVE_RUNS = 4; /** * Tracks preparing and executing runs against the MAX_ACTIVE_RUNS admission cap. One * registry per project: every session/server sharing a project shares its cap, and a * cross-session `action:"status"` can find the live promise instead of falling back to polling. */ export declare class ActiveRunRegistry { private starting; private readonly active; reserve(): boolean; activeCount(): number; releaseReservation(): void; has(runId: string): boolean; hold(runId: string): void; track(runId: string, promise: Promise): void; get(runId: string): Promise | undefined; evict(runId: string): void; } export interface ProjectContext { projectDir: string; manager: WorkflowManager; activeRuns: ActiveRunRegistry; } /** The routing surface WorkflowScriptResources needs — a registry, or a single pinned store. */ export interface RunStoreRouter { /** The context whose store contains runId, if any. */ storeFor(runId: string): ProjectContext | undefined; /** Every currently-live context (for bounded list merging). */ stores(): ProjectContext[]; /** Aggregated runDeleted events across all current and future contexts; returns detach. */ onRunDeleted(listener: (event: { runId: string; }) => void): () => void; /** Durable event appends across all current and future contexts; returns detach. */ onRunEventPersisted(listener: (record: RunEventLogRecord) => void): () => void; /** Whole-run stop events across all current and future contexts; returns detach. */ onRunStopped(listener: (event: { runId: string; }) => void): () => void; } export type ProjectDirResolution = { ok: true; projectDir: string; } | { ok: false; message: string; }; /** * Validate a caller-supplied project directory before any engine state is created for it. * Realpathing keeps symlinked paths from splitting one project into several stores. */ export declare function resolveProjectDir(raw: unknown): ProjectDirResolution; export declare class WorkflowProjectRegistry implements RunStoreRouter { private readonly runner; private readonly options; readonly notificationClaims: WorkflowNotificationClaims; private readonly contexts; private readonly deletionListeners; private readonly persistedEventListeners; private readonly stoppedListeners; constructor(runner: AgentRunner, options?: { leaseOwnerId?: string; }); /** Adopt an externally built manager as its project's context (composition back-compat). */ adopt(manager: WorkflowManager, activeRuns?: ActiveRunRegistry): ProjectContext; /** Context for a validated project directory, creating its manager on first use. */ getOrCreate(projectDir: string): ProjectContext; private register; storeFor(runId: string): ProjectContext | undefined; /** * Find runId among project stores this process has never opened, via each store's * `project.json` manifest. Stores predating the manifest are skipped (they heal on their * project's next engine construction). */ private locateOnDisk; stores(): ProjectContext[]; onRunDeleted(listener: (event: { runId: string; }) => void): () => void; onRunEventPersisted(listener: (record: RunEventLogRecord) => void): () => void; onRunStopped(listener: (event: { runId: string; }) => void): () => void; activeRunCount(): number; snapshot(): Array<{ projectDir: string; activeRuns: number; }>; } /** A fixed single-store router for hosts that construct WorkflowScriptResources directly. */ export declare function singleStoreRouter(manager: WorkflowManager): RunStoreRouter; //# sourceMappingURL=project-registry.d.ts.map