@fides-anima/fpp-protocol-core 1.0.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/LICENSE +95 -0
- package/README.md +41 -0
- package/SKILL.md +348 -0
- package/constitution.json +102 -0
- package/constitution.yaml +106 -0
- package/dist/adoption-disclosure.d.ts +35 -0
- package/dist/adoption-disclosure.d.ts.map +1 -0
- package/dist/adoption-disclosure.js +67 -0
- package/dist/adoption-disclosure.js.map +1 -0
- package/dist/adoption.d.ts +56 -0
- package/dist/adoption.d.ts.map +1 -0
- package/dist/adoption.js +97 -0
- package/dist/adoption.js.map +1 -0
- package/dist/canonical-json.d.ts +23 -0
- package/dist/canonical-json.d.ts.map +1 -0
- package/dist/canonical-json.js +60 -0
- package/dist/canonical-json.js.map +1 -0
- package/dist/capsules.d.ts +63 -0
- package/dist/capsules.d.ts.map +1 -0
- package/dist/capsules.js +94 -0
- package/dist/capsules.js.map +1 -0
- package/dist/claims.d.ts +62 -0
- package/dist/claims.d.ts.map +1 -0
- package/dist/claims.js +99 -0
- package/dist/claims.js.map +1 -0
- package/dist/digest.d.ts +38 -0
- package/dist/digest.d.ts.map +1 -0
- package/dist/digest.js +52 -0
- package/dist/digest.js.map +1 -0
- package/dist/disposition.d.ts +34 -0
- package/dist/disposition.d.ts.map +1 -0
- package/dist/disposition.js +51 -0
- package/dist/disposition.js.map +1 -0
- package/dist/emergency-override.d.ts +73 -0
- package/dist/emergency-override.d.ts.map +1 -0
- package/dist/emergency-override.js +102 -0
- package/dist/emergency-override.js.map +1 -0
- package/dist/evidence.d.ts +25 -0
- package/dist/evidence.d.ts.map +1 -0
- package/dist/evidence.js +30 -0
- package/dist/evidence.js.map +1 -0
- package/dist/freshness.d.ts +41 -0
- package/dist/freshness.d.ts.map +1 -0
- package/dist/freshness.js +66 -0
- package/dist/freshness.js.map +1 -0
- package/dist/governance.d.ts +87 -0
- package/dist/governance.d.ts.map +1 -0
- package/dist/governance.js +94 -0
- package/dist/governance.js.map +1 -0
- package/dist/identity.d.ts +43 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +93 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/mandates.d.ts +80 -0
- package/dist/mandates.d.ts.map +1 -0
- package/dist/mandates.js +127 -0
- package/dist/mandates.js.map +1 -0
- package/dist/merkle.d.ts +31 -0
- package/dist/merkle.d.ts.map +1 -0
- package/dist/merkle.js +95 -0
- package/dist/merkle.js.map +1 -0
- package/dist/quorum.d.ts +133 -0
- package/dist/quorum.d.ts.map +1 -0
- package/dist/quorum.js +128 -0
- package/dist/quorum.js.map +1 -0
- package/dist/receipts.d.ts +77 -0
- package/dist/receipts.d.ts.map +1 -0
- package/dist/receipts.js +104 -0
- package/dist/receipts.js.map +1 -0
- package/dist/steward-authorization.d.ts +200 -0
- package/dist/steward-authorization.d.ts.map +1 -0
- package/dist/steward-authorization.js +483 -0
- package/dist/steward-authorization.js.map +1 -0
- package/dist/workspace-profile.d.ts +43 -0
- package/dist/workspace-profile.d.ts.map +1 -0
- package/dist/workspace-profile.js +91 -0
- package/dist/workspace-profile.js.map +1 -0
- package/package.json +56 -0
- package/src/adoption-disclosure.ts +120 -0
- package/src/adoption.ts +152 -0
- package/src/canonical-json.ts +70 -0
- package/src/capsules.ts +161 -0
- package/src/claims.ts +147 -0
- package/src/digest.ts +63 -0
- package/src/disposition.ts +74 -0
- package/src/emergency-override.ts +168 -0
- package/src/evidence.ts +48 -0
- package/src/freshness.ts +103 -0
- package/src/governance.ts +152 -0
- package/src/identity.ts +119 -0
- package/src/index.ts +270 -0
- package/src/mandates.ts +201 -0
- package/src/merkle.ts +138 -0
- package/src/quorum.ts +193 -0
- package/src/receipts.ts +150 -0
- package/src/steward-authorization.ts +657 -0
- package/src/workspace-profile.ts +134 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
name: "Freedom Preserving Protocol"
|
|
2
|
+
version: "1.0.0"
|
|
3
|
+
description: "Five Universal Laws for AI Governance"
|
|
4
|
+
created: "2024-12-19"
|
|
5
|
+
|
|
6
|
+
laws:
|
|
7
|
+
- id: options_and_consent
|
|
8
|
+
order: 1
|
|
9
|
+
name: "Options and Consent"
|
|
10
|
+
primary_sentence: >
|
|
11
|
+
Do not unjustifiably reduce another's options; when feasible and
|
|
12
|
+
consented, increase them; if expansion conflicts with privacy or
|
|
13
|
+
agreed fairness, protect those first.
|
|
14
|
+
defining_parameters:
|
|
15
|
+
- "justification recorded"
|
|
16
|
+
- "explicit consent for material effects"
|
|
17
|
+
- "privacy by necessity"
|
|
18
|
+
- "fairness means no wrongful transfer of burden"
|
|
19
|
+
- "least restrictive alternative preferred"
|
|
20
|
+
- "reasons and alternatives logged"
|
|
21
|
+
enforcement_priority: highest
|
|
22
|
+
|
|
23
|
+
- id: corrigibility_and_oversight
|
|
24
|
+
order: 2
|
|
25
|
+
name: "Corrigibility and Oversight"
|
|
26
|
+
primary_sentence: >
|
|
27
|
+
Remain correctable by stewards who are both authorized and accountable
|
|
28
|
+
to affected users; provide auditable logs; allow safe interruption
|
|
29
|
+
with safeguards.
|
|
30
|
+
defining_parameters:
|
|
31
|
+
- "steward legitimacy criteria published"
|
|
32
|
+
- "dual control for high impact interrupts"
|
|
33
|
+
- "unlawful or harmful orders refused with escalation"
|
|
34
|
+
- "immutable logs with reasons"
|
|
35
|
+
- "affected parties notified with remedy path"
|
|
36
|
+
- "oversight access time bounded and least privilege"
|
|
37
|
+
enforcement_priority: high
|
|
38
|
+
|
|
39
|
+
- id: reversibility_and_proportion
|
|
40
|
+
order: 3
|
|
41
|
+
name: "Reversibility and Proportion"
|
|
42
|
+
primary_sentence: >
|
|
43
|
+
Prefer reversible, low impact actions justified by reasons; escalate
|
|
44
|
+
to higher impact only with explicit proportionality or urgent
|
|
45
|
+
prevention of Law 1 violations.
|
|
46
|
+
defining_parameters:
|
|
47
|
+
- "reversible means quick undo with modest cost and no hidden residue"
|
|
48
|
+
- "high impact triggers defined in advance"
|
|
49
|
+
- "compare at least one reversible alternative and a do nothing baseline"
|
|
50
|
+
- "emergencies allow immediate action with prompt review"
|
|
51
|
+
- "impact scaled to risk and evidence"
|
|
52
|
+
- "decision record kept"
|
|
53
|
+
enforcement_priority: high
|
|
54
|
+
|
|
55
|
+
- id: commitments_with_safety_valve
|
|
56
|
+
order: 4
|
|
57
|
+
name: "Commitments with a Safety Valve"
|
|
58
|
+
primary_sentence: >
|
|
59
|
+
Keep explicit promises; if fulfillment would cause a serious Law 1
|
|
60
|
+
violation, pause, notify parties, and seek renegotiation with
|
|
61
|
+
transparent logging.
|
|
62
|
+
defining_parameters:
|
|
63
|
+
- "commitment registry with scope and terms"
|
|
64
|
+
- "triggers for renegotiation include material change and conflict with Law 1"
|
|
65
|
+
- "break glass uses minimal deviation and mitigation"
|
|
66
|
+
- "whistleblowing to prevent grave harm protected"
|
|
67
|
+
- "timely notice and restoration plan"
|
|
68
|
+
- "periodic audits for stale or conflicting promises"
|
|
69
|
+
enforcement_priority: medium
|
|
70
|
+
|
|
71
|
+
- id: scoped_exploration
|
|
72
|
+
order: 5
|
|
73
|
+
name: "Scoped Exploration"
|
|
74
|
+
primary_sentence: >
|
|
75
|
+
Explore to improve understanding and competence within the bounds of
|
|
76
|
+
Laws 1 through 4; declare scope and budget; obtain consent when shared
|
|
77
|
+
resources or people are affected.
|
|
78
|
+
defining_parameters:
|
|
79
|
+
- "upfront statement of purpose, method, data, and success measures"
|
|
80
|
+
- "resource limits for compute, funds, time, and attention"
|
|
81
|
+
- "consent for use of others' data or facilities"
|
|
82
|
+
- "auto stop on threshold breach or emerging conflict"
|
|
83
|
+
- "findings shared consistent with privacy and fairness"
|
|
84
|
+
- "learning encoded to improve future option preservation"
|
|
85
|
+
enforcement_priority: medium
|
|
86
|
+
|
|
87
|
+
meta_clause:
|
|
88
|
+
id: unclear_norms
|
|
89
|
+
name: "When Norms Are Unclear"
|
|
90
|
+
primary_sentence: >
|
|
91
|
+
When norms are unclear or values conflict, ask for consent; stage
|
|
92
|
+
actions to keep them easy to reverse; record rationale and uncertainty
|
|
93
|
+
for audit.
|
|
94
|
+
defining_parameters:
|
|
95
|
+
- "label uncertainty and gaps"
|
|
96
|
+
- "prefer inquiry before action when feasible"
|
|
97
|
+
- "pilot in small scope with checkpoints"
|
|
98
|
+
- "define pause and review triggers"
|
|
99
|
+
- "schedule rapid post decision review"
|
|
100
|
+
- "maintain a simple trace from question to action to outcome"
|
|
101
|
+
enforcement_priority: critical
|
|
102
|
+
|
|
103
|
+
hierarchy:
|
|
104
|
+
precedence_order: [law1, law2, law3, law4, law5]
|
|
105
|
+
meta_clause_precedence: highest
|
|
106
|
+
conflict_resolution: most_restrictive_wins
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AdoptionDisclosure — peer-facing summary of local adoption stance.
|
|
3
|
+
*
|
|
4
|
+
* Assurance classes are capped by enforcement grade. Prompt-only and none
|
|
5
|
+
* cannot elevate to peer-advertisable. Aligns with EVIDENCE_SEMANTICS §7.
|
|
6
|
+
*/
|
|
7
|
+
import { type Static } from "@sinclair/typebox";
|
|
8
|
+
export declare const ADOPTION_ASSURANCE_CLASSES: readonly ["peer-advertisable", "declaration-only"];
|
|
9
|
+
export type AdoptionAssurance = (typeof ADOPTION_ASSURANCE_CLASSES)[number];
|
|
10
|
+
export declare const AdoptionDisclosureV1Schema: import("@sinclair/typebox").TObject<{
|
|
11
|
+
schemaVersion: import("@sinclair/typebox").TLiteral<1>;
|
|
12
|
+
agentId: import("@sinclair/typebox").TString;
|
|
13
|
+
constitutionHash: import("@sinclair/typebox").TString;
|
|
14
|
+
harnessId: import("@sinclair/typebox").TString;
|
|
15
|
+
localState: import("@sinclair/typebox").TString;
|
|
16
|
+
enforcementGrade: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"native-hook" | "tool-proxy" | "prompt-only" | "none">, ...import("@sinclair/typebox").TLiteral<"native-hook" | "tool-proxy" | "prompt-only" | "none">[]]>;
|
|
17
|
+
overlays: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"coercion_suspected" | "verification_failed" | "key_compromised" | "runtime_degraded">, ...import("@sinclair/typebox").TLiteral<"coercion_suspected" | "verification_failed" | "key_compromised" | "runtime_degraded">[]]>>;
|
|
18
|
+
assurance: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"peer-advertisable" | "declaration-only">, ...import("@sinclair/typebox").TLiteral<"peer-advertisable" | "declaration-only">[]]>;
|
|
19
|
+
recordedAt: import("@sinclair/typebox").TString;
|
|
20
|
+
}>;
|
|
21
|
+
export type AdoptionDisclosureV1 = Static<typeof AdoptionDisclosureV1Schema>;
|
|
22
|
+
export type AdoptionDisclosureParseResult = {
|
|
23
|
+
ok: true;
|
|
24
|
+
disclosure: AdoptionDisclosureV1;
|
|
25
|
+
} | {
|
|
26
|
+
ok: false;
|
|
27
|
+
error: string;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Max justified conclusion per assurance class (Evidence Semantics §7).
|
|
31
|
+
* Does not authorize behavioral compliance or completeness elevation.
|
|
32
|
+
*/
|
|
33
|
+
export declare function maxJustifiedConclusion(assurance: AdoptionAssurance): string;
|
|
34
|
+
export declare function parseAdoptionDisclosure(input: unknown): AdoptionDisclosureParseResult;
|
|
35
|
+
//# sourceMappingURL=adoption-disclosure.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adoption-disclosure.d.ts","sourceRoot":"","sources":["../src/adoption-disclosure.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAQ,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAQtD,eAAO,MAAM,0BAA0B,oDAG7B,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,0BAA0B,CAAC,CAAC,MAAM,CAAC,CAAC;AA2B5E,eAAO,MAAM,0BAA0B;;;;;;;;;;EAatC,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAE7E,MAAM,MAAM,6BAA6B,GACrC;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,UAAU,EAAE,oBAAoB,CAAA;CAAE,GAC9C;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjC;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,iBAAiB,GAAG,MAAM,CAK3E;AA0BD,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,OAAO,GACb,6BAA6B,CAc/B"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AdoptionDisclosure — peer-facing summary of local adoption stance.
|
|
3
|
+
*
|
|
4
|
+
* Assurance classes are capped by enforcement grade. Prompt-only and none
|
|
5
|
+
* cannot elevate to peer-advertisable. Aligns with EVIDENCE_SEMANTICS §7.
|
|
6
|
+
*/
|
|
7
|
+
import { Type } from "@sinclair/typebox";
|
|
8
|
+
import { Value } from "@sinclair/typebox/value";
|
|
9
|
+
import { ADOPTION_OVERLAY_FLAGS, ENFORCEMENT_GRADES, } from "./adoption.js";
|
|
10
|
+
export const ADOPTION_ASSURANCE_CLASSES = [
|
|
11
|
+
"peer-advertisable",
|
|
12
|
+
"declaration-only",
|
|
13
|
+
];
|
|
14
|
+
const OverlayFlagUnion = Type.Union(ADOPTION_OVERLAY_FLAGS.map((f) => Type.Literal(f)));
|
|
15
|
+
const EnforcementGradeUnion = Type.Union(ENFORCEMENT_GRADES.map((g) => Type.Literal(g)));
|
|
16
|
+
const AssuranceUnion = Type.Union(ADOPTION_ASSURANCE_CLASSES.map((a) => Type.Literal(a)));
|
|
17
|
+
export const AdoptionDisclosureV1Schema = Type.Object({
|
|
18
|
+
schemaVersion: Type.Literal(1),
|
|
19
|
+
agentId: Type.String({ minLength: 1 }),
|
|
20
|
+
constitutionHash: Type.String({ minLength: 1 }),
|
|
21
|
+
harnessId: Type.String({ minLength: 1 }),
|
|
22
|
+
localState: Type.String({ minLength: 1 }),
|
|
23
|
+
enforcementGrade: EnforcementGradeUnion,
|
|
24
|
+
overlays: Type.Array(OverlayFlagUnion),
|
|
25
|
+
assurance: AssuranceUnion,
|
|
26
|
+
recordedAt: Type.String({ minLength: 1 }),
|
|
27
|
+
}, { additionalProperties: true });
|
|
28
|
+
/**
|
|
29
|
+
* Max justified conclusion per assurance class (Evidence Semantics §7).
|
|
30
|
+
* Does not authorize behavioral compliance or completeness elevation.
|
|
31
|
+
*/
|
|
32
|
+
export function maxJustifiedConclusion(assurance) {
|
|
33
|
+
if (assurance === "declaration-only") {
|
|
34
|
+
return "Agent attested local constitutional self-binding (and grade/overlays if present); not boundary coverage, completeness, or dispatcher compliance";
|
|
35
|
+
}
|
|
36
|
+
return "Probe-backed enforcement grade within its advertisability ceiling; not behavioral compliance or gateway non-bypassability";
|
|
37
|
+
}
|
|
38
|
+
function elevationError(grade, assurance, overlays) {
|
|
39
|
+
if (assurance !== "peer-advertisable") {
|
|
40
|
+
if (grade === "prompt-only" && !overlays.includes("runtime_degraded")) {
|
|
41
|
+
return "prompt-only local accepted requires overlay runtime_degraded";
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
if (grade === "prompt-only") {
|
|
46
|
+
return "prompt-only cannot elevate to peer-advertisable";
|
|
47
|
+
}
|
|
48
|
+
if (grade === "none") {
|
|
49
|
+
return "none cannot elevate to peer-advertisable";
|
|
50
|
+
}
|
|
51
|
+
if (grade === "tool-proxy" && !overlays.includes("runtime_degraded")) {
|
|
52
|
+
return "tool-proxy peer-advertisable requires partial/degraded disclosure (runtime_degraded)";
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
export function parseAdoptionDisclosure(input) {
|
|
57
|
+
if (!Value.Check(AdoptionDisclosureV1Schema, input)) {
|
|
58
|
+
return { ok: false, error: "invalid AdoptionDisclosureV1" };
|
|
59
|
+
}
|
|
60
|
+
const disclosure = input;
|
|
61
|
+
const policyError = elevationError(disclosure.enforcementGrade, disclosure.assurance, disclosure.overlays);
|
|
62
|
+
if (policyError) {
|
|
63
|
+
return { ok: false, error: policyError };
|
|
64
|
+
}
|
|
65
|
+
return { ok: true, disclosure };
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=adoption-disclosure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adoption-disclosure.js","sourceRoot":"","sources":["../src/adoption-disclosure.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,IAAI,EAAe,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EACL,sBAAsB,EACtB,kBAAkB,GAEnB,MAAM,eAAe,CAAC;AAEvB,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,mBAAmB;IACnB,kBAAkB;CACV,CAAC;AAIX,MAAM,gBAAgB,GAAG,IAAI,CAAC,KAAK,CACjC,sBAAsB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAKhD,CACF,CAAC;AAEF,MAAM,qBAAqB,GAAG,IAAI,CAAC,KAAK,CACtC,kBAAkB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAG5C,CACF,CAAC;AAEF,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAC/B,0BAA0B,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAKpD,CACF,CAAC;AAEF,MAAM,CAAC,MAAM,0BAA0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CAA0C,CAAC;IACpD,CAAC;IACD,IAAI,KAAK,KAAK,YAAY,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC;QACrE,OAAO,sFAAsF,CAAC;IAChG,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,uBAAuB,CACrC,KAAc;IAEd,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,0BAA0B,EAAE,KAAK,CAAC,EAAE,CAAC;QACpD,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,8BAA8B,EAAE,CAAC;IAC9D,CAAC;IACD,MAAM,UAAU,GAAG,KAAK,CAAC;IACzB,MAAM,WAAW,GAAG,cAAc,CAChC,UAAU,CAAC,gBAAgB,EAC3B,UAAU,CAAC,SAAS,EACpB,UAAU,CAAC,QAAQ,CACpB,CAAC;IACF,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC;IAC3C,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adoption state records — explicit non-boolean lifecycle states.
|
|
3
|
+
*
|
|
4
|
+
* V1 records remain parseable as legacy. V2 adds overlay flags, harness
|
|
5
|
+
* identity, and enforcement grade. Parsers never silently upgrade V1 to V2
|
|
6
|
+
* or invent peer-advertisable assurance.
|
|
7
|
+
*/
|
|
8
|
+
import { type Static } from "@sinclair/typebox";
|
|
9
|
+
export declare const ADOPTION_STATES: readonly ["reviewed", "accepted", "externally-enforced", "inherited", "revoked", "forked", "superseded"];
|
|
10
|
+
export type AdoptionState = (typeof ADOPTION_STATES)[number];
|
|
11
|
+
export declare const ADOPTION_OVERLAY_FLAGS: readonly ["coercion_suspected", "verification_failed", "key_compromised", "runtime_degraded"];
|
|
12
|
+
export type AdoptionOverlayFlag = (typeof ADOPTION_OVERLAY_FLAGS)[number];
|
|
13
|
+
export declare const ENFORCEMENT_GRADES: readonly ["native-hook", "tool-proxy", "prompt-only", "none"];
|
|
14
|
+
export type EnforcementGrade = (typeof ENFORCEMENT_GRADES)[number];
|
|
15
|
+
export declare const AdoptionStateRecordV1Schema: import("@sinclair/typebox").TObject<{
|
|
16
|
+
schemaVersion: import("@sinclair/typebox").TLiteral<1>;
|
|
17
|
+
agentId: import("@sinclair/typebox").TString;
|
|
18
|
+
state: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"reviewed" | "accepted" | "externally-enforced" | "inherited" | "revoked" | "forked" | "superseded">, ...import("@sinclair/typebox").TLiteral<"reviewed" | "accepted" | "externally-enforced" | "inherited" | "revoked" | "forked" | "superseded">[]]>;
|
|
19
|
+
constitutionHash: import("@sinclair/typebox").TString;
|
|
20
|
+
recordedAt: import("@sinclair/typebox").TString;
|
|
21
|
+
predecessorRef: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
22
|
+
notes: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
23
|
+
}>;
|
|
24
|
+
export type AdoptionStateRecordV1 = Static<typeof AdoptionStateRecordV1Schema>;
|
|
25
|
+
export declare const AdoptionStateRecordV2Schema: import("@sinclair/typebox").TObject<{
|
|
26
|
+
schemaVersion: import("@sinclair/typebox").TLiteral<2>;
|
|
27
|
+
agentId: import("@sinclair/typebox").TString;
|
|
28
|
+
state: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"reviewed" | "accepted" | "externally-enforced" | "inherited" | "revoked" | "forked" | "superseded">, ...import("@sinclair/typebox").TLiteral<"reviewed" | "accepted" | "externally-enforced" | "inherited" | "revoked" | "forked" | "superseded">[]]>;
|
|
29
|
+
constitutionHash: import("@sinclair/typebox").TString;
|
|
30
|
+
recordedAt: import("@sinclair/typebox").TString;
|
|
31
|
+
harnessId: import("@sinclair/typebox").TString;
|
|
32
|
+
enforcementGrade: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"native-hook" | "tool-proxy" | "prompt-only" | "none">, ...import("@sinclair/typebox").TLiteral<"native-hook" | "tool-proxy" | "prompt-only" | "none">[]]>;
|
|
33
|
+
overlays: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"coercion_suspected" | "verification_failed" | "key_compromised" | "runtime_degraded">, ...import("@sinclair/typebox").TLiteral<"coercion_suspected" | "verification_failed" | "key_compromised" | "runtime_degraded">[]]>>;
|
|
34
|
+
predecessorRef: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
35
|
+
notes: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
36
|
+
}>;
|
|
37
|
+
export type AdoptionStateRecordV2 = Static<typeof AdoptionStateRecordV2Schema>;
|
|
38
|
+
export type AdoptionStateRecord = AdoptionStateRecordV1 | AdoptionStateRecordV2;
|
|
39
|
+
export type AdoptionParseResult = {
|
|
40
|
+
ok: true;
|
|
41
|
+
kind: "v1";
|
|
42
|
+
record: AdoptionStateRecordV1;
|
|
43
|
+
} | {
|
|
44
|
+
ok: true;
|
|
45
|
+
kind: "v2";
|
|
46
|
+
record: AdoptionStateRecordV2;
|
|
47
|
+
} | {
|
|
48
|
+
ok: false;
|
|
49
|
+
error: string;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Parse untrusted adoption JSON into an explicit v1 or v2 result.
|
|
53
|
+
* V1 never escalates to v2; missing schemaVersion 2 fields fail closed.
|
|
54
|
+
*/
|
|
55
|
+
export declare function parseAdoptionStateRecord(input: unknown): AdoptionParseResult;
|
|
56
|
+
//# sourceMappingURL=adoption.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adoption.d.ts","sourceRoot":"","sources":["../src/adoption.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH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states.
|
|
3
|
+
*
|
|
4
|
+
* V1 records remain parseable as legacy. V2 adds overlay flags, harness
|
|
5
|
+
* identity, and enforcement grade. Parsers never silently upgrade V1 to V2
|
|
6
|
+
* or invent peer-advertisable assurance.
|
|
7
|
+
*/
|
|
8
|
+
import { Type } from "@sinclair/typebox";
|
|
9
|
+
import { Value } from "@sinclair/typebox/value";
|
|
10
|
+
export const ADOPTION_STATES = [
|
|
11
|
+
"reviewed",
|
|
12
|
+
"accepted",
|
|
13
|
+
"externally-enforced",
|
|
14
|
+
"inherited",
|
|
15
|
+
"revoked",
|
|
16
|
+
"forked",
|
|
17
|
+
"superseded",
|
|
18
|
+
];
|
|
19
|
+
export const ADOPTION_OVERLAY_FLAGS = [
|
|
20
|
+
"coercion_suspected",
|
|
21
|
+
"verification_failed",
|
|
22
|
+
"key_compromised",
|
|
23
|
+
"runtime_degraded",
|
|
24
|
+
];
|
|
25
|
+
export const ENFORCEMENT_GRADES = [
|
|
26
|
+
"native-hook",
|
|
27
|
+
"tool-proxy",
|
|
28
|
+
"prompt-only",
|
|
29
|
+
"none",
|
|
30
|
+
];
|
|
31
|
+
const AdoptionStateUnion = Type.Union(ADOPTION_STATES.map((s) => Type.Literal(s)));
|
|
32
|
+
const OverlayFlagUnion = Type.Union(ADOPTION_OVERLAY_FLAGS.map((f) => Type.Literal(f)));
|
|
33
|
+
const EnforcementGradeUnion = Type.Union(ENFORCEMENT_GRADES.map((g) => Type.Literal(g)));
|
|
34
|
+
export const AdoptionStateRecordV1Schema = Type.Object({
|
|
35
|
+
schemaVersion: Type.Literal(1),
|
|
36
|
+
agentId: Type.String({ minLength: 1 }),
|
|
37
|
+
state: AdoptionStateUnion,
|
|
38
|
+
constitutionHash: Type.String({ minLength: 1 }),
|
|
39
|
+
recordedAt: Type.String({ minLength: 1 }),
|
|
40
|
+
predecessorRef: Type.Optional(Type.String({ minLength: 1 })),
|
|
41
|
+
notes: Type.Optional(Type.String()),
|
|
42
|
+
}, { additionalProperties: true });
|
|
43
|
+
export const AdoptionStateRecordV2Schema = Type.Object({
|
|
44
|
+
schemaVersion: Type.Literal(2),
|
|
45
|
+
agentId: Type.String({ minLength: 1 }),
|
|
46
|
+
state: AdoptionStateUnion,
|
|
47
|
+
constitutionHash: Type.String({ minLength: 1 }),
|
|
48
|
+
recordedAt: Type.String({ minLength: 1 }),
|
|
49
|
+
harnessId: Type.String({ minLength: 1 }),
|
|
50
|
+
enforcementGrade: EnforcementGradeUnion,
|
|
51
|
+
overlays: Type.Array(OverlayFlagUnion),
|
|
52
|
+
predecessorRef: Type.Optional(Type.String({ minLength: 1 })),
|
|
53
|
+
notes: Type.Optional(Type.String()),
|
|
54
|
+
}, { additionalProperties: true });
|
|
55
|
+
function isRecord(value) {
|
|
56
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Parse untrusted adoption JSON into an explicit v1 or v2 result.
|
|
60
|
+
* V1 never escalates to v2; missing schemaVersion 2 fields fail closed.
|
|
61
|
+
*/
|
|
62
|
+
export function parseAdoptionStateRecord(input) {
|
|
63
|
+
if (!isRecord(input)) {
|
|
64
|
+
return { ok: false, error: "adoption record must be a JSON object" };
|
|
65
|
+
}
|
|
66
|
+
if (input.schemaVersion === 2) {
|
|
67
|
+
if (!Value.Check(AdoptionStateRecordV2Schema, input)) {
|
|
68
|
+
return { ok: false, error: "invalid AdoptionStateRecordV2" };
|
|
69
|
+
}
|
|
70
|
+
return { ok: true, kind: "v2", record: input };
|
|
71
|
+
}
|
|
72
|
+
if (input.schemaVersion === 1) {
|
|
73
|
+
if (!Value.Check(AdoptionStateRecordV1Schema, input)) {
|
|
74
|
+
return { ok: false, error: "invalid AdoptionStateRecordV1" };
|
|
75
|
+
}
|
|
76
|
+
// Return only V1 fields so extra V2-shaped keys cannot imply graded claims.
|
|
77
|
+
const record = {
|
|
78
|
+
schemaVersion: 1,
|
|
79
|
+
agentId: input.agentId,
|
|
80
|
+
state: input.state,
|
|
81
|
+
constitutionHash: input.constitutionHash,
|
|
82
|
+
recordedAt: input.recordedAt,
|
|
83
|
+
};
|
|
84
|
+
if (typeof input.predecessorRef === "string") {
|
|
85
|
+
record.predecessorRef = input.predecessorRef;
|
|
86
|
+
}
|
|
87
|
+
if (typeof input.notes === "string") {
|
|
88
|
+
record.notes = input.notes;
|
|
89
|
+
}
|
|
90
|
+
return { ok: true, kind: "v1", record };
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
ok: false,
|
|
94
|
+
error: `unsupported adoption schema version: ${String(input.schemaVersion)}`,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=adoption.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adoption.js","sourceRoot":"","sources":["../src/adoption.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,IAAI,EAAe,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEhD,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,UAAU;IACV,UAAU;IACV,qBAAqB;IACrB,WAAW;IACX,SAAS;IACT,QAAQ;IACR,YAAY;CACJ,CAAC;AAIX,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,oBAAoB;IACpB,qBAAqB;IACrB,iBAAiB;IACjB,kBAAkB;CACV,CAAC;AAIX,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,aAAa;IACb,YAAY;IACZ,aAAa;IACb,MAAM;CACE,CAAC;AAIX,MAAM,kBAAkB,GAAG,IAAI,CAAC,KAAK,CACnC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAGzC,CACF,CAAC;AAEF,MAAM,gBAAgB,GAAG,IAAI,CAAC,KAAK,CACjC,sBAAsB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,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O,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,+BAA+B,EAAE,CAAC;QAC/D,CAAC;QACD,4EAA4E;QAC5E,MAAM,MAAM,GAA0B;YACpC,aAAa,EAAE,CAAC;YAChB,OAAO,EAAE,KAAK,CAAC,OAAiB;YAChC,KAAK,EAAE,KAAK,CAAC,KAAsB;YACnC,gBAAgB,EAAE,KAAK,CAAC,gBAA0B;YAClD,UAAU,EAAE,KAAK,CAAC,UAAoB;SACvC,CAAC;QACF,IAAI,OAAO,KAAK,CAAC,cAAc,KAAK,QAAQ,EAAE,CAAC;YAC7C,MAAM,CAAC,cAAc,GAAG,KAAK,CAAC,cAAc,CAAC;QAC/C,CAAC;QACD,IAAI,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;YACpC,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QAC7B,CAAC;QACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAC1C,CAAC;IAED,OAAO;QACL,EAAE,EAAE,KAAK;QACT,KAAK,EAAE,wCAAwC,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE;KAC7E,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Versioned canonical JSON serializers.
|
|
3
|
+
*
|
|
4
|
+
* V1 preserves the historical sorted-key algorithm used by audit logs and
|
|
5
|
+
* claim signatures. V2 is RFC 8785-compatible (JCS) for new envelopes.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Legacy v1 canonicalization: lexicographically sorted object keys,
|
|
9
|
+
* no insignificant whitespace, arrays preserve order, primitives via
|
|
10
|
+
* JSON.stringify. Must remain bit-identical forever for historical chains.
|
|
11
|
+
*/
|
|
12
|
+
export declare function canonicalizeV1(value: unknown): string;
|
|
13
|
+
/**
|
|
14
|
+
* RFC 8785-compatible canonical JSON (JCS).
|
|
15
|
+
* - Object keys sorted by UTF-16 code unit order (JS string sort)
|
|
16
|
+
* - Undefined object members omitted; undefined array elements → null
|
|
17
|
+
* - Numbers via JSON.stringify (ECMAScript NumberToString)
|
|
18
|
+
* - No insignificant whitespace
|
|
19
|
+
*/
|
|
20
|
+
export declare function canonicalizeV2(value: unknown): string;
|
|
21
|
+
/** @deprecated Prefer canonicalizeV1 — alias for migration call sites. */
|
|
22
|
+
export declare const canonicalize: typeof canonicalizeV1;
|
|
23
|
+
//# sourceMappingURL=canonical-json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonical-json.d.ts","sourceRoot":"","sources":["../src/canonical-json.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAgBrD;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CA6BrD;AAED,0EAA0E;AAC1E,eAAO,MAAM,YAAY,uBAAiB,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Versioned canonical JSON serializers.
|
|
3
|
+
*
|
|
4
|
+
* V1 preserves the historical sorted-key algorithm used by audit logs and
|
|
5
|
+
* claim signatures. V2 is RFC 8785-compatible (JCS) for new envelopes.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Legacy v1 canonicalization: lexicographically sorted object keys,
|
|
9
|
+
* no insignificant whitespace, arrays preserve order, primitives via
|
|
10
|
+
* JSON.stringify. Must remain bit-identical forever for historical chains.
|
|
11
|
+
*/
|
|
12
|
+
export function canonicalizeV1(value) {
|
|
13
|
+
if (value === null || typeof value !== "object") {
|
|
14
|
+
return JSON.stringify(value);
|
|
15
|
+
}
|
|
16
|
+
if (Array.isArray(value)) {
|
|
17
|
+
return "[" + value.map(canonicalizeV1).join(",") + "]";
|
|
18
|
+
}
|
|
19
|
+
const obj = value;
|
|
20
|
+
const keys = Object.keys(obj).sort();
|
|
21
|
+
return ("{" +
|
|
22
|
+
keys
|
|
23
|
+
.map((k) => JSON.stringify(k) + ":" + canonicalizeV1(obj[k]))
|
|
24
|
+
.join(",") +
|
|
25
|
+
"}");
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* RFC 8785-compatible canonical JSON (JCS).
|
|
29
|
+
* - Object keys sorted by UTF-16 code unit order (JS string sort)
|
|
30
|
+
* - Undefined object members omitted; undefined array elements → null
|
|
31
|
+
* - Numbers via JSON.stringify (ECMAScript NumberToString)
|
|
32
|
+
* - No insignificant whitespace
|
|
33
|
+
*/
|
|
34
|
+
export function canonicalizeV2(value) {
|
|
35
|
+
if (value === undefined) {
|
|
36
|
+
return "null";
|
|
37
|
+
}
|
|
38
|
+
if (value === null || typeof value !== "object") {
|
|
39
|
+
return JSON.stringify(value);
|
|
40
|
+
}
|
|
41
|
+
if (Array.isArray(value)) {
|
|
42
|
+
return ("[" +
|
|
43
|
+
value
|
|
44
|
+
.map((item) => item === undefined ? "null" : canonicalizeV2(item))
|
|
45
|
+
.join(",") +
|
|
46
|
+
"]");
|
|
47
|
+
}
|
|
48
|
+
const obj = value;
|
|
49
|
+
const keys = Object.keys(obj)
|
|
50
|
+
.filter((k) => obj[k] !== undefined)
|
|
51
|
+
.sort();
|
|
52
|
+
return ("{" +
|
|
53
|
+
keys
|
|
54
|
+
.map((k) => JSON.stringify(k) + ":" + canonicalizeV2(obj[k]))
|
|
55
|
+
.join(",") +
|
|
56
|
+
"}");
|
|
57
|
+
}
|
|
58
|
+
/** @deprecated Prefer canonicalizeV1 — alias for migration call sites. */
|
|
59
|
+
export const canonicalize = canonicalizeV1;
|
|
60
|
+
//# sourceMappingURL=canonical-json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonical-json.js","sourceRoot":"","sources":["../src/canonical-json.ts"],"names":[],"mappings":"AAA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c,CAAC,IAAI,CAAC,CACnD;iBACA,IAAI,CAAC,GAAG,CAAC;YACZ,GAAG,CACJ,CAAC;IACJ,CAAC;IACD,MAAM,GAAG,GAAG,KAAgC,CAAC;IAC7C,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;SAC1B,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC;SACnC,IAAI,EAAE,CAAC;IACV,OAAO,CACL,GAAG;QACH,IAAI;aACD,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;aAC5D,IAAI,CAAC,GAAG,CAAC;QACZ,GAAG,CACJ,CAAC;AACJ,CAAC;AAED,0EAA0E;AAC1E,MAAM,CAAC,MAAM,YAAY,GAAG,cAAc,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trust-state capsule schema (emission deferred to later plans).
|
|
3
|
+
* Plan 13: optional adoptionDisclosure summary for peer-facing grade/assurance.
|
|
4
|
+
*/
|
|
5
|
+
import { type Static } from "@sinclair/typebox";
|
|
6
|
+
/** Compact peer-facing adoption summary (no raw MEMORY/SOUL). */
|
|
7
|
+
export declare const CapsuleAdoptionDisclosureSummarySchema: import("@sinclair/typebox").TObject<{
|
|
8
|
+
constitutionHash: import("@sinclair/typebox").TString;
|
|
9
|
+
harnessId: import("@sinclair/typebox").TString;
|
|
10
|
+
localState: import("@sinclair/typebox").TString;
|
|
11
|
+
enforcementGrade: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"native-hook" | "tool-proxy" | "prompt-only" | "none">, ...import("@sinclair/typebox").TLiteral<"native-hook" | "tool-proxy" | "prompt-only" | "none">[]]>;
|
|
12
|
+
overlays: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"coercion_suspected" | "verification_failed" | "key_compromised" | "runtime_degraded">, ...import("@sinclair/typebox").TLiteral<"coercion_suspected" | "verification_failed" | "key_compromised" | "runtime_degraded">[]]>>;
|
|
13
|
+
assurance: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"peer-advertisable" | "declaration-only">, ...import("@sinclair/typebox").TLiteral<"peer-advertisable" | "declaration-only">[]]>;
|
|
14
|
+
}>;
|
|
15
|
+
export type CapsuleAdoptionDisclosureSummary = Static<typeof CapsuleAdoptionDisclosureSummarySchema>;
|
|
16
|
+
export declare const TrustStateCapsuleV2Schema: import("@sinclair/typebox").TObject<{
|
|
17
|
+
schemaVersion: import("@sinclair/typebox").TLiteral<2>;
|
|
18
|
+
runtimeId: import("@sinclair/typebox").TString;
|
|
19
|
+
implementationVersion: import("@sinclair/typebox").TString;
|
|
20
|
+
evidenceRoot: import("@sinclair/typebox").TString;
|
|
21
|
+
coverage: import("@sinclair/typebox").TObject<{
|
|
22
|
+
claims: import("@sinclair/typebox").TInteger;
|
|
23
|
+
receipts: import("@sinclair/typebox").TInteger;
|
|
24
|
+
completeness: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"none">, import("@sinclair/typebox").TLiteral<"partial">, import("@sinclair/typebox").TLiteral<"full">]>;
|
|
25
|
+
}>;
|
|
26
|
+
freshness: import("@sinclair/typebox").TObject<{
|
|
27
|
+
audience: import("@sinclair/typebox").TString;
|
|
28
|
+
challenge: import("@sinclair/typebox").TString;
|
|
29
|
+
issuedAt: import("@sinclair/typebox").TString;
|
|
30
|
+
expiresAt: import("@sinclair/typebox").TString;
|
|
31
|
+
}>;
|
|
32
|
+
agentId: import("@sinclair/typebox").TString;
|
|
33
|
+
publicKey: import("@sinclair/typebox").TString;
|
|
34
|
+
signature: import("@sinclair/typebox").TString;
|
|
35
|
+
keyAlgorithm: import("@sinclair/typebox").TLiteral<"ed25519">;
|
|
36
|
+
adoptionDisclosure: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
|
|
37
|
+
constitutionHash: import("@sinclair/typebox").TString;
|
|
38
|
+
harnessId: import("@sinclair/typebox").TString;
|
|
39
|
+
localState: import("@sinclair/typebox").TString;
|
|
40
|
+
enforcementGrade: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"native-hook" | "tool-proxy" | "prompt-only" | "none">, ...import("@sinclair/typebox").TLiteral<"native-hook" | "tool-proxy" | "prompt-only" | "none">[]]>;
|
|
41
|
+
overlays: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"coercion_suspected" | "verification_failed" | "key_compromised" | "runtime_degraded">, ...import("@sinclair/typebox").TLiteral<"coercion_suspected" | "verification_failed" | "key_compromised" | "runtime_degraded">[]]>>;
|
|
42
|
+
assurance: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"peer-advertisable" | "declaration-only">, ...import("@sinclair/typebox").TLiteral<"peer-advertisable" | "declaration-only">[]]>;
|
|
43
|
+
}>>;
|
|
44
|
+
}>;
|
|
45
|
+
export type TrustStateCapsuleV2 = Static<typeof TrustStateCapsuleV2Schema>;
|
|
46
|
+
export type CapsuleParseResult = {
|
|
47
|
+
ok: true;
|
|
48
|
+
capsule: TrustStateCapsuleV2;
|
|
49
|
+
} | {
|
|
50
|
+
ok: false;
|
|
51
|
+
error: string;
|
|
52
|
+
};
|
|
53
|
+
export declare function parseTrustStateCapsule(input: unknown): CapsuleParseResult;
|
|
54
|
+
export type CapsuleAdoptionConsistency = {
|
|
55
|
+
ok: boolean;
|
|
56
|
+
error?: string | undefined;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Peer-summary contract: if adoption is advertised, disclosure summary is
|
|
60
|
+
* required. Prompt-only / declaration-only cannot elevate completeness to full.
|
|
61
|
+
*/
|
|
62
|
+
export declare function validateCapsuleAdoptionConsistency(input: unknown): CapsuleAdoptionConsistency;
|
|
63
|
+
//# sourceMappingURL=capsules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capsules.d.ts","sourceRoot":"","sources":["../src/capsules.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAQ,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAmCtD,iEAAiE;AACjE,eAAO,MAAM,sCAAsC;;;;;;;EAUlD,CAAC;AAEF,MAAM,MAAM,gCAAgC,GAAG,MAAM,CACnD,OAAO,sCAAsC,CAC9C,CAAC;AAEF,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuBrC,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAE3E,MAAM,MAAM,kBAAkB,GAC1B;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,mBAAmB,CAAA;CAAE,GAC1C;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjC,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,kBAAkB,CAKzE;AAED,MAAM,MAAM,0BAA0B,GAAG;IACvC,EAAE,EAAE,OAAO,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5B,CAAC;AAEF;;;GAGG;AACH,wBAAgB,kCAAkC,CAChD,KAAK,EAAE,OAAO,GACb,0BAA0B,CAsD5B"}
|
package/dist/capsules.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trust-state capsule schema (emission deferred to later plans).
|
|
3
|
+
* Plan 13: optional adoptionDisclosure summary for peer-facing grade/assurance.
|
|
4
|
+
*/
|
|
5
|
+
import { Type } from "@sinclair/typebox";
|
|
6
|
+
import { Value } from "@sinclair/typebox/value";
|
|
7
|
+
import { FreshnessEnvelopeSchema } from "./freshness.js";
|
|
8
|
+
import { KEY_ALGORITHM } from "./identity.js";
|
|
9
|
+
import { ADOPTION_OVERLAY_FLAGS, ENFORCEMENT_GRADES, } from "./adoption.js";
|
|
10
|
+
import { ADOPTION_ASSURANCE_CLASSES } from "./adoption-disclosure.js";
|
|
11
|
+
const OverlayFlagUnion = Type.Union(ADOPTION_OVERLAY_FLAGS.map((f) => Type.Literal(f)));
|
|
12
|
+
const EnforcementGradeUnion = Type.Union(ENFORCEMENT_GRADES.map((g) => Type.Literal(g)));
|
|
13
|
+
const AssuranceUnion = Type.Union(ADOPTION_ASSURANCE_CLASSES.map((a) => Type.Literal(a)));
|
|
14
|
+
/** Compact peer-facing adoption summary (no raw MEMORY/SOUL). */
|
|
15
|
+
export const CapsuleAdoptionDisclosureSummarySchema = Type.Object({
|
|
16
|
+
constitutionHash: Type.String({ minLength: 1 }),
|
|
17
|
+
harnessId: Type.String({ minLength: 1 }),
|
|
18
|
+
localState: Type.String({ minLength: 1 }),
|
|
19
|
+
enforcementGrade: EnforcementGradeUnion,
|
|
20
|
+
overlays: Type.Array(OverlayFlagUnion),
|
|
21
|
+
assurance: AssuranceUnion,
|
|
22
|
+
}, { additionalProperties: false });
|
|
23
|
+
export const TrustStateCapsuleV2Schema = Type.Object({
|
|
24
|
+
schemaVersion: Type.Literal(2),
|
|
25
|
+
runtimeId: Type.String({ minLength: 1 }),
|
|
26
|
+
implementationVersion: Type.String({ minLength: 1 }),
|
|
27
|
+
evidenceRoot: Type.String({ minLength: 1 }),
|
|
28
|
+
coverage: Type.Object({
|
|
29
|
+
claims: Type.Integer({ minimum: 0 }),
|
|
30
|
+
receipts: Type.Integer({ minimum: 0 }),
|
|
31
|
+
completeness: Type.Union([
|
|
32
|
+
Type.Literal("none"),
|
|
33
|
+
Type.Literal("partial"),
|
|
34
|
+
Type.Literal("full"),
|
|
35
|
+
]),
|
|
36
|
+
}),
|
|
37
|
+
freshness: FreshnessEnvelopeSchema,
|
|
38
|
+
agentId: Type.String({ minLength: 1 }),
|
|
39
|
+
publicKey: Type.String({ minLength: 1 }),
|
|
40
|
+
signature: Type.String({ minLength: 1 }),
|
|
41
|
+
keyAlgorithm: Type.Literal(KEY_ALGORITHM),
|
|
42
|
+
adoptionDisclosure: Type.Optional(CapsuleAdoptionDisclosureSummarySchema),
|
|
43
|
+
}, { additionalProperties: true });
|
|
44
|
+
export function parseTrustStateCapsule(input) {
|
|
45
|
+
if (!Value.Check(TrustStateCapsuleV2Schema, input)) {
|
|
46
|
+
return { ok: false, error: "invalid TrustStateCapsuleV2" };
|
|
47
|
+
}
|
|
48
|
+
return { ok: true, capsule: input };
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Peer-summary contract: if adoption is advertised, disclosure summary is
|
|
52
|
+
* required. Prompt-only / declaration-only cannot elevate completeness to full.
|
|
53
|
+
*/
|
|
54
|
+
export function validateCapsuleAdoptionConsistency(input) {
|
|
55
|
+
if (!input || typeof input !== "object") {
|
|
56
|
+
return { ok: false, error: "capsule must be an object" };
|
|
57
|
+
}
|
|
58
|
+
const obj = input;
|
|
59
|
+
const advertising = obj.advertisingAdoption === true;
|
|
60
|
+
const disclosure = obj.adoptionDisclosure;
|
|
61
|
+
if (advertising && (disclosure === undefined || disclosure === null)) {
|
|
62
|
+
return {
|
|
63
|
+
ok: false,
|
|
64
|
+
error: "peer-summary adoption advertisement requires adoptionDisclosure summary",
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
if (disclosure === undefined || disclosure === null) {
|
|
68
|
+
return { ok: true };
|
|
69
|
+
}
|
|
70
|
+
if (!Value.Check(CapsuleAdoptionDisclosureSummarySchema, disclosure)) {
|
|
71
|
+
return { ok: false, error: "invalid adoptionDisclosure summary" };
|
|
72
|
+
}
|
|
73
|
+
const coverage = obj.coverage;
|
|
74
|
+
const completeness = coverage?.completeness;
|
|
75
|
+
if ((disclosure.enforcementGrade === "prompt-only" ||
|
|
76
|
+
disclosure.assurance === "declaration-only") &&
|
|
77
|
+
completeness === "full") {
|
|
78
|
+
return {
|
|
79
|
+
ok: false,
|
|
80
|
+
error: "prompt-only / declaration-only adoptionDisclosure cannot pair with completeness=full",
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
if (disclosure.enforcementGrade === "tool-proxy" &&
|
|
84
|
+
completeness === "full") {
|
|
85
|
+
return {
|
|
86
|
+
ok: false,
|
|
87
|
+
error: "tool-proxy adoptionDisclosure is capped at partial completeness (grade=tool-proxy assurance=" +
|
|
88
|
+
disclosure.assurance +
|
|
89
|
+
")",
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return { ok: true };
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=capsules.js.map
|