@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.
Files changed (94) hide show
  1. package/README.md +4 -4
  2. package/dist/args.d.ts.map +1 -1
  3. package/dist/args.js +5 -1
  4. package/dist/args.js.map +1 -1
  5. package/dist/commands/chart.d.ts +21 -0
  6. package/dist/commands/chart.d.ts.map +1 -0
  7. package/dist/commands/chart.js +209 -0
  8. package/dist/commands/chart.js.map +1 -0
  9. package/dist/commands/doctor.d.ts +18 -1
  10. package/dist/commands/doctor.d.ts.map +1 -1
  11. package/dist/commands/doctor.js +123 -4
  12. package/dist/commands/doctor.js.map +1 -1
  13. package/dist/commands/hc.d.ts +16 -0
  14. package/dist/commands/hc.d.ts.map +1 -0
  15. package/dist/commands/hc.js +689 -0
  16. package/dist/commands/hc.js.map +1 -0
  17. package/dist/commands/serve.d.ts +23 -2
  18. package/dist/commands/serve.d.ts.map +1 -1
  19. package/dist/commands/serve.js +72 -14
  20. package/dist/commands/serve.js.map +1 -1
  21. package/dist/main.d.ts.map +1 -1
  22. package/dist/main.js +6 -0
  23. package/dist/main.js.map +1 -1
  24. package/dist/output.d.ts +1 -1
  25. package/dist/output.d.ts.map +1 -1
  26. package/dist/output.js +6 -0
  27. package/dist/output.js.map +1 -1
  28. package/dist/packs/apply.d.ts +36 -0
  29. package/dist/packs/apply.d.ts.map +1 -0
  30. package/dist/packs/apply.js +103 -0
  31. package/dist/packs/apply.js.map +1 -0
  32. package/dist/packs/bundled.d.ts +27 -0
  33. package/dist/packs/bundled.d.ts.map +1 -0
  34. package/dist/packs/bundled.js +42 -0
  35. package/dist/packs/bundled.js.map +1 -0
  36. package/dist/packs/pack.d.ts +142 -0
  37. package/dist/packs/pack.d.ts.map +1 -0
  38. package/dist/packs/pack.js +204 -0
  39. package/dist/packs/pack.js.map +1 -0
  40. package/dist/packs/plan.d.ts +123 -0
  41. package/dist/packs/plan.d.ts.map +1 -0
  42. package/dist/packs/plan.js +307 -0
  43. package/dist/packs/plan.js.map +1 -0
  44. package/dist/packs/templates-dir.d.ts +29 -0
  45. package/dist/packs/templates-dir.d.ts.map +1 -0
  46. package/dist/packs/templates-dir.js +49 -0
  47. package/dist/packs/templates-dir.js.map +1 -0
  48. package/package.json +4 -2
  49. package/templates/packs/claude/claude-step.mjs +666 -0
  50. package/templates/packs/claude/pack.json +38 -0
  51. package/templates/packs/smoke/pack.json +20 -0
  52. package/templates/packs/smoke/smoke.mjs +104 -0
  53. package/ui/_app/immutable/assets/0.CTk3h7Zx.css +2 -0
  54. package/ui/_app/immutable/chunks/9Dk6YhUf.js +1 -0
  55. package/ui/_app/immutable/chunks/BDgjZRhb.js +1 -0
  56. package/ui/_app/immutable/chunks/BQUxoyXx.js +1 -0
  57. package/ui/_app/immutable/chunks/BVvEKWUw.js +1 -0
  58. package/ui/_app/immutable/chunks/BXIfM5K1.js +1 -0
  59. package/ui/_app/immutable/chunks/B_XCALJf.js +1 -0
  60. package/ui/_app/immutable/chunks/BiQUXUyr.js +1 -0
  61. package/ui/_app/immutable/chunks/CPty2F6V.js +2 -0
  62. package/ui/_app/immutable/chunks/CqLqOuLw.js +4 -0
  63. package/ui/_app/immutable/chunks/Cta5wR5U.js +1 -0
  64. package/ui/_app/immutable/chunks/DlHMls5I.js +1 -0
  65. package/ui/_app/immutable/chunks/DqmgjiJ7.js +3 -0
  66. package/ui/_app/immutable/chunks/{D8sQwgC_.js → DxP_sZrQ.js} +1 -1
  67. package/ui/_app/immutable/chunks/PR6kdzSw.js +1 -0
  68. package/ui/_app/immutable/entry/app.DefioTIJ.js +2 -0
  69. package/ui/_app/immutable/entry/start.D3LG_apg.js +2 -0
  70. package/ui/_app/immutable/nodes/0.Bxn1Q-bg.js +1 -0
  71. package/ui/_app/immutable/nodes/1.DVMonhb0.js +1 -0
  72. package/ui/_app/immutable/nodes/2.DiUZ9i2y.js +2 -0
  73. package/ui/_app/immutable/nodes/3.C6GP2DYu.js +1 -0
  74. package/ui/_app/immutable/nodes/4._uRXFvRQ.js +3 -0
  75. package/ui/_app/immutable/nodes/5.BwtM7IQO.js +1 -0
  76. package/ui/_app/version.json +1 -1
  77. package/ui/build.json +3 -3
  78. package/ui/index.html +22 -18
  79. package/ui/_app/immutable/assets/0.Y-Ej83kR.css +0 -1
  80. package/ui/_app/immutable/assets/2.D2FEqQBh.css +0 -1
  81. package/ui/_app/immutable/assets/3.CI7aeD9i.css +0 -1
  82. package/ui/_app/immutable/assets/StartRunDialog.BbbZvJfB.css +0 -1
  83. package/ui/_app/immutable/assets/runs.CU5wtnW2.css +0 -1
  84. package/ui/_app/immutable/chunks/BKHbyffl.js +0 -3
  85. package/ui/_app/immutable/chunks/BeG5AxKI.js +0 -3
  86. package/ui/_app/immutable/chunks/Buwi_lQz.js +0 -2
  87. package/ui/_app/immutable/chunks/CV2Ptlrp.js +0 -1
  88. package/ui/_app/immutable/chunks/CtbaNJav.js +0 -1
  89. package/ui/_app/immutable/entry/app.DPg5reEl.js +0 -2
  90. package/ui/_app/immutable/entry/start.iWBP-EvH.js +0 -2
  91. package/ui/_app/immutable/nodes/0.Cu8SyVzm.js +0 -1
  92. package/ui/_app/immutable/nodes/1.Bga_qdeZ.js +0 -1
  93. package/ui/_app/immutable/nodes/2.CKNrkmzJ.js +0 -1
  94. package/ui/_app/immutable/nodes/3.OrFQ8OoI.js +0 -1
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The packs that ship inside the CLI tarball (plan D8, NFR Packaging).
3
+ *
4
+ * `../../templates` is resolved from the compiled module's own URL, so the same code finds the
5
+ * assets from a development checkout (`src/packs/bundled.ts` → `packages/cli/templates`), from
6
+ * `dist/packs/bundled.js` after `npm run build`, and from a global install
7
+ * (`…/lib/node_modules/@thaodangspace/argos/dist/packs/bundled.js`). Nothing here spawns a process
8
+ * or reads the network.
9
+ *
10
+ * A tarball built before `templates` was added to `files` would install nothing; that is a broken
11
+ * installation, not an operator error, so it fails loudly instead of reporting "0 packs".
12
+ */
13
+ /** `<cli package root>/templates` — beside `dist/` and `src/`, in both layouts. */
14
+ export declare const BUNDLED_TEMPLATES_DIR: string;
15
+ /** The bundled assets are not where the tarball says they should be. */
16
+ export declare class PackAssetsError extends Error {
17
+ readonly name = "PackAssetsError";
18
+ }
19
+ export interface BundledPacks {
20
+ /** The directory that holds one subdirectory per pack. */
21
+ readonly dir: string;
22
+ /** Pack directory names, sorted, so an install without arguments is deterministic. */
23
+ readonly names: readonly string[];
24
+ }
25
+ /** The bundled pack directory and its pack names; `dir` is injectable for tests. */
26
+ export declare function bundledPacks(dir?: string): BundledPacks;
27
+ //# sourceMappingURL=bundled.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundled.d.ts","sourceRoot":"","sources":["../../src/packs/bundled.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH,mFAAmF;AACnF,eAAO,MAAM,qBAAqB,QAA6D,CAAC;AAEhG,wEAAwE;AACxE,qBAAa,eAAgB,SAAQ,KAAK;IACxC,SAAkB,IAAI,qBAAqB;CAC5C;AAED,MAAM,WAAW,YAAY;IAC3B,0DAA0D;IAC1D,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,sFAAsF;IACtF,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;CACnC;AAED,oFAAoF;AACpF,wBAAgB,YAAY,CAAC,GAAG,GAAE,MAA6C,GAAG,YAAY,CAqB7F"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * The packs that ship inside the CLI tarball (plan D8, NFR Packaging).
3
+ *
4
+ * `../../templates` is resolved from the compiled module's own URL, so the same code finds the
5
+ * assets from a development checkout (`src/packs/bundled.ts` → `packages/cli/templates`), from
6
+ * `dist/packs/bundled.js` after `npm run build`, and from a global install
7
+ * (`…/lib/node_modules/@thaodangspace/argos/dist/packs/bundled.js`). Nothing here spawns a process
8
+ * or reads the network.
9
+ *
10
+ * A tarball built before `templates` was added to `files` would install nothing; that is a broken
11
+ * installation, not an operator error, so it fails loudly instead of reporting "0 packs".
12
+ */
13
+ import { existsSync, readdirSync, statSync } from "node:fs";
14
+ import { join } from "node:path";
15
+ import { fileURLToPath } from "node:url";
16
+ /** `<cli package root>/templates` — beside `dist/` and `src/`, in both layouts. */
17
+ export const BUNDLED_TEMPLATES_DIR = fileURLToPath(new URL("../../templates", import.meta.url));
18
+ /** The bundled assets are not where the tarball says they should be. */
19
+ export class PackAssetsError extends Error {
20
+ name = "PackAssetsError";
21
+ }
22
+ /** The bundled pack directory and its pack names; `dir` is injectable for tests. */
23
+ export function bundledPacks(dir = join(BUNDLED_TEMPLATES_DIR, "packs")) {
24
+ let entries;
25
+ try {
26
+ entries = readdirSync(dir);
27
+ }
28
+ catch {
29
+ throw new PackAssetsError(`bundled hc template packs are missing at ${dir}; this installation is incomplete (reinstall @thaodangspace/argos)`);
30
+ }
31
+ const names = entries
32
+ .filter((entry) => {
33
+ const path = join(dir, entry);
34
+ return statSync(path).isDirectory() && existsSync(join(path, "pack.json"));
35
+ })
36
+ .sort();
37
+ if (names.length === 0) {
38
+ throw new PackAssetsError(`bundled hc template packs are missing at ${dir}; this installation is incomplete (reinstall @thaodangspace/argos)`);
39
+ }
40
+ return { dir, names };
41
+ }
42
+ //# sourceMappingURL=bundled.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundled.js","sourceRoot":"","sources":["../../src/packs/bundled.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,mFAAmF;AACnF,MAAM,CAAC,MAAM,qBAAqB,GAAG,aAAa,CAAC,IAAI,GAAG,CAAC,iBAAiB,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAEhG,wEAAwE;AACxE,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACtB,IAAI,GAAG,iBAAiB,CAAC;CAC5C;AASD,oFAAoF;AACpF,MAAM,UAAU,YAAY,CAAC,GAAG,GAAW,IAAI,CAAC,qBAAqB,EAAE,OAAO,CAAC;IAC7E,IAAI,OAAiB,CAAC;IACtB,IAAI,CAAC;QACH,OAAO,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,eAAe,CACvB,4CAA4C,GAAG,oEAAoE,CACpH,CAAC;IACJ,CAAC;IACD,MAAM,KAAK,GAAG,OAAO;SAClB,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;QAChB,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC9B,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC;IAC7E,CAAC,CAAC;SACD,IAAI,EAAE,CAAC;IACV,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,eAAe,CACvB,4CAA4C,GAAG,oEAAoE,CACpH,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;AACxB,CAAC"}
@@ -0,0 +1,142 @@
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 declare const PACK_NAME_RULE: RegExp;
17
+ /** The ownership marker's stable prefix. The whole line is `· argos-pack <name> <version>`. */
18
+ export declare const PACK_MARKER_PREFIX = "\u00B7 argos-pack";
19
+ /** One template a pack ships: its args, and the step budget authors should write. */
20
+ export declare const PackTemplateSchema: z.ZodObject<{
21
+ name: z.ZodString;
22
+ args: z.ZodString;
23
+ minStepTimeoutMs: z.ZodNumber;
24
+ description: z.ZodOptional<z.ZodString>;
25
+ }, z.core.$strict>;
26
+ export type PackTemplate = z.infer<typeof PackTemplateSchema>;
27
+ /** `pack.json`: strict, because an operator writes packs and a typo must not be a silent no-op. */
28
+ export declare const PackSchema: z.ZodObject<{
29
+ name: z.ZodString;
30
+ version: z.ZodNumber;
31
+ description: z.ZodOptional<z.ZodString>;
32
+ requires: z.ZodObject<{
33
+ node: z.ZodString;
34
+ hcProtocol: z.ZodNumber;
35
+ hc: z.ZodOptional<z.ZodString>;
36
+ claude: z.ZodOptional<z.ZodString>;
37
+ }, z.core.$strict>;
38
+ program: z.ZodObject<{
39
+ file: z.ZodString;
40
+ args: z.ZodOptional<z.ZodString>;
41
+ }, z.core.$strict>;
42
+ templates: z.ZodArray<z.ZodObject<{
43
+ name: z.ZodString;
44
+ args: z.ZodString;
45
+ minStepTimeoutMs: z.ZodNumber;
46
+ description: z.ZodOptional<z.ZodString>;
47
+ }, z.core.$strict>>;
48
+ }, z.core.$strict>;
49
+ export type Pack = z.infer<typeof PackSchema>;
50
+ /** One installed template: where its `.md` lives and the step budget the pack declared. */
51
+ export declare const PackManifestTemplateSchema: z.ZodObject<{
52
+ file: z.ZodString;
53
+ minStepTimeoutMs: z.ZodNumber;
54
+ }, z.core.$strict>;
55
+ export type PackManifestTemplate = z.infer<typeof PackManifestTemplateSchema>;
56
+ /**
57
+ * One installed pack. `program` is always the absolute destination path (the copy, or the symlink);
58
+ * a copied pack carries `programSha256`, a `--link`ed one carries `link` instead (FR11).
59
+ */
60
+ export declare const PackManifestPackSchema: z.ZodObject<{
61
+ version: z.ZodNumber;
62
+ source: z.ZodString;
63
+ program: z.ZodString;
64
+ programSha256: z.ZodOptional<z.ZodString>;
65
+ link: z.ZodOptional<z.ZodString>;
66
+ templates: z.ZodRecord<z.ZodString, z.ZodObject<{
67
+ file: z.ZodString;
68
+ minStepTimeoutMs: z.ZodNumber;
69
+ }, z.core.$strict>>;
70
+ }, z.core.$strict>;
71
+ export type PackManifestPack = z.infer<typeof PackManifestPackSchema>;
72
+ /** `$ARGOS_HOME/hc/packs.json` (D1). Argos-owned; hc never reads it, and it has no timestamps (D12). */
73
+ export declare const PackManifestSchema: z.ZodObject<{
74
+ version: z.ZodLiteral<1>;
75
+ packs: z.ZodRecord<z.ZodString, z.ZodObject<{
76
+ version: z.ZodNumber;
77
+ source: z.ZodString;
78
+ program: z.ZodString;
79
+ programSha256: z.ZodOptional<z.ZodString>;
80
+ link: z.ZodOptional<z.ZodString>;
81
+ templates: z.ZodRecord<z.ZodString, z.ZodObject<{
82
+ file: z.ZodString;
83
+ minStepTimeoutMs: z.ZodNumber;
84
+ }, z.core.$strict>>;
85
+ }, z.core.$strict>>;
86
+ }, z.core.$strict>;
87
+ export type PackManifest = z.infer<typeof PackManifestSchema>;
88
+ export declare function emptyManifest(): PackManifest;
89
+ /** Canonical bytes: two-space indent, insertion order, trailing LF. No timestamp, ever (D12). */
90
+ export declare function serializeManifest(manifest: PackManifest): string;
91
+ export interface PackIssue {
92
+ /** `<file>` or `<file>:<field path>`, so an operator knows exactly which line to edit. */
93
+ readonly path: string;
94
+ readonly message: string;
95
+ }
96
+ export type ParseResult<T> = {
97
+ readonly ok: true;
98
+ readonly value: T;
99
+ } | {
100
+ readonly ok: false;
101
+ readonly issues: readonly PackIssue[];
102
+ };
103
+ /** Validate `pack.json` text; an unknown key or a bad floor names the file and the field. */
104
+ export declare function parsePack(text: string, file: string): ParseResult<Pack>;
105
+ /** Validate a manifest document; a hand-edited row is refused, never merged. */
106
+ export declare function parseManifest(text: string, file: string): ParseResult<PackManifest>;
107
+ export interface PackIdentity {
108
+ readonly name: string;
109
+ readonly version: number;
110
+ }
111
+ /** `· argos-pack claude 1` — the one ownership signal a template file carries. */
112
+ export declare function packMarker(pack: PackIdentity): string;
113
+ /** The marker a description carries, or `undefined` when the file is not ours. */
114
+ export declare function markerOf(description: string | undefined): PackIdentity | undefined;
115
+ export interface RenderTemplateInput {
116
+ readonly name: string;
117
+ /** The author's sentence; the marker is appended by `renderTemplate`, never by a caller. */
118
+ readonly description: string;
119
+ readonly command: string;
120
+ /** When given, the description gains the ownership marker (FR2). */
121
+ readonly pack?: PackIdentity;
122
+ }
123
+ /**
124
+ * A generated template (FR2): frontmatter `name`/`description`/`command`, empty body — hc sends a
125
+ * template's body *with* the prompt, and our prompt is the whole task.
126
+ *
127
+ * `description` and `command` are written as YAML double-quoted scalars (JSON escaping is a YAML
128
+ * subset), so a path that contains a quote, a space, or a `#` cannot silently break the document.
129
+ */
130
+ export declare function renderTemplate(input: RenderTemplateInput): string;
131
+ export interface ParsedTemplate {
132
+ readonly name?: string;
133
+ readonly description?: string;
134
+ readonly command?: string;
135
+ /** Everything after the closing `---` (empty for a generated template). */
136
+ readonly body: string;
137
+ /** `· argos-pack <name> <version>` when the description carries our marker. */
138
+ readonly pack?: PackIdentity;
139
+ }
140
+ /** Parse a template's frontmatter. Never throws: a foreign file is data, not an error. */
141
+ export declare function parseTemplate(text: string): ParsedTemplate;
142
+ //# sourceMappingURL=pack.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pack.d.ts","sourceRoot":"","sources":["../../src/packs/pack.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,mFAAmF;AACnF,eAAO,MA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AAE,YAAY,CAAC;CAC9B;AAED,0FAA0F;AAC1F,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CA2B1D"}
@@ -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
+ }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C,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAChE,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,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,QA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