@anureo/adapter-claude 0.2.0 → 0.3.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 CHANGED
@@ -2,26 +2,35 @@
2
2
 
3
3
  Adapter connecting the Anureo SDK to the official [`@anthropic-ai/claude-agent-sdk`](https://www.npmjs.com/package/@anthropic-ai/claude-agent-sdk). It drives the Claude SDK's streaming `query()` interface and maps messages, permissions, tool use, and subagents onto the unified AHP session model.
4
4
 
5
- > Part of the [Anureo SDK workspace](../../README.md). Install with `npm install @anureo/adapter-claude`.
5
+ > Part of the [Anureo SDK workspace](../../../README.md). Install with `npm install @anureo/adapter-claude`.
6
6
 
7
7
  ## Usage
8
8
 
9
+ This example uses the revised workspace API described under [Capabilities](#capabilities).
10
+
9
11
  ```typescript
10
- import { createHarnessRuntime } from '@anureo/sdk'
12
+ import { createClient } from '@anureo/sdk'
11
13
  import { createClaudeAdapter } from '@anureo/adapter-claude'
12
14
 
13
- const runtime = createHarnessRuntime(createClaudeAdapter({
14
- // Claude must run under an isolated, explicit CLAUDE_CONFIG_DIR…
15
- stateDir: '/var/my-host/claude-state',
16
- // …or deliberately reuse the CLI's login/profile home:
17
- // defaultHome: true,
18
- }))
15
+ const client = await createClient({
16
+ adapter: createClaudeAdapter({
17
+ // Claude must run under an isolated, explicit CLAUDE_CONFIG_DIR…
18
+ stateDir: '/var/my-host/claude-state',
19
+ // …or deliberately reuse the CLI's login/profile home:
20
+ // defaultHome: true,
21
+ }),
22
+ identity: { adapterId: 'claude', runtimeConfigId: 'local' },
23
+ })
24
+ // Use client.sessions.create(...) and session.submit(...); dispose in finally.
19
25
  ```
20
26
 
21
27
  Initialization fails with `HARNESS_CONFIG_INVALID` unless one of `stateDir` (or `env.CLAUDE_CONFIG_DIR`), `defaultHome`, or an injected `queryFactory` is provided — accidental reuse of a user's default Claude home is never silent.
22
28
 
23
29
  ## Capabilities
24
30
 
31
+ The revised workspace API shown here differs from the published 0.2.0 API.
32
+ The adapter pins `@anthropic-ai/claude-agent-sdk` to 0.3.265.
33
+
25
34
  What the adapter can offer depends on the options it was constructed with:
26
35
 
27
36
  | Condition | Unlocks |
@@ -29,7 +38,78 @@ What the adapter can offer depends on the options it was constructed with:
29
38
  | A session store is present (`stateDir`, or injected `sessionStore`) | `session.resume`, fork (`before`/`through`), `revert: conversation`, `history` |
30
39
  | `enableFileCheckpointing: true` | `revert: files` (and `both` together with a store), backed by the SDK's checkpoint/rewind support |
31
40
 
32
- Always available: `turn.interrupt`, `approval` / `userInput` / `elicitation` interactions, nested subagent events, and MCP (stdio + http, with `form`/`url` elicitation). Steer and output schemas are not offered because the Claude SDK does not support them.
41
+ Revert requires no active execution or pending input. Those cases, and input,
42
+ configuration changes or another revert attempted during a revert, reject with
43
+ `SESSION_BUSY`. Finish or interrupt the current execution and await its terminal
44
+ result before reverting.
45
+
46
+ The revised workspace exposes native input delivery (`native` → `next`,
47
+ `afterTurn` → `later`) and **session-scoped** interrupt with pending-input receipts.
48
+ Exact-turn steer and interrupt are not declared. It also supports `approval` / `userInput` / `elicitation` interactions, nested subagent events, MCP (stdio + http, with `form`/`url` elicitation), and `turn.outputSchema`.
49
+
50
+ Validation covers two layers:
51
+
52
+ - Injected Query fixtures exercise native input priority mapping, multi-message
53
+ correlation, and session interrupt mapping, including pending-input receipts.
54
+ - Transport tests run the pinned official SDK against a simulated child executable
55
+ to check single-input correlation.
56
+
57
+ Validation of native input priority, multi-message correlation, and interruption
58
+ behavior with real Claude execution remains unconfirmed by these tests.
59
+
60
+ Additional guidance uses another `await session.submit({ input, delivery: 'native' })`.
61
+ It may join the same execution or reach a later one. Session input delivery is
62
+ distinct from atomic exact-turn steering. See the
63
+ [Claude example](../../../docs/native-harness-lifecycle.md#42-claude追加会话指导与精确-steer-分开).
64
+
65
+ ## Structured output
66
+
67
+ Pass a self-contained draft-07 JSON Schema with `type: 'object'` at its root:
68
+
69
+ ```typescript
70
+ const turn = await session.submit({
71
+ input: 'Return the number of matching files.',
72
+ outputSchema: {
73
+ type: 'object',
74
+ properties: { count: { type: 'integer', minimum: 0 } },
75
+ required: ['count'],
76
+ additionalProperties: false,
77
+ },
78
+ })
79
+ const result = await turn.result()
80
+ if (result.status === 'completed') {
81
+ const data = JSON.parse(result.text)
82
+ console.log(data.count)
83
+ }
84
+ ```
85
+
86
+ The adapter passes the schema to the official Agent SDK's `outputFormat` option.
87
+ The SDK handles tool use, output validation and correction attempts. The adapter
88
+ validates the returned `structured_output` with draft-07 AJV and publishes its
89
+ JSON serialization as the final `agentMessage` and `TurnResult.text`. Intermediate
90
+ prose remains commentary. `format` annotations are accepted without enforcement;
91
+ asynchronous schemas, external references and newer schema dialects are rejected
92
+ with `INVALID_PARAMS` before input dispatch.
93
+
94
+ The pinned SDK sets output format at Query initialization. Equal schemas (object
95
+ key order does not matter) reuse the existing Query, including native overlapping
96
+ input. Changing or omitting the schema closes and drains that Query, then starts
97
+ another with the same native session ID and the latest session configuration.
98
+ After an execution, the new Query resumes the saved conversation. This adds
99
+ process startup cost when switching formats. A switch requires no active execution,
100
+ pending inputs or configuration changes; otherwise it rejects with `SESSION_BUSY`,
101
+ including for `delivery: 'afterTurn'`. Omit `outputSchema` to return to ordinary text;
102
+ the previous schema is never implicitly inherited. Input and configuration changes
103
+ are also refused while a format switch is in progress.
104
+
105
+ Missing or invalid structured output fails the turn with
106
+ `CLAUDE_STRUCTURED_OUTPUT_MISSING` or `CLAUDE_STRUCTURED_OUTPUT_INVALID`.
107
+ Native correction-limit exhaustion maps to
108
+ `CLAUDE_STRUCTURED_OUTPUT_RETRIES_EXCEEDED`; interruption remains `interrupted`.
109
+ The adapter never resubmits the task to repair output or recover a failed switch.
110
+ When a session store is available, history also exposes saved structured-output
111
+ attachments linked to surviving `StructuredOutput` calls, including after resume
112
+ or fork. Reading these saved attachments does not rerun schema validation.
33
113
 
34
114
  ## Exports
35
115
 
@@ -47,6 +127,17 @@ Resume, fork, and history need the official `SessionStore` contract. `FileSessio
47
127
 
48
128
  `createClaudeCatalogSession(options)` opens a prompt-less connection to list supported models (including effort levels per model) without creating a product session; `adapter.listModels(cwd)` is the one-shot variant.
49
129
 
130
+ ## Code structure
131
+
132
+ | Path | Responsibility |
133
+ |---|---|
134
+ | [`src/index.ts`](src/index.ts) | Assembles the application factories, adapter types, store and catalog exports. |
135
+ | [`src/adapter.ts`](src/adapter.ts) | Implements the native adapter and its backend sessions, including input, events and query lifecycle. `ClaudeBackendSession` remains exported for compatibility; the adapter constructs it. |
136
+ | [`src/options.ts`](src/options.ts) | Defines host launch options and query-factory extension contracts shared with catalog discovery. Hosts supply these contracts; adapter and catalog operations invoke the factories and close their queries. |
137
+ | [`src/catalog.ts`](src/catalog.ts) | Owns reusable prompt-less discovery queries and cancellation, sharing adapter launch options through `queryOptions()`. |
138
+ | [`src/store.ts`](src/store.ts) | Implements the public opaque session store used for resume, fork and history. |
139
+ | [`src/file-changes.ts`](src/file-changes.ts), [`src/output-schema.ts`](src/output-schema.ts), [`src/turn-error.ts`](src/turn-error.ts) | Project native file changes, validate structured output and classify terminal failures. |
140
+
50
141
  ## Configuration options
51
142
 
52
143
  Session-scoped config options exposed through AHP: `model`, `permissionMode` (`default` / `acceptEdits` / `bypassPermissions` / `plan` / `dontAsk` / `auto`), `effort` (`low`–`max`, per-model support reported by the catalog), `fastMode`, and `maxThinkingTokens`. Text and image inputs are supported.
@@ -56,12 +147,16 @@ For script-based Claude executables, `executableRuntime: 'node' | 'bun' | 'deno'
56
147
  ## Development
57
148
 
58
149
  ```sh
59
- cd packages/claude
150
+ cd packages/adapter/claude
60
151
  bun run typecheck
61
152
  bun test src
62
153
  ```
63
154
 
64
155
  ## Documentation
65
156
 
66
- - [Architecture](../../docs/architecture.md) — adapters' role in the SDK (currently in Chinese)
67
- - [AHP v1 protocol](../../spec/ahp-v1.md)
157
+ - [Architecture](../../../docs/architecture.md) — adapters' role in the SDK (currently in Chinese)
158
+ - [AHP v1 protocol](../../../spec/ahp-v1.md)
159
+
160
+ ## AHP v1 lifecycle revision
161
+
162
+ See the [design and implementation plan](../../../docs/native-harness-lifecycle.md).
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@anureo/adapter-claude",
3
- "version": "0.2.0",
4
3
  "description": "Anureo SDK adapter for the official Claude Agent SDK",
4
+ "version": "0.3.0",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
7
7
  "anureo",
@@ -15,7 +15,7 @@
15
15
  "repository": {
16
16
  "type": "git",
17
17
  "url": "git+https://github.com/hi-youichi/anureo-sdk.git",
18
- "directory": "packages/claude"
18
+ "directory": "packages/adapter/claude"
19
19
  },
20
20
  "bugs": {
21
21
  "url": "https://github.com/hi-youichi/anureo-sdk/issues"
@@ -26,35 +26,35 @@
26
26
  "type": "module",
27
27
  "exports": {
28
28
  ".": {
29
- "types": "./dist/index.d.ts",
30
- "import": "./dist/index.js",
31
- "default": "./dist/index.js"
29
+ "types": "./src/index.d.ts",
30
+ "import": "./src/index.js",
31
+ "default": "./src/index.js"
32
32
  },
33
33
  "./store": {
34
- "types": "./dist/store.d.ts",
35
- "import": "./dist/store.js",
36
- "default": "./dist/store.js"
34
+ "types": "./src/store.d.ts",
35
+ "import": "./src/store.js",
36
+ "default": "./src/store.js"
37
37
  },
38
38
  "./catalog": {
39
- "types": "./dist/catalog.d.ts",
40
- "import": "./dist/catalog.js",
41
- "default": "./dist/catalog.js"
39
+ "types": "./src/catalog.d.ts",
40
+ "import": "./src/catalog.js",
41
+ "default": "./src/catalog.js"
42
42
  }
43
43
  },
44
- "files": [
45
- "dist",
46
- "schema",
47
- "protocol",
48
- "examples",
49
- "README.md",
50
- "LICENSE"
51
- ],
52
44
  "dependencies": {
53
- "@anureo/protocol": "0.2.0",
54
- "@anureo/sdk": "0.2.0",
55
- "@anthropic-ai/claude-agent-sdk": "0.3.257"
45
+ "@anthropic-ai/claude-agent-sdk": "0.3.265",
46
+ "@anureo/protocol": "0.3.0",
47
+ "@anureo/sdk": "0.3.0",
48
+ "ajv": "8.20.0"
56
49
  },
57
50
  "engines": {
58
51
  "node": ">=22"
59
- }
52
+ },
53
+ "files": [
54
+ "src",
55
+ "bin",
56
+ "schema",
57
+ "protocol",
58
+ "examples"
59
+ ]
60
60
  }
@@ -0,0 +1,253 @@
1
+ import type { ClaudeAdapterOptions } from "./options.js";
2
+ import { type Options, type Query, type SessionStore } from "@anthropic-ai/claude-agent-sdk";
3
+ import { type BackendSession, type HarnessAdapter, type SessionEventSink, type SessionMethod } from "@anureo/sdk";
4
+ import { type Capabilities, type AhpRequestMap, type AhpResultMap, type InitializeParams, type InitializeResult, type SessionBinding, type SessionOpenParams } from "@anureo/protocol";
5
+ import { FileSessionStore } from "./store.js";
6
+ /** Connect a client to Claude queries and retain ownership of opened backend sessions.
7
+ * createClient initializes and disposes this adapter through its output wrapper; direct consumers
8
+ * initialize before opening sessions and await disposal when finished. */
9
+ export declare class ClaudeNativeAdapter implements HarnessAdapter {
10
+ /** Select the launch environment and store without starting Claude. stateDir takes precedence
11
+ * for adapter storage. With defaultHome enabled, an explicitly supplied CLAUDE_CONFIG_DIR is
12
+ * forwarded as supplied. */
13
+ constructor(options?: ClaudeAdapterOptions);
14
+ /** Report store/checkpoint-dependent support without native discovery or resource acquisition. */
15
+ get capabilities(): Capabilities;
16
+ /** Negotiate protocol support for Client.initialize through withStructuredOutput. Reject invalid
17
+ * negotiation, a disposed adapter, or an absent Claude home unless defaultHome or a query
18
+ * factory is supplied. Native launch is deferred to discovery or a session open. */
19
+ initialize(params: InitializeParams): Promise<InitializeResult>;
20
+ /** Open and retain a backend for OutputSession.open to attach. Await resume/fork setup, query
21
+ * construction and any resumed-title refresh. Native handshake and execution events arrive
22
+ * independently through the sink. Setup errors reject the open. The client disposes the backend
23
+ * it attaches, and adapter disposal also releases retained sessions. */
24
+ openSession(params: SessionOpenParams, sink: SessionEventSink): Promise<BackendSession>;
25
+ /** Read model metadata with a one-shot query using cwd, which defaults to process.cwd().
26
+ * The adapter supplies an empty input stream and closes the query after discovery. Startup,
27
+ * discovery and close failures reject, with a close failure taking precedence over discovery. */
28
+ listModels(cwd?: string): Promise<Awaited<ReturnType<Query["supportedModels"]>>>;
29
+ /** Build native launch options for internal use without starting a query. listModels uses them
30
+ * directly. ClaudeBackendSession.sessionQueryOptions and createClaudeCatalogSession's openConnection
31
+ * add their own options. The operation that starts the query owns its cleanup. */
32
+ queryOptions(cwd: string): Options;
33
+ /** Release retained sessions. Await all attempts and reject with the first cleanup failure in
34
+ * registry order. Once disposal starts, subsequent calls resolve independently of that cleanup. */
35
+ dispose(): Promise<void>;
36
+ /** Retained launch/extension configuration used by later queries; avoid mutating it during work. */
37
+ readonly options: ClaudeAdapterOptions;
38
+ /** Selected native store, shared with sessions; an injected store keeps its host-owned lifecycle. */
39
+ readonly sessionStore?: SessionStore;
40
+ /** Native launch environment; may contain credentials and is not a safe diagnostic projection. */
41
+ readonly env: Record<string, string | undefined>;
42
+ private readonly sessions;
43
+ /** Internal map from native session ID to the input UUIDs verified against SDK turns.
44
+ * Backend sessions reuse it across in-memory resume and copy it for forks. */
45
+ readonly turnMaps: Map<string, Record<string, string>>;
46
+ private readonly defaultStore?;
47
+ private disposed;
48
+ }
49
+ /** Adapter-internal BackendSession implementation retained in the root export for compatibility.
50
+ * ClaudeNativeAdapter.openSession constructs and opens it; OutputSession.execute forwards SDK
51
+ * requests and OutputSession.dispose awaits its cleanup on behalf of the client.
52
+ * Native receipt, execution association and terminal completion remain separate observations. */
53
+ export declare class ClaudeBackendSession implements BackendSession {
54
+ private readonly adapter;
55
+ private readonly params;
56
+ private readonly sink;
57
+ private readonly fileStore?;
58
+ /** Prepare binding/configuration for ClaudeNativeAdapter.openSession without starting a query.
59
+ * Reject unsupported config keys or invalid values before native open. */
60
+ constructor(adapter: ClaudeNativeAdapter, params: SessionOpenParams, sink: SessionEventSink, fileStore?: FileSessionStore | undefined);
61
+ /** Resolve resume/fork state and start a query for ClaudeNativeAdapter.openSession. Store,
62
+ * boundary and query-setup failures reject before the adapter registers the backend. */
63
+ open(): Promise<void>;
64
+ /** Dispatch requests forwarded by OutputSession.execute. Submission returns after enqueueing
65
+ * native input. Association and terminal results arrive through the sink. Busy or unsupported
66
+ * operations and native failures reject. Close awaits query cleanup with execution stop unconfirmed. */
67
+ execute<M extends SessionMethod>(method: M, params: AhpRequestMap[M]): Promise<AhpResultMap[M]>;
68
+ /** Share query close/return completion between the close request and OutputSession.dispose.
69
+ * Stop input admission, clear pending associations and invalidate message observation immediately.
70
+ * Cleanup rejects on release failure and leaves native execution stop unconfirmed. */
71
+ dispose(): Promise<void>;
72
+ /** Current native session identity, updated by fork/revert and native initialization. */
73
+ binding: SessionBinding;
74
+ /** Store/checkpoint capability projection captured from the adapter at construction. */
75
+ readonly capabilities: Capabilities;
76
+ /** Enforce execute's query admission policy for operations other than history and close. */
77
+ private requireQuery;
78
+ /** Apply execute's configuration controls in order and publish state after all controls succeed.
79
+ * Earlier native effects, including model changes, survive a rejected patch. Keep output-format
80
+ * replacement blocked until the patch settles. Session.onRequestFailed enters recovery when
81
+ * the returned SDK error carries an unknown outcome. */
82
+ private setConfig;
83
+ private release?;
84
+ private readonly nativeInputs;
85
+ private query?;
86
+ private pumping?;
87
+ private readonly queryReleases;
88
+ private outputSchema?;
89
+ private switchingOutput;
90
+ private queryMode;
91
+ private queryResumeAt?;
92
+ private queryFailure?;
93
+ private configOperations;
94
+ private input?;
95
+ private active?;
96
+ private generation;
97
+ private closed;
98
+ private reverting;
99
+ private config;
100
+ private capabilityRevision;
101
+ private model?;
102
+ private turns;
103
+ private historySnapshots;
104
+ /** Native fast-mode outcome as the CLI reports it (the setting may be on but not in effect). */
105
+ private fastMode?;
106
+ private storeKeys;
107
+ private sessionTitle?;
108
+ private metadataTail;
109
+ private metadataPending?;
110
+ /** Wrap startQuery's store so successful main-session appends schedule title refreshes.
111
+ * Forward store failures unchanged and ignore appends from replaced queries; metadata refresh runs
112
+ * independently so title reads cannot reject a committed append. Store lifecycle stays host-owned. */
113
+ private observedStore;
114
+ /** Coalesce title reads for observedStore, startQuery and completeTurn. startQuery awaits the
115
+ * refresh on resume, while append and terminal publication proceed independently. Ignore stale
116
+ * reads after replacement or close and report read failures with a best-effort warning. */
117
+ private refreshMetadata;
118
+ private get nativeId();
119
+ /** Let open choose a fresh query for an empty fork. A history read failure rejects open. */
120
+ private hasHistory;
121
+ /** Copy the source transcript through a verified cutoff for open or restoreConversation.
122
+ * The caller installs the returned session ID. Native copy failures reject that phase. */
123
+ private forkTranscript;
124
+ /** Open, association, init and conversation restore update the in-memory map before awaiting
125
+ * its optional disk copy. Save failure rejects the caller without undoing the map update. */
126
+ private rememberTurnMap;
127
+ /** Accept native init/result fast-mode states and report whether the public snapshot changed. */
128
+ private trackFastMode;
129
+ /** Clone binding and config for state publications during initialization, configuration,
130
+ * completion and conversation restore. Report running while an execution occupies the active slot. */
131
+ private snapshot;
132
+ /** Construct a generation-specific query for open, restoreConversation or replaceOutputFormat,
133
+ * then start background pumping and await resumed-title refresh. Fresh mode opens the current native
134
+ * ID as a new session; resume mode reopens its transcript, optionally at resumeAt. Factory/setup
135
+ * failures reject here; subsequent source failures are reported to the sink by pump. */
136
+ private startQuery;
137
+ /** Project the session and generation into launch options for startQuery. Native tool callbacks
138
+ * are invoked by the SDK. The observed store schedules title refreshes only for this generation. */
139
+ private sessionQueryOptions;
140
+ /** Consume the query started by startQuery until closure/generation replacement. Fail SDK
141
+ * observation on source errors or early EOF with pending work; never replay native input. */
142
+ private pump;
143
+ /** Return the active execution to associateInputs. Allocate and publish it on the first native
144
+ * execution evidence from associateInputs or permissionRequest. Starting work also makes later
145
+ * schema replacements resume the native transcript. Publication failure rejects to the caller. */
146
+ private beginExecution;
147
+ /** Route pump messages after processing native input refusal or association evidence. Bind
148
+ * inputs before projecting the associated reply. Sink and store failures reject back to pump. */
149
+ private mapMessage;
150
+ /** Complete live tool calls from matching native user-message results. mapMessage awaits
151
+ * publication to keep these effects ordered before later native messages. */
152
+ private publishToolResults;
153
+ /** Map native task updates to an item's start, patch or terminal event. mapMessage awaits
154
+ * publication, falling back to a notice when the native task identity is missing. */
155
+ private publishTask;
156
+ /** Give hook progress a start event when the hook was previously unseen. mapMessage awaits
157
+ * publication before consuming another message, including when a missing hook ID emits a notice. */
158
+ private publishHook;
159
+ /** Publish mapMessage's native refusal/no-execution evidence before removing a pending input.
160
+ * Unknown UUIDs are ignored; publication failure leaves the input retained and rejects into pump. */
161
+ private rejectInput;
162
+ /** Bind mapMessage's echoed UUIDs to the current execution and persist the verified map.
163
+ * Native evidence can add inputs to an existing execution, but cannot move a bound input to a
164
+ * different execution. Binding or store failures reject and are reported by pump. */
165
+ private associateInputs;
166
+ /** Finish mapMessage's captured execution. Validate final output, publish items and usage, then
167
+ * clear consumed input IDs before the terminal and ready-state events. Uncorrelated inputs stay
168
+ * pending. A sink failure rejects into pump. */
169
+ private completeTurn;
170
+ /** Classify native termination and validate structured output before completeTurn publishes
171
+ * any final item. Missing or invalid output becomes a terminal error. An interruption bypasses
172
+ * schema validation and retains precedence in the terminal event. */
173
+ private terminalOutput;
174
+ /** Update the active turn from streamed content, publishing starts/deltas before final blocks.
175
+ * mapMessage calls only with an active turn; sink rejection propagates to the query pump. */
176
+ private streamEvent;
177
+ /** Project a live/history content block to a public item, preserving unknown native content safely. */
178
+ private blockItem;
179
+ /** Reconcile completeBlock with unfinished text/thinking streams before allocating a fallback ID.
180
+ * Mutates the turn's fallback counter only when no native or unfinished-stream identity exists. */
181
+ private resolveCompleteBlockId;
182
+ /** Merge a complete assistant block into active output and publish its start/patch/completion.
183
+ * Text and tool calls stay pending until native result/tool evidence; sink failures reach pump. */
184
+ private completeBlock;
185
+ /** Publish otherwise unmapped native messages through the sink with privacy-safe raw content. */
186
+ private notice;
187
+ /** Native canUseTool callback supplied by sessionQueryOptions. Await SDK approval/user answers or
188
+ * native cancellation, translating unavailable interactions to denial and removing the abort listener.
189
+ * Session and InteractionRegistry invoke the registered responder for answers or cancellation.
190
+ * Execution-start publication failures reject this native callback before interaction registration. */
191
+ private permissionRequest;
192
+ /** Build stable qN question identities for permissionRequest so answers map back to native text. */
193
+ private createUserQuestionRequest;
194
+ /** Offer session approval to permissionRequest only when the native callback supplied a
195
+ * session-scoped permission update it can return. */
196
+ private createToolApprovalRequest;
197
+ /** Native onElicitation callback supplied by sessionQueryOptions. Await a sink-delivered answer
198
+ * or native abort. The answer can reach Claude before the sink publishes interaction/resolved.
199
+ * Unrepresentable form content rejects responder delivery. Native abort or a rejected sink wait
200
+ * returns cancellation. */
201
+ private elicitationRequest;
202
+ /** Register the responder for permissionRequest and elicitationRequest. Resolve the native
203
+ * wait once and remove its abort listener. Native abort reports expiry to the sink without
204
+ * awaiting publication. A rejected sink wait supplies the operation's fallback response. */
205
+ private awaitInteraction;
206
+ /** Read native history for boundary/history callers through the supplied public store. Capture
207
+ * the SDK-derived store key for opaque attachment reads; reject absent stores and read failures. */
208
+ private messages;
209
+ /** Resolve the checkpoint and transcript cutoff for open and revert. Without a store, use
210
+ * native prompt IDs or known associations for file checkpoints. With a store, verify the prompt
211
+ * in history and include opaque trailing entries for through boundaries when available.
212
+ * Unknown boundaries and store failures reject the caller. */
213
+ private boundaryPoint;
214
+ /** Restore execute's requested file/conversation scope only while idle. Drain the old query
215
+ * before replacement. Hold admission across lookup and cleanup, releasing it on any outcome.
216
+ * Failed conversation restoration after file rewind rejects with REVERT_PARTIAL and appliedScope. */
217
+ private revert;
218
+ /** Revert's file phase verifies a checkpoint with a dry run before applying it. Recheck close
219
+ * after preview; a failed/partial native rewind rejects without attempting conversation restore. */
220
+ private restoreFiles;
221
+ /** Revert's conversation phase forks at the verified cutoff, drains the old query, then publishes
222
+ * the replacement binding/state. Recheck close after native waits so disposal cannot reopen work;
223
+ * revert translates failure to a REVERT_PARTIAL rejection when its file phase already applied. */
224
+ private restoreConversation;
225
+ /** Admit execute's bounded input and enqueue native content, returning a dispatch receipt.
226
+ * Changed schemas replace an idle query first; rejection never retries or replays the new input. */
227
+ private submitInput;
228
+ /** Drain and replace the query for submitInput before enqueueing its input. Reject startup or
229
+ * cleanup failure as a definite dispatch failure and latch it for later query operations while open. */
230
+ private replaceOutputFormat;
231
+ /** Invalidate the retired query's observation and end its input before release. Conversation
232
+ * restore and output replacement each await close/return and their own pump before reopening. */
233
+ private endQueryInput;
234
+ /** Share query close/return completion across replacement, revert and disposal. Attempt both
235
+ * stages and reject RESOURCE_RELEASE_FAILED with safe codes when either fails. */
236
+ private releaseQuery;
237
+ /** Build/reuse one of eight retained history snapshots for execute, then clone the requested page.
238
+ * A new snapshot projects native entries before loading structured-output attachments. Reject expired
239
+ * snapshots, invalid offsets or store failures; pagination reuses the snapshot without rereading it. */
240
+ private readHistory;
241
+ /** Reconstruct readHistory's live-compatible item IDs and tool results from ordered native entries.
242
+ * Keep grouping and per-API-message block counters local to this snapshot; tool results amend only
243
+ * an earlier call in the same turn, and unmatched results remain visible as unknown content. */
244
+ private projectHistory;
245
+ /** Add saved structured-output attachments only for tool calls surviving readHistory's transcript.
246
+ * Read the captured public-store key; missing keys leave history unchanged and load failures reject. */
247
+ private structuredHistory;
248
+ }
249
+ /** Construct the adapter supplied to createClient without opening Claude. The client initializes
250
+ * and disposes it through its output wrapper; direct adapter consumers initialize before session opens
251
+ * and await disposal after use. Options and injected store lifecycle remain host-owned. */
252
+ export declare function createClaudeAdapter(options?: ClaudeAdapterOptions): ClaudeNativeAdapter;
253
+ export { FileSessionStore } from "./store.js";