@mago-foundation/mago-ski 0.0.0-stage → 0.1.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 (55) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +4 -0
  3. package/README.md +121 -2
  4. package/action.yml +58 -0
  5. package/dist/hosts/github/run.d.ts +21 -0
  6. package/dist/hosts/github/run.js +119 -0
  7. package/dist/hosts/pi/index.d.ts +11 -0
  8. package/dist/hosts/pi/index.js +388 -0
  9. package/dist/hosts/pi/paths.d.ts +9 -0
  10. package/dist/hosts/pi/paths.js +55 -0
  11. package/dist/src/admin.d.ts +70 -0
  12. package/dist/src/admin.js +115 -0
  13. package/dist/src/canonical-json.d.ts +12 -0
  14. package/dist/src/canonical-json.js +104 -0
  15. package/dist/src/certificate.d.ts +34 -0
  16. package/dist/src/certificate.js +104 -0
  17. package/dist/src/cli.d.ts +2 -0
  18. package/dist/src/cli.js +419 -0
  19. package/dist/src/diff.d.ts +30 -0
  20. package/dist/src/diff.js +148 -0
  21. package/dist/src/dsse.d.ts +23 -0
  22. package/dist/src/dsse.js +55 -0
  23. package/dist/src/experimental/sigstore.d.ts +26 -0
  24. package/dist/src/experimental/sigstore.js +153 -0
  25. package/dist/src/fs-safe.d.ts +11 -0
  26. package/dist/src/fs-safe.js +96 -0
  27. package/dist/src/index.d.ts +14 -0
  28. package/dist/src/index.js +14 -0
  29. package/dist/src/keys.d.ts +21 -0
  30. package/dist/src/keys.js +108 -0
  31. package/dist/src/main-module.d.ts +5 -0
  32. package/dist/src/main-module.js +19 -0
  33. package/dist/src/names.d.ts +7 -0
  34. package/dist/src/names.js +40 -0
  35. package/dist/src/policy.d.ts +59 -0
  36. package/dist/src/policy.js +237 -0
  37. package/dist/src/revocations.d.ts +28 -0
  38. package/dist/src/revocations.js +91 -0
  39. package/dist/src/time.d.ts +9 -0
  40. package/dist/src/time.js +32 -0
  41. package/dist/src/tree-digest.d.ts +43 -0
  42. package/dist/src/tree-digest.js +243 -0
  43. package/dist/src/trust-root.d.ts +33 -0
  44. package/dist/src/trust-root.js +115 -0
  45. package/dist/src/verify.d.ts +73 -0
  46. package/dist/src/verify.js +134 -0
  47. package/docs/hosts/adapter-interface.md +33 -0
  48. package/docs/hosts/github-action.md +45 -0
  49. package/docs/hosts/pi.md +36 -0
  50. package/docs/spec/skill-certificate-v1.md +60 -0
  51. package/docs/spec/skill-tree-v2.md +59 -0
  52. package/docs/spec/trust-documents-v1.md +103 -0
  53. package/docs/spec/verification.md +46 -0
  54. package/docs/threat-model.md +44 -0
  55. package/package.json +74 -4
@@ -0,0 +1,33 @@
1
+ # Host adapter interface
2
+
3
+ What a coding-agent host must let mago-ski do, so that Claude Code, Cursor and others can be added the way Pi was. The library calls are the same for every host; only the hook points differ.
4
+
5
+ ## Required hook points
6
+
7
+ | # | Hook | Why | Pi 1.0.4 |
8
+ |---|---|---|---|
9
+ | H1 | **Change the Skill list before the model sees it**, with each Skill's name and directory | Unverified Skills must not be advertised | `before_agent_start` → `systemPromptOptions.skills` |
10
+ | H2 | **Intercept explicit Skill invocation before expansion**, and supply the expanded text | Stop unverified loads; expand verified Skills from verified bytes | `input` event (`handled` / `transform`) |
11
+ | H3 | **Block or allow file tool calls**, with the target path | Refuse unverified files; re-hash verified ones on read | `tool_call` (`block`) |
12
+ | H4 | **Block or allow shell commands**, with the command text | Best-effort coverage of scripts | `tool_call` for `bash` |
13
+ | H5 | **Report to the user** (notification, status) | Explain blocks and how to fix them | `ctx.ui.notify`, `ctx.ui.setStatus` |
14
+ | H6 | **Load configuration from a user- or admin-controlled location** | Policy must not come from the code under review | Extension reads `~/.mago-ski/policy.json` |
15
+
16
+ A host that lacks H1 or H2 can fall back to a **verified-install store**: copy verified Skills into a content-addressed directory and point the host's Skill path only there.
17
+
18
+ ## Library calls
19
+
20
+ ```ts
21
+ import { loadPolicy, loadPolicyTrust, verifyWithPolicy, hashFile, appendDecision, decisionRecord } from 'mago-ski';
22
+
23
+ const policy = await loadPolicy(policyPath);
24
+ const trust = await loadPolicyTrust(policy, new Date()); // once per run; enforces rollback state
25
+ const result = await verifyWithPolicy(policy, skillDir, { now: new Date(), skillName, context: trust.ok ? trust.context : undefined });
26
+ // result.verdict, result.reason, result.files (per-file hashes when VERIFIED)
27
+ const current = await hashFile(absolutePath, relativePath); // compare with result.files on read
28
+ await appendDecision(policy.decisionLogPath, decisionRecord(result, policy.mode, 'advertise'));
29
+ ```
30
+
31
+ ## Claude Code (planned)
32
+
33
+ Claude Code hooks (`PreToolUse`, `UserPromptSubmit`) cover H2–H5. Whether H1 is possible (removing a Skill from what the model is told) needs the same spike Pi had; if not, the verified-install store applies.
@@ -0,0 +1,45 @@
1
+ # GitHub Action
2
+
3
+ In enforce mode, fails the check when a Skill found under the policy's `skill_dirs` is not covered by a valid certificate for its exact bytes.
4
+
5
+ ```yaml
6
+ # .github/workflows/skills.yml
7
+ name: skills
8
+ on: [pull_request]
9
+ permissions:
10
+ contents: read
11
+ jobs:
12
+ verify:
13
+ runs-on: ubuntu-24.04
14
+ steps:
15
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
16
+ with:
17
+ persist-credentials: false
18
+ - uses: mago-foundation/mago-ski@<full commit sha>
19
+ with:
20
+ policy: .mago-ski/policy.json
21
+ ```
22
+
23
+ Use a Linux or macOS runner; the action stops on Windows runners (not supported in 0.1). Pin the action to a full commit SHA: the verifier runs from the action's own checkout, so the pin decides which verifier code runs.
24
+
25
+ ## Repository layout
26
+
27
+ ```
28
+ .mago-ski/
29
+ policy.json # mode, root_fingerprint, trust_root, revocations, skill_dirs, certificate_dirs
30
+ trust-root.json
31
+ revocations.json
32
+ certs/ # optional: <skill-name>.cert.json
33
+ skills/
34
+ pdf-tools/
35
+ SKILL.md
36
+ .mago-ski-cert.json # or keep certificates in .mago-ski/certs/
37
+ ```
38
+
39
+ On pull requests, `policy.json`, `trust-root.json` and `revocations.json` are read from the **base** revision. A pull request can add or update certificates (they are signed), but changes it makes to the trust documents take effect only after merge, so a pull request cannot add its own approver. Certificate directories and Skill directories are read from the pull request.
40
+
41
+ Symlinked Skill directories and symlinked `SKILL.md` files are reported as `UNVERIFIABLE`, not skipped (Pi follows such links). Discovery searches up to 16 directory levels below each `skill_dirs` entry. Anything deeper is reported as `UNVERIFIABLE` instead of being skipped: it fails the check in `enforce` mode and is reported in `shadow` mode. Policy, trust and Skill directories must resolve inside their checkout.
42
+
43
+ The action writes a summary table to the job summary and an annotation on each failing Skill's `SKILL.md`. In `shadow` mode it reports but does not fail. CI keeps no state file; rollback protection comes from reading trust documents from the protected base revision.
44
+
45
+ Run it alongside a capability scanner such as SkilLock: the scanner explains what changed, mago-ski makes sure someone approved exactly that.
@@ -0,0 +1,36 @@
1
+ # Pi host
2
+
3
+ The Pi extension (`hosts/pi/index.ts`) enforces certificates inside a normal [Pi](https://github.com/earendil-works/pi) session. Tested with Pi 1.0.4 and 1.1.0.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pi install npm:@mago-foundation/mago-ski@0.1.0 # or for one session: pi -e npm:@mago-foundation/mago-ski@0.1.0
9
+ mkdir -p ~/.mago-ski
10
+ cp policy.json trust-root.json revocations.json ~/.mago-ski/
11
+ ```
12
+
13
+ The extension reads its policy from `MAGO_SKI_POLICY` or `~/.mago-ski/policy.json`. It never reads policy from the project directory, because project files may be controlled by the code under review. Without a policy it warns once and checks nothing. If a policy exists but cannot be loaded, it blocks every Skill.
14
+
15
+ Start in `"mode": "shadow"` to see what would be blocked (the decision log records `would-block`), then switch to `"enforce"`.
16
+
17
+ ## What it does
18
+
19
+ | Pi event | Enforce mode | Shadow mode |
20
+ |---|---|---|
21
+ | Before each run (`before_agent_start`) | Verifies every discovered Skill; only `VERIFIED` Skills stay in the list sent to the model. Status bar: `mago-ski enforce: 3/4 Skills verified` | Same check, nothing removed |
22
+ | `/skill:name` (`input`) | Verified: re-verified and expanded from the verified bytes, so Pi never re-reads the file. Unverified: refused, the model is not called. Not seen yet in this session: rewritten into a plain request, so Pi does not expand it unchecked | Allowed |
23
+ | `read`, `find`, `ls`, `edit`, `write` (`tool_call`) | Refused for paths in unverified Skills. Paths are resolved the way Pi's tools resolve them (a leading `@`, `file://` URLs, `~`, Unicode spaces, Windows shell paths, and the filename variants `read` tries), and matched both before and after resolving symlinks. Reads from verified Skills are re-hashed against the certificate; changed files, files not in the certificate, and paths that leave the Skill through a link are refused. Edits to verified Skills are refused. `find` and `ls` of verified Skills are allowed (names only) | Logged |
24
+ | `grep` | Refused when it searches in or over an unverified Skill, or a verified Skill that has files excluded from its certificate (`.git`, ignored files, or an in-tree `.mago-ski-cert.json` that is not the certificate that verified the Skill). Otherwise the Skill is re-verified first and its exclusions checked again | Logged |
25
+ | `bash`, `powershell` | Refused when the command names an unverified Skill's directory; verified Skills it names are re-verified first. Best-effort (see the [threat model](../threat-model.md)) | Logged |
26
+ | Verification error | A Skill that cannot be checked is `UNVERIFIABLE`. If checking crashes outright, no Skills are advertised and file and shell tools touching any Skill path are blocked for that run | Logged |
27
+
28
+ When a verdict changes, it is written to the policy's `decision_log` (if configured and writable) with the event, verdict and reason. Verdicts other than `VERIFIED` are also shown as a notification when Pi has a UI.
29
+
30
+ ## Limits
31
+
32
+ - Linux and macOS only in 0.1. On Windows the extension shows a warning: executable bits are not covered, so Skills approved elsewhere may not verify.
33
+ - Standalone Markdown Skills (a `.md` file without its own directory and `SKILL.md`) cannot be certified and are always unverified.
34
+ - Pi runs extensions in load order; another extension can change the Skill list after mago-ski. Load mago-ski last.
35
+ - Custom tools and MCP tools that read files are not checked.
36
+ - Path matching mirrors Pi 1.1's tool path resolution (`hosts/pi/paths.ts`). A future Pi version that resolves paths differently needs a matching update; the Pi host tests pin the Pi version.
@@ -0,0 +1,60 @@
1
+ # Skill certificate v1
2
+
3
+ Status: draft, implemented by mago-ski 0.1. This page's URL is the certificate's `predicateType`. Test vectors: [`tests/vectors/certificates/`](../../tests/vectors/certificates/).
4
+
5
+ A Skill certificate records that an approver approved one exact version of one Skill until a stated time. It does **not** state that the Skill is safe.
6
+
7
+ ## Envelope
8
+
9
+ A [DSSE](https://github.com/secure-systems-lab/dsse/blob/master/protocol.md) envelope, serialized as canonical JSON (sorted keys, no whitespace, one trailing LF):
10
+
11
+ ```json
12
+ {"payload":"<base64>","payloadType":"application/vnd.in-toto+json","signatures":[{"keyid":"sha256:<hex>","sig":"<base64>"}]}
13
+ ```
14
+
15
+ - Exactly one signature, Ed25519 over the DSSE pre-authentication encoding `DSSEv1 <len(type)> <type> <len(payload)> <payload>`.
16
+ - `keyid` is `sha256:` + hex SHA-256 of the signer's DER SubjectPublicKeyInfo.
17
+
18
+ ## Payload: in-toto Statement v1
19
+
20
+ The payload is canonical JSON:
21
+
22
+ ```json
23
+ {
24
+ "_type": "https://in-toto.io/Statement/v1",
25
+ "subject": [{ "name": "pdf-tools", "digest": { "magoSkillTreeV2": "<64 hex>" } }],
26
+ "predicateType": "https://github.com/mago-foundation/mago-ski/blob/main/docs/spec/skill-certificate-v1.md",
27
+ "predicate": {
28
+ "tree_profile": "mago.skill-tree/v2",
29
+ "files": [{ "path": "SKILL.md", "size": 412, "sha256": "<64 hex>", "exec": false }],
30
+ "approval": {
31
+ "approver_key_id": "sha256:<hex>",
32
+ "issued_at": "2026-10-09T12:00:00Z",
33
+ "expires_at": "2027-01-07T12:00:00Z",
34
+ "reason": "Reviewed scripts and network use"
35
+ },
36
+ "previous_digest": "sha256:<hex>"
37
+ }
38
+ }
39
+ ```
40
+
41
+ | Field | Rule |
42
+ |---|---|
43
+ | `subject` | Exactly one. `name`: 1–128 ASCII letters, digits, `.`, `_`, `-`, starting with a letter or digit. `digest.magoSkillTreeV2`: the [tree digest](skill-tree-v2.md) without the `sha256:` prefix |
44
+ | `files` | The per-file records of the tree, sorted as in the digest. Must include `SKILL.md`. Their digest must equal the subject digest |
45
+ | `approver_key_id` | Must equal the envelope's `keyid` |
46
+ | `issued_at`, `expires_at` | UTC, second precision, `YYYY-MM-DDTHH:MM:SSZ`; `expires_at` after `issued_at` |
47
+ | `reason` | Free text, 1–1024 characters, no control characters |
48
+ | `previous_digest` | The previously approved digest of this Skill, or `null`. Informational: it forms a readable update history, it does not grant anything |
49
+
50
+ No other fields are allowed anywhere. Unknown fields make the certificate unverifiable.
51
+
52
+ ## Where certificates live
53
+
54
+ A host looks for certificates for Skill `NAME`, in this order:
55
+
56
+ 1. a file named explicitly by the caller;
57
+ 2. `<certificate_dir>/NAME.cert.json` for each `certificate_dirs` entry in the policy (for Skills the organization does not modify);
58
+ 3. `.mago-ski-cert.json` in the Skill root (excluded from the tree digest).
59
+
60
+ If any candidate verifies, the Skill is verified. Otherwise the most specific failure is reported (see [verification](verification.md)).
@@ -0,0 +1,59 @@
1
+ # Skill tree digest: `mago.skill-tree/v2`
2
+
3
+ Status: draft, implemented by mago-ski 0.1. Test vectors: [`tests/vectors/trees.json`](../../tests/vectors/trees.json).
4
+
5
+ The tree digest identifies the exact contents of a Skill directory. A certificate approves one tree digest.
6
+
7
+ ## Which files are covered
8
+
9
+ Start at the Skill root (the directory that holds `SKILL.md`) and walk it recursively.
10
+
11
+ - Every regular file is covered, except:
12
+ - the entry named `.git` at the root (file or directory);
13
+ - the file `.mago-ski-cert.json` at the root (the in-tree certificate);
14
+ - paths listed in `.skilldigestignore` at the root (below).
15
+ - `.skilldigestignore` itself is covered when present.
16
+ - `SKILL.md` at the root is required and always covered. A tree without it is not a Skill and has no digest.
17
+ - These make the whole tree **unverifiable** (the digest is not computed):
18
+ - symbolic links, sockets, FIFOs, devices;
19
+ - a path component that is not valid UTF-8, is not in Unicode NFC, is empty, `.` or `..`, contains `/`, `\`, `:` or a control character, ends with a dot or space, or is a reserved Windows device name;
20
+ - two paths that are equal after NFKC normalization and lowercasing (they would collide on case-insensitive file systems);
21
+ - more than 20,000 files, 50,000 entries, depth 64, 64 MiB per file, 256 MiB total, or 4,096 bytes per relative path;
22
+ - a file that changes while it is being read.
23
+ - Empty directories and other metadata (owner, timestamps, permissions other than the executable bit) are not covered.
24
+
25
+ ## `.skilldigestignore`
26
+
27
+ UTF-8 text, at most 64 KiB and 256 patterns. Blank lines and lines starting with `#` are skipped. Each other line is one relative POSIX path:
28
+
29
+ - `name/` excludes the directory `name` and everything under it;
30
+ - `name` excludes a file or directory with that exact relative path.
31
+
32
+ Globs (`* ? [ ] !`), absolute paths, `.` or `..` segments, backslashes, the ignore file itself and `SKILL.md` are rejected.
33
+
34
+ Excluded files are not approved. Hosts must not serve them as Skill content: the Pi host refuses to read any file inside a verified Skill that is not in the certificate's file list.
35
+
36
+ ## Per-file record
37
+
38
+ For each covered file:
39
+
40
+ | Field | Value |
41
+ |---|---|
42
+ | `path` | Relative path, `/`-separated, UTF-8, NFC |
43
+ | `size` | Byte length |
44
+ | `sha256` | Lowercase hex SHA-256 of the raw bytes (no line-ending normalization) |
45
+ | `exec` | `true` if any POSIX execute bit (`0o111`) is set. Always `false` on Windows, which has no mode bits |
46
+
47
+ ## Digest
48
+
49
+ 1. Sort records by the UTF-8 bytes of `path` (byte order, not locale order).
50
+ 2. Build `{"files": [...records], "profile": "mago.skill-tree/v2"}`.
51
+ 3. Serialize as canonical JSON: object keys sorted, no whitespace, integers only, one trailing LF.
52
+ 4. The digest is `sha256:` followed by the lowercase hex SHA-256 of those bytes.
53
+
54
+ Because the digest is computed from the record list, anyone holding a certificate's file list can recompute and check its digest, and a host can verify a single file by comparing its hash with one record.
55
+
56
+ ## Known limitations
57
+
58
+ - On Windows the executable bit is always `false`, so a Skill approved on Linux or macOS with an executable script will not verify on Windows. mago-ski 0.1 does not support Windows for this reason.
59
+ - Some file systems report every file as executable (for example WSL's DrvFs mounts of Windows drives). Digest Skills on a native Linux or macOS file system.
@@ -0,0 +1,103 @@
1
+ # Trust documents v1
2
+
3
+ Status: draft, implemented by mago-ski 0.1. Test vectors: [`tests/vectors/`](../../tests/vectors/).
4
+
5
+ An organization's trust is anchored in one **root key**, kept offline. Hosts pin the root key's fingerprint (its key id). The root signs two documents: the trust root (who may approve what) and the revocation list (what is no longer trusted). Both are DSSE envelopes signed by the root key, in the same envelope format as [certificates](skill-certificate-v1.md), with canonical JSON payloads.
6
+
7
+ ## Trust root
8
+
9
+ `payloadType`: `application/vnd.mago-ski.trust-root+json`
10
+
11
+ ```json
12
+ {
13
+ "type": "mago.trust-root/v1",
14
+ "version": 3,
15
+ "issued_at": "2026-10-09T12:00:00Z",
16
+ "expires_at": "2027-10-09T12:00:00Z",
17
+ "root": { "key_id": "sha256:<hex>", "public_key": "<base64 DER SPKI>" },
18
+ "approvers": [
19
+ { "key_id": "sha256:<hex>", "public_key": "<base64 DER SPKI>", "name": "Platform reviewers",
20
+ "scopes": ["docs-*", "pdf-tools"], "expires_at": "2027-04-07T12:00:00Z" }
21
+ ]
22
+ }
23
+ ```
24
+
25
+ - `version`: positive integer, increased on every change. Hosts with a configured state file reject versions lower than those recorded there.
26
+ - `root.public_key` must hash to `root.key_id`, which must equal the pinned fingerprint and the envelope's `keyid`.
27
+ - `approvers`: sorted by `key_id`, unique, at most 256. The root key may not also be an approver.
28
+ - `scopes`: sorted, unique, 1–64 per approver. `*` matches every Skill name; `prefix*` matches names starting with `prefix`; anything else matches one exact name.
29
+
30
+ ## Revocation list
31
+
32
+ `payloadType`: `application/vnd.mago-ski.revocations+json`
33
+
34
+ ```json
35
+ {
36
+ "type": "mago.revocations/v1",
37
+ "version": 2,
38
+ "issued_at": "2026-10-09T12:00:00Z",
39
+ "expires_at": "2026-11-08T12:00:00Z",
40
+ "root_key_id": "sha256:<hex>",
41
+ "revoked_keys": [{ "key_id": "sha256:<hex>", "reason": "laptop lost", "revoked_at": "2026-10-09T12:00:00Z" }],
42
+ "revoked_digests": [{ "digest": "sha256:<hex>", "reason": "exfiltration found", "revoked_at": "2026-10-09T12:00:00Z" }]
43
+ }
44
+ ```
45
+
46
+ - Required: a host with no valid, unexpired revocation list verifies nothing. The short default lifetime (30 days) forces the organization to republish it, so a host cannot be kept on a stale list indefinitely.
47
+ - A revoked key invalidates every certificate it signed. A revoked digest invalidates that approved version whoever signed it.
48
+ - `revoked_keys` sorted by `key_id`, `revoked_digests` by `digest`, both unique.
49
+
50
+ ## Host policy
51
+
52
+ Hand-edited JSON, read by hosts and the CLI. Paths are relative to the policy file.
53
+
54
+ ```json
55
+ {
56
+ "policy_version": "mago.policy/v1",
57
+ "mode": "shadow",
58
+ "root_fingerprint": "sha256:<hex>",
59
+ "trust_root": "trust-root.json",
60
+ "revocations": "revocations.json",
61
+ "certificate_dirs": ["certs"],
62
+ "skill_dirs": ["../skills"],
63
+ "state_file": "state.json",
64
+ "decision_log": "decisions.jsonl"
65
+ }
66
+ ```
67
+
68
+ | Field | Required | Meaning |
69
+ |---|---|---|
70
+ | `mode` | yes | `shadow`: allow and log what would be blocked. `enforce`: block |
71
+ | `root_fingerprint` | yes | Pinned root key id |
72
+ | `trust_root`, `revocations` | yes | Signed documents |
73
+ | `certificate_dirs` | no | Extra certificate locations |
74
+ | `skill_dirs` | no | Directories scanned by `verify-all` and the GitHub Action |
75
+ | `state_file` | no | Rollback protection (below). Strongly recommended on hosts |
76
+ | `decision_log` | no | JSON Lines file of decisions |
77
+
78
+ The policy itself decides who is trusted, so it must live where the code under review cannot change it. The Pi host reads it only from `MAGO_SKI_POLICY` or `~/.mago-ski/policy.json`; the GitHub Action reads it from the pull request's base revision.
79
+
80
+ ## Host state (rollback protection)
81
+
82
+ Canonical JSON written by the host:
83
+
84
+ ```json
85
+ {"roots":{"sha256:<root key id>":{"revocations_version":2,"trust_root_version":3}},"type":"mago.host-state/v1"}
86
+ ```
87
+
88
+ The host records the highest versions it has accepted for each root and rejects older documents as `UNVERIFIABLE` (rollback). Without a state file, a host can be given an older, still-unexpired trust root or revocation list.
89
+
90
+ ## Decision log
91
+
92
+ One JSON object per line:
93
+
94
+ ```json
95
+ {"timestamp":"2026-10-09T12:00:00Z","host":"laptop-7","mode":"enforce","action":"block","event":"tool:read","skill":"pdf-tools","skill_dir":"/home/a/.agents/skills/pdf-tools","digest":"sha256:...","certificate_id":"sha256:...","verdict":"UNAPPROVED_CHANGE","reason":"..."}
96
+ ```
97
+
98
+ `action` is `allow`, `block` or `would-block` (shadow mode). `certificate_id` is the SHA-256 of the certificate file.
99
+
100
+ ## Key rotation
101
+
102
+ - **Approver keys:** add the new key (`root add-approver`), re-approve the Skills, then remove the old key (`root remove-approver`). Certificates from a removed approver stop verifying once a host reads the updated trust root; revoke the old key instead if it may be compromised.
103
+ - **Root key:** not implemented in v1. Planned design: the new root's first trust root is also signed by the old root, and hosts that pin the old fingerprint accept the new one only through that cross-signed document. Until then, replacing the root means distributing a new fingerprint to every host.
@@ -0,0 +1,46 @@
1
+ # Verification
2
+
3
+ Status: draft, implemented by mago-ski 0.1 (`src/verify.ts`). Verdict test vectors: [`tests/vectors/cases.json`](../../tests/vectors/cases.json).
4
+
5
+ ## Verdicts
6
+
7
+ | Verdict | Meaning | What to do |
8
+ |---|---|---|
9
+ | `VERIFIED` | A certificate from an in-scope, trusted, unrevoked approver covers these exact bytes and has not expired | Nothing |
10
+ | `UNAPPROVED_CHANGE` | A valid certificate exists for this Skill, but the bytes differ from what it approved (including a single sentence or the executable bit) | Review the change and issue a new certificate |
11
+ | `NO_CERTIFICATE` | No certificate names this Skill | Review and approve it, or remove it |
12
+ | `UNTRUSTED_SIGNER` | The signer is not an approver in the trust root, is outside its scopes, or signed after its own expiry | Get it approved by an authorized approver |
13
+ | `REVOKED` | The approver key or the approved digest is on the revocation list | Do not use; re-approve a fixed version with another key |
14
+ | `EXPIRED` | The certificate, the approver key, the trust root or the revocation list has expired | Renew the expired item |
15
+ | `UNVERIFIABLE` | Something could not be checked: malformed or tampered documents, a trust root not signed by the pinned key, rollback, unreadable Skill files | Fix the input; treat as blocked |
16
+
17
+ Every verdict except `VERIFIED` blocks on supported hosts in enforce mode. Shadow mode allows it and records `would-block` in the decision log when one is configured (the GitHub Action reports instead).
18
+
19
+ ## Order of checks
20
+
21
+ Trust documents, once per host check:
22
+
23
+ 1. The trust root's envelope is signed by the pinned root fingerprint, names that root, and its signature is valid. Otherwise `UNVERIFIABLE`.
24
+ 2. The trust root has not expired. Otherwise `EXPIRED`.
25
+ 3. The revocation list is signed by the same root and has not expired. Otherwise `UNVERIFIABLE` or `EXPIRED`.
26
+ 4. Neither document's version is lower than the host state records. Otherwise `UNVERIFIABLE` (rollback). Accepted higher versions are recorded.
27
+
28
+ Each certificate, for a Skill named `NAME` whose current tree digest is `D`:
29
+
30
+ 1. The certificate parses, its file list hashes to its subject digest, and `approver_key_id` matches the envelope `keyid`. Otherwise `UNVERIFIABLE`.
31
+ 2. The subject name is `NAME`. Otherwise `NO_CERTIFICATE` for this candidate.
32
+ 3. The approver key is not revoked. Otherwise `REVOKED`.
33
+ 4. The approver key is in the trust root. Otherwise `UNTRUSTED_SIGNER`.
34
+ 5. One of the approver's scopes matches `NAME`. Otherwise `UNTRUSTED_SIGNER`.
35
+ 6. The signature is valid for the approver's key. Otherwise `UNVERIFIABLE`.
36
+ 7. `issued_at` is not more than 5 minutes in the future (`UNVERIFIABLE`) and is before the approver's `expires_at` (`UNTRUSTED_SIGNER`).
37
+ 8. The approver key and the certificate have not expired. Otherwise `EXPIRED`.
38
+ 9. The approved digest is not revoked. Otherwise `REVOKED`.
39
+ 10. The approved digest equals `D`. Otherwise `UNAPPROVED_CHANGE`.
40
+ 11. `VERIFIED`.
41
+
42
+ If any candidate is `VERIFIED`, the Skill is verified. Otherwise the result is the first match in this order: `REVOKED`, `UNAPPROVED_CHANGE`, `EXPIRED`, `UNTRUSTED_SIGNER`, `UNVERIFIABLE`, `NO_CERTIFICATE`.
43
+
44
+ ## Skill name
45
+
46
+ The name checked against the certificate is, in order: the name the host gives (the Pi host passes the name Pi loaded), the `name` field in `SKILL.md` frontmatter, or the directory name.
@@ -0,0 +1,44 @@
1
+ # Threat model
2
+
3
+ mago-ski answers one question: **is the Skill this agent is about to use the exact version someone in my organization approved, and is that approval still valid?** It does not decide whether a Skill is safe or benign.
4
+
5
+ ## What it protects against
6
+
7
+ | Threat | How |
8
+ |---|---|
9
+ | **Silent update ("rug pull")**: a Skill that was fine is changed, possibly by one sentence, and the agent picks up the new version | The tree digest covers every byte of covered files and their executable bits on Linux and macOS; excluded files are not approved. Any change to covered bytes or executable bits, including prose-only changes with identical capabilities, gives `UNAPPROVED_CHANGE` until someone approves the new version |
10
+ | **Unreviewed Skills**: a Skill installed outside any review process (`npx skills`, copied into `~/.agents/skills`, auto-updated) | No certificate, `NO_CERTIFICATE`. The Pi host does not advertise it and refuses its files in enforce mode |
11
+ | **Rogue or over-reaching approver**: someone signs with a key the organization never authorized, or an authorized team approves outside its area | Hosts trust only the pinned root. Approver keys must be in the root-signed trust root, and scopes limit which Skill names each key may approve: `UNTRUSTED_SIGNER` |
12
+ | **Compromised approver key** | Revoking the key invalidates every certificate it signed: `REVOKED`. This takes effect on each host once it has the updated revocation list (see *Revocation timing* below) |
13
+ | **Bad version discovered after approval** | Revoking the digest: `REVOKED` |
14
+ | **Stale trust**: keeping a host on an old revocation list or trust root | Revocation lists expire (30 days by default). The host state file rejects older versions: `UNVERIFIABLE` (rollback) |
15
+ | **Swap after verification**: a file replaced between the check and its use | The Pi host re-hashes each Skill file on read against the certificate's file list, expands `/skill:` from the bytes it verified, and re-verifies before `grep` and shell commands that touch a Skill |
16
+ | **Hiding the instructions from the digest**: `.skilldigestignore` listing `SKILL.md` | Rejected. `SKILL.md` is always covered, and certificates without it are `UNVERIFIABLE` |
17
+ | **Exposing uncovered files**: `.git`, ignored files, or an unused in-tree certificate file in a verified Skill | The Pi host refuses `read` of any file not in the certificate and refuses `grep` over Skills that have excluded files. The in-tree certificate counts as safe only when it is the certificate that verified the Skill |
18
+ | **Symlinks**: a linked Skill directory, a linked `SKILL.md`, or a link inside a Skill pointing elsewhere | Digests reject symlinks. Discovery (CLI, GitHub Action) reports linked Skills as `UNVERIFIABLE` instead of skipping them, and fails rather than skipping Skills deeper than its search limit. The Pi host matches tool paths both before and after resolving links |
19
+ | **Path aliases**: `@/path`, `file://` URLs, Unicode spaces or filename variants that Pi's tools resolve to a Skill file | The Pi host resolves tool paths the same way Pi's tools do before matching them |
20
+ | **Verification errors** | The Pi host fails closed in enforce mode: a Skill that cannot be checked is `UNVERIFIABLE`, and if checking crashes outright, file and shell tools that touch any Skill path are blocked |
21
+ | **Pull request trusting itself**: a PR adds its own root or approver | The GitHub Action reads policy, trust root and revocation list from the protected base revision |
22
+ | **Tampered documents** | Canonical JSON with exact fields and Ed25519 signatures over DSSE: a changed document fails verification. Malformed documents and invalid signatures are `UNVERIFIABLE`; a change caught by an earlier check (for example a different Skill name or signer) reports that check's verdict instead |
23
+
24
+ ## What it does not protect against
25
+
26
+ - **Malicious first versions and fooled reviewers.** A certificate records a decision; it does not make the decision correct. Review quality is the organization's job.
27
+ - **Prompt injection at runtime.** A verified Skill can still be steered by untrusted data it reads (the confused-deputy problem). Runtime evaluation of tool calls against the approved contract is a separate layer (Mago's CLEAR), not part of mago-ski.
28
+ - **Shell commands that reach Skill files indirectly.** In Pi, `bash` and `powershell` are checked by matching Skill paths in the command text. Relative paths after `cd`, globs, variables or encoded paths can evade it. In enforce mode, the guarantees that hold are: unverified Skills are not advertised, `/skill:` cannot load them, and the structured file tools (`read`, `grep`, `edit`, `write`, `find`, `ls`) refuse their files. `find` and `ls` may still list file names inside verified Skills.
29
+ - **Other code in the agent process.** A hostile Pi extension, MCP server or custom tool runs with the same permissions as mago-ski and can read files directly or change the Skill list after mago-ski filters it. Load mago-ski last and only trusted extensions.
30
+ - **A compromised host.** Root or same-user malware can change files, the policy, the state file or the extension itself. This includes racing directory replacement between path resolution and reading; the digest re-checks file identity, but a same-user attacker controls the file system.
31
+ - **A compromised root key.** Everything chains to it. Keep it offline. Root key rotation is designed but not implemented in v1.
32
+ - **Files excluded from the digest** (`.skilldigestignore`, root `.git`) are not approved. The Pi host refuses to read them from a verified Skill, but other tools may still use them.
33
+ - **Windows.** Not supported in 0.1. Windows has no POSIX executable bit, so it cannot reproduce Linux and macOS digests; see the [digest spec](spec/skill-tree-v2.md).
34
+
35
+ ## Revocation timing
36
+
37
+ Revocation is not instant everywhere. A host acts on a revocation once it reads the updated list. Until then it accepts its current list for as long as that list is unexpired, so the list's lifetime (30 days by default, set with `--expires`) is the longest a revoked certificate can still pass. Shorten it for high-risk organizations and republish often (`revoke refresh`). The host state file stops a host from being moved back to an older list. In CI there is no state file; the Action reads the list from the protected base revision, so a revocation applies to pull requests once it is merged there.
38
+
39
+ ## Assumptions
40
+
41
+ - The root private key is offline and only its holder can sign trust documents.
42
+ - Approver private keys are kept by the people they name; `approve` refuses a key stored inside the Skill directory.
43
+ - The host policy, trust documents and state file are writable only by the user or administrator, not by the code under review. The Pi host never reads policy from the project directory.
44
+ - Clocks are roughly correct (5 minutes of skew is tolerated for issue times).
package/package.json CHANGED
@@ -1,6 +1,76 @@
1
1
  {
2
2
  "name": "@mago-foundation/mago-ski",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "author": "The Mago Foundation",
5
+ "description": "Skills PKI: organization-approved, exact-version Skill certificates enforced on the agent host",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/mago-foundation/mago-ski.git"
9
+ },
10
+ "homepage": "https://magofoundation.dev",
11
+ "bugs": {
12
+ "url": "https://github.com/mago-foundation/mago-ski/issues"
13
+ },
14
+ "keywords": [
15
+ "pi-package",
16
+ "agent-skills",
17
+ "skills",
18
+ "pki",
19
+ "supply-chain",
20
+ "signing"
21
+ ],
22
+ "license": "Apache-2.0",
23
+ "type": "module",
24
+ "engines": {
25
+ "node": ">=22.0.0"
26
+ },
27
+ "os": [
28
+ "linux",
29
+ "darwin"
30
+ ],
31
+ "bin": {
32
+ "mago-ski": "dist/src/cli.js"
33
+ },
34
+ "exports": {
35
+ ".": {
36
+ "types": "./dist/src/index.d.ts",
37
+ "import": "./dist/src/index.js"
38
+ }
39
+ },
40
+ "pi": {
41
+ "extensions": [
42
+ "./dist/hosts/pi/index.js"
43
+ ]
44
+ },
45
+ "scripts": {
46
+ "build": "tsc -p tsconfig.build.json",
47
+ "typecheck": "tsc -p tsconfig.json --noEmit",
48
+ "test": "node --test --test-concurrency=1 \"tests/**/*.test.ts\"",
49
+ "check": "npm run typecheck && npm test",
50
+ "prepublishOnly": "npm run check && npm run build"
51
+ },
52
+ "files": [
53
+ "dist",
54
+ "action.yml",
55
+ "README.md",
56
+ "LICENSE",
57
+ "NOTICE",
58
+ "docs/spec",
59
+ "docs/hosts/",
60
+ "docs/threat-model.md"
61
+ ],
62
+ "devDependencies": {
63
+ "@earendil-works/pi-ai": "1.1.0",
64
+ "@earendil-works/pi-coding-agent": "1.1.0",
65
+ "@types/node": "22.20.4",
66
+ "typescript": "5.8.3"
67
+ },
68
+ "peerDependencies": {
69
+ "@earendil-works/pi-coding-agent": ">=1.0.4"
70
+ },
71
+ "peerDependenciesMeta": {
72
+ "@earendil-works/pi-coding-agent": {
73
+ "optional": true
74
+ }
75
+ }
76
+ }