@mikode13/harness 11.0.1 → 11.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +186 -16
- package/dist/agent/domain/agent.d.ts +41 -3
- package/dist/agent/domain/agent.js.map +1 -1
- package/dist/agent/domain/approval.d.ts +20 -0
- package/dist/agent/domain/approval.js.map +1 -1
- package/dist/agent/domain/inbox.d.ts +42 -0
- package/dist/agent/domain/inbox.js +81 -0
- package/dist/agent/domain/inbox.js.map +1 -0
- package/dist/agent/domain/oneRunAtATime.d.ts +17 -0
- package/dist/agent/domain/oneRunAtATime.js +32 -0
- package/dist/agent/domain/oneRunAtATime.js.map +1 -0
- package/dist/agent/domain/runContext.d.ts +9 -0
- package/dist/agent/domain/runContext.js +5 -0
- package/dist/agent/domain/runContext.js.map +1 -1
- package/dist/agent/domain/session.d.ts +15 -0
- package/dist/agent/domain/session.js +80 -0
- package/dist/agent/domain/session.js.map +1 -0
- package/dist/engines/claude/infrastructure/model/claudeAgent.d.ts +6 -2
- package/dist/engines/claude/infrastructure/model/claudeAgent.js +20 -5
- package/dist/engines/claude/infrastructure/model/claudeAgent.js.map +1 -1
- package/dist/engines/codex/infrastructure/model/codexAgent.d.ts +5 -1
- package/dist/engines/codex/infrastructure/model/codexAgent.js +13 -2
- package/dist/engines/codex/infrastructure/model/codexAgent.js.map +1 -1
- package/dist/engines/domain/model/backgroundAgents.d.ts +5 -2
- package/dist/engines/domain/model/backgroundAgents.js +11 -3
- package/dist/engines/domain/model/backgroundAgents.js.map +1 -1
- package/dist/engines/domain/model/compactor.d.ts +40 -0
- package/dist/engines/domain/model/compactor.js +5 -0
- package/dist/engines/domain/model/compactor.js.map +1 -0
- package/dist/engines/domain/model/llmAgent.d.ts +53 -2
- package/dist/engines/domain/model/llmAgent.js +419 -24
- package/dist/engines/domain/model/llmAgent.js.map +1 -1
- package/dist/engines/domain/model/recentCompaction.d.ts +39 -0
- package/dist/engines/domain/model/recentCompaction.js +119 -0
- package/dist/engines/domain/model/recentCompaction.js.map +1 -0
- package/dist/engines/domain/model/stepContext.js +3 -0
- package/dist/engines/domain/model/stepContext.js.map +1 -1
- package/dist/engines/domain/model/triagedCompaction.d.ts +27 -0
- package/dist/engines/domain/model/triagedCompaction.js +60 -0
- package/dist/engines/domain/model/triagedCompaction.js.map +1 -0
- package/dist/factory/infrastructure/agentLLMFactory.d.ts +56 -15
- package/dist/factory/infrastructure/agentLLMFactory.js +144 -25
- package/dist/factory/infrastructure/agentLLMFactory.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/llm/domain/contextTriage.d.ts +26 -0
- package/dist/llm/domain/contextTriage.js +3 -0
- package/dist/llm/domain/contextTriage.js.map +1 -0
- package/dist/llm/domain/llm.d.ts +18 -1
- package/dist/llm/domain/llm.js.map +1 -1
- package/dist/llm/domain/message.d.ts +18 -1
- package/dist/llm/domain/message.js +20 -0
- package/dist/llm/domain/message.js.map +1 -1
- package/dist/llm/infrastructure/claudeLLMClient.d.ts +4 -5
- package/dist/llm/infrastructure/claudeLLMClient.js +39 -13
- package/dist/llm/infrastructure/claudeLLMClient.js.map +1 -1
- package/dist/llm/infrastructure/jevContextTriage.d.ts +18 -0
- package/dist/llm/infrastructure/jevContextTriage.js +92 -0
- package/dist/llm/infrastructure/jevContextTriage.js.map +1 -0
- package/dist/llm/infrastructure/openAILLMClient.d.ts +4 -5
- package/dist/llm/infrastructure/openAILLMClient.js +20 -9
- package/dist/llm/infrastructure/openAILLMClient.js.map +1 -1
- package/dist/orchestration/domain/model/orchestratorAgent.d.ts +9 -1
- package/dist/orchestration/domain/model/orchestratorAgent.js +20 -3
- package/dist/orchestration/domain/model/orchestratorAgent.js.map +1 -1
- package/dist/recovery/domain/history.d.ts +10 -3
- package/dist/recovery/domain/history.js +1 -0
- package/dist/recovery/domain/history.js.map +1 -1
- package/dist/recovery/domain/recoveryStore.d.ts +14 -2
- package/dist/recovery/domain/recoveryStore.js.map +1 -1
- package/dist/recovery/infrastructure/fileRecoveryStore.d.ts +21 -2
- package/dist/recovery/infrastructure/fileRecoveryStore.js +58 -6
- package/dist/recovery/infrastructure/fileRecoveryStore.js.map +1 -1
- package/dist/recovery/infrastructure/folderClaims.d.ts +27 -0
- package/dist/recovery/infrastructure/folderClaims.js +124 -0
- package/dist/recovery/infrastructure/folderClaims.js.map +1 -0
- package/dist/shared/domain/session.d.ts +12 -0
- package/dist/shared/domain/session.js +2 -0
- package/dist/shared/domain/session.js.map +1 -0
- package/dist/tools/domain/preparedCall.d.ts +5 -2
- package/dist/tools/domain/preparedCall.js +7 -1
- package/dist/tools/domain/preparedCall.js.map +1 -1
- package/dist/tools/domain/readRegistry.d.ts +11 -0
- package/dist/tools/domain/readRegistry.js.map +1 -1
- package/dist/tools/infrastructure/agentAsTool.d.ts +6 -0
- package/dist/tools/infrastructure/agentAsTool.js +9 -0
- package/dist/tools/infrastructure/agentAsTool.js.map +1 -1
- package/dist/tools/infrastructure/commandTool.js +6 -1
- package/dist/tools/infrastructure/commandTool.js.map +1 -1
- package/dist/tools/infrastructure/exploreTool.js +2 -0
- package/dist/tools/infrastructure/exploreTool.js.map +1 -1
- package/dist/tools/infrastructure/fileTools.d.ts +2 -0
- package/dist/tools/infrastructure/fileTools.js +10 -1
- package/dist/tools/infrastructure/fileTools.js.map +1 -1
- package/dist/tools/infrastructure/removeWorktreeTool.d.ts +23 -0
- package/dist/tools/infrastructure/removeWorktreeTool.js +178 -0
- package/dist/tools/infrastructure/removeWorktreeTool.js.map +1 -0
- package/dist/tools/infrastructure/subagents.d.ts +3 -1
- package/dist/tools/infrastructure/subagents.js +2 -1
- package/dist/tools/infrastructure/subagents.js.map +1 -1
- package/dist/tools/infrastructure/trackedEdits.js +1 -0
- package/dist/tools/infrastructure/trackedEdits.js.map +1 -1
- package/dist/tools/infrastructure/workspaceWrites.d.ts +17 -1
- package/dist/tools/infrastructure/workspaceWrites.js +48 -17
- package/dist/tools/infrastructure/workspaceWrites.js.map +1 -1
- package/dist/tools/infrastructure/worktrees.d.ts +49 -0
- package/dist/tools/infrastructure/worktrees.js +154 -0
- package/dist/tools/infrastructure/worktrees.js.map +1 -0
- package/dist/tools/infrastructure/writeCeiling.d.ts +16 -0
- package/dist/tools/infrastructure/writeCeiling.js +49 -0
- package/dist/tools/infrastructure/writeCeiling.js.map +1 -0
- package/dist/tools/infrastructure/writeSession.d.ts +5 -1
- package/dist/tools/infrastructure/writeSession.js +7 -3
- package/dist/tools/infrastructure/writeSession.js.map +1 -1
- package/dist/workflow/domain/workflow.d.ts +3 -0
- package/dist/workflow/domain/workflow.js.map +1 -1
- package/dist/workflow/domain/workflowRunner.js +8 -2
- package/dist/workflow/domain/workflowRunner.js.map +1 -1
- package/package.json +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"llmAgent.js","sourceRoot":"","sources":["../../../../src/engines/domain/model/llmAgent.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,YAAY,GACZ,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAMN,cAAc,GACd,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACN,YAAY,EAEZ,UAAU,EACV,YAAY,EACZ,cAAc,GACd,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACN,uBAAuB,EACvB,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,GACf,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACN,mBAAmB,EACnB,oBAAoB,EACpB,uBAAuB,EACvB,eAAe,EACf,WAAW,GACX,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAG5D,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAuB,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAAc,WAAW,EAAqB,MAAM,4BAA4B,CAAC;AAExF,OAAO,EAGN,YAAY,EAGZ,WAAW,EACX,kBAAkB,EAClB,kBAAkB,GACl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I,UAAU,CAAC,YAAY,CAAC,CAAC;QAC/E,CAAC;IACF,CAAC;CACD","sourcesContent":["import {\n\ttype ApprovalDecision,\n\ttype ApprovalRequest,\n\ttype Approver,\n\treadDecision,\n} from '#src/agent/domain/approval';\nimport {\n\ttype Agent,\n\ttype AgentResponse,\n\ttype Callback,\n\ttype ProgressEvent,\n\ttype RunOptions,\n\tignoreProgress,\n} from '#src/agent/domain/agent';\nimport {\n\tdelegationOf,\n\ttype RunEnd,\n\tRunContext,\n\trunContextOf,\n\twithRunContext,\n} from '#src/agent/domain/runContext';\nimport {\n\tInvalidAgentConfigError,\n\tRecoverableError,\n\tUnrecoverableError,\n\twithSpentTokens,\n} from '#src/shared/domain/errors';\nimport {\n\tclassifyHostFailure,\n\tclassifyLocalFailure,\n\tclassifyProviderFailure,\n\tdescribeFailure,\n\ttreatErrors,\n} from '#src/shared/domain/providerFailure';\nimport { Conversation } from '#src/llm/domain/conversation';\nimport type { LLMClient, LLMResponse } from '#src/llm/domain/llm';\nimport type { Message, MessagePart, ToolCallPart, ToolResultPart } from '#src/llm/domain/message';\nimport { asNative, nativeOf, type ToolDefinition } from '#src/llm/domain/tool';\nimport { type Asker, readAnswers, type UserQuestion } from '#src/agent/domain/question';\nimport type { Transcript, TranscriptCallback } from '#src/agent/domain/transcript';\nimport {\n\ttype AgentTool,\n\ttype CommandEnding,\n\tisDelegating,\n\ttype PreparedCall,\n\ttype PreparedDelegation,\n\tprepareCall,\n\tRunEndingToolError,\n\tToolExecutionError,\n} from '#src/tools/domain/preparedCall';\nimport { ReadRegistry, type ToolCallContext } from '#src/tools/domain/readRegistry';\n\n/** What every tool call of one batch shares; each call adds its own id. */\ntype RunToolContext = Omit<ToolCallContext, 'callId'>;\nimport { InvalidToolInputError } from '#src/tools/domain/tool';\nimport { isAbortError } from '#src/shared/domain/isAbortError';\nimport type { ILogger } from '#src/shared/domain/logger';\nimport { addTokens, type Tokens } from '#src/shared/domain/tokens';\nimport {\n\tanotherAttempt,\n\taskAt,\n\tCommandLoops,\n\textensionNote,\n\tloopQuestion,\n\tloopStop,\n\tloopWarning,\n\trepeatedAnswersAt,\n\trepeatNote,\n\trepeatQuestion,\n\trepeatStop,\n\tstop,\n\twarnAt,\n} from './commandLoops.ts';\nimport { BackgroundAgents, sentNote } from './backgroundAgents.ts';\nimport { measureContext } from './stepContext.ts';\nimport {\n\taskUserDefinition,\n\taskUserName,\n\tdescribeAnswers,\n\treadQuestions,\n\tsummarizeQuestions,\n} from './askUser.ts';\nimport {\n\ttype Followed,\n\tfollowHistory,\n\ttype HistoryReader,\n\ttranscriptOf,\n\tundoNote,\n} from './historyFollower.ts';\n\nfunction describePart(part: MessagePart): ProgressEvent | undefined {\n\tswitch (part.type) {\n\t\tcase 'text':\n\t\t\treturn { type: 'agentMessage', message: part.text };\n\t\tcase 'reasoning':\n\t\t\treturn { type: 'reasoning', message: part.text };\n\t\tcase 'toolCall':\n\t\t\treturn { type: 'tool', id: part.id, name: part.name, status: 'in_progress' };\n\t\tcase 'toolResult':\n\t\t\treturn {\n\t\t\t\ttype: 'tool',\n\t\t\t\tid: part.callId,\n\t\t\t\tname: part.name,\n\t\t\t\tstatus: part.isError ? 'error' : 'completed',\n\t\t\t\t...(part.isError ? { error: part.output } : {}),\n\t\t\t};\n\t\tcase 'providerData':\n\t\t\t// Opaque by design: its readable side, if any, arrives as a reasoning part.\n\t\t\treturn undefined;\n\t\tcase 'compaction':\n\t\t\t// The provider's, for its client to send back; the step's context shows its effect.\n\t\t\treturn undefined;\n\t}\n}\n\n/**\n * Whether a run reached a tool's `execute`. A missing tool or a denied call never does, so it\n * has no effect a retry could repeat.\n */\ninterface RunEffects {\n\ttoolRan: boolean;\n}\n\n/** What a run has shown the model, for its transcript. */\ninterface Seen {\n\tmessages: () => Message[];\n\ttools: ToolDefinition[];\n}\n\nfunction narrate(part: MessagePart, callback: Callback, summary?: string, exitCode?: number): void {\n\tconst event = describePart(part);\n\tif (!event) return;\n\tif (event.type === 'tool') {\n\t\tif (summary !== undefined) event.summary = summary;\n\t\tif (exitCode !== undefined) event.exitCode = exitCode;\n\t}\n\temit(event, callback);\n}\n\nfunction emit(event: ProgressEvent, callback: Callback): void {\n\ttreatErrors(\n\t\t() => {\n\t\t\tcallback(event);\n\t\t},\n\t\tclassifyHostFailure,\n\t\t'LLM agent progress callback failed',\n\t);\n}\n\n/** `value` with the keys of every object sorted, so equal inputs serialize alike. */\nfunction canonical(value: unknown): unknown {\n\tif (Array.isArray(value)) return value.map(canonical);\n\tif (typeof value !== 'object' || value === null) return value;\n\treturn Object.fromEntries(\n\t\tObject.entries(value)\n\t\t\t.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))\n\t\t\t.map(([key, inner]) => [key, canonical(inner)]),\n\t);\n}\n\n/**\n * How many steps in a row have asked for exactly the same tool calls, with the same input. A\n * model that keeps asking is likely stuck: it already has what they return.\n */\nclass RepeatedCalls {\n\tprivate last: string | undefined;\n\tprivate times = 0;\n\n\t/** The user let the run go on: the count starts again. */\n\treset(): void {\n\t\tthis.times = 0;\n\t}\n\n\tcount(calls: readonly ToolCallPart[]): number {\n\t\t// Keys sorted at every level: the same input with its properties in another order is the\n\t\t// same call. Arrays, and the order of the calls, keep theirs.\n\t\tconst key = JSON.stringify(calls.map(call => [call.name, canonical(call.input)]));\n\t\tthis.times = key === this.last ? this.times + 1 : 1;\n\t\tthis.last = key;\n\t\treturn this.times;\n\t}\n}\n\n/** A call by its tool and input, its properties in any order. */\nfunction callKey(call: ToolCallPart): string {\n\treturn JSON.stringify([call.name, canonical(call.input)]);\n}\n\n// How a call the user is asked about is shown: its tool and input, cut short.\nconst shownCallCharacters = 300;\n\nfunction describeCall(call: ToolCallPart): string {\n\tconst text = `${call.name} ${JSON.stringify(canonical(call.input))}`;\n\treturn text.length > shownCallCharacters ? `${text.slice(0, shownCallCharacters)}…` : text;\n}\n\n/** The result of a call the run stopped before. */\nfunction notRun(call: ToolCallPart): ToolResultPart {\n\treturn {\n\t\ttype: 'toolResult',\n\t\tcallId: call.id,\n\t\tname: call.name,\n\t\toutput: 'Not run: the run stopped before it.',\n\t\tisError: true,\n\t};\n}\n\n/** The tool results, with `note` for the model after the last of them. */\nfunction withNote(message: Message, note: string): Message {\n\tconst last = message.content.at(-1);\n\tif (last?.type !== 'toolResult') return message;\n\treturn {\n\t\t...message,\n\t\tcontent: [...message.content.slice(0, -1), { ...last, output: `${last.output}\\n\\n${note}` }],\n\t};\n}\n\n/**\n * An agent whose conversation is owned by MiKode: every run sends the whole context to a\n * stateless `LLMClient`. Within a run the model may call the agent's tools; the agent runs them\n * and sends their results back until the model answers without calling one. Turn boundaries\n * are the consumer's to emit, as with the other engines; this agent only narrates what the\n * model produced and what its tools did.\n */\nexport class LLMAgent implements Agent {\n\tprivate readonly llmClient: LLMClient;\n\tprivate readonly conversation: Conversation;\n\tprivate readonly tools: Map<string, AgentTool>;\n\tprivate readonly toolDefinitions: ToolDefinition[];\n\t// Each call's summary, as its tool gave it when the call ran, so measuring a step that\n\t// resends the call never runs a consumer's summarizer again.\n\tprivate readonly callSummaries = new Map<string, string>();\n\tprivate readonly maxSteps: number;\n\tprivate readonly autoApprove: boolean;\n\tprivate readonly logger: ILogger | undefined;\n\tprivate readonly history: HistoryReader | undefined;\n\tprivate readonly summarizer: LLMClient | undefined;\n\tprivate readonly onTranscript: TranscriptCallback | undefined;\n\t// The latest move through the history this conversation has followed.\n\tprivate seenRevision = 0;\n\t// What this conversation has seen of each file, so an edit starts from a version it read.\n\tprivate readonly reads = new ReadRegistry();\n\n\tconstructor({\n\t\tllmClient,\n\t\tmessages,\n\t\ttools = [],\n\t\tmaxSteps = 65,\n\t\tautoApprove = false,\n\t\tlogger,\n\t\thistory,\n\t\tsummarizer,\n\t\tonTranscript,\n\t}: {\n\t\tllmClient: LLMClient;\n\t\tmessages?: Message[];\n\t\ttools?: AgentTool[];\n\t\t/** How many calls to the model one run may make before it fails. Defaults to 65. */\n\t\tmaxSteps?: number;\n\t\t/** Runs every tool call without asking, `destructive` ones included. Meant for CI. */\n\t\tautoApprove?: boolean;\n\t\t/** Where a failure the agent absorbs is reported. The factories always pass one. */\n\t\tlogger?: ILogger;\n\t\t/**\n\t\t * The history of the workspace this agent writes to. With it, each run first follows the\n\t\t * moves the user made through that history: the conversation goes back with the\n\t\t * workspace, and the model is told what was undone.\n\t\t */\n\t\thistory?: HistoryReader;\n\t\t/**\n\t\t * A cheap model that summarizes what the undone turns tried and what went wrong. Without\n\t\t * one, the model is told what those turns asked, word for word.\n\t\t */\n\t\tsummarizer?: LLMClient;\n\t\t/** Receives what the model saw in each run, once the run ended. */\n\t\tonTranscript?: TranscriptCallback;\n\t}) {\n\t\tif (!Number.isInteger(maxSteps) || maxSteps < 1) {\n\t\t\tthrow new InvalidAgentConfigError(\n\t\t\t\t`maxSteps must be a positive integer; got ${String(maxSteps)}`,\n\t\t\t);\n\t\t}\n\n\t\tthis.llmClient = llmClient;\n\t\tthis.conversation = new Conversation(messages);\n\t\tthis.maxSteps = maxSteps;\n\t\tthis.autoApprove = autoApprove;\n\t\tthis.logger = logger;\n\t\tthis.history = history;\n\t\tthis.summarizer = summarizer;\n\t\tthis.onTranscript = onTranscript;\n\t\tthis.tools = new Map(tools.map(tool => [tool.name, tool]));\n\t\tif (this.tools.size !== tools.length) {\n\t\t\t// The model calls tools by name, so a second one with the same name could never run.\n\t\t\tthrow new InvalidAgentConfigError('Two tools share a name; each name must be unique');\n\t\t}\n\t\t// The client only describes the tools to the model; running them stays with the agent.\n\t\tthis.toolDefinitions = tools.map(tool => {\n\t\t\tconst definition = {\n\t\t\t\tname: tool.name,\n\t\t\t\tdescription: tool.description,\n\t\t\t\tinputSchema: tool.inputSchema,\n\t\t\t};\n\t\t\tconst native = nativeOf(tool);\n\t\t\tif (native === undefined) return definition;\n\t\t\t// Checked now, not on the first call: an agent its client cannot serve is a setup error.\n\t\t\tif (llmClient.supportsNative?.(native) !== true) {\n\t\t\t\tthrow new InvalidAgentConfigError(\n\t\t\t\t\t`The tool \"${tool.name}\" is the native \"${native}\" tool, which this model client cannot declare`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn asNative(definition, native);\n\t\t});\n\t}\n\n\tprivate async followHistory(history: HistoryReader): Promise<Followed> {\n\t\ttry {\n\t\t\treturn await followHistory(this.conversation, history, this.seenRevision);\n\t\t} catch (error) {\n\t\t\tthrow classifyLocalFailure(error, 'The workspace history could not be read');\n\t\t}\n\t}\n\n\t/**\n\t * Asks the summarizer what the undone turns tried and what went wrong. A summary is a help,\n\t * not a need: one that fails is reported and the plain note is used instead.\n\t */\n\tprivate async summarizeUndone(\n\t\tfollowed: Followed,\n\t\tsignal: AbortSignal,\n\t): Promise<{ text?: string; usage?: Tokens; called: boolean }> {\n\t\tif (!this.summarizer) return { called: false };\n\t\tconst reasons = followed.revisions.flatMap(revision =>\n\t\t\trevision.reason ? [revision.reason] : [],\n\t\t);\n\t\tconst prompt = [\n\t\t\t'The user undid the work in the conversation below and moved the workspace back to before it.',\n\t\t\treasons.length > 0 ? `Their reason: ${reasons.map(reason => `«${reason}»`).join(' ')}` : '',\n\t\t\t'In at most five short lines, say what was tried, why it went wrong or why the user went back, and what could be done better. Plain text, no preamble.',\n\t\t\t'',\n\t\t\ttranscriptOf(this.conversation, followed.undone),\n\t\t].join('\\n');\n\n\t\tlet response: LLMResponse;\n\t\ttry {\n\t\t\tresponse = await this.summarizer.send(\n\t\t\t\t{ context: [{ role: 'user', content: [{ type: 'text', text: prompt }] }], tools: [] },\n\t\t\t\tsignal,\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tif (isAbortError(error)) throw error;\n\t\t\tthis.warnSummaryFailed(describeFailure(error));\n\t\t\treturn { called: true };\n\t\t}\n\n\t\tconst usage = response.usage ? { usage: response.usage } : {};\n\t\t// A refused or cut summary is not one: the model would read it as what was tried.\n\t\tif (response.stopReason !== 'completed') {\n\t\t\tthis.warnSummaryFailed(`the model stopped with \"${response.stopReason}\"`);\n\t\t\treturn { ...usage, called: true };\n\t\t}\n\t\tconst text = response.message.content\n\t\t\t.filter(part => part.type === 'text')\n\t\t\t.map(part => part.text)\n\t\t\t.join('\\n')\n\t\t\t.trim();\n\t\treturn { ...(text ? { text } : {}), ...usage, called: true };\n\t}\n\n\tprivate warnSummaryFailed(why: string): void {\n\t\ttreatErrors(\n\t\t\t() => {\n\t\t\t\tthis.logger?.warn(`The summary of the undone turns failed: ${why}`);\n\t\t\t},\n\t\t\tclassifyHostFailure,\n\t\t\t'LLM agent logger failed',\n\t\t);\n\t}\n\n\tprivate async llmCall(\n\t\trunMessages: Message[],\n\t\tafter: number | undefined,\n\t\t{\n\t\t\tsignal,\n\t\t\tstep,\n\t\t\tcallback,\n\t\t\ttools,\n\t\t}: { signal: AbortSignal; step: number; callback: Callback; tools: ToolDefinition[] },\n\t): Promise<{ response: LLMResponse; context: Message[] }> {\n\t\t// Sent as a copy, so what the run records is what the agent built, whatever the client does.\n\t\tconst context = [...this.conversation.contextAfter(after), ...structuredClone(runMessages)];\n\t\tlet response: LLMResponse;\n\t\ttry {\n\t\t\tresponse = await this.llmClient.send({ context, tools }, signal);\n\t\t} catch (error) {\n\t\t\tconst failure = classifyProviderFailure(error, 'The LLM call failed');\n\t\t\t// A client turns some answers into errors, such as a stop at the context window. The\n\t\t\t// call was billed, and the failure carries what it spent: it is still a step.\n\t\t\tif (\n\t\t\t\t(failure instanceof RecoverableError || failure instanceof UnrecoverableError) &&\n\t\t\t\t(failure.tokens !== undefined || failure.usageUnreported)\n\t\t\t) {\n\t\t\t\ttry {\n\t\t\t\t\tthis.narrateStep(step, failure.tokens, { context, tools }, callback);\n\t\t\t\t} catch (hostFailure) {\n\t\t\t\t\t// The callback's failure ends the run, and must carry this call's tokens too.\n\t\t\t\t\tthrow withSpentTokens(hostFailure, failure.tokens, failure.usageUnreported);\n\t\t\t\t}\n\t\t\t}\n\t\t\tthrow failure;\n\t\t}\n\n\t\treturn { response, context };\n\t}\n\n\tprivate narrateStep(\n\t\tstep: number,\n\t\ttokens: Tokens | undefined,\n\t\tsent: { context: Message[]; tools: ToolDefinition[] },\n\t\tcallback: Callback,\n\t) {\n\t\temit(\n\t\t\t{\n\t\t\t\ttype: 'step',\n\t\t\t\tstep,\n\t\t\t\t...(tokens ? { tokens } : {}),\n\t\t\t\tcontext: measureContext({\n\t\t\t\t\tinstructions: this.llmClient.systemPrompt,\n\t\t\t\t\tproviderDataSource: this.llmClient.providerDataSource,\n\t\t\t\t\ttools: sent.tools,\n\t\t\t\t\tcontext: sent.context,\n\t\t\t\t\tsummarize: call => this.callSummaries.get(call.id),\n\t\t\t\t}),\n\t\t\t},\n\t\t\tcallback,\n\t\t);\n\t}\n\n\t/**\n\t * Undefined when the call may run; otherwise why it may not, which the model receives in its\n\t * place. Only a `destructive` call is asked about: git can undo a `mutating` one. A throwing\n\t * approver ends the run, as any host callback does.\n\t */\n\tprivate async denial(\n\t\tcall: ToolCallPart,\n\t\tprepared: PreparedCall | PreparedDelegation,\n\t\tsignal: AbortSignal,\n\t\tapprove: Approver | undefined,\n\t): Promise<string | undefined> {\n\t\tconst { risk } = prepared;\n\t\tif (this.autoApprove || risk !== 'destructive') return undefined;\n\t\tconst command = 'command' in prepared ? prepared.command : undefined;\n\n\t\tconst retry = 'Do not retry the same call; choose another way, or ask the user.';\n\t\tif (!approve) {\n\t\t\treturn `The call to \"${call.name}\" was denied: it is destructive, and no one was asked to allow it. ${retry}`;\n\t\t}\n\n\t\tlet decision: ApprovalDecision;\n\t\ttry {\n\t\t\t// A copy, so what runs and what the conversation keeps is exactly what was approved.\n\t\t\tconst input: unknown = structuredClone(call.input);\n\t\t\t// Read inside the boundary: an untyped approver can answer anything, and a bad answer\n\t\t\t// is its failure, which must carry the run's tokens like any other.\n\t\t\tconst request: ApprovalRequest = {\n\t\t\t\ttool: call.name,\n\t\t\t\tinput,\n\t\t\t\trisk,\n\t\t\t\t// A copy too: the approver must not be able to change what runs.\n\t\t\t\t...(command ? { command: structuredClone(command) } : {}),\n\t\t\t};\n\t\t\tdecision = readDecision(await approve(request, signal));\n\t\t} catch (error) {\n\t\t\t// An approver that gives up on a cancellation, whatever it throws, did not fail.\n\t\t\tsignal.throwIfAborted();\n\t\t\tthrow classifyHostFailure(error, 'The tool call approver failed');\n\t\t}\n\t\t// The user may cancel the run while they are being asked.\n\t\tsignal.throwIfAborted();\n\t\tif (decision.approved) return undefined;\n\n\t\tconst reason = decision.reason ? ` Their reason: ${decision.reason}` : '';\n\t\treturn `The user denied the call to \"${call.name}\".${reason} ${retry}`;\n\t}\n\n\t/**\n\t * Always answers the call: a missing tool, a denied call or a failing one becomes an error\n\t * result, so the model can correct itself. Only a cancellation, a failing approver, or host\n\t * code that failed inside the call escapes. A call that hands tasks to agents answers once\n\t * it sent them, and `background` watches them from then on.\n\t */\n\tprivate async runTool(\n\t\tcall: ToolCallPart,\n\t\t{ signal, onProgress: callback = ignoreProgress, approve, ask }: RunOptions,\n\t\teffects: RunEffects,\n\t\ttoolCall: RunToolContext,\n\t\tbackground: BackgroundAgents,\n\t): Promise<{\n\t\tresult: ToolResultPart;\n\t\tdenied: boolean;\n\t\tdiff?: string;\n\t\tsummary?: string;\n\t\texitCode?: number;\n\t\tending?: CommandEnding;\n\t\t// It sent agents to work in the background.\n\t\tsent?: boolean;\n\t\t// It ran, and may have changed files the history does not record.\n\t\tunrecorded?: boolean;\n\t}> {\n\t\tconst result = { type: 'toolResult' as const, callId: call.id, name: call.name };\n\t\tsignal.throwIfAborted();\n\t\tif (call.name === askUserName && ask && !this.tools.has(askUserName)) {\n\t\t\treturn this.askUser(call, ask, signal, callback);\n\t\t}\n\t\tconst tool = this.tools.get(call.name);\n\t\tif (!tool) {\n\t\t\treturn {\n\t\t\t\tresult: {\n\t\t\t\t\t...result,\n\t\t\t\t\toutput: `There is no tool named \"${call.name}\". Available tools: ${[...this.tools.keys()].join(', ') || 'none'}.`,\n\t\t\t\t\tisError: true,\n\t\t\t\t},\n\t\t\t\tdenied: false,\n\t\t\t};\n\t\t}\n\n\t\tlet summary: string | undefined;\n\t\ttry {\n\t\t\t// This is deliberately before preparation and approval. A consumer-supplied\n\t\t\t// summarizer is host code, and a failed one must never leave an ambiguous call that\n\t\t\t// could be replayed by RetryingAgent.\n\t\t\tsummary = tool.summarize?.(call.input);\n\t\t\tif (summary !== undefined) this.callSummaries.set(call.id, summary);\n\t\t} catch (error) {\n\t\t\tsignal.throwIfAborted();\n\t\t\tif (error instanceof InvalidToolInputError) {\n\t\t\t\treturn {\n\t\t\t\t\tresult: { ...result, output: describeFailure(error), isError: true },\n\t\t\t\t\tdenied: false,\n\t\t\t\t};\n\t\t\t}\n\t\t\tthrow classifyHostFailure(error, 'The tool call summarizer failed');\n\t\t}\n\n\t\tlet prepared: PreparedCall | PreparedDelegation;\n\t\ttry {\n\t\t\tconst context = { ...toolCall, callId: call.id };\n\t\t\tprepared = isDelegating(tool)\n\t\t\t\t? await tool.delegate(call.input, signal, context)\n\t\t\t\t: await prepareCall(tool, call.input, signal, context);\n\t\t} catch (error) {\n\t\t\tsignal.throwIfAborted();\n\t\t\t// A call that cannot be prepared, or whose tool cannot judge it, does not run; the\n\t\t\t// model reads why, such as a refused path, and can correct itself.\n\t\t\treturn {\n\t\t\t\tresult: { ...result, output: describeFailure(error), isError: true },\n\t\t\t\tdenied: false,\n\t\t\t\t...(summary === undefined ? {} : { summary }),\n\t\t\t};\n\t\t}\n\n\t\t// Preparing may have finished after a cancellation it did not notice; nobody is asked to\n\t\t// approve a call in a run that has already stopped.\n\t\tsignal.throwIfAborted();\n\t\tconst denial = await this.denial(call, prepared, signal, approve);\n\t\tif (denial !== undefined) {\n\t\t\treturn {\n\t\t\t\tresult: { ...result, output: denial, isError: true },\n\t\t\t\tdenied: true,\n\t\t\t\t...(summary === undefined ? {} : { summary }),\n\t\t\t};\n\t\t}\n\n\t\t// Deciding took at least one await, and the run may have been cancelled meanwhile.\n\t\tsignal.throwIfAborted();\n\t\t// Announced only once it will run: a missing, failing-to-judge or denied call never is.\n\t\temit(\n\t\t\t{\n\t\t\t\ttype: 'tool',\n\t\t\t\tid: call.id,\n\t\t\t\tname: call.name,\n\t\t\t\tstatus: 'in_progress',\n\t\t\t\t...(summary === undefined ? {} : { summary }),\n\t\t\t},\n\t\t\tcallback,\n\t\t);\n\t\t// Checked again at the last moment: the consumer may cancel on the announcement itself.\n\t\tsignal.throwIfAborted();\n\t\t// Set before `execute`, so a tool that fails halfway still counts: it may have had effects.\n\t\teffects.toolRan = true;\n\t\tconst unrecorded = prepared.unrecorded === true && prepared.risk !== 'safe';\n\t\tif ('start' in prepared) {\n\t\t\t// Before its agents start, so the person watching reads it before anything they narrate.\n\t\t\temit(\n\t\t\t\t{\n\t\t\t\t\ttype: 'tool',\n\t\t\t\t\tid: call.id,\n\t\t\t\t\tname: call.name,\n\t\t\t\t\tstatus: 'sent',\n\t\t\t\t\t...(summary === undefined ? {} : { summary }),\n\t\t\t\t},\n\t\t\t\tcallback,\n\t\t\t);\n\t\t\tconst agents = prepared.start(background.signal);\n\t\t\tbackground.add(call.id, agents, unrecorded);\n\t\t\treturn {\n\t\t\t\tresult: { ...result, output: sentNote(agents), isError: false },\n\t\t\t\tdenied: false,\n\t\t\t\tsent: true,\n\t\t\t\tunrecorded,\n\t\t\t\t...(summary === undefined ? {} : { summary }),\n\t\t\t};\n\t\t}\n\t\ttry {\n\t\t\tconst output = await prepared.run(signal);\n\t\t\tconst ending = prepared.ending?.();\n\t\t\treturn {\n\t\t\t\tresult: { ...result, output, isError: false },\n\t\t\t\tdenied: false,\n\t\t\t\tunrecorded,\n\t\t\t\t...(summary === undefined ? {} : { summary }),\n\t\t\t\t...(prepared.diff === undefined ? {} : { diff: prepared.diff }),\n\t\t\t\t...(ending === undefined ? {} : { ending }),\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tsignal.throwIfAborted();\n\t\t\tif (error instanceof RunEndingToolError) throw error.failure;\n\t\t\tconst ending = prepared.ending?.();\n\t\t\treturn {\n\t\t\t\tresult: { ...result, output: describeFailure(error), isError: true },\n\t\t\t\tdenied: false,\n\t\t\t\tunrecorded,\n\t\t\t\t...(summary === undefined ? {} : { summary }),\n\t\t\t\t...(error instanceof ToolExecutionError && error.exitCode !== undefined\n\t\t\t\t\t? { exitCode: error.exitCode }\n\t\t\t\t\t: {}),\n\t\t\t\t...(ending === undefined ? {} : { ending }),\n\t\t\t};\n\t\t}\n\t}\n\n\t/**\n\t * Asks the user through the run's `ask`. Questions the model wrote wrong go back to it, to\n\t * correct; an asker that fails or answers wrongly is host code, and ends the run.\n\t */\n\tprivate async askUser(\n\t\tcall: ToolCallPart,\n\t\task: Asker,\n\t\tsignal: AbortSignal,\n\t\tcallback: Callback,\n\t): Promise<{ result: ToolResultPart; denied: boolean; summary?: string }> {\n\t\tconst result = { type: 'toolResult' as const, callId: call.id, name: call.name };\n\t\tconst questions = readQuestions(call.input);\n\t\tif (typeof questions === 'string') {\n\t\t\treturn { result: { ...result, output: questions, isError: true }, denied: false };\n\t\t}\n\t\tconst summary = summarizeQuestions(questions);\n\t\tthis.callSummaries.set(call.id, summary);\n\t\temit({ type: 'tool', id: call.id, name: call.name, status: 'in_progress', summary }, callback);\n\t\tsignal.throwIfAborted();\n\n\t\tlet answers: unknown;\n\t\ttry {\n\t\t\tanswers = await ask(questions, signal);\n\t\t} catch (error) {\n\t\t\tsignal.throwIfAborted();\n\t\t\tthrow classifyHostFailure(error, 'The asker failed');\n\t\t}\n\t\t// An answer that arrives after a cancellation is not given to the model.\n\t\tsignal.throwIfAborted();\n\t\tconst read = readAnswers(answers, questions);\n\t\tif (!read) {\n\t\t\tthrow new UnrecoverableError('The asker failed', {\n\t\t\t\tcause: `It must answer each of the ${String(questions.length)} questions with some text, in order.`,\n\t\t\t});\n\t\t}\n\t\treturn {\n\t\t\tresult: { ...result, output: describeAnswers(questions, read), isError: false },\n\t\t\tdenied: false,\n\t\t\tsummary,\n\t\t};\n\t}\n\n\t/**\n\t * One at a time and in order, so their effects and their narration never interleave. Agents a\n\t * call hands tasks to keep working in the background once it answered.\n\t */\n\tprivate async runTools(\n\t\tcalls: ToolCallPart[],\n\t\toptions: RunOptions,\n\t\teffects: RunEffects,\n\t\ttoolCall: RunToolContext,\n\t\t// Throws the failure of a progress callback a call narrated through.\n\t\tthrowIfProgressFailed: () => void,\n\t\tloops: CommandLoops,\n\t\tbackground: BackgroundAgents,\n\t): Promise<{ message: Message; stopped?: UnrecoverableError }> {\n\t\tconst { signal } = options;\n\t\tconst results: MessagePart[] = [];\n\t\tfor (const [index, call] of calls.entries()) {\n\t\t\t// A call before this one may have ignored the cancellation; this one must not start,\n\t\t\t// nor be announced as running.\n\t\t\tsignal.throwIfAborted();\n\t\t\t// `runTool` announces the call only once it is allowed to run, so a consumer never\n\t\t\t// shows a call as running early, nor while the user is still being asked.\n\t\t\tconst ran = await this.runTool(call, options, effects, toolCall, background);\n\t\t\t// A call that failed to narrate ends the run before the next one can start.\n\t\t\tthrowIfProgressFailed();\n\t\t\t// An agent at work since the last call may have changed what the history cannot copy.\n\t\t\tif (background.mayHaveChangedUnseen()) loops.unrecordedCallRan();\n\t\t\tconst settled = this.settle(call, ran, loops, options);\n\t\t\tlet { result } = settled;\n\t\t\tconst { alike, key, label } = settled;\n\t\t\t// After its result is narrated, so the user is asked about the ending they have seen.\n\t\t\tif (alike !== undefined && alike.times >= askAt) {\n\t\t\t\tconst decision = await this.decideOnLoop(\n\t\t\t\t\t{\n\t\t\t\t\t\tquestion: loopQuestion(label, alike),\n\t\t\t\t\t\tfailure: 'The LLM kept getting the same result from a command',\n\t\t\t\t\t\tstopped: reason => loopStop(label, alike, reason),\n\t\t\t\t\t\tnote: words => extensionNote(alike, words),\n\t\t\t\t\t},\n\t\t\t\t\t() => loops.extend([key]),\n\t\t\t\t\toptions,\n\t\t\t\t);\n\t\t\t\tif (typeof decision !== 'string') {\n\t\t\t\t\t// So the next run's model reads why this one ended where it did.\n\t\t\t\t\tresults.push({\n\t\t\t\t\t\t...result,\n\t\t\t\t\t\toutput: `${result.output}\\n\\nThe run stopped here: ${decision.cause}`,\n\t\t\t\t\t});\n\t\t\t\t\t// The calls after it never run, but each still gets a result, so the run that is\n\t\t\t\t\t// kept has none without one.\n\t\t\t\t\tresults.push(...calls.slice(index + 1).map(notRun));\n\t\t\t\t\treturn { message: { role: 'tool', content: results }, stopped: decision };\n\t\t\t\t}\n\t\t\t\tresult = { ...result, output: `${result.output}\\n\\n${decision}` };\n\t\t\t}\n\t\t\tresults.push(result);\n\t\t}\n\n\t\treturn { message: { role: 'tool', content: results } };\n\t}\n\n\t/**\n\t * Narrates how a call ended and notes its command's ending, with the warning for the model\n\t * when that ending keeps coming back alike.\n\t */\n\tprivate settle(\n\t\tcall: ToolCallPart,\n\t\tran: Awaited<ReturnType<LLMAgent['runTool']>>,\n\t\tloops: CommandLoops,\n\t\t{ onProgress: callback = ignoreProgress, ask }: RunOptions,\n\t): {\n\t\tresult: ToolResultPart;\n\t\talike: ReturnType<CommandLoops['observe']> | undefined;\n\t\tkey: string;\n\t\tlabel: string;\n\t} {\n\t\tconst { denied, diff, summary, exitCode, ending, sent } = ran;\n\t\tlet { result } = ran;\n\t\tif (ran.unrecorded) loops.unrecordedCallRan();\n\t\tconst key = callKey(call);\n\t\tconst label = summary ?? call.name;\n\t\tconst alike = ending === undefined ? undefined : loops.observe(key, ending);\n\t\t// A command that changed what the history cannot copy hides that change from the next.\n\t\tif (ending !== undefined && ending.state === undefined) loops.unrecordedCallRan();\n\t\t// Narrated with it, so the person watching reads what the model is told.\n\t\tif (alike?.times === warnAt) {\n\t\t\tresult = {\n\t\t\t\t...result,\n\t\t\t\toutput: `${result.output}\\n\\n${loopWarning(label, alike, ask !== undefined && !loops.wentOn)}`,\n\t\t\t};\n\t\t}\n\t\tif (denied) {\n\t\t\temit(\n\t\t\t\t{\n\t\t\t\t\ttype: 'tool',\n\t\t\t\t\tid: call.id,\n\t\t\t\t\tname: call.name,\n\t\t\t\t\tstatus: 'denied',\n\t\t\t\t\t...(summary === undefined ? {} : { summary }),\n\t\t\t\t},\n\t\t\t\tcallback,\n\t\t\t);\n\t\t} else if (sent === true) {\n\t\t\t// Narrated as it sent its agents, which go on after it until each one ends.\n\t\t}\n\t\t// The diff of a change it made, for the person watching; only once it was made.\n\t\telse if (diff !== undefined) {\n\t\t\temit(\n\t\t\t\t{\n\t\t\t\t\ttype: 'tool',\n\t\t\t\t\tid: call.id,\n\t\t\t\t\tname: call.name,\n\t\t\t\t\tstatus: 'completed',\n\t\t\t\t\tdiff,\n\t\t\t\t\t...(summary === undefined ? {} : { summary }),\n\t\t\t\t},\n\t\t\t\tcallback,\n\t\t\t);\n\t\t} else narrate(result, callback, summary, exitCode);\n\t\treturn { result, alike, key, label };\n\t}\n\n\t/**\n\t * On a loop found, the fifth ending alike of a command or the fifth answer in a row asking for\n\t * the same calls: the note for the model if the user lets the run go on, or the failure that\n\t * stops it. The run goes on once at most, and never without someone to ask.\n\t */\n\tprivate async decideOnLoop(\n\t\tloop: {\n\t\t\tquestion: UserQuestion;\n\t\t\tfailure: string;\n\t\t\tstopped: (reason: string) => string;\n\t\t\tnote: (words?: string) => string;\n\t\t},\n\t\textend: () => boolean,\n\t\t{ ask, signal }: RunOptions,\n\t): Promise<string | UnrecoverableError> {\n\t\tconst stopped = (reason: string) =>\n\t\t\tnew UnrecoverableError(loop.failure, { cause: loop.stopped(reason) });\n\t\tif (!ask) return stopped('No one could be asked whether to go on.');\n\t\tif (!extend()) return stopped('The user had already let the run go on once.');\n\n\t\tconst questions = [loop.question];\n\t\tlet answers: unknown;\n\t\ttry {\n\t\t\tanswers = await ask(questions, signal);\n\t\t} catch (error) {\n\t\t\tsignal.throwIfAborted();\n\t\t\tthrow classifyHostFailure(error, 'The asker failed');\n\t\t}\n\t\t// An answer that arrives after a cancellation is not acted on.\n\t\tsignal.throwIfAborted();\n\t\tconst [answer] = readAnswers(answers, questions) ?? [];\n\t\tif (answer === undefined) {\n\t\t\tthrow new UnrecoverableError('The asker failed', {\n\t\t\t\tcause: 'It must answer the question with some text.',\n\t\t\t});\n\t\t}\n\t\tif (answer === stop) return stopped('The user stopped it.');\n\t\treturn loop.note(answer === anotherAttempt ? undefined : answer);\n\t}\n\n\t/**\n\t * Runs inside the context of the run that reached it, or in one of its own that it ends with\n\t * the run: completed, failed or cancelled. Only a run that owns its context names the history\n\t * run it recorded, since the run is over only when that context ends.\n\t */\n\tasync run(prompt: string, options: RunOptions): Promise<AgentResponse> {\n\t\tconst inherited = runContextOf(options);\n\t\tif (inherited) return this.runSteps(prompt, options, inherited);\n\n\t\tconst context = new RunContext();\n\t\tlet end: RunEnd = 'failed';\n\t\tlet response: AgentResponse;\n\t\ttry {\n\t\t\tresponse = await this.runSteps(prompt, withRunContext(options, context), context);\n\t\t\tend = 'completed';\n\t\t} catch (error) {\n\t\t\tif (isAbortError(error)) end = 'cancelled';\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tawait this.finishContext(context, end);\n\t\t}\n\t\t// Read once the run ended: a run that changed nothing left the history then.\n\t\tconst { runId } = context.historyRun;\n\t\treturn runId ? { ...response, runId } : response;\n\t}\n\n\t/**\n\t * What the run started ends here, but its result stands: the changes it recorded are already\n\t * on disk, so a record that could not be closed is reported, not turned into a failure.\n\t */\n\tprivate async finishContext(context: RunContext, end: RunEnd): Promise<void> {\n\t\ttry {\n\t\t\tawait context.finish(end);\n\t\t} catch (error) {\n\t\t\ttreatErrors(\n\t\t\t\t() => {\n\t\t\t\t\tthis.logger?.warn(`The run could not close its records: ${describeFailure(error)}`);\n\t\t\t\t},\n\t\t\t\tclassifyHostFailure,\n\t\t\t\t'LLM agent logger failed',\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate async runSteps(\n\t\tprompt: string,\n\t\toptions: RunOptions,\n\t\tcontext: RunContext,\n\t): Promise<AgentResponse> {\n\t\tconst seen: Seen = { messages: () => [], tools: this.toolDefinitions };\n\t\tlet response: AgentResponse;\n\t\ttry {\n\t\t\tresponse = await this.takeSteps(prompt, options, context, seen);\n\t\t} catch (error) {\n\t\t\tawait this.transcribe(seen, options, isAbortError(error) ? 'cancelled' : 'failed', error);\n\t\t\tthrow error;\n\t\t}\n\t\tawait this.transcribe(seen, options, 'completed');\n\t\treturn response;\n\t}\n\n\t/** Hands the run's transcript to the consumer, whose failure is logged, not the run's. */\n\tprivate async transcribe(\n\t\tseen: Seen,\n\t\toptions: RunOptions,\n\t\toutcome: Transcript['outcome'],\n\t\terror?: unknown,\n\t): Promise<void> {\n\t\tif (!this.onTranscript) return;\n\t\tconst delegation = delegationOf(options);\n\t\ttry {\n\t\t\t// A copy, so a consumer that changes it cannot change the agent's tools or conversation.\n\t\t\tconst content: unknown = structuredClone({\n\t\t\t\tinstructions: this.llmClient.systemPrompt,\n\t\t\t\ttools: seen.tools.map(({ name, description, inputSchema }) => ({\n\t\t\t\t\tname,\n\t\t\t\t\tdescription,\n\t\t\t\t\tinputSchema,\n\t\t\t\t})),\n\t\t\t\tmessages: seen.messages(),\n\t\t\t\t...(outcome === 'completed' ? {} : { error: describeFailure(error) }),\n\t\t\t});\n\t\t\tawait this.onTranscript({\n\t\t\t\t...(delegation\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tdelegation: {\n\t\t\t\t\t\t\t\ttool: delegation.tool,\n\t\t\t\t\t\t\t\tcallId: delegation.callId,\n\t\t\t\t\t\t\t\tsubagent: delegation.subagent,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t\toutcome,\n\t\t\t\tcontent,\n\t\t\t});\n\t\t} catch (failure) {\n\t\t\ttreatErrors(\n\t\t\t\t() => {\n\t\t\t\t\tthis.logger?.warn(\n\t\t\t\t\t\t`The run's transcript could not be handed over: ${describeFailure(failure)}`,\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\tclassifyHostFailure,\n\t\t\t\t'LLM agent logger failed',\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate async takeSteps(\n\t\tprompt: string,\n\t\toptions: RunOptions,\n\t\tcontext: RunContext,\n\t\tseen: Seen,\n\t): Promise<AgentResponse> {\n\t\tconst { signal, onProgress: callback = ignoreProgress } = options;\n\t\t// A tool narrates through this without ever failing: a failing callback would reach\n\t\t// only the tool, which turns any failure into a result for the model. The run ends on\n\t\t// it once that tool returns.\n\t\tlet progressFailure: { error: unknown } | undefined;\n\t\tconst onProgress = (event: ProgressEvent) => {\n\t\t\tif (progressFailure) return;\n\t\t\ttry {\n\t\t\t\temit(event, callback);\n\t\t\t} catch (error) {\n\t\t\t\tprogressFailure = { error };\n\t\t\t}\n\t\t};\n\t\t// The agents the run's calls send to work in the background.\n\t\tconst background = new BackgroundAgents(signal, onProgress);\n\t\tconst start = Date.now();\n\t\tconst runMessages: Message[] = [{ role: 'user', content: [{ type: 'text', text: prompt }] }];\n\t\tlet tokens: Tokens | undefined;\n\t\t// Once one call went unreported the run's total is unknown, however many report later.\n\t\tlet unreported = false;\n\t\t// Per run, not per instance: what one run executed says nothing about another.\n\t\tconst effects: RunEffects = { toolRan: false };\n\t\t// The turn this one follows: the last recorded, unless the workspace moved since.\n\t\tlet after = this.conversation.currentTurn;\n\t\tlet followed: Followed | undefined;\n\t\t// What the model has seen so far, whichever turn the run ends up following.\n\t\tseen.messages = () => [...this.conversation.contextAfter(after), ...runMessages];\n\n\t\ttry {\n\t\t\tif (this.history) {\n\t\t\t\tfollowed = await this.followHistory(this.history);\n\t\t\t\tafter = followed.turn;\n\t\t\t\t// The files may no longer hold what the conversation saw of them.\n\t\t\t\tif (followed.revisions.length > 0) this.reads.clear();\n\t\t\t\tif (followed.undone.length > 0) {\n\t\t\t\t\tconst summary = await this.summarizeUndone(followed, signal);\n\t\t\t\t\ttokens = addTokens(tokens, summary.usage);\n\t\t\t\t\tunreported ||= summary.called && !summary.usage;\n\t\t\t\t\tconst note = await undoNote({\n\t\t\t\t\t\tconversation: this.conversation,\n\t\t\t\t\t\thistory: this.history,\n\t\t\t\t\t\tfollowed,\n\t\t\t\t\t\t...(summary.text ? { summary: summary.text } : {}),\n\t\t\t\t\t}).catch((error: unknown) => {\n\t\t\t\t\t\tthrow classifyLocalFailure(error, 'The workspace history could not be read');\n\t\t\t\t\t});\n\t\t\t\t\trunMessages[0]?.content.unshift({ type: 'text', text: note });\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// After following the history, which may have made every earlier read stale.\n\t\t\tconst reads = this.reads.begin();\n\t\t\tconst repeats = new RepeatedCalls();\n\t\t\tconst loops = new CommandLoops();\n\t\t\t// A tool that does its own work on the model, such as running subagents, counts it here.\n\t\t\tconst spend = (spent: Tokens | undefined, unreportedCall: boolean) => {\n\t\t\t\ttokens = addTokens(tokens, spent);\n\t\t\t\tunreported ||= unreportedCall;\n\t\t\t};\n\t\t\t// Also ends the run at its next boundary when an agent at work failed in a way that ends it.\n\t\t\tconst throwIfProgressFailed = () => {\n\t\t\t\tif (progressFailure) throw progressFailure.error;\n\t\t\t\tbackground.throwIfEnded();\n\t\t\t};\n\t\t\t// The agent's own `askUser` exists only for a run someone can answer, and never beside\n\t\t\t// a consumer's tool of that name, which the consumer gave first and which stays theirs.\n\t\t\tconst offersAsk = options.ask !== undefined && !this.tools.has(askUserName);\n\t\t\tconst tools = offersAsk ? [...this.toolDefinitions, askUserDefinition] : this.toolDefinitions;\n\t\t\tseen.tools = tools;\n\t\t\t// Recorded only once the run ends in a way that keeps it, so it never leaves a tool call\n\t\t\t// without its result; a run that is not kept gives its note on what was undone again.\n\t\t\tconst remember = () => {\n\t\t\t\tthis.conversation.addRunAfter(after, runMessages, context.historyRun);\n\t\t\t\t// With the turns that read them, and only then.\n\t\t\t\treads.commit();\n\t\t\t\tif (followed) this.seenRevision = followed.latestRevision;\n\t\t\t};\n\t\t\t// A run kept although it failed stops its agents first, and tells the next run what\n\t\t\t// became of each one, which would otherwise wait for answers that never come.\n\t\t\tconst keepFailed = async () => {\n\t\t\t\tawait background.stop();\n\t\t\t\tconst ended = background.takeAnswers();\n\t\t\t\tif (ended) runMessages.push(ended);\n\t\t\t\tremember();\n\t\t\t};\n\t\t\tfor (let step = 1; step <= this.maxSteps; step++) {\n\t\t\t\t// An agent at work may have narrated through a callback that failed.\n\t\t\t\tthrowIfProgressFailed();\n\t\t\t\tconst { response, context: sent } = await this.llmCall(runMessages, after, {\n\t\t\t\t\tsignal,\n\t\t\t\t\tstep,\n\t\t\t\t\tcallback,\n\t\t\t\t\ttools,\n\t\t\t\t});\n\t\t\t\ttokens = addTokens(tokens, response.usage);\n\t\t\t\tunreported ||= !response.usage;\n\t\t\t\t// After the tokens are counted, so a throwing callback still reports them, and for an\n\t\t\t\t// unusable answer too: the call was sent, and billed.\n\t\t\t\tthis.narrateStep(step, response.usage, { context: sent, tools }, callback);\n\t\t\t\tthrowIfProgressFailed();\n\t\t\t\tif (response.stopReason === 'truncated') {\n\t\t\t\t\t// What it wrote before the output limit, kept with the run so the next run can\n\t\t\t\t\t// take it up. Not its calls, whose input may be cut, nor what only the provider\n\t\t\t\t\t// reads back, which it may refuse incomplete.\n\t\t\t\t\tconst written = response.message.content.filter(\n\t\t\t\t\t\tpart => part.type === 'text' || part.type === 'reasoning',\n\t\t\t\t\t);\n\t\t\t\t\tfor (const part of written) narrate(part, callback);\n\t\t\t\t\tif (written.length > 0) runMessages.push({ role: 'assistant', content: written });\n\t\t\t\t\tawait keepFailed();\n\t\t\t\t\tthrow new UnrecoverableError('The LLM stopped before completing its answer', {\n\t\t\t\t\t\tcause:\n\t\t\t\t\t\t\t'The model stopped with \"truncated\". The run, and what the answer held before the limit, are kept in the conversation.',\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tif (response.stopReason !== 'completed') {\n\t\t\t\t\t// Its tokens are already counted with the run's, which the failure carries. A run\n\t\t\t\t\t// that ends so is not remembered.\n\t\t\t\t\tthrow new UnrecoverableError('The LLM stopped before completing its answer', {\n\t\t\t\t\t\tcause: `The model stopped with \"${response.stopReason}\".`,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\trunMessages.push(response.message);\n\n\t\t\t\t// Tool calls are narrated as they start, in `runTools`, and never if they do not run.\n\t\t\t\tfor (const part of response.message.content) {\n\t\t\t\t\tif (part.type !== 'toolCall') narrate(part, callback);\n\t\t\t\t}\n\n\t\t\t\tconst calls = response.message.content.filter(part => part.type === 'toolCall');\n\t\t\t\tif (calls.length === 0) {\n\t\t\t\t\t// An answer given while agents work, or before the model read what they answered,\n\t\t\t\t\t// is a wait: the model goes on with their answers.\n\t\t\t\t\tlet answers = background.takeAnswers();\n\t\t\t\t\tif (!answers && background.working && step < this.maxSteps) {\n\t\t\t\t\t\tawait background.nextAnswer();\n\t\t\t\t\t\tthrowIfProgressFailed();\n\t\t\t\t\t\tanswers = background.takeAnswers();\n\t\t\t\t\t}\n\t\t\t\t\tif (answers || background.working) {\n\t\t\t\t\t\tif (step === this.maxSteps) {\n\t\t\t\t\t\t\tthrow new UnrecoverableError('The LLM did not finish within its step limit', {\n\t\t\t\t\t\t\t\tcause: `The model was still waiting for the agents it sent after ${String(this.maxSteps)} steps.`,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (answers) runMessages.push(answers);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tremember();\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\t// Only the final answer: text from earlier steps was narrated as it came.\n\t\t\t\t\t\tresponse: response.message.content\n\t\t\t\t\t\t\t.filter(part => part.type === 'text')\n\t\t\t\t\t\t\t.map(part => part.text)\n\t\t\t\t\t\t\t.join('\\n'),\n\t\t\t\t\t\ttokens: unreported || background.usageUnknown ? undefined : tokens,\n\t\t\t\t\t\tduration: (Date.now() - start) / 1000,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\t// Before running them again: the model has already seen what they return.\n\t\t\t\tlet repeatedNote: string | undefined;\n\t\t\t\t// Not on the last step, whose calls never run: there is nothing to let go on.\n\t\t\t\tif (step < this.maxSteps && repeats.count(calls) >= repeatedAnswersAt) {\n\t\t\t\t\tconst decision = await this.decideOnLoop(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tquestion: repeatQuestion(calls.map(describeCall).join('\\n')),\n\t\t\t\t\t\t\tfailure: 'The LLM repeated the same tool calls',\n\t\t\t\t\t\t\tstopped: repeatStop,\n\t\t\t\t\t\t\tnote: repeatNote,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t() => loops.extend(calls.map(callKey)),\n\t\t\t\t\t\toptions,\n\t\t\t\t\t);\n\t\t\t\t\tif (typeof decision !== 'string') {\n\t\t\t\t\t\t// Kept like a run stopped on a command, every call given a result.\n\t\t\t\t\t\tconst [first, ...rest] = calls.map(notRun);\n\t\t\t\t\t\trunMessages.push({\n\t\t\t\t\t\t\trole: 'tool',\n\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t...(first\n\t\t\t\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t...first,\n\t\t\t\t\t\t\t\t\t\t\t\toutput: `Not run: the run stopped here. ${decision.cause}`,\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t\t\t: []),\n\t\t\t\t\t\t\t\t...rest,\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t});\n\t\t\t\t\t\tawait keepFailed();\n\t\t\t\t\t\tthrow decision;\n\t\t\t\t\t}\n\t\t\t\t\trepeats.reset();\n\t\t\t\t\trepeatedNote = decision;\n\t\t\t\t}\n\n\t\t\t\t// On the last step no call is left to send the results to, so the tools do not run.\n\t\t\t\tif (step < this.maxSteps) {\n\t\t\t\t\tconst { message, stopped } = await this.runTools(\n\t\t\t\t\t\tcalls,\n\t\t\t\t\t\toptions,\n\t\t\t\t\t\teffects,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\trun: context,\n\t\t\t\t\t\t\treads,\n\t\t\t\t\t\t\tonProgress,\n\t\t\t\t\t\t\tspend,\n\t\t\t\t\t\t\tdepth: delegationOf(options)?.depth ?? 0,\n\t\t\t\t\t\t\t...(options.approve ? { approve: options.approve } : {}),\n\t\t\t\t\t\t\t...(options.ask ? { ask: options.ask } : {}),\n\t\t\t\t\t\t},\n\t\t\t\t\t\tthrowIfProgressFailed,\n\t\t\t\t\t\tloops,\n\t\t\t\t\t\tbackground,\n\t\t\t\t\t);\n\t\t\t\t\trunMessages.push(repeatedNote === undefined ? message : withNote(message, repeatedNote));\n\t\t\t\t\t// Kept like a run cut by the output limit: the user may take it up.\n\t\t\t\t\tif (stopped) {\n\t\t\t\t\t\tawait keepFailed();\n\t\t\t\t\t\tthrow stopped;\n\t\t\t\t\t}\n\t\t\t\t\t// What agents answered meanwhile, after the results the model is waiting for.\n\t\t\t\t\tconst answers = background.takeAnswers();\n\t\t\t\t\tif (answers) runMessages.push(answers);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthrow new UnrecoverableError('The LLM did not finish within its step limit', {\n\t\t\t\tcause: `The model was still calling tools after ${String(this.maxSteps)} steps.`,\n\t\t\t});\n\t\t} catch (error) {\n\t\t\t// The run ends only after the agents still working, which stop with it: what they\n\t\t\t// changed and spent is the run's.\n\t\t\tawait background.stop();\n\t\t\tlet failure = error;\n\t\t\tif (effects.toolRan && error instanceof RecoverableError) {\n\t\t\t\t// RetryingAgent would run the whole prompt again, and with it every tool this run\n\t\t\t\t// already executed, so a failure after one ran must not invite a retry.\n\t\t\t\tconst unrecoverable = new UnrecoverableError(error.message, {\n\t\t\t\t\tcause: error.cause,\n\t\t\t\t\ttokens: error.tokens,\n\t\t\t\t\tusageUnreported: error.usageUnreported,\n\t\t\t\t});\n\t\t\t\tunrecoverable.stack = error.stack;\n\t\t\t\tfailure = unrecoverable;\n\t\t\t}\n\n\t\t\t// The run spent the tokens of every step before the one that failed.\n\t\t\tthrow withSpentTokens(failure, tokens, unreported || background.usageUnknown);\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"llmAgent.js","sourceRoot":"","sources":["../../../../src/engines/domain/model/llmAgent.ts"],"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AAE,KAAK,CAAC,eAAe;iBACtC,CAAC,CAAC;gBACH,aAAa,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;gBAClC,OAAO,GAAG,aAAa,CAAC;YACzB,CAAC;YAED,qEAAqE;YACrE,MAAM,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,IAAI,UAAU,CAAC,YAAY,CAAC,CAAC;QAC/E,CAAC;gBAAS,CAAC;YACV,aAAa,EAAE,EAAE,CAAC;QACnB,CAAC;IACF,CAAC;CACD","sourcesContent":["import {\n\ttype ApprovalDecision,\n\ttype ApprovalRequest,\n\ttype Approver,\n\treadDecision,\n} from '#src/agent/domain/approval';\nimport {\n\ttype Agent,\n\ttype AgentResponse,\n\ttype Callback,\n\ttype ProgressEvent,\n\ttype RunOptions,\n\tignoreProgress,\n} from '#src/agent/domain/agent';\nimport {\n\tdelegationOf,\n\ttype RunEnd,\n\tRunContext,\n\trunContextOf,\n\twithRunContext,\n} from '#src/agent/domain/runContext';\nimport {\n\tInvalidAgentConfigError,\n\tRecoverableError,\n\tUnrecoverableError,\n\twithSpentTokens,\n} from '#src/shared/domain/errors';\nimport {\n\tclassifyHostFailure,\n\tclassifyLocalFailure,\n\tclassifyProviderFailure,\n\tdescribeFailure,\n\ttreatErrors,\n} from '#src/shared/domain/providerFailure';\nimport { Conversation } from '#src/llm/domain/conversation';\nimport { keptScore } from '#src/llm/domain/contextTriage';\nimport { MaxContextError } from '#src/llm/domain/errors';\nimport type { LLMClient, LLMResponse } from '#src/llm/domain/llm';\nimport {\n\tcompactedContext,\n\ttype Message,\n\ttype MessagePart,\n\ttype ToolCallPart,\n\ttype ToolResultPart,\n} from '#src/llm/domain/message';\nimport { asNative, nativeOf, type ToolDefinition } from '#src/llm/domain/tool';\nimport { type Asker, readAnswers, type UserQuestion } from '#src/agent/domain/question';\nimport type { Transcript, TranscriptCallback } from '#src/agent/domain/transcript';\nimport { type InboxReader, readerOf } from '#src/agent/domain/inbox';\nimport { OneRunAtATime } from '#src/agent/domain/oneRunAtATime';\nimport { newSession, sessionOf } from '#src/agent/domain/session';\nimport {\n\ttype AgentTool,\n\ttype CommandEnding,\n\tisDelegating,\n\ttype PreparedCall,\n\ttype PreparedDelegation,\n\tprepareCall,\n\tRunEndingToolError,\n\tToolExecutionError,\n} from '#src/tools/domain/preparedCall';\nimport { ReadRegistry, type ToolCallContext } from '#src/tools/domain/readRegistry';\n\n/** What every tool call of one batch shares; each call adds its own id. */\ntype RunToolContext = Omit<ToolCallContext, 'callId'>;\nimport { InvalidToolInputError } from '#src/tools/domain/tool';\nimport { isAbortError } from '#src/shared/domain/isAbortError';\nimport type { ILogger } from '#src/shared/domain/logger';\nimport { addTokens, type Tokens } from '#src/shared/domain/tokens';\nimport {\n\tanotherAttempt,\n\taskAt,\n\tCommandLoops,\n\textensionNote,\n\tloopQuestion,\n\tloopStop,\n\tloopWarning,\n\trepeatedAnswersAt,\n\trepeatNote,\n\trepeatQuestion,\n\trepeatStop,\n\tstop,\n\twarnAt,\n} from './commandLoops.ts';\nimport { BackgroundAgents, sentNote } from './backgroundAgents.ts';\nimport { compactionOff, type Compactor, type RecentCompactor } from './compactor.ts';\nimport {\n\tmessagesAsText,\n\trecentCut,\n\trecentlyKept,\n\tsummaryRequest,\n\ttranscriptSummaryRequest,\n} from './recentCompaction.ts';\nimport { triageCandidates, triagedCut, triagedKept } from './triagedCompaction.ts';\nimport { measureContext } from './stepContext.ts';\nimport {\n\taskUserDefinition,\n\taskUserName,\n\tdescribeAnswers,\n\treadQuestions,\n\tsummarizeQuestions,\n} from './askUser.ts';\nimport {\n\ttype Followed,\n\tfollowHistory,\n\ttype HistoryReader,\n\ttranscriptOf,\n\tundoNote,\n} from './historyFollower.ts';\n\nfunction describePart(part: MessagePart): ProgressEvent | undefined {\n\tswitch (part.type) {\n\t\tcase 'text':\n\t\t\treturn { type: 'agentMessage', message: part.text };\n\t\tcase 'reasoning':\n\t\t\treturn { type: 'reasoning', message: part.text };\n\t\tcase 'toolCall':\n\t\t\treturn { type: 'tool', id: part.id, name: part.name, status: 'in_progress' };\n\t\tcase 'toolResult':\n\t\t\treturn {\n\t\t\t\ttype: 'tool',\n\t\t\t\tid: part.callId,\n\t\t\t\tname: part.name,\n\t\t\t\tstatus: part.isError ? 'error' : 'completed',\n\t\t\t\t...(part.isError ? { error: part.output } : {}),\n\t\t\t};\n\t\tcase 'providerData':\n\t\t\t// Opaque by design: its readable side, if any, arrives as a reasoning part.\n\t\t\treturn undefined;\n\t\tcase 'compaction':\n\t\t\t// The provider's, for its client to send back; the step's context shows its effect.\n\t\t\treturn undefined;\n\t\tcase 'contextSummary':\n\t\t\t// Narrated as a `compaction` event when it is written.\n\t\t\treturn undefined;\n\t}\n}\n\n/** The tokens of context a call sent: all its input, cached or not. */\nfunction contextSize(tokens: Tokens): number {\n\treturn tokens.inputTokens + tokens.readCacheTokens + tokens.writtenCacheTokens;\n}\n\n/**\n * Whether a run reached a tool's `execute`. A missing tool or a denied call never does, so it\n * has no effect a retry could repeat.\n */\ninterface RunEffects {\n\ttoolRan: boolean;\n}\n\n/**\n * `message` with each summary in it reduced to its text: what a summary kept is in the\n * conversation before it already.\n */\nfunction withoutKeptCopies(\n\tmessage: Message,\n): Message | { role: Message['role']; content: unknown[] } {\n\treturn {\n\t\trole: message.role,\n\t\tcontent: message.content.map(part =>\n\t\t\tpart.type === 'contextSummary' ? { type: part.type, summary: part.summary } : part,\n\t\t),\n\t};\n}\n\n/** What a harness compaction did, and what its summary call spent. */\ninterface CompactionOutcome {\n\tcompacted: boolean;\n\t/** Whether it spent a call that is not asked for again in the same run. */\n\tcalled: boolean;\n\tusage: Tokens | undefined;\n\tunreported: boolean;\n\t/** Why it did not compact, when it did not. */\n\twhy?: string;\n}\n\n/** What a run has shown the model, for its transcript. */\ninterface Seen {\n\tmessages: () => Message[];\n\ttools: ToolDefinition[];\n}\n\nfunction narrate(part: MessagePart, callback: Callback, summary?: string, exitCode?: number): void {\n\tconst event = describePart(part);\n\tif (!event) return;\n\tif (event.type === 'tool') {\n\t\tif (summary !== undefined) event.summary = summary;\n\t\tif (exitCode !== undefined) event.exitCode = exitCode;\n\t}\n\temit(event, callback);\n}\n\nfunction emit(event: ProgressEvent, callback: Callback): void {\n\ttreatErrors(\n\t\t() => {\n\t\t\tcallback(event);\n\t\t},\n\t\tclassifyHostFailure,\n\t\t'LLM agent progress callback failed',\n\t);\n}\n\n/** `value` with the keys of every object sorted, so equal inputs serialize alike. */\nfunction canonical(value: unknown): unknown {\n\tif (Array.isArray(value)) return value.map(canonical);\n\tif (typeof value !== 'object' || value === null) return value;\n\treturn Object.fromEntries(\n\t\tObject.entries(value)\n\t\t\t.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))\n\t\t\t.map(([key, inner]) => [key, canonical(inner)]),\n\t);\n}\n\n/**\n * How many steps in a row have asked for exactly the same tool calls, with the same input. A\n * model that keeps asking is likely stuck: it already has what they return.\n */\nclass RepeatedCalls {\n\tprivate last: string | undefined;\n\tprivate times = 0;\n\n\t/** The user let the run go on: the count starts again. */\n\treset(): void {\n\t\tthis.times = 0;\n\t}\n\n\tcount(calls: readonly ToolCallPart[]): number {\n\t\t// Keys sorted at every level: the same input with its properties in another order is the\n\t\t// same call. Arrays, and the order of the calls, keep theirs.\n\t\tconst key = JSON.stringify(calls.map(call => [call.name, canonical(call.input)]));\n\t\tthis.times = key === this.last ? this.times + 1 : 1;\n\t\tthis.last = key;\n\t\treturn this.times;\n\t}\n}\n\n/** A call by its tool and input, its properties in any order. */\nfunction callKey(call: ToolCallPart): string {\n\treturn JSON.stringify([call.name, canonical(call.input)]);\n}\n\n// How a call the user is asked about is shown: its tool and input, cut short.\nconst shownCallCharacters = 300;\n\nfunction describeCall(call: ToolCallPart): string {\n\tconst text = `${call.name} ${JSON.stringify(canonical(call.input))}`;\n\treturn text.length > shownCallCharacters ? `${text.slice(0, shownCallCharacters)}…` : text;\n}\n\n/** The result of a call the run stopped before. */\nfunction notRun(call: ToolCallPart): ToolResultPart {\n\treturn {\n\t\ttype: 'toolResult',\n\t\tcallId: call.id,\n\t\tname: call.name,\n\t\toutput: 'Not run: the run stopped before it.',\n\t\tisError: true,\n\t};\n}\n\n/** The tool results, with `note` for the model after the last of them. */\nfunction withNote(message: Message, note: string): Message {\n\tconst last = message.content.at(-1);\n\tif (last?.type !== 'toolResult') return message;\n\treturn {\n\t\t...message,\n\t\tcontent: [...message.content.slice(0, -1), { ...last, output: `${last.output}\\n\\n${note}` }],\n\t};\n}\n\n// What the model is told of a message from its inbox, ahead of the message itself.\nconst sentByUser = 'The user sent this while you worked:';\n\n/** What the user sent since the run last looked, and the message the model reads it in. */\nfunction takeInbox(\n\tinbox: InboxReader | undefined,\n): { texts: string[]; message: Message } | undefined {\n\tconst texts = inbox?.take() ?? [];\n\tif (texts.length === 0) return undefined;\n\tconst content = [sentByUser, ...texts].map(text => ({ type: 'text' as const, text }));\n\treturn { texts, message: { role: 'user', content } };\n}\n\n/**\n * An agent whose conversation is owned by MiKode: every run sends the whole context to a\n * stateless `LLMClient`. Within a run the model may call the agent's tools; the agent runs them\n * and sends their results back until the model answers without calling one. Turn boundaries\n * are the consumer's to emit, as with the other engines; this agent only narrates what the\n * model produced and what its tools did.\n */\nexport class LLMAgent implements Agent {\n\tprivate readonly llmClient: LLMClient;\n\tprivate readonly conversation: Conversation;\n\tprivate readonly tools: Map<string, AgentTool>;\n\tprivate readonly toolDefinitions: ToolDefinition[];\n\t// Each call's summary, as its tool gave it when the call ran, so measuring a step that\n\t// resends the call never runs a consumer's summarizer again.\n\tprivate readonly callSummaries = new Map<string, string>();\n\tprivate readonly maxSteps: number;\n\tprivate readonly autoApprove: boolean;\n\tprivate readonly logger: ILogger | undefined;\n\tprivate readonly history: HistoryReader | undefined;\n\tprivate readonly summarizer: LLMClient | undefined;\n\tprivate readonly onTranscript: TranscriptCallback | undefined;\n\tprivate readonly writeRoots: readonly string[] | undefined;\n\tprivate readonly compactor: Compactor;\n\t// The tokens of context the model was last sent in a run that was kept, as its provider\n\t// reported them, which the recent compactor measures against its threshold: the\n\t// conversation's size, not a run's count.\n\tprivate contextTokens: number | undefined;\n\t// The latest move through the history this conversation has followed.\n\tprivate seenRevision = 0;\n\t// What this conversation has seen of each file, so an edit starts from a version it read.\n\tprivate readonly reads = new ReadRegistry();\n\tprivate readonly runs = new OneRunAtATime();\n\t// The session its runs belong to when their options name none.\n\tprivate readonly session = newSession();\n\n\tconstructor({\n\t\tllmClient,\n\t\tmessages,\n\t\ttools = [],\n\t\tmaxSteps = 65,\n\t\tautoApprove = false,\n\t\tlogger,\n\t\thistory,\n\t\tsummarizer,\n\t\tonTranscript,\n\t\twriteRoots,\n\t\tcompactor = compactionOff,\n\t}: {\n\t\tllmClient: LLMClient;\n\t\tmessages?: Message[];\n\t\ttools?: AgentTool[];\n\t\t/** How many calls to the model one run may make before it fails. Defaults to 65. */\n\t\tmaxSteps?: number;\n\t\t/** Runs every tool call without asking, `destructive` ones included. Meant for CI. */\n\t\tautoApprove?: boolean;\n\t\t/** Where a failure the agent absorbs is reported. The factories always pass one. */\n\t\tlogger?: ILogger;\n\t\t/**\n\t\t * The history of the workspace this agent writes to. With it, each run first follows the\n\t\t * moves the user made through that history: the conversation goes back with the\n\t\t * workspace, and the model is told what was undone.\n\t\t */\n\t\thistory?: HistoryReader;\n\t\t/**\n\t\t * A cheap model that summarizes what the undone turns tried and what went wrong. Without\n\t\t * one, the model is told what those turns asked, word for word.\n\t\t */\n\t\tsummarizer?: LLMClient;\n\t\t/** Receives what the model saw in each run, once the run ended. */\n\t\tonTranscript?: TranscriptCallback;\n\t\t/**\n\t\t * The `write` roots of the agent's workspace: an agent it delegates to writes only within\n\t\t * them. Empty when it only reads; without it, it sets no limit of its own.\n\t\t */\n\t\twriteRoots?: readonly string[];\n\t\t/** How the context is compacted. Defaults to off: only a context that no longer fits is. */\n\t\tcompactor?: Compactor;\n\t}) {\n\t\tif (!Number.isInteger(maxSteps) || maxSteps < 1) {\n\t\t\tthrow new InvalidAgentConfigError(\n\t\t\t\t`maxSteps must be a positive integer; got ${String(maxSteps)}`,\n\t\t\t);\n\t\t}\n\t\tif (compactor.by === 'harness') {\n\t\t\tif (compactor.at !== undefined && !(Number.isInteger(compactor.at) && compactor.at > 0)) {\n\t\t\t\tthrow new InvalidAgentConfigError(\n\t\t\t\t\t`compactAt must be a positive whole number of tokens, not ${String(compactor.at)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t} else if (compactor.at !== undefined) {\n\t\t\tif (!llmClient.checkCompactAt) {\n\t\t\t\tthrow new InvalidAgentConfigError('This model client cannot compact; leave compactAt out');\n\t\t\t}\n\t\t\tllmClient.checkCompactAt(compactor.at);\n\t\t}\n\n\t\tthis.llmClient = llmClient;\n\t\tthis.conversation = new Conversation(messages);\n\t\tthis.maxSteps = maxSteps;\n\t\tthis.autoApprove = autoApprove;\n\t\tthis.logger = logger;\n\t\tthis.history = history;\n\t\tthis.summarizer = summarizer;\n\t\tthis.onTranscript = onTranscript;\n\t\tthis.writeRoots = writeRoots;\n\t\tthis.compactor = compactor;\n\t\tthis.tools = new Map(tools.map(tool => [tool.name, tool]));\n\t\tif (this.tools.size !== tools.length) {\n\t\t\t// The model calls tools by name, so a second one with the same name could never run.\n\t\t\tthrow new InvalidAgentConfigError('Two tools share a name; each name must be unique');\n\t\t}\n\t\t// The client only describes the tools to the model; running them stays with the agent.\n\t\tthis.toolDefinitions = tools.map(tool => {\n\t\t\tconst definition = {\n\t\t\t\tname: tool.name,\n\t\t\t\tdescription: tool.description,\n\t\t\t\tinputSchema: tool.inputSchema,\n\t\t\t};\n\t\t\tconst native = nativeOf(tool);\n\t\t\tif (native === undefined) return definition;\n\t\t\t// Checked now, not on the first call: an agent its client cannot serve is a setup error.\n\t\t\tif (llmClient.supportsNative?.(native) !== true) {\n\t\t\t\tthrow new InvalidAgentConfigError(\n\t\t\t\t\t`The tool \"${tool.name}\" is the native \"${native}\" tool, which this model client cannot declare`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn asNative(definition, native);\n\t\t});\n\t}\n\n\tprivate async followHistory(history: HistoryReader): Promise<Followed> {\n\t\ttry {\n\t\t\treturn await followHistory(this.conversation, history, this.seenRevision);\n\t\t} catch (error) {\n\t\t\tthrow classifyLocalFailure(error, 'The workspace history could not be read');\n\t\t}\n\t}\n\n\t/**\n\t * Asks the summarizer what the undone turns tried and what went wrong. A summary is a help,\n\t * not a need: one that fails is reported and the plain note is used instead.\n\t */\n\tprivate async summarizeUndone(\n\t\tfollowed: Followed,\n\t\tsignal: AbortSignal,\n\t): Promise<{ text?: string; usage?: Tokens; called: boolean }> {\n\t\tif (!this.summarizer) return { called: false };\n\t\tconst reasons = followed.revisions.flatMap(revision =>\n\t\t\trevision.reason ? [revision.reason] : [],\n\t\t);\n\t\tconst prompt = [\n\t\t\t'The user undid the work in the conversation below and moved the workspace back to before it.',\n\t\t\treasons.length > 0 ? `Their reason: ${reasons.map(reason => `«${reason}»`).join(' ')}` : '',\n\t\t\t'In at most five short lines, say what was tried, why it went wrong or why the user went back, and what could be done better. Plain text, no preamble.',\n\t\t\t'',\n\t\t\ttranscriptOf(this.conversation, followed.undone),\n\t\t].join('\\n');\n\n\t\tlet response: LLMResponse;\n\t\ttry {\n\t\t\tresponse = await this.summarizer.send(\n\t\t\t\t{ context: [{ role: 'user', content: [{ type: 'text', text: prompt }] }], tools: [] },\n\t\t\t\tsignal,\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tif (isAbortError(error)) throw error;\n\t\t\tthis.warnSummaryFailed(describeFailure(error));\n\t\t\treturn { called: true };\n\t\t}\n\n\t\tconst usage = response.usage ? { usage: response.usage } : {};\n\t\t// A refused or cut summary is not one: the model would read it as what was tried.\n\t\tif (response.stopReason !== 'completed') {\n\t\t\tthis.warnSummaryFailed(`the model stopped with \"${response.stopReason}\"`);\n\t\t\treturn { ...usage, called: true };\n\t\t}\n\t\tconst text = response.message.content\n\t\t\t.filter(part => part.type === 'text')\n\t\t\t.map(part => part.text)\n\t\t\t.join('\\n')\n\t\t\t.trim();\n\t\treturn { ...(text ? { text } : {}), ...usage, called: true };\n\t}\n\n\tprivate warnSummaryFailed(why: string): void {\n\t\ttreatErrors(\n\t\t\t() => {\n\t\t\t\tthis.logger?.warn(`The summary of the undone turns failed: ${why}`);\n\t\t\t},\n\t\t\tclassifyHostFailure,\n\t\t\t'LLM agent logger failed',\n\t\t);\n\t}\n\n\tprivate warnContextOutgrown(): void {\n\t\ttreatErrors(\n\t\t\t() => {\n\t\t\t\tthis.logger?.warn(\n\t\t\t\t\t'The context no longer fits the model; the next call compacts it and tries again',\n\t\t\t\t);\n\t\t\t},\n\t\t\tclassifyHostFailure,\n\t\t\t'LLM agent logger failed',\n\t\t);\n\t}\n\n\tprivate warnTriageFailed(why: string): void {\n\t\ttreatErrors(\n\t\t\t() => {\n\t\t\t\tthis.logger?.warn(`Jev could not choose what to keep, so the recent compactor did: ${why}`);\n\t\t\t},\n\t\t\tclassifyHostFailure,\n\t\t\t'LLM agent logger failed',\n\t\t);\n\t}\n\n\tprivate warnCompactionFailed(why: string): void {\n\t\ttreatErrors(\n\t\t\t() => {\n\t\t\t\tthis.logger?.warn(`The context could not be compacted: ${why}`);\n\t\t\t},\n\t\t\tclassifyHostFailure,\n\t\t\t'LLM agent logger failed',\n\t\t);\n\t}\n\n\t/**\n\t * Warns that a summary the model was called for failed. A logger that throws ends the run,\n\t * carrying what that call spent, which the run has not counted yet.\n\t */\n\tprivate warnSummaryCallFailed(\n\t\twhy: string,\n\t\t{ usage, unreported }: { usage: Tokens | undefined; unreported: boolean },\n\t): void {\n\t\ttry {\n\t\t\tthis.warnCompactionFailed(why);\n\t\t} catch (hostFailure) {\n\t\t\tthrow withSpentTokens(hostFailure, usage, unreported);\n\t\t}\n\t}\n\n\t/**\n\t * Has the agent's own model summarize the context before the harness compactor's cut, and\n\t * records the summary in the run, with what it keeps word for word. With a triage, Jev chooses\n\t * what is kept; when it fails, which it logs, the recent cut does. `compacted` is false when\n\t * the model had answered too few times, which costs no call, when Jev kept every answer\n\t * whole, unless the context no longer fits, or when the summary failed as `summarize` says.\n\t */\n\tprivate async compactHarness(\n\t\tcompactor: RecentCompactor,\n\t\trunMessages: Message[],\n\t\tafter: number | undefined,\n\t\toptions: { signal: AbortSignal; tools: ToolDefinition[]; outgrown: boolean },\n\t): Promise<CompactionOutcome> {\n\t\t// The run's messages are not copied, so its prompt is found where it is.\n\t\tconst context = compactedContext([...this.conversation.contextAfter(after), ...runMessages]);\n\t\tconst [prompt] = runMessages;\n\t\tlet chosen = prompt && (await this.harnessCut(compactor, context, prompt, options.signal));\n\t\t// A context that no longer fits must lose something: when Jev's cut keeps it all, even the\n\t\t// last answer it always keeps, recent cuts.\n\t\tif (prompt && compactor.triage && !chosen?.cut && options.outgrown) {\n\t\t\tchosen = this.recentChoice(compactor, context, prompt);\n\t\t}\n\t\tif (!chosen?.cut) {\n\t\t\tconst why = chosen?.triaged\n\t\t\t\t? 'Jev kept every answer whole, so there is nothing to summarize'\n\t\t\t\t: 'the model has not answered yet, so there is nothing to summarize';\n\t\t\t// A context that no longer fits ends the run, with why in its error rather than the log.\n\t\t\tif (!options.outgrown) this.warnCompactionFailed(why);\n\t\t\t// Jev would keep the same again: it is not asked again in the same run.\n\t\t\treturn {\n\t\t\t\tcompacted: false,\n\t\t\t\tcalled: chosen?.triaged ?? false,\n\t\t\t\tusage: undefined,\n\t\t\t\tunreported: false,\n\t\t\t\twhy,\n\t\t\t};\n\t\t}\n\t\t// The run's context no longer fitting is what makes a failure end it.\n\t\treturn this.summarize(chosen.cut, chosen.kept, runMessages, {\n\t\t\t...options,\n\t\t\tcontext,\n\t\t\tendsRun: options.outgrown,\n\t\t});\n\t}\n\n\t/**\n\t * Where the harness compactor cuts `context`, and what it keeps, as the summary request says\n\t * it. `triaged` when Jev was asked and answered.\n\t */\n\tprivate async harnessCut(\n\t\tcompactor: RecentCompactor,\n\t\tcontext: Message[],\n\t\tprompt: Message,\n\t\tsignal: AbortSignal,\n\t): Promise<{\n\t\tcut: { summarized: Message[]; kept: Message[] } | undefined;\n\t\tkept: string;\n\t\ttriaged: boolean;\n\t}> {\n\t\tconst { triage } = compactor;\n\t\tconst candidates = triage ? triageCandidates(context) : [];\n\t\tlet scores: number[] | undefined = triage && candidates.length === 0 ? [] : undefined;\n\t\tif (triage && candidates.length > 0) {\n\t\t\tconst latest = context.findLast(message => message.role === 'assistant');\n\t\t\ttry {\n\t\t\t\tscores = await triage.score(\n\t\t\t\t\t{\n\t\t\t\t\t\ttask: prompt.content\n\t\t\t\t\t\t\t.flatMap(part => (part.type === 'text' ? [part.text] : []))\n\t\t\t\t\t\t\t.join('\\n'),\n\t\t\t\t\t\tlatestAnswer: latest ? messagesAsText([latest], 8_000, 3_000) : '',\n\t\t\t\t\t\tresults: candidates.map(({ tool, input, output }) => ({ tool, input, output })),\n\t\t\t\t\t},\n\t\t\t\t\tsignal,\n\t\t\t\t);\n\t\t\t} catch (error) {\n\t\t\t\tif (isAbortError(error)) throw error;\n\t\t\t\tsignal.throwIfAborted();\n\t\t\t\tthis.warnTriageFailed(describeFailure(error));\n\t\t\t}\n\t\t}\n\t\tif (scores) {\n\t\t\tconst kept = candidates.filter((_, index) => (scores[index] ?? 0) >= keptScore);\n\t\t\treturn {\n\t\t\t\tcut: triagedCut(context, prompt, new Set(kept.map(({ callId }) => callId))),\n\t\t\t\tkept: triagedKept(kept),\n\t\t\t\ttriaged: candidates.length > 0,\n\t\t\t};\n\t\t}\n\t\treturn this.recentChoice(compactor, context, prompt);\n\t}\n\n\tprivate recentChoice(compactor: RecentCompactor, context: Message[], prompt: Message) {\n\t\treturn {\n\t\t\tcut: recentCut(context, prompt, compactor.keptSteps),\n\t\t\tkept: recentlyKept(compactor.keptSteps),\n\t\t\ttriaged: false,\n\t\t};\n\t}\n\n\t/**\n\t * Has the agent's own model summarize what `cut` does not keep, and records the summary in the\n\t * run. Once the threshold passed, the model reads `context`, the context as it was last sent,\n\t * from its provider's cache; once the context no longer fit, it reads what it summarizes as\n\t * text. `compacted` is false when the model wrote no summary or the provider failed in\n\t * passing, which it logs; any other failure is thrown. The summary's usage is the run's either\n\t * way.\n\t *\n\t * @param kept what `cut` keeps, as the summary request tells the model.\n\t * @param endsRun whether a failure ends the run, which throws why instead of logging it: the\n\t * run's context no longer fits. `outgrown` alone may be this call's own fallback.\n\t */\n\tprivate async summarize(\n\t\tcut: { summarized: Message[]; kept: Message[] },\n\t\tkept: string,\n\t\trunMessages: Message[],\n\t\t{\n\t\t\tcontext,\n\t\t\tsignal,\n\t\t\ttools,\n\t\t\toutgrown,\n\t\t\tendsRun,\n\t\t}: {\n\t\t\tcontext: Message[];\n\t\t\tsignal: AbortSignal;\n\t\t\ttools: ToolDefinition[];\n\t\t\toutgrown: boolean;\n\t\t\tendsRun: boolean;\n\t\t},\n\t): Promise<CompactionOutcome> {\n\t\tconst request = outgrown\n\t\t\t? { context: [transcriptSummaryRequest(cut.summarized, kept)], tools: [] }\n\t\t\t: { context: [...structuredClone(context), summaryRequest(kept)], tools };\n\n\t\tlet response: LLMResponse;\n\t\ttry {\n\t\t\tresponse = await this.llmClient.send(request, signal);\n\t\t} catch (error) {\n\t\t\tif (isAbortError(error)) throw error;\n\t\t\tconst failure = classifyProviderFailure(error, 'The context summary failed');\n\t\t\tif (failure instanceof MaxContextError && !outgrown) {\n\t\t\t\t// The context grew past the model since it was last sent: the model reads what it\n\t\t\t\t// summarizes as text instead, and this call is the run's too.\n\t\t\t\tlet fallback: CompactionOutcome;\n\t\t\t\ttry {\n\t\t\t\t\tfallback = await this.summarize(cut, kept, runMessages, {\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t\ttools,\n\t\t\t\t\t\toutgrown: true,\n\t\t\t\t\t\tendsRun,\n\t\t\t\t\t});\n\t\t\t\t} catch (fallbackFailure) {\n\t\t\t\t\tthrow withSpentTokens(fallbackFailure, failure.tokens, failure.usageUnreported);\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\t...fallback,\n\t\t\t\t\tusage: addTokens(failure.tokens, fallback.usage),\n\t\t\t\t\tunreported: fallback.unreported || failure.usageUnreported,\n\t\t\t\t};\n\t\t\t}\n\t\t\t// Only a passing failure of the provider goes without a summary: anything else, such as\n\t\t\t// a logger or a response the client could not map, ends the run as any call's would.\n\t\t\tif (!(failure instanceof RecoverableError)) throw failure;\n\t\t\tconst failed = {\n\t\t\t\tcompacted: false,\n\t\t\t\tcalled: true,\n\t\t\t\tusage: failure.tokens,\n\t\t\t\tunreported: failure.usageUnreported,\n\t\t\t\twhy: describeFailure(failure),\n\t\t\t};\n\t\t\tif (!endsRun) this.warnSummaryCallFailed(failed.why, failed);\n\t\t\treturn failed;\n\t\t}\n\n\t\tconst spent = { called: true, usage: response.usage, unreported: !response.usage };\n\t\tconst summary = response.message.content\n\t\t\t.flatMap(part => (part.type === 'text' ? [part.text] : []))\n\t\t\t.join('\\n')\n\t\t\t.trim();\n\t\t// A cut or refused answer, or one that calls a tool, is no summary of the work.\n\t\tif (\n\t\t\tresponse.stopReason !== 'completed' ||\n\t\t\tresponse.message.content.some(part => part.type === 'toolCall') ||\n\t\t\tsummary === ''\n\t\t) {\n\t\t\tconst why = 'the model did not answer with a summary';\n\t\t\tif (!endsRun) this.warnSummaryCallFailed(why, spent);\n\t\t\treturn { compacted: false, ...spent, why };\n\t\t}\n\t\trunMessages.push({\n\t\t\trole: 'user',\n\t\t\tcontent: [{ type: 'contextSummary', summary, kept: cut.kept }],\n\t\t});\n\t\treturn { compacted: true, ...spent };\n\t}\n\n\tprivate async llmCall(\n\t\trunMessages: Message[],\n\t\tafter: number | undefined,\n\t\t{\n\t\t\tsignal,\n\t\t\tstep,\n\t\t\tcallback,\n\t\t\ttools,\n\t\t\tcompactAt,\n\t\t}: {\n\t\t\tsignal: AbortSignal;\n\t\t\tstep: number;\n\t\t\tcallback: Callback;\n\t\t\ttools: ToolDefinition[];\n\t\t\tcompactAt: number | 'now' | undefined;\n\t\t},\n\t): Promise<{ response: LLMResponse; context: Message[] }> {\n\t\t// Sent as a copy, so what the run records is what the agent built, whatever the client does.\n\t\tconst context = compactedContext([\n\t\t\t...this.conversation.contextAfter(after),\n\t\t\t...structuredClone(runMessages),\n\t\t]);\n\t\tlet response: LLMResponse;\n\t\ttry {\n\t\t\tresponse = await this.llmClient.send({ context, tools, compactAt }, signal);\n\t\t} catch (error) {\n\t\t\tconst failure = classifyProviderFailure(error, 'The LLM call failed');\n\t\t\t// A client turns some answers into errors, such as a stop at the context window. The\n\t\t\t// call was billed, and the failure carries what it spent: it is still a step.\n\t\t\tif (\n\t\t\t\t(failure instanceof RecoverableError || failure instanceof UnrecoverableError) &&\n\t\t\t\t(failure.tokens !== undefined || failure.usageUnreported)\n\t\t\t) {\n\t\t\t\ttry {\n\t\t\t\t\tthis.narrateStep(step, failure.tokens, { context, tools }, callback);\n\t\t\t\t} catch (hostFailure) {\n\t\t\t\t\t// The callback's failure ends the run, and must carry this call's tokens too.\n\t\t\t\t\tthrow withSpentTokens(hostFailure, failure.tokens, failure.usageUnreported);\n\t\t\t\t}\n\t\t\t}\n\t\t\tthrow failure;\n\t\t}\n\n\t\treturn { response, context };\n\t}\n\n\tprivate narrateStep(\n\t\tstep: number,\n\t\ttokens: Tokens | undefined,\n\t\tsent: { context: Message[]; tools: ToolDefinition[] },\n\t\tcallback: Callback,\n\t) {\n\t\temit(\n\t\t\t{\n\t\t\t\ttype: 'step',\n\t\t\t\tstep,\n\t\t\t\t...(tokens ? { tokens } : {}),\n\t\t\t\tcontext: measureContext({\n\t\t\t\t\tinstructions: this.llmClient.systemPrompt,\n\t\t\t\t\tproviderDataSource: this.llmClient.providerDataSource,\n\t\t\t\t\ttools: sent.tools,\n\t\t\t\t\tcontext: sent.context,\n\t\t\t\t\tsummarize: call => this.callSummaries.get(call.id),\n\t\t\t\t}),\n\t\t\t},\n\t\t\tcallback,\n\t\t);\n\t}\n\n\t/**\n\t * Undefined when the call may run; otherwise why it may not, which the model receives in its\n\t * place. Only a `destructive` call is asked about: git can undo a `mutating` one. A throwing\n\t * approver ends the run, as any host callback does.\n\t */\n\tprivate async denial(\n\t\tcall: ToolCallPart,\n\t\tprepared: PreparedCall | PreparedDelegation,\n\t\tsignal: AbortSignal,\n\t\tapprove: Approver | undefined,\n\t): Promise<string | undefined> {\n\t\tconst { risk } = prepared;\n\t\tif (this.autoApprove || risk !== 'destructive') return undefined;\n\t\tconst command = 'command' in prepared ? prepared.command : undefined;\n\t\tconst worktree = 'worktree' in prepared ? prepared.worktree : undefined;\n\n\t\tconst retry = 'Do not retry the same call; choose another way, or ask the user.';\n\t\tif (!approve) {\n\t\t\treturn `The call to \"${call.name}\" was denied: it is destructive, and no one was asked to allow it. ${retry}`;\n\t\t}\n\n\t\tlet decision: ApprovalDecision;\n\t\ttry {\n\t\t\t// A copy, so what runs and what the conversation keeps is exactly what was approved.\n\t\t\tconst input: unknown = structuredClone(call.input);\n\t\t\t// Read inside the boundary: an untyped approver can answer anything, and a bad answer\n\t\t\t// is its failure, which must carry the run's tokens like any other.\n\t\t\tconst request: ApprovalRequest = {\n\t\t\t\ttool: call.name,\n\t\t\t\tinput,\n\t\t\t\trisk,\n\t\t\t\t// A copy too: the approver must not be able to change what runs.\n\t\t\t\t...(command ? { command: structuredClone(command) } : {}),\n\t\t\t\t...(worktree ? { worktree: structuredClone(worktree) } : {}),\n\t\t\t};\n\t\t\tdecision = readDecision(await approve(request, signal));\n\t\t} catch (error) {\n\t\t\t// An approver that gives up on a cancellation, whatever it throws, did not fail.\n\t\t\tsignal.throwIfAborted();\n\t\t\tthrow classifyHostFailure(error, 'The tool call approver failed');\n\t\t}\n\t\t// The user may cancel the run while they are being asked.\n\t\tsignal.throwIfAborted();\n\t\tif (decision.approved) return undefined;\n\n\t\tconst reason = decision.reason ? ` Their reason: ${decision.reason}` : '';\n\t\treturn `The user denied the call to \"${call.name}\".${reason} ${retry}`;\n\t}\n\n\t/**\n\t * Always answers the call: a missing tool, a denied call or a failing one becomes an error\n\t * result, so the model can correct itself. Only a cancellation, a failing approver, or host\n\t * code that failed inside the call escapes. A call that hands tasks to agents answers once\n\t * it sent them, and `background` watches them from then on.\n\t */\n\tprivate async runTool(\n\t\tcall: ToolCallPart,\n\t\t{ signal, onProgress: callback = ignoreProgress, approve, ask }: RunOptions,\n\t\teffects: RunEffects,\n\t\ttoolCall: RunToolContext,\n\t\tbackground: BackgroundAgents,\n\t): Promise<{\n\t\tresult: ToolResultPart;\n\t\tdenied: boolean;\n\t\tdiff?: string;\n\t\tsummary?: string;\n\t\texitCode?: number;\n\t\tending?: CommandEnding;\n\t\t// It sent agents to work in the background.\n\t\tsent?: boolean;\n\t\t// It ran, and may have changed files the history does not record.\n\t\tunrecorded?: boolean;\n\t}> {\n\t\tconst result = { type: 'toolResult' as const, callId: call.id, name: call.name };\n\t\tsignal.throwIfAborted();\n\t\tif (call.name === askUserName && ask && !this.tools.has(askUserName)) {\n\t\t\treturn this.askUser(call, ask, signal, callback);\n\t\t}\n\t\tconst tool = this.tools.get(call.name);\n\t\tif (!tool) {\n\t\t\treturn {\n\t\t\t\tresult: {\n\t\t\t\t\t...result,\n\t\t\t\t\toutput: `There is no tool named \"${call.name}\". Available tools: ${[...this.tools.keys()].join(', ') || 'none'}.`,\n\t\t\t\t\tisError: true,\n\t\t\t\t},\n\t\t\t\tdenied: false,\n\t\t\t};\n\t\t}\n\n\t\tlet summary: string | undefined;\n\t\ttry {\n\t\t\t// This is deliberately before preparation and approval. A consumer-supplied\n\t\t\t// summarizer is host code, and a failed one must never leave an ambiguous call that\n\t\t\t// could be replayed by RetryingAgent.\n\t\t\tsummary = tool.summarize?.(call.input);\n\t\t\tif (summary !== undefined) this.callSummaries.set(call.id, summary);\n\t\t} catch (error) {\n\t\t\tsignal.throwIfAborted();\n\t\t\tif (error instanceof InvalidToolInputError) {\n\t\t\t\treturn {\n\t\t\t\t\tresult: { ...result, output: describeFailure(error), isError: true },\n\t\t\t\t\tdenied: false,\n\t\t\t\t};\n\t\t\t}\n\t\t\tthrow classifyHostFailure(error, 'The tool call summarizer failed');\n\t\t}\n\n\t\tlet prepared: PreparedCall | PreparedDelegation;\n\t\ttry {\n\t\t\tconst context = { ...toolCall, callId: call.id };\n\t\t\tprepared = isDelegating(tool)\n\t\t\t\t? await tool.delegate(call.input, signal, context)\n\t\t\t\t: await prepareCall(tool, call.input, signal, context);\n\t\t} catch (error) {\n\t\t\tsignal.throwIfAborted();\n\t\t\t// A call that cannot be prepared, or whose tool cannot judge it, does not run; the\n\t\t\t// model reads why, such as a refused path, and can correct itself.\n\t\t\treturn {\n\t\t\t\tresult: { ...result, output: describeFailure(error), isError: true },\n\t\t\t\tdenied: false,\n\t\t\t\t...(summary === undefined ? {} : { summary }),\n\t\t\t};\n\t\t}\n\n\t\t// Preparing may have finished after a cancellation it did not notice; nobody is asked to\n\t\t// approve a call in a run that has already stopped.\n\t\tsignal.throwIfAborted();\n\t\tconst denial = await this.denial(call, prepared, signal, approve);\n\t\tif (denial !== undefined) {\n\t\t\treturn {\n\t\t\t\tresult: { ...result, output: denial, isError: true },\n\t\t\t\tdenied: true,\n\t\t\t\t...(summary === undefined ? {} : { summary }),\n\t\t\t};\n\t\t}\n\n\t\t// Deciding took at least one await, and the run may have been cancelled meanwhile.\n\t\tsignal.throwIfAborted();\n\t\t// Announced only once it will run: a missing, failing-to-judge or denied call never is.\n\t\temit(\n\t\t\t{\n\t\t\t\ttype: 'tool',\n\t\t\t\tid: call.id,\n\t\t\t\tname: call.name,\n\t\t\t\tstatus: 'in_progress',\n\t\t\t\t...(summary === undefined ? {} : { summary }),\n\t\t\t},\n\t\t\tcallback,\n\t\t);\n\t\t// Checked again at the last moment: the consumer may cancel on the announcement itself.\n\t\tsignal.throwIfAborted();\n\t\t// Set before `execute`, so a tool that fails halfway still counts: it may have had effects.\n\t\teffects.toolRan = true;\n\t\tconst unrecorded = prepared.unrecorded === true && prepared.risk !== 'safe';\n\t\tif ('start' in prepared) {\n\t\t\t// Before its agents start, so the person watching reads it before anything they narrate.\n\t\t\temit(\n\t\t\t\t{\n\t\t\t\t\ttype: 'tool',\n\t\t\t\t\tid: call.id,\n\t\t\t\t\tname: call.name,\n\t\t\t\t\tstatus: 'sent',\n\t\t\t\t\t...(summary === undefined ? {} : { summary }),\n\t\t\t\t},\n\t\t\t\tcallback,\n\t\t\t);\n\t\t\tconst agents = prepared.start(background.signal);\n\t\t\tbackground.add(call.id, agents, unrecorded);\n\t\t\treturn {\n\t\t\t\tresult: { ...result, output: sentNote(agents), isError: false },\n\t\t\t\tdenied: false,\n\t\t\t\tsent: true,\n\t\t\t\tunrecorded,\n\t\t\t\t...(summary === undefined ? {} : { summary }),\n\t\t\t};\n\t\t}\n\t\ttry {\n\t\t\tconst output = await prepared.run(signal);\n\t\t\tconst ending = prepared.ending?.();\n\t\t\treturn {\n\t\t\t\tresult: { ...result, output, isError: false },\n\t\t\t\tdenied: false,\n\t\t\t\tunrecorded,\n\t\t\t\t...(summary === undefined ? {} : { summary }),\n\t\t\t\t...(prepared.diff === undefined ? {} : { diff: prepared.diff }),\n\t\t\t\t...(ending === undefined ? {} : { ending }),\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tsignal.throwIfAborted();\n\t\t\tif (error instanceof RunEndingToolError) throw error.failure;\n\t\t\tconst ending = prepared.ending?.();\n\t\t\treturn {\n\t\t\t\tresult: { ...result, output: describeFailure(error), isError: true },\n\t\t\t\tdenied: false,\n\t\t\t\tunrecorded,\n\t\t\t\t...(summary === undefined ? {} : { summary }),\n\t\t\t\t...(error instanceof ToolExecutionError && error.exitCode !== undefined\n\t\t\t\t\t? { exitCode: error.exitCode }\n\t\t\t\t\t: {}),\n\t\t\t\t...(ending === undefined ? {} : { ending }),\n\t\t\t};\n\t\t}\n\t}\n\n\t/**\n\t * Asks the user through the run's `ask`. Questions the model wrote wrong go back to it, to\n\t * correct; an asker that fails or answers wrongly is host code, and ends the run.\n\t */\n\tprivate async askUser(\n\t\tcall: ToolCallPart,\n\t\task: Asker,\n\t\tsignal: AbortSignal,\n\t\tcallback: Callback,\n\t): Promise<{ result: ToolResultPart; denied: boolean; summary?: string }> {\n\t\tconst result = { type: 'toolResult' as const, callId: call.id, name: call.name };\n\t\tconst questions = readQuestions(call.input);\n\t\tif (typeof questions === 'string') {\n\t\t\treturn { result: { ...result, output: questions, isError: true }, denied: false };\n\t\t}\n\t\tconst summary = summarizeQuestions(questions);\n\t\tthis.callSummaries.set(call.id, summary);\n\t\temit({ type: 'tool', id: call.id, name: call.name, status: 'in_progress', summary }, callback);\n\t\tsignal.throwIfAborted();\n\n\t\tlet answers: unknown;\n\t\ttry {\n\t\t\tanswers = await ask(questions, signal);\n\t\t} catch (error) {\n\t\t\tsignal.throwIfAborted();\n\t\t\tthrow classifyHostFailure(error, 'The asker failed');\n\t\t}\n\t\t// An answer that arrives after a cancellation is not given to the model.\n\t\tsignal.throwIfAborted();\n\t\tconst read = readAnswers(answers, questions);\n\t\tif (!read) {\n\t\t\tthrow new UnrecoverableError('The asker failed', {\n\t\t\t\tcause: `It must answer each of the ${String(questions.length)} questions with some text, in order.`,\n\t\t\t});\n\t\t}\n\t\treturn {\n\t\t\tresult: { ...result, output: describeAnswers(questions, read), isError: false },\n\t\t\tdenied: false,\n\t\t\tsummary,\n\t\t};\n\t}\n\n\t/**\n\t * One at a time and in order, so their effects and their narration never interleave. Agents a\n\t * call hands tasks to keep working in the background once it answered.\n\t */\n\tprivate async runTools(\n\t\tcalls: ToolCallPart[],\n\t\toptions: RunOptions,\n\t\teffects: RunEffects,\n\t\ttoolCall: RunToolContext,\n\t\t// Throws the failure of a progress callback a call narrated through.\n\t\tthrowIfProgressFailed: () => void,\n\t\tloops: CommandLoops,\n\t\tbackground: BackgroundAgents,\n\t): Promise<{ message: Message; stopped?: UnrecoverableError }> {\n\t\tconst { signal } = options;\n\t\tconst results: MessagePart[] = [];\n\t\tfor (const [index, call] of calls.entries()) {\n\t\t\t// A call before this one may have ignored the cancellation; this one must not start,\n\t\t\t// nor be announced as running.\n\t\t\tsignal.throwIfAborted();\n\t\t\t// `runTool` announces the call only once it is allowed to run, so a consumer never\n\t\t\t// shows a call as running early, nor while the user is still being asked.\n\t\t\tconst ran = await this.runTool(call, options, effects, toolCall, background);\n\t\t\t// A call that failed to narrate ends the run before the next one can start.\n\t\t\tthrowIfProgressFailed();\n\t\t\t// An agent at work since the last call may have changed what the history cannot copy.\n\t\t\tif (background.mayHaveChangedUnseen()) loops.unrecordedCallRan();\n\t\t\tconst settled = this.settle(call, ran, loops, options);\n\t\t\tlet { result } = settled;\n\t\t\tconst { alike, key, label } = settled;\n\t\t\t// After its result is narrated, so the user is asked about the ending they have seen.\n\t\t\tif (alike !== undefined && alike.times >= askAt) {\n\t\t\t\tconst decision = await this.decideOnLoop(\n\t\t\t\t\t{\n\t\t\t\t\t\tquestion: loopQuestion(label, alike),\n\t\t\t\t\t\tfailure: 'The LLM kept getting the same result from a command',\n\t\t\t\t\t\tstopped: reason => loopStop(label, alike, reason),\n\t\t\t\t\t\tnote: words => extensionNote(alike, words),\n\t\t\t\t\t},\n\t\t\t\t\t() => loops.extend([key]),\n\t\t\t\t\toptions,\n\t\t\t\t);\n\t\t\t\tif (typeof decision !== 'string') {\n\t\t\t\t\t// So the next run's model reads why this one ended where it did.\n\t\t\t\t\tresults.push({\n\t\t\t\t\t\t...result,\n\t\t\t\t\t\toutput: `${result.output}\\n\\nThe run stopped here: ${decision.cause}`,\n\t\t\t\t\t});\n\t\t\t\t\t// The calls after it never run, but each still gets a result, so the run that is\n\t\t\t\t\t// kept has none without one.\n\t\t\t\t\tresults.push(...calls.slice(index + 1).map(notRun));\n\t\t\t\t\treturn { message: { role: 'tool', content: results }, stopped: decision };\n\t\t\t\t}\n\t\t\t\tresult = { ...result, output: `${result.output}\\n\\n${decision}` };\n\t\t\t}\n\t\t\tresults.push(result);\n\t\t}\n\n\t\treturn { message: { role: 'tool', content: results } };\n\t}\n\n\t/**\n\t * Narrates how a call ended and notes its command's ending, with the warning for the model\n\t * when that ending keeps coming back alike.\n\t */\n\tprivate settle(\n\t\tcall: ToolCallPart,\n\t\tran: Awaited<ReturnType<LLMAgent['runTool']>>,\n\t\tloops: CommandLoops,\n\t\t{ onProgress: callback = ignoreProgress, ask }: RunOptions,\n\t): {\n\t\tresult: ToolResultPart;\n\t\talike: ReturnType<CommandLoops['observe']> | undefined;\n\t\tkey: string;\n\t\tlabel: string;\n\t} {\n\t\tconst { denied, diff, summary, exitCode, ending, sent } = ran;\n\t\tlet { result } = ran;\n\t\tif (ran.unrecorded) loops.unrecordedCallRan();\n\t\tconst key = callKey(call);\n\t\tconst label = summary ?? call.name;\n\t\tconst alike = ending === undefined ? undefined : loops.observe(key, ending);\n\t\t// A command that changed what the history cannot copy hides that change from the next.\n\t\tif (ending !== undefined && ending.state === undefined) loops.unrecordedCallRan();\n\t\t// Narrated with it, so the person watching reads what the model is told.\n\t\tif (alike?.times === warnAt) {\n\t\t\tresult = {\n\t\t\t\t...result,\n\t\t\t\toutput: `${result.output}\\n\\n${loopWarning(label, alike, ask !== undefined && !loops.wentOn)}`,\n\t\t\t};\n\t\t}\n\t\tif (denied) {\n\t\t\temit(\n\t\t\t\t{\n\t\t\t\t\ttype: 'tool',\n\t\t\t\t\tid: call.id,\n\t\t\t\t\tname: call.name,\n\t\t\t\t\tstatus: 'denied',\n\t\t\t\t\t...(summary === undefined ? {} : { summary }),\n\t\t\t\t},\n\t\t\t\tcallback,\n\t\t\t);\n\t\t} else if (sent === true) {\n\t\t\t// Narrated as it sent its agents, which go on after it until each one ends.\n\t\t}\n\t\t// The diff of a change it made, for the person watching; only once it was made.\n\t\telse if (diff !== undefined) {\n\t\t\temit(\n\t\t\t\t{\n\t\t\t\t\ttype: 'tool',\n\t\t\t\t\tid: call.id,\n\t\t\t\t\tname: call.name,\n\t\t\t\t\tstatus: 'completed',\n\t\t\t\t\tdiff,\n\t\t\t\t\t...(summary === undefined ? {} : { summary }),\n\t\t\t\t},\n\t\t\t\tcallback,\n\t\t\t);\n\t\t} else narrate(result, callback, summary, exitCode);\n\t\treturn { result, alike, key, label };\n\t}\n\n\t/**\n\t * On a loop found, the fifth ending alike of a command or the fifth answer in a row asking for\n\t * the same calls: the note for the model if the user lets the run go on, or the failure that\n\t * stops it. The run goes on once at most, and never without someone to ask.\n\t */\n\tprivate async decideOnLoop(\n\t\tloop: {\n\t\t\tquestion: UserQuestion;\n\t\t\tfailure: string;\n\t\t\tstopped: (reason: string) => string;\n\t\t\tnote: (words?: string) => string;\n\t\t},\n\t\textend: () => boolean,\n\t\t{ ask, signal }: RunOptions,\n\t): Promise<string | UnrecoverableError> {\n\t\tconst stopped = (reason: string) =>\n\t\t\tnew UnrecoverableError(loop.failure, { cause: loop.stopped(reason) });\n\t\tif (!ask) return stopped('No one could be asked whether to go on.');\n\t\tif (!extend()) return stopped('The user had already let the run go on once.');\n\n\t\tconst questions = [loop.question];\n\t\tlet answers: unknown;\n\t\ttry {\n\t\t\tanswers = await ask(questions, signal);\n\t\t} catch (error) {\n\t\t\tsignal.throwIfAborted();\n\t\t\tthrow classifyHostFailure(error, 'The asker failed');\n\t\t}\n\t\t// An answer that arrives after a cancellation is not acted on.\n\t\tsignal.throwIfAborted();\n\t\tconst [answer] = readAnswers(answers, questions) ?? [];\n\t\tif (answer === undefined) {\n\t\t\tthrow new UnrecoverableError('The asker failed', {\n\t\t\t\tcause: 'It must answer the question with some text.',\n\t\t\t});\n\t\t}\n\t\tif (answer === stop) return stopped('The user stopped it.');\n\t\treturn loop.note(answer === anotherAttempt ? undefined : answer);\n\t}\n\n\t/**\n\t * Runs inside the context of the run that reached it, or in one of its own that it ends with\n\t * the run: completed, failed or cancelled. Only a run that owns its context names the history\n\t * run it recorded, since the run is over only when that context ends.\n\t *\n\t * @throws {RunInProgressError} when another run on this agent is still working.\n\t */\n\trun(prompt: string, options: RunOptions): Promise<AgentResponse> {\n\t\treturn this.runs.run(() => this.runAlone(prompt, options));\n\t}\n\n\tprivate async runAlone(prompt: string, options: RunOptions): Promise<AgentResponse> {\n\t\tconst session = sessionOf(options) ?? this.session;\n\t\t// Returned as copies: a consumer changing one must not change what later runs record.\n\t\tconst inherited = runContextOf(options);\n\t\tif (inherited) {\n\t\t\treturn { ...(await this.runSteps(prompt, options, inherited)), session: { ...session } };\n\t\t}\n\n\t\tconst context = new RunContext(session);\n\t\tlet end: RunEnd = 'failed';\n\t\tlet response: AgentResponse;\n\t\ttry {\n\t\t\tresponse = await this.runSteps(prompt, withRunContext(options, context), context);\n\t\t\tend = 'completed';\n\t\t} catch (error) {\n\t\t\tif (isAbortError(error)) end = 'cancelled';\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tawait this.finishContext(context, end);\n\t\t}\n\t\t// Read once the run ended: a run that changed nothing left the history then.\n\t\tconst { runId } = context.historyRun;\n\t\treturn { ...response, ...(runId ? { runId } : {}), session: { ...session } };\n\t}\n\n\t/**\n\t * What the run started ends here, but its result stands: the changes it recorded are already\n\t * on disk, so a record that could not be closed is reported, not turned into a failure.\n\t */\n\tprivate async finishContext(context: RunContext, end: RunEnd): Promise<void> {\n\t\ttry {\n\t\t\tawait context.finish(end);\n\t\t} catch (error) {\n\t\t\ttreatErrors(\n\t\t\t\t() => {\n\t\t\t\t\tthis.logger?.warn(`The run could not close its records: ${describeFailure(error)}`);\n\t\t\t\t},\n\t\t\t\tclassifyHostFailure,\n\t\t\t\t'LLM agent logger failed',\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate async runSteps(\n\t\tprompt: string,\n\t\toptions: RunOptions,\n\t\tcontext: RunContext,\n\t): Promise<AgentResponse> {\n\t\tconst seen: Seen = { messages: () => [], tools: this.toolDefinitions };\n\t\tlet response: AgentResponse;\n\t\ttry {\n\t\t\tresponse = await this.takeSteps(prompt, options, context, seen);\n\t\t} catch (error) {\n\t\t\tawait this.transcribe(seen, options, isAbortError(error) ? 'cancelled' : 'failed', error);\n\t\t\tthrow error;\n\t\t}\n\t\tawait this.transcribe(seen, options, 'completed');\n\t\treturn response;\n\t}\n\n\t/** Hands the run's transcript to the consumer, whose failure is logged, not the run's. */\n\tprivate async transcribe(\n\t\tseen: Seen,\n\t\toptions: RunOptions,\n\t\toutcome: Transcript['outcome'],\n\t\terror?: unknown,\n\t): Promise<void> {\n\t\tif (!this.onTranscript) return;\n\t\tconst delegation = delegationOf(options);\n\t\ttry {\n\t\t\t// A copy, so a consumer that changes it cannot change the agent's tools or conversation.\n\t\t\tconst content: unknown = structuredClone({\n\t\t\t\tinstructions: this.llmClient.systemPrompt,\n\t\t\t\ttools: seen.tools.map(({ name, description, inputSchema }) => ({\n\t\t\t\t\tname,\n\t\t\t\t\tdescription,\n\t\t\t\t\tinputSchema,\n\t\t\t\t})),\n\t\t\t\tmessages: seen.messages().map(withoutKeptCopies),\n\t\t\t\t...(outcome === 'completed' ? {} : { error: describeFailure(error) }),\n\t\t\t});\n\t\t\tawait this.onTranscript({\n\t\t\t\t...(delegation\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tdelegation: {\n\t\t\t\t\t\t\t\ttool: delegation.tool,\n\t\t\t\t\t\t\t\tcallId: delegation.callId,\n\t\t\t\t\t\t\t\tsubagent: delegation.subagent,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t\toutcome,\n\t\t\t\tcontent,\n\t\t\t});\n\t\t} catch (failure) {\n\t\t\ttreatErrors(\n\t\t\t\t() => {\n\t\t\t\t\tthis.logger?.warn(\n\t\t\t\t\t\t`The run's transcript could not be handed over: ${describeFailure(failure)}`,\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\tclassifyHostFailure,\n\t\t\t\t'LLM agent logger failed',\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate async takeSteps(\n\t\tprompt: string,\n\t\toptions: RunOptions,\n\t\tcontext: RunContext,\n\t\tseen: Seen,\n\t): Promise<AgentResponse> {\n\t\tconst { signal, onProgress: callback = ignoreProgress } = options;\n\t\tconst delegation = delegationOf(options);\n\t\t// A tool narrates through this without ever failing: a failing callback would reach\n\t\t// only the tool, which turns any failure into a result for the model. The run ends on\n\t\t// it once that tool returns.\n\t\tlet progressFailure: { error: unknown } | undefined;\n\t\tconst onProgress = (event: ProgressEvent) => {\n\t\t\tif (progressFailure) return;\n\t\t\ttry {\n\t\t\t\temit(event, callback);\n\t\t\t} catch (error) {\n\t\t\t\tprogressFailure = { error };\n\t\t\t}\n\t\t};\n\t\t// The agents the run's calls send to work in the background.\n\t\tconst background = new BackgroundAgents(signal, onProgress);\n\t\t// Checked whatever it is, as a JavaScript consumer can pass anything.\n\t\tconst inbox = options.inbox === undefined ? undefined : readerOf(options.inbox);\n\t\t// What the user sends while the run waits for its agents is worth the model's attention.\n\t\tconst stopListening = inbox?.onMessage(() => {\n\t\t\tbackground.interrupt();\n\t\t});\n\t\t// What the run read from its inbox and has not kept yet, which goes back there if the run\n\t\t// is not kept.\n\t\tconst unkept: string[] = [];\n\t\tconst takeSent = () => {\n\t\t\tconst sent = takeInbox(inbox);\n\t\t\tif (sent) unkept.push(...sent.texts);\n\t\t\treturn sent?.message;\n\t\t};\n\t\tconst start = Date.now();\n\t\tconst runMessages: Message[] = [{ role: 'user', content: [{ type: 'text', text: prompt }] }];\n\t\tlet tokens: Tokens | undefined;\n\t\t// Once one call went unreported the run's total is unknown, however many report later.\n\t\tlet unreported = false;\n\t\t// Per run, not per instance: what one run executed says nothing about another.\n\t\tconst effects: RunEffects = { toolRan: false };\n\t\t// The turn this one follows: the last recorded, unless the workspace moved since.\n\t\tlet after = this.conversation.currentTurn;\n\t\tlet followed: Followed | undefined;\n\t\t// The context's size as this run knows it, the agent's once the run is kept: a run that\n\t\t// is not kept leaves the conversation, and so its size, as they were.\n\t\tlet contextTokens = this.contextTokens;\n\t\t// What the model has seen so far, whichever turn the run ends up following: every message,\n\t\t// those a summary replaced too, for a person debugging the run.\n\t\tseen.messages = () => [...this.conversation.contextAfter(after), ...runMessages];\n\n\t\ttry {\n\t\t\tif (this.history) {\n\t\t\t\tfollowed = await this.followHistory(this.history);\n\t\t\t\tafter = followed.turn;\n\t\t\t\t// The files may no longer hold what the conversation saw of them.\n\t\t\t\tif (followed.revisions.length > 0) {\n\t\t\t\t\tthis.reads.clear();\n\t\t\t\t\t// Its context is no longer the one last sent.\n\t\t\t\t\tcontextTokens = undefined;\n\t\t\t\t}\n\t\t\t\tif (followed.undone.length > 0) {\n\t\t\t\t\tconst summary = await this.summarizeUndone(followed, signal);\n\t\t\t\t\ttokens = addTokens(tokens, summary.usage);\n\t\t\t\t\tunreported ||= summary.called && !summary.usage;\n\t\t\t\t\tconst note = await undoNote({\n\t\t\t\t\t\tconversation: this.conversation,\n\t\t\t\t\t\thistory: this.history,\n\t\t\t\t\t\tfollowed,\n\t\t\t\t\t\t...(summary.text ? { summary: summary.text } : {}),\n\t\t\t\t\t}).catch((error: unknown) => {\n\t\t\t\t\t\tthrow classifyLocalFailure(error, 'The workspace history could not be read');\n\t\t\t\t\t});\n\t\t\t\t\trunMessages[0]?.content.unshift({ type: 'text', text: note });\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// After following the history, which may have made every earlier read stale.\n\t\t\tconst reads = this.reads.begin();\n\t\t\tconst repeats = new RepeatedCalls();\n\t\t\tconst loops = new CommandLoops();\n\t\t\t// A tool that does its own work on the model, such as running subagents, counts it here.\n\t\t\tconst spend = (spent: Tokens | undefined, unreportedCall: boolean) => {\n\t\t\t\ttokens = addTokens(tokens, spent);\n\t\t\t\tunreported ||= unreportedCall;\n\t\t\t};\n\t\t\t// Also ends the run at its next boundary when an agent at work failed in a way that ends it.\n\t\t\tconst throwIfProgressFailed = () => {\n\t\t\t\tif (progressFailure) throw progressFailure.error;\n\t\t\t\tbackground.throwIfEnded();\n\t\t\t};\n\t\t\t// The agent's own `askUser` exists only for a run someone can answer, and never beside\n\t\t\t// a consumer's tool of that name, which the consumer gave first and which stays theirs.\n\t\t\tconst offersAsk = options.ask !== undefined && !this.tools.has(askUserName);\n\t\t\tconst tools = offersAsk ? [...this.toolDefinitions, askUserDefinition] : this.toolDefinitions;\n\t\t\tseen.tools = tools;\n\t\t\t// Recorded only once the run ends in a way that keeps it, so it never leaves a tool call\n\t\t\t// without its result; a run that is not kept gives its note on what was undone again.\n\t\t\tconst remember = () => {\n\t\t\t\tunkept.length = 0;\n\t\t\t\tthis.conversation.addRunAfter(after, runMessages, context.historyRun);\n\t\t\t\t// With the turns that read them, and only then.\n\t\t\t\treads.commit();\n\t\t\t\tif (followed) this.seenRevision = followed.latestRevision;\n\t\t\t\tthis.contextTokens = contextTokens;\n\t\t\t};\n\t\t\t// A run kept although it failed stops its agents first, and tells the next run what\n\t\t\t// became of each one, which would otherwise wait for answers that never come.\n\t\t\tconst keepFailed = async () => {\n\t\t\t\tawait background.stop();\n\t\t\t\tconst ended = background.takeAnswers();\n\t\t\t\tif (ended) runMessages.push(ended);\n\t\t\t\tremember();\n\t\t\t};\n\t\t\t// Whether the context outgrew the model at the last call, so this one compacts it first,\n\t\t\t// and how large it was, when the provider said.\n\t\t\tlet outgrown = false;\n\t\t\tlet outgrownTokens: number | undefined;\n\t\t\t// A summary the model failed to write is not asked for again in the same run, unless the\n\t\t\t// context no longer fits.\n\t\t\tlet summaryFailed = false;\n\t\t\t// A summary was just written, so the next call measures what it left.\n\t\t\tlet summarized = false;\n\t\t\tconst { compactor } = this;\n\t\t\tfor (let step = 1; step <= this.maxSteps; step++) {\n\t\t\t\t// An agent at work may have narrated through a callback that failed.\n\t\t\t\tthrowIfProgressFailed();\n\t\t\t\tif (\n\t\t\t\t\tcompactor.by === 'harness' &&\n\t\t\t\t\t(outgrown ||\n\t\t\t\t\t\t(!summaryFailed &&\n\t\t\t\t\t\t\tcompactor.at !== undefined &&\n\t\t\t\t\t\t\tcontextTokens !== undefined &&\n\t\t\t\t\t\t\tcontextTokens >= compactor.at))\n\t\t\t\t) {\n\t\t\t\t\tconst compaction = await this.compactHarness(compactor, runMessages, after, {\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t\ttools,\n\t\t\t\t\t\toutgrown,\n\t\t\t\t\t});\n\t\t\t\t\ttokens = addTokens(tokens, compaction.usage);\n\t\t\t\t\tunreported ||= compaction.unreported;\n\t\t\t\t\tif (compaction.compacted) {\n\t\t\t\t\t\tconst compacted = outgrown ? outgrownTokens : contextTokens;\n\t\t\t\t\t\tcontextTokens = undefined;\n\t\t\t\t\t\tsummarized = true;\n\t\t\t\t\t\temit(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: 'compaction',\n\t\t\t\t\t\t\t\tby: 'harness',\n\t\t\t\t\t\t\t\treason: outgrown ? 'maxContext' : 'threshold',\n\t\t\t\t\t\t\t\t...(compacted === undefined ? {} : { contextTokens: compacted }),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tcallback,\n\t\t\t\t\t\t);\n\t\t\t\t\t} else if (outgrown) {\n\t\t\t\t\t\tthrow new MaxContextError('The context no longer fits the model', {\n\t\t\t\t\t\t\tcause: `It no longer fit, and could not be compacted: ${compaction.why ?? 'it is unknown why'}.`,\n\t\t\t\t\t\t});\n\t\t\t\t\t} else {\n\t\t\t\t\t\tsummaryFailed = compaction.called;\n\t\t\t\t\t}\n\t\t\t\t\t// An agent at work may have ended the run while the summary was written.\n\t\t\t\t\tthrowIfProgressFailed();\n\t\t\t\t}\n\t\t\t\tlet called: Awaited<ReturnType<typeof this.llmCall>>;\n\t\t\t\ttry {\n\t\t\t\t\tcalled = await this.llmCall(runMessages, after, {\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t\tstep,\n\t\t\t\t\t\tcallback,\n\t\t\t\t\t\ttools,\n\t\t\t\t\t\t// The harness's own compactor leaves the provider's off.\n\t\t\t\t\t\tcompactAt: compactor.by === 'harness' ? undefined : outgrown ? 'now' : compactor.at,\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// Compacted once and tried again, even with compaction off: a second time in a row,\n\t\t\t\t\t// with nothing to compact it, or no step left to try ends the run.\n\t\t\t\t\tif (\n\t\t\t\t\t\t!(error instanceof MaxContextError) ||\n\t\t\t\t\t\toutgrown ||\n\t\t\t\t\t\t(compactor.by === 'provider' && !this.llmClient.checkCompactAt) ||\n\t\t\t\t\t\tstep === this.maxSteps\n\t\t\t\t\t) {\n\t\t\t\t\t\tthrow error;\n\t\t\t\t\t}\n\t\t\t\t\t// Billed, and already narrated as a step.\n\t\t\t\t\ttokens = addTokens(tokens, error.tokens);\n\t\t\t\t\tunreported ||= error.usageUnreported;\n\t\t\t\t\tthis.warnContextOutgrown();\n\t\t\t\t\toutgrown = true;\n\t\t\t\t\toutgrownTokens = error.tokens && contextSize(error.tokens);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst { response, context: sent } = called;\n\t\t\t\ttokens = addTokens(tokens, response.usage);\n\t\t\t\tunreported ||= !response.usage;\n\t\t\t\tcontextTokens = response.usage && contextSize(response.usage);\n\t\t\t\t// What a summary keeps word for word may stay past the threshold: summarizing it again\n\t\t\t\t// on every step would cost a whole context each time and keep nothing less.\n\t\t\t\tif (\n\t\t\t\t\tsummarized &&\n\t\t\t\t\tcompactor.at !== undefined &&\n\t\t\t\t\tcontextTokens !== undefined &&\n\t\t\t\t\tcontextTokens >= compactor.at\n\t\t\t\t) {\n\t\t\t\t\tsummaryFailed = true;\n\t\t\t\t\tthis.warnCompactionFailed(\n\t\t\t\t\t\t`what the summary kept is still ${String(contextTokens)} tokens, past the threshold of ${String(compactor.at)}, so the context is not compacted again in this run unless it no longer fits`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tsummarized = false;\n\t\t\t\t// After the tokens are counted, so a throwing callback still reports them, and for an\n\t\t\t\t// unusable answer too: the call was sent, and billed.\n\t\t\t\tthis.narrateStep(step, response.usage, { context: sent, tools }, callback);\n\t\t\t\tif (response.message.content.some(part => part.type === 'compaction')) {\n\t\t\t\t\temit(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: 'compaction',\n\t\t\t\t\t\t\tby: 'provider',\n\t\t\t\t\t\t\treason: outgrown ? 'maxContext' : 'threshold',\n\t\t\t\t\t\t\t...(response.compactedContextTokens === undefined\n\t\t\t\t\t\t\t\t? {}\n\t\t\t\t\t\t\t\t: { contextTokens: response.compactedContextTokens }),\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcallback,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\toutgrown = false;\n\t\t\t\tthrowIfProgressFailed();\n\t\t\t\tif (response.stopReason === 'truncated') {\n\t\t\t\t\t// What it wrote before the output limit, kept with the run so the next run can\n\t\t\t\t\t// take it up. Not its calls, whose input may be cut, nor what only the provider\n\t\t\t\t\t// reads back, which it may refuse incomplete.\n\t\t\t\t\tconst written = response.message.content.filter(\n\t\t\t\t\t\tpart => part.type === 'text' || part.type === 'reasoning',\n\t\t\t\t\t);\n\t\t\t\t\tfor (const part of written) narrate(part, callback);\n\t\t\t\t\tif (written.length > 0) runMessages.push({ role: 'assistant', content: written });\n\t\t\t\t\tawait keepFailed();\n\t\t\t\t\tthrow new UnrecoverableError('The LLM stopped before completing its answer', {\n\t\t\t\t\t\tcause:\n\t\t\t\t\t\t\t'The model stopped with \"truncated\". The run, and what the answer held before the limit, are kept in the conversation.',\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tif (response.stopReason !== 'completed') {\n\t\t\t\t\t// Its tokens are already counted with the run's, which the failure carries. A run\n\t\t\t\t\t// that ends so is not remembered.\n\t\t\t\t\tthrow new UnrecoverableError('The LLM stopped before completing its answer', {\n\t\t\t\t\t\tcause: `The model stopped with \"${response.stopReason}\".`,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\trunMessages.push(response.message);\n\n\t\t\t\t// Tool calls are narrated as they start, in `runTools`, and never if they do not run.\n\t\t\t\tfor (const part of response.message.content) {\n\t\t\t\t\tif (part.type !== 'toolCall') narrate(part, callback);\n\t\t\t\t}\n\n\t\t\t\tconst calls = response.message.content.filter(part => part.type === 'toolCall');\n\t\t\t\tif (calls.length === 0) {\n\t\t\t\t\t// An answer given while agents work, or before the model read what they answered,\n\t\t\t\t\t// is a wait: the model goes on with their answers. So is one given before it read\n\t\t\t\t\t// what the user sent, while a step is left to answer it; otherwise the message waits\n\t\t\t\t\t// in the inbox for the next run.\n\t\t\t\t\tconst lastStep = step === this.maxSteps;\n\t\t\t\t\tlet answers = background.takeAnswers();\n\t\t\t\t\tlet sent = lastStep ? undefined : takeSent();\n\t\t\t\t\tif (!answers && !sent && background.working && !lastStep) {\n\t\t\t\t\t\tawait background.nextAnswer();\n\t\t\t\t\t\tthrowIfProgressFailed();\n\t\t\t\t\t\tanswers = background.takeAnswers();\n\t\t\t\t\t\tsent = takeSent();\n\t\t\t\t\t}\n\t\t\t\t\tif (answers || sent || background.working) {\n\t\t\t\t\t\tif (lastStep) {\n\t\t\t\t\t\t\tthrow new UnrecoverableError('The LLM did not finish within its step limit', {\n\t\t\t\t\t\t\t\tcause: `The model was still waiting for the agents it sent after ${String(this.maxSteps)} steps.`,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (answers) runMessages.push(answers);\n\t\t\t\t\t\tif (sent) runMessages.push(sent);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tremember();\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\t// Only the final answer: text from earlier steps was narrated as it came.\n\t\t\t\t\t\tresponse: response.message.content\n\t\t\t\t\t\t\t.filter(part => part.type === 'text')\n\t\t\t\t\t\t\t.map(part => part.text)\n\t\t\t\t\t\t\t.join('\\n'),\n\t\t\t\t\t\ttokens: unreported || background.usageUnknown ? undefined : tokens,\n\t\t\t\t\t\tduration: (Date.now() - start) / 1000,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\t// Before running them again: the model has already seen what they return.\n\t\t\t\tlet repeatedNote: string | undefined;\n\t\t\t\t// Not on the last step, whose calls never run: there is nothing to let go on.\n\t\t\t\tif (step < this.maxSteps && repeats.count(calls) >= repeatedAnswersAt) {\n\t\t\t\t\tconst decision = await this.decideOnLoop(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tquestion: repeatQuestion(calls.map(describeCall).join('\\n')),\n\t\t\t\t\t\t\tfailure: 'The LLM repeated the same tool calls',\n\t\t\t\t\t\t\tstopped: repeatStop,\n\t\t\t\t\t\t\tnote: repeatNote,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t() => loops.extend(calls.map(callKey)),\n\t\t\t\t\t\toptions,\n\t\t\t\t\t);\n\t\t\t\t\tif (typeof decision !== 'string') {\n\t\t\t\t\t\t// Kept like a run stopped on a command, every call given a result.\n\t\t\t\t\t\tconst [first, ...rest] = calls.map(notRun);\n\t\t\t\t\t\trunMessages.push({\n\t\t\t\t\t\t\trole: 'tool',\n\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t...(first\n\t\t\t\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t...first,\n\t\t\t\t\t\t\t\t\t\t\t\toutput: `Not run: the run stopped here. ${decision.cause}`,\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t\t\t: []),\n\t\t\t\t\t\t\t\t...rest,\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t});\n\t\t\t\t\t\tawait keepFailed();\n\t\t\t\t\t\tthrow decision;\n\t\t\t\t\t}\n\t\t\t\t\trepeats.reset();\n\t\t\t\t\trepeatedNote = decision;\n\t\t\t\t}\n\n\t\t\t\t// On the last step no call is left to send the results to, so the tools do not run.\n\t\t\t\tif (step < this.maxSteps) {\n\t\t\t\t\tconst { message, stopped } = await this.runTools(\n\t\t\t\t\t\tcalls,\n\t\t\t\t\t\toptions,\n\t\t\t\t\t\teffects,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\trun: context,\n\t\t\t\t\t\t\treads,\n\t\t\t\t\t\t\tonProgress,\n\t\t\t\t\t\t\tspend,\n\t\t\t\t\t\t\tdepth: delegation?.depth ?? 0,\n\t\t\t\t\t\t\t...(delegation?.writeCeiling ? { writeCeiling: delegation.writeCeiling } : {}),\n\t\t\t\t\t\t\t...(this.writeRoots ? { agentWriteRoots: this.writeRoots } : {}),\n\t\t\t\t\t\t\t...(options.approve ? { approve: options.approve } : {}),\n\t\t\t\t\t\t\t...(options.ask ? { ask: options.ask } : {}),\n\t\t\t\t\t\t},\n\t\t\t\t\t\tthrowIfProgressFailed,\n\t\t\t\t\t\tloops,\n\t\t\t\t\t\tbackground,\n\t\t\t\t\t);\n\t\t\t\t\trunMessages.push(repeatedNote === undefined ? message : withNote(message, repeatedNote));\n\t\t\t\t\t// Kept like a run cut by the output limit: the user may take it up.\n\t\t\t\t\tif (stopped) {\n\t\t\t\t\t\tawait keepFailed();\n\t\t\t\t\t\tthrow stopped;\n\t\t\t\t\t}\n\t\t\t\t\t// What agents answered and the user sent meanwhile, after the results the model is\n\t\t\t\t\t// waiting for.\n\t\t\t\t\tconst answers = background.takeAnswers();\n\t\t\t\t\tif (answers) runMessages.push(answers);\n\t\t\t\t\tconst sent = takeSent();\n\t\t\t\t\tif (sent) runMessages.push(sent);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthrow new UnrecoverableError('The LLM did not finish within its step limit', {\n\t\t\t\tcause: `The model was still calling tools after ${String(this.maxSteps)} steps.`,\n\t\t\t});\n\t\t} catch (error) {\n\t\t\t// The run ends only after the agents still working, which stop with it: what they\n\t\t\t// changed and spent is the run's.\n\t\t\tawait background.stop();\n\t\t\t// A run not kept read nothing: what it took belongs to the next attempt or run.\n\t\t\tinbox?.giveBack(unkept);\n\t\t\tlet failure = error;\n\t\t\tif (effects.toolRan && error instanceof RecoverableError) {\n\t\t\t\t// RetryingAgent would run the whole prompt again, and with it every tool this run\n\t\t\t\t// already executed, so a failure after one ran must not invite a retry.\n\t\t\t\tconst unrecoverable = new UnrecoverableError(error.message, {\n\t\t\t\t\tcause: error.cause,\n\t\t\t\t\ttokens: error.tokens,\n\t\t\t\t\tusageUnreported: error.usageUnreported,\n\t\t\t\t});\n\t\t\t\tunrecoverable.stack = error.stack;\n\t\t\t\tfailure = unrecoverable;\n\t\t\t}\n\n\t\t\t// The run spent the tokens of every step before the one that failed.\n\t\t\tthrow withSpentTokens(failure, tokens, unreported || background.usageUnknown);\n\t\t} finally {\n\t\t\tstopListening?.();\n\t\t}\n\t}\n}\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Message } from '#src/llm/domain/message';
|
|
2
|
+
/**
|
|
3
|
+
* Where the recent compactor cuts `context`, the context the model was last sent with what the
|
|
4
|
+
* run added since: everything before the cut is summarized, and the run's prompt and its last
|
|
5
|
+
* answers, each with its tool results, are kept word for word after the summary. Answers of
|
|
6
|
+
* earlier runs are always summarized, so what is kept starts at the prompt and keeps its order.
|
|
7
|
+
* `undefined` when there is no answer to summarize.
|
|
8
|
+
*
|
|
9
|
+
* @param prompt the run's prompt. Found by identity; when it is not there, an earlier compaction
|
|
10
|
+
* of this run kept it, first, so it is in the summary's message, which is summarized again.
|
|
11
|
+
*/
|
|
12
|
+
export declare function recentCut(context: Message[], prompt: Message, keptSteps: number): {
|
|
13
|
+
summarized: Message[];
|
|
14
|
+
kept: Message[];
|
|
15
|
+
} | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Copies of `messages` without what only a provider reads back, which a changed context before
|
|
18
|
+
* it may no longer accept: its signed reasoning and its compactions. The last answer keeps its
|
|
19
|
+
* reasoning, since the provider needs it to go on with that answer's tool calls.
|
|
20
|
+
*/
|
|
21
|
+
export declare function withoutReplayedReasoning(messages: Message[]): Message[];
|
|
22
|
+
/** What the recent compactor keeps, as its summary requests tell the model. */
|
|
23
|
+
export declare function recentlyKept(keptSteps: number): string;
|
|
24
|
+
/**
|
|
25
|
+
* What the model is asked once its context passed the threshold, after that whole context.
|
|
26
|
+
*
|
|
27
|
+
* @param kept what is kept word for word after the summary, as `recentlyKept` says it.
|
|
28
|
+
*/
|
|
29
|
+
export declare function summaryRequest(kept: string): Message;
|
|
30
|
+
/**
|
|
31
|
+
* What the model is asked when the context no longer fit: the part to summarize, as text, since
|
|
32
|
+
* it can no longer be sent as it was.
|
|
33
|
+
*/
|
|
34
|
+
export declare function transcriptSummaryRequest(summarized: Message[], kept: string): Message;
|
|
35
|
+
/**
|
|
36
|
+
* `messages` as plain text, for a model to summarize: who said or did what, each part cut at
|
|
37
|
+
* `partChars`, and the whole at `maxChars`, marked when cut.
|
|
38
|
+
*/
|
|
39
|
+
export declare function messagesAsText(messages: Message[], maxChars: number, partChars: number): string;
|