create-principles-disciple 1.153.3 → 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 +153 -9
- package/console/dist/web/assets/app.js +41 -37
- package/console/dist/web/assets/intent-reflection.webp +3 -0
- 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/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/installer.d.ts +137 -9
- package/dist/installer.d.ts.map +1 -1
- package/dist/installer.js +627 -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.d.ts.map +1 -1
- package/dist/installers/workbuddy-host-installer.js +51 -15
- 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 +627 -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 +51 -15
- 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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync, lstatSync, mkdtempSync, readdirSync, realpathSync, statSync, readFileSync, writeFileSync, mkdirSync, rmSync, copyFileSync, cpSync, renameSync, chmodSync, symlinkSync } from 'fs';
|
|
1
|
+
import { existsSync, lstatSync, mkdtempSync, readdirSync, realpathSync, rmdirSync, statSync, readFileSync, writeFileSync, mkdirSync, rmSync, copyFileSync, cpSync, renameSync, chmodSync, symlinkSync, readlinkSync, openSync, readSync, closeSync } from 'fs';
|
|
2
2
|
import { tmpdir } from 'os';
|
|
3
3
|
import { createHash, randomInt, randomUUID } from 'node:crypto';
|
|
4
4
|
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
@@ -11,11 +11,13 @@ import { select } from '@inquirer/prompts';
|
|
|
11
11
|
import { logger } from './utils/logger.js';
|
|
12
12
|
import { checkOpenClawGateway, detectWorkspace, stopOpenClawGateway, restartOpenClawGateway } from './utils/env.js';
|
|
13
13
|
import { t } from './i18n.js';
|
|
14
|
-
import { generateConfigYamlContent, ExistingConfigVerifyInfraError, validateExistingConfigYamlForPreserve, getConfigYamlPath, readEnabledChannelsFromConfigYaml, getOpenClawDir, getPdDir, getPdRuntimeDir, getInstallManifestPath, getPdRuntimeBackupsDir, getPluginExtDir, getInstalledPluginDir, getInstalledLayoutPackageDir, getPdBackupsDir, getInstalledPdCliDir, getInstalledBinDir, getInstalledConsoleDir, getHomeDir, isWindows, } from './mvp-config.js';
|
|
14
|
+
import { generateConfigYamlContent, ExistingConfigVerifyInfraError, validateExistingConfigYamlForPreserve, getConfigYamlPath, readEnabledChannelsFromConfigYaml, getCodexHomeDir, getOpenClawDir, getPdDir, getPdRuntimeDir, getInstallManifestPath, getPdRuntimeBackupsDir, getPluginExtDir, getInstalledPluginDir, getInstalledLayoutPackageDir, getPdBackupsDir, getInstalledPdCliDir, getInstalledBinDir, getInstalledConsoleDir, getHomeDir, isWindows, } from './mvp-config.js';
|
|
15
15
|
import { detectInstalledHosts, evaluateRecordedHostPresence, getHostInstallers, isRecordedHost } from './installers/index.js';
|
|
16
|
+
import { errnoCode } from './utils/config-file-io.js';
|
|
16
17
|
import { readCanonicalRuntimeCohort, readInstalledRuntimeCohort, resolvePluginDataRoot } from './installers/codex-host-installer.js';
|
|
17
18
|
import { runWorkbuddyEarlyPreflight } from './installers/workbuddy-host-installer.js';
|
|
18
|
-
import {
|
|
19
|
+
import { findForeignWorkspaceOwner } from './utils/host-workspace-ownership.js';
|
|
20
|
+
import { INSTALL_LAYOUT_VERSION, getInstallLayoutPaths, getWorkbuddyWorkspaceDir, installManifestHostsForPersist, mergeInstallManifestWorkspaces, parseInstallManifest, resolvePdHome } from '@principles/install-layout';
|
|
19
21
|
import { resolveMcpServerDir } from './mcp-server-layout-compat.js';
|
|
20
22
|
import { detectOpenClawMainWorkspaceDivergence } from './utils/workspace-divergence.js';
|
|
21
23
|
import { applySkillLanguageSelection } from './skill-language.js';
|
|
@@ -91,6 +93,11 @@ const PD_CLI_VERIFICATION_TIMEOUT_MS = 30_000;
|
|
|
91
93
|
const STORY_A_VERIFICATION_TIMEOUT_MS = 30_000;
|
|
92
94
|
const CONSOLE_HEALTH_CHECK_TIMEOUT_MS = 8_000;
|
|
93
95
|
const CONSOLE_WARMUP_TIME_MS = 6_000;
|
|
96
|
+
const DEFAULT_CONSOLE_READY_PROBE_POLICY = {
|
|
97
|
+
warmupBudgetMs: CONSOLE_WARMUP_TIME_MS,
|
|
98
|
+
pollIntervalMs: 250,
|
|
99
|
+
healthTimeoutMs: CONSOLE_HEALTH_CHECK_TIMEOUT_MS,
|
|
100
|
+
};
|
|
94
101
|
// P0-2 (SPEC v1.2 §5 step 6): bounded exit-join windows for the verification
|
|
95
102
|
// child — SIGTERM wait, then SIGKILL wait. Bounded so a wedged child can never
|
|
96
103
|
// hang the install forever; the join RESULT (not a guess) decides whether
|
|
@@ -134,6 +141,15 @@ function installsOpenClaw(host) {
|
|
|
134
141
|
function installsWorkbuddy(host) {
|
|
135
142
|
return host === 'workbuddy' || host === 'all';
|
|
136
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Whether this run actually serves Codex — as the requested install target or
|
|
146
|
+
* as a persisted sibling host being refreshed. The Codex workspace is
|
|
147
|
+
* materialized ONLY then (review 2026-11-18): an OpenClaw-only run must not
|
|
148
|
+
* be rolled back by an unwritable CODEX_HOME it never asked to touch.
|
|
149
|
+
*/
|
|
150
|
+
export function installRunServesCodex(host, refreshTargets) {
|
|
151
|
+
return host === 'codex' || host === 'all' || refreshTargets.includes('codex');
|
|
152
|
+
}
|
|
137
153
|
function pluginInstallDirs() {
|
|
138
154
|
return installsOpenClaw(activeHostTarget)
|
|
139
155
|
? [getInstalledPluginDir(), getPluginExtDir()]
|
|
@@ -256,7 +272,7 @@ function resolveInstallManifestWorkspaces(workspaceDir, host) {
|
|
|
256
272
|
if (host === 'workbuddy') {
|
|
257
273
|
// Set-union via the same authority helper — order of existing entries is
|
|
258
274
|
// preserved, the governance dir is appended when absent (idempotent).
|
|
259
|
-
workspaces = mergeInstallManifestWorkspaces({ layoutVersion: parsed.manifest?.layoutVersion ?? INSTALL_LAYOUT_VERSION, mode: parsed.manifest?.mode ?? 'canonical', hosts: parsed.manifest?.hosts ?? [], workspaces }, getWorkbuddyWorkspaceDir(getHomeDir()));
|
|
275
|
+
workspaces = mergeInstallManifestWorkspaces({ layoutVersion: parsed.manifest?.layoutVersion ?? INSTALL_LAYOUT_VERSION, mode: parsed.manifest?.mode ?? 'canonical', hosts: parsed.manifest?.hosts ?? [], workspaces }, getWorkbuddyWorkspaceDir(getHomeDir(), process.env.WORKBUDDY_CONFIG_DIR));
|
|
260
276
|
}
|
|
261
277
|
return workspaces;
|
|
262
278
|
}
|
|
@@ -1049,27 +1065,136 @@ function updateProgress(spinner, currentStep, message) {
|
|
|
1049
1065
|
spinner.text = `${message} (${percent}%)`;
|
|
1050
1066
|
}
|
|
1051
1067
|
/**
|
|
1052
|
-
*
|
|
1053
|
-
*
|
|
1054
|
-
*
|
|
1055
|
-
*
|
|
1056
|
-
*
|
|
1057
|
-
|
|
1068
|
+
* §8.4: why a symlink entry must NOT be renamed into the canonical backups
|
|
1069
|
+
* root, or null when the move is target-semantics-safe. A RELATIVE target
|
|
1070
|
+
* resolves against the link's own directory — renaming the link to a different
|
|
1071
|
+
* parent silently repoints it; an unreadable target is unjudgeable. Absolute
|
|
1072
|
+
* targets (and Windows junctions, whose readlink output is absolute) are safe.
|
|
1073
|
+
*/
|
|
1074
|
+
function symlinkMoveProblem(linkPath) {
|
|
1075
|
+
let target;
|
|
1076
|
+
try {
|
|
1077
|
+
target = readlinkSync(linkPath);
|
|
1078
|
+
}
|
|
1079
|
+
catch (e) {
|
|
1080
|
+
return `symlink target unreadable: ${e instanceof Error ? e.message : String(e)}`;
|
|
1081
|
+
}
|
|
1082
|
+
return path.isAbsolute(target) ? null : `relative symlink target "${target}" would change meaning after the move`;
|
|
1083
|
+
}
|
|
1084
|
+
/**
|
|
1085
|
+
* Move legacy PD backup directories into the canonical host-neutral backups
|
|
1086
|
+
* root (<PD_HOME>/.pd/backups). This runs ONLY inside the explicit installer
|
|
1087
|
+
* flow — never on console startup, never during health checks.
|
|
1088
|
+
*
|
|
1089
|
+
* Two legacy locations are consolidated:
|
|
1090
|
+
* 1. `<openclawHome>/pd-backups` — the pre-layout OpenClaw-only backup root.
|
|
1091
|
+
* Every entry (including unknown user files) is moved, preserving names;
|
|
1092
|
+
* collisions get a deterministic `-<n>` suffix and the original under the
|
|
1093
|
+
* old root is never overwritten. The old root itself is removed only when
|
|
1094
|
+
* it became empty (its data now lives at the canonical root).
|
|
1095
|
+
* 2. `extensions/` siblings named ".pd-backup-<ts>" or
|
|
1096
|
+
* "principles-disciple.backup.<ms>" — OpenClaw plugin discovery scans
|
|
1097
|
+
* every extensions/ child directory, so those backups are discovered as
|
|
1098
|
+
* duplicate principles-disciple plugins ("duplicate plugin id detected"
|
|
1099
|
+
* on every gateway startup).
|
|
1100
|
+
*
|
|
1101
|
+
* Best-effort per entry (rc-9): a failed move keeps the original in place and
|
|
1102
|
+
* is reported; the run never fails because of it. Never recursively deletes a
|
|
1103
|
+
* directory that still contains data.
|
|
1058
1104
|
*
|
|
1059
1105
|
* Exported for real-filesystem tests (tests/backup-location.test.ts).
|
|
1060
1106
|
*/
|
|
1061
1107
|
export function migrateLegacyPdBackups() {
|
|
1108
|
+
const result = { movedFrom: [], failed: [] };
|
|
1109
|
+
const backupsDir = getPdBackupsDir();
|
|
1110
|
+
// 1. The legacy OpenClaw-only backups root. Unknown user files are moved
|
|
1111
|
+
// verbatim — this root was the owner's backup storage, not plugin data.
|
|
1112
|
+
const legacyBackupsRoot = path.join(getOpenClawDir(), 'pd-backups');
|
|
1113
|
+
if (path.resolve(legacyBackupsRoot) !== path.resolve(backupsDir)) {
|
|
1114
|
+
let legacyEntries;
|
|
1115
|
+
try {
|
|
1116
|
+
legacyEntries = readdirSync(legacyBackupsRoot, { withFileTypes: true });
|
|
1117
|
+
}
|
|
1118
|
+
catch (e) {
|
|
1119
|
+
if (errnoCode(e) !== 'ENOENT') {
|
|
1120
|
+
result.failed.push({ name: 'pd-backups', source: legacyBackupsRoot, reason: e instanceof Error ? e.message : String(e) });
|
|
1121
|
+
}
|
|
1122
|
+
legacyEntries = [];
|
|
1123
|
+
}
|
|
1124
|
+
// §8.4 (Devin Round 4 #2): a relative symlink's target may be a SIBLING
|
|
1125
|
+
// entry of the same root, and the migration moves every non-blocked entry
|
|
1126
|
+
// — preserving the link alone would strand it on a vacated target. The
|
|
1127
|
+
// provable-semantics contract cannot be met for that root, so the WHOLE
|
|
1128
|
+
// root is preserved in place (preservation over migration) with one
|
|
1129
|
+
// structured failure naming the blocking links.
|
|
1130
|
+
const blockingLinks = legacyEntries
|
|
1131
|
+
.filter((entry) => entry.isSymbolicLink() && symlinkMoveProblem(path.join(legacyBackupsRoot, entry.name)) !== null)
|
|
1132
|
+
.map((entry) => entry.name);
|
|
1133
|
+
if (blockingLinks.length > 0) {
|
|
1134
|
+
result.failed.push({
|
|
1135
|
+
name: 'pd-backups',
|
|
1136
|
+
source: legacyBackupsRoot,
|
|
1137
|
+
reason: `root preserved in place: contains relative symlink(s) whose target may live inside the root (${blockingLinks.join(', ')}) — migrating the other entries would repoint or strand them`,
|
|
1138
|
+
});
|
|
1139
|
+
return result;
|
|
1140
|
+
}
|
|
1141
|
+
let allMoved = true;
|
|
1142
|
+
for (const entry of legacyEntries) {
|
|
1143
|
+
const from = path.join(legacyBackupsRoot, entry.name);
|
|
1144
|
+
// §8.4: a symlink with a RELATIVE target resolves against its own
|
|
1145
|
+
// directory, so moving it to the canonical root (a different parent)
|
|
1146
|
+
// silently REPOINTS it — a migration that changes what the link means is
|
|
1147
|
+
// not a migration. Keep it in place and record a structured failure
|
|
1148
|
+
// instead of pretending success. Absolute targets survive a rename
|
|
1149
|
+
// unchanged and stay movable.
|
|
1150
|
+
if (entry.isSymbolicLink()) {
|
|
1151
|
+
const linkProblem = symlinkMoveProblem(from);
|
|
1152
|
+
if (linkProblem !== null) {
|
|
1153
|
+
allMoved = false;
|
|
1154
|
+
result.failed.push({ name: entry.name, source: from, reason: linkProblem });
|
|
1155
|
+
continue;
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
let dest = path.join(backupsDir, entry.name);
|
|
1159
|
+
let suffix = 1;
|
|
1160
|
+
while (existsSync(dest)) {
|
|
1161
|
+
dest = path.join(backupsDir, `${entry.name}-${suffix}`);
|
|
1162
|
+
suffix += 1;
|
|
1163
|
+
}
|
|
1164
|
+
try {
|
|
1165
|
+
mkdirSync(backupsDir, { recursive: true });
|
|
1166
|
+
renameSync(from, dest);
|
|
1167
|
+
result.movedFrom.push(from);
|
|
1168
|
+
}
|
|
1169
|
+
catch (e) {
|
|
1170
|
+
allMoved = false;
|
|
1171
|
+
result.failed.push({ name: entry.name, source: from, reason: e instanceof Error ? e.message : String(e) });
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
// The old root is only removed when it is now provably empty — never a
|
|
1175
|
+
// recursive delete of data.
|
|
1176
|
+
if (allMoved) {
|
|
1177
|
+
try {
|
|
1178
|
+
rmdirSync(legacyBackupsRoot);
|
|
1179
|
+
}
|
|
1180
|
+
catch {
|
|
1181
|
+
// Kept intact when a move failed or a concurrent entry appeared.
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
// 2. Legacy extension siblings (both break OpenClaw plugin discovery).
|
|
1062
1186
|
const extensionsDir = path.join(getOpenClawDir(), 'extensions');
|
|
1063
1187
|
let entries;
|
|
1064
1188
|
try {
|
|
1065
1189
|
entries = readdirSync(extensionsDir, { withFileTypes: true });
|
|
1066
1190
|
}
|
|
1067
|
-
catch {
|
|
1068
|
-
|
|
1191
|
+
catch (e) {
|
|
1192
|
+
if (errnoCode(e) !== 'ENOENT') {
|
|
1193
|
+
result.failed.push({ name: 'extensions', source: extensionsDir, reason: e instanceof Error ? e.message : String(e) });
|
|
1194
|
+
}
|
|
1195
|
+
return result;
|
|
1069
1196
|
}
|
|
1070
1197
|
const isLegacyName = (name) => name.startsWith('.pd-backup-') || /^principles-disciple\.backup\.\d+$/.test(name);
|
|
1071
|
-
const backupsDir = getPdBackupsDir();
|
|
1072
|
-
let moved = 0;
|
|
1073
1198
|
for (const entry of entries) {
|
|
1074
1199
|
if (!entry.isDirectory() || !isLegacyName(entry.name))
|
|
1075
1200
|
continue;
|
|
@@ -1082,14 +1207,27 @@ export function migrateLegacyPdBackups() {
|
|
|
1082
1207
|
try {
|
|
1083
1208
|
mkdirSync(backupsDir, { recursive: true });
|
|
1084
1209
|
renameSync(path.join(extensionsDir, entry.name), dest);
|
|
1085
|
-
|
|
1210
|
+
result.movedFrom.push(path.join(extensionsDir, entry.name));
|
|
1086
1211
|
}
|
|
1087
1212
|
catch (e) {
|
|
1088
|
-
|
|
1213
|
+
result.failed.push({
|
|
1214
|
+
name: entry.name,
|
|
1215
|
+
source: path.join(extensionsDir, entry.name),
|
|
1216
|
+
reason: e instanceof Error ? e.message : String(e),
|
|
1217
|
+
});
|
|
1089
1218
|
}
|
|
1090
1219
|
}
|
|
1091
|
-
|
|
1092
|
-
|
|
1220
|
+
return result;
|
|
1221
|
+
}
|
|
1222
|
+
/** Report the explicit migration outcome (rc-9) after the caller logs it. */
|
|
1223
|
+
export function reportLegacyBackupMigration(result, backupsDir) {
|
|
1224
|
+
if (result.movedFrom.length > 0) {
|
|
1225
|
+
logger.info(`Migrated ${result.movedFrom.length} legacy PD backup dir(s) into ${backupsDir}:`);
|
|
1226
|
+
for (const moved of result.movedFrom)
|
|
1227
|
+
logger.info(` ${moved}`);
|
|
1228
|
+
}
|
|
1229
|
+
for (const failure of result.failed) {
|
|
1230
|
+
logger.warn(`Could not migrate legacy PD backup "${failure.name}": ${failure.reason}. The original is preserved; move it into ${backupsDir} manually.`);
|
|
1093
1231
|
}
|
|
1094
1232
|
}
|
|
1095
1233
|
/**
|
|
@@ -1108,6 +1246,101 @@ export class BackupIntegrityError extends Error {
|
|
|
1108
1246
|
this.runtimeBackupDir = runtimeBackupDir;
|
|
1109
1247
|
}
|
|
1110
1248
|
}
|
|
1249
|
+
/** Streamed byte compare: one 1MiB chunk at a time, no whole-file buffering. */
|
|
1250
|
+
function compareFileContent(sourcePath, copyPath, label) {
|
|
1251
|
+
const CHUNK = 1024 * 1024;
|
|
1252
|
+
const sourceFd = openSync(sourcePath, 'r');
|
|
1253
|
+
// The copy may be unopenable (e.g. EACCES on the copy) AFTER the source is
|
|
1254
|
+
// already open — close the source before propagating, no fd leak.
|
|
1255
|
+
let copyFd;
|
|
1256
|
+
try {
|
|
1257
|
+
copyFd = openSync(copyPath, 'r');
|
|
1258
|
+
}
|
|
1259
|
+
catch (copyError) {
|
|
1260
|
+
closeSync(sourceFd);
|
|
1261
|
+
throw copyError;
|
|
1262
|
+
}
|
|
1263
|
+
try {
|
|
1264
|
+
const sourceBuf = Buffer.alloc(CHUNK);
|
|
1265
|
+
const copyBuf = Buffer.alloc(CHUNK);
|
|
1266
|
+
for (;;) {
|
|
1267
|
+
const sourceRead = readSync(sourceFd, sourceBuf, 0, CHUNK, null);
|
|
1268
|
+
const copyRead = readSync(copyFd, copyBuf, 0, CHUNK, null);
|
|
1269
|
+
if (sourceRead !== copyRead) {
|
|
1270
|
+
throw new Error(`copy verification failed: content length differs for "${label}"`);
|
|
1271
|
+
}
|
|
1272
|
+
if (sourceRead === 0)
|
|
1273
|
+
return;
|
|
1274
|
+
if (!sourceBuf.subarray(0, sourceRead).equals(copyBuf.subarray(0, copyRead))) {
|
|
1275
|
+
throw new Error(`copy verification failed: content differs for "${label}"`);
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
finally {
|
|
1280
|
+
closeSync(sourceFd);
|
|
1281
|
+
closeSync(copyFd);
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
/**
|
|
1285
|
+
* §7.3 integrity gate for copy-based tree moves: the copy is only as good as
|
|
1286
|
+
* its verification, and "the directory exists" proves nothing. Walks BOTH
|
|
1287
|
+
* trees in lockstep and refuses when ANY of these diverge:
|
|
1288
|
+
* - the relative entry set (missing or extra files/dirs either way);
|
|
1289
|
+
* - entry TYPES (file vs directory vs symbolic link — cpSync semantics);
|
|
1290
|
+
* - regular-file SIZES (covers empty files and large files cheaply);
|
|
1291
|
+
* - regular-file CONTENT (streamed chunk compare — one pass per side, no
|
|
1292
|
+
* whole-file buffering, no hash re-read of the copy);
|
|
1293
|
+
* - symlink TARGETS (readlink — a retargeted link is different data).
|
|
1294
|
+
* Deliberately NOT compared: mtimes (cross-volume/FAT granularity noise) —
|
|
1295
|
+
* type+size+content is the integrity core; size equality plus content equality
|
|
1296
|
+
* on every file subsumes the file-count and byte-total invariants.
|
|
1297
|
+
* Returns the verified file count; throws a plain Error with the FIRST
|
|
1298
|
+
* mismatch (rc-3) so the caller aborts before touching any original.
|
|
1299
|
+
*/
|
|
1300
|
+
function verifyCopiedTree(source, copy) {
|
|
1301
|
+
const sourceEntries = readdirSync(source, { withFileTypes: true });
|
|
1302
|
+
const copyEntries = readdirSync(copy, { withFileTypes: true });
|
|
1303
|
+
const byName = new Map(copyEntries.map((entry) => [entry.name, entry]));
|
|
1304
|
+
let verifiedFiles = 0;
|
|
1305
|
+
for (const sourceEntry of sourceEntries) {
|
|
1306
|
+
const copyEntry = byName.get(sourceEntry.name);
|
|
1307
|
+
if (copyEntry === undefined) {
|
|
1308
|
+
throw new Error(`copy verification failed: "${sourceEntry.name}" is missing from the copy of ${source}`);
|
|
1309
|
+
}
|
|
1310
|
+
byName.delete(sourceEntry.name);
|
|
1311
|
+
if (sourceEntry.isDirectory() !== copyEntry.isDirectory()
|
|
1312
|
+
|| sourceEntry.isFile() !== copyEntry.isFile()
|
|
1313
|
+
|| sourceEntry.isSymbolicLink() !== copyEntry.isSymbolicLink()) {
|
|
1314
|
+
throw new Error(`copy verification failed: entry type differs for "${sourceEntry.name}" between ${source} and ${copy}`);
|
|
1315
|
+
}
|
|
1316
|
+
const sourcePath = path.join(source, sourceEntry.name);
|
|
1317
|
+
const copyPath = path.join(copy, sourceEntry.name);
|
|
1318
|
+
if (sourceEntry.isDirectory()) {
|
|
1319
|
+
verifiedFiles += verifyCopiedTree(sourcePath, copyPath);
|
|
1320
|
+
continue;
|
|
1321
|
+
}
|
|
1322
|
+
if (sourceEntry.isSymbolicLink()) {
|
|
1323
|
+
const sourceTarget = readlinkSync(sourcePath);
|
|
1324
|
+
const copyTarget = readlinkSync(copyPath);
|
|
1325
|
+
if (sourceTarget !== copyTarget) {
|
|
1326
|
+
throw new Error(`copy verification failed: symlink target differs for "${sourceEntry.name}" (${sourceTarget} vs ${copyTarget})`);
|
|
1327
|
+
}
|
|
1328
|
+
continue;
|
|
1329
|
+
}
|
|
1330
|
+
const sourceStat = statSync(sourcePath);
|
|
1331
|
+
const copyStat = statSync(copyPath);
|
|
1332
|
+
if (sourceStat.size !== copyStat.size) {
|
|
1333
|
+
throw new Error(`copy verification failed: size differs for "${sourceEntry.name}" (${sourceStat.size} vs ${copyStat.size} bytes)`);
|
|
1334
|
+
}
|
|
1335
|
+
compareFileContent(sourcePath, copyPath, sourceEntry.name);
|
|
1336
|
+
verifiedFiles += 1;
|
|
1337
|
+
}
|
|
1338
|
+
const leftover = byName.keys().next();
|
|
1339
|
+
if (leftover.done !== true) {
|
|
1340
|
+
throw new Error(`copy verification failed: "${leftover.value}" exists only in the copy of ${source}`);
|
|
1341
|
+
}
|
|
1342
|
+
return verifiedFiles;
|
|
1343
|
+
}
|
|
1111
1344
|
/**
|
|
1112
1345
|
* Exported for real-filesystem tests (tests/backup-location.test.ts).
|
|
1113
1346
|
*/
|
|
@@ -1129,7 +1362,47 @@ export function backupExistingInstall(host = 'openclaw') {
|
|
|
1129
1362
|
try {
|
|
1130
1363
|
mkdirSync(backupsDir, { recursive: true });
|
|
1131
1364
|
if (backupDir) {
|
|
1132
|
-
|
|
1365
|
+
try {
|
|
1366
|
+
renameSync(extDir, backupDir);
|
|
1367
|
+
}
|
|
1368
|
+
catch (renameError) {
|
|
1369
|
+
// OPENCLAW_STATE_DIR may live on a different volume than <PD_HOME>
|
|
1370
|
+
// (Devin review #2699-0002): rename is same-volume only. Fall back to
|
|
1371
|
+
// copy → VERIFY → remove, keeping the ORIGINAL until the copy is
|
|
1372
|
+
// proven complete (never a delete-first move, §7.1). A failed or
|
|
1373
|
+
// partial copy removes the partial backup dir and aborts BEFORE the
|
|
1374
|
+
// original is touched — an incomplete directory is never a valid
|
|
1375
|
+
// backup. A cleanup failure AFTER the verified copy is a different
|
|
1376
|
+
// state: the FULL backup exists, so BackupIntegrityError carries its
|
|
1377
|
+
// path out for the caller's restore machinery instead of a generic
|
|
1378
|
+
// error that would strand the moved tree (Devin review xc8K).
|
|
1379
|
+
if (errnoCode(renameError) !== 'EXDEV')
|
|
1380
|
+
throw renameError;
|
|
1381
|
+
logger.warn(`Extension dir and backups root are on different volumes; falling back to copy-based backup (rename EXDEV: ${extDir} → ${backupDir})`);
|
|
1382
|
+
try {
|
|
1383
|
+
// verbatimSymlinks: true copies each link AS-IS (target string
|
|
1384
|
+
// byte-identical) — with false, Node rewrites relative targets to
|
|
1385
|
+
// absolute paths, which (a) changes what the copied tree means and
|
|
1386
|
+
// (b) makes verifyCopiedTree's readlink comparison reject a CORRECT
|
|
1387
|
+
// copy (the installer's own core link is relative). Verbatim keeps
|
|
1388
|
+
// the copied tree's link semantics exactly the original's.
|
|
1389
|
+
cpSync(extDir, backupDir, { recursive: true, verbatimSymlinks: true });
|
|
1390
|
+
verifyCopiedTree(extDir, backupDir);
|
|
1391
|
+
}
|
|
1392
|
+
catch (copyError) {
|
|
1393
|
+
try {
|
|
1394
|
+
rmSync(backupDir, { recursive: true, force: true });
|
|
1395
|
+
}
|
|
1396
|
+
catch { /* partial-backup residue is inert: nothing references it yet */ }
|
|
1397
|
+
throw copyError;
|
|
1398
|
+
}
|
|
1399
|
+
try {
|
|
1400
|
+
rmSync(extDir, { recursive: true, force: true });
|
|
1401
|
+
}
|
|
1402
|
+
catch (cleanupError) {
|
|
1403
|
+
throw new BackupIntegrityError(`Cross-volume backup copy completed and verified (${backupDir}), but removing the original ${extDir} failed partway: ${cleanupError instanceof Error ? cleanupError.message : String(cleanupError)}. The COMPLETE backup is preserved — the install failure handler restores it over the residue.`, backupDir, null);
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1133
1406
|
extMoved = true;
|
|
1134
1407
|
}
|
|
1135
1408
|
if (runtimeBackupDir) {
|
|
@@ -1140,6 +1413,11 @@ export function backupExistingInstall(host = 'openclaw') {
|
|
|
1140
1413
|
return { type: 'backed_up', backupDir, runtimeBackupDir };
|
|
1141
1414
|
}
|
|
1142
1415
|
catch (e) {
|
|
1416
|
+
// BackupIntegrityError already carries the exact recovery state (full
|
|
1417
|
+
// backup path + what failed) — rethrow untouched, never re-wrapped into a
|
|
1418
|
+
// path-less generic error (Devin review xc8K).
|
|
1419
|
+
if (e instanceof BackupIntegrityError)
|
|
1420
|
+
throw e;
|
|
1143
1421
|
// P0-3 (PRI-1070 comment §2): a PARTIAL backup (extension moved, runtime
|
|
1144
1422
|
// move failed) used to escape with no path information — the caller then
|
|
1145
1423
|
// ran restoreBackup(null, null), a no-op that silently stranded the moved
|
|
@@ -1157,6 +1435,63 @@ export function backupExistingInstall(host = 'openclaw') {
|
|
|
1157
1435
|
throw new Error(`Could not backup existing install at ${extDir}: ${e instanceof Error ? e.message : String(e)}. Aborting to prevent data loss — resolve the lock or rename manually and re-run.`, { cause: e });
|
|
1158
1436
|
}
|
|
1159
1437
|
}
|
|
1438
|
+
/**
|
|
1439
|
+
* Move `from` onto `to` with a cross-volume fallback (Devin review #2699-0002,
|
|
1440
|
+
* hardened per §7.2 / Devin review xc8p): rename is same-volume only; on EXDEV
|
|
1441
|
+
* the copy completes in a UNIQUE STAGING DIRECTORY ON THE TARGET VOLUME, is
|
|
1442
|
+
* verified there, and only then renames (same-volume, atomic) onto the formal
|
|
1443
|
+
* target. A mid-copy failure leaves the FORMAL TARGET ABSENT — so the caller's
|
|
1444
|
+
* quarantine-undo still works and the host never reads a half-restored tree.
|
|
1445
|
+
* After the verified staging rename, source cleanup failure is a DEGRADED note,
|
|
1446
|
+
* never a failure of the (already complete) restore.
|
|
1447
|
+
* Returns a residue note when source cleanup failed (caller reports it).
|
|
1448
|
+
*/
|
|
1449
|
+
function moveTreeAside(from, to) {
|
|
1450
|
+
let staging;
|
|
1451
|
+
try {
|
|
1452
|
+
renameSync(from, to);
|
|
1453
|
+
return null;
|
|
1454
|
+
}
|
|
1455
|
+
catch (renameError) {
|
|
1456
|
+
if (errnoCode(renameError) !== 'EXDEV')
|
|
1457
|
+
throw renameError;
|
|
1458
|
+
}
|
|
1459
|
+
logger.warn(`Cross-volume restore (rename EXDEV): staging copy ${from} → ${to}`);
|
|
1460
|
+
staging = `${to}.restore-staging.${Date.now()}`;
|
|
1461
|
+
try {
|
|
1462
|
+
// verbatimSymlinks: true — same link-semantics preservation as the backup
|
|
1463
|
+
// path above; a non-verbatim copy rewrites relative targets and then fails
|
|
1464
|
+
// its own verifyCopiedTree link comparison.
|
|
1465
|
+
cpSync(from, staging, { recursive: true, verbatimSymlinks: true });
|
|
1466
|
+
verifyCopiedTree(from, staging);
|
|
1467
|
+
// Copy verified → the atomic same-volume rename is the only remaining step.
|
|
1468
|
+
renameSync(staging, to);
|
|
1469
|
+
}
|
|
1470
|
+
catch (copyError) {
|
|
1471
|
+
if (staging !== null) {
|
|
1472
|
+
try {
|
|
1473
|
+
rmSync(staging, { recursive: true, force: true });
|
|
1474
|
+
}
|
|
1475
|
+
catch (cleanupError) {
|
|
1476
|
+
logger.warn(`Restore staging residue left at ${staging} after a failed copy (best-effort cleanup failed: ${cleanupError instanceof Error ? cleanupError.message : String(cleanupError)}) — nothing references it; the formal target was never touched.`);
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
throw copyError;
|
|
1480
|
+
}
|
|
1481
|
+
// The restore is COMPLETE (target holds verified bytes). Source cleanup is
|
|
1482
|
+
// best-effort: a locked file (EPERM) here must not fail the restore or undo
|
|
1483
|
+
// the quarantine swap — the leftover source is a harmless full copy of the
|
|
1484
|
+
// data that was just restored (§7.2: a cleanup failure reports DEGRADED).
|
|
1485
|
+
try {
|
|
1486
|
+
rmSync(from, { recursive: true, force: true });
|
|
1487
|
+
}
|
|
1488
|
+
catch (cleanupError) {
|
|
1489
|
+
const note = `source cleanup failed (source kept at ${from}): ${cleanupError instanceof Error ? cleanupError.message : String(cleanupError)}`;
|
|
1490
|
+
logger.warn(`Cross-volume restore completed; ${note}`);
|
|
1491
|
+
return note;
|
|
1492
|
+
}
|
|
1493
|
+
return null;
|
|
1494
|
+
}
|
|
1160
1495
|
/**
|
|
1161
1496
|
* Restore ONE tree rename-aside (P0-3, PRI-1070; SPEC v1.2 §17):
|
|
1162
1497
|
*
|
|
@@ -1164,7 +1499,7 @@ export function backupExistingInstall(host = 'openclaw') {
|
|
|
1164
1499
|
* (same-volume rename; NEVER a recursive delete — the R8 experiment
|
|
1165
1500
|
* proved a live process's mapped .node makes rmSync die with EPERM
|
|
1166
1501
|
* halfway through, while a directory rename succeeds).
|
|
1167
|
-
* 2. rename the backup onto the target.
|
|
1502
|
+
* 2. rename the backup onto the target (cross-volume: copy → verify → remove).
|
|
1168
1503
|
* 3. success → best-effort delete of the quarantine (residue is reported,
|
|
1169
1504
|
* never fatal).
|
|
1170
1505
|
* step 2 failure → try to rename the quarantine back (undo the aside);
|
|
@@ -1194,8 +1529,8 @@ function restoreTreeAside(tree, backupDir, targetDir) {
|
|
|
1194
1529
|
quarantine = null;
|
|
1195
1530
|
}
|
|
1196
1531
|
}
|
|
1197
|
-
|
|
1198
|
-
let residue = ''
|
|
1532
|
+
const sourceCleanupNote = moveTreeAside(backupDir, targetDir);
|
|
1533
|
+
let residue = sourceCleanupNote === null ? '' : `; ${sourceCleanupNote}`;
|
|
1199
1534
|
if (quarantine !== null) {
|
|
1200
1535
|
try {
|
|
1201
1536
|
rmSync(quarantine, { recursive: true, force: true });
|
|
@@ -3221,8 +3556,111 @@ function isVerifiedConsoleIdentity(payload, expectedNonce) {
|
|
|
3221
3556
|
return false;
|
|
3222
3557
|
return Reflect.get(data, 'verifyNonce') === expectedNonce;
|
|
3223
3558
|
}
|
|
3559
|
+
/**
|
|
3560
|
+
* One `/api/health` request against a spawned console attempt.
|
|
3561
|
+
*
|
|
3562
|
+
* `responded` separates "nothing is listening yet" (retry within the warmup
|
|
3563
|
+
* budget) from "something answered" (classify immediately — a responder that
|
|
3564
|
+
* cannot echo this launch's nonce will never start doing so).
|
|
3565
|
+
*/
|
|
3566
|
+
async function probeConsoleHealthOnce(port, nonce, timeoutMs) {
|
|
3567
|
+
const healthUrl = new URL('/api/health', `http://127.0.0.1:${port}`);
|
|
3568
|
+
let result;
|
|
3569
|
+
try {
|
|
3570
|
+
result = await new Promise((resolve, reject) => {
|
|
3571
|
+
const req = http.get(healthUrl, (res) => {
|
|
3572
|
+
const chunks = [];
|
|
3573
|
+
res.on('data', (chunk) => chunks.push(chunk));
|
|
3574
|
+
res.on('end', () => {
|
|
3575
|
+
resolve({ statusCode: res.statusCode ?? 0, body: Buffer.concat(chunks).toString() });
|
|
3576
|
+
});
|
|
3577
|
+
});
|
|
3578
|
+
req.on('error', reject);
|
|
3579
|
+
req.setTimeout(timeoutMs, () => { req.destroy(); reject(new Error('health check timeout')); });
|
|
3580
|
+
});
|
|
3581
|
+
}
|
|
3582
|
+
catch (e) {
|
|
3583
|
+
return {
|
|
3584
|
+
responded: false,
|
|
3585
|
+
ok: false,
|
|
3586
|
+
reason: `Console health check failed on port ${port}: ${e instanceof Error ? e.message : String(e)}`,
|
|
3587
|
+
reasonKind: 'request_error',
|
|
3588
|
+
};
|
|
3589
|
+
}
|
|
3590
|
+
const { statusCode } = result;
|
|
3591
|
+
if (statusCode !== 200) {
|
|
3592
|
+
// SPEC v1.2 §14: a 502 (or any non-200) is recorded as an observed fact
|
|
3593
|
+
// with UNKNOWN attribution — we do NOT guess whether the responder was PD,
|
|
3594
|
+
// a proxy, or another local service (PRI-1069).
|
|
3595
|
+
return {
|
|
3596
|
+
responded: true,
|
|
3597
|
+
ok: false,
|
|
3598
|
+
httpStatus: statusCode,
|
|
3599
|
+
reason: `Console /api/health returned HTTP ${statusCode} (expected 200); responder identity unknown`,
|
|
3600
|
+
reasonKind: 'http_error_status',
|
|
3601
|
+
};
|
|
3602
|
+
}
|
|
3603
|
+
if (!result.body || result.body.trim().length === 0) {
|
|
3604
|
+
return { responded: true, ok: false, httpStatus: statusCode, reason: 'Console /api/health returned empty body', reasonKind: 'bad_body' };
|
|
3605
|
+
}
|
|
3606
|
+
let parsed;
|
|
3607
|
+
try {
|
|
3608
|
+
parsed = JSON.parse(result.body);
|
|
3609
|
+
}
|
|
3610
|
+
catch {
|
|
3611
|
+
return { responded: true, ok: false, httpStatus: statusCode, reason: 'Console /api/health returned malformed JSON', reasonKind: 'bad_body' };
|
|
3612
|
+
}
|
|
3613
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
3614
|
+
return { responded: true, ok: false, httpStatus: statusCode, reason: 'Console /api/health returned non-object JSON', reasonKind: 'bad_body' };
|
|
3615
|
+
}
|
|
3616
|
+
if (!isVerifiedConsoleIdentity(parsed, nonce)) {
|
|
3617
|
+
// P0-1 fail-closed: a 200 JSON object that cannot echo THIS attempt's
|
|
3618
|
+
// nonce is some other responder (old console, foreign local service,
|
|
3619
|
+
// proxy) — never "verified".
|
|
3620
|
+
return {
|
|
3621
|
+
responded: true,
|
|
3622
|
+
ok: false,
|
|
3623
|
+
httpStatus: statusCode,
|
|
3624
|
+
reason: 'Health responder did not prove this launch instance (nonce/shape mismatch) — rejected',
|
|
3625
|
+
reasonKind: 'identity_mismatch',
|
|
3626
|
+
};
|
|
3627
|
+
}
|
|
3628
|
+
return { responded: true, ok: true, httpStatus: statusCode, reason: '', reasonKind: 'bad_body' };
|
|
3629
|
+
}
|
|
3630
|
+
/**
|
|
3631
|
+
* Waits until the spawned console is READY (answers) or the warmup budget runs
|
|
3632
|
+
* out, checking after every attempt whether the child exited early.
|
|
3633
|
+
*
|
|
3634
|
+
* Two outcomes end the wait early:
|
|
3635
|
+
* - a VERIFIED response (200 + this launch's nonce) -> ready;
|
|
3636
|
+
* - an identity MISMATCH (200 without the nonce) -> a foreign responder owns
|
|
3637
|
+
* the port; it will never echo this attempt's nonce, so retrying only burns
|
|
3638
|
+
* the budget (this is the fail-closed P0-1 case).
|
|
3639
|
+
* A non-200 answer or a transport error keeps polling: a console that binds its
|
|
3640
|
+
* port before its routes are mounted must not be misread as "not PD", and a
|
|
3641
|
+
* port that is not listening yet is simply still booting. Never reports
|
|
3642
|
+
* success: readiness still has to pass the identity check.
|
|
3643
|
+
*/
|
|
3644
|
+
async function probeConsoleReadiness(args) {
|
|
3645
|
+
const { port, nonce, policy, hasChildExited } = args;
|
|
3646
|
+
const budgetMs = Math.max(0, policy.warmupBudgetMs);
|
|
3647
|
+
const deadline = Date.now() + budgetMs;
|
|
3648
|
+
for (;;) {
|
|
3649
|
+
if (hasChildExited())
|
|
3650
|
+
return { kind: 'exited' };
|
|
3651
|
+
const probe = await probeConsoleHealthOnce(port, nonce, policy.healthTimeoutMs);
|
|
3652
|
+
if (probe.responded && (probe.ok || probe.reasonKind === 'identity_mismatch')) {
|
|
3653
|
+
return { kind: 'responded', probe };
|
|
3654
|
+
}
|
|
3655
|
+
const remaining = deadline - Date.now();
|
|
3656
|
+
if (remaining <= 0)
|
|
3657
|
+
return { kind: 'timeout', probe };
|
|
3658
|
+
await new Promise((resolve) => { setTimeout(resolve, Math.min(policy.pollIntervalMs, remaining)); });
|
|
3659
|
+
}
|
|
3660
|
+
}
|
|
3224
3661
|
/** Exported for real-subprocess tests (tests/console-verify-identity.test.ts). */
|
|
3225
|
-
export async function verifyConsole(workspaceDir) {
|
|
3662
|
+
export async function verifyConsole(workspaceDir, probePolicy = {}) {
|
|
3663
|
+
const policy = { ...DEFAULT_CONSOLE_READY_PROBE_POLICY, ...probePolicy };
|
|
3226
3664
|
const consoleDest = getInstalledConsoleDir();
|
|
3227
3665
|
const serverEntry = path.join(consoleDest, 'dist', 'server.js');
|
|
3228
3666
|
if (!existsSync(serverEntry)) {
|
|
@@ -3281,69 +3719,20 @@ export async function verifyConsole(workspaceDir) {
|
|
|
3281
3719
|
if (childStderr.length < 4000)
|
|
3282
3720
|
childStderr += chunk.toString();
|
|
3283
3721
|
});
|
|
3284
|
-
|
|
3285
|
-
if (
|
|
3722
|
+
const readiness = await probeConsoleReadiness({ port, nonce, policy, hasChildExited: () => childExited });
|
|
3723
|
+
if (readiness.kind === 'exited') {
|
|
3286
3724
|
delete process.env.PD_CONSOLE_VERIFY_NONCE;
|
|
3287
3725
|
attempts.push({ port, pid: child.pid ?? null, outcome: 'child_exited_early', exitCode: childExitCode, signal: childExitSignal, stderrTail: childStderr.slice(-300) });
|
|
3288
3726
|
continue; // Try next port
|
|
3289
3727
|
}
|
|
3290
3728
|
const healthUrl = new URL('/api/health', `http://127.0.0.1:${port}`);
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
const chunks = [];
|
|
3299
|
-
res.on('data', (chunk) => chunks.push(chunk));
|
|
3300
|
-
res.on('end', () => {
|
|
3301
|
-
resolve({ statusCode: res.statusCode ?? 0, body: Buffer.concat(chunks).toString() });
|
|
3302
|
-
});
|
|
3303
|
-
});
|
|
3304
|
-
req.on('error', reject);
|
|
3305
|
-
req.setTimeout(CONSOLE_HEALTH_CHECK_TIMEOUT_MS, () => { req.destroy(); reject(new Error('health check timeout')); });
|
|
3306
|
-
});
|
|
3307
|
-
httpStatus = result.statusCode;
|
|
3308
|
-
if (result.statusCode !== 200) {
|
|
3309
|
-
// SPEC v1.2 §14: a 502 (or any non-200) is recorded as an observed
|
|
3310
|
-
// fact with UNKNOWN attribution — we do NOT guess whether the
|
|
3311
|
-
// responder was PD, a proxy, or another local service (PRI-1069).
|
|
3312
|
-
reason = `Console /api/health returned HTTP ${result.statusCode} (expected 200); responder identity unknown`;
|
|
3313
|
-
reasonKind = 'http_error_status';
|
|
3314
|
-
}
|
|
3315
|
-
else if (!result.body || result.body.trim().length === 0) {
|
|
3316
|
-
reason = 'Console /api/health returned empty body';
|
|
3317
|
-
reasonKind = 'bad_body';
|
|
3318
|
-
}
|
|
3319
|
-
else {
|
|
3320
|
-
try {
|
|
3321
|
-
const parsed = JSON.parse(result.body);
|
|
3322
|
-
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
3323
|
-
reason = 'Console /api/health returned non-object JSON';
|
|
3324
|
-
reasonKind = 'bad_body';
|
|
3325
|
-
}
|
|
3326
|
-
else if (!isVerifiedConsoleIdentity(parsed, nonce)) {
|
|
3327
|
-
// P0-1 fail-closed: a 200 JSON object that cannot echo THIS
|
|
3328
|
-
// attempt's nonce is some other responder (old console, foreign
|
|
3329
|
-
// local service, proxy) — never "verified".
|
|
3330
|
-
reason = 'Health responder did not prove this launch instance (nonce/shape mismatch) — rejected';
|
|
3331
|
-
reasonKind = 'identity_mismatch';
|
|
3332
|
-
}
|
|
3333
|
-
else {
|
|
3334
|
-
ok = true;
|
|
3335
|
-
}
|
|
3336
|
-
}
|
|
3337
|
-
catch {
|
|
3338
|
-
reason = 'Console /api/health returned malformed JSON';
|
|
3339
|
-
reasonKind = 'bad_body';
|
|
3340
|
-
}
|
|
3341
|
-
}
|
|
3342
|
-
}
|
|
3343
|
-
catch (e) {
|
|
3344
|
-
reason = `Console health check failed on port ${port}: ${e instanceof Error ? e.message : String(e)}. Stderr: ${childStderr.slice(-300)}`;
|
|
3345
|
-
reasonKind = 'request_error';
|
|
3346
|
-
}
|
|
3729
|
+
const { probe } = readiness;
|
|
3730
|
+
const ok = probe.responded && probe.ok;
|
|
3731
|
+
const { reasonKind } = probe;
|
|
3732
|
+
const httpStatus = probe.responded ? probe.httpStatus : undefined;
|
|
3733
|
+
// A never-ready child keeps the historical diagnostic: the last transport
|
|
3734
|
+
// error plus the child's stderr tail.
|
|
3735
|
+
const reason = probe.responded ? probe.reason : `${probe.reason}. Stderr: ${childStderr.slice(-300)}`;
|
|
3347
3736
|
if (!ok) {
|
|
3348
3737
|
// P0-2: bounded terminate + REAL exit join before moving on; the child
|
|
3349
3738
|
// may hold native-module handles inside the runtime tree a later
|
|
@@ -3462,7 +3851,7 @@ async function probeAutolaunchHealth(port, timeoutMs = 1500) {
|
|
|
3462
3851
|
* the task project path. Other hosts keep the project workspace.
|
|
3463
3852
|
*/
|
|
3464
3853
|
export function resolveConsoleWorkspaceDir(host, projectWorkspaceDir, homeDir) {
|
|
3465
|
-
return host === 'workbuddy' ? getWorkbuddyWorkspaceDir(homeDir) : projectWorkspaceDir;
|
|
3854
|
+
return host === 'workbuddy' ? getWorkbuddyWorkspaceDir(homeDir, process.env.WORKBUDDY_CONFIG_DIR) : projectWorkspaceDir;
|
|
3466
3855
|
}
|
|
3467
3856
|
async function autoLaunchConsole(workspaceDir) {
|
|
3468
3857
|
const manualOpenCommand = `pd console open --workspace "${workspaceDir}"`;
|
|
@@ -3790,6 +4179,20 @@ export async function ensureOpenClawWorkspaceDeclaration(workspaceDir, channels)
|
|
|
3790
4179
|
await fse.writeJson(inspection.configPath, config, { spaces: 2 });
|
|
3791
4180
|
return { configPath: inspection.configPath, action: 'created' };
|
|
3792
4181
|
}
|
|
4182
|
+
/**
|
|
4183
|
+
* Collect every non-empty `warnings` array from the hosts this run touched —
|
|
4184
|
+
* the requested host AND the sibling refresh results. The refresh set matters:
|
|
4185
|
+
* it is exactly the path that used to leave WorkBuddy silently un-rebound.
|
|
4186
|
+
*/
|
|
4187
|
+
export function collectHostWarnings(results) {
|
|
4188
|
+
const records = [];
|
|
4189
|
+
for (const result of results) {
|
|
4190
|
+
const warnings = (result.warnings ?? []).filter((warning) => warning.trim().length > 0);
|
|
4191
|
+
if (warnings.length > 0)
|
|
4192
|
+
records.push({ hostId: result.hostId, warnings });
|
|
4193
|
+
}
|
|
4194
|
+
return records;
|
|
4195
|
+
}
|
|
3793
4196
|
/**
|
|
3794
4197
|
* Marketplace contract (2026-11-07): partition host installer results into
|
|
3795
4198
|
* REAL failures and pending MANUAL actions (e.g. the Codex Marketplace
|
|
@@ -3828,7 +4231,7 @@ export function partitionHostInstallResults(results) {
|
|
|
3828
4231
|
*/
|
|
3829
4232
|
export function summarizeTouchedHosts(results, deps = {}) {
|
|
3830
4233
|
const canonical = readCanonicalRuntimeCohort(deps.canonicalRuntimeDir ?? getPdRuntimeDir());
|
|
3831
|
-
const codexHome =
|
|
4234
|
+
const codexHome = getCodexHomeDir();
|
|
3832
4235
|
// `resolvePluginDataRoot` returns the PLUGIN DATA ROOT; the installed cohort
|
|
3833
4236
|
// lives one level below it in `runtime/`. Appending `node_modules` to the
|
|
3834
4237
|
// root read a directory that never exists, so an install that had just
|
|
@@ -3865,19 +4268,83 @@ export function summarizeTouchedHosts(results, deps = {}) {
|
|
|
3865
4268
|
* when the operator did not explicitly choose one. Under `--host all` the
|
|
3866
4269
|
* shared context carries the OpenClaw workspace, so Codex resolves its OWN
|
|
3867
4270
|
* default here (an explicit --workspace still wins for every host).
|
|
4271
|
+
*
|
|
4272
|
+
* PRI-1247 reopen: "explicit wins" was itself the incident vector — a generic
|
|
4273
|
+
* non-interactive install can pass the OpenClaw DETECTION result (env
|
|
4274
|
+
* PD_WORKSPACE_DIR → a formally declared OpenClaw workspace) as an explicit
|
|
4275
|
+
* --workspace. An explicit workspace another host OWNS (default tree, formal
|
|
4276
|
+
* `principles-disciple.json` declaration, or payload binding) is never
|
|
4277
|
+
* selected for Codex: Codex falls back to its OWN workspace and the caller
|
|
4278
|
+
* surfaces the structured note. A custom workspace owned by nobody stays
|
|
4279
|
+
* legal.
|
|
3868
4280
|
*/
|
|
3869
|
-
function resolveCodexHostWorkspace(options) {
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
|
|
3875
|
-
}
|
|
3876
|
-
|
|
4281
|
+
function resolveCodexHostWorkspace(options, notes = []) {
|
|
4282
|
+
const explicit = path.resolve(options.workspaceDir);
|
|
4283
|
+
// Directory SOURCES are the #2699 PD-Home authority (resolvePdHome — the
|
|
4284
|
+
// same HOME-first resolver every other consumer uses). This check adds
|
|
4285
|
+
// ownership VERDICT semantics (declarations, payload bindings, canonical
|
|
4286
|
+
// identity, multi-owner report), never a second layout source.
|
|
4287
|
+
const homePaths = resolvePdHome({ env: { ...process.env } });
|
|
4288
|
+
if (!homePaths.ok) {
|
|
4289
|
+
throw new Error(`PD home resolution refused (${homePaths.reason}): ${homePaths.message} Next action: ${homePaths.nextAction}`);
|
|
4290
|
+
}
|
|
4291
|
+
const foreign = findForeignWorkspaceOwner('codex', explicit, {
|
|
4292
|
+
homeDir: homePaths.homeDir,
|
|
4293
|
+
codexHome: homePaths.codexHome,
|
|
4294
|
+
openclawHome: homePaths.openclawHome,
|
|
4295
|
+
platform: process.platform,
|
|
4296
|
+
});
|
|
4297
|
+
if (foreign.owners.length === 0)
|
|
4298
|
+
return explicit;
|
|
4299
|
+
const own = detectWorkspace({ host: 'codex' }).detectedPath;
|
|
4300
|
+
notes.push(`workspace "${explicit}" is ${foreign.owners.join('+')}'s ${foreign.via === 'host_declaration' ? 'declared' : 'owned'} PD workspace; Codex uses its own "${own}" instead (PRI-1247)`);
|
|
4301
|
+
return own;
|
|
4302
|
+
}
|
|
4303
|
+
/**
|
|
4304
|
+
* PRI-1247 review round (2026-11-18): redirect detection and workspace
|
|
4305
|
+
* MATERIALIZATION are one decision — every Codex default this installer
|
|
4306
|
+
* selects on the user's behalf must EXIST before the binding is written (the
|
|
4307
|
+
* launcher refuses `binding_workspace_missing`, and the installer's own
|
|
4308
|
+
* binding health check would then report a manual-action failure). The old
|
|
4309
|
+
* inline condition covered only `--host all` non-explicit; an explicit
|
|
4310
|
+
* install run against another host's workspace redirects to Codex's own
|
|
4311
|
+
* default too, and that target may not exist yet. The user's EXPLICIT
|
|
4312
|
+
* non-foreign workspace is never created here — it is theirs.
|
|
4313
|
+
*
|
|
4314
|
+
* Injected `ensureDir`/`resolve` keep this honestly unit-testable without
|
|
4315
|
+
* driving the whole install flow.
|
|
4316
|
+
*/
|
|
4317
|
+
export async function materializeCodexWorkspace(options, io) {
|
|
4318
|
+
const notes = [];
|
|
4319
|
+
const codexWorkspaceDir = io.resolve(options, notes);
|
|
4320
|
+
for (const note of notes) {
|
|
4321
|
+
io.warn(`[codex] ${note}`);
|
|
4322
|
+
}
|
|
4323
|
+
const redirected = codexWorkspaceDir !== path.resolve(options.workspaceDir);
|
|
4324
|
+
if (redirected) {
|
|
4325
|
+
await io.ensureDir(codexWorkspaceDir);
|
|
4326
|
+
}
|
|
4327
|
+
return { codexWorkspaceDir, redirected };
|
|
4328
|
+
}
|
|
4329
|
+
export async function runHostInstallers(host, ctx, overrides = {}) {
|
|
3877
4330
|
const installers = getHostInstallers(host);
|
|
3878
4331
|
const results = [];
|
|
3879
4332
|
for (const installer of installers) {
|
|
3880
4333
|
try {
|
|
4334
|
+
// A failed Codex workspace materialization is Codex's own install or
|
|
4335
|
+
// refresh failure — never the whole transaction's (review 2026-11-18):
|
|
4336
|
+
// installing anyway would bind the explicit workspace the redirect just
|
|
4337
|
+
// refused as foreign, or a path that does not exist.
|
|
4338
|
+
if (installer.hostId === 'codex' && overrides.codexWorkspaceError !== undefined) {
|
|
4339
|
+
results.push({
|
|
4340
|
+
success: false,
|
|
4341
|
+
hostId: installer.hostId,
|
|
4342
|
+
configAction: 'skipped',
|
|
4343
|
+
reason: `Workspace materialization failed: ${overrides.codexWorkspaceError}`,
|
|
4344
|
+
nextAction: 'Make the Codex workspace parent writable (or point CODEX_HOME at a writable directory), then re-run: npx create-principles-disciple install --host codex',
|
|
4345
|
+
});
|
|
4346
|
+
continue;
|
|
4347
|
+
}
|
|
3881
4348
|
const installerCtx = installer.hostId === 'codex' && overrides.codexWorkspaceDir !== undefined
|
|
3882
4349
|
? { ...ctx, workspaceDir: overrides.codexWorkspaceDir }
|
|
3883
4350
|
: ctx;
|
|
@@ -4221,6 +4688,9 @@ transaction) {
|
|
|
4221
4688
|
// finally block can attach the gateway restart notice to the SAME object
|
|
4222
4689
|
// the caller receives (a finally block cannot rewrite an inline return).
|
|
4223
4690
|
let pendingResult;
|
|
4691
|
+
// §8.5: legacy backup-migration failures ride the structured InstallResult
|
|
4692
|
+
// (--json silences logger.warn; a degrade must never become invisible).
|
|
4693
|
+
let legacyBackupMigrationFailures;
|
|
4224
4694
|
// P0-2: bounded terminate + exit join over EVERY probe child we still own
|
|
4225
4695
|
// (the verified child plus any earlier unconfirmed ones). The aggregated
|
|
4226
4696
|
// join result decides whether destructive directory operations may proceed
|
|
@@ -4344,8 +4814,26 @@ transaction) {
|
|
|
4344
4814
|
for (const detectedHost of hostPlan.newlyCovered) {
|
|
4345
4815
|
logger.info(`Detected installed host "${detectedHost.hostId}" (${detectedHost.evidence}) — included in this upgrade.`);
|
|
4346
4816
|
}
|
|
4347
|
-
if (installsOpenClaw(options.host))
|
|
4348
|
-
migrateLegacyPdBackups();
|
|
4817
|
+
if (installsOpenClaw(options.host)) {
|
|
4818
|
+
const migration = migrateLegacyPdBackups();
|
|
4819
|
+
reportLegacyBackupMigration(migration, getPdBackupsDir());
|
|
4820
|
+
// §8.5: migration failures ride the structured InstallResult — `--json`
|
|
4821
|
+
// silences logger.warn, so this field is the only durable copy of WHAT
|
|
4822
|
+
// stayed behind, WHERE it is, and WHAT to do next (rc-9). Non-fatal:
|
|
4823
|
+
// `success` is unaffected.
|
|
4824
|
+
if (migration.failed.length > 0) {
|
|
4825
|
+
legacyBackupMigrationFailures = migration.failed.map((failure) => ({
|
|
4826
|
+
name: failure.name,
|
|
4827
|
+
// The ACTUAL preserved-in-place path, captured at the failure site
|
|
4828
|
+
// (the legacy root itself, one of its entries, or an extensions
|
|
4829
|
+
// sibling) — synthesizing it from the name pointed JSON consumers at
|
|
4830
|
+
// the wrong original (Devin Round 4 #4).
|
|
4831
|
+
source: failure.source,
|
|
4832
|
+
reason: failure.reason,
|
|
4833
|
+
nextAction: `The original was preserved in place. Inspect it and move it into ${getPdBackupsDir()} manually when safe.`,
|
|
4834
|
+
}));
|
|
4835
|
+
}
|
|
4836
|
+
}
|
|
4349
4837
|
const { backupDir: backupDirFromResult, runtimeBackupDir: runtimeBackupDirFromResult } = backupExistingInstall(options.host);
|
|
4350
4838
|
backupDir = backupDirFromResult;
|
|
4351
4839
|
runtimeBackupDir = runtimeBackupDirFromResult ?? null;
|
|
@@ -4627,13 +5115,34 @@ transaction) {
|
|
|
4627
5115
|
: undefined,
|
|
4628
5116
|
};
|
|
4629
5117
|
// The Codex binding needs its workspace to exist (the launcher refuses a
|
|
4630
|
-
// binding_workspace_missing).
|
|
4631
|
-
//
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
5118
|
+
// binding_workspace_missing). PRI-1247: under `--host all` this is the
|
|
5119
|
+
// host's own default; the review round extends materialization to the
|
|
5120
|
+
// redirect target of an explicit install run against another host's
|
|
5121
|
+
// workspace (the old condition only covered `--host all` non-explicit).
|
|
5122
|
+
// Review (2026-11-18): materialize ONLY when this run serves Codex —
|
|
5123
|
+
// the requested target or a persisted Codex sibling being refreshed.
|
|
5124
|
+
// Any other run never needed a Codex workspace, and an unwritable
|
|
5125
|
+
// CODEX_HOME must not roll back hosts the operator actually asked for.
|
|
5126
|
+
// A materialize failure is therefore attributed to Codex's own
|
|
5127
|
+
// install/refresh result below, keeping the other hosts' error
|
|
5128
|
+
// isolation intact.
|
|
5129
|
+
let codexWorkspaceDir;
|
|
5130
|
+
let codexWorkspaceError;
|
|
5131
|
+
if (installRunServesCodex(options.host, hostPlan.refreshTargets)) {
|
|
5132
|
+
try {
|
|
5133
|
+
const materialized = await materializeCodexWorkspace(options, {
|
|
5134
|
+
resolve: (target, notes) => resolveCodexHostWorkspace(options, notes),
|
|
5135
|
+
ensureDir: (dir) => fse.ensureDir(dir),
|
|
5136
|
+
warn: (message) => logger.warn(message),
|
|
5137
|
+
});
|
|
5138
|
+
({ codexWorkspaceDir } = materialized);
|
|
5139
|
+
}
|
|
5140
|
+
catch (error) {
|
|
5141
|
+
codexWorkspaceError = error instanceof Error ? error.message : String(error);
|
|
5142
|
+
logger.warn(`Host "codex" workspace materialization failed: ${codexWorkspaceError}`);
|
|
5143
|
+
}
|
|
4635
5144
|
}
|
|
4636
|
-
const hostResults = await runHostInstallers(options.host, hostInstallCtx, { codexWorkspaceDir });
|
|
5145
|
+
const hostResults = await runHostInstallers(options.host, hostInstallCtx, { codexWorkspaceDir, codexWorkspaceError });
|
|
4637
5146
|
// Report host install results (rc-9: surface failures, don't silently swallow).
|
|
4638
5147
|
// rc-9 propagation: if ANY host installer FAILED, the aggregate install
|
|
4639
5148
|
// result is NOT successful — callers (CLI, tests) must see the failure.
|
|
@@ -4654,6 +5163,13 @@ transaction) {
|
|
|
4654
5163
|
for (const msg of hostFailureMessages) {
|
|
4655
5164
|
logger.warn(msg);
|
|
4656
5165
|
}
|
|
5166
|
+
// PRI-1249: a host that installed but had to work around something the
|
|
5167
|
+
// Owner should know (e.g. an unverifiable same-name MCP entry PD refused
|
|
5168
|
+
// to touch) must not be silent — the workaround is reported, never hidden.
|
|
5169
|
+
for (const hr of hostResults) {
|
|
5170
|
+
for (const warning of hr.warnings ?? [])
|
|
5171
|
+
logger.warn(`Host "${hr.hostId}": ${warning}`);
|
|
5172
|
+
}
|
|
4657
5173
|
for (const hr of hostResults) {
|
|
4658
5174
|
if (hr.success && hr.configAction === 'skipped') {
|
|
4659
5175
|
logger.info(`Host "${hr.hostId}" install: ${hr.reason ?? 'skipped'}. Next: ${hr.nextAction}`);
|
|
@@ -4673,11 +5189,16 @@ transaction) {
|
|
|
4673
5189
|
for (const refreshTarget of refreshTargets) {
|
|
4674
5190
|
if (spinner)
|
|
4675
5191
|
updateProgress(spinner, stepIndex, `Refreshing ${refreshTarget} host binding...`);
|
|
4676
|
-
const refreshResults = await runHostInstallers(refreshTarget, hostInstallCtx, { codexWorkspaceDir });
|
|
5192
|
+
const refreshResults = await runHostInstallers(refreshTarget, hostInstallCtx, { codexWorkspaceDir, codexWorkspaceError });
|
|
4677
5193
|
refreshedResults.push(...refreshResults);
|
|
4678
5194
|
for (const hr of refreshResults) {
|
|
4679
5195
|
if (hr.success) {
|
|
4680
5196
|
logger.info(`Host "${hr.hostId}" refresh: ${hr.configAction === 'updated' ? 'updated' : 'no change needed'}${hr.reason ? ` — ${hr.reason}` : ''}.`);
|
|
5197
|
+
// PRI-1249: the sibling refresh is exactly the path that silently
|
|
5198
|
+
// skipped WorkBuddy's re-bind before this fix — its warnings must be
|
|
5199
|
+
// as visible as a first install's.
|
|
5200
|
+
for (const warning of hr.warnings ?? [])
|
|
5201
|
+
logger.warn(`Host "${hr.hostId}": ${warning}`);
|
|
4681
5202
|
}
|
|
4682
5203
|
else {
|
|
4683
5204
|
// rc-9: never silent — state the reason and the exact recovery step.
|
|
@@ -4689,6 +5210,10 @@ transaction) {
|
|
|
4689
5210
|
// First installs and upgrades share it, so an already-installed host being
|
|
4690
5211
|
// brought forward can never be silent (Owner report).
|
|
4691
5212
|
const hostSummary = summarizeTouchedHosts([...hostResults, ...refreshedResults]);
|
|
5213
|
+
// PRI-1249: the warnings of BOTH sets travel with the result — `--json`
|
|
5214
|
+
// silences logger.warn, so without this a successful install that had to
|
|
5215
|
+
// work around a host condition reports success with no trace of it.
|
|
5216
|
+
const hostWarnings = collectHostWarnings([...hostResults, ...refreshedResults]);
|
|
4692
5217
|
if (hostSummary.length > 0) {
|
|
4693
5218
|
logger.info('Install summary:');
|
|
4694
5219
|
for (const line of hostSummary)
|
|
@@ -4885,8 +5410,10 @@ transaction) {
|
|
|
4885
5410
|
nextAction: nextActions.join(' | '),
|
|
4886
5411
|
consoleUrl: launchResult.consoleUrl,
|
|
4887
5412
|
hostResults,
|
|
5413
|
+
...(hostWarnings.length > 0 ? { hostWarnings } : {}),
|
|
4888
5414
|
hostSummary,
|
|
4889
5415
|
...(compatibilityVisibility.lines.length > 0 ? { compatibilityWarnings: compatibilityVisibility.lines } : {}),
|
|
5416
|
+
...(legacyBackupMigrationFailures !== undefined ? { legacyBackupMigrationFailures } : {}),
|
|
4890
5417
|
...(manualActionReason !== undefined ? { reason: manualActionReason, manualActions: hostManualActions } : {}),
|
|
4891
5418
|
journal: installerJournalRecord(journal),
|
|
4892
5419
|
};
|