@principles/pd-cli 1.152.11 → 1.152.13
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/dist/commands/candidate.d.ts +3 -3
- package/dist/commands/candidate.d.ts.map +1 -1
- package/dist/commands/candidate.js +9 -21
- package/dist/commands/candidate.js.map +1 -1
- package/dist/index.js +0 -0
- package/dist/services/rulehost-pipeline-runner.d.ts.map +1 -1
- package/dist/services/rulehost-pipeline-runner.js +4 -17
- package/dist/services/rulehost-pipeline-runner.js.map +1 -1
- package/package.json +13 -7
- package/dist/commands/__tests__/intent-flag-wiring.test.d.ts +0 -9
- package/dist/commands/__tests__/intent-flag-wiring.test.d.ts.map +0 -1
- package/dist/commands/__tests__/intent-flag-wiring.test.js +0 -237
- package/dist/commands/__tests__/intent-flag-wiring.test.js.map +0 -1
- package/dist/commands/__tests__/legacy-cleanup.test.d.ts +0 -18
- package/dist/commands/__tests__/legacy-cleanup.test.d.ts.map +0 -1
- package/dist/commands/__tests__/legacy-cleanup.test.js +0 -467
- package/dist/commands/__tests__/legacy-cleanup.test.js.map +0 -1
- package/dist/commands/__tests__/mvp-smoke.test.d.ts +0 -15
- package/dist/commands/__tests__/mvp-smoke.test.d.ts.map +0 -1
- package/dist/commands/__tests__/mvp-smoke.test.js +0 -262
- package/dist/commands/__tests__/mvp-smoke.test.js.map +0 -1
- package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.d.ts +0 -2
- package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.d.ts.map +0 -1
- package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.js +0 -60
- package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.js.map +0 -1
- package/dist/commands/__tests__/rulecode-flag-wiring.test.d.ts +0 -21
- package/dist/commands/__tests__/rulecode-flag-wiring.test.d.ts.map +0 -1
- package/dist/commands/__tests__/rulecode-flag-wiring.test.js +0 -186
- package/dist/commands/__tests__/rulecode-flag-wiring.test.js.map +0 -1
- package/dist/commands/__tests__/rulecode-handler.test.d.ts +0 -16
- package/dist/commands/__tests__/rulecode-handler.test.d.ts.map +0 -1
- package/dist/commands/__tests__/rulecode-handler.test.js +0 -285
- package/dist/commands/__tests__/rulecode-handler.test.js.map +0 -1
- package/dist/commands/__tests__/run-rulehost-flag-wiring.test.d.ts +0 -24
- package/dist/commands/__tests__/run-rulehost-flag-wiring.test.d.ts.map +0 -1
- package/dist/commands/__tests__/run-rulehost-flag-wiring.test.js +0 -232
- package/dist/commands/__tests__/run-rulehost-flag-wiring.test.js.map +0 -1
- package/dist/commands/__tests__/runtime-activation-nextaction.test.d.ts +0 -15
- package/dist/commands/__tests__/runtime-activation-nextaction.test.d.ts.map +0 -1
- package/dist/commands/__tests__/runtime-activation-nextaction.test.js +0 -73
- package/dist/commands/__tests__/runtime-activation-nextaction.test.js.map +0 -1
- package/dist/commands/__tests__/runtime-probe-config.test.d.ts +0 -20
- package/dist/commands/__tests__/runtime-probe-config.test.d.ts.map +0 -1
- package/dist/commands/__tests__/runtime-probe-config.test.js +0 -389
- package/dist/commands/__tests__/runtime-probe-config.test.js.map +0 -1
- package/dist/commands/__tests__/telemetry-flag-wiring.test.d.ts +0 -9
- package/dist/commands/__tests__/telemetry-flag-wiring.test.d.ts.map +0 -1
- package/dist/commands/__tests__/telemetry-flag-wiring.test.js +0 -76
- package/dist/commands/__tests__/telemetry-flag-wiring.test.js.map +0 -1
- package/dist/commands/__tests__/version.test.d.ts +0 -2
- package/dist/commands/__tests__/version.test.d.ts.map +0 -1
- package/dist/commands/__tests__/version.test.js +0 -238
- package/dist/commands/__tests__/version.test.js.map +0 -1
- package/dist/commands/runtime-uat.guard.test.d.ts +0 -2
- package/dist/commands/runtime-uat.guard.test.d.ts.map +0 -1
- package/dist/commands/runtime-uat.guard.test.js +0 -153
- package/dist/commands/runtime-uat.guard.test.js.map +0 -1
- package/dist/services/__tests__/cli-output.test.d.ts +0 -18
- package/dist/services/__tests__/cli-output.test.d.ts.map +0 -1
- package/dist/services/__tests__/cli-output.test.js +0 -103
- package/dist/services/__tests__/cli-output.test.js.map +0 -1
- package/dist/services/__tests__/evaluator-runner-deps.test.d.ts +0 -2
- package/dist/services/__tests__/evaluator-runner-deps.test.d.ts.map +0 -1
- package/dist/services/__tests__/evaluator-runner-deps.test.js +0 -343
- package/dist/services/__tests__/evaluator-runner-deps.test.js.map +0 -1
- package/dist/services/__tests__/rulehost-readiness.test.d.ts +0 -2
- package/dist/services/__tests__/rulehost-readiness.test.d.ts.map +0 -1
- package/dist/services/__tests__/rulehost-readiness.test.js +0 -311
- package/dist/services/__tests__/rulehost-readiness.test.js.map +0 -1
- package/dist/services/__tests__/runtime-adapter-resolver.test.d.ts +0 -18
- package/dist/services/__tests__/runtime-adapter-resolver.test.d.ts.map +0 -1
- package/dist/services/__tests__/runtime-adapter-resolver.test.js +0 -673
- package/dist/services/__tests__/runtime-adapter-resolver.test.js.map +0 -1
- package/dist/utils/production-workspace-guard.test.d.ts +0 -2
- package/dist/utils/production-workspace-guard.test.d.ts.map +0 -1
- package/dist/utils/production-workspace-guard.test.js +0 -137
- package/dist/utils/production-workspace-guard.test.js.map +0 -1
- package/scripts/llm-dogfood.ts +0 -456
- package/scripts/migrate-illegal-expected-decision.ts +0 -252
- package/src/commands/__tests__/intent-flag-wiring.test.ts +0 -282
- package/src/commands/__tests__/legacy-cleanup.test.ts +0 -602
- package/src/commands/__tests__/mvp-smoke.test.ts +0 -300
- package/src/commands/__tests__/pain-retry-maxTokens-flag.test.ts +0 -73
- package/src/commands/__tests__/rulecode-flag-wiring.test.ts +0 -237
- package/src/commands/__tests__/rulecode-handler.test.ts +0 -369
- package/src/commands/__tests__/run-rulehost-flag-wiring.test.ts +0 -292
- package/src/commands/__tests__/runtime-activation-nextaction.test.ts +0 -81
- package/src/commands/__tests__/runtime-probe-config.test.ts +0 -432
- package/src/commands/__tests__/telemetry-flag-wiring.test.ts +0 -84
- package/src/commands/__tests__/version.test.ts +0 -251
- package/src/commands/admission-gate.ts +0 -30
- package/src/commands/artifact.ts +0 -82
- package/src/commands/build-trajectory-evidence.ts +0 -298
- package/src/commands/candidate.ts +0 -1260
- package/src/commands/codex-ingest-catchup.ts +0 -114
- package/src/commands/codex-ingest-quarantine.ts +0 -127
- package/src/commands/codex-reconcile.ts +0 -84
- package/src/commands/codex-setup.ts +0 -476
- package/src/commands/codex-worker.ts +0 -185
- package/src/commands/command-helpers.ts +0 -24
- package/src/commands/config-doctor.ts +0 -193
- package/src/commands/console.ts +0 -797
- package/src/commands/context.ts +0 -72
- package/src/commands/demo-story-a.ts +0 -241
- package/src/commands/diagnose.ts +0 -756
- package/src/commands/errors-list.ts +0 -441
- package/src/commands/evolution-tasks-list.ts +0 -48
- package/src/commands/evolution-tasks-show.ts +0 -62
- package/src/commands/flow.ts +0 -60
- package/src/commands/health-codex.ts +0 -576
- package/src/commands/health.ts +0 -315
- package/src/commands/history.ts +0 -63
- package/src/commands/intent.ts +0 -457
- package/src/commands/legacy-cleanup.ts +0 -531
- package/src/commands/legacy-import.ts +0 -104
- package/src/commands/mvp-smoke.ts +0 -160
- package/src/commands/pain-evidence.ts +0 -226
- package/src/commands/pain-list.ts +0 -239
- package/src/commands/pain-record.ts +0 -612
- package/src/commands/pain-retry.ts +0 -916
- package/src/commands/principles-stats.ts +0 -700
- package/src/commands/proven-channel-baseline.ts +0 -115
- package/src/commands/quality-scorecard.ts +0 -272
- package/src/commands/remediation-output.ts +0 -66
- package/src/commands/rulecode.ts +0 -465
- package/src/commands/run.ts +0 -89
- package/src/commands/runtime-activation.ts +0 -1629
- package/src/commands/runtime-artifact-repair.ts +0 -524
- package/src/commands/runtime-canary.ts +0 -395
- package/src/commands/runtime-compatibility-scan.ts +0 -105
- package/src/commands/runtime-diagnostics-export.ts +0 -229
- package/src/commands/runtime-features.ts +0 -153
- package/src/commands/runtime-gfi-snapshot.ts +0 -135
- package/src/commands/runtime-health-snapshot.ts +0 -108
- package/src/commands/runtime-init.ts +0 -429
- package/src/commands/runtime-internalization-enqueue-successors.ts +0 -530
- package/src/commands/runtime-internalization-integrity-repair.ts +0 -79
- package/src/commands/runtime-internalization-integrity.ts +0 -107
- package/src/commands/runtime-internalization-queue.ts +0 -135
- package/src/commands/runtime-internalization-retry.ts +0 -191
- package/src/commands/runtime-internalization-run-once.ts +0 -791
- package/src/commands/runtime-internalization-run-rulehost.ts +0 -749
- package/src/commands/runtime-internalization-wake-once.ts +0 -87
- package/src/commands/runtime-pain-flood-simulation.ts +0 -121
- package/src/commands/runtime-pruning.ts +0 -438
- package/src/commands/runtime-recovery-failed-tasks.ts +0 -258
- package/src/commands/runtime-recovery.ts +0 -109
- package/src/commands/runtime-synthetic-baseline.ts +0 -70
- package/src/commands/runtime-uat.guard.test.ts +0 -175
- package/src/commands/runtime-uat.ts +0 -380
- package/src/commands/runtime.ts +0 -473
- package/src/commands/samples-list.ts +0 -39
- package/src/commands/samples-review.ts +0 -36
- package/src/commands/task.ts +0 -271
- package/src/commands/telemetry.ts +0 -349
- package/src/commands/trace.ts +0 -174
- package/src/commands/trajectory-db-unavailable.ts +0 -19
- package/src/commands/trajectory.ts +0 -64
- package/src/commands/version.ts +0 -49
- package/src/config-reader.ts +0 -122
- package/src/index.ts +0 -1276
- package/src/legacy/legacy-import.ts +0 -179
- package/src/legacy/session-history-import.ts +0 -203
- package/src/resolve-workspace.ts +0 -106
- package/src/services/__tests__/cli-output.test.ts +0 -130
- package/src/services/__tests__/evaluator-runner-deps.test.ts +0 -382
- package/src/services/__tests__/rulehost-readiness.test.ts +0 -363
- package/src/services/__tests__/runtime-adapter-resolver.test.ts +0 -793
- package/src/services/cli-output.ts +0 -95
- package/src/services/config-doctor.ts +0 -697
- package/src/services/console-launcher.ts +0 -537
- package/src/services/demo-rule-compiler.ts +0 -40
- package/src/services/demo-story-a-runner.ts +0 -471
- package/src/services/mainline-snapshot-assembler.ts +0 -579
- package/src/services/pain-flood-simulation-runner.ts +0 -462
- package/src/services/pd-config-loader.ts +0 -433
- package/src/services/proven-channel-baseline-runner.ts +0 -157
- package/src/services/quality-scorecard/data-extractor.ts +0 -150
- package/src/services/quality-scorecard/local-evaluator.ts +0 -142
- package/src/services/quality-scorecard/strong-model-gate.ts +0 -202
- package/src/services/resolve-runtime-from-pd-config.ts +0 -230
- package/src/services/rulehost-pipeline-runner.ts +0 -1216
- package/src/services/rulehost-readiness.ts +0 -326
- package/src/services/runtime-adapter-resolver.ts +0 -364
- package/src/services/synthetic-baseline-runner.ts +0 -400
- package/src/services/version-report.ts +0 -253
- package/src/services/workspace-tool-semantics.ts +0 -26
- package/src/utils/path-security.ts +0 -96
- package/src/utils/production-workspace-guard.test.ts +0 -157
- package/src/utils/production-workspace-guard.ts +0 -210
- package/tests/bdd/cli-contract.steps.ts +0 -346
- package/tests/bdd/principles-stats.steps.ts +0 -211
- package/tests/bdd/support/gherkin-loader.ts +0 -147
- package/tests/bdd/support/repo-root.ts +0 -62
- package/tests/bdd/support/vitest-bdd.ts +0 -179
- package/tests/commands/admission-gate-coverage.test.ts +0 -79
- package/tests/commands/build-trajectory-evidence.test.ts +0 -508
- package/tests/commands/candidate-audit-repair.test.ts +0 -421
- package/tests/commands/candidate-intake.test.ts +0 -732
- package/tests/commands/candidate-internalization-backfill.test.ts +0 -548
- package/tests/commands/candidate-internalize-lineage.test.ts +0 -565
- package/tests/commands/candidate-internalize.test.ts +0 -299
- package/tests/commands/candidate-route.test.ts +0 -329
- package/tests/commands/candidate-show.test.ts +0 -95
- package/tests/commands/cli-command-tree.test.ts +0 -144
- package/tests/commands/cli-help-snapshot.test.ts +0 -155
- package/tests/commands/cli-skill-contract.test.ts +0 -121
- package/tests/commands/codex-consent-reversibility.steps.test.ts +0 -299
- package/tests/commands/codex-ingest-quarantine.test.ts +0 -136
- package/tests/commands/codex-setup.test.ts +0 -297
- package/tests/commands/codex-worker-daemon.test.ts +0 -95
- package/tests/commands/codex-worker-registration.test.ts +0 -207
- package/tests/commands/config-doctor.test.ts +0 -336
- package/tests/commands/console-launcher-edge-cases.test.ts +0 -388
- package/tests/commands/console-open.test.ts +0 -1381
- package/tests/commands/context.test.ts +0 -114
- package/tests/commands/demo-story-a.test.ts +0 -318
- package/tests/commands/diagnose.test.ts +0 -1803
- package/tests/commands/errors-list.test.ts +0 -679
- package/tests/commands/evolution-tasks-list.test.ts +0 -41
- package/tests/commands/evolution-tasks-show.test.ts +0 -46
- package/tests/commands/health-codex.test.ts +0 -349
- package/tests/commands/health-host-wiring.test.ts +0 -76
- package/tests/commands/health-reliability.test.ts +0 -99
- package/tests/commands/health.test.ts +0 -413
- package/tests/commands/intent.test.ts +0 -321
- package/tests/commands/legacy-cleanup.test.ts +0 -148
- package/tests/commands/pain-evidence.test.ts +0 -518
- package/tests/commands/pain-list.test.ts +0 -219
- package/tests/commands/pain-record-async.test.ts +0 -335
- package/tests/commands/pain-record-session-parser.test.ts +0 -228
- package/tests/commands/pain-record.test.ts +0 -851
- package/tests/commands/pain-retry.test.ts +0 -1121
- package/tests/commands/plugin-config-resolution-cutover.test.ts +0 -229
- package/tests/commands/pri-393-runtime-config-unification.test.ts +0 -443
- package/tests/commands/principles-stats-wiring.test.ts +0 -135
- package/tests/commands/principles-stats.test.ts +0 -274
- package/tests/commands/product-path-regression.test.ts +0 -86
- package/tests/commands/proven-channel-baseline.test.ts +0 -441
- package/tests/commands/rulecode.test.ts +0 -177
- package/tests/commands/run-rulehost-handler.test.ts +0 -908
- package/tests/commands/runtime-activation-approve-flag-wiring.test.ts +0 -227
- package/tests/commands/runtime-activation-deactivate-flag-wiring.test.ts +0 -167
- package/tests/commands/runtime-activation-dispatch-flag-wiring.test.ts +0 -262
- package/tests/commands/runtime-activation-governance-audit.test.ts +0 -95
- package/tests/commands/runtime-activation-list-flag-wiring.test.ts +0 -193
- package/tests/commands/runtime-activation-promote-flag-wiring.test.ts +0 -248
- package/tests/commands/runtime-activation-shadow-telemetry.test.ts +0 -130
- package/tests/commands/runtime-activation.test.ts +0 -2052
- package/tests/commands/runtime-artifact-repair-registration.test.ts +0 -74
- package/tests/commands/runtime-artifact-repair.test.ts +0 -404
- package/tests/commands/runtime-canary.test.ts +0 -430
- package/tests/commands/runtime-compatibility-scan.test.ts +0 -146
- package/tests/commands/runtime-diagnostics-export.test.ts +0 -175
- package/tests/commands/runtime-features.test.ts +0 -249
- package/tests/commands/runtime-health-snapshot.test.ts +0 -358
- package/tests/commands/runtime-init-empty-workspace.test.ts +0 -252
- package/tests/commands/runtime-init.test.ts +0 -420
- package/tests/commands/runtime-internalization-enqueue-successors.test.ts +0 -782
- package/tests/commands/runtime-internalization-integrity-repair.test.ts +0 -239
- package/tests/commands/runtime-internalization-integrity.test.ts +0 -140
- package/tests/commands/runtime-internalization-queue.test.ts +0 -380
- package/tests/commands/runtime-internalization-retry-owner-authority.test.ts +0 -431
- package/tests/commands/runtime-internalization-run-once-evaluator-parity.test.ts +0 -269
- package/tests/commands/runtime-internalization-run-once-language.test.ts +0 -303
- package/tests/commands/runtime-internalization-run-once-real-config.test.ts +0 -237
- package/tests/commands/runtime-internalization-run-once-rollout-parity.test.ts +0 -706
- package/tests/commands/runtime-internalization-run-once.test.ts +0 -1791
- package/tests/commands/runtime-internalization-wake-once.test.ts +0 -171
- package/tests/commands/runtime-internalization.test.ts +0 -53
- package/tests/commands/runtime-pain-flood-simulation.test.ts +0 -418
- package/tests/commands/runtime-pruning.test.ts +0 -694
- package/tests/commands/runtime-recovery-failed-tasks.test.ts +0 -328
- package/tests/commands/runtime-recovery.test.ts +0 -120
- package/tests/commands/runtime-synthetic-baseline.test.ts +0 -249
- package/tests/commands/runtime-uat.test.ts +0 -397
- package/tests/commands/runtime.test.ts +0 -392
- package/tests/commands/samples-list.test.ts +0 -43
- package/tests/commands/samples-review.test.ts +0 -41
- package/tests/commands/task.test.ts +0 -153
- package/tests/commands/telemetry.test.ts +0 -190
- package/tests/commands/trace.test.ts +0 -316
- package/tests/config-reader.test.ts +0 -143
- package/tests/e2e/candidate-intake-e2e.test.ts +0 -338
- package/tests/e2e/cli-full-flow.test.ts +0 -233
- package/tests/e2e/cross-package-acceptance.test.ts +0 -635
- package/tests/helpers/pd-cli-path.ts +0 -5
- package/tests/pd-cli-smoke.test.ts +0 -13
- package/tests/resolve-workspace.test.ts +0 -196
- package/tests/services/config-doctor-signal-health.test.ts +0 -109
- package/tests/services/console-launcher.test.ts +0 -114
- package/tests/services/demo-rule-compiler.test.ts +0 -242
- package/tests/services/mainline-snapshot-assembler.test.ts +0 -572
- package/tests/services/pd-config-loader.test.ts +0 -505
- package/tests/services/proven-channel-baseline-runner.test.ts +0 -30
- package/tests/services/quality-scorecard/strong-model-gate.test.ts +0 -133
- package/tests/services/resolve-runtime-from-pd-config.test.ts +0 -485
- package/tests/services/rulehost-pipeline-e2e.test.ts +0 -538
- package/tests/services/rulehost-pipeline-runner.test.ts +0 -1175
- package/tests/services/workspace-tool-semantics.test.ts +0 -76
- package/tests/utils/path-security.test.ts +0 -180
- package/tsconfig.json +0 -26
- package/vitest.config.ts +0 -9
package/src/commands/diagnose.ts
DELETED
|
@@ -1,756 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* pd diagnose run/status commands — Diagnostician execution and status inspection.
|
|
3
|
-
*
|
|
4
|
-
* Usage:
|
|
5
|
-
* pd diagnose status --task-id <taskId> --workspace <path>
|
|
6
|
-
* pd diagnose run --task-id <taskId> --workspace <path>
|
|
7
|
-
*/
|
|
8
|
-
import {
|
|
9
|
-
RuntimeStateManager,
|
|
10
|
-
SqliteHistoryQuery,
|
|
11
|
-
SqliteContextAssembler,
|
|
12
|
-
SqliteDiagnosticianCommitter,
|
|
13
|
-
SqliteTrajectoryLocator,
|
|
14
|
-
SqliteSourceTraceLocator,
|
|
15
|
-
StoreEventEmitter,
|
|
16
|
-
storeEmitter,
|
|
17
|
-
SplitDiagnosticianRunner,
|
|
18
|
-
DiagRootCauseRunner,
|
|
19
|
-
DiagDistillerRunner,
|
|
20
|
-
DiagRouterRunner,
|
|
21
|
-
DefaultDiagRootCauseValidator,
|
|
22
|
-
DefaultDiagDistillerValidator,
|
|
23
|
-
type DiagnosticianRunnerLike,
|
|
24
|
-
TestDoubleRuntimeAdapter,
|
|
25
|
-
PDRuntimeError,
|
|
26
|
-
isRuntimeConfigError,
|
|
27
|
-
CandidateIntakeService,
|
|
28
|
-
run as diagnoseRun,
|
|
29
|
-
status as diagnoseStatus,
|
|
30
|
-
PrincipleTreeLedgerAdapter,
|
|
31
|
-
buildDreamerSeedFromCandidate,
|
|
32
|
-
findExistingDreamerTask,
|
|
33
|
-
CANDIDATE_KIND_TO_ROUTE,
|
|
34
|
-
ROUTE_CHANNEL_MAP,
|
|
35
|
-
MVP_ENABLED_CHANNELS,
|
|
36
|
-
} from '@principles/core/runtime-v2';
|
|
37
|
-
import type { PDRuntimeAdapter, OutputLanguage } from '@principles/core/runtime-v2';
|
|
38
|
-
import { resolveWorkspaceDir } from '../resolve-workspace.js';
|
|
39
|
-
import { readOutputLanguageFromWorkspace } from '../config-reader.js';
|
|
40
|
-
import { loadPdConfig, resolvePromptFullPipelineSeedMode } from '../services/pd-config-loader.js';
|
|
41
|
-
import { SPLIT_PIPELINE_TOTAL_TIMEOUT_MS, resolveDiagnosticianCapability } from '@principles/core/runtime-v2';
|
|
42
|
-
import { resolveRuntimeAdapterFromConfig, ConfigResolutionError } from '../services/runtime-adapter-resolver.js';
|
|
43
|
-
import { resolveRuntimeFromPdConfig } from '../services/resolve-runtime-from-pd-config.js';
|
|
44
|
-
import { checkAdmissionGate } from './admission-gate.js';
|
|
45
|
-
import { resolveSourcePainIdFromDiagnostician } from './candidate.js';
|
|
46
|
-
import * as path from 'path';
|
|
47
|
-
|
|
48
|
-
function validateStalledThreshold(val: unknown): number | undefined {
|
|
49
|
-
if (val === undefined) {
|
|
50
|
-
return undefined;
|
|
51
|
-
}
|
|
52
|
-
const str = String(val).trim();
|
|
53
|
-
if (!/^[1-9]\d*$/.test(str)) {
|
|
54
|
-
throw new Error('stalled-threshold must be a positive integer.');
|
|
55
|
-
}
|
|
56
|
-
const num = parseInt(str, 10);
|
|
57
|
-
if (isNaN(num)) {
|
|
58
|
-
throw new Error('stalled-threshold must be a positive integer.');
|
|
59
|
-
}
|
|
60
|
-
return num;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
interface DiagnoseStatusOptions {
|
|
64
|
-
taskId: string;
|
|
65
|
-
workspace?: string;
|
|
66
|
-
json?: boolean;
|
|
67
|
-
stalledThreshold?: unknown;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
interface DiagnoseRunOptions {
|
|
71
|
-
taskId: string;
|
|
72
|
-
workspace?: string;
|
|
73
|
-
json?: boolean;
|
|
74
|
-
runtime?: string;
|
|
75
|
-
openclawLocal?: boolean;
|
|
76
|
-
openclawGateway?: boolean;
|
|
77
|
-
agent?: string;
|
|
78
|
-
provider?: string;
|
|
79
|
-
model?: string;
|
|
80
|
-
apiKeyEnv?: string;
|
|
81
|
-
baseUrl?: string;
|
|
82
|
-
maxRetries?: number;
|
|
83
|
-
timeoutMs?: number;
|
|
84
|
-
intake?: boolean;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* pd diagnose status --task-id <taskId> [--workspace <path>] [--json]
|
|
89
|
-
*
|
|
90
|
-
* Inspects the current status of a diagnostician task.
|
|
91
|
-
*/
|
|
92
|
-
export async function handleDiagnoseStatus(opts: DiagnoseStatusOptions): Promise<void> {
|
|
93
|
-
let stalledThresholdSeconds: number | undefined;
|
|
94
|
-
try {
|
|
95
|
-
stalledThresholdSeconds = validateStalledThreshold(opts.stalledThreshold);
|
|
96
|
-
} catch (err) {
|
|
97
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
98
|
-
if (opts.json) {
|
|
99
|
-
console.log(JSON.stringify({
|
|
100
|
-
ok: false,
|
|
101
|
-
reason: 'invalid_stalled_threshold',
|
|
102
|
-
nextAction: 'Provide a valid positive integer for --stalled-threshold (e.g., --stalled-threshold 300).',
|
|
103
|
-
}));
|
|
104
|
-
} else {
|
|
105
|
-
console.error(`error: ${msg}`);
|
|
106
|
-
console.error('nextAction: Provide a valid positive integer for --stalled-threshold (e.g., --stalled-threshold 300).');
|
|
107
|
-
}
|
|
108
|
-
process.exit(1);
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const workspaceDir = resolveWorkspaceDir(opts.workspace);
|
|
113
|
-
const stateManager = new RuntimeStateManager({ workspaceDir });
|
|
114
|
-
|
|
115
|
-
try {
|
|
116
|
-
await stateManager.initialize();
|
|
117
|
-
const result = await diagnoseStatus({
|
|
118
|
-
taskId: opts.taskId,
|
|
119
|
-
stateManager,
|
|
120
|
-
stalledThresholdSeconds,
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
if (!result) {
|
|
124
|
-
console.error(`Task not found: ${opts.taskId}`);
|
|
125
|
-
process.exit(1);
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (opts.json) {
|
|
130
|
-
console.log(JSON.stringify(result, null, 2));
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
console.log(`\nDiagnostician Task: ${result.taskId}\n`);
|
|
135
|
-
console.log(` Status: ${result.status}`);
|
|
136
|
-
console.log(` Attempts: ${result.attemptCount} / ${result.maxAttempts}`);
|
|
137
|
-
if (result.commitId) {
|
|
138
|
-
console.log(` Result Ref: commit://${result.commitId}`);
|
|
139
|
-
console.log(` Commit ID: ${result.commitId}`);
|
|
140
|
-
console.log(` Artifact ID: ${result.artifactId ?? 'N/A'}`);
|
|
141
|
-
console.log(` Candidates: ${result.candidateCount ?? 0}`);
|
|
142
|
-
}
|
|
143
|
-
if (result.lastError) {
|
|
144
|
-
console.log(` Last Error: ${result.lastError}`);
|
|
145
|
-
}
|
|
146
|
-
if (result.reason) {
|
|
147
|
-
console.log(` Reason: ${result.reason}`);
|
|
148
|
-
}
|
|
149
|
-
if (result.age !== undefined && result.age !== null) {
|
|
150
|
-
console.log(` Age: ${result.age}s`);
|
|
151
|
-
}
|
|
152
|
-
if (result.nextAction) {
|
|
153
|
-
console.log(` Next Action: ${result.nextAction}`);
|
|
154
|
-
}
|
|
155
|
-
console.log('');
|
|
156
|
-
} finally {
|
|
157
|
-
await stateManager.close();
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* PRI-431 Step 1d: Build diagnostician-specific test-double payload.
|
|
163
|
-
* Extracted from inline resolution in handleDiagnoseRun to use with shared resolver.
|
|
164
|
-
*/
|
|
165
|
-
function buildDiagnosticianTestDouble(taskId: string): PDRuntimeAdapter {
|
|
166
|
-
return new TestDoubleRuntimeAdapter({
|
|
167
|
-
onPollRun: (_runId: string) => ({
|
|
168
|
-
runId: _runId,
|
|
169
|
-
status: 'succeeded',
|
|
170
|
-
startedAt: new Date().toISOString(),
|
|
171
|
-
endedAt: new Date().toISOString(),
|
|
172
|
-
}),
|
|
173
|
-
onFetchOutput: (_runId: string) => ({
|
|
174
|
-
runId: _runId,
|
|
175
|
-
payload: {
|
|
176
|
-
valid: true,
|
|
177
|
-
diagnosisId: `diag-cli-${Date.now()}`,
|
|
178
|
-
taskId,
|
|
179
|
-
summary: 'CLI test diagnosis — validate tool arguments before execution',
|
|
180
|
-
rootCause: 'Test root cause — missing argument validation',
|
|
181
|
-
violatedPrinciples: [],
|
|
182
|
-
evidence: [],
|
|
183
|
-
recommendations: [
|
|
184
|
-
{ kind: 'principle', description: 'Always validate tool arguments before execution to prevent silent failures' },
|
|
185
|
-
{ kind: 'rule', description: 'Use schema validation for external inputs' },
|
|
186
|
-
],
|
|
187
|
-
confidence: 0.9,
|
|
188
|
-
},
|
|
189
|
-
}),
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* pd diagnose run --task-id <taskId> [--workspace <path>] [--json]
|
|
195
|
-
*
|
|
196
|
-
* Executes the diagnostician runner for a task.
|
|
197
|
-
*/
|
|
198
|
-
export async function handleDiagnoseRun(opts: DiagnoseRunOptions): Promise<void> {
|
|
199
|
-
const workspaceDir = resolveWorkspaceDir(opts.workspace);
|
|
200
|
-
// PRI-720: resolve the full-chain override once per invocation.
|
|
201
|
-
const seedPipelineMode = resolvePromptFullPipelineSeedMode(workspaceDir);
|
|
202
|
-
|
|
203
|
-
// Validate mutually exclusive flags (HG-03)
|
|
204
|
-
if (opts.openclawLocal && opts.openclawGateway) {
|
|
205
|
-
console.error('error: --openclaw-local and --openclaw-gateway are mutually exclusive');
|
|
206
|
-
process.exit(1);
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// PRI-638: this is the CLI's ONLY capability disable check. It reads the
|
|
211
|
-
// canonical authority (internalAgents.agents.diagnostician.enabled) through
|
|
212
|
-
// the same resolver the runtime factory uses, so `pd diagnose` can never
|
|
213
|
-
// mislabel a deliberate Owner kill switch as a missing runtime, a provider
|
|
214
|
-
// failure or a malformed config. No runtime adapter is constructed and no
|
|
215
|
-
// provider is contacted on this path.
|
|
216
|
-
const configLoadResult = loadPdConfig(workspaceDir);
|
|
217
|
-
const capability = resolveDiagnosticianCapability(
|
|
218
|
-
configLoadResult.ok ? configLoadResult.effective : configLoadResult.defaults,
|
|
219
|
-
);
|
|
220
|
-
if (!capability.available) {
|
|
221
|
-
const disabledResult = {
|
|
222
|
-
ok: false,
|
|
223
|
-
status: 'failed',
|
|
224
|
-
reason: capability.reason,
|
|
225
|
-
message: capability.message,
|
|
226
|
-
nextAction: capability.nextAction,
|
|
227
|
-
};
|
|
228
|
-
if (opts.json) {
|
|
229
|
-
console.log(JSON.stringify(disabledResult, null, 2));
|
|
230
|
-
} else {
|
|
231
|
-
console.error(`error: ${capability.message}`);
|
|
232
|
-
console.error(`reason: ${capability.reason}`);
|
|
233
|
-
console.error(`nextAction: ${capability.nextAction}`);
|
|
234
|
-
}
|
|
235
|
-
process.exit(1);
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
// Resolve runtime kind. P1 fix (mirrors pain-retry.ts): pd diagnose run
|
|
240
|
-
// must NOT default to test-double. Without --runtime, the split pipeline
|
|
241
|
-
// would validate the test-double's stale DiagnosticianOutputV1-shaped
|
|
242
|
-
// payload against DiagRootCauseOutputV1Schema and fail with
|
|
243
|
-
// max_attempts_exceeded — silently producing failed/fake diagnostic data
|
|
244
|
-
// in a real workspace. Fall back to .pd/config.yaml first; refuse if
|
|
245
|
-
// nothing is bound. (rc-9-no-silent-fallback / ERR-002; EP-03, EP-04)
|
|
246
|
-
let runtimeKind = opts.runtime;
|
|
247
|
-
if (!runtimeKind) {
|
|
248
|
-
const resolved = resolveRuntimeFromPdConfig(workspaceDir);
|
|
249
|
-
if (!isRuntimeConfigError(resolved.result) && resolved.result.runtimeKind) {
|
|
250
|
-
({ runtimeKind } = resolved.result);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
if (!runtimeKind) {
|
|
255
|
-
const missingRuntime = {
|
|
256
|
-
ok: false,
|
|
257
|
-
reason: 'missing_runtime',
|
|
258
|
-
message:
|
|
259
|
-
'No --runtime specified and no .pd/config.yaml runtime binding found. pd diagnose run must not default to test-double to prevent fake data in real workspaces.',
|
|
260
|
-
nextAction: `Specify --runtime explicitly: pd diagnose run --task-id ${opts.taskId} --runtime pi-ai --provider <provider> --model <model> --apiKeyEnv <ENV>`,
|
|
261
|
-
};
|
|
262
|
-
if (opts.json) {
|
|
263
|
-
console.log(JSON.stringify(missingRuntime, null, 2));
|
|
264
|
-
} else {
|
|
265
|
-
console.error(`error: ${missingRuntime.message}`);
|
|
266
|
-
console.error(`Next action: ${missingRuntime.nextAction}`);
|
|
267
|
-
}
|
|
268
|
-
process.exit(1);
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
const stateManager = new RuntimeStateManager({ workspaceDir });
|
|
273
|
-
|
|
274
|
-
try {
|
|
275
|
-
await stateManager.initialize();
|
|
276
|
-
|
|
277
|
-
// Build context assembler from internal stores
|
|
278
|
-
const sqliteConn = stateManager.connection;
|
|
279
|
-
const {taskStore} = stateManager;
|
|
280
|
-
const {runStore} = stateManager;
|
|
281
|
-
const historyQuery = new SqliteHistoryQuery(sqliteConn);
|
|
282
|
-
const trajectoryLocator = new SqliteTrajectoryLocator(sqliteConn);
|
|
283
|
-
const sourceTraceLocator = new SqliteSourceTraceLocator(taskStore, trajectoryLocator);
|
|
284
|
-
const contextAssembler = new SqliteContextAssembler(taskStore, historyQuery, runStore, { sourceTraceLocator });
|
|
285
|
-
|
|
286
|
-
// Select runtime adapter based on --runtime flag (CLI-02)
|
|
287
|
-
// PRI-431: migrated to shared resolveRuntimeAdapterFromConfig
|
|
288
|
-
let runtimeAdapter: PDRuntimeAdapter;
|
|
289
|
-
// Capture config info for telemetry (resolver consumes config internally)
|
|
290
|
-
let telemetryConfig: { provider?: string; model?: string; openclawMode?: string } = {};
|
|
291
|
-
try {
|
|
292
|
-
if (runtimeKind === 'test-double') {
|
|
293
|
-
runtimeAdapter = resolveRuntimeAdapterFromConfig({
|
|
294
|
-
runtimeKind,
|
|
295
|
-
workspaceDir,
|
|
296
|
-
allowTestDouble: true,
|
|
297
|
-
testDoublePayloadBuilder: () => buildDiagnosticianTestDouble(opts.taskId),
|
|
298
|
-
});
|
|
299
|
-
} else if (runtimeKind === 'openclaw-cli') {
|
|
300
|
-
const flagMode: 'local' | 'gateway' | undefined = opts.openclawLocal
|
|
301
|
-
? 'local'
|
|
302
|
-
: opts.openclawGateway
|
|
303
|
-
? 'gateway'
|
|
304
|
-
: undefined;
|
|
305
|
-
runtimeAdapter = resolveRuntimeAdapterFromConfig({
|
|
306
|
-
runtimeKind,
|
|
307
|
-
workspaceDir,
|
|
308
|
-
openclawMode: flagMode,
|
|
309
|
-
agentId: opts.agent ?? 'main',
|
|
310
|
-
onConfigResolved: (resolved) => {
|
|
311
|
-
if (!isRuntimeConfigError(resolved.result)) {
|
|
312
|
-
telemetryConfig.openclawMode = flagMode ?? resolved.result.openclawMode;
|
|
313
|
-
} else {
|
|
314
|
-
telemetryConfig.openclawMode = flagMode;
|
|
315
|
-
}
|
|
316
|
-
},
|
|
317
|
-
});
|
|
318
|
-
// TELE-01: runtime_adapter_selected — user explicitly chose openclaw-cli runtime
|
|
319
|
-
storeEmitter.emitTelemetry({
|
|
320
|
-
eventType: 'runtime_adapter_selected',
|
|
321
|
-
traceId: opts.taskId,
|
|
322
|
-
timestamp: new Date().toISOString(),
|
|
323
|
-
sessionId: 'pd-cli-diagnose',
|
|
324
|
-
agentId: 'openclaw-cli-adapter',
|
|
325
|
-
payload: {
|
|
326
|
-
runtimeKind: 'openclaw-cli',
|
|
327
|
-
runtimeMode: telemetryConfig.openclawMode ?? 'local',
|
|
328
|
-
},
|
|
329
|
-
});
|
|
330
|
-
} else if (runtimeKind === 'pi-ai') {
|
|
331
|
-
runtimeAdapter = resolveRuntimeAdapterFromConfig({
|
|
332
|
-
runtimeKind,
|
|
333
|
-
workspaceDir,
|
|
334
|
-
configOptional: true,
|
|
335
|
-
validateApiKeyEnv: true,
|
|
336
|
-
piAiOverrides: {
|
|
337
|
-
provider: opts.provider,
|
|
338
|
-
model: opts.model,
|
|
339
|
-
apiKeyEnv: opts.apiKeyEnv,
|
|
340
|
-
baseUrl: opts.baseUrl,
|
|
341
|
-
maxRetries: opts.maxRetries,
|
|
342
|
-
},
|
|
343
|
-
timeoutMs: opts.timeoutMs,
|
|
344
|
-
onConfigResolved: (resolved) => {
|
|
345
|
-
for (const w of resolved.legacyWarnings) console.warn(`[pd diagnose] ${w}`);
|
|
346
|
-
if (isRuntimeConfigError(resolved.result)) {
|
|
347
|
-
console.warn(`[pd diagnose] .pd/config.yaml resolution failed: ${resolved.result.message}. Using CLI flags if provided.`);
|
|
348
|
-
} else {
|
|
349
|
-
telemetryConfig.provider = resolved.result.provider;
|
|
350
|
-
telemetryConfig.model = resolved.result.model;
|
|
351
|
-
}
|
|
352
|
-
},
|
|
353
|
-
});
|
|
354
|
-
// TELE: runtime_adapter_selected telemetry
|
|
355
|
-
const telemetryProvider = opts.provider ?? telemetryConfig.provider;
|
|
356
|
-
const telemetryModel = opts.model ?? telemetryConfig.model;
|
|
357
|
-
storeEmitter.emitTelemetry({
|
|
358
|
-
eventType: 'runtime_adapter_selected',
|
|
359
|
-
traceId: opts.taskId,
|
|
360
|
-
timestamp: new Date().toISOString(),
|
|
361
|
-
sessionId: 'pd-cli-diagnose',
|
|
362
|
-
agentId: 'pi-ai-adapter',
|
|
363
|
-
payload: { runtimeKind: 'pi-ai', provider: telemetryProvider, model: telemetryModel, baseUrlPresent: !!opts.baseUrl },
|
|
364
|
-
});
|
|
365
|
-
} else {
|
|
366
|
-
const unsupportedResult = {
|
|
367
|
-
ok: false,
|
|
368
|
-
reason: `unsupported_runtime_kind: ${runtimeKind}`,
|
|
369
|
-
nextAction: 'Use one of: openclaw-cli, test-double, pi-ai',
|
|
370
|
-
};
|
|
371
|
-
if (opts.json) {
|
|
372
|
-
console.log(JSON.stringify(unsupportedResult, null, 2));
|
|
373
|
-
} else {
|
|
374
|
-
console.error(`error: unknown runtime kind '${runtimeKind}' (supported: openclaw-cli, test-double, pi-ai)`);
|
|
375
|
-
console.error(`Next action: ${unsupportedResult.nextAction}`);
|
|
376
|
-
}
|
|
377
|
-
process.exit(1);
|
|
378
|
-
return;
|
|
379
|
-
}
|
|
380
|
-
} catch (err) {
|
|
381
|
-
if (err instanceof ConfigResolutionError) {
|
|
382
|
-
// Preserve original error format for openclaw-cli missing mode (backward compat)
|
|
383
|
-
if (err.kind === 'missing-fields' && err.missing?.includes('openclawMode')) {
|
|
384
|
-
if (opts.json) {
|
|
385
|
-
console.log(JSON.stringify({
|
|
386
|
-
ok: false,
|
|
387
|
-
reason: 'missing_openclaw_mode',
|
|
388
|
-
message: 'runtimeKind is openclaw-cli but no mode resolved',
|
|
389
|
-
nextAction: 'Provide --openclaw-local or --openclaw-gateway, or set openclawMode in .pd/config.yaml',
|
|
390
|
-
}));
|
|
391
|
-
} else {
|
|
392
|
-
console.error('error: runtimeKind is openclaw-cli but no mode resolved');
|
|
393
|
-
console.error('nextAction: Provide --openclaw-local or --openclaw-gateway, or set openclawMode in .pd/config.yaml');
|
|
394
|
-
}
|
|
395
|
-
process.exit(1);
|
|
396
|
-
return;
|
|
397
|
-
}
|
|
398
|
-
// Default error formatting for other config resolution errors
|
|
399
|
-
if (opts.json) {
|
|
400
|
-
console.log(JSON.stringify({ ok: false, reason: err.kind, message: err.message, missing: err.missing, nextAction: err.nextAction ?? 'Check .pd/config.yaml and retry' }));
|
|
401
|
-
} else {
|
|
402
|
-
console.error(`error: ${err.message}`);
|
|
403
|
-
if (err.nextAction) {
|
|
404
|
-
console.error(`nextAction: ${err.nextAction}`);
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
process.exit(1);
|
|
408
|
-
return;
|
|
409
|
-
}
|
|
410
|
-
throw err;
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
const eventEmitter = new StoreEventEmitter();
|
|
414
|
-
const committer = new SqliteDiagnosticianCommitter(sqliteConn);
|
|
415
|
-
|
|
416
|
-
// PRI-336: Read outputLanguage from workspace config
|
|
417
|
-
const outputLangResult = readOutputLanguageFromWorkspace(workspaceDir);
|
|
418
|
-
const outputLanguage: OutputLanguage | undefined = outputLangResult.outputLanguage;
|
|
419
|
-
|
|
420
|
-
// PRI-638: implementation selection is gone. The split pipeline is the only
|
|
421
|
-
// Diagnostician implementation in the tree, so it always runs with its
|
|
422
|
-
// documented 3-stage budget; `diagnostician_split_pipeline` no longer
|
|
423
|
-
// selects a runner nor disables capability.
|
|
424
|
-
const pipelineTimeoutMs = SPLIT_PIPELINE_TOTAL_TIMEOUT_MS;
|
|
425
|
-
// BUG-1 (PRI-442): extract effectiveConfig so ADR-0019 LLM rate-limit
|
|
426
|
-
// degradation (isDegradationEnabled in base-peer-runner) can read the
|
|
427
|
-
// diagnostician_llm_degradation feature flag. Without this, the runners
|
|
428
|
-
// receive no effectiveConfig and degradation silently never fires.
|
|
429
|
-
// CR-1 (CodeRabbit P2, rc-9): warn when config load failed so the
|
|
430
|
-
// fallback to defaults is observable — no silent degradation.
|
|
431
|
-
if (!configLoadResult.ok) {
|
|
432
|
-
const errSummary = configLoadResult.errors
|
|
433
|
-
.map((e) => `${e.path}: ${e.reason}`)
|
|
434
|
-
.join('; ');
|
|
435
|
-
console.warn(
|
|
436
|
-
`[pd diagnose] .pd/config.yaml at ${configLoadResult.configPath} is malformed — falling back to default feature flags. Errors: ${errSummary}. Next action: ${configLoadResult.errors[0]?.nextAction ?? 'fix config errors and retry'}`,
|
|
437
|
-
);
|
|
438
|
-
}
|
|
439
|
-
const effectiveConfig = configLoadResult.ok ? configLoadResult.effective : configLoadResult.defaults;
|
|
440
|
-
|
|
441
|
-
const resolvedKind = typeof runtimeAdapter.kind === 'function' ? runtimeAdapter.kind() : runtimeKind;
|
|
442
|
-
const perStageTimeoutMs = pipelineTimeoutMs / 3;
|
|
443
|
-
const rootCauseRunner = new DiagRootCauseRunner(
|
|
444
|
-
{ stateManager, runtimeAdapter, eventEmitter, artifactStore: stateManager.piArtifactStore, validator: new DefaultDiagRootCauseValidator(), contextAssembler },
|
|
445
|
-
{ owner: 'pd-cli-diagnose', runtimeKind: resolvedKind, outputLanguage, timeoutMs: perStageTimeoutMs, effectiveConfig },
|
|
446
|
-
);
|
|
447
|
-
const distillerRunner = new DiagDistillerRunner(
|
|
448
|
-
{ stateManager, runtimeAdapter, eventEmitter, artifactStore: stateManager.piArtifactStore, validator: new DefaultDiagDistillerValidator() },
|
|
449
|
-
{ owner: 'pd-cli-diagnose', runtimeKind: resolvedKind, outputLanguage, timeoutMs: perStageTimeoutMs, effectiveConfig },
|
|
450
|
-
);
|
|
451
|
-
const routerRunner = new DiagRouterRunner(
|
|
452
|
-
{ stateManager, runtimeAdapter, eventEmitter, artifactStore: stateManager.piArtifactStore, committer },
|
|
453
|
-
{ owner: 'pd-cli-diagnose', runtimeKind: resolvedKind, outputLanguage, timeoutMs: perStageTimeoutMs, effectiveConfig },
|
|
454
|
-
);
|
|
455
|
-
|
|
456
|
-
const runner: DiagnosticianRunnerLike = new SplitDiagnosticianRunner({
|
|
457
|
-
rootCauseRunner,
|
|
458
|
-
distillerRunner,
|
|
459
|
-
routerRunner,
|
|
460
|
-
stateManager,
|
|
461
|
-
committer,
|
|
462
|
-
perStageTimeoutMs,
|
|
463
|
-
});
|
|
464
|
-
|
|
465
|
-
if (!opts.json) {
|
|
466
|
-
console.log(`\nRunning diagnostician for task: ${opts.taskId}`);
|
|
467
|
-
console.log(`Workspace: ${workspaceDir}\n`);
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
// ERR-067 fix: loop on `retried` status — the SplitDiagnosticianRunner
|
|
471
|
-
// handles per-stage retry internally, but the CLI must also loop in case
|
|
472
|
-
// the top-level result is `retried` (e.g., from a non-split pipeline).
|
|
473
|
-
const retryPolicy = stateManager.getRetryPolicy();
|
|
474
|
-
let result = await diagnoseRun({
|
|
475
|
-
taskId: opts.taskId,
|
|
476
|
-
stateManager,
|
|
477
|
-
runner,
|
|
478
|
-
});
|
|
479
|
-
|
|
480
|
-
let retryLoopCount = 0;
|
|
481
|
-
const maxRetryLoops = 10; // Safety limit
|
|
482
|
-
while (result.status === 'retried' && retryLoopCount < maxRetryLoops) {
|
|
483
|
-
retryLoopCount++;
|
|
484
|
-
const task = await stateManager.getTask(opts.taskId);
|
|
485
|
-
const backoffMs = task ? retryPolicy.calculateBackoff(task.attemptCount) : 30_000;
|
|
486
|
-
|
|
487
|
-
if (!opts.json) {
|
|
488
|
-
console.log(` Retry ${retryLoopCount}: waiting ${Math.round(backoffMs / 1000)}s before re-running...`);
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
await new Promise((resolve) => setTimeout(resolve, backoffMs));
|
|
492
|
-
|
|
493
|
-
result = await diagnoseRun({
|
|
494
|
-
taskId: opts.taskId,
|
|
495
|
-
stateManager,
|
|
496
|
-
runner,
|
|
497
|
-
});
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
// P0-1 fix: convert non-terminal `retried` to `failed` with reason
|
|
501
|
-
if (result.status === 'retried') {
|
|
502
|
-
result = {
|
|
503
|
-
...result,
|
|
504
|
-
status: 'failed',
|
|
505
|
-
failureReason: `Max retry loops (${maxRetryLoops}) exceeded without reaching terminal state. ${result.failureReason ?? ''}`,
|
|
506
|
-
};
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
if (result.status !== 'succeeded') {
|
|
510
|
-
if (opts.json) {
|
|
511
|
-
console.log(JSON.stringify(result, null, 2));
|
|
512
|
-
} else {
|
|
513
|
-
console.log(`\nResult:`);
|
|
514
|
-
console.log(` Status: ${result.status}`);
|
|
515
|
-
console.log(` Task ID: ${result.taskId}`);
|
|
516
|
-
if (result.errorCategory) {
|
|
517
|
-
console.log(` Error Category: ${result.errorCategory}`);
|
|
518
|
-
}
|
|
519
|
-
if (result.failureReason) {
|
|
520
|
-
console.log(` Failure Reason: ${result.failureReason}`);
|
|
521
|
-
}
|
|
522
|
-
console.log(` Attempt Count: ${result.attemptCount}`);
|
|
523
|
-
console.log('');
|
|
524
|
-
}
|
|
525
|
-
process.exit(1);
|
|
526
|
-
return;
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
const candidates = await stateManager.getCandidatesByTaskId(opts.taskId);
|
|
530
|
-
const intakeResults: { candidateId: string; ledgerEntryId?: string; status: string; error?: string; nextAction?: string }[] = [];
|
|
531
|
-
let intakeFailed = false;
|
|
532
|
-
|
|
533
|
-
if (opts.intake === false) {
|
|
534
|
-
for (const candidate of candidates) {
|
|
535
|
-
intakeResults.push({
|
|
536
|
-
candidateId: candidate.candidateId,
|
|
537
|
-
status: 'skipped',
|
|
538
|
-
});
|
|
539
|
-
}
|
|
540
|
-
} else {
|
|
541
|
-
const ledgerAdapter = new PrincipleTreeLedgerAdapter({ stateDir: path.join(workspaceDir, '.state') });
|
|
542
|
-
const intakeService = new CandidateIntakeService({ stateManager, ledgerAdapter });
|
|
543
|
-
|
|
544
|
-
for (const candidate of candidates) {
|
|
545
|
-
// PRI-503: admission gate check — refuse non-admitted candidates before
|
|
546
|
-
// intake, mirroring candidate.ts (intake/repair/backfill). Without this,
|
|
547
|
-
// `pd diagnose --intake` could bypass the gate and intake unreviewed
|
|
548
|
-
// candidates. cli-5-failure-no-mutation: refusal path does not call
|
|
549
|
-
// intake(), does not update candidate status, does not write ledger.
|
|
550
|
-
// cli-6-output-next-action: refusal result carries admissionBlock.nextAction.
|
|
551
|
-
const admissionBlock = checkAdmissionGate(candidate);
|
|
552
|
-
if (admissionBlock) {
|
|
553
|
-
intakeFailed = true;
|
|
554
|
-
intakeResults.push({
|
|
555
|
-
candidateId: candidate.candidateId,
|
|
556
|
-
status: 'intake_failed',
|
|
557
|
-
error: `Admission gate refused: ${admissionBlock.reason}`,
|
|
558
|
-
nextAction: admissionBlock.nextAction,
|
|
559
|
-
});
|
|
560
|
-
continue;
|
|
561
|
-
}
|
|
562
|
-
try {
|
|
563
|
-
const entry = await intakeService.intake(candidate.candidateId);
|
|
564
|
-
if (candidate.status !== 'consumed') {
|
|
565
|
-
await stateManager.updateCandidateStatus(candidate.candidateId, { status: 'consumed' });
|
|
566
|
-
}
|
|
567
|
-
intakeResults.push({
|
|
568
|
-
candidateId: candidate.candidateId,
|
|
569
|
-
ledgerEntryId: entry.id,
|
|
570
|
-
status: 'consumed',
|
|
571
|
-
});
|
|
572
|
-
} catch (intakeErr: unknown) {
|
|
573
|
-
intakeFailed = true;
|
|
574
|
-
const intakeErrorMessage = intakeErr instanceof Error ? intakeErr.message : String(intakeErr);
|
|
575
|
-
intakeResults.push({
|
|
576
|
-
candidateId: candidate.candidateId,
|
|
577
|
-
status: 'intake_failed',
|
|
578
|
-
error: intakeErrorMessage,
|
|
579
|
-
nextAction: `pd candidate intake --candidate-id ${candidate.candidateId} --workspace "${workspaceDir}"`,
|
|
580
|
-
});
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
// Defect-004 fix: seed dreamer task for each consumed candidate whose
|
|
586
|
-
// recommendation_kind routes to an MVP-enabled internalization channel.
|
|
587
|
-
// Without this, the chain stops at 'consumed' and never reaches internalization
|
|
588
|
-
// (11 of 18 consumed candidates hit this in production). Mirrors the pattern
|
|
589
|
-
// in PainSignalBridge.onDiagnosisComplete (pain-signal-bridge.ts L310-338).
|
|
590
|
-
//
|
|
591
|
-
// DEFECT-005 (PRI-514): the dreamer seed loop is gated ONLY by `opts.intake`,
|
|
592
|
-
// NOT by a global `intakeFailed` flag. A single defer candidate whose intake
|
|
593
|
-
// is refused by the admission gate must NOT poison dreamer seed for sibling
|
|
594
|
-
// candidates that were successfully consumed (EP-03 / ERR-089 sibling-branch
|
|
595
|
-
// defect). Per-candidate eligibility is checked inside the loop via the
|
|
596
|
-
// intake result's status. `intakeFailed` is retained solely for the
|
|
597
|
-
// nextAction/exit-code signaling below (partial failure still exits non-zero).
|
|
598
|
-
if (opts.intake !== false) {
|
|
599
|
-
for (const candidate of candidates) {
|
|
600
|
-
const kind = candidate.recommendationKind;
|
|
601
|
-
if (kind === 'defer' || kind === 'implementation') continue;
|
|
602
|
-
const intakeResult = intakeResults.find((r) => r.candidateId === candidate.candidateId);
|
|
603
|
-
if (!intakeResult || intakeResult.status !== 'consumed') continue;
|
|
604
|
-
try {
|
|
605
|
-
const route = CANDIDATE_KIND_TO_ROUTE[kind ?? ''];
|
|
606
|
-
if (!route) continue;
|
|
607
|
-
const channel = ROUTE_CHANNEL_MAP[route];
|
|
608
|
-
const ready = !!channel && MVP_ENABLED_CHANNELS.has(channel);
|
|
609
|
-
// BUG-2 (PRI-442): resolve sourcePainId from the diagnostician task
|
|
610
|
-
// chain (rc-6 lineage consistency). The candidate itself doesn't carry
|
|
611
|
-
// sourcePainId; it must be resolved from the diagnostician task's
|
|
612
|
-
// diagnosticJson. ERR-004: never invent lineage.
|
|
613
|
-
const sourcePainId = await resolveSourcePainIdFromDiagnostician(stateManager, candidate);
|
|
614
|
-
const seed = buildDreamerSeedFromCandidate(candidate, { route, ready, sourcePainId: sourcePainId ?? undefined, pipelineMode: seedPipelineMode });
|
|
615
|
-
// eslint-disable-next-line no-restricted-syntax -- 'in' required for discriminated union narrowing (BridgeTaskSeed | BridgeDecision)
|
|
616
|
-
if ('decision' in seed) continue; // not_internalizable or invalid — skip
|
|
617
|
-
// PRI-720 C6: candidate-level dedup (demotion may change the
|
|
618
|
-
// derived channel suffix vs a pre-existing chain).
|
|
619
|
-
const existingTask = await findExistingDreamerTask((id) => stateManager.getTask(id), candidate.candidateId);
|
|
620
|
-
if (!existingTask) {
|
|
621
|
-
await stateManager.createTask({
|
|
622
|
-
taskId: seed.taskId,
|
|
623
|
-
taskKind: seed.taskKind,
|
|
624
|
-
inputRef: '',
|
|
625
|
-
status: seed.status,
|
|
626
|
-
attemptCount: seed.attemptCount,
|
|
627
|
-
maxAttempts: seed.maxAttempts,
|
|
628
|
-
diagnosticJson: seed.diagnosticJson,
|
|
629
|
-
});
|
|
630
|
-
intakeResults.push({
|
|
631
|
-
candidateId: candidate.candidateId,
|
|
632
|
-
status: 'dreamer_seeded',
|
|
633
|
-
nextAction: `pd task show ${seed.taskId} | pd dreamer run --task-id ${seed.taskId}`,
|
|
634
|
-
});
|
|
635
|
-
}
|
|
636
|
-
} catch (seedErr) {
|
|
637
|
-
intakeResults.push({
|
|
638
|
-
candidateId: candidate.candidateId,
|
|
639
|
-
status: 'dreamer_seed_failed',
|
|
640
|
-
error: seedErr instanceof Error ? seedErr.message : String(seedErr),
|
|
641
|
-
nextAction: `pd candidate internalize --candidate-id ${candidate.candidateId}`,
|
|
642
|
-
});
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
if (opts.json) {
|
|
648
|
-
const candidateIds = candidates.map((c) => c.candidateId);
|
|
649
|
-
// CodeRabbit review fix: reflect dreamer seed status in nextAction so
|
|
650
|
-
// the owner knows whether internalization has already started or still
|
|
651
|
-
// needs manual candidate internalize. Previously the message always
|
|
652
|
-
// said "NOT started automatically" even when dreamer tasks were seeded.
|
|
653
|
-
const dreamerSeededCount = intakeResults.filter((r) => r.status === 'dreamer_seeded').length;
|
|
654
|
-
const dreamerSeedFailedCount = intakeResults.filter((r) => r.status === 'dreamer_seed_failed').length;
|
|
655
|
-
const internalizeNextAction = dreamerSeededCount > 0
|
|
656
|
-
? `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.)` : ''}`
|
|
657
|
-
: candidateIds.length > 0
|
|
658
|
-
? `Candidates generated but internalization has NOT started automatically. To begin internalization, run:\n ${candidateIds.map((id) => `pd candidate internalize --candidate-id ${id} --workspace "${workspaceDir}"`).join('\n ')}`
|
|
659
|
-
: 'No candidates were generated from this diagnosis.';
|
|
660
|
-
const jsonOutput = {
|
|
661
|
-
...result,
|
|
662
|
-
intake: {
|
|
663
|
-
enabled: opts.intake !== false,
|
|
664
|
-
candidates: intakeResults,
|
|
665
|
-
},
|
|
666
|
-
nextAction: internalizeNextAction,
|
|
667
|
-
};
|
|
668
|
-
console.log(JSON.stringify(jsonOutput, null, 2));
|
|
669
|
-
if (intakeFailed) {
|
|
670
|
-
process.exit(1);
|
|
671
|
-
}
|
|
672
|
-
return;
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
console.log(`\nResult:`);
|
|
676
|
-
console.log(` Status: ${result.status}`);
|
|
677
|
-
console.log(` Task ID: ${result.taskId}`);
|
|
678
|
-
if (result.contextHash) {
|
|
679
|
-
console.log(` Context Hash: ${result.contextHash.substring(0, 16)}...`);
|
|
680
|
-
}
|
|
681
|
-
if (result.output) {
|
|
682
|
-
console.log(` Diagnosis ID: ${result.output.diagnosisId}`);
|
|
683
|
-
console.log(` Summary: ${result.output.summary}`);
|
|
684
|
-
if (result.output.recommendations) {
|
|
685
|
-
const principleCount = result.output.recommendations.filter((r: { kind: string }) => r.kind === 'principle').length;
|
|
686
|
-
if (principleCount > 0) {
|
|
687
|
-
console.log(` Principles: ${principleCount} candidate(s) generated`);
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
console.log(` Attempt Count: ${result.attemptCount}`);
|
|
692
|
-
|
|
693
|
-
if (intakeResults.length > 0) {
|
|
694
|
-
console.log(`\n Candidate Intake:`);
|
|
695
|
-
for (const ir of intakeResults) {
|
|
696
|
-
if (ir.status === 'consumed') {
|
|
697
|
-
console.log(` ${ir.candidateId}: consumed (ledger: ${ir.ledgerEntryId})`);
|
|
698
|
-
} else if (ir.status === 'skipped') {
|
|
699
|
-
console.log(` ${ir.candidateId}: skipped (--no-intake)`);
|
|
700
|
-
} else if (ir.status === 'intake_failed') {
|
|
701
|
-
console.log(` ${ir.candidateId}: INTAKE FAILED — ${ir.error}`);
|
|
702
|
-
console.log(` Next action: pd candidate intake --candidate-id ${ir.candidateId} --workspace "${workspaceDir}"`);
|
|
703
|
-
} else if (ir.status === 'dreamer_seeded') {
|
|
704
|
-
// CodeRabbit review fix: surface dreamer seed success in TTY output
|
|
705
|
-
console.log(` ${ir.candidateId}: dreamer seeded — ${ir.nextAction}`);
|
|
706
|
-
} else if (ir.status === 'dreamer_seed_failed') {
|
|
707
|
-
// CodeRabbit review fix: surface dreamer seed failure in TTY output
|
|
708
|
-
console.log(` ${ir.candidateId}: DREAMER SEED FAILED — ${ir.error}`);
|
|
709
|
-
console.log(` Next action: ${ir.nextAction}`);
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
if (opts.intake === false && candidates.length > 0) {
|
|
715
|
-
console.log(`\n Note: --no-intake was set. Candidates remain at 'pending'.`);
|
|
716
|
-
console.log(` To intake manually:`);
|
|
717
|
-
for (const c of candidates) {
|
|
718
|
-
console.log(` pd candidate intake --candidate-id ${c.candidateId} --workspace "${workspaceDir}"`);
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
if (candidates.length > 0) {
|
|
723
|
-
console.log(`\n Next Action:`);
|
|
724
|
-
console.log(` Candidates generated but internalization has NOT started automatically.`);
|
|
725
|
-
console.log(` To begin internalization:`);
|
|
726
|
-
for (const c of candidates) {
|
|
727
|
-
console.log(` pd candidate internalize --candidate-id ${c.candidateId} --workspace "${workspaceDir}"`);
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
console.log('');
|
|
732
|
-
|
|
733
|
-
if (intakeFailed) {
|
|
734
|
-
process.exit(1);
|
|
735
|
-
}
|
|
736
|
-
} catch (error: unknown) {
|
|
737
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
738
|
-
let errorCategory = 'execution_failed';
|
|
739
|
-
if (error instanceof PDRuntimeError) {
|
|
740
|
-
errorCategory = error.category;
|
|
741
|
-
}
|
|
742
|
-
if (opts.json) {
|
|
743
|
-
console.log(JSON.stringify({
|
|
744
|
-
status: 'failed',
|
|
745
|
-
errorCategory,
|
|
746
|
-
message,
|
|
747
|
-
runtimeKind,
|
|
748
|
-
}, null, 2));
|
|
749
|
-
} else {
|
|
750
|
-
console.error(`error: ${message} (${errorCategory})`);
|
|
751
|
-
}
|
|
752
|
-
process.exit(1);
|
|
753
|
-
} finally {
|
|
754
|
-
await stateManager.close();
|
|
755
|
-
}
|
|
756
|
-
}
|