create-principles-disciple 1.91.0 → 1.93.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (263) hide show
  1. package/README.md +1 -1
  2. package/console/dist/server/config/AuthConfig.js +6 -0
  3. package/console/dist/server/index.js +31 -16
  4. package/console/dist/server/models/ApprovalsGroupedConsoleModel.js +6 -3
  5. package/console/dist/server/models/ConsoleLifecycleDatasource.js +1 -1
  6. package/console/dist/server/routes/activations.js +4 -0
  7. package/console/dist/server/routes/approvals.js +24 -4
  8. package/console/dist/server/routes/feedback-reports.js +7 -5
  9. package/console/dist/server/routes/lifecycle.js +6 -1
  10. package/console/dist/server/routes/principles.js +10 -2
  11. package/console/dist/server/routes/workspaces.js +4 -0
  12. package/console/dist/ui/components/ui/charts.js +4 -1
  13. package/console/dist/ui/components/ui/markdown.js +9 -5
  14. package/console/dist/ui/i18n/en.json +1 -2
  15. package/console/dist/ui/i18n/zh-CN.json +1 -2
  16. package/console/dist/ui/utils/enum-labels.js +4 -2
  17. package/console/dist/web/assets/app.js +8 -8
  18. package/core/dist/index.d.ts +0 -1
  19. package/core/dist/index.d.ts.map +1 -1
  20. package/core/dist/index.js +0 -2
  21. package/core/dist/index.js.map +1 -1
  22. package/core/dist/pain-signal.d.ts +11 -71
  23. package/core/dist/pain-signal.d.ts.map +1 -1
  24. package/core/dist/pain-signal.js +10 -120
  25. package/core/dist/pain-signal.js.map +1 -1
  26. package/core/dist/principle-tree-ledger.d.ts +4 -87
  27. package/core/dist/principle-tree-ledger.d.ts.map +1 -1
  28. package/core/dist/principle-tree-ledger.js +51 -148
  29. package/core/dist/principle-tree-ledger.js.map +1 -1
  30. package/core/dist/runtime-v2/__tests__/activation-types-helpers.test.js +6 -14
  31. package/core/dist/runtime-v2/__tests__/activation-types-helpers.test.js.map +1 -1
  32. package/core/dist/runtime-v2/__tests__/architecture-regression.test.js +180 -70
  33. package/core/dist/runtime-v2/__tests__/architecture-regression.test.js.map +1 -1
  34. package/core/dist/runtime-v2/__tests__/barrel-io-cleanup.test.d.ts +12 -0
  35. package/core/dist/runtime-v2/__tests__/barrel-io-cleanup.test.d.ts.map +1 -0
  36. package/core/dist/runtime-v2/__tests__/barrel-io-cleanup.test.js +46 -0
  37. package/core/dist/runtime-v2/__tests__/barrel-io-cleanup.test.js.map +1 -0
  38. package/core/dist/runtime-v2/__tests__/intake-to-internalization-bridge.test.js +1 -2
  39. package/core/dist/runtime-v2/__tests__/intake-to-internalization-bridge.test.js.map +1 -1
  40. package/core/dist/runtime-v2/__tests__/internalization-orchestrator.test.js +8 -8
  41. package/core/dist/runtime-v2/__tests__/internalization-orchestrator.test.js.map +1 -1
  42. package/core/dist/runtime-v2/__tests__/internalization-peer-runner-contracts.test.js +45 -80
  43. package/core/dist/runtime-v2/__tests__/internalization-peer-runner-contracts.test.js.map +1 -1
  44. package/core/dist/runtime-v2/__tests__/internalization-state-machine.test.js +31 -130
  45. package/core/dist/runtime-v2/__tests__/internalization-state-machine.test.js.map +1 -1
  46. package/core/dist/runtime-v2/__tests__/io-deletion.test.d.ts +12 -0
  47. package/core/dist/runtime-v2/__tests__/io-deletion.test.d.ts.map +1 -0
  48. package/core/dist/runtime-v2/__tests__/io-deletion.test.js +92 -0
  49. package/core/dist/runtime-v2/__tests__/io-deletion.test.js.map +1 -0
  50. package/core/dist/runtime-v2/__tests__/ledger-codec.test.d.ts +2 -0
  51. package/core/dist/runtime-v2/__tests__/ledger-codec.test.d.ts.map +1 -0
  52. package/core/dist/runtime-v2/__tests__/ledger-codec.test.js +429 -0
  53. package/core/dist/runtime-v2/__tests__/ledger-codec.test.js.map +1 -0
  54. package/core/dist/runtime-v2/__tests__/ledger-store.test.d.ts +2 -0
  55. package/core/dist/runtime-v2/__tests__/ledger-store.test.d.ts.map +1 -0
  56. package/core/dist/runtime-v2/__tests__/ledger-store.test.js +65 -0
  57. package/core/dist/runtime-v2/__tests__/ledger-store.test.js.map +1 -0
  58. package/core/dist/runtime-v2/__tests__/pain-signal-observability.test.js +146 -0
  59. package/core/dist/runtime-v2/__tests__/pain-signal-observability.test.js.map +1 -1
  60. package/core/dist/runtime-v2/__tests__/pain-signal-unification.test.d.ts +2 -0
  61. package/core/dist/runtime-v2/__tests__/pain-signal-unification.test.d.ts.map +1 -0
  62. package/core/dist/runtime-v2/__tests__/pain-signal-unification.test.js +150 -0
  63. package/core/dist/runtime-v2/__tests__/pain-signal-unification.test.js.map +1 -0
  64. package/core/dist/runtime-v2/__tests__/pain-to-principle-service.test.js +0 -1
  65. package/core/dist/runtime-v2/__tests__/pain-to-principle-service.test.js.map +1 -1
  66. package/core/dist/runtime-v2/__tests__/pitask-metadata.test.js +4 -4
  67. package/core/dist/runtime-v2/__tests__/pitask-metadata.test.js.map +1 -1
  68. package/core/dist/runtime-v2/__tests__/proven-channel-baseline.test.js +2 -5
  69. package/core/dist/runtime-v2/__tests__/proven-channel-baseline.test.js.map +1 -1
  70. package/core/dist/runtime-v2/__tests__/story-a-demo.test.js +2 -2
  71. package/core/dist/runtime-v2/__tests__/story-a-demo.test.js.map +1 -1
  72. package/core/dist/runtime-v2/activation/__tests__/activation-dispatcher.test.js +7 -10
  73. package/core/dist/runtime-v2/activation/__tests__/activation-dispatcher.test.js.map +1 -1
  74. package/core/dist/runtime-v2/activation/__tests__/approval-queue.test.js +1 -3
  75. package/core/dist/runtime-v2/activation/__tests__/approval-queue.test.js.map +1 -1
  76. package/core/dist/runtime-v2/activation/__tests__/approval-store-extended.test.js +4 -4
  77. package/core/dist/runtime-v2/activation/__tests__/sqlite-approval-store.test.js +6 -6
  78. package/core/dist/runtime-v2/activation/__tests__/sqlite-approval-store.test.js.map +1 -1
  79. package/core/dist/runtime-v2/activation/activation-dispatcher.d.ts.map +1 -1
  80. package/core/dist/runtime-v2/activation/activation-dispatcher.js +0 -1
  81. package/core/dist/runtime-v2/activation/activation-dispatcher.js.map +1 -1
  82. package/core/dist/runtime-v2/activation/activation-types.d.ts.map +1 -1
  83. package/core/dist/runtime-v2/activation/activation-types.js +0 -1
  84. package/core/dist/runtime-v2/activation/activation-types.js.map +1 -1
  85. package/core/dist/runtime-v2/adapter/__tests__/test-double-runtime-adapter.test.js +199 -0
  86. package/core/dist/runtime-v2/adapter/__tests__/test-double-runtime-adapter.test.js.map +1 -1
  87. package/core/dist/runtime-v2/adapter/pi-ai-runtime-adapter.d.ts.map +1 -1
  88. package/core/dist/runtime-v2/adapter/pi-ai-runtime-adapter.js +0 -2
  89. package/core/dist/runtime-v2/adapter/pi-ai-runtime-adapter.js.map +1 -1
  90. package/core/dist/runtime-v2/config/__tests__/pd-config-agent-binding.test.js +0 -7
  91. package/core/dist/runtime-v2/config/__tests__/pd-config-agent-binding.test.js.map +1 -1
  92. package/core/dist/runtime-v2/config/__tests__/pd-config-contract.test.js +5 -6
  93. package/core/dist/runtime-v2/config/__tests__/pd-config-contract.test.js.map +1 -1
  94. package/core/dist/runtime-v2/config/__tests__/pd-config-redaction-deep.test.js +0 -1
  95. package/core/dist/runtime-v2/config/__tests__/pd-config-redaction-deep.test.js.map +1 -1
  96. package/core/dist/runtime-v2/config/__tests__/pd-config-validation-edge-cases.test.js +0 -1
  97. package/core/dist/runtime-v2/config/__tests__/pd-config-validation-edge-cases.test.js.map +1 -1
  98. package/core/dist/runtime-v2/config/pd-config-defaults.d.ts.map +1 -1
  99. package/core/dist/runtime-v2/config/pd-config-defaults.js +0 -1
  100. package/core/dist/runtime-v2/config/pd-config-defaults.js.map +1 -1
  101. package/core/dist/runtime-v2/config/pd-config-types.d.ts +1 -1
  102. package/core/dist/runtime-v2/config/pd-config-types.d.ts.map +1 -1
  103. package/core/dist/runtime-v2/config/pd-config-types.js +0 -1
  104. package/core/dist/runtime-v2/config/pd-config-types.js.map +1 -1
  105. package/core/dist/runtime-v2/diagnostician/__tests__/diag-rootcause-output.test.js +156 -0
  106. package/core/dist/runtime-v2/diagnostician/__tests__/diag-rootcause-output.test.js.map +1 -1
  107. package/core/dist/runtime-v2/feature-flags/feature-flag-contract.d.ts.map +1 -1
  108. package/core/dist/runtime-v2/feature-flags/feature-flag-contract.js +0 -2
  109. package/core/dist/runtime-v2/feature-flags/feature-flag-contract.js.map +1 -1
  110. package/core/dist/runtime-v2/index.d.ts +2 -9
  111. package/core/dist/runtime-v2/index.d.ts.map +1 -1
  112. package/core/dist/runtime-v2/index.js +5 -6
  113. package/core/dist/runtime-v2/index.js.map +1 -1
  114. package/core/dist/runtime-v2/internalization/__tests__/diag-chain-e2e.test.js +0 -3
  115. package/core/dist/runtime-v2/internalization/__tests__/diag-chain-e2e.test.js.map +1 -1
  116. package/core/dist/runtime-v2/internalization/__tests__/internalization-job-graph.test.js +4 -36
  117. package/core/dist/runtime-v2/internalization/__tests__/internalization-job-graph.test.js.map +1 -1
  118. package/core/dist/runtime-v2/internalization/__tests__/peer-runner-lineage-injection.test.js +0 -1
  119. package/core/dist/runtime-v2/internalization/__tests__/peer-runner-lineage-injection.test.js.map +1 -1
  120. package/core/dist/runtime-v2/internalization/__tests__/queue-actionability.test.js +0 -15
  121. package/core/dist/runtime-v2/internalization/__tests__/queue-actionability.test.js.map +1 -1
  122. package/core/dist/runtime-v2/internalization/index.d.ts +1 -7
  123. package/core/dist/runtime-v2/internalization/index.d.ts.map +1 -1
  124. package/core/dist/runtime-v2/internalization/index.js +1 -4
  125. package/core/dist/runtime-v2/internalization/index.js.map +1 -1
  126. package/core/dist/runtime-v2/internalization/internalization-job-graph.d.ts +7 -18
  127. package/core/dist/runtime-v2/internalization/internalization-job-graph.d.ts.map +1 -1
  128. package/core/dist/runtime-v2/internalization/internalization-job-graph.js +7 -24
  129. package/core/dist/runtime-v2/internalization/internalization-job-graph.js.map +1 -1
  130. package/core/dist/runtime-v2/internalization/internalization-state-machine.d.ts +3 -2
  131. package/core/dist/runtime-v2/internalization/internalization-state-machine.d.ts.map +1 -1
  132. package/core/dist/runtime-v2/internalization/internalization-state-machine.js +4 -3
  133. package/core/dist/runtime-v2/internalization/internalization-state-machine.js.map +1 -1
  134. package/core/dist/runtime-v2/internalization/peer-runner-contracts.d.ts +6 -6
  135. package/core/dist/runtime-v2/internalization/peer-runner-contracts.d.ts.map +1 -1
  136. package/core/dist/runtime-v2/internalization/peer-runner-contracts.js +0 -3
  137. package/core/dist/runtime-v2/internalization/peer-runner-contracts.js.map +1 -1
  138. package/core/dist/runtime-v2/principle-tree/ledger-codec.d.ts +30 -0
  139. package/core/dist/runtime-v2/principle-tree/ledger-codec.d.ts.map +1 -0
  140. package/core/dist/runtime-v2/principle-tree/ledger-codec.js +154 -0
  141. package/core/dist/runtime-v2/principle-tree/ledger-codec.js.map +1 -0
  142. package/core/dist/runtime-v2/recovery-sweep-service.d.ts.map +1 -1
  143. package/core/dist/runtime-v2/recovery-sweep-service.js +2 -2
  144. package/core/dist/runtime-v2/recovery-sweep-service.js.map +1 -1
  145. package/core/dist/runtime-v2/store/candidate/__tests__/recommendation-kind-resolver.test.js +1 -1
  146. package/core/dist/runtime-v2/store/candidate/__tests__/recommendation-kind-resolver.test.js.map +1 -1
  147. package/core/dist/runtime-v2/types/index.d.ts +2 -0
  148. package/core/dist/runtime-v2/types/index.d.ts.map +1 -1
  149. package/core/dist/runtime-v2/types/index.js +1 -0
  150. package/core/dist/runtime-v2/types/index.js.map +1 -1
  151. package/core/dist/runtime-v2/types/ledger-store.d.ts +101 -0
  152. package/core/dist/runtime-v2/types/ledger-store.d.ts.map +1 -0
  153. package/core/dist/runtime-v2/types/ledger-store.js +15 -0
  154. package/core/dist/runtime-v2/types/ledger-store.js.map +1 -0
  155. package/core/dist/runtime-v2/types/pain-signal.d.ts +5 -3
  156. package/core/dist/runtime-v2/types/pain-signal.d.ts.map +1 -1
  157. package/core/dist/runtime-v2/types/pain-signal.js +23 -3
  158. package/core/dist/runtime-v2/types/pain-signal.js.map +1 -1
  159. package/core/package.json +3 -3
  160. package/dist/installer.d.ts.map +1 -1
  161. package/dist/installer.js +42 -5
  162. package/dist/installer.js.map +1 -1
  163. package/dist/mvp-config.d.ts +1 -1
  164. package/dist/mvp-config.d.ts.map +1 -1
  165. package/dist/mvp-config.js +4 -8
  166. package/dist/mvp-config.js.map +1 -1
  167. package/dist/utils/env.d.ts.map +1 -1
  168. package/dist/utils/env.js +10 -4
  169. package/dist/utils/env.js.map +1 -1
  170. package/package.json +1 -1
  171. package/pd-cli/dist/commands/__tests__/legacy-cleanup.test.js +11 -3
  172. package/pd-cli/dist/commands/__tests__/legacy-cleanup.test.js.map +1 -1
  173. package/pd-cli/dist/commands/build-trajectory-evidence.d.ts.map +1 -1
  174. package/pd-cli/dist/commands/build-trajectory-evidence.js +11 -5
  175. package/pd-cli/dist/commands/build-trajectory-evidence.js.map +1 -1
  176. package/pd-cli/dist/commands/candidate.d.ts.map +1 -1
  177. package/pd-cli/dist/commands/candidate.js +2 -1
  178. package/pd-cli/dist/commands/candidate.js.map +1 -1
  179. package/pd-cli/dist/commands/health.d.ts.map +1 -1
  180. package/pd-cli/dist/commands/health.js +2 -1
  181. package/pd-cli/dist/commands/health.js.map +1 -1
  182. package/pd-cli/dist/commands/runtime-activation.js.map +1 -1
  183. package/pd-cli/dist/commands/runtime-internalization-integrity.d.ts.map +1 -1
  184. package/pd-cli/dist/commands/runtime-internalization-integrity.js +3 -1
  185. package/pd-cli/dist/commands/runtime-internalization-integrity.js.map +1 -1
  186. package/pd-cli/dist/commands/runtime-internalization-run-once.d.ts.map +1 -1
  187. package/pd-cli/dist/commands/runtime-internalization-run-once.js +3 -61
  188. package/pd-cli/dist/commands/runtime-internalization-run-once.js.map +1 -1
  189. package/pd-cli/dist/commands/runtime-uat.d.ts.map +1 -1
  190. package/pd-cli/dist/commands/runtime-uat.js +4 -1
  191. package/pd-cli/dist/commands/runtime-uat.js.map +1 -1
  192. package/pd-cli/dist/legacy/session-history-import.js +7 -5
  193. package/pd-cli/dist/legacy/session-history-import.js.map +1 -1
  194. package/pd-cli/dist/services/__tests__/runtime-adapter-resolver.test.js +13 -2
  195. package/pd-cli/dist/services/__tests__/runtime-adapter-resolver.test.js.map +1 -1
  196. package/pd-cli/dist/services/pain-flood-simulation-runner.d.ts.map +1 -1
  197. package/pd-cli/dist/services/pain-flood-simulation-runner.js +6 -2
  198. package/pd-cli/dist/services/pain-flood-simulation-runner.js.map +1 -1
  199. package/pd-cli/dist/services/runtime-adapter-resolver.d.ts.map +1 -1
  200. package/pd-cli/dist/services/runtime-adapter-resolver.js +6 -4
  201. package/pd-cli/dist/services/runtime-adapter-resolver.js.map +1 -1
  202. package/plugin/dist/commands/capabilities.js +3 -2
  203. package/plugin/dist/commands/disable-impl.js +1 -1
  204. package/plugin/dist/commands/focus.js +10 -2
  205. package/plugin/dist/commands/rollback-impl.js +1 -1
  206. package/plugin/dist/commands/thinking-os.js +5 -1
  207. package/plugin/dist/core/correction-cue-learner.js +2 -0
  208. package/plugin/dist/core/event-log.js +17 -10
  209. package/plugin/dist/core/focus-history.js +1 -1
  210. package/plugin/dist/core/hygiene/tracker.js +3 -3
  211. package/plugin/dist/core/principle-compiler/compiler.js +2 -0
  212. package/plugin/dist/core/replay-engine.js +1 -1
  213. package/plugin/dist/core/rule-host.js +3 -1
  214. package/plugin/dist/core/schema/schema-definitions.js +3 -0
  215. package/plugin/dist/core/thinking-os-parser.js +13 -4
  216. package/plugin/dist/core/trajectory-types.d.ts +5 -0
  217. package/plugin/dist/core/trajectory.d.ts +1 -0
  218. package/plugin/dist/core/trajectory.js +29 -8
  219. package/plugin/dist/hooks/after-tool-call-helpers.d.ts +5 -0
  220. package/plugin/dist/hooks/after-tool-call-helpers.js +64 -0
  221. package/plugin/dist/hooks/llm.d.ts +8 -0
  222. package/plugin/dist/hooks/llm.js +30 -0
  223. package/plugin/dist/hooks/trajectory-collector.d.ts +20 -4
  224. package/plugin/dist/hooks/trajectory-collector.js +95 -156
  225. package/plugin/dist/hooks/trajectory-evidence.js +6 -2
  226. package/plugin/dist/index.js +7 -2
  227. package/plugin/dist/openclaw-sdk.d.ts +5 -1
  228. package/plugin/dist/service/evolution-worker.js +7 -3
  229. package/plugin/dist/service/internalization-auto-consumer-service.js +2 -1
  230. package/plugin/dist/service/runtime-summary-service.js +8 -1
  231. package/plugin/dist/service/workflow-watchdog.js +2 -1
  232. package/plugin/dist/utils/retry.js +7 -2
  233. package/plugin/dist/utils/session-key.js +4 -1
  234. package/core/dist/io.d.ts +0 -35
  235. package/core/dist/io.d.ts.map +0 -1
  236. package/core/dist/io.js +0 -95
  237. package/core/dist/io.js.map +0 -1
  238. package/core/dist/runtime-v2/__tests__/trainer-output-validator.test.d.ts +0 -2
  239. package/core/dist/runtime-v2/__tests__/trainer-output-validator.test.d.ts.map +0 -1
  240. package/core/dist/runtime-v2/__tests__/trainer-output-validator.test.js +0 -257
  241. package/core/dist/runtime-v2/__tests__/trainer-output-validator.test.js.map +0 -1
  242. package/core/dist/runtime-v2/__tests__/trainer-runner-vslice.test.d.ts +0 -2
  243. package/core/dist/runtime-v2/__tests__/trainer-runner-vslice.test.d.ts.map +0 -1
  244. package/core/dist/runtime-v2/__tests__/trainer-runner-vslice.test.js +0 -514
  245. package/core/dist/runtime-v2/__tests__/trainer-runner-vslice.test.js.map +0 -1
  246. package/core/dist/runtime-v2/internalization/__tests__/trainer-prompt-builder.test.d.ts +0 -2
  247. package/core/dist/runtime-v2/internalization/__tests__/trainer-prompt-builder.test.d.ts.map +0 -1
  248. package/core/dist/runtime-v2/internalization/__tests__/trainer-prompt-builder.test.js +0 -141
  249. package/core/dist/runtime-v2/internalization/__tests__/trainer-prompt-builder.test.js.map +0 -1
  250. package/core/dist/runtime-v2/internalization/trainer-output.d.ts +0 -122
  251. package/core/dist/runtime-v2/internalization/trainer-output.d.ts.map +0 -1
  252. package/core/dist/runtime-v2/internalization/trainer-output.js +0 -223
  253. package/core/dist/runtime-v2/internalization/trainer-output.js.map +0 -1
  254. package/core/dist/runtime-v2/internalization/trainer-prompt-builder.d.ts +0 -24
  255. package/core/dist/runtime-v2/internalization/trainer-prompt-builder.d.ts.map +0 -1
  256. package/core/dist/runtime-v2/internalization/trainer-prompt-builder.js +0 -57
  257. package/core/dist/runtime-v2/internalization/trainer-prompt-builder.js.map +0 -1
  258. package/core/dist/runtime-v2/internalization/trainer-runner.d.ts +0 -76
  259. package/core/dist/runtime-v2/internalization/trainer-runner.d.ts.map +0 -1
  260. package/core/dist/runtime-v2/internalization/trainer-runner.js +0 -540
  261. package/core/dist/runtime-v2/internalization/trainer-runner.js.map +0 -1
  262. package/plugin/dist/core/external-training-contract.d.ts +0 -276
  263. package/plugin/dist/core/external-training-contract.js +0 -269
package/README.md CHANGED
@@ -18,7 +18,7 @@ Three MVP-Core channels are always enabled and cannot be disabled:
18
18
  - `code_tool_hook` — RuleHost hard enforcement
19
19
  - `defer_archive` — graceful deferral
20
20
 
21
- Quiet and gone capabilities (gfi, nocturnal, idle_trigger, model_training, trainer) are **not surfaced** to users.
21
+ Quiet and gone capabilities (gfi, nocturnal, idle_trigger) are **not surfaced** to users.
22
22
 
23
23
  ## Usage
24
24
 
@@ -26,6 +26,12 @@ export class AuthConfig {
26
26
  return false;
27
27
  }
28
28
  const [, provided] = match;
29
+ if (!provided) {
30
+ return false;
31
+ }
32
+ if (!this.token) {
33
+ return false;
34
+ }
29
35
  const providedBuf = Buffer.from(provided, 'utf8');
30
36
  const expectedBuf = Buffer.from(this.token, 'utf8');
31
37
  if (providedBuf.length !== expectedBuf.length) {
@@ -45,7 +45,10 @@ function resolveWorkspaceDir(argv) {
45
45
  let explicitWorkspace = undefined;
46
46
  for (let i = 0; i < args.length; i++) {
47
47
  if (args[i] === '--workspace' && i + 1 < args.length) {
48
- explicitWorkspace = path.resolve(args[i + 1]);
48
+ const next = args[i + 1];
49
+ if (next !== undefined) {
50
+ explicitWorkspace = path.resolve(next);
51
+ }
49
52
  break;
50
53
  }
51
54
  }
@@ -60,12 +63,15 @@ function resolveWorkspaceDir(argv) {
60
63
  const workspaces = configStore.getWorkspaces();
61
64
  const enabled = workspaces.filter(e => e.config?.enabled !== false);
62
65
  if (enabled.length > 0) {
63
- const resolved = path.resolve(enabled[0].path);
64
- if (fs.existsSync(resolved)) {
65
- console.log('[pd-console] No --workspace flag; using registered workspace: ' + resolved);
66
- return resolved;
66
+ const [first] = enabled;
67
+ if (first) {
68
+ const resolved = path.resolve(first.path);
69
+ if (fs.existsSync(resolved)) {
70
+ console.log('[pd-console] No --workspace flag; using registered workspace: ' + resolved);
71
+ return resolved;
72
+ }
73
+ console.warn('[pd-console] Registered workspace path does not exist: ' + resolved + ', falling back to cwd');
67
74
  }
68
- console.warn('[pd-console] Registered workspace path does not exist: ' + resolved + ', falling back to cwd');
69
75
  }
70
76
  return process.cwd();
71
77
  }
@@ -78,24 +84,33 @@ function parseArgs(argv) {
78
84
  let token = undefined;
79
85
  for (let i = 0; i < args.length; i++) {
80
86
  if (args[i] === '--port' && i + 1 < args.length) {
81
- const parsed = parseInt(args[i + 1], 10);
82
- if (Number.isNaN(parsed) || parsed < 1 || parsed > 65535) {
83
- console.error('Invalid port: ' + args[i + 1] + '. Must be 1-65535.');
84
- process.exit(1);
87
+ const portStr = args[i + 1];
88
+ if (portStr !== undefined) {
89
+ const parsed = parseInt(portStr, 10);
90
+ if (Number.isNaN(parsed) || parsed < 1 || parsed > 65535) {
91
+ console.error('Invalid port: ' + portStr + '. Must be 1-65535.');
92
+ process.exit(1);
93
+ }
94
+ port = parsed;
95
+ i++;
85
96
  }
86
- port = parsed;
87
- i++;
88
97
  }
89
98
  else if (args[i] === '--host' && i + 1 < args.length) {
90
- host = args[i + 1];
91
- i++;
99
+ const next = args[i + 1];
100
+ if (next !== undefined) {
101
+ host = next;
102
+ i++;
103
+ }
92
104
  }
93
105
  else if (args[i] === '--no-auth') {
94
106
  noAuth = true;
95
107
  }
96
108
  else if (args[i] === '--token' && i + 1 < args.length) {
97
- token = args[i + 1];
98
- i++;
109
+ const next = args[i + 1];
110
+ if (next !== undefined) {
111
+ token = next;
112
+ i++;
113
+ }
99
114
  }
100
115
  }
101
116
  if (noAuth && host !== '127.0.0.1' && host !== 'localhost') {
@@ -1,4 +1,5 @@
1
- import { SqliteConnection, SqliteApprovalQueueStore, SqlitePIArtifactStore, ApprovalQueue, loadLedger, } from '@principles/core/runtime-v2';
1
+ import { SqliteConnection, SqliteApprovalQueueStore, SqlitePIArtifactStore, ApprovalQueue, } from '@principles/core/runtime-v2';
2
+ import { loadLedger } from '@principles/core/principle-tree-ledger';
2
3
  import * as fs from 'node:fs';
3
4
  import * as path from 'node:path';
4
5
  /** Type guard: non-null object (not array). Replaces `as Record<string, unknown>` assertions. */
@@ -41,8 +42,10 @@ function extractCandidateDescription(contentJson) {
41
42
  if (typeof obj.implementationCode === 'string') {
42
43
  const principleMatch = /\/\/\s*Principle:\s*(.+)/.exec(obj.implementationCode);
43
44
  const ruleMatch = /\/\/\s*Rule:\s*(.+)/.exec(obj.implementationCode);
44
- const principleText = principleMatch ? principleMatch[1].trim() : null;
45
- const ruleText = ruleMatch ? ruleMatch[1].trim() : null;
45
+ const principleRaw = principleMatch ? principleMatch[1] : undefined;
46
+ const ruleRaw = ruleMatch ? ruleMatch[1] : undefined;
47
+ const principleText = principleRaw ? principleRaw.trim() : null;
48
+ const ruleText = ruleRaw ? ruleRaw.trim() : null;
46
49
  if (principleText && ruleText)
47
50
  return `${principleText} — ${ruleText}`;
48
51
  if (ruleText)
@@ -1,4 +1,4 @@
1
- import { loadLedger } from '@principles/core/runtime-v2';
1
+ import { loadLedger } from '@principles/core/principle-tree-ledger';
2
2
  import * as fs from 'node:fs';
3
3
  import * as path from 'node:path';
4
4
  export class LineageSourceRetiredError extends Error {
@@ -49,6 +49,10 @@ export async function handleActivationsRoute(req, res, workspaceDir, subPath) {
49
49
  const disableExec = /^\/([^/]+)\/disable$/.exec(subPath);
50
50
  if (req.method === 'POST' && disableExec) {
51
51
  const [, rawId] = disableExec;
52
+ if (!rawId) {
53
+ sendError(res, 400, 'invalid_id', 'Activation ID is missing');
54
+ return;
55
+ }
52
56
  let activationId;
53
57
  try {
54
58
  activationId = decodeURIComponent(rawId);
@@ -77,9 +77,14 @@ export async function handleApprovalsRoute(req, res, workspaceDir, subPath) {
77
77
  // GET /api/v1/approvals/:id - detail
78
78
  const detailMatch = /^[/]([^/]+)$/.exec(subPath);
79
79
  if (req.method === 'GET' && detailMatch) {
80
+ const [, rawId] = detailMatch;
81
+ if (!rawId) {
82
+ sendError(res, 400, 'invalid_id', 'Approval ID is missing');
83
+ return;
84
+ }
80
85
  let approvalId;
81
86
  try {
82
- approvalId = decodeURIComponent(detailMatch[1]);
87
+ approvalId = decodeURIComponent(rawId);
83
88
  }
84
89
  catch {
85
90
  sendError(res, 400, 'invalid_id', 'Approval ID contains invalid URI encoding');
@@ -101,9 +106,14 @@ export async function handleApprovalsRoute(req, res, workspaceDir, subPath) {
101
106
  // POST /api/v1/approvals/:id/approve
102
107
  const approveMatch = /^[/]([^/]+)[/]approve$/.exec(subPath);
103
108
  if (req.method === 'POST' && approveMatch) {
109
+ const [, rawId] = approveMatch;
110
+ if (!rawId) {
111
+ sendError(res, 400, 'invalid_id', 'Approval ID is missing');
112
+ return;
113
+ }
104
114
  let approvalId;
105
115
  try {
106
- approvalId = decodeURIComponent(approveMatch[1]);
116
+ approvalId = decodeURIComponent(rawId);
107
117
  }
108
118
  catch {
109
119
  sendError(res, 400, 'invalid_id', 'Approval ID contains invalid URI encoding');
@@ -151,9 +161,14 @@ export async function handleApprovalsRoute(req, res, workspaceDir, subPath) {
151
161
  // POST /api/v1/approvals/:id/reject
152
162
  const rejectMatch = /^[/]([^/]+)[/]reject$/.exec(subPath);
153
163
  if (req.method === 'POST' && rejectMatch) {
164
+ const [, rawId] = rejectMatch;
165
+ if (!rawId) {
166
+ sendError(res, 400, 'invalid_id', 'Approval ID is missing');
167
+ return;
168
+ }
154
169
  let approvalId;
155
170
  try {
156
- approvalId = decodeURIComponent(rejectMatch[1]);
171
+ approvalId = decodeURIComponent(rawId);
157
172
  }
158
173
  catch {
159
174
  sendError(res, 400, 'invalid_id', 'Approval ID contains invalid URI encoding');
@@ -201,9 +216,14 @@ export async function handleApprovalsRoute(req, res, workspaceDir, subPath) {
201
216
  // POST /api/v1/approvals/:id/edit — edit a pending approval's artifact (P1 #2 fix)
202
217
  const editMatch = /^[/]([^/]+)[/]edit$/.exec(subPath);
203
218
  if (req.method === 'POST' && editMatch) {
219
+ const [, rawId] = editMatch;
220
+ if (!rawId) {
221
+ sendError(res, 400, 'invalid_id', 'Approval ID is missing');
222
+ return;
223
+ }
204
224
  let approvalId;
205
225
  try {
206
- approvalId = decodeURIComponent(editMatch[1]);
226
+ approvalId = decodeURIComponent(rawId);
207
227
  }
208
228
  catch {
209
229
  sendError(res, 400, 'invalid_id', 'Approval ID contains invalid URI encoding');
@@ -78,17 +78,19 @@ export async function handleFeedbackReportsRoute(req, res, ctx) {
78
78
  if (method === 'POST') {
79
79
  // Feature flag gate — feedback_channel must be enabled to create drafts
80
80
  if (ctx.featureFlags
81
- && Object.hasOwn(ctx.featureFlags, 'feedback_channel')
82
- && !ctx.featureFlags.feedback_channel.enabled) {
83
- sendError(res, 403, 'feedback_channel_disabled', 'feedback_channel feature flag is disabled. Enable feedback_channel in .pd/feature-flags.yaml to use feedback reports.');
84
- return;
81
+ && Object.hasOwn(ctx.featureFlags, 'feedback_channel')) {
82
+ const feedbackChannel = ctx.featureFlags.feedback_channel;
83
+ if (feedbackChannel && !feedbackChannel.enabled) {
84
+ sendError(res, 403, 'feedback_channel_disabled', 'feedback_channel feature flag is disabled. Enable feedback_channel in .pd/feature-flags.yaml to use feedback reports.');
85
+ return;
86
+ }
85
87
  }
86
88
  const bodyResult = await readJsonBody(req);
87
89
  if (!bodyResult.ok) {
88
90
  sendBadRequest(res, bodyResult.error);
89
91
  return;
90
92
  }
91
- if (bodyResult.value === null || typeof bodyResult.value !== 'object') {
93
+ if (bodyResult.value === null || typeof bodyResult.value !== 'object' || Array.isArray(bodyResult.value)) {
92
94
  sendBadRequest(res, 'request body must be a JSON object with {input, diagnostics}');
93
95
  return;
94
96
  }
@@ -18,9 +18,14 @@ export async function handleLifecycleRoute(req, res, workspaceDir, subPath) {
18
18
  // GET /api/v1/lifecycle/principles/:principleId
19
19
  const principleMatch = /^[/]principles[/]([^/]+)$/.exec(subPath);
20
20
  if (principleMatch) {
21
+ const [, rawId] = principleMatch;
22
+ if (!rawId) {
23
+ sendError(res, 400, 'invalid_encoding', 'Principle ID is missing');
24
+ return;
25
+ }
21
26
  let principleId;
22
27
  try {
23
- principleId = decodeURIComponent(principleMatch[1]);
28
+ principleId = decodeURIComponent(rawId);
24
29
  }
25
30
  catch {
26
31
  sendError(res, 400, 'invalid_encoding', 'Principle ID contains invalid percent encoding');
@@ -96,7 +96,7 @@ export async function handlePrinciplesRoute({ req, res, workspaceDir, subPath, }
96
96
  sendSuccess(res, result);
97
97
  }
98
98
  catch (err) {
99
- sendError(res, 500, 'principles_list_error', err.message);
99
+ sendError(res, 500, 'principles_list_error', err instanceof Error ? err.message : String(err));
100
100
  }
101
101
  return;
102
102
  }
@@ -104,6 +104,10 @@ export async function handlePrinciplesRoute({ req, res, workspaceDir, subPath, }
104
104
  const trajectoryMatch = /^\/([^/]+)\/trajectory$/.exec(subPath);
105
105
  if (trajectoryMatch) {
106
106
  const [, rawPrincipleId] = trajectoryMatch;
107
+ if (!rawPrincipleId) {
108
+ sendError(res, 400, 'invalid_principle_id', 'Principle ID is missing');
109
+ return;
110
+ }
107
111
  let decodedPrincipleId;
108
112
  try {
109
113
  decodedPrincipleId = decodeURIComponent(rawPrincipleId);
@@ -130,6 +134,10 @@ export async function handlePrinciplesRoute({ req, res, workspaceDir, subPath, }
130
134
  const detailMatch = /^\/([^/]+)$/.exec(subPath);
131
135
  if (detailMatch) {
132
136
  const [, principleId] = detailMatch;
137
+ if (!principleId) {
138
+ sendError(res, 400, 'invalid_principle_id', 'Principle ID is missing');
139
+ return;
140
+ }
133
141
  try {
134
142
  const result = await model.getPrincipleDetail(principleId);
135
143
  if (!result) {
@@ -139,7 +147,7 @@ export async function handlePrinciplesRoute({ req, res, workspaceDir, subPath, }
139
147
  sendSuccess(res, result);
140
148
  }
141
149
  catch (err) {
142
- sendError(res, 500, 'principle_detail_error', err.message);
150
+ sendError(res, 500, 'principle_detail_error', err instanceof Error ? err.message : String(err));
143
151
  }
144
152
  return;
145
153
  }
@@ -56,6 +56,10 @@ export function createWorkspacesRoutes(configStore, workspaceService) {
56
56
  return;
57
57
  }
58
58
  const [, wsName, rest] = nameMatch;
59
+ if (!wsName) {
60
+ sendError(res, 400, 'invalid_name', 'Workspace name is missing');
61
+ return;
62
+ }
59
63
  let decodedWsName;
60
64
  try {
61
65
  decodedWsName = decodeURIComponent(wsName);
@@ -63,7 +63,10 @@ export function computeValueBuckets(principles, bucketCount = 5) {
63
63
  }));
64
64
  for (const p of principles) {
65
65
  const bucketIndex = Math.min(Math.floor(p.valueScore / bucketSize), bucketCount - 1);
66
- buckets[bucketIndex].count++;
66
+ const bucket = buckets[bucketIndex];
67
+ if (bucket) {
68
+ bucket.count++;
69
+ }
67
70
  }
68
71
  return buckets;
69
72
  }
@@ -27,7 +27,7 @@ function detectCodeBlocks(text) {
27
27
  if (match.index > lastIndex) {
28
28
  parts.push({ type: "text", content: text.slice(lastIndex, match.index) });
29
29
  }
30
- parts.push({ type: "code", language: match[1] || "", code: match[2].trimEnd() });
30
+ parts.push({ type: "code", language: match[1] || "", code: (match[2] ?? "").trimEnd() });
31
31
  lastIndex = match.index + match[0].length;
32
32
  }
33
33
  if (lastIndex < text.length) {
@@ -77,18 +77,22 @@ function renderTextBlock(text) {
77
77
  inList = false;
78
78
  }
79
79
  if (headingMatch) {
80
- const level = headingMatch[1].length;
80
+ const levelStr = headingMatch[1] ?? "";
81
+ const content = headingMatch[2] ?? "";
82
+ const level = levelStr.length;
81
83
  const Tag = `h${level}`;
82
84
  const sizeClass = level === 1 ? "text-lg" : level === 2 ? "text-base" : "text-sm";
83
- nodes.push(_jsx(Tag, { className: cn("font-semibold mt-3 mb-1", sizeClass), children: renderInlineMarkdown(headingMatch[2]) }, key++));
85
+ nodes.push(_jsx(Tag, { className: cn("font-semibold mt-3 mb-1", sizeClass), children: renderInlineMarkdown(content) }, key++));
84
86
  }
85
87
  else if (listItemMatch) {
86
88
  inList = true;
87
- nodes.push(_jsxs("div", { className: "flex items-start gap-2 ml-2", children: [_jsx("span", { className: "text-muted-foreground mt-0.5", children: "\u2022" }), _jsx("span", { className: "flex-1", children: renderInlineMarkdown(listItemMatch[1]) })] }, key++));
89
+ const itemText = listItemMatch[1] ?? "";
90
+ nodes.push(_jsxs("div", { className: "flex items-start gap-2 ml-2", children: [_jsx("span", { className: "text-muted-foreground mt-0.5", children: "\u2022" }), _jsx("span", { className: "flex-1", children: renderInlineMarkdown(itemText) })] }, key++));
88
91
  }
89
92
  else if (numberedItemMatch) {
90
93
  inList = true;
91
- nodes.push(_jsxs("div", { className: "flex items-start gap-2 ml-2", children: [_jsx("span", { className: "text-muted-foreground text-xs tabular-nums", children: "\u2022" }), _jsx("span", { className: "flex-1", children: renderInlineMarkdown(numberedItemMatch[1]) })] }, key++));
94
+ const itemText = numberedItemMatch[1] ?? "";
95
+ nodes.push(_jsxs("div", { className: "flex items-start gap-2 ml-2", children: [_jsx("span", { className: "text-muted-foreground text-xs tabular-nums", children: "\u2022" }), _jsx("span", { className: "flex-1", children: renderInlineMarkdown(itemText) })] }, key++));
92
96
  }
93
97
  else if (line.trim() === "") {
94
98
  nodes.push(_jsx("div", { className: "h-2" }, key++));
@@ -726,8 +726,7 @@
726
726
  "code_tool_hook": "RuleHost",
727
727
  "defer_archive": "Defer Archive",
728
728
  "prompt": "Prompt",
729
- "skill": "Skill (retired)",
730
- "model_training": "Model Training (retired)"
729
+ "skill": "Skill (retired)"
731
730
  },
732
731
  "retired": "This channel is retired and cannot be actioned",
733
732
  "riskLevel": "Risk Level"
@@ -726,8 +726,7 @@
726
726
  "code_tool_hook": "RuleHost",
727
727
  "defer_archive": "延迟归档",
728
728
  "prompt": "提示词注入",
729
- "skill": "技能激活(已停用)",
730
- "model_training": "模型训练(已停用)"
729
+ "skill": "技能激活(已停用)"
731
730
  },
732
731
  "retired": "此通道已停用,无法执行审批操作",
733
732
  "riskLevel": "风险级别"
@@ -53,7 +53,6 @@ const LOCAL_LABELS = {
53
53
  'defer_archive': '延迟归档',
54
54
  'code_tool_hook': 'Code Tool Hook',
55
55
  'skill': '技能激活(已停用)',
56
- 'model_training': '模型训练(已停用)',
57
56
  },
58
57
  readiness: {
59
58
  'ready': '就绪',
@@ -149,7 +148,10 @@ export function enumLabel(category, value, t) {
149
148
  // 2. Fall back to local map
150
149
  const localMap = LOCAL_LABELS[category];
151
150
  if (localMap && Object.hasOwn(localMap, value)) {
152
- return localMap[value];
151
+ const label = localMap[value];
152
+ if (label !== undefined) {
153
+ return label;
154
+ }
153
155
  }
154
156
  // 3. Last resort: raw value
155
157
  return value;