@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
|
@@ -1,612 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* pd pain record command — Runtime v2 pain signal entry point.
|
|
3
|
-
*
|
|
4
|
-
* Uses PainToPrincipleService as the single write-side orchestration API.
|
|
5
|
-
* PRI-642 (review blocker 1): the ingress semantic interpretation — origin,
|
|
6
|
-
* bound/unbound correlation, provenance derivation, sentinel handling,
|
|
7
|
-
* submit/degrade/refuse semantics and painIngress.v1 construction — comes
|
|
8
|
-
* from the SHARED evaluator `evaluatePainIngress` in @principles/core
|
|
9
|
-
* (the same authority the OpenClaw funnel uses). This adapter only does
|
|
10
|
-
* host-specific ACQUISITION: read --session, validate it against this
|
|
11
|
-
* workspace's trajectory.db, and collect raw evidence entries.
|
|
12
|
-
*
|
|
13
|
-
* Usage:
|
|
14
|
-
* pd pain record --reason <text> [--score N] [--source manual] [--workspace <path>] [--session <id>] [--host openclaw|codex] [--rollout-id <id> --host-turn-id <id>] [--json]
|
|
15
|
-
*
|
|
16
|
-
* PRI-743: `--host` makes host attribution explicit instead of assumed.
|
|
17
|
-
* `--host openclaw` records the default attribution without the disclosure
|
|
18
|
-
* warning. `--host codex` requires the caller to supply the REAL Codex
|
|
19
|
-
* lineage — `--rollout-id` / `--host-turn-id`, with `--session` as the Codex
|
|
20
|
-
* root session — because the shared ingress evaluator only writes
|
|
21
|
-
* `host_kind=codex` for a bound correlation carrying the complete lineage
|
|
22
|
-
* tuple (rc-6). The CLI never synthesises that tuple: an unverifiable Codex
|
|
23
|
-
* attribution would be a PRI-642 recurrence in another shape (Evidence Over
|
|
24
|
-
* Assumption). `--logical-key` overrides the derived observation key; a key
|
|
25
|
-
* that does not embed the given rollout identity is refused by the evaluator
|
|
26
|
-
* (lineage_mismatch). The correlation schema itself is NOT changed —
|
|
27
|
-
* PainIngressCorrelationV1 bound branches only admit openclaw/codex.
|
|
28
|
-
*/
|
|
29
|
-
import {
|
|
30
|
-
PainToPrincipleService,
|
|
31
|
-
PrincipleTreeLedgerAdapter,
|
|
32
|
-
resolveRuntimeConfig,
|
|
33
|
-
isRuntimeConfigError,
|
|
34
|
-
isFeatureEnabled,
|
|
35
|
-
isBuiltinPiAiProvider,
|
|
36
|
-
evaluatePainIngress,
|
|
37
|
-
} from '@principles/core/runtime-v2';
|
|
38
|
-
import type { PainIngressDecision, IngressEvidenceEntry, PainEvidenceEntry, PainCorrelation } from '@principles/core/runtime-v2';
|
|
39
|
-
import { resolveWorkspaceDir } from '../resolve-workspace.js';
|
|
40
|
-
import { loadPdConfig, computeFlagsFromLoadResult } from '../services/pd-config-loader.js';
|
|
41
|
-
import { acquireTrajectoryEvidenceFromDb } from './build-trajectory-evidence.js';
|
|
42
|
-
|
|
43
|
-
interface RecordOptions {
|
|
44
|
-
reason?: string;
|
|
45
|
-
score?: number;
|
|
46
|
-
source?: string;
|
|
47
|
-
workspace?: string;
|
|
48
|
-
json?: boolean;
|
|
49
|
-
session?: string;
|
|
50
|
-
wait?: boolean;
|
|
51
|
-
/** PRI-743: explicit host attribution for a bound --session pain. */
|
|
52
|
-
host?: string;
|
|
53
|
-
/** PRI-743 follow-up: Codex rollout identity — required by --host codex. */
|
|
54
|
-
rolloutId?: string;
|
|
55
|
-
/** PRI-743 follow-up: Codex turn id — required by --host codex. */
|
|
56
|
-
hostTurnId?: string;
|
|
57
|
-
/** PRI-743 follow-up: Codex logical observation key override for --host codex. */
|
|
58
|
-
logicalKey?: string;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function emitSessionBindingFailure(
|
|
62
|
-
opts: RecordOptions,
|
|
63
|
-
failure: { reason: string; message: string; nextAction: string },
|
|
64
|
-
): void {
|
|
65
|
-
if (opts.json) {
|
|
66
|
-
console.log(JSON.stringify({
|
|
67
|
-
status: 'failed',
|
|
68
|
-
reason: failure.reason,
|
|
69
|
-
message: failure.message,
|
|
70
|
-
nextAction: failure.nextAction,
|
|
71
|
-
}, null, 2));
|
|
72
|
-
} else {
|
|
73
|
-
console.error(`Error: ${failure.message}`);
|
|
74
|
-
console.error(`Reason: ${failure.reason}`);
|
|
75
|
-
console.error(`Next action: ${failure.nextAction}`);
|
|
76
|
-
}
|
|
77
|
-
process.exit(1);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function toIngressEntry(entry: PainEvidenceEntry): IngressEvidenceEntry {
|
|
81
|
-
// Trajectory evidence references observed behavior (owner messages,
|
|
82
|
-
// assistant turns, tool-call failures) — behavior traces.
|
|
83
|
-
return { kind: 'behavior_trace', sourceRef: entry.sourceRef, note: entry.note };
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* PRI-642 (SPEC §7.3/§7.4, review blocker 1): build the report from this
|
|
88
|
-
* adapter's host-specific facts and let the SHARED evaluator decide.
|
|
89
|
-
*
|
|
90
|
-
* Per-channel policy (SPEC §7.3/§8.2 vs OpenClaw):
|
|
91
|
-
*
|
|
92
|
-
* - explicit `--session` + acquisition available (real session + real entries):
|
|
93
|
-
* → cli_explicit_session + bound → submit with real evidence.
|
|
94
|
-
* - explicit `--session` + acquisition unavailable with the binding VERIFIED
|
|
95
|
-
* (empty_trajectory / evidence-table-level evidence_read_failed — the
|
|
96
|
-
* sessions table was queried and DID contain the id; SPEC §8.2: binding
|
|
97
|
-
* failure and evidence failure are separate axes, a real session with
|
|
98
|
-
* unusable evidence is bound + unavailable, not unbound):
|
|
99
|
-
* → cli_explicit_session + bound → shared evaluator DEGRADES (row 4):
|
|
100
|
-
* submit with honest empty evidence; the admission gate owns what
|
|
101
|
-
* empty evidence is worth. PRI-783 Owner directive: a correct current
|
|
102
|
-
* session id is sufficient — empty evidence must not hard-refuse.
|
|
103
|
-
* - explicit `--session` + acquisition unavailable with the binding
|
|
104
|
-
* UNVERIFIED (session_not_found / trajectory_unavailable / DB-open-level
|
|
105
|
-
* evidence_read_failed — SPEC §8.2's "real session" premise does not
|
|
106
|
-
* hold: the CLI verifies session ids against trajectory.db itself, so
|
|
107
|
-
* when that DB is missing or unopenable the id is unproven):
|
|
108
|
-
* → cli_explicit_session + unbound → shared evaluator REFUSES (row 5)
|
|
109
|
-
* before any LLM/task/candidate mutation. Claiming bound here would
|
|
110
|
-
* also let the observability writer persist the unverified id into a
|
|
111
|
-
* freshly created trajectory.db — laundering an unproven fact into
|
|
112
|
-
* future "evidence" (PRI-783 review P1, self-proving loop).
|
|
113
|
-
* - no `--session` → unbound Owner report (matrix row 6) → submit with
|
|
114
|
-
* disclosure; no sentinel session, no placeholder evidence, no trajectory
|
|
115
|
-
* projection (the CLI skips observability when the ingress yields no
|
|
116
|
-
* bound session — SPEC §7.4).
|
|
117
|
-
*/
|
|
118
|
-
function resolveIngressDecision(
|
|
119
|
-
input: { opts: RecordOptions; stateDir: string; workspaceDir: string; painId: string },
|
|
120
|
-
): { decision: PainIngressDecision; acquisitionDetail: string | null; acquisitionReason: string | null } {
|
|
121
|
-
const { opts, stateDir, workspaceDir, painId } = input;
|
|
122
|
-
const score = opts.score ?? 80;
|
|
123
|
-
const base = {
|
|
124
|
-
identity: { kind: 'manual_pain_id' as const, painId },
|
|
125
|
-
painType: 'user_frustration' as const,
|
|
126
|
-
source: opts.source ?? 'manual',
|
|
127
|
-
reason: opts.reason ?? '',
|
|
128
|
-
score,
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
// PRI-743 follow-up: an explicit Codex attribution. The lineage ids are the
|
|
132
|
-
// caller's (presence validated in handlePainRecord); the logical observation
|
|
133
|
-
// key is derived with the SAME rule the Codex ingestion path uses
|
|
134
|
-
// (codex-adapter admission.ts buildLiveCorrectionCandidate →
|
|
135
|
-
// `codex|<rolloutIdentity>|<turnId>|user`) unless --logical-key overrides it.
|
|
136
|
-
// The CLI cannot read the Codex trajectory (that is the ingestion path's
|
|
137
|
-
// job), so the evidence class is honestly 'unavailable': the shared
|
|
138
|
-
// evaluator takes its bound+unavailable 'degrade' branch and submits the
|
|
139
|
-
// pain with real lineage and empty evidence rather than fabricating either.
|
|
140
|
-
if (opts.host === 'codex') {
|
|
141
|
-
const rolloutIdentity = opts.rolloutId as string;
|
|
142
|
-
const hostTurnId = opts.hostTurnId as string;
|
|
143
|
-
const rootSessionId = opts.session as string;
|
|
144
|
-
const correlation: PainCorrelation = {
|
|
145
|
-
status: 'bound',
|
|
146
|
-
hostKind: 'codex',
|
|
147
|
-
rootSessionId,
|
|
148
|
-
rolloutIdentity,
|
|
149
|
-
logicalObservationKey: opts.logicalKey ?? `codex|${rolloutIdentity}|${hostTurnId}|user`,
|
|
150
|
-
hostTurnId,
|
|
151
|
-
};
|
|
152
|
-
const decision = evaluatePainIngress({
|
|
153
|
-
...base,
|
|
154
|
-
origin: { kind: 'owner_manual', channel: 'cli_explicit_session' },
|
|
155
|
-
correlation,
|
|
156
|
-
evidence: { status: 'unavailable', reason: 'trajectory_unavailable' },
|
|
157
|
-
});
|
|
158
|
-
return { decision, acquisitionDetail: null, acquisitionReason: null };
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (!opts.session) {
|
|
162
|
-
// No --session: external unbound Owner report (matrix row 6). Allowed
|
|
163
|
-
// by SPEC §7.4 with a disclosure warning; never claims host binding.
|
|
164
|
-
const decision = evaluatePainIngress({
|
|
165
|
-
...base,
|
|
166
|
-
origin: { kind: 'owner_manual', channel: 'external_cli_unbound' },
|
|
167
|
-
correlation: { status: 'unbound', reason: 'external_cli' },
|
|
168
|
-
evidence: { status: 'unavailable', reason: 'not_applicable_unbound' },
|
|
169
|
-
});
|
|
170
|
-
return { decision, acquisitionDetail: null, acquisitionReason: null };
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// --session: SPEC §7.3/§8.2. Binding failure and evidence failure are
|
|
174
|
-
// separate axes, and the acquisition result carries the binding fact
|
|
175
|
-
// directly (PRI-783 review): 'verified' = the sessions table was queried
|
|
176
|
-
// and DID contain the id; 'unverified' = missing/unopenable DB or absent
|
|
177
|
-
// id. Only a VERIFIED binding may degrade to a bound submission (row 4);
|
|
178
|
-
// an unverified one is refused (row 5) — claiming bound for an unverified
|
|
179
|
-
// id would let the observability writer persist that id into a freshly
|
|
180
|
-
// created trajectory.db (self-proving loop). Per-channel policy differs;
|
|
181
|
-
// semantic authority is shared.
|
|
182
|
-
const acquisition = acquireTrajectoryEvidenceFromDb(stateDir, opts.session, workspaceDir);
|
|
183
|
-
if (acquisition.status === 'unavailable') {
|
|
184
|
-
const { reasonCode, binding } = acquisition;
|
|
185
|
-
if (binding === 'verified') {
|
|
186
|
-
// empty_trajectory / evidence-table-level evidence_read_failed —
|
|
187
|
-
// bound + unavailable (row 4): degrade to an honest empty-evidence
|
|
188
|
-
// submission; the admission gate decides what empty evidence is worth.
|
|
189
|
-
const decision = evaluatePainIngress({
|
|
190
|
-
...base,
|
|
191
|
-
origin: { kind: 'owner_manual', channel: 'cli_explicit_session' },
|
|
192
|
-
correlation: { status: 'bound', hostKind: 'openclaw', sessionId: opts.session },
|
|
193
|
-
evidence: { status: 'unavailable', reason: reasonCode },
|
|
194
|
-
});
|
|
195
|
-
return { decision, acquisitionDetail: acquisition.detail, acquisitionReason: reasonCode };
|
|
196
|
-
}
|
|
197
|
-
// binding 'unverified' (session_not_found / trajectory_unavailable /
|
|
198
|
-
// DB-open-level evidence_read_failed) — the binding claim could not be
|
|
199
|
-
// validated: refuse (row 5) before any mutation.
|
|
200
|
-
const decision = evaluatePainIngress({
|
|
201
|
-
...base,
|
|
202
|
-
origin: { kind: 'owner_manual', channel: 'cli_explicit_session' },
|
|
203
|
-
correlation: { status: 'unbound', reason: 'external_cli' },
|
|
204
|
-
evidence: { status: 'unavailable', reason: 'not_applicable_unbound' },
|
|
205
|
-
});
|
|
206
|
-
if (decision.action === 'refuse') {
|
|
207
|
-
return { decision, acquisitionDetail: acquisition.detail, acquisitionReason: reasonCode };
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// Available evidence: a real session with real entries — submit, bound.
|
|
212
|
-
if (acquisition.status === 'available') {
|
|
213
|
-
// PRI-743: host attribution is explicit when --host openclaw is given;
|
|
214
|
-
// absent --host keeps the pre-PRI-743 'openclaw' default (validated and
|
|
215
|
-
// disclosed by handlePainRecord — rc-9). --host codex never reaches this
|
|
216
|
-
// point — it returns from its own branch above and must not read the
|
|
217
|
-
// OpenClaw trajectory — so the bound correlation here is the openclaw shape.
|
|
218
|
-
const hostKind = 'openclaw' as const;
|
|
219
|
-
const decision = evaluatePainIngress({
|
|
220
|
-
...base,
|
|
221
|
-
origin: { kind: 'owner_manual', channel: 'cli_explicit_session' },
|
|
222
|
-
correlation: { status: 'bound', hostKind, sessionId: opts.session },
|
|
223
|
-
evidence: { status: 'available', entries: acquisition.entries.map(toIngressEntry) as [IngressEvidenceEntry, ...IngressEvidenceEntry[]] },
|
|
224
|
-
});
|
|
225
|
-
return { decision, acquisitionDetail: null, acquisitionReason: null };
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
// Exhaustive — acquireTrajectoryEvidenceFromDb returns {available, unavailable}
|
|
229
|
-
// only. Unavailable either returned above (degrade for verified bindings,
|
|
230
|
-
// refuse for unverified ones); a future-added reason must be classified
|
|
231
|
-
// explicitly here rather than silently degrading.
|
|
232
|
-
const decision = evaluatePainIngress({
|
|
233
|
-
...base,
|
|
234
|
-
origin: { kind: 'owner_manual', channel: 'cli_explicit_session' },
|
|
235
|
-
correlation: { status: 'unbound', reason: 'external_cli' },
|
|
236
|
-
evidence: { status: 'unavailable', reason: 'not_applicable_unbound' },
|
|
237
|
-
});
|
|
238
|
-
return { decision, acquisitionDetail: null, acquisitionReason: null };
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
export async function handlePainRecord(opts: RecordOptions): Promise<void> {
|
|
242
|
-
// PRI-743: fail loud on an unknown --host before any mutation (cli-5/cli-6).
|
|
243
|
-
if (opts.host !== undefined && opts.host !== 'openclaw' && opts.host !== 'codex') {
|
|
244
|
-
const message = `invalid --host: expected openclaw | codex, got ${opts.host}`;
|
|
245
|
-
if (opts.json) {
|
|
246
|
-
console.log(JSON.stringify({
|
|
247
|
-
status: 'failed',
|
|
248
|
-
reason: 'invalid_host_kind',
|
|
249
|
-
message,
|
|
250
|
-
nextAction: 'Pass --host openclaw or --host codex, or omit --host (defaults to openclaw).',
|
|
251
|
-
}, null, 2));
|
|
252
|
-
} else {
|
|
253
|
-
console.error(`Error: ${message}`);
|
|
254
|
-
console.error('Next action: pass --host openclaw or --host codex, or omit --host (defaults to openclaw).');
|
|
255
|
-
}
|
|
256
|
-
process.exit(1);
|
|
257
|
-
return; // guard: test stubs of process.exit continue execution (cli-2-exit-stops)
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
// PRI-743 follow-up: --host codex must carry the REAL Codex lineage. The
|
|
261
|
-
// shared ingress evaluator only attributes `host_kind=codex` to a bound
|
|
262
|
-
// correlation holding the complete tuple (rootSessionId / rolloutIdentity /
|
|
263
|
-
// logicalObservationKey / hostTurnId — rc-6); the CLI never synthesises that
|
|
264
|
-
// tuple, because an unverifiable Codex attribution would itself be the
|
|
265
|
-
// misattribution PRI-743 exists to remove. Missing lineage fails loud before
|
|
266
|
-
// any mutation (cli-5/cli-6) — the caller owns those ids.
|
|
267
|
-
if (opts.host === 'codex') {
|
|
268
|
-
const missing: string[] = [];
|
|
269
|
-
if (!opts.session) missing.push('--session <codex root session id>');
|
|
270
|
-
if (!opts.rolloutId) missing.push('--rollout-id <codex rollout identity>');
|
|
271
|
-
if (!opts.hostTurnId) missing.push('--host-turn-id <codex turn id>');
|
|
272
|
-
if (missing.length > 0) {
|
|
273
|
-
const message = `--host codex requires the real Codex lineage — missing ${missing.join(', ')}`;
|
|
274
|
-
const nextAction = 'Pass --session <root session id> --rollout-id <rollout identity> --host-turn-id <turn id> so the pain carries verifiable Codex lineage, or use --host openclaw for OpenClaw-attributed sessions.';
|
|
275
|
-
if (opts.json) {
|
|
276
|
-
console.log(JSON.stringify({
|
|
277
|
-
status: 'failed',
|
|
278
|
-
reason: 'codex_lineage_required',
|
|
279
|
-
message,
|
|
280
|
-
nextAction,
|
|
281
|
-
}, null, 2));
|
|
282
|
-
} else {
|
|
283
|
-
console.error(`Error: ${message}`);
|
|
284
|
-
console.error(`Next action: ${nextAction}`);
|
|
285
|
-
}
|
|
286
|
-
process.exit(1);
|
|
287
|
-
return; // guard: test stubs of process.exit continue execution (cli-2-exit-stops)
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
if (!opts.reason) {
|
|
292
|
-
console.error('Error: --reason <text> is required');
|
|
293
|
-
console.error('Usage: pd pain record --reason <text> [--score N] [--source manual] [--workspace <path>] [--session <id>] [--host openclaw|codex] [--rollout-id <id> --host-turn-id <id>] [--json]');
|
|
294
|
-
process.exit(1);
|
|
295
|
-
return;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
// Bug-P fix: enforce reason length limit to prevent oversized data entering the pipeline.
|
|
299
|
-
// Consistent with pain-flood-simulation.ts (MAX_REASON_LENGTH = 500) and synthetic-baseline.ts.
|
|
300
|
-
// CodeRabbit review fix: emit JSON on --json and stop execution after exit (cli-1, cli-2, cli-5).
|
|
301
|
-
const MAX_REASON_LENGTH = 500;
|
|
302
|
-
if (opts.reason.length > MAX_REASON_LENGTH) {
|
|
303
|
-
if (opts.json) {
|
|
304
|
-
console.log(JSON.stringify({
|
|
305
|
-
status: 'failed',
|
|
306
|
-
reason: 'reason_too_long',
|
|
307
|
-
message: `--reason must be at most ${MAX_REASON_LENGTH} characters (got ${opts.reason.length})`,
|
|
308
|
-
nextAction: 'Shorten the reason text or split it into multiple pain records.',
|
|
309
|
-
}, null, 2));
|
|
310
|
-
} else {
|
|
311
|
-
console.error(`Error: --reason must be at most ${MAX_REASON_LENGTH} characters (got ${opts.reason.length})`);
|
|
312
|
-
console.error('Next action: shorten the reason text or split it into multiple pain records.');
|
|
313
|
-
}
|
|
314
|
-
process.exit(1);
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
if (opts.score !== undefined && (isNaN(opts.score) || opts.score < 0 || opts.score > 100)) {
|
|
319
|
-
if (opts.json) {
|
|
320
|
-
console.log(JSON.stringify({
|
|
321
|
-
status: 'failed',
|
|
322
|
-
reason: 'score_invalid',
|
|
323
|
-
message: '--score must be a number between 0 and 100',
|
|
324
|
-
nextAction: 'Provide --score as an integer from 0 to 100, or omit it for the default (80).',
|
|
325
|
-
}, null, 2));
|
|
326
|
-
} else {
|
|
327
|
-
console.error('Error: --score must be a number between 0 and 100');
|
|
328
|
-
console.error('Next action: provide --score as an integer from 0 to 100, or omit it for the default (80).');
|
|
329
|
-
}
|
|
330
|
-
process.exit(1);
|
|
331
|
-
return;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
const workspaceDir = resolveWorkspaceDir(opts.workspace);
|
|
335
|
-
const stateDir = `${workspaceDir}/.state`;
|
|
336
|
-
const painId = `manual_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
|
|
337
|
-
|
|
338
|
-
// PRI-642: run the SHARED ingress evaluator before any service/LLM/task
|
|
339
|
-
// mutation; the decision (submit/degrade/refuse) is not made here.
|
|
340
|
-
const { decision, acquisitionDetail, acquisitionReason } = resolveIngressDecision({ opts, stateDir, workspaceDir, painId });
|
|
341
|
-
|
|
342
|
-
if (decision.action === 'refuse') {
|
|
343
|
-
// SPEC §7.3: the CLI must surface the specific acquisition reason —
|
|
344
|
-
// the shared evaluator produces the refuse decision; we map the
|
|
345
|
-
// acquisition detail to the Operator reason. PRI-783: the evaluator's
|
|
346
|
-
// generic next action suggests `pd pain record --session` — the exact
|
|
347
|
-
// path that just failed — so every CLI acquisition refuse gets honest,
|
|
348
|
-
// reason-specific guidance instead.
|
|
349
|
-
const reason = opts.session !== undefined && acquisitionReason !== null
|
|
350
|
-
? acquisitionReason
|
|
351
|
-
: decision.reasonCode;
|
|
352
|
-
const detailSuffix = acquisitionDetail !== null ? ` (${acquisitionDetail})` : '';
|
|
353
|
-
const nextAction =
|
|
354
|
-
reason === 'session_not_found'
|
|
355
|
-
? 'Check the session id — it is not present in this workspace trajectory — or drop --session to record an unbound Owner report.'
|
|
356
|
-
: reason === 'trajectory_unavailable'
|
|
357
|
-
? 'No trajectory.db exists in this workspace, so the session id could not be verified — point --workspace at the workspace that owns the session, or drop --session to record an unbound Owner report.'
|
|
358
|
-
: reason === 'evidence_read_failed'
|
|
359
|
-
? 'The workspace trajectory could not be read, so the session id could not be verified — resolve access to .state/trajectory.db, or drop --session to record an unbound Owner report.'
|
|
360
|
-
: decision.nextAction;
|
|
361
|
-
emitSessionBindingFailure(opts, {
|
|
362
|
-
reason,
|
|
363
|
-
message: `${decision.warning}${detailSuffix}`,
|
|
364
|
-
nextAction,
|
|
365
|
-
});
|
|
366
|
-
return;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
const binding = decision.legacy;
|
|
370
|
-
// SPEC §7.4: without a bound session the trajectory projection is skipped
|
|
371
|
-
// (disclosed below) instead of fabricating the sentinel session 'cli'.
|
|
372
|
-
const recordObservability = binding.sessionId !== undefined;
|
|
373
|
-
|
|
374
|
-
const ledgerAdapter = new PrincipleTreeLedgerAdapter({ stateDir });
|
|
375
|
-
// PRI-306: Load .pd/config.yaml for config-driven runtime binding
|
|
376
|
-
const configResult = loadPdConfig(workspaceDir);
|
|
377
|
-
if (!configResult.ok) {
|
|
378
|
-
// ERR-009 / Runtime Contract Rule 9: fail loud with reason, don't silently swallow
|
|
379
|
-
console.error(`Warning: .pd/config.yaml has errors — using defaults:`);
|
|
380
|
-
for (const e of configResult.errors) {
|
|
381
|
-
console.error(` ${e.path}: ${e.reason}`);
|
|
382
|
-
if (e.nextAction) console.error(` nextAction: ${e.nextAction}`);
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
const effectiveConfig = configResult.ok ? configResult.effective : configResult.defaults;
|
|
386
|
-
|
|
387
|
-
// PRI-369: Determine async mode from feature flag + --wait override
|
|
388
|
-
const featureFlags = computeFlagsFromLoadResult(configResult);
|
|
389
|
-
const asyncFlagEnabled = isFeatureEnabled(featureFlags, 'diagnostician_async_cli');
|
|
390
|
-
const asyncMode = asyncFlagEnabled && !opts.wait; // --wait overrides flag to force sync
|
|
391
|
-
|
|
392
|
-
const service = new PainToPrincipleService({
|
|
393
|
-
workspaceDir,
|
|
394
|
-
stateDir,
|
|
395
|
-
ledgerAdapter,
|
|
396
|
-
owner: 'pd-cli',
|
|
397
|
-
autoIntakeEnabled: true,
|
|
398
|
-
effectiveConfig,
|
|
399
|
-
getEnvVar: (name: string) => process.env[name],
|
|
400
|
-
asyncMode,
|
|
401
|
-
});
|
|
402
|
-
|
|
403
|
-
const result = await service.recordPain({
|
|
404
|
-
painId,
|
|
405
|
-
painType: 'user_frustration',
|
|
406
|
-
source: opts.source ?? 'manual',
|
|
407
|
-
reason: opts.reason,
|
|
408
|
-
score: opts.score ?? 80,
|
|
409
|
-
sessionId: binding.sessionId,
|
|
410
|
-
agentId: 'pd-cli',
|
|
411
|
-
provenance: binding.provenance,
|
|
412
|
-
hostKind: binding.hostKind,
|
|
413
|
-
evidence: binding.evidence,
|
|
414
|
-
recordObservability,
|
|
415
|
-
painIngress: binding.painIngress,
|
|
416
|
-
});
|
|
417
|
-
|
|
418
|
-
// Show diagnostic info for config failures
|
|
419
|
-
if (result.failureCategory === 'config_missing') {
|
|
420
|
-
const legacyConfig = resolveRuntimeConfig(stateDir);
|
|
421
|
-
if (isRuntimeConfigError(legacyConfig)) {
|
|
422
|
-
if (opts.json) {
|
|
423
|
-
console.log(JSON.stringify({
|
|
424
|
-
status: 'failed',
|
|
425
|
-
painId: result.painId,
|
|
426
|
-
taskId: result.taskId,
|
|
427
|
-
failureCategory: result.failureCategory,
|
|
428
|
-
message: result.message,
|
|
429
|
-
configError: {
|
|
430
|
-
reason: legacyConfig.reason,
|
|
431
|
-
message: legacyConfig.message,
|
|
432
|
-
nextAction: legacyConfig.nextAction,
|
|
433
|
-
},
|
|
434
|
-
}, null, 2));
|
|
435
|
-
} else {
|
|
436
|
-
console.error(` Config resolution failed: ${legacyConfig.reason}`);
|
|
437
|
-
console.error(` ${legacyConfig.message}`);
|
|
438
|
-
console.error(` nextAction: ${legacyConfig.nextAction}`);
|
|
439
|
-
}
|
|
440
|
-
process.exit(1);
|
|
441
|
-
return;
|
|
442
|
-
}
|
|
443
|
-
const config = legacyConfig;
|
|
444
|
-
const missing: string[] = [];
|
|
445
|
-
if (!config.provider) missing.push('provider');
|
|
446
|
-
if (!config.model) missing.push('model');
|
|
447
|
-
if (!config.apiKeyEnv) missing.push('apiKeyEnv');
|
|
448
|
-
if (config.provider) {
|
|
449
|
-
// PRI-621 PR2 review: the pi-ai catalog lookup is a core capability —
|
|
450
|
-
// the CLI queries it through @principles/core and must not depend on
|
|
451
|
-
// pi-ai directly (EP-06).
|
|
452
|
-
if (!isBuiltinPiAiProvider(config.provider) && !config.baseUrl) {
|
|
453
|
-
missing.push('baseUrl');
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
if (missing.length > 0 || config.provider || config.apiKeyEnv) {
|
|
458
|
-
console.error('Error: Pain signal failed\n');
|
|
459
|
-
|
|
460
|
-
if (missing.length > 0) {
|
|
461
|
-
console.error(' Missing configuration:');
|
|
462
|
-
for (const m of missing) {
|
|
463
|
-
console.error(` - ${m}`);
|
|
464
|
-
}
|
|
465
|
-
console.error('');
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
if (config.provider || config.model || config.apiKeyEnv || config.baseUrl) {
|
|
469
|
-
console.error(' Current workflow policy (pd-runtime-v2-diagnosis):');
|
|
470
|
-
console.error(` runtimeKind: ${config.runtimeKind}`);
|
|
471
|
-
if (config.provider) console.error(` provider: ${config.provider}`);
|
|
472
|
-
if (config.model) console.error(` model: ${config.model}`);
|
|
473
|
-
if (config.apiKeyEnv) console.error(` apiKeyEnv: ${config.apiKeyEnv}`);
|
|
474
|
-
if (config.baseUrl) console.error(` baseUrl: ${config.baseUrl}`);
|
|
475
|
-
console.error('');
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
console.error(' To diagnose and configure your runtime, run:');
|
|
479
|
-
console.error(' pd runtime probe --runtime pi-ai --provider <name> --model <id> --apiKeyEnv <name>');
|
|
480
|
-
console.error('');
|
|
481
|
-
|
|
482
|
-
if (result.message) console.error(` Details: ${result.message}`);
|
|
483
|
-
process.exit(1);
|
|
484
|
-
return;
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
// PRI-642 (SPEC §12.1.6): generated-but-unadmitted candidates must never
|
|
489
|
-
// read as completed internalization — surface the admission disposition.
|
|
490
|
-
const admissionDecisions = result.admissionResults?.map(r => r.admission.decision) ?? [];
|
|
491
|
-
const admittedCount = admissionDecisions.filter(d => d === 'admitted').length;
|
|
492
|
-
const gatedWarning = result.status === 'succeeded'
|
|
493
|
-
&& result.candidateIds.length > 0
|
|
494
|
-
&& admittedCount === 0
|
|
495
|
-
? `admitted: 0 of ${result.candidateIds.length} candidates (all gated — needs_evidence/deferred); `
|
|
496
|
-
+ 'nothing was internalized. See admissionResults for per-candidate reasons; add --session evidence or Owner context to raise confidence above the admission threshold.'
|
|
497
|
-
: null;
|
|
498
|
-
// PRI-642: the ingress decision's own disclosures (degrade warning /
|
|
499
|
-
// unbound context_unbound warning) are surfaced to the operator.
|
|
500
|
-
const decisionWarnings = decision.action === 'degrade'
|
|
501
|
-
? [`${decision.warning} Next action: ${decision.nextAction}`]
|
|
502
|
-
: decision.action === 'submit'
|
|
503
|
-
? decision.warnings
|
|
504
|
-
: [];
|
|
505
|
-
const cliWarnings = [...decisionWarnings, gatedWarning].filter((w): w is string => w !== null && w !== undefined);
|
|
506
|
-
|
|
507
|
-
// PRI-743: the pre-existing 'openclaw' default is an assumption, not
|
|
508
|
-
// evidence — disclose it whenever it actually applies (rc-9), so host
|
|
509
|
-
// attribution can never silently distort PRI-743-style host comparisons.
|
|
510
|
-
// Unbound reports (no --session) keep host_kind NULL: they carry no host
|
|
511
|
-
// trace at all, so labelling them 'openclaw' would be a fresh misattribution
|
|
512
|
-
// rather than a compatibility default.
|
|
513
|
-
const hostDefaultWarning = binding.sessionId !== undefined && opts.host === undefined
|
|
514
|
-
? 'host kind not specified, defaulting to openclaw; pass --host codex with --rollout-id/--host-turn-id to attribute this pain to the Codex host.'
|
|
515
|
-
: null;
|
|
516
|
-
if (hostDefaultWarning !== null) cliWarnings.push(hostDefaultWarning);
|
|
517
|
-
|
|
518
|
-
if (opts.json) {
|
|
519
|
-
const out: Record<string, unknown> = { ...result };
|
|
520
|
-
// PRI-743: surface the effective host attribution explicitly in --json
|
|
521
|
-
// (machine consumers doing host comparisons must not re-derive it).
|
|
522
|
-
if (binding.sessionId !== undefined) {
|
|
523
|
-
out.hostAttribution = binding.hostKind;
|
|
524
|
-
}
|
|
525
|
-
// Ensure nextAction is present for actionable states
|
|
526
|
-
if (out.status === 'submitted') {
|
|
527
|
-
if (!out.nextAction) {
|
|
528
|
-
out.nextAction = `pd diagnose run --task-id ${out.taskId} --workspace "${workspaceDir}" --runtime pi-ai --json`;
|
|
529
|
-
}
|
|
530
|
-
if (!out.reason) {
|
|
531
|
-
out.reason = out.message;
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
// PRI-570: async submission has NO automatic consumer — the
|
|
535
|
-
// internalization auto-consumer's runner kinds (dreamer..rollout_reviewer)
|
|
536
|
-
// do not include 'diagnostician', so a submitted task stays pending until
|
|
537
|
-
// the owner runs the diagnose command. Never let that stay implicit (rc-9).
|
|
538
|
-
// PRI-642: unbound/gated disclosures join the same warnings channel.
|
|
539
|
-
const submittedWarning = out.status === 'submitted'
|
|
540
|
-
? 'Async mode: no background consumer picks up diagnostician tasks. '
|
|
541
|
-
+ `Run ${out.nextAction} or the pain signal will remain pending indefinitely. `
|
|
542
|
-
+ 'Use --wait to diagnose synchronously instead.'
|
|
543
|
-
: null;
|
|
544
|
-
const allWarnings = [...cliWarnings];
|
|
545
|
-
if (submittedWarning !== null) allWarnings.unshift(submittedWarning);
|
|
546
|
-
if (allWarnings.length > 0) {
|
|
547
|
-
out.warning = allWarnings.join(' ');
|
|
548
|
-
out.warnings = allWarnings;
|
|
549
|
-
}
|
|
550
|
-
console.log(JSON.stringify(out, null, 2));
|
|
551
|
-
if (result.status !== 'succeeded' && result.status !== 'skipped' && result.status !== 'retried' && result.status !== 'submitted') {
|
|
552
|
-
process.exit(1);
|
|
553
|
-
return;
|
|
554
|
-
}
|
|
555
|
-
} else {
|
|
556
|
-
if (result.status === 'succeeded') {
|
|
557
|
-
console.log('[OK] Pain signal recorded via PainToPrincipleService');
|
|
558
|
-
console.log(` Pain ID: ${result.painId}`);
|
|
559
|
-
console.log(` Task ID: ${result.taskId}`);
|
|
560
|
-
if (result.runId) console.log(` Run ID: ${result.runId}`);
|
|
561
|
-
if (result.artifactId) console.log(` Artifact ID: ${result.artifactId}`);
|
|
562
|
-
if (result.candidateIds.length > 0) console.log(` Candidate IDs: ${result.candidateIds.join(', ')}`);
|
|
563
|
-
if (result.ledgerEntryIds.length > 0) console.log(` Ledger Entry IDs: ${result.ledgerEntryIds.join(', ')}`);
|
|
564
|
-
if (result.progress && result.progress.seededTaskIds.length > 0) {
|
|
565
|
-
console.log(` Seeded Task IDs: ${result.progress.seededTaskIds.join(', ')}`);
|
|
566
|
-
}
|
|
567
|
-
console.log(` Reason: ${opts.reason}`);
|
|
568
|
-
console.log(` Score: ${opts.score ?? 80}`);
|
|
569
|
-
console.log(` Source: ${opts.source ?? 'manual'}`);
|
|
570
|
-
console.log(` Workspace: ${workspaceDir}`);
|
|
571
|
-
if (binding.sessionId) {
|
|
572
|
-
console.log(` Session: ${binding.sessionId} (bound, host=${binding.hostKind}, ${binding.evidence.length} evidence entries)`);
|
|
573
|
-
} else {
|
|
574
|
-
console.log(' Session: unbound (Owner report; no trajectory evidence)');
|
|
575
|
-
}
|
|
576
|
-
if (result.admissionResults && result.admissionResults.length > 0) {
|
|
577
|
-
console.log(` Admission: ${admittedCount} of ${result.admissionResults.length} candidates admitted`);
|
|
578
|
-
for (const r of result.admissionResults) {
|
|
579
|
-
console.log(` - ${r.candidateId}: ${r.admission.decision} (${r.admission.reason})`);
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
if (result.latencyMs !== undefined) console.log(` Latency: ${result.latencyMs}ms`);
|
|
583
|
-
for (const w of cliWarnings) {
|
|
584
|
-
console.warn(` ⚠️ ${w}`);
|
|
585
|
-
}
|
|
586
|
-
console.log(`\nDiagnostician pipeline running. Check progress with:`);
|
|
587
|
-
console.log(` pd task show ${result.taskId} --workspace "${workspaceDir}"`);
|
|
588
|
-
} else if (result.status === 'submitted') {
|
|
589
|
-
console.log('[SUBMITTED] Pain signal submitted for async diagnosis');
|
|
590
|
-
console.log(` Pain ID: ${result.painId}`);
|
|
591
|
-
console.log(` Task ID: ${result.taskId}`);
|
|
592
|
-
console.log(` Status: submitted`);
|
|
593
|
-
// PRI-570: no background consumer picks up diagnostician tasks — say so
|
|
594
|
-
// explicitly instead of implying async diagnosis happens on its own (rc-9).
|
|
595
|
-
console.error(' WARNING: async mode has no automatic consumer for diagnostician tasks.');
|
|
596
|
-
console.error(` Run: pd diagnose run --task-id ${result.taskId} --workspace "${workspaceDir}" --runtime pi-ai`);
|
|
597
|
-
console.error(' Or re-record with --wait to diagnose synchronously. Without this, the task stays pending indefinitely.');
|
|
598
|
-
} else if (result.status === 'skipped') {
|
|
599
|
-
console.log(`[SKIP] Task already in progress: ${result.message ?? 'unknown'}`);
|
|
600
|
-
console.log(` Pain ID: ${result.painId}`);
|
|
601
|
-
console.log(` Task ID: ${result.taskId}`);
|
|
602
|
-
} else if (result.status === 'retried') {
|
|
603
|
-
console.log(`[RETRY] Task retried: ${result.message ?? 'unknown'}`);
|
|
604
|
-
console.log(` Pain ID: ${result.painId}`);
|
|
605
|
-
console.log(` Task ID: ${result.taskId}`);
|
|
606
|
-
} else {
|
|
607
|
-
console.error('[FAIL] Pain signal failed:', result.message);
|
|
608
|
-
process.exit(1);
|
|
609
|
-
return;
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
}
|