canopy-ui 0.18.0 → 0.18.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canopy-ui",
3
- "version": "0.18.0",
3
+ "version": "0.18.1",
4
4
  "license": "BSD-3-Clause",
5
5
  "type": "module",
6
6
  "repository": {
@@ -0,0 +1,34 @@
1
+ // @vitest-environment jsdom
2
+ import { afterEach, describe, expect, it } from "vitest";
3
+ import { cleanup, render, screen } from "@testing-library/react";
4
+
5
+ import type { Message } from "./protocol";
6
+ import { MessageItem } from "./MessageItem";
7
+
8
+ function userRow(content: Record<string, unknown>): Message {
9
+ return {
10
+ id: "1", turn_index: 1, role: "user", content,
11
+ plaintext: "This session is being continued from a previous conversation…",
12
+ status: "complete", error_detail: null, started_at: null, completed_at: null,
13
+ created_at: "2026-10-17T12:35:14Z",
14
+ };
15
+ }
16
+
17
+ afterEach(() => {
18
+ cleanup();
19
+ });
20
+
21
+ describe("MessageItem — a compaction summary", () => {
22
+ it("renders collapsed as context, not as a line the person typed", () => {
23
+ render(<MessageItem message={userRow({ record: { compact_summary: true } })} />);
24
+ const row = screen.getByTestId("compaction-summary-row");
25
+ expect(row.tagName).toBe("DETAILS");
26
+ expect(row.hasAttribute("open")).toBe(false);
27
+ expect(row.textContent).toContain("Context compacted");
28
+ });
29
+
30
+ it("leaves an ordinary typed line as a bubble", () => {
31
+ render(<MessageItem message={userRow({ record: {} })} />);
32
+ expect(screen.queryByTestId("compaction-summary-row")).toBeNull();
33
+ });
34
+ });
@@ -42,6 +42,14 @@ function otherAuthorOf(
42
42
  return isMine(message.author, currentUserId, currentContactId) ? null : message.author;
43
43
  }
44
44
 
45
+ /** A `user` row Claude Code wrote, not a person: the summary it leaves when it
46
+ * compacts the conversation. The runner keeps the transcript record's own
47
+ * flags on the row as `content.record` (`canopy_transcript.record_flags`). */
48
+ function isCompactionSummary(message: Message): boolean {
49
+ const record = message.content?.record as Record<string, unknown> | undefined;
50
+ return message.role === "user" && Boolean(record?.compact_summary);
51
+ }
52
+
45
53
  /** Count visible lines for the "▸ System context (N lines)" header. */
46
54
  function countLines(text: string): number {
47
55
  if (!text) return 0;
@@ -137,6 +145,20 @@ export function MessageItem({
137
145
  />
138
146
  );
139
147
  }
148
+ // Same treatment for a compaction summary: it sits on the human's side of the
149
+ // transcript, but nobody typed it — as a user bubble it read as the person
150
+ // pasting a wall of text.
151
+ if (isCompactionSummary(message)) {
152
+ return (
153
+ <SystemSeedRow
154
+ message={message}
155
+ forceOpen={forceToolOpen}
156
+ renderMarkdown={renderMarkdown}
157
+ label="Context compacted"
158
+ testId="compaction-summary-row"
159
+ />
160
+ );
161
+ }
140
162
 
141
163
  const otherAuthor = otherAuthorOf(message, currentUserId, currentContactId);
142
164
  // A teammate's line sits on the agent's side of the column, so it needs its
@@ -210,10 +232,14 @@ function SystemSeedRow({
210
232
  message,
211
233
  forceOpen,
212
234
  renderMarkdown,
235
+ label = "System context",
236
+ testId = "system-seed-row",
213
237
  }: {
214
238
  message: Message;
215
239
  forceOpen: boolean | undefined;
216
240
  renderMarkdown: RenderMarkdown;
241
+ label?: string;
242
+ testId?: string;
217
243
  }) {
218
244
  const text = message.plaintext;
219
245
  const lineCount = countLines(text);
@@ -221,13 +247,13 @@ function SystemSeedRow({
221
247
  return (
222
248
  <details
223
249
  className="group my-2 mr-auto max-w-[80%] rounded-2xl border border-border bg-muted/40 px-3 py-1.5 text-sm"
224
- data-testid="system-seed-row"
250
+ data-testid={testId}
225
251
  {...(openProp !== undefined ? { open: openProp } : {})}
226
252
  >
227
253
  <summary className="flex cursor-pointer items-center gap-1.5 text-muted-foreground hover:text-foreground select-none list-none [&::-webkit-details-marker]:hidden">
228
254
  <ChevronRight className="h-3.5 w-3.5 transition-transform group-open:rotate-90" />
229
255
  <span className="text-xs font-medium uppercase tracking-wide">
230
- System context
256
+ {label}
231
257
  </span>
232
258
  {lineCount > 0 && (
233
259
  <span className="text-xs text-muted-foreground/70">
package/src/chat/agui.ts CHANGED
@@ -122,6 +122,9 @@ export function fromAgui(frame: AguiFrame): WsEvent[] {
122
122
  // canopy's only chance to say (spec 2026-09-26). Absent when the
123
123
  // server sent none (an agent/scheduled/email turn's own send).
124
124
  author: m.author as MessageAuthor | undefined,
125
+ // The transcript record's provenance — the `content.record` a
126
+ // history row carries — so a compaction summary is known live.
127
+ ...(m.record ? { record: m.record as Record<string, unknown> } : {}),
125
128
  },
126
129
  },
127
130
  ];
@@ -356,7 +356,7 @@ export type WsEvent =
356
356
  // this row to the server's queued-turn projection, and a contact's or
357
357
  // widget's own send rendered twice: once as their bubble, once as a "queued"
358
358
  // placeholder for the same send.
359
- | { event: "chat.user_message"; data: { message_id: string; turn_index: number; plaintext: string; author?: MessageAuthor | null; client_id?: string } }
359
+ | { event: "chat.user_message"; data: { message_id: string; turn_index: number; plaintext: string; author?: MessageAuthor | null; client_id?: string; record?: Record<string, unknown> } }
360
360
  | { event: "chat.delta"; data: { message_id: string; text: string } }
361
361
  // `turn_index` is the row's transcript ordinal — the same key the persisted
362
362
  // Message carries, so a live tool row sorts into exactly the position it will
@@ -551,6 +551,15 @@ describe("sessionReducer — a web send arriving twice", () => {
551
551
  expect(next.messages).toHaveLength(10)
552
552
  })
553
553
 
554
+ it("keeps the record's provenance, so a compaction summary is known live", () => {
555
+ const next = sessionReducer(makeState(), {
556
+ event: "chat.user_message",
557
+ data: { message_id: "9", turn_index: 9, plaintext: "This session is being continued…",
558
+ record: { compact_summary: true } },
559
+ } as WsEvent)
560
+ expect(next.messages[0].content.record).toEqual({ compact_summary: true })
561
+ })
562
+
554
563
  it("an empty-text frame never collapses onto another empty row", () => {
555
564
  const seeded = makeState({
556
565
  messages: [makeMessage({ id: "1", turn_index: 1, role: "user", plaintext: "" })],
@@ -201,6 +201,9 @@ export function sessionReducer(prev: SessionState, frame: WsEvent): SessionState
201
201
  // had it (an optimistic send knows its own author) and the
202
202
  // frame is silent, but let the frame win otherwise.
203
203
  author: frame.data.author ?? m.author ?? null,
204
+ ...(frame.data.record
205
+ ? { content: { ...m.content, record: frame.data.record } }
206
+ : {}),
204
207
  // The agent read it, so a pending or unconfirmed row is sent.
205
208
  ...(m.role === "user" ? { status: "complete" as const, error_detail: null } : {}),
206
209
  }
@@ -216,9 +219,11 @@ export function sessionReducer(prev: SessionState, frame: WsEvent): SessionState
216
219
  // `client_id` (when the caller has one — an HTTP send) lets
217
220
  // `QueuedRows.hideClientIds` recognise the server's queued-turn
218
221
  // projection as THIS row rather than a duplicate.
219
- content: frame.data.client_id
220
- ? { text: frame.data.plaintext, client_id: frame.data.client_id }
221
- : { text: frame.data.plaintext },
222
+ content: {
223
+ text: frame.data.plaintext,
224
+ ...(frame.data.client_id ? { client_id: frame.data.client_id } : {}),
225
+ ...(frame.data.record ? { record: frame.data.record } : {}),
226
+ },
222
227
  plaintext: frame.data.plaintext,
223
228
  status: "complete",
224
229
  error_detail: null,