@qlairoslabs/acp-client 0.7.0 → 0.7.1
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 +40 -0
- package/package.json +1 -1
- package/src/command-descriptors.ts +22 -0
- package/src/controller.ts +74 -37
- package/src/index.ts +1 -0
- package/src/repl/agent-session-commands.ts +74 -1
- package/src/repl/commands.ts +1 -1
- package/src/repl/index.ts +7 -1
package/CONSUMER_GUIDE.md
CHANGED
|
@@ -60,6 +60,7 @@ Interactive helpers are a separate entry point:
|
|
|
60
60
|
import {
|
|
61
61
|
createAgentSessionCommands,
|
|
62
62
|
dispatchReplInput,
|
|
63
|
+
getAgentSessionCommands,
|
|
63
64
|
parseReplInput,
|
|
64
65
|
runAgentSessionRepl,
|
|
65
66
|
} from "@qlairoslabs/acp-client/repl";
|
|
@@ -453,6 +454,45 @@ ACP sends a harness command as a prompt. `executeInternalSessionCommand()` makes
|
|
|
453
454
|
explicit and routes it through the logical session's queue, lifecycle, transcript, and
|
|
454
455
|
metering machinery. Advertisement is discovery rather than an allow-list.
|
|
455
456
|
|
|
457
|
+
## Discover commands for a UI
|
|
458
|
+
|
|
459
|
+
The library exposes command metadata separately for the two local operation layers. A UI
|
|
460
|
+
bound to one stable logical session can read the AgentSession command registry:
|
|
461
|
+
|
|
462
|
+
```ts
|
|
463
|
+
const clientCommands = getAgentSessionCommands(session);
|
|
464
|
+
|
|
465
|
+
for (const command of clientCommands) {
|
|
466
|
+
renderCommand({
|
|
467
|
+
name: command.id,
|
|
468
|
+
description: command.description,
|
|
469
|
+
arguments: command.arguments,
|
|
470
|
+
disabled: !command.available,
|
|
471
|
+
disabledReason: command.unavailableReason,
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
This registry contains `/handoff`, `/bridge`, and the introspection commands implemented
|
|
477
|
+
by `createAgentSessionCommands()`. Its availability is recomputed from current session
|
|
478
|
+
state. `/exit` is intentionally absent because it belongs to a particular REPL, not to an
|
|
479
|
+
`AgentSession`.
|
|
480
|
+
|
|
481
|
+
The lower-level controller exposes its own dynamically negotiated registry:
|
|
482
|
+
|
|
483
|
+
```ts
|
|
484
|
+
for (const command of controller.getCommands()) {
|
|
485
|
+
console.log(command.id, command.description, command.arguments);
|
|
486
|
+
if (!command.available) console.log(command.unavailableReason);
|
|
487
|
+
}
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
These are provider-thread and transport controls such as `/load`, `/fork`, `/config`, and
|
|
491
|
+
`/degrade`; they are not aliases for logical-session operations. Harness-advertised
|
|
492
|
+
commands remain the third source in `session.internalSessionCommands` and are invoked
|
|
493
|
+
explicitly with `executeInternalSessionCommand()`. A consumer can merge all three sources
|
|
494
|
+
for display while retaining their origin so dispatch never crosses layers accidentally.
|
|
495
|
+
|
|
456
496
|
## Configure transcripts
|
|
457
497
|
|
|
458
498
|
Transcripts and audit logs are separate artifacts:
|
package/package.json
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** One positional argument accepted by a discoverable local command. */
|
|
2
|
+
export interface CommandArgumentDescriptor {
|
|
3
|
+
/** Stable machine-readable argument name. */
|
|
4
|
+
readonly name: string;
|
|
5
|
+
/** Human-readable explanation suitable for command palettes and help text. */
|
|
6
|
+
readonly description: string;
|
|
7
|
+
readonly required: boolean;
|
|
8
|
+
/** Whether this argument consumes the remaining input rather than one token. */
|
|
9
|
+
readonly variadic?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Metadata shared by the logical-session and low-level controller command surfaces. */
|
|
13
|
+
export interface CommandDescriptor<Id extends string = string> {
|
|
14
|
+
readonly id: Id;
|
|
15
|
+
/** Compact terminal representation retained for help output and compatibility. */
|
|
16
|
+
readonly usage: string;
|
|
17
|
+
readonly description: string;
|
|
18
|
+
readonly arguments: readonly CommandArgumentDescriptor[];
|
|
19
|
+
readonly available: boolean;
|
|
20
|
+
/** Present only when the command is currently unavailable. */
|
|
21
|
+
readonly unavailableReason?: string;
|
|
22
|
+
}
|
package/src/controller.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type * as schema from "@agentclientprotocol/sdk";
|
|
|
9
9
|
import type { Adapter } from "./adapters.ts";
|
|
10
10
|
import type { AgentClient, Bridgeable, BridgeOptions, InterruptOptions } from "./agent-client.ts";
|
|
11
11
|
import type { Capabilities } from "./capabilities.ts";
|
|
12
|
+
import type { CommandDescriptor } from "./command-descriptors.ts";
|
|
12
13
|
import type { ConfigOption, ConfigOptions } from "./config-options.ts";
|
|
13
14
|
import type { Logger } from "./logger.ts";
|
|
14
15
|
import type { AcpLauncher } from "./launcher.ts";
|
|
@@ -73,14 +74,11 @@ export type ControllerCommandId =
|
|
|
73
74
|
| "load"
|
|
74
75
|
| "resume"
|
|
75
76
|
| "fork"
|
|
76
|
-
| "bridge"
|
|
77
|
+
| "bridge"
|
|
78
|
+
| "degrade"
|
|
79
|
+
| "upgrade";
|
|
77
80
|
|
|
78
|
-
export interface ControllerCommand {
|
|
79
|
-
id: ControllerCommandId;
|
|
80
|
-
usage: string;
|
|
81
|
-
available: boolean;
|
|
82
|
-
unavailableReason?: string;
|
|
83
|
-
}
|
|
81
|
+
export interface ControllerCommand extends CommandDescriptor<ControllerCommandId> {}
|
|
84
82
|
|
|
85
83
|
export type ConfigValueParseResult =
|
|
86
84
|
| { ok: true; value: unknown }
|
|
@@ -347,58 +345,97 @@ export class AgentController implements AgentClient {
|
|
|
347
345
|
// The rich ACP commands are unavailable when degraded — `acp` is null there.
|
|
348
346
|
const acp = this.acp;
|
|
349
347
|
const degradedReason = "unavailable in degraded (pty) mode";
|
|
348
|
+
const acpUnavailableReason = this.current ? degradedReason : "controller is not connected";
|
|
350
349
|
const capabilities = acp ? acp.capabilities : null;
|
|
351
350
|
const session = capabilities?.agent.sessionCapabilities;
|
|
351
|
+
const command = (
|
|
352
|
+
descriptor: Omit<ControllerCommand, "available" | "unavailableReason">,
|
|
353
|
+
available: boolean,
|
|
354
|
+
unavailableReason?: string,
|
|
355
|
+
): ControllerCommand => ({
|
|
356
|
+
...descriptor,
|
|
357
|
+
available,
|
|
358
|
+
...(available || !unavailableReason ? {} : { unavailableReason }),
|
|
359
|
+
});
|
|
352
360
|
return [
|
|
353
|
-
{
|
|
354
|
-
|
|
361
|
+
command({
|
|
362
|
+
id: "caps",
|
|
363
|
+
usage: "/caps",
|
|
364
|
+
description: "Show capabilities negotiated with the active ACP harness.",
|
|
365
|
+
arguments: [],
|
|
366
|
+
}, Boolean(acp), acpUnavailableReason),
|
|
367
|
+
command({
|
|
368
|
+
id: "session",
|
|
369
|
+
usage: "/session",
|
|
370
|
+
description: "Show the active provider-thread identity, adapter, and transport mode.",
|
|
371
|
+
arguments: [],
|
|
372
|
+
}, Boolean(this.current), "controller is not connected"),
|
|
355
373
|
{
|
|
356
374
|
id: "login",
|
|
357
375
|
usage: "/login [METHOD]",
|
|
376
|
+
description: "List authentication methods or authenticate through the active ACP harness.",
|
|
377
|
+
arguments: [{ name: "method", description: "Advertised authentication method ID.", required: false }],
|
|
358
378
|
available: Boolean(acp),
|
|
359
|
-
unavailableReason:
|
|
379
|
+
...(acp ? {} : { unavailableReason: acpUnavailableReason }),
|
|
360
380
|
},
|
|
361
|
-
{
|
|
381
|
+
command({
|
|
362
382
|
id: "new",
|
|
363
383
|
usage: "/new",
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
},
|
|
367
|
-
{
|
|
384
|
+
description: "Create a fresh provider thread in the active ACP harness.",
|
|
385
|
+
arguments: [],
|
|
386
|
+
}, Boolean(acp), acpUnavailableReason),
|
|
387
|
+
command({
|
|
368
388
|
id: "sessions",
|
|
369
389
|
usage: "/sessions",
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
},
|
|
373
|
-
{
|
|
390
|
+
description: "List provider sessions advertised by the active ACP harness.",
|
|
391
|
+
arguments: [],
|
|
392
|
+
}, session?.list === true, acp ? "agent does not support session/list" : acpUnavailableReason),
|
|
393
|
+
command({
|
|
374
394
|
id: "config",
|
|
375
395
|
usage: "/config [CONFIG_ID [VALUE]]",
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
396
|
+
description: "Inspect or change an ACP session configuration option.",
|
|
397
|
+
arguments: [
|
|
398
|
+
{ name: "configId", description: "Advertised configuration option ID.", required: false },
|
|
399
|
+
{ name: "value", description: "New value for the selected option.", required: false, variadic: true },
|
|
400
|
+
],
|
|
401
|
+
}, Boolean(acp), acpUnavailableReason),
|
|
402
|
+
command({
|
|
380
403
|
id: "load",
|
|
381
404
|
usage: "/load SESSION_ID",
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
},
|
|
385
|
-
{
|
|
405
|
+
description: "Load a provider session by ID.",
|
|
406
|
+
arguments: [{ name: "sessionId", description: "Provider session ID to load.", required: true }],
|
|
407
|
+
}, capabilities?.agent.loadSession === true, acp ? "load not supported by this agent" : acpUnavailableReason),
|
|
408
|
+
command({
|
|
386
409
|
id: "resume",
|
|
387
410
|
usage: "/resume SESSION_ID",
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
},
|
|
391
|
-
{
|
|
411
|
+
description: "Resume a provider session by ID.",
|
|
412
|
+
arguments: [{ name: "sessionId", description: "Provider session ID to resume.", required: true }],
|
|
413
|
+
}, session?.resume === true, acp ? "resume not supported by this agent" : acpUnavailableReason),
|
|
414
|
+
command({
|
|
392
415
|
id: "fork",
|
|
393
416
|
usage: "/fork SESSION_ID",
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
},
|
|
397
|
-
{
|
|
417
|
+
description: "Fork a provider session into a new provider thread.",
|
|
418
|
+
arguments: [{ name: "sessionId", description: "Provider session ID to fork.", required: true }],
|
|
419
|
+
}, session?.fork === true, acp ? "fork not supported by this agent" : acpUnavailableReason),
|
|
420
|
+
command({
|
|
398
421
|
id: "bridge",
|
|
399
422
|
usage: "/bridge",
|
|
400
|
-
|
|
401
|
-
|
|
423
|
+
description: "Open the harness's interactive terminal interface.",
|
|
424
|
+
arguments: [],
|
|
425
|
+
}, Boolean(this.current), "controller is not connected"),
|
|
426
|
+
command({
|
|
427
|
+
id: "degrade",
|
|
428
|
+
usage: "/degrade",
|
|
429
|
+
description: "Replace the ACP connection with the adapter's interactive PTY mode.",
|
|
430
|
+
arguments: [],
|
|
431
|
+
}, this.mode !== "degraded" && Boolean(this.config.adapter.ptyCommand),
|
|
432
|
+
this.mode === "degraded" ? "already in degraded mode" : "adapter has no interactive PTY command"),
|
|
433
|
+
command({
|
|
434
|
+
id: "upgrade",
|
|
435
|
+
usage: "/upgrade",
|
|
436
|
+
description: "Replace degraded PTY mode with a fresh ACP connection.",
|
|
437
|
+
arguments: [],
|
|
438
|
+
}, this.mode === "degraded", "already in normal ACP mode"),
|
|
402
439
|
];
|
|
403
440
|
}
|
|
404
441
|
|
package/src/index.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
HandoffResult,
|
|
10
10
|
} from "../agent-session.ts";
|
|
11
11
|
import type { AgentMode } from "../controller.ts";
|
|
12
|
+
import type { CommandDescriptor } from "../command-descriptors.ts";
|
|
12
13
|
import type { InternalSessionCommand, PromptHandlers, PromptResult } from "../types.ts";
|
|
13
14
|
import { runRepl, type ReplOptions } from "./repl.ts";
|
|
14
15
|
|
|
@@ -40,6 +41,78 @@ export interface AgentSessionCommandHandlers {
|
|
|
40
41
|
onSlashCommand(command: string, args: string[]): Promise<boolean>;
|
|
41
42
|
}
|
|
42
43
|
|
|
44
|
+
export type AgentSessionCommandId =
|
|
45
|
+
| "help"
|
|
46
|
+
| "session"
|
|
47
|
+
| "state"
|
|
48
|
+
| "commands"
|
|
49
|
+
| "handoff"
|
|
50
|
+
| "bridge";
|
|
51
|
+
|
|
52
|
+
export interface AgentSessionCommand extends CommandDescriptor<AgentSessionCommandId> {}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Describe the first-class commands that operate on one stable logical AgentSession.
|
|
56
|
+
* The result is recomputed so availability reflects the current session state.
|
|
57
|
+
* REPL-only lifecycle commands such as `/exit` are intentionally not included.
|
|
58
|
+
*/
|
|
59
|
+
export function getAgentSessionCommands(
|
|
60
|
+
session: Pick<InteractiveAgentSession, "state">,
|
|
61
|
+
): AgentSessionCommand[] {
|
|
62
|
+
const promptability = session.state.promptability;
|
|
63
|
+
const always = (descriptor: Omit<AgentSessionCommand, "available">): AgentSessionCommand => ({
|
|
64
|
+
...descriptor,
|
|
65
|
+
available: true,
|
|
66
|
+
});
|
|
67
|
+
return [
|
|
68
|
+
always({
|
|
69
|
+
id: "help",
|
|
70
|
+
usage: "/help",
|
|
71
|
+
description: "Show commands that operate on this logical agent session.",
|
|
72
|
+
arguments: [],
|
|
73
|
+
}),
|
|
74
|
+
always({
|
|
75
|
+
id: "session",
|
|
76
|
+
usage: "/session",
|
|
77
|
+
description: "Show the stable agent-session identity and current provider-thread identity.",
|
|
78
|
+
arguments: [],
|
|
79
|
+
}),
|
|
80
|
+
always({
|
|
81
|
+
id: "state",
|
|
82
|
+
usage: "/state",
|
|
83
|
+
description: "Show lifecycle, queue, transport, and provider-thread state.",
|
|
84
|
+
arguments: [],
|
|
85
|
+
}),
|
|
86
|
+
always({
|
|
87
|
+
id: "commands",
|
|
88
|
+
usage: "/commands",
|
|
89
|
+
description: "List slash commands advertised by the active ACP harness.",
|
|
90
|
+
arguments: [],
|
|
91
|
+
}),
|
|
92
|
+
{
|
|
93
|
+
id: "handoff",
|
|
94
|
+
usage: "/handoff [SUMMARY]",
|
|
95
|
+
description: "Continue in a new provider thread while preserving the agent-session identity.",
|
|
96
|
+
arguments: [{
|
|
97
|
+
name: "summary",
|
|
98
|
+
description: "Optional continuation summary; the current thread generates one when omitted.",
|
|
99
|
+
required: false,
|
|
100
|
+
variadic: true,
|
|
101
|
+
}],
|
|
102
|
+
available: promptability.promptable,
|
|
103
|
+
...(promptability.promptable
|
|
104
|
+
? {}
|
|
105
|
+
: { unavailableReason: `session is not promptable: ${promptability.blockers.join(", ")}` }),
|
|
106
|
+
},
|
|
107
|
+
always({
|
|
108
|
+
id: "bridge",
|
|
109
|
+
usage: "/bridge",
|
|
110
|
+
description: "Open the harness's interactive terminal interface.",
|
|
111
|
+
arguments: [],
|
|
112
|
+
}),
|
|
113
|
+
];
|
|
114
|
+
}
|
|
115
|
+
|
|
43
116
|
/** Commands that control exactly one stable logical AgentSession. */
|
|
44
117
|
export function createAgentSessionCommands(
|
|
45
118
|
deps: AgentSessionCommandHandlerDeps,
|
|
@@ -49,7 +122,7 @@ export function createAgentSessionCommands(
|
|
|
49
122
|
const onSlashCommand = async (command: string, args: string[]): Promise<boolean> => {
|
|
50
123
|
switch (command) {
|
|
51
124
|
case "help":
|
|
52
|
-
note(
|
|
125
|
+
note(`local commands: ${getAgentSessionCommands(session).map((entry) => entry.usage).join(" ")} /exit`);
|
|
53
126
|
note("internal session commands: //name [input]");
|
|
54
127
|
return true;
|
|
55
128
|
|
package/src/repl/commands.ts
CHANGED
|
@@ -118,7 +118,7 @@ export function createControllerCommands(
|
|
|
118
118
|
case "help": {
|
|
119
119
|
note(
|
|
120
120
|
`commands: /help ${client.getCommands().map((c) => c.usage).join(" ")} ` +
|
|
121
|
-
`/
|
|
121
|
+
`/exit`,
|
|
122
122
|
);
|
|
123
123
|
const availableCommands = client.availableCommands;
|
|
124
124
|
if (availableCommands.length > 0) {
|
package/src/repl/index.ts
CHANGED
|
@@ -5,8 +5,14 @@ export type {
|
|
|
5
5
|
InteractiveControllerClient,
|
|
6
6
|
} from "./commands.ts";
|
|
7
7
|
|
|
8
|
-
export {
|
|
8
|
+
export {
|
|
9
|
+
createAgentSessionCommands,
|
|
10
|
+
getAgentSessionCommands,
|
|
11
|
+
runAgentSessionRepl,
|
|
12
|
+
} from "./agent-session-commands.ts";
|
|
9
13
|
export type {
|
|
14
|
+
AgentSessionCommand,
|
|
15
|
+
AgentSessionCommandId,
|
|
10
16
|
AgentSessionCommandHandlerDeps,
|
|
11
17
|
AgentSessionCommandHandlers,
|
|
12
18
|
AgentSessionReplOptions,
|