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.
Files changed (293) hide show
  1. package/_release/product-identity.json +1 -1
  2. package/codex-adapter/dist/ingestion/codex-home.d.ts +1 -0
  3. package/codex-adapter/dist/ingestion/codex-home.js +19 -7
  4. package/codex-adapter/dist/ingestion/ingestion.js +34 -7
  5. package/codex-adapter/dist/pd-hook.js +14 -6
  6. package/codex-adapter/dist/worker/workspace-worker.js +31 -1
  7. package/codex-adapter/package.json +1 -1
  8. package/console/dist/server/index.js +5 -16
  9. package/console/dist/server/utils/installed-layout.js +6 -4
  10. package/console/dist/server/utils/pd-backups.d.ts +1 -14
  11. package/console/dist/server/utils/pd-backups.js +12 -64
  12. package/console/dist/web/assets/app.css +67 -9
  13. package/console/dist/web/assets/app.js +37 -37
  14. package/console/dist/web/assets/providers/anthropic.png +0 -0
  15. package/console/dist/web/assets/providers/deepseek.png +0 -0
  16. package/console/dist/web/assets/providers/google.png +0 -0
  17. package/console/dist/web/assets/providers/groq.svg +1 -0
  18. package/console/dist/web/assets/providers/kimi.png +0 -0
  19. package/console/dist/web/assets/providers/minimax.png +0 -0
  20. package/console/dist/web/assets/providers/mistral.svg +28 -0
  21. package/console/dist/web/assets/providers/nvidia.png +0 -0
  22. package/console/dist/web/assets/providers/openai.svg +1 -0
  23. package/console/dist/web/assets/providers/openrouter.svg +3 -0
  24. package/console/dist/web/assets/providers/qwen.png +0 -0
  25. package/console/dist/web/assets/providers/together.svg +21 -0
  26. package/console/dist/web/assets/providers/xai.svg +1 -0
  27. package/console/dist/web/assets/providers/xiaomi.png +0 -0
  28. package/console/dist/web/assets/providers/zai.svg +219 -0
  29. package/core/dist/index.d.ts +1 -2
  30. package/core/dist/index.d.ts.map +1 -1
  31. package/core/dist/index.js +4 -2
  32. package/core/dist/index.js.map +1 -1
  33. package/core/dist/prompt-builder/focus-compression.d.ts +8 -60
  34. package/core/dist/prompt-builder/focus-compression.d.ts.map +1 -1
  35. package/core/dist/prompt-builder/focus-compression.js +8 -434
  36. package/core/dist/prompt-builder/focus-compression.js.map +1 -1
  37. package/core/dist/prompt-builder/index.d.ts +1 -2
  38. package/core/dist/prompt-builder/index.d.ts.map +1 -1
  39. package/core/dist/prompt-builder/index.js +3 -2
  40. package/core/dist/prompt-builder/index.js.map +1 -1
  41. package/core/dist/runtime/activation/production-gate-deps.d.ts +7 -3
  42. package/core/dist/runtime/activation/production-gate-deps.d.ts.map +1 -1
  43. package/core/dist/runtime/activation/production-gate-deps.js +15 -6
  44. package/core/dist/runtime/activation/production-gate-deps.js.map +1 -1
  45. package/core/dist/runtime/adapter/principle-tree-ledger-adapter.d.ts +2 -0
  46. package/core/dist/runtime/adapter/principle-tree-ledger-adapter.d.ts.map +1 -1
  47. package/core/dist/runtime/adapter/principle-tree-ledger-adapter.js +9 -1
  48. package/core/dist/runtime/adapter/principle-tree-ledger-adapter.js.map +1 -1
  49. package/core/dist/runtime/config/pd-config-types.d.ts +20 -1
  50. package/core/dist/runtime/config/pd-config-types.d.ts.map +1 -1
  51. package/core/dist/runtime/config/pd-config-types.js.map +1 -1
  52. package/core/dist/runtime/config/pd-config-validate.d.ts.map +1 -1
  53. package/core/dist/runtime/config/pd-config-validate.js +12 -1
  54. package/core/dist/runtime/config/pd-config-validate.js.map +1 -1
  55. package/core/dist/runtime/internalization/bash-risk.d.ts.map +1 -1
  56. package/core/dist/runtime/internalization/bash-risk.js +6 -3
  57. package/core/dist/runtime/internalization/bash-risk.js.map +1 -1
  58. package/core/dist/runtime/internalization/internalization-orchestrator.d.ts +28 -1
  59. package/core/dist/runtime/internalization/internalization-orchestrator.d.ts.map +1 -1
  60. package/core/dist/runtime/internalization/internalization-orchestrator.js +109 -13
  61. package/core/dist/runtime/internalization/internalization-orchestrator.js.map +1 -1
  62. package/core/dist/runtime/internalization/split-diagnostician-runner.d.ts +10 -0
  63. package/core/dist/runtime/internalization/split-diagnostician-runner.d.ts.map +1 -1
  64. package/core/dist/runtime/internalization/split-diagnostician-runner.js +6 -1
  65. package/core/dist/runtime/internalization/split-diagnostician-runner.js.map +1 -1
  66. package/core/dist/runtime/pain-chain-read-model.d.ts +14 -0
  67. package/core/dist/runtime/pain-chain-read-model.d.ts.map +1 -1
  68. package/core/dist/runtime/pain-chain-read-model.js +91 -3
  69. package/core/dist/runtime/pain-chain-read-model.js.map +1 -1
  70. package/core/dist/runtime/pain-ingress-payload.d.ts +15 -0
  71. package/core/dist/runtime/pain-ingress-payload.d.ts.map +1 -1
  72. package/core/dist/runtime/pain-ingress-payload.js +32 -3
  73. package/core/dist/runtime/pain-ingress-payload.js.map +1 -1
  74. package/core/dist/runtime/pain-signal-bridge.d.ts +8 -0
  75. package/core/dist/runtime/pain-signal-bridge.d.ts.map +1 -1
  76. package/core/dist/runtime/pain-signal-bridge.js +11 -0
  77. package/core/dist/runtime/pain-signal-bridge.js.map +1 -1
  78. package/core/dist/runtime/pain-signal-runtime-factory.d.ts.map +1 -1
  79. package/core/dist/runtime/pain-signal-runtime-factory.js +3 -0
  80. package/core/dist/runtime/pain-signal-runtime-factory.js.map +1 -1
  81. package/core/dist/runtime/pain-submit-capability.d.ts +54 -0
  82. package/core/dist/runtime/pain-submit-capability.d.ts.map +1 -1
  83. package/core/dist/runtime/pain-submit-capability.js +49 -1
  84. package/core/dist/runtime/pain-submit-capability.js.map +1 -1
  85. package/core/dist/runtime/storage-paths.d.ts +9 -10
  86. package/core/dist/runtime/storage-paths.d.ts.map +1 -1
  87. package/core/dist/runtime/storage-paths.js +9 -10
  88. package/core/dist/runtime/storage-paths.js.map +1 -1
  89. package/core/dist/runtime/store/context/sqlite-context-assembler.d.ts.map +1 -1
  90. package/core/dist/runtime/store/context/sqlite-context-assembler.js +10 -2
  91. package/core/dist/runtime/store/context/sqlite-context-assembler.js.map +1 -1
  92. package/core/dist/runtime/store/storage-paths.d.ts +65 -12
  93. package/core/dist/runtime/store/storage-paths.d.ts.map +1 -1
  94. package/core/dist/runtime/store/storage-paths.js +92 -39
  95. package/core/dist/runtime/store/storage-paths.js.map +1 -1
  96. package/core/package.json +1 -1
  97. package/dist/installer.d.ts +113 -9
  98. package/dist/installer.d.ts.map +1 -1
  99. package/dist/installer.js +596 -100
  100. package/dist/installer.js.map +1 -1
  101. package/dist/installers/codex-host-installer.d.ts +23 -3
  102. package/dist/installers/codex-host-installer.d.ts.map +1 -1
  103. package/dist/installers/codex-host-installer.js +36 -20
  104. package/dist/installers/codex-host-installer.js.map +1 -1
  105. package/dist/installers/index.d.ts.map +1 -1
  106. package/dist/installers/index.js +24 -3
  107. package/dist/installers/index.js.map +1 -1
  108. package/dist/installers/mcp-registration-conflict.d.ts.map +1 -1
  109. package/dist/installers/mcp-registration-conflict.js +23 -16
  110. package/dist/installers/mcp-registration-conflict.js.map +1 -1
  111. package/dist/installers/openclaw-host-installer.d.ts.map +1 -1
  112. package/dist/installers/openclaw-host-installer.js +1 -8
  113. package/dist/installers/openclaw-host-installer.js.map +1 -1
  114. package/dist/installers/workbuddy-host-installer.js +7 -7
  115. package/dist/installers/workbuddy-host-installer.js.map +1 -1
  116. package/dist/mvp-config.d.ts +30 -5
  117. package/dist/mvp-config.d.ts.map +1 -1
  118. package/dist/mvp-config.js +49 -16
  119. package/dist/mvp-config.js.map +1 -1
  120. package/dist/prompts.js +1 -1
  121. package/dist/prompts.js.map +1 -1
  122. package/dist/uninstaller.d.ts.map +1 -1
  123. package/dist/uninstaller.js +142 -5
  124. package/dist/uninstaller.js.map +1 -1
  125. package/dist/update/release-manager.d.ts.map +1 -1
  126. package/dist/update/release-manager.js +5 -2
  127. package/dist/update/release-manager.js.map +1 -1
  128. package/dist/utils/env.d.ts +5 -10
  129. package/dist/utils/env.d.ts.map +1 -1
  130. package/dist/utils/env.js +91 -34
  131. package/dist/utils/env.js.map +1 -1
  132. package/dist/utils/host-workspace-ownership.d.ts +25 -0
  133. package/dist/utils/host-workspace-ownership.d.ts.map +1 -1
  134. package/dist/utils/host-workspace-ownership.js +153 -2
  135. package/dist/utils/host-workspace-ownership.js.map +1 -1
  136. package/host-runtime/dist/adaptive-background-append.d.ts +6 -0
  137. package/host-runtime/dist/adaptive-background-append.js +4 -1
  138. package/host-runtime/dist/adaptive-decision-protocol.d.ts +18 -2
  139. package/host-runtime/dist/adaptive-decision-protocol.js +39 -9
  140. package/host-runtime/dist/adaptive-principle-context-reader.d.ts +79 -0
  141. package/host-runtime/dist/adaptive-principle-context-reader.js +303 -0
  142. package/host-runtime/dist/adaptive-priority-provider.d.ts +33 -0
  143. package/host-runtime/dist/adaptive-priority-provider.js +68 -2
  144. package/host-runtime/dist/adaptive-selection.d.ts +16 -0
  145. package/host-runtime/dist/adaptive-selection.js +23 -1
  146. package/host-runtime/dist/codex-legacy-registration.js +10 -2
  147. package/host-runtime/dist/conversation-ingestion/pipeline.d.ts +8 -0
  148. package/host-runtime/dist/conversation-ingestion/pipeline.js +179 -7
  149. package/host-runtime/dist/degraded-enforcement-marker.js +16 -2
  150. package/host-runtime/dist/diagnostician-auto-run.js +4 -0
  151. package/host-runtime/dist/governance-observation-store.d.ts +44 -0
  152. package/host-runtime/dist/governance-observation-store.js +84 -1
  153. package/host-runtime/dist/governance-trajectory-turn-reader.d.ts +30 -0
  154. package/host-runtime/dist/governance-trajectory-turn-reader.js +47 -0
  155. package/host-runtime/dist/index.d.ts +2 -0
  156. package/host-runtime/dist/index.js +6 -0
  157. package/host-runtime/dist/product-telemetry/service.js +86 -20
  158. package/host-runtime/package.json +1 -1
  159. package/install-layout/dist/index.d.ts +23 -9
  160. package/install-layout/dist/index.js +49 -24
  161. package/install-layout/dist/mcp-binding-contract.d.ts +62 -0
  162. package/install-layout/dist/mcp-binding-contract.js +175 -3
  163. package/install-layout/dist/pd-home.d.ts +35 -5
  164. package/install-layout/dist/pd-home.js +138 -23
  165. package/install-layout/package.json +1 -1
  166. package/package.json +4 -4
  167. package/pd-cli/dist/commands/candidate.d.ts.map +1 -1
  168. package/pd-cli/dist/commands/candidate.js +134 -8
  169. package/pd-cli/dist/commands/candidate.js.map +1 -1
  170. package/pd-cli/dist/commands/codex-worker.d.ts.map +1 -1
  171. package/pd-cli/dist/commands/codex-worker.js +36 -2
  172. package/pd-cli/dist/commands/codex-worker.js.map +1 -1
  173. package/pd-cli/dist/commands/diagnose.d.ts.map +1 -1
  174. package/pd-cli/dist/commands/diagnose.js +34 -8
  175. package/pd-cli/dist/commands/diagnose.js.map +1 -1
  176. package/pd-cli/dist/commands/health-codex-install.d.ts +1 -3
  177. package/pd-cli/dist/commands/health-codex-install.d.ts.map +1 -1
  178. package/pd-cli/dist/commands/health-codex-install.js +19 -6
  179. package/pd-cli/dist/commands/health-codex-install.js.map +1 -1
  180. package/pd-cli/dist/commands/health-codex.d.ts.map +1 -1
  181. package/pd-cli/dist/commands/health-codex.js +27 -9
  182. package/pd-cli/dist/commands/health-codex.js.map +1 -1
  183. package/pd-cli/dist/commands/health-console.d.ts +2 -1
  184. package/pd-cli/dist/commands/health-console.d.ts.map +1 -1
  185. package/pd-cli/dist/commands/health-console.js +12 -3
  186. package/pd-cli/dist/commands/health-console.js.map +1 -1
  187. package/pd-cli/dist/commands/health-ingestion.d.ts +10 -2
  188. package/pd-cli/dist/commands/health-ingestion.d.ts.map +1 -1
  189. package/pd-cli/dist/commands/health-ingestion.js +56 -14
  190. package/pd-cli/dist/commands/health-ingestion.js.map +1 -1
  191. package/pd-cli/dist/commands/health-mcp.d.ts +19 -7
  192. package/pd-cli/dist/commands/health-mcp.d.ts.map +1 -1
  193. package/pd-cli/dist/commands/health-mcp.js +131 -45
  194. package/pd-cli/dist/commands/health-mcp.js.map +1 -1
  195. package/pd-cli/dist/commands/health-workbuddy.d.ts +2 -1
  196. package/pd-cli/dist/commands/health-workbuddy.d.ts.map +1 -1
  197. package/pd-cli/dist/commands/health-workbuddy.js +17 -8
  198. package/pd-cli/dist/commands/health-workbuddy.js.map +1 -1
  199. package/pd-cli/dist/commands/health.d.ts.map +1 -1
  200. package/pd-cli/dist/commands/health.js +12 -5
  201. package/pd-cli/dist/commands/health.js.map +1 -1
  202. package/pd-cli/dist/commands/mcp-probe.d.ts +6 -0
  203. package/pd-cli/dist/commands/mcp-probe.d.ts.map +1 -1
  204. package/pd-cli/dist/commands/mcp-probe.js +35 -7
  205. package/pd-cli/dist/commands/mcp-probe.js.map +1 -1
  206. package/pd-cli/dist/commands/pain-retry.d.ts.map +1 -1
  207. package/pd-cli/dist/commands/pain-retry.js +10 -2
  208. package/pd-cli/dist/commands/pain-retry.js.map +1 -1
  209. package/pd-cli/dist/commands/trace.d.ts.map +1 -1
  210. package/pd-cli/dist/commands/trace.js +8 -0
  211. package/pd-cli/dist/commands/trace.js.map +1 -1
  212. package/pd-cli/dist/commands/workbuddy-setup.d.ts.map +1 -1
  213. package/pd-cli/dist/commands/workbuddy-setup.js +7 -3
  214. package/pd-cli/dist/commands/workbuddy-setup.js.map +1 -1
  215. package/pd-cli/dist/commands/workbuddy-worker.d.ts.map +1 -1
  216. package/pd-cli/dist/commands/workbuddy-worker.js +21 -6
  217. package/pd-cli/dist/commands/workbuddy-worker.js.map +1 -1
  218. package/pd-cli/dist/services/admission-write-gate.d.ts +10 -1
  219. package/pd-cli/dist/services/admission-write-gate.d.ts.map +1 -1
  220. package/pd-cli/dist/services/admission-write-gate.js +12 -2
  221. package/pd-cli/dist/services/admission-write-gate.js.map +1 -1
  222. package/pd-cli/dist/services/codex-plugin-install.d.ts +1 -3
  223. package/pd-cli/dist/services/codex-plugin-install.d.ts.map +1 -1
  224. package/pd-cli/dist/services/codex-plugin-install.js +10 -3
  225. package/pd-cli/dist/services/codex-plugin-install.js.map +1 -1
  226. package/pd-cli/dist/services/pain-flood-simulation-runner.d.ts.map +1 -1
  227. package/pd-cli/dist/services/pain-flood-simulation-runner.js +2 -0
  228. package/pd-cli/dist/services/pain-flood-simulation-runner.js.map +1 -1
  229. package/pd-cli/dist/services/pd-config-loader.d.ts +2 -2
  230. package/pd-cli/dist/services/pd-config-loader.d.ts.map +1 -1
  231. package/pd-cli/dist/services/pd-config-loader.js +28 -20
  232. package/pd-cli/dist/services/pd-config-loader.js.map +1 -1
  233. package/pd-cli/dist/services/synthetic-baseline-runner.d.ts.map +1 -1
  234. package/pd-cli/dist/services/synthetic-baseline-runner.js +2 -0
  235. package/pd-cli/dist/services/synthetic-baseline-runner.js.map +1 -1
  236. package/pd-cli/package.json +1 -1
  237. package/pd-mcp-server/dist/log-file.js +9 -2
  238. package/pd-mcp-server/dist/server.d.ts +52 -2
  239. package/pd-mcp-server/dist/server.js +40 -4
  240. package/pd-mcp-server/dist/submit-assembly.js +85 -12
  241. package/pd-mcp-server/dist/version.d.ts +1 -1
  242. package/pd-mcp-server/dist/version.js +1 -1
  243. package/pd-mcp-server/package.json +1 -1
  244. package/plugin/dist/bundle.js +761 -722
  245. package/plugin/dist/commands/focus.d.ts +10 -7
  246. package/plugin/dist/commands/strategy.d.ts +10 -0
  247. package/plugin/dist/core/focus-history.d.ts +9 -49
  248. package/plugin/dist/core/paths.d.ts +6 -53
  249. package/plugin/dist/governance-audit.js +2 -2
  250. package/plugin/dist/hooks/prompt-helpers.d.ts +6 -5
  251. package/plugin/dist/hooks/prompt-types.d.ts +6 -6
  252. package/plugin/dist/openclaw.plugin.json +1 -1
  253. package/plugin/dist/rulehost-evidence.js +29 -29
  254. package/plugin/dist/templates/workspace/okr/RECOVERY_PROTOCOL.md +8 -7
  255. package/plugin/dist/utils/io.d.ts +1 -1
  256. package/plugin/dist/utils/workspace-resolver.d.ts +0 -20
  257. package/plugin/mcp/launcher.cjs +159 -35
  258. package/plugin/openclaw.plugin.json +1 -1
  259. package/plugin/package.json +1 -1
  260. package/plugin/templates/workspace/okr/RECOVERY_PROTOCOL.md +8 -7
  261. package/release-manager/dist/installer.js +596 -100
  262. package/release-manager/dist/installers/codex-host-installer.js +36 -20
  263. package/release-manager/dist/installers/index.js +24 -3
  264. package/release-manager/dist/installers/mcp-registration-conflict.js +23 -16
  265. package/release-manager/dist/installers/openclaw-host-installer.js +1 -8
  266. package/release-manager/dist/installers/workbuddy-host-installer.js +7 -7
  267. package/release-manager/dist/mvp-config.js +49 -16
  268. package/release-manager/dist/update/release-manager.js +5 -2
  269. package/release-manager/dist/utils/env.js +91 -34
  270. package/release-manager/dist/utils/host-workspace-ownership.js +153 -2
  271. package/release-manager/package.json +2 -2
  272. package/workbuddy-adapter/dist/index.d.ts +1 -1
  273. package/workbuddy-adapter/dist/index.js +1 -1
  274. package/workbuddy-adapter/dist/ingestion/catch-up.js +15 -3
  275. package/workbuddy-adapter/dist/ingestion/index.d.ts +1 -1
  276. package/workbuddy-adapter/dist/ingestion/index.js +1 -1
  277. package/workbuddy-adapter/dist/ingestion/ingestion.d.ts +18 -0
  278. package/workbuddy-adapter/dist/ingestion/ingestion.js +20 -2
  279. package/workbuddy-adapter/dist/ingestion/transcript-path.d.ts +13 -4
  280. package/workbuddy-adapter/dist/ingestion/transcript-path.js +102 -4
  281. package/workbuddy-adapter/dist/ingestion/transcript-source.js +76 -58
  282. package/workbuddy-adapter/dist/pd-hook.js +10 -3
  283. package/workbuddy-adapter/dist/worker/workspace-worker.js +4 -1
  284. package/workbuddy-adapter/dist/workspace-resolution.d.ts +9 -2
  285. package/workbuddy-adapter/dist/workspace-resolution.js +19 -3
  286. package/workbuddy-adapter/package.json +1 -1
  287. package/workbuddy-adapter/plugin/mcp/launcher.cjs +159 -35
  288. package/plugin/dist/templates/workspace/okr/CURRENT_FOCUS.md +0 -56
  289. package/plugin/dist/templates/workspace/okr/TASK_CHANGES.jsonl +0 -6
  290. package/plugin/dist/templates/workspace/okr/WEEK_TASKS.json +0 -6
  291. package/plugin/templates/workspace/okr/CURRENT_FOCUS.md +0 -56
  292. package/plugin/templates/workspace/okr/TASK_CHANGES.jsonl +0 -6
  293. package/plugin/templates/workspace/okr/WEEK_TASKS.json +0 -6
@@ -26,13 +26,12 @@
26
26
  import { existsSync, readdirSync, readFileSync, statSync, writeFileSync } from 'fs';
27
27
  import { execSync, spawnSync } from 'child_process';
28
28
  import * as path from 'path';
29
- import * as os from 'os';
30
29
  import { createRequire } from 'module';
31
30
  import { pathToFileURL } from 'url';
32
31
  import { isNpmDependencyResolutionEnabled } from '../installer.js';
33
32
  import { isSameMcpBindingPath, validateMcpBinding, } from '@principles/install-layout';
34
- import { findForeignWorkspaceHost } from '../utils/host-workspace-ownership.js';
35
- import { getPdRuntimeDir } from '../mvp-config.js';
33
+ import { findForeignWorkspaceOwner } from '../utils/host-workspace-ownership.js';
34
+ import { getCodexHomeDir, getHomeDir, getOpenClawDir, getPdDir, getPdRuntimeDir } from '../mvp-config.js';
36
35
  // NOTE (PRI-625 review round 3 / PRI-669 gate): this installer ships as the
37
36
  // self-contained npx package — @principles/core is NOT in its dependencies,
38
37
  // and type-only imports are erased at compile time, so the import above is
@@ -64,18 +63,14 @@ function getErrorCode(err) {
64
63
  }
65
64
  // ─── Path helpers ───────────────────────────────────────────────────────────
66
65
  function getCodexDir() {
67
- // Shared authority for Marketplace observation and the legacy hook detector.
68
- // Codex accepts relative CODEX_HOME; path.resolve matches pd-cli's reader.
69
- const override = process.env.CODEX_HOME;
70
- return typeof override === 'string' && override.length > 0
71
- ? path.resolve(override)
72
- : path.join(os.homedir(), '.codex');
66
+ // Shared PD Home authority for Marketplace observation and legacy hook detection.
67
+ return getCodexHomeDir();
73
68
  }
74
69
  function getCodexHooksJsonPath() {
75
70
  return path.join(getCodexDir(), 'hooks.json');
76
71
  }
77
72
  function getPdCodexDir() {
78
- return path.join(os.homedir(), '.pd', 'codex');
73
+ return path.join(getPdDir(), 'codex');
79
74
  }
80
75
  function getPdHookMarkerPath() {
81
76
  return path.join(getPdCodexDir(), PD_HOOK_MARKER);
@@ -542,14 +537,19 @@ function isMcpBindingHealthy(input) {
542
537
  const verdict = validateMcpBinding(binding, 'codex', process.platform);
543
538
  if (!verdict.ok)
544
539
  return false;
545
- // PRI-1247: an existing, readable workspace that belongs to ANOTHER PD host
546
- // is a cross-host misbinding, not a healthy binding. Treat it as repair-needed
547
- // so the installer rewrites it with this host's workspace.
548
- if (findForeignWorkspaceHost('codex', verdict.binding.workspaceDir, {
540
+ // PRI-1247 (reopen): an existing, readable workspace that belongs to ANOTHER
541
+ // PD host is a cross-host misbinding, not a healthy binding — including a
542
+ // NON-DEFAULT workspace that host formally declared in its
543
+ // `principles-disciple.json` or payload binding (the original incident's
544
+ // target passed the defaults-only check). Treat it as repair-needed so the
545
+ // installer rewrites it with this host's workspace.
546
+ if (findForeignWorkspaceOwner('codex', verdict.binding.workspaceDir, {
549
547
  homeDir,
550
548
  codexHome,
549
+ ...(input.openclawHome !== undefined ? { openclawHome: input.openclawHome } : {}),
550
+ ...(input.workbuddyConfigDir !== undefined ? { workbuddyConfigDir: input.workbuddyConfigDir } : {}),
551
551
  platform: process.platform,
552
- }) !== null)
552
+ }).owners.length > 0)
553
553
  return false;
554
554
  // Installer-only context the shape contract cannot know: the binding must
555
555
  // describe THIS payload's runtime at THIS payload's pin. The comparison uses
@@ -579,7 +579,25 @@ export class CodexHostInstaller {
579
579
  return this.deps.codexHome ?? getCodexDir();
580
580
  }
581
581
  ownershipHome() {
582
- return this.deps.homeDir ?? os.homedir();
582
+ return this.deps.homeDir ?? getHomeDir();
583
+ }
584
+ /**
585
+ * The FOUR host roots the cross-host ownership verdict needs, honoring the
586
+ * user's custom OPENCLAW_STATE_DIR / OPENCLAW_HOME / WORKBUDDY_CONFIG_DIR
587
+ * through the shared resolver (§5.6) — omitting them would miss foreign
588
+ * bindings under custom host roots and skip a needed repair.
589
+ */
590
+ hostOwnershipRoots() {
591
+ const workbuddyOverride = process.env.WORKBUDDY_CONFIG_DIR?.trim();
592
+ return {
593
+ homeDir: this.ownershipHome(),
594
+ codexHome: this.codexHome(),
595
+ openclawHome: this.deps.openclawHome ?? getOpenClawDir(),
596
+ workbuddyConfigDir: this.deps.workbuddyConfigDir
597
+ ?? (workbuddyOverride !== undefined && workbuddyOverride.length > 0
598
+ ? path.resolve(workbuddyOverride)
599
+ : path.join(this.ownershipHome(), '.workbuddy')),
600
+ };
583
601
  }
584
602
  /**
585
603
  * Run `codex plugin add <plugin>@<marketplace>`. Re-adding an installed
@@ -747,8 +765,7 @@ export class CodexHostInstaller {
747
765
  pluginRoot: current.versionDir,
748
766
  runtimeDir,
749
767
  pin,
750
- codexHome: this.codexHome(),
751
- homeDir: this.ownershipHome(),
768
+ ...this.hostOwnershipRoots(),
752
769
  });
753
770
  let runtimeReconciled = false;
754
771
  let bindingRepaired = false;
@@ -772,8 +789,7 @@ export class CodexHostInstaller {
772
789
  pluginRoot: current.versionDir,
773
790
  runtimeDir,
774
791
  pin,
775
- codexHome: this.codexHome(),
776
- homeDir: this.ownershipHome(),
792
+ ...this.hostOwnershipRoots(),
777
793
  })) {
778
794
  return {
779
795
  success: false,
@@ -1,6 +1,7 @@
1
1
  import { existsSync, readFileSync } from 'fs';
2
2
  import * as path from 'path';
3
3
  import * as os from 'os';
4
+ import { resolvePdHome } from '@principles/install-layout';
4
5
  import { OpenClawHostInstaller } from './openclaw-host-installer.js';
5
6
  import { CodexHostInstaller, detectCodexMarketplaceState } from './codex-host-installer.js';
6
7
  import { WorkBuddyHostInstaller, readWorkbuddyHostState, resolveWorkbuddyPaths } from './workbuddy-host-installer.js';
@@ -62,7 +63,18 @@ export function getHostInstallers(target) {
62
63
  */
63
64
  export function detectInstalledHosts(homeDir = os.homedir(), codexHome) {
64
65
  const detected = [];
65
- const openclawExtension = path.join(homeDir, '.openclaw', 'extensions', 'principles-disciple');
66
+ // The OpenClaw extension lives in the ACTIVE state dir (OPENCLAW_STATE_DIR >
67
+ // OPENCLAW_HOME > <homeDir>/.openclaw) — the same resolution the host
68
+ // installer registers into. A fixed <homeDir>/.openclaw read misjudges a
69
+ // custom-state-dir install as absent, letting a manifest repair drop the
70
+ // record and a sibling-host uninstall remove the shared runtime (Devin
71
+ // review #2699-0004). Base fields only (registry surface compatibility).
72
+ const resolution = resolvePdHome({ homeDir });
73
+ if (!resolution.ok) {
74
+ // Fail-closed: an unusable PD home must not read as "no hosts installed".
75
+ throw new Error(`PD home resolution refused (${resolution.reason}): ${resolution.message} Next action: ${resolution.nextAction}`);
76
+ }
77
+ const openclawExtension = path.join(resolution.openclawHome, 'extensions', 'principles-disciple');
66
78
  if (existsSync(openclawExtension)) {
67
79
  detected.push({ hostId: 'openclaw', evidence: openclawExtension });
68
80
  }
@@ -74,7 +86,9 @@ export function detectInstalledHosts(homeDir = os.homedir(), codexHome) {
74
86
  }
75
87
  const workbuddy = readWorkbuddyHostState(homeDir);
76
88
  if (workbuddy.pluginState !== undefined && workbuddy.pluginState.registryReadable && workbuddy.pluginState.registered) {
77
- detected.push({ hostId: 'workbuddy', evidence: path.join(homeDir, '.workbuddy', 'plugins', 'installed_plugins.json') });
89
+ // Evidence follows the same WORKBUDDY_CONFIG_DIR-aware root the installer
90
+ // registered into (resolveWorkbuddyPaths), not a fixed home literal.
91
+ detected.push({ hostId: 'workbuddy', evidence: resolveWorkbuddyPaths(homeDir).registryPath });
78
92
  }
79
93
  return detected;
80
94
  }
@@ -98,7 +112,14 @@ export function evaluateRecordedHostPresence(host, homeDir = os.homedir()) {
98
112
  return { status: 'installed', evidence: detected.evidence };
99
113
  }
100
114
  if (host === 'openclaw') {
101
- const openclawDir = path.join(homeDir, '.openclaw');
115
+ // Same active-state-dir resolution the installer registers into (Devin
116
+ // review #2699-0004). A REFUSED resolution is 'undecidable' by the safety
117
+ // inversion: absence cannot be proven, so the manifest record stays.
118
+ const presenceResolution = resolvePdHome({ homeDir });
119
+ if (!presenceResolution.ok) {
120
+ return { status: 'undecidable', reason: `PD home resolution refused (${presenceResolution.reason}): ${presenceResolution.message}` };
121
+ }
122
+ const openclawDir = presenceResolution.openclawHome;
102
123
  const configPath = path.join(openclawDir, 'openclaw.json');
103
124
  let raw;
104
125
  try {
@@ -25,8 +25,8 @@
25
25
  * `pd health` reports the same verdict.
26
26
  */
27
27
  import * as fs from 'fs';
28
- import * as os from 'os';
29
28
  import * as path from 'path';
29
+ import { resolvePdHome } from '@principles/install-layout';
30
30
  export const PD_MCP_SERVER_NAME = 'pd-recall';
31
31
  /** Stamp carried by PD's own launcher (see mcp/launcher.cjs `PD_LAUNCHER_ID`). */
32
32
  const PD_LAUNCHER_ID = 'pd-mcp-launcher.v1';
@@ -37,24 +37,31 @@ const MAX_LAUNCHER_BYTES = 512 * 1024;
37
37
  function isRecord(value) {
38
38
  return value !== null && typeof value === 'object' && !Array.isArray(value);
39
39
  }
40
- function getHomeDir(options) {
41
- return path.resolve(options.homeDir ?? os.homedir());
40
+ function resolveHostPathRoots(options) {
41
+ const env = { ...process.env };
42
+ if (options.codexHome !== undefined)
43
+ env.CODEX_HOME = options.codexHome;
44
+ if (options.workbuddyConfigDir !== undefined)
45
+ env.WORKBUDDY_CONFIG_DIR = options.workbuddyConfigDir;
46
+ // No explicit homeDir → let the shared resolver decide (HOME-first). Pinning
47
+ // os.homedir() here would make the conflict check inspect a DIFFERENT
48
+ // install than the one the installer writes to when HOME ≠ os.homedir()
49
+ // (review N27).
50
+ const resolution = options.homeDir !== undefined
51
+ ? resolvePdHome({ homeDir: options.homeDir, env })
52
+ : resolvePdHome({ env });
53
+ if (!resolution.ok) {
54
+ throw new Error(`PD home resolution refused (${resolution.reason}): ${resolution.message} Next action: ${resolution.nextAction}`);
55
+ }
56
+ return resolution;
42
57
  }
43
58
  export function resolveMcpRegistrationConfigPath(host, options = {}) {
44
- const home = getHomeDir(options);
45
- if (host === 'codex') {
46
- const codexHome = options.codexHome ?? (process.env.CODEX_HOME && process.env.CODEX_HOME.length > 0
47
- ? process.env.CODEX_HOME
48
- : path.join(home, '.codex'));
49
- return path.join(codexHome, 'config.toml');
50
- }
59
+ const home = resolveHostPathRoots(options);
60
+ if (host === 'codex')
61
+ return path.join(home.codexHome, 'config.toml');
51
62
  if (host === 'openclaw')
52
- return path.join(home, '.openclaw', 'openclaw.json');
53
- const configDir = options.workbuddyConfigDir
54
- ?? (process.env.WORKBUDDY_CONFIG_DIR && process.env.WORKBUDDY_CONFIG_DIR.length > 0
55
- ? process.env.WORKBUDDY_CONFIG_DIR
56
- : path.join(home, '.workbuddy'));
57
- return path.join(configDir, 'mcp.json');
63
+ return path.join(home.openclawHome, 'openclaw.json');
64
+ return path.join(home.workbuddyConfigDir, 'mcp.json');
58
65
  }
59
66
  const HOST_MARKER_PATHS = {
60
67
  codex: ['.codex-plugin', 'plugin.json'],
@@ -20,8 +20,7 @@
20
20
  */
21
21
  import { existsSync, readFileSync, writeFileSync } from 'fs';
22
22
  import * as path from 'path';
23
- import * as os from 'os';
24
- import { validateOpenClawConfig } from '../mvp-config.js';
23
+ import { getOpenClawDir, getPluginExtDir, validateOpenClawConfig } from '../mvp-config.js';
25
24
  import { classifyOpenClawConfigObject } from './mcp-registration-conflict.js';
26
25
  // PRI-343: Keep in sync with @principles/core CONVERSATION_ACCESS_CONFIG_KEY
27
26
  const CONVERSATION_ACCESS_CONFIG_KEY = 'allowConversationAccess';
@@ -68,12 +67,6 @@ function ensureConversationAccess(config) {
68
67
  result.plugins = plugins;
69
68
  return result;
70
69
  }
71
- function getOpenClawDir() {
72
- return path.join(os.homedir(), '.openclaw');
73
- }
74
- function getPluginExtDir() {
75
- return path.join(getOpenClawDir(), 'extensions', 'principles-disciple');
76
- }
77
70
  /**
78
71
  * OpenClaw host installer — writes/merges ~/.openclaw/openclaw.json only.
79
72
  * Plugin installation records belong to the OpenClaw host; PD must not write
@@ -193,8 +193,9 @@ function missingWorkbuddyPayloadFile(root) {
193
193
  }
194
194
  export function resolveWorkbuddyPaths(homeDir) {
195
195
  const layout = getInstallLayoutPaths(homeDir);
196
- // The frozen governance dir (~/.workbuddy/pd-workspace) defines the host
197
- // config root; deriving configDir from it keeps one path authority.
196
+ // The governance workspace and host config root are derived together so
197
+ // an explicit WORKBUDDY_CONFIG_DIR cannot split PD's database from the host
198
+ // registration it is installed beside. The host-owned tree remains in place.
198
199
  //
199
200
  // HOST BOUNDARY (review P3, probe P0 fact): this installer targets the
200
201
  // WorkBuddy DESKTOP host, whose registration root is ~/.workbuddy (real
@@ -202,9 +203,8 @@ export function resolveWorkbuddyPaths(homeDir) {
202
203
  // root is ~/.codebuddy (CODEBUDDY_CONFIG_DIR); a CLI-only user's engine
203
204
  // will not read a registration written here. WORKBUDDY_CONFIG_DIR remains
204
205
  // the isolation override (Phase 0 lab discipline).
205
- const configDir = process.env.WORKBUDDY_CONFIG_DIR && process.env.WORKBUDDY_CONFIG_DIR.length > 0
206
- ? path.resolve(process.env.WORKBUDDY_CONFIG_DIR)
207
- : path.dirname(getWorkbuddyWorkspaceDir(homeDir));
206
+ const governanceDir = getWorkbuddyWorkspaceDir(homeDir, process.env.WORKBUDDY_CONFIG_DIR);
207
+ const configDir = path.dirname(governanceDir);
208
208
  return {
209
209
  homeDir: layout.homeDir,
210
210
  configDir,
@@ -212,7 +212,7 @@ export function resolveWorkbuddyPaths(homeDir) {
212
212
  registryPath: path.join(configDir, 'plugins', 'installed_plugins.json'),
213
213
  cachePluginRoot: path.join(configDir, 'plugins', 'cache', WORKBUDDY_MARKETPLACE_NAME, WORKBUDDY_PLUGIN_NAME),
214
214
  marketplaceRoot: path.join(layout.pdDir, 'workbuddy-marketplace'),
215
- governanceDir: getWorkbuddyWorkspaceDir(homeDir),
215
+ governanceDir,
216
216
  runtimeAdapterDir: layout.workbuddyAdapterDir,
217
217
  installManifestPath: layout.manifest,
218
218
  };
@@ -2168,7 +2168,7 @@ function writeWorkbuddyMcpBinding(marketplaceRoot, homeDir) {
2168
2168
  const binding = {
2169
2169
  schemaVersion: 'pd.mcp-binding.v1',
2170
2170
  host: 'workbuddy',
2171
- workspaceDir: getWorkbuddyWorkspaceDir(homeDir),
2171
+ workspaceDir: getWorkbuddyWorkspaceDir(homeDir, process.env.WORKBUDDY_CONFIG_DIR),
2172
2172
  runtimeDir: layout.runtimeDir,
2173
2173
  serverEntry,
2174
2174
  versions: { mcpServer: mcpServerVersion },
@@ -1,9 +1,10 @@
1
1
  import * as yaml from 'js-yaml';
2
2
  import * as path from 'path';
3
- import * as os from 'os';
4
3
  import { existsSync, readFileSync } from 'fs';
4
+ import { homedir as osHomedir } from 'os';
5
5
  import { execSync } from 'child_process';
6
6
  import { errnoCode } from './utils/config-file-io.js';
7
+ import { resolvePdHome } from '@principles/install-layout';
7
8
  export const MVP_CHANNELS = ['prompt', 'code_tool_hook', 'defer_archive'];
8
9
  // GFI retired 2026-11-04 (GFI-COMPLETE-REMOVAL-001): its flag became a `gone`
9
10
  // tombstone, so no quiet flag remains.
@@ -171,22 +172,55 @@ export function buildFailureOutput(reason, nextAction) {
171
172
  export function isMvpChannel(value) {
172
173
  return MVP_CHANNELS.includes(value);
173
174
  }
175
+ function requirePdHome() {
176
+ const resolution = resolvePdHome();
177
+ if (!resolution.ok) {
178
+ throw new Error(`PD home resolution refused (${resolution.reason}): ${resolution.message} Next action: ${resolution.nextAction}`);
179
+ }
180
+ return resolution;
181
+ }
182
+ /**
183
+ * The real user home, not the effective PD Home. PD-owned paths must go
184
+ * through requirePdHome()/getPdDir()/getOpenClawDir(); this value is passed to
185
+ * those resolvers as their production-home input and must not be replaced by
186
+ * PD_EXPERIMENT_ROOT (which is a separate isolation boundary).
187
+ *
188
+ * Precedence mirrors install-layout's resolvePdHome default (resolveRealUserHome):
189
+ * an explicit `HOME` wins (the POSIX semantics plus the established
190
+ * installer-family test-sandbox contract), then `os.homedir()` (USERPROFILE on
191
+ * Windows). The mirror is inline because the packaged installer must keep
192
+ * working against the PUBLISHED @principles/install-layout surface (the
193
+ * smoke-packaged-install registry-parity gate resolves the registry version,
194
+ * which does not export the helper yet) — the two implementations are pinned
195
+ * together semantically, not by import (ERR-083 OCC-20261117T190516Z: letting
196
+ * them diverge lands HOME-sandboxed tests on the real production home).
197
+ */
174
198
  export function getHomeDir() {
175
- return process.env.HOME
176
- || process.env.USERPROFILE
177
- || (process.env.HOMEDRIVE && process.env.HOMEPATH ? process.env.HOMEDRIVE + process.env.HOMEPATH : null)
178
- || '.';
199
+ const home = process.env.HOME?.trim();
200
+ return home !== undefined && home.length > 0 ? home : osHomedir();
179
201
  }
180
202
  export function getOpenClawDir() {
181
- return path.join(getHomeDir(), '.openclaw');
203
+ return requirePdHome().openclawHome;
204
+ }
205
+ export function getCodexHomeDir() {
206
+ return requirePdHome().codexHome;
182
207
  }
183
208
  /** Host-neutral PD installation root. Shared runtime must not live under a
184
209
  * host's discovery directory (ADR-0020 / ERR-097). */
185
210
  export function getPdDir() {
186
- return path.join(getHomeDir(), '.pd');
211
+ return requirePdHome().pdHome;
187
212
  }
213
+ /**
214
+ * The derived paths below are composed from the BASE PdHomePaths fields only
215
+ * (pdHome/openclawHome/codexHome — present since install-layout 0.8.3). The
216
+ * packaged installer must keep working against the PUBLISHED install-layout
217
+ * surface (smoke-packaged-install resolves the registry version), which does
218
+ * not yet carry the newer fields (runtimeDir/pdRuntimeBackupsDir/
219
+ * openclawExtensionDir). The derivations are the same constants resolvePdHome
220
+ * computes, so the two stay semantically pinned (Devin review #2699-0003).
221
+ */
188
222
  export function getPdRuntimeDir() {
189
- return path.join(getPdDir(), 'runtime');
223
+ return path.join(requirePdHome().pdHome, 'runtime');
190
224
  }
191
225
  export function getInstallManifestPath() {
192
226
  return path.join(getPdDir(), 'install.json');
@@ -195,7 +229,7 @@ export function getPdRuntimeBackupsDir() {
195
229
  return path.join(getPdDir(), 'backups');
196
230
  }
197
231
  export function getPluginExtDir() {
198
- return path.join(getOpenClawDir(), 'extensions', 'principles-disciple');
232
+ return path.join(requirePdHome().openclawHome, 'extensions', 'principles-disciple');
199
233
  }
200
234
  /** Common plugin package used by pd-cli/console. OpenClaw gets an adapter copy
201
235
  * under getPluginExtDir(); Codex-only installs use this host-neutral copy. */
@@ -206,14 +240,13 @@ export function getInstalledLayoutPackageDir() {
206
240
  return path.join(getPdRuntimeDir(), 'install-layout');
207
241
  }
208
242
  /**
209
- * PD 备份根目录(~/.openclaw/pd-backups)—— 必须位于 extensions/ 之外。
210
- * OpenClaw 插件发现会扫描 extensions/ 下每个子目录;备份目录内含
211
- * package.json(openclaw.extensions) + dist/bundle.js 时会被识别为第二个
212
- * principles-disciple 插件,导致每次 gateway 启动都出现
213
- * "duplicate plugin id detected" 告警。备份一律放这里,禁止放 extensions/ 内。
243
+ * Host-neutral PD backup root (<PD_HOME>/.pd/backups). It is outside every
244
+ * host's plugin discovery tree; OpenClaw extension backups and shared-runtime
245
+ * backups use the same owner-controlled location. Derived from the base
246
+ * pdHome field for registry-surface compatibility (see getPdRuntimeDir).
214
247
  */
215
248
  export function getPdBackupsDir() {
216
- return path.join(getOpenClawDir(), 'pd-backups');
249
+ return getPdRuntimeBackupsDir();
217
250
  }
218
251
  export function getInstalledPdCliDir() {
219
252
  return path.join(getPdRuntimeDir(), 'pd-cli');
@@ -557,7 +590,7 @@ export function getGlobalShimPaths() {
557
590
  paths.push(path.join(globalBin, 'pd'));
558
591
  }
559
592
  }
560
- const homeBin = path.join(os.homedir(), 'bin');
593
+ const homeBin = path.join(osHomedir(), 'bin');
561
594
  if (isWindows()) {
562
595
  paths.push(path.join(homeBin, 'pd.cmd'), path.join(homeBin, 'pd.ps1'), path.join(homeBin, 'pd'));
563
596
  }
@@ -9,8 +9,8 @@
9
9
  */
10
10
  import { randomUUID } from 'node:crypto';
11
11
  import * as fs from 'node:fs';
12
- import * as os from 'node:os';
13
12
  import * as path from 'node:path';
13
+ import { getOpenClawDir } from '../mvp-config.js';
14
14
  import { resolveTrustedReleaseTarget, downloadTrustedReleasePayload, ReleaseTrustError } from './trust-metadata.js';
15
15
  import { parseChannelMetadata } from './channel-metadata.js';
16
16
  import { buildReleaseMetadata, isReleaseMetadataExpired, parseReleaseMetadata, verifyReleaseMetadataIdentity, } from './release-metadata.js';
@@ -581,8 +581,11 @@ export class ReleaseManager {
581
581
  }
582
582
  }
583
583
  legacyOverlayMarker() {
584
+ // Same active OpenClaw state dir the installer and plugin resolver use
585
+ // (OPENCLAW_STATE_DIR > OPENCLAW_HOME > ~/.openclaw via the PD Home
586
+ // authority) — an experiment update inspects its own lab overlay.
584
587
  const openclawRoot = this.options.openclawHome
585
- ?? path.join(os.homedir(), '.openclaw');
588
+ ?? getOpenClawDir();
586
589
  return path.join(openclawRoot, 'extensions', 'principles-disciple');
587
590
  }
588
591
  readChannelMetadataPayload(channel) {
@@ -12,10 +12,10 @@
12
12
  import { execFileSync } from 'child_process';
13
13
  import * as fs from 'fs';
14
14
  import * as path from 'path';
15
- import * as os from 'os';
16
15
  import * as net from 'net';
17
- import { findForeignWorkspaceHost } from './host-workspace-ownership.js';
16
+ import { findForeignWorkspaceOwner } from './host-workspace-ownership.js';
18
17
  import { errnoCode } from './config-file-io.js';
18
+ import { resolvePdHome } from '@principles/install-layout';
19
19
  const IS_WIN32 = process.platform === 'win32';
20
20
  /** 探测超时:卡死的 .cmd shim / 挂起的二进制不应挂住安装器(rc-9 降级)。 */
21
21
  const DETECT_TIMEOUT_MS = 5000;
@@ -96,8 +96,8 @@ export function checkEnvironment() {
96
96
  return result;
97
97
  }
98
98
  /** The initialized Codex workspace used by `$pd-control setup` (`locateWorkspace`). */
99
- function codexWorkspaceCandidates(homeDir, codexHome, cwd) {
100
- const candidates = [path.join(codexHome, 'pd-workspace')];
99
+ function codexWorkspaceCandidates(hostRoots, workspaceDir, cwd) {
100
+ const candidates = [workspaceDir];
101
101
  // A project with `.pd/config.yaml` is an initialized workspace and wins over
102
102
  // the bare cwd, matching the plugin's own locateWorkspace order.
103
103
  let current = cwd;
@@ -113,40 +113,83 @@ function codexWorkspaceCandidates(homeDir, codexHome, cwd) {
113
113
  }
114
114
  candidates.push(cwd);
115
115
  // Never default Codex to another PD host's owned workspace, even when the
116
- // process happens to run inside it (PRI-1247).
117
- return candidates.filter((candidate) => findForeignWorkspaceHost('codex', candidate, {
118
- homeDir,
119
- codexHome,
116
+ // process happens to run inside it — INCLUDING a non-default workspace that
117
+ // host formally declared (PRI-1247 reopen: defaults-only missed the incident
118
+ // target `D:\.openclaw\workspace`). Directory SOURCES are the #2699 PD-Home
119
+ // roots authority only; the verdict adds declarations/payload bindings and
120
+ // multi-owner reporting, never a second layout source.
121
+ return candidates.filter((candidate) => findForeignWorkspaceOwner('codex', candidate, {
122
+ ...hostRoots,
120
123
  platform: process.platform,
121
- }) === null);
124
+ }).owners.length === 0);
122
125
  }
123
126
  /**
124
127
  * 检测工作区。
125
128
  *
126
- * 默认(OpenClaw)保持原有候选顺序;`host: 'codex'` 只使用 Codex 自己的
127
- * 工作区(`<CODEX_HOME>/pd-workspace` → 最近的项目 `.pd/config.yaml` → cwd),
128
- * 不再继承 OPENCLAW_WORKSPACE / PD_WORKSPACE_DIR / ~/clawd(PRI-1247)。
129
+ * Each host uses its own resolved PD governance workspace. Codex may fall back
130
+ * to a nearest initialized project workspace; WorkBuddy never inherits the
131
+ * OpenClaw workspace candidates.
132
+ */
133
+ /**
134
+ * Derive the host config roots from the BASE PdHomePaths fields only
135
+ * (pdHome/homeDir/openclawHome/codexHome — present since install-layout 0.8.3,
136
+ * which the packaged installer resolves from the npm registry — see
137
+ * mcp-server-layout-compat.ts and Devin review #2699-0003). The derivations
138
+ * mirror resolvePdHome's own computations, so the two stay semantically pinned;
139
+ * when install-layout publishes the newer fields the consumers can switch back.
129
140
  */
141
+ function deriveHostRoots(homePaths, env) {
142
+ const { homeDir, codexHome: resolvedCodexHome } = homePaths;
143
+ const codexHome = resolvedCodexHome ?? path.join(homeDir, '.codex');
144
+ const workbuddyOverride = env.WORKBUDDY_CONFIG_DIR?.trim();
145
+ const workbuddyConfigDir = workbuddyOverride !== undefined && workbuddyOverride.length > 0
146
+ ? path.resolve(workbuddyOverride)
147
+ : path.join(homeDir, '.workbuddy');
148
+ return {
149
+ homeDir,
150
+ openclawHome: homePaths.openclawHome,
151
+ codexHome,
152
+ codexWorkspaceDir: path.join(codexHome, 'pd-workspace'),
153
+ workbuddyConfigDir,
154
+ workbuddyWorkspaceDir: path.join(workbuddyConfigDir, 'pd-workspace'),
155
+ };
156
+ }
130
157
  export function detectWorkspace(options = {}) {
131
- const homeDir = options.homeDir ?? os.homedir();
132
158
  const host = options.host ?? 'openclaw';
133
- const codexHome = options.codexHome
134
- ?? (typeof process.env.CODEX_HOME === 'string' && path.isAbsolute(process.env.CODEX_HOME)
135
- ? path.resolve(process.env.CODEX_HOME)
136
- : path.join(homeDir, '.codex'));
137
- const candidates = host === 'codex'
138
- ? codexWorkspaceCandidates(homeDir, codexHome, options.cwd ?? process.cwd())
139
- : [];
140
- if (host !== 'codex') {
141
- // 安全地添加候选路径
142
- if (process.env.OPENCLAW_WORKSPACE) {
143
- candidates.push(process.env.OPENCLAW_WORKSPACE);
159
+ const env = { ...(options.env ?? process.env) };
160
+ if (options.codexHome !== undefined)
161
+ env.CODEX_HOME = options.codexHome;
162
+ // No explicit homeDir injection → let the shared resolver pick the default
163
+ // (HOME-first). Pinning os.homedir() here would bypass the shared HOME
164
+ // precedence and diverge from the installer's own write paths on hosts where
165
+ // HOME ≠ os.homedir() (review N2-).
166
+ const homePaths = resolvePdHome(options.homeDir !== undefined ? { homeDir: options.homeDir, env } : { env });
167
+ if (!homePaths.ok) {
168
+ throw new Error(`PD home resolution refused (${homePaths.reason}): ${homePaths.message} Next action: ${homePaths.nextAction}`);
169
+ }
170
+ const hostRoots = deriveHostRoots(homePaths, env);
171
+ const candidates = [];
172
+ if (host === 'codex') {
173
+ candidates.push(...codexWorkspaceCandidates({
174
+ homeDir: hostRoots.homeDir,
175
+ codexHome: hostRoots.codexHome,
176
+ openclawHome: hostRoots.openclawHome,
177
+ workbuddyConfigDir: hostRoots.workbuddyConfigDir,
178
+ }, hostRoots.codexWorkspaceDir, options.cwd ?? process.cwd()));
179
+ }
180
+ else if (host === 'workbuddy') {
181
+ candidates.push(hostRoots.workbuddyWorkspaceDir);
182
+ }
183
+ else {
184
+ // OpenClaw owns its default workspace under the active OpenClaw state dir.
185
+ if (typeof env.OPENCLAW_WORKSPACE === 'string' && env.OPENCLAW_WORKSPACE.trim().length > 0) {
186
+ candidates.push(env.OPENCLAW_WORKSPACE);
144
187
  }
145
- if (process.env.PD_WORKSPACE_DIR) {
146
- candidates.push(process.env.PD_WORKSPACE_DIR);
188
+ if (typeof env.PD_WORKSPACE_DIR === 'string' && env.PD_WORKSPACE_DIR.trim().length > 0) {
189
+ candidates.push(env.PD_WORKSPACE_DIR);
147
190
  }
148
- candidates.push(path.join(homeDir, 'clawd'));
149
- candidates.push(path.join(homeDir, '.openclaw', 'workspace'));
191
+ candidates.push(path.join(hostRoots.homeDir, 'clawd'));
192
+ candidates.push(path.join(hostRoots.openclawHome, 'workspace'));
150
193
  }
151
194
  // 核心文件列表(用于检测是否已安装)
152
195
  const CORE_FILES = [
@@ -182,8 +225,10 @@ export function detectWorkspace(options = {}) {
182
225
  }
183
226
  // Codex first install defaults to ITS OWN user workspace; OpenClaw keeps ~/clawd.
184
227
  const defaultPath = host === 'codex'
185
- ? path.join(codexHome, 'pd-workspace')
186
- : path.join(homeDir, 'clawd');
228
+ ? hostRoots.codexWorkspaceDir
229
+ : host === 'workbuddy'
230
+ ? hostRoots.workbuddyWorkspaceDir
231
+ : path.join(hostRoots.homeDir, 'clawd');
187
232
  return {
188
233
  detectedPath: defaultPath,
189
234
  exists: false,
@@ -195,14 +240,26 @@ export function detectWorkspace(options = {}) {
195
240
  /**
196
241
  * 获取 OpenClaw 配置目录
197
242
  */
198
- export function getOpenClawConfigDir() {
199
- return path.join(os.homedir(), '.openclaw');
243
+ export function getOpenClawConfigDir(homeDir, env = process.env) {
244
+ const homePaths = resolvePdHome(homeDir !== undefined ? { homeDir, env } : { env });
245
+ if (!homePaths.ok) {
246
+ throw new Error(`PD home resolution refused (${homePaths.reason}): ${homePaths.message} Next action: ${homePaths.nextAction}`);
247
+ }
248
+ // Derived from the base openclawHome field (registry-surface compatibility).
249
+ return homePaths.openclawHome;
200
250
  }
201
251
  /**
202
252
  * 获取插件扩展目录
203
253
  */
204
- export function getPluginExtDir() {
205
- return path.join(getOpenClawConfigDir(), 'extensions', 'principles-disciple');
254
+ export function getPluginExtDir(homeDir, env = process.env) {
255
+ const homePaths = resolvePdHome(homeDir !== undefined ? { homeDir, env } : { env });
256
+ if (!homePaths.ok) {
257
+ throw new Error(`PD home resolution refused (${homePaths.reason}): ${homePaths.message} Next action: ${homePaths.nextAction}`);
258
+ }
259
+ // Derived from the base openclawHome field (registry-surface compatibility,
260
+ // see deriveHostRoots above) — identical to the extension-dir computation
261
+ // resolvePdHome itself performs.
262
+ return path.join(homePaths.openclawHome, 'extensions', 'principles-disciple');
206
263
  }
207
264
  function readOpenClawPort() {
208
265
  const configPath = path.join(getOpenClawConfigDir(), 'openclaw.json');