@mago-foundation/mago-ski 0.4.1 → 0.5.0-beta.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.
package/README.md CHANGED
@@ -41,7 +41,7 @@ Host (Pi, CI) pins the root fingerprint and checks that a certificate chai
41
41
 
42
42
  ## Quickstart
43
43
 
44
- Requires Node.js 22.23.4, 24.22.1 or 26.12.1 or newer in its line (the October 2026 security releases), on Linux or macOS. No runtime dependencies.
44
+ Requires Node.js 22.23.4, 24.22.1 or 26.12.1 or newer in its line (the October 2026 security releases), on Linux or macOS. One runtime dependency: [`yaml`](https://github.com/eemeli/yaml), to read Skill frontmatter as other YAML readers do.
45
45
 
46
46
  ```bash
47
47
  npm install -g @mago-foundation/mago-ski # installs the mago-ski command
@@ -113,6 +113,8 @@ mago-ski 0.4 supports **Linux and macOS** (Node.js 22.23.4, 24.22.1 or 26.12.1 o
113
113
  | Host | What it does | Docs |
114
114
  |---|---|---|
115
115
  | **Pi** | Extension, in enforce mode: unverified Skills are not advertised to the model, `/skill:` cannot load them, file tools refuse their files, and verified files are re-hashed on read | [docs/hosts/pi.md](docs/hosts/pi.md) |
116
+ | **Skill check Action** (free, no keys) | For any Skill repository: shows what each Skill's files contain (websites, scripts, shell code) and, for Skills that declare their needs in an [OWASP USF](https://github.com/OWASP/www-project-agentic-skills-top-10/blob/main/universal-skill-format.md) manifest, fails when the declaration does not cover it. Lists what a pull request adds | [docs/hosts/skill-check.md](docs/hosts/skill-check.md) |
117
+ | **Publish Action** (keyless) | Signs a published-by statement for each Skill with the repository's own GitHub identity (`actions/attest`, public Sigstore log); `mago-ski attestation verify` checks it offline | [docs/hosts/publish.md](docs/hosts/publish.md) |
116
118
  | **GitHub Actions** | In enforce mode, fails the check when a Skill found under the policy's `skill_dirs` lacks a valid certificate. Trust comes from the base revision, so a PR cannot approve itself | [docs/hosts/github-action.md](docs/hosts/github-action.md) |
117
119
  | **CLI** | `verify`, `verify-all`, `diff`, `digest`, `inspect` and `policy check`, plus the key, root, revoke and approve commands, and the root recovery commands (`recovery`, `root-events`, `timestamp`). Run `mago-ski --help` | |
118
120
  | **Claude Code and Codex** (Linux only) | The company gate (`mago-ski gate …`) installs approved Skills into an admin-owned folder and checks every use of a Skill. Tried with the real hosts in non-interactive sessions | [Claude Code](docs/hosts/claude-code.md), [Codex](docs/hosts/codex.md), [docs/capabilities.md](docs/capabilities.md), live test results for [Claude Code](docs/spikes/claude-code-gate-live.md) and [Codex](docs/spikes/codex-gate-live.md) |
@@ -163,9 +165,9 @@ Capability scanners such as SkilLock report what a Skill change does at pull-req
163
165
 
164
166
  - [What mago-ski can do](docs/capabilities.md): what is released and what is not done, in plain language
165
167
  - [Threat model](docs/threat-model.md): what is and is not protected
166
- - Specs: [tree digest](docs/spec/skill-tree-v2.md), [certificate](docs/spec/skill-certificate-v1.md), [trust documents and policy](docs/spec/trust-documents-v1.md), [verification order](docs/spec/verification.md), [root recovery](docs/spec/root-recovery-v1.md), [GUI administration rack](docs/spec/gui-admin-rack-v1.md) (draft)
168
+ - Specs: [tree digest](docs/spec/skill-tree-v2.md), [certificate](docs/spec/skill-certificate-v1.md), [trust documents and policy](docs/spec/trust-documents-v1.md), [verification order](docs/spec/verification.md), [root recovery](docs/spec/root-recovery-v1.md), [observed profile](docs/spec/observed-profile-v1.md) (draft), [admission rules](docs/spec/admission-v0.md) (draft), [GUI administration rack](docs/spec/gui-admin-rack-v1.md) (draft)
167
169
  - [Test vectors](tests/vectors/) for other implementations
168
- - Hosts: [Claude Code](docs/hosts/claude-code.md), [Codex](docs/hosts/codex.md), [Pi](docs/hosts/pi.md), [GitHub Action](docs/hosts/github-action.md), [adapter interface](docs/hosts/adapter-interface.md)
170
+ - Hosts: [Claude Code](docs/hosts/claude-code.md), [Codex](docs/hosts/codex.md), [Pi](docs/hosts/pi.md), [GitHub Action](docs/hosts/github-action.md), [Skill check Action](docs/hosts/skill-check.md), [Publish Action](docs/hosts/publish.md), [adapter interface](docs/hosts/adapter-interface.md)
169
171
  - [Live scenario guide](scenarios/START-HERE.md): try the gate with Claude Code or Codex in an isolated Linux environment
170
172
  - [Pi interception spike](docs/phase1/pi-interception.md), [Claude Code interception spike](docs/spikes/claude-code-interception.md), gate live tests for [Claude Code](docs/spikes/claude-code-gate-live.md) and [Codex](docs/spikes/codex-gate-live.md)
171
173
  - [Security policy](SECURITY.md): how to report a vulnerability
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env node
2
+ import { type SkillCheck } from '../../src/usf-check.ts';
3
+ export interface SkillCheckRunOptions {
4
+ /** Checkout under review. */
5
+ workspace: string;
6
+ /** Where to look for Skills, relative to the workspace. */
7
+ searchPath: string;
8
+ /** Checkout of the pull request's base revision, when there is one. */
9
+ baseRoot?: string;
10
+ /** Fail Skills without a readable USF manifest. */
11
+ requireManifest?: boolean;
12
+ }
13
+ export interface SkillCheckRun {
14
+ checks: SkillCheck[];
15
+ additions: Map<string, string[]>;
16
+ /** Set when the run could not check the repository at all. */
17
+ error?: string;
18
+ exitCode: number;
19
+ summary: string;
20
+ }
21
+ export declare function runSkillCheck({ workspace, searchPath, baseRoot, requireManifest }: SkillCheckRunOptions): Promise<SkillCheckRun>;
@@ -0,0 +1,124 @@
1
+ #!/usr/bin/env node
2
+ // Runner for the free Skill check Action (check/action.yml). No keys, no accounts, no network: it reads the
3
+ // repository, compares each Skill's USF manifest with its files, and on pull requests lists what the change adds.
4
+ // The pass/fail result depends only on the pull request's own files; the base revision only feeds the list of additions.
5
+ import { appendFile, lstat } from 'node:fs/promises';
6
+ import path from 'node:path';
7
+ import { isMainModule } from "../../src/main-module.js";
8
+ import { findSkillDirs } from "../../src/policy.js";
9
+ import { checkSkill, describeAdditions, suggestedManifest } from "../../src/usf-check.js";
10
+ import { annotationLine, escapeAnnotation, markdownCell, MAX_ANNOTATIONS, MAX_SUMMARY_ROWS, withinReal } from "./run.js";
11
+ async function isDirectory(target) {
12
+ try {
13
+ return (await lstat(target)).isDirectory();
14
+ }
15
+ catch {
16
+ return false;
17
+ }
18
+ }
19
+ export async function runSkillCheck({ workspace, searchPath, baseRoot, requireManifest = false }) {
20
+ const root = path.resolve(workspace);
21
+ const additions = new Map();
22
+ const failed = (error) => ({
23
+ checks: [], additions, error, exitCode: 2, summary: `### mago-ski skill check: could not run\n\n${markdownCell(error)}\n`,
24
+ });
25
+ let skillDirs;
26
+ let tooDeep;
27
+ try {
28
+ const searchRoot = await withinReal(root, path.resolve(root, searchPath), 'path');
29
+ ({ skillDirs, tooDeep } = await findSkillDirs([searchRoot]));
30
+ }
31
+ catch (error) {
32
+ // DiscoveryBudgetError, a path outside the workspace, or an unreadable folder.
33
+ if (error instanceof Error)
34
+ return failed(error.message);
35
+ throw error;
36
+ }
37
+ if (skillDirs.length === 0 && tooDeep.length === 0)
38
+ return failed(`no Skill (a folder with SKILL.md) was found under ${searchPath}`);
39
+ const checks = [];
40
+ for (const skillDir of skillDirs) {
41
+ const check = await checkSkill(skillDir, root, { requireManifest });
42
+ checks.push(check);
43
+ if (baseRoot !== undefined) {
44
+ const baseDir = path.join(path.resolve(baseRoot), check.dir);
45
+ // The base is only described, never trusted; a Skill missing there is new.
46
+ const base = (await isDirectory(baseDir)) ? await checkSkill(baseDir, path.resolve(baseRoot)) : null;
47
+ additions.set(check.dir, describeAdditions(base, check));
48
+ }
49
+ }
50
+ for (const directory of tooDeep) {
51
+ checks.push({
52
+ format: 'owasp.usf/v1.0', dir: path.relative(root, directory), ok: false, profile: null, manifest: null, declared: false, manifestError: null, undeclaredHosts: [],
53
+ problems: ['this folder is too deeply nested; Skills below it were not checked. Point the path input closer to the Skills'], notes: [],
54
+ });
55
+ }
56
+ const failures = checks.filter((check) => !check.ok);
57
+ const ordered = [...failures, ...checks.filter((check) => check.ok)];
58
+ const shown = ordered.slice(0, MAX_SUMMARY_ROWS);
59
+ const lines = [
60
+ `### mago-ski skill check: ${checks.length - failures.length}/${checks.length} Skills pass`,
61
+ '',
62
+ '_Shows what each Skill\'s files contain, and, for Skills that declare their needs in an OWASP Universal Skill Format manifest, whether the declaration covers it. It does not say a Skill is safe._',
63
+ '',
64
+ ];
65
+ for (const check of shown) {
66
+ lines.push(`#### ${check.ok ? 'pass' : 'fail'}: ${markdownCell(check.dir)}`, '');
67
+ for (const problem of check.problems)
68
+ lines.push(`- ${markdownCell(problem)}`);
69
+ if (check.profile) {
70
+ const p = check.profile;
71
+ const none = (values) => (values.length === 0 ? 'none' : values.slice(0, 20).join(', ') + (values.length > 20 ? ` and ${values.length - 20} more` : ''));
72
+ lines.push(`- Websites in its files: ${markdownCell(none(p.web_hosts))}`);
73
+ lines.push(`- Scripts and shell code: ${markdownCell(none(p.scripts.map((s) => `${s.path} (${s.reason})`)))}`);
74
+ if (p.programs.length > 0)
75
+ lines.push(`- Programs named in shell code: ${markdownCell(none(p.programs))}`);
76
+ lines.push(`- Declared in USF: ${check.manifest ? 'yes' : check.declared ? 'unreadable' : 'no'}`);
77
+ }
78
+ const added = additions.get(check.dir);
79
+ if (added && added.length > 0) {
80
+ lines.push('', 'This change:');
81
+ for (const line of added)
82
+ lines.push(`- ${markdownCell(line)}`);
83
+ }
84
+ for (const note of check.notes)
85
+ lines.push(`- _note:_ ${markdownCell(note)}`);
86
+ if ((check.profile !== null && !check.declared) || (!check.ok && check.manifest !== null)) {
87
+ // suggestedManifest lists only plain host names, which cannot close this fence.
88
+ lines.push('', `To declare what was found, add this to the SKILL.md frontmatter (review it first: it lists what the files contain, not what the Skill should be allowed to do):`, '', '```yaml', suggestedManifest(check), '```');
89
+ }
90
+ lines.push('');
91
+ }
92
+ if (ordered.length > MAX_SUMMARY_ROWS)
93
+ lines.push(`_${ordered.length - MAX_SUMMARY_ROWS} more Skills not listed (failures are listed first)._`, '');
94
+ return { checks, additions, exitCode: failures.length > 0 ? 1 : 0, summary: lines.join('\n') };
95
+ }
96
+ async function main() {
97
+ const [workspace, searchPath, requireManifest, baseRoot] = process.argv.slice(2);
98
+ if (!workspace || !searchPath || (requireManifest !== 'true' && requireManifest !== 'false'))
99
+ throw new Error('usage: check.ts WORKSPACE PATH true|false [BASE_ROOT]');
100
+ const result = await runSkillCheck({ workspace, searchPath, requireManifest: requireManifest === 'true', ...(baseRoot ? { baseRoot } : {}) });
101
+ if (result.error)
102
+ process.stdout.write(`::error title=mago-ski skill check::${escapeAnnotation(result.error)}\n`);
103
+ let annotations = 0;
104
+ for (const check of result.checks) {
105
+ if (check.ok)
106
+ continue;
107
+ if (annotations >= MAX_ANNOTATIONS) {
108
+ process.stdout.write(`::notice title=mago-ski skill check::${MAX_ANNOTATIONS} annotations shown; see the job summary for the rest\n`);
109
+ break;
110
+ }
111
+ annotations += 1;
112
+ process.stdout.write(annotationLine('error', path.join(check.dir, 'SKILL.md'), 'skill check', check.problems.join('; ')));
113
+ }
114
+ process.stdout.write(`${result.summary}\n`);
115
+ if (process.env.GITHUB_STEP_SUMMARY)
116
+ await appendFile(process.env.GITHUB_STEP_SUMMARY, `${result.summary}\n`);
117
+ process.exitCode = result.exitCode;
118
+ }
119
+ if (isMainModule(import.meta.url)) {
120
+ main().catch((error) => {
121
+ process.stdout.write(`::error title=mago-ski skill check::${escapeAnnotation(error.message)}\n`);
122
+ process.exitCode = 2;
123
+ });
124
+ }
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ import { type PublishedByPredicate } from '../../src/published-by.ts';
3
+ export declare function preparePublish(workspace: string, searchPath: string, outDir: string, requireManifest: boolean): Promise<{
4
+ exitCode: number;
5
+ summary: string;
6
+ predicate?: PublishedByPredicate;
7
+ }>;
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env node
2
+ // Runner for the publish Action (publish/action.yml): checks every Skill like the Skill check Action, and when all
3
+ // pass, writes the published-by predicate and the subject list that actions/attest then signs with the repository's
4
+ // own GitHub identity. Nothing is signed when any Skill fails its check.
5
+ import { mkdir, writeFile } from 'node:fs/promises';
6
+ import path from 'node:path';
7
+ import { isMainModule } from "../../src/main-module.js";
8
+ import { describeSkill, packageVersion, subjectChecksums } from "../../src/published-by.js";
9
+ import { escapeAnnotation } from "./run.js";
10
+ import { runSkillCheck } from "./check.js";
11
+ export async function preparePublish(workspace, searchPath, outDir, requireManifest) {
12
+ const result = await runSkillCheck({ workspace, searchPath, requireManifest });
13
+ if (result.exitCode !== 0)
14
+ return { exitCode: result.exitCode, summary: `${result.summary}\n_Nothing was signed: every Skill must pass the check first._\n` };
15
+ const root = path.resolve(workspace);
16
+ const skills = [];
17
+ for (const check of result.checks) {
18
+ const skill = await describeSkill(path.join(root, check.dir), root);
19
+ // Sign only the bytes that were checked.
20
+ if (skill.digest !== check.profile?.digest)
21
+ return { exitCode: 2, summary: `${result.summary}\n_Nothing was signed: ${check.dir} changed after it was checked._\n` };
22
+ skills.push(skill);
23
+ }
24
+ const predicate = { generator: { name: 'mago-ski', version: packageVersion() }, skills };
25
+ await mkdir(outDir, { recursive: true, mode: 0o700 });
26
+ await writeFile(path.join(outDir, 'predicate.json'), `${JSON.stringify(predicate)}\n`, { mode: 0o600 });
27
+ await writeFile(path.join(outDir, 'subjects.txt'), subjectChecksums(skills), { mode: 0o600 });
28
+ const rows = skills.map((skill) => `| \`${skill.path.replace(/[`|\\]/gu, '_')}\` | \`${skill.digest}\` |`);
29
+ return {
30
+ exitCode: 0,
31
+ predicate,
32
+ summary: [result.summary, '', `### mago-ski publish: ${skills.length} Skill${skills.length === 1 ? '' : 's'} to sign as published-by`, '', '| Skill | Digest |', '|---|---|', ...rows, ''].join('\n'),
33
+ };
34
+ }
35
+ async function main() {
36
+ const [workspace, searchPath, requireManifest, outDir] = process.argv.slice(2);
37
+ if (!workspace || !searchPath || !outDir || (requireManifest !== 'true' && requireManifest !== 'false'))
38
+ throw new Error('usage: publish.ts WORKSPACE PATH true|false OUT_DIR');
39
+ const result = await preparePublish(workspace, searchPath, outDir, requireManifest === 'true');
40
+ process.stdout.write(`${result.summary}\n`);
41
+ if (process.env.GITHUB_STEP_SUMMARY) {
42
+ const { appendFile } = await import('node:fs/promises');
43
+ await appendFile(process.env.GITHUB_STEP_SUMMARY, `${result.summary}\n`);
44
+ }
45
+ process.exitCode = result.exitCode;
46
+ }
47
+ if (isMainModule(import.meta.url)) {
48
+ main().catch((error) => {
49
+ process.stdout.write(`::error title=mago-ski publish::${escapeAnnotation(error.message)}\n`);
50
+ process.exitCode = 2;
51
+ });
52
+ }
@@ -26,6 +26,9 @@ export interface GitHubCheckResult {
26
26
  }
27
27
  /** Names and paths come from the pull request; keep them inert inside a Markdown table cell. */
28
28
  export declare function markdownCell(value: string): string;
29
+ export declare function within(root: string, target: string, label: string): string;
30
+ /** Containment on resolved paths, so a symlink cannot point a policy path outside its checkout. */
31
+ export declare function withinReal(root: string, target: string, label: string): Promise<string>;
29
32
  export declare function runGitHubCheck(options: GitHubCheckOptions): Promise<GitHubCheckResult>;
30
33
  /** Escapes the message part of a workflow command (after the `::`). */
31
34
  export declare function escapeAnnotation(value: string): string;
@@ -19,13 +19,13 @@ export function markdownCell(value) {
19
19
  .replace(/[\\`*_[\]<>|#!~(){}]/gu, (char) => `\\${char}`)
20
20
  .slice(0, 500);
21
21
  }
22
- function within(root, target, label) {
22
+ export function within(root, target, label) {
23
23
  if (!isInside(root, target))
24
24
  throw new Error(`${label} must stay inside ${root}`);
25
25
  return target;
26
26
  }
27
27
  /** Containment on resolved paths, so a symlink cannot point a policy path outside its checkout. */
28
- async function withinReal(root, target, label) {
28
+ export async function withinReal(root, target, label) {
29
29
  within(root, target, label);
30
30
  // The existing part of the path is resolved even when the last parts are missing: a link on the way still counts.
31
31
  const resolved = await realpathAllowingMissing(target);
@@ -0,0 +1,15 @@
1
+ import { type Policy } from './policy.ts';
2
+ import type { SkillFacts } from './admission.ts';
3
+ import type { TrustContext } from './verify.ts';
4
+ export interface SigstoreInputs {
5
+ trustedRootPath: string;
6
+ cosignPath: string;
7
+ }
8
+ export interface SkillEvidence {
9
+ /** Organisation policy (mago.policy) whose trust root vouches for reviews; without it no review counts. */
10
+ policy?: Policy;
11
+ trust?: TrustContext;
12
+ /** A published-by bundle for these bytes. */
13
+ publishedBy?: string;
14
+ }
15
+ export declare function collectSkillFacts(skillDir: string, evidence: SkillEvidence, sigstore: SigstoreInputs | undefined, now: Date): Promise<SkillFacts>;
@@ -0,0 +1,48 @@
1
+ // Collects the facts an admission decision is made from (admission.ts). Everything is recomputed or verified here:
2
+ // the profile and declaration from the bytes, reviews against the organisation's trust root, published-by bundles
3
+ // with the pinned Cosign against a local trusted root. Nothing is fetched. The facts can be logged and replayed.
4
+ import { parseCertificate } from "./certificate.js";
5
+ import { readRegularFile } from "./fs-safe.js";
6
+ import { verifyWithPolicy } from "./policy.js";
7
+ import { describeSkill, publisherOf, verifyPublishedBy } from "./published-by.js";
8
+ import { resolveSkillName } from "./verify.js";
9
+ import path from 'node:path';
10
+ async function review(policy, trust, skillDir, now) {
11
+ const result = await verifyWithPolicy(policy, skillDir, { now, ...(trust ? { context: trust } : {}) });
12
+ if (result.verdict !== 'VERIFIED' || !result.certificateSource || !result.certificateId || !result.approverKeyId)
13
+ return null;
14
+ // The dates come from the certificate that was verified: its id is the hash of its bytes, so a swapped file is refused.
15
+ const certificate = parseCertificate(await readRegularFile(result.certificateSource, 'Certificate', 8 * 1024 * 1024));
16
+ if (certificate.id !== result.certificateId)
17
+ throw new Error('the certificate changed while it was being read');
18
+ return { approver_key_id: result.approverKeyId, certificate_id: result.certificateId, issued_at: certificate.issuedAt.toISOString(), expires_at: certificate.expiresAt.toISOString(), digest: certificate.digest };
19
+ }
20
+ export async function collectSkillFacts(skillDir, evidence, sigstore, now) {
21
+ const record = await describeSkill(skillDir, path.dirname(path.resolve(skillDir)));
22
+ let published_by = null;
23
+ let publishedDigest = record.digest;
24
+ if (evidence.publishedBy !== undefined) {
25
+ if (!sigstore)
26
+ throw new RangeError('a published-by bundle needs --trusted-root and --cosign');
27
+ const facts = await verifyPublishedBy(skillDir, { bundlePath: evidence.publishedBy, ...sigstore });
28
+ // A record that does not match the bytes is not evidence for them.
29
+ if (facts.differences.length > 0)
30
+ throw new Error(`the published-by record does not match these bytes: ${facts.differences.join('; ')}`);
31
+ published_by = publisherOf(facts.publisher);
32
+ publishedDigest = facts.digest;
33
+ }
34
+ const reviewed = evidence.policy ? await review(evidence.policy, evidence.trust, skillDir, now) : null;
35
+ // Every source read the bytes separately: they must all have seen the same version.
36
+ const check = await describeSkill(skillDir, path.dirname(path.resolve(skillDir)));
37
+ if (check.digest !== record.digest || publishedDigest !== record.digest || (reviewed && reviewed.digest !== record.digest))
38
+ throw new Error('the Skill changed while its facts were collected');
39
+ return {
40
+ name: await resolveSkillName(skillDir),
41
+ digest: record.digest,
42
+ profile: record.profile,
43
+ declaration: record.declaration,
44
+ declaration_error: record.declaration_error,
45
+ reviewed_by: reviewed && { approver_key_id: reviewed.approver_key_id, certificate_id: reviewed.certificate_id, issued_at: reviewed.issued_at, expires_at: reviewed.expires_at },
46
+ published_by,
47
+ };
48
+ }
@@ -0,0 +1,102 @@
1
+ import type { ObservedProfile } from './profile.ts';
2
+ import type { Publisher } from './published-by.ts';
3
+ import type { UsfManifest } from './usf.ts';
4
+ export declare const ADMISSION_VERSION = "mago.admission/v0";
5
+ export declare const ACTIONS: readonly ["ALLOW", "LOG_ONLY", "FLAG", "REQUIRE_REVIEW", "BLOCK"];
6
+ export type Action = (typeof ACTIONS)[number];
7
+ export interface Review {
8
+ approver_key_id: string;
9
+ certificate_id: string;
10
+ issued_at: string;
11
+ expires_at: string;
12
+ }
13
+ export interface SkillFacts {
14
+ name: string;
15
+ digest: string;
16
+ profile: ObservedProfile;
17
+ declaration: UsfManifest | null;
18
+ /** Why SKILL.md's declaration could not be read one way only, or null. */
19
+ declaration_error: string | null;
20
+ /** A valid certificate from the organisation's trust root for these exact bytes. */
21
+ reviewed_by: Review | null;
22
+ /** A verified published-by attestation for these exact bytes. */
23
+ published_by: Publisher | null;
24
+ }
25
+ export interface Facts {
26
+ skill: SkillFacts;
27
+ /** The reviewed version this one updates, when one was supplied (its bytes, its review, its publisher). */
28
+ base: SkillFacts | null;
29
+ }
30
+ export interface PublisherCondition {
31
+ repository_id?: string;
32
+ owner_id?: string;
33
+ workflow?: string;
34
+ branch?: string;
35
+ trigger?: string[];
36
+ }
37
+ export interface CapabilityCondition {
38
+ shell?: true;
39
+ websites?: string[];
40
+ any_website?: true;
41
+ undeclared?: true;
42
+ no_declaration?: true;
43
+ incomplete?: true;
44
+ }
45
+ export interface UpdateCondition {
46
+ same_publisher: true;
47
+ max_days_since_review?: number;
48
+ }
49
+ export interface Rule {
50
+ id: string;
51
+ when: {
52
+ publisher?: PublisherCondition;
53
+ reviewed?: boolean;
54
+ capabilities?: CapabilityCondition;
55
+ update?: UpdateCondition;
56
+ };
57
+ action: Action;
58
+ reason?: string;
59
+ }
60
+ export interface Rules {
61
+ admission_version: typeof ADMISSION_VERSION;
62
+ default: Action;
63
+ rules: Rule[];
64
+ digest: string;
65
+ }
66
+ export declare class AdmissionRulesError extends Error {
67
+ }
68
+ /**
69
+ * Parses and lints a rule file. Every mistake the closed language can detect is an error here, not a surprise at
70
+ * decision time: unknown keys, duplicate ids, a loosening rule built on self-declared or heuristic facts, a strict
71
+ * action without a reason, an ALLOW that matches every Skill.
72
+ */
73
+ export declare function parseRules(source: string): Rules;
74
+ export interface Decision {
75
+ action: Action;
76
+ admitted: boolean;
77
+ /** The rule that set the action, or "default" when none matched. */
78
+ rule_id: string;
79
+ matched: string[];
80
+ reason: string | null;
81
+ /** The smallest evidence that would change a REQUIRE_REVIEW or the default, in words. */
82
+ missing: string | null;
83
+ }
84
+ /** Why this version reaches further than its base, or null when it does not. Compares declared and observed together. */
85
+ export declare function escalation(base: SkillFacts, skill: SkillFacts): string | null;
86
+ export declare function evaluate(rules: Rules, facts: Facts, now: Date): Decision;
87
+ export interface AdmissionRecord {
88
+ decided_at: string;
89
+ rules_digest: string;
90
+ facts: Facts;
91
+ decision: Decision;
92
+ }
93
+ export interface Flip {
94
+ decided_at: string;
95
+ skill: string;
96
+ digest: string;
97
+ before: Decision;
98
+ after: Decision;
99
+ }
100
+ export declare function validRecord(value: unknown): value is AdmissionRecord;
101
+ /** Every past decision whose action would change under `next`, each re-evaluated at its own time. */
102
+ export declare function replay(previous: Rules, next: Rules, records: readonly unknown[]): Flip[];