@thaodangspace/argos 0.1.1 → 0.1.3
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/README.md +4 -4
- package/dist/args.d.ts.map +1 -1
- package/dist/args.js +5 -1
- package/dist/args.js.map +1 -1
- package/dist/commands/chart.d.ts +21 -0
- package/dist/commands/chart.d.ts.map +1 -0
- package/dist/commands/chart.js +209 -0
- package/dist/commands/chart.js.map +1 -0
- package/dist/commands/doctor.d.ts +18 -1
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +123 -4
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/hc.d.ts +16 -0
- package/dist/commands/hc.d.ts.map +1 -0
- package/dist/commands/hc.js +689 -0
- package/dist/commands/hc.js.map +1 -0
- package/dist/commands/serve.d.ts +23 -2
- package/dist/commands/serve.d.ts.map +1 -1
- package/dist/commands/serve.js +72 -14
- package/dist/commands/serve.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +6 -0
- package/dist/main.js.map +1 -1
- package/dist/output.d.ts +1 -1
- package/dist/output.d.ts.map +1 -1
- package/dist/output.js +6 -0
- package/dist/output.js.map +1 -1
- package/dist/packs/apply.d.ts +36 -0
- package/dist/packs/apply.d.ts.map +1 -0
- package/dist/packs/apply.js +103 -0
- package/dist/packs/apply.js.map +1 -0
- package/dist/packs/bundled.d.ts +27 -0
- package/dist/packs/bundled.d.ts.map +1 -0
- package/dist/packs/bundled.js +42 -0
- package/dist/packs/bundled.js.map +1 -0
- package/dist/packs/pack.d.ts +142 -0
- package/dist/packs/pack.d.ts.map +1 -0
- package/dist/packs/pack.js +204 -0
- package/dist/packs/pack.js.map +1 -0
- package/dist/packs/plan.d.ts +123 -0
- package/dist/packs/plan.d.ts.map +1 -0
- package/dist/packs/plan.js +307 -0
- package/dist/packs/plan.js.map +1 -0
- package/dist/packs/templates-dir.d.ts +29 -0
- package/dist/packs/templates-dir.d.ts.map +1 -0
- package/dist/packs/templates-dir.js +49 -0
- package/dist/packs/templates-dir.js.map +1 -0
- package/package.json +4 -2
- package/templates/packs/claude/claude-step.mjs +666 -0
- package/templates/packs/claude/pack.json +38 -0
- package/templates/packs/smoke/pack.json +20 -0
- package/templates/packs/smoke/smoke.mjs +104 -0
- package/ui/_app/immutable/assets/0.CTk3h7Zx.css +2 -0
- package/ui/_app/immutable/chunks/9Dk6YhUf.js +1 -0
- package/ui/_app/immutable/chunks/BDgjZRhb.js +1 -0
- package/ui/_app/immutable/chunks/BQUxoyXx.js +1 -0
- package/ui/_app/immutable/chunks/BVvEKWUw.js +1 -0
- package/ui/_app/immutable/chunks/BXIfM5K1.js +1 -0
- package/ui/_app/immutable/chunks/B_XCALJf.js +1 -0
- package/ui/_app/immutable/chunks/BiQUXUyr.js +1 -0
- package/ui/_app/immutable/chunks/CPty2F6V.js +2 -0
- package/ui/_app/immutable/chunks/CqLqOuLw.js +4 -0
- package/ui/_app/immutable/chunks/Cta5wR5U.js +1 -0
- package/ui/_app/immutable/chunks/DlHMls5I.js +1 -0
- package/ui/_app/immutable/chunks/DqmgjiJ7.js +3 -0
- package/ui/_app/immutable/chunks/{D8sQwgC_.js → DxP_sZrQ.js} +1 -1
- package/ui/_app/immutable/chunks/PR6kdzSw.js +1 -0
- package/ui/_app/immutable/entry/app.DefioTIJ.js +2 -0
- package/ui/_app/immutable/entry/start.D3LG_apg.js +2 -0
- package/ui/_app/immutable/nodes/0.Bxn1Q-bg.js +1 -0
- package/ui/_app/immutable/nodes/1.DVMonhb0.js +1 -0
- package/ui/_app/immutable/nodes/2.DiUZ9i2y.js +2 -0
- package/ui/_app/immutable/nodes/3.C6GP2DYu.js +1 -0
- package/ui/_app/immutable/nodes/4._uRXFvRQ.js +3 -0
- package/ui/_app/immutable/nodes/5.BwtM7IQO.js +1 -0
- package/ui/_app/version.json +1 -1
- package/ui/build.json +3 -3
- package/ui/index.html +22 -18
- package/ui/_app/immutable/assets/0.Y-Ej83kR.css +0 -1
- package/ui/_app/immutable/assets/2.D2FEqQBh.css +0 -1
- package/ui/_app/immutable/assets/3.CI7aeD9i.css +0 -1
- package/ui/_app/immutable/assets/StartRunDialog.BbbZvJfB.css +0 -1
- package/ui/_app/immutable/assets/runs.CU5wtnW2.css +0 -1
- package/ui/_app/immutable/chunks/BKHbyffl.js +0 -3
- package/ui/_app/immutable/chunks/BeG5AxKI.js +0 -3
- package/ui/_app/immutable/chunks/Buwi_lQz.js +0 -2
- package/ui/_app/immutable/chunks/CV2Ptlrp.js +0 -1
- package/ui/_app/immutable/chunks/CtbaNJav.js +0 -1
- package/ui/_app/immutable/entry/app.DPg5reEl.js +0 -2
- package/ui/_app/immutable/entry/start.iWBP-EvH.js +0 -2
- package/ui/_app/immutable/nodes/0.Cu8SyVzm.js +0 -1
- package/ui/_app/immutable/nodes/1.Bga_qdeZ.js +0 -1
- package/ui/_app/immutable/nodes/2.CKNrkmzJ.js +0 -1
- package/ui/_app/immutable/nodes/3.OrFQ8OoI.js +0 -1
|
@@ -0,0 +1,689 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `argos hc templates list|install|uninstall|verify` (spec FR10–FR14, FR15; plan Phases 2–3).
|
|
3
|
+
*
|
|
4
|
+
* Templates are **machine-level** assets: `hc` reads a directory, so an Argos install puts files
|
|
5
|
+
* there once instead of every repository vendoring a script. Nothing on this path talks to `hc`,
|
|
6
|
+
* opens a socket, reads SQLite, or spawns a process — `node:fs` plus HTTP to `argos serve` for the
|
|
7
|
+
* one question that is about the running server (`verify`), and Argos' own manifest at
|
|
8
|
+
* `$ARGOS_HOME/hc/packs.json`.
|
|
9
|
+
*
|
|
10
|
+
* The command is deliberately a thin shell around the pure planner: `--dry-run` prints the plan that
|
|
11
|
+
* the real run applies, so the two cannot disagree.
|
|
12
|
+
*/
|
|
13
|
+
import { createHash } from "node:crypto";
|
|
14
|
+
import { existsSync, lstatSync, readFileSync, readdirSync, readlinkSync, statSync, } from "node:fs";
|
|
15
|
+
import { basename, join, resolve } from "node:path";
|
|
16
|
+
import { RpcClient } from "@thaodangspace/argos-core/rpc";
|
|
17
|
+
import { flag, hasFlag, rejectUnknownFlags } from "../args.js";
|
|
18
|
+
import { EXIT_OK, EXIT_RUNTIME, EXIT_UNREACHABLE, EXIT_VALIDATION, printJson, printJsonError, } from "../output.js";
|
|
19
|
+
import { PackApplyError, applyInstall, applyUninstall } from "../packs/apply.js";
|
|
20
|
+
import { PackAssetsError, bundledPacks } from "../packs/bundled.js";
|
|
21
|
+
import { emptyManifest, parseManifest, parsePack, parseTemplate, } from "../packs/pack.js";
|
|
22
|
+
import { planInstall, planUninstall, } from "../packs/plan.js";
|
|
23
|
+
import { argosStateDir, manifestPath, packInstallDir, packsRoot, templatesDir, } from "../packs/templates-dir.js";
|
|
24
|
+
/** Read a file's text, or `undefined` when it is missing or unreadable (never throws). */
|
|
25
|
+
function readIfPresent(path) {
|
|
26
|
+
try {
|
|
27
|
+
return readFileSync(path, "utf8");
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The one projection behind `list --json` and the `packs` key of `install --json`/`uninstall
|
|
35
|
+
* --json`. `pending` is what the plan is about to write, so a `--dry-run` reports `present: true`
|
|
36
|
+
* for the files it would create instead of pretending nothing happened.
|
|
37
|
+
*/
|
|
38
|
+
function describePacks(manifest, dir, pending) {
|
|
39
|
+
const packs = Object.keys(manifest.packs)
|
|
40
|
+
.sort()
|
|
41
|
+
.map((name) => {
|
|
42
|
+
const entry = manifest.packs[name];
|
|
43
|
+
if (entry === undefined)
|
|
44
|
+
throw new Error(`manifest lost pack ${name}`);
|
|
45
|
+
const templates = Object.keys(entry.templates)
|
|
46
|
+
.sort()
|
|
47
|
+
.map((templateName) => {
|
|
48
|
+
const template = entry.templates[templateName];
|
|
49
|
+
if (template === undefined)
|
|
50
|
+
throw new Error(`manifest lost template ${templateName}`);
|
|
51
|
+
const content = pending?.get(template.file) ?? readIfPresent(template.file);
|
|
52
|
+
return {
|
|
53
|
+
name: templateName,
|
|
54
|
+
file: template.file,
|
|
55
|
+
command: content === undefined ? null : (parseTemplate(content).command ?? null),
|
|
56
|
+
minStepTimeoutMs: template.minStepTimeoutMs,
|
|
57
|
+
present: content !== undefined,
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
return {
|
|
61
|
+
name,
|
|
62
|
+
version: entry.version,
|
|
63
|
+
program: entry.program,
|
|
64
|
+
...(entry.programSha256 === undefined ? {} : { programSha256: entry.programSha256 }),
|
|
65
|
+
...(entry.link === undefined ? {} : { link: entry.link }),
|
|
66
|
+
templates,
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
return { dir, packs };
|
|
70
|
+
}
|
|
71
|
+
function pendingContents(writes) {
|
|
72
|
+
return new Map(writes.map((write) => [write.path, write.content]));
|
|
73
|
+
}
|
|
74
|
+
// ------------------------------------------------------------------ io helpers
|
|
75
|
+
function usage(io, message) {
|
|
76
|
+
io.stderr(`argos: ${message}\n`);
|
|
77
|
+
return EXIT_RUNTIME;
|
|
78
|
+
}
|
|
79
|
+
/** A validation refusal: exit 2, naming the code and the path or field (FR14). */
|
|
80
|
+
function refuse(io, json, refusals) {
|
|
81
|
+
if (json) {
|
|
82
|
+
printJsonError(io, refusals[0]?.code ?? "invalid_request", refusals.map((refusal) => refusal.message).join("; "));
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
for (const refusal of refusals)
|
|
86
|
+
io.stderr(`argos: ${refusal.code}: ${refusal.message}\n`);
|
|
87
|
+
}
|
|
88
|
+
return EXIT_VALIDATION;
|
|
89
|
+
}
|
|
90
|
+
function failure(io, json, error) {
|
|
91
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
92
|
+
if (json)
|
|
93
|
+
printJsonError(io, "internal_error", message);
|
|
94
|
+
else
|
|
95
|
+
io.stderr(`argos: ${message}\n`);
|
|
96
|
+
return EXIT_RUNTIME;
|
|
97
|
+
}
|
|
98
|
+
const NEXT_STEPS = [
|
|
99
|
+
"argos hc templates: run `hc templates` to confirm",
|
|
100
|
+
"argos hc templates: restart `argos serve` if it was already running",
|
|
101
|
+
];
|
|
102
|
+
/** The manifest is a claim about disk, so an unreadable one is refused, never rewritten blind. */
|
|
103
|
+
function readManifestDocument(home) {
|
|
104
|
+
const file = manifestPath(home);
|
|
105
|
+
const text = readIfPresent(file);
|
|
106
|
+
if (text === undefined) {
|
|
107
|
+
// Missing is fine (nothing installed); present-but-unreadable is not, and neither is a
|
|
108
|
+
// hand-edited document: rewriting it blind would silently drop another pack's entry.
|
|
109
|
+
if (existsSync(file)) {
|
|
110
|
+
return {
|
|
111
|
+
ok: false,
|
|
112
|
+
refusals: [{ code: "manifest_invalid", message: `${file}: not readable` }],
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
return { ok: true, manifest: emptyManifest() };
|
|
116
|
+
}
|
|
117
|
+
const parsed = parseManifest(text, file);
|
|
118
|
+
if (parsed.ok)
|
|
119
|
+
return { ok: true, manifest: parsed.value };
|
|
120
|
+
return {
|
|
121
|
+
ok: false,
|
|
122
|
+
refusals: parsed.issues.map((issue) => ({
|
|
123
|
+
code: "manifest_invalid",
|
|
124
|
+
message: `${issue.path}: ${issue.message}`,
|
|
125
|
+
})),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/** Every `.md` in the templates directory, content included: the plan needs bytes, not names. */
|
|
129
|
+
function readTemplates(dir) {
|
|
130
|
+
let entries;
|
|
131
|
+
try {
|
|
132
|
+
entries = readdirSync(dir);
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
return [];
|
|
136
|
+
}
|
|
137
|
+
const templates = [];
|
|
138
|
+
for (const entry of entries.sort()) {
|
|
139
|
+
if (!entry.endsWith(".md"))
|
|
140
|
+
continue;
|
|
141
|
+
const path = join(dir, entry);
|
|
142
|
+
try {
|
|
143
|
+
templates.push({ name: entry.slice(0, -".md".length), content: readFileSync(path, "utf8") });
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
// An unreadable file is not ours to reason about; treat it as absent.
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return templates;
|
|
150
|
+
}
|
|
151
|
+
function sha256(text) {
|
|
152
|
+
return createHash("sha256").update(text).digest("hex");
|
|
153
|
+
}
|
|
154
|
+
/** What is already installed at a program path (a copy's hash, or a symlink's target). */
|
|
155
|
+
function installedProgram(path) {
|
|
156
|
+
const stat = lstatSync(path, { throwIfNoEntry: false });
|
|
157
|
+
if (stat === undefined)
|
|
158
|
+
return undefined;
|
|
159
|
+
if (stat.isSymbolicLink())
|
|
160
|
+
return { linkTarget: readlinkSync(path) };
|
|
161
|
+
try {
|
|
162
|
+
return { sha256: sha256(readFileSync(path, "utf8")) };
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/** `<name>@<version>` directories that exist under `$ARGOS_HOME/hc/packs`. */
|
|
169
|
+
function existingPackDirs(home) {
|
|
170
|
+
try {
|
|
171
|
+
return readdirSync(packsRoot(home))
|
|
172
|
+
.filter((entry) => lstatSync(join(packsRoot(home), entry), { throwIfNoEntry: false })?.isDirectory() === true)
|
|
173
|
+
.sort();
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
return [];
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/** A `--from` directory: one pack (`pack.json` inside), or a directory of packs. */
|
|
180
|
+
function packDirsIn(root) {
|
|
181
|
+
if (existsSync(join(root, "pack.json")))
|
|
182
|
+
return [root];
|
|
183
|
+
let entries;
|
|
184
|
+
try {
|
|
185
|
+
entries = readdirSync(root);
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
return [];
|
|
189
|
+
}
|
|
190
|
+
return entries
|
|
191
|
+
.sort()
|
|
192
|
+
.map((entry) => join(root, entry))
|
|
193
|
+
.filter((dir) => existsSync(join(dir, "pack.json")));
|
|
194
|
+
}
|
|
195
|
+
function declaredName(dir) {
|
|
196
|
+
try {
|
|
197
|
+
const raw = JSON.parse(readFileSync(join(dir, "pack.json"), "utf8"));
|
|
198
|
+
const name = raw.name;
|
|
199
|
+
return typeof name === "string" ? name : undefined;
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
// ------------------------------------------------------------------ list
|
|
206
|
+
async function listCommand(args, io) {
|
|
207
|
+
const unknown = rejectUnknownFlags(args, ["dir"]);
|
|
208
|
+
if (unknown !== undefined)
|
|
209
|
+
return usage(io, unknown);
|
|
210
|
+
if (args.positionals.length > 2)
|
|
211
|
+
return usage(io, "hc templates list takes no arguments");
|
|
212
|
+
const dir = templatesDir(flag(args, "dir"));
|
|
213
|
+
const read = readManifestDocument(argosStateDir());
|
|
214
|
+
if (!read.ok)
|
|
215
|
+
return refuse(io, args.json, read.refusals);
|
|
216
|
+
const view = describePacks(read.manifest, dir);
|
|
217
|
+
if (args.json) {
|
|
218
|
+
printJson(io, view);
|
|
219
|
+
return EXIT_OK;
|
|
220
|
+
}
|
|
221
|
+
io.stdout(`${humanList(view)}\n`);
|
|
222
|
+
return EXIT_OK;
|
|
223
|
+
}
|
|
224
|
+
function humanList(view) {
|
|
225
|
+
const lines = [`argos hc templates: ${view.dir}`];
|
|
226
|
+
if (view.packs.length === 0) {
|
|
227
|
+
lines.push(" no packs installed; run `argos hc templates install`");
|
|
228
|
+
return lines.join("\n");
|
|
229
|
+
}
|
|
230
|
+
for (const pack of view.packs) {
|
|
231
|
+
lines.push(` ${pack.name} ${pack.version}`);
|
|
232
|
+
lines.push(` program ${pack.program}`);
|
|
233
|
+
for (const template of pack.templates) {
|
|
234
|
+
lines.push(` ${template.name} ${template.minStepTimeoutMs} ms ${template.present ? "present" : "missing"}`);
|
|
235
|
+
lines.push(` ${template.file}`);
|
|
236
|
+
if (template.command !== null)
|
|
237
|
+
lines.push(` ${template.command}`);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return lines.join("\n");
|
|
241
|
+
}
|
|
242
|
+
// ------------------------------------------------------------------ install
|
|
243
|
+
async function installCommand(args, io) {
|
|
244
|
+
const unknown = rejectUnknownFlags(args, ["dir", "from", "link", "force", "dry-run"]);
|
|
245
|
+
if (unknown !== undefined)
|
|
246
|
+
return usage(io, unknown);
|
|
247
|
+
const names = args.positionals.slice(2);
|
|
248
|
+
const dir = templatesDir(flag(args, "dir"));
|
|
249
|
+
const home = argosStateDir();
|
|
250
|
+
const link = hasFlag(args, "link");
|
|
251
|
+
const force = hasFlag(args, "force");
|
|
252
|
+
const dryRun = hasFlag(args, "dry-run");
|
|
253
|
+
const refusals = [];
|
|
254
|
+
let root;
|
|
255
|
+
let source;
|
|
256
|
+
let available;
|
|
257
|
+
try {
|
|
258
|
+
const from = flag(args, "from");
|
|
259
|
+
if (from === undefined) {
|
|
260
|
+
const bundled = bundledPacks();
|
|
261
|
+
root = bundled.dir;
|
|
262
|
+
source = "bundled";
|
|
263
|
+
available = bundled.names.map((name) => join(bundled.dir, name));
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
root = resolve(from);
|
|
267
|
+
source = root;
|
|
268
|
+
available = packDirsIn(root);
|
|
269
|
+
if (available.length === 0) {
|
|
270
|
+
refusals.push({ code: "pack_missing", message: `no pack found in ${root} (expected pack.json)` });
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
catch (error) {
|
|
275
|
+
if (error instanceof PackAssetsError)
|
|
276
|
+
return failure(io, args.json, error);
|
|
277
|
+
throw error;
|
|
278
|
+
}
|
|
279
|
+
const selected = [];
|
|
280
|
+
if (names.length === 0) {
|
|
281
|
+
selected.push(...available);
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
for (const name of names) {
|
|
285
|
+
const match = available.find((candidate) => basename(candidate) === name) ??
|
|
286
|
+
available.find((candidate) => declaredName(candidate) === name);
|
|
287
|
+
if (match === undefined) {
|
|
288
|
+
refusals.push({ code: "pack_unknown", message: `no pack "${name}" in ${root}` });
|
|
289
|
+
}
|
|
290
|
+
else if (!selected.includes(match)) {
|
|
291
|
+
selected.push(match);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
const packs = [];
|
|
296
|
+
for (const packDir of selected) {
|
|
297
|
+
const file = join(packDir, "pack.json");
|
|
298
|
+
const text = readIfPresent(file);
|
|
299
|
+
if (text === undefined) {
|
|
300
|
+
refusals.push({ code: "pack_invalid", message: `${file}: not readable` });
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
const parsed = parsePack(text, file);
|
|
304
|
+
if (!parsed.ok) {
|
|
305
|
+
for (const issue of parsed.issues) {
|
|
306
|
+
refusals.push({ code: "pack_invalid", message: `${issue.path}: ${issue.message}` });
|
|
307
|
+
}
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
const pack = parsed.value;
|
|
311
|
+
const programPath = resolve(packDir, pack.program.file);
|
|
312
|
+
let programContent;
|
|
313
|
+
if (!link) {
|
|
314
|
+
try {
|
|
315
|
+
programContent = readFileSync(programPath, "utf8");
|
|
316
|
+
}
|
|
317
|
+
catch {
|
|
318
|
+
refusals.push({
|
|
319
|
+
code: "program_missing",
|
|
320
|
+
message: `${file}: program "${pack.program.file}" is missing or unreadable`,
|
|
321
|
+
});
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
const destination = join(packInstallDir(home, pack.name, pack.version), pack.program.file);
|
|
326
|
+
const installed = installedProgram(destination);
|
|
327
|
+
packs.push({
|
|
328
|
+
pack,
|
|
329
|
+
file,
|
|
330
|
+
dir: packDir,
|
|
331
|
+
source,
|
|
332
|
+
...(programContent === undefined ? {} : { programContent }),
|
|
333
|
+
...(installed === undefined ? {} : { installedProgram: installed }),
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
const read = readManifestDocument(home);
|
|
337
|
+
if (!read.ok)
|
|
338
|
+
return refuse(io, args.json, [...refusals, ...read.refusals]);
|
|
339
|
+
if (refusals.length > 0)
|
|
340
|
+
return refuse(io, args.json, refusals);
|
|
341
|
+
const plan = planInstall({
|
|
342
|
+
packs,
|
|
343
|
+
templates: readTemplates(dir),
|
|
344
|
+
manifest: read.manifest,
|
|
345
|
+
templatesDir: dir,
|
|
346
|
+
home,
|
|
347
|
+
nodeVersion: process.versions.node,
|
|
348
|
+
nodePath: process.execPath,
|
|
349
|
+
link,
|
|
350
|
+
force,
|
|
351
|
+
});
|
|
352
|
+
if (plan.refusals.length > 0)
|
|
353
|
+
return refuse(io, args.json, plan.refusals);
|
|
354
|
+
const view = describePacks(plan.manifest, dir, pendingContents(plan.writes));
|
|
355
|
+
if (!dryRun) {
|
|
356
|
+
try {
|
|
357
|
+
applyInstall(plan, { home, templatesDir: dir });
|
|
358
|
+
}
|
|
359
|
+
catch (error) {
|
|
360
|
+
if (error instanceof PackApplyError)
|
|
361
|
+
return failure(io, args.json, error);
|
|
362
|
+
throw error;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
if (args.json) {
|
|
366
|
+
printJson(io, {
|
|
367
|
+
...view,
|
|
368
|
+
manifest: manifestPath(home),
|
|
369
|
+
dryRun,
|
|
370
|
+
unchanged: plan.unchanged,
|
|
371
|
+
writes: plan.writes.map((write) => write.path),
|
|
372
|
+
links: plan.links.map((link) => ({ path: link.path, target: link.target })),
|
|
373
|
+
warnings: [...plan.warnings],
|
|
374
|
+
});
|
|
375
|
+
return EXIT_OK;
|
|
376
|
+
}
|
|
377
|
+
io.stdout(`${humanInstall(plan, { dir, home, dryRun, names: packs.map((pack) => pack.pack.name) })}\n${NEXT_STEPS.join("\n")}\n`);
|
|
378
|
+
return EXIT_OK;
|
|
379
|
+
}
|
|
380
|
+
function humanInstall(plan, context) {
|
|
381
|
+
const lines = [
|
|
382
|
+
`argos hc templates install${context.dryRun ? " (dry run)" : ""}: ${context.names.join(", ")}`,
|
|
383
|
+
` templates ${context.dir}`,
|
|
384
|
+
` manifest ${manifestPath(context.home)}`,
|
|
385
|
+
];
|
|
386
|
+
for (const write of plan.writes)
|
|
387
|
+
lines.push(` write ${write.path}`);
|
|
388
|
+
for (const link of plan.links)
|
|
389
|
+
lines.push(` link ${link.path} -> ${link.target}`);
|
|
390
|
+
if (plan.unchanged)
|
|
391
|
+
lines.push(" unchanged everything is already current");
|
|
392
|
+
for (const warning of plan.warnings)
|
|
393
|
+
lines.push(` warning ${warning}`);
|
|
394
|
+
return lines.join("\n");
|
|
395
|
+
}
|
|
396
|
+
// ------------------------------------------------------------------ uninstall
|
|
397
|
+
async function uninstallCommand(args, io) {
|
|
398
|
+
const unknown = rejectUnknownFlags(args, ["dir", "prune", "dry-run"]);
|
|
399
|
+
if (unknown !== undefined)
|
|
400
|
+
return usage(io, unknown);
|
|
401
|
+
const names = args.positionals.slice(2);
|
|
402
|
+
if (names.length === 0) {
|
|
403
|
+
return usage(io, "hc templates uninstall needs at least one pack name");
|
|
404
|
+
}
|
|
405
|
+
const dir = templatesDir(flag(args, "dir"));
|
|
406
|
+
const home = argosStateDir();
|
|
407
|
+
const dryRun = hasFlag(args, "dry-run");
|
|
408
|
+
const prune = hasFlag(args, "prune");
|
|
409
|
+
const read = readManifestDocument(home);
|
|
410
|
+
if (!read.ok)
|
|
411
|
+
return refuse(io, args.json, read.refusals);
|
|
412
|
+
const plan = planUninstall({
|
|
413
|
+
packs: names,
|
|
414
|
+
templates: readTemplates(dir),
|
|
415
|
+
manifest: read.manifest,
|
|
416
|
+
templatesDir: dir,
|
|
417
|
+
home,
|
|
418
|
+
existingPackDirs: existingPackDirs(home),
|
|
419
|
+
prune,
|
|
420
|
+
});
|
|
421
|
+
if (plan.refusals.length > 0)
|
|
422
|
+
return refuse(io, args.json, plan.refusals);
|
|
423
|
+
const view = describePacks(plan.manifest, dir);
|
|
424
|
+
if (!dryRun) {
|
|
425
|
+
try {
|
|
426
|
+
applyUninstall(plan, { home, templatesDir: dir });
|
|
427
|
+
}
|
|
428
|
+
catch (error) {
|
|
429
|
+
if (error instanceof PackApplyError)
|
|
430
|
+
return failure(io, args.json, error);
|
|
431
|
+
throw error;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
if (args.json) {
|
|
435
|
+
printJson(io, {
|
|
436
|
+
...view,
|
|
437
|
+
manifest: manifestPath(home),
|
|
438
|
+
dryRun,
|
|
439
|
+
unchanged: plan.unchanged,
|
|
440
|
+
removed: plan.removes.map((remove) => remove.path),
|
|
441
|
+
kept: plan.keeps.map((keep) => ({ path: keep.path, reason: keep.reason })),
|
|
442
|
+
});
|
|
443
|
+
return EXIT_OK;
|
|
444
|
+
}
|
|
445
|
+
io.stdout(`${humanUninstall(plan, { dir, home, dryRun, names })}\n${NEXT_STEPS[1]}\n`);
|
|
446
|
+
return EXIT_OK;
|
|
447
|
+
}
|
|
448
|
+
function humanUninstall(plan, context) {
|
|
449
|
+
const lines = [
|
|
450
|
+
`argos hc templates uninstall${context.dryRun ? " (dry run)" : ""}: ${context.names.join(", ")}`,
|
|
451
|
+
` templates ${context.dir}`,
|
|
452
|
+
];
|
|
453
|
+
for (const remove of plan.removes)
|
|
454
|
+
lines.push(` remove ${remove.path}`);
|
|
455
|
+
for (const keep of plan.keeps)
|
|
456
|
+
lines.push(` keep ${keep.path} (${keep.reason})`);
|
|
457
|
+
if (plan.unchanged)
|
|
458
|
+
lines.push(" unchanged nothing to remove");
|
|
459
|
+
if (plan.manifestWrite !== undefined)
|
|
460
|
+
lines.push(` manifest ${plan.manifestWrite.path}`);
|
|
461
|
+
return lines.join("\n");
|
|
462
|
+
}
|
|
463
|
+
function errorText(error) {
|
|
464
|
+
return error instanceof Error ? error.message : String(error);
|
|
465
|
+
}
|
|
466
|
+
/** FR13's third question: is `argos serve` there, and what roster does it publish? */
|
|
467
|
+
async function probeServer(home) {
|
|
468
|
+
const client = new RpcClient({ home });
|
|
469
|
+
const url = client.baseUrl;
|
|
470
|
+
try {
|
|
471
|
+
await client.health();
|
|
472
|
+
}
|
|
473
|
+
catch (error) {
|
|
474
|
+
return { reachable: false, url, templates: null, note: undefined, error: errorText(error) };
|
|
475
|
+
}
|
|
476
|
+
try {
|
|
477
|
+
const info = await client.info();
|
|
478
|
+
const hc = info.executors?.find((executor) => executor.id === "hc");
|
|
479
|
+
if (hc === undefined) {
|
|
480
|
+
return {
|
|
481
|
+
reachable: true,
|
|
482
|
+
url,
|
|
483
|
+
templates: null,
|
|
484
|
+
note: "the running server does not register the hc executor; cannot tell whether it has seen them (restart `argos serve` with a reachable herdr-core)",
|
|
485
|
+
error: undefined,
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
if (hc.templates === undefined) {
|
|
489
|
+
return {
|
|
490
|
+
reachable: true,
|
|
491
|
+
url,
|
|
492
|
+
templates: null,
|
|
493
|
+
note: "the running server does not publish its hc templates; cannot tell whether it has seen them (restart `argos serve`)",
|
|
494
|
+
error: undefined,
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
return { reachable: true, url, templates: hc.templates, note: undefined, error: undefined };
|
|
498
|
+
}
|
|
499
|
+
catch (error) {
|
|
500
|
+
// `/health` answered, so the server is up; `/info` is what carries the roster.
|
|
501
|
+
return {
|
|
502
|
+
reachable: true,
|
|
503
|
+
url,
|
|
504
|
+
templates: null,
|
|
505
|
+
note: `the running server answered /health but not /info (${errorText(error)}); cannot tell`,
|
|
506
|
+
error: undefined,
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
/** A `hc/<template>` roster entry for one manifest template name (the canonical spelling). */
|
|
511
|
+
function inRoster(roster, name) {
|
|
512
|
+
return roster.includes(`hc/${name}`) || roster.includes(name);
|
|
513
|
+
}
|
|
514
|
+
/** FR13's first question, per pack: the program is one file shared by every template in it. */
|
|
515
|
+
function programFacts(entry) {
|
|
516
|
+
const messages = [];
|
|
517
|
+
const link = entry.link;
|
|
518
|
+
const installed = lstatSync(entry.program, { throwIfNoEntry: false });
|
|
519
|
+
if (installed === undefined) {
|
|
520
|
+
return {
|
|
521
|
+
present: false,
|
|
522
|
+
executable: false,
|
|
523
|
+
hashMatches: false,
|
|
524
|
+
messages: [`program missing: ${entry.program}`],
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
// `stat` follows a symlink, so this is the target's mode for a `--link` pack and the file's for
|
|
528
|
+
// a copied one. A dangling link resolves to nothing, which is the `--link` drift FR13 reports.
|
|
529
|
+
const followed = statSync(entry.program, { throwIfNoEntry: false });
|
|
530
|
+
if (followed === undefined) {
|
|
531
|
+
return {
|
|
532
|
+
present: false,
|
|
533
|
+
executable: false,
|
|
534
|
+
hashMatches: false,
|
|
535
|
+
messages: [`link target missing: ${link ?? entry.program}`],
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
const executable = (followed.mode & 0o111) !== 0;
|
|
539
|
+
if (!executable)
|
|
540
|
+
messages.push(`program is not executable: ${entry.program}`);
|
|
541
|
+
if (link !== undefined) {
|
|
542
|
+
// A linked pack records a target instead of a hash (FR11), so there is no digest to compare.
|
|
543
|
+
return { present: true, executable, hashMatches: true, messages };
|
|
544
|
+
}
|
|
545
|
+
const content = readIfPresent(entry.program);
|
|
546
|
+
const hashMatches = content !== undefined &&
|
|
547
|
+
entry.programSha256 !== undefined &&
|
|
548
|
+
sha256(content) === entry.programSha256;
|
|
549
|
+
if (!hashMatches) {
|
|
550
|
+
messages.push("program sha256 differs from the manifest; run `argos hc templates install`");
|
|
551
|
+
}
|
|
552
|
+
return { present: true, executable, hashMatches, messages };
|
|
553
|
+
}
|
|
554
|
+
/** FR13: the three independent answers, as one report and its counts. */
|
|
555
|
+
function verifyReport(manifest, dir, probe, requireServer) {
|
|
556
|
+
let warnings = 0;
|
|
557
|
+
let errors = 0;
|
|
558
|
+
const packs = Object.keys(manifest.packs)
|
|
559
|
+
.sort()
|
|
560
|
+
.map((name) => {
|
|
561
|
+
const entry = manifest.packs[name];
|
|
562
|
+
if (entry === undefined)
|
|
563
|
+
throw new Error(`manifest lost pack ${name}`);
|
|
564
|
+
const program = programFacts(entry);
|
|
565
|
+
const roster = probe.templates;
|
|
566
|
+
const templates = Object.keys(entry.templates)
|
|
567
|
+
.sort()
|
|
568
|
+
.map((templateName) => {
|
|
569
|
+
const template = entry.templates[templateName];
|
|
570
|
+
if (template === undefined)
|
|
571
|
+
throw new Error(`manifest lost template ${templateName}`);
|
|
572
|
+
const present = existsSync(template.file);
|
|
573
|
+
const inServer = roster === null ? null : inRoster(roster, templateName);
|
|
574
|
+
const messages = [...program.messages];
|
|
575
|
+
if (!present)
|
|
576
|
+
messages.push(`template file missing: ${template.file}`);
|
|
577
|
+
if (inServer === false) {
|
|
578
|
+
messages.push(`installed but not in the running server's catalog; restart \`argos serve\``);
|
|
579
|
+
}
|
|
580
|
+
else if (inServer === null) {
|
|
581
|
+
messages.push(probe.reachable
|
|
582
|
+
? (probe.note ?? "cannot tell")
|
|
583
|
+
: "argos serve is not reachable; cannot tell whether it has seen them");
|
|
584
|
+
}
|
|
585
|
+
const broken = !present || !program.present || !program.executable || !program.hashMatches;
|
|
586
|
+
const status = broken
|
|
587
|
+
? "error"
|
|
588
|
+
: inServer === true
|
|
589
|
+
? "ok"
|
|
590
|
+
: "warn";
|
|
591
|
+
if (status === "error")
|
|
592
|
+
errors += 1;
|
|
593
|
+
else if (status === "warn")
|
|
594
|
+
warnings += 1;
|
|
595
|
+
return {
|
|
596
|
+
name: templateName,
|
|
597
|
+
file: template.file,
|
|
598
|
+
present,
|
|
599
|
+
executable: program.executable,
|
|
600
|
+
hashMatches: program.hashMatches,
|
|
601
|
+
inServer,
|
|
602
|
+
status,
|
|
603
|
+
messages,
|
|
604
|
+
};
|
|
605
|
+
});
|
|
606
|
+
return { name, version: entry.version, templates };
|
|
607
|
+
});
|
|
608
|
+
return {
|
|
609
|
+
dir,
|
|
610
|
+
server: { reachable: probe.reachable, templates: probe.templates },
|
|
611
|
+
packs,
|
|
612
|
+
ok: errors === 0 && (probe.reachable || !requireServer),
|
|
613
|
+
warnings,
|
|
614
|
+
errors,
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
function countLine(count, noun) {
|
|
618
|
+
return `${count} ${noun}${count === 1 ? "" : "s"}`;
|
|
619
|
+
}
|
|
620
|
+
function humanVerify(report, probe, requireServer) {
|
|
621
|
+
const server = !report.server.reachable
|
|
622
|
+
? `${probe.url} (not reachable${probe.error === undefined ? "" : `: ${probe.error}`})`
|
|
623
|
+
: report.server.templates === null
|
|
624
|
+
? `${probe.url} (reachable, no hc templates published)`
|
|
625
|
+
: `${probe.url} (reachable, ${countLine(report.server.templates.length, "hc template")})`;
|
|
626
|
+
const lines = [
|
|
627
|
+
"argos hc templates verify",
|
|
628
|
+
` templates ${report.dir}`,
|
|
629
|
+
` server ${server}`,
|
|
630
|
+
];
|
|
631
|
+
if (report.packs.length === 0) {
|
|
632
|
+
lines.push(" no packs installed; run `argos hc templates install`");
|
|
633
|
+
}
|
|
634
|
+
for (const pack of report.packs) {
|
|
635
|
+
lines.push(` ${pack.name} ${pack.version}`);
|
|
636
|
+
for (const template of pack.templates) {
|
|
637
|
+
const detail = template.messages.length === 0 ? "" : ` ${template.messages.join("; ")}`;
|
|
638
|
+
lines.push(` ${template.name} ${template.status}${detail}`);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
lines.push(` ${countLine(report.errors, "error")}, ${countLine(report.warnings, "warning")}`);
|
|
642
|
+
if (!report.server.reachable) {
|
|
643
|
+
lines.push(requireServer
|
|
644
|
+
? " `--require-server` was given and `argos serve` is not reachable"
|
|
645
|
+
: " start it with `argos serve` to check the live catalog");
|
|
646
|
+
}
|
|
647
|
+
return lines.join("\n");
|
|
648
|
+
}
|
|
649
|
+
async function verifyCommand(args, io) {
|
|
650
|
+
const unknown = rejectUnknownFlags(args, ["dir", "require-server"]);
|
|
651
|
+
if (unknown !== undefined)
|
|
652
|
+
return usage(io, unknown);
|
|
653
|
+
if (args.positionals.length > 2)
|
|
654
|
+
return usage(io, "hc templates verify takes no arguments");
|
|
655
|
+
const dir = templatesDir(flag(args, "dir"));
|
|
656
|
+
const home = argosStateDir();
|
|
657
|
+
const requireServer = hasFlag(args, "require-server");
|
|
658
|
+
const read = readManifestDocument(home);
|
|
659
|
+
if (!read.ok)
|
|
660
|
+
return refuse(io, args.json, read.refusals);
|
|
661
|
+
const probe = await probeServer(home);
|
|
662
|
+
const report = verifyReport(read.manifest, dir, probe, requireServer);
|
|
663
|
+
if (args.json)
|
|
664
|
+
printJson(io, report);
|
|
665
|
+
else
|
|
666
|
+
io.stdout(`${humanVerify(report, probe, requireServer)}\n`);
|
|
667
|
+
// FR14/D13: 3 is `--require-server`'s alone; a broken install is an ordinary failure (1).
|
|
668
|
+
if (!probe.reachable && requireServer)
|
|
669
|
+
return EXIT_UNREACHABLE;
|
|
670
|
+
return report.errors > 0 ? EXIT_RUNTIME : EXIT_OK;
|
|
671
|
+
}
|
|
672
|
+
// ------------------------------------------------------------------ entry
|
|
673
|
+
export async function hcCommand(args, io) {
|
|
674
|
+
const group = args.positionals[0];
|
|
675
|
+
if (group !== "templates") {
|
|
676
|
+
return usage(io, "hc needs a sub-command: hc templates list|install|uninstall|verify");
|
|
677
|
+
}
|
|
678
|
+
const sub = args.positionals[1];
|
|
679
|
+
if (sub === "list")
|
|
680
|
+
return listCommand(args, io);
|
|
681
|
+
if (sub === "install")
|
|
682
|
+
return installCommand(args, io);
|
|
683
|
+
if (sub === "uninstall")
|
|
684
|
+
return uninstallCommand(args, io);
|
|
685
|
+
if (sub === "verify")
|
|
686
|
+
return verifyCommand(args, io);
|
|
687
|
+
return usage(io, "hc templates needs a sub-command: list|install|uninstall|verify");
|
|
688
|
+
}
|
|
689
|
+
//# sourceMappingURL=hc.js.map
|