feat: push/pop 上下文栈 + /digest 回溯蒸馏#1310
Conversation
/push 开一个继承完整上下文的讨论旁支,/pop 把讨论蒸馏成结构化 digest 回卷主线——讨论噪音不污染主线、只留结论。支持嵌套(≤3)、--to #N 跨层弹出、 --list 零成本列栈,以及栈感知 auto-compact 三选确认(压到最近/指定 push 点/全量)。 纯增量、opt-in,feature flag PUSH_POP。 Co-Authored-By: claude-opus-4-8[1m] <noreply@anthropic.com>
- 栈随 transcript 持久化(last-wins push-stack entry),--resume 后仍能 /pop - resume 时 projectPushStackOntoMessages 重新投影,失效标记透明丢弃并通知 - /push --list 预览改取用户最近指令,避免显示空/合成占位消息(No response requested.) - 更新 push-pop-context-stack.md:跨会话持久化由非目标转为目标,同步预览语义 - /pop 时显示进度条以及前后上下文token数变化 Co-Authored-By: claude-opus-4-8[1m] <noreply@anthropic.com>
/digest 像 /rewind 一样弹消息选择器,让用户事后选一条较早消息, 把它到对话底部的上下文蒸馏成四栏 digest(复用 pop 的 DIGEST_PROMPT + summaryFraming:'digest' + 局部压缩),不 resubmit。与 /pop 平级、 共享同一底层蒸馏原语。feature flag 复用 PUSH_POP。 Co-Authored-By: claude-opus-4-8[1m] <noreply@anthropic.com>
📝 WalkthroughWalkthroughAdds feature-gated ChangesPush/pop and digest workflows
Estimated code review effort: 4 (Complex) | ~60 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
src/services/pushStack/state.ts (1)
20-20: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueWrap the changed TypeScript lines to 80 columns.
src/services/pushStack/state.ts#L20-L20: wrap the marker-field documentation.src/services/pushStack/state.ts#L53-L53: wrap the depth-limit documentation.src/state/AppStateStore.ts#L227-L227: wrap the push-stack documentation.src/commands.ts#L173-L173: wrap the push command dynamic import assertion.src/commands.ts#L178-L178: wrap the pop command dynamic import assertion.src/commands.ts#L183-L183: wrap the digest command dynamic import assertion.src/commands/digest/index.ts#L5-L5: wrap the command description.src/commands/pop/pop.ts#L53-L53: wrap the no-stack message.src/commands/push/push.ts#L22-L22: wrap the preview documentation.As per coding guidelines, use 80-character width for other files.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/services/pushStack/state.ts` at line 20, Wrap the changed TypeScript lines to 80 columns without changing behavior: update the marker and depth-limit documentation in src/services/pushStack/state.ts (lines 20 and 53), push-stack documentation in src/state/AppStateStore.ts (line 227), dynamic import assertions in src/commands.ts (lines 173, 178, and 183), the digest command description in src/commands/digest/index.ts (line 5), the no-stack message in src/commands/pop/pop.ts (line 53), and preview documentation in src/commands/push/push.ts (line 22).Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/commands/pop/pop.ts`:
- Around line 12-31: Update parsePopArgs handling for both --to and --to= forms
to validate the entire marker value before conversion, rejecting inputs such as
2junk and 1.5 while continuing to accept valid optional-# positive integers.
Preserve the existing invalid-marker error messages and assignment to opts.to
for valid values.
In `@src/screens/REPL.tsx`:
- Around line 2376-2382: Update the resume-time notification in the push-stack
recovery flow, identified by the key “push-stack-resume-dropped,” to use English
text consistent with the sibling push/pop notifications in REPL. Preserve the
existing droppedCount interpolation, priority, timeout, and notification
behavior.
In `@src/services/compact/autoCompact.ts`:
- Around line 449-465: Update the fallback notification logic after partial
compaction failure or an unavailable chosen marker so non-interactive
fallback-to-full paths also notify through toolUseContext.addNotification.
Preserve the existing distinct messages for interactive partial failure and
explicit full compaction, while ensuring every path that removes all push
markers emits a notification.
---
Nitpick comments:
In `@src/services/pushStack/state.ts`:
- Line 20: Wrap the changed TypeScript lines to 80 columns without changing
behavior: update the marker and depth-limit documentation in
src/services/pushStack/state.ts (lines 20 and 53), push-stack documentation in
src/state/AppStateStore.ts (line 227), dynamic import assertions in
src/commands.ts (lines 173, 178, and 183), the digest command description in
src/commands/digest/index.ts (line 5), the no-stack message in
src/commands/pop/pop.ts (line 53), and preview documentation in
src/commands/push/push.ts (line 22).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: d64daa1c-9804-4797-983e-51bf1a6a3335
📒 Files selected for processing (27)
README.mddocs/features/digest.mddocs/features/push-pop-context-stack.mdscripts/defines.tssrc/Tool.tssrc/commands.tssrc/commands/__tests__/pushpop.test.tssrc/commands/digest/digest.tssrc/commands/digest/index.tssrc/commands/pop/index.tssrc/commands/pop/pop.tssrc/commands/push/index.tssrc/commands/push/push.tssrc/components/MessageSelector.tsxsrc/components/pushStack/CompactStrategyDialog.tsxsrc/main.tsxsrc/screens/REPL.tsxsrc/services/compact/autoCompact.tssrc/services/compact/compact.tssrc/services/compact/prompt.tssrc/services/pushStack/digestPrompt.tssrc/services/pushStack/state.tssrc/state/AppStateStore.tssrc/types/logs.tssrc/utils/__tests__/sessionStorage.test.tssrc/utils/forkedAgent.tssrc/utils/sessionStorage.ts
- parsePopArgs 用正则严格校验整数,拒绝 2junk/1.5 等被 parseInt 静默截断的非法序号 - 非交互会话 partial 压缩失败回退 full 时补发通知,避免 push 标记被静默丢弃 - resume 时 push 点失效通知统一为英文,与兄弟通知一致 - 补充 2junk/1.5 回归测试 Co-Authored-By: claude-opus-4-8[1m] <noreply@anthropic.com>
给 CodeRabbit docstring 覆盖率检查涉及的顶层 handler 补齐 JSDoc: push/pop/digest 三个命令的 call、REPL 的 openMessageSelector、 askCompactStrategy(行注释转 JSDoc)、onAbort。 Co-Authored-By: claude-opus-4-8[1m] <noreply@anthropic.com>
看起来CodeRabbit 的 tree-sitter 解析器把每一个箭头函数都识别成一个独立的"function 节点",这里的箭头函数和c++的lambda函数差不太多。从代码简洁度来说,一般不会给lambda函数添加注释。因为lambda函数简洁同时语意也非常明确,添加注释就类似于给都能辨认出来是猫的图片再注释一个猫。 不过这里如果需要做添加注释来补齐整个的覆盖率的话,我这里再额外添加一下。 |
|
Tip For best results, initiate chat on the files or code changes.
如果补齐阈值是合并要求,建议优先为 🐇💭 ✏️ Learnings added
|
背景
使用agent进行代码开发,本质上是从模型已有的训练分布中,去泛化新任务的分布。在每个状态节点,agent会结合现有的上下文、网络搜索、以及开发者提供的上下文进行下一步的状态转移。agent与用户的协作的整个流程看作一棵启发式的搜索树,由于并非每次决策都是正确的,遇到问题时需要小范围的试错搜索。但目前现有的顺序结构的上下文方式只能追加、无法回溯,对于失败的搜索尝试会一直记录在上下文中,导致一次跑偏的讨论会永久留在上下文里稀释后续推理。
新增的/Push/Pop、/digest 为这棵树补上「回溯」能力:弹栈时只有蒸馏物穿过节点边界,展开过程中的中间态被丢弃,从而可以支持多分叉的讨论以及尝试。
由于回溯过程是采用上下文信息 对 回溯范围内容进行蒸馏,整个回溯流程以及回溯前后都是cache友好的(只有蒸馏出来的结果小部分内容cache不命中),相较/compact能够更加自主的进行上下文管理,并且成本更低。
同时,当前功能为额外的新增功能,在不使用时和以往完全没有影响。
总结
支持嵌套、--to #N 跨层弹出、--list 零成本列栈、栈感知 auto-compact、跨会话持久化
蒸馏成 digest(复用同一底层压缩原语 + DIGEST_PROMPT),不 resubmit
Summary by CodeRabbit
/pushand/popfor nested discussion branches, including--list,--to#N``,--discard, and `--keep-code`./digestto distill a rolled-back branch into Decisions, Rejected, Open questions, and Action items.