@oathe/oathe 0.0.1 → 0.2.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 (71) hide show
  1. package/.claude-plugin/marketplace.json +14 -0
  2. package/LICENSE +202 -21
  3. package/NOTICE +7 -0
  4. package/README.md +104 -12
  5. package/assets/oathe-hero.svg +92 -0
  6. package/bin/oathe.mjs +376 -0
  7. package/docs/PRIVACY.md +45 -0
  8. package/package.json +33 -23
  9. package/plugin/.claude-plugin/plugin.json +10 -0
  10. package/plugin/.mcp.json +13 -0
  11. package/plugin/hooks/frame-note.mjs +24 -0
  12. package/plugin/hooks/heartbeat.mjs +49 -0
  13. package/plugin/hooks/hooks.json +39 -0
  14. package/plugin/hooks/lib.mjs +83 -0
  15. package/plugin/hooks/render-board.mjs +11 -0
  16. package/plugin/skills/oathe-work/SKILL.md +33 -0
  17. package/src/atif.mjs +633 -0
  18. package/src/blocks.mjs +192 -0
  19. package/src/board-render.mjs +106 -0
  20. package/src/config.mjs +169 -0
  21. package/src/context.mjs +35 -0
  22. package/src/doctor.mjs +108 -0
  23. package/src/harness.mjs +271 -0
  24. package/src/init.mjs +92 -0
  25. package/src/launch-env.mjs +25 -0
  26. package/src/launch.mjs +259 -0
  27. package/src/manifest.mjs +89 -0
  28. package/src/mcp/oathe-tools.mjs +517 -0
  29. package/src/paths.mjs +49 -0
  30. package/src/plans.mjs +50 -0
  31. package/src/runtime/discharge.mjs +57 -0
  32. package/src/runtime/provider.mjs +154 -0
  33. package/src/runtime/simple-cage.mjs +67 -0
  34. package/src/runtime/sql-acceptance-lane.mjs +89 -0
  35. package/src/session-host.mjs +81 -0
  36. package/src/substrate.mjs +337 -0
  37. package/src/successor.mjs +31 -0
  38. package/src/traces.mjs +242 -0
  39. package/src/uninstall.mjs +45 -0
  40. package/src/verifier.mjs +322 -0
  41. package/src/workspace.mjs +47 -0
  42. package/vendor/ddl/001_core.sql +312 -0
  43. package/vendor/ddl/002_claim.sql +438 -0
  44. package/vendor/ddl/003_verification.sql +480 -0
  45. package/vendor/ddl/004_delegation.sql +397 -0
  46. package/vendor/ddl/005_escalation.sql +303 -0
  47. package/vendor/ddl/006_dependency.sql +384 -0
  48. package/vendor/ddl/007_assignment.sql +502 -0
  49. package/vendor/ddl/008_effect_receipt.sql +290 -0
  50. package/vendor/ddl/009_verified_edge.sql +452 -0
  51. package/vendor/ddl/010_parent_child_verification.sql +320 -0
  52. package/vendor/ddl/011_confirm.sql +288 -0
  53. package/vendor/ddl/012_evaluator_lane.sql +444 -0
  54. package/vendor/ddl/013_claim_terminal.sql +279 -0
  55. package/vendor/ddl/014_claim_settlement.sql +327 -0
  56. package/vendor/ddl/015_claim_yield.sql +213 -0
  57. package/vendor/ddl/016_reopened_reclaim.sql +285 -0
  58. package/vendor/ddl/017_claim_yield_causes.sql +357 -0
  59. package/vendor/ddl/018_receiptless_unknown.sql +249 -0
  60. package/vendor/ddl/019_verification_contract_freeze.sql +335 -0
  61. package/vendor/ddl/020_context_compilation.sql +105 -0
  62. package/vendor/ddl/021_execution_attempt_closure.sql +95 -0
  63. package/vendor/ddl/022_verification_clause.sql +106 -0
  64. package/vendor/ddl/023_executor_role.sql +66 -0
  65. package/vendor/ddl/024_executor_role_hardening.sql +439 -0
  66. package/vendor/ddl/025_running_attempt_uniqueness.sql +102 -0
  67. package/vendor/ddl/026_acceptance_authority.sql +230 -0
  68. package/vendor/ddl/027_ownership_return.sql +836 -0
  69. package/vendor/ddl/028_attempt_bind_ownership.sql +173 -0
  70. package/vendor/ddl/manifest.json +183 -0
  71. package/index.js +0 -33
@@ -0,0 +1,452 @@
1
+ -- 009_verified_edge.sql — evaluability declared, settlement signed, failure typed.
2
+ --
3
+ -- Contract: docs/a1-cell-work-spine-contract.md §4 in full — §4.1 (evaluability
4
+ -- is a declared, substrate-visible property), §4.2 (the declare-time guard,
5
+ -- founder ruling R8), §4.3 (signer-based settlement), §4.4 (evidence-required
6
+ -- retraction, which mints no verification record), §4.5 (the registry as single
7
+ -- source of truth, written only by a governed verb), §4.6 (typed failure events,
8
+ -- each with a NAMED reader), §4.7 (dep_key validity rules).
9
+ -- Requires 001_core.sql, 003_verification.sql and 006_dependency.sql.
10
+ --
11
+ -- Re-apply: idempotent (CREATE ... IF NOT EXISTS / OR REPLACE, ON CONFLICT seeds).
12
+ -- Revert: DROP SCHEMA cell CASCADE; (this file installs nothing outside it)
13
+ --
14
+ -- FOUR MEASURED FACTS THIS FILE IS SHAPED BY
15
+ --
16
+ -- 1. **0 of the 41 `verified` edges ever declared had a pre-registered key.** So
17
+ -- on the Mac an unevaluable edge looked exactly like an evaluable one until
18
+ -- somebody went hunting for the checker that was never written. The guard
19
+ -- below therefore refuses nearly every declare at first — an honest cost the
20
+ -- ruling accepts — with one escape: an explicit acknowledgment that MINTS a
21
+ -- typed `dep_registration_debt` event naming an owner and a due date (L8).
22
+ --
23
+ -- 2. **23 historical `verified` settles bypassed the CLI by direct bus publish**
24
+ -- (12 by one principal, 11 by another), because `verified` was the only dep
25
+ -- type with a CLI gate and no substrate trigger. The signer clause here
26
+ -- checks the WRITER — a transaction-local setting only the governed verb sets
27
+ -- — and not merely the string in the settled_by column, because writing the
28
+ -- correct evaluator's name is precisely what such a publish does.
29
+ --
30
+ -- 3. **"What counts as a valid verified release" was encoded in SEVEN places**
31
+ -- plus one stale copy, and every encoding drifted. One registry, one verb.
32
+ --
33
+ -- 4. **Four silent-failure sites**: checker crash (no record at all), registry
34
+ -- unreadable (silently switched evaluation lanes), probe error (15 sites,
35
+ -- reduced to a count, then discarded entirely in continuous mode — zero log
36
+ -- lines, measured), evaluator refusal (35 events, ZERO readers). Each is a
37
+ -- typed event here, and each type must name a reader: a failure lane without
38
+ -- a reader is a contract violation (L9), so the check RAISES rather than
39
+ -- warning — nothing anywhere reported those 35 unread events as a problem.
40
+ --
41
+ -- Declared failure vocabulary added by this file (SQLSTATE class FC):
42
+ -- FC040 DEP_KEY_UNREGISTERED declared (or settled) against no checker
43
+ -- FC041 DEP_SETTLE_UNSIGNED settled by other than the registered
44
+ -- evaluator, or by a writer that is not
45
+ -- the governed verb
46
+ -- FC042 CHECKER_REGISTRY_FOREIGN_WRITER a registry edit outside the verb
47
+ -- FC043 TYPED_EVENT_WITHOUT_READER a declared failure type nothing reads
48
+ -- FC044 DEP_DECLARED_NOT_EVALUABLE a registered key left merely `declared`
49
+ -- FC045 EDGE_NOT_SETTLED a settle that matched no edge and
50
+ -- would otherwise report success
51
+
52
+ -- ---------------------------------------------------------------------------
53
+ -- checker_registry — §4.5, the single source of truth
54
+ -- ---------------------------------------------------------------------------
55
+ CREATE TABLE IF NOT EXISTS cell.checker_registry (
56
+ org_id text NOT NULL,
57
+ dep_key text NOT NULL,
58
+
59
+ -- The evaluator key is thereby EXPLICIT SETTLEMENT AUTHORITY — an accepted
60
+ -- cost of the ruling, and what makes "who released this" answerable.
61
+ evaluator_principal text NOT NULL,
62
+
63
+ checker_ref text NOT NULL,
64
+ registered_by text NOT NULL,
65
+ registered_at timestamptz NOT NULL,
66
+
67
+ CONSTRAINT checker_registry_pkey PRIMARY KEY (org_id, dep_key),
68
+
69
+ CONSTRAINT checker_registry_evaluator_is_named
70
+ CHECK (length(btrim(evaluator_principal)) > 0),
71
+ CONSTRAINT checker_registry_checker_ref_is_addressable
72
+ CHECK (length(btrim(checker_ref)) > 0)
73
+ );
74
+
75
+ COMMENT ON TABLE cell.checker_registry IS
76
+ 'Contract §4.5. One registry, one governed verb. "What counts as a valid '
77
+ 'verified release" was encoded in seven places on the Mac and every '
78
+ 'encoding drifted.';
79
+
80
+ -- Registry edits are GOVERNED operations (§4.5). Matching a `registered_by`
81
+ -- column alone would be forgeable by typing the right string, and so — MEASURED
82
+ -- in review — was the transaction-local setting this guard used to read: any
83
+ -- session could `set_config('cell.registrar', 'cell.register_checker', true)` and
84
+ -- write the registry directly. The signal is cell.written_by (002_claim.sql): the
85
+ -- verb's frame is on this trigger's call stack or it is not.
86
+ CREATE OR REPLACE FUNCTION cell.enforce_governed_registry_edit()
87
+ RETURNS trigger
88
+ LANGUAGE plpgsql
89
+ AS $governed$
90
+ BEGIN
91
+ IF NOT cell.written_by('cell.register_checker') THEN
92
+ RAISE EXCEPTION
93
+ 'CHECKER_REGISTRY_FOREIGN_WRITER:% — the checker registry is written '
94
+ 'only by cell.register_checker. A registry a service can edit directly '
95
+ 'is the eighth encoding of "what counts as a valid verified release", '
96
+ 'and the previous seven all drifted.',
97
+ NEW.dep_key
98
+ USING ERRCODE = 'FC042';
99
+ END IF;
100
+ RETURN NEW;
101
+ END;
102
+ $governed$;
103
+
104
+ CREATE OR REPLACE TRIGGER checker_registry_is_written_by_the_governed_verb
105
+ BEFORE INSERT OR UPDATE ON cell.checker_registry
106
+ FOR EACH ROW EXECUTE FUNCTION cell.enforce_governed_registry_edit();
107
+
108
+ -- ---------------------------------------------------------------------------
109
+ -- typed_event — §4.6, the four silent-failure sites made legible
110
+ --
111
+ -- Three tables, because the contract asks three separate questions: what failure
112
+ -- kinds EXIST (the vocabulary), who READS each kind (the registry L9 requires),
113
+ -- and what actually HAPPENED (the instances).
114
+ -- ---------------------------------------------------------------------------
115
+ CREATE TABLE IF NOT EXISTS cell.typed_event_type (
116
+ event_type text NOT NULL,
117
+ description text NOT NULL,
118
+
119
+ CONSTRAINT typed_event_type_pkey PRIMARY KEY (event_type)
120
+ );
121
+
122
+ CREATE TABLE IF NOT EXISTS cell.typed_event_reader (
123
+ event_type text NOT NULL,
124
+ reader text NOT NULL,
125
+ reader_kind text NOT NULL,
126
+
127
+ CONSTRAINT typed_event_reader_pkey PRIMARY KEY (event_type),
128
+
129
+ CONSTRAINT typed_event_reader_type_fkey
130
+ FOREIGN KEY (event_type) REFERENCES cell.typed_event_type (event_type),
131
+
132
+ CONSTRAINT typed_event_reader_is_named
133
+ CHECK (length(btrim(reader)) > 0),
134
+
135
+ CONSTRAINT typed_event_reader_kind_is_declared
136
+ CHECK (reader_kind IN ('operator_surface', 'monitor'))
137
+ );
138
+
139
+ CREATE TABLE IF NOT EXISTS cell.typed_event (
140
+ event_id uuid NOT NULL,
141
+ org_id text NOT NULL,
142
+ event_type text NOT NULL,
143
+ dep_key text NOT NULL,
144
+ detail jsonb NOT NULL,
145
+ ts timestamptz NOT NULL,
146
+
147
+ CONSTRAINT typed_event_pkey PRIMARY KEY (event_id),
148
+
149
+ CONSTRAINT typed_event_type_fkey
150
+ FOREIGN KEY (event_type) REFERENCES cell.typed_event_type (event_type),
151
+
152
+ CONSTRAINT typed_event_detail_is_an_object
153
+ CHECK (jsonb_typeof(detail) = 'object')
154
+ );
155
+
156
+ CREATE INDEX IF NOT EXISTS typed_event_by_type
157
+ ON cell.typed_event (org_id, event_type, ts);
158
+
159
+ -- The vocabulary: the four measured silent-failure sites, plus the debt event
160
+ -- the acknowledgment path mints.
161
+ INSERT INTO cell.typed_event_type (event_type, description) VALUES
162
+ ('checker_crash',
163
+ 'a registered checker exited non-zero; on the Mac this left NO record at all'),
164
+ ('registry_unreadable',
165
+ 'the registry could not be read; on the Mac this silently switched evaluation lanes'),
166
+ ('probe_error',
167
+ 'an evaluation probe failed; on the Mac 15 accumulation sites reduced these to a count, then discarded it entirely in continuous mode'),
168
+ ('evaluator_refusal',
169
+ 'the evaluator declined to sign; on the Mac 35 such events were written and ZERO were ever read'),
170
+ ('dep_registration_debt',
171
+ 'a verified edge was declared against an unregistered key with an explicit acknowledgment naming an owner and a due date (L8)')
172
+ ON CONFLICT (event_type) DO UPDATE SET description = EXCLUDED.description;
173
+
174
+ -- The readers §4.6 names: the operator surface routed in §3.4(4), and the
175
+ -- completed-but-unsettled age monitor — plus a due-date monitor for the debt,
176
+ -- because a dated bridge with no reader of its due date has no dated end at all.
177
+ INSERT INTO cell.typed_event_reader (event_type, reader, reader_kind) VALUES
178
+ ('checker_crash', 'operator_surface.bus_to_messaging', 'operator_surface'),
179
+ ('registry_unreadable', 'operator_surface.bus_to_messaging', 'operator_surface'),
180
+ ('probe_error', 'operator_surface.bus_to_messaging', 'operator_surface'),
181
+ ('evaluator_refusal', 'monitor.completed_but_unsettled_age', 'monitor'),
182
+ ('dep_registration_debt', 'monitor.registration_debt_due', 'monitor')
183
+ ON CONFLICT (event_type) DO UPDATE
184
+ SET reader = EXCLUDED.reader, reader_kind = EXCLUDED.reader_kind;
185
+
186
+ -- The H28 check: every detection path pairs a NAMED reader. It RAISES rather
187
+ -- than returning a verdict, because a warning is what the Mac's 35 unread
188
+ -- evaluator-refusal events effectively got.
189
+ CREATE OR REPLACE FUNCTION cell.assert_every_typed_event_has_a_reader()
190
+ RETURNS integer
191
+ LANGUAGE plpgsql
192
+ STABLE
193
+ AS $reader_check$
194
+ DECLARE
195
+ v_unpaired text;
196
+ v_total integer;
197
+ BEGIN
198
+ SELECT string_agg(t.event_type, ', ' ORDER BY t.event_type) INTO v_unpaired
199
+ FROM cell.typed_event_type t
200
+ WHERE NOT EXISTS (SELECT 1 FROM cell.typed_event_reader r
201
+ WHERE r.event_type = t.event_type);
202
+
203
+ IF v_unpaired IS NOT NULL THEN
204
+ RAISE EXCEPTION
205
+ 'TYPED_EVENT_WITHOUT_READER:% — these failure types are declared and '
206
+ 'nothing reads them. A failure lane without a reader is a contract '
207
+ 'violation (L9): the Mac wrote 35 evaluator-refusal events that no '
208
+ 'consumer ever read, and nothing anywhere reported that as a problem.',
209
+ v_unpaired
210
+ USING ERRCODE = 'FC043';
211
+ END IF;
212
+
213
+ SELECT count(*)::integer INTO v_total FROM cell.typed_event_type;
214
+ RETURN v_total;
215
+ END;
216
+ $reader_check$;
217
+
218
+ -- ------------------------------------- §4.2 the declare-time evaluability guard
219
+ --
220
+ -- Fail-closed, per the estate's own guard doctrine (migrations 0073/0081).
221
+ -- Declaring a `verified` edge whose dep_key matches no registered checker FAILS
222
+ -- loudly, unless the declarer acknowledges the debt — which mints the typed
223
+ -- event naming its owner and due date, rather than passing silently.
224
+ --
225
+ -- The same guard runs on the transition INTO `evaluable`, so a debt cannot be
226
+ -- discharged by editing a column: evaluability is a declared, substrate-visible
227
+ -- property (§4.1) and the registry is what confers it.
228
+ CREATE OR REPLACE FUNCTION cell.enforce_declare_time_evaluability()
229
+ RETURNS trigger
230
+ LANGUAGE plpgsql
231
+ AS $evaluability$
232
+ DECLARE
233
+ v_evaluator text;
234
+ BEGIN
235
+ IF NEW.dep_type <> 'verified' THEN
236
+ RETURN NEW;
237
+ END IF;
238
+ -- Only a DECLARE, or a transition into evaluable, is guarded. Re-stating an
239
+ -- unchanged state must not fail for a reason unrelated to what changed.
240
+ IF TG_OP = 'UPDATE' AND NOT (NEW.state = 'evaluable' AND OLD.state <> 'evaluable') THEN
241
+ RETURN NEW;
242
+ END IF;
243
+
244
+ SELECT evaluator_principal INTO v_evaluator
245
+ FROM cell.checker_registry
246
+ WHERE org_id = NEW.org_id AND dep_key = NEW.dep_key;
247
+
248
+ IF FOUND THEN
249
+ IF NEW.state NOT IN ('evaluable', 'satisfied', 'retracted',
250
+ 'evaluation_blocked') THEN
251
+ RAISE EXCEPTION
252
+ 'DEP_DECLARED_NOT_EVALUABLE:% — a checker IS registered for this '
253
+ 'key (evaluator %), so the edge is EVALUABLE and must say so. '
254
+ 'Leaving it in ''%'' hides an evaluable edge among the unevaluable '
255
+ 'ones, and §4.1''s alerting keys on the state.',
256
+ NEW.dep_key, v_evaluator, NEW.state
257
+ USING ERRCODE = 'FC044';
258
+ END IF;
259
+ RETURN NEW;
260
+ END IF;
261
+
262
+ IF NEW.state <> 'debt_acked' THEN
263
+ RAISE EXCEPTION
264
+ 'DEP_KEY_UNREGISTERED:% — no checker is registered for this dep_key, so '
265
+ 'this edge is not evaluable and declaring it as though it were mints a '
266
+ 'wait nothing can ever release. MEASURED: 0 of the 41 `verified` edges '
267
+ 'ever declared had a pre-registered key. Acknowledge the registration '
268
+ 'debt explicitly (state ''debt_acked'' with an owner and a due date) or '
269
+ 'register a checker first.',
270
+ NEW.dep_key
271
+ USING ERRCODE = 'FC040';
272
+ END IF;
273
+
274
+ -- The acknowledgment is not a shrug: it MINTS the typed debt event, naming
275
+ -- the owner and the due date, so L8's "every bridge has a dated end" is a row
276
+ -- a monitor reads rather than a sentence in a commit message.
277
+ INSERT INTO cell.typed_event (event_id, org_id, event_type, dep_key, detail, ts)
278
+ VALUES (gen_random_uuid(), NEW.org_id, 'dep_registration_debt', NEW.dep_key,
279
+ jsonb_build_object(
280
+ 'owner', NEW.debt_owner,
281
+ -- Rendered explicitly in UTC rather than let jsonb_build_object
282
+ -- take the writer's session TimeZone: a due date whose text
283
+ -- depends on who reads it is a due date two readers disagree
284
+ -- about, and L8's dated end has to be one date.
285
+ 'due', to_char(NEW.debt_due AT TIME ZONE 'UTC',
286
+ 'YYYY-MM-DD"T"HH24:MI:SS"Z"'),
287
+ 'edge_id', NEW.edge_id,
288
+ 'declared_by', NEW.declared_by),
289
+ NEW.declared_at);
290
+
291
+ RETURN NEW;
292
+ END;
293
+ $evaluability$;
294
+
295
+ CREATE OR REPLACE TRIGGER dep_edge_declare_time_evaluability_guard
296
+ BEFORE INSERT OR UPDATE ON cell.dep_edge
297
+ FOR EACH ROW EXECUTE FUNCTION cell.enforce_declare_time_evaluability();
298
+
299
+ -- --------------------------------------------- §4.3 the signer clause
300
+ --
301
+ -- This is the one filesystem-free substrate clause that closes every
302
+ -- direct-publish bypass. Two things must hold, and the second is the one the
303
+ -- Mac lacked: the settled_by column names the registered evaluator, AND the
304
+ -- writer is the governed verb. Checking only the column would leave the rule
305
+ -- satisfiable by typing the right name, which is exactly what a direct bus
306
+ -- publish does.
307
+ CREATE OR REPLACE FUNCTION cell.enforce_verified_edge_signer()
308
+ RETURNS trigger
309
+ LANGUAGE plpgsql
310
+ AS $signer$
311
+ DECLARE
312
+ v_evaluator text;
313
+ v_writer text;
314
+ BEGIN
315
+ IF NEW.dep_type <> 'verified' OR NEW.state IS DISTINCT FROM 'satisfied' THEN
316
+ RETURN NEW;
317
+ END IF;
318
+ IF TG_OP = 'UPDATE' AND OLD.state = 'satisfied' THEN
319
+ RETURN NEW;
320
+ END IF;
321
+
322
+ SELECT evaluator_principal INTO v_evaluator
323
+ FROM cell.checker_registry
324
+ WHERE org_id = NEW.org_id AND dep_key = NEW.dep_key;
325
+
326
+ IF NOT FOUND THEN
327
+ RAISE EXCEPTION
328
+ 'DEP_KEY_UNREGISTERED:% — no checker is registered for this dep_key, so '
329
+ 'there is no evaluator whose signature could release it. An '
330
+ 'acknowledged registration debt buys time to write a checker; it does '
331
+ 'not buy the ability to release without one.',
332
+ NEW.dep_key
333
+ USING ERRCODE = 'FC040';
334
+ END IF;
335
+
336
+ -- The WRITER, read off the call stack rather than off a setting the writer
337
+ -- could have set for itself. `v_writer` carries the evaluator's name only
338
+ -- when the governed verb is genuinely on the stack, so the refusal below
339
+ -- still prints what it found.
340
+ IF cell.written_by('cell.settle_verified_edge') THEN
341
+ v_writer := v_evaluator;
342
+ ELSE
343
+ v_writer := NULL;
344
+ END IF;
345
+
346
+ IF NEW.settled_by IS DISTINCT FROM v_evaluator OR v_writer IS DISTINCT FROM v_evaluator THEN
347
+ RAISE EXCEPTION
348
+ 'DEP_SETTLE_UNSIGNED:% — a `verified` dep_satisfied is valid only when '
349
+ 'signed by the REGISTERED evaluator (%) through cell.settle_verified_edge. '
350
+ 'This row names % and was written by %. MEASURED: 23 historical '
351
+ '`verified` settles reached the bus by direct publish past a CLI-only '
352
+ 'gate, which is why the writer is checked and not only the column — and '
353
+ 'the writer signal is the PL/pgSQL call stack, which a direct writer '
354
+ 'cannot fabricate, rather than a setting it could set for itself.',
355
+ NEW.dep_key, v_evaluator, coalesce(NEW.settled_by, '<null>'),
356
+ coalesce(v_writer, '<a writer that is not the governed verb>')
357
+ USING ERRCODE = 'FC041';
358
+ END IF;
359
+
360
+ RETURN NEW;
361
+ END;
362
+ $signer$;
363
+
364
+ CREATE OR REPLACE TRIGGER dep_edge_verified_settlement_is_signed
365
+ BEFORE INSERT OR UPDATE ON cell.dep_edge
366
+ FOR EACH ROW EXECUTE FUNCTION cell.enforce_verified_edge_signer();
367
+
368
+ -- ------------------------------------------------------------- the two verbs
369
+ --
370
+ -- Every argument is required; there is no default in either signature and there
371
+ -- will not be one. A default registrar, a default evaluator or a server-chosen
372
+ -- timestamp would each be a governance decision made in the substrate, invisible
373
+ -- at the call site.
374
+ CREATE OR REPLACE FUNCTION cell.register_checker(
375
+ p_org_id text,
376
+ p_dep_key text,
377
+ p_evaluator_principal text,
378
+ p_checker_ref text,
379
+ p_registered_by text,
380
+ p_registered_at timestamptz
381
+ )
382
+ RETURNS text
383
+ LANGUAGE plpgsql
384
+ AS $register$
385
+ BEGIN
386
+ -- Nothing is set to authorize this write: THIS frame, on the call stack, is
387
+ -- the authorization, and it stops existing when the function returns.
388
+ INSERT INTO cell.checker_registry (
389
+ org_id, dep_key, evaluator_principal, checker_ref, registered_by,
390
+ registered_at
391
+ ) VALUES (
392
+ p_org_id, p_dep_key, p_evaluator_principal, p_checker_ref, p_registered_by,
393
+ p_registered_at
394
+ )
395
+ ON CONFLICT (org_id, dep_key) DO UPDATE
396
+ SET evaluator_principal = EXCLUDED.evaluator_principal,
397
+ checker_ref = EXCLUDED.checker_ref,
398
+ registered_by = EXCLUDED.registered_by,
399
+ registered_at = EXCLUDED.registered_at;
400
+
401
+ RETURN p_dep_key;
402
+ END;
403
+ $register$;
404
+
405
+ COMMENT ON FUNCTION cell.register_checker IS
406
+ 'Contract §4.5''s governed register verb — the only writer of the checker '
407
+ 'registry, and therefore the only way a dep_key becomes evaluable.';
408
+
409
+ CREATE OR REPLACE FUNCTION cell.settle_verified_edge(
410
+ p_edge_id uuid,
411
+ p_evaluator_principal text,
412
+ p_settled_at timestamptz
413
+ )
414
+ RETURNS uuid
415
+ LANGUAGE plpgsql
416
+ AS $settle$
417
+ DECLARE
418
+ v_settled integer;
419
+ BEGIN
420
+ -- Nothing is set to authorize this write: THIS frame, on the call stack, is
421
+ -- what cell.enforce_verified_edge_signer reads, and it stops existing when
422
+ -- the function returns.
423
+ UPDATE cell.dep_edge
424
+ SET state = 'satisfied',
425
+ settled_by = p_evaluator_principal,
426
+ settle_kind = 'evaluator_verdict',
427
+ settled_at = p_settled_at
428
+ WHERE edge_id = p_edge_id;
429
+
430
+ GET DIAGNOSTICS v_settled = ROW_COUNT;
431
+
432
+ -- An UPDATE that matched nothing runs the trigger not at all, so without this
433
+ -- the verb returned p_edge_id — the identifier of an edge it did not settle —
434
+ -- and a caller checking the returned id against the one it asked for would
435
+ -- read success. An error that looks like success is the one answer a
436
+ -- release-path verb may never give.
437
+ IF v_settled <> 1 THEN
438
+ RAISE EXCEPTION
439
+ 'EDGE_NOT_SETTLED:%:% — this settle matched % edges, not exactly one, '
440
+ 'so nothing was released and there is no edge whose release this call '
441
+ 'could be evidence of.',
442
+ p_edge_id, p_evaluator_principal, v_settled
443
+ USING ERRCODE = 'FC045';
444
+ END IF;
445
+
446
+ RETURN p_edge_id;
447
+ END;
448
+ $settle$;
449
+
450
+ COMMENT ON FUNCTION cell.settle_verified_edge IS
451
+ 'Contract §4.3. The signer clause is enforced by the trigger, not here: a '
452
+ 'check that lives only in this function is a check a direct UPDATE skips.';