mandrel 2.68.0 → 2.70.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/.agents/scripts/audit-to-stories.js +39 -247
- package/.agents/scripts/lib/audit-to-stories/finding-adapter.js +1 -1
- package/.agents/scripts/lib/findings/route-finding.js +15 -0
- package/.agents/scripts/lib/orchestration/plan-context.js +14 -1
- package/.agents/scripts/lib/orchestration/plan-persist/audit-provenance.js +35 -117
- package/.agents/scripts/lib/orchestration/plan-persist/run-plan-persist.js +5 -6
- package/.agents/templates/docs/audit-sweep-runbook.md +29 -59
- package/.agents/workflows/audit-security.md +0 -1
- package/.agents/workflows/audit-to-stories.md +40 -67
- package/docs/CHANGELOG.md +18 -0
- package/lib/migrations/index.js +2 -0
- package/lib/migrations/steps/2.70.0-retire-audit-ledger.js +36 -0
- package/package.json +1 -1
- package/.agents/scripts/lib/audit-to-stories/ledger-commit.js +0 -184
- package/.agents/scripts/lib/audit-to-stories/ledger-pr.js +0 -279
- package/.agents/scripts/lib/audit-to-stories/ledger-record.js +0 -88
- package/.agents/scripts/lib/findings/audit-ledger.js +0 -289
|
@@ -13,20 +13,12 @@ import { parseArgs } from 'node:util';
|
|
|
13
13
|
import { buildStoryBody } from './lib/audit-to-stories/build-story-body.js';
|
|
14
14
|
import { classifyGroupsAgainstGitHub } from './lib/audit-to-stories/dedupe-against-github.js';
|
|
15
15
|
import { formatEpicGrouping } from './lib/audit-to-stories/epic-grouping-directive.js';
|
|
16
|
-
import {
|
|
17
|
-
toCanonicalFinding,
|
|
18
|
-
withFingerprints,
|
|
19
|
-
} from './lib/audit-to-stories/finding-adapter.js';
|
|
16
|
+
import { withFingerprints } from './lib/audit-to-stories/finding-adapter.js';
|
|
20
17
|
import { groupFindings } from './lib/audit-to-stories/group-findings.js';
|
|
21
18
|
import {
|
|
22
19
|
loadIssuesFile,
|
|
23
20
|
normaliseIssueHit,
|
|
24
21
|
} from './lib/audit-to-stories/issues-file.js';
|
|
25
|
-
import {
|
|
26
|
-
resolveLedgerSummary,
|
|
27
|
-
runLedgerCommit,
|
|
28
|
-
} from './lib/audit-to-stories/ledger-commit.js';
|
|
29
|
-
import { recordFiledIssues } from './lib/audit-to-stories/ledger-record.js';
|
|
30
22
|
import {
|
|
31
23
|
parseAuditReports,
|
|
32
24
|
readSeverityTally,
|
|
@@ -34,12 +26,6 @@ import {
|
|
|
34
26
|
import { buildPlanSeedMarkdown } from './lib/audit-to-stories/seed-from-findings.js';
|
|
35
27
|
import { wireAuditStoryEdges } from './lib/audit-to-stories/wire-dependencies.js';
|
|
36
28
|
import { runAsCli } from './lib/cli-utils.js';
|
|
37
|
-
import {
|
|
38
|
-
DEFAULT_LEDGER_PATH,
|
|
39
|
-
readLedger,
|
|
40
|
-
reconcileLedger,
|
|
41
|
-
writeLedger,
|
|
42
|
-
} from './lib/findings/audit-ledger.js';
|
|
43
29
|
import { searchSemanticCandidates } from './lib/findings/semantic-issue-search.js';
|
|
44
30
|
import {
|
|
45
31
|
normalizeSeverity,
|
|
@@ -125,7 +111,7 @@ function formatTally(tally) {
|
|
|
125
111
|
|
|
126
112
|
/**
|
|
127
113
|
* Cross-check the reports, warn on stderr, and throw under
|
|
128
|
-
* `failOnReportFailures` (`--auto`) BEFORE any
|
|
114
|
+
* `failOnReportFailures` (`--auto`) BEFORE any GitHub write; `--scan`
|
|
129
115
|
* carries the failures on the plan envelope instead.
|
|
130
116
|
*
|
|
131
117
|
* @param {object} params
|
|
@@ -602,17 +588,17 @@ function dedupPhaseWarnings({ issues, summary }) {
|
|
|
602
588
|
}
|
|
603
589
|
|
|
604
590
|
/**
|
|
605
|
-
* Scan → group → dedup
|
|
591
|
+
* Scan → group → dedup. Cross-run memory is the Issues' provenance footers,
|
|
592
|
+
* which dedup reads from live state — nothing is persisted here.
|
|
606
593
|
*
|
|
607
594
|
* @param {{ glob?: string, severity?: string, useProvider?: boolean,
|
|
608
|
-
* issuesFile?: string
|
|
595
|
+
* issuesFile?: string }} params
|
|
609
596
|
* @param {{
|
|
610
597
|
* collectReportPathsImpl?: typeof collectReportPaths,
|
|
611
598
|
* readReportsImpl?: typeof readReports,
|
|
612
599
|
* loadProviderImpl?: typeof loadProviderOrNull,
|
|
613
600
|
* classifyGroupsImpl?: typeof classifyGroupsAgainstGitHub,
|
|
614
601
|
* loadIssuesFileImpl?: typeof loadIssuesFile,
|
|
615
|
-
* reconcileScanLedgerImpl?: typeof reconcileScanLedger,
|
|
616
602
|
* logger?: { warn: Function },
|
|
617
603
|
* }} [deps]
|
|
618
604
|
* @returns {Promise<object>} the plan envelope.
|
|
@@ -623,7 +609,6 @@ async function buildPlan(
|
|
|
623
609
|
severity,
|
|
624
610
|
useProvider,
|
|
625
611
|
issuesFile,
|
|
626
|
-
ledger,
|
|
627
612
|
allowMissingTally,
|
|
628
613
|
failOnReportFailures,
|
|
629
614
|
},
|
|
@@ -635,7 +620,6 @@ async function buildPlan(
|
|
|
635
620
|
loadProviderImpl = loadProviderOrNull,
|
|
636
621
|
classifyGroupsImpl = classifyGroupsAgainstGitHub,
|
|
637
622
|
loadIssuesFileImpl = loadIssuesFile,
|
|
638
|
-
reconcileScanLedgerImpl = reconcileScanLedger,
|
|
639
623
|
logger = Logger,
|
|
640
624
|
} = deps;
|
|
641
625
|
// Before reading reports: an unusable corpus is a usage error, not a fallback.
|
|
@@ -680,32 +664,6 @@ async function buildPlan(
|
|
|
680
664
|
{ loadProviderImpl, classifyGroupsImpl, logger },
|
|
681
665
|
);
|
|
682
666
|
|
|
683
|
-
// Opt-in: plain --scan never mutates the committed ledger.
|
|
684
|
-
let ledgerSummary;
|
|
685
|
-
if (ledger) {
|
|
686
|
-
const suppressed = reconcileScanLedgerImpl({
|
|
687
|
-
ledgerPath: ledger.path ?? DEFAULT_LEDGER_PATH,
|
|
688
|
-
findings: stamped,
|
|
689
|
-
classifications,
|
|
690
|
-
write: ledger.write !== false,
|
|
691
|
-
});
|
|
692
|
-
if (suppressed.size > 0) {
|
|
693
|
-
for (const c of classifications) {
|
|
694
|
-
const findings = c.group?.findings ?? [];
|
|
695
|
-
if (
|
|
696
|
-
findings.length > 0 &&
|
|
697
|
-
findings.every((f) => suppressed.has(f?.fingerprint?.full))
|
|
698
|
-
) {
|
|
699
|
-
c.action = 'skip-accepted-risk';
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
ledgerSummary = {
|
|
704
|
-
path: ledger.path ?? DEFAULT_LEDGER_PATH,
|
|
705
|
-
suppressed: suppressed.size,
|
|
706
|
-
};
|
|
707
|
-
}
|
|
708
|
-
|
|
709
667
|
return {
|
|
710
668
|
generatedAt: new Date().toISOString(),
|
|
711
669
|
sourceReports: reportPaths,
|
|
@@ -720,62 +678,11 @@ async function buildPlan(
|
|
|
720
678
|
tally: tallyBySeverity(filtered),
|
|
721
679
|
reportFailures,
|
|
722
680
|
dedupApplied,
|
|
723
|
-
...(ledgerSummary ? { ledger: ledgerSummary } : {}),
|
|
724
681
|
...summary,
|
|
725
682
|
},
|
|
726
683
|
};
|
|
727
684
|
}
|
|
728
685
|
|
|
729
|
-
/**
|
|
730
|
-
* Fold the scan onto the ledger, persist it, and return the accepted-risk
|
|
731
|
-
* fingerprints to suppress.
|
|
732
|
-
*
|
|
733
|
-
* @param {object} params
|
|
734
|
-
* @param {string} params.ledgerPath
|
|
735
|
-
* @param {Array<object>} params.findings — stamped scan findings.
|
|
736
|
-
* @param {Array<{ group?: object, matchedIssues?: Array<{ number: number, state: string }>, matchedFingerprints?: string[] }>} params.classifications
|
|
737
|
-
* @param {boolean} [params.write=true]
|
|
738
|
-
* @returns {Set<string>}
|
|
739
|
-
*/
|
|
740
|
-
function reconcileScanLedger({ ledgerPath, findings, classifications, write }) {
|
|
741
|
-
const prior = readLedger(ledgerPath);
|
|
742
|
-
const issueStates = issueStatesFromClassifications(classifications);
|
|
743
|
-
const { ledger: next } = reconcileLedger({
|
|
744
|
-
ledger: prior,
|
|
745
|
-
findings,
|
|
746
|
-
issueStates,
|
|
747
|
-
// Passed in: the ledger importing the audit adapter would close a cycle.
|
|
748
|
-
toCanonical: toCanonicalFinding,
|
|
749
|
-
});
|
|
750
|
-
if (write !== false) writeLedger(ledgerPath, next);
|
|
751
|
-
return new Set(
|
|
752
|
-
next.entries
|
|
753
|
-
.filter((e) => e.status === 'accepted-risk')
|
|
754
|
-
.map((e) => e.fingerprint),
|
|
755
|
-
);
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
/**
|
|
759
|
-
* @param {Array<object>} classifications
|
|
760
|
-
* @returns {Record<string, { state: string, number: number|null }>}
|
|
761
|
-
*/
|
|
762
|
-
function issueStatesFromClassifications(classifications) {
|
|
763
|
-
const states = {};
|
|
764
|
-
for (const c of classifications ?? []) {
|
|
765
|
-
const issue = (c.matchedIssues ?? [])[0];
|
|
766
|
-
if (!issue) continue;
|
|
767
|
-
const state = String(issue.state ?? '')
|
|
768
|
-
.toLowerCase()
|
|
769
|
-
.includes('closed')
|
|
770
|
-
? 'closed'
|
|
771
|
-
: 'open';
|
|
772
|
-
for (const fp of c.matchedFingerprints ?? []) {
|
|
773
|
-
states[fp] = { state, number: issue.number ?? null };
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
return states;
|
|
777
|
-
}
|
|
778
|
-
|
|
779
686
|
function loadPlan(planPath) {
|
|
780
687
|
if (!planPath) throw new Error('--plan <path> is required');
|
|
781
688
|
return JSON.parse(fs.readFileSync(planPath, 'utf8'));
|
|
@@ -793,43 +700,25 @@ function severityFloorOf(explicit) {
|
|
|
793
700
|
}
|
|
794
701
|
|
|
795
702
|
/**
|
|
796
|
-
* Unattended `--auto` sweep: build the plan
|
|
797
|
-
*
|
|
798
|
-
*
|
|
703
|
+
* Unattended `--auto` sweep: build the plan and return a summary plus the
|
|
704
|
+
* create-eligible Story payloads (none under `--dry-run`). Writes nothing and
|
|
705
|
+
* never prompts.
|
|
799
706
|
*
|
|
800
707
|
* @param {object} params
|
|
801
708
|
* @param {string} [params.glob]
|
|
802
709
|
* @param {string} [params.severity] — explicit floor override.
|
|
803
710
|
* @param {boolean} [params.dryRun]
|
|
804
711
|
* @param {boolean} [params.useProvider]
|
|
805
|
-
* @param {string} [params.
|
|
806
|
-
* @param {boolean} [params.ledgerCommit] — the operator asked for a ledger PR,
|
|
807
|
-
* so an unpersistable checkout is not a warning: it is about to be fixed.
|
|
808
|
-
* @param {(cwd: string, ...args: string[]) => string} [params.git] — probe seam.
|
|
809
|
-
* @param {string} [params.cwd]
|
|
810
|
-
* @param {{ warn: Function }} [params.logger]
|
|
712
|
+
* @param {string} [params.issuesFile]
|
|
811
713
|
* @returns {Promise<{ summary: object, stories: Array<object> }>}
|
|
812
714
|
*/
|
|
813
|
-
async function runAuto({
|
|
814
|
-
glob,
|
|
815
|
-
severity,
|
|
816
|
-
dryRun,
|
|
817
|
-
useProvider,
|
|
818
|
-
issuesFile,
|
|
819
|
-
ledgerPath,
|
|
820
|
-
ledgerCommit,
|
|
821
|
-
git,
|
|
822
|
-
cwd,
|
|
823
|
-
logger = Logger,
|
|
824
|
-
}) {
|
|
715
|
+
async function runAuto({ glob, severity, dryRun, useProvider, issuesFile }) {
|
|
825
716
|
const floor = severityFloorOf(severity);
|
|
826
|
-
const resolvedLedgerPath = ledgerPath ?? DEFAULT_LEDGER_PATH;
|
|
827
717
|
const plan = await buildPlan({
|
|
828
718
|
glob,
|
|
829
719
|
severity: floor,
|
|
830
720
|
useProvider,
|
|
831
721
|
issuesFile,
|
|
832
|
-
ledger: { path: resolvedLedgerPath, write: !dryRun },
|
|
833
722
|
// No operator reads warnings unattended, so every report failure is fatal.
|
|
834
723
|
allowMissingTally: false,
|
|
835
724
|
failOnReportFailures: true,
|
|
@@ -839,13 +728,11 @@ async function runAuto({
|
|
|
839
728
|
create: [],
|
|
840
729
|
skipOpen: [],
|
|
841
730
|
skipReoccurring: [],
|
|
842
|
-
suppressed: [],
|
|
843
731
|
};
|
|
844
732
|
for (const c of plan.classifications ?? []) {
|
|
845
733
|
if (c.action === 'create') byAction.create.push(c);
|
|
846
734
|
else if (c.action === 'skip-open') byAction.skipOpen.push(c);
|
|
847
735
|
else if (c.action === 'skip-reoccurring') byAction.skipReoccurring.push(c);
|
|
848
|
-
else if (c.action === 'skip-accepted-risk') byAction.suppressed.push(c);
|
|
849
736
|
}
|
|
850
737
|
|
|
851
738
|
const eligible = byAction.create.map((c) => c.group);
|
|
@@ -863,25 +750,14 @@ async function runAuto({
|
|
|
863
750
|
create: byAction.create.length,
|
|
864
751
|
skipOpen: byAction.skipOpen.length,
|
|
865
752
|
skipReoccurring: byAction.skipReoccurring.length,
|
|
866
|
-
suppressedByLedger: byAction.suppressed.length,
|
|
867
753
|
},
|
|
868
754
|
// The caller opens the Issues; these keys feed its `--wire-edges --ids`
|
|
869
|
-
// map,
|
|
755
|
+
// map, which resolves the group edges to `blocked by #N`.
|
|
870
756
|
createGroupKeys: eligible.map((g) => g?.groupKey).filter(Boolean),
|
|
871
757
|
reDetected: byAction.skipOpen
|
|
872
758
|
.flatMap((c) => c.matchedIssues ?? [])
|
|
873
759
|
.map((i) => i.number)
|
|
874
760
|
.filter((n) => typeof n === 'number'),
|
|
875
|
-
// An ephemeral clone may not be able to keep the ledger it just wrote.
|
|
876
|
-
ledger: await resolveLedgerSummary({
|
|
877
|
-
ledger: plan.summary?.ledger ?? null,
|
|
878
|
-
ledgerPath: resolvedLedgerPath,
|
|
879
|
-
dryRun,
|
|
880
|
-
ledgerCommit,
|
|
881
|
-
cwd,
|
|
882
|
-
git,
|
|
883
|
-
logger,
|
|
884
|
-
}),
|
|
885
761
|
};
|
|
886
762
|
|
|
887
763
|
return { summary, stories };
|
|
@@ -953,44 +829,23 @@ function wireEdgesPreconditionError(reason, detail) {
|
|
|
953
829
|
/**
|
|
954
830
|
* Second pass after `--emit-stories`: given the opened `groupKey →
|
|
955
831
|
* issueNumber` map, re-render each Story with `blocked by #N` footers, mirror
|
|
956
|
-
* them as native `blocked_by
|
|
832
|
+
* them as native `blocked_by`. Writes nothing to disk.
|
|
957
833
|
*
|
|
958
834
|
* @param {object} params
|
|
959
835
|
* @param {object} params.plan A `--scan` plan envelope.
|
|
960
836
|
* @param {Record<string, number>} params.issueByGroupKey
|
|
961
|
-
* @param {string} [params.ledgerPath] — ledger to record into; defaults to
|
|
962
|
-
* `DEFAULT_LEDGER_PATH` inside the record.
|
|
963
|
-
* @param {boolean} [params.write] — `false` computes the record without
|
|
964
|
-
* persisting it (what `--dry-run` passes).
|
|
965
837
|
* @param {object} [deps]
|
|
966
838
|
* @param {Function} [deps.loadProviderImpl]
|
|
967
839
|
* @param {Function} [deps.wireImpl]
|
|
968
|
-
* @
|
|
969
|
-
* @returns {Promise<object>} the wiring summary, with the ledger record on
|
|
970
|
-
* `ledger`.
|
|
840
|
+
* @returns {Promise<object>} the wiring summary.
|
|
971
841
|
*/
|
|
972
|
-
async function wireEdges(
|
|
973
|
-
{
|
|
974
|
-
|
|
975
|
-
) {
|
|
976
|
-
const {
|
|
977
|
-
loadProviderImpl = loadProvider,
|
|
978
|
-
wireImpl = wireAuditStoryEdges,
|
|
979
|
-
recordFiledIssuesImpl = recordFiledIssues,
|
|
980
|
-
} = deps;
|
|
842
|
+
async function wireEdges({ plan, issueByGroupKey }, deps = {}) {
|
|
843
|
+
const { loadProviderImpl = loadProvider, wireImpl = wireAuditStoryEdges } =
|
|
844
|
+
deps;
|
|
981
845
|
const groups = (plan.classifications ?? [])
|
|
982
846
|
.filter((c) => c.action === 'create')
|
|
983
847
|
.map((c) => c.group);
|
|
984
848
|
|
|
985
|
-
// Record before loading the provider: a `gh`-less host, whose only duplicate
|
|
986
|
-
// protection is the ledger, must still remember what it filed.
|
|
987
|
-
const ledger = recordFiledIssuesImpl({
|
|
988
|
-
ledgerPath,
|
|
989
|
-
groups,
|
|
990
|
-
issueByGroupKey,
|
|
991
|
-
write,
|
|
992
|
-
});
|
|
993
|
-
|
|
994
849
|
let provider;
|
|
995
850
|
try {
|
|
996
851
|
provider = await loadProviderImpl();
|
|
@@ -1000,7 +855,7 @@ async function wireEdges(
|
|
|
1000
855
|
if (typeof provider?.updateTicket !== 'function') {
|
|
1001
856
|
throw wireEdgesPreconditionError('fixture-no-write-port');
|
|
1002
857
|
}
|
|
1003
|
-
|
|
858
|
+
return wireImpl({
|
|
1004
859
|
groups,
|
|
1005
860
|
edges: plan.edges ?? [],
|
|
1006
861
|
issueByGroupKey,
|
|
@@ -1008,7 +863,6 @@ async function wireEdges(
|
|
|
1008
863
|
updateBody: (issueNumber, body) =>
|
|
1009
864
|
provider.updateTicket(issueNumber, { body }),
|
|
1010
865
|
});
|
|
1011
|
-
return { ...wired, ledger };
|
|
1012
866
|
}
|
|
1013
867
|
|
|
1014
868
|
/**
|
|
@@ -1066,61 +920,10 @@ export const __testing = {
|
|
|
1066
920
|
dedupIndexDegradedWarning,
|
|
1067
921
|
buildAndGateStories,
|
|
1068
922
|
runAuto,
|
|
1069
|
-
reconcileScanLedger,
|
|
1070
|
-
issueStatesFromClassifications,
|
|
1071
923
|
wireEdges,
|
|
1072
924
|
parseIssueMap,
|
|
1073
925
|
};
|
|
1074
926
|
|
|
1075
|
-
/**
|
|
1076
|
-
* The CLI core: dispatch one sub-command and persist its output.
|
|
1077
|
-
*
|
|
1078
|
-
* @param {string[]} [argv]
|
|
1079
|
-
* @param {{
|
|
1080
|
-
* buildPlanImpl?: typeof buildPlan,
|
|
1081
|
-
* runAutoImpl?: typeof runAuto,
|
|
1082
|
-
* loadPlanImpl?: typeof loadPlan,
|
|
1083
|
-
* buildAndGateStoriesImpl?: typeof buildAndGateStories,
|
|
1084
|
-
* buildPlanSeedMarkdownImpl?: typeof buildPlanSeedMarkdown,
|
|
1085
|
-
* persistImpl?: typeof persist,
|
|
1086
|
-
* stdout?: { write: (s: string) => void },
|
|
1087
|
-
* }} [deps]
|
|
1088
|
-
* @returns {Promise<void>}
|
|
1089
|
-
*/
|
|
1090
|
-
/**
|
|
1091
|
-
* The one-line `--ledger-commit` outcome: branch and PR, or the skip reason.
|
|
1092
|
-
*
|
|
1093
|
-
* @param {{ committed?: boolean, reason?: string, branch?: string,
|
|
1094
|
-
* prUrl?: string|null, resumed?: boolean, ledgerPath?: string }} [result]
|
|
1095
|
-
* @returns {string}
|
|
1096
|
-
*/
|
|
1097
|
-
function describeLedgerCommit(result) {
|
|
1098
|
-
return result?.committed
|
|
1099
|
-
? ledgerCommittedLine(result)
|
|
1100
|
-
: ledgerSkippedLine(result);
|
|
1101
|
-
}
|
|
1102
|
-
|
|
1103
|
-
/**
|
|
1104
|
-
* @param {object} result
|
|
1105
|
-
* @returns {string}
|
|
1106
|
-
*/
|
|
1107
|
-
function ledgerCommittedLine(result) {
|
|
1108
|
-
const resumed = result.resumed ? ' (resumed an unpushed ledger branch)' : '';
|
|
1109
|
-
const pr = result.prUrl ?? '(no URL reported by gh)';
|
|
1110
|
-
return `--ledger-commit: pushed ${result.branch}${resumed} and opened ${pr}.`;
|
|
1111
|
-
}
|
|
1112
|
-
|
|
1113
|
-
/**
|
|
1114
|
-
* Names the ledger file: its state is still only in the working tree.
|
|
1115
|
-
* @param {object} [result]
|
|
1116
|
-
* @returns {string}
|
|
1117
|
-
*/
|
|
1118
|
-
function ledgerSkippedLine(result) {
|
|
1119
|
-
const reason = result?.reason ?? 'no result';
|
|
1120
|
-
const ledgerPath = result?.ledgerPath ?? 'the ledger';
|
|
1121
|
-
return `--ledger-commit: skipped (${reason}) — ${ledgerPath} was not committed.`;
|
|
1122
|
-
}
|
|
1123
|
-
|
|
1124
927
|
/**
|
|
1125
928
|
* Reject an unknown `--severity`: `meetsSeverity` would read a typo as rank 0
|
|
1126
929
|
* and silently widen the run to every finding. Absent stays absent.
|
|
@@ -1140,6 +943,21 @@ function validateSeverityFlag(raw) {
|
|
|
1140
943
|
return level;
|
|
1141
944
|
}
|
|
1142
945
|
|
|
946
|
+
/**
|
|
947
|
+
* The CLI core: dispatch one sub-command and persist its output.
|
|
948
|
+
*
|
|
949
|
+
* @param {string[]} [argv]
|
|
950
|
+
* @param {{
|
|
951
|
+
* buildPlanImpl?: typeof buildPlan,
|
|
952
|
+
* runAutoImpl?: typeof runAuto,
|
|
953
|
+
* loadPlanImpl?: typeof loadPlan,
|
|
954
|
+
* buildAndGateStoriesImpl?: typeof buildAndGateStories,
|
|
955
|
+
* buildPlanSeedMarkdownImpl?: typeof buildPlanSeedMarkdown,
|
|
956
|
+
* persistImpl?: typeof persist,
|
|
957
|
+
* stdout?: { write: (s: string) => void },
|
|
958
|
+
* }} [deps]
|
|
959
|
+
* @returns {Promise<void>}
|
|
960
|
+
*/
|
|
1143
961
|
export async function runAuditToStories(
|
|
1144
962
|
argv = process.argv.slice(2),
|
|
1145
963
|
deps = {},
|
|
@@ -1153,7 +971,6 @@ export async function runAuditToStories(
|
|
|
1153
971
|
wireEdgesImpl = wireEdges,
|
|
1154
972
|
parseIssueMapImpl = parseIssueMap,
|
|
1155
973
|
persistImpl = persist,
|
|
1156
|
-
runLedgerCommitImpl = runLedgerCommit,
|
|
1157
974
|
stdout = process.stdout,
|
|
1158
975
|
} = deps;
|
|
1159
976
|
const { values } = parseArgs({
|
|
@@ -1168,8 +985,6 @@ export async function runAuditToStories(
|
|
|
1168
985
|
ids: { type: 'string' },
|
|
1169
986
|
glob: { type: 'string' },
|
|
1170
987
|
severity: { type: 'string' },
|
|
1171
|
-
ledger: { type: 'string' },
|
|
1172
|
-
'ledger-commit': { type: 'boolean' },
|
|
1173
988
|
plan: { type: 'string' },
|
|
1174
989
|
out: { type: 'string' },
|
|
1175
990
|
'no-provider': { type: 'boolean' },
|
|
@@ -1177,7 +992,9 @@ export async function runAuditToStories(
|
|
|
1177
992
|
'allow-missing-tally': { type: 'boolean' },
|
|
1178
993
|
json: { type: 'boolean' },
|
|
1179
994
|
},
|
|
1180
|
-
|
|
995
|
+
// Strict: a retired flag (the 2.70 ledger pair) must error, not be
|
|
996
|
+
// silently ignored by a sweep that still passes it.
|
|
997
|
+
strict: true,
|
|
1181
998
|
});
|
|
1182
999
|
|
|
1183
1000
|
values.severity = validateSeverityFlag(values.severity);
|
|
@@ -1192,22 +1009,9 @@ export async function runAuditToStories(
|
|
|
1192
1009
|
dryRun: values['dry-run'],
|
|
1193
1010
|
useProvider: !values['no-provider'],
|
|
1194
1011
|
issuesFile: values['issues-file'],
|
|
1195
|
-
ledgerPath: values.ledger,
|
|
1196
|
-
ledgerCommit: values['ledger-commit'],
|
|
1197
1012
|
})
|
|
1198
1013
|
).summary;
|
|
1199
1014
|
|
|
1200
|
-
// Runs after the summary is persisted: a broken remote must not cost the
|
|
1201
|
-
// sweep's findings.
|
|
1202
|
-
const commitLedger = async () => {
|
|
1203
|
-
if (!values['ledger-commit'] || values['dry-run']) return;
|
|
1204
|
-
Logger.warn(
|
|
1205
|
-
describeLedgerCommit(
|
|
1206
|
-
await runLedgerCommitImpl({ ledgerPath: values.ledger }),
|
|
1207
|
-
),
|
|
1208
|
-
);
|
|
1209
|
-
};
|
|
1210
|
-
|
|
1211
1015
|
const scanPlan = () =>
|
|
1212
1016
|
buildPlanImpl({
|
|
1213
1017
|
glob: values.glob,
|
|
@@ -1239,14 +1043,11 @@ export async function runAuditToStories(
|
|
|
1239
1043
|
wireEdgesImpl({
|
|
1240
1044
|
plan: loadPlanImpl(values.plan),
|
|
1241
1045
|
issueByGroupKey: parseIssueMapImpl(values.ids),
|
|
1242
|
-
ledgerPath: values.ledger,
|
|
1243
|
-
// The Issues really exist here, so recording defaults on.
|
|
1244
|
-
write: !values['dry-run'],
|
|
1245
1046
|
});
|
|
1246
1047
|
|
|
1247
|
-
// [flag, render, newlineOnStdout
|
|
1048
|
+
// [flag, render, newlineOnStdout]
|
|
1248
1049
|
const subcommands = [
|
|
1249
|
-
['auto', async () => json(await runAutoSummary()), true
|
|
1050
|
+
['auto', async () => json(await runAutoSummary()), true],
|
|
1250
1051
|
['scan', async () => json(await scanPlan()), true],
|
|
1251
1052
|
['emit-plan-seed', () => seedMarkdown(), false],
|
|
1252
1053
|
['emit-stories', () => emittedStories(), true],
|
|
@@ -1259,10 +1060,9 @@ export async function runAuditToStories(
|
|
|
1259
1060
|
'Usage: node audit-to-stories.js (--scan | --emit-plan-seed | --emit-stories | --wire-edges) [options]',
|
|
1260
1061
|
);
|
|
1261
1062
|
}
|
|
1262
|
-
const [, render, newlineOnStdout
|
|
1063
|
+
const [, render, newlineOnStdout] = entry;
|
|
1263
1064
|
persistImpl(await render(), values.out);
|
|
1264
1065
|
if (newlineOnStdout && !values.out) stdout.write('\n');
|
|
1265
|
-
if (after) await after();
|
|
1266
1066
|
}
|
|
1267
1067
|
|
|
1268
1068
|
/**
|
|
@@ -1305,7 +1105,7 @@ runAsCli(import.meta.url, main, {
|
|
|
1305
1105
|
['--emit-stories', 'Emit the Story drafts as JSON.'],
|
|
1306
1106
|
[
|
|
1307
1107
|
'--wire-edges',
|
|
1308
|
-
'Second pass: resolve the detected group edges to blocked by #N footers plus native blocked_by relations
|
|
1108
|
+
'Second pass: resolve the detected group edges to blocked by #N footers plus native blocked_by relations. Needs --plan and --ids.',
|
|
1309
1109
|
],
|
|
1310
1110
|
[
|
|
1311
1111
|
'--ids <json|path>',
|
|
@@ -1313,14 +1113,6 @@ runAsCli(import.meta.url, main, {
|
|
|
1313
1113
|
],
|
|
1314
1114
|
['--glob <pattern>', 'Override the audit-results glob.'],
|
|
1315
1115
|
['--severity <level>', 'Lowest severity to include (high|medium|low).'],
|
|
1316
|
-
[
|
|
1317
|
-
'--ledger <path>',
|
|
1318
|
-
`Path to the cross-run dedup ledger (default ${DEFAULT_LEDGER_PATH}).`,
|
|
1319
|
-
],
|
|
1320
|
-
[
|
|
1321
|
-
'--ledger-commit',
|
|
1322
|
-
'After the --auto summary prints, commit a changed ledger onto chore/audit-ledger-<date>, push it, and open a PR against the base branch (never auto-merged). Ignored under --dry-run.',
|
|
1323
|
-
],
|
|
1324
1116
|
[
|
|
1325
1117
|
'--plan <path>',
|
|
1326
1118
|
'Read a previously emitted plan instead of re-scanning.',
|
|
@@ -36,7 +36,7 @@ export function toCanonicalFinding(finding) {
|
|
|
36
36
|
* @param {object} finding
|
|
37
37
|
* @returns {{ short: string, full: string, components: object }}
|
|
38
38
|
*/
|
|
39
|
-
|
|
39
|
+
function fingerprintAuditFinding(finding) {
|
|
40
40
|
return fingerprintFinding(toCanonicalFinding(finding));
|
|
41
41
|
}
|
|
42
42
|
|
|
@@ -190,6 +190,21 @@ function parseAllFooterValues(text, pattern, isValid) {
|
|
|
190
190
|
return out;
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
+
/**
|
|
194
|
+
* Every provenance footer in `text`, verbatim, one per line — the whole of
|
|
195
|
+
* what `carryProvenanceFooters` and `parseAuditLabelFooter` read from a seed,
|
|
196
|
+
* small enough to survive a seed that is cut for size.
|
|
197
|
+
*
|
|
198
|
+
* @param {unknown} text
|
|
199
|
+
* @returns {string}
|
|
200
|
+
*/
|
|
201
|
+
export function extractProvenanceFooters(text) {
|
|
202
|
+
if (typeof text !== 'string') return '';
|
|
203
|
+
const pattern =
|
|
204
|
+
/<!--\s*audit-(?:fingerprints|semantic-keys|labels):[^>]*-->/g;
|
|
205
|
+
return [...text.matchAll(pattern)].map((m) => m[0]).join('\n');
|
|
206
|
+
}
|
|
207
|
+
|
|
193
208
|
/**
|
|
194
209
|
* Append the seed's provenance footers missing from `into`, so the next
|
|
195
210
|
* sweep recognises the Story. Additive and idempotent.
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
matchesAnyFilePattern,
|
|
12
12
|
} from '../audit-suite/selector.js';
|
|
13
13
|
import { findSimilarOpenStories } from '../duplicate-search.js';
|
|
14
|
+
import { extractProvenanceFooters } from '../findings/route-finding.js';
|
|
14
15
|
import { Logger } from '../Logger.js';
|
|
15
16
|
import { parse as parseStoryBody } from '../story-body/story-body.js';
|
|
16
17
|
import {
|
|
@@ -36,6 +37,12 @@ const TRUNCATION_MARKER =
|
|
|
36
37
|
|
|
37
38
|
const MAX_TRUNCATION_ROUNDS = 8;
|
|
38
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Never cut: `seed.provenance` is the audit footers persist stamps onto every
|
|
42
|
+
* Story, and a dropped footer re-files that finding on the next sweep.
|
|
43
|
+
*/
|
|
44
|
+
const UNCUTTABLE_KEYS = new Set(['provenance']);
|
|
45
|
+
|
|
39
46
|
/**
|
|
40
47
|
* @param {unknown} value
|
|
41
48
|
* @returns {number}
|
|
@@ -91,6 +98,7 @@ function truncateField(value, excess) {
|
|
|
91
98
|
}
|
|
92
99
|
if (value && typeof value === 'object') {
|
|
93
100
|
const [key] = Object.entries(value)
|
|
101
|
+
.filter(([k]) => !UNCUTTABLE_KEYS.has(k))
|
|
94
102
|
.filter(([, v]) => typeof v === 'string')
|
|
95
103
|
.map(([k, v]) => [k, Buffer.byteLength(v, 'utf-8')])
|
|
96
104
|
.sort((a, b) => b[1] - a[1])[0] ?? [null];
|
|
@@ -651,7 +659,12 @@ async function buildSeedFileModeEnvelope({
|
|
|
651
659
|
|
|
652
660
|
return {
|
|
653
661
|
mode: modeLabel,
|
|
654
|
-
|
|
662
|
+
// Carried apart from `content` so a size cut cannot drop a footer.
|
|
663
|
+
seed: {
|
|
664
|
+
path: seedFilePath ?? null,
|
|
665
|
+
content,
|
|
666
|
+
provenance: extractProvenanceFooters(content),
|
|
667
|
+
},
|
|
655
668
|
// Advisory only — no routing authority.
|
|
656
669
|
complexitySignals,
|
|
657
670
|
duplicates,
|