ceulen 0.8.0 → 0.10.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/CHANGELOG.md +72 -0
- package/extensions/lib/registry.ts +16 -3
- package/extensions/modules/a2a/configPanel.ts +435 -0
- package/extensions/modules/a2a/index.ts +1117 -0
- package/extensions/modules/a2a/lib/activity.ts +173 -0
- package/extensions/modules/a2a/lib/client.ts +1061 -0
- package/extensions/modules/a2a/lib/config.ts +920 -0
- package/extensions/modules/a2a/lib/discovery.ts +158 -0
- package/extensions/modules/a2a/lib/gateway.ts +889 -0
- package/extensions/modules/a2a/lib/mdns.ts +233 -0
- package/extensions/modules/a2a/lib/outcome.ts +48 -0
- package/extensions/modules/a2a/lib/persistence.ts +123 -0
- package/extensions/modules/a2a/lib/protocol.ts +506 -0
- package/extensions/modules/a2a/lib/registry.ts +146 -0
- package/extensions/modules/a2a/lib/retry.ts +86 -0
- package/extensions/modules/a2a/lib/security.ts +394 -0
- package/extensions/modules/a2a/lib/server.ts +1436 -0
- package/extensions/modules/a2a/test/activity.test.ts +138 -0
- package/extensions/modules/a2a/test/bridge.test.ts +101 -0
- package/extensions/modules/a2a/test/broadcast-parse.test.ts +31 -0
- package/extensions/modules/a2a/test/chai.ts +101 -0
- package/extensions/modules/a2a/test/client.test.ts +856 -0
- package/extensions/modules/a2a/test/completion-guard.test.ts +73 -0
- package/extensions/modules/a2a/test/config.test.ts +1396 -0
- package/extensions/modules/a2a/test/configPanel.test.ts +393 -0
- package/extensions/modules/a2a/test/discovery.test.ts +144 -0
- package/extensions/modules/a2a/test/extension.test.ts +135 -0
- package/extensions/modules/a2a/test/gateway.test.ts +1449 -0
- package/extensions/modules/a2a/test/helpers.ts +39 -0
- package/extensions/modules/a2a/test/mdns.test.ts +131 -0
- package/extensions/modules/a2a/test/outcome.test.ts +61 -0
- package/extensions/modules/a2a/test/persistence.test.ts +92 -0
- package/extensions/modules/a2a/test/protocol.test.ts +217 -0
- package/extensions/modules/a2a/test/registry.test.ts +114 -0
- package/extensions/modules/a2a/test/retry.test.ts +136 -0
- package/extensions/modules/a2a/test/security.test.ts +281 -0
- package/extensions/modules/a2a/test/server.test.ts +1966 -0
- package/extensions/modules/a2a/test/tmp.ts +59 -0
- package/extensions/modules/a2a/test/vendor.test.ts +57 -0
- package/extensions/modules/a2a/types/bonjour-service.d.ts +22 -0
- package/extensions/modules/a2a/vendor/VENDORED.md +18 -0
- package/extensions/modules/a2a/vendor/package.json +1 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/LICENSE +23 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/index.d.ts +14 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/index.js +57 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/KeyValue.d.ts +4 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/KeyValue.js +3 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/bonjour.d.ts +13 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/bonjour.js +50 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/browser.d.ts +41 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/browser.js +209 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/dns-txt.d.ts +9 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/dns-txt.js +42 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/mdns-server.d.ts +14 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/mdns-server.js +119 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/registry.d.ts +14 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/registry.js +142 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/service-types.d.ts +7 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/service-types.js +53 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/service.d.ts +58 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/service.js +130 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/dns-equal.d.ts +1 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/dns-equal.js +13 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/equal-txt.d.ts +1 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/equal-txt.js +17 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/filter-service.d.ts +4 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/filter-service.js +22 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/filter-txt.d.ts +3 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/filter-txt.js +6 -0
- package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/LICENSE +21 -0
- package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/classes.js +23 -0
- package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/index.js +1761 -0
- package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/opcodes.js +50 -0
- package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/optioncodes.js +59 -0
- package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/rcodes.js +50 -0
- package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/types.js +103 -0
- package/extensions/modules/a2a/vendor/vendored_deps/fast-deep-equal/LICENSE +21 -0
- package/extensions/modules/a2a/vendor/vendored_deps/fast-deep-equal/es6.js +73 -0
- package/extensions/modules/a2a/vendor/vendored_deps/fast-deep-equal/index.js +46 -0
- package/extensions/modules/a2a/vendor/vendored_deps/ip-codec/LICENSE +21 -0
- package/extensions/modules/a2a/vendor/vendored_deps/ip-codec/index.cjs +250 -0
- package/extensions/modules/a2a/vendor/vendored_deps/multicast-dns/LICENSE +21 -0
- package/extensions/modules/a2a/vendor/vendored_deps/multicast-dns/index.js +205 -0
- package/extensions/modules/a2a/vendor/vendored_deps/thunky/LICENSE +21 -0
- package/extensions/modules/a2a/vendor/vendored_deps/thunky/index.js +55 -0
- package/extensions/modules/composer/test/module.test.ts +2 -2
- package/extensions/modules/config/index.ts +3 -0
- package/extensions/modules/config/test/renderTools.test.ts +1 -1
- package/extensions/modules/gh/configPanel.ts +82 -0
- package/extensions/modules/gh/index.ts +86 -0
- package/extensions/modules/gh/lib/gh-cli.ts +337 -0
- package/extensions/modules/gh/lib/ops.ts +771 -0
- package/extensions/modules/gh/test/gh.test.ts +280 -0
- package/extensions/modules/plan/lib/plan-tools.ts +8 -0
- package/extensions/modules/repair/index.ts +138 -0
- package/extensions/modules/repair/lib/guards.ts +1 -1
- package/extensions/modules/repair/lib/read-selector.ts +242 -0
- package/extensions/modules/repair/test/read-selector.test.ts +198 -0
- package/extensions/modules/steering/configPanel.ts +8 -0
- package/extensions/modules/steering/index.ts +6 -0
- package/extensions/modules/steering/lib/settings.ts +6 -2
- package/extensions/modules/steering/lib/think.ts +66 -0
- package/extensions/modules/steering/test/harness.ts +5 -0
- package/extensions/modules/steering/test/settings.test.ts +2 -0
- package/extensions/modules/steering/test/think.test.ts +77 -0
- package/extensions/modules/todo/configPanel.ts +55 -0
- package/extensions/modules/todo/index.ts +46 -13
- package/extensions/modules/todo/lib/render.ts +271 -0
- package/extensions/modules/todo/lib/settings.ts +73 -0
- package/extensions/modules/todo/test/todo.test.ts +276 -0
- package/extensions/modules/web/index.ts +37 -1
- package/extensions/modules/web/lib/a11y.ts +252 -0
- package/extensions/modules/web/test/a11y.test.ts +218 -0
- package/extensions/modules/web/test/extension.test.ts +2 -2
- package/extensions/modules/web/test/hook.test.ts +2 -2
- package/extensions/modules/web/vendor/axe/LICENSE +362 -0
- package/extensions/modules/web/vendor/axe/LICENSE-3RD-PARTY.txt +66 -0
- package/extensions/modules/web/vendor/axe/README.md +19 -0
- package/extensions/modules/web/vendor/axe/axe.min.js +12 -0
- package/package.json +2 -2
- package/skills/a2a/SKILL.md +63 -0
- package/skills/web/SKILL.md +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,77 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.10.0 — 2026-10-05
|
|
4
|
+
|
|
5
|
+
- **gh module**: new module — ONE read-only `github` tool over the `gh` CLI
|
|
6
|
+
(port of oh-my-pi's github tool surface): `repo_view`, `file_read`,
|
|
7
|
+
`pr_view`, `pr_diff`, the five `search_*` flavors (issues/prs/code/commits/
|
|
8
|
+
repos, with repo:/org:/user: scope detection + since/until qualifiers), and
|
|
9
|
+
`run_watch` (lean JSON poller with failed-job log tails; budget
|
|
10
|
+
`gh.runWatchTimeoutSecs`, default 600s, on /config → Tools → GitHub).
|
|
11
|
+
Zero npm deps (`node:child_process` spawn, non-interactive env, 5-min
|
|
12
|
+
deadline, 8-MB output cap, one runner seam); fails open on a missing `gh`
|
|
13
|
+
binary. Mutating flows (pr_create/checkout/push) deliberately deferred to
|
|
14
|
+
bash `gh` — plan-mode auto-allow stays valid via READ_ONLY_TOOLS.
|
|
15
|
+
|
|
16
|
+
- **Read path selectors** (repair module): the wrapped `read` accepts OMP-style
|
|
17
|
+
suffixes — `:50`, `:50-200`, `:50+150`, `:50-`, `:-60`, comma-joined
|
|
18
|
+
multi-ranges (`:5-16,960-973`, `:19,59`), `:raw` compounds, and `:conflicts`
|
|
19
|
+
(one block per unresolved merge conflict). Literal-path-wins resolution (OMP
|
|
20
|
+
#4618); multi-range/conflicts slice in-memory with `[lines … of N]` headers.
|
|
21
|
+
|
|
22
|
+
- **think scratchpad tool** (steering module): OMP-parity private scratchpad,
|
|
23
|
+
opt-in via `steering.thinkTool` (default off; binds at load — autoBg
|
|
24
|
+
precedent). The call renders as one dim `· think (N chars)` marker so
|
|
25
|
+
planning notes stay out of the visible transcript while remaining in context
|
|
26
|
+
for later rounds. OMP's externalThinking reasoning-suppression is NOT ported
|
|
27
|
+
(providers flag the request shape as abuse; pi's thinking levels are the
|
|
28
|
+
honest off-switch).
|
|
29
|
+
|
|
30
|
+
- **web_a11y** (web module, 12th tool): real rendered-page accessibility audit
|
|
31
|
+
— axe-core 4.13 vendored unmodified (`vendor/axe/`, MPL-2.0, lazy-loaded,
|
|
32
|
+
zero new deps) injected into local headless Chrome over the existing
|
|
33
|
+
web_interact CDP lifecycle. Returns OMP-format violation reports (impact,
|
|
34
|
+
rule, helpUrl, node targets, `… and N more`); `tags`/`rules`/`selector`/
|
|
35
|
+
`include_incomplete` params; same-origin iframes only (axe walks them
|
|
36
|
+
in-page). The runtime complement to `ux_audit`'s static CSS checks. In-page
|
|
37
|
+
failures ride back through the evaluate value (the CDP connection layer
|
|
38
|
+
drops top-level exceptionDetails).
|
|
39
|
+
|
|
40
|
+
## 0.9.0 — 2026-10-04
|
|
41
|
+
|
|
42
|
+
- **todo HUD**: OMP-parity live UI for the todo module — an above-editor
|
|
43
|
+
widget (same placement as the subagent HUD) rendering the board as a
|
|
44
|
+
nested tree (` └─ Tasks · n/m` head over ` ├─/└─` checkbox rows),
|
|
45
|
+
where every connector turns accent once its phase completes — the
|
|
46
|
+
completed tree reads as one lit progress path. Done rows stay visible
|
|
47
|
+
(success green + strikethrough), the current phase draws mdLink blue,
|
|
48
|
+
blocked rows warning + `(blocked by …)`, notes collapse to `+n`.
|
|
49
|
+
The transcript tool-result row draws the same colored board. When ALL
|
|
50
|
+
phases complete the board lingers `todo.lingerSecs` seconds (global
|
|
51
|
+
settings.json, default 60; 0 = instant, −1 = never; closed-set row on
|
|
52
|
+
`/config` → Tasks → Todo), then auto-clears; any new mutation cancels
|
|
53
|
+
the timer. The LLM-facing tool-result text stays the plain board.
|
|
54
|
+
|
|
55
|
+
- **a2a**: new module — the A2A Protocol v1.0 bidirectional peer ported from
|
|
56
|
+
`@bacnh85/pi-a2a` 0.7.13: 7 outbound tools (`a2a_call` with
|
|
57
|
+
`async_dispatch`, `a2a_status`, `a2a_discover`, `a2a_list`, `a2a_history`,
|
|
58
|
+
`a2a_orchestrate`, `a2a_peers`), 8 commands, the opt-in inbound server
|
|
59
|
+
(`/a2a-server start`, isolated child sessions, transcripts, audit log,
|
|
60
|
+
anti-loop, per-peer tokens), and local/mDNS/gateway discovery. `bonjour-service`
|
|
61
|
+
is vendored (flat `vendor/vendored_deps/`, no `node_modules` path) — zero new
|
|
62
|
+
runtime deps. Settings live on the **Tasks** tab of the central `/config`
|
|
63
|
+
panel (`A2A` + `A2A peers & discovery` sections); upstream's `/a2a-config`
|
|
64
|
+
is dropped, and the project `.pi/settings.json` is read only when trusted
|
|
65
|
+
(security keys stay global-only even then).
|
|
66
|
+
- **a2a fixes found against a live switchboard**: gateway-proxied peers
|
|
67
|
+
(`gw/<key>/<name>`) are never card-fetched — the proxied card advertises the
|
|
68
|
+
peer's DIRECT url, which routed dispatches around the gateway and tripped the
|
|
69
|
+
SSRF guard; `a2a_call`/`a2a_status`/`a2a_orchestrate` now pin to the proxy
|
|
70
|
+
URL. `a2a_discover` on a configured gateway origin is allowlisted and sends
|
|
71
|
+
that gateway's token (the proxy 401s an anonymous card fetch).
|
|
72
|
+
The `/config` add/remove action rows re-prompt with the reason on invalid
|
|
73
|
+
input instead of returning silently.
|
|
74
|
+
|
|
3
75
|
## 0.8.0 — 2026-10-04
|
|
4
76
|
|
|
5
77
|
- **todo**: new module (OMP port) — phased task tracking: one `todo` tool
|
|
@@ -26,7 +26,10 @@ import subagentModule from "../modules/subagent/index.ts";
|
|
|
26
26
|
import { subagentConfig } from "../modules/subagent/configPanel.js";
|
|
27
27
|
import planModule from "../modules/plan/index.ts";
|
|
28
28
|
import { planConfig } from "../modules/plan/configPanel.js";
|
|
29
|
+
import a2aModule from "../modules/a2a/index.ts";
|
|
30
|
+
import { a2aConfig } from "../modules/a2a/configPanel.js";
|
|
29
31
|
import todoModule from "../modules/todo/index.ts";
|
|
32
|
+
import { todoConfig } from "../modules/todo/configPanel.ts";
|
|
30
33
|
import steeringModule from "../modules/steering/index.ts";
|
|
31
34
|
import { steeringConfig } from "../modules/steering/configPanel.js";
|
|
32
35
|
import repairModule from "../modules/repair/index.ts";
|
|
@@ -39,6 +42,8 @@ import muninModule from "../modules/munin/index.ts";
|
|
|
39
42
|
import { muninConfig } from "../modules/munin/configPanel.ts";
|
|
40
43
|
import webModule from "../modules/web/index.ts";
|
|
41
44
|
import { webConfig } from "../modules/web/configPanel.ts";
|
|
45
|
+
import ghModule from "../modules/gh/index.ts";
|
|
46
|
+
import { ghConfig } from "../modules/gh/configPanel.js";
|
|
42
47
|
import rulesModule from "../modules/rules/index.ts";
|
|
43
48
|
import configModule from "../modules/config/index.ts";
|
|
44
49
|
|
|
@@ -122,7 +127,11 @@ export const MODULES: ModuleEntry[] = [
|
|
|
122
127
|
// (sandbox: read-only) and its before_agent_start must compose BEFORE
|
|
123
128
|
// steering (the last prompt rewriter — see its entry below).
|
|
124
129
|
{ name: "plan", category: "Tasks", describe: "Read-only plan mode: /plan toggle, tool gating, write_plan + ask_user_question, plan model/thinking, approval handoff.", load: planModule, config: planConfig, tools: ["write_plan", "ask_user_question"] },
|
|
125
|
-
|
|
130
|
+
// A2A after plan: cross-agent delegation (the remote sibling of subagent).
|
|
131
|
+
// No before_agent_start → no prompt-rewrite ordering constraint; its
|
|
132
|
+
// child sessions reuse the host-only session guards in the module.
|
|
133
|
+
{ name: "a2a", category: "Tasks", describe: "A2A Protocol v1.0 peer: call remote agents (a2a_call…), be called by them (opt-in inbound server), local/mDNS/gateway discovery.", load: a2aModule, config: a2aConfig, tools: ["a2a_call", "a2a_status", "a2a_discover", "a2a_list", "a2a_history", "a2a_orchestrate", "a2a_peers"] },
|
|
134
|
+
{ name: "todo", category: "Tasks", describe: "Phased task board: the `todo` tool (init/start/done/block/unblock) with session persistence, blockers, an above-editor HUD, and a status-segment progress readout.", load: todoModule, config: todoConfig, tools: ["todo"] },
|
|
126
135
|
// ── Tools ─────────────────────────────────────────────────────────────
|
|
127
136
|
// Repair first in the section: it wraps the built-in tools; serena/fff ride
|
|
128
137
|
// on top (no load-order dependency — hooks resolve at call time).
|
|
@@ -143,9 +152,13 @@ export const MODULES: ModuleEntry[] = [
|
|
|
143
152
|
// (conditional on web_* tools being active) — no prompt-rewrite contract
|
|
144
153
|
// beyond fff's shipped precedent.
|
|
145
154
|
{ name: "web", category: "Tools", describe: "Unified web tools: search (SearXNG/Brave/Firecrawl), extract & crawl (JSDOM/Firecrawl/Crawl4AI/agy), screenshot/PDF, CDP browser interaction, Gemini research, image generation, one-off chat.", load: webModule, config: webConfig, tools: [
|
|
146
|
-
"web_search", "web_extract", "web_map", "web_crawl", "web_screenshot", "web_pdf", "web_interact", "web_research", "web_image", "web_chat", "web_status",
|
|
155
|
+
"web_search", "web_extract", "web_map", "web_crawl", "web_screenshot", "web_pdf", "web_interact", "web_research", "web_image", "web_chat", "web_status", "web_a11y",
|
|
147
156
|
] },
|
|
148
157
|
{ name: "rules", category: "Context", describe: "Sticky RULES.md constraints carried in every request + a rulebook of on-demand rules served by rule_get. Nearest-first project walk over user-level.", load: rulesModule, tools: ["rule_get"] },
|
|
158
|
+
// gh after web: same class of external-fetch tooling; fail-open on a missing
|
|
159
|
+
// gh binary (registers nothing until installed). Read-only ops only, so
|
|
160
|
+
// plan mode auto-allows it (plan-tools.ts READ_ONLY_TOOLS).
|
|
161
|
+
{ name: "gh", category: "Tools", describe: "GitHub tool over the gh CLI: repo/file/PR views, PR diff, five search flavors, Actions run_watch. Read-only; mutating flows stay on bash gh.", load: ghModule, config: ghConfig, tools: ["github"] },
|
|
149
162
|
// Steering LAST of the prompt rewriters, i.e. after EVERY before_agent_start
|
|
150
163
|
// composer (ponytail/plan/subagent/munin/advisor/ux/fff/serena/web/rules) and
|
|
151
164
|
// before the config module (load order is load-bearing even though its
|
|
@@ -155,7 +168,7 @@ export const MODULES: ModuleEntry[] = [
|
|
|
155
168
|
// (byte-identical minimal prompt) instead of appending to a prompt that
|
|
156
169
|
// serena/web then append to. Nothing after this entry (rtk, config) touches
|
|
157
170
|
// the prompt — do not move it earlier or add a prompt rewriter after it.
|
|
158
|
-
{ name: "steering", category: "Model", describe: "Per-model-family steering (DeepSeek/GLM): first-tool hints, reasoning strip, leak cleaning, error recovery hints, DeepSeek guidance + v4-pro minimal-mode anchor.", load: steeringModule, config: steeringConfig },
|
|
171
|
+
{ name: "steering", category: "Model", describe: "Per-model-family steering (DeepSeek/GLM): first-tool hints, reasoning strip, leak cleaning, error recovery hints, DeepSeek guidance + v4-pro minimal-mode anchor.", load: steeringModule, config: steeringConfig, tools: ["think"] },
|
|
159
172
|
// ── Shell ──────────────────────────────────────────────────────────────
|
|
160
173
|
{ name: "rtk", category: "Shell", describe: "Route shell commands through RTK for token savings.", load: rtkModule },
|
|
161
174
|
// ── Plugins ────────────────────────────────────────────────────────────
|
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
// a2a's /config contribution — Tasks tab, A2A sections (📡).
|
|
2
|
+
//
|
|
3
|
+
// ceulen port: upstream @bacnh85/pi-a2a 0.7.13 shipped its own /a2a-config
|
|
4
|
+
// panel over @bacnh85/pi-config-panel — DROPPED here, the central /config
|
|
5
|
+
// panel owns A2A settings (web-module pattern). Rows are keyed `a2a.*`; the
|
|
6
|
+
// Enable row + per-tool toggles are prepended/appended by the config module
|
|
7
|
+
// (withEnableRow/withToolRows over the registry entry).
|
|
8
|
+
//
|
|
9
|
+
// Save path reuses upstream's pure patch builder (buildA2ASettingsPatch) +
|
|
10
|
+
// writer (writeSettingsA2A): env-sourced secrets are never copied to disk
|
|
11
|
+
// unless their exact row was edited, gateway blocks survive unrelated edits,
|
|
12
|
+
// peer timeouts convert settings-seconds → runtime-ms on the write side.
|
|
13
|
+
// Live apply via setConfigOverrides (config is read per call — no /reload),
|
|
14
|
+
// and a running inbound server restarts through the index.ts bridge when
|
|
15
|
+
// server/discovery config changed.
|
|
16
|
+
|
|
17
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
18
|
+
import { row, toInt, type PanelGroup } from "../../lib/panel.js";
|
|
19
|
+
import type { ModuleConfig } from "../../lib/registry.js";
|
|
20
|
+
import { isProjectTrusted } from "../../lib/registry.js";
|
|
21
|
+
import {
|
|
22
|
+
buildA2ASettingsPatch,
|
|
23
|
+
loadConfig,
|
|
24
|
+
setConfigOverrides,
|
|
25
|
+
writeSettingsA2A,
|
|
26
|
+
GATEWAY_KEY_RE,
|
|
27
|
+
type A2AConfig,
|
|
28
|
+
type GatewayEntry,
|
|
29
|
+
type Peer,
|
|
30
|
+
} from "./lib/config.js";
|
|
31
|
+
import { a2aServerRunning as a2aServerRunningIndex, restartA2AServer as restartA2AServerIndex } from "./index.js";
|
|
32
|
+
|
|
33
|
+
/** Restart bridge — defaults to the index.ts exports; tests inject via
|
|
34
|
+
* __setRestartBridgeForTests (the panel must not spin real servers). */
|
|
35
|
+
const bridge = {
|
|
36
|
+
a2aServerRunning: (): boolean => a2aServerRunningIndex(),
|
|
37
|
+
restartA2AServer: (piApi: ExtensionAPI, ctx: ExtensionContext): Promise<void> => restartA2AServerIndex(piApi, ctx),
|
|
38
|
+
};
|
|
39
|
+
/** Test seam. */
|
|
40
|
+
export function __setRestartBridgeForTests(over: { a2aServerRunning: () => boolean; restartA2AServer: (pi: ExtensionAPI, ctx: ExtensionContext) => Promise<void> } | null): void {
|
|
41
|
+
bridge.a2aServerRunning = over?.a2aServerRunning ?? ((): boolean => a2aServerRunningIndex());
|
|
42
|
+
bridge.restartA2AServer = over?.restartA2AServer ?? ((pi2: ExtensionAPI, ctx2: ExtensionContext) => restartA2AServerIndex(pi2, ctx2));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The inline prompt the panel kernel hands an action row. */
|
|
46
|
+
type ActionPrompt = (label: string, onDone: (value: string | undefined) => void) => void;
|
|
47
|
+
|
|
48
|
+
/** Env vars that shadow a saved field — disclosed in the save notify when the
|
|
49
|
+
* edited field's env override is set (web-module env-disclosure pattern). */
|
|
50
|
+
const ENV_SHADOW: Record<string, string> = {
|
|
51
|
+
"server.enabled": "A2A_SERVER_ENABLED",
|
|
52
|
+
"server.port": "A2A_PORT",
|
|
53
|
+
"server.portFallback": "A2A_PORT_FALLBACK",
|
|
54
|
+
"server.host": "A2A_HOST",
|
|
55
|
+
"server.agentName": "A2A_AGENT_NAME",
|
|
56
|
+
"server.replyTimeoutSec": "A2A_REPLY_TIMEOUT",
|
|
57
|
+
"server.asyncTimeoutSec": "A2A_ASYNC_TIMEOUT",
|
|
58
|
+
"server.maxConcurrent": "A2A_MAX_CONCURRENT",
|
|
59
|
+
"server.maxPingpongTurns": "A2A_MAX_PINGPONG_TURNS",
|
|
60
|
+
"server.rateLimitPerMin": "A2A_RATE_LIMIT",
|
|
61
|
+
"server.allowAllUsers": "A2A_ALLOW_ALL_USERS",
|
|
62
|
+
"server.childTranscripts": "A2A_CHILD_TRANSCRIPTS",
|
|
63
|
+
"server.childTranscriptRetentionDays": "A2A_CHILD_TRANSCRIPT_RETENTION_DAYS",
|
|
64
|
+
selfIdentity: "A2A_SELF_IDENTITY",
|
|
65
|
+
"discovery.local.enabled": "A2A_DISCOVERY_LOCAL",
|
|
66
|
+
"discovery.local.heartbeatSec": "A2A_HEARTBEAT_SEC",
|
|
67
|
+
"discovery.local.ttlSec": "A2A_TTL_SEC",
|
|
68
|
+
"discovery.mdns.enabled": "A2A_DISCOVERY_MDNS",
|
|
69
|
+
"discovery.mdns.serviceType": "A2A_MDNS_TYPE",
|
|
70
|
+
"discovery.enrichCard": "A2A_ENRICH_CARD",
|
|
71
|
+
"ui.transcript": "A2A_UI_TRANSCRIPT",
|
|
72
|
+
"gateway.url": "A2A_GATEWAY_URL",
|
|
73
|
+
"gateway.token": "A2A_GATEWAY_TOKEN",
|
|
74
|
+
"gateway.enabled": "A2A_GATEWAY_ENABLED",
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/** Read a dotted settings path off a config object ("a2a." already stripped). */
|
|
78
|
+
function pathValue(cfg: A2AConfig, key: string): unknown {
|
|
79
|
+
let cur: any = cfg;
|
|
80
|
+
for (const part of key.split(".")) {
|
|
81
|
+
if (cur == null || typeof cur !== "object") return undefined;
|
|
82
|
+
cur = cur[part];
|
|
83
|
+
}
|
|
84
|
+
return cur;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Set a dotted path on the working config (row setters). */
|
|
88
|
+
function setPathValue(cfg: A2AConfig, key: string, value: unknown): void {
|
|
89
|
+
const parts = key.split(".");
|
|
90
|
+
let cur: any = cfg;
|
|
91
|
+
for (const part of parts.slice(0, -1)) {
|
|
92
|
+
if (cur[part] == null || typeof cur[part] !== "object") cur[part] = {};
|
|
93
|
+
cur = cur[part];
|
|
94
|
+
}
|
|
95
|
+
cur[parts[parts.length - 1]!] = value;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Build the two A2A panel groups over the working config (mutated by row
|
|
99
|
+
* setters). Exported for tests. `onMutate` flags structural edits from
|
|
100
|
+
* action rows (peers/gateways) — they change the config without editing a
|
|
101
|
+
* row key, and the save path needs to know. */
|
|
102
|
+
export function buildA2AGroups(
|
|
103
|
+
working: A2AConfig,
|
|
104
|
+
hooks: {
|
|
105
|
+
markPeerChange: () => void;
|
|
106
|
+
markGatewayChange: () => void;
|
|
107
|
+
},
|
|
108
|
+
): PanelGroup[] {
|
|
109
|
+
const rowFor = (
|
|
110
|
+
key: string, // after "a2a."
|
|
111
|
+
label: string,
|
|
112
|
+
kind: "toggle" | "string" | "number",
|
|
113
|
+
opts: Parameters<typeof row>[5] = {},
|
|
114
|
+
) =>
|
|
115
|
+
row(
|
|
116
|
+
`a2a.${key}`,
|
|
117
|
+
label,
|
|
118
|
+
kind,
|
|
119
|
+
pathValue(working, key),
|
|
120
|
+
(v) => {
|
|
121
|
+
setPathValue(working, key, kind === "number" ? toInt(v, Number(pathValue(working, key) ?? 0)) : v);
|
|
122
|
+
},
|
|
123
|
+
opts,
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
// Panel key namespaces (gw.<key>.*, gateway.*, peer.<name>.*) do NOT mirror
|
|
127
|
+
// config paths (discovery.gateways.<key>.*, peers.<name>.*) — these rows use
|
|
128
|
+
// EXPLICIT setters mutating the entry objects (upstream panel pattern), not
|
|
129
|
+
// the generic path helper.
|
|
130
|
+
const gatewayEntryRows = (prefix: string, get: () => GatewayEntry, view: GatewayEntry): ReturnType<typeof row>[] => [
|
|
131
|
+
row(`a2a.${prefix}.enabled`, "Registration", "toggle", view.enabled, (v) => {
|
|
132
|
+
get().enabled = Boolean(v);
|
|
133
|
+
hooks.markGatewayChange();
|
|
134
|
+
}),
|
|
135
|
+
row(`a2a.${prefix}.url`, "Gateway URL", "string", view.url, (v) => {
|
|
136
|
+
get().url = String(v ?? "");
|
|
137
|
+
hooks.markGatewayChange();
|
|
138
|
+
}),
|
|
139
|
+
row(`a2a.${prefix}.token`, "API token", "string", view.token ?? "", (v) => {
|
|
140
|
+
get().token = String(v ?? "");
|
|
141
|
+
hooks.markGatewayChange();
|
|
142
|
+
}, { mask: true, description: "Gateway API token. Edit to replace — empty submit is a no-op; unedited tokens are never copied to disk from env." }),
|
|
143
|
+
row(`a2a.${prefix}.name`, "Peer name", "string", view.name ?? "", (v) => {
|
|
144
|
+
get().name = v ? String(v) : undefined;
|
|
145
|
+
hooks.markGatewayChange();
|
|
146
|
+
}, { description: "Optional registration name override (default <agentName>-<port>)." }),
|
|
147
|
+
row(`a2a.${prefix}.upstreamToken`, "Upstream token", "string", view.upstreamToken ?? "", (v) => {
|
|
148
|
+
get().upstreamToken = v ? String(v) : undefined;
|
|
149
|
+
hooks.markGatewayChange();
|
|
150
|
+
}, { mask: true, description: "Optional token the gateway presents when proxying TO this session." }),
|
|
151
|
+
row(`a2a.${prefix}.heartbeatSec`, "Heartbeat (s)", "number", view.heartbeatSec ?? 60, (v) => {
|
|
152
|
+
get().heartbeatSec = toInt(v, get().heartbeatSec ?? 60);
|
|
153
|
+
hooks.markGatewayChange();
|
|
154
|
+
}),
|
|
155
|
+
row(`a2a.${prefix}.channel`, "Reverse channel", "toggle", view.channel ?? true, (v) => {
|
|
156
|
+
get().channel = Boolean(v);
|
|
157
|
+
hooks.markGatewayChange();
|
|
158
|
+
}, { description: "Open a reverse channel so firewalled peers can call this session." }),
|
|
159
|
+
];
|
|
160
|
+
|
|
161
|
+
// Materializing accessors (upstream panel pattern): setters materialize the
|
|
162
|
+
// block on first edit so a toggle/URL entry creates it in the working config
|
|
163
|
+
// without clobbering an env-sourced gateway on unrelated edits.
|
|
164
|
+
const gwView = working.discovery.gateway ?? { enabled: false, url: "", token: "" };
|
|
165
|
+
const gw = () => (working.discovery.gateway ??= { enabled: false, url: "", token: "" });
|
|
166
|
+
// "Live" = any field differs from the inert placeholder loadConfig
|
|
167
|
+
// materializes — an inert block renders nothing (upstream parity).
|
|
168
|
+
const gatewayLive =
|
|
169
|
+
working.discovery.gateway != null &&
|
|
170
|
+
(Boolean(gwView.enabled) || Boolean(gwView.url) || Boolean(gwView.token) ||
|
|
171
|
+
gwView.name != null || gwView.upstreamToken != null ||
|
|
172
|
+
(gwView.heartbeatSec ?? 60) !== 60 || (gwView.channel ?? true) !== true);
|
|
173
|
+
|
|
174
|
+
const serverRows: ReturnType<typeof row>[] = [
|
|
175
|
+
rowFor("server.enabled", "Server enabled", "toggle", {
|
|
176
|
+
warning:
|
|
177
|
+
"Security-relevant keys (enabled/host/tokens) are read from GLOBAL settings/env only — a project settings file cannot enable the server.",
|
|
178
|
+
description: "Auto-start the inbound A2A server on session start (host sessions only). /a2a-server start|stop manages it live.",
|
|
179
|
+
}),
|
|
180
|
+
rowFor("server.port", "Port", "number", { defaultValue: 9910, description: "Inbound port. If busy, climbs port+1…+portFallback, then OS-assigned." }),
|
|
181
|
+
rowFor("server.portFallback", "Port fallback", "number", { defaultValue: 10, description: "Consecutive ports to try when the configured port is busy. 0 = configured port only, then OS-assigned." }),
|
|
182
|
+
rowFor("server.host", "Bind host", "string", {
|
|
183
|
+
defaultValue: "127.0.0.1",
|
|
184
|
+
warning: "Widen to 0.0.0.0 ONLY with a shared token set — remote exposure requires a bearer token AND an explicit host.",
|
|
185
|
+
}),
|
|
186
|
+
rowFor("server.agentName", "Agent name", "string", { description: "Name on the Agent Card (default <hostname>-<port> once started)." }),
|
|
187
|
+
rowFor("server.maxConcurrent", "Max concurrent", "number", { defaultValue: 3, description: "Max concurrent inbound tasks (blocking AND detached — each detached run pins a slot until it reaches a terminal state)." }),
|
|
188
|
+
rowFor("server.replyTimeoutSec", "Reply timeout (s)", "number", { defaultValue: 300, description: "Blocking-send reply window in seconds. 0 = unbounded (request stays open until the run settles)." }),
|
|
189
|
+
rowFor("server.asyncTimeoutSec", "Async timeout (s)", "number", { defaultValue: 86400, description: "Supervision window for detached (returnImmediately) tasks; the kill switch that frees a pinned concurrency slot. 0 = caller-supervised." }),
|
|
190
|
+
rowFor("server.maxPingpongTurns", "Max ping-pong turns", "number", { defaultValue: 5, description: "Anti-loop turn cap per context (max 20)." }),
|
|
191
|
+
rowFor("server.rateLimitPerMin", "Rate limit /min", "number", { defaultValue: 60, description: "Requests/minute per authenticated identity." }),
|
|
192
|
+
rowFor("server.allowAllUsers", "Allow all users", "toggle", {
|
|
193
|
+
defaultValue: false,
|
|
194
|
+
warning: "Dev only — admits any authenticated peer.",
|
|
195
|
+
}),
|
|
196
|
+
rowFor("server.childTranscripts", "Child transcripts", "toggle", { defaultValue: true, description: "Persist each dispatched child session's transcript to <agentDir>/a2a_sessions/ (forensic step history). Off = in-memory only." }),
|
|
197
|
+
rowFor("server.childTranscriptRetentionDays", "Transcript retention (days)", "number", { defaultValue: 30, description: "Delete child transcripts older than N days on server start. 0 = keep forever (transcripts carry everything the worker read)." }),
|
|
198
|
+
rowFor("selfIdentity", "Caller identity", "string", { description: "This session's outbound caller identity — a key in server.peerTokens (settings.json/env; not editable here). Empty = shared token (anonymous caller)." }),
|
|
199
|
+
rowFor("ui.transcript", "Transcript messages", "toggle", { defaultValue: true, description: "Show inbound task activity as transcript messages. Off = toasts + footer only." }),
|
|
200
|
+
];
|
|
201
|
+
|
|
202
|
+
// Peers group rows: one URL row per configured peer + add/remove actions.
|
|
203
|
+
const peerRows: ReturnType<typeof row>[] = Object.entries(working.peers).map(([name, p]) => {
|
|
204
|
+
const peer = p as Peer;
|
|
205
|
+
return row(`a2a.peer.${name}.url`, `Peer ${name} URL`, "string", peer.url, (v) => {
|
|
206
|
+
peer.url = String(v ?? "");
|
|
207
|
+
hooks.markPeerChange();
|
|
208
|
+
}, {
|
|
209
|
+
description: peer.description
|
|
210
|
+
? `${peer.url ? "" : "URL not set. "}${peer.capabilities.length ? `Capabilities: ${peer.capabilities.join(", ")}.` : "No capabilities advertised."}`
|
|
211
|
+
: "Peer endpoint. Auth tokens/capabilities are settings.json-only (a2a.peers.<name>), not editable here.",
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
peerRows.push({
|
|
215
|
+
key: "a2a.action.addPeer",
|
|
216
|
+
label: "+ Add peer",
|
|
217
|
+
kind: "action",
|
|
218
|
+
value: undefined,
|
|
219
|
+
set: (prompt: ActionPrompt) => {
|
|
220
|
+
// Re-prompt with the reason on bad input — a silent return reads as a
|
|
221
|
+
// dead panel (the reported "only the key prompt shows" confusion).
|
|
222
|
+
// Esc (undefined) or empty first answer = cancel.
|
|
223
|
+
const askUrl = (name: string, hint?: string) =>
|
|
224
|
+
prompt(hint ?? "Peer URL (http://…)", (url) => {
|
|
225
|
+
if (url === undefined) return;
|
|
226
|
+
if (!url.trim()) return void askUrl(name, `URL required — Peer URL for '${name}'`);
|
|
227
|
+
working.peers[name] = { url: url.trim(), auth: { type: "none" }, timeout: 120000, capabilities: [] };
|
|
228
|
+
hooks.markPeerChange();
|
|
229
|
+
});
|
|
230
|
+
const askName = (hint?: string) =>
|
|
231
|
+
prompt(hint ?? "Peer name", (name) => {
|
|
232
|
+
if (!name) return;
|
|
233
|
+
if (working.peers[name]) return void askName(`'${name}' exists — another name (Esc, then edit its URL row)`);
|
|
234
|
+
askUrl(name);
|
|
235
|
+
});
|
|
236
|
+
askName();
|
|
237
|
+
},
|
|
238
|
+
});
|
|
239
|
+
peerRows.push({
|
|
240
|
+
key: "a2a.action.removePeer",
|
|
241
|
+
label: "− Remove peer",
|
|
242
|
+
kind: "action",
|
|
243
|
+
value: undefined,
|
|
244
|
+
set: (prompt: ActionPrompt) => {
|
|
245
|
+
const names = Object.keys(working.peers);
|
|
246
|
+
if (names.length === 0) return;
|
|
247
|
+
const ask = (hint?: string) =>
|
|
248
|
+
prompt(hint ?? `Remove peer (${names.join(", ")})`, (pick) => {
|
|
249
|
+
if (!pick) return;
|
|
250
|
+
if (!working.peers[pick]) return void ask(`No peer '${pick}' — one of: ${names.join(", ")}`);
|
|
251
|
+
delete working.peers[pick];
|
|
252
|
+
hooks.markPeerChange();
|
|
253
|
+
});
|
|
254
|
+
ask();
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
// Gateways map rows: one block per configured entry + add/remove actions.
|
|
259
|
+
const gwMapRows: ReturnType<typeof row>[] = [];
|
|
260
|
+
for (const [key, entry] of Object.entries(working.discovery.gateways ?? {})) {
|
|
261
|
+
const g = () => (working.discovery.gateways![key] ??= { enabled: false, url: "", token: "" });
|
|
262
|
+
gwMapRows.push(...gatewayEntryRows(`gw.${key}`, () => g()!, entry).map((r) => r));
|
|
263
|
+
}
|
|
264
|
+
gwMapRows.push({
|
|
265
|
+
key: "a2a.action.addGateway",
|
|
266
|
+
label: "+ Add gateway",
|
|
267
|
+
kind: "action",
|
|
268
|
+
value: undefined,
|
|
269
|
+
set: (prompt: ActionPrompt) => {
|
|
270
|
+
// Same re-prompt-with-reason discipline as addPeer: a pasted URL or a
|
|
271
|
+
// space in the key must bounce with an explanation, not die silently.
|
|
272
|
+
const askUrl = (key: string, hint?: string) =>
|
|
273
|
+
prompt(hint ?? `Gateway URL for '${key}'`, (url) => {
|
|
274
|
+
if (url === undefined) return;
|
|
275
|
+
if (!url.trim()) return void askUrl(key, `URL required — Gateway URL for '${key}'`);
|
|
276
|
+
prompt(`API token for '${key}' (Enter = none)`, (token) => {
|
|
277
|
+
if (token === undefined) return;
|
|
278
|
+
working.discovery.gateways ??= {};
|
|
279
|
+
working.discovery.gateways[key] = { enabled: true, url: url.trim(), token: token.trim() };
|
|
280
|
+
hooks.markGatewayChange();
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
const askKey = (hint?: string) =>
|
|
284
|
+
prompt(hint ?? "Gateway key (letters/digits/._-, e.g. work)", (key) => {
|
|
285
|
+
if (!key) return;
|
|
286
|
+
if (!GATEWAY_KEY_RE.test(key)) return void askKey(`Invalid key '${key}' — letters/digits/._- only`);
|
|
287
|
+
if (working.discovery.gateways?.[key]) return void askKey(`'${key}' exists — another key (Esc, then edit its rows)`);
|
|
288
|
+
askUrl(key);
|
|
289
|
+
});
|
|
290
|
+
askKey();
|
|
291
|
+
},
|
|
292
|
+
});
|
|
293
|
+
gwMapRows.push({
|
|
294
|
+
key: "a2a.action.removeGateway",
|
|
295
|
+
label: "− Remove gateway",
|
|
296
|
+
kind: "action",
|
|
297
|
+
value: undefined,
|
|
298
|
+
set: (prompt: ActionPrompt) => {
|
|
299
|
+
const keys = Object.keys(working.discovery.gateways ?? {});
|
|
300
|
+
if (keys.length === 0) return;
|
|
301
|
+
const ask = (hint?: string) =>
|
|
302
|
+
prompt(hint ?? `Remove gateway (${keys.join(", ")})`, (pick) => {
|
|
303
|
+
if (!pick) return;
|
|
304
|
+
if (!working.discovery.gateways?.[pick]) return void ask(`No gateway '${pick}' — one of: ${keys.join(", ")}`);
|
|
305
|
+
delete working.discovery.gateways[pick];
|
|
306
|
+
hooks.markGatewayChange();
|
|
307
|
+
});
|
|
308
|
+
ask();
|
|
309
|
+
},
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
return [
|
|
313
|
+
{ key: "a2a", label: "A2A", tab: "Tasks", icon: "📡", rows: serverRows },
|
|
314
|
+
{
|
|
315
|
+
key: "a2a-net",
|
|
316
|
+
label: "A2A peers & discovery",
|
|
317
|
+
tab: "Tasks",
|
|
318
|
+
rows: [
|
|
319
|
+
rowFor("discovery.local.enabled", "Local registry", "toggle", { defaultValue: true, description: "Local file registry (<agentDir>/a2a_registry/) — instant same-machine discovery." }),
|
|
320
|
+
rowFor("discovery.local.heartbeatSec", "Heartbeat (s)", "number", { defaultValue: 15, description: "Registry heartbeat interval." }),
|
|
321
|
+
rowFor("discovery.local.ttlSec", "Registry TTL (s)", "number", { defaultValue: 60, description: "Registry entry TTL before stale-sweep." }),
|
|
322
|
+
rowFor("discovery.mdns.enabled", "mDNS broadcast", "toggle", { defaultValue: false, description: "LAN discovery via _a2a._tcp (vendored bonjour; announces a unique <hostname>-a2a-<pid> name so it cannot rename your Mac)." }),
|
|
323
|
+
rowFor("discovery.mdns.serviceType", "mDNS service type", "string", { defaultValue: "a2a", description: "Advertised as _<type>._tcp." }),
|
|
324
|
+
rowFor("discovery.enrichCard", "Enrich Agent Card", "toggle", {
|
|
325
|
+
defaultValue: true,
|
|
326
|
+
warning: "Publishes cwd/pid/model into the Agent Card metadata.",
|
|
327
|
+
}),
|
|
328
|
+
// Legacy single gateway block (env/settings-sourced) — hidden when inert.
|
|
329
|
+
...(gatewayLive
|
|
330
|
+
? gatewayEntryRows("gateway", () => gw()!, gwView).map((r) => r)
|
|
331
|
+
: []),
|
|
332
|
+
...peerRows,
|
|
333
|
+
...gwMapRows,
|
|
334
|
+
],
|
|
335
|
+
},
|
|
336
|
+
];
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const A2A_ENV_NAMES = new Set(Object.values(ENV_SHADOW).concat(["A2A_BEARER_TOKEN", "A2A_PEER_TOKENS", "A2A_PUBLIC_URL", "A2A_VERIFY_SSL", "A2A_RETRY", "A2A_TRUSTED_PEERS"]));
|
|
340
|
+
|
|
341
|
+
/** a2a's ModuleConfig for the central /config panel. The factory receives the
|
|
342
|
+
* module's OWN guarded pi (loader contract) and threads it to the restart
|
|
343
|
+
* bridge. Working copy + change flags live in the closure; save() diffs
|
|
344
|
+
* against the pre-open snapshot (upstream /a2a-config save semantics). */
|
|
345
|
+
export function a2aConfig(pi: ExtensionAPI): ModuleConfig {
|
|
346
|
+
const before = loadConfig({ cwd: process.cwd() });
|
|
347
|
+
const working = structuredClone(before);
|
|
348
|
+
let peerChanges = false;
|
|
349
|
+
let gatewayChanged = false;
|
|
350
|
+
|
|
351
|
+
return {
|
|
352
|
+
groups: () => buildA2AGroups(working, {
|
|
353
|
+
markPeerChange: () => {
|
|
354
|
+
peerChanges = true;
|
|
355
|
+
},
|
|
356
|
+
markGatewayChange: () => {
|
|
357
|
+
gatewayChanged = true;
|
|
358
|
+
},
|
|
359
|
+
}),
|
|
360
|
+
save: async (edited, ctx) => {
|
|
361
|
+
// Diff-based gate: action rows mutate structure without editing a row
|
|
362
|
+
// key, so editedKeys alone under-reports (makeOnAction marks dirty,
|
|
363
|
+
// which triggers this save; the diff decides whether anything changed).
|
|
364
|
+
peerChanges ||= JSON.stringify(working.peers) !== JSON.stringify(before.peers);
|
|
365
|
+
gatewayChanged ||=
|
|
366
|
+
JSON.stringify(working.discovery.gateway ?? null) !== JSON.stringify(before.discovery.gateway ?? null) ||
|
|
367
|
+
JSON.stringify(working.discovery.gateways ?? null) !== JSON.stringify(before.discovery.gateways ?? null);
|
|
368
|
+
const ownedKeyEdited = [...edited].some((k) => k.startsWith("a2a."));
|
|
369
|
+
if (!ownedKeyEdited && !peerChanges && !gatewayChanged) return;
|
|
370
|
+
|
|
371
|
+
const editedGatewayKeys = new Set(
|
|
372
|
+
[...edited]
|
|
373
|
+
.filter((k) => k.startsWith("a2a.gateway.") || k.startsWith("a2a.gw."))
|
|
374
|
+
.map((k) => k.slice("a2a.".length)),
|
|
375
|
+
);
|
|
376
|
+
const builtPatch = buildA2ASettingsPatch({
|
|
377
|
+
cfg: before,
|
|
378
|
+
working,
|
|
379
|
+
peerChanges,
|
|
380
|
+
gatewayChanged,
|
|
381
|
+
editedGatewayKeys,
|
|
382
|
+
});
|
|
383
|
+
const written = writeSettingsA2A({
|
|
384
|
+
cwd: ctx.cwd,
|
|
385
|
+
patch: builtPatch,
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
// Live apply — config is read per call; no /reload needed.
|
|
389
|
+
setConfigOverrides({
|
|
390
|
+
peers: working.peers,
|
|
391
|
+
selfIdentity: working.selfIdentity,
|
|
392
|
+
server: working.server,
|
|
393
|
+
discovery: working.discovery,
|
|
394
|
+
ui: working.ui,
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
const notes = [`A2A config saved to ${written} — applied live.`];
|
|
398
|
+
// Env overrides still shadowing edited fields.
|
|
399
|
+
const envOverrides = [...edited]
|
|
400
|
+
.map((k) => (k.startsWith("a2a.") ? ENV_SHADOW[k.slice("a2a.".length)] : undefined))
|
|
401
|
+
.filter((v): v is string => v !== undefined && process.env[v] !== undefined);
|
|
402
|
+
if (envOverrides.length) notes.push(`Still overridden by env: ${[...new Set(envOverrides)].join(", ")}.`);
|
|
403
|
+
if (A2A_ENV_NAMES.has("A2A_BEARER_TOKEN") && process.env.A2A_BEARER_TOKEN && edited.has("a2a.server.enabled")) {
|
|
404
|
+
// sharedToken comes from env; enabling the server is still token-gated.
|
|
405
|
+
notes.push("Server shared token comes from A2A_BEARER_TOKEN / settings.json server.sharedToken.");
|
|
406
|
+
}
|
|
407
|
+
// Trusted project shadow disclosure (web-module pattern).
|
|
408
|
+
if (ctx.isProjectTrusted?.() === true) {
|
|
409
|
+
const project = loadConfig({ cwd: ctx.cwd });
|
|
410
|
+
void project;
|
|
411
|
+
try {
|
|
412
|
+
const fs = await import("node:fs");
|
|
413
|
+
const raw = JSON.parse(fs.readFileSync(`${ctx.cwd}/.pi/settings.json`, "utf-8")) as { a2a?: unknown };
|
|
414
|
+
if (raw?.a2a && typeof raw.a2a === "object") {
|
|
415
|
+
notes.push("A trusted project .pi/settings.json a2a section also applies (security keys sanitized).");
|
|
416
|
+
}
|
|
417
|
+
} catch {
|
|
418
|
+
/* no project file */
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
ctx.ui.notify(notes.join(" "), "info");
|
|
422
|
+
|
|
423
|
+
// Restart the running inbound server when server/discovery config changed.
|
|
424
|
+
const restartChanged =
|
|
425
|
+
JSON.stringify(working.server) !== JSON.stringify(before.server) ||
|
|
426
|
+
JSON.stringify(working.discovery) !== JSON.stringify(before.discovery);
|
|
427
|
+
if (restartChanged && bridge.a2aServerRunning()) {
|
|
428
|
+
await bridge.restartA2AServer(pi, ctx);
|
|
429
|
+
}
|
|
430
|
+
},
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/** Exposed for tests. */
|
|
435
|
+
export { GATEWAY_KEY_RE };
|