create-principles-disciple 1.149.0 → 1.150.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. package/_release/product-identity.json +1 -1
  2. package/codex-adapter/dist/pd-hook.d.ts +22 -1
  3. package/codex-adapter/dist/pd-hook.js +81 -7
  4. package/codex-adapter/dist/worker/workspace-worker.d.ts +15 -0
  5. package/codex-adapter/dist/worker/workspace-worker.js +7 -36
  6. package/codex-adapter/package.json +1 -1
  7. package/console/dist/server/index.js +14 -0
  8. package/console/dist/server/models/ActivationsConsoleModel.d.ts +3 -17
  9. package/console/dist/server/models/ActivationsConsoleModel.js +5 -44
  10. package/console/dist/server/routes/diagnostician.d.ts +50 -0
  11. package/console/dist/server/routes/diagnostician.js +388 -0
  12. package/console/dist/web/assets/app.js +24 -24
  13. package/core/dist/host/host-installer.d.ts +7 -0
  14. package/core/dist/host/host-installer.d.ts.map +1 -1
  15. package/core/dist/host/host-installer.js.map +1 -1
  16. package/core/dist/runtime/activation/index.d.ts +3 -3
  17. package/core/dist/runtime/activation/index.d.ts.map +1 -1
  18. package/core/dist/runtime/activation/index.js +1 -1
  19. package/core/dist/runtime/activation/index.js.map +1 -1
  20. package/core/dist/runtime/activation/promotion-readiness-evaluator.d.ts +25 -1
  21. package/core/dist/runtime/activation/promotion-readiness-evaluator.d.ts.map +1 -1
  22. package/core/dist/runtime/activation/promotion-readiness-evaluator.js +58 -1
  23. package/core/dist/runtime/activation/promotion-readiness-evaluator.js.map +1 -1
  24. package/core/dist/runtime/activation/promotion-readiness-reader.d.ts.map +1 -1
  25. package/core/dist/runtime/activation/promotion-readiness-reader.js +4 -2
  26. package/core/dist/runtime/activation/promotion-readiness-reader.js.map +1 -1
  27. package/core/dist/runtime/activation/rulecode-owner-decision-service.d.ts +28 -0
  28. package/core/dist/runtime/activation/rulecode-owner-decision-service.d.ts.map +1 -1
  29. package/core/dist/runtime/activation/rulecode-owner-decision-service.js +2 -0
  30. package/core/dist/runtime/activation/rulecode-owner-decision-service.js.map +1 -1
  31. package/core/dist/runtime/admission-gate.d.ts +8 -1
  32. package/core/dist/runtime/admission-gate.d.ts.map +1 -1
  33. package/core/dist/runtime/admission-gate.js +2 -1
  34. package/core/dist/runtime/admission-gate.js.map +1 -1
  35. package/core/dist/runtime/config/pd-config-defaults.d.ts.map +1 -1
  36. package/core/dist/runtime/config/pd-config-defaults.js +20 -2
  37. package/core/dist/runtime/config/pd-config-defaults.js.map +1 -1
  38. package/core/dist/runtime/config/pd-config-validate.d.ts.map +1 -1
  39. package/core/dist/runtime/config/pd-config-validate.js +18 -0
  40. package/core/dist/runtime/config/pd-config-validate.js.map +1 -1
  41. package/core/dist/runtime/context-payload.d.ts +48 -3
  42. package/core/dist/runtime/context-payload.d.ts.map +1 -1
  43. package/core/dist/runtime/context-payload.js +38 -0
  44. package/core/dist/runtime/context-payload.js.map +1 -1
  45. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.d.ts +8 -2
  46. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.d.ts.map +1 -1
  47. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.js +28 -2
  48. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.js.map +1 -1
  49. package/core/dist/runtime/diagnostician-candidate.d.ts +24 -0
  50. package/core/dist/runtime/diagnostician-candidate.d.ts.map +1 -0
  51. package/core/dist/runtime/diagnostician-candidate.js +55 -0
  52. package/core/dist/runtime/diagnostician-candidate.js.map +1 -0
  53. package/core/dist/runtime/evidence-guards.d.ts +10 -4
  54. package/core/dist/runtime/evidence-guards.d.ts.map +1 -1
  55. package/core/dist/runtime/evidence-guards.js +12 -5
  56. package/core/dist/runtime/evidence-guards.js.map +1 -1
  57. package/core/dist/runtime/evolution/evolution-types.d.ts +4 -4
  58. package/core/dist/runtime/evolution/evolution-types.d.ts.map +1 -1
  59. package/core/dist/runtime/evolution/evolution-types.js +1 -0
  60. package/core/dist/runtime/evolution/evolution-types.js.map +1 -1
  61. package/core/dist/runtime/feature-flags/feature-flag-contract.d.ts.map +1 -1
  62. package/core/dist/runtime/feature-flags/feature-flag-contract.js +14 -0
  63. package/core/dist/runtime/feature-flags/feature-flag-contract.js.map +1 -1
  64. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.d.ts.map +1 -1
  65. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js +16 -0
  66. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js.map +1 -1
  67. package/core/dist/runtime/index.d.ts +5 -2
  68. package/core/dist/runtime/index.d.ts.map +1 -1
  69. package/core/dist/runtime/index.js +6 -1
  70. package/core/dist/runtime/index.js.map +1 -1
  71. package/core/dist/runtime/internalization/index.d.ts +1 -0
  72. package/core/dist/runtime/internalization/index.d.ts.map +1 -1
  73. package/core/dist/runtime/internalization/index.js +2 -0
  74. package/core/dist/runtime/internalization/index.js.map +1 -1
  75. package/core/dist/runtime/internalization/rule-host-contracts.d.ts +10 -0
  76. package/core/dist/runtime/internalization/rule-host-contracts.d.ts.map +1 -1
  77. package/core/dist/runtime/internalization/rule-host-evaluator.js +10 -10
  78. package/core/dist/runtime/internalization/rule-host-evaluator.js.map +1 -1
  79. package/core/dist/runtime/internalization/rule-host-input-builder.d.ts +7 -6
  80. package/core/dist/runtime/internalization/rule-host-input-builder.d.ts.map +1 -1
  81. package/core/dist/runtime/internalization/rule-host-input-builder.js +6 -2
  82. package/core/dist/runtime/internalization/rule-host-input-builder.js.map +1 -1
  83. package/core/dist/runtime/internalization/rule-host-result-normalizer.d.ts +33 -0
  84. package/core/dist/runtime/internalization/rule-host-result-normalizer.d.ts.map +1 -0
  85. package/core/dist/runtime/internalization/rule-host-result-normalizer.js +61 -0
  86. package/core/dist/runtime/internalization/rule-host-result-normalizer.js.map +1 -0
  87. package/core/dist/runtime/internalization/rule-host-validator.d.ts.map +1 -1
  88. package/core/dist/runtime/internalization/rule-host-validator.js +17 -0
  89. package/core/dist/runtime/internalization/rule-host-validator.js.map +1 -1
  90. package/core/dist/runtime/pain-ingress-payload.d.ts +27 -2
  91. package/core/dist/runtime/pain-ingress-payload.d.ts.map +1 -1
  92. package/core/dist/runtime/pain-ingress-payload.js +45 -3
  93. package/core/dist/runtime/pain-ingress-payload.js.map +1 -1
  94. package/core/dist/runtime/pain-ingress.d.ts +4 -2
  95. package/core/dist/runtime/pain-ingress.d.ts.map +1 -1
  96. package/core/dist/runtime/pain-ingress.js +23 -3
  97. package/core/dist/runtime/pain-ingress.js.map +1 -1
  98. package/core/dist/runtime/pain-severity.d.ts +14 -0
  99. package/core/dist/runtime/pain-severity.d.ts.map +1 -0
  100. package/core/dist/runtime/pain-severity.js +14 -0
  101. package/core/dist/runtime/pain-severity.js.map +1 -0
  102. package/core/dist/runtime/pain-signal-bridge.d.ts +17 -3
  103. package/core/dist/runtime/pain-signal-bridge.d.ts.map +1 -1
  104. package/core/dist/runtime/pain-signal-bridge.js +6 -0
  105. package/core/dist/runtime/pain-signal-bridge.js.map +1 -1
  106. package/core/dist/runtime/pain-signal-observability.d.ts.map +1 -1
  107. package/core/dist/runtime/pain-signal-observability.js +3 -2
  108. package/core/dist/runtime/pain-signal-observability.js.map +1 -1
  109. package/core/dist/runtime/pain-submit-capability.d.ts +164 -0
  110. package/core/dist/runtime/pain-submit-capability.d.ts.map +1 -0
  111. package/core/dist/runtime/pain-submit-capability.js +442 -0
  112. package/core/dist/runtime/pain-submit-capability.js.map +1 -0
  113. package/core/dist/runtime/pain-to-principle-service.d.ts +4 -0
  114. package/core/dist/runtime/pain-to-principle-service.d.ts.map +1 -1
  115. package/core/dist/runtime/pain-to-principle-service.js +2 -0
  116. package/core/dist/runtime/pain-to-principle-service.js.map +1 -1
  117. package/core/dist/runtime/stalled-diagnostician-task-read-model.d.ts +56 -10
  118. package/core/dist/runtime/stalled-diagnostician-task-read-model.d.ts.map +1 -1
  119. package/core/dist/runtime/stalled-diagnostician-task-read-model.js +80 -4
  120. package/core/dist/runtime/stalled-diagnostician-task-read-model.js.map +1 -1
  121. package/core/dist/runtime/store/context/sqlite-context-assembler.d.ts.map +1 -1
  122. package/core/dist/runtime/store/context/sqlite-context-assembler.js +11 -0
  123. package/core/dist/runtime/store/context/sqlite-context-assembler.js.map +1 -1
  124. package/core/dist/runtime/store/run/memory-run-store.d.ts +10 -0
  125. package/core/dist/runtime/store/run/memory-run-store.d.ts.map +1 -1
  126. package/core/dist/runtime/store/run/memory-run-store.js +21 -0
  127. package/core/dist/runtime/store/run/memory-run-store.js.map +1 -1
  128. package/core/dist/runtime/store/run/run-store.d.ts +12 -0
  129. package/core/dist/runtime/store/run/run-store.d.ts.map +1 -1
  130. package/core/dist/runtime/store/run/sqlite-run-store.d.ts +1 -0
  131. package/core/dist/runtime/store/run/sqlite-run-store.d.ts.map +1 -1
  132. package/core/dist/runtime/store/run/sqlite-run-store.js +14 -0
  133. package/core/dist/runtime/store/run/sqlite-run-store.js.map +1 -1
  134. package/core/dist/runtime/task-status.d.ts +9 -0
  135. package/core/dist/runtime/task-status.d.ts.map +1 -1
  136. package/core/dist/runtime/task-status.js +7 -1
  137. package/core/dist/runtime/task-status.js.map +1 -1
  138. package/core/dist/runtime/types/evidence-chain-contract.d.ts +18 -0
  139. package/core/dist/runtime/types/evidence-chain-contract.d.ts.map +1 -1
  140. package/core/dist/runtime/types/evidence-chain-contract.js +37 -7
  141. package/core/dist/runtime/types/evidence-chain-contract.js.map +1 -1
  142. package/core/package.json +5 -1
  143. package/dist/install-summary.d.ts +7 -0
  144. package/dist/install-summary.d.ts.map +1 -1
  145. package/dist/install-summary.js +4 -0
  146. package/dist/install-summary.js.map +1 -1
  147. package/dist/installer.d.ts +34 -1
  148. package/dist/installer.d.ts.map +1 -1
  149. package/dist/installer.js +84 -4
  150. package/dist/installer.js.map +1 -1
  151. package/dist/installers/codex-host-installer.d.ts +88 -1
  152. package/dist/installers/codex-host-installer.d.ts.map +1 -1
  153. package/dist/installers/codex-host-installer.js +350 -11
  154. package/dist/installers/codex-host-installer.js.map +1 -1
  155. package/dist/installers/index.d.ts +23 -0
  156. package/dist/installers/index.d.ts.map +1 -1
  157. package/dist/installers/index.js +38 -1
  158. package/dist/installers/index.js.map +1 -1
  159. package/dist/installers/legacy-workbuddy-skill.d.ts +59 -0
  160. package/dist/installers/legacy-workbuddy-skill.d.ts.map +1 -0
  161. package/dist/installers/legacy-workbuddy-skill.js +168 -0
  162. package/dist/installers/legacy-workbuddy-skill.js.map +1 -0
  163. package/dist/installers/workbuddy-host-installer.d.ts.map +1 -1
  164. package/dist/installers/workbuddy-host-installer.js +7 -0
  165. package/dist/installers/workbuddy-host-installer.js.map +1 -1
  166. package/host-runtime/dist/adaptive-priority-provider.d.ts +94 -0
  167. package/host-runtime/dist/adaptive-priority-provider.js +162 -0
  168. package/host-runtime/dist/adaptive-selection.d.ts +164 -0
  169. package/host-runtime/dist/adaptive-selection.js +506 -0
  170. package/host-runtime/dist/diagnostician-auto-run.d.ts +28 -0
  171. package/host-runtime/dist/diagnostician-auto-run.js +100 -0
  172. package/host-runtime/dist/host-tool-semantic-resolver.d.ts +42 -1
  173. package/host-runtime/dist/host-tool-semantic-resolver.js +80 -14
  174. package/host-runtime/dist/index.d.ts +4 -0
  175. package/host-runtime/dist/index.js +6 -0
  176. package/host-runtime/dist/production-rulehost-gate.js +17 -17
  177. package/host-runtime/dist/rulecode-event-collection.d.ts +31 -0
  178. package/host-runtime/dist/rulecode-event-collection.js +62 -0
  179. package/host-runtime/package.json +1 -1
  180. package/package.json +3 -3
  181. package/pd-cli/dist/commands/diagnose.d.ts +30 -0
  182. package/pd-cli/dist/commands/diagnose.d.ts.map +1 -1
  183. package/pd-cli/dist/commands/diagnose.js +75 -0
  184. package/pd-cli/dist/commands/diagnose.js.map +1 -1
  185. package/pd-cli/dist/commands/pain-record.d.ts.map +1 -1
  186. package/pd-cli/dist/commands/pain-record.js +5 -4
  187. package/pd-cli/dist/commands/pain-record.js.map +1 -1
  188. package/pd-cli/dist/commands/pain-retry.d.ts.map +1 -1
  189. package/pd-cli/dist/commands/pain-retry.js +2 -1
  190. package/pd-cli/dist/commands/pain-retry.js.map +1 -1
  191. package/pd-cli/dist/commands/runtime-activation.d.ts +6 -17
  192. package/pd-cli/dist/commands/runtime-activation.d.ts.map +1 -1
  193. package/pd-cli/dist/commands/runtime-activation.js +42 -48
  194. package/pd-cli/dist/commands/runtime-activation.js.map +1 -1
  195. package/pd-cli/dist/index.js +1 -0
  196. package/pd-cli/dist/index.js.map +1 -1
  197. package/pd-cli/dist/services/delivery-surfaces.js +1 -1
  198. package/pd-cli/dist/services/delivery-surfaces.js.map +1 -1
  199. package/pd-cli/package.json +1 -1
  200. package/pd-mcp-server/dist/budget.d.ts +1 -1
  201. package/pd-mcp-server/dist/budget.js +2 -2
  202. package/pd-mcp-server/dist/envelope.d.ts +15 -0
  203. package/pd-mcp-server/dist/envelope.js +49 -1
  204. package/pd-mcp-server/dist/index.d.ts +2 -0
  205. package/pd-mcp-server/dist/index.js +6 -0
  206. package/pd-mcp-server/dist/server.d.ts +83 -14
  207. package/pd-mcp-server/dist/server.js +251 -4
  208. package/pd-mcp-server/dist/version.d.ts +1 -1
  209. package/pd-mcp-server/dist/version.js +1 -1
  210. package/pd-mcp-server/dist/workspace.d.ts +4 -2
  211. package/pd-mcp-server/dist/workspace.js +5 -2
  212. package/pd-mcp-server/package.json +1 -1
  213. package/plugin/dist/bundle.js +443 -431
  214. package/plugin/dist/core/evolution-reducer.d.ts +2 -2
  215. package/plugin/dist/hooks/hook-tool-semantics.d.ts +25 -0
  216. package/plugin/dist/hooks/pain-ingress-adapter.d.ts +1 -1
  217. package/plugin/dist/openclaw.plugin.json +1 -1
  218. package/plugin/dist/rulehost-evidence.js +1 -1
  219. package/plugin/openclaw.plugin.json +1 -1
  220. package/plugin/package.json +1 -1
  221. package/release-manager/dist/installer.js +84 -4
  222. package/release-manager/dist/installers/codex-host-installer.js +350 -11
  223. package/release-manager/dist/installers/index.js +38 -1
  224. package/release-manager/dist/installers/legacy-workbuddy-skill.js +168 -0
  225. package/release-manager/dist/installers/workbuddy-host-installer.js +7 -0
  226. package/release-manager/package.json +1 -1
  227. package/workbuddy-adapter/dist/pd-hook.js +20 -4
  228. package/workbuddy-adapter/package.json +1 -1
  229. package/workbuddy-adapter/plugin/skills/pd-pain-signal/SKILL.md +123 -20
@@ -24,12 +24,13 @@
24
24
  * for precise uninstall.
25
25
  */
26
26
  import { existsSync, readdirSync, readFileSync, writeFileSync } from 'fs';
27
- import { execSync } from 'child_process';
27
+ import { execSync, spawnSync } from 'child_process';
28
28
  import * as path from 'path';
29
29
  import * as os from 'os';
30
30
  import { createRequire } from 'module';
31
31
  import { pathToFileURL } from 'url';
32
32
  import { isNpmDependencyResolutionEnabled } from '../installer.js';
33
+ import { getPdRuntimeDir } from '../mvp-config.js';
33
34
  // NOTE (PRI-625 review round 3 / PRI-669 gate): this installer ships as the
34
35
  // self-contained npx package — @principles/core is NOT in its dependencies,
35
36
  // and type-only imports are erased at compile time, so the import above is
@@ -289,9 +290,335 @@ export function detectCodexMarketplaceState(codexHome) {
289
290
  }
290
291
  return { state: 'installed', version: best.dirName, versionDir: path.join(cachePluginRoot, best.dirName) };
291
292
  }
293
+ const RUNTIME_COMPONENT_DIRS = {
294
+ codexAdapter: 'codex-adapter',
295
+ hostRuntime: 'host-runtime',
296
+ core: 'core',
297
+ mcpServer: 'pd-mcp-server',
298
+ };
299
+ function readPackageVersion(pkgJsonPath) {
300
+ try {
301
+ const parsed = JSON.parse(readFileSync(pkgJsonPath, 'utf-8'));
302
+ if (!isRecord(parsed))
303
+ return undefined;
304
+ const value = parsed.version;
305
+ return typeof value === 'string' && value.length > 0 ? value : undefined;
306
+ }
307
+ catch {
308
+ return undefined;
309
+ }
310
+ }
311
+ function pinField(record, key) {
312
+ const value = record[key];
313
+ return typeof value === 'string' && value.length > 0 ? value : undefined;
314
+ }
315
+ function buildCohort(values) {
316
+ const { codexAdapter, hostRuntime, core, mcpServer } = values;
317
+ if (codexAdapter === undefined || hostRuntime === undefined || core === undefined || mcpServer === undefined) {
318
+ return undefined;
319
+ }
320
+ return { codexAdapter, hostRuntime, core, mcpServer };
321
+ }
322
+ /** The cohort a plugin payload declares in `<pluginRoot>/runtime-version.json`. */
323
+ export function readPinnedRuntimeCohort(pluginRoot) {
324
+ let parsed;
325
+ try {
326
+ parsed = JSON.parse(readFileSync(path.join(pluginRoot, 'runtime-version.json'), 'utf-8'));
327
+ }
328
+ catch {
329
+ return undefined;
330
+ }
331
+ if (!isRecord(parsed))
332
+ return undefined;
333
+ return buildCohort({
334
+ codexAdapter: pinField(parsed, 'codexAdapter'),
335
+ hostRuntime: pinField(parsed, 'hostRuntime'),
336
+ core: pinField(parsed, 'core'),
337
+ mcpServer: pinField(parsed, 'mcpServer'),
338
+ });
339
+ }
340
+ /** The canonical PD runtime's actual versions (`<runtimeDir>/<component>/package.json`). */
341
+ export function readCanonicalRuntimeCohort(runtimeDir) {
342
+ return buildCohort({
343
+ codexAdapter: readPackageVersion(path.join(runtimeDir, RUNTIME_COMPONENT_DIRS.codexAdapter, 'package.json')),
344
+ hostRuntime: readPackageVersion(path.join(runtimeDir, RUNTIME_COMPONENT_DIRS.hostRuntime, 'package.json')),
345
+ core: readPackageVersion(path.join(runtimeDir, RUNTIME_COMPONENT_DIRS.core, 'package.json')),
346
+ mcpServer: readPackageVersion(path.join(runtimeDir, RUNTIME_COMPONENT_DIRS.mcpServer, 'package.json')),
347
+ });
348
+ }
349
+ /** The cohort installed in PLUGIN_DATA (`<runtimeDir>/node_modules/<pkg>/package.json`). */
350
+ export function readInstalledRuntimeCohort(runtimeDir) {
351
+ const packageDirs = {
352
+ codexAdapter: '@principles/codex-adapter',
353
+ hostRuntime: '@principles/host-runtime',
354
+ core: '@principles/core',
355
+ mcpServer: '@principles/pd-mcp-server',
356
+ };
357
+ return buildCohort({
358
+ codexAdapter: readPackageVersion(path.join(runtimeDir, 'node_modules', packageDirs.codexAdapter, 'package.json')),
359
+ hostRuntime: readPackageVersion(path.join(runtimeDir, 'node_modules', packageDirs.hostRuntime, 'package.json')),
360
+ core: readPackageVersion(path.join(runtimeDir, 'node_modules', packageDirs.core, 'package.json')),
361
+ mcpServer: readPackageVersion(path.join(runtimeDir, 'node_modules', packageDirs.mcpServer, 'package.json')),
362
+ });
363
+ }
364
+ function semverParts(value) {
365
+ const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(value);
366
+ if (match === null)
367
+ return undefined;
368
+ const major = Number.parseInt(match[1] ?? '', 10);
369
+ const minor = Number.parseInt(match[2] ?? '', 10);
370
+ const patch = Number.parseInt(match[3] ?? '', 10);
371
+ return [major, minor, patch].every((n) => Number.isFinite(n)) ? [major, minor, patch] : undefined;
372
+ }
373
+ /** Numeric semver compare; unparsable values compare equal (never a guess). */
374
+ export function compareRuntimeVersions(a, b) {
375
+ const left = semverParts(a);
376
+ const right = semverParts(b);
377
+ if (left === undefined || right === undefined)
378
+ return 0;
379
+ for (let i = 0; i < 3; i += 1) {
380
+ const diff = (left[i] ?? 0) - (right[i] ?? 0);
381
+ if (diff !== 0)
382
+ return diff;
383
+ }
384
+ return 0;
385
+ }
386
+ /** True when ANY pinned component is older than the target cohort. */
387
+ export function isRuntimeCohortBehind(pin, target) {
388
+ const keys = ['codexAdapter', 'hostRuntime', 'core', 'mcpServer'];
389
+ return keys.some((key) => compareRuntimeVersions(pin[key], target[key]) < 0);
390
+ }
391
+ export function cohortsEqual(left, right) {
392
+ const keys = ['codexAdapter', 'hostRuntime', 'core', 'mcpServer'];
393
+ return keys.every((key) => compareRuntimeVersions(left[key], right[key]) === 0);
394
+ }
395
+ export function describeRuntimeCohort(cohort) {
396
+ return `codex-adapter@${cohort.codexAdapter} host-runtime@${cohort.hostRuntime} core@${cohort.core} mcp-server@${cohort.mcpServer}`;
397
+ }
398
+ /** `<home>/plugins/cache/<marketplace>/principles-disciple/<version>` → marketplace name. */
399
+ function deriveMarketplaceName(versionDir) {
400
+ const marketplace = path.basename(path.dirname(path.dirname(versionDir)));
401
+ return /^[A-Za-z0-9._-]+$/.test(marketplace) ? marketplace : undefined;
402
+ }
403
+ /**
404
+ * True when `file` must be dispatched through the Windows command processor.
405
+ *
406
+ * Only a BARE command name needs it: `codex` on Windows is a `.cmd`/`.ps1`
407
+ * shim that CreateProcess cannot execute directly. An executable PATH —
408
+ * absolute, drive-qualified or containing a separator — must be spawned
409
+ * directly, because `shell: true` lets Node join the command line WITHOUT
410
+ * quoting the executable: `D:\Program Files\nodejs\node.exe` reaches cmd.exe as
411
+ * `D:\Program` and the child never starts (regression from #2505, which made
412
+ * `runRuntimeSetup` pass `process.execPath`).
413
+ */
414
+ function shouldUseShell(file) {
415
+ if (process.platform !== 'win32')
416
+ return false;
417
+ if (path.win32.isAbsolute(file))
418
+ return false;
419
+ return !/[\\/]/.test(file);
420
+ }
421
+ /**
422
+ * Default command runner. `codex` on Windows is a `.cmd`/`.ps1` shim that
423
+ * CreateProcess cannot execute directly, so it goes through the command
424
+ * processor; every argument on that path is a validated literal
425
+ * (marketplace name `/^[A-Za-z0-9._-]+$/`, no whitespace), never user input.
426
+ * Executable paths are spawned directly so a space in the path cannot split
427
+ * the command line.
428
+ */
429
+ function defaultRunCommand(file, args, timeoutMs) {
430
+ const result = spawnSync(file, [...args], {
431
+ encoding: 'utf-8',
432
+ timeout: timeoutMs,
433
+ windowsHide: true,
434
+ shell: shouldUseShell(file),
435
+ });
436
+ const stderr = typeof result.stderr === 'string' ? result.stderr.trim() : '';
437
+ const error = result.error instanceof Error ? result.error.message : undefined;
438
+ const ok = result.status === 0 && error === undefined;
439
+ const detail = stderr.length > 0 ? stderr.slice(-400) : error;
440
+ return { ok, ...(detail === undefined ? {} : { detail }) };
441
+ }
442
+ /**
443
+ * Resolve Codex's PLUGIN_DATA root. ensurePluginData creates
444
+ * `<home>/plugins/data/principles-disciple-<marketplace>`, and Codex sets
445
+ * PLUGIN_DATA for hooks but never creates the directory, so an existing single
446
+ * match wins; otherwise the caller's derived path is used (first-run create).
447
+ */
448
+ export function resolvePluginDataRoot(codexHome, marketplace) {
449
+ const dataRoot = path.join(codexHome, 'plugins', 'data');
450
+ try {
451
+ const entries = readdirSync(dataRoot);
452
+ const matches = entries.filter((entry) => entry.startsWith('principles-disciple-'));
453
+ if (matches.length === 1) {
454
+ const [only] = matches;
455
+ return only === undefined ? undefined : path.join(dataRoot, only);
456
+ }
457
+ }
458
+ catch {
459
+ // Not created yet — the derived path below is the first-run target.
460
+ }
461
+ return /^[A-Za-z0-9._-]+$/.test(marketplace) ? path.join(dataRoot, `principles-disciple-${marketplace}`) : undefined;
462
+ }
292
463
  // ─── CodexHostInstaller ─────────────────────────────────────────────────────
293
464
  export class CodexHostInstaller {
294
465
  hostId = 'codex';
466
+ deps;
467
+ constructor(deps = {}) {
468
+ this.deps = deps;
469
+ }
470
+ codexHome() {
471
+ return this.deps.codexHome ?? getCodexDir();
472
+ }
473
+ /**
474
+ * Run `codex plugin add <plugin>@<marketplace>`. Re-adding an installed
475
+ * plugin is the host's own in-place refresh path — no uninstall/remove is
476
+ * involved (Owner requirement 2026-11-11).
477
+ */
478
+ runMarketplaceAdd(marketplace) {
479
+ const args = ['plugin', 'add', `principles-disciple@${marketplace}`];
480
+ const run = this.deps.runCommand ?? defaultRunCommand;
481
+ return run('codex', args, 120_000);
482
+ }
483
+ /**
484
+ * Materialize the payload's pinned runtime in PLUGIN_DATA through the
485
+ * plugin's EXISTING setup authority (scripts/pd-setup.cjs). `--skip-init`
486
+ * and `--ingest skip` keep this a runtime/binding repair: no workspace
487
+ * initialization, no consent decision, no interactive prompt.
488
+ */
489
+ runRuntimeSetup(pluginRoot, pluginDataRoot, workspaceDir) {
490
+ const setupEntry = path.join(pluginRoot, 'scripts', 'pd-setup.cjs');
491
+ const args = [
492
+ setupEntry,
493
+ '--plugin-root', pluginRoot,
494
+ '--plugin-data', pluginDataRoot,
495
+ '--workspace', workspaceDir,
496
+ '--skip-init',
497
+ '--ingest', 'skip',
498
+ '--json',
499
+ ];
500
+ const run = this.deps.runCommand ?? defaultRunCommand;
501
+ return run(process.execPath, args, 600_000);
502
+ }
503
+ /**
504
+ * Reconcile an installed Marketplace plugin with the PD release being
505
+ * installed:
506
+ * 1. payload: refresh the cache in place when its pins trail the canonical
507
+ * runtime (`codex plugin add`, no uninstall);
508
+ * 2. runtime: install the payload's own pins into PLUGIN_DATA when they
509
+ * differ (pd-setup.cjs — the single runtime materialization authority).
510
+ * Every unverifiable/unreachable step is reported with reason + nextAction,
511
+ * never silently swallowed (rc-9).
512
+ */
513
+ reconcileInstalledPlugin(marketplace, ctx) {
514
+ const notes = [];
515
+ const marketplaceName = deriveMarketplaceName(marketplace.versionDir);
516
+ if (marketplaceName === undefined) {
517
+ return {
518
+ success: false,
519
+ hostId: this.hostId,
520
+ configAction: 'skipped',
521
+ manualActionRequired: true,
522
+ reason: `The Codex Marketplace cache path does not expose a usable marketplace name: ${marketplace.versionDir}`,
523
+ nextAction: 'Re-add the Marketplace and plugin: codex plugin marketplace add <owner/repo>, then codex plugin add principles-disciple@<marketplace>.',
524
+ };
525
+ }
526
+ const canonicalRuntimeDir = this.deps.canonicalRuntimeDir ?? getPdRuntimeDir();
527
+ const canonical = readCanonicalRuntimeCohort(canonicalRuntimeDir);
528
+ const pinBefore = readPinnedRuntimeCohort(marketplace.versionDir);
529
+ let current = { version: marketplace.version, versionDir: marketplace.versionDir };
530
+ let payloadRefreshed = false;
531
+ if (canonical === undefined || pinBefore === undefined) {
532
+ // Not a failure of this installer: the cached payload may still be
533
+ // current. But freshness is UNVERIFIABLE, so say so instead of printing
534
+ // the old "already installed" comfort line (Owner requirement 3).
535
+ notes.push(canonical === undefined
536
+ ? `payload freshness is unverifiable: the canonical PD runtime was not readable at ${canonicalRuntimeDir}`
537
+ : `payload freshness is unverifiable: ${path.join(current.versionDir, 'runtime-version.json')} is unreadable`);
538
+ }
539
+ else if (isRuntimeCohortBehind(pinBefore, canonical)) {
540
+ const refresh = this.runMarketplaceAdd(marketplaceName);
541
+ if (!refresh.ok) {
542
+ return {
543
+ success: false,
544
+ hostId: this.hostId,
545
+ configAction: 'skipped',
546
+ manualActionRequired: true,
547
+ reason: `The installed Codex plugin (cache ${current.version}, pinned ${describeRuntimeCohort(pinBefore)}) is behind the PD release being installed (${describeRuntimeCohort(canonical)}), and the in-place refresh failed${refresh.detail === undefined ? '' : `: ${refresh.detail}`}.`,
548
+ nextAction: `Run "codex plugin add principles-disciple@${marketplaceName}" (no uninstall needed) and re-run this installer — the installer then aligns the plugin runtime with the refreshed pin.`,
549
+ };
550
+ }
551
+ const after = detectCodexMarketplaceState(this.codexHome());
552
+ if (after.state === 'installed') {
553
+ current = { version: after.version, versionDir: after.versionDir };
554
+ }
555
+ payloadRefreshed = true;
556
+ notes.push(`payload refreshed ${marketplace.version} → ${current.version}`);
557
+ }
558
+ else {
559
+ notes.push(`payload ${current.version} is current for the installed PD release`);
560
+ }
561
+ const pin = readPinnedRuntimeCohort(current.versionDir);
562
+ if (pin === undefined) {
563
+ // A payload whose pin cannot be read is left exactly as it is — the
564
+ // installer must not guess a runtime cohort. Freshness is reported as
565
+ // UNVERIFIED rather than as "already installed" (rc-9 / requirement 3).
566
+ notes.push(`runtime pin unreadable in ${current.versionDir} — runtime alignment unverified`);
567
+ return {
568
+ success: true,
569
+ hostId: this.hostId,
570
+ configPath: current.versionDir,
571
+ configAction: payloadRefreshed ? 'updated' : 'preserved',
572
+ reason: `Codex Marketplace plugin ${current.version}: ${notes.join('; ')}.`,
573
+ nextAction: 'Verify manually with pd-status; reinstall the payload with codex plugin add principles-disciple@'
574
+ + `${marketplaceName} if the runtime pin stays unreadable (no uninstall needed).`,
575
+ };
576
+ }
577
+ const pluginDataRoot = resolvePluginDataRoot(this.codexHome(), marketplaceName);
578
+ if (pluginDataRoot === undefined) {
579
+ return {
580
+ success: false,
581
+ hostId: this.hostId,
582
+ configAction: 'skipped',
583
+ manualActionRequired: true,
584
+ reason: `The Codex plugin data directory could not be resolved for marketplace "${marketplaceName}".`,
585
+ nextAction: 'Run: $pd-control setup — it reports the resolved plugin data path and installs the pinned runtime.',
586
+ };
587
+ }
588
+ const runtimeDir = path.join(pluginDataRoot, 'runtime');
589
+ const installed = readInstalledRuntimeCohort(runtimeDir);
590
+ let runtimeReconciled = false;
591
+ if (installed !== undefined && cohortsEqual(installed, pin)) {
592
+ notes.push(`runtime matches the payload pin (${describeRuntimeCohort(pin)})`);
593
+ }
594
+ else {
595
+ const setup = this.runRuntimeSetup(current.versionDir, pluginDataRoot, ctx.workspaceDir);
596
+ const verified = readInstalledRuntimeCohort(runtimeDir);
597
+ if (!setup.ok || verified === undefined || !cohortsEqual(verified, pin)) {
598
+ return {
599
+ success: false,
600
+ hostId: this.hostId,
601
+ configAction: 'skipped',
602
+ manualActionRequired: true,
603
+ reason: `The Codex plugin runtime in ${runtimeDir} does not match the payload pin (${describeRuntimeCohort(pin)}) and the automatic install did not verify${setup.detail === undefined ? '' : `: ${setup.detail}`}.`,
604
+ nextAction: 'Run: $pd-control setup — it installs the pinned runtime and verifies the exact bytes. If it also fails, check that npm is on PATH.',
605
+ };
606
+ }
607
+ runtimeReconciled = true;
608
+ notes.push(`runtime installed at the payload pin (${describeRuntimeCohort(pin)})`);
609
+ }
610
+ const updated = payloadRefreshed || runtimeReconciled;
611
+ return {
612
+ success: true,
613
+ hostId: this.hostId,
614
+ configPath: current.versionDir,
615
+ configAction: updated ? 'updated' : 'preserved',
616
+ reason: `Codex Marketplace plugin ${current.version}: ${notes.join('; ')}.`,
617
+ nextAction: updated
618
+ ? 'Start a new Codex session (or restart Codex) so the refreshed plugin and runtime load. Verify with pd-status afterwards.'
619
+ : 'Nothing to update. Start a Codex session and run the plugin setup ($pd-control setup) if conversation-ingestion consent is still pending.',
620
+ };
621
+ }
295
622
  /**
296
623
  * RETIRED for new registrations (Codex Governance Closure Slice D; SPEC rev
297
624
  * 2 §17 — the Marketplace plugin is the only supported new install path;
@@ -301,8 +628,13 @@ export class CodexHostInstaller {
301
628
  * structured refusal that points at the supported path, and when a legacy
302
629
  * PD global registration is detected it offers the explicit migration
303
630
  * route (precise uninstall → Marketplace plugin → $pd-control setup consent).
631
+ *
632
+ * UPDATE CHAIN (2026-11-11): for an already-installed Marketplace plugin
633
+ * this method now RECONCILES instead of reporting the old "already
634
+ * installed" comfort line — it refreshes a stale payload in place and
635
+ * installs the payload's own runtime pins into PLUGIN_DATA.
304
636
  */
305
- async install(_ctx) {
637
+ async install(ctx) {
306
638
  const hooksJsonPath = getCodexHooksJsonPath();
307
639
  const legacy = detectLegacyCodexHookRegistration();
308
640
  if (legacy.detected) {
@@ -319,15 +651,9 @@ export class CodexHostInstaller {
319
651
  // Marketplace contract (2026-11-07): the retired global-hook installer
320
652
  // never writes anything; the Codex end state is reported honestly in
321
653
  // three states and never executes the retired registration logic.
322
- const marketplace = detectCodexMarketplaceState();
654
+ const marketplace = detectCodexMarketplaceState(this.codexHome());
323
655
  if (marketplace.state === 'installed') {
324
- return {
325
- success: true,
326
- hostId: this.hostId,
327
- configAction: 'preserved',
328
- reason: `Codex Marketplace plugin already installed and confirmable (cache version ${marketplace.version}).`,
329
- nextAction: 'If not done yet, start a Codex session and run the plugin setup ($pd-control setup) — it verifies Node/runtime/workspace/trust and records the conversation-ingestion consent.',
330
- };
656
+ return this.reconcileInstalledPlugin(marketplace, ctx);
331
657
  }
332
658
  // 'not_installed' and 'unknown' both leave a manual step pending. They are
333
659
  // NOT failures of anything this installer attempted (it never writes), so
@@ -427,7 +753,6 @@ export class CodexHostInstaller {
427
753
  : 'Codex hooks uninstalled. Verify: open ~/.codex/hooks.json (should have no __pd_marker entries).',
428
754
  };
429
755
  }
430
- // eslint-disable-next-line @typescript-eslint/class-methods-use-this
431
756
  detect() {
432
757
  const markerPath = getPdHookMarkerPath();
433
758
  const hooksJsonPath = getCodexHooksJsonPath();
@@ -475,6 +800,20 @@ export class CodexHostInstaller {
475
800
  // Malformed hooks.json — treat as not installed (will be cleaned on uninstall)
476
801
  }
477
802
  }
803
+ // UPDATE CHAIN (2026-11-11): the supported install path is the Marketplace
804
+ // plugin, which leaves NO marker/hooks.json. Detection that only looked at
805
+ // the retired global-hook artifacts reported a Marketplace-only Codex as
806
+ // "not installed", so host auto-coverage skipped it.
807
+ const marketplace = detectCodexMarketplaceState(this.codexHome());
808
+ if (marketplace.state === 'installed') {
809
+ installed = true;
810
+ paths.push({
811
+ exists: true,
812
+ path: marketplace.versionDir,
813
+ name: `Codex Marketplace plugin ${marketplace.version}`,
814
+ type: 'dir',
815
+ });
816
+ }
478
817
  return { installed, paths };
479
818
  }
480
819
  }
@@ -1,6 +1,9 @@
1
+ import { existsSync } from 'fs';
2
+ import * as path from 'path';
3
+ import * as os from 'os';
1
4
  import { OpenClawHostInstaller } from './openclaw-host-installer.js';
2
5
  import { CodexHostInstaller } from './codex-host-installer.js';
3
- import { WorkBuddyHostInstaller } from './workbuddy-host-installer.js';
6
+ import { WorkBuddyHostInstaller, readWorkbuddyHostState } from './workbuddy-host-installer.js';
4
7
  export { OpenClawHostInstaller } from './openclaw-host-installer.js';
5
8
  export { CodexHostInstaller } from './codex-host-installer.js';
6
9
  export { WorkBuddyHostInstaller } from './workbuddy-host-installer.js';
@@ -41,4 +44,38 @@ export function getHostInstallers(target) {
41
44
  return [new OpenClawHostInstaller(), new CodexHostInstaller()];
42
45
  }
43
46
  }
47
+ /**
48
+ * Detect which hosts on THIS machine already carry a PD install (update chain,
49
+ * 2026-11-11).
50
+ *
51
+ * Why this exists: `--host` defaulted to 'openclaw' and the install manifest
52
+ * only refreshed hosts PD had recorded before. A host installed outside that
53
+ * manifest was silently left on the old release during an upgrade — the Owner
54
+ * had to uninstall/reinstall it by hand, which is not an acceptable update
55
+ * chain. The installer now unions this detection into its refresh targets.
56
+ *
57
+ * Detection is deliberately conservative: "the app directory exists" is NOT
58
+ * enough (WorkBuddy is opt-in, OD-03). Each entry requires PD's own footprint:
59
+ * - openclaw: the installed extension directory;
60
+ * - codex: a Marketplace cache / legacy PD hook registration;
61
+ * - workbuddy: PD registered in its plugin registry.
62
+ */
63
+ export function detectInstalledHosts(homeDir = os.homedir(), codexHome) {
64
+ const detected = [];
65
+ const openclawExtension = path.join(homeDir, '.openclaw', 'extensions', 'principles-disciple');
66
+ if (existsSync(openclawExtension)) {
67
+ detected.push({ hostId: 'openclaw', evidence: openclawExtension });
68
+ }
69
+ const codex = new CodexHostInstaller(codexHome === undefined ? {} : { codexHome }).detect();
70
+ if (codex.installed) {
71
+ const evidence = codex.paths.find((entry) => entry.exists && entry.name.startsWith('Codex Marketplace plugin'))
72
+ ?? codex.paths.find((entry) => entry.exists);
73
+ detected.push({ hostId: 'codex', evidence: evidence?.path ?? 'codex install detected' });
74
+ }
75
+ const workbuddy = readWorkbuddyHostState(homeDir);
76
+ if (workbuddy.pluginState !== undefined && workbuddy.pluginState.registryReadable && workbuddy.pluginState.registered) {
77
+ detected.push({ hostId: 'workbuddy', evidence: path.join(homeDir, '.workbuddy', 'plugins', 'installed_plugins.json') });
78
+ }
79
+ return detected;
80
+ }
44
81
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,168 @@
1
+ /**
2
+ * Legacy WorkBuddy user-level skill retirement
3
+ * (SPEC-PD-AGENT-PAIN-INGRESS-001 §5.5 / TECHNICAL-DESIGN §7.4).
4
+ *
5
+ * PD stopped shipping a user-level `pd-record-pain` skill; pain raised by an
6
+ * agent is now ingested through the governed host path. Old machines still
7
+ * carry `~/.workbuddy/skills/pd-record-pain/SKILL.md`, which keeps telling
8
+ * agents to write pain through the retired channel.
9
+ *
10
+ * Rules this module implements — and the reasons each one exists:
11
+ *
12
+ * 1. Detection is path + frontmatter `name`. A directory that happens to be
13
+ * called `pd-record-pain` but declares a different skill name is the
14
+ * Owner's own skill; it is never touched and never reported.
15
+ * 2. Only a copy whose bytes match a PUBLISHED skill payload may be renamed.
16
+ * The published payload hashes below are derived from this repository's
17
+ * git history (the exact blobs PD used to ship), so "unmodified" is proven
18
+ * rather than assumed.
19
+ * 3. A copy that does not match any published payload is left in place with a
20
+ * structured `deprecated_skill_modified` warning. Silent overwrite or
21
+ * deletion of Owner-modified files is forbidden (SPEC §5.5, AGENTS §18).
22
+ * 4. Renaming is idempotent: once `SKILL.md.deprecated-<label>` exists the
23
+ * skill directory is reported as already retired and is not touched again.
24
+ * 5. Nothing is deleted. The renamed file stays next to the original with a
25
+ * suffix that keeps it out of skill discovery.
26
+ */
27
+ import { createHash } from 'node:crypto';
28
+ import { existsSync, readdirSync, readFileSync, renameSync } from 'node:fs';
29
+ import * as path from 'node:path';
30
+ export const LEGACY_WORKBUDDY_SKILL_DIR = 'pd-record-pain';
31
+ export const LEGACY_WORKBUDDY_SKILL_FILE = 'SKILL.md';
32
+ /**
33
+ * Every `pd-record-pain/SKILL.md` payload this repository has ever shipped,
34
+ * recovered from git history (`git cat-file blob <blob>`). Both entries were
35
+ * deleted in 5c383e572 ("refactor(skills): unify PD host skill capabilities").
36
+ */
37
+ export const PUBLISHED_LEGACY_WORKBUDDY_SKILLS = [
38
+ {
39
+ label: '0.1.1-openclaw',
40
+ sha256: 'beb758bd66c6e330ff18bb751136a276d98486d85876b4488d09551b672d8186',
41
+ provenance: 'plugins/principles-disciple/skills/pd-record-pain/SKILL.md @ plugin 0.1.1 (blob 7df4717)',
42
+ },
43
+ {
44
+ label: '0.1.0-workbuddy',
45
+ sha256: 'f2eee21234250bf530a81579f033cda4fa41c0728bc81536320774127bd2d6e6',
46
+ provenance: 'packages/workbuddy-adapter/plugin/skills/pd-record-pain/SKILL.md @ plugin 0.1.0 (blob 7338fe8)',
47
+ },
48
+ ];
49
+ function frontmatterName(content) {
50
+ // Minimal, format-only parse: the skill frontmatter is a leading `---` block
51
+ // of `key: value` lines. We only need `name`, and a missing block is a
52
+ // non-match (rc-3: never guess a skill identity from the directory name).
53
+ const lines = content.split(/\r?\n/);
54
+ if (lines[0]?.trim() !== '---')
55
+ return undefined;
56
+ for (let i = 1; i < lines.length; i += 1) {
57
+ const line = lines[i] ?? '';
58
+ if (line.trim() === '---')
59
+ return undefined;
60
+ const match = /^name:\s*(.*)$/.exec(line);
61
+ if (match !== null)
62
+ return match[1]?.trim().replace(/^['"]|['"]$/g, '');
63
+ }
64
+ return undefined;
65
+ }
66
+ function sha256Of(bytes) {
67
+ return createHash('sha256').update(bytes).digest('hex');
68
+ }
69
+ function skillDir(configDir) {
70
+ return path.join(configDir, 'skills', LEGACY_WORKBUDDY_SKILL_DIR);
71
+ }
72
+ /**
73
+ * Read-only inspection. Never renames, never deletes.
74
+ *
75
+ * `published` is injectable so the rename branch can be exercised against a
76
+ * fixture; production callers always use the shipped registry.
77
+ */
78
+ export function inspectLegacyWorkbuddySkill(options) {
79
+ const publishedVersions = options.published ?? PUBLISHED_LEGACY_WORKBUDDY_SKILLS;
80
+ const dir = skillDir(options.configDir);
81
+ const skillPath = path.join(dir, LEGACY_WORKBUDDY_SKILL_FILE);
82
+ if (!existsSync(skillPath)) {
83
+ // Idempotency: a previously retired copy leaves only the suffixed file.
84
+ let deprecatedPath;
85
+ if (existsSync(dir)) {
86
+ const suffix = `${LEGACY_WORKBUDDY_SKILL_FILE}.deprecated-`;
87
+ const retired = readdirSync(dir).find((entry) => entry.startsWith(suffix));
88
+ if (retired !== undefined)
89
+ deprecatedPath = path.join(dir, retired);
90
+ }
91
+ return deprecatedPath === undefined
92
+ ? { status: 'absent', path: skillPath }
93
+ : { status: 'already_deprecated', path: skillPath, deprecatedPath };
94
+ }
95
+ const bytes = readFileSync(skillPath);
96
+ if (frontmatterName(bytes.toString('utf8')) !== LEGACY_WORKBUDDY_SKILL_DIR) {
97
+ // Same directory name, different declared skill: not ours to retire.
98
+ return { status: 'absent', path: skillPath };
99
+ }
100
+ const digest = sha256Of(bytes);
101
+ const published = publishedVersions.find((entry) => entry.sha256 === digest);
102
+ if (published === undefined) {
103
+ return {
104
+ status: 'modified',
105
+ path: skillPath,
106
+ sha256: digest,
107
+ nextAction: `This skill is no longer shipped by PD, but its content does not match any published version, ` +
108
+ `so it was left untouched. Review it, then delete ${dir} yourself if you did not customise it.`,
109
+ };
110
+ }
111
+ return {
112
+ status: 'deprecated',
113
+ path: skillPath,
114
+ deprecatedPath: `${skillPath}.deprecated-${published.label}`,
115
+ label: published.label,
116
+ };
117
+ }
118
+ /**
119
+ * Retire the legacy user-level skill when it is provably an unmodified PD
120
+ * payload. Safe to run on every install/upgrade: absent, already-retired and
121
+ * Owner-modified states are all no-ops.
122
+ */
123
+ export function deprecateLegacyWorkbuddySkill(options) {
124
+ const state = inspectLegacyWorkbuddySkill(options);
125
+ if (state.status === 'modified') {
126
+ return {
127
+ state,
128
+ warnings: [
129
+ 'WARNING [deprecated_skill_modified]: a retired user-level skill "pd-record-pain" was found but NOT modified ' +
130
+ `(${state.path}, sha256 ${state.sha256.slice(0, 12)}…) — its content matches no published version.`,
131
+ ` ${state.nextAction}`,
132
+ ],
133
+ };
134
+ }
135
+ if (state.status !== 'deprecated') {
136
+ return { state, warnings: [] };
137
+ }
138
+ try {
139
+ if (existsSync(state.deprecatedPath)) {
140
+ // Another published label already retired this directory. Keep both; the
141
+ // live SKILL.md is still the one the host would load, so report it.
142
+ return {
143
+ state,
144
+ warnings: [
145
+ `WARNING [legacy_skill_rename_failed]: retired skill "pd-record-pain" could not be renamed because ${state.deprecatedPath} already exists.`,
146
+ ` Move or delete ${state.path} yourself; skill discovery still sees it.`,
147
+ ],
148
+ };
149
+ }
150
+ renameSync(state.path, state.deprecatedPath);
151
+ }
152
+ catch (error) {
153
+ return {
154
+ state,
155
+ warnings: [
156
+ `WARNING [legacy_skill_rename_failed]: retired skill "pd-record-pain" could not be renamed (${error instanceof Error ? error.message : String(error)}).`,
157
+ ` Delete ${state.path} yourself; skill discovery still sees it.`,
158
+ ],
159
+ };
160
+ }
161
+ return {
162
+ state,
163
+ warnings: [
164
+ `Retired the obsolete user-level skill "pd-record-pain" (renamed to ${path.basename(state.deprecatedPath)}).`,
165
+ ],
166
+ };
167
+ }
168
+ //# sourceMappingURL=legacy-workbuddy-skill.js.map
@@ -66,6 +66,7 @@ export const WORKBUDDY_PLUGIN_KEY = `${WORKBUDDY_PLUGIN_NAME}@${WORKBUDDY_MARKET
66
66
  const WORKBUDDY_REQUIRED_SKILLS = ['pd-cli-operator', 'pd-pain-signal', 'pd-review', 'pd-control'];
67
67
  import { atomicReplaceTextFile, AtomicReplaceCleanupError, AtomicReplaceConflictError, errnoCode } from '../utils/config-file-io.js';
68
68
  import { checkMcpRegistrationConflict } from './mcp-registration-conflict.js';
69
+ import { deprecateLegacyWorkbuddySkill } from './legacy-workbuddy-skill.js';
69
70
  import { resolveMcpServerDir, resolveMcpServerEntry } from '../mcp-server-layout-compat.js';
70
71
  import { getHomeDir, generateConfigYamlContent, getConfigYamlPath, resolveDefaultModelForProvider, isValidHttpBaseUrl } from '../mvp-config.js';
71
72
  // Type-only import from @principles/core — erased at compile time; this
@@ -2553,11 +2554,17 @@ export class WorkBuddyHostInstaller {
2553
2554
  const pendingRebindNote = profilePendingAgents.length > 0
2554
2555
  ? ` Pending config: agent(s) ${profilePendingAgents.join(', ')} still bind to their explicit runtime profiles; to rebind them to the install profile, set internalAgents.agents.<name>.runtimeProfile to '${GOVERNANCE_PROFILE_ID}' (or remove the per-agent runtimeProfile row so they inherit internalAgents.defaultRuntime) in ${path.join(p.governanceDir, '.pd', 'config.yaml')}.`
2555
2556
  : '';
2557
+ // SPEC-PD-AGENT-PAIN-INGRESS-001 §5.5 / TD §7.4: retire the old user-level
2558
+ // `pd-record-pain` skill once per install/upgrade. Idempotent and
2559
+ // preservation-first: a copy that is not provably a published payload is
2560
+ // reported, never overwritten or deleted.
2561
+ const legacySkill = deprecateLegacyWorkbuddySkill({ configDir: p.configDir });
2556
2562
  return {
2557
2563
  success: true,
2558
2564
  hostId: this.hostId,
2559
2565
  configPath: p.settingsPath,
2560
2566
  configAction: registration.settingsAction,
2567
+ warnings: legacySkill.warnings.length > 0 ? legacySkill.warnings : undefined,
2561
2568
  pluginState: this.readInstalledPluginState(),
2562
2569
  governance: governanceDefaults === null
2563
2570
  ? undefined
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-principles-disciple",
3
- "version": "1.149.0",
3
+ "version": "1.150.1",
4
4
  "description": "Interactive CLI installer for Principles Disciple OpenClaw plugin",
5
5
  "type": "module",
6
6
  "bin": {