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
@@ -8,14 +8,19 @@
8
8
  * model, never a CLI subprocess, never a second query implementation
9
9
  * (§3.2). Core stays MCP-SDK-free (architecture guard test pins this).
10
10
  *
11
- * The single registered tool is the read-only `pd_recall_principle_pains`
12
- * with an honest `readOnlyHint: true` (a host hint, not an OS boundary).
11
+ * The single read tool is `pd_recall_principle_pains` (`readOnlyHint: true`).
12
+ * The write tool `pd_submit_pain` exists only when the caller explicitly sets
13
+ * `enableSubmitTool: true` — the OG-4 production governance gate
14
+ * (SPEC-PD-AGENT-PAIN-INGRESS-001 §5.1.1). No env var or feature flag can turn
15
+ * it on: a deployment must opt in in code and carry the OG-4 record.
13
16
  */
17
+ import { randomBytes } from 'node:crypto';
14
18
  import { McpServer, fromJsonSchema } from '@modelcontextprotocol/server';
15
19
  import { z } from 'zod';
16
20
  import { recallPrinciplePainsCapability, } from '@principles/core/runtime/pain-recall-capability';
21
+ import { buildRefusedSubmitReceipt, buildUnconfirmedSubmitReceipt, buildReconciledSubmitReceipt, deriveSubmitTaskId, recheckSubmittedTask, } from '@principles/core/runtime/pain-submit-capability';
17
22
  import { runWithDeadline, OrphanLimiter, AdmissionLimiter, DEFAULT_DEADLINE_MS } from './deadline.js';
18
- import { assembleResult, adapterFailureEnvelope, textResult } from './envelope.js';
23
+ import { assembleResult, assembleSubmitResult, adapterFailureEnvelope, textResult, } from './envelope.js';
19
24
  import { withinBudget } from './budget.js';
20
25
  import { createLogger, sanitizeErrorKind, stderrSink } from './logging.js';
21
26
  import { SERVER_NAME, SERVER_VERSION } from './version.js';
@@ -46,6 +51,81 @@ export const toolInputSchema = z.strictObject({
46
51
  principleId: z.string().min(1).max(200),
47
52
  limit: z.number().int().min(1).max(10).optional().default(3),
48
53
  });
54
+ // ── pd_submit_pain — OG-4 gated write tool ─────────────────────────────────
55
+ export const SUBMIT_TOOL_NAME = 'pd_submit_pain';
56
+ /** §5.2 — the description is a behavioural instruction to the Agent, not
57
+ * marketing copy. It carries the anchor-first / Owner-consent-first flow and
58
+ * deliberately promises registration only, never that diagnosis will run. */
59
+ export const SUBMIT_TOOL_DESCRIPTION = `记录一条"相对锚点的显著行为背离"(Pain)。
60
+
61
+ 调用前必须完成三件事:
62
+ 1) 先确定锚点:Owner 的明确期望、已建立的原则、或 Agent Instructions/Skill 的明确要求。
63
+ 原则必须给出 id 与 version;Instructions 必须给出路径与章节;Owner 期望必须给出处。
64
+ 2) 先向 Owner 说明:①锚点及出处 ②你实际观察到的具体行为 ③行为与锚点之间的背离 ④必要时补充为什么值得关注或可能的影响。
65
+ 3) 取得 Owner 在本次对话中的明确同意。未回复、回答不明确、或只说了"随便"都不算授权。
66
+ 授权只对本次提交有效;Owner 修改了内容时,提交前必须再次确认最终版本。
67
+ 后台/无人值守 Agent 不得自行提交。
68
+
69
+ 第 2 步的 ④ 是辅助说明,不是提交条件:不要求证明未来任务一定会改变判断、
70
+ 不要求证明会重复发生、不要求已产生实际损失、不要求证明长期复用价值。
71
+ 无法证明上述任何一项,都不得成为拒绝记录这条 Pain 的理由——它们只帮助 Owner
72
+ 判断注意力优先级,不属于 Pain 是否成立的条件,也不属于提交门槛。
73
+
74
+ Pain 是否成立只看三项:明确锚点 + 具体行为 + 相对锚点的显著背离。
75
+
76
+ 不要提交:分数、严重度、优先级、会话 ID、审批令牌、推测的 painType、
77
+ 或任何你无法给出出处的"锚点"。
78
+
79
+ 如果无法确定锚点或无法说明具体行为,不要调用本工具;先向 Owner 澄清。`;
80
+ /** §5.3 — JSON Schema first; every undeclared property (score, severity,
81
+ * approved, sessionId, paths, metadata) is rejected at the protocol stage. */
82
+ export const submitToolInputJsonSchema = {
83
+ type: 'object',
84
+ properties: {
85
+ reason: {
86
+ type: 'string',
87
+ minLength: 1,
88
+ maxLength: 2000,
89
+ description: '按六项顺序组织:锚点、锚点来源与引用等级、观察到的行为、背离、为什么值得记录、上下文。',
90
+ },
91
+ anchorType: {
92
+ type: 'string',
93
+ enum: ['owner_expectation', 'established_principle', 'agent_instruction'],
94
+ description: '锚点类型。无法归类时不要提交。',
95
+ },
96
+ anchorRef: {
97
+ type: 'string',
98
+ minLength: 1,
99
+ maxLength: 300,
100
+ description: '原则:<id>@<version>;Instructions:<path>#<section>;Owner 期望:本次对话中的出处。',
101
+ },
102
+ painType: {
103
+ type: 'string',
104
+ enum: ['principle_deviation', 'tool_failure', 'subagent_error', 'user_frustration'],
105
+ description: '可选。锚点式 Pain 默认是 principle_deviation;只有你能明确归类时才填写其他值,不要猜测。',
106
+ },
107
+ },
108
+ required: ['reason', 'anchorType', 'anchorRef'],
109
+ additionalProperties: false,
110
+ };
111
+ export const submitToolProtocolSchema = fromJsonSchema(submitToolInputJsonSchema);
112
+ /** §5.3.2 — zod re-validation, kept in lockstep with the JSON Schema above. */
113
+ export const submitToolInputSchema = z.strictObject({
114
+ reason: z.string().min(1).max(2000),
115
+ anchorType: z.enum(['owner_expectation', 'established_principle', 'agent_instruction']),
116
+ anchorRef: z.string().min(1).max(300),
117
+ painType: z.enum(['principle_deviation', 'tool_failure', 'subagent_error', 'user_frustration']).optional(),
118
+ });
119
+ /** §5.7 — the bounded read-back after a write timeout (upper bound 1s). */
120
+ export const SUBMIT_RECHECK_DEADLINE_MS = 1000;
121
+ /** Handler-generated identity, known BEFORE any write: `mcp_<epoch_ms>_<8-hex>`
122
+ * (§5.4.1). Never derived from a session, host or model input. */
123
+ function defaultRandomHex() {
124
+ return randomBytes(4).toString('hex');
125
+ }
126
+ export function createMcpPainId(nowMs = Date.now(), randomHex = defaultRandomHex) {
127
+ return `mcp_${nowMs}_${randomHex()}`;
128
+ }
49
129
  /** §4.8 Adapter 执行失败 row (timeout / exception / saturated / shutting
50
130
  * down) — one sanitized `tool_execution_failed` envelope, isError: true. */
51
131
  function executionFailedResult(message) {
@@ -74,12 +154,34 @@ function resultTextBytes(result) {
74
154
  * explicit isError mapping. Nothing here writes to stdout.
75
155
  */
76
156
  export function createPdMcpServer(options) {
77
- const { workspaceDir, host = null, deadlineMs = DEFAULT_DEADLINE_MS, callCapability = recallPrinciplePainsCapability, logSink = stderrSink, } = options;
157
+ const { workspaceDir, host = null, deadlineMs = DEFAULT_DEADLINE_MS, callCapability = recallPrinciplePainsCapability, logSink = stderrSink, enableSubmitTool = false, callSubmitCapability, recheckSubmitTask = recheckSubmittedTask, } = options;
158
+ const submitCall = callSubmitCapability;
159
+ if (enableSubmitTool === true && submitCall === undefined) {
160
+ // Fail closed instead of silently falling back to resolveRuntimeConfig(),
161
+ // the deprecated .state/workflows.yaml resolver (PRI-393 forbids it on
162
+ // production execution paths). The host wrapper that opts in must bind the
163
+ // real Core capability to an effective `.pd/config.yaml` config.
164
+ throw new Error('pd_submit_pain requires an injected callSubmitCapability bound to an effective PD config; ' +
165
+ 'the MCP server must not resolve runtime config through the deprecated workflows.yaml path.');
166
+ }
78
167
  const orphans = new OrphanLimiter();
79
168
  const admissions = new AdmissionLimiter();
80
169
  let shuttingDown = false;
81
170
  const mcpServer = new McpServer({ name: SERVER_NAME, version: SERVER_VERSION });
82
171
  const log = createLogger(logSink, { host: host ?? 'unspecified' });
172
+ /** One structured `tool_call` line for the submit path (§5.5 step 11). Only
173
+ * scalars: status, error code, byte size, degradation — never Pain text. */
174
+ function logSubmitCall(input) {
175
+ log(input.level ?? 'info', 'tool_call', {
176
+ toolName: SUBMIT_TOOL_NAME,
177
+ durationMs: Date.now() - input.startedAt,
178
+ status: input.status,
179
+ errorCode: input.errorCode,
180
+ responseBytes: resultTextBytes(input.result),
181
+ truncated: false,
182
+ ...(input.degraded === undefined ? {} : { degraded: input.degraded }),
183
+ });
184
+ }
83
185
  mcpServer.registerTool(TOOL_NAME, {
84
186
  description: TOOL_DESCRIPTION,
85
187
  // Static type-interop shim ONLY: our zod 4.6.7 type instantiation does
@@ -218,6 +320,151 @@ export function createPdMcpServer(options) {
218
320
  });
219
321
  return timedOut;
220
322
  });
323
+ // ── pd_submit_pain — registered ONLY behind the explicit OG-4 gate ────────
324
+ if (enableSubmitTool === true && submitCall !== undefined) {
325
+ mcpServer.registerTool(SUBMIT_TOOL_NAME, {
326
+ description: SUBMIT_TOOL_DESCRIPTION,
327
+ // Same static interop shim as the recall tool; runtime validation is
328
+ // the SDK's JSON-Schema pass plus the zod parse inside the handler.
329
+ inputSchema: submitToolProtocolSchema,
330
+ // §5.1 — the write capability must not inherit the read tool's hint.
331
+ annotations: { readOnlyHint: false, destructiveHint: false },
332
+ }, async (rawInput) => {
333
+ const startedAt = Date.now();
334
+ if (shuttingDown) {
335
+ const refusedResult = shuttingDownResult();
336
+ logSubmitCall({
337
+ startedAt,
338
+ result: refusedResult,
339
+ status: 'unavailable',
340
+ errorCode: 'shutting_down',
341
+ level: 'warn',
342
+ });
343
+ return refusedResult;
344
+ }
345
+ if (!admissions.tryAcquire()) {
346
+ // Not attempted: no write was started, so the generic failure text is
347
+ // faithful here (unlike a timeout after the write began).
348
+ const saturated = executionFailedResult('The server is already executing the maximum number of concurrent calls; retry shortly.');
349
+ logSubmitCall({
350
+ startedAt,
351
+ result: saturated,
352
+ status: 'unavailable',
353
+ errorCode: 'saturated',
354
+ level: 'warn',
355
+ });
356
+ return saturated;
357
+ }
358
+ // §5.5 step 3 — zod re-validation. Synchronous and before any write.
359
+ let submission;
360
+ try {
361
+ submission = submitToolInputSchema.parse(rawInput);
362
+ }
363
+ catch {
364
+ admissions.release();
365
+ const receipt = buildRefusedSubmitReceipt({
366
+ painId: null,
367
+ taskId: null,
368
+ workspaceDir,
369
+ code: 'invalid_input',
370
+ message: 'The request violates the pd_submit_pain input contract (reason 1..2000, anchorType in enum, anchorRef 1..300, no extra fields). Nothing was written.',
371
+ nextAction: 'Fix the arguments and retry. If no anchor is available, do not submit — clarify with the Owner first.',
372
+ });
373
+ const assembled = assembleSubmitResult(receipt);
374
+ logSubmitCall({
375
+ startedAt,
376
+ result: assembled.result,
377
+ status: receipt.status,
378
+ errorCode: 'invalid_input',
379
+ degraded: assembled.degraded,
380
+ level: 'warn',
381
+ });
382
+ return assembled.result;
383
+ }
384
+ // §5.5 step 5 — identity exists BEFORE the write, so a timeout can be
385
+ // reconciled by id instead of guessing (§5.7).
386
+ const painId = createMcpPainId();
387
+ const taskId = deriveSubmitTaskId(painId);
388
+ const outcome = await runWithDeadline(async () => {
389
+ try {
390
+ const receipt = await submitCall({ workspaceDir, painId, taskId, submission });
391
+ return { kind: 'receipt', receipt };
392
+ }
393
+ catch (err) {
394
+ // The capability promises not to throw; if it does, the outcome
395
+ // after identity assignment is unknown, never "failed".
396
+ return { kind: 'exception', errorKind: sanitizeErrorKind(err) };
397
+ }
398
+ finally {
399
+ admissions.release();
400
+ }
401
+ }, deadlineMs, (orphaned) => orphans.register(orphaned));
402
+ if (outcome.ok) {
403
+ if (outcome.value.kind === 'receipt') {
404
+ const assembled = assembleSubmitResult(outcome.value.receipt);
405
+ logSubmitCall({
406
+ startedAt,
407
+ result: assembled.result,
408
+ status: outcome.value.receipt.status,
409
+ errorCode: outcome.value.receipt.error?.code ?? 'none',
410
+ degraded: assembled.degraded,
411
+ level: outcome.value.receipt.status === 'failed' ? 'error' : 'info',
412
+ });
413
+ return assembled.result;
414
+ }
415
+ const unconfirmed = buildUnconfirmedSubmitReceipt({
416
+ painId,
417
+ taskId,
418
+ workspaceDir,
419
+ message: 'The submission threw unexpectedly after the identity was assigned; the write outcome is unknown (it may already have been written).',
420
+ });
421
+ const assembled = assembleSubmitResult(unconfirmed);
422
+ logSubmitCall({
423
+ startedAt,
424
+ result: assembled.result,
425
+ status: unconfirmed.status,
426
+ errorCode: `unexpected_${outcome.value.errorKind}`,
427
+ degraded: assembled.degraded,
428
+ level: 'error',
429
+ });
430
+ return assembled.result;
431
+ }
432
+ // §5.7 — write deadline exceeded. One bounded read-back, then report.
433
+ // Never a plain failure, never an automatic resubmission.
434
+ const recheck = await runWithDeadline(() => recheckSubmitTask({ workspaceDir, painId, taskId }), SUBMIT_RECHECK_DEADLINE_MS);
435
+ if (recheck.ok && recheck.value === 'found') {
436
+ const reconciled = buildReconciledSubmitReceipt({ painId, taskId, workspaceDir });
437
+ const assembled = assembleSubmitResult(reconciled);
438
+ logSubmitCall({
439
+ startedAt,
440
+ result: assembled.result,
441
+ status: reconciled.status,
442
+ errorCode: 'deadline_exceeded_reconciled',
443
+ degraded: assembled.degraded,
444
+ level: 'warn',
445
+ });
446
+ return assembled.result;
447
+ }
448
+ const unconfirmed = buildUnconfirmedSubmitReceipt({
449
+ painId,
450
+ taskId,
451
+ workspaceDir,
452
+ message: recheck.ok && recheck.value === 'not_found'
453
+ ? `The submission exceeded the ${deadlineMs} ms deadline and the bounded read-back did not find task '${taskId}'. It may still be written; do not resubmit blindly.`
454
+ : `The submission exceeded the ${deadlineMs} ms deadline and the bounded read-back could not determine whether task '${taskId}' was written.`,
455
+ });
456
+ const assembled = assembleSubmitResult(unconfirmed);
457
+ logSubmitCall({
458
+ startedAt,
459
+ result: assembled.result,
460
+ status: unconfirmed.status,
461
+ errorCode: 'deadline_exceeded_unconfirmed',
462
+ degraded: assembled.degraded,
463
+ level: 'warn',
464
+ });
465
+ return assembled.result;
466
+ });
467
+ }
221
468
  return {
222
469
  mcpServer,
223
470
  orphans,
@@ -7,7 +7,7 @@
7
7
  * package.json. A unit test pins it to package.json so the two cannot drift.
8
8
  */
9
9
  export declare const SERVER_NAME: 'pd-mcp-server';
10
- export declare const SERVER_VERSION: '0.3.3';
10
+ export declare const SERVER_VERSION: '0.4.0';
11
11
  /** The only MCP SDK family/version this server is released against
12
12
  * (Gate 4-A freeze, PD_MCP_GATE4A_REALITY_CHECK §3). Exact pin — no ranges. */
13
13
  export declare const MCP_SDK_PIN: '@modelcontextprotocol/server@2.4.0';
@@ -7,7 +7,7 @@
7
7
  * package.json. A unit test pins it to package.json so the two cannot drift.
8
8
  */
9
9
  export const SERVER_NAME = 'pd-mcp-server';
10
- export const SERVER_VERSION = '0.3.3';
10
+ export const SERVER_VERSION = '0.4.0';
11
11
  /** The only MCP SDK family/version this server is released against
12
12
  * (Gate 4-A freeze, PD_MCP_GATE4A_REALITY_CHECK §3). Exact pin — no ranges. */
13
13
  export const MCP_SDK_PIN = '@modelcontextprotocol/server@2.4.0';
@@ -1,9 +1,11 @@
1
1
  export declare const WORKSPACE_DIR_ENV: 'PD_MCP_WORKSPACE_DIR';
2
2
  export declare const HOST_ENV: 'PD_MCP_HOST';
3
- export declare const KNOWN_HOSTS: readonly string[];
3
+ export type PdMcpHost = 'codex' | 'openclaw' | 'workbuddy';
4
+ export declare const KNOWN_HOSTS: readonly PdMcpHost[];
5
+ export declare function isKnownHost(value: unknown): value is PdMcpHost;
4
6
  export interface WorkspaceBinding {
5
7
  readonly workspaceDir: string;
6
- readonly host: string | null;
8
+ readonly host: PdMcpHost | null;
7
9
  }
8
10
  export type WorkspaceBindingFailureCode = 'workspace_env_missing' | 'workspace_not_absolute' | 'workspace_unreadable' | 'workspace_not_directory' | 'host_invalid';
9
11
  export type WorkspaceBindingResolution = {
@@ -18,6 +18,9 @@ import * as path from 'path';
18
18
  export const WORKSPACE_DIR_ENV = 'PD_MCP_WORKSPACE_DIR';
19
19
  export const HOST_ENV = 'PD_MCP_HOST';
20
20
  export const KNOWN_HOSTS = ['codex', 'openclaw', 'workbuddy'];
21
+ export function isKnownHost(value) {
22
+ return typeof value === 'string' && KNOWN_HOSTS.includes(value);
23
+ }
21
24
  /**
22
25
  * Resolve and validate the launch-time workspace binding from a process env
23
26
  * (injected for testability; production passes `process.env`). Checks, in
@@ -68,7 +71,7 @@ export function resolveWorkspaceBinding(env) {
68
71
  }
69
72
  const host = env[HOST_ENV];
70
73
  if (host !== undefined) {
71
- if (typeof host !== 'string' || !KNOWN_HOSTS.includes(host)) {
74
+ if (!isKnownHost(host)) {
72
75
  return {
73
76
  ok: false,
74
77
  reason: 'host marker is not one of the known PD hosts',
@@ -78,5 +81,5 @@ export function resolveWorkspaceBinding(env) {
78
81
  };
79
82
  }
80
83
  }
81
- return { ok: true, binding: { workspaceDir: path.resolve(raw), host: typeof host === 'string' ? host : null } };
84
+ return { ok: true, binding: { workspaceDir: path.resolve(raw), host: isKnownHost(host) ? host : null } };
82
85
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@principles/pd-mcp-server",
3
- "version": "0.3.3",
3
+ "version": "0.4.0",
4
4
  "description": "Principles Disciple MCP Server — the single shared MCP server implementation for the three PD hosts (Codex, OpenClaw, WorkBuddy). Read-only pain recall through the Gate 3 Capability (SPEC-PD-MCP-GATE4-001).",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",