create-principles-disciple 1.155.3 → 1.156.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 (247) hide show
  1. package/_release/product-identity.json +2 -2
  2. package/codex-adapter/dist/ingestion/pain-receipt-fallback.d.ts +28 -1
  3. package/codex-adapter/dist/ingestion/pain-receipt-fallback.js +53 -17
  4. package/codex-adapter/dist/worker/workspace-worker.js +86 -66
  5. package/codex-adapter/package.json +1 -1
  6. package/console/dist/server/index.d.ts +11 -1
  7. package/console/dist/server/index.js +84 -19
  8. package/console/dist/server/release-handover.d.ts +256 -0
  9. package/console/dist/server/release-handover.js +402 -0
  10. package/console/dist/server/routes/onboarding.js +1 -0
  11. package/console/dist/server/routes/update-transaction.js +37 -3
  12. package/console/dist/server/routes/update.js +21 -1
  13. package/console/dist/server/successor.d.ts +46 -0
  14. package/console/dist/server/successor.js +128 -0
  15. package/console/dist/web/assets/app.css +18 -0
  16. package/console/dist/web/assets/app.js +32 -31
  17. package/console/package.json +1 -1
  18. package/core/dist/runtime/candidate-intake-service.d.ts +1 -1
  19. package/core/dist/runtime/candidate-intake-service.d.ts.map +1 -1
  20. package/core/dist/runtime/candidate-intake-service.js +89 -12
  21. package/core/dist/runtime/candidate-intake-service.js.map +1 -1
  22. package/core/dist/runtime/context-payload.d.ts +11 -0
  23. package/core/dist/runtime/context-payload.d.ts.map +1 -1
  24. package/core/dist/runtime/context-payload.js +27 -0
  25. package/core/dist/runtime/context-payload.js.map +1 -1
  26. package/core/dist/runtime/host-submission-context.d.ts +13 -6
  27. package/core/dist/runtime/host-submission-context.d.ts.map +1 -1
  28. package/core/dist/runtime/host-submission-context.js +77 -8
  29. package/core/dist/runtime/host-submission-context.js.map +1 -1
  30. package/core/dist/runtime/index.d.ts +2 -1
  31. package/core/dist/runtime/index.d.ts.map +1 -1
  32. package/core/dist/runtime/index.js +8 -0
  33. package/core/dist/runtime/index.js.map +1 -1
  34. package/core/dist/runtime/pain-ingress.d.ts +8 -0
  35. package/core/dist/runtime/pain-ingress.d.ts.map +1 -1
  36. package/core/dist/runtime/pain-ingress.js +8 -1
  37. package/core/dist/runtime/pain-ingress.js.map +1 -1
  38. package/core/dist/runtime/pain-recall-read-model.d.ts +72 -0
  39. package/core/dist/runtime/pain-recall-read-model.d.ts.map +1 -1
  40. package/core/dist/runtime/pain-recall-read-model.js +46 -21
  41. package/core/dist/runtime/pain-recall-read-model.js.map +1 -1
  42. package/core/dist/runtime/pain-receipt-recovery.d.ts +4 -1
  43. package/core/dist/runtime/pain-receipt-recovery.d.ts.map +1 -1
  44. package/core/dist/runtime/pain-receipt-recovery.js +28 -10
  45. package/core/dist/runtime/pain-receipt-recovery.js.map +1 -1
  46. package/core/dist/runtime/pain-signal-bridge.d.ts +38 -23
  47. package/core/dist/runtime/pain-signal-bridge.d.ts.map +1 -1
  48. package/core/dist/runtime/pain-signal-bridge.js +533 -182
  49. package/core/dist/runtime/pain-signal-bridge.js.map +1 -1
  50. package/core/dist/runtime/pain-signal-runtime-factory.d.ts +8 -1
  51. package/core/dist/runtime/pain-signal-runtime-factory.d.ts.map +1 -1
  52. package/core/dist/runtime/pain-signal-runtime-factory.js +196 -25
  53. package/core/dist/runtime/pain-signal-runtime-factory.js.map +1 -1
  54. package/core/dist/runtime/pain-target-evidence-reconcile.d.ts +78 -4
  55. package/core/dist/runtime/pain-target-evidence-reconcile.d.ts.map +1 -1
  56. package/core/dist/runtime/pain-target-evidence-reconcile.js +229 -18
  57. package/core/dist/runtime/pain-target-evidence-reconcile.js.map +1 -1
  58. package/core/dist/runtime/pain-to-principle-service.d.ts +26 -5
  59. package/core/dist/runtime/pain-to-principle-service.d.ts.map +1 -1
  60. package/core/dist/runtime/pain-to-principle-service.js +63 -52
  61. package/core/dist/runtime/pain-to-principle-service.js.map +1 -1
  62. package/core/dist/runtime/store/candidate/admission-document.d.ts +43 -0
  63. package/core/dist/runtime/store/candidate/admission-document.d.ts.map +1 -1
  64. package/core/dist/runtime/store/candidate/admission-document.js +130 -0
  65. package/core/dist/runtime/store/candidate/admission-document.js.map +1 -1
  66. package/core/dist/runtime/store/candidate/candidate-store.d.ts +3 -1
  67. package/core/dist/runtime/store/candidate/candidate-store.d.ts.map +1 -1
  68. package/core/dist/runtime/store/candidate/memory-candidate-store.d.ts +2 -1
  69. package/core/dist/runtime/store/candidate/memory-candidate-store.d.ts.map +1 -1
  70. package/core/dist/runtime/store/candidate/memory-candidate-store.js +27 -1
  71. package/core/dist/runtime/store/candidate/memory-candidate-store.js.map +1 -1
  72. package/core/dist/runtime/store/candidate/sqlite-candidate-store.d.ts +2 -1
  73. package/core/dist/runtime/store/candidate/sqlite-candidate-store.d.ts.map +1 -1
  74. package/core/dist/runtime/store/candidate/sqlite-candidate-store.js +59 -2
  75. package/core/dist/runtime/store/candidate/sqlite-candidate-store.js.map +1 -1
  76. package/core/dist/runtime/store/context/sqlite-context-assembler.d.ts.map +1 -1
  77. package/core/dist/runtime/store/context/sqlite-context-assembler.js +18 -3
  78. package/core/dist/runtime/store/context/sqlite-context-assembler.js.map +1 -1
  79. package/core/dist/runtime/store/runtime-state-manager.d.ts +2 -1
  80. package/core/dist/runtime/store/runtime-state-manager.d.ts.map +1 -1
  81. package/core/dist/runtime/store/runtime-state-manager.js +4 -0
  82. package/core/dist/runtime/store/runtime-state-manager.js.map +1 -1
  83. package/core/dist/telemetry-event.d.ts +2 -2
  84. package/core/dist/telemetry-event.d.ts.map +1 -1
  85. package/core/dist/telemetry-event.js +5 -0
  86. package/core/dist/telemetry-event.js.map +1 -1
  87. package/core/package.json +1 -1
  88. package/dist/i18n.d.ts.map +1 -1
  89. package/dist/i18n.js +72 -0
  90. package/dist/i18n.js.map +1 -1
  91. package/dist/index.d.ts +15 -0
  92. package/dist/index.d.ts.map +1 -1
  93. package/dist/index.js +145 -35
  94. package/dist/index.js.map +1 -1
  95. package/dist/installer.d.ts +149 -9
  96. package/dist/installer.d.ts.map +1 -1
  97. package/dist/installer.js +542 -31
  98. package/dist/installer.js.map +1 -1
  99. package/dist/installers/codex-host-installer.js +1 -1
  100. package/dist/installers/codex-host-installer.js.map +1 -1
  101. package/dist/installers/index.d.ts +10 -0
  102. package/dist/installers/index.d.ts.map +1 -1
  103. package/dist/installers/index.js +4 -0
  104. package/dist/installers/index.js.map +1 -1
  105. package/dist/mvp-config.js +1 -1
  106. package/dist/mvp-config.js.map +1 -1
  107. package/dist/prompts.d.ts +36 -12
  108. package/dist/prompts.d.ts.map +1 -1
  109. package/dist/prompts.js +102 -30
  110. package/dist/prompts.js.map +1 -1
  111. package/dist/service-host-bridge.d.ts +71 -12
  112. package/dist/service-host-bridge.d.ts.map +1 -1
  113. package/dist/service-host-bridge.js +228 -48
  114. package/dist/service-host-bridge.js.map +1 -1
  115. package/dist/service-host-provisioning.d.ts +102 -0
  116. package/dist/service-host-provisioning.d.ts.map +1 -0
  117. package/dist/service-host-provisioning.js +595 -0
  118. package/dist/service-host-provisioning.js.map +1 -0
  119. package/dist/uninstaller.js +1 -1
  120. package/dist/uninstaller.js.map +1 -1
  121. package/dist/update/apply-payload.d.ts +9 -0
  122. package/dist/update/apply-payload.d.ts.map +1 -1
  123. package/dist/update/apply-payload.js +44 -2
  124. package/dist/update/apply-payload.js.map +1 -1
  125. package/dist/update/console-surface.d.ts +2 -1
  126. package/dist/update/console-surface.d.ts.map +1 -1
  127. package/dist/update/console-surface.js +6 -1
  128. package/dist/update/console-surface.js.map +1 -1
  129. package/dist/update/install-layout.d.ts +12 -0
  130. package/dist/update/install-layout.d.ts.map +1 -1
  131. package/dist/update/install-layout.js +49 -7
  132. package/dist/update/install-layout.js.map +1 -1
  133. package/dist/update/release-manager-authority.d.ts +16 -0
  134. package/dist/update/release-manager-authority.d.ts.map +1 -1
  135. package/dist/update/release-manager-authority.js +45 -3
  136. package/dist/update/release-manager-authority.js.map +1 -1
  137. package/dist/update/release-manager.d.ts +8 -3
  138. package/dist/update/release-manager.d.ts.map +1 -1
  139. package/dist/update/release-manager.js +29 -1
  140. package/dist/update/release-manager.js.map +1 -1
  141. package/dist/update/transaction-progress.d.ts +63 -0
  142. package/dist/update/transaction-progress.d.ts.map +1 -0
  143. package/dist/update/transaction-progress.js +207 -0
  144. package/dist/update/transaction-progress.js.map +1 -0
  145. package/dist/utils/env.d.ts +16 -1
  146. package/dist/utils/env.d.ts.map +1 -1
  147. package/dist/utils/env.js +55 -43
  148. package/dist/utils/env.js.map +1 -1
  149. package/host-runtime/dist/diagnostician-auto-run.js +37 -31
  150. package/host-runtime/dist/governance-observation-store.d.ts +38 -0
  151. package/host-runtime/dist/governance-observation-store.js +41 -0
  152. package/host-runtime/dist/governance-trajectory-turn-reader.js +26 -33
  153. package/host-runtime/package.json +1 -1
  154. package/install-layout/dist/background-execution-transition.d.ts +11 -1
  155. package/install-layout/dist/background-execution-transition.js +45 -1
  156. package/install-layout/dist/index.d.ts +3 -3
  157. package/install-layout/dist/index.js +10 -4
  158. package/install-layout/dist/pd-home.d.ts +12 -0
  159. package/install-layout/dist/pd-home.js +6 -1
  160. package/install-layout/package.json +1 -1
  161. package/package.json +7 -7
  162. package/pd-cli/dist/commands/candidate.d.ts +15 -0
  163. package/pd-cli/dist/commands/candidate.d.ts.map +1 -1
  164. package/pd-cli/dist/commands/candidate.js +449 -93
  165. package/pd-cli/dist/commands/candidate.js.map +1 -1
  166. package/pd-cli/dist/commands/console.d.ts.map +1 -1
  167. package/pd-cli/dist/commands/console.js +10 -0
  168. package/pd-cli/dist/commands/console.js.map +1 -1
  169. package/pd-cli/dist/commands/diagnose.d.ts.map +1 -1
  170. package/pd-cli/dist/commands/diagnose.js +254 -160
  171. package/pd-cli/dist/commands/diagnose.js.map +1 -1
  172. package/pd-cli/dist/commands/intake-outcome-guidance.d.ts +57 -0
  173. package/pd-cli/dist/commands/intake-outcome-guidance.d.ts.map +1 -0
  174. package/pd-cli/dist/commands/intake-outcome-guidance.js +206 -0
  175. package/pd-cli/dist/commands/intake-outcome-guidance.js.map +1 -0
  176. package/pd-cli/dist/commands/mcp-probe.d.ts.map +1 -1
  177. package/pd-cli/dist/commands/mcp-probe.js +1 -0
  178. package/pd-cli/dist/commands/mcp-probe.js.map +1 -1
  179. package/pd-cli/dist/commands/pain-record.d.ts.map +1 -1
  180. package/pd-cli/dist/commands/pain-record.js +18 -4
  181. package/pd-cli/dist/commands/pain-record.js.map +1 -1
  182. package/pd-cli/dist/commands/pain-retry.d.ts.map +1 -1
  183. package/pd-cli/dist/commands/pain-retry.js +91 -21
  184. package/pd-cli/dist/commands/pain-retry.js.map +1 -1
  185. package/pd-cli/dist/commands/runtime-uat.d.ts.map +1 -1
  186. package/pd-cli/dist/commands/runtime-uat.js +1 -0
  187. package/pd-cli/dist/commands/runtime-uat.js.map +1 -1
  188. package/pd-cli/dist/commands/service-lifecycle.js +1 -1
  189. package/pd-cli/dist/commands/service-lifecycle.js.map +1 -1
  190. package/pd-cli/dist/commands/service-run-once.d.ts +1 -1
  191. package/pd-cli/dist/commands/service-run-once.d.ts.map +1 -1
  192. package/pd-cli/dist/commands/service-run-once.js +9 -5
  193. package/pd-cli/dist/commands/service-run-once.js.map +1 -1
  194. package/pd-cli/dist/program.d.ts.map +1 -1
  195. package/pd-cli/dist/program.js +14 -3
  196. package/pd-cli/dist/program.js.map +1 -1
  197. package/pd-cli/dist/services/admission-write-gate.d.ts +4 -0
  198. package/pd-cli/dist/services/admission-write-gate.d.ts.map +1 -1
  199. package/pd-cli/dist/services/admission-write-gate.js +50 -48
  200. package/pd-cli/dist/services/admission-write-gate.js.map +1 -1
  201. package/pd-cli/dist/services/console-launcher.js +3 -3
  202. package/pd-cli/dist/services/console-launcher.js.map +1 -1
  203. package/pd-cli/dist/services/service-host/managed-run.d.ts.map +1 -1
  204. package/pd-cli/dist/services/service-host/managed-run.js +25 -8
  205. package/pd-cli/dist/services/service-host/managed-run.js.map +1 -1
  206. package/pd-cli/dist/services/service-host/scheduler/service-status.d.ts +12 -0
  207. package/pd-cli/dist/services/service-host/scheduler/service-status.d.ts.map +1 -1
  208. package/pd-cli/dist/services/service-host/scheduler/service-status.js +16 -7
  209. package/pd-cli/dist/services/service-host/scheduler/service-status.js.map +1 -1
  210. package/pd-cli/dist/services/service-host/status/service-run-status.d.ts +7 -5
  211. package/pd-cli/dist/services/service-host/status/service-run-status.d.ts.map +1 -1
  212. package/pd-cli/dist/services/service-host/status/service-run-status.js +1 -1
  213. package/pd-cli/dist/services/service-host/status/service-run-status.js.map +1 -1
  214. package/pd-cli/package.json +1 -1
  215. package/pd-mcp-server/dist/submit-assembly.js +61 -18
  216. package/pd-mcp-server/dist/version.d.ts +1 -1
  217. package/pd-mcp-server/dist/version.js +1 -1
  218. package/pd-mcp-server/package.json +1 -1
  219. package/plugin/dist/bundle.js +493 -493
  220. package/plugin/dist/openclaw-worker.js +263 -263
  221. package/plugin/dist/openclaw.plugin.json +1 -1
  222. package/plugin/openclaw.plugin.json +1 -1
  223. package/plugin/package.json +1 -1
  224. package/release-manager/dist/i18n.js +72 -0
  225. package/release-manager/dist/installer.js +542 -31
  226. package/release-manager/dist/installers/codex-host-installer.js +1 -1
  227. package/release-manager/dist/installers/index.js +4 -0
  228. package/release-manager/dist/mvp-config.js +1 -1
  229. package/release-manager/dist/service-host-bridge.js +228 -48
  230. package/release-manager/dist/service-host-provisioning.js +595 -0
  231. package/release-manager/dist/update/apply-payload.js +44 -2
  232. package/release-manager/dist/update/console-surface.js +6 -1
  233. package/release-manager/dist/update/install-layout.js +49 -7
  234. package/release-manager/dist/update/release-manager-authority.js +45 -3
  235. package/release-manager/dist/update/release-manager.js +29 -1
  236. package/release-manager/dist/update/transaction-progress.js +207 -0
  237. package/release-manager/dist/utils/env.js +55 -43
  238. package/release-manager/package.json +5 -5
  239. package/workbuddy-adapter/dist/codec/input-decoder.d.ts +21 -0
  240. package/workbuddy-adapter/dist/codec/input-decoder.js +50 -1
  241. package/workbuddy-adapter/dist/ingestion/pain-receipt-fallback.d.ts +68 -0
  242. package/workbuddy-adapter/dist/ingestion/pain-receipt-fallback.js +225 -0
  243. package/workbuddy-adapter/dist/pd-hook.js +60 -0
  244. package/workbuddy-adapter/dist/worker/workspace-worker.js +46 -44
  245. package/workbuddy-adapter/package.json +1 -1
  246. package/console/dist/server/utils/gateway.d.ts +0 -29
  247. package/console/dist/server/utils/gateway.js +0 -175
@@ -5,7 +5,7 @@
5
5
  * pd diagnose status --task-id <taskId> --workspace <path>
6
6
  * pd diagnose run --task-id <taskId> --workspace <path>
7
7
  */
8
- import { RuntimeStateManager, SqliteHistoryQuery, SqliteContextAssembler, SqliteDiagnosticianCommitter, SqliteTrajectoryLocator, SqliteSourceTraceLocator, SplitDiagnosticianRunner, DiagRootCauseRunner, DiagDistillerRunner, DiagRouterRunner, DefaultDiagRootCauseValidator, DefaultDiagDistillerValidator, TestDoubleRuntimeAdapter, PDRuntimeError, isRuntimeConfigError, CandidateIntakeService, run as diagnoseRun, status as diagnoseStatus, PrincipleTreeLedgerAdapter, buildDreamerSeedFromCandidate, findExistingDreamerTask, CANDIDATE_KIND_TO_ROUTE, ROUTE_CHANNEL_MAP, MVP_ENABLED_CHANNELS, persistPainDiagnosis, createBridgeTelemetryEventEmitter, createReuseRecommendationHook, computeFeatureFlagsFromConfig, isFeatureEnabled, evaluateDreamerSeedSuppression, pendingOwnerDecision, } from '@principles/core/runtime';
8
+ import { RuntimeStateManager, SqliteHistoryQuery, SqliteContextAssembler, SqliteDiagnosticianCommitter, SqliteTrajectoryLocator, SqliteSourceTraceLocator, SplitDiagnosticianRunner, DiagRootCauseRunner, DiagDistillerRunner, DiagRouterRunner, DefaultDiagRootCauseValidator, DefaultDiagDistillerValidator, TestDoubleRuntimeAdapter, PDRuntimeError, isRuntimeConfigError, CandidateIntakeService, run as diagnoseRun, status as diagnoseStatus, PrincipleTreeLedgerAdapter, buildDreamerSeedFromCandidate, findExistingDreamerTask, CANDIDATE_KIND_TO_ROUTE, ROUTE_CHANNEL_MAP, MVP_ENABLED_CHANNELS, persistPainDiagnosis, createBridgeTelemetryEventEmitter, createReuseRecommendationHook, computeFeatureFlagsFromConfig, isFeatureEnabled, evaluateDreamerSeedSuppression, pendingOwnerDecision, validateRecommendationKind, } from '@principles/core/runtime';
9
9
  import { createGovernanceTrajectoryTurnReader, createConsentLedgerSourceMaterialAuthorization, createHostIntentDocReader } from '@principles/host-runtime';
10
10
  import { resolveWorkspaceDir } from '../resolve-workspace.js';
11
11
  import { createWorkspaceTelemetryEmitter } from '../services/workspace-telemetry.js';
@@ -16,6 +16,7 @@ import { resolveRuntimeAdapterFromConfig, ConfigResolutionError } from '../servi
16
16
  import { resolveRuntimeFromPdConfig } from '../services/resolve-runtime-from-pd-config.js';
17
17
  import { enforceFullAdmissionForWrite } from '../services/admission-write-gate.js';
18
18
  import { checkAdmissionGate } from './admission-gate.js';
19
+ import { buildIntakeOutcomeGuidance } from './intake-outcome-guidance.js';
19
20
  import { resolveSourcePainIdFromDiagnostician } from './candidate.js';
20
21
  import * as path from 'path';
21
22
  function validateStalledThreshold(val) {
@@ -604,7 +605,7 @@ export async function handleDiagnoseRun(opts) {
604
605
  // cli-6-output-next-action: refusal result carries admissionBlock.nextAction.
605
606
  // SPEC review round-3 P1: the FULL write gate (persisted disposition /
606
607
  // re-evaluation), not the confidence/kind-only partial check.
607
- const admissionBlock = (await enforceFullAdmissionForWrite(stateManager, candidate.candidateId, { sourceMaterialAuthorization })) ?? checkAdmissionGate(candidate);
608
+ const admissionBlock = (await enforceFullAdmissionForWrite(stateManager, candidate.candidateId, { sourceMaterialAuthorization, coordination: ledgerAdapter })) ?? checkAdmissionGate(candidate);
608
609
  if (admissionBlock) {
609
610
  intakeFailed = true;
610
611
  intakeResults.push({
@@ -622,13 +623,49 @@ export async function handleDiagnoseRun(opts) {
622
623
  }
623
624
  try {
624
625
  const intakeResult = await intakeService.intake(candidate.candidateId);
625
- // PRI-917 v0.3.3: a parked candidate stays PENDING — no consumed
626
- // marking, no dreamer seeding. The Owner resolves it via
627
- // `pd candidate review --decide`. Phase 7.2 B2: the intake service
628
- // itself persists the park on the candidate's admission processing
629
- // (the business truth source), so a later automatic re-intake
630
- // replays the park instead of re-rolling the evaluation; the
631
- // telemetry below stays observability-only.
626
+ // Invalid RAW kinds, their unreleased recovery parks, and pending
627
+ // Owner decisions are all non-terminal governance states. None may
628
+ // be consumed or seeded by this automatic path.
629
+ if (intakeResult.outcome === 'refused' && (intakeResult.reason === 'unknown_kind'
630
+ || intakeResult.reason === 'candidate_kind_recovery_required')) {
631
+ intakeFailed = true;
632
+ const invalidKind = intakeResult.reason === 'unknown_kind';
633
+ intakeResults.push({
634
+ candidateId: candidate.candidateId,
635
+ status: 'refused',
636
+ reason: invalidKind ? 'candidate_kind_invalid' : 'candidate_kind_recovery_required',
637
+ error: `${invalidKind ? 'candidate_kind_invalid' : 'candidate_kind_recovery_required'}: ${intakeResult.message}`,
638
+ nextAction: `After restoring the intended RAW kind, obtain explicit Owner authorization: pd candidate resume-post-processing --candidate-id ${candidate.candidateId} --workspace "${workspaceDir}" --reason "<why this repair is safe>" --confirm.`,
639
+ });
640
+ continue;
641
+ }
642
+ if (intakeResult.outcome === 'refused' && intakeResult.reason === 'admission_document_unreadable') {
643
+ intakeFailed = true;
644
+ intakeResults.push({
645
+ candidateId: candidate.candidateId,
646
+ status: 'intake_failed',
647
+ error: intakeResult.message,
648
+ nextAction: 'Inspect and repair the persisted admission_json; automatic intake failed closed and did not consume this candidate.',
649
+ });
650
+ continue;
651
+ }
652
+ if (intakeResult.outcome === 'refused' && intakeResult.reason === 'owner_decision_pending') {
653
+ const admission = await stateManager.getAdmissionDocument(candidate.candidateId);
654
+ const pending = pendingOwnerDecision(admission.ok ? admission.document ?? null : null);
655
+ const decision = pending?.decision ?? (intakeResult.message.includes('--decide reuse') ? 'reuse' : 'create');
656
+ const principleArg = decision === 'reuse' && pending?.selectedPrincipleId
657
+ ? ` --principle-id ${pending.selectedPrincipleId}`
658
+ : '';
659
+ intakeResults.push({
660
+ candidateId: candidate.candidateId,
661
+ status: 'review_required',
662
+ reason: 'owner_decision_pending',
663
+ nextAction: `Resume the SAME persisted Owner verdict: pd candidate review --candidate-id ${candidate.candidateId} --workspace "${workspaceDir}" --decide ${decision}${principleArg} --reason "...".`,
664
+ });
665
+ continue;
666
+ }
667
+ // A reuse-parked candidate also stays PENDING; the Owner resolves it
668
+ // through the existing review channel.
632
669
  if (intakeResult.outcome === 'refused' && intakeResult.reason === 'reuse_pending_owner') {
633
670
  const recommended = intakeResult.reuseRecommendation?.status === 'recommended' ? intakeResult.reuseRecommendation : undefined;
634
671
  // PRI-939 review fix (CodeRabbit): the park observation reaches the
@@ -653,11 +690,20 @@ export async function handleDiagnoseRun(opts) {
653
690
  });
654
691
  continue;
655
692
  }
656
- // Phase 1 / PR1: candidate status handling is deliberately UNCHANGED
657
- // (SPEC v2.1 Step 2 "保持现有 candidate persistence / routing / defer
658
- // 行为"). Only the Principle Ledger write is gated, so a refused
659
- // candidate is still consumed and remains eligible for the kind-aware
660
- // dreamer seed loop below.
693
+ if (intakeResult.outcome === 'refused' && intakeResult.reason === 'candidate_changed_during_intake') {
694
+ intakeFailed = true;
695
+ intakeResults.push({
696
+ candidateId: candidate.candidateId,
697
+ status: 'refused',
698
+ reason: intakeResult.reason,
699
+ error: intakeResult.message,
700
+ nextAction: 'Inspect the current candidate state; no task was created. Retry candidate processing against the current row.',
701
+ });
702
+ continue;
703
+ }
704
+ // Non-principle routing/defer refusals retain the historical
705
+ // consumed disposition. Invalid-kind, unreadable-admission and
706
+ // pending-Owner cases have already continued above without mutation.
661
707
  if (candidate.status !== 'consumed') {
662
708
  await stateManager.updateCandidateStatus(candidate.candidateId, { status: 'consumed' });
663
709
  }
@@ -734,140 +780,186 @@ export async function handleDiagnoseRun(opts) {
734
780
  // nextAction/exit-code signaling below (partial failure still exits non-zero).
735
781
  if (opts.intake !== false) {
736
782
  for (const candidate of candidates) {
737
- const kind = candidate.recommendationKind;
738
- if (kind === 'defer' || kind === 'implementation')
739
- continue;
740
- const intakeResult = intakeResults.find((r) => r.candidateId === candidate.candidateId);
783
+ const intakeResult = intakeResults.find((record) => record.candidateId === candidate.candidateId);
741
784
  if (!intakeResult || intakeResult.status !== 'consumed')
742
785
  continue;
743
- // Phase 7.2 B2.5 — Dreamer seed suppression. A candidate already
744
- // resolved onto an existing principle (reuse decision / INV-R07 replay
745
- // / B1 exact-duplicate guard — identity basis 'principle_reuse') or
746
- // still reuse-parked has no information gain from an independent
747
- // exploration chain. The verdict comes from PERSISTENT facts (ledger
748
- // identity + admission processing), so it holds for restarts, rescans
749
- // and candidates consumed in earlier runs — not just this run's
750
- // in-memory intake result. Fail-open on an unexpected read failure
751
- // (same posture as the bridge): the suppression is a chain-budget
752
- // guard, not a learning gate — an unreadable fact must not block the
753
- // seed, only make the check not run.
754
- let suppression = { suppress: false };
786
+ // Re-read and seed under the same candidate coordination lock used by
787
+ // Owner reuse and pd candidate internalize. The critical section is
788
+ // bounded SQLite/ledger I/O only; no LLM or network calls occur here.
755
789
  try {
756
- const admissionDoc = await stateManager.getAdmissionDocument(candidate.candidateId);
757
- const pending = pendingOwnerDecision(admissionDoc.ok ? admissionDoc.document ?? null : null);
758
- suppression = evaluateDreamerSeedSuppression({
759
- identity: ledgerAdapter.resolveCandidatePrincipleIdentity(candidate.candidateId, kind ?? 'principle'),
760
- processing: admissionDoc.ok ? admissionDoc.document?.processing : undefined,
761
- ...(pending !== null ? { pendingOwnerDecision: { decision: pending.decision } } : {}),
762
- });
763
- }
764
- catch {
765
- suppression = { suppress: false };
766
- }
767
- if (suppression.suppress) {
768
- intakeResults.push({
769
- candidateId: candidate.candidateId,
770
- status: 'dreamer_seed_suppressed',
771
- reusedPrincipleId: suppression.reason === 'reuse_resolved_to_existing_principle' ? suppression.principleId : intakeResult.reusedPrincipleId,
772
- nextAction: suppression.reason === 'reuse_resolved_to_existing_principle'
773
- ? 'No independent Dreamer chain: this candidate is durably resolved onto the existing principle (reuseEvidence).'
774
- : `pd candidate review --candidate-id ${candidate.candidateId} --decide reuse|create --reason "..."`,
790
+ await ledgerAdapter.withCandidateCoordination(candidate.candidateId, async () => {
791
+ const currentCandidate = await stateManager.getCandidate(candidate.candidateId);
792
+ if (currentCandidate === null) {
793
+ intakeFailed = true;
794
+ intakeResults.push({
795
+ candidateId: candidate.candidateId,
796
+ status: 'intake_failed',
797
+ error: 'candidate_disappeared_before_dreamer_seed',
798
+ nextAction: 'Re-run diagnosis after verifying the candidate row and its task lineage.',
799
+ });
800
+ return;
801
+ }
802
+ const rawKind = validateRecommendationKind(currentCandidate.rawRecommendationKind);
803
+ if (rawKind === null) {
804
+ const raw = typeof currentCandidate.rawRecommendationKind === 'string' ? currentCandidate.rawRecommendationKind : 'missing';
805
+ const shown = JSON.stringify(raw).slice(1, -1).slice(0, 40);
806
+ const nextAction = `Restore the intended RAW kind, then obtain explicit Owner authorization: pd candidate resume-post-processing --candidate-id ${candidate.candidateId} --workspace "${workspaceDir}" --reason "<why this repair is safe>" --confirm.`;
807
+ const admission = await stateManager.getAdmissionDocument(candidate.candidateId);
808
+ if (admission.ok) {
809
+ await stateManager.updateAdmissionProcessing(candidate.candidateId, {
810
+ state: 'awaiting_owner',
811
+ attempts: admission.document?.processing?.attempts ?? 0,
812
+ lastFailure: { reason: 'candidate_kind_invalid', nextAction, at: new Date().toISOString() },
813
+ blockedReason: `candidate_kind_invalid:${shown}`,
814
+ });
815
+ }
816
+ intakeFailed = true;
817
+ intakeResults.push({
818
+ candidateId: candidate.candidateId,
819
+ status: 'refused',
820
+ reason: 'candidate_kind_invalid',
821
+ error: `candidate_kind_invalid: ${raw === 'missing' ? 'missing' : raw}`,
822
+ nextAction,
823
+ });
824
+ return;
825
+ }
826
+ if (rawKind === 'defer' || rawKind === 'implementation')
827
+ return;
828
+ const admissionDoc = await stateManager.getAdmissionDocument(candidate.candidateId);
829
+ if (!admissionDoc.ok) {
830
+ intakeFailed = true;
831
+ intakeResults.push({
832
+ candidateId: candidate.candidateId,
833
+ status: 'intake_failed',
834
+ error: 'admission_document_unreadable_before_dreamer_seed',
835
+ nextAction: 'Inspect and repair admission_json. No Dreamer task was created.',
836
+ });
837
+ return;
838
+ }
839
+ const processing = admissionDoc.document?.processing;
840
+ if (processing?.state === 'awaiting_owner'
841
+ && typeof processing.blockedReason === 'string'
842
+ && processing.blockedReason.startsWith('candidate_kind_invalid')) {
843
+ intakeFailed = true;
844
+ intakeResults.push({
845
+ candidateId: candidate.candidateId,
846
+ status: 'refused',
847
+ reason: 'candidate_kind_recovery_required',
848
+ error: 'candidate_kind_recovery_required: persisted RAW kind is repaired but Owner authorization is still required',
849
+ nextAction: `After repairing the persisted RAW kind, run pd candidate resume-post-processing --candidate-id ${candidate.candidateId} --workspace "${workspaceDir}" --reason "<why this repair is safe>" --confirm.`,
850
+ });
851
+ return;
852
+ }
853
+ const pending = pendingOwnerDecision(admissionDoc.document ?? null);
854
+ if (pending !== null) {
855
+ const principleArg = pending.decision === 'reuse' && pending.selectedPrincipleId
856
+ ? ` --principle-id ${pending.selectedPrincipleId}`
857
+ : '';
858
+ intakeResults.push({
859
+ candidateId: candidate.candidateId,
860
+ status: 'review_required',
861
+ reason: 'owner_decision_pending',
862
+ nextAction: `Resume the SAME persisted Owner verdict with pd candidate review --candidate-id ${candidate.candidateId} --workspace "${workspaceDir}" --decide ${pending.decision}${principleArg} --reason "...".`,
863
+ });
864
+ return;
865
+ }
866
+ let suppression;
867
+ try {
868
+ suppression = evaluateDreamerSeedSuppression({
869
+ identity: ledgerAdapter.resolveCandidatePrincipleIdentity(candidate.candidateId, currentCandidate.rawRecommendationKind),
870
+ processing: admissionDoc.document?.processing,
871
+ });
872
+ }
873
+ catch {
874
+ intakeFailed = true;
875
+ intakeResults.push({
876
+ candidateId: candidate.candidateId,
877
+ status: 'intake_failed',
878
+ error: 'candidate_seed_authority_read_failed',
879
+ nextAction: 'Inspect the Principle Ledger identity and admission document; fail-closed prevented Dreamer creation.',
880
+ });
881
+ return;
882
+ }
883
+ if (suppression.suppress) {
884
+ intakeResults.push({
885
+ candidateId: candidate.candidateId,
886
+ status: 'dreamer_seed_suppressed',
887
+ reusedPrincipleId: suppression.reason === 'reuse_resolved_to_existing_principle'
888
+ ? suppression.principleId
889
+ : intakeResult.reusedPrincipleId,
890
+ nextAction: suppression.reason === 'reuse_resolved_to_existing_principle'
891
+ ? 'No independent Dreamer chain: this candidate is durably resolved onto the existing principle (reuseEvidence).'
892
+ : `pd candidate review --candidate-id ${candidate.candidateId} --decide reuse|create --reason "...".`,
893
+ });
894
+ return;
895
+ }
896
+ try {
897
+ const route = CANDIDATE_KIND_TO_ROUTE[rawKind];
898
+ if (!route)
899
+ return;
900
+ const channel = ROUTE_CHANNEL_MAP[route];
901
+ const ready = !!channel && MVP_ENABLED_CHANNELS.has(channel);
902
+ const sourcePainId = await resolveSourcePainIdFromDiagnostician(stateManager, currentCandidate);
903
+ const seed = buildDreamerSeedFromCandidate(currentCandidate, {
904
+ route,
905
+ ready,
906
+ sourcePainId: sourcePainId ?? undefined,
907
+ pipelineMode: seedPipelineMode,
908
+ });
909
+ // eslint-disable-next-line no-restricted-syntax -- 'in' required for discriminated union narrowing (BridgeTaskSeed | BridgeDecision)
910
+ if ('decision' in seed)
911
+ return;
912
+ const existingTask = await findExistingDreamerTask((id) => stateManager.getTask(id), candidate.candidateId);
913
+ if (!existingTask) {
914
+ await stateManager.createTask({
915
+ taskId: seed.taskId,
916
+ taskKind: seed.taskKind,
917
+ inputRef: '',
918
+ status: seed.status,
919
+ attemptCount: seed.attemptCount,
920
+ maxAttempts: seed.maxAttempts,
921
+ diagnosticJson: seed.diagnosticJson,
922
+ });
923
+ intakeResults.push({
924
+ candidateId: candidate.candidateId,
925
+ status: 'dreamer_seeded',
926
+ nextAction: `pd task show ${seed.taskId} | pd dreamer run --task-id ${seed.taskId}`,
927
+ });
928
+ }
929
+ }
930
+ catch (seedErr) {
931
+ intakeResults.push({
932
+ candidateId: candidate.candidateId,
933
+ status: 'dreamer_seed_failed',
934
+ error: seedErr instanceof Error ? seedErr.message : String(seedErr),
935
+ nextAction: `pd candidate internalize --candidate-id ${candidate.candidateId}`,
936
+ });
937
+ }
775
938
  });
776
- continue;
777
- }
778
- try {
779
- const route = CANDIDATE_KIND_TO_ROUTE[kind ?? ''];
780
- if (!route)
781
- continue;
782
- const channel = ROUTE_CHANNEL_MAP[route];
783
- const ready = !!channel && MVP_ENABLED_CHANNELS.has(channel);
784
- // BUG-2 (PRI-442): resolve sourcePainId from the diagnostician task
785
- // chain (rc-6 lineage consistency). The candidate itself doesn't carry
786
- // sourcePainId; it must be resolved from the diagnostician task's
787
- // diagnosticJson. ERR-004: never invent lineage.
788
- const sourcePainId = await resolveSourcePainIdFromDiagnostician(stateManager, candidate);
789
- const seed = buildDreamerSeedFromCandidate(candidate, { route, ready, sourcePainId: sourcePainId ?? undefined, pipelineMode: seedPipelineMode });
790
- // eslint-disable-next-line no-restricted-syntax -- 'in' required for discriminated union narrowing (BridgeTaskSeed | BridgeDecision)
791
- if ('decision' in seed)
792
- continue; // not_internalizable or invalid — skip
793
- // PRI-720 C6: candidate-level dedup (demotion may change the
794
- // derived channel suffix vs a pre-existing chain).
795
- const existingTask = await findExistingDreamerTask((id) => stateManager.getTask(id), candidate.candidateId);
796
- if (!existingTask) {
797
- await stateManager.createTask({
798
- taskId: seed.taskId,
799
- taskKind: seed.taskKind,
800
- inputRef: '',
801
- status: seed.status,
802
- attemptCount: seed.attemptCount,
803
- maxAttempts: seed.maxAttempts,
804
- diagnosticJson: seed.diagnosticJson,
805
- });
806
- intakeResults.push({
807
- candidateId: candidate.candidateId,
808
- status: 'dreamer_seeded',
809
- nextAction: `pd task show ${seed.taskId} | pd dreamer run --task-id ${seed.taskId}`,
810
- });
811
- }
812
939
  }
813
- catch (seedErr) {
940
+ catch (coordinationErr) {
941
+ intakeFailed = true;
814
942
  intakeResults.push({
815
943
  candidateId: candidate.candidateId,
816
- status: 'dreamer_seed_failed',
817
- error: seedErr instanceof Error ? seedErr.message : String(seedErr),
818
- nextAction: `pd candidate internalize --candidate-id ${candidate.candidateId}`,
944
+ status: 'intake_failed',
945
+ error: coordinationErr instanceof Error ? coordinationErr.message : String(coordinationErr),
946
+ nextAction: `Resolve the candidate coordination error, then retry internalization with pd candidate internalize --candidate-id ${candidate.candidateId} --workspace "${workspaceDir}"; the diagnosis itself already succeeded and will not be rerun.`,
819
947
  });
820
948
  }
821
949
  }
822
950
  }
951
+ // classification of every candidate into an outcome class drives both
952
+ // output paths — a mixed run (seed-refused + parked + admission-refused
953
+ // + internalizable) reports every class it contains with its own next
954
+ // step, and `--no-intake` computes the raw-kind eligibility from the
955
+ // candidate rows themselves (no seed result exists on that path).
956
+ const guidance = buildIntakeOutcomeGuidance({
957
+ candidates,
958
+ intakeResults,
959
+ intakeEnabled: opts.intake !== false,
960
+ workspaceDir,
961
+ });
823
962
  if (opts.json) {
824
- const candidateIds = candidates.map((c) => c.candidateId);
825
- // CodeRabbit review fix: reflect dreamer seed status in nextAction so
826
- // the owner knows whether internalization has already started or still
827
- // needs manual candidate internalize. Previously the message always
828
- // said "NOT started automatically" even when dreamer tasks were seeded.
829
- const dreamerSeededCount = intakeResults.filter((r) => r.status === 'dreamer_seeded').length;
830
- const dreamerSeedFailedCount = intakeResults.filter((r) => r.status === 'dreamer_seed_failed').length;
831
- // PRI-917 v0.3.3 review fix (P2-4): parked candidates must NOT be told to
832
- // internalize — the Owner decides via `pd candidate review` first.
833
- const reviewRequiredIds = intakeResults
834
- .filter((r) => r.status === 'review_required')
835
- .map((r) => r.candidateId);
836
- // Phase 7.2 B2.5 (CodeRabbit): seed-SUPPRESSED candidates are resolved
837
- // onto an existing principle (or still parked) — an independent chain is
838
- // suppressed by design, so they must not be offered `pd candidate
839
- // internalize` either.
840
- const seedSuppressedIds = intakeResults
841
- .filter((r) => r.status === 'dreamer_seed_suppressed')
842
- .map((r) => r.candidateId);
843
- // PRI-1263: admission-refused candidates must NOT be offered
844
- // `pd candidate internalize` — the write gate refuses them again. Point
845
- // the operator at the ACTUAL next action (evidence supplementation or
846
- // manual review) recorded on the intake result instead.
847
- const admissionRefusedResults = intakeResults.filter((r) => r.admissionRefused === true);
848
- const admissionRefusedIds = admissionRefusedResults.map((r) => r.candidateId);
849
- const reviewRequiredNote = reviewRequiredIds.length > 0
850
- ? ` ${reviewRequiredIds.length} candidate(s) parked for reuse review (suspected duplicates) — decide before internalizing: pd candidate review --candidate-id <id> --decide reuse|create`
851
- : '';
852
- const suppressedNote = seedSuppressedIds.length > 0
853
- ? ` ${seedSuppressedIds.length} candidate(s) had their Dreamer seed SUPPRESSED (durably resolved onto an existing principle or awaiting the Owner — no independent chain by design).`
854
- : '';
855
- const admissionRefusedNote = admissionRefusedResults.length > 0
856
- ? ` ${admissionRefusedResults.length} candidate(s) were REFUSED by the admission gate (e.g. confidence below threshold or insufficient evidence) — do NOT internalize them; supplement evidence or use manual review: ${[...new Set(admissionRefusedResults.map((r) => r.nextAction ?? 'provide additional evidence or request manual review'))].join(' / ')}`
857
- : '';
858
- const internalizableCandidateIds = candidateIds
859
- .filter((id) => !reviewRequiredIds.includes(id) && !seedSuppressedIds.includes(id) && !admissionRefusedIds.includes(id));
860
- const internalizeNextAction = dreamerSeededCount > 0
861
- ? `Dreamer tasks seeded automatically for ${dreamerSeededCount} candidate(s). To continue, run the dreamer tasks shown in intake.candidates[].${dreamerSeedFailedCount > 0 ? ` (${dreamerSeedFailedCount} candidate(s) failed seeding — see intake.candidates[] for retry guidance.)` : ''}${reviewRequiredNote}${suppressedNote}${admissionRefusedNote}`
862
- : internalizableCandidateIds.length > 0
863
- ? `Candidates generated but internalization has NOT started automatically. To begin internalization, run:\n ${internalizableCandidateIds.map((id) => `pd candidate internalize --candidate-id ${id} --workspace "${workspaceDir}"`).join('\n ')}${reviewRequiredNote}${suppressedNote}${admissionRefusedNote}`
864
- : reviewRequiredIds.length > 0
865
- ? `All candidates are parked for reuse review (suspected duplicates). To decide each, run:\n ${reviewRequiredIds.map((id) => `pd candidate review --candidate-id ${id} --decide reuse|create`).join('\n ')}`
866
- : admissionRefusedIds.length > 0 && admissionRefusedIds.length === candidateIds.length
867
- ? `All candidates were refused by the admission gate — internalization is correctly blocked. Per candidate: ${[...new Set(admissionRefusedResults.map((r) => r.nextAction ?? 'provide additional evidence or request manual review'))].join(' / ')}`
868
- : seedSuppressedIds.length > 0
869
- ? `All candidates are durably resolved (Dreamer seeds suppressed by design — no independent chain).${suppressedNote}`
870
- : 'No candidates were generated from this diagnosis.';
871
963
  const jsonOutput = {
872
964
  ...result,
873
965
  // PRI-1222: explicit diagnosis-chain outcome, decoupled from candidate
@@ -881,8 +973,11 @@ export async function handleDiagnoseRun(opts) {
881
973
  intake: {
882
974
  enabled: opts.intake !== false,
883
975
  candidates: intakeResults,
976
+ // every candidate in exactly one outcome class (machine-readable):
977
+ // no caller has to re-derive mixed outcomes from record statuses.
978
+ outcomeClasses: guidance.byClass,
884
979
  },
885
- nextAction: internalizeNextAction,
980
+ nextAction: guidance.nextAction,
886
981
  };
887
982
  console.log(JSON.stringify(jsonOutput, null, 2));
888
983
  // PRI-1222 exit-code contract (unchanged for backward compatibility):
@@ -966,6 +1061,14 @@ export async function handleDiagnoseRun(opts) {
966
1061
  console.log(` ${ir.candidateId}: REUSE REVIEW REQUIRED${ir.reusedPrincipleId ? ` — suspected duplicate of existing Principle ${ir.reusedPrincipleId}` : ' — suspected duplicate'}`);
967
1062
  console.log(` Next action: ${ir.nextAction}`);
968
1063
  }
1064
+ else if (ir.status === 'refused') {
1065
+ // SPEC-PD-PIPELINE-SPINE-001 D4 (v0.9): the seed refusal must be
1066
+ // visible in TTY output with its structured reason — never folded
1067
+ // into the consumed line above.
1068
+ console.log(` ${ir.candidateId}: DREAMER SEED REFUSED — ${ir.reason}`);
1069
+ if (ir.nextAction)
1070
+ console.log(` Next action: ${ir.nextAction}`);
1071
+ }
969
1072
  else if (ir.status === 'dreamer_seed_suppressed') {
970
1073
  // Phase 7.2 B2.5 (CodeRabbit): the suppression must be visible in
971
1074
  // TTY output too — with the reason and the resolved target.
@@ -974,31 +1077,22 @@ export async function handleDiagnoseRun(opts) {
974
1077
  }
975
1078
  }
976
1079
  }
977
- if (opts.intake === false && candidates.length > 0) {
978
- console.log(`\n Note: --no-intake was set. Candidates remain at 'pending'.`);
979
- console.log(` To intake manually:`);
980
- for (const c of candidates) {
981
- console.log(` pd candidate intake --candidate-id ${c.candidateId} --workspace "${workspaceDir}"`);
982
- }
983
- }
1080
+ // The TTY guidance comes from the SAME classification as the JSON
1081
+ // nextAction (review round 2, P2-2): only a class with a valid manual step
1082
+ // gets a command block, and every refusal that needs no command stays
1083
+ // visible as a note. `--no-intake` no longer offers `pd candidate intake`
1084
+ // to a candidate whose kind intake would refuse.
984
1085
  if (candidates.length > 0) {
985
- // PRI-917 v0.3.3 review fix (P2-4): parked candidates get review
986
- // guidance instead of an internalize command that would bypass the
987
- // Owner decision.
988
- const parkedResults = intakeResults.filter((ir) => ir.status === 'review_required');
989
- if (parkedResults.length > 0) {
990
- console.log(`\n Reuse Review Required (suspected duplicates parked for Owner decision):`);
991
- for (const ir of parkedResults) {
992
- console.log(` pd candidate review --candidate-id ${ir.candidateId} --decide reuse|create`);
993
- }
1086
+ if (opts.intake === false) {
1087
+ console.log(`\n Note: --no-intake was set. Candidates remain at 'pending'.`);
1088
+ }
1089
+ for (const note of guidance.notes) {
1090
+ console.log(`\n Note: ${note}`);
994
1091
  }
995
- const internalizable = candidates.filter((c) => !parkedResults.some((ir) => ir.candidateId === c.candidateId));
996
- if (internalizable.length > 0) {
997
- console.log(`\n Next Action:`);
998
- console.log(` Candidates generated but internalization has NOT started automatically.`);
999
- console.log(` To begin internalization:`);
1000
- for (const c of internalizable) {
1001
- console.log(` pd candidate internalize --candidate-id ${c.candidateId} --workspace "${workspaceDir}"`);
1092
+ for (const step of guidance.manualSteps) {
1093
+ console.log(`\n ${step.title}`);
1094
+ for (const command of step.commands) {
1095
+ console.log(` ${command}`);
1002
1096
  }
1003
1097
  }
1004
1098
  }