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/README.md ADDED
@@ -0,0 +1,92 @@
1
+ <p align="center">
2
+ <strong>Pactium — the verifiable protocol substrate for LicoLite.</strong>
3
+ </p>
4
+
5
+ Pactium is a proof-first npm package that provides LicoLite's durable protocol substrate: verifiable operation facts, workspace projections, checkpoint recovery history, Merkle state, proof envelopes, and proof bundles.
6
+
7
+ Pactium implements the current verifiable protocol model documented in [Architecture](./docs/architecture/ARCHITECTURE.md), [Protocols](./docs/protocols/PROTOCOLS.md), and [Protocol Profile](./docs/protocols/PROFILE.md). The package root exposes only the latest proof-first API.
8
+
9
+ ## Direction
10
+
11
+ - **Operation Ledger** is the global ordering authority and uses a transparency log for inclusion and consistency proofs.
12
+ - **Operation lifecycle** is append-only through Operation Intent and Operation Outcome facts.
13
+ - **Workspace Projection** is first priority for the LicoLite Aspect and is enabled by default.
14
+ - **Verifiable Index Engine** is a shared Canonical Prolly Tree based proof engine for state, checkpoint, workspace projection, lifecycle, idempotency, and causality indexes.
15
+ - **Proof Envelopes** bind Ledger, Workspace Projection, Checkpoint, State, and LicoLite evidence into one receipt shape.
16
+ - **Proof Bundles** export portable CAR-like proof material for offline verification.
17
+ - **LicoLite Aspect** is a first-class package surface under `pactium/licolite`.
18
+
19
+ ## Boundaries
20
+
21
+ Pactium owns protocol facts, proof algorithms, canonical encoding, storage ports, verification, repair planning, and LicoLite protocol-substrate adapters.
22
+
23
+ LicoLite owns runtime policy decisions, operation dispatching, side effects, UI ownership, and durable host evidence storage.
24
+
25
+ ## Status
26
+
27
+ The proof-first implementation is active. Pactium accepts the latest verifiable schema only; earlier experimental data formats are rejected.
28
+
29
+ ## Usage
30
+
31
+ ```js
32
+ import { createPactium } from "pactium";
33
+
34
+ const pactium = createPactium({ dataDir: "./.pactium" });
35
+
36
+ const envelope = await pactium.recordOperation({
37
+ operationId: "workspace.file.write",
38
+ workspaceId: "workspace-a",
39
+ idempotencyKey: "intent-a",
40
+ outcomeIdempotencyKey: "outcome-a",
41
+ input: { path: "docs/a.md" },
42
+ stateMutations: [
43
+ { key: "docs/a.md", value: { text: "hello" } }
44
+ ]
45
+ });
46
+
47
+ console.log(await pactium.verifyEnvelope(envelope));
48
+ ```
49
+
50
+ ```js
51
+ import { createLicoLiteAspect, createLicoLiteSigner } from "pactium/licolite";
52
+
53
+ const signingSecret = process.env.LICOLITE_SIGNING_SECRET;
54
+ if (!signingSecret) throw new Error("LICOLITE_SIGNING_SECRET is required.");
55
+
56
+ const licolite = createLicoLiteAspect({
57
+ evidencePolicy: "production",
58
+ signer: createLicoLiteSigner({
59
+ signerId: "host-managed-signer",
60
+ secret: signingSecret
61
+ })
62
+ });
63
+
64
+ const envelope = await licolite.recordWorkspaceOperation({
65
+ operationId: "workspace.effect",
66
+ workspaceId: "workspace-a",
67
+ policyEvidence: { decision: "allow" },
68
+ workspaceEffectEvidence: { durableRef: "host:asset:a" }
69
+ });
70
+
71
+ console.log(await licolite.verifyEnvelope(envelope));
72
+ ```
73
+
74
+ ## Verification
75
+
76
+ ```bash
77
+ npm run verify:release
78
+ ```
79
+
80
+ The default release gate runs deterministic proof vectors, regression snapshots, seeded property tests, scaled public API pressure profiles, coverage thresholds, hygiene checks, release-readiness checks, and package dry run. CI runs the same release gate on every supported Node.js LTS major.
81
+
82
+ ## Documentation
83
+
84
+ - [Terms](./docs/TERM.md)
85
+ - [Protocol Overview](./docs/protocols/PROTOCOLS.md)
86
+ - [Protocol Profile](./docs/protocols/PROFILE.md)
87
+ - [Architecture](./docs/architecture/ARCHITECTURE.md)
88
+ - [LicoLite Aspect](./docs/LICOLITE-ASPECT.md)
89
+
90
+ ## License
91
+
92
+ This project is licensed under the [GNU General Public License v3.0 or later](LICENSE).
@@ -0,0 +1,90 @@
1
+ # Pactium
2
+
3
+ Pactium 是 LicoLite 的 proof-first protocol substrate,用于证明系统状态是可记录、可回溯、可管理的。
4
+
5
+ ## 当前状态
6
+
7
+ - package root 只导出 proof-first API。
8
+ - `pactium/licolite` 是 first-class LicoLite Aspect。
9
+ - 数据目录采用 latest schema only;不会执行历史数据迁移。
10
+ - Operation Intent / Operation Outcome 是 append-only 生命周期事实。
11
+ - Workspace Projection 默认服务 LicoLite,并与 Ledger commit 同步更新。
12
+ - Proof Envelope 与 Proof Bundle 是主要 receipt/export 形状。
13
+
14
+ ## 安装
15
+
16
+ ```bash
17
+ npm install pactium
18
+ ```
19
+
20
+ ## Root API
21
+
22
+ ```js
23
+ import { createPactium } from "pactium";
24
+
25
+ const pactium = createPactium({ dataDir: "./.pactium" });
26
+
27
+ const envelope = await pactium.recordOperation({
28
+ operationId: "workspace.file.write",
29
+ workspaceId: "workspace-a",
30
+ idempotencyKey: "intent-a",
31
+ outcomeIdempotencyKey: "outcome-a",
32
+ input: { path: "docs/a.md" },
33
+ stateMutations: [
34
+ { key: "docs/a.md", value: { text: "hello" } }
35
+ ]
36
+ });
37
+
38
+ console.log(envelope.envelopeId);
39
+ console.log(await pactium.verifyEnvelope(envelope));
40
+ ```
41
+
42
+ ## LicoLite Aspect
43
+
44
+ ```js
45
+ import { createLicoLiteAspect, createLicoLiteSigner } from "pactium/licolite";
46
+
47
+ const signingSecret = process.env.LICOLITE_SIGNING_SECRET;
48
+ if (!signingSecret) throw new Error("LICOLITE_SIGNING_SECRET is required.");
49
+
50
+ const licolite = createLicoLiteAspect({
51
+ evidencePolicy: "production",
52
+ signer: createLicoLiteSigner({
53
+ signerId: "host-managed-signer",
54
+ secret: signingSecret
55
+ })
56
+ });
57
+
58
+ const envelope = await licolite.recordWorkspaceOperation({
59
+ operationId: "workspace.effect",
60
+ workspaceId: "workspace-a",
61
+ policyEvidence: { decision: "allow" },
62
+ workspaceEffectEvidence: { durableRef: "host:asset:a" }
63
+ });
64
+
65
+ console.log(await licolite.verifyEnvelope(envelope));
66
+ ```
67
+
68
+ ## 验证
69
+
70
+ ```bash
71
+ npm run verify:release
72
+ ```
73
+
74
+ 完整压力 profile 可通过以下命令显式开启:
75
+
76
+ ```bash
77
+ PACTIUM_FULL_PRESSURE=1 npm run verify:protocol:gates
78
+ ```
79
+
80
+ ## 文档
81
+
82
+ - [Terms](./docs/TERM.md)
83
+ - [Protocol Profile](./docs/protocols/PROFILE.md)
84
+ - [Protocol Overview](./docs/protocols/PROTOCOLS.md)
85
+ - [Architecture](./docs/architecture/ARCHITECTURE.md)
86
+ - [LicoLite Aspect](./docs/LICOLITE-ASPECT.md)
87
+
88
+ ## 许可证
89
+
90
+ 本项目基于 [GNU General Public License v3.0 or later](LICENSE) 发布。
package/SECURITY.md ADDED
@@ -0,0 +1,7 @@
1
+ # Security
2
+
3
+ Pactium records operation metadata and redacts common sensitive fields before writing ledger inputs.
4
+
5
+ Host systems remain responsible for authentication, authorization, network exposure, tenant isolation, and secret storage. Pactium should be embedded behind the host system's security boundary.
6
+
7
+ Please report security issues privately through the repository owner rather than opening a public issue with exploit details.
@@ -0,0 +1,121 @@
1
+ #!/usr/bin/env node
2
+ import fs from "node:fs/promises";
3
+ import { createPactium, resolveDataDir } from "../src/index.js";
4
+ import { startPactiumHttpServer } from "../src/http.js";
5
+ import { createLicoLiteAspect } from "../src/aspects/licolite/index.js";
6
+
7
+ function argValue(args, name, fallback = "") {
8
+ const index = args.indexOf(name);
9
+ return index >= 0 && index + 1 < args.length ? args[index + 1] : fallback;
10
+ }
11
+
12
+ function hasArg(args, name) {
13
+ return args.includes(name);
14
+ }
15
+
16
+ function printJson(value) {
17
+ process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
18
+ }
19
+
20
+ async function bodyFromArgs(args) {
21
+ const inline = argValue(args, "--body", "");
22
+ if (inline) return JSON.parse(inline);
23
+ const file = argValue(args, "--body-file", "");
24
+ if (file) return JSON.parse(await fs.readFile(file, "utf8"));
25
+ if (!process.stdin.isTTY) {
26
+ const chunks = [];
27
+ for await (const chunk of process.stdin) chunks.push(chunk);
28
+ const text = Buffer.concat(chunks).toString("utf8").trim();
29
+ if (text) return JSON.parse(text);
30
+ }
31
+ return {};
32
+ }
33
+
34
+ function usage() {
35
+ return `Pactium
36
+
37
+ Usage:
38
+ pactium doctor [--data-dir DIR]
39
+ pactium serve [--data-dir DIR] [--host HOST] [--port PORT]
40
+ pactium intent begin --body JSON
41
+ pactium outcome append --body JSON
42
+ pactium operation record --body JSON
43
+ pactium envelope verify --body JSON
44
+ pactium bundle verify --body JSON
45
+ pactium licolite record --body JSON
46
+ pactium licolite verify --body JSON
47
+ `;
48
+ }
49
+
50
+ async function main() {
51
+ const args = process.argv.slice(2);
52
+ if (args.length === 0 || hasArg(args, "--help") || hasArg(args, "-h")) {
53
+ process.stdout.write(usage());
54
+ return;
55
+ }
56
+ const dataDir = resolveDataDir(argValue(args, "--data-dir", ""));
57
+ const pactium = createPactium({ dataDir });
58
+ const licolite = createLicoLiteAspect({
59
+ pactium,
60
+ evidencePolicy: argValue(args, "--evidence-policy", "opportunistic")
61
+ });
62
+ const [domain, action] = args.filter((arg, index, all) => {
63
+ if (index > 0 && all[index - 1].startsWith("--")) return false;
64
+ return !arg.startsWith("--");
65
+ });
66
+
67
+ if (domain === "doctor") {
68
+ printJson(await pactium.doctor());
69
+ return;
70
+ }
71
+ if (domain === "serve") {
72
+ const host = argValue(args, "--host", "127.0.0.1");
73
+ const port = Number(argValue(args, "--port", process.env.PACTIUM_HTTP_PORT || "7288"));
74
+ const started = await startPactiumHttpServer({ dataDir, host, port });
75
+ printJson({
76
+ protocol: started.protocol,
77
+ url: started.url,
78
+ dataDir
79
+ });
80
+ return;
81
+ }
82
+ if (domain === "intent" && action === "begin") {
83
+ printJson(await pactium.beginOperationIntent(await bodyFromArgs(args)));
84
+ return;
85
+ }
86
+ if (domain === "outcome" && action === "append") {
87
+ printJson(await pactium.appendOperationOutcome(await bodyFromArgs(args)));
88
+ return;
89
+ }
90
+ if (domain === "operation" && action === "record") {
91
+ printJson(await pactium.recordOperation(await bodyFromArgs(args)));
92
+ return;
93
+ }
94
+ if (domain === "envelope" && action === "verify") {
95
+ printJson(await pactium.verifyEnvelope(await bodyFromArgs(args)));
96
+ return;
97
+ }
98
+ if (domain === "bundle" && action === "verify") {
99
+ const { verifyProofBundle } = await import("../src/index.js");
100
+ printJson(await verifyProofBundle(await bodyFromArgs(args)));
101
+ return;
102
+ }
103
+ if (domain === "licolite" && action === "record") {
104
+ printJson(await licolite.recordWorkspaceOperation(await bodyFromArgs(args)));
105
+ return;
106
+ }
107
+ if (domain === "licolite" && action === "verify") {
108
+ printJson(await licolite.verifyEnvelope(await bodyFromArgs(args)));
109
+ return;
110
+ }
111
+ process.exitCode = 1;
112
+ process.stderr.write(usage());
113
+ }
114
+
115
+ main().catch((error) => {
116
+ process.exitCode = 1;
117
+ printJson({
118
+ code: "pactium_cli_error",
119
+ error: error instanceof Error ? error.message : String(error)
120
+ });
121
+ });
@@ -0,0 +1,57 @@
1
+ # LicoLite Aspect
2
+
3
+ This document describes the current LicoLite package surface implemented by `pactium/licolite`.
4
+
5
+ Pactium is LicoLite's proof-first protocol substrate. LicoLite is the primary host, and `pactium/licolite` is a first-class aspect whose requirements may shape Pactium core capability design.
6
+
7
+ ## Non-Negotiables
8
+
9
+ | Area | Required behavior |
10
+ | --- | --- |
11
+ | Package relationship | Pactium is subordinate to LicoLite and provides the protocol substrate LicoLite needs. |
12
+ | Export shape | Package root exposes latest proof-first API only; `pactium/licolite` exposes the LicoLite Aspect. |
13
+ | Workspace Projection | Enabled by default for LicoLite and first priority. |
14
+ | Ledger authority | Global Operation Ledger remains the ordering authority. |
15
+ | Projection commit | Workspace Projection updates happen synchronously with Ledger-bound protocol commits. |
16
+ | Workspace reverse lookup | Workspace Membership Index proves whether a Ledger fact belongs to a workspace. |
17
+ | Signing | Enabled by default for the LicoLite Aspect; missing signer behavior is LicoLite policy. |
18
+ | Policy evidence | LicoLite Policy Extension is critical and hash-bound. |
19
+ | Workspace effect evidence | LicoLite Workspace Effect Extension is critical and hash-bound. |
20
+ | Verifier | LicoLite Verifier is required and returns structured Verification Failures. |
21
+ | Data directories | New Pactium-format data directories only. |
22
+ | Migration | No historical LicoLite or Pactium data migration in Pactium. |
23
+ | Host boundary | LicoLite owns policy decisions, operation dispatching, side effects, UI, authorization, and durable Host Evidence storage. |
24
+
25
+ ## Required Public Surfaces
26
+
27
+ | Surface | Requirement |
28
+ | --- | --- |
29
+ | Root API | Proof-first lifecycle, Ledger, index, state, checkpoint, proof, verification, maintenance, and repair APIs only. |
30
+ | `pactium/licolite` | LicoLite workspace operation recording and verification with default Workspace Projection. |
31
+ | Proof response | Synchronous Pactium Proof Envelope with content-addressed Proof Material Refs. |
32
+ | Offline proof | Proof Bundle export and verification without local Pactium storage. |
33
+ | Lifecycle | Operation Intent, Operation Outcome, Open Intent recovery, idempotency replay, and Operation Causality Index. |
34
+ | Workspace projection | Workspace Order Index plus Workspace Membership Index over the shared Verifiable Index Engine. |
35
+ | State | State Commit bound to Operation Outcome only. |
36
+ | Checkpoint | Intent Checkpoint and Outcome Checkpoint; LicoLite side-effect checkpoints default to Outcome. |
37
+ | Repair | Repair Planner produces deterministic plans; hosts execute them. |
38
+
39
+ ## Explicitly Rejected Old Assumptions
40
+
41
+ - `pactium/licolite` is not an external plugin.
42
+ - LicoLite Workspace Projection is not optional or secondary.
43
+ - Pactium does not keep removed storage-shaped APIs in the package root export.
44
+ - Pactium does not read or migrate historical LicoLite protocol data in place.
45
+ - Pactium does not expose proof hashes as substitutes for membership, non-membership, consistency, or bundle verification.
46
+ - Pactium does not execute LicoLite policy, side effects, operation dispatching, UI behavior, or authorization.
47
+ - Pactium does not make Protocol Hash, Canonical Value encoding, Prolly Tree chunking, or proof formats host configurable.
48
+
49
+ ## Acceptance Evidence
50
+
51
+ The LicoLite Aspect is acceptable only when the release gate passes and includes evidence for:
52
+
53
+ - root export and `pactium/licolite` export snapshots;
54
+ - LicoLite workspace operations with signing, critical extensions, Workspace Projection, State Commit, Checkpoint, Proof Envelope, and Proof Bundle;
55
+ - missing signer/evidence behavior controlled by LicoLite policy, with production-style fail-closed tests;
56
+ - structured Verification Failures for bad signature, missing proof material, unsupported critical extension, bad workspace projection proof, and Ledger consistency failure;
57
+ - public API pressure test `api:licolite-record` in the default scaled release gate, with the 5,000-operation profile available through `PACTIUM_FULL_PRESSURE=1 npm run verify:protocol:gates` for explicit full review.
package/docs/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # Pactium Public Docs
2
+
3
+ Pactium is a proof-first protocol substrate for LicoLite.
4
+
5
+ ## Package Documents
6
+
7
+ - [Architecture](architecture/ARCHITECTURE.md)
8
+ - [Protocols](protocols/PROTOCOLS.md)
9
+ - [Protocol Profile](protocols/PROFILE.md)
10
+ - [LicoLite Aspect](LICOLITE-ASPECT.md)
11
+ - [Terms](TERM.md)
12
+
13
+ The current `src/` tree implements the proof-first package surface. Repository maintenance, release, tooling, ADR, and optimization records are intentionally not part of the published npm package.