@noetic-tools/acp 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/server.js ADDED
@@ -0,0 +1,65 @@
1
+ /**
2
+ * The Node stdio entry for the server direction — the inverse of `./stdio`,
3
+ * which spawns a child and binds to *its* stdio: `serveAcp` binds a served
4
+ * harness to the **current process's** stdin/stdout, so an ACP client (Zed,
5
+ * another editor, a Noetic step) that launched this process as its agent can
6
+ * drive the harness.
7
+ *
8
+ * Lives behind the `@noetic-tools/acp/server` subpath so the package's main
9
+ * entry stays runtime-neutral.
10
+ *
11
+ * ```ts
12
+ * import { AgentHarness } from '@noetic-tools/core';
13
+ * import { serveAcp } from '@noetic-tools/acp/server';
14
+ *
15
+ * const harness = new AgentHarness({ name: 'my-agent', agentGraph, tools, params: {} });
16
+ * await serveAcp(harness).closed;
17
+ * ```
18
+ */
19
+ import { Readable, Writable } from 'node:stream';
20
+ import { frameworkCast } from '@noetic-tools/types';
21
+ import { AgentSideConnection, ndJsonStream } from '@zed-industries/agent-client-protocol';
22
+ import { toAcpAgent } from './serve.js';
23
+ /**
24
+ * Serve a harness as an ACP agent over the current process's stdio. `await`
25
+ * the returned handle's `closed` to keep the process alive until the client
26
+ * disconnects.
27
+ * @public
28
+ */
29
+ export function serveAcp(source, options = {}) {
30
+ let agent;
31
+ // Constructing the connection registers its message pump on the streams; no
32
+ // further reference is needed to keep it running — process.stdin holds the
33
+ // event loop open until it ends or close() destroys it.
34
+ new AgentSideConnection((conn) => {
35
+ agent = toAcpAgent(source, options)(conn);
36
+ return agent;
37
+ }, ndJsonStream(frameworkCast(Writable.toWeb(process.stdout)), frameworkCast(Readable.toWeb(process.stdin))));
38
+ let resolveClosed;
39
+ const closed = new Promise((resolve) => {
40
+ resolveClosed = resolve;
41
+ });
42
+ let closing = false;
43
+ const close = async () => {
44
+ if (closing) {
45
+ return closed;
46
+ }
47
+ closing = true;
48
+ await agent?.dispose().catch(() => undefined);
49
+ // Tear the transport down: ending stdin ends the connection's read loop,
50
+ // so a close() while the client is still attached doesn't leave the
51
+ // process parked on a live pipe.
52
+ process.stdin.destroy();
53
+ resolveClosed();
54
+ };
55
+ process.stdin.once('close', () => {
56
+ void close();
57
+ });
58
+ process.stdin.once('end', () => {
59
+ void close();
60
+ });
61
+ return {
62
+ closed,
63
+ close,
64
+ };
65
+ }
@@ -6,6 +6,7 @@
6
6
  * both directions — capability negotiation, session updates, permission
7
7
  * round-trips, `fs/*` and `terminal/*` callbacks — without spawning a process.
8
8
  */
9
+ import { frameworkCast } from '@noetic-tools/types';
9
10
  import { AgentSideConnection, ndJsonStream } from '@zed-industries/agent-client-protocol';
10
11
  function endpoint(readable, writable) {
11
12
  let closed = false;
@@ -45,15 +46,27 @@ export function createAcpLoopbackPair() {
45
46
  export function loopbackTransport(toAgent) {
46
47
  return async () => {
47
48
  const pair = createAcpLoopbackPair();
49
+ let agent;
48
50
  // The connection registers its own message pump on construction; holding
49
51
  // the reference keeps it alive for the life of the transport.
50
- const connection = new AgentSideConnection(toAgent, ndJsonStream(pair.agent.writable, pair.agent.readable));
52
+ const connection = new AgentSideConnection((conn) => {
53
+ agent = toAgent(conn);
54
+ return agent;
55
+ }, ndJsonStream(pair.agent.writable, pair.agent.readable));
51
56
  return {
52
57
  readable: pair.client.readable,
53
58
  writable: pair.client.writable,
54
59
  async close() {
55
60
  void connection;
56
61
  await pair.client.close();
62
+ // A served Noetic agent (and any agent following the same shape)
63
+ // exposes dispose() to cancel its live sessions; without this, the
64
+ // in-process path would leave sessions running after the client is
65
+ // gone — only the stdio entry's stdin handlers would ever clean up.
66
+ const disposable = frameworkCast(agent);
67
+ if (typeof disposable?.dispose === 'function') {
68
+ await disposable.dispose().catch(() => undefined);
69
+ }
57
70
  },
58
71
  };
59
72
  };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@noetic-tools/acp",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "type": "module",
5
- "description": "Agent Client Protocol client for Noetic. Drives any ACP-speaking coding agent (Claude Code, Codex, Gemini CLI, …) as a step, serving fs/*, terminal/*, and permission requests from Noetic's own adapters.",
5
+ "description": "Both directions of the Agent Client Protocol for Noetic. Drives any ACP-speaking coding agent (Claude Code, Codex, Gemini CLI, …) as a step, and serves a Noetic harness as an ACP agent for editors like Zed (toAcpAgent / serveAcp).",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
8
8
  "type": "git",
@@ -33,6 +33,10 @@
33
33
  "types": "./dist/stdio.d.ts",
34
34
  "default": "./dist/stdio.js"
35
35
  },
36
+ "./server": {
37
+ "types": "./dist/server.d.ts",
38
+ "default": "./dist/server.js"
39
+ },
36
40
  "./package.json": "./package.json"
37
41
  },
38
42
  "files": [
@@ -44,13 +48,15 @@
44
48
  "access": "public"
45
49
  },
46
50
  "devDependencies": {
47
- "bun-types": "latest"
51
+ "bun-types": "latest",
52
+ "@noetic-tools/core": "workspace:*",
53
+ "@noetic-tools/context": "workspace:*"
48
54
  },
49
55
  "peerDependencies": {
50
56
  "zod": "^4.0.0"
51
57
  },
52
58
  "dependencies": {
53
- "@noetic-tools/types": "^3.2.2",
59
+ "@noetic-tools/types": "^3.3.0",
54
60
  "@zed-industries/agent-client-protocol": "^0.4.5",
55
61
  "zod": "^4.0.0"
56
62
  },