@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
@@ -70,6 +70,10 @@ export interface AdminFaceDeps extends Pick<CanvasNotifyDeps, 'verifyOriginClaim
70
70
  }>;
71
71
  readonly layoutStore: LayoutStore;
72
72
  readonly taskLedger: TaskLedger;
73
+ readonly enforceRefused?: {
74
+ reason: string;
75
+ blockers: readonly string[];
76
+ };
73
77
  /** #114 S6: observe (lazily) and return the /state `authorization` block. */
74
78
  readonly authorizationView: () => unknown;
75
79
  readonly idempotencyStore: IdempotencyStore;
@@ -140,7 +144,14 @@ export interface AdminFaceDeps extends Pick<CanvasNotifyDeps, 'verifyOriginClaim
140
144
  readonly legacyInboundCount: number;
141
145
  readonly unboundInboundCount: number;
142
146
  readonly boundMissInboundCount: number;
147
+ readonly boundMissRecent: ReadonlyArray<{
148
+ caller: string;
149
+ audience: string;
150
+ count: number;
151
+ lastAt: number;
152
+ }>;
143
153
  readonly ownCardUrl: string;
154
+ ownerSeatNames: Record<string, string>;
144
155
  ownerAllowlist: string[];
145
156
  ownerTeamScopeInfo: boolean;
146
157
  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,8 +128,10 @@ 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>;
134
+ readonly diagnoseCanvas: (team: string, reason: string, caller?: string) => Promise<string>;
133
135
  readonly remoteCliProof: (handle: string, claim: Extract<OriginClaimResult, {
134
136
  ok: true;
135
137
  }>) => Promise<RemoteCliProof | undefined>;
@@ -168,6 +170,7 @@ export interface WireDeps {
168
170
  /** gh#224: refuses a new delivery once the target already owes `targetQueueCap` receipts. */
169
171
  readonly refuseIfQueueFull: (caller: string, message: string, team: string, taskId: string, mailbox: boolean, res: ServerResponse) => boolean;
170
172
  /** Settles a receipt; returns the enforce refusal of the row its header names (#139), if any. */
173
+ readonly waitForForwardBirth: (message: string) => Promise<void>;
171
174
  readonly settleAndAnnounce: (message: string, settler?: Settler) => SettlementRefusal | undefined;
172
175
  readonly touchWakeDemand: () => void;
173
176
  readonly session: string;
@@ -198,7 +201,7 @@ export interface WireDeps {
198
201
  readonly nativeTeamsRound: (prepared: Extract<NativePrepared, {
199
202
  ok: true;
200
203
  }>, team: string, caller: string, message: string, taskId: string | undefined, proofClause: string, external?: AbortSignal, proofHeader?: (team: string, taskId: string, from: string, proofClause: string) => string) => Promise<NativeRoundOutcome>;
201
- readonly routeIntoAgent: (team: string, message: string, caller: string, taskId?: string, proofClause?: string, directHeader?: (from: string) => string) => Promise<RouteOutcome>;
204
+ readonly routeIntoAgent: (team: string, message: string, caller: string, taskId?: string, proofClause?: string, directHeader?: (from: string) => string, localFrom?: string, onSteered?: (target: Agent, floor: number) => void) => Promise<RouteOutcome>;
202
205
  }
203
206
  /**
204
207
  * #187: what a verified claim may vouch for at settlement. The signing key always (the card was
@@ -91,7 +91,7 @@ export interface Config {
91
91
  * (which is left untouched). Inbound faces keep answering. Default false.
92
92
  */
93
93
  readonly isolated: boolean;
94
- /** Forward online local CLI deliveries one hop after a local miss. Default off. */
94
+ /** Forward online local CLI deliveries one hop after a local miss. Default on from 0.6.38; explicit false opts out. */
95
95
  readonly forwardDirect: boolean;
96
96
  /** Human-facing name published on the agent card. */
97
97
  readonly agentName: string;
@@ -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). */
@@ -110,10 +117,15 @@ export declare function verifyOriginClaim(req: IncomingMessage, d: {
110
117
  /** Count one accepted unbound envelope (the drain gauge). */
111
118
  readonly onUnbound: () => void;
112
119
  /** Count one bound form that missed and fell back to the unbound one. */
113
- readonly onBoundMiss?: () => void;
120
+ readonly onBoundMiss?: (miss: {
121
+ readonly caller: string;
122
+ readonly audience: string;
123
+ }) => void;
114
124
  /** A loopback arrival is an audience of its own (default); off when originClaimUrl declares a tunnel or proxy. */
115
125
  readonly loopbackArrival?: boolean;
116
126
  readonly now: number;
127
+ /** Exact received bytes, supplied by the bounded body reader. Missing bytes cannot verify Sig3. */
128
+ readonly rawBody?: Uint8Array;
117
129
  /** On the faces that admit CLI identities: the deposit a claim URL names. */
118
130
  readonly cliDeposit?: (callerUrl: string) => CliDepositCard | undefined;
119
131
  }): 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;
@@ -0,0 +1,13 @@
1
+ /** Host-specific badge projection only. Never use this to admit callers or choose CLI homes. */
2
+ import type { A2aPeerCard } from './types.ts';
3
+ export declare function peerLinkDisplay(peerUrl: string, d: {
4
+ readonly card: A2aPeerCard | undefined;
5
+ readonly ownUrl: string;
6
+ readonly seeds: readonly string[];
7
+ readonly refs: readonly string[];
8
+ readonly ownHandles: ReadonlySet<string>;
9
+ readonly cards: readonly A2aPeerCard[];
10
+ }): {
11
+ link: 'linked' | 'stranger';
12
+ verified: boolean;
13
+ };
@@ -232,6 +232,8 @@ export interface SettlementRow {
232
232
  readonly peerHost?: string;
233
233
  /** #139: the member that actually received the task (canvas and bare-zone deliveries). */
234
234
  readonly deliveredTo?: string;
235
+ readonly forwarded?: true;
236
+ readonly receiverMembers?: readonly string[];
235
237
  }
236
238
  /** Facts from outside the row. */
237
239
  export interface SettlementFacts {
@@ -0,0 +1,352 @@
1
+ /** Stateless ledger row types, classifiers and restore projections; moved verbatim for #258. */
2
+ import { type AuthProof, type ChainRole, type SettlementReason, type SettlementVerdict, type TaskAuthorization } from './task-auth.ts';
3
+ import type { ReceiptOutcomeV2 } from './receipt.ts';
4
+ import type { ConservationSnapshot } from './ledger-conservation.ts';
5
+ /**
6
+ * Caller-ended summaries (abandon / cancel) share one isolation law: late
7
+ * receipts never rewrite the verdict — they only stamp lateReceiptAt, and
8
+ * the projected outcome collapses to 'abandoned'.
9
+ */
10
+ export declare const CALLER_ENDED_PREFIX: RegExp;
11
+ /** Hard cap on the owed book (pending + dead-lettered rows, most recent first). */
12
+ export declare const TASK_CAP = 64;
13
+ /** Hard cap on the settled archive (most recent kept). */
14
+ export declare const ARCHIVE_CAP = 64;
15
+ /** Longest receipt summary kept on a record (multi-line outcomes collapse). */
16
+ export declare const SUMMARY_CAP = 200;
17
+ /**
18
+ * Longest dispatch brief kept per row. A ledger row without its payload is
19
+ * unreadable to supervision — "direct-8f3a1c2b → dsh/ec4ce7f8, 3h old" says
20
+ * nothing about whether to nudge, abandon, or read the receipt. The brief is
21
+ * the first non-empty line of the message, capped; the full body never enters
22
+ * the ledger (it can be arbitrarily large and may quote another session's log).
23
+ */
24
+ export declare const BRIEF_CAP = 120;
25
+ /** Reduce a dispatch body to one readable line: first non-empty line, collapsed, capped. */
26
+ export declare function briefOf(message: string | undefined): string | undefined;
27
+ /**
28
+ * Age at which an unsettled task auto-dead-letters. A dead row exits the
29
+ * owed view, disarms its async-nudge retry (a cold session cannot consume a
30
+ * re-steer anyway), and still accepts a late receipt from a revived target.
31
+ * Injectable per instance so tests can use short windows; sweeping stays
32
+ * lazy — every read/write entry point sweeps first.
33
+ */
34
+ export declare const TASK_STALE_TTL_MS: number;
35
+ /**
36
+ * The receipt correlation template now lives in `receipt.ts` (shared codec
37
+ * for header + v2 envelope line). This ledger consumes `parseReceipt` so
38
+ * human summaries and machine projections can never drift apart again.
39
+ */
40
+ /** Lifecycle of a tracked outbound task inside the owed book. */
41
+ export type TaskStatus = 'pending' | 'dead';
42
+ /** F5 layer-3: why a dead row aged out (stamped by the sweep at flip time). */
43
+ export type DeadReason = 'fire-forget' | 'unconsumed';
44
+ /** gh#31: which archive path ended a row — a receipt, a content echo, or the caller. */
45
+ export type ArchiveEnd = 'receipt' | 'echo' | 'abandoned' | 'cancelled' | 'evicted';
46
+ export declare const ARCHIVE_ENDS: readonly string[];
47
+ /** Summary marker {@link TaskLedger.resolveEcho} writes on echo-settled rows. */
48
+ export declare const ECHO_SUMMARY = "(settled by content echo)";
49
+ /**
50
+ * #114 S3: who really sent one outbound task — the routing session, the
51
+ * agent-less host face, or a native-teams bridge submitter. Before this
52
+ * field every outbound row was attributable only to the host ("home"), so
53
+ * same-host seats could not be told apart.
54
+ */
55
+ export interface Sender {
56
+ readonly kind: 'session' | 'host' | 'bridge' | 'cli';
57
+ /**
58
+ * A session's `<zone>/<id8>` node team, the host process label, or the
59
+ * bridge submitter. Group senders by `kind:id`, never by `id` alone: a host
60
+ * label set by hand may look like a session handle.
61
+ */
62
+ readonly id: string;
63
+ /**
64
+ * Host senders only: the label the call borrowed on the wire when it
65
+ * differs from {@link id} (quick dispatch rides a live joined session's
66
+ * team). Display context, never a bucket key.
67
+ */
68
+ readonly face?: string;
69
+ }
70
+ /** Longest sender id kept; anything longer is malformed, not truncated. */
71
+ export declare const SENDER_ID_CAP = 256;
72
+ /**
73
+ * Restore-side allowlist for one persisted sender: a well-formed value comes
74
+ * back as a fresh object holding only kind, id and (when present) face; anything else is dropped whole (the row
75
+ * itself survives — a bad sender never costs the debt record).
76
+ * @param raw - the persisted value.
77
+ * @returns the sender, or undefined when absent or malformed.
78
+ */
79
+ export declare function parseSender(raw: unknown): Sender | undefined;
80
+ /**
81
+ * Spread helper for restore: `{ sender }` when the persisted value parses and
82
+ * the row is not inbound (an inbound row's originator is its caller, never a
83
+ * sender this host recorded), else nothing.
84
+ */
85
+ export declare function withSender(raw: unknown, direction: unknown): {
86
+ sender?: Sender;
87
+ };
88
+ /**
89
+ * #114 S2: `{ auth }` when a persisted INBOUND row carries a record that
90
+ * parses whole (parseAuthorization) and belongs to THIS row — its target is
91
+ * the row's team and its receipt target the row's peer — else nothing: the
92
+ * row survives as a pre-S2 row, never with a partially adopted or borrowed
93
+ * record.
94
+ */
95
+ export declare function withAuth(raw: unknown, entry: {
96
+ direction?: unknown;
97
+ team?: unknown;
98
+ peer?: unknown;
99
+ forwarded?: unknown;
100
+ sender?: unknown;
101
+ }, now: number): {
102
+ auth?: TaskAuthorization;
103
+ };
104
+ /** Routing and answer facts copied unchanged between a row and its archive entry. */
105
+ export declare function routingOf(row: Pick<TaskRecord, 'peerKey' | 'peerHost' | 'deliveredTo' | 'forwarded' | 'answeredAt' | 'receiverMembers'>): Pick<TaskRecord, 'peerKey' | 'peerHost' | 'deliveredTo' | 'forwarded' | 'answeredAt' | 'receiverMembers'>;
106
+ /** #139: what an outbound row is born with besides its sender. */
107
+ export interface OutboundBirth {
108
+ readonly forwarded?: true;
109
+ /** Local-candidate admission, or a forwarded online CLI's verified wire admission. */
110
+ readonly auth?: TaskAuthorization;
111
+ readonly peerKey?: string;
112
+ readonly peerHost?: string;
113
+ readonly deliveredTo?: string;
114
+ /** Verified selected peer canvas membership at dispatch; actual deliveredTo remains stricter when available. */
115
+ readonly receiverMembers?: readonly string[];
116
+ }
117
+ /** The facts of one outbound birth that fit the row (see {@link withRouting} for the same shape on restore). */
118
+ export declare function birthFacts(peer: string, birth: OutboundBirth | undefined, team?: string, sender?: Sender, now?: number, warn?: (message: string) => void): Pick<TaskRecord, 'auth' | 'peerKey' | 'peerHost' | 'deliveredTo' | 'forwarded' | 'receiverMembers'>;
119
+ /** Bound on a persisted routing fact; anything longer (or empty, or not a string) is dropped on restore. */
120
+ export declare const ROUTING_FACT_CAP = 256;
121
+ export declare function parseReceiverMembers(value: unknown, warn?: (message: string) => void): readonly string[] | undefined;
122
+ /**
123
+ * #139: restore-side allowlist for the routing facts. Each is kept only in
124
+ * its shape — a non-empty string within the cap — and the peer facts only on
125
+ * a remote outbound row; anything else is dropped (the row survives as one
126
+ * born before the fields, judged by current membership and origin).
127
+ */
128
+ export declare function withRouting(entry: Record<string, unknown>, warn?: (message: string) => void): Pick<TaskRecord, 'peerKey' | 'peerHost' | 'deliveredTo' | 'forwarded' | 'answeredAt' | 'receiverMembers'>;
129
+ /** One tracked outbound task still in the owed book (unsettled). */
130
+ export interface TaskRecord {
131
+ readonly taskId: string;
132
+ readonly team: string;
133
+ readonly peer: string;
134
+ readonly startedAt: number;
135
+ /**
136
+ * Which side of the wire this row serves: 'outbound' (this node sent and
137
+ * awaits a receipt) or 'inbound' (this node received and owes one).
138
+ * Absent on rows persisted before F2' — those are outbound by birth.
139
+ */
140
+ readonly direction?: 'inbound' | 'outbound';
141
+ /**
142
+ * F5: whether a receipt is actually owed. Absent ⇒ true (back-compat).
143
+ * `false` marks fire-and-forget deliveries — the caller's label could not
144
+ * receive a receipt at dispatch (process-form label), so no debt was born
145
+ * and supervision must not chase this row.
146
+ */
147
+ readonly receiptExpected?: boolean;
148
+ /** The conversation the delivery steered, for follow-up routes. */
149
+ readonly contextId?: string;
150
+ /**
151
+ * Head of the dispatched message (first non-empty line, {@link BRIEF_CAP}).
152
+ * What the row is ABOUT — the fact that makes the ledger readable without
153
+ * replaying the conversation. Absent on rows persisted before this field.
154
+ */
155
+ readonly brief?: string;
156
+ /** #114 S3: the real sender of an outbound row (absent on inbound rows and rows persisted before the field). */
157
+ readonly sender?: Sender;
158
+ /** Home host forwarded an online CLI request to a peer. */
159
+ readonly forwarded?: true;
160
+ /**
161
+ * #114 S2: the immutable authorization the row was born with — an inbound
162
+ * row's wire admission, or (#139) an outbound row's local-candidate
163
+ * admission (`ingress: 'local'`). Absent on remote outbound and older rows.
164
+ */
165
+ readonly auth?: TaskAuthorization;
166
+ /** #139: the public key of the peer card a remote outbound row was dispatched to. */
167
+ readonly peerKey?: string;
168
+ /** #139: that card's session label (the peer host's process label). */
169
+ readonly peerHost?: string;
170
+ /** #139: the member that actually received the task (canvas / bare-zone deliveries). */
171
+ readonly deliveredTo?: string;
172
+ /** Verified selected peer canvas membership at dispatch; actual deliveredTo remains stricter when available. */
173
+ readonly receiverMembers?: readonly string[];
174
+ /** Local target has produced an answer; still owed until receipt delivery/settlement, but no longer queued. */
175
+ answeredAt?: number;
176
+ status: TaskStatus;
177
+ /** When the row was swept to dead-letter (absent while pending). */
178
+ deadAt?: number;
179
+ /**
180
+ * F5 layer-3: why the row aged out. 'fire-forget' — a receiptExpected:false
181
+ * row expiring is expected bookkeeping, not a failure; 'unconsumed' — a
182
+ * receipt-owed row never settled, the actionable stale shape. Absent on
183
+ * dead rows persisted before this field (rendered as 'unspecified').
184
+ */
185
+ reason?: DeadReason;
186
+ }
187
+ /** One settled task kept for audit, with its receipt-correlated outcome. */
188
+ export interface ArchivedRecord {
189
+ readonly taskId: string;
190
+ readonly team: string;
191
+ readonly peer: string;
192
+ readonly startedAt: number;
193
+ readonly contextId?: string;
194
+ readonly resolvedAt: number;
195
+ readonly summary?: string;
196
+ /** Head of the dispatched message that this row settled (see {@link TaskRecord.brief}). */
197
+ readonly brief?: string;
198
+ /** Controlled vocabulary verdict when the settling receipt carried a v2 envelope; forced 'abandoned' for caller-abandoned rows. */
199
+ readonly outcome?: ReceiptOutcomeV2 | 'abandoned';
200
+ /** Remote-turn wall-clock cost, when the settling envelope carried it. */
201
+ readonly elapsedMs?: number;
202
+ /**
203
+ * When a receipt arrived for an explicitly abandoned row ({@link TaskLedger.abandon}).
204
+ * Orphan isolation: the abandonment outcome stays verbatim; the late answer is
205
+ * recorded as metadata only, never promoted to resolution.
206
+ */
207
+ readonly lateReceiptAt?: number;
208
+ /**
209
+ * gh#31: which archive path ended the row, recorded at archive time. Absent
210
+ * on rows archived before the field — {@link archivedEndedBy} derives it.
211
+ */
212
+ readonly endedBy?: ArchiveEnd;
213
+ /** gh#31: which side of the wire the row served, copied from the owed row (absent on rows archived before the field). */
214
+ readonly direction?: 'inbound' | 'outbound';
215
+ /**
216
+ * gh#68: copied from the owed row when it awaited no receipt, so a tidied
217
+ * fire-forget expiry is not read as a send we gave up on. Only `false` is
218
+ * ever stored; absent means a receipt was owed (or the row predates the field).
219
+ */
220
+ readonly receiptExpected?: false;
221
+ /** #114 S3: copied from the owed row (absent on inbound rows and rows archived before the field). */
222
+ readonly sender?: Sender;
223
+ /** Home host forwarded an online CLI request to a peer. */
224
+ readonly forwarded?: true;
225
+ /** #114 S2: carried over from the live row unchanged. */
226
+ readonly auth?: TaskAuthorization;
227
+ /** #139: carried over from the live row unchanged (a late receipt is judged against them). */
228
+ readonly peerKey?: string;
229
+ readonly peerHost?: string;
230
+ readonly deliveredTo?: string;
231
+ /** Verified selected peer canvas membership at dispatch; actual deliveredTo remains stricter when available. */
232
+ readonly receiverMembers?: readonly string[];
233
+ /** Local answer time retained as audit metadata, independent of resolution time. */
234
+ readonly answeredAt?: number;
235
+ /** #114 S4: who settled the row (receipt and echo ends), and their chain role. */
236
+ readonly settledBy?: SettledBy;
237
+ }
238
+ /**
239
+ * How one archived row ended (gh#31). The recorded field wins; legacy rows
240
+ * fall back to the summary markers this ledger writes itself. The fallback
241
+ * reads a receipt-settled row's summary, which is the peer's text, so it is
242
+ * only as exact as the legacy data allows.
243
+ * @param row - the archived record.
244
+ * @returns the archive path that ended it.
245
+ */
246
+ export declare function archivedEndedBy(row: ArchivedRecord): ArchiveEnd;
247
+ /** Result of an explicit caller-side abandon. Total and never-thrown. */
248
+ export type AbandonOutcome = 'cleared' | 'already-terminal' | 'unknown';
249
+ /** Structured verdict for one {@link TaskLedger.abandon} call (consumer contract: idempotent). */
250
+ export interface AbandonResult {
251
+ readonly outcome: AbandonOutcome;
252
+ readonly taskId: string;
253
+ /** Settle time: fresh abandonment's clock tick, or the already-settled row's original resolvedAt. */
254
+ readonly archivedAt?: number;
255
+ }
256
+ /** Result of a cooperative {@link TaskLedger.cancel}; adds routing facts for the notify half. */
257
+ export interface CancelledResult extends AbandonResult {
258
+ /** Team the ended row addressed — the route layer reaches a live local target through it. */
259
+ readonly team?: string;
260
+ readonly contextId?: string;
261
+ }
262
+ /** Per-instance knobs; defaults come from the exported constants. */
263
+ export interface TaskLedgerOptions {
264
+ /** Invalid persisted member entries are dropped individually and reported without their content. */
265
+ warn?: (message: string) => void;
266
+ /** Stale-TTL override (tests inject short windows); defaults to {@link TASK_STALE_TTL_MS}. */
267
+ staleTtlMs?: number;
268
+ /** Archive capacity override; defaults to {@link ARCHIVE_CAP}. */
269
+ archiveCap?: number;
270
+ /**
271
+ * Clock injection for tests: every sweep/TTL decision reads the time from
272
+ * here. Defaults to Date.now. Injecting a steppable clock makes the stale
273
+ * transition deterministic - no real sleeps to race under load.
274
+ */
275
+ now?: () => number;
276
+ }
277
+ /**
278
+ * What one correlated receipt settled — the payload of the
279
+ * `a2a/receipt-resolved` event, emitted for consumers that react to receipt
280
+ * arrivals (P2: native-teams settles its outstanding async submissions from
281
+ * this seam). `outcome` carries the v2 envelope's controlled-vocabulary
282
+ * verdict when the receipt rode one; `late` marks a receipt answering a
283
+ * dead-lettered row (revival) or an abandoned row (arrival recorded) — a
284
+ * healthy row's duplicate receipt refreshes the archive with NO marker.
285
+ */
286
+ export interface ReceiptResolvedInfo {
287
+ readonly taskId: string;
288
+ /** The team the task was routed to (as the dispatcher recorded it). */
289
+ readonly team: string;
290
+ /** The peer (or `'local'`) the task was dispatched through. */
291
+ readonly peer: string;
292
+ /** v2 envelope outcome, when the receipt rode one. */
293
+ readonly outcome?: string;
294
+ /** One-line outcome summary, when the receipt carried one. */
295
+ readonly summary?: string;
296
+ /** True when the receipt answered a dead-lettered or abandoned row. */
297
+ readonly late?: boolean;
298
+ }
299
+ /** The persisted ledger document: the owed book plus its settled archive. */
300
+ export interface TaskLedgerSnapshot {
301
+ readonly tasks: readonly TaskRecord[];
302
+ readonly archived?: readonly ArchivedRecord[];
303
+ /** #114 S4: the bounded ring of refused / would-be-refused settlements. */
304
+ readonly settlementRefusals?: readonly SettlementRefusalRecord[];
305
+ /** #114 S4: monotonic count of every refusal noted. */
306
+ readonly settlementRefusalsTotal?: number;
307
+ /** gh#154: lifetime conservation counters (persisted; absent = pre-#154 legacy) — the module contract, shared by classifier, counters, and this schema (review P3). */
308
+ readonly conservation?: ConservationSnapshot;
309
+ }
310
+ /** #114 S4: who settled an archived row, and how they stood on its authorization chain. */
311
+ export interface SettledBy {
312
+ readonly caller: string;
313
+ readonly chain_role: ChainRole | 'off-chain';
314
+ }
315
+ /** #114 S4: one settlement the judgement refused (enforce) or would have refused (observe). */
316
+ export interface SettlementRefusalRecord {
317
+ readonly taskId: string;
318
+ readonly at: number;
319
+ readonly settler: {
320
+ readonly caller: string;
321
+ readonly proof: AuthProof;
322
+ readonly ingress: 'wire' | 'local';
323
+ };
324
+ readonly reason: SettlementReason;
325
+ /** The receipt's first line, bounded. */
326
+ readonly head: string;
327
+ /** true: the settlement was refused (enforce); false: recorded only (observe). */
328
+ readonly enforced: boolean;
329
+ /** 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). */
330
+ readonly count: number;
331
+ }
332
+ /** Bound on ids and callers kept in settlement records; longer values are cut on write and refused on restore. */
333
+ export declare const SETTLEMENT_ID_CAP = 256;
334
+ /** Bound of the refusal ring (design §4.4). */
335
+ export declare const SETTLEMENT_REFUSAL_CAP = 64;
336
+ /**
337
+ * #114 S4: how the ledger asks whether a settler may settle a row. `check`
338
+ * is the pure judgement (task-auth.ts judgeSettlement) bound to this
339
+ * receipt's facts; `enforce` decides whether an off-chain verdict blocks
340
+ * the settlement or is only recorded.
341
+ */
342
+ export interface SettlementJudge {
343
+ readonly enforce: boolean;
344
+ readonly settler: SettlementRefusalRecord['settler'];
345
+ check(row: Pick<TaskRecord, 'team' | 'peer' | 'direction' | 'auth' | 'peerKey' | 'peerHost' | 'deliveredTo' | 'forwarded' | 'receiverMembers'>, echo: boolean): SettlementVerdict;
346
+ }
347
+ /** Restore-side allowlist for settledBy: whole or nothing. */
348
+ export declare function withSettledBy(raw: unknown): {
349
+ settledBy?: SettledBy;
350
+ };
351
+ /** Restore-side allowlist for one refusal record: whole or nothing. */
352
+ export declare function parseRefusal(raw: unknown): SettlementRefusalRecord | undefined;