create-principles-disciple 1.150.2 → 1.150.4

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 (267) hide show
  1. package/_release/product-identity.json +1 -1
  2. package/codex-adapter/dist/ingestion/admission.js +2 -0
  3. package/codex-adapter/dist/pd-hook.d.ts +7 -5
  4. package/codex-adapter/dist/pd-hook.js +18 -7
  5. package/codex-adapter/dist/tool-semantics.js +5 -1
  6. package/codex-adapter/dist/worker/workspace-worker.js +4 -2
  7. package/codex-adapter/package.json +1 -1
  8. package/console/dist/lib/utils.js +16 -1
  9. package/console/dist/web/assets/app.css +147 -46
  10. package/console/dist/web/assets/app.js +35 -32
  11. package/console/package.json +2 -0
  12. package/core/dist/runtime/activation/adaptive-selection-output.d.ts +35 -0
  13. package/core/dist/runtime/activation/adaptive-selection-output.d.ts.map +1 -0
  14. package/core/dist/runtime/activation/adaptive-selection-output.js +38 -0
  15. package/core/dist/runtime/activation/adaptive-selection-output.js.map +1 -0
  16. package/core/dist/runtime/activation-compatibility-read-model.d.ts.map +1 -1
  17. package/core/dist/runtime/activation-compatibility-read-model.js +2 -1
  18. package/core/dist/runtime/activation-compatibility-read-model.js.map +1 -1
  19. package/core/dist/runtime/adapter/artificer-l2-adapter.d.ts.map +1 -1
  20. package/core/dist/runtime/adapter/artificer-l2-adapter.js +89 -27
  21. package/core/dist/runtime/adapter/artificer-l2-adapter.js.map +1 -1
  22. package/core/dist/runtime/adapter/context-budget.d.ts +49 -0
  23. package/core/dist/runtime/adapter/context-budget.d.ts.map +1 -0
  24. package/core/dist/runtime/adapter/context-budget.js +127 -0
  25. package/core/dist/runtime/adapter/context-budget.js.map +1 -0
  26. package/core/dist/runtime/adapter/output-schema-registry.d.ts.map +1 -1
  27. package/core/dist/runtime/adapter/output-schema-registry.js +7 -0
  28. package/core/dist/runtime/adapter/output-schema-registry.js.map +1 -1
  29. package/core/dist/runtime/adapter/pi-ai-runtime-adapter.d.ts +30 -7
  30. package/core/dist/runtime/adapter/pi-ai-runtime-adapter.d.ts.map +1 -1
  31. package/core/dist/runtime/adapter/pi-ai-runtime-adapter.js +559 -211
  32. package/core/dist/runtime/adapter/pi-ai-runtime-adapter.js.map +1 -1
  33. package/core/dist/runtime/candidate-audit.d.ts.map +1 -1
  34. package/core/dist/runtime/candidate-audit.js +2 -1
  35. package/core/dist/runtime/candidate-audit.js.map +1 -1
  36. package/core/dist/runtime/config/pd-config-effective.d.ts.map +1 -1
  37. package/core/dist/runtime/config/pd-config-effective.js +2 -0
  38. package/core/dist/runtime/config/pd-config-effective.js.map +1 -1
  39. package/core/dist/runtime/config/pd-config-types.d.ts +52 -0
  40. package/core/dist/runtime/config/pd-config-types.d.ts.map +1 -1
  41. package/core/dist/runtime/config/pd-config-types.js.map +1 -1
  42. package/core/dist/runtime/config/pd-config-validate.d.ts.map +1 -1
  43. package/core/dist/runtime/config/pd-config-validate.js +134 -0
  44. package/core/dist/runtime/config/pd-config-validate.js.map +1 -1
  45. package/core/dist/runtime/feature-flags/feature-flag-contract.d.ts.map +1 -1
  46. package/core/dist/runtime/feature-flags/feature-flag-contract.js +8 -0
  47. package/core/dist/runtime/feature-flags/feature-flag-contract.js.map +1 -1
  48. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.d.ts.map +1 -1
  49. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js +24 -0
  50. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js.map +1 -1
  51. package/core/dist/runtime/index.d.ts +2 -0
  52. package/core/dist/runtime/index.d.ts.map +1 -1
  53. package/core/dist/runtime/index.js +2 -0
  54. package/core/dist/runtime/index.js.map +1 -1
  55. package/core/dist/runtime/internalization/rule-host-input-builder.d.ts +16 -0
  56. package/core/dist/runtime/internalization/rule-host-input-builder.d.ts.map +1 -1
  57. package/core/dist/runtime/internalization/rule-host-input-builder.js +18 -0
  58. package/core/dist/runtime/internalization/rule-host-input-builder.js.map +1 -1
  59. package/core/dist/runtime/internalization/split-diagnostician-runner.d.ts +8 -0
  60. package/core/dist/runtime/internalization/split-diagnostician-runner.d.ts.map +1 -1
  61. package/core/dist/runtime/internalization/split-diagnostician-runner.js +24 -2
  62. package/core/dist/runtime/internalization/split-diagnostician-runner.js.map +1 -1
  63. package/core/dist/runtime/internalization/tool-semantic-registry.d.ts +26 -0
  64. package/core/dist/runtime/internalization/tool-semantic-registry.d.ts.map +1 -1
  65. package/core/dist/runtime/internalization/tool-semantic-registry.js +55 -5
  66. package/core/dist/runtime/internalization/tool-semantic-registry.js.map +1 -1
  67. package/core/dist/runtime/internalization-chain-integrity-read-model.d.ts.map +1 -1
  68. package/core/dist/runtime/internalization-chain-integrity-read-model.js +2 -2
  69. package/core/dist/runtime/internalization-chain-integrity-read-model.js.map +1 -1
  70. package/core/dist/runtime/internalization-integrity-remediation.d.ts.map +1 -1
  71. package/core/dist/runtime/internalization-integrity-remediation.js +2 -2
  72. package/core/dist/runtime/internalization-integrity-remediation.js.map +1 -1
  73. package/core/dist/runtime/operator-health-read-model.d.ts.map +1 -1
  74. package/core/dist/runtime/operator-health-read-model.js +2 -2
  75. package/core/dist/runtime/operator-health-read-model.js.map +1 -1
  76. package/core/dist/runtime/pain-recall-read-model.d.ts.map +1 -1
  77. package/core/dist/runtime/pain-recall-read-model.js +4 -3
  78. package/core/dist/runtime/pain-recall-read-model.js.map +1 -1
  79. package/core/dist/runtime/pruning-read-model.d.ts.map +1 -1
  80. package/core/dist/runtime/pruning-read-model.js +3 -2
  81. package/core/dist/runtime/pruning-read-model.js.map +1 -1
  82. package/core/dist/runtime/risk/risk-calculator-policy.d.ts +12 -2
  83. package/core/dist/runtime/risk/risk-calculator-policy.d.ts.map +1 -1
  84. package/core/dist/runtime/risk/risk-calculator-policy.js +33 -22
  85. package/core/dist/runtime/risk/risk-calculator-policy.js.map +1 -1
  86. package/core/dist/runtime/schema-conformance-read-model.js +2 -2
  87. package/core/dist/runtime/schema-conformance-read-model.js.map +1 -1
  88. package/core/dist/runtime/store/sqlite-connection.d.ts +0 -5
  89. package/core/dist/runtime/store/sqlite-connection.d.ts.map +1 -1
  90. package/core/dist/runtime/store/sqlite-connection.js +4 -12
  91. package/core/dist/runtime/store/sqlite-connection.js.map +1 -1
  92. package/core/dist/runtime/store/storage-paths.d.ts +17 -0
  93. package/core/dist/runtime/store/storage-paths.d.ts.map +1 -0
  94. package/core/dist/runtime/store/storage-paths.js +52 -0
  95. package/core/dist/runtime/store/storage-paths.js.map +1 -0
  96. package/core/dist/runtime/trajectory-retention.d.ts +257 -0
  97. package/core/dist/runtime/trajectory-retention.d.ts.map +1 -0
  98. package/core/dist/runtime/trajectory-retention.js +598 -0
  99. package/core/dist/runtime/trajectory-retention.js.map +1 -0
  100. package/core/dist/telemetry-event.d.ts +2 -2
  101. package/core/dist/telemetry-event.d.ts.map +1 -1
  102. package/core/dist/telemetry-event.js +5 -0
  103. package/core/dist/telemetry-event.js.map +1 -1
  104. package/core/dist/trajectory-store.d.ts +9 -9
  105. package/core/dist/trajectory-store.d.ts.map +1 -1
  106. package/core/dist/trajectory-store.js +9 -12
  107. package/core/dist/trajectory-store.js.map +1 -1
  108. package/core/package.json +1 -1
  109. package/dist/installers/codex-host-installer.d.ts.map +1 -1
  110. package/dist/installers/codex-host-installer.js +92 -5
  111. package/dist/installers/codex-host-installer.js.map +1 -1
  112. package/dist/installers/mcp-binding-shape-mirror.d.ts +27 -0
  113. package/dist/installers/mcp-binding-shape-mirror.d.ts.map +1 -0
  114. package/dist/installers/mcp-binding-shape-mirror.js +105 -0
  115. package/dist/installers/mcp-binding-shape-mirror.js.map +1 -0
  116. package/dist/skill-catalog.d.ts +35 -0
  117. package/dist/skill-catalog.d.ts.map +1 -0
  118. package/dist/skill-catalog.js +85 -0
  119. package/dist/skill-catalog.js.map +1 -0
  120. package/dist/skill-delivery-parity.d.ts +22 -0
  121. package/dist/skill-delivery-parity.d.ts.map +1 -0
  122. package/dist/skill-delivery-parity.js +31 -0
  123. package/dist/skill-delivery-parity.js.map +1 -0
  124. package/host-runtime/dist/active-principle-prompt.d.ts +8 -0
  125. package/host-runtime/dist/active-principle-prompt.js +15 -5
  126. package/host-runtime/dist/adaptive-decision-protocol.d.ts +142 -0
  127. package/host-runtime/dist/adaptive-decision-protocol.js +190 -0
  128. package/host-runtime/dist/adaptive-priority-provider.d.ts +37 -13
  129. package/host-runtime/dist/adaptive-priority-provider.js +65 -62
  130. package/host-runtime/dist/adaptive-selection.d.ts +67 -62
  131. package/host-runtime/dist/adaptive-selection.js +218 -301
  132. package/host-runtime/dist/adaptive-skip-decision.d.ts +26 -14
  133. package/host-runtime/dist/adaptive-skip-decision.js +33 -29
  134. package/host-runtime/dist/codex-rule-context-provider.js +4 -1
  135. package/host-runtime/dist/governance-observation-store.d.ts +40 -1
  136. package/host-runtime/dist/governance-observation-store.js +188 -9
  137. package/host-runtime/dist/governance-signal-admission.d.ts +19 -3
  138. package/host-runtime/dist/governance-signal-admission.js +12 -4
  139. package/host-runtime/dist/host-tool-declaration.d.ts +18 -2
  140. package/host-runtime/dist/host-tool-declaration.js +67 -11
  141. package/host-runtime/dist/host-tool-semantic-resolver.d.ts +7 -0
  142. package/host-runtime/dist/host-tool-semantic-resolver.js +22 -2
  143. package/host-runtime/dist/index.d.ts +3 -0
  144. package/host-runtime/dist/index.js +14 -0
  145. package/host-runtime/dist/production-rulehost-gate.js +36 -4
  146. package/host-runtime/dist/trajectory-retention.d.ts +147 -0
  147. package/host-runtime/dist/trajectory-retention.js +907 -0
  148. package/host-runtime/package.json +1 -1
  149. package/install-layout/dist/index.d.ts +9 -2
  150. package/install-layout/dist/index.js +26 -9
  151. package/install-layout/dist/mcp-binding-contract.d.ts +91 -0
  152. package/install-layout/dist/mcp-binding-contract.js +230 -0
  153. package/install-layout/package.json +1 -1
  154. package/package.json +4 -4
  155. package/pd-cli/dist/commands/build-trajectory-evidence.d.ts.map +1 -1
  156. package/pd-cli/dist/commands/build-trajectory-evidence.js +17 -11
  157. package/pd-cli/dist/commands/build-trajectory-evidence.js.map +1 -1
  158. package/pd-cli/dist/commands/codex-reconcile.d.ts +7 -0
  159. package/pd-cli/dist/commands/codex-reconcile.d.ts.map +1 -1
  160. package/pd-cli/dist/commands/codex-reconcile.js +11 -2
  161. package/pd-cli/dist/commands/codex-reconcile.js.map +1 -1
  162. package/pd-cli/dist/commands/codex-worker.d.ts.map +1 -1
  163. package/pd-cli/dist/commands/codex-worker.js +35 -0
  164. package/pd-cli/dist/commands/codex-worker.js.map +1 -1
  165. package/pd-cli/dist/commands/command-helpers.d.ts +1 -1
  166. package/pd-cli/dist/commands/command-helpers.js +1 -1
  167. package/pd-cli/dist/commands/errors-list.d.ts +1 -1
  168. package/pd-cli/dist/commands/errors-list.js +1 -1
  169. package/pd-cli/dist/commands/health-mcp.d.ts +23 -1
  170. package/pd-cli/dist/commands/health-mcp.d.ts.map +1 -1
  171. package/pd-cli/dist/commands/health-mcp.js +81 -22
  172. package/pd-cli/dist/commands/health-mcp.js.map +1 -1
  173. package/pd-cli/dist/commands/health.d.ts +1 -1
  174. package/pd-cli/dist/commands/health.d.ts.map +1 -1
  175. package/pd-cli/dist/commands/health.js +12 -5
  176. package/pd-cli/dist/commands/health.js.map +1 -1
  177. package/pd-cli/dist/commands/principles-stats.d.ts +1 -1
  178. package/pd-cli/dist/commands/principles-stats.js +1 -1
  179. package/pd-cli/dist/commands/trajectory-retention.d.ts +23 -0
  180. package/pd-cli/dist/commands/trajectory-retention.d.ts.map +1 -0
  181. package/pd-cli/dist/commands/trajectory-retention.js +159 -0
  182. package/pd-cli/dist/commands/trajectory-retention.js.map +1 -0
  183. package/pd-cli/dist/commands/workbuddy-setup.d.ts +69 -0
  184. package/pd-cli/dist/commands/workbuddy-setup.d.ts.map +1 -0
  185. package/pd-cli/dist/commands/workbuddy-setup.js +379 -0
  186. package/pd-cli/dist/commands/workbuddy-setup.js.map +1 -0
  187. package/pd-cli/dist/commands/workbuddy-worker.d.ts.map +1 -1
  188. package/pd-cli/dist/commands/workbuddy-worker.js +42 -6
  189. package/pd-cli/dist/commands/workbuddy-worker.js.map +1 -1
  190. package/pd-cli/dist/index.d.ts +1 -7
  191. package/pd-cli/dist/index.d.ts.map +1 -1
  192. package/pd-cli/dist/index.js +15 -1201
  193. package/pd-cli/dist/index.js.map +1 -1
  194. package/pd-cli/dist/program.d.ts +17 -0
  195. package/pd-cli/dist/program.d.ts.map +1 -0
  196. package/pd-cli/dist/program.js +1263 -0
  197. package/pd-cli/dist/program.js.map +1 -0
  198. package/pd-cli/dist/services/delivery-surfaces.d.ts.map +1 -1
  199. package/pd-cli/dist/services/delivery-surfaces.js +7 -5
  200. package/pd-cli/dist/services/delivery-surfaces.js.map +1 -1
  201. package/pd-cli/dist/services/version-report.d.ts.map +1 -1
  202. package/pd-cli/dist/services/version-report.js +30 -4
  203. package/pd-cli/dist/services/version-report.js.map +1 -1
  204. package/pd-cli/package.json +1 -1
  205. package/pd-mcp-server/dist/version.d.ts +1 -1
  206. package/pd-mcp-server/dist/version.js +1 -1
  207. package/pd-mcp-server/package.json +3 -1
  208. package/plugin/dist/bundle.js +477 -471
  209. package/plugin/dist/constants/tools.d.ts +8 -1
  210. package/plugin/dist/core/trajectory-retention-trigger.d.ts +13 -0
  211. package/plugin/dist/core/trajectory.d.ts +14 -0
  212. package/plugin/dist/hooks/gate-block-helper.d.ts +17 -0
  213. package/plugin/dist/hooks/gate.d.ts +7 -2
  214. package/plugin/dist/host-runtime/openclaw-host-runtime.d.ts +1 -0
  215. package/plugin/dist/index.d.ts +5 -0
  216. package/plugin/dist/openclaw.plugin.json +1 -1
  217. package/plugin/dist/rulehost-evidence.js +29 -23
  218. package/plugin/dist/templates/langs/en/skills/pd-cli-operator/SKILL.md +16 -5
  219. package/plugin/dist/templates/langs/en/skills/pd-control/SKILL.md +7 -6
  220. package/plugin/dist/templates/langs/en/skills/pd-pain-signal/SKILL.md +141 -28
  221. package/plugin/dist/templates/langs/en/skills/pd-review/SKILL.md +15 -1
  222. package/plugin/dist/templates/langs/zh/skills/pd-cli-operator/SKILL.md +16 -5
  223. package/plugin/dist/templates/langs/zh/skills/pd-control/SKILL.md +7 -6
  224. package/plugin/dist/templates/langs/zh/skills/pd-pain-signal/SKILL.md +142 -29
  225. package/plugin/dist/templates/langs/zh/skills/pd-review/SKILL.md +15 -1
  226. package/plugin/openclaw.plugin.json +1 -1
  227. package/plugin/package.json +1 -1
  228. package/plugin/templates/langs/en/skills/pd-cli-operator/SKILL.md +16 -5
  229. package/plugin/templates/langs/en/skills/pd-control/SKILL.md +7 -6
  230. package/plugin/templates/langs/en/skills/pd-pain-signal/SKILL.md +141 -28
  231. package/plugin/templates/langs/en/skills/pd-review/SKILL.md +15 -1
  232. package/plugin/templates/langs/zh/skills/pd-cli-operator/SKILL.md +16 -5
  233. package/plugin/templates/langs/zh/skills/pd-control/SKILL.md +7 -6
  234. package/plugin/templates/langs/zh/skills/pd-pain-signal/SKILL.md +142 -29
  235. package/plugin/templates/langs/zh/skills/pd-review/SKILL.md +15 -1
  236. package/release-manager/dist/installers/codex-host-installer.js +92 -5
  237. package/release-manager/dist/installers/mcp-binding-shape-mirror.js +105 -0
  238. package/release-manager/package.json +1 -1
  239. package/workbuddy-adapter/dist/codec/input-decoder.d.ts +10 -0
  240. package/workbuddy-adapter/dist/codec/input-decoder.js +62 -5
  241. package/workbuddy-adapter/dist/host-adapter.js +1 -0
  242. package/workbuddy-adapter/dist/index.d.ts +1 -0
  243. package/workbuddy-adapter/dist/index.js +1 -0
  244. package/workbuddy-adapter/dist/ingestion/catch-up.d.ts +25 -0
  245. package/workbuddy-adapter/dist/ingestion/catch-up.js +161 -0
  246. package/workbuddy-adapter/dist/ingestion/encode-cwd.d.ts +6 -0
  247. package/workbuddy-adapter/dist/ingestion/encode-cwd.js +39 -0
  248. package/workbuddy-adapter/dist/ingestion/index.d.ts +13 -0
  249. package/workbuddy-adapter/dist/ingestion/index.js +13 -0
  250. package/workbuddy-adapter/dist/ingestion/ingestion.d.ts +46 -0
  251. package/workbuddy-adapter/dist/ingestion/ingestion.js +135 -0
  252. package/workbuddy-adapter/dist/ingestion/transcript-decoder.d.ts +70 -0
  253. package/workbuddy-adapter/dist/ingestion/transcript-decoder.js +554 -0
  254. package/workbuddy-adapter/dist/ingestion/transcript-path.d.ts +39 -0
  255. package/workbuddy-adapter/dist/ingestion/transcript-path.js +117 -0
  256. package/workbuddy-adapter/dist/ingestion/transcript-source.d.ts +15 -0
  257. package/workbuddy-adapter/dist/ingestion/transcript-source.js +152 -0
  258. package/workbuddy-adapter/dist/pd-hook.d.ts +8 -0
  259. package/workbuddy-adapter/dist/pd-hook.js +59 -2
  260. package/workbuddy-adapter/dist/worker/workspace-worker.d.ts +9 -0
  261. package/workbuddy-adapter/dist/worker/workspace-worker.js +46 -17
  262. package/workbuddy-adapter/package.json +1 -1
  263. package/workbuddy-adapter/plugin/hooks/hooks.json +11 -0
  264. package/workbuddy-adapter/plugin/skills/pd-cli-operator/SKILL.md +57 -19
  265. package/workbuddy-adapter/plugin/skills/pd-control/SKILL.md +21 -9
  266. package/workbuddy-adapter/plugin/skills/pd-pain-signal/SKILL.md +72 -61
  267. package/workbuddy-adapter/plugin/skills/pd-review/SKILL.md +27 -12
@@ -3,64 +3,75 @@ import { ADAPTIVE_SELECTION_LIMITS, runAdaptiveSelection, } from './adaptive-sel
3
3
  import { decideAdaptiveSkip } from './adaptive-skip-decision.js';
4
4
  /** Independent switch. `features.host.codex.enabled` remains the whole-hook gate. */
5
5
  export const ADAPTIVE_ACTIVATION_FLAG = 'host.codex.adaptive_activation';
6
- export function resolveAdaptiveSelectionModel(config, env) {
7
- const feature = config.features[ADAPTIVE_ACTIVATION_FLAG];
6
+ /**
7
+ * PRI-1182 §2: time kept back from the host window for the principle assembly
8
+ * and the hook's own output. Selection never spends the reserve.
9
+ */
10
+ export const ADAPTIVE_OUTPUT_RESERVE_MS = 200;
11
+ export function resolveAdaptiveSelectionModel(config, env, flag = ADAPTIVE_ACTIVATION_FLAG) {
12
+ const feature = config.features[flag];
8
13
  if (feature?.enabled !== true) {
9
14
  return {
10
15
  ok: false,
11
- reason: `${ADAPTIVE_ACTIVATION_FLAG} is disabled in .pd/config.yaml`,
12
- nextAction: `Enable it explicitly with ${ADAPTIVE_ACTIVATION_FLAG}: {enabled: true}`,
13
- };
14
- }
15
- const profileId = config.internalAgents.defaultRuntime;
16
- const profile = config.runtimeProfiles[profileId];
17
- if (!profile) {
18
- return {
19
- ok: false,
20
- reason: `Runtime profile '${profileId}' not found`,
21
- nextAction: `Add runtime profile '${profileId}' to runtimeProfiles`,
16
+ readiness: 'disabled',
17
+ reason: `${flag} is disabled in .pd/config.yaml`,
18
+ nextAction: `Enable it explicitly with ${flag}: {enabled: true}`,
22
19
  };
23
20
  }
24
- if (profile.type !== 'pi-ai') {
21
+ // PRI-1182: the Adaptive path has its OWN endpoint + model + credential
22
+ // reference. It no longer borrows a pi-ai runtime profile, because the
23
+ // Decisions protocol is a single scoring endpoint, not a chat completion.
24
+ const section = config.adaptiveActivation;
25
+ if (!section) {
25
26
  return {
26
27
  ok: false,
27
- reason: `Runtime profile '${profileId}' is '${profile.type}', not pi-ai`,
28
- nextAction: 'ADR-0029 requires a pi-ai runtime profile for adaptive selection',
28
+ readiness: 'needs_setup',
29
+ reason: 'adaptiveActivation is not configured in .pd/config.yaml',
30
+ nextAction: 'Add adaptiveActivation: {endpoint, model, apiKeyEnv} to .pd/config.yaml',
29
31
  };
30
32
  }
31
- if (!profile.provider || !profile.model || !profile.apiKeyEnv) {
33
+ if (!section.endpoint || !section.model || !section.apiKeyEnv) {
32
34
  return {
33
35
  ok: false,
34
- reason: `pi-ai profile '${profileId}' missing provider/model/apiKeyEnv`,
35
- nextAction: `Set provider, model and apiKeyEnv on runtime profile '${profileId}'`,
36
+ readiness: 'needs_setup',
37
+ reason: 'adaptiveActivation is missing endpoint/model/apiKeyEnv',
38
+ nextAction: 'Set endpoint (https URL), model and apiKeyEnv on adaptiveActivation',
36
39
  };
37
40
  }
38
- if (!Object.hasOwn(env, profile.apiKeyEnv) || !env[profile.apiKeyEnv]) {
41
+ if (!Object.hasOwn(env, section.apiKeyEnv) || !env[section.apiKeyEnv]) {
39
42
  return {
40
43
  ok: false,
41
- reason: `Environment variable '${profile.apiKeyEnv}' is not set or empty`,
42
- nextAction: `Set the environment variable '${profile.apiKeyEnv}' with a valid API key`,
44
+ readiness: 'needs_setup',
45
+ reason: `Environment variable '${section.apiKeyEnv}' is not set or empty`,
46
+ nextAction: `Set the environment variable '${section.apiKeyEnv}' with a valid API key`,
43
47
  };
44
48
  }
45
49
  return {
46
50
  ok: true,
47
- profileId,
48
51
  model: {
49
- provider: profile.provider,
50
- model: profile.model,
51
- apiKeyEnv: profile.apiKeyEnv,
52
- ...(profile.baseUrl ? { baseUrl: profile.baseUrl } : {}),
52
+ endpoint: section.endpoint,
53
+ model: section.model,
54
+ apiKeyEnv: section.apiKeyEnv,
55
+ ...(section.provider ? { provider: section.provider } : {}),
56
+ ...(section.responseModels && section.responseModels.length > 0
57
+ ? { allowedResponseModels: section.responseModels }
58
+ : {}),
53
59
  },
54
60
  };
55
61
  }
56
62
  export function createAdaptivePriorityProvider(options) {
57
63
  const now = options.now ?? Date.now;
58
- const firstByteTimeoutMs = options.firstByteTimeoutMs ?? ADAPTIVE_SELECTION_LIMITS.firstByteTimeoutMs;
59
- const generationTimeoutMs = options.generationTimeoutMs ?? ADAPTIVE_SELECTION_LIMITS.generationTimeoutMs;
60
- return async (event) => {
64
+ const requestTimeoutMs = options.requestTimeoutMs ?? ADAPTIVE_SELECTION_LIMITS.requestTimeoutMs;
65
+ const outputReserveMs = options.outputReserveMs ?? ADAPTIVE_OUTPUT_RESERVE_MS;
66
+ return async (event, candidates) => {
61
67
  if (event.kind !== 'before_prompt_build')
62
68
  return undefined;
63
69
  const { sessionId, turnId, promptContent, workspaceDir } = event.context;
70
+ // The host budget starts before selection; the request budget starts at send.
71
+ const nowMs = now();
72
+ const hostDeadlineAt = options.outerDeadlineAt === undefined
73
+ ? undefined
74
+ : options.outerDeadlineAt - outputReserveMs;
64
75
  // PRI-1181: deterministic gate BEFORE the candidate read. A skipped turn
65
76
  // costs zero reads and zero sends; the Native body is untouched.
66
77
  const skip = decideAdaptiveSkip({
@@ -68,11 +79,9 @@ export function createAdaptivePriorityProvider(options) {
68
79
  sessionId,
69
80
  turnId,
70
81
  prompt: promptContent ?? '',
71
- ...(options.outerDeadlineAt === undefined
72
- ? {}
73
- : { remainingBudgetMs: options.outerDeadlineAt - now() }),
74
- ...(options.minRemainingBudgetMs !== undefined
75
- ? { minRemainingBudgetMs: options.minRemainingBudgetMs }
82
+ remainingBudgetMs: Math.max(0, Math.min(requestTimeoutMs, (hostDeadlineAt ?? Infinity) - nowMs)),
83
+ ...(options.minExecutableBudgetMs !== undefined
84
+ ? { minExecutableBudgetMs: options.minExecutableBudgetMs }
76
85
  : {}),
77
86
  });
78
87
  if (skip.skip) {
@@ -81,11 +90,16 @@ export function createAdaptivePriorityProvider(options) {
81
90
  reason: skip.reason,
82
91
  stage: 'gate',
83
92
  sends: 0,
93
+ requestSentAt: null,
84
94
  firstByteAt: null,
85
95
  generationEndedAt: null,
96
+ validatedAt: null,
86
97
  cancelledAt: null,
87
98
  httpStatus: null,
88
99
  finishReason: 'skipped',
100
+ modelObserved: null,
101
+ providerObserved: null,
102
+ decision: null,
89
103
  failures: [],
90
104
  });
91
105
  return undefined;
@@ -93,27 +107,14 @@ export function createAdaptivePriorityProvider(options) {
93
107
  // The gate already proved identity and a non-blank prompt (rc-3); the
94
108
  // selector only needs the prompt body from here on.
95
109
  const prompt = promptContent ?? '';
96
- const admissionDeadlineAt = options.outerDeadlineAt === undefined
97
- ? now() + firstByteTimeoutMs
98
- : Math.min(now() + firstByteTimeoutMs, options.outerDeadlineAt);
99
- const remainingBudgetMs = options.outerDeadlineAt === undefined
100
- ? firstByteTimeoutMs
101
- : Math.max(1, options.outerDeadlineAt - now());
102
- const effectiveGenerationTimeoutMs = options.outerDeadlineAt === undefined
103
- ? generationTimeoutMs
104
- : Math.min(generationTimeoutMs, remainingBudgetMs);
105
- // Reuse the selector's AbortSignal seam instead of a second timer: it is
106
- // combined with the first-byte and request signals inside the transport.
107
- const signal = options.outerDeadlineAt === undefined ? undefined : AbortSignal.timeout(remainingBudgetMs);
110
+ const signal = hostDeadlineAt === undefined ? undefined : AbortSignal.timeout(Math.max(1, hostDeadlineAt - now()));
108
111
  const outcome = await runAdaptiveSelection({
109
112
  workspaceDir: workspaceDir || options.workspaceDir,
110
113
  currentPrompt: prompt,
111
- admissionDeadlineAt,
114
+ candidates,
112
115
  model: options.model,
113
- generationTimeoutMs: effectiveGenerationTimeoutMs,
114
- ...(options.outerDeadlineAt !== undefined ? { outerDeadlineAt: options.outerDeadlineAt } : {}),
115
- ...(signal ? { signal } : {}),
116
- ...(options.maxTokens !== undefined ? { maxTokens: options.maxTokens } : {}),
116
+ requestTimeoutMs,
117
+ ...(hostDeadlineAt !== undefined ? { outerDeadlineAt: hostDeadlineAt, signal } : {}),
117
118
  ...(options.now ? { now: options.now } : {}),
118
119
  ...(options.fetchImpl ? { fetchImpl: options.fetchImpl } : {}),
119
120
  });
@@ -122,11 +123,16 @@ export function createAdaptivePriorityProvider(options) {
122
123
  reason: outcome.reason,
123
124
  stage: outcome.diagnostics.stage,
124
125
  sends: outcome.sends,
126
+ requestSentAt: outcome.diagnostics.requestSentAt,
125
127
  firstByteAt: outcome.diagnostics.firstByteAt,
126
128
  generationEndedAt: outcome.diagnostics.generationEndedAt,
129
+ validatedAt: outcome.diagnostics.validatedAt,
127
130
  cancelledAt: outcome.diagnostics.cancelledAt,
128
131
  httpStatus: outcome.diagnostics.httpStatus,
129
132
  finishReason: outcome.diagnostics.finishReason,
133
+ modelObserved: outcome.diagnostics.modelObserved,
134
+ providerObserved: outcome.diagnostics.providerObserved,
135
+ decision: outcome.diagnostics.decision,
130
136
  failures: [...outcome.diagnostics.failures],
131
137
  });
132
138
  if (outcome.status !== 'selected' || !outcome.target)
@@ -135,8 +141,7 @@ export function createAdaptivePriorityProvider(options) {
135
141
  artifactId: outcome.target.artifactId,
136
142
  activationId: outcome.target.activationId,
137
143
  additiveOnly: true,
138
- deadlineAt: options.outerDeadlineAt ?? admissionDeadlineAt + generationTimeoutMs,
139
- ...(signal ? { signal } : {}),
144
+ ...(hostDeadlineAt !== undefined ? { deadlineAt: hostDeadlineAt, signal } : {}),
140
145
  };
141
146
  };
142
147
  }
@@ -145,11 +150,11 @@ export function createAdaptivePriorityProvider(options) {
145
150
  * workspace config for the current turn.
146
151
  */
147
152
  export function createAdaptivePriorityProviderForConfig(config, workspaceDir, options = {}) {
148
- const resolved = resolveAdaptiveSelectionModel(config, options.env ?? process.env);
153
+ const resolved = resolveAdaptiveSelectionModel(config, options.env ?? process.env, options.flag);
149
154
  if (!resolved.ok) {
150
155
  return {
151
156
  ok: false,
152
- readiness: 'disabled',
157
+ readiness: resolved.readiness,
153
158
  reason: resolved.reason,
154
159
  nextAction: resolved.nextAction,
155
160
  };
@@ -157,11 +162,10 @@ export function createAdaptivePriorityProviderForConfig(config, workspaceDir, op
157
162
  const provider = createAdaptivePriorityProvider({
158
163
  workspaceDir,
159
164
  model: resolved.model,
160
- ...(options.firstByteTimeoutMs !== undefined ? { firstByteTimeoutMs: options.firstByteTimeoutMs } : {}),
161
- ...(options.generationTimeoutMs !== undefined ? { generationTimeoutMs: options.generationTimeoutMs } : {}),
165
+ ...(options.requestTimeoutMs !== undefined ? { requestTimeoutMs: options.requestTimeoutMs } : {}),
162
166
  ...(options.outerDeadlineAt !== undefined ? { outerDeadlineAt: options.outerDeadlineAt } : {}),
163
- ...(options.minRemainingBudgetMs !== undefined ? { minRemainingBudgetMs: options.minRemainingBudgetMs } : {}),
164
- ...(options.maxTokens !== undefined ? { maxTokens: options.maxTokens } : {}),
167
+ ...(options.outputReserveMs !== undefined ? { outputReserveMs: options.outputReserveMs } : {}),
168
+ ...(options.minExecutableBudgetMs !== undefined ? { minExecutableBudgetMs: options.minExecutableBudgetMs } : {}),
165
169
  ...(options.now ? { now: options.now } : {}),
166
170
  ...(options.fetchImpl ? { fetchImpl: options.fetchImpl } : {}),
167
171
  ...(options.onDiagnostic ? { onDiagnostic: options.onDiagnostic } : {}),
@@ -169,10 +173,9 @@ export function createAdaptivePriorityProviderForConfig(config, workspaceDir, op
169
173
  return {
170
174
  ok: true,
171
175
  readiness: 'ready',
172
- reason: `adaptive selection ready via runtime profile '${resolved.profileId}'`,
176
+ reason: `adaptive decision ready at '${resolved.model.endpoint}' (model '${resolved.model.model}')`,
173
177
  nextAction: 'none',
174
178
  provider,
175
- profileId: resolved.profileId,
176
179
  };
177
180
  }
178
181
  /**
@@ -1,24 +1,31 @@
1
- import { PiAiRuntimeAdapter, type ActivatedPrinciple } from '@principles/core/runtime';
1
+ import type { ActivatedPrinciple } from '@principles/core/runtime';
2
+ import { type DecisionOutcome, type DecisionProtocolError, type DecisionRequestEnvelope } from './adaptive-decision-protocol.js';
2
3
  export declare const ADAPTIVE_SELECTION_LIMITS: {
3
4
  readonly maxCandidates: 12;
4
5
  readonly maxCandidateChars: 600;
5
6
  readonly maxPriorMessages: 4;
6
7
  readonly maxPriorMessageChars: 1200;
7
8
  readonly maxInputChars: 6000;
8
- /** Admission (time-to-first-byte) deadline for the incremental step. */
9
- readonly firstByteTimeoutMs: 10000;
10
- /** Bounded completion window once the endpoint has started answering. */
11
- readonly generationTimeoutMs: 10000;
12
- readonly maxOutputTokens: 512;
9
+ /** Total time from sending a decision request to validating the full response. */
10
+ readonly requestTimeoutMs: 2000;
11
+ /** Bounded outbound payload (current instruction + candidate snapshot + conditions). */
12
+ readonly maxPayloadChars: 20000;
13
+ /** Bounded response body; a Decisions answer table is a few KB at most. */
14
+ readonly maxResponseBytes: 65536;
13
15
  };
14
16
  export type AdaptiveSelectionModel = {
15
- readonly provider: string;
17
+ /** Exact Decisions endpoint (for example https://openrouter.ai/api/alpha/decisions). */
18
+ readonly endpoint: string;
16
19
  readonly model: string;
17
20
  readonly apiKeyEnv: string;
18
- /** Exact request URL when the caller already knows it (lab). */
19
- readonly url?: string;
20
- /** Outbound allowlist prefix when only a base URL is known (production). */
21
- readonly baseUrl?: string;
21
+ /** Optional provider allowlist label (for example Respan). */
22
+ readonly provider?: string;
23
+ /**
24
+ * Frozen exact response-model allowlist for the acceptance batch. When set,
25
+ * a response whose `model` is not one of these strings is rejected — a
26
+ * same-prefix slug with an unregistered date does not pass.
27
+ */
28
+ readonly allowedResponseModels?: readonly string[];
22
29
  };
23
30
  export type AdaptiveCandidateSource = ActivatedPrinciple;
24
31
  export interface AdaptiveCandidate {
@@ -35,7 +42,6 @@ export interface BoundedSelectionInput {
35
42
  readonly source: string;
36
43
  readonly index: number;
37
44
  }[];
38
- /** `digest` is precomputed locally and only copied by the model. */
39
45
  readonly candidates: readonly {
40
46
  readonly ref: string;
41
47
  readonly text: string;
@@ -52,47 +58,53 @@ export type BuildBoundedInputResult = {
52
58
  readonly ok: false;
53
59
  readonly reason: string;
54
60
  };
55
- export type SelectionShape = {
56
- readonly status: 'selected';
57
- readonly id: string;
58
- readonly digest: string;
59
- } | {
60
- readonly status: 'none_applicable' | 'uncertain';
61
- readonly id: null;
62
- readonly digest: null;
63
- };
64
- export type ValidateSelectionResult = {
65
- readonly ok: true;
66
- readonly selected: AdaptiveCandidate | null;
67
- readonly outcome: 'selected' | 'no_increment' | 'uncertain';
68
- } | {
69
- readonly ok: false;
70
- readonly reason: string;
71
- readonly refValid: boolean | null;
72
- readonly digestValid: boolean | null;
73
- };
74
- export type AdaptiveFailureCode = 'SELECTION_REFERENCE_INVALID' | 'SELECTION_DIGEST_INVALID' | 'SELECTION_OUTPUT_INVALID' | 'SELECTION_AMBIGUOUS' | 'SELECTION_EXPIRED'
61
+ export type AdaptiveFailureCode = 'SELECTION_OUTPUT_INVALID' | DecisionProtocolError
75
62
  /** The host's outer hook window ended Adaptive; distinct from the model's own timeout. */
76
- | 'TURN_DEADLINE_EXCEEDED' | 'TRANSPORT_NOT_SENT' | 'TRANSPORT_FAILED' | 'INPUT_REFUSED';
63
+ | 'TURN_DEADLINE_EXCEEDED'
64
+ /** The request's own short admission/completion window ended. */
65
+ | 'SELECTION_EXPIRED'
66
+ /**
67
+ * Configuration fault: the credential named by `apiKeyEnv` is absent at send
68
+ * time. Deliberately NOT in the TRANSPORT_* family — an operator must be able
69
+ * to tell "we never had a key" apart from "the network broke".
70
+ */
71
+ | 'DECISION_CREDENTIAL_MISSING' | 'TRANSPORT_NOT_SENT' | 'TRANSPORT_FAILED' | 'TRANSPORT_HTTP_ERROR';
77
72
  export type AdaptiveSelectionStage = 'idle' | 'admission' | 'generation' | 'validate' | 'revalidate' | 'done';
78
73
  export interface AdaptiveSelectionDiagnostics {
79
74
  stage: AdaptiveSelectionStage;
80
- readonly admissionDeadlineAt: number;
75
+ readonly requestDeadlineAt: number | null;
76
+ /** Epoch ms at which the single POST was actually issued (null = never sent). */
77
+ requestSentAt: number | null;
81
78
  completionDeadlineAt: number | null;
82
79
  firstByteAt: number | null;
83
80
  generationEndedAt: number | null;
81
+ /** Epoch ms at which the WHOLE answer table passed validation (null = never). */
82
+ validatedAt: number | null;
84
83
  cancelledAt: number | null;
85
84
  httpStatus: number | null;
86
- /** Server-reported finish reason, or 'unknown' when the transport does not expose one. */
85
+ /** `decisions` once a valid answer table was read; `unknown` otherwise. */
87
86
  finishReason: string;
87
+ /** Exact response model observed (null until a body was parsed). */
88
+ modelObserved: string | null;
89
+ /** Response provider label observed; null both before parsing and when absent. */
90
+ providerObserved: string | null;
88
91
  usage: {
89
92
  inputTokens: number | null;
90
93
  outputTokens: number | null;
91
94
  } | null;
95
+ /**
96
+ * Local adjudication of the independent condition scores. Bounded: question
97
+ * ids are `c1..cN` plus `insufficient_context`, never prompt text.
98
+ */
99
+ decision: {
100
+ status: string;
101
+ ref: string | null;
102
+ reason: string;
103
+ scores: Readonly<Record<string, number>>;
104
+ } | null;
92
105
  failures: AdaptiveFailureCode[];
93
106
  }
94
107
  export declare function hash(value: string): string;
95
- export declare const ADAPTIVE_SELECTOR_SYSTEM: string;
96
108
  export declare function buildBoundedSelectionInput(input: {
97
109
  readonly currentInput: string;
98
110
  readonly priorMessages?: readonly {
@@ -101,30 +113,22 @@ export declare function buildBoundedSelectionInput(input: {
101
113
  }[];
102
114
  readonly candidates: readonly AdaptiveCandidateSource[];
103
115
  }): BuildBoundedInputResult;
104
- export declare function parseSelectionShape(value: unknown): {
105
- readonly ok: true;
106
- readonly selection: SelectionShape;
107
- } | {
108
- readonly ok: false;
109
- readonly reason: string;
110
- };
111
- export declare function validateSelectionResult(value: unknown, entries: readonly AdaptiveCandidate[]): ValidateSelectionResult;
112
- export declare function localFailureCode(reason: string): AdaptiveFailureCode;
113
- export interface SingleModelSelectorOptions {
114
- readonly PiAiRuntimeAdapterImpl?: typeof PiAiRuntimeAdapter;
116
+ export interface DecisionSelectorOptions {
115
117
  readonly fetchImpl?: typeof fetch;
116
118
  readonly now?: () => number;
117
- /** Absolute deadline for the first byte of the model response. */
118
- readonly admissionDeadlineAt: number;
119
- readonly generationTimeoutMs?: number;
119
+ readonly requestTimeoutMs?: number;
120
120
  readonly model: AdaptiveSelectionModel;
121
- readonly maxTokens?: number;
122
121
  readonly signal?: AbortSignal;
123
122
  /** Absolute host deadline. Reaching it is NOT the model's generation timeout. */
124
123
  readonly outerDeadlineAt?: number;
125
124
  }
126
- export interface SingleModelSelector {
127
- readonly select: (input: BoundedSelectionInput) => Promise<unknown>;
125
+ export interface DecisionSelectorInput {
126
+ readonly body: DecisionRequestEnvelope;
127
+ readonly questionIds: readonly string[];
128
+ readonly candidates: readonly AdaptiveCandidate[];
129
+ }
130
+ export interface DecisionSelector {
131
+ readonly select: (input: DecisionSelectorInput) => Promise<DecisionOutcome>;
128
132
  readonly report: () => {
129
133
  readonly sends: number;
130
134
  readonly status: 'not_sent' | 'sent' | 'failed';
@@ -132,21 +136,22 @@ export interface SingleModelSelector {
132
136
  readonly diagnostics: AdaptiveSelectionDiagnostics;
133
137
  };
134
138
  }
135
- export declare function createSingleModelSelector(options: SingleModelSelectorOptions): SingleModelSelector;
139
+ /**
140
+ * One Decisions POST per turn. Every failure is classified at the transport
141
+ * edge; the caller never sees provider text, headers or credentials.
142
+ */
143
+ export declare function createDecisionSelector(options: DecisionSelectorOptions): DecisionSelector;
136
144
  export interface RunAdaptiveSelectionOptions {
137
145
  readonly workspaceDir: string;
138
146
  readonly currentPrompt: string;
139
- /** Absolute first-byte deadline for the incremental step. */
140
- readonly admissionDeadlineAt: number;
147
+ readonly candidates: readonly ActivatedPrinciple[];
141
148
  readonly model: AdaptiveSelectionModel;
142
- readonly generationTimeoutMs?: number;
143
- readonly maxTokens?: number;
149
+ readonly requestTimeoutMs?: number;
144
150
  readonly signal?: AbortSignal;
145
151
  /** Absolute host deadline shared by selection, revalidation and packing. */
146
152
  readonly outerDeadlineAt?: number;
147
153
  readonly now?: () => number;
148
154
  readonly fetchImpl?: typeof fetch;
149
- readonly PiAiRuntimeAdapterImpl?: typeof PiAiRuntimeAdapter;
150
155
  }
151
156
  export interface AdaptiveSelectionOutcome {
152
157
  readonly status: 'selected' | 'none' | 'unavailable';
@@ -157,8 +162,8 @@ export interface AdaptiveSelectionOutcome {
157
162
  readonly diagnostics: AdaptiveSelectionDiagnostics;
158
163
  }
159
164
  /**
160
- * Minimal host-facing selection step: read the current frozen candidates,
161
- * make at most one bounded model call, verify ref+digest, then independently
162
- * revalidate the chosen principle's content/revision/authorization.
165
+ * Minimal host-facing selection step: use the current frozen Native gap,
166
+ * make at most one bounded Decisions request, adjudicate locally, then
167
+ * independently revalidate the chosen principle's content/revision/authorization.
163
168
  */
164
169
  export declare function runAdaptiveSelection(options: RunAdaptiveSelectionOptions): Promise<AdaptiveSelectionOutcome>;