@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,335 @@
1
+ -- 019_verification_contract_freeze.sql — the verification contract is FROZEN at
2
+ -- claim time, and the live plan equals the bound contract by construction.
3
+ --
4
+ -- Contract: A3 worksheet §7 (acceptance lane) + a3-verification-strategy.md §3.2
5
+ -- row ACC-CONTRACT-FROZEN. Verification report 3 (a3-founder-rulings.md) MEASURED
6
+ -- the defect this closes: judgment currently FLOATS on the mutable live plan —
7
+ -- `cell.task.verification_plan` can be edited directly under an active claim, so
8
+ -- the bar a claim was accepted against and the bar it is settled against are two
9
+ -- different objects, and nothing records the change. That is the AC-01-drift /
10
+ -- bar-lowering class (strategy §5). Requires 001_core.sql, 002_claim.sql (the
11
+ -- `cell.written_by` writer signal) and 009_verified_edge.sql (the typed-event
12
+ -- vocabulary + reader registry the CONTRACT_CHANGED event registers into).
13
+ --
14
+ -- Re-apply: idempotent (CREATE ... IF NOT EXISTS / OR REPLACE; ON CONFLICT seed).
15
+ -- Revert: DROP FUNCTION cell.amend_verification_contract(text,text,jsonb,timestamptz,uuid,text);
16
+ -- DROP FUNCTION cell.contract_drift(); DROP VIEW cell.v_contract_parity;
17
+ -- DROP TRIGGER task_verification_contract_is_frozen ON cell.task;
18
+ -- DROP TRIGGER work_claim_freezes_its_contract ON cell.work_claim;
19
+ -- DROP FUNCTION cell.enforce_verification_contract_frozen();
20
+ -- DROP FUNCTION cell.freeze_verification_contract();
21
+ -- DROP FUNCTION cell.hash_verification_contract(jsonb);
22
+ -- DROP TABLE cell.verification_contract;
23
+ -- DELETE FROM cell.typed_event_reader WHERE event_type='contract_changed';
24
+ -- DELETE FROM cell.typed_event_type WHERE event_type='contract_changed';
25
+ --
26
+ -- Declared failure vocabulary (SQLSTATE class FC; this lane reserves FC160-FC169):
27
+ -- FC160 CONTRACT_FROZEN_UNDER_CLAIM a direct verification_plan edit under an
28
+ -- active claim, by any writer but the one
29
+ -- typed amend verb
30
+ -- FC161 CONTRACT_AMEND_NO_ACTIVE_CLAIM the amend verb called on work no
31
+ -- principal currently holds — where the
32
+ -- plan is freely mutable and needs no verb
33
+
34
+ -- ---------------------------------------------------------------------------
35
+ -- the canonical hash of a verification contract
36
+ --
37
+ -- The contract IS the task's verification_plan (its clauses and their status).
38
+ -- jsonb text output is canonical in Postgres — keys sorted, no insignificant
39
+ -- whitespace — so md5(plan::text) is a stable fingerprint that does not depend on
40
+ -- how the plan was spelled at the call site. IMMUTABLE so it may sit in a view's
41
+ -- WHERE and in an index later without re-evaluation surprises.
42
+ -- ---------------------------------------------------------------------------
43
+ CREATE OR REPLACE FUNCTION cell.hash_verification_contract(p_plan jsonb)
44
+ RETURNS text
45
+ LANGUAGE sql
46
+ IMMUTABLE
47
+ AS $hash$
48
+ SELECT md5(p_plan::text);
49
+ $hash$;
50
+
51
+ COMMENT ON FUNCTION cell.hash_verification_contract IS
52
+ 'The canonical fingerprint of a verification contract: md5 over the jsonb '
53
+ 'canonical text of the plan. The claim binds this hash; the parity check '
54
+ 'reads it back against the live plan.';
55
+
56
+ -- ---------------------------------------------------------------------------
57
+ -- verification_contract — the bar a claim was accepted against, bound at claim
58
+ -- time. One row per work_claim: the interval of responsibility and the contract
59
+ -- it answers to are the same lifetime.
60
+ --
61
+ -- This is a BINDING, not a second settlement authority: nothing reads it to
62
+ -- decide completion (that is still v_task_completion over the live plan). What it
63
+ -- exists for is to make the sentence "the live plan still equals the bound
64
+ -- contract" a mechanical fact the parity check can read, instead of a hope.
65
+ -- ---------------------------------------------------------------------------
66
+ CREATE TABLE IF NOT EXISTS cell.verification_contract (
67
+ work_claim_id uuid NOT NULL,
68
+ org_id text NOT NULL,
69
+ task_id text NOT NULL,
70
+
71
+ -- The hash bound at claim time (or re-bound by an amend). Non-empty by
72
+ -- construction: md5 is 32 hex chars, and a blank hash would make the parity
73
+ -- check compare a value against nothing.
74
+ contract_hash text NOT NULL,
75
+
76
+ -- The exact plan the hash was taken over, kept so an amend's before/after is
77
+ -- addressable and a parity failure can show WHAT drifted, not only that it did.
78
+ plan_snapshot jsonb NOT NULL,
79
+
80
+ frozen_at timestamptz NOT NULL,
81
+
82
+ CONSTRAINT verification_contract_pkey PRIMARY KEY (work_claim_id),
83
+
84
+ CONSTRAINT verification_contract_claim_fkey
85
+ FOREIGN KEY (org_id, work_claim_id)
86
+ REFERENCES cell.work_claim (org_id, work_claim_id),
87
+
88
+ CONSTRAINT verification_contract_task_fkey
89
+ FOREIGN KEY (org_id, task_id) REFERENCES cell.task (org_id, task_id),
90
+
91
+ CONSTRAINT verification_contract_hash_is_addressable
92
+ CHECK (length(btrim(contract_hash)) > 0),
93
+
94
+ CONSTRAINT verification_contract_snapshot_is_an_object
95
+ CHECK (jsonb_typeof(plan_snapshot) = 'object')
96
+ );
97
+
98
+ COMMENT ON TABLE cell.verification_contract IS
99
+ 'The verification contract bound to a work_claim at claim time. A binding '
100
+ 'the parity check reads, never a settlement authority — completion is still '
101
+ 'derived from the live plan by v_task_completion.';
102
+
103
+ -- ------------------------------------------------ the freeze, at claim time
104
+ --
105
+ -- Fires in the SAME transaction as the claim (cell.claim_work INSERTs the claim
106
+ -- row; this AFTER INSERT trigger runs before that transaction commits), so a
107
+ -- claim and its bound contract appear together or not at all — the split-brain of
108
+ -- a claim with no bound bar is impossible by construction. Only an ACTIVE claim
109
+ -- binds a contract: a terminal claim row (a takeover record, an expiry) is not a
110
+ -- live interval of responsibility and has no bar to answer to.
111
+ CREATE OR REPLACE FUNCTION cell.freeze_verification_contract()
112
+ RETURNS trigger
113
+ LANGUAGE plpgsql
114
+ AS $freeze$
115
+ DECLARE
116
+ v_plan jsonb;
117
+ BEGIN
118
+ SELECT verification_plan INTO v_plan
119
+ FROM cell.task
120
+ WHERE org_id = NEW.org_id AND task_id = NEW.task_id;
121
+
122
+ -- The claim's own FK to cell.task guarantees the task exists; if it somehow
123
+ -- does not, the claim insert itself fails on that FK and this trigger never
124
+ -- reached a commit anyway.
125
+ INSERT INTO cell.verification_contract (
126
+ work_claim_id, org_id, task_id, contract_hash, plan_snapshot, frozen_at
127
+ ) VALUES (
128
+ NEW.work_claim_id, NEW.org_id, NEW.task_id,
129
+ cell.hash_verification_contract(v_plan), v_plan, NEW.claimed_at
130
+ );
131
+
132
+ RETURN NEW;
133
+ END;
134
+ $freeze$;
135
+
136
+ CREATE OR REPLACE TRIGGER work_claim_freezes_its_contract
137
+ AFTER INSERT ON cell.work_claim
138
+ FOR EACH ROW WHEN (NEW.state = 'active')
139
+ EXECUTE FUNCTION cell.freeze_verification_contract();
140
+
141
+ -- ------------------------------------------------ the freeze, enforced
142
+ --
143
+ -- A direct UPDATE of the plan under an active claim is refused for EVERY writer
144
+ -- but the one typed amend verb — the same call-stack writer signal the claim and
145
+ -- evaluator lanes already use (002_claim.sql cell.written_by), so a service that
146
+ -- learned the table name cannot lower the bar by typing an UPDATE, and cannot
147
+ -- forge the amend frame without CREATE on schema cell (owner authority).
148
+ --
149
+ -- Scoped to a plan CHANGE: objective, origin, assignment and every other column
150
+ -- of cell.task stay freely updatable (the evaluator-seat suite asserts exactly
151
+ -- that). A guard on the whole row would break the assignment lane for a reason
152
+ -- that has nothing to do with the contract.
153
+ CREATE OR REPLACE FUNCTION cell.enforce_verification_contract_frozen()
154
+ RETURNS trigger
155
+ LANGUAGE plpgsql
156
+ AS $frozen$
157
+ BEGIN
158
+ -- Only a plan change is a contract change. IS NOT DISTINCT FROM handles the
159
+ -- jsonb NULL cases the way '=' cannot.
160
+ IF NEW.verification_plan IS NOT DISTINCT FROM OLD.verification_plan THEN
161
+ RETURN NEW;
162
+ END IF;
163
+
164
+ IF EXISTS (SELECT 1 FROM cell.work_claim
165
+ WHERE org_id = NEW.org_id
166
+ AND task_id = NEW.task_id
167
+ AND state = 'active')
168
+ AND NOT cell.written_by('cell.amend_verification_contract') THEN
169
+ RAISE EXCEPTION
170
+ 'CONTRACT_FROZEN_UNDER_CLAIM:%/% — the verification contract is bound '
171
+ 'to the active claim on this work, and a direct edit of the plan would '
172
+ 'settle the claim against a bar different from the one it was accepted '
173
+ 'against with nothing recorded (the AC-01 / bar-lowering class). Lower '
174
+ 'or change the bar through cell.amend_verification_contract, which '
175
+ 're-binds the contract and emits CONTRACT_CHANGED so the change is '
176
+ 'visible, never silent.',
177
+ NEW.org_id, NEW.task_id
178
+ USING ERRCODE = 'FC160';
179
+ END IF;
180
+
181
+ RETURN NEW;
182
+ END;
183
+ $frozen$;
184
+
185
+ CREATE OR REPLACE TRIGGER task_verification_contract_is_frozen
186
+ BEFORE UPDATE ON cell.task
187
+ FOR EACH ROW EXECUTE FUNCTION cell.enforce_verification_contract_frozen();
188
+
189
+ -- ------------------------------------------------ the ONE amendment verb
190
+ --
191
+ -- The only lawful way to change the bar under an active claim. It re-binds the
192
+ -- contract (so the live plan and the bound hash stay equal by construction) and
193
+ -- emits a typed CONTRACT_CHANGED event with a named reader, so bar-lowering is a
194
+ -- fact on a lane a monitor reads rather than an invisible UPDATE.
195
+ CREATE OR REPLACE FUNCTION cell.amend_verification_contract(
196
+ p_org_id text,
197
+ p_task_id text,
198
+ p_new_plan jsonb,
199
+ p_amended_at timestamptz,
200
+ p_event_id uuid,
201
+ p_reason text
202
+ )
203
+ RETURNS text
204
+ LANGUAGE plpgsql
205
+ AS $amend$
206
+ DECLARE
207
+ v_claim uuid;
208
+ v_old_plan jsonb;
209
+ v_old_hash text;
210
+ v_new_hash text;
211
+ BEGIN
212
+ -- Lock the task row: an amend and a competing claim terminal serialize here,
213
+ -- the same discipline cell.claim_work uses.
214
+ SELECT verification_plan INTO v_old_plan
215
+ FROM cell.task
216
+ WHERE org_id = p_org_id AND task_id = p_task_id
217
+ FOR UPDATE;
218
+
219
+ IF NOT FOUND THEN
220
+ RAISE EXCEPTION
221
+ 'CONTRACT_AMEND_NO_ACTIVE_CLAIM:%/% — no task by that identity exists.',
222
+ p_org_id, p_task_id
223
+ USING ERRCODE = 'FC161';
224
+ END IF;
225
+
226
+ SELECT work_claim_id INTO v_claim
227
+ FROM cell.work_claim
228
+ WHERE org_id = p_org_id AND task_id = p_task_id AND state = 'active';
229
+
230
+ IF NOT FOUND THEN
231
+ RAISE EXCEPTION
232
+ 'CONTRACT_AMEND_NO_ACTIVE_CLAIM:%/% — no principal holds an active '
233
+ 'claim on this work, so there is no bound contract to amend and the '
234
+ 'plan is freely mutable. This verb exists only for the frozen window; '
235
+ 'edit the plan directly when nobody is responsible for the work.',
236
+ p_org_id, p_task_id
237
+ USING ERRCODE = 'FC161';
238
+ END IF;
239
+
240
+ v_old_hash := cell.hash_verification_contract(v_old_plan);
241
+ v_new_hash := cell.hash_verification_contract(p_new_plan);
242
+
243
+ -- The plan edit. This frame is on the call stack, so the freeze guard admits
244
+ -- it and refuses everyone else.
245
+ UPDATE cell.task
246
+ SET verification_plan = p_new_plan
247
+ WHERE org_id = p_org_id AND task_id = p_task_id;
248
+
249
+ -- Re-bind: the live plan and the bound hash are equal again by construction.
250
+ UPDATE cell.verification_contract
251
+ SET contract_hash = v_new_hash,
252
+ plan_snapshot = p_new_plan,
253
+ frozen_at = p_amended_at
254
+ WHERE work_claim_id = v_claim;
255
+
256
+ -- The change, on a lane a named reader consumes (L9).
257
+ INSERT INTO cell.typed_event (event_id, org_id, event_type, dep_key, detail, ts)
258
+ VALUES (p_event_id, p_org_id, 'contract_changed', p_task_id,
259
+ jsonb_build_object('work_claim_id', v_claim,
260
+ 'old_hash', v_old_hash,
261
+ 'new_hash', v_new_hash,
262
+ 'reason', p_reason),
263
+ p_amended_at);
264
+
265
+ RETURN v_new_hash;
266
+ END;
267
+ $amend$;
268
+
269
+ COMMENT ON FUNCTION cell.amend_verification_contract IS
270
+ 'The one verb that changes the verification bar under an active claim: '
271
+ 're-binds the frozen contract and emits CONTRACT_CHANGED. Bar-lowering is '
272
+ 'visible on a monitored lane, never a silent UPDATE (the AC-01 class).';
273
+
274
+ -- The CONTRACT_CHANGED lane, declared into the §4.6 typed-event vocabulary with
275
+ -- a NAMED reader — the H28 assertion (cell.assert_every_typed_event_has_a_reader)
276
+ -- refuses a declared type nothing reads.
277
+ INSERT INTO cell.typed_event_type (event_type, description) VALUES
278
+ ('contract_changed',
279
+ 'the verification contract was amended under an active claim via cell.amend_verification_contract; bar-lowering is a visible fact on this lane, never a silent plan UPDATE (the AC-01 / bar-lowering class)')
280
+ ON CONFLICT (event_type) DO UPDATE SET description = EXCLUDED.description;
281
+
282
+ INSERT INTO cell.typed_event_reader (event_type, reader, reader_kind) VALUES
283
+ ('contract_changed', 'monitor.contract_change_audit', 'monitor')
284
+ ON CONFLICT (event_type) DO UPDATE
285
+ SET reader = EXCLUDED.reader, reader_kind = EXCLUDED.reader_kind;
286
+
287
+ -- ------------------------------------------------ the standing parity check
288
+ --
289
+ -- The live plan equals the bound contract for every active claim — the invariant
290
+ -- ACC-CONTRACT-FROZEN asserts holds BY CONSTRUCTION. Every row this returns is a
291
+ -- red: either an active claim whose frozen contract hash no longer matches its
292
+ -- task's live plan (a plan changed out from under the bar), or an active claim
293
+ -- with no bound contract at all (a claim that never froze). Both are impossible
294
+ -- while the trigger and verb above are installed and enabled; the check exists to
295
+ -- MEASURE that, exactly as cell.unverified_past_verify_by measures the R2 clock.
296
+ CREATE OR REPLACE VIEW cell.v_contract_parity AS
297
+ SELECT
298
+ c.org_id,
299
+ c.task_id,
300
+ c.work_claim_id,
301
+ f.contract_hash AS bound_hash,
302
+ cell.hash_verification_contract(t.verification_plan) AS live_hash,
303
+ CASE
304
+ WHEN f.work_claim_id IS NULL THEN 'unbound'
305
+ WHEN f.contract_hash IS DISTINCT FROM
306
+ cell.hash_verification_contract(t.verification_plan) THEN 'drifted'
307
+ ELSE 'bound'
308
+ END AS parity
309
+ FROM cell.work_claim c
310
+ JOIN cell.task t
311
+ ON t.org_id = c.org_id AND t.task_id = c.task_id
312
+ LEFT JOIN cell.verification_contract f
313
+ ON f.work_claim_id = c.work_claim_id
314
+ WHERE c.state = 'active';
315
+
316
+ CREATE OR REPLACE FUNCTION cell.contract_drift()
317
+ RETURNS TABLE (
318
+ org_id text,
319
+ task_id text,
320
+ work_claim_id uuid,
321
+ parity text
322
+ )
323
+ LANGUAGE sql
324
+ STABLE
325
+ AS $drift$
326
+ SELECT p.org_id, p.task_id, p.work_claim_id, p.parity
327
+ FROM cell.v_contract_parity p
328
+ WHERE p.parity <> 'bound'
329
+ ORDER BY p.task_id, p.work_claim_id;
330
+ $drift$;
331
+
332
+ COMMENT ON FUNCTION cell.contract_drift IS
333
+ 'ACC-CONTRACT-FROZEN: every row is RED — an active claim whose bound contract '
334
+ 'no longer equals its live plan, or one with no bound contract at all. Empty '
335
+ 'by construction while the freeze trigger and amend verb are installed.';
@@ -0,0 +1,105 @@
1
+ -- 020_context_compilation.sql — the ContextCompilation provenance record.
2
+ --
3
+ -- Contract: R-A3-5 (FOUNDER RULING 2026-08-20 — "Context is disposable, context
4
+ -- compilation is reproducible, and company state is authoritative"; the
5
+ -- ContextCompilation first-class object) + R-A3-6 point 4/5, worksheet §7,
6
+ -- a3-verification-strategy.md §3.3 rows CTX-PROVENANCE / CTX-FRONTIER /
7
+ -- CTX-ARTIFACT / CTX-BUDGET. Requires 001_core.sql.
8
+ --
9
+ -- Re-apply: idempotent (CREATE ... IF NOT EXISTS throughout).
10
+ -- Revert: DROP TABLE cell.context_compilation;
11
+ --
12
+ -- WHY THIS TABLE HOLDS NO LOAD-BEARING FK
13
+ --
14
+ -- A ContextCompilation answers "what did the agent know when it decided?" — it is
15
+ -- FOOTAGE, an evidence asset (L14), not a second authority for settlement. So it
16
+ -- carries its subject identifiers as plain columns and NOT as foreign keys into
17
+ -- the work spine: a compilation row must never be able to block a claim from
18
+ -- settling, and a settlement path must never wait on a provenance write. The
19
+ -- attempt row references a compilation by id (021), but that reference is itself
20
+ -- nullable and non-load-bearing — the spine settles whether or not the footage
21
+ -- was captured, and a MISSING compilation is a red the CTX-* falsifiers read, not
22
+ -- a constraint that stops the company from working.
23
+
24
+ CREATE TABLE IF NOT EXISTS cell.context_compilation (
25
+ compilation_id uuid NOT NULL,
26
+ org_id text NOT NULL,
27
+
28
+ -- The subject of the compilation, as plain (non-FK) identifiers — the work
29
+ -- claim it was compiled for, and optionally the principal and decision. A
30
+ -- soft reference on purpose (see header): footage names its subject without
31
+ -- becoming load-bearing for it.
32
+ work_claim_id uuid NOT NULL,
33
+ principal_id text NOT NULL,
34
+ decision_id text,
35
+
36
+ objective text NOT NULL,
37
+
38
+ -- INITIAL | DELTA | RECONCILE | RECOMPILE — the three continuity mechanisms
39
+ -- R-A3-5 names (resume→DELTA, compact→RECONCILE, fresh→RECOMPILE) plus the
40
+ -- first allocation. CTX-RECOMPILE/-DELTA/-RECONCILE assert the SessionStart
41
+ -- source-router recorded which one produced this package.
42
+ mode text NOT NULL,
43
+
44
+ compiled_at timestamptz NOT NULL,
45
+
46
+ -- CTX-PROVENANCE: per-source refs AND hashes, so the package can be traced
47
+ -- back to exactly which company-state reads produced it. An object keyed by
48
+ -- source name; each value carries the ref(s) consulted and their hash.
49
+ source_refs jsonb NOT NULL,
50
+
51
+ -- CTX-FRONTIER: the per-source frontier, valid_at vs known_at PRESERVED — a
52
+ -- projection claiming currency without declaring the instant it is current AS
53
+ -- OF and the instant it was KNOWN AS OF is a hindsight leak waiting to happen.
54
+ -- Candidate PRD law (staged A3.1): derived state declares its source frontier.
55
+ source_frontier jsonb NOT NULL,
56
+
57
+ strategy_version text NOT NULL,
58
+
59
+ -- CTX-BUDGET: ONE budget, and everything dropped to fit it recorded in
60
+ -- excluded[] with its reason. Silent omission is the failure; an explicit
61
+ -- (possibly empty) array is the honest report.
62
+ budget bigint NOT NULL,
63
+ excluded jsonb NOT NULL,
64
+
65
+ -- CTX-ARTIFACT: the content-addressed package. package_hash is the hash of
66
+ -- the compiled context; exact_context_artifact_ref resolves to the EXACT
67
+ -- bytes supplied to the model, so a recomputed hash can be checked equal.
68
+ package_hash text NOT NULL,
69
+ exact_context_artifact_ref text NOT NULL,
70
+
71
+ CONSTRAINT context_compilation_pkey PRIMARY KEY (compilation_id),
72
+
73
+ CONSTRAINT context_compilation_mode_is_a_declared_mode
74
+ CHECK (mode IN ('initial', 'delta', 'reconcile', 'recompile')),
75
+
76
+ CONSTRAINT context_compilation_source_refs_is_an_object
77
+ CHECK (jsonb_typeof(source_refs) = 'object'),
78
+
79
+ -- Load-bearing IS NOT NULL echo of 001's plan-status guard: with no frontier
80
+ -- key the -> yields SQL NULL, jsonb_typeof(NULL) is NULL, and a CHECK passes
81
+ -- on NULL — so an object is required, not merely "not a non-object".
82
+ CONSTRAINT context_compilation_frontier_is_an_object
83
+ CHECK (jsonb_typeof(source_frontier) = 'object'),
84
+
85
+ CONSTRAINT context_compilation_excluded_is_an_array
86
+ CHECK (jsonb_typeof(excluded) = 'array'),
87
+
88
+ CONSTRAINT context_compilation_budget_is_positive
89
+ CHECK (budget > 0),
90
+
91
+ CONSTRAINT context_compilation_package_hash_is_addressable
92
+ CHECK (length(btrim(package_hash)) > 0),
93
+
94
+ CONSTRAINT context_compilation_artifact_ref_is_addressable
95
+ CHECK (length(btrim(exact_context_artifact_ref)) > 0)
96
+ );
97
+
98
+ COMMENT ON TABLE cell.context_compilation IS
99
+ 'R-A3-5: the ContextCompilation. Footage answering "what did the agent know '
100
+ 'when it decided?" — per-source refs+hashes, the valid_at/known_at frontier, '
101
+ 'the budget and what it excluded, and the content-addressed exact context '
102
+ 'artifact. Evidence (L14), never a settlement authority: no load-bearing FK.';
103
+
104
+ CREATE INDEX IF NOT EXISTS context_compilation_by_claim
105
+ ON cell.context_compilation (org_id, work_claim_id, compiled_at);
@@ -0,0 +1,95 @@
1
+ -- 021_execution_attempt_closure.sql — the execution attempt names its EXACT
2
+ -- runtime/config/capability closure, and its context compilation.
3
+ --
4
+ -- Contract: R-A3-12 (an ExecutionAttempt owns a complete execution tree) + plan
5
+ -- §4 ScopeAllocator ("the attempt row carries harness+SDK version, model,
6
+ -- session_id, context_compilation_ref and the full runtime/config/capability
7
+ -- closure") + a3-verification-strategy.md §3.2 row RT-CLOSURE and §3.3
8
+ -- HANDOFF-PROVENANCE. Requires 001_core.sql (extends its execution_attempt) and
9
+ -- is ordered after 020 so the context_compilation it references already exists.
10
+ --
11
+ -- Re-apply: idempotent (ADD COLUMN IF NOT EXISTS; CREATE OR REPLACE).
12
+ -- Revert: ALTER TABLE cell.execution_attempt
13
+ -- DROP COLUMN harness_version, DROP COLUMN sdk_version,
14
+ -- DROP COLUMN model, DROP COLUMN image_digest,
15
+ -- DROP COLUMN config_spine_revision, DROP COLUMN capability_set,
16
+ -- DROP COLUMN context_compilation_ref, DROP COLUMN closure;
17
+ -- DROP FUNCTION cell.attempts_unattributed();
18
+ --
19
+ -- WHY THESE COLUMNS ARE NULLABLE, AND WHAT THAT MEANS FOR THE FALSIFIER
20
+ --
21
+ -- 001_core.sql's execution_attempt is the disposable runtime binding beneath a
22
+ -- claim; the work spine (A1/A2) writes attempt rows for the claim lifecycle and
23
+ -- knows nothing of an SDK version or a context artifact. Making these ADDED
24
+ -- columns NOT NULL would retroactively demand a closure of every spine-written
25
+ -- attempt and break the A1/A2 suites that predate the runtime. So the columns are
26
+ -- nullable at the SCHEMA level and the completeness rule lives in a FALSIFIER
27
+ -- (RT-CLOSURE): cell.attempts_unattributed() returns every attempt missing any
28
+ -- closure field, and the runtime's own attempts must return none. A null here is
29
+ -- a red the falsifier reads, exactly as an asserted-unverified task past its
30
+ -- verify_by is a red cell.unverified_past_verify_by reads — not a state the
31
+ -- schema makes unreachable, but one the substrate can NAME.
32
+
33
+ ALTER TABLE cell.execution_attempt
34
+ ADD COLUMN IF NOT EXISTS harness_version text,
35
+ ADD COLUMN IF NOT EXISTS sdk_version text,
36
+ ADD COLUMN IF NOT EXISTS model text,
37
+ ADD COLUMN IF NOT EXISTS image_digest text,
38
+ ADD COLUMN IF NOT EXISTS config_spine_revision text,
39
+ ADD COLUMN IF NOT EXISTS capability_set jsonb,
40
+ ADD COLUMN IF NOT EXISTS context_compilation_ref uuid,
41
+ ADD COLUMN IF NOT EXISTS closure jsonb;
42
+
43
+ COMMENT ON COLUMN cell.execution_attempt.closure IS
44
+ 'R-A3-12 / plan §4: the full runtime/config/capability closure this attempt '
45
+ 'was bound with — MCP set, hooks, permission posture, budgets, egress class '
46
+ '— rebound from Oathe state at allocation, never inherited from a prior '
47
+ 'process (RT-CLOSURE, RT-ATTEMPT-PROVENANCE).';
48
+
49
+ COMMENT ON COLUMN cell.execution_attempt.context_compilation_ref IS
50
+ 'The cell.context_compilation this attempt was allocated from (R-A3-5). '
51
+ 'Non-load-bearing by design: the reference is nullable and the spine settles '
52
+ 'without it — a missing ref is a red HANDOFF-PROVENANCE reads, not a block.';
53
+
54
+ -- ------------------------------------------------ RT-CLOSURE, as a query
55
+ --
56
+ -- Every attempt names its exact closure: harness+SDK version, model, image
57
+ -- digest, config-spine revision, capability set and the context compilation it
58
+ -- was allocated from. Every row this returns has a null in one of them and is a
59
+ -- red — the runtime's attempts must return NONE. The columns checked are exactly
60
+ -- the seven RT-CLOSURE names plus context_compilation_ref; session_id and
61
+ -- executor_version are already NOT NULL in 001 and cannot be missing.
62
+ CREATE OR REPLACE FUNCTION cell.attempts_unattributed()
63
+ RETURNS TABLE (
64
+ attempt_id uuid,
65
+ work_claim_id uuid,
66
+ missing text
67
+ )
68
+ LANGUAGE sql
69
+ STABLE
70
+ AS $unattributed$
71
+ SELECT a.attempt_id, a.work_claim_id,
72
+ concat_ws(',',
73
+ CASE WHEN a.harness_version IS NULL THEN 'harness_version' END,
74
+ CASE WHEN a.sdk_version IS NULL THEN 'sdk_version' END,
75
+ CASE WHEN a.model IS NULL THEN 'model' END,
76
+ CASE WHEN a.image_digest IS NULL THEN 'image_digest' END,
77
+ CASE WHEN a.config_spine_revision IS NULL THEN 'config_spine_revision' END,
78
+ CASE WHEN a.capability_set IS NULL THEN 'capability_set' END,
79
+ CASE WHEN a.context_compilation_ref IS NULL THEN 'context_compilation_ref' END
80
+ ) AS missing
81
+ FROM cell.execution_attempt a
82
+ WHERE a.harness_version IS NULL
83
+ OR a.sdk_version IS NULL
84
+ OR a.model IS NULL
85
+ OR a.image_digest IS NULL
86
+ OR a.config_spine_revision IS NULL
87
+ OR a.capability_set IS NULL
88
+ OR a.context_compilation_ref IS NULL
89
+ ORDER BY a.work_claim_id, a.attempt_id;
90
+ $unattributed$;
91
+
92
+ COMMENT ON FUNCTION cell.attempts_unattributed IS
93
+ 'RT-CLOSURE: every row is RED — an execution attempt missing a runtime, '
94
+ 'config or capability closure field. A runtime-written attempt names its '
95
+ 'whole closure and returns nothing here.';
@@ -0,0 +1,106 @@
1
+ -- 022_verification_clause.sql — the acceptance-clause object, minimal.
2
+ --
3
+ -- Contract: worksheet §7 acceptance lane ("the acceptance-package v1 port —
4
+ -- author/executor/seat split, task_id-keyed, +evidence_refs/trace_ref/
5
+ -- privacy_class/transfer_scope") + a3-verification-strategy.md §3.3 rows
6
+ -- ACC-CLAUSE-SCHEMA / ACC-PACKAGE-SPLIT / ACC-NON-AUTHOR. Requires 001_core.sql.
7
+ --
8
+ -- Re-apply: idempotent (CREATE ... IF NOT EXISTS).
9
+ -- Revert: DROP TABLE cell.verification_clause;
10
+ --
11
+ -- MINIMAL BY RULING. This is the clause OBJECT and its split — not the acceptance
12
+ -- lane. The registered-checker runner, the fail-toward-blocked verdict producer
13
+ -- and the eval-is-not-a-verdict gate are a later layer (REC-1); this file gives
14
+ -- the schema those legs will assert against, and the two invariants that are a
15
+ -- property of the object itself: the author/executor/seat split is TYPED (three
16
+ -- distinct identity fields, not one), and the seat that releases a clause is not
17
+ -- the author of the work it releases (ACC-NON-AUTHOR, the R1 rule at clause
18
+ -- grain). Everything a clause carries that a verification carries — evidence,
19
+ -- trace, privacy, transfer — is mandatory here for the same R4 reason.
20
+
21
+ CREATE TABLE IF NOT EXISTS cell.verification_clause (
22
+ clause_id uuid NOT NULL,
23
+ org_id text NOT NULL,
24
+
25
+ -- Keyed to the task (worksheet §7: "task_id-keyed"), the anchor the
26
+ -- verification plan's clauses and the completion tri-state both count over.
27
+ task_id text NOT NULL,
28
+
29
+ -- WHICH plan clause this object is about — the same clause name a
30
+ -- verification's verification_plan_ref discharges (e.g. 'acceptance_package').
31
+ clause_key text NOT NULL,
32
+
33
+ -- The split, TYPED as three identities rather than one (ACC-PACKAGE-SPLIT):
34
+ -- author — who made the completion claim this clause evaluates
35
+ -- executor — the runtime actor that produced the work
36
+ -- seat — the non-author seat that releases the clause
37
+ -- Collapsing any two of these is exactly what let author-run output release
38
+ -- work on the Mac. NULL author/executor is lawful for a clause DECLARED
39
+ -- before any claim; the seat is present only once the clause is released.
40
+ author_principal text,
41
+ executor_principal text,
42
+ seat_principal text,
43
+
44
+ -- R4, mandatory and non-empty when a seat has released (an unreleased clause
45
+ -- carries none yet). A released clause with no evidence is a verdict about
46
+ -- nothing checked.
47
+ evidence_refs jsonb NOT NULL,
48
+
49
+ -- R4: addressable trace, and H7 privacy/transfer, from day one — the same
50
+ -- clauses cell.verification carries, so a clause and the verification that
51
+ -- discharges it cannot disagree about how far the record may travel.
52
+ trace_ref text,
53
+ privacy_class text NOT NULL,
54
+ transfer_scope text NOT NULL,
55
+
56
+ created_at timestamptz NOT NULL,
57
+
58
+ CONSTRAINT verification_clause_pkey PRIMARY KEY (clause_id),
59
+
60
+ CONSTRAINT verification_clause_task_fkey
61
+ FOREIGN KEY (org_id, task_id) REFERENCES cell.task (org_id, task_id),
62
+
63
+ -- One object per (task, clause): the plan names a clause once, and a second
64
+ -- object for the same clause is two ideas of what releases it.
65
+ CONSTRAINT verification_clause_task_clause_key UNIQUE (org_id, task_id, clause_key),
66
+
67
+ CONSTRAINT verification_clause_key_is_addressable
68
+ CHECK (length(btrim(clause_key)) > 0),
69
+
70
+ CONSTRAINT verification_clause_evidence_refs_is_an_array
71
+ CHECK (jsonb_typeof(evidence_refs) = 'array'),
72
+
73
+ CONSTRAINT verification_clause_privacy_class_is_a_declared_class
74
+ CHECK (privacy_class IN ('public', 'org_internal', 'customer_derived')),
75
+
76
+ CONSTRAINT verification_clause_transfer_scope_is_a_declared_scope
77
+ CHECK (transfer_scope IN ('cell_only', 'org_internal', 'exportable')),
78
+
79
+ -- H7, the same constraint verification carries: customer-derived content
80
+ -- stays in the cell.
81
+ CONSTRAINT verification_clause_customer_derived_content_stays_in_the_cell
82
+ CHECK (privacy_class <> 'customer_derived' OR transfer_scope = 'cell_only'),
83
+
84
+ -- A released clause (seat present) is non-author (ACC-NON-AUTHOR at clause
85
+ -- grain) and carries its R4 evidence and trace. Before release the seat is
86
+ -- absent and these are not yet due.
87
+ CONSTRAINT verification_clause_release_is_non_author
88
+ CHECK (seat_principal IS NULL
89
+ OR (seat_principal IS DISTINCT FROM author_principal
90
+ AND seat_principal IS DISTINCT FROM executor_principal)),
91
+
92
+ CONSTRAINT verification_clause_release_carries_evidence
93
+ CHECK (seat_principal IS NULL OR jsonb_array_length(evidence_refs) > 0),
94
+
95
+ CONSTRAINT verification_clause_release_carries_a_trace
96
+ CHECK (seat_principal IS NULL OR length(btrim(coalesce(trace_ref, ''))) > 0)
97
+ );
98
+
99
+ COMMENT ON TABLE cell.verification_clause IS
100
+ 'Minimal acceptance-clause object (worksheet §7). Task-keyed; the '
101
+ 'author/executor/seat split is three typed identities; a released clause is '
102
+ 'non-author and carries R4 evidence/trace/privacy/transfer. The runner and '
103
+ 'the verdict producer are a later layer (REC-1).';
104
+
105
+ CREATE INDEX IF NOT EXISTS verification_clause_by_task
106
+ ON cell.verification_clause (org_id, task_id, clause_key);