@coralai/claude-code-agent 0.1.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 +111 -0
- package/dist/agent.d.ts +240 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +592 -0
- package/dist/agent.js.map +1 -0
- package/dist/errors.d.ts +27 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +33 -0
- package/dist/errors.js.map +1 -0
- package/dist/hooks/fs.d.ts +26 -0
- package/dist/hooks/fs.d.ts.map +1 -0
- package/dist/hooks/fs.js +61 -0
- package/dist/hooks/fs.js.map +1 -0
- package/dist/hooks/index.d.ts +18 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/permissions.d.ts +42 -0
- package/dist/hooks/permissions.d.ts.map +1 -0
- package/dist/hooks/permissions.js +79 -0
- package/dist/hooks/permissions.js.map +1 -0
- package/dist/hooks/terminal.d.ts +56 -0
- package/dist/hooks/terminal.d.ts.map +1 -0
- package/dist/hooks/terminal.js +127 -0
- package/dist/hooks/terminal.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/acp-client-interface.d.ts +107 -0
- package/dist/internal/acp-client-interface.d.ts.map +1 -0
- package/dist/internal/acp-client-interface.js +17 -0
- package/dist/internal/acp-client-interface.js.map +1 -0
- package/dist/internal/acp-types.d.ts +64 -0
- package/dist/internal/acp-types.d.ts.map +1 -0
- package/dist/internal/acp-types.js +17 -0
- package/dist/internal/acp-types.js.map +1 -0
- package/dist/internal/agent-runtime-interface.d.ts +40 -0
- package/dist/internal/agent-runtime-interface.d.ts.map +1 -0
- package/dist/internal/agent-runtime-interface.js +17 -0
- package/dist/internal/agent-runtime-interface.js.map +1 -0
- package/dist/internal/local-acp-client.d.ts +27 -0
- package/dist/internal/local-acp-client.d.ts.map +1 -0
- package/dist/internal/local-acp-client.js +26 -0
- package/dist/internal/local-acp-client.js.map +1 -0
- package/dist/internal/sdk-adapter.d.ts +24 -0
- package/dist/internal/sdk-adapter.d.ts.map +1 -0
- package/dist/internal/sdk-adapter.js +453 -0
- package/dist/internal/sdk-adapter.js.map +1 -0
- package/dist/internal/session-accumulator.d.ts +55 -0
- package/dist/internal/session-accumulator.d.ts.map +1 -0
- package/dist/internal/session-accumulator.js +133 -0
- package/dist/internal/session-accumulator.js.map +1 -0
- package/dist/prompt-handle.d.ts +70 -0
- package/dist/prompt-handle.d.ts.map +1 -0
- package/dist/prompt-handle.js +137 -0
- package/dist/prompt-handle.js.map +1 -0
- package/dist/recording/index.d.ts +10 -0
- package/dist/recording/index.d.ts.map +1 -0
- package/dist/recording/index.js +10 -0
- package/dist/recording/index.js.map +1 -0
- package/dist/recording/replayer.d.ts +17 -0
- package/dist/recording/replayer.d.ts.map +1 -0
- package/dist/recording/replayer.js +68 -0
- package/dist/recording/replayer.js.map +1 -0
- package/dist/recording/writer.d.ts +32 -0
- package/dist/recording/writer.d.ts.map +1 -0
- package/dist/recording/writer.js +122 -0
- package/dist/recording/writer.js.map +1 -0
- package/dist/telemetry/index.d.ts +8 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +8 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/telemetry/otel-adapter.d.ts +105 -0
- package/dist/telemetry/otel-adapter.d.ts.map +1 -0
- package/dist/telemetry/otel-adapter.js +153 -0
- package/dist/telemetry/otel-adapter.js.map +1 -0
- package/package.json +45 -0
package/README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# @coralai/claude-code-agent
|
|
2
|
+
|
|
3
|
+
> **Status**: v0.1.0-alpha.0 (skeleton, Phase 1 Step 1.2 of extraction plan)
|
|
4
|
+
> **Full API spec**: `/home/coral/projects/claude-code-agent/README.md` (vision doc)
|
|
5
|
+
> **CEO plan**: `~/.gstack/projects/claude-code-agent/ceo-plans/2026-05-14-acp-runtime-v1.md`
|
|
6
|
+
|
|
7
|
+
Lean runtime primitive for embedding ACP-compatible agents (Claude Code) in Node.js apps.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { ClaudeCodeAgent } from '@coralai/claude-code-agent';
|
|
11
|
+
|
|
12
|
+
const agent = new ClaudeCodeAgent({ cwd: '/path/to/project' });
|
|
13
|
+
await agent.start();
|
|
14
|
+
const handle = agent.prompt('Reply with OK');
|
|
15
|
+
const result = await handle.result;
|
|
16
|
+
console.log(result.text); // "OK"
|
|
17
|
+
await agent.stop();
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## 📅 Status
|
|
23
|
+
|
|
24
|
+
| Item | Status |
|
|
25
|
+
|---|---|
|
|
26
|
+
| Package skeleton | ✅ Step 1.2 done |
|
|
27
|
+
| Code extraction from sps-cli | ⏳ Step 1.3 |
|
|
28
|
+
| New API implementation | ⏳ Step 1.4 (PromptHandle / fork / promptJson / recording / OTel / elicitation hook) |
|
|
29
|
+
| sps-cli use this package | ⏳ Step 1.5 |
|
|
30
|
+
| Regression gates | ⏳ Step 1.6 |
|
|
31
|
+
| First publish to npm | ⏳ Step 1.7 (as v0.1.0) |
|
|
32
|
+
|
|
33
|
+
**Do not import this package yet** — `src/` is intentionally empty until Step 1.4.
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Module layout (per CEO plan D2 decision)
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
src/
|
|
41
|
+
index.ts ← public API barrel
|
|
42
|
+
agent.ts ← ClaudeCodeAgent main class (~300 lines target)
|
|
43
|
+
prompt-handle.ts ← PromptHandle + queue logic (~200 lines)
|
|
44
|
+
hooks/ ← default fs / terminal / permission / elicitation impls (~250)
|
|
45
|
+
recording/ ← session jsonl writer + replayer (~250)
|
|
46
|
+
telemetry/ ← OpenTelemetry adapter (~150)
|
|
47
|
+
errors.ts ← AgentError + 18 codes (~50)
|
|
48
|
+
internal/ ← capability negotiation + state machine + transport wiring (~150)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Target total: **~1000-1300 lines** of TypeScript.
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Hard prerequisites (runtime)
|
|
56
|
+
|
|
57
|
+
For consumers once v0.1.0 ships:
|
|
58
|
+
|
|
59
|
+
| Dependency | Install |
|
|
60
|
+
|---|---|
|
|
61
|
+
| Node.js ≥ 18 | (ESM-only) |
|
|
62
|
+
| `claude` CLI binary | `curl -fsSL https://claude.ai/install.sh \| bash` |
|
|
63
|
+
| `claude-agent-acp` shim | `npm install -g @agentclientprotocol/claude-agent-acp@^0.33` |
|
|
64
|
+
| Anthropic auth | `claude` reads `$ANTHROPIC_API_KEY` or `~/.claude/.credentials.json`; this package does not manage auth |
|
|
65
|
+
|
|
66
|
+
⚠️ **Production embedding**: must explicitly set `permissionMode: 'readonly'` or `'manual'`; default `'auto'` is dev-only.
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Decisions in effect (from review pipeline)
|
|
71
|
+
|
|
72
|
+
| Decision | Source |
|
|
73
|
+
|---|---|
|
|
74
|
+
| Package name stays `@coralai/claude-code-agent` for v1 (no rename to `acp-runtime`) | codex outside voice + CEO reversal 1 |
|
|
75
|
+
| `prompt()` returns `PromptHandle`, not `Promise<PromptResult>` | codex finding #4/#5 + Eng D1 |
|
|
76
|
+
| `PromptHandle.updates` is **broadcast** (buffer-all, multi-consumer) | Eng D1 |
|
|
77
|
+
| `fork()` no-args (forks current session) | codex finding #7 |
|
|
78
|
+
| `warmup()` removed → `start({ eager: true })` | codex finding #6 |
|
|
79
|
+
| 6-module layout (this README §Module layout) | Eng D2 |
|
|
80
|
+
| Recording fixtures: manual generation + nightly live verify | Eng D3 |
|
|
81
|
+
| Recording write: async batch (100ms / 64KB flush) | Eng D4 |
|
|
82
|
+
| OTel attribute: truncate @ 8KB + `truncated: true` flag | Eng D4 |
|
|
83
|
+
| `onElicitation` hook reserved but dormant (shim 0.33.1 doesn't fire) | Elicitation spike 2026-05-14 |
|
|
84
|
+
| Hook signature uses SDK native `schema.CreateElicitationRequest/Response` | spike |
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Why this package exists
|
|
89
|
+
|
|
90
|
+
sps-cli currently embeds ~5000 lines of ACP/session/worker management code directly. This package extracts that into a reusable primitive:
|
|
91
|
+
|
|
92
|
+
- 90% of code reuse from sps-cli's `providers/` + `manager/` + relevant `core/`
|
|
93
|
+
- Captures spawn race / orphan recovery / marker file lessons learned the hard way
|
|
94
|
+
- Forward-compatible with codex/gemini ACP agents (v1.1 expansion)
|
|
95
|
+
- Forward-compatible with elicitation (when shim wires it up)
|
|
96
|
+
|
|
97
|
+
After v1, sps-cli depends on this package instead of carrying its own ACP implementation.
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## Links
|
|
102
|
+
|
|
103
|
+
- Full vision doc (851 lines, all decisions): `/home/coral/projects/claude-code-agent/README.md`
|
|
104
|
+
- CEO plan with cross-model reversals: `~/.gstack/projects/claude-code-agent/ceo-plans/2026-05-14-acp-runtime-v1.md`
|
|
105
|
+
- Test plan: `~/.gstack/projects/claude-code-agent/coral-main-eng-review-test-plan-*.md`
|
|
106
|
+
- Elicitation spike data: `~/.gstack/projects/claude-code-agent/elicitation-spike-results-*.json`
|
|
107
|
+
- Spike code: `/home/coral/projects/claude-code-agent/spike/spike.ts`
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
*v0.1.0-alpha.0 · skeleton · 2026-05-14*
|
package/dist/agent.d.ts
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import type * as schema from '@agentclientprotocol/sdk';
|
|
2
|
+
import { AgentError } from './errors.js';
|
|
3
|
+
import { type PromptHandle } from './prompt-handle.js';
|
|
4
|
+
import { type AgentRegistryEntry } from './internal/sdk-adapter.js';
|
|
5
|
+
import { type Tracer } from './telemetry/otel-adapter.js';
|
|
6
|
+
export type { Tracer } from './telemetry/otel-adapter.js';
|
|
7
|
+
/** Lifecycle states. See §5 state machine diagram in vision doc. */
|
|
8
|
+
export type AgentStatus = 'idle' | 'starting' | 'warming' | 'ready' | 'busy' | 'resuming' | 'replaying' | 'stopping' | 'stopped' | 'error';
|
|
9
|
+
/** Public permission mode. Internal `hooks/permissions.PermissionMode` is
|
|
10
|
+
* different — mapped at construction. */
|
|
11
|
+
export type PermissionMode = 'auto' | 'readonly' | 'manual';
|
|
12
|
+
export interface PromptAttachment {
|
|
13
|
+
type: string;
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
}
|
|
16
|
+
export interface PromptOptions {
|
|
17
|
+
attachments?: PromptAttachment[];
|
|
18
|
+
timeoutMs?: number;
|
|
19
|
+
signal?: AbortSignal;
|
|
20
|
+
}
|
|
21
|
+
export interface PermissionRequest {
|
|
22
|
+
toolName: string;
|
|
23
|
+
toolInput: unknown;
|
|
24
|
+
rationale?: string;
|
|
25
|
+
}
|
|
26
|
+
export type PermissionDecision = 'allow' | 'allow_once' | 'deny' | 'cancel';
|
|
27
|
+
export interface UsageSummary {
|
|
28
|
+
inputTokens: number;
|
|
29
|
+
outputTokens: number;
|
|
30
|
+
cacheReadTokens?: number;
|
|
31
|
+
cacheWriteTokens?: number;
|
|
32
|
+
estimatedCostUsd?: number;
|
|
33
|
+
}
|
|
34
|
+
export interface RuntimeCheck {
|
|
35
|
+
claudeBinary: {
|
|
36
|
+
ok: boolean;
|
|
37
|
+
path?: string;
|
|
38
|
+
version?: string;
|
|
39
|
+
};
|
|
40
|
+
shim: {
|
|
41
|
+
ok: boolean;
|
|
42
|
+
path?: string;
|
|
43
|
+
version?: string;
|
|
44
|
+
mode: 'global' | 'npx';
|
|
45
|
+
};
|
|
46
|
+
auth: {
|
|
47
|
+
mode: 'env_api_key' | 'oauth_subscription' | 'none';
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/** Hook callbacks for runtime customization. All optional; defaults are
|
|
51
|
+
* filesystem/terminal helpers scoped to AgentOptions.cwd. */
|
|
52
|
+
export interface AgentHooks {
|
|
53
|
+
/** Stream of every SessionUpdate emitted for any turn. Use turnId to
|
|
54
|
+
* associate. Called synchronously before broadcasting to PromptHandle. */
|
|
55
|
+
onSessionUpdate?: (update: schema.SessionNotification['update'], turnId: string) => void;
|
|
56
|
+
/** Required when permissionMode = 'manual'. Returns user's decision for
|
|
57
|
+
* each tool permission request. */
|
|
58
|
+
onPermissionRequest?: (req: PermissionRequest) => Promise<PermissionDecision>;
|
|
59
|
+
/** Reserved for v1.x. claude-agent-acp 0.33.1 does not fire elicitation
|
|
60
|
+
* (spike 2026-05-14: disallowedTools includes AskUserQuestion).
|
|
61
|
+
* Hook signature uses SDK native types for forward compatibility. */
|
|
62
|
+
onElicitation?: (req: schema.CreateElicitationRequest) => Promise<schema.CreateElicitationResponse>;
|
|
63
|
+
/** Custom filesystem implementations. Defaults read/write inside cwd. */
|
|
64
|
+
fs?: {
|
|
65
|
+
readTextFile?: (path: string) => Promise<string>;
|
|
66
|
+
writeTextFile?: (path: string, content: string) => Promise<void>;
|
|
67
|
+
};
|
|
68
|
+
/** Custom terminal implementations. Defaults use child_process.spawn. */
|
|
69
|
+
terminal?: {
|
|
70
|
+
create?: (req: unknown) => Promise<unknown>;
|
|
71
|
+
output?: (handle: string) => Promise<string>;
|
|
72
|
+
waitExit?: (handle: string) => Promise<unknown>;
|
|
73
|
+
kill?: (handle: string) => Promise<void>;
|
|
74
|
+
release?: (handle: string) => Promise<void>;
|
|
75
|
+
};
|
|
76
|
+
/** Lifecycle: spawn succeeded, session ready. */
|
|
77
|
+
onStart?: (info: {
|
|
78
|
+
pid: number | undefined;
|
|
79
|
+
sessionId: string;
|
|
80
|
+
}) => void;
|
|
81
|
+
/** Lifecycle: agent stopped (clean or shim-died). */
|
|
82
|
+
onStop?: (info: {
|
|
83
|
+
code: number | null;
|
|
84
|
+
reason?: string;
|
|
85
|
+
}) => void;
|
|
86
|
+
/** Lifecycle: AgentError surfaced anywhere. */
|
|
87
|
+
onError?: (err: AgentError) => void;
|
|
88
|
+
}
|
|
89
|
+
/** Construction options. Only `cwd` is required. */
|
|
90
|
+
export interface AgentOptions {
|
|
91
|
+
/** Working directory. Determines which CLAUDE.md / .claude/ Claude reads. */
|
|
92
|
+
cwd: string;
|
|
93
|
+
/** Extra env passed to spawned shim (and through to claude binary). Do
|
|
94
|
+
* NOT set ANTHROPIC_API_KEY here unless you want API-key billing. */
|
|
95
|
+
env?: Record<string, string>;
|
|
96
|
+
/** Override the shim command. Default: resolved by loadAgentRegistry()
|
|
97
|
+
* (claude-agent-acp on PATH → direct; else npx fallback). */
|
|
98
|
+
agentCommand?: AgentRegistryEntry;
|
|
99
|
+
/** Default 'auto' (dev). Server embedding MUST set 'readonly' or 'manual'. */
|
|
100
|
+
permissionMode?: PermissionMode;
|
|
101
|
+
hooks?: AgentHooks;
|
|
102
|
+
/** Optional structured logger. Defaults to process.stderr for warn/error. */
|
|
103
|
+
logger?: (level: 'info' | 'warn' | 'error', msg: string) => void;
|
|
104
|
+
/** OTel Tracer (peer dep `@opentelemetry/api ≥1.7 <2`, optional). Pass
|
|
105
|
+
* `trace.getTracer('myapp')` to emit span hierarchy:
|
|
106
|
+
* agent.session → agent.prompt → agent.tool.call / permission / elicitation.
|
|
107
|
+
* Attributes follow OTel GenAI semantic conventions. Zero cost if unset. */
|
|
108
|
+
tracer?: Tracer;
|
|
109
|
+
/** jsonl recording path. Captures ACP frames + hook IO + turn boundaries.
|
|
110
|
+
* ⚠️ Contains raw prompts/responses/tool IO; treat as sensitive. */
|
|
111
|
+
recording?: string;
|
|
112
|
+
/** Queue policy when busy. Default 'auto' (use shim promptQueueing if
|
|
113
|
+
* capability present, else throw BUSY). */
|
|
114
|
+
queuePrompts?: 'auto' | 'never' | 'always';
|
|
115
|
+
spawnTimeoutMs?: number;
|
|
116
|
+
promptTimeoutMs?: number;
|
|
117
|
+
elicitationTimeoutMs?: number;
|
|
118
|
+
/** Max queued prompts. Default 32. Exceeding throws QUEUE_FULL. */
|
|
119
|
+
maxQueueLength?: number;
|
|
120
|
+
}
|
|
121
|
+
export declare class ClaudeCodeAgent {
|
|
122
|
+
private readonly options;
|
|
123
|
+
private _status;
|
|
124
|
+
private _sessionId;
|
|
125
|
+
private _pid;
|
|
126
|
+
private readonly _sessionName;
|
|
127
|
+
private _client;
|
|
128
|
+
private _startPromise;
|
|
129
|
+
private _stopPromise;
|
|
130
|
+
private _supportsPromptQueueing;
|
|
131
|
+
private _currentTurn;
|
|
132
|
+
private _recording;
|
|
133
|
+
private _spans;
|
|
134
|
+
private _cumUsage;
|
|
135
|
+
constructor(options: AgentOptions);
|
|
136
|
+
get status(): AgentStatus;
|
|
137
|
+
get sessionId(): string | undefined;
|
|
138
|
+
get pid(): number | undefined;
|
|
139
|
+
/** Whether the shim advertised promptQueueing capability at initialize.
|
|
140
|
+
* Read after start() completes successfully. Used by Step 1.4.4. */
|
|
141
|
+
get supportsPromptQueueing(): boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Spawn shim + ACP initialize + newSession. Idempotent: repeated calls
|
|
144
|
+
* return the same Promise. `eager: true` is a documentation signal that
|
|
145
|
+
* the caller wants the spawn to happen now (vs lazy "spawn on first
|
|
146
|
+
* prompt") — in v0.1, start() always spawns now, so the flag only
|
|
147
|
+
* controls the displayed status ('warming' vs 'starting').
|
|
148
|
+
*
|
|
149
|
+
* Throws AgentError with code SPAWN_FAILED / SPAWN_TIMEOUT / INIT_FAILED /
|
|
150
|
+
* SESSION_FAILED / AUTH_ERROR / PROTOCOL_ERROR depending on failure point.
|
|
151
|
+
*/
|
|
152
|
+
start(opts?: {
|
|
153
|
+
eager?: boolean;
|
|
154
|
+
}): Promise<void>;
|
|
155
|
+
private _doStart;
|
|
156
|
+
/**
|
|
157
|
+
* Close session (v0.20 stable closeSession) + drain in-flight prompts +
|
|
158
|
+
* kill shim. Idempotent. An agent that was never started transitions
|
|
159
|
+
* directly to 'stopped'.
|
|
160
|
+
*/
|
|
161
|
+
stop(): Promise<void>;
|
|
162
|
+
private _doStop;
|
|
163
|
+
/**
|
|
164
|
+
* Submit a prompt. Returns a PromptHandle whose `result` resolves with the
|
|
165
|
+
* aggregated PromptResult, and whose `updates` AsyncIterable broadcasts
|
|
166
|
+
* every SessionUpdate (D1 broadcast semantics).
|
|
167
|
+
*
|
|
168
|
+
* v0.1: single in-flight prompt per agent. Concurrent prompt() throws BUSY
|
|
169
|
+
* unless queuePrompts='always' (queue implementation lands in 1.4.4+).
|
|
170
|
+
* For v0.1.0-alpha we accept the simplest behavior: BUSY on overlap.
|
|
171
|
+
*/
|
|
172
|
+
prompt(text: string, opts?: PromptOptions): PromptHandle;
|
|
173
|
+
/**
|
|
174
|
+
* Cancel the in-flight prompt (and, when v1.x queueing lands, the queued
|
|
175
|
+
* prompts too). v0.1: same effect as `handle.cancel()` for the current
|
|
176
|
+
* turn. Safe to call when no turn is active (no-op).
|
|
177
|
+
*/
|
|
178
|
+
cancelAll(): Promise<void>;
|
|
179
|
+
/** Step 1.4.8 will implement fork via v0.20 session.fork + resumeSession. */
|
|
180
|
+
fork(): Promise<ClaudeCodeAgent>;
|
|
181
|
+
/**
|
|
182
|
+
* Structured output helper. Sends a prompt that asks Claude to return JSON
|
|
183
|
+
* matching the supplied zod schema. Parses + validates the result.
|
|
184
|
+
*
|
|
185
|
+
* v0.1: claude-only. Non-claude agents throw UNSUPPORTED_ON_AGENT (the
|
|
186
|
+
* agent registry doesn't expose JSON mode capability uniformly yet).
|
|
187
|
+
*
|
|
188
|
+
* The supplied schema must have a `.parse(input): T` method (zod-compatible
|
|
189
|
+
* structural interface — works with zod v3 + v4).
|
|
190
|
+
*/
|
|
191
|
+
promptJson<T>(text: string, schema: {
|
|
192
|
+
parse: (input: unknown) => T;
|
|
193
|
+
}, opts?: PromptOptions): Promise<T>;
|
|
194
|
+
/** Cumulative token + cost usage across all turns settled so far. */
|
|
195
|
+
usage(): UsageSummary;
|
|
196
|
+
/**
|
|
197
|
+
* Detect runtime prerequisites: local `claude` CLI binary, the
|
|
198
|
+
* `claude-agent-acp` shim, and the active auth mode.
|
|
199
|
+
* Step 1.4.8 ships best-effort detection; refined in v0.2 with
|
|
200
|
+
* shim version detection.
|
|
201
|
+
*/
|
|
202
|
+
static checkRuntime(): Promise<RuntimeCheck>;
|
|
203
|
+
/** Resume an existing session by id. Deferred to v1.1 — requires the
|
|
204
|
+
* AcpSdkAdapter to expose a `loadSession` method against the shim's
|
|
205
|
+
* v0.20 loadSession capability. */
|
|
206
|
+
static resumeSession(_sessionId: string, _options: AgentOptions): Promise<ClaudeCodeAgent>;
|
|
207
|
+
/** Replay a session from a recording file. Minimal v0.1 implementation
|
|
208
|
+
* reads the jsonl; full hook-divergence validation (REPLAY_MISMATCH)
|
|
209
|
+
* lands in v0.2 once the public agent surface supports replay-driven
|
|
210
|
+
* hook injection. */
|
|
211
|
+
static replay(_recordingPath: string, _options?: Partial<AgentOptions>): Promise<ClaudeCodeAgent>;
|
|
212
|
+
/** Map public permission mode to internal hooks/permissions PermissionMode.
|
|
213
|
+
* 'manual' currently maps to 'deny-all' — Step 1.4.5 will properly route
|
|
214
|
+
* through onPermissionRequest hook instead. */
|
|
215
|
+
private _mapPermissionMode;
|
|
216
|
+
/** Wrap an AcpSdkAdapter error into the appropriate AgentError code.
|
|
217
|
+
* Best-effort string matching; refinement lives in Step 1.4.5 when we
|
|
218
|
+
* surface structured errors from the adapter. */
|
|
219
|
+
private _wrapStartError;
|
|
220
|
+
/** Accumulate turn usage into the cumulative session usage tally. */
|
|
221
|
+
private _addUsage;
|
|
222
|
+
/** Tear down the current turn's subscription and reset status to ready. */
|
|
223
|
+
private _endTurn;
|
|
224
|
+
/** Map accumulator stopReason string to PromptResult stopReason union. */
|
|
225
|
+
private _mapStopReason;
|
|
226
|
+
/** Convert pre-parsed AccumulatorEvent back to a raw-SDK-shape SessionUpdate.
|
|
227
|
+
* prompt-handle.ts uses raw SDK shape so consumers see ACP-native fields.
|
|
228
|
+
* Returns null if the event has no SessionUpdate analogue (e.g. complete). */
|
|
229
|
+
private _accumulatorToSessionUpdate;
|
|
230
|
+
/** Run a hook callback and swallow any throw so a misbehaving hook never
|
|
231
|
+
* poisons the lifecycle contract. Hook errors get logged. */
|
|
232
|
+
private _safeFire;
|
|
233
|
+
private _log;
|
|
234
|
+
protected _DEFAULTS: {
|
|
235
|
+
readonly spawnTimeoutMs: 60000;
|
|
236
|
+
readonly elicitationTimeoutMs: 60000;
|
|
237
|
+
readonly maxQueueLength: 32;
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,KAAK,MAAM,MAAM,0BAA0B,CAAC;AAExD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,KAAK,YAAY,EAMlB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAEL,KAAK,kBAAkB,EACxB,MAAM,2BAA2B,CAAC;AAInC,OAAO,EAAe,KAAK,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAGvE,YAAY,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAI1D,oEAAoE;AACpE,MAAM,MAAM,WAAW,GACnB,MAAM,GACN,UAAU,GACV,SAAS,GACT,OAAO,GACP,MAAM,GACN,UAAU,GACV,WAAW,GACX,UAAU,GACV,SAAS,GACT,OAAO,CAAC;AAEZ;0CAC0C;AAC1C,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,UAAU,GAAG,QAAQ,CAAC;AAE5D,MAAM,WAAW,gBAAgB;IAE/B,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MA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