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.
Files changed (298) 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 +153 -9
  13. package/console/dist/web/assets/app.js +41 -37
  14. package/console/dist/web/assets/intent-reflection.webp +3 -0
  15. package/console/dist/web/assets/providers/anthropic.png +0 -0
  16. package/console/dist/web/assets/providers/deepseek.png +0 -0
  17. package/console/dist/web/assets/providers/google.png +0 -0
  18. package/console/dist/web/assets/providers/groq.svg +1 -0
  19. package/console/dist/web/assets/providers/kimi.png +0 -0
  20. package/console/dist/web/assets/providers/minimax.png +0 -0
  21. package/console/dist/web/assets/providers/mistral.svg +28 -0
  22. package/console/dist/web/assets/providers/nvidia.png +0 -0
  23. package/console/dist/web/assets/providers/openai.svg +1 -0
  24. package/console/dist/web/assets/providers/openrouter.svg +3 -0
  25. package/console/dist/web/assets/providers/qwen.png +0 -0
  26. package/console/dist/web/assets/providers/together.svg +21 -0
  27. package/console/dist/web/assets/providers/xai.svg +1 -0
  28. package/console/dist/web/assets/providers/xiaomi.png +0 -0
  29. package/console/dist/web/assets/providers/zai.svg +219 -0
  30. package/core/dist/index.d.ts +1 -2
  31. package/core/dist/index.d.ts.map +1 -1
  32. package/core/dist/index.js +4 -2
  33. package/core/dist/index.js.map +1 -1
  34. package/core/dist/prompt-builder/focus-compression.d.ts +8 -60
  35. package/core/dist/prompt-builder/focus-compression.d.ts.map +1 -1
  36. package/core/dist/prompt-builder/focus-compression.js +8 -434
  37. package/core/dist/prompt-builder/focus-compression.js.map +1 -1
  38. package/core/dist/prompt-builder/index.d.ts +1 -2
  39. package/core/dist/prompt-builder/index.d.ts.map +1 -1
  40. package/core/dist/prompt-builder/index.js +3 -2
  41. package/core/dist/prompt-builder/index.js.map +1 -1
  42. package/core/dist/runtime/activation/production-gate-deps.d.ts +7 -3
  43. package/core/dist/runtime/activation/production-gate-deps.d.ts.map +1 -1
  44. package/core/dist/runtime/activation/production-gate-deps.js +15 -6
  45. package/core/dist/runtime/activation/production-gate-deps.js.map +1 -1
  46. package/core/dist/runtime/adapter/principle-tree-ledger-adapter.d.ts +2 -0
  47. package/core/dist/runtime/adapter/principle-tree-ledger-adapter.d.ts.map +1 -1
  48. package/core/dist/runtime/adapter/principle-tree-ledger-adapter.js +9 -1
  49. package/core/dist/runtime/adapter/principle-tree-ledger-adapter.js.map +1 -1
  50. package/core/dist/runtime/config/pd-config-types.d.ts +20 -1
  51. package/core/dist/runtime/config/pd-config-types.d.ts.map +1 -1
  52. package/core/dist/runtime/config/pd-config-types.js.map +1 -1
  53. package/core/dist/runtime/config/pd-config-validate.d.ts.map +1 -1
  54. package/core/dist/runtime/config/pd-config-validate.js +12 -1
  55. package/core/dist/runtime/config/pd-config-validate.js.map +1 -1
  56. package/core/dist/runtime/internalization/bash-risk.d.ts.map +1 -1
  57. package/core/dist/runtime/internalization/bash-risk.js +6 -3
  58. package/core/dist/runtime/internalization/bash-risk.js.map +1 -1
  59. package/core/dist/runtime/internalization/internalization-orchestrator.d.ts +28 -1
  60. package/core/dist/runtime/internalization/internalization-orchestrator.d.ts.map +1 -1
  61. package/core/dist/runtime/internalization/internalization-orchestrator.js +109 -13
  62. package/core/dist/runtime/internalization/internalization-orchestrator.js.map +1 -1
  63. package/core/dist/runtime/internalization/split-diagnostician-runner.d.ts +10 -0
  64. package/core/dist/runtime/internalization/split-diagnostician-runner.d.ts.map +1 -1
  65. package/core/dist/runtime/internalization/split-diagnostician-runner.js +6 -1
  66. package/core/dist/runtime/internalization/split-diagnostician-runner.js.map +1 -1
  67. package/core/dist/runtime/pain-chain-read-model.d.ts +14 -0
  68. package/core/dist/runtime/pain-chain-read-model.d.ts.map +1 -1
  69. package/core/dist/runtime/pain-chain-read-model.js +91 -3
  70. package/core/dist/runtime/pain-chain-read-model.js.map +1 -1
  71. package/core/dist/runtime/pain-ingress-payload.d.ts +15 -0
  72. package/core/dist/runtime/pain-ingress-payload.d.ts.map +1 -1
  73. package/core/dist/runtime/pain-ingress-payload.js +32 -3
  74. package/core/dist/runtime/pain-ingress-payload.js.map +1 -1
  75. package/core/dist/runtime/pain-signal-bridge.d.ts +8 -0
  76. package/core/dist/runtime/pain-signal-bridge.d.ts.map +1 -1
  77. package/core/dist/runtime/pain-signal-bridge.js +11 -0
  78. package/core/dist/runtime/pain-signal-bridge.js.map +1 -1
  79. package/core/dist/runtime/pain-signal-runtime-factory.d.ts.map +1 -1
  80. package/core/dist/runtime/pain-signal-runtime-factory.js +3 -0
  81. package/core/dist/runtime/pain-signal-runtime-factory.js.map +1 -1
  82. package/core/dist/runtime/pain-submit-capability.d.ts +54 -0
  83. package/core/dist/runtime/pain-submit-capability.d.ts.map +1 -1
  84. package/core/dist/runtime/pain-submit-capability.js +49 -1
  85. package/core/dist/runtime/pain-submit-capability.js.map +1 -1
  86. package/core/dist/runtime/storage-paths.d.ts +9 -10
  87. package/core/dist/runtime/storage-paths.d.ts.map +1 -1
  88. package/core/dist/runtime/storage-paths.js +9 -10
  89. package/core/dist/runtime/storage-paths.js.map +1 -1
  90. package/core/dist/runtime/store/context/sqlite-context-assembler.d.ts.map +1 -1
  91. package/core/dist/runtime/store/context/sqlite-context-assembler.js +10 -2
  92. package/core/dist/runtime/store/context/sqlite-context-assembler.js.map +1 -1
  93. package/core/dist/runtime/store/storage-paths.d.ts +65 -12
  94. package/core/dist/runtime/store/storage-paths.d.ts.map +1 -1
  95. package/core/dist/runtime/store/storage-paths.js +92 -39
  96. package/core/dist/runtime/store/storage-paths.js.map +1 -1
  97. package/core/package.json +1 -1
  98. package/dist/index.d.ts.map +1 -1
  99. package/dist/index.js +6 -0
  100. package/dist/index.js.map +1 -1
  101. package/dist/installer.d.ts +137 -9
  102. package/dist/installer.d.ts.map +1 -1
  103. package/dist/installer.js +627 -100
  104. package/dist/installer.js.map +1 -1
  105. package/dist/installers/codex-host-installer.d.ts +23 -3
  106. package/dist/installers/codex-host-installer.d.ts.map +1 -1
  107. package/dist/installers/codex-host-installer.js +36 -20
  108. package/dist/installers/codex-host-installer.js.map +1 -1
  109. package/dist/installers/index.d.ts.map +1 -1
  110. package/dist/installers/index.js +24 -3
  111. package/dist/installers/index.js.map +1 -1
  112. package/dist/installers/mcp-registration-conflict.d.ts.map +1 -1
  113. package/dist/installers/mcp-registration-conflict.js +23 -16
  114. package/dist/installers/mcp-registration-conflict.js.map +1 -1
  115. package/dist/installers/openclaw-host-installer.d.ts.map +1 -1
  116. package/dist/installers/openclaw-host-installer.js +1 -8
  117. package/dist/installers/openclaw-host-installer.js.map +1 -1
  118. package/dist/installers/workbuddy-host-installer.d.ts.map +1 -1
  119. package/dist/installers/workbuddy-host-installer.js +51 -15
  120. package/dist/installers/workbuddy-host-installer.js.map +1 -1
  121. package/dist/mvp-config.d.ts +30 -5
  122. package/dist/mvp-config.d.ts.map +1 -1
  123. package/dist/mvp-config.js +49 -16
  124. package/dist/mvp-config.js.map +1 -1
  125. package/dist/prompts.js +1 -1
  126. package/dist/prompts.js.map +1 -1
  127. package/dist/uninstaller.d.ts.map +1 -1
  128. package/dist/uninstaller.js +142 -5
  129. package/dist/uninstaller.js.map +1 -1
  130. package/dist/update/release-manager.d.ts.map +1 -1
  131. package/dist/update/release-manager.js +5 -2
  132. package/dist/update/release-manager.js.map +1 -1
  133. package/dist/utils/env.d.ts +5 -10
  134. package/dist/utils/env.d.ts.map +1 -1
  135. package/dist/utils/env.js +91 -34
  136. package/dist/utils/env.js.map +1 -1
  137. package/dist/utils/host-workspace-ownership.d.ts +25 -0
  138. package/dist/utils/host-workspace-ownership.d.ts.map +1 -1
  139. package/dist/utils/host-workspace-ownership.js +153 -2
  140. package/dist/utils/host-workspace-ownership.js.map +1 -1
  141. package/host-runtime/dist/adaptive-background-append.d.ts +6 -0
  142. package/host-runtime/dist/adaptive-background-append.js +4 -1
  143. package/host-runtime/dist/adaptive-decision-protocol.d.ts +18 -2
  144. package/host-runtime/dist/adaptive-decision-protocol.js +39 -9
  145. package/host-runtime/dist/adaptive-principle-context-reader.d.ts +79 -0
  146. package/host-runtime/dist/adaptive-principle-context-reader.js +303 -0
  147. package/host-runtime/dist/adaptive-priority-provider.d.ts +33 -0
  148. package/host-runtime/dist/adaptive-priority-provider.js +68 -2
  149. package/host-runtime/dist/adaptive-selection.d.ts +16 -0
  150. package/host-runtime/dist/adaptive-selection.js +23 -1
  151. package/host-runtime/dist/codex-legacy-registration.js +10 -2
  152. package/host-runtime/dist/conversation-ingestion/pipeline.d.ts +8 -0
  153. package/host-runtime/dist/conversation-ingestion/pipeline.js +179 -7
  154. package/host-runtime/dist/degraded-enforcement-marker.js +16 -2
  155. package/host-runtime/dist/diagnostician-auto-run.js +4 -0
  156. package/host-runtime/dist/governance-observation-store.d.ts +44 -0
  157. package/host-runtime/dist/governance-observation-store.js +84 -1
  158. package/host-runtime/dist/governance-trajectory-turn-reader.d.ts +30 -0
  159. package/host-runtime/dist/governance-trajectory-turn-reader.js +47 -0
  160. package/host-runtime/dist/index.d.ts +2 -0
  161. package/host-runtime/dist/index.js +6 -0
  162. package/host-runtime/dist/product-telemetry/service.js +86 -20
  163. package/host-runtime/package.json +1 -1
  164. package/install-layout/dist/index.d.ts +23 -9
  165. package/install-layout/dist/index.js +49 -24
  166. package/install-layout/dist/mcp-binding-contract.d.ts +62 -0
  167. package/install-layout/dist/mcp-binding-contract.js +175 -3
  168. package/install-layout/dist/pd-home.d.ts +35 -5
  169. package/install-layout/dist/pd-home.js +138 -23
  170. package/install-layout/package.json +1 -1
  171. package/package.json +4 -4
  172. package/pd-cli/dist/commands/candidate.d.ts.map +1 -1
  173. package/pd-cli/dist/commands/candidate.js +134 -8
  174. package/pd-cli/dist/commands/candidate.js.map +1 -1
  175. package/pd-cli/dist/commands/codex-worker.d.ts.map +1 -1
  176. package/pd-cli/dist/commands/codex-worker.js +36 -2
  177. package/pd-cli/dist/commands/codex-worker.js.map +1 -1
  178. package/pd-cli/dist/commands/diagnose.d.ts.map +1 -1
  179. package/pd-cli/dist/commands/diagnose.js +34 -8
  180. package/pd-cli/dist/commands/diagnose.js.map +1 -1
  181. package/pd-cli/dist/commands/health-codex-install.d.ts +1 -3
  182. package/pd-cli/dist/commands/health-codex-install.d.ts.map +1 -1
  183. package/pd-cli/dist/commands/health-codex-install.js +19 -6
  184. package/pd-cli/dist/commands/health-codex-install.js.map +1 -1
  185. package/pd-cli/dist/commands/health-codex.d.ts.map +1 -1
  186. package/pd-cli/dist/commands/health-codex.js +27 -9
  187. package/pd-cli/dist/commands/health-codex.js.map +1 -1
  188. package/pd-cli/dist/commands/health-console.d.ts +2 -1
  189. package/pd-cli/dist/commands/health-console.d.ts.map +1 -1
  190. package/pd-cli/dist/commands/health-console.js +12 -3
  191. package/pd-cli/dist/commands/health-console.js.map +1 -1
  192. package/pd-cli/dist/commands/health-ingestion.d.ts +10 -2
  193. package/pd-cli/dist/commands/health-ingestion.d.ts.map +1 -1
  194. package/pd-cli/dist/commands/health-ingestion.js +56 -14
  195. package/pd-cli/dist/commands/health-ingestion.js.map +1 -1
  196. package/pd-cli/dist/commands/health-mcp.d.ts +19 -7
  197. package/pd-cli/dist/commands/health-mcp.d.ts.map +1 -1
  198. package/pd-cli/dist/commands/health-mcp.js +131 -45
  199. package/pd-cli/dist/commands/health-mcp.js.map +1 -1
  200. package/pd-cli/dist/commands/health-workbuddy.d.ts +2 -1
  201. package/pd-cli/dist/commands/health-workbuddy.d.ts.map +1 -1
  202. package/pd-cli/dist/commands/health-workbuddy.js +17 -8
  203. package/pd-cli/dist/commands/health-workbuddy.js.map +1 -1
  204. package/pd-cli/dist/commands/health.d.ts.map +1 -1
  205. package/pd-cli/dist/commands/health.js +12 -5
  206. package/pd-cli/dist/commands/health.js.map +1 -1
  207. package/pd-cli/dist/commands/mcp-probe.d.ts +6 -0
  208. package/pd-cli/dist/commands/mcp-probe.d.ts.map +1 -1
  209. package/pd-cli/dist/commands/mcp-probe.js +35 -7
  210. package/pd-cli/dist/commands/mcp-probe.js.map +1 -1
  211. package/pd-cli/dist/commands/pain-retry.d.ts.map +1 -1
  212. package/pd-cli/dist/commands/pain-retry.js +10 -2
  213. package/pd-cli/dist/commands/pain-retry.js.map +1 -1
  214. package/pd-cli/dist/commands/trace.d.ts.map +1 -1
  215. package/pd-cli/dist/commands/trace.js +8 -0
  216. package/pd-cli/dist/commands/trace.js.map +1 -1
  217. package/pd-cli/dist/commands/workbuddy-setup.d.ts.map +1 -1
  218. package/pd-cli/dist/commands/workbuddy-setup.js +7 -3
  219. package/pd-cli/dist/commands/workbuddy-setup.js.map +1 -1
  220. package/pd-cli/dist/commands/workbuddy-worker.d.ts.map +1 -1
  221. package/pd-cli/dist/commands/workbuddy-worker.js +21 -6
  222. package/pd-cli/dist/commands/workbuddy-worker.js.map +1 -1
  223. package/pd-cli/dist/services/admission-write-gate.d.ts +10 -1
  224. package/pd-cli/dist/services/admission-write-gate.d.ts.map +1 -1
  225. package/pd-cli/dist/services/admission-write-gate.js +12 -2
  226. package/pd-cli/dist/services/admission-write-gate.js.map +1 -1
  227. package/pd-cli/dist/services/codex-plugin-install.d.ts +1 -3
  228. package/pd-cli/dist/services/codex-plugin-install.d.ts.map +1 -1
  229. package/pd-cli/dist/services/codex-plugin-install.js +10 -3
  230. package/pd-cli/dist/services/codex-plugin-install.js.map +1 -1
  231. package/pd-cli/dist/services/pain-flood-simulation-runner.d.ts.map +1 -1
  232. package/pd-cli/dist/services/pain-flood-simulation-runner.js +2 -0
  233. package/pd-cli/dist/services/pain-flood-simulation-runner.js.map +1 -1
  234. package/pd-cli/dist/services/pd-config-loader.d.ts +2 -2
  235. package/pd-cli/dist/services/pd-config-loader.d.ts.map +1 -1
  236. package/pd-cli/dist/services/pd-config-loader.js +28 -20
  237. package/pd-cli/dist/services/pd-config-loader.js.map +1 -1
  238. package/pd-cli/dist/services/synthetic-baseline-runner.d.ts.map +1 -1
  239. package/pd-cli/dist/services/synthetic-baseline-runner.js +2 -0
  240. package/pd-cli/dist/services/synthetic-baseline-runner.js.map +1 -1
  241. package/pd-cli/package.json +1 -1
  242. package/pd-mcp-server/dist/log-file.js +9 -2
  243. package/pd-mcp-server/dist/server.d.ts +52 -2
  244. package/pd-mcp-server/dist/server.js +40 -4
  245. package/pd-mcp-server/dist/submit-assembly.js +85 -12
  246. package/pd-mcp-server/dist/version.d.ts +1 -1
  247. package/pd-mcp-server/dist/version.js +1 -1
  248. package/pd-mcp-server/package.json +1 -1
  249. package/plugin/dist/bundle.js +761 -722
  250. package/plugin/dist/commands/focus.d.ts +10 -7
  251. package/plugin/dist/commands/strategy.d.ts +10 -0
  252. package/plugin/dist/core/focus-history.d.ts +9 -49
  253. package/plugin/dist/core/paths.d.ts +6 -53
  254. package/plugin/dist/governance-audit.js +2 -2
  255. package/plugin/dist/hooks/prompt-helpers.d.ts +6 -5
  256. package/plugin/dist/hooks/prompt-types.d.ts +6 -6
  257. package/plugin/dist/openclaw.plugin.json +1 -1
  258. package/plugin/dist/rulehost-evidence.js +29 -29
  259. package/plugin/dist/templates/workspace/okr/RECOVERY_PROTOCOL.md +8 -7
  260. package/plugin/dist/utils/io.d.ts +1 -1
  261. package/plugin/dist/utils/workspace-resolver.d.ts +0 -20
  262. package/plugin/mcp/launcher.cjs +159 -35
  263. package/plugin/openclaw.plugin.json +1 -1
  264. package/plugin/package.json +1 -1
  265. package/plugin/templates/workspace/okr/RECOVERY_PROTOCOL.md +8 -7
  266. package/release-manager/dist/installer.js +627 -100
  267. package/release-manager/dist/installers/codex-host-installer.js +36 -20
  268. package/release-manager/dist/installers/index.js +24 -3
  269. package/release-manager/dist/installers/mcp-registration-conflict.js +23 -16
  270. package/release-manager/dist/installers/openclaw-host-installer.js +1 -8
  271. package/release-manager/dist/installers/workbuddy-host-installer.js +51 -15
  272. package/release-manager/dist/mvp-config.js +49 -16
  273. package/release-manager/dist/update/release-manager.js +5 -2
  274. package/release-manager/dist/utils/env.js +91 -34
  275. package/release-manager/dist/utils/host-workspace-ownership.js +153 -2
  276. package/release-manager/package.json +2 -2
  277. package/workbuddy-adapter/dist/index.d.ts +1 -1
  278. package/workbuddy-adapter/dist/index.js +1 -1
  279. package/workbuddy-adapter/dist/ingestion/catch-up.js +15 -3
  280. package/workbuddy-adapter/dist/ingestion/index.d.ts +1 -1
  281. package/workbuddy-adapter/dist/ingestion/index.js +1 -1
  282. package/workbuddy-adapter/dist/ingestion/ingestion.d.ts +18 -0
  283. package/workbuddy-adapter/dist/ingestion/ingestion.js +20 -2
  284. package/workbuddy-adapter/dist/ingestion/transcript-path.d.ts +13 -4
  285. package/workbuddy-adapter/dist/ingestion/transcript-path.js +102 -4
  286. package/workbuddy-adapter/dist/ingestion/transcript-source.js +76 -58
  287. package/workbuddy-adapter/dist/pd-hook.js +10 -3
  288. package/workbuddy-adapter/dist/worker/workspace-worker.js +4 -1
  289. package/workbuddy-adapter/dist/workspace-resolution.d.ts +9 -2
  290. package/workbuddy-adapter/dist/workspace-resolution.js +19 -3
  291. package/workbuddy-adapter/package.json +1 -1
  292. package/workbuddy-adapter/plugin/mcp/launcher.cjs +159 -35
  293. package/plugin/dist/templates/workspace/okr/CURRENT_FOCUS.md +0 -56
  294. package/plugin/dist/templates/workspace/okr/TASK_CHANGES.jsonl +0 -6
  295. package/plugin/dist/templates/workspace/okr/WEEK_TASKS.json +0 -6
  296. package/plugin/templates/workspace/okr/CURRENT_FOCUS.md +0 -56
  297. package/plugin/templates/workspace/okr/TASK_CHANGES.jsonl +0 -6
  298. package/plugin/templates/workspace/okr/WEEK_TASKS.json +0 -6
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "productVersion": "2.8.8",
4
- "sourceCommit": "57948395d8f4c8763027b95dd3e9463cba846bce"
4
+ "sourceCommit": "95de4c633aedd4d588286c665baf3af816f6250a"
5
5
  }
@@ -16,4 +16,5 @@ export type CodexHomeResolution = {
16
16
  export declare function canonicalizePath(target: string): string;
17
17
  export declare function resolveCodexHome(env?: {
18
18
  CODEX_HOME?: string | undefined;
19
+ PD_EXPERIMENT_ROOT?: string | undefined;
19
20
  }): CodexHomeResolution;
@@ -4,12 +4,12 @@
4
4
  *
5
5
  * Rules: CODEX_HOME, when set and non-empty, MUST already exist and be a
6
6
  * directory and is canonicalized; a missing path or a file path is an error.
7
- * When unset, the home comes from the OS home directory plus `.codex`, and
8
- * existence is NOT verified. There is one OS-generic implementation.
7
+ * When unset, the home comes from PD Home resolution (production: OS home
8
+ * plus `.codex`; experiment: <PD_EXPERIMENT_ROOT>/.codex), and existence is
9
+ * NOT verified. There is one OS-generic implementation.
9
10
  */
10
11
  import fs from 'node:fs';
11
- import os from 'node:os';
12
- import path from 'node:path';
12
+ import { resolvePdHome } from '@principles/install-layout';
13
13
  /**
14
14
  * Canonicalize a Windows path to its final long form. Node's JS realpath
15
15
  * preserves 8.3 short-name segments (ADMINI~1), while hook payloads carry
@@ -26,18 +26,30 @@ export function canonicalizePath(target) {
26
26
  }
27
27
  }
28
28
  export function resolveCodexHome(env = process.env) {
29
+ const pdHome = resolvePdHome({ env });
30
+ if (!pdHome.ok) {
31
+ return {
32
+ ok: false,
33
+ reason: 'pd_home_resolution_failed',
34
+ nextAction: `PD home resolution refused (${pdHome.reason}): ${pdHome.message} ${pdHome.nextAction}`,
35
+ };
36
+ }
29
37
  const configured = env.CODEX_HOME;
30
38
  if (configured !== undefined && configured.trim() !== '') {
39
+ // Validation and canonicalization run on the path resolvePdHome VERIFIED
40
+ // and returned (pdHome.codexHome), never on the raw env string: a symlinked
41
+ // CODEX_HOME must not pass its existence check on one path and then be
42
+ // consumed via another (validated path == used path).
31
43
  try {
32
- const stats = fs.statSync(configured);
44
+ const stats = fs.statSync(pdHome.codexHome);
33
45
  if (!stats.isDirectory()) {
34
46
  return { ok: false, reason: 'codex_home_not_directory', nextAction: 'CODEX_HOME must point at an existing directory (Codex fatal-error contract).' };
35
47
  }
36
- return { ok: true, home: canonicalizePath(configured) };
48
+ return { ok: true, home: canonicalizePath(pdHome.codexHome) };
37
49
  }
38
50
  catch {
39
51
  return { ok: false, reason: 'codex_home_unavailable', nextAction: 'CODEX_HOME is set but does not exist; unset it or create the directory.' };
40
52
  }
41
53
  }
42
- return { ok: true, home: path.join(os.homedir(), '.codex') };
54
+ return { ok: true, home: pdHome.codexHome };
43
55
  }
@@ -155,20 +155,31 @@ function codexVerifiedOutcomesPreIngest({ workspaceDir, delta, now: _now }) {
155
155
  }
156
156
  return { ok: true };
157
157
  }
158
+ /**
159
+ * PRI-1262: live and catch-up ingestion reuse the FORMAL consent judgment —
160
+ * the same v3 ledger `pd health` reads (`readConversationIngestionConsent`).
161
+ * The PRI-1171 phasing invariant 'granted' made the runtime ingest even when
162
+ * health reported `flag_on_without_grant`; now a missing / revoked / failed
163
+ * record degrades with `consent_not_granted:<decision>` BEFORE any transcript
164
+ * read, so runtime and health can no longer disagree. An unreadable ledger
165
+ * resolves to 'not_present' (fail closed — nothing is read).
166
+ */
167
+ function resolveCodexConsentGate(workspaceDir) {
168
+ const read = readConversationIngestionConsent(workspaceDir, 'codex');
169
+ const record = read.ok ? read.record : null;
170
+ return { decision: record?.decision ?? 'not_present' };
171
+ }
158
172
  function ingestTranscriptDelta({ fallbackRootSessionId, transcriptPath, workspaceDir, env, now, port }) {
159
173
  const outcome = runConversationIngestion({
160
174
  workspaceDir,
161
175
  source: createCodexTranscriptSource({ env, fallbackRootSessionId, now }),
162
176
  session: { sessionId: fallbackRootSessionId },
163
177
  hints: { transcriptPath },
164
- // PRI-1171 P1 phasing: the double FLAG gate (host.codex ∧
165
- // codex_conversation_ingestion) is checked by pd-hook / catch-up BEFORE
166
- // this module is entered, and the consent LEDGER remains the governance
167
- // record the setup flow enforces (v2 authority model — the runtime gate
168
- // reads only the flags). The pipeline's consent gate therefore keeps
169
- // receiving the setup-flow invariant 'granted'.
178
+ // The double FLAG gate (host.codex ∧ codex_conversation_ingestion) is
179
+ // checked by pd-hook / catch-up BEFORE this module is entered; the consent
180
+ // LEDGER gate below is the PRI-1262 formal judgment.
170
181
  flags: { ingestionEnabled: true },
171
- consent: { decision: 'granted' },
182
+ consent: resolveCodexConsentGate(workspaceDir),
172
183
  // PRI-1179: the STORED TEXT bound is a separate fact from the gate above —
173
184
  // it comes from the recorded v3 consent record, so a stale disclosure or a
174
185
  // revoke can only ever narrow what is stored, never widen it.
@@ -206,6 +217,22 @@ export function ingestCodexConversation(rawPayload, kind, options) {
206
217
  }
207
218
  const now = options.now ?? new Date();
208
219
  if (kind === 'before_prompt_build' || kind === 'after_tool_call') {
220
+ // PRI-1262 review fix (2026-11-18): the live path used to write the user
221
+ // prompt (and tool facts) WITHOUT the formal consent ledger judgment,
222
+ // contradicting this module's own contract comment — a revoked / pending /
223
+ // failed / absent ledger still captured the prompt as a bounded
224
+ // `user_turn`. Now the SAME `resolveCodexConsentGate` verdict the catch-up
225
+ // path applies gates the live write too: not granted → degrade with
226
+ // `consent_not_granted:<decision>` BEFORE any observation is stored.
227
+ const consent = resolveCodexConsentGate(options.workspaceDir);
228
+ if (consent.decision !== 'granted') {
229
+ return {
230
+ status: 'degraded',
231
+ reason: `consent_not_granted:${consent.decision}`,
232
+ nextAction: 'conversation ingestion consent is not granted for this workspace; grant it via the PD consent flow (or re-grant after revoke) before live PD behavior is captured.',
233
+ warnings: [],
234
+ };
235
+ }
209
236
  // Live observations key on the rollout identity derived from the SAME
210
237
  // validated transcript reference the Stop replay later converges with
211
238
  // (SPEC §10) — validate here exactly as before the seam migration.
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  import { readFileSync, realpathSync, statSync } from 'node:fs';
3
- import os from 'node:os';
4
3
  import path from 'node:path';
5
4
  import process from 'node:process';
6
5
  import { pathToFileURL, fileURLToPath } from 'node:url';
7
6
  import { appendEventLogLine, redactTelemetryString, isRuleHostEvaluatedEventData } from '@principles/core/runtime';
8
7
  import { ADAPTIVE_SELECTION_LIMITS, createAdaptivePriorityProviderForConfig, createCodexRuleContextProvider, createProductionHostRuntime, loadPdConfigForPlugin, renderAcceptedAdaptiveAppend, resolveHostToolSemanticsForHook, resolveNearestPdWorkspace } from '@principles/host-runtime';
8
+ import { resolvePdHome } from '@principles/install-layout';
9
9
  import { classifyBashRisk } from '@principles/core/runtime/internalization/bash-risk';
10
10
  import { CODEX_TOOL_SEMANTIC_MAPPINGS, CODEX_TOOL_SEMANTICS } from './tool-semantics.js';
11
11
  import { computeFeatureFlagsFromConfig } from '@principles/core/runtime';
@@ -48,7 +48,7 @@ function adaptiveSelectionDiagnostic(line) {
48
48
  const decision = line.decision === null
49
49
  ? 'unknown'
50
50
  : `${line.decision.status}:${line.decision.reason}:${line.decision.ref ?? 'none'}`;
51
- return `[PD] status=${status} reason=adaptive_selection_${line.status}:${line.reason} stage=${line.stage} sends=${line.sends} requestSentAt=${line.requestSentAt ?? 'unknown'} firstByteAt=${line.firstByteAt ?? 'unknown'} generationEndedAt=${line.generationEndedAt ?? 'unknown'} validatedAt=${line.validatedAt ?? 'unknown'} cancelledAt=${line.cancelledAt ?? 'unknown'} httpStatus=${line.httpStatus ?? 'unknown'} finishReason=${line.finishReason} modelObserved=${line.modelObserved ?? 'unknown'} providerObserved=${line.providerObserved ?? 'absent'} decision=${decision} scores=${scores} failures=${failures}`
51
+ return `[PD] status=${status} reason=adaptive_selection_${line.status}:${line.reason} stage=${line.stage} sends=${line.sends} principleContext=${line.principleContext ?? 'not_reached'} requestSentAt=${line.requestSentAt ?? 'unknown'} firstByteAt=${line.firstByteAt ?? 'unknown'} generationEndedAt=${line.generationEndedAt ?? 'unknown'} validatedAt=${line.validatedAt ?? 'unknown'} cancelledAt=${line.cancelledAt ?? 'unknown'} httpStatus=${line.httpStatus ?? 'unknown'} finishReason=${line.finishReason} modelObserved=${line.modelObserved ?? 'unknown'} providerObserved=${line.providerObserved ?? 'absent'} decision=${decision} scores=${scores} failures=${failures}`
52
52
  .replace(/\s+/g, ' ')
53
53
  .trim()
54
54
  .slice(0, MAX_DIAGNOSTIC * 2);
@@ -381,10 +381,17 @@ export async function processHookInvocation(rawStdin, _env = process.env, cwd =
381
381
  const requestedCwd = event.context.workspaceDir || cwd;
382
382
  if (!path.isAbsolute(requestedCwd))
383
383
  return { stdout: {}, exitCode: 0, stderr: [diagnostic('cwd_not_absolute', 'Provide the absolute Codex project directory.')] };
384
- // Resolve like pd-locate.cjs does: a relative CODEX_HOME must yield the same
385
- // absolute workspace for hooks and owner scripts, or resolveNearestPdWorkspace
386
- // rejects it after the config check already accepted it.
387
- const userWorkspace = path.join(path.resolve(_env.CODEX_HOME || path.join(os.homedir(), '.codex')), 'pd-workspace');
384
+ // Resolve the Codex user workspace through the same PD Home authority used
385
+ // by the installer and CLI, with the SAME home precedence (no explicit
386
+ // os.homedir() injection: that would bypass the HOME-first default and split
387
+ // the host config root from the installer's when HOME ≠ OS home — Devin
388
+ // review #2699-0006). In experiment mode this derives from the lab root and
389
+ // refuses inherited host paths that escape it.
390
+ const pdHome = resolvePdHome({ env: _env });
391
+ if (!pdHome.ok) {
392
+ return { stdout: {}, exitCode: 0, stderr: [diagnostic(pdHome.reason, pdHome.nextAction)] };
393
+ }
394
+ const userWorkspace = pdHome.codexWorkspaceDir;
388
395
  let userWorkspaceInitialized = false;
389
396
  try {
390
397
  userWorkspaceInitialized = statSync(path.join(userWorkspace, '.pd', 'config.yaml')).isFile();
@@ -590,6 +597,7 @@ export async function processHookInvocation(rawStdin, _env = process.env, cwd =
590
597
  reason: line.reason,
591
598
  sends: line.sends,
592
599
  targetActivationId: line.targetActivationId,
600
+ ...(line.principleContext !== undefined ? { principleContext: line.principleContext } : {}),
593
601
  };
594
602
  },
595
603
  });
@@ -28,7 +28,7 @@
28
28
  import fs from 'node:fs';
29
29
  import path from 'node:path';
30
30
  import { computeFeatureFlagsFromConfig, createRuntimeStateHandle, createPainSignalBridge, isRetryWaitBackoffElapsed, pickDiagnosticianCandidate, PrincipleTreeLedgerAdapter, resolveDiagnosticianCapability, } from '@principles/core/runtime';
31
- import { createWorkspaceBehaviorEvidencePort, createCodexArtificerTrustedFactsPort, loadPdConfigForPlugin, loadFeatureFlagFromConfig, reconcileGovernanceContinuation, runInternalizationConsumerCycle, runStage2CorrectionCycle, createSignalClassifierForWorkspace, createHostIntentDocReader, saveHostToolDeclaration, HOST_TOOL_DECLARATION_VERSION, } from '@principles/host-runtime';
31
+ import { createWorkspaceBehaviorEvidencePort, createCodexArtificerTrustedFactsPort, loadPdConfigForPlugin, loadFeatureFlagFromConfig, reconcileGovernanceContinuation, runInternalizationConsumerCycle, runStage2CorrectionCycle, createSignalClassifierForWorkspace, createGovernanceTrajectoryTurnReader, createHostIntentDocReader, saveHostToolDeclaration, HOST_TOOL_DECLARATION_VERSION, } from '@principles/host-runtime';
32
32
  import { catchUpCodexIngestion } from '../ingestion/catch-up.js';
33
33
  import { CODEX_TOOL_SEMANTIC_MAPPINGS, CODEX_TOOL_SEMANTICS } from '../tool-semantics.js';
34
34
  const WORKER_OWNER = 'companion-worker';
@@ -147,6 +147,22 @@ export async function runCodexWorkspaceWorkerCycle(options) {
147
147
  }
148
148
  const { flags } = computeFeatureFlagsFromConfig(config.effective);
149
149
  if (flags['host.codex']?.enabled !== true) {
150
+ // PRI-1264 review round (2026-11-18): an intentional CONFIG pause must
151
+ // keep the liveness heartbeat alive — the worker process IS alive and
152
+ // cycling, it is just deliberately idle. Without this heartbeat the
153
+ // Companion's stall detector (completion age > 2× interval) read the stale
154
+ // pre-pause record and raised a false `workspace_worker_stalled`
155
+ // notification whose "restart Companion" guidance could never fix the
156
+ // config pause. The workspace directory and config were already proven
157
+ // readable above (CR-08 ordering), so the write is legitimate.
158
+ writeLiveness(workspaceDir, {
159
+ runningStage: 'paused',
160
+ // Explicit null: a paused state has no in-flight stage, and the merge
161
+ // must not leave the PRE-pause cycle's deadline behind.
162
+ stageDeadline: null,
163
+ lastCycleStartedAt: cycleStartedAt.toISOString(),
164
+ lastCycleDriver: process.env.PD_INVOCATION_SOURCE === 'companion' ? 'companion' : 'manual',
165
+ });
150
166
  // PRI-1063 (review fix): single-line flow mapping — see catch-up.ts.
151
167
  return { ...base, mode: 'paused', reason: 'host.codex_disabled', nextAction: 'Enable Codex PD behavior in the Workspace .pd/config.yaml — in the existing "features:" block set host.codex: {enabled: true} (one flat key, not nested).' };
152
168
  }
@@ -156,6 +172,11 @@ export async function runCodexWorkspaceWorkerCycle(options) {
156
172
  lastCycleStartedAt: cycleStartedAt.toISOString(),
157
173
  runningStage: 'catch_up',
158
174
  stageDeadline: new Date(cycleStartedAt.getTime() + LIVENESS_STAGE_DEADLINE_MS.catch_up).toISOString(),
175
+ // PRI-1264: record WHO drove this cycle. `pd codex worker --status` reads
176
+ // the marker so the Owner can tell a companion-driven (resident, should
177
+ // keep cycling) worker from a manual one-shot — "registered" alone said
178
+ // nothing about whether a driver is actually alive.
179
+ lastCycleDriver: process.env.PD_INVOCATION_SOURCE === 'companion' ? 'companion' : 'manual',
159
180
  });
160
181
  const consumerFlag = loadFeatureFlagFromConfig(workspaceDir, 'internalization_auto_consumer', { info: (m) => logger.info(m), warn: (m) => logger.warn(m) });
161
182
  // PRI-638 P1-C: the Diagnostician capability gate is resolved from the same
@@ -234,6 +255,9 @@ export async function runCodexWorkspaceWorkerCycle(options) {
234
255
  // for governance-admitted Codex pains — the neutral host reader
235
256
  // must ride along (flag-off = zero filesystem access inside it).
236
257
  intentDocReader: createHostIntentDocReader({ workspaceDir, effectiveConfig: config.effective }),
258
+ // PRI-1265: the worker's Stage A gets the bound session's ORIGINAL
259
+ // turns from the workspace's own consent-tiered governance store.
260
+ trajectoryTurnReader: createGovernanceTrajectoryTurnReader({ workspaceDir }),
237
261
  });
238
262
  const executed = await bridge.executePendingDiagnosis({ taskId: candidate.taskId });
239
263
  // PRI-917 v0.3.3 review fix (P2-2): forward the parked-candidate
@@ -313,6 +337,9 @@ export async function runCodexWorkspaceWorkerCycle(options) {
313
337
  owner: WORKER_OWNER,
314
338
  effectiveConfig: config.effective,
315
339
  getEnvVar: (name) => process.env[name],
340
+ // PRI-1265: post-processing resumes see the same authorized
341
+ // trajectory context as the initial diagnosis run.
342
+ trajectoryTurnReader: createGovernanceTrajectoryTurnReader({ workspaceDir }),
316
343
  });
317
344
  for (const item of backlog) {
318
345
  const resumed = await bridge.resumeSucceededDiagnosisPostProcessing({ taskId: item.taskId });
@@ -436,6 +463,9 @@ export async function runCodexWorkspaceWorkerCycle(options) {
436
463
  lastCycleCompletedAt: new Date().toISOString(),
437
464
  lastCycleDurationMs: Date.now() - cycleStartedAt.getTime(),
438
465
  lastCycleMode: degradedReason !== undefined ? 'degraded' : 'ready',
466
+ // PRI-1264: driver of the last COMPLETED cycle — the stall verdict reads
467
+ // this so a no_recent_cycle report names WHO stopped driving.
468
+ lastCycleDriver: process.env.PD_INVOCATION_SOURCE === 'companion' ? 'companion' : 'manual',
439
469
  ...(degradedReason !== undefined ? { lastDegradedReason: degradedReason } : {}),
440
470
  });
441
471
  return {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@principles/codex-adapter",
3
- "version": "0.12.1",
3
+ "version": "0.13.0",
4
4
  "description": "Codex CLI host adapter for Principles Disciple — implements HostAdapter interface for OpenAI Codex CLI's stdin/stdout JSON hook model (ADR-0020).",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -42,7 +42,6 @@ import { handleUpdateHistoryRoute, handleUpdateHistoryPruneRoute, reconcileUpdat
42
42
  import { handleUpdateTransactionRoute } from './routes/update-transaction.js';
43
43
  import { handleConfigRoute } from './routes/config.js';
44
44
  import { sendJson, sendNotFound, sendError } from './utils/response.js';
45
- import { migrateLegacyExtensionBackups, resolvePdBackupsRoot } from './utils/pd-backups.js';
46
45
  const __filename = fileURLToPath(import.meta.url);
47
46
  const __dirname = path.dirname(__filename);
48
47
  // WEB_ROOT calculation: server is at PKG_ROOT/dist/server/index.js
@@ -708,21 +707,11 @@ export async function main() {
708
707
  // application-level credential, so it must never be reachable off-machine.
709
708
  assertLoopbackBind(host);
710
709
  const services = await initServices(workspace);
711
- // One-time hygiene: move legacy PD backups out of ~/.openclaw/extensions so
712
- // OpenClaw plugin discovery stops reporting a duplicate principles-disciple
713
- // plugin on every gateway startup. Best-effort, never blocks startup.
714
- try {
715
- const legacy = migrateLegacyExtensionBackups();
716
- if (legacy.movedFrom.length > 0) {
717
- console.log(`[pd-console] Migrated ${legacy.movedFrom.length} legacy PD backup dir(s) out of the extensions dir to ${resolvePdBackupsRoot()}`);
718
- }
719
- for (const failure of legacy.failed) {
720
- console.warn(`[pd-console] Could not migrate legacy PD backup "${failure.name}" out of the extensions dir: ${failure.reason}. Move it out manually to silence the OpenClaw "duplicate plugin id" warning.`);
721
- }
722
- }
723
- catch (err) {
724
- console.warn('[pd-console] Legacy backup migration failed:', err instanceof Error ? err.message : err);
725
- }
710
+ // Backups live in the canonical <PD_HOME>/.pd/backups root and the Console
711
+ // only ever reads/uses that location. Relocating legacy backup directories
712
+ // (the old <openclawHome>/pd-backups root, extensions/ siblings) is an
713
+ // EXPLICIT installer operation — never an implicit console-startup move of
714
+ // Owner files.
726
715
  const server = http.createServer(handleRequest(services));
727
716
  // Anonymous Product Telemetry v1 (PRI-595~603): one fire-and-forget export
728
717
  // attempt per console startup. The console process is the long-lived PD
@@ -12,7 +12,7 @@
12
12
  */
13
13
  import * as fs from 'fs';
14
14
  import * as path from 'path';
15
- import { getInstallLayoutPaths, resolveInstallLayout } from '@principles/install-layout';
15
+ import { getInstallLayoutPathsFromPdHome, resolveInstallLayout } from '@principles/install-layout';
16
16
  import { resolveOpenClawHome } from './pd-backups.js';
17
17
  import { getPdHome } from './pd-home.js';
18
18
  export function resolveExtensionsDir() {
@@ -44,8 +44,9 @@ function resolveCanonicalCodexAdapterDir(paths) {
44
44
  export function resolveUpdateLayout() {
45
45
  // PRI-872: the home comes from the process-wide resolution, so an experiment
46
46
  // console inspects the EXPERIMENT install instead of the production one.
47
- const { homeDir } = getPdHome();
48
- const paths = getInstallLayoutPaths(homeDir);
47
+ const homePaths = getPdHome();
48
+ const { homeDir } = homePaths;
49
+ const paths = getInstallLayoutPathsFromPdHome(homePaths);
49
50
  const legacyPluginDir = path.join(resolveExtensionsDir(), 'principles-disciple');
50
51
  let manifest;
51
52
  try {
@@ -56,6 +57,7 @@ export function resolveUpdateLayout() {
56
57
  }
57
58
  const resolution = resolveInstallLayout({
58
59
  homeDir,
60
+ homePaths,
59
61
  manifest,
60
62
  canonicalRuntimeExists: fs.existsSync(paths.runtimeDir),
61
63
  legacyExtensionExists: fs.existsSync(legacyPluginDir),
@@ -101,7 +103,7 @@ export function resolvePluginDir(_workspaceDir) {
101
103
  * guard allow-root even when the install resolves to legacy mode.
102
104
  */
103
105
  export function resolveCanonicalRuntimeRoot() {
104
- return getInstallLayoutPaths(getPdHome().homeDir).runtimeDir;
106
+ return getPdHome().runtimeDir;
105
107
  }
106
108
  // rc-2: type-guard the parsed JSON instead of an `as` cast (ERR-001).
107
109
  function isRecord(value) {
@@ -1,10 +1,3 @@
1
- export interface LegacyBackupMigrationResult {
2
- movedFrom: string[];
3
- failed: {
4
- name: string;
5
- reason: string;
6
- }[];
7
- }
8
1
  /**
9
2
  * Resolve the OpenClaw install home.
10
3
  *
@@ -16,7 +9,7 @@ export interface LegacyBackupMigrationResult {
16
9
  * `utils/installed-layout.ts` both derive from it.
17
10
  */
18
11
  export declare function resolveOpenClawHome(): string;
19
- /** Backups root — outside the extensions dir OpenClaw scans for plugins. */
12
+ /** Host-neutral backup root — outside every host plugin discovery directory. */
20
13
  export declare function resolvePdBackupsRoot(): string;
21
14
  /**
22
15
  * Reserve a unique backup destination under the backups root:
@@ -27,9 +20,3 @@ export declare function resolvePdBackupsRoot(): string;
27
20
  * unbounded).
28
21
  */
29
22
  export declare function reservePdBackupDestination(targetName: string): string;
30
- /**
31
- * Move legacy PD backup directories out of the extensions dir into the
32
- * backups root, so OpenClaw stops discovering them as duplicate plugins.
33
- * Best-effort per entry (rc-9: failures are reported, never silent).
34
- */
35
- export declare function migrateLegacyExtensionBackups(): LegacyBackupMigrationResult;
@@ -1,18 +1,17 @@
1
1
  /**
2
2
  * PD plugin backup location utilities.
3
3
  *
4
- * Backups must NEVER live inside ~/.openclaw/extensions: OpenClaw's plugin
5
- * discovery scans every child directory of the extensions root, so a backup
6
- * containing package.json (openclaw.extensions) + dist/bundle.js is discovered
7
- * as a SECOND "principles-disciple" plugin, producing
8
- * "duplicate plugin id detected; global plugin will be overridden by global
9
- * plugin" on every gateway startup.
4
+ * Backups must NEVER live inside any host plugin discovery tree. OpenClaw scans
5
+ * every child directory of its extensions root, so a backup containing
6
+ * package.json (openclaw.extensions) + dist/bundle.js would be discovered as a
7
+ * second plugin. All host and runtime backups therefore live in the shared
8
+ * <PD_HOME>/.pd/backups directory.
10
9
  *
11
- * Backups therefore live in <openclawHome>/pd-backups, which is outside every
12
- * plugin discovery root. Legacy backups that older PD versions left inside
13
- * extensions/ (".pd-backup-<ts>" from the console updater,
14
- * "principles-disciple.backup.<ms>" from the installer) are migrated out by
15
- * migrateLegacyExtensionBackups().
10
+ * The Console only ever USES this canonical root. Migrating legacy backups out
11
+ * of the old <openclawHome>/pd-backups root and the extensions/ siblings is an
12
+ * EXPLICIT installer operation (create-principles-disciple
13
+ * migrateLegacyPdBackups) — the Console never relocates user files on startup
14
+ * (PD迁移策略: 安装器显式迁移; Companion/Console 不隐式搬迁).
16
15
  */
17
16
  import * as fs from 'fs';
18
17
  import * as path from 'path';
@@ -31,9 +30,9 @@ import { getPdHome } from './pd-home.js';
31
30
  export function resolveOpenClawHome() {
32
31
  return getPdHome().openclawHome;
33
32
  }
34
- /** Backups root — outside the extensions dir OpenClaw scans for plugins. */
33
+ /** Host-neutral backup root — outside every host plugin discovery directory. */
35
34
  export function resolvePdBackupsRoot() {
36
- return path.join(resolveOpenClawHome(), 'pd-backups');
35
+ return getPdHome().pdRuntimeBackupsDir;
37
36
  }
38
37
  /**
39
38
  * Extract a POSIX errno code from a thrown fs error (rc-2: type guard, no
@@ -76,54 +75,3 @@ export function reservePdBackupDestination(targetName) {
76
75
  }
77
76
  throw new Error(`Could not reserve a unique backup directory under ${root}: ${errorMessage(lastError)}`);
78
77
  }
79
- /**
80
- * Backup directory names older PD versions created as siblings of the plugin
81
- * inside the extensions dir (both are re-discovered as duplicate plugins).
82
- */
83
- function isLegacyPdBackupName(name) {
84
- // Console updater (<= 2026-08): ".pd-backup-<ISO ts>" sibling.
85
- if (name.startsWith('.pd-backup-'))
86
- return true;
87
- // Installer (<= 2026-08): "<extDir>.backup.<epoch ms>" sibling.
88
- return /^principles-disciple\.backup\.\d+$/.test(name);
89
- }
90
- /**
91
- * Move legacy PD backup directories out of the extensions dir into the
92
- * backups root, so OpenClaw stops discovering them as duplicate plugins.
93
- * Best-effort per entry (rc-9: failures are reported, never silent).
94
- */
95
- export function migrateLegacyExtensionBackups() {
96
- const result = { movedFrom: [], failed: [] };
97
- const extensionsDir = path.join(resolveOpenClawHome(), 'extensions');
98
- let entries;
99
- try {
100
- entries = fs.readdirSync(extensionsDir, { withFileTypes: true });
101
- }
102
- catch {
103
- return result; // no extensions dir — nothing to migrate
104
- }
105
- const root = resolvePdBackupsRoot();
106
- for (const entry of entries) {
107
- if (!entry.isDirectory() || !isLegacyPdBackupName(entry.name))
108
- continue;
109
- const from = path.join(extensionsDir, entry.name);
110
- let to = path.join(root, entry.name);
111
- let suffix = 1;
112
- while (fs.existsSync(to)) {
113
- to = path.join(root, `${entry.name}-${suffix}`);
114
- suffix += 1;
115
- }
116
- try {
117
- fs.mkdirSync(root, { recursive: true });
118
- fs.renameSync(from, to);
119
- result.movedFrom.push(from);
120
- }
121
- catch (err) {
122
- result.failed.push({
123
- name: entry.name,
124
- reason: errorMessage(err),
125
- });
126
- }
127
- }
128
- return result;
129
- }