create-principles-disciple 1.155.2 → 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.
- package/_release/product-identity.json +2 -2
- package/codex-adapter/dist/ingestion/pain-receipt-fallback.d.ts +28 -1
- package/codex-adapter/dist/ingestion/pain-receipt-fallback.js +53 -17
- package/codex-adapter/dist/worker/workspace-worker.js +86 -66
- package/codex-adapter/package.json +1 -1
- package/console/dist/server/index.d.ts +11 -1
- package/console/dist/server/index.js +84 -19
- package/console/dist/server/release-handover.d.ts +256 -0
- package/console/dist/server/release-handover.js +402 -0
- package/console/dist/server/routes/onboarding.js +1 -0
- package/console/dist/server/routes/update-transaction.js +37 -3
- package/console/dist/server/routes/update.js +21 -1
- package/console/dist/server/successor.d.ts +46 -0
- package/console/dist/server/successor.js +128 -0
- package/console/dist/web/assets/app.css +18 -0
- package/console/dist/web/assets/app.js +32 -31
- package/console/package.json +2 -2
- package/core/dist/runtime/candidate-intake-service.d.ts +1 -1
- package/core/dist/runtime/candidate-intake-service.d.ts.map +1 -1
- package/core/dist/runtime/candidate-intake-service.js +89 -12
- package/core/dist/runtime/candidate-intake-service.js.map +1 -1
- package/core/dist/runtime/context-payload.d.ts +11 -0
- package/core/dist/runtime/context-payload.d.ts.map +1 -1
- package/core/dist/runtime/context-payload.js +27 -0
- package/core/dist/runtime/context-payload.js.map +1 -1
- package/core/dist/runtime/host-submission-context.d.ts +13 -6
- package/core/dist/runtime/host-submission-context.d.ts.map +1 -1
- package/core/dist/runtime/host-submission-context.js +77 -8
- package/core/dist/runtime/host-submission-context.js.map +1 -1
- package/core/dist/runtime/index.d.ts +2 -1
- package/core/dist/runtime/index.d.ts.map +1 -1
- package/core/dist/runtime/index.js +8 -0
- package/core/dist/runtime/index.js.map +1 -1
- package/core/dist/runtime/pain-ingress.d.ts +8 -0
- package/core/dist/runtime/pain-ingress.d.ts.map +1 -1
- package/core/dist/runtime/pain-ingress.js +8 -1
- package/core/dist/runtime/pain-ingress.js.map +1 -1
- package/core/dist/runtime/pain-recall-read-model.d.ts +72 -0
- package/core/dist/runtime/pain-recall-read-model.d.ts.map +1 -1
- package/core/dist/runtime/pain-recall-read-model.js +46 -21
- package/core/dist/runtime/pain-recall-read-model.js.map +1 -1
- package/core/dist/runtime/pain-receipt-recovery.d.ts +4 -1
- package/core/dist/runtime/pain-receipt-recovery.d.ts.map +1 -1
- package/core/dist/runtime/pain-receipt-recovery.js +28 -10
- package/core/dist/runtime/pain-receipt-recovery.js.map +1 -1
- package/core/dist/runtime/pain-signal-bridge.d.ts +38 -23
- package/core/dist/runtime/pain-signal-bridge.d.ts.map +1 -1
- package/core/dist/runtime/pain-signal-bridge.js +533 -182
- package/core/dist/runtime/pain-signal-bridge.js.map +1 -1
- package/core/dist/runtime/pain-signal-runtime-factory.d.ts +8 -1
- package/core/dist/runtime/pain-signal-runtime-factory.d.ts.map +1 -1
- package/core/dist/runtime/pain-signal-runtime-factory.js +196 -25
- package/core/dist/runtime/pain-signal-runtime-factory.js.map +1 -1
- package/core/dist/runtime/pain-target-evidence-reconcile.d.ts +78 -4
- package/core/dist/runtime/pain-target-evidence-reconcile.d.ts.map +1 -1
- package/core/dist/runtime/pain-target-evidence-reconcile.js +229 -18
- package/core/dist/runtime/pain-target-evidence-reconcile.js.map +1 -1
- package/core/dist/runtime/pain-to-principle-service.d.ts +26 -5
- package/core/dist/runtime/pain-to-principle-service.d.ts.map +1 -1
- package/core/dist/runtime/pain-to-principle-service.js +63 -52
- package/core/dist/runtime/pain-to-principle-service.js.map +1 -1
- package/core/dist/runtime/store/candidate/admission-document.d.ts +43 -0
- package/core/dist/runtime/store/candidate/admission-document.d.ts.map +1 -1
- package/core/dist/runtime/store/candidate/admission-document.js +130 -0
- package/core/dist/runtime/store/candidate/admission-document.js.map +1 -1
- package/core/dist/runtime/store/candidate/candidate-store.d.ts +3 -1
- package/core/dist/runtime/store/candidate/candidate-store.d.ts.map +1 -1
- package/core/dist/runtime/store/candidate/memory-candidate-store.d.ts +2 -1
- package/core/dist/runtime/store/candidate/memory-candidate-store.d.ts.map +1 -1
- package/core/dist/runtime/store/candidate/memory-candidate-store.js +27 -1
- package/core/dist/runtime/store/candidate/memory-candidate-store.js.map +1 -1
- package/core/dist/runtime/store/candidate/sqlite-candidate-store.d.ts +2 -1
- package/core/dist/runtime/store/candidate/sqlite-candidate-store.d.ts.map +1 -1
- package/core/dist/runtime/store/candidate/sqlite-candidate-store.js +59 -2
- package/core/dist/runtime/store/candidate/sqlite-candidate-store.js.map +1 -1
- package/core/dist/runtime/store/context/sqlite-context-assembler.d.ts.map +1 -1
- package/core/dist/runtime/store/context/sqlite-context-assembler.js +18 -3
- package/core/dist/runtime/store/context/sqlite-context-assembler.js.map +1 -1
- package/core/dist/runtime/store/runtime-state-manager.d.ts +2 -1
- package/core/dist/runtime/store/runtime-state-manager.d.ts.map +1 -1
- package/core/dist/runtime/store/runtime-state-manager.js +4 -0
- package/core/dist/runtime/store/runtime-state-manager.js.map +1 -1
- package/core/dist/telemetry-event.d.ts +2 -2
- package/core/dist/telemetry-event.d.ts.map +1 -1
- package/core/dist/telemetry-event.js +5 -0
- package/core/dist/telemetry-event.js.map +1 -1
- package/core/package.json +1 -1
- package/dist/i18n.d.ts.map +1 -1
- package/dist/i18n.js +72 -0
- package/dist/i18n.js.map +1 -1
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +145 -35
- package/dist/index.js.map +1 -1
- package/dist/installer.d.ts +149 -9
- package/dist/installer.d.ts.map +1 -1
- package/dist/installer.js +562 -38
- package/dist/installer.js.map +1 -1
- package/dist/installers/codex-host-installer.js +1 -1
- package/dist/installers/codex-host-installer.js.map +1 -1
- package/dist/installers/index.d.ts +10 -0
- package/dist/installers/index.d.ts.map +1 -1
- package/dist/installers/index.js +4 -0
- package/dist/installers/index.js.map +1 -1
- package/dist/mvp-config.js +1 -1
- package/dist/mvp-config.js.map +1 -1
- package/dist/prompts.d.ts +36 -12
- package/dist/prompts.d.ts.map +1 -1
- package/dist/prompts.js +102 -30
- package/dist/prompts.js.map +1 -1
- package/dist/service-host-bridge.d.ts +71 -12
- package/dist/service-host-bridge.d.ts.map +1 -1
- package/dist/service-host-bridge.js +228 -48
- package/dist/service-host-bridge.js.map +1 -1
- package/dist/service-host-provisioning.d.ts +102 -0
- package/dist/service-host-provisioning.d.ts.map +1 -0
- package/dist/service-host-provisioning.js +595 -0
- package/dist/service-host-provisioning.js.map +1 -0
- package/dist/uninstaller.js +1 -1
- package/dist/uninstaller.js.map +1 -1
- package/dist/update/apply-payload.d.ts +9 -0
- package/dist/update/apply-payload.d.ts.map +1 -1
- package/dist/update/apply-payload.js +44 -2
- package/dist/update/apply-payload.js.map +1 -1
- package/dist/update/console-surface.d.ts +2 -1
- package/dist/update/console-surface.d.ts.map +1 -1
- package/dist/update/console-surface.js +6 -1
- package/dist/update/console-surface.js.map +1 -1
- package/dist/update/install-layout.d.ts +12 -0
- package/dist/update/install-layout.d.ts.map +1 -1
- package/dist/update/install-layout.js +49 -7
- package/dist/update/install-layout.js.map +1 -1
- package/dist/update/release-manager-authority.d.ts +16 -0
- package/dist/update/release-manager-authority.d.ts.map +1 -1
- package/dist/update/release-manager-authority.js +45 -3
- package/dist/update/release-manager-authority.js.map +1 -1
- package/dist/update/release-manager.d.ts +8 -3
- package/dist/update/release-manager.d.ts.map +1 -1
- package/dist/update/release-manager.js +29 -1
- package/dist/update/release-manager.js.map +1 -1
- package/dist/update/transaction-progress.d.ts +63 -0
- package/dist/update/transaction-progress.d.ts.map +1 -0
- package/dist/update/transaction-progress.js +207 -0
- package/dist/update/transaction-progress.js.map +1 -0
- package/dist/utils/env.d.ts +16 -1
- package/dist/utils/env.d.ts.map +1 -1
- package/dist/utils/env.js +55 -43
- package/dist/utils/env.js.map +1 -1
- package/host-runtime/dist/diagnostician-auto-run.js +37 -31
- package/host-runtime/dist/governance-observation-store.d.ts +38 -0
- package/host-runtime/dist/governance-observation-store.js +41 -0
- package/host-runtime/dist/governance-trajectory-turn-reader.js +26 -33
- package/host-runtime/package.json +1 -1
- package/install-layout/dist/background-execution-transition.d.ts +11 -1
- package/install-layout/dist/background-execution-transition.js +45 -1
- package/install-layout/dist/index.d.ts +3 -3
- package/install-layout/dist/index.js +10 -4
- package/install-layout/dist/pd-home.d.ts +12 -0
- package/install-layout/dist/pd-home.js +6 -1
- package/install-layout/package.json +1 -1
- package/package.json +10 -10
- package/pd-cli/dist/commands/candidate.d.ts +15 -0
- package/pd-cli/dist/commands/candidate.d.ts.map +1 -1
- package/pd-cli/dist/commands/candidate.js +449 -93
- package/pd-cli/dist/commands/candidate.js.map +1 -1
- package/pd-cli/dist/commands/console.d.ts.map +1 -1
- package/pd-cli/dist/commands/console.js +10 -0
- package/pd-cli/dist/commands/console.js.map +1 -1
- package/pd-cli/dist/commands/diagnose.d.ts.map +1 -1
- package/pd-cli/dist/commands/diagnose.js +254 -160
- package/pd-cli/dist/commands/diagnose.js.map +1 -1
- package/pd-cli/dist/commands/intake-outcome-guidance.d.ts +57 -0
- package/pd-cli/dist/commands/intake-outcome-guidance.d.ts.map +1 -0
- package/pd-cli/dist/commands/intake-outcome-guidance.js +206 -0
- package/pd-cli/dist/commands/intake-outcome-guidance.js.map +1 -0
- package/pd-cli/dist/commands/mcp-probe.d.ts.map +1 -1
- package/pd-cli/dist/commands/mcp-probe.js +1 -0
- package/pd-cli/dist/commands/mcp-probe.js.map +1 -1
- package/pd-cli/dist/commands/pain-record.d.ts.map +1 -1
- package/pd-cli/dist/commands/pain-record.js +18 -4
- package/pd-cli/dist/commands/pain-record.js.map +1 -1
- package/pd-cli/dist/commands/pain-retry.d.ts.map +1 -1
- package/pd-cli/dist/commands/pain-retry.js +91 -21
- package/pd-cli/dist/commands/pain-retry.js.map +1 -1
- package/pd-cli/dist/commands/runtime-uat.d.ts.map +1 -1
- package/pd-cli/dist/commands/runtime-uat.js +1 -0
- package/pd-cli/dist/commands/runtime-uat.js.map +1 -1
- package/pd-cli/dist/commands/service-lifecycle.js +1 -1
- package/pd-cli/dist/commands/service-lifecycle.js.map +1 -1
- package/pd-cli/dist/commands/service-run-once.d.ts +1 -1
- package/pd-cli/dist/commands/service-run-once.d.ts.map +1 -1
- package/pd-cli/dist/commands/service-run-once.js +9 -5
- package/pd-cli/dist/commands/service-run-once.js.map +1 -1
- package/pd-cli/dist/program.d.ts.map +1 -1
- package/pd-cli/dist/program.js +14 -3
- package/pd-cli/dist/program.js.map +1 -1
- package/pd-cli/dist/services/admission-write-gate.d.ts +4 -0
- package/pd-cli/dist/services/admission-write-gate.d.ts.map +1 -1
- package/pd-cli/dist/services/admission-write-gate.js +50 -48
- package/pd-cli/dist/services/admission-write-gate.js.map +1 -1
- package/pd-cli/dist/services/console-launcher.js +3 -3
- package/pd-cli/dist/services/console-launcher.js.map +1 -1
- package/pd-cli/dist/services/service-host/managed-run.d.ts.map +1 -1
- package/pd-cli/dist/services/service-host/managed-run.js +25 -8
- package/pd-cli/dist/services/service-host/managed-run.js.map +1 -1
- package/pd-cli/dist/services/service-host/scheduler/service-status.d.ts +12 -0
- package/pd-cli/dist/services/service-host/scheduler/service-status.d.ts.map +1 -1
- package/pd-cli/dist/services/service-host/scheduler/service-status.js +16 -7
- package/pd-cli/dist/services/service-host/scheduler/service-status.js.map +1 -1
- package/pd-cli/dist/services/service-host/status/service-run-status.d.ts +7 -5
- package/pd-cli/dist/services/service-host/status/service-run-status.d.ts.map +1 -1
- package/pd-cli/dist/services/service-host/status/service-run-status.js +1 -1
- package/pd-cli/dist/services/service-host/status/service-run-status.js.map +1 -1
- package/pd-cli/package.json +1 -1
- package/pd-mcp-server/dist/submit-assembly.js +61 -18
- package/pd-mcp-server/dist/version.d.ts +1 -1
- package/pd-mcp-server/dist/version.js +1 -1
- package/pd-mcp-server/package.json +1 -1
- package/plugin/dist/bundle.js +493 -493
- package/plugin/dist/openclaw-worker.js +263 -263
- package/plugin/dist/openclaw.plugin.json +1 -1
- package/plugin/openclaw.plugin.json +1 -1
- package/plugin/package.json +1 -1
- package/release-manager/dist/i18n.js +72 -0
- package/release-manager/dist/installer.js +562 -38
- package/release-manager/dist/installers/codex-host-installer.js +1 -1
- package/release-manager/dist/installers/index.js +4 -0
- package/release-manager/dist/mvp-config.js +1 -1
- package/release-manager/dist/service-host-bridge.js +228 -48
- package/release-manager/dist/service-host-provisioning.js +595 -0
- package/release-manager/dist/update/apply-payload.js +44 -2
- package/release-manager/dist/update/console-surface.js +6 -1
- package/release-manager/dist/update/install-layout.js +49 -7
- package/release-manager/dist/update/release-manager-authority.js +45 -3
- package/release-manager/dist/update/release-manager.js +29 -1
- package/release-manager/dist/update/transaction-progress.js +207 -0
- package/release-manager/dist/utils/env.js +55 -43
- package/release-manager/package.json +8 -8
- package/workbuddy-adapter/dist/codec/input-decoder.d.ts +21 -0
- package/workbuddy-adapter/dist/codec/input-decoder.js +50 -1
- package/workbuddy-adapter/dist/ingestion/pain-receipt-fallback.d.ts +68 -0
- package/workbuddy-adapter/dist/ingestion/pain-receipt-fallback.js +225 -0
- package/workbuddy-adapter/dist/pd-hook.js +60 -0
- package/workbuddy-adapter/dist/worker/workspace-worker.js +46 -44
- package/workbuddy-adapter/package.json +1 -1
- package/console/dist/server/utils/gateway.d.ts +0 -29
- package/console/dist/server/utils/gateway.js +0 -175
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* pd candidate review --candidate-id <id> --decide create --reason "..." [--json]
|
|
11
11
|
* pd candidate audit --workspace <path> [--json]
|
|
12
12
|
* pd candidate repair --candidate-id <id> --workspace <path> [--json]
|
|
13
|
+
* pd candidate resume-post-processing --candidate-id <id> --reason "..." --confirm [--json]
|
|
13
14
|
* pd candidate route --candidate-id <id> --workspace <path> [--json]
|
|
14
15
|
*/
|
|
15
16
|
import { randomUUID } from 'crypto';
|
|
@@ -17,7 +18,7 @@ import * as path from 'path';
|
|
|
17
18
|
import { RuntimeStateManager, candidateList, candidateShow, CandidateIntakeService, CandidateIntakeError, INTAKE_ERROR_CODES, decideInternalizationRoute, buildDreamerSeedFromCandidate, findExistingDreamerTask, parseSeedSourcePainId, PrincipleTreeLedgerAdapter,
|
|
18
19
|
// PRI-917 PR3A: the review surface consumes the SAME proposal/semantics
|
|
19
20
|
// machinery as the intake gate (audit C4 — one implementation, no drift).
|
|
20
|
-
buildReuseProposal, buildReuseShortlist, extractIntakeRecommendation, isPrincipleLedgerEligibleKind, resolveOwnerIdentity, defaultOwnerIdentityHomeDir, evaluateDreamerSeedSuppression, pendingOwnerDecision, ReuseEvaluationRunner, ReuseEvaluationError, createBridgeTelemetryEventEmitter, auditCandidateLedgerConsistency, } from '@principles/core/runtime';
|
|
21
|
+
buildReuseProposal, buildReuseShortlist, extractIntakeRecommendation, isPrincipleLedgerEligibleKind, resolveOwnerIdentity, defaultOwnerIdentityHomeDir, evaluateDreamerSeedSuppression, pendingOwnerDecision, validateRecommendationKind, ReuseEvaluationRunner, ReuseEvaluationError, createBridgeTelemetryEventEmitter, auditCandidateLedgerConsistency, } from '@principles/core/runtime';
|
|
21
22
|
import { loadLedger, getLedgerFilePathPublic } from '@principles/core/principle-tree-ledger';
|
|
22
23
|
import { resolveWorkspaceDir } from '../resolve-workspace.js';
|
|
23
24
|
import { createWorkspaceTelemetryEmitter } from '../services/workspace-telemetry.js';
|
|
@@ -254,9 +255,10 @@ export async function handleCandidateInternalize(opts) {
|
|
|
254
255
|
// PRI-1267 review round: `--dry-run` previews must not mutate the persisted
|
|
255
256
|
// admission document, so the preview path re-evaluates WITHOUT persisting
|
|
256
257
|
// (same verdict, zero writes — cli-4).
|
|
258
|
+
const coordinationLedgerAdapter = new PrincipleTreeLedgerAdapter({ stateDir: path.join(workspaceDir, '.state') });
|
|
257
259
|
let fullGate;
|
|
258
260
|
try {
|
|
259
|
-
fullGate = await enforceFullAdmissionForWrite(stateManager, opts.candidateId, { persistReevaluation: opts.dryRun !== true, sourceMaterialAuthorization });
|
|
261
|
+
fullGate = await enforceFullAdmissionForWrite(stateManager, opts.candidateId, { persistReevaluation: opts.dryRun !== true, sourceMaterialAuthorization, coordination: coordinationLedgerAdapter });
|
|
260
262
|
}
|
|
261
263
|
catch (err) {
|
|
262
264
|
const result = {
|
|
@@ -373,108 +375,317 @@ export async function handleCandidateInternalize(opts) {
|
|
|
373
375
|
return;
|
|
374
376
|
}
|
|
375
377
|
const { channel } = seed;
|
|
376
|
-
|
|
377
|
-
const result = {
|
|
378
|
-
candidateId: opts.candidateId,
|
|
379
|
-
route: decision.route,
|
|
380
|
-
channel: seed.channel,
|
|
381
|
-
status: 'dry_run',
|
|
382
|
-
reason: 'Dry-run mode — no task created',
|
|
383
|
-
};
|
|
384
|
-
if (opts.json) {
|
|
385
|
-
console.log(JSON.stringify(result, null, 2));
|
|
386
|
-
}
|
|
387
|
-
else {
|
|
388
|
-
console.log(`\nCandidate Internalize (dry-run): ${opts.candidateId}\n`);
|
|
389
|
-
console.log(` Route: ${decision.route}`);
|
|
390
|
-
console.log(` Channel: ${channel}`);
|
|
391
|
-
console.log(` Would create: dreamer PI task`);
|
|
392
|
-
console.log('');
|
|
393
|
-
}
|
|
394
|
-
return;
|
|
395
|
-
}
|
|
396
|
-
// PRI-720 C6: candidate-level dedup (demotion may change the derived
|
|
397
|
-
// channel suffix vs a pre-existing chain).
|
|
398
|
-
const existingTask = await findExistingDreamerTask((id) => stateManager.getTask(id), opts.candidateId);
|
|
399
|
-
if (existingTask) {
|
|
400
|
-
const result = {
|
|
401
|
-
candidateId: opts.candidateId,
|
|
402
|
-
route: decision.route,
|
|
403
|
-
taskId: existingTask.taskId,
|
|
404
|
-
channel: seed.channel,
|
|
405
|
-
status: 'existing',
|
|
406
|
-
reason: 'Task already exists for this candidate (any channel variant)',
|
|
407
|
-
};
|
|
408
|
-
if (opts.json) {
|
|
409
|
-
console.log(JSON.stringify(result, null, 2));
|
|
410
|
-
}
|
|
411
|
-
else {
|
|
412
|
-
console.log(`\nCandidate Internalize: ${opts.candidateId}\n`);
|
|
413
|
-
console.log(` Route: ${decision.route}`);
|
|
414
|
-
console.log(` Channel: ${channel}`);
|
|
415
|
-
console.log(` Task: ${existingTask.taskId} (existing)`);
|
|
416
|
-
console.log('');
|
|
417
|
-
}
|
|
418
|
-
return;
|
|
419
|
-
}
|
|
420
|
-
// PRI-1268: the Dreamer-task enqueue is a store write that can fail for
|
|
421
|
-
// environmental reasons (readonly state.db, locked store, disk). A bare
|
|
422
|
-
// SqliteError stack on stderr with EMPTY --json stdout is not an operator
|
|
423
|
-
// result. cli-1-strict-json / cli-6-output-next-action: --json emits ONE
|
|
424
|
-
// structured object with a stable reason code + nextAction and the process
|
|
425
|
-
// exits non-zero; the candidate status and task count are unchanged
|
|
426
|
-
// (cli-5-failure-no-mutation — createTask itself is atomic per row).
|
|
427
|
-
let task;
|
|
378
|
+
let outcome;
|
|
428
379
|
try {
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
380
|
+
outcome = await coordinationLedgerAdapter.withCandidateCoordination(opts.candidateId, async () => {
|
|
381
|
+
// (1) The RAW persisted kind is re-read INSIDE the lock — it drives
|
|
382
|
+
// the identity decision below (candidate-store contract: the
|
|
383
|
+
// normalized `recommendationKind` folds invalid values to 'principle';
|
|
384
|
+
// never use it for a write-boundary decision).
|
|
385
|
+
const current = await stateManager.getCandidate(opts.candidateId);
|
|
386
|
+
if (!current) {
|
|
387
|
+
return {
|
|
388
|
+
kind: 'refused',
|
|
389
|
+
headline: `Candidate not found: ${opts.candidateId}`,
|
|
390
|
+
result: {
|
|
391
|
+
candidateId: opts.candidateId,
|
|
392
|
+
route: decision.route,
|
|
393
|
+
status: 'refused',
|
|
394
|
+
reason: 'candidate_unreadable',
|
|
395
|
+
nextAction: 'Verify candidate ID and run pd candidate show <id> to check existence',
|
|
396
|
+
},
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
// the route decision and the seed above were derived from the row read
|
|
400
|
+
// before the lock: a kind that changed in between invalidates them
|
|
401
|
+
if (JSON.stringify(current) !== JSON.stringify(candidate)) {
|
|
402
|
+
return {
|
|
403
|
+
kind: 'refused',
|
|
404
|
+
headline: `Candidate ${opts.candidateId} changed while it was being internalized`,
|
|
405
|
+
result: {
|
|
406
|
+
candidateId: opts.candidateId,
|
|
407
|
+
route: decision.route,
|
|
408
|
+
status: 'refused',
|
|
409
|
+
reason: 'candidate_changed_during_internalize',
|
|
410
|
+
nextAction: 'The candidate row was modified by another writer; re-run pd candidate internalize to decide on the current row',
|
|
411
|
+
},
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
const rawKind = validateRecommendationKind(current.rawRecommendationKind);
|
|
415
|
+
if (rawKind !== null && (rawKind !== current.recommendationKind || rawKind !== recommendation.kind)) {
|
|
416
|
+
return {
|
|
417
|
+
kind: 'refused',
|
|
418
|
+
headline: `Refusing to internalize candidate ${opts.candidateId}: persisted RAW kind does not match the normalized route kind.`,
|
|
419
|
+
result: {
|
|
420
|
+
candidateId: opts.candidateId,
|
|
421
|
+
route: decision.route,
|
|
422
|
+
status: 'refused',
|
|
423
|
+
reason: 'candidate_kind_mismatch',
|
|
424
|
+
nextAction: 'Repair the persisted recommendation_kind so the RAW and normalized candidate kinds agree, then re-run internalize; no Dreamer task was created.',
|
|
425
|
+
},
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
// (2) existing-task dedup runs BEFORE the identity gate — a candidate
|
|
429
|
+
// whose ledger identity changed after its Dreamer task was created
|
|
430
|
+
// must report the EXISTING task, not a retrospective refusal.
|
|
431
|
+
// PRI-720 C6: candidate-level dedup (demotion may change the derived
|
|
432
|
+
// channel suffix vs a pre-existing chain).
|
|
433
|
+
const existingTask = await findExistingDreamerTask((id) => stateManager.getTask(id), opts.candidateId);
|
|
434
|
+
if (existingTask) {
|
|
435
|
+
return {
|
|
436
|
+
kind: 'existing',
|
|
437
|
+
result: {
|
|
438
|
+
candidateId: opts.candidateId,
|
|
439
|
+
route: decision.route,
|
|
440
|
+
taskId: existingTask.taskId,
|
|
441
|
+
channel: seed.channel,
|
|
442
|
+
status: 'existing',
|
|
443
|
+
reason: 'Task already exists for this candidate (any channel variant)',
|
|
444
|
+
},
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
if (rawKind === null) {
|
|
448
|
+
// An invalid or missing RAW kind is a type violation of the identity
|
|
449
|
+
// authority (`candidate_kind_invalid`): nothing may be seeded, and
|
|
450
|
+
// no command is suggested that would be refused for the same reason.
|
|
451
|
+
return {
|
|
452
|
+
kind: 'refused',
|
|
453
|
+
headline: `Refusing to internalize candidate ${opts.candidateId}: candidate_kind_invalid`,
|
|
454
|
+
result: {
|
|
455
|
+
candidateId: opts.candidateId,
|
|
456
|
+
route: decision.route,
|
|
457
|
+
status: 'refused',
|
|
458
|
+
reason: 'candidate_kind_invalid',
|
|
459
|
+
nextAction: 'The persisted recommendation_kind is not a valid kind; no task was created. Re-run the diagnosis or repair the candidate row before internalizing.',
|
|
460
|
+
},
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
// (3) Authority identity + seed suppression — single-snapshot reuse
|
|
464
|
+
// of the SAME mechanisms the automatic entries (PainSignalBridge /
|
|
465
|
+
// diagnose seed loop) use; never a second identity authority.
|
|
466
|
+
const identity = coordinationLedgerAdapter.resolveCandidatePrincipleIdentity(opts.candidateId, current.rawRecommendationKind);
|
|
467
|
+
const gateAdmissionDoc = await stateManager.getAdmissionDocument(opts.candidateId);
|
|
468
|
+
if (!gateAdmissionDoc.ok) {
|
|
469
|
+
// candidate-store contract: { ok: false } is a damaged/unreadable
|
|
470
|
+
// document — NEVER folded into "no document". Fail closed.
|
|
471
|
+
return {
|
|
472
|
+
kind: 'refused',
|
|
473
|
+
headline: `Admission document unreadable for candidate ${opts.candidateId}; refusing to internalize.`,
|
|
474
|
+
result: {
|
|
475
|
+
candidateId: opts.candidateId,
|
|
476
|
+
route: decision.route,
|
|
477
|
+
status: 'refused',
|
|
478
|
+
reason: 'admission_document_unreadable',
|
|
479
|
+
nextAction: 'Inspect principle_candidates.admission_json for this candidate; repair the document or re-run the diagnosis',
|
|
480
|
+
},
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
const processing = gateAdmissionDoc.document?.processing;
|
|
484
|
+
if (processing?.state === 'awaiting_owner'
|
|
485
|
+
&& typeof processing.blockedReason === 'string'
|
|
486
|
+
&& processing.blockedReason.startsWith('candidate_kind_invalid')) {
|
|
487
|
+
return {
|
|
488
|
+
kind: 'refused',
|
|
489
|
+
headline: `Dreamer seed blocked for candidate ${opts.candidateId}: invalid-kind recovery has not been authorized.`,
|
|
490
|
+
result: {
|
|
491
|
+
candidateId: opts.candidateId,
|
|
492
|
+
route: decision.route,
|
|
493
|
+
status: 'refused',
|
|
494
|
+
reason: 'candidate_kind_recovery_required',
|
|
495
|
+
nextAction: `After repairing the persisted RAW kind, run pd candidate resume-post-processing --candidate-id ${opts.candidateId} --workspace "${workspaceDir}" --reason "<why this repair is safe>" --confirm. Do not use internalize to bypass the saved park.`,
|
|
496
|
+
},
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
const currentEvaluation = gateAdmissionDoc.document?.evaluations.find((evaluation) => evaluation.evaluationId === gateAdmissionDoc.document?.currentEvaluationId);
|
|
500
|
+
if ((currentEvaluation === undefined && opts.dryRun !== true) || (currentEvaluation !== undefined && currentEvaluation.decision !== 'admitted')) {
|
|
501
|
+
return {
|
|
502
|
+
kind: 'refused',
|
|
503
|
+
headline: `Admission changed while candidate ${opts.candidateId} was being internalized.`,
|
|
504
|
+
result: {
|
|
505
|
+
candidateId: opts.candidateId,
|
|
506
|
+
route: decision.route,
|
|
507
|
+
status: 'refused',
|
|
508
|
+
reason: currentEvaluation?.reason ?? 'admission_evaluation_missing',
|
|
509
|
+
nextAction: 'Re-run the full admission check and inspect the latest persisted admission evaluation; no Dreamer task was created.',
|
|
510
|
+
},
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
const gatePending = pendingOwnerDecision(gateAdmissionDoc.document ?? null);
|
|
514
|
+
const suppression = evaluateDreamerSeedSuppression({
|
|
515
|
+
identity,
|
|
516
|
+
processing: gateAdmissionDoc.document?.processing,
|
|
517
|
+
...(gatePending !== null ? { pendingOwnerDecision: { decision: gatePending.decision } } : {}),
|
|
518
|
+
});
|
|
519
|
+
if (suppression.suppress) {
|
|
520
|
+
const suppressionReason = suppression.reason === 'reuse_resolved_to_existing_principle'
|
|
521
|
+
? `dreamer_seed_suppressed: candidate is durably resolved onto existing principle ${suppression.principleId} (reuseEvidence)`
|
|
522
|
+
: `dreamer_seed_suppressed: ${suppression.reason}`;
|
|
523
|
+
const pendingDecision = gatePending;
|
|
524
|
+
const pendingPrincipleArg = pendingDecision?.decision === 'reuse' && pendingDecision.selectedPrincipleId
|
|
525
|
+
? ` --principle-id ${pendingDecision.selectedPrincipleId}`
|
|
526
|
+
: '';
|
|
527
|
+
const suppressionNextAction = suppression.reason === 'owner_decision_pending'
|
|
528
|
+
? `pd candidate review --candidate-id ${opts.candidateId} --workspace "${workspaceDir}" --decide ${pendingDecision?.decision ?? 'reuse'}${pendingPrincipleArg} --reason "..." (re-run the SAME verdict if it was interrupted)`
|
|
529
|
+
: suppression.reason === 'reuse_resolved_to_existing_principle'
|
|
530
|
+
? 'No independent Dreamer chain by design; the candidate is durably resolved onto the existing principle.'
|
|
531
|
+
: `pd candidate review --candidate-id ${opts.candidateId} --decide reuse|create --reason "..."`;
|
|
532
|
+
return {
|
|
533
|
+
kind: 'refused',
|
|
534
|
+
headline: `Dreamer seed suppressed for candidate ${opts.candidateId}: ${suppressionReason}`,
|
|
535
|
+
result: {
|
|
536
|
+
candidateId: opts.candidateId,
|
|
537
|
+
route: decision.route,
|
|
538
|
+
status: 'refused',
|
|
539
|
+
reason: suppressionReason,
|
|
540
|
+
nextAction: suppressionNextAction,
|
|
541
|
+
},
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
if (identity.status !== 'resolved') {
|
|
545
|
+
// Only a PRINCIPLE candidate needs a ledger identity before a
|
|
546
|
+
// Dreamer seed: it is the one kind `pd candidate intake` writes
|
|
547
|
+
// into the ledger. For a rule or prompt candidate an ABSENT
|
|
548
|
+
// identity is the normal pre-binding state — a new rule candidate
|
|
549
|
+
// gets its Owner binding at the ScribeRunner preflight
|
|
550
|
+
// (awaiting_owner_binding), the SAME window PainSignalBridge and
|
|
551
|
+
// the diagnose seed loop allow, and prompt candidates never enter
|
|
552
|
+
// the ledger. Refusing them with `pd candidate intake` as the way
|
|
553
|
+
// out recommended a command that answers `non_principle_kind`
|
|
554
|
+
// (review round 2, P2-1). Every OTHER unresolved reason —
|
|
555
|
+
// unreadable / corrupt / ambiguous ledger, revoked binding,
|
|
556
|
+
// ineligible target — still fails closed for every kind.
|
|
557
|
+
const identityOptional = identity.reason === 'missing' && rawKind !== 'principle';
|
|
558
|
+
if (!identityOptional) {
|
|
559
|
+
const identityReason = identity.reason === 'missing'
|
|
560
|
+
? 'candidate_not_in_ledger'
|
|
561
|
+
: `ledger_identity_${identity.reason}`;
|
|
562
|
+
const identityNextAction = identity.reason === 'missing'
|
|
563
|
+
? `pd candidate intake --candidate-id ${opts.candidateId} --workspace "${workspaceDir}"`
|
|
564
|
+
: identity.nextAction;
|
|
565
|
+
return {
|
|
566
|
+
kind: 'refused',
|
|
567
|
+
headline: `Refusing to internalize candidate ${opts.candidateId}: ${identityReason}`,
|
|
568
|
+
result: {
|
|
569
|
+
candidateId: opts.candidateId,
|
|
570
|
+
route: decision.route,
|
|
571
|
+
status: 'refused',
|
|
572
|
+
reason: identityReason,
|
|
573
|
+
nextAction: identityNextAction,
|
|
574
|
+
},
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
if (opts.dryRun) {
|
|
579
|
+
return {
|
|
580
|
+
kind: 'dry_run',
|
|
581
|
+
result: {
|
|
582
|
+
candidateId: opts.candidateId,
|
|
583
|
+
route: decision.route,
|
|
584
|
+
channel: seed.channel,
|
|
585
|
+
status: 'dry_run',
|
|
586
|
+
reason: 'Dry-run mode — no task created',
|
|
587
|
+
},
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
// PRI-1268: the Dreamer-task enqueue is a store write that can fail for
|
|
591
|
+
// environmental reasons (readonly state.db, locked store, disk). A bare
|
|
592
|
+
// SqliteError stack on stderr with EMPTY --json stdout is not an operator
|
|
593
|
+
// result. cli-1-strict-json / cli-6-output-next-action: --json emits ONE
|
|
594
|
+
// structured object with a stable reason code + nextAction and the process
|
|
595
|
+
// exits non-zero; the candidate status and task count are unchanged
|
|
596
|
+
// (cli-5-failure-no-mutation — createTask itself is atomic per row).
|
|
597
|
+
try {
|
|
598
|
+
const task = await stateManager.createTask({
|
|
599
|
+
taskId: seed.taskId,
|
|
600
|
+
taskKind: seed.taskKind,
|
|
601
|
+
status: seed.status,
|
|
602
|
+
attemptCount: seed.attemptCount,
|
|
603
|
+
maxAttempts: seed.maxAttempts,
|
|
604
|
+
diagnosticJson: seed.diagnosticJson,
|
|
605
|
+
});
|
|
606
|
+
return {
|
|
607
|
+
kind: 'created',
|
|
608
|
+
result: {
|
|
609
|
+
candidateId: opts.candidateId,
|
|
610
|
+
route: decision.route,
|
|
611
|
+
taskId: task.taskId,
|
|
612
|
+
channel: seed.channel,
|
|
613
|
+
status: 'created',
|
|
614
|
+
},
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
catch (err) {
|
|
618
|
+
// rc-8-safe-serialization: bounded, single-line, control chars stripped —
|
|
619
|
+
// the raw store error never reaches logs verbatim.
|
|
620
|
+
const detail = boundedStoreErrorDetail(err);
|
|
621
|
+
return {
|
|
622
|
+
kind: 'write_failed',
|
|
623
|
+
headline: `Candidate Internalize FAILED for ${opts.candidateId}: task enqueue write failed.`,
|
|
624
|
+
reasonLine: `Reason: internalize_task_write_failed:${detail}`,
|
|
625
|
+
result: {
|
|
626
|
+
candidateId: opts.candidateId,
|
|
627
|
+
route: decision.route,
|
|
628
|
+
channel: seed.channel,
|
|
629
|
+
status: 'write_failed',
|
|
630
|
+
reason: `internalize_task_write_failed:${detail}`,
|
|
631
|
+
nextAction: `The Dreamer task was NOT created and the candidate is unchanged. Fix the underlying state store failure (unlock .pd/state.db / check disk permissions), verify with "pd task show ${seed.taskId} --workspace <workspace>", then re-run pd candidate internalize (idempotent).`,
|
|
632
|
+
},
|
|
633
|
+
};
|
|
634
|
+
}
|
|
436
635
|
});
|
|
437
636
|
}
|
|
438
637
|
catch (err) {
|
|
439
|
-
//
|
|
440
|
-
//
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
638
|
+
// The coordination lock fails LOUD after its bounded retry budget
|
|
639
|
+
// (adapter contract: a contender never bypasses it) — another process
|
|
640
|
+
// is still operating on this candidate. A structured refusal, never a
|
|
641
|
+
// bare stack with an empty --json stdout (cli-1-strict-json /
|
|
642
|
+
// cli-6-output-next-action).
|
|
643
|
+
if (err instanceof Error && err.name === 'LockAcquisitionError') {
|
|
644
|
+
outcome = {
|
|
645
|
+
kind: 'refused',
|
|
646
|
+
headline: `Candidate ${opts.candidateId} is busy; refusing to internalize.`,
|
|
647
|
+
result: {
|
|
648
|
+
candidateId: opts.candidateId,
|
|
649
|
+
route: decision.route,
|
|
650
|
+
status: 'refused',
|
|
651
|
+
reason: 'candidate_coordination_lock_timeout',
|
|
652
|
+
nextAction: `Another pd command is still operating on candidate ${opts.candidateId}; wait for it to finish, then re-run pd candidate internalize (idempotent).`,
|
|
653
|
+
},
|
|
654
|
+
};
|
|
452
655
|
}
|
|
453
656
|
else {
|
|
454
|
-
|
|
455
|
-
console.error(` Reason: ${result.reason}`);
|
|
456
|
-
console.error(` Next Action: ${result.nextAction}`);
|
|
657
|
+
throw err;
|
|
457
658
|
}
|
|
458
|
-
process.exit(1);
|
|
459
|
-
return;
|
|
460
659
|
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
route: decision.route,
|
|
464
|
-
taskId: task.taskId,
|
|
465
|
-
channel: seed.channel,
|
|
466
|
-
status: 'created',
|
|
467
|
-
};
|
|
660
|
+
// ── report AFTER the lock is released (the critical section never prints
|
|
661
|
+
// and never exits, so a refusal cannot leave the lock held) ──
|
|
468
662
|
if (opts.json) {
|
|
469
|
-
console.log(JSON.stringify(result, null, 2));
|
|
663
|
+
console.log(JSON.stringify(outcome.result, null, 2));
|
|
470
664
|
}
|
|
471
|
-
else {
|
|
665
|
+
else if (outcome.kind === 'refused' || outcome.kind === 'write_failed') {
|
|
666
|
+
console.error(outcome.headline);
|
|
667
|
+
if (outcome.reasonLine !== undefined) {
|
|
668
|
+
console.error(` ${outcome.reasonLine}`);
|
|
669
|
+
}
|
|
670
|
+
console.error(` Next Action: ${outcome.result.nextAction}`);
|
|
671
|
+
}
|
|
672
|
+
else if (outcome.kind === 'created' || outcome.kind === 'existing') {
|
|
472
673
|
console.log(`\nCandidate Internalize: ${opts.candidateId}\n`);
|
|
473
674
|
console.log(` Route: ${decision.route}`);
|
|
474
675
|
console.log(` Channel: ${channel}`);
|
|
475
|
-
console.log(` Task: ${
|
|
676
|
+
console.log(` Task: ${outcome.result.taskId} (${outcome.kind === 'created' ? 'created' : 'existing'})`);
|
|
677
|
+
console.log('');
|
|
678
|
+
}
|
|
679
|
+
else {
|
|
680
|
+
console.log(`\nCandidate Internalize (dry-run): ${opts.candidateId}\n`);
|
|
681
|
+
console.log(` Route: ${decision.route}`);
|
|
682
|
+
console.log(` Channel: ${channel}`);
|
|
683
|
+
console.log(` Would create: dreamer PI task`);
|
|
476
684
|
console.log('');
|
|
477
685
|
}
|
|
686
|
+
if (outcome.kind === 'refused' || outcome.kind === 'write_failed') {
|
|
687
|
+
process.exit(1);
|
|
688
|
+
}
|
|
478
689
|
}
|
|
479
690
|
finally {
|
|
480
691
|
await stateManager.close();
|
|
@@ -977,13 +1188,20 @@ async function seedDreamerForConsumedCandidate(deps) {
|
|
|
977
1188
|
// exploration of an already-learned mechanism. Fail-open on an unexpected
|
|
978
1189
|
// read failure (same posture as the bridge).
|
|
979
1190
|
let suppression;
|
|
1191
|
+
let pendingDecision = null;
|
|
980
1192
|
try {
|
|
981
1193
|
const admissionDoc = await deps.stateManager.getAdmissionDocument(deps.candidateId);
|
|
982
|
-
|
|
1194
|
+
pendingDecision = pendingOwnerDecision(admissionDoc.ok ? admissionDoc.document ?? null : null);
|
|
983
1195
|
suppression = evaluateDreamerSeedSuppression({
|
|
984
|
-
|
|
1196
|
+
// The suppression verdict reads the candidate's LEDGER LINEAGE, which
|
|
1197
|
+
// does not depend on the delivery kind: it is resolved with the
|
|
1198
|
+
// NORMALIZED kind, so a candidate whose RAW kind is invalid but which
|
|
1199
|
+
// the ledger records as reuse-resolved (or reuse-parked) is still
|
|
1200
|
+
// suppressed here. The raw-kind refusal is decided separately below —
|
|
1201
|
+
// an invalid kind never re-opens seeding (review round 2).
|
|
1202
|
+
identity: deps.ledgerAdapter.resolveCandidatePrincipleIdentity(deps.candidateId, candidate.recommendationKind),
|
|
985
1203
|
processing: admissionDoc.ok ? admissionDoc.document?.processing : undefined,
|
|
986
|
-
...(
|
|
1204
|
+
...(pendingDecision !== null ? { pendingOwnerDecision: { decision: pendingDecision.decision } } : {}),
|
|
987
1205
|
});
|
|
988
1206
|
}
|
|
989
1207
|
catch {
|
|
@@ -998,10 +1216,13 @@ async function seedDreamerForConsumedCandidate(deps) {
|
|
|
998
1216
|
};
|
|
999
1217
|
}
|
|
1000
1218
|
if (suppression.reason === 'owner_decision_pending') {
|
|
1219
|
+
const pendingPrincipleArg = pendingDecision?.decision === 'reuse' && pendingDecision.selectedPrincipleId
|
|
1220
|
+
? ` --principle-id ${pendingDecision.selectedPrincipleId}`
|
|
1221
|
+
: '';
|
|
1001
1222
|
return {
|
|
1002
1223
|
status: 'not_seeded',
|
|
1003
1224
|
reason: `dreamer_seed_suppressed: an Owner ${suppression.decision} decision is recorded but its execution has not completed`,
|
|
1004
|
-
nextAction: `pd candidate review --candidate-id ${deps.candidateId} --decide
|
|
1225
|
+
nextAction: `pd candidate review --candidate-id ${deps.candidateId} --workspace "${deps.workspaceDir}" --decide ${pendingDecision?.decision ?? suppression.decision}${pendingPrincipleArg} --reason "..." (re-run the SAME verdict to resume the recorded decision)`,
|
|
1005
1226
|
};
|
|
1006
1227
|
}
|
|
1007
1228
|
return {
|
|
@@ -1010,6 +1231,17 @@ async function seedDreamerForConsumedCandidate(deps) {
|
|
|
1010
1231
|
nextAction: `pd candidate review --candidate-id ${deps.candidateId} --decide reuse|create --reason "..."`,
|
|
1011
1232
|
};
|
|
1012
1233
|
}
|
|
1234
|
+
// SPEC-PD-PIPELINE-SPINE-001 D4: an invalid or missing RAW kind never
|
|
1235
|
+
// seeds. Decided AFTER the Owner park / reuse checks above, so those still
|
|
1236
|
+
// win — the recorded Owner decision is the stronger fact — but an invalid
|
|
1237
|
+
// kind can never re-open the seeding they would otherwise have closed.
|
|
1238
|
+
if (validateRecommendationKind(candidate.rawRecommendationKind) === null) {
|
|
1239
|
+
return {
|
|
1240
|
+
status: 'not_seeded',
|
|
1241
|
+
reason: 'candidate_kind_invalid: the persisted recommendation_kind is not a valid kind; no Dreamer task was created',
|
|
1242
|
+
nextAction: 'Repair the candidate row or re-run the diagnosis; do not internalize this candidate.',
|
|
1243
|
+
};
|
|
1244
|
+
}
|
|
1013
1245
|
const recommendation = resolveCandidateRecommendation(candidate, deps.stateManager, deps.candidateId);
|
|
1014
1246
|
// The create decision already admitted this principle into the ledger, so
|
|
1015
1247
|
// its text is ledger-eligible even when the diagnostician used `description`
|
|
@@ -1738,6 +1970,130 @@ export async function handleCandidateRepair(opts) {
|
|
|
1738
1970
|
await stateManager.close();
|
|
1739
1971
|
}
|
|
1740
1972
|
}
|
|
1973
|
+
/**
|
|
1974
|
+
* Resume only a candidate whose post-processing was parked by an invalid RAW
|
|
1975
|
+
* recommendation kind. The data repair is performed separately; this command
|
|
1976
|
+
* is an explicit, ADR-0022-verified Owner authorization that appends an audit
|
|
1977
|
+
* record and moves the existing processing state to in_progress. It never
|
|
1978
|
+
* creates a Dreamer task directly and never releases a genuine Owner park.
|
|
1979
|
+
*/
|
|
1980
|
+
export async function handleCandidatePostProcessingRecovery(opts) {
|
|
1981
|
+
const workspaceDir = resolveWorkspaceDir(opts.workspace);
|
|
1982
|
+
const reason = opts.reason.trim();
|
|
1983
|
+
const output = (value, failed = false) => {
|
|
1984
|
+
if (opts.json)
|
|
1985
|
+
console.log(JSON.stringify(value, null, 2));
|
|
1986
|
+
else {
|
|
1987
|
+
const status = String(value.status ?? 'refused');
|
|
1988
|
+
console.log(`\nCandidate Post-processing Recovery: ${opts.candidateId}\n`);
|
|
1989
|
+
console.log(` Status: ${status}`);
|
|
1990
|
+
if (typeof value.reason === 'string')
|
|
1991
|
+
console.log(` Reason: ${value.reason}`);
|
|
1992
|
+
if (typeof value.recoveryId === 'string')
|
|
1993
|
+
console.log(` Recovery: ${value.recoveryId}`);
|
|
1994
|
+
if (typeof value.ownerId === 'string')
|
|
1995
|
+
console.log(` Owner: ${value.ownerId} (${String(value.identitySource)})`);
|
|
1996
|
+
if (typeof value.nextAction === 'string')
|
|
1997
|
+
console.log(` Next: ${value.nextAction}`);
|
|
1998
|
+
console.log('');
|
|
1999
|
+
}
|
|
2000
|
+
if (failed)
|
|
2001
|
+
process.exitCode = 1;
|
|
2002
|
+
};
|
|
2003
|
+
if (!opts.confirm) {
|
|
2004
|
+
output({
|
|
2005
|
+
candidateId: opts.candidateId,
|
|
2006
|
+
status: 'confirmation_required',
|
|
2007
|
+
reason: 'explicit_owner_confirmation_required',
|
|
2008
|
+
nextAction: `After confirming the raw kind is repaired, run pd candidate resume-post-processing --candidate-id ${opts.candidateId} --workspace "${workspaceDir}" --reason "<why this repair is safe>" --confirm. This operation only authorizes the existing worker backlog; it does not create a Dreamer task.`,
|
|
2009
|
+
}, true);
|
|
2010
|
+
return;
|
|
2011
|
+
}
|
|
2012
|
+
const containsControlCharacter = [...reason].some((character) => {
|
|
2013
|
+
const code = character.charCodeAt(0);
|
|
2014
|
+
return code <= 0x1f || code === 0x7f;
|
|
2015
|
+
});
|
|
2016
|
+
if (reason.length === 0 || reason.length > 500 || containsControlCharacter) {
|
|
2017
|
+
output({
|
|
2018
|
+
candidateId: opts.candidateId,
|
|
2019
|
+
status: 'refused',
|
|
2020
|
+
reason: 'recovery_reason_invalid',
|
|
2021
|
+
nextAction: 'Provide a non-empty --reason of at most 500 characters without control characters.',
|
|
2022
|
+
}, true);
|
|
2023
|
+
return;
|
|
2024
|
+
}
|
|
2025
|
+
let identity;
|
|
2026
|
+
try {
|
|
2027
|
+
identity = resolveOwnerIdentity(process.env, defaultOwnerIdentityHomeDir());
|
|
2028
|
+
}
|
|
2029
|
+
catch {
|
|
2030
|
+
output({
|
|
2031
|
+
candidateId: opts.candidateId,
|
|
2032
|
+
status: 'refused',
|
|
2033
|
+
reason: 'owner_identity_home_unavailable',
|
|
2034
|
+
nextAction: 'Repair the configured PD Owner identity home; no recovery was authorized.',
|
|
2035
|
+
}, true);
|
|
2036
|
+
return;
|
|
2037
|
+
}
|
|
2038
|
+
const verifiedOwnerId = identity.ownerId;
|
|
2039
|
+
if ((identity.source !== 'env' && identity.source !== 'file')
|
|
2040
|
+
|| typeof verifiedOwnerId !== 'string' || verifiedOwnerId.length === 0
|
|
2041
|
+
|| !identity.credentialId) {
|
|
2042
|
+
output({
|
|
2043
|
+
candidateId: opts.candidateId,
|
|
2044
|
+
status: 'refused',
|
|
2045
|
+
reason: identity.error ?? 'verified_owner_identity_required',
|
|
2046
|
+
nextAction: 'Register the Owner identity through the existing PD Owner identity flow, then retry. A CLI-supplied owner name is not accepted.',
|
|
2047
|
+
}, true);
|
|
2048
|
+
return;
|
|
2049
|
+
}
|
|
2050
|
+
const stateManager = new RuntimeStateManager({ workspaceDir });
|
|
2051
|
+
try {
|
|
2052
|
+
await stateManager.initialize();
|
|
2053
|
+
const ledgerAdapter = new PrincipleTreeLedgerAdapter({ stateDir: path.join(workspaceDir, '.state') });
|
|
2054
|
+
const recovery = await ledgerAdapter.withCandidateCoordination(opts.candidateId, async () => stateManager.authorizeInvalidKindPostProcessingRecovery(opts.candidateId, {
|
|
2055
|
+
ownerId: verifiedOwnerId,
|
|
2056
|
+
identitySource: identity.source,
|
|
2057
|
+
reason,
|
|
2058
|
+
authorizedAt: new Date().toISOString(),
|
|
2059
|
+
}));
|
|
2060
|
+
if (recovery.status === 'refused') {
|
|
2061
|
+
const nextAction = recovery.reason === 'candidate_kind_still_invalid'
|
|
2062
|
+
? 'Repair the persisted principle_candidates.recommendation_kind to a valid seedable kind first; do not bypass the invalid-kind refusal.'
|
|
2063
|
+
: recovery.reason === 'owner_decision_pending_recovery_forbidden' || recovery.reason === 'processing_not_blocked_by_invalid_raw_kind'
|
|
2064
|
+
? 'This is not an invalid-kind-only park. Preserve the Owner decision/reuse state and use the existing pd candidate review flow.'
|
|
2065
|
+
: recovery.reason === 'candidate_kind_has_no_dreamer_route'
|
|
2066
|
+
? 'The repaired kind has no enabled Dreamer route; do not resume it as an internalization candidate.'
|
|
2067
|
+
: 'Inspect the candidate admission processing record; recovery was refused without changing it.';
|
|
2068
|
+
output({ candidateId: opts.candidateId, status: 'refused', reason: recovery.reason, nextAction }, true);
|
|
2069
|
+
return;
|
|
2070
|
+
}
|
|
2071
|
+
const recoveryRecord = recovery.recovery;
|
|
2072
|
+
output({
|
|
2073
|
+
candidateId: opts.candidateId,
|
|
2074
|
+
status: recovery.status,
|
|
2075
|
+
recoveryId: recoveryRecord.recoveryId,
|
|
2076
|
+
ownerId: recoveryRecord.ownerId,
|
|
2077
|
+
identitySource: recoveryRecord.identitySource,
|
|
2078
|
+
rawRecommendationKind: recoveryRecord.rawRecommendationKind,
|
|
2079
|
+
priorBlockedReason: recoveryRecord.priorBlockedReason,
|
|
2080
|
+
processingState: recovery.document.processing?.state ?? null,
|
|
2081
|
+
nextAction: 'The existing diagnosis post-processing worker will pick up this in_progress candidate on its next cycle. The audit and backlog state survive worker restart. This command does not create a Dreamer task.',
|
|
2082
|
+
});
|
|
2083
|
+
}
|
|
2084
|
+
catch (error) {
|
|
2085
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2086
|
+
output({
|
|
2087
|
+
candidateId: opts.candidateId,
|
|
2088
|
+
status: 'refused',
|
|
2089
|
+
reason: message.includes('LockAcquisitionError') ? 'candidate_coordination_lock_timeout' : 'candidate_post_processing_recovery_failed',
|
|
2090
|
+
nextAction: 'No recovery was authorized. Wait for any candidate operation to finish, inspect the admission document, and retry only after confirming the raw kind is repaired.',
|
|
2091
|
+
}, true);
|
|
2092
|
+
}
|
|
2093
|
+
finally {
|
|
2094
|
+
await stateManager.close();
|
|
2095
|
+
}
|
|
2096
|
+
}
|
|
1741
2097
|
function createBackfillRemediationResult(output) {
|
|
1742
2098
|
const actions = output.results
|
|
1743
2099
|
.filter((result) => result.status === 'would_create' || result.status === 'created' || result.status === 'would_intake_and_create' || result.status === 'intake_failed' || result.status === 'intake_succeeded_existing_task')
|