@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.
@@ -20,6 +20,9 @@ import type {
20
20
  OperationKind,
21
21
  TranscriptCheckpointRecord,
22
22
  TranscriptOperationRecord,
23
+ TranscriptActivityRecord,
24
+ TranscriptMessageRecord,
25
+ TranscriptReasoningRecord,
23
26
  } from "./records.ts";
24
27
  import type { PersistedMachineCode } from "./integrity.ts";
25
28
  import {
@@ -29,7 +32,11 @@ import {
29
32
  type SessionLogWriterLock,
30
33
  } from "./session-log-writer.ts";
31
34
  import type { TranscriptHeaderRecord } from "./records.ts";
32
- import type { PersistenceStateRuntime } from "./state-runtime.ts";
35
+ import type {
36
+ PersistenceStateRuntime,
37
+ PresentationPersistenceEvent,
38
+ TranscriptPresentationRecord,
39
+ } from "./state-runtime.ts";
33
40
 
34
41
  export interface TranscriptTerminalCheckpointChanges {
35
42
  readonly model?: string | null;
@@ -90,6 +97,12 @@ export class TranscriptPersistenceRuntime implements PersistenceStateRuntime {
90
97
  checkpoint: AgentSessionCheckpoint,
91
98
  history: readonly InternalSessionHistoryEntry[],
92
99
  ) => Promise<void>) | null = null;
100
+ private readonly presentationStates = new Map<string, {
101
+ readonly position: number;
102
+ readonly revision: number;
103
+ readonly kind: PresentationPersistenceEvent["kind"];
104
+ readonly operationId: string;
105
+ }>();
93
106
 
94
107
  private constructor(
95
108
  private readonly writer: FileSessionLogWriter<"transcript">,
@@ -281,6 +294,52 @@ export class TranscriptPersistenceRuntime implements PersistenceStateRuntime {
281
294
  }
282
295
  }
283
296
 
297
+ async appendPresentationEvent(
298
+ event: PresentationPersistenceEvent,
299
+ ts = Date.now(),
300
+ ): Promise<TranscriptPresentationRecord | null> {
301
+ this.assertUsable();
302
+ if (!event.presentation) {
303
+ throw new TranscriptRuntimeStateError("presentation event requires identity and revision");
304
+ }
305
+ const existing = this.presentationStates.get(event.presentation.id);
306
+ if (existing && (existing.kind !== event.kind
307
+ || existing.operationId !== presentationOperationId(event)
308
+ || existing.revision >= event.presentation.revision)) {
309
+ throw new TranscriptRuntimeStateError(`invalid presentation revision for ${event.presentation.id}`);
310
+ }
311
+ const position = existing?.position ?? this.writer.nextSequence;
312
+ const positioned = {
313
+ ...event,
314
+ presentation: { ...event.presentation, position },
315
+ } as PresentationPersistenceEvent;
316
+ const record = projectTranscriptEvent(positioned, {
317
+ transcriptId: this.header.transcriptId,
318
+ generation: this.header.generation,
319
+ agentSessionId: this.header.agentSessionId,
320
+ seq: this.writer.nextSequence,
321
+ ts,
322
+ policy: this.header.effectivePolicy,
323
+ });
324
+ if (!record) return null;
325
+ if (!isTranscriptPresentationRecord(record)) {
326
+ throw new TranscriptRuntimeStateError("presentation event projected to a non-presentation record");
327
+ }
328
+ try {
329
+ await this.writer.append(record);
330
+ this.presentationStates.set(event.presentation.id, {
331
+ position,
332
+ revision: event.presentation.revision,
333
+ kind: event.kind,
334
+ operationId: presentationOperationId(event),
335
+ });
336
+ return structuredClone(record);
337
+ } catch (error) {
338
+ this.failure = error instanceof Error ? error : new Error(String(error));
339
+ throw error;
340
+ }
341
+ }
342
+
284
343
  async appendTransitionEvent(
285
344
  event: NonActivationTransitionEvent,
286
345
  options: { readonly durable?: boolean; readonly ts?: number } = {},
@@ -587,6 +646,17 @@ export class TranscriptPersistenceRuntime implements PersistenceStateRuntime {
587
646
  }
588
647
  }
589
648
 
649
+ function isTranscriptPresentationRecord(
650
+ record: ReturnType<typeof projectTranscriptEvent>,
651
+ ): record is TranscriptMessageRecord | TranscriptReasoningRecord | TranscriptActivityRecord {
652
+ return record !== null
653
+ && (record.t === "message" || record.t === "reasoning" || record.t === "activity");
654
+ }
655
+
656
+ function presentationOperationId(event: PresentationPersistenceEvent): string {
657
+ return event.kind === "activity" ? event.activity.operationId : event.operationId;
658
+ }
659
+
590
660
  function checkpointRecord(
591
661
  seq: number,
592
662
  checkpoint: AgentSessionCheckpoint,
@@ -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("local commands: /help /session /state /commands /handoff [SUMMARY] /bridge /exit");
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
 
@@ -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
- `/degrade /upgrade /exit`,
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 { createAgentSessionCommands, runAgentSessionRepl } from "./agent-session-commands.ts";
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,
package/src/response.ts CHANGED
@@ -7,6 +7,16 @@ export interface IncomingResponseChunk {
7
7
  startsMessage?: boolean;
8
8
  }
9
9
 
10
+ /**
11
+ * Produce the legacy combined-text view without erasing protocol message boundaries.
12
+ * Message text is preserved verbatim; the only inserted content is the boundary between
13
+ * entries. Empty entries therefore participate in the literal join rather than being
14
+ * silently removed.
15
+ */
16
+ export function joinResponseMessages(messages: readonly ResponseMessage[]): string {
17
+ return messages.map((message) => message.text).join("\n\n");
18
+ }
19
+
10
20
  /**
11
21
  * Fold response deltas without inventing separators. Only a change between two explicit
12
22
  * ACP message ids proves that a new assistant message started; missing ids remain part of
@@ -45,7 +55,7 @@ export class ResponseAccumulator {
45
55
  }
46
56
 
47
57
  get text(): string {
48
- return this.entries.map((entry) => entry.text).join("");
58
+ return joinResponseMessages(this.entries);
49
59
  }
50
60
 
51
61
  snapshot(): readonly ResponseMessage[] {
package/src/types.ts CHANGED
@@ -58,7 +58,7 @@ export type Usage = TokenUsage;
58
58
  * call RESOLVES (not rejects) with whatever partial text arrived.
59
59
  */
60
60
  export interface PromptResult {
61
- /** Legacy flattened projection of `messages` (partial if cancelled). */
61
+ /** Combined display projection of `messages`, separated by one blank line. */
62
62
  text: string;
63
63
  /** Assistant messages in protocol order, preserving ACP `messageId` boundaries. */
64
64
  messages: readonly ResponseMessage[];
@@ -242,7 +242,7 @@ export interface PermissionRequest {
242
242
 
243
243
  /** Per-prompt callbacks. All optional. */
244
244
  export interface PromptHandlers {
245
- /** Legacy text-only response stream. Prefer `onResponseChunk` when boundaries matter. */
245
+ /** Legacy raw text stream. Concatenation does not encode message boundaries. */
246
246
  onChunk?: (text: string) => void;
247
247
  /** Boundary-aware response stream preserving ACP `messageId`. */
248
248
  onResponseChunk?: (chunk: ResponseChunk) => void;
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Facundo Hannoch
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.