feat(backend): 上下文蒸发纯函数核心(P1) - #29
Closed
Jaxton07 wants to merge 8 commits into
Closed
Conversation
内置扩展(backend/src/tools/channel-watch/ 八模块):订阅
.local/agent-work/channel/<topic>/ 目录,他人写入 → 3s 防抖 →
hash 去重 → 自写抑制 → followUp 唤醒注入。防环三层:自写 10s
窗口 + sha256 内容快照 + 乒乓上限(≥6 次/10min 暂停)。
- subscriptions 恢复 last-wins(退订空集不幽灵复活,含回归测试)
- 唤醒管道可观测:成功投递/抑制均 log.info 带 topic/relPath/reason
- 设置页通用面板开关(channelWatch:getConfig/setEnabled IPC,
settings.json channelWatchEnabled 默认开,仅显式 false 关)
- 修订版协作 skill 随包分发:resources/skills/{channel-pickup,
design-handoff},additionalSkillPaths 扫描(.agents/skills/
旧副本已删,防优先级链压制内置版)
- 测试:backend 412(channel-watch 34 个,含 bash 旁路 cat>>
补测);冒烟 scripts/smoke-channel-watch.mts V1–V6
TokenGate 的 failed state 永不置 true,「令牌无效」文案不可达(UX v2 review 发现)。改为 store 级信号:LanAppState 加 authFailed,logout() (仅由三处 401 触发)置 true,setToken() 重试时清;组件删掉死 local state,错误块改读 store。
快模型流式高峰(50-100+ delta/s)时每条 IPC 各自触发 zustand set → 全 App 级联重渲染 + 全量行重建,与状态行动画/CenterOrb 争抢主线程掉帧。 - 新增 stores/event-conflator.ts:App onEvent 与 transcript store 之间按帧合流, 纯追加型 delta(text/thinking/toolcall_delta、string partialResult)同键原地 拼接每帧最多一次提交;边界事件先冲刷再立即透传,顺序语义与逐条转发严格一致; 隐藏页 setTimeout 250ms 兜底,dispose 冲刷不丢尾帧 - App.tsx:selector 收敛为原始值 showEmpty(App 及无 memo 子树退出 delta 级联) - MessageList.tsx:buildChatRows 包 useMemo(局部 state 翻转不再全量重建行模型) - chat-rows.ts:历史 MetaItem 走 committedMetaCache WeakMap(键=消息对象), items 引用跨渲染稳定 - MetaGroup.tsx:React.memo + metaGroupPropsEqual(items 逐元素身份比较), 流式期间历史折叠组完全静止 - 测试:event-conflator.test.ts 8 例(合并/边界保序/多会话/隐藏兜底/缺 contentIndex 透传)+ chat-rows.test.ts 引用稳定性 2 例
- 新工具 channel_post({topic, message, closed?}):消息追加到频道 MESSAGES.md
(时间戳精确到秒 + 来源会话标记),closed=true 为终态信号(订阅方查收后退订)
- watcher 投递收窄:仅 MESSAGES.md 触发唤醒,频道内其余文件静默——根治
「一次任务写 N 个文件 = N 条唤醒」,沟通成为 agent 主动行为
- 唤醒文案改为一行「有新消息,请读 MESSAGES.md 查收」
- post 经 appendFile 绕过 tool_call 钩子,手动 markSelfWrite 防自订阅自唤醒
- skill 文档(design-handoff/channel-pickup)协议同步:写文件 ≠ 通知,
post = 通知;终态 closed → 订阅方 channel_unsubscribe(系统不自动踢人)
- 测试 20 个全绿:新增双会话联动(A post→B 唤醒/A 不自醒)、自订阅抑制、
closed 落盘、非 MESSAGES 静默;typecheck/lint 全过
- spec: .local/agent-work/spec/channel-post.md
用户气泡等纯文本容器只有 whitespace-pre-wrap,无断词规则,超长无空格
token(如带长 query 的微信链接)不可折行,横向溢出气泡并被聊天容器
overflow-x-hidden 裁掉。
- 用户气泡正文 / skill 分支文本 / 压缩摘要 / 思考内容:+ break-words
- 工具参数/输出 <pre>(等宽技术文本):+ break-all(对齐 ApprovalDock 约定)
助手 markdown 侧无需改:markstream 自带 .text-node { word-break: break-word },
已实测 231 字符裸 URL 正常折行不溢出。
- tools/context-evaporation/{types,estimate,evaporate}.ts:零 SDK/零仓库
import(除彼此);四级水位线决策机与 wire 重建,决策单调持久化
(full→snip→stub 只升不降),保护区/红线/hysteresis 与 replay 口径
逐字节对齐;context 钩子侧绝不 throw,未蒸发消息保持对象身份
- test/context-evaporation.test.ts:31 例(每层每 Tier 规则、stub 快照、
单调性、红线、保护区按 token、hysteresis、Tier 累积、冷启动超集、
tier2Scope、trimAssistantText、usage 口径)
- scripts/replay-evaporation.mts 入库(含 160K/256K budget 网格档):
新增 --core 开关(mono 模拟改用蒸发核心,离线/在线同构验证)与
t6085 档线(方案 B 定稿 60/85/95);同构验证 mono-p8k-t60-w128k
基准重跑与既有结果逐字节一致(201 会话 / 11706 步)
Owner
Author
|
误提:未经用户确认且本地验证未完成,先关闭。分支保留,待本地验证后再由用户决定是否重开。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
「上下文蒸发」P1:蒸发纯函数核心 + 单测 + replay 同构验证(spec
.local/agent-work/spec/context-evaporation.md,本 PR 只含纯新增,零接线、零行为变化)。改动
packages/backend/src/tools/context-evaporation/{types,estimate,evaporate}.ts:核心三文件零 SDK/零仓库 import(除彼此)。四级水位线决策机 + wire 重建;决策单调持久化(KV cache 第一约束);保护区(尾部 token + 最近 isError)、红线(用户纯文本/todo/protectedTools/compactionProtected)、hysteresis 大跳与 replay 口径逐字节对齐packages/backend/test/context-evaporation.test.ts:31 例单测(每层每 Tier 规则、stub 格式逐字符快照、单调性、红线、保护区按 token 不按条数、hysteresis、Tier 累积、冷启动超集、tier2Scope、trimAssistantText、usageTokens 口径)scripts/replay-evaporation.mts入库(含 160K/256K 网格档):--core开关:mono 模拟改 import 蒸发核心驱动——同构验证通过:mono-p8k-t60-w128k基准重跑与既有结果逐字节一致(201 会话 / 11706 步 / 含冷启动探针与全部浮点指标)t6085档线(方案 B 定稿 60/85/95):mono-p8k-t6085-w256kcorpus 基线 T1/T2/T3=25/3/0、201 stubs、误杀 u3=15、cw/step 2033自测
npm run typecheck && npm run lint && npm run test全绿(448 tests)npx tsx scripts/replay-evaporation.mts --configs mono-p8k-t60-w128k --core --out .local/replay-data/out-core与.local/replay-data/out/runs/mono-p8k-t60-w128k.jsondiff为空