@loomwork/plugin-content 0.0.0-stage → 0.1.1

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 (69) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +8 -0
  3. package/README.md +92 -2
  4. package/dist/CachingContentStore.d.ts +54 -0
  5. package/dist/CachingContentStore.d.ts.map +1 -0
  6. package/dist/CachingContentStore.js +171 -0
  7. package/dist/CachingContentStore.js.map +1 -0
  8. package/dist/ContentResolvingEventStore.d.ts +70 -0
  9. package/dist/ContentResolvingEventStore.d.ts.map +1 -0
  10. package/dist/ContentResolvingEventStore.js +245 -0
  11. package/dist/ContentResolvingEventStore.js.map +1 -0
  12. package/dist/ContentStore.d.ts +186 -0
  13. package/dist/ContentStore.d.ts.map +1 -0
  14. package/dist/ContentStore.js +177 -0
  15. package/dist/ContentStore.js.map +1 -0
  16. package/dist/ContentTouchingSnapshotStore.d.ts +56 -0
  17. package/dist/ContentTouchingSnapshotStore.d.ts.map +1 -0
  18. package/dist/ContentTouchingSnapshotStore.js +85 -0
  19. package/dist/ContentTouchingSnapshotStore.js.map +1 -0
  20. package/dist/citations.d.ts +40 -0
  21. package/dist/citations.d.ts.map +1 -0
  22. package/dist/citations.js +118 -0
  23. package/dist/citations.js.map +1 -0
  24. package/dist/content.bench.d.ts +2 -0
  25. package/dist/content.bench.d.ts.map +1 -0
  26. package/dist/content.bench.js +75 -0
  27. package/dist/content.bench.js.map +1 -0
  28. package/dist/content.d.ts +40 -0
  29. package/dist/content.d.ts.map +1 -0
  30. package/dist/content.js +177 -0
  31. package/dist/content.js.map +1 -0
  32. package/dist/derive.d.ts +9 -0
  33. package/dist/derive.d.ts.map +1 -0
  34. package/dist/derive.js +40 -0
  35. package/dist/derive.js.map +1 -0
  36. package/dist/errors.d.ts +6 -0
  37. package/dist/errors.d.ts.map +1 -0
  38. package/dist/errors.js +20 -0
  39. package/dist/errors.js.map +1 -0
  40. package/dist/executionEnd.d.ts +22 -0
  41. package/dist/executionEnd.d.ts.map +1 -0
  42. package/dist/executionEnd.js +66 -0
  43. package/dist/executionEnd.js.map +1 -0
  44. package/dist/gc.d.ts +470 -0
  45. package/dist/gc.d.ts.map +1 -0
  46. package/dist/gc.js +819 -0
  47. package/dist/gc.js.map +1 -0
  48. package/dist/index.d.ts +10 -0
  49. package/dist/index.d.ts.map +1 -0
  50. package/dist/index.js +42 -0
  51. package/dist/index.js.map +1 -0
  52. package/dist/touchAround.d.ts +46 -0
  53. package/dist/touchAround.d.ts.map +1 -0
  54. package/dist/touchAround.js +98 -0
  55. package/dist/touchAround.js.map +1 -0
  56. package/package.json +58 -3
  57. package/src/CachingContentStore.ts +184 -0
  58. package/src/ContentResolvingEventStore.ts +325 -0
  59. package/src/ContentStore.ts +317 -0
  60. package/src/ContentTouchingSnapshotStore.ts +109 -0
  61. package/src/citations.ts +117 -0
  62. package/src/content.bench.ts +84 -0
  63. package/src/content.ts +191 -0
  64. package/src/derive.ts +40 -0
  65. package/src/errors.ts +19 -0
  66. package/src/executionEnd.ts +64 -0
  67. package/src/gc.ts +1213 -0
  68. package/src/index.ts +54 -0
  69. package/src/touchAround.ts +131 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
package/NOTICE ADDED
@@ -0,0 +1,8 @@
1
+ Loom
2
+ Copyright 2026 Sushil Chhetri
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this project except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
package/README.md CHANGED
@@ -1,3 +1,93 @@
1
- # Temporary Holding Version
1
+ # @loomwork/plugin-content
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The content-addressed blob seam. A large value leaves the log by reference: the log keeps a thin, ordered
4
+ authority and the bytes live in a `ContentStore`, addressed by the hash of the bytes (`sha256:<hex>`).
5
+ Use it when payloads are too big or too sensitive to keep inline, when forks should share blobs, or when
6
+ you need to reclaim stored bytes safely. The durable store here is `SqliteContentStore` (`@loomwork/plugin-sqlite`);
7
+ `@loomwork/plugin-crypto` has an `EncryptingContentStore`, and you can implement the SPI for another backend.
8
+
9
+ ```ts
10
+ import { defineConfig } from "@loomwork/app";
11
+ import { InMemoryAsyncEventStore } from "@loomwork/event-runtime";
12
+ import {
13
+ ContentResolvingEventStore,
14
+ InMemoryContentStore,
15
+ sweepUnpinnedContent,
16
+ } from "@loomwork/plugin-content";
17
+
18
+ const content = new InMemoryContentStore();
19
+ const inner = new InMemoryAsyncEventStore();
20
+
21
+ // Move one payload field per event kind out of the log; reads resolve it back.
22
+ const events = new ContentResolvingEventStore(inner, content, {
23
+ externalize: { STEP_COMPLETED: ["output.document"] },
24
+ });
25
+ export const app = defineConfig({ storage: { kind: "custom", eventStore: events } });
26
+
27
+ // Mark-and-sweep reclamation. The API erases unless `dryRun: true`, so look first.
28
+ export async function sweep(now: number) {
29
+ return sweepUnpinnedContent({
30
+ eventStores: [inner], // every live store and every archive; scan the raw store
31
+ contentStore: content,
32
+ pinnedEventTypes: ["FINDING_RECORDED"],
33
+ olderThanMs: 30 * 24 * 3600_000,
34
+ now, // LOG time, compared against event timestamps
35
+ dryRun: true,
36
+ });
37
+ }
38
+ ```
39
+
40
+ ## Surface
41
+
42
+ - **Store seam.** `ContentStore` (`put`, `get`, `delete`, with optional `getMany`, `touch`, `listPage`,
43
+ `deleteIfUntouchedSince`, `touchClock`), `InMemoryContentStore`, `CachingContentStore`.
44
+ - **Log integration.** `ContentResolvingEventStore` (externalize on write, resolve on read),
45
+ `ContentTouchingSnapshotStore`, `externalizePathsFromSteps` (derives paths from steps that mark an
46
+ output `externalized()`), `ContentRef`, `collectContentRefs`.
47
+ - **Reclamation.** `sweepUnpinnedContent`, `pinByEventKinds`, and the errors it refuses with
48
+ (`ReclaimOrphansAckError`, `ArchiveStoresRequiredError`, `SealedArchiveScanError`, and others).
49
+
50
+ ## Behaviour that surprises people
51
+
52
+ - **Which refs can be reclaimed.** A bare ref in a payload is load-bearing: the resolving store throws
53
+ `ContentMissingError` when its blob is gone, so a sweep keeps it while any scanned event cites it. The
54
+ same goes for a ref cited by a `pinnedEventTypes` event, a `roots` address, an archive segment or a
55
+ snapshot. Only an ADR 0054 claim-check envelope's `ref` is TTL-reclaimable, and not even that when the
56
+ envelope has `retain: true` at the top-level `output` of a `STEP_COMPLETED` (ADR 0140). A nested
57
+ `retain: true` lookalike does not count.
58
+ - **Reclaimable refs age from the end of the run.** A cited ref's age runs from the citing execution's
59
+ end if that is later than the citation (ADR 0146), so a blob cannot be erased while the log citing it
60
+ is retained under the same policy. A running or re-opened execution keeps the citation clock. The
61
+ change only ever deletes less; a dry run lists what it kept in `heldByEndClock`.
62
+ - **Two clocks.** `now` is LOG time, compared with event timestamps. The race guard uses the store's
63
+ own touch clock (`touchedBefore`, default `touchClock() - olderThanMs`). Without
64
+ `deleteIfUntouchedSince` the sweep falls back to a plain delete and reports `raceSafe: false`.
65
+ - **The API erases by default.** Only `dryRun: true` is a dry run (the `loom sweep content` CLI defaults
66
+ to one). Give exactly one of `olderThanMs` or `policy`.
67
+ - **Erasing orphans is gated.** `reclaimOrphans` needs `{ completeScan: true }` (a bare `true` throws),
68
+ a store with `touch`, `listPage` and `deleteIfUntouchedSince`, and a margin of at least 60 s. It also
69
+ needs `snapshotsTouchContent: true` when you pass `snapshotStores`. Passing it asserts that
70
+ `eventStores`, `snapshotStores` and `roots` cover every place that cites content; the sweep cannot
71
+ detect a store you left out.
72
+ - **Compaction needs archives.** An erasing pass refuses a compacted log its `archiveStores` do not
73
+ cover (`ArchiveStoresRequiredError`) unless `acknowledgeUnarchivedLogs: true`.
74
+ - **Deleting a log does not delete blobs.** `deleteExecution` and `truncatePrefix` leave them, because
75
+ forks share content. Reclamation is the sweep, or `contentStore.delete(ref)`.
76
+ - **A sealing store cannot back `ContentResolvingEventStore`.** The constructor throws `TypeError` for
77
+ `sealsContent: true`, since that path does not carry the owning execution. Compose it inside an
78
+ audit chain, not outside, or the chain hashes only the ref.
79
+
80
+ ## See also
81
+
82
+ - API reference: section "`@loomwork/plugin-content` — the content-addressed blob seam" in
83
+ [docs/api-reference.org](../../docs/api-reference.org).
84
+ - Guides: [operations](../../docs/operations.md), [plugins](../../docs/plugins.md).
85
+ - ADRs: [0046 content store seam](../../docs/adr/0046-content-store-seam-thin-authoritative-log.md),
86
+ [0055 pin seam and content GC](../../docs/adr/0055-k10-6-pin-seam-content-gc.md),
87
+ [0140 agent claim-check](../../docs/adr/0140-agent-claim-check-opt-in.md),
88
+ [0145 retention policy](../../docs/adr/0145-app-owned-retention-policy.md),
89
+ [0146 content age from execution end](../../docs/adr/0146-content-age-from-execution-end.md).
90
+
91
+ ## Install
92
+
93
+ Unpublished for now: inside this repo use `workspace:*`; from a sibling checkout use a `link:` override (see [AGENTS.md](../../AGENTS.md)).
@@ -0,0 +1,54 @@
1
+ import type { ContentAccess, ContentStore } from "./ContentStore";
2
+ import { type ContentRef } from "./content";
3
+ export interface CachingContentStoreOptions {
4
+ /**
5
+ * Total cache budget in BYTES (not entries — blob sizes vary by orders of
6
+ * magnitude). A single blob larger than the budget is never admitted.
7
+ */
8
+ maxBytes: number;
9
+ }
10
+ /**
11
+ * ADR 0062 — a caching decorator for any {@link ContentStore}. Content
12
+ * addressing makes this trivially correct: a blob's address is a pure function
13
+ * of its bytes, so cached entries are immutable and valid forever — with
14
+ * exactly one edge: **`delete` evicts BEFORE forwarding**, so an erased /
15
+ * crypto-shredded blob (K10, T3) is never resurrected from a warm cache.
16
+ *
17
+ * Byte-budgeted LRU on Map insertion order (touch = delete+set, evict = first
18
+ * key) — O(1) per operation. `getMany` serves hits from cache and fetches only
19
+ * the misses (one inner `getMany` when supported). A decorator is still a
20
+ * conformant store and runs the full conformance kit.
21
+ */
22
+ export declare class CachingContentStore implements ContentStore {
23
+ private readonly inner;
24
+ private readonly options;
25
+ private readonly cache;
26
+ private cachedBytes;
27
+ readonly putStream?: NonNullable<ContentStore["putStream"]>;
28
+ readonly getMany: NonNullable<ContentStore["getMany"]>;
29
+ readonly deleteIfUntouchedSince?: NonNullable<ContentStore["deleteIfUntouchedSince"]>;
30
+ readonly listPage?: NonNullable<ContentStore["listPage"]>;
31
+ readonly touchClock?: NonNullable<ContentStore["touchClock"]>;
32
+ readonly touch?: NonNullable<ContentStore["touch"]>;
33
+ constructor(inner: ContentStore, options: CachingContentStoreOptions);
34
+ put(bytes: Uint8Array, access?: ContentAccess): Promise<ContentRef>;
35
+ get(ref: ContentRef, access?: ContentAccess): Promise<Uint8Array | null>;
36
+ delete(ref: ContentRef): Promise<void>;
37
+ private evict;
38
+ /** Cache hit with LRU touch (delete+set moves the key to the Map's tail). */
39
+ private lruTouch;
40
+ /**
41
+ * Audit SEC-2 — FETCHED bytes are verified against their content address
42
+ * before they are served OR cached: a buggy/compromised inner store returning
43
+ * wrong bytes for an address must neither poison the cache nor reach the
44
+ * caller (the sandbox pins scripts by hash through this store — a mispairing
45
+ * would defeat that provenance). Throws loudly on mismatch. Applies only to
46
+ * sha256-addressed refs (the ADR 0046 scheme) and only to the fetch path —
47
+ * `put` bytes came from the caller and the inner store derived the address.
48
+ */
49
+ private verifyFetched;
50
+ private admit;
51
+ /** Observability for tests: current cached byte total. */
52
+ get cacheBytes(): number;
53
+ }
54
+ //# sourceMappingURL=CachingContentStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CachingContentStore.d.ts","sourceRoot":"","sources":["../src/CachingContentStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,KAAK,UAAU,EAAkB,MAAM,WAAW,CAAC;AAE5D,MAAM,WAAW,0BAA0B;IACzC;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;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
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CachingContentStore = void 0;
4
+ const content_1 = require("./content");
5
+ /**
6
+ * ADR 0062 — a caching decorator for any {@link ContentStore}. Content
7
+ * addressing makes this trivially correct: a blob's address is a pure function
8
+ * of its bytes, so cached entries are immutable and valid forever — with
9
+ * exactly one edge: **`delete` evicts BEFORE forwarding**, so an erased /
10
+ * crypto-shredded blob (K10, T3) is never resurrected from a warm cache.
11
+ *
12
+ * Byte-budgeted LRU on Map insertion order (touch = delete+set, evict = first
13
+ * key) — O(1) per operation. `getMany` serves hits from cache and fetches only
14
+ * the misses (one inner `getMany` when supported). A decorator is still a
15
+ * conformant store and runs the full conformance kit.
16
+ */
17
+ class CachingContentStore {
18
+ inner;
19
+ options;
20
+ cache = new Map();
21
+ cachedBytes = 0;
22
+ putStream;
23
+ getMany;
24
+ deleteIfUntouchedSince;
25
+ listPage;
26
+ touchClock;
27
+ touch;
28
+ constructor(inner, options) {
29
+ this.inner = inner;
30
+ this.options = options;
31
+ // ADR 0143: this cache holds PLAINTEXT keyed by address, so over a sealing store a warm hit would hand a
32
+ // blob to a caller who never proved the subject (and whose fetch-hash check could not pass anyway: the
33
+ // sealing store returns plaintext for a ciphertext address). Cache the CIPHERTEXT instead: wrap the plain
34
+ // store, then seal on top (`new EncryptingContentStore(new CachingContentStore(plain, ..), ..)`).
35
+ if (inner.sealsContent === true) {
36
+ throw new TypeError("CachingContentStore: refusing to cache a store that seals content (sealsContent: true): a warm hit would serve plaintext without the subject check. Put the cache BELOW the sealing store.");
37
+ }
38
+ // Forwarded uncached: the stream's bytes are consumed by the inner upload.
39
+ if (inner.putStream !== undefined) {
40
+ this.putStream = (stream, access) => inner.putStream(stream, access);
41
+ }
42
+ // SPI 1.3.0 (ADR 0055 D5/D6): forwarded iff the inner store has them — a decorator that
43
+ // dropped them would silently make the sweep racy and `reclaimOrphans` refuse. Touch
44
+ // times are the inner store's; `put` already forwards, so a re-citation still bumps.
45
+ if (inner.deleteIfUntouchedSince !== undefined) {
46
+ this.deleteIfUntouchedSince = async (ref, cutoffMs) => {
47
+ this.evict(ref.__loomContent); // before: erasure is never served from a warm cache
48
+ const deleted = await inner.deleteIfUntouchedSince(ref, cutoffMs);
49
+ // after: a concurrent miss may have re-admitted the bytes while the delete ran
50
+ if (deleted)
51
+ this.evict(ref.__loomContent);
52
+ return deleted;
53
+ };
54
+ }
55
+ if (inner.listPage !== undefined) {
56
+ this.listPage = (opts) => inner.listPage(opts);
57
+ }
58
+ if (inner.touchClock !== undefined) {
59
+ this.touchClock = () => inner.touchClock();
60
+ }
61
+ // SPI 1.4.0: the touch time is the inner store's; the byte cache is untouched by it.
62
+ if (inner.touch !== undefined) {
63
+ this.touch = (addresses) => inner.touch(addresses);
64
+ }
65
+ this.getMany = async (refs, access) => {
66
+ const results = new Array(refs.length);
67
+ const missIndexes = [];
68
+ const missRefs = [];
69
+ refs.forEach((ref, i) => {
70
+ const hit = this.lruTouch(ref.__loomContent);
71
+ if (hit !== undefined) {
72
+ results[i] = hit;
73
+ }
74
+ else {
75
+ missIndexes.push(i);
76
+ missRefs.push(ref);
77
+ }
78
+ });
79
+ if (missRefs.length > 0) {
80
+ const fetched = inner.getMany !== undefined
81
+ ? await inner.getMany(missRefs, access)
82
+ : await Promise.all(missRefs.map((r) => inner.get(r, access)));
83
+ fetched.forEach((bytes, j) => {
84
+ const at = missIndexes[j];
85
+ if (bytes != null) {
86
+ this.verifyFetched(missRefs[j].__loomContent, bytes);
87
+ this.admit(missRefs[j].__loomContent, bytes);
88
+ }
89
+ results[at] = bytes ?? null;
90
+ });
91
+ }
92
+ return results;
93
+ };
94
+ }
95
+ async put(bytes, access) {
96
+ const ref = await this.inner.put(bytes, access);
97
+ this.admit(ref.__loomContent, bytes);
98
+ return ref;
99
+ }
100
+ async get(ref, access) {
101
+ const hit = this.lruTouch(ref.__loomContent);
102
+ if (hit !== undefined)
103
+ return hit;
104
+ const bytes = await this.inner.get(ref, access);
105
+ if (bytes !== null) {
106
+ this.verifyFetched(ref.__loomContent, bytes);
107
+ this.admit(ref.__loomContent, bytes);
108
+ }
109
+ return bytes;
110
+ }
111
+ async delete(ref) {
112
+ // Evict FIRST — erasure must never be resurrected from cache.
113
+ this.evict(ref.__loomContent);
114
+ return this.inner.delete(ref);
115
+ }
116
+ evict(address) {
117
+ const cached = this.cache.get(address);
118
+ if (cached !== undefined) {
119
+ this.cache.delete(address);
120
+ this.cachedBytes -= cached.byteLength;
121
+ }
122
+ }
123
+ /** Cache hit with LRU touch (delete+set moves the key to the Map's tail). */
124
+ lruTouch(address) {
125
+ const hit = this.cache.get(address);
126
+ if (hit !== undefined) {
127
+ this.cache.delete(address);
128
+ this.cache.set(address, hit);
129
+ }
130
+ return hit;
131
+ }
132
+ /**
133
+ * Audit SEC-2 — FETCHED bytes are verified against their content address
134
+ * before they are served OR cached: a buggy/compromised inner store returning
135
+ * wrong bytes for an address must neither poison the cache nor reach the
136
+ * caller (the sandbox pins scripts by hash through this store — a mispairing
137
+ * would defeat that provenance). Throws loudly on mismatch. Applies only to
138
+ * sha256-addressed refs (the ADR 0046 scheme) and only to the fetch path —
139
+ * `put` bytes came from the caller and the inner store derived the address.
140
+ */
141
+ verifyFetched(address, bytes) {
142
+ if (address.startsWith("sha256:") && (0, content_1.contentAddress)(bytes) !== address) {
143
+ throw new Error(`CachingContentStore: inner store returned bytes whose hash does not match "${address}" — refusing to cache or serve (possible corruption or poisoning)`);
144
+ }
145
+ }
146
+ admit(address, bytes) {
147
+ if (bytes.byteLength > this.options.maxBytes)
148
+ return; // never admit an over-budget blob
149
+ const existing = this.cache.get(address);
150
+ if (existing !== undefined) {
151
+ this.cache.delete(address);
152
+ this.cachedBytes -= existing.byteLength;
153
+ }
154
+ this.cache.set(address, bytes);
155
+ this.cachedBytes += bytes.byteLength;
156
+ while (this.cachedBytes > this.options.maxBytes) {
157
+ const oldest = this.cache.keys().next();
158
+ if (oldest.done === true)
159
+ break;
160
+ const evicted = this.cache.get(oldest.value);
161
+ this.cache.delete(oldest.value);
162
+ this.cachedBytes -= evicted.byteLength;
163
+ }
164
+ }
165
+ /** Observability for tests: current cached byte total. */
166
+ get cacheBytes() {
167
+ return this.cachedBytes;
168
+ }
169
+ }
170
+ exports.CachingContentStore = CachingContentStore;
171
+ //# sourceMappingURL=CachingContentStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CachingContentStore.js","sourceRoot":"","sources":["../src/CachingContentStore.ts"],"names":[],"mappings":";;;AACA,uCAA4D;AAU5D;;;;;;;;;;;GAWG;AACH,MAAa,mBAAmB;IAWX;IACA;IAXF,KAAK,GAAG,IAAI,GAAG,EAAsB,CAAC;IAC/C,WAAW,GAAG,CAAC,CAAC;IACf,SAAS,CAA0C;IACnD,OAAO,CAAuC;IAC9C,sBAAsB,CAAuD;IAC7E,QAAQ,CAAyC;IACjD,UAAU,CAA2C;IACrD,KAAK,CAAsC;IAEpD,YACmB,KAAmB,EACnB,OAAmC;QADnC,UAAK,GAAL,KAAK,CAAc;QACnB,YAAO,GAAP,OAAO,CAA4B;QAEpD,yGAAyG;QACzG,uGAAuG;QACvG,0GAA0G;QAC1G,kGAAkG;QAClG,IAAI,KAAK,CAAC,YAAY,KAAK,IAAI,EAAE,CAAC;YAChC,MAAM,IAAI,SAAS,CACjB,4LAA4L,CAC7L,CAAC;QACJ,CAAC;QACD,2EAA2E;QAC3E,IAAI,KAAK,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;YAClC,IAAI,CAAC,SAAS,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,KAAK,CAAC,SAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACxE,CAAC;QACD,wFAAwF;QACxF,qFAAqF;QACrF,qFAAqF;QACrF,IAAI,KAAK,CAAC,sBAAsB,KAAK,SAAS,EAAE,CAAC;YAC/C,IAAI,CAAC,sBAAsB,GAAG,KAAK,EAAE,GAAG,EAAE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CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAe,CAAC;YAC3D,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAChC,IAAI,CAAC,WAAW,IAAI,OAAO,CAAC,UAAU,CAAC;QACzC,CAAC;IACH,CAAC;IAED,0DAA0D;IAC1D,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;CACF;AAhKD,kDAgKC"}
@@ -0,0 +1,70 @@
1
+ import type { EventEnvelope } from "@loomwork/core";
2
+ import { type EventStore } from "@loomwork/event-runtime";
3
+ import type { ContentStore } from "./ContentStore";
4
+ import { type TouchErrorHook } from "./touchAround";
5
+ export interface ContentResolvingEventStoreOptions {
6
+ /**
7
+ * Payload dot-paths to externalize per event type, e.g. `{ STEP_COMPLETED: ["output.doc"] }`.
8
+ * On append those fields are moved to the content store and replaced by a {@link ContentRef};
9
+ * on read they are resolved back. Unmarked events are stored verbatim (zero overhead, G2).
10
+ */
11
+ externalize: Record<string, readonly string[]>;
12
+ /**
13
+ * Observer for the SPI 1.4.0 `touch` this store makes around ref-carrying writes (ADR 0055 D6
14
+ * amendment 2): called when the touch AFTER a durable write threw (swallowed otherwise, since the
15
+ * write already landed), and when either touch reports a cited bare ref MISSING (the write cites
16
+ * a blob that is already gone). A failure of the touch BEFORE the write still rejects the write.
17
+ * Wire it to your logger or metrics. See {@link TouchErrorHook}.
18
+ */
19
+ onTouchError?: TouchErrorHook;
20
+ }
21
+ export declare class ContentResolvingEventStore implements EventStore {
22
+ private readonly inner;
23
+ private readonly content;
24
+ private readonly externalize;
25
+ private readonly onTouchError;
26
+ readonly appendBatch?: NonNullable<EventStore["appendBatch"]>;
27
+ readonly head?: NonNullable<EventStore["head"]>;
28
+ readonly readRange?: NonNullable<EventStore["readRange"]>;
29
+ readonly acquireFence?: NonNullable<EventStore["acquireFence"]>;
30
+ readonly acquireFenceIf?: NonNullable<EventStore["acquireFenceIf"]>;
31
+ readonly appendIfUnchanged?: NonNullable<EventStore["appendIfUnchanged"]>;
32
+ readonly storeNow?: NonNullable<EventStore["storeNow"]>;
33
+ readonly sealingCapability?: NonNullable<EventStore["sealingCapability"]>;
34
+ readonly readAtRest?: NonNullable<EventStore["readAtRest"]>;
35
+ readonly copyPrefix?: NonNullable<EventStore["copyPrefix"]>;
36
+ readonly deleteExecution?: NonNullable<EventStore["deleteExecution"]>;
37
+ readonly deleteThrough?: NonNullable<EventStore["deleteThrough"]>;
38
+ readonly truncatePrefix?: NonNullable<EventStore["truncatePrefix"]>;
39
+ readonly truncatePrefixKeeping?: NonNullable<EventStore["truncatePrefixKeeping"]>;
40
+ readonly listExecutions?: NonNullable<EventStore["listExecutions"]>;
41
+ readonly listExecutionsPage?: NonNullable<EventStore["listExecutionsPage"]>;
42
+ constructor(inner: EventStore, content: ContentStore, options: ContentResolvingEventStoreOptions);
43
+ private externalizeEnvelope;
44
+ append(envelope: EventEnvelope): Promise<void>;
45
+ /**
46
+ * SPI 1.4.0 (ADR 0055 D6 amendment 2) — a ref that reaches a log WITHOUT a `put` (one an
47
+ * incoming payload already carries: a recalled memory value, a `scriptRef`, a ref handed
48
+ * between steps) is a citation the orphan sweep's conditional delete cannot see. So, when the
49
+ * content store can `touch`, the payloads' cited addresses are touched BEFORE the write (a
50
+ * failure aborts it, nothing landed) and again AFTER it (best-effort and reported through
51
+ * `onTouchError`: the write is durable, so its outcome must not be turned into a failure).
52
+ * The guarantee is D5's: the BEFORE touch protects a write whose touch-to-commit window is
53
+ * shorter than the sweep's margin (`touchClock() - cutoff`, which an erasing orphan pass
54
+ * requires to be at least 60 s); the AFTER touch only extends that for a slower write. See
55
+ * {@link touchAround}. Refs externalized by THIS write are not in the INPUT payloads (their
56
+ * `put` is the touch). Cost: with no `touch` on the store, nothing (the closure is the
57
+ * write); otherwise one iterative cycle-safe walk of the input payload (no recursion; the same
58
+ * walker the sweep's mark phase uses), and a round trip only when a ref was found.
59
+ */
60
+ private touching;
61
+ private externalizeValue;
62
+ read(executionId: string): Promise<EventEnvelope[]>;
63
+ readFrom(executionId: string, fromSequence: number): Promise<EventEnvelope[]>;
64
+ private resolveAll;
65
+ /** Fetch all distinct refs; loudness contract unchanged (missing ⇒ ContentMissingError, G1). */
66
+ private fetchBytes;
67
+ subscribe(executionId: string, handler: (event: EventEnvelope) => void): Promise<() => void>;
68
+ close(): Promise<void>;
69
+ }
70
+ //# sourceMappingURL=ContentResolvingEventStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContentResolvingEventStore.d.ts","sourceRoot":"","sources":["../src/ContentResolvingEventStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAEL,KAAK,UAAU,EAIhB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAUnD,OAAO,EAAE,KAAK,cAAc,EAAe,MAAM,eAAe,CAAC;AAEjE,MAAM,WAAW,iCAAiC;IAChD;;;;OAIG;IACH,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC;IAC/C;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,cAAc,CAAC;CAC/B;AAyCD,qBAAa,0BAA2B,YAAW,UAAU;IAqBzD,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO;IArB1B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoC;IAChE,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA6B;IAC1D,QAAQ,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC;IAC9D,QAAQ,CAAC,IAAI,CAAC,EAAE,WAAW,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;IAChD,QAAQ,CAAC,SAAS,CAAC,EA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