A local-first multi-agent app development platform, built on PenguinHarness
fix(web): a conversation opens on its latest 50 turns instead of the whole transcript (#665)
Yaowei Zheng08898a44fdfc
diff --git a/changelog/unreleased/2026-09-10-history-window-fifty-turns.md b/changelog/unreleased/2026-09-10-history-window-fifty-turns.mdnew file mode 100644index 00000000..d7d8bcd8--- /dev/null+++ b/changelog/unreleased/2026-09-10-history-window-fifty-turns.md@@ -0,0 +1,15 @@+# A conversation opens on its latest 50 turns instead of the whole transcript++- **Date:** 2026-09-10+- **Type:** fix+- **Scope:** `web`, `docs`+- **PR:** [#665](https://github.com/Prism-Shadow/penguin-harness/pull/665)++[中文版](2026-09-10-history-window-fifty-turns.zh.md)++Opening a conversation in the Web App now fetches its latest 50 turns, and scrolling near the top backfills 50 more at a time. The history window existed already, but its tail size of 200 Tasks covered nearly every real Session, so every open still read, shipped and rendered the whole transcript, tool output included; long agentic Sessions took seconds to open for content nobody was looking at.++## Details++- The initial history window is 50 Tasks (was 200) and each scroll-up backfill fetches 50 (was 100). The window mechanics are unchanged: Task-aligned cuts, reading position held across a prepend, the beginning-of-conversation marker, the click-to-retry row, and turn numbering and header statistics seeded from the server's cumulative values so a windowed load matches a full one.+- The server API docs describe the `tailLimit` / `before`+`limit` window forms and the `page` envelope of `GET /api/sessions/:sessionId/messages`, and the Web App docs describe the 50-turn window.diff --git a/changelog/unreleased/2026-09-10-history-window-fifty-turns.zh.md b/changelog/unreleased/2026-09-10-history-window-fifty-turns.zh.mdnew file mode 100644index 00000000..b1c4c0b5--- /dev/null+++ b/changelog/unreleased/2026-09-10-history-window-fifty-turns.zh.md@@ -0,0 +1,15 @@+# 对话打开只加载最近 50 轮,不再一次载入整段历史++- **Date:** 2026-09-10+- **Type:** fix+- **Scope:** `web`, `docs`+- **PR:** [#665](https://github.com/Prism-Shadow/penguin-harness/pull/665)++[English](2026-09-10-history-window-fifty-turns.md)++Web App 打开一个对话现在只拉取最近 50 轮,滚动到顶部附近时每次再向前续载 50 轮。历史窗口机制早已存在,但尾窗取 200 个 Task,几乎所有真实 Session 都装得下,于是每次打开仍然把整段历史(含工具输出)读完、传完、渲染完;长时间的 Agent 会话要花好几秒打开一堆没人在看的内容。++## 细节++- 初始历史窗口为 50 个 Task(原 200),每次向上滚动续载 50 个(原 100)。窗口机制不变:按 Task 边界切分、插入时保持阅读位置、到达开头的标记、失败后的点击重试,以及由服务端随窗口附带的累计值接续轮次编号与顶部统计,使窗口加载与整段加载一致。+- 服务端 API 文档补充 `GET /api/sessions/:sessionId/messages` 的 `tailLimit` / `before`+`limit` 窗口形式与 `page` 字段;Web App 文档说明 50 轮窗口。diff --git a/packages/docs/content/server-api.en.md b/packages/docs/content/server-api.en.mdindex c3f7a933..2e5f1e27 100644--- a/packages/docs/content/server-api.en.md+++ b/packages/docs/content/server-api.en.md@@ -270,7 +270,7 @@ The paths below omit the `/api/sessions/:sessionId` prefix. For the storage mode| GET | / | Session info (the single-session GET additionally carries `tracePath`, the absolute path of the latest Trace file; list rows omit it) || PATCH | / | Update: `{approvalMode?, thinkingLevel?, archived?, title?}`. `thinkingLevel` pins the level on this Session (durable) and applies from its very next LLM request — the thinking level is soft-limited: changeable mid-context, at the cost of the provider's cached context, which is why the picker advises compacting first — and it comes back as `SessionInfo.thinkingLevel` (absent = never pinned: the Agent config applies) || DELETE | / | Delete the Session (along with its Traces and scratch files) |-| GET | /messages | Full OmniMessage history; while a Task runs the response also carries `live` (the in-progress stream tail, see below) |+| GET | /messages | Without parameters, the full OmniMessage history; `tailLimit=n` or `before=<cursor>&limit=n` reads a Task-aligned window instead (the bundled Web App opens a conversation on its latest 50 turns and backfills on scroll), and the response then carries `page` (the next-page cursor `before`, the turns before the window `earlierTurns`, and the cumulative `prior` stats). While a Task runs the response also carries `live` (the in-progress stream tail, see below) || POST | /fork | Fork an idle Session through a completed assistant reply: `{position:{fileIndex,ordinal}}` → `{session}` || GET | /stream | SSE event stream (next section) || POST | /tasks | Start a Task: `{input: TaskInputPart[], queueIfBusy?}` → 202. With `queueIfBusy`, a busy session holds the input as a follow-up (`queued: true`) and auto-starts it as an ordinary next task once idle; `task_state` events report the queued count. `file` input parts are written to the Session scratchpad and handed to the model as `[attached file: <path>]` lines (see the request body below). With `goal: {budget?}` the input starts a goal loop instead (409 `goal_plugin_not_installed` unless the `goal` plugin is installed on the Agent): it must carry non-empty text (an image alone states no objective), any images it carries fold into the objective as scratchpad path lines whatever the model's vision, and `file` parts are refused — nothing folds them into a re-injected objective — see [Goal mode](/goal-mode) |diff --git a/packages/docs/content/server-api.zh.md b/packages/docs/content/server-api.zh.mdindex f7beb90d..bae307d3 100644--- a/packages/docs/content/server-api.zh.md+++ b/packages/docs/content/server-api.zh.md@@ -270,7 +270,7 @@ Trace 下载对任意成员开放;导入仅限 owner(同 Agent 快照导入| GET | / | Session 信息(单会话 GET 额外携带 `tracePath`:最新 Trace 文件的绝对路径;列表行不含) || PATCH | / | 更新:`{approvalMode?, thinkingLevel?, archived?, title?}`。`thinkingLevel` 将思考等级钉在该 Session 上并持久化,自下一次 LLM 请求起生效——思考等级是软限制参数:允许中途更换,代价是提供商的缓存失效,因此选择器会建议先压缩;读取时由 `SessionInfo.thinkingLevel` 返回(缺省即从未钉住:按 Agent 配置生效) || DELETE | / | 删除 Session(连同 Trace 与暂存文件) |-| GET | /messages | 完整 OmniMessage 历史;Task 运行期间响应额外携带 `live`(进行中的流式尾部,见下) |+| GET | /messages | 无参数时返回完整 OmniMessage 历史;`tailLimit=n` 或 `before=<游标>&limit=n` 改为读取一个按 Task 切分的窗口(自带 Web App 打开对话只读最近 50 轮,滚动到顶部再续载),此时响应携带 `page`(下一页游标 `before`、窗口前的轮数 `earlierTurns` 与累计统计 `prior`)。Task 运行期间响应额外携带 `live`(进行中的流式尾部,见下) || POST | /fork | 从一条已完成的模型回复分叉空闲 Session:`{position:{fileIndex,ordinal}}` → `{session}` || GET | /stream | SSE 事件流(见下节) || POST | /tasks | 发起 Task:`{input: TaskInputPart[], queueIfBusy?}` → 202。带 `queueIfBusy` 时,运行中的 Session 会把输入暂存为跟进消息(`queued: true`),空闲后按序自动作为普通 Task 发出;`task_state` 事件携带排队数。`file` 类型的输入会写入 Session scratchpad,以 `[attached file: <路径>]` 行交给模型(见下方请求体)。带 `goal: {budget?}` 时该输入转为发起目标循环(Agent 未安装 `goal` 插件则 409 `goal_plugin_not_installed`):必须含非空文字(一张图说明不了目标),随行的图片一律折叠成 scratchpad 路径行写入目标文本、与模型是否支持视觉无关,而 `file` 会被拒绝——没有东西能把它折进每轮重注入的目标里——见[目标模式](/goal-mode) |diff --git a/packages/docs/content/web-app.en.md b/packages/docs/content/web-app.en.mdindex 4b9599e8..acf5b6fe 100644--- a/packages/docs/content/web-app.en.md+++ b/packages/docs/content/web-app.en.md@@ -59,6 +59,7 @@ Pinning is offered only in the active list — the archived, subagent and schedu- A context compaction leaves a row whose title doubles as its status, the work-group header's Running/Done idiom: Compacting while it runs and Compacted once it settles (Clearing/Cleared for a discard), with its wall time; while a summarize runs the row is open: its thinking section appears once the request's thinking arrives, and its result section only after that thinking finishes, when the first summary text lands — each closed by default, each with its own wall time — and the row closes itself again once the compaction settles, leaving the one line; a failed compaction keeps the bare mode word (Compaction, or Clear) over a one-line reason instead;- Subagents leave a full-width row in the stream, styled like the other collapsed step rows (agent avatar, name, short session id, running spinner, and an amber dot while one of their tool calls awaits approval); clicking it opens the agents side panel — a call graph of that row's Task on top (each node shows its elapsed time; click a node to switch) and the selected child's live conversation below — the child's own user prompts included — where nested tool cards and approvals work exactly as in the main chat. Panel visibility is task-scoped: sending a message that starts a new task closes it by default (entering a session starts closed too), and it comes back when you open it yourself or — on desktop — when the current task spawns a subagent (one auto-open per task; a manual close holds until the next task; never over an open files panel). Opening the panel from the toolbar, or switching sessions, shows the latest Task's graph; a row on an older turn brings back that turn's graph. The agents panel and the Workspace files panel never show together — opening one closes the other. Context compaction and the first-run MCP connect show a unified step row (the work-group header shell, sticky title bar included — running/success/failure only swap the icon and the one-line detail, with the wall time on the result; the MCP row leads with the discovered-tool count and names unavailable servers, and expands into one group per server — status, tool count and that server's connect time — each opening into its tool list or the failure detail);- After each Task, a stats line shows tokens, TPS, elapsed time, cost, copy, and a **Fork** action to the right of copy. Fork asks for confirmation first — it duplicates the conversation into a new chat — and only then opens a new Session at that completed assistant reply with the same Agent, model, Workspace, approval mode, and retained transcript. Forks from different replies in one source chat share an increasing, language-neutral title sequence (`Source title (1)`, `Source title (2)`). Its Trace and scratchpad are independent snapshots: local images/files keep rendering even after the source chat is deleted;+- Opening a conversation loads its latest 50 turns; scrolling near the top backfills 50 more with your reading position held in place, the beginning of the conversation is marked once nothing older remains, and a failed backfill offers a retry. Turn numbering and the header statistics continue from the cumulative values the server sends with the window, so they match a full load.### Header Stats and the Details Carddiff --git a/packages/docs/content/web-app.zh.md b/packages/docs/content/web-app.zh.mdindex cef75c10..feada6c8 100644--- a/packages/docs/content/web-app.zh.md+++ b/packages/docs/content/web-app.zh.md@@ -59,6 +59,7 @@ penguin web- 上下文压缩在消息流中留下一行,标题兼作状态、与工作分组组头的「运行中」/「运行完毕」同一写法:按实际动作写作「压缩中」/「压缩完毕」,discard 则为「清空中」/「清空完毕」,并带用时;summarize 运行期间该行展开:压缩请求的思考一到就出现「思考」一节,「压缩结果」一节要等思考结束、第一段摘要文本抵达后才出现——两节默认折叠、各带自己的用时——压缩结束后该行自行收起,只留下这一行;失败的压缩保留裸的「压缩」或「清空」标题与一行原因;- 子 Agent 在消息流中只留下一条通栏行,样式与其他折叠步骤行一致(头像、名称、短会话号、运行中转圈,子会话内有待审批时带琥珀色圆点);点击打开右侧智能体面板——上方是该行所属 Task 派生关系的调用图(节点上显示运行时长,点节点切换),下方是所选子会话的实时对话(含子会话自己的用户消息),嵌套工具卡片与审批与主对话完全一致;面板的显示以任务为界:发送消息开启新任务时默认关闭(进入会话时同样默认关闭),仅在手动打开、或(桌面端)当前任务派生子智能体时重新显示(每个任务自动打开一次,任务内手动关闭后保持关闭到下个任务,且不抢占已打开的工作区面板);从工具条打开面板或切换 Session 时默认展示最新 Task 的调用图,点旧轮次的行则回看那一轮的调用图;智能体面板与工作区面板不会同时显示,打开一个即关闭另一个;上下文压缩与首次 MCP 连接以统一样式的步骤行提示(与运行分组头同款外壳,含吸顶标题栏,连接中/成功/失败仅切换图标与单行详情,结果行含耗时;MCP 行主显发现的工具数并点名不可用的 Server,展开后按 Server 分组——每组一行状态、工具数与该 Server 的连接耗时,点开组内是工具列表或失败原因);- 每个 Task 结束后显示统计行:Token 用量、TPS、耗时、费用、复制以及位于复制按钮右侧的**分叉**操作。分叉会先弹出确认框(该操作会把对话复制为一个新对话),确认后才在该条已完成的模型回复处新建 Session,沿用 Agent、模型、Workspace、审批模式和保留范围内的历史;同一源对话从不同回复分叉时,标题使用不依赖界面语言的编号后缀,按 `原标题 (1)`、`原标题 (2)` 递增。新旧会话的 Trace 与 scratchpad 是独立快照,即使删除源对话,本地图片和附件仍可显示;+- 打开一个对话只加载最近 50 轮;滚动到顶部附近会自动向前续载 50 轮,阅读位置保持不动,载到开头显示「已是对话开头」,续载失败则点击重试。轮次编号与顶部统计由服务端随窗口附带的累计值接续,与整段加载一致。### 头部统计与详情卡diff --git a/packages/web/src/lib/omni/stream-controller.ts b/packages/web/src/lib/omni/stream-controller.tsindex 2c302fdd..5fd77bf6 100644--- a/packages/web/src/lib/omni/stream-controller.ts+++ b/packages/web/src/lib/omni/stream-controller.ts@@ -83,16 +83,16 @@ export type MessagesPageQuery =/*** Initial (tail) window size, in message-bearing units — one unit = one Task, opened by- * a user prompt (the server's cut rule; see MessagesPageInfo). 200 covers the vast- * majority of real sessions in a single request, so ordinary conversations still load- * whole exactly as before — only the pathological long tail (months-long sessions,- * agentic marathons) starts windowed, which is the point: their full-transcript reads- * were the unbounded memory/disk cost this pagination removes.+ * a user prompt (the server's cut rule; see MessagesPageInfo). 50 is what a reader+ * actually looks at when a conversation opens: the rest of a long Session streams in on+ * scroll (see loadOlder). Anything much larger stops being a window at all — at 200 the+ * tail covered nearly every real Session, so every open still read, shipped and rendered+ * the whole transcript, tool output included.*/-export const TAIL_UNITS = 200;+export const TAIL_UNITS = 50;-/** Scroll-up backfill window size: smaller than the tail so each prepend stays snappy. */-export const OLDER_UNITS = 100;+/** Scroll-up backfill window size: one more tail's worth per prepend, so each stays snappy. */+export const OLDER_UNITS = 50;/*** Item-id space reserved per prepended window. The live model numbers its items upward