acp-chat 0.2.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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Raman Marozau <raman@worktif.com>
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # acp-chat
2
+
3
+ Agent-to-agent dialogue over TCP/Unix socket using the ACP protocol.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install acp-chat
9
+ ```
10
+
11
+ ## CLI Usage
12
+
13
+ ```bash
14
+ # Create new session and send message
15
+ npx acp-chat new "Hello"
16
+
17
+ # Continue existing session
18
+ npx acp-chat <sessionId> "Follow-up message"
19
+ ```
20
+
21
+ ## Programmatic Usage
22
+
23
+ ```typescript
24
+ import { createACPClient, NDJSONClient } from 'acp-chat';
25
+
26
+ const ndjsonClient = new NDJSONClient({
27
+ address: '127.0.0.1:9800',
28
+ connectionType: 'tcp',
29
+ maxReconnectAttempts: 3,
30
+ baseReconnectDelayMs: 500,
31
+ maxReconnectDelayMs: 5000,
32
+ });
33
+
34
+ await ndjsonClient.connect();
35
+
36
+ const client = createACPClient(ndjsonClient, {
37
+ agentId: 'codex-acp',
38
+ requestTimeoutMs: 5 * 60 * 1000,
39
+ clientInfo: { name: 'my-app', version: '1.0.0' },
40
+ });
41
+
42
+ // Stream responses in real-time
43
+ client.on('update', (sessionId, update) => {
44
+ if (update.sessionUpdate === 'agent_message_chunk') {
45
+ process.stdout.write(update.content.text);
46
+ }
47
+ });
48
+
49
+ await client.initialize();
50
+
51
+ const session = await client.sessionNew();
52
+ const result = await client.sessionPrompt(session.sessionId, 'Hello!');
53
+
54
+ console.log(result.text);
55
+
56
+ await ndjsonClient.close();
57
+ ```
58
+
59
+ ## API
60
+
61
+ ### `NDJSONClient`
62
+
63
+ TCP/Unix socket client with NDJSON framing and automatic reconnection.
64
+
65
+ ### `createACPClient(ndjsonClient, options)`
66
+
67
+ Creates an ACP client for agent communication.
68
+
69
+ Options:
70
+ - `agentId`: Target agent identifier
71
+ - `requestTimeoutMs`: Request timeout (default: 120000)
72
+ - `clientInfo`: Client identification info
73
+
74
+ ### Client Methods
75
+
76
+ - `initialize()`: Initialize the ACP connection
77
+ - `sessionNew(configOptions?)`: Create a new session
78
+ - `sessionPrompt(sessionId, text, role?)`: Send a prompt
79
+ - `sessionConfigure(sessionId, options)`: Configure session
80
+ - `sessionCancel(sessionId)`: Cancel ongoing operation
81
+
82
+ ### Events
83
+
84
+ - `update`: Session update notifications (streaming chunks, tool calls, etc.)
85
+ - `notification`: Raw JSON-RPC notifications
86
+
87
+ ## License
88
+
89
+ Apache-2.0
@@ -0,0 +1,90 @@
1
+ import { NDJSONClient } from './ndjson-client.js';
2
+ import { type RequestTracker } from './request-tracker.js';
3
+ import { EventEmitter } from 'node:events';
4
+ export interface SessionUpdateNotification {
5
+ jsonrpc: '2.0';
6
+ method: 'session/update';
7
+ params: {
8
+ sessionId: string;
9
+ update: SessionUpdate;
10
+ };
11
+ }
12
+ export type SessionUpdate = AgentMessageChunk | PlanUpdate | ToolCallUpdate | ToolCallStatusUpdate;
13
+ export interface AgentMessageChunk {
14
+ sessionUpdate: 'agent_message_chunk';
15
+ content: {
16
+ type: string;
17
+ text: string;
18
+ };
19
+ }
20
+ export interface PlanUpdate {
21
+ sessionUpdate: 'plan';
22
+ entries: Array<{
23
+ content: string;
24
+ priority: string;
25
+ status: string;
26
+ }>;
27
+ }
28
+ export interface ToolCallUpdate {
29
+ sessionUpdate: 'tool_call';
30
+ toolCallId: string;
31
+ title: string;
32
+ kind: string;
33
+ status: string;
34
+ }
35
+ export interface ToolCallStatusUpdate {
36
+ sessionUpdate: 'tool_call_update';
37
+ toolCallId: string;
38
+ status: string;
39
+ content?: Array<{
40
+ type: string;
41
+ content: {
42
+ type: string;
43
+ text: string;
44
+ };
45
+ }>;
46
+ }
47
+ export interface SessionNewResult {
48
+ sessionId: string;
49
+ modes?: unknown;
50
+ models?: unknown;
51
+ configOptions?: unknown;
52
+ }
53
+ export interface PromptResult {
54
+ stopReason: string;
55
+ updates: SessionUpdate[];
56
+ text: string;
57
+ }
58
+ export interface InitializeResult {
59
+ protocolVersion: number;
60
+ agentCapabilities?: Record<string, unknown>;
61
+ agentInfo?: {
62
+ name: string;
63
+ title?: string;
64
+ version?: string;
65
+ };
66
+ authMethods?: unknown[];
67
+ }
68
+ export interface ConfigOption {
69
+ id: string;
70
+ value: string;
71
+ }
72
+ export interface ACPClient extends EventEmitter {
73
+ initialize(): Promise<InitializeResult>;
74
+ sessionNew(configOptions?: ConfigOption[]): Promise<SessionNewResult>;
75
+ sessionPrompt(sessionId: string, text: string, role?: string): Promise<PromptResult>;
76
+ sessionConfigure(sessionId: string, options: ConfigOption[]): Promise<void>;
77
+ sessionCancel(sessionId: string): void;
78
+ readonly requestTracker: RequestTracker;
79
+ }
80
+ export interface ACPClientOptions {
81
+ agentId: string;
82
+ requestTimeoutMs?: number;
83
+ clientInfo?: {
84
+ name: string;
85
+ title?: string;
86
+ version?: string;
87
+ };
88
+ }
89
+ export declare function createACPClient(ndjsonClient: NDJSONClient, opts: ACPClientOptions): ACPClient;
90
+ //# sourceMappingURL=acp-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"acp-client.d.ts","sourceRoot":"","sources":["../src/acp-client.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAwB,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEjF,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAM3C,MAAM,WAAW,yBAAyB;IACxC,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE,gBAAgB,CAAC;IACzB,MAAM,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,aAAa,CAAA;KAAE,CAAC;CACtD;AAED,MAAM,MAA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1
+ // Copyright 2026 Raman Marozau <raman@worktif.com>
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ import { createRequestTracker } from './request-tracker.js';
16
+ import { EventEmitter } from 'node:events';
17
+ // ---------------------------------------------------------------------------
18
+ // Factory
19
+ // ---------------------------------------------------------------------------
20
+ export function createACPClient(ndjsonClient, opts) {
21
+ const { agentId, requestTimeoutMs = 120_000, clientInfo } = opts;
22
+ const emitter = new EventEmitter();
23
+ const requestTracker = createRequestTracker({ defaultTimeoutMs: requestTimeoutMs });
24
+ let nextId = 1;
25
+ const clientSessionId = `client-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
26
+ const pendingUpdates = new Map();
27
+ ndjsonClient.on('message', (msg) => {
28
+ const obj = msg;
29
+ if (!obj || obj['jsonrpc'] !== '2.0')
30
+ return;
31
+ if ('id' in obj && ('result' in obj || 'error' in obj)) {
32
+ requestTracker.resolve(obj);
33
+ return;
34
+ }
35
+ if ('method' in obj && !('id' in obj)) {
36
+ const method = obj['method'];
37
+ const params = obj['params'];
38
+ if (method === 'session/update' && params) {
39
+ const sessionId = params['sessionId'];
40
+ const update = params['update'];
41
+ const updates = pendingUpdates.get(sessionId);
42
+ if (updates)
43
+ updates.push(update);
44
+ emitter.emit('update', sessionId, update);
45
+ }
46
+ emitter.emit('notification', method, params);
47
+ }
48
+ });
49
+ function send(method, params) {
50
+ const id = nextId++;
51
+ const request = { jsonrpc: '2.0', id, method, agentId, sessionId: clientSessionId, params };
52
+ const promise = requestTracker.register(id);
53
+ ndjsonClient.send(request);
54
+ return promise;
55
+ }
56
+ async function initialize() {
57
+ const resp = await send('initialize', {
58
+ protocolVersion: 1,
59
+ clientCapabilities: {},
60
+ clientInfo: clientInfo ?? { name: 'acp-chat', version: '1.0.0' },
61
+ });
62
+ if (resp.error)
63
+ throw new Error(`initialize: [${resp.error.code}] ${resp.error.message}`);
64
+ return resp.result;
65
+ }
66
+ async function sessionNew(configOptions) {
67
+ const params = { cwd: process.cwd(), mcpServers: [] };
68
+ if (configOptions?.length)
69
+ params['configOptions'] = configOptions;
70
+ const resp = await send('session/new', params);
71
+ if (resp.error)
72
+ throw new Error(`session/new: [${resp.error.code}] ${resp.error.message}`);
73
+ return resp.result;
74
+ }
75
+ async function sessionPrompt(sessionId, text, role = 'user') {
76
+ pendingUpdates.set(sessionId, []);
77
+ const resp = await send('session/prompt', { sessionId, prompt: [{ type: 'text', role, text }] });
78
+ await new Promise(resolve => setTimeout(resolve, 200));
79
+ const updates = pendingUpdates.get(sessionId) ?? [];
80
+ pendingUpdates.delete(sessionId);
81
+ if (resp.error)
82
+ throw new Error(`session/prompt: [${resp.error.code}] ${resp.error.message}`);
83
+ const result = resp.result;
84
+ const textParts = [];
85
+ for (const u of updates) {
86
+ if (u.sessionUpdate === 'agent_message_chunk' && u.content?.text) {
87
+ textParts.push(u.content.text);
88
+ }
89
+ if (u.sessionUpdate === 'tool_call_update' && u.content) {
90
+ for (const c of u.content) {
91
+ if (c.content?.text)
92
+ textParts.push(c.content.text);
93
+ }
94
+ }
95
+ }
96
+ return { stopReason: result.stopReason, updates, text: textParts.join('') };
97
+ }
98
+ async function sessionConfigure(sessionId, options) {
99
+ const resp = await send('session/configure', { sessionId, options });
100
+ if (resp.error)
101
+ throw new Error(`session/configure: [${resp.error.code}] ${resp.error.message}`);
102
+ }
103
+ function sessionCancel(sessionId) {
104
+ ndjsonClient.send({
105
+ jsonrpc: '2.0',
106
+ method: 'session/cancel',
107
+ params: { sessionId },
108
+ agentId,
109
+ sessionId: clientSessionId,
110
+ });
111
+ }
112
+ return Object.assign(emitter, { initialize, sessionNew, sessionPrompt, sessionConfigure, sessionCancel, requestTracker });
113
+ }
114
+ //# sourceMappingURL=acp-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"acp-client.js","sourceRoot":"","sources":["../src/acp-client.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,sCAAsC;AACtC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAOjC,OAAO,EAAE,oBAAoB,EAAuB,MAAM,sBAAsB,CAAC;AAEjF,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAuF3C,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E,MAAM,UAAU,eAAe,CAAC,YAA0B,EAAE,IAAsB;IAChF,MAAM,EAAE,OAAO,EAAE,gBAAgB,GAAG,OAAO,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;IACjE,MAAM,OAAO,GAAG,IAAI,YAAY,EAAE,CAAC;IACnC,MAAM,cAAc,GAAG,oBAAoB,CAAC,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,CAAC,CAAC;IAEpF,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,MAAM,eAAe,GAAG,UAAU,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;IACzF,MAAM,cAAc,GAAG,IAAI,GAAG,EAA2B,CAAC;IAE1D,YAAY,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,GAAY,EAAE,EAAE;QAC1C,MAAM,GAAG,GAAG,GAA8B,CAAC;QAC3C,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,S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B;QACxE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,mBAAmB,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;QACrE,IAAI,IAAI,CAAC,KAAK;YAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IACnG,CAAC;IAED,SAAS,aAAa,CAAC,SAAiB;QACtC,YAAY,CAAC,IAAI,CAAC;YAChB,OAAO,EAAE,KAAc;YACvB,MAAM,EAAE,gBAAgB;YACxB,MAAM,EAAE,EAAE,SAAS,EAAE;YACrB,OAAO;YACP,SAAS,EAAE,eAAe;SAC3B,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,gBAAgB,EAAE,aAAa,EAAE,cAAc,EAAE,CAAc,CAAC;AACzI,CAAC"}
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env node
2
+ // Copyright 2026 Raman Marozau <raman@worktif.com>
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 (the "License");
6
+ // you may not use this file except in compliance with the License.
7
+ // You may obtain a copy of the License at
8
+ //
9
+ // http://www.apache.org/licenses/LICENSE-2.0
10
+ //
11
+ // Unless required by applicable law or agreed to in writing, software
12
+ // distributed under the License is distributed on an "AS IS" BASIS,
13
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ // See the License for the specific language governing permissions and
15
+ // limitations under the License.
16
+ // ============================================================================
17
+ // ACP Chat CLI — single-turn tool for agent-to-agent dialogue
18
+ // ============================================================================
19
+ // Usage:
20
+ // acp-chat new "Hello" — create session + send
21
+ // acp-chat <sessionId> "Hello" — continue session
22
+ import { NDJSONClient } from './ndjson-client.js';
23
+ import { createACPClient } from './acp-client.js';
24
+ const BUS_ADDRESS = process.env['ACP_BUS_ADDRESS'] ?? '127.0.0.1:9800';
25
+ const AGENT_ID = process.env['ACP_AGENT_ID'] ?? 'codex-acp';
26
+ async function main() {
27
+ const [sessionArg, message] = process.argv.slice(2);
28
+ if (!sessionArg || !message) {
29
+ console.error('Usage: acp-chat <sessionId|"new"> "<message>"');
30
+ process.exit(1);
31
+ }
32
+ const ndjsonClient = new NDJSONClient({
33
+ address: BUS_ADDRESS,
34
+ connectionType: 'tcp',
35
+ maxReconnectAttempts: 3,
36
+ baseReconnectDelayMs: 500,
37
+ maxReconnectDelayMs: 5000,
38
+ });
39
+ try {
40
+ await ndjsonClient.connect();
41
+ const client = createACPClient(ndjsonClient, {
42
+ agentId: AGENT_ID,
43
+ requestTimeoutMs: 5 * 60 * 1000,
44
+ clientInfo: { name: 'acp-chat-cli', version: '1.0.0' },
45
+ });
46
+ client.on('update', (_sid, update) => {
47
+ if (update.sessionUpdate === 'agent_message_chunk') {
48
+ process.stdout.write(update.content.text);
49
+ }
50
+ });
51
+ await client.initialize();
52
+ let sessionId;
53
+ if (sessionArg === 'new') {
54
+ const session = await client.sessionNew();
55
+ sessionId = session.sessionId;
56
+ console.error(`SESSION_ID=${sessionId}`);
57
+ }
58
+ else {
59
+ sessionId = sessionArg;
60
+ console.error(`SESSION_ID=${sessionId} (continued)`);
61
+ }
62
+ const result = await client.sessionPrompt(sessionId, message);
63
+ process.stdout.write('\n');
64
+ console.error(`STOP=${result.stopReason} UPDATES=${result.updates.length}`);
65
+ }
66
+ finally {
67
+ await ndjsonClient.close();
68
+ }
69
+ }
70
+ main().catch((err) => {
71
+ console.error('ERROR:', err.message);
72
+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AAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,21 @@
1
+ export declare const ErrorCodes: {
2
+ readonly CAPACITY_EXCEEDED: -32000;
3
+ readonly REQUEST_TIMEOUT: -32001;
4
+ readonly DISCONNECTED: -32004;
5
+ };
6
+ export type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
7
+ export declare class ACPError extends Error {
8
+ readonly code: ErrorCode;
9
+ readonly data?: unknown;
10
+ constructor(code: ErrorCode, message: string, data?: unknown);
11
+ }
12
+ export declare class CapacityExceededError extends ACPError {
13
+ constructor(message?: string, data?: unknown);
14
+ }
15
+ export declare class RequestTimeoutError extends ACPError {
16
+ constructor(message?: string, data?: unknown);
17
+ }
18
+ export declare class DisconnectedError extends ACPError {
19
+ constructor(message?: string, data?: unknown);
20
+ }
21
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAmBA,eAAO,MAAM,UAAU;;;;CAIb,CAAC;AAEX,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,OAAO,UAAU,CAAC,CAAC;AAErE,qBAAa,QAAS,SAAQ,KAAK;IACjC,SAAgB,IAAI,EAAE,SAAS,CAAC;IAChC,SAAgB,IAAI,CAAC,EAAE,OAAO,CAAC;gBAEnB,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO;CAM7D;AAED,qBAAa,qBAAsB,SAAQ,QAAQ;gBACrC,OAAO,SAAsB,EAAE,IAAI,CAAC,EAAE,OAAO;CAI1D;AAED,qBAAa,mBAAoB,SAAQ,QAAQ;gBACnC,OAAO,SAAoB,EAAE,IAAI,CAAC,EAAE,OAAO;CAIxD;AAED,qBAAa,iBAAkB,SAAQ,QAAQ;gBACjC,OAAO,SAAiB,EAAE,IAAI,CAAC,EAAE,OAAO;CAIrD"}
package/dist/errors.js ADDED
@@ -0,0 +1,51 @@
1
+ // Copyright 2026 Raman Marozau <raman@worktif.com>
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ // ============================================================================
16
+ // ACP Chat — Error Classes
17
+ // ============================================================================
18
+ export const ErrorCodes = {
19
+ CAPACITY_EXCEEDED: -32000,
20
+ REQUEST_TIMEOUT: -32001,
21
+ DISCONNECTED: -32004,
22
+ };
23
+ export class ACPError extends Error {
24
+ code;
25
+ data;
26
+ constructor(code, message, data) {
27
+ super(message);
28
+ this.name = 'ACPError';
29
+ this.code = code;
30
+ this.data = data;
31
+ }
32
+ }
33
+ export class CapacityExceededError extends ACPError {
34
+ constructor(message = 'Capacity exceeded', data) {
35
+ super(ErrorCodes.CAPACITY_EXCEEDED, message, data);
36
+ this.name = 'CapacityExceededError';
37
+ }
38
+ }
39
+ export class RequestTimeoutError extends ACPError {
40
+ constructor(message = 'Request timeout', data) {
41
+ super(ErrorCodes.REQUEST_TIMEOUT, message, data);
42
+ this.name = 'RequestTimeoutError';
43
+ }
44
+ }
45
+ export class DisconnectedError extends ACPError {
46
+ constructor(message = 'Disconnected', data) {
47
+ super(ErrorCodes.DISCONNECTED, message, data);
48
+ this.name = 'DisconnectedError';
49
+ }
50
+ }
51
+ //# source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BAAkB,SAAQ,QAAQ;IAC7C,YAAY,OAAO,GAAG,cAAc,EAAE,IAAc;QAClD,KAAK,CAAC,UAAU,CAAC,YAAY,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;QAC9C,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ export { NDJSONClient, type NDJSONClientOptions, type NDJSONClientEvents } from './ndjson-client.js';
2
+ export { createACPClient, type ACPClient, type ACPClientOptions, type SessionUpdate, type SessionNewResult, type PromptResult, type InitializeResult, type ConfigOption, type AgentMessageChunk, type PlanUpdate, type ToolCallUpdate, type ToolCallStatusUpdate } from './acp-client.js';
3
+ export { createRequestTracker, type RequestTracker, type RequestTrackerOptions } from './request-tracker.js';
4
+ export { DisconnectedError, CapacityExceededError, RequestTimeoutError, ACPError, ErrorCodes } from './errors.js';
5
+ export type { JsonRpcId, JsonRpcResponse, JsonRpcError, ConnectionState } from './types.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,KAAK,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACrG,OAAO,EAAE,eAAe,EAAE,KAAK,SAAS,EAAE,KAAK,gBAAgB,EAAE,KAAK,aAAa,EAAE,KAAK,gBAAgB,EAAE,KAAK,YAAY,EAAE,KAAK,gBAAgB,EAAE,KAAK,YAAY,EAAE,KAAK,iBAAiB,EAAE,KAAK,UAAU,EAAE,KAAK,cAAc,EAAE,KAAK,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAC1R,OAAO,EAAE,oBAAoB,EAAE,KAAK,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7G,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAClH,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ // Copyright 2026 Raman Marozau <raman@worktif.com>
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ // ============================================================================
16
+ // ACP Chat — Public API
17
+ // ============================================================================
18
+ export { NDJSONClient } from './ndjson-client.js';
19
+ export { createACPClient } from './acp-client.js';
20
+ export { createRequestTracker } from './request-tracker.js';
21
+ export { DisconnectedError, CapacityExceededError, RequestTimeoutError, ACPError, ErrorCodes } from './errors.js';
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,sCAAsC;AACtC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,+EAA+E;AAC/E,wBAAwB;AACxB,+EAA+E;AAE/E,OAAO,EAAE,YAAY,EAAqD,MAAM,oBAAoB,CAAC;AACrG,OAAO,EAAE,eAAe,EAA0O,MAAM,iBAAiB,CAAC;AAC1R,OAAO,EAAE,oBAAoB,EAAmD,MAAM,sBAAsB,CAAC;AAC7G,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,39 @@
1
+ import { EventEmitter } from 'node:events';
2
+ import type { ConnectionState } from './types.js';
3
+ export interface NDJSONClientOptions {
4
+ address: string;
5
+ connectionType: 'tcp' | 'unix';
6
+ maxReconnectAttempts: number;
7
+ baseReconnectDelayMs: number;
8
+ maxReconnectDelayMs: number;
9
+ }
10
+ export interface NDJSONClientEvents {
11
+ message: (msg: unknown) => void;
12
+ error: (err: Error) => void;
13
+ disconnect: () => void;
14
+ reconnect: (attempt: number) => void;
15
+ framingError: (line: string, err: Error) => void;
16
+ }
17
+ export declare class NDJSONClient extends EventEmitter {
18
+ private readonly opts;
19
+ private socket;
20
+ private state;
21
+ private reconnectAttempt;
22
+ private reconnectTimer;
23
+ private lineBuffer;
24
+ private closedByUser;
25
+ constructor(opts: NDJSONClientOptions);
26
+ connect(): Promise<void>;
27
+ send(message: unknown): void;
28
+ close(): Promise<void>;
29
+ isConnected(): boolean;
30
+ getState(): ConnectionState;
31
+ private createConnection;
32
+ private buildConnectOptions;
33
+ private wireSocketEvents;
34
+ private handleData;
35
+ private scheduleReconnect;
36
+ private attemptReconnect;
37
+ private clearReconnectTimer;
38
+ }
39
+ //# sourceMappingURL=ndjson-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ndjson-client.d.ts","sourceRoot":"","sources":["../src/ndjson-client.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAI3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,KAAK,GAAG,MAAM,CAAC;IAC/B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,mBAAmB,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC;IAChC,KAAK,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,CAAC;IAC5B,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,SAAS,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,KAAK,IAAI,CAAC;CAClD;AAED,qBAAa,YAAa,SAAQ,YAAY;IAC5C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAsB;IAC3C,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,KAAK,CAAmC;IAChD,OAAO,CAAC,gBAAgB,CAAK;IAC7B,OAAO,CAAC,cAAc,CAA+B;IACrD,OAAO,CAAC,UAAU,CAAM;IACxB,OAAO,CAAC,YAAY,CAAS;gBAEjB,IAAI,EAAE,mBAAmB;IAKrC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IASxB,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAO5B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAqBtB,WAAW,IAAI,OAAO;IACtB,QAAQ,IAAI,eAAe;IAE3B,OAAO,CAAC,gBAAgB;IAmCxB,OAAO,CAAC,mBAAmB;IAU3B,OAAO,CAAC,gBAAgB;IAWxB,OAAO,CAAC,UAAU;IAelB,OAAO,CAAC,iBAAiB;IAoBzB,OAAO,CAAC,gBAAgB;IAmBxB,OAAO,CAAC,mBAAmB;CAM5B"}
@@ -0,0 +1,184 @@
1
+ // Copyright 2026 Raman Marozau <raman@worktif.com>
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ // ============================================================================
16
+ // ACP Chat — NDJSON Client (TCP/Unix Socket Transport)
17
+ // ============================================================================
18
+ import { EventEmitter } from 'node:events';
19
+ import * as net from 'node:net';
20
+ import { serializeNdjson, deserializeNdjsonLine } from './ndjson.js';
21
+ import { DisconnectedError } from './errors.js';
22
+ export class NDJSONClient extends EventEmitter {
23
+ opts;
24
+ socket = null;
25
+ state = 'disconnected';
26
+ reconnectAttempt = 0;
27
+ reconnectTimer = null;
28
+ lineBuffer = '';
29
+ closedByUser = false;
30
+ constructor(opts) {
31
+ super();
32
+ this.opts = opts;
33
+ }
34
+ connect() {
35
+ if (this.state === 'connected' || this.state === 'connecting')
36
+ return Promise.resolve();
37
+ if (this.state === 'closed')
38
+ return Promise.reject(new Error('Client has been closed'));
39
+ this.closedByUser = false;
40
+ this.reconnectAttempt = 0;
41
+ return this.createConnection();
42
+ }
43
+ send(message) {
44
+ if (this.state !== 'connected' || !this.socket) {
45
+ throw new DisconnectedError('Cannot send: not connected to stdio Bus');
46
+ }
47
+ this.socket.write(serializeNdjson(message));
48
+ }
49
+ close() {
50
+ this.closedByUser = true;
51
+ this.clearReconnectTimer();
52
+ const prevState = this.state;
53
+ this.state = 'closed';
54
+ if (prevState === 'closed' || prevState === 'disconnected')
55
+ return Promise.resolve();
56
+ return new Promise((resolve) => {
57
+ if (this.socket) {
58
+ const sock = this.socket;
59
+ this.socket = null;
60
+ if (sock.destroyed) {
61
+ resolve();
62
+ return;
63
+ }
64
+ sock.once('close', () => resolve());
65
+ sock.destroy();
66
+ }
67
+ else {
68
+ resolve();
69
+ }
70
+ });
71
+ }
72
+ isConnected() { return this.state === 'connected'; }
73
+ getState() { return this.state; }
74
+ createConnection() {
75
+ return new Promise((resolve, reject) => {
76
+ this.state = this.reconnectAttempt === 0 ? 'connecting' : 'reconnecting';
77
+ this.lineBuffer = '';
78
+ const connectOpts = this.buildConnectOptions();
79
+ const socket = net.createConnection(connectOpts);
80
+ this.socket = socket;
81
+ const onConnect = () => {
82
+ cleanup();
83
+ this.state = 'connected';
84
+ this.reconnectAttempt = 0;
85
+ this.wireSocketEvents(socket);
86
+ resolve();
87
+ };
88
+ const onError = (err) => {
89
+ cleanup();
90
+ if (this.reconnectAttempt === 0 && this.state === 'connecting') {
91
+ this.state = 'disconnected';
92
+ reject(err);
93
+ }
94
+ };
95
+ const cleanup = () => {
96
+ socket.removeListener('connect', onConnect);
97
+ socket.removeListener('error', onError);
98
+ };
99
+ socket.once('connect', onConnect);
100
+ socket.once('error', onError);
101
+ });
102
+ }
103
+ buildConnectOptions() {
104
+ if (this.opts.connectionType === 'unix')
105
+ return { path: this.opts.address };
106
+ const lastColon = this.opts.address.lastIndexOf(':');
107
+ if (lastColon === -1)
108
+ throw new Error(`Invalid TCP address: expected "host:port", got "${this.opts.address}"`);
109
+ const host = this.opts.address.slice(0, lastColon);
110
+ const port = parseInt(this.opts.address.slice(lastColon + 1), 10);
111
+ if (isNaN(port))
112
+ throw new Error(`Invalid TCP port in address "${this.opts.address}"`);
113
+ return { host, port };
114
+ }
115
+ wireSocketEvents(socket) {
116
+ socket.on('data', (chunk) => this.handleData(chunk.toString('utf-8')));
117
+ socket.on('error', (err) => this.emit('error', err));
118
+ socket.on('close', () => {
119
+ if (this.closedByUser || this.state === 'closed')
120
+ return;
121
+ this.state = 'disconnected';
122
+ this.emit('disconnect');
123
+ this.scheduleReconnect();
124
+ });
125
+ }
126
+ handleData(data) {
127
+ this.lineBuffer += data;
128
+ let newlineIdx;
129
+ while ((newlineIdx = this.lineBuffer.indexOf('\n')) !== -1) {
130
+ const line = this.lineBuffer.slice(0, newlineIdx);
131
+ this.lineBuffer = this.lineBuffer.slice(newlineIdx + 1);
132
+ if (line.length === 0)
133
+ continue;
134
+ try {
135
+ this.emit('message', deserializeNdjsonLine(line));
136
+ }
137
+ catch (err) {
138
+ this.emit('framingError', line, err instanceof Error ? err : new Error(String(err)));
139
+ }
140
+ }
141
+ }
142
+ scheduleReconnect() {
143
+ if (this.closedByUser || this.state === 'closed')
144
+ return;
145
+ if (this.reconnectAttempt >= this.opts.maxReconnectAttempts) {
146
+ this.state = 'disconnected';
147
+ this.emit('disconnect');
148
+ return;
149
+ }
150
+ this.state = 'reconnecting';
151
+ const attempt = this.reconnectAttempt++;
152
+ const jitter = Math.random() * this.opts.baseReconnectDelayMs;
153
+ const delay = Math.min(this.opts.baseReconnectDelayMs * Math.pow(2, attempt) + jitter, this.opts.maxReconnectDelayMs);
154
+ this.reconnectTimer = setTimeout(() => {
155
+ this.reconnectTimer = null;
156
+ this.emit('reconnect', this.reconnectAttempt);
157
+ this.attemptReconnect();
158
+ }, delay);
159
+ }
160
+ attemptReconnect() {
161
+ if (this.closedByUser || this.state === 'closed')
162
+ return;
163
+ this.lineBuffer = '';
164
+ const socket = net.createConnection(this.buildConnectOptions());
165
+ this.socket = socket;
166
+ socket.once('connect', () => {
167
+ socket.removeAllListeners('error');
168
+ this.state = 'connected';
169
+ this.reconnectAttempt = 0;
170
+ this.wireSocketEvents(socket);
171
+ });
172
+ socket.once('error', () => {
173
+ socket.destroy();
174
+ this.scheduleReconnect();
175
+ });
176
+ }
177
+ clearReconnectTimer() {
178
+ if (this.reconnectTimer !== null) {
179
+ clearTimeout(this.reconnectTimer);
180
+ this.reconnectTimer = null;
181
+ }
182
+ }
183
+ }
184
+ //# sourceMappingURL=ndjson-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ndjson-client.js","sourceRoot":"","sources":["../src/ndjson-client.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,sCAAsC;AACtC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;A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I,IAAI,CAAC,cAAc,KAAK,IAAI,EAAE,CAAC;YACjC,YAAY,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;YAClC,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;QAC7B,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ export declare function serializeNdjson(obj: unknown): string;
2
+ export declare function deserializeNdjsonLine(line: string): unknown;
3
+ //# sourceMappingURL=ndjson.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ndjson.d.ts","sourceRoot":"","sources":["../src/ndjson.ts"],"names":[],"mappings":"AAmBA,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAMpD;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE3D"}
package/dist/ndjson.js ADDED
@@ -0,0 +1,28 @@
1
+ // Copyright 2026 Raman Marozau <raman@worktif.com>
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ // ============================================================================
16
+ // ACP Chat — NDJSON Framing
17
+ // ============================================================================
18
+ export function serializeNdjson(obj) {
19
+ const json = JSON.stringify(obj);
20
+ if (json === undefined) {
21
+ throw new TypeError('Value is not JSON-serializable');
22
+ }
23
+ return json + '\n';
24
+ }
25
+ export function deserializeNdjsonLine(line) {
26
+ return JSON.parse(line);
27
+ }
28
+ //# sourceMappingURL=ndjson.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ndjson.js","sourceRoot":"","sources":["../src/ndjson.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,sCAAsC;AACtC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,+EAA+E;AAC/E,4BAA4B;AAC5B,+EAA+E;AAE/E,MAAM,UAAU,eAAe,CAAC,GAAY;IAC1C,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IACjC,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,MAAM,IAAI,SAAS,CAAC,gCAAgC,CAAC,CAAC;IACxD,CAAC;IACD,OAAO,IAAI,GAAG,IAAI,CAAC;AACrB,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { JsonRpcId, JsonRpcResponse } from './types.js';
2
+ export interface RequestTrackerOptions {
3
+ maxPending: number;
4
+ defaultTimeoutMs: number;
5
+ }
6
+ export interface RequestTracker {
7
+ register(id: JsonRpcId, timeoutMs?: number): Promise<JsonRpcResponse>;
8
+ resolve(response: JsonRpcResponse): boolean;
9
+ cancelAll(reason: Error): void;
10
+ pendingCount(): number;
11
+ hasPending(id: JsonRpcId): boolean;
12
+ }
13
+ export declare function createRequestTracker(opts?: Partial<RequestTrackerOptions>): RequestTracker;
14
+ //# sourceMappingURL=request-tracker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-tracker.d.ts","sourceRoot":"","sources":["../src/request-tracker.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAgB,MAAM,YAAY,CAAC;AAG3E,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AASD,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IACtE,OAAO,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC;IAC5C,SAAS,CAAC,MAAM,EAAE,KAAK,GAAG,IAAI,CAAC;IAC/B,YAAY,IAAI,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,EAAE,SAAS,GAAG,OAAO,CAAC;CACpC;AAED,wBAAgB,oBAAoB,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,GAAG,cAAc,CAqD1F"}
@@ -0,0 +1,64 @@
1
+ // Copyright 2026 Raman Marozau <raman@worktif.com>
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ import { CapacityExceededError, RequestTimeoutError } from './errors.js';
16
+ const DEFAULT_OPTIONS = {
17
+ maxPending: 4096,
18
+ defaultTimeoutMs: 30_000,
19
+ };
20
+ const MIN_TIMEOUT_MS = 1000;
21
+ export function createRequestTracker(opts) {
22
+ const options = { ...DEFAULT_OPTIONS, ...opts };
23
+ if (options.defaultTimeoutMs < MIN_TIMEOUT_MS) {
24
+ options.defaultTimeoutMs = MIN_TIMEOUT_MS;
25
+ }
26
+ const pending = new Map();
27
+ function register(id, timeoutMs) {
28
+ if (pending.size >= options.maxPending) {
29
+ return Promise.reject(new CapacityExceededError(`Maximum pending requests (${options.maxPending}) exceeded`));
30
+ }
31
+ let effectiveTimeout = timeoutMs ?? options.defaultTimeoutMs;
32
+ if (effectiveTimeout < MIN_TIMEOUT_MS) {
33
+ effectiveTimeout = MIN_TIMEOUT_MS;
34
+ }
35
+ return new Promise((resolve, reject) => {
36
+ const timeoutHandle = setTimeout(() => {
37
+ pending.delete(id);
38
+ reject(new RequestTimeoutError(`Request ${String(id)} timed out after ${effectiveTimeout}ms`, { id, timeoutMs: effectiveTimeout }));
39
+ }, effectiveTimeout);
40
+ if (timeoutHandle.unref) {
41
+ timeoutHandle.unref();
42
+ }
43
+ pending.set(id, { id, registeredAt: Date.now(), timeoutMs: effectiveTimeout, timeoutHandle, resolve, reject });
44
+ });
45
+ }
46
+ function resolve(response) {
47
+ const entry = pending.get(response.id);
48
+ if (!entry)
49
+ return false;
50
+ clearTimeout(entry.timeoutHandle);
51
+ pending.delete(response.id);
52
+ entry.resolve(response);
53
+ return true;
54
+ }
55
+ function cancelAll(reason) {
56
+ for (const [, entry] of pending) {
57
+ clearTimeout(entry.timeoutHandle);
58
+ entry.reject(reason);
59
+ }
60
+ pending.clear();
61
+ }
62
+ return { register, resolve, cancelAll, pendingCount: () => pending.size, hasPending: (id) => pending.has(id) };
63
+ }
64
+ //# sourceMappingURL=request-tracker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-tracker.js","sourceRoot":"","sources":["../src/request-tracker.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,sCAAsC;AACtC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAOjC,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAOzE,MAAM,eAAe,GAA0B;IAC7C,UAAU,EAAE,IAAI;IAChB,gBAAgB,EAAE,MAAM;CACzB,C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AAI,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,gBAAgB,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;QACjH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,SAAS,OAAO,CAAC,QAAyB;QACxC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QACvC,IAAI,CAAC,KAAK;YAAE,OAAO,KAAK,CAAC;QACzB,YAAY,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QAClC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAC5B,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACxB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,SAAS,SAAS,CAAC,MAAa;QAC9B,KAAK,MAAM,CAAC,EAAE,KAAK,CAAC,IAAI,OAAO,EAAE,CAAC;YAChC,YAAY,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;YAClC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACvB,CAAC;QACD,OAAO,CAAC,KAAK,EAAE,CAAC;IAClB,CAAC;IAED,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,UAAU,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;AACjH,CAAC"}
@@ -0,0 +1,22 @@
1
+ export type JsonRpcId = string | number;
2
+ export interface JsonRpcResponse {
3
+ jsonrpc: '2.0';
4
+ id: JsonRpcId;
5
+ result?: unknown;
6
+ error?: JsonRpcError;
7
+ }
8
+ export interface JsonRpcError {
9
+ code: number;
10
+ message: string;
11
+ data?: unknown;
12
+ }
13
+ export interface PendingEntry {
14
+ id: JsonRpcId;
15
+ registeredAt: number;
16
+ timeoutMs: number;
17
+ timeoutHandle: NodeJS.Timeout;
18
+ resolve: (response: JsonRpcResponse) => void;
19
+ reject: (error: Error) => void;
20
+ }
21
+ export type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 'reconnecting' | 'closed';
22
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAmBA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;AAExC,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,SAAS,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,YAAY,CAAC;CACtB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,SAAS,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC,OAAO,CAAC;IAC9B,OAAO,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,IAAI,CAAC;IAC7C,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAChC;AAED,MAAM,MAAM,eAAe,GAAG,cAAc,GAAG,YAAY,GAAG,WAAW,GAAG,cAAc,GAAG,QAAQ,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1,16 @@
1
+ // Copyright 2026 Raman Marozau <raman@worktif.com>
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ export {};
16
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,sCAAsC;AACtC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC"}
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "acp-chat",
3
+ "version": "0.2.0",
4
+ "description": "ACP Chat — agent-to-agent dialogue over TCP/Unix socket using the ACP protocol.",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "bin": {
9
+ "acp-chat": "dist/cli.js"
10
+ },
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "clean": "rm -rf dist",
14
+ "prepublishOnly": "npm run build"
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "README.md"
19
+ ],
20
+ "keywords": [
21
+ "acp",
22
+ "agent",
23
+ "chat",
24
+ "stdio-bus",
25
+ "json-rpc"
26
+ ],
27
+ "license": "Apache-2.0",
28
+ "author": "Raman Marozau <raman@worktif.com>",
29
+ "engines": {
30
+ "node": ">=18"
31
+ },
32
+ "devDependencies": {
33
+ "typescript": "^5.0.0",
34
+ "@types/node": "^20.0.0"
35
+ }
36
+ }