You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by as...@apache.org on 2026/09/07 14:32:20 UTC

(maka) branch style/context-compaction-checkpoint created (now e4eda512a7)

This is an automated email from the ASF dual-hosted git repository.

Astro-Han pushed a change to branch style/context-compaction-checkpoint
in repository https://gitbox.apache.org/repos/asf/maka.git


      at e4eda512a7 style(ui): present context compaction as a transcript checkpoint

This branch includes the following new commits:

     new e4eda512a7 style(ui): present context compaction as a transcript checkpoint

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


(maka) 01/01: style(ui): present context compaction as a transcript checkpoint

Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

Astro-Han pushed a commit to branch style/context-compaction-checkpoint
in repository https://gitbox.apache.org/repos/asf/maka.git

commit e4eda512a7da4edf6be1fd6615040214efb6caa7
Author: AstroHan <le...@outlook.com>
AuthorDate: Mon Sep 7 22:31:48 2026 +0800

    style(ui): present context compaction as a transcript checkpoint
    
    Generated-by: Codex
---
 apps/desktop/stories/app-shell.stories.tsx         |  32 ++++--
 .../__tests__/chat-view-empty-compaction.test.tsx  | 116 +++++++++++++++++++++
 packages/ui/src/chat-turn.tsx                      |  66 +++++++-----
 packages/ui/src/materialize.ts                     |   9 +-
 packages/ui/src/styles.css                         |   4 +-
 5 files changed, 191 insertions(+), 36 deletions(-)

diff --git a/apps/desktop/stories/app-shell.stories.tsx b/apps/desktop/stories/app-shell.stories.tsx
index f1f49adb49..eb50613780 100644
--- a/apps/desktop/stories/app-shell.stories.tsx
+++ b/apps/desktop/stories/app-shell.stories.tsx
@@ -3238,9 +3238,11 @@ export const WorkbarCollapseKeepsOneToggleInPlace: Story = {
 // Real path (#3587): an explicit compaction runs as its own host Turn. The
 // transcript shows a live "正在压缩上下文…" row driven by the live Turn snapshot
 // (rootExecutionKind: 'context_compact'), with no assistant content of its own.
-export const ContextCompactionRunning: Story = {
-  render: () => (
+function CompactionRunningScene(props: { motionEnabled?: boolean }) {
+  const [startedAt] = useState(() => props.motionEnabled ? Date.now() - 25_000 : NOW - 2_000);
+  return (
     <ComposedShell
+      motionEnabled={props.motionEnabled}
       session={{ status: 'running', streaming: true }}
       chat={{
         runningStatus: true,
@@ -3248,19 +3250,22 @@ export const ContextCompactionRunning: Story = {
           user('msg-c-1', 'turn-c1', 6, '继续把上下文压缩那个功能实现完。'),
           assistant('msg-c-2', 'turn-c1', 5, '好的,我先梳理一下现有实现,再动手。'),
           { type: 'turn_state', id: 'state-c1', turnId: 'turn-c1', ts: NOW - 300_000, status: 'completed', partialOutputRetained: false },
-          { type: 'turn_state', id: 'state-compact', turnId: 'turn-compact', ts: NOW - 2_000, status: 'running', partialOutputRetained: false },
+          { type: 'turn_state', id: 'state-compact', turnId: 'turn-compact', ts: startedAt, status: 'running', partialOutputRetained: false },
         ],
         liveTurn: {
           turnId: 'turn-compact',
           phase: 'waiting',
           steps: [],
           rootExecutionKind: 'context_compact',
-          startedAt: NOW - 2_000,
+          startedAt,
         },
       }}
     />
-  ),
-};
+  );
+}
+
+export const ContextCompactionRunning: Story = { render: () => <CompactionRunningScene /> };
+export const ContextCompactionLive: Story = { render: () => <CompactionRunningScene motionEnabled /> };
 
 // Real path (#3587): the compaction Turn ends. The live row settles into the
 // durable `context_compacted` system note, rendered in transcript order.
@@ -3279,3 +3284,18 @@ export const ContextCompactionCompacted: Story = {
     />
   ),
 };
+
+export const ContextCompactionFailed: Story = {
+  render: () => (
+    <ComposedShell
+      chat={{
+        messages: [
+          user('msg-c-1', 'turn-c1', 6, '继续把上下文压缩那个功能实现完。'),
+          assistant('msg-c-2', 'turn-c1', 5, '好的,我先梳理一下现有实现,再动手。'),
+          { type: 'system_note', id: 'note-compact', turnId: 'turn-c1', ts: NOW - 1_000, kind: 'context_compaction_failed_open' },
+          { type: 'turn_state', id: 'state-c1', turnId: 'turn-c1', ts: NOW - 1_000, status: 'completed', partialOutputRetained: false },
+        ],
+      }}
+    />
+  ),
+};
diff --git a/packages/ui/src/__tests__/chat-view-empty-compaction.test.tsx b/packages/ui/src/__tests__/chat-view-empty-compaction.test.tsx
index 61edf716a8..f89eb5dd03 100644
--- a/packages/ui/src/__tests__/chat-view-empty-compaction.test.tsx
+++ b/packages/ui/src/__tests__/chat-view-empty-compaction.test.tsx
@@ -19,6 +19,11 @@
 
 import assert from 'node:assert/strict';
 import test from 'node:test';
+import { act } from 'react';
+import { createRoot } from 'react-dom/client';
+import { parseHTML } from 'linkedom';
+import { TurnView } from '../chat-turn.js';
+import { materializeTurns, overlayLiveTurn } from '../materialize.js';
 import { renderToStaticMarkup } from 'react-dom/server';
 import type { SessionSummary } from '@maka/core/session';
 import { ChatSurfaceLayout } from '../chat-surface-layout.js';
@@ -61,6 +66,10 @@ test('renders the live compaction row in a session with no settled messages', ()
   // Before the fix, showEmptyState hid this overlaid row behind the empty hero
   // because it keyed off chat.length (0) and never saw the synthesized turn.
   assert.match(markup, /Compacting context/);
+  const { document } = parseHTML(markup);
+  const row = document.querySelector('[data-compaction-state="running"]');
+  assert.equal(row?.getAttribute('data-variant'), 'divider');
+  assert.equal(row?.querySelector('.astryx-spinner')?.getAttribute('aria-hidden'), 'true');
 });
 
 test('renders the empty hero when an empty session has no live compaction row', () => {
@@ -68,3 +77,110 @@ test('renders the empty hero when an empty session has no live compaction row',
 
   assert.doesNotMatch(markup, /Compacting context/);
 });
+
+for (const [kind, state, variant] of [
+  ['context_compacted', 'compacted', 'divider'],
+  ['context_compaction_failed_open', 'failed', 'default'],
+] as const) {
+  test(`durable ${kind} renders the appropriate compaction state`, () => {
+    const [turn] = materializeTurns(
+      [{ type: 'system_note', id: 'note', turnId: 'compact', ts: 1000, kind }],
+      'en',
+    );
+    const { document } = parseHTML(
+      renderToStaticMarkup(
+        <LocaleProvider locale="en">
+          <TurnView turn={turn!} />
+        </LocaleProvider>,
+      ),
+    );
+    const row = document.querySelector('[data-compaction-state]');
+    assert.equal(row?.getAttribute('data-compaction-state'), state);
+    assert.equal(row?.getAttribute('data-variant'), variant);
+    assert.equal(row?.querySelector('.astryx-spinner'), null);
+  });
+}
+
+test('compaction clock uses the live Host start and disappears when the durable note takes over', async () => {
+  const previous = { window: globalThis.window, document: globalThis.document };
+  const actGlobals = globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT?: boolean };
+  const previousAct = actGlobals.IS_REACT_ACT_ENVIRONMENT;
+  const { window, document } = parseHTML('<div id="root"></div>');
+  Object.assign(globalThis, { window, document, IS_REACT_ACT_ENVIRONMENT: true });
+  const container = document.querySelector('#root')!;
+  const root = createRoot(container);
+  try {
+    const [turn] = overlayLiveTurn(
+      materializeTurns(
+        [
+          {
+            type: 'turn_state',
+            id: 'running',
+            turnId: 'compact',
+            ts: Date.now() - 60_000,
+            status: 'running',
+            partialOutputRetained: false,
+          },
+        ],
+        'en',
+      ),
+      {
+        turnId: 'compact',
+        phase: 'waiting',
+        steps: [],
+        rootExecutionKind: 'context_compact',
+        startedAt: Date.now() - 25_000,
+      },
+      'en',
+    );
+    await act(() =>
+      root.render(
+        <LocaleProvider locale="en">
+          <TurnView turn={turn!} />
+        </LocaleProvider>,
+      ),
+    );
+    const clock = container.querySelector('.maka-turn-elapsed')!;
+    assert.equal(clock.textContent, '25s');
+    assert.equal(clock.getAttribute('aria-hidden'), 'true');
+    await act(() => new Promise((resolve) => setTimeout(resolve, 1100)));
+    assert.equal(clock.textContent, '26s');
+    const [done] = materializeTurns(
+      [
+        {
+          type: 'system_note',
+          id: 'done',
+          turnId: 'compact',
+          ts: Date.now(),
+          kind: 'context_compacted',
+        },
+      ],
+      'en',
+    );
+    await act(() =>
+      root.render(
+        <LocaleProvider locale="en">
+          <TurnView turn={done!} />
+        </LocaleProvider>,
+      ),
+    );
+    assert.equal(container.querySelector('.maka-turn-elapsed'), null);
+    assert.equal(container.querySelector('.astryx-spinner'), null);
+    assert.equal(
+      container.querySelector('[data-compaction-state]')?.getAttribute('data-variant'),
+      'divider',
+    );
+    container.setAttribute('data-maka-e2e-fixture', 'true');
+    await act(() =>
+      root.render(
+        <LocaleProvider locale="en">
+          <TurnView turn={turn!} />
+        </LocaleProvider>,
+      ),
+    );
+    assert.equal(container.querySelector('.maka-turn-elapsed')?.textContent, '');
+  } finally {
+    await act(() => root.unmount());
+    Object.assign(globalThis, previous, { IS_REACT_ACT_ENVIRONMENT: previousAct });
+  }
+});
diff --git a/packages/ui/src/chat-turn.tsx b/packages/ui/src/chat-turn.tsx
index 153503f4f5..67b55a627d 100644
--- a/packages/ui/src/chat-turn.tsx
+++ b/packages/ui/src/chat-turn.tsx
@@ -608,9 +608,17 @@ export const TurnView = memo(function TurnView(props: {
         <ChatSystemMessage
           key={note.id}
           className="maka-chat-system-message"
-          aria-label={copy.systemAriaLabel}
+          variant={note.compactionState === "running" || note.compactionState === "compacted" ? "divider" : "default"}
+          data-compaction-state={note.compactionState}
+          aria-label={note.compactionState === "running" ? note.text : copy.systemAriaLabel}
         >
-          {note.text}
+          {note.compactionState ? (
+            <span className="maka-compaction-status">
+              {note.compactionState === "running" && <Spinner size="sm" shade="subtle" aria-hidden="true" />}
+              <span>{note.text}</span>
+              {note.compactionState === "running" && <TurnElapsedTime startedAt={note.ts} />}
+            </span>
+          ) : note.text}
         </ChatSystemMessage>
       ))}
       {conversationSegments.map((segment, segmentIndex) => {
@@ -992,8 +1000,30 @@ export function TurnRunningStatus(props: {
   activityLabel?: string;
 }) {
   const copy = getConversationCopy(useUiLocale()).messages;
+
+  return (
+    <div
+      className="maka-turn-processing"
+      role="status"
+      aria-label={props.activityLabel ?? copy.awaitingModelOutput}
+    >
+      {props.showSpinner !== false && (
+        <Spinner size="md" shade="subtle" aria-hidden="true" />
+      )}
+      {/* Name the activity once; the clock must not announce each second. */}
+      <span className="maka-turn-indicator-text" aria-hidden="true">
+        <span className="maka-turn-status-label">
+          {props.activityLabel ?? copy.awaitingModelOutput}
+        </span>
+        <TurnElapsedTime startedAt={props.startedAt} separator />
+      </span>
+    </div>
+  );
+}
+
+function TurnElapsedTime(props: { startedAt?: number; separator?: boolean }) {
   const { startedAt } = props;
-  const rootRef = useRef<HTMLDivElement>(null);
+  const rootRef = useRef<HTMLSpanElement>(null);
   // Undefined until an effect measures it, which is also what keeps a static
   // render deterministic: the clock is a client-only value, so server markup
   // and the first paint carry the phrase alone.
@@ -1013,30 +1043,12 @@ export function TurnRunningStatus(props: {
   }, [startedAt]);
 
   return (
-    <div
-      className="maka-turn-processing"
-      role="status"
-      aria-label={props.activityLabel ?? copy.awaitingModelOutput}
-      ref={rootRef}
-    >
-      {props.showSpinner !== false && (
-        <Spinner size="md" shade="subtle" aria-hidden="true" />
-      )}
-      {/* Every visible token here moves on the clock. Announcing either would
-          talk over the answer being streamed beside it, so the row's label is
-          its whole accessible name and the text is decoration. */}
-      <span className="maka-turn-indicator-text" aria-hidden="true">
-        <span className="maka-turn-status-label">
-          {props.activityLabel ?? copy.awaitingModelOutput}
-        </span>
-        {elapsedMs !== undefined && (
-          <>
-            <span className="maka-turn-status-separator">·</span>
-            <span className="maka-turn-elapsed">{formatTurnDuration(elapsedMs)}</span>
-          </>
-        )}
-      </span>
-    </div>
+    <span className="maka-turn-elapsed" aria-hidden="true" ref={rootRef}>
+      {elapsedMs !== undefined && <>
+        {props.separator && <span className="maka-turn-status-separator">·</span>}
+        {formatTurnDuration(elapsedMs)}
+      </>}
+    </span>
   );
 }
 
diff --git a/packages/ui/src/materialize.ts b/packages/ui/src/materialize.ts
index 3cacfa985c..16a4410825 100644
--- a/packages/ui/src/materialize.ts
+++ b/packages/ui/src/materialize.ts
@@ -49,6 +49,7 @@ import { getConversationCopy } from "./conversation-copy.js";
 export { isCancelledToolResultContent, isInFlightToolStatus, toolResultActivityStatus } from '@maka/core/tool-result-status';
 
 export interface ChatItem {
+  compactionState?: "running" | "compacted" | "failed";
   id: string;
   role: "user" | "assistant" | "system";
   text: string;
@@ -227,6 +228,7 @@ export function materializeChat(
         id: message.id,
         role: "system",
         text: systemNoteLabel(message.kind, message.data, locale),
+        compactionState: message.kind === "context_compacted" ? "compacted" : message.kind === "context_compaction_failed_open" ? "failed" : undefined,
         ts: message.ts,
       });
     }
@@ -478,7 +480,8 @@ export function overlayLiveTurn(
         id: noteId,
         role: "system",
         text: getConversationCopy(locale).messages.systemNotes.contextCompacting,
-        ts: existing.startedAt,
+        compactionState: "running",
+        ts: liveTurn.startedAt ?? existing.startedAt,
       };
       return turns.map((turn, index) =>
         index === targetIndex ? { ...turn, notes: [...turn.notes, note] } : turn,
@@ -496,7 +499,8 @@ export function overlayLiveTurn(
             id: noteId,
             role: "system",
             text: getConversationCopy(locale).messages.systemNotes.contextCompacting,
-            ts: startedAt,
+            compactionState: "running",
+            ts: liveTurn.startedAt,
           },
         ],
         timeline: [],
@@ -855,6 +859,7 @@ export function materializeTurns(
         id: message.id,
         role: "system",
         text: systemNoteLabel(message.kind, message.data, locale),
+        compactionState: message.kind === "context_compacted" ? "compacted" : message.kind === "context_compaction_failed_open" ? "failed" : undefined,
         ts: message.ts,
       });
     } else if (message.type === "token_usage") {
diff --git a/packages/ui/src/styles.css b/packages/ui/src/styles.css
index ecbdf18e9b..c9881f00c9 100644
--- a/packages/ui/src/styles.css
+++ b/packages/ui/src/styles.css
@@ -243,7 +243,9 @@
 .maka-turn-status-label { font-weight: var(--font-weight-medium); }
 .maka-turn-status-separator { color: var(--foreground-alpha-16); }
 /* Tabular figures so a ticking clock changes glyphs without changing width. */
-.maka-turn-elapsed { font-variant-numeric: tabular-nums; }
+.maka-turn-elapsed { display: inline-flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
+.maka-turn-elapsed:empty { display: none; }
+.maka-compaction-status { display: inline-flex; align-items: center; gap: 8px; font: var(--maka-text-body); vertical-align: top; }
 /* #1879: an Astryx `Badge variant="yellow"` now — the warning tone it used to
    draw by hand (hairline + 5% wash) is a variant, and the box comes with it.
    Product CSS keeps only what is layout: it is a block-level note under the


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org