@nelsonlongxiang/dsh-open-a2a-net 0.6.36 → 0.6.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +7 -4
  2. package/README_zh.md +7 -4
  3. package/assets/nexusDist/assets/index-C7HagaGy.css +1 -0
  4. package/assets/nexusDist/assets/index-NkNSeIx6.js +9 -0
  5. package/assets/nexusDist/index.html +2 -2
  6. package/cli/a2a.mjs +35 -5
  7. package/lib/a2a-client.js +3 -3
  8. package/lib/canvas-discovery.js +29 -0
  9. package/lib/client.js +63 -63
  10. package/lib/direct-forward.js +49 -27
  11. package/lib/faces/admin.js +30 -4
  12. package/lib/faces/canvas-notify.js +8 -6
  13. package/lib/faces/wire.js +29 -10
  14. package/lib/index.js +107 -24
  15. package/lib/origin-claim.js +31 -8
  16. package/lib/owner-settings.js +38 -1
  17. package/lib/peer-directory.js +1 -1
  18. package/lib/peer-link-display.js +15 -0
  19. package/lib/skill/references/cli.md +11 -3
  20. package/lib/skill/references/pitfalls.md +1 -1
  21. package/lib/skill/references/setup.md +9 -9
  22. package/lib/task-auth.js +1 -1
  23. package/lib/task-ledger-rows.js +220 -0
  24. package/lib/task-ledger.js +13 -196
  25. package/lib/tools/info.js +14 -5
  26. package/lib/types/a2a-client.d.ts +1 -0
  27. package/lib/types/canvas-discovery.d.ts +20 -0
  28. package/lib/types/direct-forward.d.ts +9 -0
  29. package/lib/types/faces/admin.d.ts +11 -0
  30. package/lib/types/faces/canvas-notify.d.ts +3 -1
  31. package/lib/types/faces/wire.d.ts +4 -1
  32. package/lib/types/index.d.ts +3 -1
  33. package/lib/types/origin-claim.d.ts +16 -4
  34. package/lib/types/owner-settings.d.ts +5 -0
  35. package/lib/types/peer-link-display.d.ts +13 -0
  36. package/lib/types/task-auth.d.ts +2 -0
  37. package/lib/types/task-ledger-rows.d.ts +352 -0
  38. package/lib/types/task-ledger.d.ts +7 -288
  39. package/lib/types/tools/info.d.ts +5 -0
  40. package/lib/types/types.d.ts +2 -1
  41. package/nexus-stage/src/planning-member-handles.ts +28 -1
  42. package/nexus-stage/src/planning-menus.ts +12 -5
  43. package/nexus-stage/src/planning-view.ts +18 -14
  44. package/nexus-stage/src/seat-name-editor.ts +31 -0
  45. package/nexus-stage/src/session-drag.ts +64 -0
  46. package/nexus-stage/src/wb-directory.ts +2 -0
  47. package/nexus-stage/src/workbench.css +2 -0
  48. package/nexus-stage/src/workbench.ts +16 -5
  49. package/package.json +1 -1
  50. package/assets/nexusDist/assets/index-DIQNDBy6.js +0 -9
  51. package/assets/nexusDist/assets/index-z33lHtLw.css +0 -1
@@ -18,294 +18,10 @@
18
18
  * illusion: settlements vanished while debts piled up).
19
19
  * @module @nelsonlongxiang/dsh-open-a2a-net/task-ledger
20
20
  */
21
- import { type AuthProof, type ChainRole, type SettlementReason, type SettlementVerdict, type TaskAuthorization } from './task-auth.ts';
22
- import { type ReceiptOutcomeV2 } from './receipt.ts';
23
- import { type ConservationSnapshot, type ConservationVerdict } from './ledger-conservation.ts';
24
- /** Hard cap on the owed book (pending + dead-lettered rows, most recent first). */
25
- export declare const TASK_CAP = 64;
26
- /** Hard cap on the settled archive (most recent kept). */
27
- export declare const ARCHIVE_CAP = 64;
28
- /** Longest receipt summary kept on a record (multi-line outcomes collapse). */
29
- export declare const SUMMARY_CAP = 200;
30
- /**
31
- * Longest dispatch brief kept per row. A ledger row without its payload is
32
- * unreadable to supervision — "direct-8f3a1c2b → dsh/ec4ce7f8, 3h old" says
33
- * nothing about whether to nudge, abandon, or read the receipt. The brief is
34
- * the first non-empty line of the message, capped; the full body never enters
35
- * the ledger (it can be arbitrarily large and may quote another session's log).
36
- */
37
- export declare const BRIEF_CAP = 120;
38
- /** Reduce a dispatch body to one readable line: first non-empty line, collapsed, capped. */
39
- export declare function briefOf(message: string | undefined): string | undefined;
40
- /**
41
- * Age at which an unsettled task auto-dead-letters. A dead row exits the
42
- * owed view, disarms its async-nudge retry (a cold session cannot consume a
43
- * re-steer anyway), and still accepts a late receipt from a revived target.
44
- * Injectable per instance so tests can use short windows; sweeping stays
45
- * lazy — every read/write entry point sweeps first.
46
- */
47
- export declare const TASK_STALE_TTL_MS: number;
48
- /**
49
- * The receipt correlation template now lives in `receipt.ts` (shared codec
50
- * for header + v2 envelope line). This ledger consumes `parseReceipt` so
51
- * human summaries and machine projections can never drift apart again.
52
- */
53
- /** Lifecycle of a tracked outbound task inside the owed book. */
54
- export type TaskStatus = 'pending' | 'dead';
55
- /** F5 layer-3: why a dead row aged out (stamped by the sweep at flip time). */
56
- export type DeadReason = 'fire-forget' | 'unconsumed';
57
- /** gh#31: which archive path ended a row — a receipt, a content echo, or the caller. */
58
- export type ArchiveEnd = 'receipt' | 'echo' | 'abandoned' | 'cancelled' | 'evicted';
59
- /**
60
- * #114 S3: who really sent one outbound task — the routing session, the
61
- * agent-less host face, or a native-teams bridge submitter. Before this
62
- * field every outbound row was attributable only to the host ("home"), so
63
- * same-host seats could not be told apart.
64
- */
65
- export interface Sender {
66
- readonly kind: 'session' | 'host' | 'bridge' | 'cli';
67
- /**
68
- * A session's `<zone>/<id8>` node team, the host process label, or the
69
- * bridge submitter. Group senders by `kind:id`, never by `id` alone: a host
70
- * label set by hand may look like a session handle.
71
- */
72
- readonly id: string;
73
- /**
74
- * Host senders only: the label the call borrowed on the wire when it
75
- * differs from {@link id} (quick dispatch rides a live joined session's
76
- * team). Display context, never a bucket key.
77
- */
78
- readonly face?: string;
79
- }
80
- /** Longest sender id kept; anything longer is malformed, not truncated. */
81
- export declare const SENDER_ID_CAP = 256;
82
- /**
83
- * Restore-side allowlist for one persisted sender: a well-formed value comes
84
- * back as a fresh object holding only kind, id and (when present) face; anything else is dropped whole (the row
85
- * itself survives — a bad sender never costs the debt record).
86
- * @param raw - the persisted value.
87
- * @returns the sender, or undefined when absent or malformed.
88
- */
89
- export declare function parseSender(raw: unknown): Sender | undefined;
90
- /** #139: what an outbound row is born with besides its sender. */
91
- export interface OutboundBirth {
92
- readonly forwarded?: true;
93
- /** The local-candidate admission (ingress local); kept only on a row whose peer is 'local'. */
94
- readonly auth?: TaskAuthorization;
95
- readonly peerKey?: string;
96
- readonly peerHost?: string;
97
- readonly deliveredTo?: string;
98
- }
99
- /** One tracked outbound task still in the owed book (unsettled). */
100
- export interface TaskRecord {
101
- readonly taskId: string;
102
- readonly team: string;
103
- readonly peer: string;
104
- readonly startedAt: number;
105
- /**
106
- * Which side of the wire this row serves: 'outbound' (this node sent and
107
- * awaits a receipt) or 'inbound' (this node received and owes one).
108
- * Absent on rows persisted before F2' — those are outbound by birth.
109
- */
110
- readonly direction?: 'inbound' | 'outbound';
111
- /**
112
- * F5: whether a receipt is actually owed. Absent ⇒ true (back-compat).
113
- * `false` marks fire-and-forget deliveries — the caller's label could not
114
- * receive a receipt at dispatch (process-form label), so no debt was born
115
- * and supervision must not chase this row.
116
- */
117
- readonly receiptExpected?: boolean;
118
- /** The conversation the delivery steered, for follow-up routes. */
119
- readonly contextId?: string;
120
- /**
121
- * Head of the dispatched message (first non-empty line, {@link BRIEF_CAP}).
122
- * What the row is ABOUT — the fact that makes the ledger readable without
123
- * replaying the conversation. Absent on rows persisted before this field.
124
- */
125
- readonly brief?: string;
126
- /** #114 S3: the real sender of an outbound row (absent on inbound rows and rows persisted before the field). */
127
- readonly sender?: Sender;
128
- /** Home host forwarded an online CLI request to a peer. */
129
- readonly forwarded?: true;
130
- /**
131
- * #114 S2: the immutable authorization the row was born with — an inbound
132
- * row's wire admission, or (#139) an outbound row's local-candidate
133
- * admission (`ingress: 'local'`). Absent on remote outbound and older rows.
134
- */
135
- readonly auth?: TaskAuthorization;
136
- /** #139: the public key of the peer card a remote outbound row was dispatched to. */
137
- readonly peerKey?: string;
138
- /** #139: that card's session label (the peer host's process label). */
139
- readonly peerHost?: string;
140
- /** #139: the member that actually received the task (canvas / bare-zone deliveries). */
141
- readonly deliveredTo?: string;
142
- /** Local target has produced an answer; still owed until receipt delivery/settlement, but no longer queued. */
143
- answeredAt?: number;
144
- status: TaskStatus;
145
- /** When the row was swept to dead-letter (absent while pending). */
146
- deadAt?: number;
147
- /**
148
- * F5 layer-3: why the row aged out. 'fire-forget' — a receiptExpected:false
149
- * row expiring is expected bookkeeping, not a failure; 'unconsumed' — a
150
- * receipt-owed row never settled, the actionable stale shape. Absent on
151
- * dead rows persisted before this field (rendered as 'unspecified').
152
- */
153
- reason?: DeadReason;
154
- }
155
- /** One settled task kept for audit, with its receipt-correlated outcome. */
156
- export interface ArchivedRecord {
157
- readonly taskId: string;
158
- readonly team: string;
159
- readonly peer: string;
160
- readonly startedAt: number;
161
- readonly contextId?: string;
162
- readonly resolvedAt: number;
163
- readonly summary?: string;
164
- /** Head of the dispatched message that this row settled (see {@link TaskRecord.brief}). */
165
- readonly brief?: string;
166
- /** Controlled vocabulary verdict when the settling receipt carried a v2 envelope; forced 'abandoned' for caller-abandoned rows. */
167
- readonly outcome?: ReceiptOutcomeV2 | 'abandoned';
168
- /** Remote-turn wall-clock cost, when the settling envelope carried it. */
169
- readonly elapsedMs?: number;
170
- /**
171
- * When a receipt arrived for an explicitly abandoned row ({@link TaskLedger.abandon}).
172
- * Orphan isolation: the abandonment outcome stays verbatim; the late answer is
173
- * recorded as metadata only, never promoted to resolution.
174
- */
175
- readonly lateReceiptAt?: number;
176
- /**
177
- * gh#31: which archive path ended the row, recorded at archive time. Absent
178
- * on rows archived before the field — {@link archivedEndedBy} derives it.
179
- */
180
- readonly endedBy?: ArchiveEnd;
181
- /** gh#31: which side of the wire the row served, copied from the owed row (absent on rows archived before the field). */
182
- readonly direction?: 'inbound' | 'outbound';
183
- /**
184
- * gh#68: copied from the owed row when it awaited no receipt, so a tidied
185
- * fire-forget expiry is not read as a send we gave up on. Only `false` is
186
- * ever stored; absent means a receipt was owed (or the row predates the field).
187
- */
188
- readonly receiptExpected?: false;
189
- /** #114 S3: copied from the owed row (absent on inbound rows and rows archived before the field). */
190
- readonly sender?: Sender;
191
- /** Home host forwarded an online CLI request to a peer. */
192
- readonly forwarded?: true;
193
- /** #114 S2: carried over from the live row unchanged. */
194
- readonly auth?: TaskAuthorization;
195
- /** #139: carried over from the live row unchanged (a late receipt is judged against them). */
196
- readonly peerKey?: string;
197
- readonly peerHost?: string;
198
- readonly deliveredTo?: string;
199
- /** Local answer time retained as audit metadata, independent of resolution time. */
200
- readonly answeredAt?: number;
201
- /** #114 S4: who settled the row (receipt and echo ends), and their chain role. */
202
- readonly settledBy?: SettledBy;
203
- }
204
- /**
205
- * How one archived row ended (gh#31). The recorded field wins; legacy rows
206
- * fall back to the summary markers this ledger writes itself. The fallback
207
- * reads a receipt-settled row's summary, which is the peer's text, so it is
208
- * only as exact as the legacy data allows.
209
- * @param row - the archived record.
210
- * @returns the archive path that ended it.
211
- */
212
- export declare function archivedEndedBy(row: ArchivedRecord): ArchiveEnd;
213
- /** Result of an explicit caller-side abandon. Total and never-thrown. */
214
- export type AbandonOutcome = 'cleared' | 'already-terminal' | 'unknown';
215
- /** Structured verdict for one {@link TaskLedger.abandon} call (consumer contract: idempotent). */
216
- export interface AbandonResult {
217
- readonly outcome: AbandonOutcome;
218
- readonly taskId: string;
219
- /** Settle time: fresh abandonment's clock tick, or the already-settled row's original resolvedAt. */
220
- readonly archivedAt?: number;
221
- }
222
- /** Result of a cooperative {@link TaskLedger.cancel}; adds routing facts for the notify half. */
223
- export interface CancelledResult extends AbandonResult {
224
- /** Team the ended row addressed — the route layer reaches a live local target through it. */
225
- readonly team?: string;
226
- readonly contextId?: string;
227
- }
228
- /** Per-instance knobs; defaults come from the exported constants. */
229
- export interface TaskLedgerOptions {
230
- /** Stale-TTL override (tests inject short windows); defaults to {@link TASK_STALE_TTL_MS}. */
231
- staleTtlMs?: number;
232
- /** Archive capacity override; defaults to {@link ARCHIVE_CAP}. */
233
- archiveCap?: number;
234
- /**
235
- * Clock injection for tests: every sweep/TTL decision reads the time from
236
- * here. Defaults to Date.now. Injecting a steppable clock makes the stale
237
- * transition deterministic - no real sleeps to race under load.
238
- */
239
- now?: () => number;
240
- }
241
- /**
242
- * What one correlated receipt settled — the payload of the
243
- * `a2a/receipt-resolved` event, emitted for consumers that react to receipt
244
- * arrivals (P2: native-teams settles its outstanding async submissions from
245
- * this seam). `outcome` carries the v2 envelope's controlled-vocabulary
246
- * verdict when the receipt rode one; `late` marks a receipt answering a
247
- * dead-lettered row (revival) or an abandoned row (arrival recorded) — a
248
- * healthy row's duplicate receipt refreshes the archive with NO marker.
249
- */
250
- export interface ReceiptResolvedInfo {
251
- readonly taskId: string;
252
- /** The team the task was routed to (as the dispatcher recorded it). */
253
- readonly team: string;
254
- /** The peer (or `'local'`) the task was dispatched through. */
255
- readonly peer: string;
256
- /** v2 envelope outcome, when the receipt rode one. */
257
- readonly outcome?: string;
258
- /** One-line outcome summary, when the receipt carried one. */
259
- readonly summary?: string;
260
- /** True when the receipt answered a dead-lettered or abandoned row. */
261
- readonly late?: boolean;
262
- }
263
- /** The persisted ledger document: the owed book plus its settled archive. */
264
- export interface TaskLedgerSnapshot {
265
- readonly tasks: readonly TaskRecord[];
266
- readonly archived?: readonly ArchivedRecord[];
267
- /** #114 S4: the bounded ring of refused / would-be-refused settlements. */
268
- readonly settlementRefusals?: readonly SettlementRefusalRecord[];
269
- /** #114 S4: monotonic count of every refusal noted. */
270
- readonly settlementRefusalsTotal?: number;
271
- /** gh#154: lifetime conservation counters (persisted; absent = pre-#154 legacy) — the module contract, shared by classifier, counters, and this schema (review P3). */
272
- readonly conservation?: ConservationSnapshot;
273
- }
274
- /** #114 S4: who settled an archived row, and how they stood on its authorization chain. */
275
- export interface SettledBy {
276
- readonly caller: string;
277
- readonly chain_role: ChainRole | 'off-chain';
278
- }
279
- /** #114 S4: one settlement the judgement refused (enforce) or would have refused (observe). */
280
- export interface SettlementRefusalRecord {
281
- readonly taskId: string;
282
- readonly at: number;
283
- readonly settler: {
284
- readonly caller: string;
285
- readonly proof: AuthProof;
286
- readonly ingress: 'wire' | 'local';
287
- };
288
- readonly reason: SettlementReason;
289
- /** The receipt's first line, bounded. */
290
- readonly head: string;
291
- /** true: the settlement was refused (enforce); false: recorded only (observe). */
292
- readonly enforced: boolean;
293
- /** Repeats of the same (task, settler, reason) folded into this entry, so a flood cannot push older evidence out (review of PR #140 P2-4). */
294
- readonly count: number;
295
- }
296
- /** Bound of the refusal ring (design §4.4). */
297
- export declare const SETTLEMENT_REFUSAL_CAP = 64;
298
- /**
299
- * #114 S4: how the ledger asks whether a settler may settle a row. `check`
300
- * is the pure judgement (task-auth.ts judgeSettlement) bound to this
301
- * receipt's facts; `enforce` decides whether an off-chain verdict blocks
302
- * the settlement or is only recorded.
303
- */
304
- export interface SettlementJudge {
305
- readonly enforce: boolean;
306
- readonly settler: SettlementRefusalRecord['settler'];
307
- check(row: Pick<TaskRecord, 'team' | 'peer' | 'direction' | 'auth' | 'peerKey' | 'peerHost' | 'deliveredTo'>, echo: boolean): SettlementVerdict;
308
- }
21
+ import type { TaskAuthorization } from './task-auth.ts';
22
+ import { type ConservationVerdict } from './ledger-conservation.ts';
23
+ import type { TaskRecord, ArchivedRecord, Sender, OutboundBirth, TaskLedgerOptions, ReceiptResolvedInfo, SettlementRefusalRecord, SettlementJudge, AbandonResult, CancelledResult } from './task-ledger-rows.ts';
24
+ export * from './task-ledger-rows.ts';
309
25
  /**
310
26
  * Bounded outbound-task ledger with whole-file persistence. Pure of any
311
27
  * routing knowledge: callers {@link track} a task when a route leaves it
@@ -328,6 +44,7 @@ export declare class TaskLedger {
328
44
  private readonly archiveCap;
329
45
  /** Injectable clock (option `now`). */
330
46
  private readonly now;
47
+ private readonly warn;
331
48
  /**
332
49
  * @param path - persistence file (`<dsh-home>/a2a/tasks.json`); empty = no persistence.
333
50
  * @param options - TTL/capacity overrides; defaults come from the exported constants.
@@ -339,6 +56,8 @@ export declare class TaskLedger {
339
56
  * @returns the owed-book records.
340
57
  */
341
58
  list(): readonly TaskRecord[];
59
+ /** #275: old forwarded canvas debts cannot be safely upgraded by inventing receiver authority. */
60
+ settlementEnforceBlockers(): string[];
342
61
  /**
343
62
  * The settled archive, most recently resolved first. Rows land here the
344
63
  * moment their receipt correlates and stay until the archive cap evicts
@@ -17,6 +17,10 @@ export type DirectoryTeamRow = {
17
17
  team: string;
18
18
  session: string;
19
19
  name: string;
20
+ seatName?: string;
21
+ kind?: 'canvas';
22
+ owner?: string;
23
+ memberCount?: number;
20
24
  description: string;
21
25
  local?: boolean;
22
26
  origin?: string;
@@ -67,6 +71,7 @@ export interface InfoToolsDeps {
67
71
  readonly sessionTeamOf: (agent: Agent) => string;
68
72
  readonly nodeMetadataOf: (agent: Agent) => {
69
73
  name: string;
74
+ seatName?: string;
70
75
  description: string;
71
76
  workspace?: string;
72
77
  };
@@ -72,8 +72,9 @@ export interface A2aPeerCard {
72
72
  export interface A2aSessionTeamInfo {
73
73
  /** Session team name (`<team>/<agentId8>`); the route target. */
74
74
  readonly team: string;
75
- /** The session's title at read time. */
75
+ /** Human seatName when configured, otherwise the session title at read time. */
76
76
  readonly name: string;
77
+ readonly seatName?: string;
77
78
  /** One-line excerpt of the session's newest user or assistant text. */
78
79
  readonly description: string;
79
80
  /** CLI deposit status, explicitly online/offline on full host cards; absent on ordinary sessions. */
@@ -1,4 +1,4 @@
1
- /** Pure joined-local-handle projection for remote organization members. */
1
+ /** Pure membership projections: joined-local handles for remote organization members, canvas team indexes, mirror-frame members. */
2
2
  import type { RemoteTeamRow } from './federation'
3
3
  import type { SessionLite } from './world'
4
4
 
@@ -32,3 +32,30 @@ export function remoteMemberBoardId(member: string, localIdsByHandle: ReadonlyMa
32
32
  const peerZone = remoteTeams?.find(row => row.via === peerUrl)?.team.split('/')[0] ?? 'dsh'
33
33
  return `member-${peerZone}-${member.replace(/^session-/, '').slice(0, 8)}`
34
34
  }
35
+
36
+ /** Each member id → the canvas teams it sits in, with its position in that team's member order. */
37
+ export function membershipIndex(teams: ReadonlyArray<{ name: string; members: ReadonlyArray<{ id: string }> }>): Map<string, Array<{ team: string; index: number }>> {
38
+ const memberships = new Map<string, Array<{ team: string; index: number }>>()
39
+ for (const team of teams) {
40
+ for (let i = 0; i < team.members.length; i++) {
41
+ const id = team.members[i]!.id
42
+ const list = memberships.get(id) ?? []
43
+ list.push({ team: team.name, index: i })
44
+ memberships.set(id, list)
45
+ }
46
+ }
47
+ return memberships
48
+ }
49
+
50
+ /** Local joined sessions that sit in a peer's org team (a mirror frame): they are teamed even with no local team. */
51
+ export function mirrorMemberIds(peerOrg: ReadonlyArray<{ org: ReadonlyArray<{ members: readonly string[] }> }>, sessions: ReadonlyArray<HandleSession>, remoteTeams: ReadonlyArray<RemoteTeamRow> | undefined): Set<string> {
52
+ const byHandle = joinedLocalIdsByHandle(sessions, new Set((remoteTeams ?? []).map(session => session.team)))
53
+ const ids = new Set<string>()
54
+ for (const row of peerOrg) {
55
+ for (const team of row.org) for (const member of team.members) {
56
+ const id = byHandle.get(member)
57
+ if (id !== undefined) ids.add(id)
58
+ }
59
+ }
60
+ return ids
61
+ }
@@ -306,14 +306,13 @@ export function createPlanningMenus(d: MenusDeps): PlanningMenus {
306
306
  const create = menuItem('组成团队…', model.selectedIds().length >= 2, () => openNameDialog(selectedByY()))
307
307
  create.title = '先框选或 Shift 加选至少 2 个节点'
308
308
  items.push(create)
309
+ const teamsOf = model.getNode(id)?.memberships.map(m => m.team) ?? []
309
310
  if (d.teams().length > 0) {
310
311
  items.push(menuItem('加入团队 ▸', true, () => openMenu(x, y, target, 'join')))
311
- const teamsOf = model.getNode(id)?.memberships.map(m => m.team) ?? []
312
- if (teamsOf.length > 0) {
313
- items.push(menuItem('置顶路由 ▸', true, () => openMenu(x, y, target, 'promote')))
314
- items.push(menuItem('离队 ▸', true, () => openMenu(x, y, target, 'leave')))
315
- }
312
+ if (teamsOf.length > 0) items.push(menuItem('置顶路由 ▸', true, () => openMenu(x, y, target, 'promote')))
316
313
  }
314
+ // A card that is only in mirror frames (a peer's team) still has a team to leave.
315
+ if (teamsOf.length > 0) items.push(menuItem('离队 ▸', true, () => openMenu(x, y, target, 'leave')))
317
316
  // Network-level leave (distinct from canvas-team membership): the
318
317
  // panel-slim migration moved the join/leave toggle here. Remote
319
318
  // nodes are read-only entries — never a leave target.
@@ -342,6 +341,14 @@ export function createPlanningMenus(d: MenusDeps): PlanningMenus {
342
341
  }))
343
342
  }
344
343
  }
344
+ // d.teams() is this host's own teams; a mirror frame's membership leaves through
345
+ // the owner's relay (the view adds fleetPeer), so list those memberships too.
346
+ if (level === 'leave') {
347
+ const local = new Set(d.teams().map(t => t.name))
348
+ for (const m of model.getNode(id)?.memberships ?? []) {
349
+ if (!local.has(m.team)) items.push(menuItem(titleOf(m.team), true, () => d.emit({ type: 'remove-member', team: m.team, ids: [id] })))
350
+ }
351
+ }
345
352
  }
346
353
  }
347
354
  el.append(...items)
@@ -30,7 +30,8 @@ import { buildLayoutDoc, clampDoc, type LayoutDoc, type LayoutRect } from './lay
30
30
  import { FRAME_HEAD_LIFT } from './edges'
31
31
  import { drawMemberEdges } from './planning-edges'
32
32
  import { createFederationOverlay } from './federation-overlay'
33
- import { joinedLocalIdsByHandle, remoteMemberBoardId } from './planning-member-handles'
33
+ import { joinedLocalIdsByHandle, membershipIndex, mirrorMemberIds, remoteMemberBoardId } from './planning-member-handles'
34
+ import { attachSessionDrop } from './session-drag'
34
35
  import { displayName } from './stage-name'
35
36
  import {
36
37
  activityEdges, federalEdges, flyBounds, groupRemoteTeams, peerNodeId, peerHostOf, placePeers,
@@ -625,6 +626,12 @@ export function createPlanningView(deps: PlanningDeps): PlanningView {
625
626
  openNameDialog: menus.openNameDialog,
626
627
  locate: locateNode,
627
628
  })
629
+ // A rail 本机会话 row dropped on a frame joins that team, like a card drop (session-drag).
630
+ attachSessionDrop(root, {
631
+ signal, frames: () => frameEls,
632
+ frameAt: (clientX, clientY) => { const p = localXY({ clientX, clientY }); return innermostFrameAt(new Map(model.allFrames()), screenToWorld(vp, p.x, p.y)) },
633
+ drop: (team, id) => model.getNode(id)?.memberships.some(m => m.team === team) === true ? notice('info', '该会话已在这个队里') : emitAction({ type: 'add-member', team, ids: [id] }),
634
+ })
628
635
 
629
636
  /** Center the viewport on one canvas node (the 已组队 row's 定位). */
630
637
  function locateNode(id: string): void {
@@ -1119,15 +1126,7 @@ export function createPlanningView(deps: PlanningDeps): PlanningView {
1119
1126
  // toolbar chip instead of vanishing entirely.
1120
1127
  lastSessions = input.sessions
1121
1128
  menus.setUnjoined(input.sessions.filter(s => s.joined !== true && !s.id.startsWith('peer-')))
1122
- const memberships = new Map<string, Array<{ team: string; index: number }>>()
1123
- for (const team of input.teams) {
1124
- for (let i = 0; i < team.members.length; i++) {
1125
- const id = team.members[i]!.id
1126
- const list = memberships.get(id) ?? []
1127
- list.push({ team: team.name, index: i })
1128
- memberships.set(id, list)
1129
- }
1130
- }
1129
+ const memberships = membershipIndex(input.teams)
1131
1130
  lastCanvasMemberIds = new Set(memberships.keys())
1132
1131
  const seen = new Set<string>()
1133
1132
  // In-flight write guard: membership entries of teams with unsettled
@@ -1161,15 +1160,20 @@ export function createPlanningView(deps: PlanningDeps): PlanningView {
1161
1160
  syncViewSize()
1162
1161
  clusterSeats = planTeamClusters(input.teams, seatIds, viewW > 0 ? viewW : undefined)
1163
1162
  }
1163
+ // A joined session whose only team is a peer's (a mirror frame) is teamed too: without its
1164
+ // card the mirror frame cannot show it, and 离队 has nothing to reach (owner report 2026-11-04).
1165
+ const mirrorMembers = input.peerOrg !== undefined ? mirrorMemberIds(input.peerOrg, input.sessions, input.remoteTeams) : new Set<string>()
1166
+ // The node list reads the same fact: such a session is teamed, not 未组队.
1167
+ if (input.peerOrg !== undefined) lastCanvasMemberIds = new Set([...lastCanvasMemberIds, ...mirrorMembers])
1164
1168
  for (const s of input.sessions) {
1165
1169
  if (s.joined !== true) continue
1166
1170
  // Teamed-only canvas (network-membership-display ruling): a joined
1167
1171
  // session earns a canvas node only with a team — canvas membership
1168
- // (optimistic-aware) or a declared roster team. Teamless joined
1169
- // sessions ride the node list's 未组队 group instead; sessions absent
1170
- // from `seen` are swept from the model below.
1172
+ // (optimistic-aware), a declared roster team, or a mirror frame's
1173
+ // membership. Teamless joined sessions ride the node list's 未组队
1174
+ // group instead; sessions absent from `seen` are swept from the model below.
1171
1175
  const effective = resolveMemberships(s.id)
1172
- if (effective.length === 0 && (s.teams === undefined || s.teams.length === 0)) continue
1176
+ if (effective.length === 0 && (s.teams === undefined || s.teams.length === 0) && !mirrorMembers.has(s.id)) continue
1173
1177
  seen.add(s.id)
1174
1178
  if (model.getNode(s.id) !== undefined) {
1175
1179
  model.upsertNode({
@@ -0,0 +1,31 @@
1
+ /** Human owner form only: labels never grant membership or become routing ids. */
2
+ export function createSeatNameEditor(sessions: readonly { id: string; name?: string; label?: string }[], names: Record<string, string>, save: (names: Record<string, string>) => Promise<{ ok: boolean; error?: string }>): HTMLElement {
3
+ const box = document.createElement('section')
4
+ const heading = document.createElement('h4'); heading.textContent = '会话席位名(仅人工设定)'; box.appendChild(heading)
5
+ const note = document.createElement('p'); note.className = 'wb-hint'; note.textContent = '稳定展示名,不改变会话标题、路由句柄或准入。留空并保存可清除。'; box.appendChild(note)
6
+ const select = document.createElement('select'); select.setAttribute('aria-label', '选择命名的本机会话')
7
+ for (const id of new Set([...sessions.map(row => row.id), ...Object.keys(names)])) {
8
+ const row = sessions.find(row => row.id === id), option = document.createElement('option')
9
+ option.value = id; option.textContent = (names[id] ?? row?.name ?? row?.label ?? id) + ' · ' + id; select.appendChild(option)
10
+ }
11
+ const input = document.createElement('input'); input.type = 'text'; input.maxLength = 64; input.setAttribute('aria-label', '人工席位名'); input.placeholder = '例如:开发席'
12
+ const button = document.createElement('button'); button.type = 'submit'; button.textContent = '保存席位名'; button.className = 'wb-member-submit'
13
+ const form = document.createElement('form'); form.className = 'wb-member-add'; form.append(select, input, button)
14
+ const status = document.createElement('p'); status.className = 'wb-hint'; status.setAttribute('role', 'status'); status.setAttribute('aria-live', 'polite')
15
+ let pending = false
16
+ const load = () => { input.value = names[select.value] ?? ''; button.disabled = pending || select.value === '' }
17
+ select.addEventListener('change', load); load()
18
+ form.addEventListener('submit', async event => {
19
+ event.preventDefault(); if (pending || select.value === '') return
20
+ const id = select.value, value = input.value.trim(), next = { ...names }
21
+ if (value === '') delete next[id]; else next[id] = value
22
+ pending = true; button.disabled = true; select.disabled = true; input.disabled = true
23
+ try {
24
+ const result = await save(next)
25
+ if (result.ok) { delete names[id]; if (value !== '') names[id] = value; status.textContent = '席位名已保存;目录将随状态刷新。' }
26
+ else status.textContent = result.error ?? '保存失败'
27
+ } catch (error) { status.textContent = '保存失败:' + String(error) }
28
+ finally { pending = false; select.disabled = false; input.disabled = false; load() }
29
+ })
30
+ box.append(form, status); return box
31
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Drag a local session from the workbench rail (目录 · 本机会话) straight into
3
+ * a canvas team frame on the board (owner request 2026-11-04). The rail row
4
+ * carries the session id in a private drag type; the board accepts it only
5
+ * over a frame and turns the drop into the same add-member action a card drop
6
+ * makes, so roster frames, mirror frames (fleet relay) and the host's own
7
+ * refusals all behave exactly as for an on-board drag.
8
+ * @module nexus-stage/session-drag
9
+ */
10
+
11
+ /** Private drag type: an arbitrary page or file dropped on the board is ignored. */
12
+ export const SESSION_DRAG_TYPE = 'application/x-dsh-session'
13
+
14
+ /** Make one rail row draggable as a local session. */
15
+ export function makeSessionDraggable(item: HTMLElement, sessionId: string): void {
16
+ item.draggable = true
17
+ item.classList.add('is-draggable')
18
+ item.title = `${item.title === '' ? sessionId : item.title} · 可拖入画布队`
19
+ item.addEventListener('dragstart', ev => {
20
+ if (ev.dataTransfer === null) return
21
+ ev.dataTransfer.setData(SESSION_DRAG_TYPE, sessionId)
22
+ ev.dataTransfer.effectAllowed = 'copy'
23
+ })
24
+ }
25
+
26
+ export interface SessionDropDeps {
27
+ /** The innermost team frame under a client point, if any. */
28
+ frameAt(clientX: number, clientY: number): string | undefined
29
+ /** Frame elements by team name, for the drop-target highlight. */
30
+ frames(): ReadonlyMap<string, HTMLElement>
31
+ /** A session dropped on a frame. */
32
+ drop(team: string, sessionId: string): void
33
+ readonly signal: AddEventListenerOptions
34
+ }
35
+
36
+ /** Accept rail session drags on the board root. */
37
+ export function attachSessionDrop(root: HTMLElement, d: SessionDropDeps): void {
38
+ const carries = (ev: DragEvent): boolean => ev.dataTransfer !== null && [...ev.dataTransfer.types].includes(SESSION_DRAG_TYPE)
39
+ const highlight = (team: string | undefined): void => {
40
+ for (const [name, el] of d.frames()) el.classList.toggle('drop-target', name === team)
41
+ }
42
+ root.addEventListener('dragover', ev => {
43
+ if (!carries(ev)) return
44
+ const team = d.frameAt(ev.clientX, ev.clientY)
45
+ highlight(team)
46
+ if (team === undefined) return
47
+ ev.preventDefault() // only a frame is a drop target
48
+ ev.dataTransfer!.dropEffect = 'copy'
49
+ }, d.signal)
50
+ root.addEventListener('dragleave', ev => {
51
+ if (carries(ev) && (ev.relatedTarget === null || !root.contains(ev.relatedTarget as Node))) highlight(undefined)
52
+ }, d.signal)
53
+ // A drag cancelled with Esc over a frame fires no dragleave on the board: the source's dragend clears it.
54
+ root.ownerDocument.addEventListener('dragend', () => highlight(undefined), d.signal)
55
+ root.addEventListener('drop', ev => {
56
+ if (!carries(ev)) return
57
+ highlight(undefined)
58
+ const team = d.frameAt(ev.clientX, ev.clientY)
59
+ const id = ev.dataTransfer!.getData(SESSION_DRAG_TYPE)
60
+ if (team === undefined || id === '') return
61
+ ev.preventDefault()
62
+ d.drop(team, id)
63
+ }, d.signal)
64
+ }
@@ -15,6 +15,7 @@
15
15
  import type { CanvasTeamRow, StateBody } from './workbench'
16
16
  import type { ChatTarget } from './wb-chat'
17
17
  import { displayName } from './stage-name'
18
+ import { makeSessionDraggable } from './session-drag'
18
19
 
19
20
  export type DirFilter = 'all' | 'local' | 'canvas' | 'remote' | 'logs'
20
21
 
@@ -140,6 +141,7 @@ export function renderDirectory(box: HTMLElement, ctx: DirectoryContext): string
140
141
  item.querySelector('.wb-item-text')?.appendChild(note)
141
142
  }
142
143
  badges(item, s.canvasTeams)
144
+ makeSessionDraggable(item, s.id)
143
145
  }
144
146
  }
145
147
 
@@ -49,6 +49,7 @@ body{background:var(--n-bg);color:var(--n-ink);font:13px/1.45 system-ui,"Segoe U
49
49
  width:30px;height:30px;display:none;align-items:center;justify-content:center;font:inherit;font-size:14px;
50
50
  cursor:pointer;flex:none}
51
51
  .wb-icon-btn:hover{border-color:var(--n-accent)}
52
+ .wb-owner-btn{display:inline-flex}
52
53
  .wb-menu{margin-left:0}
53
54
  .wb-rail-toggle{margin-left:auto}
54
55
  .wb.is-rail-collapsed .wb-rail{display:none}
@@ -320,6 +321,7 @@ body{background:var(--n-bg);color:var(--n-ink);font:13px/1.45 system-ui,"Segoe U
320
321
  .wb-dir-day{padding:6px 6px 2px;font-size:10.5px;color:var(--n-ink-muted)}
321
322
  .wb-dir-empty{padding:24px 8px;text-align:center;font-size:12px;color:var(--n-ink-muted)}
322
323
  .wb-directory .wb-item{gap:9px;padding:5px 6px;border-radius:8px}
324
+ .wb-directory .wb-item.is-draggable{cursor:grab}
323
325
  .wb-directory .wb-item:focus-visible{outline:2px solid var(--n-accent);outline-offset:-2px}
324
326
  .wb-item-text{display:flex;flex-direction:column;flex:1 1 auto;min-width:0;line-height:1.35}
325
327
  .wb-item-sub{font:11px/1.35 ui-monospace,Consolas,monospace;color:var(--n-ink-muted);