@qlairoslabs/acp-client 0.7.0 → 0.7.2

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
@@ -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";
@@ -213,9 +214,19 @@ const unsubscribe = session.subscribe((notification: AgentSessionNotification) =
213
214
  if (notification.event.kind === "metering_recorded") {
214
215
  persistBillingMetadata(notification.event.record);
215
216
  }
217
+
218
+ if (notification.event.kind === "presentation_recorded") {
219
+ upsertChatItem(notification.event.item.id, notification.event.item);
220
+ }
216
221
  });
217
222
  ```
218
223
 
224
+ `onResponseChunk` and activity callbacks are provisional live streams. A
225
+ `presentation_recorded` notification means the displayed item revision has been appended
226
+ to the V2 transcript. Its ID, first position, revision, record sequence, and operation ID
227
+ are exactly the values the presentation reader returns after a restart. Upsert by `id`
228
+ and ignore revisions older than the one already rendered.
229
+
219
230
  Useful live properties include:
220
231
 
221
232
  ```ts
@@ -453,6 +464,45 @@ ACP sends a harness command as a prompt. `executeInternalSessionCommand()` makes
453
464
  explicit and routes it through the logical session's queue, lifecycle, transcript, and
454
465
  metering machinery. Advertisement is discovery rather than an allow-list.
455
466
 
467
+ ## Discover commands for a UI
468
+
469
+ The library exposes command metadata separately for the two local operation layers. A UI
470
+ bound to one stable logical session can read the AgentSession command registry:
471
+
472
+ ```ts
473
+ const clientCommands = getAgentSessionCommands(session);
474
+
475
+ for (const command of clientCommands) {
476
+ renderCommand({
477
+ name: command.id,
478
+ description: command.description,
479
+ arguments: command.arguments,
480
+ disabled: !command.available,
481
+ disabledReason: command.unavailableReason,
482
+ });
483
+ }
484
+ ```
485
+
486
+ This registry contains `/handoff`, `/bridge`, and the introspection commands implemented
487
+ by `createAgentSessionCommands()`. Its availability is recomputed from current session
488
+ state. `/exit` is intentionally absent because it belongs to a particular REPL, not to an
489
+ `AgentSession`.
490
+
491
+ The lower-level controller exposes its own dynamically negotiated registry:
492
+
493
+ ```ts
494
+ for (const command of controller.getCommands()) {
495
+ console.log(command.id, command.description, command.arguments);
496
+ if (!command.available) console.log(command.unavailableReason);
497
+ }
498
+ ```
499
+
500
+ These are provider-thread and transport controls such as `/load`, `/fork`, `/config`, and
501
+ `/degrade`; they are not aliases for logical-session operations. Harness-advertised
502
+ commands remain the third source in `session.internalSessionCommands` and are invoked
503
+ explicitly with `executeInternalSessionCommand()`. A consumer can merge all three sources
504
+ for display while retaining their origin so dispatch never crosses layers accidentally.
505
+
456
506
  ## Configure transcripts
457
507
 
458
508
  Transcripts and audit logs are separate artifacts:
@@ -544,6 +594,24 @@ const records = await reader.readPage({
544
594
  });
545
595
  ```
546
596
 
597
+ For an end-user chat timeline, prefer the folded presentation projection:
598
+
599
+ ```ts
600
+ const presentation = await reader.readPresentationPage({ limit: 50 });
601
+
602
+ for (const item of presentation.items) {
603
+ // message, reasoning, or activity; activity revisions are already folded.
604
+ renderOrReplace(item.id, item);
605
+ }
606
+ ```
607
+
608
+ `readPresentationPage()` preserves the order in which logical items first appeared. A
609
+ tool that settles later keeps its original position, and distinct assistant messages stay
610
+ separate around intervening activity. The raw `timeline` view intentionally remains
611
+ available when the consumer needs every physical lifecycle revision rather than a chat
612
+ projection. Presentation pagination scans the snapshot with bounded item memory and does
613
+ not require the consumer to load the entire transcript.
614
+
547
615
  Each page is ordered oldest-first within that page, while the initial page selects the
548
616
  newest matching records. Navigate using `olderCursor` and `newerCursor`:
549
617
 
@@ -562,6 +630,10 @@ Navigation cursors are bound to the snapshot, view, and filter. Reusing one with
562
630
  view or filter fails explicitly. Appends after the snapshot do not reorder the page being
563
631
  read, while rewrites before its boundary invalidate the cursor.
564
632
 
633
+ Presentation navigation uses its own cursor type and the same stable snapshot semantics.
634
+ V1 and older V2 records without presentation metadata remain readable through `readPage`
635
+ but are not assigned invented interleaving in the folded V2 presentation view.
636
+
565
637
  Fold revisioned activities at the same snapshot:
566
638
 
567
639
  ```ts
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@qlairoslabs/acp-client",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "Embeddable Agent Client Protocol (ACP) client library with degraded PTY fallback.",
5
5
  "type": "module",
6
6
  "module": "src/index.ts",
7
- "license": "MIT",
7
+ "license": "UNLICENSED",
8
8
  "author": "Facundo Hannoch <ffacu594@gmail.com>",
9
9
  "repository": {
10
10
  "type": "git",
package/src/activity.ts CHANGED
@@ -235,6 +235,14 @@ export class ActivityAggregator {
235
235
  return out;
236
236
  }
237
237
 
238
+ /**
239
+ * Close only the current reasoning block when another presentation item begins.
240
+ * Long-running tools remain open: later revisions keep the tool's first position.
241
+ */
242
+ closeReasoningBoundary(): AggregatedRecord | null {
243
+ return this.closeThinking();
244
+ }
245
+
238
246
  /**
239
247
  * Full state of the turn so far. A subscriber that joins mid-turn takes this, then
240
248
  * discards any frame whose `seq` is not greater than the snapshot's — otherwise a
@@ -53,6 +53,7 @@ import type {
53
53
  Attachment,
54
54
  PromptHandlers,
55
55
  PromptResult,
56
+ ResponseMessage,
56
57
  SessionListEntry,
57
58
  TokenUsage,
58
59
  WireEntry,
@@ -79,9 +80,17 @@ import type {
79
80
  OperationKind,
80
81
  } from "./persistence/records.ts";
81
82
  import { TranscriptPersistenceRuntime } from "./persistence/transcript-runtime.ts";
82
- import { RegistryPersistenceRuntime, type PersistenceStateRuntime } from "./persistence/state-runtime.ts";
83
+ import {
84
+ RegistryPersistenceRuntime,
85
+ type PersistenceStateRuntime,
86
+ type PresentationPersistenceEvent,
87
+ } from "./persistence/state-runtime.ts";
83
88
  import { AuditPersistenceRuntime, AuditedPersistenceRuntime, type AuditLogIdentity } from "./persistence/audit-runtime.ts";
84
89
  import { TranscriptReader } from "./persistence/transcript-reader.ts";
90
+ import {
91
+ presentationItemFromRecord,
92
+ type TranscriptPresentationItem,
93
+ } from "./persistence/presentation.ts";
85
94
  import {
86
95
  snapshotSessionConfiguration,
87
96
  snapshotSessionConfigurationAfterSelection,
@@ -336,6 +345,8 @@ export type AgentSessionEvent =
336
345
  | { kind: "turn_started"; turnId: string }
337
346
  | { kind: "turn_completed"; turnId: string; result: PromptResult }
338
347
  | { kind: "turn_failed"; turnId: string; error: string }
348
+ /** A display item revision was appended to the transcript and can be joined to reloads by id. */
349
+ | { kind: "presentation_recorded"; item: TranscriptPresentationItem }
339
350
  /** The active ACP harness changed the slash commands it advertises. */
340
351
  | { kind: "internal_session_commands_changed"; commands: readonly InternalSessionCommand[] }
341
352
  | {
@@ -599,7 +610,8 @@ export class AgentSession implements AgentClient, Bridgeable {
599
610
  private readonly creationId: string;
600
611
  private v2Transcript: PersistenceStateRuntime | null = null;
601
612
  private v2TranscriptPath: string | null = null;
602
- private v2ActivityWrite: Promise<void> = Promise.resolve();
613
+ /** One display queue preserves the live message/activity interleaving seen by consumers. */
614
+ private v2PresentationWrite: Promise<void> = Promise.resolve();
603
615
  private readonly transcriptActivity: boolean;
604
616
  private readonly activityKinds: Set<string>;
605
617
  private readonly activityRawOutput: boolean;
@@ -2504,13 +2516,16 @@ export class AgentSession implements AgentClient, Bridgeable {
2504
2516
  operation = await this.openMeteredOperation(item);
2505
2517
  await this.v2Transcript.beginOperation(item.turnId, persistenceOperationKind(item.operationKind));
2506
2518
  transcriptStarted = true;
2507
- await this.v2Transcript.appendEvent({
2519
+ const userRecord = await this.v2Transcript.appendPresentationEvent({
2508
2520
  kind: "message",
2509
2521
  operationId: item.turnId,
2510
2522
  role: "user",
2511
2523
  text: item.text,
2524
+ status: "completed",
2525
+ presentation: { id: `message:${item.turnId}:user`, revision: 1 },
2512
2526
  });
2513
2527
  await this.v2Transcript.syncBeforeDispatch();
2528
+ this.emitPresentationRecord(userRecord);
2514
2529
  } catch (error) {
2515
2530
  this.endTurn(item.handlers);
2516
2531
  if (transcriptStarted) {
@@ -2533,6 +2548,51 @@ export class AgentSession implements AgentClient, Bridgeable {
2533
2548
 
2534
2549
  const chunks: string[] = [];
2535
2550
  const response = new ResponseAccumulator();
2551
+ let assistantOrdinal = 0;
2552
+ let assistantMessage: {
2553
+ readonly id: string;
2554
+ providerMessageId?: string;
2555
+ text: string;
2556
+ revision: number;
2557
+ dirty: boolean;
2558
+ } | null = null;
2559
+ const beginAssistantMessage = (providerMessageId?: string) => {
2560
+ assistantOrdinal++;
2561
+ assistantMessage = {
2562
+ id: `message:${item.turnId}:assistant:${assistantOrdinal}`,
2563
+ ...(providerMessageId === undefined ? {} : { providerMessageId }),
2564
+ text: "",
2565
+ revision: 0,
2566
+ dirty: false,
2567
+ };
2568
+ return assistantMessage;
2569
+ };
2570
+ const flushAssistantMessage = (
2571
+ status: "in_progress" | "completed" | "cancelled" | "error",
2572
+ stopReason?: string,
2573
+ force = false,
2574
+ ) => {
2575
+ if (!this.v2Transcript || !assistantMessage || (!assistantMessage.dirty && !force)) return;
2576
+ assistantMessage.revision++;
2577
+ assistantMessage.dirty = false;
2578
+ const message = assistantMessage;
2579
+ this.queueV2Presentation({
2580
+ kind: "message",
2581
+ operationId: item.turnId,
2582
+ role: "assistant",
2583
+ text: message.text,
2584
+ ...(message.providerMessageId === undefined ? {} : { providerMessageId: message.providerMessageId }),
2585
+ structured: {
2586
+ version: 1,
2587
+ messages: [message.providerMessageId === undefined
2588
+ ? { text: message.text }
2589
+ : { messageId: message.providerMessageId, text: message.text }],
2590
+ },
2591
+ status,
2592
+ ...(stopReason === undefined ? {} : { stopReason }),
2593
+ presentation: { id: message.id, revision: message.revision },
2594
+ });
2595
+ };
2536
2596
  const wrappedHandlers: PromptHandlers = {
2537
2597
  ...item.handlers,
2538
2598
  // Fired from here, from the one aggregator this session owns — nothing below needs
@@ -2543,10 +2603,33 @@ export class AgentSession implements AgentClient, Bridgeable {
2543
2603
  item.handlers?.onChunk?.(chunk);
2544
2604
  },
2545
2605
  onResponseChunk: (chunk) => {
2606
+ const settledReasoning = this.aggregator.closeReasoningBoundary();
2607
+ if (settledReasoning) {
2608
+ if (this.transcriptActivity || this.v2Transcript) this.writeActivity(settledReasoning);
2609
+ item.handlers?.onRecord?.({ current: null, delta: null, emitted: [settledReasoning] });
2610
+ }
2546
2611
  response.append(chunk);
2612
+ if (this.v2Transcript) {
2613
+ if (chunk.startsMessage) {
2614
+ flushAssistantMessage("completed", undefined, assistantMessage !== null);
2615
+ beginAssistantMessage(chunk.messageId);
2616
+ }
2617
+ const current = assistantMessage ?? beginAssistantMessage(chunk.messageId);
2618
+ if (current.providerMessageId === undefined && chunk.messageId !== undefined) {
2619
+ current.providerMessageId = chunk.messageId;
2620
+ }
2621
+ current.text += chunk.text;
2622
+ current.dirty = true;
2623
+ // Persist the first usable snapshot. Later token chunks remain in memory until
2624
+ // an interleaving item, a new message, or the operation boundary.
2625
+ if (current.revision === 0) flushAssistantMessage("in_progress");
2626
+ }
2547
2627
  item.handlers?.onResponseChunk?.(chunk);
2548
2628
  },
2549
2629
  onActivity: (event) => {
2630
+ // The message snapshot must enter the shared queue before an activity first seen
2631
+ // after it. Later activity revisions keep their original presentation position.
2632
+ flushAssistantMessage("in_progress");
2550
2633
  const result = this.aggregator.apply(event);
2551
2634
  if (this.transcriptActivity || this.v2Transcript) {
2552
2635
  for (const record of result.emitted) this.writeActivity(record);
@@ -2560,6 +2643,18 @@ export class AgentSession implements AgentClient, Bridgeable {
2560
2643
  let transcriptClosed = false;
2561
2644
  try {
2562
2645
  const res = await this.controller.prompt(item.text, wrappedHandlers, item.attachments);
2646
+ if (this.v2Transcript) {
2647
+ if (assistantOrdinal === 0) {
2648
+ for (const message of res.messages) {
2649
+ const current = beginAssistantMessage(message.messageId);
2650
+ current.text = message.text;
2651
+ current.dirty = true;
2652
+ flushAssistantMessage(res.status, res.stopReason, true);
2653
+ }
2654
+ } else {
2655
+ flushAssistantMessage(res.status, res.stopReason, true);
2656
+ }
2657
+ }
2563
2658
  // Before the assistant msg: `msg` delimits a turn, so anything still open has to
2564
2659
  // land inside those fences.
2565
2660
  this.endTurn(item.handlers);
@@ -2580,16 +2675,7 @@ export class AgentSession implements AgentClient, Bridgeable {
2580
2675
  closed = record;
2581
2676
  await this.persist();
2582
2677
  if (this.v2Transcript) {
2583
- await this.drainV2Activity();
2584
- await this.v2Transcript.appendEvent({
2585
- kind: "message",
2586
- operationId: item.turnId,
2587
- role: "assistant",
2588
- text: res.text,
2589
- structured: { version: 1, messages: res.messages },
2590
- stopReason: res.stopReason,
2591
- status: res.status,
2592
- });
2678
+ await this.drainV2Presentation();
2593
2679
  await this.finishV2Prompt(res.status, record);
2594
2680
  transcriptClosed = true;
2595
2681
  } else {
@@ -2610,26 +2696,25 @@ export class AgentSession implements AgentClient, Bridgeable {
2610
2696
  // Easy to miss, and the whole point of R4: a turn that died mid-tool still records
2611
2697
  // what it was doing, at its real status.
2612
2698
  this.endTurn(item.handlers);
2613
- const text = chunks.join("");
2614
2699
  const structured = response.snapshot();
2615
- const messages = structured.length > 0
2700
+ const text = structured.length > 0 ? response.text : chunks.join("");
2701
+ const messages: readonly ResponseMessage[] = structured.length > 0
2616
2702
  ? structured
2617
2703
  : text
2618
2704
  ? Object.freeze([{ text }])
2619
2705
  : Object.freeze([]);
2620
2706
  if (this.v2Transcript) {
2621
- await this.drainV2Activity().catch(() => undefined);
2622
- if (!transcriptClosed) {
2623
- await this.v2Transcript.appendEvent({
2624
- kind: "message",
2625
- operationId: item.turnId,
2626
- role: "assistant",
2627
- text,
2628
- structured: { version: 1, messages },
2629
- stopReason: "error",
2630
- status: "error",
2631
- }).catch(() => undefined);
2707
+ if (!transcriptClosed && assistantOrdinal === 0 && messages.length > 0) {
2708
+ for (const message of messages) {
2709
+ const current = beginAssistantMessage(message.messageId);
2710
+ current.text = message.text;
2711
+ current.dirty = true;
2712
+ flushAssistantMessage("error", "error", true);
2713
+ }
2714
+ } else if (!transcriptClosed) {
2715
+ flushAssistantMessage("error", "error", true);
2632
2716
  }
2717
+ await this.drainV2Presentation().catch(() => undefined);
2633
2718
  } else {
2634
2719
  await this.appendTranscript({
2635
2720
  v: 1,
@@ -2957,8 +3042,13 @@ export class AgentSession implements AgentClient, Bridgeable {
2957
3042
  const operationId = this.v2Transcript.checkpoint.boundary.status === "in_flight"
2958
3043
  ? this.v2Transcript.checkpoint.boundary.interruptedOperationId
2959
3044
  : record.recordId.split(":", 1)[0] ?? record.recordId;
2960
- this.v2ActivityWrite = this.v2ActivityWrite.then(async () => {
2961
- await this.v2Transcript!.appendEvent(persistenceEventFromActivity(record, operationId));
3045
+ const projected = persistenceEventFromActivity(record, operationId);
3046
+ this.queueV2Presentation({
3047
+ ...projected,
3048
+ presentation: {
3049
+ id: `${projected.kind}:${operationId}:${record.recordId}`,
3050
+ revision: record.seq,
3051
+ },
2962
3052
  });
2963
3053
  return;
2964
3054
  }
@@ -2967,8 +3057,24 @@ export class AgentSession implements AgentClient, Bridgeable {
2967
3057
  void this.appendTranscript(this.toActivityLine(record));
2968
3058
  }
2969
3059
 
2970
- private async drainV2Activity(): Promise<void> {
2971
- await this.v2ActivityWrite;
3060
+ private queueV2Presentation(event: PresentationPersistenceEvent): void {
3061
+ this.v2PresentationWrite = this.v2PresentationWrite.then(async () => {
3062
+ if (!this.v2Transcript) return;
3063
+ const record = await this.v2Transcript.appendPresentationEvent(event);
3064
+ this.emitPresentationRecord(record);
3065
+ });
3066
+ }
3067
+
3068
+ private emitPresentationRecord(
3069
+ record: Awaited<ReturnType<PersistenceStateRuntime["appendPresentationEvent"]>>,
3070
+ ): void {
3071
+ if (!record) return;
3072
+ const item = presentationItemFromRecord(record);
3073
+ if (item) this.emit({ kind: "presentation_recorded", item });
3074
+ }
3075
+
3076
+ private async drainV2Presentation(): Promise<void> {
3077
+ await this.v2PresentationWrite;
2972
3078
  }
2973
3079
 
2974
3080
  private toActivityLine(record: AggregatedRecord): TranscriptActivityLine {
@@ -3036,7 +3142,7 @@ export class AgentSession implements AgentClient, Bridgeable {
3036
3142
  this.phase = "stopped";
3037
3143
  this.emitStateIfChanged();
3038
3144
  await this.controller.stop();
3039
- await this.drainV2Activity().catch(() => undefined);
3145
+ await this.drainV2Presentation().catch(() => undefined);
3040
3146
  await this.v2Transcript?.close();
3041
3147
  }
3042
3148
 
@@ -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
- { id: "caps", usage: "/caps", available: Boolean(acp), unavailableReason: degradedReason },
354
- { id: "session", usage: "/session", available: Boolean(this.current) },
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: degradedReason,
379
+ ...(acp ? {} : { unavailableReason: acpUnavailableReason }),
360
380
  },
361
- {
381
+ command({
362
382
  id: "new",
363
383
  usage: "/new",
364
- available: Boolean(acp),
365
- unavailableReason: degradedReason,
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
- available: session?.list === true,
371
- unavailableReason: acp ? "agent does not support session/list" : degradedReason,
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
- available: Boolean(acp),
377
- unavailableReason: degradedReason,
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
- available: capabilities?.agent.loadSession === true,
383
- unavailableReason: acp ? "load not supported by this agent" : degradedReason,
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
- available: session?.resume === true,
389
- unavailableReason: acp ? "resume not supported by this agent" : degradedReason,
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
- available: session?.fork === true,
395
- unavailableReason: acp ? "fork not supported by this agent" : degradedReason,
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
- available: Boolean(this.current),
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
@@ -24,6 +24,7 @@ export {
24
24
  parseJsonOrString,
25
25
  formatConfigValue,
26
26
  } from "./controller.ts";
27
+ export type { CommandArgumentDescriptor, CommandDescriptor } from "./command-descriptors.ts";
27
28
  export type {
28
29
  AgentControllerConfig,
29
30
  AgentMode,
@@ -247,8 +248,17 @@ export type {
247
248
  AuditProjectionContext,
248
249
  NormalizedActivityProjection,
249
250
  NormalizedPersistenceEvent,
251
+ NormalizedPresentationMetadata,
250
252
  TranscriptProjectionContext,
251
253
  } from "./persistence/projection.ts";
254
+ export { presentationItemFromRecord } from "./persistence/presentation.ts";
255
+ export type {
256
+ TranscriptPresentationActivity,
257
+ TranscriptPresentationItem,
258
+ TranscriptPresentationMessage,
259
+ TranscriptPresentationReasoning,
260
+ TranscriptPresentationRecord,
261
+ } from "./persistence/presentation.ts";
252
262
  export {
253
263
  SessionLogTruncationError,
254
264
  truncateSessionLogRecord,
@@ -336,9 +346,12 @@ export type {
336
346
  PersistedActivityState,
337
347
  PersistedActivityStatePage,
338
348
  ReadTranscriptPageOptions,
349
+ ReadTranscriptPresentationPageOptions,
339
350
  TranscriptConversationItem,
340
351
  TranscriptCursor,
341
352
  TranscriptPage,
353
+ TranscriptPresentationCursor,
354
+ TranscriptPresentationPage,
342
355
  TranscriptSnapshotCursor,
343
356
  TranscriptTimelineItem,
344
357
  TranscriptReadableRecord,
@@ -3,6 +3,11 @@ import type { ActivityEvent, ToolActivity } from "../types.ts";
3
3
  import type { JsonObject, JsonValue } from "./checkpoint.ts";
4
4
  import type { NormalizedPersistenceEvent } from "./projection.ts";
5
5
 
6
+ type NormalizedActivityPersistenceEvent = Extract<
7
+ NormalizedPersistenceEvent,
8
+ { kind: "reasoning" | "activity" }
9
+ >;
10
+
6
11
  /**
7
12
  * Classify an already-folded live activity record into persistence security buckets.
8
13
  * This function deliberately does not serialize or hash values: capture projection gets
@@ -11,7 +16,7 @@ import type { NormalizedPersistenceEvent } from "./projection.ts";
11
16
  export function persistenceEventFromActivity(
12
17
  record: AggregatedRecord,
13
18
  operationId: string,
14
- ): NormalizedPersistenceEvent {
19
+ ): NormalizedActivityPersistenceEvent {
15
20
  if (record.event.kind === "thinking") {
16
21
  return {
17
22
  kind: "reasoning",