{"version":3,"file":"drive.d.ts","sourceRoot":"","sources":["../../../src/harness/runtime/drive.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAgBxD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAE,KAAK,EAAmB,MAAM,YAAY,CAAC;AAUzD,qGAAqG;AACrG,wBAAsB,cAAc,CAAC,QAAQ,SAAS,MAAM,GAAG,SAAS,EACvE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,EACpB,KAAK,EAAE,KAAK,GACV,OAAO,CAAC,YAAY,CAAC,CA0EvB","sourcesContent":["import type { DriveOutcome } from \"../agent-harness.ts\";\nimport { AbortRequested } from \"../execution/effect-gate.ts\";\nimport { SessionInvariantError } from \"../session/session.ts\";\nimport { runCheckpoint, startRun } from \"./drive/checkpoint.ts\";\nimport { runDeferred } from \"./drive/deferred.ts\";\nimport { runGeneration } from \"./drive/generation.ts\";\nimport { reconcileOperation } from \"./drive/reconcile.ts\";\nimport { recoverAssistantGeneration } from \"./drive/recovery.ts\";\nimport {\n\tcommitNavigation,\n\trecoverStructuralGeneration,\n\trunStructuralDecision,\n\trunStructuralGeneration,\n\trunStructuralRetryWait,\n} from \"./drive/structural.ts\";\nimport { runTools } from \"./drive/tools.ts\";\nimport type { Lane } from \"./lane.ts\";\nimport type { Drive, ProcedureResult } from \"./types.ts\";\n\nfunction currentOperation<TContext extends object | undefined>(lane: Lane<TContext>, drive: Drive) {\n\tconst operation = lane.state.operation;\n\tif (operation === null || operation.meta.operationId !== drive.operationId) {\n\t\tthrow new SessionInvariantError(`Drive ${drive.operationId} has no matching current operation`);\n\t}\n\treturn operation;\n}\n\n/** Drive one installed pass through direct durable procedures until settlement or a durable wait. */\nexport async function driveOperation<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n): Promise<DriveOutcome> {\n\tlet operation = currentOperation(lane, drive);\n\tif (operation.state.control.status === \"running\") {\n\t\ttry {\n\t\t\tawait lane.hooks.runWithGate(\n\t\t\t\t\"before_drive\",\n\t\t\t\t{ lane: lane.name, runId: drive.operationId, operation: operation.meta.intent.kind },\n\t\t\t\tdrive.gate,\n\t\t\t\tdrive.context,\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tif (!(error instanceof AbortRequested)) throw error;\n\t\t\tawait error.cancellation;\n\t\t}\n\t}\n\n\tfor (;;) {\n\t\toperation = currentOperation(lane, drive);\n\t\tconst state = operation.state;\n\t\tlet result: ProcedureResult;\n\t\ttry {\n\t\t\tif (state.control.status === \"cancel_requested\") {\n\t\t\t\tresult = await reconcileOperation(lane, drive);\n\t\t\t} else\n\t\t\t\tswitch (state.at) {\n\t\t\t\t\tcase \"starting\":\n\t\t\t\t\t\tresult = await startRun(lane, drive, state);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"checkpoint\":\n\t\t\t\t\t\tresult = await runCheckpoint(lane, drive, state);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"assistant.ready\":\n\t\t\t\t\tcase \"assistant.retry_wait\":\n\t\t\t\t\t\tresult = await runGeneration(lane, drive, state);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"assistant.effect_pending\":\n\t\t\t\t\t\tresult = await recoverAssistantGeneration(lane, drive, state);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"tools\":\n\t\t\t\t\t\tresult = await runTools(lane, drive, state);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"deferred.suspended\":\n\t\t\t\t\tcase \"deferred.effect_pending\":\n\t\t\t\t\t\tresult = await runDeferred(lane, drive, state);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"summary.deciding\":\n\t\t\t\t\t\tresult = await runStructuralDecision(lane, drive, state);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"summary.ready\":\n\t\t\t\t\t\tresult = await runStructuralGeneration(lane, drive, state);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"summary.effect_pending\":\n\t\t\t\t\t\tresult = await recoverStructuralGeneration(lane, drive, state);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"summary.retry_wait\":\n\t\t\t\t\t\tresult = await runStructuralRetryWait(lane, drive, state);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"navigation.ready_to_commit\":\n\t\t\t\t\t\tresult = await commitNavigation(lane, drive, state);\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (!(error instanceof AbortRequested)) throw error;\n\t\t\tawait error.cancellation;\n\t\t\tresult = { kind: \"continue\" };\n\t\t}\n\n\t\tif (result.kind === \"settled\") return { kind: \"settled\", outcome: result.outcome };\n\t\tif (result.kind === \"waiting\") return result.outcome;\n\t\tconst next = currentOperation(lane, drive).state;\n\t\tif (next === state && next.control.status !== \"cancel_requested\") {\n\t\t\tthrow new SessionInvariantError(`Drive procedure made no progress from ${state.at}`);\n\t\t}\n\t}\n}\n"]}