@agenticprimitives/content-storage 0.1.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.
Files changed (72) hide show
  1. package/CLAUDE.md +55 -0
  2. package/LICENSE +21 -0
  3. package/README.md +69 -0
  4. package/dist/access.d.ts +64 -0
  5. package/dist/access.d.ts.map +1 -0
  6. package/dist/access.js +30 -0
  7. package/dist/access.js.map +1 -0
  8. package/dist/anchors.d.ts +31 -0
  9. package/dist/anchors.d.ts.map +1 -0
  10. package/dist/anchors.js +12 -0
  11. package/dist/anchors.js.map +1 -0
  12. package/dist/bundle.d.ts +39 -0
  13. package/dist/bundle.d.ts.map +1 -0
  14. package/dist/bundle.js +57 -0
  15. package/dist/bundle.js.map +1 -0
  16. package/dist/canonicalization.d.ts +5 -0
  17. package/dist/canonicalization.d.ts.map +1 -0
  18. package/dist/canonicalization.js +11 -0
  19. package/dist/canonicalization.js.map +1 -0
  20. package/dist/containment.d.ts +40 -0
  21. package/dist/containment.d.ts.map +1 -0
  22. package/dist/containment.js +53 -0
  23. package/dist/containment.js.map +1 -0
  24. package/dist/context.d.ts +28 -0
  25. package/dist/context.d.ts.map +1 -0
  26. package/dist/context.js +27 -0
  27. package/dist/context.js.map +1 -0
  28. package/dist/index.d.ts +33 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +51 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/manifest.d.ts +38 -0
  33. package/dist/manifest.d.ts.map +1 -0
  34. package/dist/manifest.js +70 -0
  35. package/dist/manifest.js.map +1 -0
  36. package/dist/publish.d.ts +62 -0
  37. package/dist/publish.d.ts.map +1 -0
  38. package/dist/publish.js +81 -0
  39. package/dist/publish.js.map +1 -0
  40. package/dist/receipts.d.ts +21 -0
  41. package/dist/receipts.d.ts.map +1 -0
  42. package/dist/receipts.js +13 -0
  43. package/dist/receipts.js.map +1 -0
  44. package/dist/relations.d.ts +23 -0
  45. package/dist/relations.d.ts.map +1 -0
  46. package/dist/relations.js +19 -0
  47. package/dist/relations.js.map +1 -0
  48. package/dist/release.d.ts +56 -0
  49. package/dist/release.d.ts.map +1 -0
  50. package/dist/release.js +30 -0
  51. package/dist/release.js.map +1 -0
  52. package/dist/resolver.d.ts +42 -0
  53. package/dist/resolver.d.ts.map +1 -0
  54. package/dist/resolver.js +58 -0
  55. package/dist/resolver.js.map +1 -0
  56. package/dist/storage-port.d.ts +81 -0
  57. package/dist/storage-port.d.ts.map +1 -0
  58. package/dist/storage-port.js +2 -0
  59. package/dist/storage-port.js.map +1 -0
  60. package/dist/types.d.ts +121 -0
  61. package/dist/types.d.ts.map +1 -0
  62. package/dist/types.js +2 -0
  63. package/dist/types.js.map +1 -0
  64. package/dist/versioning.d.ts +22 -0
  65. package/dist/versioning.d.ts.map +1 -0
  66. package/dist/versioning.js +13 -0
  67. package/dist/versioning.js.map +1 -0
  68. package/dist/wire.d.ts +88 -0
  69. package/dist/wire.d.ts.map +1 -0
  70. package/dist/wire.js +81 -0
  71. package/dist/wire.js.map +1 -0
  72. package/package.json +57 -0
package/CLAUDE.md ADDED
@@ -0,0 +1,55 @@
1
+ # @agenticprimitives/content-storage — Claude guide
2
+
3
+ Managed storage for **Content Artifacts** — SKILL.md, `.ttl`, `.md`, JSON-LD, and
4
+ the images/video that travel with them. The **stored** complement to
5
+ `content-primitives`' **referenced** content (ADR-0033): same locus/descriptor/
6
+ commitment/entitlement machinery, but the bytes live in a managed, encrypted blob
7
+ store this package fronts. **Architect-of-record: [spec 335](../../specs/335-content-artifact-managed-storage.md).**
8
+
9
+ ## Status
10
+
11
+ **Scaffold.** Owns the model (`ContentArtifact`/`ArtifactBundle`), the `StoragePort`/
12
+ `StorageProvider` interfaces, and the fail-closed `StorageManifest` validator. The
13
+ seal/open orchestration, the `/node` S3-API adapter, and the delivery plane are
14
+ phased in per spec 335 §18.
15
+
16
+ ## The one idea
17
+
18
+ `content-primitives` deliberately never stores content. A **Content Artifact** is a
19
+ `ContentDescriptor` whose `retrievalPointer` is a `blob:sha256:<ciphertext-hash>`
20
+ resolved by a `StoragePort`. Bytes are **client-side envelope-encrypted** (per-object
21
+ DEK wrapped by a KMS KEK via the `vault` `DekWrapper`), so the storage provider only
22
+ ever holds ciphertext. The descriptor/metadata live in the vault; the two-layer split
23
+ (content vs relational) is the same one the repo already enforces.
24
+
25
+ ## What this package owns
26
+
27
+ - `ContentArtifact` (stored FRBR Item) + `ArtifactBundle` (a `.md`/`.ttl` + its media
28
+ as one signed, versioned manifest) — `src/types.ts`.
29
+ - `StoragePort` (high-level, envelope-aware) + `StorageProvider` (low-level, S3-API,
30
+ **app-injected** — the one provider-specific seam) — `src/storage-port.ts`.
31
+ - `StorageManifest` + `validateStorageManifest`/`assertStorageManifest`/`resolveBackend`
32
+ — `src/manifest.ts`. Provider creds are referenced by env-var NAME, never inlined.
33
+
34
+ ## Hard rules
35
+
36
+ - **No provider hostnames or credentials in the package** (ADR-0021/0037). The concrete
37
+ `StorageProvider` driver (R2 binding, AWS SDK, GCS client) is app-injected; the
38
+ manifest names the credential env var, it never holds the secret.
39
+ - **The port does the crypto, the provider moves opaque bytes.** Envelope encryption
40
+ lives at the `StoragePort` boundary (reusing `vault` `sealEnvelope`/`DekWrapper`);
41
+ the `StorageProvider` never encrypts, decrypts, or evaluates authority.
42
+ - **Entitlement gate BEFORE `get`** (spec 335 §7): callers run the `entitlements`
43
+ matcher before decrypting; the delivery plane (§12) admits at the edge and authorizes
44
+ at the origin (ADR-0043) — this package never decides authority.
45
+ - **Commitment is required** for a stored artifact (integrity is not optional); it's the
46
+ repo-wide `contentCommitment` SHA-256 value.
47
+
48
+ ## Dependency direction (spec 335 §12)
49
+
50
+ `content-storage → { content-primitives, vault, entitlements, provenance, key-custody }`.
51
+ No back-edges. Delivery is fronted by `edge-runtime`/`edge-cloudflare` + `surface-catalog`.
52
+
53
+ ## Build
54
+
55
+ `pnpm --filter @agenticprimitives/content-storage typecheck` · `… test`
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,69 @@
1
+ # @agenticprimitives/content-storage
2
+
3
+ Managed storage for **Content Artifacts** — the unstructured content apps and agents produce, consume, and present: `SKILL.md` (agent operating guidance), `.ttl` (ontology T-box + SHACL), other Markdown/MDX docs, JSON-LD records, and the images and video that travel with them.
4
+
5
+ `@agenticprimitives/content-primitives` is deliberately a *referenced*-content substrate — it names, commits, entitlement-gates, and cites content that lives **off-platform** under a third-party rights holder, and never stores it ([ADR-0033](../../docs/architecture/decisions/0033-content-agnostic-verifiable-content-firewall.md)). This package is the **complementary stored case**: content an app/agent **owns** and must **store and manage** with the same rigor the vault gives structured/JSON-LD data — versioning, encryption, entitlement-gated access, provenance, and citation.
6
+
7
+ Architect-of-record: **[spec 335](../../specs/335-content-artifact-managed-storage.md)**.
8
+
9
+ ## The model
10
+
11
+ A **Content Artifact** is a `content-primitives` `ContentDescriptor` whose `retrievalPointer` resolves into a managed, encrypted blob store behind a `StoragePort` (`blob:sha256:<hex-of-ciphertext>`). A `.md`/`.ttl` and its media bind into one versioned, signed **`ArtifactBundle`** (a `CorpusManifest` — a Merkle root over the per-item commitments), published by advancing one immutable snapshot root.
12
+
13
+ The bytes are **client-side envelope-encrypted**: a fresh per-object DEK seals the bytes (AES-256-GCM), and the DEK is wrapped by a KMS-held KEK — so the storage provider only ever holds ciphertext. The small descriptor/metadata lives in the vault; the two-layer split (custodian-controlled content vs reconstitutable relational metadata) is the one the repo already enforces.
14
+
15
+ ## What it owns
16
+
17
+ | Concern | Export | File |
18
+ | --- | --- | --- |
19
+ | Stored FRBR Item + media bundle | `ContentArtifact`, `ArtifactBundle`, `ArtifactStorage`, `MediaChunking` | `src/types.ts` |
20
+ | The high-level, envelope-aware port | `StoragePort` (`put`/`get`/`presignGet`/`presignPut`/`delete`/`stat`) | `src/storage-port.ts` |
21
+ | The low-level, app-injected provider seam | `StorageProvider` (S3-API; R2/S3/GCS/B2/…) | `src/storage-port.ts` |
22
+ | Declarative backend config + fail-closed gate | `StorageManifest`, `validateStorageManifest`, `assertStorageManifest`, `resolveBackend` | `src/manifest.ts` |
23
+
24
+ ## Two injected ports (the ap-kms pattern, ADR-0037)
25
+
26
+ Encryption and storage are **orthogonal, injected** ports, so swapping the blob backend never touches key handling:
27
+
28
+ - **`DekWrapper` (KMS)** — the per-object DEK is wrapped by a KMS KEK. Reused from `@agenticprimitives/vault` / `key-custody`; never re-implemented here.
29
+ - **`StorageProvider` (blobs)** — a provider-agnostic S3-API adapter covers S3 / Cloudflare R2 / GCS-interop / Backblaze B2 / Tigris / Wasabi / MinIO from one client; a separate adapter covers content-addressed stores (IPFS/Arweave). The concrete driver is **app-injected** and selected by an opaque `platform` tag; the `StorageManifest` names the credential **env var**, never the secret.
30
+
31
+ ## Delivery (spec 335 §12–§13)
32
+
33
+ Artifacts are reached through the **Agentic Edge**, which owns *admission* only, never authority ([ADR-0043](../../docs/architecture/decisions/0043-edge-owns-admission-never-authority.md)). Because the bytes are encrypted, the **ciphertext is inert and publicly CDN-cacheable by content address**; the access gate sits only on the short-TTL **presign + DEK release** the origin issues after re-running the Web3 authority check (delegation + entitlement + signature). An external relying-party app reaches artifacts via SSO (`connect`/`fedcm-rp`) — which federates **identity, never authority**; the custodial authority is a scoped, revocable delegation re-verified at the origin ([ADR-0019](../../docs/architecture/decisions/0019-relying-site-authority-is-a-scoped-delegation.md), [ADR-0041](../../docs/architecture/decisions/0041-web3-authority-not-oauth-on-a2a-to-mcp.md)).
34
+
35
+ ## Competitive positioning — an agent-native document library
36
+
37
+ Full analysis: [`docs/architecture/content-library-competitive-analysis.md`](../../docs/architecture/content-library-competitive-analysis.md) (SharePoint, Google Drive, Dropbox, Box, Notion, Confluence, M-Files, Egnyte, Alfresco).
38
+
39
+ Every incumbent DMS treats **access** as a share-link/ACL bolted to a folder, **conversation** as comment threads *adjacent to* (never bound to) the artifact, and **provenance** as a mutable, vendor-trusted version list — and "AI" is a retrieval assistant layered on a **human-owned** permission model. This package is the substrate for a library where each of those is a **native primitive**, so they compose out of the box:
40
+
41
+ | | Incumbents | This library |
42
+ |---|---|---|
43
+ | Access | share link / ACL row (vendor-trusted, silently mutable) | **on-chain entitlement + scoped delegation** — per-artifact, expiring, **revocable + verifiable** (ADR-0019, `entitlements`) |
44
+ | Discussion | comment threads / Teams / Board views; only Alfresco has a forum, and it's *site*-scoped | **native discussion board bound to the artifact's canonical id** |
45
+ | Notify | vendor email / in-app feed (human-addressed) | **native agent-to-agent messaging** to the grantee agent |
46
+ | Provenance | mutable version list (Google deletes after 30d/100) | **append-only Merkle transparency log**, independently verifiable (`contentCommitment`) |
47
+ | Content | one backend | **multi-source** — object store / GraphDB / vault under one canonical id |
48
+ | Actor | a person; agents borrow a human seat | **agent-native** — person / org / service agent IS the entitlement subject |
49
+
50
+ ## Native integration — the one seam
51
+
52
+ Because access, messaging, discussion, provenance, and identity are the **same** substrate's primitives, they compose with **zero connectors**. The uniform hook is one context link — `artifactContextRef(canonicalId)` → `{ kind: 'artifact', id: 'artifact:<canonicalId>' }` — which every messaging (`MessageEnvelopeV1.contextRefs`), discussion (`ConversationDescriptorV1`/`DiscussionTopicV1`), inbox-rule (`InboxRuleV1.contextRefAnyOf`), and notification (`HomeControlEventV1.refs`) surface already accepts, all keyed on the **same identity** the entitlement layer gates on (`artifactResourceId`):
53
+
54
+ - **Grant a document to an org** → an on-chain entitlement is minted → the org-agent **auto-receives a native message** → gains access to the artifact's **discussion board** under that same grant. One action, three primitives, zero connectors.
55
+ - **Publish a new version** → a new Merkle leaf → the validator proves it independently → every grantee agent is **messaged natively** → the board thread stays bound across the bump.
56
+ - **Revoke** → an on-chain state transition → the entitlement is verifiably dead → board/message access drops in the same motion.
57
+
58
+ Exports for this: `artifactContextRef`, `ARTIFACT_CONTEXT_KIND`, `isArtifactContextRef` (`src/context.ts`); `buildArtifactAccessGrant`, `artifactResourceId` (`src/access.ts`).
59
+
60
+ ## Status
61
+
62
+ **Scaffold** — the model, the ports, and the manifest validator, with the phased roadmap in spec 335 §18 (seal/open orchestration → encrypted `.md` → media → seekable encrypted video → LLM binding → delivery plane). The concrete `StorageProvider` drivers and the deployed edge are app/external-repo code (ADR-0037), never shipped from this package.
63
+
64
+ ## Build
65
+
66
+ ```bash
67
+ pnpm --filter @agenticprimitives/content-storage typecheck
68
+ pnpm --filter @agenticprimitives/content-storage test
69
+ ```
@@ -0,0 +1,64 @@
1
+ import type { Address, Hex } from '@agenticprimitives/types';
2
+ import type { ContentArtifact } from './types.js';
3
+ export type AgentKind = 'person' | 'org' | 'service';
4
+ /** An agent being granted (or holding) access — a Smart Agent, classed per ADR-0046. */
5
+ export interface AgentRef {
6
+ address: Address;
7
+ kind: AgentKind;
8
+ /** Optional display label (name/handle) — presentation only; the address is canonical. */
9
+ label?: string;
10
+ }
11
+ /** Actions grantable on an artifact (a subset of the `entitlements` action set). */
12
+ export type ArtifactAction = 'read' | 'write' | 'share' | 'export' | 'delete';
13
+ /**
14
+ * The entitlement `resource` id for an artifact — its **canonical locus**, UNIFORM across sources.
15
+ * A `.ttl` from GraphDB, a JSON-LD record from a vault, and a `.md` blob all resolve access the same
16
+ * way, because access is keyed on the artifact identity, not its storage.
17
+ */
18
+ export declare function artifactResourceId(canonicalId: Hex): string;
19
+ /** Convenience: the resource id for a stored artifact record. */
20
+ export declare function resourceForArtifact(artifact: Pick<ContentArtifact, 'descriptor'>): string;
21
+ /**
22
+ * A request to grant an agent access to one specific artifact — the shape the manage-access UI emits.
23
+ * It is a *specification*; the `entitlements`/`delegation` layer mints the actual VC + delegation
24
+ * (injected, per ADR-0006). `grantor` is the owning person or org SA; `grantee` is any person/org/
25
+ * service SA. `fields` narrows to a sub-artifact (e.g. front-matter vs body vs a media variant).
26
+ */
27
+ export interface ArtifactAccessGrant {
28
+ /** The artifact's canonical locus. */
29
+ artifact: Hex;
30
+ /** `artifactResourceId(artifact)` — the entitlement resource. */
31
+ resource: string;
32
+ /** The owning person/org SA issuing the grant. */
33
+ grantor: Address;
34
+ /** The person/org/service SA being given access. */
35
+ grantee: AgentRef;
36
+ actions: ArtifactAction[];
37
+ fields?: string[];
38
+ validFrom?: string;
39
+ validUntil?: string;
40
+ /** Human-readable reason/terms (audit + the grantee's consent record). */
41
+ terms?: string;
42
+ }
43
+ /** Pure shaper: build the grant spec for "give this agent access to this artifact". */
44
+ export declare function buildArtifactAccessGrant(input: {
45
+ artifact: Pick<ContentArtifact, 'descriptor'>;
46
+ grantor: Address;
47
+ grantee: AgentRef;
48
+ actions: ArtifactAction[];
49
+ fields?: string[];
50
+ validFrom?: string;
51
+ validUntil?: string;
52
+ terms?: string;
53
+ }): ArtifactAccessGrant;
54
+ /** A resolved "who has access" row for the manage-access view (projected from live entitlements). */
55
+ export interface ArtifactAccessEntry {
56
+ grantee: AgentRef;
57
+ actions: ArtifactAction[];
58
+ fields?: string[];
59
+ status: 'active' | 'expired' | 'revoked';
60
+ validUntil?: string;
61
+ /** The entitlement/delegation reference backing this row (for the revoke control). */
62
+ grantRef?: string;
63
+ }
64
+ //# sourceMappingURL=access.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"access.d.ts","sourceRoot":"","sources":["../src/access.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AASlD,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,KAAK,GAAG,SAAS,CAAC;AAErD,wFAAwF;AACxF,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,SAAS,CAAC;IAChB,0FAA0F;IAC1F,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,oFAAoF;AACpF,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE9E;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,GAAG,GAAG,MAAM,CAE3D;AAED,iEAAiE;AACjE,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,IAAI,CAAC,eAAe,EAAE,YAAY,CAAC,GAAG,MAAM,CAEzF;AAED;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC,sCAAsC;IACtC,QAAQ,EAAE,GAAG,CAAC;IACd,iEAAiE;IACjE,QAAQ,EAAE,MAAM,CAAC;IACjB,kDAAkD;IAClD,OAAO,EAAE,OAAO,CAAC;IACjB,oDAAoD;IACpD,OAAO,EAAE,QAAQ,CAAC;IAClB,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,0EAA0E;IAC1E,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,uFAAuF;AACvF,wBAAgB,wBAAwB,CAAC,KAAK,EAAE;IAC9C,QAAQ,EAAE,IAAI,CAAC,eAAe,EAAE,YAAY,CAAC,CAAC;IAC9C,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,QAAQ,CAAC;IAClB,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,GAAG,mBAAmB,CActB;AAED,qGAAqG;AACrG,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,QAAQ,CAAC;IAClB,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,EAAE,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;IACzC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,sFAAsF;IACtF,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
package/dist/access.js ADDED
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The entitlement `resource` id for an artifact — its **canonical locus**, UNIFORM across sources.
3
+ * A `.ttl` from GraphDB, a JSON-LD record from a vault, and a `.md` blob all resolve access the same
4
+ * way, because access is keyed on the artifact identity, not its storage.
5
+ */
6
+ export function artifactResourceId(canonicalId) {
7
+ return `artifact:${canonicalId}`;
8
+ }
9
+ /** Convenience: the resource id for a stored artifact record. */
10
+ export function resourceForArtifact(artifact) {
11
+ return artifactResourceId(artifact.descriptor.canonicalId);
12
+ }
13
+ /** Pure shaper: build the grant spec for "give this agent access to this artifact". */
14
+ export function buildArtifactAccessGrant(input) {
15
+ if (input.actions.length === 0)
16
+ throw new Error('an access grant must include at least one action');
17
+ const canonicalId = input.artifact.descriptor.canonicalId;
18
+ return {
19
+ artifact: canonicalId,
20
+ resource: artifactResourceId(canonicalId),
21
+ grantor: input.grantor,
22
+ grantee: input.grantee,
23
+ actions: [...new Set(input.actions)],
24
+ fields: input.fields,
25
+ validFrom: input.validFrom,
26
+ validUntil: input.validUntil,
27
+ terms: input.terms,
28
+ };
29
+ }
30
+ //# sourceMappingURL=access.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"access.js","sourceRoot":"","sources":["../src/access.ts"],"names":[],"mappings":"AAuBA;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,WAAgB;IACjD,OAAO,YAAY,WAAW,EAAE,CAAC;AACnC,CAAC;AAED,iEAAiE;AACjE,MAAM,UAAU,mBAAmB,CAAC,QAA6C;IAC/E,OAAO,kBAAkB,CAAC,QAAQ,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;AAC7D,CAAC;AAyBD,uFAAuF;AACvF,MAAM,UAAU,wBAAwB,CAAC,KASxC;IACC,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACpG,MAAM,WAAW,GAAG,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,WAAW,CAAC;IAC1D,OAAO;QACL,QAAQ,EAAE,WAAW;QACrB,QAAQ,EAAE,kBAAkB,CAAC,WAAW,CAAC;QACzC,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,OAAO,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACpC,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,KAAK,EAAE,KAAK,CAAC,KAAK;KACnB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,31 @@
1
+ import type { Hex } from '@agenticprimitives/types';
2
+ export type AnchorSelector = {
3
+ kind: 'byte-range';
4
+ start: number;
5
+ end: number;
6
+ } | {
7
+ kind: 'char-range';
8
+ start: number;
9
+ end: number;
10
+ } | {
11
+ kind: 'line-range';
12
+ start: number;
13
+ end: number;
14
+ } | {
15
+ kind: 'json-pointer';
16
+ pointer: string;
17
+ } | {
18
+ kind: 'fragment';
19
+ value: string;
20
+ };
21
+ export interface ContentAnchor {
22
+ /** The `versionId` (or content commitment) the anchor is bound to. */
23
+ target: Hex;
24
+ selector: AnchorSelector;
25
+ /** Canonical digest over (target, selector) — stable, tamper-evident. */
26
+ anchorId: Hex;
27
+ }
28
+ export declare function anchorId(target: Hex, selector: AnchorSelector): Hex;
29
+ export declare function buildAnchor(target: Hex, selector: AnchorSelector): ContentAnchor;
30
+ export declare function verifyAnchor(a: ContentAnchor): boolean;
31
+ //# sourceMappingURL=anchors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anchors.d.ts","sourceRoot":"","sources":["../src/anchors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAQpD,MAAM,MAAM,cAAc,GACtB;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAClD;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAClD;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAClD;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACzC;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAExC,MAAM,WAAW,aAAa;IAC5B,sEAAsE;IACtE,MAAM,EAAE,GAAG,CAAC;IACZ,QAAQ,EAAE,cAAc,CAAC;IACzB,yEAAyE;IACzE,QAAQ,EAAE,GAAG,CAAC;CACf;AAID,wBAAgB,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,cAAc,GAAG,GAAG,CAEnE;AACD,wBAAgB,WAAW,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,cAAc,GAAG,aAAa,CAEhF;AACD,wBAAgB,YAAY,CAAC,CAAC,EAAE,aAAa,GAAG,OAAO,CAEtD"}
@@ -0,0 +1,12 @@
1
+ import { canonicalDigest } from './canonicalization.js';
2
+ const idFields = (target, selector) => ({ target, selector });
3
+ export function anchorId(target, selector) {
4
+ return canonicalDigest(idFields(target, selector));
5
+ }
6
+ export function buildAnchor(target, selector) {
7
+ return { target, selector, anchorId: anchorId(target, selector) };
8
+ }
9
+ export function verifyAnchor(a) {
10
+ return anchorId(a.target, a.selector) === a.anchorId;
11
+ }
12
+ //# sourceMappingURL=anchors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anchors.js","sourceRoot":"","sources":["../src/anchors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAsBxD,MAAM,QAAQ,GAAG,CAAC,MAAW,EAAE,QAAwB,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;AAEnF,MAAM,UAAU,QAAQ,CAAC,MAAW,EAAE,QAAwB;IAC5D,OAAO,eAAe,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;AACrD,CAAC;AACD,MAAM,UAAU,WAAW,CAAC,MAAW,EAAE,QAAwB;IAC/D,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,CAAC;AACpE,CAAC;AACD,MAAM,UAAU,YAAY,CAAC,CAAgB;IAC3C,OAAO,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC;AACvD,CAAC"}
@@ -0,0 +1,39 @@
1
+ import type { Hex } from '@agenticprimitives/types';
2
+ import type { ArtifactBundle, BundleKind, BundleMemberRole } from './types.js';
3
+ export declare const BUNDLE_MEMBER_ROLES: readonly BundleMemberRole[];
4
+ /** A manifest entry — one member file inside a bundle directory, with its logical path, role, and
5
+ * content commitment (what the `containmentRoot` is computed over). */
6
+ export interface BundleMember {
7
+ /** Logical path within the bundle, e.g. `SKILL.md`, `./queries/find.rq`, `./img/fig1.png`. */
8
+ path: string;
9
+ role: BundleMemberRole;
10
+ /** The member's content commitment (`contentCommitment(bytes).value`). */
11
+ commitment: Hex;
12
+ }
13
+ /** A bundle manifest — the primary body + supporting members that make up one skill/doc directory. */
14
+ export interface BundleManifest {
15
+ bundleKind: BundleKind;
16
+ /** The logical path of the primary member (the SKILL.md / doc `.md`). */
17
+ primaryPath: string;
18
+ members: BundleMember[];
19
+ }
20
+ /** Infer a member's role from its logical path (and optional content type) — the default classifier a
21
+ * drag-and-drop import uses. `SKILL.md` → skill-md; `*.rq`/`*.sparql` → sparql; code/schema/data/media
22
+ * by extension; everything else → asset. */
23
+ export declare function inferMemberRole(path: string, contentType?: string): BundleMemberRole;
24
+ /** The Merkle root over a bundle's members — its manifest commitment. Identical to a container's
25
+ * `containmentRoot`: a skill directory and a folder are the same primitive. */
26
+ export declare function bundleManifestRoot(members: Pick<BundleMember, 'commitment'>[]): Hex;
27
+ /** The container resource id addressing the whole bundle — a grant on it cascades to every member. */
28
+ export declare function bundleResourceId(bundlePath: string): string;
29
+ /** Recompute a bundle's `containmentRoot` from its members and confirm the stored root matches — the
30
+ * integrity check that the manifest wasn't tampered with. */
31
+ export declare function verifyBundleRoot(bundle: Pick<ArtifactBundle, 'containmentRoot'>, members: Pick<BundleMember, 'commitment'>[]): boolean;
32
+ /** Prove a single member is in the bundle (the `containment-membership-v1` inclusion proof). */
33
+ export declare function proveBundleMember(members: Pick<BundleMember, 'commitment'>[], index: number): {
34
+ proof: Hex[];
35
+ root: Hex;
36
+ };
37
+ /** Verify a member-inclusion proof against a bundle root. */
38
+ export declare function verifyBundleMember(memberCommitment: Hex, proof: Hex[], root: Hex): boolean;
39
+ //# sourceMappingURL=bundle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAS/E,eAAO,MAAM,mBAAmB,EAAE,SAAS,gBAAgB,EAE1D,CAAC;AAEF;wEACwE;AACxE,MAAM,WAAW,YAAY;IAC3B,8FAA8F;IAC9F,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,gBAAgB,CAAC;IACvB,0EAA0E;IAC1E,UAAU,EAAE,GAAG,CAAC;CACjB;AAED,sGAAsG;AACtG,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,UAAU,CAAC;IACvB,yEAAyE;IACzE,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,YAAY,EAAE,CAAC;CACzB;AAED;;6CAE6C;AAC7C,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAapF;AAED;gFACgF;AAChF,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,EAAE,YAAY,CAAC,EAAE,GAAG,GAAG,CAEnF;AAED,sGAAsG;AACtG,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAE3D;AAED;8DAC8D;AAC9D,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE,iBAAiB,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,YAAY,EAAE,YAAY,CAAC,EAAE,GAAG,OAAO,CAEtI;AAED,gGAAgG;AAChG,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,EAAE,YAAY,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,GAAG,EAAE,CAAC;IAAC,IAAI,EAAE,GAAG,CAAA;CAAE,CAEzH;AAED,6DAA6D;AAC7D,wBAAgB,kBAAkB,CAAC,gBAAgB,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAE1F"}
package/dist/bundle.js ADDED
@@ -0,0 +1,57 @@
1
+ import { containmentRoot, verifyMembership, proveMembership, containerResourceId } from './containment.js';
2
+ // Skill/doc BUNDLE = a directory that IS a Container (spec 335 §7.2). A skill is not a single SKILL.md
3
+ // file — it's a directory of a SKILL.md plus the SPARQL queries, code segments, schemas, and media that
4
+ // realize it (Claude skill management models a skill this way). A rich doc is a `.md` plus its media.
5
+ // Membership is Merkle-committed via the SAME `containmentRoot` used for folders and spatial regions —
6
+ // one primitive — so a grant on the bundle cascades to every member and membership is O(log n)-provable.
7
+ export const BUNDLE_MEMBER_ROLES = [
8
+ 'skill-md', 'doc-md', 'sparql', 'code', 'schema', 'data', 'media', 'asset',
9
+ ];
10
+ /** Infer a member's role from its logical path (and optional content type) — the default classifier a
11
+ * drag-and-drop import uses. `SKILL.md` → skill-md; `*.rq`/`*.sparql` → sparql; code/schema/data/media
12
+ * by extension; everything else → asset. */
13
+ export function inferMemberRole(path, contentType) {
14
+ const p = path.toLowerCase().replace(/^\.\//, '');
15
+ const base = p.split('/').pop() ?? p;
16
+ const ext = base.includes('.') ? base.slice(base.lastIndexOf('.') + 1) : '';
17
+ if (base === 'skill.md')
18
+ return 'skill-md';
19
+ if (ext === 'rq' || ext === 'sparql')
20
+ return 'sparql';
21
+ if (['ttl', 'shacl', 'owl', 'rdf', 'nt', 'jsonschema'].includes(ext))
22
+ return 'schema';
23
+ if (['ts', 'tsx', 'js', 'mjs', 'py', 'rs', 'go', 'sh', 'sql'].includes(ext))
24
+ return 'code';
25
+ if (['png', 'jpg', 'jpeg', 'gif', 'webp', 'svg', 'mp4', 'webm', 'mov', 'mp3', 'wav'].includes(ext))
26
+ return 'media';
27
+ if (['json', 'jsonld', 'csv', 'tsv', 'yaml', 'yml'].includes(ext))
28
+ return 'data';
29
+ if (ext === 'md')
30
+ return 'doc-md';
31
+ if (contentType?.startsWith('image/') || contentType?.startsWith('video/') || contentType?.startsWith('audio/'))
32
+ return 'media';
33
+ return 'asset';
34
+ }
35
+ /** The Merkle root over a bundle's members — its manifest commitment. Identical to a container's
36
+ * `containmentRoot`: a skill directory and a folder are the same primitive. */
37
+ export function bundleManifestRoot(members) {
38
+ return containmentRoot(members.map((m) => m.commitment));
39
+ }
40
+ /** The container resource id addressing the whole bundle — a grant on it cascades to every member. */
41
+ export function bundleResourceId(bundlePath) {
42
+ return containerResourceId(bundlePath);
43
+ }
44
+ /** Recompute a bundle's `containmentRoot` from its members and confirm the stored root matches — the
45
+ * integrity check that the manifest wasn't tampered with. */
46
+ export function verifyBundleRoot(bundle, members) {
47
+ return bundle.containmentRoot === bundleManifestRoot(members);
48
+ }
49
+ /** Prove a single member is in the bundle (the `containment-membership-v1` inclusion proof). */
50
+ export function proveBundleMember(members, index) {
51
+ return proveMembership(members.map((m) => m.commitment), index);
52
+ }
53
+ /** Verify a member-inclusion proof against a bundle root. */
54
+ export function verifyBundleMember(memberCommitment, proof, root) {
55
+ return verifyMembership(memberCommitment, proof, root);
56
+ }
57
+ //# sourceMappingURL=bundle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundle.js","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,eAAe,EAAE,m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,CAAC,gBAAqB,EAAE,KAAY,EAAE,IAAS;IAC/E,OAAO,gBAAgB,CAAC,gBAAgB,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;AACzD,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { jcsCanonicalize } from '@agenticprimitives/content-primitives';
2
+ import type { Hex } from '@agenticprimitives/types';
3
+ export declare function canonicalDigest(value: unknown): Hex;
4
+ export { jcsCanonicalize };
5
+ //# sourceMappingURL=canonicalization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonicalization.d.ts","sourceRoot":"","sources":["../src/canonicalization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,eAAe,EAAE,MAAM,uCAAuC,CAAC;AACvF,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAOpD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,GAAG,CAEnD;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { canonicalHash, jcsCanonicalize } from '@agenticprimitives/content-primitives';
2
+ // Contracts-before-storage (spec 335 §Phase 2). Every stable id/digest in the content fabric is derived
3
+ // from the ONE canonicalization stack — RFC 8785 JCS + keccak256, shared with credentials — never a
4
+ // bespoke serializer. `canonicalDigest(x)` is the stable commitment over any JSON-able value: two
5
+ // values that normalize equally (key order, whitespace, number form) produce an identical digest. This
6
+ // is what makes version ids, release ids, dependency locks, and receipts reproducible across producers.
7
+ export function canonicalDigest(value) {
8
+ return canonicalHash(value);
9
+ }
10
+ export { jcsCanonicalize };
11
+ //# sourceMappingURL=canonicalization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonicalization.js","sourceRoot":"","sources":["../src/canonicalization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAGvF,wGAAwG;AACxG,oGAAoG;AACpG,kGAAkG;AAClG,uGAAuG;AACvG,wGAAwG;AACxG,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,OAAO,aAAa,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
@@ -0,0 +1,40 @@
1
+ import type { Hex } from '@agenticprimitives/types';
2
+ /** The container-resource id for a hierarchical path, e.g. `container:reports/2026`. Access on this
3
+ * resource cascades to everything under the path — uniform whether the path is a folder or a region. */
4
+ export declare function containerResourceId(path: string): string;
5
+ /** The inclusive ancestor paths of a container path: `a/b/c` → [`a`, `a/b`, `a/b/c`]. */
6
+ export declare function ancestorPaths(path: string): string[];
7
+ /** The container-resource ids of every ancestor of a leaf at `path` (broadest → narrowest). A grant
8
+ * on any of these authorizes the leaf. */
9
+ export declare function ancestorContainerResources(path: string): string[];
10
+ /** The Merkle root committing a container's subtree — over the sorted-order member commitments. */
11
+ export declare function containmentRoot(memberCommitments: Hex[]): Hex;
12
+ /** Prove that member #`index` is under a container: returns its inclusion proof + the root. */
13
+ export declare function proveMembership(memberCommitments: Hex[], index: number): {
14
+ proof: Hex[];
15
+ root: Hex;
16
+ };
17
+ /** Verify "this member is under this container" — the `containment-membership-v1` check. */
18
+ export declare function verifyMembership(memberCommitment: Hex, proof: Hex[], root: Hex): boolean;
19
+ /** The minimal shape a resolver query/decision must have for inheritance. Structural, so this stays
20
+ * free of the entitlements package — pass any `EntitlementResolver` (VerifiedEntitlementResolver). */
21
+ export interface InheritableResolver<Q extends {
22
+ resource: string;
23
+ }, D extends {
24
+ decision: string;
25
+ }> {
26
+ resolve(query: Q): Promise<D> | D;
27
+ }
28
+ /**
29
+ * Resolve access WITH hierarchical inheritance: a grant on any ancestor container authorizes the leaf.
30
+ * Wraps an inner resolver (e.g. `VerifiedEntitlementResolver`) — the audited matcher is unchanged; this
31
+ * only expands the query to the ancestor container resources (broadest → narrowest) and the leaf, and
32
+ * returns the first `allow`. This is the ancestor-walk that makes "grant a folder → everything under it"
33
+ * (and "grant a country → every place within it") work over one primitive.
34
+ */
35
+ export declare function resolveWithInheritance<Q extends {
36
+ resource: string;
37
+ }, D extends {
38
+ decision: string;
39
+ }>(inner: InheritableResolver<Q, D>, query: Q, ancestorResources: string[]): Promise<D>;
40
+ //# sourceMappingURL=containment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"containment.d.ts","sourceRoot":"","sources":["../src/containment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AASpD;yGACyG;AACzG,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAExD;AAED,yFAAyF;AACzF,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAGpD;AAED;2CAC2C;AAC3C,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAEjE;AAID,mGAAmG;AACnG,wBAAgB,eAAe,CAAC,iBAAiB,EAAE,GAAG,EAAE,GAAG,GAAG,CAE7D;AAED,+FAA+F;AAC/F,wBAAgB,eAAe,CAAC,iBAAiB,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,GAAG,EAAE,CAAC;IAAC,IAAI,EAAE,GAAG,CAAA;CAAE,CAGpG;AAED,4FAA4F;AAC5F,wBAAgB,gBAAgB,CAAC,gBAAgB,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAExF;AAID;uGACuG;AACvG,MAAM,WAAW,mBAAmB,CAAC,CAAC,SAAS;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,EAAE,CAAC,SAAS;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE;IACjG,OAAO,CAAC,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;CACnC;AAED;;;;;;GAMG;AACH,wBAAsB,sBAAsB,CAAC,CAAC,SAAS;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,EAAE,CAAC,SAAS;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,EACzG,KAAK,EAAE,mBAAmB,CAAC,CAAC,EAAE,CAAC,CAAC,EAChC,KAAK,EAAE,CAAC,EACR,iBAAiB,EAAE,MAAM,EAAE,GAC1B,OAAO,CAAC,CAAC,CAAC,CAQZ"}
@@ -0,0 +1,53 @@
1
+ import { buildCorpusTree, leafHash, merkleProof, verifyInclusion, merkleRoot } from '@agenticprimitives/content-primitives';
2
+ // Containment hierarchy (spec 335 §7.2, ontology at:Container/at:contains). One abstraction over BOTH
3
+ // document folders AND spatial regions (country → state → … → point): a Container holds contents
4
+ // transitively, so a grant on a container reaches its whole subtree, and membership is efficiently
5
+ // provable via a Merkle `containmentRoot` — reusing the audited content-primitives merkle helpers
6
+ // (sorted-pair, double-keccak leaf, OpenZeppelin-compatible; the `merkle-membership-v1` atom).
7
+ /** The container-resource id for a hierarchical path, e.g. `container:reports/2026`. Access on this
8
+ * resource cascades to everything under the path — uniform whether the path is a folder or a region. */
9
+ export function containerResourceId(path) {
10
+ return `container:${path.replace(/^\/+|\/+$/g, '')}`;
11
+ }
12
+ /** The inclusive ancestor paths of a container path: `a/b/c` → [`a`, `a/b`, `a/b/c`]. */
13
+ export function ancestorPaths(path) {
14
+ const segs = path.replace(/^\/+|\/+$/g, '').split('/').filter(Boolean);
15
+ return segs.map((_, i) => segs.slice(0, i + 1).join('/'));
16
+ }
17
+ /** The container-resource ids of every ancestor of a leaf at `path` (broadest → narrowest). A grant
18
+ * on any of these authorizes the leaf. */
19
+ export function ancestorContainerResources(path) {
20
+ return ancestorPaths(path).map(containerResourceId);
21
+ }
22
+ // ── Merkle-committed subtree membership (reuses content-primitives merkle) ──
23
+ /** The Merkle root committing a container's subtree — over the sorted-order member commitments. */
24
+ export function containmentRoot(memberCommitments) {
25
+ return merkleRoot(memberCommitments.map(leafHash));
26
+ }
27
+ /** Prove that member #`index` is under a container: returns its inclusion proof + the root. */
28
+ export function proveMembership(memberCommitments, index) {
29
+ const tree = buildCorpusTree(memberCommitments.map(leafHash));
30
+ return { proof: merkleProof(tree, index), root: tree.root };
31
+ }
32
+ /** Verify "this member is under this container" — the `containment-membership-v1` check. */
33
+ export function verifyMembership(memberCommitment, proof, root) {
34
+ return verifyInclusion(leafHash(memberCommitment), proof, root);
35
+ }
36
+ /**
37
+ * Resolve access WITH hierarchical inheritance: a grant on any ancestor container authorizes the leaf.
38
+ * Wraps an inner resolver (e.g. `VerifiedEntitlementResolver`) — the audited matcher is unchanged; this
39
+ * only expands the query to the ancestor container resources (broadest → narrowest) and the leaf, and
40
+ * returns the first `allow`. This is the ancestor-walk that makes "grant a folder → everything under it"
41
+ * (and "grant a country → every place within it") work over one primitive.
42
+ */
43
+ export async function resolveWithInheritance(inner, query, ancestorResources) {
44
+ let last;
45
+ for (const resource of [...ancestorResources, query.resource]) {
46
+ const d = await inner.resolve({ ...query, resource });
47
+ if (d.decision === 'allow')
48
+ return d;
49
+ last = d;
50
+ }
51
+ return last ?? (await inner.resolve(query));
52
+ }
53
+ //# sourceMappingURL=containment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"containment.js","sourceRoot":"","sources":["../src/containment.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,WAAW,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AAE5H,sGAAsG;AACtG,iGAAiG;AACjG,mGAAmG;AACnG,kGAAkG;AAClG,+FAA+F;AAE/F;yGACyG;AACzG,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC9C,OAAO,aAAa,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,EAAE,CAAC;AACvD,CAAC;AAED,yFAAyF;AACzF,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,E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,CAAC,EAAE,CAAC;QAC9D,MAAM,CAAC,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,EAAE,GAAG,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;QACtD,IAAI,CAAC,CAAC,QAAQ,KAAK,OAAO;YAAE,OAAO,CAAC,CAAC;QACrC,IAAI,GAAG,CAAC,CAAC;IACX,CAAC;IACD,OAAO,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,28 @@
1
+ import type { Hex } from '@agenticprimitives/types';
2
+ /** The ContextRef `kind` for a Content Artifact (an app-defined kind per ADR-0021). */
3
+ export declare const ARTIFACT_CONTEXT_KIND: "artifact";
4
+ /** A typed pointer that says "this message / thread / event is ABOUT this artifact". Structurally a
5
+ * `fabric` `ContextRefV1` — display + routing metadata, never authority. */
6
+ export interface ArtifactContextRef {
7
+ kind: typeof ARTIFACT_CONTEXT_KIND;
8
+ /** `artifact:<canonicalId>` — the same resource the entitlement layer gates on. */
9
+ id: string;
10
+ /** Optional human label for the surface that shows it. */
11
+ label?: string;
12
+ /** Optional content commitment (integrity), matching the `content-hash` ref precedent. */
13
+ hash?: Hex;
14
+ }
15
+ /**
16
+ * Build the artifact ContextRef. `id` is `artifactResourceId(canonicalId)`, so "discuss it", "share it
17
+ * to a channel", "notify grantees", and "who can access it" all resolve to one identity — the seam that
18
+ * lets the Library reuse messaging / discussion / entitlements natively.
19
+ */
20
+ export declare function artifactContextRef(canonicalId: Hex, opts?: {
21
+ label?: string;
22
+ hash?: Hex;
23
+ }): ArtifactContextRef;
24
+ /** True if a ContextRef-like value points at an artifact. */
25
+ export declare function isArtifactContextRef(ref: {
26
+ kind?: string;
27
+ } | null | undefined): ref is ArtifactContextRef;
28
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAepD,uFAAuF;AACvF,eAAO,MAAM,qBAAqB,EAAG,UAAmB,CAAC;AAEzD;6EAC6E;AAC7E,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,OAAO,qBAAqB,CAAC;IACnC,mFAAmF;IACnF,EAAE,EAAE,MAAM,CAAC;IACX,0DAA0D;IAC1D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0FAA0F;IAC1F,IAAI,CAAC,EAAE,GAAG,CAAC;CACZ;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,GAAG,CAAA;CAAE,GAAG,kBAAkB,CAE9G;AAED,6DAA6D;AAC7D,wBAAgB,oBAAoB,CAAC,GAAG,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,GAAG,SAAS,GAAG,GAAG,IAAI,kBAAkB,CAEzG"}
@@ -0,0 +1,27 @@
1
+ import { artifactResourceId } from './access.js';
2
+ // The shared "about-ness" link that binds a Content Artifact into ANY agentic-primitives surface —
3
+ // this is what makes the Library integrate with access, messaging, and discussion boards OUT OF THE BOX
4
+ // rather than as bolt-on connectors (spec 335 §7.1; the `fabric` ContextRefV1 pattern, ADR-0021 app kind).
5
+ //
6
+ // One primitive: emit an `artifact` ContextRef and every surface accepts it, all keyed on the SAME
7
+ // identity the entitlement layer gates on (`artifact:<canonicalId>`):
8
+ // - messaging — MessageEnvelopeV1.contextRefs → "message an agent ABOUT this document"
9
+ // - discussion — ConversationDescriptorV1 / DiscussionTopicV1.contextRefs → "discuss this document"
10
+ // - inbox rules — InboxRuleV1.contextRefAnyOf → "route everything about this document"
11
+ // - notifications — HomeControlEventV1.refs → "notify grantees on grant/revoke"
12
+ // - coordination — alongside the `endeavor` kind → "assign/track work on this document"
13
+ /** The ContextRef `kind` for a Content Artifact (an app-defined kind per ADR-0021). */
14
+ export const ARTIFACT_CONTEXT_KIND = 'artifact';
15
+ /**
16
+ * Build the artifact ContextRef. `id` is `artifactResourceId(canonicalId)`, so "discuss it", "share it
17
+ * to a channel", "notify grantees", and "who can access it" all resolve to one identity — the seam that
18
+ * lets the Library reuse messaging / discussion / entitlements natively.
19
+ */
20
+ export function artifactContextRef(canonicalId, opts) {
21
+ return { kind: ARTIFACT_CONTEXT_KIND, id: artifactResourceId(canonicalId), label: opts?.label, hash: opts?.hash };
22
+ }
23
+ /** True if a ContextRef-like value points at an artifact. */
24
+ export function isArtifactContextRef(ref) {
25
+ return !!ref && ref.kind === ARTIFACT_CONTEXT_KIND;
26
+ }
27
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,mGAAmG;AACnG,wGAAwG;AACxG,2GAA2G;AAC3G,EAAE;AACF,mGAAmG;AACnG,sEAAsE;AACtE,8FAA8F;AAC9F,yGAAyG;AACzG,2FAA2F;AAC3F,kFAAkF;AAClF,2FAA2F;AAE3F,uFAAuF;AACvF,MAAM,CAAC,MAAM,qBAAqB,GAAG,UAAmB,CAAC;AAczD;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,WAAgB,EAAE,IAAqC;IACxF,OAAO,EAAE,IAAI,EAAE,qBAAqB,EAAE,EAAE,EAAE,kBAAkB,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AACpH,CAAC;AAED,6DAA6D;AAC7D,MAAM,UAAU,oBAAoB,CAAC,GAAyC;IAC5E,OAAO,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,KAAK,qBAAqB,CAAC;AACrD,CAAC"}