create-principles-disciple 1.156.2 → 1.157.2

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 (242) hide show
  1. package/_release/product-identity.json +2 -2
  2. package/codex-adapter/dist/worker/workspace-worker.d.ts +11 -3
  3. package/codex-adapter/dist/worker/workspace-worker.js +30 -16
  4. package/codex-adapter/package.json +1 -1
  5. package/console/dist/server/models/OwnerDecisionConsoleModel.js +33 -1
  6. package/console/dist/web/assets/app.js +3 -3
  7. package/core/dist/runtime/adversarial-loop.d.ts +8 -0
  8. package/core/dist/runtime/adversarial-loop.d.ts.map +1 -1
  9. package/core/dist/runtime/adversarial-loop.js +420 -45
  10. package/core/dist/runtime/adversarial-loop.js.map +1 -1
  11. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js +3 -3
  12. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js.map +1 -1
  13. package/core/dist/runtime/feature-flags/plugin-surface-registry.d.ts.map +1 -1
  14. package/core/dist/runtime/feature-flags/plugin-surface-registry.js +0 -16
  15. package/core/dist/runtime/feature-flags/plugin-surface-registry.js.map +1 -1
  16. package/core/dist/runtime/index.d.ts +4 -0
  17. package/core/dist/runtime/index.d.ts.map +1 -1
  18. package/core/dist/runtime/index.js +10 -0
  19. package/core/dist/runtime/index.js.map +1 -1
  20. package/core/dist/runtime/internalization/artificer-runner.d.ts +9 -0
  21. package/core/dist/runtime/internalization/artificer-runner.d.ts.map +1 -1
  22. package/core/dist/runtime/internalization/artificer-runner.js +52 -0
  23. package/core/dist/runtime/internalization/artificer-runner.js.map +1 -1
  24. package/core/dist/runtime/internalization/correlation-lineage.d.ts +16 -3
  25. package/core/dist/runtime/internalization/correlation-lineage.d.ts.map +1 -1
  26. package/core/dist/runtime/internalization/correlation-lineage.js +4 -4
  27. package/core/dist/runtime/internalization/correlation-lineage.js.map +1 -1
  28. package/core/dist/runtime/internalization/evaluator-runner.d.ts +35 -0
  29. package/core/dist/runtime/internalization/evaluator-runner.d.ts.map +1 -1
  30. package/core/dist/runtime/internalization/evaluator-runner.js +390 -91
  31. package/core/dist/runtime/internalization/evaluator-runner.js.map +1 -1
  32. package/core/dist/runtime/internalization/internalization-orchestrator.d.ts +40 -13
  33. package/core/dist/runtime/internalization/internalization-orchestrator.d.ts.map +1 -1
  34. package/core/dist/runtime/internalization/internalization-orchestrator.js +520 -199
  35. package/core/dist/runtime/internalization/internalization-orchestrator.js.map +1 -1
  36. package/core/dist/runtime/internalization/internalization-transition-decision.js +1 -1
  37. package/core/dist/runtime/internalization/internalization-transition-decision.js.map +1 -1
  38. package/core/dist/runtime/internalization/owner-resolution-service.d.ts.map +1 -1
  39. package/core/dist/runtime/internalization/owner-resolution-service.js +10 -8
  40. package/core/dist/runtime/internalization/owner-resolution-service.js.map +1 -1
  41. package/core/dist/runtime/internalization/owner-review.d.ts +2 -0
  42. package/core/dist/runtime/internalization/owner-review.d.ts.map +1 -1
  43. package/core/dist/runtime/internalization/owner-review.js +17 -11
  44. package/core/dist/runtime/internalization/owner-review.js.map +1 -1
  45. package/core/dist/runtime/internalization/peer-runner-contracts.d.ts +2 -0
  46. package/core/dist/runtime/internalization/peer-runner-contracts.d.ts.map +1 -1
  47. package/core/dist/runtime/internalization/peer-runner-contracts.js.map +1 -1
  48. package/core/dist/runtime/internalization/pitask-metadata.d.ts +36 -1
  49. package/core/dist/runtime/internalization/pitask-metadata.d.ts.map +1 -1
  50. package/core/dist/runtime/internalization/pitask-metadata.js +23 -2
  51. package/core/dist/runtime/internalization/pitask-metadata.js.map +1 -1
  52. package/core/dist/runtime/internalization/repair-create.d.ts +73 -0
  53. package/core/dist/runtime/internalization/repair-create.d.ts.map +1 -0
  54. package/core/dist/runtime/internalization/repair-create.js +200 -0
  55. package/core/dist/runtime/internalization/repair-create.js.map +1 -0
  56. package/core/dist/runtime/internalization/repair-lineage-backfill.d.ts +94 -0
  57. package/core/dist/runtime/internalization/repair-lineage-backfill.d.ts.map +1 -0
  58. package/core/dist/runtime/internalization/repair-lineage-backfill.js +123 -0
  59. package/core/dist/runtime/internalization/repair-lineage-backfill.js.map +1 -0
  60. package/core/dist/runtime/internalization/repair-task-identity.d.ts +99 -4
  61. package/core/dist/runtime/internalization/repair-task-identity.d.ts.map +1 -1
  62. package/core/dist/runtime/internalization/repair-task-identity.js +225 -7
  63. package/core/dist/runtime/internalization/repair-task-identity.js.map +1 -1
  64. package/core/dist/runtime/internalization/revision-reopen.d.ts +56 -1
  65. package/core/dist/runtime/internalization/revision-reopen.d.ts.map +1 -1
  66. package/core/dist/runtime/internalization/revision-reopen.js +82 -39
  67. package/core/dist/runtime/internalization/revision-reopen.js.map +1 -1
  68. package/core/dist/runtime/internalization/rollout-reviewer-runner.d.ts +0 -7
  69. package/core/dist/runtime/internalization/rollout-reviewer-runner.d.ts.map +1 -1
  70. package/core/dist/runtime/internalization/rollout-reviewer-runner.js +13 -68
  71. package/core/dist/runtime/internalization/rollout-reviewer-runner.js.map +1 -1
  72. package/core/dist/runtime/internalization/successor-create.d.ts +69 -0
  73. package/core/dist/runtime/internalization/successor-create.d.ts.map +1 -0
  74. package/core/dist/runtime/internalization/successor-create.js +173 -0
  75. package/core/dist/runtime/internalization/successor-create.js.map +1 -0
  76. package/core/dist/runtime/internalization/successor-lookup.d.ts +50 -0
  77. package/core/dist/runtime/internalization/successor-lookup.d.ts.map +1 -0
  78. package/core/dist/runtime/internalization/successor-lookup.js +213 -0
  79. package/core/dist/runtime/internalization/successor-lookup.js.map +1 -0
  80. package/core/dist/runtime/runner/succeeded-result-recovery.d.ts +58 -0
  81. package/core/dist/runtime/runner/succeeded-result-recovery.d.ts.map +1 -0
  82. package/core/dist/runtime/runner/succeeded-result-recovery.js +117 -0
  83. package/core/dist/runtime/runner/succeeded-result-recovery.js.map +1 -0
  84. package/core/dist/runtime/store/runtime-state-manager.d.ts +1 -0
  85. package/core/dist/runtime/store/runtime-state-manager.d.ts.map +1 -1
  86. package/core/dist/runtime/store/runtime-state-manager.js +4 -0
  87. package/core/dist/runtime/store/runtime-state-manager.js.map +1 -1
  88. package/core/dist/runtime/store/task/memory-task-store.d.ts +3 -3
  89. package/core/dist/runtime/store/task/memory-task-store.d.ts.map +1 -1
  90. package/core/dist/runtime/store/task/memory-task-store.js +52 -0
  91. package/core/dist/runtime/store/task/memory-task-store.js.map +1 -1
  92. package/core/dist/runtime/store/task/sqlite-task-store.d.ts +3 -0
  93. package/core/dist/runtime/store/task/sqlite-task-store.d.ts.map +1 -1
  94. package/core/dist/runtime/store/task/sqlite-task-store.js +204 -135
  95. package/core/dist/runtime/store/task/sqlite-task-store.js.map +1 -1
  96. package/core/dist/runtime/store/task/task-store.d.ts +17 -0
  97. package/core/dist/runtime/store/task/task-store.d.ts.map +1 -1
  98. package/core/dist/telemetry-event.d.ts +2 -2
  99. package/core/dist/telemetry-event.d.ts.map +1 -1
  100. package/core/dist/telemetry-event.js +4 -0
  101. package/core/dist/telemetry-event.js.map +1 -1
  102. package/core/package.json +1 -1
  103. package/dist/index.js +1 -1
  104. package/dist/index.js.map +1 -1
  105. package/dist/installer.d.ts +69 -11
  106. package/dist/installer.d.ts.map +1 -1
  107. package/dist/installer.js +432 -120
  108. package/dist/installer.js.map +1 -1
  109. package/dist/service-host-bridge.d.ts +0 -5
  110. package/dist/service-host-bridge.d.ts.map +1 -1
  111. package/dist/service-host-bridge.js.map +1 -1
  112. package/dist/service-host-provisioning.d.ts +123 -18
  113. package/dist/service-host-provisioning.d.ts.map +1 -1
  114. package/dist/service-host-provisioning.js +645 -77
  115. package/dist/service-host-provisioning.js.map +1 -1
  116. package/dist/utils/env.d.ts +9 -0
  117. package/dist/utils/env.d.ts.map +1 -1
  118. package/dist/utils/env.js +269 -49
  119. package/dist/utils/env.js.map +1 -1
  120. package/host-runtime/dist/codex-worker-status.d.ts +6 -4
  121. package/host-runtime/dist/codex-worker-status.js +7 -5
  122. package/host-runtime/dist/diagnostician-auto-run.js +2 -2
  123. package/host-runtime/dist/governance-signal-admission.d.ts +2 -1
  124. package/host-runtime/dist/governance-signal-admission.js +2 -1
  125. package/host-runtime/dist/index.d.ts +4 -2
  126. package/host-runtime/dist/index.js +6 -2
  127. package/host-runtime/dist/internalization-consumer-cycle.d.ts +13 -106
  128. package/host-runtime/dist/internalization-consumer-cycle.js +21 -99
  129. package/host-runtime/dist/internalization-consumer-governance.d.ts +3 -3
  130. package/host-runtime/dist/internalization-consumer-governance.js +17 -96
  131. package/host-runtime/dist/internalization-task-executor.d.ts +127 -0
  132. package/host-runtime/dist/internalization-task-executor.js +121 -0
  133. package/host-runtime/dist/workbuddy-worker-status.d.ts +6 -3
  134. package/host-runtime/dist/workbuddy-worker-status.js +7 -4
  135. package/host-runtime/dist/workspace-telemetry-emitter.js +1 -1
  136. package/host-runtime/package.json +1 -1
  137. package/install-layout/dist/background-execution-transition.d.ts +25 -29
  138. package/install-layout/dist/background-execution-transition.js +90 -138
  139. package/install-layout/dist/index.d.ts +45 -33
  140. package/install-layout/dist/index.js +24 -18
  141. package/install-layout/package.json +1 -1
  142. package/package.json +5 -4
  143. package/pd-cli/dist/commands/codex-worker.d.ts +7 -3
  144. package/pd-cli/dist/commands/codex-worker.d.ts.map +1 -1
  145. package/pd-cli/dist/commands/codex-worker.js +125 -101
  146. package/pd-cli/dist/commands/codex-worker.js.map +1 -1
  147. package/pd-cli/dist/commands/runtime-internalization-enqueue-successors.d.ts.map +1 -1
  148. package/pd-cli/dist/commands/runtime-internalization-enqueue-successors.js +148 -130
  149. package/pd-cli/dist/commands/runtime-internalization-enqueue-successors.js.map +1 -1
  150. package/pd-cli/dist/commands/runtime-internalization-run-once.d.ts.map +1 -1
  151. package/pd-cli/dist/commands/runtime-internalization-run-once.js +4 -0
  152. package/pd-cli/dist/commands/runtime-internalization-run-once.js.map +1 -1
  153. package/pd-cli/dist/commands/runtime-internalization-run-rulehost.js +1 -1
  154. package/pd-cli/dist/commands/runtime-internalization-run-rulehost.js.map +1 -1
  155. package/pd-cli/dist/commands/service-run-once.d.ts +12 -27
  156. package/pd-cli/dist/commands/service-run-once.d.ts.map +1 -1
  157. package/pd-cli/dist/commands/service-run-once.js +15 -206
  158. package/pd-cli/dist/commands/service-run-once.js.map +1 -1
  159. package/pd-cli/dist/commands/workbuddy-worker.d.ts +7 -2
  160. package/pd-cli/dist/commands/workbuddy-worker.d.ts.map +1 -1
  161. package/pd-cli/dist/commands/workbuddy-worker.js +133 -99
  162. package/pd-cli/dist/commands/workbuddy-worker.js.map +1 -1
  163. package/pd-cli/dist/commands/worker-service-host-gate.d.ts +38 -0
  164. package/pd-cli/dist/commands/worker-service-host-gate.d.ts.map +1 -0
  165. package/pd-cli/dist/commands/worker-service-host-gate.js +110 -0
  166. package/pd-cli/dist/commands/worker-service-host-gate.js.map +1 -0
  167. package/pd-cli/dist/program.d.ts.map +1 -1
  168. package/pd-cli/dist/program.js +20 -84
  169. package/pd-cli/dist/program.js.map +1 -1
  170. package/pd-cli/dist/services/rulehost-pipeline-runner.d.ts.map +1 -1
  171. package/pd-cli/dist/services/rulehost-pipeline-runner.js +198 -142
  172. package/pd-cli/dist/services/rulehost-pipeline-runner.js.map +1 -1
  173. package/pd-cli/dist/services/service-host/coordinator-common.d.ts.map +1 -1
  174. package/pd-cli/dist/services/service-host/coordinator-common.js +4 -5
  175. package/pd-cli/dist/services/service-host/coordinator-common.js.map +1 -1
  176. package/pd-cli/dist/services/service-host/index.d.ts +7 -10
  177. package/pd-cli/dist/services/service-host/index.d.ts.map +1 -1
  178. package/pd-cli/dist/services/service-host/index.js +8 -11
  179. package/pd-cli/dist/services/service-host/index.js.map +1 -1
  180. package/pd-cli/dist/services/service-host/install-identity.d.ts +5 -5
  181. package/pd-cli/dist/services/service-host/managed-run.d.ts.map +1 -1
  182. package/pd-cli/dist/services/service-host/managed-run.js +19 -22
  183. package/pd-cli/dist/services/service-host/managed-run.js.map +1 -1
  184. package/pd-cli/dist/services/service-host/scheduler/linux.d.ts.map +1 -1
  185. package/pd-cli/dist/services/service-host/scheduler/linux.js +21 -2
  186. package/pd-cli/dist/services/service-host/scheduler/linux.js.map +1 -1
  187. package/pd-cli/dist/services/service-host/scheduler/service-status.d.ts +1 -1
  188. package/pd-cli/dist/services/service-host/scheduler/service-status.d.ts.map +1 -1
  189. package/pd-cli/dist/services/service-host/scheduler/service-status.js +0 -2
  190. package/pd-cli/dist/services/service-host/scheduler/service-status.js.map +1 -1
  191. package/pd-cli/dist/services/service-host/status/service-run-status.d.ts +7 -51
  192. package/pd-cli/dist/services/service-host/status/service-run-status.d.ts.map +1 -1
  193. package/pd-cli/dist/services/service-host/status/service-run-status.js.map +1 -1
  194. package/pd-cli/dist/services/service-host/worker-adapter-openclaw.js +3 -3
  195. package/pd-cli/dist/services/service-host/worker-adapter.d.ts +0 -10
  196. package/pd-cli/dist/services/service-host/worker-adapter.d.ts.map +1 -1
  197. package/pd-cli/dist/services/service-host/worker-adapter.js +4 -12
  198. package/pd-cli/dist/services/service-host/worker-adapter.js.map +1 -1
  199. package/pd-cli/dist/services/service-host/worker-env.d.ts +1 -1
  200. package/pd-cli/dist/services/service-host/workspace-dispatch.d.ts +5 -7
  201. package/pd-cli/dist/services/service-host/workspace-dispatch.d.ts.map +1 -1
  202. package/pd-cli/dist/services/service-host/workspace-dispatch.js +1 -3
  203. package/pd-cli/dist/services/service-host/workspace-dispatch.js.map +1 -1
  204. package/pd-cli/package.json +1 -1
  205. package/plugin/dist/bundle.js +616 -1319
  206. package/plugin/dist/core/openclaw-tool-declaration.d.ts +13 -0
  207. package/plugin/dist/index.d.ts +0 -9
  208. package/plugin/dist/openclaw-worker.d.ts +21 -8
  209. package/plugin/dist/openclaw-worker.js +267 -267
  210. package/plugin/dist/openclaw.plugin.json +1 -1
  211. package/plugin/openclaw.plugin.json +1 -1
  212. package/plugin/package.json +1 -1
  213. package/release-manager/dist/installer.js +432 -120
  214. package/release-manager/dist/service-host-provisioning.js +645 -77
  215. package/release-manager/dist/utils/env.js +269 -49
  216. package/release-manager/package.json +3 -2
  217. package/workbuddy-adapter/dist/worker/workspace-worker.d.ts +9 -1
  218. package/workbuddy-adapter/dist/worker/workspace-worker.js +21 -9
  219. package/workbuddy-adapter/package.json +1 -1
  220. package/pd-cli/dist/commands/service-handover.d.ts +0 -12
  221. package/pd-cli/dist/commands/service-handover.d.ts.map +0 -1
  222. package/pd-cli/dist/commands/service-handover.js +0 -117
  223. package/pd-cli/dist/commands/service-handover.js.map +0 -1
  224. package/pd-cli/dist/commands/worker-drain.d.ts +0 -7
  225. package/pd-cli/dist/commands/worker-drain.d.ts.map +0 -1
  226. package/pd-cli/dist/commands/worker-drain.js +0 -51
  227. package/pd-cli/dist/commands/worker-drain.js.map +0 -1
  228. package/pd-cli/dist/services/service-host/handover-claims.d.ts +0 -14
  229. package/pd-cli/dist/services/service-host/handover-claims.d.ts.map +0 -1
  230. package/pd-cli/dist/services/service-host/handover-claims.js +0 -50
  231. package/pd-cli/dist/services/service-host/handover-claims.js.map +0 -1
  232. package/pd-cli/dist/services/service-host/shadow-run.d.ts +0 -87
  233. package/pd-cli/dist/services/service-host/shadow-run.d.ts.map +0 -1
  234. package/pd-cli/dist/services/service-host/shadow-run.js +0 -549
  235. package/pd-cli/dist/services/service-host/shadow-run.js.map +0 -1
  236. package/pd-cli/dist/services/service-host/workspace-handover.d.ts +0 -190
  237. package/pd-cli/dist/services/service-host/workspace-handover.d.ts.map +0 -1
  238. package/pd-cli/dist/services/service-host/workspace-handover.js +0 -1393
  239. package/pd-cli/dist/services/service-host/workspace-handover.js.map +0 -1
  240. package/plugin/dist/service/gateway-consumer-lease.d.ts +0 -142
  241. package/plugin/dist/service/gateway-quiesce-ack.d.ts +0 -40
  242. package/plugin/dist/service/internalization-auto-consumer-service.d.ts +0 -100
@@ -0,0 +1,200 @@
1
+ /**
2
+ * repair-create.ts — Repair task creation 的唯一权威 (PRI-1299 Phase 1 / OD-1).
3
+ *
4
+ * 两个生产入口 (host-runtime consumer governance、pd-cli RuleHost runner)
5
+ * 必须只做参数装配与错误映射; repair identity、reuse adjudication、lineage
6
+ * proof、insert 和 UNIQUE-race re-arbitration 全部收敛到本模块。
7
+ *
8
+ * RepairSuccessorIdentity = (sourceEvaluatorTaskId, taskKind='artificer',
9
+ * channel, repairIteration)。channel 是 mandatory consistency dimension:
10
+ * mismatch fail closed,不得成为创建第二行 repair 的理由。R1/R2 拥有不同
11
+ * repairIteration,因此合法共存;同一 identity 的复用必须先验证完整 payload。
12
+ */
13
+ import { canonicalStringify } from './artifact-content-hash.js';
14
+ import { resolveAuthoritativeCorrelationId } from './correlation-lineage.js';
15
+ import { validateAndBackfillRepairLineage } from './repair-lineage-backfill.js';
16
+ import { verifyRepairTaskIdentity } from './repair-task-identity.js';
17
+ import { artificerRepairTaskId, createPITaskDiagnosticJson, hydratePITaskRecord, isValidRepairPayload, } from './pitask-metadata.js';
18
+ /**
19
+ * Backward-compatible host error text for a failed creation/adoption outcome.
20
+ * host-runtime and pd-cli intentionally preserve their legacy throw-based
21
+ * seeder contract; keeping this pure mapping beside the authority prevents
22
+ * drift while leaving recovery classification unchanged.
23
+ */
24
+ export function repairSeedErrorMessage(result) {
25
+ if (result.reason === 'concurrent_modification') {
26
+ return `evaluator_repair_seed_concurrent_modification: repair task ${result.task?.taskId ?? 'unknown'} changed during lineage backfill — seed NOT applied, safe to retry`;
27
+ }
28
+ if (result.reason === 'terminal_repair_task')
29
+ return result.detail;
30
+ if (result.failureStage !== 'adoption' && result.reason === 'repair_source_evaluator_missing') {
31
+ return `evaluator_repair_seed_lineage_refused: ${result.detail}`;
32
+ }
33
+ if (result.failureStage !== 'adoption' && result.reason === 'repair_source_lineage_unprovable') {
34
+ return `evaluator_repair_seed_lineage_refused:${result.detail}`;
35
+ }
36
+ return `evaluator_repair_seed_lineage_refused:${result.reason}:${result.detail}`;
37
+ }
38
+ // eslint-disable-next-line @typescript-eslint/max-params -- optional provenance discriminator keeps legacy error mapping local without widening the request object.
39
+ function fail(reason, detail, task, failureStage) {
40
+ return task === undefined
41
+ ? { outcome: 'fail_closed', reason, detail, ...(failureStage !== undefined ? { failureStage } : {}) }
42
+ : { outcome: 'fail_closed', reason, detail, task, ...(failureStage !== undefined ? { failureStage } : {}) };
43
+ }
44
+ // eslint-disable-next-line @typescript-eslint/max-params -- optional provenance discriminator keeps legacy error mapping local without widening the request object.
45
+ function conflict(reason, detail, task, failureStage) {
46
+ return task === undefined
47
+ ? { outcome: 'conflict', reason, detail, ...(failureStage !== undefined ? { failureStage } : {}) }
48
+ : { outcome: 'conflict', reason, detail, task, ...(failureStage !== undefined ? { failureStage } : {}) };
49
+ }
50
+ function isTerminalRepairTask(task) {
51
+ return task.status === 'succeeded' || task.status === 'failed' || task.status === 'needs_human_review';
52
+ }
53
+ function isUniqueViolation(error) {
54
+ const message = error instanceof Error ? error.message : String(error);
55
+ return message.includes('UNIQUE constraint') || message.includes('PRIMARY KEY') || message.includes('already exists');
56
+ }
57
+ function samePayload(existing, requested) {
58
+ if (existing === undefined)
59
+ return false;
60
+ const left = canonicalStringify(existing);
61
+ const right = canonicalStringify(requested);
62
+ if (left.truncated || right.truncated)
63
+ return 'unbounded';
64
+ return left.text === right.text;
65
+ }
66
+ /**
67
+ * 复用已有 deterministic-id repair。任何 payload/channel/lineage 不符都
68
+ * fail closed;只有 identity 与 payload 完全一致的在途任务可以 adopted。
69
+ */
70
+ async function adoptExistingRepairTask(input) {
71
+ const { store, existing, params, repairTaskId } = input;
72
+ if (isTerminalRepairTask(existing)) {
73
+ return conflict('terminal_repair_task', `repair task ${repairTaskId} already reached terminal status ${existing.status}; refusing to reuse it as new corrective work (PRI-718 revise-ne-resume)`, existing, 'adoption');
74
+ }
75
+ const identity = await verifyRepairTaskIdentity(existing, params.repairPayload.sourceEvaluatorTaskId, params.repairPayload.repairIteration, store);
76
+ if (!identity.ok) {
77
+ return fail(identity.reason, identity.detail, existing, 'adoption');
78
+ }
79
+ const pi = hydratePITaskRecord(existing);
80
+ if (!pi) {
81
+ return fail('repair_identity_unreadable_metadata', `task=${repairTaskId}`, existing, 'adoption');
82
+ }
83
+ if (pi.channel !== params.inheritedChannel) {
84
+ return fail('repair_channel_mismatch', `task=${repairTaskId};channel=${pi.channel};requested_channel=${params.inheritedChannel}`, existing, 'adoption');
85
+ }
86
+ const payloadMatch = samePayload(pi.repairPayload, params.repairPayload);
87
+ if (payloadMatch === 'unbounded') {
88
+ return fail('repair_payload_unbounded', `task=${repairTaskId};payload exceeds canonical comparison budget`, existing, 'adoption');
89
+ }
90
+ if (!payloadMatch) {
91
+ return conflict('repair_payload_mismatch', `task=${repairTaskId};persisted repair payload differs from requested payload`, existing, 'adoption');
92
+ }
93
+ if (!identity.needsLineageBackfill) {
94
+ return { outcome: 'adopted_existing', task: existing, backfilled: false };
95
+ }
96
+ const lineage = await validateAndBackfillRepairLineage({
97
+ repairTaskId,
98
+ existing,
99
+ sourceEvaluatorTaskId: params.repairPayload.sourceEvaluatorTaskId,
100
+ repairIteration: params.repairPayload.repairIteration,
101
+ }, store);
102
+ if (!lineage.ok) {
103
+ if (lineage.reason === 'concurrent_modification') {
104
+ return conflict('concurrent_modification', lineage.detail, existing, 'adoption');
105
+ }
106
+ return fail(lineage.reason, lineage.detail, existing, 'adoption');
107
+ }
108
+ const adopted = lineage.backfilled ? await store.getTask(repairTaskId) : existing;
109
+ if (adopted === null) {
110
+ return fail('repair_task_disappeared_after_backfill', `task=${repairTaskId}`, undefined, 'adoption');
111
+ }
112
+ return {
113
+ outcome: 'adopted_existing',
114
+ task: adopted,
115
+ backfilled: lineage.backfilled,
116
+ };
117
+ }
118
+ async function proveRepairLineage(store, params) {
119
+ const sourceTask = await store.getTask(params.repairPayload.sourceEvaluatorTaskId);
120
+ if (sourceTask === null) {
121
+ return { ok: false, reason: 'repair_source_evaluator_missing', detail: `source evaluator task ${params.repairPayload.sourceEvaluatorTaskId} not found` };
122
+ }
123
+ if (sourceTask.taskKind !== 'evaluator') {
124
+ return { ok: false, reason: 'repair_source_not_evaluator', detail: `source=${params.repairPayload.sourceEvaluatorTaskId};kind=${sourceTask.taskKind}` };
125
+ }
126
+ const sourcePi = hydratePITaskRecord(sourceTask);
127
+ if (!sourcePi) {
128
+ return { ok: false, reason: 'repair_source_unreadable_metadata', detail: `source=${params.repairPayload.sourceEvaluatorTaskId}` };
129
+ }
130
+ if (sourcePi.channel !== params.inheritedChannel) {
131
+ return {
132
+ ok: false,
133
+ reason: 'repair_channel_mismatch',
134
+ detail: `source=${params.repairPayload.sourceEvaluatorTaskId};source_channel=${sourcePi.channel};requested_channel=${params.inheritedChannel}`,
135
+ };
136
+ }
137
+ const lineage = await resolveAuthoritativeCorrelationId(sourceTask, (taskId) => store.getTask(taskId));
138
+ if (!lineage.ok) {
139
+ return { ok: false, reason: lineage.reason, detail: lineage.detail };
140
+ }
141
+ return { ok: true, correlationId: lineage.correlationId };
142
+ }
143
+ /**
144
+ * Create or adopt the unique repair task for one RepairSuccessorIdentity.
145
+ *
146
+ * 所有 read-check-write 都在 store 的 write transaction 内执行;SQLite
147
+ * BEGIN IMMEDIATE 将跨连接 seeding serialize。UNIQUE race 必须重新仲裁为
148
+ * adopted/conflict/fail_closed,不得冒泡成 generic seed failure。
149
+ */
150
+ export async function createRepairTask(store, params) {
151
+ return store.withWriteTransaction(async () => {
152
+ if (!isValidRepairPayload(params.repairPayload)) {
153
+ return fail('malformed_repair_payload', 'repairPayload failed structural validation');
154
+ }
155
+ const repairTaskId = artificerRepairTaskId(params.repairPayload.sourceEvaluatorTaskId, params.repairPayload.repairIteration);
156
+ const existing = await store.getTask(repairTaskId);
157
+ if (existing !== null) {
158
+ return adoptExistingRepairTask({ store, existing, params, repairTaskId });
159
+ }
160
+ const lineage = await proveRepairLineage(store, params);
161
+ if (!lineage.ok) {
162
+ return fail(lineage.reason, lineage.detail);
163
+ }
164
+ try {
165
+ const task = await store.createTask({
166
+ taskId: repairTaskId,
167
+ taskKind: 'artificer',
168
+ status: 'pending',
169
+ attemptCount: 0,
170
+ maxAttempts: 3,
171
+ diagnosticJson: createPITaskDiagnosticJson({
172
+ dependencyTaskIds: [...params.inheritedDependencyTaskIds],
173
+ channel: params.inheritedChannel,
174
+ pipelineMode: params.inheritedPipelineMode,
175
+ timeoutMs: params.inheritedTimeoutMs,
176
+ inputArtifactRefs: [...params.inheritedInputArtifactRefs],
177
+ outputArtifactRefs: [],
178
+ parentTaskId: params.repairPayload.sourceEvaluatorTaskId,
179
+ correlationId: lineage.correlationId,
180
+ ...(params.ownerEvidenceSelection !== undefined
181
+ ? { ownerEvidenceSelection: params.ownerEvidenceSelection }
182
+ : {}),
183
+ repairPayload: params.repairPayload,
184
+ repairTaskRole: 'repair_artificer',
185
+ }),
186
+ });
187
+ return { outcome: 'created', task };
188
+ }
189
+ catch (error) {
190
+ if (!isUniqueViolation(error))
191
+ throw error;
192
+ const raced = await store.getTask(repairTaskId);
193
+ if (raced === null) {
194
+ return fail('unique_violation_without_verified_repair', `task=${repairTaskId};insert collided but no repair row is visible`);
195
+ }
196
+ return adoptExistingRepairTask({ store, existing: raced, params, repairTaskId });
197
+ }
198
+ });
199
+ }
200
+ //# sourceMappingURL=repair-create.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repair-create.js","sourceRoot":"","sources":["../../../src/runtime/internalization/repair-create.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAGhE,OAAO,EAAE,iCAAiC,EAAE,MAAM,0BAA0B,CAAC;AAE7E,OAAO,EAAE,gCAAgC,EAAE,MAAM,8BAA8B,CAAC;AAChF,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EACL,qBAAqB,EACrB,0BAA0B,EAC1B,mBAAmB,EACnB,oBAAoB,GAErB,MAAM,sBAAsB,CAAC;AAkC9B;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAAmC;IACxE,IAAI,MAAM,CAAC,MAAM,KAAK,yBAAyB,EAAE,CAAC;QAChD,OAAO,8D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0 +1,94 @@
1
+ /**
2
+ * repair-lineage-backfill.ts — Repair 任务血缘校验 + 六项快照前提 CAS 回填的
3
+ * 唯一写侧实现 (PRI-1300)。
4
+ *
5
+ * 三个生产消费方共享同一规则 (禁止各自演化):
6
+ * 1. host-runtime Repair Seeder 复用路径;
7
+ * 2. pd-cli RuleHost Repair Seeder 复用路径;
8
+ * 3. orchestrator REOPEN_SOURCE_EVALUATOR 分支 (repair 完成后修改来源
9
+ * Evaluator 之前的身份前置验证 + 回填)。
10
+ *
11
+ * 本模块组合 (而非复制) 两个既有权威:
12
+ * - verifyRepairTaskIdentity (repair-task-identity.ts): 只读完整身份验证 —
13
+ * payload 存在 + 来源/iteration 一致 + taskId 互证 + 来源 Evaluator 真实
14
+ * + parent/correlation 一致 + channel 一致;
15
+ * - 六项快照前提 CAS (diagnosticJson + status/attemptCount/maxAttempts/
16
+ * leaseOwner/leaseExpiresAt/leaseGeneration): 缺失亲缘字段的安全补齐。
17
+ *
18
+ * fail-closed 边界与 verifyRepairTaskIdentity 相同: payload 身份不符一律拒绝,
19
+ * 仅 parentTaskId/correlationId 缺失且来源已证明时经 CAS 补齐。CAS 落败 =
20
+ * 并发修改, 返回结构化 concurrent_modification — 零部分写入 (单条条件 UPDATE
21
+ * 要么整体应用要么整体不应用), 调用方安全重试。
22
+ *
23
+ * 本模块不写日志、不抛宿主包装错误: 结构化结果的 reason/detail 沿用
24
+ * verifyRepairTaskIdentity 的既有词汇, 宿主层负责逐字映射为既有 throw 字符串
25
+ * (evaluator_repair_seed_lineage_refused:... /
26
+ * evaluator_repair_seed_concurrent_modification:...) 或 orchestrator 决策。
27
+ */
28
+ import type { TaskRecord } from '../task-status.js';
29
+ import type { TaskStoreUpdatePatch } from '../store/task/task-store.js';
30
+ import type { CorrelationLineageTaskStore } from './correlation-lineage.js';
31
+ /**
32
+ * 血缘回填对任务存储的最窄需求 — 不得传入整个宿主对象:
33
+ * - getTask / listTasks: 权威血缘解析的只读取证面 (见
34
+ * CorrelationLineageTaskStore; listTasks 供 legacy adversarial round≥2
35
+ * 链的唯一前置 Evaluator 推断, 非推测性暴露);
36
+ * - updateTaskIfDiagnosticJsonUnchanged: 回填唯一写路径 (单条条件 UPDATE,
37
+ * 六项快照前提不满足则整体不应用)。
38
+ * RuntimeStateManager 结构满足本接口 — 宿主注入既有实例即可。
39
+ */
40
+ export interface RepairLineageBackfillStore extends CorrelationLineageTaskStore {
41
+ updateTaskIfDiagnosticJsonUnchanged(taskId: string, expectedDiagnosticJson: string | null, patch: TaskStoreUpdatePatch, options?: {
42
+ readonly expectedStatus?: string;
43
+ readonly expectedAttemptCount?: number;
44
+ readonly expectedMaxAttempts?: number;
45
+ readonly expectedLeaseOwner?: string | null;
46
+ readonly expectedLeaseExpiresAt?: string | null;
47
+ readonly expectedLeaseGeneration?: number;
48
+ }): Promise<TaskRecord | null>;
49
+ }
50
+ export interface ValidateAndBackfillRepairLineageParams {
51
+ /** 确定性 repair 任务 id (artificerRepairTaskId 派生) — 回填 CAS 的目标行。 */
52
+ readonly repairTaskId: string;
53
+ /** 复用/完成路径读到的 repair 任务行 — 身份验证与六项 CAS 前提的快照来源。 */
54
+ readonly existing: TaskRecord;
55
+ /** 请求侧来源 Evaluator (seeder 参数或 payload 自证值)。 */
56
+ readonly sourceEvaluatorTaskId: string;
57
+ /** 请求侧 iteration。 */
58
+ readonly repairIteration: number;
59
+ }
60
+ /**
61
+ * 结构化判别联合。失败 reason 词汇:
62
+ * - verifyRepairTaskIdentity 的全部 reason 原样透传
63
+ * (repair_identity_not_artificer / repair_payload_missing /
64
+ * repair_payload_source_mismatch / repair_payload_iteration_mismatch /
65
+ * repair_task_id_payload_mismatch / repair_source_evaluator_missing /
66
+ * repair_source_not_evaluator / repair_source_unreadable_metadata /
67
+ * repair_parent_conflicts_payload_source / repair_source_lineage_unprovable /
68
+ * repair_correlation_conflicts_authoritative / repair_channel_mismatch /
69
+ * repair_identity_unreadable_metadata);
70
+ * - 'repair_task_id_mismatch': params.repairTaskId 与 existing.taskId
71
+ * 不一致 — 验证行与写目标不是同一行, fail fast 零写入;
72
+ * - 'invalid_task_metadata': 验证通过后 diagnosticJson 根文档不可解析
73
+ * 或 merge 前提 hydrate 失败 (防御性分支);
74
+ * - 'concurrent_modification': 回填 CAS 落败 — 任务在读取后被并发触碰,
75
+ * 零写入, 调用方安全重试。
76
+ */
77
+ export type RepairLineageBackfillResult = {
78
+ readonly ok: true;
79
+ /** true = 本次调用经 CAS 补齐了缺失的 parent/correlation; false = 血缘已完整, 零写入。 */
80
+ readonly backfilled: boolean;
81
+ /** 来源 Evaluator 的权威 correlationId (链经 canonical resolver 验证)。 */
82
+ readonly authoritativeCorrelationId: string;
83
+ } | {
84
+ readonly ok: false;
85
+ readonly reason: string;
86
+ readonly detail: string;
87
+ };
88
+ /**
89
+ * 校验 repair 任务完整身份; 仅在亲缘字段缺失且来源已证明时经六项快照前提
90
+ * CAS 补齐。除该单条条件 UPDATE 外不写任何状态; 任何验证失败或 CAS 落败
91
+ * 都是零写入的结构化拒绝。
92
+ */
93
+ export declare function validateAndBackfillRepairLineage(params: ValidateAndBackfillRepairLineageParams, store: RepairLineageBackfillStore): Promise<RepairLineageBackfillResult>;
94
+ //# sourceMappingURL=repair-lineage-backfill.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repair-lineage-backfill.d.ts","sourceRoot":"","sources":["../../../src/runtime/internalization/repair-lineage-backfill.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAI5E;;;;;;;;GAQG;AACH,MAAM,WAAW,0BAA2B,SAAQ,2BAA2B;IAC7E,mCAAmC,CACjC,MAAM,EAAE,MAAM,EACd,sBAAsB,E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,CAAC,CAoEtC"}
@@ -0,0 +1,123 @@
1
+ /**
2
+ * repair-lineage-backfill.ts — Repair 任务血缘校验 + 六项快照前提 CAS 回填的
3
+ * 唯一写侧实现 (PRI-1300)。
4
+ *
5
+ * 三个生产消费方共享同一规则 (禁止各自演化):
6
+ * 1. host-runtime Repair Seeder 复用路径;
7
+ * 2. pd-cli RuleHost Repair Seeder 复用路径;
8
+ * 3. orchestrator REOPEN_SOURCE_EVALUATOR 分支 (repair 完成后修改来源
9
+ * Evaluator 之前的身份前置验证 + 回填)。
10
+ *
11
+ * 本模块组合 (而非复制) 两个既有权威:
12
+ * - verifyRepairTaskIdentity (repair-task-identity.ts): 只读完整身份验证 —
13
+ * payload 存在 + 来源/iteration 一致 + taskId 互证 + 来源 Evaluator 真实
14
+ * + parent/correlation 一致 + channel 一致;
15
+ * - 六项快照前提 CAS (diagnosticJson + status/attemptCount/maxAttempts/
16
+ * leaseOwner/leaseExpiresAt/leaseGeneration): 缺失亲缘字段的安全补齐。
17
+ *
18
+ * fail-closed 边界与 verifyRepairTaskIdentity 相同: payload 身份不符一律拒绝,
19
+ * 仅 parentTaskId/correlationId 缺失且来源已证明时经 CAS 补齐。CAS 落败 =
20
+ * 并发修改, 返回结构化 concurrent_modification — 零部分写入 (单条条件 UPDATE
21
+ * 要么整体应用要么整体不应用), 调用方安全重试。
22
+ *
23
+ * 本模块不写日志、不抛宿主包装错误: 结构化结果的 reason/detail 沿用
24
+ * verifyRepairTaskIdentity 的既有词汇, 宿主层负责逐字映射为既有 throw 字符串
25
+ * (evaluator_repair_seed_lineage_refused:... /
26
+ * evaluator_repair_seed_concurrent_modification:...) 或 orchestrator 决策。
27
+ */
28
+ import { verifyRepairTaskIdentity } from './repair-task-identity.js';
29
+ import { hydratePITaskRecord, mergePITaskMetadata, createPITaskDiagnosticJson, PI_METADATA_KEY } from './pitask-metadata.js';
30
+ function fail(reason, detail) {
31
+ return { ok: false, reason, detail };
32
+ }
33
+ function isPlainObjectRecord(value) {
34
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
35
+ }
36
+ function parseDiagnosticRoot(diagnosticJson) {
37
+ if (diagnosticJson === null || diagnosticJson.trim() === '')
38
+ return {};
39
+ try {
40
+ const parsed = JSON.parse(diagnosticJson);
41
+ if (!isPlainObjectRecord(parsed))
42
+ return null;
43
+ return parsed;
44
+ }
45
+ catch {
46
+ return null;
47
+ }
48
+ }
49
+ /**
50
+ * 只替换 namespaced pi_metadata 信封, 保留 diagnosticJson 根上的宿主/Runner
51
+ * 诊断键 (lastValidatorErrors / output_failure_details / validator_error_history
52
+ * 等)。backfill 的授权范围是亲缘字段, 不得借整文档重建丢弃无关重试证据。
53
+ */
54
+ function replacePIMetadataEnvelope(existingDiagnosticJson, metadata) {
55
+ const root = parseDiagnosticRoot(existingDiagnosticJson);
56
+ const envelopeRoot = parseDiagnosticRoot(createPITaskDiagnosticJson(metadata));
57
+ const piMetadata = envelopeRoot?.[PI_METADATA_KEY];
58
+ if (root === null || piMetadata === undefined)
59
+ return null;
60
+ return JSON.stringify({ ...root, [PI_METADATA_KEY]: piMetadata });
61
+ }
62
+ /**
63
+ * 校验 repair 任务完整身份; 仅在亲缘字段缺失且来源已证明时经六项快照前提
64
+ * CAS 补齐。除该单条条件 UPDATE 外不写任何状态; 任何验证失败或 CAS 落败
65
+ * 都是零写入的结构化拒绝。
66
+ */
67
+ export async function validateAndBackfillRepairLineage(params, store) {
68
+ // 0. 验证快照与 CAS 目标必须是同一行 — 两个标识分别由调用方传入时
69
+ // 不得静默把 A 行的验证结论写到 B 行。
70
+ if (params.repairTaskId !== params.existing.taskId) {
71
+ return fail('repair_task_id_mismatch', `param=${params.repairTaskId};snapshot=${params.existing.taskId}`);
72
+ }
73
+ // 1. 只读完整身份验证 (与三消费方同一规则 — 单一实现, 不复制)。
74
+ const identity = await verifyRepairTaskIdentity(params.existing, params.sourceEvaluatorTaskId, params.repairIteration, store);
75
+ if (!identity.ok) {
76
+ return fail(identity.reason, identity.detail);
77
+ }
78
+ // 2. merge 前提: hydrate repair metadata (验证通过即可 hydrate — 此分支为
79
+ // 防御性守卫, detail 沿用宿主既有错误语义词汇)。
80
+ const pi = hydratePITaskRecord(params.existing);
81
+ if (!pi) {
82
+ return fail('invalid_task_metadata', `repair task ${params.repairTaskId} diagnosticJson unreadable`);
83
+ }
84
+ // 3. 血缘已完整 — 零写入。
85
+ if (!identity.needsLineageBackfill) {
86
+ return {
87
+ ok: true,
88
+ backfilled: false,
89
+ authoritativeCorrelationId: identity.authoritativeCorrelationId,
90
+ };
91
+ }
92
+ // 4. 缺失亲缘字段按权威来源补齐 — merge 保持其余 metadata 字段, CAS 断言
93
+ // 读取时的完整快照 (diagnosticJson + status/attemptCount/maxAttempts/
94
+ // leaseOwner/leaseExpiresAt/leaseGeneration 六项前提)。verify 已证明任何
95
+ // 非空 parent/correlation 与权威值一致, 故 merge 覆盖不产生语义变更。
96
+ const merged = mergePITaskMetadata(pi, {
97
+ parentTaskId: params.sourceEvaluatorTaskId,
98
+ correlationId: identity.authoritativeCorrelationId,
99
+ repairTaskRole: 'repair_artificer',
100
+ });
101
+ const nextDiagnosticJson = replacePIMetadataEnvelope(params.existing.diagnosticJson ?? null, merged);
102
+ if (nextDiagnosticJson === null) {
103
+ return fail('invalid_task_metadata', `repair task ${params.repairTaskId} diagnosticJson root unreadable`);
104
+ }
105
+ const casResult = await store.updateTaskIfDiagnosticJsonUnchanged(params.repairTaskId, params.existing.diagnosticJson ?? null, { diagnosticJson: nextDiagnosticJson }, {
106
+ expectedStatus: params.existing.status,
107
+ expectedAttemptCount: params.existing.attemptCount,
108
+ expectedMaxAttempts: params.existing.maxAttempts,
109
+ expectedLeaseOwner: params.existing.leaseOwner ?? null,
110
+ expectedLeaseExpiresAt: params.existing.leaseExpiresAt ?? null,
111
+ expectedLeaseGeneration: params.existing.leaseGeneration ?? 0,
112
+ });
113
+ if (casResult === null) {
114
+ // 并发被触碰 — 单条条件 UPDATE 整体未应用, 零部分写入; 调用方安全重试。
115
+ return fail('concurrent_modification', `task=${params.repairTaskId}`);
116
+ }
117
+ return {
118
+ ok: true,
119
+ backfilled: true,
120
+ authoritativeCorrelationId: identity.authoritativeCorrelationId,
121
+ };
122
+ }
123
+ //# sourceMappingURL=repair-lineage-backfill.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repair-lineage-backfill.js","sourceRoot":"","sources":["../../../src/runtime/internalization/repair-lineage-backfill.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAKH,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAiE7H,SAAS,IAAI,CAAC,MAAc,EAAE,MAAc;IAC1C,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AACvC,CAAC;AAED,SAAS,mBAAmB,CAAC,KAAc;IACzC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,mBAAmB,CAAC,cAA6B;IACxD,IAAI,cAAc,KAAK,IAAI,IAAI,cAAc,CAAC,IAAI,EAAE,KAAK,EAAE;QAAE,OAAO,EAAE,CAAC;IACvE,IAAI,CAAC;QACH,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;QACnD,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC;YAAE,OAAO,IAAI,CAAC;QAC9C,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAS,yBAAyB,CAAC,sBAAqC,EAAE,QAA0D;IAClI,MAAM,IAAI,GAAG,mB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C;QAC7C,OAAO,IAAI,CAAC,yBAAyB,EAAE,QAAQ,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC;IACxE,CAAC;IACD,OAAO;QACL,EAAE,EAAE,IAAI;QACR,UAAU,EAAE,IAAI;QAChB,0BAA0B,EAAE,QAAQ,CAAC,0BAA0B;KAChE,CAAC;AACJ,CAAC"}
@@ -1,10 +1,11 @@
1
1
  /**
2
2
  * repair-task-identity.ts — Repair 任务身份完整验证的单一实现 (PRI-1293 R7 P1-1)。
3
3
  *
4
- * 三个生产消费方必须共享同一规则 (禁止各自演化):
4
+ * 生产消费方必须共享同一规则 (禁止各自演化):
5
5
  * 1. host-runtime Repair Seeder 复用前验证;
6
6
  * 2. pd-cli RuleHost Repair Seeder 复用前验证;
7
- * 3. orchestrator REOPEN_SOURCE_EVALUATOR 分支在修改来源 Evaluator 之前验证。
7
+ * 3. orchestrator REOPEN_SOURCE_EVALUATOR 分支在修改来源 Evaluator 之前验证;
8
+ * 4. evaluator/owner 消费 repair dependency 或推断 repair round 之前验证。
8
9
  *
9
10
  * 确定性任务 id (artificerRepairTaskId) 不证明 diagnosticJson 内 repairPayload
10
11
  * 与本次请求一致 — 复用/完成路径都必须重新验证持久化 payload 的完整身份:
@@ -17,7 +18,9 @@
17
18
  * 缺失且来源已证明时可安全补齐 (调用方经既有 CAS 执行, 本模块只读)。
18
19
  */
19
20
  import type { TaskRecord } from '../task-status.js';
20
- import type { RuntimeStateManager } from '../store/runtime-state-manager.js';
21
+ import type { RepairPayload } from './pitask-metadata.js';
22
+ import type { PITaskRecord } from './peer-runner-contracts.js';
23
+ import { type CorrelationLineageTaskStore } from './correlation-lineage.js';
21
24
  export type RepairIdentityVerification = {
22
25
  readonly ok: true;
23
26
  /** 来源 Evaluator 的权威 correlationId (链经 canonical resolver 验证)。 */
@@ -39,5 +42,97 @@ export type RepairIdentityVerification = {
39
42
  * payload 自证值)
40
43
  * @param expectedRepairIteration 请求侧 iteration
41
44
  */
42
- export declare function verifyRepairTaskIdentity(existing: TaskRecord, expectedSourceEvaluatorTaskId: string, expectedRepairIteration: number, stateManager: RuntimeStateManager): Promise<RepairIdentityVerification>;
45
+ export declare function verifyRepairTaskIdentity(existing: TaskRecord, expectedSourceEvaluatorTaskId: string, expectedRepairIteration: number, stateManager: CorrelationLineageTaskStore): Promise<RepairIdentityVerification>;
46
+ export type VerifiedRepairIdentity = Extract<RepairIdentityVerification, {
47
+ readonly ok: true;
48
+ }>;
49
+ export type EvaluatorArtificerDependencyCandidate = {
50
+ readonly class: 'ordinary';
51
+ readonly task: TaskRecord;
52
+ readonly piTask: PITaskRecord;
53
+ } | {
54
+ readonly class: 'legal_repair' | 'legacy_repair';
55
+ readonly task: TaskRecord;
56
+ readonly piTask: PITaskRecord;
57
+ readonly payload: RepairPayload;
58
+ readonly identity: VerifiedRepairIdentity;
59
+ } | {
60
+ readonly class: 'role_only';
61
+ readonly task: TaskRecord;
62
+ readonly piTask: PITaskRecord;
63
+ readonly reason: 'repair_role_payload_missing';
64
+ readonly detail: string;
65
+ } | {
66
+ readonly class: 'malformed';
67
+ readonly dependencyTaskId: string;
68
+ readonly task?: TaskRecord;
69
+ readonly reason: string;
70
+ readonly detail: string;
71
+ } | {
72
+ readonly class: 'unprovable';
73
+ readonly dependencyTaskId: string;
74
+ readonly task?: TaskRecord;
75
+ readonly piTask?: PITaskRecord;
76
+ readonly reason: string;
77
+ readonly detail: string;
78
+ };
79
+ export interface EvaluatorArtificerDependencyScan {
80
+ readonly evaluatorTaskId: string;
81
+ readonly evaluatorMetadataMalformed: boolean;
82
+ readonly candidates: readonly EvaluatorArtificerDependencyCandidate[];
83
+ }
84
+ /**
85
+ * Read-only complete scan of every artificer dependency. Unlike singular input
86
+ * selection, this scan does not stop at the first ordinary or corrupt row: the
87
+ * orchestrator must see all repair-round evidence before reopen can destructively
88
+ * replace the evaluator dependency set.
89
+ */
90
+ export declare function scanEvaluatorArtificerDependencyIdentity(input: {
91
+ readonly evaluatorTask: TaskRecord;
92
+ readonly store: CorrelationLineageTaskStore;
93
+ }): Promise<EvaluatorArtificerDependencyScan>;
94
+ export type EvaluatorArtificerDependencyResolution = {
95
+ readonly kind: 'none';
96
+ } | {
97
+ readonly kind: 'ordinary';
98
+ readonly task: TaskRecord;
99
+ readonly piTask: PITaskRecord;
100
+ } | {
101
+ readonly kind: 'repair';
102
+ readonly task: TaskRecord;
103
+ readonly piTask: PITaskRecord;
104
+ readonly payload: RepairPayload;
105
+ readonly identity: VerifiedRepairIdentity;
106
+ /** payload-valid row whose durable role/parent/correlation is absent but backfillable. */
107
+ readonly legacyRepair: boolean;
108
+ } | {
109
+ readonly kind: 'invalid';
110
+ readonly reason: string;
111
+ readonly detail: string;
112
+ };
113
+ /**
114
+ * Singular adapter for consumers answering "which artifact/input is the evaluator
115
+ * currently bound to?". For that question multiple artificer rows are genuinely
116
+ * ambiguous; stale-round evidence scanning uses scanEvaluatorArtificerDependencyIdentity
117
+ * directly instead.
118
+ */
119
+ export declare function resolveEvaluatorArtificerDependencyIdentity(input: {
120
+ readonly evaluatorTask: TaskRecord;
121
+ readonly store: CorrelationLineageTaskStore;
122
+ }): Promise<EvaluatorArtificerDependencyResolution>;
123
+ export type StaleRepairTransitionPlan = {
124
+ readonly kind: 'clear';
125
+ } | {
126
+ readonly kind: 'superseded';
127
+ } | {
128
+ readonly kind: 'invalid';
129
+ readonly reason: string;
130
+ readonly detail: string;
131
+ };
132
+ /** Pure stale-round adjudication over the complete scan. Ordinary rows are input-chain evidence, not repair-round evidence. */
133
+ export declare function planStaleRepairTransitionFromDependencyScan(input: {
134
+ readonly scan: EvaluatorArtificerDependencyScan;
135
+ readonly completingRepairTaskId: string;
136
+ readonly completingRepairIteration: number;
137
+ }): StaleRepairTransitionPlan;
43
138
  //# sourceMappingURL=repair-task-identity.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"repair-task-identity.d.ts","sourceRoot":"","sources":["../../../src/runtime/internalization/repair-task-identity.ts"],"names":[],"mappings":"AAAA;;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