@mmerterden/multi-agent-pipeline 23.6.0 → 24.0.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 +56 -1
- package/README.md +61 -27
- package/README.tr.md +46 -12
- package/SECURITY.md +3 -3
- package/docs/architecture.md +47 -8
- package/docs/ecosystem.md +20 -18
- package/docs/engineering.md +1 -1
- package/docs/facts.json +8 -6
- package/docs/features.md +59 -15
- package/install/_codex-agents.mjs +13 -8
- package/install/_common.mjs +24 -0
- package/install/_dev-only-files.mjs +4 -0
- package/install/_mcp-register.mjs +6 -2
- package/install/_rewrite-tree.mjs +197 -0
- package/install/codex.mjs +96 -180
- package/install/copilot.mjs +24 -54
- package/install/index.mjs +29 -11
- package/install/templates/codex-instructions.md +21 -5
- package/install/templates/copilot-instructions.md +21 -14
- package/manifest.json +2082 -0
- package/package.json +6 -2
- package/pipeline/commands/multi-agent/SKILL.md +7 -5
- package/pipeline/commands/multi-agent/analysis/SKILL.md +4 -0
- package/pipeline/commands/multi-agent/autopilot-on/SKILL.md +31 -3
- package/pipeline/commands/multi-agent/autopilot-status/SKILL.md +5 -1
- package/pipeline/commands/multi-agent/channels/SKILL.md +16 -8
- package/pipeline/commands/multi-agent/log/SKILL.md +2 -0
- package/pipeline/commands/multi-agent/resume/SKILL.md +2 -0
- package/pipeline/commands/multi-agent/review-rounds/SKILL.md +94 -0
- package/pipeline/commands/multi-agent/stack/SKILL.md +1 -1
- package/pipeline/commands/multi-agent/sync/SKILL.md +3 -3
- package/pipeline/contract/manifest.json +1 -1
- package/pipeline/contract/types/index.d.ts +1 -0
- package/pipeline/lib/_jira-auth.sh +50 -78
- package/pipeline/lib/_service-account.sh +191 -0
- package/pipeline/lib/credential-inventory.sh +49 -37
- package/pipeline/lib/credential-store.sh +48 -3
- package/pipeline/lib/fetch-confluence.sh +76 -92
- package/pipeline/lib/fetch-crashlytics.sh +30 -59
- package/pipeline/lib/fetch-figma-annotations.sh +9 -9
- package/pipeline/lib/fetch-fortify.sh +77 -81
- package/pipeline/lib/fetch-graylog.sh +38 -77
- package/pipeline/lib/figma-mcp-refresh.sh +23 -4
- package/pipeline/lib/figma-screenshot.sh +7 -8
- package/pipeline/lib/figma-token.sh +39 -46
- package/pipeline/lib/host.mjs +138 -0
- package/pipeline/lib/host.sh +48 -0
- package/pipeline/lib/issue-fetcher.sh +25 -41
- package/pipeline/lib/jira-publish.sh +23 -21
- package/pipeline/lib/local-model.mjs +93 -0
- package/pipeline/lib/md2confluence-v3.py +37 -30
- package/pipeline/lib/model-dispatch.sh +41 -4
- package/pipeline/lib/model-resolve.mjs +58 -0
- package/pipeline/lib/post-pr-review.sh +38 -53
- package/pipeline/lib/reviewer-families.mjs +70 -0
- package/pipeline/lib/service-account.mjs +2131 -0
- package/pipeline/lib/service-account.sh +35 -0
- package/pipeline/lib/usage-names.generated.mjs +3 -0
- package/pipeline/lib/usage-token.mjs +64 -24
- package/pipeline/lib/usage-vocab.mjs +1 -1
- package/pipeline/lib/user-facing.mjs +11 -3
- package/pipeline/lib/vercel-deploy.sh +17 -26
- package/pipeline/multi-agent-refs/_entry-picker.md +62 -0
- package/pipeline/multi-agent-refs/_input-parser.md +1 -1
- package/pipeline/multi-agent-refs/analysis/intake.md +2 -0
- package/pipeline/multi-agent-refs/analysis/reusable-refs.md +1 -0
- package/pipeline/multi-agent-refs/analysis/unattended.md +135 -0
- package/pipeline/multi-agent-refs/autopilot-on/details.md +16 -0
- package/pipeline/multi-agent-refs/channels/generator.md +10 -2
- package/pipeline/multi-agent-refs/channels/menu.md +3 -1
- package/pipeline/multi-agent-refs/channels/preview.md +3 -1
- package/pipeline/multi-agent-refs/channels/reference.md +16 -2
- package/pipeline/multi-agent-refs/channels/report-file.md +188 -0
- package/pipeline/multi-agent-refs/component-dispatch.md +2 -2
- package/pipeline/multi-agent-refs/cross-cli-contract.md +38 -30
- package/pipeline/multi-agent-refs/features/autopilot-circuit-breaker.md +4 -4
- package/pipeline/multi-agent-refs/features/doctor.md +37 -11
- package/pipeline/multi-agent-refs/features/free-models.md +3 -3
- package/pipeline/multi-agent-refs/features/local-model.md +87 -0
- package/pipeline/multi-agent-refs/features/model-fallback.md +25 -10
- package/pipeline/multi-agent-refs/features/product-context.md +6 -5
- package/pipeline/multi-agent-refs/features/review-delta.md +1 -1
- package/pipeline/multi-agent-refs/features/review-rounds.md +40 -0
- package/pipeline/multi-agent-refs/features/rework-escalation.md +5 -4
- package/pipeline/multi-agent-refs/features/service-accounts.md +233 -0
- package/pipeline/multi-agent-refs/features/unattended-security.md +10 -1
- package/pipeline/multi-agent-refs/help/en.md +31 -2
- package/pipeline/multi-agent-refs/help/tr.md +31 -2
- package/pipeline/multi-agent-refs/orchestrator/copilot-pipeline.md +3 -2
- package/pipeline/multi-agent-refs/orchestrator/dispatcher.md +2 -1
- package/pipeline/multi-agent-refs/phases/modes.md +20 -1
- package/pipeline/multi-agent-refs/phases/operations.md +1 -1
- package/pipeline/multi-agent-refs/phases/phase-0-init.md +1 -1
- package/pipeline/multi-agent-refs/phases/phase-2-dev.md +4 -4
- package/pipeline/multi-agent-refs/phases/phase-3-review.md +7 -3
- package/pipeline/multi-agent-refs/phases/phase-5-report.md +12 -10
- package/pipeline/multi-agent-refs/phases.md +4 -3
- package/pipeline/multi-agent-refs/resume/details.md +2 -0
- package/pipeline/multi-agent-refs/review/panel.md +30 -18
- package/pipeline/multi-agent-refs/setup/discovery.md +17 -5
- package/pipeline/multi-agent-refs/setup/token-save-flow.md +21 -2
- package/pipeline/multi-agent-refs/sync/overview.md +11 -5
- package/pipeline/multi-agent-refs/tracker-contract.md +28 -10
- package/pipeline/office/index.html +4 -4
- package/pipeline/schemas/agent-state.schema.json +19 -1
- package/pipeline/schemas/autopilot-config.schema.json +29 -4
- package/pipeline/schemas/hosts.json +512 -0
- package/pipeline/schemas/hosts.schema.json +310 -0
- package/pipeline/schemas/launch.json +22 -2
- package/pipeline/schemas/launch.schema.json +2 -1
- package/pipeline/schemas/phases.json +21 -3
- package/pipeline/schemas/phases.schema.json +8 -0
- package/pipeline/schemas/prefs.schema.json +346 -7
- package/pipeline/schemas/token-budget.json +2 -2
- package/pipeline/scripts/.doctor-mut.47076.mjs +2253 -0
- package/pipeline/scripts/_autopilot-config.mjs +67 -4
- package/pipeline/scripts/_autopilot-item.mjs +67 -0
- package/pipeline/scripts/_autopilot-outcomes.mjs +6 -0
- package/pipeline/scripts/_cost.mjs +75 -3
- package/pipeline/scripts/analysis-sources.mjs +22 -5
- package/pipeline/scripts/analysis-unattended.mjs +360 -0
- package/pipeline/scripts/anonymize-findings.mjs +3 -7
- package/pipeline/scripts/autopilot-arming.mjs +19 -10
- package/pipeline/scripts/autopilot-intake.mjs +124 -27
- package/pipeline/scripts/autopilot-menubar.swift +7 -0
- package/pipeline/scripts/autopilot-runner.mjs +77 -48
- package/pipeline/scripts/autopilot-status.sh +32 -9
- package/pipeline/scripts/bulk-read.sh +37 -5
- package/pipeline/scripts/confluence-readback.mjs +15 -7
- package/pipeline/scripts/cost-table.json +65 -25
- package/pipeline/scripts/doctor.mjs +119 -32
- package/pipeline/scripts/entry-mode.mjs +101 -0
- package/pipeline/scripts/estimate.mjs +30 -16
- package/pipeline/scripts/feedback-send.mjs +11 -8
- package/pipeline/scripts/gen-facts.mjs +16 -13
- package/pipeline/scripts/jira-attach.sh +23 -28
- package/pipeline/scripts/jira-search.sh +5 -21
- package/pipeline/scripts/launch-request.mjs +15 -9
- package/pipeline/scripts/migrate-prefs.mjs +56 -0
- package/pipeline/scripts/phase-tracker.sh +146 -38
- package/pipeline/scripts/priority-review.mjs +14 -7
- package/pipeline/scripts/product-context.mjs +26 -7
- package/pipeline/scripts/prune-logs.sh +4 -2
- package/pipeline/scripts/report-file.mjs +285 -0
- package/pipeline/scripts/review-rounds.mjs +592 -0
- package/pipeline/scripts/rework-escalation.mjs +26 -7
- package/pipeline/scripts/service-read.mjs +19 -17
- package/pipeline/scripts/skill-siblings.mjs +17 -1
- package/pipeline/scripts/status-overview.mjs +20 -10
- package/pipeline/scripts/uninstall.mjs +145 -57
- package/pipeline/scripts/usage-register.mjs +34 -11
- package/pipeline/scripts/usage-report.mjs +31 -26
- package/pipeline/scripts/validate-state.mjs +19 -11
- package/pipeline/scripts/validate-triage.mjs +11 -1
- package/pipeline/scripts/work-items.mjs +25 -28
- package/pipeline/scripts/write-store-config.mjs +37 -11
- package/pipeline/skills/.skill-manifest.json +11 -7
- package/pipeline/skills/.skills-index.json +13 -2
- package/pipeline/skills/shared/README.md +4 -3
- package/pipeline/skills/shared/core/multi-agent/SKILL.md +14 -6
- package/pipeline/skills/shared/core/multi-agent-analysis/SKILL.md +2 -0
- package/pipeline/skills/shared/core/multi-agent-channels/SKILL.md +11 -8
- package/pipeline/skills/shared/core/multi-agent-resume/SKILL.md +1 -1
- package/pipeline/skills/shared/core/multi-agent-review-rounds/SKILL.md +92 -0
- package/pipeline/skills/shared/core/multi-agent-sync/SKILL.md +3 -3
- package/pipeline/skills/skills-index.md +2 -1
- package/pipeline/lib/credential-resolve.mjs +0 -75
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* report-file.mjs - the run's report, on disk, whatever the channels did.
|
|
4
|
+
*
|
|
5
|
+
* Phase 5 composes a development summary and test scenarios and hands them to
|
|
6
|
+
* PR, Jira, Confluence and Wiki. Every one of those is an external write, and
|
|
7
|
+
* three ordinary paths end with nothing written at all: a local-only repo
|
|
8
|
+
* short-circuits before the menu, an unattended run defers delivery to the
|
|
9
|
+
* runner, and a cancelled or timed-out menu posts nothing. On a machine with no
|
|
10
|
+
* tracker the work was summarized and then thrown away.
|
|
11
|
+
*
|
|
12
|
+
* So this is not a fifth channel. A channel is selectable, waits for the
|
|
13
|
+
* approval gate, and is skipped unattended and offline - each of which would
|
|
14
|
+
* reintroduce one of the three losses. It is internal capture, like
|
|
15
|
+
* `agent-log.md`: unconditional, local, and with no preference to get wrong.
|
|
16
|
+
*
|
|
17
|
+
* Nothing here composes anything. The bodies are handed in as files and copied
|
|
18
|
+
* byte for byte, so the file says exactly what the preview said and what the
|
|
19
|
+
* adapters posted.
|
|
20
|
+
*
|
|
21
|
+
* Usage:
|
|
22
|
+
* report-file.mjs write --dir <task-dir> --run <id> --meta <meta.json>
|
|
23
|
+
* --body <name>=<file> [--body ...] [--delivery <json>]
|
|
24
|
+
* report-file.mjs path --dir <task-dir>
|
|
25
|
+
*
|
|
26
|
+
* Block names: `report`, `pr:<label>`, `jira`, `confluence`. Order is fixed
|
|
27
|
+
* here, not by the argument order.
|
|
28
|
+
*
|
|
29
|
+
* Exit: 0 written; 2 usage, no body, an empty body, or a path that is not
|
|
30
|
+
* inside the logs root; 7 a body carries credential-shaped text.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
import {
|
|
34
|
+
existsSync,
|
|
35
|
+
lstatSync,
|
|
36
|
+
mkdirSync,
|
|
37
|
+
readFileSync,
|
|
38
|
+
readdirSync,
|
|
39
|
+
realpathSync,
|
|
40
|
+
renameSync,
|
|
41
|
+
rmSync,
|
|
42
|
+
unlinkSync,
|
|
43
|
+
writeFileSync,
|
|
44
|
+
} from "node:fs";
|
|
45
|
+
import { basename, join, resolve } from "node:path";
|
|
46
|
+
import { ArgsError, parseArgs } from "../lib/args.mjs";
|
|
47
|
+
import { scan } from "../lib/outbound-gate.mjs";
|
|
48
|
+
import { logsRoot } from "./_run-paths.mjs";
|
|
49
|
+
|
|
50
|
+
await import("../lib/cli-help.mjs").then(
|
|
51
|
+
(m) => m.exitOnHelp(import.meta.url),
|
|
52
|
+
() => {},
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const FILE_NAME = "task-report.md";
|
|
56
|
+
const HISTORY_DIR = "report-history";
|
|
57
|
+
const HISTORY_KEEP = 5;
|
|
58
|
+
|
|
59
|
+
/** Blocks in the order a reader wants them, whatever order they arrived in. */
|
|
60
|
+
const ORDER = ["report", "pr", "jira", "confluence"];
|
|
61
|
+
const rank = (name) => {
|
|
62
|
+
const kind = name.startsWith("pr:") ? "pr" : name;
|
|
63
|
+
const at = ORDER.indexOf(kind);
|
|
64
|
+
return at < 0 ? ORDER.length : at;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/** What a block is called in the file. Fixed English, so the file stays parseable. */
|
|
68
|
+
function heading(name) {
|
|
69
|
+
if (name === "report") return "Report";
|
|
70
|
+
if (name === "jira") return "Jira comment";
|
|
71
|
+
if (name === "confluence") return "Confluence page";
|
|
72
|
+
if (name.startsWith("pr:")) return `PR description (${name.slice(3)})`;
|
|
73
|
+
return name;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function die(code, message) {
|
|
77
|
+
process.stderr.write(`report-file: ${message}\n`);
|
|
78
|
+
process.exit(code);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The flags, through the shared parser.
|
|
83
|
+
*
|
|
84
|
+
* `--body` is the only repeatable one, and every flag here takes a value, so
|
|
85
|
+
* a missing one is a usage error rather than a `true` that would later read
|
|
86
|
+
* as a filename.
|
|
87
|
+
*/
|
|
88
|
+
function parseArgv(argv) {
|
|
89
|
+
try {
|
|
90
|
+
const { flags } = parseArgs(argv, {
|
|
91
|
+
values: ["dir", "run", "meta", "delivery", "body"],
|
|
92
|
+
multiple: ["body"],
|
|
93
|
+
unknown: "error",
|
|
94
|
+
});
|
|
95
|
+
return { ...flags, body: flags.body ?? [] };
|
|
96
|
+
} catch (error) {
|
|
97
|
+
if (error instanceof ArgsError) die(2, error.message);
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The task directory, proven to be inside the logs root.
|
|
104
|
+
*
|
|
105
|
+
* `realpath` on the root and on the directory's parent, then a prefix test: a
|
|
106
|
+
* caller that passes `..`, or a symlink pointing out of the tree, is asking
|
|
107
|
+
* this script to write somewhere it has no business writing. Refused rather
|
|
108
|
+
* than normalized, because a path that needed normalizing was not the path the
|
|
109
|
+
* caller meant.
|
|
110
|
+
*/
|
|
111
|
+
function taskDir(given) {
|
|
112
|
+
if (!given) die(2, "--dir is required");
|
|
113
|
+
const dir = resolve(given);
|
|
114
|
+
if (!existsSync(dir)) die(2, `no such directory: ${dir}`);
|
|
115
|
+
let real;
|
|
116
|
+
let root;
|
|
117
|
+
try {
|
|
118
|
+
real = realpathSync(dir);
|
|
119
|
+
root = realpathSync(logsRoot());
|
|
120
|
+
} catch {
|
|
121
|
+
die(2, "the logs root does not resolve");
|
|
122
|
+
}
|
|
123
|
+
if (real !== root && !real.startsWith(root + "/")) {
|
|
124
|
+
die(2, `refusing to write outside the logs root: ${real}`);
|
|
125
|
+
}
|
|
126
|
+
return real;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** A path that exists and is not a link. A link here points the write elsewhere. */
|
|
130
|
+
function refuseLink(path, what) {
|
|
131
|
+
if (!existsSync(path)) return;
|
|
132
|
+
if (lstatSync(path).isSymbolicLink()) die(2, `${what} is a symbolic link: ${path}`);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* The history name for a report already on disk.
|
|
137
|
+
*
|
|
138
|
+
* The stamp leads, so the directory sorts chronologically, and the run id
|
|
139
|
+
* follows, because the stamp is minute-resolution and two runs inside one
|
|
140
|
+
* minute would otherwise share a name - the second quietly replacing the first
|
|
141
|
+
* in the very place that exists to not lose it.
|
|
142
|
+
*/
|
|
143
|
+
function historyName(text) {
|
|
144
|
+
const stamp = (
|
|
145
|
+
/^- Written: (\d{4}-\d{2}-\d{2} \d{2}:\d{2})/m.exec(text)?.[1] ?? "unknown"
|
|
146
|
+
).replace(/[: ]/g, "-");
|
|
147
|
+
const run = (runOf(text) ?? "unknown").replace(/[^A-Za-z0-9._-]/g, "_").slice(0, 40);
|
|
148
|
+
return `task-report-${stamp}-${run}.md`;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** The run id a file on disk was written for. */
|
|
152
|
+
function runOf(text) {
|
|
153
|
+
return /^- Written:.*\(run ([^)]*)\)/m.exec(text)?.[1] ?? null;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function localStamp(now = new Date()) {
|
|
157
|
+
const p = (n) => String(n).padStart(2, "0");
|
|
158
|
+
return `${now.getFullYear()}-${p(now.getMonth() + 1)}-${p(now.getDate())} ${p(now.getHours())}:${p(now.getMinutes())}`;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function readJson(path, what) {
|
|
162
|
+
if (!path) return null;
|
|
163
|
+
try {
|
|
164
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
165
|
+
} catch {
|
|
166
|
+
die(2, `${what} does not parse: ${path}`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** The whole file, envelope then blocks. */
|
|
171
|
+
function render(meta, blocks, delivery) {
|
|
172
|
+
const head = [
|
|
173
|
+
`# ${meta.taskKey ?? "(untitled run)"}${meta.title ? ` - ${meta.title}` : ""}`,
|
|
174
|
+
"",
|
|
175
|
+
`- Branch: ${meta.branch ? `\`${meta.branch}\`${meta.base ? ` -> \`${meta.base}\`` : ""}` : "none"}`,
|
|
176
|
+
`- PR: ${meta.prUrl ?? "none"}`,
|
|
177
|
+
`- Tracker: ${meta.tracker ?? "none"}`,
|
|
178
|
+
`- Written: ${localStamp()} by /multi-agent:channels (run ${meta.runId})`,
|
|
179
|
+
`- Delivery: ${delivery ?? "not sent"}`,
|
|
180
|
+
"",
|
|
181
|
+
];
|
|
182
|
+
const body = [];
|
|
183
|
+
for (const { name, text } of blocks) {
|
|
184
|
+
body.push("---", "", `# ${heading(name)}`, "", text.replace(/\n+$/, ""), "");
|
|
185
|
+
}
|
|
186
|
+
return head.concat(body).join("\n").replace(/\n+$/, "") + "\n";
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** One line per channel, from the dispatch result, or null when nothing ran. */
|
|
190
|
+
function deliveryLine(results) {
|
|
191
|
+
if (!results) return null;
|
|
192
|
+
const parts = [];
|
|
193
|
+
for (const [channel, r] of Object.entries(results)) {
|
|
194
|
+
if (!r || typeof r !== "object") continue;
|
|
195
|
+
const status = r.status ?? "unknown";
|
|
196
|
+
parts.push(`${channel} ${status}${r.reason ? `: ${r.reason}` : ""}`);
|
|
197
|
+
}
|
|
198
|
+
return parts.length ? parts.join(" · ") : null;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function cmdWrite(a) {
|
|
202
|
+
const dir = taskDir(a.dir);
|
|
203
|
+
if (!a.run) die(2, "--run is required");
|
|
204
|
+
if (!a.body.length) die(2, "at least one --body <name>=<file> is required");
|
|
205
|
+
|
|
206
|
+
const blocks = [];
|
|
207
|
+
for (const pair of a.body) {
|
|
208
|
+
const at = pair.indexOf("=");
|
|
209
|
+
if (at < 1) die(2, `--body wants <name>=<file>, got: ${pair}`);
|
|
210
|
+
const name = pair.slice(0, at);
|
|
211
|
+
const file = pair.slice(at + 1);
|
|
212
|
+
let text;
|
|
213
|
+
try {
|
|
214
|
+
text = readFileSync(file, "utf8");
|
|
215
|
+
} catch {
|
|
216
|
+
die(2, `body file unreadable: ${file}`);
|
|
217
|
+
}
|
|
218
|
+
if (!text.trim()) die(2, `body is empty: ${name}`);
|
|
219
|
+
blocks.push({ name, text });
|
|
220
|
+
}
|
|
221
|
+
blocks.sort((x, y) => rank(x.name) - rank(y.name) || x.name.localeCompare(y.name));
|
|
222
|
+
|
|
223
|
+
// Scanned before anything is written, and the match itself is never printed:
|
|
224
|
+
// a report naming the rule that fired is useful, a report quoting the secret
|
|
225
|
+
// it found has copied the secret somewhere new.
|
|
226
|
+
for (const { name, text } of blocks) {
|
|
227
|
+
const blocking = scan(text).filter((f) => f.certain);
|
|
228
|
+
if (blocking.length) {
|
|
229
|
+
const named = blocking.map((f) => `${f.rule} (line ${f.line})`).join(", ");
|
|
230
|
+
die(7, `credential-shaped text in the ${heading(name)} body: ${named} - nothing written`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const meta = { ...(readJson(a.meta, "--meta") ?? {}), runId: a.run };
|
|
235
|
+
const delivery = deliveryLine(readJson(a.delivery, "--delivery"));
|
|
236
|
+
const target = join(dir, FILE_NAME);
|
|
237
|
+
const history = join(dir, HISTORY_DIR);
|
|
238
|
+
refuseLink(target, FILE_NAME);
|
|
239
|
+
refuseLink(history, HISTORY_DIR);
|
|
240
|
+
|
|
241
|
+
// A new run keeps the previous file rather than overwriting it, and the same
|
|
242
|
+
// run rewrites in place: the Edit loop and the delivery stamp are the same
|
|
243
|
+
// run saying the same thing again, not a second report.
|
|
244
|
+
let rotated = false;
|
|
245
|
+
if (existsSync(target)) {
|
|
246
|
+
const previous = readFileSync(target, "utf8");
|
|
247
|
+
if (runOf(previous) !== a.run) {
|
|
248
|
+
mkdirSync(history, { recursive: true, mode: 0o700 });
|
|
249
|
+
writeFileSync(join(history, historyName(previous)), previous, { mode: 0o600 });
|
|
250
|
+
rotated = true;
|
|
251
|
+
const kept = readdirSync(history)
|
|
252
|
+
.filter((f) => f.startsWith("task-report-") && f.endsWith(".md"))
|
|
253
|
+
.sort()
|
|
254
|
+
.reverse();
|
|
255
|
+
for (const old of kept.slice(HISTORY_KEEP)) rmSync(join(history, old), { force: true });
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Temp file in the same directory, then rename: a reader never sees a half
|
|
260
|
+
// written report, and a crash leaves the previous one intact.
|
|
261
|
+
const tmp = join(dir, `.${FILE_NAME}.${process.pid}.tmp`);
|
|
262
|
+
try {
|
|
263
|
+
writeFileSync(tmp, render(meta, blocks, delivery), { mode: 0o600 });
|
|
264
|
+
renameSync(tmp, target);
|
|
265
|
+
} catch (error) {
|
|
266
|
+
try {
|
|
267
|
+
unlinkSync(tmp);
|
|
268
|
+
} catch {
|
|
269
|
+
/* the temp file is already gone */
|
|
270
|
+
}
|
|
271
|
+
die(2, `could not write ${target}: ${error.message}`);
|
|
272
|
+
}
|
|
273
|
+
process.stdout.write(target + "\n");
|
|
274
|
+
if (rotated) process.stderr.write(`report-file: previous report kept in ${HISTORY_DIR}/\n`);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function cmdPath(a) {
|
|
278
|
+
process.stdout.write(join(taskDir(a.dir), FILE_NAME) + "\n");
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const [command, ...rest] = process.argv.slice(2);
|
|
282
|
+
const args = parseArgv(rest);
|
|
283
|
+
if (command === "write") cmdWrite(args);
|
|
284
|
+
else if (command === "path") cmdPath(args);
|
|
285
|
+
else die(2, `usage: ${basename(process.argv[1])} {write|path} --dir <task-dir> [...]`);
|