etymd 0.8.0 → 0.9.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 +11 -0
- package/dist/{approve-MYOIDCAM.js → approve-H4UMLKRJ.js} +2 -2
- package/dist/{audit-HO56CZNV.js → audit-22SOGKLY.js} +4 -4
- package/dist/{brief-XI4RCNYS.js → brief-VKNKPZJF.js} +2 -2
- package/dist/{chunk-PRIH2NZF.js → chunk-5P7KZV4W.js} +772 -677
- package/dist/{chunk-72Y2V7VF.js → chunk-E3CVCK5X.js} +1 -1
- package/dist/{chunk-CIRNG736.js → chunk-MUNRU2LF.js} +1 -1
- package/dist/{chunk-KBYEWHYX.js → chunk-ZA7GVR63.js} +1 -1
- package/dist/cli.js +13 -13
- package/dist/{doctor-ZAAEVVB4.js → doctor-ITR74ZUE.js} +4 -4
- package/dist/{fleet-6U6XW72I.js → fleet-CTBMXRHV.js} +4 -4
- package/dist/{gates-N25LGIR2.js → gates-X7WY7IRK.js} +2 -2
- package/dist/index.js +775 -680
- package/dist/{init-SSAJVX52.js → init-ROJ6LQX3.js} +2 -2
- package/dist/{scan-H2IPH4C3.js → scan-2ODW52EK.js} +2 -2
- package/dist/scan-VL4DW5ZT.js +5 -0
- package/package.json +1 -1
- package/dist/scan-LVJOAOUJ.js +0 -5
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
import { measureContext } from './chunk-JSUYV26K.js';
|
|
3
3
|
import { readLedger, reconcileLedger, writeLedger, visibleFindings } from './chunk-OAFYLBVG.js';
|
|
4
4
|
import { DEFAULT_CONFIG, readConfig, CONFIG_FILE } from './chunk-D2RI3CCT.js';
|
|
5
|
-
import { scanProject, expandFileGlobs } from './chunk-
|
|
5
|
+
import { scanProject, expandFileGlobs } from './chunk-MUNRU2LF.js';
|
|
6
6
|
import { ETYMD_DIR, writeCachedFacts, readBaseline, deriveProfile, baselineCarriesMachinePath, BASELINE_FILE } from './chunk-C7LBUFNU.js';
|
|
7
7
|
import { PACK_VERSION } from './chunk-6DUDIVIC.js';
|
|
8
|
-
import { pathExists, readJson,
|
|
8
|
+
import { pathExists, readJson, readText, isDirectory, matchesAnyGlob, git, normalizeRelPath, isCiEnvironment, isExecutable } from './chunk-IV3FYVTS.js';
|
|
9
9
|
import path from 'node:path';
|
|
10
10
|
import YAML from 'yaml';
|
|
11
11
|
import { promises } from 'node:fs';
|
|
@@ -667,786 +667,881 @@ var gateIntegrityLens = {
|
|
|
667
667
|
};
|
|
668
668
|
}
|
|
669
669
|
};
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
}
|
|
689
|
-
const rulesDir = path.join(root, ".cursor", "rules");
|
|
690
|
-
if (await isDirectory(rulesDir)) {
|
|
691
|
-
try {
|
|
692
|
-
for (const entry of await promises.readdir(rulesDir)) {
|
|
693
|
-
if (entry.endsWith(".md") || entry.endsWith(".mdc"))
|
|
694
|
-
await add(path.join(".cursor/rules", entry));
|
|
695
|
-
}
|
|
696
|
-
} catch {
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
const skillsDir = path.join(root, ".claude", "skills");
|
|
700
|
-
if (await isDirectory(skillsDir)) {
|
|
701
|
-
try {
|
|
702
|
-
for (const entry of await promises.readdir(skillsDir)) {
|
|
703
|
-
const skill = path.join(".claude/skills", entry, "SKILL.md");
|
|
704
|
-
await add(skill);
|
|
705
|
-
}
|
|
706
|
-
} catch {
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
const detected = new Set(files.map((f) => f.path));
|
|
710
|
-
const included = [];
|
|
711
|
-
for (const rel of await expandFileGlobs(root, scope?.include ?? [])) {
|
|
712
|
-
if (detected.has(rel)) continue;
|
|
713
|
-
const before = files.length;
|
|
714
|
-
await add(rel);
|
|
715
|
-
if (files.length > before) included.push(rel);
|
|
716
|
-
}
|
|
717
|
-
const exclude = scope?.exclude ?? [];
|
|
718
|
-
if (!exclude.length) return { files, excluded: [], included };
|
|
719
|
-
const kept = [];
|
|
720
|
-
const excluded = [];
|
|
721
|
-
for (const file of files) {
|
|
722
|
-
if (matchesAnyGlob(file.path, exclude)) excluded.push(file.path);
|
|
723
|
-
else kept.push(file);
|
|
724
|
-
}
|
|
725
|
-
return { files: kept, excluded, included };
|
|
726
|
-
}
|
|
727
|
-
function extractCodeTokens(text) {
|
|
728
|
-
const tokens = [];
|
|
729
|
-
for (const m of text.matchAll(/`([^`\n]+)`/g)) tokens.push(m[1].trim());
|
|
730
|
-
for (const block of text.matchAll(/```[a-z]*\n([\s\S]*?)```/g)) {
|
|
731
|
-
for (const line of block[1].split("\n")) {
|
|
732
|
-
const trimmed = line.trim();
|
|
733
|
-
if (trimmed && !trimmed.startsWith("#")) tokens.push(trimmed);
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
return tokens;
|
|
737
|
-
}
|
|
738
|
-
var PM_BUILTINS = /* @__PURE__ */ new Set([
|
|
739
|
-
"install",
|
|
740
|
-
"i",
|
|
741
|
-
"add",
|
|
742
|
-
"remove",
|
|
743
|
-
"rm",
|
|
744
|
-
"up",
|
|
745
|
-
"update",
|
|
746
|
-
"upgrade",
|
|
747
|
-
"dlx",
|
|
748
|
-
"exec",
|
|
749
|
-
"create",
|
|
750
|
-
"init",
|
|
751
|
-
"link",
|
|
752
|
-
"unlink",
|
|
753
|
-
"publish",
|
|
754
|
-
"pack",
|
|
755
|
-
"audit",
|
|
756
|
-
"outdated",
|
|
757
|
-
"why",
|
|
758
|
-
"list",
|
|
759
|
-
"ls",
|
|
760
|
-
"view",
|
|
761
|
-
"info",
|
|
762
|
-
"config",
|
|
763
|
-
"store",
|
|
764
|
-
"import",
|
|
765
|
-
"rebuild",
|
|
766
|
-
"prune",
|
|
767
|
-
"setup",
|
|
768
|
-
"env",
|
|
769
|
-
"bin",
|
|
770
|
-
"root",
|
|
771
|
-
"licenses",
|
|
772
|
-
"patch",
|
|
773
|
-
"approve-builds",
|
|
774
|
-
"workspaces",
|
|
775
|
-
"workspace",
|
|
776
|
-
"cache",
|
|
777
|
-
"version",
|
|
778
|
-
"help"
|
|
779
|
-
]);
|
|
780
|
-
function extractCommandClaims(text) {
|
|
781
|
-
const scripts = /* @__PURE__ */ new Map();
|
|
782
|
-
let filteredSkipped = 0;
|
|
783
|
-
for (const token of extractCodeTokens(text)) {
|
|
784
|
-
for (const m of token.matchAll(
|
|
785
|
-
/(?:^|&&\s*|\|\|\s*|;\s*|\|\s*|\$\s+|\(\s*)(pnpm|yarn|npm|bun)\s+(?:(run)\s+)?(-{0,2}[A-Za-z0-9:._@/[\]-]+)/g
|
|
786
|
-
)) {
|
|
787
|
-
const pm = m[1];
|
|
788
|
-
const ranExplicit = Boolean(m[2]);
|
|
789
|
-
const arg = m[3];
|
|
790
|
-
if (arg.startsWith("-")) {
|
|
791
|
-
filteredSkipped += 1;
|
|
792
|
-
continue;
|
|
793
|
-
}
|
|
794
|
-
if (pm === "npm" && !ranExplicit && arg !== "test" && arg !== "start") continue;
|
|
795
|
-
if ((pm === "bun" || pm === "yarn" || pm === "pnpm") && !ranExplicit && PM_BUILTINS.has(arg))
|
|
796
|
-
continue;
|
|
797
|
-
if (ranExplicit && PM_BUILTINS.has(arg)) continue;
|
|
798
|
-
scripts.set(arg, token);
|
|
799
|
-
}
|
|
670
|
+
var LENS_ID3 = "state-freshness";
|
|
671
|
+
var DECISIONS_FORMAT_MARKER = "<!-- decisions-format: 1 -->";
|
|
672
|
+
var KNOWN_FORMAT_VERSION = 1;
|
|
673
|
+
var MARKER_RE = /<!--\s*decisions-format:\s*(\d+)([^>]*?)-->/;
|
|
674
|
+
var FIELD_NAME_RE = /^[A-Za-z0-9 _-]+$/;
|
|
675
|
+
var BUILT_IN_FIELDS = /* @__PURE__ */ new Set(["scope"]);
|
|
676
|
+
var MS_PER_DAY = 864e5;
|
|
677
|
+
function parseDecisionsFormat(text) {
|
|
678
|
+
const m = MARKER_RE.exec(text);
|
|
679
|
+
if (!m) return null;
|
|
680
|
+
const problems = [];
|
|
681
|
+
const fields = [];
|
|
682
|
+
const offset = m.index ?? 0;
|
|
683
|
+
const version = Number(m[1]);
|
|
684
|
+
if (version !== KNOWN_FORMAT_VERSION) {
|
|
685
|
+
problems.push(
|
|
686
|
+
`declares decisions-format version ${version}; this etymd understands version ${KNOWN_FORMAT_VERSION} \u2014 checked as version ${KNOWN_FORMAT_VERSION}.`
|
|
687
|
+
);
|
|
800
688
|
}
|
|
801
|
-
|
|
802
|
-
}
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
var CREATION_CONTEXT_RE = /\b(?:creat(?:e|es|ed|ing)|generat(?:e|es|ed|ing)|scaffold(?:s|ed|ing)?|quarantin(?:e|es|ed|ing)|(?:writ(?:e|es|ten|ing)|output(?:s|ted)?|emit(?:s|ted|ting)?|sav(?:e|es|ed|ing)|mov(?:e|es|ed|ing)|copy|copi(?:es|ed))\s+(?:it\s+|them\s+)?(?:to|into)|new\s+(?:file|directory|folder)|will\s+(?:be\s+)?(?:created|generated|written)|add(?:s|ed|ing)?\s+(?:a|the)\s+new)\b/i;
|
|
808
|
-
var PLACEHOLDER_SEGMENTS = /* @__PURE__ */ new Set(["placeholder", "foo", "bar", "baz", "qux"]);
|
|
809
|
-
var PLACEHOLDER_PREFIX_RE = /^(?:my|your)-/i;
|
|
810
|
-
function isPlaceholderClaim(token) {
|
|
811
|
-
return token.split("/").some((seg) => PLACEHOLDER_PREFIX_RE.test(seg) || PLACEHOLDER_SEGMENTS.has(seg.toLowerCase()));
|
|
812
|
-
}
|
|
813
|
-
function claimContext(text, index) {
|
|
814
|
-
const start = text.lastIndexOf("\n", index) + 1;
|
|
815
|
-
const endRaw = text.indexOf("\n", index);
|
|
816
|
-
const end = endRaw === -1 ? text.length : endRaw;
|
|
817
|
-
const line = text.slice(start, end);
|
|
818
|
-
if (!/^\s*(?:[-*+]|\d+[.)]|\|)/.test(line)) return line;
|
|
819
|
-
let cursor = start;
|
|
820
|
-
while (cursor > 0) {
|
|
821
|
-
const prevEnd = cursor - 1;
|
|
822
|
-
const prevStart = text.lastIndexOf("\n", prevEnd - 1) + 1;
|
|
823
|
-
const prev = text.slice(prevStart, prevEnd);
|
|
824
|
-
cursor = prevStart;
|
|
825
|
-
if (!prev.trim()) continue;
|
|
826
|
-
if (/^\s*(?:[-*+]|\d+[.)]|\|)/.test(prev)) continue;
|
|
827
|
-
return `${prev}
|
|
828
|
-
${line}`;
|
|
689
|
+
const attrs = (m[2] ?? "").trim();
|
|
690
|
+
if (!attrs) return { fields, offset, problems };
|
|
691
|
+
const declared = /^fields=(.*)$/.exec(attrs);
|
|
692
|
+
if (!declared) {
|
|
693
|
+
problems.push(`marker attribute \`${attrs}\` is not understood \u2014 ignored (only \`fields=\`).`);
|
|
694
|
+
return { fields, offset, problems };
|
|
829
695
|
}
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
if (token.startsWith("/") || token.startsWith("~") || token.startsWith("@") || token.startsWith("$"))
|
|
839
|
-
continue;
|
|
840
|
-
if (token.includes("://") || token.startsWith("www.")) continue;
|
|
841
|
-
if (/[*?{}<>|]/.test(token)) continue;
|
|
842
|
-
if (token.includes("@")) continue;
|
|
843
|
-
if (!PATH_TOKEN_RE.test(token)) continue;
|
|
844
|
-
if (token.split("/").some((seg) => seg.startsWith("$"))) continue;
|
|
845
|
-
const isDirClaim = token.endsWith("/");
|
|
846
|
-
const ext = token.toLowerCase().match(/\.([a-z0-9]{1,8})$/)?.[1];
|
|
847
|
-
if (!isDirClaim && !(ext && KNOWN_EXTENSIONS.has(ext))) continue;
|
|
848
|
-
const claim = token.replace(/\/$/, "");
|
|
849
|
-
if (isPlaceholderClaim(claim)) {
|
|
850
|
-
placeholder.add(claim);
|
|
696
|
+
const seen = new Set(BUILT_IN_FIELDS);
|
|
697
|
+
for (const raw of declared[1].split(",")) {
|
|
698
|
+
const name = raw.trim();
|
|
699
|
+
if (!name) continue;
|
|
700
|
+
if (!FIELD_NAME_RE.test(name)) {
|
|
701
|
+
problems.push(
|
|
702
|
+
`declared field \`${name}\` is not a usable field name (letters, digits, spaces, \`-\`, \`_\`) \u2014 not checked.`
|
|
703
|
+
);
|
|
851
704
|
continue;
|
|
852
705
|
}
|
|
853
|
-
const
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
const prospective = [];
|
|
858
|
-
for (const [claim, only] of prospectiveOnly) {
|
|
859
|
-
if (only) prospective.push(claim);
|
|
860
|
-
else paths.push(claim);
|
|
706
|
+
const key = name.toLowerCase();
|
|
707
|
+
if (seen.has(key)) continue;
|
|
708
|
+
seen.add(key);
|
|
709
|
+
fields.push(name);
|
|
861
710
|
}
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
function packageManagerUsage(text) {
|
|
865
|
-
const counts = /* @__PURE__ */ new Map();
|
|
866
|
-
for (const token of extractCodeTokens(text)) {
|
|
867
|
-
for (const m of token.matchAll(/\b(pnpm|yarn|npm|bun)\s+(?:run\s+)?[A-Za-z-]/g)) {
|
|
868
|
-
const pm = m[1];
|
|
869
|
-
counts.set(pm, (counts.get(pm) ?? 0) + 1);
|
|
870
|
-
}
|
|
711
|
+
if (fields.length === 0 && problems.length === 0) {
|
|
712
|
+
problems.push("marker declares `fields=` with no field names \u2014 no extra fields checked.");
|
|
871
713
|
}
|
|
872
|
-
return
|
|
714
|
+
return { fields, offset, problems };
|
|
873
715
|
}
|
|
874
|
-
|
|
875
|
-
"
|
|
876
|
-
"CLAUDE.md",
|
|
877
|
-
"PROJECT_CONTEXT.md",
|
|
878
|
-
"DECISIONS.md",
|
|
879
|
-
"GEMINI.md"
|
|
880
|
-
];
|
|
881
|
-
function extractDocRefs(text) {
|
|
882
|
-
return KNOWN_DOC_REFS.filter((name) => text.includes(name));
|
|
716
|
+
function hasField(block, name) {
|
|
717
|
+
return new RegExp(`${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}[\\s*]*:`).test(block);
|
|
883
718
|
}
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
719
|
+
function parseDecisionEntries(text) {
|
|
720
|
+
const headings = [...text.matchAll(/^## .*$/gm)];
|
|
721
|
+
const entries = [];
|
|
722
|
+
for (let i = 0; i < headings.length; i++) {
|
|
723
|
+
const h = headings[i];
|
|
724
|
+
const m = /^## (D-(\d+))\b/.exec(h[0]);
|
|
725
|
+
if (!m) continue;
|
|
726
|
+
const offset = h.index ?? 0;
|
|
727
|
+
const start = offset + h[0].length;
|
|
728
|
+
const end = i + 1 < headings.length ? headings[i + 1].index : void 0;
|
|
729
|
+
entries.push({ id: m[1], num: Number(m[2]), block: text.slice(start, end), offset });
|
|
730
|
+
}
|
|
731
|
+
return entries;
|
|
890
732
|
}
|
|
891
|
-
function
|
|
892
|
-
const
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
733
|
+
function checkIdSequence(file, entries) {
|
|
734
|
+
const findings = [];
|
|
735
|
+
const nextFree = Math.max(0, ...entries.map((e) => e.num)) + 1;
|
|
736
|
+
const seen = /* @__PURE__ */ new Map();
|
|
737
|
+
const duplicated = /* @__PURE__ */ new Set();
|
|
738
|
+
let prev;
|
|
739
|
+
for (const entry of entries) {
|
|
740
|
+
if (seen.has(entry.num)) {
|
|
741
|
+
if (!duplicated.has(entry.num)) {
|
|
742
|
+
duplicated.add(entry.num);
|
|
743
|
+
findings.push({
|
|
744
|
+
id: `${LENS_ID3}/duplicate-id:${file}:${entry.id}`,
|
|
745
|
+
lens: LENS_ID3,
|
|
746
|
+
tier: "gap",
|
|
747
|
+
claim: `${file} carries more than one ${entry.id} entry`,
|
|
748
|
+
evidence: [`${file}: ${entry.id} appears twice`],
|
|
749
|
+
why: "Two decisions under one id cannot be cited, superseded, or dismissed unambiguously \u2014 append races collide exactly here.",
|
|
750
|
+
action: `Rename the later entry to D-${String(nextFree).padStart(3, "0")} (the next free id).`,
|
|
751
|
+
effort: "S",
|
|
752
|
+
confidence: "high"
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
} else {
|
|
756
|
+
seen.set(entry.num, entry);
|
|
757
|
+
if (prev && entry.num < prev.num) {
|
|
758
|
+
findings.push({
|
|
759
|
+
id: `${LENS_ID3}/id-order:${file}:${entry.id}`,
|
|
760
|
+
lens: LENS_ID3,
|
|
761
|
+
tier: "gap",
|
|
762
|
+
claim: `${file} lists ${entry.id} after ${prev.id} \u2014 ids out of append order`,
|
|
763
|
+
evidence: [`${file}: ${prev.id} precedes ${entry.id}`],
|
|
764
|
+
why: "An append-only record reads in id order; out-of-order ids make the newest decision hard to find and the next id hard to pick.",
|
|
765
|
+
action: `Rename the out-of-order entry into sequence (next free id: D-${String(nextFree).padStart(3, "0")}).`,
|
|
904
766
|
effort: "S",
|
|
905
767
|
confidence: "high"
|
|
906
|
-
})
|
|
907
|
-
|
|
768
|
+
});
|
|
769
|
+
}
|
|
770
|
+
prev = entry;
|
|
908
771
|
}
|
|
909
772
|
}
|
|
910
|
-
return
|
|
773
|
+
return findings;
|
|
911
774
|
}
|
|
912
|
-
function
|
|
913
|
-
const
|
|
914
|
-
const
|
|
915
|
-
|
|
916
|
-
const
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
775
|
+
function checkFormatFields(file, entries, today, declaredFields, markerOffset) {
|
|
776
|
+
const findings = [];
|
|
777
|
+
for (const entry of entries) {
|
|
778
|
+
const bound = entry.offset >= markerOffset;
|
|
779
|
+
for (const field of bound ? declaredFields : []) {
|
|
780
|
+
if (hasField(entry.block, field)) continue;
|
|
781
|
+
findings.push({
|
|
782
|
+
id: `${LENS_ID3}/field-missing:${file}:${entry.id}:${field}`,
|
|
783
|
+
lens: LENS_ID3,
|
|
784
|
+
tier: "gap",
|
|
785
|
+
claim: `${file} ${entry.id} has no ${field}: field`,
|
|
786
|
+
evidence: [`${file}: ${entry.id}`, `${file} marker declares required field \`${field}\``],
|
|
787
|
+
why: "The file declares this field required on every entry after the marker; whatever reads the record for it finds nothing here.",
|
|
788
|
+
action: `Add a ${field}: line to ${entry.id}.`,
|
|
789
|
+
effort: "S",
|
|
790
|
+
confidence: "high"
|
|
791
|
+
});
|
|
792
|
+
}
|
|
793
|
+
if (bound && !/Scope[\s*]*:/.test(entry.block)) {
|
|
794
|
+
findings.push({
|
|
795
|
+
id: `${LENS_ID3}/scope-missing:${file}:${entry.id}`,
|
|
796
|
+
lens: LENS_ID3,
|
|
797
|
+
tier: "gap",
|
|
798
|
+
claim: `${file} ${entry.id} has no Scope: field`,
|
|
799
|
+
evidence: [`${file}: ${entry.id}`],
|
|
800
|
+
why: "A decision without a scope binds nobody \u2014 a reader cannot tell whether it covers the project they are working in.",
|
|
801
|
+
action: "Add a Scope: line naming what the decision binds.",
|
|
802
|
+
effort: "S",
|
|
803
|
+
confidence: "high"
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
const revisit = /Revisit[\s*]*:[\s*]*(\d{4}-\d{2}-\d{2})/.exec(entry.block);
|
|
807
|
+
if (revisit && revisit[1] < today) {
|
|
808
|
+
findings.push({
|
|
809
|
+
id: `${LENS_ID3}/revisit-due:${file}:${entry.id}`,
|
|
810
|
+
lens: LENS_ID3,
|
|
811
|
+
tier: "gap",
|
|
812
|
+
claim: `${file} ${entry.id} was due for revisit on ${revisit[1]}`,
|
|
813
|
+
evidence: [`${file}: ${entry.id} Revisit: ${revisit[1]}`],
|
|
814
|
+
why: "Review debt is due \u2014 a Revisit date is a promise to re-evaluate, and a past one silently hardens into policy.",
|
|
815
|
+
action: "Re-evaluate the decision: supersede it or move the Revisit date.",
|
|
816
|
+
effort: "S",
|
|
817
|
+
confidence: "high"
|
|
818
|
+
});
|
|
930
819
|
}
|
|
931
820
|
}
|
|
932
|
-
return
|
|
933
|
-
}
|
|
934
|
-
function compareLayout(baseline, fresh) {
|
|
935
|
-
const now = new Set(fresh.tree.dirs.map((d) => d.name));
|
|
936
|
-
return baseline.tree.dirs.filter((d) => !now.has(d.name)).map(
|
|
937
|
-
(d) => finding2({
|
|
938
|
-
id: `${LENS_ID3}/dir-gone-${d.name}`,
|
|
939
|
-
tier: "gap",
|
|
940
|
-
claim: `Top-level \`${d.name}/\` from the baseline no longer exists \u2014 the repo map may be stale`,
|
|
941
|
-
evidence: [`${d.name}/`],
|
|
942
|
-
why: "A stale map sends agents (and people) to paths that are gone.",
|
|
943
|
-
action: "Update the repo map and refresh the baseline.",
|
|
944
|
-
effort: "S",
|
|
945
|
-
confidence: "medium"
|
|
946
|
-
})
|
|
947
|
-
);
|
|
821
|
+
return findings;
|
|
948
822
|
}
|
|
949
|
-
var
|
|
823
|
+
var stateFreshnessLens = {
|
|
950
824
|
id: LENS_ID3,
|
|
951
825
|
version: "1",
|
|
952
|
-
title: "
|
|
826
|
+
title: "State freshness",
|
|
953
827
|
kind: "truth",
|
|
954
828
|
async run(ctx) {
|
|
829
|
+
const budgets = ctx.config?.config.state ?? DEFAULT_CONFIG.state;
|
|
955
830
|
const findings = [];
|
|
956
|
-
const disclosures = [];
|
|
957
|
-
const
|
|
958
|
-
const
|
|
959
|
-
|
|
960
|
-
const
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
included: includedExtra
|
|
964
|
-
} = await listInstructionFiles(root, facts, config.instructions);
|
|
965
|
-
if (!files.length) {
|
|
966
|
-
findings.push(
|
|
967
|
-
finding2({
|
|
968
|
-
id: `${LENS_ID3}/no-contract`,
|
|
969
|
-
tier: "gap",
|
|
970
|
-
claim: "No agent instruction files exist (AGENTS.md or equivalents)",
|
|
971
|
-
evidence: ["AGENTS.md (missing)"],
|
|
972
|
-
why: "Every agent in this repo works from generic priors instead of the project's rules.",
|
|
973
|
-
action: "Run `etymd init` to scaffold one.",
|
|
974
|
-
effort: "M",
|
|
975
|
-
confidence: "high"
|
|
976
|
-
})
|
|
977
|
-
);
|
|
978
|
-
}
|
|
979
|
-
const knownScripts = new Set(Object.keys(facts.commands.raw));
|
|
980
|
-
for (const pkg of facts.packages) {
|
|
981
|
-
const pkgJson = await readJson(
|
|
982
|
-
path.join(root, pkg.dir, "package.json")
|
|
983
|
-
);
|
|
984
|
-
for (const key of Object.keys(pkgJson?.scripts ?? {})) knownScripts.add(key);
|
|
831
|
+
const disclosures = [...ctx.config?.problems ?? []];
|
|
832
|
+
const outOfScope = [];
|
|
833
|
+
const today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
834
|
+
const stateArtifacts = ctx.facts.artifacts.filter((a) => a.kind === "state" && a.exists);
|
|
835
|
+
const decisionArtifacts = ctx.facts.artifacts.filter((a) => a.kind === "decisions" && a.exists);
|
|
836
|
+
if (stateArtifacts.length === 0 && decisionArtifacts.length === 0) {
|
|
837
|
+
disclosures.push("No state or decisions artifacts detected \u2014 nothing to check.");
|
|
985
838
|
}
|
|
986
|
-
const
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
}
|
|
993
|
-
return false;
|
|
994
|
-
};
|
|
995
|
-
const binResolves = async (name) => {
|
|
996
|
-
const bases = [root, ...facts.packages.map((p) => path.join(root, p.dir))];
|
|
997
|
-
for (const base of bases) {
|
|
998
|
-
if (await pathExists(path.join(base, "node_modules", ".bin", name))) return true;
|
|
999
|
-
}
|
|
1000
|
-
return false;
|
|
1001
|
-
};
|
|
1002
|
-
const nodeModulesInstalled = await pathExists(path.join(root, "node_modules"));
|
|
1003
|
-
let totalFilteredSkipped = 0;
|
|
1004
|
-
let binaryResolved = 0;
|
|
1005
|
-
let unverifiableCommands = 0;
|
|
1006
|
-
let gitignoredSkipped = 0;
|
|
1007
|
-
let prospectiveSkipped = 0;
|
|
1008
|
-
let placeholderSkipped = 0;
|
|
1009
|
-
for (const file of files) {
|
|
1010
|
-
const { scripts: claimed, filteredSkipped } = extractCommandClaims(file.text);
|
|
1011
|
-
totalFilteredSkipped += filteredSkipped;
|
|
1012
|
-
for (const [script, raw] of claimed) {
|
|
1013
|
-
if (knownScripts.has(script)) continue;
|
|
1014
|
-
if (await binResolves(script)) {
|
|
1015
|
-
binaryResolved += 1;
|
|
1016
|
-
continue;
|
|
1017
|
-
}
|
|
1018
|
-
if (!nodeModulesInstalled) {
|
|
1019
|
-
unverifiableCommands += 1;
|
|
1020
|
-
continue;
|
|
1021
|
-
}
|
|
1022
|
-
findings.push(
|
|
1023
|
-
finding2({
|
|
1024
|
-
id: `${LENS_ID3}/stale-command:${file.path}:${script}`,
|
|
1025
|
-
tier: "risk",
|
|
1026
|
-
claim: `${file.path} tells agents to run \`${script}\` \u2014 no such script exists`,
|
|
1027
|
-
evidence: [`${file.path}: \`${raw}\``, "package.json scripts (root + workspaces)"],
|
|
1028
|
-
why: "An agent following this instruction runs a command that fails \u2014 or silently skips the check it was meant to run.",
|
|
1029
|
-
action: "Update the instruction to the current script name (or restore the script).",
|
|
1030
|
-
effort: "S",
|
|
1031
|
-
confidence: "high"
|
|
1032
|
-
})
|
|
1033
|
-
);
|
|
1034
|
-
}
|
|
1035
|
-
const { paths, prospective, placeholder } = extractPathClaims(file.text);
|
|
1036
|
-
prospectiveSkipped += prospective.length;
|
|
1037
|
-
placeholderSkipped += placeholder.length;
|
|
1038
|
-
const missing = [];
|
|
1039
|
-
for (const claim of paths) {
|
|
1040
|
-
if (!await pathResolves(claim)) missing.push(claim);
|
|
839
|
+
const freshness = ctx.facts.freshness;
|
|
840
|
+
if (!freshness) {
|
|
841
|
+
disclosures.push("Scan carried no freshness facts \u2014 staleness unchecked.");
|
|
842
|
+
} else {
|
|
843
|
+
for (const u of freshness.unverifiable) {
|
|
844
|
+
disclosures.push(`Freshness of ${u.path} is unverifiable (${u.reason}) \u2014 not flagged.`);
|
|
1041
845
|
}
|
|
1042
|
-
const
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
if (gitignored.has(claim)) {
|
|
1047
|
-
gitignoredSkipped += 1;
|
|
1048
|
-
continue;
|
|
1049
|
-
}
|
|
1050
|
-
if (pathFindings >= MAX_PATH_FINDINGS_PER_FILE) {
|
|
846
|
+
for (const a of stateArtifacts) {
|
|
847
|
+
const fact = freshness.artifacts.find((f) => f.artifactId === a.id);
|
|
848
|
+
if (!fact || !freshness.repoLastCommit) continue;
|
|
849
|
+
if (fact.dirty) {
|
|
1051
850
|
disclosures.push(
|
|
1052
|
-
`${
|
|
851
|
+
`${a.path} has uncommitted changes \u2014 modified since its last commit; treated fresh-now, not flagged.`
|
|
1053
852
|
);
|
|
1054
|
-
|
|
853
|
+
continue;
|
|
1055
854
|
}
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
id: `${LENS_ID3}/stale-path:${file.path}:${claim}`,
|
|
1060
|
-
tier: "gap",
|
|
1061
|
-
claim: `${file.path} references \`${claim}\` \u2014 it does not exist in the repo`,
|
|
1062
|
-
evidence: [file.path, `missing: ${claim}`],
|
|
1063
|
-
why: "Agents navigate by these references; a dead path wastes a lookup and erodes trust in the rest of the file.",
|
|
1064
|
-
action: "Fix or remove the reference.",
|
|
1065
|
-
effort: "S",
|
|
1066
|
-
confidence: "medium"
|
|
1067
|
-
})
|
|
855
|
+
if (!fact.commitsSince) continue;
|
|
856
|
+
const gapDays = Math.floor(
|
|
857
|
+
(Date.parse(freshness.repoLastCommit) - Date.parse(fact.lastCommit)) / MS_PER_DAY
|
|
1068
858
|
);
|
|
859
|
+
if (gapDays <= budgets.staleAfterDays) continue;
|
|
860
|
+
const escalated = gapDays > budgets.staleAfterDays * 3;
|
|
861
|
+
findings.push({
|
|
862
|
+
id: `${LENS_ID3}/stale-state:${a.path}`,
|
|
863
|
+
lens: LENS_ID3,
|
|
864
|
+
tier: escalated ? "risk" : "gap",
|
|
865
|
+
claim: `${a.path} trails the repo by ${gapDays} days of commit traffic \u2014 it says "now" but the repo moved on`,
|
|
866
|
+
evidence: [
|
|
867
|
+
`${a.path} last commit: ${fact.lastCommit}`,
|
|
868
|
+
`repo last commit: ${freshness.repoLastCommit}`
|
|
869
|
+
],
|
|
870
|
+
why: escalated ? `Over three times the ${budgets.staleAfterDays}-day threshold while commits kept landing \u2014 every session starts from a picture of the project that is no longer true.` : `A state doc more than ${budgets.staleAfterDays} days behind continued commit traffic misleads every session that loads it.`,
|
|
871
|
+
action: "Refresh the state doc (or record why it is still current).",
|
|
872
|
+
effort: "S",
|
|
873
|
+
confidence: "high"
|
|
874
|
+
});
|
|
1069
875
|
}
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
876
|
+
}
|
|
877
|
+
for (const a of stateArtifacts) {
|
|
878
|
+
const text = await readText(path.join(ctx.root, a.path));
|
|
879
|
+
if (text === null) {
|
|
880
|
+
disclosures.push(`${a.path} could not be read \u2014 unexamined, not clean.`);
|
|
881
|
+
outOfScope.push(a.path);
|
|
882
|
+
continue;
|
|
883
|
+
}
|
|
884
|
+
if (text.length > budgets.maxChars) {
|
|
885
|
+
findings.push({
|
|
886
|
+
id: `${LENS_ID3}/state-over-budget:${a.path}`,
|
|
887
|
+
lens: LENS_ID3,
|
|
888
|
+
tier: "gap",
|
|
889
|
+
claim: `${a.path} is ${text.length} chars \u2014 over the ${budgets.maxChars}-char state budget`,
|
|
890
|
+
evidence: [`${a.path}: ${text.length} chars`],
|
|
891
|
+
why: "Session-injection hooks truncate state around 10,000 chars \u2014 an over-budget state doc gets cut mid-sentence, and every session pays its full weight before the task begins.",
|
|
892
|
+
action: "Trim to budget; move overflow into decisions/docs and keep a pointer.",
|
|
893
|
+
effort: "M",
|
|
894
|
+
confidence: "high"
|
|
895
|
+
});
|
|
1089
896
|
}
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
claim: `${file.path} references ${ref} \u2014 no such file exists`,
|
|
1097
|
-
evidence: [file.path, `missing: ${ref}`],
|
|
1098
|
-
why: "The pointer chain agents follow breaks at a file they can never read.",
|
|
1099
|
-
action: `Create ${ref} or remove the reference.`,
|
|
1100
|
-
effort: "S",
|
|
1101
|
-
confidence: "high"
|
|
1102
|
-
})
|
|
897
|
+
}
|
|
898
|
+
for (const a of decisionArtifacts) {
|
|
899
|
+
const text = await readText(path.join(ctx.root, a.path));
|
|
900
|
+
if (text === null) {
|
|
901
|
+
disclosures.push(
|
|
902
|
+
`${a.path} recognized as a decisions convention (directory) \u2014 age-exempt; per-entry format checks apply only to marker-carrying decisions files.`
|
|
1103
903
|
);
|
|
904
|
+
continue;
|
|
1104
905
|
}
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
...compareArtifacts(ctx.baseline.facts, facts),
|
|
1110
|
-
...compareLayout(ctx.baseline.facts, facts)
|
|
1111
|
-
);
|
|
1112
|
-
if (baselineCarriesMachinePath(ctx.baseline)) {
|
|
906
|
+
const entries = parseDecisionEntries(text);
|
|
907
|
+
findings.push(...checkIdSequence(a.path, entries));
|
|
908
|
+
const format = parseDecisionsFormat(text);
|
|
909
|
+
if (!format) {
|
|
1113
910
|
disclosures.push(
|
|
1114
|
-
`${
|
|
911
|
+
`${a.path} carries no \`${DECISIONS_FORMAT_MARKER}\` marker \u2014 format checks skipped (forward-only, never retroactive); id-sequence checks still ran.`
|
|
1115
912
|
);
|
|
913
|
+
outOfScope.push(a.path);
|
|
914
|
+
continue;
|
|
1116
915
|
}
|
|
1117
|
-
|
|
916
|
+
for (const problem of format.problems) disclosures.push(`${a.path}: ${problem}`);
|
|
917
|
+
const exempt = entries.filter((e) => e.offset < format.offset);
|
|
918
|
+
if (format.fields.length > 0) {
|
|
1118
919
|
disclosures.push(
|
|
1119
|
-
|
|
920
|
+
`${a.path} declares required entry fields: ${format.fields.join(", ")} \u2014 checked on every entry at or after the marker (etymd attaches no meaning to the names).`
|
|
1120
921
|
);
|
|
1121
922
|
}
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
disclosures.push(
|
|
1129
|
-
`${binaryResolved} command claim(s) are installed binaries (node_modules/.bin), not package scripts \u2014 treated as true.`
|
|
1130
|
-
);
|
|
1131
|
-
}
|
|
1132
|
-
if (unverifiableCommands) {
|
|
1133
|
-
disclosures.push(
|
|
1134
|
-
`node_modules is not installed \u2014 ${unverifiableCommands} command claim(s) matching no package script could not be checked against installed binaries; skipped, not flagged.`
|
|
1135
|
-
);
|
|
1136
|
-
}
|
|
1137
|
-
if (gitignoredSkipped) {
|
|
1138
|
-
disclosures.push(
|
|
1139
|
-
`${gitignoredSkipped} missing path claim(s) are gitignored (machine-local, e.g. .env) \u2014 existence is not verifiable from the repo; skipped, not flagged.`
|
|
1140
|
-
);
|
|
1141
|
-
}
|
|
1142
|
-
if (prospectiveSkipped) {
|
|
1143
|
-
disclosures.push(
|
|
1144
|
-
`${prospectiveSkipped} path claim(s) sit in create-this prose (the file instructs generating them) \u2014 forward-looking, not stale; skipped, not flagged.`
|
|
1145
|
-
);
|
|
1146
|
-
}
|
|
1147
|
-
if (placeholderSkipped) {
|
|
1148
|
-
disclosures.push(
|
|
1149
|
-
`${placeholderSkipped} path claim(s) are naming stand-ins (e.g. \`my-custom-skill\`) rather than real references; skipped, not flagged.`
|
|
1150
|
-
);
|
|
1151
|
-
}
|
|
1152
|
-
if (excluded.length) {
|
|
1153
|
-
const shown = excluded.slice(0, 5).join(", ");
|
|
1154
|
-
disclosures.push(
|
|
1155
|
-
`${excluded.length} instruction file(s) excluded by ${CONFIG_FILE} and NOT audited: ${shown}${excluded.length > 5 ? `, +${excluded.length - 5} more` : ""}.`
|
|
1156
|
-
);
|
|
1157
|
-
}
|
|
1158
|
-
if (includedExtra.length) {
|
|
1159
|
-
disclosures.push(
|
|
1160
|
-
`${includedExtra.length} extra instruction file(s) audited via ${CONFIG_FILE} \`instructions.include\`: ${includedExtra.slice(0, 5).join(", ")}${includedExtra.length > 5 ? `, +${includedExtra.length - 5} more` : ""}.`
|
|
1161
|
-
);
|
|
923
|
+
if (exempt.length > 0) {
|
|
924
|
+
disclosures.push(
|
|
925
|
+
`${a.path}: ${exempt.length} entr${exempt.length === 1 ? "y" : "ies"} precede the format marker (${exempt[0]?.id}\u2026${exempt[exempt.length - 1]?.id}) \u2014 field presence not checked there (forward-only from the marker's position).`
|
|
926
|
+
);
|
|
927
|
+
}
|
|
928
|
+
findings.push(...checkFormatFields(a.path, entries, today, format.fields, format.offset));
|
|
1162
929
|
}
|
|
1163
930
|
disclosures.push(
|
|
1164
|
-
`
|
|
931
|
+
`Thresholds: staleAfterDays ${budgets.staleAfterDays} (3x escalates to risk), state budget ${budgets.maxChars} chars (${budgets.staleAfterDays === DEFAULT_CONFIG.state.staleAfterDays && budgets.maxChars === DEFAULT_CONFIG.state.maxChars ? `defaults \u2014 override under \`state\` in ${CONFIG_FILE}` : `set in ${CONFIG_FILE}`}). Decisions artifacts are exempt from age \u2014 old decisions are history, not defects.`
|
|
1165
932
|
);
|
|
1166
933
|
return {
|
|
1167
934
|
lens: LENS_ID3,
|
|
1168
935
|
version: "1",
|
|
1169
|
-
title: "
|
|
936
|
+
title: "State freshness",
|
|
1170
937
|
kind: "truth",
|
|
1171
938
|
status: "ran",
|
|
1172
939
|
disclosures,
|
|
1173
940
|
findings,
|
|
1174
|
-
outOfScope:
|
|
941
|
+
...outOfScope.length ? { outOfScope } : {}
|
|
1175
942
|
};
|
|
1176
943
|
}
|
|
1177
944
|
};
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
);
|
|
945
|
+
async function listInstructionFiles(root, facts, scope) {
|
|
946
|
+
const files = [];
|
|
947
|
+
const add = async (rel) => {
|
|
948
|
+
const text = await readText(path.join(root, rel));
|
|
949
|
+
if (text !== null) files.push({ path: normalizeRelPath(rel), text });
|
|
950
|
+
};
|
|
951
|
+
const singleFileArtifacts = [
|
|
952
|
+
"agents",
|
|
953
|
+
"claude",
|
|
954
|
+
"gemini",
|
|
955
|
+
"copilot",
|
|
956
|
+
"cursorrules",
|
|
957
|
+
"cline",
|
|
958
|
+
"windsurf"
|
|
959
|
+
];
|
|
960
|
+
for (const id of singleFileArtifacts) {
|
|
961
|
+
const artifact = facts.artifacts.find((a) => a.id === id);
|
|
962
|
+
if (artifact?.exists) await add(artifact.path);
|
|
1196
963
|
}
|
|
1197
|
-
const
|
|
1198
|
-
if (
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
964
|
+
const rulesDir = path.join(root, ".cursor", "rules");
|
|
965
|
+
if (await isDirectory(rulesDir)) {
|
|
966
|
+
try {
|
|
967
|
+
for (const entry of await promises.readdir(rulesDir)) {
|
|
968
|
+
if (entry.endsWith(".md") || entry.endsWith(".mdc"))
|
|
969
|
+
await add(path.join(".cursor/rules", entry));
|
|
970
|
+
}
|
|
971
|
+
} catch {
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
const skillsDir = path.join(root, ".claude", "skills");
|
|
975
|
+
if (await isDirectory(skillsDir)) {
|
|
976
|
+
try {
|
|
977
|
+
for (const entry of await promises.readdir(skillsDir)) {
|
|
978
|
+
const skill = path.join(".claude/skills", entry, "SKILL.md");
|
|
979
|
+
await add(skill);
|
|
980
|
+
}
|
|
981
|
+
} catch {
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
const detected = new Set(files.map((f) => f.path));
|
|
985
|
+
const included = [];
|
|
986
|
+
for (const rel of await expandFileGlobs(root, scope?.include ?? [])) {
|
|
987
|
+
if (detected.has(rel)) continue;
|
|
988
|
+
const before = files.length;
|
|
989
|
+
await add(rel);
|
|
990
|
+
if (files.length > before) included.push(rel);
|
|
991
|
+
}
|
|
992
|
+
const exclude = scope?.exclude ?? [];
|
|
993
|
+
if (!exclude.length) return { files, excluded: [], included };
|
|
994
|
+
const kept = [];
|
|
995
|
+
const excluded = [];
|
|
996
|
+
for (const file of files) {
|
|
997
|
+
if (matchesAnyGlob(file.path, exclude)) excluded.push(file.path);
|
|
998
|
+
else kept.push(file);
|
|
999
|
+
}
|
|
1000
|
+
return { files: kept, excluded, included };
|
|
1001
|
+
}
|
|
1002
|
+
async function listStateDocuments(root, facts) {
|
|
1003
|
+
const docs = [];
|
|
1004
|
+
for (const artifact of facts.artifacts) {
|
|
1005
|
+
if (artifact.kind !== "state" || !artifact.exists) continue;
|
|
1006
|
+
const text = await readText(path.join(root, artifact.path));
|
|
1007
|
+
if (text !== null) docs.push({ path: normalizeRelPath(artifact.path), text });
|
|
1008
|
+
}
|
|
1009
|
+
return docs;
|
|
1010
|
+
}
|
|
1011
|
+
function extractCodeTokens(text) {
|
|
1012
|
+
const tokens = [];
|
|
1013
|
+
for (const m of text.matchAll(/`([^`\n]+)`/g)) tokens.push(m[1].trim());
|
|
1014
|
+
for (const block of text.matchAll(/```[a-z]*\n([\s\S]*?)```/g)) {
|
|
1015
|
+
for (const line of block[1].split("\n")) {
|
|
1016
|
+
const trimmed = line.trim();
|
|
1017
|
+
if (trimmed && !trimmed.startsWith("#")) tokens.push(trimmed);
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
return tokens;
|
|
1021
|
+
}
|
|
1022
|
+
var PM_BUILTINS = /* @__PURE__ */ new Set([
|
|
1023
|
+
"install",
|
|
1024
|
+
"i",
|
|
1025
|
+
"add",
|
|
1026
|
+
"remove",
|
|
1027
|
+
"rm",
|
|
1028
|
+
"up",
|
|
1029
|
+
"update",
|
|
1030
|
+
"upgrade",
|
|
1031
|
+
"dlx",
|
|
1032
|
+
"exec",
|
|
1033
|
+
"create",
|
|
1034
|
+
"init",
|
|
1035
|
+
"link",
|
|
1036
|
+
"unlink",
|
|
1037
|
+
"publish",
|
|
1038
|
+
"pack",
|
|
1039
|
+
"audit",
|
|
1040
|
+
"outdated",
|
|
1041
|
+
"why",
|
|
1042
|
+
"list",
|
|
1043
|
+
"ls",
|
|
1044
|
+
"view",
|
|
1045
|
+
"info",
|
|
1046
|
+
"config",
|
|
1047
|
+
"store",
|
|
1048
|
+
"import",
|
|
1049
|
+
"rebuild",
|
|
1050
|
+
"prune",
|
|
1051
|
+
"setup",
|
|
1052
|
+
"env",
|
|
1053
|
+
"bin",
|
|
1054
|
+
"root",
|
|
1055
|
+
"licenses",
|
|
1056
|
+
"patch",
|
|
1057
|
+
"approve-builds",
|
|
1058
|
+
"workspaces",
|
|
1059
|
+
"workspace",
|
|
1060
|
+
"cache",
|
|
1061
|
+
"version",
|
|
1062
|
+
"help"
|
|
1063
|
+
]);
|
|
1064
|
+
function extractCommandClaims(text) {
|
|
1065
|
+
const scripts = /* @__PURE__ */ new Map();
|
|
1066
|
+
let filteredSkipped = 0;
|
|
1067
|
+
for (const token of extractCodeTokens(text)) {
|
|
1068
|
+
for (const m of token.matchAll(
|
|
1069
|
+
/(?:^|&&\s*|\|\|\s*|;\s*|\|\s*|\$\s+|\(\s*)(pnpm|yarn|npm|bun)\s+(?:(run)\s+)?(-{0,2}[A-Za-z0-9:._@/[\]-]+)/g
|
|
1070
|
+
)) {
|
|
1071
|
+
const pm = m[1];
|
|
1072
|
+
const ranExplicit = Boolean(m[2]);
|
|
1073
|
+
const arg = m[3];
|
|
1074
|
+
if (arg.startsWith("-")) {
|
|
1075
|
+
filteredSkipped += 1;
|
|
1076
|
+
continue;
|
|
1077
|
+
}
|
|
1078
|
+
if (pm === "npm" && !ranExplicit && arg !== "test" && arg !== "start") continue;
|
|
1079
|
+
if ((pm === "bun" || pm === "yarn" || pm === "pnpm") && !ranExplicit && PM_BUILTINS.has(arg))
|
|
1080
|
+
continue;
|
|
1081
|
+
if (ranExplicit && PM_BUILTINS.has(arg)) continue;
|
|
1082
|
+
scripts.set(arg, token);
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
return { scripts, filteredSkipped };
|
|
1086
|
+
}
|
|
1087
|
+
var PATH_TOKEN_RE = /^[A-Za-z0-9_.-]+(\/[A-Za-z0-9_.$-]+)+\/?$/;
|
|
1088
|
+
var KNOWN_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
1089
|
+
..."ts tsx cts mts js jsx cjs mjs json jsonc json5 md mdx mdc yml yaml toml ini cfg conf env sh bash zsh fish ps1 bat cmd css scss sass less html htm xml svg sql prisma graphql gql proto py rb rs go java kt kts swift c h cc cpp hpp cs php vue svelte astro txt log lock csv tsv png jpg jpeg gif webp ico avif woff woff2 ttf otf wasm map pem key crt tf tfvars example sample local snap ejs hbs pug".split(" ")
|
|
1090
|
+
]);
|
|
1091
|
+
var CREATION_CONTEXT_RE = /\b(?:creat(?:e|es|ed|ing)|generat(?:e|es|ed|ing)|scaffold(?:s|ed|ing)?|quarantin(?:e|es|ed|ing)|(?:writ(?:e|es|ten|ing)|output(?:s|ted)?|emit(?:s|ted|ting)?|sav(?:e|es|ed|ing)|mov(?:e|es|ed|ing)|copy|copi(?:es|ed))\s+(?:it\s+|them\s+)?(?:to|into)|new\s+(?:file|directory|folder)|will\s+(?:be\s+)?(?:created|generated|written)|add(?:s|ed|ing)?\s+(?:a|the)\s+new)\b/i;
|
|
1092
|
+
var PLACEHOLDER_SEGMENTS = /* @__PURE__ */ new Set(["placeholder", "foo", "bar", "baz", "qux"]);
|
|
1093
|
+
var PLACEHOLDER_PREFIX_RE = /^(?:my|your)-/i;
|
|
1094
|
+
function isPlaceholderClaim(token) {
|
|
1095
|
+
return token.split("/").some((seg) => PLACEHOLDER_PREFIX_RE.test(seg) || PLACEHOLDER_SEGMENTS.has(seg.toLowerCase()));
|
|
1096
|
+
}
|
|
1097
|
+
function claimContext(text, index) {
|
|
1098
|
+
const start = text.lastIndexOf("\n", index) + 1;
|
|
1099
|
+
const endRaw = text.indexOf("\n", index);
|
|
1100
|
+
const end = endRaw === -1 ? text.length : endRaw;
|
|
1101
|
+
const line = text.slice(start, end);
|
|
1102
|
+
if (!/^\s*(?:[-*+]|\d+[.)]|\|)/.test(line)) return line;
|
|
1103
|
+
let cursor = start;
|
|
1104
|
+
while (cursor > 0) {
|
|
1105
|
+
const prevEnd = cursor - 1;
|
|
1106
|
+
const prevStart = text.lastIndexOf("\n", prevEnd - 1) + 1;
|
|
1107
|
+
const prev = text.slice(prevStart, prevEnd);
|
|
1108
|
+
cursor = prevStart;
|
|
1109
|
+
if (!prev.trim()) continue;
|
|
1110
|
+
if (/^\s*(?:[-*+]|\d+[.)]|\|)/.test(prev)) continue;
|
|
1111
|
+
return `${prev}
|
|
1112
|
+
${line}`;
|
|
1203
1113
|
}
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1114
|
+
return line;
|
|
1115
|
+
}
|
|
1116
|
+
function extractPathClaims(text) {
|
|
1117
|
+
const prospectiveOnly = /* @__PURE__ */ new Map();
|
|
1118
|
+
const placeholder = /* @__PURE__ */ new Set();
|
|
1119
|
+
for (const m of text.matchAll(/`([^`\n]+)`/g)) {
|
|
1120
|
+
const token = m[1].trim();
|
|
1121
|
+
if (token.includes(" ") || token.length > 120) continue;
|
|
1122
|
+
if (token.startsWith("/") || token.startsWith("~") || token.startsWith("@") || token.startsWith("$"))
|
|
1123
|
+
continue;
|
|
1124
|
+
if (token.includes("://") || token.startsWith("www.")) continue;
|
|
1125
|
+
if (/[*?{}<>|]/.test(token)) continue;
|
|
1126
|
+
if (token.includes("@")) continue;
|
|
1127
|
+
if (!PATH_TOKEN_RE.test(token)) continue;
|
|
1128
|
+
if (token.split("/").some((seg) => seg.startsWith("$"))) continue;
|
|
1129
|
+
const isDirClaim = token.endsWith("/");
|
|
1130
|
+
const ext = token.toLowerCase().match(/\.([a-z0-9]{1,8})$/)?.[1];
|
|
1131
|
+
if (!isDirClaim && !(ext && KNOWN_EXTENSIONS.has(ext))) continue;
|
|
1132
|
+
const claim = token.replace(/\/$/, "");
|
|
1133
|
+
if (isPlaceholderClaim(claim)) {
|
|
1134
|
+
placeholder.add(claim);
|
|
1212
1135
|
continue;
|
|
1213
1136
|
}
|
|
1214
|
-
const
|
|
1215
|
-
|
|
1216
|
-
seen.add(key);
|
|
1217
|
-
fields.push(name);
|
|
1137
|
+
const prospective2 = CREATION_CONTEXT_RE.test(claimContext(text, m.index ?? 0));
|
|
1138
|
+
prospectiveOnly.set(claim, (prospectiveOnly.get(claim) ?? true) && prospective2);
|
|
1218
1139
|
}
|
|
1219
|
-
|
|
1220
|
-
|
|
1140
|
+
const paths = [];
|
|
1141
|
+
const prospective = [];
|
|
1142
|
+
for (const [claim, only] of prospectiveOnly) {
|
|
1143
|
+
if (only) prospective.push(claim);
|
|
1144
|
+
else paths.push(claim);
|
|
1221
1145
|
}
|
|
1222
|
-
return {
|
|
1146
|
+
return { paths, prospective, placeholder: [...placeholder] };
|
|
1223
1147
|
}
|
|
1224
|
-
|
|
1225
|
-
|
|
1148
|
+
var LOCAL_REF_LEADINS = new Set(
|
|
1149
|
+
"decision decisions entry entries ruling rulings record records ledger id ids item items see per in of on at by to as is was are were the a an and or but not with under over from via vs than after before since between through against latest newest earliest only also still now supersedes superseded superseding amends amended extends extended cites cited citing adds added adding wrote written writes locked locks closed closes opened opens resolves resolved reopened recorded number numbers".split(" ")
|
|
1150
|
+
);
|
|
1151
|
+
function extractDecisionRefs(text) {
|
|
1152
|
+
const byNum = /* @__PURE__ */ new Map();
|
|
1153
|
+
for (const m of text.matchAll(/\bD-(\d{1,4})\b/g)) {
|
|
1154
|
+
const index = m.index ?? 0;
|
|
1155
|
+
if (index > 0 && /[-/_.]/.test(text[index - 1])) continue;
|
|
1156
|
+
const before = text.slice(Math.max(0, index - 48), index);
|
|
1157
|
+
const lead = /([A-Za-z][A-Za-z0-9'’-]*)[ \t]+$/.exec(before)?.[1];
|
|
1158
|
+
const local = !lead || LOCAL_REF_LEADINS.has(lead.toLowerCase());
|
|
1159
|
+
const num = Number(m[1]);
|
|
1160
|
+
const seen = byNum.get(num);
|
|
1161
|
+
if (!seen) byNum.set(num, { asWritten: m[0], local });
|
|
1162
|
+
else seen.local = seen.local || local;
|
|
1163
|
+
}
|
|
1164
|
+
const refs = /* @__PURE__ */ new Map();
|
|
1165
|
+
let qualifiedSkipped = 0;
|
|
1166
|
+
for (const [num, ref] of byNum) {
|
|
1167
|
+
if (ref.local) refs.set(num, ref.asWritten);
|
|
1168
|
+
else qualifiedSkipped += 1;
|
|
1169
|
+
}
|
|
1170
|
+
return { refs, qualifiedSkipped };
|
|
1226
1171
|
}
|
|
1227
|
-
function
|
|
1228
|
-
const
|
|
1229
|
-
const
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
const offset = h.index ?? 0;
|
|
1235
|
-
const start = offset + h[0].length;
|
|
1236
|
-
const end = i + 1 < headings.length ? headings[i + 1].index : void 0;
|
|
1237
|
-
entries.push({ id: m[1], num: Number(m[2]), block: text.slice(start, end), offset });
|
|
1172
|
+
function packageManagerUsage(text) {
|
|
1173
|
+
const counts = /* @__PURE__ */ new Map();
|
|
1174
|
+
for (const token of extractCodeTokens(text)) {
|
|
1175
|
+
for (const m of token.matchAll(/\b(pnpm|yarn|npm|bun)\s+(?:run\s+)?[A-Za-z-]/g)) {
|
|
1176
|
+
const pm = m[1];
|
|
1177
|
+
counts.set(pm, (counts.get(pm) ?? 0) + 1);
|
|
1178
|
+
}
|
|
1238
1179
|
}
|
|
1239
|
-
return
|
|
1180
|
+
return counts;
|
|
1240
1181
|
}
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1182
|
+
var KNOWN_DOC_REFS = [
|
|
1183
|
+
"AGENTS.md",
|
|
1184
|
+
"CLAUDE.md",
|
|
1185
|
+
"PROJECT_CONTEXT.md",
|
|
1186
|
+
"DECISIONS.md",
|
|
1187
|
+
"GEMINI.md"
|
|
1188
|
+
];
|
|
1189
|
+
function extractDocRefs(text) {
|
|
1190
|
+
return KNOWN_DOC_REFS.filter((name) => text.includes(name));
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
// src/lenses/instruction-truth/lens.ts
|
|
1194
|
+
var LENS_ID4 = "instruction-truth";
|
|
1195
|
+
var MAX_PATH_FINDINGS_PER_FILE = 15;
|
|
1196
|
+
function finding2(partial) {
|
|
1197
|
+
return { lens: LENS_ID4, ...partial };
|
|
1198
|
+
}
|
|
1199
|
+
function compareCommands(baseline, fresh) {
|
|
1200
|
+
const out = [];
|
|
1201
|
+
for (const role of ["test", "lint", "typecheck", "format", "formatCheck", "build"]) {
|
|
1202
|
+
const before = baseline.commands[role];
|
|
1203
|
+
if (before && !(before in fresh.commands.raw)) {
|
|
1204
|
+
out.push(
|
|
1205
|
+
finding2({
|
|
1206
|
+
id: `${LENS_ID4}/command-gone-${role}`,
|
|
1207
|
+
tier: "risk",
|
|
1208
|
+
claim: `Documented ${role} command \`${before}\` no longer exists in package.json`,
|
|
1209
|
+
evidence: ["package.json"],
|
|
1210
|
+
why: "Every doc, hook, and agent instruction naming it now fails or silently skips a check.",
|
|
1211
|
+
action: "Re-point the contract/hooks at the renamed script, then refresh the baseline.",
|
|
1259
1212
|
effort: "S",
|
|
1260
1213
|
confidence: "high"
|
|
1261
|
-
})
|
|
1262
|
-
|
|
1263
|
-
}
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1214
|
+
})
|
|
1215
|
+
);
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
return out;
|
|
1219
|
+
}
|
|
1220
|
+
function compareArtifacts(baseline, fresh) {
|
|
1221
|
+
const out = [];
|
|
1222
|
+
const freshById = new Map(fresh.artifacts.map((a) => [a.id, a]));
|
|
1223
|
+
for (const a of baseline.artifacts) {
|
|
1224
|
+
const now = freshById.get(a.id);
|
|
1225
|
+
if (a.exists && now && !now.exists) {
|
|
1226
|
+
out.push(
|
|
1227
|
+
finding2({
|
|
1228
|
+
id: `${LENS_ID4}/artifact-gone-${a.id}`,
|
|
1269
1229
|
tier: "gap",
|
|
1270
|
-
claim: `${
|
|
1271
|
-
evidence: [
|
|
1272
|
-
why: "
|
|
1273
|
-
action:
|
|
1230
|
+
claim: `${a.label} was present at baseline but is now missing`,
|
|
1231
|
+
evidence: [a.path],
|
|
1232
|
+
why: "Agents and docs still assume it exists; instructions referring to it now mislead.",
|
|
1233
|
+
action: "Restore it or update the contract and refresh the baseline.",
|
|
1274
1234
|
effort: "S",
|
|
1275
1235
|
confidence: "high"
|
|
1276
|
-
})
|
|
1277
|
-
|
|
1278
|
-
prev = entry;
|
|
1236
|
+
})
|
|
1237
|
+
);
|
|
1279
1238
|
}
|
|
1280
1239
|
}
|
|
1281
|
-
return
|
|
1240
|
+
return out;
|
|
1282
1241
|
}
|
|
1283
|
-
function
|
|
1284
|
-
const
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
effort: "S",
|
|
1298
|
-
confidence: "high"
|
|
1299
|
-
});
|
|
1300
|
-
}
|
|
1301
|
-
if (bound && !/Scope[\s*]*:/.test(entry.block)) {
|
|
1302
|
-
findings.push({
|
|
1303
|
-
id: `${LENS_ID4}/scope-missing:${file}:${entry.id}`,
|
|
1304
|
-
lens: LENS_ID4,
|
|
1305
|
-
tier: "gap",
|
|
1306
|
-
claim: `${file} ${entry.id} has no Scope: field`,
|
|
1307
|
-
evidence: [`${file}: ${entry.id}`],
|
|
1308
|
-
why: "A decision without a scope binds nobody \u2014 a reader cannot tell whether it covers the project they are working in.",
|
|
1309
|
-
action: "Add a Scope: line naming what the decision binds.",
|
|
1310
|
-
effort: "S",
|
|
1311
|
-
confidence: "high"
|
|
1312
|
-
});
|
|
1313
|
-
}
|
|
1314
|
-
const revisit = /Revisit[\s*]*:[\s*]*(\d{4}-\d{2}-\d{2})/.exec(entry.block);
|
|
1315
|
-
if (revisit && revisit[1] < today) {
|
|
1316
|
-
findings.push({
|
|
1317
|
-
id: `${LENS_ID4}/revisit-due:${file}:${entry.id}`,
|
|
1318
|
-
lens: LENS_ID4,
|
|
1319
|
-
tier: "gap",
|
|
1320
|
-
claim: `${file} ${entry.id} was due for revisit on ${revisit[1]}`,
|
|
1321
|
-
evidence: [`${file}: ${entry.id} Revisit: ${revisit[1]}`],
|
|
1322
|
-
why: "Review debt is due \u2014 a Revisit date is a promise to re-evaluate, and a past one silently hardens into policy.",
|
|
1323
|
-
action: "Re-evaluate the decision: supersede it or move the Revisit date.",
|
|
1324
|
-
effort: "S",
|
|
1325
|
-
confidence: "high"
|
|
1326
|
-
});
|
|
1327
|
-
}
|
|
1328
|
-
}
|
|
1329
|
-
return findings;
|
|
1242
|
+
function compareLayout(baseline, fresh) {
|
|
1243
|
+
const now = new Set(fresh.tree.dirs.map((d) => d.name));
|
|
1244
|
+
return baseline.tree.dirs.filter((d) => !now.has(d.name)).map(
|
|
1245
|
+
(d) => finding2({
|
|
1246
|
+
id: `${LENS_ID4}/dir-gone-${d.name}`,
|
|
1247
|
+
tier: "gap",
|
|
1248
|
+
claim: `Top-level \`${d.name}/\` from the baseline no longer exists \u2014 the repo map may be stale`,
|
|
1249
|
+
evidence: [`${d.name}/`],
|
|
1250
|
+
why: "A stale map sends agents (and people) to paths that are gone.",
|
|
1251
|
+
action: "Update the repo map and refresh the baseline.",
|
|
1252
|
+
effort: "S",
|
|
1253
|
+
confidence: "medium"
|
|
1254
|
+
})
|
|
1255
|
+
);
|
|
1330
1256
|
}
|
|
1331
|
-
var
|
|
1257
|
+
var instructionTruthLens = {
|
|
1332
1258
|
id: LENS_ID4,
|
|
1333
1259
|
version: "1",
|
|
1334
|
-
title: "
|
|
1260
|
+
title: "Instruction truth",
|
|
1335
1261
|
kind: "truth",
|
|
1336
1262
|
async run(ctx) {
|
|
1337
|
-
const budgets = ctx.config?.config.state ?? DEFAULT_CONFIG.state;
|
|
1338
1263
|
const findings = [];
|
|
1339
|
-
const disclosures = [
|
|
1340
|
-
const
|
|
1341
|
-
const
|
|
1342
|
-
|
|
1343
|
-
const
|
|
1344
|
-
|
|
1345
|
-
|
|
1264
|
+
const disclosures = [];
|
|
1265
|
+
const { facts, root } = ctx;
|
|
1266
|
+
const config = ctx.config?.config ?? DEFAULT_CONFIG;
|
|
1267
|
+
disclosures.push(...ctx.config?.problems ?? []);
|
|
1268
|
+
const {
|
|
1269
|
+
files,
|
|
1270
|
+
excluded,
|
|
1271
|
+
included: includedExtra
|
|
1272
|
+
} = await listInstructionFiles(root, facts, config.instructions);
|
|
1273
|
+
if (!files.length) {
|
|
1274
|
+
findings.push(
|
|
1275
|
+
finding2({
|
|
1276
|
+
id: `${LENS_ID4}/no-contract`,
|
|
1277
|
+
tier: "gap",
|
|
1278
|
+
claim: "No agent instruction files exist (AGENTS.md or equivalents)",
|
|
1279
|
+
evidence: ["AGENTS.md (missing)"],
|
|
1280
|
+
why: "Every agent in this repo works from generic priors instead of the project's rules.",
|
|
1281
|
+
action: "Run `etymd init` to scaffold one.",
|
|
1282
|
+
effort: "M",
|
|
1283
|
+
confidence: "high"
|
|
1284
|
+
})
|
|
1285
|
+
);
|
|
1346
1286
|
}
|
|
1347
|
-
const
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1287
|
+
const knownScripts = new Set(Object.keys(facts.commands.raw));
|
|
1288
|
+
for (const pkg of facts.packages) {
|
|
1289
|
+
const pkgJson = await readJson(
|
|
1290
|
+
path.join(root, pkg.dir, "package.json")
|
|
1291
|
+
);
|
|
1292
|
+
for (const key of Object.keys(pkgJson?.scripts ?? {})) knownScripts.add(key);
|
|
1293
|
+
}
|
|
1294
|
+
const pathResolves = async (claim) => {
|
|
1295
|
+
const bases = [root, ...facts.packages.map((p) => path.join(root, p.dir))];
|
|
1296
|
+
for (const base of bases) {
|
|
1297
|
+
if (await pathExists(path.join(base, claim))) return true;
|
|
1298
|
+
if (await pathExists(path.join(base, "src", claim))) return true;
|
|
1299
|
+
if (await pathExists(path.join(base, "scripts", claim))) return true;
|
|
1353
1300
|
}
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1301
|
+
return false;
|
|
1302
|
+
};
|
|
1303
|
+
const binResolves = async (name) => {
|
|
1304
|
+
const bases = [root, ...facts.packages.map((p) => path.join(root, p.dir))];
|
|
1305
|
+
for (const base of bases) {
|
|
1306
|
+
if (await pathExists(path.join(base, "node_modules", ".bin", name))) return true;
|
|
1307
|
+
}
|
|
1308
|
+
return false;
|
|
1309
|
+
};
|
|
1310
|
+
const nodeModulesInstalled = await pathExists(path.join(root, "node_modules"));
|
|
1311
|
+
const manifestExists = await pathExists(path.join(root, "package.json")) || facts.packages.length > 0;
|
|
1312
|
+
let totalFilteredSkipped = 0;
|
|
1313
|
+
let binaryResolved = 0;
|
|
1314
|
+
let unverifiableCommands = 0;
|
|
1315
|
+
let gitignoredSkipped = 0;
|
|
1316
|
+
let prospectiveSkipped = 0;
|
|
1317
|
+
let placeholderSkipped = 0;
|
|
1318
|
+
const auditClaims = async (file) => {
|
|
1319
|
+
const { scripts: claimed, filteredSkipped } = extractCommandClaims(file.text);
|
|
1320
|
+
totalFilteredSkipped += filteredSkipped;
|
|
1321
|
+
for (const [script, raw] of claimed) {
|
|
1322
|
+
if (knownScripts.has(script)) continue;
|
|
1323
|
+
if (await binResolves(script)) {
|
|
1324
|
+
binaryResolved += 1;
|
|
1325
|
+
continue;
|
|
1326
|
+
}
|
|
1327
|
+
if (!nodeModulesInstalled && manifestExists) {
|
|
1328
|
+
unverifiableCommands += 1;
|
|
1329
|
+
continue;
|
|
1330
|
+
}
|
|
1331
|
+
findings.push(
|
|
1332
|
+
finding2({
|
|
1333
|
+
id: `${LENS_ID4}/stale-command:${file.path}:${script}`,
|
|
1334
|
+
tier: "risk",
|
|
1335
|
+
claim: `${file.path} tells agents to run \`${script}\` \u2014 no such script exists`,
|
|
1336
|
+
evidence: [`${file.path}: \`${raw}\``, "package.json scripts (root + workspaces)"],
|
|
1337
|
+
why: "An agent following this instruction runs a command that fails \u2014 or silently skips the check it was meant to run.",
|
|
1338
|
+
action: "Update the instruction to the current script name (or restore the script).",
|
|
1339
|
+
effort: "S",
|
|
1340
|
+
confidence: "high"
|
|
1341
|
+
})
|
|
1342
|
+
);
|
|
1343
|
+
}
|
|
1344
|
+
const { paths, prospective, placeholder } = extractPathClaims(file.text);
|
|
1345
|
+
prospectiveSkipped += prospective.length;
|
|
1346
|
+
placeholderSkipped += placeholder.length;
|
|
1347
|
+
const missing = [];
|
|
1348
|
+
for (const claim of paths) {
|
|
1349
|
+
if (!await pathResolves(claim)) missing.push(claim);
|
|
1350
|
+
}
|
|
1351
|
+
const ignoredOut = missing.length ? await git(root, ["check-ignore", ...missing]) : null;
|
|
1352
|
+
const gitignored = new Set((ignoredOut ?? "").split("\n").filter(Boolean));
|
|
1353
|
+
let pathFindings = 0;
|
|
1354
|
+
for (const claim of missing) {
|
|
1355
|
+
if (gitignored.has(claim)) {
|
|
1356
|
+
gitignoredSkipped += 1;
|
|
1357
|
+
continue;
|
|
1358
|
+
}
|
|
1359
|
+
if (pathFindings >= MAX_PATH_FINDINGS_PER_FILE) {
|
|
1358
1360
|
disclosures.push(
|
|
1359
|
-
`${
|
|
1361
|
+
`${file.path}: more than ${MAX_PATH_FINDINGS_PER_FILE} missing-path claims \u2014 truncated.`
|
|
1360
1362
|
);
|
|
1361
|
-
|
|
1363
|
+
break;
|
|
1362
1364
|
}
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
(
|
|
1365
|
+
pathFindings += 1;
|
|
1366
|
+
findings.push(
|
|
1367
|
+
finding2({
|
|
1368
|
+
id: `${LENS_ID4}/stale-path:${file.path}:${claim}`,
|
|
1369
|
+
tier: "gap",
|
|
1370
|
+
claim: `${file.path} references \`${claim}\` \u2014 it does not exist in the repo`,
|
|
1371
|
+
evidence: [file.path, `missing: ${claim}`],
|
|
1372
|
+
why: "Agents navigate by these references; a dead path wastes a lookup and erodes trust in the rest of the file.",
|
|
1373
|
+
action: "Fix or remove the reference.",
|
|
1374
|
+
effort: "S",
|
|
1375
|
+
confidence: "medium"
|
|
1376
|
+
})
|
|
1366
1377
|
);
|
|
1367
|
-
if (gapDays <= budgets.staleAfterDays) continue;
|
|
1368
|
-
const escalated = gapDays > budgets.staleAfterDays * 3;
|
|
1369
|
-
findings.push({
|
|
1370
|
-
id: `${LENS_ID4}/stale-state:${a.path}`,
|
|
1371
|
-
lens: LENS_ID4,
|
|
1372
|
-
tier: escalated ? "risk" : "gap",
|
|
1373
|
-
claim: `${a.path} trails the repo by ${gapDays} days of commit traffic \u2014 it says "now" but the repo moved on`,
|
|
1374
|
-
evidence: [
|
|
1375
|
-
`${a.path} last commit: ${fact.lastCommit}`,
|
|
1376
|
-
`repo last commit: ${freshness.repoLastCommit}`
|
|
1377
|
-
],
|
|
1378
|
-
why: escalated ? `Over three times the ${budgets.staleAfterDays}-day threshold while commits kept landing \u2014 every session starts from a picture of the project that is no longer true.` : `A state doc more than ${budgets.staleAfterDays} days behind continued commit traffic misleads every session that loads it.`,
|
|
1379
|
-
action: "Refresh the state doc (or record why it is still current).",
|
|
1380
|
-
effort: "S",
|
|
1381
|
-
confidence: "high"
|
|
1382
|
-
});
|
|
1383
1378
|
}
|
|
1384
|
-
}
|
|
1385
|
-
for (const
|
|
1386
|
-
|
|
1387
|
-
if (
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1379
|
+
};
|
|
1380
|
+
for (const file of files) {
|
|
1381
|
+
await auditClaims(file);
|
|
1382
|
+
if (facts.packageManager !== "unknown") {
|
|
1383
|
+
const usage = packageManagerUsage(file.text);
|
|
1384
|
+
const own = usage.get(facts.packageManager) ?? 0;
|
|
1385
|
+
for (const [pm, count] of usage) {
|
|
1386
|
+
if (pm === facts.packageManager || count < 2 || count <= own) continue;
|
|
1387
|
+
findings.push(
|
|
1388
|
+
finding2({
|
|
1389
|
+
id: `${LENS_ID4}/pm-conflict:${file.path}`,
|
|
1390
|
+
tier: "gap",
|
|
1391
|
+
claim: `${file.path} instructs \`${pm}\` (${count}\xD7) but the repo uses ${facts.packageManager}`,
|
|
1392
|
+
evidence: [file.path, `lockfile \u2192 ${facts.packageManager}`],
|
|
1393
|
+
why: "Mixed package-manager instructions produce divergent lockfiles and broken installs.",
|
|
1394
|
+
action: `Rewrite the commands for ${facts.packageManager}.`,
|
|
1395
|
+
effort: "S",
|
|
1396
|
+
confidence: "medium"
|
|
1397
|
+
})
|
|
1398
|
+
);
|
|
1399
|
+
break;
|
|
1400
|
+
}
|
|
1391
1401
|
}
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1402
|
+
for (const ref of extractDocRefs(file.text)) {
|
|
1403
|
+
if (await pathExists(path.join(root, ref))) continue;
|
|
1404
|
+
findings.push(
|
|
1405
|
+
finding2({
|
|
1406
|
+
id: `${LENS_ID4}/dangling-ref:${file.path}:${ref}`,
|
|
1407
|
+
tier: "gap",
|
|
1408
|
+
claim: `${file.path} references ${ref} \u2014 no such file exists`,
|
|
1409
|
+
evidence: [file.path, `missing: ${ref}`],
|
|
1410
|
+
why: "The pointer chain agents follow breaks at a file they can never read.",
|
|
1411
|
+
action: `Create ${ref} or remove the reference.`,
|
|
1412
|
+
effort: "S",
|
|
1413
|
+
confidence: "high"
|
|
1414
|
+
})
|
|
1415
|
+
);
|
|
1404
1416
|
}
|
|
1405
1417
|
}
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1418
|
+
const auditedPaths = new Set(files.map((f) => f.path));
|
|
1419
|
+
const stateDocs = await listStateDocuments(root, facts);
|
|
1420
|
+
let qualifiedRefsSkipped = 0;
|
|
1421
|
+
let unresolvableRefs = 0;
|
|
1422
|
+
let ledgerIds = null;
|
|
1423
|
+
const ledgerSources = [];
|
|
1424
|
+
if (stateDocs.length) {
|
|
1425
|
+
for (const artifact of facts.artifacts) {
|
|
1426
|
+
if (artifact.kind !== "decisions" || !artifact.exists) continue;
|
|
1427
|
+
const text = await readText(path.join(root, artifact.path));
|
|
1428
|
+
if (text === null) continue;
|
|
1429
|
+
const entries = parseDecisionEntries(text);
|
|
1430
|
+
if (!entries.length) continue;
|
|
1431
|
+
ledgerIds ??= /* @__PURE__ */ new Set();
|
|
1432
|
+
for (const entry of entries) ledgerIds.add(entry.num);
|
|
1433
|
+
ledgerSources.push(artifact.path);
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
for (const doc of stateDocs) {
|
|
1437
|
+
if (!auditedPaths.has(doc.path)) await auditClaims(doc);
|
|
1438
|
+
const { refs, qualifiedSkipped } = extractDecisionRefs(doc.text);
|
|
1439
|
+
qualifiedRefsSkipped += qualifiedSkipped;
|
|
1440
|
+
if (!refs.size) continue;
|
|
1441
|
+
if (!ledgerIds) {
|
|
1442
|
+
unresolvableRefs += refs.size;
|
|
1412
1443
|
continue;
|
|
1413
1444
|
}
|
|
1414
|
-
const
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1445
|
+
for (const [num, asWritten] of refs) {
|
|
1446
|
+
if (ledgerIds.has(num)) continue;
|
|
1447
|
+
findings.push(
|
|
1448
|
+
finding2({
|
|
1449
|
+
id: `${LENS_ID4}/dead-decision-ref:${doc.path}:${asWritten}`,
|
|
1450
|
+
tier: "gap",
|
|
1451
|
+
claim: `${doc.path} cites ${asWritten} \u2014 no such entry exists in ${ledgerSources.join(", ")}`,
|
|
1452
|
+
evidence: [doc.path, `${ledgerSources.join(", ")}: no ${asWritten} entry`],
|
|
1453
|
+
why: "A state doc is read as ground truth on return; a citation the decision record cannot back sends readers to a ruling that was never written.",
|
|
1454
|
+
action: "Fix the reference \u2014 or record the missing decision.",
|
|
1455
|
+
effort: "S",
|
|
1456
|
+
confidence: "medium"
|
|
1457
|
+
})
|
|
1420
1458
|
);
|
|
1421
|
-
outOfScope.push(a.path);
|
|
1422
|
-
continue;
|
|
1423
1459
|
}
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1460
|
+
}
|
|
1461
|
+
if (ctx.baseline) {
|
|
1462
|
+
findings.push(
|
|
1463
|
+
...compareCommands(ctx.baseline.facts, facts),
|
|
1464
|
+
...compareArtifacts(ctx.baseline.facts, facts),
|
|
1465
|
+
...compareLayout(ctx.baseline.facts, facts)
|
|
1466
|
+
);
|
|
1467
|
+
if (baselineCarriesMachinePath(ctx.baseline)) {
|
|
1427
1468
|
disclosures.push(
|
|
1428
|
-
`${
|
|
1469
|
+
`${BASELINE_FILE} records an absolute machine path as its scan root (written by an older etymd). It is committed, so that path is published with your repo \u2014 run \`etymd approve\` to rewrite it.`
|
|
1429
1470
|
);
|
|
1430
1471
|
}
|
|
1431
|
-
if (
|
|
1472
|
+
if (ctx.baseline.packVersion !== PACK_VERSION) {
|
|
1432
1473
|
disclosures.push(
|
|
1433
|
-
|
|
1474
|
+
`Baseline was approved under pack v${ctx.baseline.packVersion}; current pack is v${PACK_VERSION}.`
|
|
1434
1475
|
);
|
|
1435
1476
|
}
|
|
1436
|
-
|
|
1477
|
+
} else {
|
|
1478
|
+
disclosures.push(
|
|
1479
|
+
"No committed baseline (.etymd/baseline.json) \u2014 drift over time is not measurable; run `etymd init` to approve one."
|
|
1480
|
+
);
|
|
1481
|
+
}
|
|
1482
|
+
if (binaryResolved) {
|
|
1483
|
+
disclosures.push(
|
|
1484
|
+
`${binaryResolved} command claim(s) are installed binaries (node_modules/.bin), not package scripts \u2014 treated as true.`
|
|
1485
|
+
);
|
|
1486
|
+
}
|
|
1487
|
+
if (unverifiableCommands) {
|
|
1488
|
+
disclosures.push(
|
|
1489
|
+
`node_modules is not installed \u2014 ${unverifiableCommands} command claim(s) matching no package script could not be checked against installed binaries; skipped, not flagged.`
|
|
1490
|
+
);
|
|
1491
|
+
}
|
|
1492
|
+
if (gitignoredSkipped) {
|
|
1493
|
+
disclosures.push(
|
|
1494
|
+
`${gitignoredSkipped} missing path claim(s) are gitignored (machine-local, e.g. .env) \u2014 existence is not verifiable from the repo; skipped, not flagged.`
|
|
1495
|
+
);
|
|
1496
|
+
}
|
|
1497
|
+
if (prospectiveSkipped) {
|
|
1498
|
+
disclosures.push(
|
|
1499
|
+
`${prospectiveSkipped} path claim(s) sit in create-this prose (the file instructs generating them) \u2014 forward-looking, not stale; skipped, not flagged.`
|
|
1500
|
+
);
|
|
1501
|
+
}
|
|
1502
|
+
if (placeholderSkipped) {
|
|
1503
|
+
disclosures.push(
|
|
1504
|
+
`${placeholderSkipped} path claim(s) are naming stand-ins (e.g. \`my-custom-skill\`) rather than real references; skipped, not flagged.`
|
|
1505
|
+
);
|
|
1506
|
+
}
|
|
1507
|
+
if (stateDocs.length) {
|
|
1508
|
+
disclosures.push(
|
|
1509
|
+
`Checked ${stateDocs.length} state document(s) for command, path, and decision-reference claims (same skip classes as instruction files); decision ids resolved against ${ledgerSources.length ? ledgerSources.join(", ") : "nothing \u2014 no decisions file with D-NNN entries"}.`
|
|
1510
|
+
);
|
|
1511
|
+
}
|
|
1512
|
+
if (qualifiedRefsSkipped) {
|
|
1513
|
+
disclosures.push(
|
|
1514
|
+
`${qualifiedRefsSkipped} decision reference(s) name another record (e.g. a fleet-level ledger) \u2014 not claims about this repo's decisions; skipped, not flagged.`
|
|
1515
|
+
);
|
|
1516
|
+
}
|
|
1517
|
+
if (unresolvableRefs) {
|
|
1518
|
+
disclosures.push(
|
|
1519
|
+
`${unresolvableRefs} decision reference(s) could not be resolved \u2014 no decisions file with \`## D-NNN\` entries; skipped, not flagged.`
|
|
1520
|
+
);
|
|
1521
|
+
}
|
|
1522
|
+
if (excluded.length) {
|
|
1523
|
+
const shown = excluded.slice(0, 5).join(", ");
|
|
1524
|
+
disclosures.push(
|
|
1525
|
+
`${excluded.length} instruction file(s) excluded by ${CONFIG_FILE} and NOT audited: ${shown}${excluded.length > 5 ? `, +${excluded.length - 5} more` : ""}.`
|
|
1526
|
+
);
|
|
1527
|
+
}
|
|
1528
|
+
if (includedExtra.length) {
|
|
1529
|
+
disclosures.push(
|
|
1530
|
+
`${includedExtra.length} extra instruction file(s) audited via ${CONFIG_FILE} \`instructions.include\`: ${includedExtra.slice(0, 5).join(", ")}${includedExtra.length > 5 ? `, +${includedExtra.length - 5} more` : ""}.`
|
|
1531
|
+
);
|
|
1437
1532
|
}
|
|
1438
1533
|
disclosures.push(
|
|
1439
|
-
`
|
|
1534
|
+
`Checked ${files.length} instruction file(s); commands resolved against root + ${facts.packages.length} workspace manifest(s) plus installed binaries; paths matched against root and package roots. Heuristics: workspace-filtered commands skipped (${totalFilteredSkipped}); tokens without a recognized extension treated as prose (a dir claim needs a trailing slash); gitignored claims unverifiable; create-this and stand-in path claims skipped; absolute/globbed/placeholder tokens skipped; framework-pattern staleness not checked.`
|
|
1440
1535
|
);
|
|
1441
1536
|
return {
|
|
1442
1537
|
lens: LENS_ID4,
|
|
1443
1538
|
version: "1",
|
|
1444
|
-
title: "
|
|
1539
|
+
title: "Instruction truth",
|
|
1445
1540
|
kind: "truth",
|
|
1446
1541
|
status: "ran",
|
|
1447
1542
|
disclosures,
|
|
1448
1543
|
findings,
|
|
1449
|
-
|
|
1544
|
+
outOfScope: excluded
|
|
1450
1545
|
};
|
|
1451
1546
|
}
|
|
1452
1547
|
};
|