Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .scratch/cot-variants/PRD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
Status: done
---

# 思维链(Chain of Thought)形态探索 — 决策记录

2026-08-09,从 `/proto` 原型跑了 4 个变体(基于真实数据形态:Pi 一条 assistant 消息 =
`thinking | tool_call | text` 的有序 part 序列,think→tool→think 多轮循环是一等公民,
见 `packages/core/src/agent-runtime-event.ts:21`),对比后决策如下。

## 决策

- **Baseline(现状,折叠一行 + 左边线步骤列表)保持默认**。ChatChainOfThought 不动。
- **Rail(时间轨)保留为正式组件** `shared/ui/chat/chat-chain-of-thought-rail.tsx`:
轮次分界 + 节点轨道,思考/工具是不同形态节点,每步时长右对齐(tabular-nums)。
暂不在 agent-workspace 接线;等 Appearance 设置页落地后作为用户可选项
(见 issues/01)。
- **Ledger(台账,等宽五列网格)不进聊天流**,但形态验证成功,定为 **Trace 页重构方向**
(见 issues/02)。原型实现要点:等宽字体、`kind/name/subject/duration` 网格列、
轮次分隔线、行内展开 payload、状态字形(✓/✕/●)。
- **Narrative(叙事流,工具压成行内 chip)淘汰**:设计不成立——工具信息弱化过头,
chip 超过一排后挤压严重,气质上也没有带来足够收益。

## 关键实现记号(从原型带出)

- 节点圆点必须按节点类型分别对齐首行中心(思考标签行中心 ≈12px,32px 工具行中心
≈16px),统一 top 值必然错位。
- 说明性 `<p>` 在深色浮层里要显式设 color,应用全局段落色(近黑)会压过继承。
- 工具行 target 提取与时长格式化直接复用 `chat-tool.tsx` 的
`toolTargetFromArgs` / `formatToolDuration`。

## 原型位置(已拆除)

原型面 `apps/desktop/src/proto/chain-of-thought/` 与 `main.tsx` 中带
`proto:chain-of-thought` 栅栏注释的 dev-only 挂载已在决策后删除。
24 changes: 24 additions & 0 deletions .scratch/cot-variants/issues/01-appearance-setting-cot-style.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
Status: needs-triage
---

# Appearance 设置:思维链样式可选项(Baseline / Rail)

## 背景

思维链形态探索(见 ../PRD.md)决定同时保留两种渲染:默认 Baseline
(`ChatChainOfThought`),可选 Rail(`ChatChainOfThoughtRail`,已落
`shared/ui/chat/` 并注册 /design 页)。

## 要做的事

- 等 Settings 出现 Appearance 分区时,增加 "Chain of thought style" 选项:
`Compact(默认,Baseline)` / `Timeline(Rail)`。
- 偏好持久化(跟随现有 settings 存储机制),agent-workspace 的
`AssistantRunTrace` 按偏好在两个组件间切换。
- 两种样式共用同一数据(RunTimelineItem 序列),切换不改行为契约
(data-slot 断言、折叠默认值 DF-005B 的 remount 逻辑保持)。

## 阻塞

- 依赖 Appearance 设置页立项(当前 Settings 只有 Provider 配置)。
20 changes: 20 additions & 0 deletions .scratch/cot-variants/issues/02-trace-page-ledger-refactor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
Status: needs-triage
---

# Trace 页重构:采用台账(Ledger)形态

## 背景

思维链形态探索(见 ../PRD.md)中,Ledger 变体(等宽字体、kind/name/subject/duration
对齐网格、轮次分隔、行内展开 payload、✓/✕/● 状态字形)被验证为高密度扫读 trace 的
最佳形态——12.4s 的失败 Bash 一眼跳出。它不适合聊天流,但正好命中 Trace 页
"做得不好看、信息密度低"的痛点。

## 要做的事

- 以 Ledger 形态重构 Trace 页的会话事件列表(`pages/trace.tsx` / session-detail)。
- 从原型提炼网格列:状态字形 / kind / 名称 / 对象(target 截断) / 右对齐 tabular-nums
时长;轮次(或消息)分隔线;行内展开 args/output。
- 组件落 `shared/ui/`(命名待定,如 `pi-trace-ledger`),同 PR 注册 /design 页。
- 原型参考实现见 ../PRD.md 的"关键实现记号"(原型代码已拆除,形态见决策记录)。
83 changes: 83 additions & 0 deletions apps/desktop/src/pages/design-components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { PiBarChart } from "@/shared/ui/pi-bar-chart";
import { PiKpi } from "@/shared/ui/pi-kpi";
import { PiSheet } from "@/shared/ui/pi-sheet";
import { ChatChainOfThought } from "@/shared/ui/chat/chat-chain-of-thought";
import {
ChatChainOfThoughtRail,
type ChainOfThoughtRailPart,
} from "@/shared/ui/chat/chat-chain-of-thought-rail";
import { ChatCodeBlock } from "@/shared/ui/chat/chat-code-block";
import { ChatConversation } from "@/shared/ui/chat/chat-conversation";
import { ChatMarkdown, ChatStreamMarkdown } from "@/shared/ui/chat/chat-markdown";
Expand Down Expand Up @@ -513,6 +517,84 @@ function ChatChainOfThoughtGallery() {
);
}

const railParts: ChainOfThoughtRailPart[] = [
{
kind: "thinking",
id: "rail-t1",
durationMs: 8200,
text: "The failing assertion says the replay projection dropped the tool_call part after a fork — reading the projection code first.",
},
{
kind: "tool",
id: "rail-c1",
tool: {
toolName: "Read",
toolCallId: "rail-call-1",
state: "output-available",
durationMs: 320,
argsText: JSON.stringify({ path: "packages/backend/src/workspace/fork.ts" }),
output: "77 remapEntryId(part.piEntryId)\n81 part.toolCallId // never remapped",
},
},
{
kind: "tool",
id: "rail-c2",
tool: {
toolName: "Bash",
toolCallId: "rail-call-2",
state: "output-error",
durationMs: 12400,
argsText: JSON.stringify({ command: "bun test packages/backend/src/workspace" }),
output: "1 tests failed:\n ✗ replays forked session [4012ms]",
},
},
{
kind: "thinking",
id: "rail-t2",
durationMs: 2100,
text: "Root cause confirmed: toolCallId is never remapped on fork. Fixing.",
},
{
kind: "tool",
id: "rail-c3",
tool: {
toolName: "Grep",
toolCallId: "rail-call-3",
state: "input-streaming",
argsText: JSON.stringify({ pattern: "remapToolCallId" }),
},
},
];

function ChatChainOfThoughtRailGallery() {
return (
<GallerySection title="ChatChainOfThoughtRail">
<div className="flex max-w-xl flex-col gap-4">
<Variant caption="expanded, settled — rounds with done/failed tools">
<ChatChainOfThoughtRail
defaultExpanded
parts={railParts.slice(0, 4)}
summary="Thought for 23s · 2 tool calls"
/>
</Variant>
<Variant caption="streaming — expanded by default, running tool pulses">
<ChatChainOfThoughtRail
isStreaming
parts={railParts}
summary="Thinking…"
/>
</Variant>
<Variant caption="collapsed, settled">
<ChatChainOfThoughtRail
parts={railParts.slice(0, 4)}
summary="Thought for 23s · 2 tool calls"
/>
</Variant>
</div>
</GallerySection>
);
}

function ChatConversationGallery() {
return (
<GallerySection title="ChatConversation">
Expand Down Expand Up @@ -559,6 +641,7 @@ export function DesignComponentsLayer() {
<ChatPromptInputGallery />
<ChatPromptSuggestionGallery />
<ChatChainOfThoughtGallery />
<ChatChainOfThoughtRailGallery />
<ChatConversationGallery />
<TextShimmerGallery />
</>
Expand Down
109 changes: 109 additions & 0 deletions apps/desktop/src/shared/ui/chat/chat-chain-of-thought-rail.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, expect, it } from "vitest";
import {
ChatChainOfThoughtRail,
type ChainOfThoughtRailPart,
} from "@/shared/ui/chat/chat-chain-of-thought-rail";

const parts: ChainOfThoughtRailPart[] = [
{ kind: "thinking", id: "t1", text: "Reading the projection first.", durationMs: 8200 },
{
kind: "tool",
id: "c1",
tool: {
toolName: "Read",
toolCallId: "call_1",
state: "output-available",
durationMs: 320,
argsText: JSON.stringify({ path: "packages/backend/src/workspace/fork.ts" }),
output: "77 remapEntryId(part.piEntryId)",
},
},
{
kind: "tool",
id: "c2",
tool: {
toolName: "Bash",
toolCallId: "call_2",
state: "output-error",
durationMs: 12400,
argsText: JSON.stringify({ command: "bun test packages/backend" }),
output: "1 tests failed",
},
},
{ kind: "thinking", id: "t2", text: "Root cause confirmed, fixing.", durationMs: 2100 },
];

describe("ChatChainOfThoughtRail", () => {
it("groups think→tool loops into labeled rounds with distinct node kinds", () => {
const { container } = render(
<ChatChainOfThoughtRail defaultExpanded parts={parts} summary="Thought for 23s" />,
);

expect(
container.querySelector('[data-slot="chain-of-thought-rail"]'),
).toBeInTheDocument();
expect(screen.getByText("Round 1")).toBeInTheDocument();
expect(screen.getByText("Round 2")).toBeInTheDocument();

const nodes = container.querySelectorAll('[data-slot="chain-of-thought-rail-node"]');
expect(nodes).toHaveLength(4);
expect(nodes[0]).toHaveAttribute("data-kind", "thinking");
expect(nodes[1]).toHaveAttribute("data-kind", "tool");
});

it("shows tool name, extracted target, duration, and error state", () => {
const { container } = render(
<ChatChainOfThoughtRail defaultExpanded parts={parts} summary="Thought for 23s" />,
);

expect(screen.getByText("Read")).toBeInTheDocument();
expect(screen.getByText("packages/backend/src/workspace/fork.ts")).toBeInTheDocument();
expect(screen.getByText("320ms")).toBeInTheDocument();
expect(screen.getByText("failed")).toBeInTheDocument();
expect(
container.querySelector('[data-slot="chain-of-thought-rail-node"][data-state="output-error"]'),
).toBeInTheDocument();
});

it("reveals args and output when a tool row is expanded", async () => {
const user = userEvent.setup();
render(
<ChatChainOfThoughtRail defaultExpanded parts={parts} summary="Thought for 23s" />,
);

const detail = screen.getByText("77 remapEntryId(part.piEntryId)", { exact: false });
expect(detail.closest("details")).not.toHaveAttribute("open");

await user.click(screen.getByText("Read"));

expect(detail.closest("details")).toHaveAttribute("open");
});

it("collapses by default when settled and toggles from the trigger", async () => {
const user = userEvent.setup();
render(<ChatChainOfThoughtRail parts={parts} summary="Thought for 23s" />);

const trigger = screen.getByRole("button", { name: "Thought for 23s" });
expect(trigger).toHaveAttribute("aria-expanded", "false");

await user.click(trigger);
expect(trigger).toHaveAttribute("aria-expanded", "true");
});

it("streams: expands by default and shimmers the trigger label", () => {
const { container } = render(
<ChatChainOfThoughtRail
isStreaming
parts={parts}
summary="Thought for 23s"
/>,
);

const trigger = screen.getByRole("button");
expect(trigger).toHaveAttribute("aria-expanded", "true");
expect(trigger).toHaveTextContent("Thinking…");
expect(container.querySelector('[data-slot="text-shimmer"]')).toBeInTheDocument();
});
});
Loading