@dommaker/harness 1.14.0 → 1.15.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.
Files changed (281) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +4 -2
  3. package/dist/cli/commands/constraints-disable.d.ts +48 -0
  4. package/dist/cli/commands/constraints-disable.d.ts.map +1 -0
  5. package/dist/cli/commands/constraints-disable.js +156 -0
  6. package/dist/cli/commands/constraints-disable.js.map +1 -0
  7. package/dist/cli/commands/constraints-pack-proposal.d.ts +1 -1
  8. package/dist/cli/commands/constraints-pack-proposal.js +1 -1
  9. package/dist/cli/commands/constraints-reactivate.d.ts.map +1 -1
  10. package/dist/cli/commands/constraints-reactivate.js +4 -2
  11. package/dist/cli/commands/constraints-reactivate.js.map +1 -1
  12. package/dist/cli/commands/constraints-retire.d.ts +14 -4
  13. package/dist/cli/commands/constraints-retire.d.ts.map +1 -1
  14. package/dist/cli/commands/constraints-retire.js +10 -6
  15. package/dist/cli/commands/constraints-retire.js.map +1 -1
  16. package/dist/cli/commands/constraints.d.ts +1 -1
  17. package/dist/cli/commands/constraints.js +1 -1
  18. package/dist/cli/commands/definitions.d.ts.map +1 -1
  19. package/dist/cli/commands/definitions.js +16 -1
  20. package/dist/cli/commands/definitions.js.map +1 -1
  21. package/dist/cli/commands/knowledge-view.d.ts +3 -3
  22. package/dist/cli/commands/knowledge-view.js +4 -4
  23. package/dist/cli/commands/knowledge-view.js.map +1 -1
  24. package/dist/cli/commands/release.d.ts +2 -2
  25. package/dist/cli/commands/release.js +2 -2
  26. package/dist/cli/commands/sync-docs/agents-syncer.js +2 -4
  27. package/dist/cli/commands/sync-docs/agents-syncer.js.map +1 -1
  28. package/dist/cli/commands/sync-docs/head-gate.d.ts +34 -0
  29. package/dist/cli/commands/sync-docs/head-gate.d.ts.map +1 -0
  30. package/dist/cli/commands/sync-docs/head-gate.js +86 -0
  31. package/dist/cli/commands/sync-docs/head-gate.js.map +1 -0
  32. package/dist/cli/commands/sync-docs/index.d.ts +7 -0
  33. package/dist/cli/commands/sync-docs/index.d.ts.map +1 -1
  34. package/dist/cli/commands/sync-docs/index.js +51 -1
  35. package/dist/cli/commands/sync-docs/index.js.map +1 -1
  36. package/dist/completion-checkers/contract-presence.d.ts +1 -1
  37. package/dist/completion-checkers/contract-presence.js +1 -1
  38. package/dist/core/constraints/capabilities-parser.js +1 -1
  39. package/dist/core/constraints/check-cache.d.ts +1 -1
  40. package/dist/core/constraints/check-cache.js +1 -1
  41. package/dist/core/constraints/checkers/capability-sync.d.ts +1 -1
  42. package/dist/core/constraints/checkers/capability-sync.js +1 -1
  43. package/dist/core/constraints/checkers/docs-freshness.js +1 -1
  44. package/dist/core/constraints/checkers/docs-freshness.js.map +1 -1
  45. package/dist/core/constraints/checkers/governance-presence.d.ts +1 -1
  46. package/dist/core/constraints/checkers/governance-presence.js +1 -1
  47. package/dist/core/constraints/checkers/index.d.ts.map +1 -1
  48. package/dist/core/constraints/checkers/index.js +2 -2
  49. package/dist/core/constraints/checkers/index.js.map +1 -1
  50. package/dist/core/constraints/checkers/no-completion-without-verification.d.ts +34 -0
  51. package/dist/core/constraints/checkers/no-completion-without-verification.d.ts.map +1 -0
  52. package/dist/core/constraints/checkers/no-completion-without-verification.js +157 -0
  53. package/dist/core/constraints/checkers/no-completion-without-verification.js.map +1 -0
  54. package/dist/core/constraints/checkers/no-hardcoded-credentials.d.ts +3 -0
  55. package/dist/core/constraints/checkers/no-hardcoded-credentials.d.ts.map +1 -1
  56. package/dist/core/constraints/checkers/no-hardcoded-credentials.js +19 -2
  57. package/dist/core/constraints/checkers/no-hardcoded-credentials.js.map +1 -1
  58. package/dist/core/constraints/checkers/types.d.ts +1 -1
  59. package/dist/core/constraints/checkers/types.js +1 -1
  60. package/dist/core/constraints/context-builder.d.ts.map +1 -1
  61. package/dist/core/constraints/context-builder.js +0 -17
  62. package/dist/core/constraints/context-builder.js.map +1 -1
  63. package/dist/core/constraints/definitions/guidelines.js +1 -1
  64. package/dist/core/constraints/definitions/iron-laws.js +2 -2
  65. package/dist/core/constraints/definitions/iron-laws.js.map +1 -1
  66. package/dist/core/constraints/definitions.d.ts +1 -1
  67. package/dist/core/constraints/definitions.js +1 -1
  68. package/dist/core/constraints/index.d.ts +1 -1
  69. package/dist/core/constraints/index.d.ts.map +1 -1
  70. package/dist/core/constraints/index.js.map +1 -1
  71. package/dist/core/constraints/run-env.d.ts +3 -2
  72. package/dist/core/constraints/run-env.d.ts.map +1 -1
  73. package/dist/core/constraints/run-env.js +5 -4
  74. package/dist/core/constraints/run-env.js.map +1 -1
  75. package/dist/core/constraints/usage-report.d.ts +0 -5
  76. package/dist/core/constraints/usage-report.d.ts.map +1 -1
  77. package/dist/core/constraints/usage-report.js +3 -12
  78. package/dist/core/constraints/usage-report.js.map +1 -1
  79. package/dist/core/effective-constraints.d.ts +1 -1
  80. package/dist/core/effective-constraints.js +1 -1
  81. package/dist/core/index.d.ts +1 -1
  82. package/dist/core/index.d.ts.map +1 -1
  83. package/dist/core/index.js.map +1 -1
  84. package/dist/core/retired-constraints.d.ts +66 -0
  85. package/dist/core/retired-constraints.d.ts.map +1 -0
  86. package/dist/core/retired-constraints.js +52 -0
  87. package/dist/core/retired-constraints.js.map +1 -0
  88. package/dist/core/validators/checkpoint.d.ts +4 -2
  89. package/dist/core/validators/checkpoint.d.ts.map +1 -1
  90. package/dist/core/validators/checkpoint.js +4 -2
  91. package/dist/core/validators/checkpoint.js.map +1 -1
  92. package/dist/core/validators/passes-gate.d.ts +2 -2
  93. package/dist/core/validators/passes-gate.d.ts.map +1 -1
  94. package/dist/core/validators/passes-gate.js +4 -3
  95. package/dist/core/validators/passes-gate.js.map +1 -1
  96. package/dist/gates/checker-gate.d.ts +3 -3
  97. package/dist/gates/checker-gate.js +3 -3
  98. package/dist/gates/index.d.ts +1 -1
  99. package/dist/gates/index.js +1 -1
  100. package/dist/index.d.ts +3 -1
  101. package/dist/index.d.ts.map +1 -1
  102. package/dist/index.js +7 -5
  103. package/dist/index.js.map +1 -1
  104. package/dist/knowledge/audit-scoring.js +1 -1
  105. package/dist/knowledge/audit-scoring.js.map +1 -1
  106. package/dist/monitoring/trace-analyzer.d.ts +2 -2
  107. package/dist/monitoring/trace-analyzer.js +2 -2
  108. package/dist/monitoring/traces.d.ts +1 -1
  109. package/dist/monitoring/traces.js +4 -4
  110. package/dist/monitoring/traces.js.map +1 -1
  111. package/dist/pretool-use-hook.d.ts +1 -1
  112. package/dist/pretool-use-hook.d.ts.map +1 -1
  113. package/dist/pretool-use-hook.js +5 -5
  114. package/dist/pretool-use-hook.js.map +1 -1
  115. package/dist/release/integrity.d.ts +4 -4
  116. package/dist/release/integrity.js +4 -4
  117. package/dist/test-setup/mkdtemp-cleanup.js +1 -1
  118. package/dist/tools/definitions/core/notification/notify.yml +0 -1
  119. package/dist/tools/definitions/ext/browser/browser-close.yml +0 -1
  120. package/dist/tools/definitions/ext/browser/browser-start.yml +0 -1
  121. package/dist/tools/definitions/std/evolution/implement.yml +0 -1
  122. package/dist/tools/definitions/std/evolution/prioritize.yml +0 -1
  123. package/dist/tools/definitions/std/evolution/report-gap.yml +0 -1
  124. package/dist/tools/definitions/std/governance/aggregate-opinions.yml +0 -1
  125. package/dist/tools/definitions/std/governance/audit-task.yml +0 -1
  126. package/dist/tools/definitions/std/governance/cast-vote.yml +0 -1
  127. package/dist/tools/definitions/std/governance/create-voting-session.yml +0 -1
  128. package/dist/tools/definitions/std/governance/define-stance.yml +0 -1
  129. package/dist/tools/definitions/std/governance/impeach.yml +0 -1
  130. package/dist/tools/definitions/std/governance/multi-stance-review.yml +0 -1
  131. package/dist/tools/definitions/std/governance/rollback.yml +0 -1
  132. package/dist/tools/definitions/std/governance/stance-review.yml +0 -1
  133. package/dist/tools/definitions/std/governance/track-effect.yml +0 -1
  134. package/dist/tools/definitions/std/governance/vote-tally.yml +0 -1
  135. package/dist/tools/definitions/std/planning/split-batch.yml +0 -1
  136. package/dist/tools/definitions/std/planning/split-tasks.yml +0 -1
  137. package/dist/types/constraint.d.ts +1 -7
  138. package/dist/types/constraint.d.ts.map +1 -1
  139. package/dist/types/constraint.js.map +1 -1
  140. package/dist/types/passes-gate.d.ts +7 -0
  141. package/dist/types/passes-gate.d.ts.map +1 -1
  142. package/dist/types/passes-gate.js +8 -0
  143. package/dist/types/passes-gate.js.map +1 -1
  144. package/dist/utils/detect-source-roots.d.ts +1 -1
  145. package/dist/utils/detect-source-roots.d.ts.map +1 -1
  146. package/dist/utils/detect-source-roots.js +2 -21
  147. package/dist/utils/detect-source-roots.js.map +1 -1
  148. package/package.json +1 -2
  149. package/src/CONTEXT.md +2 -2
  150. package/src/__tests__/checker-extra.test.ts +32 -9
  151. package/src/__tests__/checker-primitives-sdk.test.ts +2 -2
  152. package/src/__tests__/checker.test.ts +16 -14
  153. package/src/__tests__/detect-source-roots.test.ts +5 -4
  154. package/src/__tests__/exec-checker-full-chain.test.ts +3 -3
  155. package/src/__tests__/iron-laws.test.ts +13 -20
  156. package/src/__tests__/no-studio-references.test.ts +54 -0
  157. package/src/__tests__/passes-gate-check.test.ts +1 -1
  158. package/src/__tests__/pretool-use-hook.test.ts +2 -2
  159. package/src/__tests__/public-exports.test.ts +1 -0
  160. package/src/__tests__/public-type-surface.test.ts +2 -2
  161. package/src/__tests__/retired-constraints.test.ts +99 -0
  162. package/src/__tests__/skip-semantics.test.ts +16 -33
  163. package/src/__tests__/usage-report-public-export.test.ts +3 -3
  164. package/src/cli/commands/CONTEXT.md +7 -6
  165. package/src/cli/commands/__tests__/check-read-count.test.ts +3 -0
  166. package/src/cli/commands/__tests__/check.test.ts +33 -6
  167. package/src/cli/commands/__tests__/constraints-disable.test.ts +229 -0
  168. package/src/cli/commands/__tests__/constraints-report-json-flag.test.ts +1 -1
  169. package/src/cli/commands/__tests__/constraints-report.test.ts +4 -4
  170. package/src/cli/commands/__tests__/knowledge-flywheel-consistency.test.ts +1 -1
  171. package/src/cli/commands/__tests__/knowledge.test.ts +3 -3
  172. package/src/cli/commands/__tests__/project-path-anchoring.test.ts +4 -1
  173. package/src/cli/commands/__tests__/project-path-convention.test.ts +1 -1
  174. package/src/cli/commands/__tests__/spec-baseline-index-cap.test.ts +1 -1
  175. package/src/cli/commands/__tests__/sync-docs-agents.test.ts +1 -24
  176. package/src/cli/commands/__tests__/sync-docs-gate.test.ts +154 -0
  177. package/src/cli/commands/__tests__/sync-docs-table-layout.test.ts +1 -1
  178. package/src/cli/commands/__tests__/sync-docs.test.ts +3 -3
  179. package/src/cli/commands/constraints-disable.ts +145 -0
  180. package/src/cli/commands/constraints-pack-proposal.ts +1 -1
  181. package/src/cli/commands/constraints-reactivate.ts +4 -2
  182. package/src/cli/commands/constraints-retire.ts +11 -8
  183. package/src/cli/commands/constraints.ts +1 -1
  184. package/src/cli/commands/definitions.ts +16 -1
  185. package/src/cli/commands/knowledge-view.ts +4 -4
  186. package/src/cli/commands/release.ts +2 -2
  187. package/src/cli/commands/sync-docs/agents-syncer.ts +2 -4
  188. package/src/cli/commands/sync-docs/head-gate.ts +87 -0
  189. package/src/cli/commands/sync-docs/index.ts +62 -1
  190. package/src/completion-checkers/contract-presence.ts +1 -1
  191. package/src/core/CONTEXT.md +4 -3
  192. package/src/core/constraints/__tests__/capabilities-reconcile.test.ts +1 -1
  193. package/src/core/constraints/__tests__/check-cache.test.ts +1 -1
  194. package/src/core/constraints/__tests__/collect-constraints.test.ts +42 -18
  195. package/src/core/constraints/__tests__/run-env.test.ts +7 -7
  196. package/src/core/constraints/__tests__/trace-injection.test.ts +8 -2
  197. package/src/core/constraints/capabilities-parser.ts +1 -1
  198. package/src/core/constraints/check-cache.ts +1 -1
  199. package/src/core/constraints/checkers/__tests__/fixtures/public-repo-sanitization.mjs +1 -1
  200. package/src/core/constraints/checkers/__tests__/governance-presence.test.ts +1 -1
  201. package/src/core/constraints/checkers/__tests__/input-contract.test.ts +3 -3
  202. package/src/core/constraints/checkers/__tests__/no-completion-without-verification.test.ts +208 -0
  203. package/src/core/constraints/checkers/__tests__/no-hardcoded-credentials.test.ts +17 -0
  204. package/src/core/constraints/checkers/capability-sync.ts +1 -1
  205. package/src/core/constraints/checkers/docs-freshness.ts +1 -1
  206. package/src/core/constraints/checkers/governance-presence.ts +1 -1
  207. package/src/core/constraints/checkers/index.ts +1 -3
  208. package/src/core/constraints/checkers/no-completion-without-verification.ts +126 -0
  209. package/src/core/constraints/checkers/no-hardcoded-credentials.ts +20 -2
  210. package/src/core/constraints/checkers/types.ts +1 -1
  211. package/src/core/constraints/context-builder.ts +0 -18
  212. package/src/core/constraints/definitions/guidelines.ts +1 -1
  213. package/src/core/constraints/definitions/iron-laws.ts +2 -2
  214. package/src/core/constraints/definitions.ts +1 -1
  215. package/src/core/constraints/doc-freshness/__tests__/runner.test.ts +3 -3
  216. package/src/core/constraints/index.ts +0 -1
  217. package/src/core/constraints/run-env.ts +6 -5
  218. package/src/core/constraints/usage-report.ts +2 -12
  219. package/src/core/effective-constraints.ts +1 -1
  220. package/src/core/index.ts +0 -1
  221. package/src/core/retired-constraints.ts +77 -0
  222. package/src/core/validators/checkpoint.ts +4 -2
  223. package/src/core/validators/passes-gate.ts +4 -3
  224. package/src/gates/CONTEXT.md +3 -2
  225. package/src/gates/__tests__/checker-gate.test.ts +3 -3
  226. package/src/gates/checker-gate.ts +3 -3
  227. package/src/gates/index.ts +1 -1
  228. package/src/hooks/CONTEXT.md +2 -2
  229. package/src/index.ts +9 -3
  230. package/src/knowledge/CONTEXT.md +2 -2
  231. package/src/knowledge/__tests__/audit.test.ts +1 -1
  232. package/src/knowledge/__tests__/flywheel-metrics.test.ts +1 -1
  233. package/src/knowledge/audit-scoring.ts +1 -1
  234. package/src/monitoring/CONTEXT.md +2 -2
  235. package/src/monitoring/__tests__/skipped-lines-report.test.ts +2 -2
  236. package/src/monitoring/__tests__/traces.test.ts +1 -1
  237. package/src/monitoring/trace-analyzer.ts +2 -2
  238. package/src/monitoring/traces.ts +4 -4
  239. package/src/pretool-use-hook.ts +5 -5
  240. package/src/release/CONTEXT.md +3 -3
  241. package/src/release/integrity.ts +4 -4
  242. package/src/test-setup/__tests__/mkdtemp-cleanup.test.ts +1 -1
  243. package/src/test-setup/mkdtemp-cleanup.ts +1 -1
  244. package/src/tools/CONTEXT.md +3 -3
  245. package/src/tools/__tests__/registry.test.ts +3 -3
  246. package/src/tools/definitions/core/notification/notify.yml +0 -1
  247. package/src/tools/definitions/ext/browser/browser-close.yml +0 -1
  248. package/src/tools/definitions/ext/browser/browser-start.yml +0 -1
  249. package/src/tools/definitions/std/evolution/implement.yml +0 -1
  250. package/src/tools/definitions/std/evolution/prioritize.yml +0 -1
  251. package/src/tools/definitions/std/evolution/report-gap.yml +0 -1
  252. package/src/tools/definitions/std/governance/aggregate-opinions.yml +0 -1
  253. package/src/tools/definitions/std/governance/audit-task.yml +0 -1
  254. package/src/tools/definitions/std/governance/cast-vote.yml +0 -1
  255. package/src/tools/definitions/std/governance/create-voting-session.yml +0 -1
  256. package/src/tools/definitions/std/governance/define-stance.yml +0 -1
  257. package/src/tools/definitions/std/governance/impeach.yml +0 -1
  258. package/src/tools/definitions/std/governance/multi-stance-review.yml +0 -1
  259. package/src/tools/definitions/std/governance/rollback.yml +0 -1
  260. package/src/tools/definitions/std/governance/stance-review.yml +0 -1
  261. package/src/tools/definitions/std/governance/track-effect.yml +0 -1
  262. package/src/tools/definitions/std/governance/vote-tally.yml +0 -1
  263. package/src/tools/definitions/std/planning/split-batch.yml +0 -1
  264. package/src/tools/definitions/std/planning/split-tasks.yml +0 -1
  265. package/src/types/constraint.ts +1 -8
  266. package/src/types/passes-gate.ts +8 -0
  267. package/src/utils/detect-source-roots.ts +2 -20
  268. package/bin/harness-knowledge-track.sh +0 -47
  269. package/bin/harness-sensitive-check.sh +0 -67
  270. package/dist/core/constraints/checkers/iron-flags.d.ts +0 -12
  271. package/dist/core/constraints/checkers/iron-flags.d.ts.map +0 -1
  272. package/dist/core/constraints/checkers/iron-flags.js +0 -16
  273. package/dist/core/constraints/checkers/iron-flags.js.map +0 -1
  274. package/src/core/constraints/checkers/__tests__/iron-flags.test.ts +0 -43
  275. package/src/core/constraints/checkers/iron-flags.ts +0 -17
  276. package/templates/nextjs-app/.github/workflows/ci.yml +0 -39
  277. package/templates/node-api/.github/workflows/ci.yml +0 -36
  278. package/templates/node-api/package.json +0 -23
  279. package/templates/node-api/src/index.ts +0 -2
  280. package/templates/node-api/tsconfig.json +0 -19
  281. package/templates/python-api/.github/workflows/ci.yml +0 -39
@@ -3,16 +3,18 @@
3
3
  *
4
4
  * 覆盖:
5
5
  * - 三条存在性探测(capability_sync / context_doc_sync / docs_freshness)有/无约定两路
6
- * - flag 型 error 级约束 undefined → skip(显式 false 仍 fail,true 仍 pass)
7
6
  * - error 级 skip 不阻断 checkConstraints
8
7
  * - detectTrigger 代码文件 → 附加 code_implementation 推断
9
8
  * - trace 记录 result: 'skip';TraceAnalyzer 的 pass/fail 率分母不计 skip
9
+ *
10
+ * harness#183:flag 型 error 约束(hasVerificationEvidence 三态)随证据源重构退役,
11
+ * no_completion_without_verification 改为 checker 体内读 .harness/evidence;
12
+ * 「error 级 skip 不阻断」的钉子和 trace skip 形态改用 docs_freshness 的存在性探测承载。
10
13
  */
11
14
 
12
15
  import { describe, it, expect, beforeAll, afterAll } from '@jest/globals';
13
16
  import { ConstraintChecker } from '../core/constraints/checker';
14
17
  import { detectTrigger, buildConstraintContext } from '../core/constraints/context-builder';
15
- import { CONSTRAINTS } from '../core/constraints/definitions';
16
18
  import { TraceAnalyzer } from '../monitoring/trace-analyzer';
17
19
  import type { Constraint, ConstraintContext } from '../types/constraint';
18
20
  import type { ExecutionTrace } from '../types/trace';
@@ -162,48 +164,27 @@ describe('skip 三态语义(ADR-0001)', () => {
162
164
  });
163
165
  });
164
166
 
165
- describe('flag 型 error 级约束:undefined → skip', () => {
166
- it('hasVerificationEvidence undefined → skip;false → fail;true → pass', async () => {
167
- const law = CONSTRAINTS['no_completion_without_verification'];
168
-
169
- const skipped = await checker.check(law, { operation: 'code_implementation' });
170
- expect(skipped.skipped).toBe(true);
171
- expect(skipped.satisfied).toBe(true);
172
-
173
- const failed = await checker.check(law, {
174
- operation: 'code_implementation',
175
- hasVerificationEvidence: false,
176
- });
177
- expect(failed.skipped).toBeUndefined();
178
- expect(failed.satisfied).toBe(false);
179
-
180
- const passed = await checker.check(law, {
181
- operation: 'code_implementation',
182
- hasVerificationEvidence: true,
183
- });
184
- expect(passed.skipped).toBeUndefined();
185
- expect(passed.satisfied).toBe(true);
186
- });
187
-
188
- it('Iron Law skip 不阻断 checkConstraints', async () => {
189
- // flag 未接线(CLI pre-commit 路径的典型形态)
167
+ describe('error 级约束的 skip / fail 语义', () => {
168
+ it('error 级 skip 不阻断 checkConstraints(docs_freshness 存在性探测承载)', async () => {
169
+ // 无任何 freshness 约定/目标的空目录:docs_freshness skip(harness#183 前由
170
+ // no_completion_without_verification 的 flag 未接线承载该语义)
190
171
  const result = await checker.checkConstraints({
191
- operation: 'code_implementation',
172
+ operation: 'file_modification',
192
173
  projectPath: path.join(tempDir, 'empty'),
193
174
  });
194
175
 
195
176
  expect(result.passed).toBe(true);
196
177
  const skippedIds = result.errors.filter(r => r.skipped).map(r => r.id);
197
178
  expect(skippedIds).toEqual(
198
- expect.arrayContaining(['no_completion_without_verification'])
179
+ expect.arrayContaining(['docs_freshness'])
199
180
  );
200
181
  });
201
182
 
202
- it('显式 false 仍按 fail 阻断(skip 语义不改变 fail-closed)', async () => {
183
+ it('无验证证据仍按 fail 阻断(skip 语义不改变 fail-closed)', async () => {
203
184
  await expect(
204
185
  checker.checkConstraints({
205
186
  operation: 'code_implementation',
206
- hasVerificationEvidence: false,
187
+ projectPath: path.join(tempDir, 'empty'),
207
188
  hasSingleTask: true,
208
189
  hasRequirement: true,
209
190
  })
@@ -273,14 +254,16 @@ describe('skip 三态语义(ADR-0001)', () => {
273
254
  const records: ExecutionTrace[] = [];
274
255
  const recording = new ConstraintChecker({ record: (t) => records.push(t) });
275
256
 
257
+ // skip 形态由 docs_freshness 存在性探测承载(harness#183 前是 flag 未接线的
258
+ // no_completion_without_verification)
276
259
  await recording.checkConstraints({
277
- operation: 'code_implementation',
260
+ operation: 'file_modification',
278
261
  projectPath: path.join(tempDir, 'empty'),
279
262
  });
280
263
 
281
264
  const skipTraces = records.filter(t => t.result === 'skip');
282
265
  expect(skipTraces.map(t => t.constraintId)).toEqual(
283
- expect.arrayContaining(['no_completion_without_verification'])
266
+ expect.arrayContaining(['docs_freshness'])
284
267
  );
285
268
  });
286
269
 
@@ -1,14 +1,14 @@
1
1
  /**
2
- * studio#602 / E1 飞轮修复:usage-report 数据层公共导出守门。
2
+ * E1 飞轮修复:usage-report 数据层公共导出守门。
3
3
  *
4
4
  * 背景:buildConstraintsUsageReport / diagnoseRetireCandidates 自 0.17.0 起存在于
5
5
  * core/constraints/usage-report,但未从包公共入口导出(exports map 的 ./core 亦不含),
6
- * studio E1 (a) 链路(约束退役候选 → 进化提案)无法消费。本测试钉住公共导出面,
6
+ * 下游消费方进化链路(约束退役候选 → 进化提案)无法消费。本测试钉住公共导出面,
7
7
  * 防回归「加了实现忘加导出」。
8
8
  */
9
9
  import * as harness from '../index';
10
10
 
11
- describe('usage-report public exports (studio#602)', () => {
11
+ describe('usage-report public exports', () => {
12
12
  it('buildConstraintsUsageReport / diagnoseRetireCandidates 从包根导出', () => {
13
13
  expect(typeof (harness as Record<string, unknown>).buildConstraintsUsageReport).toBe('function');
14
14
  expect(typeof (harness as Record<string, unknown>).diagnoseRetireCandidates).toBe('function');
@@ -1,7 +1,7 @@
1
1
  # cli/commands/
2
2
 
3
3
  ## 职责
4
- CLI 子命令实现:20 个顶层命令 + constraints 治理子命令 report/retire/reactivate/pack-proposal,覆盖约束检查/门禁验证/文档同步/知识管理/失败诊断/发布等。
4
+ CLI 子命令实现:20 个顶层命令 + constraints 治理子命令 report/retire/reactivate/disable/pack-proposal,覆盖约束检查/门禁验证/文档同步/知识管理/失败诊断/发布等。
5
5
 
6
6
  H5(#44)起:
7
7
  - **命令定义即注册**:`definitions.ts` 的 `COMMAND_DEFINITIONS` 是命令形状(名称/别名/位置参数/选项/子命令/实现引用)的单一来源;bin/harness.js 遍历本表注册表驱动生成,不再手写 commander 命令块,不再有 index.ts barrel 两处同步(R6)
@@ -19,7 +19,7 @@ H5(#44)起:
19
19
  - 6 门禁命令实现在 `acceptance` / `command` / `contract` / `performance` / `review` / `security`(其 CLI 元数据在 `src/gates/definitions.ts`,形状同为 `CommandDefinition`,ADR-0007);**判定一律穿过统一接口 `evaluate()`**,成败与措辞由共享面映射。`command` 只复用映射、保留自己的单行 ✓/✗ 输出(已对外的机器友好形状);`security audit` / `acceptance list` / `contract validate-schema` / `review status` / `command --list/--level` 是只展示不判断的子命令,直读报告面(`scan()` 等),不套骨架;`security secrets`(P1-8,ADR-0031,wayfinder 票08)是判定子命令但不经门禁——直跑 gitleaks 全历史扫描:二进制缺失 → skip(不 fail),有泄露 → fail(只列条数与文件、不打印密钥原文),干净 → ok;CI 的 secrets job(harness-governance.yml,fetch-depth: 0 + 固定版本安装 gitleaks)跑同一命令,安装后才是真门
20
20
  - CLI 子命令 `command` 的两个分支共用同一台 gate 实例(#135/ADR-0024):默认分支经 `evaluate()` 取裁决、`--level` 经同一实例的 `getRiskLevel()` 取等级,命令侧不再引用模块级单例出口——「配置传进去却到不了判定」的那条路已封。`--strict` 旗帜随 `CommandGateConfig.strict`(零消费者、从不生效)一并删除
21
21
 
22
- `constraints` 下挂治理子命令:`constraints report`(使用统计 + 退役候选诊断 + 配置健康,`--export` 脱敏;JSON 输出走 `--json-output`——原名 `--json` 与父命令同名会被 commander 消费在父侧、JSON 分支不可达,E1 复盘修正 M3.1 换名,闸见 `__tests__/constraints-report-json-flag.test.ts`)、`constraints retire`(交互选择 + 人确认退役;带 id 直达需显式 `--yes`(#24 人确认闸门),无 `--yes` 报错 + 非零退出码且不落盘;落 config.yml retired 墓碑 + KnowledgeStore 沉淀——沉淀写口的 baseDir 走 knowledge-view `openKnowledgeStore` 同一解析点,与 knowledge 读口同根,不再硬编码 projectRoot 拼接(harness#177)。ADR-0029:注入漂移小节、prompt 注入清单、custom 落点与治理注入段同步已随文本注入层关停移除。ADR-0032:already_retired 只认 retired 墓碑,裸 enabled:false 由退休流程接管补墓碑+沉淀(票 02 断点 6);落盘后 git 仓内附 commit 提示,不替用户动 git(断点 4)。ADR-0033:findRetireTarget 扩到内置 + 应用层(`.harness/constraints.yml`)——应用层退休墓碑同写 config.yml(enabled:false + retired 同形),constraints.yml 条文保留不删,沉淀条目 tags 加 `source:app`)、`constraints reactivate`(点对点复活:删 retired 墓碑段 + 写 `constraint-reactivated-<id>` 新沉淀,不改历史(ADR-0032 决策 6.5,票 02 断点 5);直达同需 `--yes`,无交互模式;ADR-0033 起对应用层约束同路径可用)、`constraints pack-proposal`(升级提案材料打包,ADR-0033 决策 4,块 3 子项 5:条文 + checker 模板与参数 + traces 使用统计 + 升级理由留白的脱敏 markdown,缺省落 `.harness/reports/proposal-<id>-<YYYYMMDD>.md`,`--stdout` 打印不落盘;脱敏只做项目根路径→`<repoRoot>` 替换,params 原文带出并标注人工确认——打包是质量前置不是保密闸门,人拿材料去 harness 仓开 issue)。
22
+ `constraints` 下挂治理子命令:`constraints report`(使用统计 + 退役候选诊断 + 配置健康,`--export` 脱敏;JSON 输出走 `--json-output`——原名 `--json` 与父命令同名会被 commander 消费在父侧、JSON 分支不可达,E1 复盘修正 M3.1 换名,闸见 `__tests__/constraints-report-json-flag.test.ts`)、`constraints retire`(交互选择 + 人确认退役;带 id 直达需显式 `--yes`(#24 人确认闸门),无 `--yes` 报错 + 非零退出码且不落盘;落 config.yml retired 墓碑 + KnowledgeStore 沉淀——沉淀写口的 baseDir 走 knowledge-view `openKnowledgeStore` 同一解析点,与 knowledge 读口同根,不再硬编码 projectRoot 拼接(harness#177)。ADR-0029:注入漂移小节、prompt 注入清单、custom 落点与治理注入段同步已随文本注入层关停移除。ADR-0032:already_retired 只认 retired 墓碑,裸 enabled:false 由退休流程接管补墓碑+沉淀(票 02 断点 6);落盘后 git 仓内附 commit 提示,不替用户动 git(断点 4)。ADR-0033:findRetireTarget 扩到内置 + 应用层(`.harness/constraints.yml`)——应用层退休墓碑同写 config.yml(enabled:false + retired 同形),constraints.yml 条文保留不删,沉淀条目 tags 加 `source:app`)、`constraints reactivate`(点对点复活:删 retired 墓碑段 + 写 `constraint-reactivated-<id>` 新沉淀,不改历史(ADR-0032 决策 6.5,票 02 断点 5);直达同需 `--yes`,无交互模式;ADR-0033 起对应用层约束同路径可用)、`constraints disable`(裸禁用,harness#190 = ADR-0032 决策 6.6 的另一侧:config.yml `enabled:false` 无 retired 墓碑、无知识沉淀,区别于 retire;幂等 already_disabled,retired 墓碑不接管返回 already_retired;写后验证生效集已缩小、失败回滚备份——与下游消费方 applier 的 applyDisable 同一纪律(经下游裁定 config.yml 归 harness,本命令是下游切换落点);直达同需 `--yes`,无交互模式;认内置 + 应用层约束(findRetireTarget 同路径))、`constraints pack-proposal`(升级提案材料打包,ADR-0033 决策 4,块 3 子项 5:条文 + checker 模板与参数 + traces 使用统计 + 升级理由留白的脱敏 markdown,缺省落 `.harness/reports/proposal-<id>-<YYYYMMDD>.md`,`--stdout` 打印不落盘;脱敏只做项目根路径→`<repoRoot>` 替换,params 原文带出并标注人工确认——打包是质量前置不是保密闸门,人拿材料去 harness 仓开 issue)。
23
23
 
24
24
  ## 依赖关系
25
25
  - 依赖 `src/core/constraints/` 约束引擎
@@ -45,10 +45,11 @@ H5(#44)起:
45
45
  - `constraints report`:提示属于**报告体内的降级位**,与既有的 `traceFileExists` 说明同在 stdout;结构化面另两份——`--json-output` 的 `skippedLines` 字段、`--export` markdown 的警示行(只报条数,不报路径与坏行内容)
46
46
  - `constraints retire`:两条路径都**走 stderr**——交互模式在候选列表前一行(沿用本函数既有的 console 例外,`console.error`),`--yes` 直达分支在落盘前 `logError(io, …)`(`retireConstraint` 本身按契约「纯执行无交互」不打印)
47
47
  - 原则正本与逐点去向见 `src/monitoring/CONTEXT.md`「约定」段;机器可检面是 `src/utils/__tests__/jsonl-skip-disposition.test.ts`(冻结全仓 skip 读点集合 + 要求每个读点记名声明 `计数去向:`)
48
+ - **sync-docs `--gate`:自愈写入 + vs HEAD 漂移判定(harness#189)**:流水线「仓库级漏登门」(harness#120 方案 A 的内联 `git diff --exit-code CAPABILITIES.md`)收进 harness 侧的落点。语义 = 照常跑写模式自愈(幽灵剔除、file 模式补行不变),再用 `git status --porcelain` 判定被管理文档(CAPABILITIES.md;`--agents` 时含 AGENTS.md;本轮新建的 CONTEXT.md)相对 HEAD 是否有 diff——有 diff 判 `fail` 且点名(diff 新增行即缺登记名单,经 `head-gate.ts` 的 `missingRegistrationNames` 从表格行取「文件」列),无 diff 判 `ok`;「需要自愈」本身成为失败,自愈顺序不变(写入永远在校验之前)。与 `--check`/`--json`/`--compact` 互斥(usage-error,不猜意图);非 git 仓库或无 HEAD → usage-error 且零落盘(前置校验先于写入)。判定本体住 `sync-docs/head-gate.ts`(`assertHeadGateEnv` / `diffManagedDocsAgainstHead`)。不动 `capability_sync` 判定(ADR-0016 决策 3 归因口径不回退)。机器可检:`__tests__/sync-docs-gate.test.ts`(真 git 仓 fixture:漏登 fail 且点名 + 写入已落盘 / HEAD 干净 ok / 幽灵剔除触发门 / AGENTS.md untracked 漂移 / 非 git 仓 usage-error 零写入 / 三旗帜互斥)
48
49
  - **一次命令运行内,同一份数据至多取一次(harness#146,#140 A 票;与 ADR-0023 同族,但不扩 `RunEnv` 公共面)**:`spec-baseline-check` 的三条验证路径(文件存在性 / 依赖 / 代码模式)一律从命令级共享索引 `createBaselineIndex(projectPath)` 取数,不再各自裸调 `fs`——全仓 `.ts`/`.js` 内容扫描一遍建成 `路径 → 内容` 表、`package.json` 读解析一次(**读取失败态同样入库**,不逐条重试)、同一落点的存在性探测只 stat 一次;逐条前置与每个关键词只在索引上重放判定。索引**懒建**(没有前置需要某类数据时该类读取一次都不发生)、**运行结束即弃**(不跨命令复用:本命令是独立命令而非 `harness check` 的子步骤,「同一口径取一次」命令内自足即够,#140 triage 裁决 5)。改前代价 = 前置条件数 × 关键词数 × 源文件数,改后与条数无关,判定/证据文案/stdout/退出码逐字不变。**驻留上界(harness#162)**:索引容量有双上限 `SOURCE_INDEX_MAX_ENTRIES = 5000` / `SOURCE_INDEX_MAX_BYTES = 64MB`——超任一上限即放弃驻留、**回落逐文件流式读**(每个关键词重扫一遍,读完即弃),峰值内存由 O(全仓源码) 回到 O(单文件),正常规模仓保留「一次遍历」收益;取数面相应由 `sourceContents(): Map` 改为 `countFilesContaining(keyword)`,容量策略全部收在索引内部。机器可检:`__tests__/spec-baseline-read-count.test.ts`(形状照 `check-read-count.test.ts`:`readFileSync`·只读 `openSync`·`existsSync`·`readdirSync` 记件 + 整张读取表与目录扫描表逐条冻结 + 「同一份数据的同一口径至多取一次」+ N×K 缩放不变式 + 懒建不扫 + 失败态入库)+ `__tests__/spec-baseline-index-cap.test.ts`(驻留上界闸:上限内每文件至多读一遍、超条目/字节上限回落流式且判定不变)
49
50
  - **先判定「本次要什么」再决定「读什么」,且清单顺序是对外面(harness#147,#140 B 票)**:`sync-docs/index.ts` 把 CAPABILITIES.md 的**格式判定放在源码扫描之前**——capability-listing 格式的判定面是计数、不做条目级比对,模块清单在本次运行里无人消费,于是整棵源码树**一份 `.ts` 内容都不读**(改造前是无条件全树逐文件 `await readFile`,只为首行注释)。要描述的分支(file-table)照旧取描述,但 `project-reader.ts` 分两步:先按目录遍历序定清单,再经 `extractFileDescriptions()` **并发**取数(上限固定 16,按票下裁决不做成配置面)并**按原索引回填**。清单顺序对外可见(`--check` 逐行比对生成的表格、人看 diff),票下裁决是「顺序逐字保持现状、不改字典序」,故「按并发完成顺序 append」属行为漂移而非优化。读盘次数之外一切不变:判定、漂移检测、写回内容逐字保持。机器可检:`__tests__/sync-docs-read-count.test.ts`(形状照 `check-read-count.test.ts`——listing 模式 `.ts` 内容读 = 0 + file-table 反证每份文件恰读一次 + 整张读取表冻结)、`sync-docs/__tests__/module-descriptions.test.ts`(替身把「起始序」与「完成序」刻意错开:串位或重排即红,另钉上限)、`__tests__/sync-docs-module-order.test.ts`(生成表格行序 = 目录遍历序、两次运行逐字复现)
50
51
 
51
- - **撤登记要整行删,排版判定与修复共用一份正本(harness#171)**:`capabilities-syncer.ts` 删幽灵行此前是 `content.replace(/^\|…$/gm, '')`——`m` 下 `^…$` 只框住行内容、**不含行尾换行**,删完留一个空行;CommonMark 以空行断表,于是每撤一次登记就把一张能力表多切一刀(studio 存量攒到 40 处)。同函数末尾的 `\n{3,}→\n\n` 救不了它:删一行只产两个换行,够不着阈值(删相邻两行也不变好——只是把两刀并成一刀)。现行形状:① 删除按行 split/filter/join,行尾随之消失(CRLF 一并处理,正则尾上加 `\r?` 保持与旧 `m` 相同的匹配面);② 排版收拢正本是 `normalizeCapabilitiesTableLayout(content)`——规则①删两侧都是表格行的空行段、规则②收掉无数据行的表头/分隔行,**表格外的段落空行不动**,且**两条规则互相制造触发点**(①吃掉两张空表之间那个空行后,②在同一轮只收得掉后一张),故**跑到不动点**:一次 `sync-docs` 必须把 `--check` 报出来的全清掉,否则下游 CI 修完还红;③ 原有的一处 `\n{3,}→\n\n` 由「增删之后」移到**收拢之后**(收掉一张夹在两段散文之间的空表本身会新产 `\n\n\n`,留在前面就漏折叠),并删掉增删分支内那份重复折叠。围栏代码块(``` / ~~~)内的行在**排版收拢一侧整体豁免**(CAPABILITIES.md 是手写文档,块内长得像表格的示例行不是脏行:不给豁免时一块「表头+分隔行」示例被判空表删掉正文、`--check` 还为此判红)——但**幽灵行删除一侧刻意不豁免**,两侧口径故意不同:登记条目由 `core/constraints/capabilities-parser` 全文扫描得出(ADR-0009),围栏内的行同样算登记项,只让删除认围栏而条目不认,块内示例引用的已删文件会永远报成幽灵条目且 `--check` 修不掉(机器可检:「围栏内示例行引用已删文件」用例同时钉收敛与「只吃掉那一行、块内其余正文留着」)。让两侧同认围栏 = 改 ADR-0009 的登记面并连带影响 docs_freshness 判定,另票裁决。`--check` 的判定面就是「它返回的内容与入参是否不同」,写模式在**增删之后**调用收拢(先收拢会误删「本轮要往空表里补新行」的表头),故 check 报得出、fix 必清得掉(不重演 2026-08-04 studio PR #44 的「check 永不收敛」)。机器可检:`__tests__/sync-docs-table-layout.test.ts`(13 例:中间行/末行/目录条目行/CRLF 四种撤登形状 + 存量脏行 check 判红后写模式转绿 + 空表收掉 + 两张空表相邻一次收干净 + 收拢后不留三连换行 + 四条反向闸「有新行不误删表头」「表格外空行不动」「代码块内空表不被收」「代码块内表格样式行不被收拢」)
52
+ - **撤登记要整行删,排版判定与修复共用一份正本(harness#171)**:`capabilities-syncer.ts` 删幽灵行此前是 `content.replace(/^\|…$/gm, '')`——`m` 下 `^…$` 只框住行内容、**不含行尾换行**,删完留一个空行;CommonMark 以空行断表,于是每撤一次登记就把一张能力表多切一刀(下游消费方存量曾攒到 40 处)。同函数末尾的 `\n{3,}→\n\n` 救不了它:删一行只产两个换行,够不着阈值(删相邻两行也不变好——只是把两刀并成一刀)。现行形状:① 删除按行 split/filter/join,行尾随之消失(CRLF 一并处理,正则尾上加 `\r?` 保持与旧 `m` 相同的匹配面);② 排版收拢正本是 `normalizeCapabilitiesTableLayout(content)`——规则①删两侧都是表格行的空行段、规则②收掉无数据行的表头/分隔行,**表格外的段落空行不动**,且**两条规则互相制造触发点**(①吃掉两张空表之间那个空行后,②在同一轮只收得掉后一张),故**跑到不动点**:一次 `sync-docs` 必须把 `--check` 报出来的全清掉,否则下游 CI 修完还红;③ 原有的一处 `\n{3,}→\n\n` 由「增删之后」移到**收拢之后**(收掉一张夹在两段散文之间的空表本身会新产 `\n\n\n`,留在前面就漏折叠),并删掉增删分支内那份重复折叠。围栏代码块(``` / ~~~)内的行在**排版收拢一侧整体豁免**(CAPABILITIES.md 是手写文档,块内长得像表格的示例行不是脏行:不给豁免时一块「表头+分隔行」示例被判空表删掉正文、`--check` 还为此判红)——但**幽灵行删除一侧刻意不豁免**,两侧口径故意不同:登记条目由 `core/constraints/capabilities-parser` 全文扫描得出(ADR-0009),围栏内的行同样算登记项,只让删除认围栏而条目不认,块内示例引用的已删文件会永远报成幽灵条目且 `--check` 修不掉(机器可检:「围栏内示例行引用已删文件」用例同时钉收敛与「只吃掉那一行、块内其余正文留着」)。让两侧同认围栏 = 改 ADR-0009 的登记面并连带影响 docs_freshness 判定,另票裁决。`--check` 的判定面就是「它返回的内容与入参是否不同」,写模式在**增删之后**调用收拢(先收拢会误删「本轮要往空表里补新行」的表头),故 check 报得出、fix 必清得掉(不重演 2026-08-04 CI 不收敛事故的「check 永不收敛」)。机器可检:`__tests__/sync-docs-table-layout.test.ts`(13 例:中间行/末行/目录条目行/CRLF 四种撤登形状 + 存量脏行 check 判红后写模式转绿 + 空表收掉 + 两张空表相邻一次收干净 + 收拢后不留三连换行 + 四条反向闸「有新行不误删表头」「表格外空行不动」「代码块内空表不被收」「代码块内表格样式行不被收拢」)
52
53
 
53
54
  ## 注意事项
54
55
  - 新增命令需同步更新 CLAUDE.md / CAPABILITIES.md / src/CONTEXT.md
@@ -65,12 +66,12 @@ H5(#44)起:
65
66
  - **冻结类测试的两条判据(#133 收尾须知自报第一条,#151 补完其推论)**:
66
67
  - **fixture 走不到的分支须逐个建形,不共用一个空根**。闸 4b 的 `emptyRoot()` 是裸 `mkdtemp` 目录,天然没有 `.harness/knowledge-docs/`,于是 `syncRagRows` 的两个空态分支只有第一个(`!docsPresent`)进过基线,第二个(目录在场、无 `.md`)在测试里走不到——文案改字全绿。而 json 面两分支恒同形(`data = {directory, files}`),`--json` 断言钉不住人读第二行。落点:闸 4c 的平行表 `EXTRA_EMPTY_HUMAN_CASES`(每 case 自带 `makeRoot` + 人读逐行基线 + json 形状;不改 `EMPTY_HUMAN_BASELINE: Record<SubName, string[]>` 的形状,一个子命令只装一种形状的约束留在原表)。
67
68
  - **渲染类映射(tone / label / 颜色)必须有纯函数级断言,identity-mock 的文本基线不算覆盖**。`knowledge-view.test.ts` 把 chalk mock 成 identity(其注释「人读断言看的是文本,不看 ANSI」即本条病灶的自供),于是 `TONE_STYLES` 与 `toneForMaturity`/`toneForSeverity`/`toneForScore` 全仓零命中,#133 有意偏离③(`stats` 的 `verified` 由黄变青)改回去不会有任何测试红。落点:`knowledge-tone-mapping.test.ts` 逐格冻两张表——「输入值 → tone」(6 个成熟度 / 7 个 severity / 分数边界各一格)与「tone → chalk 样式键」(7 个档位;chalk 替身按样式键给文本加标签,断言走 `renderDisplayModel` / `announce` 的真实渲染链而非只读表),另加「表键集合穷尽」双钉(编译期 `Record<DisplayTone, …>` 缺键即 tsc 红 + 运行期与源码 `DisplayTone` 联合、`TONE_STYLES` 字面量逐字对撞)。**生产侧零改动**:`TONE_STYLES` 仍不导出——本闸钉的是它的行为与声明形状,不是它的可访问性(导出会动 `knowledge-view.ts` 的公开面,ADR-0022 口径下得另走定级)。#158 补最后一跳:`knowledge-view.test.ts` 另有一条 display model 结构断言「stats 成熟度格必须携带 `tone` 且 = `toneForMaturity(maturity)`」——命令侧把 `tone:` 从格上摘掉(复审 M7)由它撞红,看结构不看 ANSI,不违 identity-mock 立场。
68
- - **json 面现状冻结**:11 个顶层形状逐字不动(双仓核实 `knowledge --json` 零程序化消费者,studio 走 library 直调;统一包壳是纯 churn,删除 `--json` 死面按 ADR-0022 口径另票评估)。三处有意偏离,均不改字段集合:① `snapshot`/`index` 的 `--json` 由单行紧凑改为两空格缩进(分派单点化的直接结果,与其余 9 个子操作同形);② `sync-rag` 的两个空态此前把人类文案直接打到 `--json` 的 stdout(吐出的不是 JSON),现由 display model 承担,json 面恒为 `{directory, files}`;③ `stats` 人读面 `verified` 成熟度的颜色随 `toneForMaturity` 单表变为青色(此前 list 青 / stats 黄两处手抄不一致,文字不变)。
69
+ - **json 面现状冻结**:11 个顶层形状逐字不动(双仓核实 `knowledge --json` 零程序化消费者,下游消费方走 library 直调;统一包壳是纯 churn,删除 `--json` 死面按 ADR-0022 口径另票评估)。三处有意偏离,均不改字段集合:① `snapshot`/`index` 的 `--json` 由单行紧凑改为两空格缩进(分派单点化的直接结果,与其余 9 个子操作同形);② `sync-rag` 的两个空态此前把人类文案直接打到 `--json` 的 stdout(吐出的不是 JSON),现由 display model 承担,json 面恒为 `{directory, files}`;③ `stats` 人读面 `verified` 成熟度的颜色随 `toneForMaturity` 单表变为青色(此前 list 青 / stats 黄两处手抄不一致,文字不变)。
69
70
  - 与 #134(KnowledgeAudit 收 store)独立落地,唯一交点 `knowledgeAudit` 命令函数——#134 是后到方并已适配:`knowledgeAuditView` 经 `openKnowledgeStore` 取 store 作引擎第一形参、`shortContentThreshold` 作第二形参(构造期不再自建 store)。审计后重建索引「只在人读路径发生」是本票保留的既有策略(`--json` 不写盘),也是 `knowledge.ts` 内被逐行冻结的唯一 `options.json` 分支。
70
- - init 治理约束段写入落点(studio #302,ADR 2026-08-21 落点模型):新仓 → AGENTS.md `PRESERVE:governance` 段(sync-docs 重新生成时保留);旧模型仓(CLAUDE.md 已有 HARNESS_CONSTRAINTS 标记或 `## Governance Rules` 块)→ 续写 CLAUDE.md,幂等重跑不制造双份正本。治理段「在场守护」由 core 侧 governance_presence checker 承担(段缺失/为空时 check 报警)
71
+ - init 治理约束段写入落点(ADR 2026-08-21 落点模型):新仓 → AGENTS.md `PRESERVE:governance` 段(sync-docs 重新生成时保留);旧模型仓(CLAUDE.md 已有 HARNESS_CONSTRAINTS 标记或 `## Governance Rules` 块)→ 续写 CLAUDE.md,幂等重跑不制造双份正本。治理段「在场守护」由 core 侧 governance_presence checker 承担(段缺失/为空时 check 报警)
71
72
  - ADR-0029(文本注入层关停):init 的约束注入段 writer(setupAgentsMdConstraints / setupClaudeMdConstraints / setupGovernanceConstraints)、check 的注入漂移警告块、report 的漂移小节与 prompt 注入清单、retire 的注入段同步全部移除;sync-docs 不再生成 HARNESS_CONSTRAINTS 注入段。PRESERVE 标记保留机制本身保留(通用机制,非约束注入);历史 HARNESS_CONSTRAINTS 段在 `hasGovernanceContract` 中仅作治理契约在场的历史兼容判据
72
73
  - marker-range 替换与治理正本探测收口在 `core/constraints/injection-writer`(ADR-0011):init 的 Output Style 段 writer 为「渲染 body + 调 writer」,半标记(单边/乱序)一律拒写告警;注入段落点路由(resolveInjectionTarget / resolveGovernanceLanding)已随 ADR-0029 删除
73
- - knowledge 命令包含 11 个子操作(list/search/import/decay/stats/sync-rag/audit/snapshot/migrate/index/health);upsert/sync-status 已迁至 studio CLI(harness#110,二者硬编码 localhost Studio 内部端点,不属 harness「通用框架、文件驱动」定位)
74
+ - knowledge 命令包含 11 个子操作(list/search/import/decay/stats/sync-rag/audit/snapshot/migrate/index/health);upsert/sync-status 已迁至下游消费方 CLI(harness#110,二者硬编码 localhost 下游内部端点,不属 harness「通用框架、文件驱动」定位)
74
75
  - `stats` / `health` 的飞轮数字不在 CLI 内计算:分子口径唯一实现是 `knowledge/flywheel-metrics.ts`(`evaluateFlywheel`,ADR-0013),本层只做百分比取整/一位小数与字段名映射;`.consumption-stats.json` 的读取留在各命令(module 零 IO)
75
76
  - 特殊路由(选项条件、子命令兜底、裸跑语义)表达在定义表的 optionRoutes / subcommands / subcommandStrict / bareRunsAction 字段,bin 是纯通用引擎、不含单命令知识
76
77
  - **数值旗帜装配口径(harness#152)**:`<n>` / `<rate>` 这类数值旗帜经 commander 到命令侧**恒是字符串**(`defaultValue: '50'` 也是),所以入参声明必须跟着运行时形状走——装配点之前声明 `string`(或双形 `string | number`,如 `failure --limit`),数值只在装配点转一次。装配点有两处:**有 `mapActionArgs` 的命令在定义表装配**(`status --hours`、`constraints report` 三阈值、门禁 `--coverage-threshold`/`--bundle-threshold`/`--min-reviewers`),**knowledge 族是「纯投影条目」故编组归命令模块**(`knowledgeSearchCommand` 的 `--limit`、`knowledgeAudit` 的 `--threshold`);两形都对,判据是「声明与运行时一致」,因此 `as any` 不该出现在这条链上(它替编译器记住了旗帜的实际形状,去掉 `parseInt` 就是往数值槽塞字符串)。**转不出来必须 fail-loud**(`logError` + `usage-error`,非零退出):下游兜底写的多是 `?? 缺省值`,而 `??` 只兜 `null`/`undefined`、NaN 照单全收,于是一句 `len < NaN` 恒 false 就把一道质量判定静默关掉、退出码仍是 0(#152 病灶正本:`knowledge audit --threshold abc`)。上游按口径挡住的,引擎侧不再重复兜(库面向的守卫已落 harness#163:`KnowledgeAudit` 构造器对 `shortContentThreshold`/`staleDays`/`promotionBlockDays` 三槽的显式脏值(NaN/±Infinity/负数)构造期抛 `TypeError`,未传/显式 `undefined` 走缺省、显式 `0` 合法)。可检面:`__tests__/knowledge-audit-threshold.test.ts`(脏值 fail-loud / 缺省 '50' 与未传同果 / 显式 '0' 不被当未传 / `knowledge.ts` 零 `as any`)+ `__tests__/bin-exit-mapping.test.ts`(对外退出码 1 的端到端证据);knowledge 的 `kind:` 逐行冻结豁免表在 `__tests__/knowledge-view.test.ts` 闸 1(#152 起两行、#154 起三行,理由随表注)。其余数值旗帜的脏输入后果(fail-closed 与静默按缺省两类)逐项判定见 #152 票面,#152 只收 `knowledge audit --threshold` 一处;**harness#154 已把口径推广到全部数值旗帜**(已推广清单如下),**唯一解析器 = `src/utils/numeric-flag.ts`**(本条目指名的正本:`parseNumericFlag` 判别 + `numericFlagMessage` 文案模板 + `requireNumericFlag` 抛出 + `NumericFlagError`;`parseInt`/`parseFloat` 的前缀截断 `'30abc'→30`、`'1e2'→1` 同属静默误读,禁回)。两消费形同一条判定规则:定义表 `mapActionArgs` 站点(`constraints report` 三阈值、`performance --coverage-threshold`/`--bundle-threshold`、`review --min-reviewers`)走 `requireNumericFlag` 抛出、bin 在 `runDefinition` 捕获映射 usage-error——定义表是纯数据模块返回不了 CommandResult,装配失败的通道只此一条,bin 不因此新增单命令知识;命令模块站点(`knowledge search --limit`、`failure list --limit`、`passes-gate --coverage-threshold` 的 `coverageCheck`)走 `parseNumericFlag` 就地 `logError` + `usage-error`,且都先于 store/recorder 构造与任何执行(脏值零落盘)。#152 的 `assembleShortContentThreshold` 改为委派 `parseNumericFlag`(函数面与 #152 报错文案保留、冻结测试钉死,未新建第二套解析器)。**#152 判为 fail-closed 的两处不保留、一并收敛 fail-loud**(#154 裁定):`passes-gate --coverage-threshold` 的「覆盖率不足 (x% < NaN%)」自证异常文案与 `review --min-reviewers` 的恒不通过——脏输入属用法错误、自证异常的文案即缺陷;合法输入路径逐字不变,退出码面 review 1→1、passes-gate coverage 脏值 0→1 属缺陷修正(定级与 CHANGELOG 入账见该票)。边界不动:门禁/引擎构造器侧的 falsy/`??` 约定是库面向语义(显式 `0` 在 performance 门禁内仍 = 不检查该项),与 #163 同例不重复兜;`status --hours` 是死旗帜,另族另票。可检面新增:`src/utils/__tests__/numeric-flag.test.ts`(解析规则矩阵)+ `src/cli/commands/__tests__/numeric-flag-assembly.test.ts`(定义表逐旗帜装配 + 命令入口 + 端到端 spawn:脏输入 / 合法路径对拍 / 显式 `0`)
@@ -92,6 +92,9 @@ function fixtureRepo(): string {
92
92
  // 改一个已登记的源文件并 stage → 触发条件 module_modification
93
93
  write(dir, 'src/existing.ts', 'export const a = 2;\n');
94
94
  git(dir, 'add', '--', 'src/existing.ts');
95
+ // harness#183:真验证证据(.harness/evidence 落盘,须在变更之后写 → mtime 更新);
96
+ // readdir/stat 不经本套件的读取计数器,冻结表不变
97
+ write(dir, '.harness/evidence/test-fixture.log', '1 passed\n');
95
98
  return dir;
96
99
  }
97
100
 
@@ -67,7 +67,7 @@ function stageChange(dir: string, rel: string, content: string): void {
67
67
  git(dir, 'add', '--', rel);
68
68
  }
69
69
 
70
- /** 真验证证据:traces.log 里有一条 pass(未跟踪,不进 diff) */
70
+ /** trace 种子行(未跟踪,不进 diff);仅供 trace 计数/切片类用例预置 */
71
71
  function passTraces(dir: string, lines = 1): void {
72
72
  write(
73
73
  dir,
@@ -76,6 +76,14 @@ function passTraces(dir: string, lines = 1): void {
76
76
  );
77
77
  }
78
78
 
79
+ /**
80
+ * 真验证证据(harness#183):.harness/evidence 落盘一条测试输出(未跟踪,不进 diff)。
81
+ * traces.log 不再充当验证证据(其唯一写入方是约束检查自身,语义循环已拆除)。
82
+ */
83
+ function passEvidence(dir: string): void {
84
+ write(dir, '.harness/evidence/test-fixture.log', '1 passed\n');
85
+ }
86
+
79
87
  /**
80
88
  * 本项目的 trace 落点记录(harness#139:命令侧收集器锚根构造,写的就是 `<projectPath>/DEFAULT_TRACE_FILE` 正本)
81
89
  *
@@ -146,6 +154,7 @@ function stagedTestDeletion(): string {
146
154
  git(dir, 'commit', '-q', '-m', 'tests');
147
155
  stageChange(dir, 'src/__tests__/existing.test.ts', "test('a', () => {}\n");
148
156
  passTraces(dir);
157
+ passEvidence(dir);
149
158
  return dir;
150
159
  }
151
160
 
@@ -161,6 +170,7 @@ describe('check command(真 git fixture)', () => {
161
170
  const dir = gitRepo();
162
171
  stageChange(dir, 'src/existing.ts', 'export const a = 2;\n');
163
172
  passTraces(dir);
173
+ passEvidence(dir);
164
174
 
165
175
  const result = await check(
166
176
  { preset: 'standard', staged: true, projectPath: dir, trigger: 'code_implementation' },
@@ -183,11 +193,12 @@ describe('check command(真 git fixture)', () => {
183
193
  io
184
194
  );
185
195
 
186
- expect(io.outText()).toContain('禁止无验证声明完成,必须运行验证命令');
187
- expect(result).toEqual({
188
- kind: 'fail',
189
- reason: 'check error: 禁止无验证声明完成,必须运行验证命令',
190
- });
196
+ expect(io.outText()).toContain('禁止无验证声明完成,必须有晚于最新变更的验证证据');
197
+ // reason 携带证据行(harness#119 证据通道),前缀比对即可
198
+ expect(result.kind).toBe('fail');
199
+ expect(result.kind === 'fail' && result.reason).toContain(
200
+ 'check error: 禁止无验证声明完成,必须有晚于最新变更的验证证据(.harness/evidence)'
201
+ );
191
202
  });
192
203
 
193
204
  it('staged 删除测试行 → 真 git diff 驱动 no_test_simplification 拦截', async () => {
@@ -216,6 +227,7 @@ describe('check command(真 git fixture)', () => {
216
227
  'export const a = 1;\nconst pass' + 'word = "correcthorsebattery";\n'
217
228
  );
218
229
  passTraces(dir);
230
+ passEvidence(dir);
219
231
 
220
232
  const result = await check(
221
233
  { preset: 'standard', staged: true, projectPath: dir, trigger: 'code_implementation' },
@@ -233,6 +245,7 @@ describe('check command(真 git fixture)', () => {
233
245
  write(dir, '.harness/config.yml', 'preset: standard\n');
234
246
  stageChange(dir, 'src/existing.ts', 'export const a = 2;\n');
235
247
  passTraces(dir);
248
+ passEvidence(dir);
236
249
 
237
250
  // 不显式传 trigger:governance_presence 的触发词是 file_modification,由 diff 推断
238
251
  const result = await check(
@@ -251,6 +264,7 @@ describe('check command(真 git fixture)', () => {
251
264
  stageChange(dir, 'src/existing.ts', 'export const a = 2;\n');
252
265
  stageChange(dir, 'src/nested/deep.ts', 'export const d = 2;\n');
253
266
  passTraces(dir);
267
+ passEvidence(dir);
254
268
 
255
269
  await check(
256
270
  { preset: 'standard', staged: true, projectPath: dir, trigger: 'code_implementation' },
@@ -274,6 +288,7 @@ describe('check command(真 git fixture)', () => {
274
288
  const dir = gitRepo();
275
289
  stageChange(dir, 'src/existing.ts', 'export const a = 2;\n');
276
290
  passTraces(dir);
291
+ passEvidence(dir);
277
292
 
278
293
  await check({ staged: true, projectPath: dir, trigger: 'code_implementation' }, io);
279
294
  await check(
@@ -309,6 +324,7 @@ describe('check command(真 git fixture)', () => {
309
324
  const dir = capRepo(['src/existing.ts', 'src/nested/deep.ts']);
310
325
  stageChange(dir, 'src/nested/extra.ts', 'export const e = 1;\n');
311
326
  passTraces(dir);
327
+ passEvidence(dir);
312
328
 
313
329
  const result = await check(
314
330
  { preset: 'standard', staged: true, projectPath: dir, trigger: 'module_modification' },
@@ -323,6 +339,7 @@ describe('check command(真 git fixture)', () => {
323
339
  it('仓库级漂移(与本次变更无关)→ 提示块露出,不判违规', async () => {
324
340
  const dir = capRepo(['src/existing.ts']);
325
341
  passTraces(dir);
342
+ passEvidence(dir);
326
343
 
327
344
  const result = await check(
328
345
  { preset: 'standard', staged: true, projectPath: dir, trigger: 'module_modification' },
@@ -342,6 +359,7 @@ describe('check command(真 git fixture)', () => {
342
359
  it('提示与违规都写进 trace 的 evidence 字段(统计侧可诊断)', async () => {
343
360
  const dir = capRepo(['src/existing.ts']);
344
361
  passTraces(dir);
362
+ passEvidence(dir);
345
363
 
346
364
  await check(
347
365
  { preset: 'standard', staged: true, projectPath: dir, trigger: 'module_modification' },
@@ -361,6 +379,7 @@ describe('check command(真 git fixture)', () => {
361
379
  const dir = gitRepo();
362
380
  stageChange(dir, 'src/__tests__/added.test.ts', "test('a', () => {}\n");
363
381
  passTraces(dir);
382
+ passEvidence(dir);
364
383
  const { evidence, requests, commands } = recordingEvidence(dir);
365
384
 
366
385
  const result = await check({ preset: 'standard', staged: true, projectPath: dir, evidence }, io);
@@ -376,6 +395,7 @@ describe('check command(真 git fixture)', () => {
376
395
  const stagedDir = gitRepo();
377
396
  stageChange(stagedDir, 'src/existing.ts', 'export const a = 2;\n');
378
397
  passTraces(stagedDir);
398
+ passEvidence(stagedDir);
379
399
  const staged = recordingEvidence(stagedDir);
380
400
  await check(
381
401
  { preset: 'standard', staged: true, projectPath: stagedDir, trigger: 'code_implementation', evidence: staged.evidence },
@@ -388,6 +408,7 @@ describe('check command(真 git fixture)', () => {
388
408
  const worktreeDir = gitRepo();
389
409
  write(worktreeDir, 'src/existing.ts', 'export const a = 3;\n');
390
410
  passTraces(worktreeDir);
411
+ passEvidence(worktreeDir);
391
412
  const worktree = recordingEvidence(worktreeDir);
392
413
  await check(
393
414
  { preset: 'standard', staged: false, projectPath: worktreeDir, trigger: 'code_implementation', evidence: worktree.evidence },
@@ -404,6 +425,7 @@ describe('check command(真 git fixture)', () => {
404
425
  const dir = gitRepo();
405
426
  stageChange(dir, 'src/existing.ts', 'export const a = 2;\n');
406
427
  passTraces(dir);
428
+ passEvidence(dir);
407
429
  const seeded = projectTraces(dir).length;
408
430
 
409
431
  await check(
@@ -427,6 +449,7 @@ describe('check command(真 git fixture)', () => {
427
449
  const dir = gitRepo();
428
450
  stageChange(dir, 'src/existing.ts', 'export const a = 2;\n');
429
451
  passTraces(dir);
452
+ passEvidence(dir);
430
453
 
431
454
  await check({ preset: 'standard', staged: true, projectPath: dir }, io);
432
455
 
@@ -437,6 +460,7 @@ describe('check command(真 git fixture)', () => {
437
460
  const dir = gitRepo();
438
461
  stageChange(dir, 'src/brandnew/mod.ts', 'export const n = 1;\n');
439
462
  passTraces(dir);
463
+ passEvidence(dir);
440
464
 
441
465
  await check({ preset: 'standard', staged: true, projectPath: dir }, io);
442
466
 
@@ -447,6 +471,7 @@ describe('check command(真 git fixture)', () => {
447
471
  const dir = gitRepo();
448
472
  stageChange(dir, 'src/__tests__/existing.test.ts', "test('a', () => {}\n");
449
473
  passTraces(dir);
474
+ passEvidence(dir);
450
475
 
451
476
  await check({ preset: 'standard', staged: true, projectPath: dir }, io);
452
477
 
@@ -467,6 +492,7 @@ describe('check command(真 git fixture)', () => {
467
492
  const dir = gitRepo();
468
493
  stageChange(dir, 'src/existing.ts', 'export const a = 2;\n');
469
494
  passTraces(dir);
495
+ passEvidence(dir);
470
496
 
471
497
  await check(
472
498
  { preset: 'standard', staged: true, projectPath: dir, trigger: 'design_request' },
@@ -483,6 +509,7 @@ describe('check command(真 git fixture)', () => {
483
509
  const dir = gitRepo();
484
510
  stageChange(dir, 'src/existing.ts', 'export const a = 2;\n');
485
511
  passTraces(dir);
512
+ passEvidence(dir);
486
513
  write(
487
514
  dir,
488
515
  '.harness/config.yml',
@@ -0,0 +1,229 @@
1
+ /**
2
+ * harness constraints disable 测试(harness#190,ADR-0032 决策 6.6 的另一侧)
3
+ *
4
+ * 裸禁用 = config.yml `constraints.<id>.enabled:false`,无 retired 墓碑、无知识沉淀
5
+ * (墓碑与沉淀是 retire 专有语义)。幂等 already_disabled;retired 墓碑不接管不动;
6
+ * 写后验证生效集已缩小,失败回滚(与下游消费方 applier 同一纪律)。
7
+ * CLI 直达(constraintsDisable):--yes 人确认闸门,与 retire/reactivate 同形。
8
+ *
9
+ * 使用真实临时目录。
10
+ */
11
+
12
+ import * as fs from 'fs';
13
+ import * as os from 'os';
14
+ import * as path from 'path';
15
+ import * as yaml from 'js-yaml';
16
+ import { captureIO, type CapturingIO } from '../../command-contract';
17
+ import { getEffectiveConstraints } from '../../../core/effective-constraints';
18
+ import * as effectiveConstraints from '../../../core/effective-constraints';
19
+ import { FileKnowledgeStore } from '../../../knowledge/store';
20
+ import { retireConstraint } from '../constraints-retire';
21
+ import { disableConstraint, constraintsDisable, printDisableResult } from '../constraints-disable';
22
+ import { createProjectFixture, writeProjectConfig } from '../../../test-setup/project-fixture';
23
+
24
+ const FIXED_NOW = new Date('2026-08-08T12:00:00.000Z');
25
+
26
+ function readConfig(root: string): any {
27
+ return yaml.load(fs.readFileSync(path.join(root, '.harness', 'config.yml'), 'utf-8'));
28
+ }
29
+
30
+ let io: CapturingIO;
31
+ beforeEach(() => {
32
+ io = captureIO();
33
+ // disable 不写沉淀——隔离知识库根以便断言「零沉淀」
34
+ process.env.KNOWLEDGE_BASE_DIR = fs.mkdtempSync(path.join(os.tmpdir(), 'harness-disable-kb-'));
35
+ });
36
+ afterEach(() => {
37
+ fs.rmSync(process.env.KNOWLEDGE_BASE_DIR!, { recursive: true, force: true });
38
+ delete process.env.KNOWLEDGE_BASE_DIR;
39
+ });
40
+
41
+ describe('disableConstraint 执行逻辑', () => {
42
+ it('禁用落盘:config.yml enabled:false 无 retired 段,约束离开生效集', () => {
43
+ const root = createProjectFixture({ name: 'harness-disable-test' });
44
+ expect(getEffectiveConstraints(root).some(c => c.id === 'capability_sync')).toBe(true);
45
+
46
+ const result = disableConstraint(root, 'capability_sync');
47
+
48
+ expect(result.status).toBe('disabled');
49
+ const entry = readConfig(root).constraints.capability_sync;
50
+ expect(entry.enabled).toBe(false);
51
+ expect(entry.retired).toBeUndefined();
52
+ expect(getEffectiveConstraints(root).some(c => c.id === 'capability_sync')).toBe(false);
53
+ });
54
+
55
+ it('零知识沉淀:disable 不写任何 KnowledgeStore 条目(沉淀是 retire 专有语义)', () => {
56
+ const root = createProjectFixture({ name: 'harness-disable-test' });
57
+
58
+ const result = disableConstraint(root, 'capability_sync');
59
+
60
+ expect(result.status).toBe('disabled');
61
+ const store = new FileKnowledgeStore({ baseDir: process.env.KNOWLEDGE_BASE_DIR! });
62
+ expect(store.list()).toHaveLength(0);
63
+ });
64
+
65
+ it('幂等:裸 enabled:false 已禁用 → already_disabled,配置原样不动', () => {
66
+ const root = createProjectFixture({
67
+ name: 'harness-disable-test',
68
+ config: 'constraints:\n capability_sync:\n enabled: false\n',
69
+ });
70
+ const before = fs.readFileSync(path.join(root, '.harness', 'config.yml'), 'utf-8');
71
+
72
+ const result = disableConstraint(root, 'capability_sync');
73
+
74
+ expect(result.status).toBe('already_disabled');
75
+ expect(fs.readFileSync(path.join(root, '.harness', 'config.yml'), 'utf-8')).toBe(before);
76
+ });
77
+
78
+ it('retired 墓碑不接管:already_retired,墓碑原样保留(disable 不吞 retire 语义)', () => {
79
+ const root = createProjectFixture({ name: 'harness-disable-test' });
80
+ retireConstraint(root, 'capability_sync', { reason: '先退', now: FIXED_NOW });
81
+
82
+ const result = disableConstraint(root, 'capability_sync');
83
+
84
+ expect(result.status).toBe('already_retired');
85
+ const entry = readConfig(root).constraints.capability_sync;
86
+ expect(entry.enabled).toBe(false);
87
+ expect(entry.retired).toBeDefined();
88
+ expect(entry.retired.reason).toBe('先退');
89
+ });
90
+
91
+ it('未知 id:unknown_id,不落盘任何文件', () => {
92
+ const root = createProjectFixture({ name: 'harness-disable-test' });
93
+
94
+ const result = disableConstraint(root, 'not_a_constraint');
95
+
96
+ expect(result.status).toBe('unknown_id');
97
+ expect(fs.existsSync(path.join(root, '.harness'))).toBe(false);
98
+ });
99
+
100
+ it('同文件其他约束条目不受影响', () => {
101
+ const root = createProjectFixture({
102
+ name: 'harness-disable-test',
103
+ config: 'constraints:\n docs_freshness:\n enabled: false\n',
104
+ });
105
+
106
+ const result = disableConstraint(root, 'capability_sync');
107
+
108
+ expect(result.status).toBe('disabled');
109
+ const config = readConfig(root);
110
+ expect(config.constraints.docs_freshness.enabled).toBe(false);
111
+ expect(config.constraints.capability_sync.enabled).toBe(false);
112
+ });
113
+
114
+ it('禁用结果打印:git 仓内附 commit 提示,非 git 目录不提示', () => {
115
+ const gitRoot = createProjectFixture({ name: 'harness-disable-test', files: { '.git/HEAD': 'ref: refs/heads/master\n' } });
116
+ printDisableResult(disableConstraint(gitRoot, 'capability_sync'), io, gitRoot);
117
+ expect(io.outText()).toContain('git add .harness/config.yml');
118
+
119
+ const plainRoot = createProjectFixture({ name: 'harness-disable-test' });
120
+ const plainIo = captureIO();
121
+ printDisableResult(disableConstraint(plainRoot, 'capability_sync'), plainIo, plainRoot);
122
+ expect(plainIo.outText()).not.toContain('git add');
123
+ });
124
+ });
125
+
126
+ describe('写后验证失败回滚(harness#190 AC:失败回滚)', () => {
127
+ afterEach(() => {
128
+ jest.restoreAllMocks();
129
+ });
130
+
131
+ it('生效集仍含该约束 → verify_failed,config.yml 恢复备份逐字节', () => {
132
+ const root = createProjectFixture({
133
+ name: 'harness-disable-test',
134
+ config: 'constraints:\n docs_freshness:\n enabled: false\n',
135
+ });
136
+ const before = fs.readFileSync(path.join(root, '.harness', 'config.yml'), 'utf-8');
137
+ // 强制验证失败:生效集仍含该 id(spy 只钉本用例,afterEach 恢复)
138
+ jest.spyOn(effectiveConstraints, 'getEffectiveConstraints').mockReturnValue([{ id: 'capability_sync' } as any]);
139
+
140
+ const result = disableConstraint(root, 'capability_sync');
141
+
142
+ expect(result.status).toBe('verify_failed');
143
+ expect(fs.readFileSync(path.join(root, '.harness', 'config.yml'), 'utf-8')).toBe(before);
144
+ });
145
+
146
+ it('原本无 config.yml → verify_failed 时删除新建文件,回到零落盘', () => {
147
+ const root = createProjectFixture({ name: 'harness-disable-test' });
148
+ jest.spyOn(effectiveConstraints, 'getEffectiveConstraints').mockReturnValue([{ id: 'capability_sync' } as any]);
149
+
150
+ const result = disableConstraint(root, 'capability_sync');
151
+
152
+ expect(result.status).toBe('verify_failed');
153
+ expect(fs.existsSync(path.join(root, '.harness', 'config.yml'))).toBe(false);
154
+ });
155
+
156
+ it('verify_failed 打印:fail kind + 回滚告知走 stderr', () => {
157
+ const cmdResult = printDisableResult({ id: 'capability_sync', status: 'verify_failed' }, io);
158
+ expect(cmdResult.kind).toBe('fail');
159
+ expect(io.errText()).toContain('已回滚');
160
+ });
161
+ });
162
+
163
+ describe('constraintsDisable 非交互直达', () => {
164
+ it('无 --yes 直达:报错 + 非零退出码 + 不落盘任何文件(人确认闸门)', async () => {
165
+ const root = createProjectFixture({ name: 'harness-disable-test' });
166
+
167
+ const result = await constraintsDisable('capability_sync', { projectPath: root }, io);
168
+
169
+ expect(io.errText()).toContain('--yes');
170
+ expect(result.kind).toBe('usage-error');
171
+ expect(fs.existsSync(path.join(root, '.harness'))).toBe(false);
172
+ expect(getEffectiveConstraints(root).some(c => c.id === 'capability_sync')).toBe(true);
173
+ });
174
+
175
+ it('--yes 直达禁用:落盘并打印结果', async () => {
176
+ const root = createProjectFixture({ name: 'harness-disable-test' });
177
+
178
+ const result = await constraintsDisable('capability_sync', { projectPath: root, yes: true }, io);
179
+
180
+ expect(result.kind).toBe('ok');
181
+ expect(io.outText()).toContain('已禁用');
182
+ expect(readConfig(root).constraints.capability_sync.enabled).toBe(false);
183
+ });
184
+
185
+ it('--yes 直达已禁用:幂等 skip', async () => {
186
+ const root = createProjectFixture({ name: 'harness-disable-test' });
187
+ writeProjectConfig(root, 'constraints:\n capability_sync:\n enabled: false\n');
188
+
189
+ const result = await constraintsDisable('capability_sync', { projectPath: root, yes: true }, io);
190
+
191
+ expect(result.kind).toBe('skip');
192
+ expect(io.outText()).toContain('已处于禁用状态');
193
+ });
194
+
195
+ it('缺 id:usage-error 提示用法', async () => {
196
+ const result = await constraintsDisable(undefined, { yes: true }, io);
197
+ expect(result.kind).toBe('usage-error');
198
+ expect(io.errText()).toContain('用法');
199
+ });
200
+ });
201
+
202
+ describe('应用层约束禁用(ADR-0033 同路径)', () => {
203
+ const APP_YML = [
204
+ 'constraints:',
205
+ ' - id: app_no_internal_url',
206
+ ' rule: Web code must not contain internal URLs',
207
+ ' checker: regex-scan',
208
+ ' params:',
209
+ " pattern: 'https?://10\\.'",
210
+ ' severity: warning',
211
+ '',
212
+ ].join('\n');
213
+
214
+ it('应用层 check 约束可禁用:config.yml enabled:false,离开生效集,constraints.yml 条文保留', () => {
215
+ const root = createProjectFixture({
216
+ name: 'harness-disable-test',
217
+ files: { [path.join('.harness', 'constraints.yml')]: APP_YML },
218
+ });
219
+ expect(getEffectiveConstraints(root).some(c => c.id === 'app_no_internal_url')).toBe(true);
220
+
221
+ const result = disableConstraint(root, 'app_no_internal_url');
222
+
223
+ expect(result.status).toBe('disabled');
224
+ expect(readConfig(root).constraints.app_no_internal_url.enabled).toBe(false);
225
+ expect(getEffectiveConstraints(root).some(c => c.id === 'app_no_internal_url')).toBe(false);
226
+ // 条文保留不删(禁用 = 停用不是删除)
227
+ expect(fs.readFileSync(path.join(root, '.harness', 'constraints.yml'), 'utf-8')).toBe(APP_YML);
228
+ });
229
+ });
@@ -7,7 +7,7 @@
7
7
  * `constraints report --json` 输出的仍是文本格式。
8
8
  *
9
9
  * 修法(计划允许二选一):子命令换名 --json-output。
10
- * 理由:父命令 --json 有活跃消费者(studio-agent 取约束 hash),
10
+ * 理由:父命令 --json 有活跃消费者(下游消费方取约束 hash),
11
11
  * 删除会静默降级其取数;子命令 --json 因本 bug 从未可达、零消费者,
12
12
  * 换名零破坏。
13
13
  *