@godspeedai/cognate-realitytrace 0.1.1 → 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.
- package/README.md +97 -34
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,42 +1,105 @@
|
|
|
1
1
|
# @godspeedai/cognate-realitytrace
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Cognate's adapter for RealityTrace (SXR), an independent observation-and-evidence tool driven
|
|
4
|
+
through its `sxr` CLI. This package moves observations of
|
|
5
|
+
your application's committed history to RealityTrace without ever blocking or rewriting that
|
|
6
|
+
history: an outbox-based delivery port, persisted per-observation receipts, a strict
|
|
7
|
+
"was it recorded?" gate, and typed envelopes for execution traces and evidence packets.
|
|
5
8
|
|
|
6
|
-
|
|
9
|
+
**When to use this package:** you want an external, independent ledger of what your Cognate
|
|
10
|
+
application actually did — recorded at-least-once from committed events, with correlation ids
|
|
11
|
+
that survive the trip — while keeping the adapter optional and RealityTrace unchanged.
|
|
12
|
+
Everything here degrades gracefully: if RealityTrace is slow or down, your app keeps running.
|
|
7
13
|
|
|
8
|
-
|
|
9
|
-
decision as the event; `ObservationDelivery` drains the outbox at-least-once
|
|
10
|
-
in the background. A slow or unreachable SXR never blocks or rolls back
|
|
11
|
-
committed history — failures retry with backoff, then poison for operator
|
|
12
|
-
reconciliation (`unreconciled()`).
|
|
14
|
+
## Installation
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
```sh
|
|
17
|
+
bun add @godspeedai/cognate-realitytrace
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Requires [Bun](https://bun.sh) >= 1.4.0, a
|
|
21
|
+
[`@godspeedai/cognate-events`](https://www.npmjs.com/package/@godspeedai/cognate-events)
|
|
22
|
+
store, and the external RealityTrace CLI:
|
|
23
|
+
|
|
24
|
+
- The `sxr` binary must be installed on the machine; you pass its path to the port.
|
|
25
|
+
- A working directory the tool can enroll as its repository (the adapter initializes it with
|
|
26
|
+
git on first `prepare()`).
|
|
27
|
+
- RealityTrace >= 0.3.0 for structured correlation readback (`readCorrelation`).
|
|
28
|
+
|
|
29
|
+
The SDK ships Bun-native TypeScript source, so add `@types/bun` and `@types/node` as dev
|
|
30
|
+
dependencies when typechecking your project.
|
|
31
|
+
|
|
32
|
+
## Quick start
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { openSqliteStore } from "@godspeedai/cognate-store-sqlite";
|
|
36
|
+
import {
|
|
37
|
+
createSxrCliPort,
|
|
38
|
+
ObservationDelivery,
|
|
39
|
+
observationIntent,
|
|
40
|
+
} from "@godspeedai/cognate-realitytrace";
|
|
41
|
+
|
|
42
|
+
const store = openSqliteStore({ path: "./app.sqlite" });
|
|
43
|
+
|
|
44
|
+
// One-time enrollment of the external tool (repo, question, threshold, run):
|
|
45
|
+
const port = createSxrCliPort({ bin: "/usr/local/bin/sxr", repoDir: "./sxr-repo" });
|
|
46
|
+
const workflow = await port.prepare({ title: "Runtime behaves as declared" });
|
|
47
|
+
|
|
48
|
+
const delivery = new ObservationDelivery(store, {
|
|
49
|
+
port,
|
|
50
|
+
backoff: { baseMs: 1_000, maxMs: 30_000, maxAttempts: 8 },
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// When committing an event whose observation matters, include the observation intent
|
|
54
|
+
// in the SAME commit — the observation can then never refer to an event that may not exist:
|
|
55
|
+
await store.commit({
|
|
56
|
+
appends: [/* your event */],
|
|
57
|
+
outbox: [observationIntent(event, { classification: "durable_fact", capabilityId: "refund.approve" })],
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// From a background loop, drain deliveries. A slow or unreachable tool never blocks
|
|
61
|
+
// committed history: failures retry with backoff, then park for operator attention.
|
|
62
|
+
await delivery.drain();
|
|
63
|
+
|
|
64
|
+
// Normal mode: check on delivery. Strict mode: gate an operation on it.
|
|
65
|
+
const status = await delivery.status(eventId); // queued | accepted | duplicate | retrying | failed
|
|
66
|
+
const stuck = await delivery.unreconciled(); // deliveries needing operator attention
|
|
67
|
+
if (await delivery.isRecorded(eventId)) {
|
|
68
|
+
// the tool has accepted (or already had) this observation
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The CLI port (`createSxrCliPort`) also offers `readCorrelation(targetRef)` — your observation's
|
|
73
|
+
correlation ids read back from the tool's committed record — plus `deriveEvidence` and
|
|
74
|
+
`readEvidence` for the tool's own evidence derivation, and `executionTraceEnvelope`,
|
|
75
|
+
`governedTraceFor`, and `evidencePacketEnvelope` for typed record envelopes at the boundary.
|
|
17
76
|
|
|
18
77
|
## What a receipt means — and does not mean
|
|
19
78
|
|
|
20
|
-
A `
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
port
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
79
|
+
A delivery receipt (`accepted` or `duplicate`) means RealityTrace's ledger recorded — or had
|
|
80
|
+
already recorded — the observation. It is **not evidence** and **not settlement**: deriving
|
|
81
|
+
evidence and settling questions are separate, explicit steps of the external tool, invoked
|
|
82
|
+
through this adapter but decided by it. Delivery is idempotent per observation (retries land
|
|
83
|
+
on the same ledger position and report as `duplicate`), and the authoritative event →
|
|
84
|
+
observation → receipt mapping stays in your store, keyed by event id.
|
|
85
|
+
|
|
86
|
+
## Limitations
|
|
87
|
+
|
|
88
|
+
- The port holds the enrollment workflow in memory: call `prepare()` once per process before
|
|
89
|
+
recording, and again after a restart if the process is long-lived.
|
|
90
|
+
- Delivery is at-least-once; the external tool deduplicates by run and verifier.
|
|
91
|
+
- Every delivery shells out to the `sxr` binary — budget for that process cost in hot paths.
|
|
92
|
+
- If deliveries exhaust their retries they are poisoned for operator reconciliation; nothing
|
|
93
|
+
deletes or rewrites committed events in the meantime.
|
|
94
|
+
|
|
95
|
+
## Related packages
|
|
96
|
+
|
|
97
|
+
- [`@godspeedai/cognate-events`](https://www.npmjs.com/package/@godspeedai/cognate-events) —
|
|
98
|
+
the store and outbox machinery deliveries are driven from.
|
|
99
|
+
- [`@godspeedai/cognate-runtime-bun`](https://www.npmjs.com/package/@godspeedai/cognate-runtime-bun) —
|
|
100
|
+
the reference runtime whose events this adapter observes.
|
|
101
|
+
- [`@godspeedai/cognate`](https://www.npmjs.com/package/@godspeedai/cognate) — the SDK umbrella.
|
|
102
|
+
|
|
103
|
+
## License
|
|
104
|
+
|
|
105
|
+
Apache-2.0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@godspeedai/cognate-realitytrace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Observation port, committed-outbox delivery, receipts, strict gating, and the SXR CLI adapter (spec §20). RealityTrace stays unchanged.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
".": "./src/index.ts"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@godspeedai/cognate-events": "^0.
|
|
26
|
-
"@godspeedai/cognate-kernel-api": "^0.
|
|
25
|
+
"@godspeedai/cognate-events": "^0.2.0",
|
|
26
|
+
"@godspeedai/cognate-kernel-api": "^0.2.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@godspeedai/cognate-store-memory": "workspace:*",
|