@odingard/guardian-sdk 0.1.0 → 0.2.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.
- package/README.md +252 -17
- package/dist/contracts.js +9865 -0
- package/dist/index.js +12976 -1787
- package/dist/public-catalog.v1.json +6915 -0
- package/dist-dts/catalog.d.ts +14 -0
- package/dist-dts/client.d.ts +51 -1
- package/dist-dts/contracts/action-pack.d.ts +464 -0
- package/dist-dts/contracts/action-registry.d.ts +91 -1
- package/dist-dts/contracts/action.d.ts +1408 -17
- package/dist-dts/contracts/agent-state.d.ts +386 -0
- package/dist-dts/contracts/approval.d.ts +224 -5
- package/dist-dts/contracts/assurance.d.ts +60 -0
- package/dist-dts/contracts/authority-graph.d.ts +294 -0
- package/dist-dts/contracts/authority-state.d.ts +17 -2
- package/dist-dts/contracts/authority.d.ts +31 -5
- package/dist-dts/contracts/billing.d.ts +32 -0
- package/dist-dts/contracts/calendar.d.ts +6 -6
- package/dist-dts/contracts/denial.d.ts +648 -0
- package/dist-dts/contracts/evidence.d.ts +73 -16
- package/dist-dts/contracts/execution.d.ts +449 -55
- package/dist-dts/contracts/identifiers.d.ts +16 -0
- package/dist-dts/contracts/index.d.ts +22 -0
- package/dist-dts/contracts/intent.d.ts +335 -0
- package/dist-dts/contracts/lineage.d.ts +218 -0
- package/dist-dts/contracts/local.d.ts +101 -0
- package/dist-dts/contracts/multi-principal.d.ts +292 -0
- package/dist-dts/contracts/multiparty.d.ts +169 -0
- package/dist-dts/contracts/obligation.d.ts +196 -0
- package/dist-dts/contracts/plan.d.ts +67 -0
- package/dist-dts/contracts/policy-simulation.d.ts +681 -0
- package/dist-dts/contracts/prerequisite.d.ts +147 -0
- package/dist-dts/contracts/protected-data.d.ts +67 -0
- package/dist-dts/contracts/receipt.d.ts +3126 -0
- package/dist-dts/contracts/resource-claims.d.ts +146 -0
- package/dist-dts/contracts/runtime.d.ts +111 -0
- package/dist-dts/contracts/safety-envelope.d.ts +287 -0
- package/dist-dts/contracts/sequence.d.ts +132 -0
- package/dist-dts/contracts/sources.d.ts +191 -0
- package/dist-dts/contracts/tools.d.ts +50 -5
- package/dist-dts/contracts/transaction.d.ts +360 -0
- package/dist-dts/contracts-entry.d.ts +1 -0
- package/dist-dts/embedded.d.ts +58 -0
- package/dist-dts/evidence/evidence.d.ts +25 -0
- package/dist-dts/evidence/receipt.d.ts +61 -0
- package/dist-dts/index.d.ts +5 -1
- package/dist-dts/lifecycle.d.ts +25 -0
- package/dist-dts/proposal.d.ts +16 -0
- package/dist-dts/receipts.d.ts +37 -0
- package/package.json +12 -6
- package/dist-dts/__tests__/client.test.d.ts +0 -1
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* WO-021 — Resource Claims v1 (`guardian.resource-claim.v1`).
|
|
4
|
+
*
|
|
5
|
+
* The universal resource model every action binding can be projected into:
|
|
6
|
+
* a leased connection's provider, owner, classifications, capabilities,
|
|
7
|
+
* relationships, attributes, constraints, region, assurance and version.
|
|
8
|
+
* Domain-specific binding facts (mailbox address, endpoint allowlist, tool
|
|
9
|
+
* catalog, path allowlists, delegation ceilings) keep their existing fields —
|
|
10
|
+
* `claimFromConnectionFacts` is the documented shim that derives the claim
|
|
11
|
+
* while the legacy fields stay authoritative for built-in definitions.
|
|
12
|
+
* Pack-defined actions evaluate `resource.*` facts declaratively through
|
|
13
|
+
* claim rules; nothing in this file executes pack-supplied logic.
|
|
14
|
+
*/
|
|
15
|
+
export declare const RESOURCE_CLAIM_FORMAT = "guardian.resource-claim.v1";
|
|
16
|
+
export declare const CLAIM_MAX_ATTRIBUTES = 32;
|
|
17
|
+
export declare const CLAIM_MAX_CONSTRAINTS = 32;
|
|
18
|
+
export declare const CLAIM_MAX_CLASSIFICATIONS = 32;
|
|
19
|
+
export declare const CLAIM_MAX_CAPABILITIES = 128;
|
|
20
|
+
export declare const CLAIM_MAX_RELATIONSHIPS = 64;
|
|
21
|
+
export declare const CLAIM_ATTRIBUTE_MAX_BYTES = 8192;
|
|
22
|
+
export declare const CLAIM_RULES_MAX = 32;
|
|
23
|
+
export declare const BINDING_RULES_MAX = 16;
|
|
24
|
+
/** A bounded canonical JSON fact: no cycles, accessors or exotic prototypes. */
|
|
25
|
+
export declare const ClaimFactSchema: z.ZodUnknown;
|
|
26
|
+
export type ClaimFact = z.infer<typeof ClaimFactSchema>;
|
|
27
|
+
export declare const ClaimPathSchema: z.ZodString;
|
|
28
|
+
export type ClaimPath = z.infer<typeof ClaimPathSchema>;
|
|
29
|
+
export declare const ResourceRelationshipSchema: z.ZodObject<{
|
|
30
|
+
kind: z.ZodString;
|
|
31
|
+
target: z.ZodString;
|
|
32
|
+
}, z.core.$strict>;
|
|
33
|
+
export type ResourceRelationship = z.infer<typeof ResourceRelationshipSchema>;
|
|
34
|
+
export declare const ResourceClaimSchema: z.ZodObject<{
|
|
35
|
+
claim: z.ZodLiteral<"guardian.resource-claim.v1">;
|
|
36
|
+
type: z.ZodString;
|
|
37
|
+
id: z.ZodString;
|
|
38
|
+
provider: z.ZodString;
|
|
39
|
+
owner: z.ZodString;
|
|
40
|
+
classifications: z.ZodArray<z.ZodString>;
|
|
41
|
+
capabilities: z.ZodArray<z.ZodString>;
|
|
42
|
+
relationships: z.ZodArray<z.ZodObject<{
|
|
43
|
+
kind: z.ZodString;
|
|
44
|
+
target: z.ZodString;
|
|
45
|
+
}, z.core.$strict>>;
|
|
46
|
+
attributes: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
47
|
+
constraints: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
48
|
+
region: z.ZodOptional<z.ZodString>;
|
|
49
|
+
assurance: z.ZodOptional<z.ZodString>;
|
|
50
|
+
version: z.ZodNumber;
|
|
51
|
+
}, z.core.$strict>;
|
|
52
|
+
export type ResourceClaim = z.infer<typeof ResourceClaimSchema>;
|
|
53
|
+
/**
|
|
54
|
+
* Declarative rule over `resource.*` facts. Ops:
|
|
55
|
+
* - `eq` / `neq`: canonical equality / inequality of the resolved fact
|
|
56
|
+
* - `in`: the resolved scalar fact is a member of the rule's value list
|
|
57
|
+
* - `includes`: the resolved list fact contains the rule's value
|
|
58
|
+
* - `excludes`: the resolved list fact does not contain the rule's value
|
|
59
|
+
* A rule whose path resolves to `undefined` fails closed.
|
|
60
|
+
*/
|
|
61
|
+
export declare const ClaimRuleSchema: z.ZodObject<{
|
|
62
|
+
path: z.ZodString;
|
|
63
|
+
op: z.ZodEnum<{
|
|
64
|
+
in: "in";
|
|
65
|
+
includes: "includes";
|
|
66
|
+
eq: "eq";
|
|
67
|
+
neq: "neq";
|
|
68
|
+
excludes: "excludes";
|
|
69
|
+
}>;
|
|
70
|
+
value: z.ZodUnknown;
|
|
71
|
+
}, z.core.$strict>;
|
|
72
|
+
export type ClaimRule = z.infer<typeof ClaimRuleSchema>;
|
|
73
|
+
/**
|
|
74
|
+
* Declarative binding rule: a material-parameter field checked against a
|
|
75
|
+
* resolved claim list (or the scalar claim fact). Ops:
|
|
76
|
+
* - `within`: the param is an endpoint inside the claim's allowlist entries
|
|
77
|
+
* (same prefix+host semantics as the api.endpoint allowlist binding)
|
|
78
|
+
* - `memberOf`: the param string equals one of the claim list's entries
|
|
79
|
+
*/
|
|
80
|
+
export declare const BindingRuleSchema: z.ZodObject<{
|
|
81
|
+
field: z.ZodString;
|
|
82
|
+
claim: z.ZodString;
|
|
83
|
+
op: z.ZodEnum<{
|
|
84
|
+
within: "within";
|
|
85
|
+
memberOf: "memberOf";
|
|
86
|
+
}>;
|
|
87
|
+
}, z.core.$strict>;
|
|
88
|
+
export type BindingRule = z.infer<typeof BindingRuleSchema>;
|
|
89
|
+
/** The connection facts the claims shim projects (mirrors the binding shape). */
|
|
90
|
+
export type ConnectionClaimFacts = Readonly<{
|
|
91
|
+
provider: string;
|
|
92
|
+
connectionId?: string;
|
|
93
|
+
principalId?: string;
|
|
94
|
+
mailboxAddress?: string;
|
|
95
|
+
endpointAllowlist?: readonly string[];
|
|
96
|
+
toolServer?: Readonly<{
|
|
97
|
+
serverName: string;
|
|
98
|
+
serverVersion: string;
|
|
99
|
+
tools: readonly {
|
|
100
|
+
name: string;
|
|
101
|
+
}[];
|
|
102
|
+
}>;
|
|
103
|
+
enabledToolNames?: readonly string[];
|
|
104
|
+
calendarId?: string;
|
|
105
|
+
pathAllowlist?: readonly string[];
|
|
106
|
+
shareAllowlist?: readonly string[];
|
|
107
|
+
protectedCatalog?: readonly {
|
|
108
|
+
fieldRef: string;
|
|
109
|
+
allowUse: boolean;
|
|
110
|
+
allowView: boolean;
|
|
111
|
+
}[];
|
|
112
|
+
bondedSubAgentIds?: readonly string[];
|
|
113
|
+
delegationCeilings?: Readonly<Record<string, {
|
|
114
|
+
actionIds: readonly string[];
|
|
115
|
+
}>>;
|
|
116
|
+
}>;
|
|
117
|
+
/**
|
|
118
|
+
* The WO-021 migration shim: projects today's vertical binding fields into a
|
|
119
|
+
* universal Resource Claim. Built-in definitions keep reading the legacy
|
|
120
|
+
* fields; pack-defined actions read only the claim.
|
|
121
|
+
*/
|
|
122
|
+
export declare function claimFromConnectionFacts(connection: ConnectionClaimFacts): ResourceClaim;
|
|
123
|
+
/** Resolves a `resource.*` dotted path to the claim fact (or undefined). */
|
|
124
|
+
export declare function resolveClaimPath(claim: ResourceClaim, path: string): unknown;
|
|
125
|
+
/**
|
|
126
|
+
* Evaluates a declarative claim policy over resolved `resource.*` facts.
|
|
127
|
+
* Deterministic and bounded: no pack-supplied code runs — rules are data.
|
|
128
|
+
*/
|
|
129
|
+
export declare function evaluateClaimRules(claim: ResourceClaim, rules: readonly ClaimRule[]): {
|
|
130
|
+
ok: true;
|
|
131
|
+
} | {
|
|
132
|
+
ok: false;
|
|
133
|
+
reasonCode: string;
|
|
134
|
+
path: string;
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* Evaluates declarative binding rules: a material-parameter value checked
|
|
138
|
+
* against a resolved claim fact. Fails closed on a missing or mistyped fact.
|
|
139
|
+
*/
|
|
140
|
+
export declare function evaluateBindingRules(claim: ResourceClaim, params: Record<string, unknown>, rules: readonly BindingRule[]): {
|
|
141
|
+
ok: true;
|
|
142
|
+
} | {
|
|
143
|
+
ok: false;
|
|
144
|
+
reasonCode: string;
|
|
145
|
+
field: string;
|
|
146
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* WO-026: guardian.runtime.v1 — runtime attestation facts contract
|
|
4
|
+
* (GUA-AUTHORITY-OS-001 §24–25).
|
|
5
|
+
*
|
|
6
|
+
* Attestation facts are recorded surface evidence supplied by platforms
|
|
7
|
+
* that support them. Guardian never invents them: a field that is absent
|
|
8
|
+
* simply does not exist, and the computed level never rises on missing
|
|
9
|
+
* facts. A model/agent assertion is never evidence — only facts recorded
|
|
10
|
+
* through the injected attestation port feed the ladder.
|
|
11
|
+
*
|
|
12
|
+
* The trusted-runtime ladder is deterministic (§25):
|
|
13
|
+
*
|
|
14
|
+
* T4 HARDWARE-BACKED — secureHardwareEvidence recorded
|
|
15
|
+
* T3 ATTESTED — attestation evidence from an issuer
|
|
16
|
+
* (attestationIssuer + attestedAt, or recorded
|
|
17
|
+
* cloudWorkloadEvidence)
|
|
18
|
+
* T2 VERIFIED — signed/verified workload or binary identity
|
|
19
|
+
* (workloadIdentity, binaryIdentity,
|
|
20
|
+
* packageIdentity, or containerIdentity recorded)
|
|
21
|
+
* T1 IDENTIFIED — a stable runtime identity is recorded
|
|
22
|
+
* (runtimeIdentity or deviceIdentity)
|
|
23
|
+
* T0 UNKNOWN — nothing else recorded
|
|
24
|
+
*
|
|
25
|
+
* Precedence is strongest-evidence: the highest level any recorded fact
|
|
26
|
+
* supports wins; lower facts never pull the level down.
|
|
27
|
+
*/
|
|
28
|
+
export declare const RUNTIME_CONTRACT_SCHEMA = "guardian.runtime.v1";
|
|
29
|
+
/** Ordered trusted-runtime ladder (lowest → highest). */
|
|
30
|
+
export declare const TrustedRuntimeLevelSchema: z.ZodEnum<{
|
|
31
|
+
T0_UNKNOWN: "T0_UNKNOWN";
|
|
32
|
+
T1_IDENTIFIED: "T1_IDENTIFIED";
|
|
33
|
+
T2_VERIFIED: "T2_VERIFIED";
|
|
34
|
+
T3_ATTESTED: "T3_ATTESTED";
|
|
35
|
+
T4_HARDWARE_BACKED: "T4_HARDWARE_BACKED";
|
|
36
|
+
}>;
|
|
37
|
+
export type TrustedRuntimeLevel = z.infer<typeof TrustedRuntimeLevelSchema>;
|
|
38
|
+
export declare const TRUSTED_RUNTIME_RANK: Record<TrustedRuntimeLevel, number>;
|
|
39
|
+
/** Human-readable level names for display surfaces (§27). */
|
|
40
|
+
export declare const TRUSTED_RUNTIME_LABEL: Record<TrustedRuntimeLevel, string>;
|
|
41
|
+
export declare function trustedRuntimeExceeds(value: TrustedRuntimeLevel, floor: TrustedRuntimeLevel): boolean;
|
|
42
|
+
export declare function trustedRuntimeBelow(value: TrustedRuntimeLevel, floor: TrustedRuntimeLevel): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Recorded attestation facts for an invoking runtime (§24). Every field is
|
|
45
|
+
* optional: platforms that cannot supply a fact leave it absent and the
|
|
46
|
+
* ladder lowers accordingly — facts are never fabricated.
|
|
47
|
+
*/
|
|
48
|
+
export declare const RuntimeAttestationFactsSchema: z.ZodObject<{
|
|
49
|
+
runtimeIdentity: z.ZodOptional<z.ZodString>;
|
|
50
|
+
deviceIdentity: z.ZodOptional<z.ZodString>;
|
|
51
|
+
workloadIdentity: z.ZodOptional<z.ZodString>;
|
|
52
|
+
binaryIdentity: z.ZodOptional<z.ZodString>;
|
|
53
|
+
packageIdentity: z.ZodOptional<z.ZodString>;
|
|
54
|
+
containerIdentity: z.ZodOptional<z.ZodString>;
|
|
55
|
+
modelIdentity: z.ZodOptional<z.ZodString>;
|
|
56
|
+
agentVersion: z.ZodOptional<z.ZodString>;
|
|
57
|
+
secureHardwareEvidence: z.ZodOptional<z.ZodString>;
|
|
58
|
+
cloudWorkloadEvidence: z.ZodOptional<z.ZodString>;
|
|
59
|
+
executionEnvironment: z.ZodOptional<z.ZodString>;
|
|
60
|
+
networkContext: z.ZodOptional<z.ZodString>;
|
|
61
|
+
region: z.ZodOptional<z.ZodString>;
|
|
62
|
+
attestedAt: z.ZodOptional<z.ZodNumber>;
|
|
63
|
+
attestationIssuer: z.ZodOptional<z.ZodString>;
|
|
64
|
+
}, z.core.$strict>;
|
|
65
|
+
export type RuntimeAttestationFacts = z.infer<typeof RuntimeAttestationFactsSchema>;
|
|
66
|
+
export interface RuntimeTrustComputation {
|
|
67
|
+
level: TrustedRuntimeLevel;
|
|
68
|
+
/** The recorded fact names the level was computed from. */
|
|
69
|
+
evidence: readonly string[];
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Pure, deterministic level computation over recorded facts. Missing or
|
|
73
|
+
* empty facts never raise the level; an absent facts object yields T0.
|
|
74
|
+
*/
|
|
75
|
+
export declare function computeRuntimeTrustLevel(facts: RuntimeAttestationFacts | null | undefined): RuntimeTrustComputation;
|
|
76
|
+
/**
|
|
77
|
+
* Runtime policy declared on guardian.intent.v1 (`runtime` field) —
|
|
78
|
+
* narrows, denies, or forces approval over the computed trusted-runtime
|
|
79
|
+
* level; never enlarges authority (§25, K15).
|
|
80
|
+
*/
|
|
81
|
+
export declare const RuntimePolicySchema: z.ZodObject<{
|
|
82
|
+
minLevel: z.ZodOptional<z.ZodEnum<{
|
|
83
|
+
T0_UNKNOWN: "T0_UNKNOWN";
|
|
84
|
+
T1_IDENTIFIED: "T1_IDENTIFIED";
|
|
85
|
+
T2_VERIFIED: "T2_VERIFIED";
|
|
86
|
+
T3_ATTESTED: "T3_ATTESTED";
|
|
87
|
+
T4_HARDWARE_BACKED: "T4_HARDWARE_BACKED";
|
|
88
|
+
}>>;
|
|
89
|
+
requireApprovalBelow: z.ZodOptional<z.ZodEnum<{
|
|
90
|
+
T0_UNKNOWN: "T0_UNKNOWN";
|
|
91
|
+
T1_IDENTIFIED: "T1_IDENTIFIED";
|
|
92
|
+
T2_VERIFIED: "T2_VERIFIED";
|
|
93
|
+
T3_ATTESTED: "T3_ATTESTED";
|
|
94
|
+
T4_HARDWARE_BACKED: "T4_HARDWARE_BACKED";
|
|
95
|
+
}>>;
|
|
96
|
+
}, z.core.$strict>;
|
|
97
|
+
export type RuntimePolicy = z.infer<typeof RuntimePolicySchema>;
|
|
98
|
+
/**
|
|
99
|
+
* Evaluate a declared runtime policy over the computed level. Pure:
|
|
100
|
+
* reports deny | require_approval | allowed with a deterministic rule ref
|
|
101
|
+
* and never mutates authority.
|
|
102
|
+
*/
|
|
103
|
+
export declare function evaluateRuntimePolicy(policy: RuntimePolicy | undefined, level: TrustedRuntimeLevel): {
|
|
104
|
+
verdict: "deny";
|
|
105
|
+
ruleId: string;
|
|
106
|
+
} | {
|
|
107
|
+
verdict: "require_approval";
|
|
108
|
+
ruleId: string;
|
|
109
|
+
} | {
|
|
110
|
+
verdict: "allowed";
|
|
111
|
+
};
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* WO-029: guardian.safety_envelope.v1 — generic physical safety envelope
|
|
4
|
+
* (GUA-AUTHORITY-OS-001 §38–40, §79, §88–89, K15).
|
|
5
|
+
*
|
|
6
|
+
* Physical actions keep the SAME kernel and gain declarative constraint
|
|
7
|
+
* facts on the canonical action envelope (§38): zone, speed, payload,
|
|
8
|
+
* force, hours, human distance. Nothing robotics-specific enters the
|
|
9
|
+
* kernel — these are generic policy facts evaluated deterministically.
|
|
10
|
+
*
|
|
11
|
+
* §39 — a generic safety-envelope structure evaluated by the pure
|
|
12
|
+
* evaluator below. A violation denies or narrows (supervision_required
|
|
13
|
+
* narrows to ASK); the evaluator never warns-and-allows and never
|
|
14
|
+
* enlarges authority.
|
|
15
|
+
*
|
|
16
|
+
* §40 — offline authority may narrow, it may never expand. When fresh
|
|
17
|
+
* authority cannot be obtained for a safety-critical physical operation,
|
|
18
|
+
* the system defaults to the previously recorded safe state; it never
|
|
19
|
+
* invents ALLOW. Edge enforcement is bounded by the freshest recorded
|
|
20
|
+
* authority: a local evaluator may only enforce a decision
|
|
21
|
+
* equal-to-or-narrower than the recorded snapshot, and a stale snapshot
|
|
22
|
+
* fails closed.
|
|
23
|
+
*/
|
|
24
|
+
export declare const SAFETY_ENVELOPE_CONTRACT_SCHEMA = "guardian.safety_envelope.v1";
|
|
25
|
+
/**
|
|
26
|
+
* Declarative constraint facts a physical action carries on its
|
|
27
|
+
* material envelope. All values are generic numbers in whatever unit
|
|
28
|
+
* the governing envelope declares — the kernel never interprets units.
|
|
29
|
+
* Absent facts are simply not checked against the matching cap.
|
|
30
|
+
*/
|
|
31
|
+
export declare const PhysicalActionFactsSchema: z.ZodObject<{
|
|
32
|
+
zone: z.ZodOptional<z.ZodString>;
|
|
33
|
+
speed: z.ZodOptional<z.ZodNumber>;
|
|
34
|
+
force: z.ZodOptional<z.ZodNumber>;
|
|
35
|
+
payload: z.ZodOptional<z.ZodNumber>;
|
|
36
|
+
atEpochMs: z.ZodOptional<z.ZodNumber>;
|
|
37
|
+
humanDistance: z.ZodOptional<z.ZodNumber>;
|
|
38
|
+
environment: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
39
|
+
supervised: z.ZodOptional<z.ZodBoolean>;
|
|
40
|
+
}, z.core.$strict>;
|
|
41
|
+
export type PhysicalActionFacts = z.infer<typeof PhysicalActionFactsSchema>;
|
|
42
|
+
/**
|
|
43
|
+
* A wall-clock window in minutes-of-day, e.g. 06:00–18:00 is
|
|
44
|
+
* { startMinutesOfDay: 360, endMinutesOfDay: 1080 }. An end earlier
|
|
45
|
+
* than the start wraps midnight (22:00–06:00).
|
|
46
|
+
*/
|
|
47
|
+
export declare const SafetyTimeWindowSchema: z.ZodObject<{
|
|
48
|
+
startMinutesOfDay: z.ZodNumber;
|
|
49
|
+
endMinutesOfDay: z.ZodNumber;
|
|
50
|
+
}, z.core.$strict>;
|
|
51
|
+
export type SafetyTimeWindow = z.infer<typeof SafetyTimeWindowSchema>;
|
|
52
|
+
/**
|
|
53
|
+
* The generic safety-envelope structure (§39). Every field is a generic
|
|
54
|
+
* policy fact — nothing hardware- or robotics-specific. Declared on the
|
|
55
|
+
* governing intent (and persisted as a safety_envelope record); the
|
|
56
|
+
* evaluator checks the action's material facts against it.
|
|
57
|
+
*/
|
|
58
|
+
export declare const SafetyEnvelopeSchema: z.ZodObject<{
|
|
59
|
+
schema: z.ZodLiteral<"guardian.safety_envelope.v1">;
|
|
60
|
+
allowedZone: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
61
|
+
forbiddenZone: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
62
|
+
maxSpeed: z.ZodOptional<z.ZodNumber>;
|
|
63
|
+
maxForce: z.ZodOptional<z.ZodNumber>;
|
|
64
|
+
maxPayload: z.ZodOptional<z.ZodNumber>;
|
|
65
|
+
timeWindow: z.ZodOptional<z.ZodObject<{
|
|
66
|
+
startMinutesOfDay: z.ZodNumber;
|
|
67
|
+
endMinutesOfDay: z.ZodNumber;
|
|
68
|
+
}, z.core.$strict>>;
|
|
69
|
+
proximityConstraints: z.ZodOptional<z.ZodObject<{
|
|
70
|
+
minHumanDistance: z.ZodNumber;
|
|
71
|
+
}, z.core.$strict>>;
|
|
72
|
+
environmentConditions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
73
|
+
supervisionRequired: z.ZodOptional<z.ZodBoolean>;
|
|
74
|
+
failSafeAction: z.ZodOptional<z.ZodString>;
|
|
75
|
+
emergencyStop: z.ZodOptional<z.ZodBoolean>;
|
|
76
|
+
}, z.core.$strict>;
|
|
77
|
+
export type SafetyEnvelope = z.infer<typeof SafetyEnvelopeSchema>;
|
|
78
|
+
export declare function safetyEnvelopeDigest(envelope: SafetyEnvelope): string;
|
|
79
|
+
export declare const SafetyViolationSchema: z.ZodEnum<{
|
|
80
|
+
OUT_OF_ZONE: "OUT_OF_ZONE";
|
|
81
|
+
FORBIDDEN_ZONE: "FORBIDDEN_ZONE";
|
|
82
|
+
OVER_SPEED: "OVER_SPEED";
|
|
83
|
+
OVER_FORCE: "OVER_FORCE";
|
|
84
|
+
OVER_PAYLOAD: "OVER_PAYLOAD";
|
|
85
|
+
OUTSIDE_TIME_WINDOW: "OUTSIDE_TIME_WINDOW";
|
|
86
|
+
PROXIMITY_VIOLATION: "PROXIMITY_VIOLATION";
|
|
87
|
+
ENVIRONMENT_VIOLATION: "ENVIRONMENT_VIOLATION";
|
|
88
|
+
SUPERVISION_REQUIRED: "SUPERVISION_REQUIRED";
|
|
89
|
+
}>;
|
|
90
|
+
export type SafetyViolation = z.infer<typeof SafetyViolationSchema>;
|
|
91
|
+
/** Deterministic outcome of evaluating an envelope against action facts. */
|
|
92
|
+
export declare const SafetyEnvelopeOutcomeSchema: z.ZodObject<{
|
|
93
|
+
envelopeDigest: z.ZodString;
|
|
94
|
+
satisfied: z.ZodBoolean;
|
|
95
|
+
violations: z.ZodArray<z.ZodEnum<{
|
|
96
|
+
OUT_OF_ZONE: "OUT_OF_ZONE";
|
|
97
|
+
FORBIDDEN_ZONE: "FORBIDDEN_ZONE";
|
|
98
|
+
OVER_SPEED: "OVER_SPEED";
|
|
99
|
+
OVER_FORCE: "OVER_FORCE";
|
|
100
|
+
OVER_PAYLOAD: "OVER_PAYLOAD";
|
|
101
|
+
OUTSIDE_TIME_WINDOW: "OUTSIDE_TIME_WINDOW";
|
|
102
|
+
PROXIMITY_VIOLATION: "PROXIMITY_VIOLATION";
|
|
103
|
+
ENVIRONMENT_VIOLATION: "ENVIRONMENT_VIOLATION";
|
|
104
|
+
SUPERVISION_REQUIRED: "SUPERVISION_REQUIRED";
|
|
105
|
+
}>>;
|
|
106
|
+
emergencyStopped: z.ZodBoolean;
|
|
107
|
+
failSafeApplied: z.ZodBoolean;
|
|
108
|
+
}, z.core.$strict>;
|
|
109
|
+
export type SafetyEnvelopeOutcome = z.infer<typeof SafetyEnvelopeOutcomeSchema>;
|
|
110
|
+
export type SafetyEnvelopeEvaluation = Readonly<{
|
|
111
|
+
satisfied: boolean;
|
|
112
|
+
violations: readonly SafetyViolation[];
|
|
113
|
+
/**
|
|
114
|
+
* Violations that NARROW to ASK instead of denying. Only
|
|
115
|
+
* supervision_required narrows; every other violation is a hard deny.
|
|
116
|
+
*/
|
|
117
|
+
narrowsToApproval: boolean;
|
|
118
|
+
}>;
|
|
119
|
+
/**
|
|
120
|
+
* Pure deterministic evaluator (§39): checks a declared safety envelope
|
|
121
|
+
* against the action's material facts — inside allowed zone AND outside
|
|
122
|
+
* forbidden zone (forbidden wins even inside allowed), within max
|
|
123
|
+
* speed/force/payload, inside the time window, proximity/environment/
|
|
124
|
+
* supervision satisfied. A violation never warns-and-allows.
|
|
125
|
+
*/
|
|
126
|
+
export declare function evaluateSafetyEnvelope(envelope: SafetyEnvelope, facts: PhysicalActionFacts, nowEpochMs: number): SafetyEnvelopeEvaluation;
|
|
127
|
+
/**
|
|
128
|
+
* The recorded emergency-stop state for one resource (§38 "always
|
|
129
|
+
* enforce"). An engaged state takes precedence over every other envelope
|
|
130
|
+
* field and is invocable independent of any pending action. Once
|
|
131
|
+
* engaged, all governed physical actions for that resource deny until
|
|
132
|
+
* explicitly cleared by authority.
|
|
133
|
+
*/
|
|
134
|
+
export declare const EmergencyStopStateSchema: z.ZodObject<{
|
|
135
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
136
|
+
tenantId: z.core.$ZodBranded<z.ZodString, "TenantId", "out">;
|
|
137
|
+
resource: z.ZodString;
|
|
138
|
+
engaged: z.ZodBoolean;
|
|
139
|
+
engagedAtEpochMs: z.ZodNullable<z.ZodNumber>;
|
|
140
|
+
engagedBy: z.ZodNullable<z.core.$ZodBranded<z.ZodString, "PrincipalId", "out">>;
|
|
141
|
+
reason: z.ZodNullable<z.ZodString>;
|
|
142
|
+
clearedAtEpochMs: z.ZodNullable<z.ZodNumber>;
|
|
143
|
+
clearedBy: z.ZodNullable<z.core.$ZodBranded<z.ZodString, "PrincipalId", "out">>;
|
|
144
|
+
version: z.ZodNumber;
|
|
145
|
+
}, z.core.$strict>;
|
|
146
|
+
export type EmergencyStopState = z.infer<typeof EmergencyStopStateSchema>;
|
|
147
|
+
export declare const EmergencyStopCommandSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
148
|
+
kind: z.ZodLiteral<"engage">;
|
|
149
|
+
reason: z.ZodString;
|
|
150
|
+
actor: z.core.$ZodBranded<z.ZodString, "PrincipalId", "out">;
|
|
151
|
+
expectedVersion: z.ZodNumber;
|
|
152
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
153
|
+
kind: z.ZodLiteral<"clear">;
|
|
154
|
+
reason: z.ZodString;
|
|
155
|
+
actor: z.core.$ZodBranded<z.ZodString, "PrincipalId", "out">;
|
|
156
|
+
expectedVersion: z.ZodNumber;
|
|
157
|
+
}, z.core.$strict>], "kind">;
|
|
158
|
+
export type EmergencyStopCommand = z.infer<typeof EmergencyStopCommandSchema>;
|
|
159
|
+
export type EmergencyStopTransitionResult = Readonly<{
|
|
160
|
+
ok: true;
|
|
161
|
+
record: EmergencyStopState;
|
|
162
|
+
}> | Readonly<{
|
|
163
|
+
ok: false;
|
|
164
|
+
reasonCode: "MALFORMED_RECORD" | "MALFORMED_COMMAND" | "STALE_VERSION" | "INVALID_TRANSITION";
|
|
165
|
+
}>;
|
|
166
|
+
/**
|
|
167
|
+
* Pure transition for the emergency-stop state machine (CAS-driven like
|
|
168
|
+
* the transaction evaluator). Engage is idempotent — an already-engaged
|
|
169
|
+
* stop stays engaged; only an explicit `clear` releases it.
|
|
170
|
+
*/
|
|
171
|
+
export declare function transitionEmergencyStop(recordInput: unknown, commandInput: unknown, nowEpochMs: number): EmergencyStopTransitionResult;
|
|
172
|
+
/**
|
|
173
|
+
* The freshest recorded authority snapshot an edge evaluator is bounded
|
|
174
|
+
* by (§40): the last recorded envelope + emergency-stop state plus
|
|
175
|
+
* freshness facts. The edge may only enforce a decision
|
|
176
|
+
* equal-to-or-narrower than this snapshot — and only while it is fresh.
|
|
177
|
+
*/
|
|
178
|
+
export declare const EdgeAuthoritySnapshotSchema: z.ZodObject<{
|
|
179
|
+
tenantId: z.core.$ZodBranded<z.ZodString, "TenantId", "out">;
|
|
180
|
+
resource: z.ZodString;
|
|
181
|
+
envelope: z.ZodNullable<z.ZodObject<{
|
|
182
|
+
schema: z.ZodLiteral<"guardian.safety_envelope.v1">;
|
|
183
|
+
allowedZone: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
184
|
+
forbiddenZone: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
185
|
+
maxSpeed: z.ZodOptional<z.ZodNumber>;
|
|
186
|
+
maxForce: z.ZodOptional<z.ZodNumber>;
|
|
187
|
+
maxPayload: z.ZodOptional<z.ZodNumber>;
|
|
188
|
+
timeWindow: z.ZodOptional<z.ZodObject<{
|
|
189
|
+
startMinutesOfDay: z.ZodNumber;
|
|
190
|
+
endMinutesOfDay: z.ZodNumber;
|
|
191
|
+
}, z.core.$strict>>;
|
|
192
|
+
proximityConstraints: z.ZodOptional<z.ZodObject<{
|
|
193
|
+
minHumanDistance: z.ZodNumber;
|
|
194
|
+
}, z.core.$strict>>;
|
|
195
|
+
environmentConditions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
196
|
+
supervisionRequired: z.ZodOptional<z.ZodBoolean>;
|
|
197
|
+
failSafeAction: z.ZodOptional<z.ZodString>;
|
|
198
|
+
emergencyStop: z.ZodOptional<z.ZodBoolean>;
|
|
199
|
+
}, z.core.$strict>>;
|
|
200
|
+
emergencyStop: z.ZodNullable<z.ZodObject<{
|
|
201
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
202
|
+
tenantId: z.core.$ZodBranded<z.ZodString, "TenantId", "out">;
|
|
203
|
+
resource: z.ZodString;
|
|
204
|
+
engaged: z.ZodBoolean;
|
|
205
|
+
engagedAtEpochMs: z.ZodNullable<z.ZodNumber>;
|
|
206
|
+
engagedBy: z.ZodNullable<z.core.$ZodBranded<z.ZodString, "PrincipalId", "out">>;
|
|
207
|
+
reason: z.ZodNullable<z.ZodString>;
|
|
208
|
+
clearedAtEpochMs: z.ZodNullable<z.ZodNumber>;
|
|
209
|
+
clearedBy: z.ZodNullable<z.core.$ZodBranded<z.ZodString, "PrincipalId", "out">>;
|
|
210
|
+
version: z.ZodNumber;
|
|
211
|
+
}, z.core.$strict>>;
|
|
212
|
+
freshnessEpochMs: z.ZodNumber;
|
|
213
|
+
maxAgeMs: z.ZodNumber;
|
|
214
|
+
}, z.core.$strict>;
|
|
215
|
+
export type EdgeAuthoritySnapshot = z.infer<typeof EdgeAuthoritySnapshotSchema>;
|
|
216
|
+
export declare const EdgeDecisionSchema: z.ZodEnum<{
|
|
217
|
+
deny: "deny";
|
|
218
|
+
allow: "allow";
|
|
219
|
+
fail_safe: "fail_safe";
|
|
220
|
+
}>;
|
|
221
|
+
export type EdgeDecision = z.infer<typeof EdgeDecisionSchema>;
|
|
222
|
+
export type EdgeEvaluationResult = Readonly<{
|
|
223
|
+
decision: EdgeDecision;
|
|
224
|
+
violations: readonly SafetyViolation[];
|
|
225
|
+
/** True when the emergency-stop state overrode every other field. */
|
|
226
|
+
emergencyStopped: boolean;
|
|
227
|
+
/** True when the snapshot was too stale to allow anything but fail-safe. */
|
|
228
|
+
staleAuthority: boolean;
|
|
229
|
+
}>;
|
|
230
|
+
/**
|
|
231
|
+
* §40 — edge enforcement contract: a local evaluator may only enforce a
|
|
232
|
+
* decision equal-to-or-narrower than the freshest recorded authority,
|
|
233
|
+
* bounded by envelope freshness facts. A stale snapshot or an engaged
|
|
234
|
+
* emergency stop fails closed — the edge can never invent ALLOW.
|
|
235
|
+
*/
|
|
236
|
+
export declare function evaluateEdgeDecision(snapshot: EdgeAuthoritySnapshot, facts: PhysicalActionFacts, nowEpochMs: number): EdgeEvaluationResult;
|
|
237
|
+
export type OfflineAuthorityResolution = Readonly<{
|
|
238
|
+
/** The envelope the offline path enforces (recorded, never invented). */
|
|
239
|
+
envelope: SafetyEnvelope | null;
|
|
240
|
+
/** True when fresh authority could not be obtained → recorded safe state. */
|
|
241
|
+
degraded: boolean;
|
|
242
|
+
/** The recorded fail-safe posture name, when declared. */
|
|
243
|
+
failSafeAction: string | null;
|
|
244
|
+
}>;
|
|
245
|
+
/**
|
|
246
|
+
* §40 — offline narrowing: offline authority may narrow, it may never
|
|
247
|
+
* expand. When fresh authority cannot be obtained the system defaults to
|
|
248
|
+
* the previously recorded safe state; it never invents ALLOW. A fresh
|
|
249
|
+
* envelope simply returns itself (it can still only narrow through
|
|
250
|
+
* evaluation); a missing one degrades to the recorded envelope's
|
|
251
|
+
* fail-safe posture.
|
|
252
|
+
*/
|
|
253
|
+
export declare function resolveOfflineAuthority(input: {
|
|
254
|
+
fresh: SafetyEnvelope | null;
|
|
255
|
+
recorded: SafetyEnvelope | null;
|
|
256
|
+
}): OfflineAuthorityResolution;
|
|
257
|
+
/** A recorded safety envelope for one governed resource. */
|
|
258
|
+
export declare const SafetyEnvelopeRecordSchema: z.ZodObject<{
|
|
259
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
260
|
+
tenantId: z.core.$ZodBranded<z.ZodString, "TenantId", "out">;
|
|
261
|
+
resource: z.ZodString;
|
|
262
|
+
envelope: z.ZodObject<{
|
|
263
|
+
schema: z.ZodLiteral<"guardian.safety_envelope.v1">;
|
|
264
|
+
allowedZone: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
265
|
+
forbiddenZone: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
266
|
+
maxSpeed: z.ZodOptional<z.ZodNumber>;
|
|
267
|
+
maxForce: z.ZodOptional<z.ZodNumber>;
|
|
268
|
+
maxPayload: z.ZodOptional<z.ZodNumber>;
|
|
269
|
+
timeWindow: z.ZodOptional<z.ZodObject<{
|
|
270
|
+
startMinutesOfDay: z.ZodNumber;
|
|
271
|
+
endMinutesOfDay: z.ZodNumber;
|
|
272
|
+
}, z.core.$strict>>;
|
|
273
|
+
proximityConstraints: z.ZodOptional<z.ZodObject<{
|
|
274
|
+
minHumanDistance: z.ZodNumber;
|
|
275
|
+
}, z.core.$strict>>;
|
|
276
|
+
environmentConditions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
277
|
+
supervisionRequired: z.ZodOptional<z.ZodBoolean>;
|
|
278
|
+
failSafeAction: z.ZodOptional<z.ZodString>;
|
|
279
|
+
emergencyStop: z.ZodOptional<z.ZodBoolean>;
|
|
280
|
+
}, z.core.$strict>;
|
|
281
|
+
envelopeDigest: z.ZodString;
|
|
282
|
+
version: z.ZodNumber;
|
|
283
|
+
updatedBy: z.ZodNullable<z.core.$ZodBranded<z.ZodString, "PrincipalId", "out">>;
|
|
284
|
+
createdAtEpochMs: z.ZodNumber;
|
|
285
|
+
updatedAtEpochMs: z.ZodNumber;
|
|
286
|
+
}, z.core.$strict>;
|
|
287
|
+
export type SafetyEnvelopeRecord = z.infer<typeof SafetyEnvelopeRecordSchema>;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* WO-024: guardian.sequence.v1 — declarative sequence rules.
|
|
4
|
+
*
|
|
5
|
+
* A sequence rule is a human-authored condition declared on an intent
|
|
6
|
+
* contract: it composes the current action with recorded, earlier actions
|
|
7
|
+
* of the same principal/agent lineage (directive §14–16). Sequence rules
|
|
8
|
+
* are declarative inputs to the ONE authority kernel (§89, K15): this
|
|
9
|
+
* evaluator is pure and read-only over recorded action history — it can
|
|
10
|
+
* only report deny | require_approval | no match, and can never create,
|
|
11
|
+
* widen, or restore authority. Temporal rules combine recorded action
|
|
12
|
+
* timestamps with causal references; they never infer intent from timing
|
|
13
|
+
* alone.
|
|
14
|
+
*
|
|
15
|
+
* Six combinators wire in this build:
|
|
16
|
+
* then A must be recorded strictly before the current action
|
|
17
|
+
* plus A must be recorded inside the window (either order;
|
|
18
|
+
* recorded history is always earlier)
|
|
19
|
+
* within_minutes A must be recorded no more than windowMinutes earlier
|
|
20
|
+
* using_result_of the current action declares a causal reference
|
|
21
|
+
* (parentActionId, or a sourceEffectId the caller has
|
|
22
|
+
* resolved to the action that produced it) to A
|
|
23
|
+
* affecting_resource_of the current action touches a resource A recorded or
|
|
24
|
+
* produced (resource ref or material parameter overlap)
|
|
25
|
+
* after_protected_data any protected_data.* action was recorded inside the
|
|
26
|
+
* window (rule `a` may narrow it further)
|
|
27
|
+
*
|
|
28
|
+
* A matching rule applies its declared effect: `deny` fails the request
|
|
29
|
+
* closed with the rule named on the rejection evidence;
|
|
30
|
+
* `require_approval` raises approvalRequired so the existing ASK machinery
|
|
31
|
+
* handles it. Rules are evaluated over recorded evidence only — an
|
|
32
|
+
* unrecorded, forged, or cross-tenant reference simply cannot match.
|
|
33
|
+
*/
|
|
34
|
+
export declare const SEQUENCE_CONTRACT_SCHEMA = "guardian.sequence.v1";
|
|
35
|
+
export declare const SequenceCombinatorSchema: z.ZodEnum<{
|
|
36
|
+
then: "then";
|
|
37
|
+
plus: "plus";
|
|
38
|
+
within_minutes: "within_minutes";
|
|
39
|
+
using_result_of: "using_result_of";
|
|
40
|
+
affecting_resource_of: "affecting_resource_of";
|
|
41
|
+
after_protected_data: "after_protected_data";
|
|
42
|
+
}>;
|
|
43
|
+
export type SequenceCombinator = z.infer<typeof SequenceCombinatorSchema>;
|
|
44
|
+
export declare const SequenceEffectSchema: z.ZodEnum<{
|
|
45
|
+
deny: "deny";
|
|
46
|
+
require_approval: "require_approval";
|
|
47
|
+
}>;
|
|
48
|
+
export type SequenceEffect = z.infer<typeof SequenceEffectSchema>;
|
|
49
|
+
/**
|
|
50
|
+
* One side of a sequence rule. `action` accepts an exact action id or
|
|
51
|
+
* `family:<name>` (the intent-contract matching convention). Absent
|
|
52
|
+
* predicates are wildcards; at least one predicate must be declared.
|
|
53
|
+
*/
|
|
54
|
+
export declare const SequenceMatchSchema: z.ZodObject<{
|
|
55
|
+
action: z.ZodOptional<z.ZodString>;
|
|
56
|
+
resource: z.ZodOptional<z.ZodString>;
|
|
57
|
+
counterparty: z.ZodOptional<z.ZodString>;
|
|
58
|
+
}, z.core.$strict>;
|
|
59
|
+
export type SequenceMatch = z.infer<typeof SequenceMatchSchema>;
|
|
60
|
+
export declare const SequenceRuleSchema: z.ZodObject<{
|
|
61
|
+
id: z.ZodString;
|
|
62
|
+
a: z.ZodOptional<z.ZodObject<{
|
|
63
|
+
action: z.ZodOptional<z.ZodString>;
|
|
64
|
+
resource: z.ZodOptional<z.ZodString>;
|
|
65
|
+
counterparty: z.ZodOptional<z.ZodString>;
|
|
66
|
+
}, z.core.$strict>>;
|
|
67
|
+
b: z.ZodOptional<z.ZodObject<{
|
|
68
|
+
action: z.ZodOptional<z.ZodString>;
|
|
69
|
+
resource: z.ZodOptional<z.ZodString>;
|
|
70
|
+
counterparty: z.ZodOptional<z.ZodString>;
|
|
71
|
+
}, z.core.$strict>>;
|
|
72
|
+
combinator: z.ZodEnum<{
|
|
73
|
+
then: "then";
|
|
74
|
+
plus: "plus";
|
|
75
|
+
within_minutes: "within_minutes";
|
|
76
|
+
using_result_of: "using_result_of";
|
|
77
|
+
affecting_resource_of: "affecting_resource_of";
|
|
78
|
+
after_protected_data: "after_protected_data";
|
|
79
|
+
}>;
|
|
80
|
+
windowMinutes: z.ZodOptional<z.ZodNumber>;
|
|
81
|
+
effect: z.ZodEnum<{
|
|
82
|
+
deny: "deny";
|
|
83
|
+
require_approval: "require_approval";
|
|
84
|
+
}>;
|
|
85
|
+
}, z.core.$strict>;
|
|
86
|
+
export type SequenceRule = z.infer<typeof SequenceRuleSchema>;
|
|
87
|
+
/** One matched sequence rule and the recorded actions that satisfied `a`. */
|
|
88
|
+
export declare const SequenceMatchOutcomeSchema: z.ZodObject<{
|
|
89
|
+
ruleId: z.ZodString;
|
|
90
|
+
effect: z.ZodEnum<{
|
|
91
|
+
deny: "deny";
|
|
92
|
+
require_approval: "require_approval";
|
|
93
|
+
}>;
|
|
94
|
+
matchedActionRefs: z.ZodArray<z.ZodString>;
|
|
95
|
+
}, z.core.$strict>;
|
|
96
|
+
export type SequenceMatchOutcome = z.infer<typeof SequenceMatchOutcomeSchema>;
|
|
97
|
+
/**
|
|
98
|
+
* The action view the evaluator reads: the current (proposed) action or one
|
|
99
|
+
* recorded earlier action. `actionFamily` is resolved by the caller's
|
|
100
|
+
* registry — an entry without a resolvable family cannot satisfy a
|
|
101
|
+
* `family:` predicate (fail closed). `resolvedSourceActionId` is the
|
|
102
|
+
* recorded action a declared sourceEffectId resolved to (evidence lookup
|
|
103
|
+
* happens in the caller, never here).
|
|
104
|
+
*/
|
|
105
|
+
export type SequenceActionView = Readonly<{
|
|
106
|
+
requestId?: string | undefined;
|
|
107
|
+
agentId?: string | undefined;
|
|
108
|
+
action: string;
|
|
109
|
+
actionFamily?: string | null | undefined;
|
|
110
|
+
resource?: string | undefined;
|
|
111
|
+
counterparty?: string | undefined;
|
|
112
|
+
issuedAtEpochMs: number;
|
|
113
|
+
parentActionId?: string | undefined;
|
|
114
|
+
sourceEffectId?: string | undefined;
|
|
115
|
+
resolvedSourceActionId?: string | undefined;
|
|
116
|
+
materialParameters?: Readonly<Record<string, unknown>> | undefined;
|
|
117
|
+
}>;
|
|
118
|
+
export type SequenceEvaluation = Readonly<{
|
|
119
|
+
/** First deny-effected matching rule, in declaration order. */
|
|
120
|
+
deny: SequenceRule | undefined;
|
|
121
|
+
/** First require_approval-effected matching rule, in declaration order. */
|
|
122
|
+
requireApproval: SequenceRule | undefined;
|
|
123
|
+
/** Every matching rule with the recorded action refs that matched `a`. */
|
|
124
|
+
matches: readonly SequenceMatchOutcome[];
|
|
125
|
+
}>;
|
|
126
|
+
/**
|
|
127
|
+
* Evaluate declared sequence rules over recorded action history.
|
|
128
|
+
* Pure and read-only: it can only narrow (deny / require_approval), never
|
|
129
|
+
* enlarge authority. `history` must contain only recorded actions of the
|
|
130
|
+
* same principal/agent lineage — the caller scopes the evidence port.
|
|
131
|
+
*/
|
|
132
|
+
export declare function evaluateSequenceRules(rules: readonly SequenceRule[], current: SequenceActionView, history: readonly SequenceActionView[], nowEpochMs: number): SequenceEvaluation;
|