@mmerterden/multi-agent-pipeline 20.43.0 → 20.44.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 +34 -0
- package/README.md +19 -3
- package/README.tr.md +19 -4
- package/docs/ecosystem.md +7 -7
- package/docs/facts.json +8 -8
- package/docs/features.md +1 -1
- package/manifest.json +58 -48
- package/package.json +1 -1
- package/pipeline/commands/multi-agent/review-priority/SKILL.md +10 -5
- package/pipeline/commands/multi-agent/setup/SKILL.md +1 -1
- package/pipeline/commands/multi-agent/update/SKILL.md +18 -7
- package/pipeline/contract/CHANGELOG.md +43 -3
- package/pipeline/contract/README.md +65 -63
- package/pipeline/contract/fixtures/error-invalid-request.json +1 -1
- package/pipeline/contract/fixtures/error-unauthorized.json +1 -1
- package/pipeline/contract/fixtures/error-unsigned.json +1 -1
- package/pipeline/contract/manifest.json +41 -4
- package/pipeline/contract/types/index.d.ts +112 -3
- package/pipeline/multi-agent-refs/features/office-remote-protocol.md +4 -2
- package/pipeline/multi-agent-refs/features/office-threat-model.md +3 -1
- package/pipeline/multi-agent-refs/features/usage-reporting.md +48 -7
- package/pipeline/multi-agent-refs/help/en.md +1 -1
- package/pipeline/multi-agent-refs/help/tr.md +1 -1
- package/pipeline/office/index.html +434 -28
- package/pipeline/office/toolkit.json +1 -1
- package/pipeline/rules/outside-the-pipeline.md +1 -1
- package/pipeline/schemas/contract-error.schema.json +2 -1
- package/pipeline/schemas/disk-clean-request.schema.json +66 -0
- package/pipeline/schemas/disk-clean.schema.json +243 -0
- package/pipeline/schemas/office-jobs.json +25 -0
- package/pipeline/schemas/office-jobs.schema.json +19 -0
- package/pipeline/schemas/skill-catalog.schema.json +91 -0
- package/pipeline/schemas/toolkit-path-params.json +23 -1
- package/pipeline/scripts/_contract-core.mjs +1 -1
- package/pipeline/scripts/_contract-routes-catalog.mjs +31 -3
- package/pipeline/scripts/_contract-routes-ops.mjs +11 -1
- package/pipeline/scripts/_stack-routing.mjs +2 -0
- package/pipeline/scripts/contract-server.mjs +4 -0
- package/pipeline/scripts/job-launch.mjs +50 -9
- package/pipeline/scripts/office-disk.mjs +262 -0
- package/pipeline/scripts/skill-catalog.mjs +302 -0
- package/pipeline/scripts/stack-toggle.mjs +104 -41
- package/pipeline/scripts/usage-register.mjs +86 -9
- package/pipeline/skills/.skill-manifest.json +13 -5
- package/pipeline/skills/.skills-index.json +23 -1
- package/pipeline/skills/shared/README.md +5 -3
- package/pipeline/skills/shared/core/multi-agent-review-priority/SKILL.md +3 -2
- package/pipeline/skills/shared/core/multi-agent-setup/SKILL.md +1 -1
- package/pipeline/skills/shared/core/multi-agent-update/SKILL.md +11 -5
- package/pipeline/skills/shared/external/release-video/SKILL.md +147 -0
- package/pipeline/skills/shared/external/release-video/evals/evals.json +45 -0
- package/pipeline/skills/shared/external/short-video-craft/SKILL.md +177 -0
- package/pipeline/skills/shared/external/short-video-craft/evals/evals.json +43 -0
- package/pipeline/skills/shared/external/short-video-craft/references/generated-defaults.md +24 -0
- package/pipeline/skills/skills-index.md +3 -1
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* GET /v1/runs runs-index.mjs --json [--group G] [--redact]
|
|
17
17
|
* GET /v1/runs/{id} runs-index.mjs --json --task-id {id} [--redact]
|
|
18
18
|
* GET /v1/commands commands.mjs --json
|
|
19
|
+
* GET /v1/skills?repo=R skill-catalog.mjs --json [--repo P] (local-only)
|
|
19
20
|
* GET /v1/questions launch-request.mjs questions
|
|
20
21
|
* GET /v1/issues issues.mjs --json [--source S] [--project K]... [--max N]
|
|
21
22
|
* GET /v1/worktrees worktrees.mjs --json [--measure] [--redact]
|
|
@@ -31,6 +32,7 @@
|
|
|
31
32
|
* POST /v1/runs/{id}/kill run-kill.mjs preview, then apply (two steps)
|
|
32
33
|
* POST /v1/gc gc-plan.mjs preview, then apply (two steps)
|
|
33
34
|
* POST /v1/prune-logs office-prune.mjs preview, then apply the listed folders (two steps)
|
|
35
|
+
* POST /v1/disk-clean office-disk.mjs measure, preview ticked categories, apply them (two steps)
|
|
34
36
|
* GET /v1/settings office-settings.mjs --json
|
|
35
37
|
* POST /v1/settings office-settings.mjs set S V, after a preview (two steps)
|
|
36
38
|
* GET /v1/autopilot autopilot-control.mjs status
|
|
@@ -346,6 +348,7 @@ export const ROUTES = [
|
|
|
346
348
|
runs.list,
|
|
347
349
|
runs.one,
|
|
348
350
|
catalog.commands,
|
|
351
|
+
catalog.skills,
|
|
349
352
|
catalog.questions,
|
|
350
353
|
catalog.issues,
|
|
351
354
|
catalog.worktrees,
|
|
@@ -361,6 +364,7 @@ export const ROUTES = [
|
|
|
361
364
|
runs.kill,
|
|
362
365
|
ops.gc,
|
|
363
366
|
ops.pruneLogs,
|
|
367
|
+
ops.diskClean,
|
|
364
368
|
ops.settings,
|
|
365
369
|
ops.settingsSet,
|
|
366
370
|
ops.autopilot,
|
|
@@ -60,12 +60,13 @@ import {
|
|
|
60
60
|
workingTreeState,
|
|
61
61
|
writeRequestFile,
|
|
62
62
|
} from "./launch-request.mjs";
|
|
63
|
+
import { teams as priorityTeamFiles } from "./priority-review.mjs";
|
|
63
64
|
import { listRuns, logsRoot } from "./_run-paths.mjs";
|
|
64
65
|
import { exitOnHelp } from "../lib/cli-help.mjs";
|
|
65
66
|
|
|
66
67
|
exitOnHelp(import.meta.url);
|
|
67
68
|
|
|
68
|
-
export const CONTRACT_VERSION = "1.
|
|
69
|
+
export const CONTRACT_VERSION = "1.1.0";
|
|
69
70
|
|
|
70
71
|
const JOBS = JSON.parse(
|
|
71
72
|
readFileSync(new URL("../schemas/office-jobs.json", import.meta.url), "utf8"),
|
|
@@ -97,18 +98,50 @@ export const jobs = () => JOBS.jobs;
|
|
|
97
98
|
|
|
98
99
|
export const jobById = (id) => JOBS.jobs.find((j) => j.id === id) ?? null;
|
|
99
100
|
|
|
101
|
+
/** The review-priority teams whose rule files parse; none when the directory cannot be read. */
|
|
102
|
+
function priorityTeams(env) {
|
|
103
|
+
try {
|
|
104
|
+
return priorityTeamFiles(env).good;
|
|
105
|
+
} catch {
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Where an enum's values come from on this machine, by its `choices` name.
|
|
111
|
+
const CHOICES = {
|
|
112
|
+
"review-priority-teams": (env) => ({ values: priorityTeams(env).map((t) => t.slug) }),
|
|
113
|
+
"review-priority-presets": (env) => {
|
|
114
|
+
const valuesFor = {};
|
|
115
|
+
for (const t of priorityTeams(env)) valuesFor[t.slug] = t.selection.presets.map((p) => p.id);
|
|
116
|
+
return { values: [...new Set(Object.values(valuesFor).flat())], valuesFor };
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/** `job` with every `choices` parameter's values read from this machine. */
|
|
121
|
+
export function jobWithChoices(job, env = process.env) {
|
|
122
|
+
if (!job.params.some((p) => p.choices)) return job;
|
|
123
|
+
return {
|
|
124
|
+
...job,
|
|
125
|
+
params: job.params.map((p) => (p.choices ? { ...p, ...CHOICES[p.choices](env) } : p)),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
100
129
|
/**
|
|
101
130
|
* The catalog as GET /v1/jobs serves it: each job with whether its command is
|
|
102
|
-
* installed here, and why not when it is not.
|
|
131
|
+
* installed here, and why not when it is not, and its choices filled in.
|
|
103
132
|
*/
|
|
104
|
-
export function jobsDocument() {
|
|
133
|
+
export function jobsDocument({ env = process.env } = {}) {
|
|
105
134
|
const dir = commandsDir();
|
|
106
135
|
return {
|
|
107
136
|
contractVersion: CONTRACT_VERSION,
|
|
108
137
|
jobs: JOBS.jobs.map((j) => {
|
|
109
138
|
const installed =
|
|
110
139
|
j.command === "multi-agent" || Boolean(dir && existsSync(join(dir, j.command, "SKILL.md")));
|
|
111
|
-
return {
|
|
140
|
+
return {
|
|
141
|
+
...jobWithChoices(j, env),
|
|
142
|
+
available: installed,
|
|
143
|
+
reason: installed ? null : "command-not-installed",
|
|
144
|
+
};
|
|
112
145
|
}),
|
|
113
146
|
};
|
|
114
147
|
}
|
|
@@ -175,9 +208,14 @@ export function paramErrors(
|
|
|
175
208
|
if (!RUN_ID.test(v)) bad("a run id");
|
|
176
209
|
else if (knownRun && !knownRun(v)) bad("no run has that id");
|
|
177
210
|
break;
|
|
178
|
-
case "enum":
|
|
179
|
-
|
|
211
|
+
case "enum": {
|
|
212
|
+
const narrowed = p.valuesFor && p.dependsOn ? p.valuesFor[given[p.dependsOn]] : null;
|
|
213
|
+
if (!p.values.includes(v))
|
|
214
|
+
bad(`one of ${p.values.join(", ") || "nothing on this machine"}`);
|
|
215
|
+
else if (narrowed && !narrowed.includes(v))
|
|
216
|
+
bad(`one of ${narrowed.join(", ")} for that ${p.dependsOn}`);
|
|
180
217
|
break;
|
|
218
|
+
}
|
|
181
219
|
case "repo-path":
|
|
182
220
|
if (!repoPath || !insideRepo(repoPath, v)) bad("a path inside the repository");
|
|
183
221
|
break;
|
|
@@ -260,7 +298,9 @@ const fill = (template, values) =>
|
|
|
260
298
|
|
|
261
299
|
/** The prompt a solo job's session receives: the command and its arguments, in catalog order. */
|
|
262
300
|
export function soloPrompt(job, args) {
|
|
263
|
-
const parts = job.params
|
|
301
|
+
const parts = job.params
|
|
302
|
+
.filter((p) => typeof args[p.name] === "string" && args[p.name])
|
|
303
|
+
.map((p) => (p.prefix ?? "") + args[p.name]);
|
|
264
304
|
return [`/multi-agent:${job.command}`, ...parts].join(" ");
|
|
265
305
|
}
|
|
266
306
|
|
|
@@ -429,8 +469,9 @@ export function reapEndedJobs({ env = process.env, sessions, now = Date.now() })
|
|
|
429
469
|
* confirmation shows.
|
|
430
470
|
*/
|
|
431
471
|
export function previewJob({ jobId, args = {}, answers, repoPath, knownRun, sessions }) {
|
|
432
|
-
const
|
|
433
|
-
if (!
|
|
472
|
+
const listed = jobById(jobId);
|
|
473
|
+
if (!listed) throw new JobError("unknown-job", "no such job");
|
|
474
|
+
const job = jobWithChoices(listed);
|
|
434
475
|
const doc = jobsDocument().jobs.find((j) => j.id === jobId);
|
|
435
476
|
if (!doc.available) throw new JobError("command-not-installed", "that command is not installed");
|
|
436
477
|
if (!isAbsolute(repoPath ?? ""))
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* @file office-disk.mjs - the disk section of the office's cleanup window.
|
|
4
|
+
*
|
|
5
|
+
* A thin wrapper over disk-cleaner.mjs, the script /multi-agent:clean-disk
|
|
6
|
+
* runs, behind POST /v1/disk-clean:
|
|
7
|
+
*
|
|
8
|
+
* {} measure: the cleaner's dry run with both
|
|
9
|
+
* opt-ins, so the Trash and old transcripts are
|
|
10
|
+
* sized too; no token
|
|
11
|
+
* {categories, trash?, transcripts?}
|
|
12
|
+
* preview: the dry run of exactly the ticked
|
|
13
|
+
* categories, and a token bound to that list
|
|
14
|
+
* {confirmToken} apply: the cleaner's --apply of the categories
|
|
15
|
+
* the token was minted for, nothing else
|
|
16
|
+
*
|
|
17
|
+
* Every category is checked against the cleaner's own allow-list
|
|
18
|
+
* (CATEGORIES); nothing else from the request reaches its command line. The
|
|
19
|
+
* Trash and transcripts are opt-in twice: their id in `categories` and their
|
|
20
|
+
* own `trash: true` / `transcripts: true`. A server started unattended
|
|
21
|
+
* (MULTI_AGENT_UNATTENDED=1) measures the cleaner's unattended set and refuses
|
|
22
|
+
* a preview and an apply, since nobody is there to confirm. The cleaner itself
|
|
23
|
+
* guards every path again right before it deletes it.
|
|
24
|
+
*
|
|
25
|
+
* The document carries each category's size, item count, largest items (real
|
|
26
|
+
* paths), the reasons items were kept, the reclaimable total and the free
|
|
27
|
+
* space expected afterwards; never the full candidate list.
|
|
28
|
+
*
|
|
29
|
+
* Usage:
|
|
30
|
+
* office-disk.mjs measure [--json]
|
|
31
|
+
*
|
|
32
|
+
* Exit: 0 printed, 1 the cleaner failed, 2 usage.
|
|
33
|
+
*
|
|
34
|
+
* @module pipeline/scripts/office-disk
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
import { dirname, join } from "node:path";
|
|
38
|
+
import { fileURLToPath } from "node:url";
|
|
39
|
+
|
|
40
|
+
import { ArgsError, parseArgs } from "../lib/args.mjs";
|
|
41
|
+
import { exitOnHelp } from "../lib/cli-help.mjs";
|
|
42
|
+
import { runMain } from "../lib/fatal.mjs";
|
|
43
|
+
import { invokedDirectly } from "../lib/invoked-directly.mjs";
|
|
44
|
+
import { isUnattended } from "../lib/unattended.mjs";
|
|
45
|
+
import { CATEGORIES } from "./disk-cleaner.mjs";
|
|
46
|
+
import { spawnAsync } from "./_spawn-async.mjs";
|
|
47
|
+
import { HttpError, isToken, mintConfirm, redeemConfirm, requireBody } from "./_contract-core.mjs";
|
|
48
|
+
|
|
49
|
+
exitOnHelp(import.meta.url);
|
|
50
|
+
|
|
51
|
+
export const CONTRACT_VERSION = "1.0.0";
|
|
52
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
53
|
+
const TOP = 5;
|
|
54
|
+
const MAX_FAILURES = 20;
|
|
55
|
+
const CLEANER_TIMEOUT_MS = 600_000;
|
|
56
|
+
|
|
57
|
+
export const CATEGORY_IDS = CATEGORIES.map((c) => c.id);
|
|
58
|
+
const BY_ID = new Map(CATEGORIES.map((c) => [c.id, c]));
|
|
59
|
+
/** Each opt-in category with the request flag it needs: {trash: "trash", ...}. */
|
|
60
|
+
export const OPT_INS = Object.fromEntries(
|
|
61
|
+
CATEGORIES.filter((c) => c.optIn).map((c) => [c.id, c.optIn]),
|
|
62
|
+
);
|
|
63
|
+
const OPT_IN_FLAGS = [...new Set(Object.values(OPT_INS))];
|
|
64
|
+
|
|
65
|
+
const isCategoryList = (v) =>
|
|
66
|
+
Array.isArray(v) &&
|
|
67
|
+
v.length > 0 &&
|
|
68
|
+
v.every((id) => typeof id === "string" && BY_ID.has(id)) &&
|
|
69
|
+
new Set(v).size === v.length;
|
|
70
|
+
|
|
71
|
+
/** The cleaner run the default route uses: node disk-cleaner.mjs <args>. */
|
|
72
|
+
export function spawnCleaner(args, env = process.env) {
|
|
73
|
+
return spawnAsync(process.execPath, [join(HERE, "disk-cleaner.mjs"), ...args], {
|
|
74
|
+
env,
|
|
75
|
+
timeoutMs: CLEANER_TIMEOUT_MS,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const inCatalogOrder = (ids) => CATEGORY_IDS.filter((id) => ids.includes(id));
|
|
80
|
+
const optInFlagsFor = (ids) =>
|
|
81
|
+
OPT_IN_FLAGS.filter((f) => ids.some((id) => OPT_INS[id] === f)).map((f) => `--${f}`);
|
|
82
|
+
|
|
83
|
+
async function cleaner(runCleaner, args, env) {
|
|
84
|
+
const r = await runCleaner(["--json", `--top=${TOP}`, ...args], env);
|
|
85
|
+
// Exit 1 is an apply with failed deletions; the report still comes back.
|
|
86
|
+
if (r.status === 0 || (r.status === 1 && args.includes("--apply"))) {
|
|
87
|
+
try {
|
|
88
|
+
return JSON.parse(r.stdout);
|
|
89
|
+
} catch {
|
|
90
|
+
// Falls through to the refusal below.
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
throw new HttpError(502, "upstream-failed", "the disk cleaner did not finish");
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The cleaner's report as the office reads it. */
|
|
97
|
+
export function summarize(report, mode) {
|
|
98
|
+
const before = report.disk?.before ?? {};
|
|
99
|
+
const doc = {
|
|
100
|
+
contractVersion: CONTRACT_VERSION,
|
|
101
|
+
mode,
|
|
102
|
+
unattended: report.unattended === true,
|
|
103
|
+
disk: {
|
|
104
|
+
freeBytes: before.freeBytes ?? null,
|
|
105
|
+
totalBytes: before.totalBytes ?? null,
|
|
106
|
+
expectedFreeBytes: report.disk?.expectedFreeBytes ?? null,
|
|
107
|
+
...(report.disk?.after ? { afterFreeBytes: report.disk.after.freeBytes ?? null } : {}),
|
|
108
|
+
},
|
|
109
|
+
reclaimableBytes: report.reclaimableBytes ?? 0,
|
|
110
|
+
categories: (report.categories ?? [])
|
|
111
|
+
.filter((c) => BY_ID.has(c.id))
|
|
112
|
+
.map((c) => {
|
|
113
|
+
const def = BY_ID.get(c.id);
|
|
114
|
+
return {
|
|
115
|
+
id: c.id,
|
|
116
|
+
label: def.label,
|
|
117
|
+
items: Array.isArray(c.candidates) ? c.candidates.length : 0,
|
|
118
|
+
bytes: c.bytes ?? 0,
|
|
119
|
+
top: (c.top ?? []).map((x) => ({ path: String(x.path ?? x.kind), bytes: x.bytes ?? 0 })),
|
|
120
|
+
more: c.more ?? 0,
|
|
121
|
+
kept: c.kept ?? {},
|
|
122
|
+
blocked: c.blocked || null,
|
|
123
|
+
note: c.note || null,
|
|
124
|
+
safe: def.unattended === true,
|
|
125
|
+
optIn: def.optIn ?? null,
|
|
126
|
+
};
|
|
127
|
+
}),
|
|
128
|
+
orphans: Array.isArray(report.orphans) ? report.orphans.length : 0,
|
|
129
|
+
};
|
|
130
|
+
if (report.applied) {
|
|
131
|
+
const a = report.applied;
|
|
132
|
+
doc.applied = {
|
|
133
|
+
removed: a.removed ?? 0,
|
|
134
|
+
failed: a.failed ?? 0,
|
|
135
|
+
freedBytes: a.freedBytes ?? null,
|
|
136
|
+
failures: (a.failures ?? []).slice(0, MAX_FAILURES).map((f) => ({
|
|
137
|
+
category: f.category,
|
|
138
|
+
path: String(f.path ?? ""),
|
|
139
|
+
reason: String(f.reason ?? ""),
|
|
140
|
+
})),
|
|
141
|
+
held: (a.held ?? []).map((h) => ({ category: h.category, reason: String(h.reason ?? "") })),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
return doc;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** The opt-in rule: an opt-in id and its own flag come together or not at all. */
|
|
148
|
+
function optInErrors(ids, body) {
|
|
149
|
+
const errors = [];
|
|
150
|
+
for (const [id, flag] of Object.entries(OPT_INS)) {
|
|
151
|
+
if (ids.includes(id) && body[flag] !== true)
|
|
152
|
+
errors.push(`${id} needs its own flag: ${flag}: true`);
|
|
153
|
+
}
|
|
154
|
+
for (const flag of OPT_IN_FLAGS) {
|
|
155
|
+
const ids_ = Object.keys(OPT_INS).filter((id) => OPT_INS[id] === flag);
|
|
156
|
+
if (body[flag] === true && !ids_.some((id) => ids.includes(id)))
|
|
157
|
+
errors.push(`${flag}: true without the ${ids_.join(", ")} category`);
|
|
158
|
+
}
|
|
159
|
+
return errors;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const refusedUnattended = () =>
|
|
163
|
+
new HttpError(
|
|
164
|
+
409,
|
|
165
|
+
"unattended-refused",
|
|
166
|
+
"an unattended server measures only; nobody can confirm",
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* POST /v1/disk-clean. `runCleaner` and `env` are for tests; the server passes
|
|
171
|
+
* neither.
|
|
172
|
+
*/
|
|
173
|
+
export async function diskCleanRoute(
|
|
174
|
+
{ body },
|
|
175
|
+
{ env = process.env, runCleaner = spawnCleaner } = {},
|
|
176
|
+
) {
|
|
177
|
+
requireBody(
|
|
178
|
+
body,
|
|
179
|
+
{
|
|
180
|
+
confirmToken: isToken,
|
|
181
|
+
categories: isCategoryList,
|
|
182
|
+
...Object.fromEntries(OPT_IN_FLAGS.map((f) => [f, (v) => v === true])),
|
|
183
|
+
},
|
|
184
|
+
"disk-clean-request.schema.json",
|
|
185
|
+
);
|
|
186
|
+
const unattended = isUnattended(env);
|
|
187
|
+
if (body.confirmToken !== undefined) {
|
|
188
|
+
if (body.categories !== undefined || OPT_IN_FLAGS.some((f) => body[f] !== undefined))
|
|
189
|
+
throw new HttpError(400, "invalid-body", "the confirmation carries only its token");
|
|
190
|
+
if (unattended) throw refusedUnattended();
|
|
191
|
+
const { categories } = redeemConfirm(body.confirmToken, "disk-clean", "");
|
|
192
|
+
const report = await cleaner(
|
|
193
|
+
runCleaner,
|
|
194
|
+
["--apply", `--only=${categories.join(",")}`, ...optInFlagsFor(categories)],
|
|
195
|
+
env,
|
|
196
|
+
);
|
|
197
|
+
return summarize(report, "applied");
|
|
198
|
+
}
|
|
199
|
+
if (body.categories === undefined) {
|
|
200
|
+
if (OPT_IN_FLAGS.some((f) => body[f] !== undefined))
|
|
201
|
+
throw new HttpError(
|
|
202
|
+
400,
|
|
203
|
+
"invalid-body",
|
|
204
|
+
"an opt-in flag belongs to a preview with its category",
|
|
205
|
+
);
|
|
206
|
+
const report = await cleaner(
|
|
207
|
+
runCleaner,
|
|
208
|
+
["--dry-run", ...(unattended ? ["--unattended"] : OPT_IN_FLAGS.map((f) => `--${f}`))],
|
|
209
|
+
env,
|
|
210
|
+
);
|
|
211
|
+
return summarize(report, "measure");
|
|
212
|
+
}
|
|
213
|
+
const errors = optInErrors(body.categories, body);
|
|
214
|
+
if (errors.length) throw new HttpError(400, "invalid-body", errors.join("; "), { errors });
|
|
215
|
+
if (unattended) throw refusedUnattended();
|
|
216
|
+
const categories = inCatalogOrder(body.categories);
|
|
217
|
+
const report = await cleaner(
|
|
218
|
+
runCleaner,
|
|
219
|
+
["--dry-run", `--only=${categories.join(",")}`, ...optInFlagsFor(categories)],
|
|
220
|
+
env,
|
|
221
|
+
);
|
|
222
|
+
return { ...summarize(report, "preview"), ...mintConfirm("disk-clean", "", { categories }) };
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function main(argv) {
|
|
226
|
+
let parsed;
|
|
227
|
+
try {
|
|
228
|
+
parsed = parseArgs(argv, { booleans: ["json"], unknown: "error" });
|
|
229
|
+
} catch (err) {
|
|
230
|
+
if (!(err instanceof ArgsError)) throw err;
|
|
231
|
+
process.stderr.write(
|
|
232
|
+
`office-disk: unknown argument ${err.token}\nusage: office-disk.mjs measure [--json]\n`,
|
|
233
|
+
);
|
|
234
|
+
return Promise.resolve(2);
|
|
235
|
+
}
|
|
236
|
+
if (parsed.positionals.length !== 1 || parsed.positionals[0] !== "measure") {
|
|
237
|
+
process.stderr.write("usage: office-disk.mjs measure [--json]\n");
|
|
238
|
+
return Promise.resolve(2);
|
|
239
|
+
}
|
|
240
|
+
return diskCleanRoute({ body: { contractVersion: "1.0.0" } }).then(
|
|
241
|
+
(doc) => {
|
|
242
|
+
if (parsed.flags.json) process.stdout.write(JSON.stringify(doc, null, 2) + "\n");
|
|
243
|
+
else {
|
|
244
|
+
for (const c of doc.categories)
|
|
245
|
+
process.stdout.write(`${c.id.padEnd(18)} ${String(c.items).padStart(6)} ${c.bytes}\n`);
|
|
246
|
+
process.stdout.write(`reclaimable ${doc.reclaimableBytes}\n`);
|
|
247
|
+
}
|
|
248
|
+
return 0;
|
|
249
|
+
},
|
|
250
|
+
(err) => {
|
|
251
|
+
if (!(err instanceof HttpError)) throw err;
|
|
252
|
+
process.stderr.write(`office-disk: ${err.message}\n`);
|
|
253
|
+
return 1;
|
|
254
|
+
},
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (invokedDirectly(import.meta.url)) {
|
|
259
|
+
runMain("office-disk", async () => {
|
|
260
|
+
process.exitCode = await main(process.argv.slice(2));
|
|
261
|
+
});
|
|
262
|
+
}
|