@erzhe/harness-kit 0.3.0 → 0.4.0

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
@@ -77,8 +77,8 @@ harness-kit 的长期价值不在首次接入,而在**代码演进时上下文
77
77
  | `harness-kit prepare-adoption` | 在仓外生成私有 blind-audit bundle;包含旧入口、嵌套 AGENTS/CLAUDE 及它们显式引用的文档证据和确定性候选,不改仓内文件 |
78
78
  | `harness-kit record-adoption-audit` | 把声明的 pass/fail、理由和审计报告 hash 绑定到一版候选 |
79
79
  | `harness-kit sync --adopt-existing --candidate ... --audit ...` | 首次接管:只有 live legacy、候选、manifest 和 pass receipt 逐字节一致才事务写入 |
80
- | `harness-kit doctor` | 体检:完整性 / 路径引用 / 漂移 / 新鲜度 / 体量预算 |
81
- | `harness-kit verify [--json]` | 门禁:跑不变量 + 契约 + 漂移,列出 GAPS;可输出单个结构化 JSON,失败非 0 退出 |
80
+ | `harness-kit doctor [--details]` | 体检:完整性 / 路径引用 / 漂移 / 新鲜度 / 体量预算;默认折叠无需马上处理的边界 |
81
+ | `harness-kit verify [--json] [--details]` | 门禁:跑不变量 + 契约 + 漂移,给出分类后的下一步;失败非 0 退出 |
82
82
  | `harness-kit accept-contract` | 有意变更接口后,记录新的契约指纹为基线 |
83
83
  | `harness-kit install-hooks` | 可选装原生 Git hooks;共享 worktree、自定义/全局路径或第三方 hook 时安全拒绝 |
84
84
  | `harness-kit install-hooks --stop --agents <client>` | 只给实际使用的客户端装生命周期门禁:会话开始记基线,结束前跑 `run-checks` + `verify` |
@@ -91,6 +91,17 @@ harness-kit 的长期价值不在首次接入,而在**代码演进时上下文
91
91
 
92
92
  所有命令都支持 `-C <dir>` 指定目标仓库(默认当前目录)。
93
93
 
94
+ ### 怎么看验证结果
95
+
96
+ `verify` 不再把所有无法自动执行的事项混成一个 GAP 数字:
97
+
98
+ - **REQUIRED | AGENT**:当前 Agent 自动完成后才能收尾,例如安装 Hook、重跑过期 evidence。
99
+ - **REQUIRED | HUMAN**:Harness 发现不属于自己的 Hook 或必须由宿主授权,只请你确认这一项具体变更。
100
+ - **RECOMMENDED**:自动化覆盖可以继续改善,只在首次接入或专门维护 Harness 时处理,不扩大普通业务任务。
101
+ - **INFORMATIONAL**:发布、真实网络、生产上传、后台服务等只在相关任务中验证,不是失败,也不需要平时逐条处理。
102
+
103
+ 默认文本只展开当前必须处理的动作;`--details` 展开全部声明,`--json` 提供 `gapDetails`、`gapSummary` 和 `nextActions` 给 Agent 稳定执行。`verify: OK` 表示声明的确定性门禁已通过;只有同时显示 `Harness readiness: READY`,才表示 Lifecycle Hook 等初始化收尾也已完成。
104
+
94
105
  首次接管是一个窄状态机,不靠 Agent 记住长说明:`init` 保存将被接管的旧入口 → `prepare-adoption` 在仓外收集原地 guidance 并生成候选 → 独立 Agent 盲审 → `record-adoption-audit` 绑定报告 → 带 candidate/receipt 的 `sync --adopt-existing` 才能写真实入口。manifest、旧入口、snapshot/index、嵌套入口/显式引用文档、候选文件或审计报告任一变化,旧回执立即失效;裸 `--adopt-existing` 不能接管。回执明确写 `assurance: declared`、`independence: unverified`:它能强制顺序和准确字节,不能在没有外部身份系统时伪装证明“审计者一定独立、语义判断一定正确”。
95
106
 
96
107
  ## 实现之后,怎么保证真的验收了
@@ -143,7 +154,7 @@ knowledge:
143
154
  - **怎么跑** → `capabilities`(setup / build / test / dev…)
144
155
  - **什么绝不能破** → `invariants`(声明式正则门禁)+ `contracts`(接口指纹基线)
145
156
  - **改东西看哪** → `routing`(按改动类型导航)+ `modules`(模块卡)
146
- - **哪些验证不了** → `GAPS`(诚实标注,绝不谎报)
157
+ - **哪些验证不了** → 分类后的验证边界与 `nextActions`(明确何时需要、谁来处理)
147
158
 
148
159
  harness-kit 把这些沉淀进 manifest,再确定性地生成与校验。
149
160
 
@@ -162,7 +173,7 @@ harness-kit 把这些沉淀进 manifest,再确定性地生成与校验。
162
173
  - **不变量**:声明式正则 `enforcement`(确定性、无 LLM),或标 `manual`
163
174
  - **契约**:`snapshot` 打印接口指纹 → CLI 存基线并 diff(协议无关)
164
175
  - **新鲜度**:知识条目可登记任意 repo 内相对路径;`authority` 决定语义责任,Agent 审查后记录内容与 `binds` hash,任何一侧变化都会失效
165
- - **GAPS**:打包 / 真网络 / 生产上传等本地验证不了的,显式列出
176
+ - **验证边界**:打包 / 真网络 / 生产上传等本地验证不了的,按场景保留;默认不冒充故障反复提醒
166
177
 
167
178
  ---
168
179
 
@@ -18185,7 +18185,7 @@ var import_node_path18 = require("node:path");
18185
18185
  // package.json
18186
18186
  var package_default = {
18187
18187
  name: "@erzhe/harness-kit",
18188
- version: "0.3.0",
18188
+ version: "0.4.0",
18189
18189
  type: "module",
18190
18190
  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`.",
18191
18191
  keywords: [
@@ -19182,12 +19182,15 @@ function renderAgentsMd(m) {
19182
19182
  "3. Run `harness-kit run-checks` to verify THIS change (impact-driven) and `harness-kit verify` for drift/invariants. Treat blocking gaps as unfinished work \u2014 close them; only eligible coverage gaps may be waived with a scoped reason."
19183
19183
  );
19184
19184
  else
19185
- L.push("3. Run `harness-kit verify`. It enforces the invariants below and prints a **GAPS** list of what it cannot check.");
19185
+ L.push("3. Run `harness-kit verify`. It enforces the invariants below and classifies anything it cannot check automatically.");
19186
19186
  L.push(
19187
- "4. **Never claim a check you didn't run.** If something is a GAP (packaging, real network, prod upload), say so \u2014 don't pretend it passed."
19187
+ "4. Read `NEXT ACTIONS` (or JSON `nextActions`): complete every `required | agent` action automatically before finishing; ask the user only for a `required | human` decision. Defer `recommended` maintenance during unrelated product work."
19188
19188
  );
19189
19189
  L.push(
19190
- "5. If you learned something an agent could not infer from code (a gotcha, a decision, a fix), update the registered knowledge source in place, or add new Harness-owned knowledge under `.agents/knowledge/` (a journal ADR for decisions). Never move/copy an existing repo document just to fit a folder name. Do NOT record one-off noise or anything already obvious from the code."
19190
+ "5. **Never claim a check you didn't run.** Informational boundaries (packaging, real network, prod upload) are not failures; mention one only when it is relevant to this task."
19191
+ );
19192
+ L.push(
19193
+ "6. If you learned something an agent could not infer from code (a gotcha, a decision, a fix), update the registered knowledge source in place, or add new Harness-owned knowledge under `.agents/knowledge/` (a journal ADR for decisions). Never move/copy an existing repo document just to fit a folder name. Do NOT record one-off noise or anything already obvious from the code."
19191
19194
  );
19192
19195
  L.push("");
19193
19196
  if (id.scope_in?.length || id.scope_out?.length) {
@@ -20409,6 +20412,229 @@ var import_fast_glob2 = __toESM(require_out4(), 1);
20409
20412
  var import_node_fs12 = require("node:fs");
20410
20413
  var import_node_path12 = require("node:path");
20411
20414
 
20415
+ // src/guidance.ts
20416
+ function gap(kind, scope, classification, title, reason, when, legacyText) {
20417
+ return { id: `${kind}:${scope}`, kind, scope, classification, title, reason, when, legacyText };
20418
+ }
20419
+ function declaredVerificationGaps(manifest) {
20420
+ const gaps = [];
20421
+ for (const invariant of manifest.invariants ?? []) {
20422
+ if (invariant.manual) {
20423
+ gaps.push(gap(
20424
+ "manual-invariant",
20425
+ invariant.id,
20426
+ "informational",
20427
+ `Review invariant ${invariant.id} when relevant`,
20428
+ invariant.rule,
20429
+ "Only when a change may affect this declared rule.",
20430
+ `invariant ${invariant.id}: manual, not machine-enforced \u2014 ${invariant.rule}`
20431
+ ));
20432
+ } else if (!invariant.enforcement && !invariant.check) {
20433
+ gaps.push(gap(
20434
+ "unenforced-invariant",
20435
+ invariant.id,
20436
+ "recommended",
20437
+ `Add enforcement for invariant ${invariant.id}`,
20438
+ invariant.rule,
20439
+ "During onboarding or a dedicated Harness-maintenance task, not an unrelated product change.",
20440
+ `invariant ${invariant.id}: no enforcement/check declared \u2014 ${invariant.rule}`
20441
+ ));
20442
+ }
20443
+ }
20444
+ for (const contract of manifest.contracts ?? []) {
20445
+ if (contract.check || contract.snapshot) continue;
20446
+ const legacyText = `contract ${contract.id}: no automatic check` + (contract.manual_verify ? ` \u2014 verify by hand: ${contract.manual_verify}` : "");
20447
+ if (contract.manual_verify) {
20448
+ gaps.push(gap(
20449
+ "manual-contract",
20450
+ contract.id,
20451
+ "informational",
20452
+ `Verify contract ${contract.id} when it changes`,
20453
+ contract.manual_verify,
20454
+ "Only when this contract is changed or before the release that carries it.",
20455
+ legacyText
20456
+ ));
20457
+ } else {
20458
+ gaps.push(gap(
20459
+ "unchecked-contract",
20460
+ contract.id,
20461
+ "recommended",
20462
+ `Add a check or manual procedure for contract ${contract.id}`,
20463
+ "The contract has neither an automatic check nor a declared manual verification procedure.",
20464
+ "During onboarding or a dedicated Harness-maintenance task.",
20465
+ legacyText
20466
+ ));
20467
+ }
20468
+ }
20469
+ for (const [verb, capability] of Object.entries(manifest.capabilities ?? {})) {
20470
+ if (capability.mutating) {
20471
+ gaps.push(gap(
20472
+ "mutating-capability",
20473
+ verb,
20474
+ "informational",
20475
+ `Run ${verb} only when deliberately requested`,
20476
+ `The command \`${capability.run}\` can change external or repository state, so verify never runs it automatically.`,
20477
+ "Only when the task explicitly requires this capability.",
20478
+ `capability ${verb} (\`${capability.run}\`): mutating \u2014 not run here, verify deliberately`
20479
+ ));
20480
+ } else if (capability.background) {
20481
+ gaps.push(gap(
20482
+ "background-capability",
20483
+ verb,
20484
+ "informational",
20485
+ `Exercise ${verb} only when its runtime is relevant`,
20486
+ `The command \`${capability.run}\` is long-running, so verify does not start it.`,
20487
+ "Only for tasks that need the live service or background process.",
20488
+ `capability ${verb} (\`${capability.run}\`): long-running \u2014 not run in this gate`
20489
+ ));
20490
+ }
20491
+ }
20492
+ return gaps;
20493
+ }
20494
+ function automationAction(gaps) {
20495
+ const recommended = gaps.filter((item) => item.classification === "recommended");
20496
+ if (!recommended.length) return null;
20497
+ return {
20498
+ id: "improve-verification-automation",
20499
+ priority: "recommended",
20500
+ owner: "agent",
20501
+ when: "harness-maintenance",
20502
+ title: `Improve ${recommended.length} verification declaration(s)`,
20503
+ reason: "These declarations have no executable check or complete manual procedure. They do not invalidate this run, but they weaken future coverage.",
20504
+ commands: ["harness-kit verify --repo . --details"],
20505
+ completion: "Each declaration has a real enforcement/check, or an explicit manual procedure when automation is genuinely impossible."
20506
+ };
20507
+ }
20508
+ function evidenceOnlyIssue(issue) {
20509
+ return /latest lifecycle evidence|start a new Agent session/.test(issue);
20510
+ }
20511
+ function unsafeHookIssue(issue) {
20512
+ return /not valid hook JSON|not a safe .*regular file|unknown hooks shape|must be an array|foreign|belongs to another worktree/.test(
20513
+ issue
20514
+ );
20515
+ }
20516
+ function hookActions(hooks) {
20517
+ if (hooks.state === "active") return [];
20518
+ const configured = hooks.configuredAgents.join(",");
20519
+ if (hooks.state === "configured" || hooks.configuredAgents.length > 0 && hooks.issues.every(evidenceOnlyIssue)) {
20520
+ return [{
20521
+ id: "prove-lifecycle-hooks",
20522
+ priority: "required",
20523
+ owner: "agent",
20524
+ when: "before-harness-ready",
20525
+ title: "Prove the lifecycle Hook in a fresh Agent session",
20526
+ reason: `A complete Hook is configured for ${configured || "the current Agent"}, but no current SessionStart + Stop evidence proves that the host executed it.`,
20527
+ commands: ["harness-kit evidence --repo . --json"],
20528
+ completion: "A newly created Agent session finishes once and evidence reports hookActive: true."
20529
+ }];
20530
+ }
20531
+ const unsafe = hooks.issues.filter(unsafeHookIssue);
20532
+ if (unsafe.length) {
20533
+ return [{
20534
+ id: "review-lifecycle-hook-conflict",
20535
+ priority: "required",
20536
+ owner: "human",
20537
+ when: "before-harness-ready",
20538
+ title: "Approve resolution of an existing Hook configuration conflict",
20539
+ reason: "Harness found a Hook file or registration it cannot safely replace: " + unsafe.join("; "),
20540
+ commands: [],
20541
+ completion: "The user approves one exact proposed change; the Agent then installs safely and proves hookActive: true in a fresh session."
20542
+ }];
20543
+ }
20544
+ const agents = configured || "<current-agent>";
20545
+ return [{
20546
+ id: hooks.configuredAgents.length ? "repair-lifecycle-hooks" : "install-lifecycle-hooks",
20547
+ priority: "required",
20548
+ owner: "agent",
20549
+ when: "before-harness-ready",
20550
+ title: hooks.configuredAgents.length ? "Repair the Agent lifecycle Hook" : "Install the Agent lifecycle Hook",
20551
+ reason: "Automatic SessionStart + Stop validation is not currently effective. The Agent should handle safe installation without asking the user to choose an implementation.",
20552
+ commands: [
20553
+ `harness-kit install-hooks --repo . --stop --agents ${agents}`,
20554
+ "harness-kit install-hooks --repo . --stop --agents codex --allow-user-dispatcher # linked Codex worktree only",
20555
+ "harness-kit evidence --repo . --json # after one fresh Agent session finishes"
20556
+ ],
20557
+ completion: "A fresh Agent session records both gates and evidence reports hookActive: true."
20558
+ }];
20559
+ }
20560
+ function evidenceActions(evidence) {
20561
+ if (!evidence.found) {
20562
+ return [{
20563
+ id: "record-delivery-evidence",
20564
+ priority: "required",
20565
+ owner: "agent",
20566
+ when: "before-finish",
20567
+ title: "Create delivery evidence for this change",
20568
+ reason: "No run-checks + verify evidence exists for the current worktree/session.",
20569
+ commands: [
20570
+ "harness-kit run-checks --repo . --base <task-start-sha>",
20571
+ "harness-kit verify --repo .",
20572
+ "harness-kit evidence --repo . --json"
20573
+ ],
20574
+ completion: "Evidence reports valid: true for the current code fingerprint."
20575
+ }];
20576
+ }
20577
+ if (evidence.stale) {
20578
+ return [{
20579
+ id: "refresh-stale-delivery-evidence",
20580
+ priority: "required",
20581
+ owner: "agent",
20582
+ when: "before-finish",
20583
+ title: "Re-run validation for the current code",
20584
+ reason: "The saved green result belongs to an older code fingerprint.",
20585
+ commands: [
20586
+ "harness-kit run-checks --repo . --base <task-start-sha>",
20587
+ "harness-kit verify --repo .",
20588
+ "harness-kit evidence --repo . --json"
20589
+ ],
20590
+ completion: "Evidence is no longer stale and reports valid: true."
20591
+ }];
20592
+ }
20593
+ if (!evidence.runChecksValid) {
20594
+ return [{
20595
+ id: "complete-run-checks",
20596
+ priority: "required",
20597
+ owner: "agent",
20598
+ when: "before-finish",
20599
+ title: "Complete the impact-driven checks",
20600
+ reason: "The selected checks did not produce valid evidence for the current code.",
20601
+ commands: ["harness-kit run-checks --repo . --base <task-start-sha>", "harness-kit evidence --repo . --json"],
20602
+ completion: "Evidence reports runChecksValid: true for the current code fingerprint."
20603
+ }];
20604
+ }
20605
+ if (!evidence.verifyPassed || !evidence.valid) {
20606
+ return [{
20607
+ id: "complete-verify",
20608
+ priority: "required",
20609
+ owner: "agent",
20610
+ when: "before-finish",
20611
+ title: "Complete repository verification",
20612
+ reason: "Change checks passed, but matching verify evidence is missing or failed.",
20613
+ commands: ["harness-kit verify --repo .", "harness-kit evidence --repo . --json"],
20614
+ completion: "Evidence reports valid: true for the current code fingerprint."
20615
+ }];
20616
+ }
20617
+ return [];
20618
+ }
20619
+ function buildHarnessGuidance(input) {
20620
+ const gapDetails = input.manifest ? declaredVerificationGaps(input.manifest) : [];
20621
+ const nextActions = [
20622
+ ...input.evidence ? evidenceActions(input.evidence) : [],
20623
+ ...input.hooks ? hookActions(input.hooks) : []
20624
+ ];
20625
+ const improvement = automationAction(gapDetails);
20626
+ if (improvement) nextActions.push(improvement);
20627
+ return {
20628
+ gapDetails,
20629
+ gapSummary: {
20630
+ total: gapDetails.length,
20631
+ recommended: gapDetails.filter((item) => item.classification === "recommended").length,
20632
+ informational: gapDetails.filter((item) => item.classification === "informational").length
20633
+ },
20634
+ nextActions
20635
+ };
20636
+ }
20637
+
20412
20638
  // src/hook-status.ts
20413
20639
  var import_node_fs10 = require("node:fs");
20414
20640
  var import_node_path10 = require("node:path");
@@ -21286,8 +21512,13 @@ ROOT="$(git rev-parse --show-toplevel 2>/dev/null)" || block_infrastructure_fail
21286
21512
  cd "$ROOT" || block_infrastructure_failure
21287
21513
  [ -f .agents/manifest.yaml ] || block_infrastructure_failure
21288
21514
 
21289
- HK="\${HARNESS_KIT_CMD:-npx -y @erzhe/harness-kit@${package_default.version}}"
21290
- output=$($HK hook-event --repo "$ROOT" --agent "$AGENT" --event "$EVENT")
21515
+ if [ -n "\${HARNESS_KIT_CMD:-}" ]; then
21516
+ output=$($HARNESS_KIT_CMD hook-event --repo "$ROOT" --agent "$AGENT" --event "$EVENT")
21517
+ else
21518
+ # Resolve the pinned package outside the target repository. npm otherwise
21519
+ # mistakes a same-named source checkout for the requested published package.
21520
+ output=$(cd "\${TMPDIR:-/tmp}" && npx -y @erzhe/harness-kit@${package_default.version} hook-event --repo "$ROOT" --agent "$AGENT" --event "$EVENT")
21521
+ fi
21291
21522
  code=$?
21292
21523
  [ "$code" -eq 0 ] || block_infrastructure_failure
21293
21524
  [ -n "$output" ] && printf '%s
@@ -22029,7 +22260,7 @@ function recordContextReview(repo, manifest, opts) {
22029
22260
  // src/commands/doctor.ts
22030
22261
  var AGENTS_MAX_LINES = 150;
22031
22262
  var AGENTS_MAX_WORDS = 700;
22032
- function doctorCmd(repo) {
22263
+ function doctorCmd(repo, opts = {}) {
22033
22264
  let problems = 0;
22034
22265
  const m = loadManifest(repo);
22035
22266
  info("1) Manifest validation");
@@ -22178,10 +22409,21 @@ function doctorCmd(repo) {
22178
22409
  }
22179
22410
  if (!freshness.length) ok("no knowledge drift");
22180
22411
  }
22181
- info("\n5) Tech debt (manual invariants)");
22182
- const manual = (m.invariants ?? []).filter((i) => i.manual);
22183
- if (!manual.length) ok("no manual invariants");
22184
- else warn(`${manual.length} manual (not machine-enforced): ${manual.map((i) => i.id).join(", ")}`);
22412
+ const declaredGuidance = buildHarnessGuidance({ manifest: m });
22413
+ info("\n5) Declared verification boundaries");
22414
+ if (!declaredGuidance.gapSummary.total) ok("no declared verification boundaries");
22415
+ else {
22416
+ info(
22417
+ `${declaredGuidance.gapSummary.total} declared: ${declaredGuidance.gapSummary.recommended} automation improvement(s), ${declaredGuidance.gapSummary.informational} check(s) only when relevant; these are not health failures`
22418
+ );
22419
+ if (opts.details) {
22420
+ for (const gap2 of declaredGuidance.gapDetails) {
22421
+ const text = `[${gap2.classification.toUpperCase()}] ${gap2.title} \u2014 ${gap2.when} ${gap2.reason}`;
22422
+ if (gap2.classification === "recommended") warn(text);
22423
+ else info(text);
22424
+ }
22425
+ } else info(" details: `harness-kit doctor --details`");
22426
+ }
22185
22427
  info("\n6) AGENTS.md size budget (must stay short \u2014 agents read it every session)");
22186
22428
  const agents = renderAgentsMd(m);
22187
22429
  const nLines = agents.split("\n").length;
@@ -22203,12 +22445,30 @@ function doctorCmd(repo) {
22203
22445
  } else {
22204
22446
  warn(`DEGRADED \u2014 configured: ${configuredAgents}; ${hooks.issues.join("; ")}`);
22205
22447
  }
22448
+ const guidance = buildHarnessGuidance({ manifest: m, hooks });
22449
+ const visibleActions = opts.details ? guidance.nextActions : guidance.nextActions.filter((action) => action.priority === "required");
22450
+ info("\nNEXT ACTIONS");
22451
+ if (!visibleActions.length) ok("nothing required now");
22452
+ for (const action of visibleActions) {
22453
+ warn(`[${action.priority.toUpperCase()} | ${action.owner.toUpperCase()}] ${action.title}`);
22454
+ info(` why: ${action.reason}`);
22455
+ info(` when: ${action.when}`);
22456
+ for (const command of action.commands) info(` run: ${command}`);
22457
+ info(` done when: ${action.completion}`);
22458
+ }
22459
+ const hiddenRecommended = guidance.nextActions.length - visibleActions.length;
22460
+ if (hiddenRecommended > 0)
22461
+ info(` ${hiddenRecommended} recommended maintenance action(s) hidden; use \`--details\` to view`);
22206
22462
  info("");
22463
+ const requiredActions = guidance.nextActions.filter((action) => action.priority === "required");
22207
22464
  if (problems) {
22208
22465
  info(`doctor: ${problems} problem(s) found`);
22466
+ if (requiredActions.length) warn(`Harness readiness: INCOMPLETE (${requiredActions.length} required action(s) above)`);
22209
22467
  return 1;
22210
22468
  }
22211
- info("doctor: healthy");
22469
+ info("doctor: repository configuration healthy");
22470
+ if (requiredActions.length) warn(`Harness readiness: INCOMPLETE (${requiredActions.length} required action(s) above)`);
22471
+ else ok("Harness readiness: READY");
22212
22472
  return 0;
22213
22473
  }
22214
22474
 
@@ -22312,6 +22572,9 @@ function verifyInternal(repo, opts) {
22312
22572
  context: [],
22313
22573
  hooks: hooks2,
22314
22574
  gaps: [],
22575
+ gapDetails: [],
22576
+ gapSummary: { total: 0, recommended: 0, informational: 0 },
22577
+ nextActions: [],
22315
22578
  messages: [{ level: "error", text: message }]
22316
22579
  };
22317
22580
  process.stdout.write(JSON.stringify(report) + "\n");
@@ -22319,11 +22582,12 @@ function verifyInternal(repo, opts) {
22319
22582
  return 1;
22320
22583
  }
22321
22584
  let failures = 0;
22322
- const gaps = [];
22323
22585
  const context = [];
22324
22586
  const messages = [];
22325
22587
  let manifestErrors = [];
22326
22588
  const hooks = safeInspectAgentHookStatus(repo);
22589
+ const guidance = buildHarnessGuidance({ manifest, hooks });
22590
+ const gaps = guidance.gapDetails.map((gap2) => gap2.legacyText);
22327
22591
  const emit = (level, text) => {
22328
22592
  messages.push({ level, text });
22329
22593
  if (opts.json) return;
@@ -22337,7 +22601,8 @@ function verifyInternal(repo, opts) {
22337
22601
  if (opts.recordManualEvidence !== false) {
22338
22602
  try {
22339
22603
  const marked = markManualVerifyResult(repo, code === 0);
22340
- if (marked === "stale") emit("warn", "manual run-checks evidence no longer matches this change; rerun run-checks before relying on evidence");
22604
+ if (marked === "stale" && hooks.state !== "active")
22605
+ emit("warn", "manual run-checks evidence no longer matches this change; rerun run-checks before relying on evidence");
22341
22606
  } catch (error) {
22342
22607
  emit("error", `cannot persist manual verify evidence: ${error.message}`);
22343
22608
  failures++;
@@ -22353,6 +22618,9 @@ function verifyInternal(repo, opts) {
22353
22618
  context,
22354
22619
  hooks,
22355
22620
  gaps,
22621
+ gapDetails: guidance.gapDetails,
22622
+ gapSummary: guidance.gapSummary,
22623
+ nextActions: guidance.nextActions,
22356
22624
  messages
22357
22625
  };
22358
22626
  process.stdout.write(JSON.stringify(report) + "\n");
@@ -22417,7 +22685,6 @@ verify: FAILED (${manifestErrors.length} manifest problem(s))`);
22417
22685
  for (const invariant of manifest.invariants ?? []) {
22418
22686
  if (!withinBudget(`before invariant ${invariant.id}`)) break;
22419
22687
  if (invariant.manual) {
22420
- gaps.push(`invariant ${invariant.id}: manual, not machine-enforced \u2014 ${invariant.rule}`);
22421
22688
  continue;
22422
22689
  }
22423
22690
  if (invariant.enforcement) {
@@ -22446,7 +22713,7 @@ verify: FAILED (${manifestErrors.length} manifest problem(s))`);
22446
22713
  `${invariant.id}: check ${result.timedOut ? "timed out / verification budget exhausted" : "failed"} (${invariant.check})`
22447
22714
  );
22448
22715
  }
22449
- } else gaps.push(`invariant ${invariant.id}: no enforcement/check declared \u2014 ${invariant.rule}`);
22716
+ }
22450
22717
  }
22451
22718
  const contracts = manifest.contracts ?? [];
22452
22719
  const autochecked = contracts.filter((contract) => contract.check || contract.snapshot);
@@ -22491,15 +22758,6 @@ verify: FAILED (${manifestErrors.length} manifest problem(s))`);
22491
22758
  if (!withinBudget(`while checking contract ${contract.id}`)) break;
22492
22759
  }
22493
22760
  }
22494
- for (const contract of contracts)
22495
- if (!contract.check && !contract.snapshot)
22496
- gaps.push(
22497
- `contract ${contract.id}: no automatic check` + (contract.manual_verify ? ` \u2014 verify by hand: ${contract.manual_verify}` : "")
22498
- );
22499
- for (const [verb, capability] of Object.entries(manifest.capabilities ?? {})) {
22500
- if (capability.mutating) gaps.push(`capability ${verb} (\`${capability.run}\`): mutating \u2014 not run here, verify deliberately`);
22501
- else if (capability.background) gaps.push(`capability ${verb} (\`${capability.run}\`): long-running \u2014 not run in this gate`);
22502
- }
22503
22761
  emit("info", "\n5) Agent lifecycle hooks");
22504
22762
  const configuredAgents = hooks.configuredAgents.length ? hooks.configuredAgents.join(", ") : "none";
22505
22763
  if (hooks.state === "active")
@@ -22507,15 +22765,45 @@ verify: FAILED (${manifestErrors.length} manifest problem(s))`);
22507
22765
  else if (hooks.state === "configured")
22508
22766
  emit("warn", `CONFIGURED \u2014 ${configuredAgents}; a fresh Agent session has not produced current Stop evidence yet`);
22509
22767
  else emit("warn", `DEGRADED \u2014 configured: ${configuredAgents}; ${hooks.issues.join("; ")}`);
22510
- emit("info", "\nGAPS \u2014 not verifiable here (report honestly, never fake)");
22511
- if (!gaps.length) emit("ok", "no declared gaps");
22512
- else for (const gap of gaps) emit("warn", gap);
22768
+ emit("info", "\n6) Declared verification boundaries");
22769
+ if (!guidance.gapSummary.total) emit("ok", "no declared verification boundaries");
22770
+ else {
22771
+ emit(
22772
+ "info",
22773
+ `${guidance.gapSummary.total} declared: ${guidance.gapSummary.recommended} automation improvement(s), ${guidance.gapSummary.informational} check(s) only when relevant; none changes this verify result`
22774
+ );
22775
+ if (opts.details) {
22776
+ for (const gap2 of guidance.gapDetails) {
22777
+ const text = `[${gap2.classification.toUpperCase()}] ${gap2.title} \u2014 ${gap2.when} ${gap2.reason}`;
22778
+ emit(gap2.classification === "recommended" ? "warn" : "info", text);
22779
+ }
22780
+ } else emit("info", " details: `harness-kit verify --details`");
22781
+ }
22782
+ const visibleActions = opts.details ? guidance.nextActions : guidance.nextActions.filter((action) => action.priority === "required");
22783
+ emit("info", "\nNEXT ACTIONS");
22784
+ if (!visibleActions.length) emit("ok", "nothing required now");
22785
+ for (const action of visibleActions) {
22786
+ emit("warn", `[${action.priority.toUpperCase()} | ${action.owner.toUpperCase()}] ${action.title}`);
22787
+ emit("info", ` why: ${action.reason}`);
22788
+ emit("info", ` when: ${action.when}`);
22789
+ for (const command of action.commands) emit("info", ` run: ${command}`);
22790
+ emit("info", ` done when: ${action.completion}`);
22791
+ }
22792
+ const hiddenRecommended = guidance.nextActions.length - visibleActions.length;
22793
+ if (hiddenRecommended > 0)
22794
+ emit("info", ` ${hiddenRecommended} recommended maintenance action(s) hidden; use \`--details\` to view`);
22513
22795
  emit("info", "");
22796
+ const requiredActions = guidance.nextActions.filter((action) => action.priority === "required");
22514
22797
  if (failures) {
22515
- emit("info", `verify: FAILED (${failures} problem(s), ${gaps.length} gap(s))`);
22798
+ emit("info", `verify: FAILED (${failures} problem(s))`);
22799
+ if (requiredActions.length)
22800
+ emit("warn", `Harness readiness: INCOMPLETE (${requiredActions.length} required action(s) above)`);
22516
22801
  return finish(1);
22517
22802
  }
22518
- emit("info", `verify: OK (${gaps.length} gap(s) \u2014 see above)`);
22803
+ emit("info", "verify: OK (all declared gates passed)");
22804
+ if (requiredActions.length)
22805
+ emit("warn", `Harness readiness: INCOMPLETE (${requiredActions.length} required action(s) above)`);
22806
+ else emit("ok", "Harness readiness: READY");
22519
22807
  return finish(0);
22520
22808
  }
22521
22809
  function verifyCmd(repo, opts = {}) {
@@ -22536,6 +22824,9 @@ function verifyCmd(repo, opts = {}) {
22536
22824
  context: [],
22537
22825
  hooks: safeInspectAgentHookStatus(repo),
22538
22826
  gaps: [],
22827
+ gapDetails: [],
22828
+ gapSummary: { total: 0, recommended: 0, informational: 0 },
22829
+ nextActions: [],
22539
22830
  messages: [{ level: "error", text: message }]
22540
22831
  };
22541
22832
  process.stdout.write(JSON.stringify(report) + "\n");
@@ -22627,6 +22918,31 @@ function checkLoopCmd() {
22627
22918
  }
22628
22919
 
22629
22920
  // src/commands/evidence.ts
22921
+ function safeHookStatus(repo) {
22922
+ try {
22923
+ return inspectAgentHookStatus(repo);
22924
+ } catch (error) {
22925
+ return {
22926
+ state: "degraded",
22927
+ configuredAgents: [],
22928
+ issues: [`cannot inspect Agent lifecycle hooks: ${error.message}`]
22929
+ };
22930
+ }
22931
+ }
22932
+ function printNextActions(actions) {
22933
+ info("\nNEXT ACTIONS");
22934
+ if (!actions.length) {
22935
+ ok("nothing required now");
22936
+ return;
22937
+ }
22938
+ for (const action of actions) {
22939
+ warn(`[${action.priority.toUpperCase()} | ${action.owner.toUpperCase()}] ${action.title}`);
22940
+ info(` why: ${action.reason}`);
22941
+ info(` when: ${action.when}`);
22942
+ for (const command of action.commands) info(` run: ${command}`);
22943
+ info(` done when: ${action.completion}`);
22944
+ }
22945
+ }
22630
22946
  function evidenceCmd(repo, opts = {}) {
22631
22947
  let session;
22632
22948
  try {
@@ -22635,9 +22951,22 @@ function evidenceCmd(repo, opts = {}) {
22635
22951
  err(`cannot read validation evidence: ${error.message}`);
22636
22952
  return 1;
22637
22953
  }
22954
+ const hooks = safeHookStatus(repo);
22638
22955
  if (!session?.lastEvidence) {
22639
- if (opts.json) process.stdout.write(JSON.stringify({ schema: "ai-harness/evidence/v1", found: false }, null, 2) + "\n");
22640
- else warn("no validation evidence recorded for this worktree/session");
22956
+ const guidance2 = buildHarnessGuidance({ hooks, evidence: { found: false } });
22957
+ if (opts.json) {
22958
+ process.stdout.write(
22959
+ JSON.stringify(
22960
+ { schema: "ai-harness/evidence/v1", found: false, hooks, nextActions: guidance2.nextActions },
22961
+ null,
22962
+ 2
22963
+ ) + "\n"
22964
+ );
22965
+ } else {
22966
+ warn("no validation evidence recorded for this worktree/session");
22967
+ printNextActions(guidance2.nextActions.filter((action) => action.priority === "required"));
22968
+ warn(`Harness readiness: INCOMPLETE (${guidance2.nextActions.filter((action) => action.priority === "required").length} required action(s) above)`);
22969
+ }
22641
22970
  return 1;
22642
22971
  }
22643
22972
  const body = {
@@ -22662,7 +22991,22 @@ function evidenceCmd(repo, opts = {}) {
22662
22991
  const valid = runChecksValid && evidence.verifyPassed === true;
22663
22992
  const hookConfigurationCurrent = session.agent !== "manual" && !!session.hookConfigFingerprint && agentHookConfigurationFingerprint(repo, session.agent) === session.hookConfigFingerprint;
22664
22993
  const hookActive = valid && hookConfigurationCurrent;
22665
- const result = { ...body, runChecksValid, valid, hookActive, hookConfigurationCurrent, stale, currentFingerprint, refreshError };
22994
+ const guidance = buildHarnessGuidance({
22995
+ hooks,
22996
+ evidence: { found: true, stale, runChecksValid, verifyPassed: evidence.verifyPassed, valid }
22997
+ });
22998
+ const result = {
22999
+ ...body,
23000
+ runChecksValid,
23001
+ valid,
23002
+ hookActive,
23003
+ hookConfigurationCurrent,
23004
+ stale,
23005
+ currentFingerprint,
23006
+ refreshError,
23007
+ hooks,
23008
+ nextActions: guidance.nextActions
23009
+ };
22666
23010
  if (opts.json) {
22667
23011
  process.stdout.write(JSON.stringify(result, null, 2) + "\n");
22668
23012
  return valid ? 0 : 1;
@@ -22689,6 +23033,10 @@ function evidenceCmd(repo, opts = {}) {
22689
23033
  info("errors:");
22690
23034
  for (const message of evidence.errors) err(message);
22691
23035
  }
23036
+ const requiredActions = guidance.nextActions.filter((action) => action.priority === "required");
23037
+ printNextActions(requiredActions);
23038
+ if (requiredActions.length) warn(`Harness readiness: INCOMPLETE (${requiredActions.length} required action(s) above)`);
23039
+ else ok("Harness readiness: READY");
22692
23040
  return valid ? 0 : 1;
22693
23041
  }
22694
23042
 
@@ -22837,7 +23185,7 @@ function planChecks(m, input, opts = {}) {
22837
23185
  severity: "advisory"
22838
23186
  });
22839
23187
  }
22840
- if (changed.length > 0 && checks.length === 0 && !gaps.some((gap) => gap.kind === "unknown-profile")) {
23188
+ if (changed.length > 0 && checks.length === 0 && !gaps.some((gap2) => gap2.kind === "unknown-profile")) {
22841
23189
  gaps.push({
22842
23190
  kind: "no-checks-selected",
22843
23191
  where: "validation",
@@ -22863,8 +23211,8 @@ var WAIVABLE_GAP_KINDS = /* @__PURE__ */ new Set([
22863
23211
  "module-without-tests",
22864
23212
  "unmapped-required-file"
22865
23213
  ]);
22866
- function isWaivableGap(gap) {
22867
- return gap.severity === "blocking" && WAIVABLE_GAP_KINDS.has(gap.kind);
23214
+ function isWaivableGap(gap2) {
23215
+ return gap2.severity === "blocking" && WAIVABLE_GAP_KINDS.has(gap2.kind);
22868
23216
  }
22869
23217
  function runOne(repo, cmd, timeoutMs) {
22870
23218
  const started = Date.now();
@@ -22914,37 +23262,37 @@ function reportHuman(report) {
22914
23262
  for (const line of failure.logTail.split("\n")) if (line) info(` ${line}`);
22915
23263
  }
22916
23264
  for (const message of report.errors) err(message);
22917
- const blocking = report.gaps.filter((gap) => gap.severity === "blocking");
22918
- const advisory = report.gaps.filter((gap) => gap.severity === "advisory");
23265
+ const blocking = report.gaps.filter((gap2) => gap2.severity === "blocking");
23266
+ const advisory = report.gaps.filter((gap2) => gap2.severity === "advisory");
22919
23267
  if (blocking.length) info("\nblocking gaps:");
22920
- for (const gap of blocking) {
22921
- err(`[${gap.kind}] ${gap.where ? `${gap.where} \u2014 ` : ""}${gap.why}`);
22922
- info(` -> ${gap.suggestion}`);
23268
+ for (const gap2 of blocking) {
23269
+ err(`[${gap2.kind}] ${gap2.where ? `${gap2.where} \u2014 ` : ""}${gap2.why}`);
23270
+ info(` -> ${gap2.suggestion}`);
22923
23271
  }
22924
23272
  if (advisory.length) info("\nadvisory gaps:");
22925
- for (const gap of advisory) warn(`[${gap.kind}] ${gap.where ? `${gap.where} \u2014 ` : ""}${gap.why}`);
23273
+ for (const gap2 of advisory) warn(`[${gap2.kind}] ${gap2.where ? `${gap2.where} \u2014 ` : ""}${gap2.why}`);
22926
23274
  for (const waiver of report.waivers) warn(`waived ${waiver.kind}:${waiver.where} \u2014 ${waiver.reason}`);
22927
23275
  for (const note of report.notes) info(` NOTE ${note.message}`);
22928
23276
  info("");
22929
23277
  if (!report.ok) info(`run-checks: NOT VERIFIED (${report.status})`);
22930
23278
  else info(`run-checks: ${report.status.toUpperCase()} (${report.passed.length} passed, ${report.gaps.length} gap(s))`);
22931
23279
  }
22932
- function matchingWaiver(waiver, fingerprint2, gap) {
22933
- return isWaivableGap(gap) && waiver.fingerprint === fingerprint2 && waiver.kind === gap.kind && waiver.where === gap.where;
23280
+ function matchingWaiver(waiver, fingerprint2, gap2) {
23281
+ return isWaivableGap(gap2) && waiver.fingerprint === fingerprint2 && waiver.kind === gap2.kind && waiver.where === gap2.where;
22934
23282
  }
22935
23283
  function buildReport(args) {
22936
23284
  const { changes, plan, passed, failed, skipped, checks, waivers, errors, session } = args;
22937
23285
  const unwaivedBlocking = plan.gaps.filter(
22938
- (gap) => gap.severity === "blocking" && !waivers.some((waiver) => matchingWaiver(waiver, changes.fingerprint, gap))
23286
+ (gap2) => gap2.severity === "blocking" && !waivers.some((waiver) => matchingWaiver(waiver, changes.fingerprint, gap2))
22939
23287
  );
22940
23288
  const activeWaivers = waivers.filter(
22941
- (waiver) => plan.gaps.some((gap) => gap.severity === "blocking" && matchingWaiver(waiver, changes.fingerprint, gap))
23289
+ (waiver) => plan.gaps.some((gap2) => gap2.severity === "blocking" && matchingWaiver(waiver, changes.fingerprint, gap2))
22942
23290
  );
22943
23291
  let status;
22944
23292
  if (errors.length || failed.length || skipped.length || unwaivedBlocking.length) status = "not-verified";
22945
23293
  else if (changes.files.length === 0) status = "no-change";
22946
23294
  else if (activeWaivers.length) status = "verified-with-waivers";
22947
- else if (plan.gaps.some((gap) => gap.severity === "advisory")) status = "verified-with-advisories";
23295
+ else if (plan.gaps.some((gap2) => gap2.severity === "advisory")) status = "verified-with-advisories";
22948
23296
  else status = "verified";
22949
23297
  return {
22950
23298
  schema: "ai-harness/run-checks/v1",
@@ -23044,7 +23392,7 @@ function runChecksCmd(repo, opts) {
23044
23392
  if (opts.waive) {
23045
23393
  if (!opts.reason?.trim()) errors.push("waiver reason is required and cannot be empty");
23046
23394
  if (!opts.where?.trim()) errors.push("waiver scope is required; pass --where <scope>");
23047
- const matchingGaps = opts.where?.trim() ? plan.gaps.filter((gap) => gap.severity === "blocking" && gap.kind === opts.waive && gap.where === opts.where.trim()) : [];
23395
+ const matchingGaps = opts.where?.trim() ? plan.gaps.filter((gap2) => gap2.severity === "blocking" && gap2.kind === opts.waive && gap2.where === opts.where.trim()) : [];
23048
23396
  const candidates = matchingGaps.filter(isWaivableGap);
23049
23397
  if (opts.where?.trim() && matchingGaps.length > 0 && candidates.length === 0)
23050
23398
  errors.push(
@@ -23053,11 +23401,11 @@ function runChecksCmd(repo, opts) {
23053
23401
  else if (opts.where?.trim() && candidates.length === 0)
23054
23402
  errors.push(`no waivable blocking gap matches ${opts.waive}:${opts.where.trim()}`);
23055
23403
  if (session && opts.reason?.trim() && candidates.length === 1) {
23056
- const gap = candidates[0];
23404
+ const gap2 = candidates[0];
23057
23405
  session = recordWaiver(repo, session, {
23058
23406
  fingerprint: changes.fingerprint,
23059
- kind: gap.kind,
23060
- where: gap.where,
23407
+ kind: gap2.kind,
23408
+ where: gap2.where,
23061
23409
  reason: opts.reason.trim(),
23062
23410
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
23063
23411
  });
@@ -23202,8 +23550,8 @@ function failureMessage(report, verifyOutput, token) {
23202
23550
  for (const message of report.errors.slice(0, 5)) lines.push(`- ${message}`);
23203
23551
  for (const failure of report.failed.slice(0, 5)) lines.push(`- check ${failure.id} failed (exit ${failure.code})`);
23204
23552
  for (const skipped of report.skipped.slice(0, 5)) lines.push(`- check ${skipped.id} was not run: ${skipped.reason}`);
23205
- for (const gap of report.gaps.filter((item) => item.severity === "blocking").slice(0, 5))
23206
- lines.push(`- [${gap.kind}] ${gap.where ? `${gap.where}: ` : ""}${gap.why}`);
23553
+ for (const gap2 of report.gaps.filter((item) => item.severity === "blocking").slice(0, 5))
23554
+ lines.push(`- [${gap2.kind}] ${gap2.where ? `${gap2.where}: ` : ""}${gap2.why}`);
23207
23555
  }
23208
23556
  if (verifyOutput.trim()) {
23209
23557
  const outputLines = verifyOutput.trim().split("\n");
@@ -23650,8 +23998,8 @@ program2.command("record-adoption-audit").description("record a declared pass/fa
23650
23998
  })
23651
23999
  )
23652
24000
  );
23653
- program2.command("doctor").description("dev-time health check: completeness, drift, freshness, tech debt").option("-C, --repo <dir>", "target repo dir (default: current directory)").action((o) => guard(() => doctorCmd(repoOf(o))));
23654
- program2.command("verify").description("CI gate: run enforceable invariants + contracts + drift; nonzero on failure").option("-C, --repo <dir>", "target repo dir (default: current directory)").option("--json", "machine-readable output", false).action((o) => guard(() => verifyCmd(repoOf(o), { json: o.json })));
24001
+ program2.command("doctor").description("dev-time health check: completeness, drift, freshness, tech debt").option("-C, --repo <dir>", "target repo dir (default: current directory)").option("--details", "show every declared verification boundary and maintenance action", false).action((o) => guard(() => doctorCmd(repoOf(o), { details: o.details })));
24002
+ program2.command("verify").description("CI gate: run enforceable invariants + contracts + drift; nonzero on failure").option("-C, --repo <dir>", "target repo dir (default: current directory)").option("--json", "machine-readable output", false).option("--details", "show every declared verification boundary and maintenance action", false).action((o) => guard(() => verifyCmd(repoOf(o), { json: o.json, details: o.details })));
23655
24003
  program2.command("plan-checks").description("compute which declared checks THIS change should run (impact-driven, executes nothing)").option("-C, --repo <dir>", "target repo dir (default: current directory)").option("--base <ref>", "diff base (default: working tree + untracked vs HEAD)", "HEAD").option("--profile <checkset>", "use a validation.checksets entry instead of per-module checks").option("--json", "machine-readable output", false).action((o) => guard(() => planChecksCmd(repoOf(o), { base: o.base, json: o.json, profile: o.profile })));
23656
24004
  program2.command("run-checks").description("plan + run resolved checks; record evidence; nonzero on failure/unresolved blocking gap").option("-C, --repo <dir>", "target repo dir (default: current directory)").option("--base <ref>", "task-start ref; required for manual proof after task changes were committed").option("--profile <checkset>", "use a validation.checksets entry instead of per-module checks").option("--waive <kind>", "waive one eligible coverage gap for this exact change fingerprint").option("--where <scope>", "exact gap scope; required when a kind matches multiple gaps").option("--reason <text>", "reason recorded with --waive").option("--session <token>", "validation session token (normally supplied by an agent hook)").option("--json", "machine-readable output", false).action(
23657
24005
  (o) => guard(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@erzhe/harness-kit",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
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": [
@@ -100,7 +100,9 @@ harness-kit verify
100
100
 
101
101
  - 路径不存在就修 manifest;impact glob 零命中就回到真实文件清单修正,不能扩大假 glob。
102
102
  - 契约提示 baseline 未设置时,先确认当前接口符合 policy,再运行 `harness-kit accept-contract --repo .`;拿不准是否 breaking 就升级给用户,绝不静默 accept。
103
- - 迭代到 `doctor` healthy、`verify` 退出码 0,且 GAPS 只剩确实无法自动执行的覆盖。
103
+ - 读取 `NEXT ACTIONS`(JSON 为 `nextActions`):`required | agent` 由你立即完成;`required | human` 只向用户请求那一个明确授权或语义决定,不能把技术选型抛给用户。
104
+ - 首次接入本身就是 Harness 维护任务,所以 `recommended` 的自动化改进也要逐项判断并尽量完成;确实无法自动执行的条目改成有明确时机和步骤的人工验证边界,不能只留下“GAP”。
105
+ - 迭代到 `doctor` repository configuration healthy、`verify` 退出码 0、所有 `required` action 清零。`informational` 只表示按需验证边界,不是待修问题。
104
106
 
105
107
  ## 6. 自动安装有效的会话门禁并验证
106
108
 
@@ -122,6 +124,8 @@ Codex 首次信任用户分发器时,agent 先用一句人话说明:“它
122
124
 
123
125
  随后启动一个**全新的 Agent 会话**,完成一次安全的验证闭环,再运行 `harness-kit evidence --repo . --json`。宿主支持创建会话/Agent(例如 Orca)时由当前 agent 自动创建和检查;不支持时才请用户重开一次会话。只有 evidence 明确记录该新会话的 SessionStart 基线、Stop 阶段 `run-checks + verify` 结果并且 `hookActive: true`,才能宣称 hooks 已生效。客户端未执行 hooks 时要报 GAP,并用任务开始 SHA 手动跑 `run-checks --base <sha>`,不能把默认 `no-change` 当证据。
124
126
 
127
+ 若 `doctor` / `verify` 输出 `install-lifecycle-hooks`、`repair-lifecycle-hooks` 或 `prove-lifecycle-hooks`,这不是给用户看的建议,而是你在宣布接入完成前必须自动收敛的动作。只有安装器发现未知第三方结构,或宿主 UI 必须批准精确的 managed dispatcher 时,才暂停并请用户确认。
128
+
125
129
  原生 Git hooks(pre-commit / pre-push)是**可选且仅限确认安全时**的增强:不得覆盖既有 hooks,不得改变未知的团队工作流,也不能作为首次接入完成条件。**绝不要指示用户修改 CI。**
126
130
 
127
131
  ## 7. 日常维护 / 自愈
@@ -133,11 +137,12 @@ Codex 首次信任用户分发器时,agent 先用一句人话说明:“它
133
137
  3. 契约 drift → 只有需求和代码证据都表明有意变更才 accept,并写进审查清单;否则升级。
134
138
  4. invariant 违规 → 修代码;确认 policy 已变更后才能改规则。
135
139
  5. 重跑 `record-context-review`(仅在分析完成后)、`run-checks` 和 `verify` 到绿,列出改了什么、证据、accept 的契约及未动项。
140
+ 6. 最终汇报按“验证是否通过 / Agent 已自动完成 / 用户仍需做什么 / 仅在什么场景才需验证”分组;不要把总 GAP 数量单独抛给用户判断。
136
141
 
137
142
  ## 反模式
138
143
 
139
144
  - 手写生成的 `AGENTS.md` / `CLAUDE.md` / `routing.md` / `modules.md`。
140
145
  - 用 `sync` 或 `record-context-review` 冒充仓库分析。
141
146
  - 移动/复制业务文档,或按目录名漏掉显式引用文档。
142
- - 为了消灭 GAPS 发明 capability、glob 或检查。
147
+ - 为了消灭验证边界发明 capability、glob 或检查。
143
148
  - 跳过 legacy 快照、逐规则 ledger 或独立盲审。
@@ -49,6 +49,10 @@ harness-kit 只提供确定性弹药,不替你判断功能对不对:
49
49
  - 真属于本次**非目标**的覆盖类 blocking gap(`missing-test-touch` / `module-without-tests` / `unmapped-required-file`),才用 `run-checks --waive <kind> --where <输出中的 scope> --reason <为什么>` 豁免。检查未跑、配置/Git 失败等不能豁免;豁免只绑定当前代码指纹,改代码后必须重新判断。
50
50
  修完回第 3 步,直到 `run-checks` 退出码 0。
51
51
  5. **交付**:用 `harness-kit evidence --repo .` 复核最终证据;手动流程里只有 `runChecksValid:true` 仍不完整,必须看到匹配的 `verifyPassed:true` 与整体 `valid:true`。若显示 `stale`,说明留证后代码又变了,回到第 3 步。只有两道门禁都绿了才算完;把改了什么、补了哪些用例、豁免了什么及原因写进交付说明。
52
+ - 同时读取 `verify` / `evidence` 的 `NEXT ACTIONS`(JSON 为 `nextActions`)。所有 `required | agent` 由你自动完成后再交付;`required | human` 只请求一个明确授权,不能让用户自己解释 Hook 或选择安装方式。
53
+ - 若要求安装、修复或证明 lifecycle Hook:识别当前真实客户端和 linked-worktree 形态,安全安装后创建一个新会话,并以 `hookActive:true` 收口。宿主不能创建新会话时,才请用户重开一次。
54
+ - `recommended` 只在 onboarding / Harness 维护任务处理,不要在无关业务改动里扩大范围;`informational` 是按需验证边界,只有本任务确实涉及发布、真实网络、上传或后台运行时才写进交付说明。
55
+ - 最终汇报明确写“验证是否通过、Agent 已处理什么、用户还需做什么”;不要只报一个 GAP 总数让用户判断。
52
56
 
53
57
  ## 拔高正确率的三根杠杆(闭环保证的是一致性,不是"意图全对"——用这些逼近意图)
54
58