@agenticprimitives/fulfillment 0.0.0-alpha.10

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Agentic Trust Labs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # @agenticprimitives/fulfillment
2
+
3
+ > **Status: STUB** (Wave 0.5 of the W1 implementation wave). State machines, types, and invariant guards ship today; the full fulfillment runtime lands in Wave 7b per the [w1 implementation wave plan](../../docs/architecture/w1-implementation-wave-plan.md).
4
+
5
+ An agreement between two agents is worthless if no one can say, afterward, what actually happened. Who did the work, who was it handed to, what did they produce, and does the outcome match what was promised? Agent frameworks orchestrate tasks; almost none of them produce *evidence*. This package is the designed answer: a `FulfillmentCase` container where every task, message, artifact, and handoff is bound to canonical Smart Agent identities, gated by typed policy, and promoted into credentials — an `OutcomeCredential` that cannot exist without citing the `EvidenceCredential` backing it. The claim "we delivered" is structurally forced to point at proof.
6
+
7
+ This is the fulfillment slice of the substrate — spine Layers 10–12, spec'd in full, scaffolded now, landing in the implementation waves — and it shares one trust chain with the delegations that authorize the work and the payment mandates that settle it.
8
+
9
+ Part of [agenticprimitives](../../README.md) — the trust substrate for the agent economy: one canonical Smart Agent identity with custody, delegation, naming, credentials, and audit evidence designed as one system.
10
+
11
+ ## What ships today
12
+
13
+ Types, state machines, and invariant guards — no runtime, storage, or credential issuance yet:
14
+
15
+ - **`FulfillmentCase` type + lifecycle state machine** — thirteen states (`drafted` → … → `archived` / `canceled` / `disputed`) with `canTransition` enforcing legal edges. Note: transitions are shape-checked only; actor authorization is wave work.
16
+ - **A2A `Task` state machine** — `canTaskTransition` per spec 245, including the `auth-required` suspension loop for tasks awaiting a fresh delegation.
17
+ - **`HandoffPolicy` type + `isHandoffAllowed`** — typed authority binding for cross-agent handoffs. Today's check covers the agent/class allowlists only; `requiresUserApproval`, `preservePrivacyTier`, `allowedScopes`, and `maxHopCount` enforcement is wave work (tracked openly as NEW-FLF-1 in the [findings ledger](../../docs/audits/findings.yaml)).
18
+ - **`Artifact` + `OutcomeCredentialSubject` types** — hash-anchored artifacts (body never on-chain) and `assertOutcomeCitations`, the FLF-OUT-1 guard: an outcome with zero evidence citations throws.
19
+ - **`IntentTraceSpan`** — typed trace spans (parse / resolve / handoff / tool_call / user_approval / …) for end-to-end execution forensics.
20
+
21
+ ## What lands in the waves (designed, not shipped)
22
+
23
+ The operational runtime: `buildFulfillmentCase`, `transitionLifecycle` with actor authorization, `handoffTask` with full policy enforcement, message threads, artifact publication, `promoteToEvidence` / `assertOutcome` credential issuance into the attestation layer, trace-tree assembly, and lifecycle ↔ agreement-status reconciliation (FLF-INV-01). Workflow engines stay app-layer; this package is engine-agnostic.
24
+
25
+ ## Where this is heading / market context
26
+
27
+ - **Google A2A** defines the Task/Message/Artifact wire model; we adopt it (via `mcp-runtime`, spec 245) rather than invent a rival — this package adds the case container, handoff policy, and evidence promotion A2A leaves out.
28
+ - **Google AP2 and x402** give agents payment mandates; a `FulfillmentCase` binds those mandates to the tasks they pay for (`ContextBinding.taskId`, FLF-INV-11), so a machine payment is never unmoored from the work it settled.
29
+ - The differentiated combination: task execution, handoff authority, payment binding, and outcome evidence under **one** delegation + custody + audit substrate — the seam where stitched stacks lose the thread is exactly what Layers 10–12 are designed to hold.
30
+
31
+ **Authoritative spec:** [spec 244 — fulfillment](../../specs/244-fulfillment.md) (see [`spec.md`](./spec.md)). Owns spine layers 10–12; bounded surface in `CLAUDE.md` and `capability.manifest.json`.
32
+
33
+ ## Build
34
+
35
+ ```bash
36
+ pnpm --filter @agenticprimitives/fulfillment typecheck
37
+ pnpm --filter @agenticprimitives/fulfillment test
38
+ pnpm --filter @agenticprimitives/fulfillment build
39
+ ```
40
+
41
+ ## Status — honest version
42
+
43
+ STUB. What ships is the typed skeleton plus pure guards; everything operational is wave work, and the two known enforcement gaps (handoff policy fields, transition authorization) are logged publicly in [`docs/audits/findings.yaml`](../../docs/audits/findings.yaml) rather than papered over. Wave sequencing: [w1-implementation-wave-plan.md](../../docs/architecture/w1-implementation-wave-plan.md).
@@ -0,0 +1,118 @@
1
+ /**
2
+ * @agenticprimitives/fulfillment — FulfillmentCase + Task/Message/Artifact +
3
+ * Evidence/Outcome credential lifecycle.
4
+ *
5
+ * Spine Layers 10–12.
6
+ * Authoritative spec: specs/244-fulfillment.md
7
+ */
8
+ import type { Address } from '@agenticprimitives/types';
9
+ import type { VisibilityTier } from '@agenticprimitives/verifiable-credentials';
10
+ export declare const PACKAGE_NAME = "@agenticprimitives/fulfillment";
11
+ export declare const PACKAGE_STATUS: "w1-foundational";
12
+ export declare const SPEC_REF = "specs/244-fulfillment.md";
13
+ export type Hex32 = `0x${string}`;
14
+ export type FulfillmentLifecycle = 'drafted' | 'clarified' | 'expressed' | 'acknowledged' | 'proposed' | 'accepted' | 'committed' | 'in_progress' | 'fulfilled' | 'validated' | 'archived' | 'canceled' | 'disputed';
15
+ export declare function canTransition(from: FulfillmentLifecycle, to: FulfillmentLifecycle): boolean;
16
+ export type TaskState = 'submitted' | 'working' | 'completed' | 'failed' | 'canceled' | 'input-required' | 'rejected' | 'auth-required';
17
+ export declare function canTaskTransition(from: TaskState, to: TaskState): boolean;
18
+ export interface FulfillmentCase {
19
+ caseId: Hex32;
20
+ agreementCommitment: Hex32;
21
+ parties: [Address, Address];
22
+ lifecycle: FulfillmentLifecycle;
23
+ lifecycleHistory: {
24
+ from: FulfillmentLifecycle;
25
+ to: FulfillmentLifecycle;
26
+ actor: Address;
27
+ epochBucket: number;
28
+ }[];
29
+ taskIds: Hex32[];
30
+ topology: 'linear' | 'parallel' | 'dag';
31
+ visibility: string;
32
+ paymentMandateIds: Hex32[];
33
+ }
34
+ export interface Task {
35
+ taskId: Hex32;
36
+ parentCaseId?: Hex32;
37
+ parentIntentId?: string;
38
+ state: TaskState;
39
+ assignee: Address;
40
+ assigneeKind: 'person' | 'org' | 'agent' | 'oracle' | 'hybrid';
41
+ inputHash: Hex32;
42
+ artifactIds: Hex32[];
43
+ deadline?: number;
44
+ maxRetries: number;
45
+ permissionGrantRef: Hex32;
46
+ }
47
+ export interface HandoffPolicy {
48
+ allowedTargetAgents: Address[];
49
+ allowedAgentClasses: string[];
50
+ requiresUserApproval: boolean;
51
+ preservePrivacyTier: boolean;
52
+ allowedScopes: string[];
53
+ maxHopCount: number;
54
+ }
55
+ /**
56
+ * Evidence threaded into a handoff decision (FLF-INV-09 / FLF-INV-10). All fields are optional so a
57
+ * caller that has no information about a policy dimension defaults to the fail-closed answer for that
58
+ * dimension (absent approval, no requested scopes, hop 0, no destination tier).
59
+ */
60
+ export interface HandoffContext {
61
+ /** The target's agent class — checked against `HandoffPolicy.allowedAgentClasses`. */
62
+ targetClass?: string;
63
+ /** The scope(s) the handoff would carry — MUST be a subset of `allowedScopes` when that set is non-empty. */
64
+ requestedScopes?: string[];
65
+ /** The number of handoffs already performed for this task BEFORE this one (current hop, 0-based). */
66
+ hopCount?: number;
67
+ /** Explicit evidence that the user approved this handoff. Required when `requiresUserApproval` is set. */
68
+ userApproved?: boolean;
69
+ /** The source (current assignee) privacy tier — the floor the destination must not drop below. */
70
+ sourceTier?: VisibilityTier;
71
+ /** The destination (target) privacy tier — checked against `sourceTier` when `preservePrivacyTier` is set. */
72
+ destinationTier?: VisibilityTier;
73
+ }
74
+ /**
75
+ * FLF-INV-09 + FLF-INV-10: enforce the FULL handoff policy at runtime, fail-closed (ADR-0013).
76
+ *
77
+ * NEW-FLF-1: the prior implementation only checked `allowedTargetAgents` / `allowedAgentClasses` and
78
+ * silently IGNORED `requiresUserApproval`, `preservePrivacyTier`, `allowedScopes`, and `maxHopCount`,
79
+ * so handoffs those fields should have blocked or constrained were allowed. Every field is now
80
+ * enforced, and each enforcement denies (returns `false`) when its precondition is unmet — empty is an
81
+ * answer, never an escalation to a weaker path.
82
+ */
83
+ export declare function isHandoffAllowed(policy: HandoffPolicy, target: Address, ctx?: HandoffContext): boolean;
84
+ export interface Artifact {
85
+ artifactId: Hex32;
86
+ caseId: Hex32;
87
+ taskId?: Hex32;
88
+ producer: Address;
89
+ artifactKind: string;
90
+ bodyHash: Hex32;
91
+ bodyContentType: string;
92
+ disclosurePolicy: string;
93
+ createdAt: number;
94
+ }
95
+ export interface OutcomeCredentialSubject {
96
+ intentId: string;
97
+ caseId: Hex32;
98
+ intentExpected: Record<string, unknown>;
99
+ delivered: Record<string, unknown>;
100
+ actorSatisfaction: 'fully' | 'partially' | 'not';
101
+ evidenceAssertionUids: Hex32[];
102
+ }
103
+ /** FLF-OUT-1: OutcomeCredential MUST cite at least one EvidenceCredential UID. */
104
+ export declare function assertOutcomeCitations(subject: OutcomeCredentialSubject): void;
105
+ export type SpanType = 'parse' | 'clarify' | 'resolve' | 'match' | 'handoff' | 'tool_call' | 'wallet_simulation' | 'user_approval' | 'execution' | 'validation' | 'task_state_change' | 'lifecycle_transition';
106
+ export interface IntentTraceSpan {
107
+ spanId: Hex32;
108
+ parentSpanId?: Hex32;
109
+ caseId: Hex32;
110
+ intentId?: string;
111
+ spanType: SpanType;
112
+ actorAgent: Address;
113
+ inputHash: Hex32;
114
+ outputHash: Hex32;
115
+ policyVersion: string;
116
+ timestamp: number;
117
+ }
118
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2CAA2C,CAAC;AAEhF,eAAO,MAAM,YAAY,mCAAmC,CAAC;AAC7D,eAAO,MAAM,cAAc,EAAG,iBAA0B,CAAC;AACzD,eAAO,MAAM,QAAQ,6BAA6B,CAAC;AAEnD,MAAM,MAAM,KAAK,GAAG,KAAK,MAAM,EAAE,CAAC;AAIlC,MAAM,MAAM,oBAAoB,GAC5B,SAAS,GACT,WAAW,GACX,WAAW,GACX,cAAc,GACd,UAAU,GACV,UAAU,GACV,WAAW,GACX,aAAa,GACb,WAAW,GACX,WAAW,GACX,UAAU,GACV,UAAU,GACV,UAAU,CAAC;AAkBf,wBAAgB,aAAa,CAAC,IAAI,EAAE,oBAAoB,EAAE,EAAE,EAAE,oBAAoB,GAAG,OAAO,CAE3F;AAID,MAAM,MAAM,SAAS,GACjB,WAAW,GACX,SAAS,GACT,WAAW,GACX,QAAQ,GACR,UAAU,GACV,gBAAgB,GAChB,UAAU,GACV,eAAe,CAAC;AAgBpB,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,GAAG,OAAO,CAEzE;AAID,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,KAAK,CAAC;IACd,mBAAmB,EAAE,KAAK,CAAC;IAC3B,OAAO,EAAE,CAAC,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W,eAAe;IAC9B,MAAM,EAAE,KAAK,CAAC;IACd,YAAY,CAAC,EAAE,KAAK,CAAC;IACrB,MAAM,EAAE,KAAK,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,QAAQ,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,KAAK,CAAC;IACjB,UAAU,EAAE,KAAK,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;CACnB"}
package/dist/index.js ADDED
@@ -0,0 +1,103 @@
1
+ /**
2
+ * @agenticprimitives/fulfillment — FulfillmentCase + Task/Message/Artifact +
3
+ * Evidence/Outcome credential lifecycle.
4
+ *
5
+ * Spine Layers 10–12.
6
+ * Authoritative spec: specs/244-fulfillment.md
7
+ */
8
+ export const PACKAGE_NAME = '@agenticprimitives/fulfillment';
9
+ export const PACKAGE_STATUS = 'w1-foundational';
10
+ export const SPEC_REF = 'specs/244-fulfillment.md';
11
+ const LIFECYCLE_TRANSITIONS = {
12
+ drafted: ['clarified', 'canceled'],
13
+ clarified: ['expressed', 'canceled'],
14
+ expressed: ['acknowledged', 'canceled'],
15
+ acknowledged: ['proposed', 'canceled'],
16
+ proposed: ['accepted', 'canceled'],
17
+ accepted: ['committed', 'canceled'],
18
+ committed: ['in_progress', 'canceled', 'disputed'],
19
+ in_progress: ['fulfilled', 'disputed', 'canceled'],
20
+ fulfilled: ['validated', 'disputed'],
21
+ validated: ['archived'],
22
+ archived: [],
23
+ canceled: ['archived'],
24
+ disputed: ['archived'],
25
+ };
26
+ export function canTransition(from, to) {
27
+ return (LIFECYCLE_TRANSITIONS[from] ?? []).includes(to);
28
+ }
29
+ const TASK_TRANSITIONS = {
30
+ // spec 245 §4 — a `working` handler may suspend to `auth-required` pending a fresh/again-scoped
31
+ // delegation (the auth-required loop); resubmission goes `auth-required → submitted`. A not-yet-started
32
+ // `submitted` task can also be `canceled` (the sender withdraws before processing).
33
+ submitted: ['working', 'rejected', 'auth-required', 'canceled'],
34
+ 'auth-required': ['submitted'],
35
+ working: ['completed', 'failed', 'canceled', 'input-required', 'auth-required'],
36
+ 'input-required': ['working'],
37
+ completed: [],
38
+ failed: [],
39
+ canceled: [],
40
+ rejected: [],
41
+ };
42
+ export function canTaskTransition(from, to) {
43
+ return (TASK_TRANSITIONS[from] ?? []).includes(to);
44
+ }
45
+ /**
46
+ * Privacy-tier ordering, strongest → weakest. A handoff under `preservePrivacyTier` MUST NOT move to a
47
+ * tier with a HIGHER index (weaker confidentiality) than the source. Mirrors the `VisibilityTier`
48
+ * ladder in `@agenticprimitives/verifiable-credentials`.
49
+ */
50
+ const PRIVACY_TIER_RANK = {
51
+ OffchainOnly: 0,
52
+ PrivateZK: 1,
53
+ PrivateCommitment: 2,
54
+ PublicCoarse: 3,
55
+ Public: 4,
56
+ };
57
+ /**
58
+ * FLF-INV-09 + FLF-INV-10: enforce the FULL handoff policy at runtime, fail-closed (ADR-0013).
59
+ *
60
+ * NEW-FLF-1: the prior implementation only checked `allowedTargetAgents` / `allowedAgentClasses` and
61
+ * silently IGNORED `requiresUserApproval`, `preservePrivacyTier`, `allowedScopes`, and `maxHopCount`,
62
+ * so handoffs those fields should have blocked or constrained were allowed. Every field is now
63
+ * enforced, and each enforcement denies (returns `false`) when its precondition is unmet — empty is an
64
+ * answer, never an escalation to a weaker path.
65
+ */
66
+ export function isHandoffAllowed(policy, target, ctx = {}) {
67
+ // 1. Target must be an allowed agent or an allowed agent class.
68
+ const targetAllowed = policy.allowedTargetAgents.includes(target) ||
69
+ (ctx.targetClass !== undefined && policy.allowedAgentClasses.includes(ctx.targetClass));
70
+ if (!targetAllowed)
71
+ return false;
72
+ // 2. requiresUserApproval — absent explicit approval evidence → deny (fail-closed).
73
+ if (policy.requiresUserApproval && ctx.userApproved !== true)
74
+ return false;
75
+ // 3. allowedScopes — when the set is non-empty, every requested scope MUST be inside it.
76
+ if (policy.allowedScopes.length > 0) {
77
+ const requested = ctx.requestedScopes ?? [];
78
+ for (const scope of requested) {
79
+ if (!policy.allowedScopes.includes(scope))
80
+ return false;
81
+ }
82
+ }
83
+ // 4. maxHopCount — the current hop count must be strictly below the cap (this handoff is hop+1).
84
+ const hopCount = ctx.hopCount ?? 0;
85
+ if (hopCount >= policy.maxHopCount)
86
+ return false;
87
+ // 5. preservePrivacyTier — the destination tier must not be weaker than the source tier.
88
+ if (policy.preservePrivacyTier) {
89
+ // Fail-closed: if we can't compare tiers (source or destination unknown), deny.
90
+ if (ctx.sourceTier === undefined || ctx.destinationTier === undefined)
91
+ return false;
92
+ if (PRIVACY_TIER_RANK[ctx.destinationTier] > PRIVACY_TIER_RANK[ctx.sourceTier])
93
+ return false;
94
+ }
95
+ return true;
96
+ }
97
+ /** FLF-OUT-1: OutcomeCredential MUST cite at least one EvidenceCredential UID. */
98
+ export function assertOutcomeCitations(subject) {
99
+ if (subject.evidenceAssertionUids.length === 0) {
100
+ throw new Error(`[fulfillment/FLF-OUT-1] OutcomeCredential MUST cite at least one EvidenceCredential UID. D-40 substrate invariant.`);
101
+ }
102
+ }
103
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,MAAM,CAAC,MAAM,YAAY,GAAG,gCAAgC,CAAC;AAC7D,MAAM,CAAC,MAAM,cAAc,GAAG,iBAA0B,CAAC;AACzD,MAAM,CAAC,MAAM,QAAQ,GAAG,0BAA0B,CAAC;AAqBnD,MAAM,qBAAqB,GAAyD;IAClF,OAAO,EAAE,CAAC,WAAW,EAAE,UAAU,CAAC;IAClC,SAAS,EAAE,CAAC,WAAW,EAAE,UAAU,CAAC;IACpC,SAAS,EAAE,CAAC,cAAc,EAAE,UAAU,CAAC;IACvC,YAAY,EAAE,CAAC,UAAU,EAAE,UAAU,CAAC;IACtC,QAAQ,EAAE,CAAC,UAAU,EAAE,UAAU,CAAC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AAU,CAAC;YAAE,OAAO,KAAK,CAAC;IAC/F,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAuBD,kFAAkF;AAClF,MAAM,UAAU,sBAAsB,CAAC,OAAiC;IACtE,IAAI,OAAO,CAAC,qBAAqB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC/C,MAAM,IAAI,KAAK,CACb,oHAAoH,CACrH,CAAC;IACJ,CAAC;AACH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@agenticprimitives/fulfillment",
3
+ "version": "0.0.0-alpha.10",
4
+ "description": "FulfillmentCase lifecycle + Task/Message/Artifact (re-exported from mcp-runtime/a2a) + HandoffPolicy + EvidenceCredential + OutcomeCredential issuance.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/agentictrustlabs/agenticprimitives.git",
9
+ "directory": "packages/fulfillment"
10
+ },
11
+ "homepage": "https://github.com/agentictrustlabs/agenticprimitives/tree/master/packages/fulfillment",
12
+ "bugs": {
13
+ "url": "https://github.com/agentictrustlabs/agenticprimitives/issues"
14
+ },
15
+ "type": "module",
16
+ "main": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js"
22
+ }
23
+ },
24
+ "files": [
25
+ "LICENSE",
26
+ "dist",
27
+ "spec.md",
28
+ "README.md"
29
+ ],
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "peerDependencies": {
34
+ "viem": "^2.52.2"
35
+ },
36
+ "devDependencies": {
37
+ "vitest": "^4.1.8",
38
+ "viem": "^2.52.2"
39
+ },
40
+ "keywords": [
41
+ "agentic",
42
+ "primitives",
43
+ "fulfillment"
44
+ ],
45
+ "dependencies": {
46
+ "@noble/hashes": "^2.2.0",
47
+ "@agenticprimitives/agreements": "0.0.0-alpha.10",
48
+ "@agenticprimitives/attestations": "0.0.0-alpha.9",
49
+ "@agenticprimitives/delegation": "1.0.0-alpha.13",
50
+ "@agenticprimitives/types": "1.0.0-alpha.13",
51
+ "@agenticprimitives/verifiable-credentials": "0.0.0-alpha.10"
52
+ },
53
+ "scripts": {
54
+ "build": "tsc -p tsconfig.build.json",
55
+ "typecheck": "tsc -p tsconfig.json --noEmit",
56
+ "test": "vitest run",
57
+ "test:unit": "vitest run test/unit --passWithNoTests",
58
+ "test:watch": "vitest",
59
+ "clean": "rm -rf dist"
60
+ }
61
+ }
package/spec.md ADDED
@@ -0,0 +1,5 @@
1
+ # Spec pointer
2
+
3
+ Canonical spec: [`../../specs/244-*.md`](../../specs/)
4
+
5
+ Owning layers (per [coordination-substrate.md](../../docs/architecture/coordination-substrate.md)): layers-10-12.