opencode-agent-harness 0.0.0-stage → 0.3.14
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 +217 -0
- package/LICENSE +21 -0
- package/README.md +636 -2
- package/bin/agent-harness.js +3182 -0
- package/contrib/global-plugins/README.md +49 -0
- package/contrib/global-plugins/harness-freshness.ts +355 -0
- package/package.json +86 -4
- package/templates/.agents/AGENTS.md +148 -0
- package/templates/.agents/features/INDEX.md +10 -0
- package/templates/.agents/handoffs/README.md +87 -0
- package/templates/.agents/memory/dev-loop.md +59 -0
- package/templates/.agents/memory/domain-map.md +29 -0
- package/templates/.agents/memory/environments.md +35 -0
- package/templates/.agents/memory/flow-map.md +23 -0
- package/templates/.agents/memory/history.md +7 -0
- package/templates/.agents/memory/locations.md +14 -0
- package/templates/.agents/memory/model-routing.md +261 -0
- package/templates/.agents/memory/orchestration.md +183 -0
- package/templates/.agents/memory/owned-files.md +19 -0
- package/templates/.agents/memory/product-principles.md +37 -0
- package/templates/.agents/memory/quality-parameters.md +37 -0
- package/templates/.agents/memory/stack-versions.md +35 -0
- package/templates/.agents/memory/test-design-parameters.md +36 -0
- package/templates/.agents/nightly.json +17 -0
- package/templates/.agents/qa-plans/README.md +70 -0
- package/templates/.agents/qa-runs/README.md +21 -0
- package/templates/.agents/reviews/README.md +47 -0
- package/templates/.agents/rules/00-operating.md +199 -0
- package/templates/.agents/skills/data-engineer/SKILL.md +31 -0
- package/templates/.agents/skills/devops-engineer/SKILL.md +50 -0
- package/templates/.agents/skills/diagnostics-expert/SKILL.md +44 -0
- package/templates/.agents/skills/docs/SKILL.md +140 -0
- package/templates/.agents/skills/features/SKILL.md +187 -0
- package/templates/.agents/skills/frontend-engineer/SKILL.md +81 -0
- package/templates/.agents/skills/handoff/SKILL.md +85 -0
- package/templates/.agents/skills/mobile-engineer/SKILL.md +101 -0
- package/templates/.agents/skills/planner/SKILL.md +112 -0
- package/templates/.agents/skills/product-manager/SKILL.md +115 -0
- package/templates/.agents/skills/qa-architect/SKILL.md +224 -0
- package/templates/.agents/skills/qa-runner/SKILL.md +64 -0
- package/templates/.agents/skills/security-engineer/SKILL.md +53 -0
- package/templates/.agents/skills/system-architect/SKILL.md +42 -0
- package/templates/.agents/skills/ui-designer/SKILL.md +71 -0
- package/templates/.github/workflows/ci.yml +148 -0
- package/templates/.github/workflows/deploy-uat.yml +95 -0
- package/templates/.github/workflows/nightly.yml +83 -0
- package/templates/.github/workflows/uat-health.yml +41 -0
- package/templates/.husky/pre-push +23 -0
- package/templates/.ignore +28 -0
- package/templates/.opencode/agents/data-engineer.md +37 -0
- package/templates/.opencode/agents/devops-engineer.md +37 -0
- package/templates/.opencode/agents/diagnostics-expert.md +37 -0
- package/templates/.opencode/agents/docs.md +37 -0
- package/templates/.opencode/agents/features.md +21 -0
- package/templates/.opencode/agents/frontend-engineer.md +37 -0
- package/templates/.opencode/agents/handoff.md +21 -0
- package/templates/.opencode/agents/mobile-engineer.md +37 -0
- package/templates/.opencode/agents/planner.md +34 -0
- package/templates/.opencode/agents/product-manager.md +29 -0
- package/templates/.opencode/agents/qa-architect.md +27 -0
- package/templates/.opencode/agents/qa-runner.md +17 -0
- package/templates/.opencode/agents/security-engineer.md +37 -0
- package/templates/.opencode/agents/system-architect.md +37 -0
- package/templates/.opencode/agents/ui-designer.md +37 -0
- package/templates/.opencode/commands/board.md +15 -0
- package/templates/.opencode/commands/checkpoint.md +25 -0
- package/templates/.opencode/commands/feature.md +56 -0
- package/templates/.opencode/commands/finish.md +36 -0
- package/templates/.opencode/commands/next.md +49 -0
- package/templates/.opencode/commands/report.md +55 -0
- package/templates/.opencode/commands/resume.md +39 -0
- package/templates/.opencode/commands/switch-model.md +34 -0
- package/templates/.opencode/commands/tidy.md +49 -0
- package/templates/.opencode/plugins/backlog-notify.ts +57 -0
- package/templates/.opencode/plugins/backlog.ts +272 -0
- package/templates/.opencode/plugins/checkpoint.ts +160 -0
- package/templates/.opencode/plugins/context-guard.ts +1164 -0
- package/templates/.opencode/plugins/diff.ts +85 -0
- package/templates/.opencode/plugins/gates.ts +71 -0
- package/templates/.opencode/plugins/job-notify.ts +241 -0
- package/templates/.opencode/plugins/orient.ts +67 -0
- package/templates/.opencode/plugins/session.ts +89 -0
- package/templates/.opencode/plugins/wait.ts +101 -0
- package/templates/.opencode/plugins/where.ts +70 -0
- package/templates/.opencode/skills/bounded-explore/SKILL.md +38 -0
- package/templates/.opencode/skills/dev-loop/SKILL.md +87 -0
- package/templates/.vercelignore +16 -0
- package/templates/AGENTS.md +27 -0
- package/templates/BACKLOG.md +95 -0
- package/templates/docs/ci-cd-pipeline.md +81 -0
- package/templates/docs/gates.md +128 -0
- package/templates/docs/mcp-integrations.md +97 -0
- package/templates/docs/mobile-testing.md +555 -0
- package/templates/docs/nightly-testing.md +106 -0
- package/templates/docs/wsl-optimizations.md +290 -0
- package/templates/opencode.json +188 -0
- package/templates/scripts/agent-report.js +541 -0
- package/templates/scripts/agent-search.sh +117 -0
- package/templates/scripts/backlog.js +1924 -0
- package/templates/scripts/board-service.sh +214 -0
- package/templates/scripts/checkpoint.js +290 -0
- package/templates/scripts/finalize.js +416 -0
- package/templates/scripts/nightly.js +913 -0
- package/templates/scripts/orient.js +514 -0
- package/templates/scripts/qa/board-client.js +323 -0
- package/templates/scripts/qa/board-lib.js +96 -0
- package/templates/scripts/qa/board-sync.js +499 -0
- package/templates/scripts/qa/capacity-lib.js +916 -0
- package/templates/scripts/qa/check-backlog.js +434 -0
- package/templates/scripts/qa/check-capacity.js +85 -0
- package/templates/scripts/qa/check-ci-policy.js +164 -0
- package/templates/scripts/qa/check-concurrency.js +344 -0
- package/templates/scripts/qa/check-dispatch-config.js +296 -0
- package/templates/scripts/qa/check-docs.js +288 -0
- package/templates/scripts/qa/check-integrate.js +98 -0
- package/templates/scripts/qa/check-linger.js +160 -0
- package/templates/scripts/qa/check-prefix-stability.js +187 -0
- package/templates/scripts/qa/check-product.js +177 -0
- package/templates/scripts/qa/check-qa-plan.js +378 -0
- package/templates/scripts/qa/check-qa-scripts.js +85 -0
- package/templates/scripts/qa/check-quality.js +249 -0
- package/templates/scripts/qa/check-test-wiring.js +253 -0
- package/templates/scripts/qa/check-worktrees.js +93 -0
- package/templates/scripts/qa/ci-triage.js +346 -0
- package/templates/scripts/qa/ci-usage-lib.js +185 -0
- package/templates/scripts/qa/ci-wait-lib.js +294 -0
- package/templates/scripts/qa/command-classifier.js +552 -0
- package/templates/scripts/qa/context-guard-core.js +1618 -0
- package/templates/scripts/qa/diff.js +174 -0
- package/templates/scripts/qa/feature-scaffold.js +224 -0
- package/templates/scripts/qa/fixtures/backlog.md +104 -0
- package/templates/scripts/qa/governance.js +174 -0
- package/templates/scripts/qa/hash-file.js +32 -0
- package/templates/scripts/qa/lease-lib.js +263 -0
- package/templates/scripts/qa/merge-backlog.js +324 -0
- package/templates/scripts/qa/mobile-e2e/analyze-timings.js +300 -0
- package/templates/scripts/qa/mobile-e2e/apk-cache.js +420 -0
- package/templates/scripts/qa/mobile-e2e/backend-build-cache.js +203 -0
- package/templates/scripts/qa/mobile-e2e/boot-emulator.sh +432 -0
- package/templates/scripts/qa/mobile-e2e/build-apk.sh +210 -0
- package/templates/scripts/qa/mobile-e2e/check-flows.js +568 -0
- package/templates/scripts/qa/mobile-e2e/config.yaml +18 -0
- package/templates/scripts/qa/mobile-e2e/device-down.sh +88 -0
- package/templates/scripts/qa/mobile-e2e/device-up.sh +258 -0
- package/templates/scripts/qa/mobile-e2e/ios-simulator-down.sh +72 -0
- package/templates/scripts/qa/mobile-e2e/ios-simulator-up.sh +153 -0
- package/templates/scripts/qa/mobile-e2e/job-events.js +181 -0
- package/templates/scripts/qa/mobile-e2e/prewarm.sh +56 -0
- package/templates/scripts/qa/mobile-e2e/run-detached.sh +222 -0
- package/templates/scripts/qa/mobile-e2e/run-maestro.js +1543 -0
- package/templates/scripts/qa/mobile-e2e/ui-dump.js +327 -0
- package/templates/scripts/qa/models.allowlist.txt +32 -0
- package/templates/scripts/qa/provider-stats.js +878 -0
- package/templates/scripts/qa/run-clean.js +83 -0
- package/templates/scripts/qa/run-gates.js +213 -0
- package/templates/scripts/qa/run-loop.js +220 -0
- package/templates/scripts/qa/session-recon.js +512 -0
- package/templates/scripts/qa/store-lib.js +324 -0
- package/templates/scripts/qa/tool-lib.js +134 -0
- package/templates/scripts/qa/where.js +214 -0
- package/templates/scripts/qa/worktree-hygiene.js +217 -0
- package/templates/scripts/qa/wslconfig-merge.js +157 -0
- package/templates/scripts/serve.js +1328 -0
- package/templates/scripts/setup-nightly.sh +185 -0
- package/templates/scripts/setup-tmpfs.sh +374 -0
- package/templates/scripts/ship.js +586 -0
- package/templates/scripts/switch-reasoning-model.ps1 +101 -0
- package/templates/scripts/switch-reasoning-model.sh +104 -0
- package/templates/scripts/wait-for.js +342 -0
- package/templates/scripts/wsl-gpu.sh +180 -0
- package/templates/scripts/wsl-tune.sh +319 -0
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/*
|
|
4
|
+
* test:backlog — canonical-single-backlog gate (repo guard).
|
|
5
|
+
*
|
|
6
|
+
* Mechanically enforces the harness's ONE-write-path rule: `BACKLOG.md` at the
|
|
7
|
+
* repo root is the single source of truth for open work, and every other list
|
|
8
|
+
* (`.agents/features/INDEX.md`, `.agents/memory/todo.md`) is a pointer (or
|
|
9
|
+
* absent), never a live list.
|
|
10
|
+
*
|
|
11
|
+
* 1. Only ONE canonical backlog file exists: the repo-root `BACKLOG.md`.
|
|
12
|
+
* 2. Priority values are from {P1..P4} and apply to open rows only.
|
|
13
|
+
* 3. Every `frozen` row has a non-empty "why / reopen" condition.
|
|
14
|
+
* 4. Every `open` row has non-empty priority and evidence cells. `?` is
|
|
15
|
+
* allowed but must be explicit — a blank cell is a failure.
|
|
16
|
+
* 5. Every `in progress` row has non-empty task and handoff cells (`?` allowed
|
|
17
|
+
* for handoff, but not blank).
|
|
18
|
+
* 6. No duplicate IDs across the whole file.
|
|
19
|
+
* 7. `INDEX.md` / `todo.md`, if present, are pointers (content referencing
|
|
20
|
+
* BACKLOG.md), not live row lists.
|
|
21
|
+
* 8. `BACKLOG.md` is git-tracked (committed), not untracked — the board syncs
|
|
22
|
+
* across sessions only through git. Skipped outside a git repo.
|
|
23
|
+
*/
|
|
24
|
+
const fs = require("fs");
|
|
25
|
+
const path = require("path");
|
|
26
|
+
const { execFileSync } = require("child_process");
|
|
27
|
+
const { splitCells, findCycle } = require("./board-lib.js");
|
|
28
|
+
|
|
29
|
+
const root = path.resolve(__dirname, "..", "..");
|
|
30
|
+
|
|
31
|
+
const PRIORITY = new Set(["P1", "P2", "P3", "P4"]);
|
|
32
|
+
|
|
33
|
+
const failures = [];
|
|
34
|
+
const warnings = [];
|
|
35
|
+
const check = (ok, msg) => {
|
|
36
|
+
console.log(` ${ok ? "\u2713" : "\u2717"} ${msg}`);
|
|
37
|
+
if (!ok) failures.push(msg);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/* ADR 0001: when the board service is the backend, the gate validates the
|
|
41
|
+
* SERVICE's board (the service enforces every invariant on write), not the
|
|
42
|
+
* legacy file. We map the service JSON into the same `lines`-based `buckets`
|
|
43
|
+
* shape the checks below already consume, so one implementation covers both. */
|
|
44
|
+
const boardClient = (() => {
|
|
45
|
+
try {
|
|
46
|
+
return require("./board-client.js");
|
|
47
|
+
} catch {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
})();
|
|
51
|
+
const serviceActive = boardClient && boardClient.enabled(root);
|
|
52
|
+
const useService = serviceActive && !process.argv.includes("--file");
|
|
53
|
+
|
|
54
|
+
if (useService) {
|
|
55
|
+
console.log("backlog gate \u2014 board service integrity (BACKLOG_BACKEND=service)");
|
|
56
|
+
} else {
|
|
57
|
+
console.log("backlog gate \u2014 canonical single-file BACKLOG.md");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function insideGitRepo() {
|
|
61
|
+
try {
|
|
62
|
+
const r = execFileSync("git", ["rev-parse", "--is-inside-work-tree"], {
|
|
63
|
+
cwd: root,
|
|
64
|
+
stdio: "pipe",
|
|
65
|
+
});
|
|
66
|
+
return (r.toString() || "").trim() === "true";
|
|
67
|
+
} catch (_) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function gitTracked(rel) {
|
|
72
|
+
try {
|
|
73
|
+
const r = execFileSync("git", ["ls-files", "--error-unmatch", rel], {
|
|
74
|
+
cwd: root,
|
|
75
|
+
stdio: "pipe",
|
|
76
|
+
});
|
|
77
|
+
return (r.toString() || "").trim().length > 0;
|
|
78
|
+
} catch (_) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/* Git-tracked paths matching a pathspec glob (relative to the repo root). */
|
|
83
|
+
function gitLsFiles(pattern) {
|
|
84
|
+
try {
|
|
85
|
+
const r = execFileSync("git", ["ls-files", "--", pattern], {
|
|
86
|
+
cwd: root,
|
|
87
|
+
stdio: "pipe",
|
|
88
|
+
});
|
|
89
|
+
return (r.toString() || "")
|
|
90
|
+
.split(/\r?\n/)
|
|
91
|
+
.map((s) => s.trim())
|
|
92
|
+
.filter(Boolean);
|
|
93
|
+
} catch (_) {
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/* Render the service `BacklogBoard` JSON as markdown table lines, so the shared
|
|
99
|
+
* row checks below run against it unchanged. */
|
|
100
|
+
function serviceBoardToLines(board) {
|
|
101
|
+
const cell = (v) => String(v == null ? "" : v).replace(/\|/g, "/").replace(/\s+/g, " ").trim();
|
|
102
|
+
const row = (cells) => "| " + cells.map(cell).join(" | ") + " |";
|
|
103
|
+
const out = [];
|
|
104
|
+
out.push("## Epics", "", "| Key | Label | Goal |", "|---|---|---|");
|
|
105
|
+
for (const e of board.epics || []) out.push(row([e.key, e.label, e.goal]));
|
|
106
|
+
out.push("", "## In progress", "", "| ID | Epic | Task | Handoff |", "|---|---|---|---|");
|
|
107
|
+
for (const r of board.inprogress || []) out.push(row([r.id, r.epic, r.task, r.handoff]));
|
|
108
|
+
for (const [key, label] of [["queued", "Queued"], ["open", "Open"]]) {
|
|
109
|
+
out.push("", `## ${label}`, "", "| ID | P | Epic | Task | Evidence | Depends on |", "|---|---|---|---|---|---|");
|
|
110
|
+
for (const r of board[key] || []) out.push(row([r.id, r.priority, r.epic, r.task, r.evidence, r.dependsOn]));
|
|
111
|
+
}
|
|
112
|
+
out.push("", "## Frozen", "", "| ID | Epic | Task | Why frozen / reopen when |", "|---|---|---|---|");
|
|
113
|
+
for (const r of board.frozen || []) out.push(row([r.id, r.epic, r.task, r.condition]));
|
|
114
|
+
out.push("", "## Archive (shipped · done)", "", "| ID | Epic | Task | Closed |", "|---|---|---|---|");
|
|
115
|
+
for (const r of board.archive || []) out.push(row([r.id, r.epic, r.task, r.closed]));
|
|
116
|
+
return out;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
let lines;
|
|
120
|
+
if (useService) {
|
|
121
|
+
let snapshot;
|
|
122
|
+
try {
|
|
123
|
+
snapshot = boardClient.getBoard(root);
|
|
124
|
+
} catch (e) {
|
|
125
|
+
console.error(`FATAL: board service unreachable — ${e.message}`);
|
|
126
|
+
process.exit(2);
|
|
127
|
+
}
|
|
128
|
+
// The service enforces uniqueness/priority/evidence/cycles on write; the gate
|
|
129
|
+
// still re-verifies structure so a corrupt row can never slip through.
|
|
130
|
+
check(true, "board service reachable (BACKLOG_BACKEND=service)");
|
|
131
|
+
// The stray scan must not count the harness's own template board: every
|
|
132
|
+
// project repo ships `templates/BACKLOG.md` as a scaffold source, never as a
|
|
133
|
+
// live board. Only a stray *project* board is a defect.
|
|
134
|
+
const strays = insideGitRepo()
|
|
135
|
+
? gitLsFiles("*BACKLOG.md").filter((f) => f !== "BACKLOG.md" && !f.startsWith("templates/"))
|
|
136
|
+
: [];
|
|
137
|
+
check(strays.length === 0, `no stray BACKLOG.md boards (found: ${strays.join(", ") || "none"})`);
|
|
138
|
+
lines = serviceBoardToLines(snapshot);
|
|
139
|
+
} else {
|
|
140
|
+
// ---- 1. Only ONE canonical backlog file ----------------------------------
|
|
141
|
+
const canonical = path.join(root, "BACKLOG.md");
|
|
142
|
+
if (!fs.existsSync(canonical)) {
|
|
143
|
+
console.error("FATAL: missing BACKLOG.md at repo root (the canonical task list)");
|
|
144
|
+
process.exit(2);
|
|
145
|
+
}
|
|
146
|
+
check(true, "canonical BACKLOG.md present at repo root");
|
|
147
|
+
|
|
148
|
+
// No stray/secondary boards: the root file is the ONLY canonical board.
|
|
149
|
+
if (insideGitRepo()) {
|
|
150
|
+
const strays = gitLsFiles("*BACKLOG.md").filter(
|
|
151
|
+
(f) => f !== "BACKLOG.md" && !f.startsWith("templates/")
|
|
152
|
+
);
|
|
153
|
+
check(strays.length === 0, `no stray BACKLOG.md boards (found: ${strays.join(", ") || "none"})`);
|
|
154
|
+
} else {
|
|
155
|
+
check(true, "not a git repo \u2014 skipping stray BACKLOG.md check");
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// ---- 7. BACKLOG.md must be git-tracked (committed), not untracked --------
|
|
159
|
+
if (insideGitRepo()) {
|
|
160
|
+
check(
|
|
161
|
+
gitTracked("BACKLOG.md"),
|
|
162
|
+
"BACKLOG.md is git-tracked (run `git add BACKLOG.md` then commit — an untracked board never syncs)"
|
|
163
|
+
);
|
|
164
|
+
} else {
|
|
165
|
+
check(true, "not a git repo \u2014 skipping BACKLOG.md tracking check");
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
lines = fs.readFileSync(canonical, "utf8").split(/\r?\n/);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// ---- table parsing ----------------------------------------------------------
|
|
172
|
+
// Split a markdown table row on unescaped `|` — shared with backlog.js and the
|
|
173
|
+
// other board gates via board-lib.js (one home for the row parser, so a parse
|
|
174
|
+
// fix never has to be replicated across scripts).
|
|
175
|
+
|
|
176
|
+
// Group table rows by the last `##`/`###` section heading that preceded them.
|
|
177
|
+
// Also records each section's column width (from its separator row) and flags
|
|
178
|
+
// data rows with MORE cells than the header — the signature of an unescaped `|`
|
|
179
|
+
// (or stray `|` fragment) splitting one logical row into corrupt cells. Over-wide
|
|
180
|
+
// rows are reported with a precise message and EXCLUDED from the per-column
|
|
181
|
+
// checks below, whose shifted indexes would otherwise produce misleading errors
|
|
182
|
+
// ("depends on unknown row 404" when the real defect is a 7-cell Open row).
|
|
183
|
+
function parseSectionRows(lines) {
|
|
184
|
+
const buckets = {};
|
|
185
|
+
const widths = {};
|
|
186
|
+
const overWide = [];
|
|
187
|
+
let current = null;
|
|
188
|
+
let rowCount = 0;
|
|
189
|
+
for (const raw of lines) {
|
|
190
|
+
const heading = raw.match(/^#{2,3}\s+(.*)$/);
|
|
191
|
+
if (heading) {
|
|
192
|
+
current = heading[1].trim();
|
|
193
|
+
buckets[current] = buckets[current] || [];
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
if (!current) continue;
|
|
197
|
+
const row = raw.trim();
|
|
198
|
+
if (!/^\|.*\|$/.test(row)) continue;
|
|
199
|
+
const inner = row.slice(1, -1);
|
|
200
|
+
const cells = splitCells(inner);
|
|
201
|
+
// separator row `|---|---|` — records this section's canonical width
|
|
202
|
+
if (cells.length > 1 && cells.every((c) => /^[-:|\s]*$/.test(c))) {
|
|
203
|
+
if (!(current in widths)) widths[current] = cells.length;
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
const joined = cells.join("|").trim();
|
|
207
|
+
if (/^([-:|\s]*)$/.test(joined)) continue;
|
|
208
|
+
// skip header rows named ID/P/Epic/Task/... and the Epics registry header (Key/Label/Goal)
|
|
209
|
+
if (cells.some((c) => /^(ID|[Ii]d|P|Epic|Task|Evidence|Handoff|Why frozen \/ reopen when|Closed|Key|Label|Goal|Depends on)$/.test(c))) continue;
|
|
210
|
+
// over-wide row = unescaped `|`/stray fragment split the logical row
|
|
211
|
+
if (widths[current] && cells.length > widths[current]) {
|
|
212
|
+
overWide.push({ heading: current, cells, expected: widths[current] });
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
buckets[current].push(cells);
|
|
216
|
+
rowCount++;
|
|
217
|
+
}
|
|
218
|
+
return { buckets, widths, overWide, rowCount };
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const parsed = parseSectionRows(lines);
|
|
222
|
+
const { buckets, overWide, rowCount } = parsed;
|
|
223
|
+
|
|
224
|
+
// ---- honest cell-count diagnostics (before per-column checks) ---------------
|
|
225
|
+
for (const bad of overWide) {
|
|
226
|
+
const label = bad.heading.toLowerCase();
|
|
227
|
+
const id = (bad.cells[0] || "?").trim();
|
|
228
|
+
const extra = bad.cells.length - bad.expected;
|
|
229
|
+
check(
|
|
230
|
+
false,
|
|
231
|
+
`row ${id} under "${bad.heading}" has ${bad.cells.length} cells, expected ${bad.expected} ` +
|
|
232
|
+
`(${extra} extra — an unescaped \`|\` or stray fragment is splitting one logical row). ` +
|
|
233
|
+
`Repair the row with the backlog tools (never hand-edit): ` +
|
|
234
|
+
`remove the stray \`|\` or re-add the row via \`node scripts/backlog.js\`.`
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// Column indexes per section (from the BACKLOG template schema).
|
|
239
|
+
const COLS = {
|
|
240
|
+
open: { id: 0, priority: 1, epic: 2, evidence: 4, dependsOn: 5 },
|
|
241
|
+
queued: { id: 0, priority: 1, epic: 2, evidence: 4, dependsOn: 5 },
|
|
242
|
+
"in progress": { id: 0, epic: 1, task: 2, handoff: 3 },
|
|
243
|
+
frozen: { id: 0, epic: 1, reopen: 3 },
|
|
244
|
+
"archive (shipped · done)": { id: 0, epic: 1 },
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
function bucketRows(key) {
|
|
248
|
+
// tolerate loose heading variants
|
|
249
|
+
return buckets[key] || [];
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const openRows = bucketRows("Open");
|
|
253
|
+
const queuedRows = bucketRows("Queued");
|
|
254
|
+
const inProgressRows = bucketRows("In progress");
|
|
255
|
+
const frozenRows = bucketRows("Frozen");
|
|
256
|
+
const archiveRows = bucketRows("Archive (shipped · done)") || bucketRows("Archive");
|
|
257
|
+
|
|
258
|
+
// ---- Epics registry: parse + validate -------------------------------------
|
|
259
|
+
const epicRows = buckets["Epics"] || [];
|
|
260
|
+
const epicKeys = new Set();
|
|
261
|
+
for (const r of epicRows) {
|
|
262
|
+
const key = (r[0] || "").trim();
|
|
263
|
+
const label = (r[1] || "").trim();
|
|
264
|
+
if (!key) {
|
|
265
|
+
check(false, `epics entry: key must not be blank`);
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
if (epicKeys.has(key)) check(false, `epics entry "${key}": duplicate key`);
|
|
269
|
+
epicKeys.add(key);
|
|
270
|
+
check(label.length > 0, `epics entry "${key}": label must not be blank`);
|
|
271
|
+
}
|
|
272
|
+
if (epicRows.length > 0) {
|
|
273
|
+
check(true, `parsed ${epicRows.length} epic(s) from ## Epics`);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function checkEpic(id, raw) {
|
|
277
|
+
const epic = (raw || "").trim();
|
|
278
|
+
if (epic.length === 0) {
|
|
279
|
+
check(false, `row ${id}: epic must not be blank (use a declared epic key or \`?\`)`);
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
if (epic !== "?" && !epicKeys.has(epic)) {
|
|
283
|
+
check(false, `row ${id}: epic "${epic}" is not a declared epic (add it to ## Epics or use ?)`);
|
|
284
|
+
} else {
|
|
285
|
+
check(true, `row ${id}: epic \`${epic}\` is valid`);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// ---- In progress rows: non-empty task + handoff ----------------------------
|
|
290
|
+
for (const r of inProgressRows) {
|
|
291
|
+
const id = r[COLS["in progress"].id] || "?";
|
|
292
|
+
const task = (r[COLS["in progress"].task] || "").trim();
|
|
293
|
+
const handoff = (r[COLS["in progress"].handoff] || "").trim();
|
|
294
|
+
check(task.length > 0, `in-progress row ${id}: task must not be blank`);
|
|
295
|
+
check(
|
|
296
|
+
handoff.length > 0,
|
|
297
|
+
`in-progress row ${id}: handoff must not be blank (session handoff file, or \`?\` if unknown)`
|
|
298
|
+
);
|
|
299
|
+
checkEpic(id, r[COLS["in progress"].epic]);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// ---- 3. Frozen requires a reopen condition ---------------------------------
|
|
303
|
+
for (const r of frozenRows) {
|
|
304
|
+
const reopen = (r[COLS.frozen.reopen] || "").trim();
|
|
305
|
+
check(
|
|
306
|
+
reopen.length > 0,
|
|
307
|
+
`frozen row ${r[COLS.frozen.id]}: must carry a "why frozen / reopen when" condition`
|
|
308
|
+
);
|
|
309
|
+
checkEpic(r[COLS.frozen.id], r[COLS.frozen.epic]);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// ---- 2 + 4. Open rows: valid priority + non-empty evidence -----------------
|
|
313
|
+
for (const r of openRows) {
|
|
314
|
+
const id = r[COLS.open.id] || "?";
|
|
315
|
+
const priority = (r[COLS.open.priority] || "").trim();
|
|
316
|
+
const evidence = (r[COLS.open.evidence] || "").trim();
|
|
317
|
+
if (priority.length === 0) {
|
|
318
|
+
check(false, `open row ${id}: priority must not be blank (use P1..P4, or \`?\` if unknown)`);
|
|
319
|
+
} else if (!PRIORITY.has(priority)) {
|
|
320
|
+
check(false, `open row ${id}: priority \`${priority}\` not in {P1,P2,P3,P4}`);
|
|
321
|
+
} else {
|
|
322
|
+
check(true, `open row ${id}: priority \`${priority}\` is valid`);
|
|
323
|
+
}
|
|
324
|
+
check(
|
|
325
|
+
evidence.length > 0,
|
|
326
|
+
`open row ${id}: evidence must not be blank (pointer, or \`?\` if unknown)`
|
|
327
|
+
);
|
|
328
|
+
checkEpic(id, r[COLS.open.epic]);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// ---- 2 + 4 (queued). Queued rows: valid priority + evidence + epic ---------
|
|
332
|
+
for (const r of queuedRows) {
|
|
333
|
+
const id = r[COLS.queued.id] || "?";
|
|
334
|
+
const priority = (r[COLS.queued.priority] || "").trim();
|
|
335
|
+
const evidence = (r[COLS.queued.evidence] || "").trim();
|
|
336
|
+
if (priority.length === 0) {
|
|
337
|
+
check(false, `queued row ${id}: priority must not be blank (use P1..P4, or \`?\` if unknown)`);
|
|
338
|
+
} else if (!PRIORITY.has(priority)) {
|
|
339
|
+
check(false, `queued row ${id}: priority \`${priority}\` not in {P1,P2,P3,P4}`);
|
|
340
|
+
} else {
|
|
341
|
+
check(true, `queued row ${id}: priority \`${priority}\` is valid`);
|
|
342
|
+
}
|
|
343
|
+
check(
|
|
344
|
+
evidence.length > 0,
|
|
345
|
+
`queued row ${id}: evidence must not be blank (pointer, or \`?\` if unknown)`
|
|
346
|
+
);
|
|
347
|
+
checkEpic(id, r[COLS.queued.epic]);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// ---- Archive rows: epic must be declared (or `?`) --------------------------
|
|
351
|
+
for (const r of archiveRows) {
|
|
352
|
+
checkEpic(r[COLS["archive (shipped · done)"].id], r[COLS["archive (shipped · done)"].epic]);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// ---- 5. No duplicate IDs across the whole file -----------------------------
|
|
356
|
+
const allRows = [...openRows.map((r, i) => ({ cells: r, tag: "Open" })),
|
|
357
|
+
...queuedRows.map((r, i) => ({ cells: r, tag: "Queued" })),
|
|
358
|
+
...inProgressRows.map((r, i) => ({ cells: r, tag: "In progress" })),
|
|
359
|
+
...frozenRows.map((r, i) => ({ cells: r, tag: "Frozen" })),
|
|
360
|
+
...archiveRows.map((r, i) => ({ cells: r, tag: "Archive" }))];
|
|
361
|
+
const totalRows = allRows.length;
|
|
362
|
+
if (totalRows > 0) {
|
|
363
|
+
check(true, `parsed ${totalRows} row(s) across Open/Queued/In progress/Frozen/Archive`);
|
|
364
|
+
const seen = new Map();
|
|
365
|
+
const allIds = new Set();
|
|
366
|
+
for (const { cells, tag } of allRows) {
|
|
367
|
+
const id = (cells[0] || "").trim();
|
|
368
|
+
if (!id) {
|
|
369
|
+
check(false, `${tag}: a row has no ID — rows must carry an ID (F-001, ...)`);
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
if (seen.has(id)) check(false, `duplicate ID \`${id}\` (${seen.get(id)} and ${tag})`);
|
|
373
|
+
else seen.set(id, tag);
|
|
374
|
+
allIds.add(id);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// ---- Depends-on references must name existing rows ---------------------
|
|
378
|
+
const dependsRows = [
|
|
379
|
+
...openRows.map((r) => ({ id: (r[COLS.open.id] || "").trim(), dep: r[COLS.open.dependsOn] || "", tag: "Open" })),
|
|
380
|
+
...queuedRows.map((r) => ({ id: (r[COLS.queued.id] || "").trim(), dep: r[COLS.queued.dependsOn] || "", tag: "Queued" })),
|
|
381
|
+
];
|
|
382
|
+
for (const { id, dep, tag } of dependsRows) {
|
|
383
|
+
const raw = (dep || "").trim();
|
|
384
|
+
if (!raw || raw === "?") continue;
|
|
385
|
+
for (const ref of raw.split(/[\s,]+/).filter(Boolean)) {
|
|
386
|
+
if (!allIds.has(ref)) {
|
|
387
|
+
check(false, `${tag} row ${id}: depends on unknown row \`${ref}\` (no such ID in BACKLOG.md)`);
|
|
388
|
+
} else {
|
|
389
|
+
check(true, `${tag} row ${id}: depends on \`${ref}\` (valid reference)`);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// ---- Dependency cycles are permanently blocking -------------------------
|
|
395
|
+
const graph = new Map();
|
|
396
|
+
for (const { id, dep } of dependsRows) {
|
|
397
|
+
if (!id) continue;
|
|
398
|
+
const raw = (dep || "").trim();
|
|
399
|
+
graph.set(id, !raw || raw === "?" ? [] : raw.split(/[\s,]+/).filter(Boolean));
|
|
400
|
+
}
|
|
401
|
+
const cycle = findCycle(graph);
|
|
402
|
+
check(
|
|
403
|
+
!cycle,
|
|
404
|
+
cycle
|
|
405
|
+
? `dependency cycle: ${cycle.join(" -> ")} — every row in the cycle is permanently blocked`
|
|
406
|
+
: "no dependency cycles among Open/Queued rows"
|
|
407
|
+
);
|
|
408
|
+
} else {
|
|
409
|
+
check(true, "empty board (no Open/In progress/Frozen/Archive rows yet) — valid for a fresh project");
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// ---- 6. INDEX.md / todo.md are pointers, not live lists --------------------
|
|
413
|
+
for (const rel of [".agents/features/INDEX.md", ".agents/memory/todo.md"]) {
|
|
414
|
+
const p = path.join(root, rel);
|
|
415
|
+
if (!fs.existsSync(p)) {
|
|
416
|
+
check(true, `${rel} absent`);
|
|
417
|
+
continue;
|
|
418
|
+
}
|
|
419
|
+
const content = fs.readFileSync(p, "utf8");
|
|
420
|
+
const isPointer = /BACKLOG\.md/.test(content);
|
|
421
|
+
const hasList = /^\s*\|.+\|/m.test(content);
|
|
422
|
+
if (isPointer) {
|
|
423
|
+
check(true, `${rel} is a pointer to BACKLOG.md`);
|
|
424
|
+
} else if (hasList) {
|
|
425
|
+
check(false, `${rel} looks like a live list — point it at BACKLOG.md (or remove it)`);
|
|
426
|
+
} else {
|
|
427
|
+
check(true, `${rel} present and not a live list`);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
console.log(
|
|
432
|
+
`\nRESULT: ${failures.length ? `${failures.length} FAILURE(S)` : "backlog green"}`
|
|
433
|
+
);
|
|
434
|
+
process.exit(failures.length ? 1 : 0);
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/*
|
|
4
|
+
* test:capacity — the machine capacity envelope gate (harness-shipped).
|
|
5
|
+
*
|
|
6
|
+
* The 2026-09-29 freeze was a WSL2 memory/CPU exhaustion, not a stuck agent:
|
|
7
|
+
* emulator (~3 GB) + two opencode agents + `next dev` + a gate filled a 10 GB
|
|
8
|
+
* VM, swap hit 4 GB, load hit 60, and the host<->VM vsock relay starved — every
|
|
9
|
+
* terminal froze at once. Parallel *agents* are fine; parallel *heavy tiers* are
|
|
10
|
+
* not. This gate makes the envelope visible and mechanical:
|
|
11
|
+
*
|
|
12
|
+
* - reports free RAM / swap / load / live `.serve/` processes + idle ages;
|
|
13
|
+
* - FAILS when the envelope is already exceeded (free RAM below the floor, or
|
|
14
|
+
* more live heavy tiers than allowed) — the state in which a heavy launch
|
|
15
|
+
* tips the machine into thrash;
|
|
16
|
+
* - WARNS on the softer signals (too many live serves, swap high, an idle
|
|
17
|
+
* daemon past the reap age) so the fix is obvious before it is fatal;
|
|
18
|
+
* - SKIPS (exit 0) on a non-Linux host or when AGENT_CAPACITY_DISABLE=1.
|
|
19
|
+
*
|
|
20
|
+
* The numbers are the project-owned envelope in `.agents/memory/orchestration.md`
|
|
21
|
+
* (shared with `serve.js`, the `context-guard` plugin, and `doctor`), falling
|
|
22
|
+
* back to documented defaults. Stay quiet when there is nothing to fix.
|
|
23
|
+
*/
|
|
24
|
+
const path = require("path");
|
|
25
|
+
const capacity = require("./capacity-lib.js");
|
|
26
|
+
|
|
27
|
+
const root = path.resolve(__dirname, "..", "..");
|
|
28
|
+
|
|
29
|
+
console.log("capacity gate \u2014 the machine capacity envelope must not already be exceeded");
|
|
30
|
+
|
|
31
|
+
if (process.env.AGENT_CAPACITY_DISABLE === "1") {
|
|
32
|
+
console.log(" \u26a0 capacity checks disabled (AGENT_CAPACITY_DISABLE=1)");
|
|
33
|
+
console.log("\nRESULT: skipped (0 failures)");
|
|
34
|
+
process.exit(0);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const sample = capacity.sample(root);
|
|
38
|
+
if (!sample.mem) {
|
|
39
|
+
console.log(" \u26a0 host memory not readable (non-Linux) \u2014 capacity gate skipped");
|
|
40
|
+
console.log("\nRESULT: skipped (0 failures)");
|
|
41
|
+
process.exit(0);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const e = sample.envelope;
|
|
45
|
+
console.log(` ${capacity.formatSummary(sample)}`);
|
|
46
|
+
console.log(
|
|
47
|
+
` envelope: max_heavy_tiers=${e.maxHeavyTiers} · max_live_serves=${e.maxLiveServes} · ` +
|
|
48
|
+
`min_available_mem_mb=${e.minAvailableMemMb} · idle_reap_minutes=${e.idleReapMinutes}`
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const live = sample.serves.filter((s) => s.alive);
|
|
52
|
+
if (sample.serves.length) {
|
|
53
|
+
for (const s of sample.serves) {
|
|
54
|
+
const age = s.ageMs != null ? ` · up ${Math.round(s.ageMs / 60000)}m` : "";
|
|
55
|
+
console.log(
|
|
56
|
+
` ${s.alive ? "live " : "stale"} ${s.name}${s.heavy ? " [heavy]" : ""}${age} \u2014 ${s.cmd || "?"}`
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
} else {
|
|
60
|
+
console.log(" no serve processes recorded");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const ev = capacity.evaluate(sample);
|
|
64
|
+
for (const w of ev.warnings) console.log(" \u26a0 " + w);
|
|
65
|
+
for (const r of ev.reasons) console.log(" \u2717 " + r);
|
|
66
|
+
|
|
67
|
+
if (!ev.ok) {
|
|
68
|
+
console.log(
|
|
69
|
+
"\n Stop an idle dev server / emulator before starting another heavy tier:\n" +
|
|
70
|
+
" node scripts/serve.js stop --name <name>\n" +
|
|
71
|
+
" node scripts/serve.js stop-all\n" +
|
|
72
|
+
" (`node scripts/serve.js list` shows ages; the capacity envelope lives in " +
|
|
73
|
+
".agents/memory/orchestration.md.)"
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
console.log(
|
|
78
|
+
"\nRESULT: " +
|
|
79
|
+
(ev.ok
|
|
80
|
+
? live.length
|
|
81
|
+
? "green (capacity within envelope \u2014 see warnings)"
|
|
82
|
+
: "green"
|
|
83
|
+
: `${ev.reasons.length} FAILURE(S) \u2014 the machine capacity envelope is already exceeded`)
|
|
84
|
+
);
|
|
85
|
+
process.exit(ev.ok ? 0 : 1);
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/*
|
|
4
|
+
* check-ci-policy — a gate against the workflow shapes that silently leave the
|
|
5
|
+
* GitHub Actions free tier.
|
|
6
|
+
*
|
|
7
|
+
* Root cause of the 2026-10 outage (see `ci-usage-lib.js`): the burn was not one
|
|
8
|
+
* bad job, it was a handful of workflow *shapes* — a sub-hourly cron that bills 1,440
|
|
9
|
+
* jobs/month, an unpinned macOS runner on every push, and three mobile workflows
|
|
10
|
+
* each triggering on the same push. Cost policy belongs in a gate so the shape
|
|
11
|
+
* cannot be reintroduced by a passing PR.
|
|
12
|
+
*
|
|
13
|
+
* Rules (FAIL blocks landing; WARN is advisory):
|
|
14
|
+
* scheduled-too-frequent — a `cron:` firing more than hourly (WARN above
|
|
15
|
+
* 8/day) bills jobs every time it runs
|
|
16
|
+
* expensive-every-push — a macOS/Windows runner on `push` with NO `paths:`
|
|
17
|
+
* filter: every push pays the expensive rate
|
|
18
|
+
* larger-runner — a `-large`/`-xlarge` runner is ALWAYS billed and is
|
|
19
|
+
* never covered by included minutes
|
|
20
|
+
* duplicate-expensive-push — two or more macOS workflows triggered on the same
|
|
21
|
+
* unfiltered push (the duplicate-mobile-workflow burn)
|
|
22
|
+
*
|
|
23
|
+
* A project with no `.github/workflows` passes (nothing to police). The audit is
|
|
24
|
+
* pure given `{ name, src }` file records, so it is unit-testable offline.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
const fs = require("fs");
|
|
28
|
+
const path = require("path");
|
|
29
|
+
|
|
30
|
+
const { workflowRunnerLabels, scheduleMinutes } = require("./ci-triage.js");
|
|
31
|
+
const { jobsPerMonth, rateForLabel } = require("./ci-usage-lib.js");
|
|
32
|
+
|
|
33
|
+
/* Jobs-per-month above which a schedule FAILS (more than hourly) or WARNS
|
|
34
|
+
* (more than ~8/day). */
|
|
35
|
+
const SCHEDULE_FAIL_JOBS = 720;
|
|
36
|
+
const SCHEDULE_WARN_JOBS = 240;
|
|
37
|
+
|
|
38
|
+
/* True when a workflow's `on:` includes an unfiltered `push`. Unfiltered means
|
|
39
|
+
* no `paths:`/`paths-ignore:` directly under `push:`. Best-effort text scan. */
|
|
40
|
+
function pushTrigger(src) {
|
|
41
|
+
const text = String(src || "");
|
|
42
|
+
const inline = /^\s*on:\s*\[([^\]]*)\]/m.exec(text);
|
|
43
|
+
if (inline) {
|
|
44
|
+
return { push: /(^|[\s,])push([\s,]|$)/.test(inline[1]), paths: false };
|
|
45
|
+
}
|
|
46
|
+
const m = /^on:\s*$/m.exec(text) || /^on:\s*\n/m.exec(text);
|
|
47
|
+
const body = m ? text.slice(m.index) : text;
|
|
48
|
+
const push = /^\s{2}push:\s*(#.*)?$/m.test(body) || /^\s{2}push:\s*\[/m.test(body);
|
|
49
|
+
if (!push) return { push: false, paths: false };
|
|
50
|
+
// The `push:` block runs until the next key at the same (2-space) indent, or
|
|
51
|
+
// EOF. A blank line does NOT end it — `$(?![\s\S])` is the true end of string
|
|
52
|
+
// (a bare `$` would also match at the end of the first line and truncate it).
|
|
53
|
+
const pm = /^(\s{2})push:\s*\n([\s\S]*?)(?=^\s{0,2}\S|$(?![\s\S]))/m.exec(body);
|
|
54
|
+
const block = pm ? pm[2] : "";
|
|
55
|
+
const paths = /^\s{4,}(paths|paths-ignore):/m.test(block);
|
|
56
|
+
return { push: true, paths };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/* Audit a list of `{ name, src }` workflow records. Returns findings
|
|
60
|
+
* `[{ level, rule, name, detail }]`. */
|
|
61
|
+
function auditWorkflows(files) {
|
|
62
|
+
const findings = [];
|
|
63
|
+
const expensivePush = [];
|
|
64
|
+
for (const file of files || []) {
|
|
65
|
+
const name = file.name;
|
|
66
|
+
const src = file.src;
|
|
67
|
+
const labels = workflowRunnerLabels(src);
|
|
68
|
+
const rates = labels.map((l) => ({ label: l, ...rateForLabel(l) }));
|
|
69
|
+
|
|
70
|
+
for (const n of scheduleMinutes(src)) {
|
|
71
|
+
const jobs = jobsPerMonth(n);
|
|
72
|
+
const cadence = n >= 60 ? `hourly` : `every ${n} min`;
|
|
73
|
+
if (jobs > SCHEDULE_FAIL_JOBS) {
|
|
74
|
+
findings.push({ level: "fail", rule: "scheduled-too-frequent", name, detail: `cron ${cadence} ≈ ${jobs} jobs/mo — use a daily/6-hourly cadence (or an event trigger) instead of a sub-hourly probe` });
|
|
75
|
+
} else if (jobs > SCHEDULE_WARN_JOBS) {
|
|
76
|
+
findings.push({ level: "warn", rule: "scheduled-too-frequent", name, detail: `cron ${cadence} ≈ ${jobs} jobs/mo — verify each run is worth the billed minute` });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
for (const r of rates.filter((r) => r.isLarger)) {
|
|
81
|
+
findings.push({ level: "warn", rule: "larger-runner", name, detail: `\`${r.label}\` is a larger runner — always billed ($${r.rate}/min), never covered by included minutes` });
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const expensive = rates.find((r) => r.key === "macos" || r.key === "windows");
|
|
85
|
+
const push = pushTrigger(src);
|
|
86
|
+
if (expensive && push.push && !push.paths) {
|
|
87
|
+
expensivePush.push(name);
|
|
88
|
+
findings.push({ level: "fail", rule: "expensive-every-push", name, detail: `\`${expensive.label}\` runs on every push (no \`paths:\` filter) at $${expensive.rate}/min — add a path filter (e.g. \`mobile/**\`) or move it off the push trigger` });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (expensivePush.length > 1) {
|
|
93
|
+
for (const name of expensivePush) {
|
|
94
|
+
findings.push({ level: "fail", rule: "duplicate-expensive-push", name, detail: `${expensivePush.length} expensive workflows run on the same unfiltered push (${expensivePush.join(", ")}) — merge them or path-filter each` });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return findings;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function readWorkflows(root) {
|
|
101
|
+
const dir = path.join(root, ".github", "workflows");
|
|
102
|
+
const out = [];
|
|
103
|
+
if (!fs.existsSync(dir)) return out;
|
|
104
|
+
for (const file of fs.readdirSync(dir).sort()) {
|
|
105
|
+
if (!/\.ya?ml$/i.test(file)) continue;
|
|
106
|
+
try {
|
|
107
|
+
out.push({ name: file, src: fs.readFileSync(path.join(dir, file), "utf8") });
|
|
108
|
+
} catch (_) {
|
|
109
|
+
/* unreadable: skip */
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return out;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function parseArgs(argv) {
|
|
116
|
+
const out = { root: null, json: false, help: false };
|
|
117
|
+
for (let i = 0; i < argv.length; i++) {
|
|
118
|
+
const a = argv[i];
|
|
119
|
+
if (a === "--root") out.root = argv[++i];
|
|
120
|
+
else if (a.startsWith("--root=")) out.root = a.slice("--root=".length);
|
|
121
|
+
else if (a === "--json") out.json = true;
|
|
122
|
+
else if (a === "--help" || a === "-h") out.help = true;
|
|
123
|
+
}
|
|
124
|
+
return out;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function main() {
|
|
128
|
+
const args = parseArgs(process.argv.slice(2));
|
|
129
|
+
if (args.help) {
|
|
130
|
+
console.log("Usage: node scripts/qa/check-ci-policy.js [--root <dir>] [--json]");
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const root = path.resolve(args.root || process.cwd());
|
|
134
|
+
const files = readWorkflows(root);
|
|
135
|
+
const findings = auditWorkflows(files);
|
|
136
|
+
const fails = findings.filter((f) => f.level === "fail");
|
|
137
|
+
const warns = findings.filter((f) => f.level === "warn");
|
|
138
|
+
|
|
139
|
+
if (args.json) {
|
|
140
|
+
console.log(JSON.stringify({ schema: "ci-policy/1", checked: files.map((f) => f.name), findings }, null, 2));
|
|
141
|
+
process.exit(fails.length ? 1 : 0);
|
|
142
|
+
}
|
|
143
|
+
if (files.length === 0) {
|
|
144
|
+
console.log("ci-policy: OK — no .github/workflows to check");
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
for (const f of findings) {
|
|
148
|
+
console.log(` [${f.level === "fail" ? "FAIL" : "warn"}] ${f.name}: ${f.rule} — ${f.detail}`);
|
|
149
|
+
}
|
|
150
|
+
const verdict = fails.length ? "FAIL" : "OK";
|
|
151
|
+
console.log(`ci-policy: ${verdict} — ${files.length} workflow(s) checked, ${fails.length} failure(s), ${warns.length} warning(s)`);
|
|
152
|
+
process.exit(fails.length ? 1 : 0);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (require.main === module) {
|
|
156
|
+
try {
|
|
157
|
+
main();
|
|
158
|
+
} catch (e) {
|
|
159
|
+
console.error("ci-policy: " + (e && e.message ? e.message : e));
|
|
160
|
+
process.exit(1);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
module.exports = { auditWorkflows, readWorkflows, pushTrigger, parseArgs, SCHEDULE_FAIL_JOBS, SCHEDULE_WARN_JOBS };
|