mason-context 0.16.3 → 0.17.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/CHANGELOG.md +16 -0
- package/README.md +1 -1
- package/dist/mason-audit.js +1718 -770
- package/dist/mason-audit.js.map +1 -1
- package/dist/mason-auto.js +1359 -813
- package/dist/mason-auto.js.map +1 -1
- package/dist/mason-mcp.js +3279 -2616
- package/dist/mason-mcp.js.map +1 -1
- package/dist/mason-review.js +80 -19
- package/dist/mason-review.js.map +1 -1
- package/dist/mason.js +1422 -876
- package/dist/mason.js.map +1 -1
- package/package.json +5 -1
package/dist/mason-auto.js
CHANGED
|
@@ -346,6 +346,89 @@ var init_store = __esm({
|
|
|
346
346
|
}
|
|
347
347
|
});
|
|
348
348
|
|
|
349
|
+
// src/audit/commands.ts
|
|
350
|
+
import path4 from "path";
|
|
351
|
+
function splitCommands(line) {
|
|
352
|
+
const parts = [];
|
|
353
|
+
let quote = "", start = 0;
|
|
354
|
+
for (let i = 0; i < line.length; i++) {
|
|
355
|
+
const char = line[i];
|
|
356
|
+
if (char === "\\") {
|
|
357
|
+
i++;
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
if (quote) {
|
|
361
|
+
if (char === quote) quote = "";
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
if (char === "'" || char === '"') {
|
|
365
|
+
quote = char;
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
if (char === ";" || line.slice(i, i + 2) === "&&") {
|
|
369
|
+
parts.push(line.slice(start, i));
|
|
370
|
+
if (char === "&") i++;
|
|
371
|
+
start = i + 1;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
parts.push(line.slice(start));
|
|
375
|
+
return parts;
|
|
376
|
+
}
|
|
377
|
+
function commandClaims(line, lineNo, cwd, shell = false) {
|
|
378
|
+
const claims = [];
|
|
379
|
+
const segments = splitCommands(line);
|
|
380
|
+
for (const segment of segments) {
|
|
381
|
+
const text2 = segment.trim().replace(/^\$\s+/, "");
|
|
382
|
+
if (text2.startsWith("#") || /^(?:echo|printf)\b/.test(text2)) continue;
|
|
383
|
+
const cd = text2.match(/^cd\s+(.+)$/);
|
|
384
|
+
if (cd) {
|
|
385
|
+
const directory = literal(cd[1]);
|
|
386
|
+
cwd = directory === null || cwd === null || /\s/.test(directory) && !/^["']/.test(cd[1]) ? null : path4.posix.join(cwd ?? ".", directory);
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
for (const match of text2.matchAll(COMMAND)) {
|
|
390
|
+
const flags = match[2].trim();
|
|
391
|
+
const selector = flags.match(/^(?:--prefix|--dir|-C)(?:\s+|=)(.+)$/);
|
|
392
|
+
let directory = cwd;
|
|
393
|
+
let scopeUnknown;
|
|
394
|
+
if (shell && match.index !== 0 || match[3].startsWith("-")) scopeUnknown = "Unsupported shell wrapper or options before the script.";
|
|
395
|
+
if (selector) {
|
|
396
|
+
const selected = literal(selector[1]);
|
|
397
|
+
directory = selected === null || cwd === null ? null : path4.posix.join(cwd ?? ".", selected);
|
|
398
|
+
} else if (flags) scopeUnknown = "Unsupported package-manager options before run: " + flags;
|
|
399
|
+
const tail = text2.slice(match.index + match[0].length).split(/\s--(?:\s|$)/)[0];
|
|
400
|
+
if (/(?:^|\s)(?:--workspace(?:s)?|-w|--filter|-F|--prefix|--dir|-C|--if-present)(?:\s|=|$)/.test(tail)) {
|
|
401
|
+
scopeUnknown = "Package selection or conditional options after the script need review.";
|
|
402
|
+
}
|
|
403
|
+
if (/[|()]/.test(text2) || /\b(?:pushd|popd|if|for|while)\b/.test(text2) || directory === null) {
|
|
404
|
+
scopeUnknown = "The command's working directory or shell control flow could not be resolved.";
|
|
405
|
+
}
|
|
406
|
+
claims.push({
|
|
407
|
+
scriptName: match[3],
|
|
408
|
+
invocation: match[0],
|
|
409
|
+
excerpt: match[0],
|
|
410
|
+
line: lineNo,
|
|
411
|
+
...directory !== void 0 && directory !== null ? { directory } : {},
|
|
412
|
+
...scopeUnknown ? { scopeUnknown } : {}
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
if (/\b(?:cd|pushd|popd)\b/.test(text2)) cwd = null;
|
|
416
|
+
}
|
|
417
|
+
return { claims, cwd };
|
|
418
|
+
}
|
|
419
|
+
var TOKEN, COMMAND, literal;
|
|
420
|
+
var init_commands = __esm({
|
|
421
|
+
"src/audit/commands.ts"() {
|
|
422
|
+
"use strict";
|
|
423
|
+
TOKEN = `(?:"[^"\\n]*"|'[^'\\n]*'|[^\\s\`;&|]+)`;
|
|
424
|
+
COMMAND = new RegExp(`\\b(npm|pnpm|yarn)((?:[ \\t]+${TOKEN})*?)[ \\t]+run[ \\t]+([A-Za-z0-9:_.-]+)`, "g");
|
|
425
|
+
literal = (value) => {
|
|
426
|
+
const unquoted = value.replace(/^(["'])(.*)\1$/, "$2");
|
|
427
|
+
return /[$`*?\[\]{}~\\\x00-\x1f]/.test(unquoted) || path4.posix.isAbsolute(unquoted) ? null : unquoted;
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
|
|
349
432
|
// src/audit/tree.ts
|
|
350
433
|
function glyphIndex(line) {
|
|
351
434
|
for (const glyph of GLYPHS) {
|
|
@@ -425,6 +508,7 @@ var init_tree = __esm({
|
|
|
425
508
|
});
|
|
426
509
|
|
|
427
510
|
// src/audit/claims.ts
|
|
511
|
+
import MarkdownIt from "markdown-it";
|
|
428
512
|
function normalizePathToken(token) {
|
|
429
513
|
let t = token.trim();
|
|
430
514
|
if (!t) return null;
|
|
@@ -488,11 +572,34 @@ function extractClaims(content2) {
|
|
|
488
572
|
const counts = [];
|
|
489
573
|
const commands = /* @__PURE__ */ new Map();
|
|
490
574
|
const addPath = (claim) => {
|
|
491
|
-
|
|
575
|
+
const key = [claim.relativeTo ?? "scope", claim.path].join(":");
|
|
576
|
+
if (!paths.has(key)) paths.set(key, claim);
|
|
492
577
|
};
|
|
493
578
|
const addCommand = (claim) => {
|
|
494
|
-
|
|
579
|
+
const key = JSON.stringify([claim.scriptName, claim.directory, claim.scopeUnknown]);
|
|
580
|
+
if (!commands.has(key)) commands.set(key, claim);
|
|
495
581
|
};
|
|
582
|
+
const parsed = markdown.parse(lines.map((line, i) => ignored[i] ? "" : line).join("\n"), {});
|
|
583
|
+
for (const token of parsed) {
|
|
584
|
+
if (token.type !== "inline" || !token.map) continue;
|
|
585
|
+
let line = token.map[0] + 1;
|
|
586
|
+
for (const child of token.children ?? []) {
|
|
587
|
+
const target = child.type === "link_open" ? child.attrGet("href") : child.type === "image" ? child.attrGet("src") : null;
|
|
588
|
+
if (target && !/^(?:[a-z][a-z0-9+.-]*:|[\/#~])/i.test(target)) {
|
|
589
|
+
let pathname = null;
|
|
590
|
+
try {
|
|
591
|
+
pathname = decodeURIComponent(target.split(/[?#]/)[0]);
|
|
592
|
+
} catch {
|
|
593
|
+
}
|
|
594
|
+
if (pathname && !/[$*?{}<>\\\x00-\x1f]/.test(pathname)) {
|
|
595
|
+
addPath({ path: pathname, line, excerpt: target, relativeTo: "document" });
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
if (child.type === "softbreak" || child.type === "hardbreak") line++;
|
|
599
|
+
else line += child.content.split("\n").length - 1;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
let shellCwd;
|
|
496
603
|
let inFence = false;
|
|
497
604
|
let fenceInfo = "";
|
|
498
605
|
let fenceMarker = "";
|
|
@@ -523,6 +630,7 @@ function extractClaims(content2) {
|
|
|
523
630
|
fenceMarker = fenceMatch[1][0];
|
|
524
631
|
fenceInfo = fenceMatch[2].trim().toLowerCase();
|
|
525
632
|
blockLines = [];
|
|
633
|
+
shellCwd = void 0;
|
|
526
634
|
blockStartLine = lineNo + 1;
|
|
527
635
|
} else if (fenceMatch[1][0] === fenceMarker) {
|
|
528
636
|
inFence = false;
|
|
@@ -533,14 +641,9 @@ function extractClaims(content2) {
|
|
|
533
641
|
if (inFence) {
|
|
534
642
|
blockLines.push(ignored[i] ? "" : line);
|
|
535
643
|
if (!ignored[i] && SHELL_FENCE_INFOS.has(fenceInfo)) {
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
invocation: m[0],
|
|
540
|
-
line: lineNo,
|
|
541
|
-
excerpt: m[0]
|
|
542
|
-
});
|
|
543
|
-
}
|
|
644
|
+
const scanned = commandClaims(line, lineNo, shellCwd, true);
|
|
645
|
+
shellCwd = scanned.cwd;
|
|
646
|
+
for (const claim of scanned.claims) addCommand(claim);
|
|
544
647
|
}
|
|
545
648
|
continue;
|
|
546
649
|
}
|
|
@@ -567,14 +670,10 @@ function extractClaims(content2) {
|
|
|
567
670
|
excerpt: m[0]
|
|
568
671
|
});
|
|
569
672
|
}
|
|
570
|
-
for (const
|
|
571
|
-
addCommand(
|
|
572
|
-
scriptName: m[2],
|
|
573
|
-
invocation: m[0],
|
|
574
|
-
line: lineNo,
|
|
575
|
-
excerpt: m[0]
|
|
576
|
-
});
|
|
673
|
+
for (const match of line.matchAll(/`([^`]+)`/g)) {
|
|
674
|
+
for (const claim of commandClaims(match[1], lineNo, void 0, true).claims) addCommand(claim);
|
|
577
675
|
}
|
|
676
|
+
for (const claim of commandClaims(line.replace(/`[^`]+`/g, ""), lineNo).claims) addCommand(claim);
|
|
578
677
|
}
|
|
579
678
|
if (inFence) processBlock();
|
|
580
679
|
return {
|
|
@@ -583,10 +682,11 @@ function extractClaims(content2) {
|
|
|
583
682
|
commands: [...commands.values()]
|
|
584
683
|
};
|
|
585
684
|
}
|
|
586
|
-
var ROOT_FILE_NAMES, SHELL_FENCE_INFOS,
|
|
685
|
+
var ROOT_FILE_NAMES, SHELL_FENCE_INFOS, markdown, COUNT_RE, COUNT_DENYLIST_RE, IGNORE_LINE, IGNORE_START, IGNORE_END;
|
|
587
686
|
var init_claims = __esm({
|
|
588
687
|
"src/audit/claims.ts"() {
|
|
589
688
|
"use strict";
|
|
689
|
+
init_commands();
|
|
590
690
|
init_tree();
|
|
591
691
|
ROOT_FILE_NAMES = /* @__PURE__ */ new Set([
|
|
592
692
|
"package.json",
|
|
@@ -620,7 +720,7 @@ var init_claims = __esm({
|
|
|
620
720
|
".env.example"
|
|
621
721
|
]);
|
|
622
722
|
SHELL_FENCE_INFOS = /* @__PURE__ */ new Set(["", "bash", "sh", "shell", "console", "zsh"]);
|
|
623
|
-
|
|
723
|
+
markdown = new MarkdownIt("commonmark", { html: false });
|
|
624
724
|
COUNT_RE = /(\d+)\s+(modules?|packages?|workspaces?|crates?)\b/gi;
|
|
625
725
|
COUNT_DENYLIST_RE = /^\s*(manager|registr|lock|json)/i;
|
|
626
726
|
IGNORE_LINE = "<!-- mason:ignore -->";
|
|
@@ -641,7 +741,7 @@ async function lastCommitOf(resolvedRoot, relPath) {
|
|
|
641
741
|
try {
|
|
642
742
|
const { stdout } = await exec2(
|
|
643
743
|
"git",
|
|
644
|
-
["log", "-1", `--format=${COMMIT_FORMAT}`, "--", relPath],
|
|
744
|
+
["log", "-1", `--format=${COMMIT_FORMAT}`, "--", `:(literal)${relPath}`],
|
|
645
745
|
{ cwd: resolvedRoot }
|
|
646
746
|
);
|
|
647
747
|
const line = stdout.trim().split("\n")[0];
|
|
@@ -660,7 +760,7 @@ async function deletingCommitOf(resolvedRoot, relPath) {
|
|
|
660
760
|
"--diff-filter=D",
|
|
661
761
|
`--format=${COMMIT_FORMAT}`,
|
|
662
762
|
"--",
|
|
663
|
-
relPath
|
|
763
|
+
`:(literal)${relPath}`
|
|
664
764
|
],
|
|
665
765
|
{ cwd: resolvedRoot }
|
|
666
766
|
);
|
|
@@ -674,7 +774,7 @@ async function firstCommitOf(resolvedRoot, relPath) {
|
|
|
674
774
|
try {
|
|
675
775
|
const { stdout } = await exec2(
|
|
676
776
|
"git",
|
|
677
|
-
["log", "--reverse", `--format=${COMMIT_FORMAT}`, "--", relPath],
|
|
777
|
+
["log", "--reverse", `--format=${COMMIT_FORMAT}`, "--", `:(literal)${relPath}`],
|
|
678
778
|
{ cwd: resolvedRoot, maxBuffer: 10 * 1024 * 1024 }
|
|
679
779
|
);
|
|
680
780
|
const line = stdout.trim().split("\n")[0];
|
|
@@ -720,42 +820,242 @@ var init_git = __esm({
|
|
|
720
820
|
}
|
|
721
821
|
});
|
|
722
822
|
|
|
723
|
-
// src/audit/
|
|
823
|
+
// src/audit/inputs.ts
|
|
724
824
|
import fs4 from "fs/promises";
|
|
725
|
-
import
|
|
825
|
+
import * as nativeFs from "fs";
|
|
826
|
+
import path5 from "path";
|
|
726
827
|
import { execFile as execFile3 } from "child_process";
|
|
727
828
|
import { promisify as promisify3 } from "util";
|
|
829
|
+
import fg2 from "fast-glob";
|
|
830
|
+
async function auditInputPath(root, file) {
|
|
831
|
+
if (file === ".") return fs4.realpath(root);
|
|
832
|
+
try {
|
|
833
|
+
return await storePath(root, file);
|
|
834
|
+
} catch (error) {
|
|
835
|
+
if (error instanceof Error && error.message.startsWith("Symlink")) {
|
|
836
|
+
throw new Error(`Audit input contains a symbolic link: ${file}. Its evidence could not be verified.`, { cause: error });
|
|
837
|
+
}
|
|
838
|
+
throw error;
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
async function readAuditInput(root, file) {
|
|
842
|
+
try {
|
|
843
|
+
const value = await readBoundedFile(await auditInputPath(root, file), 10 * 1024 * 1024);
|
|
844
|
+
if (value === null) throw new Error(`Unreadable or oversized audit input: ${file}`);
|
|
845
|
+
return value;
|
|
846
|
+
} catch (error) {
|
|
847
|
+
if (error.code === "ENOENT") return null;
|
|
848
|
+
throw error;
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
async function auditGlob(root, patterns, options) {
|
|
852
|
+
if (Array.isArray(patterns) && !patterns.length) return [];
|
|
853
|
+
const directories = /* @__PURE__ */ new Set();
|
|
854
|
+
const readdir2 = ((directory, opts, callback) => {
|
|
855
|
+
const relative = path5.relative(root, directory).split(path5.sep).join("/") || ".";
|
|
856
|
+
directories.add(relative);
|
|
857
|
+
if (directories.size > MAX_INPUTS) {
|
|
858
|
+
callback(new Error(`${options.label} exceeds ${MAX_INPUTS.toLocaleString("en-US")} directories while inspecting ${relative}. Narrow this check's inputs.`));
|
|
859
|
+
return;
|
|
860
|
+
}
|
|
861
|
+
auditInputPath(root, relative).then(() => {
|
|
862
|
+
nativeFs.readdir(directory, opts, callback);
|
|
863
|
+
}, callback);
|
|
864
|
+
});
|
|
865
|
+
const lstat2 = ((file, callback) => {
|
|
866
|
+
const relative = path5.relative(root, file).split(path5.sep).join("/") || ".";
|
|
867
|
+
auditInputPath(root, relative).then(() => nativeFs.lstat(file, callback), callback);
|
|
868
|
+
});
|
|
869
|
+
const stream = fg2.stream(patterns, {
|
|
870
|
+
cwd: root,
|
|
871
|
+
ignore: options.ignore,
|
|
872
|
+
onlyFiles: false,
|
|
873
|
+
onlyDirectories: options.onlyDirectories,
|
|
874
|
+
objectMode: true,
|
|
875
|
+
followSymbolicLinks: options.followSymbolicLinks ?? true,
|
|
876
|
+
fs: { readdir: readdir2, lstat: lstat2 },
|
|
877
|
+
concurrency: 16
|
|
878
|
+
});
|
|
879
|
+
const matches = [];
|
|
880
|
+
try {
|
|
881
|
+
for await (const value of stream) {
|
|
882
|
+
const entry = value;
|
|
883
|
+
const file = entry.path;
|
|
884
|
+
if (options.select && !options.select(file)) continue;
|
|
885
|
+
await auditInputPath(root, file);
|
|
886
|
+
if (!options.onlyDirectories && !entry.dirent.isFile()) continue;
|
|
887
|
+
matches.push(file);
|
|
888
|
+
if (matches.length > MAX_INPUTS) {
|
|
889
|
+
const largest = [...matches.reduce((counts, item) => {
|
|
890
|
+
const dir = item.split("/")[0];
|
|
891
|
+
counts.set(dir, (counts.get(dir) ?? 0) + 1);
|
|
892
|
+
return counts;
|
|
893
|
+
}, /* @__PURE__ */ new Map())].sort((a, b) => b[1] - a[1]).slice(0, 3);
|
|
894
|
+
throw new Error(`${options.label} exceeds ${MAX_INPUTS.toLocaleString("en-US")} relevant paths. Largest directories: ${largest.map(([dir, count4]) => `${dir} (${count4})`).join(", ")}. Narrow this check's inputs.`);
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
} finally {
|
|
898
|
+
stream.destroy();
|
|
899
|
+
}
|
|
900
|
+
return matches.sort();
|
|
901
|
+
}
|
|
902
|
+
async function gitSourcePaths(root) {
|
|
903
|
+
const { stdout } = await execute(
|
|
904
|
+
"git",
|
|
905
|
+
[
|
|
906
|
+
"ls-files",
|
|
907
|
+
"-z",
|
|
908
|
+
"--cached",
|
|
909
|
+
"--others",
|
|
910
|
+
"--exclude-standard",
|
|
911
|
+
"--",
|
|
912
|
+
...SOURCE_EXTENSIONS.map((extension) => `:(glob)**/*.${extension}`)
|
|
913
|
+
],
|
|
914
|
+
{ cwd: root, maxBuffer: 32 * 1024 * 1024, timeout: 1e4 }
|
|
915
|
+
);
|
|
916
|
+
return [...new Set(stdout.split("\0").filter(Boolean))].sort();
|
|
917
|
+
}
|
|
918
|
+
async function gitIgnoredPaths(root, files) {
|
|
919
|
+
if (!files.length) return /* @__PURE__ */ new Set();
|
|
920
|
+
const operation = execute(
|
|
921
|
+
"git",
|
|
922
|
+
["check-ignore", "-z", "--stdin"],
|
|
923
|
+
{ cwd: root, maxBuffer: 4 * 1024 * 1024, timeout: 1e4 }
|
|
924
|
+
);
|
|
925
|
+
operation.child.stdin.on("error", () => {
|
|
926
|
+
});
|
|
927
|
+
operation.child.stdin.end(files.join("\0") + "\0");
|
|
928
|
+
try {
|
|
929
|
+
return new Set((await operation).stdout.split("\0").filter(Boolean));
|
|
930
|
+
} catch (error) {
|
|
931
|
+
if (error.code === 1) return /* @__PURE__ */ new Set();
|
|
932
|
+
throw error;
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
var execute, MAX_INPUTS;
|
|
936
|
+
var init_inputs = __esm({
|
|
937
|
+
"src/audit/inputs.ts"() {
|
|
938
|
+
"use strict";
|
|
939
|
+
init_files();
|
|
940
|
+
init_storage();
|
|
941
|
+
execute = promisify3(execFile3);
|
|
942
|
+
MAX_INPUTS = 1e5;
|
|
943
|
+
}
|
|
944
|
+
});
|
|
945
|
+
|
|
946
|
+
// src/audit/docs.ts
|
|
947
|
+
import fs5 from "fs/promises";
|
|
948
|
+
import path6 from "path";
|
|
949
|
+
import { execFile as execFile4 } from "child_process";
|
|
950
|
+
import { promisify as promisify4 } from "util";
|
|
951
|
+
import fg3 from "fast-glob";
|
|
728
952
|
async function isDirty(resolvedRoot, relPath) {
|
|
729
953
|
try {
|
|
730
954
|
const { stdout } = await exec3(
|
|
731
955
|
"git",
|
|
732
|
-
["status", "--porcelain", "--", relPath],
|
|
956
|
+
["status", "--porcelain", "--", `:(literal)${relPath}`],
|
|
733
957
|
{ cwd: resolvedRoot }
|
|
734
958
|
);
|
|
735
959
|
return stdout.trim().length > 0;
|
|
736
960
|
} catch {
|
|
737
|
-
return
|
|
961
|
+
return true;
|
|
738
962
|
}
|
|
739
963
|
}
|
|
740
|
-
async function
|
|
741
|
-
|
|
742
|
-
|
|
964
|
+
async function discoverDocPaths(root) {
|
|
965
|
+
let candidates = [];
|
|
966
|
+
try {
|
|
967
|
+
const { stdout } = await exec3(
|
|
968
|
+
"git",
|
|
969
|
+
[
|
|
970
|
+
"ls-files",
|
|
971
|
+
"-z",
|
|
972
|
+
"--cached",
|
|
973
|
+
"--others",
|
|
974
|
+
"--exclude-standard",
|
|
975
|
+
"--",
|
|
976
|
+
":(icase,glob)**/readme.md",
|
|
977
|
+
":(icase,glob)**/agents.md",
|
|
978
|
+
":(icase,glob)**/claude.md"
|
|
979
|
+
],
|
|
980
|
+
{ cwd: root, maxBuffer: 16 * 1024 * 1024, timeout: 1e4 }
|
|
981
|
+
);
|
|
982
|
+
candidates = stdout.split("\0").filter(Boolean);
|
|
983
|
+
} catch (error) {
|
|
743
984
|
try {
|
|
744
|
-
|
|
985
|
+
await exec3("git", ["rev-parse", "--git-dir"], { cwd: root });
|
|
745
986
|
} catch {
|
|
746
|
-
return
|
|
987
|
+
return localDocPaths(root);
|
|
988
|
+
}
|
|
989
|
+
throw error;
|
|
990
|
+
}
|
|
991
|
+
candidates.push(...await localDocPaths(root));
|
|
992
|
+
const config = await loadProjectConfig(root);
|
|
993
|
+
const excluded = [
|
|
994
|
+
"**/node_modules/**",
|
|
995
|
+
"**/vendor/**",
|
|
996
|
+
"**/dist/**",
|
|
997
|
+
"**/build/**",
|
|
998
|
+
"**/target/**",
|
|
999
|
+
"**/.git/**",
|
|
1000
|
+
"**/.venv/**",
|
|
1001
|
+
"**/venv/**",
|
|
1002
|
+
".mason/**",
|
|
1003
|
+
...config.ignore ?? []
|
|
1004
|
+
];
|
|
1005
|
+
const paths = [];
|
|
1006
|
+
const unique = [...new Set(candidates)].sort();
|
|
1007
|
+
for (let offset = 0; offset < unique.length; offset += 256) {
|
|
1008
|
+
paths.push(...await auditGlob(root, unique.slice(offset, offset + 256).map((p) => fg3.escapePath(p)), {
|
|
1009
|
+
ignore: excluded,
|
|
1010
|
+
followSymbolicLinks: false,
|
|
1011
|
+
label: "Documentation discovery"
|
|
1012
|
+
}));
|
|
1013
|
+
if (paths.length > 1e4) throw new Error("Documentation discovery exceeds 10,000 relevant files; narrow .mason/config.json ignore patterns.");
|
|
1014
|
+
}
|
|
1015
|
+
const priority2 = (file) => {
|
|
1016
|
+
const index2 = DOC_CANDIDATES.findIndex((p) => p.toLowerCase() === file.toLowerCase());
|
|
1017
|
+
return index2 < 0 ? DOC_CANDIDATES.length : index2;
|
|
1018
|
+
};
|
|
1019
|
+
return paths.sort((a, b) => priority2(a) - priority2(b) || a.localeCompare(b));
|
|
1020
|
+
}
|
|
1021
|
+
async function localDocPaths(root) {
|
|
1022
|
+
const paths = [];
|
|
1023
|
+
for (const dir of [".", ".claude"]) {
|
|
1024
|
+
let entries;
|
|
1025
|
+
try {
|
|
1026
|
+
entries = await fs5.readdir(await auditInputPath(root, dir), { withFileTypes: true });
|
|
1027
|
+
} catch (error) {
|
|
1028
|
+
if (error.code === "ENOENT") continue;
|
|
1029
|
+
throw error;
|
|
1030
|
+
}
|
|
1031
|
+
for (const entry of entries) if (/^(?:agents|claude|readme)\.md$/i.test(entry.name)) {
|
|
1032
|
+
paths.push(path6.posix.join(dir, entry.name));
|
|
747
1033
|
}
|
|
1034
|
+
}
|
|
1035
|
+
return paths;
|
|
1036
|
+
}
|
|
1037
|
+
function documentScope(file) {
|
|
1038
|
+
const parent = path6.posix.dirname(file);
|
|
1039
|
+
return path6.posix.basename(parent).toLowerCase() === ".claude" ? path6.posix.dirname(parent) : parent;
|
|
1040
|
+
}
|
|
1041
|
+
async function discoverDocs(resolvedRoot) {
|
|
1042
|
+
const docs = [];
|
|
1043
|
+
for (const candidate of await discoverDocPaths(resolvedRoot)) {
|
|
1044
|
+
const content2 = await readAuditInput(resolvedRoot, candidate);
|
|
1045
|
+
if (content2 === null) throw new Error("Document disappeared during discovery: " + candidate);
|
|
748
1046
|
const [lastCommit, dirty] = await Promise.all([lastCommitOf(resolvedRoot, candidate), isDirty(resolvedRoot, candidate)]);
|
|
749
|
-
|
|
1047
|
+
docs.push({
|
|
750
1048
|
path: candidate,
|
|
751
1049
|
content: content2,
|
|
1050
|
+
scope: documentScope(candidate),
|
|
1051
|
+
kind: /^readme\.md$/i.test(path6.posix.basename(candidate)) ? "readme" : "instructions",
|
|
752
1052
|
lineCount: content2.split("\n").length,
|
|
753
1053
|
lastCommit,
|
|
754
1054
|
dirty,
|
|
755
1055
|
claims: extractClaims(content2)
|
|
756
|
-
};
|
|
757
|
-
}
|
|
758
|
-
return docs
|
|
1056
|
+
});
|
|
1057
|
+
}
|
|
1058
|
+
return docs;
|
|
759
1059
|
}
|
|
760
1060
|
var exec3, DOC_CANDIDATES;
|
|
761
1061
|
var init_docs = __esm({
|
|
@@ -763,7 +1063,9 @@ var init_docs = __esm({
|
|
|
763
1063
|
"use strict";
|
|
764
1064
|
init_claims();
|
|
765
1065
|
init_git();
|
|
766
|
-
|
|
1066
|
+
init_inputs();
|
|
1067
|
+
init_files();
|
|
1068
|
+
exec3 = promisify4(execFile4);
|
|
767
1069
|
DOC_CANDIDATES = [
|
|
768
1070
|
"AGENTS.md",
|
|
769
1071
|
"CLAUDE.md",
|
|
@@ -772,10 +1074,50 @@ var init_docs = __esm({
|
|
|
772
1074
|
}
|
|
773
1075
|
});
|
|
774
1076
|
|
|
1077
|
+
// src/audit/scope.ts
|
|
1078
|
+
import fs6 from "fs/promises";
|
|
1079
|
+
import path7 from "path";
|
|
1080
|
+
function scopedPath(directory, value) {
|
|
1081
|
+
if (path7.posix.isAbsolute(value) || value.includes("\\") || /[\x00-\x1f]/.test(value)) return null;
|
|
1082
|
+
const resolved = path7.posix.normalize(path7.posix.join(directory, value));
|
|
1083
|
+
return resolved === ".." || resolved.startsWith("../") ? null : resolved;
|
|
1084
|
+
}
|
|
1085
|
+
function pathClaimScope(doc, claim) {
|
|
1086
|
+
const directory = claim.relativeTo === "document" ? path7.posix.dirname(doc) : documentScope(doc);
|
|
1087
|
+
const local = scopedPath(directory, claim.path);
|
|
1088
|
+
if (!local) return null;
|
|
1089
|
+
const candidates = claim.relativeTo === "document" || directory === "." ? [local] : [...new Set([local, scopedPath(".", claim.path)].filter((p) => p !== null))];
|
|
1090
|
+
return {
|
|
1091
|
+
basis: claim.relativeTo === "document" ? "document-link" : directory === "." ? "repository" : "document",
|
|
1092
|
+
directory,
|
|
1093
|
+
candidates
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
async function pathExists(root, file) {
|
|
1097
|
+
const absolute = await auditInputPath(root, file);
|
|
1098
|
+
try {
|
|
1099
|
+
await fs6.access(absolute);
|
|
1100
|
+
return true;
|
|
1101
|
+
} catch (error) {
|
|
1102
|
+
if (error.code === "ENOENT") return false;
|
|
1103
|
+
throw error;
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
function optionalMasonPath(file) {
|
|
1107
|
+
return file.split("/").includes(".mason");
|
|
1108
|
+
}
|
|
1109
|
+
var init_scope = __esm({
|
|
1110
|
+
"src/audit/scope.ts"() {
|
|
1111
|
+
"use strict";
|
|
1112
|
+
init_inputs();
|
|
1113
|
+
init_docs();
|
|
1114
|
+
}
|
|
1115
|
+
});
|
|
1116
|
+
|
|
775
1117
|
// src/test-map.ts
|
|
776
|
-
import
|
|
1118
|
+
import path8 from "path";
|
|
777
1119
|
async function buildTestMap(dir) {
|
|
778
|
-
const rootDir =
|
|
1120
|
+
const rootDir = path8.resolve(dir);
|
|
779
1121
|
const access = await createFileAccess(rootDir);
|
|
780
1122
|
const testPatterns = [
|
|
781
1123
|
"**/*.test.*",
|
|
@@ -796,7 +1138,7 @@ async function buildTestMap(dir) {
|
|
|
796
1138
|
const sourceByBaseName = /* @__PURE__ */ new Map();
|
|
797
1139
|
for (const file of sourceFiles) {
|
|
798
1140
|
if (testFiles.includes(file)) continue;
|
|
799
|
-
const baseName =
|
|
1141
|
+
const baseName = path8.basename(file).replace(/\.[^.]+$/, "");
|
|
800
1142
|
const existing = sourceByBaseName.get(baseName) ?? [];
|
|
801
1143
|
existing.push(file);
|
|
802
1144
|
sourceByBaseName.set(baseName, existing);
|
|
@@ -804,7 +1146,7 @@ async function buildTestMap(dir) {
|
|
|
804
1146
|
const paired = [];
|
|
805
1147
|
const unmatched = [];
|
|
806
1148
|
for (const testFile of testFiles) {
|
|
807
|
-
const testBaseName =
|
|
1149
|
+
const testBaseName = path8.basename(testFile).replace(/\.[^.]+$/, "");
|
|
808
1150
|
const sourceName = testBaseName.replace(/Test$|Tests$|Spec$|\.test$|\.spec$/, "").replace(/^test_|_test$/, "");
|
|
809
1151
|
if (!sourceName) {
|
|
810
1152
|
unmatched.push(testFile);
|
|
@@ -812,10 +1154,10 @@ async function buildTestMap(dir) {
|
|
|
812
1154
|
}
|
|
813
1155
|
const candidates = sourceByBaseName.get(sourceName);
|
|
814
1156
|
if (candidates && candidates.length > 0) {
|
|
815
|
-
const testDir =
|
|
1157
|
+
const testDir = path8.dirname(testFile);
|
|
816
1158
|
const bestMatch = candidates.reduce((best, candidate) => {
|
|
817
|
-
const candidateDir =
|
|
818
|
-
const bestDir =
|
|
1159
|
+
const candidateDir = path8.dirname(candidate);
|
|
1160
|
+
const bestDir = path8.dirname(best);
|
|
819
1161
|
const candidateOverlap = commonSegments(testDir, candidateDir);
|
|
820
1162
|
const bestOverlap = commonSegments(testDir, bestDir);
|
|
821
1163
|
return candidateOverlap > bestOverlap ? candidate : best;
|
|
@@ -834,12 +1176,12 @@ async function buildTestMap(dir) {
|
|
|
834
1176
|
function commonSegments(pathA, pathB) {
|
|
835
1177
|
const segsA = pathA.split("/");
|
|
836
1178
|
const segsB = pathB.split("/");
|
|
837
|
-
let
|
|
1179
|
+
let count4 = 0;
|
|
838
1180
|
for (let i = 0; i < Math.min(segsA.length, segsB.length); i++) {
|
|
839
|
-
if (segsA[i] === segsB[i])
|
|
1181
|
+
if (segsA[i] === segsB[i]) count4++;
|
|
840
1182
|
else break;
|
|
841
1183
|
}
|
|
842
|
-
return
|
|
1184
|
+
return count4;
|
|
843
1185
|
}
|
|
844
1186
|
var init_test_map = __esm({
|
|
845
1187
|
"src/test-map.ts"() {
|
|
@@ -849,9 +1191,9 @@ var init_test_map = __esm({
|
|
|
849
1191
|
});
|
|
850
1192
|
|
|
851
1193
|
// src/snapshot/snapshot.ts
|
|
852
|
-
import
|
|
853
|
-
import { execFile as
|
|
854
|
-
import { promisify as
|
|
1194
|
+
import path9 from "path";
|
|
1195
|
+
import { execFile as execFile5 } from "child_process";
|
|
1196
|
+
import { promisify as promisify5 } from "util";
|
|
855
1197
|
import { z as z2 } from "zod";
|
|
856
1198
|
async function inspectSnapshot(rootDir) {
|
|
857
1199
|
try {
|
|
@@ -884,7 +1226,7 @@ var init_snapshot = __esm({
|
|
|
884
1226
|
init_storage();
|
|
885
1227
|
init_paths();
|
|
886
1228
|
init_test_map();
|
|
887
|
-
exec4 =
|
|
1229
|
+
exec4 = promisify5(execFile5);
|
|
888
1230
|
repoPath = z2.string().refine((value) => normalizeRepoPath(value) !== null, "Expected a relative repository path");
|
|
889
1231
|
verificationFields = {
|
|
890
1232
|
refreshedHash: z2.string().optional(),
|
|
@@ -913,10 +1255,10 @@ var init_snapshot = __esm({
|
|
|
913
1255
|
});
|
|
914
1256
|
|
|
915
1257
|
// src/drift/drift.ts
|
|
916
|
-
import
|
|
917
|
-
import
|
|
918
|
-
import { execFile as
|
|
919
|
-
import { promisify as
|
|
1258
|
+
import fs7 from "fs/promises";
|
|
1259
|
+
import path10 from "path";
|
|
1260
|
+
import { execFile as execFile6 } from "child_process";
|
|
1261
|
+
import { promisify as promisify6 } from "util";
|
|
920
1262
|
function parseChanges(output) {
|
|
921
1263
|
const fields = output.split("\0");
|
|
922
1264
|
const changes = [];
|
|
@@ -939,273 +1281,111 @@ async function getChangesWithStatus(resolvedRoot, fromHash, toHash = "HEAD") {
|
|
|
939
1281
|
try {
|
|
940
1282
|
const { stdout } = await exec5("git", ["diff", "--name-status", "-z", "-M", fromHash, toHash, "--"], { cwd: resolvedRoot, maxBuffer: 10 * 1024 * 1024 });
|
|
941
1283
|
return parseChanges(stdout);
|
|
942
|
-
} catch {
|
|
943
|
-
return null;
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
async function getWorkingTree(resolvedRoot) {
|
|
947
|
-
try {
|
|
948
|
-
const [diff, untracked] = await Promise.all([
|
|
949
|
-
exec5("git", ["diff", "--name-status", "-z", "-M", "HEAD", "--"], { cwd: resolvedRoot, maxBuffer: 10 * 1024 * 1024 }),
|
|
950
|
-
exec5("git", ["ls-files", "-z", "--others", "--exclude-standard"], { cwd: resolvedRoot, maxBuffer: 10 * 1024 * 1024 })
|
|
951
|
-
]);
|
|
952
|
-
const untrackedFiles = untracked.stdout.split("\0").filter((f) => f && !f.startsWith(".mason/"));
|
|
953
|
-
return { available: true, changedFiles: [.../* @__PURE__ */ new Set([...touchedPaths(parseChanges(diff.stdout)), ...untrackedFiles])].sort(), untrackedFiles };
|
|
954
|
-
} catch {
|
|
955
|
-
return { available: false, changedFiles: [], untrackedFiles: [] };
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
|
-
var exec5;
|
|
959
|
-
var init_drift = __esm({
|
|
960
|
-
"src/drift/drift.ts"() {
|
|
961
|
-
"use strict";
|
|
962
|
-
init_snapshot();
|
|
963
|
-
init_paths();
|
|
964
|
-
exec5 = promisify5(execFile5);
|
|
965
|
-
}
|
|
966
|
-
});
|
|
967
|
-
|
|
968
|
-
// src/audit/types.ts
|
|
969
|
-
var ALL_CHECKS;
|
|
970
|
-
var init_types = __esm({
|
|
971
|
-
"src/audit/types.ts"() {
|
|
972
|
-
"use strict";
|
|
973
|
-
ALL_CHECKS = [
|
|
974
|
-
"deleted-reference",
|
|
975
|
-
"new-module",
|
|
976
|
-
"stale-count",
|
|
977
|
-
"dead-command",
|
|
978
|
-
"deps-changed",
|
|
979
|
-
"decision-anchor-drift"
|
|
980
|
-
];
|
|
981
|
-
}
|
|
982
|
-
});
|
|
983
|
-
|
|
984
|
-
// src/audit/checks/deleted-reference.ts
|
|
985
|
-
import fs6 from "fs/promises";
|
|
986
|
-
import path8 from "path";
|
|
987
|
-
async function exists(absPath) {
|
|
988
|
-
try {
|
|
989
|
-
await fs6.access(absPath);
|
|
990
|
-
return true;
|
|
991
|
-
} catch {
|
|
992
|
-
return false;
|
|
993
|
-
}
|
|
994
|
-
}
|
|
995
|
-
async function checkDeletedReferences(ctx) {
|
|
996
|
-
const result = emptyResult();
|
|
997
|
-
for (const doc of ctx.docs) {
|
|
998
|
-
const changes = ctx.changesSinceDoc.get(doc.path);
|
|
999
|
-
const renames = /* @__PURE__ */ new Map();
|
|
1000
|
-
for (const change of changes ?? []) {
|
|
1001
|
-
if (change.status === "renamed" && change.previousPath) {
|
|
1002
|
-
renames.set(change.previousPath, change.path);
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
|
-
for (const claim of doc.claims.paths) {
|
|
1006
|
-
if (claim.path === ".mason" || claim.path.startsWith(".mason/")) {
|
|
1007
|
-
continue;
|
|
1008
|
-
}
|
|
1009
|
-
if (await exists(path8.join(ctx.root, claim.path))) continue;
|
|
1010
|
-
const anchor = { doc: doc.path, line: claim.line, excerpt: claim.excerpt };
|
|
1011
|
-
const renamedTo = renames.get(claim.path) ?? null;
|
|
1012
|
-
if (renamedTo) {
|
|
1013
|
-
result.issues.push({
|
|
1014
|
-
type: "deleted-reference",
|
|
1015
|
-
message: `\`${claim.path}\` was renamed to \`${renamedTo}\``,
|
|
1016
|
-
anchor,
|
|
1017
|
-
confidence: "certain",
|
|
1018
|
-
evidence: {
|
|
1019
|
-
kind: "missing-path",
|
|
1020
|
-
claimed: claim.path,
|
|
1021
|
-
renamedTo,
|
|
1022
|
-
deletedInCommit: null,
|
|
1023
|
-
everTracked: true,
|
|
1024
|
-
parentDirExists: true
|
|
1025
|
-
}
|
|
1026
|
-
});
|
|
1027
|
-
continue;
|
|
1028
|
-
}
|
|
1029
|
-
const tracked = await lastCommitOf(ctx.root, claim.path);
|
|
1030
|
-
if (tracked) {
|
|
1031
|
-
const deleted = await deletingCommitOf(ctx.root, claim.path);
|
|
1032
|
-
const detail = deleted ? ` \u2013 deleted in ${deleted.hash.slice(0, 7)} "${deleted.subject}" (${deleted.date.slice(0, 10)})` : "";
|
|
1033
|
-
result.issues.push({
|
|
1034
|
-
type: "deleted-reference",
|
|
1035
|
-
message: `\`${claim.path}\` no longer exists${detail}`,
|
|
1036
|
-
anchor,
|
|
1037
|
-
confidence: "certain",
|
|
1038
|
-
evidence: {
|
|
1039
|
-
kind: "missing-path",
|
|
1040
|
-
claimed: claim.path,
|
|
1041
|
-
renamedTo: null,
|
|
1042
|
-
deletedInCommit: deleted,
|
|
1043
|
-
everTracked: true,
|
|
1044
|
-
parentDirExists: await exists(
|
|
1045
|
-
path8.join(ctx.root, path8.dirname(claim.path))
|
|
1046
|
-
)
|
|
1047
|
-
}
|
|
1048
|
-
});
|
|
1049
|
-
continue;
|
|
1050
|
-
}
|
|
1051
|
-
const parentDirExists = await exists(
|
|
1052
|
-
path8.join(ctx.root, path8.dirname(claim.path))
|
|
1053
|
-
);
|
|
1054
|
-
if (!parentDirExists) continue;
|
|
1055
|
-
const issue = {
|
|
1056
|
-
type: "deleted-reference",
|
|
1057
|
-
message: `\`${claim.path}\` does not exist (never tracked in git \u2013 possible typo or invented path)`,
|
|
1058
|
-
anchor,
|
|
1059
|
-
confidence: "likely",
|
|
1060
|
-
evidence: {
|
|
1061
|
-
kind: "missing-path",
|
|
1062
|
-
claimed: claim.path,
|
|
1063
|
-
renamedTo: null,
|
|
1064
|
-
deletedInCommit: null,
|
|
1065
|
-
everTracked: false,
|
|
1066
|
-
parentDirExists: true
|
|
1067
|
-
}
|
|
1068
|
-
};
|
|
1069
|
-
result.issues.push(issue);
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
return result;
|
|
1073
|
-
}
|
|
1074
|
-
var init_deleted_reference = __esm({
|
|
1075
|
-
"src/audit/checks/deleted-reference.ts"() {
|
|
1076
|
-
"use strict";
|
|
1077
|
-
init_git();
|
|
1078
|
-
init_checks();
|
|
1079
|
-
}
|
|
1080
|
-
});
|
|
1081
|
-
|
|
1082
|
-
// src/audit/inputs.ts
|
|
1083
|
-
import fs7 from "fs/promises";
|
|
1084
|
-
import * as nativeFs from "fs";
|
|
1085
|
-
import path9 from "path";
|
|
1086
|
-
import { execFile as execFile6 } from "child_process";
|
|
1087
|
-
import { promisify as promisify6 } from "util";
|
|
1088
|
-
import fg2 from "fast-glob";
|
|
1089
|
-
async function auditInputPath(root, file) {
|
|
1090
|
-
if (file === ".") return fs7.realpath(root);
|
|
1091
|
-
try {
|
|
1092
|
-
return await storePath(root, file);
|
|
1093
|
-
} catch (error) {
|
|
1094
|
-
if (error instanceof Error && error.message.startsWith("Symlink")) {
|
|
1095
|
-
throw new Error(`Audit input contains a symbolic link: ${file}. Its evidence could not be verified.`, { cause: error });
|
|
1096
|
-
}
|
|
1097
|
-
throw error;
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
async function readAuditInput(root, file) {
|
|
1101
|
-
try {
|
|
1102
|
-
const value = await readBoundedFile(await auditInputPath(root, file), 10 * 1024 * 1024);
|
|
1103
|
-
if (value === null) throw new Error(`Unreadable or oversized audit input: ${file}`);
|
|
1104
|
-
return value;
|
|
1105
|
-
} catch (error) {
|
|
1106
|
-
if (error.code === "ENOENT") return null;
|
|
1107
|
-
throw error;
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1110
|
-
async function auditGlob(root, patterns, options) {
|
|
1111
|
-
if (Array.isArray(patterns) && !patterns.length) return [];
|
|
1112
|
-
const directories = /* @__PURE__ */ new Set();
|
|
1113
|
-
const readdir2 = ((directory, opts, callback) => {
|
|
1114
|
-
const relative = path9.relative(root, directory).split(path9.sep).join("/") || ".";
|
|
1115
|
-
directories.add(relative);
|
|
1116
|
-
if (directories.size > MAX_INPUTS) {
|
|
1117
|
-
callback(new Error(`${options.label} exceeds ${MAX_INPUTS.toLocaleString("en-US")} directories while inspecting ${relative}. Narrow this check's inputs.`));
|
|
1118
|
-
return;
|
|
1119
|
-
}
|
|
1120
|
-
auditInputPath(root, relative).then(() => {
|
|
1121
|
-
nativeFs.readdir(directory, opts, callback);
|
|
1122
|
-
}, callback);
|
|
1123
|
-
});
|
|
1124
|
-
const lstat2 = ((file, callback) => {
|
|
1125
|
-
const relative = path9.relative(root, file).split(path9.sep).join("/") || ".";
|
|
1126
|
-
auditInputPath(root, relative).then(() => nativeFs.lstat(file, callback), callback);
|
|
1127
|
-
});
|
|
1128
|
-
const stream = fg2.stream(patterns, {
|
|
1129
|
-
cwd: root,
|
|
1130
|
-
ignore: options.ignore,
|
|
1131
|
-
onlyFiles: false,
|
|
1132
|
-
onlyDirectories: options.onlyDirectories,
|
|
1133
|
-
objectMode: true,
|
|
1134
|
-
followSymbolicLinks: options.followSymbolicLinks ?? true,
|
|
1135
|
-
fs: { readdir: readdir2, lstat: lstat2 },
|
|
1136
|
-
concurrency: 16
|
|
1137
|
-
});
|
|
1138
|
-
const matches = [];
|
|
1139
|
-
try {
|
|
1140
|
-
for await (const value of stream) {
|
|
1141
|
-
const entry = value;
|
|
1142
|
-
const file = entry.path;
|
|
1143
|
-
if (options.select && !options.select(file)) continue;
|
|
1144
|
-
await auditInputPath(root, file);
|
|
1145
|
-
if (!options.onlyDirectories && !entry.dirent.isFile()) continue;
|
|
1146
|
-
matches.push(file);
|
|
1147
|
-
if (matches.length > MAX_INPUTS) {
|
|
1148
|
-
const largest = [...matches.reduce((counts, item) => {
|
|
1149
|
-
const dir = item.split("/")[0];
|
|
1150
|
-
counts.set(dir, (counts.get(dir) ?? 0) + 1);
|
|
1151
|
-
return counts;
|
|
1152
|
-
}, /* @__PURE__ */ new Map())].sort((a, b) => b[1] - a[1]).slice(0, 3);
|
|
1153
|
-
throw new Error(`${options.label} exceeds ${MAX_INPUTS.toLocaleString("en-US")} relevant paths. Largest directories: ${largest.map(([dir, count3]) => `${dir} (${count3})`).join(", ")}. Narrow this check's inputs.`);
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
} finally {
|
|
1157
|
-
stream.destroy();
|
|
1284
|
+
} catch {
|
|
1285
|
+
return null;
|
|
1158
1286
|
}
|
|
1159
|
-
return matches.sort();
|
|
1160
|
-
}
|
|
1161
|
-
async function gitSourcePaths(root) {
|
|
1162
|
-
const { stdout } = await execute(
|
|
1163
|
-
"git",
|
|
1164
|
-
[
|
|
1165
|
-
"ls-files",
|
|
1166
|
-
"-z",
|
|
1167
|
-
"--cached",
|
|
1168
|
-
"--others",
|
|
1169
|
-
"--exclude-standard",
|
|
1170
|
-
"--",
|
|
1171
|
-
...SOURCE_EXTENSIONS.map((extension) => `:(glob)**/*.${extension}`)
|
|
1172
|
-
],
|
|
1173
|
-
{ cwd: root, maxBuffer: 32 * 1024 * 1024, timeout: 1e4 }
|
|
1174
|
-
);
|
|
1175
|
-
return [...new Set(stdout.split("\0").filter(Boolean))].sort();
|
|
1176
1287
|
}
|
|
1177
|
-
async function
|
|
1178
|
-
if (!files.length) return /* @__PURE__ */ new Set();
|
|
1179
|
-
const operation = execute(
|
|
1180
|
-
"git",
|
|
1181
|
-
["check-ignore", "-z", "--stdin"],
|
|
1182
|
-
{ cwd: root, maxBuffer: 4 * 1024 * 1024, timeout: 1e4 }
|
|
1183
|
-
);
|
|
1184
|
-
operation.child.stdin.on("error", () => {
|
|
1185
|
-
});
|
|
1186
|
-
operation.child.stdin.end(files.join("\0") + "\0");
|
|
1288
|
+
async function getWorkingTree(resolvedRoot) {
|
|
1187
1289
|
try {
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1290
|
+
const [diff, untracked] = await Promise.all([
|
|
1291
|
+
exec5("git", ["diff", "--name-status", "-z", "-M", "HEAD", "--"], { cwd: resolvedRoot, maxBuffer: 10 * 1024 * 1024 }),
|
|
1292
|
+
exec5("git", ["ls-files", "-z", "--others", "--exclude-standard"], { cwd: resolvedRoot, maxBuffer: 10 * 1024 * 1024 })
|
|
1293
|
+
]);
|
|
1294
|
+
const untrackedFiles = untracked.stdout.split("\0").filter((f) => f && !f.startsWith(".mason/"));
|
|
1295
|
+
return { available: true, changedFiles: [.../* @__PURE__ */ new Set([...touchedPaths(parseChanges(diff.stdout)), ...untrackedFiles])].sort(), untrackedFiles };
|
|
1296
|
+
} catch {
|
|
1297
|
+
return { available: false, changedFiles: [], untrackedFiles: [] };
|
|
1192
1298
|
}
|
|
1193
1299
|
}
|
|
1194
|
-
var
|
|
1195
|
-
var
|
|
1196
|
-
"src/
|
|
1300
|
+
var exec5;
|
|
1301
|
+
var init_drift = __esm({
|
|
1302
|
+
"src/drift/drift.ts"() {
|
|
1197
1303
|
"use strict";
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1304
|
+
init_snapshot();
|
|
1305
|
+
init_paths();
|
|
1306
|
+
exec5 = promisify6(execFile6);
|
|
1307
|
+
}
|
|
1308
|
+
});
|
|
1309
|
+
|
|
1310
|
+
// src/audit/types.ts
|
|
1311
|
+
var ALL_CHECKS;
|
|
1312
|
+
var init_types = __esm({
|
|
1313
|
+
"src/audit/types.ts"() {
|
|
1314
|
+
"use strict";
|
|
1315
|
+
ALL_CHECKS = [
|
|
1316
|
+
"deleted-reference",
|
|
1317
|
+
"new-module",
|
|
1318
|
+
"stale-count",
|
|
1319
|
+
"dead-command",
|
|
1320
|
+
"deps-changed",
|
|
1321
|
+
"decision-anchor-drift"
|
|
1322
|
+
];
|
|
1323
|
+
}
|
|
1324
|
+
});
|
|
1325
|
+
|
|
1326
|
+
// src/audit/checks/deleted-reference.ts
|
|
1327
|
+
import path11 from "path";
|
|
1328
|
+
async function checkDeletedReferences(ctx) {
|
|
1329
|
+
const result = emptyResult();
|
|
1330
|
+
for (const doc of ctx.docs) {
|
|
1331
|
+
const changes = ctx.changesSinceDoc.get(doc.path);
|
|
1332
|
+
const renames = new Map((changes ?? []).filter((c) => c.status === "renamed" && c.previousPath).map((c) => [c.previousPath, c.path]));
|
|
1333
|
+
for (const claim of doc.claims.paths) {
|
|
1334
|
+
const scope = pathClaimScope(doc.path, claim);
|
|
1335
|
+
if (!scope) {
|
|
1336
|
+
result.skipped.push({
|
|
1337
|
+
check: "deleted-reference",
|
|
1338
|
+
doc: doc.path,
|
|
1339
|
+
reason: `Reference ${claim.excerpt} is outside the repository or has an unsupported path.`
|
|
1340
|
+
});
|
|
1341
|
+
continue;
|
|
1342
|
+
}
|
|
1343
|
+
if (scope.candidates.some(optionalMasonPath)) continue;
|
|
1344
|
+
if ((await Promise.all(scope.candidates.map((file) => pathExists(ctx.root, file)))).some(Boolean)) continue;
|
|
1345
|
+
const candidates = await Promise.all(scope.candidates.map(async (file) => ({
|
|
1346
|
+
file,
|
|
1347
|
+
tracked: await lastCommitOf(ctx.root, file),
|
|
1348
|
+
parent: await pathExists(ctx.root, path11.posix.dirname(file))
|
|
1349
|
+
})));
|
|
1350
|
+
const candidate = candidates.find((c) => c.tracked || renames.has(c.file)) ?? candidates.find((c) => c.parent);
|
|
1351
|
+
if (!candidate && claim.relativeTo !== "document") continue;
|
|
1352
|
+
const resolvedPath = candidate?.file ?? scope.candidates[0];
|
|
1353
|
+
const renamedTo = renames.get(resolvedPath) ?? null;
|
|
1354
|
+
const deletedInCommit = candidate?.tracked && !renamedTo ? await deletingCommitOf(ctx.root, resolvedPath) : null;
|
|
1355
|
+
const evidence = {
|
|
1356
|
+
kind: "missing-path",
|
|
1357
|
+
claimed: claim.path,
|
|
1358
|
+
resolvedPath,
|
|
1359
|
+
scope,
|
|
1360
|
+
renamedTo,
|
|
1361
|
+
deletedInCommit,
|
|
1362
|
+
everTracked: !!candidate?.tracked || !!renamedTo,
|
|
1363
|
+
parentDirExists: candidate?.parent ?? false
|
|
1364
|
+
};
|
|
1365
|
+
const anchor = { doc: doc.path, line: claim.line, excerpt: claim.excerpt };
|
|
1366
|
+
const message2 = renamedTo ? `\`${resolvedPath}\` was renamed to \`${renamedTo}\`` : `\`${resolvedPath}\` does not exist` + (deletedInCommit ? ` \u2013 deleted in ${deletedInCommit.hash.slice(0, 7)} "${deletedInCommit.subject}" (${deletedInCommit.date.slice(0, 10)})` : "");
|
|
1367
|
+
if (scope.basis !== "document" && (renamedTo || candidate?.tracked)) {
|
|
1368
|
+
result.issues.push({ type: "deleted-reference", message: message2, anchor, confidence: "certain", evidence });
|
|
1369
|
+
} else {
|
|
1370
|
+
result.advisories.push({ resolution: "recheck", type: "deleted-reference", message: message2 + (scope.basis === "document" ? "; the bare path's document/repository scope needs review." : "; no tracked history establishes it as a required file. Review for a typo, generated output, or example."), anchor, evidence });
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
return result;
|
|
1375
|
+
}
|
|
1376
|
+
var init_deleted_reference = __esm({
|
|
1377
|
+
"src/audit/checks/deleted-reference.ts"() {
|
|
1378
|
+
"use strict";
|
|
1379
|
+
init_git();
|
|
1380
|
+
init_scope();
|
|
1381
|
+
init_checks();
|
|
1202
1382
|
}
|
|
1203
1383
|
});
|
|
1204
1384
|
|
|
1205
1385
|
// src/audit/checks/new-module.ts
|
|
1206
|
-
import
|
|
1386
|
+
import fg4 from "fast-glob";
|
|
1207
1387
|
import fs8 from "fs/promises";
|
|
1208
|
-
import
|
|
1388
|
+
import path12 from "path";
|
|
1209
1389
|
function escapeRegExp(text2) {
|
|
1210
1390
|
return text2.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1211
1391
|
}
|
|
@@ -1219,15 +1399,15 @@ function isMentioned(combinedDocs, name) {
|
|
|
1219
1399
|
async function checkNewModules(ctx) {
|
|
1220
1400
|
const result = emptyResult();
|
|
1221
1401
|
if (ctx.docs.length === 0) return result;
|
|
1222
|
-
const combinedDocs = ctx.docs
|
|
1402
|
+
const combinedDocs = moduleDocumentation(ctx.docs);
|
|
1223
1403
|
const primaryDoc = ctx.docs[0].path;
|
|
1224
1404
|
const checkedDocs = ctx.docs.map((d) => d.path);
|
|
1225
1405
|
const flag = async (dir, sourceFileCount) => {
|
|
1226
|
-
result.
|
|
1406
|
+
result.advisories.push({
|
|
1407
|
+
resolution: "recheck",
|
|
1227
1408
|
type: "new-module",
|
|
1228
|
-
message: `directory \`${dir}/\` contains ${sourceFileCount} source file${sourceFileCount === 1 ? "" : "s"} but is not mentioned in
|
|
1409
|
+
message: `directory \`${dir}/\` contains ${sourceFileCount} source file${sourceFileCount === 1 ? "" : "s"} but is not mentioned in the discovered documentation; review whether it needs documenting`,
|
|
1229
1410
|
anchor: { doc: primaryDoc, line: null, excerpt: dir },
|
|
1230
|
-
confidence: "likely",
|
|
1231
1411
|
evidence: {
|
|
1232
1412
|
kind: "unmentioned-dir",
|
|
1233
1413
|
dir,
|
|
@@ -1242,41 +1422,44 @@ async function checkNewModules(ctx) {
|
|
|
1242
1422
|
}
|
|
1243
1423
|
return result;
|
|
1244
1424
|
}
|
|
1425
|
+
function moduleDocumentation(docs) {
|
|
1426
|
+
return docs.map((doc) => doc.content + "\n" + (path12.posix.dirname(doc.path) === "." ? "" : path12.posix.dirname(doc.path) + "/")).join("\n");
|
|
1427
|
+
}
|
|
1245
1428
|
async function moduleCandidates(root, combinedDocs) {
|
|
1246
1429
|
const [config, sourcePaths] = await Promise.all([loadProjectConfig(root), gitSourcePaths(root)]);
|
|
1247
1430
|
const ignore = [...SOURCE_IGNORE, ...config.ignore ?? []];
|
|
1248
1431
|
const sources = sourcePaths.filter((file) => !file.split("/").some((part) => part.startsWith(".")));
|
|
1249
1432
|
const listSubdirs = async (dir) => {
|
|
1250
1433
|
const entries = await fs8.readdir(await auditInputPath(root, dir), { withFileTypes: true });
|
|
1251
|
-
const dirs = entries.filter((entry) => (entry.isDirectory() || entry.isSymbolicLink()) && !entry.name.startsWith(".") && !DIR_DENYLIST.has(entry.name)).map((entry) =>
|
|
1434
|
+
const dirs = entries.filter((entry) => (entry.isDirectory() || entry.isSymbolicLink() && sources.some((file) => file.startsWith(path12.posix.join(dir, entry.name) + "/"))) && !entry.name.startsWith(".") && !DIR_DENYLIST.has(entry.name)).map((entry) => path12.posix.join(dir, entry.name));
|
|
1252
1435
|
const ignored = await gitIgnoredPaths(root, dirs);
|
|
1253
1436
|
const visible = new Set(dirs.filter((dir2) => !ignored.has(dir2) || sources.some((file) => file.startsWith(dir2 + "/"))));
|
|
1254
|
-
return (await auditGlob(root, dir === "." ? "*" : `${
|
|
1437
|
+
return (await auditGlob(root, dir === "." ? "*" : `${fg4.escapePath(dir)}/*`, {
|
|
1255
1438
|
ignore,
|
|
1256
1439
|
onlyDirectories: true,
|
|
1257
1440
|
label: "Module directory discovery",
|
|
1258
1441
|
select: (file) => visible.has(file)
|
|
1259
|
-
})).map((file) =>
|
|
1442
|
+
})).map((file) => path12.posix.basename(file));
|
|
1260
1443
|
};
|
|
1261
1444
|
const countSourceFiles = async (dir) => {
|
|
1262
1445
|
const files = sources.filter((file) => file.startsWith(dir + "/"));
|
|
1263
|
-
let
|
|
1446
|
+
let count4 = 0;
|
|
1264
1447
|
for (let offset = 0; offset < files.length; offset += 256) {
|
|
1265
|
-
|
|
1448
|
+
count4 += (await auditGlob(root, files.slice(offset, offset + 256).map((file) => fg4.escapePath(file)), {
|
|
1266
1449
|
ignore,
|
|
1267
1450
|
followSymbolicLinks: false,
|
|
1268
1451
|
label: `Source discovery in ${dir}`
|
|
1269
1452
|
})).length;
|
|
1270
|
-
if (
|
|
1453
|
+
if (count4 > 1e5) throw new Error(`Source discovery in ${dir} exceeds 100,000 relevant files. Exclude generated source with .mason/config.json ignore patterns or narrow this audit's checks.`);
|
|
1271
1454
|
}
|
|
1272
|
-
return
|
|
1455
|
+
return count4;
|
|
1273
1456
|
};
|
|
1274
1457
|
const candidates = [];
|
|
1275
1458
|
for (const topDir of await listSubdirs(".")) {
|
|
1276
1459
|
const topMentioned = isMentioned(combinedDocs, topDir);
|
|
1277
1460
|
if (!topMentioned) {
|
|
1278
|
-
const
|
|
1279
|
-
if (
|
|
1461
|
+
const count4 = await countSourceFiles(topDir);
|
|
1462
|
+
if (count4 >= 1) candidates.push({ dir: topDir, sourceFileCount: count4 });
|
|
1280
1463
|
continue;
|
|
1281
1464
|
}
|
|
1282
1465
|
const subdirs = await listSubdirs(topDir);
|
|
@@ -1284,9 +1467,9 @@ async function moduleCandidates(root, combinedDocs) {
|
|
|
1284
1467
|
if (mentioned.length < ENUMERATION_THRESHOLD) continue;
|
|
1285
1468
|
for (const sub of subdirs) {
|
|
1286
1469
|
if (isMentioned(combinedDocs, sub)) continue;
|
|
1287
|
-
const
|
|
1288
|
-
if (
|
|
1289
|
-
candidates.push({ dir: `${topDir}/${sub}`, sourceFileCount:
|
|
1470
|
+
const count4 = await countSourceFiles(`${topDir}/${sub}`);
|
|
1471
|
+
if (count4 >= SECOND_LEVEL_MIN_SOURCE_FILES) {
|
|
1472
|
+
candidates.push({ dir: `${topDir}/${sub}`, sourceFileCount: count4 });
|
|
1290
1473
|
}
|
|
1291
1474
|
}
|
|
1292
1475
|
}
|
|
@@ -1325,7 +1508,7 @@ var init_new_module = __esm({
|
|
|
1325
1508
|
});
|
|
1326
1509
|
|
|
1327
1510
|
// src/audit/checks/stale-count.ts
|
|
1328
|
-
import
|
|
1511
|
+
import path13 from "path";
|
|
1329
1512
|
async function countGradleModules(root) {
|
|
1330
1513
|
for (const name of ["settings.gradle.kts", "settings.gradle"]) {
|
|
1331
1514
|
const content2 = await readAuditInput(root, name);
|
|
@@ -1359,7 +1542,7 @@ async function countNpmWorkspaces(root) {
|
|
|
1359
1542
|
return {
|
|
1360
1543
|
actual: matched.length,
|
|
1361
1544
|
countedFrom: "package.json workspaces",
|
|
1362
|
-
members: matched.map((m) =>
|
|
1545
|
+
members: matched.map((m) => path13.dirname(m)).sort()
|
|
1363
1546
|
};
|
|
1364
1547
|
}
|
|
1365
1548
|
}
|
|
@@ -1390,7 +1573,7 @@ async function countNpmWorkspaces(root) {
|
|
|
1390
1573
|
return {
|
|
1391
1574
|
actual: matched.length,
|
|
1392
1575
|
countedFrom: "pnpm-workspace.yaml",
|
|
1393
|
-
members: matched.map((m) =>
|
|
1576
|
+
members: matched.map((m) => path13.dirname(m)).sort()
|
|
1394
1577
|
};
|
|
1395
1578
|
}
|
|
1396
1579
|
}
|
|
@@ -1412,8 +1595,8 @@ async function countCargoCrates(root) {
|
|
|
1412
1595
|
ignore: ["**/target/**"],
|
|
1413
1596
|
label: "Cargo workspace discovery"
|
|
1414
1597
|
});
|
|
1415
|
-
for (const m of matched) members.add(
|
|
1416
|
-
} else if (await readAuditInput(root,
|
|
1598
|
+
for (const m of matched) members.add(path13.dirname(m));
|
|
1599
|
+
} else if (await readAuditInput(root, path13.posix.join(entry, "Cargo.toml")) !== null) {
|
|
1417
1600
|
members.add(entry);
|
|
1418
1601
|
}
|
|
1419
1602
|
}
|
|
@@ -1431,11 +1614,21 @@ async function resolveCountSource(root, claim) {
|
|
|
1431
1614
|
if (unit === "crate") return countCargoCrates(root);
|
|
1432
1615
|
return await countNpmWorkspaces(root) ?? await countCargoCrates(root) ?? await countGradleModules(root);
|
|
1433
1616
|
}
|
|
1617
|
+
async function resolveDocCountSource(root, doc, claim) {
|
|
1618
|
+
const scope = documentScope(doc);
|
|
1619
|
+
const source = await resolveCountSource(path13.join(root, scope), claim);
|
|
1620
|
+
if (!source || scope === ".") return source;
|
|
1621
|
+
return {
|
|
1622
|
+
...source,
|
|
1623
|
+
countedFrom: scope + "/" + source.countedFrom,
|
|
1624
|
+
members: source.members.map((member) => scope + "/" + member)
|
|
1625
|
+
};
|
|
1626
|
+
}
|
|
1434
1627
|
async function checkStaleCounts(ctx) {
|
|
1435
1628
|
const result = emptyResult();
|
|
1436
1629
|
for (const doc of ctx.docs) {
|
|
1437
1630
|
for (const claim of doc.claims.counts) {
|
|
1438
|
-
const source = await
|
|
1631
|
+
const source = await resolveDocCountSource(ctx.root, doc.path, claim);
|
|
1439
1632
|
if (source === null) {
|
|
1440
1633
|
result.skipped.push({
|
|
1441
1634
|
check: "stale-count",
|
|
@@ -1467,6 +1660,7 @@ var MEMBERS_CAP;
|
|
|
1467
1660
|
var init_stale_count = __esm({
|
|
1468
1661
|
"src/audit/checks/stale-count.ts"() {
|
|
1469
1662
|
"use strict";
|
|
1663
|
+
init_docs();
|
|
1470
1664
|
init_inputs();
|
|
1471
1665
|
init_checks();
|
|
1472
1666
|
MEMBERS_CAP = 50;
|
|
@@ -1474,61 +1668,94 @@ var init_stale_count = __esm({
|
|
|
1474
1668
|
});
|
|
1475
1669
|
|
|
1476
1670
|
// src/audit/checks/dead-command.ts
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
if (raw === null) return null;
|
|
1671
|
+
import path14 from "path";
|
|
1672
|
+
function scriptsOf(raw) {
|
|
1480
1673
|
try {
|
|
1481
1674
|
const pkg = JSON.parse(raw);
|
|
1482
|
-
|
|
1675
|
+
if (!pkg || typeof pkg !== "object" || Array.isArray(pkg)) return null;
|
|
1676
|
+
if (pkg.scripts === void 0) return [];
|
|
1677
|
+
return pkg.scripts && typeof pkg.scripts === "object" && !Array.isArray(pkg.scripts) && Object.values(pkg.scripts).every((value) => typeof value === "string") ? Object.keys(pkg.scripts) : null;
|
|
1483
1678
|
} catch {
|
|
1484
1679
|
return null;
|
|
1485
1680
|
}
|
|
1486
1681
|
}
|
|
1682
|
+
async function commandInputs(root, docs) {
|
|
1683
|
+
const contents = /* @__PURE__ */ new Map();
|
|
1684
|
+
const read = async (file) => {
|
|
1685
|
+
if (!contents.has(file)) contents.set(file, await readAuditInput(root, file));
|
|
1686
|
+
return contents.get(file);
|
|
1687
|
+
};
|
|
1688
|
+
await read("package.json");
|
|
1689
|
+
let inventory;
|
|
1690
|
+
const resolutions = [];
|
|
1691
|
+
for (const doc of docs) for (const claim of doc.claims.commands) {
|
|
1692
|
+
const base = documentScope(doc.path);
|
|
1693
|
+
const directory = scopedPath(base, claim.directory ?? ".");
|
|
1694
|
+
const scope = {
|
|
1695
|
+
basis: claim.directory === void 0 ? "document" : "explicit",
|
|
1696
|
+
directory: directory ?? base,
|
|
1697
|
+
candidates: []
|
|
1698
|
+
};
|
|
1699
|
+
const resolution = { doc: doc.path, claim, scope, manifest: null, scripts: [], elsewhere: [] };
|
|
1700
|
+
resolutions.push(resolution);
|
|
1701
|
+
if (claim.scopeUnknown || directory === null) {
|
|
1702
|
+
resolution.problem = claim.scopeUnknown ?? "The command's directory leaves the repository.";
|
|
1703
|
+
continue;
|
|
1704
|
+
}
|
|
1705
|
+
let cursor = directory;
|
|
1706
|
+
while (true) {
|
|
1707
|
+
const manifest = path14.posix.join(cursor, "package.json");
|
|
1708
|
+
scope.candidates.push(manifest);
|
|
1709
|
+
const raw = await read(manifest);
|
|
1710
|
+
if (raw !== null) {
|
|
1711
|
+
resolution.manifest = manifest;
|
|
1712
|
+
const scripts = scriptsOf(raw);
|
|
1713
|
+
if (scripts === null) resolution.problem = "Invalid package manifest: " + manifest;
|
|
1714
|
+
else resolution.scripts = scripts;
|
|
1715
|
+
break;
|
|
1716
|
+
}
|
|
1717
|
+
if (claim.directory !== void 0 || cursor === ".") break;
|
|
1718
|
+
cursor = path14.posix.dirname(cursor);
|
|
1719
|
+
}
|
|
1720
|
+
if (!resolution.manifest && !resolution.problem) {
|
|
1721
|
+
resolution.problem = `No package.json for the command's scope (${directory}).`;
|
|
1722
|
+
}
|
|
1723
|
+
if (resolution.problem || resolution.scripts.includes(claim.scriptName) || claim.directory !== void 0) continue;
|
|
1724
|
+
inventory ??= await commandManifests(root);
|
|
1725
|
+
for (const manifest of [.../* @__PURE__ */ new Set(["package.json", ...inventory])].sort()) {
|
|
1726
|
+
if (scope.candidates.includes(manifest)) continue;
|
|
1727
|
+
scope.candidates.push(manifest);
|
|
1728
|
+
const raw = await read(manifest);
|
|
1729
|
+
if (raw === null) continue;
|
|
1730
|
+
const scripts = scriptsOf(raw);
|
|
1731
|
+
if (scripts === null) resolution.problem = "Cannot establish script availability: invalid manifest " + manifest;
|
|
1732
|
+
else if (scripts.includes(claim.scriptName)) resolution.elsewhere.push(manifest);
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
return { manifests: [...contents].sort(([a], [b]) => a.localeCompare(b)), resolutions };
|
|
1736
|
+
}
|
|
1487
1737
|
async function checkDeadCommands(ctx) {
|
|
1488
1738
|
const result = emptyResult();
|
|
1489
|
-
const
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
if (rootScripts === null) {
|
|
1495
|
-
result.skipped.push({
|
|
1496
|
-
check: "dead-command",
|
|
1497
|
-
reason: "no package.json at the repo root"
|
|
1498
|
-
});
|
|
1499
|
-
return result;
|
|
1500
|
-
}
|
|
1501
|
-
const rootSet = new Set(rootScripts);
|
|
1502
|
-
let workspaceScripts = null;
|
|
1503
|
-
let manifestsChecked = ["package.json"];
|
|
1504
|
-
const loadWorkspaceScripts = async () => {
|
|
1505
|
-
if (workspaceScripts !== null) return workspaceScripts;
|
|
1506
|
-
workspaceScripts = /* @__PURE__ */ new Set();
|
|
1507
|
-
const manifests = await commandManifests(ctx.root);
|
|
1508
|
-
manifestsChecked = ["package.json", ...manifests.sort()];
|
|
1509
|
-
for (const manifest of manifests) {
|
|
1510
|
-
const scripts = await scriptsOf(ctx.root, manifest);
|
|
1511
|
-
for (const name of scripts ?? []) workspaceScripts.add(name);
|
|
1739
|
+
const { resolutions } = await commandInputs(ctx.root, ctx.docs);
|
|
1740
|
+
for (const { doc, claim, scope, scripts, elsewhere, problem, manifest } of resolutions) {
|
|
1741
|
+
if (problem) {
|
|
1742
|
+
result.skipped.push({ check: "dead-command", doc, reason: problem });
|
|
1743
|
+
continue;
|
|
1512
1744
|
}
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
invocation: claim.invocation,
|
|
1528
|
-
manifestsChecked,
|
|
1529
|
-
availableScripts: rootScripts.slice(0, AVAILABLE_SCRIPTS_CAP)
|
|
1530
|
-
}
|
|
1531
|
-
});
|
|
1745
|
+
if (scripts.includes(claim.scriptName)) continue;
|
|
1746
|
+
const evidence = {
|
|
1747
|
+
kind: "missing-script",
|
|
1748
|
+
scriptName: claim.scriptName,
|
|
1749
|
+
invocation: claim.invocation,
|
|
1750
|
+
manifestsChecked: scope.candidates,
|
|
1751
|
+
availableScripts: scripts.slice(0, AVAILABLE_SCRIPTS_CAP),
|
|
1752
|
+
scope
|
|
1753
|
+
};
|
|
1754
|
+
const anchor = { doc, line: claim.line, excerpt: claim.excerpt };
|
|
1755
|
+
const message2 = `\`${claim.invocation}\` names script "${claim.scriptName}", which is absent from ${manifest}`;
|
|
1756
|
+
const certain = documentScope(doc) === "." && (scope.basis === "explicit" || !elsewhere.length);
|
|
1757
|
+
if (certain) result.issues.push({ type: "dead-command", message: message2, anchor, confidence: "certain", evidence });
|
|
1758
|
+
else result.advisories.push({ resolution: "recheck", type: "dead-command", message: message2 + (elsewhere.length ? `; it exists in ${elsewhere.join(", ")}. Clarify the intended working directory.` : "; the intended working directory needs review."), anchor, evidence });
|
|
1532
1759
|
}
|
|
1533
1760
|
return result;
|
|
1534
1761
|
}
|
|
@@ -1543,6 +1770,8 @@ var init_dead_command = __esm({
|
|
|
1543
1770
|
"src/audit/checks/dead-command.ts"() {
|
|
1544
1771
|
"use strict";
|
|
1545
1772
|
init_inputs();
|
|
1773
|
+
init_docs();
|
|
1774
|
+
init_scope();
|
|
1546
1775
|
init_checks();
|
|
1547
1776
|
AVAILABLE_SCRIPTS_CAP = 30;
|
|
1548
1777
|
}
|
|
@@ -1556,13 +1785,13 @@ async function git(root, args) {
|
|
|
1556
1785
|
}
|
|
1557
1786
|
function withoutAndroidReleaseValues(text2) {
|
|
1558
1787
|
if (/\/\*|"""|'''/.test(text2) || !/id\s*\(?\s*["']com\.android\.(application|library)["']/.test(text2)) return null;
|
|
1559
|
-
const
|
|
1788
|
+
const scopes2 = [];
|
|
1560
1789
|
const normalized = [];
|
|
1561
1790
|
let assignments = 0;
|
|
1562
1791
|
for (const line of text2.split("\n")) {
|
|
1563
1792
|
const code = line.replace(/"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\/\/.*$/g, (token) => token.startsWith("//") ? "" : '""');
|
|
1564
1793
|
const assignment = line.match(/^(\s*)(versionName|versionCode)(\s*(?:=\s*|\s+))("[A-Za-z0-9._+-]+"|'[A-Za-z0-9._+-]+'|\d+)(\s*)$/);
|
|
1565
|
-
if (assignment &&
|
|
1794
|
+
if (assignment && scopes2.join("/") === "android/defaultConfig" && (assignment[2] === "versionCode" ? /^\d+$/.test(assignment[4]) : /^["']/.test(assignment[4]))) {
|
|
1566
1795
|
normalized.push(assignment[1] + assignment[2] + assignment[3] + "<release-value>" + assignment[5]);
|
|
1567
1796
|
assignments++;
|
|
1568
1797
|
} else {
|
|
@@ -1571,12 +1800,12 @@ function withoutAndroidReleaseValues(text2) {
|
|
|
1571
1800
|
}
|
|
1572
1801
|
const named = code.match(/^\s*(android|defaultConfig)\s*\{\s*$/)?.[1];
|
|
1573
1802
|
for (const brace of code.matchAll(/[{}]/g)) {
|
|
1574
|
-
if (brace[0] === "{")
|
|
1575
|
-
else if (!
|
|
1576
|
-
else
|
|
1803
|
+
if (brace[0] === "{") scopes2.push(named ?? "unknown");
|
|
1804
|
+
else if (!scopes2.length) return null;
|
|
1805
|
+
else scopes2.pop();
|
|
1577
1806
|
}
|
|
1578
1807
|
}
|
|
1579
|
-
return assignments && !
|
|
1808
|
+
return assignments && !scopes2.length ? normalized.join("\n") : null;
|
|
1580
1809
|
}
|
|
1581
1810
|
async function releaseMetadataOnly(root, commit) {
|
|
1582
1811
|
if (!commit.files.length || !commit.files.every((file) => /(^|\/)build\.gradle(?:\.kts)?$/.test(file))) return false;
|
|
@@ -1607,6 +1836,12 @@ var init_release_metadata = __esm({
|
|
|
1607
1836
|
});
|
|
1608
1837
|
|
|
1609
1838
|
// src/audit/checks/deps-changed.ts
|
|
1839
|
+
function manifestPathspecs(doc) {
|
|
1840
|
+
const scope = documentScope(doc);
|
|
1841
|
+
if (scope === ".") return MANIFEST_PATHSPECS;
|
|
1842
|
+
const escaped = scope.replace(/[\\*?\[\]]/g, "\\$&");
|
|
1843
|
+
return MANIFEST_PATHSPECS.map((spec) => spec.startsWith(":(glob)") ? ":(glob)" + escaped + "/" + spec.slice(":(glob)".length) : ":(literal)" + scope + "/" + spec);
|
|
1844
|
+
}
|
|
1610
1845
|
async function checkDepsChanged(ctx) {
|
|
1611
1846
|
const result = emptyResult();
|
|
1612
1847
|
result.suppressedAdvisories = [];
|
|
@@ -1630,7 +1865,7 @@ async function checkDepsChanged(ctx) {
|
|
|
1630
1865
|
const range = await commitsTouchingSince(
|
|
1631
1866
|
ctx.root,
|
|
1632
1867
|
doc.lastCommit.hash,
|
|
1633
|
-
|
|
1868
|
+
manifestPathspecs(doc.path)
|
|
1634
1869
|
);
|
|
1635
1870
|
if (range === null) {
|
|
1636
1871
|
result.skipped.push({
|
|
@@ -1669,6 +1904,7 @@ var MANIFEST_COMMITS_CAP, MANIFEST_PATHSPECS;
|
|
|
1669
1904
|
var init_deps_changed = __esm({
|
|
1670
1905
|
"src/audit/checks/deps-changed.ts"() {
|
|
1671
1906
|
"use strict";
|
|
1907
|
+
init_docs();
|
|
1672
1908
|
init_release_metadata();
|
|
1673
1909
|
init_git();
|
|
1674
1910
|
init_checks();
|
|
@@ -1691,7 +1927,7 @@ var init_deps_changed = __esm({
|
|
|
1691
1927
|
});
|
|
1692
1928
|
|
|
1693
1929
|
// src/context/lexical.ts
|
|
1694
|
-
import
|
|
1930
|
+
import path15 from "path";
|
|
1695
1931
|
var init_lexical = __esm({
|
|
1696
1932
|
"src/context/lexical.ts"() {
|
|
1697
1933
|
"use strict";
|
|
@@ -1875,7 +2111,7 @@ var init_provenance = __esm({
|
|
|
1875
2111
|
|
|
1876
2112
|
// src/decisions/decisions.ts
|
|
1877
2113
|
import fs9 from "fs/promises";
|
|
1878
|
-
import
|
|
2114
|
+
import path16 from "path";
|
|
1879
2115
|
import { createHash } from "crypto";
|
|
1880
2116
|
import { z as z4 } from "zod";
|
|
1881
2117
|
async function loadDecisionStore(rootDir) {
|
|
@@ -1926,9 +2162,9 @@ var init_decisions = __esm({
|
|
|
1926
2162
|
});
|
|
1927
2163
|
|
|
1928
2164
|
// src/decisions/drift.ts
|
|
1929
|
-
import
|
|
2165
|
+
import path17 from "path";
|
|
1930
2166
|
async function computeDecisionDrift(rootDir, decisions) {
|
|
1931
|
-
const resolvedRoot =
|
|
2167
|
+
const resolvedRoot = path17.resolve(rootDir);
|
|
1932
2168
|
const store = decisions ? { records: decisions, diagnostics: [] } : await loadDecisionStore(resolvedRoot);
|
|
1933
2169
|
const report = { historyAvailable: true, totalDecisions: store.records.length, staleDecisions: {}, freshness: {}, diagnostics: store.diagnostics };
|
|
1934
2170
|
const [head, workingTree] = await Promise.all([getCurrentGitHash(resolvedRoot), getWorkingTree(resolvedRoot)]);
|
|
@@ -2019,36 +2255,328 @@ var init_decision_anchor = __esm({
|
|
|
2019
2255
|
}
|
|
2020
2256
|
});
|
|
2021
2257
|
|
|
2022
|
-
// src/audit/checks/index.ts
|
|
2023
|
-
function emptyResult() {
|
|
2024
|
-
return { issues: [], advisories: [], skipped: [] };
|
|
2258
|
+
// src/audit/checks/index.ts
|
|
2259
|
+
function emptyResult() {
|
|
2260
|
+
return { issues: [], advisories: [], skipped: [] };
|
|
2261
|
+
}
|
|
2262
|
+
var CHECKS;
|
|
2263
|
+
var init_checks = __esm({
|
|
2264
|
+
"src/audit/checks/index.ts"() {
|
|
2265
|
+
"use strict";
|
|
2266
|
+
init_deleted_reference();
|
|
2267
|
+
init_new_module();
|
|
2268
|
+
init_stale_count();
|
|
2269
|
+
init_dead_command();
|
|
2270
|
+
init_deps_changed();
|
|
2271
|
+
init_decision_anchor();
|
|
2272
|
+
CHECKS = {
|
|
2273
|
+
"deleted-reference": checkDeletedReferences,
|
|
2274
|
+
"new-module": checkNewModules,
|
|
2275
|
+
"stale-count": checkStaleCounts,
|
|
2276
|
+
"dead-command": checkDeadCommands,
|
|
2277
|
+
"deps-changed": checkDepsChanged,
|
|
2278
|
+
"decision-anchor-drift": checkDecisionAnchors
|
|
2279
|
+
};
|
|
2280
|
+
}
|
|
2281
|
+
});
|
|
2282
|
+
|
|
2283
|
+
// src/audit/findings.ts
|
|
2284
|
+
import { createHash as createHash2 } from "crypto";
|
|
2285
|
+
import { z as z5 } from "zod";
|
|
2286
|
+
function findingId(finding) {
|
|
2287
|
+
const e = finding.evidence;
|
|
2288
|
+
let key;
|
|
2289
|
+
switch (e.kind) {
|
|
2290
|
+
case "missing-path":
|
|
2291
|
+
key = e.resolvedPath && e.resolvedPath !== e.claimed ? [e.claimed, e.resolvedPath] : e.claimed;
|
|
2292
|
+
break;
|
|
2293
|
+
case "unmentioned-dir":
|
|
2294
|
+
key = e.dir;
|
|
2295
|
+
break;
|
|
2296
|
+
case "count-mismatch":
|
|
2297
|
+
key = [e.unit.replace(/s$/, ""), e.countedFrom];
|
|
2298
|
+
break;
|
|
2299
|
+
case "missing-script":
|
|
2300
|
+
key = e.scope && e.scope.directory !== "." ? [e.scriptName, e.scope.directory] : e.scriptName;
|
|
2301
|
+
break;
|
|
2302
|
+
case "doc-behind-manifests":
|
|
2303
|
+
key = null;
|
|
2304
|
+
break;
|
|
2305
|
+
case "decision-anchor":
|
|
2306
|
+
key = [e.decisionId, e.provenance?.revision, e.provenance?.approval];
|
|
2307
|
+
break;
|
|
2308
|
+
}
|
|
2309
|
+
return digest([finding.type, finding.anchor.doc, key]);
|
|
2310
|
+
}
|
|
2311
|
+
var digest, checkSchema, commitSchema, anchorSchema, count, scopeSchema, evidenceSchema, findingSchema, issueSchema, advisorySchema, checkResultSchema;
|
|
2312
|
+
var init_findings = __esm({
|
|
2313
|
+
"src/audit/findings.ts"() {
|
|
2314
|
+
"use strict";
|
|
2315
|
+
digest = (value) => createHash2("sha256").update(JSON.stringify(value)).digest("hex");
|
|
2316
|
+
checkSchema = z5.enum(["deleted-reference", "new-module", "stale-count", "dead-command", "deps-changed", "decision-anchor-drift"]);
|
|
2317
|
+
commitSchema = z5.object({ hash: z5.string().regex(/^[a-f0-9]{40,64}$/), date: z5.string(), subject: z5.string() });
|
|
2318
|
+
anchorSchema = z5.object({ doc: z5.string(), line: z5.number().int().positive().nullable(), excerpt: z5.string().nullable() });
|
|
2319
|
+
count = z5.number().int().nonnegative();
|
|
2320
|
+
scopeSchema = z5.object({
|
|
2321
|
+
basis: z5.enum(["repository", "document", "document-link", "explicit"]),
|
|
2322
|
+
directory: z5.string(),
|
|
2323
|
+
candidates: z5.array(z5.string())
|
|
2324
|
+
});
|
|
2325
|
+
evidenceSchema = z5.discriminatedUnion("kind", [
|
|
2326
|
+
z5.object({
|
|
2327
|
+
kind: z5.literal("missing-path"),
|
|
2328
|
+
claimed: z5.string(),
|
|
2329
|
+
renamedTo: z5.string().nullable(),
|
|
2330
|
+
deletedInCommit: commitSchema.nullable(),
|
|
2331
|
+
everTracked: z5.boolean(),
|
|
2332
|
+
parentDirExists: z5.boolean(),
|
|
2333
|
+
resolvedPath: z5.string().optional(),
|
|
2334
|
+
scope: scopeSchema.optional()
|
|
2335
|
+
}),
|
|
2336
|
+
z5.object({
|
|
2337
|
+
kind: z5.literal("unmentioned-dir"),
|
|
2338
|
+
dir: z5.string(),
|
|
2339
|
+
sourceFileCount: count,
|
|
2340
|
+
firstCommit: commitSchema.nullable(),
|
|
2341
|
+
checkedDocs: z5.array(z5.string())
|
|
2342
|
+
}),
|
|
2343
|
+
z5.object({
|
|
2344
|
+
kind: z5.literal("count-mismatch"),
|
|
2345
|
+
claimed: count,
|
|
2346
|
+
actual: count,
|
|
2347
|
+
unit: z5.string(),
|
|
2348
|
+
countedFrom: z5.string(),
|
|
2349
|
+
members: z5.array(z5.string())
|
|
2350
|
+
}),
|
|
2351
|
+
z5.object({
|
|
2352
|
+
kind: z5.literal("missing-script"),
|
|
2353
|
+
scriptName: z5.string(),
|
|
2354
|
+
invocation: z5.string(),
|
|
2355
|
+
manifestsChecked: z5.array(z5.string()),
|
|
2356
|
+
availableScripts: z5.array(z5.string()),
|
|
2357
|
+
scope: scopeSchema.optional()
|
|
2358
|
+
}),
|
|
2359
|
+
z5.object({
|
|
2360
|
+
kind: z5.literal("doc-behind-manifests"),
|
|
2361
|
+
docLastCommit: commitSchema,
|
|
2362
|
+
manifestCommits: z5.array(commitSchema.extend({ files: z5.array(z5.string()) })),
|
|
2363
|
+
totalCommits: count
|
|
2364
|
+
}),
|
|
2365
|
+
z5.object({
|
|
2366
|
+
kind: z5.literal("decision-anchor"),
|
|
2367
|
+
decisionId: z5.string(),
|
|
2368
|
+
title: z5.string(),
|
|
2369
|
+
changedFiles: z5.array(z5.string()),
|
|
2370
|
+
refreshedHash: z5.string(),
|
|
2371
|
+
provenance: z5.object({}).passthrough().optional()
|
|
2372
|
+
})
|
|
2373
|
+
]);
|
|
2374
|
+
findingSchema = z5.object({ message: z5.string(), anchor: anchorSchema, evidence: evidenceSchema });
|
|
2375
|
+
issueSchema = findingSchema.extend({
|
|
2376
|
+
type: z5.enum(["deleted-reference", "new-module", "stale-count", "dead-command"]),
|
|
2377
|
+
confidence: z5.enum(["certain", "likely"])
|
|
2378
|
+
});
|
|
2379
|
+
advisorySchema = findingSchema.extend({ type: checkSchema, resolution: z5.literal("recheck").optional() });
|
|
2380
|
+
checkResultSchema = z5.object({
|
|
2381
|
+
issues: z5.array(issueSchema),
|
|
2382
|
+
advisories: z5.array(advisorySchema),
|
|
2383
|
+
suppressedAdvisories: z5.array(advisorySchema).optional(),
|
|
2384
|
+
skipped: z5.array(z5.object({ check: z5.string(), reason: z5.string(), doc: z5.string().optional() }))
|
|
2385
|
+
});
|
|
2386
|
+
}
|
|
2387
|
+
});
|
|
2388
|
+
|
|
2389
|
+
// src/audit/advisory-review.ts
|
|
2390
|
+
import fs10 from "fs/promises";
|
|
2391
|
+
import { execFile as execFile8 } from "child_process";
|
|
2392
|
+
import { promisify as promisify8 } from "util";
|
|
2393
|
+
import { z as z6 } from "zod";
|
|
2394
|
+
async function readRecord(root, id) {
|
|
2395
|
+
const raw = await readStoreJson(root, recordPath(id));
|
|
2396
|
+
if (raw === null) return null;
|
|
2397
|
+
const record = recordSchema.parse(raw);
|
|
2398
|
+
const { digest: stored, ...payload } = record;
|
|
2399
|
+
if (record.id !== id || digest(payload) !== stored || record.events.some((event) => findingId(event.finding) !== id || event.evidence.fingerprint !== digest([event.evidence.scope, event.evidence.tree, event.evidence.lastScopeCommit, event.evidence.paths]))) {
|
|
2400
|
+
throw new Error("Advisory review record is inconsistent or modified; inspect its history.");
|
|
2401
|
+
}
|
|
2402
|
+
return record;
|
|
2025
2403
|
}
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
"
|
|
2404
|
+
function scopes(finding) {
|
|
2405
|
+
const files = [finding.anchor.doc], e = finding.evidence;
|
|
2406
|
+
if (e.kind === "decision-anchor") throw new Error("Use review_decision for decision acceptance, reaffirmation or retirement.");
|
|
2407
|
+
if (e.kind === "doc-behind-manifests") return [`:(literal)${finding.anchor.doc}`, ...manifestPathspecs(finding.anchor.doc)];
|
|
2408
|
+
if (e.kind === "missing-path") files.push(...e.scope?.candidates ?? [e.resolvedPath ?? e.claimed]);
|
|
2409
|
+
else if (e.kind === "missing-script") files.push(...e.manifestsChecked, ...e.scope?.candidates ?? []);
|
|
2410
|
+
else if (e.kind === "unmentioned-dir") files.push(e.dir, ...e.checkedDocs);
|
|
2411
|
+
else throw new Error("This advisory has no supported review scope.");
|
|
2412
|
+
return [...new Set(files)].map((file) => {
|
|
2413
|
+
if (normalizeRepoPath(file) !== file) throw new Error("Advisory contains an invalid scoped path: " + file);
|
|
2414
|
+
return `:(literal)${file}`;
|
|
2415
|
+
}).sort();
|
|
2416
|
+
}
|
|
2417
|
+
async function reviewEvidence(root, finding) {
|
|
2418
|
+
if (normalizeRepoPath(finding.anchor.doc) !== finding.anchor.doc) throw new Error("Invalid advisory document path.");
|
|
2419
|
+
const scope = scopes(finding);
|
|
2420
|
+
const head = (await git2(root, "rev-parse", "HEAD")).trim();
|
|
2421
|
+
const tracked = (await git2(root, "ls-files", "--cached", "-z", "--", ...scope)).split("\0").filter(Boolean);
|
|
2422
|
+
if (tracked.length > 2e4) throw new Error("Advisory scope exceeds 20,000 tracked files.");
|
|
2423
|
+
const [tree, status, lastScopeCommit, document] = await Promise.all([
|
|
2424
|
+
tracked.length ? git2(root, "ls-tree", "-r", "-z", "HEAD", "--", ...tracked.map((file) => `:(literal)${file}`)) : "",
|
|
2425
|
+
git2(root, "status", "--porcelain=v1", "-z", "--untracked-files=all", "--", ...scope),
|
|
2426
|
+
git2(root, "log", "-1", "--format=%H", "HEAD", "--", ...scope).then((value) => value.trim()),
|
|
2427
|
+
readAuditInput(root, finding.anchor.doc)
|
|
2428
|
+
]);
|
|
2429
|
+
if (!document?.trim()) throw new Error("Original advisory document is missing, empty or unreadable.");
|
|
2430
|
+
if (tree.length > 2 * 1024 * 1024 || tree.split("\0").length > 2e4) throw new Error("Advisory scope is too large for a complete review; narrow the documentation scope.");
|
|
2431
|
+
for (const entry of tree.split("\0").filter(Boolean)) {
|
|
2432
|
+
const tab = entry.indexOf(" "), file = entry.slice(tab + 1);
|
|
2433
|
+
if (entry.startsWith("120000 ") || entry.startsWith("160000 ")) throw new Error("Symlink or submodule in advisory review scope: " + file);
|
|
2434
|
+
await storePath(root, file);
|
|
2435
|
+
}
|
|
2436
|
+
const paths = finding.evidence.kind === "missing-path" ? await Promise.all(
|
|
2437
|
+
(finding.evidence.scope?.candidates ?? [finding.evidence.resolvedPath ?? finding.evidence.claimed]).map(async (file) => ({ path: file, exists: await pathExists(root, file) }))
|
|
2438
|
+
) : [];
|
|
2439
|
+
let dirty = status.length > 0;
|
|
2440
|
+
if (finding.evidence.kind === "missing-script") {
|
|
2441
|
+
for (const file of [...finding.evidence.manifestsChecked, ...finding.evidence.scope?.candidates ?? []]) {
|
|
2442
|
+
if (!tracked.includes(file) && await pathExists(root, file)) dirty = true;
|
|
2443
|
+
}
|
|
2444
|
+
}
|
|
2445
|
+
const fingerprint = digest([scope, tree, lastScopeCommit, paths]);
|
|
2446
|
+
if ((await git2(root, "rev-parse", "HEAD")).trim() !== head) throw new Error("HEAD changed while collecting review evidence.");
|
|
2447
|
+
return {
|
|
2448
|
+
...evidenceSchema2.parse({ head, scope, tree, lastScopeCommit, paths, fingerprint }),
|
|
2449
|
+
dirty,
|
|
2450
|
+
documentDigest: digest(document)
|
|
2451
|
+
};
|
|
2452
|
+
}
|
|
2453
|
+
async function decisionAssessment(root, finding, baselineHead) {
|
|
2454
|
+
const evidence = finding.evidence;
|
|
2455
|
+
if (evidence.kind !== "decision-anchor") return null;
|
|
2456
|
+
const id = findingId(finding);
|
|
2457
|
+
const store = await loadDecisionStore(root);
|
|
2458
|
+
if (store.diagnostics.length) throw new Error("Decision records have unavailable or malformed evidence; review cannot be confirmed.");
|
|
2459
|
+
const record = store.records.find((record2) => record2.id === evidence.decisionId);
|
|
2460
|
+
if (!record || record.version !== 2) return null;
|
|
2461
|
+
const events2 = record.history.filter((event2) => ["accepted", "reaffirmed", "retired"].includes(event2.kind));
|
|
2462
|
+
const event = events2.at(-1);
|
|
2463
|
+
if (!event?.evidence || !event.actor || !event.note || !event.evidence.historyAvailable || event.evidence.localChanges.length) return null;
|
|
2464
|
+
try {
|
|
2465
|
+
await git2(root, "merge-base", "--is-ancestor", baselineHead, event.evidence.headHash);
|
|
2466
|
+
} catch {
|
|
2467
|
+
return null;
|
|
2468
|
+
}
|
|
2469
|
+
const drift = await computeDecisionDrift(root, [record]);
|
|
2470
|
+
if (!drift.historyAvailable) throw new Error("Decision review history is unavailable.");
|
|
2471
|
+
const retired = record.status === "retired" && event.kind === "retired";
|
|
2472
|
+
const current = retired || record.status === "active" && record.approval === "accepted" && drift.freshness?.[record.id] === "current" && !drift.pendingProposals?.[record.id];
|
|
2473
|
+
return {
|
|
2474
|
+
id,
|
|
2475
|
+
status: current ? "current" : "reopened",
|
|
2476
|
+
outcome: event.kind,
|
|
2477
|
+
reviewer: event.actor,
|
|
2478
|
+
note: event.note,
|
|
2479
|
+
reviewedHead: event.evidence.headHash,
|
|
2480
|
+
recordPath: `.mason/decisions/${record.id}.json`,
|
|
2481
|
+
reason: current ? "The existing decision review records acceptance, reaffirmation or retirement covering the original finding." : "Decision content or anchor evidence changed after its review; review the decision again."
|
|
2482
|
+
};
|
|
2483
|
+
}
|
|
2484
|
+
async function assessAdvisory(root, finding, baselineHead) {
|
|
2485
|
+
if ("confidence" in finding) return null;
|
|
2486
|
+
const id = findingId(finding);
|
|
2487
|
+
try {
|
|
2488
|
+
if (finding.evidence.kind === "decision-anchor") return await decisionAssessment(root, finding, baselineHead);
|
|
2489
|
+
const record = await readRecord(root, id);
|
|
2490
|
+
if (!record) return null;
|
|
2491
|
+
const event = record.events.at(-1);
|
|
2492
|
+
const current = await reviewEvidence(root, event.finding);
|
|
2493
|
+
await git2(root, "merge-base", "--is-ancestor", event.evidence.head, current.head);
|
|
2494
|
+
const base = {
|
|
2495
|
+
id,
|
|
2496
|
+
recordPath: recordPath(id),
|
|
2497
|
+
reviewer: event.reviewer,
|
|
2498
|
+
note: event.note,
|
|
2499
|
+
outcome: event.outcome,
|
|
2500
|
+
reviewedHead: event.evidence.head
|
|
2501
|
+
};
|
|
2502
|
+
if (current.dirty || current.fingerprint !== event.evidence.fingerprint || digest(scopes(finding)) !== digest(event.evidence.scope)) return { ...base, status: "reopened", reason: "Relevant document or repository evidence changed after the assessment; prepare a new review." };
|
|
2503
|
+
return { ...base, status: event.outcome === "deferred" ? "deferred" : "current", reason: event.outcome === "deferred" ? "The review was deferred and remains outstanding." : "An explicit assessment covers the current committed scope. This does not approve an engineering decision or certify correctness." };
|
|
2504
|
+
} catch (error) {
|
|
2505
|
+
return { id, status: "unverified", reason: error instanceof Error ? error.message : String(error) };
|
|
2506
|
+
}
|
|
2507
|
+
}
|
|
2508
|
+
async function advisoryReviewInventory(root) {
|
|
2509
|
+
let names;
|
|
2510
|
+
try {
|
|
2511
|
+
names = await fs10.readdir(await storePath(root, ".mason/reviews/advisories"));
|
|
2512
|
+
} catch (error) {
|
|
2513
|
+
if (error.code === "ENOENT") return [];
|
|
2514
|
+
throw error;
|
|
2515
|
+
}
|
|
2516
|
+
if (names.length > 5e3) throw new Error("Advisory review inventory exceeds 5,000 records.");
|
|
2517
|
+
return Promise.all(names.filter((name) => name.endsWith(".json")).sort().map(async (name) => [name, await readAuditInput(root, ".mason/reviews/advisories/" + name)]));
|
|
2518
|
+
}
|
|
2519
|
+
var execute2, git2, hashSchema, commitSchema2, evidenceSchema2, eventSchema2, recordSchema, reviewSummarySchema, advisoryReviewRequest, recordPath;
|
|
2520
|
+
var init_advisory_review = __esm({
|
|
2521
|
+
"src/audit/advisory-review.ts"() {
|
|
2029
2522
|
"use strict";
|
|
2030
|
-
|
|
2031
|
-
init_new_module();
|
|
2032
|
-
init_stale_count();
|
|
2033
|
-
init_dead_command();
|
|
2523
|
+
init_findings();
|
|
2034
2524
|
init_deps_changed();
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
};
|
|
2525
|
+
init_inputs();
|
|
2526
|
+
init_scope();
|
|
2527
|
+
init_storage();
|
|
2528
|
+
init_paths();
|
|
2529
|
+
init_store();
|
|
2530
|
+
init_decisions();
|
|
2531
|
+
init_drift2();
|
|
2532
|
+
execute2 = promisify8(execFile8);
|
|
2533
|
+
git2 = async (root, ...args) => (await execute2("git", args, { cwd: root, timeout: 1e4, maxBuffer: 8 * 1024 * 1024 })).stdout;
|
|
2534
|
+
hashSchema = z6.string().regex(/^[a-f0-9]{64}$/);
|
|
2535
|
+
commitSchema2 = z6.string().regex(/^[a-f0-9]{40,64}$/);
|
|
2536
|
+
evidenceSchema2 = z6.object({
|
|
2537
|
+
head: commitSchema2,
|
|
2538
|
+
fingerprint: hashSchema,
|
|
2539
|
+
scope: z6.array(z6.string()).min(1).max(1e3),
|
|
2540
|
+
tree: z6.string().max(2 * 1024 * 1024),
|
|
2541
|
+
lastScopeCommit: commitSchema2,
|
|
2542
|
+
paths: z6.array(z6.object({ path: z6.string(), exists: z6.boolean() })).max(1e3)
|
|
2543
|
+
});
|
|
2544
|
+
eventSchema2 = z6.object({
|
|
2545
|
+
at: z6.string().datetime(),
|
|
2546
|
+
reviewer: z6.string().trim().min(1).max(200),
|
|
2547
|
+
note: z6.string().trim().min(1).max(2500),
|
|
2548
|
+
outcome: z6.enum(["addressed", "inapplicable", "deferred"]),
|
|
2549
|
+
finding: advisorySchema.refine((finding) => finding.evidence.kind !== "decision-anchor", "Decision findings use decision reviews"),
|
|
2550
|
+
evidence: evidenceSchema2
|
|
2551
|
+
});
|
|
2552
|
+
recordSchema = z6.object({ version: z6.literal(1), id: hashSchema, events: z6.array(eventSchema2).min(1).max(200), digest: hashSchema });
|
|
2553
|
+
reviewSummarySchema = z6.object({
|
|
2554
|
+
id: hashSchema,
|
|
2555
|
+
status: z6.enum(["current", "reopened", "deferred", "unverified"]),
|
|
2556
|
+
reason: z6.string(),
|
|
2557
|
+
recordPath: z6.string().optional(),
|
|
2558
|
+
reviewer: z6.string().optional(),
|
|
2559
|
+
note: z6.string().optional(),
|
|
2560
|
+
outcome: z6.enum(["addressed", "inapplicable", "deferred", "accepted", "reaffirmed", "retired"]).optional(),
|
|
2561
|
+
reviewedHead: z6.string().optional()
|
|
2562
|
+
});
|
|
2563
|
+
advisoryReviewRequest = z6.object({
|
|
2564
|
+
baselinePath: z6.string().min(1),
|
|
2565
|
+
findingId: hashSchema,
|
|
2566
|
+
action: z6.enum(["prepare", "addressed", "inapplicable", "deferred"]).default("prepare"),
|
|
2567
|
+
reviewer: eventSchema2.shape.reviewer.optional(),
|
|
2568
|
+
note: eventSchema2.shape.note.optional(),
|
|
2569
|
+
reviewToken: hashSchema.optional()
|
|
2570
|
+
});
|
|
2571
|
+
recordPath = (id) => `.mason/reviews/advisories/${hashSchema.parse(id)}.json`;
|
|
2044
2572
|
}
|
|
2045
2573
|
});
|
|
2046
2574
|
|
|
2047
2575
|
// src/audit/audit.ts
|
|
2048
|
-
import
|
|
2049
|
-
import
|
|
2576
|
+
import fs11 from "fs/promises";
|
|
2577
|
+
import path18 from "path";
|
|
2050
2578
|
async function computeAudit(rootDir, options = {}) {
|
|
2051
|
-
const resolvedRoot =
|
|
2579
|
+
const resolvedRoot = path18.resolve(rootDir);
|
|
2052
2580
|
const [docs, headHash] = await Promise.all([discoverDocs(resolvedRoot), getCurrentGitHash(resolvedRoot)]);
|
|
2053
2581
|
if (docs.length === 0) return null;
|
|
2054
2582
|
const report = {
|
|
@@ -2059,6 +2587,8 @@ async function computeAudit(rootDir, options = {}) {
|
|
|
2059
2587
|
checksRun: [],
|
|
2060
2588
|
docs: docs.map((d) => ({
|
|
2061
2589
|
path: d.path,
|
|
2590
|
+
scope: d.scope,
|
|
2591
|
+
kind: d.kind,
|
|
2062
2592
|
lastCommit: d.lastCommit,
|
|
2063
2593
|
dirty: d.dirty,
|
|
2064
2594
|
lineCount: d.lineCount
|
|
@@ -2080,7 +2610,7 @@ async function computeAudit(rootDir, options = {}) {
|
|
|
2080
2610
|
}
|
|
2081
2611
|
let decisionsPresent = false;
|
|
2082
2612
|
try {
|
|
2083
|
-
await
|
|
2613
|
+
await fs11.access(path18.join(resolvedRoot, ".mason", "decisions"));
|
|
2084
2614
|
decisionsPresent = true;
|
|
2085
2615
|
} catch {
|
|
2086
2616
|
}
|
|
@@ -2103,6 +2633,8 @@ async function computeAudit(rootDir, options = {}) {
|
|
|
2103
2633
|
report.skippedChecks.push(...skipped);
|
|
2104
2634
|
}
|
|
2105
2635
|
report.clean = report.issues.length === 0;
|
|
2636
|
+
const reviews = (await Promise.all([...report.advisories, ...report.suppressedAdvisories].map((finding) => assessAdvisory(resolvedRoot, finding, headHash)))).filter((review) => review !== null);
|
|
2637
|
+
if (reviews.length) report.advisoryReviews = reviews;
|
|
2106
2638
|
return report;
|
|
2107
2639
|
}
|
|
2108
2640
|
var init_audit = __esm({
|
|
@@ -2113,45 +2645,24 @@ var init_audit = __esm({
|
|
|
2113
2645
|
init_docs();
|
|
2114
2646
|
init_types();
|
|
2115
2647
|
init_checks();
|
|
2648
|
+
init_advisory_review();
|
|
2116
2649
|
}
|
|
2117
2650
|
});
|
|
2118
2651
|
|
|
2119
2652
|
// src/audit/repair.ts
|
|
2120
|
-
import
|
|
2121
|
-
import
|
|
2122
|
-
import {
|
|
2123
|
-
import { z as
|
|
2124
|
-
function
|
|
2125
|
-
|
|
2126
|
-
let key;
|
|
2127
|
-
switch (e.kind) {
|
|
2128
|
-
case "missing-path":
|
|
2129
|
-
key = e.claimed;
|
|
2130
|
-
break;
|
|
2131
|
-
case "unmentioned-dir":
|
|
2132
|
-
key = e.dir;
|
|
2133
|
-
break;
|
|
2134
|
-
case "count-mismatch":
|
|
2135
|
-
key = [e.unit.replace(/s$/, ""), e.countedFrom];
|
|
2136
|
-
break;
|
|
2137
|
-
case "missing-script":
|
|
2138
|
-
key = e.scriptName;
|
|
2139
|
-
break;
|
|
2140
|
-
case "doc-behind-manifests":
|
|
2141
|
-
key = null;
|
|
2142
|
-
break;
|
|
2143
|
-
case "decision-anchor":
|
|
2144
|
-
key = [e.decisionId, e.provenance?.revision, e.provenance?.approval];
|
|
2145
|
-
break;
|
|
2146
|
-
}
|
|
2147
|
-
return digest([finding.type, finding.anchor.doc, key]);
|
|
2653
|
+
import fs12 from "fs/promises";
|
|
2654
|
+
import path19 from "path";
|
|
2655
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
2656
|
+
import { z as z7 } from "zod";
|
|
2657
|
+
function recheckable(finding) {
|
|
2658
|
+
return !("confidence" in finding) && finding.resolution === "recheck" && ["deleted-reference", "dead-command", "new-module"].includes(finding.type) && ["missing-path", "missing-script", "unmentioned-dir"].includes(finding.evidence.kind);
|
|
2148
2659
|
}
|
|
2149
2660
|
function allFindings(report) {
|
|
2150
2661
|
return [...report.issues, ...report.advisories, ...report.suppressedAdvisories ?? []];
|
|
2151
2662
|
}
|
|
2152
2663
|
async function docState(root) {
|
|
2153
2664
|
const docs = [];
|
|
2154
|
-
for (const doc of
|
|
2665
|
+
for (const doc of await discoverDocPaths(root)) {
|
|
2155
2666
|
try {
|
|
2156
2667
|
const content2 = await readBoundedFile(await storePath(root, doc), 10 * 1024 * 1024);
|
|
2157
2668
|
if (content2 === null) throw new Error("Context file is not regular or exceeds 10 MiB: " + doc);
|
|
@@ -2173,8 +2684,8 @@ async function stableAudit(root, checks, options = {}) {
|
|
|
2173
2684
|
return report;
|
|
2174
2685
|
}
|
|
2175
2686
|
async function prepareRepair(rootDir, checks = ALL_CHECKS, options = {}) {
|
|
2176
|
-
const root = await
|
|
2177
|
-
const selected =
|
|
2687
|
+
const root = await fs12.realpath(rootDir);
|
|
2688
|
+
const selected = z7.array(checkSchema).nonempty().parse(checks);
|
|
2178
2689
|
const report = await stableAudit(root, selected, options);
|
|
2179
2690
|
if (!report) throw new Error("No context files found to prepare a repair.");
|
|
2180
2691
|
if (!report.gitAvailable) throw new Error("Readable Git history is required to prepare a repair.");
|
|
@@ -2189,23 +2700,29 @@ async function prepareRepair(rootDir, checks = ALL_CHECKS, options = {}) {
|
|
|
2189
2700
|
await writeStoreJson(root, baselinePath, { ...payload, digest: digest(payload) });
|
|
2190
2701
|
return { version: 1, action: "prepare", baselinePath, report };
|
|
2191
2702
|
}
|
|
2192
|
-
async function
|
|
2193
|
-
const root = await
|
|
2194
|
-
const declaredRoot =
|
|
2195
|
-
const relative =
|
|
2703
|
+
async function loadRepairBaseline(rootDir, baselinePath) {
|
|
2704
|
+
const root = await fs12.realpath(rootDir);
|
|
2705
|
+
const declaredRoot = path19.resolve(rootDir);
|
|
2706
|
+
const relative = path19.isAbsolute(baselinePath) ? path19.relative(isWithinRoot(declaredRoot, baselinePath) ? declaredRoot : root, baselinePath) : baselinePath;
|
|
2196
2707
|
const stored = baselineSchema.parse(await readStoreJson(root, relative));
|
|
2197
2708
|
const { digest: savedDigest, ...payload } = stored;
|
|
2198
2709
|
if (digest(payload) !== savedDigest) throw new Error("Repair baseline was modified; use the original baseline.");
|
|
2199
2710
|
if (stored.report.root !== root) throw new Error("Repair baseline belongs to a different repository.");
|
|
2200
2711
|
const original = stored.report;
|
|
2712
|
+
return { root, relative, original };
|
|
2713
|
+
}
|
|
2714
|
+
async function verifyRepair(rootDir, baselinePath, options = {}) {
|
|
2715
|
+
const { root, relative, original } = await loadRepairBaseline(rootDir, baselinePath);
|
|
2201
2716
|
const diagnostics = [];
|
|
2717
|
+
let reviewDigest;
|
|
2202
2718
|
let current = null;
|
|
2203
2719
|
try {
|
|
2720
|
+
reviewDigest = digest(await advisoryReviewInventory(root));
|
|
2204
2721
|
current = await stableAudit(root, original.checksRun, options);
|
|
2205
2722
|
if (!current) diagnostics.push("No context files remain available to audit.");
|
|
2206
2723
|
else if (!current.gitAvailable) diagnostics.push("Git history is unavailable.");
|
|
2207
2724
|
for (const doc of original.docs) {
|
|
2208
|
-
if (!original.
|
|
2725
|
+
if (!allFindings(original).some((f) => f.anchor.doc === doc.path) || !current?.docs.some((d) => d.path === doc.path)) continue;
|
|
2209
2726
|
const content2 = await readBoundedFile(await storePath(root, doc.path), 10 * 1024 * 1024);
|
|
2210
2727
|
if (content2 === null || !content2.trim()) {
|
|
2211
2728
|
diagnostics.push("Original context file " + doc.path + " is empty or unreadable; losing its claims does not verify a repair.");
|
|
@@ -2222,21 +2739,27 @@ async function verifyRepair(rootDir, baselinePath, options = {}) {
|
|
|
2222
2739
|
const originalIds = new Set(originalFindings.map(findingId));
|
|
2223
2740
|
const missingDocs = original.docs.filter((doc) => !current?.docs.some((d) => d.path === doc.path));
|
|
2224
2741
|
for (const doc of missingDocs) diagnostics.push("Original context file " + doc.path + " is unavailable; removing it does not verify a repair.");
|
|
2225
|
-
const findings = originalFindings.map((finding) => {
|
|
2742
|
+
const findings = await Promise.all(originalFindings.map(async (finding) => {
|
|
2226
2743
|
const id = findingId(finding);
|
|
2227
2744
|
const now = currentById.get(id);
|
|
2228
2745
|
const base = { id, original: finding, ...now ? { current: now } : {} };
|
|
2229
2746
|
if (diagnostics.length || !current) {
|
|
2230
2747
|
return { ...base, status: "unverified", reason: "The original audit scope could not be verified. See diagnostics." };
|
|
2231
2748
|
}
|
|
2232
|
-
if ("confidence" in finding
|
|
2749
|
+
if (now && ("confidence" in finding || "confidence" in now)) {
|
|
2233
2750
|
return { ...base, status: "unresolved", reason: "The original check still reports this claim." };
|
|
2234
2751
|
}
|
|
2235
2752
|
const skipped = current.skippedChecks.filter((s) => s.check === finding.type && (!s.doc || s.doc === finding.anchor.doc));
|
|
2236
2753
|
if (!current.checksRun?.includes(finding.type) || skipped.length) {
|
|
2237
2754
|
return { ...base, status: "unverified", reason: skipped.map((s) => s.reason).join("; ") || "The original check did not run." };
|
|
2238
2755
|
}
|
|
2239
|
-
|
|
2756
|
+
const review = await assessAdvisory(root, now ?? finding, original.headHash);
|
|
2757
|
+
if (review) {
|
|
2758
|
+
if (review.status === "unverified") return { ...base, review, status: "unverified", reason: review.reason };
|
|
2759
|
+
if (review.status === "current") return { ...base, review, status: "resolved", reason: review.reason };
|
|
2760
|
+
return { ...base, review, status: "review-required", reason: review.reason };
|
|
2761
|
+
}
|
|
2762
|
+
if (!("confidence" in finding) && (!recheckable(finding) || now)) {
|
|
2240
2763
|
return {
|
|
2241
2764
|
...base,
|
|
2242
2765
|
status: "review-required",
|
|
@@ -2244,11 +2767,27 @@ async function verifyRepair(rootDir, baselinePath, options = {}) {
|
|
|
2244
2767
|
};
|
|
2245
2768
|
}
|
|
2246
2769
|
return { ...base, status: "resolved", reason: "The original check ran and no longer reports this claim. Inspect the edit for semantic correctness." };
|
|
2247
|
-
});
|
|
2770
|
+
}));
|
|
2771
|
+
try {
|
|
2772
|
+
if (reviewDigest !== digest(await advisoryReviewInventory(root)) || current?.headHash !== await getCurrentGitHash(root)) {
|
|
2773
|
+
diagnostics.push("HEAD or advisory review records changed during verification; repeat against stable evidence.");
|
|
2774
|
+
for (const finding of findings) {
|
|
2775
|
+
finding.status = "unverified";
|
|
2776
|
+
finding.reason = diagnostics.at(-1);
|
|
2777
|
+
}
|
|
2778
|
+
}
|
|
2779
|
+
} catch (error) {
|
|
2780
|
+
diagnostics.push(String(error));
|
|
2781
|
+
for (const finding of findings) {
|
|
2782
|
+
finding.status = "unverified";
|
|
2783
|
+
finding.reason = "Advisory review evidence became unavailable during verification.";
|
|
2784
|
+
}
|
|
2785
|
+
}
|
|
2248
2786
|
const newFindings = [...currentById].filter(([id]) => !originalIds.has(id)).map(([, f]) => f);
|
|
2787
|
+
const reviewedIds = new Set(current?.advisoryReviews?.filter((review) => review.status === "current").map((review) => review.id));
|
|
2249
2788
|
const counts = { resolved: 0, unresolved: 0, "review-required": 0, unverified: 0 };
|
|
2250
2789
|
for (const f of findings) counts[f.status]++;
|
|
2251
|
-
const incomplete = diagnostics.length > 0 || counts.unverified > 0 || counts["review-required"] > 0 || (current?.skippedChecks.length ?? 0) > 0 || newFindings.some((f) => !("confidence" in f));
|
|
2790
|
+
const incomplete = diagnostics.length > 0 || counts.unverified > 0 || counts["review-required"] > 0 || (current?.skippedChecks.length ?? 0) > 0 || newFindings.some((f) => !("confidence" in f) && !reviewedIds.has(findingId(f)));
|
|
2252
2791
|
const issuesRemain = counts.unresolved > 0 || newFindings.some((f) => "confidence" in f);
|
|
2253
2792
|
return {
|
|
2254
2793
|
version: 1,
|
|
@@ -2262,10 +2801,10 @@ async function verifyRepair(rootDir, baselinePath, options = {}) {
|
|
|
2262
2801
|
diagnostics,
|
|
2263
2802
|
currentAudit: current,
|
|
2264
2803
|
counts,
|
|
2265
|
-
scope: "Original audit checks over current context files and repository evidence. Resolved means no longer detected by
|
|
2804
|
+
scope: "Original audit checks over current context files and repository evidence. Resolved means no longer detected by the check or covered by an explicit assessment of current evidence; inspect each finding's reason and review. This is not a certification of documentation or application correctness."
|
|
2266
2805
|
};
|
|
2267
2806
|
}
|
|
2268
|
-
var
|
|
2807
|
+
var count2, reportSchema, baselineSchema, repairFindingSchema;
|
|
2269
2808
|
var init_repair = __esm({
|
|
2270
2809
|
"src/audit/repair.ts"() {
|
|
2271
2810
|
"use strict";
|
|
@@ -2277,101 +2816,45 @@ var init_repair = __esm({
|
|
|
2277
2816
|
init_files();
|
|
2278
2817
|
init_paths();
|
|
2279
2818
|
init_types();
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
renamedTo: z5.string().nullable(),
|
|
2289
|
-
deletedInCommit: commitSchema.nullable(),
|
|
2290
|
-
everTracked: z5.boolean(),
|
|
2291
|
-
parentDirExists: z5.boolean()
|
|
2292
|
-
}),
|
|
2293
|
-
z5.object({
|
|
2294
|
-
kind: z5.literal("unmentioned-dir"),
|
|
2295
|
-
dir: z5.string(),
|
|
2296
|
-
sourceFileCount: count,
|
|
2297
|
-
firstCommit: commitSchema.nullable(),
|
|
2298
|
-
checkedDocs: z5.array(z5.string())
|
|
2299
|
-
}),
|
|
2300
|
-
z5.object({
|
|
2301
|
-
kind: z5.literal("count-mismatch"),
|
|
2302
|
-
claimed: count,
|
|
2303
|
-
actual: count,
|
|
2304
|
-
unit: z5.string(),
|
|
2305
|
-
countedFrom: z5.string(),
|
|
2306
|
-
members: z5.array(z5.string())
|
|
2307
|
-
}),
|
|
2308
|
-
z5.object({
|
|
2309
|
-
kind: z5.literal("missing-script"),
|
|
2310
|
-
scriptName: z5.string(),
|
|
2311
|
-
invocation: z5.string(),
|
|
2312
|
-
manifestsChecked: z5.array(z5.string()),
|
|
2313
|
-
availableScripts: z5.array(z5.string())
|
|
2314
|
-
}),
|
|
2315
|
-
z5.object({
|
|
2316
|
-
kind: z5.literal("doc-behind-manifests"),
|
|
2317
|
-
docLastCommit: commitSchema,
|
|
2318
|
-
manifestCommits: z5.array(commitSchema.extend({ files: z5.array(z5.string()) })),
|
|
2319
|
-
totalCommits: count
|
|
2320
|
-
}),
|
|
2321
|
-
z5.object({
|
|
2322
|
-
kind: z5.literal("decision-anchor"),
|
|
2323
|
-
decisionId: z5.string(),
|
|
2324
|
-
title: z5.string(),
|
|
2325
|
-
changedFiles: z5.array(z5.string()),
|
|
2326
|
-
refreshedHash: z5.string(),
|
|
2327
|
-
provenance: z5.object({}).passthrough().optional()
|
|
2328
|
-
})
|
|
2329
|
-
]);
|
|
2330
|
-
findingSchema = z5.object({ message: z5.string(), anchor: anchorSchema, evidence: evidenceSchema });
|
|
2331
|
-
issueSchema = findingSchema.extend({
|
|
2332
|
-
type: z5.enum(["deleted-reference", "new-module", "stale-count", "dead-command"]),
|
|
2333
|
-
confidence: z5.enum(["certain", "likely"])
|
|
2334
|
-
});
|
|
2335
|
-
advisorySchema = findingSchema.extend({ type: z5.enum(["deps-changed", "decision-anchor-drift"]) });
|
|
2336
|
-
checkResultSchema = z5.object({
|
|
2337
|
-
issues: z5.array(issueSchema),
|
|
2338
|
-
advisories: z5.array(advisorySchema),
|
|
2339
|
-
suppressedAdvisories: z5.array(advisorySchema).optional(),
|
|
2340
|
-
skipped: z5.array(z5.object({ check: z5.string(), reason: z5.string(), doc: z5.string().optional() }))
|
|
2341
|
-
});
|
|
2342
|
-
reportSchema = z5.object({
|
|
2343
|
-
version: z5.literal(1),
|
|
2344
|
-
root: z5.string(),
|
|
2345
|
-
gitAvailable: z5.literal(true),
|
|
2819
|
+
init_findings();
|
|
2820
|
+
init_advisory_review();
|
|
2821
|
+
init_findings();
|
|
2822
|
+
count2 = z7.number().int().nonnegative();
|
|
2823
|
+
reportSchema = z7.object({
|
|
2824
|
+
version: z7.literal(1),
|
|
2825
|
+
root: z7.string(),
|
|
2826
|
+
gitAvailable: z7.literal(true),
|
|
2346
2827
|
headHash: commitSchema.shape.hash,
|
|
2347
|
-
checksRun:
|
|
2348
|
-
docs:
|
|
2349
|
-
path:
|
|
2828
|
+
checksRun: z7.array(checkSchema).nonempty(),
|
|
2829
|
+
docs: z7.array(z7.object({
|
|
2830
|
+
path: z7.string().refine((value) => normalizeRepoPath(value) === value),
|
|
2831
|
+
scope: z7.string().optional(),
|
|
2832
|
+
kind: z7.enum(["instructions", "readme"]).optional(),
|
|
2350
2833
|
lastCommit: commitSchema.nullable(),
|
|
2351
|
-
dirty:
|
|
2352
|
-
lineCount:
|
|
2834
|
+
dirty: z7.boolean(),
|
|
2835
|
+
lineCount: count2
|
|
2353
2836
|
})).nonempty(),
|
|
2354
|
-
decisionsChecked:
|
|
2355
|
-
clean:
|
|
2356
|
-
issues:
|
|
2357
|
-
advisories:
|
|
2358
|
-
suppressedAdvisories:
|
|
2359
|
-
skippedChecks:
|
|
2837
|
+
decisionsChecked: z7.boolean(),
|
|
2838
|
+
clean: z7.boolean(),
|
|
2839
|
+
issues: z7.array(issueSchema),
|
|
2840
|
+
advisories: z7.array(advisorySchema),
|
|
2841
|
+
suppressedAdvisories: z7.array(advisorySchema).optional(),
|
|
2842
|
+
skippedChecks: z7.array(z7.object({ check: z7.string(), reason: z7.string(), doc: z7.string().optional() }))
|
|
2360
2843
|
});
|
|
2361
|
-
baselineSchema =
|
|
2362
|
-
kind:
|
|
2363
|
-
version:
|
|
2364
|
-
createdAt:
|
|
2844
|
+
baselineSchema = z7.object({
|
|
2845
|
+
kind: z7.literal("mason-audit-repair"),
|
|
2846
|
+
version: z7.literal(1),
|
|
2847
|
+
createdAt: z7.string().datetime(),
|
|
2365
2848
|
report: reportSchema,
|
|
2366
|
-
digest:
|
|
2849
|
+
digest: z7.string().regex(/^[a-f0-9]{64}$/)
|
|
2367
2850
|
});
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2851
|
+
repairFindingSchema = z7.object({
|
|
2852
|
+
id: z7.string(),
|
|
2853
|
+
original: z7.union([issueSchema, advisorySchema]),
|
|
2854
|
+
status: z7.enum(["resolved", "unresolved", "review-required", "unverified"]),
|
|
2855
|
+
reason: z7.string(),
|
|
2856
|
+
current: z7.union([issueSchema, advisorySchema]).optional(),
|
|
2857
|
+
review: reviewSummarySchema.optional()
|
|
2375
2858
|
});
|
|
2376
2859
|
}
|
|
2377
2860
|
});
|
|
@@ -2380,102 +2863,94 @@ var init_repair = __esm({
|
|
|
2380
2863
|
var evidence_exports = {};
|
|
2381
2864
|
__export(evidence_exports, {
|
|
2382
2865
|
checkCache: () => checkCache,
|
|
2383
|
-
git: () =>
|
|
2866
|
+
git: () => git3,
|
|
2384
2867
|
hash: () => hash,
|
|
2385
2868
|
readInputs: () => readInputs,
|
|
2386
2869
|
workspace: () => workspace
|
|
2387
2870
|
});
|
|
2388
|
-
import
|
|
2389
|
-
import
|
|
2871
|
+
import fs13 from "fs/promises";
|
|
2872
|
+
import path20 from "path";
|
|
2390
2873
|
import { createHash as createHash3 } from "crypto";
|
|
2391
|
-
import { execFile as
|
|
2392
|
-
import { promisify as
|
|
2393
|
-
import
|
|
2394
|
-
import { z as
|
|
2395
|
-
async function
|
|
2874
|
+
import { execFile as execFile9 } from "child_process";
|
|
2875
|
+
import { promisify as promisify9 } from "util";
|
|
2876
|
+
import fg5 from "fast-glob";
|
|
2877
|
+
import { z as z8 } from "zod";
|
|
2878
|
+
async function git3(root, ...args) {
|
|
2396
2879
|
return (await exec7("git", args, { cwd: root, maxBuffer: 16 * 1024 * 1024, timeout: 1e4 })).stdout;
|
|
2397
2880
|
}
|
|
2398
2881
|
async function workspace(dir) {
|
|
2399
|
-
const root = await
|
|
2400
|
-
const gitDir = await
|
|
2882
|
+
const root = await fs13.realpath((await git3(dir, "rev-parse", "--show-toplevel")).trim());
|
|
2883
|
+
const gitDir = await fs13.realpath((await git3(root, "rev-parse", "--absolute-git-dir")).trim());
|
|
2401
2884
|
let branch;
|
|
2402
2885
|
try {
|
|
2403
|
-
branch = (await
|
|
2886
|
+
branch = (await git3(root, "symbolic-ref", "--quiet", "HEAD")).trim();
|
|
2404
2887
|
} catch {
|
|
2405
2888
|
branch = "detached";
|
|
2406
2889
|
}
|
|
2407
2890
|
return { root, gitDir, branch, directory: ".mason/reports/automation/" + hash([root, gitDir, branch]).slice(0, 24) };
|
|
2408
2891
|
}
|
|
2409
2892
|
async function readInputs(root) {
|
|
2893
|
+
const docPaths = await discoverDocPaths(root);
|
|
2410
2894
|
const [headText, docStatus, shallowPath, replacements] = await Promise.all([
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2895
|
+
git3(root, "rev-parse", "HEAD"),
|
|
2896
|
+
docPaths.length ? git3(root, "status", "--porcelain=v1", "-z", "--untracked-files=all", "--", ...docPaths.map((p) => `:(literal)${p}`)) : "",
|
|
2897
|
+
git3(root, "rev-parse", "--git-path", "shallow"),
|
|
2898
|
+
git3(root, "for-each-ref", "--format=%(refname) %(objectname)", "refs/replace")
|
|
2415
2899
|
]);
|
|
2416
2900
|
const head = headText.trim();
|
|
2417
2901
|
let shallow = null;
|
|
2418
2902
|
try {
|
|
2419
|
-
shallow = await
|
|
2903
|
+
shallow = await fs13.readFile(path20.resolve(root, shallowPath.trim()), "utf8");
|
|
2420
2904
|
} catch (error) {
|
|
2421
2905
|
if (error.code !== "ENOENT") throw error;
|
|
2422
2906
|
}
|
|
2423
2907
|
const docs = {};
|
|
2424
2908
|
const docContents = [];
|
|
2425
2909
|
const claims = [];
|
|
2426
|
-
for (const file of
|
|
2910
|
+
for (const file of docPaths) {
|
|
2427
2911
|
const text2 = await content(root, file);
|
|
2428
2912
|
docs[file] = text2 === null ? null : hash(text2);
|
|
2429
2913
|
docContents.push([file, text2]);
|
|
2430
2914
|
for (const claim of text2 ? extractClaims(text2).paths : []) {
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
const combinedDocs = docContents.map(([, text2]) => text2 ?? "").join("\n");
|
|
2437
|
-
const countClaims = docContents.flatMap(([, text2]) => text2 ? extractClaims(text2).counts : []);
|
|
2438
|
-
const commandClaims = docContents.flatMap(([, text2]) => text2 ? extractClaims(text2).commands : []);
|
|
2439
|
-
const rootPackage = await content(root, "package.json");
|
|
2440
|
-
let rootScripts = null;
|
|
2441
|
-
if (rootPackage !== null) {
|
|
2442
|
-
try {
|
|
2443
|
-
const pkg = JSON.parse(rootPackage);
|
|
2444
|
-
rootScripts = pkg?.scripts && typeof pkg.scripts === "object" ? Object.keys(pkg.scripts) : [];
|
|
2445
|
-
} catch {
|
|
2915
|
+
const scope = pathClaimScope(file, claim);
|
|
2916
|
+
for (const candidate of scope?.candidates ?? []) {
|
|
2917
|
+
if (optionalMasonPath(candidate)) continue;
|
|
2918
|
+
claims.push([candidate, await pathExists(root, candidate), await pathExists(root, path20.posix.dirname(candidate))]);
|
|
2919
|
+
}
|
|
2446
2920
|
}
|
|
2447
2921
|
}
|
|
2448
|
-
const
|
|
2922
|
+
const parsedDocs = docContents.map(([file, text2]) => ({ path: file, content: text2 ?? "", claims: extractClaims(text2 ?? "") }));
|
|
2923
|
+
const combinedDocs = moduleDocumentation(parsedDocs);
|
|
2924
|
+
const countClaims = parsedDocs.flatMap((doc) => doc.claims.counts.map((claim) => ({ doc: doc.path, claim })));
|
|
2449
2925
|
const decisionDirectory = await storePath(root, ".mason/decisions");
|
|
2450
|
-
const decisionPresence = await
|
|
2926
|
+
const decisionPresence = await fs13.lstat(decisionDirectory).then((stat) => stat.isDirectory() ? "directory" : "file", (error) => {
|
|
2451
2927
|
if (error.code === "ENOENT") return "absent";
|
|
2452
2928
|
throw error;
|
|
2453
2929
|
});
|
|
2454
|
-
const [modules, counts,
|
|
2930
|
+
const [modules, counts, commands, decisionFiles] = await Promise.all([
|
|
2455
2931
|
combinedDocs ? moduleCandidates(root, combinedDocs) : [],
|
|
2456
|
-
Promise.all(countClaims.map((claim) =>
|
|
2457
|
-
|
|
2458
|
-
|
|
2932
|
+
Promise.all(countClaims.map(({ doc, claim }) => resolveDocCountSource(root, doc, claim))),
|
|
2933
|
+
commandInputs(root, parsedDocs),
|
|
2934
|
+
fg5(".mason/decisions/*.json", { cwd: root, dot: true, onlyFiles: false, followSymbolicLinks: false })
|
|
2459
2935
|
]);
|
|
2460
|
-
const packages = [["package.json", rootPackage], ...await Promise.all(manifests.sort().map(async (file) => [file, await content(root, file)]))];
|
|
2461
2936
|
const decisions = await Promise.all(decisionFiles.sort().map(async (file) => {
|
|
2462
2937
|
await storePath(root, file);
|
|
2463
2938
|
return [file, await content(root, file)];
|
|
2464
2939
|
}));
|
|
2465
2940
|
const [status, index2] = decisions.length ? await Promise.all([
|
|
2466
|
-
|
|
2467
|
-
|
|
2941
|
+
git3(root, "status", "--porcelain=v1", "-z", "--untracked-files=all", "--", ".", ":(exclude).mason/reports"),
|
|
2942
|
+
git3(root, "ls-files", "--stage", "-z", "--", ".", ":(exclude).mason/reports")
|
|
2468
2943
|
]) : ["", ""];
|
|
2469
|
-
const common = [
|
|
2944
|
+
const common = [4, engineVersion, head, shallow, replacements, docContents];
|
|
2470
2945
|
const keys = {
|
|
2471
2946
|
"deleted-reference": hash([common, claims, docStatus]),
|
|
2472
2947
|
"new-module": hash([common, modules]),
|
|
2473
2948
|
"stale-count": hash([common, counts]),
|
|
2474
|
-
"dead-command": hash([common,
|
|
2949
|
+
"dead-command": hash([common, commands]),
|
|
2475
2950
|
"deps-changed": hash([common, docStatus]),
|
|
2476
2951
|
"decision-anchor-drift": hash([common, decisionPresence, decisions, status, index2])
|
|
2477
2952
|
};
|
|
2478
|
-
return { fingerprint: hash(keys), head, docs, keys };
|
|
2953
|
+
return { fingerprint: hash([keys, await advisoryReviewInventory(root)]), head, docs, keys };
|
|
2479
2954
|
}
|
|
2480
2955
|
function checkCache(raw, inputs) {
|
|
2481
2956
|
let entries = {};
|
|
@@ -2502,11 +2977,12 @@ function checkCache(raw, inputs) {
|
|
|
2502
2977
|
return { version: 1, entries: canonical, digest: hash(canonical) };
|
|
2503
2978
|
} };
|
|
2504
2979
|
}
|
|
2505
|
-
var exec7, engineVersion, hash, content,
|
|
2980
|
+
var exec7, engineVersion, hash, content, cacheSchema;
|
|
2506
2981
|
var init_evidence = __esm({
|
|
2507
2982
|
"src/automation/evidence.ts"() {
|
|
2508
2983
|
"use strict";
|
|
2509
2984
|
init_docs();
|
|
2985
|
+
init_scope();
|
|
2510
2986
|
init_claims();
|
|
2511
2987
|
init_repair();
|
|
2512
2988
|
init_checks();
|
|
@@ -2515,20 +2991,20 @@ var init_evidence = __esm({
|
|
|
2515
2991
|
init_stale_count();
|
|
2516
2992
|
init_dead_command();
|
|
2517
2993
|
init_storage();
|
|
2518
|
-
|
|
2519
|
-
|
|
2994
|
+
init_advisory_review();
|
|
2995
|
+
exec7 = promisify9(execFile9);
|
|
2996
|
+
engineVersion = true ? "0.17.0" : "development";
|
|
2520
2997
|
hash = (value) => createHash3("sha256").update(JSON.stringify(value)).digest("hex");
|
|
2521
2998
|
content = readAuditInput;
|
|
2522
|
-
|
|
2523
|
-
cacheSchema = z6.object({ version: z6.literal(1), entries: z6.record(z6.object({ key: z6.string(), result: checkResultSchema })), digest: z6.string() });
|
|
2999
|
+
cacheSchema = z8.object({ version: z8.literal(1), entries: z8.record(z8.object({ key: z8.string(), result: checkResultSchema })), digest: z8.string() });
|
|
2524
3000
|
}
|
|
2525
3001
|
});
|
|
2526
3002
|
|
|
2527
3003
|
// src/automation/execution.ts
|
|
2528
3004
|
import os2 from "os";
|
|
2529
|
-
import
|
|
3005
|
+
import fs14 from "fs/promises";
|
|
2530
3006
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
2531
|
-
import { z as
|
|
3007
|
+
import { z as z9 } from "zod";
|
|
2532
3008
|
function parseExecution(raw) {
|
|
2533
3009
|
try {
|
|
2534
3010
|
return executionSchema.parse(raw);
|
|
@@ -2546,7 +3022,7 @@ function automationFailure(error) {
|
|
|
2546
3022
|
codes.add(String(cause.code));
|
|
2547
3023
|
cause = cause.cause;
|
|
2548
3024
|
}
|
|
2549
|
-
const code = codes.has("ENOSPC") || codes.has("EDQUOT") ? "storage-full" : /changed during|changed while|changed between/.test(message2) ? "inputs-changed" : /Automation is busy/.test(message2) ? "busy" : /not a git repository|unknown revision|bad revision|different history|unreachable/.test(message2) ? "history-unavailable" : error instanceof
|
|
3025
|
+
const code = codes.has("ENOSPC") || codes.has("EDQUOT") ? "storage-full" : /changed during|changed while|changed between/.test(message2) ? "inputs-changed" : /Automation is busy/.test(message2) ? "busy" : /not a git repository|unknown revision|bad revision|different history|unreachable/.test(message2) ? "history-unavailable" : error instanceof z9.ZodError || error instanceof SyntaxError || /Hook input|Expected one command|Unknown automation command|--host/.test(message2) ? "invalid-input" : /store|baseline|modified|symbolic link|Symlink|automation state|state belongs/.test(message2) ? "invalid-evidence" : [...codes].some((c) => /^E[A-Z]+$/.test(c)) ? "io-error" : "internal";
|
|
2550
3026
|
return { code, message: message2, retryable: ["inputs-changed", "storage-full", "busy", "io-error"].includes(code), receiptRecorded: false };
|
|
2551
3027
|
}
|
|
2552
3028
|
function failureMessage(error) {
|
|
@@ -2654,7 +3130,7 @@ async function recordExecution(root, directory, event, run) {
|
|
|
2654
3130
|
throw Object.assign(new Error(failure.message, { cause: error }), { failure });
|
|
2655
3131
|
}
|
|
2656
3132
|
} finally {
|
|
2657
|
-
await
|
|
3133
|
+
await fs14.rm(await storePath(root, owner), { force: true }).catch(() => {
|
|
2658
3134
|
});
|
|
2659
3135
|
}
|
|
2660
3136
|
}
|
|
@@ -2675,33 +3151,33 @@ var init_execution = __esm({
|
|
|
2675
3151
|
init_store();
|
|
2676
3152
|
init_evidence();
|
|
2677
3153
|
init_storage();
|
|
2678
|
-
failureSchema =
|
|
2679
|
-
code:
|
|
2680
|
-
message:
|
|
2681
|
-
retryable:
|
|
2682
|
-
receiptRecorded:
|
|
3154
|
+
failureSchema = z9.object({
|
|
3155
|
+
code: z9.enum(["inputs-changed", "storage-full", "busy", "invalid-input", "history-unavailable", "invalid-evidence", "io-error", "internal"]),
|
|
3156
|
+
message: z9.string(),
|
|
3157
|
+
retryable: z9.boolean(),
|
|
3158
|
+
receiptRecorded: z9.boolean()
|
|
2683
3159
|
});
|
|
2684
|
-
attemptSchema =
|
|
2685
|
-
id:
|
|
2686
|
-
lease:
|
|
2687
|
-
event:
|
|
2688
|
-
startedAt:
|
|
2689
|
-
finishedAt:
|
|
2690
|
-
durationMs:
|
|
2691
|
-
pid:
|
|
2692
|
-
host:
|
|
2693
|
-
status:
|
|
2694
|
-
verificationStatus:
|
|
2695
|
-
reportPath:
|
|
3160
|
+
attemptSchema = z9.object({
|
|
3161
|
+
id: z9.string().regex(/^[a-zA-Z0-9_-]+$/),
|
|
3162
|
+
lease: z9.literal(true).optional(),
|
|
3163
|
+
event: z9.string(),
|
|
3164
|
+
startedAt: z9.string(),
|
|
3165
|
+
finishedAt: z9.string().optional(),
|
|
3166
|
+
durationMs: z9.number().nonnegative().optional(),
|
|
3167
|
+
pid: z9.number().int().positive(),
|
|
3168
|
+
host: z9.string(),
|
|
3169
|
+
status: z9.enum(["running", "completed", "failed", "unknown"]),
|
|
3170
|
+
verificationStatus: z9.string().optional(),
|
|
3171
|
+
reportPath: z9.string().optional(),
|
|
2696
3172
|
failure: failureSchema.optional()
|
|
2697
3173
|
});
|
|
2698
|
-
executionSchema =
|
|
2699
|
-
notificationsSchema =
|
|
2700
|
-
signature:
|
|
3174
|
+
executionSchema = z9.object({ version: z9.literal(1), attempts: z9.array(attemptSchema).max(160), discardedAttempts: z9.number().int().nonnegative().default(0) });
|
|
3175
|
+
notificationsSchema = z9.object({ version: z9.literal(1), sessions: z9.record(z9.object({
|
|
3176
|
+
signature: z9.string(),
|
|
2701
3177
|
code: failureSchema.shape.code,
|
|
2702
|
-
message:
|
|
2703
|
-
count:
|
|
2704
|
-
lastAt:
|
|
3178
|
+
message: z9.string(),
|
|
3179
|
+
count: z9.number().int().positive(),
|
|
3180
|
+
lastAt: z9.string()
|
|
2705
3181
|
})) });
|
|
2706
3182
|
leasePath = (directory, id) => `${directory}/executions/${id}.json`;
|
|
2707
3183
|
}
|
|
@@ -2709,7 +3185,7 @@ var init_execution = __esm({
|
|
|
2709
3185
|
|
|
2710
3186
|
// src/automation/runtime.ts
|
|
2711
3187
|
import { randomUUID as randomUUID4 } from "crypto";
|
|
2712
|
-
import { z as
|
|
3188
|
+
import { z as z10 } from "zod";
|
|
2713
3189
|
async function observeReadOnlyTool(dir, event) {
|
|
2714
3190
|
const ws = await workspace(dir);
|
|
2715
3191
|
await withLock(ws.root, ws.directory, async () => {
|
|
@@ -2787,7 +3263,7 @@ async function computeAnalysis(ws, state, inputs, event) {
|
|
|
2787
3263
|
baselinePaths: [],
|
|
2788
3264
|
reportPath: "",
|
|
2789
3265
|
findings: [],
|
|
2790
|
-
diagnostics: ["No
|
|
3266
|
+
diagnostics: ["No README.md or agent instruction files were discovered. Documentation capture is unavailable; other Mason tools remain usable."],
|
|
2791
3267
|
checks: { ran: [], reused: [], skipped: [] },
|
|
2792
3268
|
counts: { resolved: 0, unresolved: 0, "review-required": 0, unverified: 0 },
|
|
2793
3269
|
capture: "unknown",
|
|
@@ -2798,7 +3274,7 @@ async function computeAnalysis(ws, state, inputs, event) {
|
|
|
2798
3274
|
const previous = await readStoreJson(ws.root, state.latest);
|
|
2799
3275
|
if (!previous?.head || !/^[a-f0-9]{40,64}$/.test(previous.head)) throw new Error("The previous detached checkout evidence is unavailable.");
|
|
2800
3276
|
try {
|
|
2801
|
-
await
|
|
3277
|
+
await git3(ws.root, "merge-base", "--is-ancestor", previous.head, inputs.head);
|
|
2802
3278
|
} catch {
|
|
2803
3279
|
throw new Error("Detached checkout moved to a different history; original repair evidence was retained. Inspect that baseline explicitly.");
|
|
2804
3280
|
}
|
|
@@ -3003,35 +3479,35 @@ var init_runtime = __esm({
|
|
|
3003
3479
|
init_storage();
|
|
3004
3480
|
init_evidence();
|
|
3005
3481
|
init_store();
|
|
3006
|
-
SCOPE = "Documentation audit evidence only. Hook receipts show observed events, not complete interception. Resolved
|
|
3482
|
+
SCOPE = "Documentation audit evidence only. Hook receipts show observed events, not complete interception. Resolved findings no longer fail their checks or have a recorded assessment covering current evidence. Repair and review only within the user's task authorization.";
|
|
3007
3483
|
priority = { resolved: 0, "review-required": 1, unresolved: 2, unverified: 3 };
|
|
3008
3484
|
cleanText = (text2) => text2.replace(/[\u0000-\u001f\u007f-\u009f]/g, " ").slice(0, 250);
|
|
3009
|
-
analysisSchema =
|
|
3010
|
-
id:
|
|
3011
|
-
fingerprint:
|
|
3012
|
-
completedAt:
|
|
3013
|
-
baselineDigest:
|
|
3014
|
-
report:
|
|
3015
|
-
version:
|
|
3016
|
-
status:
|
|
3017
|
-
root:
|
|
3018
|
-
branch:
|
|
3019
|
-
head:
|
|
3020
|
-
baselinePaths:
|
|
3021
|
-
reportPath:
|
|
3022
|
-
findings:
|
|
3023
|
-
diagnostics:
|
|
3024
|
-
checks:
|
|
3025
|
-
ran:
|
|
3026
|
-
reused:
|
|
3027
|
-
skipped:
|
|
3485
|
+
analysisSchema = z10.object({
|
|
3486
|
+
id: z10.string(),
|
|
3487
|
+
fingerprint: z10.string(),
|
|
3488
|
+
completedAt: z10.number(),
|
|
3489
|
+
baselineDigest: z10.string(),
|
|
3490
|
+
report: z10.object({
|
|
3491
|
+
version: z10.literal(1),
|
|
3492
|
+
status: z10.enum(["verified", "issues-remain", "incomplete", "unavailable"]),
|
|
3493
|
+
root: z10.string(),
|
|
3494
|
+
branch: z10.string(),
|
|
3495
|
+
head: z10.string(),
|
|
3496
|
+
baselinePaths: z10.array(z10.string()),
|
|
3497
|
+
reportPath: z10.string(),
|
|
3498
|
+
findings: z10.array(repairFindingSchema),
|
|
3499
|
+
diagnostics: z10.array(z10.string()),
|
|
3500
|
+
checks: z10.object({
|
|
3501
|
+
ran: z10.array(z10.string()),
|
|
3502
|
+
reused: z10.array(z10.string()),
|
|
3503
|
+
skipped: z10.array(z10.object({ check: z10.string(), reason: z10.string(), doc: z10.string().optional() }))
|
|
3028
3504
|
}),
|
|
3029
|
-
counts:
|
|
3030
|
-
capture:
|
|
3031
|
-
scope:
|
|
3505
|
+
counts: z10.object({ resolved: z10.number(), unresolved: z10.number(), "review-required": z10.number(), unverified: z10.number() }),
|
|
3506
|
+
capture: z10.enum(["observed", "unknown"]),
|
|
3507
|
+
scope: z10.string()
|
|
3032
3508
|
})
|
|
3033
3509
|
});
|
|
3034
|
-
sharedSchema =
|
|
3510
|
+
sharedSchema = z10.object({ analysis: analysisSchema, digest: z10.string() });
|
|
3035
3511
|
baselineDigest = async (ws, state) => hash(await Promise.all(
|
|
3036
3512
|
state.baselines.map(async (b) => [b.path, await readStoreJson(ws.root, b.path)])
|
|
3037
3513
|
));
|
|
@@ -3039,7 +3515,7 @@ var init_runtime = __esm({
|
|
|
3039
3515
|
});
|
|
3040
3516
|
|
|
3041
3517
|
// src/setup/model.ts
|
|
3042
|
-
import { z as
|
|
3518
|
+
import { z as z11 } from "zod";
|
|
3043
3519
|
async function loadSetup(root) {
|
|
3044
3520
|
const raw = await readStoreJson(root, SETUP_PATH);
|
|
3045
3521
|
if (raw === null) return null;
|
|
@@ -3057,42 +3533,42 @@ var init_model = __esm({
|
|
|
3057
3533
|
"src/setup/model.ts"() {
|
|
3058
3534
|
"use strict";
|
|
3059
3535
|
init_storage();
|
|
3060
|
-
setupHostSchema =
|
|
3061
|
-
configuredVersion:
|
|
3062
|
-
revision:
|
|
3063
|
-
fingerprint:
|
|
3064
|
-
mcpFingerprint:
|
|
3065
|
-
instructions:
|
|
3536
|
+
setupHostSchema = z11.object({
|
|
3537
|
+
configuredVersion: z11.string(),
|
|
3538
|
+
revision: z11.string().uuid(),
|
|
3539
|
+
fingerprint: z11.string(),
|
|
3540
|
+
mcpFingerprint: z11.string(),
|
|
3541
|
+
instructions: z11.array(z11.string())
|
|
3066
3542
|
});
|
|
3067
|
-
setupSchema =
|
|
3543
|
+
setupSchema = z11.object({ version: z11.literal(2), hosts: z11.object({
|
|
3068
3544
|
codex: setupHostSchema.optional(),
|
|
3069
3545
|
claude: setupHostSchema.optional()
|
|
3070
3546
|
}) });
|
|
3071
3547
|
SETUP_PATH = ".mason/local/setup.json";
|
|
3072
|
-
receiptSchema =
|
|
3073
|
-
version:
|
|
3074
|
-
host:
|
|
3075
|
-
status:
|
|
3076
|
-
initialReportPath:
|
|
3077
|
-
initialBaselinePaths:
|
|
3078
|
-
root:
|
|
3079
|
-
revision:
|
|
3080
|
-
configuredAt:
|
|
3548
|
+
receiptSchema = z11.object({
|
|
3549
|
+
version: z11.literal(1),
|
|
3550
|
+
host: z11.enum(["codex", "claude"]),
|
|
3551
|
+
status: z11.enum(["installing", "configured"]),
|
|
3552
|
+
initialReportPath: z11.string(),
|
|
3553
|
+
initialBaselinePaths: z11.array(z11.string()),
|
|
3554
|
+
root: z11.string(),
|
|
3555
|
+
revision: z11.string().uuid(),
|
|
3556
|
+
configuredAt: z11.string().optional()
|
|
3081
3557
|
});
|
|
3082
3558
|
}
|
|
3083
3559
|
});
|
|
3084
3560
|
|
|
3085
3561
|
// src/setup/launcher.ts
|
|
3086
|
-
import { execFile as
|
|
3087
|
-
import { promisify as
|
|
3088
|
-
import
|
|
3562
|
+
import { execFile as execFile10 } from "child_process";
|
|
3563
|
+
import { promisify as promisify10 } from "util";
|
|
3564
|
+
import fs15 from "fs/promises";
|
|
3089
3565
|
function globalCommand(args, platform = process.platform) {
|
|
3090
3566
|
return platform === "win32" ? { command: "cmd.exe", args: ["/d", "/s", "/c", "mason", ...args] } : { command: "mason", args };
|
|
3091
3567
|
}
|
|
3092
3568
|
async function installedCommand() {
|
|
3093
3569
|
const invocation = globalCommand(["internal-integration-version"]);
|
|
3094
3570
|
try {
|
|
3095
|
-
const { stdout } = await
|
|
3571
|
+
const { stdout } = await promisify10(execFile10)(
|
|
3096
3572
|
invocation.command,
|
|
3097
3573
|
invocation.args,
|
|
3098
3574
|
{ timeout: 5e3, maxBuffer: 8192, windowsHide: true }
|
|
@@ -3110,7 +3586,7 @@ var init_launcher = __esm({
|
|
|
3110
3586
|
"use strict";
|
|
3111
3587
|
init_evidence();
|
|
3112
3588
|
init_model();
|
|
3113
|
-
executingVersion = () => true ? "0.
|
|
3589
|
+
executingVersion = () => true ? "0.17.0" : "development";
|
|
3114
3590
|
mcpCommand = (host) => globalCommand(["--setup-host", host, "mcp"]);
|
|
3115
3591
|
hookCommand = (host) => `mason --setup-host ${host} auto`;
|
|
3116
3592
|
}
|
|
@@ -3123,8 +3599,8 @@ __export(observations_exports, {
|
|
|
3123
3599
|
observeActivation: () => observeActivation,
|
|
3124
3600
|
readObservation: () => readObservation
|
|
3125
3601
|
});
|
|
3126
|
-
import
|
|
3127
|
-
import { z as
|
|
3602
|
+
import fs16 from "fs/promises";
|
|
3603
|
+
import { z as z12 } from "zod";
|
|
3128
3604
|
function observationPath(directory, host, revision, version = executingVersion()) {
|
|
3129
3605
|
return `${directory}/activation/${host}-${revision}-${hash(version).slice(0, 12)}.json`;
|
|
3130
3606
|
}
|
|
@@ -3140,8 +3616,8 @@ async function observeActivation(dir, event, options = {}) {
|
|
|
3140
3616
|
if (host !== "codex" && host !== "claude" || !revision || !process.env.MASON_SETUP_ROOT) return null;
|
|
3141
3617
|
try {
|
|
3142
3618
|
const capturedDirectory = options.directory?.match(/^\.mason\/reports\/automation\/[a-f0-9]{24}$/)?.[0] ?? options.reportPath?.match(/^(\.mason\/reports\/automation\/[a-f0-9]{24})\/checks\//)?.[1];
|
|
3143
|
-
const ws = capturedDirectory ? { root: await
|
|
3144
|
-
if (ws.root !== await
|
|
3619
|
+
const ws = capturedDirectory ? { root: await fs16.realpath(dir), directory: capturedDirectory } : await workspace(dir);
|
|
3620
|
+
if (ws.root !== await fs16.realpath(process.env.MASON_SETUP_ROOT)) return null;
|
|
3145
3621
|
const setup = await loadSetup(ws.root);
|
|
3146
3622
|
if (setup?.hosts[host]?.revision !== revision) return "Mason setup changed; restart the assistant to observe the current integration.";
|
|
3147
3623
|
const directory = ws.directory + "/activation";
|
|
@@ -3189,26 +3665,26 @@ var init_observations = __esm({
|
|
|
3189
3665
|
init_storage();
|
|
3190
3666
|
init_model();
|
|
3191
3667
|
init_launcher();
|
|
3192
|
-
observationSchema =
|
|
3193
|
-
version:
|
|
3194
|
-
masonVersion:
|
|
3195
|
-
root:
|
|
3196
|
-
revision:
|
|
3197
|
-
host:
|
|
3198
|
-
contextCalls:
|
|
3199
|
-
lastContextAt:
|
|
3200
|
-
sessions:
|
|
3201
|
-
events:
|
|
3202
|
-
at:
|
|
3203
|
-
verificationStatus:
|
|
3204
|
-
reportPath:
|
|
3668
|
+
observationSchema = z12.object({
|
|
3669
|
+
version: z12.literal(1),
|
|
3670
|
+
masonVersion: z12.string(),
|
|
3671
|
+
root: z12.string(),
|
|
3672
|
+
revision: z12.string(),
|
|
3673
|
+
host: z12.enum(["codex", "claude"]),
|
|
3674
|
+
contextCalls: z12.number().int().nonnegative(),
|
|
3675
|
+
lastContextAt: z12.string().optional(),
|
|
3676
|
+
sessions: z12.record(z12.object({
|
|
3677
|
+
events: z12.array(z12.enum(events)),
|
|
3678
|
+
at: z12.string(),
|
|
3679
|
+
verificationStatus: z12.string().optional(),
|
|
3680
|
+
reportPath: z12.string().optional()
|
|
3205
3681
|
}))
|
|
3206
3682
|
});
|
|
3207
3683
|
}
|
|
3208
3684
|
});
|
|
3209
3685
|
|
|
3210
3686
|
// src/automation/adapters.ts
|
|
3211
|
-
import { z as
|
|
3687
|
+
import { z as z13 } from "zod";
|
|
3212
3688
|
function normalizeHook(host, raw) {
|
|
3213
3689
|
hostSchema.parse(host);
|
|
3214
3690
|
const input2 = inputSchema.parse(raw);
|
|
@@ -3282,15 +3758,15 @@ var init_adapters = __esm({
|
|
|
3282
3758
|
init_execution();
|
|
3283
3759
|
init_runtime();
|
|
3284
3760
|
init_store();
|
|
3285
|
-
inputSchema =
|
|
3286
|
-
cwd:
|
|
3287
|
-
session_id:
|
|
3288
|
-
hook_event_name:
|
|
3289
|
-
tool_name:
|
|
3290
|
-
tool_use_id:
|
|
3291
|
-
tool_input:
|
|
3292
|
-
stop_hook_active:
|
|
3293
|
-
permission_mode:
|
|
3761
|
+
inputSchema = z13.object({
|
|
3762
|
+
cwd: z13.string().min(1),
|
|
3763
|
+
session_id: z13.string().min(1).max(500),
|
|
3764
|
+
hook_event_name: z13.enum(["SessionStart", "UserPromptSubmit", "PreToolUse", "PostToolUse", "Stop"]),
|
|
3765
|
+
tool_name: z13.string().optional(),
|
|
3766
|
+
tool_use_id: z13.string().max(500).optional(),
|
|
3767
|
+
tool_input: z13.unknown().optional(),
|
|
3768
|
+
stop_hook_active: z13.boolean().optional(),
|
|
3769
|
+
permission_mode: z13.string().optional()
|
|
3294
3770
|
});
|
|
3295
3771
|
lifecycle = {
|
|
3296
3772
|
SessionStart: "session_start",
|
|
@@ -3310,8 +3786,8 @@ __export(files_exports, {
|
|
|
3310
3786
|
managedBlock: () => managedBlock,
|
|
3311
3787
|
readText: () => readText
|
|
3312
3788
|
});
|
|
3313
|
-
import
|
|
3314
|
-
import
|
|
3789
|
+
import fs17 from "fs/promises";
|
|
3790
|
+
import path21 from "path";
|
|
3315
3791
|
import { randomUUID as randomUUID5 } from "crypto";
|
|
3316
3792
|
async function readText(root, file) {
|
|
3317
3793
|
try {
|
|
@@ -3340,14 +3816,14 @@ async function applyEdit(root, edit) {
|
|
|
3340
3816
|
if (edit.after === null) {
|
|
3341
3817
|
const file2 = await storePath(root, edit.path);
|
|
3342
3818
|
if (await readText(root, edit.path) !== edit.before) throw new Error("Input changed during removal: " + edit.path);
|
|
3343
|
-
await
|
|
3819
|
+
await fs17.unlink(file2);
|
|
3344
3820
|
return true;
|
|
3345
3821
|
}
|
|
3346
3822
|
const file = await storePath(root, edit.path, true);
|
|
3347
|
-
const temporary =
|
|
3823
|
+
const temporary = path21.join(path21.dirname(file), ".mason-setup-" + randomUUID5() + ".tmp");
|
|
3348
3824
|
try {
|
|
3349
|
-
const mode = await
|
|
3350
|
-
const handle = await
|
|
3825
|
+
const mode = await fs17.stat(file).then((s) => s.mode & 511, () => 384);
|
|
3826
|
+
const handle = await fs17.open(temporary, "wx", mode);
|
|
3351
3827
|
try {
|
|
3352
3828
|
await handle.writeFile(edit.after, "utf8");
|
|
3353
3829
|
await handle.sync();
|
|
@@ -3355,10 +3831,10 @@ async function applyEdit(root, edit) {
|
|
|
3355
3831
|
await handle.close();
|
|
3356
3832
|
}
|
|
3357
3833
|
if (await readText(root, edit.path) !== edit.before) throw new Error("Integration input changed during update: " + edit.path);
|
|
3358
|
-
await
|
|
3834
|
+
await fs17.rename(temporary, file);
|
|
3359
3835
|
return true;
|
|
3360
3836
|
} finally {
|
|
3361
|
-
await
|
|
3837
|
+
await fs17.rm(temporary, { force: true });
|
|
3362
3838
|
}
|
|
3363
3839
|
}
|
|
3364
3840
|
var init_files2 = __esm({
|
|
@@ -3379,7 +3855,7 @@ __export(ownership_exports, {
|
|
|
3379
3855
|
ownershipEdit: () => ownershipEdit,
|
|
3380
3856
|
ownershipSchema: () => ownershipSchema
|
|
3381
3857
|
});
|
|
3382
|
-
import { z as
|
|
3858
|
+
import { z as z14 } from "zod";
|
|
3383
3859
|
import { parse } from "smol-toml";
|
|
3384
3860
|
function blockSpan(text2, start, end) {
|
|
3385
3861
|
const starts = text2.split(start).length - 1, ends = text2.split(end).length - 1;
|
|
@@ -3430,30 +3906,30 @@ var init_ownership = __esm({
|
|
|
3430
3906
|
["<!-- mason:agents:start -->", "<!-- mason:agents:end -->"],
|
|
3431
3907
|
["# mason:mcp:start", "# mason:mcp:end"]
|
|
3432
3908
|
];
|
|
3433
|
-
fileSchema =
|
|
3434
|
-
created:
|
|
3435
|
-
initialHash:
|
|
3436
|
-
blocks:
|
|
3437
|
-
mcpHash:
|
|
3438
|
-
hookCommands:
|
|
3439
|
-
hooks:
|
|
3909
|
+
fileSchema = z14.object({
|
|
3910
|
+
created: z14.boolean(),
|
|
3911
|
+
initialHash: z14.string(),
|
|
3912
|
+
blocks: z14.record(z14.string()),
|
|
3913
|
+
mcpHash: z14.string().optional(),
|
|
3914
|
+
hookCommands: z14.array(z14.string()).optional(),
|
|
3915
|
+
hooks: z14.record(z14.array(z14.string())).optional()
|
|
3440
3916
|
});
|
|
3441
|
-
ownershipSchema =
|
|
3917
|
+
ownershipSchema = z14.object({ version: z14.literal(1), files: z14.record(fileSchema) });
|
|
3442
3918
|
}
|
|
3443
3919
|
});
|
|
3444
3920
|
|
|
3445
3921
|
// src/mcp/init.ts
|
|
3446
|
-
import { z as
|
|
3922
|
+
import { z as z15 } from "zod";
|
|
3447
3923
|
var markerSchema, CLAUDE_MD_SECTION, ASSISTANT_SETUP, QUICKSTART_PLAYBOOK, MAP_PLAYBOOK;
|
|
3448
3924
|
var init_init = __esm({
|
|
3449
3925
|
"src/mcp/init.ts"() {
|
|
3450
3926
|
"use strict";
|
|
3451
3927
|
init_storage();
|
|
3452
3928
|
init_files2();
|
|
3453
|
-
markerSchema =
|
|
3454
|
-
version:
|
|
3455
|
-
initializedAt:
|
|
3456
|
-
features:
|
|
3929
|
+
markerSchema = z15.object({
|
|
3930
|
+
version: z15.literal(1),
|
|
3931
|
+
initializedAt: z15.string(),
|
|
3932
|
+
features: z15.object({ confluence: z15.boolean().optional() }).passthrough().optional()
|
|
3457
3933
|
}).passthrough();
|
|
3458
3934
|
CLAUDE_MD_SECTION = `<!-- mason:start -->
|
|
3459
3935
|
## Mason project knowledge
|
|
@@ -3463,12 +3939,14 @@ Mason provides recorded decisions and file impact over MCP. A concept map is opt
|
|
|
3463
3939
|
- Task, bug, change request, or investigation of why the project works this way \u2192 \`get_context\` with the task text and known files: matching decisions, related tests, impact, and any available map entries.
|
|
3464
3940
|
- Before editing a file \u2192 \`get_impact\` to check references, tests, and historical change partners.
|
|
3465
3941
|
- Investigation or correction reveals a reusable project lesson \u2192 \`save_decision\` before finishing. Capture only the lasting constraint and reason, with anchors and known sources, owner, and recorder. This creates a proposal; never infer approval. Preserve uncertain causes and unknown attribution. Route project lessons here; keep personal preferences in agent memory. Skip code summaries, current checkout status, temporary task permissions, session trivia, and secrets. No qualifying lesson means no record.
|
|
3942
|
+
- Before saving, compare the lesson with matching \`get_context\` records and any pending proposal. If new evidence changes the same lesson's assumptions, scope, or recommended action, revise it with \`save_decision(id: existingId)\`, including when it is accepted. Preserve supported rationale and sources, replace obsolete instructions, and add the new evidence. Create a separate record for a genuinely distinct lesson; skip unchanged restatements. Revision preserves history and leaves the accepted version operative until authorized review.
|
|
3466
3943
|
- Consult trust metadata before relying on entries: unknown or changed freshness requires inspection, and failed verification means the description must be corrected. Check approval too: proposals are suggestions, legacy records are unreviewed, and accepted decisions are recorded constraints subject to freshness checks. An accepted revision remains operative while a pending proposal is reviewed; keep both versions and their freshness distinct.
|
|
3467
3944
|
- Asked to review or re-verify a decision \u2192 \`review_decision\` first to inspect content, sources, history, and code changes. Record acceptance, reaffirmation, or retirement only when authorized by the user or a cited team review, with the actual reviewer and reason. Never infer approval from unchanged code. Review and commit the local record through the normal project workflow.
|
|
3468
3945
|
- For an architectural overview, use \`get_snapshot\` if a map is available. If \`map.status\` is missing or invalid, use available decisions and source evidence; do not start building a map unless requested.
|
|
3469
3946
|
- \`mason_init\` returns documentation audit and committed-diff review results, plus a short setup guide. Pass \`evidence\` with local CI manifest paths to include test and analysis results; the CLI equivalent is \`mason-review --evidence <manifest>\`. State skipped, unavailable, stale, or unknown checks explicitly. Related accepted decisions identify review context, not proven violations.
|
|
3470
3947
|
|
|
3471
3948
|
- When documentation repair is authorized, use \`mason_repair(action: "prepare")\` before edits, keep its baselinePath, and use \`mason_repair(action: "verify", baselinePath)\` after edits and any final doc commit. Report every original finding's outcome and any new findings. Suppressed advisories remain unresolved; editing a doc does not approve it.
|
|
3949
|
+
- When advisory assessment is authorized, use \`review_advisory(action: "prepare", baselinePath, findingId)\` to inspect original evidence and history. Record \`addressed\`, \`inapplicable\`, or \`deferred\` with the actual reviewer, reason in note, and returned reviewToken only after relevant edits are committed. Commit the assessment and verify the same baseline again. Relevant evidence changes reopen it; deferral stays outstanding. Decision findings use \`review_decision\`; advisory closure never approves a decision.
|
|
3472
3950
|
|
|
3473
3951
|
- When Mason automation is installed, use \`mason_automation(action: "status")\` to inspect configured hooks and observed events, and \`mason_automation(action: "check")\` to resume its retained repair evidence. CLI fallback: \`mason-auto status\` / \`mason-auto check\`. Preserve existing baselines across sessions. Automatic checks do not authorize unrelated repairs or approve advisories.
|
|
3474
3952
|
|
|
@@ -3484,7 +3962,7 @@ ${CLAUDE_MD_SECTION}`;
|
|
|
3484
3962
|
|
|
3485
3963
|
1. Explain the actionable findings with their source evidence. Separate audit issues, advisories, and skipped checks. The review covers committed changes from the merge base to HEAD; workingTree paths are not included in that review. An unavailable or empty check is not proof that the project is correct. Use the CLI for full output if a summary is truncated.
|
|
3486
3964
|
2. Address findings within the user's requested scope. Setup alone authorizes Mason host configuration, hooks, instructions, and ignore rules; rewriting existing project claims requires repair scope. If repair is authorized, call \`mason_repair(dir, action: "prepare")\` before editing; it saves the full original findings even when this summary is truncated. Inspect relevant source, make grounded edits, then call \`mason_repair(dir, action: "verify", baselinePath)\` with that same baseline, including after any final doc commit. Report resolved, unresolved, review-required, unverified, and new findings. Keep suppressed advisories visible even when setup has already dirtied a doc. Do not invent a decision just to populate the store.
|
|
3487
|
-
3. When the task reveals a real lesson or constraint,
|
|
3965
|
+
3. When the task reveals a real lesson or constraint, compare matching \`get_context\` records first. If its assumptions, scope, or recommended action changed, revise that record using \`save_decision(id: existingId)\`; create a separate record for a genuinely distinct lesson and skip unchanged restatements. Include title, body, category, anchors, and known owner/source/actor information. Preserve supported rationale and sources, replace obsolete instructions, and add new evidence. Missing attribution can be added later. The tool writes a local proposal; editing it preserves revision history and requires a new acceptance, while any earlier accepted revision remains operative. An unchanged save never refreshes its evidence. When decision review is requested, \`review_decision\` prepares the record and code evidence before any authorized verdict. Review and commit records through the normal workflow. Retrieve it on the next relevant task with \`get_context(dir, task, files)\`.
|
|
3488
3966
|
|
|
3489
3967
|
${ASSISTANT_SETUP}
|
|
3490
3968
|
|
|
@@ -3530,8 +4008,8 @@ var git_exports = {};
|
|
|
3530
4008
|
__export(git_exports, {
|
|
3531
4009
|
isGitRepo: () => isGitRepo
|
|
3532
4010
|
});
|
|
3533
|
-
import { execFile as
|
|
3534
|
-
import { promisify as
|
|
4011
|
+
import { execFile as execFile11 } from "child_process";
|
|
4012
|
+
import { promisify as promisify11 } from "util";
|
|
3535
4013
|
async function isGitRepo(dir) {
|
|
3536
4014
|
try {
|
|
3537
4015
|
await exec8("git", ["rev-parse", "--git-dir"], { cwd: dir });
|
|
@@ -3544,7 +4022,7 @@ var exec8;
|
|
|
3544
4022
|
var init_git2 = __esm({
|
|
3545
4023
|
"src/utils/git.ts"() {
|
|
3546
4024
|
"use strict";
|
|
3547
|
-
exec8 =
|
|
4025
|
+
exec8 = promisify11(execFile11);
|
|
3548
4026
|
}
|
|
3549
4027
|
});
|
|
3550
4028
|
|
|
@@ -3560,7 +4038,7 @@ __export(config_exports, {
|
|
|
3560
4038
|
});
|
|
3561
4039
|
import { isDeepStrictEqual } from "util";
|
|
3562
4040
|
import { parse as parse2, stringify } from "smol-toml";
|
|
3563
|
-
import { z as
|
|
4041
|
+
import { z as z16 } from "zod";
|
|
3564
4042
|
async function instructionEdits(root, host) {
|
|
3565
4043
|
const found = await Promise.all(DOC_CANDIDATES.map(async (file) => ({ path: file, text: await readText(root, file) })));
|
|
3566
4044
|
const existing = found.find((f) => f.text !== null);
|
|
@@ -3629,11 +4107,11 @@ async function hookEdits(root, host) {
|
|
|
3629
4107
|
}
|
|
3630
4108
|
async function ancillaryEdits(root) {
|
|
3631
4109
|
const ignore = await readText(root, ".gitignore");
|
|
3632
|
-
const { git:
|
|
4110
|
+
const { git: git4 } = await Promise.resolve().then(() => (init_evidence(), evidence_exports));
|
|
3633
4111
|
const { isGitRepo: isGitRepo2 } = await Promise.resolve().then(() => (init_git2(), git_exports));
|
|
3634
4112
|
let parentIgnored = false;
|
|
3635
4113
|
try {
|
|
3636
|
-
if (await isGitRepo2(root)) parentIgnored = !!(await
|
|
4114
|
+
if (await isGitRepo2(root)) parentIgnored = !!(await git4(root, "check-ignore", "--no-index", ".mason")).trim();
|
|
3637
4115
|
} catch (error) {
|
|
3638
4116
|
if (error.code !== 1) throw error;
|
|
3639
4117
|
}
|
|
@@ -3642,6 +4120,8 @@ async function ancillaryEdits(root) {
|
|
|
3642
4120
|
...retainParentRule ? ["!/.mason/", "/.mason/*"] : [],
|
|
3643
4121
|
"!/.mason/decisions/",
|
|
3644
4122
|
"!/.mason/decisions/**",
|
|
4123
|
+
"!/.mason/reviews/",
|
|
4124
|
+
"!/.mason/reviews/**",
|
|
3645
4125
|
"!/.mason/config.json",
|
|
3646
4126
|
"!/.mason/snapshot.json",
|
|
3647
4127
|
"/.mason/local/",
|
|
@@ -3676,7 +4156,7 @@ var init_config = __esm({
|
|
|
3676
4156
|
init_install();
|
|
3677
4157
|
init_files2();
|
|
3678
4158
|
init_launcher();
|
|
3679
|
-
object =
|
|
4159
|
+
object = z16.record(z16.unknown());
|
|
3680
4160
|
mcpPath = (host) => host === "codex" ? ".codex/config.toml" : ".mcp.json";
|
|
3681
4161
|
TOML_START = "# mason:mcp:start";
|
|
3682
4162
|
TOML_END = "# mason:mcp:end";
|
|
@@ -3694,11 +4174,11 @@ __export(install_exports, {
|
|
|
3694
4174
|
installAutomation: () => installAutomation,
|
|
3695
4175
|
installedAutomation: () => installedAutomation,
|
|
3696
4176
|
planAutomationInstall: () => planAutomationInstall,
|
|
3697
|
-
recordSchema: () =>
|
|
4177
|
+
recordSchema: () => recordSchema2
|
|
3698
4178
|
});
|
|
3699
|
-
import { z as
|
|
4179
|
+
import { z as z17 } from "zod";
|
|
3700
4180
|
async function installationRecord(root) {
|
|
3701
|
-
return
|
|
4181
|
+
return recordSchema2.parse(await readStoreJson(root, AUTOMATION_PATH) ?? { version: 1, hosts: {} });
|
|
3702
4182
|
}
|
|
3703
4183
|
async function installAutomation(dir, host, command) {
|
|
3704
4184
|
const ws = await workspace(dir);
|
|
@@ -3767,7 +4247,7 @@ async function installedAutomation(dir) {
|
|
|
3767
4247
|
}
|
|
3768
4248
|
return result;
|
|
3769
4249
|
}
|
|
3770
|
-
var groupSchema, automationConfigSchema,
|
|
4250
|
+
var groupSchema, automationConfigSchema, recordSchema2, AUTOMATION_PATH, configPath;
|
|
3771
4251
|
var init_install = __esm({
|
|
3772
4252
|
"src/automation/install.ts"() {
|
|
3773
4253
|
"use strict";
|
|
@@ -3777,9 +4257,9 @@ var init_install = __esm({
|
|
|
3777
4257
|
init_store();
|
|
3778
4258
|
init_files2();
|
|
3779
4259
|
init_ownership();
|
|
3780
|
-
groupSchema =
|
|
3781
|
-
automationConfigSchema =
|
|
3782
|
-
|
|
4260
|
+
groupSchema = z17.object({ hooks: z17.array(z17.object({ type: z17.string(), command: z17.string().optional() }).passthrough()) }).passthrough();
|
|
4261
|
+
automationConfigSchema = z17.object({ hooks: z17.record(z17.array(groupSchema)).optional() }).passthrough();
|
|
4262
|
+
recordSchema2 = z17.object({ version: z17.literal(1), hosts: z17.record(z17.object({ command: z17.string() })) });
|
|
3783
4263
|
AUTOMATION_PATH = ".mason/local/automation.json";
|
|
3784
4264
|
configPath = (host) => host === "claude" ? ".claude/settings.json" : ".codex/hooks.json";
|
|
3785
4265
|
}
|
|
@@ -3793,8 +4273,8 @@ __export(teardown_exports, {
|
|
|
3793
4273
|
});
|
|
3794
4274
|
import { isDeepStrictEqual as isDeepStrictEqual2 } from "util";
|
|
3795
4275
|
import { parse as parse3, stringify as stringify2 } from "smol-toml";
|
|
3796
|
-
import
|
|
3797
|
-
import { z as
|
|
4276
|
+
import fg6 from "fast-glob";
|
|
4277
|
+
import { z as z18 } from "zod";
|
|
3798
4278
|
async function planTeardown(root, selected) {
|
|
3799
4279
|
const edits = [], diagnostics = [];
|
|
3800
4280
|
const inputs = /* @__PURE__ */ new Map();
|
|
@@ -3814,7 +4294,7 @@ async function planTeardown(root, selected) {
|
|
|
3814
4294
|
const setupBefore = await read(SETUP_PATH);
|
|
3815
4295
|
const setup = setupBefore === null ? null : setupSchema.parse(JSON.parse(setupBefore));
|
|
3816
4296
|
const automationBefore = await read(AUTOMATION_PATH);
|
|
3817
|
-
const automation = automationBefore === null ? null :
|
|
4297
|
+
const automation = automationBefore === null ? null : recordSchema2.parse(JSON.parse(automationBefore));
|
|
3818
4298
|
const commands = (host) => new Set([
|
|
3819
4299
|
automation?.hosts[host]?.command,
|
|
3820
4300
|
...ownership.files[configPath(host)]?.hookCommands ?? [],
|
|
@@ -3928,7 +4408,7 @@ async function planTeardown(root, selected) {
|
|
|
3928
4408
|
if (diagnostics.length) edits.splice(instructionEditStart);
|
|
3929
4409
|
if (!diagnostics.length) {
|
|
3930
4410
|
const cleanup = [];
|
|
3931
|
-
const receiptFiles = await
|
|
4411
|
+
const receiptFiles = await fg6(
|
|
3932
4412
|
selected.map((host) => ".mason/reports/automation/*/setup-" + host + ".json"),
|
|
3933
4413
|
{ cwd: root, dot: true, onlyFiles: false, followSymbolicLinks: false }
|
|
3934
4414
|
);
|
|
@@ -3941,7 +4421,7 @@ async function planTeardown(root, selected) {
|
|
|
3941
4421
|
if (!remainingHost) await attempt(".mason/local/project.json", async () => {
|
|
3942
4422
|
const before = await read(".mason/local/project.json");
|
|
3943
4423
|
if (before === null) return;
|
|
3944
|
-
|
|
4424
|
+
z18.object({ version: z18.literal(1), initializedAt: z18.string() }).strict().parse(JSON.parse(before));
|
|
3945
4425
|
cleanup.push({ path: ".mason/local/project.json", before, after: null });
|
|
3946
4426
|
});
|
|
3947
4427
|
if (!diagnostics.length) {
|
|
@@ -4013,14 +4493,14 @@ var init_teardown = __esm({
|
|
|
4013
4493
|
init_model();
|
|
4014
4494
|
init_ownership();
|
|
4015
4495
|
hosts = ["codex", "claude"];
|
|
4016
|
-
object2 =
|
|
4496
|
+
object2 = z18.record(z18.unknown());
|
|
4017
4497
|
json = (value) => JSON.stringify(value, null, 2) + "\n";
|
|
4018
4498
|
}
|
|
4019
4499
|
});
|
|
4020
4500
|
|
|
4021
4501
|
// src/review/cochange.ts
|
|
4022
|
-
import { execFile as
|
|
4023
|
-
import { promisify as
|
|
4502
|
+
import { execFile as execFile12 } from "child_process";
|
|
4503
|
+
import { promisify as promisify12 } from "util";
|
|
4024
4504
|
async function buildMatrix(resolvedRoot) {
|
|
4025
4505
|
try {
|
|
4026
4506
|
const { stdout: shallow } = await exec9("git", ["rev-parse", "--is-shallow-repository"], { cwd: resolvedRoot });
|
|
@@ -4085,7 +4565,7 @@ var exec9, HISTORY_COMMITS, MIN_FILE_COMMITS, MIN_SHARED_COMMITS, MIN_COCHANGE_R
|
|
|
4085
4565
|
var init_cochange = __esm({
|
|
4086
4566
|
"src/review/cochange.ts"() {
|
|
4087
4567
|
"use strict";
|
|
4088
|
-
exec9 =
|
|
4568
|
+
exec9 = promisify12(execFile12);
|
|
4089
4569
|
HISTORY_COMMITS = 1500;
|
|
4090
4570
|
MIN_FILE_COMMITS = 5;
|
|
4091
4571
|
MIN_SHARED_COMMITS = 4;
|
|
@@ -4140,7 +4620,7 @@ var init_types2 = __esm({
|
|
|
4140
4620
|
});
|
|
4141
4621
|
|
|
4142
4622
|
// src/review/evidence/vitest.ts
|
|
4143
|
-
import { z as
|
|
4623
|
+
import { z as z19 } from "zod";
|
|
4144
4624
|
function parseVitest(raw, sourceRoot) {
|
|
4145
4625
|
const report = schema.parse(raw);
|
|
4146
4626
|
const findings = [], diagnostics = [];
|
|
@@ -4183,30 +4663,30 @@ function parseVitest(raw, sourceRoot) {
|
|
|
4183
4663
|
diagnostics
|
|
4184
4664
|
};
|
|
4185
4665
|
}
|
|
4186
|
-
var
|
|
4666
|
+
var count3, schema;
|
|
4187
4667
|
var init_vitest = __esm({
|
|
4188
4668
|
"src/review/evidence/vitest.ts"() {
|
|
4189
4669
|
"use strict";
|
|
4190
4670
|
init_paths2();
|
|
4191
4671
|
init_types2();
|
|
4192
|
-
|
|
4193
|
-
schema =
|
|
4194
|
-
success:
|
|
4195
|
-
numTotalTests:
|
|
4196
|
-
numPassedTests:
|
|
4197
|
-
numFailedTests:
|
|
4198
|
-
numPendingTests:
|
|
4199
|
-
numTodoTests:
|
|
4200
|
-
numFailedTestSuites:
|
|
4201
|
-
testResults:
|
|
4202
|
-
name:
|
|
4203
|
-
status:
|
|
4204
|
-
message:
|
|
4205
|
-
assertionResults:
|
|
4206
|
-
fullName:
|
|
4207
|
-
status:
|
|
4208
|
-
failureMessages:
|
|
4209
|
-
location:
|
|
4672
|
+
count3 = z19.number().int().nonnegative();
|
|
4673
|
+
schema = z19.object({
|
|
4674
|
+
success: z19.boolean(),
|
|
4675
|
+
numTotalTests: count3,
|
|
4676
|
+
numPassedTests: count3,
|
|
4677
|
+
numFailedTests: count3,
|
|
4678
|
+
numPendingTests: count3,
|
|
4679
|
+
numTodoTests: count3,
|
|
4680
|
+
numFailedTestSuites: count3,
|
|
4681
|
+
testResults: z19.array(z19.object({
|
|
4682
|
+
name: z19.string().min(1),
|
|
4683
|
+
status: z19.enum(["passed", "failed"]),
|
|
4684
|
+
message: z19.string().optional(),
|
|
4685
|
+
assertionResults: z19.array(z19.object({
|
|
4686
|
+
fullName: z19.string(),
|
|
4687
|
+
status: z19.enum(["passed", "failed", "pending", "skipped", "todo", "disabled"]),
|
|
4688
|
+
failureMessages: z19.array(z19.string()).nullable().optional(),
|
|
4689
|
+
location: z19.object({ line: count3, column: count3 }).nullable().optional()
|
|
4210
4690
|
}))
|
|
4211
4691
|
}))
|
|
4212
4692
|
});
|
|
@@ -4214,7 +4694,7 @@ var init_vitest = __esm({
|
|
|
4214
4694
|
});
|
|
4215
4695
|
|
|
4216
4696
|
// src/review/evidence/sarif.ts
|
|
4217
|
-
import { z as
|
|
4697
|
+
import { z as z20 } from "zod";
|
|
4218
4698
|
function parseSarif(raw, sourceRoot) {
|
|
4219
4699
|
const report = schema2.parse(raw), findings = [], diagnostics = [];
|
|
4220
4700
|
let active = 0, suppressed = 0, absent = 0, unresolved = 0;
|
|
@@ -4305,40 +4785,98 @@ var init_sarif = __esm({
|
|
|
4305
4785
|
"use strict";
|
|
4306
4786
|
init_paths2();
|
|
4307
4787
|
init_types2();
|
|
4308
|
-
index =
|
|
4309
|
-
artifact =
|
|
4310
|
-
message =
|
|
4311
|
-
level =
|
|
4312
|
-
location =
|
|
4313
|
-
schema2 =
|
|
4314
|
-
version:
|
|
4315
|
-
runs:
|
|
4316
|
-
tool:
|
|
4317
|
-
invocations:
|
|
4318
|
-
versionControlProvenance:
|
|
4319
|
-
originalUriBaseIds:
|
|
4320
|
-
artifacts:
|
|
4321
|
-
results:
|
|
4322
|
-
ruleId:
|
|
4788
|
+
index = z20.number().int().nonnegative();
|
|
4789
|
+
artifact = z20.object({ uri: z20.string().optional(), uriBaseId: z20.string().optional(), index: index.optional() });
|
|
4790
|
+
message = z20.object({ text: z20.string().optional(), markdown: z20.string().optional(), id: z20.string().optional(), arguments: z20.array(z20.string()).optional() });
|
|
4791
|
+
level = z20.enum(["error", "warning", "note", "none"]);
|
|
4792
|
+
location = z20.object({ physicalLocation: z20.object({ artifactLocation: artifact.optional(), region: z20.object({ startLine: index.optional(), startColumn: index.optional() }).optional() }).optional() });
|
|
4793
|
+
schema2 = z20.object({
|
|
4794
|
+
version: z20.literal("2.1.0"),
|
|
4795
|
+
runs: z20.array(z20.object({
|
|
4796
|
+
tool: z20.object({ driver: z20.object({ name: z20.string().min(1), rules: z20.array(z20.object({ id: z20.string(), defaultConfiguration: z20.object({ level: level.optional() }).optional(), messageStrings: z20.record(message).optional() })).optional(), globalMessageStrings: z20.record(message).optional() }) }),
|
|
4797
|
+
invocations: z20.array(z20.object({ executionSuccessful: z20.boolean(), commandLine: z20.string().optional(), toolExecutionNotifications: z20.array(z20.object({ level: level.optional(), message })).optional() })).optional(),
|
|
4798
|
+
versionControlProvenance: z20.array(z20.object({ revisionId: z20.string().optional() })).optional(),
|
|
4799
|
+
originalUriBaseIds: z20.record(artifact).optional(),
|
|
4800
|
+
artifacts: z20.array(z20.object({ location: artifact.optional() })).optional(),
|
|
4801
|
+
results: z20.array(z20.object({
|
|
4802
|
+
ruleId: z20.string().optional(),
|
|
4323
4803
|
ruleIndex: index.optional(),
|
|
4324
4804
|
message,
|
|
4325
4805
|
level: level.optional(),
|
|
4326
|
-
kind:
|
|
4327
|
-
baselineState:
|
|
4328
|
-
suppressions:
|
|
4329
|
-
locations:
|
|
4330
|
-
relatedLocations:
|
|
4806
|
+
kind: z20.enum(["fail", "pass", "open", "informational", "notApplicable", "review"]).optional(),
|
|
4807
|
+
baselineState: z20.enum(["new", "unchanged", "updated", "absent"]).optional(),
|
|
4808
|
+
suppressions: z20.array(z20.object({ kind: z20.enum(["inSource", "external"]), status: z20.enum(["accepted", "underReview", "rejected"]).optional() })).nullable().optional(),
|
|
4809
|
+
locations: z20.array(location).optional(),
|
|
4810
|
+
relatedLocations: z20.array(location).optional()
|
|
4331
4811
|
})).optional()
|
|
4332
4812
|
}))
|
|
4333
4813
|
});
|
|
4334
4814
|
}
|
|
4335
4815
|
});
|
|
4336
4816
|
|
|
4817
|
+
// src/review/evidence/check.ts
|
|
4818
|
+
import { z as z21 } from "zod";
|
|
4819
|
+
function parseCheck(raw, sourceRoot) {
|
|
4820
|
+
const report = schema3.parse(raw);
|
|
4821
|
+
const diagnostics = [], findings = [];
|
|
4822
|
+
const counts = { total: report.results.length, passed: 0, failed: 0, skipped: 0 };
|
|
4823
|
+
for (const [index2, result] of report.results.entries()) {
|
|
4824
|
+
counts[result.status]++;
|
|
4825
|
+
const locations = result.locations.flatMap((location2) => {
|
|
4826
|
+
const file = evidencePath(location2.file, sourceRoot);
|
|
4827
|
+
if (!file) {
|
|
4828
|
+
diagnostics.push(`Check location is outside the declared checkout or invalid: ${location2.file}`);
|
|
4829
|
+
return [];
|
|
4830
|
+
}
|
|
4831
|
+
return [{ ...location2, file }];
|
|
4832
|
+
});
|
|
4833
|
+
if (result.status === "failed") findings.push({
|
|
4834
|
+
id: String(index2),
|
|
4835
|
+
...messagePreview([result.name, result.message].filter(Boolean).join("\n")),
|
|
4836
|
+
severity: "error",
|
|
4837
|
+
state: "active",
|
|
4838
|
+
locations
|
|
4839
|
+
});
|
|
4840
|
+
}
|
|
4841
|
+
if (!counts.total) diagnostics.push("No check results were recorded; an empty report is not passing evidence.");
|
|
4842
|
+
if (counts.skipped) diagnostics.push(`${counts.skipped} checks were skipped; verification is incomplete.`);
|
|
4843
|
+
return {
|
|
4844
|
+
outcome: counts.failed ? "failed" : !counts.total ? "unavailable" : !counts.passed ? "skipped" : "passed",
|
|
4845
|
+
counts,
|
|
4846
|
+
findings,
|
|
4847
|
+
incomplete: diagnostics.length > 0,
|
|
4848
|
+
diagnostics,
|
|
4849
|
+
...report.commit ? { reportedCommits: [report.commit] } : {}
|
|
4850
|
+
};
|
|
4851
|
+
}
|
|
4852
|
+
var schema3;
|
|
4853
|
+
var init_check = __esm({
|
|
4854
|
+
"src/review/evidence/check.ts"() {
|
|
4855
|
+
"use strict";
|
|
4856
|
+
init_paths2();
|
|
4857
|
+
init_types2();
|
|
4858
|
+
schema3 = z21.object({
|
|
4859
|
+
version: z21.literal(1),
|
|
4860
|
+
commit: z21.string().regex(/^(?:[a-fA-F0-9]{40}|[a-fA-F0-9]{64})$/).optional(),
|
|
4861
|
+
results: z21.array(z21.object({
|
|
4862
|
+
name: z21.string().min(1).max(1e3),
|
|
4863
|
+
status: z21.enum(["passed", "failed", "skipped"]),
|
|
4864
|
+
message: z21.string().max(1e5).optional(),
|
|
4865
|
+
locations: z21.array(z21.object({
|
|
4866
|
+
file: z21.string().min(1).max(4e3),
|
|
4867
|
+
line: z21.number().int().positive().optional(),
|
|
4868
|
+
column: z21.number().int().positive().optional()
|
|
4869
|
+
})).max(100).default([])
|
|
4870
|
+
})).max(1e5)
|
|
4871
|
+
});
|
|
4872
|
+
}
|
|
4873
|
+
});
|
|
4874
|
+
|
|
4337
4875
|
// src/review/evidence.ts
|
|
4338
|
-
import
|
|
4339
|
-
import { z as
|
|
4876
|
+
import path22 from "path";
|
|
4877
|
+
import { z as z22 } from "zod";
|
|
4340
4878
|
function relativeArtifact(root, file) {
|
|
4341
|
-
const relative =
|
|
4879
|
+
const relative = path22.isAbsolute(file) ? path22.relative(root, file) : file;
|
|
4342
4880
|
const normalized = normalizeRepoPath(relative);
|
|
4343
4881
|
if (!normalized) throw new Error(`Evidence artifact must be inside the repository: ${file}`);
|
|
4344
4882
|
return normalized;
|
|
@@ -4377,7 +4915,7 @@ async function collectReviewEvidence(root, manifests, changedFiles, decisions, d
|
|
|
4377
4915
|
let manifest, raw;
|
|
4378
4916
|
try {
|
|
4379
4917
|
manifest = relativeArtifact(root, supplied);
|
|
4380
|
-
raw =
|
|
4918
|
+
raw = z22.object({ version: z22.literal(1), checks: z22.array(z22.unknown()) }).parse(await readStoreJson(root, manifest));
|
|
4381
4919
|
} catch (error) {
|
|
4382
4920
|
output.diagnostics.push(`${supplied}: ${String(error)}`);
|
|
4383
4921
|
continue;
|
|
@@ -4416,7 +4954,8 @@ async function collectReviewEvidence(root, manifests, changedFiles, decisions, d
|
|
|
4416
4954
|
counts: {},
|
|
4417
4955
|
incomplete: false,
|
|
4418
4956
|
diagnostics: [],
|
|
4419
|
-
truncated: false
|
|
4957
|
+
truncated: false,
|
|
4958
|
+
...check.environment ? { environment: check.environment } : {}
|
|
4420
4959
|
};
|
|
4421
4960
|
output.checks.push(result);
|
|
4422
4961
|
if (check.workingTreeClean !== true) result.diagnostics.push("The check's working tree was dirty or not recorded; its results cannot be attributed to the claimed commit alone.");
|
|
@@ -4429,13 +4968,13 @@ async function collectReviewEvidence(root, manifests, changedFiles, decisions, d
|
|
|
4429
4968
|
}
|
|
4430
4969
|
try {
|
|
4431
4970
|
if (!check.report) throw new Error("Completed check has no report artifact.");
|
|
4432
|
-
if (check.kind === "tests" !== (check.report.format === "vitest-json")) throw new Error("Test checks require vitest-json; analysis checks require sarif.");
|
|
4971
|
+
if (check.report.format !== "mason-check-json" && check.kind === "tests" !== (check.report.format === "vitest-json")) throw new Error("Test checks require vitest-json or mason-check-json; analysis checks require sarif or mason-check-json.");
|
|
4433
4972
|
const file = relativeArtifact(root, check.report.path);
|
|
4434
4973
|
const report = await readStoreJson(root, file);
|
|
4435
4974
|
if (report === null) throw new Error(`Report artifact is missing: ${file}`);
|
|
4436
4975
|
const sourceRoot = check.sourceRoot ?? root;
|
|
4437
|
-
if (!
|
|
4438
|
-
const parsed = check.report.format === "vitest-json" ? parseVitest(report, sourceRoot) : parseSarif(report, sourceRoot);
|
|
4976
|
+
if (!path22.posix.isAbsolute(sourceRoot) && !/^[A-Za-z]:[\\/]/.test(sourceRoot)) throw new Error("sourceRoot must identify the absolute checkout root on the check runner.");
|
|
4977
|
+
const parsed = check.report.format === "vitest-json" ? parseVitest(report, sourceRoot) : check.report.format === "mason-check-json" ? parseCheck(report, sourceRoot) : parseSarif(report, sourceRoot);
|
|
4439
4978
|
result.outcome = parsed.outcome;
|
|
4440
4979
|
result.counts = parsed.counts;
|
|
4441
4980
|
result.incomplete = parsed.incomplete;
|
|
@@ -4455,7 +4994,7 @@ async function collectReviewEvidence(root, manifests, changedFiles, decisions, d
|
|
|
4455
4994
|
result.outcome = "failed";
|
|
4456
4995
|
result.diagnostics.push(`Check command exited ${check.exitCode} despite a report with no active failures.`);
|
|
4457
4996
|
}
|
|
4458
|
-
if (check.
|
|
4997
|
+
if (check.kind === "tests" && pairs === void 0) {
|
|
4459
4998
|
try {
|
|
4460
4999
|
pairs = (await buildTestMap(root)).paired;
|
|
4461
5000
|
} catch (error) {
|
|
@@ -4529,29 +5068,36 @@ var init_evidence2 = __esm({
|
|
|
4529
5068
|
init_provenance();
|
|
4530
5069
|
init_vitest();
|
|
4531
5070
|
init_sarif();
|
|
5071
|
+
init_check();
|
|
4532
5072
|
init_types2();
|
|
4533
|
-
checkSchema2 =
|
|
4534
|
-
id:
|
|
4535
|
-
kind:
|
|
4536
|
-
tool:
|
|
4537
|
-
command:
|
|
4538
|
-
commit:
|
|
4539
|
-
workingTreeClean:
|
|
4540
|
-
source:
|
|
4541
|
-
sourceRoot:
|
|
4542
|
-
status:
|
|
4543
|
-
reason:
|
|
4544
|
-
exitCode:
|
|
4545
|
-
|
|
5073
|
+
checkSchema2 = z22.object({
|
|
5074
|
+
id: z22.string().min(1).max(100),
|
|
5075
|
+
kind: z22.enum(["tests", "static-analysis", "security", "complexity", "duplication", "documentation"]),
|
|
5076
|
+
tool: z22.string().min(1).max(200),
|
|
5077
|
+
command: z22.string().min(1).max(2e3),
|
|
5078
|
+
commit: z22.string().regex(/^(?:[a-fA-F0-9]{40}|[a-fA-F0-9]{64})$/).nullable().optional(),
|
|
5079
|
+
workingTreeClean: z22.boolean().optional(),
|
|
5080
|
+
source: z22.string().max(2e3).optional(),
|
|
5081
|
+
sourceRoot: z22.string().min(1).max(4e3).optional(),
|
|
5082
|
+
status: z22.enum(["completed", "skipped", "unavailable"]).default("completed"),
|
|
5083
|
+
reason: z22.string().min(1).max(2e3).optional(),
|
|
5084
|
+
exitCode: z22.number().int().nullable().optional(),
|
|
5085
|
+
environment: z22.object({
|
|
5086
|
+
toolVersion: z22.string().min(1).max(200),
|
|
5087
|
+
runtime: z22.string().min(1).max(200).optional(),
|
|
5088
|
+
platform: z22.string().min(1).max(200).optional(),
|
|
5089
|
+
configuration: z22.array(z22.string().min(1).max(4e3)).max(100).optional()
|
|
5090
|
+
}).optional(),
|
|
5091
|
+
report: z22.object({ format: z22.enum(["vitest-json", "sarif", "mason-check-json"]), path: z22.string().min(1).max(4e3) }).optional()
|
|
4546
5092
|
});
|
|
4547
5093
|
}
|
|
4548
5094
|
});
|
|
4549
5095
|
|
|
4550
5096
|
// src/review/review.ts
|
|
4551
|
-
import
|
|
4552
|
-
import
|
|
4553
|
-
import { execFile as
|
|
4554
|
-
import { promisify as
|
|
5097
|
+
import fs18 from "fs/promises";
|
|
5098
|
+
import path23 from "path";
|
|
5099
|
+
import { execFile as execFile13 } from "child_process";
|
|
5100
|
+
import { promisify as promisify13 } from "util";
|
|
4555
5101
|
async function resolveMergeBase(resolvedRoot, base, head) {
|
|
4556
5102
|
try {
|
|
4557
5103
|
const { stdout } = await exec10("git", ["merge-base", base, head], {
|
|
@@ -4578,7 +5124,7 @@ function anchorsTouched(record, changedFiles) {
|
|
|
4578
5124
|
return matchingPaths(record.files, changedFiles);
|
|
4579
5125
|
}
|
|
4580
5126
|
async function computeReview(rootDir, base, options = {}) {
|
|
4581
|
-
const resolvedRoot =
|
|
5127
|
+
const resolvedRoot = path23.resolve(rootDir);
|
|
4582
5128
|
const head = await getCurrentGitHash(resolvedRoot);
|
|
4583
5129
|
if (head === "unknown") return null;
|
|
4584
5130
|
const mergeBase = await resolveMergeBase(resolvedRoot, base, head);
|
|
@@ -4628,7 +5174,7 @@ async function computeReview(rootDir, base, options = {}) {
|
|
|
4628
5174
|
analyzed,
|
|
4629
5175
|
async (relPath) => {
|
|
4630
5176
|
try {
|
|
4631
|
-
await
|
|
5177
|
+
await fs18.access(path23.join(resolvedRoot, relPath));
|
|
4632
5178
|
return true;
|
|
4633
5179
|
} catch {
|
|
4634
5180
|
return false;
|
|
@@ -4673,7 +5219,7 @@ var init_review = __esm({
|
|
|
4673
5219
|
init_cochange();
|
|
4674
5220
|
init_evidence2();
|
|
4675
5221
|
init_snapshot();
|
|
4676
|
-
exec10 =
|
|
5222
|
+
exec10 = promisify13(execFile13);
|
|
4677
5223
|
MAX_ANALYZED_FILES = 50;
|
|
4678
5224
|
}
|
|
4679
5225
|
});
|
|
@@ -4682,7 +5228,7 @@ var init_review = __esm({
|
|
|
4682
5228
|
async function auditSummary(root) {
|
|
4683
5229
|
try {
|
|
4684
5230
|
const report = await computeAudit(root);
|
|
4685
|
-
if (!report) return { status: "no-context-files", reason: "No
|
|
5231
|
+
if (!report) return { status: "no-context-files", reason: "No README.md or agent instruction files found to audit." };
|
|
4686
5232
|
if (!report.gitAvailable) return { status: "unavailable", reason: "Audit needs readable Git history to verify documentation claims.", docs: report.docs };
|
|
4687
5233
|
return {
|
|
4688
5234
|
...report,
|