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

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 (43) hide show
  1. package/README.md +4 -1
  2. package/README_zh.md +4 -1
  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 +1 -1
  7. package/lib/a2a-client.js +3 -3
  8. package/lib/client.js +63 -63
  9. package/lib/faces/admin.js +20 -4
  10. package/lib/faces/canvas-notify.js +8 -6
  11. package/lib/faces/wire.js +11 -5
  12. package/lib/index.js +30 -10
  13. package/lib/origin-claim.js +30 -7
  14. package/lib/owner-settings.js +38 -1
  15. package/lib/peer-link-display.js +15 -0
  16. package/lib/skill/references/cli.md +4 -0
  17. package/lib/skill/references/setup.md +4 -0
  18. package/lib/task-ledger-rows.js +192 -0
  19. package/lib/task-ledger.js +2 -191
  20. package/lib/tools/info.js +3 -1
  21. package/lib/types/a2a-client.d.ts +1 -0
  22. package/lib/types/faces/admin.d.ts +1 -0
  23. package/lib/types/faces/canvas-notify.d.ts +3 -1
  24. package/lib/types/faces/wire.d.ts +1 -0
  25. package/lib/types/index.d.ts +2 -0
  26. package/lib/types/origin-claim.d.ts +12 -3
  27. package/lib/types/owner-settings.d.ts +5 -0
  28. package/lib/types/peer-link-display.d.ts +13 -0
  29. package/lib/types/task-ledger-rows.d.ts +341 -0
  30. package/lib/types/task-ledger.d.ts +4 -288
  31. package/lib/types/tools/info.d.ts +2 -0
  32. package/lib/types/types.d.ts +2 -1
  33. package/nexus-stage/src/planning-member-handles.ts +28 -1
  34. package/nexus-stage/src/planning-menus.ts +12 -5
  35. package/nexus-stage/src/planning-view.ts +18 -14
  36. package/nexus-stage/src/seat-name-editor.ts +31 -0
  37. package/nexus-stage/src/session-drag.ts +64 -0
  38. package/nexus-stage/src/wb-directory.ts +2 -0
  39. package/nexus-stage/src/workbench.css +2 -0
  40. package/nexus-stage/src/workbench.ts +16 -5
  41. package/package.json +1 -1
  42. package/assets/nexusDist/assets/index-DIQNDBy6.js +0 -9
  43. package/assets/nexusDist/assets/index-z33lHtLw.css +0 -1
@@ -8,8 +8,39 @@
8
8
  * else; a missing entry is appended in the canonical short-id form.
9
9
  * @module @nelsonlongxiang/dsh-open-a2a-net/owner-settings
10
10
  */
11
+ /** A label shaped like a routable address (`dsh/66abc2cf`, `zone/canvas/x`, `name/<16 hex>`) would pass for another
12
+ * session in the directory and in `a2a-net teams <query>`; labels are display-only, so that shape is refused. */
13
+ const ADDRESS_SHAPED = /^[A-Za-z0-9._-]+\/\S+$/;
14
+ /** Shared validation for boot config and owner POST; labels are plain text, never handles or authority. */
15
+ export function parseSeatNames(value) {
16
+ if (value === null || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).length > 1024)
17
+ return undefined;
18
+ const entries = Object.entries(value);
19
+ if (entries.some(([id, name]) => !/^session-[a-zA-Z0-9-]{8,128}$/.test(id) || typeof name !== 'string' || name.trim() === '' || [...name.trim()].length > 64 || /[\p{Cc}\p{Cf}\u2028\u2029\ufffd]/u.test(name) || !/[^\p{Z}\p{C}\p{M}]/u.test(name) || ADDRESS_SHAPED.test(name.trim())))
20
+ return undefined;
21
+ return Object.fromEntries(entries.map(([id, name]) => [id, name.trim()]));
22
+ }
23
+ /** Boot config degrades entry-by-entry; owner POST remains all-or-nothing. Never echo label contents in warnings. */
24
+ export function loadSeatNames(value, warn) {
25
+ if (value === null || typeof value !== 'object' || Array.isArray(value)) {
26
+ warn('seatNames: ignored invalid map');
27
+ return {};
28
+ }
29
+ const kept = {};
30
+ let count = 0;
31
+ for (const [id, name] of Object.entries(value)) {
32
+ const entry = parseSeatNames({ [id]: name });
33
+ if (entry === undefined || count >= 1024) {
34
+ warn('seatNames: ignored invalid or over-cap entry');
35
+ continue;
36
+ }
37
+ Object.assign(kept, entry);
38
+ count += 1;
39
+ }
40
+ return kept;
41
+ }
11
42
  /** The exact keys this module may touch, in wire order. */
12
- const KEYS = ['teamJoinAllowlist', 'teamScopeInfo', 'announce'];
43
+ const KEYS = ['teamJoinAllowlist', 'teamScopeInfo', 'announce', 'seatNames'];
13
44
  export function applyOwnerSettings(patchYaml, changes) {
14
45
  const lines = patchYaml.split('\n');
15
46
  // Find the a2a entry: `- id: a2a` / `- id: 'a2a'` variants.
@@ -34,6 +65,8 @@ export function applyOwnerSettings(patchYaml, changes) {
34
65
  writes.push(` teamScopeInfo: ${changes.teamScopeInfo ? 'true' : 'false'}`);
35
66
  if (changes.announce !== undefined)
36
67
  writes.push(` announce: ${changes.announce ? 'true' : 'false'}`);
68
+ if (changes.seatNames !== undefined)
69
+ writes.push(` seatNames: ${JSON.stringify(changes.seatNames)}`);
37
70
  if (writes.length === 0)
38
71
  return { yaml: patchYaml, restartNeeded };
39
72
  if (entryStart === -1) {
@@ -81,6 +114,10 @@ export function applyOwnerSettings(patchYaml, changes) {
81
114
  if (write !== undefined) {
82
115
  lines[j] = write;
83
116
  found = true;
117
+ // A map may have been authored as block YAML. Replace its nested rows too, not just the heading.
118
+ if (key === 'seatNames')
119
+ while (j + 1 < lines.length && (/^ {5,}\S/.test(lines[j + 1] ?? '') || /^\s*$/.test(lines[j + 1] ?? '')))
120
+ lines.splice(j + 1, 1);
84
121
  }
85
122
  break;
86
123
  }
@@ -0,0 +1,15 @@
1
+ export function peerLinkDisplay(peerUrl, d) {
2
+ const { card } = d;
3
+ if (card === undefined)
4
+ return { link: 'stranger', verified: false };
5
+ const origin = (url) => { try {
6
+ return new URL(url).origin;
7
+ }
8
+ catch {
9
+ return '';
10
+ } };
11
+ const peerOrigin = origin(peerUrl), ownOrigin = origin(d.ownUrl);
12
+ const bilateral = peerOrigin !== '' && ownOrigin !== '' && d.seeds.some(url => origin(url) === peerOrigin) && (card.peers ?? []).some(url => origin(url) === ownOrigin);
13
+ const exactMember = d.refs.some(ref => !d.ownHandles.has(ref) && (card.sessionTeams ?? []).some(row => row.team === ref) && !d.cards.some(other => other.publicKey !== card.publicKey && (other.sessionTeams ?? []).some(row => row.team === ref)));
14
+ return { link: bilateral || exactMember ? 'linked' : 'stranger', verified: true };
15
+ }
@@ -42,6 +42,10 @@ model tools.
42
42
  405 with an empty body. The fix is a host upgrade, not a retry.
43
43
  - `a2a-net revoke` deregisters early.
44
44
 
45
+ ## Team display names
46
+
47
+ `a2a-net teams <query>` searches the owner-set seat label as well as the route handle; `--json` exposes the effective display name. Local rows prefer `seatName`, then the current title (`name`), then the legacy label. Only the human workbench owner panel/config can set `seatNames`; the CLI has no naming command.
48
+
45
49
  ## Tasks: ledger and host observability
46
50
 
47
51
  `a2a-net tasks --json` returns the existing `pending`, `dead`, and `archived` arrays plus `settlement` and `conservation` copied unchanged from `/__dsh_a2a/state`. These blocks include the lifetime `settlement.refusalsTotal`, refusal ring and mode, and the host conservation verdict/counters/duplicate ids. Older hosts omit a block they do not expose; the CLI does not manufacture zero counters or a passing verdict. Plain `tasks` appends a conservation line (`conserved`, `delta`) and a settlement line (`mode`, `refusalsTotal`, `offChain`) when the respective block exists.
@@ -21,6 +21,10 @@ presenting the operator's gesture on the operator's behalf is exactly the
21
21
  | Version | `/__dsh_a2a/state` `version`, or the workbench header badge | the same version on every host you will link (0.6.28+) |
22
22
  | Clock | `date` on each host | NTP-synced: card signatures carry `expiresAt`, and the OriginClaim envelope allows ±5 min |
23
23
 
24
+ ## Human seat names
25
+
26
+ The owner can open the workbench header ⚙, select a local session under “会话席位名”, and explicitly save a stable display name (up to 64 characters; a name shaped like a route address such as `dsh/66abc2cf` is refused so it cannot pass for another session). Empty input clears the label. The `seatNames` map is stored in the home patch layer and hot-applies; cards and the board prefer it over the session title, and `a2a_whoami` / `a2a-net teams <name>` expose it. It never changes the route handle, join state or admission. Agents must ask the owner rather than self-name: A2A tool arguments containing `seatName`/`seatNames` are refused; no naming model tool exists. The owner control API keeps its existing apiKey/loopback trust model, not a sandbox against local shell or config-file writers.
27
+
24
28
  ## 1. One host: sessions talking to each other
25
29
 
26
30
  **Owner:**
@@ -0,0 +1,192 @@
1
+ /** Stateless ledger row types, classifiers and restore projections; moved verbatim for #258. */
2
+ import { parseAuthorization } from "./task-auth.js";
3
+ /**
4
+ * Caller-ended summaries (abandon / cancel) share one isolation law: late
5
+ * receipts never rewrite the verdict — they only stamp lateReceiptAt, and
6
+ * the projected outcome collapses to 'abandoned'.
7
+ */
8
+ export const CALLER_ENDED_PREFIX = /^caller-(abandoned|cancelled)/;
9
+ /** Hard cap on the owed book (pending + dead-lettered rows, most recent first). */
10
+ export const TASK_CAP = 64;
11
+ /** Hard cap on the settled archive (most recent kept). */
12
+ export const ARCHIVE_CAP = 64;
13
+ /** Longest receipt summary kept on a record (multi-line outcomes collapse). */
14
+ export const SUMMARY_CAP = 200;
15
+ /**
16
+ * Longest dispatch brief kept per row. A ledger row without its payload is
17
+ * unreadable to supervision — "direct-8f3a1c2b → dsh/ec4ce7f8, 3h old" says
18
+ * nothing about whether to nudge, abandon, or read the receipt. The brief is
19
+ * the first non-empty line of the message, capped; the full body never enters
20
+ * the ledger (it can be arbitrarily large and may quote another session's log).
21
+ */
22
+ export const BRIEF_CAP = 120;
23
+ /** Reduce a dispatch body to one readable line: first non-empty line, collapsed, capped. */
24
+ export function briefOf(message) {
25
+ if (message === undefined)
26
+ return undefined;
27
+ for (const raw of message.split('\n')) {
28
+ const line = raw.trim().replace(/\s+/g, ' ');
29
+ if (line !== '')
30
+ return line.length <= BRIEF_CAP ? line : `${line.slice(0, BRIEF_CAP - 1)}…`;
31
+ }
32
+ return undefined;
33
+ }
34
+ /**
35
+ * Age at which an unsettled task auto-dead-letters. A dead row exits the
36
+ * owed view, disarms its async-nudge retry (a cold session cannot consume a
37
+ * re-steer anyway), and still accepts a late receipt from a revived target.
38
+ * Injectable per instance so tests can use short windows; sweeping stays
39
+ * lazy — every read/write entry point sweeps first.
40
+ */
41
+ export const TASK_STALE_TTL_MS = 24 * 60 * 60_000;
42
+ export const ARCHIVE_ENDS = ['receipt', 'echo', 'abandoned', 'cancelled', 'evicted'];
43
+ /** Summary marker {@link TaskLedger.resolveEcho} writes on echo-settled rows. */
44
+ export const ECHO_SUMMARY = '(settled by content echo)';
45
+ const SENDER_KINDS = ['session', 'host', 'bridge', 'cli'];
46
+ /** Longest sender id kept; anything longer is malformed, not truncated. */
47
+ export const SENDER_ID_CAP = 256;
48
+ /**
49
+ * Restore-side allowlist for one persisted sender: a well-formed value comes
50
+ * back as a fresh object holding only kind, id and (when present) face; anything else is dropped whole (the row
51
+ * itself survives — a bad sender never costs the debt record).
52
+ * @param raw - the persisted value.
53
+ * @returns the sender, or undefined when absent or malformed.
54
+ */
55
+ export function parseSender(raw) {
56
+ if (raw === null || typeof raw !== 'object' || Array.isArray(raw))
57
+ return undefined;
58
+ const { kind, id, face } = raw;
59
+ if (typeof kind !== 'string' || !SENDER_KINDS.includes(kind))
60
+ return undefined;
61
+ if (typeof id !== 'string' || id === '' || id.length > SENDER_ID_CAP)
62
+ return undefined;
63
+ if (face !== undefined && (typeof face !== 'string' || face === '' || face.length > SENDER_ID_CAP))
64
+ return undefined;
65
+ // `face` belongs to host senders only; on any other kind it is dropped, the sender kept.
66
+ return { kind: kind, id, ...(face !== undefined && kind === 'host' ? { face } : {}) };
67
+ }
68
+ /**
69
+ * Spread helper for restore: `{ sender }` when the persisted value parses and
70
+ * the row is not inbound (an inbound row's originator is its caller, never a
71
+ * sender this host recorded), else nothing.
72
+ */
73
+ export function withSender(raw, direction) {
74
+ if (direction === 'inbound')
75
+ return {};
76
+ const sender = parseSender(raw);
77
+ return sender === undefined ? {} : { sender };
78
+ }
79
+ /**
80
+ * #114 S2: `{ auth }` when a persisted INBOUND row carries a record that
81
+ * parses whole (parseAuthorization) and belongs to THIS row — its target is
82
+ * the row's team and its receipt target the row's peer — else nothing: the
83
+ * row survives as a pre-S2 row, never with a partially adopted or borrowed
84
+ * record.
85
+ */
86
+ export function withAuth(raw, entry, now) {
87
+ if (entry.direction !== 'inbound' && entry.direction !== 'outbound')
88
+ return {};
89
+ const auth = parseAuthorization(raw, now);
90
+ if (auth === undefined || auth.target !== entry.team)
91
+ return {};
92
+ if (entry.direction === 'inbound')
93
+ return auth.ingress === 'wire' && `local:${auth.receipt_target}` === entry.peer ? { auth } : {};
94
+ // #139: an outbound row carries only its local-candidate admission.
95
+ return auth.ingress === 'local' && entry.peer === 'local' ? { auth } : {};
96
+ }
97
+ /** Routing and answer facts copied unchanged between a row and its archive entry. */
98
+ export function routingOf(row) {
99
+ return {
100
+ ...(row.answeredAt !== undefined ? { answeredAt: row.answeredAt } : {}),
101
+ ...(row.forwarded === true ? { forwarded: true } : {}),
102
+ ...(row.peerKey !== undefined ? { peerKey: row.peerKey } : {}),
103
+ ...(row.peerHost !== undefined ? { peerHost: row.peerHost } : {}),
104
+ ...(row.deliveredTo !== undefined ? { deliveredTo: row.deliveredTo } : {}),
105
+ };
106
+ }
107
+ /** The facts of one outbound birth that fit the row (see {@link withRouting} for the same shape on restore). */
108
+ export function birthFacts(peer, birth) {
109
+ if (birth === undefined)
110
+ return {};
111
+ const fact = (v) => v !== undefined && v !== '' && v.length <= ROUTING_FACT_CAP;
112
+ const remote = peer !== 'local' && !peer.startsWith('local:');
113
+ return {
114
+ ...(!remote && birth.auth !== undefined && birth.auth.ingress === 'local' ? { auth: birth.auth } : {}),
115
+ ...(remote && birth.forwarded === true ? { forwarded: true } : {}),
116
+ ...(remote && fact(birth.peerKey) ? { peerKey: birth.peerKey } : {}),
117
+ ...(remote && fact(birth.peerHost) ? { peerHost: birth.peerHost } : {}),
118
+ ...(fact(birth.deliveredTo) ? { deliveredTo: birth.deliveredTo } : {}),
119
+ };
120
+ }
121
+ /** Bound on a persisted routing fact; anything longer (or empty, or not a string) is dropped on restore. */
122
+ export const ROUTING_FACT_CAP = 256;
123
+ /**
124
+ * #139: restore-side allowlist for the routing facts. Each is kept only in
125
+ * its shape — a non-empty string within the cap — and the peer facts only on
126
+ * a remote outbound row; anything else is dropped (the row survives as one
127
+ * born before the fields, judged by current membership and origin).
128
+ */
129
+ export function withRouting(entry) {
130
+ const fact = (v) => typeof v === 'string' && v !== '' && v.length <= ROUTING_FACT_CAP;
131
+ const remoteOutbound = entry.direction === 'outbound' && typeof entry.peer === 'string' && entry.peer !== 'local' && !entry.peer.startsWith('local:');
132
+ return {
133
+ ...(typeof entry.answeredAt === 'number' && Number.isFinite(entry.answeredAt) && entry.answeredAt >= 0 ? { answeredAt: entry.answeredAt } : {}),
134
+ ...(remoteOutbound && entry.forwarded === true ? { forwarded: true } : {}),
135
+ ...(remoteOutbound && fact(entry.peerKey) ? { peerKey: entry.peerKey } : {}),
136
+ ...(remoteOutbound && fact(entry.peerHost) ? { peerHost: entry.peerHost } : {}),
137
+ ...(fact(entry.deliveredTo) ? { deliveredTo: entry.deliveredTo } : {}),
138
+ };
139
+ }
140
+ /**
141
+ * How one archived row ended (gh#31). The recorded field wins; legacy rows
142
+ * fall back to the summary markers this ledger writes itself. The fallback
143
+ * reads a receipt-settled row's summary, which is the peer's text, so it is
144
+ * only as exact as the legacy data allows.
145
+ * @param row - the archived record.
146
+ * @returns the archive path that ended it.
147
+ */
148
+ export function archivedEndedBy(row) {
149
+ if (row.endedBy !== undefined)
150
+ return row.endedBy;
151
+ const summary = row.summary ?? '';
152
+ if (summary.startsWith('caller-cancelled'))
153
+ return 'cancelled';
154
+ if (summary.startsWith('caller-abandoned'))
155
+ return 'abandoned';
156
+ if (summary === ECHO_SUMMARY)
157
+ return 'echo';
158
+ return 'receipt';
159
+ }
160
+ /** Bound on ids and callers kept in settlement records; longer values are cut on write and refused on restore. */
161
+ export const SETTLEMENT_ID_CAP = 256;
162
+ /** Bound of the refusal ring (design §4.4). */
163
+ export const SETTLEMENT_REFUSAL_CAP = 64;
164
+ const SETTLEMENT_REASONS = ['settler-off-chain', 'settler-unverified', 'on-behalf-mismatch', 'echo-off-chain'];
165
+ const CHAIN_ROLES = ['target', 'target-member', 'host-face', 'compat', 'legacy', 'off-chain'];
166
+ const PROOF_VALUES = ['origin-claim', 'claim-mismatch', 'legacy-window', 'unbound', 'cli-identity', 'in-process', 'none'];
167
+ /** Restore-side allowlist for settledBy: whole or nothing. */
168
+ export function withSettledBy(raw) {
169
+ if (raw === null || typeof raw !== 'object')
170
+ return {};
171
+ const r = raw;
172
+ if (typeof r.caller !== 'string' || r.caller.length > SETTLEMENT_ID_CAP || typeof r.chain_role !== 'string' || !CHAIN_ROLES.includes(r.chain_role))
173
+ return {};
174
+ return { settledBy: { caller: r.caller, chain_role: r.chain_role } };
175
+ }
176
+ /** Restore-side allowlist for one refusal record: whole or nothing. */
177
+ export function parseRefusal(raw) {
178
+ if (raw === null || typeof raw !== 'object')
179
+ return undefined;
180
+ const r = raw;
181
+ const st = r.settler;
182
+ if (typeof r.taskId !== 'string' || r.taskId === '' || r.taskId.length > SETTLEMENT_ID_CAP || typeof r.at !== 'number' || !Number.isFinite(r.at))
183
+ return undefined;
184
+ if (typeof r.reason !== 'string' || !SETTLEMENT_REASONS.includes(r.reason) || typeof r.head !== 'string' || typeof r.enforced !== 'boolean')
185
+ return undefined;
186
+ if (st === null || typeof st !== 'object' || typeof st.caller !== 'string' || st.caller.length > SETTLEMENT_ID_CAP || typeof st.proof !== 'string' || !PROOF_VALUES.includes(st.proof) || (st.ingress !== 'wire' && st.ingress !== 'local'))
187
+ return undefined;
188
+ const count = r.count === undefined ? 1 : r.count;
189
+ if (typeof count !== 'number' || !Number.isInteger(count) || count < 1)
190
+ return undefined;
191
+ return { taskId: r.taskId, at: r.at, settler: { caller: st.caller, proof: st.proof, ingress: st.ingress }, reason: r.reason, head: r.head.slice(0, SUMMARY_CAP), enforced: r.enforced, count };
192
+ }
@@ -18,201 +18,12 @@
18
18
  * illusion: settlements vanished while debts piled up).
19
19
  * @module @nelsonlongxiang/dsh-open-a2a-net/task-ledger
20
20
  */
21
- import { parseAuthorization } from "./task-auth.js";
22
21
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
23
22
  import { dirname } from 'node:path';
24
23
  import { parseReceipt, RECEIPT_OUTCOMES } from "./receipt.js";
25
24
  import { classifyConservationBlock, ConservationCounters } from "./ledger-conservation.js";
26
- /**
27
- * Caller-ended summaries (abandon / cancel) share one isolation law: late
28
- * receipts never rewrite the verdict — they only stamp lateReceiptAt, and
29
- * the projected outcome collapses to 'abandoned'.
30
- */
31
- const CALLER_ENDED_PREFIX = /^caller-(abandoned|cancelled)/;
32
- /** Hard cap on the owed book (pending + dead-lettered rows, most recent first). */
33
- export const TASK_CAP = 64;
34
- /** Hard cap on the settled archive (most recent kept). */
35
- export const ARCHIVE_CAP = 64;
36
- /** Longest receipt summary kept on a record (multi-line outcomes collapse). */
37
- export const SUMMARY_CAP = 200;
38
- /**
39
- * Longest dispatch brief kept per row. A ledger row without its payload is
40
- * unreadable to supervision — "direct-8f3a1c2b → dsh/ec4ce7f8, 3h old" says
41
- * nothing about whether to nudge, abandon, or read the receipt. The brief is
42
- * the first non-empty line of the message, capped; the full body never enters
43
- * the ledger (it can be arbitrarily large and may quote another session's log).
44
- */
45
- export const BRIEF_CAP = 120;
46
- /** Reduce a dispatch body to one readable line: first non-empty line, collapsed, capped. */
47
- export function briefOf(message) {
48
- if (message === undefined)
49
- return undefined;
50
- for (const raw of message.split('\n')) {
51
- const line = raw.trim().replace(/\s+/g, ' ');
52
- if (line !== '')
53
- return line.length <= BRIEF_CAP ? line : `${line.slice(0, BRIEF_CAP - 1)}…`;
54
- }
55
- return undefined;
56
- }
57
- /**
58
- * Age at which an unsettled task auto-dead-letters. A dead row exits the
59
- * owed view, disarms its async-nudge retry (a cold session cannot consume a
60
- * re-steer anyway), and still accepts a late receipt from a revived target.
61
- * Injectable per instance so tests can use short windows; sweeping stays
62
- * lazy — every read/write entry point sweeps first.
63
- */
64
- export const TASK_STALE_TTL_MS = 24 * 60 * 60_000;
65
- const ARCHIVE_ENDS = ['receipt', 'echo', 'abandoned', 'cancelled', 'evicted'];
66
- /** Summary marker {@link TaskLedger.resolveEcho} writes on echo-settled rows. */
67
- const ECHO_SUMMARY = '(settled by content echo)';
68
- const SENDER_KINDS = ['session', 'host', 'bridge', 'cli'];
69
- /** Longest sender id kept; anything longer is malformed, not truncated. */
70
- export const SENDER_ID_CAP = 256;
71
- /**
72
- * Restore-side allowlist for one persisted sender: a well-formed value comes
73
- * back as a fresh object holding only kind, id and (when present) face; anything else is dropped whole (the row
74
- * itself survives — a bad sender never costs the debt record).
75
- * @param raw - the persisted value.
76
- * @returns the sender, or undefined when absent or malformed.
77
- */
78
- export function parseSender(raw) {
79
- if (raw === null || typeof raw !== 'object' || Array.isArray(raw))
80
- return undefined;
81
- const { kind, id, face } = raw;
82
- if (typeof kind !== 'string' || !SENDER_KINDS.includes(kind))
83
- return undefined;
84
- if (typeof id !== 'string' || id === '' || id.length > SENDER_ID_CAP)
85
- return undefined;
86
- if (face !== undefined && (typeof face !== 'string' || face === '' || face.length > SENDER_ID_CAP))
87
- return undefined;
88
- // `face` belongs to host senders only; on any other kind it is dropped, the sender kept.
89
- return { kind: kind, id, ...(face !== undefined && kind === 'host' ? { face } : {}) };
90
- }
91
- /**
92
- * Spread helper for restore: `{ sender }` when the persisted value parses and
93
- * the row is not inbound (an inbound row's originator is its caller, never a
94
- * sender this host recorded), else nothing.
95
- */
96
- function withSender(raw, direction) {
97
- if (direction === 'inbound')
98
- return {};
99
- const sender = parseSender(raw);
100
- return sender === undefined ? {} : { sender };
101
- }
102
- /**
103
- * #114 S2: `{ auth }` when a persisted INBOUND row carries a record that
104
- * parses whole (parseAuthorization) and belongs to THIS row — its target is
105
- * the row's team and its receipt target the row's peer — else nothing: the
106
- * row survives as a pre-S2 row, never with a partially adopted or borrowed
107
- * record.
108
- */
109
- function withAuth(raw, entry, now) {
110
- if (entry.direction !== 'inbound' && entry.direction !== 'outbound')
111
- return {};
112
- const auth = parseAuthorization(raw, now);
113
- if (auth === undefined || auth.target !== entry.team)
114
- return {};
115
- if (entry.direction === 'inbound')
116
- return auth.ingress === 'wire' && `local:${auth.receipt_target}` === entry.peer ? { auth } : {};
117
- // #139: an outbound row carries only its local-candidate admission.
118
- return auth.ingress === 'local' && entry.peer === 'local' ? { auth } : {};
119
- }
120
- /** Routing and answer facts copied unchanged between a row and its archive entry. */
121
- function routingOf(row) {
122
- return {
123
- ...(row.answeredAt !== undefined ? { answeredAt: row.answeredAt } : {}),
124
- ...(row.forwarded === true ? { forwarded: true } : {}),
125
- ...(row.peerKey !== undefined ? { peerKey: row.peerKey } : {}),
126
- ...(row.peerHost !== undefined ? { peerHost: row.peerHost } : {}),
127
- ...(row.deliveredTo !== undefined ? { deliveredTo: row.deliveredTo } : {}),
128
- };
129
- }
130
- /** The facts of one outbound birth that fit the row (see {@link withRouting} for the same shape on restore). */
131
- function birthFacts(peer, birth) {
132
- if (birth === undefined)
133
- return {};
134
- const fact = (v) => v !== undefined && v !== '' && v.length <= ROUTING_FACT_CAP;
135
- const remote = peer !== 'local' && !peer.startsWith('local:');
136
- return {
137
- ...(!remote && birth.auth !== undefined && birth.auth.ingress === 'local' ? { auth: birth.auth } : {}),
138
- ...(remote && birth.forwarded === true ? { forwarded: true } : {}),
139
- ...(remote && fact(birth.peerKey) ? { peerKey: birth.peerKey } : {}),
140
- ...(remote && fact(birth.peerHost) ? { peerHost: birth.peerHost } : {}),
141
- ...(fact(birth.deliveredTo) ? { deliveredTo: birth.deliveredTo } : {}),
142
- };
143
- }
144
- /** Bound on a persisted routing fact; anything longer (or empty, or not a string) is dropped on restore. */
145
- const ROUTING_FACT_CAP = 256;
146
- /**
147
- * #139: restore-side allowlist for the routing facts. Each is kept only in
148
- * its shape — a non-empty string within the cap — and the peer facts only on
149
- * a remote outbound row; anything else is dropped (the row survives as one
150
- * born before the fields, judged by current membership and origin).
151
- */
152
- function withRouting(entry) {
153
- const fact = (v) => typeof v === 'string' && v !== '' && v.length <= ROUTING_FACT_CAP;
154
- const remoteOutbound = entry.direction === 'outbound' && typeof entry.peer === 'string' && entry.peer !== 'local' && !entry.peer.startsWith('local:');
155
- return {
156
- ...(typeof entry.answeredAt === 'number' && Number.isFinite(entry.answeredAt) && entry.answeredAt >= 0 ? { answeredAt: entry.answeredAt } : {}),
157
- ...(remoteOutbound && entry.forwarded === true ? { forwarded: true } : {}),
158
- ...(remoteOutbound && fact(entry.peerKey) ? { peerKey: entry.peerKey } : {}),
159
- ...(remoteOutbound && fact(entry.peerHost) ? { peerHost: entry.peerHost } : {}),
160
- ...(fact(entry.deliveredTo) ? { deliveredTo: entry.deliveredTo } : {}),
161
- };
162
- }
163
- /**
164
- * How one archived row ended (gh#31). The recorded field wins; legacy rows
165
- * fall back to the summary markers this ledger writes itself. The fallback
166
- * reads a receipt-settled row's summary, which is the peer's text, so it is
167
- * only as exact as the legacy data allows.
168
- * @param row - the archived record.
169
- * @returns the archive path that ended it.
170
- */
171
- export function archivedEndedBy(row) {
172
- if (row.endedBy !== undefined)
173
- return row.endedBy;
174
- const summary = row.summary ?? '';
175
- if (summary.startsWith('caller-cancelled'))
176
- return 'cancelled';
177
- if (summary.startsWith('caller-abandoned'))
178
- return 'abandoned';
179
- if (summary === ECHO_SUMMARY)
180
- return 'echo';
181
- return 'receipt';
182
- }
183
- /** Bound on ids and callers kept in settlement records; longer values are cut on write and refused on restore. */
184
- const SETTLEMENT_ID_CAP = 256;
185
- /** Bound of the refusal ring (design §4.4). */
186
- export const SETTLEMENT_REFUSAL_CAP = 64;
187
- const SETTLEMENT_REASONS = ['settler-off-chain', 'settler-unverified', 'on-behalf-mismatch', 'echo-off-chain'];
188
- const CHAIN_ROLES = ['target', 'target-member', 'host-face', 'compat', 'legacy', 'off-chain'];
189
- const PROOF_VALUES = ['origin-claim', 'claim-mismatch', 'legacy-window', 'unbound', 'cli-identity', 'in-process', 'none'];
190
- /** Restore-side allowlist for settledBy: whole or nothing. */
191
- function withSettledBy(raw) {
192
- if (raw === null || typeof raw !== 'object')
193
- return {};
194
- const r = raw;
195
- if (typeof r.caller !== 'string' || r.caller.length > SETTLEMENT_ID_CAP || typeof r.chain_role !== 'string' || !CHAIN_ROLES.includes(r.chain_role))
196
- return {};
197
- return { settledBy: { caller: r.caller, chain_role: r.chain_role } };
198
- }
199
- /** Restore-side allowlist for one refusal record: whole or nothing. */
200
- function parseRefusal(raw) {
201
- if (raw === null || typeof raw !== 'object')
202
- return undefined;
203
- const r = raw;
204
- const st = r.settler;
205
- if (typeof r.taskId !== 'string' || r.taskId === '' || r.taskId.length > SETTLEMENT_ID_CAP || typeof r.at !== 'number' || !Number.isFinite(r.at))
206
- return undefined;
207
- if (typeof r.reason !== 'string' || !SETTLEMENT_REASONS.includes(r.reason) || typeof r.head !== 'string' || typeof r.enforced !== 'boolean')
208
- return undefined;
209
- if (st === null || typeof st !== 'object' || typeof st.caller !== 'string' || st.caller.length > SETTLEMENT_ID_CAP || typeof st.proof !== 'string' || !PROOF_VALUES.includes(st.proof) || (st.ingress !== 'wire' && st.ingress !== 'local'))
210
- return undefined;
211
- const count = r.count === undefined ? 1 : r.count;
212
- if (typeof count !== 'number' || !Number.isInteger(count) || count < 1)
213
- return undefined;
214
- return { taskId: r.taskId, at: r.at, settler: { caller: st.caller, proof: st.proof, ingress: st.ingress }, reason: r.reason, head: r.head.slice(0, SUMMARY_CAP), enforced: r.enforced, count };
215
- }
25
+ import { CALLER_ENDED_PREFIX, TASK_CAP, ARCHIVE_CAP, SUMMARY_CAP, TASK_STALE_TTL_MS, ARCHIVE_ENDS, ECHO_SUMMARY, ROUTING_FACT_CAP, SETTLEMENT_ID_CAP, SETTLEMENT_REFUSAL_CAP, withSender, withAuth, routingOf, birthFacts, withRouting, withSettledBy, parseRefusal, archivedEndedBy } from "./task-ledger-rows.js";
26
+ export * from "./task-ledger-rows.js";
216
27
  /**
217
28
  * Bounded outbound-task ledger with whole-file persistence. Pure of any
218
29
  * routing knowledge: callers {@link track} a task when a route leaves it
package/lib/tools/info.js CHANGED
@@ -124,7 +124,7 @@ export function createInfoTools(deps) {
124
124
  type: 'text',
125
125
  text: value.face === 'host'
126
126
  ? `Host face on team ${String(value.node?.team ?? '?')}: routing rides the bare node team (能发即能收)`
127
- : `Node ${String(value.node?.id ?? '?')}: joined=${String(value.node?.joined)}, live=${String(value.node?.live)}; roster teams: ${(value.teams?.roster ?? []).join(', ') || 'none'}; canvas: ${(value.teams?.canvas ?? []).join(', ') || 'none'}; allowlist effect: ${String(value.allowlist?.effect ?? '?')}`,
127
+ : `Node ${String(value.node?.name ?? '')} ${String(value.node?.id ?? '?')}: joined=${String(value.node?.joined)}, live=${String(value.node?.live)}; roster teams: ${(value.teams?.roster ?? []).join(', ') || 'none'}; canvas: ${(value.teams?.canvas ?? []).join(', ') || 'none'}; allowlist effect: ${String(value.allowlist?.effect ?? '?')}`,
128
128
  }],
129
129
  },
130
130
  presentCall: () => ({ card: 'generic', title: 'A2A whoami', kind: 'other', rawInput: null }),
@@ -151,6 +151,7 @@ export function createInfoTools(deps) {
151
151
  face: 'session',
152
152
  node: {
153
153
  id: agentId,
154
+ ...(exec.agent !== undefined ? { name: nodeMetadataOf(exec.agent).name, ...(nodeMetadataOf(exec.agent).seatName !== undefined ? { seatName: nodeMetadataOf(exec.agent).seatName } : {}) } : {}),
154
155
  ...(joined ? { team: `${config.team}/${id8(agentId)}` } : {}),
155
156
  joined,
156
157
  live,
@@ -209,6 +210,7 @@ export function createInfoTools(deps) {
209
210
  team: { type: 'string', required: true },
210
211
  session: { type: 'string', required: true },
211
212
  name: { type: 'string', required: true },
213
+ seatName: { type: 'string', description: 'Human-owned stable display label, never a route identity.' },
212
214
  description: { type: 'string', required: true },
213
215
  local: { type: 'boolean', description: 'true when the team is served by this host (loopback candidate).' },
214
216
  origin: { type: 'string', description: 'The publishing host (node session label, LAN IP when known) — the natural grouping for fleet rows.' },
@@ -45,6 +45,7 @@ export interface A2aClientOptions {
45
45
  readonly originClaim?: (target: {
46
46
  readonly url: string;
47
47
  readonly method: string;
48
+ readonly body?: string;
48
49
  }) => Record<string, string>;
49
50
  /** Delayed-callback seam (HTTP timeouts). */
50
51
  readonly schedule: A2aSchedule;
@@ -141,6 +141,7 @@ export interface AdminFaceDeps extends Pick<CanvasNotifyDeps, 'verifyOriginClaim
141
141
  readonly unboundInboundCount: number;
142
142
  readonly boundMissInboundCount: number;
143
143
  readonly ownCardUrl: string;
144
+ ownerSeatNames: Record<string, string>;
144
145
  ownerAllowlist: string[];
145
146
  ownerTeamScopeInfo: boolean;
146
147
  ownerAnnounceRestartPending: boolean;
@@ -44,7 +44,9 @@ export interface CanvasNotifyDeps {
44
44
  readonly canvasStore: CanvasStore;
45
45
  readonly cardCache: Map<string, CardCacheEntry>;
46
46
  readonly originClaimHeaders: (target: OriginClaimTarget) => Record<string, string>;
47
- readonly verifyOriginClaim: (req: IncomingMessage) => Promise<{
47
+ readonly verifyOriginClaim: (req: IncomingMessage, options?: {
48
+ readonly rawBody?: Uint8Array;
49
+ }) => Promise<{
48
50
  ok: true;
49
51
  caller: string;
50
52
  callerUrl: string;
@@ -128,6 +128,7 @@ export interface WireDeps {
128
128
  readonly idempotencyStore: IdempotencyStore;
129
129
  readonly verifyOriginClaim: (req: IncomingMessage, options?: {
130
130
  readonly cli?: boolean;
131
+ readonly rawBody?: Uint8Array;
131
132
  }) => Promise<OriginClaimResult>;
132
133
  readonly forwardDirect: (request: ForwardRequest) => Promise<A2aRouteResult>;
133
134
  readonly remoteCliProof: (handle: string, claim: Extract<OriginClaimResult, {
@@ -228,6 +228,8 @@ export interface Config {
228
228
  * nobody created. Empty list denies every join (default).
229
229
  */
230
230
  readonly teamJoinAllowlist: string[];
231
+ /** Human-owned stable display labels keyed by full local session id; never a routing identity. */
232
+ readonly seatNames: Record<string, unknown>;
231
233
  /**
232
234
  * S3 (phase-2 default-ON, owner ruling 2026-09-01): route dispatch checks
233
235
  * caller↔target shared team membership before addressing; set false to
@@ -4,7 +4,7 @@
4
4
  * face (card, /a2a/direct, /a2a/log, /a2a/canvas-op, /a2a/canvas-changed)
5
5
  * runs.
6
6
  *
7
- * Two canonical forms ride the same four base headers
7
+ * Three canonical forms share the base caller headers
8
8
  * (X-A2A-Caller / -Url / -Ts):
9
9
  * · bound (v2, §2.1): JSON.stringify([tag, caller, callerUrl, ts,
10
10
  * audience, METHOD, path]) in X-A2A-Caller-Sig2, the audience origin in
@@ -14,7 +14,8 @@
14
14
  * · unbound (v1, legacy): JSON.stringify([caller, callerUrl, ts]) in
15
15
  * X-A2A-Caller-Sig. Emitted and accepted only while the unbound window
16
16
  * is open (originClaimUnboundWindow); accepted ones are counted.
17
- * Once the window closes a present Sig2 is the only thing verified. While
17
+ * A present Sig3 requires the exact raw body and v3 signature, with no downgrade.
18
+ * Without Sig3, once the window closes a present Sig2 is the only thing verified. While
18
19
  * it is open, a Sig2 that misses (audience or signature) falls back to the
19
20
  * Sig the envelope also carries — no more than stripping Sig2 would give —
20
21
  * and the miss is counted, so a peer dialled by an unlisted name keeps
@@ -29,12 +30,16 @@ import type { A2aPeerCard } from './types.ts';
29
30
  export declare const ORIGIN_CLAIM_SKEW_MS: number;
30
31
  /** Domain tag of the bound form: a v1 signature can never verify as v2. */
31
32
  export declare const ORIGIN_CLAIM_BOUND_TAG = "a2a-origin-claim/2";
33
+ export declare const ORIGIN_CLAIM_BODY_TAG = "a2a-origin-claim/3";
34
+ /** Digest the exact UTF-8 string/bytes passed to transport, never reserialized JSON. */
35
+ export declare const originBodySha256: (body: string | Uint8Array) => string;
32
36
  /** Where an outbound request goes: the bound form signs both. */
33
37
  export interface OriginClaimTarget {
34
38
  readonly url: string;
35
39
  readonly method: string;
40
+ readonly body?: string | Uint8Array;
36
41
  }
37
- export type OriginClaimRefusal = 'absent' | 'bad-caller-shape' | 'bad-ts' | 'no-card' | 'bad-sig' | 'not-derivable' | 'wrong-audience' | 'unbound-closed';
42
+ export type OriginClaimRefusal = 'absent' | 'bad-caller-shape' | 'bad-ts' | 'no-card' | 'bad-sig' | 'not-derivable' | 'wrong-audience' | 'unbound-closed' | 'body-mismatch';
38
43
  /** Only the canonical origin root can claim that origin's identity. */
39
44
  export declare function isRootOriginUrl(value: string): boolean;
40
45
  /**
@@ -59,6 +64,8 @@ export type OriginClaimVerdict = {
59
64
  export declare function unboundCanonical(caller: string, callerUrl: string, ts: number): string;
60
65
  /** The bound (v2) canonical form; method upper-cased, path without query. */
61
66
  export declare function boundCanonical(caller: string, callerUrl: string, ts: number, audience: string, method: string, path: string): string;
67
+ /** The body-bound v3 form is domain-separated from v1/v2, with the digest appended. */
68
+ export declare function bodyBoundCanonical(caller: string, callerUrl: string, ts: number, audience: string, method: string, path: string, bodySha256: string): string;
62
69
  /** An origin in URL's normal form, or '' when the text is not an http(s) URL. */
63
70
  export declare function originOf(url: string): string;
64
71
  /** The path a request names, without its query (the bound form signs this). */
@@ -114,6 +121,8 @@ export declare function verifyOriginClaim(req: IncomingMessage, d: {
114
121
  /** A loopback arrival is an audience of its own (default); off when originClaimUrl declares a tunnel or proxy. */
115
122
  readonly loopbackArrival?: boolean;
116
123
  readonly now: number;
124
+ /** Exact received bytes, supplied by the bounded body reader. Missing bytes cannot verify Sig3. */
125
+ readonly rawBody?: Uint8Array;
117
126
  /** On the faces that admit CLI identities: the deposit a claim URL names. */
118
127
  readonly cliDeposit?: (callerUrl: string) => CliDepositCard | undefined;
119
128
  }): Promise<OriginClaimVerdict>;
@@ -12,7 +12,12 @@ export interface OwnerSettings {
12
12
  teamJoinAllowlist?: string[];
13
13
  teamScopeInfo?: boolean;
14
14
  announce?: boolean;
15
+ seatNames?: Record<string, string>;
15
16
  }
17
+ /** Shared validation for boot config and owner POST; labels are plain text, never handles or authority. */
18
+ export declare function parseSeatNames(value: unknown): Record<string, string> | undefined;
19
+ /** Boot config degrades entry-by-entry; owner POST remains all-or-nothing. Never echo label contents in warnings. */
20
+ export declare function loadSeatNames(value: unknown, warn: (reason: string) => void): Record<string, string>;
16
21
  export declare function applyOwnerSettings(patchYaml: string, changes: OwnerSettings): {
17
22
  yaml: string;
18
23
  restartNeeded: boolean;