awb-agent-manager 1.6.76 → 1.6.78

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 (78) hide show
  1. package/README.md +18 -9
  2. package/dist/lib/agent-manager-commands.d.ts +2 -0
  3. package/dist/lib/agent-manager-commands.js +31 -13
  4. package/dist/lib/agent-manager-commands.js.map +1 -1
  5. package/dist/lib/cli-adapters/index.d.ts +3 -0
  6. package/dist/lib/cli-adapters/index.js +12 -3
  7. package/dist/lib/cli-adapters/index.js.map +1 -1
  8. package/dist/lib/constants.d.ts +1 -0
  9. package/dist/lib/constants.js +1 -0
  10. package/dist/lib/constants.js.map +1 -1
  11. package/dist/lib/event-dispatcher.d.ts +4 -0
  12. package/dist/lib/event-dispatcher.js +146 -0
  13. package/dist/lib/event-dispatcher.js.map +1 -1
  14. package/dist/lib/instance-heartbeat.d.ts +3 -0
  15. package/dist/lib/instance-heartbeat.js +4 -0
  16. package/dist/lib/instance-heartbeat.js.map +1 -1
  17. package/dist/lib/managed-agent-context.d.ts +2 -0
  18. package/dist/lib/managed-agent-context.js +1 -0
  19. package/dist/lib/managed-agent-context.js.map +1 -1
  20. package/dist/lib/managed-agent-store.d.ts +2 -0
  21. package/dist/lib/managed-agent-store.js.map +1 -1
  22. package/dist/lib/orphan-cleanup.d.ts +1 -0
  23. package/dist/lib/orphan-cleanup.js +56 -1
  24. package/dist/lib/orphan-cleanup.js.map +1 -1
  25. package/dist/lib/outbox.d.ts +28 -0
  26. package/dist/lib/outbox.js +169 -0
  27. package/dist/lib/outbox.js.map +1 -0
  28. package/dist/lib/rest.d.ts +36 -2
  29. package/dist/lib/rest.js +78 -6
  30. package/dist/lib/rest.js.map +1 -1
  31. package/dist/lib/runtime/acp/acp-client.d.ts +29 -0
  32. package/dist/lib/runtime/acp/acp-client.js +227 -0
  33. package/dist/lib/runtime/acp/acp-client.js.map +1 -0
  34. package/dist/lib/runtime/acp/acp-types.d.ts +118 -0
  35. package/dist/lib/runtime/acp/acp-types.js +2 -0
  36. package/dist/lib/runtime/acp/acp-types.js.map +1 -0
  37. package/dist/lib/runtime/acp/json-rpc-peer.d.ts +34 -0
  38. package/dist/lib/runtime/acp/json-rpc-peer.js +262 -0
  39. package/dist/lib/runtime/acp/json-rpc-peer.js.map +1 -0
  40. package/dist/lib/runtime/collaboration-governor.d.ts +29 -0
  41. package/dist/lib/runtime/collaboration-governor.js +125 -0
  42. package/dist/lib/runtime/collaboration-governor.js.map +1 -0
  43. package/dist/lib/runtime/hermes/hermes-process.d.ts +26 -0
  44. package/dist/lib/runtime/hermes/hermes-process.js +128 -0
  45. package/dist/lib/runtime/hermes/hermes-process.js.map +1 -0
  46. package/dist/lib/runtime/hermes/hermes-runtime.d.ts +38 -0
  47. package/dist/lib/runtime/hermes/hermes-runtime.js +146 -0
  48. package/dist/lib/runtime/hermes/hermes-runtime.js.map +1 -0
  49. package/dist/lib/runtime/hermes/hermes-session-store.d.ts +29 -0
  50. package/dist/lib/runtime/hermes/hermes-session-store.js +96 -0
  51. package/dist/lib/runtime/hermes/hermes-session-store.js.map +1 -0
  52. package/dist/lib/runtime/runtime-events.d.ts +48 -0
  53. package/dist/lib/runtime/runtime-events.js +2 -0
  54. package/dist/lib/runtime/runtime-events.js.map +1 -0
  55. package/dist/lib/runtime/runtime-health.d.ts +22 -0
  56. package/dist/lib/runtime/runtime-health.js +105 -0
  57. package/dist/lib/runtime/runtime-health.js.map +1 -0
  58. package/dist/lib/runtime/runtime-registry.d.ts +7 -0
  59. package/dist/lib/runtime/runtime-registry.js +142 -0
  60. package/dist/lib/runtime/runtime-registry.js.map +1 -0
  61. package/dist/lib/runtime/runtime-supervisor.d.ts +54 -0
  62. package/dist/lib/runtime/runtime-supervisor.js +234 -0
  63. package/dist/lib/runtime/runtime-supervisor.js.map +1 -0
  64. package/dist/lib/runtime/runtime-types.d.ts +36 -0
  65. package/dist/lib/runtime/runtime-types.js +11 -0
  66. package/dist/lib/runtime/runtime-types.js.map +1 -0
  67. package/dist/lib/service-install.js +1 -1
  68. package/dist/lib/setup.js +1 -1
  69. package/dist/lib/setup.js.map +1 -1
  70. package/dist/lib/skills/skill-materializer.d.ts +23 -0
  71. package/dist/lib/skills/skill-materializer.js +82 -0
  72. package/dist/lib/skills/skill-materializer.js.map +1 -0
  73. package/dist/lib/ticket-ref-capture.js +1 -0
  74. package/dist/lib/ticket-ref-capture.js.map +1 -1
  75. package/dist/main.js +110 -19
  76. package/dist/main.js.map +1 -1
  77. package/dist/package.json +2 -2
  78. package/package.json +2 -2
@@ -0,0 +1,227 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { ACP_PROTOCOL_VERSION } from './acp-types.js';
3
+ import { AcpProtocolError, JsonRpcPeer, } from './json-rpc-peer.js';
4
+ import { isChildTool } from '../collaboration-governor.js';
5
+ export { AcpProtocolError } from './json-rpc-peer.js';
6
+ function objectValue(value) {
7
+ return value && typeof value === 'object' && !Array.isArray(value)
8
+ ? value
9
+ : {};
10
+ }
11
+ function stringValue(value) {
12
+ return typeof value === 'string' ? value : '';
13
+ }
14
+ function numberValue(value) {
15
+ return typeof value === 'number' && Number.isFinite(value) ? value : 0;
16
+ }
17
+ function field(value, camel, snake) {
18
+ return value[camel] ?? value[snake];
19
+ }
20
+ function sanitizeDiagnostic(value, depth = 0) {
21
+ if (depth > 4)
22
+ return '[truncated]';
23
+ if (typeof value === 'string')
24
+ return value.slice(0, 2_048);
25
+ if (Array.isArray(value)) {
26
+ return value.slice(0, 50).map((entry) => sanitizeDiagnostic(entry, depth + 1));
27
+ }
28
+ if (!value || typeof value !== 'object')
29
+ return value;
30
+ const result = {};
31
+ for (const [key, entry] of Object.entries(value).slice(0, 50)) {
32
+ result[key] = /token|secret|password|authorization|api.?key/i.test(key)
33
+ ? '[REDACTED]'
34
+ : sanitizeDiagnostic(entry, depth + 1);
35
+ }
36
+ return result;
37
+ }
38
+ function normalizeUsage(sessionId, usageValue) {
39
+ const usage = objectValue(usageValue);
40
+ return {
41
+ type: 'usage',
42
+ sessionId,
43
+ inputTokens: numberValue(field(usage, 'inputTokens', 'input_tokens')),
44
+ outputTokens: numberValue(field(usage, 'outputTokens', 'output_tokens')),
45
+ totalTokens: numberValue(field(usage, 'totalTokens', 'total_tokens')),
46
+ cachedReadTokens: numberValue(field(usage, 'cachedReadTokens', 'cached_read_tokens')),
47
+ thoughtTokens: numberValue(field(usage, 'thoughtTokens', 'thought_tokens')),
48
+ };
49
+ }
50
+ function normalizeUpdate(paramsValue, childToolCalls) {
51
+ const params = objectValue(paramsValue);
52
+ const sessionId = stringValue(params.sessionId
53
+ ?? params.session_id);
54
+ const update = objectValue(params.update);
55
+ const kind = stringValue(field(update, 'sessionUpdate', 'session_update'));
56
+ if (kind === 'agent_message_chunk' || kind === 'user_message_chunk') {
57
+ const content = objectValue(update.content);
58
+ return { type: 'message_delta', sessionId, text: stringValue(content.text) };
59
+ }
60
+ if (kind === 'agent_thought_chunk') {
61
+ const content = objectValue(update.content);
62
+ return { type: 'reasoning_delta', sessionId, text: stringValue(content.text) };
63
+ }
64
+ if (kind === 'tool_call') {
65
+ const toolCallId = stringValue(field(update, 'toolCallId', 'tool_call_id'));
66
+ const title = stringValue(update.title);
67
+ const toolKind = stringValue(update.kind) || undefined;
68
+ if (isChildTool({ title, kind: toolKind })) {
69
+ childToolCalls.add(toolCallId);
70
+ return {
71
+ type: 'child_started',
72
+ sessionId,
73
+ childRunId: toolCallId,
74
+ title,
75
+ kind: toolKind,
76
+ input: field(update, 'rawInput', 'raw_input'),
77
+ };
78
+ }
79
+ return {
80
+ type: 'tool_started',
81
+ sessionId,
82
+ toolCallId,
83
+ title,
84
+ kind: toolKind,
85
+ input: field(update, 'rawInput', 'raw_input'),
86
+ };
87
+ }
88
+ if (kind === 'tool_call_update') {
89
+ const status = stringValue(update.status);
90
+ const toolCallId = stringValue(field(update, 'toolCallId', 'tool_call_id'));
91
+ if (childToolCalls.has(toolCallId)
92
+ && (status === 'completed' || status === 'failed' || status === 'cancelled')) {
93
+ childToolCalls.delete(toolCallId);
94
+ return {
95
+ type: 'child_finished',
96
+ sessionId,
97
+ childRunId: toolCallId,
98
+ status: status,
99
+ output: field(update, 'rawOutput', 'raw_output'),
100
+ };
101
+ }
102
+ return {
103
+ type: status === 'completed' || status === 'failed'
104
+ ? 'tool_completed'
105
+ : 'tool_updated',
106
+ sessionId,
107
+ toolCallId,
108
+ status: status || undefined,
109
+ output: field(update, 'rawOutput', 'raw_output'),
110
+ };
111
+ }
112
+ if (kind === 'usage_update') {
113
+ const nativeUsage = update.usage ?? {
114
+ inputTokens: update.inputTokens,
115
+ outputTokens: update.outputTokens,
116
+ totalTokens: update.used,
117
+ };
118
+ return normalizeUsage(sessionId, nativeUsage);
119
+ }
120
+ return {
121
+ type: 'diagnostic',
122
+ method: 'session/update',
123
+ sessionId,
124
+ data: sanitizeDiagnostic(update),
125
+ };
126
+ }
127
+ export class AcpClient {
128
+ #peer;
129
+ #onEvent;
130
+ #onPermissionRequest;
131
+ #childToolCalls = new Set();
132
+ constructor(peer, options) {
133
+ this.#peer = peer;
134
+ this.#onEvent = options.onEvent;
135
+ this.#onPermissionRequest = options.onPermissionRequest;
136
+ }
137
+ static async spawn(options) {
138
+ if (!options.command.trim()) {
139
+ throw new AcpProtocolError('acp_write_failed', 'ACP command is required');
140
+ }
141
+ let client;
142
+ const child = spawn(options.command, options.args ?? [], {
143
+ ...options.spawnOptions,
144
+ cwd: options.cwd,
145
+ env: options.env,
146
+ shell: false,
147
+ windowsHide: true,
148
+ stdio: ['pipe', 'pipe', 'pipe'],
149
+ });
150
+ const peer = new JsonRpcPeer(child, {
151
+ requestTimeoutMs: options.requestTimeoutMs,
152
+ maxLineBytes: options.maxLineBytes,
153
+ maxMessageBytes: options.maxMessageBytes,
154
+ onStderr: options.onStderr,
155
+ onNotification: (method, params) => {
156
+ if (client)
157
+ client.#handleNotification(method, params);
158
+ },
159
+ onRequest: (method, params) => {
160
+ if (!client)
161
+ throw new Error('ACP client is not ready');
162
+ return client.#handleRequest(method, params);
163
+ },
164
+ });
165
+ client = new AcpClient(peer, options);
166
+ return client;
167
+ }
168
+ get process() {
169
+ return this.#peer.process;
170
+ }
171
+ request(method, params, options) {
172
+ return this.#peer.request(method, params, options);
173
+ }
174
+ initialize(request) {
175
+ return this.request('initialize', {
176
+ protocolVersion: request.protocolVersion ?? ACP_PROTOCOL_VERSION,
177
+ clientCapabilities: request.clientCapabilities ?? {},
178
+ clientInfo: request.clientInfo,
179
+ });
180
+ }
181
+ newSession(request) {
182
+ return this.request('session/new', request);
183
+ }
184
+ loadSession(request) {
185
+ return this.request('session/load', request);
186
+ }
187
+ prompt(request, options) {
188
+ return this.request('session/prompt', request, options);
189
+ }
190
+ cancel(sessionId) {
191
+ this.#peer.notify('session/cancel', { sessionId });
192
+ return Promise.resolve();
193
+ }
194
+ async closeSession(sessionId) {
195
+ await this.request('session/close', { sessionId });
196
+ }
197
+ close() {
198
+ this.#peer.close();
199
+ }
200
+ #handleNotification(method, params) {
201
+ if (method === 'session/update') {
202
+ this.#onEvent?.(normalizeUpdate(params, this.#childToolCalls));
203
+ return;
204
+ }
205
+ const data = objectValue(params);
206
+ this.#onEvent?.({
207
+ type: 'diagnostic',
208
+ method,
209
+ sessionId: stringValue(data.sessionId ?? data.session_id) || undefined,
210
+ data: sanitizeDiagnostic(params),
211
+ });
212
+ }
213
+ async #handleRequest(method, params) {
214
+ if (method !== 'session/request_permission') {
215
+ throw new Error(`Unsupported ACP client request: ${method}`);
216
+ }
217
+ const request = params;
218
+ const outcome = this.#onPermissionRequest
219
+ ? await this.#onPermissionRequest(request)
220
+ : { outcome: 'cancelled' };
221
+ return { outcome };
222
+ }
223
+ }
224
+ export function runtimeEventFromPromptUsage(sessionId, usage) {
225
+ return usage ? normalizeUsage(sessionId, usage) : null;
226
+ }
227
+ //# sourceMappingURL=acp-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"acp-client.js","sourceRoot":"","sources":["../../../../src/lib/runtime/acp/acp-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;SACjC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,MAAc,EAAE,MAAe;QAClD,IAAI,MAAM,KAAK,4BAA4B,EAAE,CAAC;YAC5C,MAAM,IAAI,KAAK,CAAC,mCAAmC,MAAM,EAAE,CAAC,CAAC;QAC/D,CAAC;QACD,MAAM,OAAO,GAAG,MAA8B,CAAC;QAC/C,MAAM,OAAO,GAAG,IAAI,CAAC,oBAAoB;YACvC,CAAC,CAAC,MAAM,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC;YAC1C,CAAC,CAAC,EAAE,OAAO,EAAE,WAAoB,EAAE,CAAC;QACtC,OAAO,EAAE,OAAO,EAAE,CAAC;IACrB,CAAC;CACF;AAED,MAAM,UAAU,2BAA2B,CACzC,SAAiB,EACjB,KAAgB;IAEhB,OAAO,KAAK,CAAC,CAAC,CAAC,cAAc,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACzD,CAAC"}
@@ -0,0 +1,118 @@
1
+ export declare const ACP_PROTOCOL_VERSION = 1;
2
+ export type JsonRpcId = string | number;
3
+ export interface JsonRpcRequest {
4
+ jsonrpc: '2.0';
5
+ id: JsonRpcId;
6
+ method: string;
7
+ params?: unknown;
8
+ }
9
+ export interface JsonRpcNotification {
10
+ jsonrpc: '2.0';
11
+ method: string;
12
+ params?: unknown;
13
+ }
14
+ export interface JsonRpcSuccess {
15
+ jsonrpc: '2.0';
16
+ id: JsonRpcId;
17
+ result: unknown;
18
+ }
19
+ export interface JsonRpcFailure {
20
+ jsonrpc: '2.0';
21
+ id: JsonRpcId;
22
+ error: {
23
+ code: number;
24
+ message: string;
25
+ data?: unknown;
26
+ };
27
+ }
28
+ export type JsonRpcMessage = JsonRpcRequest | JsonRpcNotification | JsonRpcSuccess | JsonRpcFailure;
29
+ export interface AcpImplementation {
30
+ name: string;
31
+ version: string;
32
+ }
33
+ export interface AcpInitializeRequest {
34
+ protocolVersion?: number;
35
+ clientCapabilities?: Record<string, unknown>;
36
+ clientInfo: AcpImplementation;
37
+ }
38
+ export interface AcpInitializeResponse {
39
+ protocolVersion: number;
40
+ agentCapabilities: Record<string, unknown>;
41
+ agentInfo: AcpImplementation;
42
+ authMethods?: unknown[];
43
+ }
44
+ export interface AcpMcpServer {
45
+ name: string;
46
+ command?: string;
47
+ args?: string[];
48
+ env?: Array<{
49
+ name: string;
50
+ value: string;
51
+ }>;
52
+ url?: string;
53
+ headers?: Array<{
54
+ name: string;
55
+ value: string;
56
+ }>;
57
+ }
58
+ export interface AcpNewSessionRequest {
59
+ cwd: string;
60
+ mcpServers?: AcpMcpServer[];
61
+ }
62
+ export interface AcpNewSessionResponse {
63
+ sessionId: string;
64
+ models?: unknown;
65
+ modes?: unknown;
66
+ }
67
+ export interface AcpLoadSessionRequest extends AcpNewSessionRequest {
68
+ sessionId: string;
69
+ }
70
+ export interface AcpContentBlock {
71
+ type: string;
72
+ text?: string;
73
+ [key: string]: unknown;
74
+ }
75
+ export interface AcpPromptRequest {
76
+ sessionId: string;
77
+ prompt: AcpContentBlock[];
78
+ }
79
+ export interface AcpUsage {
80
+ inputTokens?: number;
81
+ outputTokens?: number;
82
+ totalTokens?: number;
83
+ cachedReadTokens?: number;
84
+ thoughtTokens?: number;
85
+ }
86
+ export interface AcpPromptResponse {
87
+ stopReason: string;
88
+ usage?: AcpUsage;
89
+ }
90
+ export interface AcpPermissionOption {
91
+ optionId: string;
92
+ name: string;
93
+ kind: string;
94
+ }
95
+ export interface AcpPermissionRequest {
96
+ sessionId: string;
97
+ toolCall: {
98
+ toolCallId: string;
99
+ title?: string;
100
+ kind?: string;
101
+ [key: string]: unknown;
102
+ };
103
+ options: AcpPermissionOption[];
104
+ }
105
+ export type AcpPermissionOutcome = {
106
+ outcome: 'selected';
107
+ optionId: string;
108
+ } | {
109
+ outcome: 'cancelled';
110
+ };
111
+ export interface AcpSessionUpdateParams {
112
+ sessionId: string;
113
+ update: {
114
+ sessionUpdate?: string;
115
+ session_update?: string;
116
+ [key: string]: unknown;
117
+ };
118
+ }
@@ -0,0 +1,2 @@
1
+ export const ACP_PROTOCOL_VERSION = 1;
2
+ //# sourceMappingURL=acp-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"acp-types.js","sourceRoot":"","sources":["../../../../src/lib/runtime/acp/acp-types.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC"}
@@ -0,0 +1,34 @@
1
+ import type { ChildProcessWithoutNullStreams } from 'node:child_process';
2
+ export type AcpProtocolErrorCode = 'acp_timeout' | 'acp_aborted' | 'acp_closed' | 'acp_process_exited' | 'acp_malformed_message' | 'acp_message_too_large' | 'acp_remote_error' | 'acp_write_failed';
3
+ export declare class AcpProtocolError extends Error {
4
+ readonly code: AcpProtocolErrorCode;
5
+ readonly exitCode?: number | null;
6
+ readonly rpcCode?: number;
7
+ readonly data?: unknown;
8
+ constructor(code: AcpProtocolErrorCode, message: string, options?: {
9
+ cause?: unknown;
10
+ exitCode?: number | null;
11
+ rpcCode?: number;
12
+ data?: unknown;
13
+ });
14
+ }
15
+ export interface JsonRpcPeerOptions {
16
+ requestTimeoutMs?: number;
17
+ maxLineBytes?: number;
18
+ maxMessageBytes?: number;
19
+ onNotification?: (method: string, params: unknown) => void | Promise<void>;
20
+ onRequest?: (method: string, params: unknown) => unknown | Promise<unknown>;
21
+ onStderr?: (line: string) => void;
22
+ }
23
+ export interface JsonRpcRequestOptions {
24
+ timeoutMs?: number;
25
+ signal?: AbortSignal;
26
+ }
27
+ export declare class JsonRpcPeer {
28
+ #private;
29
+ constructor(child: ChildProcessWithoutNullStreams, options?: JsonRpcPeerOptions);
30
+ get process(): ChildProcessWithoutNullStreams;
31
+ request<T = unknown>(method: string, params?: unknown, options?: JsonRpcRequestOptions): Promise<T>;
32
+ notify(method: string, params?: unknown): void;
33
+ close(): void;
34
+ }
@@ -0,0 +1,262 @@
1
+ export class AcpProtocolError extends Error {
2
+ code;
3
+ exitCode;
4
+ rpcCode;
5
+ data;
6
+ constructor(code, message, options = {}) {
7
+ super(message, options.cause === undefined ? undefined : { cause: options.cause });
8
+ this.name = 'AcpProtocolError';
9
+ this.code = code;
10
+ this.exitCode = options.exitCode;
11
+ this.rpcCode = options.rpcCode;
12
+ this.data = options.data;
13
+ }
14
+ }
15
+ const DEFAULT_REQUEST_TIMEOUT_MS = 30_000;
16
+ const DEFAULT_MAX_LINE_BYTES = 4 * 1024 * 1024;
17
+ const DEFAULT_MAX_MESSAGE_BYTES = 4 * 1024 * 1024;
18
+ function hasOwn(value, key) {
19
+ return Object.prototype.hasOwnProperty.call(value, key);
20
+ }
21
+ function redactDiagnostic(input) {
22
+ return input
23
+ .replace(/\b(authorization\s*:\s*bearer|api[_-]?key|access[_-]?token|refresh[_-]?token|password|secret|token)\b(\s*[:=]\s*|\s+)[^\s,;]+/gi, '$1$2[REDACTED]')
24
+ .slice(0, 8_192);
25
+ }
26
+ export class JsonRpcPeer {
27
+ #child;
28
+ #options;
29
+ #pending = new Map();
30
+ #nextId = 1;
31
+ #stdoutBuffer = Buffer.alloc(0);
32
+ #stderrBuffer = '';
33
+ #fatalError = null;
34
+ #closed = false;
35
+ constructor(child, options = {}) {
36
+ this.#child = child;
37
+ this.#options = {
38
+ ...options,
39
+ requestTimeoutMs: options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS,
40
+ maxLineBytes: options.maxLineBytes ?? DEFAULT_MAX_LINE_BYTES,
41
+ maxMessageBytes: options.maxMessageBytes ?? DEFAULT_MAX_MESSAGE_BYTES,
42
+ };
43
+ child.stdout.on('data', (chunk) => {
44
+ this.#consumeStdout(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
45
+ });
46
+ child.stderr.setEncoding('utf8');
47
+ child.stderr.on('data', (chunk) => this.#consumeStderr(chunk));
48
+ child.once('error', (error) => {
49
+ this.#fail(new AcpProtocolError('acp_process_exited', error.message, { cause: error }));
50
+ });
51
+ child.once('exit', (code, signal) => {
52
+ if (this.#closed)
53
+ return;
54
+ this.#fail(new AcpProtocolError('acp_process_exited', `ACP process exited (code=${String(code)}, signal=${String(signal)})`, { exitCode: code }));
55
+ });
56
+ }
57
+ get process() {
58
+ return this.#child;
59
+ }
60
+ request(method, params, options = {}) {
61
+ if (this.#fatalError)
62
+ return Promise.reject(this.#fatalError);
63
+ if (this.#closed) {
64
+ return Promise.reject(new AcpProtocolError('acp_closed', 'ACP peer is closed'));
65
+ }
66
+ if (options.signal?.aborted) {
67
+ return Promise.reject(new AcpProtocolError('acp_aborted', `ACP request aborted: ${method}`));
68
+ }
69
+ const id = this.#nextId++;
70
+ const timeoutMs = options.timeoutMs ?? this.#options.requestTimeoutMs;
71
+ return new Promise((resolve, reject) => {
72
+ const timer = setTimeout(() => {
73
+ this.#pending.delete(id);
74
+ reject(new AcpProtocolError('acp_timeout', `ACP request timed out after ${timeoutMs}ms: ${method}`));
75
+ }, timeoutMs);
76
+ const pending = {
77
+ resolve: (value) => resolve(value),
78
+ reject,
79
+ timer,
80
+ };
81
+ if (options.signal) {
82
+ const onAbort = () => {
83
+ const current = this.#pending.get(id);
84
+ if (!current)
85
+ return;
86
+ this.#pending.delete(id);
87
+ clearTimeout(current.timer);
88
+ reject(new AcpProtocolError('acp_aborted', `ACP request aborted: ${method}`));
89
+ };
90
+ options.signal.addEventListener('abort', onAbort, { once: true });
91
+ pending.removeAbort = () => options.signal?.removeEventListener('abort', onAbort);
92
+ }
93
+ this.#pending.set(id, pending);
94
+ try {
95
+ this.#write({ jsonrpc: '2.0', id, method, params });
96
+ }
97
+ catch (error) {
98
+ this.#settle(id, false, error);
99
+ }
100
+ });
101
+ }
102
+ notify(method, params) {
103
+ if (this.#fatalError)
104
+ throw this.#fatalError;
105
+ if (this.#closed)
106
+ throw new AcpProtocolError('acp_closed', 'ACP peer is closed');
107
+ this.#write({ jsonrpc: '2.0', method, params });
108
+ }
109
+ close() {
110
+ if (this.#closed)
111
+ return;
112
+ this.#closed = true;
113
+ this.#rejectPending(new AcpProtocolError('acp_closed', 'ACP peer closed'));
114
+ if (!this.#child.killed)
115
+ this.#child.kill();
116
+ }
117
+ #write(message) {
118
+ const encoded = `${JSON.stringify(message)}\n`;
119
+ if (Buffer.byteLength(encoded) > this.#options.maxMessageBytes) {
120
+ throw new AcpProtocolError('acp_message_too_large', 'Outbound ACP message exceeds the configured byte limit');
121
+ }
122
+ try {
123
+ this.#child.stdin.write(encoded);
124
+ }
125
+ catch (error) {
126
+ throw new AcpProtocolError('acp_write_failed', 'Failed to write ACP message', {
127
+ cause: error,
128
+ });
129
+ }
130
+ }
131
+ #consumeStdout(chunk) {
132
+ if (this.#fatalError || this.#closed)
133
+ return;
134
+ this.#stdoutBuffer = Buffer.concat([this.#stdoutBuffer, chunk]);
135
+ if (this.#stdoutBuffer.length > this.#options.maxLineBytes
136
+ && this.#stdoutBuffer.indexOf(0x0a) === -1) {
137
+ this.#fail(new AcpProtocolError('acp_message_too_large', 'ACP stdout line exceeds the configured byte limit'));
138
+ return;
139
+ }
140
+ while (true) {
141
+ const newline = this.#stdoutBuffer.indexOf(0x0a);
142
+ if (newline === -1)
143
+ break;
144
+ const line = this.#stdoutBuffer.subarray(0, newline);
145
+ this.#stdoutBuffer = this.#stdoutBuffer.subarray(newline + 1);
146
+ if (line.length === 0)
147
+ continue;
148
+ if (line.length > this.#options.maxLineBytes) {
149
+ this.#fail(new AcpProtocolError('acp_message_too_large', 'ACP stdout line exceeds the configured byte limit'));
150
+ return;
151
+ }
152
+ this.#parseLine(line.toString('utf8').replace(/\r$/, ''));
153
+ if (this.#fatalError)
154
+ return;
155
+ }
156
+ }
157
+ #consumeStderr(chunk) {
158
+ this.#stderrBuffer += chunk;
159
+ const lines = this.#stderrBuffer.split(/\r?\n/);
160
+ this.#stderrBuffer = lines.pop() ?? '';
161
+ for (const line of lines) {
162
+ if (line)
163
+ this.#options.onStderr?.(redactDiagnostic(line));
164
+ }
165
+ }
166
+ #parseLine(line) {
167
+ let value;
168
+ try {
169
+ value = JSON.parse(line);
170
+ }
171
+ catch (error) {
172
+ this.#fail(new AcpProtocolError('acp_malformed_message', 'ACP stdout contained malformed JSON', { cause: error }));
173
+ return;
174
+ }
175
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
176
+ this.#fail(new AcpProtocolError('acp_malformed_message', 'ACP stdout contained an invalid JSON-RPC message'));
177
+ return;
178
+ }
179
+ const message = value;
180
+ if (message.jsonrpc !== '2.0') {
181
+ this.#fail(new AcpProtocolError('acp_malformed_message', 'ACP message is missing jsonrpc=2.0'));
182
+ return;
183
+ }
184
+ if (typeof message.method === 'string') {
185
+ if (hasOwn(message, 'id')) {
186
+ void this.#handleIncomingRequest(message.id, message.method, message.params);
187
+ }
188
+ else {
189
+ void Promise.resolve(this.#options.onNotification?.(message.method, message.params)).catch(() => undefined);
190
+ }
191
+ return;
192
+ }
193
+ if (!hasOwn(message, 'id')) {
194
+ this.#fail(new AcpProtocolError('acp_malformed_message', 'ACP response is missing an id'));
195
+ return;
196
+ }
197
+ const id = message.id;
198
+ if (hasOwn(message, 'error')) {
199
+ const remote = message;
200
+ this.#settle(id, false, new AcpProtocolError('acp_remote_error', remote.error?.message || 'ACP peer returned an error', { rpcCode: remote.error?.code, data: remote.error?.data }));
201
+ }
202
+ else if (hasOwn(message, 'result')) {
203
+ this.#settle(id, true, message.result);
204
+ }
205
+ else {
206
+ this.#fail(new AcpProtocolError('acp_malformed_message', 'ACP response has neither result nor error'));
207
+ }
208
+ }
209
+ async #handleIncomingRequest(id, method, params) {
210
+ try {
211
+ if (!this.#options.onRequest) {
212
+ this.#write({
213
+ jsonrpc: '2.0',
214
+ id,
215
+ error: { code: -32601, message: `Method not found: ${method}` },
216
+ });
217
+ return;
218
+ }
219
+ const result = await this.#options.onRequest(method, params);
220
+ this.#write({ jsonrpc: '2.0', id, result: result ?? null });
221
+ }
222
+ catch (error) {
223
+ this.#write({
224
+ jsonrpc: '2.0',
225
+ id,
226
+ error: {
227
+ code: -32000,
228
+ message: error instanceof Error ? error.message : 'Client request handler failed',
229
+ },
230
+ });
231
+ }
232
+ }
233
+ #settle(id, succeeded, value) {
234
+ const pending = this.#pending.get(id);
235
+ if (!pending)
236
+ return;
237
+ this.#pending.delete(id);
238
+ clearTimeout(pending.timer);
239
+ pending.removeAbort?.();
240
+ if (succeeded)
241
+ pending.resolve(value);
242
+ else
243
+ pending.reject(value);
244
+ }
245
+ #rejectPending(error) {
246
+ for (const [id, pending] of this.#pending) {
247
+ this.#pending.delete(id);
248
+ clearTimeout(pending.timer);
249
+ pending.removeAbort?.();
250
+ pending.reject(error);
251
+ }
252
+ }
253
+ #fail(error) {
254
+ if (this.#fatalError || this.#closed)
255
+ return;
256
+ this.#fatalError = error;
257
+ this.#rejectPending(error);
258
+ if (!this.#child.killed)
259
+ this.#child.kill();
260
+ }
261
+ }
262
+ //# sourceMappingURL=json-rpc-peer.js.map