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,323 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/*
|
|
4
|
+
* board-client — HTTP client for the shared board service (ADR 0001).
|
|
5
|
+
*
|
|
6
|
+
* The service is the external, project-scoped board (its own Next.js + Prisma
|
|
7
|
+
* app). This module is the single home for talking to it, so the CLI
|
|
8
|
+
* (scripts/backlog.js), the opencode tools, and any future consumer share one
|
|
9
|
+
* transport. `scripts/backlog.js` picks a backend via `BACKLOG_BACKEND`:
|
|
10
|
+
* - service : all board reads/writes go to the HTTP service
|
|
11
|
+
* - file : the legacy BACKLOG.md path (unchanged)
|
|
12
|
+
*
|
|
13
|
+
* Config is resolved from the project's `.harness.json` `board` block first
|
|
14
|
+
* (per project, survives harness updates), then the environment:
|
|
15
|
+
* .harness.json -> { "board": { "url", "token", "project", "backend" } }
|
|
16
|
+
* BACKLOG_API_URL / BACKLOG_API_TOKEN / BACKLOG_PROJECT (env override)
|
|
17
|
+
* `board.backend` pins `"file"` (deliberate legacy board) or `"service"`
|
|
18
|
+
* without relying on a shell export.
|
|
19
|
+
*
|
|
20
|
+
* The functions mirror `backlog.js` command results so `formatResult` prints the
|
|
21
|
+
* same text for either backend.
|
|
22
|
+
*/
|
|
23
|
+
const fs = require("fs");
|
|
24
|
+
const path = require("path");
|
|
25
|
+
|
|
26
|
+
/* Read the per-project board config block from `.harness.json`, if present.
|
|
27
|
+
* The `token` there is honored but discouraged (it is a committed secret); the
|
|
28
|
+
* machine-level token store below is the recommended home. */
|
|
29
|
+
function projectBoardConfig(root) {
|
|
30
|
+
try {
|
|
31
|
+
const cfg = JSON.parse(fs.readFileSync(path.join(root, ".harness.json"), "utf8"));
|
|
32
|
+
const b = cfg && cfg.board;
|
|
33
|
+
if (b && typeof b === "object") {
|
|
34
|
+
return {
|
|
35
|
+
url: typeof b.url === "string" ? b.url : "",
|
|
36
|
+
token: typeof b.token === "string" ? b.token : "",
|
|
37
|
+
project: typeof b.project === "string" ? b.project : "",
|
|
38
|
+
backend: typeof b.backend === "string" ? b.backend.trim().toLowerCase() : "",
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
} catch {
|
|
42
|
+
/* no .harness.json / no board block */
|
|
43
|
+
}
|
|
44
|
+
return { url: "", token: "", project: "", backend: "" };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/* Machine-level client config. `board-service.sh install` writes
|
|
48
|
+
* `~/.config/agent-harness/board.env` and sources it from `~/.bashrc`; an
|
|
49
|
+
* opencode server launched outside that shell (systemd, a desktop launcher, a
|
|
50
|
+
* resumed session) never inherits those exports. Read the file directly so a
|
|
51
|
+
* board-configured project still reaches its service instead of silently
|
|
52
|
+
* falling back to a checkout-local file. */
|
|
53
|
+
function boardEnvFile() {
|
|
54
|
+
const base = process.env.XDG_CONFIG_HOME || path.join(require("os").homedir(), ".config");
|
|
55
|
+
try {
|
|
56
|
+
const src = fs.readFileSync(path.join(base, "agent-harness", "board.env"), "utf8");
|
|
57
|
+
const out = {};
|
|
58
|
+
for (const raw of src.split(/\r?\n/)) {
|
|
59
|
+
const m = /^\s*(?:export\s+)?([A-Z0-9_]+)\s*=\s*(.*?)\s*$/.exec(raw);
|
|
60
|
+
if (!m) continue;
|
|
61
|
+
let value = m[2];
|
|
62
|
+
if (
|
|
63
|
+
(value.startsWith('"') && value.endsWith('"')) ||
|
|
64
|
+
(value.startsWith("'") && value.endsWith("'"))
|
|
65
|
+
) {
|
|
66
|
+
value = value.slice(1, -1);
|
|
67
|
+
}
|
|
68
|
+
out[m[1]] = value;
|
|
69
|
+
}
|
|
70
|
+
return out;
|
|
71
|
+
} catch {
|
|
72
|
+
return {};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/* Machine-level token store: `~/.config/agent-harness/tokens.json` maps a
|
|
77
|
+
* project key to its service token (never committed). */
|
|
78
|
+
function tokenStore(project) {
|
|
79
|
+
const base = process.env.XDG_CONFIG_HOME || path.join(require("os").homedir(), ".config");
|
|
80
|
+
try {
|
|
81
|
+
const store = JSON.parse(fs.readFileSync(path.join(base, "agent-harness", "tokens.json"), "utf8"));
|
|
82
|
+
if (project && typeof store[project] === "string") return store[project];
|
|
83
|
+
} catch {
|
|
84
|
+
/* no store */
|
|
85
|
+
}
|
|
86
|
+
return "";
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function config(root) {
|
|
90
|
+
const file = root ? projectBoardConfig(root) : { url: "", token: "", project: "" };
|
|
91
|
+
const machine = boardEnvFile();
|
|
92
|
+
const project = process.env.BACKLOG_PROJECT || file.project || machine.BACKLOG_PROJECT || "";
|
|
93
|
+
const url = (
|
|
94
|
+
process.env.BACKLOG_API_URL ||
|
|
95
|
+
file.url ||
|
|
96
|
+
machine.BACKLOG_API_URL ||
|
|
97
|
+
""
|
|
98
|
+
).replace(/\/+$/, "");
|
|
99
|
+
const token =
|
|
100
|
+
process.env.BACKLOG_API_TOKEN ||
|
|
101
|
+
file.token ||
|
|
102
|
+
machine.BACKLOG_API_TOKEN ||
|
|
103
|
+
tokenStore(project) ||
|
|
104
|
+
"";
|
|
105
|
+
return { url, token, project };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* True when the CLI should use the service backend.
|
|
110
|
+
*
|
|
111
|
+
* `opts.forceFile` pins the legacy file backend unconditionally. An explicit
|
|
112
|
+
* `--root <dir>` names a local checkout, so an ambient service config
|
|
113
|
+
* (`BACKLOG_BACKEND=service`, `BACKLOG_API_URL`/`TOKEN`, or a `.harness.json`
|
|
114
|
+
* board block) must never redirect that write to the shared board — the F-333
|
|
115
|
+
* leak, where file-backend QA tests passing `--root <tmp>` added fixture rows to
|
|
116
|
+
* the live service because the ambient config re-enabled it.
|
|
117
|
+
*
|
|
118
|
+
* Auto mode requires the root's OWN `.harness.json` `board.url` — i.e. the
|
|
119
|
+
* project itself declares a board. Ambient environment alone (the
|
|
120
|
+
* `board-service.sh` shell hook exports `BACKLOG_API_URL`/`TOKEN`/`PROJECT`
|
|
121
|
+
* globally) must NOT auto-select the service, or any file-backend run under a
|
|
122
|
+
* board-configured shell (e.g. `npm test` in the harness) writes its local
|
|
123
|
+
* fixtures into the live shared board — the F-339 fixture-row leak. An
|
|
124
|
+
* env-only setup opts in explicitly with `BACKLOG_BACKEND=service`.
|
|
125
|
+
*
|
|
126
|
+
* A declared board is MANDATORY: once the project itself declares `board.url`,
|
|
127
|
+
* the service backend wins even when the token is not configured yet. The
|
|
128
|
+
* request then fails loudly in `httpSync` ("token missing") instead of quietly
|
|
129
|
+
* writing the checkout's local `BACKLOG.md` — the split-board defect where a
|
|
130
|
+
* feature worktree filed a row that never reached the main board. The legacy
|
|
131
|
+
* file backend remains available only through an explicit opt-out
|
|
132
|
+
* (`BACKLOG_BACKEND=file`, `--root`, or the durable `.harness.json`
|
|
133
|
+
* `board.backend: "file"` — a project choice that also beats ambient env).
|
|
134
|
+
*/
|
|
135
|
+
function enabled(root, opts) {
|
|
136
|
+
if (opts && opts.forceFile) return false;
|
|
137
|
+
const declared = projectBoardConfig(root);
|
|
138
|
+
if (declared.backend === "file") return false;
|
|
139
|
+
if (process.env.BACKLOG_BACKEND === "file") return false;
|
|
140
|
+
if (process.env.BACKLOG_BACKEND === "service") return true;
|
|
141
|
+
if (declared.backend === "service") return true;
|
|
142
|
+
if (!declared.url) return false;
|
|
143
|
+
return Boolean(config(root).url);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function projectKey(root) {
|
|
147
|
+
const c = config(root);
|
|
148
|
+
if (c.project) return c.project;
|
|
149
|
+
try {
|
|
150
|
+
const cfg = JSON.parse(fs.readFileSync(path.join(root, ".harness.json"), "utf8"));
|
|
151
|
+
if (cfg && typeof cfg.projectName === "string" && cfg.projectName.trim()) return cfg.projectName.trim();
|
|
152
|
+
} catch {
|
|
153
|
+
/* no .harness.json — fall back to the directory name */
|
|
154
|
+
}
|
|
155
|
+
return path.basename(root);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Synchronous HTTP via a tiny child that uses fetch and prints the response.
|
|
160
|
+
* The CLI is synchronous end-to-end (execFileSync-based), so a blocking bridge
|
|
161
|
+
* keeps the call sites unchanged and avoids rewriting every command async.
|
|
162
|
+
*/
|
|
163
|
+
function httpSync(root, method, endpoint, body) {
|
|
164
|
+
const c = config(root);
|
|
165
|
+
if (!c.url) throw new Error("board service not configured: set BACKLOG_API_URL");
|
|
166
|
+
if (!c.token) {
|
|
167
|
+
const base = process.env.XDG_CONFIG_HOME || path.join(require("os").homedir(), ".config");
|
|
168
|
+
throw new Error(
|
|
169
|
+
`board service token missing for project "${projectKey(root)}": set BACKLOG_API_TOKEN, ` +
|
|
170
|
+
`add it to ${path.join(base, "agent-harness", "tokens.json")} or ` +
|
|
171
|
+
`${path.join(base, "agent-harness", "board.env")}.\n` +
|
|
172
|
+
"This project declares a board service, so the CLI will not fall back to a checkout-local " +
|
|
173
|
+
"BACKLOG.md (set BACKLOG_BACKEND=file only to opt into the legacy board deliberately)."
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const payload = JSON.stringify({
|
|
178
|
+
url: `${c.url}${endpoint}`,
|
|
179
|
+
method,
|
|
180
|
+
token: c.token,
|
|
181
|
+
project: projectKey(root),
|
|
182
|
+
body: body === undefined ? null : body,
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
const script = `
|
|
186
|
+
const p = JSON.parse(require("fs").readFileSync(0, "utf8"));
|
|
187
|
+
const headers = { Authorization: "Bearer " + p.token, "X-Project": p.project };
|
|
188
|
+
const init = { method: p.method, headers };
|
|
189
|
+
if (p.body !== null) { headers["Content-Type"] = "application/json"; init.body = JSON.stringify(p.body); }
|
|
190
|
+
fetch(p.url, init).then(async (r) => {
|
|
191
|
+
const text = await r.text();
|
|
192
|
+
process.stdout.write(JSON.stringify({ status: r.status, body: text }));
|
|
193
|
+
}).catch((e) => { process.stdout.write(JSON.stringify({ status: 0, error: String(e && e.message || e) })); });
|
|
194
|
+
`;
|
|
195
|
+
|
|
196
|
+
const res = require("child_process").execFileSync(process.execPath, ["-e", script], {
|
|
197
|
+
input: payload,
|
|
198
|
+
encoding: "utf8",
|
|
199
|
+
maxBuffer: 32 * 1024 * 1024,
|
|
200
|
+
});
|
|
201
|
+
let parsed;
|
|
202
|
+
try {
|
|
203
|
+
parsed = JSON.parse(res);
|
|
204
|
+
} catch {
|
|
205
|
+
throw new Error(`board service: unparseable response: ${res.slice(0, 200)}`);
|
|
206
|
+
}
|
|
207
|
+
if (parsed.status === 0) throw new Error(`board service unreachable at ${c.url}: ${parsed.error}`);
|
|
208
|
+
const json = parsed.body ? JSON.parse(parsed.body) : {};
|
|
209
|
+
if (parsed.status >= 400) throw new Error(json.error || `board service error ${parsed.status}`);
|
|
210
|
+
return json;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** The frozen BacklogBoard shape. */
|
|
214
|
+
function getBoard(root) {
|
|
215
|
+
return httpSync(root, "GET", "/api/board");
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function cmdResult(root, action, id, body) {
|
|
219
|
+
const endpoint = id ? `/api/items/${encodeURIComponent(id)}/${action}` : `/api/items`;
|
|
220
|
+
return httpSync(root, "POST", endpoint, body || {});
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function add(root, args) {
|
|
224
|
+
return httpSync(root, "POST", "/api/items", {
|
|
225
|
+
task: args._[0],
|
|
226
|
+
priority: args.p,
|
|
227
|
+
evidence: args.evidence,
|
|
228
|
+
epic: args.epic,
|
|
229
|
+
dependsOn: args["depends-on"] || args.depends,
|
|
230
|
+
id: args.id,
|
|
231
|
+
}).result;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** Look up a row in the live board so results carry task/closed for output parity. */
|
|
235
|
+
function rowById(board, id) {
|
|
236
|
+
for (const key of ["open", "queued", "inprogress", "frozen", "archive"]) {
|
|
237
|
+
const row = (board[key] || []).find((r) => r.id === id);
|
|
238
|
+
if (row) return { key, row };
|
|
239
|
+
}
|
|
240
|
+
return { key: null, row: null };
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function take(root, id, handoff) {
|
|
244
|
+
const json = httpSync(root, "POST", `/api/items/${encodeURIComponent(id)}/take`, { handoff });
|
|
245
|
+
const { row } = rowById(json.board, id);
|
|
246
|
+
return { ...json.result, handoff: row ? row.handoff : handoff };
|
|
247
|
+
}
|
|
248
|
+
function queue(root, id) {
|
|
249
|
+
const json = httpSync(root, "POST", `/api/items/${encodeURIComponent(id)}/queue`, {});
|
|
250
|
+
const { row } = rowById(json.board, id);
|
|
251
|
+
return { ...json.result, task: row ? row.task : undefined };
|
|
252
|
+
}
|
|
253
|
+
function unqueue(root, id) {
|
|
254
|
+
const json = httpSync(root, "POST", `/api/items/${encodeURIComponent(id)}/unqueue`, {});
|
|
255
|
+
const { row } = rowById(json.board, id);
|
|
256
|
+
return { ...json.result, task: row ? row.task : undefined };
|
|
257
|
+
}
|
|
258
|
+
function archive(root, id, closed) {
|
|
259
|
+
const json = httpSync(root, "POST", `/api/items/${encodeURIComponent(id)}/archive`, { closed });
|
|
260
|
+
const { row } = rowById(json.board, id);
|
|
261
|
+
return { ...json.result, task: row ? row.task : undefined, closed: row ? row.closed : closed };
|
|
262
|
+
}
|
|
263
|
+
function freeze(root, id, why, reopen) {
|
|
264
|
+
const json = httpSync(root, "POST", `/api/items/${encodeURIComponent(id)}/freeze`, { why, reopen });
|
|
265
|
+
const { row } = rowById(json.board, id);
|
|
266
|
+
return { ...json.result, cond: row ? row.condition : [why, reopen ? `reopen when ${reopen}` : ""].filter(Boolean).join(" — ") };
|
|
267
|
+
}
|
|
268
|
+
function reopen(root, id, reason, priority) {
|
|
269
|
+
const json = httpSync(root, "POST", `/api/items/${encodeURIComponent(id)}/reopen`, { reason, priority });
|
|
270
|
+
const { row } = rowById(json.board, id);
|
|
271
|
+
return { ...json.result, reason: reason || "reopened", priority: row ? row.priority : priority };
|
|
272
|
+
}
|
|
273
|
+
function priority(root, id, p) {
|
|
274
|
+
return httpSync(root, "POST", `/api/items/${encodeURIComponent(id)}/priority`, { priority: p }).result;
|
|
275
|
+
}
|
|
276
|
+
function setEpic(root, id, to) {
|
|
277
|
+
return httpSync(root, "POST", `/api/items/${encodeURIComponent(id)}/epic`, { to }).result;
|
|
278
|
+
}
|
|
279
|
+
function depends(root, id, on) {
|
|
280
|
+
return httpSync(root, "POST", `/api/items/${encodeURIComponent(id)}/depends`, { on }).result;
|
|
281
|
+
}
|
|
282
|
+
function owns(root, id, files) {
|
|
283
|
+
return httpSync(root, "POST", `/api/items/${encodeURIComponent(id)}/owns`, { files }).result;
|
|
284
|
+
}
|
|
285
|
+
function worktreeRecord(root, id, dir, branch, handoff) {
|
|
286
|
+
return httpSync(root, "POST", `/api/items/${encodeURIComponent(id)}/worktree`, { dir, branch, handoff }).result;
|
|
287
|
+
}
|
|
288
|
+
function epicAdd(root, key, label, goal) {
|
|
289
|
+
return httpSync(root, "POST", "/api/epics", { key, label, goal }).result;
|
|
290
|
+
}
|
|
291
|
+
function next(root) {
|
|
292
|
+
return httpSync(root, "GET", "/api/next");
|
|
293
|
+
}
|
|
294
|
+
function nextTake(root, handoff) {
|
|
295
|
+
return httpSync(root, "POST", "/api/next/take", { handoff }).result;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* The `list --json` shape is the board contract; both backends share it via
|
|
300
|
+
* `getBoard`. The human `list` renderer needs the same arrays, so callers use
|
|
301
|
+
* this directly.
|
|
302
|
+
*/
|
|
303
|
+
module.exports = {
|
|
304
|
+
enabled,
|
|
305
|
+
projectKey,
|
|
306
|
+
getBoard,
|
|
307
|
+
add,
|
|
308
|
+
take,
|
|
309
|
+
queue,
|
|
310
|
+
unqueue,
|
|
311
|
+
archive,
|
|
312
|
+
freeze,
|
|
313
|
+
reopen,
|
|
314
|
+
priority,
|
|
315
|
+
setEpic,
|
|
316
|
+
depends,
|
|
317
|
+
owns,
|
|
318
|
+
worktreeRecord,
|
|
319
|
+
epicAdd,
|
|
320
|
+
next,
|
|
321
|
+
nextTake,
|
|
322
|
+
httpSync,
|
|
323
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/*
|
|
4
|
+
* board-lib — shared BACKLOG.md row primitives (harness-shipped).
|
|
5
|
+
*
|
|
6
|
+
* One home for the markdown-table row logic the board toolchain shares, so a
|
|
7
|
+
* parse/format bug is fixed in exactly one place instead of being copy-pasted
|
|
8
|
+
* across backlog.js + the QA gates (check-backlog / check-concurrency /
|
|
9
|
+
* merge-backlog). F-094 was the cautionary tale: the write-path sanitizer was
|
|
10
|
+
* added only to a deployed copy and silently reverted by the next harness
|
|
11
|
+
* update because it never reached a shared source.
|
|
12
|
+
*
|
|
13
|
+
* Exports:
|
|
14
|
+
* splitCells(row) split a markdown table row on unescaped `|`
|
|
15
|
+
* isSep(cells) true when a row is a `|---|` separator
|
|
16
|
+
* sanitizeCell(value) make a single cell table-safe (single line, no `|`)
|
|
17
|
+
* formatRow(cells) join cells into one physical `| a | b |` row
|
|
18
|
+
*/
|
|
19
|
+
function splitCells(row) {
|
|
20
|
+
const cells = [];
|
|
21
|
+
let cur = "";
|
|
22
|
+
let esc = false;
|
|
23
|
+
for (const ch of row) {
|
|
24
|
+
if (esc) {
|
|
25
|
+
cur += ch;
|
|
26
|
+
esc = false;
|
|
27
|
+
} else if (ch === "\\") {
|
|
28
|
+
esc = true;
|
|
29
|
+
cur += ch;
|
|
30
|
+
} else if (ch === "|") {
|
|
31
|
+
cells.push(cur.trim());
|
|
32
|
+
cur = "";
|
|
33
|
+
} else {
|
|
34
|
+
cur += ch;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
cells.push(cur.trim());
|
|
38
|
+
return cells;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function isSep(cells) {
|
|
42
|
+
return cells.every((c) => /^[-:|\s]*$/.test(c));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* A markdown table cell is one token on one physical line. A raw newline (or any
|
|
46
|
+
* other control char) or an unescaped `|` would split one logical row into
|
|
47
|
+
* corrupt fragments — the F-094 newline corruption and the F-127 pipe corruption
|
|
48
|
+
* both came from cells written verbatim. Sanitize before ANY cell is written, so
|
|
49
|
+
* no caller (CLI add, backlog_* tools, reports/admin routes that shell the CLI)
|
|
50
|
+
* can corrupt the board through the shared write path. */
|
|
51
|
+
function sanitizeCell(value) {
|
|
52
|
+
return String(value)
|
|
53
|
+
.replace(/[\x00-\x1f\x7f]/g, " ") // control chars (incl \n, \r, \t) -> space
|
|
54
|
+
.replace(/\s+/g, " ") // collapse whitespace runs (incl ones we just made)
|
|
55
|
+
.replace(/\|/g, "/") // a pipe can never become a column delimiter
|
|
56
|
+
.trim();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function formatRow(cells) {
|
|
60
|
+
return "| " + cells.map(sanitizeCell).join(" | ") + " |";
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/* Return a cycle (as an `A -> B -> A` id list) in a dependency graph
|
|
64
|
+
* (Map<id, string[]>), or null. A cycle leaves every member permanently
|
|
65
|
+
* "blocked" with no mechanical signal, so the board write path and the gate
|
|
66
|
+
* both reject it. Pure — shared by backlog.js and check-backlog.js. */
|
|
67
|
+
function findCycle(graph) {
|
|
68
|
+
const WHITE = 0;
|
|
69
|
+
const GRAY = 1;
|
|
70
|
+
const BLACK = 2;
|
|
71
|
+
const color = new Map();
|
|
72
|
+
const stack = [];
|
|
73
|
+
let cycle = null;
|
|
74
|
+
const visit = (node) => {
|
|
75
|
+
color.set(node, GRAY);
|
|
76
|
+
stack.push(node);
|
|
77
|
+
for (const dep of graph.get(node) || []) {
|
|
78
|
+
if (!graph.has(dep)) continue; // unknown/archived refs are handled elsewhere
|
|
79
|
+
const c = color.get(dep) || WHITE;
|
|
80
|
+
if (c === GRAY) {
|
|
81
|
+
cycle = stack.slice(stack.indexOf(dep)).concat(dep);
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
if (c === WHITE && visit(dep)) return true;
|
|
85
|
+
}
|
|
86
|
+
stack.pop();
|
|
87
|
+
color.set(node, BLACK);
|
|
88
|
+
return false;
|
|
89
|
+
};
|
|
90
|
+
for (const node of graph.keys()) {
|
|
91
|
+
if ((color.get(node) || WHITE) === WHITE && visit(node)) break;
|
|
92
|
+
}
|
|
93
|
+
return cycle;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
module.exports = { splitCells, isSep, sanitizeCell, formatRow, findCycle };
|