@wrongstack/acp 0.260.0 → 0.265.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.
@@ -167,6 +167,13 @@ interface ClientTransportOptions {
167
167
  env?: Record<string, string>;
168
168
  cwd?: string | undefined;
169
169
  handshakeTimeoutMs?: number | undefined;
170
+ /**
171
+ * Set to true when the child is an external ACP agent (Claude Code,
172
+ * Gemini CLI, Codex CLI, …) that does NOT emit a `[wstack-acp]\n`
173
+ * marker on startup. The v1 client (`ACPSession`) sets this; the
174
+ * server-side transport (the default) keeps the marker check.
175
+ */
176
+ skipHandshakeMarker?: boolean | undefined;
170
177
  }
171
178
  interface ACPChildProcess extends EventEmitter {
172
179
  stdout: NodeJS.ReadableStream;
@@ -195,4 +202,4 @@ declare class ClientTransport {
195
202
  private dispatch;
196
203
  }
197
204
 
198
- export { type ACPCancelParams as A, ClientTransport as C, StdioTransport as S, type ACPCapabilities as a, type ACPChildProcess as b, type ACPError as c, type ACPImageContent as d, type ACPInitializeParams as e, type ACPInputSchema as f, type ACPMessage as g, type ACPNotification as h, type ACPPlanContent as i, type ACPPlanStep as j, type ACPProgressContent as k, type ACPRequest as l, type ACPResourceContent as m, type ACPResponse as n, type ACPSessionInfo as o, type ACPSessionMode as p, type ACPTextContent as q, type ACPToolCallRequest as r, type ACPToolCallResponse as s, type ACPToolDefinition as t, type ACPToolList as u, type ACPToolResult as v, type AgentServerTransport as w, type ClientTransportOptions as x, type ContentBlock as y };
205
+ export { type AgentServerTransport as A, ClientTransport as C, StdioTransport as S, type ACPToolList as a, type ACPToolResult as b, type ACPCancelParams as c, type ACPCapabilities as d, type ACPChildProcess as e, type ACPError as f, type ACPImageContent as g, type ACPInitializeParams as h, type ACPInputSchema as i, type ACPMessage as j, type ACPNotification as k, type ACPPlanContent as l, type ACPPlanStep as m, type ACPProgressContent as n, type ACPRequest as o, type ACPResourceContent as p, type ACPResponse as q, type ACPSessionInfo as r, type ACPSessionMode as s, type ACPTextContent as t, type ACPToolCallRequest as u, type ACPToolCallResponse as v, type ACPToolDefinition as w, type ClientTransportOptions as x, type ContentBlock as y };
@@ -0,0 +1,36 @@
1
+ import { Tool } from '@wrongstack/core';
2
+ import { a as ACPToolList, b as ACPToolResult } from './stdio-transport-CsFr8JzC.js';
3
+
4
+ /**
5
+ * Tools registry for ACP agent-side.
6
+ *
7
+ * Translates WrongStack Tool definitions → ACP ACPToolDefinition format.
8
+ * Provides tool lookup and result assembly for the ACP protocol handler.
9
+ */
10
+
11
+ declare class ACPToolsRegistry {
12
+ private tools;
13
+ private readonly owner;
14
+ constructor(owner?: string);
15
+ /**
16
+ * Register one or more tools.
17
+ * Throws on duplicate name unless force=true.
18
+ */
19
+ register(tools: Tool[]): void;
20
+ /**
21
+ * Replace the current tool set.
22
+ */
23
+ setTools(tools: Tool[]): void;
24
+ get(name: string): Tool | undefined;
25
+ has(name: string): boolean;
26
+ list(): Tool[];
27
+ /** Build the ACP tools/list payload from registered tools. */
28
+ buildToolList(): ACPToolList;
29
+ /**
30
+ * Execute a tool by name and return ACP-formatted result.
31
+ * Returns null if the tool is not found.
32
+ */
33
+ execute(name: string, args: Record<string, unknown>, ctx: unknown, signal: AbortSignal): Promise<ACPToolResult | null>;
34
+ }
35
+
36
+ export { ACPToolsRegistry as A };
@@ -0,0 +1,310 @@
1
+ import { A as AgentServerTransport } from './stdio-transport-CsFr8JzC.js';
2
+
3
+ type ToolCallId = string & {
4
+ readonly __acpToolCallId: unique symbol;
5
+ };
6
+ type TerminalId = string & {
7
+ readonly __acpTerminalId: unique symbol;
8
+ };
9
+ /**
10
+ * Annotations attached to a content block. Optional, agent-supplied hint
11
+ * about audience/priority. Spec leaves shape open; we mirror the fields
12
+ * the spec shows in its examples.
13
+ */
14
+ interface ContentAnnotations {
15
+ audience?: ('user' | 'assistant')[] | undefined;
16
+ priority?: number | undefined;
17
+ [key: string]: unknown;
18
+ }
19
+ interface TextContent {
20
+ type: 'text';
21
+ text: string;
22
+ annotations?: ContentAnnotations | undefined;
23
+ }
24
+ interface ImageContent {
25
+ type: 'image';
26
+ mimeType: string;
27
+ /** Base64-encoded image data. */
28
+ data: string;
29
+ uri?: string | undefined;
30
+ annotations?: ContentAnnotations | undefined;
31
+ }
32
+ interface AudioContent {
33
+ type: 'audio';
34
+ mimeType: string;
35
+ /** Base64-encoded audio data. */
36
+ data: string;
37
+ annotations?: ContentAnnotations | undefined;
38
+ }
39
+ interface TextResourceContents {
40
+ uri: string;
41
+ mimeType?: string | undefined;
42
+ text: string;
43
+ }
44
+ interface BlobResourceContents {
45
+ uri: string;
46
+ mimeType?: string | undefined;
47
+ /** Base64-encoded binary. */
48
+ blob: string;
49
+ }
50
+ type EmbeddedResourceContents = TextResourceContents | BlobResourceContents;
51
+ interface EmbeddedResourceContent {
52
+ type: 'resource';
53
+ resource: EmbeddedResourceContents;
54
+ annotations?: ContentAnnotations | undefined;
55
+ }
56
+ interface ResourceLinkContent {
57
+ type: 'resource_link';
58
+ uri: string;
59
+ name: string;
60
+ mimeType?: string | undefined;
61
+ title?: string | undefined;
62
+ description?: string | undefined;
63
+ size?: number | undefined;
64
+ annotations?: ContentAnnotations | undefined;
65
+ }
66
+ type ContentBlock = TextContent | ImageContent | AudioContent | EmbeddedResourceContent | ResourceLinkContent;
67
+ type ToolKind = 'read' | 'edit' | 'delete' | 'move' | 'search' | 'execute' | 'think' | 'fetch' | 'switch_mode' | 'other';
68
+ type ToolCallStatus = 'pending' | 'in_progress' | 'completed' | 'failed';
69
+ /** A single concrete content payload attached to a tool call. */
70
+ type ToolCallContent = {
71
+ type: 'content';
72
+ content: ContentBlock;
73
+ } | {
74
+ type: 'diff';
75
+ path: string;
76
+ oldText: string | null;
77
+ newText: string;
78
+ } | {
79
+ type: 'terminal';
80
+ terminalId: TerminalId;
81
+ };
82
+ interface ToolCallLocation {
83
+ path: string;
84
+ /** 1-based per the spec's argument requirements. */
85
+ line?: number | undefined;
86
+ }
87
+ type PlanEntryPriority = 'high' | 'medium' | 'low';
88
+ type PlanEntryStatus = 'pending' | 'in_progress' | 'completed';
89
+ interface PlanEntry {
90
+ /** Required by the spec for the array shape, but per-entry id is optional. */
91
+ content: string;
92
+ priority: PlanEntryPriority;
93
+ status: PlanEntryStatus;
94
+ }
95
+ interface UsageCost {
96
+ amount: number;
97
+ /** ISO 4217 currency code, e.g. "USD". */
98
+ currency: string;
99
+ }
100
+ type PermissionOptionKind = 'allow_once' | 'allow_always' | 'reject_once' | 'reject_always';
101
+ interface PermissionOption {
102
+ optionId: string;
103
+ name: string;
104
+ kind: PermissionOptionKind;
105
+ }
106
+ type RequestPermissionOutcome = {
107
+ outcome: 'cancelled';
108
+ } | {
109
+ outcome: 'selected';
110
+ optionId: string;
111
+ };
112
+ type StopReason = 'end_turn' | 'max_tokens' | 'max_turn_requests' | 'refusal' | 'cancelled' | string;
113
+ /** Subsequent updates to a previously-emitted tool call. */
114
+ interface ToolCallUpdateNotification {
115
+ sessionUpdate: 'tool_call_update';
116
+ toolCallId: ToolCallId;
117
+ status?: ToolCallStatus | undefined;
118
+ content?: ToolCallContent[] | undefined;
119
+ title?: string | undefined;
120
+ kind?: ToolKind | undefined;
121
+ locations?: ToolCallLocation[] | undefined;
122
+ rawInput?: Record<string, unknown> | undefined;
123
+ rawOutput?: Record<string, unknown> | undefined;
124
+ }
125
+
126
+ /**
127
+ * ACP v1 server-side protocol handler.
128
+ *
129
+ * Receives JSON-RPC requests from an external ACP client (Zed, JetBrains
130
+ * Junie, VS Code ACP extension, etc.) over stdio and answers them per the
131
+ * v1 spec. See https://agentclientprotocol.com/protocol/v1/overview.
132
+ *
133
+ * Supported methods
134
+ * ─────────────────
135
+ * - initialize — handshake
136
+ * - authenticate — optional, no-op when auth isn't required
137
+ * - session/new — create a session
138
+ * - session/load — restore a session by id
139
+ * - session/prompt — run one turn, stream session/update
140
+ * notifications, return stopReason
141
+ * - session/cancel — notification (no response); cancels the
142
+ * in-flight turn on the target session
143
+ * - session/set_mode — change the active mode for a session
144
+ * - session/set_config_option — change a config option value
145
+ * - session/list — list known sessions
146
+ *
147
+ * Method execution
148
+ * ────────────────
149
+ * The handler is transport-agnostic; it sends responses via the
150
+ * `AgentServerTransport` injected at construction. The actual
151
+ * agent-loop work for a `session/prompt` turn is delegated to the
152
+ * caller-provided `runTurn` callback, which receives the prompt
153
+ * blocks and the per-turn AbortSignal and resolves with the final
154
+ * stopReason. Updates are streamed via the `emit` callback passed
155
+ * to `runTurn`; the handler wraps each as a `session/update`
156
+ * notification.
157
+ *
158
+ * This separation keeps the handler unit-testable: tests can supply
159
+ * a fake `runTurn` that yields a canned sequence of updates, and
160
+ * assert on the JSON-RPC traffic the handler produces. A real
161
+ * production caller wires `runTurn` to a core `Agent` instance.
162
+ *
163
+ * Concurrency
164
+ * ───────────
165
+ * Each session is single-threaded (one active turn at a time). The
166
+ * handler keeps a per-session AbortController so a `session/cancel`
167
+ * notification can stop the running turn mid-stream without tearing
168
+ * down the session. Multiple sessions can be active concurrently.
169
+ */
170
+
171
+ interface RunTurnInput {
172
+ sessionId: string;
173
+ /** Content blocks the client sent. */
174
+ prompt: readonly ContentBlock[];
175
+ /** Cancelled when the client sends `session/cancel` for this session. */
176
+ signal: AbortSignal;
177
+ }
178
+ interface RunTurnResult {
179
+ stopReason: StopReason;
180
+ /** Optional summary text the agent produced. */
181
+ text?: string;
182
+ plan?: PlanEntry[];
183
+ usage?: {
184
+ used: number;
185
+ size: number;
186
+ cost?: UsageCost | undefined;
187
+ };
188
+ }
189
+ /**
190
+ * The agent's per-turn work. Streams `SessionUpdate` notifications to
191
+ * `emit` and resolves with the final stopReason. Errors thrown from
192
+ * this iterable are converted to a `prompt_failed` JSON-RPC error.
193
+ */
194
+ type RunTurn = (input: RunTurnInput, emit: (update: unknown) => void) => Promise<RunTurnResult>;
195
+ interface SessionState {
196
+ id: string;
197
+ cwd: string;
198
+ /** Per-turn abort signal — aborted when the session is cancelled or closed. */
199
+ abort: AbortController;
200
+ /** Active mode, advertised to the client in current_mode_update. */
201
+ modeId: string;
202
+ /** Created at, for session/list ordering. */
203
+ createdAt: string;
204
+ /** Last activity timestamp, for session/info_update. */
205
+ updatedAt: string;
206
+ /** Optional human title. */
207
+ title?: string;
208
+ }
209
+ /** MCP-style session mode advertised in current_mode_update. */
210
+ interface SessionMode {
211
+ id: string;
212
+ name: string;
213
+ description?: string | undefined;
214
+ }
215
+ interface SessionConfigOption {
216
+ id: string;
217
+ name: string;
218
+ type: 'select' | string;
219
+ currentValue: string;
220
+ options: {
221
+ value: string;
222
+ name: string;
223
+ description?: string | undefined;
224
+ }[];
225
+ }
226
+ interface ProtocolHandlerOptions {
227
+ transport: AgentServerTransport;
228
+ /** Where the server is running; used for new sessions' default cwd. */
229
+ defaultCwd: string;
230
+ /** Agent's per-turn implementation. */
231
+ runTurn: RunTurn;
232
+ /**
233
+ * Optional callbacks for the lifecycle events the server should
234
+ * surface to the client. All default to no-ops.
235
+ */
236
+ onSessionNew?: ((state: SessionState) => void) | undefined;
237
+ /** Static list of available modes (advertised to clients). */
238
+ modes?: readonly SessionMode[] | undefined;
239
+ /** Static list of config options. */
240
+ configOptions?: readonly SessionConfigOption[] | undefined;
241
+ /** Agent name advertised in initialize. */
242
+ agentName?: string | undefined;
243
+ }
244
+ declare class ACPProtocolHandler {
245
+ private readonly transport;
246
+ private readonly defaultCwd;
247
+ private readonly runTurn;
248
+ private readonly onSessionNew;
249
+ private readonly modes;
250
+ private readonly configOptions;
251
+ private readonly agentName;
252
+ private initialized;
253
+ private readonly sessions;
254
+ private nextId;
255
+ constructor(opts: ProtocolHandlerOptions);
256
+ /**
257
+ * Process one inbound message. Returns true if this was a terminal
258
+ * message (rare; reserved for future use by the server's own
259
+ * shutdown signal).
260
+ */
261
+ handleMessage(msg: unknown): Promise<boolean>;
262
+ /** Abort all active turns and drop session state. */
263
+ close(): void;
264
+ private handleRequest;
265
+ private handleInitialize;
266
+ private handleAuthenticate;
267
+ private handleSessionNew;
268
+ private handleSessionLoad;
269
+ private handleSessionPrompt;
270
+ private handleSetMode;
271
+ private handleSetConfigOption;
272
+ private handleSessionList;
273
+ private handleNotification;
274
+ private sendNotification;
275
+ private sendError;
276
+ private allocId;
277
+ }
278
+
279
+ interface WrongStackACPServerOptions {
280
+ /**
281
+ * Per-turn implementation. If omitted, the server runs a no-op turn
282
+ * that just resolves with `end_turn`. The real production usage
283
+ * passes the result of `makeACPServerAgentTurn({ agentFor: ... })`
284
+ * from `./server-agent-turn.js` so each session gets a real
285
+ * `Agent` instance.
286
+ */
287
+ runTurn?: RunTurn | undefined;
288
+ /** Default cwd for new sessions. Defaults to the current process cwd. */
289
+ defaultCwd?: string | undefined;
290
+ /** Agent name advertised in initialize. */
291
+ agentName?: string | undefined;
292
+ }
293
+ declare class WrongStackACPServer {
294
+ private readonly transport;
295
+ private readonly handler;
296
+ private running;
297
+ constructor(opts?: WrongStackACPServerOptions);
298
+ /**
299
+ * Start the server. Blocks until the client disconnects.
300
+ *
301
+ * 1. Print the legacy `[wstack-acp]\n` marker so the client knows the
302
+ * process is the ACP server (the old `StdioTransport` handshake).
303
+ * 2. Loop: read messages, dispatch to the handler, until EOF / error.
304
+ */
305
+ start(): Promise<void>;
306
+ /** Stop the server. */
307
+ stop(): void;
308
+ }
309
+
310
+ export { ACPProtocolHandler as A, type PermissionOption as P, type RunTurn as R, type StopReason as S, type ToolCallUpdateNotification as T, type UsageCost as U, WrongStackACPServer as W, type WrongStackACPServerOptions as a, type RequestPermissionOutcome as b, type PlanEntry as c };
@@ -0,0 +1,3 @@
1
+ export { W as WrongStackACPServer, a as WrongStackACPServerOptions } from './wrongstack-acp-agent-Dv-A0bEm.js';
2
+ import './stdio-transport-CsFr8JzC.js';
3
+ import 'node:events';