@ours.network/tg-connector 0.1.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 (37) hide show
  1. package/LICENSE +98 -0
  2. package/README.md +318 -0
  3. package/dist/cli.js +726 -0
  4. package/dist/connector.js +1578 -0
  5. package/dist/mufl_code/2DA1D5F860E42C605D92F1E24E2466C70EFDDBF057BBCBA52F0ECC639EFCA387.muflo +0 -0
  6. package/dist/mufl_code/actor.mu +1757 -0
  7. package/dist/mufl_code/config.mufl +27 -0
  8. package/dist/mufl_code/core/CLUSTER_API.md +640 -0
  9. package/dist/mufl_code/core/CLUSTER_CONTRACT.md +121 -0
  10. package/dist/mufl_code/core/CLUSTER_INTRODUCTION_PLAN.md +200 -0
  11. package/dist/mufl_code/core/CONFIGURATION_DESIGN.md +35 -0
  12. package/dist/mufl_code/core/CONFIGURATION_PLAN.md +394 -0
  13. package/dist/mufl_code/core/DEVELOPMENT.md +168 -0
  14. package/dist/mufl_code/core/EPHEMERAL_INVITE_PLAN.md +465 -0
  15. package/dist/mufl_code/core/GROUP_CHAT_DESIGN.md +520 -0
  16. package/dist/mufl_code/core/LICENSE +98 -0
  17. package/dist/mufl_code/core/README.md +76 -0
  18. package/dist/mufl_code/core/a2a_capabilities.mm +350 -0
  19. package/dist/mufl_code/core/a2a_cluster.mm +601 -0
  20. package/dist/mufl_code/core/a2a_control.mm +89 -0
  21. package/dist/mufl_code/core/a2a_messaging.mm +2103 -0
  22. package/dist/mufl_code/core/a2a_monitoring.mm +94 -0
  23. package/dist/mufl_code/core/a2a_protocol.mm +231 -0
  24. package/dist/mufl_code/core/config.mufl +26 -0
  25. package/dist/mufl_code/core/release-notes/2.0.md +268 -0
  26. package/dist/mufl_code/core/release-notes/2.1.md +92 -0
  27. package/dist/mufl_code/core/release-notes/2.2.md +94 -0
  28. package/dist/mufl_code/core/release-notes/3.0.md +162 -0
  29. package/dist/mufl_code/core/release-notes/3.1.md +43 -0
  30. package/dist/mufl_code/core/release-notes/README.md +32 -0
  31. package/dist/mufl_code/core/tests/README.md +66 -0
  32. package/dist/mufl_code/core/tests/run.sh +67 -0
  33. package/dist/mufl_code/core/tests/test.mjs +467 -0
  34. package/dist/mufl_code/core/tests/test_actor.mu +287 -0
  35. package/dist/mufl_code/core/version.mm +24 -0
  36. package/dist/mufl_code/protocol_container.mm +18 -0
  37. package/package.json +46 -0
@@ -0,0 +1,94 @@
1
+ // Shared ours monitoring library — CONTROL-PLANE (receiver) side.
2
+ //
3
+ // Monitoring is split across two libraries by WHERE the state lives:
4
+ //
5
+ // - NODE side (a2a_messaging): the forced copy GENERATION
6
+ // (monitor_copy_actions in the send/receive chokepoint) AND the gate state
7
+ // it reads (monitoring_proxy / proxy_pending) plus that state's mutators —
8
+ // the 6-digit bind ceremony (set_proxy_pending / verify_proxy_code), the
9
+ // CP-authenticated disable_monitoring, and get_monitoring_status. They MUST
10
+ // live in a2a_messaging because the gate state is `hidden` there, and hidden
11
+ // state is mutable only by its declaring library — that is precisely what
12
+ // stops an app (or any other library) from assigning monitoring_proxy -> NIL
13
+ // to switch monitoring off without the ceremony.
14
+ //
15
+ // - CONTROL-PLANE side (HERE): the receiver for the copies a monitored node
16
+ // forwards. It touches NO gate state — it only validates the sender is a
17
+ // known contact and hands the copy to the app's storage hook. This is the
18
+ // only piece that can safely live outside a2a_messaging.
19
+ //
20
+ // Security model (founder directive, the ours monitoring design's accepted self-assertion limitation): monitoring is secured by the
21
+ // bind ceremony + open source + eviction; a node self-asserts monitoring_status,
22
+ // it is NOT cert-enforced. The "app can't override" guarantee is the narrower,
23
+ // real one: copy generation is unconditional core code and the gate state is
24
+ // non-app-writable (hidden), so an honest app cannot silently disable monitoring.
25
+ library a2a_monitoring loads libraries
26
+ current_transaction_info,
27
+ encrypted_channel,
28
+ a2a_messaging
29
+ uses transactions
30
+ {
31
+ hidden
32
+ {
33
+ // App-injected: store one received monitoring copy. Storage stays app-side
34
+ // (the messenger persists the feed), like a2a_messaging's message hooks.
35
+ // Receives ($source_id, $copy). Fires only for a known-contact sender.
36
+ on_monitoring_copy_received is (any -> transaction::action::type[]) = fn (_: any) -> transaction::action::type[] { abort "on_monitoring_copy_received hook is unset in a2a_monitoring (call a2a_monitoring::init)." when TRUE. return []. }
37
+ // core 3.2: store one pushed roster snapshot. Fires only for a known-contact
38
+ // sender (the node this control plane monitors). Receives ($source_id, $version, $members).
39
+ on_roster_update is (any -> transaction::action::type[]) = fn (_: any) -> transaction::action::type[] { abort "on_roster_update hook is unset in a2a_monitoring (call a2a_monitoring::init)." when TRUE. return []. }
40
+ }
41
+
42
+ init = fn (_:(
43
+ $on_monitoring_copy_received -> cb: (any -> transaction::action::type[]),
44
+ $on_roster_update -> rcb: (any -> transaction::action::type[])
45
+ ))
46
+ {
47
+ on_monitoring_copy_received -> cb.
48
+ on_roster_update -> rcb.
49
+ }
50
+
51
+ // Receive a forced copy from a node this control plane monitors. Storage is
52
+ // the app's (the on_monitoring_copy_received hook); the source is the channel-
53
+ // authenticated envelope sender, which must be a known contact. Touches no
54
+ // gate state — purely the CP-side ingest.
55
+ fn handle_receive_monitoring_copy (args: any) -> transaction::results::type
56
+ {
57
+ current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::external,).
58
+ encrypted_channel::check_encrypted_or_abort().
59
+
60
+ sender_id = current_transaction_info::get_external_envelope_or_abort() $from.
61
+ abort "Monitoring copy from an unknown sender was rejected." when (a2a_messaging::contacts sender_id) == NIL.
62
+ copy = (args $copy) safe a2a_messaging::monitoring_copy_t.
63
+ abort "Unsupported monitoring copy version." when (copy $version) != 1.
64
+
65
+ return transaction::success (on_monitoring_copy_received (
66
+ $source_id -> sender_id,
67
+ $copy -> copy
68
+ )).
69
+ }
70
+
71
+ trn receive_monitoring_copy args: any
72
+ {
73
+ return handle_receive_monitoring_copy args.
74
+ }
75
+
76
+ // core 3.2: receive a roster snapshot pushed by a node we control. Same CP-side
77
+ // ingest contract as receive_monitoring_copy — known-contact sender only, no gate
78
+ // state touched; the app stores it (on_roster_update). $members is opaque (the app
79
+ // interprets member_t); $version lets the app dedup/order.
80
+ fn handle_receive_roster_update (args: any) -> transaction::results::type
81
+ {
82
+ current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::external,).
83
+ encrypted_channel::check_encrypted_or_abort().
84
+ sender_id = current_transaction_info::get_external_envelope_or_abort() $from.
85
+ abort "Roster update from an unknown sender was rejected." when (a2a_messaging::contacts sender_id) == NIL.
86
+ return transaction::success (on_roster_update (
87
+ $source_id -> sender_id,
88
+ $version -> (args $version),
89
+ $members -> (args $members)
90
+ )).
91
+ }
92
+
93
+ trn receive_roster_update args: any { return handle_receive_roster_update args. }
94
+ }
@@ -0,0 +1,231 @@
1
+ // Shared ours protocol library.
2
+ //
3
+ // The wire-facing shapes and verification logic common to every ours
4
+ // packet (the agent/MCP packet, the web messenger, and future clients).
5
+ // Everything here is network protocol surface: peers exchange these shapes
6
+ // byte-for-byte, so any change is a protocol revision — keep the shapes
7
+ // backward-compatible and bump version.mm with every edit to this core.
8
+ library a2a_protocol loads library
9
+ key_utils,
10
+ key_storage,
11
+ address_document_types,
12
+ a2a_capabilities
13
+ {
14
+ metadef contact_t: ($name -> str, $container_id -> global_id).
15
+
16
+ // ---- identity hierarchy wire shapes ---------------------------------
17
+ // Delegation certificate: "role X belongs to root Y, signed by Y". The
18
+ // signature is over the core's _value_id, binding the role's container
19
+ // id AND its full key material (the address-document hash) to one root.
20
+ // An identity carrying NIL here is a root (or a legacy flat identity) —
21
+ // detection is structural, not a flag. v1 revocation == delete the role.
22
+ metadef delegation_core_t: (
23
+ $version -> int,
24
+ $role_cid -> global_id,
25
+ $role_ad_hash -> hash_code,
26
+ $role_id -> str,
27
+ $root_cid -> global_id,
28
+ $issued_at -> time
29
+ ).
30
+ metadef delegation_cert_t: ($c -> delegation_core_t, $s -> crypto_signature).
31
+ // Self-signed root profile, carried in role invites so an external peer
32
+ // learns WHO is behind the role. It includes the root's key list, so the
33
+ // receiver can verify both this signature and the delegation cert with
34
+ // no prior knowledge of the root.
35
+ metadef root_profile_core_t: (
36
+ $version -> int,
37
+ $root_cid -> global_id,
38
+ $name -> str,
39
+ $bio -> str,
40
+ $keys -> key_utils::t_publickey(,)
41
+ ).
42
+ metadef root_profile_t: ($p -> root_profile_core_t, $s -> crypto_signature).
43
+
44
+ // §3c root-half CP binding. The root self-signs {version, context_tag,
45
+ // root_cid, cid_cp} — see the verifier and context tag lower in this library
46
+ // for the full rationale. Carried (as a blob) on the leg-1/leg-3 identity bundle.
47
+ metadef root_cp_binding_core_t: (
48
+ $version -> int,
49
+ $context_tag -> str,
50
+ $root_cid -> global_id,
51
+ $cid_cp -> global_id
52
+ ).
53
+ metadef root_cp_binding_t: ($c -> root_cp_binding_core_t, $s -> crypto_signature).
54
+ // Verified root linkage learned about a contact (from its role invite or
55
+ // a sibling introduction). Kept beside `contacts` so old state blobs
56
+ // (whose contact_t has no such fields) import unchanged.
57
+ metadef contact_root_t: ($root_cid -> global_id, $root_name -> str, $role_id -> str).
58
+
59
+ // ---- core 3.0 ephemeral-key slim invite -----------------------------
60
+ // THE invite shape (the fat invite_t / invite_role_t were removed in core 3.0
61
+ // together with the old offline-redeem path). Carries ONLY an ephemeral
62
+ // encryption pubkey, the inviter's routing/identity cid, a display name, and
63
+ // the crypto scheme id — NO identity keys, NO self-sigs, NO cert, NO root
64
+ // profile. The inviter's (and responder's) address documents + delegation
65
+ // chains move to a two-message ENCRYPTED hop after redemption:
66
+ //
67
+ // (OOB) inviter ─► responder : invite_eph_t (this shape)
68
+ // leg 1 responder ─► inviter : submit_invite_response (BARE send; a box to
69
+ // eph_pub_inviter) — cleartext envelope:
70
+ // { $invite_id -> global_id, $epk -> publickey_encrypt /*responder eph pub*/,
71
+ // $v -> int /*scheme*/, $data -> crypto_message }
72
+ // leg 3 inviter ─► responder : complete_invite (ALSO a BARE send; a box to the
73
+ // RESPONDER's eph pub from leg 1 — it cannot ride encrypted_channel because
74
+ // the responder has not registered the inviter yet, and the stdlib exposes
75
+ // no raw long-term privkey to box against instead). Same envelope shape:
76
+ // { $invite_id -> global_id, $epk -> publickey_encrypt /*inviter eph pub*/,
77
+ // $v -> int /*scheme*/, $data -> crypto_message }
78
+ // Both boxes' `data` decrypt to the SAME identity bundle:
79
+ // { $ad -> t_address_document, $cert -> bin+, $root_profile -> bin+,
80
+ // $cp_binding -> bin+, $invite_id -> global_id }
81
+ // After leg 3, both sides hold the other's verified AD and encrypted_channel
82
+ // resumes for all subsequent send_message traffic.
83
+ // $d invite_id (correlates leg-1 to the stored eph privkey; single-use)
84
+ // $c inviter container_id (routing target + identity pin)
85
+ // $n inviter display name (metadata only) $k eph_pub_inviter $v scheme id
86
+ metadef invite_eph_t: (
87
+ $d -> global_id,
88
+ $c -> global_id,
89
+ $n -> str,
90
+ $k -> publickey_encrypt,
91
+ $v -> int
92
+ ).
93
+
94
+ // A reply pointer carried on a message: the stable wire id of the message
95
+ // being replied to, plus an optional 1-based sentence index into that
96
+ // message's text. wire_id is the stringified _new_id the sender stamped on
97
+ // the original (msg_id is receiver-local, so it cannot be referenced across
98
+ // sides). The recipient resolves this against its own copy of the referenced
99
+ // message IF it still holds it — agents GC fast, so this is best-effort
100
+ // context for the recipient, not durable thread state.
101
+ metadef reply_ref_t: ($wire_id -> str, $sentence -> int+).
102
+
103
+ // ---- local contact book wire shapes ---------------------------------
104
+ // Introduction credential, minted PER CONNECT ATTEMPT by the host's
105
+ // registrar packet (never stored in the book). It binds the joiner's
106
+ // identity AND address document to one target, with freshness + a nonce,
107
+ // so possession of book material alone authorizes nothing: only the
108
+ // registrar (whose key never leaves the host) can mint one, which is
109
+ // what makes "local" a cryptographic property rather than a convention.
110
+ metadef intro_t: (
111
+ $version -> int,
112
+ $joiner_cid -> global_id,
113
+ $joiner_ad_hash -> hash_code,
114
+ $target_cid -> global_id,
115
+ $iat -> time,
116
+ $nonce -> global_id
117
+ ).
118
+ metadef signed_intro_t: ($i -> intro_t, $s -> crypto_signature).
119
+ // What the registrar signs for a contact-book entry (tamper-evidence for
120
+ // the host-side book file; verified by the SENDER before connecting).
121
+ metadef book_entry_t: ($version -> int, $name -> str, $ad_hash -> hash_code).
122
+
123
+ // Verify a delegation chain presented by a peer: the root profile is
124
+ // internally consistent and the cert binds the peer's container id AND
125
+ // its address document to that root, both signed by the root's keys.
126
+ // The chain is self-contained (the profile carries the root's key list),
127
+ // so it proves "this role belongs to the root that signed it" — it does
128
+ // NOT vouch for who the root is (root verification is deferred to v2).
129
+ // Aborts on any mismatch; returns the linkage to record.
130
+ fn verify_peer_delegation (peer_cid: global_id, peer_ad_hash: hash_code, cert: delegation_cert_t, rp: root_profile_t) -> contact_root_t
131
+ {
132
+ abort "Unsupported delegation certificate version." when (cert $c $version) != 1.
133
+ abort "Unsupported root profile version." when (rp $p $version) != 1.
134
+ abort "Delegation certificate was issued for a different identity." when (cert $c $role_cid) != peer_cid.
135
+ abort "Delegation certificate does not match the peer's address document." when (cert $c $role_ad_hash) != peer_ad_hash.
136
+ abort "Root profile does not match the delegation certificate's root." when (rp $p $root_cid) != (cert $c $root_cid).
137
+ abort "Root profile signature is invalid." when key_storage::check_signature_new_container (_value_id (rp $p)) (rp $s) (rp $p $keys) != TRUE.
138
+ abort "Delegation certificate was not signed by its root." when key_storage::check_signature_new_container (_value_id (cert $c)) (cert $s) (rp $p $keys) != TRUE.
139
+ return ($root_cid -> cert $c $root_cid, $root_name -> rp $p $name, $role_id -> cert $c $role_id).
140
+ }
141
+
142
+ // (core 3.0: rebuild_peer_address_document was removed — the inviter's address
143
+ // document now travels whole, inside the boxed leg-1/leg-3 identity bundle, and
144
+ // is replayed directly through address_document::process_address_document; there
145
+ // is no longer a key-list-only invite to reconstruct an AD from.)
146
+
147
+ // ---- CP->root governance attestation (§3c, core 1.8) -----------------
148
+ // NON-enforcing visibility only — the sole monitoring gate stays the 6-digit
149
+ // proxy-bind ceremony. cid_cp is the CP's container_id, which IS the key-
150
+ // derived commitment over the CP's SIGN key (P3, adapt-toolkit #77:
151
+ // container_id == key_storage::address_of_key(sign_pub), a hash of the SIGN
152
+ // key alone — NOT _value_id of the whole key_list), so pinning cid_cp pins
153
+ // the CP's signing key and lazy resolution cannot substitute a different CP
154
+ // without breaking it.
155
+ metadef cp_attestation_commitment_t: (
156
+ $version -> int,
157
+ $cid_cp -> global_id
158
+ ).
159
+
160
+ // The lazily-resolved full attestation: the CP signs the ROOT's container_id
161
+ // (the key-derived commitment over the root's SIGN key, P3) — key material,
162
+ // never a label. cp_cid pins it to the same CP as the inline commitment.
163
+ metadef cp_attestation_core_t: (
164
+ $version -> int,
165
+ $root_cid -> global_id,
166
+ $cp_cid -> global_id
167
+ ).
168
+ metadef cp_attestation_t: ($c -> cp_attestation_core_t, $s -> crypto_signature).
169
+
170
+ // P3 (adapt-toolkit #77): container_id == key_storage::address_of_key(sign_pub)
171
+ // — a hash of the SIGN key alone, not _value_id of the whole key_list. This
172
+ // re-derives that commitment from an identity's own key material so
173
+ // verify_cp_attestation below stays a SELF-CONTAINED check (independent of
174
+ // whatever the caller already validated), mirroring address_document.mm's
175
+ // own "container id does not commit to signing key" check and
176
+ // identity_proof_document_impl.mm::validate.
177
+ fn _address_of_signing_key (key_list: key_utils::t_publickey(,), default_keys: key_utils::t_function->>key_utils::t_key_id) -> global_id
178
+ {
179
+ sign_key_id = default_keys $SIGN.
180
+ sign_pub IS publickey_sign+ = NIL.
181
+ sc key_list -- (k->) {
182
+ if _crypto_get_key_id k == sign_key_id {
183
+ sign_pub -> k SAFE(publickey_sign).
184
+ break.
185
+ }
186
+ }
187
+ abort "verify_cp_attestation: SIGN key not found in cp_ad key_list" WHEN sign_pub == NIL.
188
+ return key_storage::address_of_key sign_pub?.
189
+ }
190
+
191
+ // Verify a resolved §3c attestation. TRUE only when the commitment binds the
192
+ // CP keys (cp_ad's key-derived container_id AND its own re-derived
193
+ // address-of-SIGN-key both equal cid_cp), the attestation is pinned to that
194
+ // same CP, it attests the ACTUAL root, and it is CP-signed. The CALLER must
195
+ // have run process_address_document on cp_ad first (that enforces the CP AD
196
+ // proof-of-possession self-sig) and must render an UNRESOLVABLE cp_ad as
197
+ // present-but-unverified — never call this without a resolved, PoP-checked
198
+ // cp_ad.
199
+ fn verify_cp_attestation (commitment: cp_attestation_commitment_t, cp_ad: address_document_types::t_address_document, att: cp_attestation_t, root_cid: global_id) -> bool
200
+ {
201
+ return (commitment $version) == 1
202
+ && (att $c $version) == 1
203
+ && (cp_ad $identity $container_id) == (commitment $cid_cp)
204
+ && (_address_of_signing_key (cp_ad $identity $key_list) (cp_ad $identity $default_keys)) == (commitment $cid_cp)
205
+ && (att $c $cp_cid) == (commitment $cid_cp)
206
+ && (att $c $root_cid) == root_cid
207
+ && key_storage::check_signature_new_container (_value_id (att $c)) (att $s) (cp_ad $identity $key_list) == TRUE.
208
+ }
209
+
210
+ // ---- §3c root half: root-signed CP binding (core 1.9) ----------------
211
+ // The root self-signs its governance edge so peers TOFU-pin "root R is
212
+ // managed by CP cid_cp". A SEPARATE artifact from root_profile — keeps its
213
+ // signature and persisted state byte-identical (no migration, no sig
214
+ // invalidation), crypto-confirmed to preserve the §3c binding. Strip-evident
215
+ // only via TOFU: a genesis-time strip downgrades to a visible "no attestation
216
+ // present" — costs visibility, not security, since the edge is non-enforcing.
217
+ cp_attestation_context_tag = "ours:cp-attestation:v1".
218
+
219
+ // Verify the root half: root-signed and domain-separated, binding the root's
220
+ // OWN key-derived container_id (P3 — NEVER a free root_cid label, the D1
221
+ // trap) to the CP commitment. root_keys is the root key list the caller
222
+ // already pins (the delegation chain / root_ad), so this proves the EDGE,
223
+ // not who the root is.
224
+ fn verify_root_cp_binding (binding: root_cp_binding_t, root_cid: global_id, root_keys: key_utils::t_publickey(,)) -> bool
225
+ {
226
+ return (binding $c $version) == 1
227
+ && (binding $c $context_tag) == cp_attestation_context_tag
228
+ && (binding $c $root_cid) == root_cid
229
+ && key_storage::check_signature_new_container (_value_id (binding $c)) (binding $s) root_keys == TRUE.
230
+ }
231
+ }
@@ -0,0 +1,26 @@
1
+ // ours shared mufl core — compile configuration.
2
+ //
3
+ // Not compiled standalone: consumers (the MCP agent packet, the web
4
+ // messenger) pull these libraries in via `config_load #"core"` from their own
5
+ // config.mufl, with this repo checked out as a `core/` subfolder of their
6
+ // mufl_code/ directory.
7
+
8
+ config script
9
+ {
10
+ (
11
+ $exports ->
12
+ (
13
+ $libraries ->
14
+ (
15
+ $version -> #"version.mm",
16
+ $a2a_capabilities -> #"a2a_capabilities.mm",
17
+ $a2a_protocol -> #"a2a_protocol.mm",
18
+ $a2a_messaging -> #"a2a_messaging.mm",
19
+ $a2a_cluster -> #"a2a_cluster.mm",
20
+ $a2a_monitoring -> #"a2a_monitoring.mm",
21
+ $a2a_control -> #"a2a_control.mm"
22
+ ),
23
+ ),
24
+ $imports -> (config_load #$MUFL_STDLIB_PATH) $exports
25
+ ).
26
+ }
@@ -0,0 +1,268 @@
1
+ # ours mufl core — Configuration / Control-Plane release notes
2
+
3
+ Covers the generic configuration & control-plane features added to the shared
4
+ mufl core on branch `feat/core-config-control-plane` (core **1.10 → 2.0**).
5
+ Written for the engineers who will later wire these into the TS wrappers
6
+ (MCP daemon, browser messenger) and other ours apps. **No app integration is
7
+ included in this branch** — this is the protocol layer only.
8
+
9
+ > Status: implemented + compiles clean against the ADAPT toolkit. B1/B3 code
10
+ > reviewed GREEN by critic-1; B1 verified by ours-tester-1 (22/22 runtime +
11
+ > hostile-write + cold-channel). **B2 was radically simplified in core 2.0**
12
+ > (SAS / CP-signature / connect-descriptor machinery removed — see the B2 section);
13
+ > the simplified design reviewed GREEN by critic. No open questions for the
14
+ > dev/test track (the `outgoing_only` direction question is moot — policy was
15
+ > removed from the protocol entirely).
16
+
17
+ ## What shipped, by version
18
+
19
+ | Core | Feature |
20
+ |------|---------|
21
+ | 1.11 | **B1** — forced monitoring: copy generation in the core send/recv chokepoint + `a2a_monitoring` (CP-side receiver). |
22
+ | 1.12 | **B1 hardening** (hidden gate state, ceremony relocated into `a2a_messaging`) + **B3** — control-plane configuration (`set_app_config`). |
23
+ | 1.13 | **B2** — `core.connect` control-plane introduction of two managed nodes. |
24
+ | 1.14 | **B3 scope correction** — removed the typed per-contact policy / `outgoing_only` core enforcement; policy is app-level (human ruling). |
25
+ | 1.15 | **B2 revision** — (superseded by 2.0) non-repudiable CP-signed introduction reusing `signed_intro_t`. |
26
+ | **2.0** | **B2 radical simplification (BREAKING)** — removed SAS (`safety_number`/`pending_sas`/`confirm_introduction`/`list_pending_introductions`), the CP-signed intro path (`mint_cp_introduction`/`verify_cp_introduction`), and the `connect_descriptor_t` wrapper (`get_connect_descriptor`/`build_connect_descriptor`/`verify_connect_descriptor`). Introduction is now: CP relays each node the other's peer-signed address document; the node verifies the AD self-signature, that the relay came from its bound CP, and that its own manifest advertises `core.connect`, then registers immediately. New CP-side `introduce`/`introduce_to_group`; reworked node-side `ingest_connect_descriptor`. |
27
+
28
+ B1/B3 (1.11–1.15) were additive (no existing wire shape changed bytes) — MIN
29
+ bumps; a node compiled at an older core stayed wire-compatible. **Core 2.0 is a
30
+ MAJ bump**: it removes wire shapes and changes the `ingest_connect_descriptor`
31
+ payload, so consumers of the old `core.connect` surface must update (see
32
+ *Breaking changes* below). The monitoring/config surface is unchanged across 2.0.
33
+
34
+ ---
35
+
36
+ ## Already present before this work (context)
37
+
38
+ The manifest + capability surface the brief asked for already existed:
39
+
40
+ - `a2a_capabilities::app_manifest_t` = `(version, app_id, name, description, monitoring_status, capabilities)`, read via the readonly **`get_manifest`** transaction. `app_id` is also auto-stamped on every `a2a_control` message.
41
+ - Typed capabilities: `core.configuration`, `core.monitoring`, `core.connect`; verb envelope `(cap, verb, args, req_id)` + `dispatch`.
42
+ - `core.configuration` carries an **opaque JSON `$params`** (schema + values the frontend renders) with **secret-field redaction** (`secret_field_t`, `$set/$unset/$needs_reentry`, epoch auto-clear on CP change).
43
+ - `a2a_control` transport: `send_control(contact, payload)` + inbound `control_message` (origin + known-sender gated, `on_control_received` hook).
44
+ - Connect primitives existed in an earlier form (`connect_descriptor_t` + `verify_connect_descriptor`, `safety_number` SAS); **all removed in core 2.0** in favour of relaying peer-signed address documents directly (see the B2 section).
45
+
46
+ This work makes those usable as a **generic** control plane: forced monitoring,
47
+ a place to store/enforce config, and an introduction flow.
48
+
49
+ ---
50
+
51
+ ## B1 — Forced monitoring
52
+
53
+ **Goal:** once a control plane (CP) is bound, the node is protocol-forced to
54
+ re-encrypt and forward a copy of every chat message to it, and the app cannot
55
+ turn that off.
56
+
57
+ ### Where the enforcement lives (and why)
58
+ - Copy **generation** is unconditional core code in `a2a_messaging`’s
59
+ `send_message` and `handle_receive_message` (the single path every app routes
60
+ through) — **not** an app-injected hook (an app could no-op a hook).
61
+ - The **gate state** (`monitoring_proxy`, `proxy_pending`) is declared `hidden`
62
+ in `a2a_messaging`. `hidden` blocks external read **and** write, so no app or
63
+ other library can do `a2a_messaging::monitoring_proxy -> NIL` to disable
64
+ monitoring. Because hidden state is mutable only by its declaring library, the
65
+ bind ceremony + disable live **in `a2a_messaging`**.
66
+ - Copies are **fire-and-forget through the broker**: one
67
+ `encrypted_channel::send_encrypted_tx` to the proxy, no local queue, no
68
+ liveness handling. If the CP is offline the ADAPT broker holds the message.
69
+ - **Uniform rule:** `monitoring_proxy` bound ⇒ emit; else nothing. No
70
+ role-vs-root sink split.
71
+ - **No recursion:** the copy rides a distinct tx (`::a2a_monitoring::receive_monitoring_copy`), never `send_message`, so copies aren’t themselves monitored.
72
+ - **Re-encrypted:** ciphertext on the wire under the CP channel key.
73
+
74
+ ### Transactions (node side — `a2a_messaging`)
75
+ | Transaction | Origin | Args | Effect |
76
+ |---|---|---|---|
77
+ | `set_proxy_pending` | user (host) | `$code: str`, `$proxy: str (contact ref)` | Store the host-generated 6-digit code for a contact. |
78
+ | `verify_proxy_code` | user (host) | `$code: str`, `$sender: str (contact ref)` | Atomic verify (≤3 attempts, 300 s expiry, failures returned as **data** not aborts). On success sets `monitoring_proxy`. |
79
+ | `disable_monitoring` | **external** | — | CP-AUTHENTICATED: sender must be the bound proxy. Clears the binding. No user/app-callable clear exists. |
80
+ | `get_monitoring_status` | readonly | — | `($monitored, $proxy_pending, $proxy_cid)`. |
81
+ | `monitor_copy_actions` | (internal fn) | direction, peer_cid, date, body | Builds the fire-and-forget copy; self-gates on `monitoring_proxy`. |
82
+
83
+ ### Transactions (control-plane side — `a2a_monitoring`)
84
+ | Transaction | Origin | Args | Effect |
85
+ |---|---|---|---|
86
+ | `receive_monitoring_copy` | external | `$copy: monitoring_copy_t` | Known-contact-only; delegates storage to the `on_monitoring_copy_received` init hook. |
87
+
88
+ `monitoring_copy_t = (version, direction "out"/"in", peer_cid, peer_name, date, body)`.
89
+
90
+ ### Wrapper interaction
91
+ 1. The CP becomes a contact of the node (normal invite, Ring 3).
92
+ 2. Host/daemon runs `set_proxy_pending(code, cpContact)` (the daemon generates the 6-digit code, shows it host-side).
93
+ 3. Human enters the code in the CP UI → CP’s bind reaches the daemon → daemon calls `verify_proxy_code(code, cpContact)`.
94
+ 4. From then on every chat send/recv emits a copy to the CP. The CP packet handles `receive_monitoring_copy` and stores the feed via `on_monitoring_copy_received` (call `a2a_monitoring::init` with that hook).
95
+ 5. To stop: the CP sends `disable_monitoring` (only it can).
96
+
97
+ **Scope (v1):** copies cover **chat send/receive only** — contact establishment
98
+ and control traffic are out of the "all traffic" scope.
99
+
100
+ ---
101
+
102
+ ## B3 — Control-plane configuration (opaque only)
103
+
104
+ **Goal:** the bound CP configures the app from the rendered JSON schema. The core
105
+ **stores and transports** an opaque, app-custom config blob and bakes in **no
106
+ policy semantics whatsoever** — per-application policy (including anything like
107
+ "outgoing-only") is **application logic in the wrapper**, driven by the app's own
108
+ custom config schema, NOT a protocol feature (human ruling, 2026-06-17).
109
+
110
+ The bound CP (`monitoring_proxy`) is the configuration authority. `set_app_config`
111
+ is **external + CP-authenticated** via `require_bound_cp_or_abort` (sender must be
112
+ the bound proxy). `app_config` is **hidden** (so an app can’t rewrite its own
113
+ stored config).
114
+
115
+ ### Transactions (`a2a_messaging`)
116
+ | Transaction | Origin | Args | Effect |
117
+ |---|---|---|---|
118
+ | `set_app_config` | external (CP) | `$config: str` | Store the **opaque** JSON config blob (the core never parses it). Fires `$config_updated`. |
119
+ | `get_app_config` | readonly | — | `($config)`. |
120
+
121
+ That is the **entire** B3 protocol surface: opaque config storage + arbitrary
122
+ per-app JSON schemas. No typed policy, no core-enforced semantics.
123
+
124
+ ### MUFL vs wrapper split
125
+ - **Everything app-specific → wrapper.** `app_config` is owned by the TS wrapper.
126
+ On `$config_updated`, the wrapper pulls `get_app_config` and applies *all* of it
127
+ — operational config (e.g. telegram-connector: bot tokens, chat→contact routing)
128
+ AND any policy the app wants (e.g. "outgoing-only"). The core never maps
129
+ JSON↔mufl and enforces nothing app-specific.
130
+ - The core's only job here is to **transport + store** the opaque blob (hidden,
131
+ CP-gated, persisted) and notify the wrapper to re-apply.
132
+
133
+ ### Wrapper interaction
134
+ 1. CP renders `core.configuration`’s `$params` schema, user fills it.
135
+ 2. CP sends `set_app_config(json)` → node stores it, fires `$config_updated`.
136
+ 3. Wrapper pulls `get_app_config` and applies it (operational + any app policy).
137
+
138
+ ---
139
+
140
+ ## B2 — `core.connect` control-plane introduction (core 2.0, simplified)
141
+
142
+ **Goal:** the CP, bound to two nodes that aren’t in each other’s contacts,
143
+ introduces them (e.g. set node B as a proxy for telegram-connector A).
144
+
145
+ **Design (radically simple).** The CP already holds each managed node’s
146
+ peer-signed address document in `peer_ads` (captured when the node bound the CP).
147
+ An introduction is therefore just: **send each node the other’s signed AD.** The
148
+ receiving node verifies the AD’s own self-signature, that the relay came from its
149
+ bound CP, and that its own manifest still advertises `core.connect`, then registers
150
+ the contact immediately. There is **no SAS, no confirmation step, and no CP
151
+ signature on the introduction** — the bound-CP channel *is* the authorization, and
152
+ the node-side capability gate is the authoritative “do I accept introductions”.
153
+
154
+ ### Flow
155
+ 1. Daemon pre-check (CP side): pull `get_manifest` for A and B; **refuse to
156
+ introduce if EITHER lacks `core.connect`** (prevents a half-open pairing). This
157
+ is daemon logic, not core.
158
+ 2. CP calls `introduce(A, B)` (host-fired, user origin). The core looks up
159
+ `peer_ads[A]` and `peer_ads[B]` and emits, in one transaction, two encrypted
160
+ relays to `ingest_connect_descriptor`: A receives B’s signed AD (+ B’s CP-supplied
161
+ display name) and B receives A’s.
162
+ 3. Each node’s `ingest_connect_descriptor` (external, encrypted):
163
+ - `require_bound_cp_or_abort(sender)` — the relay must come from my bound CP;
164
+ - **node-side capability gate** — abort unless `a2a_capabilities::self_supports("core.connect")`
165
+ (reads the live `describe()` manifest). This is the authoritative enforcement.
166
+ - `process_address_document(peer_ad, TRUE)` — re-checks the peer’s **own**
167
+ self-signatures (proof-of-possession; aborts on a forged/inconsistent AD before
168
+ any write — `TRUE` only relaxes external-authorizing-container trust, not the
169
+ self-signature);
170
+ - registers the peer (contact + `peer_ads`) under the CP-supplied name (cid as a
171
+ last resort) and fires `$introduced` (`container_id, name, by_cp`).
172
+ - **Idempotent re-introduction:** if the peer is already a contact, it only
173
+ refreshes the stored AD and keeps the existing name (`$reintroduced` — never a
174
+ downgrade or rename).
175
+
176
+ `introduce_to_group(joiner, members)` is the cluster-root fan-out: for each member
177
+ it emits the same pair of relays as `introduce(joiner, member)`, all in one
178
+ transaction — the natural “new subagent joins, give it everyone” primitive.
179
+
180
+ ### Transactions (`a2a_messaging`)
181
+ | Transaction | Origin | Args | Effect |
182
+ |---|---|---|---|
183
+ | `introduce` | user (CP host) | `$peer_a: str`, `$peer_b: str` (contact refs) | Emits the two signed-AD relays to A and B. Aborts if either is not an established contact (no `peer_ads`) or if `a == b`. |
184
+ | `introduce_to_group` | user (CP host) | `$joiner: str`, `$members: str[]` | Emits `introduce(joiner, member)` relays for every member, one transaction. |
185
+ | `ingest_connect_descriptor` | external (CP) | `$peer_ad: t_address_document`, `$peer_name: str` | Node-side: CP-sender gate + node capability gate + AD self-sig (PoP), then register; `$introduced` / `$reintroduced` notify. |
186
+
187
+ The node-side inbound is the dedicated tx `::a2a_messaging::ingest_connect_descriptor`
188
+ (NOT routed through the `a2a_capabilities` verb dispatcher).
189
+
190
+ ### Security notes
191
+ - **`core.connect` in the manifest means “I ACCEPT introductions” — not “my AD is
192
+ never relayed / I am undiscoverable”.** A node’s address document is public
193
+ (invite-equivalent), so the boolean does not hide it. The half-open preventer is
194
+ the **daemon pre-check**, which must refuse if *either* party lacks support (not
195
+ just the recipient). The node-side gate then independently enforces acceptance.
196
+ - The CP-supplied `$peer_name` is an **unauthenticated** display label (receiver-
197
+ chosen); the AD self-signature is the only authenticated identity the receiver
198
+ trusts. Never key an enforcement decision on the name.
199
+ - Trust model: the node trusts its **bound CP** to introduce honestly (no SAS).
200
+ This is deliberate — the same governance/honesty class as the monitoring bind and
201
+ the README §8 self-assertion limit, documented not oversold.
202
+
203
+ ### Wrapper interaction
204
+ The daemon orchestrates: (1) `get_manifest(A)` + `get_manifest(B)`, refuse if either
205
+ lacks `core.connect`; (2) call `introduce(A, B)`; (3) the core emits both signed-AD
206
+ relays; (4) each node’s `ingest_connect_descriptor` gates and registers. The CP
207
+ never holds the A↔B channel keys (fresh DH between A and B on first message).
208
+
209
+ ---
210
+
211
+ ## Out of scope / deferred
212
+
213
+ - **Governance-attestation layer** (`cp_attestation_t` 1.8 / `root_cp_binding_t`
214
+ 1.9 / invite threading 1.10): kept **off the critical path** per the human’s
215
+ ruling — out-of-scope-pending-founder-review. B1/B2/B3 do not depend on it.
216
+ - Frontend per-app-name rendering (B4) — a different repo (messenger).
217
+ - **Per-application policy (e.g. "outgoing-only") — explicitly OUT of the
218
+ protocol** (human ruling). The core provides opaque config + arbitrary per-app
219
+ schemas; it bakes in no app-specific semantics. Apps implement policy in the
220
+ wrapper from their own config.
221
+ - Generic JSON↔mufl config auto-mapping.
222
+ - App integration / daemon wiring in any consuming repo.
223
+
224
+ > Note: the standalone `signed_intro_t` CP-signed introduction path (briefly
225
+ > required and implemented in core 1.15 as `mint_cp_introduction` /
226
+ > `verify_cp_introduction`) was **removed in core 2.0** when B2 was simplified to
227
+ > bound-CP-channel authorization. The underlying `intro_t` / `signed_intro_t` /
228
+ > `book_entry_t` shapes remain in `a2a_protocol` — they are the out-of-repo
229
+ > local-book registrar credential, now unused inside this repo (kept; prune later
230
+ > if confirmed dead).
231
+
232
+ ## Breaking changes in core 2.0 (B2 simplification)
233
+
234
+ Consumers of the old `core.connect` surface MUST absorb:
235
+
236
+ - **`ingest_connect_descriptor` payload changed**: `{$descriptor (connect_descriptor_t blob), $intro (signed_intro_t blob)}` → `{$peer_ad (t_address_document), $peer_name (str)}`.
237
+ - **`$introduced` notify shrank**: it no longer carries `$sas` or `$monitoring_status` — just `$container_id, $name, $by_cp`. Any agent/UI reading `$sas` must update.
238
+ - **Removed transactions**: `get_connect_descriptor`, `mint_cp_introduction`, `confirm_introduction`, `list_pending_introductions`. The messenger’s SAS / pending-confirm UI and any flow calling these must be reworked (introductions are now established immediately, with no confirm step).
239
+ - **New CP-side transactions**: `introduce(A, B)`, `introduce_to_group(joiner, members)`. The daemon drives these after its `get_manifest` pre-check (refuse if either party lacks `core.connect`).
240
+ - **`a2a_capabilities::init` is now a hard prerequisite on the ingest path**: the node-side gate calls the live `describe()` hook via `self_supports`, so an uninitialised `describe` **fails closed** (aborts the ingest). “Supports introductions” is `core.connect` present in `describe()`’s live manifest `$capabilities` map — NOT the `init` `$supported` list.
241
+
242
+ ## Integration TODO for consumers (when this lands)
243
+
244
+ - The monitoring bind ceremony + status moved to **`::a2a_messaging::`**
245
+ (`set_proxy_pending`, `verify_proxy_code`, `disable_monitoring`,
246
+ `get_monitoring_status`) — update any daemon that addressed them at
247
+ `::a2a_monitoring::`.
248
+ - A control-plane packet must call `a2a_monitoring::init($on_monitoring_copy_received)`
249
+ to receive the feed.
250
+ - `config.mufl` now exports `a2a_monitoring`; consumers’ core checkout must include it.
251
+ - **`core.connect`**: the daemon must `get_manifest`-pre-check both parties and call
252
+ `introduce` (see *Breaking changes* above); the node packet must wire
253
+ `a2a_capabilities::init` (describe hook advertising `core.connect`) or it will
254
+ reject all introductions.
255
+
256
+ ## Open questions
257
+
258
+ None outstanding for the dev/test track.
259
+
260
+ - **`outgoing_only` direction** — moot: the typed contact policy was removed
261
+ entirely (human ruling 2026-06-17). Per-app policy is application logic in the
262
+ wrapper, driven by the app's own custom config schema; the core stores only the
263
+ opaque blob.
264
+ - **B2 authorization model** — RESOLVED (core 2.0): the non-repudiable CP-signed
265
+ introduction (`signed_intro_t`, core 1.15) was **removed** when the human ruled
266
+ for a radically simpler design. Authorization is now the bound-CP channel itself
267
+ plus the node-side `core.connect` capability gate; no SAS, no per-introduction
268
+ signature. (The 1.15 CP-signed path was the prior decision, now superseded.)