{"version":3,"file":"terminal.d.ts","sourceRoot":"","sources":["../../../../src/harness/runtime/drive/terminal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEhD,OAAO,KAAK,EACX,cAAc,EACd,aAAa,EACb,qBAAqB,EACrB,cAAc,EACd,aAAa,EACb,cAAc,EACd,KAAK,EACL,MAAM,wBAAwB,CAAC;AAchC,sGAAsG;AACtG,wBAAsB,sBAAsB,CAC3C,MAAM,EAAE,aAAa,EACrB,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,cAAc,EACrB,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,KAAK,EAAE,CAAC,CA6BlB;AAED,4EAA4E;AAC5E,wBAAgB,qBAAqB,CACpC,IAAI,EAAE,aAAa,EACnB,MAAM,EAAE,cAAc,EACtB,KAAK,EAAE,MAAM,GAAG,IAAI,EACpB,KAAK,CAAC,EAAE,cAAc,GACpB,qBAAqB,CAcvB","sourcesContent":["import type { Context } from \"../../context.ts\";\nimport { SessionInvariantError } from \"../../session/session.ts\";\nimport type {\n\tOperationError,\n\tOperationMeta,\n\tOperationResultRecord,\n\tOperationState,\n\tSessionReader,\n\tTerminalStatus,\n\tWrite,\n} from \"../../session/types.ts\";\nimport {\n\tdeleteList,\n\tdeleteValue,\n\toperationMeta,\n\toperationPreparationPrefix,\n\toperationState as operationStateValue,\n\toperationToolArgsPrefix,\n\toperationToolMemoPrefix,\n\tpendingAssistantFrames,\n\tpendingEntry,\n\tpendingToolOutputPrefix,\n} from \"../../session/values.ts\";\n\n/** Build the mechanical operation-owned suffix used by an owning procedure's terminal transaction. */\nexport async function operationCleanupWrites(\n\treader: SessionReader,\n\toperationId: string,\n\tstate: OperationState,\n\tcontext: Context,\n): Promise<Write[]> {\n\tconst [toolArguments, toolMemos, preparations, toolOutputs] = await Promise.all([\n\t\treader.scanValues(operationToolArgsPrefix(operationId), context),\n\t\treader.scanValues(operationToolMemoPrefix(operationId), context),\n\t\treader.scanValues(operationPreparationPrefix(operationId), context),\n\t\treader.scanValues(pendingToolOutputPrefix(operationId), context),\n\t]);\n\n\tconst pendingIds = new Set<string>();\n\tif (state.at === \"tools\") {\n\t\tfor (const call of state.batch.calls) {\n\t\t\tif (call.status === \"outcome_ready\") pendingIds.add(call.resultEntryId);\n\t\t}\n\t}\n\tlet frameDelete: Write | undefined;\n\tif (state.at === \"assistant.effect_pending\" || state.at === \"deferred.effect_pending\") {\n\t\tframeDelete = deleteList(pendingAssistantFrames(operationId, state.responseEntryId));\n\t}\n\n\treturn [\n\t\tdeleteValue(operationMeta(operationId)),\n\t\tdeleteValue(operationStateValue(operationId)),\n\t\t...toolArguments.map(({ address }) => deleteValue(address)),\n\t\t...toolMemos.map(({ address }) => deleteValue(address)),\n\t\t...preparations.map(({ address }) => deleteValue(address)),\n\t\t...toolOutputs.map(({ address }) => deleteValue(address)),\n\t\t...(frameDelete === undefined ? [] : [frameDelete]),\n\t\t...[...pendingIds].map((id) => deleteValue(pendingEntry(id))),\n\t];\n}\n\n/** Construct the immutable observation record for one terminal decision. */\nexport function operationResultRecord(\n\tmeta: OperationMeta,\n\tstatus: TerminalStatus,\n\ttipId: string | null,\n\terror?: OperationError,\n): OperationResultRecord {\n\tif ((status === \"failed\") !== (error !== undefined)) {\n\t\tthrow new SessionInvariantError(\"Only a failed operation result may carry an error\");\n\t}\n\treturn {\n\t\toperationId: meta.operationId,\n\t\tkind: meta.intent.kind,\n\t\tstatus,\n\t\t...(error === undefined ? {} : { error }),\n\t\tfromTipId: meta.sourceTipId,\n\t\ttipId,\n\t\tstartedAt: meta.startedAt,\n\t\tendedAt: Date.now(),\n\t};\n}\n"]}