create-principles-disciple 1.153.0 → 1.153.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 (139) hide show
  1. package/_release/product-identity.json +2 -2
  2. package/console/dist/server/models/ActivationsConsoleModel.d.ts +8 -0
  3. package/console/dist/server/models/ActivationsConsoleModel.js +3 -2
  4. package/console/dist/server/models/ExaminerEvidenceModel.d.ts +6 -2
  5. package/console/dist/server/models/ExaminerEvidenceModel.js +13 -2
  6. package/console/dist/server/routes/examiner-executor.d.ts +33 -0
  7. package/console/dist/server/routes/examiner-executor.js +95 -0
  8. package/console/dist/server/routes/examiner.js +12 -9
  9. package/console/dist/web/assets/app.css +8 -10
  10. package/console/dist/web/assets/app.js +29 -29
  11. package/console/package.json +2 -2
  12. package/core/dist/ledger-file-lock.d.ts +38 -0
  13. package/core/dist/ledger-file-lock.d.ts.map +1 -0
  14. package/core/dist/ledger-file-lock.js +240 -0
  15. package/core/dist/ledger-file-lock.js.map +1 -0
  16. package/core/dist/principle-text-normalization.d.ts +32 -0
  17. package/core/dist/principle-text-normalization.d.ts.map +1 -0
  18. package/core/dist/principle-text-normalization.js +34 -0
  19. package/core/dist/principle-text-normalization.js.map +1 -0
  20. package/core/dist/principle-tree-ledger.d.ts +22 -21
  21. package/core/dist/principle-tree-ledger.d.ts.map +1 -1
  22. package/core/dist/principle-tree-ledger.js +77 -204
  23. package/core/dist/principle-tree-ledger.js.map +1 -1
  24. package/core/dist/runtime/adapter/principle-tree-ledger-adapter.d.ts +13 -0
  25. package/core/dist/runtime/adapter/principle-tree-ledger-adapter.d.ts.map +1 -1
  26. package/core/dist/runtime/adapter/principle-tree-ledger-adapter.js +90 -1
  27. package/core/dist/runtime/adapter/principle-tree-ledger-adapter.js.map +1 -1
  28. package/core/dist/runtime/adapter/schema-prompt-adapter.d.ts.map +1 -1
  29. package/core/dist/runtime/adapter/schema-prompt-adapter.js +21 -30
  30. package/core/dist/runtime/adapter/schema-prompt-adapter.js.map +1 -1
  31. package/core/dist/runtime/candidate-intake-service.d.ts +40 -1
  32. package/core/dist/runtime/candidate-intake-service.d.ts.map +1 -1
  33. package/core/dist/runtime/candidate-intake-service.js +548 -110
  34. package/core/dist/runtime/candidate-intake-service.js.map +1 -1
  35. package/core/dist/runtime/candidate-intake.d.ts +59 -2
  36. package/core/dist/runtime/candidate-intake.d.ts.map +1 -1
  37. package/core/dist/runtime/candidate-intake.js +23 -0
  38. package/core/dist/runtime/candidate-intake.js.map +1 -1
  39. package/core/dist/runtime/candidate-seed-suppression.d.ts +63 -0
  40. package/core/dist/runtime/candidate-seed-suppression.d.ts.map +1 -0
  41. package/core/dist/runtime/candidate-seed-suppression.js +29 -0
  42. package/core/dist/runtime/candidate-seed-suppression.js.map +1 -0
  43. package/core/dist/runtime/config/pd-config-agent-binding.d.ts +5 -5
  44. package/core/dist/runtime/config/pd-config-agent-binding.d.ts.map +1 -1
  45. package/core/dist/runtime/config/pd-config-agent-binding.js +22 -16
  46. package/core/dist/runtime/config/pd-config-agent-binding.js.map +1 -1
  47. package/core/dist/runtime/config/pd-credentials.d.ts.map +1 -1
  48. package/core/dist/runtime/config/pd-credentials.js +7 -1
  49. package/core/dist/runtime/config/pd-credentials.js.map +1 -1
  50. package/core/dist/runtime/diagnostician/distiller-prompt-builder.d.ts.map +1 -1
  51. package/core/dist/runtime/diagnostician/distiller-prompt-builder.js +30 -3
  52. package/core/dist/runtime/diagnostician/distiller-prompt-builder.js.map +1 -1
  53. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.d.ts.map +1 -1
  54. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.js +16 -5
  55. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.js.map +1 -1
  56. package/core/dist/runtime/diagnostician/router-prompt-builder.d.ts.map +1 -1
  57. package/core/dist/runtime/diagnostician/router-prompt-builder.js +16 -4
  58. package/core/dist/runtime/diagnostician/router-prompt-builder.js.map +1 -1
  59. package/core/dist/runtime/index.d.ts +4 -2
  60. package/core/dist/runtime/index.d.ts.map +1 -1
  61. package/core/dist/runtime/index.js +3 -1
  62. package/core/dist/runtime/index.js.map +1 -1
  63. package/core/dist/runtime/internalization/dreamer-prompt-builder.d.ts.map +1 -1
  64. package/core/dist/runtime/internalization/dreamer-prompt-builder.js +177 -29
  65. package/core/dist/runtime/internalization/dreamer-prompt-builder.js.map +1 -1
  66. package/core/dist/runtime/internalization/internalization-orchestrator.d.ts +16 -2
  67. package/core/dist/runtime/internalization/internalization-orchestrator.d.ts.map +1 -1
  68. package/core/dist/runtime/internalization/internalization-orchestrator.js +48 -14
  69. package/core/dist/runtime/internalization/internalization-orchestrator.js.map +1 -1
  70. package/core/dist/runtime/internalization/philosopher-prompt-builder.d.ts.map +1 -1
  71. package/core/dist/runtime/internalization/philosopher-prompt-builder.js +7 -6
  72. package/core/dist/runtime/internalization/philosopher-prompt-builder.js.map +1 -1
  73. package/core/dist/runtime/internalization/scribe-prompt-builder.d.ts +13 -6
  74. package/core/dist/runtime/internalization/scribe-prompt-builder.d.ts.map +1 -1
  75. package/core/dist/runtime/internalization/scribe-prompt-builder.js +15 -10
  76. package/core/dist/runtime/internalization/scribe-prompt-builder.js.map +1 -1
  77. package/core/dist/runtime/pain-signal-bridge.d.ts +3 -0
  78. package/core/dist/runtime/pain-signal-bridge.d.ts.map +1 -1
  79. package/core/dist/runtime/pain-signal-bridge.js +224 -93
  80. package/core/dist/runtime/pain-signal-bridge.js.map +1 -1
  81. package/core/dist/runtime/pain-submit-capability.d.ts.map +1 -1
  82. package/core/dist/runtime/pain-submit-capability.js +3 -5
  83. package/core/dist/runtime/pain-submit-capability.js.map +1 -1
  84. package/core/dist/runtime/pain-to-principle-service.d.ts.map +1 -1
  85. package/core/dist/runtime/pain-to-principle-service.js +18 -21
  86. package/core/dist/runtime/pain-to-principle-service.js.map +1 -1
  87. package/core/dist/runtime/store/candidate/admission-document.d.ts +129 -0
  88. package/core/dist/runtime/store/candidate/admission-document.d.ts.map +1 -1
  89. package/core/dist/runtime/store/candidate/admission-document.js +196 -0
  90. package/core/dist/runtime/store/candidate/admission-document.js.map +1 -1
  91. package/core/dist/runtime/store/candidate/candidate-store.d.ts +54 -1
  92. package/core/dist/runtime/store/candidate/candidate-store.d.ts.map +1 -1
  93. package/core/dist/runtime/store/candidate/memory-candidate-store.d.ts +32 -1
  94. package/core/dist/runtime/store/candidate/memory-candidate-store.d.ts.map +1 -1
  95. package/core/dist/runtime/store/candidate/memory-candidate-store.js +24 -1
  96. package/core/dist/runtime/store/candidate/memory-candidate-store.js.map +1 -1
  97. package/core/dist/runtime/store/candidate/sqlite-candidate-store.d.ts +32 -1
  98. package/core/dist/runtime/store/candidate/sqlite-candidate-store.d.ts.map +1 -1
  99. package/core/dist/runtime/store/candidate/sqlite-candidate-store.js +76 -1
  100. package/core/dist/runtime/store/candidate/sqlite-candidate-store.js.map +1 -1
  101. package/core/dist/runtime/store/runtime-state-manager.d.ts +34 -1
  102. package/core/dist/runtime/store/runtime-state-manager.d.ts.map +1 -1
  103. package/core/dist/runtime/store/runtime-state-manager.js +10 -0
  104. package/core/dist/runtime/store/runtime-state-manager.js.map +1 -1
  105. package/core/package.json +1 -1
  106. package/host-runtime/dist/governance-signal-admission.js +1 -5
  107. package/host-runtime/package.json +1 -1
  108. package/package.json +3 -3
  109. package/pd-cli/dist/commands/candidate.d.ts.map +1 -1
  110. package/pd-cli/dist/commands/candidate.js +243 -28
  111. package/pd-cli/dist/commands/candidate.js.map +1 -1
  112. package/pd-cli/dist/commands/diagnose.d.ts.map +1 -1
  113. package/pd-cli/dist/commands/diagnose.js +110 -7
  114. package/pd-cli/dist/commands/diagnose.js.map +1 -1
  115. package/pd-cli/dist/commands/pain-retry.d.ts.map +1 -1
  116. package/pd-cli/dist/commands/pain-retry.js +3 -0
  117. package/pd-cli/dist/commands/pain-retry.js.map +1 -1
  118. package/pd-cli/dist/commands/runtime-internalization-run-once.d.ts.map +1 -1
  119. package/pd-cli/dist/commands/runtime-internalization-run-once.js +68 -2
  120. package/pd-cli/dist/commands/runtime-internalization-run-once.js.map +1 -1
  121. package/pd-cli/dist/program.d.ts.map +1 -1
  122. package/pd-cli/dist/program.js +11 -1
  123. package/pd-cli/dist/program.js.map +1 -1
  124. package/pd-cli/dist/services/admission-write-gate.d.ts.map +1 -1
  125. package/pd-cli/dist/services/admission-write-gate.js +18 -7
  126. package/pd-cli/dist/services/admission-write-gate.js.map +1 -1
  127. package/pd-cli/dist/services/demo-story-a-runner.d.ts.map +1 -1
  128. package/pd-cli/dist/services/demo-story-a-runner.js +8 -3
  129. package/pd-cli/dist/services/demo-story-a-runner.js.map +1 -1
  130. package/pd-cli/dist/services/reuse-park-release.d.ts +142 -0
  131. package/pd-cli/dist/services/reuse-park-release.d.ts.map +1 -0
  132. package/pd-cli/dist/services/reuse-park-release.js +201 -0
  133. package/pd-cli/dist/services/reuse-park-release.js.map +1 -0
  134. package/pd-cli/package.json +1 -1
  135. package/plugin/dist/bundle.js +819 -629
  136. package/plugin/dist/openclaw.plugin.json +1 -1
  137. package/plugin/openclaw.plugin.json +1 -1
  138. package/plugin/package.json +1 -1
  139. package/release-manager/package.json +2 -2
@@ -17,12 +17,13 @@ import * as path from 'path';
17
17
  import { RuntimeStateManager, candidateList, candidateShow, CandidateIntakeService, CandidateIntakeError, INTAKE_ERROR_CODES, decideInternalizationRoute, buildDreamerSeedFromCandidate, findExistingDreamerTask, parseSeedSourcePainId, PrincipleTreeLedgerAdapter,
18
18
  // PRI-917 PR3A: the review surface consumes the SAME proposal/semantics
19
19
  // machinery as the intake gate (audit C4 — one implementation, no drift).
20
- buildReuseProposal, buildReuseShortlist, extractIntakeRecommendation, isPrincipleLedgerEligibleKind, resolveOwnerIdentity, defaultOwnerIdentityHomeDir, ReuseEvaluationRunner, ReuseEvaluationError, createBridgeTelemetryEventEmitter, auditCandidateLedgerConsistency, } from '@principles/core/runtime';
20
+ buildReuseProposal, buildReuseShortlist, extractIntakeRecommendation, isPrincipleLedgerEligibleKind, resolveOwnerIdentity, defaultOwnerIdentityHomeDir, evaluateDreamerSeedSuppression, pendingOwnerDecision, ReuseEvaluationRunner, ReuseEvaluationError, createBridgeTelemetryEventEmitter, auditCandidateLedgerConsistency, } from '@principles/core/runtime';
21
21
  import { loadLedger, getLedgerFilePathPublic } from '@principles/core/principle-tree-ledger';
22
22
  import { resolveWorkspaceDir } from '../resolve-workspace.js';
23
23
  import { createWorkspaceTelemetryEmitter } from '../services/workspace-telemetry.js';
24
24
  import { loadPdConfig } from '../services/pd-config-loader.js';
25
25
  import { createReuseGatedIntakeService } from '../services/reuse-gated-intake.js';
26
+ import { recordOwnerDecisionIntent, completeOwnerDecisionExecution } from '../services/reuse-park-release.js';
26
27
  import { resolveRuntimeAdapterFromConfig } from '../services/runtime-adapter-resolver.js';
27
28
  import { resolvePromptFullPipelineSeedMode } from '../services/pd-config-loader.js';
28
29
  import { createRemediationResult, remediationAction } from './remediation-output.js';
@@ -582,8 +583,19 @@ async function evaluateReuseProposal(workspaceDir, claim, entries) {
582
583
  }
583
584
  /**
584
585
  * Decision mode of {@link handleCandidateReview}: validate the CLI contract
585
- * (rc-3), resolve the Owner identity (fail-closed), then run the EXISTING
586
- * intake chain with the §11 verdict injected. No CLI-side persistence.
586
+ * (rc-3), resolve the Owner identity (fail-closed), then run the RECOVERABLE
587
+ * three-phase decision lifecycle (Phase 7.2 P1-01):
588
+ *
589
+ * Phase A — persist the typed decision INTENT (admission ownerDecisions,
590
+ * executionStatus pending). The park is NOT cleared.
591
+ * Phase B — execute the verdict through the intake service's
592
+ * ownerDecision channel (persisted-decision authorization, coordination
593
+ * lock, idempotent replays by decisionId).
594
+ * Phase C — one transactional write: decision applied + release audit
595
+ * (when a park was lifted) + processing complete.
596
+ *
597
+ * Every crash window resumes: a re-run with the same verdict detects the
598
+ * pending (or applied) record and continues / reports without re-asking.
587
599
  */
588
600
  async function executeOwnerDecision(deps) {
589
601
  const { opts, stateManager, ledgerAdapter, stateDir, workspaceDir } = deps;
@@ -598,30 +610,25 @@ async function executeOwnerDecision(deps) {
598
610
  process.exit(1);
599
611
  };
600
612
  if (typeof opts.reason !== 'string' || opts.reason.trim() === '') {
601
- failCli('--reason is required with --decide (the evidence entry must record why the Owner resolved this candidate)', 'Re-run with --reason "..." (non-empty).');
613
+ failCli('--reason is required with --decide (the decision record must state why the Owner resolved this candidate)', 'Re-run with --reason "..." (non-empty).');
614
+ return;
602
615
  }
603
616
  if (opts.decide === 'reuse' && (typeof opts.principleId !== 'string' || opts.principleId.trim() === '')) {
604
617
  failCli('--principle-id is required with --decide reuse', 'Re-run with --principle-id <id from the review proposal>.');
618
+ return;
605
619
  }
606
620
  // Owner identity: env > ~/.pd/owner.json > none (ADR-0022 resolver).
607
621
  const identity = resolveOwnerIdentity(process.env, defaultOwnerIdentityHomeDir());
608
622
  if ((identity.source !== 'env' && identity.source !== 'file') || !identity.ownerId) {
609
623
  failCli(`Owner identity is required to record a ${opts.decide} decision (identity source: ${identity.source})${identity.error ? `: ${identity.error}` : ''}`, 'Register the Owner identity file (~/.pd/owner.json) or set PD_OWNER_ID and PD_OWNER_CREDENTIAL_ID together, then retry.');
624
+ return;
610
625
  }
611
- const decision = opts.decide === 'reuse'
612
- ? {
613
- decision: 'reuse',
614
- selectedPrincipleId: opts.principleId,
615
- actor: { kind: 'owner', id: identity.ownerId },
616
- reason: opts.reason,
617
- decidedAt: new Date().toISOString(),
618
- }
619
- : { decision: 'create' };
620
- // INV-R08: verify the selected principle is in the current proposal.
621
- // This prevents a stale or empty proposal from silently degrading reuse
622
- // into create.
626
+ // INV-R08 FIRST: verify the selected principle is in the current proposal
627
+ // BEFORE recording the intent — recording a verdict that then fails
628
+ // validation would leave a dead pending decision on the candidate.
629
+ const decisionCandidate = await stateManager.getCandidate(opts.candidateId);
623
630
  if (opts.decide === 'reuse') {
624
- const candidate = await stateManager.getCandidate(opts.candidateId);
631
+ const candidate = decisionCandidate;
625
632
  const artifact = candidate ? await stateManager.getArtifact(candidate.artifactId) : null;
626
633
  const extracted = candidate ? extractIntakeRecommendation(candidate, artifact) : null;
627
634
  if (!candidate || !extracted || !extracted.ok) {
@@ -637,35 +644,142 @@ async function executeOwnerDecision(deps) {
637
644
  failCli(`Principle ${opts.principleId} is not in the current reuse proposal`, 'Re-run `pd candidate review` to see the current proposal.');
638
645
  }
639
646
  }
647
+ // ── Phase A — record the decision INTENT (park NOT cleared) ──
648
+ const rawKind = typeof decisionCandidate?.rawRecommendationKind === 'string' ? decisionCandidate.rawRecommendationKind : null;
649
+ const phaseA = await recordOwnerDecisionIntent({
650
+ stateManager,
651
+ executionProbe: ledgerAdapter,
652
+ // P1-1: Phase A serializes on the SAME candidate coordination lock as
653
+ // Phase B — the read → probe → supersede/record sequence must never
654
+ // interleave with another process's verify → write.
655
+ coordination: ledgerAdapter,
656
+ candidateId: opts.candidateId,
657
+ decide: opts.decide,
658
+ reason: opts.reason,
659
+ ownerId: identity.ownerId,
660
+ identitySource: identity.source,
661
+ rawRecommendationKind: rawKind,
662
+ ...(opts.decide === 'reuse' ? { selectedPrincipleId: opts.principleId } : {}),
663
+ });
664
+ if (phaseA.status === 'failed') {
665
+ failCli(`Cannot record the ${opts.decide} decision: ${phaseA.reason}`, phaseA.nextAction);
666
+ return;
667
+ }
668
+ if (phaseA.status === 'already_applied') {
669
+ // Crash window AFTER Phase C with the response lost — the decision is
670
+ // durable and complete; report it without re-executing anything.
671
+ const info = {
672
+ candidateId: opts.candidateId,
673
+ decision: opts.decide,
674
+ decisionId: phaseA.decision.decisionId,
675
+ status: 'already_applied',
676
+ resultingPrincipleId: phaseA.decision.resultingPrincipleId,
677
+ message: `This ${opts.decide} decision already completed (applied ${phaseA.decision.executedAt ?? 'earlier'}); nothing was re-executed.`,
678
+ };
679
+ if (opts.json) {
680
+ console.log(JSON.stringify(info, null, 2));
681
+ }
682
+ else {
683
+ console.log(`\nPrinciple Candidate Decision: ${opts.candidateId} (already applied)\n`);
684
+ console.log(` Decision: ${opts.decide} (${phaseA.decision.decisionId})`);
685
+ console.log(` Principle: ${phaseA.decision.resultingPrincipleId ?? '(n/a)'}\n`);
686
+ }
687
+ return;
688
+ }
689
+ const decision = phaseA.decision;
690
+ // ── Phase B — execute the verdict through the persisted-decision channel ──
640
691
  const service = new CandidateIntakeService({
641
692
  stateManager,
642
693
  ledgerAdapter,
643
- // The verdict is fixed by the CLI invocation; the intake gate still
644
- // validates it (rc-1/rc-2/rc-3) and checks the selection against the
645
- // proposal (INV-R08) — the CLI cannot smuggle a decision past the gate.
646
- reuseDecision: () => decision,
694
+ // The verdict comes from the PERSISTED decision record the service
695
+ // re-verifies under the coordination lock — no callback channel (P1-03:
696
+ // an injected callback is not Owner authorization).
647
697
  reuseStateDir: stateDir,
648
698
  });
649
- const intakeResult = await service.intake(opts.candidateId);
699
+ let intakeResult;
700
+ try {
701
+ intakeResult = await service.intake(opts.candidateId, { ownerDecision: { decisionId: decision.decisionId } });
702
+ }
703
+ catch (err) {
704
+ // Structured execution refusals (P1-01) fail the CLI gracefully with a
705
+ // resume nextAction instead of an unhandled error (cli-6). The intent
706
+ // stays pending/applied exactly as the service left it.
707
+ if (err instanceof CandidateIntakeError) {
708
+ const reason = typeof err.context?.reason === 'string' ? err.context.reason : '';
709
+ failCli(`The ${opts.decide} decision was NOT executed: ${err.message}`, reason === 'owner_decision_conflicts_applied'
710
+ ? 'A different verdict already governs this candidate — inspect `pd candidate show` and the admission document before deciding again.'
711
+ : 'Re-run the SAME verdict to resume, or inspect the candidate admission document.');
712
+ return;
713
+ }
714
+ throw err;
715
+ }
650
716
  if (intakeResult.outcome === 'refused' && intakeResult.reason === 'reuse_selected') {
717
+ // ── Phase C for a reuse execution ──
718
+ const resultingPrincipleId = intakeResult.selectedPrincipleId ?? decision.selectedPrincipleId;
719
+ if (resultingPrincipleId === undefined) {
720
+ failCli(`The reuse execution reported no selected principle for candidate ${opts.candidateId} (contract violation); the decision stays pending`, 'Re-run the SAME reuse verdict to resume; if it persists, inspect the candidate admission document.');
721
+ return;
722
+ }
723
+ const phaseC = await completeOwnerDecisionExecution({
724
+ stateManager,
725
+ coordination: ledgerAdapter,
726
+ candidateId: opts.candidateId,
727
+ decision,
728
+ resultingPrincipleId,
729
+ ownerId: identity.ownerId,
730
+ identitySource: identity.source,
731
+ rawRecommendationKind: rawKind,
732
+ });
733
+ if (phaseC.status === 'failed') {
734
+ failCli(`The reuse decision executed but could not be completed: ${phaseC.reason}`, phaseC.nextAction);
735
+ return;
736
+ }
651
737
  await reportReuseResolution({ stateManager, candidateId: opts.candidateId, result: intakeResult, json: opts.json === true });
652
738
  return;
653
739
  }
654
740
  if (intakeResult.outcome === 'refused') {
655
- // A non-principle kind or unknown kind cannot carry a reuse decision.
741
+ // A non-principle kind or unknown kind cannot carry an Owner decision.
742
+ // The intent stays pending — the candidate must be repaired first.
656
743
  throw new CandidateIntakeError(INTAKE_ERROR_CODES.INPUT_INVALID, `Principle Ledger write refused: ${intakeResult.message}`, { candidateId: opts.candidateId, reason: intakeResult.reason });
657
744
  }
658
- // create verdict (or gate absent shapes) — same durable outcome as intake.
745
+ // P1-2 belt-and-braces: a REUSE decision can never legitimately take the
746
+ // ledger_entry shape (reuse leaves evidence on the selected principle, not
747
+ // an own entry). The service now refuses that combination fail-closed; this
748
+ // CLI-side type check keeps the create-shaped Phase C unreachable even if a
749
+ // future adapter regression reintroduces the generic replay.
750
+ if (decision.decision === 'reuse') {
751
+ failCli(`The reuse decision was NOT executed: the intake returned a ledger entry (${intakeResult.entry.id}) for this candidate — a reuse verdict must resolve onto the SELECTED principle via reuseEvidence instead (contract violation)`, "Inspect the candidate's ledger lineage (a derived principle of its own conflicts with a reuse verdict); repair the candidate state, then re-run the SAME reuse verdict.");
752
+ return;
753
+ }
754
+ // ── Phase C for a create execution (B1 dedup may redirect the entry) ──
659
755
  const { entry } = intakeResult;
756
+ const phaseC = await completeOwnerDecisionExecution({
757
+ stateManager,
758
+ coordination: ledgerAdapter,
759
+ candidateId: opts.candidateId,
760
+ decision,
761
+ resultingPrincipleId: entry.id,
762
+ ownerId: identity.ownerId,
763
+ identitySource: identity.source,
764
+ rawRecommendationKind: rawKind,
765
+ });
766
+ if (phaseC.status === 'failed') {
767
+ failCli(`The create decision executed but could not be completed: ${phaseC.reason}`, phaseC.nextAction);
768
+ return;
769
+ }
660
770
  const consumedState = await markCandidateConsumed(stateManager, opts.candidateId, entry.id);
661
771
  // PRI-1193: consuming the candidate is not the end of the create decision.
662
772
  // `run-rulehost --pain-id` resolves the dreamer by pain; without a task
663
773
  // bound to THIS principle candidate it silently picks the rule candidate's
664
774
  // dreamer (no ledgerEntryId) and skips approval enqueue. Seed the principle
665
775
  // dreamer here, exactly like `candidate internalize` does.
776
+ // Phase 7.2 B2.5: the seed helper itself suppresses the chain when the
777
+ // candidate is durably resolved onto an existing principle (e.g. the Owner
778
+ // create verdict met the B1 exact-duplicate guard) or still reuse-parked.
666
779
  // eslint-disable-next-line @typescript-eslint/no-use-before-define -- helper is defined beside this command for readability
667
780
  const dreamer = await seedDreamerForConsumedCandidate({
668
781
  stateManager,
782
+ ledgerAdapter,
669
783
  workspaceDir,
670
784
  candidateId: opts.candidateId,
671
785
  });
@@ -693,6 +807,7 @@ async function executeOwnerDecision(deps) {
693
807
  const result = {
694
808
  candidateId: opts.candidateId,
695
809
  decision: opts.decide,
810
+ decisionId: decision.decisionId,
696
811
  ledgerEntryId: entry.id,
697
812
  status: 'consumed',
698
813
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
@@ -725,6 +840,47 @@ async function seedDreamerForConsumedCandidate(deps) {
725
840
  nextAction: 'Run `pd candidate internalization backfill --include-pending --confirm` after restoring the candidate row.',
726
841
  };
727
842
  }
843
+ // Phase 7.2 B2.5 — suppress the independent Dreamer chain when the candidate
844
+ // is durably resolved onto an existing principle (ledger reuseEvidence — an
845
+ // Owner reuse decision OR the B1 exact-duplicate guard resolving an Owner
846
+ // create) or still reuse-parked. The Owner create verdict itself is honored
847
+ // (the candidate IS consumed); what is suppressed is the redundant
848
+ // exploration of an already-learned mechanism. Fail-open on an unexpected
849
+ // read failure (same posture as the bridge).
850
+ let suppression;
851
+ try {
852
+ const admissionDoc = await deps.stateManager.getAdmissionDocument(deps.candidateId);
853
+ const pending = pendingOwnerDecision(admissionDoc.ok ? admissionDoc.document ?? null : null);
854
+ suppression = evaluateDreamerSeedSuppression({
855
+ identity: deps.ledgerAdapter.resolveCandidatePrincipleIdentity(deps.candidateId, candidate.recommendationKind ?? 'principle'),
856
+ processing: admissionDoc.ok ? admissionDoc.document?.processing : undefined,
857
+ ...(pending !== null ? { pendingOwnerDecision: { decision: pending.decision } } : {}),
858
+ });
859
+ }
860
+ catch {
861
+ suppression = { suppress: false };
862
+ }
863
+ if (suppression.suppress) {
864
+ if (suppression.reason === 'reuse_resolved_to_existing_principle') {
865
+ return {
866
+ status: 'not_seeded',
867
+ reason: `dreamer_seed_suppressed: candidate is durably resolved onto existing principle ${suppression.principleId} (reuseEvidence)`,
868
+ nextAction: 'No independent Dreamer chain by design; the existing principle already carries the mechanism.',
869
+ };
870
+ }
871
+ if (suppression.reason === 'owner_decision_pending') {
872
+ return {
873
+ status: 'not_seeded',
874
+ reason: `dreamer_seed_suppressed: an Owner ${suppression.decision} decision is recorded but its execution has not completed`,
875
+ nextAction: `pd candidate review --candidate-id ${deps.candidateId} --decide reuse|create --reason "..." (re-run the SAME verdict to resume the recorded decision)`,
876
+ };
877
+ }
878
+ return {
879
+ status: 'not_seeded',
880
+ reason: 'dreamer_seed_suppressed: reuse park is pending the Owner decision',
881
+ nextAction: `pd candidate review --candidate-id ${deps.candidateId} --decide reuse|create --reason "..."`,
882
+ };
883
+ }
728
884
  const recommendation = resolveCandidateRecommendation(candidate, deps.stateManager, deps.candidateId);
729
885
  // The create decision already admitted this principle into the ledger, so
730
886
  // its text is ledger-eligible even when the diagnostician used `description`
@@ -931,7 +1087,10 @@ export async function handleCandidateIntake(opts) {
931
1087
  // R7 gate-bypass fix: the Reuse Review Gate parked this candidate as a
932
1088
  // suspected duplicate. No ledger entry was written and the candidate
933
1089
  // stays pending for the Owner — do NOT mark it consumed. cli-5: this
934
- // path performs no state mutation at all.
1090
+ // CLI path performs no FURTHER state mutation; the park itself is
1091
+ // persisted by the intake service on the candidate's admission
1092
+ // processing (Phase 7.2 B2), so an automatic re-intake now replays the
1093
+ // park instead of re-rolling the evaluation.
935
1094
  reportReusePark({
936
1095
  workspaceDir,
937
1096
  candidateId: opts.candidateId,
@@ -1395,8 +1554,10 @@ export async function handleCandidateRepair(opts) {
1395
1554
  if (intakeResult.outcome === 'refused' && intakeResult.reason === 'reuse_pending_owner') {
1396
1555
  // R7 gate-bypass fix: the gate suspects a semantic duplicate — restoring
1397
1556
  // the entry would recreate a near-duplicate Principle. No write happened;
1398
- // the Owner resolves it via the review channel. cli-5: no mutation on
1399
- // this path (candidate stays consumed, ledger untouched).
1557
+ // the Owner resolves it via the review channel. cli-5: no FURTHER
1558
+ // mutation on this path (candidate stays consumed, ledger untouched);
1559
+ // the park is persisted on the candidate's admission processing by the
1560
+ // intake service (Phase 7.2 B2).
1400
1561
  reportReusePark({
1401
1562
  workspaceDir,
1402
1563
  candidateId: opts.candidateId,
@@ -1523,6 +1684,10 @@ export async function handleCandidateInternalizationBackfill(opts) {
1523
1684
  errors: 0,
1524
1685
  results: [],
1525
1686
  };
1687
+ // Phase 7.2 B2.5: the seed-suppression guard needs the ledger adapter in
1688
+ // the CONSUMED loop too (a second --confirm run re-selects resolved
1689
+ // candidates whose first run suppressed the task creation).
1690
+ const ledgerAdapter = new PrincipleTreeLedgerAdapter({ stateDir: path.join(workspaceDir, '.state') });
1526
1691
  for (const row of consumedRows) {
1527
1692
  const candidateId = row.candidate_id;
1528
1693
  const candidate = await stateManager.getCandidate(candidateId);
@@ -1572,6 +1737,31 @@ export async function handleCandidateInternalizationBackfill(opts) {
1572
1737
  output.results.push({ candidateId, route: decision.route, status: 'existing', taskId: existingTask.taskId, channel, statusBefore: 'consumed', statusAfter: 'consumed', intakeDecision: 'not_needed', seedDecision: 'existing' });
1573
1738
  continue;
1574
1739
  }
1740
+ // Phase 7.2 B2.5 (CodeRabbit): a re-run of backfill re-selects this
1741
+ // consumed candidate; if it is durably resolved onto an existing
1742
+ // principle (or still reuse-parked), the FIRST run already suppressed
1743
+ // its task — this run must suppress it too, or it would create exactly
1744
+ // the chain the first run decided against. Same persistent-facts check
1745
+ // as the pending branch; fail-open on an unexpected read failure.
1746
+ let consumedSuppression = { suppress: false };
1747
+ try {
1748
+ const consumedAdmissionDoc = await stateManager.getAdmissionDocument(candidateId);
1749
+ consumedSuppression = evaluateDreamerSeedSuppression({
1750
+ identity: ledgerAdapter.resolveCandidatePrincipleIdentity(candidateId, 'principle'),
1751
+ processing: consumedAdmissionDoc.ok ? consumedAdmissionDoc.document?.processing : undefined,
1752
+ });
1753
+ }
1754
+ catch {
1755
+ consumedSuppression = { suppress: false };
1756
+ }
1757
+ if (consumedSuppression.suppress) {
1758
+ const suppressReason = consumedSuppression.reason === 'reuse_resolved_to_existing_principle'
1759
+ ? `dreamer_seed_suppressed: durably resolved onto existing principle ${consumedSuppression.principleId} (reuseEvidence)`
1760
+ : 'dreamer_seed_suppressed: reuse park pending Owner decision';
1761
+ output.deferred++;
1762
+ output.results.push({ candidateId, route: decision.route, status: 'deferred', reason: suppressReason, statusBefore: 'consumed', statusAfter: 'consumed', intakeDecision: 'not_needed', seedDecision: 'skipped', nextAction: 'No action required: this candidate is durably resolved; no independent chain by design.' });
1763
+ continue;
1764
+ }
1575
1765
  output.missingDreamerTask++;
1576
1766
  if (!isConfirm) {
1577
1767
  output.results.push({ candidateId, route: decision.route, status: 'would_create', taskId, channel, statusBefore: 'consumed', statusAfter: 'consumed', intakeDecision: 'not_needed', seedDecision: 'would_seed' });
@@ -1594,7 +1784,6 @@ export async function handleCandidateInternalizationBackfill(opts) {
1594
1784
  output.results.push({ candidateId, route: decision.route, status: 'error', reason: err instanceof Error ? err.message : String(err), statusBefore: 'consumed', statusAfter: 'consumed', intakeDecision: 'not_needed', seedDecision: 'skipped', nextAction: 'Investigate dreamer task creation failure' });
1595
1785
  }
1596
1786
  }
1597
- const ledgerAdapter = new PrincipleTreeLedgerAdapter({ stateDir: path.join(workspaceDir, '.state') });
1598
1787
  // R7 gate-bypass fix (adhoc-20261007): --include-pending intakes parked
1599
1788
  // (reuse_review_required) candidates too — the worst bypass, because it
1600
1789
  // consumed the very state the gate created to await the Owner (R7 Wave-2
@@ -1703,6 +1892,32 @@ export async function handleCandidateInternalizationBackfill(opts) {
1703
1892
  continue;
1704
1893
  }
1705
1894
  output.intakeSucceeded++;
1895
+ // Phase 7.2 B2.5 — seed suppression for resolved/parked candidates. The
1896
+ // intake above can succeed AS a resolution (B1 exact-duplicate guard:
1897
+ // ledger_entry written:false + deduplicatedAgainst, audited via
1898
+ // reuseEvidence). Such a candidate is consumed, but an independent
1899
+ // Dreamer chain has no information gain — the mechanism is already in
1900
+ // the ledger. Persistent facts only (identity + admission processing).
1901
+ // Fail-open on an unexpected read failure (same posture as the bridge).
1902
+ let backfillSuppression = { suppress: false };
1903
+ try {
1904
+ const backfillAdmissionDoc = await stateManager.getAdmissionDocument(candidateId);
1905
+ backfillSuppression = evaluateDreamerSeedSuppression({
1906
+ identity: ledgerAdapter.resolveCandidatePrincipleIdentity(candidateId, 'principle'),
1907
+ processing: backfillAdmissionDoc.ok ? backfillAdmissionDoc.document?.processing : undefined,
1908
+ });
1909
+ }
1910
+ catch {
1911
+ backfillSuppression = { suppress: false };
1912
+ }
1913
+ if (backfillSuppression.suppress) {
1914
+ const suppressReason = backfillSuppression.reason === 'reuse_resolved_to_existing_principle'
1915
+ ? `dreamer_seed_suppressed: durably resolved onto existing principle ${backfillSuppression.principleId} (reuseEvidence)`
1916
+ : 'dreamer_seed_suppressed: reuse park pending Owner decision';
1917
+ output.deferred++;
1918
+ output.results.push({ candidateId, route: decision.route, status: 'deferred', reason: suppressReason, statusBefore: 'pending', statusAfter: 'consumed', intakeDecision: 'intake_succeeded', seedDecision: 'skipped', nextAction: 'No action required: the candidate is resolved onto an existing principle; no independent chain by design.' });
1919
+ continue;
1920
+ }
1706
1921
  const existingTask = await stateManager.getTask(taskId);
1707
1922
  if (existingTask) {
1708
1923
  output.alreadyHaveTask++;