mirror of
https://github.com/czm15053/write-notes-like-deepseek
synced 2026-11-24 16:14:17 +08:00
feat: write-notes-like-deepseek — 像 DeepSeek 团队一样沉淀 Agent Notes
可叠加到任何仓库的决策留痕 Skill:路径即分类、文件即契约、门禁防腐烂
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
node_modules/
|
||||
.DS_Store
|
||||
docs/
|
||||
@@ -0,0 +1,157 @@
|
||||
# write-notes-like-deepseek
|
||||
|
||||
> 像 DeepSeek 团队一样,把"为什么这样改"写下来——半年后打开还能懂。
|
||||
|
||||
为每一次重要改动留下一篇可检索、可校验的笔记:为什么要改、考虑过哪些备选、最终为何这样取舍。让半年后的自己或同事不用翻聊天记录,打开仓库就能看懂。
|
||||
|
||||
来自 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) 两个月 740+ 篇笔记的实践提炼,装进任何项目都能用,不改你现有的工作流。
|
||||
|
||||
```bash
|
||||
npx skills add czm15053/write-notes-like-deepseek
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 解决什么问题
|
||||
|
||||
代码会变,记忆会忘。改了一处架构,两个月后没人记得为什么这么选、放弃了哪条路、代价是什么——只能重新踩坑。
|
||||
|
||||
这个 Skill 只做一件事:**做决定时就写,最晚和代码同一次提交**(有 PR 以 PR 为单位,没有就以 commit 为单位)。路径即分类,文件即契约,门禁保证格式不腐烂。
|
||||
|
||||
---
|
||||
|
||||
## 一篇笔记长什么样
|
||||
|
||||
放在 `.agents/notes/implemented/feature/2026-08-23-xxx.md`:
|
||||
|
||||
```markdown
|
||||
# Agent Note: 用 SQLite 存会话,为什么不用 JSONL
|
||||
|
||||
Status: implemented
|
||||
|
||||
## Problem 为什么要改?不看方案也能懂
|
||||
## Decision 最终怎么做的?现在时
|
||||
## Alternatives considered 认真考虑过哪 2–3 种做法,为什么没选
|
||||
## Consequences 代价和收益各是什么
|
||||
```
|
||||
|
||||
四段写完,一次改动的来龙去脉就钉住了。`Alternatives considered` 是必填项——不记录打败了什么,决定迟早被重审。格式不对,门禁直接报错。
|
||||
|
||||
---
|
||||
|
||||
## 什么时候写
|
||||
|
||||
| 要写 | 不用写 |
|
||||
|---|---|
|
||||
| 改了运行时行为或 UI 表现 | 只改空格、格式、导入顺序 |
|
||||
| 改了架构、模块边界、跨文件契约 | 无歧义重命名、错别字 |
|
||||
| 改了流程、门禁、测试策略 | 注释里加一句说明 |
|
||||
| 改了落盘 / 网络 / 配置格式 | 文档里改个标点 |
|
||||
|
||||
一句话判断:**"半年后有人回来看,会想知道为什么这样改吗?"** 会,就写一篇。
|
||||
|
||||
> 不确定就按要写处理。别用"以后再补 / 代码即文档 / 改动小"跳过。
|
||||
|
||||
---
|
||||
|
||||
## 放在哪
|
||||
|
||||
路径即分类:
|
||||
|
||||
```
|
||||
.agents/notes/{状态}/{种类}/2026-08-23-主题.md
|
||||
# 例:.agents/notes/implemented/feature/2026-08-23-xxx.md
|
||||
```
|
||||
|
||||
完整目录(轻量项目只建 `implemented/<class>/` 即可,空目录可直接删):
|
||||
|
||||
```
|
||||
.agents/notes/
|
||||
├── implemented/
|
||||
│ ├── feature/
|
||||
│ ├── bug-fix/
|
||||
│ ├── architecture/
|
||||
│ ├── process/
|
||||
│ ├── testing/
|
||||
│ └── simplification/
|
||||
├── proposed/ # 同上 6 类,按需创建
|
||||
├── rejected/ # 同上
|
||||
└── archived/ # 同上,冻结不可改
|
||||
```
|
||||
|
||||
- **状态**:`proposed` 提议中 → `implemented` 已上线 → `rejected` 已否掉 → `archived` 归档冻结
|
||||
- **种类**(6 选 1,写错会报错):`feature` / `bug-fix` / `architecture` / `process` / `testing` / `simplification`
|
||||
|
||||
`refactor` 不单列——用 `simplification` 的标准判断:可观察行为变了吗?没变就是简化。
|
||||
|
||||
---
|
||||
|
||||
## 怎么用
|
||||
|
||||
```bash
|
||||
# 1. 安装
|
||||
npx skills add czm15053/write-notes-like-deepseek
|
||||
|
||||
# 2. 做决定时就写:有想法先写 proposed,做完最晚与代码同一次提交更新为 implemented
|
||||
# 已有归属的决定 → 更新那篇;全新决定 → 新建一篇
|
||||
```
|
||||
|
||||
校验(可选接 CI):
|
||||
|
||||
```bash
|
||||
npx tsx scripts/verify-agent-note-tree.ts # 路径、状态、种类、文件名
|
||||
npx tsx scripts/verify-agent-note-format.ts # 开头三行、必备章节、Alternatives
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 让 Agent 自动执行
|
||||
|
||||
在项目的 `AGENTS.md` / `CLAUDE.md` 加一句钩子,Agent 就会在重要改动时自动按本 Skill 走:
|
||||
|
||||
```markdown
|
||||
## 决策留痕
|
||||
|
||||
重要改动或重要决定(行为 / 架构 / 契约 / 流程 / 落盘格式,或动手前的选型与否决)执行
|
||||
[write-notes-like-deepseek](.agents/skills/write-notes-like-deepseek/SKILL.md):
|
||||
有想法先写 `proposed`,落地后最晚与代码同一次提交更新为 `implemented`;被否决的写 `rejected`;
|
||||
每篇必含 `## Alternatives considered`。
|
||||
只改格式 / 无歧义重命名 / 错别字标 `not applicable`。
|
||||
```
|
||||
|
||||
团队项目可在 `CONTRIBUTING.md` 或 PR 模板再加一句:"非平凡改动必带 Note",与 CI 门禁闭环:
|
||||
|
||||
```json
|
||||
{
|
||||
"scripts": {
|
||||
"verify-agent-note-tree": "tsx .agents/skills/write-notes-like-deepseek/scripts/agent-note-tree.ts",
|
||||
"verify-agent-note-format": "tsx .agents/skills/write-notes-like-deepseek/scripts/verify-agent-note-format.ts",
|
||||
"doc-sync": "npm run verify-agent-note-tree && npm run verify-agent-note-format"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 包含什么
|
||||
|
||||
```
|
||||
.
|
||||
├── SKILL.md # Agent 执行的主流程(每次必读)
|
||||
├── templates/ # 三态模板:proposed / implemented / rejected
|
||||
├── references/ # 按需加载:格式 / 分类 / 归档 / 行文 / 简化 / 校验
|
||||
└── scripts/ # 校验脚本
|
||||
```
|
||||
|
||||
## 参考
|
||||
|
||||
- 来源:[deepseek-ai/deepseek-harness](https://github.com/deepseek-ai/deepseek-harness) 的 `.agents/notes/README.md`、`.agents/skills/dsh-archive-agent-notes`、`scripts/agent-note-tree.ts`、`scripts/verify-agent-note-format.ts`
|
||||
- 规范:[Agent Skills](https://agentskills.io)
|
||||
|
||||
## 友链
|
||||
|
||||
- [LinuxDo](https://linux.do) — 真诚、友善、团结、专业的新生代 AI 社区
|
||||
|
||||
## 许可
|
||||
|
||||
MIT
|
||||
@@ -0,0 +1,113 @@
|
||||
---
|
||||
name: write-notes-like-deepseek
|
||||
description: 像 DeepSeek 团队一样沉淀 Agent Notes——决策、取舍与验证一处留痕,半年后仍可追溯。Use when making a non-trivial change or decision worth revisiting. 适用于任何仓库
|
||||
---
|
||||
|
||||
# Write Notes Like DeepSeek
|
||||
|
||||
> 从 DeepSeek Harness 提炼的决策沉淀纪律。宿主负责拆任务、排计划;本 Skill 只解决一件事:**为什么这样改、放弃了什么、怎么证明改对了**,都留在一处可检索、可校验的地方。
|
||||
|
||||
## 定位
|
||||
|
||||
这不是文档生成器,也不是 ADR 模板合集。它的定位是**决策留痕层**——当涉及行为、架构、契约、流程或落盘格式这类半年后会有人回头问"为什么"的地方,用一篇 Agent Note 把 rationale 钉住。包括动手前的选型与被否决的方案——无代码的决定也值得留。
|
||||
|
||||
- 只改格式 / 无歧义重命名 / 错别字 → 标 `not applicable`,不写。
|
||||
- 不确定是否算重要改动 → 按要写处理。
|
||||
- 别用"以后再补 / 代码即文档 / 改动小"给自己开绿灯。
|
||||
|
||||
一句话判断:**"半年后有人回来看,会想知道为什么这样改吗?"** 会,就写。
|
||||
|
||||
> "决策"不重——个人项目里就是"为什么选 A 没选 B"。选型、取舍、踩过的坑,都值得钉住。
|
||||
|
||||
## 0. 先探测,再落地
|
||||
|
||||
别一上来建全套目录。按宿主现状选型:
|
||||
|
||||
1. 有 `AGENTS.md` / `CLAUDE.md` / 贡献指南 → 读它;有 `docs/adr/`、`docs/decisions/`、Issue 模板等既有决策记录 → 沿用,语义映射到本 Skill 的 lifecycle / class 即可。
|
||||
2. 没有决策记录 → 建最小 Note 树:**轻量项目只建 `.agents/notes/implemented/<class>/`**,用到 `proposed` / `rejected` / `archived` 再建;空目录可直接删。
|
||||
3. 团队长期仓库 → 建全套 `proposed / implemented / rejected / archived × 6 class`。
|
||||
|
||||
## 1. 路径即分类
|
||||
|
||||
每条 Note 的路径就是身份:`{lifecycle}/{class}/yyyy-mm-dd-topic.md`
|
||||
|
||||
**Lifecycle(状态):**
|
||||
|
||||
- `proposed` — 想法阶段,有了方案但还没落地
|
||||
- `implemented` — 已落地,与代码同一次提交保持同步
|
||||
- `rejected` — 审慎否掉的提案,仅当能防止重犯时保留,否则删整组
|
||||
- `archived` — 已完成且未来参考价值低的 implemented 记录,冻结不可改
|
||||
|
||||
**Class(种类,封闭集,新增需改门禁):**
|
||||
|
||||
`feature` / `bug-fix` / `simplification` / `architecture` / `process` / `testing`
|
||||
|
||||
> 详见 `references/classification.md`;`refactor` 不单列——用 `simplification` 的判据"可观察行为变了吗"区分。不建集中 `INDEX.md`,用目录与搜索发现。
|
||||
|
||||
## 2. 文件格式(门禁强制)
|
||||
|
||||
前三行固定:
|
||||
|
||||
```markdown
|
||||
# Agent Note: <标题>
|
||||
|
||||
Status: <状态>
|
||||
```
|
||||
|
||||
- `proposed` → `Status: proposed`
|
||||
- `implemented` → `Status: implemented`
|
||||
- `rejected` → `Status: rejected — <一句话原因>`
|
||||
|
||||
状态必须与所在 lifecycle 文件夹一致;文件名日期是**首次提出日**,状态不带日期。
|
||||
|
||||
**Body 骨架:**
|
||||
|
||||
- `proposed`:`## Problem` → `## Proposal` → …自由节… → `## Alternatives considered` → `## Acceptance criteria` → `## Risks`
|
||||
- `implemented`:`## Problem` → `## Decision`(现在时) → …自由节… → `## Alternatives considered` → `## Consequences`
|
||||
- `rejected`:冻结的 proposal 形态,结论在 `Status:` 行
|
||||
|
||||
> 禁止在 `implemented` 中出现 `## Proposal` / `## Plan` / `## Acceptance criteria` 等提案口吻;详见 `references/note-format.md`。
|
||||
> 每篇 Note 必含 `## Alternatives considered`——没写就重审。
|
||||
> `implemented` 用现在时描述已落地事实;一条 Note 永远不被改写成另一个决定。
|
||||
|
||||
模板见 `templates/`。
|
||||
|
||||
## 3. 什么时候写、什么时候改
|
||||
|
||||
跟着**做决定的时机**写,不只是提交时补。新建前先搜现有归属——同决定的改动更新那一篇,不另起新篇:
|
||||
|
||||
- **有想法、还没动手** → 先写 `proposed`(为什么想这么做、考虑过哪几条路),评审完再动手。纯调研/选型没有代码时,Note 本身就是交付物。
|
||||
- **动手时 / 刚做完** → 写或更新 `implemented`,**最晚与代码同一次提交**,避免遗漏。有 PR 以 PR 为单位,没有就以 commit / 推送批次为单位。
|
||||
- **改的是已有 Note 对应的决定** → 更新那一篇(事实、路径、验证变了就同步),不另起一篇。
|
||||
- **决定没被完全取代** → 新旧两篇都留并互链。
|
||||
- **决定被完全取代** → 新 Note 接管,旧 Note 按归档规则冻结,或按合并规则删除(需保留所有独特 rationale 并修复入链)。
|
||||
|
||||
> 判定与流转见 `references/when-to-write.md`,归档与删除见 `references/archiving.md`。
|
||||
|
||||
## 4. 怎么写好
|
||||
|
||||
- `## Consequences` 同时写**代价和收益**,不是只写"放弃了什么"。
|
||||
- 自由节(package 拓扑、wire 契约、schema 等)放在 `Decision` 与 `Alternatives` 之间,保持可检索的机制名与 `must / may / never` 时序强调。
|
||||
- 跨 Note 引用用相对 Markdown 链接 `[topic](../../implemented/architecture/2026-…-….md)`,不要裸数字,以便机械可校验。
|
||||
- 文风与去推导痕迹见 `references/prose-checklist.md`;简化机会见 `references/simplification-checklist.md`。
|
||||
|
||||
## 5. 校验
|
||||
|
||||
```sh
|
||||
npx tsx <skill目录>/scripts/verify-agent-note-tree.ts # 路径、lifecycle、class、文件名
|
||||
npx tsx <skill目录>/scripts/verify-agent-note-format.ts # 头块、骨架、Alternatives、禁用词
|
||||
```
|
||||
|
||||
每个校验都是独立 tsx 脚本,串进 `doc-sync` 即成门禁。团队项目可在 `CONTRIBUTING.md` / PR 模板加一句"非平凡改动必带 Note",并把上面两个脚本接进 CI 形成闭环。详见 `references/verification.md`。
|
||||
|
||||
## References
|
||||
|
||||
按需加载:
|
||||
|
||||
- `references/note-format.md` — 头块与 body 骨架展开
|
||||
- `references/classification.md` — 6 class 判定与边界
|
||||
- `references/when-to-write.md` — 何时新建 / 更新 / 流转
|
||||
- `references/archiving.md` — 归档与合并删除(含"未来参考价值"判定与新增即审计)
|
||||
- `references/prose-checklist.md` — 行文与去泄露自检
|
||||
- `references/simplification-checklist.md` — 简化机会自检
|
||||
- `references/verification.md` — 校验脚本说明
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "write-notes-like-deepseek",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"description": "像 DeepSeek 团队一样沉淀 Agent Notes",
|
||||
"scripts": {
|
||||
"verify-agent-note-tree": "tsx scripts/verify-agent-note-tree.ts",
|
||||
"verify-agent-note-format": "tsx scripts/verify-agent-note-format.ts"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
# 按需阅读:归档与合并删除
|
||||
|
||||
> 提炼自 `dsh-archive-agent-notes` 与 `.agents/notes/README.md`。收尾或复盘时对照;日常改动跳过。
|
||||
|
||||
## 何时归档(implemented → archived)
|
||||
|
||||
按“未来参考价值”语义判定,而非字数/年龄/配额:
|
||||
|
||||
- **保留 active**:rationale、alternatives、negative guarantee、持久化/wire 语义、ownership 边界、安全规则、重引入条件仍可能指导未来改动。
|
||||
- **移入 archived**:已完成且上述价值已低;冻结为 `archived/{class}/yyyy-mm-dd-topic.md`。
|
||||
|
||||
每新增一条 Note 即触发同域已落地 Note 的 supersession 审计:同改动内归档被完全取代者,保留并互链部分取代者。
|
||||
|
||||
## 怎么归档
|
||||
|
||||
- 移动单文件 `archived/{class}/yyyy-mm-dd-topic.md`,保留 `Status: implemented`,在状态行下方插入 `Archived: YYYY-MM-DD`,修复或删除入链;除此之外不改内容。
|
||||
- 归档后永久冻结:不编辑、不重排、不移动、不作为现行权威;文档门禁跳过 archived 的出链;主动引用历史时可链入。
|
||||
|
||||
## 合并删除(完全取代)
|
||||
|
||||
仅当旧 Note 被新 Note **完全取代**时可删除;部分取代两者都留并互链。
|
||||
|
||||
删除前必须:保留旧 Note 的所有独特 rationale/alternative/consequence/验证要求/覆盖缺口到新 Note;修复所有入链。禁止把旧文件改写成对立面,也禁止“只留 git 历史”。
|
||||
|
||||
- `feature` 的新增 Note 只有在能力已从生产代码/配置/schema/持久化/wire/迁移/兼容行为中完全消失、文档不再宣称可用、测试不再以其为可用行为时,才可被后续 removal Note 合并。
|
||||
@@ -0,0 +1,26 @@
|
||||
# 按需阅读:Class 分类
|
||||
|
||||
> SKILL §1 的展开。新建 Note 选 class 时对照。
|
||||
|
||||
## 封闭集(6 个,新增需改门禁)
|
||||
|
||||
| Class | 覆盖范围 |
|
||||
|---|---|
|
||||
| `feature` | 新增面向用户或模型的能力 |
|
||||
| `bug-fix` | 修缺陷或补 postmortem 暴露的缺口 |
|
||||
| `simplification` | 不新增能力的前提下删代码/行为/表面 |
|
||||
| `architecture` | 已发布源码的结构性决定——包如何关联、运行时词汇是什么 |
|
||||
| `process` | 代码之外的工具/策略/流程——门禁、包管理、vendoring 等 |
|
||||
| `testing` | 测试 infra 与策略 |
|
||||
|
||||
判定技巧:
|
||||
|
||||
- `architecture` vs `process`:前者是"发出去的源码长什么样",后者是"围绕源码的工具链与工作流"。
|
||||
- `refactor` 不单列——用 `simplification` 的判据"可观察行为变了吗"区分;行为不变即 simplification,行为变了归对应 feature/bug-fix/architecture。
|
||||
- 拿不准时看这条 Note 以后会被谁检索:找能力演进看 `feature`,找结构决策看 `architecture`,找门禁/发布看 `process`。
|
||||
|
||||
## 门禁
|
||||
|
||||
`scripts/agent-note-tree.ts` 定义 `AGENT_NOTE_CLASSES` 常量;`verify-agent-note-classification` 拒绝未知 class 文件夹与 lifecycle 根下的散落 `.md`。新增 class 必须同时改常量与本文档,否则门禁直接红。
|
||||
|
||||
详见 Harness 原文:`implemented/process/2026-06-20-agent-note-classification.md`。
|
||||
@@ -0,0 +1,69 @@
|
||||
# 按需阅读:Note 文件格式
|
||||
|
||||
> SKILL §2 的展开。写/改 Note 时对照;只改代码不动 Note 时跳过。
|
||||
|
||||
## 头块(前三行,门禁强制)
|
||||
|
||||
```markdown
|
||||
# Agent Note: <标题>
|
||||
|
||||
Status: <状态>
|
||||
```
|
||||
|
||||
- `proposed` → `Status: proposed`
|
||||
- `implemented` → `Status: implemented`
|
||||
- `rejected` → `Status: rejected — <一句话原因>`
|
||||
|
||||
标题前必须带 `Agent Note: ` 前缀;状态不含日期与括号;必须与所在 lifecycle 文件夹一致(门禁交叉校验)。文件名日期是首次提出日,git 承载其余时间信息。
|
||||
|
||||
## Body 骨架
|
||||
|
||||
每篇 Note 都以 `## Problem` 开头——动机要能脱离方案独立成立。之后按 lifecycle区分:
|
||||
|
||||
**`proposed/`**
|
||||
|
||||
```markdown
|
||||
## Problem
|
||||
## Proposal
|
||||
…自由节…
|
||||
## Alternatives considered
|
||||
## Acceptance criteria
|
||||
## Risks
|
||||
```
|
||||
|
||||
`Proposal` 可用将来时;`Acceptance criteria` 说清什么可观察状态算完成;`Risks` 同时写风险与已知取舍。
|
||||
|
||||
**`implemented/`**
|
||||
|
||||
```markdown
|
||||
## Problem
|
||||
## Decision
|
||||
…自由节…
|
||||
## Alternatives considered
|
||||
## Consequences
|
||||
```
|
||||
|
||||
`Decision` 用现在时描述已落地事实;禁止出现 `## Proposal` / `## Plan` / `## Migration plan` / `## Acceptance criteria` 等提案口吻(门禁直接拦);用 `## Consequences` 同时记录代价与收益;可按需加 `## Testing` / `## Verification` 等现在时事实节。
|
||||
|
||||
**`rejected/`**
|
||||
|
||||
冻结的 proposal 形态,verdict 在 `Status:` 行;保留提案时的 `Alternatives` 等节,不改写为对立面。
|
||||
|
||||
## Alternatives considered(必写)
|
||||
|
||||
每篇 Note 必含 `## Alternatives considered`:每个真考虑过的备选为何没选,一段一备选(可用 `### Why not <X>?` 子节)。没写就重审——不记录打败了什么,决定就会被重审。
|
||||
|
||||
- 只有 2026-07-05 前且不可追溯的 pre-format Note 可用 `<!-- agent-note-format: alternatives-not-recorded (pre-format Agent Note) -->` 占位,其余一律实写。新项目可忽略此条。
|
||||
|
||||
## 时态与禁止改写
|
||||
|
||||
- `proposed` 可用将来时;`implemented` 一律现在时,描述已落地事实。
|
||||
- 一条 Note 永远不被改写成另一个决定;被取代用新 Note 接管,旧 Note 按归档/合并规则处理。
|
||||
|
||||
## 自由节与文风
|
||||
|
||||
- 自由节(package 拓扑、wire 契约、schema 等)放在 `Decision` 与 `Alternatives` 之间。
|
||||
- 保留可检索的机制名与 `must`/`may`/`never` 时序强调;一个事实只在一处讲透,其余链过去。
|
||||
- 跨 Note 引用用相对 Markdown 链接 `[topic](../../implemented/architecture/2026-…-….md)`,不要裸数字。
|
||||
|
||||
来源:Harness `.agents/notes/README.md#the-file-format` 与 `implemented/process/2026-07-05-uniform-agent-note-format.md`(本项目中文单语,头块 `Agent Note:` 与 `Status:` 保持英文原文以便门禁校验,正文用中文)。
|
||||
@@ -0,0 +1,41 @@
|
||||
# 按需阅读:Notes 行文与去泄露自检
|
||||
|
||||
> 提炼自 `dsh-prose-standard` 与 `dsh-trim-cot-leakage` 的可搬运部分。写/改 Note 时对照此清单;只改代码不动 Note 时跳过。
|
||||
|
||||
## 原则
|
||||
|
||||
- 只写代码表达不了的契约:行为、失败、时序、所有权、后果与取舍。别复述代码或推导过程。
|
||||
- 说人话,点名谁做了什么、在什么条件下、会怎样;少用“契约/边界/形态”等抽象词,除非指的就是该技术主体。
|
||||
- 一个事实只在一处讲透,其余链过去;别把同一规则抄得到处都是。
|
||||
- 写完自问:这段话不看实现能独立成立吗?半年后的读者能验证吗?
|
||||
|
||||
## 写前自检(来自 prose-standard)
|
||||
|
||||
- 每段保留完整命题:主体/动作、条件/时序、must/may/never、否定保证与例外、所有权/副作用/失败与后果——缺一不可。
|
||||
- `implemented` 用现在时,描述已落地事实;去掉计划口吻与 checklist。
|
||||
- 保留可检索的机制名与关键 must/may/never、时序与否定强调;装饰性加粗和感叹少用。
|
||||
- 一个改动内批量套用刚学到的规则到相似段落,别只改一处。
|
||||
|
||||
## 按位置查
|
||||
|
||||
- **Decision/Consequences**:区分、抛错/拒绝、副作用、所有权、时序、取消、持久化是否说清。
|
||||
- **自由节**(拓扑/契约/schema):讲清职责、依赖与非显而易见的选择及指向。
|
||||
- **Alternatives/Consequences**:同时写代价与收益,点名放弃的能力与重引入条件。
|
||||
- **Testing/Verification**:只解释“为何这样验证”(fixture/断言/真实入口的必要性),不写走读。
|
||||
|
||||
## 去泄露自检(来自 trim-cot-leakage)
|
||||
|
||||
对每段可疑文字问:**只有当时的会话/PR/草稿可见吗?HEAD 的读者能独立验证吗?** 不能则重述为仓库视角,删去会话痕迹。
|
||||
|
||||
常见泄露(命中即改):
|
||||
|
||||
1. 死引用:`(decision 7)`/`(audit C2)`/`§N`/`plan §1.4` — 改为对已提交 Note/文档的具名路径引用,无主则删引用、重述事实。
|
||||
2. 栈/PR 视角:`后续 PR`/`本 PR 新增`/`上一 commit` — 改为已落地的机制或扩展点;未做事项用 `TODO` 或 issue 引用。
|
||||
3. 变更叙事:`used to`/`不再`/`旧 X`/`this cut`/`now` — 改为现在时;回归用现在时反事实“若无 X 则 Y”。
|
||||
4. 评审编排:`评审时否掉`/`reviewer 确认`/`v5` — 只留决定与理由,删谁说的、何时说的。
|
||||
5. 自证正确:`这样转是安全的,因为…` — 改为使之安全的 invariant,或直接删(代码已自明)。
|
||||
6. 过程复述:`先 X 再 Y`/`测试走读` — 删,只留非显然契约。
|
||||
7. 含糊与占位:`应该够了`/`probably fine` — 升为 `TODO/FIXME` 或明确边界。
|
||||
8. 语言串台:中英混杂的工作语言片段 — 翻译或删除。
|
||||
|
||||
**不算泄露(保留):** issue 引用 `#1470`/`TODO(name):`、Agent Note 与 postmortem 内的已合并 PR 引用、suppression 理由、现在时反事实、带实测值的边界、运行时 old/new 状态、已提交文档的 `§` 编号。
|
||||
@@ -0,0 +1,26 @@
|
||||
# 按需阅读:简化机会自检
|
||||
|
||||
> 提炼自 `dsh-find-simplifications` 的可搬运部分。收尾或重构时扫一遍;别在功能改动里硬塞无关简化。
|
||||
|
||||
## 值得删/合/降级的信号
|
||||
|
||||
- 公开方法、事件、配置项、包、持久化事件或测试产物没有生产消费方(测试/文档是唯一消费方且行为非关键)。
|
||||
- 两处表示同一事实(尤其是持久化事件与瞬态事件各存一份)。
|
||||
- 某个能力的所有实现都必须实现某方法,但没有消费方在用它。
|
||||
- 包只为测试/demo/支撑而存在,增加发布与依赖成本。
|
||||
- 为“以后可能要”做的通用性:多会话、后台任务台账、年中转向、工具自带 UI 等,无当前归属。
|
||||
- 为不存在的 API 准备的不变式、回滚、快照或特判。
|
||||
- 手写了业界已有包或同版本 Node 已提供的能力,换掉能净删除实现与对应测试。
|
||||
|
||||
## 怎么证实
|
||||
|
||||
- 用 `rg` 搜符号/事件/配置键/包名,看生产代码(`packages/*/src`、`examples` 运行时、`loader/config` 路径)是否真在用。
|
||||
- 区分生产/非生产/模糊语料——测试与文档里的出现不算生产证据;`knip` 可辅助但不能替代读调用点。
|
||||
- 小而确定的清理用 `TODO/FIXME/XXX` 记下,别为此开一条 Note;只有 durable 的取舍才值得一条 proposed Note。
|
||||
- Hand-rolled vs 依赖:看净删除(实现+测试+文档)、健康度、边界贴合度;能真删才换,包一层同样复杂度不算赢。
|
||||
|
||||
## 与 Notes 的衔接
|
||||
|
||||
- 符合信号且需 durable 决策 → 写 `proposed/simplification` Note(Problem/Proposal/Alternatives/Acceptance/Risks)。
|
||||
- 已落地的 simplification → `implemented/simplification`,Consequences 同时写删掉的成本与省下的负担。
|
||||
- 触发 Note 树膨胀时,用 `archiving.md` 的“未来参考价值”判定是否归档,而非字数/年龄。
|
||||
@@ -0,0 +1,21 @@
|
||||
# 按需阅读:校验脚本
|
||||
|
||||
> SKILL §5 的展开。接入 CI 时对照;本地轻量使用时跳过。
|
||||
|
||||
## 门禁(均为 tsx,零新增依赖)
|
||||
|
||||
1. **`verify-agent-note-tree`**(`scripts/agent-note-tree.ts` + `scripts/verify-agent-note-tree.ts`)
|
||||
- 校验 lifecycle 封闭集 `proposed/implemented/rejected` + `archived`、class 封闭集 6 个、路径深度 `{lifecycle}/{class}/file.md`、文件名 `yyyy-mm-dd-topic.md`、禁止 `INDEX.md`。
|
||||
|
||||
2. **`verify-agent-note-format`**(`scripts/verify-agent-note-format.ts`)
|
||||
- 校验头三行 `# Agent Note:` / 空行 / `Status:` 与 lifecycle 一致、Status 唯一、`## Problem` 首节、per-lifecycle 必需节与禁用节、`## Alternatives considered` 必写、grandfather 仅对 2026-07-05 前有效、禁止 legacy 债务标记。
|
||||
|
||||
3. **`verify-archived-agent-notes`**(可选,团队需要冻结清单时再加)
|
||||
- Harness 原版校验 `archived/` 单文件 + `Archived: YYYY-MM-DD` + sidecar 哈希 + manifest。本项目默认不带,轻量可先不接。
|
||||
|
||||
## 接入建议
|
||||
|
||||
- 轻量:接前两个即可(`archived` 用到再加第三个)。
|
||||
- 完整:前两个串进 `doc-sync`,与 `verify-md-links` / `verify-doc-refs` 同链,失败即红。
|
||||
|
||||
来源:Harness `scripts/agent-note-tree.ts` / `verify-agent-note-format.ts` / `verify-archived-agent-notes.ts`(本项目为中文单语精简版,不含翻译配对)。
|
||||
@@ -0,0 +1,28 @@
|
||||
# 按需阅读:何时写、何时改
|
||||
|
||||
> SKILL §3 的展开。每个非平凡改动对照一次。
|
||||
|
||||
## 何时必须写
|
||||
|
||||
按做决定的时机写:动手前写 `proposed`,实现时最晚与代码同一次提交新增或更新 `implemented`(有 PR 以 PR 为单位,没有就以 commit 为单位)。非平凡 = 改了行为、架构、跨文件契约、流程/门禁/测试策略、落盘/网络/配置格式,或其他会被后人合理追问"为什么"的决定。
|
||||
|
||||
- 纯机械/局部且无行为与契约变化 → 豁免,不写。
|
||||
- 不确定 → 按非平凡处理,写一条。
|
||||
|
||||
## 新建前先搜
|
||||
|
||||
新建前用目录浏览或 `rg` 搜现有归属;同决定的改动更新那一张,不另起一篇。
|
||||
|
||||
## 新建 vs 更新
|
||||
|
||||
- 已有归属的决定(文件名/路径能对应上)→ **更新那一条**,不另起一篇。事实、路径、默认值、验证变了就在同一改动内同步到 Note(facts only),不改 decision 本身。
|
||||
- 无归属的新决定 / 能防止重犯的否决 / 可复用复盘 → 新建。
|
||||
- 一条 Note 永远不会被改写成另一个决定;被取代用新 Note 接管,旧 Note 按归档/合并规则处理。
|
||||
|
||||
## Lifecycle 流转
|
||||
|
||||
- `proposed/` → `implemented/`:重写 `Status:`,把 `## Proposal` 改为现在时的 `## Decision`,把 `## Acceptance criteria` / `## Risks` 收敛进 `## Consequences` 或 `## Testing`/`## Verification`,去掉计划口吻。
|
||||
- `proposed/` → `rejected/`:仅在 `Status:` 行追加 `— <原因>` 并冻结文件。
|
||||
- `implemented/` 内更新:保持现在时;与代码同一次提交保持同步(有 PR 以 PR 为单位,没有就以 commit 为单位)。
|
||||
|
||||
来源:Harness `.agents/notes/README.md#when-to-write-one` 与 `implemented/AGENTS.md`。
|
||||
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* Shared structural source of truth for the Agent Note tree.
|
||||
* Portable: resolves .agents/notes from cwd (or AGENT_NOTE_ROOT env).
|
||||
*/
|
||||
import { globSync, readdirSync, existsSync } from 'node:fs'
|
||||
import { resolve, sep } from 'node:path'
|
||||
|
||||
function resolveAgentNoteRoot(): string {
|
||||
if (process.env.AGENT_NOTE_ROOT) return resolve(process.env.AGENT_NOTE_ROOT)
|
||||
// walk up from cwd to find .agents/notes, fallback to cwd/.agents/notes
|
||||
let cur = process.cwd()
|
||||
for (let i = 0; i < 6; i++) {
|
||||
const cand = resolve(cur, '.agents/notes')
|
||||
if (existsSync(cand)) return cand
|
||||
const parent = resolve(cur, '..')
|
||||
if (parent === cur) break
|
||||
cur = parent
|
||||
}
|
||||
return resolve(process.cwd(), '.agents/notes')
|
||||
}
|
||||
|
||||
export const agentNoteRoot = resolveAgentNoteRoot()
|
||||
|
||||
const AGENT_NOTE_LIFECYCLES = ['proposed', 'implemented', 'rejected'] as const
|
||||
export const AGENT_NOTE_CLASSES = ['feature', 'bug-fix', 'simplification', 'architecture', 'process', 'testing'] as const
|
||||
const AGENT_NOTE_ARCHIVE = 'archived'
|
||||
const ROOT_ALLOWLIST = new Set(['AGENTS.md', 'CLAUDE.md'])
|
||||
|
||||
export interface AgentNote {
|
||||
lifecycle: string
|
||||
rel: string
|
||||
date: string
|
||||
}
|
||||
|
||||
export function walkAgentNoteTree(): { notes: AgentNote[]; errors: string[] } {
|
||||
const notes: AgentNote[] = []
|
||||
const errors: string[] = []
|
||||
if (!existsSync(agentNoteRoot)) return { notes, errors }
|
||||
for (const entry of readdirSync(agentNoteRoot, { withFileTypes: true })) {
|
||||
if (entry.name === 'INDEX.md') {
|
||||
errors.push('structure: INDEX.md — centralized Agent Note indexes are forbidden; browse the lifecycle/class tree or search the repository')
|
||||
continue
|
||||
}
|
||||
if (entry.isDirectory() && entry.name !== AGENT_NOTE_ARCHIVE && !(AGENT_NOTE_LIFECYCLES as readonly string[]).includes(entry.name)) {
|
||||
errors.push(`structure: ${entry.name}/ — unknown lifecycle folder (allowed: ${AGENT_NOTE_LIFECYCLES.join(', ')}, plus ${AGENT_NOTE_ARCHIVE}/)`)
|
||||
}
|
||||
}
|
||||
for (const lifecycle of AGENT_NOTE_LIFECYCLES) {
|
||||
for (const match of globSync(`${lifecycle}/**/*.md`, { cwd: agentNoteRoot }).map(p => p.split(sep).join('/')).sort()) {
|
||||
const segs = match.split('/')
|
||||
if (segs.length === 2 && ROOT_ALLOWLIST.has(segs[1] ?? '')) continue
|
||||
if (match.endsWith('.zh.md')) continue
|
||||
const cls = segs[1]
|
||||
const base = segs[2]
|
||||
if (segs.length !== 3 || cls === undefined || base === undefined) {
|
||||
errors.push(`structure: ${match} — expected {lifecycle}/{class}/file.md (got depth ${segs.length})`)
|
||||
continue
|
||||
}
|
||||
if (!(AGENT_NOTE_CLASSES as readonly string[]).includes(cls)) {
|
||||
errors.push(`structure: ${match} — unknown class folder "${cls}" (allowed: ${AGENT_NOTE_CLASSES.join(', ')})`)
|
||||
continue
|
||||
}
|
||||
if (!/^\d{4}-\d{2}-\d{2}-.+\.md$/.test(base)) {
|
||||
errors.push(`structure: ${match} — filename must be yyyy-mm-dd-topic.md`)
|
||||
continue
|
||||
}
|
||||
notes.push({ lifecycle, rel: match, date: base.slice(0, 10) })
|
||||
}
|
||||
}
|
||||
return { notes, errors }
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Enforce Agent Note headers, lifecycle-specific sections, alternatives.
|
||||
* Run: npx tsx scripts/verify-agent-note-format.ts
|
||||
*/
|
||||
import { readFileSync } from "node:fs";
|
||||
import { resolve } from "node:path";
|
||||
import { agentNoteRoot, walkAgentNoteTree } from "./agent-note-tree.ts";
|
||||
|
||||
const FORMAT_ADOPTED = "2026-07-05";
|
||||
const GRANDFATHER = "<!-- agent-note-format: alternatives-not-recorded (pre-format Agent Note) -->";
|
||||
const LEGACY_MARKERS = ["XXX: legacy ADR/RFC body format", "XXX: legacy ADR/Agent Note body format"];
|
||||
const STATUS: Record<string, RegExp> = {
|
||||
proposed: /^Status: proposed$/,
|
||||
implemented: /^Status: implemented$/,
|
||||
rejected: /^Status: rejected — .+$/,
|
||||
};
|
||||
const REQUIRED: Record<string, string[]> = {
|
||||
proposed: ["## Proposal", "## Acceptance criteria", "## Risks"],
|
||||
implemented: ["## Decision", "## Consequences"],
|
||||
rejected: ["## Proposal"],
|
||||
};
|
||||
const BANNED_IMPLEMENTED = /^## (?:Proposal\b|Plan\b|Migration plan\b|Acceptance criteria\b)/i;
|
||||
|
||||
const { notes, errors } = walkAgentNoteTree();
|
||||
for (const note of notes) {
|
||||
const fail = (msg: string) => { errors.push(`format: ${note.rel} — ${msg}`); };
|
||||
const raw = readFileSync(resolve(agentNoteRoot, note.rel), "utf8");
|
||||
const lines = raw.split("\n");
|
||||
let inFence = false;
|
||||
const prose = lines.filter((l) => { if (l.startsWith("```")) { inFence = !inFence; return false; } return !inFence; });
|
||||
if (!/^# Agent Note: \S/.test(lines[0] ?? "")) fail("line 1 must be `# Agent Note: <title>`");
|
||||
if (lines[1] !== "") fail("line 2 must be blank");
|
||||
const re = STATUS[note.lifecycle];
|
||||
if (re && !re.test(lines[2] ?? "")) fail(`line 3 must match ${note.lifecycle} status grammar (${String(re)})`);
|
||||
if (lines[3] !== "") fail("line 4 must be blank");
|
||||
// single Status line
|
||||
const statusCount = prose.filter((l) => l.startsWith("Status:")).length;
|
||||
if (statusCount !== 1) fail("Status: line must appear exactly once");
|
||||
const h2s = prose.filter((l) => l.startsWith("## ")).map((l) => l.trimEnd());
|
||||
if (h2s[0] !== "## Problem") fail(`first section must be ## Problem (got ${JSON.stringify(h2s[0] ?? "<none>")})`);
|
||||
for (const h of REQUIRED[note.lifecycle] ?? []) if (!h2s.includes(h)) fail(`missing ${h}`);
|
||||
if (note.lifecycle === "implemented") for (const h of h2s.filter((x) => BANNED_IMPLEMENTED.test(x))) fail(`banned in implemented: ${h}`);
|
||||
const hasAlt = h2s.includes("## Alternatives considered");
|
||||
const hasGrandfather = prose.includes(GRANDFATHER);
|
||||
if (hasAlt && hasGrandfather) fail("has both ## Alternatives considered and grandfather comment — drop the comment");
|
||||
if (!hasAlt && !hasGrandfather) fail("missing ## Alternatives considered");
|
||||
if (hasGrandfather && note.date >= FORMAT_ADOPTED) fail("grandfather comment only valid before " + FORMAT_ADOPTED);
|
||||
if (prose.some((l) => LEGACY_MARKERS.some((m) => l.includes(m)))) fail("retired legacy-format debt marker");
|
||||
}
|
||||
if (errors.length) { for (const e of errors) console.error(e); process.exit(1); }
|
||||
console.log(`ok: ${notes.length} note(s) verified`);
|
||||
@@ -0,0 +1,5 @@
|
||||
/** Verify tree: lifecycle/class/filename/INDEX. Run: npx tsx scripts/verify-agent-note-tree.ts */
|
||||
import { walkAgentNoteTree } from "./agent-note-tree.ts";
|
||||
const { notes, errors } = walkAgentNoteTree();
|
||||
if (errors.length) { for (const e of errors) console.error(e); process.exit(1); }
|
||||
console.log(`ok: ${notes.length} note(s) tree verified`);
|
||||
@@ -0,0 +1,24 @@
|
||||
# Agent Note: <标题>
|
||||
|
||||
Status: implemented
|
||||
|
||||
## Problem
|
||||
|
||||
<动机,脱离方案也能独立成立>
|
||||
|
||||
## Decision
|
||||
|
||||
<已落地事实,用现在时;含 package 拓扑 / wire 契约 / schema 等自由节>
|
||||
|
||||
## Alternatives considered
|
||||
|
||||
- **<备选 A>** — <为何没选>
|
||||
- **<备选 B>** — <为何没选>
|
||||
|
||||
## Consequences
|
||||
|
||||
<代价与收益同时写;含取舍、边界与后续影响>
|
||||
|
||||
## Testing
|
||||
|
||||
<可选,现在时事实:如何验证、覆盖哪些表面>
|
||||
@@ -0,0 +1,24 @@
|
||||
# Agent Note: <标题>
|
||||
|
||||
Status: proposed
|
||||
|
||||
## Problem
|
||||
|
||||
<动机,脱离方案也能独立成立;写清背景、约束与失败条件>
|
||||
|
||||
## Proposal
|
||||
|
||||
<拟议改动,可用将来时;含关键设计、迁移步骤与开放问题>
|
||||
|
||||
## Alternatives considered
|
||||
|
||||
- **<备选 A>** — <为何没选,一段一备选;或用 ### Why not <X>? 子节>
|
||||
- **<备选 B>** — <同上>
|
||||
|
||||
## Acceptance criteria
|
||||
|
||||
<什么可观察状态算完成;含验证表面与门禁>
|
||||
|
||||
## Risks
|
||||
|
||||
<可能出什么问题、已知取舍与回滚条件>
|
||||
@@ -0,0 +1,19 @@
|
||||
# Agent Note: <标题>
|
||||
|
||||
Status: rejected — <一句话原因>
|
||||
|
||||
## Problem
|
||||
|
||||
<动机>
|
||||
|
||||
## Proposal
|
||||
|
||||
<曾拟议的方案,冻结保留>
|
||||
|
||||
## Alternatives considered
|
||||
|
||||
- **<备选>** — <为何当时考虑/为何最终否掉>
|
||||
|
||||
## Risks
|
||||
|
||||
<为何否掉、若重提需满足什么条件>
|
||||
Reference in New Issue
Block a user