@erzhe/harness-kit 0.7.0 → 0.7.1

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 picomatch4 = (glob, options, returnState = false) => {
4945
+ var picomatch5 = (glob, options, returnState = false) => {
4946
4946
  if (Array.isArray(glob)) {
4947
- const fns = glob.map((input) => picomatch4(input, options, returnState));
4947
+ const fns = glob.map((input) => picomatch5(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 posix2 = opts.windows;
4963
- const regex = isState ? picomatch4.compileRe(glob, options) : picomatch4.makeRe(glob, options, false, true);
4963
+ const regex = isState ? picomatch5.compileRe(glob, options) : picomatch5.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 = picomatch4(opts.ignore, ignoreOpts, returnState);
4969
+ isIgnored = picomatch5(opts.ignore, ignoreOpts, returnState);
4970
4970
  }
4971
4971
  const matcher = (input, returnObject = false) => {
4972
- const { isMatch, match, output } = picomatch4.test(input, regex, options, { glob, posix: posix2 });
4972
+ const { isMatch, match, output } = picomatch5.test(input, regex, options, { glob, posix: posix2 });
4973
4973
  const result = { glob, state, regex, posix: posix2, 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
- picomatch4.test = (input, regex, options, { glob, posix: posix2 } = {}) => {
4998
+ picomatch5.test = (input, regex, options, { glob, posix: posix2 } = {}) => {
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 = picomatch4.matchBase(input, regex, options, posix2);
5015
+ match = picomatch5.matchBase(input, regex, options, posix2);
5016
5016
  } else {
5017
5017
  match = regex.exec(output);
5018
5018
  }
5019
5019
  }
5020
5020
  return { isMatch: Boolean(match), match, output };
5021
5021
  };
5022
- picomatch4.matchBase = (input, glob, options, posix2 = options && options.windows) => {
5023
- const regex = glob instanceof RegExp ? glob : picomatch4.makeRe(glob, options);
5022
+ picomatch5.matchBase = (input, glob, options, posix2 = options && options.windows) => {
5023
+ const regex = glob instanceof RegExp ? glob : picomatch5.makeRe(glob, options);
5024
5024
  return regex.test(utils.basename(input, { windows: posix2 }));
5025
5025
  };
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));
5026
+ picomatch5.isMatch = (str, patterns, options) => picomatch5(patterns, options)(str);
5027
+ picomatch5.parse = (pattern, options) => {
5028
+ if (Array.isArray(pattern)) return pattern.map((p) => picomatch5.parse(p, options));
5029
5029
  return parse(pattern, { ...options, fastpaths: false });
5030
5030
  };
5031
- picomatch4.scan = (input, options) => scan(input, options);
5032
- picomatch4.compileRe = (state, options, returnOutput = false, returnState = false) => {
5031
+ picomatch5.scan = (input, options) => scan(input, options);
5032
+ picomatch5.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 = picomatch4.toRegex(source, options);
5043
+ const regex = picomatch5.toRegex(source, options);
5044
5044
  if (returnState === true) {
5045
5045
  regex.state = state;
5046
5046
  }
5047
5047
  return regex;
5048
5048
  };
5049
- picomatch4.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
5049
+ picomatch5.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 picomatch4.compileRe(parsed, options, returnOutput, returnState);
5060
+ return picomatch5.compileRe(parsed, options, returnOutput, returnState);
5061
5061
  };
5062
- picomatch4.toRegex = (source, options) => {
5062
+ picomatch5.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
- picomatch4.constants = constants3;
5072
- module2.exports = picomatch4;
5071
+ picomatch5.constants = constants3;
5072
+ module2.exports = picomatch5;
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 picomatch4(glob, options, returnState = false) {
5082
+ function picomatch5(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(picomatch4, pico);
5089
- module2.exports = picomatch4;
5088
+ Object.assign(picomatch5, pico);
5089
+ module2.exports = picomatch5;
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 picomatch4 = (glob, options, returnState = false) => {
15401
+ var picomatch5 = (glob, options, returnState = false) => {
15402
15402
  if (Array.isArray(glob)) {
15403
- const fns = glob.map((input) => picomatch4(input, options, returnState));
15403
+ const fns = glob.map((input) => picomatch5(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 posix2 = utils.isWindows(options);
15419
- const regex = isState ? picomatch4.compileRe(glob, options) : picomatch4.makeRe(glob, options, false, true);
15419
+ const regex = isState ? picomatch5.compileRe(glob, options) : picomatch5.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 = picomatch4(opts.ignore, ignoreOpts, returnState);
15425
+ isIgnored = picomatch5(opts.ignore, ignoreOpts, returnState);
15426
15426
  }
15427
15427
  const matcher = (input, returnObject = false) => {
15428
- const { isMatch, match, output } = picomatch4.test(input, regex, options, { glob, posix: posix2 });
15428
+ const { isMatch, match, output } = picomatch5.test(input, regex, options, { glob, posix: posix2 });
15429
15429
  const result = { glob, state, regex, posix: posix2, 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
- picomatch4.test = (input, regex, options, { glob, posix: posix2 } = {}) => {
15454
+ picomatch5.test = (input, regex, options, { glob, posix: posix2 } = {}) => {
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 = picomatch4.matchBase(input, regex, options, posix2);
15471
+ match = picomatch5.matchBase(input, regex, options, posix2);
15472
15472
  } else {
15473
15473
  match = regex.exec(output);
15474
15474
  }
15475
15475
  }
15476
15476
  return { isMatch: Boolean(match), match, output };
15477
15477
  };
15478
- picomatch4.matchBase = (input, glob, options, posix2 = utils.isWindows(options)) => {
15479
- const regex = glob instanceof RegExp ? glob : picomatch4.makeRe(glob, options);
15478
+ picomatch5.matchBase = (input, glob, options, posix2 = utils.isWindows(options)) => {
15479
+ const regex = glob instanceof RegExp ? glob : picomatch5.makeRe(glob, options);
15480
15480
  return regex.test(path.basename(input));
15481
15481
  };
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));
15482
+ picomatch5.isMatch = (str, patterns, options) => picomatch5(patterns, options)(str);
15483
+ picomatch5.parse = (pattern, options) => {
15484
+ if (Array.isArray(pattern)) return pattern.map((p) => picomatch5.parse(p, options));
15485
15485
  return parse(pattern, { ...options, fastpaths: false });
15486
15486
  };
15487
- picomatch4.scan = (input, options) => scan(input, options);
15488
- picomatch4.compileRe = (state, options, returnOutput = false, returnState = false) => {
15487
+ picomatch5.scan = (input, options) => scan(input, options);
15488
+ picomatch5.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 = picomatch4.toRegex(source, options);
15499
+ const regex = picomatch5.toRegex(source, options);
15500
15500
  if (returnState === true) {
15501
15501
  regex.state = state;
15502
15502
  }
15503
15503
  return regex;
15504
15504
  };
15505
- picomatch4.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
15505
+ picomatch5.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 picomatch4.compileRe(parsed, options, returnOutput, returnState);
15516
+ return picomatch5.compileRe(parsed, options, returnOutput, returnState);
15517
15517
  };
15518
- picomatch4.toRegex = (source, options) => {
15518
+ picomatch5.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
- picomatch4.constants = constants3;
15528
- module2.exports = picomatch4;
15527
+ picomatch5.constants = constants3;
15528
+ module2.exports = picomatch5;
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 picomatch4 = require_picomatch4();
15546
+ var picomatch5 = 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 = picomatch4(String(patterns[i]), { ...options, onResult }, true);
15567
+ let isMatch = picomatch5(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) => picomatch4(pattern, options);
15596
- micromatch.isMatch = (str, patterns, options) => picomatch4(patterns, options)(str);
15595
+ micromatch.matcher = (pattern, options) => picomatch5(pattern, options);
15596
+ micromatch.isMatch = (str, patterns, options) => picomatch5(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 = picomatch4(String(pattern), options);
15643
+ let isMatch = picomatch5(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 = picomatch4(String(pattern), options);
15653
+ let isMatch = picomatch5(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) => picomatch4(p, options)(str));
15664
+ return [].concat(patterns).every((p) => picomatch5(p, options)(str));
15665
15665
  };
15666
15666
  micromatch.capture = (glob, input, options) => {
15667
15667
  let posix2 = utils.isWindows(options);
15668
- let regex = picomatch4.makeRe(String(glob), { ...options, capture: true });
15668
+ let regex = picomatch5.makeRe(String(glob), { ...options, capture: true });
15669
15669
  let match = regex.exec(posix2 ? 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) => picomatch4.makeRe(...args);
15675
- micromatch.scan = (...args) => picomatch4.scan(...args);
15674
+ micromatch.makeRe = (...args) => picomatch5.makeRe(...args);
15675
+ micromatch.scan = (...args) => picomatch5.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(picomatch4.parse(str, options));
15680
+ res.push(picomatch5.parse(str, options));
15681
15681
  }
15682
15682
  }
15683
15683
  return res;
@@ -18185,7 +18185,7 @@ var import_node_path21 = require("node:path");
18185
18185
  // package.json
18186
18186
  var package_default = {
18187
18187
  name: "@erzhe/harness-kit",
18188
- version: "0.7.0",
18188
+ version: "0.7.1",
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: [
@@ -18253,17 +18253,42 @@ var import_node_crypto4 = require("node:crypto");
18253
18253
  var import_node_fs6 = require("node:fs");
18254
18254
  var import_node_path6 = require("node:path");
18255
18255
 
18256
+ // src/harness-cli.ts
18257
+ var import_node_fs = require("node:fs");
18258
+ var import_node_path = require("node:path");
18259
+ var HARNESS_LOCK_REL = ".agents/harness.lock.json";
18260
+ var HARNESS_PACKAGE = package_default.name;
18261
+ var SAFE_VERSION = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
18262
+ function lockedHarnessVersion(repo) {
18263
+ const path = (0, import_node_path.join)(repo, HARNESS_LOCK_REL);
18264
+ try {
18265
+ if (!(0, import_node_fs.lstatSync)(path).isFile()) return null;
18266
+ const value = JSON.parse((0, import_node_fs.readFileSync)(path, "utf8"));
18267
+ if (value?.package !== HARNESS_PACKAGE || typeof value.version !== "string") return null;
18268
+ return SAFE_VERSION.test(value.version) ? value.version : null;
18269
+ } catch {
18270
+ return null;
18271
+ }
18272
+ }
18273
+ function harnessInvocation(version) {
18274
+ const pinned = version && SAFE_VERSION.test(version) ? version : "latest";
18275
+ return `npx -y ${HARNESS_PACKAGE}@${pinned}`;
18276
+ }
18277
+ function repoHarnessInvocation(repo) {
18278
+ return harnessInvocation(lockedHarnessVersion(repo));
18279
+ }
18280
+
18256
18281
  // src/manifest.ts
18257
- var import_node_fs2 = require("node:fs");
18258
- var import_node_path2 = require("node:path");
18282
+ var import_node_fs3 = require("node:fs");
18283
+ var import_node_path3 = require("node:path");
18259
18284
  var import_picomatch = __toESM(require_picomatch2(), 1);
18260
18285
  var import_yaml = __toESM(require_dist(), 1);
18261
18286
 
18262
18287
  // src/contracts.ts
18263
18288
  var import_node_child_process = require("node:child_process");
18264
18289
  var import_node_crypto = require("node:crypto");
18265
- var import_node_fs = require("node:fs");
18266
- var import_node_path = require("node:path");
18290
+ var import_node_fs2 = require("node:fs");
18291
+ var import_node_path2 = require("node:path");
18267
18292
  var CONTRACT_ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
18268
18293
  var WINDOWS_RESERVED_STEM_RE = /^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i;
18269
18294
  var CONTRACTS_REL = ".agents/contracts";
@@ -18275,11 +18300,11 @@ function assertSafeContractId(id) {
18275
18300
  throw new Error(`unsafe contract id "${id}": use a portable 1-128 character ASCII filename (letters, digits, dot, underscore, or hyphen; no reserved device stem)`);
18276
18301
  }
18277
18302
  function contractsDirectory(repo) {
18278
- return (0, import_node_path.resolve)(repo, CONTRACTS_REL);
18303
+ return (0, import_node_path2.resolve)(repo, CONTRACTS_REL);
18279
18304
  }
18280
18305
  function lstatIfExists(path) {
18281
18306
  try {
18282
- return (0, import_node_fs.lstatSync)(path);
18307
+ return (0, import_node_fs2.lstatSync)(path);
18283
18308
  } catch (error) {
18284
18309
  if (error.code === "ENOENT") return null;
18285
18310
  throw error;
@@ -18289,26 +18314,26 @@ function safeDirectory(path, label, create) {
18289
18314
  let stat = lstatIfExists(path);
18290
18315
  if (!stat) {
18291
18316
  if (!create) return false;
18292
- (0, import_node_fs.mkdirSync)(path);
18293
- stat = (0, import_node_fs.lstatSync)(path);
18317
+ (0, import_node_fs2.mkdirSync)(path);
18318
+ stat = (0, import_node_fs2.lstatSync)(path);
18294
18319
  }
18295
18320
  if (!stat.isDirectory() || stat.isSymbolicLink()) throw new Error(`${label} must be a real directory, not a symlink or other file`);
18296
18321
  return true;
18297
18322
  }
18298
18323
  function ensureSafeContractDirectory(repo, create) {
18299
- const repoRoot = (0, import_node_path.resolve)(repo);
18300
- const agents = (0, import_node_path.resolve)(repoRoot, ".agents");
18324
+ const repoRoot = (0, import_node_path2.resolve)(repo);
18325
+ const agents = (0, import_node_path2.resolve)(repoRoot, ".agents");
18301
18326
  if (!safeDirectory(agents, ".agents", create)) return null;
18302
18327
  const contracts = contractsDirectory(repoRoot);
18303
- if ((0, import_node_path.dirname)(contracts) !== agents) throw new Error("contract storage escaped .agents");
18328
+ if ((0, import_node_path2.dirname)(contracts) !== agents) throw new Error("contract storage escaped .agents");
18304
18329
  if (!safeDirectory(contracts, CONTRACTS_REL, create)) return null;
18305
18330
  return contracts;
18306
18331
  }
18307
18332
  function baselinePath(repo, id) {
18308
18333
  assertSafeContractId(id);
18309
18334
  const root = contractsDirectory(repo);
18310
- const candidate = (0, import_node_path.resolve)(root, `${id}.snapshot`);
18311
- if ((0, import_node_path.dirname)(candidate) !== root) throw new Error(`contract baseline escaped ${CONTRACTS_REL}`);
18335
+ const candidate = (0, import_node_path2.resolve)(root, `${id}.snapshot`);
18336
+ if ((0, import_node_path2.dirname)(candidate) !== root) throw new Error(`contract baseline escaped ${CONTRACTS_REL}`);
18312
18337
  return candidate;
18313
18338
  }
18314
18339
  var DEFAULT_COMMAND_TIMEOUT_MS = 2 * 60 * 1e3;
@@ -18334,7 +18359,7 @@ function readBaseline(repo, id) {
18334
18359
  const stat = lstatIfExists(path);
18335
18360
  if (!stat) return null;
18336
18361
  if (!stat.isFile() || stat.isSymbolicLink()) throw new Error(`${CONTRACTS_REL}/${id}.snapshot must be a regular file`);
18337
- return (0, import_node_fs.readFileSync)(path, "utf8");
18362
+ return (0, import_node_fs2.readFileSync)(path, "utf8");
18338
18363
  }
18339
18364
  function writeBaseline(repo, id, content) {
18340
18365
  const path = baselinePath(repo, id);
@@ -18344,14 +18369,14 @@ function writeBaseline(repo, id, content) {
18344
18369
  const stat = existing;
18345
18370
  if (!stat.isFile() || stat.isSymbolicLink()) throw new Error(`${CONTRACTS_REL}/${id}.snapshot must be a regular file`);
18346
18371
  }
18347
- const temp = (0, import_node_path.resolve)(directory, `.${(0, import_node_path.basename)(path)}.tmp-${process.pid}-${(0, import_node_crypto.randomBytes)(8).toString("hex")}`);
18348
- if ((0, import_node_path.dirname)(temp) !== directory) throw new Error(`temporary contract baseline escaped ${CONTRACTS_REL}`);
18372
+ const temp = (0, import_node_path2.resolve)(directory, `.${(0, import_node_path2.basename)(path)}.tmp-${process.pid}-${(0, import_node_crypto.randomBytes)(8).toString("hex")}`);
18373
+ if ((0, import_node_path2.dirname)(temp) !== directory) throw new Error(`temporary contract baseline escaped ${CONTRACTS_REL}`);
18349
18374
  try {
18350
- (0, import_node_fs.writeFileSync)(temp, content, { encoding: "utf8", flag: "wx" });
18351
- (0, import_node_fs.renameSync)(temp, path);
18375
+ (0, import_node_fs2.writeFileSync)(temp, content, { encoding: "utf8", flag: "wx" });
18376
+ (0, import_node_fs2.renameSync)(temp, path);
18352
18377
  } finally {
18353
18378
  try {
18354
- (0, import_node_fs.unlinkSync)(temp);
18379
+ (0, import_node_fs2.unlinkSync)(temp);
18355
18380
  } catch {
18356
18381
  }
18357
18382
  }
@@ -18362,14 +18387,14 @@ var MANIFEST_REL = ".agents/manifest.yaml";
18362
18387
  var SUPPORTED_MANIFEST_SPECS = ["ai-harness/v0", "ai-harness/v1"];
18363
18388
  var MAX_GLOB_PATTERN_LENGTH = 4096;
18364
18389
  function manifestPath(repo) {
18365
- return (0, import_node_path2.join)(repo, MANIFEST_REL);
18390
+ return (0, import_node_path3.join)(repo, MANIFEST_REL);
18366
18391
  }
18367
18392
  function loadManifest(repo) {
18368
18393
  const p = manifestPath(repo);
18369
- if (!(0, import_node_fs2.existsSync)(p)) {
18394
+ if (!(0, import_node_fs3.existsSync)(p)) {
18370
18395
  throw new Error(`\u672A\u627E\u5230 ${MANIFEST_REL}\uFF08\u5728 ${repo}\uFF09\u3002\u5148\u8DD1 \`harness-kit init\`\u3002`);
18371
18396
  }
18372
- const parsed = import_yaml.default.parse((0, import_node_fs2.readFileSync)(p, "utf8"));
18397
+ const parsed = import_yaml.default.parse((0, import_node_fs3.readFileSync)(p, "utf8"));
18373
18398
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error(`${MANIFEST_REL} \u6839\u8282\u70B9\u5FC5\u987B\u662F\u5BF9\u8C61`);
18374
18399
  return parsed;
18375
18400
  }
@@ -18447,7 +18472,7 @@ function validateManifest(m) {
18447
18472
  function checkRelativePath(value, prefix) {
18448
18473
  if (typeof value !== "string") return;
18449
18474
  const components = value.split(/[\\/]/);
18450
- if (!value || value.includes("\0") || (0, import_node_path2.isAbsolute)(value) || components.includes(".."))
18475
+ if (!value || value.includes("\0") || (0, import_node_path3.isAbsolute)(value) || components.includes(".."))
18451
18476
  issues.push({ level: "error", msg: `${prefix} \u5FC5\u987B\u662F\u58F0\u660E\u6839\u76EE\u5F55\u5185\u7684\u975E\u7A7A\u76F8\u5BF9\u8DEF\u5F84\uFF0C\u4E0D\u80FD\u8D8A\u754C: ${value}` });
18452
18477
  }
18453
18478
  function checkRelativePaths(value, prefix) {
@@ -18761,8 +18786,8 @@ function validateManifest(m) {
18761
18786
 
18762
18787
  // src/managed-files.ts
18763
18788
  var import_node_crypto2 = require("node:crypto");
18764
- var import_node_fs3 = require("node:fs");
18765
- var import_node_path3 = require("node:path");
18789
+ var import_node_fs4 = require("node:fs");
18790
+ var import_node_path4 = require("node:path");
18766
18791
  function isErrno(error, code) {
18767
18792
  return error?.code === code;
18768
18793
  }
@@ -18783,29 +18808,29 @@ function sameIdentity(left, right) {
18783
18808
  return left.dev === right.dev && left.ino === right.ino && left.mode === right.mode && left.size === right.size && left.mtimeMs === right.mtimeMs;
18784
18809
  }
18785
18810
  function inside(root, candidate) {
18786
- const rel = (0, import_node_path3.relative)(root, candidate);
18787
- return rel === "" || rel !== ".." && !rel.startsWith(`..${import_node_path3.sep}`) && !(0, import_node_path3.isAbsolute)(rel);
18811
+ const rel = (0, import_node_path4.relative)(root, candidate);
18812
+ return rel === "" || rel !== ".." && !rel.startsWith(`..${import_node_path4.sep}`) && !(0, import_node_path4.isAbsolute)(rel);
18788
18813
  }
18789
18814
  function repositoryRoot(repo) {
18790
18815
  let root;
18791
18816
  try {
18792
- root = (0, import_node_fs3.realpathSync)(repo);
18817
+ root = (0, import_node_fs4.realpathSync)(repo);
18793
18818
  } catch (error) {
18794
18819
  throw new Error(`cannot resolve repository root ${repo}: ${errorMessage(error)}`);
18795
18820
  }
18796
- if (!(0, import_node_fs3.statSync)(root).isDirectory()) throw new Error(`repository root is not a directory: ${repo}`);
18821
+ if (!(0, import_node_fs4.statSync)(root).isDirectory()) throw new Error(`repository root is not a directory: ${repo}`);
18797
18822
  return root;
18798
18823
  }
18799
18824
  function targetPath(root, relativePath) {
18800
18825
  if (typeof relativePath !== "string" || relativePath.length === 0 || relativePath.includes("\0")) {
18801
18826
  throw new Error("generated target path must be a non-empty string");
18802
18827
  }
18803
- if ((0, import_node_path3.isAbsolute)(relativePath)) throw new Error(`generated target path must be relative: ${relativePath}`);
18804
- const normalized = (0, import_node_path3.normalize)(relativePath);
18805
- if (normalized === ".." || normalized.startsWith(`..${import_node_path3.sep}`)) {
18828
+ if ((0, import_node_path4.isAbsolute)(relativePath)) throw new Error(`generated target path must be relative: ${relativePath}`);
18829
+ const normalized = (0, import_node_path4.normalize)(relativePath);
18830
+ if (normalized === ".." || normalized.startsWith(`..${import_node_path4.sep}`)) {
18806
18831
  throw new Error(`generated target path escapes repository: ${relativePath}`);
18807
18832
  }
18808
- const absolutePath = (0, import_node_path3.resolve)(root, relativePath);
18833
+ const absolutePath = (0, import_node_path4.resolve)(root, relativePath);
18809
18834
  if (absolutePath === root || !inside(root, absolutePath)) {
18810
18835
  throw new Error(`generated target path escapes repository: ${relativePath}`);
18811
18836
  }
@@ -18816,12 +18841,12 @@ function preflightParent(root, parent, relativePath) {
18816
18841
  while (true) {
18817
18842
  let stat;
18818
18843
  try {
18819
- stat = (0, import_node_fs3.lstatSync)(cursor);
18844
+ stat = (0, import_node_fs4.lstatSync)(cursor);
18820
18845
  } catch (error) {
18821
18846
  if (!isErrno(error, "ENOENT")) {
18822
18847
  throw new Error(`cannot inspect parent for ${relativePath}: ${errorMessage(error)}`);
18823
18848
  }
18824
- const next = (0, import_node_path3.dirname)(cursor);
18849
+ const next = (0, import_node_path4.dirname)(cursor);
18825
18850
  if (next === cursor || !inside(root, next)) {
18826
18851
  throw new Error(`target ${relativePath} parent escapes repository`);
18827
18852
  }
@@ -18830,7 +18855,7 @@ function preflightParent(root, parent, relativePath) {
18830
18855
  }
18831
18856
  let resolvedParent;
18832
18857
  try {
18833
- resolvedParent = (0, import_node_fs3.realpathSync)(cursor);
18858
+ resolvedParent = (0, import_node_fs4.realpathSync)(cursor);
18834
18859
  } catch (error) {
18835
18860
  throw new Error(`cannot resolve parent for ${relativePath}: ${errorMessage(error)}`);
18836
18861
  }
@@ -18843,37 +18868,37 @@ function preflightParent(root, parent, relativePath) {
18843
18868
  if (!stat.isDirectory()) {
18844
18869
  throw new Error(`target ${relativePath} parent is not a directory`);
18845
18870
  }
18846
- if (!(0, import_node_fs3.statSync)(resolvedParent).isDirectory()) {
18871
+ if (!(0, import_node_fs4.statSync)(resolvedParent).isDirectory()) {
18847
18872
  throw new Error(`target ${relativePath} parent is not a directory`);
18848
18873
  }
18849
18874
  return;
18850
18875
  }
18851
18876
  }
18852
18877
  function ensureSafeParent(root, parent, relativePath) {
18853
- const rel = (0, import_node_path3.relative)(root, parent);
18878
+ const rel = (0, import_node_path4.relative)(root, parent);
18854
18879
  if (!inside(root, parent)) throw new Error(`target ${relativePath} parent escapes repository`);
18855
18880
  let cursor = root;
18856
- for (const component of rel.split(import_node_path3.sep).filter(Boolean)) {
18857
- cursor = (0, import_node_path3.join)(cursor, component);
18881
+ for (const component of rel.split(import_node_path4.sep).filter(Boolean)) {
18882
+ cursor = (0, import_node_path4.join)(cursor, component);
18858
18883
  let stat;
18859
18884
  try {
18860
- stat = (0, import_node_fs3.lstatSync)(cursor);
18885
+ stat = (0, import_node_fs4.lstatSync)(cursor);
18861
18886
  } catch (error) {
18862
18887
  if (!isErrno(error, "ENOENT")) {
18863
18888
  throw new Error(`cannot inspect parent for ${relativePath}: ${errorMessage(error)}`);
18864
18889
  }
18865
18890
  try {
18866
- (0, import_node_fs3.mkdirSync)(cursor);
18891
+ (0, import_node_fs4.mkdirSync)(cursor);
18867
18892
  } catch (mkdirError) {
18868
18893
  if (!isErrno(mkdirError, "EEXIST")) {
18869
18894
  throw new Error(`cannot create parent for ${relativePath}: ${errorMessage(mkdirError)}`);
18870
18895
  }
18871
18896
  }
18872
- stat = (0, import_node_fs3.lstatSync)(cursor);
18897
+ stat = (0, import_node_fs4.lstatSync)(cursor);
18873
18898
  }
18874
18899
  let resolvedParent;
18875
18900
  try {
18876
- resolvedParent = (0, import_node_fs3.realpathSync)(cursor);
18901
+ resolvedParent = (0, import_node_fs4.realpathSync)(cursor);
18877
18902
  } catch (error) {
18878
18903
  throw new Error(`cannot resolve parent for ${relativePath}: ${errorMessage(error)}`);
18879
18904
  }
@@ -18886,37 +18911,37 @@ function ensureSafeParent(root, parent, relativePath) {
18886
18911
  if (!stat.isDirectory()) {
18887
18912
  throw new Error(`target ${relativePath} parent is not a directory`);
18888
18913
  }
18889
- if (!(0, import_node_fs3.statSync)(resolvedParent).isDirectory()) {
18914
+ if (!(0, import_node_fs4.statSync)(resolvedParent).isDirectory()) {
18890
18915
  throw new Error(`target ${relativePath} parent is not a directory`);
18891
18916
  }
18892
18917
  }
18893
18918
  }
18894
18919
  function openRegularNoFollow(path, expected) {
18895
- const fd = (0, import_node_fs3.openSync)(path, import_node_fs3.constants.O_RDONLY | import_node_fs3.constants.O_NOFOLLOW);
18920
+ const fd = (0, import_node_fs4.openSync)(path, import_node_fs4.constants.O_RDONLY | import_node_fs4.constants.O_NOFOLLOW);
18896
18921
  try {
18897
- const opened = (0, import_node_fs3.fstatSync)(fd);
18922
+ const opened = (0, import_node_fs4.fstatSync)(fd);
18898
18923
  if (!opened.isFile()) throw new Error("target is no longer a regular file");
18899
18924
  const identity = identityOf(opened);
18900
18925
  if (!sameIdentity(expected, identity)) throw new Error("target changed during preflight");
18901
18926
  return { fd, identity };
18902
18927
  } catch (error) {
18903
- (0, import_node_fs3.closeSync)(fd);
18928
+ (0, import_node_fs4.closeSync)(fd);
18904
18929
  throw error;
18905
18930
  }
18906
18931
  }
18907
18932
  function allowedClaudeAlias(root, absolutePath, linkTarget) {
18908
- if (absolutePath !== (0, import_node_path3.join)(root, "CLAUDE.md") || (0, import_node_path3.isAbsolute)(linkTarget)) return false;
18909
- const normalized = (0, import_node_path3.normalize)(linkTarget);
18910
- if (normalized === ".." || normalized.startsWith(`..${import_node_path3.sep}`)) return false;
18911
- return (0, import_node_path3.resolve)((0, import_node_path3.dirname)(absolutePath), linkTarget) === (0, import_node_path3.join)(root, "AGENTS.md");
18933
+ if (absolutePath !== (0, import_node_path4.join)(root, "CLAUDE.md") || (0, import_node_path4.isAbsolute)(linkTarget)) return false;
18934
+ const normalized = (0, import_node_path4.normalize)(linkTarget);
18935
+ if (normalized === ".." || normalized.startsWith(`..${import_node_path4.sep}`)) return false;
18936
+ return (0, import_node_path4.resolve)((0, import_node_path4.dirname)(absolutePath), linkTarget) === (0, import_node_path4.join)(root, "AGENTS.md");
18912
18937
  }
18913
18938
  function inspectOne(root, relativePath, content) {
18914
18939
  if (typeof content !== "string") throw new Error(`generated content for ${relativePath} must be a string`);
18915
18940
  const absolutePath = targetPath(root, relativePath);
18916
- preflightParent(root, (0, import_node_path3.dirname)(absolutePath), relativePath);
18941
+ preflightParent(root, (0, import_node_path4.dirname)(absolutePath), relativePath);
18917
18942
  let stat;
18918
18943
  try {
18919
- stat = (0, import_node_fs3.lstatSync)(absolutePath);
18944
+ stat = (0, import_node_fs4.lstatSync)(absolutePath);
18920
18945
  } catch (error) {
18921
18946
  if (isErrno(error, "ENOENT")) {
18922
18947
  return {
@@ -18934,7 +18959,7 @@ function inspectOne(root, relativePath, content) {
18934
18959
  }
18935
18960
  const identity = identityOf(stat);
18936
18961
  if (stat.isSymbolicLink()) {
18937
- const linkTarget = (0, import_node_fs3.readlinkSync)(absolutePath);
18962
+ const linkTarget = (0, import_node_fs4.readlinkSync)(absolutePath);
18938
18963
  if (!allowedClaudeAlias(root, absolutePath, linkTarget)) {
18939
18964
  throw new Error(`target ${relativePath} is an unsafe symlink; only CLAUDE.md -> AGENTS.md is allowed`);
18940
18965
  }
@@ -18953,7 +18978,7 @@ function inspectOne(root, relativePath, content) {
18953
18978
  if (!stat.isFile()) throw new Error(`target ${relativePath} is not a regular file`);
18954
18979
  const opened = openRegularNoFollow(absolutePath, identity);
18955
18980
  try {
18956
- const currentContent = (0, import_node_fs3.readFileSync)(opened.fd, "utf8");
18981
+ const currentContent = (0, import_node_fs4.readFileSync)(opened.fd, "utf8");
18957
18982
  return {
18958
18983
  relativePath,
18959
18984
  absolutePath,
@@ -18965,7 +18990,7 @@ function inspectOne(root, relativePath, content) {
18965
18990
  identity: opened.identity
18966
18991
  };
18967
18992
  } finally {
18968
- (0, import_node_fs3.closeSync)(opened.fd);
18993
+ (0, import_node_fs4.closeSync)(opened.fd);
18969
18994
  }
18970
18995
  }
18971
18996
  function preflightTargets(repo, targets) {
@@ -18994,18 +19019,18 @@ function inspectManagedFiles(repo, targets) {
18994
19019
  return preflightTargets(repo, targets).targets.map(publicInspection);
18995
19020
  }
18996
19021
  function siblingArtifact(path, role) {
18997
- return (0, import_node_path3.join)((0, import_node_path3.dirname)(path), `.${(0, import_node_path3.basename)(path)}.harness-kit-${process.pid}-${(0, import_node_crypto2.randomUUID)()}.${role}`);
19022
+ return (0, import_node_path4.join)((0, import_node_path4.dirname)(path), `.${(0, import_node_path4.basename)(path)}.harness-kit-${process.pid}-${(0, import_node_crypto2.randomUUID)()}.${role}`);
18998
19023
  }
18999
19024
  function writeExclusive(path, content, mode) {
19000
- const fd = (0, import_node_fs3.openSync)(
19025
+ const fd = (0, import_node_fs4.openSync)(
19001
19026
  path,
19002
- import_node_fs3.constants.O_WRONLY | import_node_fs3.constants.O_CREAT | import_node_fs3.constants.O_EXCL | import_node_fs3.constants.O_NOFOLLOW,
19027
+ import_node_fs4.constants.O_WRONLY | import_node_fs4.constants.O_CREAT | import_node_fs4.constants.O_EXCL | import_node_fs4.constants.O_NOFOLLOW,
19003
19028
  mode & 511
19004
19029
  );
19005
19030
  try {
19006
- (0, import_node_fs3.writeFileSync)(fd, content);
19031
+ (0, import_node_fs4.writeFileSync)(fd, content);
19007
19032
  } finally {
19008
- (0, import_node_fs3.closeSync)(fd);
19033
+ (0, import_node_fs4.closeSync)(fd);
19009
19034
  }
19010
19035
  }
19011
19036
  function unchanged(previous, current) {
@@ -19026,7 +19051,7 @@ function assertTargetStillCurrent(root, target) {
19026
19051
  }
19027
19052
  function removeBestEffort(path) {
19028
19053
  try {
19029
- (0, import_node_fs3.unlinkSync)(path);
19054
+ (0, import_node_fs4.unlinkSync)(path);
19030
19055
  } catch (error) {
19031
19056
  if (!isErrno(error, "ENOENT")) {
19032
19057
  }
@@ -19034,7 +19059,7 @@ function removeBestEffort(path) {
19034
19059
  }
19035
19060
  function currentIdentity(path) {
19036
19061
  try {
19037
- return identityOf((0, import_node_fs3.lstatSync)(path));
19062
+ return identityOf((0, import_node_fs4.lstatSync)(path));
19038
19063
  } catch (error) {
19039
19064
  if (isErrno(error, "ENOENT")) return null;
19040
19065
  throw error;
@@ -19046,10 +19071,10 @@ function restoreDisplacedRegular(item) {
19046
19071
  if (current !== null) {
19047
19072
  if (item.installedIdentity === null || !sameIdentity(item.installedIdentity, current))
19048
19073
  throw new Error("target changed during transaction; preserving the newer path and rollback backup");
19049
- (0, import_node_fs3.unlinkSync)(item.target.absolutePath);
19074
+ (0, import_node_fs4.unlinkSync)(item.target.absolutePath);
19050
19075
  }
19051
- (0, import_node_fs3.linkSync)(item.backupPath, item.target.absolutePath);
19052
- (0, import_node_fs3.unlinkSync)(item.backupPath);
19076
+ (0, import_node_fs4.linkSync)(item.backupPath, item.target.absolutePath);
19077
+ (0, import_node_fs4.unlinkSync)(item.backupPath);
19053
19078
  item.backupCreated = false;
19054
19079
  item.installedIdentity = null;
19055
19080
  }
@@ -19072,7 +19097,7 @@ function rollback(staged) {
19072
19097
  throw new Error("target changed after transaction write; preserving the newer path and rollback backup");
19073
19098
  if (item.target.kind === "missing") {
19074
19099
  try {
19075
- (0, import_node_fs3.unlinkSync)(item.target.absolutePath);
19100
+ (0, import_node_fs4.unlinkSync)(item.target.absolutePath);
19076
19101
  } catch (error) {
19077
19102
  if (!isErrno(error, "ENOENT")) throw error;
19078
19103
  }
@@ -19101,10 +19126,10 @@ function assertInstalledTargetsStillCurrent(staged) {
19101
19126
  throw new Error(`generated target changed during transaction: ${item.target.relativePath}`);
19102
19127
  const opened = openRegularNoFollow(item.target.absolutePath, item.installedIdentity);
19103
19128
  try {
19104
- if ((0, import_node_fs3.readFileSync)(opened.fd, "utf8") !== item.target.content)
19129
+ if ((0, import_node_fs4.readFileSync)(opened.fd, "utf8") !== item.target.content)
19105
19130
  throw new Error(`generated target content changed during transaction: ${item.target.relativePath}`);
19106
19131
  } finally {
19107
- (0, import_node_fs3.closeSync)(opened.fd);
19132
+ (0, import_node_fs4.closeSync)(opened.fd);
19108
19133
  }
19109
19134
  }
19110
19135
  }
@@ -19115,22 +19140,22 @@ function writeManagedFiles(repo, targets, options = {}) {
19115
19140
  (target) => target.kind !== "allowed-alias" && !target.satisfiesDesired
19116
19141
  );
19117
19142
  const staged = [];
19118
- const rename = options.rename ?? import_node_fs3.renameSync;
19119
- const link = options.link ?? import_node_fs3.linkSync;
19143
+ const rename = options.rename ?? import_node_fs4.renameSync;
19144
+ const link = options.link ?? import_node_fs4.linkSync;
19120
19145
  try {
19121
19146
  for (const target of writable) {
19122
- ensureSafeParent(preflight.root, (0, import_node_path3.dirname)(target.absolutePath), target.relativePath);
19147
+ ensureSafeParent(preflight.root, (0, import_node_path4.dirname)(target.absolutePath), target.relativePath);
19123
19148
  const tempPath = siblingArtifact(target.absolutePath, "tmp");
19124
19149
  const backupPath = target.kind === "regular" ? siblingArtifact(target.absolutePath, "backup") : null;
19125
19150
  const mode = target.identity?.mode ?? 438;
19126
19151
  writeExclusive(tempPath, target.content, mode);
19127
- if (target.identity !== null) (0, import_node_fs3.chmodSync)(tempPath, target.identity.mode & 511);
19152
+ if (target.identity !== null) (0, import_node_fs4.chmodSync)(tempPath, target.identity.mode & 511);
19128
19153
  const item = {
19129
19154
  target,
19130
19155
  tempPath,
19131
19156
  backupPath,
19132
19157
  backupCreated: false,
19133
- replacementIdentity: identityOf((0, import_node_fs3.lstatSync)(tempPath)),
19158
+ replacementIdentity: identityOf((0, import_node_fs4.lstatSync)(tempPath)),
19134
19159
  installedIdentity: null
19135
19160
  };
19136
19161
  staged.push(item);
@@ -19141,19 +19166,19 @@ function writeManagedFiles(repo, targets, options = {}) {
19141
19166
  if (item.target.kind === "missing") {
19142
19167
  link(item.tempPath, item.target.absolutePath);
19143
19168
  item.installedIdentity = item.replacementIdentity;
19144
- (0, import_node_fs3.unlinkSync)(item.tempPath);
19169
+ (0, import_node_fs4.unlinkSync)(item.tempPath);
19145
19170
  } else {
19146
19171
  if (item.backupPath === null || item.target.identity === null)
19147
19172
  throw new Error(`regular target has no displacement backup: ${item.target.relativePath}`);
19148
19173
  rename(item.target.absolutePath, item.backupPath);
19149
19174
  item.backupCreated = true;
19150
- const displacedIdentity = identityOf((0, import_node_fs3.lstatSync)(item.backupPath));
19151
- const displacedContent = (0, import_node_fs3.readFileSync)(item.backupPath, "utf8");
19175
+ const displacedIdentity = identityOf((0, import_node_fs4.lstatSync)(item.backupPath));
19176
+ const displacedContent = (0, import_node_fs4.readFileSync)(item.backupPath, "utf8");
19152
19177
  if (!sameIdentity(item.target.identity, displacedIdentity) || displacedContent !== item.target.currentContent)
19153
19178
  throw new Error(`generated target changed during commit: ${item.target.relativePath}`);
19154
19179
  link(item.tempPath, item.target.absolutePath);
19155
19180
  item.installedIdentity = item.replacementIdentity;
19156
- (0, import_node_fs3.unlinkSync)(item.tempPath);
19181
+ (0, import_node_fs4.unlinkSync)(item.tempPath);
19157
19182
  }
19158
19183
  }
19159
19184
  assertInstalledTargetsStillCurrent(staged);
@@ -19171,31 +19196,6 @@ function writeManagedFiles(repo, targets, options = {}) {
19171
19196
  };
19172
19197
  }
19173
19198
 
19174
- // src/harness-cli.ts
19175
- var import_node_fs4 = require("node:fs");
19176
- var import_node_path4 = require("node:path");
19177
- var HARNESS_LOCK_REL = ".agents/harness.lock.json";
19178
- var HARNESS_PACKAGE = package_default.name;
19179
- var SAFE_VERSION = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
19180
- function lockedHarnessVersion(repo) {
19181
- const path = (0, import_node_path4.join)(repo, HARNESS_LOCK_REL);
19182
- try {
19183
- if (!(0, import_node_fs4.lstatSync)(path).isFile()) return null;
19184
- const value = JSON.parse((0, import_node_fs4.readFileSync)(path, "utf8"));
19185
- if (value?.package !== HARNESS_PACKAGE || typeof value.version !== "string") return null;
19186
- return SAFE_VERSION.test(value.version) ? value.version : null;
19187
- } catch {
19188
- return null;
19189
- }
19190
- }
19191
- function harnessInvocation(version) {
19192
- const pinned = version && SAFE_VERSION.test(version) ? version : "latest";
19193
- return `npx -y ${HARNESS_PACKAGE}@${pinned}`;
19194
- }
19195
- function repoHarnessInvocation(repo) {
19196
- return harnessInvocation(lockedHarnessVersion(repo));
19197
- }
19198
-
19199
19199
  // src/util.ts
19200
19200
  var import_node_crypto3 = require("node:crypto");
19201
19201
  var import_node_fs5 = require("node:fs");
@@ -19447,6 +19447,9 @@ var DOCUMENT_EXTENSIONS = /* @__PURE__ */ new Set([".md", ".mdx", ".markdown", "
19447
19447
  var ALWAYS_PRUNED_DIRECTORY_NAMES = /* @__PURE__ */ new Set([".git", ".hg", ".svn"]);
19448
19448
  var GENERATED_MARKER = "<!-- GENERATED by ai-harness \u2014 DO NOT EDIT.";
19449
19449
  var CANDIDATE_METADATA = "candidate.json";
19450
+ var LANDING_ROOT = ".agents";
19451
+ var LANDING_EXCLUDED_FILES = /* @__PURE__ */ new Set([MANIFEST_REL, HARNESS_LOCK_REL, ".agents/.harness-state.json", ...MANAGED_ENTRY_PATHS]);
19452
+ var LANDING_EXCLUDED_DIRECTORIES = /* @__PURE__ */ new Set([".agents/adoption", ".agents/hooks"]);
19450
19453
  var RECEIPT_DEFAULT = "adoption-audit-receipt.json";
19451
19454
  var ADOPTION_CANDIDATE_SCHEMA = "ai-harness/adoption-candidate/v1";
19452
19455
  var ADOPTION_RECEIPT_SCHEMA = "ai-harness/adoption-audit-receipt/v1";
@@ -19883,6 +19886,47 @@ function discoverGuidance(repo, testHooks = {}) {
19883
19886
  }
19884
19887
  return [...evidence].sort().map((path) => liveGuidanceEvidence(root, path, testHooks));
19885
19888
  }
19889
+ function posixPath(path) {
19890
+ return path.split(import_node_path6.sep).join("/");
19891
+ }
19892
+ function liveLandingEvidence(repoRoot, path) {
19893
+ const absolute = (0, import_node_path6.join)(repoRoot, path);
19894
+ if (!ensureNoSymlinkDirectoryChain(repoRoot, (0, import_node_path6.dirname)(absolute), `landing ${path}`, false))
19895
+ throw new Error(`landing disappeared while it was being inspected: ${path}`);
19896
+ const stat = (0, import_node_fs6.lstatSync)(absolute);
19897
+ if (stat.isSymbolicLink()) return { path, type: "symlink", mode: permissionMode(stat.mode), linkTarget: (0, import_node_fs6.readlinkSync)(absolute) };
19898
+ const source = readOptionalRepositoryFile(repoRoot, path, `landing ${path}`);
19899
+ if (!source) throw new Error(`landing disappeared while it was being inspected: ${path}`);
19900
+ return { path, type: "file", mode: source.mode, bytes: source.bytes };
19901
+ }
19902
+ function discoverLanding(repoRoot, manifest) {
19903
+ const paths = /* @__PURE__ */ new Set();
19904
+ const walk = (relativePath) => {
19905
+ const absolute = (0, import_node_path6.join)(repoRoot, relativePath);
19906
+ if (!entryExists(absolute)) return;
19907
+ const stat = (0, import_node_fs6.lstatSync)(absolute);
19908
+ const key = posixPath(relativePath);
19909
+ if (stat.isSymbolicLink() || stat.isFile()) {
19910
+ if (!LANDING_EXCLUDED_FILES.has(key)) paths.add(relativePath);
19911
+ return;
19912
+ }
19913
+ if (!stat.isDirectory()) throw new Error(`landing must be a regular file, symlink, or directory: ${key}`);
19914
+ if (LANDING_EXCLUDED_DIRECTORIES.has(key) || ALWAYS_PRUNED_DIRECTORY_NAMES.has((0, import_node_path6.basename)(relativePath))) return;
19915
+ if (!inside2(repoRoot, (0, import_node_fs6.realpathSync)(absolute))) throw new Error(`landing directory resolves outside the repository: ${key}`);
19916
+ for (const name of (0, import_node_fs6.readdirSync)(absolute).sort()) walk((0, import_node_path6.join)(relativePath, name));
19917
+ };
19918
+ walk(LANDING_ROOT);
19919
+ for (const knowledge of manifest.knowledge ?? []) {
19920
+ if (knowledge.root !== "repo" || typeof knowledge.path !== "string") continue;
19921
+ const relativePath = safeRelativePath(knowledge.path.replace(/\/+$/, ""), "repo knowledge");
19922
+ if (!ensureNoSymlinkDirectoryChain(repoRoot, (0, import_node_path6.dirname)((0, import_node_path6.join)(repoRoot, relativePath)), `landing ${relativePath}`, false)) continue;
19923
+ walk(relativePath);
19924
+ }
19925
+ return [...paths].sort().map((path) => liveLandingEvidence(repoRoot, path));
19926
+ }
19927
+ function landingEvidenceArtifact(evidence) {
19928
+ return evidence.type === "file" ? (0, import_node_path6.join)("landing", evidence.path) : (0, import_node_path6.join)("landing-links", `${sha256(evidence.path)}.symlink.json`);
19929
+ }
19886
19930
  function captureLegacyEntries(repo, testHooks = {}) {
19887
19931
  const repoRoot = repositoryRoot2(repo);
19888
19932
  const previousSource = readAdoptionIndexSource(repoRoot);
@@ -20093,6 +20137,8 @@ function validateCandidateMetadata(value) {
20093
20137
  if (value.schema !== ADOPTION_CANDIDATE_SCHEMA || value.assurance !== "declared" || value.independence !== "unverified" || !isSha256(value.candidateHash) || !value.source || typeof value.source !== "object" || Array.isArray(value.source) || !Array.isArray(value.legacy) || !Array.isArray(value.guidance) || !Array.isArray(value.targets)) {
20094
20138
  throw new Error(`${CANDIDATE_METADATA} format is invalid`);
20095
20139
  }
20140
+ if (!Array.isArray(value.landing))
20141
+ throw new Error(`${CANDIDATE_METADATA} has no landing evidence; this bundle predates landing binding, run prepare-adoption into a new empty directory`);
20096
20142
  const source = value.source;
20097
20143
  const manifest = source.manifest;
20098
20144
  const legacyIndex = source.legacyIndex;
@@ -20123,6 +20169,17 @@ function validateCandidateMetadata(value) {
20123
20169
  if (item.type === "symlink" && typeof item.linkTarget !== "string")
20124
20170
  throw new Error(`${CANDIDATE_METADATA} guidance symlink evidence is invalid: ${item.path}`);
20125
20171
  }
20172
+ const landingPaths = /* @__PURE__ */ new Set();
20173
+ for (const raw of value.landing) {
20174
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) throw new Error(`${CANDIDATE_METADATA} landing metadata is invalid`);
20175
+ const item = raw;
20176
+ if (typeof item.path !== "string" || !safeEvidencePath(item.path) || LANDING_EXCLUDED_FILES.has(posixPath(item.path)) || landingPaths.has(item.path) || item.type !== "file" && item.type !== "symlink" || typeof item.artifact !== "string" || !isSha256(item.sha256) || !validPermissionMode(item.mode)) {
20177
+ throw new Error(`${CANDIDATE_METADATA} landing metadata is invalid`);
20178
+ }
20179
+ landingPaths.add(item.path);
20180
+ if (item.type === "symlink" && typeof item.linkTarget !== "string")
20181
+ throw new Error(`${CANDIDATE_METADATA} landing symlink evidence is invalid: ${item.path}`);
20182
+ }
20126
20183
  const targetPaths = /* @__PURE__ */ new Set();
20127
20184
  for (const raw of value.targets) {
20128
20185
  if (!raw || typeof raw !== "object" || Array.isArray(raw)) throw new Error(`${CANDIDATE_METADATA} target metadata is invalid`);
@@ -20137,6 +20194,7 @@ function validateCandidateMetadata(value) {
20137
20194
  safeRelativePath(legacyIndex.artifact, "legacy index artifact");
20138
20195
  for (const raw of value.legacy) safeRelativePath(raw.artifact, "legacy artifact");
20139
20196
  for (const raw of value.guidance) safeRelativePath(raw.artifact, "guidance artifact");
20197
+ for (const raw of value.landing) safeRelativePath(raw.artifact, "landing artifact");
20140
20198
  for (const raw of value.targets) safeRelativePath(raw.artifact, "generated artifact");
20141
20199
  const metadata = value;
20142
20200
  if (expectedCandidateHash(metadata) !== metadata.candidateHash)
@@ -20156,6 +20214,7 @@ function readCandidateBundle(repoRoot, candidateDir) {
20156
20214
  { path: metadata.source.legacyIndex.artifact, hash: metadata.source.legacyIndex.sha256, label: "candidate legacy index" },
20157
20215
  ...metadata.legacy.map((item) => ({ path: item.artifact, hash: item.sha256, label: `legacy evidence ${item.path}` })),
20158
20216
  ...metadata.guidance.map((item) => ({ path: item.artifact, hash: item.sha256, label: `guidance evidence ${item.path}` })),
20217
+ ...metadata.landing.map((item) => ({ path: item.artifact, hash: item.sha256, label: `landing evidence ${item.path}` })),
20159
20218
  ...metadata.targets.map((item) => ({ path: item.artifact, hash: item.sha256, label: `generated candidate ${item.path}` }))
20160
20219
  ];
20161
20220
  const artifactPaths = /* @__PURE__ */ new Set();
@@ -20178,6 +20237,7 @@ function prepareAdoptionCandidate(repo, outputDir, testHooks = {}) {
20178
20237
  const invalidLegacy = index.entries.find((entry) => !verifyAdoptionEntry(repoRoot, entry));
20179
20238
  if (invalidLegacy) throw new Error(`legacy evidence is stale for ${invalidLegacy.path}; prepare refused`);
20180
20239
  const liveGuidance = discoverGuidance(repoRoot, testHooks);
20240
+ const liveLanding = discoverLanding(repoRoot, manifest);
20181
20241
  const root = prepareEmptyExternalDirectory(repoRoot, outputDir);
20182
20242
  const manifestBytes = readRegularFile((0, import_node_path6.join)(repoRoot, MANIFEST_REL), "manifest");
20183
20243
  const indexBytes = readLiveIndexBytes(repoRoot);
@@ -20225,6 +20285,20 @@ function prepareAdoptionCandidate(repo, outputDir, testHooks = {}) {
20225
20285
  ...evidence.type === "symlink" ? { linkTarget: evidence.linkTarget } : {}
20226
20286
  });
20227
20287
  }
20288
+ const landing = [];
20289
+ for (const evidence of liveLanding) {
20290
+ const artifact = landingEvidenceArtifact(evidence);
20291
+ const bytes = guidanceEvidenceBytes(evidence);
20292
+ privateWriteBundleFile(root, artifact, bytes);
20293
+ landing.push({
20294
+ path: evidence.path,
20295
+ type: evidence.type,
20296
+ artifact,
20297
+ sha256: sha256(bytes),
20298
+ mode: evidence.mode,
20299
+ ...evidence.type === "symlink" ? { linkTarget: evidence.linkTarget } : {}
20300
+ });
20301
+ }
20228
20302
  const targets = [];
20229
20303
  for (const [path, content] of renderTargets(manifest, { harnessVersion: lockedHarnessVersion(repoRoot) })) {
20230
20304
  const artifact = (0, import_node_path6.join)("generated", path);
@@ -20242,6 +20316,7 @@ function prepareAdoptionCandidate(repo, outputDir, testHooks = {}) {
20242
20316
  },
20243
20317
  legacy,
20244
20318
  guidance,
20319
+ landing,
20245
20320
  targets
20246
20321
  };
20247
20322
  const metadata = { ...unsigned, candidateHash: candidateDigest(unsigned) };
@@ -20363,6 +20438,17 @@ function assertManagedFileAdoptionReceipt(repo, inspections, candidateDir, recei
20363
20438
  const manifest = loadManifest(repoRoot);
20364
20439
  const errors = validateManifest(manifest).filter((issue) => issue.level === "error");
20365
20440
  if (errors.length) throw new Error(`manifest invalid: ${errors.map((issue) => issue.msg).join("; ")}`);
20441
+ const liveLanding = discoverLanding(repoRoot, manifest);
20442
+ if (!samePathList(metadata.landing.map((item) => item.path), liveLanding.map((item) => item.path)))
20443
+ throw new Error("live landing inventory changed after candidate preparation");
20444
+ for (let i = 0; i < liveLanding.length; i++) {
20445
+ const live = liveLanding[i];
20446
+ const evidence = metadata.landing[i];
20447
+ if (evidence.type !== live.type || evidence.mode !== live.mode || live.type === "symlink" && evidence.linkTarget !== live.linkTarget)
20448
+ throw new Error(`live landing topology or mode changed for ${live.path}`);
20449
+ const artifact = readBundleFile(candidate.root, evidence.artifact, `landing evidence ${live.path}`);
20450
+ if (!artifact.equals(guidanceEvidenceBytes(live))) throw new Error(`live landing bytes changed for ${live.path}`);
20451
+ }
20366
20452
  const rendered = renderTargets(manifest, { harnessVersion: lockedHarnessVersion(repoRoot) });
20367
20453
  if (!samePathList(metadata.targets.map((target) => target.path), rendered.map(([path]) => path)))
20368
20454
  throw new Error("current render target list differs from the audited candidate");
@@ -20982,6 +21068,7 @@ function syncCmd(repo, opts = {}) {
20982
21068
 
20983
21069
  // src/commands/doctor.ts
20984
21070
  var import_fast_glob3 = __toESM(require_out4(), 1);
21071
+ var import_picomatch4 = __toESM(require_picomatch2(), 1);
20985
21072
  var import_node_fs13 = require("node:fs");
20986
21073
  var import_node_path13 = require("node:path");
20987
21074
 
@@ -21996,7 +22083,7 @@ function startValidationSession(args) {
21996
22083
  const token = validationSessionToken(args.agent, args.sessionId);
21997
22084
  const existing = readValidationSession(repo, token);
21998
22085
  if (existing) {
21999
- const resumed = { ...existing, hookConfigFingerprint: args.hookConfigFingerprint, lastEvidence: void 0 };
22086
+ const resumed = { ...existing, hookConfigFingerprint: args.hookConfigFingerprint, lastEvidence: void 0, lastStop: void 0 };
22000
22087
  writeValidationSession(repo, resumed);
22001
22088
  pruneValidationState(repo);
22002
22089
  return resumed;
@@ -22085,6 +22172,16 @@ function writeValidationSession(repo, session) {
22085
22172
  function recordValidationEvidence(repo, session, evidence) {
22086
22173
  writeValidationSession(repo, { ...session, lastEvidence: evidence });
22087
22174
  }
22175
+ function recordStopObservation(repoInput, token, observation, evidence) {
22176
+ const repo = gitRoot(repoInput);
22177
+ const session = readValidationSession(repo, token);
22178
+ if (!session || session.agent === "manual") return false;
22179
+ const next = { ...session, lastStop: observation, updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
22180
+ if (evidence === null) delete next.lastEvidence;
22181
+ else if (evidence) next.lastEvidence = evidence;
22182
+ writePrivateJson(sessionPath(repo, token), next);
22183
+ return true;
22184
+ }
22088
22185
  function inspectValidationEvidenceFreshness(repo, evidence) {
22089
22186
  let currentFingerprint = "";
22090
22187
  let currentPlanFingerprint = "";
@@ -22457,8 +22554,12 @@ function installStopHooks(repo, agents, opts = {}) {
22457
22554
  linkedPlan?.requiresRuntimeRefresh ? "codex: Orca mirrors this user Hook source into new terminals; start a fresh Orca Agent session, then review `/hooks` once" : linkedPlan ? "codex: run `/hooks` once to review and trust the Harness user dispatcher before it can run" : "codex: run `/hooks` to review and trust the new project hooks before they can run"
22458
22555
  );
22459
22556
  }
22460
- info("\nSessionStart records the exact task base; every Stop reruns run-checks + verify.");
22461
- info("After the first real agent session, run `harness-kit evidence`; no record means that client surface did not execute project hooks.");
22557
+ info(
22558
+ "\nSessionStart records the exact task base. By default (thin) each Stop requires an accepted deliver stamp for the current change; HARNESS_KIT_STOP_MODE=execute makes Stop rerun run-checks + verify itself. Every Stop is recorded as lifecycle evidence."
22559
+ );
22560
+ info(
22561
+ `Prove it: in a fresh Agent session, deliver a change and finish the turn, then \`${repoHarnessInvocation(repo)} evidence --repo . --json\` must show hookActive: true. No lifecycle record means that client surface did not execute project hooks.`
22562
+ );
22462
22563
  info(`Runner is pinned to @erzhe/harness-kit@${package_default.version}; override with HARNESS_KIT_CMD for local development.`);
22463
22564
  return 0;
22464
22565
  }
@@ -22665,7 +22766,12 @@ function inspectAgentHookStatus(repo) {
22665
22766
  try {
22666
22767
  const session = readLatestHookValidationSession(repo);
22667
22768
  const evidence = session?.lastEvidence;
22668
- if (session && session.agent !== "manual" && evidence) {
22769
+ if (session && session.agent !== "manual" && !evidence && session.lastStop?.decision === "block") {
22770
+ evidenceAgent = session.agent;
22771
+ evidenceAt = session.lastStop.at;
22772
+ evidenceInvalid = true;
22773
+ issues.push(`latest lifecycle evidence: ${session.agent} Stop blocked (${session.lastStop.reason}); run deliver, then finish the turn again`);
22774
+ } else if (session && session.agent !== "manual" && evidence) {
22669
22775
  evidenceAgent = session.agent;
22670
22776
  evidenceAt = evidence.createdAt;
22671
22777
  const freshness = inspectValidationEvidenceFreshness(repo, evidence);
@@ -23028,16 +23134,20 @@ function doctorCmd(repo, opts = {}) {
23028
23134
  if (n === 0 && !inv.enforcement.allow_empty)
23029
23135
  warn(`invariant ${inv.id}: enforcement path_glob matches 0 files \u2014 passes without checking anything (wrong path_glob for this repo layout?)`);
23030
23136
  }
23137
+ const repoFiles = (m.modules ?? []).some((mod) => mod.owns?.length || mod.tests?.length) ? import_fast_glob3.default.sync("**/*", { cwd: repo, onlyFiles: true, dot: true, ignore: ["**/node_modules/**", "**/.git/**", "**/dist/**"] }) : [];
23138
+ const matchesNothing = (glob) => {
23139
+ const matcher = (0, import_picomatch4.default)(glob, { dot: true });
23140
+ return !repoFiles.some((file) => matcher(file));
23141
+ };
23031
23142
  for (const mod of m.modules ?? []) {
23032
- if (!mod.owns?.length) continue;
23033
- const n = import_fast_glob3.default.sync(mod.owns, {
23034
- cwd: repo,
23035
- onlyFiles: true,
23036
- dot: true,
23037
- ignore: ["**/node_modules/**", "**/.git/**", "**/dist/**"]
23038
- }).length;
23039
- if (n === 0)
23143
+ const deadOwns = (mod.owns ?? []).filter(matchesNothing);
23144
+ if (deadOwns.length && deadOwns.length === mod.owns.length)
23040
23145
  warn(`module ${mod.name}: owns glob matches 0 files \u2014 impact planner can never select it (stale owns for this layout?)`);
23146
+ else
23147
+ for (const glob of deadOwns)
23148
+ warn(`module ${mod.name}: owns glob "${glob}" matches 0 files \u2014 changes under it can never select this module (stale path?)`);
23149
+ for (const glob of (mod.tests ?? []).filter(matchesNothing))
23150
+ warn(`module ${mod.name}: tests glob "${glob}" matches 0 files \u2014 it can never map a test change or satisfy test_touch (stale path?)`);
23041
23151
  }
23042
23152
  for (const glob of m.validation?.required_coverage ?? []) {
23043
23153
  const n = import_fast_glob3.default.sync(glob, {
@@ -23347,6 +23457,14 @@ function stampCoversScope(repoInput, scope) {
23347
23457
  if (scope.changes.files.length === 0) return stamp.status === "no-change" || stamp.status === "accepted";
23348
23458
  return stamp.status === "accepted" && stamp.fingerprint === scope.changes.fingerprint;
23349
23459
  }
23460
+ function coveringStampEvidence(repoInput, scope) {
23461
+ if (!stampCoversScope(repoInput, scope)) return null;
23462
+ try {
23463
+ return readLatestValidationSession(gitRoot(repoInput))?.lastEvidence ?? null;
23464
+ } catch {
23465
+ return null;
23466
+ }
23467
+ }
23350
23468
  function inheritedContextIssueKeys(repo, manifest, issues, base) {
23351
23469
  if (!issues.some((issue) => issue.severity === "blocking")) return /* @__PURE__ */ new Set();
23352
23470
  const changes = collectChanges(repo, base, { mode: "exact" });
@@ -23860,6 +23978,40 @@ function checkLoopCmd() {
23860
23978
  }
23861
23979
 
23862
23980
  // src/commands/evidence.ts
23981
+ function lifecycleProof(repo, session) {
23982
+ if (!session || session.agent === "manual") return null;
23983
+ const configurationCurrent = !!session.hookConfigFingerprint && agentHookConfigurationFingerprint(repo, session.agent) === session.hookConfigFingerprint;
23984
+ const evidence = session.lastEvidence;
23985
+ let evidenceValid = false;
23986
+ if (evidence) {
23987
+ const runChecksStatus = evidence.runChecksStatus ?? (evidence.ok ? evidence.status : "not-verified");
23988
+ evidenceValid = runChecksStatus !== "not-verified" && evidence.verifyPassed === true && !inspectValidationEvidenceFreshness(repo, evidence).stale;
23989
+ }
23990
+ return {
23991
+ agent: session.agent,
23992
+ session: session.token,
23993
+ sessionStartedAt: session.createdAt,
23994
+ baseSha: session.baseSha,
23995
+ configurationCurrent,
23996
+ stop: session.lastStop ?? null,
23997
+ evidenceSource: evidence ? evidence.source ?? "run-checks" : null,
23998
+ evidenceValid,
23999
+ active: configurationCurrent && evidenceValid
24000
+ };
24001
+ }
24002
+ function safeLifecycleProof(repo, session) {
24003
+ try {
24004
+ return lifecycleProof(repo, session === void 0 ? readLatestHookValidationSession(repo) : session);
24005
+ } catch {
24006
+ return null;
24007
+ }
24008
+ }
24009
+ function describeLifecycle(lifecycle) {
24010
+ if (!lifecycle) return "lifecycle: no SessionStart recorded by an installed hook";
24011
+ const stop = lifecycle.stop ? `last Stop ${lifecycle.stop.decision} (${lifecycle.stop.mode}, ${lifecycle.stop.reason}) at ${lifecycle.stop.at}` : "no Stop observed yet";
24012
+ const config = lifecycle.configurationCurrent ? "" : "; hook configuration changed since SessionStart";
24013
+ return `lifecycle: ${lifecycle.agent} session started ${lifecycle.sessionStartedAt}; ${stop}${config}; hookActive: ${lifecycle.active ? "yes" : "no"}`;
24014
+ }
23863
24015
  function safeHookStatus(repo) {
23864
24016
  try {
23865
24017
  return inspectAgentHookStatus(repo);
@@ -23894,18 +24046,27 @@ function evidenceCmd(repo, opts = {}) {
23894
24046
  return 1;
23895
24047
  }
23896
24048
  const hooks = safeHookStatus(repo);
24049
+ const lifecycle = safeLifecycleProof(repo, opts.session ? session : void 0);
23897
24050
  if (!session?.lastEvidence) {
23898
24051
  const guidance2 = buildHarnessGuidance({ hooks, evidence: { found: false }, cli: repoHarnessInvocation(repo) });
23899
24052
  if (opts.json) {
23900
24053
  process.stdout.write(
23901
24054
  JSON.stringify(
23902
- { schema: "ai-harness/evidence/v1", found: false, hooks, nextActions: guidance2.nextActions },
24055
+ {
24056
+ schema: "ai-harness/evidence/v1",
24057
+ found: false,
24058
+ hooks,
24059
+ hookActive: lifecycle?.active ?? false,
24060
+ lifecycle,
24061
+ nextActions: guidance2.nextActions
24062
+ },
23903
24063
  null,
23904
24064
  2
23905
24065
  ) + "\n"
23906
24066
  );
23907
24067
  } else {
23908
24068
  warn("no validation evidence recorded for this worktree/session");
24069
+ info(describeLifecycle(lifecycle));
23909
24070
  printNextActions(guidance2.nextActions.filter((action) => action.priority === "required"));
23910
24071
  warn(`Harness readiness: INCOMPLETE (${guidance2.nextActions.filter((action) => action.priority === "required").length} required action(s) above)`);
23911
24072
  }
@@ -23926,7 +24087,7 @@ function evidenceCmd(repo, opts = {}) {
23926
24087
  const runChecksValid = (evidence.runChecksStatus !== void 0 ? evidence.runChecksStatus !== "not-verified" : evidence.ok && evidence.status !== "not-verified") && !stale;
23927
24088
  const valid = runChecksValid && evidence.verifyPassed === true;
23928
24089
  const hookConfigurationCurrent = session.agent !== "manual" && !!session.hookConfigFingerprint && agentHookConfigurationFingerprint(repo, session.agent) === session.hookConfigFingerprint;
23929
- const hookActive = valid && hookConfigurationCurrent;
24090
+ const hookActive = valid && hookConfigurationCurrent || (lifecycle?.active ?? false);
23930
24091
  const stamp = inspectDeliveryStamp(repo);
23931
24092
  const guidance = buildHarnessGuidance({
23932
24093
  hooks,
@@ -23940,6 +24101,7 @@ function evidenceCmd(repo, opts = {}) {
23940
24101
  stamp,
23941
24102
  hookActive,
23942
24103
  hookConfigurationCurrent,
24104
+ lifecycle,
23943
24105
  stale,
23944
24106
  currentFingerprint,
23945
24107
  currentPlanFingerprint,
@@ -23978,6 +24140,7 @@ function evidenceCmd(repo, opts = {}) {
23978
24140
  }
23979
24141
  if (hooks.configuredAgents.length) {
23980
24142
  info(`session intercept: ${hooks.state} (configured: ${hooks.configuredAgents.join(",")})`);
24143
+ info(describeLifecycle(lifecycle));
23981
24144
  } else {
23982
24145
  info("session intercept: none (cooperative deliver only)");
23983
24146
  }
@@ -24706,16 +24869,33 @@ function failureMessage(report, verifyOutput, token, cli) {
24706
24869
  );
24707
24870
  return lines.join("\n");
24708
24871
  }
24709
- function thinStop(repo, agent) {
24872
+ function observeStop(repo, token, observation, evidence) {
24873
+ try {
24874
+ recordStopObservation(repo, token, { at: (/* @__PURE__ */ new Date()).toISOString(), ...observation }, evidence);
24875
+ } catch {
24876
+ }
24877
+ }
24878
+ function thinStop(repo, agent, id) {
24710
24879
  const cli = repoHarnessInvocation(repo);
24880
+ const token = validationSessionToken(agent, id);
24711
24881
  let scope;
24712
24882
  try {
24713
24883
  scope = resolveChangeScope(repo);
24714
24884
  } catch (error) {
24885
+ observeStop(repo, token, { mode: "thin", decision: "block", reason: "scope-error" }, null);
24715
24886
  return block(agent, "stop", deliverBlockMessage(cli, `cannot resolve changes: ${error.message}`));
24716
24887
  }
24717
- if (scope.changes.files.length === 0) return allow(agent);
24718
- if (stampCoversScope(repo, scope)) return allow(agent);
24888
+ const fingerprint2 = scope.changes.fingerprint;
24889
+ if (scope.changes.files.length === 0) {
24890
+ observeStop(repo, token, { mode: "thin", decision: "allow", reason: "clean", fingerprint: fingerprint2 }, null);
24891
+ return allow(agent);
24892
+ }
24893
+ const stamp = coveringStampEvidence(repo, scope);
24894
+ if (stamp) {
24895
+ observeStop(repo, token, { mode: "thin", decision: "allow", reason: "stamp", fingerprint: fingerprint2 }, { ...stamp, source: "deliver-stamp" });
24896
+ return allow(agent);
24897
+ }
24898
+ observeStop(repo, token, { mode: "thin", decision: "block", reason: "no-stamp", fingerprint: fingerprint2 }, null);
24719
24899
  return block(
24720
24900
  agent,
24721
24901
  "stop",
@@ -24789,7 +24969,14 @@ function executeStop(repo, agent, id) {
24789
24969
  } catch (error) {
24790
24970
  return block(agent, "stop", deliverBlockMessage(cli, `could not persist verify result: ${error.message}`));
24791
24971
  }
24792
- if (run.code === 0 && report?.ok && verifyPassed && evidencePersisted) return allow(agent);
24972
+ const passed = run.code === 0 && !!report?.ok && verifyPassed && evidencePersisted;
24973
+ observeStop(repo, token, {
24974
+ mode: "execute",
24975
+ decision: passed ? "allow" : "block",
24976
+ reason: "checks",
24977
+ ...report?.fingerprint ? { fingerprint: report.fingerprint } : {}
24978
+ });
24979
+ if (passed) return allow(agent);
24793
24980
  const verifyDetails = [
24794
24981
  verify.code === 0 ? "" : verify.output.trim(),
24795
24982
  finalFingerprintError,
@@ -24842,7 +25029,7 @@ function hookEventCmd(repoInput, opts) {
24842
25029
  }
24843
25030
  }
24844
25031
  if (opts.agent === "cursor" && ["aborted", "error"].includes(payload.status ?? "")) return allow(opts.agent);
24845
- if (stopMode() === "thin") return thinStop(repo, opts.agent);
25032
+ if (stopMode() === "thin") return thinStop(repo, opts.agent, id);
24846
25033
  return executeStop(repo, opts.agent, id);
24847
25034
  }
24848
25035
 
@@ -25024,7 +25211,9 @@ var SKILL_REL2 = "skills/erzhe-harness-init/SKILL.md";
25024
25211
  var META2 = `<!-- harness-kit onboard -->
25025
25212
  You are an AI agent onboarding the CURRENT repository to harness-kit.
25026
25213
  Follow the skill below verbatim. Run every harness-kit command through
25027
- \`npx -y @erzhe/harness-kit@latest <cmd>\` \u2014 always the latest version, no global install.
25214
+ \`${harnessInvocation(package_default.version)} <cmd>\` \u2014 the exact version printing this skill,
25215
+ no global install. \`init\` records it in .agents/harness.lock.json. If the repository
25216
+ already has that lock, use the version it pins instead and never mix versions.
25028
25217
  Do not fabricate: confirm uncertain fields with the user, and report honest GAPS.
25029
25218
 
25030
25219
  ---
@@ -25119,10 +25308,14 @@ function prepareAdoptionCmd(repo, opts) {
25119
25308
  assurance: candidate.assurance,
25120
25309
  independence: candidate.independence,
25121
25310
  legacyEvidenceCount: candidate.legacy.length,
25311
+ landingEvidenceCount: candidate.landing.length,
25122
25312
  targetCount: candidate.targets.length
25123
25313
  };
25124
25314
  if (opts.json) process.stdout.write(JSON.stringify(result) + "\n");
25125
- else ok(`prepared adoption candidate ${candidate.candidateHash} at ${output}`);
25315
+ else {
25316
+ ok(`prepared adoption candidate ${candidate.candidateHash} at ${output}`);
25317
+ ok(`bundle: ${candidate.legacy.length} legacy, ${candidate.guidance.length} guidance, ${candidate.landing.length} landing, ${candidate.targets.length} generated`);
25318
+ }
25126
25319
  return 0;
25127
25320
  }
25128
25321
 
@@ -25362,7 +25555,7 @@ program2.command("record-context-review").description("record an Agent's complet
25362
25555
  )
25363
25556
  );
25364
25557
  program2.command("accept-contract").description("record current contract fingerprint(s) as the accepted baseline (after an intended change)").option("-C, --repo <dir>", "target repo dir (default: current directory)").option("--id <id>", "only this contract (default: all with a snapshot command)").action((o) => guard(() => acceptContractCmd(repoOf(o), o.id)));
25365
- program2.command("install-hooks").description("install git hooks and/or agent SessionStart + Stop hooks (run-checks + verify gate)").option("-C, --repo <dir>", "target repo dir (default: current directory)").option("--git", "install git hooks (default when no selector given)").option("--stop", "install agent SessionStart + Stop hooks (Claude Code / Cursor / Codex)").option("--agents <list>", "comma list of agent tools for --stop: claude,cursor,codex (default: all)").option("--force", "refresh harness-kit-managed hooks; never overwrite foreign hooks", false).option("--allow-shared-git-hooks", "acknowledge native hooks affect every linked worktree", false).option(
25558
+ program2.command("install-hooks").description("install git hooks and/or agent SessionStart + Stop hooks (Stop requires an accepted deliver stamp)").option("-C, --repo <dir>", "target repo dir (default: current directory)").option("--git", "install git hooks (default when no selector given)").option("--stop", "install agent SessionStart + Stop hooks (Claude Code / Cursor / Codex)").option("--agents <list>", "comma list of agent tools for --stop: claude,cursor,codex (default: all)").option("--force", "refresh harness-kit-managed hooks; never overwrite foreign hooks", false).option("--allow-shared-git-hooks", "acknowledge native hooks affect every linked worktree", false).option(
25366
25559
  "--allow-user-dispatcher",
25367
25560
  "allow the safe CODEX_HOME dispatcher required by Codex in linked worktrees",
25368
25561
  false
@@ -25378,7 +25571,7 @@ program2.command("install-hooks").description("install git hooks and/or agent Se
25378
25571
  })
25379
25572
  )
25380
25573
  );
25381
- program2.command("onboard").description("print the erzhe-harness-init skill for an agent to follow (use via npx, always latest)").action(() => guard(() => onboardCmd()));
25574
+ program2.command("onboard").description("print the erzhe-harness-init skill for an agent to follow (pins this exact version)").action(() => guard(() => onboardCmd()));
25382
25575
  program2.command("check-loop").description("print the harness-check-loop skill: the implement -> verify loop for an agent").action(() => guard(() => checkLoopCmd()));
25383
25576
  program2.command("hook-event", { hidden: true }).description("internal lifecycle hook adapter").requiredOption("-C, --repo <dir>", "target repo dir").requiredOption("--agent <agent>", "claude, cursor, or codex").requiredOption("--event <event>", "session-start or stop").action(
25384
25577
  (o) => guard(() => {