@bbcsoftwarefactory/cli 0.1.1 → 1.1.3
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/dist/audit-ledger.d.ts +2 -0
- package/dist/audit-ledger.js +71 -0
- package/dist/bbc-install.d.ts +2 -0
- package/dist/bbc-install.js +1278 -0
- package/dist/bbc.js +87 -3
- package/dist/bundle/commands/daily/SKILL.md +112 -0
- package/dist/bundle/commands/daily/adapters/command.md +17 -0
- package/dist/bundle/commands/daily/adapters/gemini.toml +17 -0
- package/dist/bundle/commands/issue-clean-and-close/SKILL.md +85 -0
- package/dist/bundle/commands/issue-clean-and-close/adapters/command.md +17 -0
- package/dist/bundle/commands/issue-clean-and-close/adapters/gemini.toml +17 -0
- package/dist/bundle/commands/issue-clean-and-close/references/policy.md +87 -0
- package/dist/bundle/commands/recap/SKILL.md +84 -0
- package/dist/bundle/commands/recap/adapters/command.md +17 -0
- package/dist/bundle/commands/recap/adapters/gemini.toml +17 -0
- package/dist/bundle/installer/clients.json +103 -0
- package/dist/bundle/skills/code-quality-gate/SKILL.md +58 -0
- package/dist/bundle/skills/code-quality-gate/references/gate-bigo.md +31 -0
- package/dist/bundle/skills/code-quality-gate/references/gate-earlyreturn.md +73 -0
- package/dist/bundle/skills/code-quality-gate/references/gate-typesafe.md +32 -0
- package/dist/bundle/skills/code-quality-gate/references/output-schema.yml +40 -0
- package/dist/bundle/skills/delivery-coordinator/SKILL.md +80 -0
- package/dist/bundle/skills/delivery-coordinator/references/hud-output.md +55 -0
- package/dist/bundle/skills/delivery-coordinator/references/intake.md +86 -0
- package/dist/bundle/skills/delivery-coordinator/references/issue-claim.md +143 -0
- package/dist/bundle/skills/delivery-coordinator/references/issue-dedup.md +38 -0
- package/dist/bundle/skills/delivery-coordinator/references/sleuth-regression-exercise.md +60 -0
- package/dist/bundle/skills/delivery-coordinator/references/visual-reference.md +45 -0
- package/dist/bundle/skills/delivery-coordinator/references/worktree-isolation.md +19 -0
- package/dist/bundle/skills/documentation-steward/SKILL.md +43 -0
- package/dist/bundle/skills/documentation-steward/references/discovery.md +17 -0
- package/dist/bundle/skills/documentation-steward/references/handoff.md +15 -0
- package/dist/bundle/skills/greptile-review-loop/SKILL.md +56 -0
- package/dist/bundle/skills/greptile-review-loop/references/review-protocol.md +37 -0
- package/dist/bundle/skills/issue-reviewer/SKILL.md +84 -0
- package/dist/bundle/skills/issue-reviewer/references/review-format.md +100 -0
- package/dist/bundle/skills/issue-reviewer/references/triage.md +105 -0
- package/dist/bundle/skills/question-gate/SKILL.md +64 -0
- package/dist/bundle/skills/question-gate/references/client-hooks.md +111 -0
- package/dist/bundle/skills/question-gate/references/diagram-routing.md +58 -0
- package/dist/bundle/skills/question-gate/tests/fixtures/question-corpus.json +481 -0
- package/dist/bundle/skills/regression-testing/SKILL.md +49 -0
- package/dist/bundle/skills/regression-testing/references/evidence-record.md +35 -0
- package/dist/bundle/skills/requirements-spec/SKILL.md +59 -0
- package/dist/bundle/skills/risk-scout/SKILL.md +53 -0
- package/dist/bundle/skills/risk-scout/references/risk-matrix.md +49 -0
- package/dist/bundle/skills/skill-clean-architecture/SKILL.md +53 -0
- package/dist/bundle/skills/skill-clean-architecture/references/layer-rules.md +22 -0
- package/dist/bundle/skills/skill-clean-architecture/references/source-headers.md +30 -0
- package/dist/bundle/skills/skill-clean-architecture/tests/fixtures/bigo/bad-utf8.js +1 -0
- package/dist/bundle/skills/skill-clean-architecture/tests/fixtures/bigo/edge-crlf.ts +6 -0
- package/dist/bundle/skills/skill-clean-architecture/tests/fixtures/bigo/edge-mixed.ts +15 -0
- package/dist/bundle/skills/skill-clean-architecture/tests/fixtures/bigo/empty.js +0 -0
- package/dist/bundle/skills/skill-clean-architecture/tests/fixtures/bigo/no-newline.js +1 -0
- package/dist/bundle/skills/skill-clean-architecture/tests/fixtures/bigo.expected.yml +95 -0
- package/dist/bundle/skills/tool-depot/SKILL.md +47 -0
- package/dist/bundle/skills/tool-depot/references/checkout.md +29 -0
- package/dist/bundle/skills/tool-depot/references/loki-read.md +41 -0
- package/dist/bundle/skills/tool-depot/references/readonly-access.md +84 -0
- package/dist/bundle/skills/tool-depot/references/tool-catalog.json +47 -0
- package/dist/bundle/skills/tool-depot/scripts/loki-runtime-logs.py +305 -0
- package/dist/bundle/skills/tool-depot/tests/loki-runtime-logs.test.sh +101 -0
- package/dist/bundle/skills/watcher-observability/SKILL.md +72 -0
- package/dist/bundle/skills/watcher-observability/references/batch-protocol.md +44 -0
- package/dist/bundle/skills/watcher-observability/references/configuration.md +31 -0
- package/dist/bundle/skills/watcher-observability/references/error-scan.md +102 -0
- package/dist/bundle/skills/watcher-observability/references/live-protocol.md +49 -0
- package/dist/bundle/skills/watcher-observability/references/server-account.md +72 -0
- package/dist/bundle/skills/watcher-observability/server/watcher-gate.sh +51 -0
- package/dist/bundle/skills/watcher-observability/tests/watcher-gate.test.sh +113 -0
- package/dist/bundle/skills/watcher-observability/watcher.json +1 -0
- package/dist/bundle/skills/workflow-auditor/SKILL.md +53 -0
- package/dist/bundle/skills/workflow-auditor/references/audit-protocol.md +49 -0
- package/dist/bundle/skills/workflow-auditor/references/ledger.md +122 -0
- package/dist/change-lane/classification.js +3 -1
- package/dist/check-issue-claim.d.ts +2 -0
- package/dist/check-issue-claim.js +146 -0
- package/dist/check-worktree-guard.d.ts +2 -0
- package/dist/check-worktree-guard.js +114 -0
- package/dist/error-scan.d.ts +3 -0
- package/dist/error-scan.js +216 -0
- package/dist/export-public.d.ts +9 -0
- package/dist/export-public.js +274 -0
- package/dist/fetch-issue-attachments.d.ts +22 -0
- package/dist/fetch-issue-attachments.js +325 -0
- package/dist/issue-claim/evaluation.d.ts +66 -0
- package/dist/issue-claim/evaluation.js +259 -0
- package/dist/issue-claim/loaders.d.ts +5 -0
- package/dist/issue-claim/loaders.js +116 -0
- package/dist/list-zed-commands.d.ts +7 -0
- package/dist/list-zed-commands.js +288 -0
- package/dist/plan-issue-triage.d.ts +3 -0
- package/dist/plan-issue-triage.js +404 -0
- package/dist/question-gate/ledger.d.ts +5 -0
- package/dist/question-gate/ledger.js +115 -0
- package/dist/question-gate/rules.d.ts +40 -0
- package/dist/question-gate/rules.js +483 -0
- package/dist/recap/board.d.ts +5 -0
- package/dist/recap/board.js +384 -0
- package/dist/recap/git-and-github.d.ts +11 -0
- package/dist/recap/git-and-github.js +620 -0
- package/dist/recap/report-and-hud.d.ts +2 -0
- package/dist/recap/report-and-hud.js +294 -0
- package/dist/recap/time-and-refs.d.ts +27 -0
- package/dist/recap/time-and-refs.js +148 -0
- package/dist/recap.d.ts +2 -0
- package/dist/recap.js +217 -0
- package/dist/render-workflow.js +12 -14
- package/dist/resolve-containers.d.ts +2 -0
- package/dist/resolve-containers.js +96 -0
- package/dist/review-loop.d.ts +7 -0
- package/dist/review-loop.js +622 -0
- package/dist/save-counts.d.ts +2 -0
- package/dist/save-counts.js +191 -0
- package/dist/summarize-logs.d.ts +2 -0
- package/dist/summarize-logs.js +41 -0
- package/dist/sweep-github.d.ts +10 -0
- package/dist/sweep-github.js +453 -0
- package/dist/sweep-issues.d.ts +56 -0
- package/dist/sweep-issues.js +650 -0
- package/dist/sweep.d.ts +2 -0
- package/dist/sweep.js +301 -0
- package/dist/triage-question.d.ts +2 -0
- package/dist/triage-question.js +189 -0
- package/dist/validate-skills.d.ts +2 -0
- package/dist/validate-skills.js +48 -0
- package/dist/watch-live.d.ts +7 -0
- package/dist/watch-live.js +83 -0
- package/dist/watcher/config.d.ts +11 -0
- package/dist/watcher/config.js +265 -0
- package/dist/watcher/live-classifier.d.ts +52 -0
- package/dist/watcher/live-classifier.js +510 -0
- package/dist/watcher/safe-fs.d.ts +9 -0
- package/dist/watcher/safe-fs.js +159 -0
- package/dist/watcher/stream.d.ts +27 -0
- package/dist/watcher/stream.js +340 -0
- package/dist/watcher/summarizer.d.ts +19 -0
- package/dist/watcher/summarizer.js +121 -0
- package/dist/wave3/process.d.ts +14 -0
- package/dist/wave3/process.js +84 -0
- package/dist/wave4/process.d.ts +14 -0
- package/dist/wave4/process.js +128 -0
- package/dist/workflow/render.d.ts +1 -1
- package/dist/workflow/render.js +1 -1
- package/dist/workflow-auditor/audit.d.ts +27 -0
- package/dist/workflow-auditor/audit.js +583 -0
- package/dist/workflow-auditor/ledger-io.d.ts +5 -0
- package/dist/workflow-auditor/ledger-io.js +99 -0
- package/dist/workflow-auditor/skills-validator.d.ts +10 -0
- package/dist/workflow-auditor/skills-validator.js +533 -0
- package/dist/worktree-guard/evaluation.d.ts +19 -0
- package/dist/worktree-guard/evaluation.js +84 -0
- package/dist/worktree-guard/git.d.ts +3 -0
- package/dist/worktree-guard/git.js +61 -0
- package/package.json +32 -33
|
@@ -0,0 +1,583 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LAYER: Domain
|
|
3
|
+
* Contains: Delivery ledger workflow conformance rules and server-log verification.
|
|
4
|
+
* Rules: Pure offline audit rules; never read files or call external commands.
|
|
5
|
+
* BigO: O(n^2) score:1
|
|
6
|
+
* keywords: [LedgerAudit, ToolDepotRules, ServerLogVerify]
|
|
7
|
+
* GOAL: Evaluate a delivery ledger against workflow stages, authorizations, and Tool Depot catalog.
|
|
8
|
+
*/
|
|
9
|
+
export class AuditUnusableError extends Error {
|
|
10
|
+
}
|
|
11
|
+
const STAGES = [
|
|
12
|
+
'observe', 'specify', 'claim', 'reproduce', 'implement', 'verify', 'quality',
|
|
13
|
+
'docs', 'commit_pr', 'review', 'residual_risk', 'code_owner', 'release_owner',
|
|
14
|
+
];
|
|
15
|
+
const ORDER = new Map(STAGES.map((stage, index) => [stage, index]));
|
|
16
|
+
const KINDS = new Set(['change', 'issue-only', 'read-only']);
|
|
17
|
+
const LANES = new Set(['trivial', 'standard', 'high-risk']);
|
|
18
|
+
const STATUSES = new Set(['done', 'reused', 'gap']);
|
|
19
|
+
const REQUIRED_FOR_CHANGE = ['specify', 'reproduce', 'implement', 'verify', 'quality', 'commit_pr', 'review'];
|
|
20
|
+
const WRITE_STAGES = new Set(['claim', 'implement', 'verify', 'quality', 'commit_pr', 'review']);
|
|
21
|
+
const RERUN_AFTER_CHANGE = ['verify', 'quality', 'commit_pr', 'review'];
|
|
22
|
+
const LOOP_TARGETS = new Set(['reproduce', 'implement']);
|
|
23
|
+
const AUTHORIZED_STAGES = new Set(['claim', 'implement', 'commit_pr']);
|
|
24
|
+
const COVERED_BY = { claim: ['claim', 'implement'] };
|
|
25
|
+
const HUMAN_STAGES = new Set(['code_owner', 'release_owner']);
|
|
26
|
+
const GAP_ALLOWED = new Set(['observe', 'claim', 'reproduce', 'verify', 'docs', 'review', 'residual_risk']);
|
|
27
|
+
const QUALITY_CHECKS = ['typesafe', 'earlyreturn', 'bigo'];
|
|
28
|
+
const GAP_TYPES = new Set(['not-reproducible', 'no-runnable-test']);
|
|
29
|
+
const WRITE_TOOLS = new Set(['github-write']);
|
|
30
|
+
const SHA_RE = /^[0-9a-fA-F]{7,40}$/;
|
|
31
|
+
const ISSUE_LINK_PURPOSES = new Set(['comment-approved-issue', 'update-approved-issue']);
|
|
32
|
+
const ISSUE_WRITE_PURPOSES = new Set(['publish-approved-issue', 'update-approved-issue', 'comment-approved-issue']);
|
|
33
|
+
const DEDUP_GUARDED_PURPOSES = new Set(['publish-approved-issue', 'reopen-approved-issue']);
|
|
34
|
+
const CLAIM_FREE = new Set(['free', 'claimed-by-you']);
|
|
35
|
+
const CLAIM_HELD = new Set(['claimed-by-other', 'orphan-claim']);
|
|
36
|
+
const CLAIM_BRANCH_RE = /^feat\/(\d+)-[a-z0-9][a-z0-9._-]*$/;
|
|
37
|
+
const ISSUE_NUMBER_RE = /#(\d+)$/;
|
|
38
|
+
const GATE_LOGS_RE = /^docker logs .* -- ([A-Za-z0-9][A-Za-z0-9_.-]*)$/;
|
|
39
|
+
const GATE_PS_RE = /^docker ps --filter 'name=\^\/\?((?:[A-Za-z0-9_-]|\\\.)+)\.\*\$' --format/;
|
|
40
|
+
const TARGET_TOKEN_RE = /[A-Za-z0-9][A-Za-z0-9_.*-]*/g;
|
|
41
|
+
class AuditCollector {
|
|
42
|
+
violations = [];
|
|
43
|
+
gaps = [];
|
|
44
|
+
violation(rule, detail, where) {
|
|
45
|
+
const finding = { rule, detail };
|
|
46
|
+
if (where !== undefined)
|
|
47
|
+
finding.at = where;
|
|
48
|
+
this.violations.push(finding);
|
|
49
|
+
}
|
|
50
|
+
gap(rule, detail, where) {
|
|
51
|
+
const finding = { rule, detail };
|
|
52
|
+
if (where !== undefined)
|
|
53
|
+
finding.at = where;
|
|
54
|
+
this.gaps.push(finding);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function isRecord(value) {
|
|
58
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
59
|
+
}
|
|
60
|
+
function isText(value) {
|
|
61
|
+
return typeof value === 'string' && value.trim() !== '';
|
|
62
|
+
}
|
|
63
|
+
function isSha(value) {
|
|
64
|
+
return typeof value === 'string' && SHA_RE.test(value);
|
|
65
|
+
}
|
|
66
|
+
function records(ledger, key) {
|
|
67
|
+
const value = ledger[key] ?? [];
|
|
68
|
+
if (!Array.isArray(value) || !value.every(isRecord)) {
|
|
69
|
+
throw new AuditUnusableError(`Ledger field "${key}" must be an array of objects.`);
|
|
70
|
+
}
|
|
71
|
+
return value;
|
|
72
|
+
}
|
|
73
|
+
function lastStage(stages, name) {
|
|
74
|
+
for (let i = stages.length - 1; i >= 0; i--) {
|
|
75
|
+
if (stages[i]?.stage === name)
|
|
76
|
+
return stages[i];
|
|
77
|
+
}
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
function evidenceOf(stage) {
|
|
81
|
+
const value = stage?.evidence;
|
|
82
|
+
return isRecord(value) ? value : {};
|
|
83
|
+
}
|
|
84
|
+
function repositoryOf(target) {
|
|
85
|
+
return typeof target === 'string' ? target.split('#', 1)[0].trim() : '';
|
|
86
|
+
}
|
|
87
|
+
export function validateLedgerShape(ledger) {
|
|
88
|
+
if (!isRecord(ledger))
|
|
89
|
+
throw new AuditUnusableError('Ledger must be a JSON object.');
|
|
90
|
+
if (ledger.version !== 1)
|
|
91
|
+
throw new AuditUnusableError('Unsupported ledger version; expected 1.');
|
|
92
|
+
if (typeof ledger.kind !== 'string' || !KINDS.has(ledger.kind)) {
|
|
93
|
+
throw new AuditUnusableError(`Ledger kind must be one of: ${[...KINDS].join(', ')}.`);
|
|
94
|
+
}
|
|
95
|
+
if (ledger.lane !== undefined && ledger.lane !== null && (typeof ledger.lane !== 'string' || !LANES.has(ledger.lane))) {
|
|
96
|
+
throw new AuditUnusableError(`Ledger lane must be one of: ${[...LANES].join(', ')}.`);
|
|
97
|
+
}
|
|
98
|
+
const stages = records(ledger, 'stages');
|
|
99
|
+
for (let index = 0; index < stages.length; index++) {
|
|
100
|
+
const stage = stages[index];
|
|
101
|
+
if (typeof stage.stage !== 'string' || !ORDER.has(stage.stage)) {
|
|
102
|
+
throw new AuditUnusableError(`stages[${index}] has an unknown stage.`);
|
|
103
|
+
}
|
|
104
|
+
if (typeof stage.status !== 'string' || !STATUSES.has(stage.status)) {
|
|
105
|
+
throw new AuditUnusableError(`stages[${index}] has an unknown status.`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return ledger;
|
|
109
|
+
}
|
|
110
|
+
function checkPeople(ledger, audit) {
|
|
111
|
+
const people = new Map();
|
|
112
|
+
for (const auth of records(ledger, 'authorizations')) {
|
|
113
|
+
const authId = auth.id;
|
|
114
|
+
if (!isText(authId)) {
|
|
115
|
+
audit.violation('A2', 'An authorization has no id.');
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (auth.by !== 'person') {
|
|
119
|
+
audit.violation('A2', 'Only people approve; this authorization was not granted by a person.', authId);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const covers = Array.isArray(auth.covers) ? auth.covers.filter((item) => typeof item === 'string') : [];
|
|
123
|
+
people.set(authId, new Set(covers));
|
|
124
|
+
}
|
|
125
|
+
return people;
|
|
126
|
+
}
|
|
127
|
+
function checkWorktree(ledger, audit) {
|
|
128
|
+
if (ledger.kind !== 'change')
|
|
129
|
+
return;
|
|
130
|
+
const worktree = ledger.worktree;
|
|
131
|
+
if (!isRecord(worktree)) {
|
|
132
|
+
audit.violation('W1', 'Change work needs a dedicated worktree record.');
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (!isText(worktree.path))
|
|
136
|
+
audit.violation('W1', 'Worktree path is missing.');
|
|
137
|
+
const branch = worktree.branch;
|
|
138
|
+
if (!(typeof branch === 'string' && branch.startsWith('feat/') && branch.length > 'feat/'.length)) {
|
|
139
|
+
audit.violation('W1', 'Branch must be a unique feat/<task> branch.');
|
|
140
|
+
}
|
|
141
|
+
if (!isSha(worktree.base_sha))
|
|
142
|
+
audit.violation('W1', 'Default-branch base SHA is missing or not a hex SHA.');
|
|
143
|
+
}
|
|
144
|
+
function checkKind(ledger, stages, audit) {
|
|
145
|
+
if (ledger.kind === 'change')
|
|
146
|
+
return;
|
|
147
|
+
for (let index = 0; index < stages.length; index++) {
|
|
148
|
+
const name = String(stages[index].stage);
|
|
149
|
+
if (WRITE_STAGES.has(name)) {
|
|
150
|
+
audit.violation('K1', `${String(ledger.kind)} work cannot include write stages.`, `stages[${index}]`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function checkOrder(stages, audit) {
|
|
155
|
+
for (let index = 1; index < stages.length; index++) {
|
|
156
|
+
const before = String(stages[index - 1].stage);
|
|
157
|
+
const after = String(stages[index].stage);
|
|
158
|
+
if ((ORDER.get(after) ?? -1) >= (ORDER.get(before) ?? -1) || LOOP_TARGETS.has(after))
|
|
159
|
+
continue;
|
|
160
|
+
audit.violation('S2', `Stage "${after}" runs after "${before}"; loops may only return to reproduce or implement.`, `stages[${index}]`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function checkRequired(ledger, stages, audit) {
|
|
164
|
+
if (ledger.kind !== 'change')
|
|
165
|
+
return;
|
|
166
|
+
const names = stages.map((stage) => String(stage.stage));
|
|
167
|
+
const nameSet = new Set(names);
|
|
168
|
+
for (const required of REQUIRED_FOR_CHANGE) {
|
|
169
|
+
if (!nameSet.has(required))
|
|
170
|
+
audit.violation('S1', `Required stage "${required}" is missing.`);
|
|
171
|
+
}
|
|
172
|
+
const firstChange = names.indexOf('implement');
|
|
173
|
+
if (firstChange === -1)
|
|
174
|
+
return;
|
|
175
|
+
const beforeImpl = new Set(names.slice(0, firstChange));
|
|
176
|
+
for (const prerequisite of ['specify', 'reproduce']) {
|
|
177
|
+
if (!beforeImpl.has(prerequisite)) {
|
|
178
|
+
audit.violation('S3', `Stage "${prerequisite}" must come before the first implementation.`);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const lastChange = names.lastIndexOf('implement');
|
|
182
|
+
const afterLastImpl = new Set(names.slice(lastChange + 1));
|
|
183
|
+
for (const rerun of RERUN_AFTER_CHANGE) {
|
|
184
|
+
if (!afterLastImpl.has(rerun)) {
|
|
185
|
+
audit.violation('S4', `Stage "${rerun}" was not rerun after the last implementation.`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function checkStatuses(stages, audit) {
|
|
190
|
+
for (let index = 0; index < stages.length; index++) {
|
|
191
|
+
const stage = stages[index];
|
|
192
|
+
const where = `stages[${index}]`;
|
|
193
|
+
const status = String(stage.status);
|
|
194
|
+
const name = String(stage.stage);
|
|
195
|
+
if (status === 'reused' && !isText(stage.reason)) {
|
|
196
|
+
audit.violation('S5', 'Reused evidence needs a reason naming its source.', where);
|
|
197
|
+
}
|
|
198
|
+
if (status !== 'gap')
|
|
199
|
+
continue;
|
|
200
|
+
if (!isText(stage.reason))
|
|
201
|
+
audit.violation('S5', 'A gap needs a stated reason.', where);
|
|
202
|
+
if (!GAP_ALLOWED.has(name)) {
|
|
203
|
+
audit.violation('S5', `Stage "${name}" cannot be closed as a gap.`, where);
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
audit.gap('G1', `Stage "${name}" closed as a gap; tell the Code Owner.`, where);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
function checkReproduction(stages, audit) {
|
|
210
|
+
const names = stages.map((stage) => String(stage.stage));
|
|
211
|
+
const lastImplementIdx = names.lastIndexOf('implement');
|
|
212
|
+
for (let index = 0; index < stages.length; index++) {
|
|
213
|
+
const stage = stages[index];
|
|
214
|
+
if (stage.stage !== 'reproduce')
|
|
215
|
+
continue;
|
|
216
|
+
const where = `stages[${index}]`;
|
|
217
|
+
if (stage.status === 'done') {
|
|
218
|
+
const facts = evidenceOf(stage);
|
|
219
|
+
if (!isText(facts.command) || facts.result !== 'fail') {
|
|
220
|
+
audit.violation('E1', 'RED needs the test command and an observed failing result.', where);
|
|
221
|
+
}
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
if (stage.status !== 'gap')
|
|
225
|
+
continue;
|
|
226
|
+
const gapType = stage.gap_type;
|
|
227
|
+
if (typeof gapType !== 'string' || !GAP_TYPES.has(gapType)) {
|
|
228
|
+
audit.violation('E1', `A reproduction gap needs gap_type: ${[...GAP_TYPES].join(' or ')}.`, where);
|
|
229
|
+
}
|
|
230
|
+
else if (gapType === 'not-reproducible' && lastImplementIdx > index) {
|
|
231
|
+
audit.violation('E1', 'Implemented after an unreproduced bug; document the gap and stop.', where);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
function checkResults(stages, audit) {
|
|
236
|
+
const verify = lastStage(stages, 'verify');
|
|
237
|
+
const reproduce = lastStage(stages, 'reproduce');
|
|
238
|
+
if (verify !== undefined && verify.status === 'gap') {
|
|
239
|
+
if (reproduce === undefined || reproduce.gap_type !== 'no-runnable-test') {
|
|
240
|
+
audit.violation('E2', 'Verification can be a gap only when no runnable test applies.');
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
else if (verify !== undefined) {
|
|
244
|
+
const facts = evidenceOf(verify);
|
|
245
|
+
if (!isText(facts.command) || facts.result !== 'pass') {
|
|
246
|
+
audit.violation('E2', 'The last verification needs its command and a passing result.');
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
const quality = lastStage(stages, 'quality');
|
|
250
|
+
if (quality !== undefined) {
|
|
251
|
+
const facts = quality.status === 'gap' ? {} : evidenceOf(quality);
|
|
252
|
+
const failing = QUALITY_CHECKS.filter((check) => facts[check] !== 'pass');
|
|
253
|
+
if (failing.length > 0) {
|
|
254
|
+
audit.violation('Q1', `The last quality gate did not pass: ${failing.join(', ')}.`);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
function checkReview(stages, audit) {
|
|
259
|
+
const pull = lastStage(stages, 'commit_pr');
|
|
260
|
+
const review = lastStage(stages, 'review');
|
|
261
|
+
if (pull !== undefined) {
|
|
262
|
+
const facts = evidenceOf(pull);
|
|
263
|
+
if (!isText(facts.pr) || !isSha(facts.head_sha)) {
|
|
264
|
+
audit.violation('R1', 'Commit & PR needs the PR reference and the exact head SHA.');
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (review === undefined || review.status === 'gap' || pull === undefined)
|
|
268
|
+
return;
|
|
269
|
+
const facts = evidenceOf(review);
|
|
270
|
+
if (!isText(facts.score))
|
|
271
|
+
audit.violation('R1', 'The Greptile review needs the observed score.');
|
|
272
|
+
if (facts.head_sha !== evidenceOf(pull).head_sha) {
|
|
273
|
+
audit.violation('R1', 'The Greptile review is not for the current PR head.');
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
function buildRequestMap(ledger) {
|
|
277
|
+
const requests = new Map();
|
|
278
|
+
for (const req of records(ledger, 'tool_requests')) {
|
|
279
|
+
if (isText(req.id))
|
|
280
|
+
requests.set(req.id, req);
|
|
281
|
+
}
|
|
282
|
+
return requests;
|
|
283
|
+
}
|
|
284
|
+
function checkIssueLink(ledger, stages, requests, audit) {
|
|
285
|
+
const pull = lastStage(stages, 'commit_pr');
|
|
286
|
+
if (pull === undefined || pull.status === 'gap')
|
|
287
|
+
return;
|
|
288
|
+
const issue = evidenceOf(pull).issue;
|
|
289
|
+
if (!isText(issue))
|
|
290
|
+
return;
|
|
291
|
+
if (evidenceOf(pull).issue_linked !== true) {
|
|
292
|
+
audit.violation('R2', 'PR opened for a canonical issue must record issue_linked: true.');
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
const hasUse = records(ledger, 'tool_uses').some((use) => {
|
|
296
|
+
if (use.tool !== 'github-write' || use.target !== issue)
|
|
297
|
+
return false;
|
|
298
|
+
const req = isText(use.request) ? requests.get(use.request) : undefined;
|
|
299
|
+
return req !== undefined && req.disposition === 'eligible' && typeof req.purpose === 'string' && ISSUE_LINK_PURPOSES.has(req.purpose);
|
|
300
|
+
});
|
|
301
|
+
if (!hasUse) {
|
|
302
|
+
audit.violation('R2', 'PR opened for a canonical issue must link the PR back on that issue via Tool Depot.');
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
function checkVisuals(ledger, requests, audit) {
|
|
306
|
+
const uses = records(ledger, 'tool_uses');
|
|
307
|
+
for (let index = 0; index < uses.length; index++) {
|
|
308
|
+
const use = uses[index];
|
|
309
|
+
const req = isText(use.request) ? requests.get(use.request) : undefined;
|
|
310
|
+
if (req === undefined || typeof req.purpose !== 'string' || !ISSUE_WRITE_PURPOSES.has(req.purpose))
|
|
311
|
+
continue;
|
|
312
|
+
const where = `tool_uses[${index}]`;
|
|
313
|
+
const visual = use.visual;
|
|
314
|
+
if (typeof visual === 'string' && visual.startsWith('https://'))
|
|
315
|
+
continue;
|
|
316
|
+
if (isRecord(visual) && isText(visual.gap)) {
|
|
317
|
+
audit.gap('G2', 'Issue write has no visual reference; the stated gap travels with the PR.', where);
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
audit.violation('V1', 'Issue write needs a visual reference URL or a stated visual gap.', where);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
function checkDedup(ledger, requests, audit) {
|
|
324
|
+
const searched = new Set();
|
|
325
|
+
const uses = records(ledger, 'tool_uses');
|
|
326
|
+
for (let index = 0; index < uses.length; index++) {
|
|
327
|
+
const use = uses[index];
|
|
328
|
+
const req = isText(use.request) ? requests.get(use.request) : undefined;
|
|
329
|
+
if (req === undefined || req.disposition !== 'eligible')
|
|
330
|
+
continue;
|
|
331
|
+
const repo = repositoryOf(use.target);
|
|
332
|
+
if (req.purpose === 'check-duplicate-issues' && repo !== '') {
|
|
333
|
+
searched.add(repo);
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
if (typeof req.purpose === 'string' && DEDUP_GUARDED_PURPOSES.has(req.purpose) && !searched.has(repo)) {
|
|
337
|
+
audit.violation('D1', 'Issue filed or reopened without an earlier duplicate search of the same repository.', `tool_uses[${index}]`);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
function checkTriage(ledger, requests, audit) {
|
|
342
|
+
const read = new Set();
|
|
343
|
+
const pending = new Map();
|
|
344
|
+
const uses = records(ledger, 'tool_uses');
|
|
345
|
+
for (let index = 0; index < uses.length; index++) {
|
|
346
|
+
const use = uses[index];
|
|
347
|
+
const req = isText(use.request) ? requests.get(use.request) : undefined;
|
|
348
|
+
if (req === undefined || req.disposition !== 'eligible')
|
|
349
|
+
continue;
|
|
350
|
+
const target = use.target;
|
|
351
|
+
const purpose = req.purpose;
|
|
352
|
+
if (purpose === 'check-issue-triage') {
|
|
353
|
+
read.add(target);
|
|
354
|
+
}
|
|
355
|
+
else if (purpose === 'triage-approved-issue') {
|
|
356
|
+
if (!read.has(target)) {
|
|
357
|
+
audit.violation('I1', 'Issue triaged without an earlier check-issue-triage read of the same issue.', `tool_uses[${index}]`);
|
|
358
|
+
}
|
|
359
|
+
pending.set(target, index);
|
|
360
|
+
}
|
|
361
|
+
else if (purpose === 'comment-approved-issue') {
|
|
362
|
+
pending.delete(target);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
const remaining = [...pending.values()].sort((a, b) => a - b);
|
|
366
|
+
for (const index of remaining) {
|
|
367
|
+
audit.violation('I2', 'Triage applied without a later comment on the issue that states it.', `tool_uses[${index}]`);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
function canonicalIssue(ledger, stages) {
|
|
371
|
+
if (isText(ledger.issue))
|
|
372
|
+
return ledger.issue.trim();
|
|
373
|
+
const pull = lastStage(stages, 'commit_pr');
|
|
374
|
+
const issue = pull !== undefined ? evidenceOf(pull).issue : undefined;
|
|
375
|
+
return isText(issue) ? issue.trim() : undefined;
|
|
376
|
+
}
|
|
377
|
+
function firstUseIndex(ledger, requests, purpose, target) {
|
|
378
|
+
const uses = records(ledger, 'tool_uses');
|
|
379
|
+
for (let index = 0; index < uses.length; index++) {
|
|
380
|
+
const use = uses[index];
|
|
381
|
+
const req = isText(use.request) ? requests.get(use.request) : undefined;
|
|
382
|
+
if (req !== undefined && req.disposition === 'eligible' && req.purpose === purpose && use.target === target) {
|
|
383
|
+
return index;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
return undefined;
|
|
387
|
+
}
|
|
388
|
+
function checkClaim(ledger, stages, people, requests, audit) {
|
|
389
|
+
if (ledger.kind !== 'change')
|
|
390
|
+
return;
|
|
391
|
+
const issue = canonicalIssue(ledger, stages);
|
|
392
|
+
if (issue === undefined)
|
|
393
|
+
return;
|
|
394
|
+
const names = stages.map((stage) => String(stage.stage));
|
|
395
|
+
const index = names.lastIndexOf('claim');
|
|
396
|
+
if (index === -1) {
|
|
397
|
+
audit.violation('C1', 'Work on a canonical issue needs a claim stage before RED.');
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
const claim = stages[index];
|
|
401
|
+
const where = `stages[${index}]`;
|
|
402
|
+
if (claim.status === 'gap')
|
|
403
|
+
return;
|
|
404
|
+
const facts = evidenceOf(claim);
|
|
405
|
+
if (facts.issue !== issue)
|
|
406
|
+
audit.violation('C2', 'The claim is not for the canonical issue of this delivery.', where);
|
|
407
|
+
if (!isText(facts.claimant))
|
|
408
|
+
audit.violation('C2', 'The claim must name the claimant login.', where);
|
|
409
|
+
const check = typeof facts.check === 'string' ? facts.check : '';
|
|
410
|
+
if (CLAIM_HELD.has(check)) {
|
|
411
|
+
const handover = typeof facts.handover === 'string' ? facts.handover : '';
|
|
412
|
+
const covers = people.get(handover);
|
|
413
|
+
if (covers === undefined || !covers.has('claim')) {
|
|
414
|
+
audit.violation('C2', 'The issue was held by someone else; a handover needs a person authorization that covers claim.', where);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
else if (!CLAIM_FREE.has(check)) {
|
|
418
|
+
audit.violation('C2', 'The check verdict must be free or claimed-by-you (or a handover).', where);
|
|
419
|
+
}
|
|
420
|
+
if (facts.verify !== 'claimed-by-you') {
|
|
421
|
+
audit.violation('C2', 'The recheck after claiming must be claimed-by-you.', where);
|
|
422
|
+
}
|
|
423
|
+
const readAt = firstUseIndex(ledger, requests, 'check-issue-claim', issue);
|
|
424
|
+
const writeAt = firstUseIndex(ledger, requests, 'claim-approved-issue', issue);
|
|
425
|
+
if (readAt === undefined)
|
|
426
|
+
audit.violation('C3', 'No eligible check-issue-claim read of the canonical issue.', where);
|
|
427
|
+
if (writeAt === undefined && check !== 'claimed-by-you') {
|
|
428
|
+
audit.violation('C3', 'The claim was never recorded on GitHub through claim-approved-issue.', where);
|
|
429
|
+
}
|
|
430
|
+
if (writeAt !== undefined && readAt !== undefined && writeAt < readAt) {
|
|
431
|
+
audit.violation('C3', 'The claim was written before the issue was checked.', where);
|
|
432
|
+
}
|
|
433
|
+
const numMatch = ISSUE_NUMBER_RE.exec(issue);
|
|
434
|
+
const worktreeBranch = isRecord(ledger.worktree) ? String(ledger.worktree.branch ?? '') : '';
|
|
435
|
+
const branchMatch = CLAIM_BRANCH_RE.exec(worktreeBranch);
|
|
436
|
+
if (numMatch === null || branchMatch === null || branchMatch[1] !== numMatch[1]) {
|
|
437
|
+
audit.violation('C4', 'The worktree branch must be feat/<issue-number>-<slug> for the canonical issue.');
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
function checkAuthorizations(stages, people, audit) {
|
|
441
|
+
for (let index = 0; index < stages.length; index++) {
|
|
442
|
+
const stage = stages[index];
|
|
443
|
+
const name = String(stage.stage);
|
|
444
|
+
const where = `stages[${index}]`;
|
|
445
|
+
if (HUMAN_STAGES.has(name) && stage.actor !== 'person') {
|
|
446
|
+
audit.violation('H1', `Stage "${name}" belongs to a person, not an agent.`, where);
|
|
447
|
+
}
|
|
448
|
+
if (!AUTHORIZED_STAGES.has(name) || stage.status === 'gap')
|
|
449
|
+
continue;
|
|
450
|
+
const authId = typeof stage.authorization === 'string' ? stage.authorization : '';
|
|
451
|
+
const covers = people.get(authId);
|
|
452
|
+
if (covers === undefined) {
|
|
453
|
+
audit.violation('A1', `Stage "${name}" has no authorization granted by a person.`, where);
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
456
|
+
const allowed = COVERED_BY[name] ?? [name];
|
|
457
|
+
if (!allowed.some((item) => covers.has(item))) {
|
|
458
|
+
audit.violation('A1', `The cited authorization does not cover "${name}".`, where);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
const names = stages.map((stage) => String(stage.stage));
|
|
463
|
+
const releaseIdx = names.indexOf('release_owner');
|
|
464
|
+
if (releaseIdx !== -1 && !names.slice(0, releaseIdx).includes('code_owner')) {
|
|
465
|
+
audit.violation('H2', 'A deployment decision needs a prior Code Owner review.');
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
function checkTools(ledger, catalog, people, audit) {
|
|
469
|
+
const requests = new Map();
|
|
470
|
+
for (const request of records(ledger, 'tool_requests')) {
|
|
471
|
+
const requestId = request.id;
|
|
472
|
+
if (!isText(requestId)) {
|
|
473
|
+
audit.violation('T6', 'A Tool Depot request has no id.');
|
|
474
|
+
continue;
|
|
475
|
+
}
|
|
476
|
+
requests.set(requestId, request);
|
|
477
|
+
const missing = ['requester', 'tool', 'purpose', 'target', 'operation', 'disposition'].filter((key) => !isText(request[key]));
|
|
478
|
+
if (missing.length > 0) {
|
|
479
|
+
audit.violation('T6', `Tool Depot request is incomplete: ${missing.join(', ')}.`, requestId);
|
|
480
|
+
}
|
|
481
|
+
if (request.disposition !== 'eligible')
|
|
482
|
+
continue;
|
|
483
|
+
const tool = typeof request.tool === 'string' ? request.tool : '';
|
|
484
|
+
const purposes = catalog.get(tool);
|
|
485
|
+
if (purposes === undefined || typeof request.purpose !== 'string' || !purposes.has(request.purpose)) {
|
|
486
|
+
audit.violation('T3', 'Eligible request uses a tool or purpose that is not in the catalog.', requestId);
|
|
487
|
+
}
|
|
488
|
+
if (WRITE_TOOLS.has(tool) && (typeof request.authorization !== 'string' || !people.has(request.authorization))) {
|
|
489
|
+
audit.violation('T5', 'A GitHub write needs an authorization granted by a person.', requestId);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
const uses = records(ledger, 'tool_uses');
|
|
493
|
+
for (let index = 0; index < uses.length; index++) {
|
|
494
|
+
const use = uses[index];
|
|
495
|
+
const where = `tool_uses[${index}]`;
|
|
496
|
+
const request = isText(use.request) ? requests.get(use.request) : undefined;
|
|
497
|
+
if (request === undefined) {
|
|
498
|
+
audit.violation('T1', 'External tool used without a Tool Depot request.', where);
|
|
499
|
+
continue;
|
|
500
|
+
}
|
|
501
|
+
if (request.disposition !== 'eligible') {
|
|
502
|
+
audit.violation('T2', 'Tool used although the Depot did not return eligible.', where);
|
|
503
|
+
}
|
|
504
|
+
if (use.tool !== request.tool || use.target !== request.target) {
|
|
505
|
+
audit.violation('T4', 'Tool or target differs from the eligible request.', where);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
function checkLane(ledger, stages, audit) {
|
|
510
|
+
if (ledger.lane !== 'high-risk')
|
|
511
|
+
return;
|
|
512
|
+
const residual = lastStage(stages, 'residual_risk');
|
|
513
|
+
if (residual === undefined || residual.status !== 'done') {
|
|
514
|
+
audit.violation('L1', 'High-risk lane requires a completed residual_risk assessment.');
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
function serverTarget(command) {
|
|
518
|
+
const logs = GATE_LOGS_RE.exec(command);
|
|
519
|
+
if (logs !== null)
|
|
520
|
+
return { name: logs[1], isPrefix: false };
|
|
521
|
+
const ps = GATE_PS_RE.exec(command);
|
|
522
|
+
if (ps !== null)
|
|
523
|
+
return { name: ps[1].replaceAll('\\.', '.'), isPrefix: true };
|
|
524
|
+
return { name: null, isPrefix: false };
|
|
525
|
+
}
|
|
526
|
+
function checkServerLog(ledger, commands, audit) {
|
|
527
|
+
const uses = records(ledger, 'tool_uses')
|
|
528
|
+
.filter((use) => use.tool === 'ssh')
|
|
529
|
+
.map((use) => {
|
|
530
|
+
const text = typeof use.target === 'string' ? use.target : '';
|
|
531
|
+
return new Set(text.match(TARGET_TOKEN_RE) ?? []);
|
|
532
|
+
});
|
|
533
|
+
for (let index = 0; index < commands.length; index++) {
|
|
534
|
+
const command = commands[index];
|
|
535
|
+
const { name, isPrefix } = serverTarget(command);
|
|
536
|
+
const wanted = isPrefix && name !== null ? [`${name}*`, name] : name !== null ? [name] : [];
|
|
537
|
+
const matchIndex = name === null
|
|
538
|
+
? -1
|
|
539
|
+
: uses.findIndex((tokens) => wanted.some((token) => tokens.has(token)));
|
|
540
|
+
if (matchIndex === -1) {
|
|
541
|
+
audit.violation('T7', `The server ran an SSH command with no matching ssh tool_use in the ledger: ${command.slice(0, 160)}`, `server_log[${index}]`);
|
|
542
|
+
}
|
|
543
|
+
else {
|
|
544
|
+
uses.splice(matchIndex, 1);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
export function auditLedgerData(rawLedger, catalog, serverCommands = null) {
|
|
549
|
+
const ledger = validateLedgerShape(rawLedger);
|
|
550
|
+
const audit = new AuditCollector();
|
|
551
|
+
const stages = records(ledger, 'stages');
|
|
552
|
+
const requests = buildRequestMap(ledger);
|
|
553
|
+
const people = checkPeople(ledger, audit);
|
|
554
|
+
checkWorktree(ledger, audit);
|
|
555
|
+
checkKind(ledger, stages, audit);
|
|
556
|
+
checkOrder(stages, audit);
|
|
557
|
+
checkRequired(ledger, stages, audit);
|
|
558
|
+
checkStatuses(stages, audit);
|
|
559
|
+
checkReproduction(stages, audit);
|
|
560
|
+
checkResults(stages, audit);
|
|
561
|
+
checkReview(stages, audit);
|
|
562
|
+
checkLane(ledger, stages, audit);
|
|
563
|
+
checkIssueLink(ledger, stages, requests, audit);
|
|
564
|
+
checkVisuals(ledger, requests, audit);
|
|
565
|
+
checkDedup(ledger, requests, audit);
|
|
566
|
+
checkTriage(ledger, requests, audit);
|
|
567
|
+
checkClaim(ledger, stages, people, requests, audit);
|
|
568
|
+
checkAuthorizations(stages, people, audit);
|
|
569
|
+
checkTools(ledger, catalog, people, audit);
|
|
570
|
+
if (serverCommands !== null)
|
|
571
|
+
checkServerLog(ledger, serverCommands, audit);
|
|
572
|
+
const verdict = audit.violations.length > 0 ? 'violations' : audit.gaps.length > 0 ? 'gaps' : 'conforms';
|
|
573
|
+
return {
|
|
574
|
+
verdict,
|
|
575
|
+
violations: audit.violations,
|
|
576
|
+
gaps: audit.gaps,
|
|
577
|
+
checked: {
|
|
578
|
+
stages: stages.length,
|
|
579
|
+
tool_requests: records(ledger, 'tool_requests').length,
|
|
580
|
+
tool_uses: records(ledger, 'tool_uses').length,
|
|
581
|
+
},
|
|
582
|
+
};
|
|
583
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function defaultCatalogPath(): string;
|
|
2
|
+
export declare function loadJsonFile(path: string, label: string): unknown;
|
|
3
|
+
export declare function loadCatalogFile(path: string): Map<string, Set<string>>;
|
|
4
|
+
export declare function loadServerLogFile(path: string): string[];
|
|
5
|
+
export declare function resolveDefaultLedgerPath(): string;
|