@abot-ai/runtime 1.9.0 → 2.0.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 (506) hide show
  1. package/README.md +5 -1
  2. package/dist/scripts/add-runtime-model.js +11 -5
  3. package/dist/scripts/init-runtime.js +15 -10
  4. package/dist/scripts/runtime-model-addition.js +6 -1
  5. package/dist/scripts/runtime-setup-command-options.d.ts +11 -0
  6. package/dist/scripts/runtime-setup-command-options.js +41 -0
  7. package/dist/scripts/runtime-setup-files.d.ts +3 -2
  8. package/dist/scripts/runtime-setup-files.js +19 -4
  9. package/dist/scripts/runtime-setup-model-options.d.ts +8 -0
  10. package/dist/scripts/runtime-setup-model-options.js +40 -0
  11. package/dist/scripts/runtime-setup-presentation.js +2 -2
  12. package/dist/scripts/runtime-setup-provider-options.d.ts +4 -0
  13. package/dist/scripts/runtime-setup-provider-options.js +20 -0
  14. package/dist/src/model-gateway/client/contracts.d.ts +3 -0
  15. package/dist/src/model-gateway/client/input-token-count.js +36 -16
  16. package/dist/src/model-gateway/client/message-projection.d.ts +2 -0
  17. package/dist/src/model-gateway/client/message-projection.js +1 -0
  18. package/dist/src/model-gateway/client/options.js +1 -1
  19. package/dist/src/model-gateway/client/raw.js +1 -0
  20. package/dist/src/model-gateway/index.d.ts +1 -1
  21. package/dist/src/model-gateway/observability/input-token-count-diagnostics.d.ts +26 -0
  22. package/dist/src/model-gateway/observability/input-token-count-diagnostics.js +178 -0
  23. package/dist/src/model-gateway/policy/invocation-policy.d.ts +1 -3
  24. package/dist/src/model-gateway/policy/invocation-policy.js +3 -30
  25. package/dist/src/model-gateway/policy/reasoning-mode-budget.d.ts +5 -0
  26. package/dist/src/model-gateway/policy/reasoning-mode-budget.js +13 -0
  27. package/dist/src/model-gateway/policy/reasoning-policy.d.ts +10 -0
  28. package/dist/src/model-gateway/policy/reasoning-policy.js +124 -0
  29. package/dist/src/model-gateway/protocol/openai-embedding-response.d.ts +1 -0
  30. package/dist/src/model-gateway/protocol/openai-embedding-response.js +28 -0
  31. package/dist/src/model-gateway/protocol/sse-data.d.ts +9 -0
  32. package/dist/src/model-gateway/protocol/sse-data.js +67 -0
  33. package/dist/src/model-gateway/providers/envelope-budget.js +10 -1
  34. package/dist/src/model-gateway/providers/llamacpp/adapter.d.ts +2 -0
  35. package/dist/src/model-gateway/providers/llamacpp/adapter.js +79 -0
  36. package/dist/src/model-gateway/providers/llamacpp/connection.d.ts +9 -0
  37. package/dist/src/model-gateway/providers/llamacpp/connection.js +73 -0
  38. package/dist/src/model-gateway/providers/llamacpp/diagnostics.d.ts +2 -0
  39. package/dist/src/model-gateway/providers/llamacpp/diagnostics.js +17 -0
  40. package/dist/src/model-gateway/providers/llamacpp/embeddings.d.ts +2 -0
  41. package/dist/src/model-gateway/providers/llamacpp/embeddings.js +56 -0
  42. package/dist/src/model-gateway/providers/llamacpp/input-token-count.d.ts +3 -0
  43. package/dist/src/model-gateway/providers/llamacpp/input-token-count.js +59 -0
  44. package/dist/src/model-gateway/providers/llamacpp/message-projection.d.ts +2 -0
  45. package/dist/src/model-gateway/providers/llamacpp/message-projection.js +33 -0
  46. package/dist/src/model-gateway/providers/llamacpp/payload.d.ts +2 -0
  47. package/dist/src/model-gateway/providers/llamacpp/payload.js +44 -0
  48. package/dist/src/model-gateway/providers/llamacpp/response-lifetime.d.ts +1 -0
  49. package/dist/src/model-gateway/providers/llamacpp/response-lifetime.js +56 -0
  50. package/dist/src/model-gateway/providers/llamacpp/schema-format.d.ts +2 -0
  51. package/dist/src/model-gateway/providers/llamacpp/schema-format.js +29 -0
  52. package/dist/src/model-gateway/providers/llamacpp/settings.d.ts +9 -0
  53. package/dist/src/model-gateway/providers/llamacpp/settings.js +25 -0
  54. package/dist/src/model-gateway/providers/llamacpp/stream-normalizer.d.ts +10 -0
  55. package/dist/src/model-gateway/providers/llamacpp/stream-normalizer.js +85 -0
  56. package/dist/src/model-gateway/providers/llamacpp/stream.d.ts +9 -0
  57. package/dist/src/model-gateway/providers/llamacpp/stream.js +33 -0
  58. package/dist/src/model-gateway/providers/openai/embeddings.js +2 -29
  59. package/dist/src/model-gateway/providers/openai/sse-data.d.ts +1 -9
  60. package/dist/src/model-gateway/providers/openai/sse-data.js +1 -67
  61. package/dist/src/model-gateway/providers/registry.js +2 -0
  62. package/dist/src/model-gateway/server/input-token-count-handler.js +10 -1
  63. package/dist/src/model-gateway/types.d.ts +11 -1
  64. package/dist/src/runtime/adapters/long-term-memory/onboarding-provider-availability.d.ts +4 -0
  65. package/dist/src/runtime/adapters/long-term-memory/onboarding-provider-availability.js +11 -0
  66. package/dist/src/runtime/adapters/long-term-memory/onboarding-service.js +28 -1
  67. package/dist/src/runtime/adapters/registered-tool-payload-related-artifacts.d.ts +1 -0
  68. package/dist/src/runtime/adapters/registered-tool-payload-related-artifacts.js +6 -1
  69. package/dist/src/runtime/adapters/registered-tool-worker-capabilities/contracts.d.ts +1 -0
  70. package/dist/src/runtime/adapters/registered-tool-worker-capabilities/execution.d.ts +1 -0
  71. package/dist/src/runtime/adapters/registered-tool-worker-capabilities/execution.js +2 -0
  72. package/dist/src/runtime/adapters/registered-tool-worker-capabilities/payload-lifecycle.d.ts +1 -0
  73. package/dist/src/runtime/adapters/registered-tool-worker-capabilities/payload-lifecycle.js +2 -0
  74. package/dist/src/runtime/adapters/registered-tool-worker-capabilities/payload-stages.d.ts +1 -0
  75. package/dist/src/runtime/adapters/registered-tool-worker-capabilities/payload-stages.js +1 -0
  76. package/dist/src/runtime/adapters/registered-tool-worker-capabilities.js +1 -0
  77. package/dist/src/runtime/adapters/scheduler-runtime.js +2 -0
  78. package/dist/src/runtime/automations/agent-step-executor.js +1 -0
  79. package/dist/src/runtime/automations/catalog.d.ts +3 -0
  80. package/dist/src/runtime/automations/catalog.js +2 -0
  81. package/dist/src/runtime/automations/definition-contracts.d.ts +2 -0
  82. package/dist/src/runtime/automations/definition-input.js +3 -1
  83. package/dist/src/runtime/automations/draft-mutations.js +5 -1
  84. package/dist/src/runtime/automations/model-dependency-projection.d.ts +3 -1
  85. package/dist/src/runtime/automations/model-dependency-projection.js +4 -2
  86. package/dist/src/runtime/automations/publication-validation.js +7 -0
  87. package/dist/src/runtime/automations/saved-agent-management.js +1 -0
  88. package/dist/src/runtime/automations/service.d.ts +3 -0
  89. package/dist/src/runtime/capabilities/automation-builder/payload-schema.js +7 -5
  90. package/dist/src/runtime/capabilities/automations/authoring-catalog.d.ts +9 -0
  91. package/dist/src/runtime/capabilities/automations/authoring-catalog.js +1 -0
  92. package/dist/src/runtime/capabilities/automations/authoring-preparation.d.ts +3 -0
  93. package/dist/src/runtime/capabilities/automations/tool-contract.js +3 -2
  94. package/dist/src/runtime/capabilities/automations/tool-module.js +16 -7
  95. package/dist/src/runtime/capabilities/model-reasoning-controls.d.ts +23 -0
  96. package/dist/src/runtime/capabilities/model-reasoning-controls.js +56 -0
  97. package/dist/src/runtime/capabilities/scheduling/create-operations.js +2 -0
  98. package/dist/src/runtime/capabilities/scheduling/job-list-page.d.ts +1 -0
  99. package/dist/src/runtime/capabilities/scheduling/tool-module.js +5 -2
  100. package/dist/src/runtime/capabilities/scheduling/update-operations.js +2 -0
  101. package/dist/src/runtime/config/builders.js +6 -0
  102. package/dist/src/runtime/config/effective-model-config-validation.js +4 -0
  103. package/dist/src/runtime/config/llamacpp-profile-validation.d.ts +3 -0
  104. package/dist/src/runtime/config/llamacpp-profile-validation.js +15 -0
  105. package/dist/src/runtime/config/model-reasoning-schema.d.ts +40 -0
  106. package/dist/src/runtime/config/model-reasoning-schema.js +38 -0
  107. package/dist/src/runtime/config/model-reasoning-validation.d.ts +3 -0
  108. package/dist/src/runtime/config/model-reasoning-validation.js +37 -0
  109. package/dist/src/runtime/config/runner/step-instructions.d.ts +4 -0
  110. package/dist/src/runtime/config/runner/step-instructions.js +10 -6
  111. package/dist/src/runtime/config/schema.js +3 -0
  112. package/dist/src/runtime/config/validation/model-invocation-config-validation.js +14 -0
  113. package/dist/src/runtime/context/compacted-capability-result-receipt.d.ts +2 -0
  114. package/dist/src/runtime/context/compacted-capability-result-receipt.js +8 -7
  115. package/dist/src/runtime/context/execution-compacted-evidence.d.ts +4 -0
  116. package/dist/src/runtime/context/execution-compacted-evidence.js +2 -23
  117. package/dist/src/runtime/context/execution-compaction-checkpoint-selection.d.ts +19 -0
  118. package/dist/src/runtime/context/execution-compaction-checkpoint-selection.js +104 -0
  119. package/dist/src/runtime/context/model-step-compaction-inheritance.d.ts +12 -0
  120. package/dist/src/runtime/context/model-step-compaction-inheritance.js +28 -0
  121. package/dist/src/runtime/context/model-step-compaction-projection.d.ts +12 -0
  122. package/dist/src/runtime/context/model-step-compaction-projection.js +322 -0
  123. package/dist/src/runtime/context/model-step-compaction.d.ts +2 -1
  124. package/dist/src/runtime/context/model-step-compaction.js +25 -316
  125. package/dist/src/runtime/context/operation-supervision-compacted-evidence.js +7 -1
  126. package/dist/src/runtime/context/request-context.d.ts +2 -0
  127. package/dist/src/runtime/context/request-context.js +16 -0
  128. package/dist/src/runtime/context/request-tool-results-checkpoint.d.ts +2 -1
  129. package/dist/src/runtime/context/request-tool-results-checkpoint.js +35 -6
  130. package/dist/src/runtime/context/request-tool-results.js +3 -1
  131. package/dist/src/runtime/context/semantic-compaction/checkpoint-message.d.ts +5 -1
  132. package/dist/src/runtime/context/semantic-compaction/checkpoint-message.js +10 -4
  133. package/dist/src/runtime/context/semantic-compaction/execution-evidence-instructions.d.ts +4 -0
  134. package/dist/src/runtime/context/semantic-compaction/execution-evidence-instructions.js +38 -0
  135. package/dist/src/runtime/context/semantic-compaction/generation-contracts.d.ts +3 -1
  136. package/dist/src/runtime/context/semantic-compaction/generation-input.js +15 -10
  137. package/dist/src/runtime/context/semantic-compaction/inherited-source-digests.d.ts +8 -0
  138. package/dist/src/runtime/context/semantic-compaction/inherited-source-digests.js +76 -0
  139. package/dist/src/runtime/context/semantic-compaction/replacement-budget.js +3 -1
  140. package/dist/src/runtime/context/semantic-compaction/run.js +6 -12
  141. package/dist/src/runtime/knowledge-skills/builtins/computer-use.js +1 -1
  142. package/dist/src/runtime/knowledge-skills/builtins/technical-work.js +20 -2
  143. package/dist/src/runtime/knowledge-skills/builtins/what-can-i-do.d.ts +2 -0
  144. package/dist/src/runtime/knowledge-skills/builtins/what-can-i-do.js +27 -0
  145. package/dist/src/runtime/knowledge-skills/catalog.js +2 -0
  146. package/dist/src/runtime/local-application.d.ts +5 -0
  147. package/dist/src/runtime/local-host/app-service-dispatch.d.ts +1 -1
  148. package/dist/src/runtime/local-host/app-service-dispatch.js +2 -0
  149. package/dist/src/runtime/local-host/client-services.d.ts +5 -0
  150. package/dist/src/runtime/local-host/saved-approvals.js +1 -0
  151. package/dist/src/runtime/long-term-memory/onboarding/configuration.js +5 -7
  152. package/dist/src/runtime/long-term-memory/onboarding/contracts.d.ts +26 -0
  153. package/dist/src/runtime/long-term-memory/onboarding/embedding-profile-id.d.ts +1 -0
  154. package/dist/src/runtime/long-term-memory/onboarding/embedding-profile-id.js +8 -0
  155. package/dist/src/runtime/long-term-memory/onboarding/saved-profiles.d.ts +17 -0
  156. package/dist/src/runtime/long-term-memory/onboarding/saved-profiles.js +77 -0
  157. package/dist/src/runtime/long-term-memory/onboarding/service.js +40 -10
  158. package/dist/src/runtime/model/input-token-count.js +1 -0
  159. package/dist/src/runtime/model/invoke-step.js +12 -0
  160. package/dist/src/runtime/model/invoke-structured-step.d.ts +4 -1
  161. package/dist/src/runtime/model/invoke-structured-step.js +4 -0
  162. package/dist/src/runtime/model/model-catalog.d.ts +3 -0
  163. package/dist/src/runtime/model/model-catalog.js +2 -0
  164. package/dist/src/runtime/model/model-context-budget.d.ts +5 -0
  165. package/dist/src/runtime/model/model-context-budget.js +2 -0
  166. package/dist/src/runtime/model/model-step-port.d.ts +7 -0
  167. package/dist/src/runtime/model/optional-context-admission.d.ts +18 -0
  168. package/dist/src/runtime/model/optional-context-admission.js +23 -0
  169. package/dist/src/runtime/ports.d.ts +3 -1
  170. package/dist/src/runtime/projects/contracts.d.ts +6 -0
  171. package/dist/src/runtime/projects/registry-format.d.ts +3 -0
  172. package/dist/src/runtime/projects/registry-format.js +50 -0
  173. package/dist/src/runtime/projects/repository.d.ts +6 -3
  174. package/dist/src/runtime/projects/repository.js +26 -19
  175. package/dist/src/runtime/projects/service.js +11 -0
  176. package/dist/src/runtime/request/approval-wait/preflight.js +1 -0
  177. package/dist/src/runtime/request/approval-wait/snapshot.d.ts +1 -1
  178. package/dist/src/runtime/request/approval-wait/snapshot.js +1 -0
  179. package/dist/src/runtime/request/contracts.d.ts +5 -1
  180. package/dist/src/runtime/request/execution-facets.js +2 -0
  181. package/dist/src/runtime/request/execution-payload-artifact-policy.d.ts +3 -0
  182. package/dist/src/runtime/request/execution-payload-artifact-policy.js +6 -0
  183. package/dist/src/runtime/request/execution-payload-compacted-evidence.js +1 -0
  184. package/dist/src/runtime/request/execution-scope-surfaces.d.ts +2 -0
  185. package/dist/src/runtime/request/execution-scope-surfaces.js +3 -0
  186. package/dist/src/runtime/request/execution-scope.d.ts +2 -0
  187. package/dist/src/runtime/request/execution-scope.js +2 -0
  188. package/dist/src/runtime/request/input.d.ts +1 -0
  189. package/dist/src/runtime/request/input.js +1 -0
  190. package/dist/src/runtime/request/prepared-execution.d.ts +1 -0
  191. package/dist/src/runtime/request/prepared-execution.js +3 -0
  192. package/dist/src/runtime/request/reasoning-preference.d.ts +10 -0
  193. package/dist/src/runtime/request/reasoning-preference.js +29 -0
  194. package/dist/src/runtime/request/root-reference-action.js +3 -3
  195. package/dist/src/runtime/request/root-skill-read-admission.d.ts +4 -0
  196. package/dist/src/runtime/request/root-skill-read-admission.js +14 -0
  197. package/dist/src/runtime/request/root-skill-read.js +13 -5
  198. package/dist/src/runtime/request/supervisor-skill-selection-window.d.ts +16 -0
  199. package/dist/src/runtime/request/supervisor-skill-selection-window.js +17 -0
  200. package/dist/src/runtime/request/worker-capability-composition.js +2 -0
  201. package/dist/src/runtime/scheduler/contracts.d.ts +7 -1
  202. package/dist/src/runtime/scheduler/job-management.js +7 -1
  203. package/dist/src/runtime/scheduler/run-records.js +2 -0
  204. package/dist/src/runtime/scheduler/schedule-validation.js +2 -0
  205. package/dist/src/runtime/scheduler/scheduler-engine.js +1 -0
  206. package/dist/src/runtime/scheduler/snapshot-validation.js +2 -0
  207. package/dist/src/runtime/steps/auditor-decision/projection.js +2 -0
  208. package/dist/src/runtime/steps/execution-agent/capability-controls-partition.d.ts +9 -0
  209. package/dist/src/runtime/steps/execution-agent/capability-controls-partition.js +29 -0
  210. package/dist/src/runtime/steps/execution-agent/capability-scope.d.ts +17 -0
  211. package/dist/src/runtime/steps/execution-agent/capability-scope.js +54 -0
  212. package/dist/src/runtime/steps/execution-agent/compaction.js +22 -6
  213. package/dist/src/runtime/steps/execution-agent/controls-compacted-evidence.js +2 -0
  214. package/dist/src/runtime/steps/execution-agent/evidence-reuse-instructions.d.ts +6 -0
  215. package/dist/src/runtime/steps/execution-agent/evidence-reuse-instructions.js +13 -0
  216. package/dist/src/runtime/steps/execution-agent/format.js +3 -6
  217. package/dist/src/runtime/steps/execution-agent/input.d.ts +5 -1
  218. package/dist/src/runtime/steps/execution-agent/input.js +10 -36
  219. package/dist/src/runtime/steps/execution-agent/observation-guidance.d.ts +11 -0
  220. package/dist/src/runtime/steps/execution-agent/observation-guidance.js +33 -0
  221. package/dist/src/runtime/steps/execution-agent/prompt.js +2 -0
  222. package/dist/src/runtime/steps/execution-agent/refinement.d.ts +3 -2
  223. package/dist/src/runtime/steps/execution-agent/refinement.js +17 -6
  224. package/dist/src/runtime/steps/execution-agent/run.js +7 -1
  225. package/dist/src/runtime/steps/skill-read-decision.d.ts +1 -0
  226. package/dist/src/runtime/steps/skill-read-decision.js +9 -4
  227. package/dist/src/runtime/steps/supervisor-decision/artifact-paths.d.ts +6 -1
  228. package/dist/src/runtime/steps/supervisor-decision/artifact-paths.js +15 -0
  229. package/dist/src/runtime/steps/supervisor-decision/contracts.d.ts +1 -1
  230. package/dist/src/runtime/steps/supervisor-decision/contracts.js +2 -0
  231. package/dist/src/runtime/steps/supervisor-decision/decision-phases.d.ts +3 -0
  232. package/dist/src/runtime/steps/supervisor-decision/decision-phases.js +22 -3
  233. package/dist/src/runtime/steps/supervisor-decision/delegation-contract.d.ts +9 -0
  234. package/dist/src/runtime/steps/supervisor-decision/delegation-contract.js +82 -0
  235. package/dist/src/runtime/steps/supervisor-decision/delegation-input.d.ts +7 -0
  236. package/dist/src/runtime/steps/supervisor-decision/delegation-input.js +105 -0
  237. package/dist/src/runtime/steps/supervisor-decision/delegation-prompt.d.ts +7 -0
  238. package/dist/src/runtime/steps/supervisor-decision/delegation-prompt.js +13 -0
  239. package/dist/src/runtime/steps/supervisor-decision/input.d.ts +1 -0
  240. package/dist/src/runtime/steps/supervisor-decision/preparation-input.d.ts +3 -5
  241. package/dist/src/runtime/steps/supervisor-decision/preparation-input.js +5 -21
  242. package/dist/src/runtime/steps/supervisor-decision/preparation.d.ts +4 -1
  243. package/dist/src/runtime/steps/supervisor-decision/preparation.js +58 -6
  244. package/dist/src/runtime/steps/supervisor-decision/procedure-entry.d.ts +22 -0
  245. package/dist/src/runtime/steps/supervisor-decision/procedure-entry.js +61 -0
  246. package/dist/src/runtime/steps/supervisor-decision/procedure-gate.d.ts +39 -0
  247. package/dist/src/runtime/steps/supervisor-decision/procedure-gate.js +146 -0
  248. package/dist/src/runtime/steps/supervisor-decision/procedure-memory.d.ts +9 -0
  249. package/dist/src/runtime/steps/supervisor-decision/procedure-memory.js +100 -0
  250. package/dist/src/runtime/steps/supervisor-decision/procedure-recall.d.ts +10 -0
  251. package/dist/src/runtime/steps/supervisor-decision/procedure-recall.js +52 -0
  252. package/dist/src/runtime/steps/supervisor-decision/prompt.js +3 -16
  253. package/dist/src/runtime/steps/supervisor-decision/response-recommendation.js +2 -2
  254. package/dist/src/runtime/steps/supervisor-decision/role-guidance.d.ts +3 -0
  255. package/dist/src/runtime/steps/supervisor-decision/role-guidance.js +20 -0
  256. package/dist/src/runtime/steps/supervisor-decision/run.js +50 -7
  257. package/dist/src/runtime/steps/supervisor-decision/skill-read-state.d.ts +10 -0
  258. package/dist/src/runtime/steps/supervisor-decision/skill-read-state.js +45 -0
  259. package/dist/src/runtime/steps/supervisor-decision/skill-selection-candidates.d.ts +15 -0
  260. package/dist/src/runtime/steps/supervisor-decision/skill-selection-candidates.js +25 -0
  261. package/dist/src/runtime/steps/supervisor-decision/skill-selection-catalog.d.ts +3 -0
  262. package/dist/src/runtime/steps/supervisor-decision/skill-selection-catalog.js +15 -0
  263. package/dist/src/runtime/steps/supervisor-decision/skill-selection-continuation.d.ts +10 -0
  264. package/dist/src/runtime/steps/supervisor-decision/skill-selection-continuation.js +65 -0
  265. package/dist/src/runtime/steps/supervisor-decision/skill-selection-input.d.ts +3 -1
  266. package/dist/src/runtime/steps/supervisor-decision/skill-selection-input.js +20 -22
  267. package/dist/src/runtime/steps/supervisor-decision/skill-selection.d.ts +3 -2
  268. package/dist/src/runtime/steps/supervisor-decision/skill-selection.js +62 -15
  269. package/dist/src/runtime/steps/supervisor-response/prompt.js +18 -4
  270. package/dist/src/shared/model-reasoning-modes.d.ts +5 -0
  271. package/dist/src/shared/model-reasoning-modes.js +20 -0
  272. package/dist/src/shared/model-reasoning-schema.d.ts +38 -0
  273. package/dist/src/shared/model-reasoning-schema.js +29 -0
  274. package/dist/src/shared/model-reasoning.d.ts +35 -0
  275. package/dist/src/shared/model-reasoning.js +100 -0
  276. package/dist/src/web-ui/app/ARCHITECTURE.md +13 -0
  277. package/dist/src/web-ui/app/app-bootstrap.js +9 -12
  278. package/dist/src/web-ui/app/app-dom.js +6 -1
  279. package/dist/src/web-ui/app/app-state.js +1 -0
  280. package/dist/src/web-ui/app/app.js +8 -3
  281. package/dist/src/web-ui/app/appearance-feature.js +28 -0
  282. package/dist/src/web-ui/app/automations-feature.js +20 -11
  283. package/dist/src/web-ui/app/components/appearance-dialog.js +79 -0
  284. package/dist/src/web-ui/app/components/automations/archive-actions.js +5 -3
  285. package/dist/src/web-ui/app/components/automations/authoring-entry.js +26 -7
  286. package/dist/src/web-ui/app/components/automations/confirmation-actions.js +78 -0
  287. package/dist/src/web-ui/app/components/automations/draft-recovery-actions.js +1 -0
  288. package/dist/src/web-ui/app/components/automations/node-inspector.js +5 -1
  289. package/dist/src/web-ui/app/components/automations/step-editor-dialog.js +4 -2
  290. package/dist/src/web-ui/app/components/automations/timeline.js +2 -2
  291. package/dist/src/web-ui/app/components/automations/workspace-navigation.js +37 -0
  292. package/dist/src/web-ui/app/components/automations/workspace.js +31 -46
  293. package/dist/src/web-ui/app/components/config-workspace/config-model.js +6 -0
  294. package/dist/src/web-ui/app/components/config-workspace/model-removal.js +4 -2
  295. package/dist/src/web-ui/app/components/config-workspace/model-rendering.js +8 -16
  296. package/dist/src/web-ui/app/components/config-workspace/reasoning-budget-edit.js +113 -0
  297. package/dist/src/web-ui/app/components/config-workspace/reasoning-budget.d.ts +16 -0
  298. package/dist/src/web-ui/app/components/config-workspace/reasoning-budget.js +67 -0
  299. package/dist/src/web-ui/app/components/config-workspace/reasoning-mode-budgets.d.ts +7 -0
  300. package/dist/src/web-ui/app/components/config-workspace/reasoning-mode-budgets.js +25 -0
  301. package/dist/src/web-ui/app/components/config-workspace/workspace-events.js +15 -7
  302. package/dist/src/web-ui/app/components/config-workspace/workspace-mutations.js +32 -12
  303. package/dist/src/web-ui/app/components/config-workspace/workspace-persistence.js +1 -1
  304. package/dist/src/web-ui/app/components/config-workspace.js +2 -1
  305. package/dist/src/web-ui/app/components/confirmation-dialog.js +88 -0
  306. package/dist/src/web-ui/app/components/conversation-activity.d.ts +2 -0
  307. package/dist/src/web-ui/app/components/conversation-activity.js +32 -3
  308. package/dist/src/web-ui/app/components/conversation-memory-activity.js +31 -0
  309. package/dist/src/web-ui/app/components/conversation-role-cards.d.ts +2 -0
  310. package/dist/src/web-ui/app/components/conversation-role-cards.js +14 -11
  311. package/dist/src/web-ui/app/components/conversation-skill-activity.js +67 -0
  312. package/dist/src/web-ui/app/components/conversation-tools.js +5 -5
  313. package/dist/src/web-ui/app/components/conversation-view.js +6 -0
  314. package/dist/src/web-ui/app/components/dashboard/approvals.js +13 -1
  315. package/dist/src/web-ui/app/components/long-term-memory/embedding-connection-dialog.d.ts +38 -0
  316. package/dist/src/web-ui/app/components/long-term-memory/embedding-connection-dialog.js +289 -0
  317. package/dist/src/web-ui/app/components/long-term-memory/embedding-connection-feature.js +75 -0
  318. package/dist/src/web-ui/app/components/long-term-memory/embedding-connection-rendering.js +31 -0
  319. package/dist/src/web-ui/app/components/long-term-memory/manager.js +15 -5
  320. package/dist/src/web-ui/app/components/long-term-memory/saved-embedding-profiles.js +114 -0
  321. package/dist/src/web-ui/app/components/long-term-memory/setup-rendering.js +55 -0
  322. package/dist/src/web-ui/app/components/long-term-memory-setup.js +141 -76
  323. package/dist/src/web-ui/app/components/model-setup/rendering.js +3 -2
  324. package/dist/src/web-ui/app/components/model-setup/validation.js +6 -2
  325. package/dist/src/web-ui/app/components/model-setup/wizard.d.ts +1 -0
  326. package/dist/src/web-ui/app/components/model-setup/wizard.js +28 -5
  327. package/dist/src/web-ui/app/components/passive-learning/memory.js +12 -5
  328. package/dist/src/web-ui/app/components/plugins/manager.js +14 -0
  329. package/dist/src/web-ui/app/components/plugins/removal.js +10 -2
  330. package/dist/src/web-ui/app/components/project-group-actions.js +35 -0
  331. package/dist/src/web-ui/app/components/project-session-groups.js +17 -31
  332. package/dist/src/web-ui/app/components/runtime-setup/commands.js +1 -1
  333. package/dist/src/web-ui/app/components/runtime-setup/connection-form.d.ts +15 -0
  334. package/dist/src/web-ui/app/components/runtime-setup/connection-form.js +32 -9
  335. package/dist/src/web-ui/app/components/runtime-setup/connection-input.js +23 -0
  336. package/dist/src/web-ui/app/components/runtime-setup/connection-inspection.js +57 -0
  337. package/dist/src/web-ui/app/components/runtime-setup/connection-state.js +18 -4
  338. package/dist/src/web-ui/app/components/runtime-setup/embedding-credential-status.js +3 -0
  339. package/dist/src/web-ui/app/components/runtime-setup/embedding-provider-options.js +54 -0
  340. package/dist/src/web-ui/app/components/runtime-setup/embedding-provider-receipt.js +3 -0
  341. package/dist/src/web-ui/app/components/runtime-setup/embedding-rendering.js +22 -22
  342. package/dist/src/web-ui/app/components/runtime-setup/embedding.js +60 -16
  343. package/dist/src/web-ui/app/components/runtime-setup/reasoning-fields.d.ts +17 -0
  344. package/dist/src/web-ui/app/components/runtime-setup/reasoning-fields.js +54 -0
  345. package/dist/src/web-ui/app/components/runtime-setup/validation.js +5 -1
  346. package/dist/src/web-ui/app/components/runtime-setup-guide.d.ts +9 -3
  347. package/dist/src/web-ui/app/components/runtime-setup-guide.js +20 -29
  348. package/dist/src/web-ui/app/components/schedules/details.js +2 -2
  349. package/dist/src/web-ui/app/components/schedules/form.js +12 -5
  350. package/dist/src/web-ui/app/components/schedules/workspace.js +30 -18
  351. package/dist/src/web-ui/app/components/session-list-viewport.js +49 -0
  352. package/dist/src/web-ui/app/components/session-search-disclosure.js +27 -0
  353. package/dist/src/web-ui/app/components/skills/workspace.js +7 -3
  354. package/dist/src/web-ui/app/components/spark-chat/panel.js +7 -3
  355. package/dist/src/web-ui/app/components/spark-chat/settings.js +57 -15
  356. package/dist/src/web-ui/app/components/tool-approval-card.d.ts +2 -1
  357. package/dist/src/web-ui/app/components/tool-approval-card.js +10 -2
  358. package/dist/src/web-ui/app/components/tool-approval-rejection-input.js +116 -0
  359. package/dist/src/web-ui/app/components/workspace-shell.js +30 -38
  360. package/dist/src/web-ui/app/components/workspace-transitions.js +42 -0
  361. package/dist/src/web-ui/app/configuration-feature.js +34 -4
  362. package/dist/src/web-ui/app/controllers/app-event-bindings.js +45 -29
  363. package/dist/src/web-ui/app/controllers/appearance-controller.js +105 -0
  364. package/dist/src/web-ui/app/controllers/automations-controller.js +9 -1
  365. package/dist/src/web-ui/app/controllers/composer-feature.d.ts +1 -1
  366. package/dist/src/web-ui/app/controllers/composer-feature.js +10 -3
  367. package/dist/src/web-ui/app/controllers/composer-queue-controller.d.ts +1 -1
  368. package/dist/src/web-ui/app/controllers/composer-queue-controller.js +9 -3
  369. package/dist/src/web-ui/app/controllers/composer-submission-lifecycle.d.ts +1 -1
  370. package/dist/src/web-ui/app/controllers/conversation-workspace-activation.js +8 -2
  371. package/dist/src/web-ui/app/controllers/dashboard-approvals-controller.js +10 -9
  372. package/dist/src/web-ui/app/controllers/environment-transition.js +2 -2
  373. package/dist/src/web-ui/app/controllers/environment-workspace-preparation.js +9 -7
  374. package/dist/src/web-ui/app/controllers/preference-view-sync.js +35 -0
  375. package/dist/src/web-ui/app/controllers/projects-controller.d.ts +4 -0
  376. package/dist/src/web-ui/app/controllers/projects-controller.js +64 -3
  377. package/dist/src/web-ui/app/controllers/reasoning-budget-controller.d.ts +17 -0
  378. package/dist/src/web-ui/app/controllers/reasoning-budget-controller.js +80 -0
  379. package/dist/src/web-ui/app/controllers/reasoning-budget-menu-events.js +45 -0
  380. package/dist/src/web-ui/app/controllers/reasoning-mode-controller.js +35 -40
  381. package/dist/src/web-ui/app/controllers/runtime-selection-controller.d.ts +6 -1
  382. package/dist/src/web-ui/app/controllers/runtime-selection-controller.js +16 -3
  383. package/dist/src/web-ui/app/controllers/session-controller.js +34 -9
  384. package/dist/src/web-ui/app/controllers/session-sidebar-controller.js +4 -3
  385. package/dist/src/web-ui/app/controllers/skills-controller.js +33 -16
  386. package/dist/src/web-ui/app/controllers/spark-chat-sync.js +1 -1
  387. package/dist/src/web-ui/app/controllers/spark-handoff-navigation.js +7 -1
  388. package/dist/src/web-ui/app/controllers/tool-approval-controller.d.ts +2 -1
  389. package/dist/src/web-ui/app/controllers/tool-approval-controller.js +36 -3
  390. package/dist/src/web-ui/app/controllers/workspace-conversation-opener.js +8 -2
  391. package/dist/src/web-ui/app/controllers/workspace-route-controller.js +41 -10
  392. package/dist/src/web-ui/app/index.html +38 -32
  393. package/dist/src/web-ui/app/lib/color-palettes.d.ts +17 -0
  394. package/dist/src/web-ui/app/lib/color-palettes.js +20 -0
  395. package/dist/src/web-ui/app/lib/memory-activity-model.d.ts +12 -0
  396. package/dist/src/web-ui/app/lib/memory-activity-model.js +61 -0
  397. package/dist/src/web-ui/app/lib/navigation-display.d.ts +8 -0
  398. package/dist/src/web-ui/app/lib/navigation-display.js +12 -0
  399. package/dist/src/web-ui/app/lib/reasoning-controls.js +47 -6
  400. package/dist/src/web-ui/app/lib/reasoning-preference.d.ts +9 -0
  401. package/dist/src/web-ui/app/lib/reasoning-preference.js +75 -0
  402. package/dist/src/web-ui/app/lib/session-composer-queue.d.ts +4 -0
  403. package/dist/src/web-ui/app/lib/session-composer-queue.js +4 -0
  404. package/dist/src/web-ui/app/lib/session-project-groups.js +28 -0
  405. package/dist/src/web-ui/app/lib/session-sidebar-order.js +7 -5
  406. package/dist/src/web-ui/app/lib/tool-activity-event.d.ts +1 -0
  407. package/dist/src/web-ui/app/lib/tool-activity-event.js +1 -0
  408. package/dist/src/web-ui/app/lib/tool-activity-model.d.ts +1 -0
  409. package/dist/src/web-ui/app/lib/tool-activity-model.js +1 -0
  410. package/dist/src/web-ui/app/lib/tool-approval-rejection-drafts.js +45 -0
  411. package/dist/src/web-ui/app/lib/tool-skill-activity-fields.js +1 -1
  412. package/dist/src/web-ui/app/notifications-feature.js +10 -2
  413. package/dist/src/web-ui/app/passive-learning-feature.js +2 -2
  414. package/dist/src/web-ui/app/projects-feature.js +40 -10
  415. package/dist/src/web-ui/app/runtime-onboarding-feature.js +1 -0
  416. package/dist/src/web-ui/app/schedules-feature.js +28 -5
  417. package/dist/src/web-ui/app/services/client-preferences.d.ts +4 -1
  418. package/dist/src/web-ui/app/services/client-preferences.js +2 -0
  419. package/dist/src/web-ui/app/services/conversation-reasoning-preferences.d.ts +11 -0
  420. package/dist/src/web-ui/app/services/conversation-reasoning-preferences.js +30 -0
  421. package/dist/src/web-ui/app/services/runtime-web-client/automations.js +6 -4
  422. package/dist/src/web-ui/app/services/runtime-web-client/configuration.js +5 -0
  423. package/dist/src/web-ui/app/services/runtime-web-client/memory.js +21 -0
  424. package/dist/src/web-ui/app/services/runtime-web-client/projects.d.ts +2 -1
  425. package/dist/src/web-ui/app/services/runtime-web-client/projects.js +4 -0
  426. package/dist/src/web-ui/app/services/runtime-web-client/tool-approvals.js +2 -0
  427. package/dist/src/web-ui/app/services/runtime-web-client.d.ts +16 -0
  428. package/dist/src/web-ui/app/services/runtime-web-client.js +2 -0
  429. package/dist/src/web-ui/app/services/session-sidebar-preferences.js +33 -13
  430. package/dist/src/web-ui/app/skills-feature.js +2 -3
  431. package/dist/src/web-ui/app/spark-chat-conversation.js +29 -3
  432. package/dist/src/web-ui/app/spark-chat-feature.js +13 -7
  433. package/dist/src/web-ui/app/styles/01-color-palettes.css +90 -0
  434. package/dist/src/web-ui/app/styles/11-product-links.css +6 -2
  435. package/dist/src/web-ui/app/styles/11-workspace-header-width.css +37 -25
  436. package/dist/src/web-ui/app/styles/12-conversation-sidebar.css +56 -22
  437. package/dist/src/web-ui/app/styles/13-projects.css +56 -19
  438. package/dist/src/web-ui/app/styles/19-runtime-setup.css +16 -0
  439. package/dist/src/web-ui/app/styles/22-reasoning-budget.css +39 -0
  440. package/dist/src/web-ui/app/styles/27-conversation-memory.css +45 -0
  441. package/dist/src/web-ui/app/styles/27-conversation-skills.css +96 -0
  442. package/dist/src/web-ui/app/styles/28-tool-approval-card.css +38 -1
  443. package/dist/src/web-ui/app/styles/35-embedding-profiles.css +159 -0
  444. package/dist/src/web-ui/app/styles/54-spark-chat.css +62 -46
  445. package/dist/src/web-ui/app/styles/65-appearance.css +60 -0
  446. package/dist/src/web-ui/app/styles/66-navigation-display.css +30 -0
  447. package/dist/src/web-ui/app/styles/67-confirmation-dialog.css +32 -0
  448. package/dist/src/web-ui/app/styles.css +8 -0
  449. package/dist/src/web-ui/client-state/preference-shapes.js +6 -1
  450. package/dist/src/web-ui/client-state/preferences.js +8 -2
  451. package/dist/src/web-ui/client-state/reasoning-preference-shape.d.ts +1 -0
  452. package/dist/src/web-ui/client-state/reasoning-preference-shape.js +18 -0
  453. package/dist/src/web-ui/local-runtime/api-router.d.ts +1 -0
  454. package/dist/src/web-ui/local-runtime/api-router.js +11 -0
  455. package/dist/src/web-ui/local-runtime/memory-embedding-connection-input.d.ts +7 -0
  456. package/dist/src/web-ui/local-runtime/memory-embedding-connection-input.js +22 -0
  457. package/dist/src/web-ui/local-runtime/memory-embedding-connection-service.d.ts +20 -0
  458. package/dist/src/web-ui/local-runtime/memory-embedding-connection-service.js +47 -0
  459. package/dist/src/web-ui/local-runtime/memory-onboarding-routes.js +32 -0
  460. package/dist/src/web-ui/local-runtime/model-connection-inspection.d.ts +7 -0
  461. package/dist/src/web-ui/local-runtime/model-connection-inspection.js +48 -0
  462. package/dist/src/web-ui/local-runtime/model-setup-catalog.d.ts +2 -1
  463. package/dist/src/web-ui/local-runtime/model-setup-catalog.js +3 -1
  464. package/dist/src/web-ui/local-runtime/model-setup-identity.js +1 -1
  465. package/dist/src/web-ui/local-runtime/model-setup-input.d.ts +5 -2
  466. package/dist/src/web-ui/local-runtime/model-setup-input.js +29 -6
  467. package/dist/src/web-ui/local-runtime/model-setup-provider.d.ts +1 -1
  468. package/dist/src/web-ui/local-runtime/model-setup-provider.js +9 -6
  469. package/dist/src/web-ui/local-runtime/model-setup-retry.js +4 -1
  470. package/dist/src/web-ui/local-runtime/model-setup-service.d.ts +2 -1
  471. package/dist/src/web-ui/local-runtime/pending-tool-approvals.js +4 -1
  472. package/dist/src/web-ui/local-runtime/project-routes.js +10 -2
  473. package/dist/src/web-ui/local-runtime/request-execution.js +1 -0
  474. package/dist/src/web-ui/local-runtime/runtime-setup-auth.d.ts +2 -0
  475. package/dist/src/web-ui/local-runtime/runtime-setup-auth.js +20 -0
  476. package/dist/src/web-ui/local-runtime/runtime-setup-connection-edit.js +3 -2
  477. package/dist/src/web-ui/local-runtime/runtime-setup-credential-completion.js +6 -1
  478. package/dist/src/web-ui/local-runtime/runtime-setup-input.d.ts +3 -2
  479. package/dist/src/web-ui/local-runtime/runtime-setup-input.js +17 -5
  480. package/dist/src/web-ui/local-runtime/runtime-setup-provider.d.ts +4 -1
  481. package/dist/src/web-ui/local-runtime/runtime-setup-provider.js +6 -2
  482. package/dist/src/web-ui/local-runtime/runtime-setup-routes.d.ts +11 -2
  483. package/dist/src/web-ui/local-runtime/runtime-setup-routes.js +11 -2
  484. package/dist/src/web-ui/local-runtime/runtime-setup-scaffold.js +3 -2
  485. package/dist/src/web-ui/local-runtime/runtime-setup-service.d.ts +25 -4
  486. package/dist/src/web-ui/local-runtime/runtime-setup-service.js +19 -9
  487. package/dist/src/web-ui/local-runtime/setup-embedding-input.d.ts +3 -1
  488. package/dist/src/web-ui/local-runtime/setup-embedding-input.js +38 -6
  489. package/dist/src/web-ui/local-runtime/setup-embedding-llamacpp.d.ts +11 -0
  490. package/dist/src/web-ui/local-runtime/setup-embedding-llamacpp.js +53 -0
  491. package/dist/src/web-ui/local-runtime/setup-embedding-provider.js +23 -9
  492. package/dist/src/web-ui/local-runtime/setup-embedding-routes.d.ts +7 -2
  493. package/dist/src/web-ui/local-runtime/setup-embedding-routes.js +5 -3
  494. package/dist/src/web-ui/local-runtime/setup-embedding-service.d.ts +1 -0
  495. package/docs/configuration.md +10 -8
  496. package/docs/installation.md +11 -5
  497. package/docs/llamacpp.md +248 -0
  498. package/docs/long-term-memory.md +12 -0
  499. package/docs/running-locally.md +7 -1
  500. package/package.json +2 -1
  501. package/plugins/project-orientation/source/index.ts +2 -3
  502. package/plugins/project-orientation/source/inspection-failure.ts +1 -1
  503. package/plugins/project-orientation/source/project-target.ts +29 -0
  504. package/plugins/project-orientation/src/index.cjs +21 -2
  505. package/runtime.config.schema.json +140 -0
  506. package/src/runtime/README.md +50 -4
@@ -0,0 +1,105 @@
1
+ import { resolveMemoryRecallSteeringVersion } from "../../long-term-memory/recall-binding.js";
2
+ import { buildSupervisorMemoryRecallContinuationParts } from "./memory-recall-continuation.js";
3
+ import { buildSparkConversationInstructions } from "../../context/spark-conversation-policy.js";
4
+ import { projectLatestSettledConversationTurn, projectRequestContext } from "../../context/request-context.js";
5
+ import { buildRequestTemporalContextMessage } from "../../context/request-temporal-context.js";
6
+ import { projectScheduledExecutionContext } from "../../context/scheduled-execution-context.js";
7
+ import { resolveModelContextBudget } from "../../model/model-context-budget.js";
8
+ import { traceDebug } from "../../observability/debug-logger.js";
9
+ import { SUPERVISOR_DECISION_MODEL_STEP, SUPERVISOR_DELEGATE_ROLE_IDS } from "./contracts.js";
10
+ import { createSupervisorDelegationFormat } from "./delegation-contract.js";
11
+ import { buildSupervisorDelegationInstructions } from "./delegation-prompt.js";
12
+ import { projectSupervisorArtifactPaths } from "./artifact-paths.js";
13
+ /**
14
+ * Initial delegation uses one exact settled conversation turn, not the full routing
15
+ * history or captured Skill bodies. Those remain available to their execution
16
+ * owners. This projection is phase-local and never changes session checkpoints.
17
+ */
18
+ export function buildSupervisorDelegationInput(request, options) {
19
+ const allowedRoleIds = [...new Set(options.allowedRoleIds ?? SUPERVISOR_DELEGATE_ROLE_IDS)]
20
+ .filter((role) => role === "worker" || role === "planner");
21
+ const allowMemoryRecall = options.allowMemoryRecall === true && options.memoryRecallMessage === undefined;
22
+ const continuationParts = [];
23
+ if (options.memoryRecallMessage) {
24
+ const diagnostic = options.diagnostic;
25
+ if (!diagnostic?.callId || !diagnostic.invocationAttempt)
26
+ throw new Error("supervisor_recall_call_identity_required");
27
+ resolveMemoryRecallSteeringVersion(options.memoryRecallMessage, request.requestId, diagnostic.callId);
28
+ continuationParts.push(...buildSupervisorMemoryRecallContinuationParts({
29
+ memoryRecallMessage: options.memoryRecallMessage,
30
+ currentCallId: diagnostic.callId,
31
+ currentInvocationAttempt: diagnostic.invocationAttempt,
32
+ }));
33
+ }
34
+ const format = createSupervisorDelegationFormat({ allowedRoleIds, allowMemoryRecall });
35
+ const budget = resolveModelContextBudget({
36
+ runnerConfig: request.runnerConfig,
37
+ agentMode: request.agentMode,
38
+ modelStep: SUPERVISOR_DECISION_MODEL_STEP,
39
+ modelPreference: request.modelPreference,
40
+ modelPolicy: request.modelPolicy,
41
+ });
42
+ const instructions = [
43
+ buildSupervisorDelegationInstructions({
44
+ allowedRoleIds, allowMemoryRecall, hasMemoryRecallContext: options.memoryRecallMessage !== undefined,
45
+ }),
46
+ ...buildSparkConversationInstructions(request.sessionKind),
47
+ ].join("\n");
48
+ const scheduledExecution = projectScheduledExecutionContext(request, instructions, "decision");
49
+ const referenceMessages = [
50
+ ...scheduledExecution.referenceMessages,
51
+ ...(!options.memoryRecallMessage && options.initialMemoryMessage ? [options.initialMemoryMessage] : []),
52
+ ...(request.temporalContext ? [buildRequestTemporalContextMessage(request.temporalContext)] : []),
53
+ ];
54
+ const historyMessages = projectLatestSettledConversationTurn(request.historyMessages) ?? [];
55
+ const contextInput = {
56
+ instructions: scheduledExecution.instructions,
57
+ format,
58
+ prompt: request.prompt,
59
+ historyMessages,
60
+ // Keep this single source turn whole. The exact model-step admission still
61
+ // accounts for it and rejects oversize input before any child is dispatched.
62
+ historyRetention: "compaction_managed",
63
+ referenceMessages,
64
+ continuationParts,
65
+ ...(request.attachments ? { attachments: request.attachments } : {}),
66
+ budget,
67
+ diagnostic: options.diagnostic,
68
+ onEvent: request.onEvent,
69
+ deferCompactionFailure: true,
70
+ };
71
+ const artifactPathsProjection = projectSupervisorArtifactPaths({
72
+ targets: request.sessionArtifactPaths,
73
+ context: contextInput,
74
+ additionalBudgetMessages: options.capabilityBriefBudgetMessages,
75
+ });
76
+ if (artifactPathsProjection)
77
+ referenceMessages.push(artifactPathsProjection.message);
78
+ const projected = projectRequestContext({
79
+ ...contextInput,
80
+ instructions: artifactPathsProjection?.instructions ?? contextInput.instructions,
81
+ });
82
+ const selectedIds = new Set(projected.selectedHistoryMessageIds);
83
+ const context = {
84
+ ...projected,
85
+ omittedHistoryMessageIds: request.historyMessages
86
+ .filter((message) => !selectedIds.has(message.id)).map((message) => message.id),
87
+ };
88
+ traceDebug("runtime.supervisor", "delegation.context.projected", {
89
+ ...options.diagnostic,
90
+ messageCount: context.messages.length,
91
+ messageCharacterCount: context.messages.reduce((sum, message) => sum + message.content.length, 0),
92
+ selectedHistoryMessageCount: context.selectedHistoryMessageIds.length,
93
+ omittedHistoryMessageCount: context.omittedHistoryMessageIds.length,
94
+ referenceMessageCount: referenceMessages.length,
95
+ allowedRoleIds,
96
+ });
97
+ return {
98
+ context, format, modelStep: SUPERVISOR_DECISION_MODEL_STEP,
99
+ delegationOnly: true,
100
+ includeAcknowledgement: false, includeTitle: false, includeResponseRecommendation: false,
101
+ allowMemoryRecall, allowSkillAuthoring: false, allowedRoleIds,
102
+ workerCapabilityAffordances: [], availableWorkerCapabilityCatalog: [],
103
+ ...(artifactPathsProjection ? { artifactPathsProjection } : {}),
104
+ };
105
+ }
@@ -0,0 +1,7 @@
1
+ import type { SupervisorDelegateRoleId } from "./contracts.js";
2
+ /** A procedure was accepted; this phase chooses root recall or a bounded child assignment. */
3
+ export declare function buildSupervisorDelegationInstructions(options: Readonly<{
4
+ allowedRoleIds: readonly SupervisorDelegateRoleId[];
5
+ allowMemoryRecall?: boolean;
6
+ hasMemoryRecallContext?: boolean;
7
+ }>): string;
@@ -0,0 +1,13 @@
1
+ import { buildMemoryRecallDecisionInstructions } from "../memory-recall-prompt.js";
2
+ import { buildSupervisorRoleGuidance, buildSupervisorDelegationGuidance } from "./role-guidance.js";
3
+ /** A procedure was accepted; this phase chooses root recall or a bounded child assignment. */
4
+ export function buildSupervisorDelegationInstructions(options) {
5
+ return [
6
+ options.allowMemoryRecall
7
+ ? "A procedure is required. Choose your own memory lookup or Worker/Planner with a bounded task using only the supplied JSON schema. Do not reconsider a direct reply here. Tool availability and tool selection belong to the execution role, not this decision."
8
+ : "A procedure is required. Choose Worker or Planner and its bounded task using only the supplied JSON schema. Do not reconsider a direct reply. Tool availability and tool selection belong to the execution role, not this decision.",
9
+ ...buildMemoryRecallDecisionInstructions(options.allowMemoryRecall === true, options.hasMemoryRecallContext),
10
+ ...buildSupervisorRoleGuidance(options.allowedRoleIds),
11
+ ...buildSupervisorDelegationGuidance(),
12
+ ].join("\n");
13
+ }
@@ -31,6 +31,7 @@ export declare function buildSupervisorDecisionInput(request: SupervisorDecision
31
31
  includeAcknowledgement: boolean;
32
32
  includeTitle: boolean;
33
33
  includeResponseRecommendation: boolean;
34
+ delegationOnly?: boolean;
34
35
  allowMemoryRecall: boolean;
35
36
  allowSkillAuthoring: boolean;
36
37
  allowedRoleIds: readonly SupervisorDelegateRoleId[];
@@ -1,18 +1,16 @@
1
- import type { ModelGatewayJsonSchemaFormat } from "../../../model-gateway/types.js";
1
+ import type { ChatMessage, ModelGatewayJsonSchemaFormat } from "../../../model-gateway/types.js";
2
2
  import type { RequestExecutionScope } from "../../request/execution-scope.js";
3
- import type { KnowledgeSkillMetadata } from "../../knowledge-skills/store.js";
4
3
  import { type SupervisorDecisionDiagnosticContext } from "./contracts.js";
5
4
  /** Preparation sees the current request, not routing state or prior tool/document bodies. */
6
5
  export declare function buildSupervisorPreparationInput(request: RequestExecutionScope, options: {
7
6
  instructions: string;
8
7
  format: ModelGatewayJsonSchemaFormat;
9
8
  diagnostic: SupervisorDecisionDiagnosticContext;
10
- availableSkills?: readonly KnowledgeSkillMetadata[];
11
- expandedCatalog?: boolean;
9
+ referenceMessages?: readonly ChatMessage[];
12
10
  }): {
13
11
  format: ModelGatewayJsonSchemaFormat;
14
12
  context: Readonly<{
15
- messages: import("../../../model-gateway/types.js").ChatMessage[];
13
+ messages: ChatMessage[];
16
14
  selectedHistoryMessageIds: string[];
17
15
  omittedHistoryMessageIds: string[];
18
16
  budget: import("../../context/request-context-contracts.js").RequestContextBudgetEstimate & {
@@ -1,9 +1,5 @@
1
1
  import { projectRequestContext } from "../../context/request-context.js";
2
- import { resolveModelContextAdmission, resolveModelContextBudget } from "../../model/model-context-budget.js";
3
- import { estimateMessagesTokens } from "../../context/token-estimator.js";
4
- import { appendRequestSteeringContext } from "../../request/request-steering-context.js";
5
- import { resolveRequestSteeringInbox } from "../../request/request-steering.js";
6
- import { buildAvailableSkillsText, AVAILABLE_SKILLS_MAX_TOKENS } from "../../knowledge-skills/available-skills-projection.js";
2
+ import { resolveModelContextBudget } from "../../model/model-context-budget.js";
7
3
  import { SUPERVISOR_DECISION_MODEL_STEP } from "./contracts.js";
8
4
  /** Preparation sees the current request, not routing state or prior tool/document bodies. */
9
5
  export function buildSupervisorPreparationInput(request, options) {
@@ -14,26 +10,14 @@ export function buildSupervisorPreparationInput(request, options) {
14
10
  ...(request.modelPolicy ? { modelPolicy: request.modelPolicy } : {}),
15
11
  };
16
12
  const budget = resolveModelContextBudget(admissionOptions);
17
- const calibration = resolveModelContextAdmission(admissionOptions).invocation.instructions ?? [];
18
- const additionalMessages = appendRequestSteeringContext(calibration.length ? [{ role: "system", content: calibration.join("\n") }] : [], resolveRequestSteeringInbox(request.requestSteering).snapshot());
19
- const additionalTokens = estimateMessagesTokens(additionalMessages, budget.tokenEstimation);
20
13
  const base = {
21
14
  instructions: options.instructions, format: options.format,
22
15
  prompt: request.prompt, historyMessages: [], budget,
16
+ referenceMessages: options.referenceMessages,
23
17
  ...(request.attachments ? { attachments: request.attachments } : {}),
24
18
  diagnostic: options.diagnostic, onEvent: request.onEvent, deferCompactionFailure: true,
25
19
  };
26
- const baseContext = projectRequestContext(base);
27
- const catalog = options.availableSkills === undefined ? undefined : buildAvailableSkillsText({
28
- skills: options.availableSkills,
29
- budgetTokens: options.expandedCatalog
30
- ? Math.max(0, baseContext.budget.availableInputTokens - baseContext.budget.estimatedInputTokens - additionalTokens)
31
- : AVAILABLE_SKILLS_MAX_TOKENS,
32
- tokenEstimation: budget.tokenEstimation,
33
- includeListHint: false,
34
- });
35
- const instructions = options.availableSkills === undefined ? options.instructions : [
36
- catalog ?? "Available Skills: no remaining candidate metadata is available.", options.instructions,
37
- ].join("\n");
38
- return { format: options.format, context: projectRequestContext({ ...base, instructions }) };
20
+ // The exact model-step admission measures the complete envelope, including late
21
+ // calibration and steering. Keep metadata whole even when this estimate exceeds it.
22
+ return { format: options.format, context: projectRequestContext(base) };
39
23
  }
@@ -1,6 +1,7 @@
1
1
  import type { RequestExecutionScope } from "../../request/execution-scope.js";
2
+ import type { SupervisorSkillSelectionWindow } from "../../request/supervisor-skill-selection-window.js";
2
3
  import type { RoleCallLedgerHead } from "../../orchestration/role-calls/index.js";
3
- import { type SupervisorDecisionDiagnosticContext } from "./contracts.js";
4
+ import { type SupervisorDecisionDiagnosticContext, type SupervisorResumeContext } from "./contracts.js";
4
5
  import { type SupervisorPresentation } from "./presentation.js";
5
6
  import { type SupervisorSkillSelection } from "./skill-selection.js";
6
7
  export declare function prepareSupervisorDecision(request: RequestExecutionScope, options: {
@@ -9,6 +10,8 @@ export declare function prepareSupervisorDecision(request: RequestExecutionScope
9
10
  includeTitle: boolean;
10
11
  allowSkillReads: boolean;
11
12
  skillReadHead?: RoleCallLedgerHead;
13
+ resume?: SupervisorResumeContext;
14
+ skillSelectionWindow: SupervisorSkillSelectionWindow;
12
15
  boundSteeringVersion?: number;
13
16
  }): Promise<{
14
17
  presentation: SupervisorPresentation;
@@ -1,14 +1,16 @@
1
- import { invokeStructuredModelStep } from "../../model/invoke-structured-step.js";
1
+ import { invokeStructuredModelStep, StructuredModelInvalidOutputError } from "../../model/invoke-structured-step.js";
2
2
  import { assertBoundModelStepSteeringCurrent } from "../../model/model-step-steering.js";
3
+ import { STRUCTURED_MODEL_MAX_REPAIR_ATTEMPTS } from "../../model/repair-prompts.js";
3
4
  import { traceDebug } from "../../observability/debug-logger.js";
4
5
  import { resolveRequestSteeringInbox } from "../../request/request-steering.js";
5
6
  import { SUPERVISOR_DECISION_MODEL_STEP } from "./contracts.js";
6
7
  import { buildSupervisorPreparationInput } from "./preparation-input.js";
7
8
  import { buildSupervisorSkillSelectionInput } from "./skill-selection-input.js";
8
9
  import { buildSupervisorPresentationInstructions, createSupervisorPresentationFormat, parseSupervisorPresentationOutput } from "./presentation.js";
9
- import { parseSupervisorSkillSelectionOutput } from "./skill-selection.js";
10
+ import { hasEligibleSkillCandidates, parseSupervisorSkillSelectionOutput } from "./skill-selection.js";
10
11
  export async function prepareSupervisorDecision(request, options) {
11
12
  const steering = resolveRequestSteeringInbox(request.requestSteering);
13
+ const { skillSelectionWindow } = options;
12
14
  let steeringVersion = options.boundSteeringVersion;
13
15
  let presentation = {};
14
16
  if (needsSupervisorPresentation(options)) {
@@ -27,11 +29,44 @@ export async function prepareSupervisorDecision(request, options) {
27
29
  if (!canSelectSupervisorSkills(options))
28
30
  return { presentation, selection: { action: "continue" }, steeringVersion: steeringVersion ?? steering.snapshot().version };
29
31
  const diagnostic = { ...options.diagnostic, decisionPhase: "skill_selection" };
30
- const input = buildSupervisorSkillSelectionInput(request, { skillReadHead: options.skillReadHead, diagnostic });
31
- const accepted = await invokePreparationPhase(request, {
32
- input, diagnostic, boundSteeringVersion: steeringVersion,
33
- parse: parseSupervisorSkillSelectionOutput,
32
+ const input = buildSupervisorSkillSelectionInput(request, {
33
+ skillReadHead: options.skillReadHead, diagnostic, ...(options.resume ? { resume: options.resume } : {}),
34
34
  });
35
+ if (!hasEligibleSkillCandidates(input.eligibleSkillIds)) {
36
+ skillSelectionWindow.complete();
37
+ return { presentation, selection: { action: "continue" }, steeringVersion: steeringVersion ?? steering.snapshot().version };
38
+ }
39
+ let accepted;
40
+ let rejectedSteeringVersion;
41
+ try {
42
+ accepted = await invokePreparationPhase(request, {
43
+ input, diagnostic, boundSteeringVersion: steeringVersion,
44
+ parse(text) {
45
+ const parsed = parseSupervisorSkillSelectionOutput(text, input.eligibleSkillIds);
46
+ if (!parsed.ok)
47
+ rejectedSteeringVersion = steering.snapshot().version;
48
+ return parsed;
49
+ },
50
+ });
51
+ }
52
+ catch (error) {
53
+ request.abortSignal.throwIfAborted();
54
+ if (!isExhaustedDuplicateSkillSelection(error))
55
+ throw error;
56
+ if (rejectedSteeringVersion === undefined)
57
+ throw error;
58
+ assertBoundModelStepSteeringCurrent(steering, steeringVersion);
59
+ assertBoundModelStepSteeringCurrent(steering, rejectedSteeringVersion);
60
+ skillSelectionWindow.complete();
61
+ traceDebug("runtime.supervisor", "skill_selection.rejected", {
62
+ ...diagnostic, steeringVersion: rejectedSteeringVersion,
63
+ issues: error.issues.map(({ code, path }) => ({ code, path })),
64
+ repairAttempts: error.repairAttempts, disposition: "continue_routing",
65
+ });
66
+ return { presentation, selection: { action: "continue" }, steeringVersion: rejectedSteeringVersion };
67
+ }
68
+ assertBoundModelStepSteeringCurrent(steering, accepted.steeringVersion);
69
+ skillSelectionWindow.complete();
35
70
  return { presentation, selection: accepted.decision, steeringVersion: accepted.steeringVersion };
36
71
  }
37
72
  function needsSupervisorPresentation(options) {
@@ -40,8 +75,25 @@ function needsSupervisorPresentation(options) {
40
75
  function canSelectSupervisorSkills(options) {
41
76
  if (!options.allowSkillReads)
42
77
  return false;
78
+ if (!options.skillSelectionWindow.isOpen())
79
+ return false;
43
80
  return !options.skillReadHead?.state.skillReads?.some((read) => read.result.outcome === "failed");
44
81
  }
82
+ function isExhaustedDuplicateSkillSelection(error) {
83
+ if (!(error instanceof StructuredModelInvalidOutputError))
84
+ return false;
85
+ if (error.modelStep !== SUPERVISOR_DECISION_MODEL_STEP)
86
+ return false;
87
+ if (error.message !== "invalid_supervisor_decision")
88
+ return false;
89
+ if (error.validationStage !== "domain_parser")
90
+ return false;
91
+ if (error.repairAttempts !== STRUCTURED_MODEL_MAX_REPAIR_ATTEMPTS)
92
+ return false;
93
+ if (error.issues.length !== 1)
94
+ return false;
95
+ return error.issues[0]?.code === "skill_selection_ids_duplicate";
96
+ }
45
97
  async function invokePreparationPhase(request, options) {
46
98
  const steering = resolveRequestSteeringInbox(request.requestSteering);
47
99
  const startedAt = Date.now();
@@ -0,0 +1,22 @@
1
+ import { type SupervisorDecisionCallIdentity, type SupervisorDelegateRoleId, type SupervisorResumeContext } from "./contracts.js";
2
+ import type { RequestToolResultsView } from "../../context/request-tool-results.js";
3
+ import type { ChatMessage } from "../../../model-gateway/types.js";
4
+ import type { RoleCallLedgerHead } from "../../orchestration/role-calls/index.js";
5
+ import { canOfferMemoryRecall } from "../../long-term-memory/recall-policy.js";
6
+ type ProcedureEntryOptions = Readonly<{
7
+ resume?: SupervisorResumeContext;
8
+ call: SupervisorDecisionCallIdentity;
9
+ skillReadHead?: RoleCallLedgerHead;
10
+ memoryRecallMessage?: ChatMessage;
11
+ toolResults: RequestToolResultsView;
12
+ allowedRoleIds?: readonly SupervisorDelegateRoleId[];
13
+ }>;
14
+ type ProcedureEntry = Readonly<{
15
+ classifyProcedure: boolean;
16
+ allowInitialMemoryRecall: boolean;
17
+ memoryRecallMessage: ChatMessage | undefined;
18
+ }>;
19
+ /** One canonical projection owns initial entry, recall eligibility and its receipt. */
20
+ export declare function projectSupervisorProcedureEntry(options: ProcedureEntryOptions, steeringVersion: number): ProcedureEntry;
21
+ export declare function canRecallSupervisorMemory(entry: ProcedureEntry, policy: Parameters<typeof canOfferMemoryRecall>[0]): boolean;
22
+ export {};
@@ -0,0 +1,61 @@
1
+ import { SUPERVISOR_DELEGATE_ROLE_IDS, } from "./contracts.js";
2
+ import { projectRootMemoryRecallMessage } from "../../long-term-memory/recall-context.js";
3
+ import { canOfferMemoryRecall } from "../../long-term-memory/recall-policy.js";
4
+ /** One canonical projection owns initial entry, recall eligibility and its receipt. */
5
+ export function projectSupervisorProcedureEntry(options, steeringVersion) {
6
+ const continuation = Object.freeze({
7
+ classifyProcedure: false, allowInitialMemoryRecall: false,
8
+ memoryRecallMessage: options.memoryRecallMessage,
9
+ });
10
+ if (options.resume !== undefined)
11
+ return continuation;
12
+ if (options.toolResults.results.length > 0)
13
+ return continuation;
14
+ if (!hasProcedureDelegate(options))
15
+ return continuation;
16
+ const head = options.skillReadHead;
17
+ // Isolated callers retain fresh classification, but cannot open a recall
18
+ // without canonical state proving that its initial allowance is unused.
19
+ if (!head)
20
+ return Object.freeze({
21
+ ...continuation, classifyProcedure: options.memoryRecallMessage === undefined,
22
+ });
23
+ const root = head.state.calls.find(call => call.callId === head.state.rootCallId);
24
+ if (!root)
25
+ return continuation;
26
+ if (root.callId !== options.call.callId)
27
+ return continuation;
28
+ if (root.status !== "active")
29
+ return continuation;
30
+ if (root.activationCount !== options.call.invocationAttempt)
31
+ return continuation;
32
+ if (root.childCallIds.length > 0)
33
+ return continuation;
34
+ return Object.freeze({
35
+ classifyProcedure: true,
36
+ allowInitialMemoryRecall: !hasInitialRecallForCurrentIntent(head, steeringVersion),
37
+ memoryRecallMessage: projectRootMemoryRecallMessage({
38
+ head, callId: root.callId, steeringVersion,
39
+ }),
40
+ });
41
+ }
42
+ function hasProcedureDelegate(options) {
43
+ const roles = options.allowedRoleIds ?? SUPERVISOR_DELEGATE_ROLE_IDS;
44
+ return roles.some((role) => role === "worker" || role === "planner");
45
+ }
46
+ export function canRecallSupervisorMemory(entry, policy) {
47
+ if (!policy.enabled)
48
+ return false;
49
+ if (entry.classifyProcedure && !entry.allowInitialMemoryRecall)
50
+ return false;
51
+ return canOfferMemoryRecall(policy);
52
+ }
53
+ function hasInitialRecallForCurrentIntent(head, steeringVersion) {
54
+ return head.state.memoryRecalls.some(recall => {
55
+ if (recall.callId !== head.state.rootCallId)
56
+ return false;
57
+ if (recall.steeringVersion !== steeringVersion)
58
+ return false;
59
+ return recall.completedChildCount === 0;
60
+ });
61
+ }
@@ -0,0 +1,39 @@
1
+ import type { ChatMessage, ModelGatewayJsonSchemaFormat } from "../../../model-gateway/types.js";
2
+ import { type StructuredModelParseResult } from "../../model/invoke-structured-step.js";
3
+ import type { RequestExecutionScope } from "../../request/execution-scope.js";
4
+ import { type SupervisorDecisionDiagnosticContext } from "./contracts.js";
5
+ export type SupervisorProcedureGateDecision = Readonly<{
6
+ requiresProcedure: true;
7
+ } | {
8
+ requiresProcedure: false;
9
+ responseRecommendation?: string;
10
+ }>;
11
+ export declare function createSupervisorProcedureGateFormat(): ModelGatewayJsonSchemaFormat;
12
+ export declare function parseSupervisorProcedureGateOutput(text: string): StructuredModelParseResult<SupervisorProcedureGateDecision>;
13
+ type ProcedureGateContextOptions = Readonly<{
14
+ diagnostic: SupervisorDecisionDiagnosticContext;
15
+ initialMemoryMessage?: ChatMessage;
16
+ memoryRecallMessage?: ChatMessage;
17
+ boundSteeringVersion?: number;
18
+ }>;
19
+ export declare function buildSupervisorProcedureGateInput(request: RequestExecutionScope, options: ProcedureGateContextOptions): {
20
+ modelStep: "supervisor.decision";
21
+ format: ModelGatewayJsonSchemaFormat;
22
+ context: Readonly<{
23
+ messages: ChatMessage[];
24
+ selectedHistoryMessageIds: string[];
25
+ omittedHistoryMessageIds: string[];
26
+ budget: import("../../context/request-context-contracts.js").RequestContextBudgetEstimate & {
27
+ parts: import("../../context/request-context-contracts.js").RequestContextBudgetParts;
28
+ };
29
+ compaction: Readonly<{
30
+ applied: boolean;
31
+ compactedSourceRefs: readonly string[];
32
+ }>;
33
+ }>;
34
+ };
35
+ export declare function runSupervisorProcedureGate(request: RequestExecutionScope, options: ProcedureGateContextOptions): Promise<{
36
+ decision: SupervisorProcedureGateDecision;
37
+ steeringVersion: number;
38
+ }>;
39
+ export {};
@@ -0,0 +1,146 @@
1
+ import { projectRequestContext } from "../../context/request-context.js";
2
+ import { invokeStructuredModelStep } from "../../model/invoke-structured-step.js";
3
+ import { resolveModelContextBudget } from "../../model/model-context-budget.js";
4
+ import { assertBoundModelStepSteeringCurrent } from "../../model/model-step-steering.js";
5
+ import { createStructuredDecisionEnvelopeSchema, readStructuredDecisionEnvelope, structuredDecisionVariantSchemaPath } from "../../model/structured-decision-envelope.js";
6
+ import { traceDebug } from "../../observability/debug-logger.js";
7
+ import { resolveRequestSteeringInbox } from "../../request/request-steering.js";
8
+ import { SUPERVISOR_DECISION_MODEL_STEP } from "./contracts.js";
9
+ import { projectSupervisorResponseRecommendation, SUPERVISOR_RESPONSE_RECOMMENDATION_MAX_LENGTH } from "./response-recommendation.js";
10
+ import { projectSupervisorProcedureRecall } from "./procedure-recall.js";
11
+ import { projectSupervisorProcedureMemory } from "./procedure-memory.js";
12
+ const PROCEDURE_GATE_INSTRUCTIONS = [
13
+ "Decide only whether fulfilling the current user request requires a procedure before answering.",
14
+ "requiresProcedure=true: work must be carried out, observed or changed before a grounded final reply can fulfill the request.",
15
+ "requiresProcedure=false: the requested outcome is a direct conversational answer, explanation, or necessary clarification.",
16
+ "Judge what the request requires, regardless of which tools exist. Tool availability and role/tool selection belong to later stages.",
17
+ "Do not execute work, plan it, or claim completion. Return only the supplied JSON. If false, include a short response recommendation, not the final answer.",
18
+ ].join("\n");
19
+ export function createSupervisorProcedureGateFormat() {
20
+ return {
21
+ type: "json_schema", name: "supervisor_procedure_gate", strict: true,
22
+ schema: createStructuredDecisionEnvelopeSchema([
23
+ {
24
+ type: "object", properties: { requiresProcedure: { type: "boolean", const: true } },
25
+ required: ["requiresProcedure"], additionalProperties: false,
26
+ },
27
+ {
28
+ type: "object",
29
+ properties: {
30
+ requiresProcedure: { type: "boolean", const: false },
31
+ responseRecommendation: { type: "string", minLength: 1, maxLength: SUPERVISOR_RESPONSE_RECOMMENDATION_MAX_LENGTH },
32
+ },
33
+ required: ["requiresProcedure", "responseRecommendation"], additionalProperties: false,
34
+ },
35
+ ]),
36
+ postValidatedSchemaConstraints: [{
37
+ keyword: "maxLength",
38
+ path: `${structuredDecisionVariantSchemaPath(1, 2)}/properties/responseRecommendation/maxLength`,
39
+ }],
40
+ };
41
+ }
42
+ export function parseSupervisorProcedureGateOutput(text) {
43
+ let record;
44
+ try {
45
+ record = readStructuredDecisionEnvelope(JSON.parse(text));
46
+ }
47
+ catch { /* Rejected below. */ }
48
+ if (isProcedureRequiredDecision(record)) {
49
+ return { ok: true, decision: Object.freeze({ requiresProcedure: true }) };
50
+ }
51
+ if (isDirectResponseDecision(record)) {
52
+ return { ok: true, decision: Object.freeze({
53
+ requiresProcedure: false, ...projectSupervisorResponseRecommendation(record.responseRecommendation),
54
+ }) };
55
+ }
56
+ return {
57
+ ok: false, stage: "domain_parser", issues: [{
58
+ code: "supervisor_procedure_gate_invalid", path: "decision",
59
+ message: "Return requiresProcedure as a boolean. Only false may include responseRecommendation; supply a non-empty recommendation of at most 300 characters. Include no other fields.",
60
+ }],
61
+ };
62
+ }
63
+ function isProcedureRequiredDecision(record) {
64
+ if (!record)
65
+ return false;
66
+ if (record.requiresProcedure !== true)
67
+ return false;
68
+ return Object.keys(record).length === 1;
69
+ }
70
+ function isDirectResponseDecision(record) {
71
+ if (!record)
72
+ return false;
73
+ if (record.requiresProcedure !== false)
74
+ return false;
75
+ return Object.keys(record).every((key) => key === "requiresProcedure" || key === "responseRecommendation");
76
+ }
77
+ function projectProcedureMemoryContext(request, options) {
78
+ if (!request.longTermMemory?.enabled)
79
+ return undefined;
80
+ if (!options.memoryRecallMessage)
81
+ return projectSupervisorProcedureMemory(options.initialMemoryMessage);
82
+ return projectSupervisorProcedureRecall(options.memoryRecallMessage, {
83
+ requestId: request.requestId,
84
+ callId: options.diagnostic.callId ?? "",
85
+ steeringVersion: options.boundSteeringVersion ?? 0,
86
+ });
87
+ }
88
+ export function buildSupervisorProcedureGateInput(request, options) {
89
+ const format = createSupervisorProcedureGateFormat();
90
+ const memory = projectProcedureMemoryContext(request, options);
91
+ const budget = resolveModelContextBudget({
92
+ runnerConfig: request.runnerConfig, agentMode: request.agentMode,
93
+ modelStep: SUPERVISOR_DECISION_MODEL_STEP,
94
+ configuredInstructionPolicy: "omit",
95
+ ...(request.modelPreference ? { modelPreference: request.modelPreference } : {}),
96
+ ...(request.reasoningPreference ? { reasoningPreference: request.reasoningPreference } : {}),
97
+ ...(request.modelPolicy ? { modelPolicy: request.modelPolicy } : {}),
98
+ });
99
+ const context = projectRequestContext({
100
+ instructions: [PROCEDURE_GATE_INSTRUCTIONS, ...(memory ? [memory.instructions] : [])].join("\n"), format,
101
+ prompt: request.prompt, historyMessages: [], budget,
102
+ ...(memory ? { referenceMessages: [memory.message] } : {}),
103
+ diagnostic: options.diagnostic, onEvent: request.onEvent,
104
+ deferCompactionFailure: true,
105
+ });
106
+ return { modelStep: SUPERVISOR_DECISION_MODEL_STEP, format, context };
107
+ }
108
+ export async function runSupervisorProcedureGate(request, options) {
109
+ const diagnostic = { ...options.diagnostic, decisionPhase: "procedure_gate" };
110
+ const steering = resolveRequestSteeringInbox(request.requestSteering);
111
+ const startedAt = Date.now();
112
+ try {
113
+ assertBoundModelStepSteeringCurrent(steering, options.boundSteeringVersion);
114
+ const input = buildSupervisorProcedureGateInput(request, { ...options, diagnostic });
115
+ traceDebug("runtime.supervisor", "model.started", {
116
+ ...diagnostic, outputContract: input.format.name, messageCount: input.context.messages.length,
117
+ });
118
+ const accepted = await invokeStructuredModelStep({
119
+ request, modelStep: SUPERVISOR_DECISION_MODEL_STEP,
120
+ messages: input.context.messages, format: input.format,
121
+ boundSteeringVersion: options.boundSteeringVersion, contextRetention: "exact",
122
+ configuredInstructionPolicy: "omit",
123
+ timeoutReason: "supervisor_decision_timeout", invalidOutputReason: "invalid_supervisor_decision",
124
+ parse(text) {
125
+ const parsed = parseSupervisorProcedureGateOutput(text);
126
+ if (!parsed.ok)
127
+ return parsed;
128
+ return { ok: true, decision: { decision: parsed.decision, steeringVersion: steering.snapshot().version } };
129
+ },
130
+ });
131
+ request.abortSignal.throwIfAborted();
132
+ assertBoundModelStepSteeringCurrent(steering, accepted.steeringVersion);
133
+ traceDebug("runtime.supervisor", "model.completed", {
134
+ ...diagnostic, outputContract: input.format.name, durationMs: Date.now() - startedAt,
135
+ requiresProcedure: accepted.decision.requiresProcedure,
136
+ });
137
+ return accepted;
138
+ }
139
+ catch (error) {
140
+ traceDebug("runtime.supervisor", "model.failed", {
141
+ ...diagnostic, durationMs: Date.now() - startedAt,
142
+ errorType: error instanceof Error ? error.name : typeof error,
143
+ });
144
+ throw error;
145
+ }
146
+ }
@@ -0,0 +1,9 @@
1
+ import type { ChatMessage } from "../../../model-gateway/types.js";
2
+ export declare const MAX_MEMORY_CHARACTERS = 1000;
3
+ export declare const MEMORY_INSTRUCTIONS: string;
4
+ /** Read-only view of the existing request snapshot; never changes stored memory. */
5
+ export declare function projectSupervisorProcedureMemory(message: ChatMessage | undefined): Readonly<{
6
+ message: ChatMessage;
7
+ instructions: string;
8
+ }> | undefined;
9
+ export declare function renderCompleteMemory(value: unknown): string | undefined;