@erzhe/harness-kit 0.4.1 → 0.5.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.
@@ -4942,9 +4942,9 @@ var require_picomatch = __commonJS({
4942
4942
  var utils = require_utils();
4943
4943
  var constants3 = require_constants();
4944
4944
  var isObject = (val) => val && typeof val === "object" && !Array.isArray(val);
4945
- var picomatch3 = (glob, options, returnState = false) => {
4945
+ var picomatch4 = (glob, options, returnState = false) => {
4946
4946
  if (Array.isArray(glob)) {
4947
- const fns = glob.map((input) => picomatch3(input, options, returnState));
4947
+ const fns = glob.map((input) => picomatch4(input, options, returnState));
4948
4948
  const arrayMatcher = (str) => {
4949
4949
  for (const isMatch of fns) {
4950
4950
  const state2 = isMatch(str);
@@ -4960,16 +4960,16 @@ var require_picomatch = __commonJS({
4960
4960
  }
4961
4961
  const opts = options || {};
4962
4962
  const posix = opts.windows;
4963
- const regex = isState ? picomatch3.compileRe(glob, options) : picomatch3.makeRe(glob, options, false, true);
4963
+ const regex = isState ? picomatch4.compileRe(glob, options) : picomatch4.makeRe(glob, options, false, true);
4964
4964
  const state = regex.state;
4965
4965
  delete regex.state;
4966
4966
  let isIgnored = () => false;
4967
4967
  if (opts.ignore) {
4968
4968
  const ignoreOpts = { ...options, ignore: null, onMatch: null, onResult: null };
4969
- isIgnored = picomatch3(opts.ignore, ignoreOpts, returnState);
4969
+ isIgnored = picomatch4(opts.ignore, ignoreOpts, returnState);
4970
4970
  }
4971
4971
  const matcher = (input, returnObject = false) => {
4972
- const { isMatch, match, output } = picomatch3.test(input, regex, options, { glob, posix });
4972
+ const { isMatch, match, output } = picomatch4.test(input, regex, options, { glob, posix });
4973
4973
  const result = { glob, state, regex, posix, input, output, match, isMatch };
4974
4974
  if (typeof opts.onResult === "function") {
4975
4975
  opts.onResult(result);
@@ -4995,7 +4995,7 @@ var require_picomatch = __commonJS({
4995
4995
  }
4996
4996
  return matcher;
4997
4997
  };
4998
- picomatch3.test = (input, regex, options, { glob, posix } = {}) => {
4998
+ picomatch4.test = (input, regex, options, { glob, posix } = {}) => {
4999
4999
  if (typeof input !== "string") {
5000
5000
  throw new TypeError("Expected input to be a string");
5001
5001
  }
@@ -5012,24 +5012,24 @@ var require_picomatch = __commonJS({
5012
5012
  }
5013
5013
  if (match === false || opts.capture === true) {
5014
5014
  if (opts.matchBase === true || opts.basename === true) {
5015
- match = picomatch3.matchBase(input, regex, options, posix);
5015
+ match = picomatch4.matchBase(input, regex, options, posix);
5016
5016
  } else {
5017
5017
  match = regex.exec(output);
5018
5018
  }
5019
5019
  }
5020
5020
  return { isMatch: Boolean(match), match, output };
5021
5021
  };
5022
- picomatch3.matchBase = (input, glob, options, posix = options && options.windows) => {
5023
- const regex = glob instanceof RegExp ? glob : picomatch3.makeRe(glob, options);
5022
+ picomatch4.matchBase = (input, glob, options, posix = options && options.windows) => {
5023
+ const regex = glob instanceof RegExp ? glob : picomatch4.makeRe(glob, options);
5024
5024
  return regex.test(utils.basename(input, { windows: posix }));
5025
5025
  };
5026
- picomatch3.isMatch = (str, patterns, options) => picomatch3(patterns, options)(str);
5027
- picomatch3.parse = (pattern, options) => {
5028
- if (Array.isArray(pattern)) return pattern.map((p) => picomatch3.parse(p, options));
5026
+ picomatch4.isMatch = (str, patterns, options) => picomatch4(patterns, options)(str);
5027
+ picomatch4.parse = (pattern, options) => {
5028
+ if (Array.isArray(pattern)) return pattern.map((p) => picomatch4.parse(p, options));
5029
5029
  return parse(pattern, { ...options, fastpaths: false });
5030
5030
  };
5031
- picomatch3.scan = (input, options) => scan(input, options);
5032
- picomatch3.compileRe = (state, options, returnOutput = false, returnState = false) => {
5031
+ picomatch4.scan = (input, options) => scan(input, options);
5032
+ picomatch4.compileRe = (state, options, returnOutput = false, returnState = false) => {
5033
5033
  if (returnOutput === true) {
5034
5034
  return state.output;
5035
5035
  }
@@ -5040,13 +5040,13 @@ var require_picomatch = __commonJS({
5040
5040
  if (state && state.negated === true) {
5041
5041
  source = `^(?!${source}).*$`;
5042
5042
  }
5043
- const regex = picomatch3.toRegex(source, options);
5043
+ const regex = picomatch4.toRegex(source, options);
5044
5044
  if (returnState === true) {
5045
5045
  regex.state = state;
5046
5046
  }
5047
5047
  return regex;
5048
5048
  };
5049
- picomatch3.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
5049
+ picomatch4.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
5050
5050
  if (!input || typeof input !== "string") {
5051
5051
  throw new TypeError("Expected a non-empty string");
5052
5052
  }
@@ -5057,9 +5057,9 @@ var require_picomatch = __commonJS({
5057
5057
  if (!parsed.output) {
5058
5058
  parsed = parse(input, options);
5059
5059
  }
5060
- return picomatch3.compileRe(parsed, options, returnOutput, returnState);
5060
+ return picomatch4.compileRe(parsed, options, returnOutput, returnState);
5061
5061
  };
5062
- picomatch3.toRegex = (source, options) => {
5062
+ picomatch4.toRegex = (source, options) => {
5063
5063
  try {
5064
5064
  const opts = options || {};
5065
5065
  return new RegExp(source, opts.flags || (opts.nocase ? "i" : ""));
@@ -5068,8 +5068,8 @@ var require_picomatch = __commonJS({
5068
5068
  return /$^/;
5069
5069
  }
5070
5070
  };
5071
- picomatch3.constants = constants3;
5072
- module2.exports = picomatch3;
5071
+ picomatch4.constants = constants3;
5072
+ module2.exports = picomatch4;
5073
5073
  }
5074
5074
  });
5075
5075
 
@@ -5079,14 +5079,14 @@ var require_picomatch2 = __commonJS({
5079
5079
  "use strict";
5080
5080
  var pico = require_picomatch();
5081
5081
  var utils = require_utils();
5082
- function picomatch3(glob, options, returnState = false) {
5082
+ function picomatch4(glob, options, returnState = false) {
5083
5083
  if (options && (options.windows === null || options.windows === void 0)) {
5084
5084
  options = { ...options, windows: utils.isWindows() };
5085
5085
  }
5086
5086
  return pico(glob, options, returnState);
5087
5087
  }
5088
- Object.assign(picomatch3, pico);
5089
- module2.exports = picomatch3;
5088
+ Object.assign(picomatch4, pico);
5089
+ module2.exports = picomatch4;
5090
5090
  }
5091
5091
  });
5092
5092
 
@@ -15398,9 +15398,9 @@ var require_picomatch3 = __commonJS({
15398
15398
  var utils = require_utils3();
15399
15399
  var constants3 = require_constants3();
15400
15400
  var isObject = (val) => val && typeof val === "object" && !Array.isArray(val);
15401
- var picomatch3 = (glob, options, returnState = false) => {
15401
+ var picomatch4 = (glob, options, returnState = false) => {
15402
15402
  if (Array.isArray(glob)) {
15403
- const fns = glob.map((input) => picomatch3(input, options, returnState));
15403
+ const fns = glob.map((input) => picomatch4(input, options, returnState));
15404
15404
  const arrayMatcher = (str) => {
15405
15405
  for (const isMatch of fns) {
15406
15406
  const state2 = isMatch(str);
@@ -15416,16 +15416,16 @@ var require_picomatch3 = __commonJS({
15416
15416
  }
15417
15417
  const opts = options || {};
15418
15418
  const posix = utils.isWindows(options);
15419
- const regex = isState ? picomatch3.compileRe(glob, options) : picomatch3.makeRe(glob, options, false, true);
15419
+ const regex = isState ? picomatch4.compileRe(glob, options) : picomatch4.makeRe(glob, options, false, true);
15420
15420
  const state = regex.state;
15421
15421
  delete regex.state;
15422
15422
  let isIgnored = () => false;
15423
15423
  if (opts.ignore) {
15424
15424
  const ignoreOpts = { ...options, ignore: null, onMatch: null, onResult: null };
15425
- isIgnored = picomatch3(opts.ignore, ignoreOpts, returnState);
15425
+ isIgnored = picomatch4(opts.ignore, ignoreOpts, returnState);
15426
15426
  }
15427
15427
  const matcher = (input, returnObject = false) => {
15428
- const { isMatch, match, output } = picomatch3.test(input, regex, options, { glob, posix });
15428
+ const { isMatch, match, output } = picomatch4.test(input, regex, options, { glob, posix });
15429
15429
  const result = { glob, state, regex, posix, input, output, match, isMatch };
15430
15430
  if (typeof opts.onResult === "function") {
15431
15431
  opts.onResult(result);
@@ -15451,7 +15451,7 @@ var require_picomatch3 = __commonJS({
15451
15451
  }
15452
15452
  return matcher;
15453
15453
  };
15454
- picomatch3.test = (input, regex, options, { glob, posix } = {}) => {
15454
+ picomatch4.test = (input, regex, options, { glob, posix } = {}) => {
15455
15455
  if (typeof input !== "string") {
15456
15456
  throw new TypeError("Expected input to be a string");
15457
15457
  }
@@ -15468,24 +15468,24 @@ var require_picomatch3 = __commonJS({
15468
15468
  }
15469
15469
  if (match === false || opts.capture === true) {
15470
15470
  if (opts.matchBase === true || opts.basename === true) {
15471
- match = picomatch3.matchBase(input, regex, options, posix);
15471
+ match = picomatch4.matchBase(input, regex, options, posix);
15472
15472
  } else {
15473
15473
  match = regex.exec(output);
15474
15474
  }
15475
15475
  }
15476
15476
  return { isMatch: Boolean(match), match, output };
15477
15477
  };
15478
- picomatch3.matchBase = (input, glob, options, posix = utils.isWindows(options)) => {
15479
- const regex = glob instanceof RegExp ? glob : picomatch3.makeRe(glob, options);
15478
+ picomatch4.matchBase = (input, glob, options, posix = utils.isWindows(options)) => {
15479
+ const regex = glob instanceof RegExp ? glob : picomatch4.makeRe(glob, options);
15480
15480
  return regex.test(path.basename(input));
15481
15481
  };
15482
- picomatch3.isMatch = (str, patterns, options) => picomatch3(patterns, options)(str);
15483
- picomatch3.parse = (pattern, options) => {
15484
- if (Array.isArray(pattern)) return pattern.map((p) => picomatch3.parse(p, options));
15482
+ picomatch4.isMatch = (str, patterns, options) => picomatch4(patterns, options)(str);
15483
+ picomatch4.parse = (pattern, options) => {
15484
+ if (Array.isArray(pattern)) return pattern.map((p) => picomatch4.parse(p, options));
15485
15485
  return parse(pattern, { ...options, fastpaths: false });
15486
15486
  };
15487
- picomatch3.scan = (input, options) => scan(input, options);
15488
- picomatch3.compileRe = (state, options, returnOutput = false, returnState = false) => {
15487
+ picomatch4.scan = (input, options) => scan(input, options);
15488
+ picomatch4.compileRe = (state, options, returnOutput = false, returnState = false) => {
15489
15489
  if (returnOutput === true) {
15490
15490
  return state.output;
15491
15491
  }
@@ -15496,13 +15496,13 @@ var require_picomatch3 = __commonJS({
15496
15496
  if (state && state.negated === true) {
15497
15497
  source = `^(?!${source}).*$`;
15498
15498
  }
15499
- const regex = picomatch3.toRegex(source, options);
15499
+ const regex = picomatch4.toRegex(source, options);
15500
15500
  if (returnState === true) {
15501
15501
  regex.state = state;
15502
15502
  }
15503
15503
  return regex;
15504
15504
  };
15505
- picomatch3.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
15505
+ picomatch4.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
15506
15506
  if (!input || typeof input !== "string") {
15507
15507
  throw new TypeError("Expected a non-empty string");
15508
15508
  }
@@ -15513,9 +15513,9 @@ var require_picomatch3 = __commonJS({
15513
15513
  if (!parsed.output) {
15514
15514
  parsed = parse(input, options);
15515
15515
  }
15516
- return picomatch3.compileRe(parsed, options, returnOutput, returnState);
15516
+ return picomatch4.compileRe(parsed, options, returnOutput, returnState);
15517
15517
  };
15518
- picomatch3.toRegex = (source, options) => {
15518
+ picomatch4.toRegex = (source, options) => {
15519
15519
  try {
15520
15520
  const opts = options || {};
15521
15521
  return new RegExp(source, opts.flags || (opts.nocase ? "i" : ""));
@@ -15524,8 +15524,8 @@ var require_picomatch3 = __commonJS({
15524
15524
  return /$^/;
15525
15525
  }
15526
15526
  };
15527
- picomatch3.constants = constants3;
15528
- module2.exports = picomatch3;
15527
+ picomatch4.constants = constants3;
15528
+ module2.exports = picomatch4;
15529
15529
  }
15530
15530
  });
15531
15531
 
@@ -15543,7 +15543,7 @@ var require_micromatch = __commonJS({
15543
15543
  "use strict";
15544
15544
  var util = require("util");
15545
15545
  var braces = require_braces();
15546
- var picomatch3 = require_picomatch4();
15546
+ var picomatch4 = require_picomatch4();
15547
15547
  var utils = require_utils3();
15548
15548
  var isEmptyString = (v) => v === "" || v === "./";
15549
15549
  var hasBraces = (v) => {
@@ -15564,7 +15564,7 @@ var require_micromatch = __commonJS({
15564
15564
  }
15565
15565
  };
15566
15566
  for (let i = 0; i < patterns.length; i++) {
15567
- let isMatch = picomatch3(String(patterns[i]), { ...options, onResult }, true);
15567
+ let isMatch = picomatch4(String(patterns[i]), { ...options, onResult }, true);
15568
15568
  let negated = isMatch.state.negated || isMatch.state.negatedExtglob;
15569
15569
  if (negated) negatives++;
15570
15570
  for (let item of list) {
@@ -15592,8 +15592,8 @@ var require_micromatch = __commonJS({
15592
15592
  return matches;
15593
15593
  };
15594
15594
  micromatch.match = micromatch;
15595
- micromatch.matcher = (pattern, options) => picomatch3(pattern, options);
15596
- micromatch.isMatch = (str, patterns, options) => picomatch3(patterns, options)(str);
15595
+ micromatch.matcher = (pattern, options) => picomatch4(pattern, options);
15596
+ micromatch.isMatch = (str, patterns, options) => picomatch4(patterns, options)(str);
15597
15597
  micromatch.any = micromatch.isMatch;
15598
15598
  micromatch.not = (list, patterns, options = {}) => {
15599
15599
  patterns = [].concat(patterns).map(String);
@@ -15640,7 +15640,7 @@ var require_micromatch = __commonJS({
15640
15640
  micromatch.some = (list, patterns, options) => {
15641
15641
  let items = [].concat(list);
15642
15642
  for (let pattern of [].concat(patterns)) {
15643
- let isMatch = picomatch3(String(pattern), options);
15643
+ let isMatch = picomatch4(String(pattern), options);
15644
15644
  if (items.some((item) => isMatch(item))) {
15645
15645
  return true;
15646
15646
  }
@@ -15650,7 +15650,7 @@ var require_micromatch = __commonJS({
15650
15650
  micromatch.every = (list, patterns, options) => {
15651
15651
  let items = [].concat(list);
15652
15652
  for (let pattern of [].concat(patterns)) {
15653
- let isMatch = picomatch3(String(pattern), options);
15653
+ let isMatch = picomatch4(String(pattern), options);
15654
15654
  if (!items.every((item) => isMatch(item))) {
15655
15655
  return false;
15656
15656
  }
@@ -15661,23 +15661,23 @@ var require_micromatch = __commonJS({
15661
15661
  if (typeof str !== "string") {
15662
15662
  throw new TypeError(`Expected a string: "${util.inspect(str)}"`);
15663
15663
  }
15664
- return [].concat(patterns).every((p) => picomatch3(p, options)(str));
15664
+ return [].concat(patterns).every((p) => picomatch4(p, options)(str));
15665
15665
  };
15666
15666
  micromatch.capture = (glob, input, options) => {
15667
15667
  let posix = utils.isWindows(options);
15668
- let regex = picomatch3.makeRe(String(glob), { ...options, capture: true });
15668
+ let regex = picomatch4.makeRe(String(glob), { ...options, capture: true });
15669
15669
  let match = regex.exec(posix ? utils.toPosixSlashes(input) : input);
15670
15670
  if (match) {
15671
15671
  return match.slice(1).map((v) => v === void 0 ? "" : v);
15672
15672
  }
15673
15673
  };
15674
- micromatch.makeRe = (...args) => picomatch3.makeRe(...args);
15675
- micromatch.scan = (...args) => picomatch3.scan(...args);
15674
+ micromatch.makeRe = (...args) => picomatch4.makeRe(...args);
15675
+ micromatch.scan = (...args) => picomatch4.scan(...args);
15676
15676
  micromatch.parse = (patterns, options) => {
15677
15677
  let res = [];
15678
15678
  for (let pattern of [].concat(patterns || [])) {
15679
15679
  for (let str of braces(String(pattern), options)) {
15680
- res.push(picomatch3.parse(str, options));
15680
+ res.push(picomatch4.parse(str, options));
15681
15681
  }
15682
15682
  }
15683
15683
  return res;
@@ -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.4.1",
18188
+ version: "0.5.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: [
@@ -18359,7 +18359,7 @@ function writeBaseline(repo, id, content) {
18359
18359
 
18360
18360
  // src/manifest.ts
18361
18361
  var MANIFEST_REL = ".agents/manifest.yaml";
18362
- var SUPPORTED_MANIFEST_SPEC = "ai-harness/v0";
18362
+ var SUPPORTED_MANIFEST_SPECS = ["ai-harness/v0", "ai-harness/v1"];
18363
18363
  var MAX_GLOB_PATTERN_LENGTH = 4096;
18364
18364
  function manifestPath(repo) {
18365
18365
  return (0, import_node_path2.join)(repo, MANIFEST_REL);
@@ -18456,8 +18456,8 @@ function validateManifest(m) {
18456
18456
  }
18457
18457
  if (!m.spec) issues.push({ level: "error", msg: "\u7F3A\u5C11 spec \u5B57\u6BB5" });
18458
18458
  else if (typeof m.spec !== "string") issues.push({ level: "error", msg: "spec \u5FC5\u987B\u662F\u5B57\u7B26\u4E32" });
18459
- else if (m.spec !== SUPPORTED_MANIFEST_SPEC)
18460
- issues.push({ level: "error", msg: `\u4E0D\u652F\u6301 manifest spec ${m.spec}\uFF1B\u5F53\u524D CLI \u53EA\u652F\u6301 ${SUPPORTED_MANIFEST_SPEC}` });
18459
+ else if (!SUPPORTED_MANIFEST_SPECS.includes(m.spec))
18460
+ issues.push({ level: "error", msg: `\u4E0D\u652F\u6301 manifest spec ${m.spec}\uFF1B\u5F53\u524D CLI \u652F\u6301 ${SUPPORTED_MANIFEST_SPECS.join(", ")}` });
18461
18461
  if (!m.identity || !isRecord(m.identity)) issues.push({ level: "error", msg: "identity \u5FC5\u987B\u662F\u5BF9\u8C61" });
18462
18462
  if (!m.identity?.name) issues.push({ level: "error", msg: "identity.name \u5FC5\u586B" });
18463
18463
  else if (typeof m.identity.name !== "string") issues.push({ level: "error", msg: "identity.name \u5FC5\u987B\u662F\u5B57\u7B26\u4E32" });
@@ -18592,6 +18592,16 @@ function validateManifest(m) {
18592
18592
  issues.push({ level: "warn", msg: `routing "${r.when}" \u7684 verify \u5F15\u7528\u4E86\u672A\u58F0\u660E\u7684 capability: ${v2}` });
18593
18593
  }
18594
18594
  }
18595
+ const validationRecord = isRecord(m.validation) ? m.validation : {};
18596
+ const declaredGates = isRecord(validationRecord.gates) ? validationRecord.gates : {};
18597
+ const usesValidationGates = Object.keys(declaredGates).length > 0 || Array.isArray(m.modules) && m.modules.some((module2) => isRecord(module2) && Array.isArray(module2.gates) && module2.gates.length > 0);
18598
+ if (m.spec === "ai-harness/v0" && usesValidationGates)
18599
+ issues.push({
18600
+ level: "error",
18601
+ msg: "validation.gates / modules[].gates \u9700\u8981 spec: ai-harness/v1\uFF1Bv1 \u4F1A\u8BA9\u65E7\u7248 CLI fail closed\uFF0C\u4E0D\u80FD\u88AB\u9759\u9ED8\u5F53\u6210 unit-only"
18602
+ });
18603
+ const gateIds = new Set(Object.keys(declaredGates));
18604
+ const referencedGates = /* @__PURE__ */ new Set();
18595
18605
  const modSeen = /* @__PURE__ */ new Set();
18596
18606
  for (const rawModule of checkedList(m.modules, "modules")) {
18597
18607
  if (!isRecord(rawModule)) {
@@ -18608,7 +18618,7 @@ function validateManifest(m) {
18608
18618
  if (typeof mod.role !== "string" || !mod.role) issues.push({ level: "error", msg: `module ${mod.name}.role \u5FC5\u586B` });
18609
18619
  if (!mod.entry?.length)
18610
18620
  issues.push({ level: "warn", msg: `module ${mod.name} \u672A\u58F0\u660E entry\uFF08\u65E0\u6CD5\u505A\u65B0\u9C9C\u5EA6\u7ED1\u5B9A\uFF09` });
18611
- for (const field of ["entry", "upstream", "downstream", "must_know", "pitfalls", "owns", "tests", "checks"]) {
18621
+ for (const field of ["entry", "upstream", "downstream", "must_know", "pitfalls", "owns", "tests", "checks", "gates"]) {
18612
18622
  checkStrArr(mod[field], `module "${mod.name}" \u7684 ${field}`);
18613
18623
  }
18614
18624
  checkRelativePaths(mod.entry, `module "${mod.name}" \u7684 entry`);
@@ -18624,6 +18634,14 @@ function validateManifest(m) {
18624
18634
  }
18625
18635
  if (mod.test_touch !== void 0 && !["required", "advisory", "off"].includes(mod.test_touch))
18626
18636
  issues.push({ level: "error", msg: `module "${mod.name}" \u7684 test_touch \u5FC5\u987B\u662F required/advisory/off` });
18637
+ if (Array.isArray(mod.gates) && mod.gates.length > 0 && !(mod.owns?.length ?? 0))
18638
+ issues.push({ level: "error", msg: `module "${mod.name}" \u58F0\u660E\u4E86 gates \u4F46\u6CA1\u6709 owns\uFF1B\u751F\u4EA7\u6539\u52A8\u6C38\u8FDC\u65E0\u6CD5\u89E6\u53D1 gate` });
18639
+ for (const gate of Array.isArray(mod.gates) ? mod.gates : []) {
18640
+ if (typeof gate !== "string") continue;
18641
+ referencedGates.add(gate);
18642
+ if (!gateIds.has(gate))
18643
+ issues.push({ level: "error", msg: `module "${mod.name}" \u5F15\u7528\u7684 validation gate ${gate} \u672A\u58F0\u660E` });
18644
+ }
18627
18645
  for (const c of Array.isArray(mod.checks) ? mod.checks : []) {
18628
18646
  if (typeof c === "string" && !capVerbs.has(c))
18629
18647
  issues.push({ level: "error", msg: `module "${mod.name}" \u7684 checks \u5F15\u7528\u4E86\u672A\u58F0\u660E\u7684 capability: ${c}\uFF08checks \u53EA\u80FD\u662F capability \u52A8\u8BCD\uFF09` });
@@ -18643,6 +18661,50 @@ function validateManifest(m) {
18643
18661
  issues.push({ level: "error", msg: "validation \u5FC5\u987B\u662F\u5BF9\u8C61" });
18644
18662
  return issues;
18645
18663
  }
18664
+ const gates = v.gates;
18665
+ if (gates !== void 0 && !isRecord(gates)) issues.push({ level: "error", msg: "validation.gates \u5FC5\u987B\u662F\u5BF9\u8C61" });
18666
+ for (const [id, rawGate] of Object.entries(isRecord(gates) ? gates : {})) {
18667
+ if (!id.trim()) {
18668
+ issues.push({ level: "error", msg: "validation gate id \u4E0D\u80FD\u4E3A\u7A7A" });
18669
+ continue;
18670
+ }
18671
+ if (!isRecord(rawGate)) {
18672
+ issues.push({ level: "error", msg: `validation gate ${id} \u5FC5\u987B\u662F\u5BF9\u8C61` });
18673
+ continue;
18674
+ }
18675
+ if (rawGate.desc !== void 0 && typeof rawGate.desc !== "string")
18676
+ issues.push({ level: "error", msg: `validation gate ${id}.desc \u5FC5\u987B\u662F\u5B57\u7B26\u4E32` });
18677
+ const checks = rawGate.checks;
18678
+ if (!Array.isArray(checks) || checks.length === 0)
18679
+ issues.push({ level: "error", msg: `validation gate ${id}.checks \u5FC5\u987B\u5305\u542B\u81F3\u5C11\u4E00\u4E2A capability` });
18680
+ else checkStrArr(checks, `validation gate ${id}.checks`);
18681
+ for (const check of Array.isArray(checks) ? checks : []) {
18682
+ if (typeof check !== "string") continue;
18683
+ if (!capVerbs.has(check))
18684
+ issues.push({ level: "error", msg: `validation gate ${id}.checks \u5F15\u7528\u4E86\u672A\u58F0\u660E\u7684 capability: ${check}` });
18685
+ else {
18686
+ const cap = capabilities[check];
18687
+ if (cap?.mutating || cap?.background)
18688
+ issues.push({ level: "error", msg: `validation gate ${id}.checks \u5F15\u7528\u4E86\u4E0D\u53EF\u81EA\u52A8\u6267\u884C\u7684 capability: ${check}` });
18689
+ }
18690
+ }
18691
+ const acceptance = rawGate.acceptance;
18692
+ if (acceptance !== void 0 && !isRecord(acceptance)) {
18693
+ issues.push({ level: "error", msg: `validation gate ${id}.acceptance \u5FC5\u987B\u662F\u5BF9\u8C61` });
18694
+ } else if (isRecord(acceptance)) {
18695
+ if (!Array.isArray(acceptance.tests) || acceptance.tests.length === 0)
18696
+ issues.push({ level: "error", msg: `validation gate ${id}.acceptance.tests \u5FC5\u987B\u5305\u542B\u81F3\u5C11\u4E00\u4E2A glob` });
18697
+ else checkStrArr(acceptance.tests, `validation gate ${id} \u7684 acceptance.tests`);
18698
+ checkPositiveGlobs(acceptance.tests, `validation gate ${id} \u7684 acceptance.tests`);
18699
+ checkGlobSafety(acceptance.tests, `validation gate ${id} \u7684 acceptance.tests`);
18700
+ checkRelativePaths(acceptance.tests, `validation gate ${id} \u7684 acceptance.tests`);
18701
+ if (!["required", "advisory", "off"].includes(String(acceptance.test_touch)))
18702
+ issues.push({ level: "error", msg: `validation gate ${id}.acceptance.test_touch \u5FC5\u987B\u662F required/advisory/off` });
18703
+ }
18704
+ if (!referencedGates.has(id)) {
18705
+ issues.push({ level: "error", msg: `validation gate ${id} \u672A\u88AB\u4EFB\u4F55 module.gates \u5F15\u7528\uFF0C\u751F\u4EA7\u6539\u52A8\u4E0D\u4F1A\u89E6\u53D1\u5B83` });
18706
+ }
18707
+ }
18646
18708
  const checksets = v.checksets;
18647
18709
  if (checksets !== void 0 && !isRecord(checksets))
18648
18710
  issues.push({ level: "error", msg: "validation.checksets \u5FC5\u987B\u662F\u5BF9\u8C61" });
@@ -19311,6 +19373,7 @@ function renderModulesMd(m) {
19311
19373
  if (mod.owns?.length) L.push(`- Owns (prod): ${mod.owns.map((s) => `\`${safeStr(s)}\``).join(", ")}`);
19312
19374
  if (mod.tests?.length) L.push(`- Tests: ${mod.tests.map((s) => `\`${safeStr(s)}\``).join(", ")}`);
19313
19375
  if (mod.checks?.length) L.push(`- Checks: ${mod.checks.map((s) => `\`${safeStr(s)}\``).join(", ")}`);
19376
+ if (mod.gates?.length) L.push(`- Validation gates: ${mod.gates.map((s) => `\`${safeStr(s)}\``).join(", ")}`);
19314
19377
  if (mod.test_touch) L.push(`- Test touch: \`${safeStr(mod.test_touch)}\``);
19315
19378
  if (mod.playbook) L.push(`- Playbook: \`${safeStr(mod.playbook)}\``);
19316
19379
  if (mod.upstream?.length) L.push(`- Upstream: ${mod.upstream.map(safeStr).join(", ")}`);
@@ -19319,6 +19382,19 @@ function renderModulesMd(m) {
19319
19382
  if (mod.pitfalls?.length) for (const p of mod.pitfalls) L.push(`- Pitfall: ${safeStr(p)}`);
19320
19383
  L.push("");
19321
19384
  }
19385
+ if (m.validation?.gates && Object.keys(m.validation.gates).length) {
19386
+ L.push("# Validation gates", "");
19387
+ L.push("Project-defined mandatory proof obligations. Profiles may replace ordinary module checks, but they cannot bypass these gates.", "");
19388
+ for (const [id, gate] of Object.entries(m.validation.gates)) {
19389
+ L.push(`## ${safeStr(id)}${gate.desc ? ` \u2014 ${safeStr(gate.desc)}` : ""}`);
19390
+ L.push(`- Mandatory checks: ${gate.checks.map((check) => `\`${safeStr(check)}\``).join(", ")}`);
19391
+ if (gate.acceptance) {
19392
+ L.push(`- Acceptance tests: ${gate.acceptance.tests.map((test) => `\`${safeStr(test)}\``).join(", ")}`);
19393
+ L.push(`- Acceptance test touch: \`${safeStr(gate.acceptance.test_touch)}\``);
19394
+ }
19395
+ L.push("");
19396
+ }
19397
+ }
19322
19398
  return L.join("\n");
19323
19399
  }
19324
19400
  function renderClaudeMd() {
@@ -20408,7 +20484,7 @@ function syncCmd(repo, opts = {}) {
20408
20484
  }
20409
20485
 
20410
20486
  // src/commands/doctor.ts
20411
- var import_fast_glob2 = __toESM(require_out4(), 1);
20487
+ var import_fast_glob3 = __toESM(require_out4(), 1);
20412
20488
  var import_node_fs12 = require("node:fs");
20413
20489
  var import_node_path12 = require("node:path");
20414
20490
 
@@ -21238,6 +21314,309 @@ function inspectCodexLinkedHooks(repoInput) {
21238
21314
  var import_node_crypto6 = require("node:crypto");
21239
21315
  var import_node_fs8 = require("node:fs");
21240
21316
  var import_node_path8 = require("node:path");
21317
+
21318
+ // src/planner.ts
21319
+ var import_picomatch2 = __toESM(require_picomatch2(), 1);
21320
+ function validationPlanFingerprint(plan) {
21321
+ return sha256(
21322
+ JSON.stringify({
21323
+ version: 1,
21324
+ profile: plan.profile,
21325
+ changed: plan.changed,
21326
+ affected: plan.affected,
21327
+ gates: plan.gates,
21328
+ checks: plan.checks,
21329
+ gaps: plan.gaps,
21330
+ notes: plan.notes
21331
+ })
21332
+ );
21333
+ }
21334
+ function matchesAny(file, globs) {
21335
+ if (!globs || globs.length === 0) return false;
21336
+ return (0, import_picomatch2.default)(globs, { dot: true })(file);
21337
+ }
21338
+ function suggestionFor(mod, base) {
21339
+ return mod.remediation ? mod.remediation : base;
21340
+ }
21341
+ function planChecks(m, input, opts = {}) {
21342
+ const changeEntries = input.map((change) => typeof change === "string" ? { path: change, status: "M" } : change);
21343
+ const changed = [...new Set(changeEntries.map((change) => change.path))];
21344
+ const finalStatus = /* @__PURE__ */ new Map();
21345
+ const layerPriority = { index: 1, worktree: 2, untracked: 3 };
21346
+ for (const change of changeEntries) {
21347
+ const priority = change.layer ? layerPriority[change.layer] : 4;
21348
+ const previous = finalStatus.get(change.path);
21349
+ if (!previous || priority >= previous.priority) finalStatus.set(change.path, { priority, status: change.status });
21350
+ }
21351
+ const modules = m.modules ?? [];
21352
+ const compiled = modules.map((mod) => ({
21353
+ mod,
21354
+ owns: mod.owns?.length ? (0, import_picomatch2.default)(mod.owns, { dot: true }) : null,
21355
+ tests: mod.tests?.length ? (0, import_picomatch2.default)(mod.tests, { dot: true }) : null
21356
+ }));
21357
+ const modulesWithOwns = compiled.filter((item) => item.owns !== null);
21358
+ const gateDefs = m.validation?.gates ?? {};
21359
+ const compiledGates = Object.entries(gateDefs).map(([id, gate]) => ({
21360
+ id,
21361
+ gate,
21362
+ acceptance: gate.acceptance?.tests?.length ? (0, import_picomatch2.default)(gate.acceptance.tests, { dot: true }) : null,
21363
+ overlapsModuleBoundary: (0, import_picomatch2.default)(
21364
+ modules.filter((mod) => mod.gates?.includes(id)).flatMap((mod) => [...mod.owns ?? [], ...mod.tests ?? []]),
21365
+ { dot: true }
21366
+ )
21367
+ }));
21368
+ const gaps = [];
21369
+ const notes = [];
21370
+ const affectedModules = [];
21371
+ const productionAffected = /* @__PURE__ */ new Set();
21372
+ const affectedGateSet = /* @__PURE__ */ new Set();
21373
+ const productionAffectedGates = /* @__PURE__ */ new Set();
21374
+ const matchedFiles = /* @__PURE__ */ new Set();
21375
+ for (const item of compiled) {
21376
+ const { mod } = item;
21377
+ let productionHit = false;
21378
+ let testHit = false;
21379
+ for (const f of changed) {
21380
+ if (item.owns?.(f)) {
21381
+ productionHit = true;
21382
+ matchedFiles.add(f);
21383
+ }
21384
+ if (item.tests?.(f)) {
21385
+ testHit = true;
21386
+ matchedFiles.add(f);
21387
+ }
21388
+ }
21389
+ if (productionHit || testHit) affectedModules.push(mod);
21390
+ if (productionHit) productionAffected.add(mod.name);
21391
+ }
21392
+ for (const mod of affectedModules) {
21393
+ for (const gate of mod.gates ?? []) affectedGateSet.add(gate);
21394
+ if (productionAffected.has(mod.name)) for (const gate of mod.gates ?? []) productionAffectedGates.add(gate);
21395
+ }
21396
+ for (const item of compiledGates) {
21397
+ if (!item.acceptance) continue;
21398
+ for (const file of changed) {
21399
+ if (!item.acceptance(file)) continue;
21400
+ matchedFiles.add(file);
21401
+ affectedGateSet.add(item.id);
21402
+ }
21403
+ }
21404
+ const affectedGates = compiledGates.filter((item) => affectedGateSet.has(item.id));
21405
+ const unmapped = changed.filter((f) => !matchedFiles.has(f));
21406
+ const requiredCoverage = m.validation?.required_coverage?.length ? (0, import_picomatch2.default)(m.validation.required_coverage, { dot: true }) : null;
21407
+ const requiredUnmapped = requiredCoverage ? unmapped.filter((file) => requiredCoverage(file)) : [];
21408
+ const advisoryUnmapped = unmapped.filter((file) => !requiredUnmapped.includes(file));
21409
+ const checks = [];
21410
+ const seen = /* @__PURE__ */ new Set();
21411
+ const add = (id, reason) => {
21412
+ if (seen.has(id)) return;
21413
+ seen.add(id);
21414
+ checks.push({ id, reason });
21415
+ };
21416
+ const profile = opts.profile ?? null;
21417
+ if (profile) {
21418
+ const set = m.validation?.checksets?.[profile];
21419
+ if (!set) {
21420
+ gaps.push({
21421
+ kind: "unknown-profile",
21422
+ where: profile,
21423
+ why: `validation.checksets \u6CA1\u6709\u58F0\u660E profile: ${profile}`,
21424
+ suggestion: "\u68C0\u67E5 --profile \u62FC\u5199\uFF0C\u6216\u5148\u5728 validation.checksets \u4E2D\u58F0\u660E\u5B83",
21425
+ severity: "blocking"
21426
+ });
21427
+ } else {
21428
+ for (const c of set.checks ?? []) add(c, `profile:${profile}`);
21429
+ }
21430
+ } else {
21431
+ for (const mod of affectedModules) for (const c of mod.checks ?? []) add(c, `module:${mod.name}`);
21432
+ if (affectedModules.length === 0)
21433
+ for (const c of m.validation?.defaults?.no_match ?? []) add(c, "no_match");
21434
+ }
21435
+ for (const item of affectedGates) for (const check of item.gate.checks ?? []) add(check, `gate:${item.id}`);
21436
+ for (const c of m.validation?.defaults?.always ?? []) add(c, "always");
21437
+ if (modulesWithOwns.length === 0) {
21438
+ gaps.push({
21439
+ kind: "no-impact-map",
21440
+ where: "modules",
21441
+ why: "manifest \u6CA1\u6709\u4EFB\u4F55\u58F0\u660E owns \u7684\u6A21\u5757\uFF0C\u65E0\u6CD5\u6309\u5F71\u54CD\u9762\u9009\u6D4B",
21442
+ suggestion: "\u5728 .agents/manifest.yaml \u7684 modules[] \u8865 owns/tests/checks\uFF0C\u8BA9\u6539\u52A8\u80FD\u6620\u5C04\u5230\u9A8C\u8BC1",
21443
+ severity: "advisory"
21444
+ });
21445
+ }
21446
+ for (const mod of affectedModules) {
21447
+ if (!productionAffected.has(mod.name)) continue;
21448
+ const testTouch = mod.test_touch ?? m.validation?.policies?.test_touch_default ?? "advisory";
21449
+ if (!(mod.tests?.length ?? 0)) {
21450
+ if (testTouch === "off") continue;
21451
+ gaps.push({
21452
+ kind: "module-without-tests",
21453
+ where: mod.name,
21454
+ why: `\u6A21\u5757 ${mod.name} \u672A\u58F0\u660E tests\uFF0C\u65E0\u56DE\u5F52\u7F51\u3001\u4E5F\u65E0\u6CD5\u5224\u65AD\u6D4B\u8BD5\u662F\u5426\u88AB\u8865`,
21455
+ suggestion: suggestionFor(
21456
+ mod,
21457
+ `\u7ED9\u6A21\u5757 ${mod.name} \u58F0\u660E tests glob \u5E76\u8865\u6D4B\u8BD5${mod.playbook ? `\uFF1B\u53C2\u8003 playbook ${mod.playbook}` : ""}`
21458
+ ),
21459
+ severity: testTouch === "required" ? "blocking" : "advisory"
21460
+ });
21461
+ continue;
21462
+ }
21463
+ const testTouched = changed.some((path) => finalStatus.get(path)?.status !== "D" && matchesAny(path, mod.tests));
21464
+ if (!testTouched && testTouch !== "off") {
21465
+ gaps.push({
21466
+ kind: "missing-test-touch",
21467
+ where: mod.name,
21468
+ why: `\u6539\u4E86 ${mod.name} \u7684\u751F\u4EA7\u4EE3\u7801\uFF0C\u4F46\u5B83\u7684\u6D4B\u8BD5(${mod.tests.join(", ")})\u4E00\u4E2A\u90FD\u6CA1\u52A8`,
21469
+ suggestion: suggestionFor(
21470
+ mod,
21471
+ `\u5728 ${mod.tests.join(" / ")} \u8865\u8986\u76D6\u672C\u6B21\u6539\u52A8\u7684\u7528\u4F8B${mod.playbook ? `\uFF08\u53C2\u8003 playbook ${mod.playbook}\uFF09` : ""}\uFF0C\u6216 --waive missing-test-touch --where ${mod.name} --reason <\u7406\u7531>`
21472
+ ),
21473
+ severity: testTouch === "required" ? "blocking" : "advisory"
21474
+ });
21475
+ }
21476
+ }
21477
+ for (const item of affectedGates) {
21478
+ if (!productionAffectedGates.has(item.id) || !item.gate.acceptance) continue;
21479
+ const policy = item.gate.acceptance.test_touch;
21480
+ if (policy === "off") continue;
21481
+ const testTouched = changed.some(
21482
+ (path) => finalStatus.get(path)?.status !== "D" && matchesAny(path, item.gate.acceptance.tests) && !item.overlapsModuleBoundary(path)
21483
+ );
21484
+ if (!testTouched) {
21485
+ gaps.push({
21486
+ kind: "missing-test-touch",
21487
+ where: `gate:${item.id}`,
21488
+ why: `\u751F\u4EA7\u4EE3\u7801\u89E6\u53D1\u4E86 validation gate ${item.id}\uFF0C\u4F46\u5B83\u7684 acceptance tests(${item.gate.acceptance.tests.join(", ")})\u4E00\u4E2A\u90FD\u6CA1\u52A8`,
21489
+ suggestion: `\u5728 ${item.gate.acceptance.tests.join(" / ")} \u8865\u8986\u76D6\u672C\u6B21\u7528\u6237\u53EF\u89C2\u5BDF\u884C\u4E3A\u7684\u9A8C\u6536\u7528\u4F8B\uFF0C\u6216 --waive missing-test-touch --where gate:${item.id} --reason <\u7406\u7531>`,
21490
+ severity: policy === "required" ? "blocking" : "advisory"
21491
+ });
21492
+ }
21493
+ }
21494
+ if (requiredUnmapped.length) {
21495
+ const shown = requiredUnmapped.slice(0, 8).join(", ");
21496
+ gaps.push({
21497
+ kind: "unmapped-required-file",
21498
+ where: shown + (requiredUnmapped.length > 8 ? ` \u2026(+${requiredUnmapped.length - 8})` : ""),
21499
+ why: "\u8FD9\u4E9B\u6539\u52A8\u4F4D\u4E8E validation.required_coverage\uFF0C\u4F46\u4E0D\u5C5E\u4E8E\u4EFB\u4F55\u6A21\u5757\u7684 owns/tests",
21500
+ suggestion: "\u628A\u6587\u4EF6\u52A0\u5165\u5DF2\u6709\u6A21\u5757\u7684 owns/tests\uFF0C\u6216\u65B0\u589E\u6A21\u5757\u5361\uFF1B\u5FC5\u9700\u8986\u76D6\u8303\u56F4\u4E0D\u80FD\u9759\u9ED8\u8DF3\u8FC7",
21501
+ severity: "blocking"
21502
+ });
21503
+ }
21504
+ if (advisoryUnmapped.length) {
21505
+ const shown = advisoryUnmapped.slice(0, 8).join(", ");
21506
+ gaps.push({
21507
+ kind: "unmapped-file",
21508
+ where: shown + (advisoryUnmapped.length > 8 ? ` \u2026(+${advisoryUnmapped.length - 8})` : ""),
21509
+ why: "\u8FD9\u4E9B\u6539\u52A8\u6587\u4EF6\u4E0D\u5C5E\u4E8E\u4EFB\u4F55\u6A21\u5757\u7684 owns\uFF0C\u672A\u7EB3\u5165\u5F71\u54CD\u9762",
21510
+ suggestion: "\u82E5\u5C5E\u4E8E\u5DF2\u6709\u6A21\u5757\uFF0C\u8865\u5176 owns\uFF1B\u82E5\u662F\u65B0\u6A21\u5757\uFF0C\u5728 modules[] \u58F0\u660E owns/tests/checks",
21511
+ severity: "advisory"
21512
+ });
21513
+ }
21514
+ if (changed.length > 0 && checks.length === 0 && !gaps.some((gap2) => gap2.kind === "unknown-profile")) {
21515
+ gaps.push({
21516
+ kind: "no-checks-selected",
21517
+ where: "validation",
21518
+ why: "\u6709\u6539\u52A8\uFF0C\u4F46\u6CA1\u6709\u89E3\u6790\u51FA\u4EFB\u4F55\u8981\u8DD1\u7684 check\uFF08\u547D\u4E2D\u6A21\u5757\u65E0 checks\uFF0C\u6216 profile/defaults \u4E3A\u7A7A\uFF09",
21519
+ suggestion: "\u7ED9\u547D\u4E2D\u7684\u6A21\u5757\u58F0\u660E checks\uFF0C\u6216\u914D\u7F6E validation.defaults.no_match / profile checkset",
21520
+ severity: "blocking"
21521
+ });
21522
+ }
21523
+ if (affectedModules.length > 0) {
21524
+ notes.push({
21525
+ kind: "propagation-note",
21526
+ message: "\u5F71\u54CD\u9762\u6309\u9759\u6001 glob \u8BA1\u7B97\uFF0C\u4E0D\u5206\u6790\u8DE8\u6A21\u5757\u4F9D\u8D56\uFF1B\u4E0B\u6E38\u6A21\u5757\u53EF\u80FD\u672A\u88AB\u9009\u4E2D",
21527
+ suggestion: "\u82E5\u672C\u6B21\u6539\u7684\u662F\u5171\u4EAB/\u5E95\u5C42\u4EE3\u7801\uFF0C\u624B\u52A8\u786E\u8BA4\u4F9D\u8D56\u5B83\u7684\u6A21\u5757\u7684\u6D4B\u8BD5"
21528
+ });
21529
+ }
21530
+ return {
21531
+ changed,
21532
+ affected: affectedModules.map((x) => x.name),
21533
+ gates: affectedGates.map((item) => item.id),
21534
+ checks,
21535
+ gaps,
21536
+ notes,
21537
+ profile
21538
+ };
21539
+ }
21540
+
21541
+ // src/validation-gates.ts
21542
+ var import_fast_glob = __toESM(require_out4(), 1);
21543
+ var import_picomatch3 = __toESM(require_picomatch2(), 1);
21544
+ var SCAN_OPTIONS = {
21545
+ onlyFiles: true,
21546
+ dot: true,
21547
+ followSymbolicLinks: false,
21548
+ ignore: ["**/node_modules/**", "**/.git/**", "**/dist/**"]
21549
+ };
21550
+ function matchingFiles(repoFiles, globs) {
21551
+ if (!globs.length) return [];
21552
+ const matches = (0, import_picomatch3.default)(globs, { dot: true });
21553
+ return repoFiles.filter((file) => matches(file));
21554
+ }
21555
+ function issueLevel(policy) {
21556
+ return policy === "required" ? "error" : "warn";
21557
+ }
21558
+ function inspectValidationGateHealth(repo, manifest) {
21559
+ const issues = [];
21560
+ const repoFiles = import_fast_glob.default.sync("**/*", { cwd: repo, ...SCAN_OPTIONS });
21561
+ for (const [id, gate] of Object.entries(manifest.validation?.gates ?? {})) {
21562
+ const acceptance = gate.acceptance;
21563
+ const acceptanceFiles = /* @__PURE__ */ new Set();
21564
+ if (acceptance) {
21565
+ const level = issueLevel(acceptance.test_touch);
21566
+ for (const glob of acceptance.tests) {
21567
+ const matches = matchingFiles(repoFiles, [glob]);
21568
+ for (const file of matches) acceptanceFiles.add(file);
21569
+ if (!matches.length) {
21570
+ issues.push({
21571
+ level,
21572
+ gate: id,
21573
+ message: `acceptance glob matches 0 files: ${glob}${level === "error" ? " \u2014 required acceptance coverage cannot be vacuous" : ""}`
21574
+ });
21575
+ }
21576
+ }
21577
+ }
21578
+ const modules = (manifest.modules ?? []).filter((module2) => module2.gates?.includes(id));
21579
+ for (const module2 of modules) {
21580
+ const ownedFiles = new Set(matchingFiles(repoFiles, module2.owns ?? []));
21581
+ if (ownedFiles.size === 0) {
21582
+ issues.push({
21583
+ level: "error",
21584
+ gate: id,
21585
+ message: `module ${module2.name} owns matches 0 files \u2014 production changes cannot activate this gate`
21586
+ });
21587
+ }
21588
+ if (!acceptance) continue;
21589
+ const unitFiles = new Set(matchingFiles(repoFiles, module2.tests ?? []));
21590
+ const overlap = [...acceptanceFiles].filter((file) => ownedFiles.has(file) || unitFiles.has(file));
21591
+ if (overlap.length) {
21592
+ const shown = overlap.slice(0, 5).join(", ");
21593
+ issues.push({
21594
+ level: issueLevel(acceptance.test_touch),
21595
+ gate: id,
21596
+ message: `acceptance files overlap module ${module2.name} owns/tests: ${shown}${overlap.length > 5 ? ` \u2026(+${overlap.length - 5})` : ""} \u2014 unit or production files cannot satisfy gate acceptance touch`
21597
+ });
21598
+ }
21599
+ }
21600
+ }
21601
+ return issues;
21602
+ }
21603
+
21604
+ // src/validation-plan.ts
21605
+ function planRepositoryChecks(repo, manifest, changes, options = {}) {
21606
+ const plan = planChecks(manifest, changes, options);
21607
+ for (const issue of inspectValidationGateHealth(repo, manifest)) {
21608
+ plan.gaps.push({
21609
+ kind: "validation-gate-invalid",
21610
+ where: `gate:${issue.gate}`,
21611
+ why: issue.message,
21612
+ suggestion: "\u4FEE\u6B63 validation gate \u7684 owns/tests/acceptance \u8FB9\u754C\u5E76\u786E\u4FDD\u771F\u5B9E\u9A8C\u6536\u6587\u4EF6\u5B58\u5728\uFF0C\u7136\u540E\u91CD\u8DD1\u68C0\u67E5",
21613
+ severity: issue.level === "error" ? "blocking" : "advisory"
21614
+ });
21615
+ }
21616
+ return plan;
21617
+ }
21618
+
21619
+ // src/validation-state.ts
21241
21620
  var TOKEN_RX = /^[a-f0-9]{64}$/;
21242
21621
  var MAX_SESSIONS = 100;
21243
21622
  var MAX_AGE_MS = 7 * 24 * 60 * 60 * 1e3;
@@ -21410,6 +21789,26 @@ function writeValidationSession(repo, session) {
21410
21789
  function recordValidationEvidence(repo, session, evidence) {
21411
21790
  writeValidationSession(repo, { ...session, lastEvidence: evidence });
21412
21791
  }
21792
+ function inspectValidationEvidenceFreshness(repo, evidence) {
21793
+ let currentFingerprint = "";
21794
+ let currentPlanFingerprint = "";
21795
+ let error = "";
21796
+ try {
21797
+ const current = collectChanges(repo, evidence.resolvedBase ?? EMPTY_TREE_BASE, { mode: "exact" });
21798
+ currentFingerprint = current.fingerprint;
21799
+ const manifest = loadManifest(repo);
21800
+ const manifestErrors = validateManifest(manifest).filter((issue) => issue.level === "error");
21801
+ if (manifestErrors.length) throw new Error(`manifest invalid: ${manifestErrors.map((issue) => issue.msg).join("; ")}`);
21802
+ const plan = planRepositoryChecks(repo, manifest, current.entries, { profile: evidence.profile ?? void 0 });
21803
+ currentPlanFingerprint = validationPlanFingerprint(plan);
21804
+ } catch (cause) {
21805
+ error = cause.message;
21806
+ }
21807
+ const fingerprintStale = !currentFingerprint || currentFingerprint !== evidence.fingerprint;
21808
+ const planStale = !currentPlanFingerprint || !evidence.planFingerprint || currentPlanFingerprint !== evidence.planFingerprint;
21809
+ if (!error && !evidence.planFingerprint) error = "validation evidence predates plan fingerprint binding; rerun run-checks";
21810
+ return { currentFingerprint, currentPlanFingerprint, fingerprintStale, planStale, stale: fingerprintStale || planStale, error };
21811
+ }
21413
21812
  function clearValidationEvidence(repo, session) {
21414
21813
  writeValidationSession(repo, { ...session, lastEvidence: void 0 });
21415
21814
  }
@@ -21422,11 +21821,12 @@ function recordWaiver(repo, session, waiver) {
21422
21821
  writeValidationSession(repo, next);
21423
21822
  return next;
21424
21823
  }
21425
- function markLatestVerifyResult(repo, token, passed, expectedFingerprint) {
21824
+ function markLatestVerifyResult(repo, token, passed, expectedFingerprint, expectedPlanFingerprint) {
21426
21825
  const session = readValidationSession(repo, token);
21427
21826
  if (!session?.lastEvidence) return false;
21428
21827
  const evidence = session.lastEvidence;
21429
21828
  if (expectedFingerprint && evidence.fingerprint !== expectedFingerprint) return false;
21829
+ if (!evidence.planFingerprint || expectedPlanFingerprint && evidence.planFingerprint !== expectedPlanFingerprint) return false;
21430
21830
  const runChecksStatus = evidence.runChecksStatus ?? evidence.status;
21431
21831
  const runChecksOk = runChecksStatus !== "not-verified";
21432
21832
  recordValidationEvidence(repo, session, {
@@ -21449,14 +21849,8 @@ function markManualVerifyResult(repoInput, passed) {
21449
21849
  const session = readValidationSession(repo, token);
21450
21850
  if (!session?.lastEvidence) return "none";
21451
21851
  const evidence = session.lastEvidence;
21452
- let matches = false;
21453
- try {
21454
- const current = collectChanges(repo, evidence.resolvedBase ?? EMPTY_TREE_BASE, { mode: "exact" });
21455
- matches = current.fingerprint === evidence.fingerprint;
21456
- } catch {
21457
- matches = false;
21458
- }
21459
- const updated = markLatestVerifyResult(repo, token, passed && matches, evidence.fingerprint);
21852
+ const matches = !inspectValidationEvidenceFreshness(repo, evidence).stale;
21853
+ const updated = markLatestVerifyResult(repo, token, passed && matches, evidence.fingerprint, evidence.planFingerprint);
21460
21854
  return matches && updated ? "matched" : "stale";
21461
21855
  }
21462
21856
 
@@ -21978,13 +22372,9 @@ function inspectAgentHookStatus(repo) {
21978
22372
  if (session && session.agent !== "manual" && evidence) {
21979
22373
  evidenceAgent = session.agent;
21980
22374
  evidenceAt = evidence.createdAt;
21981
- let currentFingerprint = "";
21982
- try {
21983
- currentFingerprint = collectChanges(repo, evidence.resolvedBase ?? EMPTY_TREE_BASE, { mode: "exact" }).fingerprint;
21984
- } catch (error) {
21985
- issues.push(`cannot refresh lifecycle evidence: ${error.message}`);
21986
- }
21987
- const stale = !currentFingerprint || currentFingerprint !== evidence.fingerprint;
22375
+ const freshness = inspectValidationEvidenceFreshness(repo, evidence);
22376
+ if (freshness.error) issues.push(`cannot refresh lifecycle evidence: ${freshness.error}`);
22377
+ const stale = freshness.stale;
21988
22378
  const runChecksValid = (evidence.runChecksStatus !== void 0 ? evidence.runChecksStatus !== "not-verified" : evidence.ok && evidence.status !== "not-verified") && !stale;
21989
22379
  const valid = runChecksValid && evidence.verifyPassed === true;
21990
22380
  if (!valid) {
@@ -22018,7 +22408,7 @@ function inspectAgentHookStatus(repo) {
22018
22408
  // src/state.ts
22019
22409
  var import_node_fs11 = require("node:fs");
22020
22410
  var import_node_path11 = require("node:path");
22021
- var import_fast_glob = __toESM(require_out4(), 1);
22411
+ var import_fast_glob2 = __toESM(require_out4(), 1);
22022
22412
  var STATE_REL = ".agents/.harness-state.json";
22023
22413
  function inside3(base, target) {
22024
22414
  const rel = (0, import_node_path11.relative)(base, target);
@@ -22040,7 +22430,7 @@ function hashPath(absPath) {
22040
22430
  }
22041
22431
  if (stat.isFile()) return hashFile(absPath) ?? "(missing)";
22042
22432
  if (!stat.isDirectory()) return "(missing)";
22043
- const files = import_fast_glob.default.sync("**/*", { cwd: absPath, onlyFiles: true, dot: true, followSymbolicLinks: false }).sort();
22433
+ const files = import_fast_glob2.default.sync("**/*", { cwd: absPath, onlyFiles: true, dot: true, followSymbolicLinks: false }).sort();
22044
22434
  const entries = files.map((path) => [path, hashFile((0, import_node_path11.join)(absPath, path)) ?? "(missing)"]);
22045
22435
  return sha256(JSON.stringify(entries));
22046
22436
  }
@@ -22281,7 +22671,7 @@ function doctorCmd(repo, opts = {}) {
22281
22671
  for (const inv of m.invariants ?? []) {
22282
22672
  if (!inv.enforcement) continue;
22283
22673
  const globs = inv.enforcement.path_glob?.length ? inv.enforcement.path_glob : ["**/*"];
22284
- const n = import_fast_glob2.default.sync(globs, {
22674
+ const n = import_fast_glob3.default.sync(globs, {
22285
22675
  cwd: repo,
22286
22676
  onlyFiles: true,
22287
22677
  dot: false,
@@ -22292,7 +22682,7 @@ function doctorCmd(repo, opts = {}) {
22292
22682
  }
22293
22683
  for (const mod of m.modules ?? []) {
22294
22684
  if (!mod.owns?.length) continue;
22295
- const n = import_fast_glob2.default.sync(mod.owns, {
22685
+ const n = import_fast_glob3.default.sync(mod.owns, {
22296
22686
  cwd: repo,
22297
22687
  onlyFiles: true,
22298
22688
  dot: true,
@@ -22302,7 +22692,7 @@ function doctorCmd(repo, opts = {}) {
22302
22692
  warn(`module ${mod.name}: owns glob matches 0 files \u2014 impact planner can never select it (stale owns for this layout?)`);
22303
22693
  }
22304
22694
  for (const glob of m.validation?.required_coverage ?? []) {
22305
- const n = import_fast_glob2.default.sync(glob, {
22695
+ const n = import_fast_glob3.default.sync(glob, {
22306
22696
  cwd: repo,
22307
22697
  onlyFiles: true,
22308
22698
  dot: true,
@@ -22311,6 +22701,15 @@ function doctorCmd(repo, opts = {}) {
22311
22701
  if (n === 0)
22312
22702
  warn(`validation.required_coverage glob matches 0 files: ${glob} \u2014 a typo here silently weakens unmapped-file protection`);
22313
22703
  }
22704
+ for (const issue of inspectValidationGateHealth(repo, m)) {
22705
+ const message = `validation gate ${issue.gate}: ${issue.message}`;
22706
+ if (issue.level === "error") {
22707
+ err(message);
22708
+ problems++;
22709
+ } else {
22710
+ warn(message);
22711
+ }
22712
+ }
22314
22713
  info("\n2) Referenced paths");
22315
22714
  const checkPath = (rel, label) => {
22316
22715
  if ((0, import_node_fs12.existsSync)((0, import_node_path12.join)(repo, ".agents", rel))) ok(`${label}: ${rel}`);
@@ -22329,8 +22728,8 @@ function doctorCmd(repo, opts = {}) {
22329
22728
  } else ok(`${label}: ${rel}`);
22330
22729
  };
22331
22730
  const checkRepoPointer = (pointer, label) => {
22332
- if (!import_fast_glob2.default.isDynamicPattern(pointer)) return checkRepoPath(pointer, label);
22333
- const matches = import_fast_glob2.default.sync(pointer, {
22731
+ if (!import_fast_glob3.default.isDynamicPattern(pointer)) return checkRepoPath(pointer, label);
22732
+ const matches = import_fast_glob3.default.sync(pointer, {
22334
22733
  cwd: repo,
22335
22734
  onlyFiles: false,
22336
22735
  dot: true,
@@ -22476,13 +22875,13 @@ function doctorCmd(repo, opts = {}) {
22476
22875
  var import_node_child_process5 = require("node:child_process");
22477
22876
 
22478
22877
  // src/enforce.ts
22479
- var import_fast_glob3 = __toESM(require_out4(), 1);
22878
+ var import_fast_glob4 = __toESM(require_out4(), 1);
22480
22879
  var import_node_fs13 = require("node:fs");
22481
22880
  var import_node_path13 = require("node:path");
22482
22881
  var DEFAULT_IGNORE = ["**/node_modules/**", "**/.git/**", "**/dist/**", "**/.agents/map/**"];
22483
22882
  function runEnforcement(repo, invId, e) {
22484
22883
  const globs = e.path_glob?.length ? e.path_glob : ["**/*"];
22485
- const files = import_fast_glob3.default.sync(globs, {
22884
+ const files = import_fast_glob4.default.sync(globs, {
22486
22885
  cwd: repo,
22487
22886
  onlyFiles: true,
22488
22887
  dot: false,
@@ -22648,6 +23047,15 @@ function verifyInternal(repo, opts) {
22648
23047
  verify: FAILED (${manifestErrors.length} manifest problem(s))`);
22649
23048
  return finish(1);
22650
23049
  }
23050
+ const gateHealth = inspectValidationGateHealth(repo, manifest);
23051
+ if (gateHealth.length) emit("info", "0) Validation gate coverage");
23052
+ for (const issue of gateHealth) {
23053
+ const message = `validation gate ${issue.gate}: ${issue.message}`;
23054
+ if (issue.level === "error") {
23055
+ failures++;
23056
+ emit("error", message);
23057
+ } else emit("warn", message);
23058
+ }
22651
23059
  emit("info", "1) Generated files in sync");
22652
23060
  try {
22653
23061
  for (const inspection of inspectManagedFiles(repo, renderTargets(manifest))) {
@@ -22800,7 +23208,7 @@ verify: FAILED (${manifestErrors.length} manifest problem(s))`);
22800
23208
  emit("warn", `Harness readiness: INCOMPLETE (${requiredActions.length} required action(s) above)`);
22801
23209
  return finish(1);
22802
23210
  }
22803
- emit("info", "verify: OK (all declared gates passed)");
23211
+ emit("info", "verify: OK (repository drift, invariants, and contracts passed; validation checks require matching run-checks evidence)");
22804
23212
  if (requiredActions.length)
22805
23213
  emit("warn", `Harness readiness: INCOMPLETE (${requiredActions.length} required action(s) above)`);
22806
23214
  else emit("ok", "Harness readiness: READY");
@@ -22979,14 +23387,8 @@ function evidenceCmd(repo, opts = {}) {
22979
23387
  evidence: session.lastEvidence
22980
23388
  };
22981
23389
  const evidence = session.lastEvidence;
22982
- let currentFingerprint = "";
22983
- let refreshError = "";
22984
- try {
22985
- currentFingerprint = collectChanges(repo, evidence.resolvedBase ?? EMPTY_TREE_BASE, { mode: "exact" }).fingerprint;
22986
- } catch (error) {
22987
- refreshError = error.message;
22988
- }
22989
- const stale = !currentFingerprint || currentFingerprint !== evidence.fingerprint;
23390
+ const freshness = inspectValidationEvidenceFreshness(repo, evidence);
23391
+ const { currentFingerprint, currentPlanFingerprint, stale } = freshness;
22990
23392
  const runChecksValid = (evidence.runChecksStatus !== void 0 ? evidence.runChecksStatus !== "not-verified" : evidence.ok && evidence.status !== "not-verified") && !stale;
22991
23393
  const valid = runChecksValid && evidence.verifyPassed === true;
22992
23394
  const hookConfigurationCurrent = session.agent !== "manual" && !!session.hookConfigFingerprint && agentHookConfigurationFingerprint(repo, session.agent) === session.hookConfigFingerprint;
@@ -23003,7 +23405,10 @@ function evidenceCmd(repo, opts = {}) {
23003
23405
  hookConfigurationCurrent,
23004
23406
  stale,
23005
23407
  currentFingerprint,
23006
- refreshError,
23408
+ currentPlanFingerprint,
23409
+ fingerprintStale: freshness.fingerprintStale,
23410
+ planStale: freshness.planStale,
23411
+ refreshError: freshness.error,
23007
23412
  hooks,
23008
23413
  nextActions: guidance.nextActions
23009
23414
  };
@@ -23023,8 +23428,9 @@ function evidenceCmd(repo, opts = {}) {
23023
23428
  info(`dirty at SessionStart: ${session.initialDirty.length ? session.initialDirty.join(", ") : "(none)"}`);
23024
23429
  if (evidence.verifyPassed !== void 0) info(`verify: ${evidence.verifyPassed ? "passed" : "failed"}`);
23025
23430
  else err("verify: no matching result was recorded");
23026
- if (refreshError) err(`cannot refresh current fingerprint: ${refreshError}`);
23431
+ if (freshness.error) err(`cannot refresh current validation plan: ${freshness.error}`);
23027
23432
  info(`checks: ${evidence.checks.map((check) => `${check.id}:${check.status}`).join(", ") || "(none)"}`);
23433
+ if (evidence.gates?.length) info(`validation gates: ${evidence.gates.join(", ")}`);
23028
23434
  if (evidence.waivers.length) {
23029
23435
  info("waivers:");
23030
23436
  for (const waiver of evidence.waivers) warn(`${waiver.kind}:${waiver.where} \u2014 ${waiver.reason}`);
@@ -23045,166 +23451,6 @@ var import_node_fs15 = require("node:fs");
23045
23451
 
23046
23452
  // src/commands/run-checks.ts
23047
23453
  var import_node_child_process6 = require("node:child_process");
23048
-
23049
- // src/planner.ts
23050
- var import_picomatch2 = __toESM(require_picomatch2(), 1);
23051
- function matchesAny(file, globs) {
23052
- if (!globs || globs.length === 0) return false;
23053
- return (0, import_picomatch2.default)(globs, { dot: true })(file);
23054
- }
23055
- function suggestionFor(mod, base) {
23056
- return mod.remediation ? mod.remediation : base;
23057
- }
23058
- function planChecks(m, input, opts = {}) {
23059
- const changeEntries = input.map((change) => typeof change === "string" ? { path: change, status: "M" } : change);
23060
- const changed = [...new Set(changeEntries.map((change) => change.path))];
23061
- const finalStatus = /* @__PURE__ */ new Map();
23062
- const layerPriority = { index: 1, worktree: 2, untracked: 3 };
23063
- for (const change of changeEntries) {
23064
- const priority = change.layer ? layerPriority[change.layer] : 4;
23065
- const previous = finalStatus.get(change.path);
23066
- if (!previous || priority >= previous.priority) finalStatus.set(change.path, { priority, status: change.status });
23067
- }
23068
- const modules = m.modules ?? [];
23069
- const compiled = modules.map((mod) => ({
23070
- mod,
23071
- owns: mod.owns?.length ? (0, import_picomatch2.default)(mod.owns, { dot: true }) : null,
23072
- tests: mod.tests?.length ? (0, import_picomatch2.default)(mod.tests, { dot: true }) : null
23073
- }));
23074
- const modulesWithOwns = compiled.filter((item) => item.owns !== null);
23075
- const gaps = [];
23076
- const notes = [];
23077
- const affectedModules = [];
23078
- const productionAffected = /* @__PURE__ */ new Set();
23079
- const matchedFiles = /* @__PURE__ */ new Set();
23080
- for (const item of compiled) {
23081
- const { mod } = item;
23082
- let productionHit = false;
23083
- let testHit = false;
23084
- for (const f of changed) {
23085
- if (item.owns?.(f)) {
23086
- productionHit = true;
23087
- matchedFiles.add(f);
23088
- }
23089
- if (item.tests?.(f)) {
23090
- testHit = true;
23091
- matchedFiles.add(f);
23092
- }
23093
- }
23094
- if (productionHit || testHit) affectedModules.push(mod);
23095
- if (productionHit) productionAffected.add(mod.name);
23096
- }
23097
- const unmapped = changed.filter((f) => !matchedFiles.has(f));
23098
- const requiredCoverage = m.validation?.required_coverage?.length ? (0, import_picomatch2.default)(m.validation.required_coverage, { dot: true }) : null;
23099
- const requiredUnmapped = requiredCoverage ? unmapped.filter((file) => requiredCoverage(file)) : [];
23100
- const advisoryUnmapped = unmapped.filter((file) => !requiredUnmapped.includes(file));
23101
- const checks = [];
23102
- const seen = /* @__PURE__ */ new Set();
23103
- const add = (id, reason) => {
23104
- if (seen.has(id)) return;
23105
- seen.add(id);
23106
- checks.push({ id, reason });
23107
- };
23108
- const profile = opts.profile ?? null;
23109
- if (profile) {
23110
- const set = m.validation?.checksets?.[profile];
23111
- if (!set) {
23112
- gaps.push({
23113
- kind: "unknown-profile",
23114
- where: profile,
23115
- why: `validation.checksets \u6CA1\u6709\u58F0\u660E profile: ${profile}`,
23116
- suggestion: "\u68C0\u67E5 --profile \u62FC\u5199\uFF0C\u6216\u5148\u5728 validation.checksets \u4E2D\u58F0\u660E\u5B83",
23117
- severity: "blocking"
23118
- });
23119
- } else {
23120
- for (const c of set.checks ?? []) add(c, `profile:${profile}`);
23121
- }
23122
- } else {
23123
- for (const mod of affectedModules) for (const c of mod.checks ?? []) add(c, `module:${mod.name}`);
23124
- if (affectedModules.length === 0)
23125
- for (const c of m.validation?.defaults?.no_match ?? []) add(c, "no_match");
23126
- }
23127
- for (const c of m.validation?.defaults?.always ?? []) add(c, "always");
23128
- if (modulesWithOwns.length === 0) {
23129
- gaps.push({
23130
- kind: "no-impact-map",
23131
- where: "modules",
23132
- why: "manifest \u6CA1\u6709\u4EFB\u4F55\u58F0\u660E owns \u7684\u6A21\u5757\uFF0C\u65E0\u6CD5\u6309\u5F71\u54CD\u9762\u9009\u6D4B",
23133
- suggestion: "\u5728 .agents/manifest.yaml \u7684 modules[] \u8865 owns/tests/checks\uFF0C\u8BA9\u6539\u52A8\u80FD\u6620\u5C04\u5230\u9A8C\u8BC1",
23134
- severity: "advisory"
23135
- });
23136
- }
23137
- for (const mod of affectedModules) {
23138
- if (!productionAffected.has(mod.name)) continue;
23139
- const testTouch = mod.test_touch ?? m.validation?.policies?.test_touch_default ?? "advisory";
23140
- if (!(mod.tests?.length ?? 0)) {
23141
- if (testTouch === "off") continue;
23142
- gaps.push({
23143
- kind: "module-without-tests",
23144
- where: mod.name,
23145
- why: `\u6A21\u5757 ${mod.name} \u672A\u58F0\u660E tests\uFF0C\u65E0\u56DE\u5F52\u7F51\u3001\u4E5F\u65E0\u6CD5\u5224\u65AD\u6D4B\u8BD5\u662F\u5426\u88AB\u8865`,
23146
- suggestion: suggestionFor(
23147
- mod,
23148
- `\u7ED9\u6A21\u5757 ${mod.name} \u58F0\u660E tests glob \u5E76\u8865\u6D4B\u8BD5${mod.playbook ? `\uFF1B\u53C2\u8003 playbook ${mod.playbook}` : ""}`
23149
- ),
23150
- severity: testTouch === "required" ? "blocking" : "advisory"
23151
- });
23152
- continue;
23153
- }
23154
- const testTouched = changed.some((path) => finalStatus.get(path)?.status !== "D" && matchesAny(path, mod.tests));
23155
- if (!testTouched && testTouch !== "off") {
23156
- gaps.push({
23157
- kind: "missing-test-touch",
23158
- where: mod.name,
23159
- why: `\u6539\u4E86 ${mod.name} \u7684\u751F\u4EA7\u4EE3\u7801\uFF0C\u4F46\u5B83\u7684\u6D4B\u8BD5(${mod.tests.join(", ")})\u4E00\u4E2A\u90FD\u6CA1\u52A8`,
23160
- suggestion: suggestionFor(
23161
- mod,
23162
- `\u5728 ${mod.tests.join(" / ")} \u8865\u8986\u76D6\u672C\u6B21\u6539\u52A8\u7684\u7528\u4F8B${mod.playbook ? `\uFF08\u53C2\u8003 playbook ${mod.playbook}\uFF09` : ""}\uFF0C\u6216 --waive missing-test-touch --where ${mod.name} --reason <\u7406\u7531>`
23163
- ),
23164
- severity: testTouch === "required" ? "blocking" : "advisory"
23165
- });
23166
- }
23167
- }
23168
- if (requiredUnmapped.length) {
23169
- const shown = requiredUnmapped.slice(0, 8).join(", ");
23170
- gaps.push({
23171
- kind: "unmapped-required-file",
23172
- where: shown + (requiredUnmapped.length > 8 ? ` \u2026(+${requiredUnmapped.length - 8})` : ""),
23173
- why: "\u8FD9\u4E9B\u6539\u52A8\u4F4D\u4E8E validation.required_coverage\uFF0C\u4F46\u4E0D\u5C5E\u4E8E\u4EFB\u4F55\u6A21\u5757\u7684 owns/tests",
23174
- suggestion: "\u628A\u6587\u4EF6\u52A0\u5165\u5DF2\u6709\u6A21\u5757\u7684 owns/tests\uFF0C\u6216\u65B0\u589E\u6A21\u5757\u5361\uFF1B\u5FC5\u9700\u8986\u76D6\u8303\u56F4\u4E0D\u80FD\u9759\u9ED8\u8DF3\u8FC7",
23175
- severity: "blocking"
23176
- });
23177
- }
23178
- if (advisoryUnmapped.length) {
23179
- const shown = advisoryUnmapped.slice(0, 8).join(", ");
23180
- gaps.push({
23181
- kind: "unmapped-file",
23182
- where: shown + (advisoryUnmapped.length > 8 ? ` \u2026(+${advisoryUnmapped.length - 8})` : ""),
23183
- why: "\u8FD9\u4E9B\u6539\u52A8\u6587\u4EF6\u4E0D\u5C5E\u4E8E\u4EFB\u4F55\u6A21\u5757\u7684 owns\uFF0C\u672A\u7EB3\u5165\u5F71\u54CD\u9762",
23184
- suggestion: "\u82E5\u5C5E\u4E8E\u5DF2\u6709\u6A21\u5757\uFF0C\u8865\u5176 owns\uFF1B\u82E5\u662F\u65B0\u6A21\u5757\uFF0C\u5728 modules[] \u58F0\u660E owns/tests/checks",
23185
- severity: "advisory"
23186
- });
23187
- }
23188
- if (changed.length > 0 && checks.length === 0 && !gaps.some((gap2) => gap2.kind === "unknown-profile")) {
23189
- gaps.push({
23190
- kind: "no-checks-selected",
23191
- where: "validation",
23192
- why: "\u6709\u6539\u52A8\uFF0C\u4F46\u6CA1\u6709\u89E3\u6790\u51FA\u4EFB\u4F55\u8981\u8DD1\u7684 check\uFF08\u547D\u4E2D\u6A21\u5757\u65E0 checks\uFF0C\u6216 profile/defaults \u4E3A\u7A7A\uFF09",
23193
- suggestion: "\u7ED9\u547D\u4E2D\u7684\u6A21\u5757\u58F0\u660E checks\uFF0C\u6216\u914D\u7F6E validation.defaults.no_match / profile checkset",
23194
- severity: "blocking"
23195
- });
23196
- }
23197
- if (affectedModules.length > 0) {
23198
- notes.push({
23199
- kind: "propagation-note",
23200
- message: "\u5F71\u54CD\u9762\u6309\u9759\u6001 glob \u8BA1\u7B97\uFF0C\u4E0D\u5206\u6790\u8DE8\u6A21\u5757\u4F9D\u8D56\uFF1B\u4E0B\u6E38\u6A21\u5757\u53EF\u80FD\u672A\u88AB\u9009\u4E2D",
23201
- suggestion: "\u82E5\u672C\u6B21\u6539\u7684\u662F\u5171\u4EAB/\u5E95\u5C42\u4EE3\u7801\uFF0C\u624B\u52A8\u786E\u8BA4\u4F9D\u8D56\u5B83\u7684\u6A21\u5757\u7684\u6D4B\u8BD5"
23202
- });
23203
- }
23204
- return { changed, affected: affectedModules.map((x) => x.name), checks, gaps, notes, profile };
23205
- }
23206
-
23207
- // src/commands/run-checks.ts
23208
23454
  var CHECK_BUDGET_MS = 7 * 60 * 1e3;
23209
23455
  var WAIVABLE_GAP_KINDS = /* @__PURE__ */ new Set([
23210
23456
  "missing-test-touch",
@@ -23230,7 +23476,7 @@ ${r.error.message}` : ""}`;
23230
23476
  return { ok: code === 0, code, logTail, durationMs: Date.now() - started };
23231
23477
  }
23232
23478
  function emptyPlan(changed, gaps = []) {
23233
- return { changed, affected: [], checks: [], gaps, notes: [], profile: null };
23479
+ return { changed, affected: [], gates: [], checks: [], gaps, notes: [], profile: null };
23234
23480
  }
23235
23481
  function outputJson(report) {
23236
23482
  process.stdout.write(JSON.stringify(report, null, 2) + "\n");
@@ -23243,8 +23489,11 @@ function evidenceOf(report) {
23243
23489
  requestedBase: report.requestedBase,
23244
23490
  resolvedBase: report.resolvedBase,
23245
23491
  fingerprint: report.fingerprint,
23492
+ profile: report.profile,
23493
+ planFingerprint: report.planFingerprint,
23246
23494
  changed: report.changed,
23247
23495
  affected: report.affected,
23496
+ gates: report.gates,
23248
23497
  checks: report.checks,
23249
23498
  gaps: report.gaps,
23250
23499
  notes: report.notes,
@@ -23255,6 +23504,7 @@ function evidenceOf(report) {
23255
23504
  }
23256
23505
  function reportHuman(report) {
23257
23506
  info(`run-checks (base ${report.requestedBase}) \u2014 ${report.changed.length} changed file(s), ${report.checks.length} check(s)`);
23507
+ if (report.gates.length) info(`validation gates: ${report.gates.join(", ")}`);
23258
23508
  for (const id of report.passed) ok(id);
23259
23509
  for (const skipped of report.skipped) err(`${skipped.id}: NOT RUN \u2014 ${skipped.reason}`);
23260
23510
  for (const failure of report.failed) {
@@ -23302,8 +23552,10 @@ function buildReport(args) {
23302
23552
  resolvedBase: changes.resolvedBase,
23303
23553
  fingerprint: changes.fingerprint,
23304
23554
  profile: plan.profile,
23555
+ planFingerprint: validationPlanFingerprint(plan),
23305
23556
  changed: changes.files,
23306
23557
  affected: plan.affected,
23558
+ gates: plan.gates,
23307
23559
  passed,
23308
23560
  failed,
23309
23561
  skipped,
@@ -23355,7 +23607,7 @@ function runChecksCmd(repo, opts) {
23355
23607
  errors.push(...manifestErrors.map((issue) => `manifest-invalid: ${issue.msg}`));
23356
23608
  let plan = emptyPlan(changes.files);
23357
23609
  if (manifest && !manifestErrors.length && changes.fingerprint) {
23358
- plan = planChecks(manifest, changes.entries, { profile: opts.profile });
23610
+ plan = planRepositoryChecks(repo, manifest, changes.entries, { profile: opts.profile });
23359
23611
  } else if (manifestErrors.length) {
23360
23612
  plan.gaps.push({
23361
23613
  kind: "manifest-invalid",
@@ -23647,7 +23899,7 @@ function hookEventCmd(repoInput, opts) {
23647
23899
  const verifyPassed = verify.code === 0 && !finalFingerprintError;
23648
23900
  let evidencePersisted = false;
23649
23901
  try {
23650
- evidencePersisted = markLatestVerifyResult(repo, token, verifyPassed, report?.fingerprint);
23902
+ evidencePersisted = markLatestVerifyResult(repo, token, verifyPassed, report?.fingerprint, report?.planFingerprint);
23651
23903
  } catch (error) {
23652
23904
  return block(opts.agent, opts.event, `harness-kit could not persist the final verify result: ${error.message}`);
23653
23905
  }
@@ -23866,7 +24118,7 @@ function planChecksCmd(repo, opts) {
23866
24118
  const kind = error instanceof GitDiffError ? error.kind : "diff-failed";
23867
24119
  errors.push(`${kind}: ${error.message}`);
23868
24120
  }
23869
- const plan = m && changes && !errors.length ? planChecks(m, changes.entries, { profile: opts.profile }) : null;
24121
+ const plan = m && changes && !errors.length ? planRepositoryChecks(repo, m, changes.entries, { profile: opts.profile }) : null;
23870
24122
  if (opts.json) {
23871
24123
  process.stdout.write(
23872
24124
  JSON.stringify(
@@ -23875,7 +24127,7 @@ function planChecksCmd(repo, opts) {
23875
24127
  requestedBase: base,
23876
24128
  resolvedBase: changes?.resolvedBase ?? null,
23877
24129
  fingerprint: changes?.fingerprint ?? "",
23878
- ...plan ?? { changed: changes?.files ?? [], affected: [], checks: [], gaps: [], notes: [], profile: opts.profile ?? null },
24130
+ ...plan ?? { changed: changes?.files ?? [], affected: [], gates: [], checks: [], gaps: [], notes: [], profile: opts.profile ?? null },
23879
24131
  errors
23880
24132
  },
23881
24133
  null,
@@ -23891,6 +24143,7 @@ function planChecksCmd(repo, opts) {
23891
24143
  }
23892
24144
  info(`plan-checks (base ${base} -> ${changes.resolvedBase ?? "empty tree"}) \u2014 ${changes.files.length} changed file(s)`);
23893
24145
  info(plan.affected.length ? `affected modules: ${plan.affected.join(", ")}` : "affected modules: (none)");
24146
+ info(plan.gates.length ? `validation gates: ${plan.gates.join(", ")}` : "validation gates: (none)");
23894
24147
  info("\nchecks to run:");
23895
24148
  if (!plan.checks.length) info(" (none)");
23896
24149
  for (const c of plan.checks) ok(`${c.id} [${c.reason}]`);