@principles/pd-cli 1.152.12 → 1.152.14
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.map +1 -1
- package/dist/commands/candidate.js +34 -7
- package/dist/commands/candidate.js.map +1 -1
- package/dist/commands/diagnose.d.ts.map +1 -1
- package/dist/commands/diagnose.js +23 -7
- package/dist/commands/diagnose.js.map +1 -1
- package/dist/commands/pain-retry.d.ts.map +1 -1
- package/dist/commands/pain-retry.js +21 -7
- package/dist/commands/pain-retry.js.map +1 -1
- package/package.json +13 -7
- package/CHANGELOG.md +0 -23
- 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 -1250
- 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 -1214
- 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 -628
- 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 -1242
- 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 -10
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
import * as fs from 'node:fs';
|
|
2
|
-
import * as os from 'node:os';
|
|
3
|
-
import * as path from 'node:path';
|
|
4
|
-
import { afterEach, describe, expect, it } from 'vitest';
|
|
5
|
-
import { buildVersionReport, formatShortVersion, VersionReportError } from '../../services/version-report.js';
|
|
6
|
-
|
|
7
|
-
const temporaryDirectories: string[] = [];
|
|
8
|
-
|
|
9
|
-
function tempHome(): string {
|
|
10
|
-
const root = fs.mkdtempSync(path.join(fs.realpathSync(os.tmpdir()), 'pd-version-'));
|
|
11
|
-
temporaryDirectories.push(root);
|
|
12
|
-
return root;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function writeDualSlotHome(home: string): void {
|
|
16
|
-
const pdHome = path.join(home, '.pd');
|
|
17
|
-
fs.mkdirSync(path.join(pdHome, 'releases', 'b'.repeat(64), 'plugin'), { recursive: true });
|
|
18
|
-
fs.mkdirSync(path.join(pdHome, 'bootstrap'), { recursive: true });
|
|
19
|
-
fs.mkdirSync(path.join(pdHome, 'logs'), { recursive: true });
|
|
20
|
-
fs.writeFileSync(path.join(pdHome, 'active.json'), JSON.stringify({
|
|
21
|
-
schemaVersion: 1,
|
|
22
|
-
generation: 4,
|
|
23
|
-
releaseId: 'b'.repeat(64),
|
|
24
|
-
releaseMetadataDigest: '2'.repeat(64),
|
|
25
|
-
previousReleaseId: 'a'.repeat(64),
|
|
26
|
-
transactionId: 'txn-9',
|
|
27
|
-
productVersion: '1.223.0',
|
|
28
|
-
}));
|
|
29
|
-
fs.writeFileSync(path.join(pdHome, 'bootstrap', 'bootstrap.json'), JSON.stringify({
|
|
30
|
-
bootstrapVersion: '1.1.0',
|
|
31
|
-
installedAt: '2026-08-25T00:00:00Z',
|
|
32
|
-
}));
|
|
33
|
-
fs.writeFileSync(path.join(pdHome, 'install.json'), JSON.stringify({ channel: 'candidate', autoCheck: true }));
|
|
34
|
-
fs.writeFileSync(path.join(pdHome, 'releases', 'b'.repeat(64), 'metadata.json'), JSON.stringify({
|
|
35
|
-
productVersion: '1.223.0',
|
|
36
|
-
releaseId: 'b'.repeat(64),
|
|
37
|
-
metadataDigest: '2'.repeat(64),
|
|
38
|
-
}));
|
|
39
|
-
fs.writeFileSync(path.join(pdHome, 'releases', 'b'.repeat(64), 'plugin', 'package.json'), JSON.stringify({ version: '1.76.1' }));
|
|
40
|
-
fs.writeFileSync(path.join(pdHome, 'logs', 'history.jsonl'), [
|
|
41
|
-
JSON.stringify({ at: '2026-08-24T00:00:00Z', kind: 'update', outcome: 'succeeded', transactionId: 'txn-8' }),
|
|
42
|
-
JSON.stringify({ at: '2026-08-25T00:00:00Z', kind: 'recovery', outcome: 'recovered', transactionId: 'txn-9' }),
|
|
43
|
-
].join('\n') + '\n');
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
afterEach(() => {
|
|
47
|
-
while (temporaryDirectories.length > 0) {
|
|
48
|
-
const directory = temporaryDirectories.pop();
|
|
49
|
-
if (directory) fs.rmSync(directory, { recursive: true, force: true, maxRetries: 10, retryDelay: 200 });
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
describe('canonical version report (SPEC 12 / 18-1, 18-10)', () => {
|
|
54
|
-
it('reports the canonical product identity from ~/.pd, not package.json', () => {
|
|
55
|
-
const home = tempHome();
|
|
56
|
-
writeDualSlotHome(home);
|
|
57
|
-
const report = buildVersionReport(home);
|
|
58
|
-
expect(report).toMatchObject({
|
|
59
|
-
productVersion: '1.223.0',
|
|
60
|
-
releaseId: 'b'.repeat(64),
|
|
61
|
-
bootstrapVersion: '1.1.0',
|
|
62
|
-
channel: 'candidate',
|
|
63
|
-
source: 'official-installer',
|
|
64
|
-
generation: 4,
|
|
65
|
-
health: 'healthy',
|
|
66
|
-
});
|
|
67
|
-
expect(report.components.plugin).toBe('1.76.1');
|
|
68
|
-
expect(report.lastTransaction).toEqual({ id: 'txn-9', kind: 'recovery', outcome: 'recovered' });
|
|
69
|
-
expect(formatShortVersion(report)).toBe(`Principles Disciple 1.223.0 (${'b'.repeat(12)})`);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('classifies a legacy overlay installation with an installer next action', () => {
|
|
73
|
-
const home = tempHome();
|
|
74
|
-
// The current official installer creates ~/.pd/bin before the transactional
|
|
75
|
-
// dual-slot layout is activated. That support directory must not make a
|
|
76
|
-
// valid legacy overlay look like a corrupt partial dual-slot install.
|
|
77
|
-
fs.mkdirSync(path.join(home, '.pd', 'bin'), { recursive: true });
|
|
78
|
-
const overlay = path.join(home, '.openclaw', 'extensions', 'principles-disciple');
|
|
79
|
-
fs.mkdirSync(overlay, { recursive: true });
|
|
80
|
-
fs.writeFileSync(path.join(overlay, 'package.json'), JSON.stringify({ version: '1.218.0' }));
|
|
81
|
-
const report = buildVersionReport(home);
|
|
82
|
-
expect(report).toMatchObject({
|
|
83
|
-
productVersion: '1.218.0',
|
|
84
|
-
source: 'official-legacy-overlay',
|
|
85
|
-
health: 'degraded',
|
|
86
|
-
generation: 0,
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('retains compatibility with the older nested legacy overlay manifest', () => {
|
|
91
|
-
const home = tempHome();
|
|
92
|
-
const overlay = path.join(home, '.openclaw', 'extensions', 'principles-disciple', 'plugin');
|
|
93
|
-
fs.mkdirSync(overlay, { recursive: true });
|
|
94
|
-
fs.writeFileSync(path.join(overlay, 'package.json'), JSON.stringify({ version: '1.202.0' }));
|
|
95
|
-
expect(buildVersionReport(home)).toMatchObject({
|
|
96
|
-
productVersion: '1.202.0', source: 'official-legacy-overlay', health: 'degraded',
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('refuses with a structured reason and next action when nothing is installed', () => {
|
|
101
|
-
const home = tempHome();
|
|
102
|
-
try {
|
|
103
|
-
buildVersionReport(home);
|
|
104
|
-
throw new Error('expected VersionReportError');
|
|
105
|
-
} catch (error) {
|
|
106
|
-
expect(error).toBeInstanceOf(VersionReportError);
|
|
107
|
-
const refusal = error as VersionReportError;
|
|
108
|
-
expect(refusal.reason).toBe('not_installed');
|
|
109
|
-
expect(refusal.nextAction).toMatch(/official installer/i);
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('reports degraded health when the active release directory is incomplete', () => {
|
|
114
|
-
const home = tempHome();
|
|
115
|
-
writeDualSlotHome(home);
|
|
116
|
-
fs.rmSync(path.join(home, '.pd', 'releases', 'b'.repeat(64), 'metadata.json'), { force: true });
|
|
117
|
-
const report = buildVersionReport(home);
|
|
118
|
-
expect(report.health).toBe('degraded');
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('reports corrupt health when release metadata exists but disagrees with active.json', () => {
|
|
122
|
-
const home = tempHome();
|
|
123
|
-
writeDualSlotHome(home);
|
|
124
|
-
fs.writeFileSync(path.join(home, '.pd', 'releases', 'b'.repeat(64), 'metadata.json'), '{}');
|
|
125
|
-
const report = buildVersionReport(home);
|
|
126
|
-
expect(report.health).toBe('corrupt');
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it('refuses a malformed active record loudly instead of guessing', () => {
|
|
130
|
-
const home = tempHome();
|
|
131
|
-
fs.mkdirSync(path.join(home, '.pd'), { recursive: true });
|
|
132
|
-
fs.writeFileSync(path.join(home, '.pd', 'active.json'), JSON.stringify({ generation: 'four' }));
|
|
133
|
-
try {
|
|
134
|
-
buildVersionReport(home);
|
|
135
|
-
throw new Error('expected VersionReportError');
|
|
136
|
-
} catch (error) {
|
|
137
|
-
expect(error).toBeInstanceOf(VersionReportError);
|
|
138
|
-
expect((error as VersionReportError).reason).toBe('active_record_corrupt');
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
describe('runtime layout version report (SPEC 12, installed ~/.pd/runtime layout)', () => {
|
|
144
|
-
/** Mirrors the real installed layout: active.json + runtime/<component>/, no releases/, no logs/, no bootstrap/. */
|
|
145
|
-
function writeRuntimeOnlyHome(home: string): void {
|
|
146
|
-
const pdHome = path.join(home, '.pd');
|
|
147
|
-
fs.mkdirSync(pdHome, { recursive: true });
|
|
148
|
-
fs.writeFileSync(path.join(pdHome, 'active.json'), JSON.stringify({
|
|
149
|
-
schemaVersion: 1,
|
|
150
|
-
generation: 14,
|
|
151
|
-
releaseId: 'bundled-1.74.1-5eb58e30bfad',
|
|
152
|
-
releaseMetadataDigest: '5eb58e30bfad6205e3028b99fa7a3a6f67e138b9e97c7ed40b043ba9d8d85343',
|
|
153
|
-
previousReleaseId: 'bundled-1.74.1-9bbf8abc3b86',
|
|
154
|
-
transactionId: 'install-1789622247194-0346a565',
|
|
155
|
-
productVersion: '1.74.1',
|
|
156
|
-
}));
|
|
157
|
-
fs.writeFileSync(path.join(pdHome, 'install.json'), JSON.stringify({ channel: 'stable', autoCheck: true }));
|
|
158
|
-
const componentVersions: Readonly<Record<string, string>> = {
|
|
159
|
-
'codex-adapter': '0.1.0',
|
|
160
|
-
console: '0.1.0',
|
|
161
|
-
core: '1.74.1',
|
|
162
|
-
'host-runtime': '0.1.0',
|
|
163
|
-
'install-layout': '0.2.0',
|
|
164
|
-
'pd-cli': '1.74.1',
|
|
165
|
-
plugin: '1.76.1',
|
|
166
|
-
'release-manager': '1.74.1',
|
|
167
|
-
};
|
|
168
|
-
for (const [component, version] of Object.entries(componentVersions)) {
|
|
169
|
-
const dir = path.join(pdHome, 'runtime', component);
|
|
170
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
171
|
-
fs.writeFileSync(path.join(dir, 'package.json'), JSON.stringify({ name: `@principles/${component}`, version }));
|
|
172
|
-
}
|
|
173
|
-
// The real runtime also carries non-package support directories.
|
|
174
|
-
fs.mkdirSync(path.join(pdHome, 'runtime', 'bin'), { recursive: true });
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
it('reads component versions from the live runtime layout and stays explicit about unverifiable identity', () => {
|
|
178
|
-
const home = tempHome();
|
|
179
|
-
writeRuntimeOnlyHome(home);
|
|
180
|
-
const report = buildVersionReport(home);
|
|
181
|
-
expect(report).toMatchObject({
|
|
182
|
-
productVersion: '1.74.1',
|
|
183
|
-
releaseId: 'bundled-1.74.1-5eb58e30bfad',
|
|
184
|
-
source: 'official-installer',
|
|
185
|
-
generation: 14,
|
|
186
|
-
channel: 'stable',
|
|
187
|
-
});
|
|
188
|
-
expect(report.components.plugin).toBe('1.76.1');
|
|
189
|
-
expect(report.components.core).toBe('1.74.1');
|
|
190
|
-
expect(report.components['pd-cli']).toBe('1.74.1');
|
|
191
|
-
expect(report.components['release-manager']).toBe('1.74.1');
|
|
192
|
-
expect(report.componentsSource).toBe('runtime');
|
|
193
|
-
// No release metadata exists to verify the active identity against, and
|
|
194
|
-
// independently versioned components are not corruption: the report stays
|
|
195
|
-
// honestly degraded instead of claiming health from package versions.
|
|
196
|
-
expect(report.health).toBe('degraded');
|
|
197
|
-
expect(report.lastTransaction).toBeNull();
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
it('degrades a malformed runtime component manifest to an omitted component instead of dying (PRI-833 review P1)', () => {
|
|
201
|
-
const home = tempHome();
|
|
202
|
-
writeRuntimeOnlyHome(home);
|
|
203
|
-
// Exactly the corruption this command exists to diagnose: one live
|
|
204
|
-
// component manifest is garbage. The report must survive with that
|
|
205
|
-
// component omitted — not abort with state_corrupt.
|
|
206
|
-
const corruptManifest = '{' + 'not-valid-json';
|
|
207
|
-
fs.writeFileSync(path.join(home, '.pd', 'runtime', 'plugin', 'package.json'), corruptManifest);
|
|
208
|
-
const report = buildVersionReport(home);
|
|
209
|
-
expect(report.components.plugin).toBeUndefined();
|
|
210
|
-
expect(report.components.core).toBe('1.74.1');
|
|
211
|
-
expect(report.componentsSource).toBe('runtime');
|
|
212
|
-
expect(report.health).toBe('degraded');
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
it('falls back to the release cache per component when the runtime copy is missing (PRI-833 review P2)', () => {
|
|
216
|
-
const home = tempHome();
|
|
217
|
-
writeRuntimeOnlyHome(home);
|
|
218
|
-
// Partially populated runtime: the core manifest vanished. The release
|
|
219
|
-
// cache (active releaseId dir) still knows core's version.
|
|
220
|
-
fs.rmSync(path.join(home, '.pd', 'runtime', 'core'), { recursive: true, force: true });
|
|
221
|
-
const coreFallbackDir = path.join(home, '.pd', 'releases', 'bundled-1.74.1-5eb58e30bfad', 'core');
|
|
222
|
-
fs.mkdirSync(coreFallbackDir, { recursive: true });
|
|
223
|
-
fs.writeFileSync(path.join(coreFallbackDir, 'package.json'), JSON.stringify({ name: '@principles/core', version: '1.60.0' }));
|
|
224
|
-
const report = buildVersionReport(home);
|
|
225
|
-
expect(report.components.core).toBe('1.60.0');
|
|
226
|
-
expect(report.components.plugin).toBe('1.76.1');
|
|
227
|
-
expect(report.componentsSource).toBe('runtime');
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
it('prefers live runtime component manifests over the release cache when both exist', () => {
|
|
231
|
-
const home = tempHome();
|
|
232
|
-
writeDualSlotHome(home);
|
|
233
|
-
const pdHome = path.join(home, '.pd');
|
|
234
|
-
fs.rmSync(path.join(pdHome, 'releases', 'b'.repeat(64), 'plugin'), { recursive: true, force: true });
|
|
235
|
-
fs.mkdirSync(path.join(pdHome, 'runtime', 'plugin'), { recursive: true });
|
|
236
|
-
fs.writeFileSync(path.join(pdHome, 'runtime', 'plugin', 'package.json'), JSON.stringify({ version: '1.999.0' }));
|
|
237
|
-
const report = buildVersionReport(home);
|
|
238
|
-
expect(report.health).toBe('healthy');
|
|
239
|
-
expect(report.componentsSource).toBe('runtime');
|
|
240
|
-
expect(report.components.plugin).toBe('1.999.0');
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
it('keeps the release-cache fallback for installs without a runtime directory', () => {
|
|
244
|
-
const home = tempHome();
|
|
245
|
-
writeDualSlotHome(home);
|
|
246
|
-
const report = buildVersionReport(home);
|
|
247
|
-
expect(report.health).toBe('healthy');
|
|
248
|
-
expect(report.componentsSource).toBe('release-cached');
|
|
249
|
-
expect(report.components.plugin).toBe('1.76.1');
|
|
250
|
-
});
|
|
251
|
-
});
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared admission gate helper for CLI commands that call intakeService.intake().
|
|
3
|
-
*
|
|
4
|
-
* PRI-442 Stage 4 / PRI-503: previously only `candidate.ts` checked the gate;
|
|
5
|
-
* `pain-retry.ts` and `diagnose.ts` bypassed it (ERR-089 sibling-branch defect).
|
|
6
|
-
* This shared helper is the single entry point so future CLI commands that
|
|
7
|
-
* call intake() can reuse it instead of re-implementing (or skipping) the check.
|
|
8
|
-
*
|
|
9
|
-
* Runtime Contract: rc-9-no-silent-fallback — refusal includes reason + nextAction
|
|
10
|
-
* (callers MUST surface these in their structured CLI output).
|
|
11
|
-
*/
|
|
12
|
-
import { evaluateCandidateAdmissionFromRecord, type AdmissionGateResult } from '@principles/core/runtime-v2';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Check admission gate for a candidate. Returns null if admitted (caller may
|
|
16
|
-
* proceed); returns AdmissionGateResult with reason + nextAction if refused
|
|
17
|
-
* (caller must refuse and surface reason/nextAction in CLI output).
|
|
18
|
-
*
|
|
19
|
-
* @param candidate - Must carry recommendationKind and confidence from the candidate record
|
|
20
|
-
*/
|
|
21
|
-
export function checkAdmissionGate(
|
|
22
|
-
candidate: { recommendationKind: string; confidence: number | null },
|
|
23
|
-
): AdmissionGateResult | null {
|
|
24
|
-
const admission = evaluateCandidateAdmissionFromRecord({
|
|
25
|
-
recommendationKind: candidate.recommendationKind as Parameters<typeof evaluateCandidateAdmissionFromRecord>[0]['recommendationKind'],
|
|
26
|
-
confidence: candidate.confidence,
|
|
27
|
-
});
|
|
28
|
-
if (admission.decision === 'admitted') return null;
|
|
29
|
-
return admission;
|
|
30
|
-
}
|
package/src/commands/artifact.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* pd artifact show command — Artifact registry inspection.
|
|
3
|
-
*
|
|
4
|
-
* Usage:
|
|
5
|
-
* pd artifact show <artifactId> --workspace <path> [--json]
|
|
6
|
-
*/
|
|
7
|
-
import {
|
|
8
|
-
RuntimeStateManager,
|
|
9
|
-
artifactShow,
|
|
10
|
-
} from '@principles/core/runtime-v2';
|
|
11
|
-
import { resolveWorkspaceDir } from '../resolve-workspace.js';
|
|
12
|
-
|
|
13
|
-
interface ArtifactShowOptions {
|
|
14
|
-
artifactId: string;
|
|
15
|
-
workspace?: string;
|
|
16
|
-
json?: boolean;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* pd artifact show <artifactId> [--workspace <path>] [--json]
|
|
21
|
-
*
|
|
22
|
-
* Shows artifact content and its associated principle candidates.
|
|
23
|
-
* Returns: artifactId, runId, taskId, artifactKind, contentJson, createdAt, candidates[].
|
|
24
|
-
*/
|
|
25
|
-
export async function handleArtifactShow(opts: ArtifactShowOptions): Promise<void> {
|
|
26
|
-
const workspaceDir: string = resolveWorkspaceDir(opts.workspace);
|
|
27
|
-
const stateManager = new RuntimeStateManager({ workspaceDir });
|
|
28
|
-
|
|
29
|
-
try {
|
|
30
|
-
await stateManager.initialize();
|
|
31
|
-
|
|
32
|
-
const result = await artifactShow({
|
|
33
|
-
artifactId: opts.artifactId,
|
|
34
|
-
stateManager,
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
if (!result) {
|
|
38
|
-
console.error(`Artifact not found: ${opts.artifactId}`);
|
|
39
|
-
process.exit(1);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (opts.json) {
|
|
43
|
-
console.log(JSON.stringify(result, null, 2));
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
console.log(`\nArtifact: ${result.artifactId}\n`);
|
|
48
|
-
console.log(` Kind: ${result.artifactKind}`);
|
|
49
|
-
console.log(` Run: ${result.runId}`);
|
|
50
|
-
console.log(` Task: ${result.taskId}`);
|
|
51
|
-
console.log(` Created: ${result.createdAt}`);
|
|
52
|
-
console.log(` Candidates: ${result.candidates.length}`);
|
|
53
|
-
|
|
54
|
-
// Pretty-print the JSON content
|
|
55
|
-
try {
|
|
56
|
-
const parsed = JSON.parse(result.contentJson);
|
|
57
|
-
console.log(`\n Content (parsed):`);
|
|
58
|
-
console.log(` diagnosisId: ${parsed.diagnosisId ?? 'N/A'}`);
|
|
59
|
-
console.log(` summary: ${parsed.summary ?? 'N/A'}`);
|
|
60
|
-
if (parsed.recommendations) {
|
|
61
|
-
console.log(` recommendations: ${parsed.recommendations.length}`);
|
|
62
|
-
const principles = parsed.recommendations.filter((r: { kind: string }) => r.kind === 'principle');
|
|
63
|
-
if (principles.length > 0) {
|
|
64
|
-
console.log(` (${principles.length} principle candidates)`);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
} catch {
|
|
68
|
-
console.log(` Content: ${result.contentJson.substring(0, 200)}...`);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (result.candidates.length > 0) {
|
|
72
|
-
console.log(`\n Candidate Details:`);
|
|
73
|
-
for (const c of result.candidates) {
|
|
74
|
-
console.log(` - ${c.candidateId} | ${c.title} | ${c.status}`);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
console.log('');
|
|
79
|
-
} finally {
|
|
80
|
-
await stateManager.close();
|
|
81
|
-
}
|
|
82
|
-
}
|
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Trajectory Evidence Builder for CLI — PRI-341
|
|
3
|
-
*
|
|
4
|
-
* Reads trajectory.db directly to extract evidence entries for `pd pain record`.
|
|
5
|
-
* This avoids a dependency on openclaw-plugin (which uses WorkspaceContext / TrajectoryRegistry)
|
|
6
|
-
* while providing the same capability for the CLI path.
|
|
7
|
-
*
|
|
8
|
-
* Core/plugin boundary: this file lives in pd-cli (I/O boundary), not in principles-core.
|
|
9
|
-
* Uses better-sqlite3 (already a pd-cli dependency) and sanitizeString from core.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import Database from 'better-sqlite3';
|
|
13
|
-
import * as fs from 'fs';
|
|
14
|
-
import * as path from 'path';
|
|
15
|
-
import {
|
|
16
|
-
MAX_EVIDENCE_ENTRIES,
|
|
17
|
-
MAX_EVIDENCE_NOTE_CHARS,
|
|
18
|
-
sanitizeString,
|
|
19
|
-
} from '@principles/core/runtime-v2';
|
|
20
|
-
import type { PainEvidenceEntry } from '@principles/core/runtime-v2';
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* PRI-642 (SPEC §7.3): discriminated acquisition result. `unavailable` carries
|
|
24
|
-
* a distinct reasonCode so `pd pain record --session` can fail/degrade
|
|
25
|
-
* explicitly BEFORE any LLM/task/candidate mutation, without placeholder
|
|
26
|
-
* evidence.
|
|
27
|
-
*
|
|
28
|
-
* `binding` (PRI-783 review P1) is the small separate-axes fact the ingress
|
|
29
|
-
* decision keys on: 'verified' = the sessions table was queried and DID
|
|
30
|
-
* contain the id; 'unverified' = the id could not be validated (DB missing,
|
|
31
|
-
* DB unopenable, id absent, or sessions table unreadable). Only verified
|
|
32
|
-
* bindings may degrade to a bound submission — claiming bound for an
|
|
33
|
-
* unverified id would let the observability writer persist that id into a
|
|
34
|
-
* freshly created trajectory.db, laundering an unverified fact into future
|
|
35
|
-
* "evidence" (self-proving loop).
|
|
36
|
-
*/
|
|
37
|
-
export type TrajectoryEvidenceAcquisition =
|
|
38
|
-
| { status: 'available'; entries: PainEvidenceEntry[] }
|
|
39
|
-
| {
|
|
40
|
-
status: 'unavailable';
|
|
41
|
-
reasonCode: 'trajectory_unavailable' | 'session_not_found' | 'empty_trajectory' | 'evidence_read_failed';
|
|
42
|
-
detail: string;
|
|
43
|
-
binding: 'verified' | 'unverified';
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
/** SourceRef markers that carry no real behavior trace (placeholder shapes). */
|
|
47
|
-
const PLACEHOLDER_SOURCE_REFS = new Set([
|
|
48
|
-
'owner_reported:cli',
|
|
49
|
-
'owner_message:unavailable',
|
|
50
|
-
'agent_turn:unavailable',
|
|
51
|
-
'tool_call_failure:unavailable',
|
|
52
|
-
'trajectory:empty',
|
|
53
|
-
]);
|
|
54
|
-
|
|
55
|
-
interface TrajectoryDbCollection {
|
|
56
|
-
entries: PainEvidenceEntry[];
|
|
57
|
-
realEntryCount: number;
|
|
58
|
-
readFailed: boolean;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Collect evidence entries from an open trajectory.db for one session.
|
|
63
|
-
* Shared by the typed acquisition API and the legacy array wrapper so the
|
|
64
|
-
* two can never drift.
|
|
65
|
-
*/
|
|
66
|
-
function collectEvidenceFromDb(
|
|
67
|
-
db: Database.Database,
|
|
68
|
-
sessionId: string,
|
|
69
|
-
workspaceDir?: string,
|
|
70
|
-
): TrajectoryDbCollection {
|
|
71
|
-
const evidence: PainEvidenceEntry[] = [];
|
|
72
|
-
let readFailed = false;
|
|
73
|
-
|
|
74
|
-
// Try to read user turns with correction detection
|
|
75
|
-
try {
|
|
76
|
-
const userTurns = db.prepare(`
|
|
77
|
-
SELECT id, raw_excerpt, correction_detected, correction_cue, created_at
|
|
78
|
-
FROM user_turns
|
|
79
|
-
WHERE session_id = ?
|
|
80
|
-
ORDER BY id ASC
|
|
81
|
-
`).all(sessionId) as Record<string, unknown>[];
|
|
82
|
-
|
|
83
|
-
const lastCorrectionTurn = [...userTurns].reverse().find(t => Boolean(t.correction_detected));
|
|
84
|
-
if (lastCorrectionTurn) {
|
|
85
|
-
const rawExcerpt = typeof lastCorrectionTurn.raw_excerpt === 'string'
|
|
86
|
-
? lastCorrectionTurn.raw_excerpt
|
|
87
|
-
: '';
|
|
88
|
-
const sanitizedNote = sanitizeString(
|
|
89
|
-
rawExcerpt.slice(0, MAX_EVIDENCE_NOTE_CHARS),
|
|
90
|
-
workspaceDir,
|
|
91
|
-
);
|
|
92
|
-
evidence.push({
|
|
93
|
-
sourceRef: `owner_message:${String(lastCorrectionTurn.created_at ?? 'unknown')}`,
|
|
94
|
-
note: sanitizedNote,
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
} catch {
|
|
98
|
-
readFailed = true;
|
|
99
|
-
// user_turns table may not exist — degrade gracefully
|
|
100
|
-
if (evidence.length < MAX_EVIDENCE_ENTRIES) {
|
|
101
|
-
evidence.push({
|
|
102
|
-
sourceRef: 'owner_message:unavailable',
|
|
103
|
-
note: 'trajectory_user_turns_unavailable',
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Try to read assistant turns (last 3)
|
|
109
|
-
try {
|
|
110
|
-
const assistantTurns = db.prepare(`
|
|
111
|
-
SELECT id, sanitized_text, stop_reason, created_at
|
|
112
|
-
FROM assistant_turns
|
|
113
|
-
WHERE session_id = ?
|
|
114
|
-
ORDER BY id ASC
|
|
115
|
-
`).all(sessionId) as Record<string, unknown>[];
|
|
116
|
-
|
|
117
|
-
const recentAssistant = assistantTurns.slice(-3);
|
|
118
|
-
for (const turn of recentAssistant) {
|
|
119
|
-
if (evidence.length >= MAX_EVIDENCE_ENTRIES) break;
|
|
120
|
-
const sanitizedText = typeof turn.sanitized_text === 'string'
|
|
121
|
-
? turn.sanitized_text
|
|
122
|
-
: '';
|
|
123
|
-
const sanitizedNote = sanitizeString(
|
|
124
|
-
sanitizedText.slice(0, MAX_EVIDENCE_NOTE_CHARS),
|
|
125
|
-
workspaceDir,
|
|
126
|
-
);
|
|
127
|
-
// Enhanced: append truncation warning when stop_reason=length
|
|
128
|
-
const stopReason = typeof turn.stop_reason === 'string' ? turn.stop_reason : null;
|
|
129
|
-
const truncationWarning = stopReason === 'length' ? ' [TRUNCATED: output cut off by length limit]' : '';
|
|
130
|
-
evidence.push({
|
|
131
|
-
sourceRef: `agent_turn:${String(turn.created_at ?? 'unknown')}`,
|
|
132
|
-
note: sanitizedNote + truncationWarning,
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
} catch {
|
|
136
|
-
readFailed = true;
|
|
137
|
-
// assistant_turns table may not exist — degrade gracefully
|
|
138
|
-
if (evidence.length < MAX_EVIDENCE_ENTRIES) {
|
|
139
|
-
evidence.push({
|
|
140
|
-
sourceRef: 'agent_turn:unavailable',
|
|
141
|
-
note: 'trajectory_assistant_turns_unavailable',
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// PRI-358: Try to read failed tool_calls (last 3 failures, chronological order)
|
|
147
|
-
try {
|
|
148
|
-
const failedToolCalls = db.prepare(`
|
|
149
|
-
SELECT tool_name, error_type, exit_code, result_preview, created_at
|
|
150
|
-
FROM (
|
|
151
|
-
SELECT tool_name, error_type, exit_code, result_preview, created_at
|
|
152
|
-
FROM tool_calls
|
|
153
|
-
WHERE session_id = ? AND outcome = 'failure'
|
|
154
|
-
ORDER BY created_at DESC
|
|
155
|
-
LIMIT 3
|
|
156
|
-
)
|
|
157
|
-
ORDER BY created_at ASC
|
|
158
|
-
`).all(sessionId) as Record<string, unknown>[];
|
|
159
|
-
|
|
160
|
-
for (const tc of failedToolCalls) {
|
|
161
|
-
if (evidence.length >= MAX_EVIDENCE_ENTRIES) break;
|
|
162
|
-
const toolName = typeof tc.tool_name === 'string' ? tc.tool_name : 'unknown';
|
|
163
|
-
const errorType = typeof tc.error_type === 'string' ? tc.error_type : 'unknown';
|
|
164
|
-
const exitCode = tc.exit_code != null ? String(tc.exit_code) : 'N/A';
|
|
165
|
-
// Enhanced: append resultPreview when available
|
|
166
|
-
const resultPreview = typeof tc.result_preview === 'string' ? tc.result_preview : null;
|
|
167
|
-
const previewSuffix = resultPreview ? ` | ${resultPreview.slice(0, 200)}` : '';
|
|
168
|
-
const note = `Tool ${toolName} failed: ${errorType} (exitCode: ${exitCode})${previewSuffix}`;
|
|
169
|
-
evidence.push({
|
|
170
|
-
sourceRef: `tool_call_failure:${String(tc.created_at ?? 'unknown')}`,
|
|
171
|
-
note: sanitizeString(note.slice(0, MAX_EVIDENCE_NOTE_CHARS), workspaceDir),
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
} catch {
|
|
175
|
-
readFailed = true;
|
|
176
|
-
// tool_calls table may not exist — degrade gracefully (only when no other evidence)
|
|
177
|
-
if (evidence.length === 0) {
|
|
178
|
-
evidence.push({
|
|
179
|
-
sourceRef: 'tool_call_failure:unavailable',
|
|
180
|
-
note: 'trajectory_tool_calls_unavailable',
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// If no evidence at all from trajectory, provide a meaningful placeholder
|
|
186
|
-
if (evidence.length === 0) {
|
|
187
|
-
evidence.push({
|
|
188
|
-
sourceRef: 'trajectory:empty',
|
|
189
|
-
note: 'trajectory_available_but_empty: no user correction or assistant turns found',
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const bounded = evidence.slice(0, MAX_EVIDENCE_ENTRIES);
|
|
194
|
-
const realEntryCount = bounded.reduce(
|
|
195
|
-
(count, entry) => count + (PLACEHOLDER_SOURCE_REFS.has(entry.sourceRef) ? 0 : 1),
|
|
196
|
-
0,
|
|
197
|
-
);
|
|
198
|
-
return { entries: bounded, realEntryCount, readFailed };
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* PRI-642 Scope A typed acquisition from trajectory.db (SPEC §7.3).
|
|
203
|
-
*
|
|
204
|
-
* Validates that the requested session exists in the trajectory `sessions`
|
|
205
|
-
* table (every recorded turn/tool call upserts its session row, so an absent
|
|
206
|
-
* row means the session was never seen) and classifies the outcome:
|
|
207
|
-
* - `available` — session bound, ≥1 real behavior-trace entry;
|
|
208
|
-
* - `session_not_found` — session absent from the sessions table (or a
|
|
209
|
-
* `cli`/`unknown` sentinel — never a real session);
|
|
210
|
-
* - `trajectory_unavailable` — no trajectory.db in this workspace;
|
|
211
|
-
* - `evidence_read_failed` — the DB exists but cannot be opened/read;
|
|
212
|
-
* - `empty_trajectory` — real session, no usable evidence rows.
|
|
213
|
-
*/
|
|
214
|
-
export function acquireTrajectoryEvidenceFromDb(
|
|
215
|
-
stateDir: string,
|
|
216
|
-
sessionId: string | undefined,
|
|
217
|
-
workspaceDir?: string,
|
|
218
|
-
): TrajectoryEvidenceAcquisition {
|
|
219
|
-
if (!sessionId || sessionId === 'cli' || sessionId === 'unknown') {
|
|
220
|
-
return {
|
|
221
|
-
status: 'unavailable',
|
|
222
|
-
reasonCode: 'session_not_found',
|
|
223
|
-
detail: sessionId ? `sentinel_session_id:${sessionId}` : 'missing_session_id',
|
|
224
|
-
binding: 'unverified',
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
const dbPath = path.join(stateDir, 'trajectory.db');
|
|
229
|
-
if (!fs.existsSync(dbPath)) {
|
|
230
|
-
return {
|
|
231
|
-
status: 'unavailable',
|
|
232
|
-
reasonCode: 'trajectory_unavailable',
|
|
233
|
-
detail: 'trajectory_db_missing',
|
|
234
|
-
binding: 'unverified',
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
let db: Database.Database;
|
|
239
|
-
try {
|
|
240
|
-
db = new Database(dbPath, { readonly: true });
|
|
241
|
-
} catch (err) {
|
|
242
|
-
return {
|
|
243
|
-
status: 'unavailable',
|
|
244
|
-
reasonCode: 'evidence_read_failed',
|
|
245
|
-
detail: `trajectory_db_unreadable: ${err instanceof Error ? err.message : String(err)}`,
|
|
246
|
-
binding: 'unverified',
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
try {
|
|
251
|
-
// Session existence: rows are upserted by every turn/tool-call write, so
|
|
252
|
-
// an absent row means the trajectory never saw this session.
|
|
253
|
-
let sessionExists = false;
|
|
254
|
-
// PRI-783 review P1: only a query that actually RAN and found the row
|
|
255
|
-
// counts as binding verification — the legacy fallback (sessions table
|
|
256
|
-
// missing) leaves the id unverified.
|
|
257
|
-
let sessionVerified = false;
|
|
258
|
-
try {
|
|
259
|
-
const row = db.prepare('SELECT 1 FROM sessions WHERE session_id = ?').get(sessionId);
|
|
260
|
-
sessionExists = row !== undefined;
|
|
261
|
-
sessionVerified = sessionExists;
|
|
262
|
-
} catch {
|
|
263
|
-
// sessions table missing → cannot validate existence; fall through and
|
|
264
|
-
// let the evidence rows decide (legacy DBs may lack the table).
|
|
265
|
-
sessionExists = true;
|
|
266
|
-
sessionVerified = false;
|
|
267
|
-
}
|
|
268
|
-
if (!sessionExists) {
|
|
269
|
-
return {
|
|
270
|
-
status: 'unavailable',
|
|
271
|
-
reasonCode: 'session_not_found',
|
|
272
|
-
detail: 'session_not_present_in_trajectory',
|
|
273
|
-
binding: 'unverified',
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
const collection = collectEvidenceFromDb(db, sessionId, workspaceDir);
|
|
278
|
-
if (collection.realEntryCount > 0) {
|
|
279
|
-
return { status: 'available', entries: collection.entries };
|
|
280
|
-
}
|
|
281
|
-
if (collection.readFailed) {
|
|
282
|
-
return {
|
|
283
|
-
status: 'unavailable',
|
|
284
|
-
reasonCode: 'evidence_read_failed',
|
|
285
|
-
detail: 'trajectory_tables_unreadable',
|
|
286
|
-
binding: sessionVerified ? 'verified' : 'unverified',
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
return {
|
|
290
|
-
status: 'unavailable',
|
|
291
|
-
reasonCode: 'empty_trajectory',
|
|
292
|
-
detail: 'session_present_but_no_usable_evidence',
|
|
293
|
-
binding: sessionVerified ? 'verified' : 'unverified',
|
|
294
|
-
};
|
|
295
|
-
} finally {
|
|
296
|
-
db.close();
|
|
297
|
-
}
|
|
298
|
-
}
|