@erzhe/harness-kit 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,81 +1,131 @@
1
1
  # @erzhe/harness-kit
2
2
 
3
- > AI-friendly repo harness —— 把工程知识变成 agent 可消费的**契约层**。
3
+ > Agent 发一句话,让它帮你把仓库变成 AI 友好的。
4
4
 
5
- 一份 `.agents/manifest.yaml` 作为单一事实源,生成各家 agent 的入口文件(`AGENTS.md` / `CLAUDE.md` / Cursor rules),并用**门禁**保证不变量、对外契约和文档不漂移。让不同的人、不同的机器上的 agent,构建出**一模一样的范式**。
5
+ harness-kit 把仓库的工程知识(这是什么、怎么跑、什么不能破、改东西看哪)沉淀成一份 `.agents/manifest.yaml`,然后自动生成各家 Agent 的入口文件(`AGENTS.md` / `CLAUDE.md` / Cursor rules),并用门禁保证它们始终一致。
6
6
 
7
- > 包名 `@erzhe/harness-kit`,安装后命令行工具叫 **`harness-kit`**。
7
+ ---
8
8
 
9
- ## 最快上手(推荐,零安装)
9
+ ## 最快上手
10
10
 
11
- 在**任意仓库**里,把这句丢给你的 agent(Cursor / Claude Code / Codex 通用):
11
+ 在**任意仓库**里,把这句话丢给你的 Agent(Cursor / Claude Code / Codex 通用):
12
12
 
13
- > Onboard 本仓库到 harness-kit:跑 `npx -y @erzhe/harness-kit@latest onboard`,然后严格按输出执行。
13
+ ```
14
+ Onboard 本仓库到 harness-kit:跑 npx -y @erzhe/harness-kit@latest onboard,然后严格按输出执行。
15
+ ```
14
16
 
15
- agent 会拉取**最新版**的 onboard skill 并照着做:仓库考古 → 逐块跟你确认着填 `.agents/manifest.yaml` → `sync` / `doctor` / `verify` 到绿。全程走 `npx`,不往机器上装任何全局东西;你一发新版,所有人下次执行就用上了。
17
+ 就这一句。Agent 会:
16
18
 
17
- ## 为什么
19
+ 1. 拉取最新版的 onboard skill
20
+ 2. 扫描你的仓库(读 README、package.json、目录结构…)
21
+ 3. 逐块跟你确认着填 `.agents/manifest.yaml`
22
+ 4. 跑 `sync` / `doctor` / `verify` 直到全绿
18
23
 
19
- 传统工程化(脚手架 / lint / CI)是**面向过去、面向人**的。Agent 需要的是显式、结构化、可机器消费的知识:这个仓库是什么、能跑什么、什么绝不能破、改动该看哪、哪些验证不了。`harness-kit` 把这些沉淀进 manifest,再确定性地生成与校验。
24
+ 全程走 `npx`,不往机器上装任何全局东西;你一发新版,所有人下次执行就用上了。
20
25
 
21
- ## 安装
26
+ ---
22
27
 
23
- ```bash
24
- npm i -g @erzhe/harness-kit # 或 pnpm add -g / 直接 npx @erzhe/harness-kit
25
- harness-kit --help
28
+ ## 初始化后你得到什么
29
+
30
+ ```
31
+ 你的仓库/
32
+ AGENTS.md ← [生成] 跨工具入口,Agent 每次会话必读
33
+ CLAUDE.md ← [生成] Claude Code 入口
34
+ .cursor/rules/ ← [生成] Cursor 规则
35
+ .agents/
36
+ manifest.yaml ← 你维护的唯一真相源
37
+ knowledge/ ← Agent 从代码推不出来的知识(领域、约定、决策)
38
+ contracts/ ← 对外接口的契约基线
39
+ playbooks/ ← 可复用的工作流(SKILL.md)
40
+ routing.md ← [生成] 按改动类型导航:改 UI 看哪、加接口看哪
41
+ modules.md ← [生成] 模块卡:每个子系统的职责/入口/坑
26
42
  ```
27
43
 
44
+ 以后改工程知识 → 编辑 `manifest.yaml` → `harness-kit sync`。别手改生成物。
45
+
46
+ ---
47
+
28
48
  ## 命令
29
49
 
30
- ```
31
- harness-kit onboard # 打印 onboard skill 给 agent(配合 npx,永远最新、零安装)
32
- harness-kit init # .agents/ 骨架 + starter manifest
33
- harness-kit sync # manifest -> AGENTS.md / CLAUDE.md / Cursor rules / routing / modules
34
- harness-kit doctor # 开发态体检:补全度 / 引用路径 / 漂移 / 新鲜度 / 体量预算
35
- harness-kit verify # 门禁(CI):跑不变量 + 契约 + 漂移,列出 GAPS,失败非 0 退出
36
- harness-kit accept-contract # 一次预期的接口变更后,记录新的契约指纹为基线
37
- ```
50
+ | 命令 | 作用 |
51
+ | --- | --- |
52
+ | `harness-kit onboard` | 打印 onboard skill Agent(配合 npx,永远最新、零安装) |
53
+ | `harness-kit init` | `.agents/` 骨架 + 空白 manifest |
54
+ | `harness-kit sync` | manifest → 生成 AGENTS.md / CLAUDE.md / Cursor rules / routing / modules |
55
+ | `harness-kit doctor` | 体检:完整性 / 路径引用 / 漂移 / 新鲜度 / 体量预算 |
56
+ | `harness-kit verify` | 门禁:跑不变量 + 契约 + 漂移,列出 GAPS,失败非 0 退出 |
57
+ | `harness-kit accept-contract` | 有意变更接口后,记录新的契约指纹为基线 |
58
+ | `harness-kit install-hooks` | 装 git 钩子:pre-commit 自动 sync + pre-push verify 拦漂移 |
59
+
60
+ 所有命令都支持 `-C <dir>` 指定目标仓库(默认当前目录)。
61
+
62
+ ---
63
+
64
+ ## 它解决什么问题
38
65
 
39
- ## 心智模型
66
+ 传统工程化(脚手架 / lint / CI)是**面向人、面向过去**的。Agent 需要的是显式、结构化、可机器消费的知识:
67
+
68
+ - **这是什么** → `identity`(name / summary / scope)
69
+ - **怎么跑** → `capabilities`(setup / build / test / dev…)
70
+ - **什么绝不能破** → `invariants`(声明式正则门禁)+ `contracts`(接口指纹基线)
71
+ - **改东西看哪** → `routing`(按改动类型导航)+ `modules`(模块卡)
72
+ - **哪些验证不了** → `GAPS`(诚实标注,绝不谎报)
73
+
74
+ harness-kit 把这些沉淀进 manifest,再确定性地生成与校验。
75
+
76
+ ---
77
+
78
+ ## 工作原理
40
79
 
41
80
  ```
42
- .agents/manifest.yaml (你 + agent 维护的唯一源)
43
- |
81
+ .agents/manifest.yaml (你 + Agent 维护的唯一源)
82
+
44
83
  harness-kit sync (确定性生成,勿手改产物)
45
- v
84
+
46
85
  AGENTS.md / CLAUDE.md / .cursor/rules / .agents/routing.md / .agents/modules.md
47
- |
48
- harness-kit verify (门禁:不变量 enforcement + 契约 snapshot + 生成物/知识漂移)
49
- v
50
- exit 0 / 非 0 + 诚实的 GAPS 清单(查不了的东西绝不谎报)
86
+
87
+ harness-kit verify (门禁:不变量 + 契约 + 漂移)
88
+
89
+ exit 0 / 非 0 + 诚实的 GAPS 清单
51
90
  ```
52
91
 
53
- - **不变量**:声明式正则 `enforcement`(确定性、无 LLM),或标 `manual`。
54
- - **契约**:协议无关——`check`(跑仓库自带工具看退出码)或 `snapshot`(打印接口指纹 → CLI 存基线并 diff)。
55
- - **新鲜度**:知识条目 / 模块卡 `binds` 源文件哈希,代码一动就告警,无需人肉维护日期。
56
- - **GAPS**:打包 / 真网络 / 生产上传等本地验证不了的,`verify` 显式列出,绝不假装通过。
92
+ - **不变量**:声明式正则 `enforcement`(确定性、无 LLM),或标 `manual`
93
+ - **契约**:`snapshot` 打印接口指纹 → CLI 存基线并 diff(协议无关)
94
+ - **新鲜度**:知识条目 `binds` 源文件哈希,代码一动就告警
95
+ - **GAPS**:打包 / 真网络 / 生产上传等本地验证不了的,显式列出
57
96
 
58
- ## 让 agent 来配置:onboard skill
97
+ ---
59
98
 
60
- 手写 manifest 门槛高,但对 agent 是绝配。随包附带的 [`skills/erzhe-harness-init`](skills/erzhe-harness-init/SKILL.md) 引导 agent 做仓库考古、逐块跟你确认着填 manifest、再跑 `sync/doctor/verify` 到绿。
99
+ ## Agent 自动触发(可选)
61
100
 
62
- 最省事的用法就是上面的 [最快上手](#最快上手推荐零安装)——`npx ... onboard` skill 打印给 agent,零安装、永远最新。若想让某个 agent **自动触发**(不用每次点名),可选地把 skill 软链进它的 skill 目录:`ln -sf "$(npm root -g)/@erzhe/harness-kit/skills/erzhe-harness-init" ~/.cursor/skills/`。
101
+ 上面的"最快上手"是**显式调用**——你每次说"onboard 本仓库",Agent 才会做。如果你想让某个 Agent **自动识别**"该给仓库接 harness-kit",可以把 skill 软链进它的 skill 目录:
63
102
 
64
- ## 文档
103
+ ```bash
104
+ # Cursor
105
+ ln -sf "$(npm root -g)/@erzhe/harness-kit/skills/erzhe-harness-init" ~/.cursor/skills/
65
106
 
66
- - [`SPEC-v0.md`](SPEC-v0.md) —— manifest schema + 生成/校验契约(当前 v0.2)
67
- - [`DESIGN.md`](DESIGN.md) —— 设计决策、调研与决策日志
107
+ # Claude Code
108
+ ln -sf "$(npm root -g)/@erzhe/harness-kit/skills/erzhe-harness-init" ~/.claude/skills/
109
+ ```
110
+
111
+ 这样当用户说"给这个仓库配置 harness"时,Agent 会自动找到并执行这个 skill。
112
+
113
+ ---
68
114
 
69
115
  ## 开发
70
116
 
71
117
  ```bash
72
118
  pnpm install
73
- pnpm typecheck
74
- pnpm test # node:test + tsx,核心逻辑单测
75
- pnpm build # esbuild 打包成 dist/harness-kit.cjs 单文件可执行
76
- pnpm exec tsx src/cli.ts verify --repo . # 开发态直接跑,且自托管验证本仓
119
+ pnpm typecheck # tsc --noEmit
120
+ pnpm test # node:test + tsx
121
+ pnpm build # esbuild dist/harness-kit.cjs
122
+ pnpm exec tsx src/cli.ts verify --repo . # 自托管验证
77
123
  ```
78
124
 
125
+ ## 文档
126
+
127
+ - [`SPEC-v0.md`](SPEC-v0.md) — manifest schema + 生成/校验契约
128
+
79
129
  ## License
80
130
 
81
131
  MIT © [MeCKodo (二哲)](https://erzhe.me/)
@@ -11883,41 +11883,41 @@ var require_queue = __commonJS({
11883
11883
  queue.drained = drained;
11884
11884
  return queue;
11885
11885
  function push(value) {
11886
- var p = new Promise(function(resolve2, reject) {
11886
+ var p = new Promise(function(resolve3, reject) {
11887
11887
  pushCb(value, function(err2, result) {
11888
11888
  if (err2) {
11889
11889
  reject(err2);
11890
11890
  return;
11891
11891
  }
11892
- resolve2(result);
11892
+ resolve3(result);
11893
11893
  });
11894
11894
  });
11895
11895
  p.catch(noop);
11896
11896
  return p;
11897
11897
  }
11898
11898
  function unshift(value) {
11899
- var p = new Promise(function(resolve2, reject) {
11899
+ var p = new Promise(function(resolve3, reject) {
11900
11900
  unshiftCb(value, function(err2, result) {
11901
11901
  if (err2) {
11902
11902
  reject(err2);
11903
11903
  return;
11904
11904
  }
11905
- resolve2(result);
11905
+ resolve3(result);
11906
11906
  });
11907
11907
  });
11908
11908
  p.catch(noop);
11909
11909
  return p;
11910
11910
  }
11911
11911
  function drained() {
11912
- var p = new Promise(function(resolve2) {
11912
+ var p = new Promise(function(resolve3) {
11913
11913
  process.nextTick(function() {
11914
11914
  if (queue.idle()) {
11915
- resolve2();
11915
+ resolve3();
11916
11916
  } else {
11917
11917
  var previousDrain = queue.drain;
11918
11918
  queue.drain = function() {
11919
11919
  if (typeof previousDrain === "function") previousDrain();
11920
- resolve2();
11920
+ resolve3();
11921
11921
  queue.drain = previousDrain;
11922
11922
  };
11923
11923
  }
@@ -12403,9 +12403,9 @@ var require_stream3 = __commonJS({
12403
12403
  });
12404
12404
  }
12405
12405
  _getStat(filepath) {
12406
- return new Promise((resolve2, reject) => {
12406
+ return new Promise((resolve3, reject) => {
12407
12407
  this._stat(filepath, this._fsStatSettings, (error, stats) => {
12408
- return error === null ? resolve2(stats) : reject(error);
12408
+ return error === null ? resolve3(stats) : reject(error);
12409
12409
  });
12410
12410
  });
12411
12411
  }
@@ -12429,10 +12429,10 @@ var require_async5 = __commonJS({
12429
12429
  this._readerStream = new stream_1.default(this._settings);
12430
12430
  }
12431
12431
  dynamic(root, options) {
12432
- return new Promise((resolve2, reject) => {
12432
+ return new Promise((resolve3, reject) => {
12433
12433
  this._walkAsync(root, options, (error, entries) => {
12434
12434
  if (error === null) {
12435
- resolve2(entries);
12435
+ resolve3(entries);
12436
12436
  } else {
12437
12437
  reject(error);
12438
12438
  }
@@ -12442,10 +12442,10 @@ var require_async5 = __commonJS({
12442
12442
  async static(patterns, options) {
12443
12443
  const entries = [];
12444
12444
  const stream = this._readerStream.static(patterns, options);
12445
- return new Promise((resolve2, reject) => {
12445
+ return new Promise((resolve3, reject) => {
12446
12446
  stream.once("error", reject);
12447
12447
  stream.on("data", (entry) => entries.push(entry));
12448
- stream.once("end", () => resolve2(entries));
12448
+ stream.once("end", () => resolve3(entries));
12449
12449
  });
12450
12450
  }
12451
12451
  };
@@ -16471,7 +16471,7 @@ function useColor() {
16471
16471
  var program = new Command();
16472
16472
 
16473
16473
  // src/cli.ts
16474
- var import_node_path12 = require("node:path");
16474
+ var import_node_path13 = require("node:path");
16475
16475
 
16476
16476
  // src/commands/init.ts
16477
16477
  var import_node_fs3 = require("node:fs");
@@ -17164,14 +17164,87 @@ function acceptContractCmd(repo, id) {
17164
17164
  return problems ? 1 : 0;
17165
17165
  }
17166
17166
 
17167
- // src/commands/onboard.ts
17167
+ // src/commands/install-hooks.ts
17168
+ var import_node_child_process4 = require("node:child_process");
17168
17169
  var import_node_fs7 = require("node:fs");
17169
17170
  var import_node_path11 = require("node:path");
17171
+ var MARK = "harness-kit-managed-hook";
17172
+ function hooksDir(repo) {
17173
+ const out = (0, import_node_child_process4.execSync)("git rev-parse --git-path hooks", { cwd: repo, encoding: "utf8" }).trim();
17174
+ return (0, import_node_path11.resolve)(repo, out);
17175
+ }
17176
+ function preCommit() {
17177
+ return `#!/bin/sh
17178
+ # ${MARK} (pre-commit): regenerate agent files from the manifest and stage them,
17179
+ # so generated docs never drift from .agents/manifest.yaml.
17180
+ # Reset with \`harness-kit install-hooks --force\`; delete this file to remove.
17181
+ [ -f .agents/manifest.yaml ] || exit 0
17182
+ HK="\${HARNESS_KIT_CMD:-npx -y @erzhe/harness-kit@latest}"
17183
+ if ! $HK sync --repo . >/dev/null; then
17184
+ echo "harness-kit: sync failed (run \\\`$HK sync\\\` to see why)" >&2
17185
+ exit 1
17186
+ fi
17187
+ git add AGENTS.md CLAUDE.md .cursor/rules .agents >/dev/null 2>&1 || true
17188
+ exit 0
17189
+ `;
17190
+ }
17191
+ function prePush() {
17192
+ return `#!/bin/sh
17193
+ # ${MARK} (pre-push): block the push when the agent context has drifted from code.
17194
+ # Bypass once with \`git push --no-verify\`.
17195
+ [ -f .agents/manifest.yaml ] || exit 0
17196
+ HK="\${HARNESS_KIT_CMD:-npx -y @erzhe/harness-kit@latest}"
17197
+ if ! $HK verify --repo .; then
17198
+ echo "" >&2
17199
+ echo "harness-kit: verify failed \u2014 agent context drifted from code." >&2
17200
+ echo " self-heal: run an agent with \\\`$HK onboard\\\` and follow its Maintenance section," >&2
17201
+ echo " then review the diff. Bypass once with \\\`git push --no-verify\\\`." >&2
17202
+ exit 1
17203
+ fi
17204
+ exit 0
17205
+ `;
17206
+ }
17207
+ function installHooksCmd(repo, force = false) {
17208
+ let dir;
17209
+ try {
17210
+ dir = hooksDir(repo);
17211
+ } catch {
17212
+ err("not a git repo (git rev-parse failed) \u2014 run inside a git working tree");
17213
+ return 1;
17214
+ }
17215
+ const targets = [
17216
+ ["pre-commit", preCommit()],
17217
+ ["pre-push", prePush()]
17218
+ ];
17219
+ for (const [name, body] of targets) {
17220
+ const p = (0, import_node_path11.join)(dir, name);
17221
+ if ((0, import_node_fs7.existsSync)(p) && !force) {
17222
+ const cur = (0, import_node_fs7.readFileSync)(p, "utf8");
17223
+ if (!cur.includes(MARK)) {
17224
+ warn(`${name} exists and isn't harness-kit-managed \u2014 skipped (use --force to overwrite)`);
17225
+ continue;
17226
+ }
17227
+ }
17228
+ writeText(p, body);
17229
+ (0, import_node_fs7.chmodSync)(p, 493);
17230
+ ok(`installed ${name}`);
17231
+ }
17232
+ info(`
17233
+ Hooks written to ${dir}`);
17234
+ info("pre-commit: regenerates agent files from the manifest and stages them.");
17235
+ info("pre-push: runs `harness-kit verify` and blocks on drift (bypass: git push --no-verify).");
17236
+ info("override the CLI it calls with env HARNESS_KIT_CMD (e.g. for local dev).");
17237
+ return 0;
17238
+ }
17239
+
17240
+ // src/commands/onboard.ts
17241
+ var import_node_fs8 = require("node:fs");
17242
+ var import_node_path12 = require("node:path");
17170
17243
  var import_node_url = require("node:url");
17171
17244
  var import_meta = {};
17172
17245
  function moduleDir() {
17173
17246
  if (typeof __dirname !== "undefined" && __dirname) return __dirname;
17174
- return (0, import_node_path11.dirname)((0, import_node_url.fileURLToPath)(import_meta.url));
17247
+ return (0, import_node_path12.dirname)((0, import_node_url.fileURLToPath)(import_meta.url));
17175
17248
  }
17176
17249
  var HERE = moduleDir();
17177
17250
  var SKILL_REL = "skills/erzhe-harness-init/SKILL.md";
@@ -17185,9 +17258,9 @@ Do not fabricate: confirm uncertain fields with the user, and report honest GAPS
17185
17258
 
17186
17259
  `;
17187
17260
  function resolveSkill() {
17188
- for (const up of ["..", (0, import_node_path11.join)("..", "..")]) {
17189
- const p = (0, import_node_path11.join)(HERE, up, SKILL_REL);
17190
- if ((0, import_node_fs7.existsSync)(p)) return p;
17261
+ for (const up of ["..", (0, import_node_path12.join)("..", "..")]) {
17262
+ const p = (0, import_node_path12.join)(HERE, up, SKILL_REL);
17263
+ if ((0, import_node_fs8.existsSync)(p)) return p;
17191
17264
  }
17192
17265
  return null;
17193
17266
  }
@@ -17198,7 +17271,7 @@ function onboardCmd() {
17198
17271
  return 1;
17199
17272
  }
17200
17273
  process.stdout.write(META);
17201
- process.stdout.write((0, import_node_fs7.readFileSync)(p, "utf8"));
17274
+ process.stdout.write((0, import_node_fs8.readFileSync)(p, "utf8"));
17202
17275
  return 0;
17203
17276
  }
17204
17277
 
@@ -17213,13 +17286,14 @@ function guard(fn) {
17213
17286
  }
17214
17287
  }
17215
17288
  var program2 = new Command();
17216
- program2.name("harness-kit").description("AI-friendly repo harness").version("0.1.1");
17217
- var repoOf = (o) => (0, import_node_path12.resolve)(o.repo);
17289
+ program2.name("harness-kit").description("AI-friendly repo harness").version("0.1.2");
17290
+ var repoOf = (o) => (0, import_node_path13.resolve)(o.repo);
17218
17291
  program2.command("init").description("scaffold .agents/ skeleton + starter manifest").option("-C, --repo <dir>", "target repo dir", process.cwd()).option("--name <name>", "project name", "my-project").option("--force", "overwrite existing manifest", false).action((o) => guard(() => initCmd(repoOf(o), o.name, o.force)));
17219
17292
  program2.command("sync").description("generate tool files (AGENTS.md, CLAUDE.md, .cursor rules) from manifest").option("-C, --repo <dir>", "target repo dir", process.cwd()).action((o) => guard(() => syncCmd(repoOf(o))));
17220
17293
  program2.command("doctor").description("dev-time health check: completeness, drift, freshness, tech debt").option("-C, --repo <dir>", "target repo dir", process.cwd()).action((o) => guard(() => doctorCmd(repoOf(o))));
17221
17294
  program2.command("verify").description("CI gate: run enforceable invariants + contracts + drift; nonzero on failure").option("-C, --repo <dir>", "target repo dir", process.cwd()).action((o) => guard(() => verifyCmd(repoOf(o))));
17222
17295
  program2.command("accept-contract").description("record current contract fingerprint(s) as the accepted baseline (after an intended change)").option("-C, --repo <dir>", "target repo dir", process.cwd()).option("--id <id>", "only this contract (default: all with a snapshot command)").action((o) => guard(() => acceptContractCmd(repoOf(o), o.id)));
17296
+ program2.command("install-hooks").description("install git hooks: pre-commit auto-sync + pre-push verify (drift gate)").option("-C, --repo <dir>", "target repo dir", process.cwd()).option("--force", "overwrite existing hooks", false).action((o) => guard(() => installHooksCmd(repoOf(o), o.force)));
17223
17297
  program2.command("onboard").description("print the erzhe-harness-init skill for an agent to follow (use via npx, always latest)").action(() => guard(() => onboardCmd()));
17224
17298
  program2.parseAsync();
17225
17299
  /*! Bundled license information:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@erzhe/harness-kit",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "description": "AI-friendly repo harness: a manifest.yaml single source of truth that generates AGENTS.md / CLAUDE.md / Cursor rules and enforces invariants, contracts and drift via `harness-kit verify`.",
6
6
  "keywords": [
@@ -66,7 +66,36 @@ harness-kit verify # 门禁:跑不变量 + 契约 + 漂移,并列
66
66
 
67
67
  - `harness-kit verify` 退出码 0;`GAPS` 段里每一条都是**真的没法自动查**(打包 / 真网络 / 生产上传 / 人肉不变量),不是偷懒。
68
68
  - `AGENTS.md` 在体量预算内(`doctor` 第 6 项会报行数/词数)。
69
- - 把生成物 + `.agents/` + 契约基线一起提交;告诉用户:**以后改 manifest → `harness-kit sync`,别手改生成物**;把 `harness-kit verify` 挂进 CI / pre-commit 才能真正兑现"跨人跨机一致"。
69
+ - 把生成物 + `.agents/` + 契约基线一起提交;告诉用户:**以后改 manifest → `harness-kit sync`,别手改生成物**。
70
+ - 装上自动化门禁,让防腐烂不靠人自律:
71
+ ```
72
+ harness-kit install-hooks --repo .
73
+ ```
74
+ pre-commit 自动 sync 并暂存生成物、pre-push 跑 `verify` 拦漂移;团队再把 `harness-kit verify` 放进 CI,才能真正兑现"跨人跨机一致"。
75
+
76
+ ## 5. 日常维护 / 自愈(接入之后,长期靠这个防腐烂)
77
+
78
+ harness-kit 的持续价值不在首次接入,而在**代码演进时上下文不腐烂**。机制是:门禁发现漂移 → agent 自动修 → 人只 review。**别把维护活丢回给人**——你(agent)来修,人只做最后一次审查。
79
+
80
+ **触发**:`harness-kit verify` 非零,或 `doctor` 报 drift / 新鲜度告警(装了 pre-push hook 会在 push 时自动拦)。
81
+
82
+ **自愈流程(你就是那个 agent,按此做):**
83
+ 1. 跑 `harness-kit verify`,逐条读红灯——它已把"哪块过期 / 哪个契约变了 / 该 sync 还是该 accept"写清楚了。
84
+ 2. 逐条处理:
85
+ - **生成物 drift**("AGENTS.md drifted, run sync")→ 直接 `harness-kit sync`。
86
+ - **knowledge 新鲜度告警**(绑定的源文件变了)→ 重新读那个源文件,判断知识是否真过时;过时就改 `.agents/knowledge/*` 或对应 manifest 字段再 sync。**没实质变化就别乱改**。
87
+ - **契约 drift**(snapshot 变了)→ 看对应代码改动:确属**有意**改接口(有需求 / commit 佐证)才 `harness-kit accept-contract --id <id>`;拿不准是否 breaking 就**别 accept**,标给人。
88
+ - **invariant 违规** → 按规则修代码;确认该规则已过时才动 manifest。
89
+ 3. 全部处理完再 `verify` 到退出码 0。
90
+ 4. **产出一份变更清单交给人 review(这是唯一的人工动作)**,至少含:
91
+ - 改了哪些 manifest 字段 / knowledge 文件,为什么;
92
+ - accept 了哪些契约、对应什么代码改动、是否 breaking;
93
+ - 哪些**没动**及原因。
94
+
95
+ **红线**:
96
+ - 契约 accept 必须有据可依且**必写进给人的清单**——绝不静默 auto-accept 对外接口变更。
97
+ - 拿不准就标 GAP 交人,别用幻觉填。
98
+ - 只修真漂移,别为了凑绿去改无关内容。
70
99
 
71
100
  ## 反模式(别做)
72
101