@qlairoslabs/acp-client 0.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/LICENSE +21 -0
- package/README.md +222 -0
- package/package.json +62 -0
- package/src/adapters.ts +52 -0
- package/src/agent-client.ts +50 -0
- package/src/agent-session.ts +212 -0
- package/src/capabilities.ts +104 -0
- package/src/cli/index.ts +112 -0
- package/src/client.ts +613 -0
- package/src/config-options.ts +65 -0
- package/src/controller.ts +446 -0
- package/src/degraded/emulator.ts +77 -0
- package/src/degraded/extract.ts +87 -0
- package/src/degraded/index.ts +18 -0
- package/src/degraded/pty-client.ts +304 -0
- package/src/degraded/pty-transport.ts +130 -0
- package/src/errors.ts +28 -0
- package/src/index.ts +81 -0
- package/src/logger.ts +65 -0
- package/src/parser/index.ts +4 -0
- package/src/parser/ollama.ts +26 -0
- package/src/parser/types.ts +20 -0
- package/src/repl/colors.ts +15 -0
- package/src/repl/commands.ts +435 -0
- package/src/repl/index.ts +9 -0
- package/src/repl/repl.ts +312 -0
- package/src/session-manager.ts +125 -0
- package/src/session-store.ts +96 -0
- package/src/transport/acp-transport.ts +193 -0
- package/src/types.ts +112 -0
- package/src/updates.ts +45 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// Capabilities mirror the protocol's nested structure directly (see SPEC.md
|
|
2
|
+
// "Capabilities"). We do NOT flatten — the nesting maps cleanly to what UIs gate on,
|
|
3
|
+
// e.g. `capabilities.agent.auth.logout != null` → show the logout button.
|
|
4
|
+
//
|
|
5
|
+
// A null/omitted capability means UNSUPPORTED (per spec: omitted == unsupported). This
|
|
6
|
+
// is what lets callers gate behavior in advance instead of failing at call time.
|
|
7
|
+
|
|
8
|
+
import type * as schema from "@agentclientprotocol/sdk";
|
|
9
|
+
|
|
10
|
+
/** An auth method the agent advertises in initialize — pass `id` to authenticate(). */
|
|
11
|
+
export interface AuthMethod {
|
|
12
|
+
id: string;
|
|
13
|
+
name: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface Capabilities {
|
|
18
|
+
/** Protocol version the agent agreed on. */
|
|
19
|
+
protocolVersion: number;
|
|
20
|
+
/** Agent name/title/version, if provided. */
|
|
21
|
+
agentInfo?: { name?: string; title?: string; version?: string };
|
|
22
|
+
/** What WE told the agent we support (echoed back for convenience). */
|
|
23
|
+
client: ClientCapabilities;
|
|
24
|
+
/** What the AGENT reports it supports — discovered from initialize. */
|
|
25
|
+
agent: AgentCapabilities;
|
|
26
|
+
/** Auth methods the agent advertises. Empty ≠ "authenticated" — auth state is opaque. */
|
|
27
|
+
authMethods: AuthMethod[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface ClientCapabilities {
|
|
31
|
+
fs: { readTextFile: boolean; writeTextFile: boolean };
|
|
32
|
+
terminal: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface AgentCapabilities {
|
|
36
|
+
loadSession: boolean;
|
|
37
|
+
promptCapabilities: {
|
|
38
|
+
image: boolean;
|
|
39
|
+
audio: boolean;
|
|
40
|
+
embeddedContext: boolean;
|
|
41
|
+
};
|
|
42
|
+
mcpCapabilities: {
|
|
43
|
+
http: boolean;
|
|
44
|
+
sse: boolean;
|
|
45
|
+
};
|
|
46
|
+
/** Null when the agent does not advertise logout. */
|
|
47
|
+
auth: { logout: boolean } | null;
|
|
48
|
+
/** Optional session-lifecycle methods, each true only if the agent advertises it. */
|
|
49
|
+
sessionCapabilities: {
|
|
50
|
+
list: boolean;
|
|
51
|
+
delete: boolean;
|
|
52
|
+
close: boolean;
|
|
53
|
+
fork: boolean;
|
|
54
|
+
resume: boolean;
|
|
55
|
+
additionalDirectories: boolean;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** The client capabilities we always advertise. Kept in one place. */
|
|
60
|
+
export const CLIENT_CAPABILITIES: ClientCapabilities = {
|
|
61
|
+
fs: { readTextFile: true, writeTextFile: true },
|
|
62
|
+
terminal: true,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/** Parse a raw InitializeResponse into our nested Capabilities model. */
|
|
66
|
+
export function parseCapabilities(init: schema.InitializeResponse): Capabilities {
|
|
67
|
+
const a = (init.agentCapabilities ?? {}) as Record<string, any>;
|
|
68
|
+
const prompt = a.promptCapabilities ?? {};
|
|
69
|
+
const mcp = a.mcpCapabilities ?? {};
|
|
70
|
+
const session = a.sessionCapabilities ?? {};
|
|
71
|
+
const agentInfo = (init as any).agentInfo as Capabilities["agentInfo"] | undefined;
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
protocolVersion: init.protocolVersion,
|
|
75
|
+
agentInfo,
|
|
76
|
+
client: CLIENT_CAPABILITIES,
|
|
77
|
+
agent: {
|
|
78
|
+
loadSession: a.loadSession === true,
|
|
79
|
+
promptCapabilities: {
|
|
80
|
+
image: prompt.image === true,
|
|
81
|
+
audio: prompt.audio === true,
|
|
82
|
+
embeddedContext: prompt.embeddedContext === true,
|
|
83
|
+
},
|
|
84
|
+
mcpCapabilities: {
|
|
85
|
+
http: mcp.http === true,
|
|
86
|
+
sse: mcp.sse === true,
|
|
87
|
+
},
|
|
88
|
+
auth: a.auth != null ? { logout: a.auth.logout != null } : null,
|
|
89
|
+
sessionCapabilities: {
|
|
90
|
+
list: session.list != null,
|
|
91
|
+
delete: session.delete != null,
|
|
92
|
+
close: session.close != null,
|
|
93
|
+
fork: session.fork != null,
|
|
94
|
+
resume: session.resume != null,
|
|
95
|
+
additionalDirectories: session.additionalDirectories != null,
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
authMethods: ((init as any).authMethods ?? []).map((m: Record<string, any>) => ({
|
|
99
|
+
id: m.id,
|
|
100
|
+
name: m.name ?? m.id,
|
|
101
|
+
description: m.description ?? undefined,
|
|
102
|
+
})),
|
|
103
|
+
};
|
|
104
|
+
}
|
package/src/cli/index.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
// Thin CLI entry — arg parsing + wiring only. Imports the public library like any
|
|
3
|
+
// external caller and owns NO protocol logic. The interactive loop lives in ./repl.ts.
|
|
4
|
+
// See SPEC.md "library first, CLI second".
|
|
5
|
+
//
|
|
6
|
+
// Usage:
|
|
7
|
+
// acp-lib chat [SESSION_ID] [--adapter kimi] [--exec "docker exec -i <ctr>"]
|
|
8
|
+
// [--cwd /workspace] [--approve] [--verbose] [--debug]
|
|
9
|
+
// [--no-activity] [--degraded]
|
|
10
|
+
//
|
|
11
|
+
// activity (thinking/tool markers) shows by DEFAULT; --no-activity disables it.
|
|
12
|
+
// --verbose (-v): lifecycle summaries (connect, session_new, prompt_end)
|
|
13
|
+
// --debug (-d): the above PLUS raw protocol payloads (initialize/prompt/session_update)
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
AgentController,
|
|
17
|
+
ADAPTERS,
|
|
18
|
+
createConsoleLogger,
|
|
19
|
+
type AdapterPreset,
|
|
20
|
+
} from "../index.ts";
|
|
21
|
+
import { createAgentCommands, runRepl } from "../repl/index.ts";
|
|
22
|
+
import { DIM, colorEnabled, paint } from "../repl/colors.ts";
|
|
23
|
+
|
|
24
|
+
interface Args {
|
|
25
|
+
command: string;
|
|
26
|
+
sessionId?: string;
|
|
27
|
+
adapter: AdapterPreset;
|
|
28
|
+
execPrefix: string[];
|
|
29
|
+
cwd?: string;
|
|
30
|
+
degraded: boolean;
|
|
31
|
+
approve: boolean;
|
|
32
|
+
verbose: boolean;
|
|
33
|
+
debug: boolean;
|
|
34
|
+
activity: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function parseArgs(argv: string[]): Args {
|
|
38
|
+
const a: Args = {
|
|
39
|
+
command: argv[0] ?? "chat",
|
|
40
|
+
adapter: "kimi",
|
|
41
|
+
execPrefix: [],
|
|
42
|
+
degraded: false,
|
|
43
|
+
approve: false,
|
|
44
|
+
verbose: false,
|
|
45
|
+
debug: false,
|
|
46
|
+
activity: true,
|
|
47
|
+
};
|
|
48
|
+
for (let i = 1; i < argv.length; i++) {
|
|
49
|
+
const arg = argv[i];
|
|
50
|
+
if (arg === "--adapter") a.adapter = argv[++i] as AdapterPreset;
|
|
51
|
+
else if (arg === "--exec") a.execPrefix = (argv[++i] ?? "").split(" ").filter(Boolean);
|
|
52
|
+
else if (arg === "--cwd") a.cwd = argv[++i];
|
|
53
|
+
else if (arg === "--degraded") a.degraded = true;
|
|
54
|
+
else if (arg === "--approve") a.approve = true;
|
|
55
|
+
else if (arg === "--verbose" || arg === "-v") a.verbose = true;
|
|
56
|
+
else if (arg === "--debug" || arg === "-d") a.debug = true;
|
|
57
|
+
else if (arg === "--no-activity" || arg === "--disable-activity") a.activity = false;
|
|
58
|
+
else if (arg && !arg.startsWith("--")) a.sessionId = arg;
|
|
59
|
+
}
|
|
60
|
+
return a;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function chat(args: Args): Promise<void> {
|
|
64
|
+
// Logging levels:
|
|
65
|
+
// default → warn (quiet — only warnings/errors)
|
|
66
|
+
// --verbose → info (lifecycle summaries: connect, session_new, prompt_end, …)
|
|
67
|
+
// --debug → debug (the above PLUS full protocol payloads + raw session updates)
|
|
68
|
+
const minLevel = args.debug ? "debug" : args.verbose ? "info" : "warn";
|
|
69
|
+
const logger = createConsoleLogger({ minLevel });
|
|
70
|
+
|
|
71
|
+
const controller = new AgentController({
|
|
72
|
+
adapter: ADAPTERS[args.adapter],
|
|
73
|
+
adapterId: args.adapter,
|
|
74
|
+
mode: args.degraded ? "degraded" : "normal",
|
|
75
|
+
execPrefix: args.execPrefix,
|
|
76
|
+
cwd: args.cwd,
|
|
77
|
+
sessionId: args.sessionId,
|
|
78
|
+
defaultPermission: args.approve ? "approve" : "cancel",
|
|
79
|
+
logger,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const { sessionId, resumed } = await controller.start();
|
|
83
|
+
const label = ADAPTERS[args.adapter].displayName ?? args.adapter;
|
|
84
|
+
const intro = controller.isDegraded
|
|
85
|
+
? `degraded (pty) session (${label}) — no ACP capabilities · /exit to quit, Ctrl-C to interrupt`
|
|
86
|
+
: `${resumed ? "resumed" : "new"} session ${sessionId} (${label}) — ` +
|
|
87
|
+
`/exit to quit, Ctrl-C to interrupt`;
|
|
88
|
+
|
|
89
|
+
const color = colorEnabled(process.stderr);
|
|
90
|
+
const note = (s: string) => process.stderr.write(paint(color, DIM, s) + "\n");
|
|
91
|
+
|
|
92
|
+
const commands = createAgentCommands({ client: controller, note, color });
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
await runRepl(controller, {
|
|
96
|
+
activity: args.activity,
|
|
97
|
+
// Suppress the spinner under --debug: raw session_update lines would fight its \r.
|
|
98
|
+
spinner: !args.debug,
|
|
99
|
+
intro,
|
|
100
|
+
onSlashCommand: commands.onSlashCommand,
|
|
101
|
+
});
|
|
102
|
+
} finally {
|
|
103
|
+
await controller.stop();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const args = parseArgs(process.argv.slice(2));
|
|
108
|
+
if (args.command !== "chat") {
|
|
109
|
+
console.error(`unknown command: ${args.command}`);
|
|
110
|
+
process.exit(1);
|
|
111
|
+
}
|
|
112
|
+
await chat(args);
|