create-principles-disciple 1.154.5 → 1.155.1

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 (409) hide show
  1. package/_release/product-identity.json +2 -2
  2. package/codex-adapter/dist/codec/input-decoder.d.ts +17 -0
  3. package/codex-adapter/dist/codec/input-decoder.js +39 -0
  4. package/codex-adapter/dist/ingestion/explicit-owner-statement.js +125 -1
  5. package/codex-adapter/dist/ingestion/pain-receipt-fallback.d.ts +46 -0
  6. package/codex-adapter/dist/ingestion/pain-receipt-fallback.js +193 -0
  7. package/codex-adapter/dist/ingestion/turn-context.d.ts +10 -15
  8. package/codex-adapter/dist/ingestion/turn-context.js +35 -9
  9. package/codex-adapter/dist/pd-hook.js +57 -1
  10. package/codex-adapter/dist/worker/workspace-worker.d.ts +15 -0
  11. package/codex-adapter/dist/worker/workspace-worker.js +91 -12
  12. package/codex-adapter/package.json +1 -1
  13. package/console/dist/server/index.js +10 -0
  14. package/console/dist/server/models/EvidenceChainConsoleModel.js +31 -0
  15. package/console/dist/server/routes/service-host.d.ts +19 -0
  16. package/console/dist/server/routes/service-host.js +129 -0
  17. package/console/dist/web/assets/app.js +37 -37
  18. package/core/dist/runtime/context-payload.d.ts +48 -0
  19. package/core/dist/runtime/context-payload.d.ts.map +1 -1
  20. package/core/dist/runtime/context-payload.js +12 -0
  21. package/core/dist/runtime/context-payload.js.map +1 -1
  22. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.d.ts.map +1 -1
  23. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.js +18 -0
  24. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.js.map +1 -1
  25. package/core/dist/runtime/diagnostician-candidate.d.ts.map +1 -1
  26. package/core/dist/runtime/diagnostician-candidate.js +18 -2
  27. package/core/dist/runtime/diagnostician-candidate.js.map +1 -1
  28. package/core/dist/runtime/evidence-guards.d.ts +7 -3
  29. package/core/dist/runtime/evidence-guards.d.ts.map +1 -1
  30. package/core/dist/runtime/evidence-guards.js +9 -7
  31. package/core/dist/runtime/evidence-guards.js.map +1 -1
  32. package/core/dist/runtime/feature-flags/feature-flag-contract.d.ts.map +1 -1
  33. package/core/dist/runtime/feature-flags/feature-flag-contract.js +14 -0
  34. package/core/dist/runtime/feature-flags/feature-flag-contract.js.map +1 -1
  35. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.d.ts.map +1 -1
  36. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js +8 -0
  37. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js.map +1 -1
  38. package/core/dist/runtime/host-submission-context.d.ts +83 -0
  39. package/core/dist/runtime/host-submission-context.d.ts.map +1 -0
  40. package/core/dist/runtime/host-submission-context.js +183 -0
  41. package/core/dist/runtime/host-submission-context.js.map +1 -0
  42. package/core/dist/runtime/index.d.ts +9 -2
  43. package/core/dist/runtime/index.d.ts.map +1 -1
  44. package/core/dist/runtime/index.js +29 -2
  45. package/core/dist/runtime/index.js.map +1 -1
  46. package/core/dist/runtime/intent/intent-doc.d.ts.map +1 -1
  47. package/core/dist/runtime/intent/intent-doc.js +29 -5
  48. package/core/dist/runtime/intent/intent-doc.js.map +1 -1
  49. package/core/dist/runtime/internalization/diag-distiller-runner.d.ts +9 -0
  50. package/core/dist/runtime/internalization/diag-distiller-runner.d.ts.map +1 -1
  51. package/core/dist/runtime/internalization/diag-distiller-runner.js +13 -0
  52. package/core/dist/runtime/internalization/diag-distiller-runner.js.map +1 -1
  53. package/core/dist/runtime/internalization/diag-rootcause-runner.d.ts +11 -0
  54. package/core/dist/runtime/internalization/diag-rootcause-runner.d.ts.map +1 -1
  55. package/core/dist/runtime/internalization/diag-rootcause-runner.js +10 -0
  56. package/core/dist/runtime/internalization/diag-rootcause-runner.js.map +1 -1
  57. package/core/dist/runtime/internalization/diag-router-runner.d.ts +9 -0
  58. package/core/dist/runtime/internalization/diag-router-runner.d.ts.map +1 -1
  59. package/core/dist/runtime/internalization/diag-router-runner.js +13 -0
  60. package/core/dist/runtime/internalization/diag-router-runner.js.map +1 -1
  61. package/core/dist/runtime/internalization/index.d.ts +1 -1
  62. package/core/dist/runtime/internalization/index.d.ts.map +1 -1
  63. package/core/dist/runtime/internalization/index.js +1 -1
  64. package/core/dist/runtime/internalization/index.js.map +1 -1
  65. package/core/dist/runtime/internalization/intake-to-internalization-bridge.d.ts +19 -0
  66. package/core/dist/runtime/internalization/intake-to-internalization-bridge.d.ts.map +1 -1
  67. package/core/dist/runtime/internalization/intake-to-internalization-bridge.js +24 -0
  68. package/core/dist/runtime/internalization/intake-to-internalization-bridge.js.map +1 -1
  69. package/core/dist/runtime/internalization/internalization-orchestrator.d.ts +8 -0
  70. package/core/dist/runtime/internalization/internalization-orchestrator.d.ts.map +1 -1
  71. package/core/dist/runtime/internalization/internalization-orchestrator.js +36 -4
  72. package/core/dist/runtime/internalization/internalization-orchestrator.js.map +1 -1
  73. package/core/dist/runtime/internalization/source-authorization-boundary.d.ts +39 -0
  74. package/core/dist/runtime/internalization/source-authorization-boundary.d.ts.map +1 -0
  75. package/core/dist/runtime/internalization/source-authorization-boundary.js +57 -0
  76. package/core/dist/runtime/internalization/source-authorization-boundary.js.map +1 -0
  77. package/core/dist/runtime/internalization/split-diagnostician-runner.d.ts.map +1 -1
  78. package/core/dist/runtime/internalization/split-diagnostician-runner.js +72 -5
  79. package/core/dist/runtime/internalization/split-diagnostician-runner.js.map +1 -1
  80. package/core/dist/runtime/pain-admission-disposition.d.ts +60 -0
  81. package/core/dist/runtime/pain-admission-disposition.d.ts.map +1 -0
  82. package/core/dist/runtime/pain-admission-disposition.js +37 -0
  83. package/core/dist/runtime/pain-admission-disposition.js.map +1 -0
  84. package/core/dist/runtime/pain-ingress-payload.d.ts +36 -2
  85. package/core/dist/runtime/pain-ingress-payload.d.ts.map +1 -1
  86. package/core/dist/runtime/pain-ingress-payload.js +63 -6
  87. package/core/dist/runtime/pain-ingress-payload.js.map +1 -1
  88. package/core/dist/runtime/pain-ingress.d.ts.map +1 -1
  89. package/core/dist/runtime/pain-ingress.js +28 -0
  90. package/core/dist/runtime/pain-ingress.js.map +1 -1
  91. package/core/dist/runtime/pain-recall-read-model.d.ts +13 -1
  92. package/core/dist/runtime/pain-recall-read-model.d.ts.map +1 -1
  93. package/core/dist/runtime/pain-recall-read-model.js +50 -7
  94. package/core/dist/runtime/pain-recall-read-model.js.map +1 -1
  95. package/core/dist/runtime/pain-receipt-recovery.d.ts +147 -0
  96. package/core/dist/runtime/pain-receipt-recovery.d.ts.map +1 -0
  97. package/core/dist/runtime/pain-receipt-recovery.js +475 -0
  98. package/core/dist/runtime/pain-receipt-recovery.js.map +1 -0
  99. package/core/dist/runtime/pain-signal-bridge.d.ts +13 -1
  100. package/core/dist/runtime/pain-signal-bridge.d.ts.map +1 -1
  101. package/core/dist/runtime/pain-signal-bridge.js +174 -0
  102. package/core/dist/runtime/pain-signal-bridge.js.map +1 -1
  103. package/core/dist/runtime/pain-signal-runtime-factory.d.ts +9 -0
  104. package/core/dist/runtime/pain-signal-runtime-factory.d.ts.map +1 -1
  105. package/core/dist/runtime/pain-signal-runtime-factory.js +8 -3
  106. package/core/dist/runtime/pain-signal-runtime-factory.js.map +1 -1
  107. package/core/dist/runtime/pain-submit-capability.d.ts +11 -0
  108. package/core/dist/runtime/pain-submit-capability.d.ts.map +1 -1
  109. package/core/dist/runtime/pain-submit-capability.js +77 -3
  110. package/core/dist/runtime/pain-submit-capability.js.map +1 -1
  111. package/core/dist/runtime/pain-target-evidence-reconcile.d.ts +55 -0
  112. package/core/dist/runtime/pain-target-evidence-reconcile.d.ts.map +1 -0
  113. package/core/dist/runtime/pain-target-evidence-reconcile.js +164 -0
  114. package/core/dist/runtime/pain-target-evidence-reconcile.js.map +1 -0
  115. package/core/dist/runtime/pain-to-principle-service.d.ts +8 -0
  116. package/core/dist/runtime/pain-to-principle-service.d.ts.map +1 -1
  117. package/core/dist/runtime/pain-to-principle-service.js +1 -0
  118. package/core/dist/runtime/pain-to-principle-service.js.map +1 -1
  119. package/core/dist/runtime/source-material-authorization.d.ts +166 -0
  120. package/core/dist/runtime/source-material-authorization.d.ts.map +1 -0
  121. package/core/dist/runtime/source-material-authorization.js +250 -0
  122. package/core/dist/runtime/source-material-authorization.js.map +1 -0
  123. package/core/dist/runtime/store/context/index.d.ts +1 -0
  124. package/core/dist/runtime/store/context/index.d.ts.map +1 -1
  125. package/core/dist/runtime/store/context/index.js +1 -0
  126. package/core/dist/runtime/store/context/index.js.map +1 -1
  127. package/core/dist/runtime/store/context/promoted-evidence-reader.d.ts +8 -0
  128. package/core/dist/runtime/store/context/promoted-evidence-reader.d.ts.map +1 -1
  129. package/core/dist/runtime/store/context/promoted-evidence-reader.js +15 -1
  130. package/core/dist/runtime/store/context/promoted-evidence-reader.js.map +1 -1
  131. package/core/dist/runtime/store/context/sqlite-context-assembler.d.ts +22 -0
  132. package/core/dist/runtime/store/context/sqlite-context-assembler.d.ts.map +1 -1
  133. package/core/dist/runtime/store/context/sqlite-context-assembler.js +153 -3
  134. package/core/dist/runtime/store/context/sqlite-context-assembler.js.map +1 -1
  135. package/core/dist/runtime/store/context/trajectory-turn-reader.d.ts +13 -0
  136. package/core/dist/runtime/store/context/trajectory-turn-reader.d.ts.map +1 -1
  137. package/core/dist/runtime/store/lifecycle/lease-manager.d.ts +15 -0
  138. package/core/dist/runtime/store/lifecycle/lease-manager.d.ts.map +1 -1
  139. package/core/dist/runtime/store/lifecycle/lease-manager.js +16 -1
  140. package/core/dist/runtime/store/lifecycle/lease-manager.js.map +1 -1
  141. package/core/dist/runtime/store/runtime-state-manager.d.ts +2 -0
  142. package/core/dist/runtime/store/runtime-state-manager.d.ts.map +1 -1
  143. package/core/dist/runtime/store/runtime-state-manager.js.map +1 -1
  144. package/core/dist/runtime/store/task/memory-task-store.d.ts +1 -0
  145. package/core/dist/runtime/store/task/memory-task-store.d.ts.map +1 -1
  146. package/core/dist/runtime/store/task/memory-task-store.js +37 -0
  147. package/core/dist/runtime/store/task/memory-task-store.js.map +1 -1
  148. package/core/dist/runtime/store/task/sqlite-task-store.d.ts +10 -0
  149. package/core/dist/runtime/store/task/sqlite-task-store.d.ts.map +1 -1
  150. package/core/dist/runtime/store/task/sqlite-task-store.js +20 -0
  151. package/core/dist/runtime/store/task/sqlite-task-store.js.map +1 -1
  152. package/core/dist/runtime/store/task/task-store.d.ts +16 -0
  153. package/core/dist/runtime/store/task/task-store.d.ts.map +1 -1
  154. package/core/dist/runtime/task-status.d.ts +13 -0
  155. package/core/dist/runtime/task-status.d.ts.map +1 -1
  156. package/core/dist/runtime/task-status.js +9 -0
  157. package/core/dist/runtime/task-status.js.map +1 -1
  158. package/core/dist/runtime/types/evidence-chain-contract.d.ts +10 -0
  159. package/core/dist/runtime/types/evidence-chain-contract.d.ts.map +1 -1
  160. package/core/dist/runtime/types/evidence-chain-contract.js +7 -0
  161. package/core/dist/runtime/types/evidence-chain-contract.js.map +1 -1
  162. package/core/package.json +1 -1
  163. package/dist/index.d.ts.map +1 -1
  164. package/dist/index.js +11 -0
  165. package/dist/index.js.map +1 -1
  166. package/dist/installer.d.ts.map +1 -1
  167. package/dist/installer.js +77 -30
  168. package/dist/installer.js.map +1 -1
  169. package/dist/installers/mcp-registration-conflict.d.ts +8 -0
  170. package/dist/installers/mcp-registration-conflict.d.ts.map +1 -1
  171. package/dist/installers/mcp-registration-conflict.js +34 -1
  172. package/dist/installers/mcp-registration-conflict.js.map +1 -1
  173. package/dist/installers/workbuddy-host-installer.d.ts +45 -13
  174. package/dist/installers/workbuddy-host-installer.d.ts.map +1 -1
  175. package/dist/installers/workbuddy-host-installer.js +284 -21
  176. package/dist/installers/workbuddy-host-installer.js.map +1 -1
  177. package/dist/prompts.d.ts +11 -0
  178. package/dist/prompts.d.ts.map +1 -1
  179. package/dist/prompts.js +4 -0
  180. package/dist/prompts.js.map +1 -1
  181. package/dist/service-host-bridge.d.ts +67 -0
  182. package/dist/service-host-bridge.d.ts.map +1 -0
  183. package/dist/service-host-bridge.js +292 -0
  184. package/dist/service-host-bridge.js.map +1 -0
  185. package/dist/uninstaller.d.ts.map +1 -1
  186. package/dist/uninstaller.js +26 -0
  187. package/dist/uninstaller.js.map +1 -1
  188. package/dist/update/install-layout.d.ts +0 -12
  189. package/dist/update/install-layout.d.ts.map +1 -1
  190. package/dist/update/install-layout.js +42 -15
  191. package/dist/update/install-layout.js.map +1 -1
  192. package/host-runtime/dist/diagnostician-auto-run.js +4 -1
  193. package/host-runtime/dist/governance-observation-store.d.ts +7 -0
  194. package/host-runtime/dist/governance-observation-store.js +15 -4
  195. package/host-runtime/dist/governance-signal-admission.d.ts +49 -0
  196. package/host-runtime/dist/governance-signal-admission.js +355 -94
  197. package/host-runtime/dist/governance-trajectory-turn-reader.d.ts +20 -4
  198. package/host-runtime/dist/governance-trajectory-turn-reader.js +77 -5
  199. package/host-runtime/dist/index.d.ts +2 -0
  200. package/host-runtime/dist/index.js +5 -0
  201. package/host-runtime/dist/internalization-consumer-cycle.js +4 -1
  202. package/host-runtime/dist/pd-config.d.ts +10 -0
  203. package/host-runtime/dist/pd-config.js +37 -0
  204. package/host-runtime/dist/signal-stage2-cycle.js +28 -1
  205. package/host-runtime/dist/source-material-authorization.d.ts +53 -0
  206. package/host-runtime/dist/source-material-authorization.js +67 -0
  207. package/host-runtime/dist/source-revocation-sweep.d.ts +172 -0
  208. package/host-runtime/dist/source-revocation-sweep.js +928 -0
  209. package/host-runtime/package.json +5 -1
  210. package/install-layout/dist/background-execution-transition.d.ts +258 -0
  211. package/install-layout/dist/background-execution-transition.js +836 -0
  212. package/install-layout/dist/index.d.ts +8 -0
  213. package/install-layout/dist/index.js +8 -0
  214. package/install-layout/package.json +6 -2
  215. package/package.json +4 -4
  216. package/pd-cli/dist/commands/candidate.d.ts.map +1 -1
  217. package/pd-cli/dist/commands/candidate.js +16 -5
  218. package/pd-cli/dist/commands/candidate.js.map +1 -1
  219. package/pd-cli/dist/commands/codex-setup.d.ts.map +1 -1
  220. package/pd-cli/dist/commands/codex-setup.js +17 -1
  221. package/pd-cli/dist/commands/codex-setup.js.map +1 -1
  222. package/pd-cli/dist/commands/codex-worker.d.ts.map +1 -1
  223. package/pd-cli/dist/commands/codex-worker.js +8 -4
  224. package/pd-cli/dist/commands/codex-worker.js.map +1 -1
  225. package/pd-cli/dist/commands/consent-sweep-revoked.d.ts +20 -0
  226. package/pd-cli/dist/commands/consent-sweep-revoked.d.ts.map +1 -0
  227. package/pd-cli/dist/commands/consent-sweep-revoked.js +85 -0
  228. package/pd-cli/dist/commands/consent-sweep-revoked.js.map +1 -0
  229. package/pd-cli/dist/commands/context.d.ts.map +1 -1
  230. package/pd-cli/dist/commands/context.js +9 -1
  231. package/pd-cli/dist/commands/context.js.map +1 -1
  232. package/pd-cli/dist/commands/diagnose.d.ts.map +1 -1
  233. package/pd-cli/dist/commands/diagnose.js +12 -6
  234. package/pd-cli/dist/commands/diagnose.js.map +1 -1
  235. package/pd-cli/dist/commands/openclaw-worker.d.ts +11 -0
  236. package/pd-cli/dist/commands/openclaw-worker.d.ts.map +1 -0
  237. package/pd-cli/dist/commands/openclaw-worker.js +199 -0
  238. package/pd-cli/dist/commands/openclaw-worker.js.map +1 -0
  239. package/pd-cli/dist/commands/pain-explicit.d.ts.map +1 -1
  240. package/pd-cli/dist/commands/pain-explicit.js +1 -0
  241. package/pd-cli/dist/commands/pain-explicit.js.map +1 -1
  242. package/pd-cli/dist/commands/pain-recall.d.ts +2 -2
  243. package/pd-cli/dist/commands/pain-recall.d.ts.map +1 -1
  244. package/pd-cli/dist/commands/pain-recall.js +7 -1
  245. package/pd-cli/dist/commands/pain-recall.js.map +1 -1
  246. package/pd-cli/dist/commands/pain-retry.d.ts.map +1 -1
  247. package/pd-cli/dist/commands/pain-retry.js +12 -6
  248. package/pd-cli/dist/commands/pain-retry.js.map +1 -1
  249. package/pd-cli/dist/commands/runtime-internalization-enqueue-successors.d.ts.map +1 -1
  250. package/pd-cli/dist/commands/runtime-internalization-enqueue-successors.js +2 -1
  251. package/pd-cli/dist/commands/runtime-internalization-enqueue-successors.js.map +1 -1
  252. package/pd-cli/dist/commands/runtime-internalization-run-once.d.ts +1 -0
  253. package/pd-cli/dist/commands/runtime-internalization-run-once.d.ts.map +1 -1
  254. package/pd-cli/dist/commands/runtime-internalization-run-once.js +32 -8
  255. package/pd-cli/dist/commands/runtime-internalization-run-once.js.map +1 -1
  256. package/pd-cli/dist/commands/runtime-internalization-wake-once.d.ts.map +1 -1
  257. package/pd-cli/dist/commands/runtime-internalization-wake-once.js +2 -1
  258. package/pd-cli/dist/commands/runtime-internalization-wake-once.js.map +1 -1
  259. package/pd-cli/dist/commands/service-handover.d.ts +12 -0
  260. package/pd-cli/dist/commands/service-handover.d.ts.map +1 -0
  261. package/pd-cli/dist/commands/service-handover.js +117 -0
  262. package/pd-cli/dist/commands/service-handover.js.map +1 -0
  263. package/pd-cli/dist/commands/service-lifecycle.d.ts +31 -0
  264. package/pd-cli/dist/commands/service-lifecycle.d.ts.map +1 -0
  265. package/pd-cli/dist/commands/service-lifecycle.js +207 -0
  266. package/pd-cli/dist/commands/service-lifecycle.js.map +1 -0
  267. package/pd-cli/dist/commands/service-run-once.d.ts +96 -0
  268. package/pd-cli/dist/commands/service-run-once.d.ts.map +1 -1
  269. package/pd-cli/dist/commands/service-run-once.js +432 -13
  270. package/pd-cli/dist/commands/service-run-once.js.map +1 -1
  271. package/pd-cli/dist/commands/workbuddy-setup.d.ts.map +1 -1
  272. package/pd-cli/dist/commands/workbuddy-setup.js +22 -2
  273. package/pd-cli/dist/commands/workbuddy-setup.js.map +1 -1
  274. package/pd-cli/dist/program.d.ts.map +1 -1
  275. package/pd-cli/dist/program.js +167 -9
  276. package/pd-cli/dist/program.js.map +1 -1
  277. package/pd-cli/dist/services/admission-write-gate.d.ts +3 -1
  278. package/pd-cli/dist/services/admission-write-gate.d.ts.map +1 -1
  279. package/pd-cli/dist/services/admission-write-gate.js +1 -0
  280. package/pd-cli/dist/services/admission-write-gate.js.map +1 -1
  281. package/pd-cli/dist/services/service-host/coordinator-common.d.ts +49 -0
  282. package/pd-cli/dist/services/service-host/coordinator-common.d.ts.map +1 -0
  283. package/pd-cli/dist/services/service-host/coordinator-common.js +158 -0
  284. package/pd-cli/dist/services/service-host/coordinator-common.js.map +1 -0
  285. package/pd-cli/dist/services/service-host/handover-claims.d.ts +14 -0
  286. package/pd-cli/dist/services/service-host/handover-claims.d.ts.map +1 -0
  287. package/pd-cli/dist/services/service-host/handover-claims.js +50 -0
  288. package/pd-cli/dist/services/service-host/handover-claims.js.map +1 -0
  289. package/pd-cli/dist/services/service-host/index.d.ts +19 -3
  290. package/pd-cli/dist/services/service-host/index.d.ts.map +1 -1
  291. package/pd-cli/dist/services/service-host/index.js +21 -3
  292. package/pd-cli/dist/services/service-host/index.js.map +1 -1
  293. package/pd-cli/dist/services/service-host/install-identity.d.ts +23 -3
  294. package/pd-cli/dist/services/service-host/install-identity.d.ts.map +1 -1
  295. package/pd-cli/dist/services/service-host/install-identity.js +15 -5
  296. package/pd-cli/dist/services/service-host/install-identity.js.map +1 -1
  297. package/pd-cli/dist/services/service-host/locking/service-run-lock.d.ts +130 -9
  298. package/pd-cli/dist/services/service-host/locking/service-run-lock.d.ts.map +1 -1
  299. package/pd-cli/dist/services/service-host/locking/service-run-lock.js +99 -19
  300. package/pd-cli/dist/services/service-host/locking/service-run-lock.js.map +1 -1
  301. package/pd-cli/dist/services/service-host/managed-run.d.ts +75 -0
  302. package/pd-cli/dist/services/service-host/managed-run.d.ts.map +1 -0
  303. package/pd-cli/dist/services/service-host/managed-run.js +550 -0
  304. package/pd-cli/dist/services/service-host/managed-run.js.map +1 -0
  305. package/pd-cli/dist/services/service-host/progress-evidence.d.ts +38 -0
  306. package/pd-cli/dist/services/service-host/progress-evidence.d.ts.map +1 -0
  307. package/pd-cli/dist/services/service-host/progress-evidence.js +155 -0
  308. package/pd-cli/dist/services/service-host/progress-evidence.js.map +1 -0
  309. package/pd-cli/dist/services/service-host/run-once.d.ts.map +1 -1
  310. package/pd-cli/dist/services/service-host/run-once.js +4 -136
  311. package/pd-cli/dist/services/service-host/run-once.js.map +1 -1
  312. package/pd-cli/dist/services/service-host/scheduler/contract.d.ts +184 -0
  313. package/pd-cli/dist/services/service-host/scheduler/contract.d.ts.map +1 -0
  314. package/pd-cli/dist/services/service-host/scheduler/contract.js +86 -0
  315. package/pd-cli/dist/services/service-host/scheduler/contract.js.map +1 -0
  316. package/pd-cli/dist/services/service-host/scheduler/index.d.ts +76 -0
  317. package/pd-cli/dist/services/service-host/scheduler/index.d.ts.map +1 -0
  318. package/pd-cli/dist/services/service-host/scheduler/index.js +128 -0
  319. package/pd-cli/dist/services/service-host/scheduler/index.js.map +1 -0
  320. package/pd-cli/dist/services/service-host/scheduler/linux.d.ts +27 -0
  321. package/pd-cli/dist/services/service-host/scheduler/linux.d.ts.map +1 -0
  322. package/pd-cli/dist/services/service-host/scheduler/linux.js +1010 -0
  323. package/pd-cli/dist/services/service-host/scheduler/linux.js.map +1 -0
  324. package/pd-cli/dist/services/service-host/scheduler/macos.d.ts +13 -0
  325. package/pd-cli/dist/services/service-host/scheduler/macos.d.ts.map +1 -0
  326. package/pd-cli/dist/services/service-host/scheduler/macos.js +819 -0
  327. package/pd-cli/dist/services/service-host/scheduler/macos.js.map +1 -0
  328. package/pd-cli/dist/services/service-host/scheduler/runtime-io.d.ts +13 -0
  329. package/pd-cli/dist/services/service-host/scheduler/runtime-io.d.ts.map +1 -0
  330. package/pd-cli/dist/services/service-host/scheduler/runtime-io.js +141 -0
  331. package/pd-cli/dist/services/service-host/scheduler/runtime-io.js.map +1 -0
  332. package/pd-cli/dist/services/service-host/scheduler/service-status.d.ts +99 -0
  333. package/pd-cli/dist/services/service-host/scheduler/service-status.d.ts.map +1 -0
  334. package/pd-cli/dist/services/service-host/scheduler/service-status.js +202 -0
  335. package/pd-cli/dist/services/service-host/scheduler/service-status.js.map +1 -0
  336. package/pd-cli/dist/services/service-host/scheduler/windows.d.ts +40 -0
  337. package/pd-cli/dist/services/service-host/scheduler/windows.d.ts.map +1 -0
  338. package/pd-cli/dist/services/service-host/scheduler/windows.js +688 -0
  339. package/pd-cli/dist/services/service-host/scheduler/windows.js.map +1 -0
  340. package/pd-cli/dist/services/service-host/shadow-progress-store.d.ts +43 -0
  341. package/pd-cli/dist/services/service-host/shadow-progress-store.d.ts.map +1 -0
  342. package/pd-cli/dist/services/service-host/shadow-progress-store.js +156 -0
  343. package/pd-cli/dist/services/service-host/shadow-progress-store.js.map +1 -0
  344. package/pd-cli/dist/services/service-host/shadow-run.d.ts +87 -0
  345. package/pd-cli/dist/services/service-host/shadow-run.d.ts.map +1 -0
  346. package/pd-cli/dist/services/service-host/shadow-run.js +549 -0
  347. package/pd-cli/dist/services/service-host/shadow-run.js.map +1 -0
  348. package/pd-cli/dist/services/service-host/status/service-run-status.d.ts +114 -4
  349. package/pd-cli/dist/services/service-host/status/service-run-status.d.ts.map +1 -1
  350. package/pd-cli/dist/services/service-host/status/service-run-status.js +37 -0
  351. package/pd-cli/dist/services/service-host/status/service-run-status.js.map +1 -1
  352. package/pd-cli/dist/services/service-host/worker-adapter-codex.d.ts +2 -0
  353. package/pd-cli/dist/services/service-host/worker-adapter-codex.d.ts.map +1 -0
  354. package/pd-cli/dist/services/service-host/worker-adapter-codex.js +76 -0
  355. package/pd-cli/dist/services/service-host/worker-adapter-codex.js.map +1 -0
  356. package/pd-cli/dist/services/service-host/worker-adapter-openclaw.d.ts +2 -0
  357. package/pd-cli/dist/services/service-host/worker-adapter-openclaw.d.ts.map +1 -0
  358. package/pd-cli/dist/services/service-host/worker-adapter-openclaw.js +49 -0
  359. package/pd-cli/dist/services/service-host/worker-adapter-openclaw.js.map +1 -0
  360. package/pd-cli/dist/services/service-host/worker-adapter-workbuddy.d.ts +2 -0
  361. package/pd-cli/dist/services/service-host/worker-adapter-workbuddy.d.ts.map +1 -0
  362. package/pd-cli/dist/services/service-host/worker-adapter-workbuddy.js +36 -0
  363. package/pd-cli/dist/services/service-host/worker-adapter-workbuddy.js.map +1 -0
  364. package/pd-cli/dist/services/service-host/worker-adapter.d.ts +187 -0
  365. package/pd-cli/dist/services/service-host/worker-adapter.d.ts.map +1 -0
  366. package/pd-cli/dist/services/service-host/worker-adapter.js +609 -0
  367. package/pd-cli/dist/services/service-host/worker-adapter.js.map +1 -0
  368. package/pd-cli/dist/services/service-host/worker-env.d.ts +84 -0
  369. package/pd-cli/dist/services/service-host/worker-env.d.ts.map +1 -0
  370. package/pd-cli/dist/services/service-host/worker-env.js +195 -0
  371. package/pd-cli/dist/services/service-host/worker-env.js.map +1 -0
  372. package/pd-cli/dist/services/service-host/worker-process.d.ts +75 -0
  373. package/pd-cli/dist/services/service-host/worker-process.d.ts.map +1 -0
  374. package/pd-cli/dist/services/service-host/worker-process.js +225 -0
  375. package/pd-cli/dist/services/service-host/worker-process.js.map +1 -0
  376. package/pd-cli/dist/services/service-host/workspace-dispatch.d.ts +61 -0
  377. package/pd-cli/dist/services/service-host/workspace-dispatch.d.ts.map +1 -0
  378. package/pd-cli/dist/services/service-host/workspace-dispatch.js +105 -0
  379. package/pd-cli/dist/services/service-host/workspace-dispatch.js.map +1 -0
  380. package/pd-cli/dist/services/service-host/workspace-handover.d.ts +190 -0
  381. package/pd-cli/dist/services/service-host/workspace-handover.d.ts.map +1 -0
  382. package/pd-cli/dist/services/service-host/workspace-handover.js +1393 -0
  383. package/pd-cli/dist/services/service-host/workspace-handover.js.map +1 -0
  384. package/pd-cli/package.json +6 -5
  385. package/pd-mcp-server/dist/submit-assembly.js +159 -42
  386. package/pd-mcp-server/dist/version.d.ts +1 -1
  387. package/pd-mcp-server/dist/version.js +1 -1
  388. package/pd-mcp-server/package.json +1 -1
  389. package/plugin/dist/bundle.js +586 -568
  390. package/plugin/dist/openclaw-worker.d.ts +92 -0
  391. package/plugin/dist/openclaw-worker.js +2439 -0
  392. package/plugin/dist/openclaw.plugin.json +1 -1
  393. package/plugin/dist/service/gateway-consumer-lease.d.ts +142 -0
  394. package/plugin/dist/service/gateway-quiesce-ack.d.ts +40 -0
  395. package/plugin/dist/service/internalization-auto-consumer-service.d.ts +68 -1
  396. package/plugin/openclaw.plugin.json +1 -1
  397. package/plugin/package.json +5 -1
  398. package/release-manager/dist/installer.js +77 -30
  399. package/release-manager/dist/installers/mcp-registration-conflict.js +34 -1
  400. package/release-manager/dist/installers/workbuddy-host-installer.js +284 -21
  401. package/release-manager/dist/service-host-bridge.js +292 -0
  402. package/release-manager/dist/update/install-layout.js +42 -15
  403. package/release-manager/package.json +2 -2
  404. package/workbuddy-adapter/dist/index.d.ts +1 -1
  405. package/workbuddy-adapter/dist/index.js +1 -1
  406. package/workbuddy-adapter/dist/worker/workspace-worker.d.ts +7 -0
  407. package/workbuddy-adapter/dist/worker/workspace-worker.js +179 -10
  408. package/workbuddy-adapter/package.json +1 -1
  409. package/workbuddy-adapter/plugin/.codebuddy-plugin/plugin.json +2 -2
@@ -0,0 +1,1010 @@
1
+ /**
2
+ * Linux scheduler adapter — systemd --user service + timer (SPEC §10.2,
3
+ * task §3.4).
4
+ *
5
+ * Registration: `<user-unit-dir>/pd-service-host-<key>.service` + `.timer`
6
+ * (current user units only — never a root/system unit). Unit files are
7
+ * written atomically; every `systemctl --user` failure (including
8
+ * daemon-reload and bus-unavailable states) is reported honestly — an
9
+ * unreadable enabled/active state is NEVER folded into "not installed" /
10
+ * "disabled" / "inactive" (task §13 review).
11
+ *
12
+ * Dual-unit contract (task §4 review): the registration is the PAIR —
13
+ * install, status, enable, disable and uninstall check BOTH unit files
14
+ * independently; each must parse as this install's own unit (the service's
15
+ * ExecStart/WorkingDirectory, the timer's Unit= pointer) or PD refuses to
16
+ * touch it. The uninstall sequence verifies ownership first, stops and
17
+ * disables the timer CHECKING each command's result, CONFIRMS inactive and
18
+ * disabled via independent queries, only then removes the files, reloads
19
+ * the manager and re-verifies the registration is gone.
20
+ *
21
+ * Unit-search-path semantics (task §12 review): PD writes under
22
+ * `<home>/.config/systemd/user` — the manager's default search path. A
23
+ * mismatched HOME / XDG_CONFIG_HOME makes the manager unable to see the
24
+ * written units; install therefore ends by asking the manager
25
+ * (`is-enabled` / `cat`) whether it can see the unit, and refuses to
26
+ * report "registered" when it cannot.
27
+ *
28
+ * Honest platform semantics (SPEC §10.2 audit): the user manager runs while
29
+ * the user has a login session. `loginctl enable-linger` is NOT enabled by
30
+ * PD (task §3.4) — running after logout is explicitly NOT a V1 default.
31
+ *
32
+ * IMPORTANT (task §9.F): unit-tested against a faked command boundary; real
33
+ * Linux acceptance is recorded as NOT_VERIFIED until it runs on a real host.
34
+ */
35
+ import * as path from 'node:path';
36
+ import { schedulerInvocationArgs } from './contract.js';
37
+ /**
38
+ * Parse the complete, deliberately small unit-file grammar emitted by PD.
39
+ * Unknown syntax, continuation lines, extra sections and extra directives
40
+ * are rejected rather than silently ignored by an ownership check.
41
+ * Comments and blank lines are semantically inert.
42
+ */
43
+ function parseUnitDocument(content) {
44
+ const entries = [];
45
+ let section = null;
46
+ for (const raw of content.split(/\r?\n/)) {
47
+ const line = raw.trim();
48
+ if (line === '' || line.startsWith('#') || line.startsWith(';'))
49
+ continue;
50
+ const header = /^\[([A-Za-z][A-Za-z0-9]*)\]$/.exec(line);
51
+ if (header !== null) {
52
+ section = header[1] ?? null;
53
+ if (section === null)
54
+ return null;
55
+ entries.push({ kind: 'section', section });
56
+ continue;
57
+ }
58
+ if (section === null)
59
+ return null;
60
+ const setting = /^([A-Za-z][A-Za-z0-9]*)\s*=(.*)$/.exec(line);
61
+ if (setting === null)
62
+ return null;
63
+ entries.push({
64
+ kind: 'setting',
65
+ section,
66
+ key: setting[1] ?? '',
67
+ value: (setting[2] ?? '').trim(),
68
+ });
69
+ }
70
+ return entries;
71
+ }
72
+ /**
73
+ * Compare every parsed section and directive against the canonical PD unit.
74
+ * The timer's OnUnitActiveSec value is the sole variable. Its syntax is
75
+ * validated separately by the install path; ownership still requires the
76
+ * exact directive shape so a malformed PD unit can be repaired or removed.
77
+ */
78
+ function matchesCanonicalUnit(content, canonicalContent, allowVariableTimerInterval = false) {
79
+ const actual = parseUnitDocument(content);
80
+ const expected = parseUnitDocument(canonicalContent);
81
+ if (actual === null || expected === null || actual.length !== expected.length)
82
+ return false;
83
+ return actual.every((entry, index) => {
84
+ const canonical = expected[index];
85
+ if (canonical === undefined || entry.kind !== canonical.kind || entry.section !== canonical.section)
86
+ return false;
87
+ if (entry.kind === 'section' || canonical.kind === 'section')
88
+ return entry.kind === 'section' && canonical.kind === 'section';
89
+ if (entry.key !== canonical.key)
90
+ return false;
91
+ if (allowVariableTimerInterval && entry.section === 'Timer' && entry.key === 'OnUnitActiveSec')
92
+ return true;
93
+ return entry.value === canonical.value;
94
+ });
95
+ }
96
+ /** All `Key=` values inside `[Section]` (comments, blank lines and other
97
+ * sections are ignored — systemd semantics). Empty `Key=` lines are kept:
98
+ * in systemd they RESET a list setting, so ownership must see them. */
99
+ function sectionSettings(content, section, key) {
100
+ const values = [];
101
+ let inSection = false;
102
+ for (const raw of content.split('\n')) {
103
+ const line = raw.trim();
104
+ const header = /^\[([^\]]+)\]$/.exec(line);
105
+ if (header !== null) {
106
+ inSection = header[1] === section;
107
+ continue;
108
+ }
109
+ if (!inSection || line === '' || line.startsWith('#') || line.startsWith(';'))
110
+ continue;
111
+ const kv = /^([A-Za-z][A-Za-z0-9]*)\s*=\s*(.*)$/.exec(line);
112
+ if (kv !== null && kv[1] === key)
113
+ values.push((kv[2] ?? '').trim());
114
+ }
115
+ return values;
116
+ }
117
+ /**
118
+ * systemd time-span → ms: `900s`, `15min`, `2h`, `1d`, `1w`, `1h30min`,
119
+ * `1h 30min`, or a bare number (seconds). Composite expressions are summed
120
+ * like systemd does; unknown units/leftover text yield null.
121
+ */
122
+ export function parseSystemdDurationMs(value) {
123
+ const compact = value.trim().replace(/\s+/g, '');
124
+ if (compact === '')
125
+ return null;
126
+ if (/^\d+(?:\.\d+)?$/.test(compact))
127
+ return Math.round(Number(compact) * 1000);
128
+ const UNIT_MS = {
129
+ us: 0.001,
130
+ usec: 0.001,
131
+ 'µs': 0.001,
132
+ ms: 1,
133
+ msec: 1,
134
+ s: 1000,
135
+ sec: 1000,
136
+ second: 1000,
137
+ seconds: 1000,
138
+ m: 60_000,
139
+ min: 60_000,
140
+ minute: 60_000,
141
+ minutes: 60_000,
142
+ h: 3_600_000,
143
+ hr: 3_600_000,
144
+ hour: 3_600_000,
145
+ hours: 3_600_000,
146
+ d: 86_400_000,
147
+ day: 86_400_000,
148
+ days: 86_400_000,
149
+ w: 604_800_000,
150
+ week: 604_800_000,
151
+ weeks: 604_800_000,
152
+ };
153
+ let rest = compact;
154
+ let total = 0;
155
+ while (rest.length > 0) {
156
+ const match = /^(\d+(?:\.\d+)?)(usec|us|µs|msec|ms|seconds?|sec|s|minutes?|min|m|hours?|hr|h|days?|d|weeks?|w)/i.exec(rest);
157
+ if (match === null)
158
+ return null;
159
+ const unit = UNIT_MS[(match[2] ?? '').toLowerCase()];
160
+ if (unit === undefined)
161
+ return null;
162
+ total += Number(match[1]) * unit;
163
+ rest = rest.slice(match[0].length);
164
+ }
165
+ return total > 0 ? Math.round(total) : null;
166
+ }
167
+ /** Parse `OnUnitActiveSec=` from the timer unit's [Timer] section. */
168
+ export function parseLinuxTimerIntervalMs(timerUnit) {
169
+ const values = sectionSettings(timerUnit, 'Timer', 'OnUnitActiveSec');
170
+ const [value] = values;
171
+ if (value === undefined)
172
+ return null;
173
+ return parseSystemdDurationMs(value);
174
+ }
175
+ /**
176
+ * Escape a value for a non-command unit SETTING line (WorkingDirectory=,
177
+ * Description=): systemd expands `%` specifiers there, but does NOT apply
178
+ * `$`/`${}` environment substitution (that substitution only applies to
179
+ * Exec* command lines and a few documented settings) — doubling `$` here
180
+ * would leave a literal `$$` in the unit.
181
+ */
182
+ function systemdSettingEscape(value) {
183
+ return value.replace(/%/g, '%%');
184
+ }
185
+ /**
186
+ * Quote one ExecStart argv token (task §7 review): double-quote the token
187
+ * and escape, in order, `%` → `%%` (specifier), `$` → `$$` (env
188
+ * expansion), `\` → `\\` and `"` → `\"` (quote syntax). The previous
189
+ * serializer escaped only `\` and `"`, silently corrupting paths like
190
+ * `/home/$USER dir` or `C:\proj%` on real hosts.
191
+ */
192
+ export function systemdQuote(value) {
193
+ const escaped = value
194
+ .replace(/%/g, '%%')
195
+ .replace(/\$/g, '$$$$')
196
+ .replace(/\\/g, '\\\\')
197
+ .replace(/"/g, '\\"');
198
+ return `"${escaped}"`;
199
+ }
200
+ function secondsDuration(intervalMs) {
201
+ if (intervalMs % 1000 === 0)
202
+ return `${Math.round(intervalMs / 1000)}s`;
203
+ return `${(intervalMs / 1000).toFixed(3)}s`;
204
+ }
205
+ /** The oneshot service unit. Exported for unit tests. */
206
+ export function buildLinuxServiceUnit(registration) {
207
+ const execStart = [registration.nodePath, ...schedulerInvocationArgs(registration)]
208
+ .map(systemdQuote)
209
+ .join(' ');
210
+ return [
211
+ '[Unit]',
212
+ `Description=PD Service Host managed run-once (pdHome=${systemdSettingEscape(registration.pdHome)})`,
213
+ 'Documentation=https://github.com/csuzngjh/principles',
214
+ '',
215
+ '[Service]',
216
+ 'Type=oneshot',
217
+ `ExecStart=${execStart}`,
218
+ `WorkingDirectory=${systemdSettingEscape(registration.pdHome)}`,
219
+ '',
220
+ ].join('\n');
221
+ }
222
+ /** The repeating timer unit. Exported for unit tests. */
223
+ export function buildLinuxTimerUnit(registration) {
224
+ return [
225
+ '[Unit]',
226
+ 'Description=PD Service Host periodic trigger',
227
+ '',
228
+ '[Timer]',
229
+ `Unit=${registration.identity.linuxUnitBase}.service`,
230
+ 'OnBootSec=2min',
231
+ `OnUnitActiveSec=${secondsDuration(registration.intervalMs)}`,
232
+ 'AccuracySec=30s',
233
+ '',
234
+ '[Install]',
235
+ 'WantedBy=timers.target',
236
+ '',
237
+ ].join('\n');
238
+ }
239
+ export function createLinuxSchedulerAdapter(deps) {
240
+ const { runner, fileIo } = deps;
241
+ /** homeDir derived from the trusted pdHome (…/<home>/.pd → <home>). */
242
+ function homeDirFor(registration) {
243
+ return path.dirname(registration.pdHome);
244
+ }
245
+ function unitDir(registration) {
246
+ return path.join(homeDirFor(registration), '.config', 'systemd', 'user');
247
+ }
248
+ function serviceUnitPath(registration) {
249
+ return path.join(unitDir(registration), `${registration.identity.linuxUnitBase}.service`);
250
+ }
251
+ function timerUnitPath(registration) {
252
+ return path.join(unitDir(registration), `${registration.identity.linuxUnitBase}.timer`);
253
+ }
254
+ function timerUnitName(registration) {
255
+ return `${registration.identity.linuxUnitBase}.timer`;
256
+ }
257
+ function serviceUnitName(registration) {
258
+ return `${registration.identity.linuxUnitBase}.service`;
259
+ }
260
+ /**
261
+ * Ownership verdict from the PARSED service unit (task §5 review):
262
+ * ExecStart must decode to exactly [nodePath, ...schedulerInvocationArgs]
263
+ * and WorkingDirectory to exactly this pdHome. A unit merely CONTAINING
264
+ * our path strings inside another job definition is foreign.
265
+ */
266
+ function serviceOwnership(content, registration) {
267
+ // Prove the complete Service unit, not just matching path substrings.
268
+ // Extra ExecStartPre/ExecStartPost/ExecStop/User/Environment directives,
269
+ // duplicate sections, or any unknown setting make it foreign.
270
+ return matchesCanonicalUnit(content, buildLinuxServiceUnit(registration));
271
+ }
272
+ /**
273
+ * Ownership verdict from the PARSED timer unit (task §4 review): the
274
+ * timer's `Unit=` must point at THIS install's service unit — a foreign
275
+ * timer driving a foreign service is never ours.
276
+ */
277
+ function timerOwnership(content, registration) {
278
+ // Unit= alone is not ownership proof. Require the complete canonical
279
+ // Timer + Install structure, with only OnUnitActiveSec allowed to vary.
280
+ return matchesCanonicalUnit(content, buildLinuxTimerUnit(registration), true);
281
+ }
282
+ /** 'ok' | 'missing' | 'unreadable' — narrowing helper for the union result. */
283
+ function unitState(read) {
284
+ if (read.ok)
285
+ return 'ok';
286
+ return read.reason;
287
+ }
288
+ function unitDetail(read) {
289
+ if (read.ok || read.detail === undefined)
290
+ return 'unreadable';
291
+ return read.detail;
292
+ }
293
+ async function systemctl(args) {
294
+ return runner.run('systemctl', ['--user', ...args]);
295
+ }
296
+ /**
297
+ * `is-enabled` verdict (task §13 review): distinguishes
298
+ * enabled / disabled / masked / not-found / command-failure.
299
+ * A not-found or manager-unavailable answer is NEVER folded into
300
+ * "disabled" — it is its own evidence class.
301
+ */
302
+ /** stderr phrases that are systemd's definitive "manager has no such
303
+ * unit" answer (search-path miss, never loaded, or systemd 254+ exit 4). */
304
+ const UNIT_NOT_FOUND = /not[- ]found|no such unit|could not be found|no such file or directory|no files found/i;
305
+ /**
306
+ * `is-enabled` verdict — evidence classes only, never stderr inference
307
+ * (task review §3.1): only an explicit stdout verdict decides
308
+ * enabled/disabled; a not-found phrase decides not_found; EVERY other
309
+ * outcome — permission denied, empty output, spawn failure, timeout, a
310
+ * dead user bus, an unrecognized exit code/text — is `unreadable`
311
+ * (UNKNOWN), never folded into "disabled".
312
+ */
313
+ async function enabledVerdict(registration) {
314
+ const result = await systemctl(['is-enabled', timerUnitName(registration)]);
315
+ const stdout = result.stdout.trim();
316
+ const stderr = result.stderr.trim();
317
+ if (result.spawnError !== undefined) {
318
+ return { enabled: null, state: 'unreadable', unreadableReason: `systemctl_is_enabled_failed:spawn:${result.spawnError.slice(0, 120)}` };
319
+ }
320
+ if (result.code === 0) {
321
+ if (stdout === 'enabled' || stdout === 'enabled-runtime' || stdout === 'alias') {
322
+ return { enabled: true, state: 'enabled' };
323
+ }
324
+ // static/indirect/generated/masked-runtime etc. are enablement states
325
+ // the contract cannot classify — they stay UNKNOWN, never disabled.
326
+ return { enabled: null, state: 'unreadable', unreadableReason: `systemd_unit_unexpected_state:${stdout.slice(0, 60)}` };
327
+ }
328
+ // Non-zero exit: only an explicit verdict line counts as evidence.
329
+ if (stdout === 'disabled') {
330
+ return { enabled: false, state: 'disabled' };
331
+ }
332
+ // 'masked' cannot fire and cannot be enabled — a stronger form of
333
+ // disabled that satisfies "not enabled" but is still explicit stdout.
334
+ if (stdout === 'masked' || stdout === 'masked-runtime') {
335
+ return { enabled: false, state: 'disabled' };
336
+ }
337
+ if (stdout === 'not-found' || UNIT_NOT_FOUND.test(stderr)) {
338
+ // Exit 4 + "not-found" (systemd 254+), exit 1 + "Failed to get unit
339
+ // file state ... No such file", etc. — positive not-registered.
340
+ return { enabled: null, state: 'not_found' };
341
+ }
342
+ return {
343
+ enabled: null,
344
+ state: 'unreadable',
345
+ unreadableReason: `systemctl_is_enabled_failed:${result.code ?? 'spawn'}:${(stderr || stdout || 'no output').slice(0, 120)}`,
346
+ };
347
+ }
348
+ /**
349
+ * `is-active` verdict (task §14 review): independently queries whether the
350
+ * timer is ACTIVE. An unreadable active-state stays null — never folded
351
+ * into enabled/disabled.
352
+ */
353
+ async function activeVerdict(registration) {
354
+ const result = await systemctl(['is-active', timerUnitName(registration)]);
355
+ const stdout = result.stdout.trim();
356
+ if (result.code === 0 && stdout === 'active')
357
+ return { active: true };
358
+ if (stdout === 'inactive' || stdout === 'failed' || stdout === 'deactivating')
359
+ return { active: false };
360
+ if (result.code === 3 || result.code === 4)
361
+ return { active: false };
362
+ return {
363
+ active: null,
364
+ unreadableReason: `systemctl_is_active_failed:${result.code ?? 'spawn'}:${(result.spawnError ?? (result.stderr.trim() || stdout)).slice(0, 120)}`,
365
+ };
366
+ }
367
+ /**
368
+ * Whether the manager can SEE the written unit (task §12 review): after
369
+ * writing the units PD asks the manager for them — a not-found answer
370
+ * means the unit dir is outside the manager's search path (HOME/XDG
371
+ * mismatch) and "registered" must not be reported.
372
+ */
373
+ /**
374
+ * Manager view of BOTH units via `systemctl cat` (review §3.5):
375
+ * `cat` prints `# /resolved/path` headers — the primary file for each
376
+ * unit must be OUR file (a same-name unit elsewhere in the search path
377
+ * shadows ours → ambiguous), and any `*.d/*.conf` drop-in makes the
378
+ * effective unit different from the file we verified → ambiguous.
379
+ */
380
+ async function managerUnitView(registration) {
381
+ const units = [
382
+ [serviceUnitName(registration), serviceUnitPath(registration)],
383
+ [timerUnitName(registration), timerUnitPath(registration)],
384
+ ];
385
+ for (const [name, file] of units) {
386
+ const result = await systemctl(['cat', name]);
387
+ if (result.code !== 0) {
388
+ if (result.spawnError === undefined && (UNIT_NOT_FOUND.test(result.stderr) || (result.code === 1 && result.stderr.trim() === ''))) {
389
+ return { seen: false };
390
+ }
391
+ return {
392
+ seen: false,
393
+ unreadableReason: `systemctl_cat_failed:${result.code ?? 'spawn'}:${(result.spawnError ?? result.stderr.trim()).slice(0, 120)}`,
394
+ };
395
+ }
396
+ const headers = [...result.stdout.matchAll(/^#\s*(\S+)\s*$/gm)].map((m) => m[1] ?? '');
397
+ const primary = headers.find((h) => h.endsWith('.service') || h.endsWith('.timer'));
398
+ if (primary !== undefined && primary !== file) {
399
+ return { seen: true, shadowed: `resolved_path:${primary}` };
400
+ }
401
+ const dropIn = headers.find((h) => /\.d\/[^/]+\.conf$/.test(h));
402
+ if (dropIn !== undefined) {
403
+ return { seen: true, shadowed: `drop_in:${dropIn}` };
404
+ }
405
+ }
406
+ return { seen: true };
407
+ }
408
+ /**
409
+ * Verify that the manager's effective unit presence matches the pre-write
410
+ * disk snapshot after a rollback reload. This handles full and partial
411
+ * prior registrations without claiming that a missing unit is present.
412
+ */
413
+ async function managerUnitsMatchPresence(registration, expected) {
414
+ const units = [
415
+ [serviceUnitName(registration), serviceUnitPath(registration), expected.service],
416
+ [timerUnitName(registration), timerUnitPath(registration), expected.timer],
417
+ ];
418
+ for (const [name, file, shouldExist] of units) {
419
+ const result = await systemctl(['cat', name]);
420
+ const notFound = result.spawnError === undefined
421
+ && (UNIT_NOT_FOUND.test(result.stderr) || (result.code === 1 && result.stderr.trim() === ''));
422
+ if (!shouldExist) {
423
+ if (notFound)
424
+ continue;
425
+ if (result.code === 0)
426
+ return { ok: false, reason: 'manager_unexpected_unit_present:' + name };
427
+ return {
428
+ ok: false,
429
+ reason: 'manager_presence_query_failed:' + name + ':' + (result.code ?? 'spawn') + ':' + (result.spawnError ?? result.stderr.trim()).slice(0, 100),
430
+ };
431
+ }
432
+ if (result.code !== 0) {
433
+ return {
434
+ ok: false,
435
+ reason: notFound
436
+ ? 'manager_expected_unit_missing:' + name
437
+ : 'manager_presence_query_failed:' + name + ':' + (result.code ?? 'spawn') + ':' + (result.spawnError ?? result.stderr.trim()).slice(0, 100),
438
+ };
439
+ }
440
+ const headers = [...result.stdout.matchAll(/^#\s*(\S+)\s*$/gm)].map((match) => match[1] ?? '');
441
+ const primary = headers.find((header) => header.endsWith('.service') || header.endsWith('.timer'));
442
+ if (primary !== undefined && primary !== file) {
443
+ return { ok: false, reason: 'manager_unit_shadowed:' + name + ':' + primary };
444
+ }
445
+ const dropIn = headers.find((header) => /\.d\/[^/]+\.conf$/.test(header));
446
+ if (dropIn !== undefined)
447
+ return { ok: false, reason: 'manager_unit_drop_in:' + name + ':' + dropIn };
448
+ }
449
+ return { ok: true };
450
+ }
451
+ /** Both units must be definitively gone from the manager's view. */
452
+ async function managerUnitsGone(registration) {
453
+ for (const name of [serviceUnitName(registration), timerUnitName(registration)]) {
454
+ const result = await systemctl(['cat', name]);
455
+ if (result.code === 0)
456
+ return { gone: false, still: name };
457
+ if (result.spawnError === undefined && (UNIT_NOT_FOUND.test(result.stderr) || (result.code === 1 && result.stderr.trim() === ''))) {
458
+ continue;
459
+ }
460
+ return {
461
+ gone: null,
462
+ unreadableReason: `systemctl_cat_failed:${result.code ?? 'spawn'}:${(result.spawnError ?? result.stderr.trim()).slice(0, 120)}`,
463
+ };
464
+ }
465
+ return { gone: true };
466
+ }
467
+ /** Last execution status/timestamp from `systemctl show` (absent = null). */
468
+ async function serviceFacts(registration) {
469
+ const show = await systemctl([
470
+ 'show', serviceUnitName(registration),
471
+ '--property=ExecMainStatus', '--property=ExecMainExitTimestamp', '--value',
472
+ ]);
473
+ if (show.code !== 0) {
474
+ return {
475
+ lastResult: null,
476
+ lastRunAt: null,
477
+ unreadableReason: `systemctl_show_failed:${show.code ?? 'spawn'}:${(show.spawnError ?? show.stderr.trim()).slice(0, 120)}`,
478
+ };
479
+ }
480
+ const lines = show.stdout.trim().split('\n');
481
+ const lastResult = lines[0] !== undefined && lines[0].trim() !== '' ? lines[0].trim() : null;
482
+ const lastRunAt = lines[1] !== undefined && lines[1].trim() !== '' ? lines[1].trim() : null;
483
+ return { lastResult, lastRunAt };
484
+ }
485
+ function unreadableRegistration(registration, detail) {
486
+ return {
487
+ ok: false,
488
+ kind: 'command_failed',
489
+ reason: `systemd_unit_unreadable:${detail.slice(0, 120)}`,
490
+ nextAction: `The unit files under ${unitDir(registration)} exist but cannot be read. PD does not treat an unreadable registration as "not installed" — fix permissions and re-run pd service status.`,
491
+ };
492
+ }
493
+ function baseFacts(registration, fields) {
494
+ return {
495
+ platform: 'linux',
496
+ taskName: timerUnitName(registration),
497
+ registered: null,
498
+ enabled: null,
499
+ active: null,
500
+ lastRunAt: null,
501
+ lastResult: null,
502
+ ...fields,
503
+ };
504
+ }
505
+ /** Facts gathered after a mutation — each witness read independently. */
506
+ async function gatherFacts(registration) {
507
+ const enabled = await enabledVerdict(registration);
508
+ const active = await activeVerdict(registration);
509
+ const facts = await serviceFacts(registration);
510
+ const degraded = [];
511
+ if (enabled.unreadableReason !== undefined)
512
+ degraded.push(enabled.unreadableReason);
513
+ if (active.unreadableReason !== undefined)
514
+ degraded.push(active.unreadableReason);
515
+ if (facts.unreadableReason !== undefined)
516
+ degraded.push(facts.unreadableReason);
517
+ return baseFacts(registration, {
518
+ registered: true,
519
+ enabled: enabled.enabled,
520
+ active: active.active,
521
+ lastRunAt: facts.lastRunAt,
522
+ lastResult: facts.lastResult,
523
+ ...(degraded.length > 0 ? { degradedReasons: degraded } : {}),
524
+ });
525
+ }
526
+ async function status(registration) {
527
+ const serviceFile = serviceUnitPath(registration);
528
+ const timerFile = timerUnitPath(registration);
529
+ const service = fileIo.readIfExists(serviceFile);
530
+ const timer = fileIo.readIfExists(timerFile);
531
+ if (service.ok && timer.ok) {
532
+ if (!serviceOwnership(service.content, registration)) {
533
+ return {
534
+ ok: false,
535
+ kind: 'external_conflict',
536
+ reason: 'systemd_unit_conflict_foreign_unit',
537
+ nextAction: `${serviceFile} exists but its ExecStart/WorkingDirectory do not match this PD install (${registration.pdHome}); PD refuses to touch foreign units. Inspect it manually.`,
538
+ };
539
+ }
540
+ if (!timerOwnership(timer.content, registration)) {
541
+ return {
542
+ ok: false,
543
+ kind: 'external_conflict',
544
+ reason: 'systemd_timer_conflict_foreign_unit',
545
+ nextAction: `${timerFile} exists but its Unit= does not point at this PD install's service; PD refuses to touch foreign units. Inspect it manually.`,
546
+ };
547
+ }
548
+ const facts = await gatherFacts(registration);
549
+ return {
550
+ ok: true,
551
+ changed: false,
552
+ facts: { ...facts, triggerIntervalMs: parseLinuxTimerIntervalMs(timer.content) },
553
+ };
554
+ }
555
+ if (unitState(service) === 'missing' && unitState(timer) === 'missing') {
556
+ return {
557
+ ok: true,
558
+ changed: false,
559
+ facts: baseFacts(registration, { registered: false, enabled: false, active: false }),
560
+ };
561
+ }
562
+ if (unitState(service) === 'unreadable' || unitState(timer) === 'unreadable') {
563
+ return unreadableRegistration(registration, unitDetail(service) + '/' + unitDetail(timer));
564
+ }
565
+ // Partial registration (one of the two units) — unsafe, refuse to guess.
566
+ return {
567
+ ok: false,
568
+ kind: 'unsafe_state',
569
+ reason: 'systemd_units_partial_registration',
570
+ nextAction: `Only one of ${serviceFile} / ${timerFile} exists. A partial registration is not a usable scheduler state — inspect both files, remove leftovers manually if they are yours, then re-run pd service install.`,
571
+ };
572
+ }
573
+ return {
574
+ platform: 'linux',
575
+ async install(registration) {
576
+ const serviceFile = serviceUnitPath(registration);
577
+ const timerFile = timerUnitPath(registration);
578
+ const existingService = fileIo.readIfExists(serviceFile);
579
+ const existingTimer = fileIo.readIfExists(timerFile);
580
+ if (unitState(existingService) !== 'missing' || unitState(existingTimer) !== 'missing') {
581
+ if (unitState(existingService) === 'unreadable' || unitState(existingTimer) === 'unreadable') {
582
+ return unreadableRegistration(registration, unitDetail(existingService) + '/' + unitDetail(existingTimer));
583
+ }
584
+ if (!existingService.ok || !existingTimer.ok) {
585
+ // A partial registration completes only when the present file is
586
+ // provably OURS — a foreign leftover is still a refusal.
587
+ if (existingService.ok && !serviceOwnership(existingService.content, registration)) {
588
+ return {
589
+ ok: false,
590
+ kind: 'external_conflict',
591
+ reason: 'systemd_unit_conflict_foreign_unit',
592
+ nextAction: `${serviceFile} exists but its ExecStart/WorkingDirectory do not match this PD install; PD never overwrites foreign systemd units. Inspect it manually.`,
593
+ };
594
+ }
595
+ if (existingTimer.ok && !timerOwnership(existingTimer.content, registration)) {
596
+ return {
597
+ ok: false,
598
+ kind: 'external_conflict',
599
+ reason: 'systemd_timer_conflict_foreign_unit',
600
+ nextAction: `${timerFile} exists but its Unit= does not point at this PD install's service; PD never overwrites foreign systemd units. Inspect it manually.`,
601
+ };
602
+ }
603
+ // own partial leftover from a failed first install → the writes
604
+ // below complete the pair (first-install rollback normally
605
+ // removes leftovers; this path is the safe resume).
606
+ }
607
+ else {
608
+ // Each unit is verified independently (task §4): a foreign service
609
+ // AND a foreign timer are two separate refusal paths.
610
+ if (!serviceOwnership(existingService.content, registration)) {
611
+ return {
612
+ ok: false,
613
+ kind: 'external_conflict',
614
+ reason: 'systemd_unit_conflict_foreign_unit',
615
+ nextAction: `${serviceFile} already exists but its ExecStart/WorkingDirectory do not match this PD install; PD never overwrites foreign systemd units.`,
616
+ };
617
+ }
618
+ if (!timerOwnership(existingTimer.content, registration)) {
619
+ return {
620
+ ok: false,
621
+ kind: 'external_conflict',
622
+ reason: 'systemd_timer_conflict_foreign_unit',
623
+ nextAction: `${timerFile} already exists but its Unit= does not point at this PD install's service; PD never overwrites foreign systemd units.`,
624
+ };
625
+ }
626
+ // Idempotent: our own units — rewrite with the current definition
627
+ // (refresh) and reload; the enabled state is systemd enablement
628
+ // state, PRESERVED by not touching enable/disable here.
629
+ }
630
+ }
631
+ // Refresh semantics (task §15): an existing OWN registration keeps
632
+ // its interval — only the node/CLI entry and args move forward —
633
+ // UNLESS the caller explicitly passed a new --interval-ms. An
634
+ // UNPARSEABLE existing interval must refuse BEFORE writing: silently
635
+ // falling back to the default would clobber an unknown schedule.
636
+ const preservedInterval = existingTimer.ok && registration.intervalExplicit !== true
637
+ ? parseLinuxTimerIntervalMs(existingTimer.content)
638
+ : null;
639
+ if (existingTimer.ok && registration.intervalExplicit !== true && preservedInterval === null) {
640
+ return {
641
+ ok: false,
642
+ kind: 'unsafe_state',
643
+ reason: 'systemd_timer_interval_unparseable',
644
+ nextAction: `The existing timer's OnUnitActiveSec in ${timerFile} could not be parsed — PD refuses to overwrite an unknown interval with a default. Fix the value manually or pass --interval-ms explicitly, then retry.`,
645
+ };
646
+ }
647
+ const effective = preservedInterval !== null
648
+ ? { ...registration, intervalMs: preservedInterval }
649
+ : registration;
650
+ const dir = unitDir(registration);
651
+ const mkdir = fileIo.mkdirs(dir);
652
+ if (!mkdir.ok) {
653
+ return { ok: false, kind: 'command_failed', reason: `systemd_unit_dir_unwritable:${mkdir.reason.slice(0, 80)}`, nextAction: `Could not create ${dir}; check permissions and retry pd service install.` };
654
+ }
655
+ // Refresh failure must restore the ORIGINAL files — a half-rewritten
656
+ // pair is never left behind (review §5). A first install has no
657
+ // original: its rollback removes the file this call created.
658
+ const priorService = existingService.ok ? existingService.content : null;
659
+ const priorTimer = existingTimer.ok ? existingTimer.content : null;
660
+ const rollbackUnit = (file, prior) => {
661
+ if (prior === null) {
662
+ const removed = fileIo.remove(file);
663
+ return removed.ok ? { ok: true } : { ok: false, detail: 'remove_failed:' + file + ':' + removed.reason.slice(0, 60) };
664
+ }
665
+ const restored = fileIo.writeAtomic(file, prior);
666
+ return restored.ok ? { ok: true } : { ok: false, detail: 'restore_failed:' + file + ':' + restored.reason.slice(0, 60) };
667
+ };
668
+ const writtenService = fileIo.writeAtomic(serviceFile, buildLinuxServiceUnit(effective));
669
+ if (!writtenService.ok) {
670
+ return { ok: false, kind: 'command_failed', reason: `systemd_service_write_failed:${writtenService.reason.slice(0, 80)}`, nextAction: `Could not write ${serviceFile}; retry pd service install after fixing the filesystem issue.` };
671
+ }
672
+ const writtenTimer = fileIo.writeAtomic(timerFile, buildLinuxTimerUnit(effective));
673
+ if (!writtenTimer.ok) {
674
+ const serviceRestore = rollbackUnit(serviceFile, priorService);
675
+ const rollbackDetail = serviceRestore.ok ? '' : '+rollback_' + (serviceRestore.detail ?? 'failed');
676
+ return {
677
+ ok: false,
678
+ kind: 'command_failed',
679
+ reason: 'systemd_timer_write_failed:' + writtenTimer.reason.slice(0, 80) + rollbackDetail,
680
+ nextAction: 'Could not write ' + timerFile + '; the service unit was rolled back to its previous content (or removed for a first install). Re-run pd service install.',
681
+ };
682
+ }
683
+ const rollbackBoth = async (reason) => {
684
+ const timerRestore = rollbackUnit(timerFile, priorTimer);
685
+ const serviceRestore = rollbackUnit(serviceFile, priorService);
686
+ const diskFailures = [timerRestore, serviceRestore]
687
+ .filter((restore) => !restore.ok)
688
+ .map((restore) => restore.detail ?? 'unknown_disk_restore_failure');
689
+ // The first reload may already have changed systemd's in-memory view.
690
+ // Reload the restored snapshot and verify the previous unit presence.
691
+ const rollbackReload = await systemctl(['daemon-reload']);
692
+ if (rollbackReload.code !== 0) {
693
+ const detail = 'systemd_refresh_rollback_manager_reload_failed:' + (rollbackReload.code ?? 'spawn') + ':' + (rollbackReload.spawnError ?? rollbackReload.stderr).trim().slice(0, 100);
694
+ return detail + ':' + reason + (diskFailures.length > 0 ? '+' + diskFailures.join('+') : '');
695
+ }
696
+ const managerRestore = await managerUnitsMatchPresence(registration, {
697
+ service: priorService !== null,
698
+ timer: priorTimer !== null,
699
+ });
700
+ if (!managerRestore.ok) {
701
+ const detail = 'systemd_refresh_rollback_manager_view_unverified:' + managerRestore.reason;
702
+ return detail + ':' + reason + (diskFailures.length > 0 ? '+' + diskFailures.join('+') : '');
703
+ }
704
+ if (diskFailures.length > 0) {
705
+ return 'systemd_refresh_rollback_disk_restore_failed:' + diskFailures.join('+') + ':' + reason;
706
+ }
707
+ return reason;
708
+ };
709
+ const reload = await systemctl(['daemon-reload']);
710
+ if (reload.code !== 0) {
711
+ return {
712
+ ok: false,
713
+ kind: 'command_failed',
714
+ reason: await rollbackBoth(`systemctl_daemon_reload_failed:${reload.code ?? 'spawn'}:${(reload.spawnError ?? reload.stderr).trim().slice(0, 120)}`),
715
+ nextAction: 'Unit files were written but `systemctl --user daemon-reload` failed; the files were rolled back to their previous content (or removed for a first install). Fix the cause (a dead user bus usually means no active login session) and re-run pd service install.',
716
+ };
717
+ }
718
+ // Task §12 review: never report registered when the manager cannot
719
+ // see BOTH units (HOME/XDG_CONFIG_HOME search-path mismatch). A
720
+ // resolved path that is not our file, or a *.d/*.conf drop-in, makes
721
+ // the effective unit ambiguous → refuse, never claim it ours.
722
+ const view = await managerUnitView(registration);
723
+ if (!view.seen) {
724
+ if (view.unreadableReason === undefined) {
725
+ return {
726
+ ok: false,
727
+ kind: 'unsafe_state',
728
+ reason: await rollbackBoth('systemd_unit_not_in_manager_search_path'),
729
+ nextAction: 'The manager could not see the written units. PD restored the previous unit-file snapshot and reloaded the manager; if rollback verification failed, inspect HOME/XDG_CONFIG_HOME and systemctl --user cat before retrying.',
730
+ };
731
+ }
732
+ return {
733
+ ok: false,
734
+ kind: 'command_failed',
735
+ reason: await rollbackBoth(view.unreadableReason),
736
+ nextAction: 'The unit files were written but PD could not verify the manager sees them; the files were rolled back to their previous content. Inspect the stderr above and re-run pd service install.',
737
+ };
738
+ }
739
+ if (view.shadowed !== undefined) {
740
+ return {
741
+ ok: false,
742
+ kind: 'unsafe_state',
743
+ reason: await rollbackBoth(`systemd_unit_ambiguous_manager_view:${view.shadowed.slice(0, 100)}`),
744
+ nextAction: `The written units are ours, but the manager's effective unit resolves differently (${view.shadowed}) — a same-name unit elsewhere or a drop-in changes what systemd would run; the files were rolled back. Inspect \`systemctl --user cat\` and resolve the conflict, then re-run pd service install.`,
745
+ };
746
+ }
747
+ const facts = await gatherFacts(registration);
748
+ return {
749
+ ok: true,
750
+ changed: true,
751
+ facts: { ...facts, triggerIntervalMs: effective.intervalMs },
752
+ };
753
+ },
754
+ async enable(registration) {
755
+ const serviceFile = serviceUnitPath(registration);
756
+ const timerFile = timerUnitPath(registration);
757
+ const service = fileIo.readIfExists(serviceFile);
758
+ const timer = fileIo.readIfExists(timerFile);
759
+ if (!service.ok || !timer.ok) {
760
+ if (unitState(service) === 'missing' || unitState(timer) === 'missing') {
761
+ return {
762
+ ok: false,
763
+ kind: 'unsafe_state',
764
+ reason: 'scheduler_not_registered',
765
+ nextAction: 'No systemd user timer registration exists for this install. Run pd service install first — enable never creates one.',
766
+ };
767
+ }
768
+ return unreadableRegistration(registration, unitDetail(service) + '/' + unitDetail(timer));
769
+ }
770
+ if (!serviceOwnership(service.content, registration) || !timerOwnership(timer.content, registration)) {
771
+ return {
772
+ ok: false,
773
+ kind: 'external_conflict',
774
+ reason: 'systemd_unit_conflict_foreign_unit',
775
+ nextAction: 'The unit pair is not PD\'s own registration; PD refuses to modify foreign systemd units.',
776
+ };
777
+ }
778
+ // Drop-ins or a same-name unit elsewhere make the EFFECTIVE unit
779
+ // different from the file we verified → ambiguous, refuse to arm it.
780
+ const view = await managerUnitView(registration);
781
+ if (view.seen && view.shadowed !== undefined) {
782
+ return {
783
+ ok: false,
784
+ kind: 'external_conflict',
785
+ reason: `systemd_unit_ambiguous_manager_view:${view.shadowed.slice(0, 100)}`,
786
+ nextAction: `The manager's effective unit resolves via ${view.shadowed} — a drop-in or same-name unit changes what systemd would run; PD refuses to modify an ambiguous registration. Inspect \`systemctl --user cat\` manually.`,
787
+ };
788
+ }
789
+ const already = await enabledVerdict(registration);
790
+ const active = await activeVerdict(registration);
791
+ if (already.enabled === true && active.active === true) {
792
+ const facts = await gatherFacts(registration);
793
+ return {
794
+ ok: true,
795
+ changed: false,
796
+ facts,
797
+ };
798
+ }
799
+ const enable = await systemctl(['enable', '--now', timerUnitName(registration)]);
800
+ if (enable.code !== 0) {
801
+ return {
802
+ ok: false,
803
+ kind: 'command_failed',
804
+ reason: `systemctl_enable_failed:${enable.code ?? 'spawn'}:${(enable.spawnError ?? enable.stderr).trim().slice(0, 120)}`,
805
+ nextAction: '`systemctl --user enable --now` failed. A dead user bus usually means no active login session. Inspect the stderr above; the registration exists but will not fire until enabled.',
806
+ };
807
+ }
808
+ // Verify before reporting enabled (task §4/§14): the enable command's
809
+ // exit code alone is not proof — BOTH is-enabled and is-active must
810
+ // positively answer; either UNKNOWN means the enable is unverified.
811
+ const verified = await gatherFacts(registration);
812
+ if (verified.enabled !== true || verified.active !== true) {
813
+ return {
814
+ ok: false,
815
+ kind: 'command_failed',
816
+ reason: 'systemd_enable_unverified',
817
+ nextAction: '`systemctl --user enable --now` returned success but `is-enabled`/`is-active` do not positively report enabled+active. Run pd service status to inspect and retry.',
818
+ };
819
+ }
820
+ return {
821
+ ok: true,
822
+ changed: true,
823
+ facts: verified,
824
+ };
825
+ },
826
+ async disable(registration) {
827
+ const serviceFile = serviceUnitPath(registration);
828
+ const timerFile = timerUnitPath(registration);
829
+ const service = fileIo.readIfExists(serviceFile);
830
+ const timer = fileIo.readIfExists(timerFile);
831
+ if (!service.ok || !timer.ok) {
832
+ if (unitState(service) === 'missing' || unitState(timer) === 'missing') {
833
+ return {
834
+ ok: false,
835
+ kind: 'unsafe_state',
836
+ reason: 'scheduler_not_registered',
837
+ nextAction: 'No systemd user registration exists for this install; nothing to disable.',
838
+ };
839
+ }
840
+ return unreadableRegistration(registration, unitDetail(service) + '/' + unitDetail(timer));
841
+ }
842
+ if (!serviceOwnership(service.content, registration) || !timerOwnership(timer.content, registration)) {
843
+ return {
844
+ ok: false,
845
+ kind: 'external_conflict',
846
+ reason: 'systemd_unit_conflict_foreign_unit',
847
+ nextAction: 'The unit pair is not PD\'s own registration; PD refuses to modify foreign systemd units.',
848
+ };
849
+ }
850
+ const view = await managerUnitView(registration);
851
+ if (view.seen && view.shadowed !== undefined) {
852
+ return {
853
+ ok: false,
854
+ kind: 'external_conflict',
855
+ reason: `systemd_unit_ambiguous_manager_view:${view.shadowed.slice(0, 100)}`,
856
+ nextAction: `The manager's effective unit resolves via ${view.shadowed} — a drop-in or same-name unit changes what systemd would run; PD refuses to modify an ambiguous registration. Inspect \`systemctl --user cat\` manually.`,
857
+ };
858
+ }
859
+ const already = await enabledVerdict(registration);
860
+ const activeBefore = await activeVerdict(registration);
861
+ if (already.enabled === false && activeBefore.active === false) {
862
+ const facts = await gatherFacts(registration);
863
+ return {
864
+ ok: true,
865
+ changed: false,
866
+ facts,
867
+ };
868
+ }
869
+ const disable = await systemctl(['disable', '--now', timerUnitName(registration)]);
870
+ if (disable.code !== 0) {
871
+ return {
872
+ ok: false,
873
+ kind: 'command_failed',
874
+ reason: `systemctl_disable_failed:${disable.code ?? 'spawn'}:${(disable.spawnError ?? disable.stderr).trim().slice(0, 120)}`,
875
+ nextAction: '`systemctl --user disable --now` failed; future automatic triggers may still fire. Inspect the stderr above and retry.',
876
+ };
877
+ }
878
+ // "无法证明停止时不得返回成功" — require POSITIVE disabled+inactive
879
+ // evidence; an unreadable verdict (query timeout/failure) is not
880
+ // proof of stopped and must fail closed, not report success.
881
+ const verified = await gatherFacts(registration);
882
+ if (verified.enabled !== false || verified.active !== false) {
883
+ return {
884
+ ok: false,
885
+ kind: 'command_failed',
886
+ reason: 'systemd_disable_unverified',
887
+ nextAction: '`systemctl --user disable --now` returned success but the timer does not positively report disabled and inactive. Run pd service status to inspect and retry.',
888
+ };
889
+ }
890
+ return {
891
+ ok: true,
892
+ changed: true,
893
+ facts: verified,
894
+ };
895
+ },
896
+ status,
897
+ async uninstall(registration) {
898
+ const serviceFile = serviceUnitPath(registration);
899
+ const timerFile = timerUnitPath(registration);
900
+ const service = fileIo.readIfExists(serviceFile);
901
+ const timer = fileIo.readIfExists(timerFile);
902
+ if (unitState(service) === 'missing' && unitState(timer) === 'missing') {
903
+ return {
904
+ ok: true,
905
+ changed: false,
906
+ facts: baseFacts(registration, { registered: false, enabled: false, active: false }),
907
+ };
908
+ }
909
+ if (unitState(service) === 'unreadable' || unitState(timer) === 'unreadable') {
910
+ return unreadableRegistration(registration, unitDetail(service) + '/' + unitDetail(timer));
911
+ }
912
+ // Verify ownership of BOTH units before touching anything (task §4).
913
+ if (service.ok && !serviceOwnership(service.content, registration)) {
914
+ return {
915
+ ok: false,
916
+ kind: 'external_conflict',
917
+ reason: 'systemd_unit_conflict_foreign_unit',
918
+ nextAction: `${serviceFile} is not PD's own unit; PD never deletes foreign systemd units. Inspect it manually.`,
919
+ };
920
+ }
921
+ if (timer.ok && !timerOwnership(timer.content, registration)) {
922
+ return {
923
+ ok: false,
924
+ kind: 'external_conflict',
925
+ reason: 'systemd_timer_conflict_foreign_unit',
926
+ nextAction: `${timerFile} is not PD's own unit; PD never deletes foreign systemd units. Inspect it manually.`,
927
+ };
928
+ }
929
+ // Partial leftovers of OUR units are still removed below.
930
+ // 1. Stop future triggers — CHECK the result (task §4: a failing
931
+ // disable previously still deleted the files and reported success).
932
+ const disable = await systemctl(['disable', '--now', timerUnitName(registration)]);
933
+ if (disable.code !== 0) {
934
+ const stderr = disable.stderr.trim();
935
+ const notFound = /not[- ]found|no such unit|could not be found|no such file|does not exist/i.test(stderr);
936
+ if (!notFound || disable.spawnError !== undefined) {
937
+ return {
938
+ ok: false,
939
+ kind: 'command_failed',
940
+ reason: `systemctl_disable_failed:${disable.code ?? 'spawn'}:${(disable.spawnError ?? stderr).slice(0, 120)}`,
941
+ nextAction: '`systemctl --user disable --now` failed during uninstall; the unit files were NOT removed. Inspect the stderr above and re-run pd service uninstall.',
942
+ };
943
+ }
944
+ // not-found: the manager already has no such unit — continue to
945
+ // remove the on-disk files.
946
+ }
947
+ // 2. Confirm inactive + disabled before deleting (task §4): require
948
+ // POSITIVE stopped evidence — `not_found` (the manager provably has
949
+ // no such timer) or `disabled` for enablement, and an explicit
950
+ // inactive answer for activity. An UNREADABLE verdict is not proof;
951
+ // treat it as still-live and refuse to delete.
952
+ const enabled = await enabledVerdict(registration);
953
+ const active = await activeVerdict(registration);
954
+ const provablyDisabled = enabled.enabled === false || enabled.state === 'not_found';
955
+ if (!provablyDisabled || active.active !== false) {
956
+ return {
957
+ ok: false,
958
+ kind: 'command_failed',
959
+ reason: 'systemd_uninstall_unverified',
960
+ nextAction: 'The timer does not positively report disabled and inactive after disable (enabled/active may still be true or unreadable); the unit files were NOT removed. Inspect with pd service status and re-run pd service uninstall.',
961
+ };
962
+ }
963
+ // 3. Remove ONLY our unit files.
964
+ const removed = [];
965
+ for (const file of [serviceFile, timerFile]) {
966
+ if (fileIo.exists(file)) {
967
+ const result = fileIo.remove(file);
968
+ if (!result.ok) {
969
+ return {
970
+ ok: false,
971
+ kind: 'command_failed',
972
+ reason: `systemd_unit_remove_failed:${result.reason.slice(0, 80)}`,
973
+ nextAction: `Some unit files were removed (${removed.join(', ') || 'none'}) but ${file} could not be; remove it manually and re-run pd service uninstall to complete the daemon-reload.`,
974
+ };
975
+ }
976
+ removed.push(file);
977
+ }
978
+ }
979
+ // 4. daemon-reload + re-verify the registration is gone (task §4).
980
+ const reload = await systemctl(['daemon-reload']);
981
+ if (reload.code !== 0) {
982
+ return {
983
+ ok: false,
984
+ kind: 'command_failed',
985
+ reason: `systemctl_daemon_reload_failed:${reload.code ?? 'spawn'}:${(reload.spawnError ?? reload.stderr).trim().slice(0, 120)}`,
986
+ nextAction: 'The unit files were removed but `systemctl --user daemon-reload` failed; the manager may hold a stale registration until the next reload or login. Re-run pd service uninstall (idempotent).',
987
+ };
988
+ }
989
+ // BOTH units must be definitively gone from the manager's view —
990
+ // an unreadable manager query is UNKNOWN, not success.
991
+ const gone = await managerUnitsGone(registration);
992
+ if (gone.gone !== true) {
993
+ return {
994
+ ok: false,
995
+ kind: 'command_failed',
996
+ reason: gone.gone === false ? 'systemd_uninstall_unverified' : `systemd_uninstall_unverified:${gone.unreadableReason.slice(0, 80)}`,
997
+ nextAction: gone.gone === false
998
+ ? `The unit files were removed but the manager still resolves ${gone.still} — a stale registration may exist in another unit directory. Inspect \`systemctl --user cat ${gone.still}\` manually.`
999
+ : 'The unit files were removed but the manager state could not be verified — the removal is on disk but OS-visible state is UNKNOWN. Re-run pd service uninstall once systemctl answers.',
1000
+ };
1001
+ }
1002
+ return {
1003
+ ok: true,
1004
+ changed: true,
1005
+ facts: baseFacts(registration, { registered: false, enabled: false, active: false }),
1006
+ };
1007
+ },
1008
+ };
1009
+ }
1010
+ //# sourceMappingURL=linux.js.map