@oathe/oathe 0.0.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/LICENSE +202 -21
- package/NOTICE +7 -0
- package/README.md +99 -12
- package/assets/oathe-hero.svg +92 -0
- package/bin/oathe.mjs +376 -0
- package/docs/PRIVACY.md +45 -0
- package/package.json +32 -23
- package/plugin/.claude-plugin/plugin.json +10 -0
- package/plugin/.mcp.json +13 -0
- package/plugin/hooks/frame-note.mjs +24 -0
- package/plugin/hooks/heartbeat.mjs +49 -0
- package/plugin/hooks/hooks.json +39 -0
- package/plugin/hooks/lib.mjs +83 -0
- package/plugin/hooks/render-board.mjs +11 -0
- package/plugin/skills/oathe-work/SKILL.md +33 -0
- package/src/atif.mjs +633 -0
- package/src/blocks.mjs +192 -0
- package/src/board-render.mjs +106 -0
- package/src/config.mjs +169 -0
- package/src/context.mjs +35 -0
- package/src/doctor.mjs +108 -0
- package/src/harness.mjs +271 -0
- package/src/init.mjs +92 -0
- package/src/launch-env.mjs +25 -0
- package/src/launch.mjs +259 -0
- package/src/manifest.mjs +89 -0
- package/src/mcp/oathe-tools.mjs +517 -0
- package/src/paths.mjs +49 -0
- package/src/plans.mjs +50 -0
- package/src/runtime/discharge.mjs +57 -0
- package/src/runtime/provider.mjs +154 -0
- package/src/runtime/simple-cage.mjs +67 -0
- package/src/runtime/sql-acceptance-lane.mjs +89 -0
- package/src/session-host.mjs +81 -0
- package/src/substrate.mjs +337 -0
- package/src/successor.mjs +31 -0
- package/src/traces.mjs +242 -0
- package/src/uninstall.mjs +45 -0
- package/src/verifier.mjs +322 -0
- package/src/workspace.mjs +47 -0
- package/vendor/ddl/001_core.sql +312 -0
- package/vendor/ddl/002_claim.sql +438 -0
- package/vendor/ddl/003_verification.sql +480 -0
- package/vendor/ddl/004_delegation.sql +397 -0
- package/vendor/ddl/005_escalation.sql +303 -0
- package/vendor/ddl/006_dependency.sql +384 -0
- package/vendor/ddl/007_assignment.sql +502 -0
- package/vendor/ddl/008_effect_receipt.sql +290 -0
- package/vendor/ddl/009_verified_edge.sql +452 -0
- package/vendor/ddl/010_parent_child_verification.sql +320 -0
- package/vendor/ddl/011_confirm.sql +288 -0
- package/vendor/ddl/012_evaluator_lane.sql +444 -0
- package/vendor/ddl/013_claim_terminal.sql +279 -0
- package/vendor/ddl/014_claim_settlement.sql +327 -0
- package/vendor/ddl/015_claim_yield.sql +213 -0
- package/vendor/ddl/016_reopened_reclaim.sql +285 -0
- package/vendor/ddl/017_claim_yield_causes.sql +357 -0
- package/vendor/ddl/018_receiptless_unknown.sql +249 -0
- package/vendor/ddl/019_verification_contract_freeze.sql +335 -0
- package/vendor/ddl/020_context_compilation.sql +105 -0
- package/vendor/ddl/021_execution_attempt_closure.sql +95 -0
- package/vendor/ddl/022_verification_clause.sql +106 -0
- package/vendor/ddl/023_executor_role.sql +66 -0
- package/vendor/ddl/024_executor_role_hardening.sql +439 -0
- package/vendor/ddl/025_running_attempt_uniqueness.sql +102 -0
- package/vendor/ddl/026_acceptance_authority.sql +230 -0
- package/vendor/ddl/027_ownership_return.sql +836 -0
- package/vendor/ddl/028_attempt_bind_ownership.sql +173 -0
- package/vendor/ddl/manifest.json +183 -0
- package/index.js +0 -33
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
-- 008_effect_receipt.sql — claim the receipt BEFORE the effect fires.
|
|
2
|
+
--
|
|
3
|
+
-- Contract: docs/a1-cell-work-spine-contract.md §1.2 (R3's interrupted attempts
|
|
4
|
+
-- and their reconciliation), §5 case 3 (kill after external effect, before
|
|
5
|
+
-- completion bookkeeping) and case 6's MID-EFFECT-HOLD; FOUNDER RULING R3
|
|
6
|
+
-- ("bundled inseparably: effect receipts — an irreversible external effect
|
|
7
|
+
-- claims a durable receipt in-substrate before firing; WITHOUT RECEIPTS,
|
|
8
|
+
-- UNKNOWN IS PERMANENT BY CONSTRUCTION"). Field shape per the A2 verification
|
|
9
|
+
-- strategy §2 (the measured Slack gateway sequence).
|
|
10
|
+
-- Requires 001_core.sql.
|
|
11
|
+
--
|
|
12
|
+
-- Re-apply: idempotent (CREATE ... IF NOT EXISTS / OR REPLACE).
|
|
13
|
+
-- Revert: DROP SCHEMA cell CASCADE; (this file installs nothing outside it)
|
|
14
|
+
--
|
|
15
|
+
-- WHY THE RECEIPT IS CLAIMED FIRST, AND WHY THAT IS THE WHOLE POINT
|
|
16
|
+
--
|
|
17
|
+
-- R3 makes `execution_attempt.outcome_status='unknown'` a state with a deadline
|
|
18
|
+
-- and a named resolver rather than a permanent shrug. That only works if there
|
|
19
|
+
-- is something to reconcile AGAINST. If the sole record that an effect was about
|
|
20
|
+
-- to fire lives in the process that fires it, then killing that process between
|
|
21
|
+
-- the remote commit and the local checkpoint destroys the only evidence, and
|
|
22
|
+
-- `unknown` becomes permanent by construction — which is why `evidence_lost` was
|
|
23
|
+
-- REJECTED as a terminal: it mints an unobserved fact. The receipt row is the
|
|
24
|
+
-- durable pre-image, written before the effect, surviving the process that wrote
|
|
25
|
+
-- it. The estate's own `slack_post_marker` is the measured precedent: built,
|
|
26
|
+
-- tested, and zero rows, because nothing made it mandatory.
|
|
27
|
+
--
|
|
28
|
+
-- The sequence this table stands under (strategy §2):
|
|
29
|
+
-- receipt-claim → POST → remote apply → response → receipt-confirm → statement
|
|
30
|
+
-- Killing at any of those points leaves a row that says exactly how far it got.
|
|
31
|
+
--
|
|
32
|
+
-- Declared failure vocabulary added by this file (SQLSTATE class FC; this lane
|
|
33
|
+
-- reserves FC080-FC089 — it previously trespassed on the assignment lane's half
|
|
34
|
+
-- of the FC020-FC039 block, which made FC030/FC031 mean two things each):
|
|
35
|
+
-- FC080 RECEIPT_KEY_PAYLOAD_CONFLICT a reused key with a different payload
|
|
36
|
+
-- FC081 RECEIPT_KEY_ADDRESS_CONFLICT a reused key aimed somewhere else
|
|
37
|
+
-- FC082 RECEIPT_CONFIRMED_WITHOUT_CLAIM a confirmation with no claim behind it
|
|
38
|
+
-- FC083 RECEIPT_OUTCOME_CONTRADICTED two different answers about one effect
|
|
39
|
+
|
|
40
|
+
CREATE TABLE IF NOT EXISTS cell.effect_receipt (
|
|
41
|
+
org_id text NOT NULL,
|
|
42
|
+
|
|
43
|
+
-- The idempotency key, chosen by the caller and meaningful to it. This is
|
|
44
|
+
-- the primary key with org_id and nothing else: exactly-once is a property
|
|
45
|
+
-- of the KEY, so a second row under the same key must be impossible for
|
|
46
|
+
-- every writer, not only for callers that remembered to check first.
|
|
47
|
+
receipt_key text NOT NULL,
|
|
48
|
+
|
|
49
|
+
-- Whose responsibility, and which runtime binding, was mid-effect. R6's
|
|
50
|
+
-- kill exclusion reads this: an attempt holding a claimed-unresolved receipt
|
|
51
|
+
-- is not terminated until the receipt resolves via ledger reconciliation.
|
|
52
|
+
work_claim_id uuid NOT NULL,
|
|
53
|
+
attempt_id uuid NOT NULL,
|
|
54
|
+
|
|
55
|
+
bus_event_ref text NOT NULL,
|
|
56
|
+
|
|
57
|
+
-- strategy §2: WHICH connector, at WHAT address. "What have we already done
|
|
58
|
+
-- to this destination" is answerable from the substrate alone, without
|
|
59
|
+
-- asking the remote service — which matters most precisely when the remote
|
|
60
|
+
-- service is the thing that is unreachable.
|
|
61
|
+
connector text NOT NULL,
|
|
62
|
+
address text NOT NULL,
|
|
63
|
+
|
|
64
|
+
payload_hash text NOT NULL,
|
|
65
|
+
claimed_at timestamptz NOT NULL,
|
|
66
|
+
|
|
67
|
+
-- NULL exactly while the outcome is still `claimed`.
|
|
68
|
+
confirmed_at timestamptz,
|
|
69
|
+
|
|
70
|
+
outcome text NOT NULL,
|
|
71
|
+
|
|
72
|
+
-- The pointer into the remote's own append-only ledger — the "remote truth"
|
|
73
|
+
-- the reconciler reads to settle an `unknown` (R3). A resolved receipt with
|
|
74
|
+
-- no pointer is a resolution nobody can check.
|
|
75
|
+
remote_ref text,
|
|
76
|
+
|
|
77
|
+
CONSTRAINT effect_receipt_pkey PRIMARY KEY (org_id, receipt_key),
|
|
78
|
+
|
|
79
|
+
CONSTRAINT effect_receipt_claim_fkey
|
|
80
|
+
FOREIGN KEY (org_id, work_claim_id)
|
|
81
|
+
REFERENCES cell.work_claim (org_id, work_claim_id),
|
|
82
|
+
|
|
83
|
+
CONSTRAINT effect_receipt_attempt_fkey
|
|
84
|
+
FOREIGN KEY (attempt_id) REFERENCES cell.execution_attempt (attempt_id),
|
|
85
|
+
|
|
86
|
+
CONSTRAINT effect_receipt_outcome_is_a_declared_outcome
|
|
87
|
+
CHECK (outcome IN ('claimed', 'applied', 'deduped', 'conflict', 'refused')),
|
|
88
|
+
|
|
89
|
+
CONSTRAINT effect_receipt_claimed_receipt_is_the_unconfirmed_one
|
|
90
|
+
CHECK ((outcome = 'claimed') = (confirmed_at IS NULL)),
|
|
91
|
+
|
|
92
|
+
CONSTRAINT effect_receipt_resolved_receipt_points_at_the_remote_record
|
|
93
|
+
CHECK (outcome NOT IN ('applied', 'deduped', 'conflict')
|
|
94
|
+
OR remote_ref IS NOT NULL),
|
|
95
|
+
|
|
96
|
+
CONSTRAINT effect_receipt_unconfirmed_receipt_has_no_remote_record
|
|
97
|
+
CHECK (outcome <> 'claimed' OR remote_ref IS NULL),
|
|
98
|
+
|
|
99
|
+
-- NOT NULL permits the empty string. A blank connector or address is an
|
|
100
|
+
-- absent one wearing a value's clothes, and the receipt would then say an
|
|
101
|
+
-- effect was claimed somewhere without saying where.
|
|
102
|
+
CONSTRAINT effect_receipt_connector_is_addressable
|
|
103
|
+
CHECK (length(btrim(connector)) > 0),
|
|
104
|
+
CONSTRAINT effect_receipt_address_is_addressable
|
|
105
|
+
CHECK (length(btrim(address)) > 0),
|
|
106
|
+
CONSTRAINT effect_receipt_bus_event_ref_is_addressable
|
|
107
|
+
CHECK (length(btrim(bus_event_ref)) > 0)
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
COMMENT ON TABLE cell.effect_receipt IS
|
|
111
|
+
'FOUNDER RULING R3: an irreversible external effect claims a durable receipt '
|
|
112
|
+
'here BEFORE firing. Without receipts, outcome_status=''unknown'' is '
|
|
113
|
+
'permanent by construction.';
|
|
114
|
+
|
|
115
|
+
CREATE INDEX IF NOT EXISTS effect_receipt_unresolved_by_attempt
|
|
116
|
+
ON cell.effect_receipt (org_id, attempt_id)
|
|
117
|
+
WHERE outcome = 'claimed';
|
|
118
|
+
|
|
119
|
+
-- ------------------------------------------------------------- claim the receipt
|
|
120
|
+
--
|
|
121
|
+
-- Returns TRUE when this call took the key and FALSE when it found an identical
|
|
122
|
+
-- claim already there. The boolean is the point: a caller that cannot tell
|
|
123
|
+
-- "I claimed it" from "somebody already did" has no way to decide whether to
|
|
124
|
+
-- fire, and firing on both answers is the duplicate-effect bug.
|
|
125
|
+
--
|
|
126
|
+
-- ON CONFLICT DO NOTHING rather than DO UPDATE, deliberately: an upsert would
|
|
127
|
+
-- make a reused key silently overwrite the first claim's payload and address,
|
|
128
|
+
-- and the reconciler would then be reading a receipt for an effect that was
|
|
129
|
+
-- never fired with those contents. Divergence is RAISED instead.
|
|
130
|
+
CREATE OR REPLACE FUNCTION cell.claim_effect_receipt(
|
|
131
|
+
p_org_id text,
|
|
132
|
+
p_receipt_key text,
|
|
133
|
+
p_work_claim_id uuid,
|
|
134
|
+
p_attempt_id uuid,
|
|
135
|
+
p_bus_event_ref text,
|
|
136
|
+
p_connector text,
|
|
137
|
+
p_address text,
|
|
138
|
+
p_payload_hash text,
|
|
139
|
+
p_claimed_at timestamptz
|
|
140
|
+
)
|
|
141
|
+
RETURNS boolean
|
|
142
|
+
LANGUAGE plpgsql
|
|
143
|
+
AS $claim_receipt$
|
|
144
|
+
DECLARE
|
|
145
|
+
v_claimed boolean := false;
|
|
146
|
+
v_payload_hash text;
|
|
147
|
+
v_address text;
|
|
148
|
+
v_connector text;
|
|
149
|
+
BEGIN
|
|
150
|
+
INSERT INTO cell.effect_receipt (
|
|
151
|
+
org_id, receipt_key, work_claim_id, attempt_id, bus_event_ref,
|
|
152
|
+
connector, address, payload_hash, claimed_at, confirmed_at, outcome,
|
|
153
|
+
remote_ref
|
|
154
|
+
) VALUES (
|
|
155
|
+
p_org_id, p_receipt_key, p_work_claim_id, p_attempt_id, p_bus_event_ref,
|
|
156
|
+
p_connector, p_address, p_payload_hash, p_claimed_at, NULL, 'claimed',
|
|
157
|
+
NULL
|
|
158
|
+
)
|
|
159
|
+
ON CONFLICT (org_id, receipt_key) DO NOTHING;
|
|
160
|
+
|
|
161
|
+
GET DIAGNOSTICS v_claimed = ROW_COUNT;
|
|
162
|
+
IF v_claimed THEN
|
|
163
|
+
RETURN true;
|
|
164
|
+
END IF;
|
|
165
|
+
|
|
166
|
+
SELECT payload_hash, address, connector
|
|
167
|
+
INTO v_payload_hash, v_address, v_connector
|
|
168
|
+
FROM cell.effect_receipt
|
|
169
|
+
WHERE org_id = p_org_id AND receipt_key = p_receipt_key;
|
|
170
|
+
|
|
171
|
+
IF v_payload_hash IS DISTINCT FROM p_payload_hash THEN
|
|
172
|
+
RAISE EXCEPTION
|
|
173
|
+
'RECEIPT_KEY_PAYLOAD_CONFLICT:% — this key already holds a receipt for '
|
|
174
|
+
'a DIFFERENT payload (recorded %, offered %). Overwriting it would '
|
|
175
|
+
'leave the reconciler reading a receipt for an effect that was never '
|
|
176
|
+
'fired with those contents; a key that can be re-pointed at another '
|
|
177
|
+
'payload is not an idempotency key.',
|
|
178
|
+
p_receipt_key, v_payload_hash, p_payload_hash
|
|
179
|
+
USING ERRCODE = 'FC080';
|
|
180
|
+
END IF;
|
|
181
|
+
|
|
182
|
+
IF v_address IS DISTINCT FROM p_address OR v_connector IS DISTINCT FROM p_connector THEN
|
|
183
|
+
RAISE EXCEPTION
|
|
184
|
+
'RECEIPT_KEY_ADDRESS_CONFLICT:% — this key already holds a receipt '
|
|
185
|
+
'aimed at %/%, and this call aims at %/%. Same reasoning as the '
|
|
186
|
+
'payload clause, one field over.',
|
|
187
|
+
p_receipt_key, v_connector, v_address, p_connector, p_address
|
|
188
|
+
USING ERRCODE = 'FC081';
|
|
189
|
+
END IF;
|
|
190
|
+
|
|
191
|
+
-- An identical re-claim: the effect was already claimed by this or an
|
|
192
|
+
-- earlier attempt, and the caller must NOT fire again.
|
|
193
|
+
RETURN false;
|
|
194
|
+
END;
|
|
195
|
+
$claim_receipt$;
|
|
196
|
+
|
|
197
|
+
-- ----------------------------------------------------------- confirm the fire
|
|
198
|
+
--
|
|
199
|
+
-- Returns TRUE when this call moved the receipt and FALSE when it restated an
|
|
200
|
+
-- outcome already recorded — case 3's REPLAY-N, where the gateway sequence is
|
|
201
|
+
-- replayed and the substrate must end in the same state with no second effect
|
|
202
|
+
-- implied.
|
|
203
|
+
CREATE OR REPLACE FUNCTION cell.confirm_effect_receipt(
|
|
204
|
+
p_org_id text,
|
|
205
|
+
p_receipt_key text,
|
|
206
|
+
p_outcome text,
|
|
207
|
+
p_remote_ref text,
|
|
208
|
+
p_confirmed_at timestamptz
|
|
209
|
+
)
|
|
210
|
+
RETURNS boolean
|
|
211
|
+
LANGUAGE plpgsql
|
|
212
|
+
AS $confirm_receipt$
|
|
213
|
+
DECLARE
|
|
214
|
+
v_outcome text;
|
|
215
|
+
v_remote_ref text;
|
|
216
|
+
BEGIN
|
|
217
|
+
SELECT outcome, remote_ref INTO v_outcome, v_remote_ref
|
|
218
|
+
FROM cell.effect_receipt
|
|
219
|
+
WHERE org_id = p_org_id AND receipt_key = p_receipt_key
|
|
220
|
+
FOR UPDATE;
|
|
221
|
+
|
|
222
|
+
IF NOT FOUND THEN
|
|
223
|
+
RAISE EXCEPTION
|
|
224
|
+
'RECEIPT_CONFIRMED_WITHOUT_CLAIM:% — no receipt was claimed under this '
|
|
225
|
+
'key, so an effect fired with no durable record that it was about to. '
|
|
226
|
+
'Claim-before-fire is the whole of R3: without the pre-image there is '
|
|
227
|
+
'nothing for a reconciler to resolve an unknown outcome against.',
|
|
228
|
+
p_receipt_key
|
|
229
|
+
USING ERRCODE = 'FC082';
|
|
230
|
+
END IF;
|
|
231
|
+
|
|
232
|
+
IF v_outcome <> 'claimed' THEN
|
|
233
|
+
IF v_outcome = p_outcome AND v_remote_ref IS NOT DISTINCT FROM p_remote_ref THEN
|
|
234
|
+
RETURN false; -- an identical replay
|
|
235
|
+
END IF;
|
|
236
|
+
RAISE EXCEPTION
|
|
237
|
+
'RECEIPT_OUTCOME_CONTRADICTED:% — this receipt already records ''%'' '
|
|
238
|
+
'(remote %), and this call says ''%'' (remote %). Two different answers '
|
|
239
|
+
'about whether one irreversible effect happened is not a value to '
|
|
240
|
+
'overwrite; it is a fact to investigate.',
|
|
241
|
+
p_receipt_key, v_outcome, coalesce(v_remote_ref, '<none>'),
|
|
242
|
+
p_outcome, coalesce(p_remote_ref, '<none>')
|
|
243
|
+
USING ERRCODE = 'FC083';
|
|
244
|
+
END IF;
|
|
245
|
+
|
|
246
|
+
UPDATE cell.effect_receipt
|
|
247
|
+
SET outcome = p_outcome,
|
|
248
|
+
remote_ref = p_remote_ref,
|
|
249
|
+
confirmed_at = p_confirmed_at
|
|
250
|
+
WHERE org_id = p_org_id AND receipt_key = p_receipt_key;
|
|
251
|
+
|
|
252
|
+
RETURN true;
|
|
253
|
+
END;
|
|
254
|
+
$confirm_receipt$;
|
|
255
|
+
|
|
256
|
+
-- ------------------------------------------- what the reconciler and the killer read
|
|
257
|
+
--
|
|
258
|
+
-- Two readers, one set. R3: this is what an `outcome_status='unknown'` is
|
|
259
|
+
-- reconciled against. R6: an attempt appearing here is one the supervisor may
|
|
260
|
+
-- NOT terminate until the receipt resolves (MID-EFFECT-HOLD, KILLED_MID_EFFECT).
|
|
261
|
+
--
|
|
262
|
+
-- The instant is an explicit argument, as everywhere else in this substrate: a
|
|
263
|
+
-- sweep reading now() cannot be asserted at a stated moment, and a leg that
|
|
264
|
+
-- cannot state its moment is a flake wearing a green tick. `claimed_at < p_as_of`
|
|
265
|
+
-- is strict, so "unresolved as of the instant it was claimed" is empty rather
|
|
266
|
+
-- than reporting an effect that had not yet been claimed when the caller looked.
|
|
267
|
+
CREATE OR REPLACE FUNCTION cell.unresolved_receipts(p_as_of timestamptz)
|
|
268
|
+
RETURNS TABLE (
|
|
269
|
+
org_id text,
|
|
270
|
+
receipt_key text,
|
|
271
|
+
work_claim_id uuid,
|
|
272
|
+
attempt_id uuid,
|
|
273
|
+
connector text,
|
|
274
|
+
address text,
|
|
275
|
+
claimed_at timestamptz
|
|
276
|
+
)
|
|
277
|
+
LANGUAGE sql
|
|
278
|
+
STABLE
|
|
279
|
+
AS $unresolved$
|
|
280
|
+
SELECT r.org_id, r.receipt_key, r.work_claim_id, r.attempt_id,
|
|
281
|
+
r.connector, r.address, r.claimed_at
|
|
282
|
+
FROM cell.effect_receipt r
|
|
283
|
+
WHERE r.outcome = 'claimed'
|
|
284
|
+
AND r.claimed_at < p_as_of
|
|
285
|
+
ORDER BY r.receipt_key;
|
|
286
|
+
$unresolved$;
|
|
287
|
+
|
|
288
|
+
COMMENT ON FUNCTION cell.unresolved_receipts IS
|
|
289
|
+
'R3 + R6: the set an unknown outcome is reconciled against, and the set whose '
|
|
290
|
+
'attempts a supervisor may not terminate until they resolve.';
|