dsh-kingdom 2.0.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/ASSETS_NOTICE.md +22 -22
  2. package/README.md +246 -243
  3. package/THIRD_PARTY_NOTICES.md +92 -92
  4. package/docs/DSH-KINGDOM-3.0-ANNOUNCEMENT.md +13 -0
  5. package/docs/V2.0-RELEASE-NOTES.md +30 -30
  6. package/docs/V2.0-USER-GUIDE.md +74 -74
  7. package/docs/V3.0-RELEASE-NOTES.md +21 -0
  8. package/docs/V3.0-USER-GUIDE.md +33 -0
  9. package/docs/V3.1-RELEASE-NOTES.md +76 -0
  10. package/docs/V3.2-RELEASE-NOTES.md +103 -0
  11. package/lib/core/binding.js +167 -60
  12. package/lib/core/binding.js.map +1 -1
  13. package/lib/core/db.js +582 -546
  14. package/lib/core/db.js.map +1 -1
  15. package/lib/core/delivery-ack.js +1356 -0
  16. package/lib/core/delivery-ack.js.map +1 -0
  17. package/lib/core/delivery-change.js +1237 -0
  18. package/lib/core/delivery-change.js.map +1 -0
  19. package/lib/core/owner-binding-intent.js +14 -25
  20. package/lib/core/owner-binding-intent.js.map +1 -1
  21. package/lib/core/owner-window.js +698 -23
  22. package/lib/core/owner-window.js.map +1 -1
  23. package/lib/core/task-service.js +144 -5
  24. package/lib/core/task-service.js.map +1 -1
  25. package/lib/core/territory.js +43 -9
  26. package/lib/core/territory.js.map +1 -1
  27. package/lib/gui/assets/characters/chancellor-idle.svg +67 -67
  28. package/lib/gui/assets/characters/chancellor-sleeping.svg +67 -67
  29. package/lib/gui/assets/characters/chancellor-thinking.svg +67 -67
  30. package/lib/gui/assets/characters/chancellor-working.svg +67 -67
  31. package/lib/gui/assets/characters/knight-redraw-r1-idle.svg +67 -67
  32. package/lib/gui/assets/characters/knight-redraw-r1-sleeping.svg +67 -67
  33. package/lib/gui/assets/characters/knight-redraw-r1-thinking.svg +67 -67
  34. package/lib/gui/assets/characters/knight-redraw-r1-working.svg +67 -67
  35. package/lib/gui/assets/characters/supervisor-idle.svg +67 -67
  36. package/lib/gui/assets/characters/supervisor-sleeping.svg +67 -67
  37. package/lib/gui/assets/characters/supervisor-thinking.svg +67 -67
  38. package/lib/gui/assets/characters/supervisor-working.svg +67 -67
  39. package/lib/gui/console-app.js +7 -1
  40. package/lib/gui/console-app.js.map +1 -1
  41. package/lib/gui/contract.js +6 -0
  42. package/lib/gui/contract.js.map +1 -1
  43. package/lib/gui/control-contract.js +3 -2
  44. package/lib/gui/control-contract.js.map +1 -1
  45. package/lib/gui/owner-control.js +114 -4
  46. package/lib/gui/owner-control.js.map +1 -1
  47. package/lib/gui/owner-ui.js +645 -183
  48. package/lib/gui/owner-ui.js.map +1 -1
  49. package/lib/gui/server.js +109 -109
  50. package/lib/gui/snapshot.js +127 -4
  51. package/lib/gui/snapshot.js.map +1 -1
  52. package/lib/gui/visual-assets.js +37 -21
  53. package/lib/gui/visual-assets.js.map +1 -1
  54. package/lib/gui/visual-system.js +269 -269
  55. package/lib/gui/workbench-ui.js +549 -136
  56. package/lib/gui/workbench-ui.js.map +1 -1
  57. package/lib/gui/workbench.js +133 -0
  58. package/lib/gui/workbench.js.map +1 -1
  59. package/lib/index.js +392 -40
  60. package/lib/index.js.map +1 -1
  61. package/lib/types/core/binding.d.ts +29 -0
  62. package/lib/types/core/db.d.ts +14 -0
  63. package/lib/types/core/delivery-ack.d.ts +688 -0
  64. package/lib/types/core/delivery-change.d.ts +381 -0
  65. package/lib/types/core/owner-binding-intent.d.ts +9 -1
  66. package/lib/types/core/owner-window.d.ts +237 -3
  67. package/lib/types/core/task-service.d.ts +22 -0
  68. package/lib/types/core/territory.d.ts +18 -3
  69. package/lib/types/gui/contract.d.ts +162 -1
  70. package/lib/types/gui/owner-control.d.ts +61 -1
  71. package/lib/types/gui/snapshot.d.ts +8 -0
  72. package/lib/types/gui/visual-assets.d.ts +16 -0
  73. package/lib/types/gui/workbench.d.ts +47 -1
  74. package/lib/types/index.d.ts +60 -1
  75. package/lib/types/worker/governed-executor.d.ts +15 -0
  76. package/lib/worker/governed-executor.js +21 -0
  77. package/lib/worker/governed-executor.js.map +1 -1
  78. package/package.json +80 -75
@@ -0,0 +1,688 @@
1
+ import type { EventRow, KingdomStore, RoleBindingRow, TaskRow, WorkerResultRow } from './db.js';
2
+ import type { CommandContext } from './task-service.js';
3
+ export declare const DELIVERY_ACK_EVENT_TYPE = "OWNER_DELIVERY_ITEM_ACKNOWLEDGED";
4
+ /** 知悉回执载荷版本;形状变化时必须递增,旧记录按旧版本读取。 */
5
+ export declare const DELIVERY_ACK_PAYLOAD_VERSION = "KingdomDeliveryItemAck/v1";
6
+ /**
7
+ * 交付条目提问与回复:**两条独立**的治理事实,写在既有 events 账本里。
8
+ *
9
+ * 它们与「知悉」无关:提问不是知悉、不是 ACCEPT、不是 Task DONE,也不改变任何
10
+ * Task/Claim/审查/发布状态;回复同理。二者都不触发任何自动派发、唤醒或后续动作。
11
+ */
12
+ export declare const DELIVERY_QUESTION_EVENT_TYPE = "OWNER_DELIVERY_ITEM_QUESTIONED";
13
+ export declare const DELIVERY_REPLY_EVENT_TYPE = "OWNER_DELIVERY_ITEM_ANSWERED";
14
+ export declare const DELIVERY_QUESTION_PAYLOAD_VERSION = "KingdomDeliveryItemQuestion/v1";
15
+ export declare const DELIVERY_REPLY_PAYLOAD_VERSION = "KingdomDeliveryItemReply/v1";
16
+ /** 需要最小化投影的事件类型;通用事件投影只保留元数据,绝不带问答正文。 */
17
+ export declare const DELIVERY_QUESTION_EVENT_TYPES: readonly string[];
18
+ /** 交付页的三层结构:成果摘要 → 模块/事项 → 证据/改动。 */
19
+ export declare const DELIVERY_ITEM_LAYERS: readonly ["SUMMARY", "MODULE", "EVIDENCE"];
20
+ export type DeliveryItemLayer = (typeof DELIVERY_ITEM_LAYERS)[number];
21
+ /**
22
+ * 条目槽位:与所属层一起构成身份的命名空间。
23
+ *
24
+ * `artifacts`(产物引用)与 `risks`(执行者报告的风险)同属 EVIDENCE 层。
25
+ * 若身份只用「层 + 位置」,追加一个 artifact 会把后面所有 risk 的位置整体
26
+ * 后移,使旧的 risk 条目 ID 被另一个 artifact 占用——既有知悉会错误地指向
27
+ * 另一条内容。因此身份必须带槽位,各类条目在各自槽位内独立编号。
28
+ *
29
+ * `CHANGE` 槽位承载「主管确认的改动证据」条目;它的身份来自稳定的 entry id,
30
+ * 而不是位置,避免主管换选改动时旧条目 ID 被挪用。
31
+ */
32
+ export declare const DELIVERY_ITEM_SLOTS: readonly ["SUMMARY", "ARTIFACT", "RISK", "CHANGE"];
33
+ export type DeliveryItemSlot = (typeof DELIVERY_ITEM_SLOTS)[number];
34
+ /**
35
+ * 「查看改动」可信度分类。
36
+ *
37
+ * - `REPO_RELATIVE_VERIFIED`:可验证的仓库相对路径 + 固定源码版本/差异。只有
38
+ * 主管在 ACCEPT 中显式选择、且本地内容寻址证据 hash 重验通过时才成立。
39
+ * - `NOT_LOCATABLE`:无可信来源。GUI 必须明确显示「不可定位」而不是给出链接。
40
+ */
41
+ export declare const DELIVERY_CHANGE_REF_KINDS: readonly ["REPO_RELATIVE_VERIFIED", "NOT_LOCATABLE"];
42
+ export type DeliveryChangeRefKind = (typeof DELIVERY_CHANGE_REF_KINDS)[number];
43
+ /** 界面与报告共用的固定标注:这是主管确认的改动证据,不是作者证据。 */
44
+ export declare const CHANGE_EVIDENCE_LABEL = "\u4E3B\u7BA1\u786E\u8BA4\u7684\u6539\u52A8\u8BC1\u636E";
45
+ export declare const CHANGE_EVIDENCE_NOTE = "\u672C\u5DEE\u5F02\u6765\u81EA\u672C\u6B21 Task/attempt \u7A97\u53E3\u524D\u540E\u7684\u6709\u754C\u672C\u5730\u5FEB\u7167\uFF0C\u5E76\u7531\u8BE5\u9886\u5730\u5F53\u524D ACTIVE \u4E3B\u7BA1\u5728\u540C\u4E00\u4E8B\u52A1\u7684 ACCEPT \u4E2D\u663E\u5F0F\u9009\u62E9\u786E\u8BA4\u3002\u5B83\u53EA\u8BC1\u660E\u8FD9\u4E9B\u4ED3\u5E93\u76F8\u5BF9\u8DEF\u5F84\u5728\u7A97\u53E3\u5185\u53D1\u751F\u53D8\u5316\uFF1B\u4E0D\u8BC1\u660E Git \u4F5C\u8005\u8EAB\u4EFD\uFF0C\u4E5F\u4E0D\u8BC1\u660E\u7531\u54EA\u4E2A\u6267\u884C\u8005\u5199\u5165\u3002";
46
+ /** 已确认改动证据的最小可投影形状(由 `delivery-change.ts` 解析后传入)。 */
47
+ export interface DeliveryChangeEvidenceItem {
48
+ entryId: string;
49
+ /** 仓库相对路径;公开展示、链接与内容版本都用它,不使用工作区相对路径。 */
50
+ repoPath: string;
51
+ status: string;
52
+ note: string;
53
+ }
54
+ export interface DeliveryChangeEvidenceInput {
55
+ evidenceId: string;
56
+ attemptNo: number;
57
+ repoHead: string | null;
58
+ coverageComplete: boolean;
59
+ coverageReasons: string[];
60
+ note: string;
61
+ entries: DeliveryChangeEvidenceItem[];
62
+ }
63
+ export interface DeliveryChangeRef {
64
+ kind: DeliveryChangeRefKind;
65
+ /** 仅 `REPO_RELATIVE_VERIFIED` 时存在,且必须通过严格校验。 */
66
+ repoPath: string | null;
67
+ /** 固定源码版本或差异标识;缺失即不可信。 */
68
+ revision: string | null;
69
+ reasonCode: string | null;
70
+ note: string;
71
+ /** 已确认证据的 manifest id 与条目 id;只在可信时存在。 */
72
+ evidenceId?: string | null;
73
+ entryId?: string | null;
74
+ /** 固定标注「主管确认的改动证据」。 */
75
+ evidenceLabel?: string | null;
76
+ /** 部分覆盖时的诚实提示;完整覆盖为 null。 */
77
+ coverageNote?: string | null;
78
+ }
79
+ export interface DeliveryItemDetail {
80
+ label: string;
81
+ detail: string;
82
+ sourceRef: DeliverySourceRef | null;
83
+ }
84
+ export interface DeliveryItemContent {
85
+ layer: DeliveryItemLayer;
86
+ label: string;
87
+ detail: string;
88
+ sourceRef: DeliverySourceRef | null;
89
+ change: DeliveryChangeRef;
90
+ details: DeliveryItemDetail[];
91
+ }
92
+ export interface DeliveryItem {
93
+ /** 稳定 ID:同一交付内同一角色条目在任意重建中保持相同。 */
94
+ itemId: string;
95
+ /** 内容版本:条目内容(含主管接受的 attempt)变化时改变。 */
96
+ contentHash: string;
97
+ content: DeliveryItemContent;
98
+ }
99
+ export interface DeliverySourceRef {
100
+ entityType: 'worker_results' | 'tasks' | 'executions';
101
+ entityId: string | null;
102
+ }
103
+ /** Owner 知悉一次回执;只记录 principal、条目/版本与时间,不采集理由或理解程度。 */
104
+ export interface DeliveryAcknowledgement {
105
+ deliveryId: string;
106
+ itemId: string;
107
+ contentHash: string;
108
+ ownerId: string;
109
+ acknowledgedAt: string;
110
+ eventSeq: number;
111
+ eventId: string;
112
+ /** 该次知悉写入时交付所依据的接受证据强度(历史回执为 UNKNOWN)。 */
113
+ acceptanceEvidenceKind: DeliveryAcceptanceEvidenceKind | 'UNKNOWN';
114
+ /** 该次知悉写入时是否 exact result-bound。 */
115
+ acceptanceEvidenceExact: boolean;
116
+ }
117
+ export type DeliveryAcknowledgementState = 'ACKNOWLEDGED' | 'PENDING' | 'PENDING_REVISION';
118
+ /**
119
+ * 主管 ACCEPT 确认交付时**实际可核对到**的证据强度。
120
+ *
121
+ * - `EXACT_RESULT_BOUND`:`TASK_ACCEPTED` 同时锁定了本次 Claim 的 `reviewed_result_id`
122
+ * 与 `reviewed_result_digest`,且两者都与当前 Claim 一致。这是新格式的强证据。
123
+ * - `LEGACY_ATTEMPT_ONLY`:immutable v1.0.0 的合法 `TASK_ACCEPTED` 只有
124
+ * `reviewed_attempt_no`(以及 decision/reviewer/claimed_outcome 等真实字段),
125
+ * 既没有 `reviewed_result_id` 也没有 `reviewed_result_digest`。Owner 2026-09-27
126
+ * 裁决允许知悉这类历史交付,但必须标注「历史接受证据较弱」:它只按真实事件字段
127
+ * 与**同 Task/attempt 的唯一 WorkerResult** 判定,不冒充 exact result-bound。
128
+ * - 新格式两字段只出现其一、digest 不一致、或 JSON 形状与真实 v1.0.0 事件不符时
129
+ * 一律拒绝(`invalid`),不会退回弱判据,也不会静默隐藏历史交付。
130
+ */
131
+ export declare const DELIVERY_ACCEPTANCE_EVIDENCE_KINDS: readonly ["EXACT_RESULT_BOUND", "LEGACY_ATTEMPT_ONLY"];
132
+ export type DeliveryAcceptanceEvidenceKind = (typeof DELIVERY_ACCEPTANCE_EVIDENCE_KINDS)[number];
133
+ /** 历史(v1.0.0)接受证据的固定标注文案;工作台与 Owner 窗口共用同一措辞。 */
134
+ export declare const LEGACY_ACCEPTANCE_EVIDENCE_NOTE = "\u5386\u53F2\u63A5\u53D7\u8BC1\u636E\u8F83\u5F31\uFF1A\u8BE5 Task/attempt \u7684 TASK_ACCEPTED \u662F v1.0.0 \u65E7\u683C\u5F0F\uFF0C\u53EA\u6709\u5C1D\u8BD5\u7F16\u53F7\uFF0C\u7F3A\u5C11\u88AB\u5BA1\u67E5\u7ED3\u679C ID \u4E0E\u5185\u5BB9\u6458\u8981\uFF1B\u672C\u6761\u6309\u771F\u5B9E\u4E8B\u4EF6\u5B57\u6BB5\u4E0E\u540C Task/attempt \u7684\u552F\u4E00 WorkerResult \u5224\u5B9A\uFF0C\u4E0D\u6784\u6210 exact result-bound \u8BC1\u636E\u3002";
135
+ export interface DeliveryAcceptanceEvidence {
136
+ attemptNo: number;
137
+ /** 被审查结果的 ID;legacy 判定下是本 Task/attempt 唯一 WorkerResult 的 ID。 */
138
+ resultId: string;
139
+ /** true 仅当 `reviewed_result_id` 与 `reviewed_result_digest` 都与当前 Claim 一致。 */
140
+ exactResultBound: boolean;
141
+ /** 与事件 attempt 匹配的 WorkerResult 数量;legacy 必须恰好为 1。 */
142
+ matchingResultCount: number;
143
+ }
144
+ export interface DeliveryAcceptanceClassification {
145
+ kind: DeliveryAcceptanceEvidenceKind;
146
+ evidence: DeliveryAcceptanceEvidence;
147
+ legacyNote: string | null;
148
+ }
149
+ export interface DeliveryItemAcknowledgementView {
150
+ state: DeliveryAcknowledgementState;
151
+ /** 当前版本是否已有 Owner 知悉。 */
152
+ acknowledged: boolean;
153
+ /** 旧版本的知悉只留历史,不覆盖当前版本。 */
154
+ historicalCount: number;
155
+ acknowledgedAt: string | null;
156
+ acknowledgedByOwnerId: string | null;
157
+ acknowledgementEventSeq: number | null;
158
+ /**
159
+ * 当前版本那次知悉写入时依据的接受证据强度。
160
+ * 旧回执或尚无当前版本知悉时为 `UNKNOWN`,不猜测。
161
+ */
162
+ acknowledgedAcceptanceEvidenceKind: DeliveryAcceptanceEvidenceKind | 'UNKNOWN';
163
+ /** 当前版本那次知悉写入时是否 exact result-bound。 */
164
+ acknowledgedAcceptanceEvidenceExact: boolean;
165
+ }
166
+ export declare function digestText(value: string): string;
167
+ /**
168
+ * 交付身份 = 一个 Task 的一条交付时间线。
169
+ *
170
+ * 刻意**不含** attempt/result:同一 Task 的后续已接受尝试是同一交付的新版本,
171
+ * 因此条目 ID 保持稳定,旧知悉随内容版本变化自动降为历史。若是每次尝试换一个
172
+ * 交付身份,旧知悉就无法作为「同一条目的历史」被识别。
173
+ */
174
+ export declare function deliveryIdFor(taskId: string): string;
175
+ /**
176
+ * 条目 ID 来自条目在交付结构中的**位置**(层 + 槽位 + 槽位内位置),
177
+ * 不来自可变化的正文,因此同一逻辑条目改版后仍是同一条。新增条目会追加
178
+ * 新 ID,旧条目 ID 不变;不同槽位(产物引用 / 风险)之间也不会互相挪用。
179
+ */
180
+ export declare function deliveryItemId(deliveryId: string, layer: DeliveryItemLayer, slot: DeliveryItemSlot, position: number): string;
181
+ /**
182
+ * 改动证据条目的身份来自稳定 entry id(= 仓库相对路径的摘要),不来自位置:
183
+ * 主管换选或增删改动时,旧条目 ID 不会被另一条改动占用。
184
+ */
185
+ export declare function deliveryChangeItemId(deliveryId: string, entryId: string): string;
186
+ /**
187
+ * 内容版本 = 结构、标签、正文、证据文本与改动引用状态(含可见 note、已确认
188
+ * 证据 id 与条目 id)的规范化摘要。
189
+ *
190
+ * 只在字段真实存在时把 evidenceId/entryId 纳入摘要,因此未带改动证据的既有
191
+ * 条目版本保持不变,历史知悉不会被本次扩展误判为改版。
192
+ */
193
+ export declare function deliveryContentHash(content: DeliveryItemContent): string;
194
+ /**
195
+ * 严格校验仓库相对路径。
196
+ *
197
+ * 拒绝:绝对路径、Windows 盘符、UNC/网络共享、`..` 逃逸、`.git` 内部路径、控制字符、
198
+ * 反斜杠(仓库相对路径一律使用 `/`)。任何不通过的值都不得成为链接。
199
+ */
200
+ export declare function validateRepoRelativePath(value: unknown): string | null;
201
+ /** 固定源码版本/差异标识:有界、无空白的 opaque 标识(含 git 的 `~`/`^` 相对写法)。 */
202
+ export declare function validateSourceRevision(value: unknown): string | null;
203
+ /**
204
+ * 只有「通过严格校验的仓库相对路径 + 固定版本」才构成可信改动引用。
205
+ * 其余一切(任意 Claim 字符串、本机绝对路径、现有 `SourceRef`)都返回 null,
206
+ * 由调用方明确渲染为不可定位。
207
+ */
208
+ export declare function trustedChangeRef(repoPath: unknown, revision: unknown): {
209
+ repoPath: string;
210
+ revision: string;
211
+ } | null;
212
+ export interface AcceptedDelivery {
213
+ task: TaskRow;
214
+ claim: WorkerResultRow;
215
+ }
216
+ /**
217
+ * 只有**同一 Task/attempt 的主管 ACCEPT** 才确认交付。
218
+ *
219
+ * `TASK_ACCEPTED` 事件必须同时锁定本次 Claim 的 attempt、`result_id` 与内容
220
+ * 摘要(`reviewed_result_digest`,与主管审查写入端使用同一 `ownerInputHash`)。
221
+ * 只比对 attempt 会让一条针对同一 attempt 但另一份/已改内容的 ACCEPT 冒充确认,
222
+ * 因此三者缺一不可。
223
+ *
224
+ * 这是严格的**布尔**判据:新格式必须两字段齐备并一致,两字段只出现其一即拒绝。
225
+ * 需要区分「历史接受证据较弱」的调用方请看 {@link classifyAcceptedDelivery}。
226
+ */
227
+ export declare function acceptedDelivery(store: KingdomStore, claim: WorkerResultRow | null, latestReview: EventRow | null): boolean;
228
+ /**
229
+ * 把一次主管 ACCEPT 判定为「exact result-bound」或「历史接受证据较弱」,或 null(拒绝)。
230
+ *
231
+ * 判据(任一条不成立即返回 null,不返回较弱证据):
232
+ * - Task 处于 `DONE`,最近一次主管裁定是 `TASK_ACCEPTED`(`readLatestReviewEvent`
233
+ * 已限定 `actor_role = SUPERVISOR`)且 `decision = 'ACCEPT'`;
234
+ * - `reviewed_attempt_no` 必须等于本次 Claim 的 attempt;
235
+ * - **新格式**:`reviewed_result_id` 与 `reviewed_result_digest` 必须同时存在、均为
236
+ * 字符串,并分别等于本次 Claim 的 `result_id` 与 `ownerInputHash(claim)`;
237
+ * - **旧格式(v1.0.0)**:两个新格式字段必须**同时缺失**,payload 必须**恰好**由
238
+ * v1.0.0 的五个真实字段(decision / reviewed_attempt_no / reason /
239
+ * reviewer_binding_id / claimed_outcome)组成——缺一个或多一个都不是旧格式,
240
+ * 且该 Task/attempt 恰好只有一条 WorkerResult 且就是本次 Claim。缺少这一唯一性
241
+ * 核对时无法排除「同一 attempt 有多份结果」,因此拒绝。
242
+ *
243
+ * 旧格式只做上述真实字段核对,不虚构 result-bound 证据:它证明的是「该尝试的唯一
244
+ * 已记录结果被接受」,而不是「该事件的摘要与这份内容一致」。
245
+ */
246
+ export declare function classifyAcceptedDelivery(store: KingdomStore, claim: WorkerResultRow | null, latestReview: EventRow | null): DeliveryAcceptanceClassification | null;
247
+ /** 读取某 Task 最近一次主管裁定事件(与投影窗口无关的精确读取)。 */
248
+ export declare function readLatestReviewEvent(store: KingdomStore, kingdomId: string, taskId: string): EventRow | null;
249
+ export declare const CREDENTIAL_REDACTION_PATTERN: RegExp;
250
+ /** 只做凭据关键字 + 完整值(含 Bearer 等 scheme)替换;调用方决定是否再做路径脱敏。 */
251
+ export declare function redactCredentialText(value: string): string;
252
+ /**
253
+ * 交付文本的公开呈现脱敏。
254
+ *
255
+ * 沿用工作台投影既有的公开内容规则(`src/gui/snapshot.ts` 的
256
+ * `sanitizePublicJsonString` public-content 分支):本机绝对路径、UNC 路径与
257
+ * 内联凭据替换为占位符。刻意只做这一件事——不做递归 JSON 遍历,也不是
258
+ * 新的通用脱敏框架;核心派生一次脱敏,所有呈现面(Owner 窗口与工作台投影)
259
+ * 都不会再看到原始 Claim 文本。
260
+ */
261
+ export declare function redactDeliveryText(value: string): string;
262
+ /**
263
+ * 从已确认的交付派生三层条目。
264
+ *
265
+ * 摘要层恒有 1 条(内容为执行者自述摘要);每条 `artifacts` 与 `risks` 各派生一条
266
+ * 证据层条目。所有条目都带独立 ID 与内容版本,外层知悉不会覆盖子条。
267
+ *
268
+ * 位置在每个槽位内独立编号,因此追加 artifact 不会移动既有 risk 的身份。
269
+ *
270
+ * `changeEvidence` 只在主管在 ACCEPT 中显式选择了改动引用、且本地内容寻址证据
271
+ * hash 重验通过时传入。它派生的条目**不是**执行者自述,而是有界窗口观测 +
272
+ * 主管确认;标签固定为「主管确认的改动证据」,且绝不声称 Git 证明作者身份。
273
+ */
274
+ export declare function deriveDeliveryItems(taskId: string, claim: WorkerResultRow, changeEvidence?: DeliveryChangeEvidenceInput | null): DeliveryItem[];
275
+ /** 按 delivery + item 读取全部历史知悉(升序),包括旧版本。 */
276
+ export declare function readDeliveryAcknowledgements(store: KingdomStore, kingdomId: string, deliveryId: string): DeliveryAcknowledgement[];
277
+ /**
278
+ * 汇总某交付内每条条目的当前知悉状态。
279
+ *
280
+ * - 当前 `contentHash` 已有知悉 → `ACKNOWLEDGED`
281
+ * - 只有旧版本知悉 → `PENDING_REVISION`(旧知悉仅留历史)
282
+ * - 从无知悉 → `PENDING`
283
+ *
284
+ * `ownerId` 是当前王国 Owner principal:知悉回执必须归属于该 principal,
285
+ * 其他 actor 的历史事件(即使事件类型相同)都不构成 Owner 知悉。
286
+ */
287
+ export declare function deliveryAcknowledgementView(acknowledgements: DeliveryAcknowledgement[], item: DeliveryItem, ownerId: string): DeliveryItemAcknowledgementView;
288
+ export declare class DeliveryAcknowledgementError extends Error {
289
+ readonly code: string;
290
+ constructor(code: string, message: string);
291
+ }
292
+ /** 幂等事件 ID:同一交付条目版本的再次知悉不会写出第二条事实。 */
293
+ export declare function deliveryAckEventId(kingdomId: string, deliveryId: string, itemId: string, contentHash: string): string;
294
+ export interface RecordDeliveryAcknowledgementInput {
295
+ kingdomId: string;
296
+ deliveryId: string;
297
+ itemId: string;
298
+ contentHash: string;
299
+ taskId: string;
300
+ attemptNo: number;
301
+ resultId: string;
302
+ ownerId: string;
303
+ ownerBindingId: string | null;
304
+ itemLabel: string;
305
+ acknowledgedAt: string;
306
+ /** 已确认的改动证据;仅在主管已选择且本地 hash 重验通过时传入,用于派生相同条目集合。 */
307
+ changeEvidence?: DeliveryChangeEvidenceInput | null;
308
+ /**
309
+ * Owner Control Plane 归因(source_channel / decision_id / operation_id)。
310
+ * 与既有 `OWNER_OPERATION_APPLIED` 回执同款,便于把知悉事实回溯到具体操作。
311
+ */
312
+ attribution?: Record<string, unknown>;
313
+ }
314
+ /**
315
+ * 追加一条 Owner 知悉事实。
316
+ *
317
+ * 前置校验(任一失败即零写入):
318
+ * - Task 当前确实处于「主管 ACCEPT 确认交付」状态;
319
+ * - 传入的 `deliveryId`/`itemId`/`contentHash` 与当前派生结果完全一致
320
+ * (防止对旧版本或伪造条目写入知悉)。
321
+ *
322
+ * 幂等:同一 (delivery, item, contentHash) 已有记录时原样返回,不追加事件。
323
+ */
324
+ export declare function recordDeliveryAcknowledgement(store: KingdomStore, input: RecordDeliveryAcknowledgementInput): DeliveryAcknowledgement;
325
+ /** 界面与报告共用的固定措辞:回复只说明主管回答了这个问题。 */
326
+ export declare const DELIVERY_QUESTION_NOTE = "\u63D0\u95EE\u4E0E\u56DE\u590D\u53EA\u662F\u5BF9\u8BDD\u8BB0\u5F55\uFF1A\u5B83\u4EEC\u4E0D\u4EE3\u8868 Owner \u77E5\u6089\u3001\u8D28\u91CF\u8BA4\u53EF\u3001\u4EBA\u7C7B\u9A8C\u6536\u3001Task DONE\uFF0C\u4E5F\u4E0D\u6539\u53D8\u4EFB\u4F55\u4EFB\u52A1\u3001\u5BA1\u67E5\u6216\u53D1\u5E03\u72B6\u6001\u3002";
327
+ /** 未被主管实际读取时只能说「待领取」,不声称已通知或已阅读。 */
328
+ export declare const DELIVERY_QUESTION_UNCLAIMED = "\u5F85\u9886\u53D6\uFF08\u5C1A\u672A\u786E\u8BA4\u4E3B\u7BA1\u5DF2\u8BFB\u53D6\uFF09";
329
+ /**
330
+ * 回复可达性。`REPLY_ACCESSIBLE` 之外的状态都不得写入回复:
331
+ * 旧主管退任、session 更换或领地改绑时,问题保持可见但明确不可达,不会自动转给继任者。
332
+ */
333
+ export declare const DELIVERY_REPLY_STATES: readonly ["REPLY_ACCESSIBLE", "REVIEWER_BINDING_MISSING", "REVIEWER_BINDING_RETIRED", "REVIEWER_SESSION_CHANGED", "SUPERVISOR_REBOUND"];
334
+ export type DeliveryReplyState = (typeof DELIVERY_REPLY_STATES)[number];
335
+ /**
336
+ * 一条问题相对**当前交付目录**的版本关系。
337
+ *
338
+ * - `CURRENT`:该条目此刻重新派生出的版本与问题冻结版本一致(已验证当前)。
339
+ * - `HISTORICAL`:该条目仍可派生,但版本已变化(可确认的旧版本)。
340
+ * - `UNVERIFIABLE`:该条目此刻无法从当前 ACCEPT/证据重新派生(例如 CHANGE 证据
341
+ * 丢失或被替换);既不能当成当前版,也不能断言它是旧版。后两者都不计当前待办、
342
+ * 不可回复,但仍可读。
343
+ */
344
+ export declare const DELIVERY_ITEM_VERSION_STATES: readonly ["CURRENT", "HISTORICAL", "UNVERIFIABLE"];
345
+ export type DeliveryItemVersionState = (typeof DELIVERY_ITEM_VERSION_STATES)[number];
346
+ /** 版本关系判据:只有精确命中当前派生版本才算当前;派生失败一律 fail-as-unknown。 */
347
+ export declare function classifyDeliveryItemVersion(currentItemContentHash: string | null, questionContentHash: string): DeliveryItemVersionState;
348
+ export interface DeliveryQuestion {
349
+ questionId: string;
350
+ deliveryId: string;
351
+ taskId: string;
352
+ itemId: string;
353
+ itemLabel: string;
354
+ contentHash: string;
355
+ attemptNo: number;
356
+ resultId: string;
357
+ /** `TASK_ACCEPTED` 事件所记的主管 binding;这是首版唯一合法的接收者。 */
358
+ reviewerBindingId: string;
359
+ /** ACCEPT 证据强度与 exact result-bound(问题写入时冻结)。 */
360
+ acceptanceEvidenceKind: DeliveryAcceptanceEvidenceKind | 'UNKNOWN';
361
+ acceptanceEvidenceExact: boolean;
362
+ ownerId: string;
363
+ ownerBindingId: string | null;
364
+ /**
365
+ * 写入这条问题的 prepared Owner operation;旧记录为 null。
366
+ *
367
+ * 它与事件 ID 互为核对:同一 operation 重放必须命中同一 ID,不同 operation
368
+ * 不得因正文相同而被判为同一条问题。
369
+ */
370
+ operationId: string | null;
371
+ /** 已脱敏的问题正文;只经 Owner 授权窗口或责任主管 Tool 返回。 */
372
+ questionText: string;
373
+ askedAt: string;
374
+ eventId: string;
375
+ eventSeq: number;
376
+ reply: DeliveryQuestionReply | null;
377
+ replyState: DeliveryReplyState;
378
+ /** 领地主理当前指向的 Supervisor binding;未指派或不存在时为 null。 */
379
+ currentSupervisorBindingId: string | null;
380
+ /**
381
+ * 这条问题相对**当前交付目录**的版本关系:已验证当前、可确认的旧版本,或无法重验。
382
+ *
383
+ * 逐条按该条目当前重新派生出的 `contentHash` 判定:后两者仍可读、仍保留原文与回复,
384
+ * 但**不计当前待办**,界面也不得声称「当前可回复」。这不是可写状态,只是当前交付
385
+ * 目录与问题冻结版本之间的比较结果。
386
+ */
387
+ itemVersion: DeliveryItemVersionState;
388
+ /** 该条目此刻重新派生出的内容版本;无法派生时为 null,此时不声称任何版本关系。 */
389
+ currentItemContentHash: string | null;
390
+ }
391
+ export interface DeliveryQuestionReply {
392
+ questionId: string;
393
+ responderBindingId: string;
394
+ /** 已脱敏的回复正文。 */
395
+ replyText: string;
396
+ repliedAt: string;
397
+ eventId: string;
398
+ eventSeq: number;
399
+ }
400
+ /** 某交付条目的问答线程(Owner 窗口与工作台元数据共用入口)。 */
401
+ export interface DeliveryItemQuestionThread {
402
+ deliveryId: string;
403
+ taskId: string;
404
+ itemId: string;
405
+ itemLabel: string;
406
+ /** 目标条目在本次读取中使用的当前内容版本;无法重验时为 null。 */
407
+ contentHash: string | null;
408
+ questions: DeliveryQuestion[];
409
+ answeredCount: number;
410
+ /** 已验证当前内容版本且尚无回复的条数;历史版与无法重验的未答问题都不计入。 */
411
+ pendingCount: number;
412
+ /** 属于可确认的旧内容版本、仅留历史的条数。 */
413
+ historyCount: number;
414
+ /** 当前交付目录无法重验该条目版本、因此不声称任何版本关系的条数。 */
415
+ unverifiableCount: number;
416
+ /** 最近一条**当前版本**问题;没有当前版本问题时为 null。 */
417
+ currentQuestionId: string | null;
418
+ /** 最近一条当前版本问题的内容版本;没有当前版本问题时为 null。 */
419
+ currentContentHash: string | null;
420
+ }
421
+ /**
422
+ * 问题事实 ID:**以一次 prepared Owner operation 为界**,不以正文去重。
423
+ *
424
+ * 同一 prepared operation 重试(含 submit 重放)由调用方传入同一 operationId,
425
+ * 因此得到同一事件 ID,只写一条事实;两个**不同** operation 即使针对同一条目、
426
+ * 同一内容版本、输入完全相同的文字,也各自形成独立问题——提问身份属于一次 Owner
427
+ * 操作,不属于那段文本。
428
+ *
429
+ * 旧记录(冻结时尚未携带 operationId)用写入时冻结的 questionId/contentHash/正文
430
+ * 派生,保证同一历史问题在任何重放中仍是同一身份。
431
+ */
432
+ export declare function deliveryQuestionEventId(input: {
433
+ kingdomId: string;
434
+ deliveryId: string;
435
+ itemId: string;
436
+ contentHash: string;
437
+ operationId?: string | null;
438
+ questionId?: string | null;
439
+ questionText?: string | null;
440
+ }): string;
441
+ /**
442
+ * 幂等回复 ID:**只由 question ID 决定**,与正文无关。
443
+ *
444
+ * 一个问题因此至多存在一条回复事实行;同一文本重试回原事实,不同文本在同一
445
+ * `BEGIN IMMEDIATE` 事务里看到既有回复行并明确冲突。事件 ID 不含正文,两个并发
446
+ * 连接不可能各自写出「不同 ID 的双事实」。
447
+ */
448
+ export declare function deliveryReplyEventId(kingdomId: string, questionId: string): string;
449
+ /**
450
+ * 读取一条已确认交付的**全部**提问与回复。**只按精确引用的既有事件行读取**,不依赖
451
+ * 任何有界的最近事件投影:账本里没有记录的问题就不存在。
452
+ *
453
+ * 返回的线程按**问题自身**的 item/contentHash 归类,不用首问代表整条交付:
454
+ * `itemId`/`itemLabel`/`contentHash` 只描述最早那条问题所属的条目,调用方必须用
455
+ * {@link deliveryQuestionThreadForItem} 按目标条目过滤。
456
+ */
457
+ export declare function readDeliveryQuestionThread(store: KingdomStore, kingdomId: string, deliveryId: string): DeliveryItemQuestionThread | null;
458
+ /**
459
+ * 一个**已有提问记录**的精确条目(Owner 只读问答历史入口用;不含任何正文)。
460
+ *
461
+ * 它只从权威账本里的提问事实派生,因此条目即使已离开当前交付目录(例如 CHANGE
462
+ * 证据丢失、条目已改版消失)也仍然可发现;是否可读仍由调用方按窗口 scope 与动作判定。
463
+ */
464
+ export interface DeliveryQuestionHistoryTarget {
465
+ deliveryId: string;
466
+ taskId: string;
467
+ itemId: string;
468
+ itemLabel: string;
469
+ questionCount: number;
470
+ /** 已验证当前版本且尚无回复的条数;历史版与无法重验的都不计入。 */
471
+ pendingCount: number;
472
+ answeredCount: number;
473
+ historyCount: number;
474
+ unverifiableCount: number;
475
+ lastAskedAt: string;
476
+ /** 最近一条问题相对当前派生版本的版本关系。 */
477
+ latestItemVersion: DeliveryItemVersionState;
478
+ /** 该条目此刻重新派生出的内容版本;无法派生时为 null。 */
479
+ currentContentHash: string | null;
480
+ }
481
+ /**
482
+ * 列出本王国**已有提问记录**的精确条目索引(按最近提问时间倒序)。
483
+ *
484
+ * 只查既有提问事件账本,不依赖任何有界的最近事件投影或当前交付目录:这正是
485
+ * 「旧问答仍可发现」的最小入口。正文与回复正文不在这里返回,调用方仍须按窗口
486
+ * scope 过滤后展示,且这些条目**不能**被当作新提问目标(prepare 另有精确重验)。
487
+ */
488
+ export declare function listDeliveryQuestionHistory(store: KingdomStore, kingdomId: string): DeliveryQuestionHistoryTarget[];
489
+ /**
490
+ * 一个**精确条目**此刻重新派生出的版本(itemId、contentHash 与当前标签)。
491
+ *
492
+ * Owner 的精确 task/item 回读必须用它做版本真值,**不能**用有界展示目录:展示目录
493
+ * 为了界面规模会截断较旧条目,但那些条目依然是可以精确重验的当前版本。返回 null
494
+ * 表示该条目此刻无法从当前 ACCEPT/证据重新派生。
495
+ */
496
+ export declare function readDeliveryItemVersion(store: KingdomStore, kingdomId: string, taskId: string, itemId: string): {
497
+ itemId: string;
498
+ contentHash: string;
499
+ label: string;
500
+ } | null;
501
+ /**
502
+ * 过滤出**某一交付条目**的问答线程。
503
+ *
504
+ * 按每条问题自己的 `itemId` 归类,再按调用方给出的精确 `contentHash` 区分已验证当前、
505
+ * 历史版与无法重验;不以整条交付的首问代表其他条目。`contentHash` 为 null 表示当前
506
+ * 交付目录无法重验该条目,此时所有问题都标为无法重验而不是当前版。条目下没有任何
507
+ * 提问时返回 null,调用方据此说明「该条还没有提问记录」,而不是给出空线程或另一条的线程。
508
+ */
509
+ export declare function deliveryQuestionThreadForItem(thread: DeliveryItemQuestionThread | null, itemId: string, contentHash: string | null): DeliveryItemQuestionThread | null;
510
+ /**
511
+ * 回复可达性判据。
512
+ *
513
+ * 首版接收者是 `TASK_ACCEPTED` 所记的主管 binding(问题写入时冻结)。这里先看该
514
+ * binding 自身:不存在 → `REVIEWER_BINDING_MISSING`;已退任 → `REVIEWER_BINDING_RETIRED`;
515
+ * 领地当前主理已不是它 → `SUPERVISOR_REBOUND`;没有可用于回复的 session →
516
+ * `REVIEWER_SESSION_CHANGED`。只有全部成立才是 `REPLY_ACCESSIBLE`,否则 fail-closed。
517
+ *
518
+ * `claimedSessionId` 是调用方**实际用来证明身份**的 session:它与 binding 当前
519
+ * session 不一致(即主管已换 session)时同样不可达,避免旧 session 的调用者被误判为
520
+ * 当前责任主管。
521
+ */
522
+ export declare function classifyDeliveryReplyAccess(store: KingdomStore, kingdomId: string, reviewerBindingId: string, currentSupervisorBindingId: string | null, claimedSessionId?: string | null): {
523
+ state: DeliveryReplyState;
524
+ detail: string;
525
+ };
526
+ /** 公开事件投影的最大字段集:问答正文永不出现。 */
527
+ export declare function toDeliveryQuestionEventPayload(row: EventRow): Record<string, unknown>;
528
+ export declare class DeliveryQuestionError extends Error {
529
+ readonly code: string;
530
+ constructor(code: string, message: string);
531
+ }
532
+ export declare const DELIVERY_QUESTION_TEXT_LIMIT = 2000;
533
+ export declare const DELIVERY_REPLY_TEXT_LIMIT = 4000;
534
+ /**
535
+ * 提问/回复正文的写入形状:先做与公开呈现同一套凭据与路径脱敏,再折叠空白并限长。
536
+ *
537
+ * 事实里因此永远不保存未脱敏正文;投影端即使错误地透传字段,也不会带出凭据或本机路径。
538
+ */
539
+ export declare function boundedQuestionText(value: string, limit: number): string;
540
+ export interface RecordDeliveryQuestionInput {
541
+ kingdomId: string;
542
+ deliveryId: string;
543
+ taskId: string;
544
+ itemId: string;
545
+ itemLabel: string;
546
+ contentHash: string;
547
+ attemptNo: number;
548
+ resultId: string;
549
+ ownerId: string;
550
+ ownerBindingId: string | null;
551
+ /** 写入这条问题的 prepared Owner operation;同一 operation 重放必须幂等。 */
552
+ operationId: string;
553
+ questionText: string;
554
+ askedAt: string;
555
+ /** 已确认的改动证据;与知悉同一来源,保证 CHANGE 条目的清单可重算。 */
556
+ changeEvidence?: DeliveryChangeEvidenceInput | null;
557
+ attribution?: Record<string, unknown>;
558
+ }
559
+ /**
560
+ * 追加一条 Owner 提问事实。
561
+ *
562
+ * 前置校验(任一失败即零写入):
563
+ * - Task 当前确实处于「同一 Task/attempt 的主管 ACCEPT 确认交付」状态;
564
+ * - 传入的 delivery/item/contentHash/attempt/result 与当前派生结果完全一致;
565
+ * - `itemId` 必须正好指向一条提问槽位:入口每次只提交一条精确条目。
566
+ *
567
+ * 幂等:同一 `operationId`(即同一次 prepared operation 的重试与重放)已有记录时
568
+ * 原样返回;**不同 operation 即使问题文字相同,也各自是一条独立问题事实**。
569
+ */
570
+ export declare function recordDeliveryQuestion(store: KingdomStore, input: RecordDeliveryQuestionInput): {
571
+ questionId: string;
572
+ askedAt: string;
573
+ eventId: string;
574
+ eventSeq: number;
575
+ created: boolean;
576
+ };
577
+ /** 回复写入结果:`created=false` 表示同一回复文本已存在,未新增事实。 */
578
+ export interface RecordDeliveryReplyResult {
579
+ questionId: string;
580
+ reply: DeliveryQuestionReply;
581
+ created: boolean;
582
+ }
583
+ /**
584
+ * 追加一条主管回复事实。
585
+ *
586
+ * 写入门槛(任一失败即零写入):
587
+ * - 问题必须存在于账本里,且属于本王国、本条交付;
588
+ * - 传入 item/contentHash/attempt/result 必须与问题记录完全一致,同时仍等于当前
589
+ * 已确认交付的派生结果(条目改版后不得回复到旧版本);
590
+ * - 回复者必须**正好**是问题记录的主管 binding,且该 binding 此刻仍 ACTIVE、仍是
591
+ * 领地当前主理、其 session 仍是调用者用来证明身份的那个 session;
592
+ * - CHANGE 条目必须按**当前 ACCEPT 引用**在同一写锁内重新读取并重验证据:证据漂移、
593
+ * 被替换或条目改版时不再派生该条目,回复 fail-closed。
594
+ *
595
+ * 锁前入口校验(`replyToDeliveryQuestion`)只用于尽早拒绝与给出可读原因,**不是**
596
+ * 写入授权:上面这些可变授权事实全部在 `BEGIN IMMEDIATE` 取得写锁之后重新读取。
597
+ * 否则「A 先通过入口校验 → B 退任/改绑并提交 → A 再取锁写回复」会写出已失效的回复。
598
+ * 幂等重试仍在锁内最先判定:既有回复行 + 同一文本原样返回,不因随后改绑而报错,
599
+ * 也不会新增第二条事实。
600
+ *
601
+ * 一问最多一个当前回复,且**只由 question ID 决定回复事件 ID**:同一问题在任何
602
+ * 并发连接上都只可能写出一条回复事实行。同一文本重试幂等;不同文本明确拒绝。
603
+ * 「重验 + 单次写入」整体在 `store.withImmediateTransaction` 的 `BEGIN IMMEDIATE`
604
+ * 事务内完成:该包装在取得写锁之前不执行回调,BEGIN 因 BUSY/LOCKED/I-O/MISUSE
605
+ * 失败时原样抛出且**零回复写入**,绝不把 BEGIN 失败当作「已有外层事务」继续。
606
+ * 两个并发连接因此被 SQLite 串行化,不会各自看到空回复而写出双事实。
607
+ */
608
+ export declare function recordDeliveryReply(store: KingdomStore, input: {
609
+ kingdomId: string;
610
+ questionId: string;
611
+ responderBindingId: string;
612
+ /**
613
+ * 调用者用来证明身份的 session(Core 已由 DSH Runtime 核对的 ACTIVE session)。
614
+ * 锁内会再与 responder binding 当前 session 比对:主管已换 session 时,旧 session
615
+ * 的调用者不能被当作当前责任主管。
616
+ */
617
+ callerSessionId: string;
618
+ replyText: string;
619
+ repliedAt: string;
620
+ attribution?: Record<string, unknown>;
621
+ }): RecordDeliveryReplyResult;
622
+ /**
623
+ * 按精确 questionId 从权威账本读取一条问题;形状不可核对或不属于该王国时为 null。
624
+ */
625
+ export declare function readQuestionById(store: KingdomStore, kingdomId: string, questionId: string): DeliveryQuestion | null;
626
+ /** `TASK_ACCEPTED` 事件所记的主管 binding;形状不可核对时为 null(fail-closed)。 */
627
+ export declare function deliveryReviewerBindingId(review: EventRow | null): string | null;
628
+ /**
629
+ * 主管回复一个提问。
630
+ *
631
+ * 与收件箱共用同一套 session-bound 门槛:调用者必须已由 Core 证明为**真实、当前**的
632
+ * 同领地 ACTIVE 主管 session;问题必须正好写给该 binding,且该 binding 仍是领地当前
633
+ * 主理(退任、换 session、领地改绑一律拒绝,不改投继任者)。失败零写入。
634
+ *
635
+ * 这里的每一条都只是**早拒**:`recordDeliveryReply` 会在同一个写锁事务内用真实
636
+ * caller session、当前 binding 状态、当前领地主理与当前 ACCEPT 证据重新核对一遍,
637
+ * 因此锁前状态在等待写锁期间发生变化也不会写出失效回复。
638
+ *
639
+ * A question is answered at most once: the same reply text retried is idempotent, a
640
+ * different reply for the same question is rejected. A reply writes only this one
641
+ * conversation fact — never an acknowledgement, Task/Claim, supervisor ACCEPT, Owner
642
+ * acceptance or release fact, and never a dispatch/follow-up/wakeup.
643
+ */
644
+ export declare function replyToDeliveryQuestion(store: KingdomStore, ctx: CommandContext, input: {
645
+ questionId: string;
646
+ replyText: string;
647
+ }): {
648
+ ok: true;
649
+ text: string;
650
+ } | {
651
+ ok: false;
652
+ code: string;
653
+ message: string;
654
+ };
655
+ /** 一个 session 的全部 ACTIVE SUPERVISOR 绑定及其合并收件箱。 */
656
+ export interface SessionDeliveryQuestionInbox {
657
+ /** 该 session 当前可证明的全部 ACTIVE SUPERVISOR binding。 */
658
+ bindings: RoleBindingRow[];
659
+ entries: DeliveryQuestionInboxEntry[];
660
+ }
661
+ /**
662
+ * 按 session 读取**全部**可证明绑定的收件箱。
663
+ *
664
+ * 一个 session 可以合法持有多个 ACTIVE SUPERVISOR 绑定;只取第一个会让后续绑定的问题
665
+ * 静默消失。这里逐 binding 精确读取再合并:每条问题只有一个接收主管,因此不会重复。
666
+ * 领地界仍是这些 binding 当前主理领地的并集,授权仍由调用方用真实 session 判定。
667
+ * 找不到任何 binding 时返回空列表,由调用方 fail-closed。
668
+ */
669
+ export declare function readDeliveryQuestionInboxForSession(store: KingdomStore, kingdomId: string, sessionId: string | null | undefined): SessionDeliveryQuestionInbox;
670
+ export interface DeliveryQuestionInboxScope {
671
+ /** 调用者由 Core 证明的当前主管 binding;只返回**写给它**的问题。 */
672
+ reviewerBindingId: string;
673
+ /** 该主管当前主理的领地;仅用于展示范围的界,授权仍由 session-bound 身份判定。 */
674
+ territoryIds?: readonly string[];
675
+ }
676
+ /** 收件箱里的一条问题:正文、回复、当前可达性。 */
677
+ export interface DeliveryQuestionInboxEntry {
678
+ question: DeliveryQuestion;
679
+ taskTitle: string;
680
+ territoryName: string;
681
+ }
682
+ /**
683
+ * 按权威账本精确读取**只属于该主管 binding**的提问。
684
+ *
685
+ * 刻意不是「最近事件投影」:逐条从 events 表按 delivery 精确查询,因此不会被
686
+ * 有界的最近事件窗口截断,也不会看到其他主管或其他领地的问题。
687
+ */
688
+ export declare function readDeliveryQuestionInbox(store: KingdomStore, kingdomId: string, scope: DeliveryQuestionInboxScope): DeliveryQuestionInboxEntry[];