@qlairoslabs/acp-client 0.4.2 → 0.4.3

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/CONSUMER_GUIDE.md CHANGED
@@ -67,6 +67,7 @@ can supply any `Adapter` object.
67
67
  const adapters: Record<string, Adapter> = {
68
68
  codex: ADAPTERS.codex,
69
69
  claude: ADAPTERS.claude,
70
+ pi: ADAPTERS.pi,
70
71
  internal: {
71
72
  command: ["internal-agent", "--acp"],
72
73
  ptyCommand: ["internal-agent"],
@@ -84,6 +85,15 @@ function resolveAdapter(adapterId: string): Adapter {
84
85
  The catalog stores `adapterId`, not executable configuration. This resolver therefore
85
86
  belongs to the consumer.
86
87
 
88
+ Presets do not encode a provider's features. After the process starts, the library
89
+ discovers capabilities, authentication methods, configuration, sessions, and harness
90
+ commands through ACP. The Pi preset targets `@automatalabs/pi-acp`, which embeds Pi through
91
+ its published SDK and installs the `pi-acp` executable. The native `pi` command is used
92
+ only for interactive PTY mode.
93
+
94
+ Install the preset executable globally with `npm install -g @automatalabs/pi-acp`, or use
95
+ `{ command: ["npx", "-y", "@automatalabs/pi-acp"] }` as a custom adapter.
96
+
87
97
  ## Create the catalog and live-session registry
88
98
 
89
99
  `SessionManager` is a metadata catalog, not a registry of running objects and not a
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # @qlairoslabs/acp-client
2
2
 
3
3
  An embeddable, model-agnostic **Agent Client Protocol (ACP)** client: talk to AI coding
4
- agents (Codex, Claude, Kimi, Gemini, Copilot, OpenCode, …) over JSON-RPC 2.0, with a
4
+ agents (Codex, Claude, Kimi, Pi, Gemini, Copilot, OpenCode, …) over JSON-RPC 2.0, with a
5
5
  **degraded PTY fallback** for agents that don't speak ACP.
6
6
 
7
7
  ```ts
@@ -61,7 +61,7 @@ bun add -g @qlairoslabs/acp-client
61
61
  | **`AgentController`** | The control plane for **one** agent process: start/stop, prompt, interrupt, switch sessions, swap mode (normal ⇄ degraded), introspect capabilities & config. |
62
62
  | **`AgentSession`** | A **durable conversation** with a stable identity that survives reconnects and mode-swaps. Wraps an `AgentController` and (optionally) records itself to a catalog. The front face for consumers that want persistence. |
63
63
  | **`SessionManager` + `SessionStore`** | The session **catalog**: routing metadata (which adapter/mode/cwd a session belongs to), *not* conversation content. Merges your catalog with the agent's live `session/list`. Ships a `FileSessionStore`; inject your own (e.g. a database) for custom backends. |
64
- | **Adapter** | Just how to *launch* an agent: the spawn command. `ADAPTERS` has presets (`codex`, `claude`, `kimi`, `gemini`, `copilot`, `opencode`); you can also pass a raw `{ command: [...] }`. |
64
+ | **Adapter** | Just how to *launch* an agent: the spawn command. `ADAPTERS` has convenience presets (`codex`, `claude`, `kimi`, `pi`, `gemini`, `copilot`, `opencode`); you can also pass a raw `{ command: [...] }`. Capabilities and commands are discovered after ACP initialization. |
65
65
  | **Mode** | `"normal"` (real ACP over JSON-RPC) or `"degraded"` (drive the native CLI through a PTY and parse it). Both implement the same `AgentClient` output contract. |
66
66
 
67
67
  ---
@@ -464,6 +464,9 @@ A thin wrapper over the library is exposed as `acp-client`:
464
464
  acp-client chat # new chat with the default adapter
465
465
  acp-client chat <SESSION_ID> # resume a session
466
466
  acp-client chat --adapter codex # pick an adapter
467
+ acp-client chat --adapter pi # @automatalabs/pi-acp (the pi-acp binary)
468
+ acp-client chat --adapter private --adapter-command '["private-agent","--acp"]'
469
+ acp-client chat --adapter private --adapter-command private-acp --pty-command private-agent
467
470
  acp-client chat --exec "docker exec -i my-container" # talk to an agent in a container
468
471
  acp-client chat --cwd /workspace --approve # auto-approve tool permissions
469
472
  acp-client chat --degraded # force degraded (PTY) mode
@@ -473,6 +476,24 @@ acp-client chat --wire[=FILE] # dump every raw protocol line (stderr, or
473
476
 
474
477
  Activity markers (thinking/tool) show by default; `--no-activity` disables them.
475
478
 
479
+ Presets are launch shortcuts, not provider definitions. For a custom harness,
480
+ `--adapter-command` accepts either one executable or a JSON argv array; `--pty-command`
481
+ optionally supplies its interactive/degraded counterpart, and `--adapter-name` sets a
482
+ display label. After launch, auth methods, capabilities, configuration, session support,
483
+ and harness commands are discovered over ACP exactly as they are for a preset.
484
+
485
+ The Pi preset expects the `pi-acp` executable installed by:
486
+
487
+ ```bash
488
+ npm install -g @automatalabs/pi-acp
489
+ ```
490
+
491
+ Alternatively, run it without a global install as a custom adapter:
492
+
493
+ ```bash
494
+ acp-client chat --adapter pi --adapter-command '["npx","-y","@automatalabs/pi-acp"]'
495
+ ```
496
+
476
497
  ---
477
498
 
478
499
  ## Package exports
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qlairoslabs/acp-client",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "Embeddable Agent Client Protocol (ACP) client library with degraded PTY fallback.",
5
5
  "type": "module",
6
6
  "module": "src/index.ts",
package/src/adapters.ts CHANGED
@@ -52,6 +52,9 @@ export const ADAPTERS = {
52
52
  },
53
53
  // verified — @agentclientprotocol/codex-acp. The `codex` CLI has no `acp` subcommand.
54
54
  codex: { command: ["codex-acp"], ptyCommand: ["codex"], displayName: "Codex" },
55
+ // @automatalabs/pi-acp embeds Pi through its SDK and publishes the `pi-acp` binary.
56
+ // Pi itself remains the interactive PTY command for bridge/degraded mode.
57
+ pi: { command: ["pi-acp"], ptyCommand: ["pi"], displayName: "Pi" },
55
58
  // Below: from each project's docs, not spawned here. Correct at time of writing, unverified.
56
59
  gemini: { command: ["gemini", "--acp", "--stdio"], ptyCommand: ["gemini"], displayName: "Gemini" },
57
60
  copilot: { command: ["copilot", "--acp", "--stdio"], ptyCommand: ["copilot"], displayName: "Copilot" },
@@ -0,0 +1,69 @@
1
+ import { basename } from "node:path";
2
+ import { ADAPTERS, type Adapter } from "../adapters.ts";
3
+
4
+ export interface CliAdapterSelection {
5
+ /** Preset key, or the stable id assigned to a custom adapter. */
6
+ adapterId?: string;
7
+ /** Explicit ACP launch argv. When present, this takes precedence over presets. */
8
+ command?: string[];
9
+ /** Optional interactive launch argv for degraded mode and bridge. */
10
+ ptyCommand?: string[];
11
+ /** Optional custom display label. */
12
+ displayName?: string;
13
+ }
14
+
15
+ export interface ResolvedCliAdapter {
16
+ adapterId: string;
17
+ adapter: Adapter;
18
+ }
19
+
20
+ /**
21
+ * Parse one CLI command value. A plain value represents one executable; commands with
22
+ * arguments use a JSON string array so paths and arguments containing spaces stay exact.
23
+ */
24
+ export function parseCommandArg(value: string | undefined, flag: string): string[] {
25
+ if (!value?.trim()) throw new Error(`${flag} requires an executable or JSON argv array`);
26
+ const trimmed = value.trim();
27
+ if (!trimmed.startsWith("[")) return [trimmed];
28
+
29
+ let parsed: unknown;
30
+ try {
31
+ parsed = JSON.parse(trimmed);
32
+ } catch (error) {
33
+ throw new Error(`${flag} must be valid JSON: ${String(error)}`);
34
+ }
35
+ if (
36
+ !Array.isArray(parsed) ||
37
+ parsed.length === 0 ||
38
+ parsed.some((part) => typeof part !== "string" || part.length === 0)
39
+ ) {
40
+ throw new Error(`${flag} must be a non-empty JSON array of non-empty strings`);
41
+ }
42
+ return parsed;
43
+ }
44
+
45
+ /** Resolve a built-in preset or construct the custom adapter supplied by the CLI user. */
46
+ export function resolveCliAdapter(selection: CliAdapterSelection): ResolvedCliAdapter {
47
+ if (selection.command) {
48
+ if (selection.command.length === 0) throw new Error("custom adapter command cannot be empty");
49
+ const adapterId = selection.adapterId?.trim() || basename(selection.command[0]!) || "custom";
50
+ return {
51
+ adapterId,
52
+ adapter: {
53
+ command: [...selection.command],
54
+ ...(selection.ptyCommand ? { ptyCommand: [...selection.ptyCommand] } : {}),
55
+ ...(selection.displayName ? { displayName: selection.displayName } : {}),
56
+ },
57
+ };
58
+ }
59
+
60
+ const adapterId = selection.adapterId?.trim() || "kimi";
61
+ if (!(adapterId in ADAPTERS)) {
62
+ throw new Error(
63
+ `unknown adapter preset: ${adapterId}; known presets: ${Object.keys(ADAPTERS).join(", ")}; ` +
64
+ "use --adapter-command for a custom ACP harness",
65
+ );
66
+ }
67
+ const adapter = ADAPTERS[adapterId as keyof typeof ADAPTERS];
68
+ return { adapterId, adapter };
69
+ }
package/src/cli/index.ts CHANGED
@@ -4,9 +4,11 @@
4
4
  // See SPEC.md "library first, CLI second".
5
5
  //
6
6
  // Usage:
7
- // acp-lib chat [SESSION_ID] [--adapter kimi] [--exec "docker exec -i <ctr>"]
7
+ // acp-client chat [SESSION_ID] [--adapter kimi] [--exec "docker exec -i <ctr>"]
8
8
  // [--cwd /workspace] [--approve] [--verbose] [--debug]
9
9
  // [--no-activity] [--degraded] [--wire[=FILE]]
10
+ // acp-client chat [--adapter ID] --adapter-command '["agent","--acp"]'
11
+ // [--pty-command '["agent"]'] [--adapter-name "My Agent"]
10
12
  //
11
13
  // activity (thinking/tool markers) shows by DEFAULT; --no-activity disables it.
12
14
  // --verbose (-v): lifecycle summaries (connect, session_new, prompt_end)
@@ -16,18 +18,21 @@
16
18
 
17
19
  import {
18
20
  AgentController,
19
- ADAPTERS,
20
21
  createConsoleLogger,
21
22
  createWireLog,
22
- type AdapterPreset,
23
+ type Adapter,
23
24
  } from "../index.ts";
24
25
  import { createControllerCommands, runRepl } from "../repl/index.ts";
25
26
  import { DIM, colorEnabled, paint } from "../repl/colors.ts";
27
+ import { parseCommandArg, resolveCliAdapter } from "./adapter.ts";
26
28
 
27
29
  interface Args {
28
30
  command: string;
29
31
  sessionId?: string;
30
- adapter: AdapterPreset;
32
+ adapterId?: string;
33
+ adapterCommand?: string[];
34
+ ptyCommand?: string[];
35
+ adapterName?: string;
31
36
  execPrefix: string[];
32
37
  cwd?: string;
33
38
  degraded: boolean;
@@ -42,7 +47,6 @@ interface Args {
42
47
  function parseArgs(argv: string[]): Args {
43
48
  const a: Args = {
44
49
  command: argv[0] ?? "chat",
45
- adapter: "kimi",
46
50
  execPrefix: [],
47
51
  degraded: false,
48
52
  approve: false,
@@ -52,7 +56,14 @@ function parseArgs(argv: string[]): Args {
52
56
  };
53
57
  for (let i = 1; i < argv.length; i++) {
54
58
  const arg = argv[i];
55
- if (arg === "--adapter") a.adapter = argv[++i] as AdapterPreset;
59
+ if (arg === "--adapter") a.adapterId = argv[++i];
60
+ else if (arg === "--adapter-command") {
61
+ a.adapterCommand = parseCommandArg(argv[++i], "--adapter-command");
62
+ }
63
+ else if (arg === "--pty-command") {
64
+ a.ptyCommand = parseCommandArg(argv[++i], "--pty-command");
65
+ }
66
+ else if (arg === "--adapter-name") a.adapterName = argv[++i];
56
67
  else if (arg === "--exec") a.execPrefix = (argv[++i] ?? "").split(" ").filter(Boolean);
57
68
  else if (arg === "--cwd") a.cwd = argv[++i];
58
69
  else if (arg === "--degraded") a.degraded = true;
@@ -85,9 +96,16 @@ async function chat(args: Args): Promise<void> {
85
96
  : createWireLog({ path: args.wire });
86
97
  if (args.wire) process.stderr.write(`wire log: ${args.wire}\n`);
87
98
 
99
+ const resolved = resolveCliAdapter({
100
+ adapterId: args.adapterId,
101
+ command: args.adapterCommand,
102
+ ptyCommand: args.ptyCommand,
103
+ displayName: args.adapterName,
104
+ });
105
+ const adapter: Adapter = resolved.adapter;
88
106
  const controller = new AgentController({
89
- adapter: ADAPTERS[args.adapter],
90
- adapterId: args.adapter,
107
+ adapter,
108
+ adapterId: resolved.adapterId,
91
109
  mode: args.degraded ? "degraded" : "normal",
92
110
  execPrefix: args.execPrefix,
93
111
  cwd: args.cwd,
@@ -98,7 +116,7 @@ async function chat(args: Args): Promise<void> {
98
116
  });
99
117
 
100
118
  const { sessionId, resumed } = await controller.start();
101
- const label = ADAPTERS[args.adapter].displayName ?? args.adapter;
119
+ const label = adapter.displayName ?? resolved.adapterId;
102
120
  const intro = controller.isDegraded
103
121
  ? `degraded (pty) session (${label}) — no ACP capabilities · /exit to quit, Ctrl-C to interrupt`
104
122
  : `${resumed ? "resumed" : "new"} session ${sessionId} (${label}) — ` +
@@ -107,7 +125,12 @@ async function chat(args: Args): Promise<void> {
107
125
  const color = colorEnabled(process.stderr);
108
126
  const note = (s: string) => process.stderr.write(paint(color, DIM, s) + "\n");
109
127
 
110
- const commands = createControllerCommands({ client: controller, note, color });
128
+ const commands = createControllerCommands({
129
+ client: controller,
130
+ note,
131
+ color,
132
+ adapterId: resolved.adapterId,
133
+ });
111
134
 
112
135
  try {
113
136
  await runRepl(controller, {