@thaodangspace/argos 0.1.2 → 0.1.5
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 +34 -1
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +181 -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/rex-agents.d.ts +26 -0
- package/dist/commands/rex-agents.d.ts.map +1 -0
- package/dist/commands/rex-agents.js +505 -0
- package/dist/commands/rex-agents.js.map +1 -0
- package/dist/commands/runs.d.ts.map +1 -1
- package/dist/commands/runs.js +5 -1
- package/dist/commands/runs.js.map +1 -1
- package/dist/commands/schedule.d.ts.map +1 -1
- package/dist/commands/schedule.js +2 -1
- package/dist/commands/schedule.js.map +1 -1
- package/dist/commands/serve.d.ts +170 -10
- package/dist/commands/serve.d.ts.map +1 -1
- package/dist/commands/serve.js +291 -49
- package/dist/commands/serve.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +9 -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 +14 -4
- 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.CUSoXXAe.css +1 -0
- package/ui/_app/immutable/chunks/7kS98abs.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/BcmE4Pmo.js +2 -0
- package/ui/_app/immutable/chunks/BeleWrn1.js +5 -0
- package/ui/_app/immutable/chunks/CJuNNExc.js +1 -0
- package/ui/_app/immutable/chunks/CSzwgvai.js +55 -0
- package/ui/_app/immutable/chunks/CrMz2YMe.js +1 -0
- package/ui/_app/immutable/chunks/DK3Fl9T5.js +1 -0
- package/ui/_app/immutable/chunks/DR13iyEP.js +3 -0
- package/ui/_app/immutable/chunks/DxF9htzl.js +1 -0
- package/ui/_app/immutable/chunks/KjnrVwp0.js +4 -0
- package/ui/_app/immutable/chunks/Ta9EVp1m.js +1 -0
- package/ui/_app/immutable/chunks/UEYpU5e_.js +1 -0
- package/ui/_app/immutable/chunks/XmWYLfMV.js +1 -0
- package/ui/_app/immutable/entry/app.fpTlr2bV.js +2 -0
- package/ui/_app/immutable/entry/start.CmdXdr1Q.js +2 -0
- package/ui/_app/immutable/nodes/0.CexwxgPf.js +1 -0
- package/ui/_app/immutable/nodes/1.CXvw6Lx4.js +1 -0
- package/ui/_app/immutable/nodes/2.CVRWg4vc.js +2 -0
- package/ui/_app/immutable/nodes/3.Te_SG5Lg.js +1 -0
- package/ui/_app/immutable/nodes/4.9tMyBzuY.js +3 -0
- package/ui/_app/immutable/nodes/5.G4bzLcKA.js +1 -0
- package/ui/_app/version.json +1 -1
- package/ui/build.json +3 -3
- package/ui/index.html +23 -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/chunks/D8sQwgC_.js +0 -55
- 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,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The hc template pack model (spec FR1–FR4; plan Phase 2).
|
|
3
|
+
*
|
|
4
|
+
* A pack is **data on disk**: `pack.json` (strict, so an operator's typo is never ignored), the
|
|
5
|
+
* program named by `program.file`, and the `*.md` templates we generate from it. Nothing here
|
|
6
|
+
* touches `node:fs` — the caller hands in file contents, which is what keeps `planInstall` pure and
|
|
7
|
+
* `--dry-run` incapable of disagreeing with the real run.
|
|
8
|
+
*
|
|
9
|
+
* Every template we write carries one ownership signal in its frontmatter `description`:
|
|
10
|
+
* `· argos-pack <name> <version>`. hc echoes name/description/command from `templates.list`, so the
|
|
11
|
+
* marker is the only thing `list`, `uninstall`, and `doctor` can recognize after a machine was
|
|
12
|
+
* rebuilt with a different Argos version.
|
|
13
|
+
*/
|
|
14
|
+
import { z } from "zod";
|
|
15
|
+
/** Template and pack name rule (FR3): lower-case, digits, `-`; 1–32 characters. */
|
|
16
|
+
export const PACK_NAME_RULE = /^[a-z0-9][a-z0-9-]{0,31}$/;
|
|
17
|
+
/** The ownership marker's stable prefix. The whole line is `· argos-pack <name> <version>`. */
|
|
18
|
+
export const PACK_MARKER_PREFIX = "· argos-pack";
|
|
19
|
+
const NAME_MESSAGE = "must match ^[a-z0-9][a-z0-9-]{0,31}$";
|
|
20
|
+
/** A bare file name: the program sits beside `pack.json`, never above or below it (FR2). */
|
|
21
|
+
const BARE_FILE_NAME = z
|
|
22
|
+
.string()
|
|
23
|
+
.min(1)
|
|
24
|
+
.refine((value) => !value.includes("/") && !value.includes("\\") && value !== "." && value !== "..", "must be a bare file name beside pack.json");
|
|
25
|
+
const SHA256 = z.string().regex(/^[0-9a-f]{64}$/, "must be a lower-case hex sha256");
|
|
26
|
+
/** One template a pack ships: its args, and the step budget authors should write. */
|
|
27
|
+
export const PackTemplateSchema = z.strictObject({
|
|
28
|
+
name: z.string().regex(PACK_NAME_RULE, NAME_MESSAGE),
|
|
29
|
+
args: z.string(),
|
|
30
|
+
minStepTimeoutMs: z.number().int().min(1),
|
|
31
|
+
description: z.string().optional(),
|
|
32
|
+
});
|
|
33
|
+
/** `pack.json`: strict, because an operator writes packs and a typo must not be a silent no-op. */
|
|
34
|
+
export const PackSchema = z
|
|
35
|
+
.strictObject({
|
|
36
|
+
name: z.string().regex(PACK_NAME_RULE, NAME_MESSAGE),
|
|
37
|
+
version: z.number().int().min(1),
|
|
38
|
+
description: z.string().optional(),
|
|
39
|
+
requires: z.strictObject({
|
|
40
|
+
node: z.string().min(1),
|
|
41
|
+
hcProtocol: z.number().int(),
|
|
42
|
+
hc: z.string().optional(),
|
|
43
|
+
claude: z.string().optional(),
|
|
44
|
+
}),
|
|
45
|
+
program: z.strictObject({ file: BARE_FILE_NAME, args: z.string().optional() }),
|
|
46
|
+
templates: z.array(PackTemplateSchema).min(1),
|
|
47
|
+
})
|
|
48
|
+
.superRefine((pack, context) => {
|
|
49
|
+
const seen = new Set();
|
|
50
|
+
pack.templates.forEach((template, index) => {
|
|
51
|
+
if (seen.has(template.name)) {
|
|
52
|
+
context.addIssue({
|
|
53
|
+
code: "custom",
|
|
54
|
+
path: ["templates", index, "name"],
|
|
55
|
+
message: `duplicate template name "${template.name}"`,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
seen.add(template.name);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
/** One installed template: where its `.md` lives and the step budget the pack declared. */
|
|
62
|
+
export const PackManifestTemplateSchema = z.strictObject({
|
|
63
|
+
file: z.string().min(1),
|
|
64
|
+
minStepTimeoutMs: z.number().int().min(1),
|
|
65
|
+
});
|
|
66
|
+
/**
|
|
67
|
+
* One installed pack. `program` is always the absolute destination path (the copy, or the symlink);
|
|
68
|
+
* a copied pack carries `programSha256`, a `--link`ed one carries `link` instead (FR11).
|
|
69
|
+
*/
|
|
70
|
+
export const PackManifestPackSchema = z.strictObject({
|
|
71
|
+
version: z.number().int().min(1),
|
|
72
|
+
source: z.string().min(1),
|
|
73
|
+
program: z.string().min(1),
|
|
74
|
+
programSha256: SHA256.optional(),
|
|
75
|
+
link: z.string().min(1).optional(),
|
|
76
|
+
templates: z.record(z.string().regex(PACK_NAME_RULE, NAME_MESSAGE), PackManifestTemplateSchema),
|
|
77
|
+
});
|
|
78
|
+
/** `$ARGOS_HOME/hc/packs.json` (D1). Argos-owned; hc never reads it, and it has no timestamps (D12). */
|
|
79
|
+
export const PackManifestSchema = z.strictObject({
|
|
80
|
+
version: z.literal(1),
|
|
81
|
+
packs: z.record(z.string().regex(PACK_NAME_RULE, NAME_MESSAGE), PackManifestPackSchema),
|
|
82
|
+
});
|
|
83
|
+
export function emptyManifest() {
|
|
84
|
+
return { version: 1, packs: {} };
|
|
85
|
+
}
|
|
86
|
+
/** Canonical bytes: two-space indent, insertion order, trailing LF. No timestamp, ever (D12). */
|
|
87
|
+
export function serializeManifest(manifest) {
|
|
88
|
+
return `${JSON.stringify(manifest, null, 2)}\n`;
|
|
89
|
+
}
|
|
90
|
+
function toIssues(file, error) {
|
|
91
|
+
return error.issues.map((issue) => ({
|
|
92
|
+
path: issue.path.length === 0 ? file : `${file}:${issue.path.map(String).join(".")}`,
|
|
93
|
+
message: issue.message,
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
/** Validate `pack.json` text; an unknown key or a bad floor names the file and the field. */
|
|
97
|
+
export function parsePack(text, file) {
|
|
98
|
+
return parseJsonWith(PackSchema, text, file, "pack.json");
|
|
99
|
+
}
|
|
100
|
+
/** Validate a manifest document; a hand-edited row is refused, never merged. */
|
|
101
|
+
export function parseManifest(text, file) {
|
|
102
|
+
return parseJsonWith(PackManifestSchema, text, file, "packs.json");
|
|
103
|
+
}
|
|
104
|
+
function parseJsonWith(schema, text, file, label) {
|
|
105
|
+
let raw;
|
|
106
|
+
try {
|
|
107
|
+
raw = JSON.parse(text);
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
return {
|
|
111
|
+
ok: false,
|
|
112
|
+
issues: [{ path: file, message: `${label} is not valid JSON: ${error.message}` }],
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
const parsed = schema.safeParse(raw);
|
|
116
|
+
return parsed.success
|
|
117
|
+
? { ok: true, value: parsed.data }
|
|
118
|
+
: { ok: false, issues: toIssues(file, parsed.error) };
|
|
119
|
+
}
|
|
120
|
+
/** `· argos-pack claude 1` — the one ownership signal a template file carries. */
|
|
121
|
+
export function packMarker(pack) {
|
|
122
|
+
return `${PACK_MARKER_PREFIX} ${pack.name} ${pack.version}`;
|
|
123
|
+
}
|
|
124
|
+
const MARKER_PATTERN = new RegExp(`${PACK_MARKER_PREFIX}\\s+([a-z0-9][a-z0-9-]{0,31})\\s+(\\d+)`);
|
|
125
|
+
/** The marker a description carries, or `undefined` when the file is not ours. */
|
|
126
|
+
export function markerOf(description) {
|
|
127
|
+
if (description === undefined)
|
|
128
|
+
return undefined;
|
|
129
|
+
const match = MARKER_PATTERN.exec(description);
|
|
130
|
+
if (match === null)
|
|
131
|
+
return undefined;
|
|
132
|
+
return { name: match[1], version: Number.parseInt(match[2], 10) };
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* A generated template (FR2): frontmatter `name`/`description`/`command`, empty body — hc sends a
|
|
136
|
+
* template's body *with* the prompt, and our prompt is the whole task.
|
|
137
|
+
*
|
|
138
|
+
* `description` and `command` are written as YAML double-quoted scalars (JSON escaping is a YAML
|
|
139
|
+
* subset), so a path that contains a quote, a space, or a `#` cannot silently break the document.
|
|
140
|
+
*/
|
|
141
|
+
export function renderTemplate(input) {
|
|
142
|
+
const description = input.pack === undefined
|
|
143
|
+
? input.description
|
|
144
|
+
: input.description === ""
|
|
145
|
+
? packMarker(input.pack)
|
|
146
|
+
: `${input.description} ${packMarker(input.pack)}`;
|
|
147
|
+
return [
|
|
148
|
+
"---",
|
|
149
|
+
`name: ${input.name}`,
|
|
150
|
+
`description: ${JSON.stringify(description)}`,
|
|
151
|
+
`command: ${JSON.stringify(input.command)}`,
|
|
152
|
+
"---",
|
|
153
|
+
"",
|
|
154
|
+
].join("\n");
|
|
155
|
+
}
|
|
156
|
+
/** Parse a template's frontmatter. Never throws: a foreign file is data, not an error. */
|
|
157
|
+
export function parseTemplate(text) {
|
|
158
|
+
const match = /^---\r?\n([\s\S]*?)\r?\n---[ \t]*\r?\n?/.exec(text);
|
|
159
|
+
if (match === null)
|
|
160
|
+
return { body: text };
|
|
161
|
+
const fields = new Map();
|
|
162
|
+
for (const line of match[1].split(/\r?\n/)) {
|
|
163
|
+
const colon = line.indexOf(":");
|
|
164
|
+
if (colon <= 0)
|
|
165
|
+
continue;
|
|
166
|
+
const key = line.slice(0, colon).trim();
|
|
167
|
+
if (key === "")
|
|
168
|
+
continue;
|
|
169
|
+
fields.set(key, unquote(line.slice(colon + 1).trim()));
|
|
170
|
+
}
|
|
171
|
+
const description = fields.get("description");
|
|
172
|
+
const pack = markerOf(description);
|
|
173
|
+
const result = { body: text.slice(match[0].length) };
|
|
174
|
+
const name = fields.get("name");
|
|
175
|
+
const command = fields.get("command");
|
|
176
|
+
if (name !== undefined)
|
|
177
|
+
result.name = name;
|
|
178
|
+
if (description !== undefined)
|
|
179
|
+
result.description = description;
|
|
180
|
+
if (command !== undefined)
|
|
181
|
+
result.command = command;
|
|
182
|
+
if (pack !== undefined)
|
|
183
|
+
result.pack = pack;
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
/** One frontmatter scalar: a JSON double-quoted string, a YAML single-quoted one, or plain text. */
|
|
187
|
+
function unquote(raw) {
|
|
188
|
+
if (raw.length >= 2 && raw.startsWith('"') && raw.endsWith('"')) {
|
|
189
|
+
try {
|
|
190
|
+
const parsed = JSON.parse(raw);
|
|
191
|
+
if (typeof parsed === "string")
|
|
192
|
+
return parsed;
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
// A hand-written template may quote in a way JSON rejects; fall through to the raw text.
|
|
196
|
+
}
|
|
197
|
+
return raw.slice(1, -1);
|
|
198
|
+
}
|
|
199
|
+
if (raw.length >= 2 && raw.startsWith("'") && raw.endsWith("'")) {
|
|
200
|
+
return raw.slice(1, -1).replaceAll("''", "'");
|
|
201
|
+
}
|
|
202
|
+
return raw;
|
|
203
|
+
}
|
|
204
|
+
//# sourceMappingURL=pack.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pack.js","sourceRoot":"","sources":["../../src/packs/pack.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AAC,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pure half of the installer (spec FR11/FR12, plan Phase 2).
|
|
3
|
+
*
|
|
4
|
+
* `planInstall` and `planUninstall` take the *contents* of everything they need and return the
|
|
5
|
+
* list of writes, links, removals, and the next manifest. No fs, no clock, no env read: `--dry-run`
|
|
6
|
+
* prints this plan and the real install applies the same one, so the two cannot disagree.
|
|
7
|
+
*
|
|
8
|
+
* Rules encoded here:
|
|
9
|
+
* - a version bump installs into `packs/<name>@<version>/`, never over a running terminal's file;
|
|
10
|
+
* - identical content is no write at all, and a plan with nothing to do is `unchanged`;
|
|
11
|
+
* - a `.md` without our marker is refused unless `--force`, and a marker naming another pack is
|
|
12
|
+
* refused too (two packs may not own one template name);
|
|
13
|
+
* - the running Node must satisfy `requires.node`, and `requires.hcProtocol` must be 1;
|
|
14
|
+
* - `hc`/`claude` floors are warnings: the API has no per-template probe, and a template that works
|
|
15
|
+
* today must not be blocked by a version string;
|
|
16
|
+
* - `uninstall` deletes a file only when the file itself carries our marker.
|
|
17
|
+
*/
|
|
18
|
+
import { type Pack, type PackManifest } from "./pack.js";
|
|
19
|
+
/**
|
|
20
|
+
* One command argument, quoted for the platform that will parse it (FR11).
|
|
21
|
+
*
|
|
22
|
+
* POSIX gets single quotes with a `'\''` run for an embedded quote (correct for every byte a path
|
|
23
|
+
* can hold), Windows gets CRT-style double quotes with a backslash-escaped `"`. A path containing
|
|
24
|
+
* both quote styles therefore survives either way instead of producing a command hc cannot run.
|
|
25
|
+
*/
|
|
26
|
+
export declare function quoteCommandArg(value: string, platform?: NodeJS.Platform): string;
|
|
27
|
+
/**
|
|
28
|
+
* `satisfiesNodeFloor(">=22.13", "22.13.0")` → true. `undefined` means the floor is not a form this
|
|
29
|
+
* installer understands, which the caller turns into a refusal rather than a guess.
|
|
30
|
+
*/
|
|
31
|
+
export declare function satisfiesNodeFloor(floor: string, version: string): boolean | undefined;
|
|
32
|
+
/** A template file that is already in the templates directory (its `.md` basename, content read). */
|
|
33
|
+
export interface DiskTemplate {
|
|
34
|
+
readonly name: string;
|
|
35
|
+
readonly content: string;
|
|
36
|
+
}
|
|
37
|
+
/** The program already installed at the destination path, as read by the caller. */
|
|
38
|
+
export interface InstalledProgram {
|
|
39
|
+
readonly sha256?: string;
|
|
40
|
+
readonly linkTarget?: string;
|
|
41
|
+
}
|
|
42
|
+
/** One pack to install, with its source files already read (this is what keeps the plan pure). */
|
|
43
|
+
export interface PackSource {
|
|
44
|
+
readonly pack: Pack;
|
|
45
|
+
/** Absolute `pack.json` path, for messages. */
|
|
46
|
+
readonly file: string;
|
|
47
|
+
/** Absolute pack directory (the program lives beside `pack.json`). */
|
|
48
|
+
readonly dir: string;
|
|
49
|
+
/** The manifest's `source`: `bundled`, or the `--from` directory. */
|
|
50
|
+
readonly source: string;
|
|
51
|
+
/** Program contents; absent for `--link`, where only the source path matters. */
|
|
52
|
+
readonly programContent?: string;
|
|
53
|
+
readonly installedProgram?: InstalledProgram;
|
|
54
|
+
}
|
|
55
|
+
export interface InstallInput {
|
|
56
|
+
readonly packs: readonly PackSource[];
|
|
57
|
+
readonly templates: readonly DiskTemplate[];
|
|
58
|
+
readonly manifest: PackManifest;
|
|
59
|
+
readonly templatesDir: string;
|
|
60
|
+
readonly home: string;
|
|
61
|
+
/** The running Node, e.g. `process.versions.node`. */
|
|
62
|
+
readonly nodeVersion: string;
|
|
63
|
+
/** Absolute `process.execPath`: hc starts the program from its own minimal `PATH`. */
|
|
64
|
+
readonly nodePath: string;
|
|
65
|
+
readonly link: boolean;
|
|
66
|
+
readonly force: boolean;
|
|
67
|
+
readonly platform?: NodeJS.Platform;
|
|
68
|
+
}
|
|
69
|
+
export interface PlannedWrite {
|
|
70
|
+
readonly path: string;
|
|
71
|
+
readonly content: string;
|
|
72
|
+
/** `0700` for a program, `0644` for a template, `0600` for the manifest. */
|
|
73
|
+
readonly mode: number;
|
|
74
|
+
}
|
|
75
|
+
export interface PlannedLink {
|
|
76
|
+
readonly path: string;
|
|
77
|
+
readonly target: string;
|
|
78
|
+
}
|
|
79
|
+
export interface Refusal {
|
|
80
|
+
readonly code: string;
|
|
81
|
+
readonly message: string;
|
|
82
|
+
}
|
|
83
|
+
export interface InstallPlan {
|
|
84
|
+
readonly writes: readonly PlannedWrite[];
|
|
85
|
+
readonly links: readonly PlannedLink[];
|
|
86
|
+
readonly manifest: PackManifest;
|
|
87
|
+
/** The manifest write, applied **last** (NFR: an interrupted install is detectable). */
|
|
88
|
+
readonly manifestWrite?: PlannedWrite;
|
|
89
|
+
readonly warnings: readonly string[];
|
|
90
|
+
readonly refusals: readonly Refusal[];
|
|
91
|
+
readonly unchanged: boolean;
|
|
92
|
+
}
|
|
93
|
+
export declare function planInstall(input: InstallInput): InstallPlan;
|
|
94
|
+
export interface UninstallInput {
|
|
95
|
+
readonly packs: readonly string[];
|
|
96
|
+
readonly templates: readonly DiskTemplate[];
|
|
97
|
+
readonly manifest: PackManifest;
|
|
98
|
+
readonly templatesDir: string;
|
|
99
|
+
readonly home: string;
|
|
100
|
+
/** Basenames of the directories that exist under `<home>/hc/packs`, as read by the caller. */
|
|
101
|
+
readonly existingPackDirs: readonly string[];
|
|
102
|
+
readonly prune: boolean;
|
|
103
|
+
}
|
|
104
|
+
export interface PlannedRemove {
|
|
105
|
+
readonly path: string;
|
|
106
|
+
/** `template` is a `.md`, `pack` is a whole `<name>@<version>/` directory. */
|
|
107
|
+
readonly kind: "template" | "pack";
|
|
108
|
+
}
|
|
109
|
+
export interface KeptFile {
|
|
110
|
+
readonly path: string;
|
|
111
|
+
/** Why it stayed: `foreign`, `owned_by <pack>`, `missing`, `moved`, or a pruned-directory hint. */
|
|
112
|
+
readonly reason: string;
|
|
113
|
+
}
|
|
114
|
+
export interface UninstallPlan {
|
|
115
|
+
readonly removes: readonly PlannedRemove[];
|
|
116
|
+
readonly keeps: readonly KeptFile[];
|
|
117
|
+
readonly manifest: PackManifest;
|
|
118
|
+
readonly manifestWrite?: PlannedWrite;
|
|
119
|
+
readonly refusals: readonly Refusal[];
|
|
120
|
+
readonly unchanged: boolean;
|
|
121
|
+
}
|
|
122
|
+
export declare function planUninstall(input: UninstallInput): UninstallPlan;
|
|
123
|
+
//# sourceMappingURL=plan.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan.d.ts","sourceRoot":"","sources":["../../src/packs/plan.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAKH,OAAO,EAIL,KAAK,IAAI,EACT,KAAK,YAAY,EAElB,MAAM,WAAW,CAAC;AAKnB;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAAG,MAAM,CAGnG;AAyBD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAetF;AAID,qGAAqG;AACrG,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,oFAAoF;AACpF,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,kGAAkG;AAClG,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,+CAA+C;IAC/C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,sEAAsE;IACtE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,qEAAqE;IACrE,QAAQ,CAAC,MAAM,EAAE,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tC,QAAQ,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAC;IACtC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC7B;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,cAAc,GAAG,aAAa,CAoFlE"}
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pure half of the installer (spec FR11/FR12, plan Phase 2).
|
|
3
|
+
*
|
|
4
|
+
* `planInstall` and `planUninstall` take the *contents* of everything they need and return the
|
|
5
|
+
* list of writes, links, removals, and the next manifest. No fs, no clock, no env read: `--dry-run`
|
|
6
|
+
* prints this plan and the real install applies the same one, so the two cannot disagree.
|
|
7
|
+
*
|
|
8
|
+
* Rules encoded here:
|
|
9
|
+
* - a version bump installs into `packs/<name>@<version>/`, never over a running terminal's file;
|
|
10
|
+
* - identical content is no write at all, and a plan with nothing to do is `unchanged`;
|
|
11
|
+
* - a `.md` without our marker is refused unless `--force`, and a marker naming another pack is
|
|
12
|
+
* refused too (two packs may not own one template name);
|
|
13
|
+
* - the running Node must satisfy `requires.node`, and `requires.hcProtocol` must be 1;
|
|
14
|
+
* - `hc`/`claude` floors are warnings: the API has no per-template probe, and a template that works
|
|
15
|
+
* today must not be blocked by a version string;
|
|
16
|
+
* - `uninstall` deletes a file only when the file itself carries our marker.
|
|
17
|
+
*/
|
|
18
|
+
import { createHash } from "node:crypto";
|
|
19
|
+
import { dirname, join, resolve } from "node:path";
|
|
20
|
+
import { parseTemplate, renderTemplate, serializeManifest, } from "./pack.js";
|
|
21
|
+
import { PACK_DIR_RULE, manifestPath, packInstallDir, packsRoot } from "./templates-dir.js";
|
|
22
|
+
// ------------------------------------------------------------------ quoting
|
|
23
|
+
/**
|
|
24
|
+
* One command argument, quoted for the platform that will parse it (FR11).
|
|
25
|
+
*
|
|
26
|
+
* POSIX gets single quotes with a `'\''` run for an embedded quote (correct for every byte a path
|
|
27
|
+
* can hold), Windows gets CRT-style double quotes with a backslash-escaped `"`. A path containing
|
|
28
|
+
* both quote styles therefore survives either way instead of producing a command hc cannot run.
|
|
29
|
+
*/
|
|
30
|
+
export function quoteCommandArg(value, platform = process.platform) {
|
|
31
|
+
if (platform === "win32")
|
|
32
|
+
return quoteWindows(value);
|
|
33
|
+
return `'${value.replaceAll("'", "'\\''")}'`;
|
|
34
|
+
}
|
|
35
|
+
function quoteWindows(value) {
|
|
36
|
+
let out = '"';
|
|
37
|
+
let backslashes = 0;
|
|
38
|
+
for (const char of value) {
|
|
39
|
+
if (char === "\\") {
|
|
40
|
+
backslashes += 1;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (char === '"') {
|
|
44
|
+
out += `${"\\".repeat(backslashes * 2 + 1)}"`;
|
|
45
|
+
backslashes = 0;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
out += `${"\\".repeat(backslashes)}${char}`;
|
|
49
|
+
backslashes = 0;
|
|
50
|
+
}
|
|
51
|
+
return `${out}${"\\".repeat(backslashes * 2)}"`;
|
|
52
|
+
}
|
|
53
|
+
// ------------------------------------------------------------------ node floors
|
|
54
|
+
const NODE_FLOOR = /^>=\s*(\d+)(?:\.(\d+))?(?:\.(\d+))?$/;
|
|
55
|
+
/**
|
|
56
|
+
* `satisfiesNodeFloor(">=22.13", "22.13.0")` → true. `undefined` means the floor is not a form this
|
|
57
|
+
* installer understands, which the caller turns into a refusal rather than a guess.
|
|
58
|
+
*/
|
|
59
|
+
export function satisfiesNodeFloor(floor, version) {
|
|
60
|
+
const wanted = NODE_FLOOR.exec(floor.trim());
|
|
61
|
+
if (wanted === null)
|
|
62
|
+
return undefined;
|
|
63
|
+
const have = version.split(".").map((part) => Number.parseInt(part, 10));
|
|
64
|
+
if (have.length < 2 || have.some((part) => !Number.isInteger(part)))
|
|
65
|
+
return undefined;
|
|
66
|
+
const wantedParts = [wanted[1], wanted[2] ?? "0", wanted[3] ?? "0"].map((part) => Number.parseInt(part, 10));
|
|
67
|
+
for (let index = 0; index < 3; index += 1) {
|
|
68
|
+
const left = have[index] ?? 0;
|
|
69
|
+
const right = wantedParts[index];
|
|
70
|
+
if (left > right)
|
|
71
|
+
return true;
|
|
72
|
+
if (left < right)
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
// ------------------------------------------------------------------ install
|
|
78
|
+
function sha256(text) {
|
|
79
|
+
return createHash("sha256").update(text).digest("hex");
|
|
80
|
+
}
|
|
81
|
+
function sortedPacks(packs) {
|
|
82
|
+
const entries = Object.keys(packs)
|
|
83
|
+
.sort()
|
|
84
|
+
.map((name) => [name, packs[name]]);
|
|
85
|
+
return { version: 1, packs: Object.fromEntries(entries) };
|
|
86
|
+
}
|
|
87
|
+
/** `<abs node> <abs program> <pack args> <template args>` — quoted, never re-split by us. */
|
|
88
|
+
function templateCommand(nodePath, programPath, programArgs, templateArgs, platform) {
|
|
89
|
+
const parts = [quoteCommandArg(nodePath, platform), quoteCommandArg(programPath, platform)];
|
|
90
|
+
for (const extra of [programArgs, templateArgs]) {
|
|
91
|
+
const trimmed = extra?.trim() ?? "";
|
|
92
|
+
if (trimmed !== "")
|
|
93
|
+
parts.push(trimmed);
|
|
94
|
+
}
|
|
95
|
+
return parts.join(" ");
|
|
96
|
+
}
|
|
97
|
+
export function planInstall(input) {
|
|
98
|
+
const platform = input.platform ?? process.platform;
|
|
99
|
+
const refusals = [];
|
|
100
|
+
const warnings = [];
|
|
101
|
+
const writes = [];
|
|
102
|
+
const links = [];
|
|
103
|
+
const nextPacks = { ...input.manifest.packs };
|
|
104
|
+
const claimed = new Map();
|
|
105
|
+
const refuse = (code, message) => {
|
|
106
|
+
refusals.push({ code, message });
|
|
107
|
+
};
|
|
108
|
+
if (input.link && platform === "win32") {
|
|
109
|
+
refuse("link_unsupported", "--link is not supported on Windows (creating a symlink needs a privilege)");
|
|
110
|
+
}
|
|
111
|
+
const seen = new Set();
|
|
112
|
+
for (const source of input.packs) {
|
|
113
|
+
const pack = source.pack;
|
|
114
|
+
if (seen.has(pack.name)) {
|
|
115
|
+
refuse("pack_duplicate", `${source.file}: pack "${pack.name}" is listed twice`);
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
seen.add(pack.name);
|
|
119
|
+
if (pack.requires.hcProtocol !== 1) {
|
|
120
|
+
refuse("unsupported_protocol", `${source.file}:requires.hcProtocol is ${pack.requires.hcProtocol}; this argos speaks protocol 1`);
|
|
121
|
+
}
|
|
122
|
+
const nodeFloor = satisfiesNodeFloor(pack.requires.node, input.nodeVersion);
|
|
123
|
+
if (nodeFloor === undefined) {
|
|
124
|
+
refuse("invalid_floor", `${source.file}:requires.node ${JSON.stringify(pack.requires.node)} is not a ">=x.y" floor`);
|
|
125
|
+
}
|
|
126
|
+
else if (!nodeFloor) {
|
|
127
|
+
refuse("node_too_old", `${source.file}:requires.node ${pack.requires.node} is newer than the running Node ${input.nodeVersion}`);
|
|
128
|
+
}
|
|
129
|
+
if (pack.requires.hc !== undefined) {
|
|
130
|
+
warnings.push(`pack "${pack.name}" requires hc ${pack.requires.hc}; not checked offline (run \`hc --version\`)`);
|
|
131
|
+
}
|
|
132
|
+
if (pack.requires.claude !== undefined) {
|
|
133
|
+
warnings.push(`pack "${pack.name}" requires claude ${pack.requires.claude}; not checked offline (run \`claude --version\`)`);
|
|
134
|
+
}
|
|
135
|
+
const previous = input.manifest.packs[pack.name];
|
|
136
|
+
if (previous !== undefined && previous.version > pack.version) {
|
|
137
|
+
warnings.push(`pack "${pack.name}" is installed at version ${previous.version}; installing ${pack.version} is a downgrade`);
|
|
138
|
+
}
|
|
139
|
+
if (source.programContent === undefined && !input.link) {
|
|
140
|
+
refuse("program_missing", `${source.file}: program "${pack.program.file}" could not be read`);
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const packDir = packInstallDir(input.home, pack.name, pack.version);
|
|
144
|
+
const programDest = join(packDir, pack.program.file);
|
|
145
|
+
const programSource = resolve(source.dir, pack.program.file);
|
|
146
|
+
// A linked pack runs the program where the operator keeps it; a copied one runs the copy.
|
|
147
|
+
const programPath = input.link ? programSource : programDest;
|
|
148
|
+
if (input.link) {
|
|
149
|
+
if (source.installedProgram?.linkTarget !== programSource) {
|
|
150
|
+
links.push({ path: programDest, target: programSource });
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
const content = source.programContent;
|
|
155
|
+
if (source.installedProgram?.sha256 !== sha256(content)) {
|
|
156
|
+
writes.push({ path: programDest, content, mode: 0o700 });
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
const templates = {};
|
|
160
|
+
for (const template of pack.templates) {
|
|
161
|
+
const owner = claimed.get(template.name);
|
|
162
|
+
if (owner !== undefined && owner !== pack.name) {
|
|
163
|
+
refuse("template_conflict", `template "${template.name}" is claimed by both pack "${owner}" and pack "${pack.name}"`);
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
claimed.set(template.name, pack.name);
|
|
167
|
+
const file = join(input.templatesDir, `${template.name}.md`);
|
|
168
|
+
const existing = input.templates.find((candidate) => candidate.name === template.name);
|
|
169
|
+
if (existing !== undefined) {
|
|
170
|
+
const marker = parseTemplate(existing.content).pack;
|
|
171
|
+
if (marker === undefined) {
|
|
172
|
+
if (!input.force) {
|
|
173
|
+
refuse("template_conflict", `${file} exists and is not an argos pack template (pass --force to overwrite)`);
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
else if (marker.name !== pack.name && !input.force) {
|
|
178
|
+
refuse("template_conflict", `${file} belongs to pack "${marker.name}"; pass --force to let pack "${pack.name}" take it`);
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const command = templateCommand(input.nodePath, programPath, pack.program.args, template.args, platform);
|
|
183
|
+
const content = renderTemplate({
|
|
184
|
+
name: template.name,
|
|
185
|
+
description: template.description ?? `${pack.name} template ${template.name}`,
|
|
186
|
+
command,
|
|
187
|
+
pack: { name: pack.name, version: pack.version },
|
|
188
|
+
});
|
|
189
|
+
if (existing?.content !== content)
|
|
190
|
+
writes.push({ path: file, content, mode: 0o644 });
|
|
191
|
+
templates[template.name] = { file, minStepTimeoutMs: template.minStepTimeoutMs };
|
|
192
|
+
}
|
|
193
|
+
const entry = {
|
|
194
|
+
version: pack.version,
|
|
195
|
+
source: source.source,
|
|
196
|
+
program: programDest,
|
|
197
|
+
...(input.link
|
|
198
|
+
? { link: programPath }
|
|
199
|
+
: { programSha256: sha256(source.programContent) }),
|
|
200
|
+
templates,
|
|
201
|
+
};
|
|
202
|
+
nextPacks[pack.name] = entry;
|
|
203
|
+
}
|
|
204
|
+
// A refusal writes nothing, so a half-installed pack can never be the result of a bad input.
|
|
205
|
+
if (refusals.length > 0) {
|
|
206
|
+
return {
|
|
207
|
+
writes: [],
|
|
208
|
+
links: [],
|
|
209
|
+
manifest: input.manifest,
|
|
210
|
+
warnings,
|
|
211
|
+
refusals,
|
|
212
|
+
unchanged: false,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
const manifest = sortedPacks(nextPacks);
|
|
216
|
+
const text = serializeManifest(manifest);
|
|
217
|
+
const manifestWrite = text === serializeManifest(input.manifest)
|
|
218
|
+
? undefined
|
|
219
|
+
: { path: manifestPath(input.home), content: text, mode: 0o600 };
|
|
220
|
+
const plan = {
|
|
221
|
+
writes,
|
|
222
|
+
links,
|
|
223
|
+
manifest,
|
|
224
|
+
warnings,
|
|
225
|
+
refusals,
|
|
226
|
+
unchanged: writes.length === 0 && links.length === 0 && manifestWrite === undefined,
|
|
227
|
+
};
|
|
228
|
+
return manifestWrite === undefined ? plan : { ...plan, manifestWrite };
|
|
229
|
+
}
|
|
230
|
+
export function planUninstall(input) {
|
|
231
|
+
const refusals = [];
|
|
232
|
+
const removes = [];
|
|
233
|
+
const keeps = [];
|
|
234
|
+
const nextPacks = { ...input.manifest.packs };
|
|
235
|
+
for (const name of input.packs) {
|
|
236
|
+
const entry = nextPacks[name];
|
|
237
|
+
if (entry === undefined) {
|
|
238
|
+
refusals.push({ code: "pack_unknown", message: `pack "${name}" is not installed` });
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
delete nextPacks[name];
|
|
242
|
+
for (const [templateName, template] of Object.entries(entry.templates)) {
|
|
243
|
+
// The recorded path is authoritative: uninstalling under a different `--dir` must not reach
|
|
244
|
+
// into a directory this pack never wrote. A moved file is reported, never guessed at.
|
|
245
|
+
const expected = join(input.templatesDir, `${templateName}.md`);
|
|
246
|
+
if (resolve(template.file) !== resolve(expected)) {
|
|
247
|
+
keeps.push({ path: template.file, reason: `moved (not ${expected})` });
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
const disk = input.templates.find((candidate) => candidate.name === templateName);
|
|
251
|
+
if (disk === undefined) {
|
|
252
|
+
keeps.push({ path: expected, reason: "missing" });
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
const marker = parseTemplate(disk.content).pack;
|
|
256
|
+
if (marker === undefined) {
|
|
257
|
+
keeps.push({ path: expected, reason: "not an argos pack template" });
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
if (marker.name !== name) {
|
|
261
|
+
keeps.push({ path: expected, reason: `owned by pack "${marker.name}"` });
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
removes.push({ path: expected, kind: "template" });
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (refusals.length > 0) {
|
|
268
|
+
return {
|
|
269
|
+
removes: [],
|
|
270
|
+
keeps: [],
|
|
271
|
+
manifest: input.manifest,
|
|
272
|
+
refusals,
|
|
273
|
+
unchanged: false,
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
const manifest = sortedPacks(nextPacks);
|
|
277
|
+
const referenced = new Set(Object.values(manifest.packs).map((entry) => dirname(entry.program).split(/[\\/]/).at(-1) ?? ""));
|
|
278
|
+
// Prune is scoped to the packs the operator named: a stray `<pack>@<version>` directory of a
|
|
279
|
+
// pack still installed is never touched, and a directory Argos does not name
|
|
280
|
+
// (`<pack>@<version>`) is never ours to delete.
|
|
281
|
+
const removedPacks = new Set(input.packs);
|
|
282
|
+
const unreferenced = input.existingPackDirs
|
|
283
|
+
.filter((dir) => PACK_DIR_RULE.test(dir) &&
|
|
284
|
+
!referenced.has(dir) &&
|
|
285
|
+
removedPacks.has(dir.slice(0, dir.indexOf("@"))))
|
|
286
|
+
.sort();
|
|
287
|
+
for (const dir of unreferenced) {
|
|
288
|
+
const path = join(packsRoot(input.home), dir);
|
|
289
|
+
if (input.prune)
|
|
290
|
+
removes.push({ path, kind: "pack" });
|
|
291
|
+
else
|
|
292
|
+
keeps.push({ path, reason: "program dir (pass --prune to remove)" });
|
|
293
|
+
}
|
|
294
|
+
const text = serializeManifest(manifest);
|
|
295
|
+
const manifestWrite = text === serializeManifest(input.manifest)
|
|
296
|
+
? undefined
|
|
297
|
+
: { path: manifestPath(input.home), content: text, mode: 0o600 };
|
|
298
|
+
const plan = {
|
|
299
|
+
removes,
|
|
300
|
+
keeps,
|
|
301
|
+
manifest,
|
|
302
|
+
refusals,
|
|
303
|
+
unchanged: removes.length === 0 && manifestWrite === undefined,
|
|
304
|
+
};
|
|
305
|
+
return manifestWrite === undefined ? plan : { ...plan, manifestWrite };
|
|
306
|
+
}
|
|
307
|
+
//# sourceMappingURL=plan.js.map
|