create-principles-disciple 1.153.4 → 1.154.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_release/product-identity.json +1 -1
- package/codex-adapter/dist/ingestion/codex-home.d.ts +1 -0
- package/codex-adapter/dist/ingestion/codex-home.js +19 -7
- package/codex-adapter/dist/ingestion/ingestion.js +34 -7
- package/codex-adapter/dist/pd-hook.js +14 -6
- package/codex-adapter/dist/worker/workspace-worker.js +31 -1
- package/codex-adapter/package.json +1 -1
- package/console/dist/server/index.js +5 -16
- package/console/dist/server/utils/installed-layout.js +6 -4
- package/console/dist/server/utils/pd-backups.d.ts +1 -14
- package/console/dist/server/utils/pd-backups.js +12 -64
- package/console/dist/web/assets/app.css +67 -9
- package/console/dist/web/assets/app.js +37 -37
- package/console/dist/web/assets/providers/anthropic.png +0 -0
- package/console/dist/web/assets/providers/deepseek.png +0 -0
- package/console/dist/web/assets/providers/google.png +0 -0
- package/console/dist/web/assets/providers/groq.svg +1 -0
- package/console/dist/web/assets/providers/kimi.png +0 -0
- package/console/dist/web/assets/providers/minimax.png +0 -0
- package/console/dist/web/assets/providers/mistral.svg +28 -0
- package/console/dist/web/assets/providers/nvidia.png +0 -0
- package/console/dist/web/assets/providers/openai.svg +1 -0
- package/console/dist/web/assets/providers/openrouter.svg +3 -0
- package/console/dist/web/assets/providers/qwen.png +0 -0
- package/console/dist/web/assets/providers/together.svg +21 -0
- package/console/dist/web/assets/providers/xai.svg +1 -0
- package/console/dist/web/assets/providers/xiaomi.png +0 -0
- package/console/dist/web/assets/providers/zai.svg +219 -0
- package/core/dist/index.d.ts +1 -2
- package/core/dist/index.d.ts.map +1 -1
- package/core/dist/index.js +4 -2
- package/core/dist/index.js.map +1 -1
- package/core/dist/prompt-builder/focus-compression.d.ts +8 -60
- package/core/dist/prompt-builder/focus-compression.d.ts.map +1 -1
- package/core/dist/prompt-builder/focus-compression.js +8 -434
- package/core/dist/prompt-builder/focus-compression.js.map +1 -1
- package/core/dist/prompt-builder/index.d.ts +1 -2
- package/core/dist/prompt-builder/index.d.ts.map +1 -1
- package/core/dist/prompt-builder/index.js +3 -2
- package/core/dist/prompt-builder/index.js.map +1 -1
- package/core/dist/runtime/activation/production-gate-deps.d.ts +7 -3
- package/core/dist/runtime/activation/production-gate-deps.d.ts.map +1 -1
- package/core/dist/runtime/activation/production-gate-deps.js +15 -6
- package/core/dist/runtime/activation/production-gate-deps.js.map +1 -1
- package/core/dist/runtime/adapter/principle-tree-ledger-adapter.d.ts +2 -0
- package/core/dist/runtime/adapter/principle-tree-ledger-adapter.d.ts.map +1 -1
- package/core/dist/runtime/adapter/principle-tree-ledger-adapter.js +9 -1
- package/core/dist/runtime/adapter/principle-tree-ledger-adapter.js.map +1 -1
- package/core/dist/runtime/config/pd-config-types.d.ts +20 -1
- package/core/dist/runtime/config/pd-config-types.d.ts.map +1 -1
- package/core/dist/runtime/config/pd-config-types.js.map +1 -1
- package/core/dist/runtime/config/pd-config-validate.d.ts.map +1 -1
- package/core/dist/runtime/config/pd-config-validate.js +12 -1
- package/core/dist/runtime/config/pd-config-validate.js.map +1 -1
- package/core/dist/runtime/internalization/bash-risk.d.ts.map +1 -1
- package/core/dist/runtime/internalization/bash-risk.js +6 -3
- package/core/dist/runtime/internalization/bash-risk.js.map +1 -1
- package/core/dist/runtime/internalization/internalization-orchestrator.d.ts +28 -1
- package/core/dist/runtime/internalization/internalization-orchestrator.d.ts.map +1 -1
- package/core/dist/runtime/internalization/internalization-orchestrator.js +109 -13
- package/core/dist/runtime/internalization/internalization-orchestrator.js.map +1 -1
- package/core/dist/runtime/internalization/split-diagnostician-runner.d.ts +10 -0
- package/core/dist/runtime/internalization/split-diagnostician-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/split-diagnostician-runner.js +6 -1
- package/core/dist/runtime/internalization/split-diagnostician-runner.js.map +1 -1
- package/core/dist/runtime/pain-chain-read-model.d.ts +14 -0
- package/core/dist/runtime/pain-chain-read-model.d.ts.map +1 -1
- package/core/dist/runtime/pain-chain-read-model.js +91 -3
- package/core/dist/runtime/pain-chain-read-model.js.map +1 -1
- package/core/dist/runtime/pain-ingress-payload.d.ts +15 -0
- package/core/dist/runtime/pain-ingress-payload.d.ts.map +1 -1
- package/core/dist/runtime/pain-ingress-payload.js +32 -3
- package/core/dist/runtime/pain-ingress-payload.js.map +1 -1
- package/core/dist/runtime/pain-signal-bridge.d.ts +8 -0
- package/core/dist/runtime/pain-signal-bridge.d.ts.map +1 -1
- package/core/dist/runtime/pain-signal-bridge.js +11 -0
- package/core/dist/runtime/pain-signal-bridge.js.map +1 -1
- package/core/dist/runtime/pain-signal-runtime-factory.d.ts.map +1 -1
- package/core/dist/runtime/pain-signal-runtime-factory.js +3 -0
- package/core/dist/runtime/pain-signal-runtime-factory.js.map +1 -1
- package/core/dist/runtime/pain-submit-capability.d.ts +54 -0
- package/core/dist/runtime/pain-submit-capability.d.ts.map +1 -1
- package/core/dist/runtime/pain-submit-capability.js +49 -1
- package/core/dist/runtime/pain-submit-capability.js.map +1 -1
- package/core/dist/runtime/storage-paths.d.ts +9 -10
- package/core/dist/runtime/storage-paths.d.ts.map +1 -1
- package/core/dist/runtime/storage-paths.js +9 -10
- package/core/dist/runtime/storage-paths.js.map +1 -1
- package/core/dist/runtime/store/context/sqlite-context-assembler.d.ts.map +1 -1
- package/core/dist/runtime/store/context/sqlite-context-assembler.js +10 -2
- package/core/dist/runtime/store/context/sqlite-context-assembler.js.map +1 -1
- package/core/dist/runtime/store/storage-paths.d.ts +65 -12
- package/core/dist/runtime/store/storage-paths.d.ts.map +1 -1
- package/core/dist/runtime/store/storage-paths.js +92 -39
- package/core/dist/runtime/store/storage-paths.js.map +1 -1
- package/core/package.json +1 -1
- package/dist/installer.d.ts +113 -9
- package/dist/installer.d.ts.map +1 -1
- package/dist/installer.js +596 -100
- package/dist/installer.js.map +1 -1
- package/dist/installers/codex-host-installer.d.ts +23 -3
- package/dist/installers/codex-host-installer.d.ts.map +1 -1
- package/dist/installers/codex-host-installer.js +36 -20
- package/dist/installers/codex-host-installer.js.map +1 -1
- package/dist/installers/index.d.ts.map +1 -1
- package/dist/installers/index.js +24 -3
- package/dist/installers/index.js.map +1 -1
- package/dist/installers/mcp-registration-conflict.d.ts.map +1 -1
- package/dist/installers/mcp-registration-conflict.js +23 -16
- package/dist/installers/mcp-registration-conflict.js.map +1 -1
- package/dist/installers/openclaw-host-installer.d.ts.map +1 -1
- package/dist/installers/openclaw-host-installer.js +1 -8
- package/dist/installers/openclaw-host-installer.js.map +1 -1
- package/dist/installers/workbuddy-host-installer.js +7 -7
- package/dist/installers/workbuddy-host-installer.js.map +1 -1
- package/dist/mvp-config.d.ts +30 -5
- package/dist/mvp-config.d.ts.map +1 -1
- package/dist/mvp-config.js +49 -16
- package/dist/mvp-config.js.map +1 -1
- package/dist/prompts.js +1 -1
- package/dist/prompts.js.map +1 -1
- package/dist/uninstaller.d.ts.map +1 -1
- package/dist/uninstaller.js +142 -5
- package/dist/uninstaller.js.map +1 -1
- package/dist/update/release-manager.d.ts.map +1 -1
- package/dist/update/release-manager.js +5 -2
- package/dist/update/release-manager.js.map +1 -1
- package/dist/utils/env.d.ts +5 -10
- package/dist/utils/env.d.ts.map +1 -1
- package/dist/utils/env.js +91 -34
- package/dist/utils/env.js.map +1 -1
- package/dist/utils/host-workspace-ownership.d.ts +25 -0
- package/dist/utils/host-workspace-ownership.d.ts.map +1 -1
- package/dist/utils/host-workspace-ownership.js +153 -2
- package/dist/utils/host-workspace-ownership.js.map +1 -1
- package/host-runtime/dist/adaptive-background-append.d.ts +6 -0
- package/host-runtime/dist/adaptive-background-append.js +4 -1
- package/host-runtime/dist/adaptive-decision-protocol.d.ts +18 -2
- package/host-runtime/dist/adaptive-decision-protocol.js +39 -9
- package/host-runtime/dist/adaptive-principle-context-reader.d.ts +79 -0
- package/host-runtime/dist/adaptive-principle-context-reader.js +303 -0
- package/host-runtime/dist/adaptive-priority-provider.d.ts +33 -0
- package/host-runtime/dist/adaptive-priority-provider.js +68 -2
- package/host-runtime/dist/adaptive-selection.d.ts +16 -0
- package/host-runtime/dist/adaptive-selection.js +23 -1
- package/host-runtime/dist/codex-legacy-registration.js +10 -2
- package/host-runtime/dist/conversation-ingestion/pipeline.d.ts +8 -0
- package/host-runtime/dist/conversation-ingestion/pipeline.js +179 -7
- package/host-runtime/dist/degraded-enforcement-marker.js +16 -2
- package/host-runtime/dist/diagnostician-auto-run.js +4 -0
- package/host-runtime/dist/governance-observation-store.d.ts +44 -0
- package/host-runtime/dist/governance-observation-store.js +84 -1
- package/host-runtime/dist/governance-trajectory-turn-reader.d.ts +30 -0
- package/host-runtime/dist/governance-trajectory-turn-reader.js +47 -0
- package/host-runtime/dist/index.d.ts +2 -0
- package/host-runtime/dist/index.js +6 -0
- package/host-runtime/dist/product-telemetry/service.js +86 -20
- package/host-runtime/package.json +1 -1
- package/install-layout/dist/index.d.ts +23 -9
- package/install-layout/dist/index.js +49 -24
- package/install-layout/dist/mcp-binding-contract.d.ts +62 -0
- package/install-layout/dist/mcp-binding-contract.js +175 -3
- package/install-layout/dist/pd-home.d.ts +35 -5
- package/install-layout/dist/pd-home.js +138 -23
- package/install-layout/package.json +1 -1
- package/package.json +4 -4
- package/pd-cli/dist/commands/candidate.d.ts.map +1 -1
- package/pd-cli/dist/commands/candidate.js +134 -8
- package/pd-cli/dist/commands/candidate.js.map +1 -1
- package/pd-cli/dist/commands/codex-worker.d.ts.map +1 -1
- package/pd-cli/dist/commands/codex-worker.js +36 -2
- package/pd-cli/dist/commands/codex-worker.js.map +1 -1
- package/pd-cli/dist/commands/diagnose.d.ts.map +1 -1
- package/pd-cli/dist/commands/diagnose.js +34 -8
- package/pd-cli/dist/commands/diagnose.js.map +1 -1
- package/pd-cli/dist/commands/health-codex-install.d.ts +1 -3
- package/pd-cli/dist/commands/health-codex-install.d.ts.map +1 -1
- package/pd-cli/dist/commands/health-codex-install.js +19 -6
- package/pd-cli/dist/commands/health-codex-install.js.map +1 -1
- package/pd-cli/dist/commands/health-codex.d.ts.map +1 -1
- package/pd-cli/dist/commands/health-codex.js +27 -9
- package/pd-cli/dist/commands/health-codex.js.map +1 -1
- package/pd-cli/dist/commands/health-console.d.ts +2 -1
- package/pd-cli/dist/commands/health-console.d.ts.map +1 -1
- package/pd-cli/dist/commands/health-console.js +12 -3
- package/pd-cli/dist/commands/health-console.js.map +1 -1
- package/pd-cli/dist/commands/health-ingestion.d.ts +10 -2
- package/pd-cli/dist/commands/health-ingestion.d.ts.map +1 -1
- package/pd-cli/dist/commands/health-ingestion.js +56 -14
- package/pd-cli/dist/commands/health-ingestion.js.map +1 -1
- package/pd-cli/dist/commands/health-mcp.d.ts +19 -7
- package/pd-cli/dist/commands/health-mcp.d.ts.map +1 -1
- package/pd-cli/dist/commands/health-mcp.js +131 -45
- package/pd-cli/dist/commands/health-mcp.js.map +1 -1
- package/pd-cli/dist/commands/health-workbuddy.d.ts +2 -1
- package/pd-cli/dist/commands/health-workbuddy.d.ts.map +1 -1
- package/pd-cli/dist/commands/health-workbuddy.js +17 -8
- package/pd-cli/dist/commands/health-workbuddy.js.map +1 -1
- package/pd-cli/dist/commands/health.d.ts.map +1 -1
- package/pd-cli/dist/commands/health.js +12 -5
- package/pd-cli/dist/commands/health.js.map +1 -1
- package/pd-cli/dist/commands/mcp-probe.d.ts +6 -0
- package/pd-cli/dist/commands/mcp-probe.d.ts.map +1 -1
- package/pd-cli/dist/commands/mcp-probe.js +35 -7
- package/pd-cli/dist/commands/mcp-probe.js.map +1 -1
- package/pd-cli/dist/commands/pain-retry.d.ts.map +1 -1
- package/pd-cli/dist/commands/pain-retry.js +10 -2
- package/pd-cli/dist/commands/pain-retry.js.map +1 -1
- package/pd-cli/dist/commands/trace.d.ts.map +1 -1
- package/pd-cli/dist/commands/trace.js +8 -0
- package/pd-cli/dist/commands/trace.js.map +1 -1
- package/pd-cli/dist/commands/workbuddy-setup.d.ts.map +1 -1
- package/pd-cli/dist/commands/workbuddy-setup.js +7 -3
- package/pd-cli/dist/commands/workbuddy-setup.js.map +1 -1
- package/pd-cli/dist/commands/workbuddy-worker.d.ts.map +1 -1
- package/pd-cli/dist/commands/workbuddy-worker.js +21 -6
- package/pd-cli/dist/commands/workbuddy-worker.js.map +1 -1
- package/pd-cli/dist/services/admission-write-gate.d.ts +10 -1
- package/pd-cli/dist/services/admission-write-gate.d.ts.map +1 -1
- package/pd-cli/dist/services/admission-write-gate.js +12 -2
- package/pd-cli/dist/services/admission-write-gate.js.map +1 -1
- package/pd-cli/dist/services/codex-plugin-install.d.ts +1 -3
- package/pd-cli/dist/services/codex-plugin-install.d.ts.map +1 -1
- package/pd-cli/dist/services/codex-plugin-install.js +10 -3
- package/pd-cli/dist/services/codex-plugin-install.js.map +1 -1
- package/pd-cli/dist/services/pain-flood-simulation-runner.d.ts.map +1 -1
- package/pd-cli/dist/services/pain-flood-simulation-runner.js +2 -0
- package/pd-cli/dist/services/pain-flood-simulation-runner.js.map +1 -1
- package/pd-cli/dist/services/pd-config-loader.d.ts +2 -2
- package/pd-cli/dist/services/pd-config-loader.d.ts.map +1 -1
- package/pd-cli/dist/services/pd-config-loader.js +28 -20
- package/pd-cli/dist/services/pd-config-loader.js.map +1 -1
- package/pd-cli/dist/services/synthetic-baseline-runner.d.ts.map +1 -1
- package/pd-cli/dist/services/synthetic-baseline-runner.js +2 -0
- package/pd-cli/dist/services/synthetic-baseline-runner.js.map +1 -1
- package/pd-cli/package.json +1 -1
- package/pd-mcp-server/dist/log-file.js +9 -2
- package/pd-mcp-server/dist/server.d.ts +52 -2
- package/pd-mcp-server/dist/server.js +40 -4
- package/pd-mcp-server/dist/submit-assembly.js +85 -12
- package/pd-mcp-server/dist/version.d.ts +1 -1
- package/pd-mcp-server/dist/version.js +1 -1
- package/pd-mcp-server/package.json +1 -1
- package/plugin/dist/bundle.js +761 -722
- package/plugin/dist/commands/focus.d.ts +10 -7
- package/plugin/dist/commands/strategy.d.ts +10 -0
- package/plugin/dist/core/focus-history.d.ts +9 -49
- package/plugin/dist/core/paths.d.ts +6 -53
- package/plugin/dist/governance-audit.js +2 -2
- package/plugin/dist/hooks/prompt-helpers.d.ts +6 -5
- package/plugin/dist/hooks/prompt-types.d.ts +6 -6
- package/plugin/dist/openclaw.plugin.json +1 -1
- package/plugin/dist/rulehost-evidence.js +29 -29
- package/plugin/dist/templates/workspace/okr/RECOVERY_PROTOCOL.md +8 -7
- package/plugin/dist/utils/io.d.ts +1 -1
- package/plugin/dist/utils/workspace-resolver.d.ts +0 -20
- package/plugin/mcp/launcher.cjs +159 -35
- package/plugin/openclaw.plugin.json +1 -1
- package/plugin/package.json +1 -1
- package/plugin/templates/workspace/okr/RECOVERY_PROTOCOL.md +8 -7
- package/release-manager/dist/installer.js +596 -100
- package/release-manager/dist/installers/codex-host-installer.js +36 -20
- package/release-manager/dist/installers/index.js +24 -3
- package/release-manager/dist/installers/mcp-registration-conflict.js +23 -16
- package/release-manager/dist/installers/openclaw-host-installer.js +1 -8
- package/release-manager/dist/installers/workbuddy-host-installer.js +7 -7
- package/release-manager/dist/mvp-config.js +49 -16
- package/release-manager/dist/update/release-manager.js +5 -2
- package/release-manager/dist/utils/env.js +91 -34
- package/release-manager/dist/utils/host-workspace-ownership.js +153 -2
- package/release-manager/package.json +2 -2
- package/workbuddy-adapter/dist/index.d.ts +1 -1
- package/workbuddy-adapter/dist/index.js +1 -1
- package/workbuddy-adapter/dist/ingestion/catch-up.js +15 -3
- package/workbuddy-adapter/dist/ingestion/index.d.ts +1 -1
- package/workbuddy-adapter/dist/ingestion/index.js +1 -1
- package/workbuddy-adapter/dist/ingestion/ingestion.d.ts +18 -0
- package/workbuddy-adapter/dist/ingestion/ingestion.js +20 -2
- package/workbuddy-adapter/dist/ingestion/transcript-path.d.ts +13 -4
- package/workbuddy-adapter/dist/ingestion/transcript-path.js +102 -4
- package/workbuddy-adapter/dist/ingestion/transcript-source.js +76 -58
- package/workbuddy-adapter/dist/pd-hook.js +10 -3
- package/workbuddy-adapter/dist/worker/workspace-worker.js +4 -1
- package/workbuddy-adapter/dist/workspace-resolution.d.ts +9 -2
- package/workbuddy-adapter/dist/workspace-resolution.js +19 -3
- package/workbuddy-adapter/package.json +1 -1
- package/workbuddy-adapter/plugin/mcp/launcher.cjs +159 -35
- package/plugin/dist/templates/workspace/okr/CURRENT_FOCUS.md +0 -56
- package/plugin/dist/templates/workspace/okr/TASK_CHANGES.jsonl +0 -6
- package/plugin/dist/templates/workspace/okr/WEEK_TASKS.json +0 -6
- package/plugin/templates/workspace/okr/CURRENT_FOCUS.md +0 -56
- package/plugin/templates/workspace/okr/TASK_CHANGES.jsonl +0 -6
- package/plugin/templates/workspace/okr/WEEK_TASKS.json +0 -6
|
@@ -399,7 +399,17 @@ function applyObservation({ db, rolloutRowId, input, workspaceDir, maxVisibleTex
|
|
|
399
399
|
fill('phase', boundedString(input.phase, MAX_TEXT_BOUND));
|
|
400
400
|
fill('tool_use_id', boundedString(input.toolUseId, MAX_TEXT_BOUND));
|
|
401
401
|
fill('transcript_tool_call_id', boundedString(input.transcriptToolCallId, MAX_TEXT_BOUND));
|
|
402
|
-
|
|
402
|
+
// A terminal retention class (expired / quarantined) must not regain a body
|
|
403
|
+
// through replay enrichment — the same P2-review rule the tool-facts path
|
|
404
|
+
// below already enforces. Without this guard an expired row whose text was
|
|
405
|
+
// NULLed by retention could be refilled by a later catch-up replay of the
|
|
406
|
+
// same logical key, and the turn reader would then serve post-retention
|
|
407
|
+
// text into a diagnosis context.
|
|
408
|
+
const replayRetentionClass = rowField(existing, 'retention_class');
|
|
409
|
+
const replayRowActive = replayRetentionClass === 'operational' || replayRetentionClass === 'promoted';
|
|
410
|
+
if (replayRowActive) {
|
|
411
|
+
fill('visible_text', input.visibleText !== undefined ? boundVisibleText(input.visibleText) : null);
|
|
412
|
+
}
|
|
403
413
|
const incomingFacts = input.toolFacts !== undefined ? safeJson({ facts: sanitizeValue(input.toolFacts, 0, workspaceDir) }) : null;
|
|
404
414
|
// Cross-window tool completion (P1): the call row is partial and the result
|
|
405
415
|
// arrives under the same logical key from a later decode window. Merge the
|
|
@@ -801,6 +811,71 @@ export function listGovernanceUncheckpointedSessions(args) {
|
|
|
801
811
|
close();
|
|
802
812
|
}
|
|
803
813
|
}
|
|
814
|
+
/**
|
|
815
|
+
* PRI-1265: retained turn texts for ONE session, oldest-first — the read side
|
|
816
|
+
* behind the shared TrajectoryTurnReader adapter (CLI diagnose/pain retry,
|
|
817
|
+
* Codex/WorkBuddy workers, host-runtime auto-run). Review-round hardening
|
|
818
|
+
* (2026-11-18):
|
|
819
|
+
* - ONLY `retention_class IN ('operational','promoted')` rows are served —
|
|
820
|
+
* a replay can refill an expired row's body through the enrichment path,
|
|
821
|
+
* so `visible_text IS NOT NULL` alone is not a retention verdict;
|
|
822
|
+
* - the NEWEST `limit` turns are returned (the reported/last turn must not
|
|
823
|
+
* fall off a long session's window just because it is recent);
|
|
824
|
+
* - exact `rollout_identity` rows win over `root_session_id` rows, so a
|
|
825
|
+
* subagent rollout (whose root_session_id points at its parent thread)
|
|
826
|
+
* is never mixed into the parent's own conversation;
|
|
827
|
+
* - an optional `hostKind` keeps verification per-host (session ids are
|
|
828
|
+
* unique per `(host_kind, rollout_identity)`, not globally).
|
|
829
|
+
*/
|
|
830
|
+
export function listGovernanceTurnTexts(input) {
|
|
831
|
+
if (input.sessionId.trim().length === 0)
|
|
832
|
+
return { ok: true, turns: [] };
|
|
833
|
+
const opened = openStore(input.workspaceDir, input.databaseFactory);
|
|
834
|
+
if (!('db' in opened))
|
|
835
|
+
return opened;
|
|
836
|
+
const { db, close } = opened;
|
|
837
|
+
try {
|
|
838
|
+
const limit = Math.min(Math.max(input.limit ?? 200, 1), 2000);
|
|
839
|
+
const newestThenAsc = (identityColumn) => db.prepare('SELECT id, source_ordinal, visible_text, observed_at FROM ('
|
|
840
|
+
+ `SELECT id, source_ordinal, visible_text, observed_at, source_order FROM governance_observations `
|
|
841
|
+
+ `WHERE kind = ? AND ${identityColumn} = ? AND visible_text IS NOT NULL `
|
|
842
|
+
+ `AND retention_class IN ('operational', 'promoted')`
|
|
843
|
+
+ `${input.hostKind !== undefined ? ' AND host_kind = ?' : ''} `
|
|
844
|
+
+ 'ORDER BY observed_at DESC, source_order DESC, id DESC LIMIT ?'
|
|
845
|
+
+ ') ORDER BY observed_at ASC, source_order ASC, id ASC').all(...(input.hostKind !== undefined
|
|
846
|
+
? [input.kind, input.sessionId, input.hostKind, limit]
|
|
847
|
+
: [input.kind, input.sessionId, limit]));
|
|
848
|
+
// Exact session rows first; the root_session_id fallback keeps historical
|
|
849
|
+
// (pre-rollout-identity) rows readable but can no longer drag another
|
|
850
|
+
// rollout's turns (e.g. a subagent's) into this session's context.
|
|
851
|
+
let rows = newestThenAsc('rollout_identity');
|
|
852
|
+
if (rows.length === 0)
|
|
853
|
+
rows = newestThenAsc('root_session_id');
|
|
854
|
+
const turns = [];
|
|
855
|
+
for (const row of rows) {
|
|
856
|
+
const id = Number(rowField(row, 'id'));
|
|
857
|
+
const visibleText = rowField(row, 'visible_text');
|
|
858
|
+
const observedAt = rowField(row, 'observed_at');
|
|
859
|
+
if (!Number.isFinite(id) || typeof visibleText !== 'string' || typeof observedAt !== 'string')
|
|
860
|
+
continue;
|
|
861
|
+
const sourceOrdinal = rowField(row, 'source_ordinal');
|
|
862
|
+
turns.push({
|
|
863
|
+
id,
|
|
864
|
+
sourceOrdinal: typeof sourceOrdinal === 'number' ? sourceOrdinal : turns.length,
|
|
865
|
+
visibleText,
|
|
866
|
+
observedAt,
|
|
867
|
+
});
|
|
868
|
+
}
|
|
869
|
+
return { ok: true, turns };
|
|
870
|
+
}
|
|
871
|
+
catch (error) {
|
|
872
|
+
const detail = error instanceof Error ? error.message.slice(0, 200) : String(error).slice(0, 200);
|
|
873
|
+
return { ok: false, reason: `governance_turn_texts_failed:${detail}`, nextAction: 'Inspect the workspace trajectory.db; the diagnosis context window degraded to no trajectory fallback.' };
|
|
874
|
+
}
|
|
875
|
+
finally {
|
|
876
|
+
close();
|
|
877
|
+
}
|
|
878
|
+
}
|
|
804
879
|
export function listGovernanceObservations(input) {
|
|
805
880
|
const opened = openStore(input.workspaceDir, input.databaseFactory);
|
|
806
881
|
if (!('db' in opened))
|
|
@@ -813,6 +888,14 @@ export function listGovernanceObservations(input) {
|
|
|
813
888
|
conditions.push('rollout_identity = ?');
|
|
814
889
|
values.push(input.rolloutIdentity);
|
|
815
890
|
}
|
|
891
|
+
if (input.hostKind !== undefined) {
|
|
892
|
+
conditions.push('host_kind = ?');
|
|
893
|
+
values.push(input.hostKind);
|
|
894
|
+
}
|
|
895
|
+
if (input.hostTurnId !== undefined) {
|
|
896
|
+
conditions.push('host_turn_id = ?');
|
|
897
|
+
values.push(input.hostTurnId);
|
|
898
|
+
}
|
|
816
899
|
if (input.retentionClass !== undefined) {
|
|
817
900
|
conditions.push('retention_class = ?');
|
|
818
901
|
values.push(input.retentionClass);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PRI-1265: a TrajectoryTurnReader over the workspace's governance observation
|
|
3
|
+
* store (trajectory.db) — the SAME authorized store conversation ingestion
|
|
4
|
+
* writes. OpenClaw's hook passes its own TrajectoryDatabase adapter; Codex /
|
|
5
|
+
* WorkBuddy workers and the pd-cli diagnosis entries had NO reader at all, so
|
|
6
|
+
* a bound session with stored turns still produced a context window without
|
|
7
|
+
* the original text. This adapter closes that gap with one implementation the
|
|
8
|
+
* CLI (`pd diagnose run`, `pd pain retry`), the Codex/WorkBuddy workers and
|
|
9
|
+
* the host-runtime auto-run all inject.
|
|
10
|
+
*
|
|
11
|
+
* Read semantics (fail-open to [] — the assembler records the empty fallback
|
|
12
|
+
* as an ambiguity note, rc-9):
|
|
13
|
+
* - user turns: `kind='user_turn'` rows with retained `visible_text`;
|
|
14
|
+
* - assistant turns: `kind='assistant_turn'` rows with retained text;
|
|
15
|
+
* - a session matches by `root_session_id` OR `rollout_identity` (Codex
|
|
16
|
+
* rollout uuid / WorkBuddy sessionId), so either spelling of the same
|
|
17
|
+
* session resolves;
|
|
18
|
+
* - expired/quarantined rows are excluded naturally: retention NULLed their
|
|
19
|
+
* text at write time (PRI-1179), so nothing new is re-derived here.
|
|
20
|
+
*/
|
|
21
|
+
import type { TrajectoryTurnReader } from '@principles/core/runtime';
|
|
22
|
+
/**
|
|
23
|
+
* Build the governance-observation-backed turn reader for a workspace. The
|
|
24
|
+
* returned object is cheap to construct per invocation; each list call opens
|
|
25
|
+
* the store read (no cached handle across worker cycles, so a replaced
|
|
26
|
+
* database mid-run can never serve stale turns).
|
|
27
|
+
*/
|
|
28
|
+
export declare function createGovernanceTrajectoryTurnReader(args: {
|
|
29
|
+
readonly workspaceDir: string;
|
|
30
|
+
}): TrajectoryTurnReader;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { listGovernanceTurnTexts } from './governance-observation-store.js';
|
|
2
|
+
/** Bound on turns per list call — the assembler bounds the window again. */
|
|
3
|
+
const MAX_TURNS_PER_SESSION = 200;
|
|
4
|
+
function readTurnRows(workspaceDir, kind, sessionId) {
|
|
5
|
+
if (sessionId.trim().length === 0)
|
|
6
|
+
return [];
|
|
7
|
+
const result = listGovernanceTurnTexts({
|
|
8
|
+
workspaceDir,
|
|
9
|
+
kind,
|
|
10
|
+
sessionId,
|
|
11
|
+
limit: MAX_TURNS_PER_SESSION,
|
|
12
|
+
});
|
|
13
|
+
// Unreadable store: the empty result surfaces as an assembler ambiguity
|
|
14
|
+
// note ("no turns found"), never as a fabricated window.
|
|
15
|
+
return result.ok ? result.turns : [];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Build the governance-observation-backed turn reader for a workspace. The
|
|
19
|
+
* returned object is cheap to construct per invocation; each list call opens
|
|
20
|
+
* the store read (no cached handle across worker cycles, so a replaced
|
|
21
|
+
* database mid-run can never serve stale turns).
|
|
22
|
+
*/
|
|
23
|
+
export function createGovernanceTrajectoryTurnReader(args) {
|
|
24
|
+
return {
|
|
25
|
+
listUserTurnsForSession(sessionId) {
|
|
26
|
+
return readTurnRows(args.workspaceDir, 'user_turn', sessionId).map((row, index) => ({
|
|
27
|
+
id: row.id,
|
|
28
|
+
turnIndex: row.sourceOrdinal >= 0 ? row.sourceOrdinal : index,
|
|
29
|
+
rawExcerpt: row.visibleText,
|
|
30
|
+
correctionDetected: false,
|
|
31
|
+
correctionCue: null,
|
|
32
|
+
createdAt: row.observedAt,
|
|
33
|
+
}));
|
|
34
|
+
},
|
|
35
|
+
listAssistantTurns(sessionId) {
|
|
36
|
+
return readTurnRows(args.workspaceDir, 'assistant_turn', sessionId).map((row) => ({
|
|
37
|
+
id: row.id,
|
|
38
|
+
sessionId,
|
|
39
|
+
runId: '',
|
|
40
|
+
provider: '',
|
|
41
|
+
model: '',
|
|
42
|
+
sanitizedText: row.visibleText,
|
|
43
|
+
createdAt: row.observedAt,
|
|
44
|
+
}));
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -14,10 +14,12 @@ export * from './prompt-injection-event-evidence.js';
|
|
|
14
14
|
export * from './prompt-injection-budget-observation.js';
|
|
15
15
|
export * from './rulecode-event-collection.js';
|
|
16
16
|
export * from './pd-config.js';
|
|
17
|
+
export { resolvePdHome } from '@principles/install-layout';
|
|
17
18
|
export * from './production-rulehost-gate.js';
|
|
18
19
|
export * from './rule-implementation-runtime.js';
|
|
19
20
|
export * from './production-pain-evidence.js';
|
|
20
21
|
export * from './governance-observation-store.js';
|
|
22
|
+
export * from './governance-trajectory-turn-reader.js';
|
|
21
23
|
export * from './trajectory-retention.js';
|
|
22
24
|
export * from './conversation-ingestion/index.js';
|
|
23
25
|
export * from './governance-signal-admission.js';
|
|
@@ -25,10 +25,16 @@ export * from './prompt-injection-budget-observation.js';
|
|
|
25
25
|
// review and the Console Owner review (5B deduplication).
|
|
26
26
|
export * from './rulecode-event-collection.js';
|
|
27
27
|
export * from './pd-config.js';
|
|
28
|
+
// PD Home path authority is surfaced through host-runtime so host plugins do
|
|
29
|
+
// not need a second dependency or a private home-directory resolver.
|
|
30
|
+
export { resolvePdHome } from '@principles/install-layout';
|
|
28
31
|
export * from './production-rulehost-gate.js';
|
|
29
32
|
export * from './rule-implementation-runtime.js';
|
|
30
33
|
export * from './production-pain-evidence.js';
|
|
31
34
|
export * from './governance-observation-store.js';
|
|
35
|
+
// PRI-1265: the governance-observation-backed TrajectoryTurnReader injected by
|
|
36
|
+
// pd-cli diagnose/pain retry and the Codex/WorkBuddy workers.
|
|
37
|
+
export * from './governance-trajectory-turn-reader.js';
|
|
32
38
|
// SPEC-PD-TR-001: trajectory retention I/O boundary (lock + marker + export
|
|
33
39
|
// list + explicit VACUUM). The policy/batch engine is pure and lives in
|
|
34
40
|
// `@principles/core/runtime`.
|
|
@@ -17,11 +17,10 @@
|
|
|
17
17
|
* suppresses another workspace on the same installation.
|
|
18
18
|
*/
|
|
19
19
|
import fs from 'node:fs';
|
|
20
|
-
import os from 'node:os';
|
|
21
20
|
import path from 'node:path';
|
|
22
21
|
import { fileURLToPath } from 'node:url';
|
|
23
22
|
import { bucketDateFromTime, buildProductTelemetrySnapshot, deriveDailyTelemetryId, isValidTelemetrySecretHex, } from '@principles/core/runtime';
|
|
24
|
-
import {
|
|
23
|
+
import { getInstallLayoutPathsFromPdHome, parseInstallManifest, resolveInstallLayout, resolvePdHome } from '@principles/install-layout';
|
|
25
24
|
import { loadFeatureFlagFromConfig, loadPdConfigForPlugin } from '../pd-config.js';
|
|
26
25
|
import { deniedControlState, defaultProductTelemetryControlState, getProductTelemetryStatePath, grantedControlState, pruneWorkspaceExports, readProductTelemetryControlState, resetControlState, withControlStateLock, } from './consent-store.js';
|
|
27
26
|
import { releaseExclusiveLock, tryAcquireExclusiveLockSync } from './control-state-lock.js';
|
|
@@ -96,13 +95,19 @@ function readJsonFile(filePath) {
|
|
|
96
95
|
return undefined;
|
|
97
96
|
}
|
|
98
97
|
}
|
|
99
|
-
function resolveInstallContext(
|
|
100
|
-
const paths =
|
|
98
|
+
function resolveInstallContext(homePaths) {
|
|
99
|
+
const paths = getInstallLayoutPathsFromPdHome(homePaths);
|
|
101
100
|
const manifestParsed = parseInstallManifest(readJsonFile(paths.manifest));
|
|
102
101
|
const manifest = manifestParsed.manifest;
|
|
103
102
|
const canonicalRuntimeExists = fs.existsSync(paths.hostRuntimeDir);
|
|
104
103
|
const legacyExtensionExists = fs.existsSync(paths.openClawExtensionDir);
|
|
105
|
-
const layout = resolveInstallLayout({
|
|
104
|
+
const layout = resolveInstallLayout({
|
|
105
|
+
homeDir: homePaths.homeDir,
|
|
106
|
+
homePaths,
|
|
107
|
+
manifest,
|
|
108
|
+
canonicalRuntimeExists,
|
|
109
|
+
legacyExtensionExists,
|
|
110
|
+
});
|
|
106
111
|
let hostKind = 'other';
|
|
107
112
|
if (manifest && manifest.hosts.length === 1 && (manifest.hosts[0] === 'codex' || manifest.hosts[0] === 'openclaw' || manifest.hosts[0] === 'workbuddy')) {
|
|
108
113
|
[hostKind] = manifest.hosts;
|
|
@@ -125,25 +130,69 @@ function workspaceEnvironmentOf(workspaceDir) {
|
|
|
125
130
|
return environment ?? 'unknown';
|
|
126
131
|
}
|
|
127
132
|
export function createProductTelemetryService(deps = {}) {
|
|
128
|
-
|
|
129
|
-
|
|
133
|
+
// §6: ONE environment snapshot, fixed at service creation. The suppression
|
|
134
|
+
// gate below and the PD Home resolution MUST read the SAME env — gating on
|
|
135
|
+
// deps.env while resolving PD Home from process.env would let an experiment
|
|
136
|
+
// instance write production consent state (review N3J).
|
|
137
|
+
const resolvedEnv = deps.env ?? process.env;
|
|
138
|
+
// Telemetry control state (consent ledger, export lock) is an Owner
|
|
139
|
+
// governance fact living under the PD Home. The default follows the shared
|
|
140
|
+
// resolution (fed with the SAME snapshot) so an experiment console keeps its
|
|
141
|
+
// state inside the lab; a refused resolution fails loud instead of silently
|
|
142
|
+
// writing production state.
|
|
143
|
+
//
|
|
144
|
+
// ONE resolution, memoized for the service lifetime (§6: no re-parse, no
|
|
145
|
+
// env drift mid-life): feeding the experiment root back into a second
|
|
146
|
+
// getInstallLayoutPaths parse re-derives "production home" from it and the
|
|
147
|
+
// disjointness check then refuses the lab against its own .pd. The
|
|
148
|
+
// already-validated PdHomePaths is passed down instead
|
|
149
|
+
// (getInstallLayoutPathsFromPdHome / resolveInstallLayout({ homePaths })).
|
|
150
|
+
let cachedHomeResolution;
|
|
151
|
+
const homeResolution = () => {
|
|
152
|
+
if (cachedHomeResolution === undefined) {
|
|
153
|
+
cachedHomeResolution = deps.homeDir !== undefined
|
|
154
|
+
? resolvePdHome({ env: resolvedEnv, homeDir: path.resolve(deps.homeDir) })
|
|
155
|
+
: resolvePdHome({ env: resolvedEnv });
|
|
156
|
+
}
|
|
157
|
+
return cachedHomeResolution;
|
|
158
|
+
};
|
|
159
|
+
const homeDir = () => {
|
|
160
|
+
const resolution = homeResolution();
|
|
161
|
+
if (!resolution.ok) {
|
|
162
|
+
throw new Error(`PD home resolution refused (${resolution.reason}): ${resolution.message} Next action: ${resolution.nextAction}`);
|
|
163
|
+
}
|
|
164
|
+
return path.resolve(resolution.homeDir);
|
|
165
|
+
};
|
|
166
|
+
/** Null-safe form for never-throw callers (maybeExportDaily, getStatus). */
|
|
167
|
+
const homePathsOrNull = () => {
|
|
168
|
+
const resolution = homeResolution();
|
|
169
|
+
return resolution.ok ? resolution : null;
|
|
170
|
+
};
|
|
171
|
+
/** Validated paths for layout consumers — reuses the ONE resolution (no re-parse). */
|
|
172
|
+
const requireHomePaths = () => {
|
|
173
|
+
const resolution = homeResolution();
|
|
174
|
+
if (!resolution.ok) {
|
|
175
|
+
throw new Error(`PD home resolution refused (${resolution.reason}): ${resolution.message} Next action: ${resolution.nextAction}`);
|
|
176
|
+
}
|
|
177
|
+
return resolution;
|
|
178
|
+
};
|
|
130
179
|
const moduleDir = () => path.resolve(deps.moduleDir ?? DEFAULT_MODULE_DIR);
|
|
131
180
|
const now = () => (deps.now ?? Date.now)();
|
|
132
181
|
const logger = deps.logger ?? {};
|
|
133
|
-
function environmentResult(workspaceDir) {
|
|
182
|
+
function environmentResult(workspaceDir, homePaths) {
|
|
134
183
|
return computeTelemetryEnvironment({
|
|
135
184
|
env: {
|
|
136
|
-
killSwitch:
|
|
137
|
-
ci:
|
|
138
|
-
vitest:
|
|
139
|
-
e2eMode:
|
|
185
|
+
killSwitch: resolvedEnv[PD_TELEMETRY_DISABLED_ENV],
|
|
186
|
+
ci: resolvedEnv.CI,
|
|
187
|
+
vitest: resolvedEnv.VITEST,
|
|
188
|
+
e2eMode: resolvedEnv.PD_E2E_MODE,
|
|
140
189
|
},
|
|
141
190
|
workspaceEnvironment: workspaceEnvironmentOf(workspaceDir),
|
|
142
|
-
installMode: resolveInstallContext(
|
|
191
|
+
installMode: resolveInstallContext(homePaths).installMode,
|
|
143
192
|
moduleDir: moduleDir(),
|
|
144
193
|
});
|
|
145
194
|
}
|
|
146
|
-
function gatesFor(state, workspaceDir) {
|
|
195
|
+
function gatesFor(state, workspaceDir, homePaths) {
|
|
147
196
|
let flagEnabled = null;
|
|
148
197
|
let flagSource = null;
|
|
149
198
|
if (workspaceDir) {
|
|
@@ -151,7 +200,7 @@ export function createProductTelemetryService(deps = {}) {
|
|
|
151
200
|
flagEnabled = flag.enabled;
|
|
152
201
|
flagSource = flag.source;
|
|
153
202
|
}
|
|
154
|
-
const environment = environmentResult(workspaceDir);
|
|
203
|
+
const environment = environmentResult(workspaceDir, homePaths);
|
|
155
204
|
const blockers = [];
|
|
156
205
|
if (flagEnabled === null)
|
|
157
206
|
blockers.push('feature_flag_unresolved');
|
|
@@ -186,10 +235,19 @@ export function createProductTelemetryService(deps = {}) {
|
|
|
186
235
|
return {
|
|
187
236
|
/** Status for `pd telemetry status`. Never exposes the secret. */
|
|
188
237
|
getStatus(workspaceDir) {
|
|
238
|
+
const homePaths = homePathsOrNull();
|
|
239
|
+
if (homePaths === null) {
|
|
240
|
+
const refused = homeResolution();
|
|
241
|
+
return {
|
|
242
|
+
ok: false,
|
|
243
|
+
reason: `pd_home_unresolved:${refused.ok === false ? refused.reason : 'unknown'}`,
|
|
244
|
+
nextAction: refused.ok ? 'Resolve the PD home environment and re-run.' : `${refused.message} Next action: ${refused.nextAction}`,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
189
247
|
const read = readProductTelemetryControlState(homeDir());
|
|
190
248
|
if (!read.ok)
|
|
191
249
|
return read;
|
|
192
|
-
const gates = gatesFor(read.state, workspaceDir);
|
|
250
|
+
const gates = gatesFor(read.state, workspaceDir, homePaths);
|
|
193
251
|
// Export bookkeeping is workspace-scoped: show this workspace's entry
|
|
194
252
|
// (when a workspace was given and its scope can be derived).
|
|
195
253
|
let workspaceEntry;
|
|
@@ -215,7 +273,7 @@ export function createProductTelemetryService(deps = {}) {
|
|
|
215
273
|
preview(workspaceDir) {
|
|
216
274
|
const read = readProductTelemetryControlState(homeDir());
|
|
217
275
|
const state = read.ok ? read.state : defaultProductTelemetryControlState();
|
|
218
|
-
const gates = gatesFor(state, workspaceDir);
|
|
276
|
+
const gates = gatesFor(state, workspaceDir, requireHomePaths());
|
|
219
277
|
const timestamp = now();
|
|
220
278
|
const bucketDate = bucketDateFromTime(timestamp);
|
|
221
279
|
const secretEphemeral = !isValidTelemetrySecretHex(state.telemetrySecret);
|
|
@@ -224,7 +282,7 @@ export function createProductTelemetryService(deps = {}) {
|
|
|
224
282
|
// the ID would differ after enable.
|
|
225
283
|
const secret = state.telemetrySecret ?? '0'.repeat(64);
|
|
226
284
|
const scopeKey = workspaceScopeIdFor(secret, workspaceDir);
|
|
227
|
-
const install = resolveInstallContext(
|
|
285
|
+
const install = resolveInstallContext(requireHomePaths());
|
|
228
286
|
const { facts, notes } = readMilestoneFacts(workspaceDir);
|
|
229
287
|
const snapshot = buildProductTelemetrySnapshot({
|
|
230
288
|
dailyTelemetryId: deriveDailyTelemetryId(secret, scopeKey, bucketDate),
|
|
@@ -324,13 +382,21 @@ export function createProductTelemetryService(deps = {}) {
|
|
|
324
382
|
* EXPORT_LOCK_STALE_MS.
|
|
325
383
|
*/
|
|
326
384
|
async maybeExportDaily(workspaceDir) {
|
|
385
|
+
// §6 never-throws contract: a refused PD Home is a STRUCTURED skip, not
|
|
386
|
+
// a throw — and never a fallback to the production home.
|
|
387
|
+
const homePaths = homePathsOrNull();
|
|
388
|
+
if (homePaths === null) {
|
|
389
|
+
const refused = homeResolution();
|
|
390
|
+
logger.warn?.(`[PD:Telemetry] Export skipped: PD home resolution refused (${refused.ok === false ? refused.reason : 'unknown'}).`);
|
|
391
|
+
return { attempted: false, skipReason: `pd_home_unresolved:${refused.ok === false ? refused.reason : 'unknown'}` };
|
|
392
|
+
}
|
|
327
393
|
const read = readProductTelemetryControlState(homeDir());
|
|
328
394
|
if (!read.ok) {
|
|
329
395
|
logger.warn?.(`[PD:Telemetry] Export skipped: ${read.reason}`);
|
|
330
396
|
return { attempted: false, skipReason: 'control_state_unreadable' };
|
|
331
397
|
}
|
|
332
398
|
const { state } = read;
|
|
333
|
-
const gates = gatesFor(state, workspaceDir);
|
|
399
|
+
const gates = gatesFor(state, workspaceDir, homePaths);
|
|
334
400
|
if (!gates.flagEnabled)
|
|
335
401
|
return { attempted: false, skipReason: 'feature_flag_disabled' };
|
|
336
402
|
if (state.consent !== 'granted')
|
|
@@ -383,7 +449,7 @@ export function createProductTelemetryService(deps = {}) {
|
|
|
383
449
|
return { attempted: false, skipReason: 'already_succeeded_today' };
|
|
384
450
|
}
|
|
385
451
|
}
|
|
386
|
-
const install = resolveInstallContext(
|
|
452
|
+
const install = resolveInstallContext(requireHomePaths());
|
|
387
453
|
const { facts } = readMilestoneFacts(workspaceDir);
|
|
388
454
|
const snapshot = buildProductTelemetrySnapshot({
|
|
389
455
|
dailyTelemetryId: deriveDailyTelemetryId(secret, scopeKey, bucketDate),
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type PdHomePaths, type ResolvePdHomeOptions } from './pd-home.js';
|
|
1
2
|
export declare const INSTALL_LAYOUT_VERSION: 1;
|
|
2
3
|
export declare const INSTALL_LAYOUT_MODES: readonly ['canonical', 'legacy'];
|
|
3
4
|
export type InstallLayoutMode = (typeof INSTALL_LAYOUT_MODES)[number];
|
|
@@ -91,7 +92,10 @@ export interface LayoutResolution {
|
|
|
91
92
|
warnings?: readonly InstallManifestWarning[];
|
|
92
93
|
}
|
|
93
94
|
export interface ResolveInstallLayoutOptions {
|
|
95
|
+
/** Real OS home; ignored when a pre-resolved PD Home is supplied. */
|
|
94
96
|
homeDir: string;
|
|
97
|
+
/** Reuse the already-validated PD Home without resolving an experiment root twice. */
|
|
98
|
+
homePaths?: PdHomePaths;
|
|
95
99
|
manifest?: unknown;
|
|
96
100
|
canonicalRuntimeExists: boolean;
|
|
97
101
|
legacyExtensionExists: boolean;
|
|
@@ -118,7 +122,14 @@ export declare function parseInstallManifest(value: unknown, platform?: string):
|
|
|
118
122
|
warnings?: readonly InstallManifestWarning[];
|
|
119
123
|
error?: string;
|
|
120
124
|
};
|
|
121
|
-
|
|
125
|
+
/** Build install paths from an already-resolved PD Home (e.g. Console request scope). */
|
|
126
|
+
export declare function getInstallLayoutPathsFromPdHome(homePaths: PdHomePaths): InstallLayoutPaths;
|
|
127
|
+
/**
|
|
128
|
+
* Every install path derives from the same PD Home resolution. In particular,
|
|
129
|
+
* OpenClaw's extension directory follows OPENCLAW_STATE_DIR > OPENCLAW_HOME,
|
|
130
|
+
* while the shared runtime remains host-neutral under <PD_HOME>/.pd/runtime.
|
|
131
|
+
*/
|
|
132
|
+
export declare function getInstallLayoutPaths(homeDir: string, env?: ResolvePdHomeOptions['env']): InstallLayoutPaths;
|
|
122
133
|
/**
|
|
123
134
|
* Canonical installed MCP server entry for the shared runtime layout
|
|
124
135
|
* (~/.pd/runtime/pd-mcp-server/dist/index.js). Launchers, binding writers and
|
|
@@ -135,7 +146,7 @@ export declare function getMcpServerEntry(paths: InstallLayoutPaths): string;
|
|
|
135
146
|
* explicit setup flow — its absence means "not initialized", never a silent
|
|
136
147
|
* fallback to another host's database.
|
|
137
148
|
*/
|
|
138
|
-
export declare function getWorkbuddyWorkspaceDir(homeDir: string): string;
|
|
149
|
+
export declare function getWorkbuddyWorkspaceDir(homeDir: string, configDirOverride?: string, env?: ResolvePdHomeOptions['env']): string;
|
|
139
150
|
/**
|
|
140
151
|
* The ONE registration/enablement state definition shared by the installer
|
|
141
152
|
* (install summary + `status`) and pd-cli (`pd health --host workbuddy`).
|
|
@@ -162,6 +173,8 @@ export interface WorkbuddyHostConfigPaths {
|
|
|
162
173
|
readonly settingsPath: string;
|
|
163
174
|
readonly registryPath: string;
|
|
164
175
|
}
|
|
176
|
+
/** Build WorkBuddy host config paths from an already-validated PD Home. */
|
|
177
|
+
export declare function getWorkbuddyHostConfigPathsFromPdHome(homePaths: PdHomePaths): WorkbuddyHostConfigPaths;
|
|
165
178
|
/**
|
|
166
179
|
* Resolve the WorkBuddy HOST config paths from one authority. The frozen
|
|
167
180
|
* governance dir (~/.workbuddy/pd-workspace) defines the config root;
|
|
@@ -170,7 +183,7 @@ export interface WorkbuddyHostConfigPaths {
|
|
|
170
183
|
* so installer / status / health can never disagree about where the host
|
|
171
184
|
* files live.
|
|
172
185
|
*/
|
|
173
|
-
export declare function getWorkbuddyHostConfigPaths(homeDir: string, configDirOverride?: string): WorkbuddyHostConfigPaths;
|
|
186
|
+
export declare function getWorkbuddyHostConfigPaths(homeDir: string, configDirOverride?: string, env?: ResolvePdHomeOptions['env']): WorkbuddyHostConfigPaths;
|
|
174
187
|
/**
|
|
175
188
|
* The shared plugin-state judgment (rc-2: no `as` bypass; rc-4/5). The exact
|
|
176
189
|
* semantics the installer has applied since PR #2355, extracted so pd-cli
|
|
@@ -190,12 +203,13 @@ export declare function getConsoleServerEntry(paths: InstallLayoutPaths, mode: I
|
|
|
190
203
|
export declare function getConsoleWebIndex(paths: InstallLayoutPaths, mode: InstallLayoutMode): string;
|
|
191
204
|
export declare function getPdCliEntry(paths: InstallLayoutPaths, mode: InstallLayoutMode): string;
|
|
192
205
|
/**
|
|
193
|
-
* PD home resolution (PRI-872): production keeps the historical
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
206
|
+
* PD home resolution (PRI-872): production keeps the historical home
|
|
207
|
+
* precedence (explicit `HOME` first, then `os.homedir()`);
|
|
208
|
+
* `PD_EXPERIMENT_ROOT` opts into a fail-closed isolated root. This is the ONE
|
|
209
|
+
* authority for "which PD home does this process own" — components must not
|
|
210
|
+
* re-derive it locally.
|
|
197
211
|
*/
|
|
198
|
-
export { PD_EXPERIMENT_ROOT_ENV, PD_OPENCLAW_HOME_ENV, PD_OPENCLAW_STATE_DIR_ENV, PD_HOME_MODES, PD_HOME_FAILURE_REASONS, resolvePdHome, isPathWithinRoot, type PdHomeMode, type PdHomePaths, type PdHomeFailure, type PdHomeFailureReason, type PdHomeSuccess, type PdHomeResolution, type ResolvePdHomeOptions, } from './pd-home.js';
|
|
212
|
+
export { PD_EXPERIMENT_ROOT_ENV, PD_OPENCLAW_HOME_ENV, PD_OPENCLAW_STATE_DIR_ENV, PD_CODEX_HOME_ENV, PD_WORKBUDDY_CONFIG_DIR_ENV, PD_HOST_WORKSPACE_DIR_NAME, PD_HOME_MODES, PD_HOME_FAILURE_REASONS, resolvePdHome, isPathWithinRoot, type PdHomeMode, type PdHomePaths, type PdHomeFailure, type PdHomeFailureReason, type PdHomeSuccess, type PdHomeResolution, type ResolvePdHomeOptions, } from './pd-home.js';
|
|
199
213
|
/**
|
|
200
214
|
* Codex host-persistent binding location. The versioned payload directory is
|
|
201
215
|
* REPLACED by a host cache refresh, taking any binding written inside it with
|
|
@@ -225,4 +239,4 @@ export declare function selectCodexMcpBindingPath(codexHome: string, pluginRoot:
|
|
|
225
239
|
* against it by the parity test, and the installer / `pd health` import it
|
|
226
240
|
* directly so neither can drift into a more permissive check.
|
|
227
241
|
*/
|
|
228
|
-
export { MCP_BINDING_SCHEMA_VERSION, MCP_BINDING_HOSTS, MCP_BINDING_SERVER_ENTRY_SEGMENTS, MCP_BINDING_SHAPE_CODES, MCP_BINDING_LAUNCHER_ONLY_REASONS, MCP_BINDING_FIXTURES, getCanonicalMcpServerEntry, getHostDefaultWorkspaceDirs, findForeignWorkspaceHost, isSameMcpBindingPath, validateMcpBinding, buildMcpBindingFixture, isMcpBindingHost, isSupportedBindingSchemaVersion, isSemverVersion, type McpBindingHost, type McpHostWorkspaceOptions, type McpBindingRecord, type McpBindingVerdict, type McpBindingShapeCode, type McpBindingFixture, type McpBindingFixtureId, type McpBindingFixtureContext, } from './mcp-binding-contract.js';
|
|
242
|
+
export { MCP_BINDING_SCHEMA_VERSION, MCP_BINDING_HOSTS, MCP_BINDING_SERVER_ENTRY_SEGMENTS, MCP_BINDING_SHAPE_CODES, MCP_BINDING_LAUNCHER_ONLY_REASONS, MCP_BINDING_FIXTURES, getCanonicalMcpServerEntry, getHostDefaultWorkspaceDirs, findForeignWorkspaceHost, collectHostWorkspaceClaims, findForeignWorkspaceOwner, isSameMcpBindingPath, validateMcpBinding, buildMcpBindingFixture, isMcpBindingHost, isSupportedBindingSchemaVersion, isSemverVersion, type McpBindingHost, type McpHostWorkspaceOptions, type McpBindingRecord, type McpBindingVerdict, type McpBindingShapeCode, type McpBindingFixture, type McpBindingFixtureId, type McpBindingFixtureContext, type HostWorkspaceClaim, type HostWorkspaceClaimVia, type HostClaimReaders, type HostClaimOptions, type ForeignWorkspaceOwnerVerdict, } from './mcp-binding-contract.js';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as fs from 'node:fs';
|
|
2
2
|
import * as path from 'node:path';
|
|
3
|
+
import { resolvePdHome } from './pd-home.js';
|
|
3
4
|
export const INSTALL_LAYOUT_VERSION = 1;
|
|
4
5
|
export const INSTALL_LAYOUT_MODES = ['canonical', 'legacy'];
|
|
5
6
|
export const INSTALL_HOSTS = ['codex', 'openclaw', 'workbuddy'];
|
|
@@ -128,11 +129,16 @@ export function parseInstallManifest(value, platform = process.platform) {
|
|
|
128
129
|
...(warnings.length > 0 ? { warnings } : {}),
|
|
129
130
|
};
|
|
130
131
|
}
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
132
|
+
function requirePdHome(options) {
|
|
133
|
+
const resolution = resolvePdHome(options);
|
|
134
|
+
if (!resolution.ok) {
|
|
135
|
+
throw new Error(`PD home resolution refused (${resolution.reason}): ${resolution.message} Next action: ${resolution.nextAction}`);
|
|
136
|
+
}
|
|
137
|
+
return resolution;
|
|
138
|
+
}
|
|
139
|
+
/** Build install paths from an already-resolved PD Home (e.g. Console request scope). */
|
|
140
|
+
export function getInstallLayoutPathsFromPdHome(homePaths) {
|
|
141
|
+
const { homeDir: home, pdHome: pdDir, runtimeDir, openclawHome: openClawDir, openclawExtensionDir, } = homePaths;
|
|
136
142
|
return {
|
|
137
143
|
homeDir: home,
|
|
138
144
|
pdDir,
|
|
@@ -147,13 +153,21 @@ export function getInstallLayoutPaths(homeDir) {
|
|
|
147
153
|
binDir: path.join(runtimeDir, 'bin'),
|
|
148
154
|
codexDir: path.join(pdDir, 'codex'),
|
|
149
155
|
openClawDir,
|
|
150
|
-
openClawExtensionDir:
|
|
156
|
+
openClawExtensionDir: openclawExtensionDir,
|
|
151
157
|
releaseManagerDir: path.join(runtimeDir, 'release-manager'),
|
|
152
158
|
codexAdapterDir: path.join(runtimeDir, 'codex-adapter'),
|
|
153
159
|
workbuddyAdapterDir: path.join(runtimeDir, 'workbuddy-adapter'),
|
|
154
160
|
mcpServerDir: path.join(runtimeDir, 'pd-mcp-server'),
|
|
155
161
|
};
|
|
156
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* Every install path derives from the same PD Home resolution. In particular,
|
|
165
|
+
* OpenClaw's extension directory follows OPENCLAW_STATE_DIR > OPENCLAW_HOME,
|
|
166
|
+
* while the shared runtime remains host-neutral under <PD_HOME>/.pd/runtime.
|
|
167
|
+
*/
|
|
168
|
+
export function getInstallLayoutPaths(homeDir, env = process.env) {
|
|
169
|
+
return getInstallLayoutPathsFromPdHome(requirePdHome({ homeDir, env }));
|
|
170
|
+
}
|
|
157
171
|
/**
|
|
158
172
|
* Canonical installed MCP server entry for the shared runtime layout
|
|
159
173
|
* (~/.pd/runtime/pd-mcp-server/dist/index.js). Launchers, binding writers and
|
|
@@ -172,8 +186,11 @@ export function getMcpServerEntry(paths) {
|
|
|
172
186
|
* explicit setup flow — its absence means "not initialized", never a silent
|
|
173
187
|
* fallback to another host's database.
|
|
174
188
|
*/
|
|
175
|
-
export function getWorkbuddyWorkspaceDir(homeDir) {
|
|
176
|
-
|
|
189
|
+
export function getWorkbuddyWorkspaceDir(homeDir, configDirOverride, env = process.env) {
|
|
190
|
+
const effectiveEnv = configDirOverride !== undefined
|
|
191
|
+
? { ...env, WORKBUDDY_CONFIG_DIR: configDirOverride }
|
|
192
|
+
: env;
|
|
193
|
+
return requirePdHome({ homeDir, env: effectiveEnv }).workbuddyWorkspaceDir;
|
|
177
194
|
}
|
|
178
195
|
// ─── WorkBuddy host state (2026-11-07, read-only state contract) ────────────
|
|
179
196
|
/**
|
|
@@ -188,6 +205,15 @@ export const WORKBUDDY_PLUGIN_NAME = 'principles-disciple';
|
|
|
188
205
|
export const WORKBUDDY_MARKETPLACE_NAME = 'principles-disciple-market';
|
|
189
206
|
/** Registry/settings key: "principles-disciple@principles-disciple-market". */
|
|
190
207
|
export const WORKBUDDY_PLUGIN_KEY = `${WORKBUDDY_PLUGIN_NAME}@${WORKBUDDY_MARKETPLACE_NAME}`;
|
|
208
|
+
/** Build WorkBuddy host config paths from an already-validated PD Home. */
|
|
209
|
+
export function getWorkbuddyHostConfigPathsFromPdHome(homePaths) {
|
|
210
|
+
const configDir = homePaths.workbuddyConfigDir;
|
|
211
|
+
return {
|
|
212
|
+
configDir,
|
|
213
|
+
settingsPath: path.join(configDir, 'settings.json'),
|
|
214
|
+
registryPath: path.join(configDir, 'plugins', 'installed_plugins.json'),
|
|
215
|
+
};
|
|
216
|
+
}
|
|
191
217
|
/**
|
|
192
218
|
* Resolve the WorkBuddy HOST config paths from one authority. The frozen
|
|
193
219
|
* governance dir (~/.workbuddy/pd-workspace) defines the config root;
|
|
@@ -196,15 +222,11 @@ export const WORKBUDDY_PLUGIN_KEY = `${WORKBUDDY_PLUGIN_NAME}@${WORKBUDDY_MARKET
|
|
|
196
222
|
* so installer / status / health can never disagree about where the host
|
|
197
223
|
* files live.
|
|
198
224
|
*/
|
|
199
|
-
export function getWorkbuddyHostConfigPaths(homeDir, configDirOverride) {
|
|
200
|
-
const
|
|
201
|
-
?
|
|
202
|
-
:
|
|
203
|
-
return {
|
|
204
|
-
configDir,
|
|
205
|
-
settingsPath: path.join(configDir, 'settings.json'),
|
|
206
|
-
registryPath: path.join(configDir, 'plugins', 'installed_plugins.json'),
|
|
207
|
-
};
|
|
225
|
+
export function getWorkbuddyHostConfigPaths(homeDir, configDirOverride, env = process.env) {
|
|
226
|
+
const effectiveEnv = configDirOverride !== undefined
|
|
227
|
+
? { ...env, WORKBUDDY_CONFIG_DIR: configDirOverride }
|
|
228
|
+
: env;
|
|
229
|
+
return getWorkbuddyHostConfigPathsFromPdHome(requirePdHome({ homeDir, env: effectiveEnv }));
|
|
208
230
|
}
|
|
209
231
|
/** rc-1 minimal guard: a plain JSON object, not an array/null/primitive. */
|
|
210
232
|
function isPlainJsonObject(value) {
|
|
@@ -235,7 +257,9 @@ export function interpretWorkbuddyPluginState(input) {
|
|
|
235
257
|
};
|
|
236
258
|
}
|
|
237
259
|
export function resolveInstallLayout(options) {
|
|
238
|
-
const paths =
|
|
260
|
+
const paths = options.homePaths !== undefined
|
|
261
|
+
? getInstallLayoutPathsFromPdHome(options.homePaths)
|
|
262
|
+
: getInstallLayoutPaths(options.homeDir);
|
|
239
263
|
const parsed = parseInstallManifest(options.manifest);
|
|
240
264
|
const { warnings } = parsed;
|
|
241
265
|
if (parsed.manifest && parsed.manifest.mode === 'canonical' && options.canonicalRuntimeExists) {
|
|
@@ -290,12 +314,13 @@ export function getPdCliEntry(paths, mode) {
|
|
|
290
314
|
return path.join(root, 'dist', 'index.js');
|
|
291
315
|
}
|
|
292
316
|
/**
|
|
293
|
-
* PD home resolution (PRI-872): production keeps the historical
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
*
|
|
317
|
+
* PD home resolution (PRI-872): production keeps the historical home
|
|
318
|
+
* precedence (explicit `HOME` first, then `os.homedir()`);
|
|
319
|
+
* `PD_EXPERIMENT_ROOT` opts into a fail-closed isolated root. This is the ONE
|
|
320
|
+
* authority for "which PD home does this process own" — components must not
|
|
321
|
+
* re-derive it locally.
|
|
297
322
|
*/
|
|
298
|
-
export { PD_EXPERIMENT_ROOT_ENV, PD_OPENCLAW_HOME_ENV, PD_OPENCLAW_STATE_DIR_ENV, PD_HOME_MODES, PD_HOME_FAILURE_REASONS, resolvePdHome, isPathWithinRoot, } from './pd-home.js';
|
|
323
|
+
export { PD_EXPERIMENT_ROOT_ENV, PD_OPENCLAW_HOME_ENV, PD_OPENCLAW_STATE_DIR_ENV, PD_CODEX_HOME_ENV, PD_WORKBUDDY_CONFIG_DIR_ENV, PD_HOST_WORKSPACE_DIR_NAME, PD_HOME_MODES, PD_HOME_FAILURE_REASONS, resolvePdHome, isPathWithinRoot, } from './pd-home.js';
|
|
299
324
|
/**
|
|
300
325
|
* Codex host-persistent binding location. The versioned payload directory is
|
|
301
326
|
* REPLACED by a host cache refresh, taking any binding written inside it with
|
|
@@ -358,4 +383,4 @@ export function selectCodexMcpBindingPath(codexHome, pluginRoot) {
|
|
|
358
383
|
* against it by the parity test, and the installer / `pd health` import it
|
|
359
384
|
* directly so neither can drift into a more permissive check.
|
|
360
385
|
*/
|
|
361
|
-
export { MCP_BINDING_SCHEMA_VERSION, MCP_BINDING_HOSTS, MCP_BINDING_SERVER_ENTRY_SEGMENTS, MCP_BINDING_SHAPE_CODES, MCP_BINDING_LAUNCHER_ONLY_REASONS, MCP_BINDING_FIXTURES, getCanonicalMcpServerEntry, getHostDefaultWorkspaceDirs, findForeignWorkspaceHost, isSameMcpBindingPath, validateMcpBinding, buildMcpBindingFixture, isMcpBindingHost, isSupportedBindingSchemaVersion, isSemverVersion, } from './mcp-binding-contract.js';
|
|
386
|
+
export { MCP_BINDING_SCHEMA_VERSION, MCP_BINDING_HOSTS, MCP_BINDING_SERVER_ENTRY_SEGMENTS, MCP_BINDING_SHAPE_CODES, MCP_BINDING_LAUNCHER_ONLY_REASONS, MCP_BINDING_FIXTURES, getCanonicalMcpServerEntry, getHostDefaultWorkspaceDirs, findForeignWorkspaceHost, collectHostWorkspaceClaims, findForeignWorkspaceOwner, isSameMcpBindingPath, validateMcpBinding, buildMcpBindingFixture, isMcpBindingHost, isSupportedBindingSchemaVersion, isSemverVersion, } from './mcp-binding-contract.js';
|