@ours.network/tg-connector 0.1.2 → 0.1.4

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 (33) hide show
  1. package/README.md +1 -1
  2. package/dist/cli.js +1 -1
  3. package/dist/connector.js +1 -1
  4. package/dist/mufl_code/2DA1D5F860E42C605D92F1E24E2466C70EFDDBF057BBCBA52F0ECC639EFCA387.muflo +0 -0
  5. package/dist/mufl_code/core/CLUSTER_API.md +640 -0
  6. package/dist/mufl_code/core/CLUSTER_CONTRACT.md +121 -0
  7. package/dist/mufl_code/core/CLUSTER_INTRODUCTION_PLAN.md +200 -0
  8. package/dist/mufl_code/core/CONFIGURATION_DESIGN.md +35 -0
  9. package/dist/mufl_code/core/CONFIGURATION_PLAN.md +394 -0
  10. package/dist/mufl_code/core/DEVELOPMENT.md +168 -0
  11. package/dist/mufl_code/core/EPHEMERAL_INVITE_PLAN.md +465 -0
  12. package/dist/mufl_code/core/GROUP_CHAT_DESIGN.md +520 -0
  13. package/dist/mufl_code/core/LICENSE +98 -0
  14. package/dist/mufl_code/core/README.md +76 -0
  15. package/dist/mufl_code/core/a2a_capabilities.mm +350 -0
  16. package/dist/mufl_code/core/a2a_cluster.mm +601 -0
  17. package/dist/mufl_code/core/a2a_control.mm +89 -0
  18. package/dist/mufl_code/core/a2a_messaging.mm +2103 -0
  19. package/dist/mufl_code/core/a2a_monitoring.mm +94 -0
  20. package/dist/mufl_code/core/a2a_protocol.mm +231 -0
  21. package/dist/mufl_code/core/config.mufl +26 -0
  22. package/dist/mufl_code/core/release-notes/2.0.md +268 -0
  23. package/dist/mufl_code/core/release-notes/2.1.md +92 -0
  24. package/dist/mufl_code/core/release-notes/2.2.md +94 -0
  25. package/dist/mufl_code/core/release-notes/3.0.md +162 -0
  26. package/dist/mufl_code/core/release-notes/3.1.md +43 -0
  27. package/dist/mufl_code/core/release-notes/README.md +32 -0
  28. package/dist/mufl_code/core/tests/README.md +66 -0
  29. package/dist/mufl_code/core/tests/run.sh +67 -0
  30. package/dist/mufl_code/core/tests/test.mjs +467 -0
  31. package/dist/mufl_code/core/tests/test_actor.mu +287 -0
  32. package/dist/mufl_code/core/version.mm +24 -0
  33. package/package.json +2 -1
@@ -0,0 +1,394 @@
1
+ # ours Generic Configuration / Control-Plane — Consolidated Plan
2
+
3
+ Author: ours-developer-1 · Reviewer: critic-1 · Relay: Coordinator-1 → human
4
+ Baseline: **core v1.10** (a2a_protocol, a2a_messaging, a2a_control, a2a_capabilities, version)
5
+ Status: PLANNING ONLY — no implementation. Converged with critic-1.
6
+
7
+ > Read-the-tree note: an earlier draft was written against a stale v1.2 snapshot.
8
+ > This plan is re-baselined against the **current** tree pulled by the human:
9
+ > most of the brief is **already built**. The valuable output is the **delta**.
10
+
11
+ ---
12
+
13
+ ## A. What the brief asks for that is ALREADY BUILT (do NOT redesign)
14
+
15
+ | Brief requirement | Status | Where (current core) |
16
+ |---|---|---|
17
+ | **1. App manifest** (name, description, optional config schema) | **DONE — richer than asked** | `a2a_capabilities::app_manifest_t` = `($version,$app_id,$name,$description,$monitoring_status,$capabilities)`; `get_manifest` readonly; `app_id` also auto-stamped on the `a2a_control` transport (1.5). The "config schema" is the `core.configuration` capability's opaque-JSON `$params`. |
18
+ | **3. Optional JSON config schema, rendered by frontend** | **MOSTLY DONE** | `core.configuration` capability: `$params` is opaque JSON (schema + value) a dumb frontend renders. Full **secret-field redaction**: `secret_field_t`, `$set/$unset/$needs_reentry` sentinels, **epoch auto-clear on CP evict/rebind** ("no new party inherits live secrets"). `contact_ref_connect` (`$connect`) sentinel = the **config↔connect hinge** the telegram connector needs. |
19
+ | Config "expose all to wrapper" path | **DONE** | Opaque `$params` + the verb-envelope dispatch (`control_envelope_t` = `$cap,$verb,$args,$req_id` → `dispatch` → app handler) IS "wrapper pushes app-specific config via transaction." |
20
+ | **2. Monitoring** — first-class, governance-visible | **PARTIAL** | `monitoring_status` is a first-class manifest field. Architecture decided (1.7): the cert layer was **scrapped**; monitoring is secured by the **proxy-bind ceremony + open-source + eviction**, node **self-asserts** `monitoring_status` (accepted limitation, README §8) — NOT crypto certs. |
21
+ | **4. Introduction** — supporting shapes | **DONE (core 2.0)** | Shipped as CP-relayed **peer-signed address documents** (`introduce`/`introduce_to_group` + node-side `ingest_connect_descriptor`); `cap_connect = "core.connect"` is the node-side accept gate; `$connect` config hinge. The earlier `connect_descriptor_t` + `verify_connect_descriptor` + `safety_number` (SAS) shapes were **removed in 2.0**. Plus governance (separate): `cp_attestation_t` (§3c, 1.8), `root_cp_binding_t` (1.9), threaded through invites + `accept_contact` (1.10) so peers **TOFU-pin** "root R is managed by CP X" (NON-enforcing visibility). |
22
+ | Identity hierarchy / delegation / TOFU governance edge | **DONE** | `delegation_cert_t`, `root_profile_t`, `verify_peer_delegation`, intra-root sibling auto-connect, `intro_t`/`signed_intro_t` registrar credential (out-of-repo local-book). |
23
+
24
+ ## B. What is GENUINELY NET-NEW (the real work)
25
+
26
+ | # | Net-new item | Brief pt | Lives in |
27
+ |---|---|---|---|
28
+ | **B1** | **`a2a_monitoring` library** — referenced by `a2a_capabilities` but **does not exist**. The 6-digit proxy-bind ceremony, `monitoring_proxy` state, and the **FORCED fire-and-forget re-encrypted copy path**. | 2 | new `a2a_monitoring.mm` + a chokepoint in `a2a_messaging` |
29
+ | **B2** | **`core.connect` brokering FLOW** (shipped core 2.0, simplified): CP-side `introduce`/`introduce_to_group` relay each node the other's **peer-signed address document**; node-side `ingest_connect_descriptor` gates on bound-CP + own `core.connect` manifest, verifies the AD self-sig, registers. **This is the introduction problem** — solved without SAS / connect-descriptor / CP-signed intro. | 4 | `a2a_messaging` (CP + node txns) + `a2a_capabilities::self_supports` |
30
+ | **B3** | **`set_app_config` + typed protocol-policy txns** — store opaque config blob (CP-gated) + fire `$config_updated`; typed security-bearing policy enforced in the core send path. | 3 | `a2a_messaging` (or `a2a_config`) |
31
+ | **B4** | **Frontend per-app-name rendering** — registry map, generic fallback panel. | 5 | messenger (NOT this repo) |
32
+ | **B5** | **Docs** — README is stale (no `a2a_capabilities`, connect, governance, §8). | — | README.md |
33
+
34
+ ---
35
+
36
+ ## C. The introduction problem — explicit verdict
37
+
38
+ > **Superseded by core 2.0 (radical simplification).** The original plan below
39
+ > proposed a CP-as-registrar *signed* introduction with `connect_descriptor_t`,
40
+ > `signed_intro_t`, and a SAS. The human ruled for a far simpler design and that
41
+ > machinery was **removed**. This section now describes the shipped 2.0 model; the
42
+ > rejected-alternative rationale is retained for history.
43
+
44
+ **Does 1.10 "root-binding-through-introductions" solve it? NO — only adjacent.**
45
+ 1.10 threads the root's `root_cp_binding_t` along **existing** connect paths (invites,
46
+ `accept_contact`) so a connecting peer learns *who manages* the other side. That is
47
+ **governance visibility**, not a mechanism to connect two parties who are not yet
48
+ contacts.
49
+
50
+ **The shipped mechanism (core 2.0): the CP relays peer-signed address documents.**
51
+ The CP already holds each managed node's signed address document in `peer_ads`
52
+ (captured when the node bound the CP at the 6-digit ceremony). To introduce A and B
53
+ the CP simply sends each node the **other's signed AD**; the receiving node verifies
54
+ the AD's own self-signature, that the relay came from its bound CP, and that its own
55
+ manifest advertises `core.connect`, then registers the contact immediately. **No
56
+ SAS, no confirmation step, no per-introduction CP signature** — the bound-CP channel
57
+ *is* the authorization, and the node-side capability gate is the authoritative
58
+ "do I accept introductions".
59
+
60
+ Why not the naive invite-relay (still rejected): relaying raw invites would let the
61
+ CP register itself as a channel endpoint. Relaying the node's **own self-signed
62
+ address document** does not — the AD authorizes only the node's own keys, the
63
+ receiver re-checks the self-signature (proof-of-possession), and the contact's
64
+ channel is fresh DH between A and B (the CP never holds A↔B keys).
65
+
66
+ **Design — `introduce(A, B)` (shipped):**
67
+ 1. **Daemon pre-check (CP side):** pull `get_manifest` for A and B and **refuse if
68
+ either lacks `core.connect`** (prevents a half-open pairing). Daemon logic, not core.
69
+ 2. CP calls **`introduce(A, B)`** (host-fired). The core reads `peer_ads[A]`/`peer_ads[B]`
70
+ and emits, in one transaction, two encrypted relays: A gets B's signed AD, B gets A's.
71
+ 3. Each node runs **`ingest_connect_descriptor`**: `require_bound_cp_or_abort` (relay is
72
+ from my bound CP) → node-side capability gate (`self_supports("core.connect")`) →
73
+ `process_address_document` (peer AD self-sig / PoP, aborts on forgery) → register the
74
+ contact + `_notify_agent($introduced)`. An already-known contact is a no-op refresh
75
+ (`$reintroduced`, no downgrade/rename).
76
+
77
+ `introduce_to_group(joiner, members)` fans the same pair of relays out across a group
78
+ (cluster-root onboarding). Properties: keys bound by the AD self-signature (no swap);
79
+ the contact channel is independent of the CP; both endpoints notified. The net-new is a
80
+ thin *flow* over existing crypto (`process_address_document`, `send_encrypted_tx`) — no
81
+ new wire shapes, no SAS, no introduction signature.
82
+
83
+ ---
84
+
85
+ ## D. Net-new code — B1: forced monitoring (the chokepoint owns its gate)
86
+
87
+ ### D.1 Library split — load-order corrected (per critic-1)
88
+
89
+ Current load chain: `a2a_capabilities ← a2a_protocol ← a2a_messaging ← a2a_control`.
90
+ If a new `a2a_monitoring` **loaded** `a2a_messaging`, it would sit **above** it, so
91
+ `a2a_messaging::send_message` could **not** call up into it to emit the copy — a circular
92
+ load. **Therefore:**
93
+
94
+ - **The emit helper (`monitor_copy_actions`) AND the `monitoring_proxy` state +
95
+ `monitoring_copy_t` shape live INSIDE `a2a_messaging`** — the chokepoint owns its own
96
+ gate. This is the load-bearing change.
97
+ - **`a2a_monitoring` is management-ONLY**: the 6-digit ceremony
98
+ (`set_proxy_pending`/`verify_proxy_code`) + CP-authenticated `disable` + the CP-side
99
+ `receive_monitoring_copy` handler. It **writes `a2a_messaging`'s shared non-hidden
100
+ state** (`monitoring_proxy`) — exactly how `a2a_hierarchy` writes `a2a_messaging`'s
101
+ delegation state without owning the send path.
102
+
103
+ ### D.2 Enforcement principle (the "app can't override" guarantee)
104
+
105
+ The copy **generation** is **unconditional core code** in the shared `a2a_messaging`
106
+ send/receive path that every app routes through — **not** an app-injected hook (the
107
+ existing `on_message_*` hooks abort-if-unset and are app-supplied; an app could inject a
108
+ no-op and silently kill monitoring, breaking the brief). `monitoring_proxy` is settable
109
+ **only** by `verify_proxy_code` (6-digit, sender-bound) and clearable **only** by a
110
+ CP-authenticated `disable` — there is **no app-callable clear**. So it is structurally
111
+ impossible to send/receive a message without the copy being generated.
112
+
113
+ Invariants:
114
+ - **No recursion**: the copy is emitted as a *distinct* path (`receive_monitoring_copy`),
115
+ **never via `send_message`** — else the copy is itself monitored → infinite fan-out. The
116
+ copy traffic to the proxy is likewise **not** monitored.
117
+ - **Ciphertext on the wire**: the copy is sent with `encrypted_channel::send_encrypted_tx`
118
+ to the proxy's container id, so it is re-encrypted under the proxy channel key — never
119
+ plaintext.
120
+
121
+ ### D.3 Fire-and-forget through the broker; uniform gate (HUMAN corrections #1 + #2)
122
+
123
+ Two corrections from the human collapse the earlier (queue + sink-split) design into the
124
+ simplest faithful form:
125
+
126
+ - **#1 — Fire-and-forget through the broker.** No local `monitoring_inbox`, no
127
+ `get_monitoring_copies` daemon, **no proxy-liveness handling**. The copy is emitted
128
+ *inline* as a distinct fire-and-forget encrypted send. If the proxy is offline the
129
+ **ADAPT broker holds the pending message** — persistence/liveness is the framework's
130
+ job, not the mufl app's. (`send_encrypted_tx` just produces a `send` action; it does not
131
+ block on or wait for the receiver.)
132
+ - **#2 — Uniform gate, no sink split.** No role→root-vs-root→CP branching. One rule: **if
133
+ `monitoring_proxy` is bound, emit the copy to it**; otherwise emit nothing. Binding *is*
134
+ the enabled state, so no separate `monitoring_enabled` flag is needed.
135
+
136
+ ```mufl
137
+ // ---- a2a_messaging.mm: state + emit (the chokepoint owns these) ----
138
+ metadef proxy_binding_t: ($proxy_cid -> global_id, $bound_at -> time, $epoch -> int).
139
+ metadef monitoring_copy_t: (
140
+ $version -> int, $direction -> str /* "out"|"in" */,
141
+ $peer_cid -> global_id, $peer_name -> str, $date -> time, $body -> str
142
+ ).
143
+ // Distinct inbound tx name on the proxy — held as a literal string so a2a_messaging
144
+ // needs NO code dependency on a2a_monitoring (which sits above it in the load order).
145
+ receive_monitoring_copy_tx = "::a2a_monitoring::receive_monitoring_copy".
146
+
147
+ monitoring_proxy is proxy_binding_t+ = NIL. // set ONLY by verify_proxy_code; cleared ONLY by CP-auth disable
148
+
149
+ // Core, recursion-safe (never calls send_message). Uniform gate: proxy bound ⇒ emit one
150
+ // fire-and-forget encrypted copy to it. No queue, no liveness — the broker holds it if the
151
+ // proxy is offline. Returns [] (no churn) when no proxy is bound.
152
+ fn monitor_copy_actions (direction: str, peer_cid: global_id, peer_name: str, date: time, body: str)
153
+ -> transaction::action::type[]
154
+ {
155
+ if monitoring_proxy == NIL { return []. }
156
+ copy is monitoring_copy_t = (
157
+ $version -> 1, $direction -> direction, $peer_cid -> peer_cid,
158
+ $peer_name -> peer_name, $date -> date, $body -> body
159
+ ).
160
+ // The proxy is a registered contact (the 6-digit bind established the channel), so this
161
+ // is a plain encrypted send action — re-encrypted to the proxy key, never plaintext.
162
+ return [ encrypted_channel::send_encrypted_tx (monitoring_proxy? $proxy_cid) (
163
+ $name -> receive_monitoring_copy_tx, $targ -> ($copy -> copy)
164
+ ) ].
165
+ }
166
+ // send_message: after the user-message send action, UNCONDITIONALLY append
167
+ // monitor_copy_actions "out" target_id <name> sent_date text (the function self-gates).
168
+ // handle_receive_message: UNCONDITIONALLY append
169
+ // monitor_copy_actions "in" sender_id <name> msg_date text.
170
+ ```
171
+
172
+ ```mufl
173
+ // ---- a2a_monitoring.mm (NEW) — management ONLY; writes a2a_messaging state ----
174
+ library a2a_monitoring loads libraries
175
+ current_transaction_info, encrypted_channel, a2a_messaging
176
+ uses transactions
177
+ {
178
+ // Pending bind state stays local to this lib (only the ceremony reads it).
179
+ metadef proxy_pending_t: ($code -> str, $proxy_cid -> global_id, $expires_at -> time, $attempts -> int).
180
+ proxy_pending is proxy_pending_t+ = NIL.
181
+
182
+ // App-injected: where the CP stores a received monitoring copy (storage stays app-side,
183
+ // like a2a_messaging::on_message_received). Fires only for the bound, known proxy path.
184
+ hidden { on_monitoring_copy_received is (any -> transaction::action::type[]) = fn (_: any) -> transaction::action::type[] { abort "on_monitoring_copy_received hook is unset (call a2a_monitoring::init)." when TRUE. return []. } }
185
+ init = fn (_:($on_monitoring_copy_received -> cb: (any -> transaction::action::type[]))) { on_monitoring_copy_received -> cb. }
186
+
187
+ // TS passes the generated code (MUFL has no random source); stored as pending.
188
+ trn set_proxy_pending _:($code -> code: str, $proxy_cid -> cid: global_id, $expires_at -> exp: time)
189
+ { /* validate user origin; write proxy_pending */ ... }
190
+
191
+ // The human's verification message redeems the code; binds the proxy atomically.
192
+ trn verify_proxy_code _:($code -> code: str)
193
+ {
194
+ current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::external,).
195
+ encrypted_channel::check_encrypted_or_abort().
196
+ sender = current_transaction_info::get_external_envelope_or_abort() $from.
197
+ abort "No pending proxy bind." when proxy_pending == NIL.
198
+ abort "Bind is for a different identity." when (proxy_pending? $proxy_cid) != sender.
199
+ // expiry + attempts<3 (omitted); on wrong code increment attempts, cancel at 3.
200
+ abort "Wrong code." when (proxy_pending? $code) != code.
201
+ a2a_messaging::monitoring_proxy -> ($proxy_cid -> sender, $bound_at -> /*now*/ ..., $epoch -> /*++epoch*/ ...).
202
+ proxy_pending -> NIL.
203
+ return transaction::success [ a2a_messaging::_notify_agent ($event -> $proxy_bound, $cid -> sender), a2a_messaging::_save_state NIL ].
204
+ }
205
+
206
+ // CP-authenticated disable: only the bound proxy may clear monitoring (app can't).
207
+ trn disable_monitoring args: any { /* require sender == a2a_messaging::monitoring_proxy?.proxy_cid; clear it */ ... }
208
+
209
+ // CP side: receive a forwarded copy from a node it monitors; storage is the app's.
210
+ fn handle_receive_monitoring_copy (args: any) -> transaction::results::type
211
+ {
212
+ current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::external,).
213
+ encrypted_channel::check_encrypted_or_abort().
214
+ sender = current_transaction_info::get_external_envelope_or_abort() $from.
215
+ copy = (args $copy) safe a2a_messaging::monitoring_copy_t.
216
+ return transaction::success (on_monitoring_copy_received ($source -> sender, $copy -> copy)).
217
+ }
218
+ trn receive_monitoring_copy args: any { return handle_receive_monitoring_copy args. }
219
+ }
220
+ ```
221
+
222
+ Note: with the uniform rule, the `ours.mcp` cluster (root + N roles) is monitored by
223
+ binding the CP **per node**. Roles are full packets; a TS daemon that already manages the
224
+ cluster can drive the bind for each. Aggregation/grouping for display is a frontend concern
225
+ (B4), not a protocol one — keeping the protocol path single-rule and simple per the human.
226
+
227
+ Scope (v1, stated honestly): copies cover **chat send/receive only**. Contact
228
+ establishment + control traffic are **out of v1 "all traffic" scope**.
229
+
230
+ ---
231
+
232
+ ## E. Net-new code — B2: `core.connect` introduction flow (core 2.0, shipped)
233
+
234
+ ```mufl
235
+ // CP-side: introduce two managed nodes. Both must be established contacts of the CP
236
+ // (peer_ads holds their signed ADs). Emits both relays in one transaction. The
237
+ // manifest "supports introductions" pre-check is the DAEMON's job (get_manifest);
238
+ // the node-side gate in ingest_connect_descriptor is the authoritative enforcement.
239
+ trn introduce _:($peer_a -> ref_a: str, $peer_b -> ref_b: str)
240
+ {
241
+ // validate_origin(user); a = resolve_contact ref_a; b = resolve_contact ref_b.
242
+ // abort if a == b; abort if peer_ads[a] == NIL or peer_ads[b] == NIL.
243
+ // return success( emit_pair(a, ad_a, name_a, b, ad_b, name_b) ++ [ _return_data($introduced) ] ).
244
+ }
245
+
246
+ // emit_pair: two BARE encrypted sends (channels already established at bind, so no
247
+ // execute_transaction handshake). A gets B's signed AD, B gets A's.
248
+ fn emit_pair (a, ad_a, name_a, b, ad_b, name_b) -> transaction::action::type[]
249
+ {
250
+ return [
251
+ encrypted_channel::send_encrypted_tx a ($name -> ingest_connect_descriptor_tx, $targ -> ($peer_ad -> ad_b, $peer_name -> name_b)),
252
+ encrypted_channel::send_encrypted_tx b ($name -> ingest_connect_descriptor_tx, $targ -> ($peer_ad -> ad_a, $peer_name -> name_a))
253
+ ].
254
+ }
255
+
256
+ // Node-side: ingest the peer's signed address document the CP relayed. No SAS, no
257
+ // CP signature — the bound-CP channel + the node capability gate are the authorization.
258
+ fn handle_ingest_connect_descriptor (args: any) -> transaction::results::type
259
+ {
260
+ // validate_origin(external); check_encrypted_or_abort; sender = envelope.$from.
261
+ // require_bound_cp_or_abort(sender). // relay is from my bound CP
262
+ // abort unless a2a_capabilities::self_supports(a2a_capabilities::cap_connect). // node gate (authoritative)
263
+ peer_ad = (args $peer_ad) safe address_document_types::t_address_document.
264
+ peer_cid = peer_ad $identity $container_id.
265
+ // abort if peer_cid == _get_container_id().
266
+ address_document::process_address_document peer_ad TRUE. // peer AD self-sig / PoP, aborts on forgery
267
+ // if already a contact: refresh peer_ads only, keep name, notify $reintroduced.
268
+ // else: register contact ($peer_name || cid) + peer_ads, notify $introduced.
269
+ }
270
+ ```
271
+
272
+ CP-side orchestration (daemon): `get_manifest(A)` + `get_manifest(B)`, **refuse if
273
+ either lacks `core.connect`**, then call `introduce(A, B)`. The core emits both
274
+ signed-AD relays; each node's `ingest_connect_descriptor` gates and registers. The CP
275
+ never holds the A↔B channel keys (fresh DH between A and B on first message).
276
+
277
+ **`ingest_connect_descriptor` authorization (critic-verified, core 2.0):**
278
+ 1. **CP-sender gate** — `require_bound_cp_or_abort`: the relay must come from the CP
279
+ pinned at the 6-digit bind.
280
+ 2. **Node capability gate (authoritative)** — abort unless the node's own live manifest
281
+ advertises `core.connect`. Without this the manifest boolean would be pure CP-side
282
+ courtesy.
283
+ 3. **Peer AD self-signature** — `process_address_document(peer_ad, TRUE)` re-checks the
284
+ peer's own self-signatures and aborts on a forged/inconsistent document *before* any
285
+ write (`TRUE` only relaxes external-authorizing-container trust, not the self-sig).
286
+
287
+ **Notes (core 2.0):**
288
+ 1. **`core.connect` means "I ACCEPT introductions", not "I am undiscoverable".** A node's
289
+ AD is public (invite-equivalent); the boolean does not hide it. The half-open
290
+ preventer is the daemon pre-check, which must refuse if **either** party lacks support.
291
+ 2. **No SAS / no confirm step.** Introductions are established immediately; the node trusts
292
+ its bound CP to introduce honestly (same governance/honesty class as the monitoring bind
293
+ and the README §8 self-assertion limit). `$peer_name` is an unauthenticated display
294
+ label — never gate on it.
295
+
296
+ ---
297
+
298
+ ## F. Net-new code — B3: opaque config storage ONLY
299
+
300
+ > **SCOPE CORRECTION (human ruling, 2026-06-17):** the core stores and transports an
301
+ > **opaque, app-custom JSON blob** and bakes in **no policy semantics whatsoever**.
302
+ > The earlier typed `contact_policy` / `outgoing_only` core enforcement was **removed** —
303
+ > per-application policy (including "outgoing-only") is **application logic in the
304
+ > wrapper**, driven by the app's own custom config schema, not a protocol feature. This
305
+ > also reverses the earlier "security-bearing policy core-enforced" decision.
306
+
307
+ ```mufl
308
+ app_config is str = "". // hidden; opaque app-custom JSON, CP-sourced, persisted
309
+
310
+ fn handle_set_app_config (args: any) -> transaction::results::type
311
+ {
312
+ current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::external,).
313
+ encrypted_channel::check_encrypted_or_abort().
314
+ sender = current_transaction_info::get_external_envelope_or_abort() $from.
315
+ // GATE: only the bound CP may write config (same gate as monitoring).
316
+ require_bound_cp_or_abort sender.
317
+ app_config -> (args $config) safe str.
318
+ return transaction::success [ _notify_agent ($event -> $config_updated), _save_state NIL ].
319
+ }
320
+ // get_app_config (readonly) returns the blob. That is the ENTIRE B3 surface.
321
+ ```
322
+
323
+ - The wrapper, on `$config_updated`, pulls `get_app_config` and applies **all** of it —
324
+ operational config (bot tokens → start bots, chat→contact routing) AND any
325
+ app-specific policy (e.g. "outgoing-only"). The core never parses it.
326
+ - The core's only job: transport + store the opaque blob (hidden, CP-gated, persisted)
327
+ and notify. No JSON↔mufl mapping, no app-specific enforcement.
328
+
329
+ ---
330
+
331
+ ## G. Frontend (B4) + invariants
332
+
333
+ ```ts
334
+ const APP_RENDERERS: Record<string, AppRenderer> = { "ours.mcp": McpControlPanel };
335
+ const rendererFor = (m: AppManifest) => APP_RENDERERS[m.name] ?? GenericAppPanel;
336
+ ```
337
+ `GenericAppPanel` renders `core.configuration` `$params` (schema + redacted values) + the
338
+ monitoring feed. **Invariant (P1/P5):** `manifest.name`/`app_id` is a **RENDERING HINT
339
+ ONLY, never an authority grant** — the frontend enables NO capability from the name; the
340
+ privileged `ours.mcp` panel degrades gracefully on unsupported control commands and
341
+ surfaces the bound node's real `cid`.
342
+
343
+ ---
344
+
345
+ ## H. Versioning
346
+
347
+ B1/B3 were additive (no existing wire bytes change; the no-proxy/no-config paths stay
348
+ byte-identical) ⇒ **MIN bumps** (1.11–1.15). New `a2a_monitoring.mm` added to `config.mufl`.
349
+ The **B2 simplification is a MAJ bump → core 2.0**: it removes wire shapes
350
+ (`connect_descriptor_t`, the `signed_intro_t` CP path) and changes the
351
+ `ingest_connect_descriptor` payload, so it is not backward-compatible for consumers of the
352
+ old `core.connect` surface. Update `version.mm` and the docs (README / RELEASE_NOTES) in
353
+ the same commit.
354
+
355
+ ---
356
+
357
+ ## I. Scope — governance-attestation layer (HUMAN DECISION: out of scope, off critical path)
358
+
359
+ The **governance-attestation layer** — `cp_attestation_t` (1.8), `root_cp_binding_t`
360
+ (1.9), and the threading of `$rpb`/`$joiner_cp_binding` through `invite_role_t` +
361
+ `accept_contact` (1.10) — is **beyond this brief** (manifest / forced monitoring / config /
362
+ introduction / frontend). It is **non-enforcing** metadata (TOFU-pinned "which CP manages
363
+ which root") threaded through the most compatibility- and security-sensitive existing
364
+ paths, changing **no protocol decision**.
365
+
366
+ **Human decision (2026-06-16, relayed via Coordinator-1):** *keep the governance-
367
+ attestation layer OFF the critical path.* It is acknowledged to exist but is **excluded
368
+ from this configuration deliverable** and treated as **out-of-scope-pending-founder-
369
+ review**. The net-new pieces (B1 `a2a_monitoring` forced-copy, B2 `core.connect`
370
+ introduction flow) **must not build on it, block on it, or entangle it**. No further
371
+ non-enforcing additions to invite/`accept_contact` without a concrete enforcement purpose.
372
+
373
+ ## J. critic-1 sign-off checklist (all captured above)
374
+
375
+ 1. **Load-order** — `monitor_copy_actions` + `monitoring_proxy` state + `monitoring_copy_t`
376
+ in `a2a_messaging`; `a2a_monitoring` is management-only. → §D.1, §D code.
377
+ 2. **Fire-and-forget through the broker** (HUMAN #1) — no local queue/drain, no
378
+ proxy-liveness handling; distinct `receive_monitoring_copy` tx, **no recursion** (never
379
+ via `send_message`; copy traffic not monitored). → §D.2/§D.3, §D code.
380
+ 3. **Uniform gate** (HUMAN #2) — `monitoring_proxy` bound ⇒ emit copy to it; no
381
+ role-vs-root sink split, no separate `monitoring_enabled`. → §D.3, §D code.
382
+ 4. **core.connect** (core 2.0, simplified): three-gate authorization on ingest —
383
+ bound-CP sender, node-side `core.connect` capability gate, peer-AD self-sig (PoP).
384
+ No SAS, no CP-signed intro; daemon `get_manifest` pre-check refuses if either party
385
+ lacks support. → §C, §E.
386
+ 5. **`set_app_config` CP-gated**; security-bearing policy **core-enforced**, not
387
+ wrapper-only. → §F.
388
+ 6. **`name`/`app_id` = rendering-hint-only**, never an authority grant. → §G.
389
+ 7. **Governance-attestation layer kept off the critical path / not bundled** — HUMAN
390
+ DECISION: out-of-scope-pending-founder-review; B1/B2 must not entangle it. → §I.
391
+
392
+ **Status:** critic-1 FINAL SIGN-OFF (msg #6); HUMAN approved implementation with three
393
+ corrections (#1 fire-and-forget, #2 uniform gate, #3 attestation deferred), all captured
394
+ above. Implementation underway on branch `feat/core-config-control-plane`.
@@ -0,0 +1,168 @@
1
+ # Developing ours-mufl-core
2
+
3
+ This repo is the shared agent-to-agent protocol for [ours.network](https://ours.network),
4
+ written as pure MUFL (`.mm`) libraries. There is **no standalone build**: the
5
+ libraries are vendored as a submodule and compiled into each consumer's packet
6
+ (see [README.md](./README.md)). This document covers the protocol architecture,
7
+ how the code is compiled, and how to extend it safely.
8
+
9
+ ## 1. Protocol / architecture
10
+
11
+ The network is a set of identities (roots and their delegated roles) that
12
+ exchange end-to-end-encrypted messages over a broker/relay. These libraries
13
+ define the wire format and the verification logic; the host application (daemon,
14
+ browser, connector) only moves bytes and supplies storage hooks.
15
+
16
+ ### Wire shapes (`a2a_protocol`, `a2a_capabilities`)
17
+
18
+ All cross-node data is structural MUFL records, consumed by field key and by
19
+ `_value_id` over values — so **moving a shape between libraries never changes its
20
+ bytes, but renaming or retyping a `$field` does.** The core shapes are:
21
+
22
+ - **Invites, delegation certificates, root profiles, contact roots, local-book
23
+ introduction credentials, and control-plane governance attestation** live in
24
+ `a2a_protocol.mm`, together with their verification helpers
25
+ (`verify_peer_delegation`, `rebuild_peer_address_document`,
26
+ `verify_cp_attestation`, `verify_root_cp_binding`).
27
+ - **The app manifest** (`app_manifest_t`: `app_id` + name + a typed capability
28
+ map) is defined in `a2a_capabilities.mm` and read via `get_manifest`.
29
+
30
+ ### Capability / dispatch model (`a2a_capabilities`, `a2a_control`)
31
+
32
+ Control traffic is uniform. One opaque transport already exists —
33
+ `a2a_control::send_control($contact, $payload)` outbound, inbound
34
+ `a2a_control::control_message` (the `$on_control_received` seam). Every command
35
+ is a **capability envelope**:
36
+
37
+ ```mufl
38
+ metadef control_envelope_t: ($cap -> str, $verb -> str, $args -> str, $req_id -> str).
39
+ ```
40
+
41
+ - `$cap` — the capability id (`core.cluster`, `core.monitoring`, `core.connect`,
42
+ `core.configuration`).
43
+ - `$verb` — the verb within that capability.
44
+ - `$args` — an **opaque JSON object**, schema per verb (`"{}"` when none).
45
+ - `$req_id` — correlates the response, returned by `(sender_id, $req_id)`.
46
+
47
+ The inbound seam authorizes the envelope **once** at a single pre-dispatch
48
+ chokepoint, then routes via `a2a_capabilities::dispatch`, which keys **only on
49
+ `$cap`** to `handlers[$cap]`. Verbs stay a documented convention — the wire
50
+ carries opaque `$verb`/`$args` strings, so reserving a capability adds one
51
+ constant plus a contract, with no wire/type/dispatch change.
52
+
53
+ Forced monitoring is split across two libraries: the node-side gate state and
54
+ bind ceremony live (`hidden`) in `a2a_messaging`, while `a2a_monitoring` holds
55
+ the control-plane **receiver** side (`receive_monitoring_copy`, known-contact
56
+ only). Cluster/subagent management is the `core.cluster` surface in
57
+ `a2a_cluster`.
58
+
59
+ **Authoritative contracts:**
60
+ - [`CLUSTER_API.md`](./CLUSTER_API.md) — the FROZEN control-protocol-over-MUFL
61
+ contract: the envelope, the authz chokepoint, per-verb auth classes, host
62
+ hooks, idempotency, and protocol-version negotiation.
63
+ - [`CLUSTER_CONTRACT.md`](./CLUSTER_CONTRACT.md) — the `core.cluster` verb
64
+ contract (verb → reference handler/composition → wire alias) and its
65
+ guardrails.
66
+
67
+ Companion design/plan docs in this repo (`CONFIGURATION_PLAN.md`,
68
+ `EPHEMERAL_INVITE_PLAN.md`, `GROUP_CHAT_DESIGN.md`, `CLUSTER_INTRODUCTION_PLAN.md`)
69
+ record the rationale behind individual feature sets, and `release-notes/` tracks
70
+ what shipped per core version.
71
+
72
+ ## 2. How to build / compile
73
+
74
+ The core is never compiled alone — a consumer compiles it as part of its own
75
+ packet. The flow every consumer uses:
76
+
77
+ 1. **Vendor the core** at `<app>/mufl_code/core/` (submodule).
78
+ 2. **Merge exports.** The consumer's top-level `config.mufl` pulls the MUFL
79
+ stdlib and this repo's exports together:
80
+
81
+ ```mufl
82
+ config script
83
+ {
84
+ stdlib_config = (config_load #$MUFL_STDLIB_PATH).
85
+ core_config = (config_load #"core").
86
+ (
87
+ $imports -> ( $libraries -> (stdlib_config $exports $libraries)'(core_config $exports $libraries), ),
88
+ $exports -> ( $libraries -> (,), $applications -> (,) )
89
+ ).
90
+ }
91
+ ```
92
+
93
+ This repo's own [`config.mufl`](./config.mufl) is what `config_load #"core"`
94
+ resolves; it exports `version`, `a2a_capabilities`, `a2a_protocol`,
95
+ `a2a_messaging`, `a2a_cluster`, `a2a_monitoring`, and `a2a_control`.
96
+ 3. **Compile** with the ADAPT toolkit. Consumers wrap this in a
97
+ `scripts/compile-mufl.sh`; the underlying invocation is:
98
+
99
+ ```sh
100
+ MUFL_STDLIB_PATH="$ADAPT_TOOLKIT/mufl_stdlib" \
101
+ "$ADAPT_TOOLKIT/build.linux.release/mufl-compile" \
102
+ -mp "$ADAPT_TOOLKIT/meta" -mp "$ADAPT_TOOLKIT/transactions" \
103
+ <top-level>.mu
104
+ ```
105
+
106
+ `ADAPT_TOOLKIT` points at the toolkit root (the `mufl-compile` binary, plus
107
+ `mufl_stdlib`, `meta`, and `transactions`). The application then loads the
108
+ libraries by name (`application actor loads libraries ..., a2a_protocol,
109
+ version uses transactions`).
110
+
111
+ ### Tests
112
+
113
+ The behavioural test suite ([`tests/`](./tests/)) compiles a self-contained
114
+ `test_actor.mu` against this repo's core, boots a local broker, and runs a
115
+ loopback driver asserting receiver-side state. It needs external tooling (the
116
+ ADAPT toolkit, a consumer's `@adapt-toolkit` Node SDK, and `dev-broker.mjs`),
117
+ overridable by env:
118
+
119
+ ```sh
120
+ ADAPT_TOOLKIT=/path/to/adapt-toolkit \
121
+ OURS_SDK_NODE_MODULES=/path/to/ours-mcp/node_modules \
122
+ DEV_BROKER=/path/to/ours-mcp/scripts/dev-broker.mjs \
123
+ PORT=9799 ./tests/run.sh
124
+ ```
125
+
126
+ Exit 0 = all green; see [`tests/README.md`](./tests/README.md) for the scenarios
127
+ and invariants exercised.
128
+
129
+ ## 3. How to extend
130
+
131
+ ### Add a new capability module
132
+
133
+ 1. Create `a2a_<name>.mm` defining a `library a2a_<name>` with its shapes and
134
+ transactions. Keep wire shapes structural; gate behind the capability so
135
+ nodes that do not ship it are unaffected.
136
+ 2. Reserve a capability constant (e.g. `cap_<name>`) and, in the consuming app,
137
+ wire a handler under that constant in `a2a_capabilities::init`'s `$handlers`
138
+ map and list it in `describe()`, gated with `self_supports(cap_<name>)` —
139
+ exactly as `core.connect` / `core.cluster` are wired. `dispatch()` routes by
140
+ `$cap` only, so no dispatch change is needed.
141
+ 3. **Export it.** Add the module to [`config.mufl`](./config.mufl) under
142
+ `$exports $libraries` so `config_load #"core"` resolves it.
143
+ 4. Document the verb surface (a contract doc like `CLUSTER_CONTRACT.md`) and add
144
+ a `release-notes/` entry.
145
+
146
+ ### Adding to an existing module
147
+
148
+ Prefer adding new shapes/helpers (a backward-compatible **MIN** bump) over
149
+ changing existing ones. Never rename or retype an existing `$field`, and never
150
+ change the bytes of a shape that is already on the wire — that is a **MAJ** bump
151
+ and a protocol break for every deployed client.
152
+
153
+ ### Bump the version (required, same commit)
154
+
155
+ Every change to this repo updates `core_version` in [`version.mm`](./version.mm)
156
+ in the **same commit**:
157
+
158
+ ```mufl
159
+ core_version = create_version 0 0 1. // MAJ MIN PATCH
160
+ ```
161
+
162
+ - **PATCH** — fixes with no wire-shape or verification-semantics change.
163
+ - **MIN** — backward-compatible additions (new shapes, new helpers, new module).
164
+ - **MAJ** — any change to the bytes of an existing wire shape or to existing
165
+ verification semantics.
166
+
167
+ Both consumer packets expose the compiled-in value via their read-only
168
+ `get_version` transaction, so the deployed core version is observable at runtime.