@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.
package/dist/agent.d.ts CHANGED
@@ -1,100 +1,72 @@
1
- import { u as ACPToolList, v as ACPToolResult, w as AgentServerTransport, g as ACPMessage } from './stdio-transport-DoKRVjHz.js';
2
- export { S as StdioTransport } from './stdio-transport-DoKRVjHz.js';
3
- import { Tool } from '@wrongstack/core';
1
+ export { A as AgentServerTransport, S as StdioTransport } from './stdio-transport-CsFr8JzC.js';
2
+ export { A as ACPToolsRegistry } from './tools-registry-BCf8evEG.js';
3
+ import { R as RunTurn } from './wrongstack-acp-agent-Dv-A0bEm.js';
4
+ export { A as ACPProtocolHandler, W as WrongStackACPServer, a as WrongStackACPServerOptions } from './wrongstack-acp-agent-Dv-A0bEm.js';
5
+ import { Agent } from '@wrongstack/core';
4
6
  import 'node:events';
5
7
 
6
8
  /**
7
- * Tools registry for ACP agent-side.
9
+ * ACPServerAgentTurn `RunTurn` adapter for the v1 server side.
8
10
  *
9
- * Translates WrongStack Tool definitions ACP ACPToolDefinition format.
10
- * Provides tool lookup and result assembly for the ACP protocol handler.
11
+ * Wires the ACP v1 server (`ACPProtocolHandler`) to a core `Agent`.
12
+ * Each session gets its own `Agent` instance (per spec: sessions are
13
+ * isolated; sharing agents across sessions would defeat isolation).
14
+ * The agent is created lazily on the first `session/prompt` and
15
+ * torn down when the server is closed or the session is removed.
16
+ *
17
+ * The adapter:
18
+ * - converts the ACP `ContentBlock[]` prompt into a single string
19
+ * (concatenating text blocks; non-text blocks are recorded as a
20
+ * note in the prompt — future work can route images / audio to
21
+ * the appropriate provider)
22
+ * - calls `agent.run(prompt, {signal})` to drive the core loop
23
+ * - captures the agent's text result and emits it as one or more
24
+ * `agent_message_chunk` notifications
25
+ * - maps the agent's stop semantics to a v1 `StopReason`
26
+ *
27
+ * Streaming: the core `Agent` API is not currently token-streamed
28
+ * through this surface (its `run()` returns a final `RunResult`).
29
+ * v1 clients expect text deltas, but most implementations batch
30
+ * them — a single chunk per turn is acceptable. A future
31
+ * enhancement can use the Agent's `Renderer` interface to capture
32
+ * deltas as they're written, then forward them as multiple chunks.
33
+ *
34
+ * Scope: the adapter is deliberately minimal. It does NOT:
35
+ * - model the full conversation history across turns (the v1 spec
36
+ * leaves this to the agent; on the next prompt we re-feed the
37
+ * latest user message and the agent handles its own history)
38
+ * - use the agent's tool registry, permission policy, or
39
+ * extensions (this adapter is the lowest-fidelity integration;
40
+ * a future PR can wire a richer session-aware agent)
41
+ * - stream deltas token-by-token (see "Streaming" above)
42
+ *
43
+ * Cancellation: the parent `AbortSignal` propagates through
44
+ * `agent.run({signal})` and the underlying provider call observes
45
+ * it. On abort, the adapter maps the resulting `AbortError` to
46
+ * `{stopReason: 'cancelled'}`.
11
47
  */
12
48
 
13
- declare class ACPToolsRegistry {
14
- private tools;
15
- private readonly owner;
16
- constructor(owner?: string);
17
- /**
18
- * Register one or more tools.
19
- * Throws on duplicate name unless force=true.
20
- */
21
- register(tools: Tool[]): void;
49
+ interface ACPServerAgentTurnOptions {
22
50
  /**
23
- * Replace the current tool set.
51
+ * Factory that creates a fresh `Agent` for a given session.
52
+ * Called once per session on the first `session/prompt` turn.
53
+ * The factory must isolate each agent — sharing one agent
54
+ * across sessions would defeat v1's session-isolation model.
24
55
  */
25
- setTools(tools: Tool[]): void;
26
- get(name: string): Tool | undefined;
27
- has(name: string): boolean;
28
- list(): Tool[];
29
- /** Build the ACP tools/list payload from registered tools. */
30
- buildToolList(): ACPToolList;
56
+ agentFor: (sessionId: string, cwd: string) => Promise<Agent> | Agent;
31
57
  /**
32
- * Execute a tool by name and return ACP-formatted result.
33
- * Returns null if the tool is not found.
58
+ * Hard wall-clock cap for one turn. The agent's own provider
59
+ * timeout is layered under this; this cap is a safety belt.
60
+ * Default 5 minutes.
34
61
  */
35
- execute(name: string, args: Record<string, unknown>, ctx: unknown, signal: AbortSignal): Promise<ACPToolResult | null>;
36
- }
37
-
38
- declare class ACPProtocolHandler {
39
- private readonly transport;
40
- private readonly registry;
41
- private readonly context;
42
- private initialized;
43
- private readonly signal;
44
- private pendingCalls;
45
- constructor(transport: AgentServerTransport, registry: ACPToolsRegistry, context: unknown);
46
- /** Wire an external abort signal from the ACP client */
47
- wireAbortController(abortController: AbortController): void;
48
- /** Process one inbound message. Returns true if this was a terminal message. */
49
- handleMessage(msg: ACPMessage): Promise<boolean>;
50
- private handleRequest;
51
- private handleNotification;
52
- private handleInitialize;
53
- private handleToolsList;
54
- private handleToolCall;
55
- private handleCancel;
56
- private handleCancelNotification;
57
- private handleSessionList;
58
- private sendError;
59
- }
60
-
61
- interface WrongStackACPServerOptions {
62
- /**
63
- * Initial tool set. Typically loaded from the WrongStack tool registry
64
- * via `api.tools.list()` so the ACP server exposes exactly the tools the
65
- * CLI has configured.
66
- */
67
- tools: Tool[];
68
- /**
69
- * Owner label for tool metadata. Passed to ACPToolsRegistry.
70
- * @default 'wrongstack'
71
- */
72
- owner?: string | undefined;
73
- }
74
- declare class WrongStackACPServer {
75
- private readonly transport;
76
- private readonly registry;
77
- private readonly handler;
78
- private running;
79
- constructor(opts: WrongStackACPServerOptions);
80
- /**
81
- * Start the server. Blocks until the client disconnects.
82
- *
83
- * 1. Send the startup marker `[wstack-acp]` so the client
84
- * knows which stdout line is the protocol boundary.
85
- * 2. Loop: read messages, dispatch to handler, until EOF or error.
86
- *
87
- * Single dispatch path: every inbound message is read exactly once
88
- * from the transport and passed to the protocol handler exactly once.
89
- * An earlier version combined a `transport.onMessage` callback with
90
- * this read loop, which caused every message to be processed twice
91
- * (once by the callback, once by the loop) — duplicate tool calls
92
- * and duplicate responses to the client. See the ACP double-dispatch
93
- * fix in the security audit (P1-001).
94
- */
95
- start(): Promise<void>;
96
- /** Stop the server. */
97
- stop(): void;
62
+ timeoutMs?: number | undefined;
98
63
  }
64
+ /**
65
+ * Build a `RunTurn` that owns per-session `Agent` instances and
66
+ * delegates each turn to the appropriate agent. The returned
67
+ * function is reusable across sessions — the agents are kept in a
68
+ * Map keyed by `sessionId`.
69
+ */
70
+ declare function makeACPServerAgentTurn(opts: ACPServerAgentTurnOptions): RunTurn;
99
71
 
100
- export { ACPProtocolHandler, ACPToolsRegistry, AgentServerTransport, WrongStackACPServer, type WrongStackACPServerOptions };
72
+ export { type ACPServerAgentTurnOptions, makeACPServerAgentTurn };