@mago-foundation/mago-ski 0.3.0 → 0.4.1

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 (54) hide show
  1. package/README.md +34 -10
  2. package/action.yml +21 -2
  3. package/dist/hosts/github/run.d.ts +9 -0
  4. package/dist/hosts/github/run.js +30 -16
  5. package/dist/hosts/pi/index.js +40 -18
  6. package/dist/src/admin.d.ts +2 -1
  7. package/dist/src/admin.js +3 -2
  8. package/dist/src/canonical-json.d.ts +6 -0
  9. package/dist/src/canonical-json.js +11 -0
  10. package/dist/src/cli.d.ts +13 -1
  11. package/dist/src/cli.js +426 -8
  12. package/dist/src/diff.d.ts +5 -0
  13. package/dist/src/diff.js +2 -1
  14. package/dist/src/dsse.js +2 -2
  15. package/dist/src/experimental/sigstore.d.ts +6 -0
  16. package/dist/src/experimental/sigstore.js +13 -5
  17. package/dist/src/gate/adapters/claude-code-settings.js +1 -1
  18. package/dist/src/gate/adapters/claude-code.js +1 -0
  19. package/dist/src/gate/adapters/codex-names.d.ts +1 -0
  20. package/dist/src/gate/adapters/codex-names.js +56 -0
  21. package/dist/src/gate/adapters/codex-requirements.d.ts +11 -0
  22. package/dist/src/gate/adapters/codex-requirements.js +56 -29
  23. package/dist/src/gate/adapters/codex.d.ts +3 -0
  24. package/dist/src/gate/adapters/codex.js +147 -20
  25. package/dist/src/gate/admin-client.d.ts +19 -0
  26. package/dist/src/gate/admin-client.js +62 -0
  27. package/dist/src/gate/generations.js +2 -0
  28. package/dist/src/gate/instance.d.ts +57 -0
  29. package/dist/src/gate/instance.js +97 -0
  30. package/dist/src/gate/proc.d.ts +6 -0
  31. package/dist/src/gate/proc.js +14 -3
  32. package/dist/src/gate/service.d.ts +13 -0
  33. package/dist/src/gate/service.js +344 -37
  34. package/dist/src/gate/setup.d.ts +210 -0
  35. package/dist/src/gate/setup.js +1038 -0
  36. package/dist/src/gate/trust-store.d.ts +14 -0
  37. package/dist/src/gate/trust-store.js +66 -0
  38. package/dist/src/index.d.ts +2 -1
  39. package/dist/src/index.js +3 -1
  40. package/dist/src/policy.d.ts +7 -0
  41. package/dist/src/policy.js +19 -2
  42. package/dist/src/recovery-admin.js +7 -4
  43. package/dist/src/root-events.d.ts +2 -0
  44. package/dist/src/root-events.js +61 -4
  45. package/dist/src/tree-digest.d.ts +6 -0
  46. package/dist/src/tree-digest.js +8 -0
  47. package/docs/hosts/adapter-interface.md +1 -1
  48. package/docs/hosts/claude-code.md +108 -0
  49. package/docs/hosts/codex.md +181 -0
  50. package/docs/spec/gui-admin-rack-v1.md +1 -1
  51. package/docs/spec/root-recovery-v1.md +3 -2
  52. package/docs/spec/trust-documents-v1.md +1 -1
  53. package/docs/threat-model.md +13 -1
  54. package/package.json +3 -1
@@ -0,0 +1,210 @@
1
+ import type { Mode } from '../policy.ts';
2
+ import { type AskAdmin } from './admin-client.ts';
3
+ import { type Host, type InstanceConfig } from './instance.ts';
4
+ /** What the hook may and the service must do within these limits (the values the live tests ran with). */
5
+ export declare const HOOK_TIMEOUT_SEC = 5;
6
+ export declare const SELF_DEADLINE_MS = 3000;
7
+ export declare const CLIENT_DEADLINE_MS = 1500;
8
+ export declare const CODEX_ENFORCE_NOTE = "Codex enforcement depends on organisation controls; read docs/hosts/codex.md before enabling enforce";
9
+ /**
10
+ * `target` itself and every parent folder up to and including `stopAt` must be owned by `uid`, a real folder (a parent) and
11
+ * not writable by group or others. Not recursive: use it for folders whose contents are checked elsewhere (the managed
12
+ * folder holds symlinks by design). Throws with the first bad path.
13
+ */
14
+ export declare function checkRootOwnedChain(target: string, uid: number, stopAt?: string): Promise<void>;
15
+ /**
16
+ * Whole-tree check (G4): every entry under `target` (a folder or a file), and every parent up to `stopAt`, is owned by `uid`
17
+ * and not writable by group or others. A symlink inside the tree is refused. Throws with the first bad path.
18
+ */
19
+ export declare function checkRootOwnedTree(target: string, uid: number, stopAt?: string): Promise<void>;
20
+ /**
21
+ * A host binary: a regular ELF executable (a script would allowlist its interpreter), root-owned along its whole chain.
22
+ * It is opened without following a link; the type and owner are checked on the descriptor, and only then are its first 4 bytes read.
23
+ */
24
+ export declare function checkHostExe(exe: string, uid: number, stopAt?: string): Promise<void>;
25
+ export interface Toolchain {
26
+ installRoot: string;
27
+ /** `<install>/dist/src/gate/adapters/<host>-hook.js` */
28
+ hookEntry: string;
29
+ cliPath: string;
30
+ nodePath: string;
31
+ envPath: string;
32
+ }
33
+ export interface Seams {
34
+ /** Root of everything the command reads and writes (`/` in production). */
35
+ base?: string;
36
+ /** The uid that must own everything (0 in production). */
37
+ rootUid?: number;
38
+ platform?: NodeJS.Platform;
39
+ /** Root of the installed package; default: found from this module's location. */
40
+ installRoot?: string;
41
+ /** The node that runs the hooks and the service; default `realpath(process.execPath)`. */
42
+ nodePath?: string;
43
+ envPath?: string;
44
+ /** false skips the node and env chain checks (tests: those live outside the temporary base). */
45
+ checkExec?: boolean;
46
+ }
47
+ export declare function resolveToolchain(host: Host, seams: Seams): Promise<Toolchain>;
48
+ /** The host's default binary: its name on root's own PATH (the invoking user's PATH is never consulted). */
49
+ export declare function defaultHostExe(host: Host): string;
50
+ export interface InitOptions extends Seams {
51
+ host: Host;
52
+ rootFingerprint: string;
53
+ mode?: Mode;
54
+ /** Absolute paths of the real host binaries; default: the host's binary on PATH. */
55
+ hostExes?: string[];
56
+ inbox?: string;
57
+ /** Tests: replaces the PATH lookup of the default host binary. */
58
+ resolveHostExe?: (host: Host) => string;
59
+ /** Codex: `--user-home DIR` (repeatable). Default: every home in `<base>/etc/passwd` with uid 1000 or above and a login shell. */
60
+ userHomes?: string[];
61
+ /** Codex: `--codex-home DIR` (repeatable), a non-default CODEX_HOME. */
62
+ codexHomes?: string[];
63
+ /** Codex: `--no-deny-read` leaves deny_read out of requirements.toml. */
64
+ noDenyRead?: boolean;
65
+ /** Codex: `--lock-user-skill-folders`, see planLock. */
66
+ lockUserSkillFolders?: boolean;
67
+ /** `--new-root`: the installed instance pins a different root and the administrator means to replace it (design gate-new-root.md N2). */
68
+ newRoot?: boolean;
69
+ /** Tests: sets the immutable attribute on a path (default `chattr +i`). A failure stops the command. */
70
+ chattr?: (target: string, via?: string) => Promise<void>;
71
+ /** Tests: reads the immutable attribute (default `lsattr -d`). */
72
+ isImmutable?: (target: string, via?: string) => Promise<boolean>;
73
+ now?: () => Date;
74
+ }
75
+ export type FileRole = 'instance' | 'hook' | 'unit' | 'dropin' | 'host' | 'managed-config' | 'manifest' | 'shared-manifest';
76
+ export interface PlannedFile {
77
+ path: string;
78
+ content: string;
79
+ mode: number;
80
+ role: FileRole;
81
+ }
82
+ export interface PlannedDir {
83
+ path: string;
84
+ mode: number;
85
+ }
86
+ /** Work on user homes that `gate init --host codex` does after the files are written (printed in the plan). */
87
+ export type PlannedAction = {
88
+ kind: 'move-system';
89
+ from: string;
90
+ to: string;
91
+ } | {
92
+ kind: 'lock';
93
+ home: string;
94
+ owner: {
95
+ uid: number;
96
+ gid: number;
97
+ } | undefined;
98
+ };
99
+ export interface InitPlan {
100
+ host: Host;
101
+ /** Codex: the homes and CODEX_HOMEs the profile covers (also in the hook config), and the roots deny_read lists. */
102
+ homes: CodexHomes;
103
+ denyRoots: string[];
104
+ actions: PlannedAction[];
105
+ mode: Mode;
106
+ /** The real host binaries the gate will allow (shown by `gate init`). */
107
+ hostExes: string[];
108
+ /** In write order: instance config, hook config, unit, drop-in, the host config, then the two manifests. */
109
+ files: PlannedFile[];
110
+ /** Leaf folders to create (parents first); missing parents are created `0755`. */
111
+ dirs: PlannedDir[];
112
+ /** Existing files that mago-ski did not write (not in either manifest). */
113
+ foreign: string[];
114
+ /** Refusals found while planning (untrusted install or host binary). `init` refuses to write while any remain. */
115
+ problems: string[];
116
+ /** True when a manifest of this host already exists (a re-run). */
117
+ rerun: boolean;
118
+ /** Set when this run moves the instance from one root to another (`--new-root`). */
119
+ rootChange?: {
120
+ from: string;
121
+ to: string;
122
+ };
123
+ next: string[];
124
+ }
125
+ export declare function unitText(tc: Pick<Toolchain, 'nodePath' | 'cliPath'>): string;
126
+ export declare function dropinText(cfg: Pick<InstanceConfig, 'managed_dir'>, stateRoot: string): string;
127
+ /** Hook config (G10): exactly these keys, plus Codex's two. */
128
+ export interface CodexHomes {
129
+ userHomes: string[];
130
+ codexHomes: string[];
131
+ }
132
+ export declare function hookConfigText(host: Host, cfg: InstanceConfig, homes?: CodexHomes): string;
133
+ /** The fixed user Skill roots the requirements file denies reads of (D3: the roots of every listed home and CODEX_HOME). */
134
+ export declare function codexDenyRoots(homes: CodexHomes): string[];
135
+ /** The host's own configuration file for this instance. */
136
+ export declare function hostConfigText(host: Host, mode: Mode, tc: Toolchain, hookConfigPath: string, denyRoots?: string[]): string;
137
+ export declare function instanceFromOptions(o: {
138
+ host: Host;
139
+ mode: Mode;
140
+ rootFingerprint: string;
141
+ hostExes: string[];
142
+ inbox?: string | undefined;
143
+ base?: string | undefined;
144
+ }): InstanceConfig;
145
+ /** Everything `gate init` would write and create. Reads the disk (existing files, manifests, the install's ownership); writes nothing. */
146
+ export declare function planInit(opts: InitOptions): Promise<InitPlan>;
147
+ export interface ApplyOptions {
148
+ force?: boolean;
149
+ base?: string;
150
+ rootUid?: number;
151
+ now?: () => Date;
152
+ chattr?: (target: string, via?: string) => Promise<void>;
153
+ isImmutable?: (target: string, via?: string) => Promise<boolean>;
154
+ }
155
+ export interface ApplyResult {
156
+ written: string[];
157
+ backups: {
158
+ from: string;
159
+ to: string;
160
+ }[];
161
+ dirs: string[];
162
+ movedSystem: {
163
+ from: string;
164
+ to: string;
165
+ }[];
166
+ locked: string[];
167
+ }
168
+ /**
169
+ * Writes the plan (G5, v3 decision 3, v4 items 2-3). First it refuses (problems, foreign files without `force`, any planned
170
+ * folder or ancestor not owned by root or writable by others), before any rename or write. Then each foreign file is hard-linked
171
+ * to `<path>.mago-ski-bak-<stamp>` (the original stays in place), the folders are made, and each file is written with an atomic
172
+ * rename that replaces the original in one step: the host never lacks a config file. After a failure, a backup is put back
173
+ * only over a path this run did not write, and the message lists what is new, what was restored and what stays as a backup.
174
+ */
175
+ export declare function applyInit(plan: InitPlan, opts?: ApplyOptions): Promise<ApplyResult>;
176
+ export type CheckResult = 'PASS' | 'FAIL' | 'SKIP' | 'WARN';
177
+ export interface DoctorCheck {
178
+ check: string;
179
+ result: CheckResult;
180
+ detail: string;
181
+ }
182
+ export interface DoctorOptions extends Seams {
183
+ /** The calling uid; default `process.getuid()`. Below root the service checks are skipped. */
184
+ uid?: number;
185
+ /** Admin client seam. */
186
+ ask?: AskAdmin;
187
+ /** Tests: replace the two kernel settings read for warnings. */
188
+ somaxconn?: () => Promise<number>;
189
+ procMounts?: () => Promise<string>;
190
+ /** Codex: the output of `codex --version` for a host binary (default: runs it). */
191
+ codexVersion?: (exe: string) => Promise<string>;
192
+ /** Codex: the immutable attribute of a path (default `lsattr -d`). */
193
+ isImmutable?: (target: string, via?: string) => Promise<boolean>;
194
+ /** Tests: smaller bounds for the scan of the listed homes. */
195
+ skillScanLimits?: SkillScanLimits;
196
+ }
197
+ /** Read-only checks, in the order of the design (v1 section 6, G6, G12). Never throws. */
198
+ export declare function doctor(host: Host, opts?: DoctorOptions): Promise<DoctorCheck[]>;
199
+ export interface SkillScanLimits {
200
+ dirs: number;
201
+ entries: number;
202
+ depth: number;
203
+ }
204
+ /**
205
+ * Looks for a SKILL.md (any case) under `root`, entering dot folders and following links. Bounded in folders, in entries (read
206
+ * one at a time: a folder is never loaded whole, and the queue never holds more than `dirs` folders) and in depth. `none` means
207
+ * every folder was read. When a bound is reached with folders left, or a folder cannot be read, the answer is `incomplete`:
208
+ * a SKILL.md may exist where the scan did not look, so the caller must not report a clean home.
209
+ */
210
+ export declare function scanForSkillFile(root: string, skip?: (rel: string) => boolean, limits?: SkillScanLimits): Promise<'found' | 'none' | 'incomplete'>;