@nelsonlongxiang/dsh-open-a2a-net 0.6.28 → 0.6.30
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 +87 -14
- package/README_zh.md +83 -7
- package/assets/nexusDist/assets/index-C_x3iAth.js +9 -0
- package/assets/nexusDist/assets/index-Dz8N80tI.css +1 -0
- package/assets/nexusDist/index.html +2 -2
- package/cli/a2a.mjs +0 -0
- package/cordis.patch.yml +21 -21
- package/lib/canvas-store.js +21 -1
- package/lib/client.js +64 -64
- package/lib/client.js.map +1 -1
- package/lib/faces/admin.js +755 -0
- package/lib/faces/canvas-notify.js +138 -0
- package/lib/faces/wire.js +669 -0
- package/lib/flood-guard.js +106 -0
- package/lib/index.js +200 -1392
- package/lib/recursion-guard.js +78 -0
- package/lib/runtime.js +1 -0
- package/lib/skill/SKILL.md +35 -9
- package/lib/skill/references/cli.md +24 -7
- package/lib/skill/references/collaboration.md +355 -0
- package/lib/skill/references/discovery.md +5 -2
- package/lib/skill/references/pitfalls.md +2 -1
- package/lib/skill/references/routing.md +18 -8
- package/lib/skill/references/setup.md +152 -0
- package/lib/task-ledger.js +40 -4
- package/lib/types/canvas-store.d.ts +10 -1
- package/lib/types/faces/admin.d.ts +133 -0
- package/lib/types/faces/canvas-notify.d.ts +74 -0
- package/lib/types/faces/wire.d.ts +171 -0
- package/lib/types/flood-guard.d.ts +29 -0
- package/lib/types/index.d.ts +11 -3
- package/lib/types/recursion-guard.d.ts +56 -0
- package/lib/types/runtime.d.ts +35 -0
- package/lib/types/task-ledger.d.ts +15 -1
- package/nexus-stage/package-lock.json +2262 -2262
- package/nexus-stage/src/canvas-ops.ts +175 -175
- package/nexus-stage/src/canvas-wire.ts +156 -156
- package/nexus-stage/src/edges.ts +72 -72
- package/nexus-stage/src/federation-overlay.ts +103 -103
- package/nexus-stage/src/federation.ts +240 -240
- package/nexus-stage/src/layout-doc.ts +143 -143
- package/nexus-stage/src/layout-wire.ts +158 -158
- package/nexus-stage/src/main.ts +5 -1
- package/nexus-stage/src/planning-card-text.ts +73 -0
- package/nexus-stage/src/planning-edges.ts +26 -0
- package/nexus-stage/src/planning-fit.ts +45 -0
- package/nexus-stage/src/planning-legend.ts +38 -0
- package/nexus-stage/src/planning-mirror.ts +31 -0
- package/nexus-stage/src/planning-overlap.ts +159 -0
- package/nexus-stage/src/planning-relayout.ts +121 -0
- package/nexus-stage/src/planning-search.ts +168 -0
- package/nexus-stage/src/planning-types.ts +1 -0
- package/nexus-stage/src/planning-undo.ts +68 -0
- package/nexus-stage/src/planning-view.ts +120 -121
- package/nexus-stage/src/planning.css +41 -8
- package/nexus-stage/src/seat.ts +35 -35
- package/nexus-stage/src/stage-name.ts +13 -13
- package/nexus-stage/src/tokens.ts +31 -31
- package/nexus-stage/src/viewport.ts +24 -1
- package/nexus-stage/src/wb-chat.ts +20 -6
- package/nexus-stage/src/wb-ledger.ts +20 -7
- package/nexus-stage/src/wb-names.ts +43 -0
- package/nexus-stage/src/workbench.css +8 -2
- package/nexus-stage/src/workbench.ts +55 -17
- package/nexus-stage/src/world.ts +13 -21
- package/package.json +216 -214
- package/assets/nexusDist/assets/index-1niOBYxp.js +0 -5
- package/assets/nexusDist/assets/index-uQf7NwjF.css +0 -1
- package/nexus-stage/scripts/__pycache__/mockhost.cpython-312.pyc +0 -0
|
@@ -0,0 +1,755 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `/__dsh_a2a/*` admin faces and the two workbench pages (gh#77 batch B1).
|
|
3
|
+
*
|
|
4
|
+
* Moved verbatim out of `apply()` in `src/index.ts`: the routes register
|
|
5
|
+
* when the web server settles, exactly as before. What used to be closure
|
|
6
|
+
* captures now arrives through {@link AdminFaceDeps}:
|
|
7
|
+
* - stable bindings (stores, helpers, config) are destructured once below, so
|
|
8
|
+
* the route bodies read as they did in index.ts;
|
|
9
|
+
* - the six `let` bindings the routes read or write go through accessors on
|
|
10
|
+
* `d` (`d.ownerAllowlist = …` writes back into index.ts), keeping the live
|
|
11
|
+
* binding semantics of the closure; so does `cardCache`, which apply()
|
|
12
|
+
* declares after this registration (a destructure would hit its TDZ);
|
|
13
|
+
* - `indexUrl` is index.ts's `import.meta.url`: the asset roots
|
|
14
|
+
* (`../assets/stageDist`, `../assets/nexusDist`) resolve against the
|
|
15
|
+
* entry module, not this file (tsc mirrors src/ under lib/).
|
|
16
|
+
* @module src/faces/admin
|
|
17
|
+
*/
|
|
18
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
19
|
+
import { join } from 'node:path';
|
|
20
|
+
import { fileURLToPath } from 'node:url';
|
|
21
|
+
import { isRemoteMemberRef, validRemoteMemberRef } from "../canvas-store.js";
|
|
22
|
+
import { refreshPeerCard, registerCanvasNotify } from "./canvas-notify.js";
|
|
23
|
+
import { applyOwnerSettings } from "../owner-settings.js";
|
|
24
|
+
import { resolveStageMount } from "../stage-mount.js";
|
|
25
|
+
import { ARCHIVE_CAP, archivedEndedBy } from "../task-ledger.js";
|
|
26
|
+
import { MAX_LAYOUT_BODY_BYTES } from "../transport-caps.js";
|
|
27
|
+
/**
|
|
28
|
+
* Register the admin faces on a settled web server.
|
|
29
|
+
* @param webServer - the settled host web server.
|
|
30
|
+
* @param d - the captures listed on {@link AdminFaceDeps}.
|
|
31
|
+
*/
|
|
32
|
+
export function registerAdminFaces(webServer, d) {
|
|
33
|
+
const { ctx, config, logger, home, session, lanIp, PLUGIN_VERSION, indexUrl, controlRoute, controlTrustedWithoutKey, readJsonBody, peerStore, peerLinkState, originClaimHeaders, refreshRemoteRows, joinedSessions, exposureStore, teamMemberships, cliDeposits, groupStore, canvasStore, layoutStore, taskLedger, idempotencyStore, inFlightRoutes, recentActivity, teamAuditRing, reportRing, sessionNodes, liveRoots, mountSessionNode, coldJoinedIds, prewarmStatus, reconcileStatus, id8, sessionLabelOf, sessionTeamOf, nodeMetadataOf, canvasTeamOf, archivedSessionFilter, pruneArchivedJoins, pruneCanvasMemberships, } = d;
|
|
34
|
+
ctx.effect(() => webServer.register({
|
|
35
|
+
kind: 'exact',
|
|
36
|
+
path: '/__dsh_a2a/state',
|
|
37
|
+
handler: controlRoute((_req, res) => {
|
|
38
|
+
void (async () => {
|
|
39
|
+
const t0 = Date.now();
|
|
40
|
+
// The panel polls this route: pruning here makes a mid-session
|
|
41
|
+
// archive leave the network within one poll interval, no restart
|
|
42
|
+
// required.
|
|
43
|
+
pruneArchivedJoins();
|
|
44
|
+
pruneCanvasMemberships();
|
|
45
|
+
const tPrune = Date.now();
|
|
46
|
+
const assignments = groupStore.all();
|
|
47
|
+
const groupOf = (id) => {
|
|
48
|
+
const name = assignments[id];
|
|
49
|
+
return name === undefined ? undefined : name;
|
|
50
|
+
};
|
|
51
|
+
// Archived sessions are closed: the GUI hides them everywhere, so
|
|
52
|
+
// the panel must not re-list them as join surface rows — joined
|
|
53
|
+
// or not. (The prune above already took their join intents; this
|
|
54
|
+
// covers never-joined live roots and any intent a restart left.)
|
|
55
|
+
const isArchived = archivedSessionFilter();
|
|
56
|
+
const tFacts0 = Date.now();
|
|
57
|
+
const sessions = [...liveRoots.values()]
|
|
58
|
+
.filter(agent => isArchived?.(String(agent.id)) !== true)
|
|
59
|
+
.map(agent => ({
|
|
60
|
+
id: String(agent.id),
|
|
61
|
+
label: sessionLabelOf(agent),
|
|
62
|
+
team: sessionTeamOf(agent),
|
|
63
|
+
...nodeMetadataOf(agent),
|
|
64
|
+
joined: sessionNodes.has(String(agent.id)),
|
|
65
|
+
live: true,
|
|
66
|
+
teams: [...teamMemberships.teamsOf(String(agent.id))],
|
|
67
|
+
// #19 D3: the session's exposure tier (linked floor /
|
|
68
|
+
// fleet opt-up) — readable on the state face.
|
|
69
|
+
exposure: exposureStore.tierOf(String(agent.id)),
|
|
70
|
+
...(canvasStore.teamsOf(String(agent.id)).length > 0 ? { canvasTeams: [...canvasStore.teamsOf(String(agent.id))] } : {}),
|
|
71
|
+
...(groupOf(String(agent.id)) !== undefined ? { group: groupOf(String(agent.id)) } : {}),
|
|
72
|
+
}));
|
|
73
|
+
// Cold joined sessions: a remembered intent whose Agent is not
|
|
74
|
+
// back yet (host restarted, session not opened). The row carries
|
|
75
|
+
// no facts — the Web client merges the session title from its
|
|
76
|
+
// own list — and wakes through the normal session-open path,
|
|
77
|
+
// after which the remount above joins it automatically.
|
|
78
|
+
// Cold rows only exist when a joined intent lacks a live agent;
|
|
79
|
+
// with all intents live (or none) the persistence layer is never
|
|
80
|
+
// asked and the handler stays synchronous to its response.
|
|
81
|
+
const tFacts1 = Date.now();
|
|
82
|
+
const coldCandidates = joinedSessions.list().filter(id => !liveRoots.has(id));
|
|
83
|
+
const persistence = ctx.get('sessionPersistence');
|
|
84
|
+
const persisted = persistence !== undefined && coldCandidates.length > 0 ? await coldJoinedIds() : new Set();
|
|
85
|
+
const tCold = Date.now();
|
|
86
|
+
for (const id of coldCandidates) {
|
|
87
|
+
// Archived intents are retained on disk (an archived window is
|
|
88
|
+
// transient; the 3081 wake defect came from deleting them), so
|
|
89
|
+
// the join surface must skip them here instead.
|
|
90
|
+
if (!persisted.has(id) || isArchived?.(id) === true)
|
|
91
|
+
continue;
|
|
92
|
+
sessions.push({
|
|
93
|
+
id,
|
|
94
|
+
label: `${session}-${id8(id)}`,
|
|
95
|
+
team: `${config.team}/${id8(id)}`,
|
|
96
|
+
joined: true,
|
|
97
|
+
live: false,
|
|
98
|
+
teams: [...teamMemberships.teamsOf(id)],
|
|
99
|
+
...(canvasStore.teamsOf(id).length > 0 ? { canvasTeams: [...canvasStore.teamsOf(id)] } : {}),
|
|
100
|
+
...(groupOf(id) !== undefined ? { group: groupOf(id) } : {}),
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
const body = JSON.stringify({
|
|
104
|
+
nodes: true,
|
|
105
|
+
version: PLUGIN_VERSION,
|
|
106
|
+
sessions,
|
|
107
|
+
groups: groupStore.list(),
|
|
108
|
+
canvas: {
|
|
109
|
+
teams: canvasStore.list().map(name => ({
|
|
110
|
+
name,
|
|
111
|
+
team: canvasTeamOf(name),
|
|
112
|
+
members: canvasStore.membersOf(name).map(id => {
|
|
113
|
+
// Dual shape: local members report this zone's join/live
|
|
114
|
+
// facts; remote refs are opaque team handles — the state
|
|
115
|
+
// face passes them through with remote:true for the
|
|
116
|
+
// workbench's member chips and pickers.
|
|
117
|
+
if (isRemoteMemberRef(id)) {
|
|
118
|
+
return { id, team: id, remote: true };
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
id,
|
|
122
|
+
team: `${config.team}/${id8(id)}`,
|
|
123
|
+
joined: sessionNodes.has(id) || joinedSessions.has(id),
|
|
124
|
+
live: sessionNodes.has(id),
|
|
125
|
+
};
|
|
126
|
+
}),
|
|
127
|
+
})),
|
|
128
|
+
},
|
|
129
|
+
host: lanIp === '' ? {} : { lanIp },
|
|
130
|
+
// gh#20 W-C (host rail): each peer row also carries its display
|
|
131
|
+
// name and version from the warm card (absent until a fetch),
|
|
132
|
+
// and the last-contact timestamp for the health lamp. W-A's
|
|
133
|
+
// link/verified ride along for the badge.
|
|
134
|
+
peers: peerStore.list().map(url => {
|
|
135
|
+
const card = d.cardCache.get(url)?.card;
|
|
136
|
+
const lastContact = peerStore.lastContact(url);
|
|
137
|
+
const lastContactOk = peerStore.lastContactOk(url);
|
|
138
|
+
return {
|
|
139
|
+
url,
|
|
140
|
+
score: peerStore.score(url),
|
|
141
|
+
...(card?.name !== undefined && card.name !== '' ? { name: card.name } : {}),
|
|
142
|
+
...(typeof card?.version === 'string' && card.version !== '' ? { version: card.version } : {}),
|
|
143
|
+
...(lastContact !== undefined ? { lastContactAt: lastContact } : {}),
|
|
144
|
+
...(lastContactOk !== undefined ? { lastContactOk } : {}),
|
|
145
|
+
...peerLinkState(url),
|
|
146
|
+
};
|
|
147
|
+
}),
|
|
148
|
+
remote: (refreshRemoteRows(), (d.remoteRowsCache?.rows ?? []).map(row => {
|
|
149
|
+
const canvasTeams = canvasStore.teamsOf(row.team);
|
|
150
|
+
return canvasTeams.length > 0 ? { ...row, canvasTeams: [...canvasTeams] } : row;
|
|
151
|
+
})),
|
|
152
|
+
activity: recentActivity.slice(),
|
|
153
|
+
inFlight: [...inFlightRoutes.values()].map(route => ({
|
|
154
|
+
team: route.team,
|
|
155
|
+
peer: route.peer,
|
|
156
|
+
startedAt: route.startedAt,
|
|
157
|
+
})),
|
|
158
|
+
// Owed receipts: pending rows only — the cross-turn waits the
|
|
159
|
+
// in-flight ring cannot show. Dead-lettered rows ride their own
|
|
160
|
+
// list and settled ones just a count, all additive so the panel
|
|
161
|
+
// keeps rendering plain owed rows until it learns the tiers.
|
|
162
|
+
tasks: taskLedger.list()
|
|
163
|
+
.filter(task => task.status === 'pending')
|
|
164
|
+
.map(task => ({
|
|
165
|
+
taskId: task.taskId, team: task.team, peer: task.peer, startedAt: task.startedAt, status: task.status,
|
|
166
|
+
direction: task.direction ?? 'outbound', receiptExpected: task.receiptExpected !== false,
|
|
167
|
+
// The dispatch brief rides every row: a task id and a team
|
|
168
|
+
// say nothing about WHAT is owed — supervision cannot tell
|
|
169
|
+
// a nudge from an abandon without it.
|
|
170
|
+
...(task.brief !== undefined ? { brief: task.brief } : {}),
|
|
171
|
+
// C-ruling bucket split: a pending row is settleable while
|
|
172
|
+
// it is young, expected, and answerable; past the stale
|
|
173
|
+
// hour it is conversational noise waiting on the dead TTL.
|
|
174
|
+
settleable: task.receiptExpected !== false && Date.now() - task.startedAt < 60 * 60_000,
|
|
175
|
+
})),
|
|
176
|
+
// C face: the stale/conversational tail as a count, so the
|
|
177
|
+
// panel can render only truly settleable debt.
|
|
178
|
+
tasksStaleCount: taskLedger.list().filter(task => task.status === 'pending' && (task.receiptExpected === false || Date.now() - task.startedAt >= 60 * 60_000)).length,
|
|
179
|
+
tasksDead: taskLedger.list()
|
|
180
|
+
.filter(task => task.status === 'dead')
|
|
181
|
+
.map(task => ({ taskId: task.taskId, team: task.team, peer: task.peer, startedAt: task.startedAt, deadAt: task.deadAt ?? task.startedAt, reason: task.reason ?? 'unspecified', ...(task.brief !== undefined ? { brief: task.brief } : {}), ...(task.direction !== undefined ? { direction: task.direction } : {}) })),
|
|
182
|
+
// gh#31: per-task outcomes for rows that LEFT the ledger — the
|
|
183
|
+
// chat drawer used to guess (settled, abandoned or cancelled).
|
|
184
|
+
// Bounded to the archive (≤64), newest first, with the
|
|
185
|
+
// controlled-vocabulary verdict each row settled by.
|
|
186
|
+
// gh#31 follow-up: archive() is already newest first (settles
|
|
187
|
+
// prepend), so the projection keeps that order — the earlier
|
|
188
|
+
// .reverse() served it oldest first. Each row also says HOW it
|
|
189
|
+
// ended (endedBy: abandon and cancel both record outcome
|
|
190
|
+
// 'abandoned', and so does a peer's own 'abandoned' receipt),
|
|
191
|
+
// whether a receipt came after the caller ended it (late), and
|
|
192
|
+
// its direction when known.
|
|
193
|
+
archived: taskLedger.archive().slice(0, ARCHIVE_CAP).map(row => ({
|
|
194
|
+
taskId: row.taskId,
|
|
195
|
+
team: row.team,
|
|
196
|
+
peer: row.peer,
|
|
197
|
+
startedAt: row.startedAt,
|
|
198
|
+
resolvedAt: row.resolvedAt,
|
|
199
|
+
outcome: row.outcome ?? 'unclassified',
|
|
200
|
+
endedBy: archivedEndedBy(row),
|
|
201
|
+
...(row.direction !== undefined ? { direction: row.direction } : {}),
|
|
202
|
+
// gh#68: present only when the row awaited no receipt.
|
|
203
|
+
...(row.receiptExpected === false ? { receiptExpected: false } : {}),
|
|
204
|
+
...(row.lateReceiptAt !== undefined ? { late: true } : {}),
|
|
205
|
+
...(row.brief !== undefined ? { brief: row.brief } : {}),
|
|
206
|
+
...(row.summary !== undefined && row.summary !== '' ? { summary: row.summary.slice(0, 160) } : {}),
|
|
207
|
+
})),
|
|
208
|
+
archivedCount: taskLedger.archive().length,
|
|
209
|
+
// Ledger density face: the settled archive split by verdict, so
|
|
210
|
+
// the workbench can say WHICH way those rows settled instead of
|
|
211
|
+
// just how many. Additive and bounded (outcome vocabulary is a
|
|
212
|
+
// closed set); rows without an envelope outcome count as
|
|
213
|
+
// 'unclassified' rather than being dropped.
|
|
214
|
+
archivedSplit: (() => {
|
|
215
|
+
const split = {};
|
|
216
|
+
for (const row of taskLedger.archive()) {
|
|
217
|
+
const key = row.outcome ?? 'unclassified';
|
|
218
|
+
split[key] = (split[key] ?? 0) + 1;
|
|
219
|
+
}
|
|
220
|
+
return split;
|
|
221
|
+
})(),
|
|
222
|
+
// 0.5.36 observability: the idempotency window aggregate —
|
|
223
|
+
// window occupancy, outcome split, and cumulative claim-verdict
|
|
224
|
+
// counters (the data the UNIQUE-ization decision waits on).
|
|
225
|
+
// Read-only; no fingerprints cross here (they are /a2a/query's
|
|
226
|
+
// only auth material).
|
|
227
|
+
idempotency: idempotencyStore.stats(),
|
|
228
|
+
// gh#41 fleet planning: each tracked peer's published canvas
|
|
229
|
+
// org (full-card canvasOrg) from the warm card cache — the
|
|
230
|
+
// board renders REMOTE team frames from this. Absent until a
|
|
231
|
+
// linked fetch warmed the card.
|
|
232
|
+
peerOrg: peerStore.list().map(url => {
|
|
233
|
+
const card = d.cardCache.get(url)?.card;
|
|
234
|
+
const org = card?.canvasOrg;
|
|
235
|
+
return Array.isArray(org)
|
|
236
|
+
? { url, org: org.filter((e) => e !== null && typeof e === 'object')
|
|
237
|
+
.map(e => ({ name: typeof e.name === 'string' ? e.name : '', team: typeof e.team === 'string' ? e.team : '', members: Array.isArray(e.members) ? e.members.filter((m) => typeof m === 'string') : [] }))
|
|
238
|
+
.filter(e => e.team !== '') }
|
|
239
|
+
: { url, org: [] };
|
|
240
|
+
}),
|
|
241
|
+
// gh#9+gh#10 M1: envelope-absent deliveries during the
|
|
242
|
+
// OriginClaim window — the operator watches this drain to
|
|
243
|
+
// zero before closing the window.
|
|
244
|
+
legacyInbound: d.legacyInboundCount,
|
|
245
|
+
// F-observability: the boot prewarm's lifecycle — a dead or
|
|
246
|
+
// skipped prewarm is the root shape behind "cold rows pile up
|
|
247
|
+
// after restart" and must be readable, not a console rumor.
|
|
248
|
+
prewarm: { ...prewarmStatus, failed: [...prewarmStatus.failed] },
|
|
249
|
+
// F8 observability: reconciliation cadence, wake outcomes,
|
|
250
|
+
// and per-row failure reasons with backoff and the parked
|
|
251
|
+
// needs-repair state — the cold row's "why am I still cold".
|
|
252
|
+
reconcile: { ...reconcileStatus, rows: [...reconcileStatus.rows] },
|
|
253
|
+
// S1: flat node registry — local sessions and remote card
|
|
254
|
+
// nodes in one table, zone-qualified team handles as the
|
|
255
|
+
// stable cross-host addresses. Local ids are the session
|
|
256
|
+
// UUIDs; remote ids are the publishing team handles. (The
|
|
257
|
+
// `nodes` boolean above is the capability flag the panel
|
|
258
|
+
// already consumes; this face rides its own key.)
|
|
259
|
+
registry: {
|
|
260
|
+
nodes: [
|
|
261
|
+
...sessions.map(row => ({
|
|
262
|
+
id: String(row.id),
|
|
263
|
+
label: String(row.label ?? ''),
|
|
264
|
+
team: String(row.team ?? ''),
|
|
265
|
+
zone: config.team,
|
|
266
|
+
live: row.live === true,
|
|
267
|
+
joined: row.joined === true,
|
|
268
|
+
...(typeof row.workspace === 'string' && row.workspace !== '' ? { workspace: row.workspace } : {}),
|
|
269
|
+
teams: [...teamMemberships.teamsOf(String(row.id))],
|
|
270
|
+
})),
|
|
271
|
+
...(d.remoteRowsCache?.rows ?? []).map(row => ({
|
|
272
|
+
id: String(row.team),
|
|
273
|
+
label: String(row.name ?? ''),
|
|
274
|
+
team: String(row.team),
|
|
275
|
+
zone: String(row.team).split('/')[0] ?? config.team,
|
|
276
|
+
host: String(row.origin ?? ''),
|
|
277
|
+
...(row.workspace !== undefined && row.workspace !== '' ? { workspace: row.workspace } : {}),
|
|
278
|
+
...(row.legacy === true ? { legacy: true } : {}),
|
|
279
|
+
teams: [...(row.teams ?? [])],
|
|
280
|
+
remote: true,
|
|
281
|
+
})),
|
|
282
|
+
],
|
|
283
|
+
// S2: local team rosters rebuilt from member declarations.
|
|
284
|
+
teams: (() => {
|
|
285
|
+
const roster = new Map();
|
|
286
|
+
for (const entry of teamMemberships.list()) {
|
|
287
|
+
for (const team of entry.teams) {
|
|
288
|
+
const members = roster.get(team) ?? [];
|
|
289
|
+
members.push(entry.session);
|
|
290
|
+
roster.set(team, members);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return [...roster.entries()].map(([team, members]) => ({
|
|
294
|
+
team,
|
|
295
|
+
members,
|
|
296
|
+
live: members.filter(member => liveRoots.has(member)).length,
|
|
297
|
+
}));
|
|
298
|
+
})(),
|
|
299
|
+
// S4 audit face: join/leave attempts with outcomes — the
|
|
300
|
+
// queryable half that rotating log lines cannot be.
|
|
301
|
+
teamAudit: [...teamAuditRing],
|
|
302
|
+
},
|
|
303
|
+
// Unjoined-node reports: the one-way signal ring (design:
|
|
304
|
+
// docs/design/unjoined-report-ingress.md), newest first.
|
|
305
|
+
reports: [...reportRing].reverse(),
|
|
306
|
+
});
|
|
307
|
+
res.writeHead(200, {
|
|
308
|
+
'Content-Type': 'application/json',
|
|
309
|
+
'Content-Length': Buffer.byteLength(body),
|
|
310
|
+
// Phase timing (ms since request start): prune / live-row facts /
|
|
311
|
+
// cold-rows enumeration. Diagnostic for the poll-latency question.
|
|
312
|
+
'X-A2A-Timing': `prune=${tPrune - t0};facts=${tFacts1 - tFacts0};cold=${tCold - tFacts1};total=${Date.now() - t0}`,
|
|
313
|
+
});
|
|
314
|
+
res.end(body);
|
|
315
|
+
})();
|
|
316
|
+
}),
|
|
317
|
+
}), 'a2a: session-node state route');
|
|
318
|
+
ctx.effect(() => webServer.register({
|
|
319
|
+
kind: 'exact',
|
|
320
|
+
path: '/__dsh_a2a/join',
|
|
321
|
+
handler: controlRoute((req, res) => {
|
|
322
|
+
readJsonBody(req, res, (body) => {
|
|
323
|
+
const agent = typeof body.id === 'string' ? liveRoots.get(body.id) : undefined;
|
|
324
|
+
if (agent === undefined) {
|
|
325
|
+
const payload = JSON.stringify({ error: 'no live session with that id' });
|
|
326
|
+
res.writeHead(404, { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(payload) });
|
|
327
|
+
res.end(payload);
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
mountSessionNode(agent);
|
|
331
|
+
joinedSessions.add(String(agent.id));
|
|
332
|
+
const payload = JSON.stringify({ id: body.id, label: sessionLabelOf(agent), team: sessionTeamOf(agent) });
|
|
333
|
+
res.writeHead(200, { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(payload) });
|
|
334
|
+
res.end(payload);
|
|
335
|
+
});
|
|
336
|
+
}),
|
|
337
|
+
}), 'a2a: session-node join route');
|
|
338
|
+
ctx.effect(() => webServer.register({
|
|
339
|
+
kind: 'exact',
|
|
340
|
+
path: '/__dsh_a2a/leave',
|
|
341
|
+
handler: controlRoute((req, res) => {
|
|
342
|
+
readJsonBody(req, res, (body) => {
|
|
343
|
+
const id = typeof body.id === 'string' ? body.id : '';
|
|
344
|
+
if (id !== '')
|
|
345
|
+
sessionNodes.delete(id);
|
|
346
|
+
joinedSessions.remove(id);
|
|
347
|
+
// Leaving the network leaves every canvas team too: membership
|
|
348
|
+
// without join consent would be a routing backdoor. Team
|
|
349
|
+
// roster declarations die the same way (S2 consistency).
|
|
350
|
+
canvasStore.dropMember(id);
|
|
351
|
+
teamMemberships.dropSession(id);
|
|
352
|
+
const payload = JSON.stringify({ id });
|
|
353
|
+
res.writeHead(200, { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(payload) });
|
|
354
|
+
res.end(payload);
|
|
355
|
+
});
|
|
356
|
+
}),
|
|
357
|
+
}), 'a2a: session-node leave route');
|
|
358
|
+
// gh#45 CLI 户口 control face (loopback/key gated like every write):
|
|
359
|
+
// publish (deposit a signed CLI card, ≤4h by ruling), revoke, list,
|
|
360
|
+
// and mailbox readout — the CLI polls this while alive.
|
|
361
|
+
ctx.effect(() => webServer.register({
|
|
362
|
+
kind: 'exact',
|
|
363
|
+
path: '/__dsh_a2a/cli-deposit',
|
|
364
|
+
handler: controlRoute((req, res) => {
|
|
365
|
+
readJsonBody(req, res, (body) => {
|
|
366
|
+
const action = body.action;
|
|
367
|
+
let payload;
|
|
368
|
+
if (action === 'publish') {
|
|
369
|
+
const card = typeof body.card === 'string' ? body.card : '';
|
|
370
|
+
const out = cliDeposits.deposit(card);
|
|
371
|
+
payload = JSON.stringify(out.ok
|
|
372
|
+
? { ok: true, handle: out.handle, expiresAt: out.expiresAt, cardUrl: `${d.ownCardUrl}/a2a/cli/${encodeURIComponent(out.handle)}` }
|
|
373
|
+
: { ok: false, error: out.error });
|
|
374
|
+
}
|
|
375
|
+
else if (action === 'revoke') {
|
|
376
|
+
payload = JSON.stringify({ ok: cliDeposits.revoke(typeof body.handle === 'string' ? body.handle : '') });
|
|
377
|
+
}
|
|
378
|
+
else if (action === 'inbox') {
|
|
379
|
+
const handle = typeof body.handle === 'string' ? body.handle : '';
|
|
380
|
+
payload = JSON.stringify({ ok: true, mail: cliDeposits.readMail(handle) });
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
payload = JSON.stringify({ ok: true, deposits: cliDeposits.list().map(row => ({ handle: row.handle, name: row.name, depositedAt: row.depositedAt, expiresAt: row.expiresAt })) });
|
|
384
|
+
}
|
|
385
|
+
res.writeHead(200, { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(payload) });
|
|
386
|
+
res.end(payload);
|
|
387
|
+
});
|
|
388
|
+
}),
|
|
389
|
+
}), 'a2a: cli-deposit route');
|
|
390
|
+
// gh#41 fleet planning relay: the GUI asks THIS host to regulate a
|
|
391
|
+
// REMOTE peer's canvas team. The node key never leaves the server —
|
|
392
|
+
// the relay stamps the OriginClaim envelope and forwards to the
|
|
393
|
+
// peer's /a2a/canvas-op face; the peer's link gate authorizes.
|
|
394
|
+
ctx.effect(() => webServer.register({
|
|
395
|
+
kind: 'exact',
|
|
396
|
+
path: '/__dsh_a2a/fleet-canvas-op',
|
|
397
|
+
handler: controlRoute((req, res) => {
|
|
398
|
+
readJsonBody(req, res, async (body) => {
|
|
399
|
+
const { peer, op, name, id } = body;
|
|
400
|
+
const peerUrl = typeof peer === 'string' ? peer : '';
|
|
401
|
+
const opV = typeof op === 'string' ? op : '';
|
|
402
|
+
const nameV = typeof name === 'string' ? name : '';
|
|
403
|
+
const idV = typeof id === 'string' ? id : '';
|
|
404
|
+
const send = (payload) => {
|
|
405
|
+
res.writeHead(200, { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(payload) });
|
|
406
|
+
res.end(payload);
|
|
407
|
+
};
|
|
408
|
+
if (peerUrl === '' || !/^https?:\/\//.test(peerUrl) || !['create', 'add-member', 'remove-member'].includes(opV) || (opV !== 'create' && nameV === '')) {
|
|
409
|
+
send(JSON.stringify({ ok: false, error: 'peer (http url), op (create | add-member | remove-member), and name are required' }));
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
if (!peerStore.list().includes(peerUrl)) {
|
|
413
|
+
send(JSON.stringify({ ok: false, error: `peer ${peerUrl} is not tracked — regulate tracked peers only` }));
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
try {
|
|
417
|
+
const target = peerUrl.replace(/\/$/, '') + '/a2a/canvas-op';
|
|
418
|
+
const reply = await globalThis.fetch(target, {
|
|
419
|
+
method: 'POST',
|
|
420
|
+
headers: { 'Content-Type': 'application/json', ...originClaimHeaders() },
|
|
421
|
+
// A local session id means nothing on the peer: send its zone/id8 handle (the workbench
|
|
422
|
+
// drops a local card into a remote frame with its raw session id, which the peer refused).
|
|
423
|
+
body: JSON.stringify({ op: opV, name: nameV, ...(opV !== 'create' ? { id: idV !== '' && !isRemoteMemberRef(idV) && (sessionNodes.has(idV) || joinedSessions.has(idV)) ? `${config.team}/${id8(idV)}` : idV } : {}) }),
|
|
424
|
+
signal: AbortSignal.timeout(15_000),
|
|
425
|
+
});
|
|
426
|
+
const raw = await reply.text();
|
|
427
|
+
try {
|
|
428
|
+
const out = JSON.parse(raw);
|
|
429
|
+
// Single owner + mirror: the op landed on the owner — re-read its
|
|
430
|
+
// card, but never gate the reply on it (two serial card fetches can
|
|
431
|
+
// hang the workbench ~30s past a landed op; the owner's own
|
|
432
|
+
// canvas-changed ping is the freshness backstop). PR#96 review P2-1.
|
|
433
|
+
if (out.ok === true)
|
|
434
|
+
void refreshPeerCard(d, peerUrl);
|
|
435
|
+
send(JSON.stringify(out));
|
|
436
|
+
}
|
|
437
|
+
catch {
|
|
438
|
+
// A non-JSON reply is a peer WITHOUT the canvas-op face (a
|
|
439
|
+
// pre-gh41 build) or a proxy page — name the shape honestly.
|
|
440
|
+
send(JSON.stringify({ ok: false, error: `peer ${peerUrl} answered HTTP ${String(reply.status)} without JSON — it likely runs a build without the fleet canvas-op face (pre gh#41); upgrade it, or regulate its teams on that host directly` }));
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
catch (error) {
|
|
444
|
+
send(JSON.stringify({ ok: false, error: `fleet op failed: ${error instanceof Error ? error.message : String(error)}` }));
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
}),
|
|
448
|
+
}), 'a2a: fleet-canvas-op relay route');
|
|
449
|
+
// Owner ruling 2026-10-29 (single owner + mirror): tell linked peers to re-read this host's card on any canvas change.
|
|
450
|
+
registerCanvasNotify(webServer, d);
|
|
451
|
+
// gh#34 owner three-key panel: the remote build-out unlock knobs,
|
|
452
|
+
// surfaced as a control face instead of "翻配置文件". GET reads the
|
|
453
|
+
// effective values; POST writes the HOME patch layer (the
|
|
454
|
+
// authoritative surface) AND hot-applies the two call-time keys
|
|
455
|
+
// (teamJoinAllowlist / teamScopeInfo); announce is boot-time
|
|
456
|
+
// publishing, so its change lands on the next host restart and the
|
|
457
|
+
// reply says so. Same key gate as every write face.
|
|
458
|
+
ctx.effect(() => webServer.register({
|
|
459
|
+
kind: 'exact',
|
|
460
|
+
path: '/__dsh_a2a/owner-settings',
|
|
461
|
+
handler: controlRoute((req, res) => {
|
|
462
|
+
if (req.method === 'GET') {
|
|
463
|
+
const payload = JSON.stringify({
|
|
464
|
+
ok: true,
|
|
465
|
+
teamJoinAllowlist: [...d.ownerAllowlist],
|
|
466
|
+
teamScopeInfo: d.ownerTeamScopeInfo,
|
|
467
|
+
announce: config.announce === true,
|
|
468
|
+
announceRestartPending: d.ownerAnnounceRestartPending,
|
|
469
|
+
});
|
|
470
|
+
res.writeHead(200, { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(payload) });
|
|
471
|
+
res.end(payload);
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
readJsonBody(req, res, (rawBody) => {
|
|
475
|
+
const body = rawBody;
|
|
476
|
+
const changes = {};
|
|
477
|
+
if (Array.isArray(body.teamJoinAllowlist)) {
|
|
478
|
+
const list = body.teamJoinAllowlist.filter((name) => typeof name === 'string' && name !== '' && name.length <= 128);
|
|
479
|
+
changes.teamJoinAllowlist = [...new Set(list)];
|
|
480
|
+
}
|
|
481
|
+
if (typeof body.teamScopeInfo === 'boolean')
|
|
482
|
+
changes.teamScopeInfo = body.teamScopeInfo;
|
|
483
|
+
if (typeof body.announce === 'boolean')
|
|
484
|
+
changes.announce = body.announce;
|
|
485
|
+
if (Object.keys(changes).length === 0) {
|
|
486
|
+
const payload = JSON.stringify({ ok: false, error: 'no recognized keys: teamJoinAllowlist (string[]), teamScopeInfo (bool), announce (bool)' });
|
|
487
|
+
res.writeHead(200, { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(payload) });
|
|
488
|
+
res.end(payload);
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
try {
|
|
492
|
+
const patchPath = join(home, 'cordis.patch.yml');
|
|
493
|
+
const current = existsSync(patchPath) ? readFileSync(patchPath, 'utf8') : '';
|
|
494
|
+
const { yaml, restartNeeded } = applyOwnerSettings(current, changes);
|
|
495
|
+
mkdirSync(home, { recursive: true });
|
|
496
|
+
writeFileSync(patchPath, yaml, 'utf8');
|
|
497
|
+
// Hot-apply the two call-time keys.
|
|
498
|
+
if (changes.teamJoinAllowlist !== undefined)
|
|
499
|
+
d.ownerAllowlist = [...changes.teamJoinAllowlist];
|
|
500
|
+
if (changes.teamScopeInfo !== undefined)
|
|
501
|
+
d.ownerTeamScopeInfo = changes.teamScopeInfo;
|
|
502
|
+
if (changes.announce !== undefined && changes.announce !== (config.announce === true))
|
|
503
|
+
d.ownerAnnounceRestartPending = true;
|
|
504
|
+
if (changes.announce !== undefined && changes.announce === (config.announce === true))
|
|
505
|
+
d.ownerAnnounceRestartPending = false;
|
|
506
|
+
logger.info(`a2a: owner settings updated (${Object.keys(changes).join(', ')}${restartNeeded ? ' — restart pending for announce' : ''})`);
|
|
507
|
+
const payload = JSON.stringify({ ok: true, restartNeeded, keys: Object.keys(changes) });
|
|
508
|
+
res.writeHead(200, { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(payload) });
|
|
509
|
+
res.end(payload);
|
|
510
|
+
}
|
|
511
|
+
catch (error) {
|
|
512
|
+
const payload = JSON.stringify({ ok: false, error: `patch-layer write failed: ${error instanceof Error ? error.message : String(error)}` });
|
|
513
|
+
res.writeHead(200, { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(payload) });
|
|
514
|
+
res.end(payload);
|
|
515
|
+
}
|
|
516
|
+
});
|
|
517
|
+
}),
|
|
518
|
+
}), 'a2a: owner-settings route');
|
|
519
|
+
// Groups control: create/remove named groups and assign sessions to
|
|
520
|
+
// them (an empty name unassigns). Same guard as join/leave — the
|
|
521
|
+
// group taxonomy enumerates session ids, so it stays behind the key.
|
|
522
|
+
// Deprecated as of 0.6.6 (canvas teams supersede manual grouping);
|
|
523
|
+
// kept working for old panels.
|
|
524
|
+
ctx.effect(() => webServer.register({
|
|
525
|
+
kind: 'exact',
|
|
526
|
+
path: '/__dsh_a2a/groups',
|
|
527
|
+
handler: controlRoute((req, res) => {
|
|
528
|
+
readJsonBody(req, res, (body) => {
|
|
529
|
+
const action = body.action;
|
|
530
|
+
let payload;
|
|
531
|
+
if (action === 'create') {
|
|
532
|
+
const name = typeof body.name === 'string' ? body.name : '';
|
|
533
|
+
const stored = groupStore.create(name);
|
|
534
|
+
payload = JSON.stringify(stored === undefined ? { ok: false, error: 'invalid name or group cap reached' } : { ok: true, name: stored, groups: groupStore.list() });
|
|
535
|
+
}
|
|
536
|
+
else if (action === 'remove') {
|
|
537
|
+
const name = typeof body.name === 'string' ? body.name : '';
|
|
538
|
+
payload = JSON.stringify({ ok: groupStore.remove(name), groups: groupStore.list() });
|
|
539
|
+
}
|
|
540
|
+
else if (action === 'assign') {
|
|
541
|
+
const id = typeof body.id === 'string' ? body.id : '';
|
|
542
|
+
const name = typeof body.name === 'string' ? body.name : undefined;
|
|
543
|
+
if (id === '' || name === undefined) {
|
|
544
|
+
payload = JSON.stringify({ ok: false, error: 'id and name are required' });
|
|
545
|
+
}
|
|
546
|
+
else {
|
|
547
|
+
payload = JSON.stringify({ ok: groupStore.assign(id, name), groups: groupStore.list() });
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
else {
|
|
551
|
+
payload = JSON.stringify({ ok: false, error: 'unknown action' });
|
|
552
|
+
}
|
|
553
|
+
res.writeHead(200, { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(payload) });
|
|
554
|
+
res.end(payload);
|
|
555
|
+
});
|
|
556
|
+
}),
|
|
557
|
+
}), 'a2a: session-group route');
|
|
558
|
+
// Canvas control: create/remove named multi-member teams and manage
|
|
559
|
+
// membership. Same key guard as join/leave — membership enumerates
|
|
560
|
+
// session ids. A member must be a joined session (live node or
|
|
561
|
+
// remembered intent): canvas routing only reaches sessions the user
|
|
562
|
+
// put on the network by gesture — no routing backdoor over unjoined
|
|
563
|
+
// sessions.
|
|
564
|
+
ctx.effect(() => webServer.register({
|
|
565
|
+
kind: 'exact',
|
|
566
|
+
path: '/__dsh_a2a/canvas',
|
|
567
|
+
handler: controlRoute((req, res) => {
|
|
568
|
+
readJsonBody(req, res, (body) => {
|
|
569
|
+
const action = body.action;
|
|
570
|
+
let payload;
|
|
571
|
+
if (action === 'create') {
|
|
572
|
+
const name = typeof body.name === 'string' ? body.name : '';
|
|
573
|
+
const stored = canvasStore.create(name);
|
|
574
|
+
payload = JSON.stringify(stored === undefined ? { ok: false, error: 'invalid name or team cap reached' } : { ok: true, name: stored, teams: canvasStore.list() });
|
|
575
|
+
}
|
|
576
|
+
else if (action === 'remove') {
|
|
577
|
+
const name = typeof body.name === 'string' ? body.name : '';
|
|
578
|
+
payload = JSON.stringify({ ok: canvasStore.remove(name), teams: canvasStore.list() });
|
|
579
|
+
}
|
|
580
|
+
else if (action === 'add-member') {
|
|
581
|
+
const name = typeof body.name === 'string' ? body.name : '';
|
|
582
|
+
const id = typeof body.id === 'string' ? body.id : '';
|
|
583
|
+
// Dual member shape: a local session id must be a joined node;
|
|
584
|
+
// a remote ref is a zone-qualified team handle whose shape this
|
|
585
|
+
// gate checks and whose existence the UI picker (directory
|
|
586
|
+
// rows) vouches for. Humans compose both via the workbench.
|
|
587
|
+
const memberValid = isRemoteMemberRef(id)
|
|
588
|
+
? validRemoteMemberRef(id)
|
|
589
|
+
: id !== '' && (sessionNodes.has(id) || joinedSessions.has(id));
|
|
590
|
+
if (name === '' || !memberValid) {
|
|
591
|
+
payload = JSON.stringify({ ok: false, error: 'name and a member (joined session id, or a zone-qualified remote team handle like zone/a1b2c3d4) are required' });
|
|
592
|
+
}
|
|
593
|
+
else {
|
|
594
|
+
canvasStore.create(name);
|
|
595
|
+
payload = JSON.stringify({ ok: canvasStore.addMember(name, id), teams: canvasStore.list(), members: canvasStore.membersOf(name) });
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
else if (action === 'remove-member') {
|
|
599
|
+
const name = typeof body.name === 'string' ? body.name : '';
|
|
600
|
+
const id = typeof body.id === 'string' ? body.id : '';
|
|
601
|
+
if (name === '' || id === '') {
|
|
602
|
+
payload = JSON.stringify({ ok: false, error: 'name and id are required' });
|
|
603
|
+
}
|
|
604
|
+
else {
|
|
605
|
+
payload = JSON.stringify({ ok: canvasStore.removeMember(name, id), teams: canvasStore.list(), members: canvasStore.membersOf(name) });
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
else {
|
|
609
|
+
payload = JSON.stringify({ ok: false, error: 'unknown action' });
|
|
610
|
+
}
|
|
611
|
+
res.writeHead(200, { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(payload) });
|
|
612
|
+
res.end(payload);
|
|
613
|
+
});
|
|
614
|
+
}),
|
|
615
|
+
}), 'a2a: session-canvas route');
|
|
616
|
+
// Layout face (contract v2): whole-document GET + save/reset for the
|
|
617
|
+
// stage's spatial presentation state. Validated/clamped server-side by
|
|
618
|
+
// LayoutStore so a buggy client cannot poison persisted geometry.
|
|
619
|
+
ctx.effect(() => webServer.register({
|
|
620
|
+
kind: 'exact',
|
|
621
|
+
path: '/__dsh_a2a/canvas-layout',
|
|
622
|
+
handler: controlRoute((req, res) => {
|
|
623
|
+
if (req.method === 'GET') {
|
|
624
|
+
const payload = JSON.stringify({ ok: true, layout: layoutStore.get() });
|
|
625
|
+
res.writeHead(200, { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(payload) });
|
|
626
|
+
res.end(payload);
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
readJsonBody(req, res, (body) => {
|
|
630
|
+
const action = body.action;
|
|
631
|
+
if (action === 'reset') {
|
|
632
|
+
layoutStore.reset();
|
|
633
|
+
const payload = JSON.stringify({ ok: true, layout: null });
|
|
634
|
+
res.writeHead(200, { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(payload) });
|
|
635
|
+
res.end(payload);
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
if (action === 'save') {
|
|
639
|
+
const accepted = layoutStore.save(body.layout);
|
|
640
|
+
const payload = JSON.stringify(accepted ? { ok: true, layout: layoutStore.get() } : { ok: false, error: 'payload is not a version-1 layout document' });
|
|
641
|
+
res.writeHead(200, { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(payload) });
|
|
642
|
+
res.end(payload);
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
const payload = JSON.stringify({ ok: false, error: 'unknown action' });
|
|
646
|
+
res.writeHead(200, { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(payload) });
|
|
647
|
+
res.end(payload);
|
|
648
|
+
}, MAX_LAYOUT_BODY_BYTES);
|
|
649
|
+
}),
|
|
650
|
+
}), 'a2a: canvas-layout route');
|
|
651
|
+
// The dsh-a2a-munder-difflin floor stage: a same-origin full-page
|
|
652
|
+
// surface adapted from the Munder Difflin office renderer (stage/,
|
|
653
|
+
// NOTICE). Serves the built Vite tree with a traversal-guarded map.
|
|
654
|
+
ctx.effect(() => webServer.register({
|
|
655
|
+
kind: 'prefix',
|
|
656
|
+
path: '/__dsh_a2a_canvas',
|
|
657
|
+
handler: (req, res) => {
|
|
658
|
+
const rootDir = fileURLToPath(new URL('../assets/stageDist', indexUrl));
|
|
659
|
+
// Directory-classic resolution: the bare mount 301s onto itself
|
|
660
|
+
// with a slash, so the shell's `./assets` references resolve
|
|
661
|
+
// inside this tree instead of 404ing against the web root.
|
|
662
|
+
const MOUNT = '/__dsh_a2a_canvas';
|
|
663
|
+
const resolved = resolveStageMount(req.url ?? '/', MOUNT);
|
|
664
|
+
if (resolved.redirectTo !== undefined) {
|
|
665
|
+
res.writeHead(301, { Location: resolved.redirectTo, 'Cache-Control': 'no-store', 'X-A2A-Stage': 'redirect' });
|
|
666
|
+
res.end();
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
const rel = decodeURIComponent(resolved.rel).replace(/\\/g, '/');
|
|
670
|
+
if (rel.includes('..')) {
|
|
671
|
+
res.writeHead(403, { 'Content-Type': 'text/plain', 'X-A2A-Stage': 'traversal' });
|
|
672
|
+
res.end();
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
675
|
+
try {
|
|
676
|
+
const file = readFileSync(join(rootDir, rel));
|
|
677
|
+
const ext = rel.slice(rel.lastIndexOf('.') + 1);
|
|
678
|
+
const types = {
|
|
679
|
+
html: 'text/html; charset=utf-8',
|
|
680
|
+
js: 'text/javascript; charset=utf-8',
|
|
681
|
+
mjs: 'text/javascript; charset=utf-8',
|
|
682
|
+
css: 'text/css; charset=utf-8',
|
|
683
|
+
png: 'image/png',
|
|
684
|
+
json: 'application/json; charset=utf-8',
|
|
685
|
+
svg: 'image/svg+xml',
|
|
686
|
+
};
|
|
687
|
+
res.writeHead(200, { 'Content-Type': types[ext] ?? 'application/octet-stream', 'Cache-Control': 'no-store', 'X-A2A-Stage': 'ok:' + ext });
|
|
688
|
+
res.end(file);
|
|
689
|
+
}
|
|
690
|
+
catch (err) {
|
|
691
|
+
res.writeHead(404, { 'Content-Type': 'text/plain', 'X-A2A-Stage': 'miss' });
|
|
692
|
+
res.end('stage-miss rel=' + rel + ' rootDir=' + rootDir + ' err=' + String(err));
|
|
693
|
+
}
|
|
694
|
+
},
|
|
695
|
+
}), 'a2a: canvas-stage page');
|
|
696
|
+
// The dsh-a2a-nexus stage: Three.js infinite-canvas topology viewer.
|
|
697
|
+
// Serves the built Vite tree from assets/nexusDist with a traversal-
|
|
698
|
+
// guarded file map (same discipline as canvas-stage).
|
|
699
|
+
ctx.effect(() => webServer.register({
|
|
700
|
+
kind: 'prefix',
|
|
701
|
+
path: '/__dsh_a2a_nexus',
|
|
702
|
+
handler: (req, res) => {
|
|
703
|
+
const rootDirNexus = fileURLToPath(new URL('../assets/nexusDist', indexUrl));
|
|
704
|
+
// Same directory-classic resolution as the canvas mount: the bare
|
|
705
|
+
// `/__dsh_a2a_nexus` form used to serve the shell verbatim, whose
|
|
706
|
+
// `./assets` then 404'd at the web root — a silent black viewer.
|
|
707
|
+
const MOUNT = '/__dsh_a2a_nexus';
|
|
708
|
+
const resolved = resolveStageMount(req.url ?? '/', MOUNT);
|
|
709
|
+
if (resolved.redirectTo !== undefined) {
|
|
710
|
+
res.writeHead(301, { Location: resolved.redirectTo, 'Cache-Control': 'no-store' });
|
|
711
|
+
res.end();
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
const rel = decodeURIComponent(resolved.rel).replace(/\\/g, '/');
|
|
715
|
+
if (rel.includes('..')) {
|
|
716
|
+
res.writeHead(403, { 'Content-Type': 'text/plain' });
|
|
717
|
+
res.end();
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
try {
|
|
721
|
+
const file = readFileSync(join(rootDirNexus, rel));
|
|
722
|
+
const ext = rel.slice(rel.lastIndexOf('.') + 1);
|
|
723
|
+
const types = {
|
|
724
|
+
html: 'text/html; charset=utf-8',
|
|
725
|
+
js: 'text/javascript; charset=utf-8',
|
|
726
|
+
mjs: 'text/javascript; charset=utf-8',
|
|
727
|
+
css: 'text/css; charset=utf-8',
|
|
728
|
+
png: 'image/png',
|
|
729
|
+
json: 'application/json; charset=utf-8',
|
|
730
|
+
svg: 'image/svg+xml',
|
|
731
|
+
};
|
|
732
|
+
res.writeHead(200, { 'Content-Type': types[ext] ?? 'application/octet-stream', 'Cache-Control': 'no-store' });
|
|
733
|
+
// gh#9 §10 GUI key plumbing (REVIEW M3 fix): the shell learns
|
|
734
|
+
// the control-plane key ONLY on the loopback leniency face —
|
|
735
|
+
// a remote bare GET of the page serves the shell WITHOUT the
|
|
736
|
+
// key (the reviewer proved the pre-fix shape leaked the
|
|
737
|
+
// credential to any network-reachable fetcher on a
|
|
738
|
+
// 0.0.0.0-bound host, contradicting §10's purpose). Loopback
|
|
739
|
+
// localhost is exactly §10.2's stated leniency posture; keyed
|
|
740
|
+
// hosts behind tunnels use originClaimUrl-style operator
|
|
741
|
+
// plumbing instead.
|
|
742
|
+
if (ext === 'html' && config.apiKey !== '' && controlTrustedWithoutKey(req)) {
|
|
743
|
+
const injected = file.toString('utf8').replace('</head>', `<script>window.__DSH_A2A_KEY__=${JSON.stringify(config.apiKey)};</script></head>`);
|
|
744
|
+
res.end(Buffer.from(injected, 'utf8'));
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
res.end(file);
|
|
748
|
+
}
|
|
749
|
+
catch {
|
|
750
|
+
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
|
751
|
+
res.end();
|
|
752
|
+
}
|
|
753
|
+
},
|
|
754
|
+
}), 'a2a: nexus-stage page');
|
|
755
|
+
}
|