@mago-foundation/mago-ski 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/README.md +54 -9
  2. package/action.yml +2 -2
  3. package/dist/hosts/github/run.d.ts +9 -1
  4. package/dist/hosts/github/run.js +64 -11
  5. package/dist/hosts/pi/index.d.ts +5 -3
  6. package/dist/hosts/pi/index.js +219 -14
  7. package/dist/src/admin.d.ts +140 -1
  8. package/dist/src/admin.js +328 -63
  9. package/dist/src/canonical-json.js +73 -28
  10. package/dist/src/certificate.js +23 -15
  11. package/dist/src/cli.js +590 -89
  12. package/dist/src/diff.d.ts +0 -4
  13. package/dist/src/diff.js +326 -70
  14. package/dist/src/dsse.d.ts +6 -4
  15. package/dist/src/dsse.js +22 -6
  16. package/dist/src/fs-safe.d.ts +32 -3
  17. package/dist/src/fs-safe.js +193 -31
  18. package/dist/src/gate/adapters/claude-code-hook.d.ts +1 -0
  19. package/dist/src/gate/adapters/claude-code-hook.js +4 -0
  20. package/dist/src/gate/adapters/claude-code-settings.d.ts +13 -0
  21. package/dist/src/gate/adapters/claude-code-settings.js +49 -0
  22. package/dist/src/gate/adapters/claude-code.d.ts +33 -0
  23. package/dist/src/gate/adapters/claude-code.js +193 -0
  24. package/dist/src/gate/adapters/client.d.ts +13 -0
  25. package/dist/src/gate/adapters/client.js +57 -0
  26. package/dist/src/gate/adapters/codex-hook.d.ts +1 -0
  27. package/dist/src/gate/adapters/codex-hook.js +5 -0
  28. package/dist/src/gate/adapters/codex-requirements.d.ts +19 -0
  29. package/dist/src/gate/adapters/codex-requirements.js +56 -0
  30. package/dist/src/gate/adapters/codex.d.ts +16 -0
  31. package/dist/src/gate/adapters/codex.js +574 -0
  32. package/dist/src/gate/adapters/hook-main.d.ts +7 -0
  33. package/dist/src/gate/adapters/hook-main.js +35 -0
  34. package/dist/src/gate/adapters/host-pid.d.ts +1 -0
  35. package/dist/src/gate/adapters/host-pid.js +20 -0
  36. package/dist/src/gate/admission.d.ts +54 -0
  37. package/dist/src/gate/admission.js +490 -0
  38. package/dist/src/gate/contract.d.ts +51 -0
  39. package/dist/src/gate/contract.js +94 -0
  40. package/dist/src/gate/decision-log.d.ts +38 -0
  41. package/dist/src/gate/decision-log.js +251 -0
  42. package/dist/src/gate/generations.d.ts +67 -0
  43. package/dist/src/gate/generations.js +518 -0
  44. package/dist/src/gate/proc.d.ts +31 -0
  45. package/dist/src/gate/proc.js +79 -0
  46. package/dist/src/gate/refresh.d.ts +11 -0
  47. package/dist/src/gate/refresh.js +30 -0
  48. package/dist/src/gate/run-verifier.d.ts +23 -0
  49. package/dist/src/gate/run-verifier.js +89 -0
  50. package/dist/src/gate/service.d.ts +80 -0
  51. package/dist/src/gate/service.js +722 -0
  52. package/dist/src/gate/strict-json.d.ts +11 -0
  53. package/dist/src/gate/strict-json.js +190 -0
  54. package/dist/src/gate/trust-store.d.ts +36 -0
  55. package/dist/src/gate/trust-store.js +251 -0
  56. package/dist/src/gate/verifier-worker.d.ts +8 -0
  57. package/dist/src/gate/verifier-worker.js +66 -0
  58. package/dist/src/index.d.ts +2 -0
  59. package/dist/src/index.js +2 -0
  60. package/dist/src/keys.d.ts +4 -0
  61. package/dist/src/keys.js +85 -30
  62. package/dist/src/main-module.js +1 -1
  63. package/dist/src/names.js +2 -4
  64. package/dist/src/policy.d.ts +173 -6
  65. package/dist/src/policy.js +685 -54
  66. package/dist/src/recovery-admin.d.ts +173 -0
  67. package/dist/src/recovery-admin.js +400 -0
  68. package/dist/src/revocations.js +3 -1
  69. package/dist/src/root-events.d.ts +107 -0
  70. package/dist/src/root-events.js +376 -0
  71. package/dist/src/time.d.ts +19 -3
  72. package/dist/src/time.js +50 -8
  73. package/dist/src/timestamp.d.ts +61 -0
  74. package/dist/src/timestamp.js +107 -0
  75. package/dist/src/tree-digest.d.ts +4 -0
  76. package/dist/src/tree-digest.js +41 -16
  77. package/dist/src/trust-root.d.ts +5 -0
  78. package/dist/src/trust-root.js +34 -13
  79. package/dist/src/verify.d.ts +69 -13
  80. package/dist/src/verify.js +309 -61
  81. package/docs/hosts/adapter-interface.md +8 -2
  82. package/docs/hosts/github-action.md +3 -3
  83. package/docs/hosts/pi.md +10 -3
  84. package/docs/spec/gui-admin-rack-v1.md +289 -0
  85. package/docs/spec/root-recovery-v1.md +451 -0
  86. package/docs/spec/skill-certificate-v1.md +1 -1
  87. package/docs/spec/skill-tree-v2.md +2 -2
  88. package/docs/spec/trust-documents-v1.md +12 -6
  89. package/docs/spec/verification.md +20 -3
  90. package/docs/threat-model.md +9 -6
  91. package/package.json +49 -44
@@ -0,0 +1,5 @@
1
+ // Entry point of the Codex hook: `env -i node --no-addons codex-hook.js <config.json> <enforce|shadow>`.
2
+ // The config, socket directory and socket must be root-owned; see codex.ts.
3
+ import { runHook } from "./codex.js";
4
+ import { hookMain } from "./hook-main.js";
5
+ await hookMain(process.argv.slice(2, 4), {}, runHook);
@@ -0,0 +1,19 @@
1
+ import type { Mode } from '../../policy.ts';
2
+ export interface CodexRequirementsInput {
3
+ mode: Mode;
4
+ nodePath: string;
5
+ hookEntry: string;
6
+ configPath: string;
7
+ hookTimeoutSec: number;
8
+ /** Must match the hook config's self_deadline_ms; the host timeout has to outlast it by at least 1 s. */
9
+ selfDeadlineMs: number;
10
+ envPath?: string;
11
+ /**
12
+ * Absolute fixed user Skill roots, supplied by the installer, per user: <home>/.codex/skills, <home>/.codex/skills/.system
13
+ * (bundled system Skills) and <home>/.agents/skills (the generator reads no env, so it cannot find $CODEX_HOME). These feed
14
+ * only deny_read; the adapter derives its own scan roots from the host's environment, so listing them in the adapter
15
+ * config's `skill_roots` is optional.
16
+ */
17
+ userSkillRoots: string[];
18
+ }
19
+ export declare function codexRequirementsToml(input: CodexRequirementsInput): string;
@@ -0,0 +1,56 @@
1
+ // Generator of /etc/codex/requirements.toml for the Codex hook adapter. Pure: no file access.
2
+ // EVIDENCE: every setting marked [cx0.1]/[cx0.2] was exercised on codex-cli 0.163.0 / Linux (.agent/reviews/
3
+ // cx0.1-codex-surface-spike.md and its cx0.2 addendum, cx0.1-fixtures/evidence.txt, cx0.2-evidence.txt). Unverified for
4
+ // other Codex versions; not a broad host-level guarantee.
5
+ //
6
+ // KNOWN GAPS (also written into the generated header):
7
+ // * Repo-scope Skills (<repo>/.codex/skills, .agents/skills) cannot be hidden natively: hook-only, best-effort,
8
+ // audit-level. Codex hooks also fail OPEN on crash/timeout, so the hook is not a lock; the lock is deny_read plus
9
+ // uninstall-on-revoke.
10
+ // * deny_read does NOT hide the user roots from Codex's Skill catalog: in the live test (codex-cli 0.163.0 and 0.166.0,
11
+ // as root and as an unprivileged user with bwrap; docs/spikes/codex-gate-live.md) a Skill under a denied root was
12
+ // still listed with its path. Using it is blocked by the hook only, so the user route is hook-only like the repo route.
13
+ // * deny_read works only for the fixed absolute roots listed in `userSkillRoots` (not for ** or /home/* globs, cx0.2).
14
+ // * Codex's sandbox needs unprivileged user namespaces, so the max_user_namespaces=0 hardening used for Claude Code
15
+ // breaks Codex (cx0.2: bwrap ENOSPC). Packet 10 resolves this.
16
+ // * The hook adapter finds the employee's user roots itself from the host's CODEX_HOME/HOME (read from /proc/<host pid>/
17
+ // environ); the roots below only feed the native deny_read. The adapter scans every cwd ancestor for repo roots.
18
+ // * Not gateable by the UserPromptSubmit hook: structured Skill selection (UserInput::Skill, skill:// mentions from
19
+ // non-TUI clients or the app-server API) and app-server `skills/extraRoots/set`. Endpoint requirement: restrict
20
+ // app-server and non-TUI Codex clients. A token split across text items can differ from what the hook sees; the
21
+ // PreToolUse shell check is best-effort. In enforce, Codex coverage is weaker than Claude Code; the live test confirmed
22
+ // that the repo and user routes are audit-level.
23
+ // * Startup state: Codex fixes HOME, CODEX_HOME and ~/.codex/.env at startup; the hook sees only the current state, so
24
+ // an employee can start Codex pointed at other Skills and undo it (accepted limit; needs an admin-owned CODEX_HOME).
25
+ import path from 'node:path';
26
+ const SAFE_PATH = /^\/[A-Za-z0-9._/-]+$/u; // also valid inside a TOML basic string and a shell command: nothing to escape
27
+ const q = (s) => `"${s}"`;
28
+ export function codexRequirementsToml(input) {
29
+ const { mode, nodePath, hookEntry, configPath, hookTimeoutSec, selfDeadlineMs, userSkillRoots } = input;
30
+ const envPath = input.envPath ?? '/usr/bin/env';
31
+ for (const p of [envPath, nodePath, hookEntry, configPath, ...userSkillRoots])
32
+ if (!path.isAbsolute(p) || !SAFE_PATH.test(p) || p.endsWith('/'))
33
+ throw new Error('paths must be absolute, shell-safe and without a trailing slash');
34
+ if (mode !== 'enforce' && mode !== 'shadow')
35
+ throw new Error('mode must be enforce or shadow');
36
+ if (!Number.isInteger(hookTimeoutSec) || hookTimeoutSec < 1 || hookTimeoutSec > 600)
37
+ throw new Error('hookTimeoutSec must be an integer in 1..600');
38
+ if (!Number.isInteger(selfDeadlineMs) || selfDeadlineMs < 1 || hookTimeoutSec * 1000 < selfDeadlineMs + 1000)
39
+ throw new Error('hookTimeoutSec * 1000 must be at least selfDeadlineMs + 1000');
40
+ const command = q(`${envPath} -i ${nodePath} --no-addons ${hookEntry} ${configPath} ${mode}`); // env -i: no NODE_OPTIONS etc.
41
+ const lines = [
42
+ '# mago-ski Codex requirements (generated). Evidence: codex-cli 0.163.0 / Linux only; unverified for other versions.',
43
+ '# Known gaps: repo-scope Skills cannot be hidden in Codex (hook-only, best-effort, audit-level); deny_read covers only',
44
+ '# the fixed roots listed below; hooks fail OPEN on crash/timeout; Codex sandboxing needs unprivileged user namespaces,',
45
+ '# so max_user_namespaces=0 (used for Claude Code) breaks it.',
46
+ ];
47
+ if (mode === 'enforce') {
48
+ lines.push('# [cx0.1] managed hooks only: user/repo/project hooks are ignored.', 'allow_managed_hooks_only = true', '# [cx0.2] keeps the sandbox on; no danger-full-access.', 'allowed_sandbox_modes = ["read-only", "workspace-write"]', '', '# [cx0.2] feature pins: hooks on; plugins, remote plugins and apps off.', '[features]', 'hooks = true', 'plugins = false', 'remote_plugin = false', 'apps = false');
49
+ if (userSkillRoots.length > 0)
50
+ lines.push('', '# [cx0.2] meant to block sandboxed reads of these fixed user roots. It does NOT hide them from the Skill catalog', '# (live test, codex-cli 0.163.0 and 0.166.0); their use is blocked by the hooks only.', '[permissions.filesystem]', `deny_read = [${userSkillRoots.map((r) => q(`${r}/**`)).join(', ')}]`);
51
+ }
52
+ lines.push('', '# [cx0.1] managed hooks; Codex needs managed_dir (without it the hooks are ignored).', '[hooks]', `managed_dir = ${q(path.dirname(hookEntry))}`);
53
+ for (const [event, matcher] of [['SessionStart', false], ['UserPromptSubmit', false], ['PreToolUse', true]])
54
+ lines.push('', `[[hooks.${event}]]`, ...(matcher ? ['matcher = "*"'] : []), `[[hooks.${event}.hooks]]`, 'type = "command"', `command = ${command}`, `timeout = ${hookTimeoutSec}`);
55
+ return `${lines.join('\n')}\n`;
56
+ }
@@ -0,0 +1,16 @@
1
+ import { type HookDeps, type HookOutcome } from './claude-code.ts';
2
+ export declare const DEFAULT_ADMIN_ROOT = "/etc/codex/skills";
3
+ export declare function extractMentions(text: string, links?: string[], plain?: Set<string>, linkNames?: string[]): Set<string>;
4
+ /** What the adapter learns of the host's environment (values are never logged). */
5
+ export interface HostEnv {
6
+ codexHome?: string;
7
+ home?: string;
8
+ }
9
+ /** Reads CODEX_HOME and HOME from /proc/<pid>/environ (first occurrence, as getenv). Throws on any problem. */
10
+ export declare function readProcEnviron(pid: number): Promise<HostEnv>;
11
+ /** Codex adapter dependencies: the shared hook ones plus a reader of the host's environment (tests inject it). */
12
+ export interface CodexDeps extends HookDeps {
13
+ readHostEnv?: (pid: number) => Promise<HostEnv>;
14
+ }
15
+ /** Never throws and never outlives the self-deadline. */
16
+ export declare function runHook(argv: readonly string[], deps: CodexDeps): Promise<HookOutcome>;