owenloop 0.5.0 → 0.5.2
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/CHANGELOG.md +67 -0
- package/README.md +144 -35
- package/bin/owenloop.mjs +49 -1
- package/dist/packages/work/src/agent/brief.d.ts +29 -4
- package/dist/packages/work/src/agent/brief.js +49 -4
- package/dist/packages/work/src/agent/capability-model.d.ts +123 -0
- package/dist/packages/work/src/agent/capability-model.js +148 -0
- package/dist/packages/work/src/agent/loop.d.ts +56 -7
- package/dist/packages/work/src/agent/loop.js +166 -9
- package/dist/packages/work/src/bundle/cache.d.ts +7 -5
- package/dist/packages/work/src/bundle/cache.js +20 -6
- package/dist/packages/work/src/bundle/fetch.d.ts +7 -5
- package/dist/packages/work/src/bundle/fetch.js +27 -7
- package/dist/packages/work/src/bundle/types.d.ts +8 -4
- package/dist/packages/work/src/consumed-verifier.d.ts +45 -0
- package/dist/packages/work/src/consumed-verifier.js +205 -0
- package/dist/packages/work/src/exec/instructions.d.ts +99 -0
- package/dist/packages/work/src/exec/instructions.js +323 -0
- package/dist/packages/work/src/exec/loop.d.ts +29 -1
- package/dist/packages/work/src/exec/loop.js +313 -35
- package/dist/packages/work/src/exec/payload.d.ts +29 -0
- package/dist/packages/work/src/exec/payload.js +54 -0
- package/dist/packages/work/src/exec/receipt.d.ts +9 -6
- package/dist/packages/work/src/exec/receipt.js +12 -1
- package/dist/packages/work/src/exec/runner.d.ts +7 -1
- package/dist/packages/work/src/exec/runner.js +84 -3
- package/dist/packages/work/src/harness/child-env.js +7 -0
- package/dist/packages/work/src/harness/claude.d.ts +20 -8
- package/dist/packages/work/src/harness/claude.js +260 -58
- package/dist/packages/work/src/harness/codex.d.ts +5 -4
- package/dist/packages/work/src/harness/codex.js +169 -41
- package/dist/packages/work/src/harness/contract.d.ts +36 -11
- package/dist/packages/work/src/harness/fake.js +1 -0
- package/dist/packages/work/src/harness/jsonrpc-stdio.js +7 -0
- package/dist/packages/work/src/harness/permissions.d.ts +16 -3
- package/dist/packages/work/src/harness/permissions.js +102 -13
- package/dist/packages/work/src/harness/session-store.d.ts +30 -10
- package/dist/packages/work/src/harness/session-store.js +317 -89
- package/dist/packages/work/src/hold/mcp.d.ts +25 -5
- package/dist/packages/work/src/hold/mcp.js +134 -12
- package/dist/packages/work/src/hub/client.d.ts +8 -1
- package/dist/packages/work/src/hub/client.js +15 -1
- package/dist/packages/work/src/hub/types.d.ts +137 -33
- package/dist/packages/work/src/hub/types.js +8 -10
- package/dist/packages/work/src/mcp/server.js +1 -1
- package/dist/packages/work/src/owenloop-bin.d.ts +1 -0
- package/dist/packages/work/src/owenloop-bin.js +18 -0
- package/dist/packages/work/src/roles/agent-run.d.ts +12 -6
- package/dist/packages/work/src/roles/agent-run.js +115 -34
- package/dist/packages/work/src/roles/exec.d.ts +8 -0
- package/dist/packages/work/src/roles/exec.js +27 -2
- package/dist/packages/work/src/roles/hold.d.ts +6 -0
- package/dist/packages/work/src/roles/hold.js +83 -13
- package/dist/packages/work/src/roles/lint.d.ts +3 -4
- package/dist/packages/work/src/roles/lint.js +41 -7
- package/dist/packages/work/src/roles/settings.js +19 -2
- package/dist/packages/work/src/roles/shift.d.ts +1 -0
- package/dist/packages/work/src/roles/shift.js +36 -2
- package/dist/packages/work/src/settings/settings.d.ts +70 -1
- package/dist/packages/work/src/settings/settings.js +90 -4
- package/dist/packages/work/src/shift/logretention.d.ts +253 -0
- package/dist/packages/work/src/shift/logretention.js +407 -0
- package/dist/packages/work/src/shift/logsink.d.ts +14 -0
- package/dist/packages/work/src/shift/logsink.js +98 -0
- package/dist/packages/work/src/shift/loop.d.ts +32 -4
- package/dist/packages/work/src/shift/loop.js +687 -166
- package/dist/packages/work/src/shift/protocol.d.ts +128 -1
- package/dist/packages/work/src/shift/protocol.js +14 -0
- package/dist/packages/work/src/shift/runtime.d.ts +16 -0
- package/dist/packages/work/src/shift/runtime.js +291 -5
- package/dist/packages/work/src/shift/server.d.ts +13 -0
- package/dist/packages/work/src/shift/server.js +61 -36
- package/dist/packages/work/src/shift/spawn.d.ts +115 -19
- package/dist/packages/work/src/shift/spawn.js +234 -30
- package/dist/packages/work/src/shift/state.d.ts +76 -49
- package/dist/packages/work/src/shift/state.js +350 -103
- package/dist/packages/work/src/shift/truncate.d.ts +35 -0
- package/dist/packages/work/src/shift/truncate.js +73 -0
- package/dist/packages/work/src/submit-proof.d.ts +61 -0
- package/dist/packages/work/src/submit-proof.js +119 -0
- package/dist/packages/work/src/submit-value.d.ts +48 -0
- package/dist/packages/work/src/submit-value.js +118 -0
- package/dist/packages/work/src/usage.d.ts +1 -1
- package/dist/packages/work/src/usage.js +11 -0
- package/dist/src/add.d.ts +64 -259
- package/dist/src/add.js +81 -615
- package/dist/src/archive.d.ts +97 -0
- package/dist/src/archive.js +591 -0
- package/dist/src/bundle/index.d.ts +64 -0
- package/dist/src/bundle/index.js +508 -0
- package/dist/src/bundle/manifest.d.ts +50 -0
- package/dist/src/bundle/manifest.js +435 -0
- package/dist/src/bundle/runtime.d.ts +26 -0
- package/dist/src/bundle/runtime.js +64 -0
- package/dist/src/bundle/tar.d.ts +62 -0
- package/dist/src/bundle/tar.js +238 -0
- package/dist/src/bundle/types.d.ts +105 -0
- package/dist/src/bundle/types.js +21 -0
- package/dist/src/capabilities.d.ts +93 -0
- package/dist/src/capabilities.js +101 -0
- package/dist/src/cli.d.ts +90 -20
- package/dist/src/cli.js +2421 -374
- package/dist/src/credentials.d.ts +4 -3
- package/dist/src/credentials.js +21 -19
- package/dist/src/crypto/allowed-signers.d.ts +68 -0
- package/dist/src/crypto/allowed-signers.js +307 -0
- package/dist/src/crypto/canonical.d.ts +8 -0
- package/dist/src/crypto/canonical.js +92 -0
- package/dist/src/crypto/chain.d.ts +65 -0
- package/dist/src/crypto/chain.js +377 -0
- package/dist/src/crypto/dsse.d.ts +209 -0
- package/dist/src/crypto/dsse.js +282 -0
- package/dist/src/crypto/enrollment.d.ts +78 -0
- package/dist/src/crypto/enrollment.js +186 -0
- package/dist/src/crypto/index.d.ts +48 -0
- package/dist/src/crypto/index.js +44 -0
- package/dist/src/crypto/keys.d.ts +258 -0
- package/dist/src/crypto/keys.js +908 -0
- package/dist/src/crypto/org-root.d.ts +33 -0
- package/dist/src/crypto/org-root.js +78 -0
- package/dist/src/crypto/origin-rules.d.ts +56 -0
- package/dist/src/crypto/origin-rules.js +143 -0
- package/dist/src/crypto/policy-floor.d.ts +98 -0
- package/dist/src/crypto/policy-floor.js +353 -0
- package/dist/src/crypto/records.d.ts +319 -0
- package/dist/src/crypto/records.js +168 -0
- package/dist/src/crypto/scope.d.ts +49 -0
- package/dist/src/crypto/scope.js +83 -0
- package/dist/src/crypto/ssh.d.ts +171 -0
- package/dist/src/crypto/ssh.js +396 -0
- package/dist/src/crypto/submission.d.ts +33 -0
- package/dist/src/crypto/submission.js +47 -0
- package/dist/src/crypto/trust-roots.d.ts +29 -0
- package/dist/src/crypto/trust-roots.js +39 -0
- package/dist/src/crypto/verify-consumed.d.ts +67 -0
- package/dist/src/crypto/verify-consumed.js +259 -0
- package/dist/src/crypto/verify-origin.d.ts +50 -0
- package/dist/src/crypto/verify-origin.js +151 -0
- package/dist/src/crypto/verify-publication.d.ts +60 -0
- package/dist/src/crypto/verify-publication.js +150 -0
- package/dist/src/defs.d.ts +24 -1
- package/dist/src/defs.js +335 -27
- package/dist/src/engine.d.ts +211 -6
- package/dist/src/engine.js +459 -59
- package/dist/src/factory.d.ts +16 -0
- package/dist/src/factory.js +16 -4
- package/dist/src/global-config.d.ts +59 -0
- package/dist/src/global-config.js +84 -0
- package/dist/src/hub.d.ts +102 -32
- package/dist/src/hub.js +147 -58
- package/dist/src/index.d.ts +19 -2
- package/dist/src/index.js +23 -2
- package/dist/src/install.d.ts +538 -0
- package/dist/src/install.js +1981 -0
- package/dist/src/lock.d.ts +15 -57
- package/dist/src/lock.js +251 -143
- package/dist/src/mcp/serve.d.ts +46 -22
- package/dist/src/mcp/serve.js +174 -44
- package/dist/src/mcp/server.js +12 -1
- package/dist/src/model.d.ts +51 -0
- package/dist/src/model.js +157 -1
- package/dist/src/order-resolver.d.ts +184 -0
- package/dist/src/order-resolver.js +252 -0
- package/dist/src/package-version.d.ts +10 -0
- package/dist/src/package-version.js +42 -0
- package/dist/src/paths.d.ts +14 -1
- package/dist/src/paths.js +18 -0
- package/dist/src/schemas/enrollment-grant.v1.schema.json +90 -0
- package/dist/src/schemas/index.d.ts +1433 -0
- package/dist/src/schemas/index.js +31 -0
- package/dist/src/schemas/order.v1.schema.json +120 -0
- package/dist/src/schemas/origin.v1.schema.json +68 -0
- package/dist/src/schemas/policy-floor.v1.schema.json +29 -0
- package/dist/src/schemas/publication.v1.schema.json +31 -0
- package/dist/src/schemas/revocation.v1.schema.json +39 -0
- package/dist/src/schemas/submission.v1.schema.json +61 -0
- package/dist/src/store/def-source.d.ts +52 -0
- package/dist/src/store/def-source.js +335 -0
- package/dist/src/store/index-file.d.ts +69 -0
- package/dist/src/store/index-file.js +151 -0
- package/dist/src/store/index.d.ts +27 -0
- package/dist/src/store/index.js +22 -0
- package/dist/src/store/ingestor.d.ts +43 -0
- package/dist/src/store/ingestor.js +211 -0
- package/dist/src/store/install.d.ts +228 -0
- package/dist/src/store/install.js +555 -0
- package/dist/src/store/instruction-source.d.ts +49 -0
- package/dist/src/store/instruction-source.js +298 -0
- package/dist/src/store/origin-evidence.d.ts +21 -0
- package/dist/src/store/origin-evidence.js +66 -0
- package/dist/src/store/pre-commit-verifier.d.ts +68 -0
- package/dist/src/store/pre-commit-verifier.js +418 -0
- package/dist/src/store/resolve.d.ts +138 -0
- package/dist/src/store/resolve.js +363 -0
- package/dist/src/store/types.d.ts +288 -0
- package/dist/src/store/types.js +356 -0
- package/dist/src/store.d.ts +33 -1
- package/dist/src/store.js +57 -4
- package/dist/src/types.d.ts +146 -12
- package/dist/src/untar.d.ts +8 -23
- package/dist/src/untar.js +10 -136
- package/docs/agent-runner.md +86 -0
- package/docs/authoring.md +64 -6
- package/docs/bundles.md +350 -0
- package/docs/cli.md +1298 -106
- package/docs/crypto.md +832 -0
- package/docs/design.md +342 -20
- package/docs/embedding.md +132 -25
- package/docs/shift-logs.md +642 -0
- package/docs/wire-contracts.md +395 -0
- package/package.json +6 -1
- package/plugins/claude-code/.claude-plugin/marketplace.json +14 -0
- package/plugins/claude-code/plugin/.claude-plugin/plugin.json +8 -0
- package/plugins/claude-code/plugin/.mcp.json +14 -0
- package/plugins/claude-code/plugin/hooks/hooks.json +26 -0
- package/plugins/claude-code/plugin/hooks/session-end.sh +40 -0
- package/plugins/claude-code/plugin/hooks/session-start.sh +52 -0
- package/plugins/claude-code/plugin/skills/author/SKILL.md +181 -0
- package/plugins/claude-code/plugin/skills/conduct/SKILL.md +106 -0
- package/plugins/claude-code/plugin/skills/shift/SKILL.md +105 -0
- package/plugins/codex/.agents/plugins/marketplace.json +21 -0
- package/plugins/codex/plugins/owenloop/.codex-plugin/plugin.json +7 -0
- package/plugins/codex/plugins/owenloop/.mcp.json +20 -0
- package/plugins/codex/plugins/owenloop/hooks/hooks.json +26 -0
- package/plugins/codex/plugins/owenloop/hooks/session-end.sh +40 -0
- package/plugins/codex/plugins/owenloop/hooks/session-start.sh +52 -0
- package/plugins/codex/plugins/owenloop/skills/author/SKILL.md +181 -0
- package/plugins/codex/plugins/owenloop/skills/conduct/SKILL.md +106 -0
- package/plugins/codex/plugins/owenloop/skills/shift/SKILL.md +105 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local filesystem paths and loaders for an organization's enrollment anchor.
|
|
3
|
+
*
|
|
4
|
+
* The module derives every path from an injected environment, with
|
|
5
|
+
* XDG_CONFIG_HOME taking precedence over HOME. The loader only returns raw
|
|
6
|
+
* envelope bytes; chain.ts remains a pure verifier and does not know this
|
|
7
|
+
* layout. This module deliberately does not transport registrations, contact a
|
|
8
|
+
* hub, or expose private key bytes.
|
|
9
|
+
*/
|
|
10
|
+
export interface OrgRootPresent {
|
|
11
|
+
kind: 'present';
|
|
12
|
+
path: string;
|
|
13
|
+
publicKey: string;
|
|
14
|
+
}
|
|
15
|
+
export interface OrgRootAbsent {
|
|
16
|
+
kind: 'absent';
|
|
17
|
+
path: string;
|
|
18
|
+
}
|
|
19
|
+
export type OrgRootResolution = OrgRootPresent | OrgRootAbsent;
|
|
20
|
+
/** `<config>/owenloop/org-root.pub`, the public local trust anchor. */
|
|
21
|
+
export declare function orgRootPublicKeyPath(env: Record<string, string | undefined>): string;
|
|
22
|
+
/** `<config>/owenloop/org-root`, the private anchor path. */
|
|
23
|
+
export declare function orgRootPrivateKeyPath(env: Record<string, string | undefined>): string;
|
|
24
|
+
/** `<config>/owenloop/roster`, containing enrollment-grant envelopes. */
|
|
25
|
+
export declare function rosterDir(env: Record<string, string | undefined>): string;
|
|
26
|
+
/** `<config>/owenloop/revocations`, containing revocation envelopes. */
|
|
27
|
+
export declare function revocationsDir(env: Record<string, string | undefined>): string;
|
|
28
|
+
/** Resolve the public anchor without treating absence as a local-store error. */
|
|
29
|
+
export declare function resolveOrgRoot(env: Record<string, string | undefined>): OrgRootResolution;
|
|
30
|
+
/** Load sorted `.grant.dsse` bytes from the injected roster directory. */
|
|
31
|
+
export declare function loadRoster(env: Record<string, string | undefined>): Uint8Array[];
|
|
32
|
+
/** Load sorted `.revocation.dsse` bytes from the injected revocation directory. */
|
|
33
|
+
export declare function loadRevocations(env: Record<string, string | undefined>): Uint8Array[];
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local filesystem paths and loaders for an organization's enrollment anchor.
|
|
3
|
+
*
|
|
4
|
+
* The module derives every path from an injected environment, with
|
|
5
|
+
* XDG_CONFIG_HOME taking precedence over HOME. The loader only returns raw
|
|
6
|
+
* envelope bytes; chain.ts remains a pure verifier and does not know this
|
|
7
|
+
* layout. This module deliberately does not transport registrations, contact a
|
|
8
|
+
* hub, or expose private key bytes.
|
|
9
|
+
*/
|
|
10
|
+
import { lstatSync, readdirSync, readFileSync } from 'node:fs';
|
|
11
|
+
import { dirname, join } from 'node:path';
|
|
12
|
+
import { allowedSignersPath } from "./trust-roots.js";
|
|
13
|
+
function orgRootDir(env) {
|
|
14
|
+
// allowedSignersPath is the established injected-env resolver. Its dirname
|
|
15
|
+
// is exactly <config>/owenloop for both XDG_CONFIG_HOME and HOME fallback.
|
|
16
|
+
return dirname(allowedSignersPath(env));
|
|
17
|
+
}
|
|
18
|
+
/** `<config>/owenloop/org-root.pub`, the public local trust anchor. */
|
|
19
|
+
export function orgRootPublicKeyPath(env) {
|
|
20
|
+
return join(orgRootDir(env), 'org-root.pub');
|
|
21
|
+
}
|
|
22
|
+
/** `<config>/owenloop/org-root`, the private anchor path. */
|
|
23
|
+
export function orgRootPrivateKeyPath(env) {
|
|
24
|
+
return join(orgRootDir(env), 'org-root');
|
|
25
|
+
}
|
|
26
|
+
/** `<config>/owenloop/roster`, containing enrollment-grant envelopes. */
|
|
27
|
+
export function rosterDir(env) {
|
|
28
|
+
return join(orgRootDir(env), 'roster');
|
|
29
|
+
}
|
|
30
|
+
/** `<config>/owenloop/revocations`, containing revocation envelopes. */
|
|
31
|
+
export function revocationsDir(env) {
|
|
32
|
+
return join(orgRootDir(env), 'revocations');
|
|
33
|
+
}
|
|
34
|
+
function assertRegularFile(path, label) {
|
|
35
|
+
const stat = lstatSync(path);
|
|
36
|
+
if (stat.isSymbolicLink())
|
|
37
|
+
throw new Error(`${label} path is a symlink: ${path}`);
|
|
38
|
+
if (!stat.isFile())
|
|
39
|
+
throw new Error(`${label} path is not a regular file: ${path}`);
|
|
40
|
+
}
|
|
41
|
+
/** Resolve the public anchor without treating absence as a local-store error. */
|
|
42
|
+
export function resolveOrgRoot(env) {
|
|
43
|
+
const path = orgRootPublicKeyPath(env);
|
|
44
|
+
if (lstatSync(path, { throwIfNoEntry: false }) === undefined)
|
|
45
|
+
return { kind: 'absent', path };
|
|
46
|
+
assertRegularFile(path, 'org-root public key');
|
|
47
|
+
return { kind: 'present', path, publicKey: readFileSync(path, 'utf8') };
|
|
48
|
+
}
|
|
49
|
+
function loadEnvelopeDirectory(path, suffix, label) {
|
|
50
|
+
const dirStat = lstatSync(path, { throwIfNoEntry: false });
|
|
51
|
+
if (dirStat === undefined)
|
|
52
|
+
return [];
|
|
53
|
+
if (dirStat.isSymbolicLink())
|
|
54
|
+
throw new Error(`${label} directory is a symlink: ${path}`);
|
|
55
|
+
if (!dirStat.isDirectory())
|
|
56
|
+
throw new Error(`${label} path is not a directory: ${path}`);
|
|
57
|
+
const entries = readdirSync(path).sort();
|
|
58
|
+
const result = [];
|
|
59
|
+
for (const name of entries) {
|
|
60
|
+
const entryPath = join(path, name);
|
|
61
|
+
const stat = lstatSync(entryPath);
|
|
62
|
+
if (stat.isSymbolicLink())
|
|
63
|
+
throw new Error(`${label} entry is a symlink: ${entryPath}`);
|
|
64
|
+
if (!stat.isFile())
|
|
65
|
+
throw new Error(`${label} entry is not a regular file: ${entryPath}`);
|
|
66
|
+
if (name.endsWith(suffix))
|
|
67
|
+
result.push(readFileSync(entryPath));
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
/** Load sorted `.grant.dsse` bytes from the injected roster directory. */
|
|
72
|
+
export function loadRoster(env) {
|
|
73
|
+
return loadEnvelopeDirectory(rosterDir(env), '.grant.dsse', 'roster');
|
|
74
|
+
}
|
|
75
|
+
/** Load sorted `.revocation.dsse` bytes from the injected revocation directory. */
|
|
76
|
+
export function loadRevocations(env) {
|
|
77
|
+
return loadEnvelopeDirectory(revocationsDir(env), '.revocation.dsse', 'revocations');
|
|
78
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure namespace-scoped origin-rule parsing and evaluation.
|
|
3
|
+
*
|
|
4
|
+
* A rule is a minimum provenance strength. The namespace is one flat coordinate
|
|
5
|
+
* component, so matching uses exact keys and ordered prefixes rather than a
|
|
6
|
+
* general path-glob implementation. This module performs no filesystem,
|
|
7
|
+
* settings, or network I/O.
|
|
8
|
+
*/
|
|
9
|
+
import type { OriginVerdict } from './verify-origin.ts';
|
|
10
|
+
import type { DefPolicy } from './verify-publication.ts';
|
|
11
|
+
/** The local policy vocabulary used for origin-rule enforcement. */
|
|
12
|
+
export type OriginPolicy = DefPolicy;
|
|
13
|
+
/** The accepted minimum provenance strengths for one namespace rule. */
|
|
14
|
+
export type OriginRuleValue = 'git' | 'console' | 'agent' | 'any';
|
|
15
|
+
/** A parsed namespace-to-minimum-strength map. */
|
|
16
|
+
export type OriginRules = Readonly<Record<string, OriginRuleValue>>;
|
|
17
|
+
/** A named configuration error for malformed origin rules. */
|
|
18
|
+
export declare class OriginRulesError extends Error {
|
|
19
|
+
readonly code: "origin-rules-invalid";
|
|
20
|
+
constructor(message: string);
|
|
21
|
+
}
|
|
22
|
+
/** Provenance strength ordering. A git origin is strongest. */
|
|
23
|
+
export declare const ORIGIN_SOURCE_RANK: Readonly<Record<'git' | 'console' | 'agent', number>>;
|
|
24
|
+
/** The rule selected for one recovered namespace. */
|
|
25
|
+
export interface OriginRuleMatch {
|
|
26
|
+
/** The original settings key that selected the rule. */
|
|
27
|
+
key: string;
|
|
28
|
+
/** The minimum provenance strength required by the selected rule. */
|
|
29
|
+
value: OriginRuleValue;
|
|
30
|
+
}
|
|
31
|
+
/** The result of evaluating one origin verdict against one selected rule. */
|
|
32
|
+
export type OriginRuleEvaluation = {
|
|
33
|
+
ok: true;
|
|
34
|
+
} | {
|
|
35
|
+
ok: false;
|
|
36
|
+
kind: 'absent' | 'unverifiable' | 'invalid' | 'weaker';
|
|
37
|
+
detail: string;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Parse and validate the settings-file representation of origin rules.
|
|
41
|
+
* Malformed keys and values throw a named error instead of degrading to an
|
|
42
|
+
* empty rule set.
|
|
43
|
+
*/
|
|
44
|
+
export declare function parseOriginRules(raw: unknown): OriginRules;
|
|
45
|
+
/**
|
|
46
|
+
* Select one rule for a namespace. Exact keys win over every prefix; among
|
|
47
|
+
* prefixes, the longest matching prefix wins. The parser's equal-specificity
|
|
48
|
+
* error keeps this selection deterministic.
|
|
49
|
+
*/
|
|
50
|
+
export declare function matchOriginRule(rules: OriginRules, namespace: string): OriginRuleMatch | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Evaluate a verified or failed origin verdict against a minimum rule.
|
|
53
|
+
* `any` is no requirement; an invalid present sidecar remains a hard failure
|
|
54
|
+
* because a malformed signed statement is an attack signal, not absence.
|
|
55
|
+
*/
|
|
56
|
+
export declare function evaluateOriginRule(rule: OriginRuleValue, verdict: OriginVerdict): OriginRuleEvaluation;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure namespace-scoped origin-rule parsing and evaluation.
|
|
3
|
+
*
|
|
4
|
+
* A rule is a minimum provenance strength. The namespace is one flat coordinate
|
|
5
|
+
* component, so matching uses exact keys and ordered prefixes rather than a
|
|
6
|
+
* general path-glob implementation. This module performs no filesystem,
|
|
7
|
+
* settings, or network I/O.
|
|
8
|
+
*/
|
|
9
|
+
/** A named configuration error for malformed origin rules. */
|
|
10
|
+
export class OriginRulesError extends Error {
|
|
11
|
+
code = 'origin-rules-invalid';
|
|
12
|
+
constructor(message) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.name = 'OriginRulesError';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** Provenance strength ordering. A git origin is strongest. */
|
|
18
|
+
export const ORIGIN_SOURCE_RANK = Object.freeze({
|
|
19
|
+
git: 3,
|
|
20
|
+
console: 2,
|
|
21
|
+
agent: 1,
|
|
22
|
+
});
|
|
23
|
+
function isPlainObject(value) {
|
|
24
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
25
|
+
}
|
|
26
|
+
function normalizeRuleKey(key) {
|
|
27
|
+
if (key.length === 0) {
|
|
28
|
+
throw new OriginRulesError("invalid originRules key '': the namespace key must not be empty");
|
|
29
|
+
}
|
|
30
|
+
if (/\p{Cc}/u.test(key)) {
|
|
31
|
+
throw new OriginRulesError(`invalid originRules key ${JSON.stringify(key)}: control characters are not allowed`);
|
|
32
|
+
}
|
|
33
|
+
// The specification's namespace/name spelling is accepted as sugar. Rules
|
|
34
|
+
// are evaluated only against the namespace, so the trailing name wildcard
|
|
35
|
+
// disappears before exact/prefix selection.
|
|
36
|
+
const withoutNameSugar = key.endsWith('/*') ? key.slice(0, -2) : key;
|
|
37
|
+
if (withoutNameSugar.length === 0) {
|
|
38
|
+
throw new OriginRulesError(`invalid originRules key ${JSON.stringify(key)}: the namespace key must not be empty`);
|
|
39
|
+
}
|
|
40
|
+
if (withoutNameSugar.includes('/')) {
|
|
41
|
+
throw new OriginRulesError(`invalid originRules key ${JSON.stringify(key)}: only a trailing '/*' is allowed`);
|
|
42
|
+
}
|
|
43
|
+
if (/[?\[]/.test(withoutNameSugar)) {
|
|
44
|
+
throw new OriginRulesError(`invalid originRules key ${JSON.stringify(key)}: '?', and '[' are not supported`);
|
|
45
|
+
}
|
|
46
|
+
if (withoutNameSugar === '*')
|
|
47
|
+
return { pattern: '', exact: false };
|
|
48
|
+
if (withoutNameSugar.includes('*') && !withoutNameSugar.endsWith('*')) {
|
|
49
|
+
throw new OriginRulesError(`invalid originRules key ${JSON.stringify(key)}: '*' is only allowed at the end`);
|
|
50
|
+
}
|
|
51
|
+
if (withoutNameSugar.endsWith('*')) {
|
|
52
|
+
const pattern = withoutNameSugar.slice(0, -1);
|
|
53
|
+
if (pattern.includes('*')) {
|
|
54
|
+
throw new OriginRulesError(`invalid originRules key ${JSON.stringify(key)}: repeated '*' is not supported`);
|
|
55
|
+
}
|
|
56
|
+
return { pattern, exact: false };
|
|
57
|
+
}
|
|
58
|
+
return { pattern: withoutNameSugar, exact: true };
|
|
59
|
+
}
|
|
60
|
+
function normalizedRules(rules) {
|
|
61
|
+
if (!isPlainObject(rules)) {
|
|
62
|
+
throw new OriginRulesError('originRules must be a JSON object mapping namespace keys to git, console, agent, or any');
|
|
63
|
+
}
|
|
64
|
+
const normalized = [];
|
|
65
|
+
const seen = new Map();
|
|
66
|
+
for (const [key, value] of Object.entries(rules)) {
|
|
67
|
+
if (value !== 'git' && value !== 'console' && value !== 'agent' && value !== 'any') {
|
|
68
|
+
throw new OriginRulesError(`invalid originRules value for key ${JSON.stringify(key)}: expected 'git', 'console', 'agent', or 'any', got ${JSON.stringify(value)}`);
|
|
69
|
+
}
|
|
70
|
+
const shape = normalizeRuleKey(key);
|
|
71
|
+
const identity = `${shape.exact ? 'exact' : 'prefix'}:${shape.pattern}`;
|
|
72
|
+
const previous = seen.get(identity);
|
|
73
|
+
if (previous !== undefined) {
|
|
74
|
+
throw new OriginRulesError(`originRules keys ${JSON.stringify(previous)} and ${JSON.stringify(key)} have equal specificity after normalization; choose one`);
|
|
75
|
+
}
|
|
76
|
+
seen.set(identity, key);
|
|
77
|
+
normalized.push({ key, value, pattern: shape.pattern, exact: shape.exact });
|
|
78
|
+
}
|
|
79
|
+
return normalized;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Parse and validate the settings-file representation of origin rules.
|
|
83
|
+
* Malformed keys and values throw a named error instead of degrading to an
|
|
84
|
+
* empty rule set.
|
|
85
|
+
*/
|
|
86
|
+
export function parseOriginRules(raw) {
|
|
87
|
+
if (raw === undefined)
|
|
88
|
+
return Object.freeze({});
|
|
89
|
+
const rules = normalizedRules(raw);
|
|
90
|
+
const output = Object.create(null);
|
|
91
|
+
for (const rule of rules)
|
|
92
|
+
output[rule.key] = rule.value;
|
|
93
|
+
return Object.freeze(output);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Select one rule for a namespace. Exact keys win over every prefix; among
|
|
97
|
+
* prefixes, the longest matching prefix wins. The parser's equal-specificity
|
|
98
|
+
* error keeps this selection deterministic.
|
|
99
|
+
*/
|
|
100
|
+
export function matchOriginRule(rules, namespace) {
|
|
101
|
+
const normalized = normalizedRules(rules);
|
|
102
|
+
const exact = normalized.find((rule) => rule.exact && rule.pattern === namespace);
|
|
103
|
+
if (exact !== undefined)
|
|
104
|
+
return { key: exact.key, value: exact.value };
|
|
105
|
+
let best;
|
|
106
|
+
for (const rule of normalized) {
|
|
107
|
+
if (rule.exact || !namespace.startsWith(rule.pattern))
|
|
108
|
+
continue;
|
|
109
|
+
if (best === undefined || rule.pattern.length > best.pattern.length)
|
|
110
|
+
best = rule;
|
|
111
|
+
}
|
|
112
|
+
return best === undefined ? undefined : { key: best.key, value: best.value };
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Evaluate a verified or failed origin verdict against a minimum rule.
|
|
116
|
+
* `any` is no requirement; an invalid present sidecar remains a hard failure
|
|
117
|
+
* because a malformed signed statement is an attack signal, not absence.
|
|
118
|
+
*/
|
|
119
|
+
export function evaluateOriginRule(rule, verdict) {
|
|
120
|
+
if (verdict.kind === 'invalid')
|
|
121
|
+
return { ok: false, kind: 'invalid', detail: verdict.reason };
|
|
122
|
+
if (verdict.kind === 'absent') {
|
|
123
|
+
return rule === 'any'
|
|
124
|
+
? { ok: true }
|
|
125
|
+
: { ok: false, kind: 'absent', detail: 'no origin was recorded' };
|
|
126
|
+
}
|
|
127
|
+
if (verdict.kind === 'unverifiable') {
|
|
128
|
+
return rule === 'any'
|
|
129
|
+
? { ok: true }
|
|
130
|
+
: { ok: false, kind: 'unverifiable', detail: verdict.reason };
|
|
131
|
+
}
|
|
132
|
+
if (rule === 'any')
|
|
133
|
+
return { ok: true };
|
|
134
|
+
const actual = ORIGIN_SOURCE_RANK[verdict.source.kind];
|
|
135
|
+
const required = ORIGIN_SOURCE_RANK[rule];
|
|
136
|
+
if (actual >= required)
|
|
137
|
+
return { ok: true };
|
|
138
|
+
return {
|
|
139
|
+
ok: false,
|
|
140
|
+
kind: 'weaker',
|
|
141
|
+
detail: `origin source '${verdict.source.kind}' is weaker than the required '${rule}' origin`,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verification and monotone evaluation of admin-signed organization policy floors.
|
|
3
|
+
*
|
|
4
|
+
* This module consumes the exact DSSE envelope bytes supplied by a caller, verifies
|
|
5
|
+
* the frozen policy-floor record, and validates the signer's enrollment chain and
|
|
6
|
+
* organization-wide scope. It performs no filesystem or network I/O, and a hub or
|
|
7
|
+
* other relaying transport never authors, derives, or defaults a floor here.
|
|
8
|
+
*
|
|
9
|
+
* A floor is a minimum, never a replacement: effective definition policy is the
|
|
10
|
+
* stricter of local policy and the verified floor. Every absent or failed floor
|
|
11
|
+
* returns no floor to the merge function, so untrusted input can stall evaluation
|
|
12
|
+
* but can never weaken the driver's local policy.
|
|
13
|
+
*/
|
|
14
|
+
import type { GrantScope, PolicyFloor, PolicyFloorRecord } from './records.ts';
|
|
15
|
+
import { type ChainOptions } from './chain.ts';
|
|
16
|
+
import type { DefPolicy } from './verify-publication.ts';
|
|
17
|
+
/** The outcome of verifying one policy-floor envelope. */
|
|
18
|
+
export type PolicyFloorVerdict = {
|
|
19
|
+
kind: 'verified';
|
|
20
|
+
record: PolicyFloorRecord;
|
|
21
|
+
keyid: string;
|
|
22
|
+
signerScope: GrantScope;
|
|
23
|
+
} | {
|
|
24
|
+
kind: 'unverifiable';
|
|
25
|
+
reason: string;
|
|
26
|
+
} | {
|
|
27
|
+
kind: 'invalid';
|
|
28
|
+
reason: string;
|
|
29
|
+
};
|
|
30
|
+
/** Pure verification inputs; callers provide all trust material explicitly. */
|
|
31
|
+
export interface VerifyPolicyFloorInput {
|
|
32
|
+
/** Exact bytes of the stored or received DSSE envelope. */
|
|
33
|
+
envelopeBytes: Uint8Array;
|
|
34
|
+
/** Local organization-root public key anchor. */
|
|
35
|
+
orgRootPublicKey: string;
|
|
36
|
+
/** Raw enrollment-grant envelope bytes used by WP-D4 chain validation. */
|
|
37
|
+
grants: Uint8Array[];
|
|
38
|
+
/** Raw revocation envelope bytes used by WP-D4 chain validation. */
|
|
39
|
+
revocations?: Uint8Array[];
|
|
40
|
+
/** Explicit validation instant used for grant validity and revocation cuts. */
|
|
41
|
+
at: number;
|
|
42
|
+
}
|
|
43
|
+
/** Cryptographic seams used by verification and by hermetic tests. */
|
|
44
|
+
export interface VerifyPolicyFloorOptions {
|
|
45
|
+
/** Inject a signer for the candidate principal and one-key allowed-signers text. */
|
|
46
|
+
signerForPrincipal?: ChainOptions['signerForPrincipal'];
|
|
47
|
+
/** SSHSIG namespace used by the DSSE envelope. */
|
|
48
|
+
namespace?: string;
|
|
49
|
+
/** Maximum number of enrollment links accepted by WP-D4. */
|
|
50
|
+
maxChainDepth?: number;
|
|
51
|
+
}
|
|
52
|
+
/** Strictness ordering for the existing C2 definition-policy vocabulary. */
|
|
53
|
+
export declare const DEF_POLICY_RANK: Readonly<Record<DefPolicy, number>>;
|
|
54
|
+
/** Convert the frozen floor's unsigned-definition axis to C2's minimum policy. */
|
|
55
|
+
export declare function floorDefPolicyMinimum(floor: PolicyFloor): DefPolicy;
|
|
56
|
+
/** Convert the frozen floor's origin axis to the parallel local policy. */
|
|
57
|
+
export declare function originRulesMinimum(floor: PolicyFloor): DefPolicy;
|
|
58
|
+
/** Convert the frozen floor's unsigned-artifact axis to consume policy. */
|
|
59
|
+
export declare function artifactPolicyMinimum(floor: PolicyFloor): DefPolicy;
|
|
60
|
+
/** Return the stricter policy without assigning one policy over the other. */
|
|
61
|
+
export declare function stricterDefPolicy(a: DefPolicy, b: DefPolicy): DefPolicy;
|
|
62
|
+
/** One floor axis carried for diagnostics instead of silently dropped. */
|
|
63
|
+
export interface PolicyFloorGap {
|
|
64
|
+
axis: 'trustMode';
|
|
65
|
+
value: string;
|
|
66
|
+
reason: string;
|
|
67
|
+
}
|
|
68
|
+
/** The result of merging one optional verified floor into local policy. */
|
|
69
|
+
export interface PolicyFloorMergeResult {
|
|
70
|
+
effective: DefPolicy;
|
|
71
|
+
local: DefPolicy;
|
|
72
|
+
raised: boolean;
|
|
73
|
+
/** Effective local origin policy after applying the verified floor. */
|
|
74
|
+
originPolicy: DefPolicy;
|
|
75
|
+
/** Effective local artifact policy after applying the verified floor. */
|
|
76
|
+
artifactPolicy: DefPolicy;
|
|
77
|
+
gaps: PolicyFloorGap[];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Presets are concrete wire values, not a second policy-level primitive. The
|
|
81
|
+
* trustMode axis remains informational here; policyFloorGaps reports that
|
|
82
|
+
* unevaluated control rather than pretending this package implements it.
|
|
83
|
+
*/
|
|
84
|
+
export declare const POLICY_FLOOR_PRESETS: Readonly<Record<'L0' | 'L1' | 'L2', PolicyFloor>>;
|
|
85
|
+
/** Report every frozen axis that this engine does not evaluate yet. */
|
|
86
|
+
export declare function policyFloorGaps(floor: PolicyFloor): PolicyFloorGap[];
|
|
87
|
+
/**
|
|
88
|
+
* Merge a verified floor as a strictness minimum on both policy axes. The
|
|
89
|
+
* optional origin and artifact arguments preserve the existing positional API;
|
|
90
|
+
* callers that do not resolve either policy receive the neutral local value `off`.
|
|
91
|
+
*/
|
|
92
|
+
export declare function mergePolicyFloorWithLocal(local: DefPolicy, floor?: PolicyFloor, localOriginPolicy?: DefPolicy, localArtifactPolicy?: DefPolicy): PolicyFloorMergeResult;
|
|
93
|
+
/**
|
|
94
|
+
* Verify one exact policy-floor envelope, then validate its signer through WP-D4.
|
|
95
|
+
* The record's unauthenticated fields select candidates only; the verified signer
|
|
96
|
+
* key-id and the chain verdict authorize the floor.
|
|
97
|
+
*/
|
|
98
|
+
export declare function verifyPolicyFloorRecord(input: VerifyPolicyFloorInput, options?: VerifyPolicyFloorOptions): Promise<PolicyFloorVerdict>;
|