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,688 @@
1
+ /**
2
+ * Windows scheduler adapter — current-user Task Scheduler task via the
3
+ * ScheduledTasks PowerShell module (SPEC-PD-SERVICE-HOST-001 §10.1, task §3.2).
4
+ *
5
+ * Protocol: every operation is ONE `powershell.exe -Command` script that
6
+ * - forces UTF-8 console output (ConvertTo-Json must not mojibake);
7
+ * - reports either a structured JSON body or `{ok:false, errorId, message}`
8
+ * from a single catch — the FullyQualifiedErrorId is a stable English
9
+ * identifier, so permission denial (AccessDenied) is NEVER confused with
10
+ * "task not found" (ScheduledTaskNotFound); localized stderr prose is
11
+ * never parsed;
12
+ * - receives file paths through environment variables — nothing is
13
+ * interpolated into the script except task names, which this package
14
+ * generates from [A-Za-z0-9-] only.
15
+ *
16
+ * Security shape (task §3.2): LogonTrigger + repeating TimeTrigger,
17
+ * InteractiveToken principal ("run only when user is logged on"), RunLevel
18
+ * LeastPrivilege (no elevation), absolute node/entry paths, no credentials,
19
+ * MultipleInstancesPolicy=IgnoreNew (OS-level overlap convergence that
20
+ * complements the install-level run lock).
21
+ */
22
+ import * as path from 'node:path';
23
+ import { schedulerInvocationArgs } from './contract.js';
24
+ const POWERSHELL_ARGS_PREFIX = ['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-Command'];
25
+ /** ISO-8601 duration for the Task XML repetition interval. */
26
+ export function windowsRepetitionDuration(intervalMs) {
27
+ if (intervalMs % 60_000 === 0)
28
+ return `PT${Math.round(intervalMs / 60_000)}M`;
29
+ return `PT${Math.round(intervalMs / 1000)}S`;
30
+ }
31
+ function escapeXml(value) {
32
+ return value.replace(/[&<>"']/g, (c) => {
33
+ switch (c) {
34
+ case '&': return '&amp;';
35
+ case '<': return '&lt;';
36
+ case '>': return '&gt;';
37
+ case '"': return '&quot;';
38
+ default: return '&apos;';
39
+ }
40
+ });
41
+ }
42
+ /** Max one run-once coordinator may legitimately take (own bounds are tighter). */
43
+ const EXECUTION_TIME_LIMIT = 'PT8H';
44
+ /**
45
+ * Serialize ONE argument the way CommandLineToArgvW parses it back
46
+ * (task §3.2 review): an argument containing whitespace, a quote, or the
47
+ * empty string is wrapped in double quotes; a run of `n` backslashes
48
+ * immediately before a quote or the closing quote is doubled, and an
49
+ * embedded `"` is emitted as `\"`. Exported for the round-trip tests —
50
+ * quoting only the CLI path while joining the rest raw let a spaced
51
+ * `--pd-home` root split into extra argv entries on the OS side.
52
+ */
53
+ export function windowsSerializeArg(arg) {
54
+ if (arg.length > 0 && !/[\s"]/.test(arg))
55
+ return arg;
56
+ let out = '"';
57
+ let backslashes = 0;
58
+ for (const ch of arg) {
59
+ if (ch === '\\') {
60
+ backslashes += 1;
61
+ continue;
62
+ }
63
+ if (ch === '"') {
64
+ out += '\\'.repeat(backslashes * 2 + 1) + '"';
65
+ }
66
+ else {
67
+ out += '\\'.repeat(backslashes) + ch;
68
+ }
69
+ backslashes = 0;
70
+ }
71
+ out += '\\'.repeat(backslashes * 2) + '"';
72
+ return out;
73
+ }
74
+ /** Serialize a full argv to the single command-line string the task's Exec uses. */
75
+ export function windowsSerializeCommandLine(argv) {
76
+ return argv.map(windowsSerializeArg).join(' ');
77
+ }
78
+ /**
79
+ * CommandLineToArgvW-faithful command-line parser (the same algorithm the
80
+ * Windows process startup applies): `2n` backslashes + quote = `n` literal
81
+ * backslashes + delimiter; `2n+1` + quote = `n` backslashes + a literal
82
+ * quote; unquoted whitespace splits. Ownership verification and the
83
+ * serialization tests both go through this — never a string-contains
84
+ * shortcut (task §3.2/§5).
85
+ */
86
+ export function windowsParseCommandLine(commandLine) {
87
+ const args = [];
88
+ let current = '';
89
+ let tokenStarted = false;
90
+ let inQuotes = false;
91
+ let i = 0;
92
+ while (i < commandLine.length) {
93
+ const ch = commandLine[i];
94
+ if (ch === ' ' || ch === '\t') {
95
+ if (inQuotes) {
96
+ current += ch;
97
+ }
98
+ else if (tokenStarted) {
99
+ args.push(current);
100
+ current = '';
101
+ tokenStarted = false;
102
+ }
103
+ i += 1;
104
+ continue;
105
+ }
106
+ if (ch === '\\') {
107
+ let backslashes = 0;
108
+ while (commandLine[i] === '\\') {
109
+ backslashes += 1;
110
+ i += 1;
111
+ }
112
+ if (commandLine[i] === '"') {
113
+ if (backslashes % 2 === 0) {
114
+ current += '\\'.repeat(backslashes / 2);
115
+ inQuotes = !inQuotes;
116
+ tokenStarted = true;
117
+ }
118
+ else {
119
+ current += '\\'.repeat((backslashes - 1) / 2) + '"';
120
+ tokenStarted = true;
121
+ }
122
+ i += 1;
123
+ }
124
+ else {
125
+ current += '\\'.repeat(backslashes);
126
+ tokenStarted = true;
127
+ }
128
+ continue;
129
+ }
130
+ if (ch === '"') {
131
+ // A `""` inside a quoted run is an escaped quote for MSVC argv rules;
132
+ // outside it toggles quoting. Two adjacent quotes mid-token collapse.
133
+ if (inQuotes && commandLine[i + 1] === '"') {
134
+ current += '"';
135
+ i += 2;
136
+ continue;
137
+ }
138
+ inQuotes = !inQuotes;
139
+ tokenStarted = true;
140
+ i += 1;
141
+ continue;
142
+ }
143
+ current += ch;
144
+ tokenStarted = true;
145
+ i += 1;
146
+ }
147
+ if (tokenStarted)
148
+ args.push(current);
149
+ return args;
150
+ }
151
+ /**
152
+ * Task Scheduler StartBoundary with an EXPLICIT timezone (task §8 review):
153
+ * `YYYY-MM-DDTHH:MM:SS±HH:MM`. UTC input keeps a real offset marker —
154
+ * stripping `Z` used to pass a UTC instant off as local time and shifted
155
+ * the first trigger by the host's UTC offset.
156
+ */
157
+ export function formatWindowsStartBoundary(epochMs, offsetMinutesEast) {
158
+ const local = new Date(epochMs + offsetMinutesEast * 60_000);
159
+ const pad = (n) => String(n).padStart(2, '0');
160
+ const sign = offsetMinutesEast >= 0 ? '+' : '-';
161
+ const abs = Math.abs(offsetMinutesEast);
162
+ return (`${local.getUTCFullYear()}-${pad(local.getUTCMonth() + 1)}-${pad(local.getUTCDate())}` +
163
+ `T${pad(local.getUTCHours())}:${pad(local.getUTCMinutes())}:${pad(local.getUTCSeconds())}` +
164
+ `${sign}${pad(Math.floor(abs / 60))}:${pad(abs % 60)}`);
165
+ }
166
+ /** The Arguments element: EVERY argument is serialized independently per the Win32 argv rules. */
167
+ function schedulerArgumentsString(registration) {
168
+ return windowsSerializeCommandLine(schedulerInvocationArgs(registration));
169
+ }
170
+ export function buildWindowsTaskXml(registration, now = new Date(), enabled = false) {
171
+ const { nodePath, pdHome, intervalMs } = registration;
172
+ const startBoundary = formatWindowsStartBoundary(now.getTime(), -now.getTimezoneOffset());
173
+ const args = schedulerArgumentsString(registration);
174
+ return [
175
+ // No encoding declaration: Task Scheduler's MSXML rejects a UTF-8
176
+ // declaration on a string-sourced document with "cannot switch
177
+ // encoding" (HRESULT 0x8004131a, verified on a real zh-CN host).
178
+ '<?xml version="1.0"?>',
179
+ '<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">',
180
+ ' <RegistrationInfo>',
181
+ ` <Description>PD Service Host managed run-once trigger for pdHome ${escapeXml(pdHome)}. Installed by pd service install; remove with pd service uninstall.</Description>`,
182
+ ' </RegistrationInfo>',
183
+ ' <Triggers>',
184
+ ' <LogonTrigger>',
185
+ ' <Enabled>true</Enabled>',
186
+ ' <UserId>__PD_TASK_USER__</UserId>',
187
+ ' </LogonTrigger>',
188
+ ' <TimeTrigger>',
189
+ ` <StartBoundary>${startBoundary}</StartBoundary>`,
190
+ ' <Enabled>true</Enabled>',
191
+ ' <Repetition>',
192
+ ` <Interval>${windowsRepetitionDuration(intervalMs)}</Interval>`,
193
+ ' <StopAtDurationEnd>false</StopAtDurationEnd>',
194
+ ' </Repetition>',
195
+ ' </TimeTrigger>',
196
+ ' </Triggers>',
197
+ ' <Settings>',
198
+ ' <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>',
199
+ ' <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>',
200
+ ' <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>',
201
+ ' <AllowHardTerminate>true</AllowHardTerminate>',
202
+ ' <StartWhenAvailable>true</StartWhenAvailable>',
203
+ ' <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>',
204
+ ' <AllowStartOnDemand>true</AllowStartOnDemand>',
205
+ // installed_disabled: a FRESH registration never fires until
206
+ // `pd service enable` flips it (task §5). On refresh the caller passes
207
+ // the preserved OS enabled state (task §15).
208
+ ` <Enabled>${enabled ? 'true' : 'false'}</Enabled>`,
209
+ ' <Hidden>false</Hidden>',
210
+ ' <RunOnlyIfIdle>false</RunOnlyIfIdle>',
211
+ ' <WakeToRun>false</WakeToRun>',
212
+ ` <ExecutionTimeLimit>${EXECUTION_TIME_LIMIT}</ExecutionTimeLimit>`,
213
+ ' <Priority>7</Priority>',
214
+ ' </Settings>',
215
+ ' <Actions Context="Author">',
216
+ ' <Exec>',
217
+ ` <Command>${escapeXml(nodePath)}</Command>`,
218
+ ` <Arguments>${escapeXml(args)}</Arguments>`,
219
+ ` <WorkingDirectory>${escapeXml(pdHome)}</WorkingDirectory>`,
220
+ ' </Exec>',
221
+ ' </Actions>',
222
+ '</Task>',
223
+ '',
224
+ ].join('\r\n');
225
+ }
226
+ /** XML-unescape a scalar element's text content. */
227
+ function unescapeXml(value) {
228
+ return value
229
+ .replace(/&lt;/g, '<')
230
+ .replace(/&gt;/g, '>')
231
+ .replace(/&quot;/g, '"')
232
+ .replace(/&apos;/g, "'")
233
+ .replace(/&amp;/g, '&');
234
+ }
235
+ /** First `<tag>text</tag>` inside a scope fragment, or null. */
236
+ function xmlElement(scope, tag) {
237
+ const match = new RegExp(`<${tag}>([\\s\\S]*?)</${tag}>`, 'i').exec(scope);
238
+ return match === null ? null : unescapeXml(match[1] ?? '');
239
+ }
240
+ /**
241
+ * Actions completeness (task review §4): parse the WHOLE `<Actions>`
242
+ * block. Our task declares exactly ONE `<Exec>` action — a matching first
243
+ * Exec plus extra `<Exec>`s or any non-Exec action (ComHandler,
244
+ * ShowMessage, SendEmail) is a FOREIGN task. Every action tag anywhere
245
+ * inside Actions counts; forged content in comments still trips the
246
+ * count (conservative refusal).
247
+ */
248
+ function taskActionsExec(xml) {
249
+ const actionsMatch = /<Actions\b[^>]*>([\s\S]*?)<\/Actions>/i.exec(xml);
250
+ if (actionsMatch === null)
251
+ return { ok: false, detail: 'no_actions_block' };
252
+ const scope = actionsMatch[1] ?? '';
253
+ const actionTags = [...scope.matchAll(/<(Exec|ComHandler|ShowMessage|SendEmail)\b/gi)].map((m) => m[1] ?? '');
254
+ const execBlocks = [...scope.matchAll(/<Exec\b[^>]*>([\s\S]*?)<\/Exec>/gi)].map((m) => m[1] ?? '');
255
+ if (execBlocks.length !== 1 || actionTags.length !== 1 || actionTags[0]?.toLowerCase() !== 'exec') {
256
+ return { ok: false, detail: `unexpected_actions:${actionTags.join('+') || 'none'}` };
257
+ }
258
+ return { ok: true, exec: execBlocks[0] ?? '' };
259
+ }
260
+ /**
261
+ * `<UserId>` values inside `<LogonTrigger>` blocks only. PD declares the
262
+ * interactive principal in the LogonTrigger; a REAL Task Scheduler
263
+ * export ALSO carries a `<Principal><UserId>` (SID form) outside the
264
+ * trigger, so counting every UserId in the document wrongly rejects our
265
+ * own tasks (real-CI evidence: principal_mismatch count=2). Foreign
266
+ * ambiguity = zero or several UserIds *inside* the trigger.
267
+ */
268
+ function taskPrincipalUsers(xml) {
269
+ const users = [];
270
+ for (const trigger of xml.matchAll(/<LogonTrigger\b[^>]*>([\s\S]*?)<\/LogonTrigger>/gi)) {
271
+ for (const user of (trigger[1] ?? '').matchAll(/<UserId>([\s\S]*?)<\/UserId>/gi)) {
272
+ users.push(unescapeXml(user[1] ?? '').trim());
273
+ }
274
+ }
275
+ return users;
276
+ }
277
+ /**
278
+ * `<UserId>` values inside `<Principal>` blocks — the task's RUN-AS
279
+ * account (exported in SID form). PD registers with
280
+ * TASK_LOGON_INTERACTIVE_TOKEN for the registering user, so our own task
281
+ * declares exactly ONE Principal whose UserId is that user's SID. An
282
+ * admin may retarget a same-named task to another account while leaving
283
+ * the Exec/WorkingDirectory/LogonTrigger intact (real-review evidence):
284
+ * such a task is FOREIGN and must never be modified or deleted. Zero or
285
+ * several Principal UserIds is likewise a definition PD did not write.
286
+ */
287
+ function taskRunAsUsers(xml) {
288
+ const users = [];
289
+ for (const principal of xml.matchAll(/<Principal\b[^>]*>([\s\S]*?)<\/Principal>/gi)) {
290
+ for (const user of (principal[1] ?? '').matchAll(/<UserId>([\s\S]*?)<\/UserId>/gi)) {
291
+ users.push(unescapeXml(user[1] ?? '').trim());
292
+ }
293
+ }
294
+ return users;
295
+ }
296
+ /** Runtime guard for the error envelope (untrusted parsed JSON, rc-1/rc-3). */
297
+ function isPowerShellError(body) {
298
+ if (typeof body !== 'object' || body === null)
299
+ return false;
300
+ // `=== false` is own-property safe: an inherited `ok` reads undefined.
301
+ return body.ok === false;
302
+ }
303
+ function isPowerShellQueryBody(value) {
304
+ if (typeof value !== 'object' || value === null || !Object.hasOwn(value, 'found'))
305
+ return false;
306
+ return typeof value.found === 'boolean';
307
+ }
308
+ function isPowerShellErrorBodyValue(value) {
309
+ if (typeof value !== 'object' || value === null)
310
+ return false;
311
+ return value.ok === false && typeof value.errorId === 'string';
312
+ }
313
+ function isPowerShellMutationAck(value) {
314
+ if (typeof value !== 'object' || value === null || !Object.hasOwn(value, 'done'))
315
+ return false;
316
+ return typeof value.done === 'boolean';
317
+ }
318
+ function parsePowerShellJson(stdout) {
319
+ const cleaned = stdout.replace(/^\uFEFF/, '').trim();
320
+ if (cleaned === '')
321
+ return { ok: false, reason: 'powershell_empty_output' };
322
+ try {
323
+ const parsed = JSON.parse(cleaned);
324
+ if (isPowerShellQueryBody(parsed) || isPowerShellErrorBodyValue(parsed) || isPowerShellMutationAck(parsed)) {
325
+ return { ok: true, body: parsed };
326
+ }
327
+ return { ok: false, reason: 'powershell_unexpected_output_shape' };
328
+ }
329
+ catch (error) {
330
+ return { ok: false, reason: `powershell_unparsable_output:${error instanceof Error ? error.message.slice(0, 80) : 'unknown'}` };
331
+ }
332
+ }
333
+ /** PowerShell's "never run" sentinel timestamp — report null instead. */
334
+ const NEVER_RUN_YEAR_PREFIX = '1899';
335
+ /** Parse `<Interval>PT2M</Interval>` / `PT30S` from the exported task XML. */
336
+ export function parseWindowsIntervalMs(xml) {
337
+ const match = /<Interval>PT(?:(\d+)M)?(?:(\d+(?:\.\d+)?)S)?<\/Interval>/i.exec(xml);
338
+ if (match === null)
339
+ return null;
340
+ const minutes = match[1] !== undefined ? Number(match[1]) : 0;
341
+ const seconds = match[2] !== undefined ? Number(match[2]) : 0;
342
+ const ms = Math.round((minutes * 60 + seconds) * 1000);
343
+ return ms > 0 ? ms : null;
344
+ }
345
+ function factsFromQuery(identity, body) {
346
+ if (!body.found) {
347
+ return { platform: 'win32', taskName: identity.windowsTaskName, registered: false, enabled: false, triggerIntervalMs: null, lastRunAt: null, lastResult: null };
348
+ }
349
+ const state = typeof body.state === 'string' ? body.state : '';
350
+ // 267011 (0x41303) = SCHED_S_TASK_HAS_NOT_RUN — the never-run signal that
351
+ // survives locale-dependent timestamp sentinels (real hosts observed with
352
+ // both 1899- and 1999-dated sentinels).
353
+ const neverRan = String(body.lastResult ?? '') === '267011';
354
+ const lastRunAt = !neverRan && typeof body.lastRunAt === 'string' && !body.lastRunAt.startsWith(NEVER_RUN_YEAR_PREFIX)
355
+ ? body.lastRunAt
356
+ : null;
357
+ return {
358
+ platform: 'win32',
359
+ taskName: identity.windowsTaskName,
360
+ registered: true,
361
+ enabled: state === '' ? null : state !== 'Disabled',
362
+ active: state === '' ? null : state === 'Running',
363
+ triggerIntervalMs: typeof body.xml === 'string' ? parseWindowsIntervalMs(body.xml) : null,
364
+ lastRunAt,
365
+ lastResult: body.lastResult === undefined ? null : String(body.lastResult),
366
+ };
367
+ }
368
+ function queryScript(taskName) {
369
+ return `
370
+ [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
371
+ $ErrorActionPreference = 'Stop'
372
+ try {
373
+ $task = $null
374
+ try { $task = Get-ScheduledTask -TaskName '${taskName}' -ErrorAction Stop } catch { if ($_.FullyQualifiedErrorId -notmatch 'NotFound') { throw } }
375
+ if ($null -eq $task) {
376
+ [PSCustomObject]@{ found = $false } | ConvertTo-Json -Compress
377
+ } else {
378
+ $info = Get-ScheduledTaskInfo -TaskName '${taskName}'
379
+ $xml = Export-ScheduledTask -TaskName '${taskName}'
380
+ $lastRun = $null
381
+ # 267011 (0x41303) = SCHED_S_TASK_HAS_NOT_RUN — the RELIABLE never-run
382
+ # signal; the timestamp sentinel alone varies by locale/host (observed
383
+ # 1899- AND 1999-dated sentinons on real hosts).
384
+ if ($info.LastRunTime -and $info.LastTaskResult -ne 267011 -and $info.LastRunTime.Year -gt 1899) { $lastRun = $info.LastRunTime.ToString('o') }
385
+ $lastResult = $null
386
+ if ($null -ne $info.LastTaskResult) { $lastResult = [int64]$info.LastTaskResult }
387
+ $nextRun = $null
388
+ if ($info.NextRunTime -and $info.NextRunTime.Year -gt 1899) { $nextRun = $info.NextRunTime.ToString('o') }
389
+ # The run-as ownership witness: the SID of the account this query
390
+ # runs under, compared against the task's <Principal><UserId>.
391
+ $currentUserSid = $null
392
+ try { $currentUserSid = [System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value } catch { $currentUserSid = $null }
393
+ [PSCustomObject]@{ found = $true; state = [string]$task.State; xml = [string]$xml; lastRunAt = $lastRun; lastResult = $lastResult; nextRunTime = $nextRun; currentUserSid = $currentUserSid } | ConvertTo-Json -Compress
394
+ }
395
+ } catch {
396
+ [PSCustomObject]@{ ok = $false; errorId = $_.FullyQualifiedErrorId; message = $_.Exception.Message } | ConvertTo-Json -Compress
397
+ }
398
+ `.trim();
399
+ }
400
+ function mutationScript(body) {
401
+ return `
402
+ [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
403
+ $ErrorActionPreference = 'Stop'
404
+ try {
405
+ ${body}
406
+ } catch {
407
+ [PSCustomObject]@{ ok = $false; errorId = $_.FullyQualifiedErrorId; message = $_.Exception.Message } | ConvertTo-Json -Compress
408
+ }
409
+ `.trim();
410
+ }
411
+ export function createWindowsSchedulerAdapter(deps) {
412
+ const { runner, fileIo } = deps;
413
+ async function runPowerShell(script, extraEnv) {
414
+ return runner.run('powershell.exe', [...POWERSHELL_ARGS_PREFIX, script], extraEnv);
415
+ }
416
+ /** Query the OS task. `not-found` is a normal verdict, everything else is structured. */
417
+ async function queryTask(taskName) {
418
+ const result = await runPowerShell(queryScript(taskName));
419
+ if (result.timedOut === true) {
420
+ return { ok: false, kind: 'command_failed', reason: 'powershell_timeout', nextAction: 'The Task Scheduler query did not return in time; check powershell.exe availability and machine load, then retry.' };
421
+ }
422
+ if (result.spawnError !== undefined) {
423
+ return { ok: false, kind: 'unavailable', reason: `powershell_unavailable:${result.spawnError.slice(0, 80)}`, nextAction: 'powershell.exe could not be started; the Windows scheduler adapter needs PowerShell (built into Windows).' };
424
+ }
425
+ const parsed = parsePowerShellJson(result.stdout);
426
+ if (!parsed.ok) {
427
+ return { ok: false, kind: 'command_failed', reason: parsed.reason, nextAction: 'The Task Scheduler PowerShell query returned unparsable output; re-run pd service status to see whether it is transient.' };
428
+ }
429
+ if (isPowerShellError(parsed.body)) {
430
+ const errorId = parsed.body.errorId ?? 'unknown';
431
+ // Permission denial must NEVER be reported as "not installed" (task §5).
432
+ return {
433
+ ok: false,
434
+ kind: 'command_failed',
435
+ reason: `scheduler_query_failed:${errorId}`,
436
+ nextAction: `The Task Scheduler query failed (${errorId}: ${parsed.body.message ?? ''}). If this is an access-denied error, the task exists but this process may not read it — do not treat the install as unregistered.`,
437
+ };
438
+ }
439
+ if (!isPowerShellQueryBody(parsed.body)) {
440
+ return { ok: false, kind: 'command_failed', reason: 'powershell_unexpected_output_shape', nextAction: 'The Task Scheduler query returned an unexpected document shape; re-run pd service status to see whether it is transient.' };
441
+ }
442
+ return { ok: true, body: parsed.body };
443
+ }
444
+ /**
445
+ * Fail-closed ownership check (task §5 review): the exported Task XML is
446
+ * PARSED — Exec Command, Exec Arguments (decoded per the Win32 argv
447
+ * rules), WorkingDirectory and the LogonTrigger principal are each
448
+ * verified. A task whose definition merely CONTAINS our path strings
449
+ * (foreign content with matching substrings) is foreign; a task whose
450
+ * definition cannot be parsed at all is foreign too — PD never modifies
451
+ * or deletes what it cannot prove is its own.
452
+ */
453
+ function ownershipVerdict(body, registration) {
454
+ if (!body.found || typeof body.xml !== 'string')
455
+ return { ours: false, conflict: 'external', detail: 'no_exported_xml' };
456
+ const exec = taskActionsExec(body.xml);
457
+ if (!exec.ok) {
458
+ return { ours: false, conflict: 'external', detail: `unparsable_exec:${exec.detail}` };
459
+ }
460
+ const command = xmlElement(exec.exec, 'Command');
461
+ const argsText = xmlElement(exec.exec, 'Arguments');
462
+ const workDir = xmlElement(exec.exec, 'WorkingDirectory');
463
+ const principals = taskPrincipalUsers(body.xml);
464
+ if (command === null || argsText === null || workDir === null) {
465
+ const missing = [command === null ? 'Command' : '', argsText === null ? 'Arguments' : '', workDir === null ? 'WorkingDirectory' : ''].filter(Boolean).join('+');
466
+ return { ours: false, conflict: 'external', detail: `unparsable_exec:${missing}` };
467
+ }
468
+ const execArgv = [command, ...windowsParseCommandLine(argsText)];
469
+ const expectedArgv = [registration.nodePath, ...schedulerInvocationArgs(registration)];
470
+ const execMatches = execArgv.length === expectedArgv.length
471
+ && execArgv.every((token, index) => token.toLowerCase() === expectedArgv[index]?.toLowerCase());
472
+ const workDirMatches = workDir.toLowerCase() === registration.pdHome.toLowerCase();
473
+ // The task must declare exactly ONE non-empty interactive user
474
+ // principal on its logon trigger — zero or several inside the
475
+ // trigger means a definition PD did not write.
476
+ const principalMatches = principals.length === 1 && (principals[0] ?? '') !== '';
477
+ // The run-as principal must be exactly ONE <Principal><UserId> and
478
+ // equal the SID of the account this process runs under — otherwise
479
+ // the task was retargeted to a foreign account (or the SID could not
480
+ // be resolved) and the registration is not provably PD's.
481
+ const runAs = taskRunAsUsers(body.xml);
482
+ const sid = typeof body.currentUserSid === 'string' && body.currentUserSid !== '' ? body.currentUserSid : null;
483
+ const runAsMatches = runAs.length === 1 && (runAs[0] ?? '') !== ''
484
+ && sid !== null && (runAs[0] ?? '').toLowerCase() === sid.toLowerCase();
485
+ if (execMatches && workDirMatches && principalMatches && runAsMatches)
486
+ return { ours: true };
487
+ const detail = [
488
+ execMatches ? '' : `argv_mismatch(expected ${expectedArgv.length} got ${execArgv.length})`,
489
+ workDirMatches ? '' : 'workdir_mismatch',
490
+ principalMatches ? '' : `principal_mismatch(count=${principals.length})`,
491
+ runAsMatches ? '' : `runas_mismatch(count=${runAs.length}${sid === null ? ',sid_unresolved' : ''})`,
492
+ ].filter(Boolean).join('+');
493
+ return { ours: false, conflict: 'external', detail };
494
+ }
495
+ async function status(registration) {
496
+ const query = await queryTask(registration.identity.windowsTaskName);
497
+ if (!query.ok) {
498
+ return { ok: false, kind: query.kind, reason: query.reason, nextAction: query.nextAction };
499
+ }
500
+ return { ok: true, changed: false, facts: factsFromQuery(registration.identity, query.body) };
501
+ }
502
+ async function runMutation(registration, scriptBody, options) {
503
+ const taskName = registration.identity.windowsTaskName;
504
+ const result = await runPowerShell(mutationScript(scriptBody(taskName)), options?.extraEnv);
505
+ if (result.timedOut === true) {
506
+ return { ok: false, kind: 'command_failed', reason: 'powershell_timeout', nextAction: 'The Task Scheduler mutation did not finish in time; re-run the command — operations are idempotent.' };
507
+ }
508
+ if (result.spawnError !== undefined) {
509
+ return { ok: false, kind: 'unavailable', reason: `powershell_unavailable:${result.spawnError.slice(0, 80)}`, nextAction: 'powershell.exe could not be started; the Windows scheduler adapter needs PowerShell (built into Windows).' };
510
+ }
511
+ const parsed = parsePowerShellJson(result.stdout);
512
+ if (!parsed.ok) {
513
+ return { ok: false, kind: 'command_failed', reason: parsed.reason, nextAction: 'The Task Scheduler PowerShell mutation returned unparsable output; re-run the command and inspect the task with pd service status.' };
514
+ }
515
+ if (isPowerShellError(parsed.body)) {
516
+ const errorId = parsed.body.errorId ?? 'unknown';
517
+ return {
518
+ ok: false,
519
+ kind: 'command_failed',
520
+ reason: `scheduler_mutation_failed:${errorId}`,
521
+ nextAction: `The Task Scheduler operation failed (${errorId}: ${parsed.body.message ?? ''}). Nothing was silently skipped — re-run after fixing the cause; the operation is idempotent.`,
522
+ };
523
+ }
524
+ const statusNow = await status(registration);
525
+ if (!statusNow.ok)
526
+ return statusNow;
527
+ return { ...statusNow, changed: true };
528
+ }
529
+ /** Write the task XML under <pdHome>/service and Register-ScheduledTask it. */
530
+ async function writeAndRegisterXml(registration, xml, mode) {
531
+ const xmlDir = path.join(registration.pdHome, 'service');
532
+ const xmlFile = path.join(xmlDir, 'scheduler-registration-win.xml');
533
+ const mkdir = fileIo.mkdirs(xmlDir);
534
+ if (!mkdir.ok) {
535
+ return { ok: false, kind: 'command_failed', reason: `scheduler_xml_dir_unwritable:${mkdir.reason.slice(0, 80)}`, nextAction: `Could not prepare ${xmlDir}; check permissions and retry pd service install.` };
536
+ }
537
+ const written = fileIo.writeAtomic(xmlFile, xml);
538
+ if (!written.ok) {
539
+ return { ok: false, kind: 'command_failed', reason: `scheduler_xml_write_failed:${written.reason.slice(0, 80)}`, nextAction: `Could not write the task definition to ${xmlFile}; retry pd service install after fixing the filesystem issue.` };
540
+ }
541
+ // ITaskFolder::RegisterTask flags: TASK_CREATE(2) refuses an existing
542
+ // task; TASK_UPDATE(4) rewrites the registration IN PLACE — a failed
543
+ // update leaves the old task and its enabled state intact, unlike
544
+ // Unregister→Register which deletes first (Register-ScheduledTask has
545
+ // no overwrite flag — it fails with HRESULT 0x800700b7, and the
546
+ // delete-first workaround risked losing the registration on failure).
547
+ const taskFlags = mode === 'update' ? 4 : 2;
548
+ const body = (name) => `
549
+ # -Encoding UTF8: the definition is written UTF-8 without BOM; Windows
550
+ # PowerShell 5.1 would otherwise decode it with the ANSI codepage and
551
+ # corrupt CJK/special characters in install paths (task §3.2).
552
+ $xmlText = Get-Content -LiteralPath $env:PD_TASK_XML -Raw -Encoding UTF8
553
+ $user = "$env:USERDOMAIN\\$env:USERNAME" -replace '&','&amp;'
554
+ $xmlText = $xmlText.Replace('__PD_TASK_USER__', $user)
555
+ $ts = New-Object -ComObject Schedule.Service
556
+ $ts.Connect()
557
+ # LogonType 3 = TASK_LOGON_INTERACTIVE_TOKEN (run as the registering
558
+ # user, matching the XML's LogonTrigger principal).
559
+ $ts.GetFolder('\\').RegisterTask('${name}', $xmlText, ${taskFlags}, $null, $null, 3, $null) | Out-Null
560
+ [PSCustomObject]@{ done = $true } | ConvertTo-Json -Compress`;
561
+ return runMutation(registration, body, { extraEnv: { PD_TASK_XML: xmlFile } });
562
+ }
563
+ return {
564
+ platform: 'win32',
565
+ async install(registration) {
566
+ const taskName = registration.identity.windowsTaskName;
567
+ const query = await queryTask(taskName);
568
+ if (!query.ok) {
569
+ return { ok: false, kind: query.kind, reason: query.reason, nextAction: query.nextAction };
570
+ }
571
+ if (query.body.found) {
572
+ const ownership = ownershipVerdict(query.body, registration);
573
+ if (!ownership.ours) {
574
+ return {
575
+ ok: false,
576
+ kind: 'external_conflict',
577
+ reason: 'scheduler_task_name_conflict_foreign_task',
578
+ nextAction: `A Task Scheduler task named ${taskName} already exists but does not reference this PD install (${registration.pdHome}; verdict: ${ownership.detail}). PD never overwrites or deletes foreign registrations — remove or rename it manually, or inspect it with Export-ScheduledTask.`,
579
+ facts: factsFromQuery(registration.identity, query.body),
580
+ };
581
+ }
582
+ // Refresh our own registration (task §15 review): rewrite the
583
+ // definition from the CURRENT OS state — interval + enabled
584
+ // preserved, only the CLI entry/node path move forward — unless
585
+ // the caller explicitly passed a new --interval-ms.
586
+ const preservedInterval = typeof query.body.xml === 'string' && registration.intervalExplicit !== true
587
+ ? parseWindowsIntervalMs(query.body.xml)
588
+ : null;
589
+ const effective = preservedInterval !== null
590
+ ? { ...registration, intervalMs: preservedInterval }
591
+ : registration;
592
+ const wasEnabled = query.body.state !== '' && query.body.state !== 'Disabled';
593
+ return writeAndRegisterXml(registration, buildWindowsTaskXml(effective, new Date(), wasEnabled), 'update');
594
+ }
595
+ return writeAndRegisterXml(registration, buildWindowsTaskXml(registration), 'create');
596
+ },
597
+ async enable(registration) {
598
+ const taskName = registration.identity.windowsTaskName;
599
+ const query = await queryTask(taskName);
600
+ if (!query.ok) {
601
+ return { ok: false, kind: query.kind, reason: query.reason, nextAction: query.nextAction };
602
+ }
603
+ if (!query.body.found) {
604
+ return {
605
+ ok: false,
606
+ kind: 'unsafe_state',
607
+ reason: 'scheduler_not_registered',
608
+ nextAction: 'No scheduler registration exists for this install. Run pd service install first — enable never creates one.',
609
+ };
610
+ }
611
+ const ownership = ownershipVerdict(query.body, registration);
612
+ if (!ownership.ours) {
613
+ return {
614
+ ok: false,
615
+ kind: 'external_conflict',
616
+ reason: 'scheduler_task_name_conflict_foreign_task',
617
+ nextAction: `The task named ${taskName} is not PD's own registration (verdict: ${ownership.detail}); PD refuses to modify it. Remove it manually if you own it.`,
618
+ facts: factsFromQuery(registration.identity, query.body),
619
+ };
620
+ }
621
+ if (query.body.state === 'Ready' || query.body.state === 'Running' || query.body.state === 'Queued') {
622
+ return { ok: true, changed: false, facts: factsFromQuery(registration.identity, query.body) };
623
+ }
624
+ return runMutation(registration, (name) => `
625
+ Enable-ScheduledTask -TaskName '${name}' | Out-Null
626
+ [PSCustomObject]@{ done = $true } | ConvertTo-Json -Compress`);
627
+ },
628
+ async disable(registration) {
629
+ const taskName = registration.identity.windowsTaskName;
630
+ const query = await queryTask(taskName);
631
+ if (!query.ok) {
632
+ return { ok: false, kind: query.kind, reason: query.reason, nextAction: query.nextAction };
633
+ }
634
+ if (!query.body.found) {
635
+ return {
636
+ ok: false,
637
+ kind: 'unsafe_state',
638
+ reason: 'scheduler_not_registered',
639
+ nextAction: 'No scheduler registration exists for this install; nothing to disable. Run pd service install first if you expected one.',
640
+ };
641
+ }
642
+ const ownership = ownershipVerdict(query.body, registration);
643
+ if (!ownership.ours) {
644
+ return {
645
+ ok: false,
646
+ kind: 'external_conflict',
647
+ reason: 'scheduler_task_name_conflict_foreign_task',
648
+ nextAction: `The task named ${taskName} is not PD's own registration (verdict: ${ownership.detail}); PD refuses to modify it.`,
649
+ facts: factsFromQuery(registration.identity, query.body),
650
+ };
651
+ }
652
+ if (query.body.state === 'Disabled') {
653
+ return { ok: true, changed: false, facts: factsFromQuery(registration.identity, query.body) };
654
+ }
655
+ return runMutation(registration, (name) => `
656
+ Disable-ScheduledTask -TaskName '${name}' | Out-Null
657
+ [PSCustomObject]@{ done = $true } | ConvertTo-Json -Compress`);
658
+ },
659
+ status,
660
+ async uninstall(registration) {
661
+ const taskName = registration.identity.windowsTaskName;
662
+ const query = await queryTask(taskName);
663
+ if (!query.ok) {
664
+ return { ok: false, kind: query.kind, reason: query.reason, nextAction: query.nextAction };
665
+ }
666
+ if (!query.body.found) {
667
+ // Idempotent no-op: nothing registered, nothing to remove.
668
+ return { ok: true, changed: false, facts: factsFromQuery(registration.identity, query.body) };
669
+ }
670
+ const ownership = ownershipVerdict(query.body, registration);
671
+ if (!ownership.ours) {
672
+ return {
673
+ ok: false,
674
+ kind: 'external_conflict',
675
+ reason: 'scheduler_task_name_conflict_foreign_task',
676
+ nextAction: `A task named ${taskName} exists but does not reference this PD install (verdict: ${ownership.detail}); PD never deletes foreign registrations. Inspect it with Export-ScheduledTask and remove it manually if you own it.`,
677
+ facts: factsFromQuery(registration.identity, query.body),
678
+ };
679
+ }
680
+ // Stop future triggers first, then remove the registration (task §5).
681
+ return runMutation(registration, (name) => `
682
+ Disable-ScheduledTask -TaskName '${name}' -ErrorAction SilentlyContinue | Out-Null
683
+ Unregister-ScheduledTask -TaskName '${name}' -Confirm:$false
684
+ [PSCustomObject]@{ done = $true } | ConvertTo-Json -Compress`);
685
+ },
686
+ };
687
+ }
688
+ //# sourceMappingURL=windows.js.map