create-principles-disciple 1.154.5 → 1.155.2

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 (428) 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 +11 -0
  14. package/console/dist/server/models/EvidenceChainConsoleModel.js +31 -0
  15. package/console/dist/server/routes/health.d.ts +1 -0
  16. package/console/dist/server/routes/health.js +12 -0
  17. package/console/dist/server/routes/service-host.d.ts +19 -0
  18. package/console/dist/server/routes/service-host.js +129 -0
  19. package/console/dist/web/assets/app.js +39 -39
  20. package/console/package.json +1 -1
  21. package/core/dist/runtime/adapter/pi-ai-http-transport.d.ts.map +1 -1
  22. package/core/dist/runtime/adapter/pi-ai-http-transport.js.map +1 -1
  23. package/core/dist/runtime/context-payload.d.ts +48 -0
  24. package/core/dist/runtime/context-payload.d.ts.map +1 -1
  25. package/core/dist/runtime/context-payload.js +12 -0
  26. package/core/dist/runtime/context-payload.js.map +1 -1
  27. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.d.ts.map +1 -1
  28. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.js +18 -0
  29. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.js.map +1 -1
  30. package/core/dist/runtime/diagnostician-candidate.d.ts.map +1 -1
  31. package/core/dist/runtime/diagnostician-candidate.js +18 -2
  32. package/core/dist/runtime/diagnostician-candidate.js.map +1 -1
  33. package/core/dist/runtime/evidence-guards.d.ts +7 -3
  34. package/core/dist/runtime/evidence-guards.d.ts.map +1 -1
  35. package/core/dist/runtime/evidence-guards.js +9 -7
  36. package/core/dist/runtime/evidence-guards.js.map +1 -1
  37. package/core/dist/runtime/feature-flags/feature-flag-contract.d.ts.map +1 -1
  38. package/core/dist/runtime/feature-flags/feature-flag-contract.js +14 -0
  39. package/core/dist/runtime/feature-flags/feature-flag-contract.js.map +1 -1
  40. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.d.ts.map +1 -1
  41. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js +8 -0
  42. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js.map +1 -1
  43. package/core/dist/runtime/host-submission-context.d.ts +83 -0
  44. package/core/dist/runtime/host-submission-context.d.ts.map +1 -0
  45. package/core/dist/runtime/host-submission-context.js +183 -0
  46. package/core/dist/runtime/host-submission-context.js.map +1 -0
  47. package/core/dist/runtime/index.d.ts +9 -2
  48. package/core/dist/runtime/index.d.ts.map +1 -1
  49. package/core/dist/runtime/index.js +29 -2
  50. package/core/dist/runtime/index.js.map +1 -1
  51. package/core/dist/runtime/intent/intent-doc.d.ts.map +1 -1
  52. package/core/dist/runtime/intent/intent-doc.js +29 -5
  53. package/core/dist/runtime/intent/intent-doc.js.map +1 -1
  54. package/core/dist/runtime/internalization/diag-distiller-runner.d.ts +9 -0
  55. package/core/dist/runtime/internalization/diag-distiller-runner.d.ts.map +1 -1
  56. package/core/dist/runtime/internalization/diag-distiller-runner.js +13 -0
  57. package/core/dist/runtime/internalization/diag-distiller-runner.js.map +1 -1
  58. package/core/dist/runtime/internalization/diag-rootcause-runner.d.ts +11 -0
  59. package/core/dist/runtime/internalization/diag-rootcause-runner.d.ts.map +1 -1
  60. package/core/dist/runtime/internalization/diag-rootcause-runner.js +10 -0
  61. package/core/dist/runtime/internalization/diag-rootcause-runner.js.map +1 -1
  62. package/core/dist/runtime/internalization/diag-router-runner.d.ts +9 -0
  63. package/core/dist/runtime/internalization/diag-router-runner.d.ts.map +1 -1
  64. package/core/dist/runtime/internalization/diag-router-runner.js +13 -0
  65. package/core/dist/runtime/internalization/diag-router-runner.js.map +1 -1
  66. package/core/dist/runtime/internalization/index.d.ts +1 -1
  67. package/core/dist/runtime/internalization/index.d.ts.map +1 -1
  68. package/core/dist/runtime/internalization/index.js +1 -1
  69. package/core/dist/runtime/internalization/index.js.map +1 -1
  70. package/core/dist/runtime/internalization/intake-to-internalization-bridge.d.ts +19 -0
  71. package/core/dist/runtime/internalization/intake-to-internalization-bridge.d.ts.map +1 -1
  72. package/core/dist/runtime/internalization/intake-to-internalization-bridge.js +24 -0
  73. package/core/dist/runtime/internalization/intake-to-internalization-bridge.js.map +1 -1
  74. package/core/dist/runtime/internalization/internalization-orchestrator.d.ts +8 -0
  75. package/core/dist/runtime/internalization/internalization-orchestrator.d.ts.map +1 -1
  76. package/core/dist/runtime/internalization/internalization-orchestrator.js +36 -4
  77. package/core/dist/runtime/internalization/internalization-orchestrator.js.map +1 -1
  78. package/core/dist/runtime/internalization/source-authorization-boundary.d.ts +39 -0
  79. package/core/dist/runtime/internalization/source-authorization-boundary.d.ts.map +1 -0
  80. package/core/dist/runtime/internalization/source-authorization-boundary.js +57 -0
  81. package/core/dist/runtime/internalization/source-authorization-boundary.js.map +1 -0
  82. package/core/dist/runtime/internalization/split-diagnostician-runner.d.ts.map +1 -1
  83. package/core/dist/runtime/internalization/split-diagnostician-runner.js +72 -5
  84. package/core/dist/runtime/internalization/split-diagnostician-runner.js.map +1 -1
  85. package/core/dist/runtime/pain-admission-disposition.d.ts +60 -0
  86. package/core/dist/runtime/pain-admission-disposition.d.ts.map +1 -0
  87. package/core/dist/runtime/pain-admission-disposition.js +37 -0
  88. package/core/dist/runtime/pain-admission-disposition.js.map +1 -0
  89. package/core/dist/runtime/pain-ingress-payload.d.ts +36 -2
  90. package/core/dist/runtime/pain-ingress-payload.d.ts.map +1 -1
  91. package/core/dist/runtime/pain-ingress-payload.js +63 -6
  92. package/core/dist/runtime/pain-ingress-payload.js.map +1 -1
  93. package/core/dist/runtime/pain-ingress.d.ts.map +1 -1
  94. package/core/dist/runtime/pain-ingress.js +28 -0
  95. package/core/dist/runtime/pain-ingress.js.map +1 -1
  96. package/core/dist/runtime/pain-recall-read-model.d.ts +13 -1
  97. package/core/dist/runtime/pain-recall-read-model.d.ts.map +1 -1
  98. package/core/dist/runtime/pain-recall-read-model.js +50 -7
  99. package/core/dist/runtime/pain-recall-read-model.js.map +1 -1
  100. package/core/dist/runtime/pain-receipt-recovery.d.ts +147 -0
  101. package/core/dist/runtime/pain-receipt-recovery.d.ts.map +1 -0
  102. package/core/dist/runtime/pain-receipt-recovery.js +475 -0
  103. package/core/dist/runtime/pain-receipt-recovery.js.map +1 -0
  104. package/core/dist/runtime/pain-signal-bridge.d.ts +13 -1
  105. package/core/dist/runtime/pain-signal-bridge.d.ts.map +1 -1
  106. package/core/dist/runtime/pain-signal-bridge.js +174 -0
  107. package/core/dist/runtime/pain-signal-bridge.js.map +1 -1
  108. package/core/dist/runtime/pain-signal-runtime-factory.d.ts +9 -0
  109. package/core/dist/runtime/pain-signal-runtime-factory.d.ts.map +1 -1
  110. package/core/dist/runtime/pain-signal-runtime-factory.js +8 -3
  111. package/core/dist/runtime/pain-signal-runtime-factory.js.map +1 -1
  112. package/core/dist/runtime/pain-submit-capability.d.ts +11 -0
  113. package/core/dist/runtime/pain-submit-capability.d.ts.map +1 -1
  114. package/core/dist/runtime/pain-submit-capability.js +77 -3
  115. package/core/dist/runtime/pain-submit-capability.js.map +1 -1
  116. package/core/dist/runtime/pain-target-evidence-reconcile.d.ts +55 -0
  117. package/core/dist/runtime/pain-target-evidence-reconcile.d.ts.map +1 -0
  118. package/core/dist/runtime/pain-target-evidence-reconcile.js +164 -0
  119. package/core/dist/runtime/pain-target-evidence-reconcile.js.map +1 -0
  120. package/core/dist/runtime/pain-to-principle-service.d.ts +8 -0
  121. package/core/dist/runtime/pain-to-principle-service.d.ts.map +1 -1
  122. package/core/dist/runtime/pain-to-principle-service.js +1 -0
  123. package/core/dist/runtime/pain-to-principle-service.js.map +1 -1
  124. package/core/dist/runtime/source-material-authorization.d.ts +166 -0
  125. package/core/dist/runtime/source-material-authorization.d.ts.map +1 -0
  126. package/core/dist/runtime/source-material-authorization.js +250 -0
  127. package/core/dist/runtime/source-material-authorization.js.map +1 -0
  128. package/core/dist/runtime/store/context/index.d.ts +1 -0
  129. package/core/dist/runtime/store/context/index.d.ts.map +1 -1
  130. package/core/dist/runtime/store/context/index.js +1 -0
  131. package/core/dist/runtime/store/context/index.js.map +1 -1
  132. package/core/dist/runtime/store/context/promoted-evidence-reader.d.ts +8 -0
  133. package/core/dist/runtime/store/context/promoted-evidence-reader.d.ts.map +1 -1
  134. package/core/dist/runtime/store/context/promoted-evidence-reader.js +15 -1
  135. package/core/dist/runtime/store/context/promoted-evidence-reader.js.map +1 -1
  136. package/core/dist/runtime/store/context/sqlite-context-assembler.d.ts +22 -0
  137. package/core/dist/runtime/store/context/sqlite-context-assembler.d.ts.map +1 -1
  138. package/core/dist/runtime/store/context/sqlite-context-assembler.js +153 -3
  139. package/core/dist/runtime/store/context/sqlite-context-assembler.js.map +1 -1
  140. package/core/dist/runtime/store/context/trajectory-turn-reader.d.ts +13 -0
  141. package/core/dist/runtime/store/context/trajectory-turn-reader.d.ts.map +1 -1
  142. package/core/dist/runtime/store/lifecycle/lease-manager.d.ts +15 -0
  143. package/core/dist/runtime/store/lifecycle/lease-manager.d.ts.map +1 -1
  144. package/core/dist/runtime/store/lifecycle/lease-manager.js +16 -1
  145. package/core/dist/runtime/store/lifecycle/lease-manager.js.map +1 -1
  146. package/core/dist/runtime/store/runtime-state-manager.d.ts +2 -0
  147. package/core/dist/runtime/store/runtime-state-manager.d.ts.map +1 -1
  148. package/core/dist/runtime/store/runtime-state-manager.js.map +1 -1
  149. package/core/dist/runtime/store/task/memory-task-store.d.ts +1 -0
  150. package/core/dist/runtime/store/task/memory-task-store.d.ts.map +1 -1
  151. package/core/dist/runtime/store/task/memory-task-store.js +37 -0
  152. package/core/dist/runtime/store/task/memory-task-store.js.map +1 -1
  153. package/core/dist/runtime/store/task/sqlite-task-store.d.ts +10 -0
  154. package/core/dist/runtime/store/task/sqlite-task-store.d.ts.map +1 -1
  155. package/core/dist/runtime/store/task/sqlite-task-store.js +20 -0
  156. package/core/dist/runtime/store/task/sqlite-task-store.js.map +1 -1
  157. package/core/dist/runtime/store/task/task-store.d.ts +16 -0
  158. package/core/dist/runtime/store/task/task-store.d.ts.map +1 -1
  159. package/core/dist/runtime/task-status.d.ts +13 -0
  160. package/core/dist/runtime/task-status.d.ts.map +1 -1
  161. package/core/dist/runtime/task-status.js +9 -0
  162. package/core/dist/runtime/task-status.js.map +1 -1
  163. package/core/dist/runtime/types/evidence-chain-contract.d.ts +10 -0
  164. package/core/dist/runtime/types/evidence-chain-contract.d.ts.map +1 -1
  165. package/core/dist/runtime/types/evidence-chain-contract.js +7 -0
  166. package/core/dist/runtime/types/evidence-chain-contract.js.map +1 -1
  167. package/core/package.json +2 -2
  168. package/dist/index.d.ts.map +1 -1
  169. package/dist/index.js +11 -0
  170. package/dist/index.js.map +1 -1
  171. package/dist/installer.d.ts.map +1 -1
  172. package/dist/installer.js +77 -30
  173. package/dist/installer.js.map +1 -1
  174. package/dist/installers/mcp-registration-conflict.d.ts +8 -0
  175. package/dist/installers/mcp-registration-conflict.d.ts.map +1 -1
  176. package/dist/installers/mcp-registration-conflict.js +34 -1
  177. package/dist/installers/mcp-registration-conflict.js.map +1 -1
  178. package/dist/installers/workbuddy-host-installer.d.ts +45 -13
  179. package/dist/installers/workbuddy-host-installer.d.ts.map +1 -1
  180. package/dist/installers/workbuddy-host-installer.js +284 -21
  181. package/dist/installers/workbuddy-host-installer.js.map +1 -1
  182. package/dist/prompts.d.ts +11 -0
  183. package/dist/prompts.d.ts.map +1 -1
  184. package/dist/prompts.js +4 -0
  185. package/dist/prompts.js.map +1 -1
  186. package/dist/service-host-bridge.d.ts +67 -0
  187. package/dist/service-host-bridge.d.ts.map +1 -0
  188. package/dist/service-host-bridge.js +292 -0
  189. package/dist/service-host-bridge.js.map +1 -0
  190. package/dist/uninstaller.d.ts.map +1 -1
  191. package/dist/uninstaller.js +26 -0
  192. package/dist/uninstaller.js.map +1 -1
  193. package/dist/update/install-layout.d.ts +0 -12
  194. package/dist/update/install-layout.d.ts.map +1 -1
  195. package/dist/update/install-layout.js +42 -15
  196. package/dist/update/install-layout.js.map +1 -1
  197. package/host-runtime/dist/diagnostician-auto-run.js +4 -1
  198. package/host-runtime/dist/governance-observation-store.d.ts +7 -0
  199. package/host-runtime/dist/governance-observation-store.js +15 -4
  200. package/host-runtime/dist/governance-signal-admission.d.ts +49 -0
  201. package/host-runtime/dist/governance-signal-admission.js +355 -94
  202. package/host-runtime/dist/governance-trajectory-turn-reader.d.ts +20 -4
  203. package/host-runtime/dist/governance-trajectory-turn-reader.js +77 -5
  204. package/host-runtime/dist/index.d.ts +2 -0
  205. package/host-runtime/dist/index.js +5 -0
  206. package/host-runtime/dist/internalization-consumer-cycle.js +4 -1
  207. package/host-runtime/dist/pd-config.d.ts +10 -0
  208. package/host-runtime/dist/pd-config.js +37 -0
  209. package/host-runtime/dist/signal-stage2-cycle.js +28 -1
  210. package/host-runtime/dist/source-material-authorization.d.ts +53 -0
  211. package/host-runtime/dist/source-material-authorization.js +67 -0
  212. package/host-runtime/dist/source-revocation-sweep.d.ts +172 -0
  213. package/host-runtime/dist/source-revocation-sweep.js +928 -0
  214. package/host-runtime/package.json +5 -1
  215. package/install-layout/dist/background-execution-transition.d.ts +258 -0
  216. package/install-layout/dist/background-execution-transition.js +836 -0
  217. package/install-layout/dist/index.d.ts +8 -0
  218. package/install-layout/dist/index.js +8 -0
  219. package/install-layout/package.json +6 -2
  220. package/package.json +7 -6
  221. package/pd-cli/dist/commands/candidate.d.ts.map +1 -1
  222. package/pd-cli/dist/commands/candidate.js +16 -5
  223. package/pd-cli/dist/commands/candidate.js.map +1 -1
  224. package/pd-cli/dist/commands/codex-setup.d.ts.map +1 -1
  225. package/pd-cli/dist/commands/codex-setup.js +17 -1
  226. package/pd-cli/dist/commands/codex-setup.js.map +1 -1
  227. package/pd-cli/dist/commands/codex-worker.d.ts.map +1 -1
  228. package/pd-cli/dist/commands/codex-worker.js +8 -4
  229. package/pd-cli/dist/commands/codex-worker.js.map +1 -1
  230. package/pd-cli/dist/commands/consent-sweep-revoked.d.ts +20 -0
  231. package/pd-cli/dist/commands/consent-sweep-revoked.d.ts.map +1 -0
  232. package/pd-cli/dist/commands/consent-sweep-revoked.js +85 -0
  233. package/pd-cli/dist/commands/consent-sweep-revoked.js.map +1 -0
  234. package/pd-cli/dist/commands/console.d.ts.map +1 -1
  235. package/pd-cli/dist/commands/console.js +9 -0
  236. package/pd-cli/dist/commands/console.js.map +1 -1
  237. package/pd-cli/dist/commands/context.d.ts.map +1 -1
  238. package/pd-cli/dist/commands/context.js +9 -1
  239. package/pd-cli/dist/commands/context.js.map +1 -1
  240. package/pd-cli/dist/commands/diagnose.d.ts.map +1 -1
  241. package/pd-cli/dist/commands/diagnose.js +12 -6
  242. package/pd-cli/dist/commands/diagnose.js.map +1 -1
  243. package/pd-cli/dist/commands/health-console.d.ts +1 -1
  244. package/pd-cli/dist/commands/health-console.d.ts.map +1 -1
  245. package/pd-cli/dist/commands/health-console.js +15 -1
  246. package/pd-cli/dist/commands/health-console.js.map +1 -1
  247. package/pd-cli/dist/commands/health.d.ts.map +1 -1
  248. package/pd-cli/dist/commands/health.js +7 -1
  249. package/pd-cli/dist/commands/health.js.map +1 -1
  250. package/pd-cli/dist/commands/openclaw-worker.d.ts +11 -0
  251. package/pd-cli/dist/commands/openclaw-worker.d.ts.map +1 -0
  252. package/pd-cli/dist/commands/openclaw-worker.js +199 -0
  253. package/pd-cli/dist/commands/openclaw-worker.js.map +1 -0
  254. package/pd-cli/dist/commands/pain-explicit.d.ts.map +1 -1
  255. package/pd-cli/dist/commands/pain-explicit.js +1 -0
  256. package/pd-cli/dist/commands/pain-explicit.js.map +1 -1
  257. package/pd-cli/dist/commands/pain-recall.d.ts +2 -2
  258. package/pd-cli/dist/commands/pain-recall.d.ts.map +1 -1
  259. package/pd-cli/dist/commands/pain-recall.js +7 -1
  260. package/pd-cli/dist/commands/pain-recall.js.map +1 -1
  261. package/pd-cli/dist/commands/pain-retry.d.ts.map +1 -1
  262. package/pd-cli/dist/commands/pain-retry.js +12 -6
  263. package/pd-cli/dist/commands/pain-retry.js.map +1 -1
  264. package/pd-cli/dist/commands/runtime-internalization-enqueue-successors.d.ts.map +1 -1
  265. package/pd-cli/dist/commands/runtime-internalization-enqueue-successors.js +2 -1
  266. package/pd-cli/dist/commands/runtime-internalization-enqueue-successors.js.map +1 -1
  267. package/pd-cli/dist/commands/runtime-internalization-run-once.d.ts +1 -0
  268. package/pd-cli/dist/commands/runtime-internalization-run-once.d.ts.map +1 -1
  269. package/pd-cli/dist/commands/runtime-internalization-run-once.js +32 -8
  270. package/pd-cli/dist/commands/runtime-internalization-run-once.js.map +1 -1
  271. package/pd-cli/dist/commands/runtime-internalization-wake-once.d.ts.map +1 -1
  272. package/pd-cli/dist/commands/runtime-internalization-wake-once.js +2 -1
  273. package/pd-cli/dist/commands/runtime-internalization-wake-once.js.map +1 -1
  274. package/pd-cli/dist/commands/service-handover.d.ts +12 -0
  275. package/pd-cli/dist/commands/service-handover.d.ts.map +1 -0
  276. package/pd-cli/dist/commands/service-handover.js +117 -0
  277. package/pd-cli/dist/commands/service-handover.js.map +1 -0
  278. package/pd-cli/dist/commands/service-lifecycle.d.ts +31 -0
  279. package/pd-cli/dist/commands/service-lifecycle.d.ts.map +1 -0
  280. package/pd-cli/dist/commands/service-lifecycle.js +207 -0
  281. package/pd-cli/dist/commands/service-lifecycle.js.map +1 -0
  282. package/pd-cli/dist/commands/service-run-once.d.ts +96 -0
  283. package/pd-cli/dist/commands/service-run-once.d.ts.map +1 -1
  284. package/pd-cli/dist/commands/service-run-once.js +432 -13
  285. package/pd-cli/dist/commands/service-run-once.js.map +1 -1
  286. package/pd-cli/dist/commands/workbuddy-setup.d.ts.map +1 -1
  287. package/pd-cli/dist/commands/workbuddy-setup.js +22 -2
  288. package/pd-cli/dist/commands/workbuddy-setup.js.map +1 -1
  289. package/pd-cli/dist/program.d.ts.map +1 -1
  290. package/pd-cli/dist/program.js +167 -9
  291. package/pd-cli/dist/program.js.map +1 -1
  292. package/pd-cli/dist/services/admission-write-gate.d.ts +3 -1
  293. package/pd-cli/dist/services/admission-write-gate.d.ts.map +1 -1
  294. package/pd-cli/dist/services/admission-write-gate.js +1 -0
  295. package/pd-cli/dist/services/admission-write-gate.js.map +1 -1
  296. package/pd-cli/dist/services/console-launcher.d.ts +93 -1
  297. package/pd-cli/dist/services/console-launcher.d.ts.map +1 -1
  298. package/pd-cli/dist/services/console-launcher.js +375 -10
  299. package/pd-cli/dist/services/console-launcher.js.map +1 -1
  300. package/pd-cli/dist/services/service-host/coordinator-common.d.ts +49 -0
  301. package/pd-cli/dist/services/service-host/coordinator-common.d.ts.map +1 -0
  302. package/pd-cli/dist/services/service-host/coordinator-common.js +158 -0
  303. package/pd-cli/dist/services/service-host/coordinator-common.js.map +1 -0
  304. package/pd-cli/dist/services/service-host/handover-claims.d.ts +14 -0
  305. package/pd-cli/dist/services/service-host/handover-claims.d.ts.map +1 -0
  306. package/pd-cli/dist/services/service-host/handover-claims.js +50 -0
  307. package/pd-cli/dist/services/service-host/handover-claims.js.map +1 -0
  308. package/pd-cli/dist/services/service-host/index.d.ts +19 -3
  309. package/pd-cli/dist/services/service-host/index.d.ts.map +1 -1
  310. package/pd-cli/dist/services/service-host/index.js +21 -3
  311. package/pd-cli/dist/services/service-host/index.js.map +1 -1
  312. package/pd-cli/dist/services/service-host/install-identity.d.ts +23 -3
  313. package/pd-cli/dist/services/service-host/install-identity.d.ts.map +1 -1
  314. package/pd-cli/dist/services/service-host/install-identity.js +15 -5
  315. package/pd-cli/dist/services/service-host/install-identity.js.map +1 -1
  316. package/pd-cli/dist/services/service-host/locking/service-run-lock.d.ts +130 -9
  317. package/pd-cli/dist/services/service-host/locking/service-run-lock.d.ts.map +1 -1
  318. package/pd-cli/dist/services/service-host/locking/service-run-lock.js +99 -19
  319. package/pd-cli/dist/services/service-host/locking/service-run-lock.js.map +1 -1
  320. package/pd-cli/dist/services/service-host/managed-run.d.ts +75 -0
  321. package/pd-cli/dist/services/service-host/managed-run.d.ts.map +1 -0
  322. package/pd-cli/dist/services/service-host/managed-run.js +550 -0
  323. package/pd-cli/dist/services/service-host/managed-run.js.map +1 -0
  324. package/pd-cli/dist/services/service-host/progress-evidence.d.ts +38 -0
  325. package/pd-cli/dist/services/service-host/progress-evidence.d.ts.map +1 -0
  326. package/pd-cli/dist/services/service-host/progress-evidence.js +155 -0
  327. package/pd-cli/dist/services/service-host/progress-evidence.js.map +1 -0
  328. package/pd-cli/dist/services/service-host/run-once.d.ts.map +1 -1
  329. package/pd-cli/dist/services/service-host/run-once.js +4 -136
  330. package/pd-cli/dist/services/service-host/run-once.js.map +1 -1
  331. package/pd-cli/dist/services/service-host/scheduler/contract.d.ts +184 -0
  332. package/pd-cli/dist/services/service-host/scheduler/contract.d.ts.map +1 -0
  333. package/pd-cli/dist/services/service-host/scheduler/contract.js +86 -0
  334. package/pd-cli/dist/services/service-host/scheduler/contract.js.map +1 -0
  335. package/pd-cli/dist/services/service-host/scheduler/index.d.ts +76 -0
  336. package/pd-cli/dist/services/service-host/scheduler/index.d.ts.map +1 -0
  337. package/pd-cli/dist/services/service-host/scheduler/index.js +128 -0
  338. package/pd-cli/dist/services/service-host/scheduler/index.js.map +1 -0
  339. package/pd-cli/dist/services/service-host/scheduler/linux.d.ts +27 -0
  340. package/pd-cli/dist/services/service-host/scheduler/linux.d.ts.map +1 -0
  341. package/pd-cli/dist/services/service-host/scheduler/linux.js +1010 -0
  342. package/pd-cli/dist/services/service-host/scheduler/linux.js.map +1 -0
  343. package/pd-cli/dist/services/service-host/scheduler/macos.d.ts +13 -0
  344. package/pd-cli/dist/services/service-host/scheduler/macos.d.ts.map +1 -0
  345. package/pd-cli/dist/services/service-host/scheduler/macos.js +819 -0
  346. package/pd-cli/dist/services/service-host/scheduler/macos.js.map +1 -0
  347. package/pd-cli/dist/services/service-host/scheduler/runtime-io.d.ts +13 -0
  348. package/pd-cli/dist/services/service-host/scheduler/runtime-io.d.ts.map +1 -0
  349. package/pd-cli/dist/services/service-host/scheduler/runtime-io.js +141 -0
  350. package/pd-cli/dist/services/service-host/scheduler/runtime-io.js.map +1 -0
  351. package/pd-cli/dist/services/service-host/scheduler/service-status.d.ts +99 -0
  352. package/pd-cli/dist/services/service-host/scheduler/service-status.d.ts.map +1 -0
  353. package/pd-cli/dist/services/service-host/scheduler/service-status.js +202 -0
  354. package/pd-cli/dist/services/service-host/scheduler/service-status.js.map +1 -0
  355. package/pd-cli/dist/services/service-host/scheduler/windows.d.ts +40 -0
  356. package/pd-cli/dist/services/service-host/scheduler/windows.d.ts.map +1 -0
  357. package/pd-cli/dist/services/service-host/scheduler/windows.js +688 -0
  358. package/pd-cli/dist/services/service-host/scheduler/windows.js.map +1 -0
  359. package/pd-cli/dist/services/service-host/shadow-progress-store.d.ts +43 -0
  360. package/pd-cli/dist/services/service-host/shadow-progress-store.d.ts.map +1 -0
  361. package/pd-cli/dist/services/service-host/shadow-progress-store.js +156 -0
  362. package/pd-cli/dist/services/service-host/shadow-progress-store.js.map +1 -0
  363. package/pd-cli/dist/services/service-host/shadow-run.d.ts +87 -0
  364. package/pd-cli/dist/services/service-host/shadow-run.d.ts.map +1 -0
  365. package/pd-cli/dist/services/service-host/shadow-run.js +549 -0
  366. package/pd-cli/dist/services/service-host/shadow-run.js.map +1 -0
  367. package/pd-cli/dist/services/service-host/status/service-run-status.d.ts +114 -4
  368. package/pd-cli/dist/services/service-host/status/service-run-status.d.ts.map +1 -1
  369. package/pd-cli/dist/services/service-host/status/service-run-status.js +37 -0
  370. package/pd-cli/dist/services/service-host/status/service-run-status.js.map +1 -1
  371. package/pd-cli/dist/services/service-host/worker-adapter-codex.d.ts +2 -0
  372. package/pd-cli/dist/services/service-host/worker-adapter-codex.d.ts.map +1 -0
  373. package/pd-cli/dist/services/service-host/worker-adapter-codex.js +76 -0
  374. package/pd-cli/dist/services/service-host/worker-adapter-codex.js.map +1 -0
  375. package/pd-cli/dist/services/service-host/worker-adapter-openclaw.d.ts +2 -0
  376. package/pd-cli/dist/services/service-host/worker-adapter-openclaw.d.ts.map +1 -0
  377. package/pd-cli/dist/services/service-host/worker-adapter-openclaw.js +49 -0
  378. package/pd-cli/dist/services/service-host/worker-adapter-openclaw.js.map +1 -0
  379. package/pd-cli/dist/services/service-host/worker-adapter-workbuddy.d.ts +2 -0
  380. package/pd-cli/dist/services/service-host/worker-adapter-workbuddy.d.ts.map +1 -0
  381. package/pd-cli/dist/services/service-host/worker-adapter-workbuddy.js +36 -0
  382. package/pd-cli/dist/services/service-host/worker-adapter-workbuddy.js.map +1 -0
  383. package/pd-cli/dist/services/service-host/worker-adapter.d.ts +187 -0
  384. package/pd-cli/dist/services/service-host/worker-adapter.d.ts.map +1 -0
  385. package/pd-cli/dist/services/service-host/worker-adapter.js +609 -0
  386. package/pd-cli/dist/services/service-host/worker-adapter.js.map +1 -0
  387. package/pd-cli/dist/services/service-host/worker-env.d.ts +84 -0
  388. package/pd-cli/dist/services/service-host/worker-env.d.ts.map +1 -0
  389. package/pd-cli/dist/services/service-host/worker-env.js +195 -0
  390. package/pd-cli/dist/services/service-host/worker-env.js.map +1 -0
  391. package/pd-cli/dist/services/service-host/worker-process.d.ts +75 -0
  392. package/pd-cli/dist/services/service-host/worker-process.d.ts.map +1 -0
  393. package/pd-cli/dist/services/service-host/worker-process.js +225 -0
  394. package/pd-cli/dist/services/service-host/worker-process.js.map +1 -0
  395. package/pd-cli/dist/services/service-host/workspace-dispatch.d.ts +61 -0
  396. package/pd-cli/dist/services/service-host/workspace-dispatch.d.ts.map +1 -0
  397. package/pd-cli/dist/services/service-host/workspace-dispatch.js +105 -0
  398. package/pd-cli/dist/services/service-host/workspace-dispatch.js.map +1 -0
  399. package/pd-cli/dist/services/service-host/workspace-handover.d.ts +190 -0
  400. package/pd-cli/dist/services/service-host/workspace-handover.d.ts.map +1 -0
  401. package/pd-cli/dist/services/service-host/workspace-handover.js +1393 -0
  402. package/pd-cli/dist/services/service-host/workspace-handover.js.map +1 -0
  403. package/pd-cli/package.json +6 -5
  404. package/pd-mcp-server/dist/submit-assembly.js +159 -42
  405. package/pd-mcp-server/dist/version.d.ts +1 -1
  406. package/pd-mcp-server/dist/version.js +1 -1
  407. package/pd-mcp-server/package.json +1 -1
  408. package/plugin/dist/bundle.js +662 -637
  409. package/plugin/dist/openclaw-worker.d.ts +92 -0
  410. package/plugin/dist/openclaw-worker.js +2446 -0
  411. package/plugin/dist/openclaw.plugin.json +1 -1
  412. package/plugin/dist/service/gateway-consumer-lease.d.ts +142 -0
  413. package/plugin/dist/service/gateway-quiesce-ack.d.ts +40 -0
  414. package/plugin/dist/service/internalization-auto-consumer-service.d.ts +68 -1
  415. package/plugin/openclaw.plugin.json +1 -1
  416. package/plugin/package.json +5 -1
  417. package/release-manager/dist/installer.js +77 -30
  418. package/release-manager/dist/installers/mcp-registration-conflict.js +34 -1
  419. package/release-manager/dist/installers/workbuddy-host-installer.js +284 -21
  420. package/release-manager/dist/service-host-bridge.js +292 -0
  421. package/release-manager/dist/update/install-layout.js +42 -15
  422. package/release-manager/package.json +5 -4
  423. package/workbuddy-adapter/dist/index.d.ts +1 -1
  424. package/workbuddy-adapter/dist/index.js +1 -1
  425. package/workbuddy-adapter/dist/worker/workspace-worker.d.ts +7 -0
  426. package/workbuddy-adapter/dist/worker/workspace-worker.js +179 -10
  427. package/workbuddy-adapter/package.json +1 -1
  428. package/workbuddy-adapter/plugin/.codebuddy-plugin/plugin.json +2 -2
@@ -0,0 +1,819 @@
1
+ /**
2
+ * macOS scheduler adapter — current-user LaunchAgent (SPEC §10.2, task §3.3).
3
+ *
4
+ * Registration: `~/Library/LaunchAgents/com.principles-disciple.service-host.<key>.plist`
5
+ * with RunAtLoad + StartInterval. Managed with `launchctl bootstrap/bootout/
6
+ * enable/disable` against the caller's own `gui/<uid>` domain — never a
7
+ * LaunchDaemon, never root (task §3.3).
8
+ *
9
+ * Lifecycle contract (task §3 review):
10
+ * - install writes the plist + the log directory ONLY (no bootstrap, no
11
+ * Worker) and persistently DISABLES the label — a LaunchAgent left
12
+ * enabled would auto-load with RunAtLoad at the next login, which would
13
+ * break the installed_disabled contract;
14
+ * - enable verifies ownership, `launchctl enable`, then `bootstrap` when
15
+ * not loaded, and verifies the job is loaded before reporting enabled;
16
+ * - disable `launchctl disable` (persistent) + `bootout`, and verifies
17
+ * the job is actually unloaded — never reports stopped without proof;
18
+ * - status reads each witness independently (plist existence/ownership,
19
+ * launchd loaded state, launchd disabled flag); an unreadable witness
20
+ * yields unknown, never a guessed false;
21
+ * - uninstall verifies ownership, stops+unloads, then removes ONLY our
22
+ * own plist — an external same-label LaunchAgent is never deleted.
23
+ *
24
+ * Honest platform semantics (SPEC §10.2 audit): a LaunchAgent exists only
25
+ * inside an interactive login session — no pre-login trigger, no trigger
26
+ * after logout. This adapter never claims otherwise.
27
+ *
28
+ * IMPORTANT (task §9.F): this implementation is unit-tested against a faked
29
+ * command boundary; real-platform acceptance on macOS is recorded as
30
+ * NOT_VERIFIED until it runs on a real Darwin host.
31
+ */
32
+ import * as path from 'node:path';
33
+ import plistLib from 'plist';
34
+ import { schedulerInvocationArgs } from './contract.js';
35
+ function escapeXml(value) {
36
+ return value.replace(/[&<>"']/g, (c) => {
37
+ switch (c) {
38
+ case '&': return '&amp;';
39
+ case '<': return '&lt;';
40
+ case '>': return '&gt;';
41
+ case '"': return '&quot;';
42
+ default: return '&apos;';
43
+ }
44
+ });
45
+ }
46
+ /** The LaunchAgent plist document. Exported for unit tests. */
47
+ export function buildMacosLaunchAgentPlist(registration) {
48
+ const programArguments = [
49
+ registration.nodePath,
50
+ ...schedulerInvocationArgs(registration),
51
+ ].map((part) => ` <string>${escapeXml(part)}</string>`);
52
+ return [
53
+ '<?xml version="1.0" encoding="UTF-8"?>',
54
+ '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">',
55
+ '<plist version="1.0">',
56
+ '<dict>',
57
+ ` <key>Label</key>`,
58
+ ` <string>${escapeXml(registration.identity.macosLabel)}</string>`,
59
+ ' <key>ProgramArguments</key>',
60
+ ' <array>',
61
+ ...programArguments,
62
+ ' </array>',
63
+ ' <key>RunAtLoad</key>',
64
+ ' <true/>',
65
+ ' <key>StartInterval</key>',
66
+ ` <integer>${Math.round(registration.intervalMs / 1000)}</integer>`,
67
+ ' <key>WorkingDirectory</key>',
68
+ ` <string>${escapeXml(registration.pdHome)}</string>`,
69
+ ' <key>StandardOutPath</key>',
70
+ ` <string>${escapeXml(path.join(registration.pdHome, 'service', 'scheduler-stdout.log'))}</string>`,
71
+ ' <key>StandardErrorPath</key>',
72
+ ` <string>${escapeXml(path.join(registration.pdHome, 'service', 'scheduler-stderr.log'))}</string>`,
73
+ '</dict>',
74
+ '</plist>',
75
+ '',
76
+ ].join('\n');
77
+ }
78
+ /** Parse `<key>StartInterval</key><integer>N</integer>` (seconds) from the plist. */
79
+ export function parseMacosStartIntervalMs(plist) {
80
+ const match = /<key>StartInterval<\/key>\s*<integer>(\d+)<\/integer>/i.exec(plist);
81
+ if (match === null)
82
+ return null;
83
+ const seconds = Number(match[1] ?? 0);
84
+ return seconds > 0 ? seconds * 1000 : null;
85
+ }
86
+ /**
87
+ * The complete set of keys a PD-built LaunchAgent may declare (see
88
+ * buildMacosLaunchAgentPlist). Any additional top-level key — an extra
89
+ * trigger like StartCalendarInterval, environment overrides, or an
90
+ * unexpected action — makes the plist FOREIGN: PD never claims a document
91
+ * that does more than the builder can emit.
92
+ */
93
+ const LAUNCH_AGENT_KEYS = new Set([
94
+ 'Label',
95
+ 'ProgramArguments',
96
+ 'WorkingDirectory',
97
+ 'RunAtLoad',
98
+ 'StartInterval',
99
+ 'StandardOutPath',
100
+ 'StandardErrorPath',
101
+ ]);
102
+ function escapeRegExp(value) {
103
+ return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
104
+ }
105
+ /**
106
+ * Structural LaunchAgent plist reader: parses the real plist document with
107
+ * the project-locked `plist` library, then verifies the result against the
108
+ * builder's key/type contract. A plist fails the parse (ok=false) when it
109
+ * is unparseable, has a non-dict root, declares an unknown top-level key,
110
+ * duplicates any of the required keys anywhere in the raw text (covers
111
+ * comment-forgery — the XML parser drops comments but the raw count
112
+ * still exposes the duplicate), or carries fields of the wrong type. A
113
+ * plist that fails the parse can never equal our registration, so it is
114
+ * FOREIGN.
115
+ */
116
+ function parseLaunchAgent(plistText) {
117
+ let root;
118
+ try {
119
+ root = plistLib.parse(plistText);
120
+ }
121
+ catch {
122
+ return { ok: false };
123
+ }
124
+ if (typeof root !== 'object' || root === null || Array.isArray(root)) {
125
+ return { ok: false };
126
+ }
127
+ const dict = root;
128
+ for (const key of Object.keys(dict)) {
129
+ if (!LAUNCH_AGENT_KEYS.has(key))
130
+ return { ok: false };
131
+ // Duplicate-key guard: the parsed value keeps only one instance, so
132
+ // count raw `<key>NAME</key>` occurrences — a comment- or nesting-forged
133
+ // duplicate still shows up in the raw text.
134
+ const occurrences = plistText.match(new RegExp(`<key>${escapeRegExp(key)}</key>`, 'g'));
135
+ if ((occurrences?.length ?? 0) > 1)
136
+ return { ok: false };
137
+ }
138
+ const label = dict.Label;
139
+ const programArguments = dict.ProgramArguments;
140
+ const workingDirectory = dict.WorkingDirectory;
141
+ return {
142
+ ok: true,
143
+ parsed: {
144
+ label: typeof label === 'string' ? label : null,
145
+ programArguments: Array.isArray(programArguments) && programArguments.every((a) => typeof a === 'string')
146
+ ? (programArguments)
147
+ : null,
148
+ workingDirectory: typeof workingDirectory === 'string' ? workingDirectory : null,
149
+ },
150
+ };
151
+ }
152
+ /** launchctl print stderr/stdout patterns that definitively mean "not loaded". */
153
+ const LAUNCHCTL_NOT_LOADED = /could not find|no such|not loaded|can't find|cannot find|does not exist/i;
154
+ /** launchctl bootout stderr patterns that definitively mean "nothing to unload". */
155
+ const LAUNCHCTL_NOT_LOADED_BOOTOUT = /no such process|not loaded|No process existing with specified identity/i;
156
+ export function createMacosSchedulerAdapter(deps) {
157
+ const { runner, fileIo } = deps;
158
+ const getUid = deps.getUid ?? (() => (typeof process.getuid === 'function' ? process.getuid() : undefined));
159
+ function guiDomain() {
160
+ const uid = getUid();
161
+ if (uid === undefined) {
162
+ return {
163
+ ok: false,
164
+ reason: 'macos_uid_unavailable',
165
+ nextAction: 'The LaunchAgent domain needs the current user uid (process.getuid); it is unavailable in this process context.',
166
+ };
167
+ }
168
+ return { ok: true, domain: `gui/${uid}`, uid };
169
+ }
170
+ function plistPath(registration, homeDir) {
171
+ return path.join(homeDir, 'Library', 'LaunchAgents', `${registration.identity.macosLabel}.plist`);
172
+ }
173
+ /** homeDir derived from the trusted pdHome (…/<home>/.pd → <home>). */
174
+ function homeDirFor(registration) {
175
+ return path.dirname(registration.pdHome);
176
+ }
177
+ function logDirFor(registration) {
178
+ return path.join(registration.pdHome, 'service');
179
+ }
180
+ /**
181
+ * Ownership verdict from the PARSED plist (task §5 review): Label must be
182
+ * exactly our label, ProgramArguments must be exactly [nodePath, ...
183
+ * schedulerInvocationArgs()] and WorkingDirectory exactly our pdHome.
184
+ * Anything that fails to parse, or merely contains our strings inside a
185
+ * different job definition, is foreign — never overwritten or deleted.
186
+ */
187
+ function ownershipVerdict(registration, plist) {
188
+ const result = parseLaunchAgent(plist);
189
+ if (!result.ok)
190
+ return { ours: false };
191
+ const { parsed } = result;
192
+ if (parsed.label !== registration.identity.macosLabel)
193
+ return { ours: false };
194
+ if (parsed.workingDirectory !== registration.pdHome)
195
+ return { ours: false };
196
+ const expected = [registration.nodePath, ...schedulerInvocationArgs(registration)];
197
+ if (parsed.programArguments === null || parsed.programArguments.length !== expected.length) {
198
+ return { ours: false };
199
+ }
200
+ return parsed.programArguments.every((token, index) => token === expected[index])
201
+ ? { ours: true }
202
+ : { ours: false };
203
+ }
204
+ /**
205
+ * Strict launchctl print-disabled reader. Current macOS emits
206
+ * quoted labels followed by => disabled|enabled; older releases emit
207
+ * boolean true|false (with : or =). The command lists only overrides,
208
+ * so an absent target label means not disabled. Malformed structure,
209
+ * duplicate target labels, or unknown values are UNKNOWN.
210
+ */
211
+ function parseDisabledFlag(stdout, label) {
212
+ const lines = stdout.split(/\r?\n/).map((line) => line.trim()).filter((line) => line !== '');
213
+ if (lines.length < 2 || !/^disabled\s+services\s*=\s*\{$/i.test(lines[0] ?? ''))
214
+ return { ok: false };
215
+ let closed = false;
216
+ let targetCount = 0;
217
+ let disabled = false;
218
+ for (const line of lines.slice(1)) {
219
+ if (line === '}') {
220
+ if (closed)
221
+ return { ok: false };
222
+ closed = true;
223
+ continue;
224
+ }
225
+ if (closed)
226
+ return { ok: false };
227
+ const entry = /^"([^"]+)"\s*(?:=>|:|=)\s*(disabled|enabled|true|false|1|0)$/i.exec(line);
228
+ if (entry === null)
229
+ return { ok: false };
230
+ if (entry[1] !== label)
231
+ continue;
232
+ targetCount += 1;
233
+ if (targetCount > 1)
234
+ return { ok: false };
235
+ const value = (entry[2] ?? '').toLowerCase();
236
+ disabled = value === 'disabled' || value === 'true' || value === '1';
237
+ }
238
+ if (!closed)
239
+ return { ok: false };
240
+ return { ok: true, disabled: targetCount === 0 ? false : disabled };
241
+ }
242
+ async function run(command, args) {
243
+ return runner.run(command, args);
244
+ }
245
+ /** Loaded + disabled state from launchctl print / print-disabled. */
246
+ async function loadState(label) {
247
+ const domain = guiDomain();
248
+ if (!domain.ok) {
249
+ return { loaded: false, loadedKnown: false, disabledKnown: false, disabled: null, lastResult: null, unreadableReasons: [domain.reason] };
250
+ }
251
+ const reasons = [];
252
+ const print = await run('launchctl', ['print', `${domain.domain}/${label}`]);
253
+ const loaded = print.code === 0;
254
+ // A failed print is only proof of "not loaded" when launchd says so;
255
+ // any other failure (spawn, permission, timeout) leaves the loaded
256
+ // state UNKNOWN — an unknown state must not drive bootout/delete.
257
+ const notFound = LAUNCHCTL_NOT_LOADED.test(`${print.stderr}\n${print.stdout}`);
258
+ const loadedKnown = loaded || notFound;
259
+ if (!loaded && !notFound) {
260
+ reasons.push(`launchctl_print_failed:${print.code ?? 'spawn'}:${(print.spawnError ?? print.stderr.trim() ?? print.stdout.trim()).slice(0, 100)}`);
261
+ }
262
+ let lastResult = null;
263
+ if (loaded) {
264
+ const match = /last exit code\s*=\s*(\d+)/.exec(print.stdout);
265
+ lastResult = match !== null ? match[1] ?? null : null;
266
+ }
267
+ const disabledList = await run('launchctl', ['print-disabled', domain.domain]);
268
+ let disabled = null;
269
+ if (disabledList.code === 0) {
270
+ const probe = parseDisabledFlag(disabledList.stdout, label);
271
+ const flag = probe.ok ? probe.disabled : null;
272
+ if (flag !== null) {
273
+ disabled = flag;
274
+ }
275
+ else {
276
+ reasons.push('launchctl_print_disabled_unparseable');
277
+ }
278
+ }
279
+ else {
280
+ reasons.push(`launchctl_print_disabled_failed:${disabledList.code ?? 'spawn'}:${(disabledList.spawnError ?? disabledList.stderr).trim().slice(0, 100)}`);
281
+ }
282
+ return { loaded, loadedKnown, disabledKnown: disabled !== null, disabled, lastResult, unreadableReasons: reasons };
283
+ }
284
+ /**
285
+ * launchctl print tri-state: 'loaded' only on exit 0; 'not_loaded' only
286
+ * on launchd's definitive not-found answer; anything else is 'unknown'
287
+ * and must fail closed — never treated as unloaded.
288
+ */
289
+ async function probeLoaded(label) {
290
+ const domain = guiDomain();
291
+ if (!domain.ok)
292
+ return { state: 'unknown', reason: domain.reason };
293
+ const print = await run('launchctl', ['print', `${domain.domain}/${label}`]);
294
+ if (print.code === 0)
295
+ return { state: 'loaded' };
296
+ if (LAUNCHCTL_NOT_LOADED.test(`${print.stderr}\n${print.stdout}`))
297
+ return { state: 'not_loaded' };
298
+ return {
299
+ state: 'unknown',
300
+ reason: `launchctl_print_failed:${print.code ?? 'spawn'}:${(print.spawnError ?? print.stderr.trim() ?? print.stdout.trim()).slice(0, 100)}`,
301
+ };
302
+ }
303
+ /** launchctl print confirms the job is loaded. */
304
+ async function verifyLoaded(label) {
305
+ return (await probeLoaded(label)).state === 'loaded';
306
+ }
307
+ function baseFacts(registration, fields) {
308
+ return {
309
+ platform: 'darwin',
310
+ taskName: registration.identity.macosLabel,
311
+ registered: null,
312
+ enabled: null,
313
+ active: null,
314
+ lastRunAt: null,
315
+ lastResult: null,
316
+ ...fields,
317
+ };
318
+ }
319
+ function commandFailed(reason, nextAction) {
320
+ return { ok: false, kind: 'command_failed', reason, nextAction };
321
+ }
322
+ async function status(registration) {
323
+ const plistFile = plistPath(registration, homeDirFor(registration));
324
+ const existing = fileIo.readIfExists(plistFile);
325
+ if (!existing.ok) {
326
+ if (existing.reason === 'missing') {
327
+ return {
328
+ ok: true,
329
+ changed: false,
330
+ facts: baseFacts(registration, { registered: false, enabled: false, active: false }),
331
+ };
332
+ }
333
+ return {
334
+ ok: false,
335
+ kind: 'command_failed',
336
+ reason: `launchagent_plist_unreadable:${existing.detail ?? existing.reason}`,
337
+ nextAction: `The plist at ${plistFile} exists but cannot be read; fix its permissions. PD does not treat an unreadable registration as "not installed".`,
338
+ };
339
+ }
340
+ // Ownership is a status witness too (task §5): a foreign same-label
341
+ // LaunchAgent is NOT our registration.
342
+ if (!ownershipVerdict(registration, existing.content).ours) {
343
+ return {
344
+ ok: false,
345
+ kind: 'external_conflict',
346
+ reason: 'launchagent_conflict_foreign_plist',
347
+ nextAction: `${plistFile} exists but its Label/ProgramArguments/WorkingDirectory do not match this PD install (${registration.pdHome}); PD does not report a foreign LaunchAgent as its own — inspect it manually.`,
348
+ };
349
+ }
350
+ const state = await loadState(registration.identity.macosLabel);
351
+ // enabled (will fire) = the launchd disabled flag is clear; unreadable
352
+ // flag = null, never folded into loaded/unloaded or guessed (task §9).
353
+ const enabled = state.disabled === null ? null : !state.disabled;
354
+ const active = state.loadedKnown ? state.loaded : null;
355
+ return {
356
+ ok: true,
357
+ changed: false,
358
+ facts: baseFacts(registration, {
359
+ registered: true,
360
+ enabled,
361
+ active,
362
+ triggerIntervalMs: parseMacosStartIntervalMs(existing.content),
363
+ lastResult: state.lastResult,
364
+ ...(state.unreadableReasons.length > 0 ? { degradedReasons: state.unreadableReasons } : {}),
365
+ }),
366
+ };
367
+ }
368
+ /** Create + verify the scheduler log directory (`<pdHome>/service`). */
369
+ function ensureLogDir(registration) {
370
+ const dir = logDirFor(registration);
371
+ const made = fileIo.mkdirs(dir);
372
+ if (!made.ok) {
373
+ return {
374
+ ok: false,
375
+ result: {
376
+ ok: false,
377
+ kind: 'command_failed',
378
+ reason: `launchagent_log_dir_unwritable:${made.reason.slice(0, 80)}`,
379
+ nextAction: `The stdout/stderr log directory ${dir} could not be created; the first triggered run would fail on missing logs. Fix permissions and retry.`,
380
+ },
381
+ };
382
+ }
383
+ return { ok: true };
384
+ }
385
+ return {
386
+ platform: 'darwin',
387
+ async install(registration) {
388
+ const domain = guiDomain();
389
+ if (!domain.ok) {
390
+ return { ok: false, kind: 'unavailable', reason: domain.reason, nextAction: domain.nextAction };
391
+ }
392
+ const homeDir = homeDirFor(registration);
393
+ const plistFile = plistPath(registration, homeDir);
394
+ const agentsDir = path.dirname(plistFile);
395
+ const existing = fileIo.readIfExists(plistFile);
396
+ let refreshOnly = false;
397
+ if (existing.ok) {
398
+ const ownership = ownershipVerdict(registration, existing.content);
399
+ if (!ownership.ours) {
400
+ return {
401
+ ok: false,
402
+ kind: 'external_conflict',
403
+ reason: 'launchagent_conflict_foreign_plist',
404
+ nextAction: `${plistFile} already exists but is not this PD install's LaunchAgent (Label/ProgramArguments/WorkingDirectory mismatch). PD never overwrites a foreign LaunchAgent — inspect it manually.`,
405
+ };
406
+ }
407
+ refreshOnly = true;
408
+ }
409
+ else if (existing.reason === 'unreadable') {
410
+ return {
411
+ ok: false,
412
+ kind: 'command_failed',
413
+ reason: `launchagent_plist_unreadable:${existing.detail ?? existing.reason}`,
414
+ nextAction: `${plistFile} exists but cannot be read; PD refuses to overwrite an unreadable registration — fix its permissions first.`,
415
+ };
416
+ }
417
+ // install never bootstraps and never starts a Worker (task §3): the
418
+ // log directory is created up-front so the first ENABLED trigger can
419
+ // write stdout/stderr (task §6 review).
420
+ const logDir = ensureLogDir(registration);
421
+ if (!logDir.ok)
422
+ return logDir.result;
423
+ // Refresh semantics (task §15): an existing OWN registration keeps its
424
+ // interval — only the node/CLI entry and args move forward.
425
+ const preservedInterval = refreshOnly && registration.intervalExplicit !== true
426
+ ? (existing.ok ? parseMacosStartIntervalMs(existing.content) : null)
427
+ : null;
428
+ const effective = preservedInterval !== null
429
+ ? { ...registration, intervalMs: preservedInterval }
430
+ : registration;
431
+ const label = registration.identity.macosLabel;
432
+ // Read launchd state BEFORE replacing the plist (review §4 matrix):
433
+ // a refresh whose enabled flag is UNREADABLE must refuse before any
434
+ // mutation — a blind swap could leave a still-enabled job firing a
435
+ // stale definition.
436
+ const state = await loadState(label);
437
+ if (refreshOnly && state.disabled === null) {
438
+ return {
439
+ ok: false,
440
+ kind: 'command_failed',
441
+ reason: `launchagent_disabled_state_unverified:${(state.unreadableReasons[0] ?? 'print_disabled_unreadable').slice(0, 100)}`,
442
+ nextAction: `print-disabled could not prove the enabled flag of the existing registration; ${plistFile} was NOT replaced. Fix the launchctl error above and retry pd service install.`,
443
+ };
444
+ }
445
+ const wasEnabled = refreshOnly && state.disabled === false;
446
+ const priorContent = existing.ok ? existing.content : null;
447
+ const mkdir = fileIo.mkdirs(agentsDir);
448
+ if (!mkdir.ok) {
449
+ return { ok: false, kind: 'command_failed', reason: `launchagents_dir_unwritable:${mkdir.reason.slice(0, 80)}`, nextAction: `Could not create ${agentsDir}; check permissions and retry pd service install.` };
450
+ }
451
+ const written = fileIo.writeAtomic(plistFile, buildMacosLaunchAgentPlist(effective));
452
+ if (!written.ok) {
453
+ return { ok: false, kind: 'command_failed', reason: `launchagent_write_failed:${written.reason.slice(0, 80)}`, nextAction: `Could not write ${plistFile}; retry pd service install after fixing the filesystem issue.` };
454
+ }
455
+ /** Roll the plist back: fresh install removes the file it created; a
456
+ * refresh restores the pre-call content. The primary error stays —
457
+ * a rollback failure is appended, never hidden. */
458
+ const rollbackPlist = (reason) => {
459
+ if (priorContent === null) {
460
+ const removed = fileIo.remove(plistFile);
461
+ return removed.ok ? reason : `${reason}+rollback_remove_failed:${removed.reason.slice(0, 60)}`;
462
+ }
463
+ const restored = fileIo.writeAtomic(plistFile, priorContent);
464
+ return restored.ok ? reason : `${reason}+rollback_restore_failed:${restored.reason.slice(0, 60)}`;
465
+ };
466
+ let pinnedDisabled = false;
467
+ if (wasEnabled) {
468
+ // When the loaded state is UNKNOWN a possibly-loaded job must still
469
+ // be reloaded — bootout tolerates a definitive not-loaded answer.
470
+ if (!state.loadedKnown || state.loaded) {
471
+ const bootout = await run('launchctl', ['bootout', `${domain.domain}/${label}`]);
472
+ if (bootout.code !== 0) {
473
+ const stderr = bootout.stderr.trim();
474
+ const notLoaded = bootout.spawnError === undefined && LAUNCHCTL_NOT_LOADED_BOOTOUT.test(stderr);
475
+ if (!notLoaded) {
476
+ return {
477
+ ok: false,
478
+ kind: 'command_failed',
479
+ reason: rollbackPlist(`launchctl_bootout_failed:${bootout.code ?? 'spawn'}:${(bootout.spawnError ?? stderr).slice(0, 120)}`),
480
+ nextAction: 'The refreshed plist could not replace the loaded job (bootout failed); the previous plist was restored and its definition stays active. Inspect the stderr above and retry.',
481
+ };
482
+ }
483
+ }
484
+ }
485
+ // Reload the definition while the enabled flag stays enabled: also
486
+ // covers enabled+unloaded — a confirmed-unloaded job is bootstrapped
487
+ // straight back (bootout is skipped, nothing to unload).
488
+ const bootstrap = await run('launchctl', ['bootstrap', domain.domain, plistFile]);
489
+ if (bootstrap.code !== 0 || !(await verifyLoaded(label))) {
490
+ return {
491
+ ok: false,
492
+ kind: 'command_failed',
493
+ reason: rollbackPlist(bootstrap.code === 0 ? 'launchagent_reload_unverified' : `launchctl_bootstrap_failed:${bootstrap.code ?? 'spawn'}:${(bootstrap.spawnError ?? bootstrap.stderr).trim().slice(0, 120)}`),
494
+ nextAction: 'The refreshed plist could not be reloaded; the previous plist was restored but the job may now be unloaded — run pd service status, then retry (a retry re-bootstraps safely).',
495
+ };
496
+ }
497
+ }
498
+ else if (state.disabled !== true) {
499
+ // installed_disabled (task §3): a never-disabled LaunchAgent
500
+ // auto-loads at the next login and RunAtLoad would fire it — so
501
+ // install explicitly pins the persistent disabled flag.
502
+ const disable = await run('launchctl', ['disable', `${domain.domain}/${label}`]);
503
+ if (disable.code !== 0) {
504
+ return {
505
+ ok: false,
506
+ kind: 'command_failed',
507
+ reason: rollbackPlist(`launchctl_disable_failed:${disable.code ?? 'spawn'}:${(disable.spawnError ?? disable.stderr).trim().slice(0, 120)}`),
508
+ nextAction: `The plist was written but the persistent disable could not be verified — the install was rolled back, leaving the label enabled would fire it at the next login (RunAtLoad). Inspect the stderr above and re-run pd service install.`,
509
+ };
510
+ }
511
+ pinnedDisabled = true;
512
+ }
513
+ if (!refreshOnly) {
514
+ // First install is transactional: the disabled pin must be PROVABLE.
515
+ // On any doubt, remove the plist this call created and restore the
516
+ // disable override to its pre-install value (pinned -> enable).
517
+ const verify = await loadState(label);
518
+ if (verify.disabled !== true) {
519
+ let reason = rollbackPlist(`launchagent_disable_unverified:${(verify.unreadableReasons[0] ?? 'flag_not_set').slice(0, 80)}`);
520
+ if (pinnedDisabled) {
521
+ const enable = await run('launchctl', ['enable', `${domain.domain}/${label}`]);
522
+ if (enable.code !== 0) {
523
+ reason += `+rollback_enable_failed:${(enable.spawnError ?? enable.stderr).trim().slice(0, 60)}`;
524
+ }
525
+ }
526
+ return {
527
+ ok: false,
528
+ kind: 'command_failed',
529
+ reason,
530
+ nextAction: 'The plist was written but the persistent disable could not be proven; the install was rolled back — the new plist was removed and the disable override restored. Inspect launchctl print-disabled and retry pd service install.',
531
+ };
532
+ }
533
+ }
534
+ const after = await loadState(label);
535
+ return {
536
+ ok: true,
537
+ changed: !refreshOnly,
538
+ facts: baseFacts(registration, {
539
+ registered: true,
540
+ enabled: after.disabled === null ? null : !after.disabled,
541
+ active: after.loaded,
542
+ triggerIntervalMs: effective.intervalMs,
543
+ lastResult: after.lastResult,
544
+ ...(after.unreadableReasons.length > 0 ? { degradedReasons: after.unreadableReasons } : {}),
545
+ }),
546
+ };
547
+ },
548
+ async enable(registration) {
549
+ const domain = guiDomain();
550
+ if (!domain.ok) {
551
+ return { ok: false, kind: 'unavailable', reason: domain.reason, nextAction: domain.nextAction };
552
+ }
553
+ const plistFile = plistPath(registration, homeDirFor(registration));
554
+ const existing = fileIo.readIfExists(plistFile);
555
+ if (!existing.ok) {
556
+ if (existing.reason === 'missing') {
557
+ return {
558
+ ok: false,
559
+ kind: 'unsafe_state',
560
+ reason: 'scheduler_not_registered',
561
+ nextAction: `No LaunchAgent plist at ${plistFile}. Run pd service install first — enable never creates one.`,
562
+ };
563
+ }
564
+ return commandFailed(`launchagent_plist_unreadable:${existing.detail ?? existing.reason}`, `${plistFile} exists but cannot be read; PD refuses to enable an unverifiable registration — fix its permissions first.`);
565
+ }
566
+ if (!ownershipVerdict(registration, existing.content).ours) {
567
+ return {
568
+ ok: false,
569
+ kind: 'external_conflict',
570
+ reason: 'launchagent_conflict_foreign_plist',
571
+ nextAction: `${plistFile} is not PD's own LaunchAgent; PD refuses to modify it.`,
572
+ };
573
+ }
574
+ // The log dir must exist before bootstrap so the first fired run can
575
+ // write its stdout/stderr (task §6 review).
576
+ const logDir = ensureLogDir(registration);
577
+ if (!logDir.ok)
578
+ return logDir.result;
579
+ const label = registration.identity.macosLabel;
580
+ const state = await loadState(label);
581
+ if (state.loaded && state.disabled === false) {
582
+ return {
583
+ ok: true,
584
+ changed: false,
585
+ facts: baseFacts(registration, { registered: true, enabled: true, active: true, lastResult: state.lastResult }),
586
+ };
587
+ }
588
+ // enable BEFORE bootstrap (task §3): the flag must be clear so the
589
+ // bootstrapped job is actually armed.
590
+ if (state.disabled !== false) {
591
+ const enable = await run('launchctl', ['enable', `${domain.domain}/${label}`]);
592
+ if (enable.code !== 0) {
593
+ return {
594
+ ok: false,
595
+ kind: 'command_failed',
596
+ reason: `launchctl_enable_failed:${enable.code ?? 'spawn'}:${(enable.spawnError ?? enable.stderr).trim().slice(0, 120)}`,
597
+ nextAction: 'launchctl enable failed; the registration exists but stays disabled. Inspect the stderr above and retry.',
598
+ };
599
+ }
600
+ }
601
+ if (!state.loaded) {
602
+ const bootstrap = await run('launchctl', ['bootstrap', domain.domain, plistFile]);
603
+ if (bootstrap.code !== 0) {
604
+ return {
605
+ ok: false,
606
+ kind: 'command_failed',
607
+ reason: `launchctl_bootstrap_failed:${bootstrap.code ?? 'spawn'}:${(bootstrap.spawnError ?? bootstrap.stderr).trim().slice(0, 120)}`,
608
+ nextAction: 'bootstrap after enable failed; inspect the stderr above and retry pd service enable.',
609
+ };
610
+ }
611
+ }
612
+ // Verify before reporting success (task §3): a confirmed-loaded job
613
+ // AND a proven-clear disabled flag are both required — either
614
+ // UNKNOWN means the enable is unverified, never a success.
615
+ const postEnable = await loadState(label);
616
+ if (!postEnable.loaded || postEnable.disabled !== false) {
617
+ return {
618
+ ok: false,
619
+ kind: 'command_failed',
620
+ reason: postEnable.loaded
621
+ ? 'launchagent_enable_flag_unverified'
622
+ : 'launchagent_enable_unverified',
623
+ nextAction: 'launchctl enable/bootstrap returned success but the job is not provably loaded+enabled in the gui domain. Run pd service status to inspect and retry.',
624
+ };
625
+ }
626
+ return {
627
+ ok: true,
628
+ changed: true,
629
+ facts: baseFacts(registration, { registered: true, enabled: true, active: true }),
630
+ };
631
+ },
632
+ async disable(registration) {
633
+ const domain = guiDomain();
634
+ if (!domain.ok) {
635
+ return { ok: false, kind: 'unavailable', reason: domain.reason, nextAction: domain.nextAction };
636
+ }
637
+ const label = registration.identity.macosLabel;
638
+ const plistFile = plistPath(registration, homeDirFor(registration));
639
+ const existing = fileIo.readIfExists(plistFile);
640
+ if (!existing.ok) {
641
+ if (existing.reason === 'missing') {
642
+ return {
643
+ ok: false,
644
+ kind: 'unsafe_state',
645
+ reason: 'scheduler_not_registered',
646
+ nextAction: `No LaunchAgent plist at ${plistFile}; nothing to disable.`,
647
+ };
648
+ }
649
+ return commandFailed(`launchagent_plist_unreadable:${existing.detail ?? existing.reason}`, `${plistFile} exists but cannot be read; PD refuses to touch an unverifiable registration — fix its permissions first.`);
650
+ }
651
+ if (!ownershipVerdict(registration, existing.content).ours) {
652
+ return {
653
+ ok: false,
654
+ kind: 'external_conflict',
655
+ reason: 'launchagent_conflict_foreign_plist',
656
+ nextAction: `${plistFile} is not PD's own LaunchAgent; PD refuses to modify it.`,
657
+ };
658
+ }
659
+ const state = await loadState(label);
660
+ if (state.disabled === true && state.loadedKnown && !state.loaded) {
661
+ return {
662
+ ok: true,
663
+ changed: false,
664
+ facts: baseFacts(registration, { registered: true, enabled: false, active: false, lastResult: state.lastResult }),
665
+ };
666
+ }
667
+ // Persistent disable first (survives logout/login), then bootout the
668
+ // currently-loaded job (task §3).
669
+ if (state.disabled !== true) {
670
+ const disable = await run('launchctl', ['disable', `${domain.domain}/${label}`]);
671
+ if (disable.code !== 0) {
672
+ return {
673
+ ok: false,
674
+ kind: 'command_failed',
675
+ reason: `launchctl_disable_failed:${disable.code ?? 'spawn'}:${(disable.spawnError ?? disable.stderr).trim().slice(0, 120)}`,
676
+ nextAction: 'launchctl disable failed; future automatic triggers may still fire. Inspect the stderr above and retry.',
677
+ };
678
+ }
679
+ }
680
+ // A possibly-loaded job (loaded state UNKNOWN) is bootout-ed too —
681
+ // the command tolerates a definitive not-loaded answer, and a stale
682
+ // loaded job must not keep firing under the disabled flag.
683
+ if (state.loaded || !state.loadedKnown) {
684
+ const bootout = await run('launchctl', ['bootout', `${domain.domain}/${label}`]);
685
+ if (bootout.code !== 0) {
686
+ const stderr = bootout.stderr.trim();
687
+ if (bootout.spawnError !== undefined || !LAUNCHCTL_NOT_LOADED_BOOTOUT.test(stderr)) {
688
+ return {
689
+ ok: false,
690
+ kind: 'command_failed',
691
+ reason: `launchctl_bootout_failed:${bootout.code ?? 'spawn'}:${stderr.slice(0, 120)}`,
692
+ nextAction: 'bootout failed; the agent may still be loaded. Inspect the stderr above and retry.',
693
+ };
694
+ }
695
+ }
696
+ }
697
+ // Prove it is unloaded before reporting stopped (task §3): UNKNOWN
698
+ // is a distinct, never-successful verdict.
699
+ const probe = await probeLoaded(label);
700
+ if (probe.state !== 'not_loaded') {
701
+ return {
702
+ ok: false,
703
+ kind: 'command_failed',
704
+ reason: probe.state === 'unknown' ? `launchagent_disable_unverified:${(probe.reason ?? 'print_failed').slice(0, 80)}` : 'launchagent_disable_unverified',
705
+ nextAction: 'launchctl disable/bootout returned success but the job still reports loaded — or the loaded state could not be proven. Run pd service status to inspect and retry.',
706
+ };
707
+ }
708
+ const after = await loadState(label);
709
+ return {
710
+ ok: true,
711
+ changed: true,
712
+ facts: baseFacts(registration, {
713
+ registered: true,
714
+ enabled: after.disabled === null ? null : !after.disabled,
715
+ active: after.loaded,
716
+ lastResult: after.lastResult,
717
+ ...(after.unreadableReasons.length > 0 ? { degradedReasons: after.unreadableReasons } : {}),
718
+ }),
719
+ };
720
+ },
721
+ status,
722
+ async uninstall(registration) {
723
+ const domain = guiDomain();
724
+ if (!domain.ok) {
725
+ return { ok: false, kind: 'unavailable', reason: domain.reason, nextAction: domain.nextAction };
726
+ }
727
+ const label = registration.identity.macosLabel;
728
+ const plistFile = plistPath(registration, homeDirFor(registration));
729
+ const existing = fileIo.readIfExists(plistFile);
730
+ if (!existing.ok) {
731
+ if (existing.reason === 'missing') {
732
+ return {
733
+ ok: true,
734
+ changed: false,
735
+ facts: baseFacts(registration, { registered: false, enabled: false, active: false }),
736
+ };
737
+ }
738
+ return {
739
+ ok: false,
740
+ kind: 'command_failed',
741
+ reason: `launchagent_plist_unreadable:${existing.detail ?? existing.reason}`,
742
+ nextAction: `${plistFile} exists but cannot be read; PD never removes an unverifiable registration — fix its permissions first.`,
743
+ };
744
+ }
745
+ if (!ownershipVerdict(registration, existing.content).ours) {
746
+ return {
747
+ ok: false,
748
+ kind: 'external_conflict',
749
+ reason: 'launchagent_conflict_foreign_plist',
750
+ nextAction: `${plistFile} is not PD's own LaunchAgent; PD never deletes foreign LaunchAgents. Inspect it manually.`,
751
+ };
752
+ }
753
+ // Stop + unload OUR job first, verify it is gone, then remove ONLY our
754
+ // plist (task §3).
755
+ const state = await loadState(label);
756
+ // An UNREADABLE loaded state is not proof the job is unloaded —
757
+ // deleting the plist while a stale-loaded job still points at it
758
+ // would leave an untracked registration. Fail closed instead (the
759
+ // plist is NOT removed; re-run once launchctl answers).
760
+ if (!state.loadedKnown) {
761
+ return {
762
+ ok: false,
763
+ kind: 'command_failed',
764
+ reason: `launchagent_loaded_state_unverified:${(state.unreadableReasons[0] ?? 'launchctl_print_failed').slice(0, 120)}`,
765
+ nextAction: '`launchctl print` could not prove whether the job is loaded; the plist was NOT removed. Inspect the error above and re-run pd service uninstall.',
766
+ };
767
+ }
768
+ if (state.disabled !== true) {
769
+ const disable = await run('launchctl', ['disable', `${domain.domain}/${label}`]);
770
+ if (disable.code !== 0) {
771
+ return {
772
+ ok: false,
773
+ kind: 'command_failed',
774
+ reason: `launchctl_disable_failed:${disable.code ?? 'spawn'}:${(disable.spawnError ?? disable.stderr).trim().slice(0, 120)}`,
775
+ nextAction: 'launchctl disable failed; the job could re-load at the next login — the plist was NOT removed. Inspect the stderr above, then re-run pd service uninstall.',
776
+ };
777
+ }
778
+ }
779
+ if (state.loaded) {
780
+ const bootout = await run('launchctl', ['bootout', `${domain.domain}/${label}`]);
781
+ if (bootout.code !== 0) {
782
+ const stderr = bootout.stderr.trim();
783
+ if (bootout.spawnError !== undefined || !LAUNCHCTL_NOT_LOADED_BOOTOUT.test(stderr)) {
784
+ return {
785
+ ok: false,
786
+ kind: 'command_failed',
787
+ reason: `launchctl_bootout_failed:${bootout.code ?? 'spawn'}:${stderr.slice(0, 120)}`,
788
+ nextAction: 'bootout failed; the agent may still be loaded and its plist was NOT removed. Inspect the stderr above, then re-run pd service uninstall.',
789
+ };
790
+ }
791
+ }
792
+ const probe = await probeLoaded(label);
793
+ if (probe.state !== 'not_loaded') {
794
+ return {
795
+ ok: false,
796
+ kind: 'command_failed',
797
+ reason: probe.state === 'unknown' ? `launchagent_unload_unverified:${(probe.reason ?? 'print_failed').slice(0, 80)}` : 'launchagent_unload_unverified',
798
+ nextAction: 'The job still reports loaded after bootout — or the unload could not be proven; the plist was NOT removed. Inspect with pd service status and retry.',
799
+ };
800
+ }
801
+ }
802
+ const removed = fileIo.remove(plistFile);
803
+ if (!removed.ok) {
804
+ return {
805
+ ok: false,
806
+ kind: 'command_failed',
807
+ reason: `launchagent_remove_failed:${removed.reason.slice(0, 80)}`,
808
+ nextAction: `The agent was unloaded but ${plistFile} could not be removed; delete it manually after reviewing why.`,
809
+ };
810
+ }
811
+ return {
812
+ ok: true,
813
+ changed: true,
814
+ facts: baseFacts(registration, { registered: false, enabled: false, active: false }),
815
+ };
816
+ },
817
+ };
818
+ }
819
+ //# sourceMappingURL=macos.js.map