import type { JsonObject } from "../autonomy/contracts.ts"; import { type HarnessCapability } from "../capability-contract.ts"; import type { WorkerContextForkReference } from "./worker-context-fork-reference.ts"; export { HARNESS_CAPABILITIES, type HarnessCapability } from "../capability-contract.ts"; /** * Versioned control-plane contracts. These records are the durable truth exchanged between the * deterministic kernel/runtime and replaceable execution-plane workers. They deliberately do not * contain callbacks, provider objects, tool implementations, or transcript messages. */ export declare const ORCHESTRATION_SCHEMA_VERSION: 1; /** Shared durable-control bounds. Keep persisted orchestration records small enough to replay safely. */ export declare const MAX_ORCHESTRATION_IDENTIFIER_LENGTH = 512; export declare const MAX_ORCHESTRATION_MODEL_PROVIDER_LENGTH = 128; export declare const MAX_ORCHESTRATION_MODEL_ID_LENGTH = 512; export declare const MAX_ORCHESTRATION_DESCRIPTION_LENGTH: number; /** Worker terminal summaries use the same inline byte ceiling as ordinary tool output. */ export declare const MAX_ORCHESTRATION_WORKER_RESULT_SUMMARY_BYTES: number; export declare const MAX_ORCHESTRATION_COLLECTION_LENGTH = 64; export declare const MAX_ORCHESTRATION_DISPATCH_INSTRUCTIONS_LENGTH: number; /** * Lifetime ceilings for the retained hot projection. Terminal records are intentionally retained, * so these limits match the durable worker-fleet ceiling rather than only counting active work. */ export declare const MAX_ORCHESTRATION_AGENT_BINDINGS = 256; export declare const MAX_ORCHESTRATION_OBJECTIVES = 256; export declare const MAX_ORCHESTRATION_TASKS = 256; export declare const MAX_ORCHESTRATION_ATTEMPTS = 256; export declare const MAX_ORCHESTRATION_CHECKPOINTS = 4096; export declare const MAX_ORCHESTRATION_APPROVALS = 256; /** Approval prompts and terminal handoffs may each retain one notification per attempt. */ export declare const MAX_ORCHESTRATION_NOTIFICATIONS = 512; /** Source goal state admits at most 512 evidence entries for one objective. */ export declare const MAX_ORCHESTRATION_OBJECTIVE_EVIDENCE = 512; export declare const MAX_ORCHESTRATION_EVIDENCE = 4096; export declare const MAX_ORCHESTRATION_CHECKPOINT_SUMMARY_LENGTH: number; /** Absolute lineage bound retained for legacy durable-record recovery. New native workers are leaves. */ export declare const MAX_ORCHESTRATION_AGENT_DEPTH = 8; /** Direct-child bound retained for legacy durable-record recovery. New native workers admit none. */ export declare const MAX_ORCHESTRATION_DIRECT_CHILDREN = 64; /** One changed retained map value; aggregate projection accounting remains the authoritative ceiling. */ export declare const MAX_ORCHESTRATION_RETAINED_RECORD_BYTES: number; /** Leaves room for bounded idempotency evidence and the snapshot envelope below the on-disk ceiling. */ export declare const MAX_ORCHESTRATION_PROJECTION_BYTES: number; export declare const MAX_ORCHESTRATION_SNAPSHOT_IDEMPOTENCY_BYTES: number; export declare const MAX_ORCHESTRATION_PROJECTION_SNAPSHOT_BYTES: number; /** Matches the bounded worker/process result contract retained by the execution plane. */ export declare const MAX_ORCHESTRATION_PROCESS_OUTPUT_BYTES: number; export declare const MAX_WORKER_AUTHORITY_PATHS = 64; export declare const MAX_WORKER_AUTHORITY_PATH_LENGTH: number; export declare const MAX_WORKER_SOUL_LENGTH: number; export declare const WORKER_ROLES: readonly ["orchestrator", "planner", "explorer", "implementer", "operator", "verifier", "database"]; export type WorkerRole = (typeof WORKER_ROLES)[number]; export declare const ORCHESTRATION_THINKING_LEVELS: readonly ["off", "minimal", "low", "medium", "high", "xhigh", "max", "ultra"]; export type OrchestrationThinkingLevel = (typeof ORCHESTRATION_THINKING_LEVELS)[number]; export interface OrchestrationModelBinding { provider: string; modelId: string; thinkingLevel: OrchestrationThinkingLevel; } export interface OrchestrationModelPolicy { mode: "fixed" | "ordered-fallback"; candidates: readonly OrchestrationModelBinding[]; } /** Constrained direct-argv launcher policy. This is allowlisting, not OS/container isolation. */ export interface OrchestrationExecutionPolicy { allowedExecutables: readonly string[]; allowedEnvironmentVariables: readonly string[]; maxOutputBytes: number; } /** Legacy lineage limits retained in immutable snapshots; newly compiled native profiles use zeros. */ export interface OrchestrationDelegationLimits { /** Greatest recovered AgentBindingContract.depth the durable host may retain. */ maxDepth: number; /** Greatest number of recovered direct-child identities the durable host may retain. */ maxChildrenPerAgent: number; /** Greatest number of recovered non-root identities across this durable session. */ maxNestedAgentsPerSession?: number; } export declare const OBJECTIVE_STATUSES: readonly ["active", "paused", "completed", "cancelled"]; export type ObjectiveStatus = (typeof OBJECTIVE_STATUSES)[number]; export declare const TASK_STATUSES: readonly ["pending", "ready", "running", "blocked", "completed", "failed", "cancelled"]; export type OrchestrationTaskStatus = (typeof TASK_STATUSES)[number]; export declare const ATTEMPT_STATUSES: readonly ["queued", "leased", "running", "suspended", "completed", "partial", "blocked", "failed", "cancelled", "expired"]; export type AttemptStatus = (typeof ATTEMPT_STATUSES)[number]; export declare const WORKER_RESULT_STATUSES: readonly ["completed", "partial", "blocked", "failed", "cancelled"]; export type WorkerResultContractStatus = (typeof WORKER_RESULT_STATUSES)[number]; export type AgentBindingStatus = "registered" | "active" | "suspended" | "resuming" | "retired"; export interface AgentResumeContext { provider: "pi" | "external"; sessionId: string; sessionDir?: string; sessionFile?: string; cwd: string; worktreeLaneKey?: string; orchestrationProfileId?: string; resourceProfileNames: readonly string[]; modelRef?: string; contextPointers: readonly ResourcePointer[]; latestCheckpointId?: string; } /** Provider-neutral logical identity shared by durable orchestration and process supervision. */ export interface AgentIdentityContract { agentId: string; resumeContext: AgentResumeContext; } /** Durable logical identity. A replacement OS process resumes this same binding after interruption. */ export interface AgentBindingContract extends AgentIdentityContract { schemaVersion: typeof ORCHESTRATION_SCHEMA_VERSION; /** Legacy direct creator retained for recovery. Fresh leaf workers omit this field. */ parentAgentId?: string; /** Stable root identity retained across legacy recovered lineage. */ rootAgentId: string; /** Durable legacy lineage depth. Fresh leaf workers are always depth zero. */ depth: number; role: WorkerRole; status: AgentBindingStatus; activeAttemptId?: string; createdAt: string; updatedAt: string; } export interface RiskBudget { /** * Budget-counted tokens, not raw provider totals: input/output/cache-write tokens charge at * face value, prompt-cache reads at CACHE_READ_BUDGET_WEIGHT (see capability-gateway.ts). * Charging cache reads fully would turn this into a request counter, since every request * re-reads the fixed system prompt. */ maxTokens?: number; maxWallClockMs?: number; maxCostUsd?: number; maxAttempts?: number; maxToolCalls?: number; requireApprovalAboveCostUsd?: number; } export interface AcceptanceCriterion { id: string; description: string; required: boolean; evaluator?: string; } export interface ObjectiveContract { schemaVersion: typeof ORCHESTRATION_SCHEMA_VERSION; objectiveId: string; title: string; description: string; status: ObjectiveStatus; constraints: readonly string[]; acceptanceCriteria: readonly AcceptanceCriterion[]; riskBudget: RiskBudget; createdAt: string; updatedAt: string; } export interface TaskContract { schemaVersion: typeof ORCHESTRATION_SCHEMA_VERSION; taskId: string; objectiveId: string; title: string; description: string; role: WorkerRole; status: OrchestrationTaskStatus; dependsOn: readonly string[]; requiredCapabilities: readonly HarnessCapability[]; acceptanceCriterionIds: readonly string[]; /** Implementer task this verifier task must independently reconcile. */ verificationOfTaskId?: string; riskBudget: RiskBudget; createdAt: string; updatedAt: string; } export declare const RESOURCE_POINTER_KINDS: readonly ["repository", "worktree", "artifact", "evidence", "memory-query", "skill", "prompt", "service"]; export type ResourcePointerKind = (typeof RESOURCE_POINTER_KINDS)[number]; export declare function isResourcePointerKind(value: unknown): value is ResourcePointerKind; export interface ResourcePointer { id: string; kind: ResourcePointerKind; uri: string; readOnly: boolean; digest?: string; metadata?: JsonObject; } /** Bounded metadata-only resources retained in one worker execution contract. */ export declare const MAX_WORKER_RESOURCE_POINTERS = 64; export declare const MAX_WORKER_RESOURCE_PATH_LENGTH = 4096; export declare const MAX_WORKER_RESOURCE_METADATA_NAME_LENGTH = 256; /** Lightweight metadata catalogued without importing the executable tool module. */ export interface ToolCapabilityManifest { toolName: string; moduleSpecifier: string; capabilities: readonly HarnessCapability[]; roles: readonly WorkerRole[]; enforcements: readonly CapabilityEnforcementKind[]; sourcePath?: string; } export interface OrchestrationProfile { schemaVersion: typeof ORCHESTRATION_SCHEMA_VERSION; profileId: string; description: string; role: WorkerRole; modelPolicy: OrchestrationModelPolicy; capabilityCeiling: readonly HarnessCapability[]; toolNames: readonly string[]; /** Optional worker cwd and symmetric filesystem focus. Omitted means host-level machine scope. */ workspacePath?: string; resourceProfileNames: readonly string[]; /** Optional preset-routing metadata retained for authored profiles; never an admission allowlist. */ dispatchProfileIds: readonly string[]; executionPolicy?: OrchestrationExecutionPolicy; /** Newly compiled native profiles carry the mandatory zero-child leaf limit. */ delegationLimits?: OrchestrationDelegationLimits; budget: RiskBudget; /** Authored scheduling hint retained in the snapshot; the global scheduler owns actual concurrency. */ maxConcurrent: number; leaseTtlMs: number; requireIndependentVerification: boolean; /** Owner-pinned verifier profile. Required when independent verification is enabled. */ verificationProfileId?: string; /** Resolved origin retained for controlled improvements; omitted from authored JSON. */ sourcePath?: string; createdAt: string; updatedAt: string; } /** Admission-time worker profile materialization. Profile files are never consulted after this is persisted. */ export interface WorkerProfileExecutionContract { schemaVersion: typeof ORCHESTRATION_SCHEMA_VERSION; profile: OrchestrationProfile; modelBinding: OrchestrationModelBinding; authority: WorkerExecutionAuthorityContract; /** Metadata-only resources fixed at admission; their content remains lazy and non-durable. */ resourcePointers: readonly ResourcePointer[]; /** Resolved resource-profile identity text. Other worker resources are represented by profile tools. */ soul?: string; } /** Effective authority admitted for one materialized worker profile. */ export interface WorkerExecutionAuthorityContract { /** Process cwd fixed at admission. Legacy contracts omit it and recover from the session cwd. */ cwd?: string; capabilities: readonly HarnessCapability[]; toolNames: readonly string[]; readPaths: readonly string[]; writePaths: readonly string[]; deniedPaths: readonly string[]; budget: RiskBudget; } /** Immutable execution contract owned by the runtime, including any mandatory verifier. */ export interface WorkerExecutionContract { schemaVersion: typeof ORCHESTRATION_SCHEMA_VERSION; worker: WorkerProfileExecutionContract; verifier?: WorkerProfileExecutionContract; } /** Durable dispatch metadata. Model/tool choices are retained in the runtime-owned executionContract. */ export interface OrchestrationDispatchRequest { taskId: string; profileId: string; instructions: string; resourcePointerIds: readonly string[]; /** Legacy logical-agent creator retained only to recover previously persisted nested work. */ parentAgentId?: string; /** Runtime-owned goal/task correlation. Omitted by legacy records and normalized to an empty list. */ requirementIds?: readonly string[]; /** Execution owner. Omitted on legacy records and normalized to in-process. */ executionKind?: "in-process" | "managed-process"; /** Stable external lane identity shared by successive managed-process turns. */ logicalLaneId?: string; /** Monotonic dispatch sequence within a managed-process logical lane. */ dispatchSequence?: number; /** Durable mailbox message whose task-bearing intent owns this logical-agent turn. */ controlMessageId?: string; /** External provider identity retained for routing and diagnostics. */ provider?: string; /** Immutable profile identity used to audit the external launch authority. */ authorizationId?: string; /** Worktree-sync lane claimed by the external dispatcher. */ worktreeLaneKey?: string; /** Immutable sanitized parent context captured for this persistent logical worker at birth. */ birthContextForkReference?: WorkerContextForkReference; /** Runtime-owned immutable worker materialization. Never accepted from a model tool call. */ executionContract?: WorkerExecutionContract; } export type CapabilityEnforcementKind = "path-scope" | "process-launcher" | "service-proxy" | "memory-broker" | "control-plane"; export interface CapabilityDecision { capability: HarnessCapability; outcome: "allow" | "deny"; reasonCode: string; source: string; } export interface ExecutionGrant { schemaVersion: typeof ORCHESTRATION_SCHEMA_VERSION; grantId: string; objectiveId: string; taskId: string; attemptId: string; subjectId: string; role: WorkerRole; capabilities: readonly HarnessCapability[]; allowedTools: readonly string[]; resources: readonly ResourcePointer[]; readPaths: readonly string[]; writePaths: readonly string[]; deniedPaths: readonly string[]; budget: RiskBudget; policyVersion: string; decisionTrace: readonly CapabilityDecision[]; issuedAt: string; expiresAt?: string; } export interface AttemptLease { leaseId: string; attemptId: string; ownerId: string; fencingToken: number; issuedAt: string; expiresAt: string; } /** Restart-durable host retry ladder state for one resumable worker attempt. */ export interface AttemptRetryState { /** Scheduled retries already consumed; the initial execution is not included. */ retriesUsed: number; /** Earliest instant at which the suspended attempt may receive a fresh lease. */ notBefore: string; } /** Complete cumulative active usage for one execution attempt. Restart downtime is never included. */ export interface AttemptUsageSnapshot { toolCalls: number; inputTokens: number; outputTokens: number; cacheReadTokens: number; cacheWriteTokens: number; /** Provider-authoritative total; detail categories are not assumed to be additive. */ totalTokens: number; costUsd: number; activeWallClockMs: number; } export interface AttemptCheckpoint { checkpointId: string; attemptId: string; fencingToken: number; summary: string; artifactIds: readonly string[]; evidenceIds: readonly string[]; /** Omitted only by legacy checkpoints created before durable usage accounting existed. */ usage?: AttemptUsageSnapshot; createdAt: string; } export interface ArtifactContract { artifactId: string; kind: "diff" | "file" | "report" | "test-result" | "log" | "structured-data"; uri: string; digest?: string; sizeBytes?: number; createdAt: string; metadata?: JsonObject; } export interface EvidenceContract { evidenceId: string; criterionId?: string; kind: "observation" | "command" | "test" | "review" | "external"; summary: string; artifactIds: readonly string[]; trusted: boolean; createdAt: string; metadata?: JsonObject; } export interface WorkerErrorContract { code: string; message: string; retryable: boolean; details?: JsonObject; } export interface WorkerUsageContract { inputTokens?: number; outputTokens?: number; totalTokens?: number; costUsd?: number; wallClockMs: number; toolCalls: number; } export interface WorkerResultContract { schemaVersion: typeof ORCHESTRATION_SCHEMA_VERSION; resultId: string; objectiveId: string; taskId: string; attemptId: string; leaseId: string; fencingToken: number; status: WorkerResultContractStatus; reasonCode: string; summary: string; artifacts: readonly ArtifactContract[]; evidence: readonly EvidenceContract[]; errors: readonly WorkerErrorContract[]; nextAction?: string; usage: WorkerUsageContract; createdAt: string; } export interface ApprovalRequestContract { schemaVersion: typeof ORCHESTRATION_SCHEMA_VERSION; approvalId: string; objectiveId: string; taskId?: string; attemptId?: string; reasonCode: string; summary: string; requestedCapabilities: readonly HarnessCapability[]; requestedBudget?: RiskBudget; reversible: boolean; createdAt: string; } export declare const APPROVAL_OUTCOMES: readonly ["approved", "rejected"]; export type ApprovalOutcome = (typeof APPROVAL_OUTCOMES)[number]; /** Human decision only. Approval is not an execution grant; policy must compile a new grant afterward. */ export interface ApprovalResolutionContract { schemaVersion: typeof ORCHESTRATION_SCHEMA_VERSION; approvalId: string; outcome: ApprovalOutcome; reasonCode: string; resolvedAt: string; } export declare const ORCHESTRATION_EVENT_TYPES: readonly ["objective.created", "objective.updated", "objective.evidence_recorded", "objective.paused", "objective.resumed", "objective.completed", "objective.cancelled", "task.created", "task.attempt_prepared", "task.ready", "task.failed", "task.verification_finished", "agent.registered", "agent.retired", "agent.suspended", "agent.resume_requested", "agent.resumed", "attempt.queued", "attempt.grant_bound", "attempt.leased", "attempt.started", "attempt.lease_renewed", "attempt.checkpointed", "attempt.suspended", "attempt.resumed", "attempt.cancelled", "attempt.finished", "attempt.lease_expired", "approval.requested", "approval.resolved", "notification.enqueued", "notification.delivered"]; export type OrchestrationEventType = (typeof ORCHESTRATION_EVENT_TYPES)[number]; export type OrchestrationActorKind = "human" | "kernel" | "runtime" | "policy" | "router" | "worker"; export interface OrchestrationEvent { schemaVersion: typeof ORCHESTRATION_SCHEMA_VERSION; ordinal: number; eventId: string; type: OrchestrationEventType; aggregateId: string; actor: OrchestrationActorKind; occurredAt: string; correlationId?: string; causationId?: string; idempotencyKey?: string; payload: JsonObject; } export interface AppendOrchestrationEventInput { type: OrchestrationEventType; aggregateId: string; actor: OrchestrationActorKind; correlationId?: string; causationId?: string; idempotencyKey?: string; payload: JsonObject; } export declare function isHarnessCapability(value: unknown): value is HarnessCapability; /** Clone a runtime value into the persisted JSON domain, rejecting unsupported or over-deep data. */ export declare function toJsonObject(value: unknown): JsonObject; export declare function isOrchestrationEvent(value: unknown): value is OrchestrationEvent; //# sourceMappingURL=contracts.d.ts.map