@mikode13/harness 11.1.0 → 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 +48 -10
- package/dist/agent/domain/agent.d.ts +17 -0
- package/dist/agent/domain/agent.js.map +1 -1
- package/dist/agent/domain/runContext.d.ts +5 -0
- package/dist/agent/domain/runContext.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 +48 -2
- package/dist/engines/domain/model/llmAgent.js +351 -14
- 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 +40 -12
- package/dist/factory/infrastructure/agentLLMFactory.js +114 -18
- package/dist/factory/infrastructure/agentLLMFactory.js.map +1 -1
- package/dist/index.d.ts +1 -1
- 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/tools/domain/preparedCall.d.ts +2 -1
- 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 +4 -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.js +1 -0
- package/dist/tools/infrastructure/fileTools.js.map +1 -1
- package/dist/tools/infrastructure/removeWorktreeTool.js +7 -1
- package/dist/tools/infrastructure/removeWorktreeTool.js.map +1 -1
- 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 +13 -1
- package/dist/tools/infrastructure/workspaceWrites.js +18 -1
- package/dist/tools/infrastructure/workspaceWrites.js.map +1 -1
- 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/package.json +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agentLLMFactory.js","sourceRoot":"","sources":["../../../src/factory/infrastructure/agentLLMFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,OAAO,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAE9D,OAAO,EACN,eAAe,EACf,eAAe,EACf,yBAAyB,GACzB,MAAM,yCAAyC,CAAC;AACjD,OAAO,EACN,eAAe,EACf,YAAY,EACZ,sBAAsB,GACtB,MAAM,yCAAyC,CAAC;AACjD,OAAO,EACN,oBAAoB,EACpB,mCAAmC,EACnC,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,EACpB,mCAAmC,GACnC,MAAM,mDAAmD,CAAC;AAC3D,OAAO,EAAE,yBAAyB,EAAE,MAAM,mEAAmE,CAAC;AAE9G,OAAO,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AACtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAErD,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAE3D,OAAO,EAGN,WAAW,EAEX,gBAAgB,EAChB,iBAAiB,GACjB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EACN,cAAc,EAEd,YAAY,EAEZ,SAAS,EACT,aAAa,EACb,gBAAgB,GAEhB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,EAAE,qBAAqB,EAAE,MAAM,2CAA2C,CAAC;AAClF,OAAO,EAAE,wBAAwB,EAAE,MAAM,8CAA8C,CAAC;AACxF,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AACpE,OAAO,EACN,qBAAqB,EACrB,sBAAsB,GACtB,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,0CAA0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E;YAC/C,KAAK,EAAE,QAAQ,CAAC,KAAK;YACrB,eAAe,EAAE,QAAQ,CAAC,eAAe;YACzC,YAAY,EAAE,MAAM,CACnB,UAAU,EACV,aAAa,CAAC,QAAQ,EACtB,YAAY,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,mCAAmC,CACzE;YACD,KAAK,EAAE,eAAe;YACtB,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,SAAS,EAAE,UAAU,CAAC,QAAQ;YAC9B,WAAW;YACX,YAAY,EAAE,aAAa,CAAC,UAAU,CAAC;YACvC,GAAG,MAAM;SACT,CAAC;QACF,aAAa,EAAE,MAAM,MAAM,CAC1B,KAAK,CAAC,QAAQ,EACd,UAAU,EACV,MAAM,CACL,UAAU,EACV,aAAa,CAAC,QAAQ,EACtB,YAAY,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,mCAAmC,CACzE,CACD;QACD,yBAAyB,EAAE,IAAI,yBAAyB,EAAE;QAC1D,MAAM;KACN,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { resolve } from 'node:path';\nimport type { Agent } from '#src/agent/domain/agent';\nimport type { Transcript, TranscriptCallback } from '#src/agent/domain/transcript';\nimport type { HistoryReader } from '#src/engines/domain/model/historyFollower';\nimport { LLMAgent } from '#src/engines/domain/model/llmAgent';\nimport type { LLMClient } from '#src/llm/domain/llm';\nimport {\n\tClaudeLLMClient,\n\tclaudeLLMModels,\n\tclaudeLLMReasoningEfforts,\n} from '#src/llm/infrastructure/claudeLLMClient';\nimport {\n\tOpenAILLMClient,\n\topenAIModels,\n\topenAIReasoningEfforts,\n} from '#src/llm/infrastructure/openAILLMClient';\nimport {\n\texecutorInstructions,\n\texecutorInstructionsWithoutCommands,\n\tOrchestratorAgent,\n\tplannerInstructions,\n\treviewerInstructions,\n\treviewerInstructionsWithoutCommands,\n} from '#src/orchestration/domain/model/orchestratorAgent';\nimport { ReviewerDecisionValidator } from '#src/orchestration/infrastructure/model/reviewerDecisionValidator';\nimport type { RecoveryStore } from '#src/recovery/domain/recoveryStore';\nimport { RetryingAgent } from '#src/retry/domain/model/retryingAgent';\nimport { InvalidAgentConfigError } from '#src/shared/domain/errors';\nimport { isOneOf } from '#src/shared/domain/isOneOf';\nimport type { ILogger } from '#src/shared/domain/logger';\nimport { Logger } from '#src/shared/infrastructure/logger';\nimport type { WorkspaceRoot } from '#src/tools/domain/accessPolicy';\nimport {\n\ttype CommandRole,\n\ttype Commands,\n\tcommandsFor,\n\ttype Formatter,\n\tvalidateCommands,\n\tvalidateFormatter,\n} from '#src/tools/domain/commands';\nimport type { AgentTool } from '#src/tools/domain/preparedCall';\nimport type { Tool } from '#src/tools/domain/tool';\nimport {\n\tcommandToolFor,\n\ttype FileTool,\n\tfileToolsFor,\n\ttype OpenedWorkspace,\n\topenStore,\n\topenWorkspace,\n\tstateDirectoryOf,\n\ttype WorkspaceOptions,\n} from '#src/tools/infrastructure/fileTools';\nimport type { DelegationTool } from '#src/tools/infrastructure/agentAsTool';\nimport { createExploreTool } from '#src/tools/infrastructure/exploreTool';\nimport { createShowChangesTool } from '#src/tools/infrastructure/showChangesTool';\nimport { createRemoveWorktreeTool } from '#src/tools/infrastructure/removeWorktreeTool';\nimport { listWorktrees } from '#src/tools/infrastructure/worktrees';\nimport {\n\tcreateTrackedReadFile,\n\tcreateTrackedReadFiles,\n} from '#src/tools/infrastructure/trackedReadFile';\nimport { createWorkspaceTools } from '#src/tools/infrastructure/workspaceTools';\nimport { isAgentProvider, orchestratorRolesFor, type Role } from './agentFactory.ts';\nimport {\n\tagentProviders,\n\ttype AgentModel,\n\ttype AgentProvider,\n\ttype CreateOrchestratorOptions,\n\ttype ReasoningEffort,\n} from './types.ts';\n\n/** The models each provider's model API accepts. */\nexport const llmModels = {\n\tanthropic: claudeLLMModels,\n\topenai: openAIModels,\n} as const satisfies Readonly<Record<AgentProvider, readonly AgentModel[]>>;\n\n/** The reasoning efforts each provider's model API accepts. */\nexport const llmReasoningEfforts = {\n\tanthropic: claudeLLMReasoningEfforts,\n\topenai: openAIReasoningEfforts,\n} as const satisfies Readonly<Record<AgentProvider, readonly ReasoningEffort[]>>;\n\n/** Narrows a model to one accepted by the selected provider's model API. */\nexport function isLLMModelOf<Provider extends AgentProvider>(\n\tprovider: Provider,\n\tvalue: string,\n): value is (typeof llmModels)[Provider][number] {\n\treturn isOneOf(llmModels[provider], value);\n}\n\n/** Narrows a reasoning effort to one accepted by the selected provider's model API. */\nexport function isLLMReasoningEffortOf<Provider extends AgentProvider>(\n\tprovider: Provider,\n\tvalue: string,\n): value is (typeof llmReasoningEfforts)[Provider][number] {\n\treturn isOneOf(llmReasoningEfforts[provider], value);\n}\n\nexport interface CreateLLMAgentOptions {\n\t/**\n\t * Defaults to `'sonnet'` on Anthropic and `'gpt-5.6-luna'` on OpenAI. The provider's client\n\t * rejects a model it does not support.\n\t */\n\tmodel?: AgentModel;\n\t/** Defaults to `'high'`. The provider's client rejects an effort it does not support. */\n\treasoningEffort?: ReasoningEffort;\n\t/** Sent as the model's instructions on every call. */\n\tsystemPrompt: string;\n\t/**\n\t * The tools the model may call: the consumer's own, those of `createFileTools`, and agents\n\t * offered with `agentAsTool`. Defaults to none.\n\t */\n\ttools?: (Tool | FileTool | DelegationTool)[];\n\t/**\n\t * The folders the agent works on, the same as given to `createFileTools`. With it, the agent\n\t * follows the workspace's history: after the user undoes runs, its next run starts from the\n\t * conversation as it was, and is told what was undone. The system prompt is followed by the\n\t * roots and how to name a file in them. It gives no tools: pass those of `createFileTools`\n\t * in `tools`, and an agent given a workspace and no tools is refused.\n\t */\n\tworkspace?: WorkspaceOptions;\n\t/**\n\t * With `workspace`, a summary of what was undone, from the provider's cheap model, in place\n\t * of the undone prompts. That is Claude Haiku 5.5 or `gpt-5.6-luna`, at high effort, and the\n\t * call is billed with the run's tokens. Defaults to `true`.\n\t */\n\tsummarizeUndone?: boolean;\n\t/**\n\t * How many calls to the model one run may make before it fails. Defaults to 65, with no upper\n\t * bound. A run that asks for exactly the same tool calls 5 times in a row fails before that.\n\t */\n\tmaxSteps?: number;\n\t/**\n\t * The input tokens at which the provider compacts the conversation on its side: it replaces\n\t * every turn before that call with its own summary, which only its model reads back. The\n\t * conversation keeps every original turn. Without it, the conversation is never compacted.\n\t * At least 50,000 on Anthropic.\n\t */\n\tcompactAt?: number;\n\t/**\n\t * Runs every tool call without asking, `destructive` ones included, for CI where no one can\n\t * answer. Without it, a `destructive` call goes to the run's `approve`, or is denied.\n\t */\n\tautoApprove?: boolean;\n\t/** Defaults to warnings on stderr. */\n\tlogger?: ILogger;\n\t/**\n\t * Receives what the model saw in each run once the run ended, completed, failed or\n\t * cancelled, for debugging. See `Transcript`. Without it, nothing is kept.\n\t */\n\tonTranscript?: TranscriptCallback;\n}\n\n/** A limit per role of `createLLMOrchestrator`; a role left out keeps its default. */\nexport type RoleSteps = Partial<Record<OrchestratorRole, number>>;\n\n/** A number of tokens per role of `createLLMOrchestrator`; a role left out keeps its default. */\nexport type RoleTokens = Partial<Record<OrchestratorRole, number>>;\n\n// The same three roles a command can be given to.\ntype OrchestratorRole = CommandRole;\n\n// The executor reads, edits and checks, so it needs more calls than the roles that only read.\nconst defaultRoleSteps: Record<OrchestratorRole, number> = {\n\tplanner: 65,\n\texecutor: 80,\n\treviewer: 65,\n};\n\n// No role compacts unless asked to.\nconst defaultRoleCompaction: Record<OrchestratorRole, number | undefined> = {\n\tplanner: undefined,\n\texecutor: undefined,\n\treviewer: undefined,\n};\n\n/**\n * Each role's value of the option `name`, from one number for all of them or a number per role.\n * Each number is checked by whatever takes it.\n *\n * @throws {InvalidAgentConfigError} for a value that is neither, and for a role that does not\n * exist, which is a typo that would otherwise leave that role on its default without a word.\n */\nfunction perRole<T extends number | undefined>(\n\tname: string,\n\tvalue: unknown,\n\tdefaults: Record<OrchestratorRole, T>,\n\t{ unit, example }: { unit: string; example: string },\n): Record<OrchestratorRole, T | number> {\n\tif (value === undefined) return defaults;\n\tif (typeof value === 'number') return { planner: value, executor: value, reviewer: value };\n\t// Untyped input, such as the CLI's configuration file, can hold `null` or a list here.\n\tif (typeof value !== 'object' || value === null || Array.isArray(value)) {\n\t\tthrow new InvalidAgentConfigError(\n\t\t\t`${name} must be a number or an object of ${unit} per role, such as ${example}`,\n\t\t);\n\t}\n\tconst unknown = Object.keys(value).filter(role => !(role in defaults));\n\tif (unknown.length > 0) {\n\t\tthrow new InvalidAgentConfigError(\n\t\t\t`${name} names roles that do not exist: ${unknown.join(', ')}; expected planner, executor or reviewer`,\n\t\t);\n\t}\n\t// A role given as `undefined`, which untyped input can do, keeps its default.\n\tconst given = Object.entries(value as Record<string, unknown>).filter(\n\t\t([, each]) => each !== undefined,\n\t);\n\treturn { ...defaults, ...Object.fromEntries(given) };\n}\n\nexport interface CreateLLMOrchestratorOptions extends CreateOrchestratorOptions {\n\t/**\n\t * The folders the agents work on. The executor changes files only in a `write` root, every\n\t * change recorded in the workspace's history. Defaults to the current working directory,\n\t * read only.\n\t */\n\tworkspace?: WorkspaceOptions;\n\t/**\n\t * How many calls to the model one run of each role may make: one number for every role, or a\n\t * number per role. Defaults to 80 for the executor and 65 for the planner and the reviewer,\n\t * with no upper bound. A run that asks for exactly the same tool calls 5 times in a row fails\n\t * before its limit.\n\t */\n\tmaxSteps?: number | RoleSteps;\n\t/**\n\t * The input tokens at which each role's provider compacts its conversation, as\n\t * `CreateLLMAgentOptions.compactAt`: one number for every role, or a number per role. Without\n\t * it, no role compacts.\n\t */\n\tcompactAt?: number | RoleTokens;\n\t/**\n\t * Commands the roles may run, such as the project's tests, through `runCommand`. Each goes to\n\t * the roles its `roles` names, the executor by default. See `createFileTools`. Each needs a\n\t * `write` root to run in.\n\t */\n\tcommands?: Commands;\n\t/**\n\t * A program the executor's edits run on each file they create or change, such as the\n\t * project's formatter. See `createFileTools`. It needs a `write` root to run in.\n\t */\n\tformatter?: Formatter;\n\t/**\n\t * A summary of what the user undid, from the planner's provider's cheap model, for every\n\t * role. See `CreateLLMAgentOptions.summarizeUndone`. Defaults to `true`.\n\t */\n\tsummarizeUndone?: boolean;\n\t/**\n\t * Receives what the model saw in each run of each role and each explorer, once the run\n\t * ended, for debugging. Each transcript names its role. See `Transcript`.\n\t */\n\tonTranscript?: TranscriptCallback;\n\t/**\n\t * Gives the executor `removeWorktree`, which removes a worktree of the repository the first\n\t * root is in when the user asks. See `createFileTools`.\n\t */\n\tremoveWorktree?: boolean;\n}\n\nconst defaultLLMAgentModels = {\n\tanthropic: 'sonnet',\n\topenai: 'gpt-5.6-luna',\n} as const satisfies Record<AgentProvider, AgentModel>;\n\nfunction unknownProvider(provider: never): InvalidAgentConfigError {\n\treturn new InvalidAgentConfigError(\n\t\t`\"${String(provider)}\" is not an agent provider; expected one of: ${agentProviders.join(', ')}`,\n\t);\n}\n\nfunction llmClientFor(\n\tprovider: AgentProvider,\n\t{\n\t\tmodel,\n\t\treasoningEffort,\n\t\tcompactAt,\n\t\tsystemPrompt,\n\t\tlogger,\n\t}: {\n\t\tmodel?: AgentModel;\n\t\treasoningEffort?: ReasoningEffort;\n\t\tcompactAt?: number | undefined;\n\t\tsystemPrompt: string;\n\t\tlogger: ILogger;\n\t},\n): LLMClient {\n\tswitch (provider) {\n\t\tcase 'anthropic':\n\t\t\treturn new ClaudeLLMClient({\n\t\t\t\tmodel: model ?? defaultLLMAgentModels.anthropic,\n\t\t\t\treasoningEffort,\n\t\t\t\tcompactAt,\n\t\t\t\tsystemPrompt,\n\t\t\t\tlogger,\n\t\t\t});\n\t\tcase 'openai':\n\t\t\treturn new OpenAILLMClient({\n\t\t\t\tmodel: model ?? defaultLLMAgentModels.openai,\n\t\t\t\treasoningEffort,\n\t\t\t\tcompactAt,\n\t\t\t\tsystemPrompt,\n\t\t\t\tlogger,\n\t\t\t});\n\t\tdefault:\n\t\t\t// Reachable from untyped input.\n\t\t\tthrow unknownProvider(provider);\n\t}\n}\n\n/** The provider's cheap model, for the summary of what was undone. */\nfunction summarizerFor(provider: AgentProvider, logger: ILogger): LLMClient {\n\treturn provider === 'anthropic'\n\t\t? new ClaudeLLMClient({ model: 'haiku', reasoningEffort: 'high', systemPrompt: '', logger })\n\t\t: new OpenAILLMClient({\n\t\t\t\tmodel: 'gpt-5.6-luna',\n\t\t\t\treasoningEffort: 'high',\n\t\t\t\tsystemPrompt: '',\n\t\t\t\tlogger,\n\t\t\t});\n}\n\n/**\n * The workspace's history, opened on first use, so a factory that builds an agent stays\n * synchronous. Every agent and every file tool of one workspace reads the same files on disk.\n */\nfunction historyOf(workspace: WorkspaceOptions, logger: ILogger): HistoryReader {\n\t// Checked now: an agent with no root to follow is a setup error, not a first-run one.\n\tif (workspace.roots.length === 0) {\n\t\tthrow new InvalidAgentConfigError('A workspace needs at least one root');\n\t}\n\tlet store: Promise<RecoveryStore> | undefined;\n\tconst open = () => {\n\t\tstore ??= stateDirectoryOf(workspace)\n\t\t\t.then(directory => openStore(workspace, directory, logger))\n\t\t\t.catch((error: unknown) => {\n\t\t\t\t// Not kept: the next run tries again, as one whose disk was full for a moment.\n\t\t\t\tstore = undefined;\n\t\t\t\tthrow error;\n\t\t\t});\n\t\treturn store;\n\t};\n\treturn {\n\t\tlistRuns: async () => (await open()).listRuns(),\n\t\tlistRevisions: async () => (await open()).listRevisions(),\n\t\treadRun: async runId => (await open()).readRun(runId),\n\t};\n}\n\n/**\n * What the model is told about the workspace after its instructions: the roots, which it may\n * change, and how to name a file. A host path in an error sends the model looking for it, so\n * the real root is given here once.\n */\nfunction workspaceGuidance(roots: WorkspaceRoot[]): string {\n\tconst [first, ...others] = roots.map(root => ({ ...root, path: resolve(root.path) }));\n\tif (!first) return '';\n\tconst described = [first, ...others].map(\n\t\t({ path, access }) => `- ${path}${access === 'write' ? '' : ' (read only)'}`,\n\t);\n\treturn [\n\t\t'The workspace:',\n\t\t...described,\n\t\t`Name a file by its path relative to ${first.path}, such as src/index.ts, and a file in another folder of the workspace by its full path. Read a file before you change it.`,\n\t].join('\\n');\n}\n\nfunction withGuidance(systemPrompt: string, guidance: string): string {\n\treturn guidance === '' ? systemPrompt : `${systemPrompt}\\n\\n${guidance}`;\n}\n\n/** An `LLMAgent` on `provider`, wrapped in the harness's retry policy. */\nfunction buildLLMAgent(\n\tprovider: AgentProvider,\n\t{\n\t\tmodel,\n\t\treasoningEffort,\n\t\tsystemPrompt,\n\t\ttools,\n\t\thistory,\n\t\tsummarizer,\n\t\tmaxSteps,\n\t\tcompactAt,\n\t\tautoApprove,\n\t\tlogger,\n\t\tonTranscript,\n\t}: {\n\t\tmodel?: AgentModel;\n\t\treasoningEffort?: ReasoningEffort;\n\t\tsystemPrompt: string;\n\t\ttools: AgentTool[];\n\t\thistory?: HistoryReader;\n\t\tsummarizer?: LLMClient;\n\t\tmaxSteps?: number;\n\t\tcompactAt?: number | undefined;\n\t\tautoApprove?: boolean;\n\t\tlogger: ILogger;\n\t\tonTranscript?: TranscriptCallback | undefined;\n\t},\n): Agent {\n\tconst llmClient = llmClientFor(provider, {\n\t\tmodel,\n\t\treasoningEffort,\n\t\tcompactAt,\n\t\tsystemPrompt,\n\t\tlogger,\n\t});\n\t// LLMAgent records nothing from a failed call, so the original prompt is the whole story.\n\treturn new RetryingAgent({\n\t\tinner: new LLMAgent({\n\t\t\tllmClient,\n\t\t\ttools,\n\t\t\tautoApprove,\n\t\t\tlogger,\n\t\t\t...(history ? { history } : {}),\n\t\t\t...(summarizer ? { summarizer } : {}),\n\t\t\t...(maxSteps === undefined ? {} : { maxSteps }),\n\t\t\t...(onTranscript ? { onTranscript } : {}),\n\t\t}),\n\t\tlogger,\n\t\tnoteFailures: false,\n\t});\n}\n\n/**\n * Builds an agent whose conversation MiKode owns, on a provider's model API, already wrapped in\n * the harness's retry policy. It needs the provider's API key and bills per token, where\n * `createAgent` uses the Agent SDK's login. Each tool judges the risk of each call; a\n * `destructive` one runs only when the run's `approve` allows it, or with `autoApprove`.\n *\n * @throws {InvalidAgentConfigError} for an unknown provider, a model or reasoning effort its\n * client does not support, two tools that share a name, or a workspace given with no tools.\n * @throws {UnrecoverableError} when the client cannot be set up, for example because\n * `OPENAI_API_KEY` is missing. The Anthropic SDK resolves credentials lazily, so a missing\n * `ANTHROPIC_API_KEY` fails the first run instead, with an `UnrecoverableError`.\n */\nexport function createLLMAgent(\n\tprovider: AgentProvider,\n\t{\n\t\tmodel,\n\t\treasoningEffort,\n\t\tsystemPrompt,\n\t\ttools = [],\n\t\tworkspace,\n\t\tsummarizeUndone = true,\n\t\tmaxSteps,\n\t\tcompactAt,\n\t\tautoApprove,\n\t\tlogger = new Logger(),\n\t\tonTranscript,\n\t}: CreateLLMAgentOptions,\n): Agent {\n\t// Told where to work with nothing to work with, the model would only pretend: it writes its\n\t// tool calls as text, and the run returns them as its answer.\n\tif (workspace && tools.length === 0) {\n\t\tthrow new InvalidAgentConfigError(\n\t\t\t'An agent given a workspace needs tools to work on it: pass those of createFileTools in `tools`',\n\t\t);\n\t}\n\treturn buildLLMAgent(provider, {\n\t\tmodel,\n\t\treasoningEffort,\n\t\tsystemPrompt: workspace\n\t\t\t? withGuidance(systemPrompt, workspaceGuidance(workspace.roots))\n\t\t\t: systemPrompt,\n\t\t// A file tool or a delegation tool is a harness tool under its public name.\n\t\ttools: tools as AgentTool[],\n\t\t...(workspace ? { history: historyOf(workspace, logger) } : {}),\n\t\t...(workspace && summarizeUndone ? { summarizer: summarizerFor(provider, logger) } : {}),\n\t\tmaxSteps,\n\t\tcompactAt,\n\t\tautoApprove,\n\t\tlogger,\n\t\tonTranscript,\n\t});\n}\n\n/**\n * The file tools for an agent from `createLLMAgent` on `provider`, over `workspace`, in the\n * provider's own format:\n *\n * - OpenAI: `listFiles`, `searchText`, `readFile`, `readFiles` and its native `apply_patch`;\n * - Anthropic: `listFiles`, `searchText`, its native text editor, whose `view` reads, and\n * `delete_file`.\n *\n * Every one goes through the workspace's access policy: a path outside the roots, a secret,\n * a file `.gitignore` excludes or the harness protects is refused. A change is made only in a\n * `write` root, only from a version the agent read, and is recorded in the workspace's history,\n * so it can be undone. Without a `write` root the tools only read. Give the agent the same\n * `workspace`, so it follows what the history undoes.\n *\n * With `commands`, they include `runCommand`, which runs one of them by name, with only the\n * parameters it declares and never through a shell. Each run asks the approver, showing the\n * program exactly as it will run, and gets a small environment without the provider keys. The\n * files of the `write` roots are captured before it and compared after, so what it changed is\n * in the history too. It is trusted execution, not a sandbox: a command can reach whatever\n * this user can. Not supported on Windows yet.\n *\n * With `formatter`, every file an edit creates or changes is formatted right after, its path\n * the formatter's last argument. The edit shows the lines the formatter rewrote, and the model\n * reads a file it rewrote again before editing it. Like a command it runs without a shell, in a small environment, and what it changes in that file is\n * in the history. When it fails, the file stays as the edit wrote it, and the model is told\n * why. Not supported on Windows yet.\n *\n * With `removeWorktree`, they include `removeWorktree`, which removes a git worktree of the\n * repository the first root is in, when the user asks: its folder and every file in it, never\n * its branch. Each call asks the approver, whose request's `worktree` says what is lost:\n * changes no commit has, and the commits only a detached HEAD holds. It refuses the main folder\n * and a worktree the agent works in. See `createWorktree`.\n *\n * @throws {InvalidAgentConfigError} for an unknown provider, a workspace with no root, or an\n * invalid command or formatter, including one whose `cwd` is not in a `write` root, or any on\n * Windows, or `removeWorktree` with a first root in no git repository.\n * @throws {UnrecoverableError} when no program can read the first root.\n */\nexport async function createFileTools(\n\tprovider: AgentProvider,\n\tworkspace: WorkspaceOptions,\n\t{\n\t\tlogger = new Logger(),\n\t\tcommands,\n\t\tformatter,\n\t\tremoveWorktree = false,\n\t}: {\n\t\tlogger?: ILogger;\n\t\tcommands?: Commands;\n\t\tformatter?: Formatter;\n\t\tremoveWorktree?: boolean;\n\t} = {},\n): Promise<FileTool[]> {\n\t// Reachable from untyped input.\n\tif (!isAgentProvider(provider)) throw unknownProvider(provider);\n\tif (commands !== undefined) validateCommands(commands);\n\tif (formatter !== undefined) validateFormatter(formatter);\n\tconst opened = await openWorkspace(workspace, logger, formatter ? { formatter } : {});\n\treturn (await executorTools(provider, opened, commands, removeWorktree)) as unknown as FileTool[];\n}\n\n/** The executor's file tools, `runCommand` when there are commands, and `removeWorktree`. */\nasync function executorTools(\n\tprovider: AgentProvider,\n\tworkspace: OpenedWorkspace,\n\tcommands: Commands | undefined,\n\tremoveWorktree: boolean,\n): Promise<AgentTool[]> {\n\tconst tools = fileToolsFor(provider, workspace);\n\tif (removeWorktree) tools.push(await removeWorktreeToolFor(workspace));\n\t// Every command may belong to other roles, leaving none for this one.\n\tif (commands === undefined || Object.keys(commands).length === 0) return tools;\n\treturn [...tools, await commandToolFor(workspace, commands)];\n}\n\n/** `removeWorktree` over the repository of the first root, which must be in one. */\nasync function removeWorktreeToolFor({\n\tbase,\n\troots,\n\tstateDirectory,\n}: OpenedWorkspace): Promise<AgentTool> {\n\t// Checked now: a tool that could never work is a setup error, not a first-call one.\n\tawait listWorktrees(base).catch((error: unknown) => {\n\t\tthrow new InvalidAgentConfigError(\n\t\t\t`removeWorktree needs a first root in a git repository, and git 2.36 or later; with ${base}, ${error instanceof Error ? error.message : String(error)}`,\n\t\t);\n\t});\n\treturn createRemoveWorktreeTool({ base, roots, stateDirectory });\n}\n\n/** What an explorer finds and reads with: no edits, no changes, no commands. */\nfunction explorerTools({ read, policy }: OpenedWorkspace): AgentTool[] {\n\tconst finding = createWorkspaceTools(read).filter(\n\t\ttool => tool.name !== 'readFile' && tool.name !== 'readFiles',\n\t);\n\treturn [...finding, createTrackedReadFile(policy), createTrackedReadFiles(policy)];\n}\n\n/**\n * What the planner and the reviewer read with: no edits, the current task's changes, `explore`\n * with `explorer`, and the commands given to their role.\n */\nasync function readingTools(\n\tworkspace: OpenedWorkspace,\n\trole: CommandRole,\n\tcommands: Commands | undefined,\n\texplorer: () => Agent,\n): Promise<AgentTool[]> {\n\tconst { policy, store } = workspace;\n\tconst tools = [\n\t\t...explorerTools(workspace),\n\t\tcreateShowChangesTool({ store, policy }),\n\t\tcreateExploreTool(explorer),\n\t];\n\tconst own = commands && commandsFor(commands, role);\n\tif (!own || Object.keys(own).length === 0) return tools;\n\treturn [...tools, await commandToolFor(workspace, own)];\n}\n\nconst batching =\n\t'When you know you need several files, or several searches, ask for all of them in one answer rather than one at a time: each answer is a step, and steps are limited.';\n\n// For the roles that have `readFiles`, which the executor on Claude does not.\nconst batchingReads =\n\t'When you know you need several files, or several ranges, read them in one readFiles call, and ask for several searches in one answer, rather than one at a time: each answer is a step, and steps are limited.';\n\n// The explorers find and the role reads, as a reader asks a librarian where a book is and then\n// reads it: their reports are where to look, not a summary to work from.\nconst exploring =\n\t'To find where something is in the repository, ask explorers instead of searching yourself: send `explore` the independent questions you have in one call. They work in the background while you go on, and each one answers, once it finishes, with the files and line ranges that hold what you asked. Then read those ranges yourself, all of them in one readFiles call.';\n\n// Each provider's cheaper model, which only finds and reads.\nconst explorerRoles = {\n\tanthropic: { model: 'haiku', reasoningEffort: 'medium' },\n\topenai: { model: 'gpt-5.6-luna', reasoningEffort: 'medium' },\n} as const satisfies Record<AgentProvider, { model: AgentModel; reasoningEffort: ReasoningEffort }>;\n\nconst explorerSteps = 30;\n\nconst explorerInstructions = `You find things in a repository for another agent, which is planning or reviewing a change and asked you one question, as a reader asks a librarian where a book is. Find where the answer is with listFiles, searchText, readFile and readFiles, reading only what you need to be sure. Answer with where it is: each file and the line ranges that matter, and in a sentence what each range holds and why it answers the question. The other agent reads those ranges itself, so do not copy code beyond a line that marks a place. Say what you looked for and could not find. Do not propose changes or a plan. ${batchingReads}`;\n\n// How each role finds its way, sent after the workspace's roots, so it stays short. Only the\n// planner learns the repository; the executor and the reviewer work from its plan, so a plan\n// that leaves them guessing is the planner's to fix, not theirs to make up for.\nconst repositoryGuidance: Record<CommandRole, string> = {\n\tplanner: `Start with AGENTS.md, which says where the architecture and the decisions are, and read only the parts your task needs. Name in the plan every file to change and what to change in it, so the executor needs nothing else. ${exploring} ${batchingReads}`,\n\texecutor: `Work from the plan: read the files it names, and only what you need to change them. Do not study the repository's architecture or decisions; the plan already applied them. ${batching}`,\n\treviewer: `Work from the plan and the changes: read what they touch, and only what you need to judge them. ${exploring} ${batchingReads}`,\n};\n\n/**\n * Builds the planner → executor → reviewer workflow with every role on the model APIs, each\n * holding its role's instructions, or `systemPrompts`, as its system prompt, followed by the\n * workspace's roots.\n *\n * - The planner and the reviewer read: `listFiles`, `searchText`, `readFile`, `readFiles`, `showChanges`,\n * the current task's changes as far as each may read them, and `explore`, which sends up to 4\n * read-only explorers at once on the role's provider's cheaper model, each a new agent that\n * starts from its question and works in the background while the role goes on.\n * - The executor gets its provider's file tools (see `createFileTools`), and changes files only\n * in a `write` root; `autoApprove` reaches only it.\n * - Each role has its own step limit: `maxSteps`, 80 for the executor and 65 for the others by\n * default.\n * - Each role gets `runCommand` with the `commands` whose `roles` name it, the executor by\n * default. A command asks the approver in any role, and its files are captured around it.\n * - When the executor has a command, it is told to finish only once the tests and checks pass,\n * or to say which fail, and the reviewer takes from its response whether they pass. Without\n * one, both are told the tests were not run, and the reviewer judges from the code whether\n * they would pass.\n *\n * One run of the orchestrator is one run of the workspace's history, every round and retry\n * included, and its `AgentResponse` names it. Every role follows what the user undoes.\n * Asynchronous because opening the workspace is.\n *\n * @throws {InvalidAgentConfigError} for an unknown provider, or a workspace with no root.\n * @throws {UnrecoverableError} when a role cannot be set up, for example because\n * `OPENAI_API_KEY` is missing, or when no program can read the repository.\n */\nexport async function createLLMOrchestrator({\n\tprovider,\n\tautoApprove,\n\tsystemPrompts = {},\n\tworkspace = { roots: [{ path: process.cwd(), access: 'read' }] },\n\tmaxSteps,\n\tcompactAt,\n\tcommands,\n\tformatter,\n\tsummarizeUndone = true,\n\tlogger = new Logger(),\n\tonTranscript,\n\tremoveWorktree = false,\n}: CreateLLMOrchestratorOptions = {}): Promise<Agent> {\n\tconst roles = orchestratorRolesFor(provider);\n\tconst steps = perRole('maxSteps', maxSteps, defaultRoleSteps, {\n\t\tunit: 'steps',\n\t\texample: '{ \"executor\": 120 }',\n\t});\n\tconst compaction = perRole('compactAt', compactAt, defaultRoleCompaction, {\n\t\tunit: 'tokens',\n\t\texample: '{ \"executor\": 200000 }',\n\t});\n\tif (formatter !== undefined) validateFormatter(formatter);\n\tconst opened = await openWorkspace(workspace, logger, formatter ? { formatter } : {});\n\tconst guidance = workspaceGuidance(workspace.roots);\n\tconst summarizer = summarizeUndone ? summarizerFor(roles.planner.provider, logger) : undefined;\n\tconst shared = { history: opened.store, ...(summarizer ? { summarizer } : {}), logger };\n\t// A caller's own prompt replaces our instructions and guidance, not the workspace: the model\n\t// needs the roots to name a file, as `createLLMAgent` gives them.\n\tconst prompt = (role: CommandRole, own: string | undefined, instructions: string) =>\n\t\town === undefined\n\t\t\t? withGuidance(instructions, `${guidance}\\n${repositoryGuidance[role]}`)\n\t\t\t: withGuidance(own, guidance);\n\t// Each transcript names the agent it is of.\n\tconst transcriptsOf = (agent: Transcript['agent']) =>\n\t\tonTranscript && ((transcript: Transcript) => onTranscript({ ...transcript, agent }));\n\t// Every command, checked once, before any role takes its share.\n\tif (commands !== undefined) validateCommands(commands);\n\t// A new explorer for each question, on the role's provider: it starts from the question alone.\n\tconst explorerToolset = explorerTools(opened);\n\tconst explorer = (provider: AgentProvider) => () =>\n\t\tbuildLLMAgent(provider, {\n\t\t\t...explorerRoles[provider],\n\t\t\tsystemPrompt: withGuidance(explorerInstructions, guidance),\n\t\t\ttools: explorerToolset,\n\t\t\tmaxSteps: explorerSteps,\n\t\t\tlogger,\n\t\t\tonTranscript: transcriptsOf('explorer'),\n\t\t});\n\tconst reader = async (\n\t\t{ provider, model, reasoningEffort }: Role,\n\t\trole: CommandRole,\n\t\tsystemPrompt: string,\n\t) =>\n\t\tbuildLLMAgent(provider, {\n\t\t\tmodel,\n\t\t\treasoningEffort,\n\t\t\tsystemPrompt,\n\t\t\ttools: await readingTools(opened, role, commands, explorer(provider)),\n\t\t\tmaxSteps: steps[role],\n\t\t\tcompactAt: compaction[role],\n\t\t\tonTranscript: transcriptsOf(role),\n\t\t\t...shared,\n\t\t});\n\tconst { executor } = roles;\n\tconst executorToolset = await executorTools(\n\t\texecutor.provider,\n\t\topened,\n\t\tcommands && commandsFor(commands, 'executor'),\n\t\tremoveWorktree,\n\t);\n\t// The executor and the reviewer are told whether the tests were run, which only an executor\n\t// with a command can do.\n\tconst executorRuns = executorToolset.some(tool => tool.name === 'runCommand');\n\n\treturn new OrchestratorAgent({\n\t\tplannerAgent: await reader(\n\t\t\troles.planner,\n\t\t\t'planner',\n\t\t\tprompt('planner', systemPrompts.planner, plannerInstructions),\n\t\t),\n\t\texecutorAgent: buildLLMAgent(executor.provider, {\n\t\t\tmodel: executor.model,\n\t\t\treasoningEffort: executor.reasoningEffort,\n\t\t\tsystemPrompt: prompt(\n\t\t\t\t'executor',\n\t\t\t\tsystemPrompts.executor,\n\t\t\t\texecutorRuns ? executorInstructions : executorInstructionsWithoutCommands,\n\t\t\t),\n\t\t\ttools: executorToolset,\n\t\t\tmaxSteps: steps.executor,\n\t\t\tcompactAt: compaction.executor,\n\t\t\tautoApprove,\n\t\t\tonTranscript: transcriptsOf('executor'),\n\t\t\t...shared,\n\t\t}),\n\t\treviewerAgent: await reader(\n\t\t\troles.reviewer,\n\t\t\t'reviewer',\n\t\t\tprompt(\n\t\t\t\t'reviewer',\n\t\t\t\tsystemPrompts.reviewer,\n\t\t\t\texecutorRuns ? reviewerInstructions : reviewerInstructionsWithoutCommands,\n\t\t\t),\n\t\t),\n\t\treviewerDecisionValidator: new ReviewerDecisionValidator(),\n\t\tlogger,\n\t});\n}\n"]}
|
|
1
|
+
{"version":3,"file":"agentLLMFactory.js","sourceRoot":"","sources":["../../../src/factory/infrastructure/agentLLMFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,OAAO,EAAkB,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtF,OAAO,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAE5E,OAAO,EACN,eAAe,EAEf,eAAe,EACf,yBAAyB,GACzB,MA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C,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,mCAAmC,CACzE,CACD;QACD,yBAAyB,EAAE,IAAI,yBAAyB,EAAE;QAC1D,MAAM;KACN,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { resolve } from 'node:path';\nimport type { Agent } from '#src/agent/domain/agent';\nimport type { Transcript, TranscriptCallback } from '#src/agent/domain/transcript';\nimport type { HistoryReader } from '#src/engines/domain/model/historyFollower';\nimport { type Compactor, recentKeptSteps } from '#src/engines/domain/model/compactor';\nimport { LLMAgent } from '#src/engines/domain/model/llmAgent';\nimport { JevContextTriage } from '#src/llm/infrastructure/jevContextTriage';\nimport type { LLMClient } from '#src/llm/domain/llm';\nimport {\n\tClaudeLLMClient,\n\ttype ClaudeLLMModel,\n\tclaudeLLMModels,\n\tclaudeLLMReasoningEfforts,\n} from '#src/llm/infrastructure/claudeLLMClient';\nimport {\n\tOpenAILLMClient,\n\ttype OpenAIModel,\n\topenAIModels,\n\topenAIReasoningEfforts,\n} from '#src/llm/infrastructure/openAILLMClient';\nimport {\n\texecutorInstructions,\n\texecutorInstructionsWithoutCommands,\n\tOrchestratorAgent,\n\tplannerInstructions,\n\treviewerInstructions,\n\treviewerInstructionsWithoutCommands,\n} from '#src/orchestration/domain/model/orchestratorAgent';\nimport { ReviewerDecisionValidator } from '#src/orchestration/infrastructure/model/reviewerDecisionValidator';\nimport type { RecoveryStore } from '#src/recovery/domain/recoveryStore';\nimport { RetryingAgent } from '#src/retry/domain/model/retryingAgent';\nimport { InvalidAgentConfigError } from '#src/shared/domain/errors';\nimport { isOneOf } from '#src/shared/domain/isOneOf';\nimport type { ILogger } from '#src/shared/domain/logger';\nimport { Logger } from '#src/shared/infrastructure/logger';\nimport type { WorkspaceRoot } from '#src/tools/domain/accessPolicy';\nimport {\n\ttype CommandRole,\n\ttype Commands,\n\tcommandsFor,\n\ttype Formatter,\n\tvalidateCommands,\n\tvalidateFormatter,\n} from '#src/tools/domain/commands';\nimport type { AgentTool } from '#src/tools/domain/preparedCall';\nimport type { Tool } from '#src/tools/domain/tool';\nimport {\n\tcommandToolFor,\n\ttype FileTool,\n\tfileToolsFor,\n\ttype OpenedWorkspace,\n\topenStore,\n\topenWorkspace,\n\tstateDirectoryOf,\n\ttype WorkspaceOptions,\n} from '#src/tools/infrastructure/fileTools';\nimport type { DelegationTool } from '#src/tools/infrastructure/agentAsTool';\nimport { createExploreTool } from '#src/tools/infrastructure/exploreTool';\nimport { createShowChangesTool } from '#src/tools/infrastructure/showChangesTool';\nimport { createRemoveWorktreeTool } from '#src/tools/infrastructure/removeWorktreeTool';\nimport { listWorktrees } from '#src/tools/infrastructure/worktrees';\nimport {\n\tcreateTrackedReadFile,\n\tcreateTrackedReadFiles,\n} from '#src/tools/infrastructure/trackedReadFile';\nimport { createWorkspaceTools } from '#src/tools/infrastructure/workspaceTools';\nimport { isAgentProvider, orchestratorRolesFor, type Role } from './agentFactory.ts';\nimport {\n\tagentProviders,\n\ttype AgentModel,\n\ttype AgentProvider,\n\ttype CreateOrchestratorOptions,\n\ttype ReasoningEffort,\n} from './types.ts';\n\n/** The models each provider's model API accepts. */\nexport const llmModels = {\n\tanthropic: claudeLLMModels,\n\topenai: openAIModels,\n} as const satisfies Readonly<Record<AgentProvider, readonly AgentModel[]>>;\n\n/** The reasoning efforts each provider's model API accepts. */\nexport const llmReasoningEfforts = {\n\tanthropic: claudeLLMReasoningEfforts,\n\topenai: openAIReasoningEfforts,\n} as const satisfies Readonly<Record<AgentProvider, readonly ReasoningEffort[]>>;\n\n/** Narrows a model to one accepted by the selected provider's model API. */\nexport function isLLMModelOf<Provider extends AgentProvider>(\n\tprovider: Provider,\n\tvalue: string,\n): value is (typeof llmModels)[Provider][number] {\n\treturn isOneOf(llmModels[provider], value);\n}\n\n/** Narrows a reasoning effort to one accepted by the selected provider's model API. */\nexport function isLLMReasoningEffortOf<Provider extends AgentProvider>(\n\tprovider: Provider,\n\tvalue: string,\n): value is (typeof llmReasoningEfforts)[Provider][number] {\n\treturn isOneOf(llmReasoningEfforts[provider], value);\n}\n\nexport interface CreateLLMAgentOptions {\n\t/**\n\t * Defaults to `'sonnet'` on Anthropic and `'gpt-5.6-luna'` on OpenAI. The provider's client\n\t * rejects a model it does not support.\n\t */\n\tmodel?: AgentModel;\n\t/** Defaults to `'high'`. The provider's client rejects an effort it does not support. */\n\treasoningEffort?: ReasoningEffort;\n\t/** Sent as the model's instructions on every call. */\n\tsystemPrompt: string;\n\t/**\n\t * The tools the model may call: the consumer's own, those of `createFileTools`, and agents\n\t * offered with `agentAsTool`. Defaults to none.\n\t */\n\ttools?: (Tool | FileTool | DelegationTool)[];\n\t/**\n\t * The folders the agent works on, the same as given to `createFileTools`. With it, the agent\n\t * follows the workspace's history: after the user undoes runs, its next run starts from the\n\t * conversation as it was, and is told what was undone. The system prompt is followed by the\n\t * roots and how to name a file in them. It gives no tools: pass those of `createFileTools`\n\t * in `tools`, and an agent given a workspace and no tools is refused.\n\t */\n\tworkspace?: WorkspaceOptions;\n\t/**\n\t * With `workspace`, a summary of what was undone, from the provider's cheap model, in place\n\t * of the undone prompts. That is Claude Haiku 5.5 or `gpt-5.6-luna`, at high effort, and the\n\t * call is billed with the run's tokens. Defaults to `true`.\n\t */\n\tsummarizeUndone?: boolean;\n\t/**\n\t * How many calls to the model one run may make before it fails. Defaults to 65, with no upper\n\t * bound. A run that asks for exactly the same tool calls 5 times in a row fails before that.\n\t */\n\tmaxSteps?: number;\n\t/**\n\t * The tokens of context at which the provider compacts it on its side: it replaces every turn\n\t * before that call with its own summary, which only its model reads back. The conversation\n\t * keeps every original turn. Defaults to the model's threshold: 450,000 for Claude Opus,\n\t * Fable and Sonnet and GPT astra, sol and terra, and 125,000 for Claude Haiku and GPT luna.\n\t * `false` turns compaction off. Either way, a context that no longer fits the model is\n\t * compacted once, and the call tried again. At least 50,000 on Anthropic.\n\t */\n\tcompactAt?: number | false;\n\t/**\n\t * Who compacts the context once it passes `compactAt`. `provider`, the default, has the\n\t * model's provider compact it on its side. `recent` has the agent's own model summarize it\n\t * before the next call, from its provider's cache, and keeps the run's prompt and the run's\n\t * last 10 answers, each with its tool results, word for word after the summary, without\n\t * their signed reasoning. Earlier runs are always summarized. `jev` summarizes the same way,\n\t * but TypeSafe's Jev chooses what is kept: the run's prompt, the model's last answer with its\n\t * tool results, and each earlier tool result Jev judges the agent still needs word for word,\n\t * with its call. Jev is sent the run's prompt, the model's last answer and each of those tool\n\t * results, so what the tools read leaves for TypeSafe. It reads the key from `TYPESAFE_API_KEY`; without it, or when Jev fails, the\n\t * `recent` choice is made instead, and logged.\n\t */\n\tcompaction?: CompactionMode;\n\t/**\n\t * Runs every tool call without asking, `destructive` ones included, for CI where no one can\n\t * answer. Without it, a `destructive` call goes to the run's `approve`, or is denied.\n\t */\n\tautoApprove?: boolean;\n\t/** Defaults to warnings on stderr. */\n\tlogger?: ILogger;\n\t/**\n\t * Receives what the model saw in each run once the run ended, completed, failed or\n\t * cancelled, for debugging. See `Transcript`. Without it, nothing is kept.\n\t */\n\tonTranscript?: TranscriptCallback;\n}\n\n/** Who compacts an agent's context; see `CreateLLMAgentOptions.compaction`. */\nexport type CompactionMode = 'provider' | 'recent' | 'jev';\n\nconst compactionModes = ['provider', 'recent', 'jev'] as const satisfies readonly CompactionMode[];\n\n/** A limit per role of `createLLMOrchestrator`; a role left out keeps its default. */\nexport type RoleSteps = Partial<Record<OrchestratorRole, number>>;\n\n/** A number of tokens per role of `createLLMOrchestrator`; a role left out keeps its default. */\nexport type RoleTokens = Partial<Record<OrchestratorRole, number>>;\n\n/** The consumer's agents, from `agentAsTool`, that each role of `createLLMOrchestrator` may call. */\nexport type RoleAgents = Partial<Record<OrchestratorRole, DelegationTool[]>>;\n\n// The same three roles a command can be given to.\ntype OrchestratorRole = CommandRole;\n\n// The executor reads, edits and checks, so it needs more calls than the roles that only read.\nconst defaultRoleSteps: Record<OrchestratorRole, number> = {\n\tplanner: 65,\n\texecutor: 80,\n\treviewer: 65,\n};\n\n// Each role compacts at its model's threshold unless told otherwise.\nconst defaultRoleCompaction: Record<OrchestratorRole, number | undefined> = {\n\tplanner: undefined,\n\texecutor: undefined,\n\treviewer: undefined,\n};\n\n/**\n * Each role's value of the option `name`, from one number for all of them or a number per role.\n * Each number is checked by whatever takes it.\n *\n * @throws {InvalidAgentConfigError} for a value that is neither, and for a role that does not\n * exist, which is a typo that would otherwise leave that role on its default without a word.\n */\nfunction perRole<T extends number | undefined>(\n\tname: string,\n\tvalue: unknown,\n\tdefaults: Record<OrchestratorRole, T>,\n\t{ unit, example }: { unit: string; example: string },\n): Record<OrchestratorRole, T | number> {\n\tif (value === undefined) return defaults;\n\tif (typeof value === 'number') return { planner: value, executor: value, reviewer: value };\n\t// Untyped input, such as the CLI's configuration file, can hold `null` or a list here.\n\tif (typeof value !== 'object' || value === null || Array.isArray(value)) {\n\t\tthrow new InvalidAgentConfigError(\n\t\t\t`${name} must be a number or an object of ${unit} per role, such as ${example}`,\n\t\t);\n\t}\n\tconst unknown = Object.keys(value).filter(role => !(role in defaults));\n\tif (unknown.length > 0) {\n\t\tthrow new InvalidAgentConfigError(\n\t\t\t`${name} names roles that do not exist: ${unknown.join(', ')}; expected planner, executor or reviewer`,\n\t\t);\n\t}\n\t// A role given as `undefined`, which untyped input can do, keeps its default.\n\tconst given = Object.entries(value as Record<string, unknown>).filter(\n\t\t([, each]) => each !== undefined,\n\t);\n\treturn { ...defaults, ...Object.fromEntries(given) };\n}\n\nexport interface CreateLLMOrchestratorOptions extends CreateOrchestratorOptions {\n\t/**\n\t * The folders the agents work on. The executor changes files only in a `write` root, every\n\t * change recorded in the workspace's history. Defaults to the current working directory,\n\t * read only.\n\t */\n\tworkspace?: WorkspaceOptions;\n\t/**\n\t * How many calls to the model one run of each role may make: one number for every role, or a\n\t * number per role. Defaults to 80 for the executor and 65 for the planner and the reviewer,\n\t * with no upper bound. A run that asks for exactly the same tool calls 5 times in a row fails\n\t * before its limit.\n\t */\n\tmaxSteps?: number | RoleSteps;\n\t/**\n\t * The tokens of context at which each role's provider compacts it, as\n\t * `CreateLLMAgentOptions.compactAt`: one number for every role, or a number per role. A role\n\t * left out compacts at its model's threshold, as do the explorers. `false` turns compaction\n\t * off for every role.\n\t */\n\tcompactAt?: number | false | RoleTokens;\n\t/** Who compacts every agent's context, as `CreateLLMAgentOptions.compaction`. */\n\tcompaction?: CompactionMode;\n\t/**\n\t * Commands the roles may run, such as the project's tests, through `runCommand`. Each goes to\n\t * the roles its `roles` names, the executor by default. See `createFileTools`. Each needs a\n\t * `write` root to run in.\n\t */\n\tcommands?: Commands;\n\t/**\n\t * A program the executor's edits run on each file they create or change, such as the\n\t * project's formatter. See `createFileTools`. It needs a `write` root to run in.\n\t */\n\tformatter?: Formatter;\n\t/**\n\t * A summary of what the user undid, from the planner's provider's cheap model, for every\n\t * role. See `CreateLLMAgentOptions.summarizeUndone`. Defaults to `true`.\n\t */\n\tsummarizeUndone?: boolean;\n\t/**\n\t * Receives what the model saw in each run of each role and each explorer, once the run\n\t * ended, for debugging. Each transcript names its role. See `Transcript`.\n\t */\n\tonTranscript?: TranscriptCallback;\n\t/**\n\t * Gives the executor `removeWorktree`, which removes a worktree of the repository the first\n\t * root is in when the user asks. See `createFileTools`.\n\t */\n\tremoveWorktree?: boolean;\n\t/**\n\t * The consumer's agents, from `agentAsTool`, that each role may hand a task to, beside its own\n\t * tools: the planner and the reviewer keep their explorers. An agent never writes more than\n\t * the role that calls it, so only the executor's may write, within the `write` roots.\n\t */\n\tagents?: RoleAgents;\n}\n\nconst defaultLLMAgentModels = {\n\tanthropic: 'sonnet',\n\topenai: 'gpt-5.6-luna',\n} as const satisfies Record<AgentProvider, AgentModel>;\n\n// The tokens of context at which each model compacts by default, the small ones sooner. The\n// margins are wide on purpose: compacting at 64k cleared file reads the executor then read again.\nconst compactionThresholds: Record<ClaudeLLMModel | OpenAIModel, number> = {\n\topus: 450_000,\n\tfable: 450_000,\n\tsonnet: 450_000,\n\thaiku: 125_000,\n\t'gpt-6-astra': 450_000,\n\t'gpt-5.6-sol': 450_000,\n\t'gpt-5.6-terra': 450_000,\n\t'gpt-5.6-luna': 125_000,\n};\n\n/**\n * The compactor `mode` names for an agent on `model`: at `compactAt`, at the model's threshold\n * without it, or off with `false`, when only a context that no longer fits is compacted.\n *\n * @throws {InvalidAgentConfigError} for a mode that does not exist, from untyped input.\n */\nfunction compactorFor(\n\tmodel: AgentModel,\n\tcompactAt: number | false | undefined,\n\tmode: CompactionMode = 'provider',\n): Compactor {\n\t// Checked whatever it is, as untyped input can hold anything here.\n\tif (typeof mode !== 'string' || !isOneOf(compactionModes, mode)) {\n\t\tthrow new InvalidAgentConfigError(\n\t\t\t`compaction must be one of: ${compactionModes.join(', ')}; got ${String(mode)}`,\n\t\t);\n\t}\n\t// A model with no threshold was already refused by its client.\n\tconst at =\n\t\tcompactAt === false\n\t\t\t? undefined\n\t\t\t: (compactAt ?? (compactionThresholds as Partial<Record<string, number>>)[model]);\n\tswitch (mode) {\n\t\tcase 'provider':\n\t\t\treturn { by: 'provider', at };\n\t\tcase 'recent':\n\t\t\treturn { by: 'harness', at, keptSteps: recentKeptSteps };\n\t\tcase 'jev':\n\t\t\treturn { by: 'harness', at, keptSteps: recentKeptSteps, triage: new JevContextTriage() };\n\t}\n}\n\nfunction defaultModelOf(provider: AgentProvider): AgentModel {\n\tswitch (provider) {\n\t\tcase 'anthropic':\n\t\tcase 'openai':\n\t\t\treturn defaultLLMAgentModels[provider];\n\t\tdefault:\n\t\t\t// Reachable from untyped input.\n\t\t\tthrow unknownProvider(provider);\n\t}\n}\n\nfunction unknownProvider(provider: never): InvalidAgentConfigError {\n\treturn new InvalidAgentConfigError(\n\t\t`\"${String(provider)}\" is not an agent provider; expected one of: ${agentProviders.join(', ')}`,\n\t);\n}\n\nfunction llmClientFor(\n\tprovider: AgentProvider,\n\t{\n\t\tmodel,\n\t\treasoningEffort,\n\t\tsystemPrompt,\n\t\tlogger,\n\t}: {\n\t\tmodel: AgentModel;\n\t\treasoningEffort?: ReasoningEffort;\n\t\tsystemPrompt: string;\n\t\tlogger: ILogger;\n\t},\n): LLMClient {\n\tswitch (provider) {\n\t\tcase 'anthropic':\n\t\t\treturn new ClaudeLLMClient({\n\t\t\t\tmodel,\n\t\t\t\treasoningEffort,\n\t\t\t\tsystemPrompt,\n\t\t\t\tlogger,\n\t\t\t});\n\t\tcase 'openai':\n\t\t\treturn new OpenAILLMClient({\n\t\t\t\tmodel,\n\t\t\t\treasoningEffort,\n\t\t\t\tsystemPrompt,\n\t\t\t\tlogger,\n\t\t\t});\n\t\tdefault:\n\t\t\t// Reachable from untyped input.\n\t\t\tthrow unknownProvider(provider);\n\t}\n}\n\n/** The provider's cheap model, for the summary of what was undone. */\nfunction summarizerFor(provider: AgentProvider, logger: ILogger): LLMClient {\n\treturn provider === 'anthropic'\n\t\t? new ClaudeLLMClient({ model: 'haiku', reasoningEffort: 'high', systemPrompt: '', logger })\n\t\t: new OpenAILLMClient({\n\t\t\t\tmodel: 'gpt-5.6-luna',\n\t\t\t\treasoningEffort: 'high',\n\t\t\t\tsystemPrompt: '',\n\t\t\t\tlogger,\n\t\t\t});\n}\n\n/**\n * The workspace's history, opened on first use, so a factory that builds an agent stays\n * synchronous. Every agent and every file tool of one workspace reads the same files on disk.\n */\nfunction historyOf(workspace: WorkspaceOptions, logger: ILogger): HistoryReader {\n\t// Checked now: an agent with no root to follow is a setup error, not a first-run one.\n\tif (workspace.roots.length === 0) {\n\t\tthrow new InvalidAgentConfigError('A workspace needs at least one root');\n\t}\n\tlet store: Promise<RecoveryStore> | undefined;\n\tconst open = () => {\n\t\tstore ??= stateDirectoryOf(workspace)\n\t\t\t.then(directory => openStore(workspace, directory, logger))\n\t\t\t.catch((error: unknown) => {\n\t\t\t\t// Not kept: the next run tries again, as one whose disk was full for a moment.\n\t\t\t\tstore = undefined;\n\t\t\t\tthrow error;\n\t\t\t});\n\t\treturn store;\n\t};\n\treturn {\n\t\tlistRuns: async () => (await open()).listRuns(),\n\t\tlistRevisions: async () => (await open()).listRevisions(),\n\t\treadRun: async runId => (await open()).readRun(runId),\n\t};\n}\n\n/**\n * What the model is told about the workspace after its instructions: the roots, which it may\n * change, and how to name a file. A host path in an error sends the model looking for it, so\n * the real root is given here once.\n */\nfunction workspaceGuidance(roots: WorkspaceRoot[]): string {\n\tconst [first, ...others] = roots.map(root => ({ ...root, path: resolve(root.path) }));\n\tif (!first) return '';\n\tconst described = [first, ...others].map(\n\t\t({ path, access }) => `- ${path}${access === 'write' ? '' : ' (read only)'}`,\n\t);\n\treturn [\n\t\t'The workspace:',\n\t\t...described,\n\t\t`Name a file by its path relative to ${first.path}, such as src/index.ts, and a file in another folder of the workspace by its full path. Read a file before you change it.`,\n\t].join('\\n');\n}\n\nfunction withGuidance(systemPrompt: string, guidance: string): string {\n\treturn guidance === '' ? systemPrompt : `${systemPrompt}\\n\\n${guidance}`;\n}\n\n/** An `LLMAgent` on `provider`, wrapped in the harness's retry policy. */\nfunction buildLLMAgent(\n\tprovider: AgentProvider,\n\t{\n\t\tmodel,\n\t\treasoningEffort,\n\t\tsystemPrompt,\n\t\ttools,\n\t\thistory,\n\t\tsummarizer,\n\t\tmaxSteps,\n\t\tcompactAt,\n\t\tcompaction,\n\t\tautoApprove,\n\t\tlogger,\n\t\tonTranscript,\n\t\twriteRoots,\n\t}: {\n\t\tmodel?: AgentModel;\n\t\treasoningEffort?: ReasoningEffort;\n\t\tsystemPrompt: string;\n\t\ttools: AgentTool[];\n\t\thistory?: HistoryReader;\n\t\tsummarizer?: LLMClient;\n\t\tmaxSteps?: number;\n\t\t/** See `CreateLLMAgentOptions.compactAt`. */\n\t\tcompactAt?: number | false | undefined;\n\t\tcompaction?: CompactionMode | undefined;\n\t\tautoApprove?: boolean;\n\t\tlogger: ILogger;\n\t\tonTranscript?: TranscriptCallback | undefined;\n\t\t/** See `LLMAgent`: where an agent it delegates to may write. */\n\t\twriteRoots?: readonly string[];\n\t},\n): Agent {\n\tconst chosen = model ?? defaultModelOf(provider);\n\tconst llmClient = llmClientFor(provider, {\n\t\tmodel: chosen,\n\t\treasoningEffort,\n\t\tsystemPrompt,\n\t\tlogger,\n\t});\n\t// LLMAgent records nothing from a failed call, so the original prompt is the whole story.\n\treturn new RetryingAgent({\n\t\tinner: new LLMAgent({\n\t\t\tllmClient,\n\t\t\ttools,\n\t\t\tautoApprove,\n\t\t\tlogger,\n\t\t\t...(history ? { history } : {}),\n\t\t\t...(summarizer ? { summarizer } : {}),\n\t\t\t...(maxSteps === undefined ? {} : { maxSteps }),\n\t\t\t...(onTranscript ? { onTranscript } : {}),\n\t\t\t...(writeRoots ? { writeRoots } : {}),\n\t\t\tcompactor: compactorFor(chosen, compactAt, compaction),\n\t\t}),\n\t\tlogger,\n\t\tnoteFailures: false,\n\t});\n}\n\n/**\n * Builds an agent whose conversation MiKode owns, on a provider's model API, already wrapped in\n * the harness's retry policy. It needs the provider's API key and bills per token, where\n * `createAgent` uses the Agent SDK's login. Each tool judges the risk of each call; a\n * `destructive` one runs only when the run's `approve` allows it, or with `autoApprove`.\n *\n * @throws {InvalidAgentConfigError} for an unknown provider, a model or reasoning effort its\n * client does not support, two tools that share a name, or a workspace given with no tools.\n * @throws {UnrecoverableError} when the client cannot be set up, for example because\n * `OPENAI_API_KEY` is missing. The Anthropic SDK resolves credentials lazily, so a missing\n * `ANTHROPIC_API_KEY` fails the first run instead, with an `UnrecoverableError`.\n */\nexport function createLLMAgent(\n\tprovider: AgentProvider,\n\t{\n\t\tmodel,\n\t\treasoningEffort,\n\t\tsystemPrompt,\n\t\ttools = [],\n\t\tworkspace,\n\t\tsummarizeUndone = true,\n\t\tmaxSteps,\n\t\tcompactAt,\n\t\tcompaction,\n\t\tautoApprove,\n\t\tlogger = new Logger(),\n\t\tonTranscript,\n\t}: CreateLLMAgentOptions,\n): Agent {\n\t// Told where to work with nothing to work with, the model would only pretend: it writes its\n\t// tool calls as text, and the run returns them as its answer.\n\tif (workspace && tools.length === 0) {\n\t\tthrow new InvalidAgentConfigError(\n\t\t\t'An agent given a workspace needs tools to work on it: pass those of createFileTools in `tools`',\n\t\t);\n\t}\n\treturn buildLLMAgent(provider, {\n\t\tmodel,\n\t\treasoningEffort,\n\t\tsystemPrompt: workspace\n\t\t\t? withGuidance(systemPrompt, workspaceGuidance(workspace.roots))\n\t\t\t: systemPrompt,\n\t\t// A file tool or a delegation tool is a harness tool under its public name.\n\t\ttools: tools as AgentTool[],\n\t\t...(workspace ? { history: historyOf(workspace, logger) } : {}),\n\t\t...(workspace && summarizeUndone ? { summarizer: summarizerFor(provider, logger) } : {}),\n\t\tmaxSteps,\n\t\tcompactAt,\n\t\tcompaction,\n\t\tautoApprove,\n\t\tlogger,\n\t\tonTranscript,\n\t\t// An agent it delegates to writes only where its workspace lets it.\n\t\t...(workspace ? { writeRoots: writeRootsOf(workspace.roots) } : {}),\n\t});\n}\n\nfunction writeRootsOf(roots: readonly WorkspaceRoot[]): string[] {\n\treturn roots.filter(({ access }) => access === 'write').map(({ path }) => path);\n}\n\n/**\n * The file tools for an agent from `createLLMAgent` on `provider`, over `workspace`, in the\n * provider's own format:\n *\n * - OpenAI: `listFiles`, `searchText`, `readFile`, `readFiles` and its native `apply_patch`;\n * - Anthropic: `listFiles`, `searchText`, its native text editor, whose `view` reads, and\n * `delete_file`.\n *\n * Every one goes through the workspace's access policy: a path outside the roots, a secret,\n * a file `.gitignore` excludes or the harness protects is refused. A change is made only in a\n * `write` root, only from a version the agent read, and is recorded in the workspace's history,\n * so it can be undone. Without a `write` root the tools only read. Give the agent the same\n * `workspace`, so it follows what the history undoes.\n *\n * With `commands`, they include `runCommand`, which runs one of them by name, with only the\n * parameters it declares and never through a shell. Each run asks the approver, showing the\n * program exactly as it will run, and gets a small environment without the provider keys. The\n * files of the `write` roots are captured before it and compared after, so what it changed is\n * in the history too. It is trusted execution, not a sandbox: a command can reach whatever\n * this user can. Not supported on Windows yet.\n *\n * With `formatter`, every file an edit creates or changes is formatted right after, its path\n * the formatter's last argument. The edit shows the lines the formatter rewrote, and the model\n * reads a file it rewrote again before editing it. Like a command it runs without a shell, in a small environment, and what it changes in that file is\n * in the history. When it fails, the file stays as the edit wrote it, and the model is told\n * why. Not supported on Windows yet.\n *\n * With `removeWorktree`, they include `removeWorktree`, which removes a git worktree of the\n * repository the first root is in, when the user asks: its folder and every file in it, never\n * its branch. Each call asks the approver, whose request's `worktree` says what is lost:\n * changes no commit has, and the commits only a detached HEAD holds. It refuses the main folder\n * and a worktree the agent works in. See `createWorktree`.\n *\n * @throws {InvalidAgentConfigError} for an unknown provider, a workspace with no root, or an\n * invalid command or formatter, including one whose `cwd` is not in a `write` root, or any on\n * Windows, or `removeWorktree` with a first root in no git repository.\n * @throws {UnrecoverableError} when no program can read the first root.\n */\nexport async function createFileTools(\n\tprovider: AgentProvider,\n\tworkspace: WorkspaceOptions,\n\t{\n\t\tlogger = new Logger(),\n\t\tcommands,\n\t\tformatter,\n\t\tremoveWorktree = false,\n\t}: {\n\t\tlogger?: ILogger;\n\t\tcommands?: Commands;\n\t\tformatter?: Formatter;\n\t\tremoveWorktree?: boolean;\n\t} = {},\n): Promise<FileTool[]> {\n\t// Reachable from untyped input.\n\tif (!isAgentProvider(provider)) throw unknownProvider(provider);\n\tif (commands !== undefined) validateCommands(commands);\n\tif (formatter !== undefined) validateFormatter(formatter);\n\tconst opened = await openWorkspace(workspace, logger, formatter ? { formatter } : {});\n\treturn (await executorTools(provider, opened, commands, removeWorktree)) as unknown as FileTool[];\n}\n\n/** The executor's file tools, `runCommand` when there are commands, and `removeWorktree`. */\nasync function executorTools(\n\tprovider: AgentProvider,\n\tworkspace: OpenedWorkspace,\n\tcommands: Commands | undefined,\n\tremoveWorktree: boolean,\n): Promise<AgentTool[]> {\n\tconst tools = fileToolsFor(provider, workspace);\n\tif (removeWorktree) tools.push(await removeWorktreeToolFor(workspace));\n\t// Every command may belong to other roles, leaving none for this one.\n\tif (commands === undefined || Object.keys(commands).length === 0) return tools;\n\treturn [...tools, await commandToolFor(workspace, commands)];\n}\n\n/** `removeWorktree` over the repository of the first root, which must be in one. */\nasync function removeWorktreeToolFor({\n\tbase,\n\troots,\n\tstateDirectory,\n}: OpenedWorkspace): Promise<AgentTool> {\n\t// Checked now: a tool that could never work is a setup error, not a first-call one.\n\tawait listWorktrees(base).catch((error: unknown) => {\n\t\tthrow new InvalidAgentConfigError(\n\t\t\t`removeWorktree needs a first root in a git repository, and git 2.36 or later; with ${base}, ${error instanceof Error ? error.message : String(error)}`,\n\t\t);\n\t});\n\treturn createRemoveWorktreeTool({ base, roots, stateDirectory });\n}\n\n/**\n * Each role's agents from `agentAsTool`, as the harness's tools.\n *\n * @throws {InvalidAgentConfigError} for a role that does not exist, or a role's agents that are\n * not a list.\n */\nfunction roleAgents(agents: unknown): Record<OrchestratorRole, AgentTool[]> {\n\t// Untyped input, such as the CLI's configuration file, can hold anything here.\n\tif (typeof agents !== 'object' || agents === null || Array.isArray(agents)) {\n\t\tthrow new InvalidAgentConfigError(\n\t\t\t'agents must be an object of agentAsTool tools per role, such as { executor: [committer] }',\n\t\t);\n\t}\n\tconst byRole: Record<OrchestratorRole, AgentTool[]> = { planner: [], executor: [], reviewer: [] };\n\tfor (const [role, tools] of Object.entries(agents)) {\n\t\tif (!Object.hasOwn(byRole, role)) {\n\t\t\tthrow new InvalidAgentConfigError(\n\t\t\t\t`agents names \"${role}\", which is not a role; expected one of: ${Object.keys(byRole).join(', ')}`,\n\t\t\t);\n\t\t}\n\t\tif (tools === undefined) continue;\n\t\tif (!Array.isArray(tools)) {\n\t\t\tthrow new InvalidAgentConfigError(`agents.${role} must be a list of agentAsTool tools`);\n\t\t}\n\t\t// A delegation tool is a harness tool under its public name.\n\t\tbyRole[role as OrchestratorRole] = tools as AgentTool[];\n\t}\n\treturn byRole;\n}\n\n/** What an explorer finds and reads with: no edits, no changes, no commands. */\nfunction explorerTools({ read, policy }: OpenedWorkspace): AgentTool[] {\n\tconst finding = createWorkspaceTools(read).filter(\n\t\ttool => tool.name !== 'readFile' && tool.name !== 'readFiles',\n\t);\n\treturn [...finding, createTrackedReadFile(policy), createTrackedReadFiles(policy)];\n}\n\n/**\n * What the planner and the reviewer read with: no edits, the current task's changes, `explore`\n * with `explorer`, and the commands given to their role.\n */\nasync function readingTools(\n\tworkspace: OpenedWorkspace,\n\trole: CommandRole,\n\tcommands: Commands | undefined,\n\texplorer: () => Agent,\n): Promise<AgentTool[]> {\n\tconst { policy, store } = workspace;\n\tconst tools = [\n\t\t...explorerTools(workspace),\n\t\tcreateShowChangesTool({ store, policy }),\n\t\tcreateExploreTool(explorer),\n\t];\n\tconst own = commands && commandsFor(commands, role);\n\tif (!own || Object.keys(own).length === 0) return tools;\n\treturn [...tools, await commandToolFor(workspace, own)];\n}\n\nconst batching =\n\t'When you know you need several files, or several searches, ask for all of them in one answer rather than one at a time: each answer is a step, and steps are limited.';\n\n// For the roles that have `readFiles`, which the executor on Claude does not.\nconst batchingReads =\n\t'When you know you need several files, or several ranges, read them in one readFiles call, and ask for several searches in one answer, rather than one at a time: each answer is a step, and steps are limited.';\n\n// The explorers find and the role reads, as a reader asks a librarian where a book is and then\n// reads it: their reports are where to look, not a summary to work from.\nconst exploring =\n\t'To find where something is in the repository, ask explorers instead of searching yourself: send `explore` the independent questions you have in one call. They work in the background while you go on, and each one answers, once it finishes, with the files and line ranges that hold what you asked. Then read those ranges yourself, all of them in one readFiles call.';\n\n// Each provider's cheaper model, which only finds and reads.\nconst explorerRoles = {\n\tanthropic: { model: 'haiku', reasoningEffort: 'medium' },\n\topenai: { model: 'gpt-5.6-luna', reasoningEffort: 'medium' },\n} as const satisfies Record<AgentProvider, { model: AgentModel; reasoningEffort: ReasoningEffort }>;\n\nconst explorerSteps = 30;\n\nconst explorerInstructions = `You find things in a repository for another agent, which is planning or reviewing a change and asked you one question, as a reader asks a librarian where a book is. Find where the answer is with listFiles, searchText, readFile and readFiles, reading only what you need to be sure. Answer with where it is: each file and the line ranges that matter, and in a sentence what each range holds and why it answers the question. The other agent reads those ranges itself, so do not copy code beyond a line that marks a place. Say what you looked for and could not find. Do not propose changes or a plan. ${batchingReads}`;\n\n// How each role finds its way, sent after the workspace's roots, so it stays short. Only the\n// planner learns the repository; the executor and the reviewer work from its plan, so a plan\n// that leaves them guessing is the planner's to fix, not theirs to make up for.\nconst repositoryGuidance: Record<CommandRole, string> = {\n\tplanner: `Start with AGENTS.md, which says where the architecture and the decisions are, and read only the parts your task needs. Name in the plan every file to change and what to change in it, so the executor needs nothing else. ${exploring} ${batchingReads}`,\n\texecutor: `Work from the plan: read the files it names, and only what you need to change them. Do not study the repository's architecture or decisions; the plan already applied them. ${batching}`,\n\treviewer: `Work from the plan and the changes: read what they touch, and only what you need to judge them. ${exploring} ${batchingReads}`,\n};\n\n/**\n * Builds the planner → executor → reviewer workflow with every role on the model APIs, each\n * holding its role's instructions, or `systemPrompts`, as its system prompt, followed by the\n * workspace's roots.\n *\n * - The planner and the reviewer read: `listFiles`, `searchText`, `readFile`, `readFiles`, `showChanges`,\n * the current task's changes as far as each may read them, and `explore`, which sends up to 4\n * read-only explorers at once on the role's provider's cheaper model, each a new agent that\n * starts from its question and works in the background while the role goes on.\n * - The executor gets its provider's file tools (see `createFileTools`), and changes files only\n * in a `write` root; `autoApprove` reaches only it.\n * - Each role has its own step limit: `maxSteps`, 80 for the executor and 65 for the others by\n * default.\n * - Each role gets `runCommand` with the `commands` whose `roles` name it, the executor by\n * default. A command asks the approver in any role, and its files are captured around it.\n * - When the executor has a command, it is told to finish only once the tests and checks pass,\n * or to say which fail, and the reviewer takes from its response whether they pass. Without\n * one, both are told the tests were not run, and the reviewer judges from the code whether\n * they would pass.\n *\n * One run of the orchestrator is one run of the workspace's history, every round and retry\n * included, and its `AgentResponse` names it. Every role follows what the user undoes.\n * Asynchronous because opening the workspace is.\n *\n * @throws {InvalidAgentConfigError} for an unknown provider, or a workspace with no root.\n * @throws {UnrecoverableError} when a role cannot be set up, for example because\n * `OPENAI_API_KEY` is missing, or when no program can read the repository.\n */\nexport async function createLLMOrchestrator({\n\tprovider,\n\tautoApprove,\n\tsystemPrompts = {},\n\tworkspace = { roots: [{ path: process.cwd(), access: 'read' }] },\n\tmaxSteps,\n\tcompactAt,\n\tcompaction: compactionMode,\n\tcommands,\n\tformatter,\n\tsummarizeUndone = true,\n\tlogger = new Logger(),\n\tonTranscript,\n\tremoveWorktree = false,\n\tagents = {},\n}: CreateLLMOrchestratorOptions = {}): Promise<Agent> {\n\tconst roles = orchestratorRolesFor(provider);\n\tconst agentsOf = roleAgents(agents);\n\tconst steps = perRole('maxSteps', maxSteps, defaultRoleSteps, {\n\t\tunit: 'steps',\n\t\texample: '{ \"executor\": 120 }',\n\t});\n\tconst compaction: Record<OrchestratorRole, number | false | undefined> =\n\t\tcompactAt === false\n\t\t\t? { planner: false, executor: false, reviewer: false }\n\t\t\t: perRole('compactAt', compactAt, defaultRoleCompaction, {\n\t\t\t\t\tunit: 'tokens',\n\t\t\t\t\texample: '{ \"executor\": 200000 }',\n\t\t\t\t});\n\tif (formatter !== undefined) validateFormatter(formatter);\n\tconst opened = await openWorkspace(workspace, logger, formatter ? { formatter } : {});\n\tconst guidance = workspaceGuidance(workspace.roots);\n\tconst summarizer = summarizeUndone ? summarizerFor(roles.planner.provider, logger) : undefined;\n\tconst shared = {\n\t\thistory: opened.store,\n\t\t...(summarizer ? { summarizer } : {}),\n\t\tcompaction: compactionMode,\n\t\tlogger,\n\t};\n\t// A caller's own prompt replaces our instructions and guidance, not the workspace: the model\n\t// needs the roots to name a file, as `createLLMAgent` gives them.\n\tconst prompt = (role: CommandRole, own: string | undefined, instructions: string) =>\n\t\town === undefined\n\t\t\t? withGuidance(instructions, `${guidance}\\n${repositoryGuidance[role]}`)\n\t\t\t: withGuidance(own, guidance);\n\t// Each transcript names the agent it is of.\n\tconst transcriptsOf = (agent: Transcript['agent']) =>\n\t\tonTranscript && ((transcript: Transcript) => onTranscript({ ...transcript, agent }));\n\t// Every command, checked once, before any role takes its share.\n\tif (commands !== undefined) validateCommands(commands);\n\t// A new explorer for each question, on the role's provider: it starts from the question alone.\n\tconst explorerToolset = explorerTools(opened);\n\tconst explorer = (provider: AgentProvider) => () =>\n\t\tbuildLLMAgent(provider, {\n\t\t\t...explorerRoles[provider],\n\t\t\tsystemPrompt: withGuidance(explorerInstructions, guidance),\n\t\t\ttools: explorerToolset,\n\t\t\tmaxSteps: explorerSteps,\n\t\t\tcompaction: compactionMode,\n\t\t\tlogger,\n\t\t\tonTranscript: transcriptsOf('explorer'),\n\t\t});\n\tconst reader = async (\n\t\t{ provider, model, reasoningEffort }: Role,\n\t\trole: CommandRole,\n\t\tsystemPrompt: string,\n\t) =>\n\t\tbuildLLMAgent(provider, {\n\t\t\tmodel,\n\t\t\treasoningEffort,\n\t\t\tsystemPrompt,\n\t\t\ttools: [\n\t\t\t\t...(await readingTools(opened, role, commands, explorer(provider))),\n\t\t\t\t...agentsOf[role],\n\t\t\t],\n\t\t\tmaxSteps: steps[role],\n\t\t\tcompactAt: compaction[role],\n\t\t\tonTranscript: transcriptsOf(role),\n\t\t\t// It only reads, so the agents it calls only read too.\n\t\t\twriteRoots: [],\n\t\t\t...shared,\n\t\t});\n\tconst { executor } = roles;\n\tconst executorToolset = await executorTools(\n\t\texecutor.provider,\n\t\topened,\n\t\tcommands && commandsFor(commands, 'executor'),\n\t\tremoveWorktree,\n\t);\n\t// The executor and the reviewer are told whether the tests were run, which only an executor\n\t// with a command can do.\n\tconst executorRuns = executorToolset.some(tool => tool.name === 'runCommand');\n\n\treturn new OrchestratorAgent({\n\t\tplannerAgent: await reader(\n\t\t\troles.planner,\n\t\t\t'planner',\n\t\t\tprompt('planner', systemPrompts.planner, plannerInstructions),\n\t\t),\n\t\texecutorAgent: buildLLMAgent(executor.provider, {\n\t\t\tmodel: executor.model,\n\t\t\treasoningEffort: executor.reasoningEffort,\n\t\t\tsystemPrompt: prompt(\n\t\t\t\t'executor',\n\t\t\t\tsystemPrompts.executor,\n\t\t\t\texecutorRuns ? executorInstructions : executorInstructionsWithoutCommands,\n\t\t\t),\n\t\t\ttools: [...executorToolset, ...agentsOf.executor],\n\t\t\tmaxSteps: steps.executor,\n\t\t\tcompactAt: compaction.executor,\n\t\t\tautoApprove,\n\t\t\tonTranscript: transcriptsOf('executor'),\n\t\t\twriteRoots: writeRootsOf(workspace.roots),\n\t\t\t...shared,\n\t\t}),\n\t\treviewerAgent: await reader(\n\t\t\troles.reviewer,\n\t\t\t'reviewer',\n\t\t\tprompt(\n\t\t\t\t'reviewer',\n\t\t\t\tsystemPrompts.reviewer,\n\t\t\t\texecutorRuns ? reviewerInstructions : reviewerInstructionsWithoutCommands,\n\t\t\t),\n\t\t),\n\t\treviewerDecisionValidator: new ReviewerDecisionValidator(),\n\t\tlogger,\n\t});\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type { ILogger } from './shared/domain/logger.ts';
|
|
2
2
|
export { createAgent, createOrchestrator, agentModels, agentReasoningEfforts, isAgentProvider, isModelOf, isReasoningEffortOf, type CreateAgentOptions, } from './factory/infrastructure/agentFactory.ts';
|
|
3
|
-
export { createFileTools, createLLMAgent, createLLMOrchestrator, isLLMModelOf, isLLMReasoningEffortOf, llmModels, llmReasoningEfforts, type CreateLLMAgentOptions, type CreateLLMOrchestratorOptions, type RoleSteps, type RoleTokens, } from './factory/infrastructure/agentLLMFactory.ts';
|
|
3
|
+
export { createFileTools, createLLMAgent, createLLMOrchestrator, isLLMModelOf, isLLMReasoningEffortOf, llmModels, llmReasoningEfforts, type CreateLLMAgentOptions, type CreateLLMOrchestratorOptions, type RoleSteps, type RoleTokens, type RoleAgents, type CompactionMode, } from './factory/infrastructure/agentLLMFactory.ts';
|
|
4
4
|
export type { FileTool, WorkspaceOptions } from './tools/infrastructure/fileTools.ts';
|
|
5
5
|
export { agentAsTool, type AgentAsToolOptions, type DelegationTool, } from './tools/infrastructure/agentAsTool.ts';
|
|
6
6
|
export type { WorkspaceRoot } from './tools/domain/accessPolicy.ts';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACN,WAAW,EACX,kBAAkB,EAClB,WAAW,EACX,qBAAqB,EACrB,eAAe,EACf,SAAS,EACT,mBAAmB,GAEnB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACN,eAAe,EACf,cAAc,EACd,qBAAqB,EACrB,YAAY,EACZ,sBAAsB,EACtB,SAAS,EACT,mBAAmB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACN,WAAW,EACX,kBAAkB,EAClB,WAAW,EACX,qBAAqB,EACrB,eAAe,EACf,SAAS,EACT,mBAAmB,GAEnB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACN,eAAe,EACf,cAAc,EACd,qBAAqB,EACrB,YAAY,EACZ,sBAAsB,EACtB,SAAS,EACT,mBAAmB,GAOnB,MAAM,6CAA6C,CAAC;AAErD,OAAO,EACN,WAAW,GAGX,MAAM,uCAAuC,CAAC;AAW/C,OAAO,EACN,cAAc,GAKd,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAQN,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EACN,uBAAuB,EACvB,gBAAgB,EAChB,kBAAkB,GAClB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAG/D,OAAO,EACN,iBAAiB,GAQjB,MAAM,4BAA4B,CAAC;AAKpC,OAAO,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,4CAA4C,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAErE,OAAO,EACN,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,GAGnB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACpF,OAAO,EAAE,cAAc,EAAE,MAAM,6CAA6C,CAAC;AAC7E,OAAO,EACN,oBAAoB,GASpB,MAAM,+BAA+B,CAAC","sourcesContent":["export type { ILogger } from './shared/domain/logger.ts';\nexport {\n\tcreateAgent,\n\tcreateOrchestrator,\n\tagentModels,\n\tagentReasoningEfforts,\n\tisAgentProvider,\n\tisModelOf,\n\tisReasoningEffortOf,\n\ttype CreateAgentOptions,\n} from './factory/infrastructure/agentFactory.ts';\nexport {\n\tcreateFileTools,\n\tcreateLLMAgent,\n\tcreateLLMOrchestrator,\n\tisLLMModelOf,\n\tisLLMReasoningEffortOf,\n\tllmModels,\n\tllmReasoningEfforts,\n\ttype CreateLLMAgentOptions,\n\ttype CreateLLMOrchestratorOptions,\n\ttype RoleSteps,\n\ttype RoleTokens,\n\ttype RoleAgents,\n\ttype CompactionMode,\n} from './factory/infrastructure/agentLLMFactory.ts';\nexport type { FileTool, WorkspaceOptions } from './tools/infrastructure/fileTools.ts';\nexport {\n\tagentAsTool,\n\ttype AgentAsToolOptions,\n\ttype DelegationTool,\n} from './tools/infrastructure/agentAsTool.ts';\nexport type { WorkspaceRoot } from './tools/domain/accessPolicy.ts';\nexport type {\n\tCommandArgument,\n\tCommandDefinition,\n\tCommandParameter,\n\tCommandRole,\n\tCommands,\n\tFormatter,\n} from './tools/domain/commands.ts';\nexport type { SecretRules } from './tools/infrastructure/rootsAccessPolicy.ts';\nexport {\n\tagentProviders,\n\ttype AgentModel,\n\ttype AgentProvider,\n\ttype CreateOrchestratorOptions,\n\ttype ReasoningEffort,\n} from './factory/infrastructure/types.ts';\nexport {\n\ttype Agent,\n\ttype AgentResponse,\n\ttype Callback,\n\ttype ProgressAgent,\n\ttype ProgressEvent,\n\ttype StepContext,\n\ttype RunOptions,\n} from './agent/domain/agent.ts';\nexport type { Transcript, TranscriptCallback } from './agent/domain/transcript.ts';\nexport { Inbox } from './agent/domain/inbox.ts';\nexport { RunInProgressError } from './agent/domain/oneRunAtATime.ts';\nexport {\n\tInvalidAgentConfigError,\n\tRecoverableError,\n\tUnrecoverableError,\n} from './shared/domain/errors.ts';\nexport { isAbortError } from './shared/domain/isAbortError.ts';\nexport type { Session } from './shared/domain/session.ts';\nexport type { Tokens } from './shared/domain/tokens.ts';\nexport {\n\trememberApprovals,\n\ttype ApprovalDecision,\n\ttype ApprovalRequest,\n\ttype Approver,\n\ttype CommandLine,\n\ttype RememberableDecision,\n\ttype ToolRisk,\n\ttype WorktreeRemoval,\n} from './agent/domain/approval.ts';\nexport type { Asker, QuestionOption, UserQuestion } from './agent/domain/question.ts';\nexport type { JSONSchema, ToolDefinition } from './llm/domain/tool.ts';\nexport type { Tool, ToolSummarizer } from './tools/domain/tool.ts';\nexport type { TextMatch, Workspace } from './tools/domain/workspace.ts';\nexport { defineTool } from './tools/infrastructure/defineTool.ts';\nexport { createWorkspace } from './tools/infrastructure/createWorkspace.ts';\nexport { createWorkspaceTools } from './tools/infrastructure/workspaceTools.ts';\nexport { createHistory } from './recovery/infrastructure/createHistory.ts';\nexport { createWorktree } from './tools/infrastructure/worktrees.ts';\nexport type { History, HistoryRun, Move } from './recovery/domain/history.ts';\nexport {\n\thistoryStart,\n\tNothingToMoveError,\n\tWorkspaceBusyError,\n\tWorkspaceMovedError,\n\ttype MoveOptions,\n\ttype RunStatus,\n} from './recovery/domain/recoveryStore.ts';\nexport { HistoryExpiredError, UnknownRunError } from './recovery/domain/runTree.ts';\nexport { createWorkflow } from './factory/infrastructure/workflowFactory.ts';\nexport {\n\tdefineWorkflowStages,\n\ttype CreateWorkflowOptions,\n\ttype Workflow,\n\ttype WorkflowResult,\n\ttype WorkflowStage,\n\ttype WorkflowStageDefinition,\n\ttype WorkflowStageName,\n\ttype WorkflowStageReport,\n\ttype WorkflowTransition,\n} from './workflow/domain/workflow.ts';\nexport type { Validator } from './shared/domain/validator.ts';\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** A tool result the agent may still need word for word, with the call it answers. */
|
|
2
|
+
export interface TriagedResult {
|
|
3
|
+
tool: string;
|
|
4
|
+
input: unknown;
|
|
5
|
+
output: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Judges which tool results an agent needs word for word once its context is compacted: Jev's
|
|
9
|
+
* decision, behind its own port, so a compactor works the same without it. Internal.
|
|
10
|
+
*/
|
|
11
|
+
export interface ContextTriage {
|
|
12
|
+
/**
|
|
13
|
+
* How much the agent needs each of `results` word for word to go on from its latest answer,
|
|
14
|
+
* in their order: from 0, not again, to 3, word for word.
|
|
15
|
+
*
|
|
16
|
+
* @param task the user's request for the run.
|
|
17
|
+
* @param latestAnswer the model's latest answer, as text.
|
|
18
|
+
*/
|
|
19
|
+
score(request: {
|
|
20
|
+
task: string;
|
|
21
|
+
latestAnswer: string;
|
|
22
|
+
results: TriagedResult[];
|
|
23
|
+
}, signal: AbortSignal): Promise<number[]>;
|
|
24
|
+
}
|
|
25
|
+
/** The score from which a tool result is kept word for word: its exact details matter. */
|
|
26
|
+
export declare const keptScore = 2;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contextTriage.js","sourceRoot":"","sources":["../../../src/llm/domain/contextTriage.ts"],"names":[],"mappings":"AAyBA,0FAA0F;AAC1F,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC","sourcesContent":["/** A tool result the agent may still need word for word, with the call it answers. */\nexport interface TriagedResult {\n\ttool: string;\n\tinput: unknown;\n\toutput: string;\n}\n\n/**\n * Judges which tool results an agent needs word for word once its context is compacted: Jev's\n * decision, behind its own port, so a compactor works the same without it. Internal.\n */\nexport interface ContextTriage {\n\t/**\n\t * How much the agent needs each of `results` word for word to go on from its latest answer,\n\t * in their order: from 0, not again, to 3, word for word.\n\t *\n\t * @param task the user's request for the run.\n\t * @param latestAnswer the model's latest answer, as text.\n\t */\n\tscore(\n\t\trequest: { task: string; latestAnswer: string; results: TriagedResult[] },\n\t\tsignal: AbortSignal,\n\t): Promise<number[]>;\n}\n\n/** The score from which a tool result is kept word for word: its exact details matter. */\nexport const keptScore = 2;\n"]}
|
package/dist/llm/domain/llm.d.ts
CHANGED
|
@@ -13,6 +13,11 @@ export interface LLMResponse {
|
|
|
13
13
|
*/
|
|
14
14
|
usage: Tokens | undefined;
|
|
15
15
|
stopReason: StopReason;
|
|
16
|
+
/**
|
|
17
|
+
* When the provider compacted the context in this call: the tokens of context it compacted,
|
|
18
|
+
* as the provider reported them. Missing when it did not compact, or did not report them.
|
|
19
|
+
*/
|
|
20
|
+
compactedContextTokens?: number;
|
|
16
21
|
}
|
|
17
22
|
export interface LLMClient {
|
|
18
23
|
/** The system prompt every call sends, for measuring what a call carries. */
|
|
@@ -24,8 +29,20 @@ export interface LLMClient {
|
|
|
24
29
|
readonly providerDataSource?: string;
|
|
25
30
|
/** Whether this client can declare a native tool. Missing means it declares none. */
|
|
26
31
|
supportsNative?(tool: NativeTool): boolean;
|
|
27
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Checks a threshold for `send`'s `compactAt`. Missing when the provider cannot compact.
|
|
34
|
+
*
|
|
35
|
+
* @throws {InvalidAgentConfigError} for a threshold the provider cannot take.
|
|
36
|
+
*/
|
|
37
|
+
checkCompactAt?(compactAt: number): void;
|
|
38
|
+
/**
|
|
39
|
+
* @param compactAt the tokens of context at which the provider compacts it inside this call,
|
|
40
|
+
* answering with its summary first; `now` compacts it whatever its size, as far as the
|
|
41
|
+
* provider can. Without it, the call never compacts.
|
|
42
|
+
*/
|
|
43
|
+
send({ context, tools, compactAt, }: {
|
|
28
44
|
context: Message[];
|
|
29
45
|
tools: ToolDefinition[];
|
|
46
|
+
compactAt?: number | 'now' | undefined;
|
|
30
47
|
}, signal: AbortSignal): Promise<LLMResponse>;
|
|
31
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"llm.js","sourceRoot":"","sources":["../../../src/llm/domain/llm.ts"],"names":[],"mappings":"","sourcesContent":["import type { Tokens } from '#src/shared/domain/tokens';\nimport type { Message } from './message.ts';\nimport type { NativeTool, ToolDefinition } from './tool.ts';\n\nexport type StopReason = 'completed' | 'truncated' | 'refused';\n\nexport interface LLMResponse {\n\tmessage: Message & { role: 'assistant' };\n\t/**\n\t * Missing when the provider did not report it. The call was made and may have been billed,\n\t * so the agent keeps the answer and only its tokens become unknown; a failure raised from\n\t * such a response is marked `usageUnreported`.\n\t */\n\tusage: Tokens | undefined;\n\tstopReason: StopReason;\n}\n\nexport interface LLMClient {\n\t/** The system prompt every call sends, for measuring what a call carries. */\n\treadonly systemPrompt?: string;\n\t/**\n\t * The `source` of the `providerData` and `compaction` parts this client sends back; it drops\n\t * every other. For measuring what a call carries.\n\t */\n\treadonly providerDataSource?: string;\n\t/** Whether this client can declare a native tool. Missing means it declares none. */\n\tsupportsNative?(tool: NativeTool): boolean;\n\
|
|
1
|
+
{"version":3,"file":"llm.js","sourceRoot":"","sources":["../../../src/llm/domain/llm.ts"],"names":[],"mappings":"","sourcesContent":["import type { Tokens } from '#src/shared/domain/tokens';\nimport type { Message } from './message.ts';\nimport type { NativeTool, ToolDefinition } from './tool.ts';\n\nexport type StopReason = 'completed' | 'truncated' | 'refused';\n\nexport interface LLMResponse {\n\tmessage: Message & { role: 'assistant' };\n\t/**\n\t * Missing when the provider did not report it. The call was made and may have been billed,\n\t * so the agent keeps the answer and only its tokens become unknown; a failure raised from\n\t * such a response is marked `usageUnreported`.\n\t */\n\tusage: Tokens | undefined;\n\tstopReason: StopReason;\n\t/**\n\t * When the provider compacted the context in this call: the tokens of context it compacted,\n\t * as the provider reported them. Missing when it did not compact, or did not report them.\n\t */\n\tcompactedContextTokens?: number;\n}\n\nexport interface LLMClient {\n\t/** The system prompt every call sends, for measuring what a call carries. */\n\treadonly systemPrompt?: string;\n\t/**\n\t * The `source` of the `providerData` and `compaction` parts this client sends back; it drops\n\t * every other. For measuring what a call carries.\n\t */\n\treadonly providerDataSource?: string;\n\t/** Whether this client can declare a native tool. Missing means it declares none. */\n\tsupportsNative?(tool: NativeTool): boolean;\n\t/**\n\t * Checks a threshold for `send`'s `compactAt`. Missing when the provider cannot compact.\n\t *\n\t * @throws {InvalidAgentConfigError} for a threshold the provider cannot take.\n\t */\n\tcheckCompactAt?(compactAt: number): void;\n\t/**\n\t * @param compactAt the tokens of context at which the provider compacts it inside this call,\n\t * answering with its summary first; `now` compacts it whatever its size, as far as the\n\t * provider can. Without it, the call never compacts.\n\t */\n\tsend(\n\t\t{\n\t\t\tcontext,\n\t\t\ttools,\n\t\t\tcompactAt,\n\t\t}: { context: Message[]; tools: ToolDefinition[]; compactAt?: number | 'now' | undefined },\n\t\tsignal: AbortSignal,\n\t): Promise<LLMResponse>;\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type MessagePart = TextPart | ReasoningPart | ToolCallPart | ToolResultPart | ProviderDataPart | CompactionPart;
|
|
1
|
+
export type MessagePart = TextPart | ReasoningPart | ToolCallPart | ToolResultPart | ProviderDataPart | CompactionPart | ContextSummaryPart;
|
|
2
2
|
export interface TextPart {
|
|
3
3
|
type: 'text';
|
|
4
4
|
text: string;
|
|
@@ -42,6 +42,17 @@ export interface CompactionPart {
|
|
|
42
42
|
source: string;
|
|
43
43
|
data: unknown;
|
|
44
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* The harness's own summary of the context before it, written once the context passed the
|
|
47
|
+
* agent's threshold, with a copy of each message it kept word for word. Unlike a `CompactionPart`
|
|
48
|
+
* it belongs to no provider: the context every client sends is derived from the latest one on
|
|
49
|
+
* (`compactedContext`), and the conversation still holds every part it replaced.
|
|
50
|
+
*/
|
|
51
|
+
export interface ContextSummaryPart {
|
|
52
|
+
type: 'contextSummary';
|
|
53
|
+
summary: string;
|
|
54
|
+
kept: Message[];
|
|
55
|
+
}
|
|
45
56
|
export interface Message {
|
|
46
57
|
role: 'user' | 'assistant' | 'tool';
|
|
47
58
|
content: MessagePart[];
|
|
@@ -51,3 +62,9 @@ export interface Message {
|
|
|
51
62
|
* on, that compaction included, or the whole context when it has none.
|
|
52
63
|
*/
|
|
53
64
|
export declare function sentContext(context: Message[], source: string | undefined): Message[];
|
|
65
|
+
/**
|
|
66
|
+
* `context` from its latest `ContextSummaryPart` on: the summary, then the messages it kept word
|
|
67
|
+
* for word, then everything after it. The whole context when it has none. Messages after the
|
|
68
|
+
* summary are the same objects, not copies.
|
|
69
|
+
*/
|
|
70
|
+
export declare function compactedContext(context: Message[]): Message[];
|
|
@@ -12,4 +12,24 @@ export function sentContext(context, source) {
|
|
|
12
12
|
}
|
|
13
13
|
return context;
|
|
14
14
|
}
|
|
15
|
+
/** How the model is told that a summary stands for what came before it. */
|
|
16
|
+
const summaryHeading = 'The earlier part of this conversation was compacted into this summary, which you wrote:';
|
|
17
|
+
/**
|
|
18
|
+
* `context` from its latest `ContextSummaryPart` on: the summary, then the messages it kept word
|
|
19
|
+
* for word, then everything after it. The whole context when it has none. Messages after the
|
|
20
|
+
* summary are the same objects, not copies.
|
|
21
|
+
*/
|
|
22
|
+
export function compactedContext(context) {
|
|
23
|
+
const at = context.findLastIndex(message => message.content.some(part => part.type === 'contextSummary'));
|
|
24
|
+
const part = context[at]?.content.findLast(part => part.type === 'contextSummary');
|
|
25
|
+
if (!part)
|
|
26
|
+
return context;
|
|
27
|
+
const summary = { type: 'text', text: `${summaryHeading}\n\n${part.summary}` };
|
|
28
|
+
const [first, ...kept] = part.kept;
|
|
29
|
+
// One user message, not two in a row, when what was kept starts with the user's.
|
|
30
|
+
const opening = first?.role === 'user'
|
|
31
|
+
? [{ role: 'user', content: [summary, ...first.content] }]
|
|
32
|
+
: [{ role: 'user', content: [summary] }, ...(first ? [first] : [])];
|
|
33
|
+
return [...opening, ...kept, ...context.slice(at + 1)];
|
|
34
|
+
}
|
|
15
35
|
//# sourceMappingURL=message.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../../src/llm/domain/message.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../../src/llm/domain/message.ts"],"names":[],"mappings":"AA2EA;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,OAAkB,EAAE,MAA0B;IACzE,KAAK,IAAI,KAAK,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;QAC1D,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;QAC/B,MAAM,EAAE,GACP,OAAO,EAAE,OAAO,CAAC,aAAa,CAC7B,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,YAAY,IAAI,IAAI,CAAC,MAAM,KAAK,MAAM,CAC5D,IAAI,CAAC,CAAC,CAAC;QACT,IAAI,OAAO,IAAI,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC;YAC1B,OAAO,CAAC,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;QAC1F,CAAC;IACF,CAAC;IACD,OAAO,OAAO,CAAC;AAChB,CAAC;AAED,2EAA2E;AAC3E,MAAM,cAAc,GACnB,yFAAyF,CAAC;AAE3F;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAkB;IAClD,MAAM,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,CAC1C,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,gBAAgB,CAAC,CAC5D,CAAC;IACF,MAAM,IAAI,GAAG,OAAO,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,gBAAgB,CAAC,CAAC;IACnF,IAAI,CAAC,IAAI;QAAE,OAAO,OAAO,CAAC;IAC1B,MAAM,OAAO,GAAa,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,cAAc,OAAO,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;IACzF,MAAM,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC;IACnC,iFAAiF;IACjF,MAAM,OAAO,GACZ,KAAK,EAAE,IAAI,KAAK,MAAM;QACrB,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1D,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,OAAO,CAAC,EAAE,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACtE,OAAO,CAAC,GAAG,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC","sourcesContent":["export type MessagePart =\n\t| TextPart\n\t| ReasoningPart\n\t| ToolCallPart\n\t| ToolResultPart\n\t| ProviderDataPart\n\t| CompactionPart\n\t| ContextSummaryPart;\n\nexport interface TextPart {\n\ttype: 'text';\n\ttext: string;\n}\n\nexport interface ReasoningPart {\n\ttype: 'reasoning';\n\ttext: string;\n}\n\nexport interface ToolCallPart {\n\tid: string;\n\ttype: 'toolCall';\n\tname: string;\n\tinput: unknown;\n}\n\nexport interface ToolResultPart {\n\tcallId: string;\n\ttype: 'toolResult';\n\tname: string;\n\toutput: string;\n\tisError: boolean;\n}\n\n/**\n * A block only the client that produced it can read back, such as signed or encrypted\n * reasoning, kept whole so that client can send it again on the next call. `source` is the\n * client's own label and the domain gives it no meaning: every other client leaves the part out.\n * `data` must stay plain JSON, since the conversation is copied and will be persisted.\n */\nexport interface ProviderDataPart {\n\ttype: 'providerData';\n\tsource: string;\n\tdata: unknown;\n}\n\n/**\n * A provider's own summary of everything before it, written when its context passed the\n * client's `compactAt`. Like `ProviderDataPart`, only the client labelled `source` reads it\n * back: that client sends the conversation from its latest compaction on, and every other client\n * leaves the part out and sends the conversation whole, which the conversation still holds.\n */\nexport interface CompactionPart {\n\ttype: 'compaction';\n\tsource: string;\n\tdata: unknown;\n}\n\n/**\n * The harness's own summary of the context before it, written once the context passed the\n * agent's threshold, with a copy of each message it kept word for word. Unlike a `CompactionPart`\n * it belongs to no provider: the context every client sends is derived from the latest one on\n * (`compactedContext`), and the conversation still holds every part it replaced.\n */\nexport interface ContextSummaryPart {\n\ttype: 'contextSummary';\n\tsummary: string;\n\tkept: Message[];\n}\n\nexport interface Message {\n\trole: 'user' | 'assistant' | 'tool';\n\tcontent: MessagePart[];\n}\n\n/**\n * What the client labelled `source` sends of `context`: everything from its latest compaction\n * on, that compaction included, or the whole context when it has none.\n */\nexport function sentContext(context: Message[], source: string | undefined): Message[] {\n\tfor (let index = context.length - 1; index >= 0; index--) {\n\t\tconst message = context[index];\n\t\tconst at =\n\t\t\tmessage?.content.findLastIndex(\n\t\t\t\tpart => part.type === 'compaction' && part.source === source,\n\t\t\t) ?? -1;\n\t\tif (message && at !== -1) {\n\t\t\treturn [{ ...message, content: message.content.slice(at) }, ...context.slice(index + 1)];\n\t\t}\n\t}\n\treturn context;\n}\n\n/** How the model is told that a summary stands for what came before it. */\nconst summaryHeading =\n\t'The earlier part of this conversation was compacted into this summary, which you wrote:';\n\n/**\n * `context` from its latest `ContextSummaryPart` on: the summary, then the messages it kept word\n * for word, then everything after it. The whole context when it has none. Messages after the\n * summary are the same objects, not copies.\n */\nexport function compactedContext(context: Message[]): Message[] {\n\tconst at = context.findLastIndex(message =>\n\t\tmessage.content.some(part => part.type === 'contextSummary'),\n\t);\n\tconst part = context[at]?.content.findLast(part => part.type === 'contextSummary');\n\tif (!part) return context;\n\tconst summary: TextPart = { type: 'text', text: `${summaryHeading}\\n\\n${part.summary}` };\n\tconst [first, ...kept] = part.kept;\n\t// One user message, not two in a row, when what was kept starts with the user's.\n\tconst opening: Message[] =\n\t\tfirst?.role === 'user'\n\t\t\t? [{ role: 'user', content: [summary, ...first.content] }]\n\t\t\t: [{ role: 'user', content: [summary] }, ...(first ? [first] : [])];\n\treturn [...opening, ...kept, ...context.slice(at + 1)];\n}\n"]}
|
|
@@ -14,21 +14,20 @@ export declare class ClaudeLLMClient implements LLMClient {
|
|
|
14
14
|
private readonly client;
|
|
15
15
|
private readonly model;
|
|
16
16
|
private readonly reasoningEffort;
|
|
17
|
-
private readonly compactAt;
|
|
18
17
|
readonly systemPrompt: string;
|
|
19
18
|
readonly providerDataSource = "claude";
|
|
20
19
|
private readonly logger;
|
|
21
|
-
constructor({ model, reasoningEffort,
|
|
20
|
+
constructor({ model, reasoningEffort, systemPrompt, logger, }: {
|
|
22
21
|
model: string;
|
|
23
22
|
reasoningEffort?: string;
|
|
24
|
-
/** The input tokens at which Anthropic compacts the context on its side. Without it, never. */
|
|
25
|
-
compactAt?: number | undefined;
|
|
26
23
|
systemPrompt: string;
|
|
27
24
|
logger: ILogger;
|
|
28
25
|
});
|
|
29
26
|
supportsNative(tool: NativeTool): boolean;
|
|
30
|
-
|
|
27
|
+
checkCompactAt(compactAt: number): void;
|
|
28
|
+
send({ context, tools, compactAt, }: {
|
|
31
29
|
context: Message[];
|
|
32
30
|
tools: ToolDefinition[];
|
|
31
|
+
compactAt?: number | 'now' | undefined;
|
|
33
32
|
}, signal: AbortSignal): Promise<LLMResponse>;
|
|
34
33
|
}
|
|
@@ -73,6 +73,9 @@ function toClaudeBlocks(part) {
|
|
|
73
73
|
case 'reasoning':
|
|
74
74
|
// Unsigned text cannot be replayed as thinking. The API accepts a turn without it.
|
|
75
75
|
return [];
|
|
76
|
+
case 'contextSummary':
|
|
77
|
+
// Never sent: the agent sends the context derived from it.
|
|
78
|
+
return [];
|
|
76
79
|
}
|
|
77
80
|
}
|
|
78
81
|
/**
|
|
@@ -202,6 +205,20 @@ function toTokens(usage, logger) {
|
|
|
202
205
|
outputTokens: usage.output_tokens,
|
|
203
206
|
};
|
|
204
207
|
}
|
|
208
|
+
/**
|
|
209
|
+
* How many tokens of context the call compacted, when it did: what its compaction iteration read,
|
|
210
|
+
* since Anthropic bills a compaction as a call of its own over the context before it.
|
|
211
|
+
*/
|
|
212
|
+
function compactedContext(usage) {
|
|
213
|
+
const compaction = usage?.iterations?.find(iteration => iteration.type === 'compaction');
|
|
214
|
+
if (!compaction)
|
|
215
|
+
return {};
|
|
216
|
+
return {
|
|
217
|
+
compactedContextTokens: compaction.input_tokens +
|
|
218
|
+
compaction.cache_read_input_tokens +
|
|
219
|
+
compaction.cache_creation_input_tokens,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
205
222
|
/**
|
|
206
223
|
* @param summaries each compaction's summary as it was streamed, by the index of its block. The
|
|
207
224
|
* SDK joins a delta that carries none as the text "null", so the final message cannot tell.
|
|
@@ -223,6 +240,7 @@ function toLLMResponse(response, logger, summaries) {
|
|
|
223
240
|
},
|
|
224
241
|
usage,
|
|
225
242
|
stopReason: toStopReason(response),
|
|
243
|
+
...compactedContext(response.usage),
|
|
226
244
|
};
|
|
227
245
|
}
|
|
228
246
|
catch (error) {
|
|
@@ -280,13 +298,12 @@ export class ClaudeLLMClient {
|
|
|
280
298
|
client;
|
|
281
299
|
model;
|
|
282
300
|
reasoningEffort;
|
|
283
|
-
compactAt;
|
|
284
301
|
systemPrompt;
|
|
285
302
|
providerDataSource = claudeSource;
|
|
286
303
|
logger;
|
|
287
304
|
// `model` and `reasoningEffort` are untyped on purpose: this adapter is the one that knows
|
|
288
305
|
// what Claude supports.
|
|
289
|
-
constructor({ model, reasoningEffort,
|
|
306
|
+
constructor({ model, reasoningEffort, systemPrompt, logger, }) {
|
|
290
307
|
if (!isOneOf(claudeLLMModels, model)) {
|
|
291
308
|
throw new InvalidAgentConfigError(`"${model}" is not a Claude API model; expected one of: ${claudeLLMModels.join(', ')}`);
|
|
292
309
|
}
|
|
@@ -294,9 +311,6 @@ export class ClaudeLLMClient {
|
|
|
294
311
|
if (!isOneOf(claudeLLMReasoningEfforts, effort)) {
|
|
295
312
|
throw new InvalidAgentConfigError(`"${effort}" is not a Claude API reasoning effort; expected one of: ${claudeLLMReasoningEfforts.join(', ')}`);
|
|
296
313
|
}
|
|
297
|
-
if (compactAt !== undefined && !(Number.isInteger(compactAt) && compactAt >= minCompactAt)) {
|
|
298
|
-
throw new InvalidAgentConfigError(`compactAt must be a whole number of tokens of at least ${String(minCompactAt)} on Claude, not ${String(compactAt)}`);
|
|
299
|
-
}
|
|
300
314
|
try {
|
|
301
315
|
// The SDK's default retries stay on, as OpenAI's do. See "The provider SDKs keep their
|
|
302
316
|
// transport retries under RetryingAgent" in decisions.md.
|
|
@@ -311,14 +325,27 @@ export class ClaudeLLMClient {
|
|
|
311
325
|
}
|
|
312
326
|
this.model = claudeModelIds[model];
|
|
313
327
|
this.reasoningEffort = effort;
|
|
314
|
-
this.compactAt = compactAt;
|
|
315
328
|
this.systemPrompt = systemPrompt;
|
|
316
329
|
this.logger = logger;
|
|
317
330
|
}
|
|
318
331
|
supportsNative(tool) {
|
|
319
332
|
return tool === 'textEditor';
|
|
320
333
|
}
|
|
321
|
-
|
|
334
|
+
checkCompactAt(compactAt) {
|
|
335
|
+
if (!(Number.isInteger(compactAt) && compactAt >= minCompactAt)) {
|
|
336
|
+
throw new InvalidAgentConfigError(`compactAt must be a whole number of tokens of at least ${String(minCompactAt)} on Claude, not ${String(compactAt)}`);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
async send({ context, tools, compactAt, }, signal) {
|
|
340
|
+
// Compacting now is compacting at the least threshold Anthropic takes, which a context
|
|
341
|
+
// too large for the model has long passed.
|
|
342
|
+
const trigger = compactAt === 'now' ? minCompactAt : compactAt;
|
|
343
|
+
// The latest compaction carries everything before it, which Anthropic would only ignore.
|
|
344
|
+
const messages = sentContext(context, claudeSource);
|
|
345
|
+
// A compaction sent back needs the beta as much as one asked for, even with compaction off,
|
|
346
|
+
// as after a context that no longer fit was compacted once.
|
|
347
|
+
const first = messages[0]?.content[0];
|
|
348
|
+
const compacted = trigger !== undefined || (first?.type === 'compaction' && first.source === claudeSource);
|
|
322
349
|
let response;
|
|
323
350
|
let stream;
|
|
324
351
|
// What each compaction streamed of its summary, by block index, its missing parts left out.
|
|
@@ -331,11 +358,10 @@ export class ClaudeLLMClient {
|
|
|
331
358
|
// A compaction changes the conversation's first block, so the cache would otherwise
|
|
332
359
|
// keep nothing: this keeps the system prompt cached across it. The API rejects an
|
|
333
360
|
// empty text block, and an empty prompt has nothing to cache.
|
|
334
|
-
system:
|
|
361
|
+
system: !compacted || this.systemPrompt === ''
|
|
335
362
|
? this.systemPrompt
|
|
336
363
|
: [{ type: 'text', text: this.systemPrompt, cache_control: { type: 'ephemeral' } }],
|
|
337
|
-
|
|
338
|
-
messages: sentContext(context, claudeSource).flatMap(toClaudeInput),
|
|
364
|
+
messages: messages.flatMap(toClaudeInput),
|
|
339
365
|
// Left out when empty, so a request without tools stays as it always was.
|
|
340
366
|
...(tools.length > 0 && { tools: tools.map(toClaudeTool) }),
|
|
341
367
|
thinking: { type: 'adaptive', display: 'summarized' },
|
|
@@ -343,14 +369,14 @@ export class ClaudeLLMClient {
|
|
|
343
369
|
// Anthropic caches only on request. This marks the last block, so the next call
|
|
344
370
|
// reads everything before it from the cache instead of paying for it again.
|
|
345
371
|
cache_control: { type: 'ephemeral' },
|
|
372
|
+
...(compacted && { betas: [compactionBeta] }),
|
|
346
373
|
// Anthropic compacts inside the call that passes it, and answers with the compaction first.
|
|
347
|
-
...(
|
|
348
|
-
betas: [compactionBeta],
|
|
374
|
+
...(trigger !== undefined && {
|
|
349
375
|
context_management: {
|
|
350
376
|
edits: [
|
|
351
377
|
{
|
|
352
378
|
type: 'compact_20260112',
|
|
353
|
-
trigger: { type: 'input_tokens', value:
|
|
379
|
+
trigger: { type: 'input_tokens', value: trigger },
|
|
354
380
|
},
|
|
355
381
|
],
|
|
356
382
|
},
|