UTCP Peer and JPEN-as-Tool
UTCP Peer and JPEN-as-Tool
Section titled “UTCP Peer and JPEN-as-Tool”Call tools under capability gates over SBI TCP. Stage a JPEN envelope and
apply it as pipeline.envelope.apply.
Time: 30 minutes
Level: Intermediate
Profile: :core for peer; :cluster when packing live JPEN
Prerequisites: Basic Janus, SBI, cluster promises (for JPEN section)
Why UTCP?
Section titled “Why UTCP?”Agents and services need a tool RPC that cannot skip capability checks. REST-ish JSON over TCP is easy to sketch and hard to trust. Janus native UTCP (SPEC-244) uses the same SBI wire family as the rest of the stack.
In-process first
Section titled “In-process first”{.profile: core.}
use std.utcp.registry as registryuse std.utcp.session as session
pub func main() -> i32 do _ = registry.reset() let tid = registry.register_compile_module_demo() let s = session.open() // Missing caps → CAP_MISMATCH (-1403) _ = session.invoke(s, tid) _ = session.present_known(s, 0) _ = session.present_known(s, 1) // Full caps → OK (1) _ = session.invoke(s, tid) _ = session.close(s) return 0endPeer over TCP
Section titled “Peer over TCP”use std.utcp.peer as peer
let port = peer.listen(0)_ = peer.start_accept_pool(1, 1)let h = peer.client_connect(port)_ = peer.client_present2(h, 0, 1)_ = peer.client_invoke(h, tool_id)_ = peer.client_close(h)_ = peer.join()_ = peer.close_listen()Session protocol on one connection:
- PRESENT — accumulate caps
- STAGE (optional) — binary payload (JPEN, LEAS, or CHNK chunks)
- INVOKE — cap check + tool dispatch
- RESET — clear caps and stage
Wire and interop modes (HTTP / JSON-line vs normative SBI):
UTCP over SBI.
Discovery without JSON: invoke utcp.manual (no caps) and read the MANL
body via peer.client_last_has_manl / client_manual_*.
JPEN as a tool
Section titled “JPEN as a tool”Requires :cluster to pack a live pipeline envelope, then UTCP to carry it:
- Pack JPEN with
std.cluster.promise(pipeline_envelope_pack_scratch). - Enable cluster peer CAP for apply.
- Register
pipeline.envelope.apply(intern index 2). client_stagethe bytes,client_presentpipeline cap,client_invoke.
Proof: ./scripts/zb test-utcp-jpen-tool.
- Concurrent clients:
start_accept_pool(n, workers)+ multiple handles - Reference: std.utcp
- Spec: SPEC-244 (project
_COMPLETED/)