@sjawhar/pi-legion-envoy 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.
package/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # Pi Envoy Extension
2
+
3
+ Tracked Oh My Pi extension for Envoy messaging. It shares the Envoy HTTP client, tool
4
+ contract, envelope parsing, and subject helpers with the other Legion adapters while keeping
5
+ OMP's direct NATS subscriptions and Pi steering delivery local (inbound messages steer an
6
+ in-flight turn instead of queueing behind it).
7
+
8
+ Normal topic subscriptions are direct NATS subscriptions owned by this extension. A role claim is
9
+ different: the listener arbitrates the core-NATS role lane for the current live holder, then sends
10
+ a receipt-backed request with the original role topic to the holder's direct agent subject. The
11
+ agent pump replies after accepting the envelope; without a receipt within two seconds the listener
12
+ emits a `delivery_failed` exception. Role messages are live only; they are not retained for a later
13
+ claimant.
14
+
15
+ `envoy_list()` shows the union of the local subscriptions and the listener's persisted interest
16
+ registry. Each reported interest identifies whether it is `live`, `registry`, or `both`, so
17
+ temporary registration drift does not hide the extension's actual delivery state.
18
+
19
+ ## Session identity
20
+
21
+ Run `/whoami` to copy the active session ID to the clipboard. OMP copies through its host
22
+ clipboard API, which sends OSC 52
23
+ first for tmux and SSH sessions. The notification shows the session ID even if the copy fails.
24
+
25
+ For tmux to accept OSC 52 clipboard writes, enable clipboard support in the tmux server:
26
+
27
+ ```tmux
28
+ set -g set-clipboard on
29
+ ```
30
+
31
+ ## Development install
32
+
33
+ This package declares two OMP extension entries in `package.json`: `extensions/envoy.ts`
34
+ (Envoy messaging, subscriptions, and steering delivery) and `extensions/legion.ts` (the
35
+ Legion lifecycle: root bootstrap, worker spawning, budgets, and daemon capabilities).
36
+ Loading the package directory with OMP's `--extension` flag — as the Legion daemon does
37
+ when it launches trees and workers — loads both.
38
+
39
+ For local development of the messaging extension alone, link the entry into OMP:
40
+
41
+ ```sh
42
+ ln -sfn "$PWD/packages/pi-envoy/extensions/envoy.ts" \
43
+ ~/.omp/agent/extensions/envoy.ts
44
+ ```
45
+
46
+ The repository root `package.json` likewise loads only `extensions/envoy.ts` for dev
47
+ sessions inside this repo: the Legion extension is meant to be loaded by the daemon with
48
+ its environment prepared, not by ambient dev sessions.
49
+
50
+ ## Published package
51
+
52
+ Released installs come from npm as `@sjawhar/pi-legion-envoy`. The tarball is
53
+ self-contained: it ships only `dist/envoy.js` — bundling every dependency except the
54
+ OMP host package — and the repo `skills/` tree staged beside it at `dist/skills` so
55
+ `resources_discover` serves the Legion skills from the installed package. The published
56
+ manifest exposes only `dist/envoy.js` — matching the repository root — while the
57
+ committed manifest keeps the TypeScript entries for repo checkouts; `extensions/legion.ts`
58
+ is daemon infrastructure and is not packed at all.
59
+
60
+ `.github/workflows/release-pi-envoy.yaml` performs that manifest rewrite around
61
+ `bun pm pack` and restores the committed file before tagging. Packing with the committed
62
+ source manifest is refused by `scripts/prepack.sh`, because such a tarball would point
63
+ OMP at extension files it does not contain.
64
+
65
+ ## Dispatch
66
+
67
+ Legion sessions use the `envoy_dispatch` tool from `extensions/legion.ts`: it routes through
68
+ the Legion daemon's architect-only, tree-scoped `/legion/v1/dispatch-threads` endpoint, which
69
+ also registers the thread so replies route back to the tree. The raw dispatch MCP tool is
70
+ deliberately not served to Legion sessions — the shared shim exits without serving when it
71
+ sees a Legion environment (`LEGION_TREE`/`LEGION_CONTROLLER`), so phase workers cannot bypass
72
+ the architect gate with ambient GitHub authority.
73
+
74
+ Interactive OMP sessions get the `dispatch` MCP tool the way OpenCode sessions do: the shared
75
+ `@legion/envoy-client` shim mounts as a stdio MCP server, and it serves only when
76
+ `dispatch.enabled` is true in the shared envoy.json (`~/.config/opencode/envoy.json`,
77
+ shallow-merged with `<cwd>/.opencode/envoy.json`) or `DISPATCH_MCP_URL` is set explicitly.
78
+ The server URL comes from `dispatch.serverUrl` (default `http://localhost:8766`).
79
+
80
+ Mount it in `~/.omp/agent/mcp.json` (user-wide) or `.omp/mcp.json` (per project):
81
+
82
+ ```json
83
+ {
84
+ "mcpServers": {
85
+ "dispatch": {
86
+ "command": "bun",
87
+ "args": ["<checkout>/packages/envoy-client/bin/dispatch-mcp-shim.ts"]
88
+ }
89
+ }
90
+ }
91
+ ```
92
+
93
+ The shim forwards newline-delimited JSON-RPC from stdin to the dispatch server's Streamable
94
+ HTTP `/mcp` endpoint with a cached GitHub bearer from the user's `gh` shim. The
95
+ bearer refreshes before expiry and retries once immediately after a 401 response.