@dommaker/harness 1.11.0 → 1.13.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 (157) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/cli/commands/constraints-pack-proposal.d.ts +48 -0
  3. package/dist/cli/commands/constraints-pack-proposal.d.ts.map +1 -0
  4. package/dist/cli/commands/constraints-pack-proposal.js +169 -0
  5. package/dist/cli/commands/constraints-pack-proposal.js.map +1 -0
  6. package/dist/cli/commands/constraints-reactivate.d.ts +55 -0
  7. package/dist/cli/commands/constraints-reactivate.d.ts.map +1 -0
  8. package/dist/cli/commands/constraints-reactivate.js +175 -0
  9. package/dist/cli/commands/constraints-reactivate.js.map +1 -0
  10. package/dist/cli/commands/constraints-report.d.ts +12 -1
  11. package/dist/cli/commands/constraints-report.d.ts.map +1 -1
  12. package/dist/cli/commands/constraints-report.js +35 -2
  13. package/dist/cli/commands/constraints-report.js.map +1 -1
  14. package/dist/cli/commands/constraints-retire.d.ts +49 -4
  15. package/dist/cli/commands/constraints-retire.d.ts.map +1 -1
  16. package/dist/cli/commands/constraints-retire.js +116 -34
  17. package/dist/cli/commands/constraints-retire.js.map +1 -1
  18. package/dist/cli/commands/definitions.d.ts.map +1 -1
  19. package/dist/cli/commands/definitions.js +31 -1
  20. package/dist/cli/commands/definitions.js.map +1 -1
  21. package/dist/cli/commands/knowledge-view.d.ts +6 -3
  22. package/dist/cli/commands/knowledge-view.d.ts.map +1 -1
  23. package/dist/cli/commands/knowledge-view.js +8 -26
  24. package/dist/cli/commands/knowledge-view.js.map +1 -1
  25. package/dist/cli/commands/report.d.ts.map +1 -1
  26. package/dist/cli/commands/report.js +9 -5
  27. package/dist/cli/commands/report.js.map +1 -1
  28. package/dist/cli/commands/security.d.ts +19 -0
  29. package/dist/cli/commands/security.d.ts.map +1 -1
  30. package/dist/cli/commands/security.js +105 -0
  31. package/dist/cli/commands/security.js.map +1 -1
  32. package/dist/cli/state-io.d.ts +8 -1
  33. package/dist/cli/state-io.d.ts.map +1 -1
  34. package/dist/cli/state-io.js +2 -1
  35. package/dist/cli/state-io.js.map +1 -1
  36. package/dist/core/app-constraints-loader.d.ts +28 -0
  37. package/dist/core/app-constraints-loader.d.ts.map +1 -0
  38. package/dist/core/app-constraints-loader.js +187 -0
  39. package/dist/core/app-constraints-loader.js.map +1 -0
  40. package/dist/core/constraints/checker.js +1 -1
  41. package/dist/core/constraints/checker.js.map +1 -1
  42. package/dist/core/constraints/checkers/index.d.ts +20 -9
  43. package/dist/core/constraints/checkers/index.d.ts.map +1 -1
  44. package/dist/core/constraints/checkers/index.js +40 -11
  45. package/dist/core/constraints/checkers/index.js.map +1 -1
  46. package/dist/core/constraints/checkers/templated/file-exists.d.ts +16 -0
  47. package/dist/core/constraints/checkers/templated/file-exists.d.ts.map +1 -0
  48. package/dist/core/constraints/checkers/templated/file-exists.js +108 -0
  49. package/dist/core/constraints/checkers/templated/file-exists.js.map +1 -0
  50. package/dist/core/constraints/checkers/templated/glob.d.ts +10 -0
  51. package/dist/core/constraints/checkers/templated/glob.d.ts.map +1 -0
  52. package/dist/core/constraints/checkers/templated/glob.js +51 -0
  53. package/dist/core/constraints/checkers/templated/glob.js.map +1 -0
  54. package/dist/core/constraints/checkers/templated/index.d.ts +12 -0
  55. package/dist/core/constraints/checkers/templated/index.d.ts.map +1 -0
  56. package/dist/core/constraints/checkers/templated/index.js +17 -0
  57. package/dist/core/constraints/checkers/templated/index.js.map +1 -0
  58. package/dist/core/constraints/checkers/templated/regex-scan.d.ts +15 -0
  59. package/dist/core/constraints/checkers/templated/regex-scan.d.ts.map +1 -0
  60. package/dist/core/constraints/checkers/templated/regex-scan.js +129 -0
  61. package/dist/core/constraints/checkers/templated/regex-scan.js.map +1 -0
  62. package/dist/core/constraints/checkers/templates-registry.d.ts +17 -0
  63. package/dist/core/constraints/checkers/templates-registry.d.ts.map +1 -0
  64. package/dist/core/constraints/checkers/templates-registry.js +23 -0
  65. package/dist/core/constraints/checkers/templates-registry.js.map +1 -0
  66. package/dist/core/constraints/checkers/types.d.ts +14 -0
  67. package/dist/core/constraints/checkers/types.d.ts.map +1 -1
  68. package/dist/core/constraints/checkers/types.js.map +1 -1
  69. package/dist/core/constraints/definitions/guidelines.d.ts.map +1 -1
  70. package/dist/core/constraints/definitions/guidelines.js +0 -14
  71. package/dist/core/constraints/definitions/guidelines.js.map +1 -1
  72. package/dist/core/constraints/definitions/iron-laws.d.ts.map +1 -1
  73. package/dist/core/constraints/definitions/iron-laws.js +15 -0
  74. package/dist/core/constraints/definitions/iron-laws.js.map +1 -1
  75. package/dist/core/constraints/usage-report.d.ts +58 -6
  76. package/dist/core/constraints/usage-report.d.ts.map +1 -1
  77. package/dist/core/constraints/usage-report.js +61 -12
  78. package/dist/core/constraints/usage-report.js.map +1 -1
  79. package/dist/core/project-config-loader.d.ts +9 -6
  80. package/dist/core/project-config-loader.d.ts.map +1 -1
  81. package/dist/core/project-config-loader.js +18 -8
  82. package/dist/core/project-config-loader.js.map +1 -1
  83. package/dist/gates/command.d.ts +5 -1
  84. package/dist/gates/command.d.ts.map +1 -1
  85. package/dist/gates/command.js +56 -2
  86. package/dist/gates/command.js.map +1 -1
  87. package/dist/gates/definitions.d.ts.map +1 -1
  88. package/dist/gates/definitions.js +6 -1
  89. package/dist/gates/definitions.js.map +1 -1
  90. package/dist/knowledge/lifecycle.d.ts +14 -0
  91. package/dist/knowledge/lifecycle.d.ts.map +1 -1
  92. package/dist/knowledge/lifecycle.js +50 -0
  93. package/dist/knowledge/lifecycle.js.map +1 -1
  94. package/dist/presets/standard.d.ts +1 -1
  95. package/dist/presets/standard.d.ts.map +1 -1
  96. package/dist/presets/standard.js +2 -3
  97. package/dist/presets/standard.js.map +1 -1
  98. package/dist/pretool-use-hook.d.ts +13 -4
  99. package/dist/pretool-use-hook.d.ts.map +1 -1
  100. package/dist/pretool-use-hook.js +89 -8
  101. package/dist/pretool-use-hook.js.map +1 -1
  102. package/dist/types/constraint.d.ts +24 -0
  103. package/dist/types/constraint.d.ts.map +1 -1
  104. package/dist/types/constraint.js.map +1 -1
  105. package/package.json +1 -1
  106. package/src/CONTEXT.md +1 -1
  107. package/src/__tests__/app-constraints-loader.test.ts +220 -0
  108. package/src/__tests__/iron-laws.test.ts +5 -5
  109. package/src/__tests__/layering.test.ts +3 -1
  110. package/src/__tests__/pretool-use-hook.test.ts +211 -4
  111. package/src/cli/commands/CONTEXT.md +4 -3
  112. package/src/cli/commands/__tests__/check.test.ts +22 -4
  113. package/src/cli/commands/__tests__/constraints-pack-proposal.test.ts +142 -0
  114. package/src/cli/commands/__tests__/constraints-reactivate.test.ts +210 -0
  115. package/src/cli/commands/__tests__/constraints-report.test.ts +175 -6
  116. package/src/cli/commands/__tests__/constraints-retire.test.ts +135 -10
  117. package/src/cli/commands/__tests__/knowledge.test.ts +6 -16
  118. package/src/cli/commands/__tests__/report-app-constraints.test.ts +67 -0
  119. package/src/cli/commands/__tests__/security.test.ts +89 -1
  120. package/src/cli/commands/constraints-pack-proposal.ts +172 -0
  121. package/src/cli/commands/constraints-reactivate.ts +197 -0
  122. package/src/cli/commands/constraints-report.ts +44 -2
  123. package/src/cli/commands/constraints-retire.ts +129 -36
  124. package/src/cli/commands/definitions.ts +31 -1
  125. package/src/cli/commands/knowledge-view.ts +9 -28
  126. package/src/cli/commands/report.ts +9 -5
  127. package/src/cli/commands/security.ts +99 -0
  128. package/src/cli/state-io.ts +8 -1
  129. package/src/core/CONTEXT.md +5 -4
  130. package/src/core/app-constraints-loader.ts +165 -0
  131. package/src/core/constraints/__tests__/collect-constraints.test.ts +3 -1
  132. package/src/core/constraints/__tests__/usage-report.test.ts +63 -0
  133. package/src/core/constraints/checker.ts +1 -1
  134. package/src/core/constraints/checkers/__tests__/templated-checkers.test.ts +180 -0
  135. package/src/core/constraints/checkers/__tests__/templates-registry.test.ts +81 -0
  136. package/src/core/constraints/checkers/index.ts +44 -10
  137. package/src/core/constraints/checkers/templated/file-exists.ts +75 -0
  138. package/src/core/constraints/checkers/templated/glob.ts +46 -0
  139. package/src/core/constraints/checkers/templated/index.ts +12 -0
  140. package/src/core/constraints/checkers/templated/regex-scan.ts +132 -0
  141. package/src/core/constraints/checkers/templates-registry.ts +22 -0
  142. package/src/core/constraints/checkers/types.ts +15 -0
  143. package/src/core/constraints/definitions/guidelines.ts +0 -15
  144. package/src/core/constraints/definitions/iron-laws.ts +16 -0
  145. package/src/core/constraints/usage-report.ts +128 -13
  146. package/src/core/project-config-loader.ts +19 -8
  147. package/src/gates/CONTEXT.md +2 -2
  148. package/src/gates/__tests__/command.test.ts +54 -0
  149. package/src/gates/command.ts +57 -2
  150. package/src/gates/definitions.ts +6 -1
  151. package/src/knowledge/CONTEXT.md +3 -1
  152. package/src/knowledge/__tests__/lifecycle.test.ts +81 -0
  153. package/src/knowledge/lifecycle.ts +49 -0
  154. package/src/presets/__tests__/standard.test.ts +5 -4
  155. package/src/presets/standard.ts +2 -3
  156. package/src/pretool-use-hook.ts +104 -10
  157. package/src/types/constraint.ts +28 -0
@@ -199,8 +199,10 @@ export class KnowledgeLifecycle {
199
199
  this.store.update(entryId, { maturity: target });
200
200
 
201
201
  // AC-8a: After promotion, check skillCandidate eligibility
202
+ // 块 3 子项 6(ADR-0033):同位触发 constraintCandidate 判定——两标独立,可同挂
202
203
  if (target === 'proven') {
203
204
  this.checkSkillCandidate(entryId);
205
+ this.checkConstraintCandidate(entryId);
204
206
  }
205
207
 
206
208
  return change;
@@ -253,6 +255,53 @@ export class KnowledgeLifecycle {
253
255
  return true;
254
256
  }
255
257
 
258
+ /**
259
+ * 块 3 子项 6(ADR-0033):Check if a proven entry qualifies as a constraintCandidate.
260
+ * Marks with 'constraintCandidate' tag and emits event if eligible.
261
+ * Returns true if newly marked.
262
+ *
263
+ * 判定口径(人类已批准,设计稿 Q4):proven + 未打过标 + references≥5
264
+ * (referencedBy 条数,与 recordReference 的 refKey 口径一致)+ ≥3 个不同来源会话
265
+ * (contributors,与 skill 候选同字段)。与 skillCandidate 互不干扰,可同挂两标。
266
+ */
267
+ checkConstraintCandidate(entryId: string): boolean {
268
+ const entry = this.store.get(entryId);
269
+ if (!entry) return false;
270
+ if (!this.isConstraintCandidate(entry)) return false;
271
+
272
+ // Mark as constraintCandidate
273
+ this.store.update(entryId, {
274
+ tags: [...entry.tags, 'constraintCandidate'],
275
+ });
276
+
277
+ // Emit event for downstream consumers
278
+ const now = new Date().toISOString();
279
+ for (const cb of this.onReferenceCallbacks) {
280
+ try {
281
+ cb({
282
+ entryId,
283
+ contributor: 'lifecycle',
284
+ timestamp: now,
285
+ context: 'constraintCandidate:marked',
286
+ });
287
+ } catch { /* non-blocking */ }
288
+ }
289
+
290
+ return true;
291
+ }
292
+
293
+ /**
294
+ * 块 3 子项 6:Check if an entry meets constraintCandidate criteria.
295
+ */
296
+ private isConstraintCandidate(entry: KnowledgeEntry): boolean {
297
+ if (entry.maturity !== 'proven') return false;
298
+ if (entry.tags.includes('constraintCandidate')) return false;
299
+ if (entry.referencedBy.length < 5) return false;
300
+ if (entry.contributors.length < 3) return false;
301
+
302
+ return true;
303
+ }
304
+
256
305
  /**
257
306
  * AC-8c: Remove skillCandidate tag if success rate drops below 50%.
258
307
  * Called after execution writeback.
@@ -32,16 +32,17 @@ describe('预设数据', () => {
32
32
  describe('RELAXED_PRESET', () => {
33
33
  it('应该只启用核心约束', () => {
34
34
  expect(RELAXED_PRESET.name).toBe('relaxed');
35
- expect(RELAXED_PRESET.errors).toHaveLength(1);
36
- expect(RELAXED_PRESET.warnings).toHaveLength(1);
35
+ expect(RELAXED_PRESET.errors).toHaveLength(2);
36
+ expect(RELAXED_PRESET.warnings).toHaveLength(0);
37
37
  });
38
38
 
39
39
  it('应该包含 no_completion_without_verification', () => {
40
40
  expect(RELAXED_PRESET.errors).toContain('no_completion_without_verification');
41
41
  });
42
42
 
43
- it('应该包含 no_hardcoded_credentials', () => {
44
- expect(RELAXED_PRESET.warnings).toContain('no_hardcoded_credentials');
43
+ it('应该包含 no_hardcoded_credentials(ADR-0032 起为 error 级,同桶)', () => {
44
+ expect(RELAXED_PRESET.errors).toContain('no_hardcoded_credentials');
45
+ expect(RELAXED_PRESET.warnings).toEqual([]);
45
46
  });
46
47
  });
47
48
 
@@ -47,16 +47,15 @@ export const STANDARD_PRESET: PresetConfig = {
47
47
  /**
48
48
  * 宽松预设
49
49
  *
50
- * 仅启用核心 error 级与凭证扫描
50
+ * 仅启用核心 error 级与凭证扫描(ADR-0032 起凭证扫描为 error 级,同桶)
51
51
  */
52
52
  export const RELAXED_PRESET: PresetConfig = {
53
53
  name: 'relaxed',
54
54
  errors: [
55
55
  'no_completion_without_verification',
56
- ],
57
- warnings: [
58
56
  'no_hardcoded_credentials',
59
57
  ],
58
+ warnings: [],
60
59
  };
61
60
 
62
61
  /**
@@ -9,39 +9,132 @@
9
9
  *
10
10
  * 语义(与生成版一致):
11
11
  * - stdin 收 provider PreToolUse JSON(tool_input.command);
12
- * - CommandGate.isAllowed 判定 block 级黑名单,命中 → stderr 写原因 + exit 2
12
+ * - CommandGate 判定 block 级黑名单,命中 → stderr 写原因 + exit 2
13
13
  * (codex/kimi 阻断语义:exit 2 + stderr 阻断,其余 exit code fail-open);
14
14
  * - fail-open:stdin 非 JSON / 缺字段 / CommandGate 异常一律放行——宁可漏拦
15
15
  * 也不全体 Bash 秒断,拦截层只是纵深防御的一道;
16
- * - warn/audit 级命中同样放行(isAllowed 只看 block 级),与生成版行为一致。
16
+ * - warn/audit 级命中同样放行(只拦 block 级),与生成版行为一致。
17
+ *
18
+ * P1-7(ADR-0031,wayfinder 票08):判定后对命中写审计 trace(只记账不加新拦截
19
+ * 能力)——此前拦下/放行的危险命令只写 stderr 不落盘,traces.log 里只有约束检查
20
+ * 在写。留痕失败经 try/catch 吞掉,fail-open 口径与 shim 主路径一致。
21
+ *
22
+ * P1-5 harness 半边(ADR-0031,wayfinder 票08):识别 tool_name 非 Bash 的事件
23
+ * (Edit/Write/apply_patch/MCP 工具,studio 侧补全 codex hooks matcher 后会到达),
24
+ * 只留痕不拦截——这些事件的 tool_input 没有 command 字段,旧形状会因缺字段
25
+ * fail-open 空转;拦截归 codex 沙箱,本 shim 对它们只记账。
17
26
  */
18
27
  import { CommandGate } from './gates/command';
28
+ import type { CommandBlacklistRule } from './gates/types';
29
+ import { TraceCollector } from './monitoring/traces';
19
30
 
20
31
  /** hook 标识:与 studio-agent 生成版同一 marker(配置幂等检测共用口径) */
21
32
  export const HOOK_MARKER = 'harness-command-gate';
22
33
 
23
34
  interface PreToolUseInput {
24
- tool_input?: { command?: string };
35
+ tool_name?: string;
36
+ tool_input?: { command?: string; file_path?: string };
37
+ }
38
+
39
+ /** 一次 PreToolUse 的判定结果:放行结论 + 命中明细(hits 供审计留痕) */
40
+ export interface PreToolUseDecision {
41
+ allowed: boolean;
42
+ command: string;
43
+ hits: CommandBlacklistRule[];
44
+ /** provider 工具名(缺省按 Bash 兼容旧事件形状) */
45
+ toolName: string;
46
+ /** 非 Bash 事件的目标路径类字段(file_path;不记内容正文) */
47
+ targetPath?: string;
25
48
  }
26
49
 
27
50
  /**
28
51
  * 判定一次 PreToolUse 是否放行。
29
52
  * block 级命中 → allowed=false;warn/audit/干净命令/坏输入一律 allowed=true。
53
+ * 非 Bash 工具事件(Edit/Write/apply_patch/MCP)恒放行(P1-5:拦截归 codex 沙箱)。
30
54
  */
31
- export function decidePreToolUse(rawStdin: string): { allowed: boolean; command: string } {
55
+ export function decidePreToolUse(rawStdin: string): PreToolUseDecision {
32
56
  let input: PreToolUseInput = {};
33
57
  try {
34
58
  input = JSON.parse(rawStdin || '{}') as PreToolUseInput;
35
59
  } catch {
36
60
  // 非 JSON stdin:放行
37
61
  }
38
- const command = (input.tool_input && input.tool_input.command) || '';
62
+ const toolName = input.tool_name || 'Bash';
63
+ const toolInput = input.tool_input || {};
64
+ if (toolName !== 'Bash') {
65
+ return { allowed: true, command: '', hits: [], toolName, targetPath: toolInput.file_path };
66
+ }
67
+ const command = toolInput.command || '';
39
68
  try {
40
69
  const gate = new CommandGate();
41
- return { allowed: gate.isAllowed(command), command };
70
+ // 与 isAllowed 同一谓词(match):allowed = 无 block 级命中
71
+ const hits = gate.match(command);
72
+ return { allowed: !hits.some((r) => r.level === 'block'), command, hits, toolName };
42
73
  } catch {
43
74
  // CommandGate 加载/判定异常:fail-open
44
- return { allowed: true, command };
75
+ return { allowed: true, command, hits: [], toolName };
76
+ }
77
+ }
78
+
79
+ /** 黑名单级别 → trace severity 映射(词表不动 types/trace.ts) */
80
+ const SEVERITY_BY_LEVEL = {
81
+ block: 'error',
82
+ warn: 'warning',
83
+ audit: 'info',
84
+ } as const;
85
+
86
+ /**
87
+ * 判定留痕:非 Bash 工具事件一条 `tool-event:<tool>`(P1-5),Bash 命中一条
88
+ * 汇总 trace(P1-7)。
89
+ *
90
+ * 口径选择记理由:
91
+ * - constraintId 用汇总的 'command-gate' 而非每规则 'command-gate:<ruleId>'——
92
+ * usage-report 按 constraintId 聚合,逐规则会碎成几十个近零样本 id,
93
+ * 污染退役候选诊断;规则明细进 evidence。
94
+ * - evidence 只记规则 id + 命令首 token,不记完整命令文本——命令可能含敏感参数
95
+ * (token/路径),首 token 足以定位命令类别。
96
+ * - 隐式依赖:TraceCollector 缺省按 cwd 解析 projectPath,hook 进程 cwd 通常是
97
+ * 项目根(provider 在项目根起会话),可接受;写错地方也不拦主路径。
98
+ */
99
+ function recordHookTrace(decision: PreToolUseDecision): void {
100
+ try {
101
+ // P1-5:非 Bash 工具事件只留痕不拦截(拦截归 codex 沙箱)——constraintId
102
+ // 按工具名分(tool-event:<tool>),工具集合有界、不会碎片化聚合;evidence
103
+ // 记工具名 + 目标路径类字段(file_path),不记内容正文。
104
+ if (decision.toolName !== 'Bash') {
105
+ new TraceCollector().record({
106
+ constraintId: `tool-event:${decision.toolName}`,
107
+ severity: 'info',
108
+ timestamp: Date.now(),
109
+ result: 'pass',
110
+ operation: 'pretool-use-hook',
111
+ evidence: [
112
+ `tool:${decision.toolName}`,
113
+ ...(decision.targetPath ? [`path:${decision.targetPath}`] : []),
114
+ ],
115
+ });
116
+ return;
117
+ }
118
+ if (decision.hits.length === 0) return;
119
+ const maxLevel = decision.hits.some((r) => r.level === 'block')
120
+ ? 'block'
121
+ : decision.hits.some((r) => r.level === 'warn')
122
+ ? 'warn'
123
+ : 'audit';
124
+ const firstToken = decision.command.trim().split(/\s+/)[0] || '';
125
+ new TraceCollector().record({
126
+ constraintId: 'command-gate',
127
+ severity: SEVERITY_BY_LEVEL[maxLevel],
128
+ timestamp: Date.now(),
129
+ result: decision.allowed ? 'pass' : 'fail',
130
+ operation: 'pretool-use-hook',
131
+ evidence: [
132
+ ...decision.hits.map((r) => `rule:${r.id}`),
133
+ ...(firstToken ? [`cmd:${firstToken}`] : []),
134
+ ],
135
+ });
136
+ } catch {
137
+ // 留痕失败不影响拦截主路径(fail-open 口径与 shim 一致)
45
138
  }
46
139
  }
47
140
 
@@ -50,9 +143,10 @@ export function decidePreToolUse(rawStdin: string): { allowed: boolean; command:
50
143
  * 阻断时原因写 stderr(provider 把 stderr 作为阻断原因回填模型)。
51
144
  */
52
145
  export function runPreToolUseHook(rawStdin: string): number {
53
- const { allowed, command } = decidePreToolUse(rawStdin);
54
- if (!allowed) {
55
- console.error(`[${HOOK_MARKER}] blocked: ${command}`);
146
+ const decision = decidePreToolUse(rawStdin);
147
+ recordHookTrace(decision);
148
+ if (!decision.allowed) {
149
+ console.error(`[${HOOK_MARKER}] blocked: ${decision.command}`);
56
150
  return 2;
57
151
  }
58
152
  return 0;
@@ -32,6 +32,15 @@ export type ConstraintSeverity = 'error' | 'warning' | 'info';
32
32
  */
33
33
  export type ConstraintTrigger = string;
34
34
 
35
+ /**
36
+ * 约束来源(ADR-0033 两层约束模型)
37
+ *
38
+ * - builtin:内置约束(definitions/ 字面量定义,checker 按约束 id 注册查找)
39
+ * - app:应用层约束(应用仓 `.harness/constraints.yml` 定义,checker 按模板 id +
40
+ * params 实例化);缺省 builtin
41
+ */
42
+ export type ConstraintSource = 'builtin' | 'app';
43
+
35
44
  /**
36
45
  * 约束定义
37
46
  */
@@ -65,6 +74,25 @@ export interface Constraint {
65
74
 
66
75
  /** 是否启用 */
67
76
  enabled?: boolean;
77
+
78
+ /**
79
+ * 约束来源(ADR-0033):缺省 builtin
80
+ *
81
+ * app = 应用层约束(应用仓 `.harness/constraints.yml` 定义);
82
+ * report/退休/提案据此区分来源
83
+ */
84
+ source?: ConstraintSource;
85
+
86
+ /**
87
+ * 填空式 checker 模板 id(仅 source='app' 使用)
88
+ *
89
+ * 内置约束省略 = checker 按约束 id 在内置注册表查找;应用层约束按模板 id
90
+ * 在模板注册表(checkers/index.ts TEMPLATES)查找并带 params 实例化
91
+ */
92
+ checker?: string;
93
+
94
+ /** 模板参数(仅 source='app' 使用,形状由各模板的 validateParams 校验) */
95
+ params?: Record<string, unknown>;
68
96
  }
69
97
 
70
98
  /**