create-principles-disciple 1.152.5 → 1.153.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 (258) hide show
  1. package/_release/product-identity.json +1 -1
  2. package/agent-skill/pd-setup/SKILL.md +70 -0
  3. package/codex-adapter/dist/background-selection.d.ts +9 -0
  4. package/codex-adapter/dist/background-selection.js +142 -0
  5. package/codex-adapter/dist/ingestion/adaptive-append-state.d.ts +209 -0
  6. package/codex-adapter/dist/ingestion/adaptive-append-state.js +544 -0
  7. package/codex-adapter/dist/pd-hook.js +329 -5
  8. package/codex-adapter/package.json +1 -1
  9. package/console/dist/server/config/pd-config-store.d.ts +11 -15
  10. package/console/dist/server/config/pd-config-store.js +92 -17
  11. package/console/dist/server/models/ActivationsConsoleModel.d.ts +8 -0
  12. package/console/dist/server/models/ActivationsConsoleModel.js +3 -2
  13. package/console/dist/server/models/AdaptiveActivationConsoleModel.d.ts +43 -4
  14. package/console/dist/server/models/AdaptiveActivationConsoleModel.js +36 -7
  15. package/console/dist/server/models/ExaminerEvidenceModel.d.ts +6 -2
  16. package/console/dist/server/models/ExaminerEvidenceModel.js +13 -2
  17. package/console/dist/server/routes/config.js +34 -8
  18. package/console/dist/server/routes/examiner-executor.d.ts +33 -0
  19. package/console/dist/server/routes/examiner-executor.js +95 -0
  20. package/console/dist/server/routes/examiner.js +12 -9
  21. package/console/dist/web/assets/app.css +14 -10
  22. package/console/dist/web/assets/app.js +27 -27
  23. package/core/dist/ledger-file-lock.d.ts +38 -0
  24. package/core/dist/ledger-file-lock.d.ts.map +1 -0
  25. package/core/dist/ledger-file-lock.js +240 -0
  26. package/core/dist/ledger-file-lock.js.map +1 -0
  27. package/core/dist/principle-text-normalization.d.ts +32 -0
  28. package/core/dist/principle-text-normalization.d.ts.map +1 -0
  29. package/core/dist/principle-text-normalization.js +34 -0
  30. package/core/dist/principle-text-normalization.js.map +1 -0
  31. package/core/dist/principle-tree-ledger.d.ts +22 -21
  32. package/core/dist/principle-tree-ledger.d.ts.map +1 -1
  33. package/core/dist/principle-tree-ledger.js +77 -204
  34. package/core/dist/principle-tree-ledger.js.map +1 -1
  35. package/core/dist/runtime/activation/sqlite-approval-store.d.ts.map +1 -1
  36. package/core/dist/runtime/activation/sqlite-approval-store.js +7 -1
  37. package/core/dist/runtime/activation/sqlite-approval-store.js.map +1 -1
  38. package/core/dist/runtime/adapter/principle-tree-ledger-adapter.d.ts +13 -0
  39. package/core/dist/runtime/adapter/principle-tree-ledger-adapter.d.ts.map +1 -1
  40. package/core/dist/runtime/adapter/principle-tree-ledger-adapter.js +90 -1
  41. package/core/dist/runtime/adapter/principle-tree-ledger-adapter.js.map +1 -1
  42. package/core/dist/runtime/adapter/schema-prompt-adapter.d.ts.map +1 -1
  43. package/core/dist/runtime/adapter/schema-prompt-adapter.js +21 -30
  44. package/core/dist/runtime/adapter/schema-prompt-adapter.js.map +1 -1
  45. package/core/dist/runtime/candidate-intake-service.d.ts +40 -1
  46. package/core/dist/runtime/candidate-intake-service.d.ts.map +1 -1
  47. package/core/dist/runtime/candidate-intake-service.js +548 -110
  48. package/core/dist/runtime/candidate-intake-service.js.map +1 -1
  49. package/core/dist/runtime/candidate-intake.d.ts +59 -2
  50. package/core/dist/runtime/candidate-intake.d.ts.map +1 -1
  51. package/core/dist/runtime/candidate-intake.js +23 -0
  52. package/core/dist/runtime/candidate-intake.js.map +1 -1
  53. package/core/dist/runtime/candidate-seed-suppression.d.ts +63 -0
  54. package/core/dist/runtime/candidate-seed-suppression.d.ts.map +1 -0
  55. package/core/dist/runtime/candidate-seed-suppression.js +29 -0
  56. package/core/dist/runtime/candidate-seed-suppression.js.map +1 -0
  57. package/core/dist/runtime/config/pd-config-agent-binding.d.ts +5 -5
  58. package/core/dist/runtime/config/pd-config-agent-binding.d.ts.map +1 -1
  59. package/core/dist/runtime/config/pd-config-agent-binding.js +22 -16
  60. package/core/dist/runtime/config/pd-config-agent-binding.js.map +1 -1
  61. package/core/dist/runtime/config/pd-config-feature-flags.d.ts +10 -0
  62. package/core/dist/runtime/config/pd-config-feature-flags.d.ts.map +1 -1
  63. package/core/dist/runtime/config/pd-config-feature-flags.js +14 -0
  64. package/core/dist/runtime/config/pd-config-feature-flags.js.map +1 -1
  65. package/core/dist/runtime/config/pd-config-types.d.ts +9 -0
  66. package/core/dist/runtime/config/pd-config-types.d.ts.map +1 -1
  67. package/core/dist/runtime/config/pd-config-types.js.map +1 -1
  68. package/core/dist/runtime/config/pd-config-validate.d.ts.map +1 -1
  69. package/core/dist/runtime/config/pd-config-validate.js +10 -2
  70. package/core/dist/runtime/config/pd-config-validate.js.map +1 -1
  71. package/core/dist/runtime/config/pd-credentials.d.ts.map +1 -1
  72. package/core/dist/runtime/config/pd-credentials.js +7 -1
  73. package/core/dist/runtime/config/pd-credentials.js.map +1 -1
  74. package/core/dist/runtime/diagnostician/distiller-prompt-builder.d.ts.map +1 -1
  75. package/core/dist/runtime/diagnostician/distiller-prompt-builder.js +30 -3
  76. package/core/dist/runtime/diagnostician/distiller-prompt-builder.js.map +1 -1
  77. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.d.ts.map +1 -1
  78. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.js +16 -5
  79. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.js.map +1 -1
  80. package/core/dist/runtime/diagnostician/router-prompt-builder.d.ts.map +1 -1
  81. package/core/dist/runtime/diagnostician/router-prompt-builder.js +16 -4
  82. package/core/dist/runtime/diagnostician/router-prompt-builder.js.map +1 -1
  83. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.d.ts.map +1 -1
  84. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js +13 -2
  85. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js.map +1 -1
  86. package/core/dist/runtime/index.d.ts +4 -2
  87. package/core/dist/runtime/index.d.ts.map +1 -1
  88. package/core/dist/runtime/index.js +3 -1
  89. package/core/dist/runtime/index.js.map +1 -1
  90. package/core/dist/runtime/intent/intent-doc.d.ts +22 -0
  91. package/core/dist/runtime/intent/intent-doc.d.ts.map +1 -1
  92. package/core/dist/runtime/intent/intent-doc.js +79 -0
  93. package/core/dist/runtime/intent/intent-doc.js.map +1 -1
  94. package/core/dist/runtime/intent/intent-friction-block.d.ts +7 -0
  95. package/core/dist/runtime/intent/intent-friction-block.d.ts.map +1 -1
  96. package/core/dist/runtime/intent/intent-friction-block.js +34 -1
  97. package/core/dist/runtime/intent/intent-friction-block.js.map +1 -1
  98. package/core/dist/runtime/intent/intent-snapshot.d.ts +44 -5
  99. package/core/dist/runtime/intent/intent-snapshot.d.ts.map +1 -1
  100. package/core/dist/runtime/intent/intent-snapshot.js +83 -15
  101. package/core/dist/runtime/intent/intent-snapshot.js.map +1 -1
  102. package/core/dist/runtime/intent/strategic-conflict-gate.d.ts +19 -0
  103. package/core/dist/runtime/intent/strategic-conflict-gate.d.ts.map +1 -1
  104. package/core/dist/runtime/intent/strategic-conflict-gate.js +94 -26
  105. package/core/dist/runtime/intent/strategic-conflict-gate.js.map +1 -1
  106. package/core/dist/runtime/internalization/diag-rootcause-runner.d.ts +22 -11
  107. package/core/dist/runtime/internalization/diag-rootcause-runner.d.ts.map +1 -1
  108. package/core/dist/runtime/internalization/diag-rootcause-runner.js +101 -28
  109. package/core/dist/runtime/internalization/diag-rootcause-runner.js.map +1 -1
  110. package/core/dist/runtime/internalization/dreamer-prompt-builder.d.ts.map +1 -1
  111. package/core/dist/runtime/internalization/dreamer-prompt-builder.js +177 -28
  112. package/core/dist/runtime/internalization/dreamer-prompt-builder.js.map +1 -1
  113. package/core/dist/runtime/internalization/dreamer-runner.d.ts +9 -2
  114. package/core/dist/runtime/internalization/dreamer-runner.d.ts.map +1 -1
  115. package/core/dist/runtime/internalization/dreamer-runner.js +11 -1
  116. package/core/dist/runtime/internalization/dreamer-runner.js.map +1 -1
  117. package/core/dist/runtime/internalization/evaluator-runner.d.ts.map +1 -1
  118. package/core/dist/runtime/internalization/evaluator-runner.js +7 -0
  119. package/core/dist/runtime/internalization/evaluator-runner.js.map +1 -1
  120. package/core/dist/runtime/internalization/formation-context.d.ts +16 -0
  121. package/core/dist/runtime/internalization/formation-context.d.ts.map +1 -1
  122. package/core/dist/runtime/internalization/formation-context.js +109 -8
  123. package/core/dist/runtime/internalization/formation-context.js.map +1 -1
  124. package/core/dist/runtime/internalization/index.d.ts +2 -2
  125. package/core/dist/runtime/internalization/index.d.ts.map +1 -1
  126. package/core/dist/runtime/internalization/index.js +1 -1
  127. package/core/dist/runtime/internalization/index.js.map +1 -1
  128. package/core/dist/runtime/internalization/intent-contract.d.ts +55 -4
  129. package/core/dist/runtime/internalization/intent-contract.d.ts.map +1 -1
  130. package/core/dist/runtime/internalization/intent-contract.js +111 -30
  131. package/core/dist/runtime/internalization/intent-contract.js.map +1 -1
  132. package/core/dist/runtime/internalization/internalization-orchestrator.d.ts +16 -2
  133. package/core/dist/runtime/internalization/internalization-orchestrator.d.ts.map +1 -1
  134. package/core/dist/runtime/internalization/internalization-orchestrator.js +48 -14
  135. package/core/dist/runtime/internalization/internalization-orchestrator.js.map +1 -1
  136. package/core/dist/runtime/internalization/philosopher-prompt-builder.d.ts.map +1 -1
  137. package/core/dist/runtime/internalization/philosopher-prompt-builder.js +7 -6
  138. package/core/dist/runtime/internalization/philosopher-prompt-builder.js.map +1 -1
  139. package/core/dist/runtime/internalization/philosopher-runner.d.ts +9 -2
  140. package/core/dist/runtime/internalization/philosopher-runner.d.ts.map +1 -1
  141. package/core/dist/runtime/internalization/philosopher-runner.js +11 -1
  142. package/core/dist/runtime/internalization/philosopher-runner.js.map +1 -1
  143. package/core/dist/runtime/internalization/scribe-prompt-builder.d.ts +13 -6
  144. package/core/dist/runtime/internalization/scribe-prompt-builder.d.ts.map +1 -1
  145. package/core/dist/runtime/internalization/scribe-prompt-builder.js +15 -10
  146. package/core/dist/runtime/internalization/scribe-prompt-builder.js.map +1 -1
  147. package/core/dist/runtime/internalization/scribe-runner.d.ts.map +1 -1
  148. package/core/dist/runtime/internalization/scribe-runner.js +17 -7
  149. package/core/dist/runtime/internalization/scribe-runner.js.map +1 -1
  150. package/core/dist/runtime/pain-signal-bridge.d.ts +3 -0
  151. package/core/dist/runtime/pain-signal-bridge.d.ts.map +1 -1
  152. package/core/dist/runtime/pain-signal-bridge.js +224 -93
  153. package/core/dist/runtime/pain-signal-bridge.js.map +1 -1
  154. package/core/dist/runtime/pain-submit-capability.d.ts.map +1 -1
  155. package/core/dist/runtime/pain-submit-capability.js +3 -5
  156. package/core/dist/runtime/pain-submit-capability.js.map +1 -1
  157. package/core/dist/runtime/pain-to-principle-service.d.ts.map +1 -1
  158. package/core/dist/runtime/pain-to-principle-service.js +18 -21
  159. package/core/dist/runtime/pain-to-principle-service.js.map +1 -1
  160. package/core/dist/runtime/store/candidate/admission-document.d.ts +129 -0
  161. package/core/dist/runtime/store/candidate/admission-document.d.ts.map +1 -1
  162. package/core/dist/runtime/store/candidate/admission-document.js +196 -0
  163. package/core/dist/runtime/store/candidate/admission-document.js.map +1 -1
  164. package/core/dist/runtime/store/candidate/candidate-store.d.ts +54 -1
  165. package/core/dist/runtime/store/candidate/candidate-store.d.ts.map +1 -1
  166. package/core/dist/runtime/store/candidate/memory-candidate-store.d.ts +32 -1
  167. package/core/dist/runtime/store/candidate/memory-candidate-store.d.ts.map +1 -1
  168. package/core/dist/runtime/store/candidate/memory-candidate-store.js +24 -1
  169. package/core/dist/runtime/store/candidate/memory-candidate-store.js.map +1 -1
  170. package/core/dist/runtime/store/candidate/sqlite-candidate-store.d.ts +32 -1
  171. package/core/dist/runtime/store/candidate/sqlite-candidate-store.d.ts.map +1 -1
  172. package/core/dist/runtime/store/candidate/sqlite-candidate-store.js +76 -1
  173. package/core/dist/runtime/store/candidate/sqlite-candidate-store.js.map +1 -1
  174. package/core/dist/runtime/store/intent/sqlite-intent-decision-store.d.ts +10 -0
  175. package/core/dist/runtime/store/intent/sqlite-intent-decision-store.d.ts.map +1 -1
  176. package/core/dist/runtime/store/intent/sqlite-intent-decision-store.js +15 -4
  177. package/core/dist/runtime/store/intent/sqlite-intent-decision-store.js.map +1 -1
  178. package/core/dist/runtime/store/runtime-state-manager.d.ts +34 -1
  179. package/core/dist/runtime/store/runtime-state-manager.d.ts.map +1 -1
  180. package/core/dist/runtime/store/runtime-state-manager.js +10 -0
  181. package/core/dist/runtime/store/runtime-state-manager.js.map +1 -1
  182. package/core/dist/telemetry-event.d.ts +2 -2
  183. package/core/dist/telemetry-event.d.ts.map +1 -1
  184. package/core/dist/telemetry-event.js +6 -0
  185. package/core/dist/telemetry-event.js.map +1 -1
  186. package/core/package.json +1 -1
  187. package/dist/agent-skill.d.ts +59 -0
  188. package/dist/agent-skill.d.ts.map +1 -0
  189. package/dist/agent-skill.js +198 -0
  190. package/dist/agent-skill.js.map +1 -0
  191. package/dist/i18n.d.ts.map +1 -1
  192. package/dist/i18n.js +12 -0
  193. package/dist/i18n.js.map +1 -1
  194. package/dist/index.d.ts +3 -1
  195. package/dist/index.d.ts.map +1 -1
  196. package/dist/index.js +171 -3
  197. package/dist/index.js.map +1 -1
  198. package/dist/install-summary.d.ts +52 -0
  199. package/dist/install-summary.d.ts.map +1 -1
  200. package/dist/install-summary.js +104 -0
  201. package/dist/install-summary.js.map +1 -1
  202. package/host-runtime/dist/adaptive-background-append.d.ts +70 -0
  203. package/host-runtime/dist/adaptive-background-append.js +165 -0
  204. package/host-runtime/dist/governance-signal-admission.js +1 -5
  205. package/host-runtime/dist/index.d.ts +1 -0
  206. package/host-runtime/dist/index.js +5 -0
  207. package/host-runtime/package.json +1 -1
  208. package/package.json +3 -2
  209. package/pd-cli/dist/commands/candidate.d.ts.map +1 -1
  210. package/pd-cli/dist/commands/candidate.js +243 -28
  211. package/pd-cli/dist/commands/candidate.js.map +1 -1
  212. package/pd-cli/dist/commands/diagnose.d.ts.map +1 -1
  213. package/pd-cli/dist/commands/diagnose.js +110 -7
  214. package/pd-cli/dist/commands/diagnose.js.map +1 -1
  215. package/pd-cli/dist/commands/health-console.d.ts +21 -0
  216. package/pd-cli/dist/commands/health-console.d.ts.map +1 -0
  217. package/pd-cli/dist/commands/health-console.js +106 -0
  218. package/pd-cli/dist/commands/health-console.js.map +1 -0
  219. package/pd-cli/dist/commands/health.d.ts +159 -0
  220. package/pd-cli/dist/commands/health.d.ts.map +1 -1
  221. package/pd-cli/dist/commands/health.js +162 -2
  222. package/pd-cli/dist/commands/health.js.map +1 -1
  223. package/pd-cli/dist/commands/mcp-probe.d.ts +48 -0
  224. package/pd-cli/dist/commands/mcp-probe.d.ts.map +1 -0
  225. package/pd-cli/dist/commands/mcp-probe.js +479 -0
  226. package/pd-cli/dist/commands/mcp-probe.js.map +1 -0
  227. package/pd-cli/dist/commands/pain-retry.d.ts.map +1 -1
  228. package/pd-cli/dist/commands/pain-retry.js +3 -0
  229. package/pd-cli/dist/commands/pain-retry.js.map +1 -1
  230. package/pd-cli/dist/commands/runtime-internalization-run-once.d.ts.map +1 -1
  231. package/pd-cli/dist/commands/runtime-internalization-run-once.js +70 -4
  232. package/pd-cli/dist/commands/runtime-internalization-run-once.js.map +1 -1
  233. package/pd-cli/dist/program.d.ts.map +1 -1
  234. package/pd-cli/dist/program.js +68 -1
  235. package/pd-cli/dist/program.js.map +1 -1
  236. package/pd-cli/dist/services/admission-write-gate.d.ts.map +1 -1
  237. package/pd-cli/dist/services/admission-write-gate.js +18 -7
  238. package/pd-cli/dist/services/admission-write-gate.js.map +1 -1
  239. package/pd-cli/dist/services/console-launcher.d.ts +3 -0
  240. package/pd-cli/dist/services/console-launcher.d.ts.map +1 -1
  241. package/pd-cli/dist/services/console-launcher.js +3 -2
  242. package/pd-cli/dist/services/console-launcher.js.map +1 -1
  243. package/pd-cli/dist/services/demo-story-a-runner.d.ts.map +1 -1
  244. package/pd-cli/dist/services/demo-story-a-runner.js +8 -3
  245. package/pd-cli/dist/services/demo-story-a-runner.js.map +1 -1
  246. package/pd-cli/dist/services/reuse-park-release.d.ts +142 -0
  247. package/pd-cli/dist/services/reuse-park-release.d.ts.map +1 -0
  248. package/pd-cli/dist/services/reuse-park-release.js +201 -0
  249. package/pd-cli/dist/services/reuse-park-release.js.map +1 -0
  250. package/pd-cli/package.json +1 -1
  251. package/plugin/dist/bundle.js +914 -640
  252. package/plugin/dist/openclaw.plugin.json +1 -1
  253. package/plugin/openclaw.plugin.json +1 -1
  254. package/plugin/package.json +1 -1
  255. package/release-manager/dist/i18n.js +12 -0
  256. package/release-manager/package.json +2 -1
  257. package/workbuddy-adapter/dist/pd-hook.js +37 -3
  258. package/workbuddy-adapter/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "productVersion": "2.8.7",
4
- "sourceCommit": "6c259af4472f952e5e0e22f78a5288ac3600f2b1"
4
+ "sourceCommit": "5ebfebcc384368a6f68f62fdd539507a03fd1d4a"
5
5
  }
@@ -0,0 +1,70 @@
1
+ ---
2
+ name: pd-setup
3
+ description: Use when the Owner asks to install, set up, restart-after-install, or verify Principles Disciple (PD) on this machine. Covers host detection (OpenClaw / Codex / WorkBuddy), the one-command installer, per-host restart semantics, and the post-install acceptance loop (pd health / pd mcp probe). Do not use for daily PD operation after acceptance — that belongs to pd-cli-operator / pd-control.
4
+ ---
5
+ <!-- pd-agent-skill: pd-setup (owned by create-principles-disciple; safe to replace/remove via `npx create-principles-disciple agent-skill`) -->
6
+
7
+ <!-- Owner: create-principles-disciple (bootstrap channel). This skill is NOT
8
+ part of the plugin-delivered skill set (skill-catalog parity) — it is the
9
+ pre-install entry an agent has BEFORE PD exists on the machine. Canonical
10
+ guidance: README_AGENT.md / README_AGENT_EN.md at the repository root,
11
+ published at https://principles-website.pages.dev/install-agent.zh.md -->
12
+
13
+ # PD Setup(安装 · 重启 · 验收 / Install · Restart · Accept)
14
+
15
+ 你被问到"装 PD / 装 Principles Disciple"时,按本技能执行。完整权威指南(含排错表):
16
+ <https://principles-website.pages.dev/install-agent.zh.md>(英文:
17
+ <https://principles-website.pages.dev/install-agent.en.md>)。
18
+
19
+ ## 第 0 步 · 宿主自判 / Detect the host
20
+
21
+ | 线索 / Signal | 宿主 / Host |
22
+ |---|---|
23
+ | `~/.openclaw/` 存在 | OpenClaw |
24
+ | `~/.codex/`(或 `CODEX_HOME`)存在;有 `codex plugin` 命令 | Codex |
25
+ | `~/.workbuddy/` 存在 | WorkBuddy |
26
+ | 都不像 / none match | 按 OpenClaw 处理(安装器默认 / installer default) |
27
+
28
+ 前置 / Prerequisite: Node.js ≥ 22(`node -v`)。
29
+
30
+ ## 第 1 步 · 安装 / Install
31
+
32
+ ```bash
33
+ # OpenClaw(默认 / default)
34
+ npx create-principles-disciple --yes
35
+
36
+ # Codex
37
+ npx create-principles-disciple --host codex --yes
38
+
39
+ # WorkBuddy
40
+ npx create-principles-disciple --host workbuddy --yes
41
+ ```
42
+
43
+ - 可加 `--provider openai --api-key-env OPENAI_API_KEY --model <id>` 一次配好 LLM(`--api-key-env` 是环境变量**名**,不是密钥)。
44
+ - 机器可读:加 `--json`,成功输出的 `postInstall` 块含逐宿主 `verifyCommand`。
45
+ - Codex 若返回 `manualActions`:这些命令你自己执行——`codex plugin marketplace add csuzngjh/principles` → `codex plugin add principles-disciple@principles` → 会话内 `$pd-control setup` → `/hooks` 信任 → 重跑安装器收敛。
46
+ - WorkBuddy:装完在插件管理里**启用** PD(全新安装默认未启用)。
47
+
48
+ ## 第 2 步 · 重启语义 / Restart semantics
49
+
50
+ | 宿主 / Host | 动作 / Action |
51
+ |---|---|
52
+ | OpenClaw | 安装器已自动重启网关;仅当提示失败时手动 `openclaw gateway start` |
53
+ | Codex | **开新会话**(或重启 Codex);`/hooks` 信任 |
54
+ | WorkBuddy | **开新会话**(或 `/reload-plugins`);确认插件已启用 |
55
+
56
+ ## 第 3 步 · 验收 / Acceptance loop
57
+
58
+ ```bash
59
+ pd health --workspace "<工作区 / workspace>" --json # summary.* 逐项看,非 ok 项按 nextAction 行动
60
+ pd mcp probe --workspace "<工作区 / workspace>" --json # MCP 活体探针(握手 + 契约工具)
61
+ ```
62
+
63
+ - `summary.overall` = `healthy` 才算装好;`attention`/`error` 按 `nextAction` 修复后复跑。
64
+ - `pd` 不在 PATH 时用绝对路径 `~/.pd/runtime/bin/pd`(Windows:`pd.cmd`)。
65
+ - 控制台:`pd console open --workspace "<path>"`(owner 审核原则的界面)。
66
+
67
+ ## 边界 / Boundaries
68
+
69
+ - 不要代 Owner 做审批决定;不要手改 `.pd/config.yaml`、`.principles/`、`.state/`。
70
+ - 验收通过后的日常运维走 `pd-cli-operator` / `pd-control` 技能(若已安装)。
@@ -0,0 +1,9 @@
1
+ export type BackgroundSelectionJobResult = {
2
+ readonly status: 'selected';
3
+ readonly activationId: string;
4
+ } | {
5
+ readonly status: 'skipped' | 'unavailable' | 'invalid';
6
+ readonly reason: string;
7
+ };
8
+ /** Test seam: execute one job without the process boundary. */
9
+ export declare function runBackgroundSelectionJob(jobPath: string): Promise<BackgroundSelectionJobResult>;
@@ -0,0 +1,142 @@
1
+ /**
2
+ * PRI-1196 — detached background selector for the Codex host.
3
+ *
4
+ * argv[2] is a single-use job file written by the UserPromptSubmit hook after
5
+ * the Native body was already encoded. The job carries the current prompt ONLY
6
+ * so the SAME decision protocol can run; it is deleted before any network I/O.
7
+ * This process never writes to the host's stdout/stderr (`stdio: 'ignore'`).
8
+ */
9
+ import path from 'node:path';
10
+ import { fileURLToPath } from 'node:url';
11
+ import { runAdaptiveBackgroundSelection } from '@principles/host-runtime';
12
+ import { ADAPTIVE_APPEND_SCHEMA_VERSION, ADAPTIVE_APPEND_TTL_MS, adaptiveTurnEnded, appendAdaptiveAppendFact, discardAdaptiveAppendResult, takeAdaptiveAppendJob, writeAdaptiveAppendResultFor, } from './ingestion/adaptive-append-state.js';
13
+ function stateDirOf(workspaceDir) {
14
+ return path.join(workspaceDir, '.state');
15
+ }
16
+ function factCode(outcomeStatus, reason) {
17
+ if (outcomeStatus === 'needs_setup')
18
+ return `needs_setup:${reason}`.slice(0, 240);
19
+ return `skipped:background_${reason}`.slice(0, 240);
20
+ }
21
+ async function execute(job) {
22
+ const startedAt = Date.now();
23
+ const handoff = { workspaceDir: job.workspaceDir, sessionId: job.sessionId, turnId: job.turnId };
24
+ // Stop already ended this turn: a decision now cannot reach it.
25
+ if (adaptiveTurnEnded(handoff))
26
+ return { status: 'skipped', reason: 'turn_ended' };
27
+ const deadlineAt = job.createdAt + ADAPTIVE_APPEND_TTL_MS - 1000;
28
+ if (startedAt >= deadlineAt) {
29
+ appendAdaptiveAppendFact({
30
+ stateDir: stateDirOf(job.workspaceDir),
31
+ sessionId: job.sessionId,
32
+ turnId: job.turnId,
33
+ workspaceDir: job.workspaceDir,
34
+ resultCode: 'skipped:background_expired',
35
+ scored: false,
36
+ budget: job.budgetChars,
37
+ injectedCharCount: 0,
38
+ });
39
+ return { status: 'skipped', reason: 'expired' };
40
+ }
41
+ const outcome = await runAdaptiveBackgroundSelection({
42
+ workspaceDir: job.workspaceDir,
43
+ sessionId: job.sessionId,
44
+ turnId: job.turnId,
45
+ promptContent: job.promptContent,
46
+ nativeActivationIds: job.nativeActivationIds,
47
+ nativeChars: job.nativeChars,
48
+ budgetChars: job.budgetChars,
49
+ deadlineAt,
50
+ env: process.env,
51
+ });
52
+ const scored = outcome.diagnostic.sends > 0;
53
+ // Re-check after the decision: Stop or a new turn may have landed meanwhile.
54
+ if (adaptiveTurnEnded(handoff))
55
+ return { status: 'skipped', reason: 'turn_ended' };
56
+ if (outcome.status === 'selected') {
57
+ writeAdaptiveAppendResultFor(job.workspaceDir, {
58
+ schemaVersion: ADAPTIVE_APPEND_SCHEMA_VERSION,
59
+ createdAt: Date.now(),
60
+ startedAt: job.createdAt,
61
+ sessionId: job.sessionId,
62
+ turnId: job.turnId,
63
+ target: outcome.target,
64
+ directiveChars: outcome.directive.length,
65
+ nativeActivationIds: [...job.nativeActivationIds],
66
+ nativeChars: job.nativeChars,
67
+ budgetChars: job.budgetChars,
68
+ hookIdentity: job.hookIdentity,
69
+ });
70
+ // Close the Stop-vs-write race: if the turn ended while the result was
71
+ // being written, withdraw it so an ended turn never keeps a ready result.
72
+ if (adaptiveTurnEnded(handoff)) {
73
+ discardAdaptiveAppendResult(job.workspaceDir, job.sessionId, job.turnId);
74
+ return { status: 'skipped', reason: 'turn_ended' };
75
+ }
76
+ // "Background selected" is recorded separately from the eventual append:
77
+ // no activationIds here, so this line never claims an injection.
78
+ appendAdaptiveAppendFact({
79
+ stateDir: stateDirOf(job.workspaceDir),
80
+ sessionId: job.sessionId,
81
+ turnId: job.turnId,
82
+ workspaceDir: job.workspaceDir,
83
+ resultCode: 'selected:background_ready',
84
+ scored,
85
+ budget: job.budgetChars,
86
+ injectedCharCount: 0,
87
+ });
88
+ return { status: 'selected', activationId: outcome.target.activationId };
89
+ }
90
+ appendAdaptiveAppendFact({
91
+ stateDir: stateDirOf(job.workspaceDir),
92
+ sessionId: job.sessionId,
93
+ turnId: job.turnId,
94
+ workspaceDir: job.workspaceDir,
95
+ resultCode: factCode(outcome.diagnostic.status, outcome.reason),
96
+ scored,
97
+ budget: job.budgetChars,
98
+ injectedCharCount: 0,
99
+ });
100
+ return { status: outcome.status, reason: outcome.reason };
101
+ }
102
+ /** Test seam: execute one job without the process boundary. */
103
+ export async function runBackgroundSelectionJob(jobPath) {
104
+ const job = takeAdaptiveAppendJob(jobPath);
105
+ if (!job)
106
+ return { status: 'invalid', reason: 'job_unreadable' };
107
+ return execute(job);
108
+ }
109
+ const [, entryPath, jobPath] = process.argv;
110
+ const isMain = typeof entryPath === 'string'
111
+ && path.resolve(entryPath) === fileURLToPath(import.meta.url)
112
+ && jobPath !== undefined;
113
+ if (isMain && jobPath !== undefined) {
114
+ // The job is withdrawn ONCE. The failure fact below reuses this object: the
115
+ // old catch re-read the already-deleted file, so a thrown decision could
116
+ // never record `skipped:background_selection_failed` (it was dead code).
117
+ const job = takeAdaptiveAppendJob(jobPath);
118
+ if (job !== null) {
119
+ try {
120
+ await execute(job);
121
+ }
122
+ catch {
123
+ // A detached selector that throws must still leave the turn on Native.
124
+ // No raw error crosses into the host or the evidence log.
125
+ try {
126
+ appendAdaptiveAppendFact({
127
+ stateDir: stateDirOf(job.workspaceDir),
128
+ sessionId: job.sessionId,
129
+ turnId: job.turnId,
130
+ workspaceDir: job.workspaceDir,
131
+ resultCode: 'skipped:background_selection_failed',
132
+ scored: false,
133
+ budget: job.budgetChars,
134
+ injectedCharCount: 0,
135
+ });
136
+ }
137
+ catch {
138
+ // Nothing else can be done without risking the host; the turn is Native.
139
+ }
140
+ }
141
+ }
142
+ }
@@ -0,0 +1,209 @@
1
+ import type { AdaptiveAppendTargetRef } from '@principles/host-runtime';
2
+ export declare const ADAPTIVE_APPEND_SCHEMA_VERSION = 1;
3
+ /** Whole-turn window for a background decision to still be usable. */
4
+ export declare const ADAPTIVE_APPEND_TTL_MS = 20000;
5
+ /** Residue bound for files an abnormal exit left behind. */
6
+ export declare const ADAPTIVE_APPEND_MAX_AGE_MS: number;
7
+ /** Maximum complete turn history accepted at the append boundary. */
8
+ export declare const ADAPTIVE_APPEND_MAX_OBSERVATIONS = 64;
9
+ /**
10
+ * Turn-scoped "track this turn" marker. Written once at UserPromptSubmit,
11
+ * before the selector can withdraw the job, so the ordering gate keeps
12
+ * observing Pre/PostToolUse for the whole scoring window.
13
+ *
14
+ * The return value is also the "at most one scoring request per turn" gate:
15
+ * `exists` means a replayed prompt for the same turn must not spawn again.
16
+ */
17
+ export declare function markAdaptiveTurnStarted(input: {
18
+ workspaceDir: string;
19
+ sessionId: string;
20
+ turnId: string;
21
+ }): 'created' | 'exists' | 'failed';
22
+ /** True while this turn may still record observations or has a decision artifact. */
23
+ export declare function hasAdaptiveAppendTurn(input: {
24
+ workspaceDir: string;
25
+ sessionId: string;
26
+ turnId: string;
27
+ }): boolean;
28
+ /**
29
+ * Mark the turn as finished before the cleanup. A background selector that
30
+ * finishes after Stop checks this marker and discards its decision, so a
31
+ * late result can never surface as this turn's outcome.
32
+ */
33
+ export declare function markAdaptiveTurnEnded(input: {
34
+ workspaceDir: string;
35
+ sessionId: string;
36
+ turnId: string;
37
+ }): void;
38
+ export declare function adaptiveTurnEnded(input: {
39
+ workspaceDir: string;
40
+ sessionId: string;
41
+ turnId: string;
42
+ }): boolean;
43
+ export interface AdaptiveAppendHookIdentity {
44
+ readonly entryPath: string;
45
+ readonly mtimeMs: number;
46
+ }
47
+ /** The installed hook entry of the process that wrote the job. */
48
+ export declare function currentHookIdentity(): AdaptiveAppendHookIdentity | null;
49
+ export interface AdaptiveAppendJob {
50
+ readonly schemaVersion: number;
51
+ readonly createdAt: number;
52
+ readonly sessionId: string;
53
+ readonly turnId: string;
54
+ readonly workspaceDir: string;
55
+ readonly promptContent: string;
56
+ readonly nativeActivationIds: string[];
57
+ readonly nativeChars: number;
58
+ readonly budgetChars: number;
59
+ readonly hookIdentity: AdaptiveAppendHookIdentity | null;
60
+ }
61
+ /** rc-1/rc-3: strict job validation; an invalid job is unusable, never guessed. */
62
+ export declare function parseAdaptiveAppendJob(value: unknown): AdaptiveAppendJob | null;
63
+ export type { AdaptiveAppendTargetRef } from '@principles/host-runtime';
64
+ export interface AdaptiveAppendResult {
65
+ readonly schemaVersion: number;
66
+ readonly createdAt: number;
67
+ readonly startedAt: number;
68
+ readonly sessionId: string;
69
+ readonly turnId: string;
70
+ readonly target: AdaptiveAppendTargetRef;
71
+ readonly directiveChars: number;
72
+ readonly nativeActivationIds: string[];
73
+ readonly nativeChars: number;
74
+ readonly budgetChars: number;
75
+ readonly hookIdentity: AdaptiveAppendHookIdentity | null;
76
+ }
77
+ export declare function parseAdaptiveAppendResult(value: unknown): AdaptiveAppendResult | null;
78
+ export type AdaptiveAppendJobWrite = {
79
+ readonly ok: true;
80
+ readonly jobPath: string;
81
+ } | {
82
+ readonly ok: false;
83
+ readonly reason: 'already_started' | 'job_write_failed';
84
+ };
85
+ /**
86
+ * Parent side: create the job ONCE per turn, then hand it to a DETACHED
87
+ * process. `wx` is the gate behind "at most one scoring request per turn": a
88
+ * retried/replayed UserPromptSubmit for the same turn cannot replace the job
89
+ * and spawn a second selector. The job carries the Owner prompt for the
90
+ * decision request only, so the file is owner-only (0600) and is withdrawn by
91
+ * the selector as soon as it reads it; a write that never reaches the selector
92
+ * is removed here or aged out by the residue sweep.
93
+ */
94
+ export declare function writeAdaptiveAppendJob(job: AdaptiveAppendJob): AdaptiveAppendJobWrite;
95
+ /** A job that could not be handed off must not leave the prompt on disk. */
96
+ export declare function discardAdaptiveAppendJob(jobPath: string): void;
97
+ export type AdaptiveAppendSpawnResult = {
98
+ ok: true;
99
+ pid: number | undefined;
100
+ } | {
101
+ ok: false;
102
+ reason: string;
103
+ };
104
+ /**
105
+ * Spawn the background selector. `stdio: 'ignore'` is mandatory: a detached
106
+ * child that inherited the hook's stdout pipe would keep that pipe open and
107
+ * hold the host's first request until the decision finished.
108
+ */
109
+ export declare function spawnAdaptiveBackgroundSelection(jobPath: string): AdaptiveAppendSpawnResult;
110
+ /** Child side: read and immediately withdraw the job (the prompt is not kept). */
111
+ export declare function takeAdaptiveAppendJob(jobPath: string): AdaptiveAppendJob | null;
112
+ /** Persist the ONE ready decision for this turn. */
113
+ export declare function writeAdaptiveAppendResultFor(workspaceDir: string, result: AdaptiveAppendResult): void;
114
+ /** Withdraw a result whose turn ended while it was being written. */
115
+ export declare function discardAdaptiveAppendResult(workspaceDir: string, sessionId: string, turnId: string): void;
116
+ export type AdaptiveAppendReady = {
117
+ readonly status: 'ready';
118
+ readonly result: AdaptiveAppendResult;
119
+ readonly claimPath: string;
120
+ } | {
121
+ readonly status: 'absent' | 'invalid' | 'expired';
122
+ readonly reason?: string;
123
+ };
124
+ /**
125
+ * Atomically claim the ready result. `renameSync` is the mutex: exactly one
126
+ * concurrent consumer can move the file, so a replayed callback emits nothing.
127
+ */
128
+ export declare function claimAdaptiveAppendResult(input: {
129
+ workspaceDir: string;
130
+ sessionId: string;
131
+ turnId: string;
132
+ now: number;
133
+ }): AdaptiveAppendReady;
134
+ export declare function releaseAdaptiveAppendClaim(claimPath: string): void;
135
+ export type ToolObservationPhase = 'pre' | 'post';
136
+ export interface ToolObservation {
137
+ readonly phase: ToolObservationPhase;
138
+ readonly toolCallId: string;
139
+ readonly toolName: string;
140
+ readonly canonicalKind: string;
141
+ /** Only meaningful for execute kinds: classifyBashRisk(...) === 'safe'. */
142
+ readonly readOnly: boolean;
143
+ readonly at: number;
144
+ }
145
+ export declare function appendToolObservation(input: {
146
+ workspaceDir: string;
147
+ sessionId: string;
148
+ turnId: string;
149
+ observation: ToolObservation;
150
+ }): void;
151
+ export declare function readToolObservations(input: {
152
+ workspaceDir: string;
153
+ sessionId: string;
154
+ turnId: string;
155
+ }): ToolObservation[];
156
+ export type AppendOrdering = {
157
+ readonly ok: true;
158
+ } | {
159
+ readonly ok: false;
160
+ readonly reason: string;
161
+ };
162
+ /**
163
+ * The ordering gate:
164
+ * - the CURRENT call must have been observed at both boundaries — a lone
165
+ * post proves nothing about what happened before it;
166
+ * - a `write` call anywhere in this turn ends the opportunity;
167
+ * - an execute call that is not classified `safe`, or an unresolved kind,
168
+ * is "semantics unknown" and ends it too;
169
+ * - another call opened and not yet closed means the completion order of a
170
+ * parallel batch cannot be proven; a replayed post is a duplicate callback.
171
+ */
172
+ export declare function evaluateAppendOrdering(observations: readonly ToolObservation[], currentToolCallId: string): AppendOrdering;
173
+ /** Delete every short-lived file of one turn (Stop / terminal drop). */
174
+ export declare function clearAdaptiveAppendTurn(input: {
175
+ workspaceDir: string;
176
+ sessionId: string;
177
+ turnId: string;
178
+ }): void;
179
+ /** Opportunistic residue sweep; bounded and age-based, never touches fresh state. */
180
+ export declare function clearStaleAdaptiveAppendState(workspaceDir: string, now: number): void;
181
+ /**
182
+ * One-shot marker for a terminal fact of this turn. Returns true only to the
183
+ * caller that created it, so concurrent hooks emit the fact once.
184
+ */
185
+ export declare function claimAdaptiveReportMarker(input: {
186
+ workspaceDir: string;
187
+ sessionId: string;
188
+ turnId: string;
189
+ reason: string;
190
+ }): boolean;
191
+ export interface AdaptiveAppendFactInput {
192
+ readonly stateDir: string;
193
+ readonly sessionId: string;
194
+ readonly turnId: string;
195
+ readonly workspaceDir: string;
196
+ /** `<status>:<reason>` — the UI classifies on this prefix. */
197
+ readonly resultCode: string;
198
+ readonly scored: boolean;
199
+ readonly appended?: AdaptiveAppendTargetRef;
200
+ readonly budget: number;
201
+ readonly injectedCharCount: number;
202
+ }
203
+ /**
204
+ * The console reads `runtime_v2_prompt_activations_injected` with an
205
+ * `adaptive` fact. "Background selected" is emitted with empty arrays (no
206
+ * injection claim); "appended" carries exactly the one principle that was
207
+ * added to the later request.
208
+ */
209
+ export declare function appendAdaptiveAppendFact(input: AdaptiveAppendFactInput): void;