@mikode13/harness 0.1.0 → 1.0.1

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.
Files changed (57) hide show
  1. package/README.md +41 -25
  2. package/dist/agent/domain/agent.d.ts +5 -1
  3. package/dist/agent/domain/agent.js.map +1 -1
  4. package/dist/agent/domain/errors.d.ts +6 -1
  5. package/dist/agent/domain/errors.js +6 -0
  6. package/dist/agent/domain/errors.js.map +1 -1
  7. package/dist/agent/domain/providerFailure.d.ts +6 -1
  8. package/dist/agent/domain/providerFailure.js +13 -0
  9. package/dist/agent/domain/providerFailure.js.map +1 -1
  10. package/dist/engines/claude/infrastructure/model/claudeAgent.d.ts +14 -5
  11. package/dist/engines/claude/infrastructure/model/claudeAgent.js +142 -29
  12. package/dist/engines/claude/infrastructure/model/claudeAgent.js.map +1 -1
  13. package/dist/engines/codex/infrastructure/model/codexAgent.d.ts +8 -9
  14. package/dist/engines/codex/infrastructure/model/codexAgent.js +35 -8
  15. package/dist/engines/codex/infrastructure/model/codexAgent.js.map +1 -1
  16. package/dist/factory/infrastructure/agentFactory.d.ts +49 -0
  17. package/dist/factory/infrastructure/agentFactory.js +91 -0
  18. package/dist/factory/infrastructure/agentFactory.js.map +1 -0
  19. package/dist/index.d.ts +2 -9
  20. package/dist/index.js +2 -6
  21. package/dist/index.js.map +1 -1
  22. package/dist/orchestration/domain/interface/validator.d.ts +0 -1
  23. package/dist/orchestration/domain/interface/validator.js.map +1 -1
  24. package/dist/orchestration/domain/model/orchestratorAgent.d.ts +11 -2
  25. package/dist/orchestration/domain/model/orchestratorAgent.js +13 -1
  26. package/dist/orchestration/domain/model/orchestratorAgent.js.map +1 -1
  27. package/dist/orchestration/domain/model/reviewerDecision.d.ts +0 -1
  28. package/dist/orchestration/domain/model/reviewerDecision.js.map +1 -1
  29. package/dist/orchestration/infrastructure/model/reviewerDecisionValidator.d.ts +0 -1
  30. package/dist/orchestration/infrastructure/model/reviewerDecisionValidator.js.map +1 -1
  31. package/dist/retry/domain/model/retryingAgent.d.ts +7 -2
  32. package/dist/retry/domain/model/retryingAgent.js +13 -3
  33. package/dist/retry/domain/model/retryingAgent.js.map +1 -1
  34. package/dist/shared/domain/isAbortError.d.ts +0 -1
  35. package/dist/shared/domain/isAbortError.js.map +1 -1
  36. package/dist/shared/domain/isOneOf.d.ts +2 -0
  37. package/dist/shared/domain/isOneOf.js +5 -0
  38. package/dist/shared/domain/isOneOf.js.map +1 -0
  39. package/dist/shared/domain/logger.d.ts +0 -3
  40. package/dist/shared/domain/logger.js.map +1 -1
  41. package/dist/shared/infrastructure/logger.d.ts +4 -0
  42. package/dist/shared/infrastructure/logger.js +6 -0
  43. package/dist/shared/infrastructure/logger.js.map +1 -0
  44. package/package.json +60 -57
  45. package/dist/agent/domain/agent.d.ts.map +0 -1
  46. package/dist/agent/domain/errors.d.ts.map +0 -1
  47. package/dist/agent/domain/providerFailure.d.ts.map +0 -1
  48. package/dist/engines/claude/infrastructure/model/claudeAgent.d.ts.map +0 -1
  49. package/dist/engines/codex/infrastructure/model/codexAgent.d.ts.map +0 -1
  50. package/dist/index.d.ts.map +0 -1
  51. package/dist/orchestration/domain/interface/validator.d.ts.map +0 -1
  52. package/dist/orchestration/domain/model/orchestratorAgent.d.ts.map +0 -1
  53. package/dist/orchestration/domain/model/reviewerDecision.d.ts.map +0 -1
  54. package/dist/orchestration/infrastructure/model/reviewerDecisionValidator.d.ts.map +0 -1
  55. package/dist/retry/domain/model/retryingAgent.d.ts.map +0 -1
  56. package/dist/shared/domain/isAbortError.d.ts.map +0 -1
  57. package/dist/shared/domain/logger.d.ts.map +0 -1
package/README.md CHANGED
@@ -56,19 +56,21 @@ chat loop itself never knows the difference.
56
56
  - Cancellation with `AbortController`/`AbortSignal`, shared between the prompt
57
57
  and every agent call, all the way down through the orchestrator.
58
58
 
59
+ ## Architecture
60
+
61
+ [`docs/architecture.md`](docs/architecture.md) is the current source for the module
62
+ boundaries, the dependency direction, the public contract, and the failure classification
63
+ every engine goes through. [`docs/decisions.md`](docs/decisions.md) keeps why each of them
64
+ was chosen.
65
+
59
66
  ## Where it is going
60
67
 
61
- Remaining work (see `tasks.txt` for the actionable, dated list):
68
+ Open work is tracked in GitHub issues:
62
69
 
63
- - Live streaming already ships; still open: type-while-thinking (respond to
64
- new input without blocking on the current agent call), session persistence
65
- across process restarts, and structured per-turn usage/duration logging.
66
- - Terminal UX polish (bordered chat box, markdown rendering, user-friendly
67
- error messages) — explicitly deferred until the above is solid.
68
- - Dynamic routing (deciding which flow/agent a request needs, instead of
69
- always running the fixed plan → execute → review workflow) — deliberately
70
- built _after_ that fixed flow, not alongside it, so the routing decision
71
- reuses a technique already proven on a simpler problem.
70
+ - [#17](https://github.com/Mikode13/harness/issues/17): dynamic routing
71
+ deciding which flow or agent a request needs, instead of always running the
72
+ fixed plan execute review workflow. It reuses the structured-decision
73
+ technique already proven on the reviewer.
72
74
 
73
75
  Deliberately out of scope for now: MCP, long-term memory, graph execution, and
74
76
  file-based agent registries — each waits for a real need.
@@ -97,17 +99,14 @@ comment on `Agent` in `src/agent/domain/agent.ts`.
97
99
  pnpm add @mikode13/harness
98
100
  ```
99
101
 
100
- An agent is composed, then driven; the package brings no I/O of its own:
102
+ An agent is built by a factory, then driven. The only output the package produces
103
+ on its own is diagnostic warnings on stderr, from a default logger that both
104
+ factories let you replace through their `logger` option:
101
105
 
102
106
  ```ts
103
- import {
104
- ClaudeAgent,
105
- RetryingAgent,
106
- UnrecoverableError,
107
- type ProgressEvent,
108
- } from '@mikode13/harness';
109
-
110
- const agent = new RetryingAgent(new ClaudeAgent('sonnet'));
107
+ import { createAgent, UnrecoverableError, type ProgressEvent } from '@mikode13/harness';
108
+
109
+ const agent = createAgent('claude', { model: 'sonnet' });
111
110
  const controller = new AbortController();
112
111
 
113
112
  const render = (event: ProgressEvent) => {
@@ -124,9 +123,18 @@ try {
124
123
 
125
124
  `ProgressEvent` is the public seam for live activity; rendering it is the
126
125
  consumer's decision, not the harness's. `cli/progressEventFormatter.ts` is one
127
- terminal-shaped implementation to copy from. Swapping `ClaudeAgent` for
128
- `CodexAgent`, or for an `OrchestratorAgent` wrapping all three roles, changes
129
- nothing else in the snippet above.
126
+ terminal-shaped implementation to copy from. New event types can arrive in minor
127
+ releases, so render the ones you know and ignore the rest. Swapping the agent for
128
+ `createAgent('codex')`, or for `createOrchestrator()` and its planner → executor →
129
+ reviewer workflow, changes nothing else in the snippet above.
130
+ `createOrchestrator({ provider: 'claude' })` runs every role on one provider, for
131
+ example when the other one is out of quota.
132
+
133
+ Every agent a factory returns already retries recoverable failures. A model or
134
+ reasoning effort the chosen provider does not support throws
135
+ `InvalidAgentConfigError` when the agent is built. Building a Codex agent throws
136
+ `UnrecoverableError` if the Codex CLI binary cannot be found, which happens when
137
+ optional dependencies were skipped at install time.
130
138
 
131
139
  ## Tests
132
140
 
@@ -153,14 +161,22 @@ This maps to each provider's permission-bypass mode and grants those processes
153
161
  unrestricted command access. Keep it disabled when the host may receive untrusted
154
162
  prompts, or provide an approval workflow from the entry point.
155
163
 
156
- Real consumers (a future REST/WebSocket server, a chatbot UI) compose the
157
- exported `Agent`, `OrchestratorAgent`, and other harness building blocks with
158
- their own I/O and `ILogger` adapter. `ConversationLoop`/`IPromptEmitter` are not
164
+ Real consumers (a future REST/WebSocket server, a chatbot UI) build agents
165
+ through `createAgent` and `createOrchestrator` and bring their own I/O, and
166
+ optionally their own `ILogger` adapter. `ConversationLoop`/`IPromptEmitter` are not
159
167
  part of the published package — they encode one specific interactive,
160
168
  turn-by-turn consumption pattern (see `cli/`), not the harness seam itself; a
161
169
  consumer that wants that same loop can use `cli/`'s implementation as a
162
170
  reference rather than depend on it as a library.
163
171
 
172
+ ## Releases
173
+
174
+ Versions follow Semantic Versioning and are published to npm automatically from
175
+ `main`. npm, the `v<version>` Git tags, and GitHub Releases are the release
176
+ history; the `version` in this repository stays at `0.0.0-development`. New
177
+ `ProgressEvent` types, models, and reasoning efforts ship in minor releases;
178
+ removing any of them is a major release.
179
+
164
180
  ## License
165
181
 
166
182
  This project is source-available under the MIT License with the
@@ -5,6 +5,11 @@ export interface AgentResponse {
5
5
  duration: number;
6
6
  }
7
7
  export type Callback = (item: ProgressEvent) => void;
8
+ /**
9
+ * Live activity during a run, for narration only: the result travels in `AgentResponse`.
10
+ * New event types can arrive in a minor release, so render the types you know and ignore
11
+ * the rest instead of switching over them exhaustively with a `never` check.
12
+ */
8
13
  export type ProgressEvent = {
9
14
  type: 'command';
10
15
  command: string;
@@ -60,4 +65,3 @@ export type ProgressEvent = {
60
65
  export interface Agent {
61
66
  run(prompt: string, signal: AbortSignal, callback: Callback): Promise<AgentResponse | undefined>;
62
67
  }
63
- //# sourceMappingURL=agent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"agent.js","sourceRoot":"","sources":["../../../src/agent/domain/agent.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"agent.js","sourceRoot":"","sources":["../../../src/agent/domain/agent.ts"],"names":[],"mappings":"","sourcesContent":["// We tried to add cost, but that would imply to manage it manually for some agents.\nexport interface AgentResponse {\n\tresponse: string;\n\tinputTokens: number;\n\toutputTokens: number;\n\t// time in seconds\n\tduration: number;\n}\n\nexport type Callback = (item: ProgressEvent) => void;\n\n/**\n * Live activity during a run, for narration only: the result travels in `AgentResponse`.\n * New event types can arrive in a minor release, so render the types you know and ignore\n * the rest instead of switching over them exhaustively with a `never` check.\n */\nexport type ProgressEvent =\n\t| { type: 'command'; command: string; exitCode?: number }\n\t| { type: 'reasoning'; message: string }\n\t| { type: 'search'; query: string }\n\t| { type: 'fileChange'; changes: { path: string; kind: 'add' | 'update' | 'delete' }[] }\n\t| { type: 'mcpTool'; server: string; tool: string; status: string }\n\t| { type: 'agentMessage'; message: string }\n\t| { type: 'todoList'; items: { text: string; completed: boolean }[] }\n\t| { type: 'turnStarted' }\n\t| { type: 'turnEnded' };\n\n/**\n * The contract every engine (CodexAgent, ClaudeAgent, future providers) and every\n * decorator (RetryingAgent, OrchestratorAgent) is built against.\n *\n * Implementers MUST only ever reject with `RecoverableError` or `UnrecoverableError`\n * (see ./errors.ts) — never a raw SDK error, a plain `Error`, or anything else leaked\n * unclassified. Every consumer of `Agent` (RetryingAgent's retry decision,\n * OrchestratorAgent's failure handling) `instanceof`-checks against those two types to\n * decide what to do next; a leaked, unclassified error bypasses that decision\n * entirely — it gets retried when it shouldn't be, or crashes a run that a retry\n * would have recovered. Wrap every call into the underlying SDK so nothing escapes\n * unclassified, including failures the SDK itself doesn't model as a domain error\n * (network errors, malformed responses, etc.); `classifyProviderFailure` does this.\n *\n * Cancellation is the one exception: an `AbortError` must propagate unchanged, because\n * consumers check for it before either error type.\n */\nexport interface Agent {\n\trun(prompt: string, signal: AbortSignal, callback: Callback): Promise<AgentResponse | undefined>;\n}\n"]}
@@ -10,4 +10,9 @@ export declare class UnrecoverableError extends Error {
10
10
  cause: string;
11
11
  });
12
12
  }
13
- //# sourceMappingURL=errors.d.ts.map
13
+ /**
14
+ * An agent was requested with something its provider does not support, such as another
15
+ * provider's model. Thrown while the agent is built, never by `run()`.
16
+ */
17
+ export declare class InvalidAgentConfigError extends Error {
18
+ }
@@ -12,4 +12,10 @@ export class UnrecoverableError extends Error {
12
12
  this.cause = options.cause;
13
13
  }
14
14
  }
15
+ /**
16
+ * An agent was requested with something its provider does not support, such as another
17
+ * provider's model. Thrown while the agent is built, never by `run()`.
18
+ */
19
+ export class InvalidAgentConfigError extends Error {
20
+ }
15
21
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/agent/domain/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACjC,KAAK,CAAS;IAEvB,YAAY,OAAe,EAAE,OAA0B;QACtD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC5B,CAAC;CACD;AACD,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IACnC,KAAK,CAAS;IAEvB,YAAY,OAAe,EAAE,OAA0B;QACtD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC5B,CAAC;CACD"}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/agent/domain/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACjC,KAAK,CAAS;IAEvB,YAAY,OAAe,EAAE,OAA0B;QACtD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC5B,CAAC;CACD;AACD,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IACnC,KAAK,CAAS;IAEvB,YAAY,OAAe,EAAE,OAA0B;QACtD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC5B,CAAC;CACD;AAED;;;GAGG;AACH,MAAM,OAAO,uBAAwB,SAAQ,KAAK;CAAG","sourcesContent":["export class RecoverableError extends Error {\n\toverride cause: string;\n\n\tconstructor(message: string, options: { cause: string }) {\n\t\tsuper(message, options);\n\t\tthis.cause = options.cause;\n\t}\n}\nexport class UnrecoverableError extends Error {\n\toverride cause: string;\n\n\tconstructor(message: string, options: { cause: string }) {\n\t\tsuper(message, options);\n\t\tthis.cause = options.cause;\n\t}\n}\n\n/**\n * An agent was requested with something its provider does not support, such as another\n * provider's model. Thrown while the agent is built, never by `run()`.\n */\nexport class InvalidAgentConfigError extends Error {}\n"]}
@@ -6,6 +6,12 @@
6
6
  export declare function classifyProviderFailure(error: unknown, context: string): Error;
7
7
  /** A host failure cannot be retried safely because the provider turn may already have side effects. */
8
8
  export declare function classifyHostFailure(error: unknown, context: string): Error;
9
+ /**
10
+ * Runs host code — a logger, for example — and classifies whatever it throws with the
11
+ * classifier the caller chooses. The host code stays unaware of classification, and the
12
+ * failure cannot escape the `Agent` unclassified.
13
+ */
14
+ export declare function treatErrors<T>(operation: () => T, classify: (error: unknown, context: string) => Error, context: string): T;
9
15
  /** Preserves deliberate domain errors while making unexpected local failures fatal. */
10
16
  export declare function classifyLocalFailure(error: unknown, context: string): Error;
11
17
  /** The message alone: a stack or serialized object could expose unstable implementation details. */
@@ -17,4 +23,3 @@ export declare function describeFailure(error: unknown): string;
17
23
  * failure and `RetryingAgent` replays a turn that already ran its side effects.
18
24
  */
19
25
  export declare function classifiedProviderStream<T>(stream: AsyncIterable<T>, context: string): AsyncGenerator<T>;
20
- //# sourceMappingURL=providerFailure.d.ts.map
@@ -20,6 +20,19 @@ export function classifyHostFailure(error, context) {
20
20
  return error;
21
21
  return new UnrecoverableError(context, { cause: describeFailure(error) });
22
22
  }
23
+ /**
24
+ * Runs host code — a logger, for example — and classifies whatever it throws with the
25
+ * classifier the caller chooses. The host code stays unaware of classification, and the
26
+ * failure cannot escape the `Agent` unclassified.
27
+ */
28
+ export function treatErrors(operation, classify, context) {
29
+ try {
30
+ return operation();
31
+ }
32
+ catch (error) {
33
+ throw classify(error, context);
34
+ }
35
+ }
23
36
  /** Preserves deliberate domain errors while making unexpected local failures fatal. */
24
37
  export function classifyLocalFailure(error, context) {
25
38
  if (isAbortError(error))
@@ -1 +1 @@
1
- {"version":3,"file":"providerFailure.js","sourceRoot":"","sources":["../../../src/agent/domain/providerFailure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEnE;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,KAAc,EAAE,OAAe;IACtE,IAAI,YAAY,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACtC,IAAI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,YAAY,KAAK,IAAI,KAAK,CAAC,OAAO;QAAE,OAAO,KAAK,CAAC,OAAO,CAAC;IAClE,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK;QAAE,OAAO,KAAK,CAAC;IAErD,OAAO,4CAA4C,CAAC;AACrD,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,wBAAwB,CAC9C,MAAwB,EACxB,OAAe;IAEf,IAAI,MAAwB,CAAC;IAE7B,IAAI,CAAC;QACJ,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;IACzC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,uBAAuB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC/C,CAAC;IAED,IAAI,SAAS,GAAG,KAAK,CAAC;IAEtB,IAAI,CAAC;QACJ,SAAS,CAAC;YACT,IAAI,IAAuB,CAAC;YAE5B,IAAI,CAAC;gBACJ,IAAI,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;YAC5B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,MAAM,uBAAuB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YAC/C,CAAC;YAED,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;gBACf,SAAS,GAAG,IAAI,CAAC;gBACjB,OAAO;YACR,CAAC;YAED,MAAM,IAAI,CAAC,KAAK,CAAC;QAClB,CAAC;IACF,CAAC;YAAS,CAAC;QACV,IAAI,CAAC,SAAS,EAAE,CAAC;YAChB,IAAI,CAAC;gBACJ,MAAM,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC;YACzB,CAAC;YAAC,MAAM,CAAC;gBACR,4EAA4E;gBAC5E,4EAA4E;YAC7E,CAAC;QACF,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import { isAbortError } from '../../shared/domain/isAbortError.ts';\nimport { RecoverableError, UnrecoverableError } from './errors.ts';\n\n/**\n * Unclassified failures are transport-shaped, so recoverable is the useful default:\n * `RetryingAgent` turns a persistent one into an `UnrecoverableError` on exhaustion, while\n * the opposite default would make every transient blip fatal.\n */\nexport function classifyProviderFailure(error: unknown, context: string): Error {\n\tif (isAbortError(error)) return error;\n\tif (error instanceof RecoverableError || error instanceof UnrecoverableError) return error;\n\n\treturn new RecoverableError(context, { cause: describeFailure(error) });\n}\n\n/** A host failure cannot be retried safely because the provider turn may already have side effects. */\nexport function classifyHostFailure(error: unknown, context: string): Error {\n\tif (isAbortError(error)) return error;\n\tif (error instanceof UnrecoverableError) return error;\n\n\treturn new UnrecoverableError(context, { cause: describeFailure(error) });\n}\n\n/**\n * Runs host code — a logger, for example — and classifies whatever it throws with the\n * classifier the caller chooses. The host code stays unaware of classification, and the\n * failure cannot escape the `Agent` unclassified.\n */\nexport function treatErrors<T>(\n\toperation: () => T,\n\tclassify: (error: unknown, context: string) => Error,\n\tcontext: string,\n): T {\n\ttry {\n\t\treturn operation();\n\t} catch (error) {\n\t\tthrow classify(error, context);\n\t}\n}\n\n/** Preserves deliberate domain errors while making unexpected local failures fatal. */\nexport function classifyLocalFailure(error: unknown, context: string): Error {\n\tif (isAbortError(error)) return error;\n\tif (error instanceof RecoverableError || error instanceof UnrecoverableError) return error;\n\n\treturn new UnrecoverableError(context, { cause: describeFailure(error) });\n}\n\n/** The message alone: a stack or serialized object could expose unstable implementation details. */\nexport function describeFailure(error: unknown): string {\n\tif (error instanceof RecoverableError || error instanceof UnrecoverableError) return error.cause;\n\tif (error instanceof Error && error.message) return error.message;\n\tif (typeof error === 'string' && error) return error;\n\n\treturn 'The provider failed without a description.';\n}\n\n/**\n * Classifies the stream itself and nothing else. Consuming an SDK stream inside a\n * `try/catch` puts the loop body — item mapping, logging, the consumer callback — inside\n * the provider boundary too, so a host failure gets reported as a recoverable provider\n * failure and `RetryingAgent` replays a turn that already ran its side effects.\n */\nexport async function* classifiedProviderStream<T>(\n\tstream: AsyncIterable<T>,\n\tcontext: string,\n): AsyncGenerator<T> {\n\tlet events: AsyncIterator<T>;\n\n\ttry {\n\t\tevents = stream[Symbol.asyncIterator]();\n\t} catch (error) {\n\t\tthrow classifyProviderFailure(error, context);\n\t}\n\n\tlet completed = false;\n\n\ttry {\n\t\tfor (;;) {\n\t\t\tlet next: IteratorResult<T>;\n\n\t\t\ttry {\n\t\t\t\tnext = await events.next();\n\t\t\t} catch (error) {\n\t\t\t\tthrow classifyProviderFailure(error, context);\n\t\t\t}\n\n\t\t\tif (next.done) {\n\t\t\t\tcompleted = true;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tyield next.value;\n\t\t}\n\t} finally {\n\t\tif (!completed) {\n\t\t\ttry {\n\t\t\t\tawait events.return?.();\n\t\t\t} catch {\n\t\t\t\t// Cleanup is secondary to the failure that interrupted consumption. It must\n\t\t\t\t// never replace a classified provider error or an unrecoverable host error.\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
@@ -1,17 +1,26 @@
1
- import type { EffortLevel } from '@anthropic-ai/claude-agent-sdk';
2
1
  import type { Agent, AgentResponse, Callback } from '../../../../agent/domain/agent.ts';
3
- type Model = 'sonnet' | 'opus' | 'haiku' | 'claude-fable-5';
2
+ import type { ILogger } from '../../../../shared/domain/logger.ts';
3
+ export declare const claudeModels: readonly ["haiku", "sonnet", "opus", "fable"];
4
+ export type ClaudeModel = (typeof claudeModels)[number];
5
+ export declare const claudeReasoningEfforts: readonly ["low", "medium", "high", "xhigh", "max"];
6
+ export type ClaudeReasoningEffort = (typeof claudeReasoningEfforts)[number];
4
7
  export declare class ClaudeAgent implements Agent {
5
8
  private model;
6
9
  private autoApprove;
7
10
  private reasoningEffort;
8
11
  private sessionId?;
9
- constructor(model: Model, autoApprove?: boolean, reasoningEffort?: EffortLevel);
12
+ private logger;
13
+ constructor({ model, autoApprove, reasoningEffort, logger, }: {
14
+ model: string;
15
+ autoApprove?: boolean;
16
+ reasoningEffort?: string;
17
+ logger: ILogger;
18
+ });
10
19
  run(prompt: string, signal: AbortSignal, callback: Callback): Promise<AgentResponse | undefined>;
11
20
  private parseResponse;
21
+ private handleSystemMessage;
12
22
  private handleAssistantMessage;
13
23
  private handleUserMessage;
14
24
  private handleCompletedTool;
25
+ private warn;
15
26
  }
16
- export {};
17
- //# sourceMappingURL=claudeAgent.d.ts.map
@@ -1,6 +1,16 @@
1
1
  import { query } from '@anthropic-ai/claude-agent-sdk';
2
- import { RecoverableError } from "../../../../agent/domain/errors.js";
3
- import { classifiedProviderStream, classifyHostFailure, classifyLocalFailure, classifyProviderFailure, } from "../../../../agent/domain/providerFailure.js";
2
+ import { InvalidAgentConfigError, RecoverableError } from "../../../../agent/domain/errors.js";
3
+ import { classifiedProviderStream, classifyHostFailure, classifyLocalFailure, classifyProviderFailure, treatErrors, } from "../../../../agent/domain/providerFailure.js";
4
+ import { isOneOf } from "../../../../shared/domain/isOneOf.js";
5
+ // The SDK types `model` as a plain string, so this list is maintained by hand.
6
+ export const claudeModels = ['haiku', 'sonnet', 'opus', 'fable'];
7
+ export const claudeReasoningEfforts = [
8
+ 'low',
9
+ 'medium',
10
+ 'high',
11
+ 'xhigh',
12
+ 'max',
13
+ ];
4
14
  function emitProgress(callback, event) {
5
15
  try {
6
16
  callback(event);
@@ -61,6 +71,8 @@ function mcpTool(tool, result) {
61
71
  status: result.is_error ? 'failed' : 'completed',
62
72
  };
63
73
  }
74
+ // Tools without narration (Read, Grep, Task, ...) are a presentation choice, not an unknown:
75
+ // the tool set is open-ended, so warning here would only produce noise.
64
76
  function describeCompletedTool(tool, result, output) {
65
77
  if (tool.name === 'Bash') {
66
78
  const exitCode = asRecord(output)?.exitCode ?? asRecord(output)?.exit_code;
@@ -90,12 +102,23 @@ export class ClaudeAgent {
90
102
  autoApprove;
91
103
  reasoningEffort;
92
104
  sessionId;
93
- constructor(model, autoApprove = false, reasoningEffort = 'high') {
105
+ logger;
106
+ // `model` and `reasoningEffort` are untyped on purpose: this adapter is the one that knows
107
+ // what Claude supports, so it validates them instead of trusting the caller.
108
+ constructor({ model, autoApprove = false, reasoningEffort = 'high', logger, }) {
109
+ if (!isOneOf(claudeModels, model)) {
110
+ throw new InvalidAgentConfigError(`"${model}" is not a Claude model; expected one of: ${claudeModels.join(', ')}`);
111
+ }
112
+ if (!isOneOf(claudeReasoningEfforts, reasoningEffort)) {
113
+ throw new InvalidAgentConfigError(`"${reasoningEffort}" is not a Claude reasoning effort; expected one of: ${claudeReasoningEfforts.join(', ')}`);
114
+ }
94
115
  this.model = model;
95
116
  this.autoApprove = autoApprove;
96
117
  this.reasoningEffort = reasoningEffort;
118
+ this.logger = logger;
97
119
  }
98
120
  async run(prompt, signal, callback) {
121
+ signal.throwIfAborted();
99
122
  let stream;
100
123
  try {
101
124
  stream = query({
@@ -118,12 +141,18 @@ export class ClaudeAgent {
118
141
  catch (error) {
119
142
  throw classifyProviderFailure(error, 'Claude refused the request');
120
143
  }
121
- signal.addEventListener('abort', () => {
144
+ const closeStream = () => {
122
145
  stream.close();
123
- });
124
- return await this.parseResponse(stream, callback);
146
+ };
147
+ signal.addEventListener('abort', closeStream, { once: true });
148
+ try {
149
+ return await this.parseResponse(stream, signal, callback);
150
+ }
151
+ finally {
152
+ signal.removeEventListener('abort', closeStream);
153
+ }
125
154
  }
126
- async parseResponse(stream, callback) {
155
+ async parseResponse(stream, signal, callback) {
127
156
  const lines = [];
128
157
  let resultMessage;
129
158
  const pendingTools = new Map();
@@ -149,12 +178,31 @@ export class ClaudeAgent {
149
178
  });
150
179
  }
151
180
  break;
181
+ case 'system':
182
+ this.handleSystemMessage(message);
183
+ break;
184
+ // Known messages with nothing to narrate or report.
185
+ case 'stream_event':
186
+ case 'tool_progress':
187
+ case 'tool_use_summary':
188
+ case 'auth_status':
189
+ case 'rate_limit_event':
190
+ case 'prompt_suggestion':
191
+ case 'conversation_reset':
192
+ break;
193
+ default: {
194
+ // `never` breaks the build when an SDK upgrade adds a message type; the
195
+ // warning covers a CLI binary that is newer than the types.
196
+ const unknownMessage = message;
197
+ this.warn(unknownMessage, 'Unknown Claude message type');
198
+ }
152
199
  }
153
200
  }
154
201
  catch (error) {
155
202
  throw classifyLocalFailure(error, 'Claude failed while mapping progress');
156
203
  }
157
204
  }
205
+ signal.throwIfAborted();
158
206
  if (!lines.length || !resultMessage) {
159
207
  return undefined;
160
208
  }
@@ -165,32 +213,92 @@ export class ClaudeAgent {
165
213
  duration: resultMessage.duration_ms / 1000,
166
214
  };
167
215
  }
216
+ handleSystemMessage(message) {
217
+ switch (message.subtype) {
218
+ // Failures the SDK handled without failing the turn: only a warning makes them visible.
219
+ case 'api_retry':
220
+ case 'model_refusal_fallback':
221
+ case 'model_refusal_no_fallback':
222
+ case 'permission_denied':
223
+ case 'mirror_error':
224
+ this.warn(message, 'Claude reported a failure without failing the turn');
225
+ return;
226
+ // Known messages with nothing to narrate or report.
227
+ case 'init':
228
+ case 'compact_boundary':
229
+ case 'status':
230
+ case 'control_request_progress':
231
+ case 'local_command_output':
232
+ case 'hook_started':
233
+ case 'hook_progress':
234
+ case 'hook_response':
235
+ case 'plugin_install':
236
+ case 'task_notification':
237
+ case 'task_started':
238
+ case 'task_updated':
239
+ case 'task_progress':
240
+ case 'background_tasks_changed':
241
+ case 'thinking_tokens':
242
+ case 'session_state_changed':
243
+ case 'worker_shutting_down':
244
+ case 'commands_changed':
245
+ case 'notification':
246
+ case 'files_persisted':
247
+ case 'memory_recall':
248
+ case 'elicitation_complete':
249
+ case 'informational':
250
+ return;
251
+ default: {
252
+ const unknownMessage = message;
253
+ this.warn(unknownMessage, 'Unknown Claude system message');
254
+ }
255
+ }
256
+ }
168
257
  handleAssistantMessage(message, pendingTools, callback) {
169
258
  for (const block of message.message.content) {
170
- if (block.type === 'text') {
171
- emitProgress(callback, { type: 'agentMessage', message: block.text });
172
- continue;
173
- }
174
- if (block.type === 'thinking') {
175
- emitProgress(callback, { type: 'reasoning', message: block.thinking });
176
- continue;
177
- }
178
- if (block.type === 'tool_use' ||
179
- block.type === 'server_tool_use' ||
180
- block.type === 'mcp_tool_use') {
181
- const input = asRecord(block.input);
182
- if (input) {
183
- pendingTools.set(block.id, {
184
- name: block.name === 'web_search' ? 'WebSearch' : block.name,
185
- input,
186
- ...('server_name' in block && typeof block.server_name === 'string'
187
- ? { server: block.server_name }
188
- : parseMcpServer(block.name)),
189
- });
259
+ switch (block.type) {
260
+ case 'text':
261
+ emitProgress(callback, { type: 'agentMessage', message: block.text });
262
+ break;
263
+ case 'thinking':
264
+ emitProgress(callback, { type: 'reasoning', message: block.thinking });
265
+ break;
266
+ case 'tool_use':
267
+ case 'server_tool_use':
268
+ case 'mcp_tool_use': {
269
+ const input = asRecord(block.input);
270
+ if (input) {
271
+ pendingTools.set(block.id, {
272
+ name: block.name === 'web_search' ? 'WebSearch' : block.name,
273
+ input,
274
+ ...('server_name' in block && typeof block.server_name === 'string'
275
+ ? { server: block.server_name }
276
+ : parseMcpServer(block.name)),
277
+ });
278
+ }
279
+ break;
280
+ }
281
+ case 'web_search_tool_result':
282
+ case 'web_fetch_tool_result':
283
+ case 'advisor_tool_result':
284
+ case 'code_execution_tool_result':
285
+ case 'bash_code_execution_tool_result':
286
+ case 'text_editor_code_execution_tool_result':
287
+ case 'tool_search_tool_result':
288
+ case 'mcp_tool_result':
289
+ this.handleCompletedTool(block, pendingTools, callback);
290
+ break;
291
+ // Known blocks with nothing to narrate.
292
+ case 'redacted_thinking':
293
+ case 'container_upload':
294
+ case 'compaction':
295
+ case 'fallback':
296
+ break;
297
+ default: {
298
+ const unknownBlock = block;
299
+ this.warn(unknownBlock, 'Unknown Claude content block');
190
300
  }
191
- continue;
192
301
  }
193
- this.handleCompletedTool(block, pendingTools, callback);
194
302
  }
195
303
  }
196
304
  handleUserMessage(message, pendingTools, callback) {
@@ -215,6 +323,11 @@ export class ClaudeAgent {
215
323
  if (description)
216
324
  emitProgress(callback, description);
217
325
  }
326
+ warn(...args) {
327
+ treatErrors(() => {
328
+ this.logger.warn(...args);
329
+ }, classifyHostFailure, 'Claude logger failed while reporting progress');
330
+ }
218
331
  }
219
332
  function parseMcpServer(name) {
220
333
  if (!name.startsWith('mcp__'))
@@ -1 +1 @@
1
- {"version":3,"file":"claudeAgent.js","sourceRoot":"","sources":["../../../../../src/engines/claude/infrastructure/model/claudeAgent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AAcvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EACN,wBAAwB,EACxB,mBAAmB,EACnB,oBAAoB,EACpB,uBAAuB,GACvB,MAAM,6CAA6C,CAAC;AAiBrD,SAAS,YAAY,CAAC,QAAkB,EAAE,KAAoB;IAC7D,IAAI,CAAC;QACJ,QAAQ,CAAC,KAAK,CAAC,CAAC;IACjB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,mBAAmB,CAAC,KAAK,EAAE,iCAAiC,CAAC,CAAC;IACrE,CAAC;AACF,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAC1E,CAAC,CAAE,KAAiC;QACpC,CAAC,CAAC,SAAS,CAAC;AACd,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IAClC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACtD,CAAC;AAED,SAAS,eAAe,CAAC,KAAc;IACtC,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9B,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,KAAK,CAAC,WAAW,KAAK,QAAQ,EAAE,CAAC;QACvF,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,OAAO,KAAmC,CAAC;AAC5C,C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;QAC9B,WAAW,CACV,GAAG,EAAE;YACJ,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;QAC3B,CAAC,EACD,mBAAmB,EACnB,+CAA+C,CAC/C,CAAC;IACH,CAAC;CACD;AAED,SAAS,cAAc,CAAC,IAAY;IACnC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;QAAE,OAAO,SAAS,CAAC;IAEhD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IACzD,OAAO,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AACxC,CAAC","sourcesContent":["import { query } from '@anthropic-ai/claude-agent-sdk';\nimport type {\n\tEffortLevel,\n\tQuery,\n\tSDKAssistantMessage,\n\tSDKMessage,\n\tSDKResultSuccess,\n\tSDKUserMessage,\n} from '@anthropic-ai/claude-agent-sdk';\nimport type {\n\tAgent,\n\tAgentResponse,\n\tCallback,\n\tProgressEvent,\n} from '../../../../agent/domain/agent.ts';\nimport { InvalidAgentConfigError, RecoverableError } from '../../../../agent/domain/errors.ts';\nimport {\n\tclassifiedProviderStream,\n\tclassifyHostFailure,\n\tclassifyLocalFailure,\n\tclassifyProviderFailure,\n\ttreatErrors,\n} from '../../../../agent/domain/providerFailure.ts';\nimport type { ILogger } from '../../../../shared/domain/logger.ts';\nimport { isOneOf } from '../../../../shared/domain/isOneOf.ts';\n\n// The SDK types `model` as a plain string, so this list is maintained by hand.\nexport const claudeModels = ['haiku', 'sonnet', 'opus', 'fable'] as const;\nexport type ClaudeModel = (typeof claudeModels)[number];\n\nexport const claudeReasoningEfforts = [\n\t'low',\n\t'medium',\n\t'high',\n\t'xhigh',\n\t'max',\n] as const satisfies readonly EffortLevel[];\nexport type ClaudeReasoningEffort = (typeof claudeReasoningEfforts)[number];\n\ntype SDKSystemMessage = Extract<SDKMessage, { type: 'system' }>;\n\ninterface PendingTool {\n\tname: string;\n\tinput: Record<string, unknown>;\n\tserver?: string;\n}\n\ninterface ToolResultBlock {\n\ttype: string;\n\ttool_use_id: string;\n\tis_error?: boolean;\n\tcontent?: unknown;\n}\n\nfunction emitProgress(callback: Callback, event: ProgressEvent): void {\n\ttry {\n\t\tcallback(event);\n\t} catch (error) {\n\t\tthrow classifyHostFailure(error, 'Claude progress callback failed');\n\t}\n}\n\nfunction asRecord(value: unknown): Record<string, unknown> | undefined {\n\treturn typeof value === 'object' && value !== null && !Array.isArray(value)\n\t\t? (value as Record<string, unknown>)\n\t\t: undefined;\n}\n\nfunction stringValue(value: unknown): string | undefined {\n\treturn typeof value === 'string' ? value : undefined;\n}\n\nfunction toolResultBlock(value: unknown): ToolResultBlock | undefined {\n\tconst block = asRecord(value);\n\tif (!block || typeof block.type !== 'string' || typeof block.tool_use_id !== 'string') {\n\t\treturn undefined;\n\t}\n\n\treturn block as unknown as ToolResultBlock;\n}\n\nfunction toolResultId(value: unknown): string | undefined {\n\treturn toolResultBlock(value)?.tool_use_id;\n}\n\nfunction fileChange(\n\tname: 'Edit' | 'Write',\n\ttool: PendingTool,\n\toutput: unknown,\n): ProgressEvent | undefined {\n\tconst inputPath = stringValue(tool.input.file_path);\n\tconst outputPath = stringValue(asRecord(output)?.filePath);\n\tconst path = outputPath ?? inputPath;\n\tif (!path) return undefined;\n\n\tconst kind =\n\t\tname === 'Write' && stringValue(asRecord(output)?.type) === 'create' ? 'add' : 'update';\n\treturn { type: 'fileChange', changes: [{ path, kind }] };\n}\n\nfunction todoList(tool: PendingTool): ProgressEvent | undefined {\n\tif (!Array.isArray(tool.input.todos)) return undefined;\n\n\tconst items = tool.input.todos.flatMap(todo => {\n\t\tconst item = asRecord(todo);\n\t\tconst text = stringValue(item?.content);\n\t\tconst status = stringValue(item?.status);\n\t\treturn text && status ? [{ text, completed: status === 'completed' }] : [];\n\t});\n\n\treturn { type: 'todoList', items };\n}\n\nfunction mcpTool(tool: PendingTool, result: ToolResultBlock): ProgressEvent | undefined {\n\tconst server = tool.server;\n\tconst toolName = tool.name.startsWith('mcp__')\n\t\t? tool.name.slice('mcp__'.length).split('__').slice(1).join('__')\n\t\t: tool.name;\n\tif (!server || !toolName) return undefined;\n\n\treturn {\n\t\ttype: 'mcpTool',\n\t\tserver,\n\t\ttool: toolName,\n\t\tstatus: result.is_error ? 'failed' : 'completed',\n\t};\n}\n\n// Tools without narration (Read, Grep, Task, ...) are a presentation choice, not an unknown:\n// the tool set is open-ended, so warning here would only produce noise.\nfunction describeCompletedTool(\n\ttool: PendingTool,\n\tresult: ToolResultBlock,\n\toutput: unknown,\n): ProgressEvent | undefined {\n\tif (tool.name === 'Bash') {\n\t\tconst exitCode = asRecord(output)?.exitCode ?? asRecord(output)?.exit_code;\n\t\treturn {\n\t\t\ttype: 'command',\n\t\t\tcommand: stringValue(tool.input.command) ?? '',\n\t\t\t...(typeof exitCode === 'number' ? { exitCode } : {}),\n\t\t};\n\t}\n\n\tif (tool.name === 'WebSearch') {\n\t\tconst query = stringValue(tool.input.query);\n\t\treturn query ? { type: 'search', query } : undefined;\n\t}\n\n\tif (tool.name === 'Edit' || tool.name === 'Write') {\n\t\treturn result.is_error ? undefined : fileChange(tool.name, tool, output);\n\t}\n\n\tif (tool.name === 'TodoWrite') {\n\t\treturn result.is_error ? undefined : todoList(tool);\n\t}\n\n\tif (tool.name.startsWith('mcp__') || tool.server) {\n\t\treturn mcpTool(tool, result);\n\t}\n\n\treturn undefined;\n}\n\nexport class ClaudeAgent implements Agent {\n\tprivate model: ClaudeModel;\n\tprivate autoApprove: boolean;\n\tprivate reasoningEffort: ClaudeReasoningEffort;\n\tprivate sessionId?: string;\n\tprivate logger: ILogger;\n\n\t// `model` and `reasoningEffort` are untyped on purpose: this adapter is the one that knows\n\t// what Claude supports, so it validates them instead of trusting the caller.\n\tconstructor({\n\t\tmodel,\n\t\tautoApprove = false,\n\t\treasoningEffort = 'high',\n\t\tlogger,\n\t}: {\n\t\tmodel: string;\n\t\tautoApprove?: boolean;\n\t\treasoningEffort?: string;\n\t\tlogger: ILogger;\n\t}) {\n\t\tif (!isOneOf(claudeModels, model)) {\n\t\t\tthrow new InvalidAgentConfigError(\n\t\t\t\t`\"${model}\" is not a Claude model; expected one of: ${claudeModels.join(', ')}`,\n\t\t\t);\n\t\t}\n\t\tif (!isOneOf(claudeReasoningEfforts, reasoningEffort)) {\n\t\t\tthrow new InvalidAgentConfigError(\n\t\t\t\t`\"${reasoningEffort}\" is not a Claude reasoning effort; expected one of: ${claudeReasoningEfforts.join(', ')}`,\n\t\t\t);\n\t\t}\n\n\t\tthis.model = model;\n\t\tthis.autoApprove = autoApprove;\n\t\tthis.reasoningEffort = reasoningEffort;\n\t\tthis.logger = logger;\n\t}\n\n\tasync run(\n\t\tprompt: string,\n\t\tsignal: AbortSignal,\n\t\tcallback: Callback,\n\t): Promise<AgentResponse | undefined> {\n\t\tsignal.throwIfAborted();\n\n\t\tlet stream: Query;\n\n\t\ttry {\n\t\t\tstream = query({\n\t\t\t\tprompt,\n\t\t\t\toptions: {\n\t\t\t\t\teffort: this.reasoningEffort,\n\t\t\t\t\tmodel: this.model,\n\t\t\t\t\tmaxTurns: 3,\n\t\t\t\t\tcwd: process.cwd(),\n\t\t\t\t\tresume: this.sessionId,\n\t\t\t\t\t...(this.autoApprove\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tpermissionMode: 'bypassPermissions' as const,\n\t\t\t\t\t\t\t\tallowDangerouslySkipPermissions: true,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: {}),\n\t\t\t\t},\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tthrow classifyProviderFailure(error, 'Claude refused the request');\n\t\t}\n\n\t\tconst closeStream = () => {\n\t\t\tstream.close();\n\t\t};\n\t\tsignal.addEventListener('abort', closeStream, { once: true });\n\n\t\ttry {\n\t\t\treturn await this.parseResponse(stream, signal, callback);\n\t\t} finally {\n\t\t\tsignal.removeEventListener('abort', closeStream);\n\t\t}\n\t}\n\n\tprivate async parseResponse(\n\t\tstream: Query,\n\t\tsignal: AbortSignal,\n\t\tcallback: Callback,\n\t): Promise<AgentResponse | undefined> {\n\t\tconst lines: string[] = [];\n\t\tlet resultMessage: SDKResultSuccess | undefined;\n\t\tconst pendingTools = new Map<string, PendingTool>();\n\n\t\tconst messages = classifiedProviderStream(stream, 'Claude stream ended unexpectedly');\n\n\t\tfor await (const message of messages) {\n\t\t\tthis.sessionId ??= message.session_id;\n\n\t\t\ttry {\n\t\t\t\tswitch (message.type) {\n\t\t\t\t\tcase 'assistant':\n\t\t\t\t\t\tthis.handleAssistantMessage(message, pendingTools, callback);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'user':\n\t\t\t\t\t\tthis.handleUserMessage(message, pendingTools, callback);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'result':\n\t\t\t\t\t\tif (message.subtype === 'success') {\n\t\t\t\t\t\t\tlines.push(message.result);\n\t\t\t\t\t\t\tresultMessage = message;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthrow new RecoverableError('Claude sdk error', {\n\t\t\t\t\t\t\t\tcause: [message.stop_reason, message.terminal_reason, ...message.errors].join(','),\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'system':\n\t\t\t\t\t\tthis.handleSystemMessage(message);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t// Known messages with nothing to narrate or report.\n\t\t\t\t\tcase 'stream_event':\n\t\t\t\t\tcase 'tool_progress':\n\t\t\t\t\tcase 'tool_use_summary':\n\t\t\t\t\tcase 'auth_status':\n\t\t\t\t\tcase 'rate_limit_event':\n\t\t\t\t\tcase 'prompt_suggestion':\n\t\t\t\t\tcase 'conversation_reset':\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\t// `never` breaks the build when an SDK upgrade adds a message type; the\n\t\t\t\t\t\t// warning covers a CLI binary that is newer than the types.\n\t\t\t\t\t\tconst unknownMessage: never = message;\n\t\t\t\t\t\tthis.warn(unknownMessage, 'Unknown Claude message type');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tthrow classifyLocalFailure(error, 'Claude failed while mapping progress');\n\t\t\t}\n\t\t}\n\n\t\tsignal.throwIfAborted();\n\n\t\tif (!lines.length || !resultMessage) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tresponse: lines.join('\\n'),\n\t\t\tinputTokens: resultMessage.usage.input_tokens,\n\t\t\toutputTokens: resultMessage.usage.output_tokens,\n\t\t\tduration: resultMessage.duration_ms / 1000,\n\t\t};\n\t}\n\n\tprivate handleSystemMessage(message: SDKSystemMessage): void {\n\t\tswitch (message.subtype) {\n\t\t\t// Failures the SDK handled without failing the turn: only a warning makes them visible.\n\t\t\tcase 'api_retry':\n\t\t\tcase 'model_refusal_fallback':\n\t\t\tcase 'model_refusal_no_fallback':\n\t\t\tcase 'permission_denied':\n\t\t\tcase 'mirror_error':\n\t\t\t\tthis.warn(message, 'Claude reported a failure without failing the turn');\n\t\t\t\treturn;\n\t\t\t// Known messages with nothing to narrate or report.\n\t\t\tcase 'init':\n\t\t\tcase 'compact_boundary':\n\t\t\tcase 'status':\n\t\t\tcase 'control_request_progress':\n\t\t\tcase 'local_command_output':\n\t\t\tcase 'hook_started':\n\t\t\tcase 'hook_progress':\n\t\t\tcase 'hook_response':\n\t\t\tcase 'plugin_install':\n\t\t\tcase 'task_notification':\n\t\t\tcase 'task_started':\n\t\t\tcase 'task_updated':\n\t\t\tcase 'task_progress':\n\t\t\tcase 'background_tasks_changed':\n\t\t\tcase 'thinking_tokens':\n\t\t\tcase 'session_state_changed':\n\t\t\tcase 'worker_shutting_down':\n\t\t\tcase 'commands_changed':\n\t\t\tcase 'notification':\n\t\t\tcase 'files_persisted':\n\t\t\tcase 'memory_recall':\n\t\t\tcase 'elicitation_complete':\n\t\t\tcase 'informational':\n\t\t\t\treturn;\n\t\t\tdefault: {\n\t\t\t\tconst unknownMessage: never = message;\n\t\t\t\tthis.warn(unknownMessage, 'Unknown Claude system message');\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate handleAssistantMessage(\n\t\tmessage: SDKAssistantMessage,\n\t\tpendingTools: Map<string, PendingTool>,\n\t\tcallback: Callback,\n\t): void {\n\t\tfor (const block of message.message.content) {\n\t\t\tswitch (block.type) {\n\t\t\t\tcase 'text':\n\t\t\t\t\temitProgress(callback, { type: 'agentMessage', message: block.text });\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'thinking':\n\t\t\t\t\temitProgress(callback, { type: 'reasoning', message: block.thinking });\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'tool_use':\n\t\t\t\tcase 'server_tool_use':\n\t\t\t\tcase 'mcp_tool_use': {\n\t\t\t\t\tconst input = asRecord(block.input);\n\t\t\t\t\tif (input) {\n\t\t\t\t\t\tpendingTools.set(block.id, {\n\t\t\t\t\t\t\tname: block.name === 'web_search' ? 'WebSearch' : block.name,\n\t\t\t\t\t\t\tinput,\n\t\t\t\t\t\t\t...('server_name' in block && typeof block.server_name === 'string'\n\t\t\t\t\t\t\t\t? { server: block.server_name }\n\t\t\t\t\t\t\t\t: parseMcpServer(block.name)),\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase 'web_search_tool_result':\n\t\t\t\tcase 'web_fetch_tool_result':\n\t\t\t\tcase 'advisor_tool_result':\n\t\t\t\tcase 'code_execution_tool_result':\n\t\t\t\tcase 'bash_code_execution_tool_result':\n\t\t\t\tcase 'text_editor_code_execution_tool_result':\n\t\t\t\tcase 'tool_search_tool_result':\n\t\t\t\tcase 'mcp_tool_result':\n\t\t\t\t\tthis.handleCompletedTool(block, pendingTools, callback);\n\t\t\t\t\tbreak;\n\t\t\t\t// Known blocks with nothing to narrate.\n\t\t\t\tcase 'redacted_thinking':\n\t\t\t\tcase 'container_upload':\n\t\t\t\tcase 'compaction':\n\t\t\t\tcase 'fallback':\n\t\t\t\t\tbreak;\n\t\t\t\tdefault: {\n\t\t\t\t\tconst unknownBlock: never = block;\n\t\t\t\t\tthis.warn(unknownBlock, 'Unknown Claude content block');\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate handleUserMessage(\n\t\tmessage: SDKUserMessage,\n\t\tpendingTools: Map<string, PendingTool>,\n\t\tcallback: Callback,\n\t): void {\n\t\tif (!Array.isArray(message.message.content)) return;\n\n\t\tfor (const block of message.message.content) {\n\t\t\tthis.handleCompletedTool(block, pendingTools, callback, message.tool_use_result);\n\t\t}\n\t}\n\n\tprivate handleCompletedTool(\n\t\tblock: unknown,\n\t\tpendingTools: Map<string, PendingTool>,\n\t\tcallback: Callback,\n\t\toutput?: unknown,\n\t): void {\n\t\tconst id = toolResultId(block);\n\t\tif (!id) return;\n\n\t\tconst tool = pendingTools.get(id);\n\t\tif (!tool) return;\n\n\t\tpendingTools.delete(id);\n\t\tconst result = toolResultBlock(block);\n\t\tif (!result) return;\n\n\t\tconst description = describeCompletedTool(tool, result, output ?? result.content);\n\t\tif (description) emitProgress(callback, description);\n\t}\n\n\tprivate warn(...args: unknown[]): void {\n\t\ttreatErrors(\n\t\t\t() => {\n\t\t\t\tthis.logger.warn(...args);\n\t\t\t},\n\t\t\tclassifyHostFailure,\n\t\t\t'Claude logger failed while reporting progress',\n\t\t);\n\t}\n}\n\nfunction parseMcpServer(name: string): { server: string } | undefined {\n\tif (!name.startsWith('mcp__')) return undefined;\n\n\tconst server = name.slice('mcp__'.length).split('__')[0];\n\treturn server ? { server } : undefined;\n}\n"]}
@@ -1,19 +1,18 @@
1
- import type { Codex, ModelReasoningEffort } from '@openai/codex-sdk';
2
1
  import { type Agent, type AgentResponse, type Callback } from '../../../../agent/domain/agent.ts';
3
2
  import type { ILogger } from '../../../../shared/domain/logger.ts';
4
- type Model = 'gpt-5.6-sol' | 'gpt-5.6-luna';
3
+ export declare const codexModels: readonly ["gpt-6-astra", "gpt-5.6-sol", "gpt-5.6-luna", "gpt-5.6-terra"];
4
+ export type CodexModel = (typeof codexModels)[number];
5
+ export declare const codexReasoningEfforts: readonly ["low", "medium", "high", "xhigh", "max", "ultra"];
6
+ export type CodexReasoningEffort = (typeof codexReasoningEfforts)[number];
5
7
  export declare class CodexAgent implements Agent {
6
8
  private thread;
7
9
  private logger;
8
- constructor({ sdk, model, logger, autoApprove, reasoningEffort, }: {
9
- sdk: Codex;
10
- model: Model;
11
- logger: ILogger;
10
+ constructor({ model, autoApprove, reasoningEffort, logger, }: {
11
+ model: string;
12
12
  autoApprove?: boolean;
13
- reasoningEffort?: ModelReasoningEffort;
13
+ reasoningEffort?: string;
14
+ logger: ILogger;
14
15
  });
15
16
  run(prompt: string, signal: AbortSignal, callback: Callback): Promise<AgentResponse | undefined>;
16
17
  private parseResponse;
17
18
  }
18
- export {};
19
- //# sourceMappingURL=codexAgent.d.ts.map