@erzhe/harness-kit 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -3
- package/dist/harness-kit.cjs +913 -565
- package/package.json +4 -4
- package/skills/harness-check-loop/SKILL.md +16 -3
package/dist/harness-kit.cjs
CHANGED
|
@@ -4441,9 +4441,9 @@ var require_parse = __commonJS({
|
|
|
4441
4441
|
const idx = prev.value.lastIndexOf("[");
|
|
4442
4442
|
const pre = prev.value.slice(0, idx);
|
|
4443
4443
|
const rest2 = prev.value.slice(idx + 2);
|
|
4444
|
-
const
|
|
4445
|
-
if (
|
|
4446
|
-
prev.value = pre +
|
|
4444
|
+
const posix2 = POSIX_REGEX_SOURCE[rest2];
|
|
4445
|
+
if (posix2) {
|
|
4446
|
+
prev.value = pre + posix2;
|
|
4447
4447
|
state.backtrack = true;
|
|
4448
4448
|
advance();
|
|
4449
4449
|
if (!bos.output && tokens.indexOf(prev) === 1) {
|
|
@@ -4959,7 +4959,7 @@ var require_picomatch = __commonJS({
|
|
|
4959
4959
|
throw new TypeError("Expected pattern to be a non-empty string");
|
|
4960
4960
|
}
|
|
4961
4961
|
const opts = options || {};
|
|
4962
|
-
const
|
|
4962
|
+
const posix2 = opts.windows;
|
|
4963
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;
|
|
@@ -4969,8 +4969,8 @@ var require_picomatch = __commonJS({
|
|
|
4969
4969
|
isIgnored = picomatch4(opts.ignore, ignoreOpts, returnState);
|
|
4970
4970
|
}
|
|
4971
4971
|
const matcher = (input, returnObject = false) => {
|
|
4972
|
-
const { isMatch, match, output } = picomatch4.test(input, regex, options, { glob, posix });
|
|
4973
|
-
const result = { glob, state, regex, posix, input, output, match, isMatch };
|
|
4972
|
+
const { isMatch, match, output } = picomatch4.test(input, regex, options, { glob, posix: posix2 });
|
|
4973
|
+
const result = { glob, state, regex, posix: posix2, input, output, match, isMatch };
|
|
4974
4974
|
if (typeof opts.onResult === "function") {
|
|
4975
4975
|
opts.onResult(result);
|
|
4976
4976
|
}
|
|
@@ -4995,7 +4995,7 @@ var require_picomatch = __commonJS({
|
|
|
4995
4995
|
}
|
|
4996
4996
|
return matcher;
|
|
4997
4997
|
};
|
|
4998
|
-
picomatch4.test = (input, regex, options, { glob, posix } = {}) => {
|
|
4998
|
+
picomatch4.test = (input, regex, options, { glob, posix: posix2 } = {}) => {
|
|
4999
4999
|
if (typeof input !== "string") {
|
|
5000
5000
|
throw new TypeError("Expected input to be a string");
|
|
5001
5001
|
}
|
|
@@ -5003,7 +5003,7 @@ var require_picomatch = __commonJS({
|
|
|
5003
5003
|
return { isMatch: false, output: "" };
|
|
5004
5004
|
}
|
|
5005
5005
|
const opts = options || {};
|
|
5006
|
-
const format2 = opts.format || (
|
|
5006
|
+
const format2 = opts.format || (posix2 ? utils.toPosixSlashes : null);
|
|
5007
5007
|
let match = input === glob;
|
|
5008
5008
|
let output = match && format2 ? format2(input) : input;
|
|
5009
5009
|
if (match === false) {
|
|
@@ -5012,16 +5012,16 @@ var require_picomatch = __commonJS({
|
|
|
5012
5012
|
}
|
|
5013
5013
|
if (match === false || opts.capture === true) {
|
|
5014
5014
|
if (opts.matchBase === true || opts.basename === true) {
|
|
5015
|
-
match = picomatch4.matchBase(input, regex, options,
|
|
5015
|
+
match = picomatch4.matchBase(input, regex, options, posix2);
|
|
5016
5016
|
} else {
|
|
5017
5017
|
match = regex.exec(output);
|
|
5018
5018
|
}
|
|
5019
5019
|
}
|
|
5020
5020
|
return { isMatch: Boolean(match), match, output };
|
|
5021
5021
|
};
|
|
5022
|
-
picomatch4.matchBase = (input, glob, options,
|
|
5022
|
+
picomatch4.matchBase = (input, glob, options, posix2 = options && options.windows) => {
|
|
5023
5023
|
const regex = glob instanceof RegExp ? glob : picomatch4.makeRe(glob, options);
|
|
5024
|
-
return regex.test(utils.basename(input, { windows:
|
|
5024
|
+
return regex.test(utils.basename(input, { windows: posix2 }));
|
|
5025
5025
|
};
|
|
5026
5026
|
picomatch4.isMatch = (str, patterns, options) => picomatch4(patterns, options)(str);
|
|
5027
5027
|
picomatch4.parse = (pattern, options) => {
|
|
@@ -6733,7 +6733,7 @@ var require_log = __commonJS({
|
|
|
6733
6733
|
if (logLevel === "debug")
|
|
6734
6734
|
console.log(...messages);
|
|
6735
6735
|
}
|
|
6736
|
-
function
|
|
6736
|
+
function warn2(logLevel, warning) {
|
|
6737
6737
|
if (logLevel === "debug" || logLevel === "warn") {
|
|
6738
6738
|
if (typeof node_process.emitWarning === "function")
|
|
6739
6739
|
node_process.emitWarning(warning);
|
|
@@ -6742,7 +6742,7 @@ var require_log = __commonJS({
|
|
|
6742
6742
|
}
|
|
6743
6743
|
}
|
|
6744
6744
|
exports2.debug = debug;
|
|
6745
|
-
exports2.warn =
|
|
6745
|
+
exports2.warn = warn2;
|
|
6746
6746
|
}
|
|
6747
6747
|
});
|
|
6748
6748
|
|
|
@@ -9051,10 +9051,10 @@ var require_resolve_block_map = __commonJS({
|
|
|
9051
9051
|
let offset = bm.offset;
|
|
9052
9052
|
let commentEnd = null;
|
|
9053
9053
|
for (const collItem of bm.items) {
|
|
9054
|
-
const { start, key, sep:
|
|
9054
|
+
const { start, key, sep: sep6, value } = collItem;
|
|
9055
9055
|
const keyProps = resolveProps.resolveProps(start, {
|
|
9056
9056
|
indicator: "explicit-key-ind",
|
|
9057
|
-
next: key ??
|
|
9057
|
+
next: key ?? sep6?.[0],
|
|
9058
9058
|
offset,
|
|
9059
9059
|
onError,
|
|
9060
9060
|
parentIndent: bm.indent,
|
|
@@ -9068,7 +9068,7 @@ var require_resolve_block_map = __commonJS({
|
|
|
9068
9068
|
else if ("indent" in key && key.indent !== bm.indent)
|
|
9069
9069
|
onError(offset, "BAD_INDENT", startColMsg);
|
|
9070
9070
|
}
|
|
9071
|
-
if (!keyProps.anchor && !keyProps.tag && !
|
|
9071
|
+
if (!keyProps.anchor && !keyProps.tag && !sep6) {
|
|
9072
9072
|
commentEnd = keyProps.end;
|
|
9073
9073
|
if (keyProps.comment) {
|
|
9074
9074
|
if (map.comment)
|
|
@@ -9092,7 +9092,7 @@ var require_resolve_block_map = __commonJS({
|
|
|
9092
9092
|
ctx.atKey = false;
|
|
9093
9093
|
if (utilMapIncludes.mapIncludes(ctx, map.items, keyNode))
|
|
9094
9094
|
onError(keyStart, "DUPLICATE_KEY", "Map keys must be unique");
|
|
9095
|
-
const valueProps = resolveProps.resolveProps(
|
|
9095
|
+
const valueProps = resolveProps.resolveProps(sep6 ?? [], {
|
|
9096
9096
|
indicator: "map-value-ind",
|
|
9097
9097
|
next: value,
|
|
9098
9098
|
offset: keyNode.range[2],
|
|
@@ -9108,7 +9108,7 @@ var require_resolve_block_map = __commonJS({
|
|
|
9108
9108
|
if (ctx.options.strict && keyProps.start < valueProps.found.offset - 1024)
|
|
9109
9109
|
onError(keyNode.range, "KEY_OVER_1024_CHARS", "The : indicator must be at most 1024 chars after the start of an implicit block mapping key");
|
|
9110
9110
|
}
|
|
9111
|
-
const valueNode = value ? composeNode(ctx, value, valueProps, onError) : composeEmptyNode(ctx, offset,
|
|
9111
|
+
const valueNode = value ? composeNode(ctx, value, valueProps, onError) : composeEmptyNode(ctx, offset, sep6, null, valueProps, onError);
|
|
9112
9112
|
if (ctx.schema.compat)
|
|
9113
9113
|
utilFlowIndentCheck.flowIndentCheck(bm.indent, value, onError);
|
|
9114
9114
|
offset = valueNode.range[2];
|
|
@@ -9199,7 +9199,7 @@ var require_resolve_end = __commonJS({
|
|
|
9199
9199
|
let comment = "";
|
|
9200
9200
|
if (end) {
|
|
9201
9201
|
let hasSpace = false;
|
|
9202
|
-
let
|
|
9202
|
+
let sep6 = "";
|
|
9203
9203
|
for (const token of end) {
|
|
9204
9204
|
const { source, type } = token;
|
|
9205
9205
|
switch (type) {
|
|
@@ -9213,13 +9213,13 @@ var require_resolve_end = __commonJS({
|
|
|
9213
9213
|
if (!comment)
|
|
9214
9214
|
comment = cb;
|
|
9215
9215
|
else
|
|
9216
|
-
comment +=
|
|
9217
|
-
|
|
9216
|
+
comment += sep6 + cb;
|
|
9217
|
+
sep6 = "";
|
|
9218
9218
|
break;
|
|
9219
9219
|
}
|
|
9220
9220
|
case "newline":
|
|
9221
9221
|
if (comment)
|
|
9222
|
-
|
|
9222
|
+
sep6 += source;
|
|
9223
9223
|
hasSpace = true;
|
|
9224
9224
|
break;
|
|
9225
9225
|
default:
|
|
@@ -9262,18 +9262,18 @@ var require_resolve_flow_collection = __commonJS({
|
|
|
9262
9262
|
let offset = fc.offset + fc.start.source.length;
|
|
9263
9263
|
for (let i = 0; i < fc.items.length; ++i) {
|
|
9264
9264
|
const collItem = fc.items[i];
|
|
9265
|
-
const { start, key, sep:
|
|
9265
|
+
const { start, key, sep: sep6, value } = collItem;
|
|
9266
9266
|
const props = resolveProps.resolveProps(start, {
|
|
9267
9267
|
flow: fcName,
|
|
9268
9268
|
indicator: "explicit-key-ind",
|
|
9269
|
-
next: key ??
|
|
9269
|
+
next: key ?? sep6?.[0],
|
|
9270
9270
|
offset,
|
|
9271
9271
|
onError,
|
|
9272
9272
|
parentIndent: fc.indent,
|
|
9273
9273
|
startOnNewline: false
|
|
9274
9274
|
});
|
|
9275
9275
|
if (!props.found) {
|
|
9276
|
-
if (!props.anchor && !props.tag && !
|
|
9276
|
+
if (!props.anchor && !props.tag && !sep6 && !value) {
|
|
9277
9277
|
if (i === 0 && props.comma)
|
|
9278
9278
|
onError(props.comma, "UNEXPECTED_TOKEN", `Unexpected , in ${fcName}`);
|
|
9279
9279
|
else if (i < fc.items.length - 1)
|
|
@@ -9327,8 +9327,8 @@ var require_resolve_flow_collection = __commonJS({
|
|
|
9327
9327
|
}
|
|
9328
9328
|
}
|
|
9329
9329
|
}
|
|
9330
|
-
if (!isMap && !
|
|
9331
|
-
const valueNode = value ? composeNode(ctx, value, props, onError) : composeEmptyNode(ctx, props.end,
|
|
9330
|
+
if (!isMap && !sep6 && !props.found) {
|
|
9331
|
+
const valueNode = value ? composeNode(ctx, value, props, onError) : composeEmptyNode(ctx, props.end, sep6, null, props, onError);
|
|
9332
9332
|
coll.items.push(valueNode);
|
|
9333
9333
|
offset = valueNode.range[2];
|
|
9334
9334
|
if (isBlock(value))
|
|
@@ -9340,7 +9340,7 @@ var require_resolve_flow_collection = __commonJS({
|
|
|
9340
9340
|
if (isBlock(key))
|
|
9341
9341
|
onError(keyNode.range, "BLOCK_IN_FLOW", blockMsg);
|
|
9342
9342
|
ctx.atKey = false;
|
|
9343
|
-
const valueProps = resolveProps.resolveProps(
|
|
9343
|
+
const valueProps = resolveProps.resolveProps(sep6 ?? [], {
|
|
9344
9344
|
flow: fcName,
|
|
9345
9345
|
indicator: "map-value-ind",
|
|
9346
9346
|
next: value,
|
|
@@ -9351,8 +9351,8 @@ var require_resolve_flow_collection = __commonJS({
|
|
|
9351
9351
|
});
|
|
9352
9352
|
if (valueProps.found) {
|
|
9353
9353
|
if (!isMap && !props.found && ctx.options.strict) {
|
|
9354
|
-
if (
|
|
9355
|
-
for (const st of
|
|
9354
|
+
if (sep6)
|
|
9355
|
+
for (const st of sep6) {
|
|
9356
9356
|
if (st === valueProps.found)
|
|
9357
9357
|
break;
|
|
9358
9358
|
if (st.type === "newline") {
|
|
@@ -9369,7 +9369,7 @@ var require_resolve_flow_collection = __commonJS({
|
|
|
9369
9369
|
else
|
|
9370
9370
|
onError(valueProps.start, "MISSING_CHAR", `Missing , or : between ${fcName} items`);
|
|
9371
9371
|
}
|
|
9372
|
-
const valueNode = value ? composeNode(ctx, value, valueProps, onError) : valueProps.found ? composeEmptyNode(ctx, valueProps.end,
|
|
9372
|
+
const valueNode = value ? composeNode(ctx, value, valueProps, onError) : valueProps.found ? composeEmptyNode(ctx, valueProps.end, sep6, null, valueProps, onError) : null;
|
|
9373
9373
|
if (valueNode) {
|
|
9374
9374
|
if (isBlock(value))
|
|
9375
9375
|
onError(valueNode.range, "BLOCK_IN_FLOW", blockMsg);
|
|
@@ -9549,7 +9549,7 @@ var require_resolve_block_scalar = __commonJS({
|
|
|
9549
9549
|
chompStart = i + 1;
|
|
9550
9550
|
}
|
|
9551
9551
|
let value = "";
|
|
9552
|
-
let
|
|
9552
|
+
let sep6 = "";
|
|
9553
9553
|
let prevMoreIndented = false;
|
|
9554
9554
|
for (let i = 0; i < contentStart; ++i)
|
|
9555
9555
|
value += lines[i][0].slice(trimIndent) + "\n";
|
|
@@ -9566,24 +9566,24 @@ var require_resolve_block_scalar = __commonJS({
|
|
|
9566
9566
|
indent = "";
|
|
9567
9567
|
}
|
|
9568
9568
|
if (type === Scalar.Scalar.BLOCK_LITERAL) {
|
|
9569
|
-
value +=
|
|
9570
|
-
|
|
9569
|
+
value += sep6 + indent.slice(trimIndent) + content;
|
|
9570
|
+
sep6 = "\n";
|
|
9571
9571
|
} else if (indent.length > trimIndent || content[0] === " ") {
|
|
9572
|
-
if (
|
|
9573
|
-
|
|
9574
|
-
else if (!prevMoreIndented &&
|
|
9575
|
-
|
|
9576
|
-
value +=
|
|
9577
|
-
|
|
9572
|
+
if (sep6 === " ")
|
|
9573
|
+
sep6 = "\n";
|
|
9574
|
+
else if (!prevMoreIndented && sep6 === "\n")
|
|
9575
|
+
sep6 = "\n\n";
|
|
9576
|
+
value += sep6 + indent.slice(trimIndent) + content;
|
|
9577
|
+
sep6 = "\n";
|
|
9578
9578
|
prevMoreIndented = true;
|
|
9579
9579
|
} else if (content === "") {
|
|
9580
|
-
if (
|
|
9580
|
+
if (sep6 === "\n")
|
|
9581
9581
|
value += "\n";
|
|
9582
9582
|
else
|
|
9583
|
-
|
|
9583
|
+
sep6 = "\n";
|
|
9584
9584
|
} else {
|
|
9585
|
-
value +=
|
|
9586
|
-
|
|
9585
|
+
value += sep6 + content;
|
|
9586
|
+
sep6 = " ";
|
|
9587
9587
|
prevMoreIndented = false;
|
|
9588
9588
|
}
|
|
9589
9589
|
}
|
|
@@ -9765,25 +9765,25 @@ var require_resolve_flow_scalar = __commonJS({
|
|
|
9765
9765
|
if (!match)
|
|
9766
9766
|
return source;
|
|
9767
9767
|
let res = match[1];
|
|
9768
|
-
let
|
|
9768
|
+
let sep6 = " ";
|
|
9769
9769
|
let pos = first.lastIndex;
|
|
9770
9770
|
line.lastIndex = pos;
|
|
9771
9771
|
while (match = line.exec(source)) {
|
|
9772
9772
|
if (match[1] === "") {
|
|
9773
|
-
if (
|
|
9774
|
-
res +=
|
|
9773
|
+
if (sep6 === "\n")
|
|
9774
|
+
res += sep6;
|
|
9775
9775
|
else
|
|
9776
|
-
|
|
9776
|
+
sep6 = "\n";
|
|
9777
9777
|
} else {
|
|
9778
|
-
res +=
|
|
9779
|
-
|
|
9778
|
+
res += sep6 + match[1];
|
|
9779
|
+
sep6 = " ";
|
|
9780
9780
|
}
|
|
9781
9781
|
pos = line.lastIndex;
|
|
9782
9782
|
}
|
|
9783
9783
|
const last = /[ \t]*(.*)/sy;
|
|
9784
9784
|
last.lastIndex = pos;
|
|
9785
9785
|
match = last.exec(source);
|
|
9786
|
-
return res +
|
|
9786
|
+
return res + sep6 + (match?.[1] ?? "");
|
|
9787
9787
|
}
|
|
9788
9788
|
function doubleQuotedValue(source, onError) {
|
|
9789
9789
|
let res = "";
|
|
@@ -10593,14 +10593,14 @@ var require_cst_stringify = __commonJS({
|
|
|
10593
10593
|
}
|
|
10594
10594
|
}
|
|
10595
10595
|
}
|
|
10596
|
-
function stringifyItem({ start, key, sep:
|
|
10596
|
+
function stringifyItem({ start, key, sep: sep6, value }) {
|
|
10597
10597
|
let res = "";
|
|
10598
10598
|
for (const st of start)
|
|
10599
10599
|
res += st.source;
|
|
10600
10600
|
if (key)
|
|
10601
10601
|
res += stringifyToken(key);
|
|
10602
|
-
if (
|
|
10603
|
-
for (const st of
|
|
10602
|
+
if (sep6)
|
|
10603
|
+
for (const st of sep6)
|
|
10604
10604
|
res += st.source;
|
|
10605
10605
|
if (value)
|
|
10606
10606
|
res += stringifyToken(value);
|
|
@@ -11767,18 +11767,18 @@ var require_parser = __commonJS({
|
|
|
11767
11767
|
if (this.type === "map-value-ind") {
|
|
11768
11768
|
const prev = getPrevProps(this.peek(2));
|
|
11769
11769
|
const start = getFirstKeyStartProps(prev);
|
|
11770
|
-
let
|
|
11770
|
+
let sep6;
|
|
11771
11771
|
if (scalar.end) {
|
|
11772
|
-
|
|
11773
|
-
|
|
11772
|
+
sep6 = scalar.end;
|
|
11773
|
+
sep6.push(this.sourceToken);
|
|
11774
11774
|
delete scalar.end;
|
|
11775
11775
|
} else
|
|
11776
|
-
|
|
11776
|
+
sep6 = [this.sourceToken];
|
|
11777
11777
|
const map = {
|
|
11778
11778
|
type: "block-map",
|
|
11779
11779
|
offset: scalar.offset,
|
|
11780
11780
|
indent: scalar.indent,
|
|
11781
|
-
items: [{ start, key: scalar, sep:
|
|
11781
|
+
items: [{ start, key: scalar, sep: sep6 }]
|
|
11782
11782
|
};
|
|
11783
11783
|
this.onKeyLine = true;
|
|
11784
11784
|
this.stack[this.stack.length - 1] = map;
|
|
@@ -11931,15 +11931,15 @@ var require_parser = __commonJS({
|
|
|
11931
11931
|
} else if (isFlowToken(it.key) && !includesToken(it.sep, "newline")) {
|
|
11932
11932
|
const start2 = getFirstKeyStartProps(it.start);
|
|
11933
11933
|
const key = it.key;
|
|
11934
|
-
const
|
|
11935
|
-
|
|
11934
|
+
const sep6 = it.sep;
|
|
11935
|
+
sep6.push(this.sourceToken);
|
|
11936
11936
|
delete it.key;
|
|
11937
11937
|
delete it.sep;
|
|
11938
11938
|
this.stack.push({
|
|
11939
11939
|
type: "block-map",
|
|
11940
11940
|
offset: this.offset,
|
|
11941
11941
|
indent: this.indent,
|
|
11942
|
-
items: [{ start: start2, key, sep:
|
|
11942
|
+
items: [{ start: start2, key, sep: sep6 }]
|
|
11943
11943
|
});
|
|
11944
11944
|
} else if (start.length > 0) {
|
|
11945
11945
|
it.sep = it.sep.concat(start, this.sourceToken);
|
|
@@ -12133,13 +12133,13 @@ var require_parser = __commonJS({
|
|
|
12133
12133
|
const prev = getPrevProps(parent);
|
|
12134
12134
|
const start = getFirstKeyStartProps(prev);
|
|
12135
12135
|
fixFlowSeqItems(fc);
|
|
12136
|
-
const
|
|
12137
|
-
|
|
12136
|
+
const sep6 = fc.end.splice(1, fc.end.length);
|
|
12137
|
+
sep6.push(this.sourceToken);
|
|
12138
12138
|
const map = {
|
|
12139
12139
|
type: "block-map",
|
|
12140
12140
|
offset: fc.offset,
|
|
12141
12141
|
indent: fc.indent,
|
|
12142
|
-
items: [{ start, key: fc, sep:
|
|
12142
|
+
items: [{ start, key: fc, sep: sep6 }]
|
|
12143
12143
|
};
|
|
12144
12144
|
this.onKeyLine = true;
|
|
12145
12145
|
this.stack[this.stack.length - 1] = map;
|
|
@@ -14892,9 +14892,9 @@ var require_parse3 = __commonJS({
|
|
|
14892
14892
|
const idx = prev.value.lastIndexOf("[");
|
|
14893
14893
|
const pre = prev.value.slice(0, idx);
|
|
14894
14894
|
const rest2 = prev.value.slice(idx + 2);
|
|
14895
|
-
const
|
|
14896
|
-
if (
|
|
14897
|
-
prev.value = pre +
|
|
14895
|
+
const posix2 = POSIX_REGEX_SOURCE[rest2];
|
|
14896
|
+
if (posix2) {
|
|
14897
|
+
prev.value = pre + posix2;
|
|
14898
14898
|
state.backtrack = true;
|
|
14899
14899
|
advance();
|
|
14900
14900
|
if (!bos.output && tokens.indexOf(prev) === 1) {
|
|
@@ -15415,7 +15415,7 @@ var require_picomatch3 = __commonJS({
|
|
|
15415
15415
|
throw new TypeError("Expected pattern to be a non-empty string");
|
|
15416
15416
|
}
|
|
15417
15417
|
const opts = options || {};
|
|
15418
|
-
const
|
|
15418
|
+
const posix2 = utils.isWindows(options);
|
|
15419
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;
|
|
@@ -15425,8 +15425,8 @@ var require_picomatch3 = __commonJS({
|
|
|
15425
15425
|
isIgnored = picomatch4(opts.ignore, ignoreOpts, returnState);
|
|
15426
15426
|
}
|
|
15427
15427
|
const matcher = (input, returnObject = false) => {
|
|
15428
|
-
const { isMatch, match, output } = picomatch4.test(input, regex, options, { glob, posix });
|
|
15429
|
-
const result = { glob, state, regex, posix, input, output, match, isMatch };
|
|
15428
|
+
const { isMatch, match, output } = picomatch4.test(input, regex, options, { glob, posix: posix2 });
|
|
15429
|
+
const result = { glob, state, regex, posix: posix2, input, output, match, isMatch };
|
|
15430
15430
|
if (typeof opts.onResult === "function") {
|
|
15431
15431
|
opts.onResult(result);
|
|
15432
15432
|
}
|
|
@@ -15451,7 +15451,7 @@ var require_picomatch3 = __commonJS({
|
|
|
15451
15451
|
}
|
|
15452
15452
|
return matcher;
|
|
15453
15453
|
};
|
|
15454
|
-
picomatch4.test = (input, regex, options, { glob, posix } = {}) => {
|
|
15454
|
+
picomatch4.test = (input, regex, options, { glob, posix: posix2 } = {}) => {
|
|
15455
15455
|
if (typeof input !== "string") {
|
|
15456
15456
|
throw new TypeError("Expected input to be a string");
|
|
15457
15457
|
}
|
|
@@ -15459,7 +15459,7 @@ var require_picomatch3 = __commonJS({
|
|
|
15459
15459
|
return { isMatch: false, output: "" };
|
|
15460
15460
|
}
|
|
15461
15461
|
const opts = options || {};
|
|
15462
|
-
const format2 = opts.format || (
|
|
15462
|
+
const format2 = opts.format || (posix2 ? utils.toPosixSlashes : null);
|
|
15463
15463
|
let match = input === glob;
|
|
15464
15464
|
let output = match && format2 ? format2(input) : input;
|
|
15465
15465
|
if (match === false) {
|
|
@@ -15468,14 +15468,14 @@ var require_picomatch3 = __commonJS({
|
|
|
15468
15468
|
}
|
|
15469
15469
|
if (match === false || opts.capture === true) {
|
|
15470
15470
|
if (opts.matchBase === true || opts.basename === true) {
|
|
15471
|
-
match = picomatch4.matchBase(input, regex, options,
|
|
15471
|
+
match = picomatch4.matchBase(input, regex, options, posix2);
|
|
15472
15472
|
} else {
|
|
15473
15473
|
match = regex.exec(output);
|
|
15474
15474
|
}
|
|
15475
15475
|
}
|
|
15476
15476
|
return { isMatch: Boolean(match), match, output };
|
|
15477
15477
|
};
|
|
15478
|
-
picomatch4.matchBase = (input, glob, options,
|
|
15478
|
+
picomatch4.matchBase = (input, glob, options, posix2 = utils.isWindows(options)) => {
|
|
15479
15479
|
const regex = glob instanceof RegExp ? glob : picomatch4.makeRe(glob, options);
|
|
15480
15480
|
return regex.test(path.basename(input));
|
|
15481
15481
|
};
|
|
@@ -15664,9 +15664,9 @@ var require_micromatch = __commonJS({
|
|
|
15664
15664
|
return [].concat(patterns).every((p) => picomatch4(p, options)(str));
|
|
15665
15665
|
};
|
|
15666
15666
|
micromatch.capture = (glob, input, options) => {
|
|
15667
|
-
let
|
|
15667
|
+
let posix2 = utils.isWindows(options);
|
|
15668
15668
|
let regex = picomatch4.makeRe(String(glob), { ...options, capture: true });
|
|
15669
|
-
let match = regex.exec(
|
|
15669
|
+
let match = regex.exec(posix2 ? utils.toPosixSlashes(input) : input);
|
|
15670
15670
|
if (match) {
|
|
15671
15671
|
return match.slice(1).map((v) => v === void 0 ? "" : v);
|
|
15672
15672
|
}
|
|
@@ -18117,19 +18117,19 @@ var require_out4 = __commonJS({
|
|
|
18117
18117
|
return utils.path.convertPathToPattern(source);
|
|
18118
18118
|
}
|
|
18119
18119
|
FastGlob2.convertPathToPattern = convertPathToPattern;
|
|
18120
|
-
let
|
|
18121
|
-
(function(
|
|
18120
|
+
let posix2;
|
|
18121
|
+
(function(posix3) {
|
|
18122
18122
|
function escapePath2(source) {
|
|
18123
18123
|
assertPatternsInput(source);
|
|
18124
18124
|
return utils.path.escapePosixPath(source);
|
|
18125
18125
|
}
|
|
18126
|
-
|
|
18126
|
+
posix3.escapePath = escapePath2;
|
|
18127
18127
|
function convertPathToPattern2(source) {
|
|
18128
18128
|
assertPatternsInput(source);
|
|
18129
18129
|
return utils.path.convertPosixPathToPattern(source);
|
|
18130
18130
|
}
|
|
18131
|
-
|
|
18132
|
-
})(
|
|
18131
|
+
posix3.convertPathToPattern = convertPathToPattern2;
|
|
18132
|
+
})(posix2 = FastGlob2.posix || (FastGlob2.posix = {}));
|
|
18133
18133
|
let win32;
|
|
18134
18134
|
(function(win322) {
|
|
18135
18135
|
function escapePath2(source) {
|
|
@@ -18180,12 +18180,12 @@ var {
|
|
|
18180
18180
|
} = import_index.default;
|
|
18181
18181
|
|
|
18182
18182
|
// src/cli.ts
|
|
18183
|
-
var
|
|
18183
|
+
var import_node_path21 = require("node:path");
|
|
18184
18184
|
|
|
18185
18185
|
// package.json
|
|
18186
18186
|
var package_default = {
|
|
18187
18187
|
name: "@erzhe/harness-kit",
|
|
18188
|
-
version: "0.
|
|
18188
|
+
version: "0.7.0",
|
|
18189
18189
|
type: "module",
|
|
18190
18190
|
description: "AI-friendly repo harness: a manifest.yaml single source of truth that generates AGENTS.md / CLAUDE.md / Cursor rules and enforces invariants, contracts and drift via `harness-kit verify`.",
|
|
18191
18191
|
keywords: [
|
|
@@ -18199,13 +18199,13 @@ var package_default = {
|
|
|
18199
18199
|
"cursor",
|
|
18200
18200
|
"claude"
|
|
18201
18201
|
],
|
|
18202
|
-
homepage: "https://github.com/
|
|
18202
|
+
homepage: "https://github.com/reunion-labs/harness-kit#readme",
|
|
18203
18203
|
repository: {
|
|
18204
18204
|
type: "git",
|
|
18205
|
-
url: "git+https://github.com/
|
|
18205
|
+
url: "git+https://github.com/reunion-labs/harness-kit.git"
|
|
18206
18206
|
},
|
|
18207
18207
|
bugs: {
|
|
18208
|
-
url: "https://github.com/
|
|
18208
|
+
url: "https://github.com/reunion-labs/harness-kit/issues"
|
|
18209
18209
|
},
|
|
18210
18210
|
author: "MeCKodo (\u4E8C\u54F2) <https://erzhe.me/>",
|
|
18211
18211
|
license: "MIT",
|
|
@@ -18250,8 +18250,8 @@ var package_default = {
|
|
|
18250
18250
|
// src/adoption.ts
|
|
18251
18251
|
var import_node_child_process2 = require("node:child_process");
|
|
18252
18252
|
var import_node_crypto4 = require("node:crypto");
|
|
18253
|
-
var
|
|
18254
|
-
var
|
|
18253
|
+
var import_node_fs6 = require("node:fs");
|
|
18254
|
+
var import_node_path6 = require("node:path");
|
|
18255
18255
|
|
|
18256
18256
|
// src/manifest.ts
|
|
18257
18257
|
var import_node_fs2 = require("node:fs");
|
|
@@ -19171,27 +19171,52 @@ function writeManagedFiles(repo, targets, options = {}) {
|
|
|
19171
19171
|
};
|
|
19172
19172
|
}
|
|
19173
19173
|
|
|
19174
|
-
// src/
|
|
19175
|
-
var import_node_crypto3 = require("node:crypto");
|
|
19174
|
+
// src/harness-cli.ts
|
|
19176
19175
|
var import_node_fs4 = require("node:fs");
|
|
19177
19176
|
var import_node_path4 = require("node:path");
|
|
19177
|
+
var HARNESS_LOCK_REL = ".agents/harness.lock.json";
|
|
19178
|
+
var HARNESS_PACKAGE = package_default.name;
|
|
19179
|
+
var SAFE_VERSION = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
19180
|
+
function lockedHarnessVersion(repo) {
|
|
19181
|
+
const path = (0, import_node_path4.join)(repo, HARNESS_LOCK_REL);
|
|
19182
|
+
try {
|
|
19183
|
+
if (!(0, import_node_fs4.lstatSync)(path).isFile()) return null;
|
|
19184
|
+
const value = JSON.parse((0, import_node_fs4.readFileSync)(path, "utf8"));
|
|
19185
|
+
if (value?.package !== HARNESS_PACKAGE || typeof value.version !== "string") return null;
|
|
19186
|
+
return SAFE_VERSION.test(value.version) ? value.version : null;
|
|
19187
|
+
} catch {
|
|
19188
|
+
return null;
|
|
19189
|
+
}
|
|
19190
|
+
}
|
|
19191
|
+
function harnessInvocation(version) {
|
|
19192
|
+
const pinned = version && SAFE_VERSION.test(version) ? version : "latest";
|
|
19193
|
+
return `npx -y ${HARNESS_PACKAGE}@${pinned}`;
|
|
19194
|
+
}
|
|
19195
|
+
function repoHarnessInvocation(repo) {
|
|
19196
|
+
return harnessInvocation(lockedHarnessVersion(repo));
|
|
19197
|
+
}
|
|
19198
|
+
|
|
19199
|
+
// src/util.ts
|
|
19200
|
+
var import_node_crypto3 = require("node:crypto");
|
|
19201
|
+
var import_node_fs5 = require("node:fs");
|
|
19202
|
+
var import_node_path5 = require("node:path");
|
|
19178
19203
|
function sha256(input) {
|
|
19179
19204
|
return (0, import_node_crypto3.createHash)("sha256").update(input).digest("hex");
|
|
19180
19205
|
}
|
|
19181
19206
|
function hashFile(absPath) {
|
|
19182
19207
|
try {
|
|
19183
|
-
if (!(0,
|
|
19184
|
-
return sha256((0,
|
|
19208
|
+
if (!(0, import_node_fs5.statSync)(absPath).isFile()) return null;
|
|
19209
|
+
return sha256((0, import_node_fs5.readFileSync)(absPath));
|
|
19185
19210
|
} catch {
|
|
19186
19211
|
return null;
|
|
19187
19212
|
}
|
|
19188
19213
|
}
|
|
19189
19214
|
function readText(absPath) {
|
|
19190
|
-
return (0,
|
|
19215
|
+
return (0, import_node_fs5.existsSync)(absPath) ? (0, import_node_fs5.readFileSync)(absPath, "utf8") : null;
|
|
19191
19216
|
}
|
|
19192
19217
|
function writeText(absPath, content) {
|
|
19193
|
-
(0,
|
|
19194
|
-
(0,
|
|
19218
|
+
(0, import_node_fs5.mkdirSync)((0, import_node_path5.dirname)(absPath), { recursive: true });
|
|
19219
|
+
(0, import_node_fs5.writeFileSync)(absPath, content);
|
|
19195
19220
|
}
|
|
19196
19221
|
var ok = (m) => console.log(` OK ${m}`);
|
|
19197
19222
|
var err = (m) => console.log(` ERR ${m}`);
|
|
@@ -19206,9 +19231,9 @@ function safeStr(v) {
|
|
|
19206
19231
|
if (typeof v === "number" || typeof v === "boolean") return String(v);
|
|
19207
19232
|
return JSON.stringify(v);
|
|
19208
19233
|
}
|
|
19209
|
-
function renderTargets(m) {
|
|
19234
|
+
function renderTargets(m, opts = {}) {
|
|
19210
19235
|
const targets = [
|
|
19211
|
-
["AGENTS.md", renderAgentsMd(m)],
|
|
19236
|
+
["AGENTS.md", renderAgentsMd(m, opts)],
|
|
19212
19237
|
["CLAUDE.md", renderClaudeMd()],
|
|
19213
19238
|
[".agents/reference.md", renderReferenceMd(m)]
|
|
19214
19239
|
];
|
|
@@ -19216,15 +19241,20 @@ function renderTargets(m) {
|
|
|
19216
19241
|
if (m.modules?.length) targets.push([".agents/modules.md", renderModulesMd(m)]);
|
|
19217
19242
|
return targets;
|
|
19218
19243
|
}
|
|
19219
|
-
function renderAgentsMd(m) {
|
|
19244
|
+
function renderAgentsMd(m, opts = {}) {
|
|
19220
19245
|
const id = m.identity;
|
|
19246
|
+
const hk = harnessInvocation(opts.harnessVersion);
|
|
19221
19247
|
const L = [];
|
|
19222
19248
|
L.push(GEN_HEADER(), "");
|
|
19223
19249
|
L.push(`# ${id.name}`, "");
|
|
19224
19250
|
if (id.summary) L.push(id.summary, "");
|
|
19225
19251
|
L.push("## Working agreement (read first)", "");
|
|
19226
19252
|
L.push(
|
|
19227
|
-
|
|
19253
|
+
`Harness CLI: run every \`harness-kit <command>\` here as \`${hk} <command>\` ` + (opts.harnessVersion ? `(version pinned by \`${HARNESS_LOCK_REL}\`; no global install needed).` : `(no global install needed; this repository has no \`${HARNESS_LOCK_REL}\` version pin yet).`),
|
|
19254
|
+
""
|
|
19255
|
+
);
|
|
19256
|
+
L.push(
|
|
19257
|
+
`\`AGENTS.md\`, \`CLAUDE.md\`, and \`.agents/reference.md\` are GENERATED from \`.agents/manifest.yaml\`; \`.agents/routing.md\` / \`.agents/modules.md\` are generated when those sections are declared. Do NOT edit those files by hand \u2014 edit the manifest and run \`${hk} sync\`. Knowledge is hand-authored; \`.agents/hooks/\` is managed by \`${hk} install-hooks\`.`,
|
|
19228
19258
|
""
|
|
19229
19259
|
);
|
|
19230
19260
|
L.push("Before you touch code:");
|
|
@@ -19235,19 +19265,19 @@ function renderAgentsMd(m) {
|
|
|
19235
19265
|
L.push("2. Find your change-type in `.agents/routing.md` and read the files it points to. Do NOT full-repo grep and guess.");
|
|
19236
19266
|
else L.push("2. Read the relevant files before editing. Do NOT full-repo grep and guess.");
|
|
19237
19267
|
if ((m.modules ?? []).some((mod) => (mod.owns?.length ?? 0) > 0) || m.validation)
|
|
19238
|
-
L.push(
|
|
19268
|
+
L.push(` Prefer \`${hk} task-start\` before editing so committed work stays in the deliver scope.`);
|
|
19239
19269
|
L.push("");
|
|
19240
19270
|
const hasImpactMap = (m.modules ?? []).some((mod) => (mod.owns?.length ?? 0) > 0) || !!m.validation;
|
|
19241
19271
|
L.push("Before you finish:");
|
|
19242
19272
|
if (hasImpactMap) {
|
|
19243
19273
|
L.push(
|
|
19244
|
-
|
|
19274
|
+
`3. Run \`${hk} deliver\` (impact-driven checks + verify + stamp). Only \`status=accepted\` (or clean \`no-change\`) means the task is done. If \`needs-work\`, fix and re-run \u2014 do not claim completion without an accepted stamp.`
|
|
19245
19275
|
);
|
|
19246
19276
|
L.push(
|
|
19247
|
-
|
|
19277
|
+
` Optional: \`${hk} task-start\` before editing so later commits stay in scope; without it, deliver falls back to the current worktree git diff vs HEAD.`
|
|
19248
19278
|
);
|
|
19249
19279
|
} else {
|
|
19250
|
-
L.push(
|
|
19280
|
+
L.push(`3. Run \`${hk} deliver\` (or at least \`${hk} verify\`). Do not claim completion without a passing stamp/verify.`);
|
|
19251
19281
|
}
|
|
19252
19282
|
L.push(
|
|
19253
19283
|
"4. Read `NEXT ACTIONS` (or JSON `nextActions`): complete every `required | agent` action automatically before finishing; ask the user only for a `required | human` decision. Defer `recommended` maintenance during unrelated product work."
|
|
@@ -19300,7 +19330,7 @@ function renderAgentsMd(m) {
|
|
|
19300
19330
|
const how = inv.enforcement ? "enforced" : inv.check ? "checked" : "manual";
|
|
19301
19331
|
L.push(`- ${inv.rule} [${how}]`);
|
|
19302
19332
|
}
|
|
19303
|
-
L.push("",
|
|
19333
|
+
L.push("", `Run \`${hk} verify\` to check the enforceable ones.`, "");
|
|
19304
19334
|
}
|
|
19305
19335
|
L.push("## Knowledge & maps (load on demand)", "");
|
|
19306
19336
|
if (!m.knowledge?.length || m.knowledge.some((knowledge) => (knowledge.root ?? "agents") === "agents"))
|
|
@@ -19311,7 +19341,7 @@ function renderAgentsMd(m) {
|
|
|
19311
19341
|
L.push("- Full commands, environment, and registered knowledge catalog: `.agents/reference.md`");
|
|
19312
19342
|
if (m.routing?.length) L.push("- Change-type routing (read before editing): `.agents/routing.md`");
|
|
19313
19343
|
if (m.modules?.length) L.push("- Module map + common pitfalls: `.agents/modules.md`");
|
|
19314
|
-
if (hasImpactMap) L.push(
|
|
19344
|
+
if (hasImpactMap) L.push(`- Implement -> verify loop (deep guide): run \`${hk} check-loop\``);
|
|
19315
19345
|
L.push("- Tooling adoption log (earn heavier tooling): `.agents/adoption.md`");
|
|
19316
19346
|
if (m.playbooks?.dir) L.push(`- Task playbooks: \`.agents/${m.playbooks.dir}\``);
|
|
19317
19347
|
L.push("");
|
|
@@ -19428,7 +19458,7 @@ function validPermissionMode(mode) {
|
|
|
19428
19458
|
}
|
|
19429
19459
|
function safeEvidencePath(path) {
|
|
19430
19460
|
try {
|
|
19431
|
-
return safeRelativePath(path, "legacy evidence") === path && !path.startsWith(`${LEGACY_DIR_REL}${
|
|
19461
|
+
return safeRelativePath(path, "legacy evidence") === path && !path.startsWith(`${LEGACY_DIR_REL}${import_node_path6.sep}`);
|
|
19432
19462
|
} catch {
|
|
19433
19463
|
return false;
|
|
19434
19464
|
}
|
|
@@ -19438,39 +19468,39 @@ function isErrno2(error, code) {
|
|
|
19438
19468
|
}
|
|
19439
19469
|
function ensureNoSymlinkDirectoryChain(root, directory, label, create) {
|
|
19440
19470
|
if (!inside2(root, directory)) throw new Error(`${label} parent escapes the repository`);
|
|
19441
|
-
const rel = (0,
|
|
19471
|
+
const rel = (0, import_node_path6.relative)(root, directory);
|
|
19442
19472
|
let cursor = root;
|
|
19443
|
-
for (const component of rel.split(
|
|
19444
|
-
cursor = (0,
|
|
19473
|
+
for (const component of rel.split(import_node_path6.sep).filter(Boolean)) {
|
|
19474
|
+
cursor = (0, import_node_path6.join)(cursor, component);
|
|
19445
19475
|
let stat;
|
|
19446
19476
|
try {
|
|
19447
|
-
stat = (0,
|
|
19477
|
+
stat = (0, import_node_fs6.lstatSync)(cursor);
|
|
19448
19478
|
} catch (error) {
|
|
19449
19479
|
if (!isErrno2(error, "ENOENT")) throw new Error(`cannot inspect ${label} parent ${cursor}: ${errorMessage2(error)}`);
|
|
19450
19480
|
if (!create) return false;
|
|
19451
19481
|
try {
|
|
19452
|
-
(0,
|
|
19482
|
+
(0, import_node_fs6.mkdirSync)(cursor);
|
|
19453
19483
|
} catch (mkdirError) {
|
|
19454
19484
|
if (!isErrno2(mkdirError, "EEXIST"))
|
|
19455
19485
|
throw new Error(`cannot create ${label} parent ${cursor}: ${errorMessage2(mkdirError)}`);
|
|
19456
19486
|
}
|
|
19457
|
-
stat = (0,
|
|
19487
|
+
stat = (0, import_node_fs6.lstatSync)(cursor);
|
|
19458
19488
|
}
|
|
19459
19489
|
if (stat.isSymbolicLink()) throw new Error(`${label} parent must not be a symlink: ${cursor}`);
|
|
19460
19490
|
if (!stat.isDirectory()) throw new Error(`${label} parent must be a directory: ${cursor}`);
|
|
19461
|
-
const resolved = (0,
|
|
19491
|
+
const resolved = (0, import_node_fs6.realpathSync)(cursor);
|
|
19462
19492
|
if (!inside2(root, resolved)) throw new Error(`${label} parent resolves outside the repository: ${cursor}`);
|
|
19463
19493
|
}
|
|
19464
19494
|
return true;
|
|
19465
19495
|
}
|
|
19466
19496
|
function readOptionalRepositoryFile(repoRoot, relativePath, label, afterLstat) {
|
|
19467
19497
|
const normalized = safeRelativePath(relativePath, label);
|
|
19468
|
-
const absolute = (0,
|
|
19498
|
+
const absolute = (0, import_node_path6.resolve)(repoRoot, normalized);
|
|
19469
19499
|
if (!inside2(repoRoot, absolute) || absolute === repoRoot) throw new Error(`${label} path escapes the repository`);
|
|
19470
|
-
if (!ensureNoSymlinkDirectoryChain(repoRoot, (0,
|
|
19500
|
+
if (!ensureNoSymlinkDirectoryChain(repoRoot, (0, import_node_path6.dirname)(absolute), label, false)) return null;
|
|
19471
19501
|
let before;
|
|
19472
19502
|
try {
|
|
19473
|
-
before = (0,
|
|
19503
|
+
before = (0, import_node_fs6.lstatSync)(absolute);
|
|
19474
19504
|
} catch (error) {
|
|
19475
19505
|
if (isErrno2(error, "ENOENT")) return null;
|
|
19476
19506
|
throw new Error(`cannot inspect ${label}: ${errorMessage2(error)}`);
|
|
@@ -19479,22 +19509,22 @@ function readOptionalRepositoryFile(repoRoot, relativePath, label, afterLstat) {
|
|
|
19479
19509
|
afterLstat?.(normalized);
|
|
19480
19510
|
let fd;
|
|
19481
19511
|
try {
|
|
19482
|
-
fd = (0,
|
|
19512
|
+
fd = (0, import_node_fs6.openSync)(absolute, import_node_fs6.constants.O_RDONLY | import_node_fs6.constants.O_NOFOLLOW);
|
|
19483
19513
|
} catch (error) {
|
|
19484
19514
|
throw new Error(`cannot open ${label} without following links: ${errorMessage2(error)}`);
|
|
19485
19515
|
}
|
|
19486
19516
|
try {
|
|
19487
|
-
const opened = (0,
|
|
19517
|
+
const opened = (0, import_node_fs6.fstatSync)(fd);
|
|
19488
19518
|
if (!opened.isFile() || opened.dev !== before.dev || opened.ino !== before.ino)
|
|
19489
19519
|
throw new Error(`${label} changed while it was being inspected: ${relativePath}`);
|
|
19490
19520
|
return {
|
|
19491
|
-
bytes: (0,
|
|
19521
|
+
bytes: (0, import_node_fs6.readFileSync)(fd),
|
|
19492
19522
|
mode: permissionMode(opened.mode),
|
|
19493
19523
|
dev: opened.dev,
|
|
19494
19524
|
ino: opened.ino
|
|
19495
19525
|
};
|
|
19496
19526
|
} finally {
|
|
19497
|
-
(0,
|
|
19527
|
+
(0, import_node_fs6.closeSync)(fd);
|
|
19498
19528
|
}
|
|
19499
19529
|
}
|
|
19500
19530
|
function parseAdoptionIndex(raw) {
|
|
@@ -19512,7 +19542,7 @@ function parseAdoptionIndex(raw) {
|
|
|
19512
19542
|
throw new Error(`${INDEX_REL} \u683C\u5F0F\u65E0\u6548\uFF1Aentry path \u4E0D\u5B89\u5168\u6216\u91CD\u590D`);
|
|
19513
19543
|
seen.add(entry.path);
|
|
19514
19544
|
if (entry.type === "file") {
|
|
19515
|
-
const expectedSnapshot = (0,
|
|
19545
|
+
const expectedSnapshot = (0, import_node_path6.join)(LEGACY_DIR_REL, snapshotName(entry.path));
|
|
19516
19546
|
if (!/^[a-f0-9]{64}$/.test(entry.sha256 ?? "") || entry.snapshot !== expectedSnapshot || !validPermissionMode(entry.mode))
|
|
19517
19547
|
throw new Error(`${INDEX_REL} \u683C\u5F0F\u65E0\u6548\uFF1A${entry.path} snapshot/mode/hash \u65E0\u6548`);
|
|
19518
19548
|
} else if (entry.type === "symlink") {
|
|
@@ -19533,15 +19563,15 @@ function readAdoptionIndex(repo) {
|
|
|
19533
19563
|
}
|
|
19534
19564
|
function verifyAdoptionEntry(repo, entry) {
|
|
19535
19565
|
const root = repositoryRoot2(repo);
|
|
19536
|
-
const path = (0,
|
|
19566
|
+
const path = (0, import_node_path6.join)(root, entry.path);
|
|
19537
19567
|
let stat;
|
|
19538
19568
|
try {
|
|
19539
|
-
if (!ensureNoSymlinkDirectoryChain(root, (0,
|
|
19540
|
-
stat = (0,
|
|
19569
|
+
if (!ensureNoSymlinkDirectoryChain(root, (0, import_node_path6.dirname)(path), `legacy source ${entry.path}`, false)) return false;
|
|
19570
|
+
stat = (0, import_node_fs6.lstatSync)(path);
|
|
19541
19571
|
} catch {
|
|
19542
19572
|
return false;
|
|
19543
19573
|
}
|
|
19544
|
-
if (entry.type === "symlink") return stat.isSymbolicLink() && (0,
|
|
19574
|
+
if (entry.type === "symlink") return stat.isSymbolicLink() && (0, import_node_fs6.readlinkSync)(path) === entry.linkTarget;
|
|
19545
19575
|
if (!stat.isFile() || stat.isSymbolicLink() || !entry.sha256 || !entry.snapshot || !validPermissionMode(entry.mode)) return false;
|
|
19546
19576
|
try {
|
|
19547
19577
|
const source = readOptionalRepositoryFile(root, entry.path, `legacy source ${entry.path}`);
|
|
@@ -19555,22 +19585,22 @@ function snapshotName(path) {
|
|
|
19555
19585
|
return path.replaceAll("/", "__") + ".pre-harness";
|
|
19556
19586
|
}
|
|
19557
19587
|
function captureEntry(repo, path) {
|
|
19558
|
-
const absolute = (0,
|
|
19588
|
+
const absolute = (0, import_node_path6.join)(repo, path);
|
|
19559
19589
|
let stat;
|
|
19560
19590
|
try {
|
|
19561
|
-
stat = (0,
|
|
19591
|
+
stat = (0, import_node_fs6.lstatSync)(absolute);
|
|
19562
19592
|
} catch (error) {
|
|
19563
19593
|
if (isErrno2(error, "ENOENT")) return { entry: null };
|
|
19564
19594
|
throw error;
|
|
19565
19595
|
}
|
|
19566
|
-
if (stat.isSymbolicLink()) return { entry: { path, type: "symlink", linkTarget: (0,
|
|
19596
|
+
if (stat.isSymbolicLink()) return { entry: { path, type: "symlink", linkTarget: (0, import_node_fs6.readlinkSync)(absolute) } };
|
|
19567
19597
|
if (!stat.isFile()) throw new Error(`\u65E0\u6CD5\u63A5\u7BA1 ${path}\uFF1A\u5B83\u65E2\u4E0D\u662F\u666E\u901A\u6587\u4EF6\u4E5F\u4E0D\u662F\u8F6F\u94FE\u63A5`);
|
|
19568
19598
|
const source = readOptionalRepositoryFile(repo, path, `legacy source ${path}`);
|
|
19569
19599
|
if (!source) return { entry: null };
|
|
19570
19600
|
const content = source.bytes;
|
|
19571
19601
|
if (content.toString("utf8").startsWith(GENERATED_MARKER)) return { entry: null };
|
|
19572
19602
|
const mode = source.mode;
|
|
19573
|
-
const snapshot = (0,
|
|
19603
|
+
const snapshot = (0, import_node_path6.join)(LEGACY_DIR_REL, snapshotName(path));
|
|
19574
19604
|
const existing = readOptionalRepositoryFile(repo, snapshot, `legacy snapshot ${path}`);
|
|
19575
19605
|
if (existing && (sha256(existing.bytes) !== sha256(content) || existing.mode !== mode))
|
|
19576
19606
|
throw new Error(`\u5DF2\u6709 legacy snapshot \u5185\u5BB9\u6216 mode \u4E0D\u5339\u914D\uFF0C\u62D2\u7EDD\u8986\u76D6: ${snapshot}`);
|
|
@@ -19589,25 +19619,25 @@ function findAgentEntryPaths(repo) {
|
|
|
19589
19619
|
maxBuffer: 32 * 1024 * 1024
|
|
19590
19620
|
});
|
|
19591
19621
|
for (const path of tracked.split("\0").filter(Boolean)) {
|
|
19592
|
-
const normalized = (0,
|
|
19593
|
-
if (AGENT_ENTRY_NAMES.has((0,
|
|
19622
|
+
const normalized = (0, import_node_path6.normalize)(path);
|
|
19623
|
+
if (AGENT_ENTRY_NAMES.has((0, import_node_path6.basename)(normalized)) && safeEvidencePath(normalized) && !normalized.startsWith(`.agents${import_node_path6.sep}adoption${import_node_path6.sep}`) && entryExists((0, import_node_path6.join)(repo, normalized))) entries.add(normalized);
|
|
19594
19624
|
}
|
|
19595
19625
|
} catch {
|
|
19596
19626
|
}
|
|
19597
19627
|
const walk = (directory, prefix) => {
|
|
19598
|
-
const directoryStat = (0,
|
|
19599
|
-
if (directoryStat.isSymbolicLink() || !directoryStat.isDirectory() || !inside2(repo, (0,
|
|
19628
|
+
const directoryStat = (0, import_node_fs6.lstatSync)(directory);
|
|
19629
|
+
if (directoryStat.isSymbolicLink() || !directoryStat.isDirectory() || !inside2(repo, (0, import_node_fs6.realpathSync)(directory)))
|
|
19600
19630
|
throw new Error(`guidance scan directory is unsafe or outside the repository: ${directory}`);
|
|
19601
|
-
for (const item of (0,
|
|
19602
|
-
const path = prefix ? (0,
|
|
19603
|
-
const absolute = (0,
|
|
19604
|
-
const stat = (0,
|
|
19631
|
+
for (const item of (0, import_node_fs6.readdirSync)(directory, { withFileTypes: true })) {
|
|
19632
|
+
const path = prefix ? (0, import_node_path6.join)(prefix, item.name) : item.name;
|
|
19633
|
+
const absolute = (0, import_node_path6.join)(directory, item.name);
|
|
19634
|
+
const stat = (0, import_node_fs6.lstatSync)(absolute);
|
|
19605
19635
|
if (stat.isSymbolicLink()) {
|
|
19606
19636
|
if (AGENT_ENTRY_NAMES.has(item.name)) entries.add(path);
|
|
19607
19637
|
continue;
|
|
19608
19638
|
}
|
|
19609
19639
|
if (stat.isDirectory()) {
|
|
19610
|
-
const adoptionEvidence = item.name === "adoption" && (0,
|
|
19640
|
+
const adoptionEvidence = item.name === "adoption" && (0, import_node_path6.basename)(prefix) === ".agents";
|
|
19611
19641
|
if (ALWAYS_PRUNED_DIRECTORY_NAMES.has(item.name) || adoptionEvidence) continue;
|
|
19612
19642
|
walk(absolute, path);
|
|
19613
19643
|
continue;
|
|
@@ -19627,35 +19657,35 @@ function installPendingSnapshots(repoRoot, pending) {
|
|
|
19627
19657
|
let tempPath = null;
|
|
19628
19658
|
try {
|
|
19629
19659
|
for (const snapshot of pending) {
|
|
19630
|
-
const absolute = (0,
|
|
19631
|
-
ensureNoSymlinkDirectoryChain(repoRoot, (0,
|
|
19632
|
-
tempPath = (0,
|
|
19633
|
-
(0,
|
|
19634
|
-
`.${(0,
|
|
19660
|
+
const absolute = (0, import_node_path6.resolve)(repoRoot, snapshot.relativePath);
|
|
19661
|
+
ensureNoSymlinkDirectoryChain(repoRoot, (0, import_node_path6.dirname)(absolute), `legacy snapshot ${snapshot.relativePath}`, true);
|
|
19662
|
+
tempPath = (0, import_node_path6.join)(
|
|
19663
|
+
(0, import_node_path6.dirname)(absolute),
|
|
19664
|
+
`.${(0, import_node_path6.basename)(absolute)}.harness-kit-adoption-${process.pid}-${(0, import_node_crypto4.randomUUID)()}.tmp`
|
|
19635
19665
|
);
|
|
19636
|
-
const fd = (0,
|
|
19666
|
+
const fd = (0, import_node_fs6.openSync)(
|
|
19637
19667
|
tempPath,
|
|
19638
|
-
|
|
19668
|
+
import_node_fs6.constants.O_WRONLY | import_node_fs6.constants.O_CREAT | import_node_fs6.constants.O_EXCL | import_node_fs6.constants.O_NOFOLLOW,
|
|
19639
19669
|
snapshot.mode & 511
|
|
19640
19670
|
);
|
|
19641
19671
|
try {
|
|
19642
|
-
(0,
|
|
19643
|
-
(0,
|
|
19644
|
-
const stat = (0,
|
|
19672
|
+
(0, import_node_fs6.writeFileSync)(fd, snapshot.bytes);
|
|
19673
|
+
(0, import_node_fs6.fchmodSync)(fd, snapshot.mode);
|
|
19674
|
+
const stat = (0, import_node_fs6.fstatSync)(fd);
|
|
19645
19675
|
if (!stat.isFile()) throw new Error(`staged legacy snapshot is not a regular file: ${snapshot.relativePath}`);
|
|
19646
19676
|
} finally {
|
|
19647
|
-
(0,
|
|
19677
|
+
(0, import_node_fs6.closeSync)(fd);
|
|
19648
19678
|
}
|
|
19649
|
-
(0,
|
|
19679
|
+
(0, import_node_fs6.linkSync)(tempPath, absolute);
|
|
19650
19680
|
installed.push({ absolutePath: absolute });
|
|
19651
|
-
(0,
|
|
19681
|
+
(0, import_node_fs6.unlinkSync)(tempPath);
|
|
19652
19682
|
tempPath = null;
|
|
19653
19683
|
}
|
|
19654
19684
|
return installed;
|
|
19655
19685
|
} catch (error) {
|
|
19656
19686
|
if (tempPath) {
|
|
19657
19687
|
try {
|
|
19658
|
-
(0,
|
|
19688
|
+
(0, import_node_fs6.unlinkSync)(tempPath);
|
|
19659
19689
|
} catch (cleanupError) {
|
|
19660
19690
|
if (!isErrno2(cleanupError, "ENOENT")) {
|
|
19661
19691
|
}
|
|
@@ -19666,7 +19696,7 @@ function installPendingSnapshots(repoRoot, pending) {
|
|
|
19666
19696
|
}
|
|
19667
19697
|
function entryExists(path) {
|
|
19668
19698
|
try {
|
|
19669
|
-
(0,
|
|
19699
|
+
(0, import_node_fs6.lstatSync)(path);
|
|
19670
19700
|
return true;
|
|
19671
19701
|
} catch {
|
|
19672
19702
|
return false;
|
|
@@ -19676,8 +19706,8 @@ function textCanContainReferences(bytes) {
|
|
|
19676
19706
|
return !bytes.includes(0);
|
|
19677
19707
|
}
|
|
19678
19708
|
function isLegacyEntry(repoRoot, path, testHooks) {
|
|
19679
|
-
const absolute = (0,
|
|
19680
|
-
const stat = (0,
|
|
19709
|
+
const absolute = (0, import_node_path6.join)(repoRoot, path);
|
|
19710
|
+
const stat = (0, import_node_fs6.lstatSync)(absolute);
|
|
19681
19711
|
if (stat.isSymbolicLink() || !stat.isFile()) return true;
|
|
19682
19712
|
const source = readOptionalRepositoryFile(
|
|
19683
19713
|
repoRoot,
|
|
@@ -19689,7 +19719,7 @@ function isLegacyEntry(repoRoot, path, testHooks) {
|
|
|
19689
19719
|
return !source.bytes.toString("utf8").startsWith(GENERATED_MARKER);
|
|
19690
19720
|
}
|
|
19691
19721
|
function documentLike(path) {
|
|
19692
|
-
return AGENT_ENTRY_NAMES.has((0,
|
|
19722
|
+
return AGENT_ENTRY_NAMES.has((0, import_node_path6.basename)(path)) || DOCUMENT_EXTENSIONS.has((0, import_node_path6.extname)(path).toLowerCase());
|
|
19693
19723
|
}
|
|
19694
19724
|
function cleanReference(raw) {
|
|
19695
19725
|
let value = raw.trim();
|
|
@@ -19723,15 +19753,15 @@ function explicitReferences(content) {
|
|
|
19723
19753
|
return [...references];
|
|
19724
19754
|
}
|
|
19725
19755
|
function resolveGuidanceReference(repoRoot, sourcePath, reference, testHooks) {
|
|
19726
|
-
const candidates = reference.startsWith("/") ? [(0,
|
|
19756
|
+
const candidates = reference.startsWith("/") ? [(0, import_node_path6.resolve)(repoRoot, reference.slice(1))] : [(0, import_node_path6.resolve)(repoRoot, (0, import_node_path6.dirname)(sourcePath), reference), (0, import_node_path6.resolve)(repoRoot, reference)];
|
|
19727
19757
|
for (const absolute of candidates) {
|
|
19728
19758
|
if (!inside2(repoRoot, absolute) || !entryExists(absolute)) continue;
|
|
19729
19759
|
let stat;
|
|
19730
19760
|
try {
|
|
19731
|
-
const path2 = (0,
|
|
19732
|
-
if (!safeEvidencePath(path2) || !ensureNoSymlinkDirectoryChain(repoRoot, (0,
|
|
19761
|
+
const path2 = (0, import_node_path6.relative)(repoRoot, absolute);
|
|
19762
|
+
if (!safeEvidencePath(path2) || !ensureNoSymlinkDirectoryChain(repoRoot, (0, import_node_path6.dirname)(absolute), `guidance ${path2}`, false))
|
|
19733
19763
|
continue;
|
|
19734
|
-
stat = (0,
|
|
19764
|
+
stat = (0, import_node_fs6.lstatSync)(absolute);
|
|
19735
19765
|
if (!stat.isSymbolicLink() && !stat.isFile()) continue;
|
|
19736
19766
|
if (stat.isFile()) {
|
|
19737
19767
|
const source = readOptionalRepositoryFile(
|
|
@@ -19745,19 +19775,19 @@ function resolveGuidanceReference(repoRoot, sourcePath, reference, testHooks) {
|
|
|
19745
19775
|
} catch {
|
|
19746
19776
|
continue;
|
|
19747
19777
|
}
|
|
19748
|
-
const path = (0,
|
|
19778
|
+
const path = (0, import_node_path6.relative)(repoRoot, absolute);
|
|
19749
19779
|
if (safeEvidencePath(path)) return path;
|
|
19750
19780
|
}
|
|
19751
19781
|
return null;
|
|
19752
19782
|
}
|
|
19753
19783
|
function resolveGuidanceSymlinkTarget(repoRoot, sourcePath, linkTarget, testHooks) {
|
|
19754
|
-
const absolute = (0,
|
|
19784
|
+
const absolute = (0, import_node_path6.isAbsolute)(linkTarget) ? (0, import_node_path6.resolve)(linkTarget) : (0, import_node_path6.resolve)(repoRoot, (0, import_node_path6.dirname)(sourcePath), linkTarget);
|
|
19755
19785
|
if (!inside2(repoRoot, absolute) || !entryExists(absolute)) return null;
|
|
19756
19786
|
try {
|
|
19757
|
-
const path2 = (0,
|
|
19758
|
-
if (!safeEvidencePath(path2) || !ensureNoSymlinkDirectoryChain(repoRoot, (0,
|
|
19787
|
+
const path2 = (0, import_node_path6.relative)(repoRoot, absolute);
|
|
19788
|
+
if (!safeEvidencePath(path2) || !ensureNoSymlinkDirectoryChain(repoRoot, (0, import_node_path6.dirname)(absolute), `guidance ${path2}`, false))
|
|
19759
19789
|
return null;
|
|
19760
|
-
const stat = (0,
|
|
19790
|
+
const stat = (0, import_node_fs6.lstatSync)(absolute);
|
|
19761
19791
|
if (!stat.isSymbolicLink() && !stat.isFile()) return null;
|
|
19762
19792
|
if (stat.isFile()) {
|
|
19763
19793
|
const source = readOptionalRepositoryFile(
|
|
@@ -19771,17 +19801,17 @@ function resolveGuidanceSymlinkTarget(repoRoot, sourcePath, linkTarget, testHook
|
|
|
19771
19801
|
} catch {
|
|
19772
19802
|
return null;
|
|
19773
19803
|
}
|
|
19774
|
-
const path = (0,
|
|
19804
|
+
const path = (0, import_node_path6.relative)(repoRoot, absolute);
|
|
19775
19805
|
return safeEvidencePath(path) ? path : null;
|
|
19776
19806
|
}
|
|
19777
19807
|
function liveGuidanceEvidence(repoRoot, path, testHooks) {
|
|
19778
|
-
const absolute = (0,
|
|
19779
|
-
if (!ensureNoSymlinkDirectoryChain(repoRoot, (0,
|
|
19808
|
+
const absolute = (0, import_node_path6.join)(repoRoot, path);
|
|
19809
|
+
if (!ensureNoSymlinkDirectoryChain(repoRoot, (0, import_node_path6.dirname)(absolute), `guidance ${path}`, false))
|
|
19780
19810
|
throw new Error(`guidance disappeared while it was being inspected: ${path}`);
|
|
19781
|
-
const stat = (0,
|
|
19811
|
+
const stat = (0, import_node_fs6.lstatSync)(absolute);
|
|
19782
19812
|
const mode = permissionMode(stat.mode);
|
|
19783
19813
|
if (stat.isSymbolicLink()) {
|
|
19784
|
-
const linkTarget = (0,
|
|
19814
|
+
const linkTarget = (0, import_node_fs6.readlinkSync)(absolute);
|
|
19785
19815
|
if (!resolveGuidanceSymlinkTarget(repoRoot, path, linkTarget, testHooks))
|
|
19786
19816
|
throw new Error(`guidance symlink cannot be resolved to a safe in-repo text file: ${path}`);
|
|
19787
19817
|
return { path, type: "symlink", mode, linkTarget };
|
|
@@ -19802,13 +19832,13 @@ function discoverGuidance(repo, testHooks = {}) {
|
|
|
19802
19832
|
const all = findAgentEntryPaths(root);
|
|
19803
19833
|
const entryPaths = /* @__PURE__ */ new Set();
|
|
19804
19834
|
for (const path of all) {
|
|
19805
|
-
if (!AGENT_ENTRY_NAMES.has((0,
|
|
19806
|
-
const absolute = (0,
|
|
19835
|
+
if (!AGENT_ENTRY_NAMES.has((0, import_node_path6.basename)(path)) || !safeEvidencePath(path)) continue;
|
|
19836
|
+
const absolute = (0, import_node_path6.join)(root, path);
|
|
19807
19837
|
if (entryExists(absolute) && isLegacyEntry(root, path, testHooks)) entryPaths.add(path);
|
|
19808
19838
|
}
|
|
19809
19839
|
for (const path of MANAGED_ENTRY_PATHS) {
|
|
19810
|
-
if (!AGENT_ENTRY_NAMES.has((0,
|
|
19811
|
-
const absolute = (0,
|
|
19840
|
+
if (!AGENT_ENTRY_NAMES.has((0, import_node_path6.basename)(path))) continue;
|
|
19841
|
+
const absolute = (0, import_node_path6.join)(root, path);
|
|
19812
19842
|
if (entryExists(absolute) && isLegacyEntry(root, path, testHooks)) entryPaths.add(path);
|
|
19813
19843
|
}
|
|
19814
19844
|
const evidence = new Set([...entryPaths].filter((path) => !MANAGED_ENTRY_PATHS.includes(path)));
|
|
@@ -19819,12 +19849,12 @@ function discoverGuidance(repo, testHooks = {}) {
|
|
|
19819
19849
|
const sourcePath = queue.shift();
|
|
19820
19850
|
if (reviewed.has(sourcePath)) continue;
|
|
19821
19851
|
reviewed.add(sourcePath);
|
|
19822
|
-
const absolute = (0,
|
|
19823
|
-
if (!ensureNoSymlinkDirectoryChain(root, (0,
|
|
19852
|
+
const absolute = (0, import_node_path6.join)(root, sourcePath);
|
|
19853
|
+
if (!ensureNoSymlinkDirectoryChain(root, (0, import_node_path6.dirname)(absolute), `guidance ${sourcePath}`, false))
|
|
19824
19854
|
throw new Error(`guidance disappeared while it was being inspected: ${sourcePath}`);
|
|
19825
|
-
const stat = (0,
|
|
19855
|
+
const stat = (0, import_node_fs6.lstatSync)(absolute);
|
|
19826
19856
|
if (stat.isSymbolicLink()) {
|
|
19827
|
-
const target = resolveGuidanceSymlinkTarget(root, sourcePath, (0,
|
|
19857
|
+
const target = resolveGuidanceSymlinkTarget(root, sourcePath, (0, import_node_fs6.readlinkSync)(absolute), testHooks);
|
|
19828
19858
|
if (!target) throw new Error(`guidance symlink cannot be resolved to a safe in-repo text file: ${sourcePath}`);
|
|
19829
19859
|
if (!MANAGED_ENTRY_PATHS.includes(target)) evidence.add(target);
|
|
19830
19860
|
if (!reviewed.has(target) && !queued.has(target)) {
|
|
@@ -19902,17 +19932,17 @@ function errorMessage2(error) {
|
|
|
19902
19932
|
return error instanceof Error ? error.message : String(error);
|
|
19903
19933
|
}
|
|
19904
19934
|
function inside2(root, candidate) {
|
|
19905
|
-
const rel = (0,
|
|
19906
|
-
return rel === "" || rel !== ".." && !rel.startsWith(`..${
|
|
19935
|
+
const rel = (0, import_node_path6.relative)(root, candidate);
|
|
19936
|
+
return rel === "" || rel !== ".." && !rel.startsWith(`..${import_node_path6.sep}`) && !(0, import_node_path6.isAbsolute)(rel);
|
|
19907
19937
|
}
|
|
19908
19938
|
function repositoryRoot2(repo) {
|
|
19909
19939
|
let root;
|
|
19910
19940
|
try {
|
|
19911
|
-
root = (0,
|
|
19941
|
+
root = (0, import_node_fs6.realpathSync)(repo);
|
|
19912
19942
|
} catch (error) {
|
|
19913
19943
|
throw new Error(`cannot resolve repository root ${repo}: ${errorMessage2(error)}`);
|
|
19914
19944
|
}
|
|
19915
|
-
if (!(0,
|
|
19945
|
+
if (!(0, import_node_fs6.statSync)(root).isDirectory()) throw new Error(`repository root is not a directory: ${repo}`);
|
|
19916
19946
|
return root;
|
|
19917
19947
|
}
|
|
19918
19948
|
function canonicalJson(value) {
|
|
@@ -19928,102 +19958,102 @@ function isSha256(value) {
|
|
|
19928
19958
|
return typeof value === "string" && /^[a-f0-9]{64}$/.test(value);
|
|
19929
19959
|
}
|
|
19930
19960
|
function safeRelativePath(path, label) {
|
|
19931
|
-
if (!path || path.includes("\0") || (0,
|
|
19932
|
-
const normalized = (0,
|
|
19933
|
-
if (normalized === "." || normalized === ".." || normalized.startsWith(`..${
|
|
19961
|
+
if (!path || path.includes("\0") || (0, import_node_path6.isAbsolute)(path)) throw new Error(`${label} path is unsafe: ${path}`);
|
|
19962
|
+
const normalized = (0, import_node_path6.normalize)(path);
|
|
19963
|
+
if (normalized === "." || normalized === ".." || normalized.startsWith(`..${import_node_path6.sep}`))
|
|
19934
19964
|
throw new Error(`${label} path escapes its bundle: ${path}`);
|
|
19935
19965
|
return normalized;
|
|
19936
19966
|
}
|
|
19937
19967
|
function existingAncestor(path) {
|
|
19938
19968
|
const suffix = [];
|
|
19939
19969
|
let cursor = path;
|
|
19940
|
-
while (!(0,
|
|
19941
|
-
const parent = (0,
|
|
19970
|
+
while (!(0, import_node_fs6.existsSync)(cursor)) {
|
|
19971
|
+
const parent = (0, import_node_path6.dirname)(cursor);
|
|
19942
19972
|
if (parent === cursor) throw new Error(`cannot resolve destination parent: ${path}`);
|
|
19943
|
-
suffix.unshift(cursor.slice(parent.length + (parent.endsWith(
|
|
19973
|
+
suffix.unshift(cursor.slice(parent.length + (parent.endsWith(import_node_path6.sep) ? 0 : 1)));
|
|
19944
19974
|
cursor = parent;
|
|
19945
19975
|
}
|
|
19946
19976
|
return { ancestor: cursor, suffix };
|
|
19947
19977
|
}
|
|
19948
19978
|
function prospectiveRealPath(path) {
|
|
19949
19979
|
const { ancestor, suffix } = existingAncestor(path);
|
|
19950
|
-
const stat = (0,
|
|
19980
|
+
const stat = (0, import_node_fs6.lstatSync)(ancestor);
|
|
19951
19981
|
if (!stat.isDirectory() && !stat.isSymbolicLink()) throw new Error(`destination parent is not a directory: ${ancestor}`);
|
|
19952
|
-
const resolvedAncestor = (0,
|
|
19953
|
-
if (!(0,
|
|
19954
|
-
return (0,
|
|
19982
|
+
const resolvedAncestor = (0, import_node_fs6.realpathSync)(ancestor);
|
|
19983
|
+
if (!(0, import_node_fs6.statSync)(resolvedAncestor).isDirectory()) throw new Error(`destination parent is not a directory: ${ancestor}`);
|
|
19984
|
+
return (0, import_node_path6.resolve)(resolvedAncestor, ...suffix);
|
|
19955
19985
|
}
|
|
19956
19986
|
function assertExternalPath(repoRoot, requestedPath, label) {
|
|
19957
|
-
const absolute = (0,
|
|
19958
|
-
const resolved = (0,
|
|
19987
|
+
const absolute = (0, import_node_path6.resolve)(requestedPath);
|
|
19988
|
+
const resolved = (0, import_node_fs6.existsSync)(absolute) ? (0, import_node_fs6.realpathSync)(absolute) : prospectiveRealPath(absolute);
|
|
19959
19989
|
if (inside2(repoRoot, resolved)) throw new Error(`${label} must be outside the repository: ${absolute}`);
|
|
19960
19990
|
return resolved;
|
|
19961
19991
|
}
|
|
19962
19992
|
function prepareEmptyExternalDirectory(repoRoot, outputDir) {
|
|
19963
|
-
const absolute = (0,
|
|
19964
|
-
if ((0,
|
|
19965
|
-
const stat2 = (0,
|
|
19993
|
+
const absolute = (0, import_node_path6.resolve)(outputDir);
|
|
19994
|
+
if ((0, import_node_fs6.existsSync)(absolute)) {
|
|
19995
|
+
const stat2 = (0, import_node_fs6.lstatSync)(absolute);
|
|
19966
19996
|
if (stat2.isSymbolicLink()) throw new Error(`candidate output must not be a symlink: ${absolute}`);
|
|
19967
19997
|
if (!stat2.isDirectory()) throw new Error(`candidate output must be a directory: ${absolute}`);
|
|
19968
|
-
if ((0,
|
|
19998
|
+
if ((0, import_node_fs6.readdirSync)(absolute).length > 0) throw new Error(`candidate output must be empty: ${absolute}`);
|
|
19969
19999
|
}
|
|
19970
20000
|
const expected = assertExternalPath(repoRoot, absolute, "candidate output");
|
|
19971
|
-
if (!(0,
|
|
19972
|
-
const stat = (0,
|
|
20001
|
+
if (!(0, import_node_fs6.existsSync)(absolute)) (0, import_node_fs6.mkdirSync)(absolute, { recursive: true, mode: 448 });
|
|
20002
|
+
const stat = (0, import_node_fs6.lstatSync)(absolute);
|
|
19973
20003
|
if (stat.isSymbolicLink() || !stat.isDirectory()) throw new Error(`candidate output is unsafe: ${absolute}`);
|
|
19974
|
-
const actual = (0,
|
|
20004
|
+
const actual = (0, import_node_fs6.realpathSync)(absolute);
|
|
19975
20005
|
if (actual !== expected || inside2(repoRoot, actual)) throw new Error(`candidate output changed or escaped: ${absolute}`);
|
|
19976
|
-
(0,
|
|
20006
|
+
(0, import_node_fs6.chmodSync)(actual, 448);
|
|
19977
20007
|
return actual;
|
|
19978
20008
|
}
|
|
19979
20009
|
function ensurePrivateDirectory(bundleRoot, directory) {
|
|
19980
|
-
const rel = (0,
|
|
19981
|
-
if (rel === ".." || rel.startsWith(`..${
|
|
20010
|
+
const rel = (0, import_node_path6.relative)(bundleRoot, directory);
|
|
20011
|
+
if (rel === ".." || rel.startsWith(`..${import_node_path6.sep}`) || (0, import_node_path6.isAbsolute)(rel)) throw new Error(`bundle directory escapes: ${directory}`);
|
|
19982
20012
|
let cursor = bundleRoot;
|
|
19983
|
-
for (const component of rel.split(
|
|
19984
|
-
cursor = (0,
|
|
19985
|
-
if (!(0,
|
|
19986
|
-
const stat = (0,
|
|
20013
|
+
for (const component of rel.split(import_node_path6.sep).filter(Boolean)) {
|
|
20014
|
+
cursor = (0, import_node_path6.join)(cursor, component);
|
|
20015
|
+
if (!(0, import_node_fs6.existsSync)(cursor)) (0, import_node_fs6.mkdirSync)(cursor, { mode: 448 });
|
|
20016
|
+
const stat = (0, import_node_fs6.lstatSync)(cursor);
|
|
19987
20017
|
if (stat.isSymbolicLink() || !stat.isDirectory()) throw new Error(`bundle directory is unsafe: ${cursor}`);
|
|
19988
|
-
(0,
|
|
20018
|
+
(0, import_node_fs6.chmodSync)(cursor, 448);
|
|
19989
20019
|
}
|
|
19990
20020
|
}
|
|
19991
20021
|
function bundleFilePath(bundleRoot, relativePath) {
|
|
19992
20022
|
const normalized = safeRelativePath(relativePath, "bundle artifact");
|
|
19993
|
-
const absolute = (0,
|
|
20023
|
+
const absolute = (0, import_node_path6.resolve)(bundleRoot, normalized);
|
|
19994
20024
|
if (!inside2(bundleRoot, absolute) || absolute === bundleRoot) throw new Error(`bundle artifact escapes: ${relativePath}`);
|
|
19995
20025
|
return absolute;
|
|
19996
20026
|
}
|
|
19997
20027
|
function privateWriteBundleFile(bundleRoot, relativePath, content) {
|
|
19998
20028
|
const absolute = bundleFilePath(bundleRoot, relativePath);
|
|
19999
|
-
ensurePrivateDirectory(bundleRoot, (0,
|
|
20000
|
-
(0,
|
|
20001
|
-
(0,
|
|
20029
|
+
ensurePrivateDirectory(bundleRoot, (0, import_node_path6.dirname)(absolute));
|
|
20030
|
+
(0, import_node_fs6.writeFileSync)(absolute, content, { flag: "wx", mode: 384 });
|
|
20031
|
+
(0, import_node_fs6.chmodSync)(absolute, 384);
|
|
20002
20032
|
return absolute;
|
|
20003
20033
|
}
|
|
20004
20034
|
function readRegularFile(path, label) {
|
|
20005
20035
|
let stat;
|
|
20006
20036
|
try {
|
|
20007
|
-
stat = (0,
|
|
20037
|
+
stat = (0, import_node_fs6.lstatSync)(path);
|
|
20008
20038
|
} catch (error) {
|
|
20009
20039
|
throw new Error(`${label} is missing or unreadable at ${path}: ${errorMessage2(error)}`);
|
|
20010
20040
|
}
|
|
20011
20041
|
if (stat.isSymbolicLink() || !stat.isFile()) throw new Error(`${label} must be a regular file: ${path}`);
|
|
20012
|
-
const fd = (0,
|
|
20042
|
+
const fd = (0, import_node_fs6.openSync)(path, import_node_fs6.constants.O_RDONLY | import_node_fs6.constants.O_NOFOLLOW);
|
|
20013
20043
|
try {
|
|
20014
|
-
if (!(0,
|
|
20015
|
-
return (0,
|
|
20044
|
+
if (!(0, import_node_fs6.fstatSync)(fd).isFile()) throw new Error(`${label} must be a regular file: ${path}`);
|
|
20045
|
+
return (0, import_node_fs6.readFileSync)(fd);
|
|
20016
20046
|
} finally {
|
|
20017
|
-
(0,
|
|
20047
|
+
(0, import_node_fs6.closeSync)(fd);
|
|
20018
20048
|
}
|
|
20019
20049
|
}
|
|
20020
20050
|
function readBundleFile(bundleRoot, relativePath, label) {
|
|
20021
20051
|
const absolute = bundleFilePath(bundleRoot, relativePath);
|
|
20022
|
-
const parentRel = (0,
|
|
20052
|
+
const parentRel = (0, import_node_path6.relative)(bundleRoot, (0, import_node_path6.dirname)(absolute));
|
|
20023
20053
|
let cursor = bundleRoot;
|
|
20024
|
-
for (const component of parentRel.split(
|
|
20025
|
-
cursor = (0,
|
|
20026
|
-
const stat = (0,
|
|
20054
|
+
for (const component of parentRel.split(import_node_path6.sep).filter(Boolean)) {
|
|
20055
|
+
cursor = (0, import_node_path6.join)(cursor, component);
|
|
20056
|
+
const stat = (0, import_node_fs6.lstatSync)(cursor);
|
|
20027
20057
|
if (stat.isSymbolicLink() || !stat.isDirectory()) throw new Error(`${label} parent is unsafe: ${cursor}`);
|
|
20028
20058
|
}
|
|
20029
20059
|
return readRegularFile(absolute, label);
|
|
@@ -20039,15 +20069,15 @@ function parseJsonRecord(bytes, label) {
|
|
|
20039
20069
|
return value;
|
|
20040
20070
|
}
|
|
20041
20071
|
function readLiveIndexBytes(repoRoot) {
|
|
20042
|
-
const bytes = readRegularFile((0,
|
|
20072
|
+
const bytes = readRegularFile((0, import_node_path6.join)(repoRoot, INDEX_REL), "legacy adoption index");
|
|
20043
20073
|
if (!readAdoptionIndex(repoRoot)) throw new Error(`${INDEX_REL} is required before preparing an adoption candidate`);
|
|
20044
20074
|
return bytes;
|
|
20045
20075
|
}
|
|
20046
20076
|
function legacyEvidenceArtifact(entry) {
|
|
20047
|
-
return entry.type === "file" ? (0,
|
|
20077
|
+
return entry.type === "file" ? (0, import_node_path6.join)("legacy", snapshotName(entry.path)) : (0, import_node_path6.join)("legacy", `${sha256(entry.path)}.symlink.json`);
|
|
20048
20078
|
}
|
|
20049
20079
|
function guidanceEvidenceArtifact(evidence) {
|
|
20050
|
-
return (0,
|
|
20080
|
+
return (0, import_node_path6.join)("guidance", `${sha256(evidence.path)}.${evidence.type === "file" ? "document" : "symlink.json"}`);
|
|
20051
20081
|
}
|
|
20052
20082
|
function guidanceEvidenceBytes(evidence) {
|
|
20053
20083
|
if (evidence.type === "file") return evidence.bytes;
|
|
@@ -20114,11 +20144,11 @@ function validateCandidateMetadata(value) {
|
|
|
20114
20144
|
return metadata;
|
|
20115
20145
|
}
|
|
20116
20146
|
function readCandidateBundle(repoRoot, candidateDir) {
|
|
20117
|
-
const requested = (0,
|
|
20118
|
-
if (!(0,
|
|
20119
|
-
const stat = (0,
|
|
20147
|
+
const requested = (0, import_node_path6.resolve)(candidateDir);
|
|
20148
|
+
if (!(0, import_node_fs6.existsSync)(requested)) throw new Error(`candidate bundle is missing: ${requested}`);
|
|
20149
|
+
const stat = (0, import_node_fs6.lstatSync)(requested);
|
|
20120
20150
|
if (stat.isSymbolicLink() || !stat.isDirectory()) throw new Error(`candidate bundle must be a regular directory: ${requested}`);
|
|
20121
|
-
const root = (0,
|
|
20151
|
+
const root = (0, import_node_fs6.realpathSync)(requested);
|
|
20122
20152
|
if (inside2(repoRoot, root)) throw new Error(`candidate bundle must be outside the repository: ${requested}`);
|
|
20123
20153
|
const metadata = validateCandidateMetadata(parseJsonRecord(readBundleFile(root, CANDIDATE_METADATA, "candidate metadata"), "candidate metadata"));
|
|
20124
20154
|
const artifacts = [
|
|
@@ -20149,17 +20179,17 @@ function prepareAdoptionCandidate(repo, outputDir, testHooks = {}) {
|
|
|
20149
20179
|
if (invalidLegacy) throw new Error(`legacy evidence is stale for ${invalidLegacy.path}; prepare refused`);
|
|
20150
20180
|
const liveGuidance = discoverGuidance(repoRoot, testHooks);
|
|
20151
20181
|
const root = prepareEmptyExternalDirectory(repoRoot, outputDir);
|
|
20152
|
-
const manifestBytes = readRegularFile((0,
|
|
20182
|
+
const manifestBytes = readRegularFile((0, import_node_path6.join)(repoRoot, MANIFEST_REL), "manifest");
|
|
20153
20183
|
const indexBytes = readLiveIndexBytes(repoRoot);
|
|
20154
|
-
const manifestArtifact = (0,
|
|
20155
|
-
const indexArtifact = (0,
|
|
20184
|
+
const manifestArtifact = (0, import_node_path6.join)("source", "manifest.yaml");
|
|
20185
|
+
const indexArtifact = (0, import_node_path6.join)("source", "legacy-index.json");
|
|
20156
20186
|
privateWriteBundleFile(root, manifestArtifact, manifestBytes);
|
|
20157
20187
|
privateWriteBundleFile(root, indexArtifact, indexBytes);
|
|
20158
20188
|
const legacy = [];
|
|
20159
20189
|
for (const entry of index.entries) {
|
|
20160
20190
|
const artifact = legacyEvidenceArtifact(entry);
|
|
20161
20191
|
if (entry.type === "file") {
|
|
20162
|
-
const snapshot = readRegularFile((0,
|
|
20192
|
+
const snapshot = readRegularFile((0, import_node_path6.join)(repoRoot, entry.snapshot), `legacy snapshot ${entry.path}`);
|
|
20163
20193
|
privateWriteBundleFile(root, artifact, snapshot);
|
|
20164
20194
|
legacy.push({
|
|
20165
20195
|
path: entry.path,
|
|
@@ -20196,8 +20226,8 @@ function prepareAdoptionCandidate(repo, outputDir, testHooks = {}) {
|
|
|
20196
20226
|
});
|
|
20197
20227
|
}
|
|
20198
20228
|
const targets = [];
|
|
20199
|
-
for (const [path, content] of renderTargets(manifest)) {
|
|
20200
|
-
const artifact = (0,
|
|
20229
|
+
for (const [path, content] of renderTargets(manifest, { harnessVersion: lockedHarnessVersion(repoRoot) })) {
|
|
20230
|
+
const artifact = (0, import_node_path6.join)("generated", path);
|
|
20201
20231
|
const bytes = Buffer.from(content, "utf8");
|
|
20202
20232
|
privateWriteBundleFile(root, artifact, bytes);
|
|
20203
20233
|
targets.push({ path, artifact, sha256: sha256(bytes) });
|
|
@@ -20219,15 +20249,15 @@ function prepareAdoptionCandidate(repo, outputDir, testHooks = {}) {
|
|
|
20219
20249
|
return metadata;
|
|
20220
20250
|
}
|
|
20221
20251
|
function externalReceiptPath(repoRoot, candidateRoot, requested) {
|
|
20222
|
-
const absolute = (0,
|
|
20223
|
-
const parent = (0,
|
|
20224
|
-
if (!(0,
|
|
20225
|
-
const parentStat = (0,
|
|
20252
|
+
const absolute = (0, import_node_path6.resolve)(requested ?? (0, import_node_path6.join)(candidateRoot, RECEIPT_DEFAULT));
|
|
20253
|
+
const parent = (0, import_node_path6.dirname)(absolute);
|
|
20254
|
+
if (!(0, import_node_fs6.existsSync)(parent)) throw new Error(`receipt parent must already exist: ${parent}`);
|
|
20255
|
+
const parentStat = (0, import_node_fs6.lstatSync)(parent);
|
|
20226
20256
|
if (parentStat.isSymbolicLink() || !parentStat.isDirectory()) throw new Error(`receipt parent is unsafe: ${parent}`);
|
|
20227
|
-
const resolvedParent = (0,
|
|
20228
|
-
const resolved = (0,
|
|
20257
|
+
const resolvedParent = (0, import_node_fs6.realpathSync)(parent);
|
|
20258
|
+
const resolved = (0, import_node_path6.join)(resolvedParent, (0, import_node_path6.relative)(parent, absolute));
|
|
20229
20259
|
if (inside2(repoRoot, resolved)) throw new Error(`receipt must be outside the repository: ${absolute}`);
|
|
20230
|
-
if ((0,
|
|
20260
|
+
if ((0, import_node_fs6.existsSync)(absolute)) throw new Error(`receipt already exists: ${absolute}`);
|
|
20231
20261
|
return resolved;
|
|
20232
20262
|
}
|
|
20233
20263
|
function recordAdoptionAudit(repo, candidateDir, options) {
|
|
@@ -20236,9 +20266,9 @@ function recordAdoptionAudit(repo, candidateDir, options) {
|
|
|
20236
20266
|
const reason = options.reason?.trim();
|
|
20237
20267
|
if (!reason) throw new Error("audit reason must not be empty");
|
|
20238
20268
|
const candidate = readCandidateBundle(repoRoot, candidateDir);
|
|
20239
|
-
const reportRequested = (0,
|
|
20269
|
+
const reportRequested = (0, import_node_path6.resolve)(options.reportPath);
|
|
20240
20270
|
const reportBytes = readRegularFile(reportRequested, "audit report");
|
|
20241
|
-
const reportPath = (0,
|
|
20271
|
+
const reportPath = (0, import_node_fs6.realpathSync)(reportRequested);
|
|
20242
20272
|
const receiptPath = externalReceiptPath(repoRoot, candidate.root, options.receiptPath);
|
|
20243
20273
|
const receipt = {
|
|
20244
20274
|
schema: ADOPTION_RECEIPT_SCHEMA,
|
|
@@ -20251,20 +20281,20 @@ function recordAdoptionAudit(repo, candidateDir, options) {
|
|
|
20251
20281
|
assurance: "declared",
|
|
20252
20282
|
independence: "unverified"
|
|
20253
20283
|
};
|
|
20254
|
-
(0,
|
|
20255
|
-
(0,
|
|
20284
|
+
(0, import_node_fs6.writeFileSync)(receiptPath, canonicalJson(receipt) + "\n", { flag: "wx", mode: 384 });
|
|
20285
|
+
(0, import_node_fs6.chmodSync)(receiptPath, 384);
|
|
20256
20286
|
return { receipt, receiptPath };
|
|
20257
20287
|
}
|
|
20258
20288
|
function readReceipt(repoRoot, receiptPath) {
|
|
20259
|
-
const requested = (0,
|
|
20289
|
+
const requested = (0, import_node_path6.resolve)(receiptPath);
|
|
20260
20290
|
const resolved = assertExternalPath(repoRoot, requested, "receipt");
|
|
20261
|
-
if (resolved !== (0,
|
|
20291
|
+
if (resolved !== (0, import_node_fs6.realpathSync)(requested)) throw new Error(`receipt path changed: ${requested}`);
|
|
20262
20292
|
const value = parseJsonRecord(readRegularFile(requested, "adoption audit receipt"), "adoption audit receipt");
|
|
20263
20293
|
if (value.schema !== ADOPTION_RECEIPT_SCHEMA || !isSha256(value.candidateHash) || typeof value.candidatePath !== "string" || value.verdict !== "pass" && value.verdict !== "fail" || typeof value.reason !== "string" || !value.reason.trim() || typeof value.recordedAt !== "string" || value.assurance !== "declared" || value.independence !== "unverified" || !value.report || typeof value.report !== "object" || Array.isArray(value.report)) {
|
|
20264
20294
|
throw new Error(`adoption audit receipt format is invalid: ${requested}`);
|
|
20265
20295
|
}
|
|
20266
20296
|
const report = value.report;
|
|
20267
|
-
if (typeof report.path !== "string" || !(0,
|
|
20297
|
+
if (typeof report.path !== "string" || !(0, import_node_path6.isAbsolute)(report.path) || !isSha256(report.sha256))
|
|
20268
20298
|
throw new Error(`adoption audit receipt report binding is invalid: ${requested}`);
|
|
20269
20299
|
return value;
|
|
20270
20300
|
}
|
|
@@ -20298,7 +20328,7 @@ function assertManagedFileAdoptionReceipt(repo, inspections, candidateDir, recei
|
|
|
20298
20328
|
if (entry.type !== evidence.type) throw new Error(`candidate legacy type changed for ${entry.path}`);
|
|
20299
20329
|
const artifact = readBundleFile(candidate.root, evidence.artifact, `legacy evidence ${entry.path}`);
|
|
20300
20330
|
if (entry.type === "file") {
|
|
20301
|
-
const liveSnapshot = readRegularFile((0,
|
|
20331
|
+
const liveSnapshot = readRegularFile((0, import_node_path6.join)(repoRoot, entry.snapshot), `legacy snapshot ${entry.path}`);
|
|
20302
20332
|
if (evidence.sourceSha256 !== entry.sha256 || evidence.mode !== entry.mode || !artifact.equals(liveSnapshot))
|
|
20303
20333
|
throw new Error(`candidate legacy bytes or mode changed for ${entry.path}`);
|
|
20304
20334
|
} else {
|
|
@@ -20322,18 +20352,18 @@ function assertManagedFileAdoptionReceipt(repo, inspections, candidateDir, recei
|
|
|
20322
20352
|
if (receipt.candidatePath !== candidate.root || receipt.candidateHash !== metadata.candidateHash)
|
|
20323
20353
|
throw new Error(`receipt does not bind candidate ${metadata.candidateHash}`);
|
|
20324
20354
|
if (receipt.verdict !== "pass") throw new Error(`adoption audit verdict is ${receipt.verdict}; pass is required`);
|
|
20325
|
-
const reportPath = (0,
|
|
20326
|
-
if ((0,
|
|
20355
|
+
const reportPath = (0, import_node_path6.resolve)(receipt.report.path);
|
|
20356
|
+
if ((0, import_node_fs6.realpathSync)(reportPath) !== receipt.report.path) throw new Error(`audit report path changed: ${reportPath}`);
|
|
20327
20357
|
if (sha256(readRegularFile(reportPath, "audit report")) !== receipt.report.sha256)
|
|
20328
20358
|
throw new Error(`audit report hash mismatch: ${receipt.report.sha256}`);
|
|
20329
|
-
const manifestBytes = readRegularFile((0,
|
|
20359
|
+
const manifestBytes = readRegularFile((0, import_node_path6.join)(repoRoot, MANIFEST_REL), "manifest");
|
|
20330
20360
|
if (metadata.source.manifest.sha256 !== sha256(manifestBytes)) throw new Error("manifest changed after candidate preparation");
|
|
20331
20361
|
if (!readBundleFile(candidate.root, metadata.source.manifest.artifact, "candidate manifest").equals(manifestBytes))
|
|
20332
20362
|
throw new Error("candidate manifest no longer matches the live manifest");
|
|
20333
20363
|
const manifest = loadManifest(repoRoot);
|
|
20334
20364
|
const errors = validateManifest(manifest).filter((issue) => issue.level === "error");
|
|
20335
20365
|
if (errors.length) throw new Error(`manifest invalid: ${errors.map((issue) => issue.msg).join("; ")}`);
|
|
20336
|
-
const rendered = renderTargets(manifest);
|
|
20366
|
+
const rendered = renderTargets(manifest, { harnessVersion: lockedHarnessVersion(repoRoot) });
|
|
20337
20367
|
if (!samePathList(metadata.targets.map((target) => target.path), rendered.map(([path]) => path)))
|
|
20338
20368
|
throw new Error("current render target list differs from the audited candidate");
|
|
20339
20369
|
if (!samePathList(inspections.map((inspection) => inspection.relativePath), rendered.map(([path]) => path)))
|
|
@@ -20362,8 +20392,8 @@ var import_yaml2 = __toESM(require_dist(), 1);
|
|
|
20362
20392
|
// src/git.ts
|
|
20363
20393
|
var import_node_child_process3 = require("node:child_process");
|
|
20364
20394
|
var import_node_crypto5 = require("node:crypto");
|
|
20365
|
-
var
|
|
20366
|
-
var
|
|
20395
|
+
var import_node_fs7 = require("node:fs");
|
|
20396
|
+
var import_node_path7 = require("node:path");
|
|
20367
20397
|
var GitDiffError = class extends Error {
|
|
20368
20398
|
constructor(kind, message) {
|
|
20369
20399
|
super(message);
|
|
@@ -20451,17 +20481,17 @@ function nulList(raw) {
|
|
|
20451
20481
|
}
|
|
20452
20482
|
function canonicalPath(path) {
|
|
20453
20483
|
try {
|
|
20454
|
-
return (0,
|
|
20484
|
+
return (0, import_node_fs7.realpathSync)(path);
|
|
20455
20485
|
} catch {
|
|
20456
|
-
return (0,
|
|
20486
|
+
return (0, import_node_path7.resolve)(path);
|
|
20457
20487
|
}
|
|
20458
20488
|
}
|
|
20459
20489
|
function targetPrefix(root, target) {
|
|
20460
|
-
const native = (0,
|
|
20490
|
+
const native = (0, import_node_path7.relative)(root, target);
|
|
20461
20491
|
if (!native) return "";
|
|
20462
|
-
if ((0,
|
|
20492
|
+
if ((0, import_node_path7.isAbsolute)(native) || native === ".." || native.startsWith(`..${import_node_path7.sep}`))
|
|
20463
20493
|
throw new GitDiffError("not-a-repo", `target is outside its Git worktree: ${target}`);
|
|
20464
|
-
return native.split(
|
|
20494
|
+
return native.split(import_node_path7.sep).join("/");
|
|
20465
20495
|
}
|
|
20466
20496
|
function scopeEntries(entries, prefix) {
|
|
20467
20497
|
if (!prefix) return entries;
|
|
@@ -20469,10 +20499,10 @@ function scopeEntries(entries, prefix) {
|
|
|
20469
20499
|
return entries.filter((entry) => entry.path.startsWith(start)).map((entry) => ({ ...entry, path: entry.path.slice(start.length) }));
|
|
20470
20500
|
}
|
|
20471
20501
|
function digestPath(repo, rel) {
|
|
20472
|
-
const abs = (0,
|
|
20502
|
+
const abs = (0, import_node_path7.join)(repo, rel);
|
|
20473
20503
|
try {
|
|
20474
|
-
const stat = (0,
|
|
20475
|
-
if (stat.isSymbolicLink()) return `symlink:${(0,
|
|
20504
|
+
const stat = (0, import_node_fs7.lstatSync)(abs);
|
|
20505
|
+
if (stat.isSymbolicLink()) return `symlink:${(0, import_node_fs7.readlinkSync)(abs)}`;
|
|
20476
20506
|
if (stat.isDirectory()) {
|
|
20477
20507
|
try {
|
|
20478
20508
|
const head = (0, import_node_child_process3.execFileSync)("git", ["-C", abs, "rev-parse", "--verify", "HEAD"], {
|
|
@@ -20487,7 +20517,7 @@ function digestPath(repo, rel) {
|
|
|
20487
20517
|
}
|
|
20488
20518
|
if (!stat.isFile()) return `other:${stat.mode}`;
|
|
20489
20519
|
const gitMode = stat.mode & 73 ? "100755" : "100644";
|
|
20490
|
-
return `file:${gitMode}:${(0, import_node_crypto5.createHash)("sha256").update((0,
|
|
20520
|
+
return `file:${gitMode}:${(0, import_node_crypto5.createHash)("sha256").update((0, import_node_fs7.readFileSync)(abs)).digest("hex")}`;
|
|
20491
20521
|
} catch {
|
|
20492
20522
|
return "(missing)";
|
|
20493
20523
|
}
|
|
@@ -20563,9 +20593,22 @@ function collectChanges(repoInput, base = "HEAD", opts = {}) {
|
|
|
20563
20593
|
fingerprint: fingerprint(target, resolvedBase, entries)
|
|
20564
20594
|
};
|
|
20565
20595
|
}
|
|
20596
|
+
function readFileAtCommit(repoInput, commit, rel) {
|
|
20597
|
+
const target = canonicalPath(repoInput);
|
|
20598
|
+
const root = canonicalPath(gitRoot(target));
|
|
20599
|
+
const prefix = targetPrefix(root, target);
|
|
20600
|
+
const path = prefix ? `${prefix}/${rel}` : rel;
|
|
20601
|
+
const entry = git(root, ["--literal-pathspecs", "ls-tree", "-z", "--full-tree", commit, "--", path]);
|
|
20602
|
+
const match = /^\d+ (\w+) ([0-9a-f]+)\t/.exec(entry);
|
|
20603
|
+
if (!match || match[1] !== "blob") return null;
|
|
20604
|
+
return git(root, ["cat-file", "blob", match[2]]);
|
|
20605
|
+
}
|
|
20606
|
+
function listWorktreeFiles(dir, glob) {
|
|
20607
|
+
return nulList(git(dir, ["ls-files", "-z", "--cached", "--others", "--exclude-standard", "--", `:(glob)${glob}`]));
|
|
20608
|
+
}
|
|
20566
20609
|
|
|
20567
20610
|
// src/upgrade.ts
|
|
20568
|
-
var UPGRADE_STATE_REL =
|
|
20611
|
+
var UPGRADE_STATE_REL = HARNESS_LOCK_REL;
|
|
20569
20612
|
var UPGRADE_STATE_SCHEMA = "ai-harness/upgrade-state/v1";
|
|
20570
20613
|
var UPGRADE_REPORT_SCHEMA = "ai-harness/upgrade-report/v1";
|
|
20571
20614
|
var UPGRADE_MIGRATIONS = [
|
|
@@ -20730,15 +20773,16 @@ function internalUpgrade(repo, options) {
|
|
|
20730
20773
|
};
|
|
20731
20774
|
const manifestChanged = migratedManifestContent !== normalizedSource;
|
|
20732
20775
|
const finalManifestContent = manifestChanged ? migratedManifestContent : manifestInspection.currentContent;
|
|
20776
|
+
const generated = renderTargets(finalManifest, { harnessVersion: nextState.version });
|
|
20733
20777
|
const targets = [
|
|
20734
20778
|
// Keep an unchanged manifest in the transaction preflight so generated
|
|
20735
20779
|
// files can never be committed from bytes that changed after planning.
|
|
20736
20780
|
[MANIFEST_REL, finalManifestContent],
|
|
20737
|
-
...
|
|
20781
|
+
...generated,
|
|
20738
20782
|
[UPGRADE_STATE_REL, renderState(nextState)]
|
|
20739
20783
|
];
|
|
20740
20784
|
const preflight = inspectManagedFiles(repo, targets);
|
|
20741
|
-
const generatedPaths = new Set(
|
|
20785
|
+
const generatedPaths = new Set(generated.map(([path]) => path));
|
|
20742
20786
|
try {
|
|
20743
20787
|
assertManagedFileAdoption(
|
|
20744
20788
|
repo,
|
|
@@ -20907,7 +20951,12 @@ function syncCmd(repo, opts = {}) {
|
|
|
20907
20951
|
const errors = validateManifest(m).filter((issue) => issue.level === "error");
|
|
20908
20952
|
if (errors.length) throw new Error(`manifest invalid: ${errors.map((issue) => issue.msg).join("; ")}`);
|
|
20909
20953
|
info("Syncing generated files from .agents/manifest.yaml ...");
|
|
20910
|
-
const
|
|
20954
|
+
const harnessVersion = lockedHarnessVersion(repo);
|
|
20955
|
+
if (harnessVersion && harnessVersion !== package_default.version)
|
|
20956
|
+
warn(
|
|
20957
|
+
`running harness-kit ${package_default.version} but ${HARNESS_LOCK_REL} pins ${harnessVersion}; generated entries keep pinning ${harnessVersion}. Use \`upgrade\` to move the repository to this version.`
|
|
20958
|
+
);
|
|
20959
|
+
const targets = renderTargets(m, { harnessVersion });
|
|
20911
20960
|
if (!!opts.adoptionCandidate !== !!opts.adoptionAudit)
|
|
20912
20961
|
throw new Error("adoption requires both --candidate <bundle> and --audit <receipt>");
|
|
20913
20962
|
if ((opts.adoptionCandidate || opts.adoptionAudit) && !opts.adoptExisting)
|
|
@@ -20933,8 +20982,8 @@ function syncCmd(repo, opts = {}) {
|
|
|
20933
20982
|
|
|
20934
20983
|
// src/commands/doctor.ts
|
|
20935
20984
|
var import_fast_glob3 = __toESM(require_out4(), 1);
|
|
20936
|
-
var
|
|
20937
|
-
var
|
|
20985
|
+
var import_node_fs13 = require("node:fs");
|
|
20986
|
+
var import_node_path13 = require("node:path");
|
|
20938
20987
|
|
|
20939
20988
|
// src/guidance.ts
|
|
20940
20989
|
function gap(kind, scope, classification, title, reason, when, legacyText) {
|
|
@@ -21015,7 +21064,7 @@ function declaredVerificationGaps(manifest) {
|
|
|
21015
21064
|
}
|
|
21016
21065
|
return gaps;
|
|
21017
21066
|
}
|
|
21018
|
-
function automationAction(gaps) {
|
|
21067
|
+
function automationAction(gaps, cli) {
|
|
21019
21068
|
const recommended = gaps.filter((item) => item.classification === "recommended");
|
|
21020
21069
|
if (!recommended.length) return null;
|
|
21021
21070
|
return {
|
|
@@ -21025,7 +21074,7 @@ function automationAction(gaps) {
|
|
|
21025
21074
|
when: "harness-maintenance",
|
|
21026
21075
|
title: `Improve ${recommended.length} verification declaration(s)`,
|
|
21027
21076
|
reason: "These declarations have no executable check or complete manual procedure. They do not invalidate this run, but they weaken future coverage.",
|
|
21028
|
-
commands: [
|
|
21077
|
+
commands: [`${cli} verify --repo . --details`],
|
|
21029
21078
|
completion: "Each declaration has a real enforcement/check, or an explicit manual procedure when automation is genuinely impossible."
|
|
21030
21079
|
};
|
|
21031
21080
|
}
|
|
@@ -21037,7 +21086,7 @@ function unsafeHookIssue(issue) {
|
|
|
21037
21086
|
issue
|
|
21038
21087
|
);
|
|
21039
21088
|
}
|
|
21040
|
-
function hookActions(hooks) {
|
|
21089
|
+
function hookActions(hooks, cli) {
|
|
21041
21090
|
if (hooks.state === "active") return [];
|
|
21042
21091
|
const configured = hooks.configuredAgents.join(",");
|
|
21043
21092
|
const unsafe = hooks.issues.filter(unsafeHookIssue);
|
|
@@ -21061,7 +21110,7 @@ function hookActions(hooks) {
|
|
|
21061
21110
|
when: "harness-maintenance",
|
|
21062
21111
|
title: "Optional: observe lifecycle Hook on a later Stop",
|
|
21063
21112
|
reason: `Hooks are configured for ${configured || "the current Agent"} but not yet observed. This does not block delivery \u2014 use harness-kit deliver for task acceptance.`,
|
|
21064
|
-
commands: [
|
|
21113
|
+
commands: [`${cli} deliver --repo .`, `${cli} evidence --repo . --json`],
|
|
21065
21114
|
completion: "Deliver stamp is valid; hook observation is optional."
|
|
21066
21115
|
}];
|
|
21067
21116
|
}
|
|
@@ -21074,8 +21123,8 @@ function hookActions(hooks) {
|
|
|
21074
21123
|
title: "Optional: install Agent Stop intercept for session-level loops",
|
|
21075
21124
|
reason: "Without Stop hooks, agents must run harness-kit deliver cooperatively. Install hooks only when the host supports them.",
|
|
21076
21125
|
commands: [
|
|
21077
|
-
|
|
21078
|
-
|
|
21126
|
+
`${cli} deliver --repo .`,
|
|
21127
|
+
`${cli} install-hooks --repo . --stop --agents ${configured || "<current-agent>"}`
|
|
21079
21128
|
],
|
|
21080
21129
|
completion: "Deliver works without hooks; hooks only add session intercept when the host fires Stop."
|
|
21081
21130
|
}];
|
|
@@ -21088,13 +21137,13 @@ function hookActions(hooks) {
|
|
|
21088
21137
|
title: "Optional: repair Agent lifecycle Hook configuration",
|
|
21089
21138
|
reason: "Hook configuration is incomplete or degraded. Delivery still uses harness-kit deliver.",
|
|
21090
21139
|
commands: [
|
|
21091
|
-
|
|
21092
|
-
|
|
21140
|
+
`${cli} install-hooks --repo . --stop --agents ${configured}`,
|
|
21141
|
+
`${cli} deliver --repo .`
|
|
21093
21142
|
],
|
|
21094
21143
|
completion: "Hooks install cleanly or the team accepts deliver-only cooperative mode."
|
|
21095
21144
|
}];
|
|
21096
21145
|
}
|
|
21097
|
-
function evidenceActions(evidence) {
|
|
21146
|
+
function evidenceActions(evidence, cli) {
|
|
21098
21147
|
if (!evidence.found) {
|
|
21099
21148
|
return [{
|
|
21100
21149
|
id: "record-delivery-evidence",
|
|
@@ -21103,10 +21152,7 @@ function evidenceActions(evidence) {
|
|
|
21103
21152
|
when: "before-finish",
|
|
21104
21153
|
title: "Accept this change with harness-kit deliver",
|
|
21105
21154
|
reason: "No delivery stamp exists for the current worktree/session.",
|
|
21106
|
-
commands: [
|
|
21107
|
-
"harness-kit deliver --repo .",
|
|
21108
|
-
"harness-kit evidence --repo . --json"
|
|
21109
|
-
],
|
|
21155
|
+
commands: [`${cli} deliver --repo .`, `${cli} evidence --repo . --json`],
|
|
21110
21156
|
completion: "deliver reports status=accepted (or no-change) and evidence stamp is valid."
|
|
21111
21157
|
}];
|
|
21112
21158
|
}
|
|
@@ -21118,7 +21164,7 @@ function evidenceActions(evidence) {
|
|
|
21118
21164
|
when: "before-finish",
|
|
21119
21165
|
title: "Re-run deliver for the current code",
|
|
21120
21166
|
reason: "The saved green stamp belongs to an older code fingerprint.",
|
|
21121
|
-
commands: [
|
|
21167
|
+
commands: [`${cli} deliver --repo .`, `${cli} evidence --repo . --json`],
|
|
21122
21168
|
completion: "Stamp is no longer stale and deliver reports accepted."
|
|
21123
21169
|
}];
|
|
21124
21170
|
}
|
|
@@ -21130,7 +21176,7 @@ function evidenceActions(evidence) {
|
|
|
21130
21176
|
when: "before-finish",
|
|
21131
21177
|
title: "Complete impact-driven delivery checks",
|
|
21132
21178
|
reason: "The selected checks did not produce valid evidence for the current code.",
|
|
21133
|
-
commands: [
|
|
21179
|
+
commands: [`${cli} deliver --repo .`, `${cli} evidence --repo . --json`],
|
|
21134
21180
|
completion: "deliver reports accepted and stamp runChecksValid: true."
|
|
21135
21181
|
}];
|
|
21136
21182
|
}
|
|
@@ -21142,19 +21188,20 @@ function evidenceActions(evidence) {
|
|
|
21142
21188
|
when: "before-finish",
|
|
21143
21189
|
title: "Complete delivery verification",
|
|
21144
21190
|
reason: "Change checks passed, but matching verify evidence is missing or failed.",
|
|
21145
|
-
commands: [
|
|
21191
|
+
commands: [`${cli} deliver --repo .`, `${cli} evidence --repo . --json`],
|
|
21146
21192
|
completion: "deliver reports accepted and stamp valid: true."
|
|
21147
21193
|
}];
|
|
21148
21194
|
}
|
|
21149
21195
|
return [];
|
|
21150
21196
|
}
|
|
21151
21197
|
function buildHarnessGuidance(input) {
|
|
21198
|
+
const cli = input.cli ?? "harness-kit";
|
|
21152
21199
|
const gapDetails = input.manifest ? declaredVerificationGaps(input.manifest) : [];
|
|
21153
21200
|
const nextActions2 = [
|
|
21154
|
-
...input.evidence ? evidenceActions(input.evidence) : [],
|
|
21155
|
-
...input.hooks ? hookActions(input.hooks) : []
|
|
21201
|
+
...input.evidence ? evidenceActions(input.evidence, cli) : [],
|
|
21202
|
+
...input.hooks ? hookActions(input.hooks, cli) : []
|
|
21156
21203
|
];
|
|
21157
|
-
const improvement = automationAction(gapDetails);
|
|
21204
|
+
const improvement = automationAction(gapDetails, cli);
|
|
21158
21205
|
if (improvement) nextActions2.push(improvement);
|
|
21159
21206
|
return {
|
|
21160
21207
|
gapDetails,
|
|
@@ -21168,14 +21215,14 @@ function buildHarnessGuidance(input) {
|
|
|
21168
21215
|
}
|
|
21169
21216
|
|
|
21170
21217
|
// src/hook-status.ts
|
|
21171
|
-
var
|
|
21172
|
-
var
|
|
21218
|
+
var import_node_fs11 = require("node:fs");
|
|
21219
|
+
var import_node_path11 = require("node:path");
|
|
21173
21220
|
|
|
21174
21221
|
// src/codex-linked-hooks.ts
|
|
21175
21222
|
var import_node_child_process4 = require("node:child_process");
|
|
21176
|
-
var
|
|
21223
|
+
var import_node_fs8 = require("node:fs");
|
|
21177
21224
|
var import_node_os = require("node:os");
|
|
21178
|
-
var
|
|
21225
|
+
var import_node_path8 = require("node:path");
|
|
21179
21226
|
var CODEX_LINKED_PROTOCOL = "ai-harness/codex-linked-dispatch/v1";
|
|
21180
21227
|
var DISPATCH_ID = "codex-linked-dispatch-v1";
|
|
21181
21228
|
var DISPATCHER_REL = `harness-kit/${DISPATCH_ID}.cjs`;
|
|
@@ -21185,25 +21232,25 @@ var RUNNER_REL = ".agents/hooks/harness-agent-hook.sh";
|
|
|
21185
21232
|
var DISPATCHER_MARK = "harness-kit-managed-codex-linked-dispatch-v1";
|
|
21186
21233
|
function canonical(path) {
|
|
21187
21234
|
try {
|
|
21188
|
-
return (0,
|
|
21235
|
+
return (0, import_node_fs8.realpathSync)(path);
|
|
21189
21236
|
} catch {
|
|
21190
|
-
return (0,
|
|
21237
|
+
return (0, import_node_path8.resolve)(path);
|
|
21191
21238
|
}
|
|
21192
21239
|
}
|
|
21193
21240
|
function ensureCodexHome(requestedInput, label) {
|
|
21194
|
-
const requested = (0,
|
|
21195
|
-
(0,
|
|
21196
|
-
const resolved = (0,
|
|
21197
|
-
if (!(0,
|
|
21241
|
+
const requested = (0, import_node_path8.resolve)(requestedInput);
|
|
21242
|
+
(0, import_node_fs8.mkdirSync)(requested, { recursive: true, mode: 448 });
|
|
21243
|
+
const resolved = (0, import_node_fs8.realpathSync)(requested);
|
|
21244
|
+
if (!(0, import_node_fs8.statSync)(resolved).isDirectory()) throw new Error(`${label} is not a directory: ${requested}`);
|
|
21198
21245
|
return resolved;
|
|
21199
21246
|
}
|
|
21200
21247
|
function resolveCodexHookSourceHome(options = {}) {
|
|
21201
21248
|
const env = options.env ?? process.env;
|
|
21202
21249
|
const userHome = options.homeDir ?? (0, import_node_os.homedir)();
|
|
21203
|
-
const runtimeHome = ensureCodexHome(env.CODEX_HOME ?? (0,
|
|
21250
|
+
const runtimeHome = ensureCodexHome(env.CODEX_HOME ?? (0, import_node_path8.join)(userHome, ".codex"), "CODEX_HOME");
|
|
21204
21251
|
const orcaRuntimeHome = env.ORCA_CODEX_HOME?.trim();
|
|
21205
|
-
if (env.ORCA_WORKTREE_ID?.trim() && orcaRuntimeHome && canonical((0,
|
|
21206
|
-
const codexHome = ensureCodexHome((0,
|
|
21252
|
+
if (env.ORCA_WORKTREE_ID?.trim() && orcaRuntimeHome && canonical((0, import_node_path8.resolve)(orcaRuntimeHome)) === runtimeHome) {
|
|
21253
|
+
const codexHome = ensureCodexHome((0, import_node_path8.join)(userHome, ".codex"), "Codex system hook source home");
|
|
21207
21254
|
return { codexHome, requiresRuntimeRefresh: codexHome !== runtimeHome };
|
|
21208
21255
|
}
|
|
21209
21256
|
return { codexHome: runtimeHome, requiresRuntimeRefresh: false };
|
|
@@ -21212,7 +21259,7 @@ function shellQuote(value) {
|
|
|
21212
21259
|
return `'${value.replace(/'/g, `'"'"'`)}'`;
|
|
21213
21260
|
}
|
|
21214
21261
|
function userHookCommand(codexHome, event) {
|
|
21215
|
-
return `node ${shellQuote((0,
|
|
21262
|
+
return `node ${shellQuote((0, import_node_path8.join)(codexHome, DISPATCHER_REL))} ${event}`;
|
|
21216
21263
|
}
|
|
21217
21264
|
function managedUserGroup(codexHome, event) {
|
|
21218
21265
|
return {
|
|
@@ -21243,7 +21290,7 @@ function parseObjectJson(raw, label) {
|
|
|
21243
21290
|
throw new Error(`${label} exists but is not valid JSON`);
|
|
21244
21291
|
}
|
|
21245
21292
|
function renderUserHooks(current, codexHome) {
|
|
21246
|
-
const hooksPath = (0,
|
|
21293
|
+
const hooksPath = (0, import_node_path8.join)(codexHome, USER_HOOKS_REL);
|
|
21247
21294
|
const json = parseObjectJson(current, hooksPath);
|
|
21248
21295
|
if (json.hooks !== void 0 && (!json.hooks || typeof json.hooks !== "object" || Array.isArray(json.hooks))) {
|
|
21249
21296
|
throw new Error(`${hooksPath} hooks must be an object; refusing to replace an unknown existing shape`);
|
|
@@ -21292,9 +21339,9 @@ function registrationFrom(raw, label) {
|
|
|
21292
21339
|
}
|
|
21293
21340
|
function runnerMode(repoRoot, content) {
|
|
21294
21341
|
try {
|
|
21295
|
-
const path = (0,
|
|
21296
|
-
const stat = (0,
|
|
21297
|
-
if (stat.isFile() && !stat.isSymbolicLink() && (0,
|
|
21342
|
+
const path = (0, import_node_path8.join)(repoRoot, RUNNER_REL);
|
|
21343
|
+
const stat = (0, import_node_fs8.lstatSync)(path);
|
|
21344
|
+
if (stat.isFile() && !stat.isSymbolicLink() && (0, import_node_fs8.readFileSync)(path, "utf8") === content) return stat.mode & 511;
|
|
21298
21345
|
} catch {
|
|
21299
21346
|
}
|
|
21300
21347
|
return 493;
|
|
@@ -21428,7 +21475,7 @@ function prepareCodexLinkedInstall(repoInput, runnerContent, options = {}) {
|
|
|
21428
21475
|
const initialByPath = inspectionMap(initialUser);
|
|
21429
21476
|
const currentDispatcher = initialByPath.get(DISPATCHER_REL)?.currentContent ?? null;
|
|
21430
21477
|
if (currentDispatcher !== null && currentDispatcher !== dispatcher) {
|
|
21431
|
-
throw new Error(`${(0,
|
|
21478
|
+
throw new Error(`${(0, import_node_path8.join)(codexHome, DISPATCHER_REL)} exists and is foreign or changed; refusing to replace it`);
|
|
21432
21479
|
}
|
|
21433
21480
|
const currentHooks = initialByPath.get(USER_HOOKS_REL)?.currentContent ?? null;
|
|
21434
21481
|
const renderedHooks = renderUserHooks(currentHooks, codexHome);
|
|
@@ -21472,30 +21519,30 @@ function prepareCodexLinkedInstall(repoInput, runnerContent, options = {}) {
|
|
|
21472
21519
|
};
|
|
21473
21520
|
}
|
|
21474
21521
|
function registrationPathLabel(gitDir) {
|
|
21475
|
-
return (0,
|
|
21522
|
+
return (0, import_node_path8.join)(gitDir, REGISTRATION_REL);
|
|
21476
21523
|
}
|
|
21477
21524
|
function commitCodexLinkedInstall(plan, testHooks = {}) {
|
|
21478
21525
|
testHooks.beforeUserTransaction?.();
|
|
21479
21526
|
const userResult = writeManagedFiles(plan.codexHome, plan.userTargets, {
|
|
21480
21527
|
authorize: (current) => assertInspectionsUnchanged(plan.userInspections, current, "Codex user Hook source")
|
|
21481
21528
|
});
|
|
21482
|
-
(0,
|
|
21529
|
+
(0, import_node_fs8.chmodSync)((0, import_node_path8.join)(plan.codexHome, DISPATCHER_REL), 448);
|
|
21483
21530
|
if (userResult.inspections.find((item) => item.relativePath === USER_HOOKS_REL)?.kind === "missing") {
|
|
21484
|
-
(0,
|
|
21531
|
+
(0, import_node_fs8.chmodSync)((0, import_node_path8.join)(plan.codexHome, USER_HOOKS_REL), 384);
|
|
21485
21532
|
}
|
|
21486
21533
|
testHooks.beforeRegistrationTransaction?.();
|
|
21487
21534
|
writeManagedFiles(plan.gitDir, [plan.registrationTarget], {
|
|
21488
21535
|
authorize: (current) => assertInspectionsUnchanged(plan.registrationInspections, current, "Codex linked registration source")
|
|
21489
21536
|
});
|
|
21490
|
-
(0,
|
|
21537
|
+
(0, import_node_fs8.chmodSync)((0, import_node_path8.join)(plan.gitDir, REGISTRATION_REL), 384);
|
|
21491
21538
|
}
|
|
21492
21539
|
function safeContent(root, rel, issues) {
|
|
21493
21540
|
try {
|
|
21494
21541
|
const inspected = inspectManagedFiles(root, [[rel, ""]])[0];
|
|
21495
21542
|
if (inspected.kind === "missing" || inspected.currentContent === null) return { content: null };
|
|
21496
|
-
return { content: inspected.currentContent, mode: (0,
|
|
21543
|
+
return { content: inspected.currentContent, mode: (0, import_node_fs8.lstatSync)((0, import_node_path8.join)(root, rel)).mode & 511 };
|
|
21497
21544
|
} catch (error) {
|
|
21498
|
-
issues.push(`${(0,
|
|
21545
|
+
issues.push(`${(0, import_node_path8.join)(root, rel)} is not a safe regular file: ${error.message}`);
|
|
21499
21546
|
return { content: null };
|
|
21500
21547
|
}
|
|
21501
21548
|
}
|
|
@@ -21538,7 +21585,7 @@ function inspectCodexLinkedHooks(repoInput) {
|
|
|
21538
21585
|
issues.push("Codex user hooks.json is missing");
|
|
21539
21586
|
} else {
|
|
21540
21587
|
try {
|
|
21541
|
-
const json = parseObjectJson(userHooksFile.content, (0,
|
|
21588
|
+
const json = parseObjectJson(userHooksFile.content, (0, import_node_path8.join)(registration.codexHome, USER_HOOKS_REL));
|
|
21542
21589
|
const hooks = json.hooks;
|
|
21543
21590
|
const start = Array.isArray(hooks?.SessionStart) ? hooks.SessionStart.find((group) => isExactManagedUserGroup(group, registration.codexHome, "session-start")) : void 0;
|
|
21544
21591
|
const stop = Array.isArray(hooks?.Stop) ? hooks.Stop.find((group) => isExactManagedUserGroup(group, registration.codexHome, "stop")) : void 0;
|
|
@@ -21561,8 +21608,8 @@ function inspectCodexLinkedHooks(repoInput) {
|
|
|
21561
21608
|
|
|
21562
21609
|
// src/validation-state.ts
|
|
21563
21610
|
var import_node_crypto6 = require("node:crypto");
|
|
21564
|
-
var
|
|
21565
|
-
var
|
|
21611
|
+
var import_node_fs9 = require("node:fs");
|
|
21612
|
+
var import_node_path9 = require("node:path");
|
|
21566
21613
|
|
|
21567
21614
|
// src/planner.ts
|
|
21568
21615
|
var import_picomatch2 = __toESM(require_picomatch2(), 1);
|
|
@@ -21870,24 +21917,24 @@ var TOKEN_RX = /^[a-f0-9]{64}$/;
|
|
|
21870
21917
|
var MAX_SESSIONS = 100;
|
|
21871
21918
|
var MAX_AGE_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
21872
21919
|
function stateDir(repo) {
|
|
21873
|
-
return (0,
|
|
21920
|
+
return (0, import_node_path9.join)(gitAdminDir(repo), "harness-kit", "validation");
|
|
21874
21921
|
}
|
|
21875
21922
|
function canonicalTarget(repo) {
|
|
21876
21923
|
try {
|
|
21877
|
-
return (0,
|
|
21924
|
+
return (0, import_node_fs9.realpathSync)(repo);
|
|
21878
21925
|
} catch {
|
|
21879
|
-
return (0,
|
|
21926
|
+
return (0, import_node_path9.resolve)(repo);
|
|
21880
21927
|
}
|
|
21881
21928
|
}
|
|
21882
21929
|
function latestPath(repo) {
|
|
21883
|
-
return (0,
|
|
21930
|
+
return (0, import_node_path9.join)(stateDir(repo), `latest-${sha256(canonicalTarget(repo)).slice(0, 24)}.json`);
|
|
21884
21931
|
}
|
|
21885
21932
|
function validationSessionToken(agent, sessionId2) {
|
|
21886
21933
|
return sha256(`${agent}\0${sessionId2}`);
|
|
21887
21934
|
}
|
|
21888
21935
|
function sessionPath(repo, token) {
|
|
21889
21936
|
if (!TOKEN_RX.test(token)) throw new Error("invalid validation session token");
|
|
21890
|
-
return (0,
|
|
21937
|
+
return (0, import_node_path9.join)(stateDir(repo), `${token}.json`);
|
|
21891
21938
|
}
|
|
21892
21939
|
function readJson(path) {
|
|
21893
21940
|
const raw = readText(path);
|
|
@@ -21900,21 +21947,21 @@ function readJson(path) {
|
|
|
21900
21947
|
}
|
|
21901
21948
|
function expired(path) {
|
|
21902
21949
|
try {
|
|
21903
|
-
return Date.now() - (0,
|
|
21950
|
+
return Date.now() - (0, import_node_fs9.statSync)(path).mtimeMs > MAX_AGE_MS;
|
|
21904
21951
|
} catch {
|
|
21905
21952
|
return false;
|
|
21906
21953
|
}
|
|
21907
21954
|
}
|
|
21908
21955
|
function writePrivateJson(path, value) {
|
|
21909
|
-
(0,
|
|
21956
|
+
(0, import_node_fs9.mkdirSync)((0, import_node_path9.dirname)(path), { recursive: true });
|
|
21910
21957
|
const temp = `${path}.${process.pid}.${(0, import_node_crypto6.randomUUID)()}.tmp`;
|
|
21911
21958
|
try {
|
|
21912
|
-
(0,
|
|
21913
|
-
(0,
|
|
21914
|
-
(0,
|
|
21959
|
+
(0, import_node_fs9.writeFileSync)(temp, JSON.stringify(value, null, 2) + "\n", { mode: 384 });
|
|
21960
|
+
(0, import_node_fs9.renameSync)(temp, path);
|
|
21961
|
+
(0, import_node_fs9.chmodSync)(path, 384);
|
|
21915
21962
|
} catch (error) {
|
|
21916
21963
|
try {
|
|
21917
|
-
(0,
|
|
21964
|
+
(0, import_node_fs9.unlinkSync)(temp);
|
|
21918
21965
|
} catch {
|
|
21919
21966
|
}
|
|
21920
21967
|
throw error;
|
|
@@ -21927,9 +21974,9 @@ function pruneValidationState(repo) {
|
|
|
21927
21974
|
const dir = stateDir(repo);
|
|
21928
21975
|
let files;
|
|
21929
21976
|
try {
|
|
21930
|
-
files = (0,
|
|
21931
|
-
const path = (0,
|
|
21932
|
-
return { path, mtimeMs: (0,
|
|
21977
|
+
files = (0, import_node_fs9.readdirSync)(dir).filter((name) => TOKEN_RX.test(name.replace(/\.json$/, ""))).map((name) => {
|
|
21978
|
+
const path = (0, import_node_path9.join)(dir, name);
|
|
21979
|
+
return { path, mtimeMs: (0, import_node_fs9.statSync)(path).mtimeMs };
|
|
21933
21980
|
}).sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
21934
21981
|
} catch {
|
|
21935
21982
|
return;
|
|
@@ -21938,7 +21985,7 @@ function pruneValidationState(repo) {
|
|
|
21938
21985
|
for (const [index, file] of files.entries()) {
|
|
21939
21986
|
if (index >= MAX_SESSIONS || now - file.mtimeMs > MAX_AGE_MS) {
|
|
21940
21987
|
try {
|
|
21941
|
-
(0,
|
|
21988
|
+
(0, import_node_fs9.unlinkSync)(file.path);
|
|
21942
21989
|
} catch {
|
|
21943
21990
|
}
|
|
21944
21991
|
}
|
|
@@ -21978,7 +22025,7 @@ function readValidationSession(repo, token) {
|
|
|
21978
22025
|
const path = sessionPath(repo, token);
|
|
21979
22026
|
if (expired(path)) {
|
|
21980
22027
|
try {
|
|
21981
|
-
(0,
|
|
22028
|
+
(0, import_node_fs9.unlinkSync)(path);
|
|
21982
22029
|
} catch {
|
|
21983
22030
|
}
|
|
21984
22031
|
return null;
|
|
@@ -21996,7 +22043,7 @@ function readLatestHookValidationSession(repoInput) {
|
|
|
21996
22043
|
pruneValidationState(repo);
|
|
21997
22044
|
let tokens;
|
|
21998
22045
|
try {
|
|
21999
|
-
tokens = (0,
|
|
22046
|
+
tokens = (0, import_node_fs9.readdirSync)(stateDir(repo)).map((name) => ({ name, token: name.replace(/\.json$/, "") })).filter(({ name, token }) => name.endsWith(".json") && TOKEN_RX.test(token)).map(({ token }) => ({ token, mtimeMs: (0, import_node_fs9.statSync)(sessionPath(repo, token)).mtimeMs })).sort((left, right) => right.mtimeMs - left.mtimeMs);
|
|
22000
22047
|
} catch {
|
|
22001
22048
|
return null;
|
|
22002
22049
|
}
|
|
@@ -22104,8 +22151,8 @@ function markManualVerifyResult(repoInput, passed) {
|
|
|
22104
22151
|
}
|
|
22105
22152
|
|
|
22106
22153
|
// src/commands/stop-hooks.ts
|
|
22107
|
-
var
|
|
22108
|
-
var
|
|
22154
|
+
var import_node_fs10 = require("node:fs");
|
|
22155
|
+
var import_node_path10 = require("node:path");
|
|
22109
22156
|
var ALL_AGENTS = ["claude", "cursor", "codex"];
|
|
22110
22157
|
var SCRIPT_REL = ".agents/hooks/harness-agent-hook.sh";
|
|
22111
22158
|
var SCRIPT_MARK = "harness-kit-managed-hook (agent-lifecycle)";
|
|
@@ -22322,7 +22369,7 @@ function installStopHooks(repo, agents, opts = {}) {
|
|
|
22322
22369
|
err(`agent hooks require a Git worktree: ${error.message}`);
|
|
22323
22370
|
return 1;
|
|
22324
22371
|
}
|
|
22325
|
-
if (!(0,
|
|
22372
|
+
if (!(0, import_node_fs10.existsSync)((0, import_node_path10.join)(repo, ".agents", "manifest.yaml"))) {
|
|
22326
22373
|
err("agent hooks require .agents/manifest.yaml \u2014 onboard the repository first");
|
|
22327
22374
|
return 1;
|
|
22328
22375
|
}
|
|
@@ -22374,7 +22421,7 @@ function installStopHooks(repo, agents, opts = {}) {
|
|
|
22374
22421
|
writeManagedFiles(repo, targets, {
|
|
22375
22422
|
authorize: (transactionPreflight) => assertRenderedSourcesUnchanged(inspections, transactionPreflight)
|
|
22376
22423
|
});
|
|
22377
|
-
(0,
|
|
22424
|
+
(0, import_node_fs10.chmodSync)((0, import_node_path10.join)(repo, SCRIPT_REL), 493);
|
|
22378
22425
|
} catch (error) {
|
|
22379
22426
|
err(`agent hooks not installed: ${error.message}`);
|
|
22380
22427
|
return 1;
|
|
@@ -22399,8 +22446,8 @@ function installStopHooks(repo, agents, opts = {}) {
|
|
|
22399
22446
|
ok("codex: enabled project hooks -> .codex/config.toml");
|
|
22400
22447
|
if (linkedPlan) {
|
|
22401
22448
|
ok("codex: removed project Harness hooks so the user dispatcher is the only lifecycle path -> .codex/hooks.json");
|
|
22402
|
-
ok(`codex: installed linked-worktree dispatcher source -> ${(0,
|
|
22403
|
-
ok(`codex: registered this worktree -> ${(0,
|
|
22449
|
+
ok(`codex: installed linked-worktree dispatcher source -> ${(0, import_node_path10.join)(linkedPlan.codexHome, "harness-kit", "codex-linked-dispatch-v1.cjs")}`);
|
|
22450
|
+
ok(`codex: registered this worktree -> ${(0, import_node_path10.join)(linkedPlan.gitDir, "harness-kit", "codex-linked-dispatch-v1.json")}`);
|
|
22404
22451
|
} else {
|
|
22405
22452
|
ok("codex: installed SessionStart + Stop hooks -> .codex/hooks.json");
|
|
22406
22453
|
}
|
|
@@ -22526,7 +22573,7 @@ function codexFeatureEnabled(repo, issues) {
|
|
|
22526
22573
|
return enabled;
|
|
22527
22574
|
}
|
|
22528
22575
|
function runnerReady(repo, issues) {
|
|
22529
|
-
const path = (0,
|
|
22576
|
+
const path = (0, import_node_path11.join)(repo, RUNNER_REL2);
|
|
22530
22577
|
try {
|
|
22531
22578
|
const inspected = safeProjectText(repo, RUNNER_REL2, issues);
|
|
22532
22579
|
if (!inspected.exists) {
|
|
@@ -22534,7 +22581,7 @@ function runnerReady(repo, issues) {
|
|
|
22534
22581
|
return false;
|
|
22535
22582
|
}
|
|
22536
22583
|
if (inspected.content === null) return false;
|
|
22537
|
-
const stat = (0,
|
|
22584
|
+
const stat = (0, import_node_fs11.lstatSync)(path);
|
|
22538
22585
|
const withoutOptionalFinalNewline = (value) => value.endsWith("\n") ? value.slice(0, -1) : value;
|
|
22539
22586
|
const ready = stat.isFile() && !stat.isSymbolicLink() && (stat.mode & 64) !== 0 && withoutOptionalFinalNewline(inspected.content) === withoutOptionalFinalNewline(installedAgentHookRunnerScript());
|
|
22540
22587
|
if (!ready) issues.push(`${RUNNER_REL2} is not a managed executable runner`);
|
|
@@ -22546,7 +22593,7 @@ function runnerReady(repo, issues) {
|
|
|
22546
22593
|
}
|
|
22547
22594
|
function codexLinkedRegistrationExists(repo) {
|
|
22548
22595
|
try {
|
|
22549
|
-
return (0,
|
|
22596
|
+
return (0, import_node_fs11.existsSync)((0, import_node_path11.join)(gitAdminDir(repo), CODEX_LINKED_REGISTRATION_REL));
|
|
22550
22597
|
} catch {
|
|
22551
22598
|
return false;
|
|
22552
22599
|
}
|
|
@@ -22583,7 +22630,7 @@ function agentHookConfigurationFingerprint(repo, agent) {
|
|
|
22583
22630
|
artifacts.push({
|
|
22584
22631
|
path: rel,
|
|
22585
22632
|
content: inspected.content,
|
|
22586
|
-
...rel === RUNNER_REL2 ? { mode: (0,
|
|
22633
|
+
...rel === RUNNER_REL2 ? { mode: (0, import_node_fs11.lstatSync)((0, import_node_path11.join)(repo, rel)).mode & 4095 } : {}
|
|
22587
22634
|
});
|
|
22588
22635
|
}
|
|
22589
22636
|
artifacts.push(...linkedArtifacts);
|
|
@@ -22655,37 +22702,37 @@ function inspectAgentHookStatus(repo) {
|
|
|
22655
22702
|
}
|
|
22656
22703
|
|
|
22657
22704
|
// src/state.ts
|
|
22658
|
-
var
|
|
22659
|
-
var
|
|
22705
|
+
var import_node_fs12 = require("node:fs");
|
|
22706
|
+
var import_node_path12 = require("node:path");
|
|
22660
22707
|
var import_fast_glob2 = __toESM(require_out4(), 1);
|
|
22661
22708
|
var STATE_REL = ".agents/.harness-state.json";
|
|
22662
22709
|
function inside3(base, target) {
|
|
22663
|
-
const rel = (0,
|
|
22664
|
-
return rel === "" || !rel.startsWith("..") && !(0,
|
|
22710
|
+
const rel = (0, import_node_path12.relative)(base, target);
|
|
22711
|
+
return rel === "" || !rel.startsWith("..") && !(0, import_node_path12.isAbsolute)(rel);
|
|
22665
22712
|
}
|
|
22666
22713
|
function resolveKnowledgePath(repo, knowledge) {
|
|
22667
|
-
const base = knowledge.root === "repo" ? (0,
|
|
22668
|
-
const target = (0,
|
|
22714
|
+
const base = knowledge.root === "repo" ? (0, import_node_path12.resolve)(repo) : (0, import_node_path12.resolve)(repo, ".agents");
|
|
22715
|
+
const target = (0, import_node_path12.resolve)(base, knowledge.path);
|
|
22669
22716
|
if (!inside3(base, target)) throw new Error(`knowledge path escapes ${knowledge.root === "repo" ? "repository" : ".agents"}: ${knowledge.path}`);
|
|
22670
22717
|
return target;
|
|
22671
22718
|
}
|
|
22672
22719
|
function hashPath(absPath) {
|
|
22673
|
-
if (!(0,
|
|
22720
|
+
if (!(0, import_node_fs12.existsSync)(absPath)) return "(missing)";
|
|
22674
22721
|
let stat;
|
|
22675
22722
|
try {
|
|
22676
|
-
stat = (0,
|
|
22723
|
+
stat = (0, import_node_fs12.statSync)(absPath);
|
|
22677
22724
|
} catch {
|
|
22678
22725
|
return "(missing)";
|
|
22679
22726
|
}
|
|
22680
22727
|
if (stat.isFile()) return hashFile(absPath) ?? "(missing)";
|
|
22681
22728
|
if (!stat.isDirectory()) return "(missing)";
|
|
22682
22729
|
const files = import_fast_glob2.default.sync("**/*", { cwd: absPath, onlyFiles: true, dot: true, followSymbolicLinks: false }).sort();
|
|
22683
|
-
const entries = files.map((path) => [path, hashFile((0,
|
|
22730
|
+
const entries = files.map((path) => [path, hashFile((0, import_node_path12.join)(absPath, path)) ?? "(missing)"]);
|
|
22684
22731
|
return sha256(JSON.stringify(entries));
|
|
22685
22732
|
}
|
|
22686
22733
|
function sourceHashes(repo, paths) {
|
|
22687
22734
|
const result = {};
|
|
22688
|
-
for (const path of paths) result[path] = hashFile((0,
|
|
22735
|
+
for (const path of paths) result[path] = hashFile((0, import_node_path12.join)(repo, path)) ?? "(missing)";
|
|
22689
22736
|
return result;
|
|
22690
22737
|
}
|
|
22691
22738
|
function knowledgeKey(knowledge) {
|
|
@@ -22739,14 +22786,17 @@ function contextSnapshots(repo, manifest) {
|
|
|
22739
22786
|
}
|
|
22740
22787
|
return snapshots;
|
|
22741
22788
|
}
|
|
22742
|
-
function
|
|
22743
|
-
const raw = readText((0, import_node_path11.join)(repo, STATE_REL));
|
|
22744
|
-
if (!raw) return null;
|
|
22789
|
+
function parseState2(raw) {
|
|
22745
22790
|
const value = JSON.parse(raw);
|
|
22746
22791
|
return { bindings: value.bindings ?? {}, reviews: value.reviews ?? {} };
|
|
22747
22792
|
}
|
|
22793
|
+
function readState(repo) {
|
|
22794
|
+
const raw = readText((0, import_node_path12.join)(repo, STATE_REL));
|
|
22795
|
+
if (!raw) return null;
|
|
22796
|
+
return parseState2(raw);
|
|
22797
|
+
}
|
|
22748
22798
|
function writeState(repo, state) {
|
|
22749
|
-
writeText((0,
|
|
22799
|
+
writeText((0, import_node_path12.join)(repo, STATE_REL), JSON.stringify(state, null, 2) + "\n");
|
|
22750
22800
|
}
|
|
22751
22801
|
function changedSources(before, after) {
|
|
22752
22802
|
return [.../* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)])].filter((path) => before[path] !== after[path]).sort();
|
|
@@ -22769,6 +22819,7 @@ function inspectContextFreshness(repo, manifest) {
|
|
|
22769
22819
|
kind: snapshot.kind,
|
|
22770
22820
|
target: snapshot.target,
|
|
22771
22821
|
severity: "blocking",
|
|
22822
|
+
code: "source-missing",
|
|
22772
22823
|
reason: "\u7ED1\u5B9A\u6E90\u6587\u4EF6\u7F3A\u5931\uFF0C\u4E0D\u80FD\u628A\u4E0A\u4E0B\u6587\u89C6\u4E3A\u5DF2\u590D\u6838",
|
|
22773
22824
|
changedSources: missing
|
|
22774
22825
|
});
|
|
@@ -22781,6 +22832,7 @@ function inspectContextFreshness(repo, manifest) {
|
|
|
22781
22832
|
kind: snapshot.kind,
|
|
22782
22833
|
target: snapshot.target,
|
|
22783
22834
|
severity: "blocking",
|
|
22835
|
+
code: "authority-changed",
|
|
22784
22836
|
reason: `authority \u5728\u590D\u6838\u540E\u4ECE ${review.authority} \u53D8\u4E3A ${expectedAuthority}`,
|
|
22785
22837
|
changedSources: changedSources(review.sources, snapshot.sources)
|
|
22786
22838
|
});
|
|
@@ -22793,6 +22845,7 @@ function inspectContextFreshness(repo, manifest) {
|
|
|
22793
22845
|
kind: snapshot.kind,
|
|
22794
22846
|
target: snapshot.target,
|
|
22795
22847
|
severity: "blocking",
|
|
22848
|
+
code: "review-missing",
|
|
22796
22849
|
reason: `\u5C1A\u672A\u8BB0\u5F55\u590D\u6838\uFF08authority: ${snapshot.authority}\uFF09`,
|
|
22797
22850
|
changedSources: Object.keys(snapshot.sources).sort()
|
|
22798
22851
|
});
|
|
@@ -22805,6 +22858,7 @@ function inspectContextFreshness(repo, manifest) {
|
|
|
22805
22858
|
kind: snapshot.kind,
|
|
22806
22859
|
target: snapshot.target,
|
|
22807
22860
|
severity: "blocking",
|
|
22861
|
+
code: "content-changed",
|
|
22808
22862
|
reason: "\u77E5\u8BC6\u5185\u5BB9\u5728\u590D\u6838\u540E\u53D1\u751F\u53D8\u5316\uFF0C\u5FC5\u987B\u91CD\u65B0\u8BB0\u5F55\u590D\u6838",
|
|
22809
22863
|
changedSources: sources2
|
|
22810
22864
|
});
|
|
@@ -22814,6 +22868,7 @@ function inspectContextFreshness(repo, manifest) {
|
|
|
22814
22868
|
kind: snapshot.kind,
|
|
22815
22869
|
target: snapshot.target,
|
|
22816
22870
|
severity: "blocking",
|
|
22871
|
+
code: "sources-changed",
|
|
22817
22872
|
reason: `\u7ED1\u5B9A\u6E90\u6587\u4EF6\u5728\u590D\u6838\u540E\u53D1\u751F\u53D8\u5316\uFF08authority: ${snapshot.authority}\uFF09`,
|
|
22818
22873
|
changedSources: sources2
|
|
22819
22874
|
});
|
|
@@ -22828,6 +22883,7 @@ function inspectContextFreshness(repo, manifest) {
|
|
|
22828
22883
|
kind: snapshot.kind,
|
|
22829
22884
|
target: snapshot.target,
|
|
22830
22885
|
severity: "blocking",
|
|
22886
|
+
code: review.contentHash !== snapshot.contentHash ? "content-changed" : "sources-changed",
|
|
22831
22887
|
reason: review.contentHash !== snapshot.contentHash ? "\u4E0A\u4E0B\u6587\u5185\u5BB9\u5728\u590D\u6838\u540E\u53D1\u751F\u53D8\u5316" : "\u7ED1\u5B9A\u6E90\u6587\u4EF6\u5728\u590D\u6838\u540E\u53D1\u751F\u53D8\u5316",
|
|
22832
22888
|
changedSources: sources2
|
|
22833
22889
|
});
|
|
@@ -22843,6 +22899,7 @@ function inspectContextFreshness(repo, manifest) {
|
|
|
22843
22899
|
kind: snapshot.kind,
|
|
22844
22900
|
target: snapshot.target,
|
|
22845
22901
|
severity: "advisory",
|
|
22902
|
+
code: "legacy-baseline-changed",
|
|
22846
22903
|
reason: "legacy freshness baseline changed; record a context review to make it durable",
|
|
22847
22904
|
changedSources: sources
|
|
22848
22905
|
});
|
|
@@ -22856,12 +22913,53 @@ function inspectContextFreshness(repo, manifest) {
|
|
|
22856
22913
|
kind: review.kind,
|
|
22857
22914
|
target: review.target,
|
|
22858
22915
|
severity: "blocking",
|
|
22916
|
+
code: "orphan-review",
|
|
22859
22917
|
reason: "orphan review: \u5DF2\u590D\u6838\u7684 knowledge \u4ECD\u5728 manifest \u4E2D\uFF0C\u4F46\u4E0D\u518D\u58F0\u660E binds/authority\uFF0C\u5DF2\u6709\u590D\u6838\u4E0D\u80FD\u9759\u9ED8\u6D88\u5931",
|
|
22860
22918
|
changedSources: Object.keys(review.sources ?? {}).sort()
|
|
22861
22919
|
});
|
|
22862
22920
|
}
|
|
22863
22921
|
return issues;
|
|
22864
22922
|
}
|
|
22923
|
+
function repoRelative(path) {
|
|
22924
|
+
return import_node_path12.posix.normalize(path.split(import_node_path12.sep).join("/")).replace(/^\.\//, "").replace(/\/+$/, "");
|
|
22925
|
+
}
|
|
22926
|
+
function contextPaths(manifest, key) {
|
|
22927
|
+
const paths = [];
|
|
22928
|
+
for (const knowledge of manifest?.knowledge ?? []) {
|
|
22929
|
+
if (knowledgeKey(knowledge) !== key) continue;
|
|
22930
|
+
paths.push(repoRelative(knowledge.root === "repo" ? knowledge.path : `.agents/${knowledge.path}`));
|
|
22931
|
+
paths.push(...(knowledge.binds ?? []).map(repoRelative));
|
|
22932
|
+
}
|
|
22933
|
+
for (const module2 of manifest?.modules ?? []) {
|
|
22934
|
+
if (`module:${module2.name}` === key) paths.push(...(module2.entry ?? []).map(repoRelative));
|
|
22935
|
+
}
|
|
22936
|
+
return paths;
|
|
22937
|
+
}
|
|
22938
|
+
function contextDeclaration(manifest, key) {
|
|
22939
|
+
return JSON.stringify([
|
|
22940
|
+
...(manifest?.knowledge ?? []).filter((knowledge) => knowledgeKey(knowledge) === key).map((knowledge) => ({ binds: knowledge.binds ?? [], authority: knowledge.authority ?? null })),
|
|
22941
|
+
...(manifest?.modules ?? []).filter((module2) => `module:${module2.name}` === key).map(moduleContentHash)
|
|
22942
|
+
]);
|
|
22943
|
+
}
|
|
22944
|
+
function contextReviewEvidence(state, issue) {
|
|
22945
|
+
const legacyKey = issue.kind === "knowledge" ? issue.target : issue.key;
|
|
22946
|
+
return JSON.stringify([state?.reviews?.[issue.key] ?? null, state?.bindings?.[legacyKey] ?? null]);
|
|
22947
|
+
}
|
|
22948
|
+
function inheritedContextKeys(issues, current, base, changedFiles) {
|
|
22949
|
+
const inherited = /* @__PURE__ */ new Set();
|
|
22950
|
+
if (!base.manifest) return inherited;
|
|
22951
|
+
const changed = changedFiles.map(repoRelative);
|
|
22952
|
+
const touches = (path) => changed.some((file) => file === path || file.startsWith(`${path}/`));
|
|
22953
|
+
for (const issue of issues) {
|
|
22954
|
+
if (issue.severity !== "blocking") continue;
|
|
22955
|
+
if (contextDeclaration(current.manifest, issue.key) !== contextDeclaration(base.manifest, issue.key)) continue;
|
|
22956
|
+
if (contextReviewEvidence(current.state, issue) !== contextReviewEvidence(base.state, issue)) continue;
|
|
22957
|
+
const paths = [...contextPaths(current.manifest, issue.key), ...issue.changedSources.map(repoRelative)];
|
|
22958
|
+
if (paths.some(touches)) continue;
|
|
22959
|
+
inherited.add(issue.key);
|
|
22960
|
+
}
|
|
22961
|
+
return inherited;
|
|
22962
|
+
}
|
|
22865
22963
|
function recordContextReview(repo, manifest, opts) {
|
|
22866
22964
|
if (!!opts.path === !!opts.module) throw new Error("\u53EA\u80FD\u6307\u5B9A\u4E00\u4E2A --path \u6216 --module");
|
|
22867
22965
|
const reason = opts.reason?.trim();
|
|
@@ -22902,6 +23000,7 @@ var AGENTS_MAX_WORDS = 700;
|
|
|
22902
23000
|
function doctorCmd(repo, opts = {}) {
|
|
22903
23001
|
let problems = 0;
|
|
22904
23002
|
const m = loadManifest(repo);
|
|
23003
|
+
const render = { harnessVersion: lockedHarnessVersion(repo) };
|
|
22905
23004
|
info("1) Manifest validation");
|
|
22906
23005
|
const issues = validateManifest(m);
|
|
22907
23006
|
if (!issues.length) ok("schema looks good");
|
|
@@ -22961,18 +23060,18 @@ function doctorCmd(repo, opts = {}) {
|
|
|
22961
23060
|
}
|
|
22962
23061
|
info("\n2) Referenced paths");
|
|
22963
23062
|
const checkPath = (rel, label) => {
|
|
22964
|
-
if ((0,
|
|
23063
|
+
if ((0, import_node_fs13.existsSync)((0, import_node_path13.join)(repo, ".agents", rel))) ok(`${label}: ${rel}`);
|
|
22965
23064
|
else {
|
|
22966
23065
|
err(`${label} missing: .agents/${rel}`);
|
|
22967
23066
|
problems++;
|
|
22968
23067
|
}
|
|
22969
23068
|
};
|
|
22970
23069
|
const checkRepoPath = (rel, label, wantFile = false) => {
|
|
22971
|
-
const abs = (0,
|
|
22972
|
-
if (!(0,
|
|
23070
|
+
const abs = (0, import_node_path13.join)(repo, rel);
|
|
23071
|
+
if (!(0, import_node_fs13.existsSync)(abs)) {
|
|
22973
23072
|
err(`${label} points at a missing path: ${rel}`);
|
|
22974
23073
|
problems++;
|
|
22975
|
-
} else if (wantFile && (0,
|
|
23074
|
+
} else if (wantFile && (0, import_node_fs13.statSync)(abs).isDirectory()) {
|
|
22976
23075
|
warn(`${label}: ${rel} is a directory \u2014 entry/binds should be a file (freshness hashes file content)`);
|
|
22977
23076
|
} else ok(`${label}: ${rel}`);
|
|
22978
23077
|
};
|
|
@@ -22999,7 +23098,7 @@ function doctorCmd(repo, opts = {}) {
|
|
|
22999
23098
|
problems++;
|
|
23000
23099
|
continue;
|
|
23001
23100
|
}
|
|
23002
|
-
if ((0,
|
|
23101
|
+
if ((0, import_node_fs13.existsSync)(knowledgePath)) ok(`knowledge: ${k.path}`);
|
|
23003
23102
|
else {
|
|
23004
23103
|
err(`knowledge missing: ${k.root === "repo" ? "" : ".agents/"}${k.path}`);
|
|
23005
23104
|
problems++;
|
|
@@ -23014,11 +23113,11 @@ function doctorCmd(repo, opts = {}) {
|
|
|
23014
23113
|
for (const mod of m.modules ?? []) {
|
|
23015
23114
|
if (!mod.playbook) continue;
|
|
23016
23115
|
const candidates = [
|
|
23017
|
-
m.playbooks?.dir ? (0,
|
|
23018
|
-
(0,
|
|
23019
|
-
(0,
|
|
23116
|
+
m.playbooks?.dir ? (0, import_node_path13.join)(repo, ".agents", m.playbooks.dir, mod.playbook) : "",
|
|
23117
|
+
(0, import_node_path13.join)(repo, ".agents", mod.playbook),
|
|
23118
|
+
(0, import_node_path13.join)(repo, mod.playbook)
|
|
23020
23119
|
].filter(Boolean);
|
|
23021
|
-
if (candidates.some((c) => (0,
|
|
23120
|
+
if (candidates.some((c) => (0, import_node_fs13.existsSync)(c))) ok(`module ${mod.name} playbook: ${mod.playbook}`);
|
|
23022
23121
|
else {
|
|
23023
23122
|
err(`module ${mod.name} playbook missing: ${mod.playbook} (looked in ${m.playbooks?.dir ? `.agents/${m.playbooks.dir}/, ` : ""}.agents/, repo root)`);
|
|
23024
23123
|
problems++;
|
|
@@ -23026,7 +23125,7 @@ function doctorCmd(repo, opts = {}) {
|
|
|
23026
23125
|
}
|
|
23027
23126
|
info("\n3) Generated files drift");
|
|
23028
23127
|
try {
|
|
23029
|
-
for (const inspection of inspectManagedFiles(repo, renderTargets(m))) {
|
|
23128
|
+
for (const inspection of inspectManagedFiles(repo, renderTargets(m, render))) {
|
|
23030
23129
|
if (inspection.kind === "missing") warn(`${inspection.relativePath} not generated yet (run \`harness-kit sync\`)`);
|
|
23031
23130
|
else if (!inspection.satisfiesDesired) {
|
|
23032
23131
|
err(`${inspection.relativePath} drifted from manifest (run \`harness-kit sync\`)`);
|
|
@@ -23073,7 +23172,7 @@ function doctorCmd(repo, opts = {}) {
|
|
|
23073
23172
|
} else info(" details: `harness-kit doctor --details`");
|
|
23074
23173
|
}
|
|
23075
23174
|
info("\n6) AGENTS.md size budget (must stay short \u2014 agents read it every session)");
|
|
23076
|
-
const agents = renderAgentsMd(m);
|
|
23175
|
+
const agents = renderAgentsMd(m, render);
|
|
23077
23176
|
const nLines = agents.split("\n").length;
|
|
23078
23177
|
const nWords = agents.trim().split(/\s+/).length;
|
|
23079
23178
|
if (nLines > AGENTS_MAX_LINES || nWords > AGENTS_MAX_WORDS) {
|
|
@@ -23093,7 +23192,7 @@ function doctorCmd(repo, opts = {}) {
|
|
|
23093
23192
|
} else {
|
|
23094
23193
|
warn(`DEGRADED \u2014 configured: ${configuredAgents}; ${hooks.issues.join("; ")}`);
|
|
23095
23194
|
}
|
|
23096
|
-
const guidance = buildHarnessGuidance({ manifest: m, hooks });
|
|
23195
|
+
const guidance = buildHarnessGuidance({ manifest: m, hooks, cli: repoHarnessInvocation(repo) });
|
|
23097
23196
|
const visibleActions = opts.details ? guidance.nextActions : guidance.nextActions.filter((action) => action.priority === "required");
|
|
23098
23197
|
info("\nNEXT ACTIONS");
|
|
23099
23198
|
if (!visibleActions.length) ok("nothing required now");
|
|
@@ -23123,10 +23222,178 @@ function doctorCmd(repo, opts = {}) {
|
|
|
23123
23222
|
// src/commands/verify.ts
|
|
23124
23223
|
var import_node_child_process5 = require("node:child_process");
|
|
23125
23224
|
|
|
23225
|
+
// src/delivery.ts
|
|
23226
|
+
var import_node_crypto7 = require("node:crypto");
|
|
23227
|
+
var import_node_fs14 = require("node:fs");
|
|
23228
|
+
var import_node_path14 = require("node:path");
|
|
23229
|
+
var import_yaml3 = __toESM(require_dist(), 1);
|
|
23230
|
+
function canonicalTarget2(repo) {
|
|
23231
|
+
try {
|
|
23232
|
+
return (0, import_node_fs14.realpathSync)(repo);
|
|
23233
|
+
} catch {
|
|
23234
|
+
return (0, import_node_path14.resolve)(repo);
|
|
23235
|
+
}
|
|
23236
|
+
}
|
|
23237
|
+
function taskStateDir(repo) {
|
|
23238
|
+
return (0, import_node_path14.join)(gitAdminDir(repo), "harness-kit", "task");
|
|
23239
|
+
}
|
|
23240
|
+
function taskPath(repo) {
|
|
23241
|
+
return (0, import_node_path14.join)(taskStateDir(repo), `current-${sha256(canonicalTarget2(repo)).slice(0, 24)}.json`);
|
|
23242
|
+
}
|
|
23243
|
+
function writePrivateJson2(path, value) {
|
|
23244
|
+
(0, import_node_fs14.mkdirSync)((0, import_node_path14.dirname)(path), { recursive: true });
|
|
23245
|
+
const temp = `${path}.${process.pid}.${(0, import_node_crypto7.randomUUID)()}.tmp`;
|
|
23246
|
+
try {
|
|
23247
|
+
(0, import_node_fs14.writeFileSync)(temp, JSON.stringify(value, null, 2) + "\n", { mode: 384 });
|
|
23248
|
+
(0, import_node_fs14.renameSync)(temp, path);
|
|
23249
|
+
(0, import_node_fs14.chmodSync)(path, 384);
|
|
23250
|
+
} catch (error) {
|
|
23251
|
+
try {
|
|
23252
|
+
(0, import_node_fs14.unlinkSync)(temp);
|
|
23253
|
+
} catch {
|
|
23254
|
+
}
|
|
23255
|
+
throw error;
|
|
23256
|
+
}
|
|
23257
|
+
}
|
|
23258
|
+
function readTaskRecord(repoInput) {
|
|
23259
|
+
const repo = gitRoot(repoInput);
|
|
23260
|
+
const raw = readText(taskPath(repo));
|
|
23261
|
+
if (raw === null) return null;
|
|
23262
|
+
try {
|
|
23263
|
+
const value = JSON.parse(raw);
|
|
23264
|
+
if (value?.schema !== "ai-harness/task/v1" || typeof value.baseSha !== "string" || !value.baseSha) return null;
|
|
23265
|
+
return value;
|
|
23266
|
+
} catch {
|
|
23267
|
+
return null;
|
|
23268
|
+
}
|
|
23269
|
+
}
|
|
23270
|
+
function startTaskRecord(args) {
|
|
23271
|
+
const repo = gitRoot(args.repo);
|
|
23272
|
+
const head = collectChanges(repo, "HEAD", { mode: "exact" }).head;
|
|
23273
|
+
const baseSha = args.baseSha ?? head;
|
|
23274
|
+
if (!baseSha) throw new Error("cannot start task: repository has no HEAD commit and no --base was provided");
|
|
23275
|
+
collectChanges(repo, baseSha, { mode: "exact" });
|
|
23276
|
+
const record = {
|
|
23277
|
+
schema: "ai-harness/task/v1",
|
|
23278
|
+
baseSha,
|
|
23279
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
23280
|
+
...args.note?.trim() ? { note: args.note.trim() } : {},
|
|
23281
|
+
...args.hostSessionId ? { hostSessionId: args.hostSessionId } : {},
|
|
23282
|
+
...args.agent ? { agent: args.agent } : {}
|
|
23283
|
+
};
|
|
23284
|
+
writePrivateJson2(taskPath(repo), record);
|
|
23285
|
+
return record;
|
|
23286
|
+
}
|
|
23287
|
+
function resolveChangeScope(repoInput, opts = {}) {
|
|
23288
|
+
const repo = gitRoot(repoInput);
|
|
23289
|
+
if (opts.base !== void 0) {
|
|
23290
|
+
const changes2 = collectChanges(repo, opts.base, { mode: "exact" });
|
|
23291
|
+
return { kind: "explicit-base", base: opts.base, mode: "exact", changes: changes2, task: readTaskRecord(repo) };
|
|
23292
|
+
}
|
|
23293
|
+
const task = readTaskRecord(repo);
|
|
23294
|
+
if (task) {
|
|
23295
|
+
const changes2 = collectChanges(repo, task.baseSha, { mode: "exact" });
|
|
23296
|
+
return { kind: "task", base: task.baseSha, mode: "exact", changes: changes2, task };
|
|
23297
|
+
}
|
|
23298
|
+
const changes = collectChanges(repo, "HEAD", { mode: "exact" });
|
|
23299
|
+
return { kind: "worktree", base: "HEAD", mode: "exact", changes, task: null };
|
|
23300
|
+
}
|
|
23301
|
+
function stampFromEvidence(repo, session) {
|
|
23302
|
+
if (!session?.lastEvidence) {
|
|
23303
|
+
return { status: "missing", found: false, stale: false, valid: false, reason: "no delivery evidence recorded" };
|
|
23304
|
+
}
|
|
23305
|
+
const evidence = session.lastEvidence;
|
|
23306
|
+
const freshness = inspectValidationEvidenceFreshness(repo, evidence);
|
|
23307
|
+
const runChecksValid = (evidence.runChecksStatus !== void 0 ? evidence.runChecksStatus !== "not-verified" : evidence.ok && evidence.status !== "not-verified") && !freshness.stale;
|
|
23308
|
+
const verifyPassed = evidence.verifyPassed === true;
|
|
23309
|
+
const valid = runChecksValid && verifyPassed && !freshness.error;
|
|
23310
|
+
let status;
|
|
23311
|
+
if (freshness.stale || freshness.error) status = "stale";
|
|
23312
|
+
else if (evidence.status === "no-change" && verifyPassed) status = "no-change";
|
|
23313
|
+
else if (valid) status = "accepted";
|
|
23314
|
+
else status = "needs-work";
|
|
23315
|
+
return {
|
|
23316
|
+
status,
|
|
23317
|
+
found: true,
|
|
23318
|
+
fingerprint: evidence.fingerprint,
|
|
23319
|
+
planFingerprint: evidence.planFingerprint,
|
|
23320
|
+
runChecksStatus: evidence.runChecksStatus ?? evidence.status,
|
|
23321
|
+
verifyPassed: evidence.verifyPassed,
|
|
23322
|
+
scopeBase: evidence.resolvedBase ?? evidence.requestedBase,
|
|
23323
|
+
createdAt: evidence.createdAt,
|
|
23324
|
+
session: session.token,
|
|
23325
|
+
stale: freshness.stale || !!freshness.error,
|
|
23326
|
+
valid,
|
|
23327
|
+
reason: freshness.error || void 0
|
|
23328
|
+
};
|
|
23329
|
+
}
|
|
23330
|
+
function inspectDeliveryStamp(repoInput) {
|
|
23331
|
+
const repo = gitRoot(repoInput);
|
|
23332
|
+
try {
|
|
23333
|
+
return stampFromEvidence(repo, readLatestValidationSession(repo));
|
|
23334
|
+
} catch (error) {
|
|
23335
|
+
return {
|
|
23336
|
+
status: "missing",
|
|
23337
|
+
found: false,
|
|
23338
|
+
stale: false,
|
|
23339
|
+
valid: false,
|
|
23340
|
+
reason: `cannot read delivery stamp: ${error.message}`
|
|
23341
|
+
};
|
|
23342
|
+
}
|
|
23343
|
+
}
|
|
23344
|
+
function stampCoversScope(repoInput, scope) {
|
|
23345
|
+
const stamp = inspectDeliveryStamp(repoInput);
|
|
23346
|
+
if (!stamp.found || stamp.stale || !stamp.valid) return false;
|
|
23347
|
+
if (scope.changes.files.length === 0) return stamp.status === "no-change" || stamp.status === "accepted";
|
|
23348
|
+
return stamp.status === "accepted" && stamp.fingerprint === scope.changes.fingerprint;
|
|
23349
|
+
}
|
|
23350
|
+
function inheritedContextIssueKeys(repo, manifest, issues, base) {
|
|
23351
|
+
if (!issues.some((issue) => issue.severity === "blocking")) return /* @__PURE__ */ new Set();
|
|
23352
|
+
const changes = collectChanges(repo, base, { mode: "exact" });
|
|
23353
|
+
if (!changes.resolvedBase) return /* @__PURE__ */ new Set();
|
|
23354
|
+
const manifestText = readFileAtCommit(repo, changes.resolvedBase, MANIFEST_REL);
|
|
23355
|
+
if (manifestText === null) return /* @__PURE__ */ new Set();
|
|
23356
|
+
const parsed = import_yaml3.default.parse(manifestText);
|
|
23357
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return /* @__PURE__ */ new Set();
|
|
23358
|
+
const stateText = readFileAtCommit(repo, changes.resolvedBase, STATE_REL);
|
|
23359
|
+
const baseState = stateText ? parseState2(stateText) : null;
|
|
23360
|
+
return inheritedContextKeys(
|
|
23361
|
+
issues,
|
|
23362
|
+
{ manifest, state: readState(repo) },
|
|
23363
|
+
{ manifest: parsed, state: baseState },
|
|
23364
|
+
changes.files
|
|
23365
|
+
);
|
|
23366
|
+
}
|
|
23367
|
+
function locateHarnessTargets(repoInput) {
|
|
23368
|
+
const repo = (0, import_node_path14.resolve)(repoInput);
|
|
23369
|
+
if ((0, import_node_fs14.existsSync)((0, import_node_path14.join)(repo, MANIFEST_REL))) return { adopted: true, enclosing: null, nested: [] };
|
|
23370
|
+
let root;
|
|
23371
|
+
try {
|
|
23372
|
+
root = canonicalTarget2(gitRoot(repo));
|
|
23373
|
+
} catch {
|
|
23374
|
+
return { adopted: false, enclosing: null, nested: [] };
|
|
23375
|
+
}
|
|
23376
|
+
let enclosing = null;
|
|
23377
|
+
for (let dir = canonicalTarget2(repo); dir !== root && (0, import_node_path14.dirname)(dir) !== dir; ) {
|
|
23378
|
+
dir = (0, import_node_path14.dirname)(dir);
|
|
23379
|
+
if ((0, import_node_fs14.existsSync)((0, import_node_path14.join)(dir, MANIFEST_REL))) {
|
|
23380
|
+
enclosing = dir;
|
|
23381
|
+
break;
|
|
23382
|
+
}
|
|
23383
|
+
}
|
|
23384
|
+
let nested = [];
|
|
23385
|
+
try {
|
|
23386
|
+
const suffix = `/${MANIFEST_REL}`;
|
|
23387
|
+
nested = listWorktreeFiles(repo, `**/${MANIFEST_REL}`).filter((path) => path.endsWith(suffix)).map((path) => (0, import_node_path14.join)(repo, path.slice(0, -suffix.length))).sort();
|
|
23388
|
+
} catch {
|
|
23389
|
+
}
|
|
23390
|
+
return { adopted: false, enclosing, nested };
|
|
23391
|
+
}
|
|
23392
|
+
|
|
23126
23393
|
// src/enforce.ts
|
|
23127
23394
|
var import_fast_glob4 = __toESM(require_out4(), 1);
|
|
23128
|
-
var
|
|
23129
|
-
var
|
|
23395
|
+
var import_node_fs15 = require("node:fs");
|
|
23396
|
+
var import_node_path15 = require("node:path");
|
|
23130
23397
|
var DEFAULT_IGNORE = ["**/node_modules/**", "**/.git/**", "**/dist/**", "**/.agents/map/**"];
|
|
23131
23398
|
function runEnforcement(repo, invId, e) {
|
|
23132
23399
|
const globs = e.path_glob?.length ? e.path_glob : ["**/*"];
|
|
@@ -23143,7 +23410,7 @@ function runEnforcement(repo, invId, e) {
|
|
|
23143
23410
|
for (const rel of files) {
|
|
23144
23411
|
let content;
|
|
23145
23412
|
try {
|
|
23146
|
-
content = (0,
|
|
23413
|
+
content = (0, import_node_fs15.readFileSync)((0, import_node_path15.join)(repo, rel), "utf8");
|
|
23147
23414
|
} catch {
|
|
23148
23415
|
continue;
|
|
23149
23416
|
}
|
|
@@ -23234,7 +23501,7 @@ function verifyInternal(repo, opts) {
|
|
|
23234
23501
|
const messages = [];
|
|
23235
23502
|
let manifestErrors = [];
|
|
23236
23503
|
const hooks = safeInspectAgentHookStatus(repo);
|
|
23237
|
-
const guidance = buildHarnessGuidance({ manifest, hooks });
|
|
23504
|
+
const guidance = buildHarnessGuidance({ manifest, hooks, cli: repoHarnessInvocation(repo) });
|
|
23238
23505
|
const gaps = guidance.gapDetails.map((gap2) => gap2.legacyText);
|
|
23239
23506
|
const emit = (level, text) => {
|
|
23240
23507
|
messages.push({ level, text });
|
|
@@ -23307,7 +23574,7 @@ verify: FAILED (${manifestErrors.length} manifest problem(s))`);
|
|
|
23307
23574
|
}
|
|
23308
23575
|
emit("info", "1) Generated files in sync");
|
|
23309
23576
|
try {
|
|
23310
|
-
for (const inspection of inspectManagedFiles(repo, renderTargets(manifest))) {
|
|
23577
|
+
for (const inspection of inspectManagedFiles(repo, renderTargets(manifest, { harnessVersion: lockedHarnessVersion(repo) }))) {
|
|
23311
23578
|
if (inspection.kind === "missing") {
|
|
23312
23579
|
emit("error", `${inspection.relativePath} missing (run \`harness-kit sync\`)`);
|
|
23313
23580
|
failures++;
|
|
@@ -23323,14 +23590,29 @@ verify: FAILED (${manifestErrors.length} manifest problem(s))`);
|
|
|
23323
23590
|
}
|
|
23324
23591
|
emit("info", "\n2) Context freshness");
|
|
23325
23592
|
try {
|
|
23326
|
-
|
|
23327
|
-
|
|
23593
|
+
const issues = inspectContextFreshness(repo, manifest);
|
|
23594
|
+
let inherited = /* @__PURE__ */ new Set();
|
|
23595
|
+
if (opts.contextBase !== void 0) {
|
|
23596
|
+
try {
|
|
23597
|
+
inherited = inheritedContextIssueKeys(repo, manifest, issues, opts.contextBase);
|
|
23598
|
+
} catch (error) {
|
|
23599
|
+
emit("warn", `cannot compare context freshness with task base ${opts.contextBase}; treating it as task-scoped (${error.message})`);
|
|
23600
|
+
}
|
|
23601
|
+
}
|
|
23602
|
+
for (const issue of issues) {
|
|
23328
23603
|
const changed = issue.changedSources.length ? ` -> ${issue.changedSources.join(", ")}` : "";
|
|
23329
23604
|
const message = `${issue.key}: ${issue.reason}${changed}`;
|
|
23330
|
-
if (issue.severity === "blocking") {
|
|
23605
|
+
if (issue.severity === "blocking" && inherited.has(issue.key)) {
|
|
23606
|
+
context.push({ ...issue, inherited: true });
|
|
23607
|
+
emit("warn", `${message} (inherited: already stale on task base ${opts.contextBase}; not introduced by this task)`);
|
|
23608
|
+
} else if (issue.severity === "blocking") {
|
|
23609
|
+
context.push(issue);
|
|
23331
23610
|
failures++;
|
|
23332
23611
|
emit("error", message);
|
|
23333
|
-
} else
|
|
23612
|
+
} else {
|
|
23613
|
+
context.push(issue);
|
|
23614
|
+
emit("warn", message);
|
|
23615
|
+
}
|
|
23334
23616
|
}
|
|
23335
23617
|
} catch (error) {
|
|
23336
23618
|
failures++;
|
|
@@ -23531,19 +23813,19 @@ function acceptContractCmd(repo, id) {
|
|
|
23531
23813
|
}
|
|
23532
23814
|
|
|
23533
23815
|
// src/skill.ts
|
|
23534
|
-
var
|
|
23535
|
-
var
|
|
23816
|
+
var import_node_fs16 = require("node:fs");
|
|
23817
|
+
var import_node_path16 = require("node:path");
|
|
23536
23818
|
var import_node_url = require("node:url");
|
|
23537
23819
|
var import_meta = {};
|
|
23538
23820
|
function moduleDir() {
|
|
23539
23821
|
if (typeof __dirname !== "undefined" && __dirname) return __dirname;
|
|
23540
|
-
return (0,
|
|
23822
|
+
return (0, import_node_path16.dirname)((0, import_node_url.fileURLToPath)(import_meta.url));
|
|
23541
23823
|
}
|
|
23542
23824
|
var HERE = moduleDir();
|
|
23543
23825
|
function resolveSkill(skillRel) {
|
|
23544
|
-
for (const up of [".", "..", (0,
|
|
23545
|
-
const p = (0,
|
|
23546
|
-
if ((0,
|
|
23826
|
+
for (const up of [".", "..", (0, import_node_path16.join)("..", "..")]) {
|
|
23827
|
+
const p = (0, import_node_path16.join)(HERE, up, skillRel);
|
|
23828
|
+
if ((0, import_node_fs16.existsSync)(p)) return p;
|
|
23547
23829
|
}
|
|
23548
23830
|
return null;
|
|
23549
23831
|
}
|
|
@@ -23554,7 +23836,7 @@ function printSkill(skillRel, meta = "") {
|
|
|
23554
23836
|
return 1;
|
|
23555
23837
|
}
|
|
23556
23838
|
if (meta) process.stdout.write(meta);
|
|
23557
|
-
process.stdout.write((0,
|
|
23839
|
+
process.stdout.write((0, import_node_fs16.readFileSync)(p, "utf8"));
|
|
23558
23840
|
return 0;
|
|
23559
23841
|
}
|
|
23560
23842
|
|
|
@@ -23562,8 +23844,10 @@ function printSkill(skillRel, meta = "") {
|
|
|
23562
23844
|
var SKILL_REL = "skills/harness-check-loop/SKILL.md";
|
|
23563
23845
|
var META = `<!-- harness-kit check-loop -->
|
|
23564
23846
|
You are an AI agent implementing a requirement or fixing a bug in the CURRENT repo.
|
|
23565
|
-
Follow the loop below. Run every harness-kit command through
|
|
23566
|
-
\`npx -y @erzhe/harness-kit
|
|
23847
|
+
Follow the loop below. Run every harness-kit command through the pinned
|
|
23848
|
+
\`npx -y @erzhe/harness-kit@<version from .agents/harness.lock.json> <cmd>\`
|
|
23849
|
+
(the "Harness CLI" line in AGENTS.md; \`@latest\` only without a lock) unless a
|
|
23850
|
+
local build is available. A bare \`harness-kit\` is usually not on PATH.
|
|
23567
23851
|
Primary finish gate: \`harness-kit deliver\` (scope \u2192 run-checks + verify \u2192 stamp).
|
|
23568
23852
|
Optional Stop hooks only check that stamp; they must not demand a new session.
|
|
23569
23853
|
Use \`evidence\` to inspect the durable stamp.
|
|
@@ -23575,131 +23859,6 @@ function checkLoopCmd() {
|
|
|
23575
23859
|
return printSkill(SKILL_REL, META);
|
|
23576
23860
|
}
|
|
23577
23861
|
|
|
23578
|
-
// src/delivery.ts
|
|
23579
|
-
var import_node_crypto7 = require("node:crypto");
|
|
23580
|
-
var import_node_fs15 = require("node:fs");
|
|
23581
|
-
var import_node_path15 = require("node:path");
|
|
23582
|
-
function canonicalTarget2(repo) {
|
|
23583
|
-
try {
|
|
23584
|
-
return (0, import_node_fs15.realpathSync)(repo);
|
|
23585
|
-
} catch {
|
|
23586
|
-
return (0, import_node_path15.resolve)(repo);
|
|
23587
|
-
}
|
|
23588
|
-
}
|
|
23589
|
-
function taskStateDir(repo) {
|
|
23590
|
-
return (0, import_node_path15.join)(gitAdminDir(repo), "harness-kit", "task");
|
|
23591
|
-
}
|
|
23592
|
-
function taskPath(repo) {
|
|
23593
|
-
return (0, import_node_path15.join)(taskStateDir(repo), `current-${sha256(canonicalTarget2(repo)).slice(0, 24)}.json`);
|
|
23594
|
-
}
|
|
23595
|
-
function writePrivateJson2(path, value) {
|
|
23596
|
-
(0, import_node_fs15.mkdirSync)((0, import_node_path15.dirname)(path), { recursive: true });
|
|
23597
|
-
const temp = `${path}.${process.pid}.${(0, import_node_crypto7.randomUUID)()}.tmp`;
|
|
23598
|
-
try {
|
|
23599
|
-
(0, import_node_fs15.writeFileSync)(temp, JSON.stringify(value, null, 2) + "\n", { mode: 384 });
|
|
23600
|
-
(0, import_node_fs15.renameSync)(temp, path);
|
|
23601
|
-
(0, import_node_fs15.chmodSync)(path, 384);
|
|
23602
|
-
} catch (error) {
|
|
23603
|
-
try {
|
|
23604
|
-
(0, import_node_fs15.unlinkSync)(temp);
|
|
23605
|
-
} catch {
|
|
23606
|
-
}
|
|
23607
|
-
throw error;
|
|
23608
|
-
}
|
|
23609
|
-
}
|
|
23610
|
-
function readTaskRecord(repoInput) {
|
|
23611
|
-
const repo = gitRoot(repoInput);
|
|
23612
|
-
const raw = readText(taskPath(repo));
|
|
23613
|
-
if (raw === null) return null;
|
|
23614
|
-
try {
|
|
23615
|
-
const value = JSON.parse(raw);
|
|
23616
|
-
if (value?.schema !== "ai-harness/task/v1" || typeof value.baseSha !== "string" || !value.baseSha) return null;
|
|
23617
|
-
return value;
|
|
23618
|
-
} catch {
|
|
23619
|
-
return null;
|
|
23620
|
-
}
|
|
23621
|
-
}
|
|
23622
|
-
function startTaskRecord(args) {
|
|
23623
|
-
const repo = gitRoot(args.repo);
|
|
23624
|
-
const head = collectChanges(repo, "HEAD", { mode: "exact" }).head;
|
|
23625
|
-
const baseSha = args.baseSha ?? head;
|
|
23626
|
-
if (!baseSha) throw new Error("cannot start task: repository has no HEAD commit and no --base was provided");
|
|
23627
|
-
collectChanges(repo, baseSha, { mode: "exact" });
|
|
23628
|
-
const record = {
|
|
23629
|
-
schema: "ai-harness/task/v1",
|
|
23630
|
-
baseSha,
|
|
23631
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
23632
|
-
...args.note?.trim() ? { note: args.note.trim() } : {},
|
|
23633
|
-
...args.hostSessionId ? { hostSessionId: args.hostSessionId } : {},
|
|
23634
|
-
...args.agent ? { agent: args.agent } : {}
|
|
23635
|
-
};
|
|
23636
|
-
writePrivateJson2(taskPath(repo), record);
|
|
23637
|
-
return record;
|
|
23638
|
-
}
|
|
23639
|
-
function resolveChangeScope(repoInput, opts = {}) {
|
|
23640
|
-
const repo = gitRoot(repoInput);
|
|
23641
|
-
if (opts.base !== void 0) {
|
|
23642
|
-
const changes2 = collectChanges(repo, opts.base, { mode: "exact" });
|
|
23643
|
-
return { kind: "explicit-base", base: opts.base, mode: "exact", changes: changes2, task: readTaskRecord(repo) };
|
|
23644
|
-
}
|
|
23645
|
-
const task = readTaskRecord(repo);
|
|
23646
|
-
if (task) {
|
|
23647
|
-
const changes2 = collectChanges(repo, task.baseSha, { mode: "exact" });
|
|
23648
|
-
return { kind: "task", base: task.baseSha, mode: "exact", changes: changes2, task };
|
|
23649
|
-
}
|
|
23650
|
-
const changes = collectChanges(repo, "HEAD", { mode: "exact" });
|
|
23651
|
-
return { kind: "worktree", base: "HEAD", mode: "exact", changes, task: null };
|
|
23652
|
-
}
|
|
23653
|
-
function stampFromEvidence(repo, session) {
|
|
23654
|
-
if (!session?.lastEvidence) {
|
|
23655
|
-
return { status: "missing", found: false, stale: false, valid: false, reason: "no delivery evidence recorded" };
|
|
23656
|
-
}
|
|
23657
|
-
const evidence = session.lastEvidence;
|
|
23658
|
-
const freshness = inspectValidationEvidenceFreshness(repo, evidence);
|
|
23659
|
-
const runChecksValid = (evidence.runChecksStatus !== void 0 ? evidence.runChecksStatus !== "not-verified" : evidence.ok && evidence.status !== "not-verified") && !freshness.stale;
|
|
23660
|
-
const verifyPassed = evidence.verifyPassed === true;
|
|
23661
|
-
const valid = runChecksValid && verifyPassed && !freshness.error;
|
|
23662
|
-
let status;
|
|
23663
|
-
if (freshness.stale || freshness.error) status = "stale";
|
|
23664
|
-
else if (evidence.status === "no-change" && verifyPassed) status = "no-change";
|
|
23665
|
-
else if (valid) status = "accepted";
|
|
23666
|
-
else status = "needs-work";
|
|
23667
|
-
return {
|
|
23668
|
-
status,
|
|
23669
|
-
found: true,
|
|
23670
|
-
fingerprint: evidence.fingerprint,
|
|
23671
|
-
planFingerprint: evidence.planFingerprint,
|
|
23672
|
-
runChecksStatus: evidence.runChecksStatus ?? evidence.status,
|
|
23673
|
-
verifyPassed: evidence.verifyPassed,
|
|
23674
|
-
scopeBase: evidence.resolvedBase ?? evidence.requestedBase,
|
|
23675
|
-
createdAt: evidence.createdAt,
|
|
23676
|
-
session: session.token,
|
|
23677
|
-
stale: freshness.stale || !!freshness.error,
|
|
23678
|
-
valid,
|
|
23679
|
-
reason: freshness.error || void 0
|
|
23680
|
-
};
|
|
23681
|
-
}
|
|
23682
|
-
function inspectDeliveryStamp(repoInput) {
|
|
23683
|
-
const repo = gitRoot(repoInput);
|
|
23684
|
-
try {
|
|
23685
|
-
return stampFromEvidence(repo, readLatestValidationSession(repo));
|
|
23686
|
-
} catch (error) {
|
|
23687
|
-
return {
|
|
23688
|
-
status: "missing",
|
|
23689
|
-
found: false,
|
|
23690
|
-
stale: false,
|
|
23691
|
-
valid: false,
|
|
23692
|
-
reason: `cannot read delivery stamp: ${error.message}`
|
|
23693
|
-
};
|
|
23694
|
-
}
|
|
23695
|
-
}
|
|
23696
|
-
function stampCoversScope(repoInput, scope) {
|
|
23697
|
-
const stamp = inspectDeliveryStamp(repoInput);
|
|
23698
|
-
if (!stamp.found || stamp.stale || !stamp.valid) return false;
|
|
23699
|
-
if (scope.changes.files.length === 0) return stamp.status === "no-change" || stamp.status === "accepted";
|
|
23700
|
-
return stamp.status === "accepted" && stamp.fingerprint === scope.changes.fingerprint;
|
|
23701
|
-
}
|
|
23702
|
-
|
|
23703
23862
|
// src/commands/evidence.ts
|
|
23704
23863
|
function safeHookStatus(repo) {
|
|
23705
23864
|
try {
|
|
@@ -23736,7 +23895,7 @@ function evidenceCmd(repo, opts = {}) {
|
|
|
23736
23895
|
}
|
|
23737
23896
|
const hooks = safeHookStatus(repo);
|
|
23738
23897
|
if (!session?.lastEvidence) {
|
|
23739
|
-
const guidance2 = buildHarnessGuidance({ hooks, evidence: { found: false } });
|
|
23898
|
+
const guidance2 = buildHarnessGuidance({ hooks, evidence: { found: false }, cli: repoHarnessInvocation(repo) });
|
|
23740
23899
|
if (opts.json) {
|
|
23741
23900
|
process.stdout.write(
|
|
23742
23901
|
JSON.stringify(
|
|
@@ -23771,7 +23930,8 @@ function evidenceCmd(repo, opts = {}) {
|
|
|
23771
23930
|
const stamp = inspectDeliveryStamp(repo);
|
|
23772
23931
|
const guidance = buildHarnessGuidance({
|
|
23773
23932
|
hooks,
|
|
23774
|
-
evidence: { found: true, stale, runChecksValid, verifyPassed: evidence.verifyPassed, valid }
|
|
23933
|
+
evidence: { found: true, stale, runChecksValid, verifyPassed: evidence.verifyPassed, valid },
|
|
23934
|
+
cli: repoHarnessInvocation(repo)
|
|
23775
23935
|
});
|
|
23776
23936
|
const result = {
|
|
23777
23937
|
...body,
|
|
@@ -23829,7 +23989,10 @@ function evidenceCmd(repo, opts = {}) {
|
|
|
23829
23989
|
}
|
|
23830
23990
|
|
|
23831
23991
|
// src/commands/hook-event.ts
|
|
23832
|
-
var
|
|
23992
|
+
var import_node_fs17 = require("node:fs");
|
|
23993
|
+
|
|
23994
|
+
// src/commands/deliver.ts
|
|
23995
|
+
var import_node_path17 = require("node:path");
|
|
23833
23996
|
|
|
23834
23997
|
// src/commands/run-checks.ts
|
|
23835
23998
|
var import_node_child_process6 = require("node:child_process");
|
|
@@ -24122,6 +24285,7 @@ function runChecksCmd(repo, opts) {
|
|
|
24122
24285
|
}
|
|
24123
24286
|
|
|
24124
24287
|
// src/commands/deliver.ts
|
|
24288
|
+
var DELIVER_NOT_ADOPTED_EXIT_CODE = 3;
|
|
24125
24289
|
function captureStdout(fn) {
|
|
24126
24290
|
const chunks = [];
|
|
24127
24291
|
const original = process.stdout.write.bind(process.stdout);
|
|
@@ -24147,7 +24311,18 @@ function parseRunReport(output) {
|
|
|
24147
24311
|
return null;
|
|
24148
24312
|
}
|
|
24149
24313
|
}
|
|
24150
|
-
function
|
|
24314
|
+
function parseVerifyReport(output) {
|
|
24315
|
+
try {
|
|
24316
|
+
const report = JSON.parse(output);
|
|
24317
|
+
return report?.schema === "ai-harness/verify-report/v1" ? report : null;
|
|
24318
|
+
} catch {
|
|
24319
|
+
return null;
|
|
24320
|
+
}
|
|
24321
|
+
}
|
|
24322
|
+
function shellArg(value) {
|
|
24323
|
+
return /^[A-Za-z0-9_./@:+=,-]+$/.test(value) ? value : `'${value.replace(/'/g, `'\\''`)}'`;
|
|
24324
|
+
}
|
|
24325
|
+
function nextActions(status, report, cli) {
|
|
24151
24326
|
if (status === "accepted" || status === "no-change") return [];
|
|
24152
24327
|
const next = [];
|
|
24153
24328
|
if (report) {
|
|
@@ -24161,13 +24336,59 @@ function nextActions(status, report) {
|
|
|
24161
24336
|
next.push(`resolve skipped check ${skipped.id}: ${skipped.reason}`);
|
|
24162
24337
|
}
|
|
24163
24338
|
}
|
|
24164
|
-
next.push(
|
|
24339
|
+
next.push(`re-run: ${cli} deliver --repo .`);
|
|
24165
24340
|
return next;
|
|
24166
24341
|
}
|
|
24167
|
-
function
|
|
24342
|
+
function inheritedContextActions(issues, base, cli) {
|
|
24343
|
+
return issues.map((issue) => {
|
|
24344
|
+
const changed = issue.changedSources.length ? ` (${issue.changedSources.join(", ")})` : "";
|
|
24345
|
+
const action = {
|
|
24346
|
+
id: `refresh-inherited-context:${issue.key}`,
|
|
24347
|
+
priority: "recommended",
|
|
24348
|
+
owner: "agent",
|
|
24349
|
+
when: "harness-maintenance",
|
|
24350
|
+
title: `Refresh inherited context review: ${issue.target}`,
|
|
24351
|
+
reason: `${issue.reason}${changed}. It was already stale on task base ${base} and this task did not touch its inputs, so it does not block this delivery. Refresh it in a dedicated Harness-maintenance change, not in this task's diff.`,
|
|
24352
|
+
commands: [],
|
|
24353
|
+
completion: "verify reports no context freshness issue for this item."
|
|
24354
|
+
};
|
|
24355
|
+
if (issue.code === "source-missing") {
|
|
24356
|
+
action.title = `Fix missing bound sources: ${issue.target}`;
|
|
24357
|
+
action.reason += ` Update its binds/entry in .agents/manifest.yaml first; a review cannot be recorded against missing sources.`;
|
|
24358
|
+
return action;
|
|
24359
|
+
}
|
|
24360
|
+
if (issue.code === "orphan-review") {
|
|
24361
|
+
action.title = `Resolve orphan context review: ${issue.target}`;
|
|
24362
|
+
action.reason += ` Restore its binds/authority in .agents/manifest.yaml, or retire the stale review record deliberately.`;
|
|
24363
|
+
return action;
|
|
24364
|
+
}
|
|
24365
|
+
if (issue.changedSources.length) action.commands.push(`git log -n 5 --oneline -- ${issue.changedSources.map(shellArg).join(" ")}`);
|
|
24366
|
+
const selector = issue.kind === "knowledge" ? `--path ${shellArg(issue.target)}` : `--module ${shellArg(issue.target)}`;
|
|
24367
|
+
action.commands.push(`${cli} record-context-review --repo . ${selector} --reason "<what you re-checked>"`);
|
|
24368
|
+
return action;
|
|
24369
|
+
});
|
|
24370
|
+
}
|
|
24371
|
+
function printActions(actions) {
|
|
24372
|
+
for (const action of actions) {
|
|
24373
|
+
warn(`[${action.priority.toUpperCase()} | ${action.owner.toUpperCase()}] ${action.title}`);
|
|
24374
|
+
info(` why: ${action.reason}`);
|
|
24375
|
+
for (const command of action.commands) info(` run: ${command}`);
|
|
24376
|
+
info(` done when: ${action.completion}`);
|
|
24377
|
+
}
|
|
24378
|
+
}
|
|
24379
|
+
function reportHuman2(report, cli) {
|
|
24380
|
+
if (report.status === "not-adopted" || report.harnessTargets) {
|
|
24381
|
+
for (const message of report.errors) err(message);
|
|
24382
|
+
if (report.status === "not-adopted")
|
|
24383
|
+
warn("deliver: NOT-ADOPTED \u2014 no .agents/manifest.yaml covers this directory; harness-kit cannot accept changes here");
|
|
24384
|
+
else err("deliver: NEEDS-WORK \u2014 run deliver at the Harness target root");
|
|
24385
|
+
info("\nNEXT ACTIONS");
|
|
24386
|
+
printActions(report.nextActions);
|
|
24387
|
+
return;
|
|
24388
|
+
}
|
|
24168
24389
|
info(`deliver (scope=${report.scope}, base ${report.base}) \u2014 ${report.changed.length} changed file(s)`);
|
|
24169
24390
|
if (report.scope === "worktree" && report.status !== "no-change") {
|
|
24170
|
-
info(
|
|
24391
|
+
info(` using worktree diff vs HEAD (no task base); for committed task range run: ${cli} task-start`);
|
|
24171
24392
|
}
|
|
24172
24393
|
if (report.runChecks) {
|
|
24173
24394
|
info(` run-checks: ${report.runChecks.status} (${report.runChecks.passed.length} passed, ${report.runChecks.failed.length} failed)`);
|
|
@@ -24182,6 +24403,15 @@ function reportHuman2(report) {
|
|
|
24182
24403
|
}
|
|
24183
24404
|
if (report.verifyPassed) ok("verify: passed");
|
|
24184
24405
|
else err("verify: failed");
|
|
24406
|
+
if (report.inheritedContext.length) {
|
|
24407
|
+
warn(
|
|
24408
|
+
`context freshness: ${report.inheritedContext.length} issue(s) already stale on task base ${report.base} \u2014 not introduced by this task, so they do not block acceptance:`
|
|
24409
|
+
);
|
|
24410
|
+
for (const issue of report.inheritedContext) {
|
|
24411
|
+
const changed = issue.changedSources.length ? ` -> ${issue.changedSources.join(", ")}` : "";
|
|
24412
|
+
info(` ${issue.key}: ${issue.reason}${changed}`);
|
|
24413
|
+
}
|
|
24414
|
+
}
|
|
24185
24415
|
for (const message of report.errors) err(message);
|
|
24186
24416
|
info("");
|
|
24187
24417
|
if (report.status === "accepted") ok("deliver: ACCEPTED \u2014 task stamp is valid for this fingerprint");
|
|
@@ -24191,8 +24421,101 @@ function reportHuman2(report) {
|
|
|
24191
24421
|
info("\nNEXT");
|
|
24192
24422
|
for (const step of report.next) info(` - ${step}`);
|
|
24193
24423
|
}
|
|
24424
|
+
const maintenance = report.nextActions.filter((action) => action.priority === "recommended");
|
|
24425
|
+
if (maintenance.length) {
|
|
24426
|
+
info("\nMAINTENANCE (recommended; keep out of this task's diff unless the task is Harness maintenance)");
|
|
24427
|
+
printActions(maintenance);
|
|
24428
|
+
}
|
|
24429
|
+
}
|
|
24430
|
+
function emitReport(report, json, cli) {
|
|
24431
|
+
if (json) process.stdout.write(JSON.stringify(report, null, 2) + "\n");
|
|
24432
|
+
else reportHuman2(report, cli);
|
|
24433
|
+
if (report.status === "not-adopted") return DELIVER_NOT_ADOPTED_EXIT_CODE;
|
|
24434
|
+
return report.ok ? 0 : 1;
|
|
24435
|
+
}
|
|
24436
|
+
function unadoptedReport(repo, opts, targets) {
|
|
24437
|
+
let scope = null;
|
|
24438
|
+
try {
|
|
24439
|
+
scope = resolveChangeScope(repo, { base: opts.base });
|
|
24440
|
+
} catch {
|
|
24441
|
+
}
|
|
24442
|
+
const base = {
|
|
24443
|
+
schema: "ai-harness/deliver-report/v1",
|
|
24444
|
+
ok: false,
|
|
24445
|
+
scope: scope?.kind ?? "worktree",
|
|
24446
|
+
base: scope?.base ?? opts.base ?? "HEAD",
|
|
24447
|
+
fingerprint: scope?.changes.fingerprint ?? "",
|
|
24448
|
+
changed: scope?.changes.files ?? [],
|
|
24449
|
+
runChecks: null,
|
|
24450
|
+
verifyPassed: false,
|
|
24451
|
+
stamp: { status: "missing", found: false, stale: false, valid: false, reason: "no Harness manifest in this directory" },
|
|
24452
|
+
inheritedContext: [],
|
|
24453
|
+
harnessTargets: { enclosing: targets.enclosing, nested: targets.nested }
|
|
24454
|
+
};
|
|
24455
|
+
if (targets.enclosing) {
|
|
24456
|
+
const command = `${repoHarnessInvocation(targets.enclosing)} deliver --repo ${shellArg(targets.enclosing)}`;
|
|
24457
|
+
return {
|
|
24458
|
+
...base,
|
|
24459
|
+
status: "needs-work",
|
|
24460
|
+
adopted: true,
|
|
24461
|
+
errors: [`${repo} is inside Harness target ${targets.enclosing}; deliver must run at the target root`],
|
|
24462
|
+
next: [`re-run at the Harness target root: ${command}`],
|
|
24463
|
+
nextActions: [
|
|
24464
|
+
{
|
|
24465
|
+
id: "deliver-at-harness-target-root",
|
|
24466
|
+
priority: "required",
|
|
24467
|
+
owner: "agent",
|
|
24468
|
+
when: "before-finish",
|
|
24469
|
+
title: "Re-run deliver at the Harness target root",
|
|
24470
|
+
reason: `The manifest for this directory lives in ${targets.enclosing}.`,
|
|
24471
|
+
commands: [command],
|
|
24472
|
+
completion: "deliver at the target root reports status=accepted (or no-change on a clean tree)."
|
|
24473
|
+
}
|
|
24474
|
+
]
|
|
24475
|
+
};
|
|
24476
|
+
}
|
|
24477
|
+
const touched = targets.nested.filter((dir) => base.changed.some((file) => (0, import_node_path17.join)(repo, file).startsWith(`${dir}/`)));
|
|
24478
|
+
const nestedCommands = touched.map((dir) => `${repoHarnessInvocation(dir)} deliver --repo ${shellArg(dir)}`);
|
|
24479
|
+
const nextActions2 = [
|
|
24480
|
+
{
|
|
24481
|
+
id: "validate-with-repository-conventions",
|
|
24482
|
+
priority: "required",
|
|
24483
|
+
owner: "agent",
|
|
24484
|
+
when: "before-finish",
|
|
24485
|
+
title: "Validate with this repository's own conventions",
|
|
24486
|
+
reason: "No .agents/manifest.yaml covers this directory, so harness-kit cannot accept the change and re-running deliver will not help.",
|
|
24487
|
+
commands: [],
|
|
24488
|
+
completion: "The checks this repository documents (README / CONTRIBUTING / package scripts / CI config) pass, and the report names which ones ran."
|
|
24489
|
+
}
|
|
24490
|
+
];
|
|
24491
|
+
if (nestedCommands.length) {
|
|
24492
|
+
nextActions2.push({
|
|
24493
|
+
id: "deliver-nested-harness-targets",
|
|
24494
|
+
priority: "required",
|
|
24495
|
+
owner: "agent",
|
|
24496
|
+
when: "before-finish",
|
|
24497
|
+
title: "Deliver the changed nested Harness targets",
|
|
24498
|
+
reason: `Changed files fall inside nested Harness targets: ${touched.join(", ")}.`,
|
|
24499
|
+
commands: nestedCommands,
|
|
24500
|
+
completion: "Each listed target reports status=accepted."
|
|
24501
|
+
});
|
|
24502
|
+
}
|
|
24503
|
+
return {
|
|
24504
|
+
...base,
|
|
24505
|
+
status: "not-adopted",
|
|
24506
|
+
adopted: false,
|
|
24507
|
+
errors: [],
|
|
24508
|
+
next: [
|
|
24509
|
+
"this directory is not adopted by harness-kit (no .agents/manifest.yaml): validate with the repository's own conventions; do not re-run deliver here",
|
|
24510
|
+
...nestedCommands.map((command) => `changed nested Harness target: ${command}`)
|
|
24511
|
+
],
|
|
24512
|
+
nextActions: nextActions2
|
|
24513
|
+
};
|
|
24194
24514
|
}
|
|
24195
24515
|
function deliverCmd(repo, opts = {}) {
|
|
24516
|
+
const cli = repoHarnessInvocation(repo);
|
|
24517
|
+
const targets = locateHarnessTargets(repo);
|
|
24518
|
+
if (!targets.adopted) return emitReport(unadoptedReport(repo, opts, targets), opts.json, cli);
|
|
24196
24519
|
const errors = [];
|
|
24197
24520
|
let scope;
|
|
24198
24521
|
try {
|
|
@@ -24216,15 +24539,19 @@ function deliverCmd(repo, opts = {}) {
|
|
|
24216
24539
|
const verify = captureStdout(
|
|
24217
24540
|
() => verifyCmd(repo, {
|
|
24218
24541
|
recordManualEvidence: true,
|
|
24542
|
+
json: true,
|
|
24543
|
+
contextBase: scope.base,
|
|
24219
24544
|
budgetMs: Number(process.env.HARNESS_KIT_DELIVER_VERIFY_BUDGET_MS) || 60 * 60 * 1e3
|
|
24220
24545
|
})
|
|
24221
24546
|
);
|
|
24222
24547
|
const verifyPassed = verify.code === 0;
|
|
24548
|
+
const verifyReport = parseVerifyReport(verify.output);
|
|
24223
24549
|
if (!verifyPassed) {
|
|
24224
|
-
const
|
|
24225
|
-
if (
|
|
24550
|
+
const failures = verifyReport ? verifyReport.messages.filter((message) => message.level === "error").map((message) => message.text).slice(0, 8) : verify.output.trim().split("\n").filter(Boolean).slice(-8);
|
|
24551
|
+
if (failures.length) errors.push(`verify failed: ${failures.join(" | ")}`);
|
|
24226
24552
|
else errors.push("verify failed");
|
|
24227
24553
|
}
|
|
24554
|
+
const inheritedContext = (verifyReport?.context ?? []).filter((issue) => issue.inherited);
|
|
24228
24555
|
let fingerprintError = "";
|
|
24229
24556
|
if (runReport?.fingerprint) {
|
|
24230
24557
|
try {
|
|
@@ -24244,11 +24571,25 @@ function deliverCmd(repo, opts = {}) {
|
|
|
24244
24571
|
if (runOk && verifyPassed && stable && runReport?.status === "no-change") status = "no-change";
|
|
24245
24572
|
else if (runOk && verifyPassed && stable) status = "accepted";
|
|
24246
24573
|
else status = "needs-work";
|
|
24574
|
+
const actions = inheritedContextActions(inheritedContext, scope.base, cli);
|
|
24575
|
+
if (status === "needs-work") {
|
|
24576
|
+
actions.unshift({
|
|
24577
|
+
id: "fix-delivery-failures",
|
|
24578
|
+
priority: "required",
|
|
24579
|
+
owner: "agent",
|
|
24580
|
+
when: "before-finish",
|
|
24581
|
+
title: "Fix deliver failures and re-run deliver",
|
|
24582
|
+
reason: errors.length ? errors.slice(0, 3).join("; ") : "run-checks did not pass for this change.",
|
|
24583
|
+
commands: [`${cli} deliver --repo .`],
|
|
24584
|
+
completion: "deliver reports status=accepted (or no-change on a clean tree)."
|
|
24585
|
+
});
|
|
24586
|
+
}
|
|
24247
24587
|
const stamp = inspectDeliveryStamp(repo);
|
|
24248
24588
|
const report = {
|
|
24249
24589
|
schema: "ai-harness/deliver-report/v1",
|
|
24250
24590
|
status,
|
|
24251
24591
|
ok: status === "accepted" || status === "no-change",
|
|
24592
|
+
adopted: true,
|
|
24252
24593
|
scope: scope.kind,
|
|
24253
24594
|
base: scope.base,
|
|
24254
24595
|
fingerprint: runReport?.fingerprint ?? scope.changes.fingerprint,
|
|
@@ -24256,15 +24597,12 @@ function deliverCmd(repo, opts = {}) {
|
|
|
24256
24597
|
runChecks: runReport,
|
|
24257
24598
|
verifyPassed,
|
|
24258
24599
|
stamp,
|
|
24600
|
+
inheritedContext,
|
|
24259
24601
|
errors,
|
|
24260
|
-
next: nextActions(status, runReport)
|
|
24602
|
+
next: nextActions(status, runReport, cli),
|
|
24603
|
+
nextActions: actions
|
|
24261
24604
|
};
|
|
24262
|
-
|
|
24263
|
-
process.stdout.write(JSON.stringify(report, null, 2) + "\n");
|
|
24264
|
-
} else {
|
|
24265
|
-
reportHuman2(report);
|
|
24266
|
-
}
|
|
24267
|
-
return report.ok ? 0 : 1;
|
|
24605
|
+
return emitReport(report, opts.json, cli);
|
|
24268
24606
|
}
|
|
24269
24607
|
|
|
24270
24608
|
// src/commands/hook-event.ts
|
|
@@ -24279,7 +24617,7 @@ function stopMode() {
|
|
|
24279
24617
|
return raw === "execute" || raw === "thick" ? "execute" : "thin";
|
|
24280
24618
|
}
|
|
24281
24619
|
function readPayload() {
|
|
24282
|
-
const raw = (0,
|
|
24620
|
+
const raw = (0, import_node_fs17.readFileSync)(0, "utf8").trim();
|
|
24283
24621
|
if (!raw) return {};
|
|
24284
24622
|
const value = JSON.parse(raw);
|
|
24285
24623
|
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("hook stdin must be a JSON object");
|
|
@@ -24329,17 +24667,17 @@ function parseRunReport2(output) {
|
|
|
24329
24667
|
return null;
|
|
24330
24668
|
}
|
|
24331
24669
|
}
|
|
24332
|
-
function deliverBlockMessage(extra = "") {
|
|
24670
|
+
function deliverBlockMessage(cli, extra = "") {
|
|
24333
24671
|
const lines = [
|
|
24334
24672
|
"harness-kit: delivery is not verified; continue working before stopping.",
|
|
24335
|
-
|
|
24673
|
+
`Run: ${cli} deliver --repo .`,
|
|
24336
24674
|
"Only status=accepted (or no-change with a clean tree) may finish.",
|
|
24337
24675
|
"Fix failures from deliver, then finish again."
|
|
24338
24676
|
];
|
|
24339
24677
|
if (extra.trim()) lines.splice(1, 0, extra.trim());
|
|
24340
24678
|
return lines.join("\n");
|
|
24341
24679
|
}
|
|
24342
|
-
function failureMessage(report, verifyOutput, token) {
|
|
24680
|
+
function failureMessage(report, verifyOutput, token, cli) {
|
|
24343
24681
|
const lines = ["harness-kit: delivery is not verified; continue working before stopping."];
|
|
24344
24682
|
if (!report) lines.push("run-checks did not return valid evidence.");
|
|
24345
24683
|
else {
|
|
@@ -24362,18 +24700,19 @@ function failureMessage(report, verifyOutput, token) {
|
|
|
24362
24700
|
const actionable = outputLines.filter((line) => /\bERR\b|timed out|budget exhausted|verify: FAILED/.test(line));
|
|
24363
24701
|
lines.push(`- verify: ${(actionable.length ? actionable.slice(-8) : outputLines.slice(-8)).join(" | ")}`);
|
|
24364
24702
|
}
|
|
24365
|
-
lines.push(
|
|
24703
|
+
lines.push(`Prefer: ${cli} deliver --repo . (then finish again)`);
|
|
24366
24704
|
lines.push(
|
|
24367
|
-
`For a genuine non-goal coverage gap only:
|
|
24705
|
+
`For a genuine non-goal coverage gap only: ${cli} run-checks --repo . --session ${token} --waive <kind> --where <scope> --reason "<why>"`
|
|
24368
24706
|
);
|
|
24369
24707
|
return lines.join("\n");
|
|
24370
24708
|
}
|
|
24371
24709
|
function thinStop(repo, agent) {
|
|
24710
|
+
const cli = repoHarnessInvocation(repo);
|
|
24372
24711
|
let scope;
|
|
24373
24712
|
try {
|
|
24374
24713
|
scope = resolveChangeScope(repo);
|
|
24375
24714
|
} catch (error) {
|
|
24376
|
-
return block(agent, "stop", deliverBlockMessage(`cannot resolve changes: ${error.message}`));
|
|
24715
|
+
return block(agent, "stop", deliverBlockMessage(cli, `cannot resolve changes: ${error.message}`));
|
|
24377
24716
|
}
|
|
24378
24717
|
if (scope.changes.files.length === 0) return allow(agent);
|
|
24379
24718
|
if (stampCoversScope(repo, scope)) return allow(agent);
|
|
@@ -24381,17 +24720,19 @@ function thinStop(repo, agent) {
|
|
|
24381
24720
|
agent,
|
|
24382
24721
|
"stop",
|
|
24383
24722
|
deliverBlockMessage(
|
|
24723
|
+
cli,
|
|
24384
24724
|
`scope=${scope.kind} base=${scope.base} changed=${scope.changes.files.length} file(s); no matching accepted delivery stamp.`
|
|
24385
24725
|
)
|
|
24386
24726
|
);
|
|
24387
24727
|
}
|
|
24388
24728
|
function executeStop(repo, agent, id) {
|
|
24729
|
+
const cli = repoHarnessInvocation(repo);
|
|
24389
24730
|
const token = validationSessionToken(agent, id);
|
|
24390
24731
|
let session;
|
|
24391
24732
|
try {
|
|
24392
24733
|
session = readValidationSession(repo, token);
|
|
24393
24734
|
} catch (error) {
|
|
24394
|
-
return block(agent, "stop", deliverBlockMessage(`validation session unreadable: ${error.message}`));
|
|
24735
|
+
return block(agent, "stop", deliverBlockMessage(cli, `validation session unreadable: ${error.message}`));
|
|
24395
24736
|
}
|
|
24396
24737
|
if (!session) {
|
|
24397
24738
|
const delivered = captureStdout2(() => deliverCmd(repo, { json: true }));
|
|
@@ -24403,7 +24744,7 @@ function executeStop(repo, agent, id) {
|
|
|
24403
24744
|
} catch {
|
|
24404
24745
|
detail = delivered.output.trim().slice(0, 500);
|
|
24405
24746
|
}
|
|
24406
|
-
return block(agent, "stop", deliverBlockMessage(detail));
|
|
24747
|
+
return block(agent, "stop", deliverBlockMessage(cli, detail));
|
|
24407
24748
|
}
|
|
24408
24749
|
if (session.hookConfigFingerprint && agentHookConfigurationFingerprint(repo, agent) !== session.hookConfigFingerprint) {
|
|
24409
24750
|
const delivered = captureStdout2(() => deliverCmd(repo, { json: true }));
|
|
@@ -24412,6 +24753,7 @@ function executeStop(repo, agent, id) {
|
|
|
24412
24753
|
agent,
|
|
24413
24754
|
"stop",
|
|
24414
24755
|
deliverBlockMessage(
|
|
24756
|
+
cli,
|
|
24415
24757
|
"project hook configuration changed after SessionStart; lifecycle proof was discarded. Run deliver to re-accept the current change."
|
|
24416
24758
|
)
|
|
24417
24759
|
);
|
|
@@ -24419,11 +24761,17 @@ function executeStop(repo, agent, id) {
|
|
|
24419
24761
|
try {
|
|
24420
24762
|
clearValidationEvidence(repo, session);
|
|
24421
24763
|
} catch (error) {
|
|
24422
|
-
return block(agent, "stop", deliverBlockMessage(`could not start a fresh validation attempt: ${error.message}`));
|
|
24764
|
+
return block(agent, "stop", deliverBlockMessage(cli, `could not start a fresh validation attempt: ${error.message}`));
|
|
24423
24765
|
}
|
|
24424
24766
|
const run = captureStdout2(() => runChecksCmd(repo, { session: token, json: true, budgetMs: 0 }));
|
|
24425
24767
|
const report = parseRunReport2(run.output);
|
|
24426
|
-
const verify = captureStdout2(
|
|
24768
|
+
const verify = captureStdout2(
|
|
24769
|
+
() => verifyCmd(repo, {
|
|
24770
|
+
budgetMs: hookVerifyBudgetMs(),
|
|
24771
|
+
recordManualEvidence: false,
|
|
24772
|
+
...session.baseSha ? { contextBase: session.baseSha } : {}
|
|
24773
|
+
})
|
|
24774
|
+
);
|
|
24427
24775
|
let finalFingerprintError = "";
|
|
24428
24776
|
if (report?.fingerprint) {
|
|
24429
24777
|
try {
|
|
@@ -24439,7 +24787,7 @@ function executeStop(repo, agent, id) {
|
|
|
24439
24787
|
try {
|
|
24440
24788
|
evidencePersisted = markLatestVerifyResult(repo, token, verifyPassed, report?.fingerprint, report?.planFingerprint);
|
|
24441
24789
|
} catch (error) {
|
|
24442
|
-
return block(agent, "stop", deliverBlockMessage(`could not persist verify result: ${error.message}`));
|
|
24790
|
+
return block(agent, "stop", deliverBlockMessage(cli, `could not persist verify result: ${error.message}`));
|
|
24443
24791
|
}
|
|
24444
24792
|
if (run.code === 0 && report?.ok && verifyPassed && evidencePersisted) return allow(agent);
|
|
24445
24793
|
const verifyDetails = [
|
|
@@ -24447,7 +24795,7 @@ function executeStop(repo, agent, id) {
|
|
|
24447
24795
|
finalFingerprintError,
|
|
24448
24796
|
evidencePersisted ? "" : "matching final evidence was not persisted; refusing to allow Stop"
|
|
24449
24797
|
].filter(Boolean).join("\n");
|
|
24450
|
-
return block(agent, "stop", failureMessage(report, verifyDetails, token));
|
|
24798
|
+
return block(agent, "stop", failureMessage(report, verifyDetails, token, cli));
|
|
24451
24799
|
}
|
|
24452
24800
|
function hookEventCmd(repoInput, opts) {
|
|
24453
24801
|
let payload;
|
|
@@ -24500,8 +24848,8 @@ function hookEventCmd(repoInput, opts) {
|
|
|
24500
24848
|
|
|
24501
24849
|
// src/commands/install-hooks.ts
|
|
24502
24850
|
var import_node_child_process7 = require("node:child_process");
|
|
24503
|
-
var
|
|
24504
|
-
var
|
|
24851
|
+
var import_node_fs18 = require("node:fs");
|
|
24852
|
+
var import_node_path18 = require("node:path");
|
|
24505
24853
|
var MARK = "harness-kit-managed-hook";
|
|
24506
24854
|
function git2(repo, args) {
|
|
24507
24855
|
const result = (0, import_node_child_process7.spawnSync)("git", args, { cwd: repo, encoding: "utf8" });
|
|
@@ -24543,9 +24891,9 @@ function inspectGitHookScope(repo) {
|
|
|
24543
24891
|
}
|
|
24544
24892
|
];
|
|
24545
24893
|
});
|
|
24546
|
-
const hooksDir = (0,
|
|
24547
|
-
const commonDir = (0,
|
|
24548
|
-
const gitDir = (0,
|
|
24894
|
+
const hooksDir = (0, import_node_path18.resolve)(repo, hooks.stdout.trim());
|
|
24895
|
+
const commonDir = (0, import_node_path18.resolve)(repo, common.stdout.trim());
|
|
24896
|
+
const gitDir = (0, import_node_path18.resolve)(repo, current.stdout.trim());
|
|
24549
24897
|
return {
|
|
24550
24898
|
scope: {
|
|
24551
24899
|
hooksDir,
|
|
@@ -24554,21 +24902,21 @@ function inspectGitHookScope(repo) {
|
|
|
24554
24902
|
worktrees,
|
|
24555
24903
|
hooksPathConfigs,
|
|
24556
24904
|
hooksPathConfigRaw,
|
|
24557
|
-
defaultHooksDirMatches: hooksDir === (0,
|
|
24905
|
+
defaultHooksDirMatches: hooksDir === (0, import_node_path18.join)(commonDir, "hooks")
|
|
24558
24906
|
}
|
|
24559
24907
|
};
|
|
24560
24908
|
}
|
|
24561
24909
|
function hookOwnership(path) {
|
|
24562
24910
|
try {
|
|
24563
|
-
if (!(0,
|
|
24564
|
-
return (0,
|
|
24911
|
+
if (!(0, import_node_fs18.lstatSync)(path).isFile()) return "foreign";
|
|
24912
|
+
return (0, import_node_fs18.readFileSync)(path, "utf8").includes(MARK) ? "managed" : "foreign";
|
|
24565
24913
|
} catch (error) {
|
|
24566
24914
|
return error.code === "ENOENT" ? "missing" : "foreign";
|
|
24567
24915
|
}
|
|
24568
24916
|
}
|
|
24569
24917
|
function hooksPathReason(scope) {
|
|
24570
24918
|
if (!scope.hooksPathConfigRaw.length) {
|
|
24571
|
-
return scope.defaultHooksDirMatches ? null : `resolved hooks directory does not match ${(0,
|
|
24919
|
+
return scope.defaultHooksDirMatches ? null : `resolved hooks directory does not match ${(0, import_node_path18.join)(scope.commonDir, "hooks")}; core.hooksPath origin is ambiguous`;
|
|
24572
24920
|
}
|
|
24573
24921
|
if (scope.hooksPathConfigs.length !== 1 || scope.hooksPathConfigRaw.length !== 1) {
|
|
24574
24922
|
return `core.hooksPath is ambiguous: ${scope.hooksPathConfigRaw.join("; ")}`;
|
|
@@ -24619,7 +24967,7 @@ function installGitHooks(repo, force, allowSharedGitHooks) {
|
|
|
24619
24967
|
["pre-commit", preCommit()],
|
|
24620
24968
|
["pre-push", prePush()]
|
|
24621
24969
|
];
|
|
24622
|
-
const ownership = new Map(targets.map(([name]) => [name, hookOwnership((0,
|
|
24970
|
+
const ownership = new Map(targets.map(([name]) => [name, hookOwnership((0, import_node_path18.join)(scope.hooksDir, name))]));
|
|
24623
24971
|
const reasons = [];
|
|
24624
24972
|
const configuredPathReason = hooksPathReason(scope);
|
|
24625
24973
|
if (configuredPathReason) reasons.push(configuredPathReason);
|
|
@@ -24642,10 +24990,10 @@ function installGitHooks(repo, force, allowSharedGitHooks) {
|
|
|
24642
24990
|
);
|
|
24643
24991
|
}
|
|
24644
24992
|
for (const [name, body] of targets) {
|
|
24645
|
-
const p = (0,
|
|
24993
|
+
const p = (0, import_node_path18.join)(scope.hooksDir, name);
|
|
24646
24994
|
const wasManaged = ownership.get(name) === "managed";
|
|
24647
24995
|
writeText(p, body);
|
|
24648
|
-
(0,
|
|
24996
|
+
(0, import_node_fs18.chmodSync)(p, 493);
|
|
24649
24997
|
ok(`${wasManaged ? force ? "refreshed" : "updated" : "installed"} ${name}`);
|
|
24650
24998
|
}
|
|
24651
24999
|
info(`
|
|
@@ -24758,10 +25106,10 @@ function recordContextReviewCmd(repo, opts) {
|
|
|
24758
25106
|
}
|
|
24759
25107
|
|
|
24760
25108
|
// src/commands/prepare-adoption.ts
|
|
24761
|
-
var
|
|
25109
|
+
var import_node_path19 = require("node:path");
|
|
24762
25110
|
function prepareAdoptionCmd(repo, opts) {
|
|
24763
25111
|
if (!opts.output?.trim()) throw new Error("candidate output directory is required");
|
|
24764
|
-
const output = (0,
|
|
25112
|
+
const output = (0, import_node_path19.resolve)(opts.output);
|
|
24765
25113
|
const candidate = prepareAdoptionCandidate(repo, output);
|
|
24766
25114
|
const result = {
|
|
24767
25115
|
ok: true,
|
|
@@ -24779,15 +25127,15 @@ function prepareAdoptionCmd(repo, opts) {
|
|
|
24779
25127
|
}
|
|
24780
25128
|
|
|
24781
25129
|
// src/commands/record-adoption-audit.ts
|
|
24782
|
-
var
|
|
25130
|
+
var import_node_path20 = require("node:path");
|
|
24783
25131
|
function recordAdoptionAuditCmd(repo, opts) {
|
|
24784
25132
|
if (!opts.candidate?.trim()) throw new Error("candidate directory is required");
|
|
24785
25133
|
if (!opts.report?.trim()) throw new Error("audit report path is required");
|
|
24786
|
-
const recorded = recordAdoptionAudit(repo, (0,
|
|
25134
|
+
const recorded = recordAdoptionAudit(repo, (0, import_node_path20.resolve)(opts.candidate), {
|
|
24787
25135
|
verdict: opts.verdict,
|
|
24788
25136
|
reason: opts.reason,
|
|
24789
|
-
reportPath: (0,
|
|
24790
|
-
receiptPath: opts.receipt ? (0,
|
|
25137
|
+
reportPath: (0, import_node_path20.resolve)(opts.report),
|
|
25138
|
+
receiptPath: opts.receipt ? (0, import_node_path20.resolve)(opts.receipt) : void 0
|
|
24791
25139
|
});
|
|
24792
25140
|
const result = {
|
|
24793
25141
|
ok: true,
|
|
@@ -24905,7 +25253,7 @@ function taskStartCmd(repo, opts = {}) {
|
|
|
24905
25253
|
} else {
|
|
24906
25254
|
ok(`task started at base ${record.baseSha}`);
|
|
24907
25255
|
if (record.note) info(`note: ${record.note}`);
|
|
24908
|
-
info(
|
|
25256
|
+
info(`run ${repoHarnessInvocation(repo)} deliver when ready to accept this task's changes`);
|
|
24909
25257
|
}
|
|
24910
25258
|
return 0;
|
|
24911
25259
|
} catch (error) {
|
|
@@ -24921,7 +25269,7 @@ function taskStatusCmd(repo, opts = {}) {
|
|
|
24921
25269
|
}
|
|
24922
25270
|
if (!record) {
|
|
24923
25271
|
err("no active task record for this worktree");
|
|
24924
|
-
info(
|
|
25272
|
+
info(`run: ${repoHarnessInvocation(repo)} task-start --repo .`);
|
|
24925
25273
|
info("without a task base, deliver falls back to worktree diff vs HEAD");
|
|
24926
25274
|
return 1;
|
|
24927
25275
|
}
|
|
@@ -24943,7 +25291,7 @@ function guard(fn) {
|
|
|
24943
25291
|
}
|
|
24944
25292
|
var program2 = new Command();
|
|
24945
25293
|
program2.name("harness-kit").description("AI-friendly repo harness").version(package_default.version);
|
|
24946
|
-
var repoOf = (o) => (0,
|
|
25294
|
+
var repoOf = (o) => (0, import_node_path21.resolve)(o.repo ?? process.cwd());
|
|
24947
25295
|
function agentList(value) {
|
|
24948
25296
|
const agents = value.split(",").map((item) => item.trim()).filter(Boolean);
|
|
24949
25297
|
const invalid = agents.filter((agent) => !ALL_AGENTS.includes(agent));
|