@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.
Files changed (70) hide show
  1. package/LICENSE +202 -21
  2. package/NOTICE +7 -0
  3. package/README.md +99 -12
  4. package/assets/oathe-hero.svg +92 -0
  5. package/bin/oathe.mjs +376 -0
  6. package/docs/PRIVACY.md +45 -0
  7. package/package.json +32 -23
  8. package/plugin/.claude-plugin/plugin.json +10 -0
  9. package/plugin/.mcp.json +13 -0
  10. package/plugin/hooks/frame-note.mjs +24 -0
  11. package/plugin/hooks/heartbeat.mjs +49 -0
  12. package/plugin/hooks/hooks.json +39 -0
  13. package/plugin/hooks/lib.mjs +83 -0
  14. package/plugin/hooks/render-board.mjs +11 -0
  15. package/plugin/skills/oathe-work/SKILL.md +33 -0
  16. package/src/atif.mjs +633 -0
  17. package/src/blocks.mjs +192 -0
  18. package/src/board-render.mjs +106 -0
  19. package/src/config.mjs +169 -0
  20. package/src/context.mjs +35 -0
  21. package/src/doctor.mjs +108 -0
  22. package/src/harness.mjs +271 -0
  23. package/src/init.mjs +92 -0
  24. package/src/launch-env.mjs +25 -0
  25. package/src/launch.mjs +259 -0
  26. package/src/manifest.mjs +89 -0
  27. package/src/mcp/oathe-tools.mjs +517 -0
  28. package/src/paths.mjs +49 -0
  29. package/src/plans.mjs +50 -0
  30. package/src/runtime/discharge.mjs +57 -0
  31. package/src/runtime/provider.mjs +154 -0
  32. package/src/runtime/simple-cage.mjs +67 -0
  33. package/src/runtime/sql-acceptance-lane.mjs +89 -0
  34. package/src/session-host.mjs +81 -0
  35. package/src/substrate.mjs +337 -0
  36. package/src/successor.mjs +31 -0
  37. package/src/traces.mjs +242 -0
  38. package/src/uninstall.mjs +45 -0
  39. package/src/verifier.mjs +322 -0
  40. package/src/workspace.mjs +47 -0
  41. package/vendor/ddl/001_core.sql +312 -0
  42. package/vendor/ddl/002_claim.sql +438 -0
  43. package/vendor/ddl/003_verification.sql +480 -0
  44. package/vendor/ddl/004_delegation.sql +397 -0
  45. package/vendor/ddl/005_escalation.sql +303 -0
  46. package/vendor/ddl/006_dependency.sql +384 -0
  47. package/vendor/ddl/007_assignment.sql +502 -0
  48. package/vendor/ddl/008_effect_receipt.sql +290 -0
  49. package/vendor/ddl/009_verified_edge.sql +452 -0
  50. package/vendor/ddl/010_parent_child_verification.sql +320 -0
  51. package/vendor/ddl/011_confirm.sql +288 -0
  52. package/vendor/ddl/012_evaluator_lane.sql +444 -0
  53. package/vendor/ddl/013_claim_terminal.sql +279 -0
  54. package/vendor/ddl/014_claim_settlement.sql +327 -0
  55. package/vendor/ddl/015_claim_yield.sql +213 -0
  56. package/vendor/ddl/016_reopened_reclaim.sql +285 -0
  57. package/vendor/ddl/017_claim_yield_causes.sql +357 -0
  58. package/vendor/ddl/018_receiptless_unknown.sql +249 -0
  59. package/vendor/ddl/019_verification_contract_freeze.sql +335 -0
  60. package/vendor/ddl/020_context_compilation.sql +105 -0
  61. package/vendor/ddl/021_execution_attempt_closure.sql +95 -0
  62. package/vendor/ddl/022_verification_clause.sql +106 -0
  63. package/vendor/ddl/023_executor_role.sql +66 -0
  64. package/vendor/ddl/024_executor_role_hardening.sql +439 -0
  65. package/vendor/ddl/025_running_attempt_uniqueness.sql +102 -0
  66. package/vendor/ddl/026_acceptance_authority.sql +230 -0
  67. package/vendor/ddl/027_ownership_return.sql +836 -0
  68. package/vendor/ddl/028_attempt_bind_ownership.sql +173 -0
  69. package/vendor/ddl/manifest.json +183 -0
  70. package/index.js +0 -33
@@ -0,0 +1,230 @@
1
+ -- 026_acceptance_authority.sql — the acceptance lane's three settlement-shaped
2
+ -- inputs, held BELOW the agent instead of beside it in an environment variable.
3
+ --
4
+ -- Contract: contract §4.5 (registry edits are governed operations) + design law
5
+ -- L1 (one authoritative owner per lifecycle) + L2 (durable state lives below the
6
+ -- agent). Requires 001_core.sql for the `cell` schema and 002_claim.sql for
7
+ -- cell.written_by, the frame-stack signal this file's guard reads. It also names
8
+ -- 023_executor_role.sql's `cell_executor` in its privilege posture below, but does
9
+ -- not require it: that block is guarded and skips when the role is absent, so an
10
+ -- apply order without 023 still yields a complete and correct 026. Nothing else in
11
+ -- the substrate is touched: no existing table, verb or trigger is altered.
12
+ --
13
+ -- Re-apply: idempotent (CREATE TABLE IF NOT EXISTS / CREATE OR REPLACE; GRANT and
14
+ -- REVOKE are declarative).
15
+ -- Revert: DROP TRIGGER acceptance_authority_is_written_by_the_governed_verb
16
+ -- ON cell.acceptance_authority;
17
+ -- DROP FUNCTION cell.register_acceptance_authority(text,jsonb,jsonb,jsonb,text,timestamptz);
18
+ -- DROP FUNCTION cell.enforce_governed_acceptance_authority_edit();
19
+ -- DROP TABLE cell.acceptance_authority;
20
+ -- (a reverted cell has no registration to read, so the lane's resolver
21
+ -- falls all the way back to its env bootstrap — which is the state
22
+ -- this file exists to end, not a safe resting place)
23
+ --
24
+ -- Declared failure vocabulary (FC170-FC179 reserved; one code used):
25
+ -- FC170 ACCEPTANCE_AUTHORITY_FOREIGN_WRITER a writer other than
26
+ -- cell.register_acceptance_authority tried to set the lane's authority.
27
+ --
28
+ --
29
+ -- WHAT THIS IS FOR, AND WHAT IT REPLACES
30
+ --
31
+ -- Three environment variables decided settlement-shaped questions with nothing
32
+ -- durable behind them (the acceptance checker daemon, MEASURED before this
33
+ -- change): ACC_SEATS said WHO may transcribe a verdict, ACC_CLAUSE_SPECS said
34
+ -- WHAT the bar for a clause is, ACC_CHECKER_REFS said WHICH deployed code answers
35
+ -- a checker_ref. A deployment that changed one changed who may sign, or what
36
+ -- counts as discharged, and left no row anywhere saying it had. That is the same
37
+ -- defect cell.checker_registry (009) was built to end one level down — "what
38
+ -- counts as a valid verified release was encoded in seven places on the Mac and
39
+ -- every encoding drifted" — reappearing at the LANE's grain rather than the
40
+ -- dep_key's.
41
+ --
42
+ -- WHY NOT cell.checker_registry. It was the first place looked. Its key is
43
+ -- (org_id, dep_key) and its columns are two scalars: one evaluator principal and
44
+ -- one checker_ref, both ABOUT a single dependency key. The three values here are
45
+ -- properties of the LANE — an ordered roster, a clause_key->spec map and a
46
+ -- ref->deployed-code map, all org-grain and none of them per-dep_key. Encoding
47
+ -- them as registry rows under invented dep_keys would put three different
48
+ -- meanings in one column and make the §4.5 registry answer a question it was not
49
+ -- asked. One table, one lifecycle.
50
+ --
51
+ -- THE ENV IS STILL ALLOWED TO BOOTSTRAP, ONCE. A cell that has never been
52
+ -- registered has to learn its roster from somewhere, and the resolver
53
+ -- (`resolveAcceptanceAuthority`, src/acceptance-producer.mjs) takes the env values
54
+ -- and WRITES THEM HERE in the same startup. From the second boot on, this table
55
+ -- answers and an env value that disagrees is a typed refusal
56
+ -- (ENV_AUTHORITY_CONFLICT) rather than an override. That is the L8 shape: the
57
+ -- bridge exists, and it retires itself the first time it is crossed.
58
+ --
59
+ -- WHICH DATABASE THE LANE CONNECTS TO IS NOT HERE, deliberately. ACC_PG_URL and
60
+ -- its host/port/user siblings stay environment variables: they say WHERE the cell
61
+ -- is, not WHAT it may do. A deployment coordinate is not authority content, and
62
+ -- putting it in the substrate it addresses would be circular.
63
+
64
+ CREATE TABLE IF NOT EXISTS cell.acceptance_authority (
65
+ org_id text NOT NULL,
66
+
67
+ -- The transcribing roster, IN PREFERENCE ORDER — an array and not a set,
68
+ -- because the lane picks the first non-author seat and the order is therefore
69
+ -- part of the answer to "who signed this".
70
+ seats jsonb NOT NULL,
71
+
72
+ -- clause_key -> typed clause spec. The BAR. A lane with no spec for a clause
73
+ -- blocks rather than accepting, so an empty object is lawful and an absent
74
+ -- row is not.
75
+ clause_specs jsonb NOT NULL,
76
+
77
+ -- checker_ref -> the name of the deployed checker that answers it. The
78
+ -- substrate says a checker must answer for a dep_key (009); this says which
79
+ -- code is deployed to be that checker.
80
+ checker_refs jsonb NOT NULL,
81
+
82
+ registered_by text NOT NULL,
83
+ registered_at timestamptz NOT NULL,
84
+
85
+ CONSTRAINT acceptance_authority_pkey PRIMARY KEY (org_id),
86
+
87
+ -- A roster that is empty, or is not a list at all, would make the lane invent
88
+ -- a seat at the first verdict — and an invented seat is an invented authority.
89
+ CONSTRAINT acceptance_authority_seats_is_a_nonempty_array
90
+ CHECK (jsonb_typeof(seats) = 'array' AND jsonb_array_length(seats) > 0),
91
+ -- Stated as jsonpath rather than as `NOT EXISTS (SELECT ... jsonb_array_elements)`
92
+ -- because a CHECK may not carry a subquery. A seat that is a number, or a
93
+ -- string of spaces, is a principal nobody can be.
94
+ CONSTRAINT acceptance_authority_seats_are_named
95
+ CHECK (NOT jsonb_path_exists(seats, '$[*] ? (@.type() != "string")')
96
+ AND NOT jsonb_path_exists(seats, '$[*] ? (@ like_regex "^\\s*$")')),
97
+
98
+ CONSTRAINT acceptance_authority_clause_specs_is_an_object
99
+ CHECK (jsonb_typeof(clause_specs) = 'object'),
100
+ CONSTRAINT acceptance_authority_checker_refs_is_an_object
101
+ CHECK (jsonb_typeof(checker_refs) = 'object'),
102
+
103
+ CONSTRAINT acceptance_authority_registrar_is_named
104
+ CHECK (length(btrim(registered_by)) > 0)
105
+ );
106
+
107
+ COMMENT ON TABLE cell.acceptance_authority IS
108
+ 'The acceptance lane''s roster, clause bars and checker_ref map, held below '
109
+ 'the agent (L2) and owned by one governed verb (L1). Was three environment '
110
+ 'variables with no record that anyone had ever set them.';
111
+
112
+ -- The same governance shape 009 gave the checker registry, for the same reason
113
+ -- and against the same forgery: a `registered_by` column alone is authorised by
114
+ -- typing the right string into it. The signal is cell.written_by (002_claim.sql)
115
+ -- — the verb's frame is on this trigger's call stack or it is not.
116
+ CREATE OR REPLACE FUNCTION cell.enforce_governed_acceptance_authority_edit()
117
+ RETURNS trigger
118
+ LANGUAGE plpgsql
119
+ AS $governed$
120
+ BEGIN
121
+ IF NOT cell.written_by('cell.register_acceptance_authority') THEN
122
+ RAISE EXCEPTION
123
+ 'ACCEPTANCE_AUTHORITY_FOREIGN_WRITER:% — who may transcribe a verdict, '
124
+ 'what a clause''s bar is, and which code answers a checker_ref are set '
125
+ 'only by cell.register_acceptance_authority. A service that could write '
126
+ 'this row directly would be the second authority the row exists to '
127
+ 'remove.',
128
+ NEW.org_id
129
+ USING ERRCODE = 'FC170';
130
+ END IF;
131
+ RETURN NEW;
132
+ END;
133
+ $governed$;
134
+
135
+ CREATE OR REPLACE TRIGGER acceptance_authority_is_written_by_the_governed_verb
136
+ BEFORE INSERT OR UPDATE ON cell.acceptance_authority
137
+ FOR EACH ROW EXECUTE FUNCTION cell.enforce_governed_acceptance_authority_edit();
138
+
139
+ -- The one verb. Every argument is required and there is no default, the rule 009
140
+ -- states and this file inherits: a default roster, a default bar or a
141
+ -- server-chosen timestamp would each be a governance decision made in the
142
+ -- substrate, invisible at the call site.
143
+ CREATE OR REPLACE FUNCTION cell.register_acceptance_authority(
144
+ p_org_id text,
145
+ p_seats jsonb,
146
+ p_clause_specs jsonb,
147
+ p_checker_refs jsonb,
148
+ p_registered_by text,
149
+ p_registered_at timestamptz
150
+ )
151
+ RETURNS text
152
+ LANGUAGE plpgsql
153
+ AS $register$
154
+ BEGIN
155
+ -- Nothing is set to authorize this write: THIS frame, on the call stack, is
156
+ -- the authorization, and it stops existing when the function returns.
157
+ INSERT INTO cell.acceptance_authority (
158
+ org_id, seats, clause_specs, checker_refs, registered_by, registered_at
159
+ ) VALUES (
160
+ p_org_id, p_seats, p_clause_specs, p_checker_refs, p_registered_by,
161
+ p_registered_at
162
+ )
163
+ ON CONFLICT (org_id) DO UPDATE
164
+ SET seats = EXCLUDED.seats,
165
+ clause_specs = EXCLUDED.clause_specs,
166
+ checker_refs = EXCLUDED.checker_refs,
167
+ registered_by = EXCLUDED.registered_by,
168
+ registered_at = EXCLUDED.registered_at;
169
+
170
+ RETURN p_org_id;
171
+ END;
172
+ $register$;
173
+
174
+ COMMENT ON FUNCTION cell.register_acceptance_authority IS
175
+ 'The only writer of cell.acceptance_authority. A lane''s roster, bars and '
176
+ 'checker map become the cell''s answer by passing through here or not at all.';
177
+
178
+ -- ---------------------------------------------------- the executor's posture, STATED
179
+ --
180
+ -- WHY THIS FILE STATES ITS OWN INSTEAD OF LEAVING IT TO 023/024. Two reasons, both
181
+ -- MEASURED against the shipped chain rather than reasoned about.
182
+ --
183
+ -- GRANT DRIFT. 023:49 grants SELECT on ALL TABLES IN SCHEMA cell, and `ALL TABLES`
184
+ -- is resolved at GRANT time over the tables that exist THEN. On a first apply this
185
+ -- table does not exist yet when 023 runs, so the executor holds nothing on it; on a
186
+ -- SECOND apply over the same database it does, and the executor silently gains
187
+ -- SELECT. MEASURED on a scratch cell: sel|ins = f|f after one apply, t|f after two.
188
+ -- A substrate whose privileges depend on how many times it was applied has no stated
189
+ -- posture at all, so the chain ends HERE, in one state, whatever ran before it.
190
+ --
191
+ -- AND THE WIDEN-THEN-CLOSE CEREMONY. 024's five REVOKEs exist precisely so a careless
192
+ -- `GRANT ALL ON ALL TABLES` cannot re-open the capability surface, and the rt-domain
193
+ -- family proves it by widening every table and re-applying 024. A REVOKE for THIS
194
+ -- table written into 024 would break 024's own re-apply — 024 runs BEFORE 026 in the
195
+ -- declared order, so the table does not exist when it does. MEASURED: after that
196
+ -- ceremony, effect_receipt.INSERT closes to false and acceptance_authority.INSERT
197
+ -- stayed TRUE. Each surface is therefore closed by the file that owns it, and the leg
198
+ -- re-applies both.
199
+ --
200
+ -- WHY THE EXECUTOR GETS NOTHING HERE, not even SELECT. Reading the spine is never the
201
+ -- boundary (023's rule) — but this row is not the spine. It is the answer to "who may
202
+ -- sign", and the lane that reads it connects as the settlement writer, never as
203
+ -- cell_executor. An executor that could read the roster learns which seat to
204
+ -- impersonate; one that could write it IS the settlement authority. The anti-vacuity
205
+ -- half 023 asks for is unaffected: the executor still reads every table it works
206
+ -- against and still writes its own attempt and its own statement.
207
+
208
+ -- The governed verb is not PUBLIC's. A function is EXECUTE-to-PUBLIC by default, so
209
+ -- without this line every role in the cell — cell_executor included — could call the
210
+ -- one writer of the lane's authority, and the FC170 trigger would wave it through
211
+ -- because the verb's frame really is on the stack. The deployment GRANTs EXECUTE to
212
+ -- the principal that runs the lane; nobody else holds it.
213
+ REVOKE EXECUTE ON FUNCTION
214
+ cell.register_acceptance_authority(text,jsonb,jsonb,jsonb,text,timestamptz)
215
+ FROM PUBLIC;
216
+
217
+ -- Guarded rather than bare: 023 may not have run, and a file that fails on a role it
218
+ -- does not create would make its own Requires line a lie. Stated as an explicit
219
+ -- REVOKE and not left to an absent GRANT, for 023's own reason — the boundary reads
220
+ -- as a deliberate act rather than an omission somebody might "fix".
221
+ DO $authority_posture$
222
+ BEGIN
223
+ IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'cell_executor') THEN
224
+ REVOKE ALL ON cell.acceptance_authority FROM cell_executor;
225
+ REVOKE ALL ON FUNCTION
226
+ cell.register_acceptance_authority(text,jsonb,jsonb,jsonb,text,timestamptz)
227
+ FROM cell_executor;
228
+ END IF;
229
+ END
230
+ $authority_posture$;