@erzhe/harness-kit 0.4.1 → 0.5.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.
- package/README.md +18 -5
- package/SPEC-v0.md +26 -11
- package/dist/harness-kit.cjs +1291 -707
- package/package.json +1 -1
- package/skills/erzhe-harness-init/SKILL.md +4 -0
- package/skills/harness-check-loop/SKILL.md +5 -1
package/dist/harness-kit.cjs
CHANGED
|
@@ -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
|
|
4945
|
+
var picomatch4 = (glob, options, returnState = false) => {
|
|
4946
4946
|
if (Array.isArray(glob)) {
|
|
4947
|
-
const fns = glob.map((input) =>
|
|
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 ?
|
|
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 =
|
|
4969
|
+
isIgnored = picomatch4(opts.ignore, ignoreOpts, returnState);
|
|
4970
4970
|
}
|
|
4971
4971
|
const matcher = (input, returnObject = false) => {
|
|
4972
|
-
const { isMatch, match, output } =
|
|
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
|
-
|
|
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
|
}
|
|
@@ -5003,33 +5003,33 @@ var require_picomatch = __commonJS({
|
|
|
5003
5003
|
return { isMatch: false, output: "" };
|
|
5004
5004
|
}
|
|
5005
5005
|
const opts = options || {};
|
|
5006
|
-
const
|
|
5006
|
+
const format2 = opts.format || (posix ? utils.toPosixSlashes : null);
|
|
5007
5007
|
let match = input === glob;
|
|
5008
|
-
let output = match &&
|
|
5008
|
+
let output = match && format2 ? format2(input) : input;
|
|
5009
5009
|
if (match === false) {
|
|
5010
|
-
output =
|
|
5010
|
+
output = format2 ? format2(input) : input;
|
|
5011
5011
|
match = output === glob;
|
|
5012
5012
|
}
|
|
5013
5013
|
if (match === false || opts.capture === true) {
|
|
5014
5014
|
if (opts.matchBase === true || opts.basename === true) {
|
|
5015
|
-
match =
|
|
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
|
-
|
|
5023
|
-
const regex = glob instanceof RegExp ? glob :
|
|
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
|
-
|
|
5027
|
-
|
|
5028
|
-
if (Array.isArray(pattern)) return pattern.map((p) =>
|
|
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
|
-
|
|
5032
|
-
|
|
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 =
|
|
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
|
-
|
|
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
|
|
5060
|
+
return picomatch4.compileRe(parsed, options, returnOutput, returnState);
|
|
5061
5061
|
};
|
|
5062
|
-
|
|
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
|
-
|
|
5072
|
-
module2.exports =
|
|
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
|
|
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(
|
|
5089
|
-
module2.exports =
|
|
5088
|
+
Object.assign(picomatch4, pico);
|
|
5089
|
+
module2.exports = picomatch4;
|
|
5090
5090
|
}
|
|
5091
5091
|
});
|
|
5092
5092
|
|
|
@@ -7430,14 +7430,14 @@ var require_bool = __commonJS({
|
|
|
7430
7430
|
var require_stringifyNumber = __commonJS({
|
|
7431
7431
|
"node_modules/.pnpm/yaml@2.9.0/node_modules/yaml/dist/stringify/stringifyNumber.js"(exports2) {
|
|
7432
7432
|
"use strict";
|
|
7433
|
-
function stringifyNumber({ format, minFractionDigits, tag, value }) {
|
|
7433
|
+
function stringifyNumber({ format: format2, minFractionDigits, tag, value }) {
|
|
7434
7434
|
if (typeof value === "bigint")
|
|
7435
7435
|
return String(value);
|
|
7436
7436
|
const num = typeof value === "number" ? value : Number(value);
|
|
7437
7437
|
if (!isFinite(num))
|
|
7438
7438
|
return isNaN(num) ? ".nan" : num < 0 ? "-.inf" : ".inf";
|
|
7439
7439
|
let n = Object.is(value, -0) ? "-0" : JSON.stringify(value);
|
|
7440
|
-
if (!
|
|
7440
|
+
if (!format2 && minFractionDigits && (!tag || tag === "tag:yaml.org,2002:float") && /^-?\d/.test(n) && !n.includes("e")) {
|
|
7441
7441
|
let i = n.indexOf(".");
|
|
7442
7442
|
if (i < 0) {
|
|
7443
7443
|
i = n.length;
|
|
@@ -12298,7 +12298,7 @@ var require_public_api = __commonJS({
|
|
|
12298
12298
|
return docs;
|
|
12299
12299
|
return Object.assign([], { empty: true }, composer$1.streamInfo());
|
|
12300
12300
|
}
|
|
12301
|
-
function
|
|
12301
|
+
function parseDocument2(source, options = {}) {
|
|
12302
12302
|
const { lineCounter: lineCounter2, prettyErrors } = parseOptions(options);
|
|
12303
12303
|
const parser$1 = new parser.Parser(lineCounter2?.addNewLine);
|
|
12304
12304
|
const composer$1 = new composer.Composer(options);
|
|
@@ -12324,7 +12324,7 @@ var require_public_api = __commonJS({
|
|
|
12324
12324
|
} else if (options === void 0 && reviver && typeof reviver === "object") {
|
|
12325
12325
|
options = reviver;
|
|
12326
12326
|
}
|
|
12327
|
-
const doc =
|
|
12327
|
+
const doc = parseDocument2(src, options);
|
|
12328
12328
|
if (!doc)
|
|
12329
12329
|
return null;
|
|
12330
12330
|
doc.warnings.forEach((warning) => log.warn(doc.options.logLevel, warning));
|
|
@@ -12360,7 +12360,7 @@ var require_public_api = __commonJS({
|
|
|
12360
12360
|
}
|
|
12361
12361
|
exports2.parse = parse;
|
|
12362
12362
|
exports2.parseAllDocuments = parseAllDocuments;
|
|
12363
|
-
exports2.parseDocument =
|
|
12363
|
+
exports2.parseDocument = parseDocument2;
|
|
12364
12364
|
exports2.stringify = stringify;
|
|
12365
12365
|
}
|
|
12366
12366
|
});
|
|
@@ -13170,7 +13170,7 @@ var require_fill_range = __commonJS({
|
|
|
13170
13170
|
let padded = zeros(startString) || zeros(endString) || zeros(stepString);
|
|
13171
13171
|
let maxLen = padded ? Math.max(startString.length, endString.length, stepString.length) : 0;
|
|
13172
13172
|
let toNumber = padded === false && stringify(start, end, options) === false;
|
|
13173
|
-
let
|
|
13173
|
+
let format2 = options.transform || transform(toNumber);
|
|
13174
13174
|
if (options.toRegex && step === 1) {
|
|
13175
13175
|
return toRange(toMaxLen(start, maxLen), toMaxLen(end, maxLen), true, options);
|
|
13176
13176
|
}
|
|
@@ -13182,7 +13182,7 @@ var require_fill_range = __commonJS({
|
|
|
13182
13182
|
if (options.toRegex === true && step > 1) {
|
|
13183
13183
|
push(a);
|
|
13184
13184
|
} else {
|
|
13185
|
-
range.push(pad(
|
|
13185
|
+
range.push(pad(format2(a, index), maxLen, toNumber));
|
|
13186
13186
|
}
|
|
13187
13187
|
a = descending ? a - step : a + step;
|
|
13188
13188
|
index++;
|
|
@@ -13196,7 +13196,7 @@ var require_fill_range = __commonJS({
|
|
|
13196
13196
|
if (!isNumber(start) && start.length > 1 || !isNumber(end) && end.length > 1) {
|
|
13197
13197
|
return invalidRange(start, end, options);
|
|
13198
13198
|
}
|
|
13199
|
-
let
|
|
13199
|
+
let format2 = options.transform || ((val) => String.fromCharCode(val));
|
|
13200
13200
|
let a = `${start}`.charCodeAt(0);
|
|
13201
13201
|
let b = `${end}`.charCodeAt(0);
|
|
13202
13202
|
let descending = a > b;
|
|
@@ -13208,7 +13208,7 @@ var require_fill_range = __commonJS({
|
|
|
13208
13208
|
let range = [];
|
|
13209
13209
|
let index = 0;
|
|
13210
13210
|
while (descending ? a >= b : a <= b) {
|
|
13211
|
-
range.push(
|
|
13211
|
+
range.push(format2(a, index));
|
|
13212
13212
|
a = descending ? a - step : a + step;
|
|
13213
13213
|
index++;
|
|
13214
13214
|
}
|
|
@@ -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
|
|
15401
|
+
var picomatch4 = (glob, options, returnState = false) => {
|
|
15402
15402
|
if (Array.isArray(glob)) {
|
|
15403
|
-
const fns = glob.map((input) =>
|
|
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 ?
|
|
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 =
|
|
15425
|
+
isIgnored = picomatch4(opts.ignore, ignoreOpts, returnState);
|
|
15426
15426
|
}
|
|
15427
15427
|
const matcher = (input, returnObject = false) => {
|
|
15428
|
-
const { isMatch, match, output } =
|
|
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
|
-
|
|
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
|
}
|
|
@@ -15459,33 +15459,33 @@ var require_picomatch3 = __commonJS({
|
|
|
15459
15459
|
return { isMatch: false, output: "" };
|
|
15460
15460
|
}
|
|
15461
15461
|
const opts = options || {};
|
|
15462
|
-
const
|
|
15462
|
+
const format2 = opts.format || (posix ? utils.toPosixSlashes : null);
|
|
15463
15463
|
let match = input === glob;
|
|
15464
|
-
let output = match &&
|
|
15464
|
+
let output = match && format2 ? format2(input) : input;
|
|
15465
15465
|
if (match === false) {
|
|
15466
|
-
output =
|
|
15466
|
+
output = format2 ? format2(input) : input;
|
|
15467
15467
|
match = output === glob;
|
|
15468
15468
|
}
|
|
15469
15469
|
if (match === false || opts.capture === true) {
|
|
15470
15470
|
if (opts.matchBase === true || opts.basename === true) {
|
|
15471
|
-
match =
|
|
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
|
-
|
|
15479
|
-
const regex = glob instanceof RegExp ? glob :
|
|
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
|
-
|
|
15483
|
-
|
|
15484
|
-
if (Array.isArray(pattern)) return pattern.map((p) =>
|
|
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
|
-
|
|
15488
|
-
|
|
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 =
|
|
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
|
-
|
|
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
|
|
15516
|
+
return picomatch4.compileRe(parsed, options, returnOutput, returnState);
|
|
15517
15517
|
};
|
|
15518
|
-
|
|
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
|
-
|
|
15528
|
-
module2.exports =
|
|
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
|
|
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 =
|
|
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) =>
|
|
15596
|
-
micromatch.isMatch = (str, patterns, options) =>
|
|
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 =
|
|
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 =
|
|
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) =>
|
|
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 =
|
|
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) =>
|
|
15675
|
-
micromatch.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(
|
|
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.
|
|
18188
|
+
version: "0.5.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: [
|
|
@@ -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
|
|
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
|
|
18460
|
-
issues.push({ level: "error", msg: `\u4E0D\u652F\u6301 manifest spec ${m.spec}\uFF1B\u5F53\u524D CLI \
|
|
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() {
|
|
@@ -20276,179 +20352,623 @@ function assertManagedFileAdoption(_repo, inspections, adoptExisting) {
|
|
|
20276
20352
|
);
|
|
20277
20353
|
}
|
|
20278
20354
|
|
|
20279
|
-
// src/
|
|
20280
|
-
|
|
20281
|
-
return `spec: ai-harness/v0
|
|
20282
|
-
|
|
20283
|
-
identity:
|
|
20284
|
-
name: ${name}
|
|
20285
|
-
summary: TODO one-line description of what this repo is
|
|
20286
|
-
scope_in: []
|
|
20287
|
-
scope_out: []
|
|
20288
|
-
upstream: []
|
|
20289
|
-
downstream: []
|
|
20290
|
-
|
|
20291
|
-
capabilities:
|
|
20292
|
-
setup: { run: "pnpm install" }
|
|
20293
|
-
build: { run: "pnpm build" }
|
|
20294
|
-
test: { run: "pnpm test" }
|
|
20295
|
-
lint: { run: "pnpm lint" }
|
|
20296
|
-
verify: { run: "harness-kit verify" }
|
|
20297
|
-
|
|
20298
|
-
environment: []
|
|
20299
|
-
|
|
20300
|
-
contracts: []
|
|
20301
|
-
|
|
20302
|
-
invariants:
|
|
20303
|
-
- id: no-console-log
|
|
20304
|
-
rule: No stray console.log left in source
|
|
20305
|
-
enforcement:
|
|
20306
|
-
forbid_pattern: ["console\\\\.log\\\\("]
|
|
20307
|
-
path_glob: ["src/**"]
|
|
20308
|
-
- id: no-hardcoded-secret
|
|
20309
|
-
rule: Do not hardcode secrets / tokens in source
|
|
20310
|
-
enforcement:
|
|
20311
|
-
forbid_pattern: ["(password|secret|token)\\\\s*[:=]\\\\s*[\\"'][^\\"']+[\\"']"]
|
|
20312
|
-
path_glob: ["src/**"]
|
|
20313
|
-
|
|
20314
|
-
knowledge:
|
|
20315
|
-
- path: knowledge/domain.md
|
|
20316
|
-
role: domain
|
|
20317
|
-
- path: knowledge/conventions.md
|
|
20318
|
-
role: conventions
|
|
20319
|
-
- path: knowledge/journal/
|
|
20320
|
-
role: journal
|
|
20355
|
+
// src/upgrade.ts
|
|
20356
|
+
var import_yaml2 = __toESM(require_dist(), 1);
|
|
20321
20357
|
|
|
20322
|
-
|
|
20323
|
-
|
|
20324
|
-
|
|
20358
|
+
// src/git.ts
|
|
20359
|
+
var import_node_child_process3 = require("node:child_process");
|
|
20360
|
+
var import_node_crypto5 = require("node:crypto");
|
|
20361
|
+
var import_node_fs6 = require("node:fs");
|
|
20362
|
+
var import_node_path6 = require("node:path");
|
|
20363
|
+
var GitDiffError = class extends Error {
|
|
20364
|
+
constructor(kind, message) {
|
|
20365
|
+
super(message);
|
|
20366
|
+
this.kind = kind;
|
|
20367
|
+
this.name = "GitDiffError";
|
|
20368
|
+
}
|
|
20369
|
+
kind;
|
|
20370
|
+
};
|
|
20371
|
+
var EMPTY_TREE_BASE = "(empty-tree)";
|
|
20372
|
+
function errorText(error) {
|
|
20373
|
+
const e = error;
|
|
20374
|
+
const stderr = Buffer.isBuffer(e.stderr) ? e.stderr.toString("utf8") : e.stderr;
|
|
20375
|
+
return String(stderr || e.message || error).trim();
|
|
20325
20376
|
}
|
|
20326
|
-
function
|
|
20327
|
-
|
|
20328
|
-
|
|
20329
|
-
|
|
20330
|
-
"
|
|
20331
|
-
|
|
20332
|
-
|
|
20333
|
-
|
|
20334
|
-
|
|
20335
|
-
`
|
|
20336
|
-
],
|
|
20337
|
-
[
|
|
20338
|
-
".agents/knowledge/conventions.md",
|
|
20339
|
-
"# Conventions\n\nNaming, patterns, and style preferences that are not obvious from the code.\n"
|
|
20340
|
-
],
|
|
20341
|
-
[".agents/knowledge/journal/.gitkeep", ""],
|
|
20342
|
-
[".agents/playbooks/.gitkeep", ""],
|
|
20343
|
-
[".agents/adoption.md", adoptionTemplate()]
|
|
20344
|
-
];
|
|
20345
|
-
const collisions = inspectManagedFiles(repo, targets).filter((target) => target.kind !== "missing");
|
|
20346
|
-
if (collisions.length && !force) {
|
|
20347
|
-
err(`init scaffold \u5DF2\u5B58\u5728\uFF08\u7528 --force \u8986\u76D6\uFF09: ${collisions.map((item) => item.relativePath).join(", ")}`);
|
|
20348
|
-
return 1;
|
|
20377
|
+
function git(repo, args) {
|
|
20378
|
+
try {
|
|
20379
|
+
return (0, import_node_child_process3.execFileSync)("git", args, {
|
|
20380
|
+
cwd: repo,
|
|
20381
|
+
encoding: "utf8",
|
|
20382
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
20383
|
+
maxBuffer: 32 * 1024 * 1024
|
|
20384
|
+
});
|
|
20385
|
+
} catch (error) {
|
|
20386
|
+
throw new GitDiffError("diff-failed", `git ${args[0] ?? "command"} failed: ${errorText(error)}`);
|
|
20349
20387
|
}
|
|
20350
|
-
const adoption = captureLegacyEntries(repo);
|
|
20351
|
-
if (adoption.entries.length)
|
|
20352
|
-
ok(`captured ${adoption.entries.length} legacy agent entry/entries under .agents/adoption/ (no root file overwritten)`);
|
|
20353
|
-
const result = writeManagedFiles(repo, targets, {
|
|
20354
|
-
authorize: (inspections) => {
|
|
20355
|
-
if (force) return;
|
|
20356
|
-
const appeared = inspections.filter((target) => target.kind !== "missing");
|
|
20357
|
-
if (appeared.length)
|
|
20358
|
-
throw new Error(`init scaffold changed after preflight: ${appeared.map((item) => item.relativePath).join(", ")}`);
|
|
20359
|
-
}
|
|
20360
|
-
});
|
|
20361
|
-
for (const path of result.written) ok(`wrote ${path}`);
|
|
20362
|
-
info("\nNext: edit .agents/manifest.yaml, then run `harness-kit sync`.");
|
|
20363
|
-
return 0;
|
|
20364
20388
|
}
|
|
20365
|
-
function
|
|
20366
|
-
|
|
20367
|
-
|
|
20368
|
-
|
|
20369
|
-
|
|
20370
|
-
|
|
20371
|
-
|
|
20372
|
-
|
|
20373
|
-
|
|
20374
|
-
|
|
20375
|
-
## Log
|
|
20376
|
-
- (date) observation / friction / decision
|
|
20377
|
-
`;
|
|
20389
|
+
function tryCommit(repo, ref) {
|
|
20390
|
+
try {
|
|
20391
|
+
return (0, import_node_child_process3.execFileSync)("git", ["rev-parse", "--verify", "--end-of-options", `${ref}^{commit}`], {
|
|
20392
|
+
cwd: repo,
|
|
20393
|
+
encoding: "utf8",
|
|
20394
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
20395
|
+
}).trim();
|
|
20396
|
+
} catch {
|
|
20397
|
+
return null;
|
|
20398
|
+
}
|
|
20378
20399
|
}
|
|
20379
|
-
|
|
20380
|
-
|
|
20381
|
-
|
|
20382
|
-
|
|
20383
|
-
|
|
20384
|
-
|
|
20385
|
-
|
|
20386
|
-
|
|
20387
|
-
|
|
20388
|
-
throw new Error("adoption requires both --candidate <bundle> and --audit <receipt>");
|
|
20389
|
-
if ((opts.adoptionCandidate || opts.adoptionAudit) && !opts.adoptExisting)
|
|
20390
|
-
throw new Error("--candidate/--audit are only valid with --adopt-existing");
|
|
20391
|
-
const result = writeManagedFiles(repo, targets, {
|
|
20392
|
-
authorize: (inspections) => {
|
|
20393
|
-
if (opts.adoptExisting && opts.adoptionCandidate && opts.adoptionAudit) {
|
|
20394
|
-
assertManagedFileAdoptionReceipt(repo, inspections, opts.adoptionCandidate, opts.adoptionAudit);
|
|
20395
|
-
return;
|
|
20396
|
-
}
|
|
20397
|
-
assertManagedFileAdoption(repo, inspections, false);
|
|
20398
|
-
}
|
|
20399
|
-
});
|
|
20400
|
-
const preservedAliases = new Set(result.preservedAliases);
|
|
20401
|
-
const written = new Set(result.written);
|
|
20402
|
-
for (const [rel] of targets) {
|
|
20403
|
-
if (preservedAliases.has(rel)) ok(`preserved ${rel} -> AGENTS.md`);
|
|
20404
|
-
else if (written.has(rel)) ok(`wrote ${rel}`);
|
|
20405
|
-
else ok(`${rel} already current`);
|
|
20400
|
+
function gitRoot(repo) {
|
|
20401
|
+
try {
|
|
20402
|
+
return (0, import_node_child_process3.execFileSync)("git", ["rev-parse", "--show-toplevel"], {
|
|
20403
|
+
cwd: repo,
|
|
20404
|
+
encoding: "utf8",
|
|
20405
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
20406
|
+
}).trim();
|
|
20407
|
+
} catch (error) {
|
|
20408
|
+
throw new GitDiffError("not-a-repo", `not a git repo: ${errorText(error)}`);
|
|
20406
20409
|
}
|
|
20407
|
-
info("Context review evidence was not changed; use `record-context-review` only after an Agent reviews the context.");
|
|
20408
20410
|
}
|
|
20409
|
-
|
|
20410
|
-
|
|
20411
|
-
|
|
20412
|
-
|
|
20413
|
-
|
|
20414
|
-
|
|
20415
|
-
|
|
20416
|
-
|
|
20417
|
-
|
|
20411
|
+
function gitAdminDir(repo) {
|
|
20412
|
+
try {
|
|
20413
|
+
return (0, import_node_child_process3.execFileSync)("git", ["rev-parse", "--absolute-git-dir"], {
|
|
20414
|
+
cwd: repo,
|
|
20415
|
+
encoding: "utf8",
|
|
20416
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
20417
|
+
}).trim();
|
|
20418
|
+
} catch (error) {
|
|
20419
|
+
throw new GitDiffError("not-a-repo", `cannot resolve git metadata dir: ${errorText(error)}`);
|
|
20420
|
+
}
|
|
20418
20421
|
}
|
|
20419
|
-
function
|
|
20420
|
-
const
|
|
20421
|
-
|
|
20422
|
-
|
|
20423
|
-
|
|
20424
|
-
|
|
20425
|
-
|
|
20426
|
-
|
|
20427
|
-
|
|
20428
|
-
|
|
20429
|
-
|
|
20430
|
-
|
|
20431
|
-
)
|
|
20432
|
-
} else if (
|
|
20433
|
-
|
|
20434
|
-
|
|
20435
|
-
|
|
20436
|
-
|
|
20437
|
-
|
|
20438
|
-
invariant.rule,
|
|
20439
|
-
"During onboarding or a dedicated Harness-maintenance task, not an unrelated product change.",
|
|
20440
|
-
`invariant ${invariant.id}: no enforcement/check declared \u2014 ${invariant.rule}`
|
|
20441
|
-
));
|
|
20422
|
+
function parseNameStatus(raw, layer) {
|
|
20423
|
+
const fields = raw.split("\0");
|
|
20424
|
+
if (fields.at(-1) === "") fields.pop();
|
|
20425
|
+
const entries = [];
|
|
20426
|
+
for (let i = 0; i < fields.length; ) {
|
|
20427
|
+
const status = fields[i++] ?? "";
|
|
20428
|
+
const code = status[0] ?? "M";
|
|
20429
|
+
const first = fields[i++];
|
|
20430
|
+
if (first === void 0) throw new GitDiffError("diff-failed", "git diff returned malformed name-status output");
|
|
20431
|
+
if (code === "R") {
|
|
20432
|
+
const second = fields[i++];
|
|
20433
|
+
if (second === void 0) throw new GitDiffError("diff-failed", "git diff returned malformed rename output");
|
|
20434
|
+
entries.push({ path: first, status: "D", layer }, { path: second, status: "A", layer });
|
|
20435
|
+
} else if (code === "C") {
|
|
20436
|
+
const second = fields[i++];
|
|
20437
|
+
if (second === void 0) throw new GitDiffError("diff-failed", "git diff returned malformed copy output");
|
|
20438
|
+
entries.push({ path: second, status: "A", layer });
|
|
20439
|
+
} else {
|
|
20440
|
+
entries.push({ path: first, status: code, layer });
|
|
20442
20441
|
}
|
|
20443
20442
|
}
|
|
20444
|
-
|
|
20445
|
-
|
|
20446
|
-
|
|
20447
|
-
|
|
20448
|
-
|
|
20449
|
-
|
|
20450
|
-
|
|
20451
|
-
|
|
20443
|
+
return entries;
|
|
20444
|
+
}
|
|
20445
|
+
function nulList(raw) {
|
|
20446
|
+
return raw.split("\0").filter(Boolean);
|
|
20447
|
+
}
|
|
20448
|
+
function canonicalPath(path) {
|
|
20449
|
+
try {
|
|
20450
|
+
return (0, import_node_fs6.realpathSync)(path);
|
|
20451
|
+
} catch {
|
|
20452
|
+
return (0, import_node_path6.resolve)(path);
|
|
20453
|
+
}
|
|
20454
|
+
}
|
|
20455
|
+
function targetPrefix(root, target) {
|
|
20456
|
+
const native = (0, import_node_path6.relative)(root, target);
|
|
20457
|
+
if (!native) return "";
|
|
20458
|
+
if ((0, import_node_path6.isAbsolute)(native) || native === ".." || native.startsWith(`..${import_node_path6.sep}`))
|
|
20459
|
+
throw new GitDiffError("not-a-repo", `target is outside its Git worktree: ${target}`);
|
|
20460
|
+
return native.split(import_node_path6.sep).join("/");
|
|
20461
|
+
}
|
|
20462
|
+
function scopeEntries(entries, prefix) {
|
|
20463
|
+
if (!prefix) return entries;
|
|
20464
|
+
const start = `${prefix}/`;
|
|
20465
|
+
return entries.filter((entry) => entry.path.startsWith(start)).map((entry) => ({ ...entry, path: entry.path.slice(start.length) }));
|
|
20466
|
+
}
|
|
20467
|
+
function digestPath(repo, rel) {
|
|
20468
|
+
const abs = (0, import_node_path6.join)(repo, rel);
|
|
20469
|
+
try {
|
|
20470
|
+
const stat = (0, import_node_fs6.lstatSync)(abs);
|
|
20471
|
+
if (stat.isSymbolicLink()) return `symlink:${(0, import_node_fs6.readlinkSync)(abs)}`;
|
|
20472
|
+
if (stat.isDirectory()) {
|
|
20473
|
+
try {
|
|
20474
|
+
const head = (0, import_node_child_process3.execFileSync)("git", ["-C", abs, "rev-parse", "--verify", "HEAD"], {
|
|
20475
|
+
encoding: "utf8",
|
|
20476
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
20477
|
+
}).trim();
|
|
20478
|
+
const nested = collectChanges(abs, "HEAD", { mode: "exact" });
|
|
20479
|
+
return `gitlink:${head}:${nested.fingerprint}`;
|
|
20480
|
+
} catch {
|
|
20481
|
+
return `directory:${stat.mode}`;
|
|
20482
|
+
}
|
|
20483
|
+
}
|
|
20484
|
+
if (!stat.isFile()) return `other:${stat.mode}`;
|
|
20485
|
+
const gitMode = stat.mode & 73 ? "100755" : "100644";
|
|
20486
|
+
return `file:${gitMode}:${(0, import_node_crypto5.createHash)("sha256").update((0, import_node_fs6.readFileSync)(abs)).digest("hex")}`;
|
|
20487
|
+
} catch {
|
|
20488
|
+
return "(missing)";
|
|
20489
|
+
}
|
|
20490
|
+
}
|
|
20491
|
+
function digestIndex(repo, rel) {
|
|
20492
|
+
try {
|
|
20493
|
+
const entry = (0, import_node_child_process3.execFileSync)("git", ["ls-files", "--stage", "-z", "--", rel], {
|
|
20494
|
+
cwd: repo,
|
|
20495
|
+
encoding: "utf8",
|
|
20496
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
20497
|
+
});
|
|
20498
|
+
return entry || "(missing-index)";
|
|
20499
|
+
} catch (error) {
|
|
20500
|
+
throw new GitDiffError("diff-failed", `cannot fingerprint Git index entry ${rel}: ${errorText(error)}`);
|
|
20501
|
+
}
|
|
20502
|
+
}
|
|
20503
|
+
function fingerprint(repo, resolvedBase, entries) {
|
|
20504
|
+
const hash = (0, import_node_crypto5.createHash)("sha256");
|
|
20505
|
+
hash.update("harness-kit/change-fingerprint/v1\0");
|
|
20506
|
+
hash.update(resolvedBase ?? EMPTY_TREE_BASE);
|
|
20507
|
+
for (const entry of entries) {
|
|
20508
|
+
hash.update("\0");
|
|
20509
|
+
hash.update(entry.layer);
|
|
20510
|
+
hash.update("\0");
|
|
20511
|
+
hash.update(entry.status);
|
|
20512
|
+
hash.update("\0");
|
|
20513
|
+
hash.update(entry.path);
|
|
20514
|
+
hash.update("\0");
|
|
20515
|
+
hash.update(entry.layer === "index" ? digestIndex(repo, entry.path) : digestPath(repo, entry.path));
|
|
20516
|
+
}
|
|
20517
|
+
return hash.digest("hex");
|
|
20518
|
+
}
|
|
20519
|
+
function collectChanges(repoInput, base = "HEAD", opts = {}) {
|
|
20520
|
+
const target = canonicalPath(repoInput);
|
|
20521
|
+
const root = canonicalPath(gitRoot(target));
|
|
20522
|
+
const prefix = targetPrefix(root, target);
|
|
20523
|
+
const head = tryCommit(root, "HEAD");
|
|
20524
|
+
let baseCommit;
|
|
20525
|
+
if (base === EMPTY_TREE_BASE) {
|
|
20526
|
+
baseCommit = null;
|
|
20527
|
+
} else {
|
|
20528
|
+
baseCommit = tryCommit(root, base);
|
|
20529
|
+
if (!baseCommit && base === "HEAD" && !head) baseCommit = null;
|
|
20530
|
+
else if (!baseCommit) throw new GitDiffError("invalid-base", `invalid base ref: ${base}`);
|
|
20531
|
+
}
|
|
20532
|
+
let resolvedBase = baseCommit;
|
|
20533
|
+
if ((opts.mode ?? "merge-base") === "merge-base" && baseCommit && head) {
|
|
20534
|
+
try {
|
|
20535
|
+
resolvedBase = git(root, ["merge-base", baseCommit, head]).trim();
|
|
20536
|
+
} catch (error) {
|
|
20537
|
+
throw new GitDiffError("invalid-base", `invalid base ref or no merge base: ${base} (${error.message})`);
|
|
20538
|
+
}
|
|
20539
|
+
}
|
|
20540
|
+
let entries;
|
|
20541
|
+
if (resolvedBase) {
|
|
20542
|
+
entries = parseNameStatus(git(root, ["diff", "--cached", "--name-status", "-z", resolvedBase, "--"]), "index");
|
|
20543
|
+
} else {
|
|
20544
|
+
entries = nulList(git(root, ["ls-files", "--cached", "-z"])).map((path) => ({ path, status: "A", layer: "index" }));
|
|
20545
|
+
}
|
|
20546
|
+
entries.push(...parseNameStatus(git(root, ["diff", "--name-status", "-z", "--"]), "worktree"));
|
|
20547
|
+
for (const path of nulList(git(root, ["ls-files", "--others", "--exclude-standard", "-z"]))) {
|
|
20548
|
+
entries.push({ path, status: "A", layer: "untracked" });
|
|
20549
|
+
}
|
|
20550
|
+
entries = scopeEntries(entries, prefix);
|
|
20551
|
+
entries = entries.sort((a, b) => a.path.localeCompare(b.path) || a.layer.localeCompare(b.layer) || a.status.localeCompare(b.status));
|
|
20552
|
+
const files = [...new Set(entries.map((entry) => entry.path))];
|
|
20553
|
+
return {
|
|
20554
|
+
requestedBase: base,
|
|
20555
|
+
resolvedBase,
|
|
20556
|
+
head,
|
|
20557
|
+
files,
|
|
20558
|
+
entries,
|
|
20559
|
+
fingerprint: fingerprint(target, resolvedBase, entries)
|
|
20560
|
+
};
|
|
20561
|
+
}
|
|
20562
|
+
|
|
20563
|
+
// src/upgrade.ts
|
|
20564
|
+
var UPGRADE_STATE_REL = ".agents/harness.lock.json";
|
|
20565
|
+
var UPGRADE_STATE_SCHEMA = "ai-harness/upgrade-state/v1";
|
|
20566
|
+
var UPGRADE_REPORT_SCHEMA = "ai-harness/upgrade-report/v1";
|
|
20567
|
+
var UPGRADE_MIGRATIONS = [
|
|
20568
|
+
{
|
|
20569
|
+
id: "upgrade-state-v1",
|
|
20570
|
+
migrate: () => {
|
|
20571
|
+
}
|
|
20572
|
+
}
|
|
20573
|
+
];
|
|
20574
|
+
function parseSemver(value) {
|
|
20575
|
+
const match = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/.exec(
|
|
20576
|
+
value
|
|
20577
|
+
);
|
|
20578
|
+
if (!match) return null;
|
|
20579
|
+
const prerelease = match[4]?.split(".") ?? [];
|
|
20580
|
+
const core = [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
20581
|
+
if (core.some((part) => !Number.isSafeInteger(part))) return null;
|
|
20582
|
+
if (prerelease.some((part) => /^\d+$/.test(part) && part.length > 1 && part.startsWith("0"))) return null;
|
|
20583
|
+
return {
|
|
20584
|
+
major: core[0],
|
|
20585
|
+
minor: core[1],
|
|
20586
|
+
patch: core[2],
|
|
20587
|
+
prerelease
|
|
20588
|
+
};
|
|
20589
|
+
}
|
|
20590
|
+
function comparePrerelease(left, right) {
|
|
20591
|
+
if (!left.length || !right.length) return left.length === right.length ? 0 : left.length ? -1 : 1;
|
|
20592
|
+
const length = Math.max(left.length, right.length);
|
|
20593
|
+
for (let index = 0; index < length; index++) {
|
|
20594
|
+
const a = left[index];
|
|
20595
|
+
const b = right[index];
|
|
20596
|
+
if (a === void 0 || b === void 0) return a === b ? 0 : a === void 0 ? -1 : 1;
|
|
20597
|
+
if (a === b) continue;
|
|
20598
|
+
const aNumeric = /^\d+$/.test(a);
|
|
20599
|
+
const bNumeric = /^\d+$/.test(b);
|
|
20600
|
+
if (aNumeric && bNumeric) return a.length === b.length ? a < b ? -1 : 1 : a.length < b.length ? -1 : 1;
|
|
20601
|
+
if (aNumeric !== bNumeric) return aNumeric ? -1 : 1;
|
|
20602
|
+
return a < b ? -1 : 1;
|
|
20603
|
+
}
|
|
20604
|
+
return 0;
|
|
20605
|
+
}
|
|
20606
|
+
function compareSemver(left, right) {
|
|
20607
|
+
for (const key of ["major", "minor", "patch"]) {
|
|
20608
|
+
if (left[key] !== right[key]) return left[key] < right[key] ? -1 : 1;
|
|
20609
|
+
}
|
|
20610
|
+
return comparePrerelease(left.prerelease, right.prerelease);
|
|
20611
|
+
}
|
|
20612
|
+
function reportBase(options) {
|
|
20613
|
+
return {
|
|
20614
|
+
schema: UPGRADE_REPORT_SCHEMA,
|
|
20615
|
+
status: "blocked",
|
|
20616
|
+
package: options.packageName,
|
|
20617
|
+
fromVersion: null,
|
|
20618
|
+
toVersion: options.targetVersion,
|
|
20619
|
+
manifestSpec: null,
|
|
20620
|
+
pendingMigrations: [],
|
|
20621
|
+
appliedMigrations: [],
|
|
20622
|
+
changedFiles: [],
|
|
20623
|
+
dirtyFiles: [],
|
|
20624
|
+
hooksChanged: false,
|
|
20625
|
+
errors: [],
|
|
20626
|
+
notes: ["upgrade does not install, remove, or rewrite lifecycle hooks"]
|
|
20627
|
+
};
|
|
20628
|
+
}
|
|
20629
|
+
function fail(report, message) {
|
|
20630
|
+
report.status = "blocked";
|
|
20631
|
+
report.errors.push(message);
|
|
20632
|
+
return report;
|
|
20633
|
+
}
|
|
20634
|
+
function parseState(content, options, report) {
|
|
20635
|
+
let value;
|
|
20636
|
+
try {
|
|
20637
|
+
value = JSON.parse(content);
|
|
20638
|
+
} catch (error) {
|
|
20639
|
+
return fail(report, `${UPGRADE_STATE_REL} is not valid JSON: ${error.message}`);
|
|
20640
|
+
}
|
|
20641
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
20642
|
+
return fail(report, `${UPGRADE_STATE_REL} root must be an object`);
|
|
20643
|
+
const candidate = value;
|
|
20644
|
+
if (candidate.schema !== UPGRADE_STATE_SCHEMA)
|
|
20645
|
+
return fail(report, `${UPGRADE_STATE_REL} has unsupported schema: ${String(candidate.schema)}`);
|
|
20646
|
+
if (candidate.package !== options.packageName)
|
|
20647
|
+
return fail(report, `${UPGRADE_STATE_REL} belongs to ${String(candidate.package)}, not ${options.packageName}`);
|
|
20648
|
+
if (typeof candidate.version !== "string" || !parseSemver(candidate.version))
|
|
20649
|
+
return fail(report, `${UPGRADE_STATE_REL} has invalid version: ${String(candidate.version)}`);
|
|
20650
|
+
if (typeof candidate.manifestSpec !== "string" || !candidate.manifestSpec)
|
|
20651
|
+
return fail(report, `${UPGRADE_STATE_REL} has invalid manifestSpec`);
|
|
20652
|
+
if (!Array.isArray(candidate.appliedMigrations) || candidate.appliedMigrations.some((id) => typeof id !== "string"))
|
|
20653
|
+
return fail(report, `${UPGRADE_STATE_REL} appliedMigrations must be a string array`);
|
|
20654
|
+
const unique = new Set(candidate.appliedMigrations);
|
|
20655
|
+
if (unique.size !== candidate.appliedMigrations.length)
|
|
20656
|
+
return fail(report, `${UPGRADE_STATE_REL} appliedMigrations contains duplicates`);
|
|
20657
|
+
const known = new Set(UPGRADE_MIGRATIONS.map((migration) => migration.id));
|
|
20658
|
+
const unknown = candidate.appliedMigrations.filter((id) => !known.has(id));
|
|
20659
|
+
if (unknown.length) return fail(report, `${UPGRADE_STATE_REL} contains unknown migrations: ${unknown.join(", ")}`);
|
|
20660
|
+
return candidate;
|
|
20661
|
+
}
|
|
20662
|
+
function sameInspection(left, right) {
|
|
20663
|
+
return left.relativePath === right.relativePath && left.absolutePath === right.absolutePath && left.kind === right.kind && left.currentContent === right.currentContent && left.linkTarget === right.linkTarget;
|
|
20664
|
+
}
|
|
20665
|
+
function renderState(state) {
|
|
20666
|
+
return `${JSON.stringify(state, null, 2)}
|
|
20667
|
+
`;
|
|
20668
|
+
}
|
|
20669
|
+
function asManifest(document, report) {
|
|
20670
|
+
if (document.errors.length)
|
|
20671
|
+
return fail(report, `${MANIFEST_REL} YAML is invalid: ${document.errors.map((error) => error.message).join("; ")}`);
|
|
20672
|
+
const value = document.toJS();
|
|
20673
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
20674
|
+
return fail(report, `${MANIFEST_REL} root must be an object`);
|
|
20675
|
+
const manifest = value;
|
|
20676
|
+
const errors = validateManifest(manifest).filter((issue) => issue.level === "error");
|
|
20677
|
+
if (errors.length) return fail(report, `manifest invalid: ${errors.map((issue) => issue.msg).join("; ")}`);
|
|
20678
|
+
return manifest;
|
|
20679
|
+
}
|
|
20680
|
+
function internalUpgrade(repo, options) {
|
|
20681
|
+
const report = reportBase(options);
|
|
20682
|
+
const targetSemver = parseSemver(options.targetVersion);
|
|
20683
|
+
if (!targetSemver) return fail(report, `running harness-kit has an invalid version: ${options.targetVersion}`);
|
|
20684
|
+
const changes = collectChanges(repo, "HEAD", { mode: "exact" });
|
|
20685
|
+
report.dirtyFiles = changes.files;
|
|
20686
|
+
if (!options.check && report.dirtyFiles.length)
|
|
20687
|
+
return fail(report, `repository has uncommitted changes: ${report.dirtyFiles.join(", ")}`);
|
|
20688
|
+
const sourceInspections = inspectManagedFiles(repo, [
|
|
20689
|
+
[MANIFEST_REL, ""],
|
|
20690
|
+
[UPGRADE_STATE_REL, ""]
|
|
20691
|
+
]);
|
|
20692
|
+
const manifestInspection = sourceInspections[0];
|
|
20693
|
+
const stateInspection = sourceInspections[1];
|
|
20694
|
+
if (manifestInspection.kind === "missing" || manifestInspection.currentContent === null)
|
|
20695
|
+
return fail(report, `${MANIFEST_REL} is missing; run harness-kit init first`);
|
|
20696
|
+
let state = null;
|
|
20697
|
+
if (stateInspection.kind !== "missing") {
|
|
20698
|
+
if (stateInspection.currentContent === null) return fail(report, `${UPGRADE_STATE_REL} is not a readable regular file`);
|
|
20699
|
+
const parsed = parseState(stateInspection.currentContent, options, report);
|
|
20700
|
+
if ("status" in parsed) return parsed;
|
|
20701
|
+
state = parsed;
|
|
20702
|
+
report.fromVersion = state.version;
|
|
20703
|
+
report.appliedMigrations = [...state.appliedMigrations];
|
|
20704
|
+
const currentSemver = parseSemver(state.version);
|
|
20705
|
+
if (compareSemver(currentSemver, targetSemver) > 0)
|
|
20706
|
+
return fail(report, `refusing downgrade from ${state.version} to ${options.targetVersion}`);
|
|
20707
|
+
}
|
|
20708
|
+
const document = (0, import_yaml2.parseDocument)(manifestInspection.currentContent);
|
|
20709
|
+
const sourceManifest = asManifest(document, report);
|
|
20710
|
+
if ("status" in sourceManifest) return sourceManifest;
|
|
20711
|
+
report.manifestSpec = sourceManifest.spec;
|
|
20712
|
+
const normalizedSource = document.toString();
|
|
20713
|
+
const applied = new Set(state?.appliedMigrations ?? []);
|
|
20714
|
+
const pending = UPGRADE_MIGRATIONS.filter((migration) => !applied.has(migration.id));
|
|
20715
|
+
report.pendingMigrations = pending.map((migration) => migration.id);
|
|
20716
|
+
for (const migration of pending) migration.migrate(document);
|
|
20717
|
+
const finalManifest = asManifest(document, report);
|
|
20718
|
+
if ("status" in finalManifest) return finalManifest;
|
|
20719
|
+
const migratedManifestContent = document.toString();
|
|
20720
|
+
const nextState = {
|
|
20721
|
+
schema: UPGRADE_STATE_SCHEMA,
|
|
20722
|
+
package: options.packageName,
|
|
20723
|
+
version: options.targetVersion,
|
|
20724
|
+
manifestSpec: finalManifest.spec,
|
|
20725
|
+
appliedMigrations: UPGRADE_MIGRATIONS.map((migration) => migration.id)
|
|
20726
|
+
};
|
|
20727
|
+
const manifestChanged = migratedManifestContent !== normalizedSource;
|
|
20728
|
+
const finalManifestContent = manifestChanged ? migratedManifestContent : manifestInspection.currentContent;
|
|
20729
|
+
const targets = [
|
|
20730
|
+
// Keep an unchanged manifest in the transaction preflight so generated
|
|
20731
|
+
// files can never be committed from bytes that changed after planning.
|
|
20732
|
+
[MANIFEST_REL, finalManifestContent],
|
|
20733
|
+
...renderTargets(finalManifest),
|
|
20734
|
+
[UPGRADE_STATE_REL, renderState(nextState)]
|
|
20735
|
+
];
|
|
20736
|
+
const preflight = inspectManagedFiles(repo, targets);
|
|
20737
|
+
const generatedPaths = new Set(renderTargets(finalManifest).map(([path]) => path));
|
|
20738
|
+
try {
|
|
20739
|
+
assertManagedFileAdoption(
|
|
20740
|
+
repo,
|
|
20741
|
+
preflight.filter((inspection) => generatedPaths.has(inspection.relativePath)),
|
|
20742
|
+
false
|
|
20743
|
+
);
|
|
20744
|
+
} catch (error) {
|
|
20745
|
+
return fail(report, error.message);
|
|
20746
|
+
}
|
|
20747
|
+
report.changedFiles = preflight.filter((inspection) => !inspection.satisfiesDesired).map((inspection) => inspection.relativePath);
|
|
20748
|
+
const stateMatchesManifest = state?.manifestSpec === finalManifest.spec;
|
|
20749
|
+
const stateMatchesVersion = state?.version === options.targetVersion;
|
|
20750
|
+
const stateMatchesMigrations = state?.appliedMigrations.join("\0") === nextState.appliedMigrations.join("\0");
|
|
20751
|
+
const needsUpgrade = report.changedFiles.length > 0 || !stateMatchesManifest || !stateMatchesVersion || !stateMatchesMigrations;
|
|
20752
|
+
if (options.check) {
|
|
20753
|
+
report.status = needsUpgrade ? "upgrade-available" : "current";
|
|
20754
|
+
return report;
|
|
20755
|
+
}
|
|
20756
|
+
if (!needsUpgrade) {
|
|
20757
|
+
report.status = "current";
|
|
20758
|
+
report.pendingMigrations = [];
|
|
20759
|
+
return report;
|
|
20760
|
+
}
|
|
20761
|
+
const expected = new Map(preflight.map((inspection) => [inspection.relativePath, inspection]));
|
|
20762
|
+
const result = writeManagedFiles(repo, targets, {
|
|
20763
|
+
authorize: (inspections) => {
|
|
20764
|
+
for (const inspection of inspections) {
|
|
20765
|
+
const prior = expected.get(inspection.relativePath);
|
|
20766
|
+
if (!prior || !sameInspection(prior, inspection))
|
|
20767
|
+
throw new Error(`upgrade target changed after inspection: ${inspection.relativePath}`);
|
|
20768
|
+
}
|
|
20769
|
+
assertManagedFileAdoption(
|
|
20770
|
+
repo,
|
|
20771
|
+
inspections.filter((inspection) => generatedPaths.has(inspection.relativePath)),
|
|
20772
|
+
false
|
|
20773
|
+
);
|
|
20774
|
+
}
|
|
20775
|
+
});
|
|
20776
|
+
report.status = "upgraded";
|
|
20777
|
+
report.changedFiles = result.written;
|
|
20778
|
+
report.appliedMigrations = nextState.appliedMigrations;
|
|
20779
|
+
return report;
|
|
20780
|
+
}
|
|
20781
|
+
function upgradeRepository(repo, options) {
|
|
20782
|
+
try {
|
|
20783
|
+
return internalUpgrade(repo, options);
|
|
20784
|
+
} catch (error) {
|
|
20785
|
+
return fail(reportBase(options), error.message);
|
|
20786
|
+
}
|
|
20787
|
+
}
|
|
20788
|
+
function initialUpgradeState(packageName, version, manifestSpec) {
|
|
20789
|
+
return renderState({
|
|
20790
|
+
schema: UPGRADE_STATE_SCHEMA,
|
|
20791
|
+
package: packageName,
|
|
20792
|
+
version,
|
|
20793
|
+
manifestSpec,
|
|
20794
|
+
appliedMigrations: UPGRADE_MIGRATIONS.map((migration) => migration.id)
|
|
20795
|
+
});
|
|
20796
|
+
}
|
|
20797
|
+
|
|
20798
|
+
// src/commands/init.ts
|
|
20799
|
+
function manifestTemplate(name) {
|
|
20800
|
+
return `spec: ai-harness/v0
|
|
20801
|
+
|
|
20802
|
+
identity:
|
|
20803
|
+
name: ${name}
|
|
20804
|
+
summary: TODO one-line description of what this repo is
|
|
20805
|
+
scope_in: []
|
|
20806
|
+
scope_out: []
|
|
20807
|
+
upstream: []
|
|
20808
|
+
downstream: []
|
|
20809
|
+
|
|
20810
|
+
capabilities:
|
|
20811
|
+
setup: { run: "pnpm install" }
|
|
20812
|
+
build: { run: "pnpm build" }
|
|
20813
|
+
test: { run: "pnpm test" }
|
|
20814
|
+
lint: { run: "pnpm lint" }
|
|
20815
|
+
verify: { run: "harness-kit verify" }
|
|
20816
|
+
|
|
20817
|
+
environment: []
|
|
20818
|
+
|
|
20819
|
+
contracts: []
|
|
20820
|
+
|
|
20821
|
+
invariants:
|
|
20822
|
+
- id: no-console-log
|
|
20823
|
+
rule: No stray console.log left in source
|
|
20824
|
+
enforcement:
|
|
20825
|
+
forbid_pattern: ["console\\\\.log\\\\("]
|
|
20826
|
+
path_glob: ["src/**"]
|
|
20827
|
+
- id: no-hardcoded-secret
|
|
20828
|
+
rule: Do not hardcode secrets / tokens in source
|
|
20829
|
+
enforcement:
|
|
20830
|
+
forbid_pattern: ["(password|secret|token)\\\\s*[:=]\\\\s*[\\"'][^\\"']+[\\"']"]
|
|
20831
|
+
path_glob: ["src/**"]
|
|
20832
|
+
|
|
20833
|
+
knowledge:
|
|
20834
|
+
- path: knowledge/domain.md
|
|
20835
|
+
role: domain
|
|
20836
|
+
- path: knowledge/conventions.md
|
|
20837
|
+
role: conventions
|
|
20838
|
+
- path: knowledge/journal/
|
|
20839
|
+
role: journal
|
|
20840
|
+
|
|
20841
|
+
playbooks:
|
|
20842
|
+
dir: playbooks/
|
|
20843
|
+
`;
|
|
20844
|
+
}
|
|
20845
|
+
function initCmd(repo, name, force) {
|
|
20846
|
+
const targets = [
|
|
20847
|
+
[".agents/manifest.yaml", manifestTemplate(name)],
|
|
20848
|
+
[UPGRADE_STATE_REL, initialUpgradeState(package_default.name, package_default.version, "ai-harness/v0")],
|
|
20849
|
+
[
|
|
20850
|
+
".agents/knowledge/domain.md",
|
|
20851
|
+
`# ${name} \u2014 domain
|
|
20852
|
+
|
|
20853
|
+
What this project does and its key concepts.
|
|
20854
|
+
Write only what an agent cannot infer from the code.
|
|
20855
|
+
`
|
|
20856
|
+
],
|
|
20857
|
+
[
|
|
20858
|
+
".agents/knowledge/conventions.md",
|
|
20859
|
+
"# Conventions\n\nNaming, patterns, and style preferences that are not obvious from the code.\n"
|
|
20860
|
+
],
|
|
20861
|
+
[".agents/knowledge/journal/.gitkeep", ""],
|
|
20862
|
+
[".agents/playbooks/.gitkeep", ""],
|
|
20863
|
+
[".agents/adoption.md", adoptionTemplate()]
|
|
20864
|
+
];
|
|
20865
|
+
const collisions = inspectManagedFiles(repo, targets).filter((target) => target.kind !== "missing");
|
|
20866
|
+
if (collisions.length && !force) {
|
|
20867
|
+
err(`init scaffold \u5DF2\u5B58\u5728\uFF08\u7528 --force \u8986\u76D6\uFF09: ${collisions.map((item) => item.relativePath).join(", ")}`);
|
|
20868
|
+
return 1;
|
|
20869
|
+
}
|
|
20870
|
+
const adoption = captureLegacyEntries(repo);
|
|
20871
|
+
if (adoption.entries.length)
|
|
20872
|
+
ok(`captured ${adoption.entries.length} legacy agent entry/entries under .agents/adoption/ (no root file overwritten)`);
|
|
20873
|
+
const result = writeManagedFiles(repo, targets, {
|
|
20874
|
+
authorize: (inspections) => {
|
|
20875
|
+
if (force) return;
|
|
20876
|
+
const appeared = inspections.filter((target) => target.kind !== "missing");
|
|
20877
|
+
if (appeared.length)
|
|
20878
|
+
throw new Error(`init scaffold changed after preflight: ${appeared.map((item) => item.relativePath).join(", ")}`);
|
|
20879
|
+
}
|
|
20880
|
+
});
|
|
20881
|
+
for (const path of result.written) ok(`wrote ${path}`);
|
|
20882
|
+
info("\nNext: edit .agents/manifest.yaml, then run `harness-kit sync`.");
|
|
20883
|
+
return 0;
|
|
20884
|
+
}
|
|
20885
|
+
function adoptionTemplate() {
|
|
20886
|
+
return `# Tooling adoption log
|
|
20887
|
+
|
|
20888
|
+
Earn heavier tooling with evidence. Default posture: prefer the lightest thing that works,
|
|
20889
|
+
and only promote a convention to a machine check (\`harness-kit verify\`) after it actually bites.
|
|
20890
|
+
|
|
20891
|
+
## When to promote a soft convention to an enforced invariant
|
|
20892
|
+
- The same mistake slipped through 3+ times, OR
|
|
20893
|
+
- A manual convention held for 1+ week and is clearly worth locking in.
|
|
20894
|
+
|
|
20895
|
+
## Log
|
|
20896
|
+
- (date) observation / friction / decision
|
|
20897
|
+
`;
|
|
20898
|
+
}
|
|
20899
|
+
|
|
20900
|
+
// src/commands/sync.ts
|
|
20901
|
+
function syncCmd(repo, opts = {}) {
|
|
20902
|
+
const m = loadManifest(repo);
|
|
20903
|
+
const errors = validateManifest(m).filter((issue) => issue.level === "error");
|
|
20904
|
+
if (errors.length) throw new Error(`manifest invalid: ${errors.map((issue) => issue.msg).join("; ")}`);
|
|
20905
|
+
info("Syncing generated files from .agents/manifest.yaml ...");
|
|
20906
|
+
const targets = renderTargets(m);
|
|
20907
|
+
if (!!opts.adoptionCandidate !== !!opts.adoptionAudit)
|
|
20908
|
+
throw new Error("adoption requires both --candidate <bundle> and --audit <receipt>");
|
|
20909
|
+
if ((opts.adoptionCandidate || opts.adoptionAudit) && !opts.adoptExisting)
|
|
20910
|
+
throw new Error("--candidate/--audit are only valid with --adopt-existing");
|
|
20911
|
+
const result = writeManagedFiles(repo, targets, {
|
|
20912
|
+
authorize: (inspections) => {
|
|
20913
|
+
if (opts.adoptExisting && opts.adoptionCandidate && opts.adoptionAudit) {
|
|
20914
|
+
assertManagedFileAdoptionReceipt(repo, inspections, opts.adoptionCandidate, opts.adoptionAudit);
|
|
20915
|
+
return;
|
|
20916
|
+
}
|
|
20917
|
+
assertManagedFileAdoption(repo, inspections, false);
|
|
20918
|
+
}
|
|
20919
|
+
});
|
|
20920
|
+
const preservedAliases = new Set(result.preservedAliases);
|
|
20921
|
+
const written = new Set(result.written);
|
|
20922
|
+
for (const [rel] of targets) {
|
|
20923
|
+
if (preservedAliases.has(rel)) ok(`preserved ${rel} -> AGENTS.md`);
|
|
20924
|
+
else if (written.has(rel)) ok(`wrote ${rel}`);
|
|
20925
|
+
else ok(`${rel} already current`);
|
|
20926
|
+
}
|
|
20927
|
+
info("Context review evidence was not changed; use `record-context-review` only after an Agent reviews the context.");
|
|
20928
|
+
}
|
|
20929
|
+
|
|
20930
|
+
// src/commands/doctor.ts
|
|
20931
|
+
var import_fast_glob3 = __toESM(require_out4(), 1);
|
|
20932
|
+
var import_node_fs12 = require("node:fs");
|
|
20933
|
+
var import_node_path12 = require("node:path");
|
|
20934
|
+
|
|
20935
|
+
// src/guidance.ts
|
|
20936
|
+
function gap(kind, scope, classification, title, reason, when, legacyText) {
|
|
20937
|
+
return { id: `${kind}:${scope}`, kind, scope, classification, title, reason, when, legacyText };
|
|
20938
|
+
}
|
|
20939
|
+
function declaredVerificationGaps(manifest) {
|
|
20940
|
+
const gaps = [];
|
|
20941
|
+
for (const invariant of manifest.invariants ?? []) {
|
|
20942
|
+
if (invariant.manual) {
|
|
20943
|
+
gaps.push(gap(
|
|
20944
|
+
"manual-invariant",
|
|
20945
|
+
invariant.id,
|
|
20946
|
+
"informational",
|
|
20947
|
+
`Review invariant ${invariant.id} when relevant`,
|
|
20948
|
+
invariant.rule,
|
|
20949
|
+
"Only when a change may affect this declared rule.",
|
|
20950
|
+
`invariant ${invariant.id}: manual, not machine-enforced \u2014 ${invariant.rule}`
|
|
20951
|
+
));
|
|
20952
|
+
} else if (!invariant.enforcement && !invariant.check) {
|
|
20953
|
+
gaps.push(gap(
|
|
20954
|
+
"unenforced-invariant",
|
|
20955
|
+
invariant.id,
|
|
20956
|
+
"recommended",
|
|
20957
|
+
`Add enforcement for invariant ${invariant.id}`,
|
|
20958
|
+
invariant.rule,
|
|
20959
|
+
"During onboarding or a dedicated Harness-maintenance task, not an unrelated product change.",
|
|
20960
|
+
`invariant ${invariant.id}: no enforcement/check declared \u2014 ${invariant.rule}`
|
|
20961
|
+
));
|
|
20962
|
+
}
|
|
20963
|
+
}
|
|
20964
|
+
for (const contract of manifest.contracts ?? []) {
|
|
20965
|
+
if (contract.check || contract.snapshot) continue;
|
|
20966
|
+
const legacyText = `contract ${contract.id}: no automatic check` + (contract.manual_verify ? ` \u2014 verify by hand: ${contract.manual_verify}` : "");
|
|
20967
|
+
if (contract.manual_verify) {
|
|
20968
|
+
gaps.push(gap(
|
|
20969
|
+
"manual-contract",
|
|
20970
|
+
contract.id,
|
|
20971
|
+
"informational",
|
|
20452
20972
|
`Verify contract ${contract.id} when it changes`,
|
|
20453
20973
|
contract.manual_verify,
|
|
20454
20974
|
"Only when this contract is changed or before the release that carries it.",
|
|
@@ -20584,273 +21104,66 @@ function evidenceActions(evidence) {
|
|
|
20584
21104
|
reason: "The saved green result belongs to an older code fingerprint.",
|
|
20585
21105
|
commands: [
|
|
20586
21106
|
"harness-kit run-checks --repo . --base <task-start-sha>",
|
|
20587
|
-
"harness-kit verify --repo .",
|
|
20588
|
-
"harness-kit evidence --repo . --json"
|
|
20589
|
-
],
|
|
20590
|
-
completion: "Evidence is no longer stale and reports valid: true."
|
|
20591
|
-
}];
|
|
20592
|
-
}
|
|
20593
|
-
if (!evidence.runChecksValid) {
|
|
20594
|
-
return [{
|
|
20595
|
-
id: "complete-run-checks",
|
|
20596
|
-
priority: "required",
|
|
20597
|
-
owner: "agent",
|
|
20598
|
-
when: "before-finish",
|
|
20599
|
-
title: "Complete the impact-driven checks",
|
|
20600
|
-
reason: "The selected checks did not produce valid evidence for the current code.",
|
|
20601
|
-
commands: ["harness-kit run-checks --repo . --base <task-start-sha>", "harness-kit evidence --repo . --json"],
|
|
20602
|
-
completion: "Evidence reports runChecksValid: true for the current code fingerprint."
|
|
20603
|
-
}];
|
|
20604
|
-
}
|
|
20605
|
-
if (!evidence.verifyPassed || !evidence.valid) {
|
|
20606
|
-
return [{
|
|
20607
|
-
id: "complete-verify",
|
|
20608
|
-
priority: "required",
|
|
20609
|
-
owner: "agent",
|
|
20610
|
-
when: "before-finish",
|
|
20611
|
-
title: "Complete repository verification",
|
|
20612
|
-
reason: "Change checks passed, but matching verify evidence is missing or failed.",
|
|
20613
|
-
commands: ["harness-kit verify --repo .", "harness-kit evidence --repo . --json"],
|
|
20614
|
-
completion: "Evidence reports valid: true for the current code fingerprint."
|
|
20615
|
-
}];
|
|
20616
|
-
}
|
|
20617
|
-
return [];
|
|
20618
|
-
}
|
|
20619
|
-
function buildHarnessGuidance(input) {
|
|
20620
|
-
const gapDetails = input.manifest ? declaredVerificationGaps(input.manifest) : [];
|
|
20621
|
-
const nextActions = [
|
|
20622
|
-
...input.evidence ? evidenceActions(input.evidence) : [],
|
|
20623
|
-
...input.hooks ? hookActions(input.hooks) : []
|
|
20624
|
-
];
|
|
20625
|
-
const improvement = automationAction(gapDetails);
|
|
20626
|
-
if (improvement) nextActions.push(improvement);
|
|
20627
|
-
return {
|
|
20628
|
-
gapDetails,
|
|
20629
|
-
gapSummary: {
|
|
20630
|
-
total: gapDetails.length,
|
|
20631
|
-
recommended: gapDetails.filter((item) => item.classification === "recommended").length,
|
|
20632
|
-
informational: gapDetails.filter((item) => item.classification === "informational").length
|
|
20633
|
-
},
|
|
20634
|
-
nextActions
|
|
20635
|
-
};
|
|
20636
|
-
}
|
|
20637
|
-
|
|
20638
|
-
// src/hook-status.ts
|
|
20639
|
-
var import_node_fs10 = require("node:fs");
|
|
20640
|
-
var import_node_path10 = require("node:path");
|
|
20641
|
-
|
|
20642
|
-
// src/codex-linked-hooks.ts
|
|
20643
|
-
var import_node_child_process4 = require("node:child_process");
|
|
20644
|
-
var import_node_fs7 = require("node:fs");
|
|
20645
|
-
var import_node_os = require("node:os");
|
|
20646
|
-
var import_node_path7 = require("node:path");
|
|
20647
|
-
|
|
20648
|
-
// src/git.ts
|
|
20649
|
-
var import_node_child_process3 = require("node:child_process");
|
|
20650
|
-
var import_node_crypto5 = require("node:crypto");
|
|
20651
|
-
var import_node_fs6 = require("node:fs");
|
|
20652
|
-
var import_node_path6 = require("node:path");
|
|
20653
|
-
var GitDiffError = class extends Error {
|
|
20654
|
-
constructor(kind, message) {
|
|
20655
|
-
super(message);
|
|
20656
|
-
this.kind = kind;
|
|
20657
|
-
this.name = "GitDiffError";
|
|
20658
|
-
}
|
|
20659
|
-
kind;
|
|
20660
|
-
};
|
|
20661
|
-
var EMPTY_TREE_BASE = "(empty-tree)";
|
|
20662
|
-
function errorText(error) {
|
|
20663
|
-
const e = error;
|
|
20664
|
-
const stderr = Buffer.isBuffer(e.stderr) ? e.stderr.toString("utf8") : e.stderr;
|
|
20665
|
-
return String(stderr || e.message || error).trim();
|
|
20666
|
-
}
|
|
20667
|
-
function git(repo, args) {
|
|
20668
|
-
try {
|
|
20669
|
-
return (0, import_node_child_process3.execFileSync)("git", args, {
|
|
20670
|
-
cwd: repo,
|
|
20671
|
-
encoding: "utf8",
|
|
20672
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
20673
|
-
maxBuffer: 32 * 1024 * 1024
|
|
20674
|
-
});
|
|
20675
|
-
} catch (error) {
|
|
20676
|
-
throw new GitDiffError("diff-failed", `git ${args[0] ?? "command"} failed: ${errorText(error)}`);
|
|
20677
|
-
}
|
|
20678
|
-
}
|
|
20679
|
-
function tryCommit(repo, ref) {
|
|
20680
|
-
try {
|
|
20681
|
-
return (0, import_node_child_process3.execFileSync)("git", ["rev-parse", "--verify", "--end-of-options", `${ref}^{commit}`], {
|
|
20682
|
-
cwd: repo,
|
|
20683
|
-
encoding: "utf8",
|
|
20684
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
20685
|
-
}).trim();
|
|
20686
|
-
} catch {
|
|
20687
|
-
return null;
|
|
20688
|
-
}
|
|
20689
|
-
}
|
|
20690
|
-
function gitRoot(repo) {
|
|
20691
|
-
try {
|
|
20692
|
-
return (0, import_node_child_process3.execFileSync)("git", ["rev-parse", "--show-toplevel"], {
|
|
20693
|
-
cwd: repo,
|
|
20694
|
-
encoding: "utf8",
|
|
20695
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
20696
|
-
}).trim();
|
|
20697
|
-
} catch (error) {
|
|
20698
|
-
throw new GitDiffError("not-a-repo", `not a git repo: ${errorText(error)}`);
|
|
20699
|
-
}
|
|
20700
|
-
}
|
|
20701
|
-
function gitAdminDir(repo) {
|
|
20702
|
-
try {
|
|
20703
|
-
return (0, import_node_child_process3.execFileSync)("git", ["rev-parse", "--absolute-git-dir"], {
|
|
20704
|
-
cwd: repo,
|
|
20705
|
-
encoding: "utf8",
|
|
20706
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
20707
|
-
}).trim();
|
|
20708
|
-
} catch (error) {
|
|
20709
|
-
throw new GitDiffError("not-a-repo", `cannot resolve git metadata dir: ${errorText(error)}`);
|
|
20710
|
-
}
|
|
20711
|
-
}
|
|
20712
|
-
function parseNameStatus(raw, layer) {
|
|
20713
|
-
const fields = raw.split("\0");
|
|
20714
|
-
if (fields.at(-1) === "") fields.pop();
|
|
20715
|
-
const entries = [];
|
|
20716
|
-
for (let i = 0; i < fields.length; ) {
|
|
20717
|
-
const status = fields[i++] ?? "";
|
|
20718
|
-
const code = status[0] ?? "M";
|
|
20719
|
-
const first = fields[i++];
|
|
20720
|
-
if (first === void 0) throw new GitDiffError("diff-failed", "git diff returned malformed name-status output");
|
|
20721
|
-
if (code === "R") {
|
|
20722
|
-
const second = fields[i++];
|
|
20723
|
-
if (second === void 0) throw new GitDiffError("diff-failed", "git diff returned malformed rename output");
|
|
20724
|
-
entries.push({ path: first, status: "D", layer }, { path: second, status: "A", layer });
|
|
20725
|
-
} else if (code === "C") {
|
|
20726
|
-
const second = fields[i++];
|
|
20727
|
-
if (second === void 0) throw new GitDiffError("diff-failed", "git diff returned malformed copy output");
|
|
20728
|
-
entries.push({ path: second, status: "A", layer });
|
|
20729
|
-
} else {
|
|
20730
|
-
entries.push({ path: first, status: code, layer });
|
|
20731
|
-
}
|
|
20732
|
-
}
|
|
20733
|
-
return entries;
|
|
20734
|
-
}
|
|
20735
|
-
function nulList(raw) {
|
|
20736
|
-
return raw.split("\0").filter(Boolean);
|
|
20737
|
-
}
|
|
20738
|
-
function canonicalPath(path) {
|
|
20739
|
-
try {
|
|
20740
|
-
return (0, import_node_fs6.realpathSync)(path);
|
|
20741
|
-
} catch {
|
|
20742
|
-
return (0, import_node_path6.resolve)(path);
|
|
20743
|
-
}
|
|
20744
|
-
}
|
|
20745
|
-
function targetPrefix(root, target) {
|
|
20746
|
-
const native = (0, import_node_path6.relative)(root, target);
|
|
20747
|
-
if (!native) return "";
|
|
20748
|
-
if ((0, import_node_path6.isAbsolute)(native) || native === ".." || native.startsWith(`..${import_node_path6.sep}`))
|
|
20749
|
-
throw new GitDiffError("not-a-repo", `target is outside its Git worktree: ${target}`);
|
|
20750
|
-
return native.split(import_node_path6.sep).join("/");
|
|
20751
|
-
}
|
|
20752
|
-
function scopeEntries(entries, prefix) {
|
|
20753
|
-
if (!prefix) return entries;
|
|
20754
|
-
const start = `${prefix}/`;
|
|
20755
|
-
return entries.filter((entry) => entry.path.startsWith(start)).map((entry) => ({ ...entry, path: entry.path.slice(start.length) }));
|
|
20756
|
-
}
|
|
20757
|
-
function digestPath(repo, rel) {
|
|
20758
|
-
const abs = (0, import_node_path6.join)(repo, rel);
|
|
20759
|
-
try {
|
|
20760
|
-
const stat = (0, import_node_fs6.lstatSync)(abs);
|
|
20761
|
-
if (stat.isSymbolicLink()) return `symlink:${(0, import_node_fs6.readlinkSync)(abs)}`;
|
|
20762
|
-
if (stat.isDirectory()) {
|
|
20763
|
-
try {
|
|
20764
|
-
const head = (0, import_node_child_process3.execFileSync)("git", ["-C", abs, "rev-parse", "--verify", "HEAD"], {
|
|
20765
|
-
encoding: "utf8",
|
|
20766
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
20767
|
-
}).trim();
|
|
20768
|
-
const nested = collectChanges(abs, "HEAD", { mode: "exact" });
|
|
20769
|
-
return `gitlink:${head}:${nested.fingerprint}`;
|
|
20770
|
-
} catch {
|
|
20771
|
-
return `directory:${stat.mode}`;
|
|
20772
|
-
}
|
|
20773
|
-
}
|
|
20774
|
-
if (!stat.isFile()) return `other:${stat.mode}`;
|
|
20775
|
-
const gitMode = stat.mode & 73 ? "100755" : "100644";
|
|
20776
|
-
return `file:${gitMode}:${(0, import_node_crypto5.createHash)("sha256").update((0, import_node_fs6.readFileSync)(abs)).digest("hex")}`;
|
|
20777
|
-
} catch {
|
|
20778
|
-
return "(missing)";
|
|
20779
|
-
}
|
|
20780
|
-
}
|
|
20781
|
-
function digestIndex(repo, rel) {
|
|
20782
|
-
try {
|
|
20783
|
-
const entry = (0, import_node_child_process3.execFileSync)("git", ["ls-files", "--stage", "-z", "--", rel], {
|
|
20784
|
-
cwd: repo,
|
|
20785
|
-
encoding: "utf8",
|
|
20786
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
20787
|
-
});
|
|
20788
|
-
return entry || "(missing-index)";
|
|
20789
|
-
} catch (error) {
|
|
20790
|
-
throw new GitDiffError("diff-failed", `cannot fingerprint Git index entry ${rel}: ${errorText(error)}`);
|
|
20791
|
-
}
|
|
20792
|
-
}
|
|
20793
|
-
function fingerprint(repo, resolvedBase, entries) {
|
|
20794
|
-
const hash = (0, import_node_crypto5.createHash)("sha256");
|
|
20795
|
-
hash.update("harness-kit/change-fingerprint/v1\0");
|
|
20796
|
-
hash.update(resolvedBase ?? EMPTY_TREE_BASE);
|
|
20797
|
-
for (const entry of entries) {
|
|
20798
|
-
hash.update("\0");
|
|
20799
|
-
hash.update(entry.layer);
|
|
20800
|
-
hash.update("\0");
|
|
20801
|
-
hash.update(entry.status);
|
|
20802
|
-
hash.update("\0");
|
|
20803
|
-
hash.update(entry.path);
|
|
20804
|
-
hash.update("\0");
|
|
20805
|
-
hash.update(entry.layer === "index" ? digestIndex(repo, entry.path) : digestPath(repo, entry.path));
|
|
20806
|
-
}
|
|
20807
|
-
return hash.digest("hex");
|
|
20808
|
-
}
|
|
20809
|
-
function collectChanges(repoInput, base = "HEAD", opts = {}) {
|
|
20810
|
-
const target = canonicalPath(repoInput);
|
|
20811
|
-
const root = canonicalPath(gitRoot(target));
|
|
20812
|
-
const prefix = targetPrefix(root, target);
|
|
20813
|
-
const head = tryCommit(root, "HEAD");
|
|
20814
|
-
let baseCommit;
|
|
20815
|
-
if (base === EMPTY_TREE_BASE) {
|
|
20816
|
-
baseCommit = null;
|
|
20817
|
-
} else {
|
|
20818
|
-
baseCommit = tryCommit(root, base);
|
|
20819
|
-
if (!baseCommit && base === "HEAD" && !head) baseCommit = null;
|
|
20820
|
-
else if (!baseCommit) throw new GitDiffError("invalid-base", `invalid base ref: ${base}`);
|
|
20821
|
-
}
|
|
20822
|
-
let resolvedBase = baseCommit;
|
|
20823
|
-
if ((opts.mode ?? "merge-base") === "merge-base" && baseCommit && head) {
|
|
20824
|
-
try {
|
|
20825
|
-
resolvedBase = git(root, ["merge-base", baseCommit, head]).trim();
|
|
20826
|
-
} catch (error) {
|
|
20827
|
-
throw new GitDiffError("invalid-base", `invalid base ref or no merge base: ${base} (${error.message})`);
|
|
20828
|
-
}
|
|
21107
|
+
"harness-kit verify --repo .",
|
|
21108
|
+
"harness-kit evidence --repo . --json"
|
|
21109
|
+
],
|
|
21110
|
+
completion: "Evidence is no longer stale and reports valid: true."
|
|
21111
|
+
}];
|
|
20829
21112
|
}
|
|
20830
|
-
|
|
20831
|
-
|
|
20832
|
-
|
|
20833
|
-
|
|
20834
|
-
|
|
21113
|
+
if (!evidence.runChecksValid) {
|
|
21114
|
+
return [{
|
|
21115
|
+
id: "complete-run-checks",
|
|
21116
|
+
priority: "required",
|
|
21117
|
+
owner: "agent",
|
|
21118
|
+
when: "before-finish",
|
|
21119
|
+
title: "Complete the impact-driven checks",
|
|
21120
|
+
reason: "The selected checks did not produce valid evidence for the current code.",
|
|
21121
|
+
commands: ["harness-kit run-checks --repo . --base <task-start-sha>", "harness-kit evidence --repo . --json"],
|
|
21122
|
+
completion: "Evidence reports runChecksValid: true for the current code fingerprint."
|
|
21123
|
+
}];
|
|
20835
21124
|
}
|
|
20836
|
-
|
|
20837
|
-
|
|
20838
|
-
|
|
21125
|
+
if (!evidence.verifyPassed || !evidence.valid) {
|
|
21126
|
+
return [{
|
|
21127
|
+
id: "complete-verify",
|
|
21128
|
+
priority: "required",
|
|
21129
|
+
owner: "agent",
|
|
21130
|
+
when: "before-finish",
|
|
21131
|
+
title: "Complete repository verification",
|
|
21132
|
+
reason: "Change checks passed, but matching verify evidence is missing or failed.",
|
|
21133
|
+
commands: ["harness-kit verify --repo .", "harness-kit evidence --repo . --json"],
|
|
21134
|
+
completion: "Evidence reports valid: true for the current code fingerprint."
|
|
21135
|
+
}];
|
|
20839
21136
|
}
|
|
20840
|
-
|
|
20841
|
-
|
|
20842
|
-
|
|
21137
|
+
return [];
|
|
21138
|
+
}
|
|
21139
|
+
function buildHarnessGuidance(input) {
|
|
21140
|
+
const gapDetails = input.manifest ? declaredVerificationGaps(input.manifest) : [];
|
|
21141
|
+
const nextActions = [
|
|
21142
|
+
...input.evidence ? evidenceActions(input.evidence) : [],
|
|
21143
|
+
...input.hooks ? hookActions(input.hooks) : []
|
|
21144
|
+
];
|
|
21145
|
+
const improvement = automationAction(gapDetails);
|
|
21146
|
+
if (improvement) nextActions.push(improvement);
|
|
20843
21147
|
return {
|
|
20844
|
-
|
|
20845
|
-
|
|
20846
|
-
|
|
20847
|
-
|
|
20848
|
-
|
|
20849
|
-
|
|
21148
|
+
gapDetails,
|
|
21149
|
+
gapSummary: {
|
|
21150
|
+
total: gapDetails.length,
|
|
21151
|
+
recommended: gapDetails.filter((item) => item.classification === "recommended").length,
|
|
21152
|
+
informational: gapDetails.filter((item) => item.classification === "informational").length
|
|
21153
|
+
},
|
|
21154
|
+
nextActions
|
|
20850
21155
|
};
|
|
20851
21156
|
}
|
|
20852
21157
|
|
|
21158
|
+
// src/hook-status.ts
|
|
21159
|
+
var import_node_fs10 = require("node:fs");
|
|
21160
|
+
var import_node_path10 = require("node:path");
|
|
21161
|
+
|
|
20853
21162
|
// src/codex-linked-hooks.ts
|
|
21163
|
+
var import_node_child_process4 = require("node:child_process");
|
|
21164
|
+
var import_node_fs7 = require("node:fs");
|
|
21165
|
+
var import_node_os = require("node:os");
|
|
21166
|
+
var import_node_path7 = require("node:path");
|
|
20854
21167
|
var CODEX_LINKED_PROTOCOL = "ai-harness/codex-linked-dispatch/v1";
|
|
20855
21168
|
var DISPATCH_ID = "codex-linked-dispatch-v1";
|
|
20856
21169
|
var DISPATCHER_REL = `harness-kit/${DISPATCH_ID}.cjs`;
|
|
@@ -21223,21 +21536,324 @@ function inspectCodexLinkedHooks(repoInput) {
|
|
|
21223
21536
|
issues.push(error.message);
|
|
21224
21537
|
}
|
|
21225
21538
|
}
|
|
21226
|
-
const runnerFile = safeContent(repoRoot, RUNNER_REL, issues);
|
|
21227
|
-
if (runnerFile.content === null) issues.push("Codex linked project runner is missing");
|
|
21228
|
-
else {
|
|
21229
|
-
if (sha256(runnerFile.content) !== registration.runner.sha256) issues.push("Codex linked project runner hash changed");
|
|
21230
|
-
if (runnerFile.mode !== registration.runner.mode || ((runnerFile.mode ?? 0) & 64) === 0) {
|
|
21231
|
-
issues.push("Codex linked project runner mode changed");
|
|
21539
|
+
const runnerFile = safeContent(repoRoot, RUNNER_REL, issues);
|
|
21540
|
+
if (runnerFile.content === null) issues.push("Codex linked project runner is missing");
|
|
21541
|
+
else {
|
|
21542
|
+
if (sha256(runnerFile.content) !== registration.runner.sha256) issues.push("Codex linked project runner hash changed");
|
|
21543
|
+
if (runnerFile.mode !== registration.runner.mode || ((runnerFile.mode ?? 0) & 64) === 0) {
|
|
21544
|
+
issues.push("Codex linked project runner mode changed");
|
|
21545
|
+
}
|
|
21546
|
+
}
|
|
21547
|
+
return { linked: true, configured: issues.length === 0, issues, artifacts };
|
|
21548
|
+
}
|
|
21549
|
+
|
|
21550
|
+
// src/validation-state.ts
|
|
21551
|
+
var import_node_crypto6 = require("node:crypto");
|
|
21552
|
+
var import_node_fs8 = require("node:fs");
|
|
21553
|
+
var import_node_path8 = require("node:path");
|
|
21554
|
+
|
|
21555
|
+
// src/planner.ts
|
|
21556
|
+
var import_picomatch2 = __toESM(require_picomatch2(), 1);
|
|
21557
|
+
function validationPlanFingerprint(plan) {
|
|
21558
|
+
return sha256(
|
|
21559
|
+
JSON.stringify({
|
|
21560
|
+
version: 1,
|
|
21561
|
+
profile: plan.profile,
|
|
21562
|
+
changed: plan.changed,
|
|
21563
|
+
affected: plan.affected,
|
|
21564
|
+
gates: plan.gates,
|
|
21565
|
+
checks: plan.checks,
|
|
21566
|
+
gaps: plan.gaps,
|
|
21567
|
+
notes: plan.notes
|
|
21568
|
+
})
|
|
21569
|
+
);
|
|
21570
|
+
}
|
|
21571
|
+
function matchesAny(file, globs) {
|
|
21572
|
+
if (!globs || globs.length === 0) return false;
|
|
21573
|
+
return (0, import_picomatch2.default)(globs, { dot: true })(file);
|
|
21574
|
+
}
|
|
21575
|
+
function suggestionFor(mod, base) {
|
|
21576
|
+
return mod.remediation ? mod.remediation : base;
|
|
21577
|
+
}
|
|
21578
|
+
function planChecks(m, input, opts = {}) {
|
|
21579
|
+
const changeEntries = input.map((change) => typeof change === "string" ? { path: change, status: "M" } : change);
|
|
21580
|
+
const changed = [...new Set(changeEntries.map((change) => change.path))];
|
|
21581
|
+
const finalStatus = /* @__PURE__ */ new Map();
|
|
21582
|
+
const layerPriority = { index: 1, worktree: 2, untracked: 3 };
|
|
21583
|
+
for (const change of changeEntries) {
|
|
21584
|
+
const priority = change.layer ? layerPriority[change.layer] : 4;
|
|
21585
|
+
const previous = finalStatus.get(change.path);
|
|
21586
|
+
if (!previous || priority >= previous.priority) finalStatus.set(change.path, { priority, status: change.status });
|
|
21587
|
+
}
|
|
21588
|
+
const modules = m.modules ?? [];
|
|
21589
|
+
const compiled = modules.map((mod) => ({
|
|
21590
|
+
mod,
|
|
21591
|
+
owns: mod.owns?.length ? (0, import_picomatch2.default)(mod.owns, { dot: true }) : null,
|
|
21592
|
+
tests: mod.tests?.length ? (0, import_picomatch2.default)(mod.tests, { dot: true }) : null
|
|
21593
|
+
}));
|
|
21594
|
+
const modulesWithOwns = compiled.filter((item) => item.owns !== null);
|
|
21595
|
+
const gateDefs = m.validation?.gates ?? {};
|
|
21596
|
+
const compiledGates = Object.entries(gateDefs).map(([id, gate]) => ({
|
|
21597
|
+
id,
|
|
21598
|
+
gate,
|
|
21599
|
+
acceptance: gate.acceptance?.tests?.length ? (0, import_picomatch2.default)(gate.acceptance.tests, { dot: true }) : null,
|
|
21600
|
+
overlapsModuleBoundary: (0, import_picomatch2.default)(
|
|
21601
|
+
modules.filter((mod) => mod.gates?.includes(id)).flatMap((mod) => [...mod.owns ?? [], ...mod.tests ?? []]),
|
|
21602
|
+
{ dot: true }
|
|
21603
|
+
)
|
|
21604
|
+
}));
|
|
21605
|
+
const gaps = [];
|
|
21606
|
+
const notes = [];
|
|
21607
|
+
const affectedModules = [];
|
|
21608
|
+
const productionAffected = /* @__PURE__ */ new Set();
|
|
21609
|
+
const affectedGateSet = /* @__PURE__ */ new Set();
|
|
21610
|
+
const productionAffectedGates = /* @__PURE__ */ new Set();
|
|
21611
|
+
const matchedFiles = /* @__PURE__ */ new Set();
|
|
21612
|
+
for (const item of compiled) {
|
|
21613
|
+
const { mod } = item;
|
|
21614
|
+
let productionHit = false;
|
|
21615
|
+
let testHit = false;
|
|
21616
|
+
for (const f of changed) {
|
|
21617
|
+
if (item.owns?.(f)) {
|
|
21618
|
+
productionHit = true;
|
|
21619
|
+
matchedFiles.add(f);
|
|
21620
|
+
}
|
|
21621
|
+
if (item.tests?.(f)) {
|
|
21622
|
+
testHit = true;
|
|
21623
|
+
matchedFiles.add(f);
|
|
21624
|
+
}
|
|
21625
|
+
}
|
|
21626
|
+
if (productionHit || testHit) affectedModules.push(mod);
|
|
21627
|
+
if (productionHit) productionAffected.add(mod.name);
|
|
21628
|
+
}
|
|
21629
|
+
for (const mod of affectedModules) {
|
|
21630
|
+
for (const gate of mod.gates ?? []) affectedGateSet.add(gate);
|
|
21631
|
+
if (productionAffected.has(mod.name)) for (const gate of mod.gates ?? []) productionAffectedGates.add(gate);
|
|
21632
|
+
}
|
|
21633
|
+
for (const item of compiledGates) {
|
|
21634
|
+
if (!item.acceptance) continue;
|
|
21635
|
+
for (const file of changed) {
|
|
21636
|
+
if (!item.acceptance(file)) continue;
|
|
21637
|
+
matchedFiles.add(file);
|
|
21638
|
+
affectedGateSet.add(item.id);
|
|
21639
|
+
}
|
|
21640
|
+
}
|
|
21641
|
+
const affectedGates = compiledGates.filter((item) => affectedGateSet.has(item.id));
|
|
21642
|
+
const unmapped = changed.filter((f) => !matchedFiles.has(f));
|
|
21643
|
+
const requiredCoverage = m.validation?.required_coverage?.length ? (0, import_picomatch2.default)(m.validation.required_coverage, { dot: true }) : null;
|
|
21644
|
+
const requiredUnmapped = requiredCoverage ? unmapped.filter((file) => requiredCoverage(file)) : [];
|
|
21645
|
+
const advisoryUnmapped = unmapped.filter((file) => !requiredUnmapped.includes(file));
|
|
21646
|
+
const checks = [];
|
|
21647
|
+
const seen = /* @__PURE__ */ new Set();
|
|
21648
|
+
const add = (id, reason) => {
|
|
21649
|
+
if (seen.has(id)) return;
|
|
21650
|
+
seen.add(id);
|
|
21651
|
+
checks.push({ id, reason });
|
|
21652
|
+
};
|
|
21653
|
+
const profile = opts.profile ?? null;
|
|
21654
|
+
if (profile) {
|
|
21655
|
+
const set = m.validation?.checksets?.[profile];
|
|
21656
|
+
if (!set) {
|
|
21657
|
+
gaps.push({
|
|
21658
|
+
kind: "unknown-profile",
|
|
21659
|
+
where: profile,
|
|
21660
|
+
why: `validation.checksets \u6CA1\u6709\u58F0\u660E profile: ${profile}`,
|
|
21661
|
+
suggestion: "\u68C0\u67E5 --profile \u62FC\u5199\uFF0C\u6216\u5148\u5728 validation.checksets \u4E2D\u58F0\u660E\u5B83",
|
|
21662
|
+
severity: "blocking"
|
|
21663
|
+
});
|
|
21664
|
+
} else {
|
|
21665
|
+
for (const c of set.checks ?? []) add(c, `profile:${profile}`);
|
|
21666
|
+
}
|
|
21667
|
+
} else {
|
|
21668
|
+
for (const mod of affectedModules) for (const c of mod.checks ?? []) add(c, `module:${mod.name}`);
|
|
21669
|
+
if (affectedModules.length === 0)
|
|
21670
|
+
for (const c of m.validation?.defaults?.no_match ?? []) add(c, "no_match");
|
|
21671
|
+
}
|
|
21672
|
+
for (const item of affectedGates) for (const check of item.gate.checks ?? []) add(check, `gate:${item.id}`);
|
|
21673
|
+
for (const c of m.validation?.defaults?.always ?? []) add(c, "always");
|
|
21674
|
+
if (modulesWithOwns.length === 0) {
|
|
21675
|
+
gaps.push({
|
|
21676
|
+
kind: "no-impact-map",
|
|
21677
|
+
where: "modules",
|
|
21678
|
+
why: "manifest \u6CA1\u6709\u4EFB\u4F55\u58F0\u660E owns \u7684\u6A21\u5757\uFF0C\u65E0\u6CD5\u6309\u5F71\u54CD\u9762\u9009\u6D4B",
|
|
21679
|
+
suggestion: "\u5728 .agents/manifest.yaml \u7684 modules[] \u8865 owns/tests/checks\uFF0C\u8BA9\u6539\u52A8\u80FD\u6620\u5C04\u5230\u9A8C\u8BC1",
|
|
21680
|
+
severity: "advisory"
|
|
21681
|
+
});
|
|
21682
|
+
}
|
|
21683
|
+
for (const mod of affectedModules) {
|
|
21684
|
+
if (!productionAffected.has(mod.name)) continue;
|
|
21685
|
+
const testTouch = mod.test_touch ?? m.validation?.policies?.test_touch_default ?? "advisory";
|
|
21686
|
+
if (!(mod.tests?.length ?? 0)) {
|
|
21687
|
+
if (testTouch === "off") continue;
|
|
21688
|
+
gaps.push({
|
|
21689
|
+
kind: "module-without-tests",
|
|
21690
|
+
where: mod.name,
|
|
21691
|
+
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`,
|
|
21692
|
+
suggestion: suggestionFor(
|
|
21693
|
+
mod,
|
|
21694
|
+
`\u7ED9\u6A21\u5757 ${mod.name} \u58F0\u660E tests glob \u5E76\u8865\u6D4B\u8BD5${mod.playbook ? `\uFF1B\u53C2\u8003 playbook ${mod.playbook}` : ""}`
|
|
21695
|
+
),
|
|
21696
|
+
severity: testTouch === "required" ? "blocking" : "advisory"
|
|
21697
|
+
});
|
|
21698
|
+
continue;
|
|
21699
|
+
}
|
|
21700
|
+
const testTouched = changed.some((path) => finalStatus.get(path)?.status !== "D" && matchesAny(path, mod.tests));
|
|
21701
|
+
if (!testTouched && testTouch !== "off") {
|
|
21702
|
+
gaps.push({
|
|
21703
|
+
kind: "missing-test-touch",
|
|
21704
|
+
where: mod.name,
|
|
21705
|
+
why: `\u6539\u4E86 ${mod.name} \u7684\u751F\u4EA7\u4EE3\u7801\uFF0C\u4F46\u5B83\u7684\u6D4B\u8BD5(${mod.tests.join(", ")})\u4E00\u4E2A\u90FD\u6CA1\u52A8`,
|
|
21706
|
+
suggestion: suggestionFor(
|
|
21707
|
+
mod,
|
|
21708
|
+
`\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>`
|
|
21709
|
+
),
|
|
21710
|
+
severity: testTouch === "required" ? "blocking" : "advisory"
|
|
21711
|
+
});
|
|
21712
|
+
}
|
|
21713
|
+
}
|
|
21714
|
+
for (const item of affectedGates) {
|
|
21715
|
+
if (!productionAffectedGates.has(item.id) || !item.gate.acceptance) continue;
|
|
21716
|
+
const policy = item.gate.acceptance.test_touch;
|
|
21717
|
+
if (policy === "off") continue;
|
|
21718
|
+
const testTouched = changed.some(
|
|
21719
|
+
(path) => finalStatus.get(path)?.status !== "D" && matchesAny(path, item.gate.acceptance.tests) && !item.overlapsModuleBoundary(path)
|
|
21720
|
+
);
|
|
21721
|
+
if (!testTouched) {
|
|
21722
|
+
gaps.push({
|
|
21723
|
+
kind: "missing-test-touch",
|
|
21724
|
+
where: `gate:${item.id}`,
|
|
21725
|
+
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`,
|
|
21726
|
+
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>`,
|
|
21727
|
+
severity: policy === "required" ? "blocking" : "advisory"
|
|
21728
|
+
});
|
|
21729
|
+
}
|
|
21730
|
+
}
|
|
21731
|
+
if (requiredUnmapped.length) {
|
|
21732
|
+
const shown = requiredUnmapped.slice(0, 8).join(", ");
|
|
21733
|
+
gaps.push({
|
|
21734
|
+
kind: "unmapped-required-file",
|
|
21735
|
+
where: shown + (requiredUnmapped.length > 8 ? ` \u2026(+${requiredUnmapped.length - 8})` : ""),
|
|
21736
|
+
why: "\u8FD9\u4E9B\u6539\u52A8\u4F4D\u4E8E validation.required_coverage\uFF0C\u4F46\u4E0D\u5C5E\u4E8E\u4EFB\u4F55\u6A21\u5757\u7684 owns/tests",
|
|
21737
|
+
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",
|
|
21738
|
+
severity: "blocking"
|
|
21739
|
+
});
|
|
21740
|
+
}
|
|
21741
|
+
if (advisoryUnmapped.length) {
|
|
21742
|
+
const shown = advisoryUnmapped.slice(0, 8).join(", ");
|
|
21743
|
+
gaps.push({
|
|
21744
|
+
kind: "unmapped-file",
|
|
21745
|
+
where: shown + (advisoryUnmapped.length > 8 ? ` \u2026(+${advisoryUnmapped.length - 8})` : ""),
|
|
21746
|
+
why: "\u8FD9\u4E9B\u6539\u52A8\u6587\u4EF6\u4E0D\u5C5E\u4E8E\u4EFB\u4F55\u6A21\u5757\u7684 owns\uFF0C\u672A\u7EB3\u5165\u5F71\u54CD\u9762",
|
|
21747
|
+
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",
|
|
21748
|
+
severity: "advisory"
|
|
21749
|
+
});
|
|
21750
|
+
}
|
|
21751
|
+
if (changed.length > 0 && checks.length === 0 && !gaps.some((gap2) => gap2.kind === "unknown-profile")) {
|
|
21752
|
+
gaps.push({
|
|
21753
|
+
kind: "no-checks-selected",
|
|
21754
|
+
where: "validation",
|
|
21755
|
+
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",
|
|
21756
|
+
suggestion: "\u7ED9\u547D\u4E2D\u7684\u6A21\u5757\u58F0\u660E checks\uFF0C\u6216\u914D\u7F6E validation.defaults.no_match / profile checkset",
|
|
21757
|
+
severity: "blocking"
|
|
21758
|
+
});
|
|
21759
|
+
}
|
|
21760
|
+
if (affectedModules.length > 0) {
|
|
21761
|
+
notes.push({
|
|
21762
|
+
kind: "propagation-note",
|
|
21763
|
+
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",
|
|
21764
|
+
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"
|
|
21765
|
+
});
|
|
21766
|
+
}
|
|
21767
|
+
return {
|
|
21768
|
+
changed,
|
|
21769
|
+
affected: affectedModules.map((x) => x.name),
|
|
21770
|
+
gates: affectedGates.map((item) => item.id),
|
|
21771
|
+
checks,
|
|
21772
|
+
gaps,
|
|
21773
|
+
notes,
|
|
21774
|
+
profile
|
|
21775
|
+
};
|
|
21776
|
+
}
|
|
21777
|
+
|
|
21778
|
+
// src/validation-gates.ts
|
|
21779
|
+
var import_fast_glob = __toESM(require_out4(), 1);
|
|
21780
|
+
var import_picomatch3 = __toESM(require_picomatch2(), 1);
|
|
21781
|
+
var SCAN_OPTIONS = {
|
|
21782
|
+
onlyFiles: true,
|
|
21783
|
+
dot: true,
|
|
21784
|
+
followSymbolicLinks: false,
|
|
21785
|
+
ignore: ["**/node_modules/**", "**/.git/**", "**/dist/**"]
|
|
21786
|
+
};
|
|
21787
|
+
function matchingFiles(repoFiles, globs) {
|
|
21788
|
+
if (!globs.length) return [];
|
|
21789
|
+
const matches = (0, import_picomatch3.default)(globs, { dot: true });
|
|
21790
|
+
return repoFiles.filter((file) => matches(file));
|
|
21791
|
+
}
|
|
21792
|
+
function issueLevel(policy) {
|
|
21793
|
+
return policy === "required" ? "error" : "warn";
|
|
21794
|
+
}
|
|
21795
|
+
function inspectValidationGateHealth(repo, manifest) {
|
|
21796
|
+
const issues = [];
|
|
21797
|
+
const repoFiles = import_fast_glob.default.sync("**/*", { cwd: repo, ...SCAN_OPTIONS });
|
|
21798
|
+
for (const [id, gate] of Object.entries(manifest.validation?.gates ?? {})) {
|
|
21799
|
+
const acceptance = gate.acceptance;
|
|
21800
|
+
const acceptanceFiles = /* @__PURE__ */ new Set();
|
|
21801
|
+
if (acceptance) {
|
|
21802
|
+
const level = issueLevel(acceptance.test_touch);
|
|
21803
|
+
for (const glob of acceptance.tests) {
|
|
21804
|
+
const matches = matchingFiles(repoFiles, [glob]);
|
|
21805
|
+
for (const file of matches) acceptanceFiles.add(file);
|
|
21806
|
+
if (!matches.length) {
|
|
21807
|
+
issues.push({
|
|
21808
|
+
level,
|
|
21809
|
+
gate: id,
|
|
21810
|
+
message: `acceptance glob matches 0 files: ${glob}${level === "error" ? " \u2014 required acceptance coverage cannot be vacuous" : ""}`
|
|
21811
|
+
});
|
|
21812
|
+
}
|
|
21813
|
+
}
|
|
21814
|
+
}
|
|
21815
|
+
const modules = (manifest.modules ?? []).filter((module2) => module2.gates?.includes(id));
|
|
21816
|
+
for (const module2 of modules) {
|
|
21817
|
+
const ownedFiles = new Set(matchingFiles(repoFiles, module2.owns ?? []));
|
|
21818
|
+
if (ownedFiles.size === 0) {
|
|
21819
|
+
issues.push({
|
|
21820
|
+
level: "error",
|
|
21821
|
+
gate: id,
|
|
21822
|
+
message: `module ${module2.name} owns matches 0 files \u2014 production changes cannot activate this gate`
|
|
21823
|
+
});
|
|
21824
|
+
}
|
|
21825
|
+
if (!acceptance) continue;
|
|
21826
|
+
const unitFiles = new Set(matchingFiles(repoFiles, module2.tests ?? []));
|
|
21827
|
+
const overlap = [...acceptanceFiles].filter((file) => ownedFiles.has(file) || unitFiles.has(file));
|
|
21828
|
+
if (overlap.length) {
|
|
21829
|
+
const shown = overlap.slice(0, 5).join(", ");
|
|
21830
|
+
issues.push({
|
|
21831
|
+
level: issueLevel(acceptance.test_touch),
|
|
21832
|
+
gate: id,
|
|
21833
|
+
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`
|
|
21834
|
+
});
|
|
21835
|
+
}
|
|
21232
21836
|
}
|
|
21233
21837
|
}
|
|
21234
|
-
return
|
|
21838
|
+
return issues;
|
|
21839
|
+
}
|
|
21840
|
+
|
|
21841
|
+
// src/validation-plan.ts
|
|
21842
|
+
function planRepositoryChecks(repo, manifest, changes, options = {}) {
|
|
21843
|
+
const plan = planChecks(manifest, changes, options);
|
|
21844
|
+
for (const issue of inspectValidationGateHealth(repo, manifest)) {
|
|
21845
|
+
plan.gaps.push({
|
|
21846
|
+
kind: "validation-gate-invalid",
|
|
21847
|
+
where: `gate:${issue.gate}`,
|
|
21848
|
+
why: issue.message,
|
|
21849
|
+
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",
|
|
21850
|
+
severity: issue.level === "error" ? "blocking" : "advisory"
|
|
21851
|
+
});
|
|
21852
|
+
}
|
|
21853
|
+
return plan;
|
|
21235
21854
|
}
|
|
21236
21855
|
|
|
21237
21856
|
// src/validation-state.ts
|
|
21238
|
-
var import_node_crypto6 = require("node:crypto");
|
|
21239
|
-
var import_node_fs8 = require("node:fs");
|
|
21240
|
-
var import_node_path8 = require("node:path");
|
|
21241
21857
|
var TOKEN_RX = /^[a-f0-9]{64}$/;
|
|
21242
21858
|
var MAX_SESSIONS = 100;
|
|
21243
21859
|
var MAX_AGE_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
@@ -21410,6 +22026,26 @@ function writeValidationSession(repo, session) {
|
|
|
21410
22026
|
function recordValidationEvidence(repo, session, evidence) {
|
|
21411
22027
|
writeValidationSession(repo, { ...session, lastEvidence: evidence });
|
|
21412
22028
|
}
|
|
22029
|
+
function inspectValidationEvidenceFreshness(repo, evidence) {
|
|
22030
|
+
let currentFingerprint = "";
|
|
22031
|
+
let currentPlanFingerprint = "";
|
|
22032
|
+
let error = "";
|
|
22033
|
+
try {
|
|
22034
|
+
const current = collectChanges(repo, evidence.resolvedBase ?? EMPTY_TREE_BASE, { mode: "exact" });
|
|
22035
|
+
currentFingerprint = current.fingerprint;
|
|
22036
|
+
const manifest = loadManifest(repo);
|
|
22037
|
+
const manifestErrors = validateManifest(manifest).filter((issue) => issue.level === "error");
|
|
22038
|
+
if (manifestErrors.length) throw new Error(`manifest invalid: ${manifestErrors.map((issue) => issue.msg).join("; ")}`);
|
|
22039
|
+
const plan = planRepositoryChecks(repo, manifest, current.entries, { profile: evidence.profile ?? void 0 });
|
|
22040
|
+
currentPlanFingerprint = validationPlanFingerprint(plan);
|
|
22041
|
+
} catch (cause) {
|
|
22042
|
+
error = cause.message;
|
|
22043
|
+
}
|
|
22044
|
+
const fingerprintStale = !currentFingerprint || currentFingerprint !== evidence.fingerprint;
|
|
22045
|
+
const planStale = !currentPlanFingerprint || !evidence.planFingerprint || currentPlanFingerprint !== evidence.planFingerprint;
|
|
22046
|
+
if (!error && !evidence.planFingerprint) error = "validation evidence predates plan fingerprint binding; rerun run-checks";
|
|
22047
|
+
return { currentFingerprint, currentPlanFingerprint, fingerprintStale, planStale, stale: fingerprintStale || planStale, error };
|
|
22048
|
+
}
|
|
21413
22049
|
function clearValidationEvidence(repo, session) {
|
|
21414
22050
|
writeValidationSession(repo, { ...session, lastEvidence: void 0 });
|
|
21415
22051
|
}
|
|
@@ -21422,11 +22058,12 @@ function recordWaiver(repo, session, waiver) {
|
|
|
21422
22058
|
writeValidationSession(repo, next);
|
|
21423
22059
|
return next;
|
|
21424
22060
|
}
|
|
21425
|
-
function markLatestVerifyResult(repo, token, passed, expectedFingerprint) {
|
|
22061
|
+
function markLatestVerifyResult(repo, token, passed, expectedFingerprint, expectedPlanFingerprint) {
|
|
21426
22062
|
const session = readValidationSession(repo, token);
|
|
21427
22063
|
if (!session?.lastEvidence) return false;
|
|
21428
22064
|
const evidence = session.lastEvidence;
|
|
21429
22065
|
if (expectedFingerprint && evidence.fingerprint !== expectedFingerprint) return false;
|
|
22066
|
+
if (!evidence.planFingerprint || expectedPlanFingerprint && evidence.planFingerprint !== expectedPlanFingerprint) return false;
|
|
21430
22067
|
const runChecksStatus = evidence.runChecksStatus ?? evidence.status;
|
|
21431
22068
|
const runChecksOk = runChecksStatus !== "not-verified";
|
|
21432
22069
|
recordValidationEvidence(repo, session, {
|
|
@@ -21449,14 +22086,8 @@ function markManualVerifyResult(repoInput, passed) {
|
|
|
21449
22086
|
const session = readValidationSession(repo, token);
|
|
21450
22087
|
if (!session?.lastEvidence) return "none";
|
|
21451
22088
|
const evidence = session.lastEvidence;
|
|
21452
|
-
|
|
21453
|
-
|
|
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);
|
|
22089
|
+
const matches = !inspectValidationEvidenceFreshness(repo, evidence).stale;
|
|
22090
|
+
const updated = markLatestVerifyResult(repo, token, passed && matches, evidence.fingerprint, evidence.planFingerprint);
|
|
21460
22091
|
return matches && updated ? "matched" : "stale";
|
|
21461
22092
|
}
|
|
21462
22093
|
|
|
@@ -21978,13 +22609,9 @@ function inspectAgentHookStatus(repo) {
|
|
|
21978
22609
|
if (session && session.agent !== "manual" && evidence) {
|
|
21979
22610
|
evidenceAgent = session.agent;
|
|
21980
22611
|
evidenceAt = evidence.createdAt;
|
|
21981
|
-
|
|
21982
|
-
|
|
21983
|
-
|
|
21984
|
-
} catch (error) {
|
|
21985
|
-
issues.push(`cannot refresh lifecycle evidence: ${error.message}`);
|
|
21986
|
-
}
|
|
21987
|
-
const stale = !currentFingerprint || currentFingerprint !== evidence.fingerprint;
|
|
22612
|
+
const freshness = inspectValidationEvidenceFreshness(repo, evidence);
|
|
22613
|
+
if (freshness.error) issues.push(`cannot refresh lifecycle evidence: ${freshness.error}`);
|
|
22614
|
+
const stale = freshness.stale;
|
|
21988
22615
|
const runChecksValid = (evidence.runChecksStatus !== void 0 ? evidence.runChecksStatus !== "not-verified" : evidence.ok && evidence.status !== "not-verified") && !stale;
|
|
21989
22616
|
const valid = runChecksValid && evidence.verifyPassed === true;
|
|
21990
22617
|
if (!valid) {
|
|
@@ -22018,7 +22645,7 @@ function inspectAgentHookStatus(repo) {
|
|
|
22018
22645
|
// src/state.ts
|
|
22019
22646
|
var import_node_fs11 = require("node:fs");
|
|
22020
22647
|
var import_node_path11 = require("node:path");
|
|
22021
|
-
var
|
|
22648
|
+
var import_fast_glob2 = __toESM(require_out4(), 1);
|
|
22022
22649
|
var STATE_REL = ".agents/.harness-state.json";
|
|
22023
22650
|
function inside3(base, target) {
|
|
22024
22651
|
const rel = (0, import_node_path11.relative)(base, target);
|
|
@@ -22040,7 +22667,7 @@ function hashPath(absPath) {
|
|
|
22040
22667
|
}
|
|
22041
22668
|
if (stat.isFile()) return hashFile(absPath) ?? "(missing)";
|
|
22042
22669
|
if (!stat.isDirectory()) return "(missing)";
|
|
22043
|
-
const files =
|
|
22670
|
+
const files = import_fast_glob2.default.sync("**/*", { cwd: absPath, onlyFiles: true, dot: true, followSymbolicLinks: false }).sort();
|
|
22044
22671
|
const entries = files.map((path) => [path, hashFile((0, import_node_path11.join)(absPath, path)) ?? "(missing)"]);
|
|
22045
22672
|
return sha256(JSON.stringify(entries));
|
|
22046
22673
|
}
|
|
@@ -22281,7 +22908,7 @@ function doctorCmd(repo, opts = {}) {
|
|
|
22281
22908
|
for (const inv of m.invariants ?? []) {
|
|
22282
22909
|
if (!inv.enforcement) continue;
|
|
22283
22910
|
const globs = inv.enforcement.path_glob?.length ? inv.enforcement.path_glob : ["**/*"];
|
|
22284
|
-
const n =
|
|
22911
|
+
const n = import_fast_glob3.default.sync(globs, {
|
|
22285
22912
|
cwd: repo,
|
|
22286
22913
|
onlyFiles: true,
|
|
22287
22914
|
dot: false,
|
|
@@ -22292,7 +22919,7 @@ function doctorCmd(repo, opts = {}) {
|
|
|
22292
22919
|
}
|
|
22293
22920
|
for (const mod of m.modules ?? []) {
|
|
22294
22921
|
if (!mod.owns?.length) continue;
|
|
22295
|
-
const n =
|
|
22922
|
+
const n = import_fast_glob3.default.sync(mod.owns, {
|
|
22296
22923
|
cwd: repo,
|
|
22297
22924
|
onlyFiles: true,
|
|
22298
22925
|
dot: true,
|
|
@@ -22302,7 +22929,7 @@ function doctorCmd(repo, opts = {}) {
|
|
|
22302
22929
|
warn(`module ${mod.name}: owns glob matches 0 files \u2014 impact planner can never select it (stale owns for this layout?)`);
|
|
22303
22930
|
}
|
|
22304
22931
|
for (const glob of m.validation?.required_coverage ?? []) {
|
|
22305
|
-
const n =
|
|
22932
|
+
const n = import_fast_glob3.default.sync(glob, {
|
|
22306
22933
|
cwd: repo,
|
|
22307
22934
|
onlyFiles: true,
|
|
22308
22935
|
dot: true,
|
|
@@ -22311,6 +22938,15 @@ function doctorCmd(repo, opts = {}) {
|
|
|
22311
22938
|
if (n === 0)
|
|
22312
22939
|
warn(`validation.required_coverage glob matches 0 files: ${glob} \u2014 a typo here silently weakens unmapped-file protection`);
|
|
22313
22940
|
}
|
|
22941
|
+
for (const issue of inspectValidationGateHealth(repo, m)) {
|
|
22942
|
+
const message = `validation gate ${issue.gate}: ${issue.message}`;
|
|
22943
|
+
if (issue.level === "error") {
|
|
22944
|
+
err(message);
|
|
22945
|
+
problems++;
|
|
22946
|
+
} else {
|
|
22947
|
+
warn(message);
|
|
22948
|
+
}
|
|
22949
|
+
}
|
|
22314
22950
|
info("\n2) Referenced paths");
|
|
22315
22951
|
const checkPath = (rel, label) => {
|
|
22316
22952
|
if ((0, import_node_fs12.existsSync)((0, import_node_path12.join)(repo, ".agents", rel))) ok(`${label}: ${rel}`);
|
|
@@ -22329,8 +22965,8 @@ function doctorCmd(repo, opts = {}) {
|
|
|
22329
22965
|
} else ok(`${label}: ${rel}`);
|
|
22330
22966
|
};
|
|
22331
22967
|
const checkRepoPointer = (pointer, label) => {
|
|
22332
|
-
if (!
|
|
22333
|
-
const matches =
|
|
22968
|
+
if (!import_fast_glob3.default.isDynamicPattern(pointer)) return checkRepoPath(pointer, label);
|
|
22969
|
+
const matches = import_fast_glob3.default.sync(pointer, {
|
|
22334
22970
|
cwd: repo,
|
|
22335
22971
|
onlyFiles: false,
|
|
22336
22972
|
dot: true,
|
|
@@ -22476,13 +23112,13 @@ function doctorCmd(repo, opts = {}) {
|
|
|
22476
23112
|
var import_node_child_process5 = require("node:child_process");
|
|
22477
23113
|
|
|
22478
23114
|
// src/enforce.ts
|
|
22479
|
-
var
|
|
23115
|
+
var import_fast_glob4 = __toESM(require_out4(), 1);
|
|
22480
23116
|
var import_node_fs13 = require("node:fs");
|
|
22481
23117
|
var import_node_path13 = require("node:path");
|
|
22482
23118
|
var DEFAULT_IGNORE = ["**/node_modules/**", "**/.git/**", "**/dist/**", "**/.agents/map/**"];
|
|
22483
23119
|
function runEnforcement(repo, invId, e) {
|
|
22484
23120
|
const globs = e.path_glob?.length ? e.path_glob : ["**/*"];
|
|
22485
|
-
const files =
|
|
23121
|
+
const files = import_fast_glob4.default.sync(globs, {
|
|
22486
23122
|
cwd: repo,
|
|
22487
23123
|
onlyFiles: true,
|
|
22488
23124
|
dot: false,
|
|
@@ -22648,6 +23284,15 @@ function verifyInternal(repo, opts) {
|
|
|
22648
23284
|
verify: FAILED (${manifestErrors.length} manifest problem(s))`);
|
|
22649
23285
|
return finish(1);
|
|
22650
23286
|
}
|
|
23287
|
+
const gateHealth = inspectValidationGateHealth(repo, manifest);
|
|
23288
|
+
if (gateHealth.length) emit("info", "0) Validation gate coverage");
|
|
23289
|
+
for (const issue of gateHealth) {
|
|
23290
|
+
const message = `validation gate ${issue.gate}: ${issue.message}`;
|
|
23291
|
+
if (issue.level === "error") {
|
|
23292
|
+
failures++;
|
|
23293
|
+
emit("error", message);
|
|
23294
|
+
} else emit("warn", message);
|
|
23295
|
+
}
|
|
22651
23296
|
emit("info", "1) Generated files in sync");
|
|
22652
23297
|
try {
|
|
22653
23298
|
for (const inspection of inspectManagedFiles(repo, renderTargets(manifest))) {
|
|
@@ -22800,7 +23445,7 @@ verify: FAILED (${manifestErrors.length} manifest problem(s))`);
|
|
|
22800
23445
|
emit("warn", `Harness readiness: INCOMPLETE (${requiredActions.length} required action(s) above)`);
|
|
22801
23446
|
return finish(1);
|
|
22802
23447
|
}
|
|
22803
|
-
emit("info", "verify: OK (
|
|
23448
|
+
emit("info", "verify: OK (repository drift, invariants, and contracts passed; validation checks require matching run-checks evidence)");
|
|
22804
23449
|
if (requiredActions.length)
|
|
22805
23450
|
emit("warn", `Harness readiness: INCOMPLETE (${requiredActions.length} required action(s) above)`);
|
|
22806
23451
|
else emit("ok", "Harness readiness: READY");
|
|
@@ -22979,14 +23624,8 @@ function evidenceCmd(repo, opts = {}) {
|
|
|
22979
23624
|
evidence: session.lastEvidence
|
|
22980
23625
|
};
|
|
22981
23626
|
const evidence = session.lastEvidence;
|
|
22982
|
-
|
|
22983
|
-
|
|
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;
|
|
23627
|
+
const freshness = inspectValidationEvidenceFreshness(repo, evidence);
|
|
23628
|
+
const { currentFingerprint, currentPlanFingerprint, stale } = freshness;
|
|
22990
23629
|
const runChecksValid = (evidence.runChecksStatus !== void 0 ? evidence.runChecksStatus !== "not-verified" : evidence.ok && evidence.status !== "not-verified") && !stale;
|
|
22991
23630
|
const valid = runChecksValid && evidence.verifyPassed === true;
|
|
22992
23631
|
const hookConfigurationCurrent = session.agent !== "manual" && !!session.hookConfigFingerprint && agentHookConfigurationFingerprint(repo, session.agent) === session.hookConfigFingerprint;
|
|
@@ -23003,7 +23642,10 @@ function evidenceCmd(repo, opts = {}) {
|
|
|
23003
23642
|
hookConfigurationCurrent,
|
|
23004
23643
|
stale,
|
|
23005
23644
|
currentFingerprint,
|
|
23006
|
-
|
|
23645
|
+
currentPlanFingerprint,
|
|
23646
|
+
fingerprintStale: freshness.fingerprintStale,
|
|
23647
|
+
planStale: freshness.planStale,
|
|
23648
|
+
refreshError: freshness.error,
|
|
23007
23649
|
hooks,
|
|
23008
23650
|
nextActions: guidance.nextActions
|
|
23009
23651
|
};
|
|
@@ -23023,8 +23665,9 @@ function evidenceCmd(repo, opts = {}) {
|
|
|
23023
23665
|
info(`dirty at SessionStart: ${session.initialDirty.length ? session.initialDirty.join(", ") : "(none)"}`);
|
|
23024
23666
|
if (evidence.verifyPassed !== void 0) info(`verify: ${evidence.verifyPassed ? "passed" : "failed"}`);
|
|
23025
23667
|
else err("verify: no matching result was recorded");
|
|
23026
|
-
if (
|
|
23668
|
+
if (freshness.error) err(`cannot refresh current validation plan: ${freshness.error}`);
|
|
23027
23669
|
info(`checks: ${evidence.checks.map((check) => `${check.id}:${check.status}`).join(", ") || "(none)"}`);
|
|
23670
|
+
if (evidence.gates?.length) info(`validation gates: ${evidence.gates.join(", ")}`);
|
|
23028
23671
|
if (evidence.waivers.length) {
|
|
23029
23672
|
info("waivers:");
|
|
23030
23673
|
for (const waiver of evidence.waivers) warn(`${waiver.kind}:${waiver.where} \u2014 ${waiver.reason}`);
|
|
@@ -23045,166 +23688,6 @@ var import_node_fs15 = require("node:fs");
|
|
|
23045
23688
|
|
|
23046
23689
|
// src/commands/run-checks.ts
|
|
23047
23690
|
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
23691
|
var CHECK_BUDGET_MS = 7 * 60 * 1e3;
|
|
23209
23692
|
var WAIVABLE_GAP_KINDS = /* @__PURE__ */ new Set([
|
|
23210
23693
|
"missing-test-touch",
|
|
@@ -23230,7 +23713,7 @@ ${r.error.message}` : ""}`;
|
|
|
23230
23713
|
return { ok: code === 0, code, logTail, durationMs: Date.now() - started };
|
|
23231
23714
|
}
|
|
23232
23715
|
function emptyPlan(changed, gaps = []) {
|
|
23233
|
-
return { changed, affected: [], checks: [], gaps, notes: [], profile: null };
|
|
23716
|
+
return { changed, affected: [], gates: [], checks: [], gaps, notes: [], profile: null };
|
|
23234
23717
|
}
|
|
23235
23718
|
function outputJson(report) {
|
|
23236
23719
|
process.stdout.write(JSON.stringify(report, null, 2) + "\n");
|
|
@@ -23243,8 +23726,11 @@ function evidenceOf(report) {
|
|
|
23243
23726
|
requestedBase: report.requestedBase,
|
|
23244
23727
|
resolvedBase: report.resolvedBase,
|
|
23245
23728
|
fingerprint: report.fingerprint,
|
|
23729
|
+
profile: report.profile,
|
|
23730
|
+
planFingerprint: report.planFingerprint,
|
|
23246
23731
|
changed: report.changed,
|
|
23247
23732
|
affected: report.affected,
|
|
23733
|
+
gates: report.gates,
|
|
23248
23734
|
checks: report.checks,
|
|
23249
23735
|
gaps: report.gaps,
|
|
23250
23736
|
notes: report.notes,
|
|
@@ -23255,6 +23741,7 @@ function evidenceOf(report) {
|
|
|
23255
23741
|
}
|
|
23256
23742
|
function reportHuman(report) {
|
|
23257
23743
|
info(`run-checks (base ${report.requestedBase}) \u2014 ${report.changed.length} changed file(s), ${report.checks.length} check(s)`);
|
|
23744
|
+
if (report.gates.length) info(`validation gates: ${report.gates.join(", ")}`);
|
|
23258
23745
|
for (const id of report.passed) ok(id);
|
|
23259
23746
|
for (const skipped of report.skipped) err(`${skipped.id}: NOT RUN \u2014 ${skipped.reason}`);
|
|
23260
23747
|
for (const failure of report.failed) {
|
|
@@ -23302,8 +23789,10 @@ function buildReport(args) {
|
|
|
23302
23789
|
resolvedBase: changes.resolvedBase,
|
|
23303
23790
|
fingerprint: changes.fingerprint,
|
|
23304
23791
|
profile: plan.profile,
|
|
23792
|
+
planFingerprint: validationPlanFingerprint(plan),
|
|
23305
23793
|
changed: changes.files,
|
|
23306
23794
|
affected: plan.affected,
|
|
23795
|
+
gates: plan.gates,
|
|
23307
23796
|
passed,
|
|
23308
23797
|
failed,
|
|
23309
23798
|
skipped,
|
|
@@ -23355,7 +23844,7 @@ function runChecksCmd(repo, opts) {
|
|
|
23355
23844
|
errors.push(...manifestErrors.map((issue) => `manifest-invalid: ${issue.msg}`));
|
|
23356
23845
|
let plan = emptyPlan(changes.files);
|
|
23357
23846
|
if (manifest && !manifestErrors.length && changes.fingerprint) {
|
|
23358
|
-
plan =
|
|
23847
|
+
plan = planRepositoryChecks(repo, manifest, changes.entries, { profile: opts.profile });
|
|
23359
23848
|
} else if (manifestErrors.length) {
|
|
23360
23849
|
plan.gaps.push({
|
|
23361
23850
|
kind: "manifest-invalid",
|
|
@@ -23647,7 +24136,7 @@ function hookEventCmd(repoInput, opts) {
|
|
|
23647
24136
|
const verifyPassed = verify.code === 0 && !finalFingerprintError;
|
|
23648
24137
|
let evidencePersisted = false;
|
|
23649
24138
|
try {
|
|
23650
|
-
evidencePersisted = markLatestVerifyResult(repo, token, verifyPassed, report?.fingerprint);
|
|
24139
|
+
evidencePersisted = markLatestVerifyResult(repo, token, verifyPassed, report?.fingerprint, report?.planFingerprint);
|
|
23651
24140
|
} catch (error) {
|
|
23652
24141
|
return block(opts.agent, opts.event, `harness-kit could not persist the final verify result: ${error.message}`);
|
|
23653
24142
|
}
|
|
@@ -23866,7 +24355,7 @@ function planChecksCmd(repo, opts) {
|
|
|
23866
24355
|
const kind = error instanceof GitDiffError ? error.kind : "diff-failed";
|
|
23867
24356
|
errors.push(`${kind}: ${error.message}`);
|
|
23868
24357
|
}
|
|
23869
|
-
const plan = m && changes && !errors.length ?
|
|
24358
|
+
const plan = m && changes && !errors.length ? planRepositoryChecks(repo, m, changes.entries, { profile: opts.profile }) : null;
|
|
23870
24359
|
if (opts.json) {
|
|
23871
24360
|
process.stdout.write(
|
|
23872
24361
|
JSON.stringify(
|
|
@@ -23875,7 +24364,7 @@ function planChecksCmd(repo, opts) {
|
|
|
23875
24364
|
requestedBase: base,
|
|
23876
24365
|
resolvedBase: changes?.resolvedBase ?? null,
|
|
23877
24366
|
fingerprint: changes?.fingerprint ?? "",
|
|
23878
|
-
...plan ?? { changed: changes?.files ?? [], affected: [], checks: [], gaps: [], notes: [], profile: opts.profile ?? null },
|
|
24367
|
+
...plan ?? { changed: changes?.files ?? [], affected: [], gates: [], checks: [], gaps: [], notes: [], profile: opts.profile ?? null },
|
|
23879
24368
|
errors
|
|
23880
24369
|
},
|
|
23881
24370
|
null,
|
|
@@ -23891,6 +24380,7 @@ function planChecksCmd(repo, opts) {
|
|
|
23891
24380
|
}
|
|
23892
24381
|
info(`plan-checks (base ${base} -> ${changes.resolvedBase ?? "empty tree"}) \u2014 ${changes.files.length} changed file(s)`);
|
|
23893
24382
|
info(plan.affected.length ? `affected modules: ${plan.affected.join(", ")}` : "affected modules: (none)");
|
|
24383
|
+
info(plan.gates.length ? `validation gates: ${plan.gates.join(", ")}` : "validation gates: (none)");
|
|
23894
24384
|
info("\nchecks to run:");
|
|
23895
24385
|
if (!plan.checks.length) info(" (none)");
|
|
23896
24386
|
for (const c of plan.checks) ok(`${c.id} [${c.reason}]`);
|
|
@@ -23964,6 +24454,99 @@ function recordAdoptionAuditCmd(repo, opts) {
|
|
|
23964
24454
|
return 0;
|
|
23965
24455
|
}
|
|
23966
24456
|
|
|
24457
|
+
// src/commands/upgrade.ts
|
|
24458
|
+
var import_node_util = require("node:util");
|
|
24459
|
+
function captureOutput(run) {
|
|
24460
|
+
const chunks = [];
|
|
24461
|
+
const originalLog = console.log;
|
|
24462
|
+
const originalWrite = process.stdout.write;
|
|
24463
|
+
console.log = (...args) => {
|
|
24464
|
+
chunks.push(`${(0, import_node_util.format)(...args)}
|
|
24465
|
+
`);
|
|
24466
|
+
};
|
|
24467
|
+
process.stdout.write = ((chunk) => {
|
|
24468
|
+
chunks.push(typeof chunk === "string" ? chunk : Buffer.from(chunk).toString("utf8"));
|
|
24469
|
+
return true;
|
|
24470
|
+
});
|
|
24471
|
+
try {
|
|
24472
|
+
return { exitCode: run(), output: chunks.join("") };
|
|
24473
|
+
} catch (error) {
|
|
24474
|
+
return { exitCode: 1, output: chunks.join(""), error: error.message };
|
|
24475
|
+
} finally {
|
|
24476
|
+
console.log = originalLog;
|
|
24477
|
+
process.stdout.write = originalWrite;
|
|
24478
|
+
}
|
|
24479
|
+
}
|
|
24480
|
+
function runJsonVerification(repo, report) {
|
|
24481
|
+
const doctor = captureOutput(() => doctorCmd(repo, { details: true }));
|
|
24482
|
+
const verify = captureOutput(() => verifyCmd(repo, { json: true, details: true, recordManualEvidence: false }));
|
|
24483
|
+
let verifyReport;
|
|
24484
|
+
try {
|
|
24485
|
+
verifyReport = JSON.parse(verify.output);
|
|
24486
|
+
} catch {
|
|
24487
|
+
verifyReport = void 0;
|
|
24488
|
+
}
|
|
24489
|
+
report.verification = {
|
|
24490
|
+
doctor: { exitCode: doctor.exitCode, output: doctor.output, ...doctor.error ? { error: doctor.error } : {} },
|
|
24491
|
+
verify: verifyReport === void 0 ? { exitCode: verify.exitCode, output: verify.output, ...verify.error ? { error: verify.error } : {} } : { exitCode: verify.exitCode, report: verifyReport, ...verify.error ? { error: verify.error } : {} }
|
|
24492
|
+
};
|
|
24493
|
+
if (doctor.exitCode !== 0 || verify.exitCode !== 0) {
|
|
24494
|
+
report.status = "incomplete";
|
|
24495
|
+
report.errors.push("post-upgrade doctor or verify failed");
|
|
24496
|
+
return 1;
|
|
24497
|
+
}
|
|
24498
|
+
return 0;
|
|
24499
|
+
}
|
|
24500
|
+
function printHumanReport(report) {
|
|
24501
|
+
if (report.status === "blocked") {
|
|
24502
|
+
for (const message of report.errors) err(message);
|
|
24503
|
+
return;
|
|
24504
|
+
}
|
|
24505
|
+
if (report.status === "upgrade-available") {
|
|
24506
|
+
warn(`upgrade available: ${report.fromVersion ?? "untracked"} -> ${report.toVersion}`);
|
|
24507
|
+
if (report.pendingMigrations.length) info(`Pending migrations: ${report.pendingMigrations.join(", ")}`);
|
|
24508
|
+
if (report.changedFiles.length) info(`Files to update: ${report.changedFiles.join(", ")}`);
|
|
24509
|
+
if (report.dirtyFiles.length) warn("apply is blocked until the target Git scope is clean");
|
|
24510
|
+
return;
|
|
24511
|
+
}
|
|
24512
|
+
if (report.status === "current") {
|
|
24513
|
+
ok(`repository is current at ${report.toVersion}`);
|
|
24514
|
+
return;
|
|
24515
|
+
}
|
|
24516
|
+
ok(`upgraded repository: ${report.fromVersion ?? "untracked"} -> ${report.toVersion}`);
|
|
24517
|
+
for (const path of report.changedFiles) ok(`wrote ${path}`);
|
|
24518
|
+
info("Lifecycle hooks were not changed. Manage them explicitly with `harness-kit install-hooks`.");
|
|
24519
|
+
}
|
|
24520
|
+
function upgradeCmd(repo, options = {}) {
|
|
24521
|
+
const report = upgradeRepository(repo, {
|
|
24522
|
+
packageName: package_default.name,
|
|
24523
|
+
targetVersion: package_default.version,
|
|
24524
|
+
check: options.check
|
|
24525
|
+
});
|
|
24526
|
+
if (options.json) {
|
|
24527
|
+
let code = report.status === "blocked" ? 1 : report.status === "upgrade-available" ? 2 : 0;
|
|
24528
|
+
if (!options.check && (report.status === "upgraded" || report.status === "current"))
|
|
24529
|
+
code = runJsonVerification(repo, report);
|
|
24530
|
+
process.stdout.write(`${JSON.stringify(report)}
|
|
24531
|
+
`);
|
|
24532
|
+
return code;
|
|
24533
|
+
}
|
|
24534
|
+
printHumanReport(report);
|
|
24535
|
+
if (report.status === "blocked") return 1;
|
|
24536
|
+
if (report.status === "upgrade-available") return 2;
|
|
24537
|
+
if (options.check) return 0;
|
|
24538
|
+
info("\nRunning post-upgrade doctor --details ...");
|
|
24539
|
+
const doctorCode = doctorCmd(repo, { details: true });
|
|
24540
|
+
info("\nRunning post-upgrade verify --details ...");
|
|
24541
|
+
const verifyCode = verifyCmd(repo, { details: true, recordManualEvidence: false });
|
|
24542
|
+
if (doctorCode !== 0 || verifyCode !== 0) {
|
|
24543
|
+
err("upgrade applied, but post-upgrade verification is incomplete");
|
|
24544
|
+
return 1;
|
|
24545
|
+
}
|
|
24546
|
+
ok("upgrade complete; doctor and verify exited 0 (read their readiness output above)");
|
|
24547
|
+
return 0;
|
|
24548
|
+
}
|
|
24549
|
+
|
|
23967
24550
|
// src/cli.ts
|
|
23968
24551
|
function guard(fn) {
|
|
23969
24552
|
try {
|
|
@@ -23993,6 +24576,7 @@ program2.command("sync").description("generate tool files (AGENTS.md, CLAUDE.md)
|
|
|
23993
24576
|
})
|
|
23994
24577
|
)
|
|
23995
24578
|
);
|
|
24579
|
+
program2.command("upgrade").description("upgrade this repository to the running harness-kit version").option("-C, --repo <dir>", "target repo dir (default: current directory)").option("--check", "read-only; exit 2 when an upgrade is available", false).option("--json", "machine-readable single-report output", false).action((o) => guard(() => upgradeCmd(repoOf(o), { check: o.check, json: o.json })));
|
|
23996
24580
|
program2.command("prepare-adoption").description("render a private, repository-external candidate bundle for blind legacy review").option("-C, --repo <dir>", "target repo dir (default: current directory)").requiredOption("--out <dir>", "new or empty output directory outside the repository").option("--json", "machine-readable output", false).action((o) => guard(() => prepareAdoptionCmd(repoOf(o), { output: o.out, json: o.json })));
|
|
23997
24581
|
program2.command("record-adoption-audit").description("record a declared pass/fail review receipt bound to one adoption candidate and report").option("-C, --repo <dir>", "target repo dir (default: current directory)").requiredOption("--candidate <dir>", "prepared adoption bundle outside the repository").requiredOption("--verdict <pass|fail>", "declared audit verdict").requiredOption("--report <file>", "independent audit report to hash and bind").requiredOption("--reason <text>", "non-empty reviewer rationale").option("--out <receipt>", "receipt path outside the repository (default: candidate bundle)").option("--json", "machine-readable output", false).action(
|
|
23998
24582
|
(o) => guard(
|