create-principles-disciple 1.155.3 → 1.156.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (247) hide show
  1. package/_release/product-identity.json +2 -2
  2. package/codex-adapter/dist/ingestion/pain-receipt-fallback.d.ts +28 -1
  3. package/codex-adapter/dist/ingestion/pain-receipt-fallback.js +53 -17
  4. package/codex-adapter/dist/worker/workspace-worker.js +86 -66
  5. package/codex-adapter/package.json +1 -1
  6. package/console/dist/server/index.d.ts +11 -1
  7. package/console/dist/server/index.js +84 -19
  8. package/console/dist/server/release-handover.d.ts +256 -0
  9. package/console/dist/server/release-handover.js +402 -0
  10. package/console/dist/server/routes/onboarding.js +1 -0
  11. package/console/dist/server/routes/update-transaction.js +37 -3
  12. package/console/dist/server/routes/update.js +21 -1
  13. package/console/dist/server/successor.d.ts +46 -0
  14. package/console/dist/server/successor.js +128 -0
  15. package/console/dist/web/assets/app.css +18 -0
  16. package/console/dist/web/assets/app.js +32 -31
  17. package/console/package.json +1 -1
  18. package/core/dist/runtime/candidate-intake-service.d.ts +1 -1
  19. package/core/dist/runtime/candidate-intake-service.d.ts.map +1 -1
  20. package/core/dist/runtime/candidate-intake-service.js +89 -12
  21. package/core/dist/runtime/candidate-intake-service.js.map +1 -1
  22. package/core/dist/runtime/context-payload.d.ts +11 -0
  23. package/core/dist/runtime/context-payload.d.ts.map +1 -1
  24. package/core/dist/runtime/context-payload.js +27 -0
  25. package/core/dist/runtime/context-payload.js.map +1 -1
  26. package/core/dist/runtime/host-submission-context.d.ts +13 -6
  27. package/core/dist/runtime/host-submission-context.d.ts.map +1 -1
  28. package/core/dist/runtime/host-submission-context.js +77 -8
  29. package/core/dist/runtime/host-submission-context.js.map +1 -1
  30. package/core/dist/runtime/index.d.ts +2 -1
  31. package/core/dist/runtime/index.d.ts.map +1 -1
  32. package/core/dist/runtime/index.js +8 -0
  33. package/core/dist/runtime/index.js.map +1 -1
  34. package/core/dist/runtime/pain-ingress.d.ts +8 -0
  35. package/core/dist/runtime/pain-ingress.d.ts.map +1 -1
  36. package/core/dist/runtime/pain-ingress.js +8 -1
  37. package/core/dist/runtime/pain-ingress.js.map +1 -1
  38. package/core/dist/runtime/pain-recall-read-model.d.ts +72 -0
  39. package/core/dist/runtime/pain-recall-read-model.d.ts.map +1 -1
  40. package/core/dist/runtime/pain-recall-read-model.js +46 -21
  41. package/core/dist/runtime/pain-recall-read-model.js.map +1 -1
  42. package/core/dist/runtime/pain-receipt-recovery.d.ts +4 -1
  43. package/core/dist/runtime/pain-receipt-recovery.d.ts.map +1 -1
  44. package/core/dist/runtime/pain-receipt-recovery.js +28 -10
  45. package/core/dist/runtime/pain-receipt-recovery.js.map +1 -1
  46. package/core/dist/runtime/pain-signal-bridge.d.ts +38 -23
  47. package/core/dist/runtime/pain-signal-bridge.d.ts.map +1 -1
  48. package/core/dist/runtime/pain-signal-bridge.js +533 -182
  49. package/core/dist/runtime/pain-signal-bridge.js.map +1 -1
  50. package/core/dist/runtime/pain-signal-runtime-factory.d.ts +8 -1
  51. package/core/dist/runtime/pain-signal-runtime-factory.d.ts.map +1 -1
  52. package/core/dist/runtime/pain-signal-runtime-factory.js +196 -25
  53. package/core/dist/runtime/pain-signal-runtime-factory.js.map +1 -1
  54. package/core/dist/runtime/pain-target-evidence-reconcile.d.ts +78 -4
  55. package/core/dist/runtime/pain-target-evidence-reconcile.d.ts.map +1 -1
  56. package/core/dist/runtime/pain-target-evidence-reconcile.js +229 -18
  57. package/core/dist/runtime/pain-target-evidence-reconcile.js.map +1 -1
  58. package/core/dist/runtime/pain-to-principle-service.d.ts +26 -5
  59. package/core/dist/runtime/pain-to-principle-service.d.ts.map +1 -1
  60. package/core/dist/runtime/pain-to-principle-service.js +63 -52
  61. package/core/dist/runtime/pain-to-principle-service.js.map +1 -1
  62. package/core/dist/runtime/store/candidate/admission-document.d.ts +43 -0
  63. package/core/dist/runtime/store/candidate/admission-document.d.ts.map +1 -1
  64. package/core/dist/runtime/store/candidate/admission-document.js +130 -0
  65. package/core/dist/runtime/store/candidate/admission-document.js.map +1 -1
  66. package/core/dist/runtime/store/candidate/candidate-store.d.ts +3 -1
  67. package/core/dist/runtime/store/candidate/candidate-store.d.ts.map +1 -1
  68. package/core/dist/runtime/store/candidate/memory-candidate-store.d.ts +2 -1
  69. package/core/dist/runtime/store/candidate/memory-candidate-store.d.ts.map +1 -1
  70. package/core/dist/runtime/store/candidate/memory-candidate-store.js +27 -1
  71. package/core/dist/runtime/store/candidate/memory-candidate-store.js.map +1 -1
  72. package/core/dist/runtime/store/candidate/sqlite-candidate-store.d.ts +2 -1
  73. package/core/dist/runtime/store/candidate/sqlite-candidate-store.d.ts.map +1 -1
  74. package/core/dist/runtime/store/candidate/sqlite-candidate-store.js +59 -2
  75. package/core/dist/runtime/store/candidate/sqlite-candidate-store.js.map +1 -1
  76. package/core/dist/runtime/store/context/sqlite-context-assembler.d.ts.map +1 -1
  77. package/core/dist/runtime/store/context/sqlite-context-assembler.js +18 -3
  78. package/core/dist/runtime/store/context/sqlite-context-assembler.js.map +1 -1
  79. package/core/dist/runtime/store/runtime-state-manager.d.ts +2 -1
  80. package/core/dist/runtime/store/runtime-state-manager.d.ts.map +1 -1
  81. package/core/dist/runtime/store/runtime-state-manager.js +4 -0
  82. package/core/dist/runtime/store/runtime-state-manager.js.map +1 -1
  83. package/core/dist/telemetry-event.d.ts +2 -2
  84. package/core/dist/telemetry-event.d.ts.map +1 -1
  85. package/core/dist/telemetry-event.js +5 -0
  86. package/core/dist/telemetry-event.js.map +1 -1
  87. package/core/package.json +1 -1
  88. package/dist/i18n.d.ts.map +1 -1
  89. package/dist/i18n.js +72 -0
  90. package/dist/i18n.js.map +1 -1
  91. package/dist/index.d.ts +15 -0
  92. package/dist/index.d.ts.map +1 -1
  93. package/dist/index.js +145 -35
  94. package/dist/index.js.map +1 -1
  95. package/dist/installer.d.ts +149 -9
  96. package/dist/installer.d.ts.map +1 -1
  97. package/dist/installer.js +542 -31
  98. package/dist/installer.js.map +1 -1
  99. package/dist/installers/codex-host-installer.js +1 -1
  100. package/dist/installers/codex-host-installer.js.map +1 -1
  101. package/dist/installers/index.d.ts +10 -0
  102. package/dist/installers/index.d.ts.map +1 -1
  103. package/dist/installers/index.js +4 -0
  104. package/dist/installers/index.js.map +1 -1
  105. package/dist/mvp-config.js +1 -1
  106. package/dist/mvp-config.js.map +1 -1
  107. package/dist/prompts.d.ts +36 -12
  108. package/dist/prompts.d.ts.map +1 -1
  109. package/dist/prompts.js +102 -30
  110. package/dist/prompts.js.map +1 -1
  111. package/dist/service-host-bridge.d.ts +71 -12
  112. package/dist/service-host-bridge.d.ts.map +1 -1
  113. package/dist/service-host-bridge.js +228 -48
  114. package/dist/service-host-bridge.js.map +1 -1
  115. package/dist/service-host-provisioning.d.ts +102 -0
  116. package/dist/service-host-provisioning.d.ts.map +1 -0
  117. package/dist/service-host-provisioning.js +595 -0
  118. package/dist/service-host-provisioning.js.map +1 -0
  119. package/dist/uninstaller.js +1 -1
  120. package/dist/uninstaller.js.map +1 -1
  121. package/dist/update/apply-payload.d.ts +9 -0
  122. package/dist/update/apply-payload.d.ts.map +1 -1
  123. package/dist/update/apply-payload.js +44 -2
  124. package/dist/update/apply-payload.js.map +1 -1
  125. package/dist/update/console-surface.d.ts +2 -1
  126. package/dist/update/console-surface.d.ts.map +1 -1
  127. package/dist/update/console-surface.js +6 -1
  128. package/dist/update/console-surface.js.map +1 -1
  129. package/dist/update/install-layout.d.ts +12 -0
  130. package/dist/update/install-layout.d.ts.map +1 -1
  131. package/dist/update/install-layout.js +49 -7
  132. package/dist/update/install-layout.js.map +1 -1
  133. package/dist/update/release-manager-authority.d.ts +16 -0
  134. package/dist/update/release-manager-authority.d.ts.map +1 -1
  135. package/dist/update/release-manager-authority.js +45 -3
  136. package/dist/update/release-manager-authority.js.map +1 -1
  137. package/dist/update/release-manager.d.ts +8 -3
  138. package/dist/update/release-manager.d.ts.map +1 -1
  139. package/dist/update/release-manager.js +29 -1
  140. package/dist/update/release-manager.js.map +1 -1
  141. package/dist/update/transaction-progress.d.ts +63 -0
  142. package/dist/update/transaction-progress.d.ts.map +1 -0
  143. package/dist/update/transaction-progress.js +207 -0
  144. package/dist/update/transaction-progress.js.map +1 -0
  145. package/dist/utils/env.d.ts +16 -1
  146. package/dist/utils/env.d.ts.map +1 -1
  147. package/dist/utils/env.js +55 -43
  148. package/dist/utils/env.js.map +1 -1
  149. package/host-runtime/dist/diagnostician-auto-run.js +37 -31
  150. package/host-runtime/dist/governance-observation-store.d.ts +38 -0
  151. package/host-runtime/dist/governance-observation-store.js +41 -0
  152. package/host-runtime/dist/governance-trajectory-turn-reader.js +26 -33
  153. package/host-runtime/package.json +1 -1
  154. package/install-layout/dist/background-execution-transition.d.ts +11 -1
  155. package/install-layout/dist/background-execution-transition.js +45 -1
  156. package/install-layout/dist/index.d.ts +3 -3
  157. package/install-layout/dist/index.js +10 -4
  158. package/install-layout/dist/pd-home.d.ts +12 -0
  159. package/install-layout/dist/pd-home.js +6 -1
  160. package/install-layout/package.json +1 -1
  161. package/package.json +7 -7
  162. package/pd-cli/dist/commands/candidate.d.ts +15 -0
  163. package/pd-cli/dist/commands/candidate.d.ts.map +1 -1
  164. package/pd-cli/dist/commands/candidate.js +449 -93
  165. package/pd-cli/dist/commands/candidate.js.map +1 -1
  166. package/pd-cli/dist/commands/console.d.ts.map +1 -1
  167. package/pd-cli/dist/commands/console.js +10 -0
  168. package/pd-cli/dist/commands/console.js.map +1 -1
  169. package/pd-cli/dist/commands/diagnose.d.ts.map +1 -1
  170. package/pd-cli/dist/commands/diagnose.js +254 -160
  171. package/pd-cli/dist/commands/diagnose.js.map +1 -1
  172. package/pd-cli/dist/commands/intake-outcome-guidance.d.ts +57 -0
  173. package/pd-cli/dist/commands/intake-outcome-guidance.d.ts.map +1 -0
  174. package/pd-cli/dist/commands/intake-outcome-guidance.js +206 -0
  175. package/pd-cli/dist/commands/intake-outcome-guidance.js.map +1 -0
  176. package/pd-cli/dist/commands/mcp-probe.d.ts.map +1 -1
  177. package/pd-cli/dist/commands/mcp-probe.js +1 -0
  178. package/pd-cli/dist/commands/mcp-probe.js.map +1 -1
  179. package/pd-cli/dist/commands/pain-record.d.ts.map +1 -1
  180. package/pd-cli/dist/commands/pain-record.js +18 -4
  181. package/pd-cli/dist/commands/pain-record.js.map +1 -1
  182. package/pd-cli/dist/commands/pain-retry.d.ts.map +1 -1
  183. package/pd-cli/dist/commands/pain-retry.js +91 -21
  184. package/pd-cli/dist/commands/pain-retry.js.map +1 -1
  185. package/pd-cli/dist/commands/runtime-uat.d.ts.map +1 -1
  186. package/pd-cli/dist/commands/runtime-uat.js +1 -0
  187. package/pd-cli/dist/commands/runtime-uat.js.map +1 -1
  188. package/pd-cli/dist/commands/service-lifecycle.js +1 -1
  189. package/pd-cli/dist/commands/service-lifecycle.js.map +1 -1
  190. package/pd-cli/dist/commands/service-run-once.d.ts +1 -1
  191. package/pd-cli/dist/commands/service-run-once.d.ts.map +1 -1
  192. package/pd-cli/dist/commands/service-run-once.js +9 -5
  193. package/pd-cli/dist/commands/service-run-once.js.map +1 -1
  194. package/pd-cli/dist/program.d.ts.map +1 -1
  195. package/pd-cli/dist/program.js +14 -3
  196. package/pd-cli/dist/program.js.map +1 -1
  197. package/pd-cli/dist/services/admission-write-gate.d.ts +4 -0
  198. package/pd-cli/dist/services/admission-write-gate.d.ts.map +1 -1
  199. package/pd-cli/dist/services/admission-write-gate.js +50 -48
  200. package/pd-cli/dist/services/admission-write-gate.js.map +1 -1
  201. package/pd-cli/dist/services/console-launcher.js +3 -3
  202. package/pd-cli/dist/services/console-launcher.js.map +1 -1
  203. package/pd-cli/dist/services/service-host/managed-run.d.ts.map +1 -1
  204. package/pd-cli/dist/services/service-host/managed-run.js +25 -8
  205. package/pd-cli/dist/services/service-host/managed-run.js.map +1 -1
  206. package/pd-cli/dist/services/service-host/scheduler/service-status.d.ts +12 -0
  207. package/pd-cli/dist/services/service-host/scheduler/service-status.d.ts.map +1 -1
  208. package/pd-cli/dist/services/service-host/scheduler/service-status.js +16 -7
  209. package/pd-cli/dist/services/service-host/scheduler/service-status.js.map +1 -1
  210. package/pd-cli/dist/services/service-host/status/service-run-status.d.ts +7 -5
  211. package/pd-cli/dist/services/service-host/status/service-run-status.d.ts.map +1 -1
  212. package/pd-cli/dist/services/service-host/status/service-run-status.js +1 -1
  213. package/pd-cli/dist/services/service-host/status/service-run-status.js.map +1 -1
  214. package/pd-cli/package.json +1 -1
  215. package/pd-mcp-server/dist/submit-assembly.js +61 -18
  216. package/pd-mcp-server/dist/version.d.ts +1 -1
  217. package/pd-mcp-server/dist/version.js +1 -1
  218. package/pd-mcp-server/package.json +1 -1
  219. package/plugin/dist/bundle.js +493 -493
  220. package/plugin/dist/openclaw-worker.js +263 -263
  221. package/plugin/dist/openclaw.plugin.json +1 -1
  222. package/plugin/openclaw.plugin.json +1 -1
  223. package/plugin/package.json +1 -1
  224. package/release-manager/dist/i18n.js +72 -0
  225. package/release-manager/dist/installer.js +542 -31
  226. package/release-manager/dist/installers/codex-host-installer.js +1 -1
  227. package/release-manager/dist/installers/index.js +4 -0
  228. package/release-manager/dist/mvp-config.js +1 -1
  229. package/release-manager/dist/service-host-bridge.js +228 -48
  230. package/release-manager/dist/service-host-provisioning.js +595 -0
  231. package/release-manager/dist/update/apply-payload.js +44 -2
  232. package/release-manager/dist/update/console-surface.js +6 -1
  233. package/release-manager/dist/update/install-layout.js +49 -7
  234. package/release-manager/dist/update/release-manager-authority.js +45 -3
  235. package/release-manager/dist/update/release-manager.js +29 -1
  236. package/release-manager/dist/update/transaction-progress.js +207 -0
  237. package/release-manager/dist/utils/env.js +55 -43
  238. package/release-manager/package.json +5 -5
  239. package/workbuddy-adapter/dist/codec/input-decoder.d.ts +21 -0
  240. package/workbuddy-adapter/dist/codec/input-decoder.js +50 -1
  241. package/workbuddy-adapter/dist/ingestion/pain-receipt-fallback.d.ts +68 -0
  242. package/workbuddy-adapter/dist/ingestion/pain-receipt-fallback.js +225 -0
  243. package/workbuddy-adapter/dist/pd-hook.js +60 -0
  244. package/workbuddy-adapter/dist/worker/workspace-worker.js +46 -44
  245. package/workbuddy-adapter/package.json +1 -1
  246. package/console/dist/server/utils/gateway.d.ts +0 -29
  247. package/console/dist/server/utils/gateway.js +0 -175
@@ -98,7 +98,7 @@ function getGlobalNpmRoot() {
98
98
  if (!isNpmDependencyResolutionEnabled())
99
99
  return undefined;
100
100
  try {
101
- const root = execSync('npm root -g', { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();
101
+ const root = execSync('npm root -g', { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true }).trim();
102
102
  return root.length > 0 ? root : undefined;
103
103
  }
104
104
  catch {
@@ -9,12 +9,16 @@ export { OpenClawHostInstaller } from './openclaw-host-installer.js';
9
9
  export { CodexHostInstaller } from './codex-host-installer.js';
10
10
  export { WorkBuddyHostInstaller } from './workbuddy-host-installer.js';
11
11
  export const HOST_TARGETS = ['openclaw', 'codex', 'workbuddy', 'all'];
12
+ export const HOST_SELECTIONS = [...HOST_TARGETS, 'none'];
12
13
  /**
13
14
  * Validate a CLI --host value. rc-1/rc-3: treat input as unknown, fail loud.
14
15
  */
15
16
  export function isHostTarget(value) {
16
17
  return typeof value === 'string' && HOST_TARGETS.includes(value);
17
18
  }
19
+ export function isHostSelection(value) {
20
+ return typeof value === 'string' && HOST_SELECTIONS.includes(value);
21
+ }
18
22
  /**
19
23
  * Factory: return the concrete HostInstaller instances for a given target.
20
24
  *
@@ -555,7 +555,7 @@ export function readEnabledChannelsFromConfigYaml(workspaceDir) {
555
555
  */
556
556
  export function getNpmGlobalBinDir() {
557
557
  try {
558
- const prefix = execSync('npm prefix -g', { encoding: 'utf-8', stdio: 'pipe' }).trim();
558
+ const prefix = execSync('npm prefix -g', { encoding: 'utf-8', stdio: 'pipe', windowsHide: true }).trim();
559
559
  if (!prefix)
560
560
  return null;
561
561
  return isWindows() ? prefix : path.join(prefix, 'bin');
@@ -25,14 +25,24 @@ const STRIPPED_ENV_KEYS = ['PD_EXPERIMENT_ROOT', 'PD_WORKSPACE_DIR'];
25
25
  const BRIDGE_TIMEOUT_MS = 120_000;
26
26
  const MAX_STDOUT_BYTES = 64 * 1024;
27
27
  const MAX_STDERR_BYTES = 16 * 1024;
28
- function cleanedEnv() {
28
+ function cleanedEnv(homeDir) {
29
29
  const env = { ...process.env };
30
30
  for (const key of STRIPPED_ENV_KEYS) {
31
31
  delete env[key];
32
32
  }
33
+ // Worker commands do NOT accept --pd-home (only `pd service` does), so the
34
+ // trusted install identity is supplied the way those commands resolve it:
35
+ // through the user home. Setting BOTH names keeps Node's os.homedir()
36
+ // consistent across platforms.
37
+ if (homeDir !== undefined) {
38
+ env.HOME = homeDir;
39
+ env.USERPROFILE = homeDir;
40
+ }
33
41
  return env;
34
42
  }
35
- function spawnCli(entry, args, spawnFn = spawn) {
43
+ function spawnCli(entry, args, options = {}) {
44
+ const spawnFn = options.spawnFn ?? spawn;
45
+ const timeoutMs = options.timeoutMs ?? BRIDGE_TIMEOUT_MS;
36
46
  return new Promise((resolve) => {
37
47
  let stdout = '';
38
48
  let stderr = '';
@@ -49,7 +59,7 @@ function spawnCli(entry, args, spawnFn = spawn) {
49
59
  catch {
50
60
  // exit handler settles
51
61
  }
52
- }, BRIDGE_TIMEOUT_MS);
62
+ }, timeoutMs);
53
63
  const settle = (outcome) => {
54
64
  if (settled)
55
65
  return;
@@ -59,7 +69,7 @@ function spawnCli(entry, args, spawnFn = spawn) {
59
69
  };
60
70
  try {
61
71
  child = spawnFn(process.execPath, [entry, ...args], {
62
- env: cleanedEnv(),
72
+ env: cleanedEnv(options.homeDir),
63
73
  stdio: ['ignore', 'pipe', 'pipe'],
64
74
  windowsHide: true,
65
75
  });
@@ -89,6 +99,46 @@ function spawnCli(entry, args, spawnFn = spawn) {
89
99
  });
90
100
  });
91
101
  }
102
+ export async function runInstalledCliJson(pdHome, args, options = {}) {
103
+ const entry = path.join(pdHome, 'runtime', 'pd-cli', 'dist', 'index.js');
104
+ if (!fs.existsSync(entry)) {
105
+ return { ok: false, code: null, detail: `service_host_cli_entry_missing:${entry}` };
106
+ }
107
+ const includePdHome = options.includePdHome !== false;
108
+ const fullArgs = includePdHome ? [...args, '--pd-home', path.dirname(pdHome)] : [...args];
109
+ const outcome = await spawnCli(entry, fullArgs, {
110
+ ...(options.probes?.spawnFn !== undefined ? { spawnFn: options.probes.spawnFn } : {}),
111
+ ...(options.timeoutMs !== undefined ? { timeoutMs: options.timeoutMs } : {}),
112
+ ...(options.homeDir !== undefined ? { homeDir: options.homeDir } : {}),
113
+ });
114
+ if (outcome.timedOut === true) {
115
+ return { ok: false, code: outcome.code, detail: `service_host_cli_timeout:${args.join(' ')}` };
116
+ }
117
+ if (outcome.spawnError !== undefined) {
118
+ return { ok: false, code: outcome.code, detail: `service_host_cli_spawn_failed:${outcome.spawnError}` };
119
+ }
120
+ const stdoutDoc = outcome.stdout.trim();
121
+ if (stdoutDoc === '') {
122
+ return { ok: false, code: outcome.code, detail: `service_host_cli_no_json:exit_${outcome.code ?? 'null'}`, stderr: outcome.stderr };
123
+ }
124
+ let parsed;
125
+ try {
126
+ parsed = JSON.parse(stdoutDoc);
127
+ }
128
+ catch {
129
+ return { ok: false, code: outcome.code, detail: `service_host_cli_unparsable_json:exit_${outcome.code ?? 'null'}`, stderr: outcome.stderr };
130
+ }
131
+ if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
132
+ return { ok: false, code: outcome.code, detail: 'service_host_cli_schema_violation:top_level', stderr: outcome.stderr };
133
+ }
134
+ return {
135
+ ok: outcome.code === 0,
136
+ code: outcome.code,
137
+ detail: outcome.code === 0 ? 'ok' : `exit_${outcome.code ?? 'null'}`,
138
+ doc: parsed,
139
+ stderr: outcome.stderr,
140
+ };
141
+ }
92
142
  /** Run one `pd service <subcommand>` lifecycle call against the installed CLI. */
93
143
  export async function runServiceHostCli(pdHome, args, probes = {}) {
94
144
  // args = ['service', '<op>', ...] — the operation is the second token.
@@ -104,7 +154,7 @@ export async function runServiceHostCli(pdHome, args, probes = {}) {
104
154
  // `--pd-home` carries the HOME ROOT — the CLI derives <home>/.pd itself,
105
155
  // so passing pdHome would resolve to <home>/.pd/.pd. For the canonical
106
156
  // layout getPdDir() IS <home>/.pd, hence dirname.
107
- const outcome = await spawnCli(entry, [...args, '--json', '--pd-home', path.dirname(pdHome)], probes.spawnFn);
157
+ const outcome = await spawnCli(entry, [...args, '--json', '--pd-home', path.dirname(pdHome)], { spawnFn: probes.spawnFn });
108
158
  if (outcome.timedOut === true) {
109
159
  return {
110
160
  ok: false,
@@ -163,8 +213,12 @@ export async function runServiceHostCli(pdHome, args, probes = {}) {
163
213
  scheduler.triggerConfiguration !== null
164
214
  ? (scheduler.triggerConfiguration.intervalMs ?? null)
165
215
  : null;
216
+ const enabled = typeof scheduler === 'object' && scheduler !== null && Object.hasOwn(scheduler, 'enabled') &&
217
+ (typeof scheduler.enabled === 'boolean' || scheduler.enabled === null)
218
+ ? scheduler.enabled
219
+ : null;
166
220
  if (outcome.code === 0 && doc.schemaVersion === 'pd.service-status.v1') {
167
- return { ok: true, detail: 'ok', registered, triggerIntervalMs: typeof intervalMs === 'number' ? intervalMs : null };
221
+ return { ok: true, detail: 'ok', registered, enabled, triggerIntervalMs: typeof intervalMs === 'number' ? intervalMs : null };
168
222
  }
169
223
  const reason = typeof doc.reason === 'string' ? doc.reason : `exit_${outcome.code ?? 'null'}`;
170
224
  if (outcome.code === 0 && doc.schemaVersion !== 'pd.service-status.v1') {
@@ -233,60 +287,186 @@ export function maybeSchedulerRegistrationExists(homeDir) {
233
287
  return true;
234
288
  }
235
289
  }
290
+ async function readSchedulerStatus(input) {
291
+ return await runServiceHostCli(input.pdHome, ['service', 'status'], input.probes ?? {});
292
+ }
236
293
  /**
237
- * Post-install scheduler reconciliation (task §6). Runs AFTER the install
238
- * transaction committed, so every failure is a WARNING — a bridge failure
239
- * must never turn a committed install into a reported failure (ERR-197).
294
+ * Post-install scheduler reconciliation (task §6 / PRI-1278 Phase 5). Runs
295
+ * AFTER the install transaction committed, so every failure is a WARNING — a
296
+ * bridge failure must never turn a committed install into a reported failure
297
+ * (ERR-197).
240
298
  *
241
- * - consent given: register (default disabled), then optionally enable;
242
- * - no consent: REFRESH-IF-REGISTERED only — an existing registration is
243
- * re-installed idempotently (entry refresh, enabled state PRESERVED), and
244
- * a machine with no registration gets NOTHING silently created.
299
+ * - 'enable': register then enable, then VERIFY through `pd service status`
300
+ * that the OS reports both facts (an unreadable verdict is degraded, never
301
+ * silently reported as success);
302
+ * - 'register_only': register installed_disabled;
303
+ * - 'refresh_if_registered': an existing registration is re-installed
304
+ * idempotently (entry refresh, enabled state PRESERVED); a machine with no
305
+ * registration gets NOTHING created;
306
+ * - 'opt_out' / 'consent_required': no OS mutation at all, with a structured
307
+ * reason — never silent.
245
308
  */
246
309
  export async function reconcileServiceHostScheduler(input) {
247
- if (input.registerServiceHost) {
248
- const install = await runServiceHostCli(input.pdHome, ['service', 'install'], input.probes ?? {});
249
- if (!install.ok) {
250
- input.warn(`Service Host scheduler registration failed (${install.detail}). ${install.nextAction ?? ''}`.trim());
251
- return;
252
- }
253
- input.info?.('Service Host scheduler registered (disabled by default — enable with `pd service enable`).');
254
- if (input.enableServiceHost) {
255
- const enable = await runServiceHostCli(input.pdHome, ['service', 'enable'], input.probes ?? {});
256
- if (!enable.ok) {
257
- input.warn(`Service Host scheduler ENABLE failed (${enable.detail}) — the registration exists but stays DISABLED. ${enable.nextAction ?? ''}`.trim());
258
- return;
259
- }
260
- input.info?.('Service Host scheduler enabled — automatic managed runs are armed.');
261
- }
262
- return;
263
- }
264
- // Upgrade path: refresh only when a registration plausibly exists. The
265
- // file probe avoids a full CLI boot per install on machines where nothing
266
- // was ever registered (CI/fresh installs); an unreadable dir falls back to
267
- // asking the CLI.
268
- if (!maybeSchedulerRegistrationExists(path.dirname(input.pdHome))) {
269
- return;
310
+ const warnings = [];
311
+ const warn = (message) => {
312
+ warnings.push(message);
313
+ input.warn(message);
314
+ };
315
+ if (input.intent === 'opt_out') {
316
+ return {
317
+ state: 'opted_out',
318
+ registered: null,
319
+ enabled: null,
320
+ nextAction: 'Service Host scheduler was explicitly disabled for this install. To adopt the PD-owned background lifecycle later, re-run the installer with --enable-service-host (workspace ownership is initialized in that same run); workspace data and pending tasks are kept.',
321
+ warnings,
322
+ };
270
323
  }
271
- const status = await runServiceHostCli(input.pdHome, ['service', 'status'], input.probes ?? {});
272
- if (!status.ok) {
273
- input.warn(`Service Host scheduler state could not be verified after install (${status.detail}) — nothing was changed. ${status.nextAction ?? ''}`.trim());
274
- return;
324
+ if (input.intent === 'consent_required') {
325
+ return {
326
+ state: 'consent_required',
327
+ registered: null,
328
+ enabled: null,
329
+ nextAction: 'No OS scheduler trigger was registered: this non-interactive run did not include consent. Re-run with --enable-service-host (or --yes to accept the recommended defaults) so the installer registers, enables AND initializes workspace ownership; workspace data and pending tasks are kept.',
330
+ warnings,
331
+ };
275
332
  }
276
- if (status.registered === true) {
277
- // Refresh preserves the existing registration config (task §15): the
278
- // interval comes from the live status document — an UNREADABLE interval
279
- // fails closed (a silent default would quietly reset a custom cadence).
333
+ if (input.intent === 'refresh_if_registered') {
334
+ // Upgrade / preservation path: refresh only when a registration
335
+ // plausibly exists. The file probe avoids a full CLI boot per install
336
+ // on machines where nothing was ever registered.
337
+ if (!maybeSchedulerRegistrationExists(path.dirname(input.pdHome))) {
338
+ return {
339
+ state: 'not_registered',
340
+ registered: false,
341
+ enabled: null,
342
+ nextAction: 'No Service Host scheduler registration existed before this install and none was created (upgrade preserves the existing lifecycle). Enable it explicitly with `pd service enable` after `pd service install` if this installation should move to the PD-owned background lifecycle.',
343
+ warnings,
344
+ };
345
+ }
346
+ const status = await readSchedulerStatus(input);
347
+ if (!status.ok) {
348
+ warn(`Service Host scheduler state could not be verified after install (${status.detail}) — nothing was changed. ${status.nextAction ?? ''}`.trim());
349
+ return {
350
+ state: 'failed',
351
+ registered: status.registered ?? null,
352
+ enabled: status.enabled ?? null,
353
+ detail: status.detail,
354
+ nextAction: 'Inspect `pd service status --json` and repair the registration; the existing scheduler state was kept unchanged.',
355
+ warnings,
356
+ };
357
+ }
358
+ if (status.registered !== true) {
359
+ return {
360
+ state: 'not_registered',
361
+ registered: status.registered ?? null,
362
+ enabled: status.enabled ?? null,
363
+ nextAction: 'No Service Host registration is present; nothing was created during this upgrade. Use `pd service install` + `pd service enable` to adopt the PD-owned background lifecycle.',
364
+ warnings,
365
+ };
366
+ }
280
367
  if (status.triggerIntervalMs === undefined || status.triggerIntervalMs === null) {
281
- input.warn('Service Host scheduler refresh refused: the registered trigger interval could not be read from pd service status — the existing registration was KEPT unchanged. Re-run pd service status and repair the registration first.');
282
- return;
368
+ warn('Service Host scheduler refresh refused: the registered trigger interval could not be read from pd service status — the existing registration was KEPT unchanged. Re-run pd service status and repair the registration first.');
369
+ return {
370
+ state: 'failed',
371
+ registered: status.registered,
372
+ enabled: status.enabled ?? null,
373
+ detail: 'trigger_interval_unreadable',
374
+ nextAction: 'Repair the registration (`pd service status --json`) and re-run the installer, or re-register explicitly with `pd service install --interval-ms <ms>`.',
375
+ warnings,
376
+ };
283
377
  }
284
378
  const refresh = await runServiceHostCli(input.pdHome, ['service', 'install', '--interval-ms', String(status.triggerIntervalMs)], input.probes ?? {});
285
379
  if (!refresh.ok) {
286
- input.warn(`Service Host scheduler refresh failed (${refresh.detail}) — the last valid registration was KEPT. ${refresh.nextAction ?? ''}`.trim());
287
- return;
380
+ warn(`Service Host scheduler refresh failed (${refresh.detail}) — the last valid registration was KEPT. ${refresh.nextAction ?? ''}`.trim());
381
+ return {
382
+ state: 'failed',
383
+ registered: true,
384
+ enabled: status.enabled ?? null,
385
+ triggerIntervalMs: status.triggerIntervalMs,
386
+ detail: refresh.detail,
387
+ nextAction: 'Re-run `pd service install` manually; the previous registration still exists and was not removed.',
388
+ warnings,
389
+ };
288
390
  }
289
391
  input.info?.(`Service Host scheduler registration refreshed to the active release (interval ${status.triggerIntervalMs}ms and enabled state preserved).`);
392
+ return {
393
+ state: 'refreshed',
394
+ registered: true,
395
+ enabled: status.enabled ?? null,
396
+ triggerIntervalMs: status.triggerIntervalMs,
397
+ nextAction: 'Registration refreshed to the active release; its enabled/disabled state was preserved.',
398
+ warnings,
399
+ };
290
400
  }
401
+ // 'enable' or an explicit register on a fresh install.
402
+ const install = await runServiceHostCli(input.pdHome, ['service', 'install'], input.probes ?? {});
403
+ if (!install.ok) {
404
+ warn(`Service Host scheduler registration failed (${install.detail}). ${install.nextAction ?? ''}`.trim());
405
+ return {
406
+ state: 'failed',
407
+ registered: install.registered ?? null,
408
+ enabled: null,
409
+ detail: install.detail,
410
+ nextAction: 'The Service Host scheduler was NOT registered, so workspace ownership will not be handed over. Fix the OS scheduler registration (`pd service install --json`) and re-run the installer.',
411
+ warnings,
412
+ };
413
+ }
414
+ if (input.intent === 'register_only') {
415
+ input.info?.('Service Host scheduler registered (disabled by default — enable with `pd service enable`).');
416
+ return {
417
+ state: 'registered_disabled',
418
+ registered: true,
419
+ enabled: false,
420
+ nextAction: 'The scheduler is registered but DISABLED. Re-run the installer with --enable-service-host after arming it so the new workspace is also initialized into Service Host ownership; enabling alone does not change ownership.',
421
+ warnings,
422
+ };
423
+ }
424
+ const enable = await runServiceHostCli(input.pdHome, ['service', 'enable'], input.probes ?? {});
425
+ if (!enable.ok) {
426
+ warn(`Service Host scheduler ENABLE failed (${enable.detail}) — the registration exists but stays DISABLED. ${enable.nextAction ?? ''}`.trim());
427
+ return {
428
+ state: 'registered_disabled',
429
+ registered: true,
430
+ enabled: false,
431
+ detail: enable.detail,
432
+ nextAction: 'The scheduler registration exists but could not be enabled, so workspace ownership will not be handed over. Fix the OS trigger (`pd service enable --json`) and re-run the installer.',
433
+ warnings,
434
+ };
435
+ }
436
+ // Verify through the OS-backed status document: "enable returned 0" is not
437
+ // proof that the trigger is armed (cli-6 / AC-12 truthful health).
438
+ const verified = await readSchedulerStatus(input);
439
+ if (!verified.ok || verified.registered !== true) {
440
+ warn(`Service Host scheduler enabled but the OS state could not be verified (${verified.detail}) — treat the trigger as UNCONFIRMED. ${verified.nextAction ?? ''}`.trim());
441
+ return {
442
+ state: 'failed',
443
+ registered: verified.registered ?? null,
444
+ enabled: verified.enabled ?? null,
445
+ detail: verified.detail,
446
+ nextAction: 'Run `pd service status --json` and confirm registered=true / enabled=true before relying on automatic runs; workspace ownership was NOT handed over.',
447
+ warnings,
448
+ };
449
+ }
450
+ if (verified.enabled !== true) {
451
+ warn('Service Host scheduler enabled but `pd service status` does not report the trigger as enabled — workspace ownership was NOT handed over.');
452
+ return {
453
+ state: 'registered_disabled',
454
+ registered: true,
455
+ enabled: verified.enabled ?? null,
456
+ triggerIntervalMs: verified.triggerIntervalMs ?? null,
457
+ detail: 'enabled_unconfirmed',
458
+ nextAction: 'Inspect `pd service status --json`; run `pd service enable` again if the OS reports the trigger disabled.',
459
+ warnings,
460
+ };
461
+ }
462
+ input.info?.('Service Host scheduler enabled — automatic managed runs are armed.');
463
+ return {
464
+ state: 'enabled',
465
+ registered: true,
466
+ enabled: true,
467
+ triggerIntervalMs: verified.triggerIntervalMs ?? null,
468
+ nextAction: 'Service Host scheduler is enabled and verified. One bounded cycle runs every configured interval while the user is logged in; disable any time with `pd service disable`.',
469
+ warnings,
470
+ };
291
471
  }
292
472
  //# sourceMappingURL=service-host-bridge.js.map