create-principles-disciple 1.150.3 → 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 (248) 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-compatibility-read-model.d.ts.map +1 -1
  13. package/core/dist/runtime/activation-compatibility-read-model.js +2 -1
  14. package/core/dist/runtime/activation-compatibility-read-model.js.map +1 -1
  15. package/core/dist/runtime/adapter/pi-ai-runtime-adapter.d.ts.map +1 -1
  16. package/core/dist/runtime/adapter/pi-ai-runtime-adapter.js +106 -19
  17. package/core/dist/runtime/adapter/pi-ai-runtime-adapter.js.map +1 -1
  18. package/core/dist/runtime/candidate-audit.d.ts.map +1 -1
  19. package/core/dist/runtime/candidate-audit.js +2 -1
  20. package/core/dist/runtime/candidate-audit.js.map +1 -1
  21. package/core/dist/runtime/config/pd-config-effective.d.ts.map +1 -1
  22. package/core/dist/runtime/config/pd-config-effective.js +2 -0
  23. package/core/dist/runtime/config/pd-config-effective.js.map +1 -1
  24. package/core/dist/runtime/config/pd-config-types.d.ts +52 -0
  25. package/core/dist/runtime/config/pd-config-types.d.ts.map +1 -1
  26. package/core/dist/runtime/config/pd-config-types.js.map +1 -1
  27. package/core/dist/runtime/config/pd-config-validate.d.ts.map +1 -1
  28. package/core/dist/runtime/config/pd-config-validate.js +134 -0
  29. package/core/dist/runtime/config/pd-config-validate.js.map +1 -1
  30. package/core/dist/runtime/feature-flags/feature-flag-contract.d.ts.map +1 -1
  31. package/core/dist/runtime/feature-flags/feature-flag-contract.js +8 -0
  32. package/core/dist/runtime/feature-flags/feature-flag-contract.js.map +1 -1
  33. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.d.ts.map +1 -1
  34. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js +24 -0
  35. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js.map +1 -1
  36. package/core/dist/runtime/index.d.ts +2 -0
  37. package/core/dist/runtime/index.d.ts.map +1 -1
  38. package/core/dist/runtime/index.js +2 -0
  39. package/core/dist/runtime/index.js.map +1 -1
  40. package/core/dist/runtime/internalization/rule-host-input-builder.d.ts +16 -0
  41. package/core/dist/runtime/internalization/rule-host-input-builder.d.ts.map +1 -1
  42. package/core/dist/runtime/internalization/rule-host-input-builder.js +18 -0
  43. package/core/dist/runtime/internalization/rule-host-input-builder.js.map +1 -1
  44. package/core/dist/runtime/internalization/split-diagnostician-runner.d.ts +8 -0
  45. package/core/dist/runtime/internalization/split-diagnostician-runner.d.ts.map +1 -1
  46. package/core/dist/runtime/internalization/split-diagnostician-runner.js +24 -2
  47. package/core/dist/runtime/internalization/split-diagnostician-runner.js.map +1 -1
  48. package/core/dist/runtime/internalization/tool-semantic-registry.d.ts +26 -0
  49. package/core/dist/runtime/internalization/tool-semantic-registry.d.ts.map +1 -1
  50. package/core/dist/runtime/internalization/tool-semantic-registry.js +55 -5
  51. package/core/dist/runtime/internalization/tool-semantic-registry.js.map +1 -1
  52. package/core/dist/runtime/internalization-chain-integrity-read-model.d.ts.map +1 -1
  53. package/core/dist/runtime/internalization-chain-integrity-read-model.js +2 -2
  54. package/core/dist/runtime/internalization-chain-integrity-read-model.js.map +1 -1
  55. package/core/dist/runtime/internalization-integrity-remediation.d.ts.map +1 -1
  56. package/core/dist/runtime/internalization-integrity-remediation.js +2 -2
  57. package/core/dist/runtime/internalization-integrity-remediation.js.map +1 -1
  58. package/core/dist/runtime/operator-health-read-model.d.ts.map +1 -1
  59. package/core/dist/runtime/operator-health-read-model.js +2 -2
  60. package/core/dist/runtime/operator-health-read-model.js.map +1 -1
  61. package/core/dist/runtime/pain-recall-read-model.d.ts.map +1 -1
  62. package/core/dist/runtime/pain-recall-read-model.js +4 -3
  63. package/core/dist/runtime/pain-recall-read-model.js.map +1 -1
  64. package/core/dist/runtime/pruning-read-model.d.ts.map +1 -1
  65. package/core/dist/runtime/pruning-read-model.js +3 -2
  66. package/core/dist/runtime/pruning-read-model.js.map +1 -1
  67. package/core/dist/runtime/risk/risk-calculator-policy.d.ts +12 -2
  68. package/core/dist/runtime/risk/risk-calculator-policy.d.ts.map +1 -1
  69. package/core/dist/runtime/risk/risk-calculator-policy.js +33 -22
  70. package/core/dist/runtime/risk/risk-calculator-policy.js.map +1 -1
  71. package/core/dist/runtime/schema-conformance-read-model.js +2 -2
  72. package/core/dist/runtime/schema-conformance-read-model.js.map +1 -1
  73. package/core/dist/runtime/store/sqlite-connection.d.ts +0 -5
  74. package/core/dist/runtime/store/sqlite-connection.d.ts.map +1 -1
  75. package/core/dist/runtime/store/sqlite-connection.js +4 -12
  76. package/core/dist/runtime/store/sqlite-connection.js.map +1 -1
  77. package/core/dist/runtime/store/storage-paths.d.ts +17 -0
  78. package/core/dist/runtime/store/storage-paths.d.ts.map +1 -0
  79. package/core/dist/runtime/store/storage-paths.js +52 -0
  80. package/core/dist/runtime/store/storage-paths.js.map +1 -0
  81. package/core/dist/runtime/trajectory-retention.d.ts +257 -0
  82. package/core/dist/runtime/trajectory-retention.d.ts.map +1 -0
  83. package/core/dist/runtime/trajectory-retention.js +598 -0
  84. package/core/dist/runtime/trajectory-retention.js.map +1 -0
  85. package/core/dist/trajectory-store.d.ts +9 -9
  86. package/core/dist/trajectory-store.d.ts.map +1 -1
  87. package/core/dist/trajectory-store.js +9 -12
  88. package/core/dist/trajectory-store.js.map +1 -1
  89. package/core/package.json +1 -1
  90. package/dist/installers/codex-host-installer.d.ts.map +1 -1
  91. package/dist/installers/codex-host-installer.js +92 -5
  92. package/dist/installers/codex-host-installer.js.map +1 -1
  93. package/dist/installers/mcp-binding-shape-mirror.d.ts +27 -0
  94. package/dist/installers/mcp-binding-shape-mirror.d.ts.map +1 -0
  95. package/dist/installers/mcp-binding-shape-mirror.js +105 -0
  96. package/dist/installers/mcp-binding-shape-mirror.js.map +1 -0
  97. package/dist/skill-catalog.d.ts +35 -0
  98. package/dist/skill-catalog.d.ts.map +1 -0
  99. package/dist/skill-catalog.js +85 -0
  100. package/dist/skill-catalog.js.map +1 -0
  101. package/dist/skill-delivery-parity.d.ts +22 -0
  102. package/dist/skill-delivery-parity.d.ts.map +1 -0
  103. package/dist/skill-delivery-parity.js +31 -0
  104. package/dist/skill-delivery-parity.js.map +1 -0
  105. package/host-runtime/dist/active-principle-prompt.d.ts +8 -0
  106. package/host-runtime/dist/active-principle-prompt.js +15 -5
  107. package/host-runtime/dist/adaptive-decision-protocol.d.ts +142 -0
  108. package/host-runtime/dist/adaptive-decision-protocol.js +190 -0
  109. package/host-runtime/dist/adaptive-priority-provider.d.ts +37 -13
  110. package/host-runtime/dist/adaptive-priority-provider.js +65 -62
  111. package/host-runtime/dist/adaptive-selection.d.ts +67 -64
  112. package/host-runtime/dist/adaptive-selection.js +215 -327
  113. package/host-runtime/dist/adaptive-skip-decision.d.ts +26 -14
  114. package/host-runtime/dist/adaptive-skip-decision.js +33 -29
  115. package/host-runtime/dist/codex-rule-context-provider.js +4 -1
  116. package/host-runtime/dist/governance-observation-store.d.ts +40 -1
  117. package/host-runtime/dist/governance-observation-store.js +188 -9
  118. package/host-runtime/dist/governance-signal-admission.d.ts +19 -3
  119. package/host-runtime/dist/governance-signal-admission.js +12 -4
  120. package/host-runtime/dist/host-tool-declaration.d.ts +18 -2
  121. package/host-runtime/dist/host-tool-declaration.js +67 -11
  122. package/host-runtime/dist/host-tool-semantic-resolver.d.ts +7 -0
  123. package/host-runtime/dist/host-tool-semantic-resolver.js +22 -2
  124. package/host-runtime/dist/index.d.ts +3 -0
  125. package/host-runtime/dist/index.js +14 -0
  126. package/host-runtime/dist/production-rulehost-gate.js +15 -3
  127. package/host-runtime/dist/trajectory-retention.d.ts +147 -0
  128. package/host-runtime/dist/trajectory-retention.js +907 -0
  129. package/host-runtime/package.json +1 -1
  130. package/install-layout/dist/index.d.ts +9 -2
  131. package/install-layout/dist/index.js +26 -9
  132. package/install-layout/dist/mcp-binding-contract.d.ts +91 -0
  133. package/install-layout/dist/mcp-binding-contract.js +230 -0
  134. package/install-layout/package.json +1 -1
  135. package/package.json +4 -4
  136. package/pd-cli/dist/commands/build-trajectory-evidence.d.ts.map +1 -1
  137. package/pd-cli/dist/commands/build-trajectory-evidence.js +17 -11
  138. package/pd-cli/dist/commands/build-trajectory-evidence.js.map +1 -1
  139. package/pd-cli/dist/commands/codex-reconcile.d.ts +7 -0
  140. package/pd-cli/dist/commands/codex-reconcile.d.ts.map +1 -1
  141. package/pd-cli/dist/commands/codex-reconcile.js +11 -2
  142. package/pd-cli/dist/commands/codex-reconcile.js.map +1 -1
  143. package/pd-cli/dist/commands/codex-worker.d.ts.map +1 -1
  144. package/pd-cli/dist/commands/codex-worker.js +35 -0
  145. package/pd-cli/dist/commands/codex-worker.js.map +1 -1
  146. package/pd-cli/dist/commands/command-helpers.d.ts +1 -1
  147. package/pd-cli/dist/commands/command-helpers.js +1 -1
  148. package/pd-cli/dist/commands/errors-list.d.ts +1 -1
  149. package/pd-cli/dist/commands/errors-list.js +1 -1
  150. package/pd-cli/dist/commands/health-mcp.d.ts +23 -1
  151. package/pd-cli/dist/commands/health-mcp.d.ts.map +1 -1
  152. package/pd-cli/dist/commands/health-mcp.js +81 -22
  153. package/pd-cli/dist/commands/health-mcp.js.map +1 -1
  154. package/pd-cli/dist/commands/health.d.ts +1 -1
  155. package/pd-cli/dist/commands/health.d.ts.map +1 -1
  156. package/pd-cli/dist/commands/health.js +12 -5
  157. package/pd-cli/dist/commands/health.js.map +1 -1
  158. package/pd-cli/dist/commands/principles-stats.d.ts +1 -1
  159. package/pd-cli/dist/commands/principles-stats.js +1 -1
  160. package/pd-cli/dist/commands/trajectory-retention.d.ts +23 -0
  161. package/pd-cli/dist/commands/trajectory-retention.d.ts.map +1 -0
  162. package/pd-cli/dist/commands/trajectory-retention.js +159 -0
  163. package/pd-cli/dist/commands/trajectory-retention.js.map +1 -0
  164. package/pd-cli/dist/commands/workbuddy-setup.d.ts +69 -0
  165. package/pd-cli/dist/commands/workbuddy-setup.d.ts.map +1 -0
  166. package/pd-cli/dist/commands/workbuddy-setup.js +379 -0
  167. package/pd-cli/dist/commands/workbuddy-setup.js.map +1 -0
  168. package/pd-cli/dist/commands/workbuddy-worker.d.ts.map +1 -1
  169. package/pd-cli/dist/commands/workbuddy-worker.js +42 -6
  170. package/pd-cli/dist/commands/workbuddy-worker.js.map +1 -1
  171. package/pd-cli/dist/index.d.ts +1 -7
  172. package/pd-cli/dist/index.d.ts.map +1 -1
  173. package/pd-cli/dist/index.js +15 -1201
  174. package/pd-cli/dist/index.js.map +1 -1
  175. package/pd-cli/dist/program.d.ts +17 -0
  176. package/pd-cli/dist/program.d.ts.map +1 -0
  177. package/pd-cli/dist/program.js +1263 -0
  178. package/pd-cli/dist/program.js.map +1 -0
  179. package/pd-cli/dist/services/delivery-surfaces.d.ts.map +1 -1
  180. package/pd-cli/dist/services/delivery-surfaces.js +7 -5
  181. package/pd-cli/dist/services/delivery-surfaces.js.map +1 -1
  182. package/pd-cli/dist/services/version-report.d.ts.map +1 -1
  183. package/pd-cli/dist/services/version-report.js +30 -4
  184. package/pd-cli/dist/services/version-report.js.map +1 -1
  185. package/pd-cli/package.json +1 -1
  186. package/pd-mcp-server/dist/version.d.ts +1 -1
  187. package/pd-mcp-server/dist/version.js +1 -1
  188. package/pd-mcp-server/package.json +3 -1
  189. package/plugin/dist/bundle.js +544 -494
  190. package/plugin/dist/constants/tools.d.ts +8 -1
  191. package/plugin/dist/core/trajectory-retention-trigger.d.ts +13 -0
  192. package/plugin/dist/core/trajectory.d.ts +14 -0
  193. package/plugin/dist/hooks/gate-block-helper.d.ts +17 -0
  194. package/plugin/dist/hooks/gate.d.ts +6 -1
  195. package/plugin/dist/host-runtime/openclaw-host-runtime.d.ts +1 -0
  196. package/plugin/dist/index.d.ts +5 -0
  197. package/plugin/dist/openclaw.plugin.json +1 -1
  198. package/plugin/dist/rulehost-evidence.js +29 -23
  199. package/plugin/dist/templates/langs/en/skills/pd-cli-operator/SKILL.md +16 -5
  200. package/plugin/dist/templates/langs/en/skills/pd-control/SKILL.md +7 -6
  201. package/plugin/dist/templates/langs/en/skills/pd-pain-signal/SKILL.md +141 -28
  202. package/plugin/dist/templates/langs/en/skills/pd-review/SKILL.md +15 -1
  203. package/plugin/dist/templates/langs/zh/skills/pd-cli-operator/SKILL.md +16 -5
  204. package/plugin/dist/templates/langs/zh/skills/pd-control/SKILL.md +7 -6
  205. package/plugin/dist/templates/langs/zh/skills/pd-pain-signal/SKILL.md +142 -29
  206. package/plugin/dist/templates/langs/zh/skills/pd-review/SKILL.md +15 -1
  207. package/plugin/openclaw.plugin.json +1 -1
  208. package/plugin/package.json +1 -1
  209. package/plugin/templates/langs/en/skills/pd-cli-operator/SKILL.md +16 -5
  210. package/plugin/templates/langs/en/skills/pd-control/SKILL.md +7 -6
  211. package/plugin/templates/langs/en/skills/pd-pain-signal/SKILL.md +141 -28
  212. package/plugin/templates/langs/en/skills/pd-review/SKILL.md +15 -1
  213. package/plugin/templates/langs/zh/skills/pd-cli-operator/SKILL.md +16 -5
  214. package/plugin/templates/langs/zh/skills/pd-control/SKILL.md +7 -6
  215. package/plugin/templates/langs/zh/skills/pd-pain-signal/SKILL.md +142 -29
  216. package/plugin/templates/langs/zh/skills/pd-review/SKILL.md +15 -1
  217. package/release-manager/dist/installers/codex-host-installer.js +92 -5
  218. package/release-manager/dist/installers/mcp-binding-shape-mirror.js +105 -0
  219. package/release-manager/package.json +1 -1
  220. package/workbuddy-adapter/dist/codec/input-decoder.d.ts +10 -0
  221. package/workbuddy-adapter/dist/codec/input-decoder.js +62 -5
  222. package/workbuddy-adapter/dist/host-adapter.js +1 -0
  223. package/workbuddy-adapter/dist/index.d.ts +1 -0
  224. package/workbuddy-adapter/dist/index.js +1 -0
  225. package/workbuddy-adapter/dist/ingestion/catch-up.d.ts +25 -0
  226. package/workbuddy-adapter/dist/ingestion/catch-up.js +161 -0
  227. package/workbuddy-adapter/dist/ingestion/encode-cwd.d.ts +6 -0
  228. package/workbuddy-adapter/dist/ingestion/encode-cwd.js +39 -0
  229. package/workbuddy-adapter/dist/ingestion/index.d.ts +13 -0
  230. package/workbuddy-adapter/dist/ingestion/index.js +13 -0
  231. package/workbuddy-adapter/dist/ingestion/ingestion.d.ts +46 -0
  232. package/workbuddy-adapter/dist/ingestion/ingestion.js +135 -0
  233. package/workbuddy-adapter/dist/ingestion/transcript-decoder.d.ts +70 -0
  234. package/workbuddy-adapter/dist/ingestion/transcript-decoder.js +554 -0
  235. package/workbuddy-adapter/dist/ingestion/transcript-path.d.ts +39 -0
  236. package/workbuddy-adapter/dist/ingestion/transcript-path.js +117 -0
  237. package/workbuddy-adapter/dist/ingestion/transcript-source.d.ts +15 -0
  238. package/workbuddy-adapter/dist/ingestion/transcript-source.js +152 -0
  239. package/workbuddy-adapter/dist/pd-hook.d.ts +8 -0
  240. package/workbuddy-adapter/dist/pd-hook.js +59 -2
  241. package/workbuddy-adapter/dist/worker/workspace-worker.d.ts +9 -0
  242. package/workbuddy-adapter/dist/worker/workspace-worker.js +46 -17
  243. package/workbuddy-adapter/package.json +1 -1
  244. package/workbuddy-adapter/plugin/hooks/hooks.json +11 -0
  245. package/workbuddy-adapter/plugin/skills/pd-cli-operator/SKILL.md +57 -19
  246. package/workbuddy-adapter/plugin/skills/pd-control/SKILL.md +21 -9
  247. package/workbuddy-adapter/plugin/skills/pd-pain-signal/SKILL.md +72 -61
  248. 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,49 +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'
75
- /** The selector's schema ref is not in the adapter registry (configuration fault). */
76
- | 'SELECTION_SCHEMA_UNAVAILABLE' | 'SELECTION_AMBIGUOUS' | 'SELECTION_EXPIRED'
61
+ export type AdaptiveFailureCode = 'SELECTION_OUTPUT_INVALID' | DecisionProtocolError
77
62
  /** The host's outer hook window ended Adaptive; distinct from the model's own timeout. */
78
- | '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';
79
72
  export type AdaptiveSelectionStage = 'idle' | 'admission' | 'generation' | 'validate' | 'revalidate' | 'done';
80
73
  export interface AdaptiveSelectionDiagnostics {
81
74
  stage: AdaptiveSelectionStage;
82
- 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;
83
78
  completionDeadlineAt: number | null;
84
79
  firstByteAt: number | null;
85
80
  generationEndedAt: number | null;
81
+ /** Epoch ms at which the WHOLE answer table passed validation (null = never). */
82
+ validatedAt: number | null;
86
83
  cancelledAt: number | null;
87
84
  httpStatus: number | null;
88
- /** Server-reported finish reason, or 'unknown' when the transport does not expose one. */
85
+ /** `decisions` once a valid answer table was read; `unknown` otherwise. */
89
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;
90
91
  usage: {
91
92
  inputTokens: number | null;
92
93
  outputTokens: number | null;
93
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;
94
105
  failures: AdaptiveFailureCode[];
95
106
  }
96
107
  export declare function hash(value: string): string;
97
- export declare const ADAPTIVE_SELECTOR_SYSTEM: string;
98
108
  export declare function buildBoundedSelectionInput(input: {
99
109
  readonly currentInput: string;
100
110
  readonly priorMessages?: readonly {
@@ -103,30 +113,22 @@ export declare function buildBoundedSelectionInput(input: {
103
113
  }[];
104
114
  readonly candidates: readonly AdaptiveCandidateSource[];
105
115
  }): BuildBoundedInputResult;
106
- export declare function parseSelectionShape(value: unknown): {
107
- readonly ok: true;
108
- readonly selection: SelectionShape;
109
- } | {
110
- readonly ok: false;
111
- readonly reason: string;
112
- };
113
- export declare function validateSelectionResult(value: unknown, entries: readonly AdaptiveCandidate[]): ValidateSelectionResult;
114
- export declare function localFailureCode(reason: string): AdaptiveFailureCode;
115
- export interface SingleModelSelectorOptions {
116
- readonly PiAiRuntimeAdapterImpl?: typeof PiAiRuntimeAdapter;
116
+ export interface DecisionSelectorOptions {
117
117
  readonly fetchImpl?: typeof fetch;
118
118
  readonly now?: () => number;
119
- /** Absolute deadline for the first byte of the model response. */
120
- readonly admissionDeadlineAt: number;
121
- readonly generationTimeoutMs?: number;
119
+ readonly requestTimeoutMs?: number;
122
120
  readonly model: AdaptiveSelectionModel;
123
- readonly maxTokens?: number;
124
121
  readonly signal?: AbortSignal;
125
122
  /** Absolute host deadline. Reaching it is NOT the model's generation timeout. */
126
123
  readonly outerDeadlineAt?: number;
127
124
  }
128
- export interface SingleModelSelector {
129
- 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>;
130
132
  readonly report: () => {
131
133
  readonly sends: number;
132
134
  readonly status: 'not_sent' | 'sent' | 'failed';
@@ -134,21 +136,22 @@ export interface SingleModelSelector {
134
136
  readonly diagnostics: AdaptiveSelectionDiagnostics;
135
137
  };
136
138
  }
137
- 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;
138
144
  export interface RunAdaptiveSelectionOptions {
139
145
  readonly workspaceDir: string;
140
146
  readonly currentPrompt: string;
141
- /** Absolute first-byte deadline for the incremental step. */
142
- readonly admissionDeadlineAt: number;
147
+ readonly candidates: readonly ActivatedPrinciple[];
143
148
  readonly model: AdaptiveSelectionModel;
144
- readonly generationTimeoutMs?: number;
145
- readonly maxTokens?: number;
149
+ readonly requestTimeoutMs?: number;
146
150
  readonly signal?: AbortSignal;
147
151
  /** Absolute host deadline shared by selection, revalidation and packing. */
148
152
  readonly outerDeadlineAt?: number;
149
153
  readonly now?: () => number;
150
154
  readonly fetchImpl?: typeof fetch;
151
- readonly PiAiRuntimeAdapterImpl?: typeof PiAiRuntimeAdapter;
152
155
  }
153
156
  export interface AdaptiveSelectionOutcome {
154
157
  readonly status: 'selected' | 'none' | 'unavailable';
@@ -159,8 +162,8 @@ export interface AdaptiveSelectionOutcome {
159
162
  readonly diagnostics: AdaptiveSelectionDiagnostics;
160
163
  }
161
164
  /**
162
- * Minimal host-facing selection step: read the current frozen candidates,
163
- * make at most one bounded model call, verify ref+digest, then independently
164
- * 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.
165
168
  */
166
169
  export declare function runAdaptiveSelection(options: RunAdaptiveSelectionOptions): Promise<AdaptiveSelectionOutcome>;