最新资讯
dev.to 如何在专用 GPU 服务器上用 OpenAI 兼容 API 部署 LLM dev.to 审计 153 份 Claude Code 与 Codex 会话记录:User-Agent 与 URL 中的邮箱泄露 dev.to 你的 Agent Harness 应具备的 17 项能力 dev.to 离线 AI 记忆中 0.8 余弦阈值为何失效 dev.to Kimi K3.1 Pro 开放权重:自托管 2.8T 模型前的开发者清单 dev.to 如何通过工具调用引导模型以提升 Harness 质量 dev.to AI Agent 审计轨迹不等于对话记录 dev.to 精简 MCP server 工具数量:更少工具、更小影响面,双重收益 dev.to 为什么 git checkout 无法撤销 AI 编码 agent 的改动? wechat AI短剧门槛降降降!实测即梦短剧工作室:剧本分镜预演一条龙,伙伴计划长期护航 dev.to 让模型改写文档前,先量化事实保真度 dev.to 回放 153 个 Claude Code 与 Codex 会话,审计 Agent 的生产影响范围
多元动态
登录 注册
智能体 dev.to · @Vitaly Ivasenko

你的编码 Agent 会“故意遗忘”:PreCompact hook 是保存决策的地方

原文 我的收藏

文章讨论 coding agent 的上下文预算问题:当上下文窗口填满时,宿主会将其压缩为摘要,摘要保留“做什么”却丢失“为什么”,而工程决策中“为什么”至关重要。文中介绍了一个开源(MIT)本地任务与记忆层 myc,基于 Bun 和 TypeScript,围绕决策仍可被保存的那一刻设计,作者称其源于 agent 重复同一工作三天的经历。

AI推荐理由 介绍开源 MIT 项目 myc(基于 Bun/TypeScript 的本地任务与记忆层),针对 coding agent 上下文压缩后丢失决策理由(why)的问题,提出 PreCompact hook 思路。属于开发者工具方向的具体新信息,但正文为个人转述,未提供可验证的效果数据或基准,需保留其经验性描述。

62

正文

Your coding agent doesn't have amnesia. It has a budget. When the context window fills up, the host compacts it into a summary — and summaries keep the what while losing the why. For engineering decisions, the why is everything. This is a write-up of a tool I came across that is built around exactly that moment — the one where a decision can still be saved: myc, an open-source (MIT) local task-and-memory layer for coding agents, built on Bun and TypeScript. Its author describes three days of an agent re-doing the same work before writing it; the design follows from that. The bug report was the author The cycle, as the README tells it, looked like this. Early in a session you'd decide something: "we're doing X, not Y, because Z." Hours later the context got compacted, the reason drowned, and the agent — honestly, politely, with no memory of ever thinking otherwise — proposed Y again. Notice the failure mode: it's not that the agent forgot. It's that it had no way to know there was something to remember. Any memory layer you query after the fact is useless if nothing was written into it at the moment the context died. So the saving moment is exactly one: right before compaction. Claude Code exposes that moment as the PreCompact hook event. That's where myc lives. What the hook does myc wire installs the hook. When compaction is about to happen, two things run, in order: The session episode is written to disk first — raw, into the L0 layer, marked private, with secrets masked (password=, api_key=, and friends are matched on word boundaries so prose stays prose). The write happens before anything else: if the hook exceeds its timeout, you lose the summary, not the record. A rescue packet is printed back into the context that survives — the short list of things that must not be lost. $ myc absorb-session --reason manual --transcript … --agent claude # myc: context is being compacted — here is what must not be lost episode sess-5jh8je4g050m saved (265 B) NEXT myc show sess-5jh8je4g050m · myc ready --claim Enter fullscreen mode Exit fullscreen mode Distillation of what was saved is queued, never done on the write path. Candidates, not facts Here's the design decision that makes myc deliberately a bit inconvenient: decisions the hook lifts from the transcript ("we decided / because" lines) are stored as candidates in pending_review state. They do not come back from search, recall, prime, or the MCP tools until a human confirms them. prime says so in its footer: N pending review hidden — myc review. $ myc review PENDING REVIEW 2 · 1 in this session's prime · 1 from other sessions · session 3f9c21aa $ myc review confirm memory-6k2x… Enter fullscreen mode Exit fullscreen mode The reasoning: a memory that hallucinates is worse than no memory, because it gets believed. Confirming a candidate turns it into knowledge exactly the way a normal note is born; rejecting it retracts the note, and retracted notes are out of every retrieval path. Speed is a constraint, not a metric A memory tool lives in the agent's hot path — it gets called dozens of times per session. If it's slow, the agent starts economizing on it, and economizing on memory is forgetting. So every hot path in myc has a latency budget enforced by tests. Measured on 100,000 nodes (2026-09-11, darwin-arm64, myc 0.3.6, p99): operation p99 budget prime (session context packet) 0.608 ms 30 ms search (hybrid) 8.215 ms 25 ms write 0.327 ms 5 ms cold start 21.337 ms 60 ms Reproduce it yourself: bun install -g @aistastudio/myc bun run scripts/bench-latency.ts # from a source checkout Enter fullscreen mode Exit fullscreen mode Honest footnote: those absolute numbers are calibrated on one machine, and CI doesn't enforce them on other hardware. CI does enforce structural claims (query plans, prefiltering) and relative ones (the healthy path measured against a deliberately degraded one, interleaved so hardware cancels out). Ranking is measured too: boosts take MRR@10 from 0.520 to 0.867, two-hop graph expansion from 0.193 to 0.422 — on corpora that contain a control group which gets worse when the feature works, so you can't fake a win by shaping the corpus. Memory anchored to code — and honest when the code is gone Since 0.3.10 a note can be anchored to a span of code, and the anchor follows the code as it moves — across a refactor, even into another file (verified on TypeScript and Python). When the code is no longer where the anchor put it, the knowledge is not deleted: it ranks lower and says why. recall marks the row [code moved ×0.64], [code unverified ×0.5] or [code gone ×0.2]; knowledge whose every anchor is lost stays out of prime, and the footer counts it: N with code gone hidden. That is the answer to the question every memory tool eventually faces — "will it start lying to me in a month?" — and it is the part I have not seen elsewhere. The rest of the toolbox, one line each Tasks: a graph with dependencies, blockers inherited down the parent chain, and atomic claims — two agents never get the same task. Search: hybrid (BM25 + vectors fused by RRF). Semantics are opt-in: the embedding model (129 MB) downloads only when you ask (myc models fetch); until then search is lexical and says so on every answer. No silent fallbacks. Code index: built-in tree-sitter — symbols, callers, search by meaning for TypeScript/TSX/JS/Python. Grammars are fetched once; indexing never touches the network. Multi-agent sanity: myc run -- bun test puts heavy commands through one machine-wide queue, so parallel agents stop strangling each other. Sync: only the oplog goes to git, merged per field — two machines editing the same note converge. Migration from beads: myc import-beads brought over a live project — 796 tasks, 972 dependencies, 265 notes — in 889 ms; re-running it syncs instead of duplicating. (The first release silently dropped the export's comments; found the next day on a real project, fixed in 0.2.0, and described by the author in the README.) The limits, stated before you hit them Bun only. The runtime binds to bun:sqlite — SQLite and sqlite-vec ship inside Bun with no native Node bindings. It will not start on plain Node.js or Deno. That's the deal: one runtime, one binary, zero native build steps. macOS and Linux; on Windows use WSL — the launcher doesn't start in cmd or PowerShell. Single user. No server, no team mode, no ACL. Those are designed and tracked (the team milestone has open subtasks; the live count is on the site), not implemented. Swarm routing and memory distillation haven't been started. Try it and break it bun install -g @aistastudio/myc # 3.42 MB, pulls nothing myc init && myc wire # hooks + MCP for Claude Code, Codex, opencode, Kimi Enter fullscreen mode Exit fullscreen mode The project is about a week old and ships a release close to every day, which is another way of saying: now is the cheapest time to tell the author what's wrong. If you run agents daily, the question worth answering in the issues is whether decisions survive your sessions today — and if not, whether a compaction hook feels like the right place to save them. Repo: https://github.com/aistastudio/myc Site (every number printed next to the command that reproduces it): https://aistastudio.github.io/myc/

来源报道 · 1 篇 · 以下链接均前往原始媒体

← 返回精选动态 原文

更多内容