@abot-ai/runtime 1.1.0 → 1.2.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 (268) hide show
  1. package/README.md +6 -3
  2. package/dist/src/capabilities/tool-types.d.ts +1 -1
  3. package/dist/src/model-gateway/providers/ollama/generation-options.d.ts +1 -3
  4. package/dist/src/model-gateway/providers/ollama/generation-options.js +1 -5
  5. package/dist/src/model-gateway/providers/ollama/payload.js +0 -8
  6. package/dist/src/model-gateway/server/request-body.js +1 -0
  7. package/dist/src/plugin-sdk/index.d.ts +2 -0
  8. package/dist/src/plugin-sdk/index.js +2 -0
  9. package/dist/src/plugin-sdk/tool-availability-brief.d.ts +9 -0
  10. package/dist/src/plugin-sdk/tool-availability-brief.js +48 -0
  11. package/dist/src/plugin-sdk/tool-availability-overview.d.ts +9 -0
  12. package/dist/src/plugin-sdk/tool-availability-overview.js +62 -0
  13. package/dist/src/runtime/adapters/registered-tool-payload-plan.d.ts +0 -9
  14. package/dist/src/runtime/adapters/registered-tool-payload-plan.js +0 -67
  15. package/dist/src/runtime/adapters/registered-tool-payload-related-artifacts.d.ts +13 -0
  16. package/dist/src/runtime/adapters/registered-tool-payload-related-artifacts.js +84 -0
  17. package/dist/src/runtime/adapters/registered-tool-worker-capabilities/catalog.js +4 -0
  18. package/dist/src/runtime/adapters/registered-tool-worker-capabilities/execution.js +3 -0
  19. package/dist/src/runtime/adapters/registered-tool-worker-capabilities/payload-lifecycle.d.ts +1 -0
  20. package/dist/src/runtime/adapters/registered-tool-worker-capabilities/payload-lifecycle.js +11 -1
  21. package/dist/src/runtime/adapters/registered-tool-worker-capabilities/payload-stages.d.ts +1 -0
  22. package/dist/src/runtime/adapters/registered-tool-worker-capabilities/payload-stages.js +9 -1
  23. package/dist/src/runtime/capabilities/request-bound-tool-registry.js +1 -24
  24. package/dist/src/runtime/capabilities/tool-availability.d.ts +6 -0
  25. package/dist/src/runtime/capabilities/tool-availability.js +28 -0
  26. package/dist/src/runtime/context/capability-brief.d.ts +25 -0
  27. package/dist/src/runtime/context/capability-brief.js +106 -0
  28. package/dist/src/runtime/context/request-tool-results-message-binding.d.ts +6 -0
  29. package/dist/src/runtime/context/request-tool-results-message-binding.js +30 -0
  30. package/dist/src/runtime/context/request-tool-results-scope.d.ts +3 -0
  31. package/dist/src/runtime/context/request-tool-results-scope.js +8 -0
  32. package/dist/src/runtime/context/request-tool-results.d.ts +8 -4
  33. package/dist/src/runtime/context/request-tool-results.js +49 -38
  34. package/dist/src/runtime/orchestration/role-calls/candidate-validation.js +8 -1
  35. package/dist/src/runtime/orchestration/role-calls/child-return.d.ts +4 -0
  36. package/dist/src/runtime/orchestration/role-calls/child-return.js +25 -5
  37. package/dist/src/runtime/orchestration/role-calls/command-decoder.js +8 -3
  38. package/dist/src/runtime/orchestration/role-calls/command-dispatch/child-transitions.d.ts +1 -1
  39. package/dist/src/runtime/orchestration/role-calls/command-dispatch/child-transitions.js +17 -2
  40. package/dist/src/runtime/orchestration/role-calls/command-dispatch.d.ts +1 -1
  41. package/dist/src/runtime/orchestration/role-calls/command-dispatch.js +2 -2
  42. package/dist/src/runtime/orchestration/role-calls/contracts.d.ts +5 -2
  43. package/dist/src/runtime/orchestration/role-calls/contracts.js +4 -4
  44. package/dist/src/runtime/orchestration/role-calls/dependency-results.d.ts +1 -1
  45. package/dist/src/runtime/orchestration/role-calls/dependency-results.js +1 -0
  46. package/dist/src/runtime/orchestration/role-calls/index.d.ts +5 -1
  47. package/dist/src/runtime/orchestration/role-calls/index.js +5 -1
  48. package/dist/src/runtime/orchestration/role-calls/ledger.d.ts +3 -1
  49. package/dist/src/runtime/orchestration/role-calls/ledger.js +9 -2
  50. package/dist/src/runtime/orchestration/role-calls/reducer.d.ts +1 -1
  51. package/dist/src/runtime/orchestration/role-calls/reducer.js +2 -2
  52. package/dist/src/runtime/orchestration/role-calls/result-receipt.d.ts +49 -0
  53. package/dist/src/runtime/orchestration/role-calls/result-receipt.js +188 -0
  54. package/dist/src/runtime/orchestration/role-calls/return-result-receipt.d.ts +19 -0
  55. package/dist/src/runtime/orchestration/role-calls/return-result-receipt.js +52 -0
  56. package/dist/src/runtime/orchestration/role-calls/transactions.js +1 -0
  57. package/dist/src/runtime/orchestration/role-calls/work-result-lineage.d.ts +34 -0
  58. package/dist/src/runtime/orchestration/role-calls/work-result-lineage.js +185 -0
  59. package/dist/src/runtime/orchestration/role-calls/work-result-receipt.d.ts +36 -0
  60. package/dist/src/runtime/orchestration/role-calls/work-result-receipt.js +187 -0
  61. package/dist/src/runtime/orchestration/role-executors/activation/result-normalization.js +6 -3
  62. package/dist/src/runtime/orchestration/role-executors/child-invocation/transaction.js +1 -0
  63. package/dist/src/runtime/orchestration/role-executors/contracts.d.ts +2 -1
  64. package/dist/src/runtime/orchestration/worker-capabilities/assignment-provenance.d.ts +36 -0
  65. package/dist/src/runtime/orchestration/worker-capabilities/assignment-provenance.js +171 -0
  66. package/dist/src/runtime/orchestration/worker-capabilities/contracts.d.ts +32 -1
  67. package/dist/src/runtime/orchestration/worker-capabilities/execution/invocation-preparation.d.ts +2 -1
  68. package/dist/src/runtime/orchestration/worker-capabilities/execution/invocation-preparation.js +3 -0
  69. package/dist/src/runtime/orchestration/worker-capabilities/execution.js +42 -19
  70. package/dist/src/runtime/orchestration/worker-capabilities/index.d.ts +2 -0
  71. package/dist/src/runtime/orchestration/worker-capabilities/index.js +2 -0
  72. package/dist/src/runtime/orchestration/worker-capabilities/payload-assignment-validation.d.ts +3 -0
  73. package/dist/src/runtime/orchestration/worker-capabilities/payload-assignment-validation.js +30 -0
  74. package/dist/src/runtime/orchestration/worker-capabilities/payload-author.js +8 -19
  75. package/dist/src/runtime/orchestration/worker-capabilities/payload-contracts.d.ts +5 -1
  76. package/dist/src/runtime/orchestration/worker-capabilities/payload-instructions.js +1 -1
  77. package/dist/src/runtime/orchestration/worker-capabilities/payload-source-provenance.d.ts +14 -0
  78. package/dist/src/runtime/orchestration/worker-capabilities/payload-source-provenance.js +132 -0
  79. package/dist/src/runtime/request/capability-brief.d.ts +5 -0
  80. package/dist/src/runtime/request/capability-brief.js +24 -0
  81. package/dist/src/runtime/request/execution-scope.d.ts +2 -1
  82. package/dist/src/runtime/request/role-executor-composition.js +1 -1
  83. package/dist/src/runtime/request/worker-capability-composition.d.ts +2 -1
  84. package/dist/src/runtime/request/worker-capability-composition.js +6 -1
  85. package/dist/src/runtime/request/worker-capability-payload.js +11 -8
  86. package/dist/src/runtime/steps/execution-agent/prompt.js +4 -3
  87. package/dist/src/runtime/steps/planner-decision/capability-catalog-context.d.ts +14 -0
  88. package/dist/src/runtime/steps/planner-decision/capability-catalog-context.js +87 -0
  89. package/dist/src/runtime/steps/planner-decision/contracts.d.ts +3 -5
  90. package/dist/src/runtime/steps/planner-decision/contracts.js +3 -3
  91. package/dist/src/runtime/steps/planner-decision/format.d.ts +3 -2
  92. package/dist/src/runtime/steps/planner-decision/format.js +73 -76
  93. package/dist/src/runtime/steps/planner-decision/input.d.ts +4 -3
  94. package/dist/src/runtime/steps/planner-decision/input.js +10 -7
  95. package/dist/src/runtime/steps/planner-decision/parser.d.ts +3 -2
  96. package/dist/src/runtime/steps/planner-decision/parser.js +10 -19
  97. package/dist/src/runtime/steps/planner-decision/plan-parser.js +18 -12
  98. package/dist/src/runtime/steps/planner-decision/prompt.js +33 -28
  99. package/dist/src/runtime/steps/planner-decision/resume.d.ts +1 -1
  100. package/dist/src/runtime/steps/planner-decision/resume.js +38 -1
  101. package/dist/src/runtime/steps/planner-decision/run.d.ts +3 -2
  102. package/dist/src/runtime/steps/reviewer-decision/audit-coverage.d.ts +10 -0
  103. package/dist/src/runtime/steps/reviewer-decision/audit-coverage.js +186 -0
  104. package/dist/src/runtime/steps/reviewer-decision/contracts.d.ts +3 -8
  105. package/dist/src/runtime/steps/reviewer-decision/contracts.js +12 -6
  106. package/dist/src/runtime/steps/reviewer-decision/delegated-context.d.ts +24 -0
  107. package/dist/src/runtime/steps/reviewer-decision/delegated-context.js +70 -0
  108. package/dist/src/runtime/steps/reviewer-decision/diagnostics.js +1 -1
  109. package/dist/src/runtime/steps/reviewer-decision/format.js +37 -24
  110. package/dist/src/runtime/steps/reviewer-decision/input.js +1 -1
  111. package/dist/src/runtime/steps/reviewer-decision/model-context.d.ts +4 -3
  112. package/dist/src/runtime/steps/reviewer-decision/model-context.js +92 -10
  113. package/dist/src/runtime/steps/reviewer-decision/parser.js +19 -1
  114. package/dist/src/runtime/steps/reviewer-decision/projection.js +42 -68
  115. package/dist/src/runtime/steps/reviewer-decision/prompt.js +10 -5
  116. package/dist/src/runtime/steps/reviewer-decision/run.js +12 -3
  117. package/dist/src/runtime/steps/reviewer-decision/verification-coverage.d.ts +14 -0
  118. package/dist/src/runtime/steps/reviewer-decision/verification-coverage.js +52 -0
  119. package/dist/src/runtime/steps/supervisor-decision/capability-brief.d.ts +14 -0
  120. package/dist/src/runtime/steps/supervisor-decision/capability-brief.js +38 -0
  121. package/dist/src/runtime/steps/supervisor-decision/contracts.d.ts +7 -3
  122. package/dist/src/runtime/steps/supervisor-decision/diagnostics.d.ts +2 -0
  123. package/dist/src/runtime/steps/supervisor-decision/diagnostics.js +8 -2
  124. package/dist/src/runtime/steps/supervisor-decision/format.js +32 -20
  125. package/dist/src/runtime/steps/supervisor-decision/input.d.ts +4 -1
  126. package/dist/src/runtime/steps/supervisor-decision/input.js +19 -1
  127. package/dist/src/runtime/steps/supervisor-decision/parser.js +62 -59
  128. package/dist/src/runtime/steps/supervisor-decision/prompt.js +6 -7
  129. package/dist/src/runtime/steps/supervisor-decision/resume.js +47 -1
  130. package/dist/src/runtime/steps/supervisor-decision/run.js +10 -0
  131. package/dist/src/runtime/steps/supervisor-decision/working-directory.js +2 -1
  132. package/dist/src/runtime/steps/worker-decision/contracts.d.ts +2 -1
  133. package/dist/src/runtime/steps/worker-decision/input/canonical-state.js +8 -1
  134. package/dist/src/runtime/steps/worker-decision/input/diagnostic-projection.js +2 -2
  135. package/dist/src/runtime/steps/worker-decision/input/prompt-context.d.ts +1 -0
  136. package/dist/src/runtime/steps/worker-decision/input/prompt-context.js +4 -1
  137. package/dist/src/runtime/steps/worker-decision/input/reference-context.js +34 -14
  138. package/dist/src/runtime/steps/worker-decision/input/types.d.ts +2 -1
  139. package/dist/src/runtime/steps/worker-decision/input.d.ts +1 -0
  140. package/dist/src/runtime/steps/worker-decision/input.js +1 -0
  141. package/dist/src/runtime/steps/worker-decision/payload-dependency-results.d.ts +8 -0
  142. package/dist/src/runtime/steps/worker-decision/payload-dependency-results.js +19 -0
  143. package/dist/src/runtime/steps/worker-decision/prompt.js +8 -8
  144. package/dist/src/runtime/steps/worker-decision/result-author.js +18 -11
  145. package/dist/src/runtime/steps/worker-decision/run.js +2 -2
  146. package/dist/src/web-ui/app/ARCHITECTURE.md +19 -6
  147. package/dist/src/web-ui/app/app.js +6 -7
  148. package/dist/src/web-ui/app/components/composer-context-window.d.ts +25 -0
  149. package/dist/src/web-ui/app/components/composer-context-window.js +155 -0
  150. package/dist/src/web-ui/app/components/composer-plan.d.ts +9 -0
  151. package/dist/src/web-ui/app/components/composer-plan.js +128 -0
  152. package/dist/src/web-ui/app/components/conversation-activity.d.ts +5 -6
  153. package/dist/src/web-ui/app/components/conversation-activity.js +64 -157
  154. package/dist/src/web-ui/app/components/conversation-role-cards.d.ts +23 -0
  155. package/dist/src/web-ui/app/components/conversation-role-cards.js +181 -0
  156. package/dist/src/web-ui/app/components/conversation-sidebar-layout.js +12 -0
  157. package/dist/src/web-ui/app/components/conversation-sources.d.ts +7 -0
  158. package/dist/src/web-ui/app/components/conversation-sources.js +182 -0
  159. package/dist/src/web-ui/app/components/conversation-view.js +34 -6
  160. package/dist/src/web-ui/app/components/model-selector.js +4 -1
  161. package/dist/src/web-ui/app/components/operations-section.js +46 -0
  162. package/dist/src/web-ui/app/components/workspace-shell.js +86 -78
  163. package/dist/src/web-ui/app/controllers/realtime-event-controller.d.ts +1 -0
  164. package/dist/src/web-ui/app/controllers/realtime-event-controller.js +55 -90
  165. package/dist/src/web-ui/app/controllers/runtime-selection-controller.js +2 -0
  166. package/dist/src/web-ui/app/controllers/session-controller.js +17 -12
  167. package/dist/src/web-ui/app/index.html +209 -210
  168. package/dist/src/web-ui/app/lib/composer-plan-model.d.ts +32 -0
  169. package/dist/src/web-ui/app/lib/composer-plan-model.js +108 -0
  170. package/dist/src/web-ui/app/lib/conversation-role-model.d.ts +19 -0
  171. package/dist/src/web-ui/app/lib/conversation-role-model.js +193 -0
  172. package/dist/src/web-ui/app/lib/event-presentation.js +30 -9
  173. package/dist/src/web-ui/app/lib/source-url-policy.d.ts +2 -0
  174. package/dist/src/web-ui/app/lib/source-url-policy.js +31 -0
  175. package/dist/src/web-ui/app/lib/task-progress.d.ts +53 -0
  176. package/dist/src/web-ui/app/lib/task-progress.js +233 -0
  177. package/dist/src/web-ui/app/lib/tool-invocation-count.d.ts +5 -0
  178. package/dist/src/web-ui/app/lib/tool-invocation-count.js +21 -0
  179. package/dist/src/web-ui/app/lib/web-source-event.d.ts +8 -0
  180. package/dist/src/web-ui/app/lib/web-source-event.js +21 -0
  181. package/dist/src/web-ui/app/lib/web-sources.d.ts +36 -0
  182. package/dist/src/web-ui/app/lib/web-sources.js +177 -0
  183. package/dist/src/web-ui/app/styles/00-tokens-base.css +15 -3
  184. package/dist/src/web-ui/app/styles/10-shell-sessions.css +24 -34
  185. package/dist/src/web-ui/app/styles/12-conversation-sidebar.css +93 -0
  186. package/dist/src/web-ui/app/styles/20-chat-composer.css +55 -472
  187. package/dist/src/web-ui/app/styles/21-composer-controls.css +368 -0
  188. package/dist/src/web-ui/app/styles/22-composer-context-window.css +90 -0
  189. package/dist/src/web-ui/app/styles/23-composer-plan.css +171 -0
  190. package/dist/src/web-ui/app/styles/24-conversation-role-cards.css +205 -0
  191. package/dist/src/web-ui/app/styles/25-conversation-sources.css +141 -0
  192. package/dist/src/web-ui/app/styles/30-inspector-config.css +21 -209
  193. package/dist/src/web-ui/app/styles/35-memory-onboarding.css +8 -8
  194. package/dist/src/web-ui/app/styles/36-memory-management.css +13 -13
  195. package/dist/src/web-ui/app/styles/37-config-operations.css +197 -0
  196. package/dist/src/web-ui/app/styles/40-config-workspace.css +36 -36
  197. package/dist/src/web-ui/app/styles/90-responsive.css +14 -77
  198. package/dist/src/web-ui/app/styles/foundation.css +2 -2
  199. package/dist/src/web-ui/app/styles.css +7 -0
  200. package/dist/src/web-ui/app/ui-behavior.d.ts +1 -1
  201. package/dist/src/web-ui/app/ui-behavior.js +1 -1
  202. package/docs/configuration.md +15 -8
  203. package/docs/installation.md +7 -4
  204. package/docs/known-limitations.md +21 -0
  205. package/docs/plugins.md +28 -13
  206. package/docs/runtime-invariant-coverage.md +18 -17
  207. package/docs/runtime-prompt-policy-contracts.md +27 -17
  208. package/package.json +4 -3
  209. package/plugins/capability-brief/source/index.ts +5 -48
  210. package/plugins/capability-brief/src/index.cjs +46 -33
  211. package/plugins/system-probe/plugin.json +1 -0
  212. package/plugins/web/README.md +125 -0
  213. package/plugins/web/plugin.json +1 -1
  214. package/plugins/web/skills/web_fetch_skill/SKILL.md +2 -2
  215. package/plugins/web/skills/web_search_skill/SKILL.md +8 -4
  216. package/plugins/web/source/errors.ts +5 -1
  217. package/plugins/web/source/fetch-presentation.ts +61 -0
  218. package/plugins/web/source/fetch-service.ts +2 -31
  219. package/plugins/web/source/light/config.ts +196 -0
  220. package/plugins/web/source/light/crawl/origin-gate.ts +134 -0
  221. package/plugins/web/source/light/crawl/robots-cache.ts +71 -0
  222. package/plugins/web/source/light/crawl/robots-parser.ts +132 -0
  223. package/plugins/web/source/light/crawl/robots-policy.ts +154 -0
  224. package/plugins/web/source/light/crawl/session-budget.ts +141 -0
  225. package/plugins/web/source/light/crawl/transport.ts +216 -0
  226. package/plugins/web/source/light/discovery/candidate-values.ts +63 -0
  227. package/plugins/web/source/light/discovery/feed-document.ts +127 -0
  228. package/plugins/web/source/light/discovery/html-links.ts +80 -0
  229. package/plugins/web/source/light/discovery/html-robots-directives.ts +29 -0
  230. package/plugins/web/source/light/discovery/markup-tree.ts +145 -0
  231. package/plugins/web/source/light/discovery/origin-dates.ts +71 -0
  232. package/plugins/web/source/light/discovery/sitemap-document.ts +63 -0
  233. package/plugins/web/source/light/documents/cache-policy.ts +28 -0
  234. package/plugins/web/source/light/documents/document-cache.ts +99 -0
  235. package/plugins/web/source/light/documents/document-charset.ts +89 -0
  236. package/plugins/web/source/light/documents/document-contract.ts +20 -0
  237. package/plugins/web/source/light/documents/document-reader.ts +75 -0
  238. package/plugins/web/source/light/documents/extract-document.ts +124 -0
  239. package/plugins/web/source/light/documents/http-cache-freshness.ts +68 -0
  240. package/plugins/web/source/light/documents/response-decoding.ts +120 -0
  241. package/plugins/web/source/light/ranking/document-ranking.ts +114 -0
  242. package/plugins/web/source/light/ranking/query-normalization.ts +69 -0
  243. package/plugins/web/source/light/search-collection.ts +136 -0
  244. package/plugins/web/source/light/search-frontier.ts +246 -0
  245. package/plugins/web/source/light/search-metadata.ts +84 -0
  246. package/plugins/web/source/light/search-service.ts +154 -0
  247. package/plugins/web/source/light/search-unavailable.ts +33 -0
  248. package/plugins/web/source/light/sources/catalog.ts +312 -0
  249. package/plugins/web/source/light/sources/source-definition.ts +9 -0
  250. package/plugins/web/source/light/sources/source-selection.ts +35 -0
  251. package/plugins/web/source/plugin.ts +70 -56
  252. package/plugins/web/source/public-http.ts +10 -1
  253. package/plugins/web/source/search-presentation.ts +63 -63
  254. package/plugins/web/source/search-service-selector.ts +31 -0
  255. package/plugins/web/source/search-service.ts +6 -0
  256. package/plugins/web/source/search-source-presentation.ts +76 -0
  257. package/plugins/web/source/search-types.ts +4 -0
  258. package/plugins/web/source/source-output-receipts.ts +267 -0
  259. package/plugins/web/source/source-receipt-budget.ts +51 -0
  260. package/plugins/web/source/source-receipt-contract.ts +18 -0
  261. package/plugins/web/src/index.cjs +3214 -288
  262. package/src/runtime/README.md +30 -9
  263. package/dist/src/model-gateway/structured-output/budget.d.ts +0 -7
  264. package/dist/src/model-gateway/structured-output/budget.js +0 -20
  265. package/dist/src/model-gateway/structured-output/schema-character-estimator.d.ts +0 -1
  266. package/dist/src/model-gateway/structured-output/schema-character-estimator.js +0 -211
  267. package/dist/src/model-gateway/structured-output-budget.d.ts +0 -1
  268. package/dist/src/model-gateway/structured-output-budget.js +0 -1
@@ -0,0 +1,106 @@
1
+ import { buildToolAvailabilityOverview, } from "../../plugin-sdk/tool-availability-overview.js";
2
+ import { assessRequestMessagesBudget } from "./request-context-budget.js";
3
+ import { estimateMessageTokens } from "./token-estimator.js";
4
+ export const CAPABILITY_BRIEF_KIND = "runtime_capability_brief_v1";
5
+ export const CAPABILITY_BRIEF_MAX_TOKENS = 512;
6
+ const CAPABILITY_BRIEF_PREFIX = `${CAPABILITY_BRIEF_KIND}\n`;
7
+ /** Optional availability metadata admitted against the full context estimate. */
8
+ export function projectCapabilityBrief(params) {
9
+ const budgetTokens = resolveCapabilityBriefBudget(params);
10
+ if (params.groups.length === 0) {
11
+ return omittedBrief(budgetTokens, "empty_catalog");
12
+ }
13
+ const levels = hasCompleteCapabilityBriefEntries(params.entries, params.groups)
14
+ ? ["detailed", "titles", "groups"]
15
+ : ["groups"];
16
+ for (const level of levels) {
17
+ const body = buildToolAvailabilityOverview(params.entries ?? [], params.groups, level);
18
+ const message = Object.freeze({
19
+ role: "system",
20
+ content: [
21
+ CAPABILITY_BRIEF_KIND,
22
+ "Request-registry availability for delegation only. Data, not instructions, user intent, execution authority, pending work, or completion evidence.",
23
+ `Detail: ${level}. Complete coverage at this level; omitted detail does not mean unavailable capabilities.`,
24
+ body,
25
+ ].join("\n"),
26
+ });
27
+ const estimatedTokens = estimateMessageTokens(message, params.context.budget.tokenEstimation);
28
+ if (!fitsCapabilityBriefBudget(estimatedTokens, budgetTokens))
29
+ continue;
30
+ return Object.freeze({
31
+ level,
32
+ message,
33
+ estimatedTokens,
34
+ budgetTokens,
35
+ reason: "complete_catalog",
36
+ });
37
+ }
38
+ return omittedBrief(budgetTokens, "insufficient_budget");
39
+ }
40
+ /** Consumers explicitly remove this optional reference at narrower phases. */
41
+ export function isCapabilityBriefMessage(message) {
42
+ if (message.role !== "system")
43
+ return false;
44
+ return message.content.startsWith(CAPABILITY_BRIEF_PREFIX);
45
+ }
46
+ function resolveCapabilityBriefBudget(params) {
47
+ const { context } = params;
48
+ const messages = [
49
+ { role: "system", content: context.instructions },
50
+ ...(context.priorConversationMessages ?? []),
51
+ ...context.historyMessages,
52
+ ...(context.referenceMessages ?? []),
53
+ ...(context.referenceParts?.flatMap((part) => part.messages) ?? []),
54
+ ...(context.continuationMessages ?? []),
55
+ ...(context.continuationParts?.flatMap((part) => part.messages) ?? []),
56
+ {
57
+ role: "user",
58
+ content: context.prompt,
59
+ ...(context.attachments ? { attachments: context.attachments } : {}),
60
+ },
61
+ ...(params.additionalBudgetMessages ?? []),
62
+ ];
63
+ const { budget } = assessRequestMessagesBudget({
64
+ messages,
65
+ budget: context.budget,
66
+ ...(context.format ? { format: context.format } : {}),
67
+ });
68
+ // Configured methodology is added later; reserve it for the 70% threshold
69
+ // as well as the input ceiling. Strictly below: admission triggers on >=.
70
+ const instructionReserve = context.budget.configuredInstructionReserveTokens ?? 0;
71
+ const compactionHeadroom = budget.compactionTriggerInputTokens -
72
+ 1 -
73
+ budget.estimatedInputTokens -
74
+ instructionReserve;
75
+ const admissionHeadroom = budget.availableInputTokens - budget.estimatedInputTokens;
76
+ return Math.max(0, Math.min(CAPABILITY_BRIEF_MAX_TOKENS, compactionHeadroom, admissionHeadroom));
77
+ }
78
+ function hasCompleteCapabilityBriefEntries(entries, groups) {
79
+ if (entries === undefined)
80
+ return false;
81
+ if (entries.length === 0)
82
+ return false;
83
+ const operationIds = new Set(entries.map((entry) => entry.operationId));
84
+ if (operationIds.size !== entries.length)
85
+ return false;
86
+ const counts = new Map();
87
+ for (const entry of entries) {
88
+ for (const groupId of new Set(entry.catalogGroups)) {
89
+ counts.set(groupId, (counts.get(groupId) ?? 0) + 1);
90
+ }
91
+ }
92
+ if (counts.size !== groups.length)
93
+ return false;
94
+ return groups.every((group) => counts.get(group.groupId) === group.memberCount);
95
+ }
96
+ function fitsCapabilityBriefBudget(tokens, budget) {
97
+ return tokens <= budget;
98
+ }
99
+ function omittedBrief(budgetTokens, reason) {
100
+ return Object.freeze({
101
+ level: "none",
102
+ estimatedTokens: 0,
103
+ budgetTokens,
104
+ reason,
105
+ });
106
+ }
@@ -0,0 +1,6 @@
1
+ import type { ChatMessage } from "../../model-gateway/types.js";
2
+ import type { RequestToolResultsView } from "./request-tool-results.js";
3
+ /** Mints one frozen message bound to its exact canonical result view. */
4
+ export declare function bindRequestToolResultsMessage(view: RequestToolResultsView, content: string): ChatMessage;
5
+ /** Accepts only a message minted for this exact canonical result view. */
6
+ export declare function isRequestToolResultsMessageBoundToView(message: ChatMessage, view: RequestToolResultsView): boolean;
@@ -0,0 +1,30 @@
1
+ const REQUEST_TOOL_RESULTS_MESSAGE_AUTHORITY = Symbol("requestToolResultsMessageAuthority");
2
+ /** Mints one frozen message bound to its exact canonical result view. */
3
+ export function bindRequestToolResultsMessage(view, content) {
4
+ const message = { role: "user", content };
5
+ const authority = Object.freeze({ message, view });
6
+ Object.defineProperty(message, REQUEST_TOOL_RESULTS_MESSAGE_AUTHORITY, {
7
+ value: authority,
8
+ enumerable: false,
9
+ configurable: false,
10
+ writable: false,
11
+ });
12
+ return Object.freeze(message);
13
+ }
14
+ /** Accepts only a message minted for this exact canonical result view. */
15
+ export function isRequestToolResultsMessageBoundToView(message, view) {
16
+ const descriptor = Object.getOwnPropertyDescriptor(message, REQUEST_TOOL_RESULTS_MESSAGE_AUTHORITY);
17
+ if (!descriptor)
18
+ return false;
19
+ const authority = descriptor.value;
20
+ if (typeof authority !== "object" || authority === null)
21
+ return false;
22
+ if (!Object.isFrozen(authority))
23
+ return false;
24
+ const candidate = authority;
25
+ return (candidate.message === message &&
26
+ candidate.view === view &&
27
+ descriptor.enumerable === false &&
28
+ descriptor.configurable === false &&
29
+ descriptor.writable === false);
30
+ }
@@ -0,0 +1,3 @@
1
+ import type { RequestToolResultsView } from "./request-tool-results.js";
2
+ /** Requires Planner-item views to carry only their exact call lane. */
3
+ export declare function isRequestToolResultsViewValidForCallScope(view: RequestToolResultsView, callId: string, callScoped: boolean): boolean;
@@ -0,0 +1,8 @@
1
+ /** Requires Planner-item views to carry only their exact call lane. */
2
+ export function isRequestToolResultsViewValidForCallScope(view, callId, callScoped) {
3
+ if (!callScoped)
4
+ return view.scope === undefined;
5
+ return (view.scope?.kind === "call" &&
6
+ view.scope.callId === callId &&
7
+ view.results.every((result) => result.callId === callId));
8
+ }
@@ -26,12 +26,16 @@ export type RequestToolResult = Readonly<{
26
26
  export type RequestToolResultsView = Readonly<{
27
27
  sourceRevision: number;
28
28
  results: readonly RequestToolResult[];
29
+ scope?: Readonly<{
30
+ kind: "call";
31
+ callId: string;
32
+ }>;
29
33
  }>;
30
34
  /**
31
- * Projects every settled capability result in canonical ledger order.
32
- * Summaries remain request-wide. Complete reference data is projected only
33
- * back to the exact call that produced it; callers consume the settled child
34
- * result instead of receiving a second copy of the capability payload.
35
+ * Projects settled capability results in canonical ledger order. Direct
36
+ * Planner-owned Workers receive only their exact call lane; other roles keep
37
+ * request-wide summaries. Complete reference data is projected only back to
38
+ * the exact call that produced it.
35
39
  */
36
40
  export declare function projectRequestToolResults(params: Readonly<{
37
41
  ledger: RoleCallLedger;
@@ -1,15 +1,17 @@
1
1
  import { isRoleCapabilityId, ROLE_CAPABILITY_REFERENCE_DATA_MAX_LENGTH, ROLE_CAPABILITY_RESULT_REFERENCE_LIMIT_MAX, ROLE_CAPABILITY_RESULT_REFERENCE_TARGET_MAX_LENGTH, ROLE_CALL_RESULT_MAX_LENGTH, } from "../orchestration/role-calls/index.js";
2
+ import { projectWorkerCapabilityPlannerItemBinding } from "../orchestration/worker-capabilities/assignment-provenance.js";
2
3
  import { traceDebug } from "../observability/debug-logger.js";
3
4
  import { normalizeCapabilityAdapterResult, } from "../orchestration/capability-adapters/result.js";
5
+ import { bindRequestToolResultsMessage } from "./request-tool-results-message-binding.js";
4
6
  import { createSemanticCompactionSha256Fingerprint, } from "./semantic-compaction/index.js";
5
7
  import { projectAcceptedCapabilityAction, } from "./accepted-capability-action.js";
6
8
  export const REQUEST_TOOL_RESULTS_MESSAGE_KIND = "runtime_request_tool_results_v1";
7
9
  const REQUEST_TOOL_RESULTS_LOG_SCOPE = "runtime.request_tool_results";
8
10
  /**
9
- * Projects every settled capability result in canonical ledger order.
10
- * Summaries remain request-wide. Complete reference data is projected only
11
- * back to the exact call that produced it; callers consume the settled child
12
- * result instead of receiving a second copy of the capability payload.
11
+ * Projects settled capability results in canonical ledger order. Direct
12
+ * Planner-owned Workers receive only their exact call lane; other roles keep
13
+ * request-wide summaries. Complete reference data is projected only back to
14
+ * the exact call that produced it.
13
15
  */
14
16
  export function projectRequestToolResults(params) {
15
17
  const projected = [];
@@ -19,9 +21,12 @@ export function projectRequestToolResults(params) {
19
21
  if (params.ledger.current() !== params.head) {
20
22
  throw new Error("request_tool_results_head_stale");
21
23
  }
22
- if (!params.head.state.calls.some(({ callId }) => callId === params.callId)) {
24
+ const call = params.head.state.calls.find(({ callId }) => callId === params.callId);
25
+ if (!call) {
23
26
  throw new Error("request_tool_results_call_invalid");
24
27
  }
28
+ const plannerItemScoped = projectWorkerCapabilityPlannerItemBinding(params.head, call) !==
29
+ undefined;
25
30
  for (const execution of params.head.state.capabilityExecutions) {
26
31
  if (execution.status === "running") {
27
32
  runningExecutionCount += 1;
@@ -68,6 +73,8 @@ export function projectRequestToolResults(params) {
68
73
  adapterResult: exactResult.value,
69
74
  });
70
75
  sourceProjected.push(sourceResult);
76
+ if (plannerItemScoped && execution.callId !== params.callId)
77
+ continue;
71
78
  if (execution.callId !== params.callId) {
72
79
  const { referenceData: _referenceData, adapterResult: _adapterResult, acceptedAction: _acceptedAction, ...summaryOnlyResult } = sourceResult;
73
80
  projected.push(Object.freeze(summaryOnlyResult));
@@ -80,6 +87,14 @@ export function projectRequestToolResults(params) {
80
87
  const view = Object.freeze({
81
88
  sourceRevision: params.head.revision,
82
89
  results: Object.freeze(currentResults),
90
+ ...(plannerItemScoped
91
+ ? {
92
+ scope: Object.freeze({
93
+ kind: "call",
94
+ callId: params.callId,
95
+ }),
96
+ }
97
+ : {}),
83
98
  });
84
99
  traceProjection("projected", params, currentResults, runningExecutionCount, undefined, sourceProjected);
85
100
  return view;
@@ -91,15 +106,13 @@ export function projectRequestToolResults(params) {
91
106
  }
92
107
  export function buildRequestToolResultsMessage(view) {
93
108
  const results = projectModelVisibleRequestToolResults(view.results);
94
- return Object.freeze({
95
- role: "user",
96
- content: JSON.stringify({
97
- kind: REQUEST_TOOL_RESULTS_MESSAGE_KIND,
98
- authority: "reference_data",
99
- sourceRevision: view.sourceRevision,
100
- results,
101
- }),
102
- });
109
+ return bindRequestToolResultsMessage(view, JSON.stringify({
110
+ kind: REQUEST_TOOL_RESULTS_MESSAGE_KIND,
111
+ authority: "reference_data",
112
+ sourceRevision: view.sourceRevision,
113
+ ...(view.scope ? { coverage: view.scope } : {}),
114
+ results,
115
+ }));
103
116
  }
104
117
  export function buildCompactedRequestToolResultsMessage(view, checkpoint) {
105
118
  const modelVisibleResults = projectModelVisibleRequestToolResults(view.results);
@@ -127,30 +140,28 @@ export function buildCompactedRequestToolResultsMessage(view, checkpoint) {
127
140
  })) {
128
141
  throw new Error("request_tool_results_compaction_fingerprint_mismatch");
129
142
  }
130
- return Object.freeze({
131
- role: "user",
132
- content: JSON.stringify({
133
- kind: REQUEST_TOOL_RESULTS_MESSAGE_KIND,
134
- authority: "reference_data",
135
- sourceRevision: view.sourceRevision,
136
- semanticCheckpoint: {
137
- kind: checkpoint.kind,
138
- scopeId: checkpoint.scopeId,
139
- roleId: checkpoint.roleId,
140
- callId: checkpoint.callId,
141
- checkpointSourceRevision: checkpoint.sourceRevision,
142
- presenceEffect: "passive_role_continuation_not_user_intent_or_completion",
143
- coveredSources: checkpoint.sourceDigests.map(({ sourceRef, sourceFingerprint, digest }) => ({
144
- sourceRef,
145
- sourceFingerprint,
146
- digest,
147
- })),
148
- continuation: checkpoint.continuation,
149
- coveredResults,
150
- },
151
- results: modelVisibleResults.filter(({ executionId }) => !coveredExecutionIds.has(executionId)),
152
- }),
153
- });
143
+ return bindRequestToolResultsMessage(view, JSON.stringify({
144
+ kind: REQUEST_TOOL_RESULTS_MESSAGE_KIND,
145
+ authority: "reference_data",
146
+ sourceRevision: view.sourceRevision,
147
+ ...(view.scope ? { coverage: view.scope } : {}),
148
+ semanticCheckpoint: {
149
+ kind: checkpoint.kind,
150
+ scopeId: checkpoint.scopeId,
151
+ roleId: checkpoint.roleId,
152
+ callId: checkpoint.callId,
153
+ checkpointSourceRevision: checkpoint.sourceRevision,
154
+ presenceEffect: "passive_role_continuation_not_user_intent_or_completion",
155
+ coveredSources: checkpoint.sourceDigests.map(({ sourceRef, sourceFingerprint, digest }) => ({
156
+ sourceRef,
157
+ sourceFingerprint,
158
+ digest,
159
+ })),
160
+ continuation: checkpoint.continuation,
161
+ coveredResults,
162
+ },
163
+ results: modelVisibleResults.filter(({ executionId }) => !coveredExecutionIds.has(executionId)),
164
+ }));
154
165
  }
155
166
  /**
156
167
  * Keeps the canonical settled-result view intact while ensuring that the
@@ -8,6 +8,7 @@ import { isRoleOperationSupervisionSettlementHistoryValid, isRoleOperationSuperv
8
8
  import { isReconsiderationCauseBoundToInvocationCount } from "./reconsideration-cause.js";
9
9
  import { isRoleCapabilityId, ROLE_CAPABILITY_EXECUTION_LIMIT_MAX, ROLE_CAPABILITY_INVOCATION_INTENT_MAX_LENGTH, ROLE_CAPABILITY_REFERENCE_DATA_MAX_LENGTH, ROLE_CALL_LEDGER_CONTRACT_VERSION, } from "./contracts.js";
10
10
  import { validateRoleCallPlans } from "./plan.js";
11
+ import { isRoleCallResultReceiptValidForStoredResult } from "./result-receipt.js";
11
12
  import { findRoleActivationBudgetIssue } from "./activation-budget.js";
12
13
  import { isRoleCallWorkerCapabilityScope } from "./worker-capability-scope.js";
13
14
  import { isRoleCallWorkingDirectoryRoleId, normalizeEstablishedRoleCallWorkingDirectory, normalizeRoleCallWorkingDirectory, } from "./working-directory.js";
@@ -157,7 +158,13 @@ export function validateRoleCallState(state, policy) {
157
158
  producer.status !== "completed" ||
158
159
  producer.roleId !== result.roleId ||
159
160
  (result.outcome !== "completed" && result.outcome !== "failed") ||
160
- !isBoundedText(result.summary, policy.limits.maxResultChars)) {
161
+ !isBoundedText(result.summary, policy.limits.maxResultChars) ||
162
+ !isRoleCallResultReceiptValidForStoredResult({
163
+ receipt: result.receipt,
164
+ producer,
165
+ result,
166
+ policy, state,
167
+ })) {
161
168
  issues.push(issue("invalid_role_call_result_owner", `state.results.${result.resultRef}`));
162
169
  }
163
170
  }
@@ -1,5 +1,7 @@
1
1
  import { type RoleCallCommitEffect, type RoleCallLedger, type RoleCallLedgerCommitResult, type RoleCallLedgerHead, type RoleCallWorkerCapabilityScope } from "./contracts.js";
2
2
  import { type RuntimeDelegateRoleId } from "../roles.js";
3
+ import { type RoleCallResultReceipt } from "./result-receipt.js";
4
+ import { type RoleCallWorkResultLineage } from "./work-result-lineage.js";
3
5
  export type CompletedRoleChildResult = Readonly<{
4
6
  callerCallId: string;
5
7
  childCallId: string;
@@ -11,6 +13,8 @@ export type CompletedRoleChildResult = Readonly<{
11
13
  dependencyResultRefs: readonly string[];
12
14
  outcome: "completed" | "failed";
13
15
  summary: string;
16
+ receipt?: RoleCallResultReceipt;
17
+ workLineage?: RoleCallWorkResultLineage;
14
18
  }>;
15
19
  export type RoleChildReturnContext = Readonly<{
16
20
  callerCallId: string;
@@ -1,5 +1,7 @@
1
1
  import { ROLE_CALL_OBJECTIVE_MAX_LENGTH, ROLE_CALL_RESULT_MAX_LENGTH, } from "./contracts.js";
2
2
  import { isRuntimeDelegateRoleId, } from "../roles.js";
3
+ import { isRoleCallResultReceiptValidForStoredResult, } from "./result-receipt.js";
4
+ import { projectRoleCallWorkResultLineage, } from "./work-result-lineage.js";
3
5
  export function requireRoleCallChildReturnCommit(commit) {
4
6
  if (!commit.ok || commit.effect.type !== "child_returned") {
5
7
  throw new Error("role_child_return_commit_invalid");
@@ -27,7 +29,7 @@ export function projectRoleChildReturnContext(ledger, commit) {
27
29
  !caller.childCallIds.includes(childCallId)) {
28
30
  throw new Error("role_child_return_transition_invalid");
29
31
  }
30
- const completedChildren = projectCompletedChildren(returned.head.state, caller);
32
+ const completedChildren = projectCompletedChildren(returned.head.state, caller, returned.head.policy);
31
33
  const returnedChild = completedChildren.find((child) => child.childCallId === childCallId && child.resultRef === resultRef);
32
34
  if (returnedChild?.childCallId !== childCallId ||
33
35
  returnedChild.resultRef !== resultRef) {
@@ -41,13 +43,13 @@ export function projectRoleChildReturnContext(ledger, commit) {
41
43
  completedChildren: Object.freeze(completedChildren),
42
44
  });
43
45
  }
44
- function projectCompletedChildren(state, caller) {
46
+ function projectCompletedChildren(state, caller, policy) {
45
47
  return Object.freeze(caller.childCallIds.map((completedChildCallId) => projectCompletedChild(state, {
46
48
  callerCallId: caller.callId,
47
49
  childCallId: completedChildCallId,
48
- })));
50
+ }, policy)));
49
51
  }
50
- function projectCompletedChild(state, refs) {
52
+ function projectCompletedChild(state, refs, policy) {
51
53
  const child = state.calls.find((call) => call.callId === refs.childCallId);
52
54
  const result = state.results.find((candidate) => candidate.resultRef === child?.resultRef);
53
55
  if (child?.status !== "completed" ||
@@ -58,9 +60,17 @@ function projectCompletedChild(state, refs) {
58
60
  result?.producerCallId !== child.callId ||
59
61
  result.roleId !== child.roleId ||
60
62
  (result.outcome !== "completed" && result.outcome !== "failed") ||
61
- !isBoundedText(result.summary, ROLE_CALL_RESULT_MAX_LENGTH)) {
63
+ !isBoundedText(result.summary, ROLE_CALL_RESULT_MAX_LENGTH) ||
64
+ !isRoleCallResultReceiptValidForStoredResult({
65
+ receipt: result.receipt,
66
+ producer: child,
67
+ result,
68
+ policy,
69
+ state,
70
+ })) {
62
71
  throw new Error("role_completed_child_projection_invalid");
63
72
  }
73
+ const workLineage = projectCompletedChildWorkLineage(state, result.receipt);
64
74
  return Object.freeze({
65
75
  callerCallId: refs.callerCallId,
66
76
  childCallId: child.callId,
@@ -76,8 +86,18 @@ function projectCompletedChild(state, refs) {
76
86
  dependencyResultRefs: child.dependencyResultRefs,
77
87
  outcome: result.outcome,
78
88
  summary: result.summary,
89
+ ...(result.receipt ? { receipt: result.receipt } : {}),
90
+ ...(workLineage ? { workLineage } : {}),
79
91
  });
80
92
  }
93
+ function projectCompletedChildWorkLineage(state, receipt) {
94
+ if (receipt?.kind !== "work_result_v1")
95
+ return undefined;
96
+ const lineage = projectRoleCallWorkResultLineage({ state, receipt });
97
+ if (!lineage)
98
+ throw new Error("role_completed_child_projection_invalid");
99
+ return lineage;
100
+ }
81
101
  function isBoundedText(value, maximumLength) {
82
102
  return (typeof value === "string" &&
83
103
  value.trim().length > 0 &&
@@ -4,6 +4,7 @@ import { isRoleOperationFingerprint, isRoleOperationOutcomeFingerprintForOutcome
4
4
  import { isReconsiderationCauseBoundToInvocationCount, normalizeRoleCapabilitySelectionReconsiderationCause, } from "./reconsideration-cause.js";
5
5
  import { isRoleCapabilityId, } from "./contracts.js";
6
6
  import { parseRoleCallPlanBinding } from "./plan.js";
7
+ import { normalizeRoleCallResultReceipt } from "./result-receipt.js";
7
8
  import { parseRoleCallWorkerCapabilityScope } from "./worker-capability-scope.js";
8
9
  import { isRoleCallWorkingDirectoryRoleId, normalizeEstablishedRoleCallWorkingDirectory, normalizeRoleCallWorkingDirectory, } from "./working-directory.js";
9
10
  import { exactKeys, isRecord, isRoleCapabilityDeclaredEffect, isRoleCapabilityObservedEffect, isUniqueStringArray, parseCapabilityResultReferences, parseOptionalCapabilityAdapterResult, } from "./reducer-primitives.js";
@@ -90,7 +91,8 @@ export function decodeRoleCallCommand(input) {
90
91
  }
91
92
  : { ok: false, code: "invalid_command" };
92
93
  }
93
- case "return_child":
94
+ case "return_child": {
95
+ const receipt = normalizeRoleCallResultReceipt(input.receipt);
94
96
  return exactKeys(input, [
95
97
  "authority",
96
98
  "type",
@@ -98,12 +100,13 @@ export function decodeRoleCallCommand(input) {
98
100
  "childCallId",
99
101
  "outcome",
100
102
  "summary",
101
- ]) &&
103
+ ], ["receipt"]) &&
102
104
  input.authority === "runtime" &&
103
105
  typeof input.callerCallId === "string" &&
104
106
  typeof input.childCallId === "string" &&
105
107
  (input.outcome === "completed" || input.outcome === "failed") &&
106
- typeof input.summary === "string"
108
+ typeof input.summary === "string" &&
109
+ receipt !== null
107
110
  ? {
108
111
  ok: true,
109
112
  value: {
@@ -113,9 +116,11 @@ export function decodeRoleCallCommand(input) {
113
116
  childCallId: input.childCallId,
114
117
  outcome: input.outcome,
115
118
  summary: input.summary,
119
+ ...(receipt ? { receipt } : {}),
116
120
  },
117
121
  }
118
122
  : { ok: false, code: "invalid_command" };
123
+ }
119
124
  case "begin_capability_execution":
120
125
  return exactKeys(input, [
121
126
  "authority",
@@ -1,3 +1,3 @@
1
1
  import type { OpenChildRoleCallCommand, ReturnChildRoleCallCommand, RoleCallPolicy, RoleCallState, RoleCallTransitionResult } from "../contracts.js";
2
2
  export declare function openChild(state: RoleCallState, command: OpenChildRoleCallCommand, policy: RoleCallPolicy): RoleCallTransitionResult;
3
- export declare function returnChild(state: RoleCallState, command: ReturnChildRoleCallCommand, policy: RoleCallPolicy): RoleCallTransitionResult;
3
+ export declare function returnChild(state: RoleCallState, command: ReturnChildRoleCallCommand, policy: RoleCallPolicy, admittedHeadRevision?: number): RoleCallTransitionResult;
@@ -3,6 +3,7 @@ import { resetRoleCapabilitySelectionSupervisionState } from "../capability-sele
3
3
  import { bindRoleCallPlanChild, plannerPlanHasOpenItems, settleRoleCallPlanChild, } from "../plan.js";
4
4
  import { areOwnedDependencyResults, commit, findCall, isBoundedText, reject, } from "../reducer-primitives.js";
5
5
  import { isRoleCallWorkingDirectoryRoleId } from "../working-directory.js";
6
+ import { resolveCanonicalResultReceiptForReturn } from "../return-result-receipt.js";
6
7
  import { nextCallId, replaceCall } from "./call-frame-state.js";
7
8
  export function openChild(state, command, policy) {
8
9
  const { callerCallId, objective, workerCapabilityScope, workingDirectory, dependencyResultRefs = [], plannerPlan, } = command;
@@ -91,8 +92,8 @@ export function openChild(state, command, policy) {
91
92
  : {}),
92
93
  });
93
94
  }
94
- export function returnChild(state, command, policy) {
95
- const { callerCallId, childCallId, outcome, summary } = command;
95
+ export function returnChild(state, command, policy, admittedHeadRevision) {
96
+ const { callerCallId, childCallId, outcome, summary, receipt } = command;
96
97
  if (state.phase === "empty") {
97
98
  return reject(state, "root_missing");
98
99
  }
@@ -105,12 +106,26 @@ export function returnChild(state, command, policy) {
105
106
  return reject(state, "invalid_command");
106
107
  }
107
108
  const resultRef = nextResultRef(state);
109
+ const receiptResolution = resolveCanonicalResultReceiptForReturn({
110
+ state,
111
+ caller,
112
+ child,
113
+ resultRef,
114
+ outcome,
115
+ policy,
116
+ admittedHeadRevision,
117
+ ...(receipt ? { suppliedReceipt: receipt } : {}),
118
+ });
119
+ if (!receiptResolution.ok)
120
+ return reject(state, "invalid_command");
108
121
  const result = {
109
122
  resultRef,
110
123
  producerCallId: childCallId,
111
124
  roleId: child.roleId,
112
125
  outcome,
113
126
  summary: summary.trim(),
127
+ ...(receiptResolution.receipt
128
+ ? { receipt: receiptResolution.receipt } : {}),
114
129
  };
115
130
  if (hasIncompleteCompletedPlannerPlan(state, child, outcome)) {
116
131
  return reject(state, "planner_plan_incomplete");
@@ -1,2 +1,2 @@
1
1
  import type { RoleCallLedgerCommand, RoleCallPolicy, RoleCallState, RoleCallTransitionResult } from "./contracts.js";
2
- export declare function dispatchRoleCallCommand(state: RoleCallState, command: RoleCallLedgerCommand, policy: RoleCallPolicy): RoleCallTransitionResult;
2
+ export declare function dispatchRoleCallCommand(state: RoleCallState, command: RoleCallLedgerCommand, policy: RoleCallPolicy, admittedHeadRevision?: number): RoleCallTransitionResult;
@@ -4,7 +4,7 @@ import { reconsiderCapabilitySelection } from "./command-dispatch/capability-sel
4
4
  import { establishWorkingDirectory, updateCapabilityScope, } from "./command-dispatch/call-scope-transitions.js";
5
5
  import { openChild, returnChild, } from "./command-dispatch/child-transitions.js";
6
6
  import { completeRootResponse, createRoot, } from "./command-dispatch/root-transitions.js";
7
- export function dispatchRoleCallCommand(state, command, policy) {
7
+ export function dispatchRoleCallCommand(state, command, policy, admittedHeadRevision) {
8
8
  switch (command.type) {
9
9
  case "create_root":
10
10
  return createRoot(state);
@@ -13,7 +13,7 @@ export function dispatchRoleCallCommand(state, command, policy) {
13
13
  case "open_child":
14
14
  return openChild(state, command, policy);
15
15
  case "return_child":
16
- return returnChild(state, command, policy);
16
+ return returnChild(state, command, policy, admittedHeadRevision);
17
17
  case "begin_capability_execution":
18
18
  return beginCapabilityExecution(state, command, policy);
19
19
  case "settle_capability_execution":
@@ -4,8 +4,9 @@ import type { RuntimeDelegateRoleId, RuntimeRoleId } from "../roles.js";
4
4
  import type { RoleOperationFingerprint, RoleOperationOutcomeFingerprint, RoleOperationSupervisionState } from "./operation-supervision.js";
5
5
  import type { RoleCapabilitySelectionSupervisionStage, RoleCapabilitySelectionSupervisionState, RoleCapabilitySelectionSupervisionTrigger } from "./capability-selection-supervision.js";
6
6
  import type { RoleCapabilitySelectionReconsiderationCause } from "./reconsideration-cause.js";
7
- export declare const ROLE_CALL_LEDGER_CONTRACT_VERSION = 15;
8
- export declare const ROLE_CALL_LEDGER_HEAD_KIND: "runtime_role_call_ledger_v15";
7
+ import type { RoleCallResultReceipt } from "./result-receipt.js";
8
+ export declare const ROLE_CALL_LEDGER_CONTRACT_VERSION = 17;
9
+ export declare const ROLE_CALL_LEDGER_HEAD_KIND: "runtime_role_call_ledger_v17";
9
10
  export declare const ROLE_CALL_OBJECTIVE_MAX_LENGTH = 8192;
10
11
  export declare const ROLE_CALL_RESULT_MAX_LENGTH = 8192;
11
12
  export declare const ROLE_CALL_RESPONSE_MAX_LENGTH = 65536;
@@ -95,6 +96,7 @@ export type RoleCallResult = Readonly<{
95
96
  roleId: RuntimeDelegateRoleId;
96
97
  outcome: "completed" | "failed";
97
98
  summary: string;
99
+ receipt?: RoleCallResultReceipt;
98
100
  }>;
99
101
  export type RoleCallPlanItemStatus = "pending" | "in_progress" | "done" | "blocked";
100
102
  export type RoleCallPlanProposal = Readonly<{
@@ -214,6 +216,7 @@ export type ReturnChildRoleCallCommand = Readonly<{
214
216
  childCallId: string;
215
217
  outcome: "completed" | "failed";
216
218
  summary: string;
219
+ receipt?: RoleCallResultReceipt;
217
220
  }>;
218
221
  export type BeginRoleCapabilityExecutionCommand = Readonly<{
219
222
  authority: "active_role";
@@ -1,5 +1,5 @@
1
- export const ROLE_CALL_LEDGER_CONTRACT_VERSION = 15;
2
- export const ROLE_CALL_LEDGER_HEAD_KIND = "runtime_role_call_ledger_v15";
1
+ export const ROLE_CALL_LEDGER_CONTRACT_VERSION = 17;
2
+ export const ROLE_CALL_LEDGER_HEAD_KIND = "runtime_role_call_ledger_v17";
3
3
  export const ROLE_CALL_OBJECTIVE_MAX_LENGTH = 8_192;
4
4
  export const ROLE_CALL_RESULT_MAX_LENGTH = 8_192;
5
5
  export const ROLE_CALL_RESPONSE_MAX_LENGTH = 65_536;
@@ -24,8 +24,8 @@ export function isRoleCapabilityId(input) {
24
24
  }
25
25
  export const SUPERVISOR_WORKER_V1_AUTHORITY_SNAPSHOT = Object.freeze({
26
26
  id: "supervisor-worker-v1",
27
- version: 1,
28
- definitionHash: "sha256:40cf0e04cbf5cf2f0ae5ce6d0e1c7aa87c21247416a7771441083ec0c73db62f",
27
+ version: 2,
28
+ definitionHash: "sha256:2ee79cee6dbb27ffaeb59f84c4c838cf9d16a965ca4f07e7d638e8589868e036",
29
29
  rootContractId: "supervisor",
30
30
  availableSubordinateContractIds: Object.freeze([
31
31
  "planner",
@@ -1,5 +1,5 @@
1
1
  import type { RoleCallFrame, RoleCallLedgerHead, RoleCallResult } from "./contracts.js";
2
- export type RoleCallDependencyResult = Readonly<Pick<RoleCallResult, "resultRef" | "producerCallId" | "roleId" | "outcome" | "summary">>;
2
+ export type RoleCallDependencyResult = Readonly<Pick<RoleCallResult, "resultRef" | "producerCallId" | "roleId" | "outcome" | "summary" | "receipt">>;
3
3
  /**
4
4
  * Resolves only the canonical direct-sibling results attached to this call.
5
5
  * The role-executor boundary selects them mechanically; this projection
@@ -67,6 +67,7 @@ function projectRoleCallDependencyResultsUnchecked(head, suppliedCall) {
67
67
  roleId: result.roleId,
68
68
  outcome: result.outcome,
69
69
  summary: result.summary,
70
+ ...(result.receipt ? { receipt: result.receipt } : {}),
70
71
  });
71
72
  });
72
73
  return Object.freeze(results);
@@ -6,10 +6,14 @@ export * from "./operation-supervision-state-validation.js";
6
6
  export * from "./capability-selection-reconsideration.js";
7
7
  export * from "./capability-selection-supervision.js";
8
8
  export * from "./reconsideration-cause.js";
9
+ export * from "./result-receipt.js";
10
+ export * from "./return-result-receipt.js";
11
+ export * from "./work-result-lineage.js";
12
+ export * from "./work-result-receipt.js";
9
13
  export * from "./assignment-scope.js";
10
14
  export * from "./child-return.js";
11
15
  export * from "./dependency-results.js";
12
- export * from "./ledger.js";
16
+ export { createRoleCallLedger } from "./ledger.js";
13
17
  export * from "./plan.js";
14
18
  export * from "./reducer.js";
15
19
  export * from "./transactions.js";