pactium 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +92 -0
  3. package/README.zh-CN.md +90 -0
  4. package/SECURITY.md +7 -0
  5. package/bin/pactium.mjs +121 -0
  6. package/docs/LICOLITE-ASPECT.md +57 -0
  7. package/docs/README.md +13 -0
  8. package/docs/TERM.md +289 -0
  9. package/docs/architecture/ARCHITECTURE.md +62 -0
  10. package/docs/protocols/PROFILE.md +124 -0
  11. package/docs/protocols/PROTOCOLS.md +62 -0
  12. package/examples/record-operation.mjs +26 -0
  13. package/package.json +69 -0
  14. package/src/README.md +13 -0
  15. package/src/aspects/licolite/aspect.js +278 -0
  16. package/src/aspects/licolite/constants.js +13 -0
  17. package/src/aspects/licolite/evidence.js +47 -0
  18. package/src/aspects/licolite/index.d.ts +51 -0
  19. package/src/aspects/licolite/index.js +19 -0
  20. package/src/aspects/licolite/signing.js +78 -0
  21. package/src/canonical/value.js +40 -0
  22. package/src/core/append-condition.js +102 -0
  23. package/src/core/pactium-core.js +1073 -0
  24. package/src/core/tracking-cursor.js +68 -0
  25. package/src/http.js +99 -0
  26. package/src/index-engine/snapshot-merkle-index.js +994 -0
  27. package/src/index.d.ts +244 -0
  28. package/src/index.js +73 -0
  29. package/src/ledger/signed-head.js +204 -0
  30. package/src/ledger/transparency-log.js +702 -0
  31. package/src/maintenance/task-engine.js +36 -0
  32. package/src/proof/bundle-format.js +265 -0
  33. package/src/proof/bundle.js +77 -0
  34. package/src/proof/envelope.js +548 -0
  35. package/src/proof/registry.js +18 -0
  36. package/src/protocol/constants.js +69 -0
  37. package/src/protocol/hashing.js +47 -0
  38. package/src/quality/profile-runner.js +291 -0
  39. package/src/repair/planner.js +62 -0
  40. package/src/shared/records.js +32 -0
  41. package/src/storage/local-json-storage-port.js +360 -0
  42. package/src/verification/failure.js +31 -0
package/docs/TERM.md ADDED
@@ -0,0 +1,289 @@
1
+ # Pactium Terms
2
+
3
+ This glossary is a maintained release document and package documentation authority.
4
+
5
+ ## Language
6
+
7
+ **Operation Ledger**:
8
+ A cryptographically verifiable fact ledger for operation records. It is the source used to prove that an operation was recorded and that later ledger states remain valid continuations of earlier states.
9
+ _Avoid_: SQLite-backed operation record store, operation table, audit log
10
+
11
+ **Ledger Authority**:
12
+ The Operation Ledger's role as the global ordering authority for Pactium protocol facts. Checkpoint Tree and Merkle State facts can be independently verified, but their cross-structure ordering is interpreted through the Operation Ledger.
13
+ _Avoid_: checkpoint authority, state authority, multiple timelines
14
+
15
+ **Workspace Projection**:
16
+ A verifiable workspace-scoped projection index derived from the global Operation Ledger and related Pactium facts. The current package projects Operation Intents and Operation Outcomes without replacing Ledger Authority. Repair Facts are reserved for a future repair executor.
17
+ _Avoid_: workspace ledger, separate authority, filtered database view
18
+
19
+ **Workspace Order Index**:
20
+ The Workspace Projection index that maps workspace-local order to ledger event references. It supports verifiable workspace-scoped ordering and pagination.
21
+ _Avoid_: global ledger order view, UI sort, timestamp order
22
+
23
+ **Workspace Membership Index**:
24
+ The Workspace Projection index that maps ledger event identifiers to workspace-local membership material. It supports verifiable answers to whether a global ledger event belongs to a workspace projection.
25
+ _Avoid_: filtered lookup, secondary database index, unverified membership check
26
+
27
+ **Workspace Projection Lane**:
28
+ The logical per-workspace sequence represented by Workspace Projection ordinal assignment. The current package updates this projection synchronously during operation commits; it does not expose a separate per-workspace queue.
29
+ _Avoid_: asynchronous projection, global workspace lock, UI pagination counter
30
+
31
+ **Workspace Lane Queue**:
32
+ Reserved name for a possible future write-path FIFO queue that would serialize protocol commits for one Workspace Projection Lane while allowing different workspaces to proceed independently. It is not a current runtime surface.
33
+ _Avoid_: daemon queue, host retry loop, global write lock
34
+
35
+ **Ledger Transparency Log**:
36
+ The append-only Merkle log algorithm used by the Operation Ledger to prove entry inclusion and ledger consistency across Ledger Heads. It is separate from the Verifiable Index Engine because it owns ordered append history rather than ordered key/value state.
37
+ _Avoid_: Prolly ledger, index-backed ledger, key-value ledger
38
+
39
+ **Ledger Append Lane**:
40
+ The single commit lane that assigns global Ledger leaf order. It may accept ordered batches, but Pactium does not sort concurrent appends after the fact.
41
+ _Avoid_: concurrent ledger append, post-hoc ordering, timestamp ordering
42
+
43
+ **Ledger Head**:
44
+ The verifiable summary of an Operation Ledger state at a specific size. It identifies the ledger root that receipts and continuity checks can verify against.
45
+ _Avoid_: database snapshot, latest row, checkpoint
46
+
47
+ **Last Trusted Head**:
48
+ A Ledger Head retained by a verifier as its local trust anchor for later consistency checks. It lets clients detect ledger histories that do not continue from what they previously verified.
49
+ _Avoid_: latest server head, cached response, checkpoint file
50
+
51
+ **Signed Ledger Head**:
52
+ A Ledger Head endorsed by a host-provided signing authority. Current core verifies unsigned Ledger Heads and consistency proofs; signed Ledger Heads are an extension point rather than a shipped LicoLite Aspect behavior.
53
+ _Avoid_: required key, Pactium identity, global trust root
54
+
55
+ **Signing Authority**:
56
+ A host-provided authority capable of signing Pactium Proof Envelopes. Ledger Head signing is reserved for a future extension point.
57
+ _Avoid_: built-in product key, mandatory secret, Pactium account
58
+
59
+ **Witness Extension Point**:
60
+ The Pactium boundary for exporting and verifying Ledger Heads with external observers. Pactium core supports the data needed for witnessing, but does not run a witness or gossip network.
61
+ _Avoid_: built-in gossip service, mandatory witness, network daemon
62
+
63
+ **Host Declaration Profile**:
64
+ A host-declared integration profile that activates optional adapters without changing Pactium's core protocol vocabulary. Profiles are declared by the host rather than inferred by Pactium.
65
+ _Avoid_: auto-detection, hidden product mode, core dependency
66
+
67
+ **LicoLite Support Mandate**:
68
+ Pactium's product relationship to LicoLite: Pactium exists to provide the protocol substrate and integration surface LicoLite needs. LicoLite is the primary host, and Pactium may include complete LicoLite adapters when LicoLite declares itself.
69
+ _Avoid_: neutral host-only library, third-party-first package, LicoLite external plugin
70
+
71
+ **LicoLite Aspect**:
72
+ The first-class Pactium package surface that adapts Pactium's protocol substrate to LicoLite. It covers LicoLite-facing protocol substrate integration while leaving LicoLite runtime, policy decisions, operation dispatching, side effects, and UI ownership outside Pactium.
73
+ _Avoid_: ordinary plugin, external adapter, unofficial integration layer
74
+
75
+ **LicoLite Verifier**:
76
+ The LicoLite Aspect verifier for Pactium Proof Envelopes that checks core Pactium proofs plus LicoLite signing, workspace projection, policy extension, and workspace effect extension requirements. It verifies bindings and required evidence, not product policy correctness.
77
+ _Avoid_: writer-only adapter, LicoLite-owned duplicate verifier, policy evaluator
78
+
79
+ **Verification Failure**:
80
+ A structured verifier result item that names the failed verification layer, code, severity, and evidence reference. Pactium verifiers do not collapse proof failures into a single boolean.
81
+ _Avoid_: boolean-only verification, generic invalid receipt, unclassified error
82
+
83
+ **Repair Planner**:
84
+ The Pactium surface that translates structured Verification Failures into deterministic repair tasks. It proposes repairs; hosts decide whether and when to execute them.
85
+ _Avoid_: automatic repair, host policy executor, silent mutation
86
+
87
+ **Repair Fact**:
88
+ A reserved Ledger-bound Pactium fact for recording the result of rebuilding or repairing derived protocol material. The current package plans repair tasks but does not execute them or append Repair Facts.
89
+ _Avoid_: silent rebuild, hidden maintenance mutation, unrecorded repair
90
+
91
+ **LicoLite Workspace Projection Priority**:
92
+ The LicoLite Aspect's first priority: workspace-scoped verifiable projections are enabled by default and are the standard path for LicoLite workspace proof and view needs.
93
+ _Avoid_: optional projection, UI filtering first, global-ledger-only workspace view
94
+
95
+ **LicoLite Signing Policy**:
96
+ The LicoLite Aspect's signing behavior for Pactium Proof Envelopes. Signing is enabled by default for LicoLite envelopes, while LicoLite policy decides whether missing signing material fails closed or falls back to opportunistic signing.
97
+ _Avoid_: unsigned-by-default LicoLite, Pactium-mandated production policy, hidden key fallback
98
+
99
+ **LicoLite Policy Extension**:
100
+ A critical Proof Extension that binds LicoLite policy decision and evidence material into a Pactium Proof Envelope. Pactium carries and verifies the binding but does not decide whether the policy decision was correct.
101
+ _Avoid_: Pactium policy engine, unbound policy field, optional LicoLite governance metadata
102
+
103
+ **LicoLite Workspace Effect Extension**:
104
+ A critical Proof Extension that binds LicoLite workspace side-effect or asset evidence into a Pactium Proof Envelope. Pactium carries and verifies the binding but does not execute or validate the side effect itself.
105
+ _Avoid_: Pactium side-effect executor, unbound asset evidence, optional workspace evidence
106
+
107
+ **LicoLite Evidence Policy**:
108
+ The LicoLite Aspect's behavior when required LicoLite critical extensions are missing. LicoLite production defaults to failing closed, while other profiles may choose opportunistic behavior.
109
+ _Avoid_: silent downgrade, plain receipt fallback, Pactium-owned product policy
110
+
111
+ **New Data Directory Boundary**:
112
+ The LicoLite Aspect accepts Pactium-format data directories created under the current schema. Historical LicoLite protocol data is not read or migrated by Pactium.
113
+ _Avoid_: in-place migration, historical data acceptance, automatic upgrade
114
+
115
+ **Latest Schema Boundary**:
116
+ Pactium accepts the latest verifiable protocol schema only. Earlier experimental Pactium data formats are rejected.
117
+ _Avoid_: migration promise, experimental schema support, historical format acceptance
118
+
119
+ **Verifiable Core Rewrite**:
120
+ The current implementation that builds Pactium around proof-first protocol modules.
121
+ _Avoid_: incremental storage patch, storage-first carryover, weak proof model
122
+
123
+ **Proof Model Build Order**:
124
+ The current implementation dependency order: canonical encoding and hashing, storage, ledger, index engine, lifecycle indexes, workspace projection, state, checkpoint, proof envelopes, LicoLite Aspect, and maintenance/repair.
125
+ _Avoid_: aspect-first implementation, proof-later implementation, weak interim model
126
+
127
+ **Protocol Profile**:
128
+ The versioned parameter matrix that fixes Pactium's proof algorithms, data structures, API shape, LicoLite aspect behavior, and verification expectations for one protocol release.
129
+ _Avoid_: configuration preset, implementation checklist, tuning guide
130
+
131
+ **Pactium Receipt**:
132
+ A protocol fact receipt proving that declared Pactium facts were recorded and can be verified against Pactium history. It does not prove that host-owned business side effects completed unless the host includes its own evidence.
133
+ _Avoid_: business effect proof, external side-effect proof, completion certificate
134
+
135
+ **Operation Intent**:
136
+ An append-only Pactium fact declaring the operation that a host intends to record. It is not mutated into completion state.
137
+ _Avoid_: mutable started row, pending update, draft ledger entry
138
+
139
+ **Operation Outcome**:
140
+ An append-only Pactium fact declaring the result of an Operation Intent. Successful and failed outcomes are both recorded as new Ledger facts.
141
+ _Avoid_: row update, completion patch, overwritten status
142
+
143
+ **Terminal Outcome**:
144
+ The single Operation Outcome that closes an Operation Intent. Later retries, repairs, or compensations create new Operation Intents and link back through causality references.
145
+ _Avoid_: multiple completions, mutable final status, reopened intent
146
+
147
+ **Causality Reference**:
148
+ A reference from a Pactium fact to earlier intents, outcomes, or repair facts that explains why the new fact exists without reopening the earlier lifecycle.
149
+ _Avoid_: status rewrite, lifecycle mutation, hidden retry chain
150
+
151
+ **Operation Causality Index**:
152
+ The Verifiable Index Engine-backed index for querying causality relationships between Pactium facts such as retries, repairs, and compensations.
153
+ _Avoid_: payload traversal, UI-only relationship, unverified graph edge
154
+
155
+ **Canceled Outcome**:
156
+ An Operation Outcome that closes an Operation Intent by declaring cancellation. Cancellation is recorded as an outcome fact rather than deleting or mutating the intent.
157
+ _Avoid_: deleted intent, hidden close, canceled row update
158
+
159
+ **Open Intent**:
160
+ An Operation Intent that has been recorded without a corresponding Operation Outcome. It is a recoverable protocol state, not a hidden inconsistency.
161
+ _Avoid_: lost operation, partial row, failed transaction
162
+
163
+ **Open Intent Index**:
164
+ The Verifiable Index Engine-backed index of Operation Intents that do not yet have corresponding Operation Outcomes. It supports verified lookup and recovery of open operation lifecycles.
165
+ _Avoid_: ledger scan, in-memory pending map, unverified recovery list
166
+
167
+ **Outcome Index**:
168
+ The Verifiable Index Engine-backed index that maps Operation Intents to their Operation Outcomes. It supports verified lookup of an operation lifecycle result.
169
+ _Avoid_: status column, completion map, mutable lifecycle row
170
+
171
+ **Intent Idempotency Index**:
172
+ The Verifiable Index Engine-backed index that maps an intent idempotency key and input identity to an Operation Intent. It makes operation retries recover the same intent.
173
+ _Avoid_: hidden unique constraint, best-effort retry key, mutable pending row
174
+
175
+ **Outcome Idempotency Index**:
176
+ The Verifiable Index Engine-backed index that maps an outcome idempotency key and outcome identity to an Operation Outcome. It makes outcome retries recover the same result fact.
177
+ _Avoid_: duplicate completion guard, database-only uniqueness, retry cache
178
+
179
+ **Idempotency Replay**:
180
+ A retry result that returns an existing Operation Intent or Operation Outcome proof without appending a new Ledger fact. It is marked as a replay so callers can distinguish it from a new commit.
181
+ _Avoid_: duplicate ledger fact, hidden retry success, new operation attempt
182
+
183
+ **Pactium Proof Envelope**:
184
+ The cross-proof receipt shape that binds an Operation Ledger proof to related Checkpoint Tree and Merkle State proofs for the same protocol fact. It prevents independently valid proofs from being mis-associated.
185
+ _Avoid_: loose proof set, scattered receipt IDs, proof bundle
186
+
187
+ **Proof Material Ref**:
188
+ A content-addressed reference from a Pactium Proof Envelope to stored proof material needed for verification. It lets write paths return complete proof structure without inlining every proof byte while keeping proof material tamper-evident.
189
+ _Avoid_: missing proof, inline-only proof, opaque receipt ref
190
+
191
+ **Proof Bundle**:
192
+ A portable CAR-like export that contains a Pactium Proof Envelope, a Pactium manifest, and the content-addressed proof material needed for verification without local Pactium storage.
193
+ _Avoid_: receipt, local proof ref set, storage snapshot
194
+
195
+ **Proof Extension**:
196
+ A hash-bound host extension attached to a Pactium Proof Envelope without changing the core proof schema. Critical extensions require verifier support; non-critical extensions may be ignored but remain tamper-evident.
197
+ _Avoid_: arbitrary receipt field, unbound metadata, core schema fork
198
+
199
+ **Proof-First API**:
200
+ The public Pactium API style where write operations return verifiable proof envelopes or heads, and read operations expose verification-oriented proofs rather than storage-shaped records.
201
+ _Avoid_: storage-first API, proof hash API, loose identifier API
202
+
203
+ **Root Export**:
204
+ The default Pactium package API surface. It exposes the latest proof-first API only, not experimental historical APIs.
205
+ _Avoid_: mixed-version export, historical root API, versioned barrel
206
+
207
+ **Operation Lifecycle API**:
208
+ The proof-first API surface for beginning Operation Intents, appending Operation Outcomes, and recovering Open Intents. Higher-level operation recording APIs are conveniences over this lifecycle.
209
+ _Avoid_: mutable record API, start-complete row API, record-only lifecycle
210
+
211
+ **Host Evidence**:
212
+ Host-owned proof or artifact reference that supports a domain claim outside Pactium's protocol facts. Pactium may carry Host Evidence references but does not define their truth.
213
+ _Avoid_: Pactium proof, receipt, ledger fact
214
+
215
+ **Durable Host Evidence**:
216
+ Host Evidence that survives crashes before an Operation Outcome is recorded. Pactium binds its reference and hash, while the host owns storage and recovery of the evidence itself.
217
+ _Avoid_: transient callback result, Pactium-owned evidence store, inline side-effect result
218
+
219
+ **Maintenance Task Engine**:
220
+ The deterministic Pactium task planning surface. The current package executes the `doctor` task when a Pactium instance is provided and returns planned-only results for other task names; it does not run a resident scheduler.
221
+ _Avoid_: daemon scheduler, background service, host job runner
222
+
223
+ **Storage Port**:
224
+ The persistence boundary for Pactium protocol material. Storage backends may change how bytes are stored and retrieved, but they do not change canonical encoding, hash roots, proofs, or verification semantics.
225
+ _Avoid_: proof plugin, schema authority, storage-defined hash
226
+
227
+ **Checkpoint Tree**:
228
+ A verifiable append-only recovery tree for operation, task, or workflow history. It proves checkpoint node membership and parent-child continuity without becoming the Operation Ledger's ordering authority.
229
+ _Avoid_: plain JSON tree, restore log, second ledger
230
+
231
+ **Checkpoint Tree Head**:
232
+ The verifiable summary of a Checkpoint Tree state. It identifies the checkpoint root that node membership and continuity checks can verify against.
233
+ _Avoid_: file timestamp, latest node, ledger head
234
+
235
+ **Intent Checkpoint**:
236
+ A checkpoint node associated with an Operation Intent. It represents operation lifecycle start or recoverable progress, not confirmed side effects.
237
+ _Avoid_: effect checkpoint, completed checkpoint, outcome node
238
+
239
+ **Outcome Checkpoint**:
240
+ A checkpoint node associated with an Operation Outcome. It represents declared operation result, effect evidence, or state transition material.
241
+ _Avoid_: start marker, pending node, intent checkpoint
242
+
243
+ **Merkle State Substrate**:
244
+ A verifiable state substrate whose state roots identify content-addressed state. It is responsible for state continuity, key membership, key non-membership, and efficient state diffs.
245
+ _Avoid_: content store only, hash wrapper, blob registry
246
+
247
+ **State Commit**:
248
+ A verifiable Merkle State fact bound to an Operation Outcome. It declares state transition material and is not attached to Operation Intent.
249
+ _Avoid_: intent state commit, planned state, mutable state row
250
+
251
+ **Prolly Tree State Index**:
252
+ The canonical ordered-key index for Merkle State. It provides stable state roots, structural sharing, key membership proofs, key non-membership proofs, and efficient diffs.
253
+ _Avoid_: sorted-array index, proof hash, temporary state index
254
+
255
+ **Canonical Prolly Tree**:
256
+ Pactium's own protocol-defined Prolly Tree format. Its encoding, chunking, hash domains, and proof format are part of Pactium's trust semantics.
257
+ _Avoid_: external Prolly package, implementation detail, adapter tree
258
+
259
+ **Verifiable Index Engine**:
260
+ The shared algorithmic core used by Pactium indexes that need ordered keys, stable roots, membership proofs, non-membership proofs, structural sharing, and efficient diffs. Domain indexes may use different protocol profiles, but they do not reimplement separate proof engines.
261
+ _Avoid_: duplicate index implementation, per-domain tree algorithm, ad hoc proof store
262
+
263
+ **Index Domain Adapter**:
264
+ A domain boundary that converts host or Pactium domain material into canonical index keys and values before it enters the Verifiable Index Engine. Merkle State, Checkpoint Node, and Workspace Projection indexes use domain adapters while sharing the same proof engine.
265
+ _Avoid_: separate index engine, storage plugin, proof adapter
266
+
267
+ **Index Key**:
268
+ A canonical ordered key consumed by the Verifiable Index Engine. State paths, checkpoint node identifiers, and future domain keys are normalized into Index Keys before indexing.
269
+ _Avoid_: raw path, raw node id, host key
270
+
271
+ **Index Value**:
272
+ A canonical value envelope consumed by the Verifiable Index Engine. Domain payloads are represented as stable value material before indexing so the proof engine can remain domain-independent.
273
+ _Avoid_: domain object, mutable payload, unencoded value
274
+
275
+ **Index Value Ref**:
276
+ An Index Value that binds an indexed key to content-addressed value material rather than embedding the full domain object in the index. It keeps the Verifiable Index Engine domain-independent while allowing payloads to be verified separately.
277
+ _Avoid_: inline domain object, raw payload, stored object
278
+
279
+ **Content-Defined Chunking**:
280
+ The protocol-defined boundary rule used by the Canonical Prolly Tree to form stable chunks from ordered key/value material. Its parameters are Pactium protocol constants, not host configuration.
281
+ _Avoid_: fixed fanout, configurable fanout, storage tuning
282
+
283
+ **Protocol Hash**:
284
+ The hash algorithm fixed by a Pactium protocol version. Hosts do not configure it; a hash algorithm change requires a new protocol version.
285
+ _Avoid_: host hash option, storage hash, configurable digest
286
+
287
+ **Pactium Canonical Value**:
288
+ The restricted IPLD/DAG-CBOR-style data model used for Pactium proof material. Ledger leaves, index nodes, checkpoint nodes, state commits, and proof envelopes are encoded through this model before hashing.
289
+ _Avoid_: ordinary JSON, runtime object, stringified payload
@@ -0,0 +1,62 @@
1
+ # Pactium Architecture
2
+
3
+ Pactium is a proof-first protocol substrate for LicoLite. LicoLite is the primary host, and `pactium/licolite` is a first-class package aspect rather than an external plugin.
4
+
5
+ ```text
6
+ LicoLite host
7
+ -> pactium/licolite
8
+ -> Proof-first Pactium core
9
+ -> Canonical Value encoding and Protocol Hash
10
+ -> Storage Port and content-addressed blocks
11
+ -> Operation Ledger Transparency Log
12
+ -> Shared Verifiable Index Engine
13
+ -> Operation Lifecycle indexes
14
+ -> Workspace Projection
15
+ -> Merkle State
16
+ -> Checkpoint Tree
17
+ -> Proof Envelopes and Proof Bundles
18
+ -> Maintenance Task Engine and Repair Planner
19
+ ```
20
+
21
+ ## Authority
22
+
23
+ The Operation Ledger is the global ordering authority. Workspace Projection, Merkle State, Checkpoint Tree, lifecycle, idempotency, and causality indexes are verifiable structures, but they do not replace Ledger Authority.
24
+
25
+ The shared Verifiable Index Engine is the canonical ordered-key proof engine. State, checkpoint, workspace projection, lifecycle, idempotency, and causality indexes use domain adapters over that shared engine rather than separate tree implementations.
26
+
27
+ ## LicoLite Boundary
28
+
29
+ Pactium owns protocol facts, proof algorithms, canonical encoding, storage ports, verification, repair planning, and LicoLite protocol-substrate adapters.
30
+
31
+ LicoLite owns runtime policy decisions, operation dispatching, side effects, UI ownership, authorization, and durable Host Evidence storage. Pactium binds LicoLite policy and workspace-effect evidence as critical proof extensions and verifies those bindings.
32
+
33
+ ## Current Implementation Status
34
+
35
+ The current `src/` implementation is the proof-first package surface. The package root exports proof-first APIs, and `pactium/licolite` exports the first-class LicoLite Aspect.
36
+
37
+ The implementation follows the package protocol and aspect documents:
38
+
39
+ - [Protocol Profile](../protocols/PROFILE.md)
40
+ - [Protocols](../protocols/PROTOCOLS.md)
41
+ - [LicoLite Aspect](../LICOLITE-ASPECT.md)
42
+
43
+ ## Implemented Surfaces
44
+
45
+ The maintained design is implemented by these package surfaces:
46
+
47
+ | Design area | Implementation anchor |
48
+ | --- | --- |
49
+ | Protocol constants and hashing | `src/protocol/constants.js`, `src/protocol/hashing.js` |
50
+ | Canonical Value | `src/canonical/value.js`: `canonicalEncode`, `canonicalDecode`, `normalizeCanonicalValue` |
51
+ | Storage Port | `src/storage/local-json-storage-port.js`: `createStoragePort` |
52
+ | Ledger Transparency Log | `src/ledger/transparency-log.js`: `createLedgerTransparencyLog`, inclusion and consistency proof helpers |
53
+ | Verifiable Index Engine | `src/index-engine/snapshot-merkle-index.js`: `createVerifiableIndexEngine` |
54
+ | Operation lifecycle | `src/core/pactium-core.js`: `beginOperationIntent`, `appendOperationOutcome`, `recordOperation` |
55
+ | Workspace Projection | `src/core/pactium-core.js`: `getWorkspaceProjection`, `proveWorkspaceMembership` |
56
+ | Proof Envelopes and Bundles | `src/proof/envelope.js`, `src/proof/bundle.js`, `src/core/pactium-core.js`: verification and export surfaces |
57
+ | LicoLite Aspect | `src/aspects/licolite/`: `createLicoLiteAspect`, `createLicoLiteSigner`, evidence helpers, verifier |
58
+ | CLI and HTTP facades | `bin/pactium.mjs`, `src/http.js` |
59
+
60
+ Maintained docs must not describe SQLite storage, separate per-workspace lane queues, repair fact execution, or pressure baseline regression enforcement as implemented unless those surfaces are added and verified.
61
+
62
+ If a maintained document introduces a design area that cannot be mapped to an implementation anchor, the design must be implemented and documented before release.
@@ -0,0 +1,124 @@
1
+ # Pactium Protocol Profile
2
+
3
+ The Protocol Profile is the implementation baseline for the proof-first rewrite. These values are protocol commitments, not host tuning options.
4
+
5
+ ## Global
6
+
7
+ | Area | Parameter | Value |
8
+ | --- | --- | --- |
9
+ | Protocol | `PACTIUM_PROTOCOL` | `pactium.v0.2` |
10
+ | Hash | `Protocol Hash` | `sha256` |
11
+ | Hash domains | `domainSeparator` | Fixed per object class |
12
+ | Encoding | `Canonical Value` | Restricted IPLD/DAG-CBOR-style model |
13
+ | CID | `cid` | `cid:sha256:<hex>` |
14
+ | Time | `timestamp` | RFC3339 metadata, never ordering authority |
15
+ | Ordering | `authority` | Operation Ledger leaf order |
16
+
17
+ ## Ledger
18
+
19
+ | Parameter | Value |
20
+ | --- | --- |
21
+ | Model | RFC6962/Trillian-style transparency log |
22
+ | `leafHash` | `H(0x00 || canonical(leaf))` |
23
+ | `nodeHash` | `H(0x01 || leftHash || rightHash)` |
24
+ | `emptyTreeHash` | `H("")` |
25
+ | Append order | Single Ledger Append Lane |
26
+ | Batch append | Allowed only when ordered |
27
+ | Proofs | Inclusion and consistency proofs |
28
+ | Signing | Optional in core, default for LicoLite Aspect |
29
+ | Split-view defense | Consistency proof support; hosts retain last trusted heads; witness is extension point |
30
+
31
+ ## Operation Lifecycle
32
+
33
+ | Parameter | Value |
34
+ | --- | --- |
35
+ | Facts | Operation Intent plus Operation Outcome |
36
+ | Open state | Open Intent is first-class and recoverable |
37
+ | Terminality | One Terminal Outcome per Intent |
38
+ | Cancellation | Canceled Outcome |
39
+ | Recovery links | Causality References plus Operation Causality Index |
40
+ | Idempotency | Intent Idempotency Index and Outcome Idempotency Index |
41
+ | Replay | Returns existing proof/ref with `replayed`, appends no Ledger fact |
42
+
43
+ ## Verifiable Index Engine
44
+
45
+ | Parameter | Value |
46
+ | --- | --- |
47
+ | Structure | Canonical Prolly Tree |
48
+ | Reuse | One engine for state, checkpoint, workspace projection, lifecycle, idempotency, and causality indexes |
49
+ | Domain handling | Index Domain Adapters |
50
+ | Key | Canonical Index Key |
51
+ | Value | Content-addressed Index Value Ref |
52
+ | Chunking | Content-Defined Chunking with protocol constants |
53
+ | Proofs | Membership and non-membership |
54
+ | Diff | Shared-node hash traversal |
55
+ | Storage | CAS-backed nodes through Storage Port |
56
+
57
+ ## Workspace Projection
58
+
59
+ | Parameter | Value |
60
+ | --- | --- |
61
+ | LicoLite default | Enabled and first priority |
62
+ | Structure | Dual index |
63
+ | Order index | `workspaceOrdinal -> ledgerEventRef` |
64
+ | Membership index | `ledgerEventId -> workspaceOrdinalRef` |
65
+ | Ordinal assignment | Same protocol commit as Ledger append |
66
+ | Concurrency | Single Ledger Append Lane plus synchronous projection updates; no separate per-workspace queue in current package |
67
+ | Contents | Operation Intents and Operation Outcomes; Repair Facts are reserved for a future repair executor |
68
+ | Ledger binding | Every projection update bound by global Ledger facts |
69
+
70
+ ## Checkpoint
71
+
72
+ | Parameter | Value |
73
+ | --- | --- |
74
+ | Role | Recovery/progress structure |
75
+ | Node proof | Shared Verifiable Index Engine |
76
+ | Intent Checkpoint | Lifecycle start or recoverable progress |
77
+ | Outcome Checkpoint | Default for LicoLite effects, results, and state transitions |
78
+ | Restore | Append marker/fact, no destructive rewrite |
79
+ | Tree head | Checkpoint root plus node index root |
80
+
81
+ ## State
82
+
83
+ | Parameter | Value |
84
+ | --- | --- |
85
+ | State index | Shared Verifiable Index Engine |
86
+ | Commit binding | Operation Outcome only |
87
+ | Key proof | Membership and non-membership |
88
+ | State root | Prolly root CID/hash |
89
+ | Diff | Prolly shared-node diff |
90
+
91
+ ## Proofs
92
+
93
+ | Parameter | Value |
94
+ | --- | --- |
95
+ | Main receipt | Pactium Proof Envelope |
96
+ | Write response | Synchronous envelope with content-addressed Proof Material Refs |
97
+ | Offline export | Proof Bundle |
98
+ | Bundle format | CAR-like block bundle plus Pactium manifest |
99
+ | Extensions | Hash-bound Proof Extensions |
100
+ | Critical extension | Unsupported critical extension fails verification |
101
+
102
+ ## LicoLite Aspect
103
+
104
+ | Parameter | Value |
105
+ | --- | --- |
106
+ | Export path | `pactium/licolite` |
107
+ | Workspace projection | Enabled by default, first priority |
108
+ | Signing | Enabled by default; missing signer behavior is LicoLite policy |
109
+ | Policy evidence | Critical LicoLite Policy Extension |
110
+ | Workspace effect evidence | Critical LicoLite Workspace Effect Extension |
111
+ | Verifier | Required LicoLite Verifier |
112
+ | Failures | Structured Verification Failures |
113
+ | Repair | Repair Planner only, no automatic repair |
114
+ | Data support | Latest schema only |
115
+
116
+ ## Maintenance And Repair
117
+
118
+ | Parameter | Value |
119
+ | --- | --- |
120
+ | Scheduler | No resident daemon |
121
+ | Task model | Deterministic Maintenance Task Engine |
122
+ | Repair execution | Host executes plans |
123
+ | Derived index repair | Repair Planner returns deterministic tasks; current package does not execute repair tasks or append Repair Facts |
124
+ | Original fact/content repair | Not invented; recovered only from authority, backup, or host evidence |
@@ -0,0 +1,62 @@
1
+ # Pactium Protocols
2
+
3
+ Pactium is the current proof-first protocol substrate. The glossary is maintained in [Terms](../TERM.md), and the approved protocol parameter matrix is [Protocol Profile](./PROFILE.md).
4
+
5
+ ## Operation Ledger
6
+
7
+ The Operation Ledger is the global ordering authority for Pactium protocol facts. It uses a dedicated Ledger Transparency Log to produce verifiable Ledger Heads, inclusion proofs, and consistency proofs.
8
+
9
+ Operation lifecycle is append-only:
10
+
11
+ - `Operation Intent` records the intended operation.
12
+ - `Operation Outcome` records the terminal result.
13
+ - `Open Intent Index` and `Outcome Index` make lifecycle recovery and lookup verifiable.
14
+ - `Intent Idempotency Index` and `Outcome Idempotency Index` make retries recover existing facts rather than append duplicates.
15
+
16
+ ## Workspace Projection
17
+
18
+ Workspace Projection is a first-priority capability for the LicoLite Aspect. It is enabled by default for LicoLite and is bound by global Ledger entries.
19
+
20
+ Workspace Projection uses two Verifiable Index Engine-backed indexes:
21
+
22
+ - `Workspace Order Index` maps workspace-local order to ledger event references.
23
+ - `Workspace Membership Index` maps ledger event identifiers to workspace-local membership material.
24
+
25
+ Workspace Projection currently includes workspace-scoped Operation Intents and Operation Outcomes. Repair Facts are reserved for a future repair executor and are not appended by the current package.
26
+
27
+ ## Verifiable Index Engine
28
+
29
+ Pactium uses one shared Canonical Prolly Tree based Verifiable Index Engine for ordered-key indexes that need stable roots, structural sharing, membership proofs, non-membership proofs, and efficient diffs.
30
+
31
+ Domain adapters convert domain material into canonical `Index Key` and `Index Value Ref` values. The engine is reused for Merkle State, Checkpoint Node, Workspace Projection, lifecycle, idempotency, and causality indexes.
32
+
33
+ ## Merkle State
34
+
35
+ Merkle State uses the shared Verifiable Index Engine for state roots, key membership proofs, key non-membership proofs, and diffs. State Commits bind to Operation Outcomes, not Operation Intents.
36
+
37
+ ## Checkpoint Tree
38
+
39
+ Checkpoint Tree owns recovery and progress structure. It is verifiable, but it does not replace Ledger Authority.
40
+
41
+ Checkpoint Tree distinguishes:
42
+
43
+ - `Intent Checkpoint` for lifecycle start or recoverable progress.
44
+ - `Outcome Checkpoint` for declared results, effect evidence, or state transition material.
45
+
46
+ Checkpoint node membership and diffs use shared Verifiable Index Engine-backed indexes.
47
+
48
+ ## Proof Envelopes And Bundles
49
+
50
+ `recordOperation` and lower-level lifecycle APIs return Pactium Proof Envelopes with content-addressed Proof Material Refs. Full portable proof material is exported through Proof Bundles.
51
+
52
+ Proof Bundles are CAR-like content-addressed block bundles with a Pactium manifest naming the root envelope, required blocks, protocol versions, Ledger Head, and critical extensions.
53
+
54
+ ## LicoLite Aspect
55
+
56
+ `pactium/licolite` is a first-class package surface for LicoLite. It provides LicoLite-facing protocol substrate integration, default Workspace Projection, default signing policy, critical policy and workspace-effect extensions, LicoLite-level verification, repair planning, and new-data-directory support.
57
+
58
+ LicoLite owns runtime policy decisions, operation dispatching, side effects, UI ownership, and durable Host Evidence storage. Pactium binds LicoLite evidence and verifies the binding.
59
+
60
+ ## Current Non-Surfaces
61
+
62
+ The current package does not ship a SQLite storage backend, a separate per-workspace FIFO lane queue, a repair executor that appends Repair Facts, or pressure-profile baseline regression enforcement. These require explicit implementation before maintained docs can describe them as current behavior.
@@ -0,0 +1,26 @@
1
+ import { createPactium } from "../src/index.js";
2
+ import { createLicoLiteAspect } from "../src/aspects/licolite/index.js";
3
+
4
+ const pactium = createPactium({ dataDir: "./.pactium" });
5
+ const licolite = createLicoLiteAspect({
6
+ pactium,
7
+ evidencePolicy: "opportunistic"
8
+ });
9
+
10
+ const envelope = await licolite.recordWorkspaceOperation({
11
+ operationId: "example.write",
12
+ workspaceId: "example",
13
+ idempotencyKey: "example-intent",
14
+ outcomeIdempotencyKey: "example-outcome",
15
+ input: { target: "hello.json" },
16
+ policyEvidence: { decision: "allow" },
17
+ workspaceEffectEvidence: { durableRef: "host:example:hello" },
18
+ stateMutations: [
19
+ { key: "hello.json", value: { hello: "pactium" } }
20
+ ]
21
+ });
22
+
23
+ console.log(JSON.stringify({
24
+ envelopeId: envelope.envelopeId,
25
+ verification: await licolite.verifyEnvelope(envelope)
26
+ }, null, 2));
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "pactium",
3
+ "version": "0.2.0",
4
+ "description": "Pactium — the proof-first protocol substrate for LicoLite state recording and recovery.",
5
+ "author": "Unka Y.Y.",
6
+ "license": "GPL-3.0-or-later",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/Unka-Malloc/Pactium.git"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/Unka-Malloc/Pactium/issues"
13
+ },
14
+ "homepage": "https://github.com/Unka-Malloc/Pactium#readme",
15
+ "type": "module",
16
+ "main": "./src/index.js",
17
+ "types": "./src/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./src/index.d.ts",
21
+ "import": "./src/index.js",
22
+ "default": "./src/index.js"
23
+ },
24
+ "./licolite": {
25
+ "types": "./src/aspects/licolite/index.d.ts",
26
+ "import": "./src/aspects/licolite/index.js",
27
+ "default": "./src/aspects/licolite/index.js"
28
+ }
29
+ },
30
+ "bin": {
31
+ "pactium": "bin/pactium.mjs"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public",
35
+ "registry": "https://registry.npmjs.org/",
36
+ "provenance": true
37
+ },
38
+ "files": [
39
+ "src/",
40
+ "bin/",
41
+ "examples/",
42
+ "docs/README.md",
43
+ "docs/architecture/",
44
+ "docs/protocols/",
45
+ "docs/LICOLITE-ASPECT.md",
46
+ "docs/TERM.md",
47
+ "README.md",
48
+ "README.zh-CN.md",
49
+ "SECURITY.md",
50
+ "LICENSE"
51
+ ],
52
+ "engines": {
53
+ "node": "^22.0.0 || ^24.0.0"
54
+ },
55
+ "scripts": {
56
+ "start": "pactium serve",
57
+ "test": "node --test tests/pactium/*.test.mjs",
58
+ "test:coverage": "node --test --experimental-test-coverage '--test-coverage-exclude=bin/**' --test-coverage-exclude=src/http.js --test-coverage-lines=95 --test-coverage-functions=95 --test-coverage-branches=90 tests/pactium/*.test.mjs",
59
+ "verify": "npm run verify:release",
60
+ "verify:core": "npm run test:coverage",
61
+ "verify:hygiene": "node scripts/verify-pactium-hygiene.mjs",
62
+ "verify:protocol:gates": "node scripts/verify-protocol-gates.mjs",
63
+ "verify:package:contents": "node scripts/verify-package-contents.mjs",
64
+ "verify:release:readiness": "node scripts/verify-release-readiness.mjs",
65
+ "verify:release": "npm run verify:hygiene && npm run verify:core && npm run verify:protocol:gates && npm run verify:release:readiness && npm run verify:package:contents && npm run pack:dry-run && npm run publish:dry-run",
66
+ "pack:dry-run": "npm pack --dry-run",
67
+ "publish:dry-run": "npm publish --dry-run"
68
+ }
69
+ }
package/src/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # Source Status
2
+
3
+ `src/` is the Pactium proof-first implementation.
4
+
5
+ - `index.js` is the package root facade and exports only proof-first APIs.
6
+ - `protocol/`, `canonical/`, and `storage/` own protocol constants, canonical values, hashing, and the local storage port adapter.
7
+ - `ledger/`, `index-engine/`, `proof/`, `repair/`, and `maintenance/` own proof algorithms and verification-oriented protocol machinery.
8
+ - `core/pactium-core.js` composes the protocol modules into the root Pactium runtime.
9
+ - `aspects/licolite/` owns the first-class `pactium/licolite` LicoLite Aspect.
10
+ - `quality/` owns public API pressure profiles used by release gates.
11
+ - Historical storage-shaped source files are removed and are not accepted by the current implementation.
12
+
13
+ Use [Architecture](../docs/architecture/ARCHITECTURE.md), [Protocols](../docs/protocols/PROTOCOLS.md), and [Protocol Profile](../docs/protocols/PROFILE.md) as the protocol authority.