opencode-agent-harness 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/LICENSE +21 -0
- package/README.md +590 -2
- package/bin/agent-harness.js +3059 -0
- package/contrib/global-plugins/README.md +49 -0
- package/contrib/global-plugins/harness-freshness.ts +355 -0
- package/package.json +48 -4
- package/templates/.agents/AGENTS.md +204 -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 +1864 -0
- package/templates/scripts/board-service.sh +207 -0
- package/templates/scripts/checkpoint.js +290 -0
- package/templates/scripts/finalize.js +277 -0
- package/templates/scripts/nightly.js +913 -0
- package/templates/scripts/orient.js +514 -0
- package/templates/scripts/qa/board-client.js +260 -0
- package/templates/scripts/qa/board-lib.js +96 -0
- package/templates/scripts/qa/board-sync.js +469 -0
- package/templates/scripts/qa/capacity-lib.js +916 -0
- package/templates/scripts/qa/check-backlog.js +427 -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 +284 -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 +183 -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/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 +453 -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 +212 -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/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 +261 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/*
|
|
4
|
+
* finalize — the deterministic finalization tail in ONE command.
|
|
5
|
+
*
|
|
6
|
+
* The problem it solves: a full dev cycle (pick → plan → implement → QA → gates →
|
|
7
|
+
* docs → archive → commit → land → confirm CI) needs more context than one
|
|
8
|
+
* bounded orchestrator transcript can hold. `finalize` collapses the whole tail
|
|
9
|
+
* into a single blocking command:
|
|
10
|
+
*
|
|
11
|
+
* 1. resolve root + feature (id arg, else the `f-<n>` branch);
|
|
12
|
+
* 2. archive the row (idempotent — an already-archived row is a no-op);
|
|
13
|
+
* 3. commit the tail (board + CHANGELOG + handoff + any remaining change);
|
|
14
|
+
* 4. shell out to `scripts/ship.js`, which rebases onto `origin/main`, runs the
|
|
15
|
+
* branch gates, lands `HEAD:main` with a direct fast-forward push (retrying
|
|
16
|
+
* after a concurrent landing), and waits (bounded) for CI to go green on the
|
|
17
|
+
* landed SHA. The deploy runs after CI; there is no PR, label, merge train,
|
|
18
|
+
* or deploy watch.
|
|
19
|
+
*
|
|
20
|
+
* The one non-deterministic bit — the CHANGELOG prose — is authored by the
|
|
21
|
+
* `/finish` command's single `docs` dispatch BEFORE this runs; `finalize`
|
|
22
|
+
* commits whatever is in the tree.
|
|
23
|
+
*
|
|
24
|
+
* Usage:
|
|
25
|
+
* node scripts/finalize.js --feature <id> [--closed "<note>"]
|
|
26
|
+
* [--base main] [--root <dir>] [--dry-run]
|
|
27
|
+
* [--no-rebase] [--no-gate] [--no-ci-wait]
|
|
28
|
+
*/
|
|
29
|
+
const fs = require("fs");
|
|
30
|
+
const path = require("path");
|
|
31
|
+
const { spawnSync } = require("child_process");
|
|
32
|
+
|
|
33
|
+
function fail(message) {
|
|
34
|
+
console.error(message);
|
|
35
|
+
process.exitCode = 1;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/* Run a command, streaming its output. Returns the exit status (0 = ok). */
|
|
39
|
+
function run(cmd, args, opts) {
|
|
40
|
+
console.log(`\n$ ${[cmd, ...args].join(" ")}`);
|
|
41
|
+
const result = spawnSync(cmd, args, { stdio: "inherit", ...(opts || {}) });
|
|
42
|
+
return result.status === 0;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* Run a command and capture trimmed stdout (empty string on failure). */
|
|
46
|
+
function out(cmd, args, opts) {
|
|
47
|
+
const result = spawnSync(cmd, args, { encoding: "utf8", ...(opts || {}) });
|
|
48
|
+
return result.status === 0 ? String(result.stdout || "").trim() : "";
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* Walk up from `startDir` to the repo root (the first `.git` entry). */
|
|
52
|
+
function findRoot(startDir) {
|
|
53
|
+
let dir = path.resolve(startDir || process.cwd());
|
|
54
|
+
for (;;) {
|
|
55
|
+
if (fs.existsSync(path.join(dir, ".git"))) return dir;
|
|
56
|
+
const parent = path.dirname(dir);
|
|
57
|
+
if (parent === dir) return null;
|
|
58
|
+
dir = parent;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function readIf(p) {
|
|
63
|
+
try {
|
|
64
|
+
return fs.readFileSync(p, "utf8");
|
|
65
|
+
} catch {
|
|
66
|
+
return "";
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/* The feature id from a branch name (`f-257` -> `F-257`, `feat/F-12-x` -> `F-12`). */
|
|
71
|
+
function featureFromBranch(branch) {
|
|
72
|
+
const m = String(branch || "").match(/(?:^|\/)[fF]-?([0-9]+)/);
|
|
73
|
+
return m ? `F-${m[1]}` : null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/* The handoff's recorded outcome, if any (`## Session metadata` -> `- outcome:`). */
|
|
77
|
+
function handoffOutcome(feature) {
|
|
78
|
+
let src = readIf(path.join(root, ".agents", "handoffs", feature + ".md"));
|
|
79
|
+
if (!src) {
|
|
80
|
+
const res = spawnSync("git", ["-C", root, "worktree", "list", "--porcelain"], { encoding: "utf8" });
|
|
81
|
+
for (const line of String(res.stdout || "").split(/\r?\n/)) {
|
|
82
|
+
if (!line.startsWith("worktree ")) continue;
|
|
83
|
+
const dir = line.slice("worktree ".length).trim();
|
|
84
|
+
const candidate = readIf(path.join(dir, ".agents", "handoffs", feature + ".md"));
|
|
85
|
+
if (candidate) {
|
|
86
|
+
src = candidate;
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const m = src.match(/^[-*]\s*outcome\s*:\s*(.+)$/im);
|
|
92
|
+
return m ? m[1].trim().toLowerCase() : null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/* Whether the row is already archived on the board. When the board service is
|
|
96
|
+
* the backend (ADR 0001) the board lives in the service, so ask it; otherwise
|
|
97
|
+
* reuse the run-loop parser (same module the auto-resume runner trusts). */
|
|
98
|
+
function isArchived(feature) {
|
|
99
|
+
try {
|
|
100
|
+
const client = require(path.join(root, "scripts", "qa", "board-client.js"));
|
|
101
|
+
if (client.enabled(root)) {
|
|
102
|
+
const board = client.getBoard(root);
|
|
103
|
+
return (board.archive || []).some((r) => r.id === feature);
|
|
104
|
+
}
|
|
105
|
+
} catch {
|
|
106
|
+
/* fall back to the file parser below */
|
|
107
|
+
}
|
|
108
|
+
try {
|
|
109
|
+
const loop = require(path.join(root, "scripts", "qa", "run-loop.js"));
|
|
110
|
+
return loop.isArchived(readIf(path.join(root, "BACKLOG.md")), feature);
|
|
111
|
+
} catch {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/* Whether HEAD is already an ancestor of `origin/<base>` — i.e. the change is
|
|
117
|
+
* already landed, so a re-run is a no-op. Best-effort fetch; offline returns
|
|
118
|
+
* false (a re-run then re-lands idempotently). */
|
|
119
|
+
function landedAlready(base) {
|
|
120
|
+
spawnSync("git", ["fetch", "--quiet", "origin"], { cwd: root, stdio: "ignore", timeout: 10000 });
|
|
121
|
+
const res = spawnSync("git", ["merge-base", "--is-ancestor", "HEAD", `origin/${base}`], {
|
|
122
|
+
cwd: root,
|
|
123
|
+
stdio: "ignore",
|
|
124
|
+
});
|
|
125
|
+
return res.status === 0;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function dirtyEntries() {
|
|
129
|
+
return out("git", ["status", "--porcelain"], { cwd: root })
|
|
130
|
+
.split(/\r?\n/)
|
|
131
|
+
.filter((l) => l && !l.startsWith("!!"));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function parseArgs(argv) {
|
|
135
|
+
const args = { _: [] };
|
|
136
|
+
for (let i = 0; i < argv.length; i++) {
|
|
137
|
+
const a = argv[i];
|
|
138
|
+
if (a === "--feature") args.feature = argv[++i];
|
|
139
|
+
else if (a === "--closed") args.closed = argv[++i];
|
|
140
|
+
else if (a === "--base") args.base = argv[++i];
|
|
141
|
+
else if (a === "--root") args.root = argv[++i];
|
|
142
|
+
else if (a === "--dry-run") args["dry-run"] = true;
|
|
143
|
+
else if (a === "--no-rebase") args["no-rebase"] = true;
|
|
144
|
+
else if (a === "--no-gate") args["no-gate"] = true;
|
|
145
|
+
else if (a === "--no-ci-wait") args["no-ci-wait"] = true;
|
|
146
|
+
else if (a === "--help" || a === "-h") args.help = true;
|
|
147
|
+
else args._.push(a);
|
|
148
|
+
}
|
|
149
|
+
return args;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function usage() {
|
|
153
|
+
console.log(
|
|
154
|
+
"finalize — archive + commit + land + confirm CI in one deterministic step (no LLM)\n\n" +
|
|
155
|
+
' node scripts/finalize.js --feature <id> [--closed "<note>"] [--base main]\n' +
|
|
156
|
+
" [--root <dir>] [--dry-run]\n" +
|
|
157
|
+
" [--no-rebase] [--no-gate] [--no-ci-wait]\n\n" +
|
|
158
|
+
"Collapses the finalization tail into one blocking command: archive the row,\n" +
|
|
159
|
+
"commit the board + CHANGELOG + handoff, then `ship` (rebase, gates, direct\n" +
|
|
160
|
+
"land on the integration branch, and a bounded wait for green CI). The deploy\n" +
|
|
161
|
+
"runs after CI. Safe to re-run."
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
let root = process.cwd();
|
|
166
|
+
|
|
167
|
+
function shipArgs(args) {
|
|
168
|
+
const passthrough = [];
|
|
169
|
+
if (args.base) passthrough.push("--base", args.base);
|
|
170
|
+
if (args["no-rebase"]) passthrough.push("--no-rebase");
|
|
171
|
+
if (args["no-gate"]) passthrough.push("--no-gate");
|
|
172
|
+
if (args["no-ci-wait"]) passthrough.push("--no-ci-wait");
|
|
173
|
+
return passthrough;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function main() {
|
|
177
|
+
const args = parseArgs(process.argv.slice(2));
|
|
178
|
+
if (args.help) return usage();
|
|
179
|
+
|
|
180
|
+
const found = args.root ? path.resolve(args.root) : findRoot(process.cwd());
|
|
181
|
+
if (!found) return fail("finalize: no git repository found (no .git in this tree or its parents).");
|
|
182
|
+
root = found;
|
|
183
|
+
|
|
184
|
+
const base = args.base || "main";
|
|
185
|
+
const branch = out("git", ["rev-parse", "--abbrev-ref", "HEAD"], { cwd: root });
|
|
186
|
+
if (!branch) return fail("finalize: could not resolve the current branch.");
|
|
187
|
+
if (branch === "main" || branch === "master") {
|
|
188
|
+
return fail(
|
|
189
|
+
`finalize: refusing to finalize "${branch}" — that is the integration branch.\n` +
|
|
190
|
+
" Run finalize from the feature worktree."
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const feature = args.feature || featureFromBranch(branch);
|
|
195
|
+
if (!feature) {
|
|
196
|
+
return fail(
|
|
197
|
+
`finalize: could not derive a feature id from branch "${branch}".\n` +
|
|
198
|
+
" Pass --feature <id> explicitly."
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const shipScript = path.join(root, "scripts", "ship.js");
|
|
203
|
+
if (!fs.existsSync(shipScript)) {
|
|
204
|
+
return fail(`finalize: ${path.relative(root, shipScript)} not found — is the harness deployed in this project?`);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const closed = args.closed || handoffOutcome(feature) || "shipped";
|
|
208
|
+
const archived = isArchived(feature);
|
|
209
|
+
|
|
210
|
+
if (args["dry-run"]) {
|
|
211
|
+
console.log("finalize (dry run)\n");
|
|
212
|
+
console.log(` root: ${root}`);
|
|
213
|
+
console.log(` feature: ${feature}`);
|
|
214
|
+
console.log(` branch: ${branch}`);
|
|
215
|
+
console.log(` closed: ${closed}`);
|
|
216
|
+
console.log(` archived: ${archived ? "yes" : "no"}`);
|
|
217
|
+
console.log(` landed: ${landedAlready(base) ? "yes" : "no"}`);
|
|
218
|
+
console.log(" plan: archive -> commit -> ship (rebase, gates, land, confirm CI)");
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Idempotence: an already-archived row whose branch is contained in
|
|
223
|
+
// `origin/<base>` is done.
|
|
224
|
+
if (archived && landedAlready(base)) {
|
|
225
|
+
console.log(`[finalize] ${feature} is already archived and its branch is landed on ${base} — nothing to do.`);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const backlogScript = path.join(root, "scripts", "backlog.js");
|
|
230
|
+
|
|
231
|
+
// 1. Archive the row (idempotent). The archive runs from inside the worktree,
|
|
232
|
+
// so it moves the row in THIS board and skips removing this checkout.
|
|
233
|
+
if (!archived) {
|
|
234
|
+
if (!fs.existsSync(backlogScript)) return fail(`finalize: ${path.relative(root, backlogScript)} not found.`);
|
|
235
|
+
if (!run(process.execPath, [backlogScript, "archive", feature, "--closed", closed], { cwd: root })) {
|
|
236
|
+
return fail(`finalize: could not archive ${feature} — fix the board error above, then re-run.`);
|
|
237
|
+
}
|
|
238
|
+
} else {
|
|
239
|
+
console.log(`[finalize] ${feature} is already archived — skipping the board write.`);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// 2. Commit the tail (board + CHANGELOG + handoff + any remaining change) so
|
|
243
|
+
// `ship`'s dirty-tree guard cannot abort the documented one-command close.
|
|
244
|
+
const dirty = dirtyEntries();
|
|
245
|
+
if (dirty.length) {
|
|
246
|
+
console.log(
|
|
247
|
+
`\n[finalize] committing the finalization tail:\n` + dirty.map((l) => ` ${l}`).join("\n")
|
|
248
|
+
);
|
|
249
|
+
if (!run("git", ["add", "-A"], { cwd: root })) return fail("finalize: `git add -A` failed.");
|
|
250
|
+
if (!run("git", ["commit", "-m", `chore(${feature}): finalize — board + changelog`], { cwd: root })) {
|
|
251
|
+
return fail("finalize: the finalization commit failed.");
|
|
252
|
+
}
|
|
253
|
+
} else {
|
|
254
|
+
console.log("\n[finalize] tree already clean — nothing to commit.");
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// 3. Ship: rebase, gates, direct land, and a bounded CI-green wait.
|
|
258
|
+
if (!run(process.execPath, [shipScript, ...shipArgs(args)], { cwd: root })) {
|
|
259
|
+
return fail(
|
|
260
|
+
"finalize: ship did not complete. If the push landed but CI is unconfirmed, re-run:\n" +
|
|
261
|
+
` npm run finalize -- --feature ${feature}`
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
console.log(`\n[finalize] ${feature} landed + CI green.`);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
if (require.main === module) {
|
|
269
|
+
try {
|
|
270
|
+
main();
|
|
271
|
+
} catch (e) {
|
|
272
|
+
console.error("finalize: " + (e && e.message ? e.message : e));
|
|
273
|
+
process.exit(1);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
module.exports = { featureFromBranch, handoffOutcome };
|