@nordhavnhq/runner 0.0.0-stage → 0.95.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 (338) hide show
  1. package/bin/cliclick +0 -0
  2. package/dist/brand.d.ts +5 -0
  3. package/dist/brand.js +18 -0
  4. package/dist/cli/agent.d.ts +9 -0
  5. package/dist/cli/agent.js +80 -0
  6. package/dist/cli/folder.d.ts +2 -0
  7. package/dist/cli/folder.js +103 -0
  8. package/dist/cli/init.d.ts +2 -0
  9. package/dist/cli/init.js +67 -0
  10. package/dist/cli/lifecycle.d.ts +3 -0
  11. package/dist/cli/lifecycle.js +149 -0
  12. package/dist/cli/link.d.ts +42 -0
  13. package/dist/cli/link.js +314 -0
  14. package/dist/cli/logs.d.ts +2 -0
  15. package/dist/cli/logs.js +147 -0
  16. package/dist/cli/prompts.d.ts +7 -0
  17. package/dist/cli/prompts.js +13 -0
  18. package/dist/cli/ps.d.ts +2 -0
  19. package/dist/cli/ps.js +81 -0
  20. package/dist/cli/relay.d.ts +4 -0
  21. package/dist/cli/relay.js +29 -0
  22. package/dist/cli/update.d.ts +6 -0
  23. package/dist/cli/update.js +131 -0
  24. package/dist/config.d.ts +166 -0
  25. package/dist/config.js +383 -0
  26. package/dist/index.d.ts +2 -0
  27. package/dist/index.js +145 -0
  28. package/dist/legacy-env.d.ts +4 -0
  29. package/dist/legacy-env.js +32 -0
  30. package/dist/paths.d.ts +37 -0
  31. package/dist/paths.js +92 -0
  32. package/dist/runtime/daemon.d.ts +57 -0
  33. package/dist/runtime/daemon.js +159 -0
  34. package/dist/runtime/dev-start.d.ts +31 -0
  35. package/dist/runtime/dev-start.js +110 -0
  36. package/dist/runtime/file-claims.d.ts +58 -0
  37. package/dist/runtime/file-claims.js +174 -0
  38. package/dist/runtime/fs-browse.d.ts +18 -0
  39. package/dist/runtime/fs-browse.js +104 -0
  40. package/dist/runtime/fs-checkout.d.ts +154 -0
  41. package/dist/runtime/fs-checkout.js +1049 -0
  42. package/dist/runtime/fs-git-index.d.ts +22 -0
  43. package/dist/runtime/fs-git-index.js +133 -0
  44. package/dist/runtime/fs-git.d.ts +16 -0
  45. package/dist/runtime/fs-git.js +424 -0
  46. package/dist/runtime/git-relay.d.ts +46 -0
  47. package/dist/runtime/git-relay.js +259 -0
  48. package/dist/runtime/git-unpushed.d.ts +36 -0
  49. package/dist/runtime/git-unpushed.js +93 -0
  50. package/dist/runtime/node-version.d.ts +12 -0
  51. package/dist/runtime/node-version.js +39 -0
  52. package/dist/runtime/preview-tunnel.d.ts +16 -0
  53. package/dist/runtime/preview-tunnel.js +135 -0
  54. package/dist/runtime/processes.d.ts +61 -0
  55. package/dist/runtime/processes.js +408 -0
  56. package/dist/runtime/project-node-download.d.ts +17 -0
  57. package/dist/runtime/project-node-download.js +137 -0
  58. package/dist/runtime/project-node.d.ts +65 -0
  59. package/dist/runtime/project-node.js +223 -0
  60. package/dist/runtime/reap-scratch.d.ts +22 -0
  61. package/dist/runtime/reap-scratch.js +112 -0
  62. package/dist/runtime/spill-tool-output.d.ts +14 -0
  63. package/dist/runtime/spill-tool-output.js +84 -0
  64. package/dist/runtime/up.d.ts +6 -0
  65. package/dist/runtime/up.js +1325 -0
  66. package/dist/tools/_coerce.d.ts +2 -0
  67. package/dist/tools/_coerce.js +26 -0
  68. package/dist/tools/_commit-scope.d.ts +14 -0
  69. package/dist/tools/_commit-scope.js +70 -0
  70. package/dist/tools/_jail.d.ts +68 -0
  71. package/dist/tools/_jail.js +209 -0
  72. package/dist/tools/_output.d.ts +24 -0
  73. package/dist/tools/_output.js +48 -0
  74. package/dist/tools/_ripgrep.d.ts +46 -0
  75. package/dist/tools/_ripgrep.js +148 -0
  76. package/dist/tools/_run-worktree.d.ts +10 -0
  77. package/dist/tools/_run-worktree.js +27 -0
  78. package/dist/tools/_shell-words.d.ts +15 -0
  79. package/dist/tools/_shell-words.js +43 -0
  80. package/dist/tools/_sonar/astro.d.ts +6 -0
  81. package/dist/tools/_sonar/astro.js +45 -0
  82. package/dist/tools/_sonar/blade.d.ts +3 -0
  83. package/dist/tools/_sonar/blade.js +53 -0
  84. package/dist/tools/_sonar/build.d.ts +44 -0
  85. package/dist/tools/_sonar/build.js +147 -0
  86. package/dist/tools/_sonar/changed.d.ts +21 -0
  87. package/dist/tools/_sonar/changed.js +230 -0
  88. package/dist/tools/_sonar/diagnose/delta.d.ts +27 -0
  89. package/dist/tools/_sonar/diagnose/delta.js +64 -0
  90. package/dist/tools/_sonar/diagnose/detect.d.ts +39 -0
  91. package/dist/tools/_sonar/diagnose/detect.js +117 -0
  92. package/dist/tools/_sonar/diagnose/index.d.ts +13 -0
  93. package/dist/tools/_sonar/diagnose/index.js +217 -0
  94. package/dist/tools/_sonar/diagnose/lint-worker.d.ts +1 -0
  95. package/dist/tools/_sonar/diagnose/lint-worker.js +48 -0
  96. package/dist/tools/_sonar/diagnose/pool.d.ts +22 -0
  97. package/dist/tools/_sonar/diagnose/pool.js +149 -0
  98. package/dist/tools/_sonar/diagnose/rules.d.ts +23 -0
  99. package/dist/tools/_sonar/diagnose/rules.js +131 -0
  100. package/dist/tools/_sonar/diagnose/types-worker.d.ts +1 -0
  101. package/dist/tools/_sonar/diagnose/types-worker.js +183 -0
  102. package/dist/tools/_sonar/files.d.ts +14 -0
  103. package/dist/tools/_sonar/files.js +121 -0
  104. package/dist/tools/_sonar/graph.d.ts +34 -0
  105. package/dist/tools/_sonar/graph.js +164 -0
  106. package/dist/tools/_sonar/hints.d.ts +116 -0
  107. package/dist/tools/_sonar/hints.js +545 -0
  108. package/dist/tools/_sonar/imports.d.ts +38 -0
  109. package/dist/tools/_sonar/imports.js +275 -0
  110. package/dist/tools/_sonar/index.d.ts +79 -0
  111. package/dist/tools/_sonar/index.js +462 -0
  112. package/dist/tools/_sonar/keys.d.ts +5 -0
  113. package/dist/tools/_sonar/keys.js +248 -0
  114. package/dist/tools/_sonar/laravel-routes.d.ts +15 -0
  115. package/dist/tools/_sonar/laravel-routes.js +263 -0
  116. package/dist/tools/_sonar/laravel.d.ts +64 -0
  117. package/dist/tools/_sonar/laravel.js +326 -0
  118. package/dist/tools/_sonar/location.d.ts +33 -0
  119. package/dist/tools/_sonar/location.js +137 -0
  120. package/dist/tools/_sonar/map.d.ts +43 -0
  121. package/dist/tools/_sonar/map.js +212 -0
  122. package/dist/tools/_sonar/parse.d.ts +3 -0
  123. package/dist/tools/_sonar/parse.js +76 -0
  124. package/dist/tools/_sonar/prewarm.d.ts +9 -0
  125. package/dist/tools/_sonar/prewarm.js +96 -0
  126. package/dist/tools/_sonar/prisma.d.ts +9 -0
  127. package/dist/tools/_sonar/prisma.js +51 -0
  128. package/dist/tools/_sonar/refs.d.ts +7 -0
  129. package/dist/tools/_sonar/refs.js +273 -0
  130. package/dist/tools/_sonar/render.d.ts +66 -0
  131. package/dist/tools/_sonar/render.js +498 -0
  132. package/dist/tools/_sonar/resolve.d.ts +63 -0
  133. package/dist/tools/_sonar/resolve.js +402 -0
  134. package/dist/tools/_sonar/roots.d.ts +4 -0
  135. package/dist/tools/_sonar/roots.js +42 -0
  136. package/dist/tools/_sonar/routes.d.ts +5 -0
  137. package/dist/tools/_sonar/routes.js +247 -0
  138. package/dist/tools/_sonar/serve.d.ts +12 -0
  139. package/dist/tools/_sonar/serve.js +104 -0
  140. package/dist/tools/_sonar/suggest.d.ts +23 -0
  141. package/dist/tools/_sonar/suggest.js +114 -0
  142. package/dist/tools/_sonar/tests.d.ts +21 -0
  143. package/dist/tools/_sonar/tests.js +134 -0
  144. package/dist/tools/_sonar/tsconfig.d.ts +34 -0
  145. package/dist/tools/_sonar/tsconfig.js +188 -0
  146. package/dist/tools/_sonar/types.d.ts +81 -0
  147. package/dist/tools/_sonar/types.js +6 -0
  148. package/dist/tools/_symbols.d.ts +27 -0
  149. package/dist/tools/_symbols.js +461 -0
  150. package/dist/tools/_test-report.d.ts +47 -0
  151. package/dist/tools/_test-report.js +203 -0
  152. package/dist/tools/_touched.d.ts +44 -0
  153. package/dist/tools/_touched.js +195 -0
  154. package/dist/tools/_upload.d.ts +26 -0
  155. package/dist/tools/_upload.js +132 -0
  156. package/dist/tools/_worktree-setup.d.ts +29 -0
  157. package/dist/tools/_worktree-setup.js +204 -0
  158. package/dist/tools/browser.d.ts +2 -0
  159. package/dist/tools/browser.js +8 -0
  160. package/dist/tools/commit-guard.d.ts +44 -0
  161. package/dist/tools/commit-guard.js +165 -0
  162. package/dist/tools/computer.d.ts +13 -0
  163. package/dist/tools/computer.js +952 -0
  164. package/dist/tools/console.d.ts +44 -0
  165. package/dist/tools/console.js +739 -0
  166. package/dist/tools/database.d.ts +28 -0
  167. package/dist/tools/database.js +152 -0
  168. package/dist/tools/filesystem.d.ts +36 -0
  169. package/dist/tools/filesystem.js +506 -0
  170. package/dist/tools/git-tag.d.ts +10 -0
  171. package/dist/tools/git-tag.js +164 -0
  172. package/dist/tools/git.d.ts +52 -0
  173. package/dist/tools/git.js +1272 -0
  174. package/dist/tools/http.d.ts +12 -0
  175. package/dist/tools/http.js +119 -0
  176. package/dist/tools/image.d.ts +8 -0
  177. package/dist/tools/image.js +551 -0
  178. package/dist/tools/index.d.ts +13 -0
  179. package/dist/tools/index.js +58 -0
  180. package/dist/tools/outline.d.ts +20 -0
  181. package/dist/tools/outline.js +98 -0
  182. package/dist/tools/search.d.ts +17 -0
  183. package/dist/tools/search.js +391 -0
  184. package/dist/tools/sonar.d.ts +17 -0
  185. package/dist/tools/sonar.js +231 -0
  186. package/dist/tools/testing.d.ts +36 -0
  187. package/dist/tools/testing.js +273 -0
  188. package/dist/tools/upload.d.ts +8 -0
  189. package/dist/tools/upload.js +106 -0
  190. package/dist/tools/webcam.d.ts +28 -0
  191. package/dist/tools/webcam.js +967 -0
  192. package/dist/update/install-kind.d.ts +35 -0
  193. package/dist/update/install-kind.js +109 -0
  194. package/dist/update/install.d.ts +32 -0
  195. package/dist/update/install.js +187 -0
  196. package/dist/update/manifest.d.ts +18 -0
  197. package/dist/update/manifest.js +73 -0
  198. package/dist/update/peers.d.ts +18 -0
  199. package/dist/update/peers.js +43 -0
  200. package/dist/update/policy.d.ts +20 -0
  201. package/dist/update/policy.js +49 -0
  202. package/dist/update/supervisor.d.ts +25 -0
  203. package/dist/update/supervisor.js +83 -0
  204. package/dist/update/updater.d.ts +44 -0
  205. package/dist/update/updater.js +116 -0
  206. package/dist/utils/format.d.ts +50 -0
  207. package/dist/utils/format.js +190 -0
  208. package/dist/version.d.ts +17 -0
  209. package/dist/version.js +63 -0
  210. package/dist/version.json +5 -0
  211. package/node_modules/@nordhavnhq/runner-browser/dist/act-tools.d.ts +15 -0
  212. package/node_modules/@nordhavnhq/runner-browser/dist/act-tools.js +541 -0
  213. package/node_modules/@nordhavnhq/runner-browser/dist/cast-hub.d.ts +25 -0
  214. package/node_modules/@nordhavnhq/runner-browser/dist/cast-hub.js +137 -0
  215. package/node_modules/@nordhavnhq/runner-browser/dist/guard.d.ts +21 -0
  216. package/node_modules/@nordhavnhq/runner-browser/dist/guard.js +104 -0
  217. package/node_modules/@nordhavnhq/runner-browser/dist/host-protocol.d.ts +47 -0
  218. package/node_modules/@nordhavnhq/runner-browser/dist/host-protocol.js +41 -0
  219. package/node_modules/@nordhavnhq/runner-browser/dist/host.d.ts +18 -0
  220. package/node_modules/@nordhavnhq/runner-browser/dist/host.js +15 -0
  221. package/node_modules/@nordhavnhq/runner-browser/dist/index.d.ts +13 -0
  222. package/node_modules/@nordhavnhq/runner-browser/dist/index.js +28 -0
  223. package/node_modules/@nordhavnhq/runner-browser/dist/live-input.d.ts +74 -0
  224. package/node_modules/@nordhavnhq/runner-browser/dist/live-input.js +93 -0
  225. package/node_modules/@nordhavnhq/runner-browser/dist/live-open.d.ts +4 -0
  226. package/node_modules/@nordhavnhq/runner-browser/dist/live-open.js +57 -0
  227. package/node_modules/@nordhavnhq/runner-browser/dist/live.d.ts +148 -0
  228. package/node_modules/@nordhavnhq/runner-browser/dist/live.js +179 -0
  229. package/node_modules/@nordhavnhq/runner-browser/dist/local-live.d.ts +31 -0
  230. package/node_modules/@nordhavnhq/runner-browser/dist/local-live.js +262 -0
  231. package/node_modules/@nordhavnhq/runner-browser/dist/marks.d.ts +36 -0
  232. package/node_modules/@nordhavnhq/runner-browser/dist/marks.js +173 -0
  233. package/node_modules/@nordhavnhq/runner-browser/dist/page-events.d.ts +27 -0
  234. package/node_modules/@nordhavnhq/runner-browser/dist/page-events.js +82 -0
  235. package/node_modules/@nordhavnhq/runner-browser/dist/page-tools.d.ts +13 -0
  236. package/node_modules/@nordhavnhq/runner-browser/dist/page-tools.js +526 -0
  237. package/node_modules/@nordhavnhq/runner-browser/dist/params.d.ts +12 -0
  238. package/node_modules/@nordhavnhq/runner-browser/dist/params.js +32 -0
  239. package/node_modules/@nordhavnhq/runner-browser/dist/pick.d.ts +24 -0
  240. package/node_modules/@nordhavnhq/runner-browser/dist/pick.js +76 -0
  241. package/node_modules/@nordhavnhq/runner-browser/dist/session.d.ts +225 -0
  242. package/node_modules/@nordhavnhq/runner-browser/dist/session.js +507 -0
  243. package/node_modules/@nordhavnhq/runner-browser/dist/shots.d.ts +11 -0
  244. package/node_modules/@nordhavnhq/runner-browser/dist/shots.js +103 -0
  245. package/node_modules/@nordhavnhq/runner-browser/dist/show.d.ts +10 -0
  246. package/node_modules/@nordhavnhq/runner-browser/dist/show.js +190 -0
  247. package/node_modules/@nordhavnhq/runner-browser/dist/target.d.ts +37 -0
  248. package/node_modules/@nordhavnhq/runner-browser/dist/target.js +82 -0
  249. package/node_modules/@nordhavnhq/runner-browser/dist/tour.d.ts +19 -0
  250. package/node_modules/@nordhavnhq/runner-browser/dist/tour.js +178 -0
  251. package/node_modules/@nordhavnhq/runner-browser/package.json +18 -0
  252. package/node_modules/@nordhavnhq/runner-runtime/dist/config.d.ts +96 -0
  253. package/node_modules/@nordhavnhq/runner-runtime/dist/config.js +25 -0
  254. package/node_modules/@nordhavnhq/runner-runtime/dist/connection.d.ts +276 -0
  255. package/node_modules/@nordhavnhq/runner-runtime/dist/connection.js +507 -0
  256. package/node_modules/@nordhavnhq/runner-runtime/dist/constants.d.ts +48 -0
  257. package/node_modules/@nordhavnhq/runner-runtime/dist/constants.js +95 -0
  258. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/batch.d.ts +94 -0
  259. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/batch.js +219 -0
  260. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/calls.d.ts +136 -0
  261. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/calls.js +214 -0
  262. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/fs.d.ts +735 -0
  263. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/fs.js +40 -0
  264. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/loop.d.ts +362 -0
  265. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/loop.js +703 -0
  266. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/own-files.d.ts +105 -0
  267. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/own-files.js +202 -0
  268. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/phases.d.ts +204 -0
  269. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/phases.js +497 -0
  270. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/pins.d.ts +45 -0
  271. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/pins.js +176 -0
  272. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/processes.d.ts +74 -0
  273. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/processes.js +72 -0
  274. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/release-tag.d.ts +59 -0
  275. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/release-tag.js +117 -0
  276. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/replay.d.ts +62 -0
  277. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/replay.js +84 -0
  278. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/tool-names.d.ts +27 -0
  279. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/tool-names.js +80 -0
  280. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/version.d.ts +22 -0
  281. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/version.js +22 -0
  282. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/wire.d.ts +595 -0
  283. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/wire.js +85 -0
  284. package/node_modules/@nordhavnhq/runner-runtime/dist/index.d.ts +43 -0
  285. package/node_modules/@nordhavnhq/runner-runtime/dist/index.js +50 -0
  286. package/node_modules/@nordhavnhq/runner-runtime/dist/inference.d.ts +135 -0
  287. package/node_modules/@nordhavnhq/runner-runtime/dist/inference.js +945 -0
  288. package/node_modules/@nordhavnhq/runner-runtime/dist/mcp.d.ts +67 -0
  289. package/node_modules/@nordhavnhq/runner-runtime/dist/mcp.js +47 -0
  290. package/node_modules/@nordhavnhq/runner-runtime/dist/platform.d.ts +21 -0
  291. package/node_modules/@nordhavnhq/runner-runtime/dist/platform.js +25 -0
  292. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/auto-load.d.ts +39 -0
  293. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/auto-load.js +67 -0
  294. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/background-commands.d.ts +61 -0
  295. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/background-commands.js +58 -0
  296. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/chat-run-ends.d.ts +23 -0
  297. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/chat-run-ends.js +42 -0
  298. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/duration.d.ts +6 -0
  299. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/duration.js +12 -0
  300. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/events.d.ts +150 -0
  301. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/events.js +36 -0
  302. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/extract-json.d.ts +14 -0
  303. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/extract-json.js +49 -0
  304. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/handle-chat.d.ts +109 -0
  305. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/handle-chat.js +894 -0
  306. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/handle-task.d.ts +73 -0
  307. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/handle-task.js +765 -0
  308. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/loop.d.ts +246 -0
  309. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/loop.js +621 -0
  310. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/messages.d.ts +88 -0
  311. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/messages.js +188 -0
  312. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/pending-steers.d.ts +15 -0
  313. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/pending-steers.js +10 -0
  314. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/phased-loop.d.ts +16 -0
  315. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/phased-loop.js +97 -0
  316. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/project-instructions.d.ts +22 -0
  317. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/project-instructions.js +47 -0
  318. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/run-tools.d.ts +26 -0
  319. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/run-tools.js +48 -0
  320. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/scratch-prompt.d.ts +8 -0
  321. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/scratch-prompt.js +19 -0
  322. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/side-question.d.ts +76 -0
  323. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/side-question.js +155 -0
  324. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/task-validation.d.ts +43 -0
  325. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/task-validation.js +37 -0
  326. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/unload-toolset.d.ts +49 -0
  327. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/unload-toolset.js +104 -0
  328. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/write-scope.d.ts +16 -0
  329. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/write-scope.js +6 -0
  330. package/node_modules/@nordhavnhq/runner-runtime/dist/tools/delegate.d.ts +86 -0
  331. package/node_modules/@nordhavnhq/runner-runtime/dist/tools/delegate.js +141 -0
  332. package/node_modules/@nordhavnhq/runner-runtime/dist/tools/index.d.ts +179 -0
  333. package/node_modules/@nordhavnhq/runner-runtime/dist/tools/index.js +35 -0
  334. package/node_modules/@nordhavnhq/runner-runtime/dist/tools/mcp.d.ts +21 -0
  335. package/node_modules/@nordhavnhq/runner-runtime/dist/tools/mcp.js +179 -0
  336. package/node_modules/@nordhavnhq/runner-runtime/package.json +18 -0
  337. package/package.json +33 -4
  338. package/README.md +0 -3
@@ -0,0 +1,94 @@
1
+ /**
2
+ * The universal MCP batch envelope, shared by both agent runtimes.
3
+ *
4
+ * Part of the agent contract (see `version.ts`): this folder is copied verbatim
5
+ * into the runner (`apps/runner/packages/runtime/src/contract/`), so
6
+ * an internal agent and an external one run the SAME code here. Keep it free
7
+ * of dependencies and of imports outside this folder.
8
+ *
9
+ * Every `studio_*` tool accepts `{ batch: [args, ...] }`. The runtime that
10
+ * executes the tool fans it out into N parallel single calls and answers
11
+ * `{ results: [{ ok: true, data } | { ok: false, error, statusCode? }, ...] }`,
12
+ * in order, one failure never stopping the others. What a single call IS
13
+ * differs per runtime (a Nitro `$fetch` loopback in the studio, an HTTP call
14
+ * from the runner), so that part is handed in as `runOne`.
15
+ */
16
+ /** Cap on items per `{ batch: [...] }` call. Each item runs the full route
17
+ * chain (auth, validation, broadcasts), so it stays conservative. */
18
+ export declare const MCP_BATCH_MAX = 100;
19
+ /** Tools that must never fan out.
20
+ *
21
+ * `studio_load_toolset`'s response is consumed by the runtime itself rather
22
+ * than by the model, so a `{ results: [] }` wrapper would break that consumer.
23
+ * `studio_route_meeting_turn` is different: its response is ordinary, but the
24
+ * fan-out is parallel, and handing the floor to N agents at once in one room
25
+ * is precisely the thing a chair exists to prevent.
26
+ *
27
+ * `studio_start_timer` and `studio_stop_timer` are the same class of problem
28
+ * as the meeting floor: a person has exactly ONE running clock, and starting
29
+ * one stops the previous one. Fanned out in parallel, N starts race to stop
30
+ * each other and the surviving clock is whichever write happened to land last.
31
+ * `studio_log_time` is deliberately NOT here: settled entries do not interact,
32
+ * and "log my forgotten week" is exactly what batch is for.
33
+ *
34
+ * `studio_ask` ends the agent's turn once its question is on screen (a chat)
35
+ * or a blocking decision is open (a task), and both loops read that off the
36
+ * single-call result. */
37
+ export declare const MCP_BATCH_DENYLIST: ReadonlySet<string>;
38
+ /** Tools whose batch runs item by item, in order, instead of in parallel.
39
+ *
40
+ * `studio_speak`: every item is a clip its receivers hear in turn. In
41
+ * parallel the clips are made (and announced) in whatever order the provider
42
+ * answers, so a sentence split over three items is heard shuffled. */
43
+ export declare const MCP_BATCH_SEQUENTIAL: ReadonlySet<string>;
44
+ export type BatchItemResult = {
45
+ ok: true;
46
+ data: unknown;
47
+ } | {
48
+ ok: false;
49
+ error: string;
50
+ statusCode?: number;
51
+ };
52
+ export interface BatchEnvelope {
53
+ results: BatchItemResult[];
54
+ }
55
+ /** Detect the `batch` envelope in args, tolerating the common LLM mistake of
56
+ * serialising the array as a JSON string. Returns the parsed array, or null
57
+ * when there is no `batch` field at all (the normal single-call path).
58
+ *
59
+ * If `batch` IS present but does not resolve to an array, this THROWS rather
60
+ * than silently falling through to a single call: a stringified-but-malformed
61
+ * batch used to fan out to nothing, which is a stealthy failure mode. */
62
+ export declare function normaliseBatchValue(args: unknown): unknown[] | null;
63
+ /** Each batch item should be an object; tolerate JSON-stringified objects the
64
+ * same way `normaliseBatchValue` tolerates a stringified `batch`. */
65
+ export declare function coerceBatchItem(item: unknown): Record<string, unknown>;
66
+ /**
67
+ * Run a tool call that may carry the batch envelope. Returns null when `args`
68
+ * has no `batch` (the caller runs its ordinary single call), otherwise the
69
+ * envelope. Throws, with the message the model should read, when the batch is
70
+ * malformed, too large, or aimed at a tool on the denylist.
71
+ *
72
+ * `runOne` executes ONE item through the runtime's own single-call path and
73
+ * reports it as a `BatchItemResult`; a rejection it lets escape is reported
74
+ * as `{ ok: false, error }` with the error's message.
75
+ */
76
+ export declare function runBatch(toolName: string, args: unknown, runOne: (itemArgs: Record<string, unknown>) => Promise<BatchItemResult>): Promise<BatchEnvelope | null>;
77
+ /**
78
+ * Cutting a tool result down to what a stored or relayed tool step keeps.
79
+ *
80
+ * Both runtimes keep at most `TOOL_RESULT_CHARS` of a result on a tool-use
81
+ * frame and in a `tool_use` Entry, so a 1 MB tool body never ends up in a row
82
+ * or on a socket. A plain slice is fine for text, but not for the batch
83
+ * envelope: cut in the middle it is no longer JSON, and whoever reads it back
84
+ * (the call card, which needs each item's `ok`) reads every item as failed.
85
+ * Four calls that all answered drew as "0 answered, 4 failed", with the first
86
+ * answer's raw JSON as the error of every row. So an envelope is shortened
87
+ * ITEM BY ITEM: each keeps its `ok` and `statusCode`, its text gets an even
88
+ * share of the room, and the whole stays valid JSON, marked `clipped` so a
89
+ * reader knows the full text lives elsewhere.
90
+ */
91
+ export declare const TOOL_RESULT_CHARS = 2000;
92
+ /** The result as a stored tool step keeps it: whole when it fits, a batch
93
+ * envelope shortened per item (still JSON), anything else sliced. */
94
+ export declare function clipToolResult(result: string, max?: number): string;
@@ -0,0 +1,219 @@
1
+ /**
2
+ * The universal MCP batch envelope, shared by both agent runtimes.
3
+ *
4
+ * Part of the agent contract (see `version.ts`): this folder is copied verbatim
5
+ * into the runner (`apps/runner/packages/runtime/src/contract/`), so
6
+ * an internal agent and an external one run the SAME code here. Keep it free
7
+ * of dependencies and of imports outside this folder.
8
+ *
9
+ * Every `studio_*` tool accepts `{ batch: [args, ...] }`. The runtime that
10
+ * executes the tool fans it out into N parallel single calls and answers
11
+ * `{ results: [{ ok: true, data } | { ok: false, error, statusCode? }, ...] }`,
12
+ * in order, one failure never stopping the others. What a single call IS
13
+ * differs per runtime (a Nitro `$fetch` loopback in the studio, an HTTP call
14
+ * from the runner), so that part is handed in as `runOne`.
15
+ */
16
+ /** Cap on items per `{ batch: [...] }` call. Each item runs the full route
17
+ * chain (auth, validation, broadcasts), so it stays conservative. */
18
+ export const MCP_BATCH_MAX = 100;
19
+ /** Tools that must never fan out.
20
+ *
21
+ * `studio_load_toolset`'s response is consumed by the runtime itself rather
22
+ * than by the model, so a `{ results: [] }` wrapper would break that consumer.
23
+ * `studio_route_meeting_turn` is different: its response is ordinary, but the
24
+ * fan-out is parallel, and handing the floor to N agents at once in one room
25
+ * is precisely the thing a chair exists to prevent.
26
+ *
27
+ * `studio_start_timer` and `studio_stop_timer` are the same class of problem
28
+ * as the meeting floor: a person has exactly ONE running clock, and starting
29
+ * one stops the previous one. Fanned out in parallel, N starts race to stop
30
+ * each other and the surviving clock is whichever write happened to land last.
31
+ * `studio_log_time` is deliberately NOT here: settled entries do not interact,
32
+ * and "log my forgotten week" is exactly what batch is for.
33
+ *
34
+ * `studio_ask` ends the agent's turn once its question is on screen (a chat)
35
+ * or a blocking decision is open (a task), and both loops read that off the
36
+ * single-call result. */
37
+ export const MCP_BATCH_DENYLIST = new Set([
38
+ 'studio_load_toolset',
39
+ 'studio_route_meeting_turn',
40
+ 'studio_start_timer',
41
+ 'studio_stop_timer',
42
+ // One question per decision, and a blocking one ends the run: never fanned out.
43
+ 'studio_ask',
44
+ // The phase tools of a run that plans first (phases.ts): one plan, one
45
+ // escalation, each read by the loop itself.
46
+ 'studio_submit_plan',
47
+ 'studio_escalate',
48
+ ]);
49
+ /** Tools whose batch runs item by item, in order, instead of in parallel.
50
+ *
51
+ * `studio_speak`: every item is a clip its receivers hear in turn. In
52
+ * parallel the clips are made (and announced) in whatever order the provider
53
+ * answers, so a sentence split over three items is heard shuffled. */
54
+ export const MCP_BATCH_SEQUENTIAL = new Set([
55
+ 'studio_speak',
56
+ ]);
57
+ const BATCH_HINT = 'Pass `batch` as an actual array of arg objects: { batch: [{ ...args }, ...] }.';
58
+ /** Detect the `batch` envelope in args, tolerating the common LLM mistake of
59
+ * serialising the array as a JSON string. Returns the parsed array, or null
60
+ * when there is no `batch` field at all (the normal single-call path).
61
+ *
62
+ * If `batch` IS present but does not resolve to an array, this THROWS rather
63
+ * than silently falling through to a single call: a stringified-but-malformed
64
+ * batch used to fan out to nothing, which is a stealthy failure mode. */
65
+ export function normaliseBatchValue(args) {
66
+ if (!args || typeof args !== 'object')
67
+ return null;
68
+ const raw = args.batch;
69
+ if (raw === undefined)
70
+ return null;
71
+ if (Array.isArray(raw))
72
+ return raw;
73
+ if (typeof raw === 'string') {
74
+ let parsed;
75
+ try {
76
+ parsed = JSON.parse(raw);
77
+ }
78
+ catch {
79
+ throw new Error(`batch: got a string that is not valid JSON. ${BATCH_HINT}`);
80
+ }
81
+ if (Array.isArray(parsed))
82
+ return parsed;
83
+ throw new Error(`batch: the JSON string decoded to ${typeof parsed}, not an array. ${BATCH_HINT}`);
84
+ }
85
+ throw new Error(`batch: expected an array, got ${typeof raw}. ${BATCH_HINT}`);
86
+ }
87
+ /** Each batch item should be an object; tolerate JSON-stringified objects the
88
+ * same way `normaliseBatchValue` tolerates a stringified `batch`. */
89
+ export function coerceBatchItem(item) {
90
+ if (item && typeof item === 'object' && !Array.isArray(item)) {
91
+ return { ...item };
92
+ }
93
+ if (typeof item === 'string') {
94
+ try {
95
+ const parsed = JSON.parse(item);
96
+ if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
97
+ return { ...parsed };
98
+ }
99
+ }
100
+ catch { /* fall through */ }
101
+ }
102
+ return {};
103
+ }
104
+ /**
105
+ * Run a tool call that may carry the batch envelope. Returns null when `args`
106
+ * has no `batch` (the caller runs its ordinary single call), otherwise the
107
+ * envelope. Throws, with the message the model should read, when the batch is
108
+ * malformed, too large, or aimed at a tool on the denylist.
109
+ *
110
+ * `runOne` executes ONE item through the runtime's own single-call path and
111
+ * reports it as a `BatchItemResult`; a rejection it lets escape is reported
112
+ * as `{ ok: false, error }` with the error's message.
113
+ */
114
+ export async function runBatch(toolName, args, runOne) {
115
+ const items = normaliseBatchValue(args);
116
+ if (items === null)
117
+ return null;
118
+ if (MCP_BATCH_DENYLIST.has(toolName)) {
119
+ throw new Error(`Tool "${toolName}" does not support batch invocation.`);
120
+ }
121
+ if (items.length === 0)
122
+ return { results: [] };
123
+ if (items.length > MCP_BATCH_MAX) {
124
+ throw new Error(`batch: max ${MCP_BATCH_MAX} items per call (got ${items.length}).`);
125
+ }
126
+ let settled;
127
+ if (MCP_BATCH_SEQUENTIAL.has(toolName)) {
128
+ settled = [];
129
+ for (const item of items) {
130
+ const [one] = await Promise.allSettled([runOne(coerceBatchItem(item))]);
131
+ settled.push(one);
132
+ }
133
+ }
134
+ else {
135
+ settled = await Promise.allSettled(items.map(item => runOne(coerceBatchItem(item))));
136
+ }
137
+ return {
138
+ results: settled.map((r) => {
139
+ if (r.status === 'fulfilled')
140
+ return r.value;
141
+ const err = r.reason;
142
+ return { ok: false, error: typeof err?.message === 'string' ? err.message : String(r.reason) };
143
+ }),
144
+ };
145
+ }
146
+ /**
147
+ * Cutting a tool result down to what a stored or relayed tool step keeps.
148
+ *
149
+ * Both runtimes keep at most `TOOL_RESULT_CHARS` of a result on a tool-use
150
+ * frame and in a `tool_use` Entry, so a 1 MB tool body never ends up in a row
151
+ * or on a socket. A plain slice is fine for text, but not for the batch
152
+ * envelope: cut in the middle it is no longer JSON, and whoever reads it back
153
+ * (the call card, which needs each item's `ok`) reads every item as failed.
154
+ * Four calls that all answered drew as "0 answered, 4 failed", with the first
155
+ * answer's raw JSON as the error of every row. So an envelope is shortened
156
+ * ITEM BY ITEM: each keeps its `ok` and `statusCode`, its text gets an even
157
+ * share of the room, and the whole stays valid JSON, marked `clipped` so a
158
+ * reader knows the full text lives elsewhere.
159
+ */
160
+ export const TOOL_RESULT_CHARS = 2000;
161
+ const CUT_MARK = ' [...]';
162
+ function asText(value) {
163
+ if (typeof value === 'string')
164
+ return value;
165
+ if (value === undefined)
166
+ return '';
167
+ return JSON.stringify(value) ?? '';
168
+ }
169
+ function cut(text, room) {
170
+ if (text.length <= room)
171
+ return text;
172
+ return text.slice(0, Math.max(0, room - CUT_MARK.length)) + CUT_MARK;
173
+ }
174
+ function clipEnvelope(items, max) {
175
+ const texts = items.map(i => asText(i.ok === false ? i.error : i.data));
176
+ const build = (room) => JSON.stringify({
177
+ // With no room left an item is only its flag: a hundred of those
178
+ // still fit, and the flag is what a reader cannot do without.
179
+ results: items.map((item, n) => {
180
+ const text = room > 0 ? { [item.ok === false ? 'error' : 'data']: cut(texts[n], room) } : {};
181
+ if (item.ok === false) {
182
+ return typeof item.statusCode === 'number'
183
+ ? { ok: false, ...text, statusCode: item.statusCode }
184
+ : { ok: false, ...text };
185
+ }
186
+ return { ok: true, ...text };
187
+ }),
188
+ clipped: true,
189
+ });
190
+ // Escaping (a newline is two characters in JSON) makes the length of the
191
+ // text and of its JSON differ, so shrink the share until it fits.
192
+ let room = Math.floor(max / Math.max(1, items.length));
193
+ while (room > 0) {
194
+ const out = build(room);
195
+ if (out.length <= max)
196
+ return out;
197
+ room = Math.floor(room * Math.min(0.9, max / out.length));
198
+ }
199
+ const bare = build(0);
200
+ return bare.length <= max ? bare : null;
201
+ }
202
+ /** The result as a stored tool step keeps it: whole when it fits, a batch
203
+ * envelope shortened per item (still JSON), anything else sliced. */
204
+ export function clipToolResult(result, max = TOOL_RESULT_CHARS) {
205
+ if (result.length <= max)
206
+ return result;
207
+ if (result.startsWith('{"results":')) {
208
+ try {
209
+ const parsed = JSON.parse(result);
210
+ if (Array.isArray(parsed.results)) {
211
+ const clipped = clipEnvelope(parsed.results, max);
212
+ if (clipped)
213
+ return clipped;
214
+ }
215
+ }
216
+ catch { /* not an envelope after all: slice it like any other text */ }
217
+ }
218
+ return result.slice(0, max);
219
+ }
@@ -0,0 +1,136 @@
1
+ /**
2
+ * `studio_call_agent`: what both runtimes must agree on.
3
+ *
4
+ * Part of the agent contract (see `version.ts`), copied verbatim into the
5
+ * runner. The studio owns everything that keeps a call from hanging (fail-fast,
6
+ * the one clock, cancelling the target: `server/utils/agent/delegation.ts`);
7
+ * what lives here is the tool's own face, which an internal and an external
8
+ * agent must show identically: how its arguments are read, how many calls one
9
+ * run may place, how long a waited call may take, and the text it answers with.
10
+ * How a call is PLACED differs per runtime (a promise in-process, a
11
+ * `delegate:request` frame from the runner) and stays with each runtime.
12
+ */
13
+ /** The tool's name, for the loops that give its result a budget of its own. */
14
+ export declare const CALL_TOOL = "studio_call_agent";
15
+ /** How long a call may run when neither the agent nor the caller's own turn
16
+ * says otherwise (a caller without a turn clock, such as a task run on a
17
+ * runner). */
18
+ export declare const DEFAULT_CALL_TIMEOUT_MS: number;
19
+ /** Calls one run may have open at once. The bound on a fan-out, and the
20
+ * replacement for the generic queue-loop guard, which counts identical
21
+ * "Call from X" rows and would refuse a team of six to the same colleague.
22
+ * The studio enforces it again in `requestDelegation`. */
23
+ export declare const MAX_OPEN_CALLS_PER_RUN = 8;
24
+ /** A waited call never gets less than this, however little of the turn is
25
+ * left, so a call made late in a turn still gets a real chance. */
26
+ export declare const MIN_CALL_TIMEOUT_MS = 30000;
27
+ /**
28
+ * The tier of a call: `explore` sends a working copy of yourself to search,
29
+ * read and summarise, read-only, on the agent's explore model with a small
30
+ * prompt, and answers with findings of at most `EXPLORE_ANSWER_MAX_CHARS`.
31
+ * Only for a working copy (your own slug).
32
+ */
33
+ export declare const CALL_TIERS: readonly ["explore"];
34
+ export type CallTier = typeof CALL_TIERS[number];
35
+ /** The most an explore copy's answer may hand back (about 2k tokens). */
36
+ export declare const EXPLORE_ANSWER_MAX_CHARS = 8000;
37
+ export interface CallArgs {
38
+ agent: string;
39
+ task: string;
40
+ context?: string;
41
+ tier?: CallTier;
42
+ }
43
+ export interface CallOutcome {
44
+ output?: string;
45
+ error?: string;
46
+ }
47
+ export interface CallPlan {
48
+ calls: CallArgs[];
49
+ /** The caller used `{ batch: [...] }`: answer with the batch envelope. */
50
+ isBatch: boolean;
51
+ /** `background: true`: do not wait, the answer is delivered later. */
52
+ background: boolean;
53
+ }
54
+ export declare function parseCallArgs(raw: unknown): CallArgs | string;
55
+ /** An explore copy's answer, cut to what it may hand back, on a line break
56
+ * when one is near. */
57
+ export declare function clipExploreAnswer(text: string): string;
58
+ /** Read the tool's arguments into the calls to place, or the one-line refusal
59
+ * (already prefixed with `Error: `) the model gets back instead. */
60
+ export declare function planCalls(params: unknown): CallPlan | {
61
+ refusal: string;
62
+ };
63
+ /**
64
+ * How long a call may take from this run: what is left of the caller's turn,
65
+ * capped by the agent's own `delegateTimeoutMs` when it set one. A call never
66
+ * comes back after the turn was cut off, and a caller with an hour-long turn
67
+ * is no longer held to `DEFAULT_CALL_TIMEOUT_MS`: four working copies building
68
+ * a feature were all stopped at ten minutes, with fifty minutes of the turn
69
+ * left. That default only applies to a caller without a turn clock. Never
70
+ * below `MIN_CALL_TIMEOUT_MS`.
71
+ */
72
+ export declare function callTimeoutMs(cap: number | null | undefined, runDeadlineAt: number | null | undefined, now: number): number;
73
+ /**
74
+ * The most a call's tool result keeps in the caller's transcript, for the
75
+ * whole batch. A call's answer is the payload the caller placed it for, and
76
+ * running a copy again to read what was cut costs minutes of its work, so it
77
+ * keeps the cap of a result with no copy even when the runtime spilled it,
78
+ * not the hard `SPILLED_TOOL_RESULT_MAX_CHARS` (five answers of 4k fit).
79
+ * Shared fairly between the answers of a batch (`fitCallResult`), so no copy
80
+ * in the middle drops out.
81
+ */
82
+ export declare const CALL_RESULT_MAX_CHARS = 20000;
83
+ /** The cap on a call's result for an agent: its `toolResultTruncateChars`,
84
+ * never above `CALL_RESULT_MAX_CHARS`. */
85
+ export declare function callResultCap(override?: number | null): number;
86
+ /** The tool result for the placed calls: the answer itself for a single call,
87
+ * the universal batch envelope for a batch (the call card and the stored
88
+ * tool step read it). `isError` when nothing came back. What the model reads
89
+ * of a batch is `readableCallResult`. */
90
+ export declare function renderCallOutcomes(outcomes: CallOutcome[], isBatch: boolean): {
91
+ text: string;
92
+ isError: boolean;
93
+ };
94
+ /**
95
+ * A call's result as the caller's model reads it. A batch envelope becomes a
96
+ * count line and one section per call, its header line then the answer as
97
+ * written (or `Error: ...`); anything else stays as it is. Plain text on
98
+ * purpose: the envelope is one line with escaped breaks, so a cut could not
99
+ * land between answers and the middle answers of a batch fell out.
100
+ */
101
+ export declare function readableCallResult(text: string): string;
102
+ /**
103
+ * Fit a call's result, as `readableCallResult` gives it, into `maxChars`. A
104
+ * batch result is cut per answer: every
105
+ * header stays, and the room is shared fairly (what a short answer leaves goes
106
+ * to the longer ones), each long answer cut to its start and end around the
107
+ * usual note. A single answer is cut like any tool result. `fullOutputAt` is
108
+ * where the runtime kept the whole result, as for `truncateToolResult`. Pure,
109
+ * so both loops cut the same way.
110
+ */
111
+ export declare function fitCallResult(text: string, maxChars?: number, fullOutputAt?: string | null): string;
112
+ /**
113
+ * Where a call came from, as the studio writes it on the call's queue row
114
+ * (`inputJson.caller`). `agentSlug` + `scratchKey` name the caller's scratch
115
+ * dir, which the call may READ (never write): a caller hands its copies work
116
+ * in files there, and a copy that cannot open them fails four times over.
117
+ */
118
+ export interface CallCaller {
119
+ conversationUid: string | null;
120
+ taskUid: string | null;
121
+ agentSlug?: string;
122
+ scratchKey?: string | null;
123
+ }
124
+ /**
125
+ * The id a runtime keys a dispatch's scratch dir on: a task by its task uid,
126
+ * a chat by its conversation, anything else (a call) by its queue row. One
127
+ * rule on both sides, so the studio can tell a call where its caller's
128
+ * scratch is without knowing the machine's paths.
129
+ */
130
+ export declare function dispatchScratchKey(d: {
131
+ kind: 'chat' | 'task';
132
+ taskUid?: string | null;
133
+ conversationUid?: string | null;
134
+ queueUid?: string | null;
135
+ queueId?: number | null;
136
+ }): string | null;
@@ -0,0 +1,214 @@
1
+ /**
2
+ * `studio_call_agent`: what both runtimes must agree on.
3
+ *
4
+ * Part of the agent contract (see `version.ts`), copied verbatim into the
5
+ * runner. The studio owns everything that keeps a call from hanging (fail-fast,
6
+ * the one clock, cancelling the target: `server/utils/agent/delegation.ts`);
7
+ * what lives here is the tool's own face, which an internal and an external
8
+ * agent must show identically: how its arguments are read, how many calls one
9
+ * run may place, how long a waited call may take, and the text it answers with.
10
+ * How a call is PLACED differs per runtime (a promise in-process, a
11
+ * `delegate:request` frame from the runner) and stays with each runtime.
12
+ */
13
+ import { TOOL_RESULT_MAX_CHARS, truncateToolResult } from './loop.js';
14
+ /** The tool's name, for the loops that give its result a budget of its own. */
15
+ export const CALL_TOOL = 'studio_call_agent';
16
+ /** How long a call may run when neither the agent nor the caller's own turn
17
+ * says otherwise (a caller without a turn clock, such as a task run on a
18
+ * runner). */
19
+ export const DEFAULT_CALL_TIMEOUT_MS = 10 * 60 * 1000;
20
+ /** Calls one run may have open at once. The bound on a fan-out, and the
21
+ * replacement for the generic queue-loop guard, which counts identical
22
+ * "Call from X" rows and would refuse a team of six to the same colleague.
23
+ * The studio enforces it again in `requestDelegation`. */
24
+ export const MAX_OPEN_CALLS_PER_RUN = 8;
25
+ /** A waited call never gets less than this, however little of the turn is
26
+ * left, so a call made late in a turn still gets a real chance. */
27
+ export const MIN_CALL_TIMEOUT_MS = 30_000;
28
+ /** Kept free at the end of the caller's turn, so the answer arrives while the
29
+ * turn can still use it. */
30
+ const CALLER_TURN_MARGIN_MS = 5_000;
31
+ /**
32
+ * The tier of a call: `explore` sends a working copy of yourself to search,
33
+ * read and summarise, read-only, on the agent's explore model with a small
34
+ * prompt, and answers with findings of at most `EXPLORE_ANSWER_MAX_CHARS`.
35
+ * Only for a working copy (your own slug).
36
+ */
37
+ export const CALL_TIERS = ['explore'];
38
+ /** The most an explore copy's answer may hand back (about 2k tokens). */
39
+ export const EXPLORE_ANSWER_MAX_CHARS = 8_000;
40
+ export function parseCallArgs(raw) {
41
+ const args = (raw ?? {});
42
+ const agent = typeof args.agent === 'string' ? args.agent.trim() : '';
43
+ const task = typeof args.task === 'string' ? args.task.trim() : '';
44
+ if (!agent || !task)
45
+ return 'studio_call_agent requires both "agent" (target slug) and "task" (instruction) string fields.';
46
+ const context = typeof args.context === 'string' && args.context.trim() ? args.context : undefined;
47
+ if (args.tier == null || args.tier === '')
48
+ return { agent, task, context };
49
+ if (!CALL_TIERS.includes(args.tier))
50
+ return `"tier" is one of: ${CALL_TIERS.join(', ')} (or left out).`;
51
+ return { agent, task, context, tier: args.tier };
52
+ }
53
+ /** An explore copy's answer, cut to what it may hand back, on a line break
54
+ * when one is near. */
55
+ export function clipExploreAnswer(text) {
56
+ if (text.length <= EXPLORE_ANSWER_MAX_CHARS)
57
+ return text;
58
+ const lineBreak = text.lastIndexOf('\n', EXPLORE_ANSWER_MAX_CHARS);
59
+ const end = lineBreak >= EXPLORE_ANSWER_MAX_CHARS * 0.8 ? lineBreak : EXPLORE_ANSWER_MAX_CHARS;
60
+ return `${text.slice(0, end)}\n[... ${text.length - end} more characters of the findings were cut: ask a narrower question]`;
61
+ }
62
+ /** Read the tool's arguments into the calls to place, or the one-line refusal
63
+ * (already prefixed with `Error: `) the model gets back instead. */
64
+ export function planCalls(params) {
65
+ const raw = (params ?? {});
66
+ const isBatch = Array.isArray(raw.batch);
67
+ const items = isBatch ? raw.batch : [params];
68
+ const parsed = items.map(parseCallArgs);
69
+ const invalid = parsed.findIndex(p => typeof p === 'string');
70
+ if (invalid >= 0)
71
+ return { refusal: `Error: ${isBatch ? `batch[${invalid}]: ` : ''}${parsed[invalid]}` };
72
+ if (items.length === 0)
73
+ return { refusal: 'Error: batch is empty.' };
74
+ if (items.length > MAX_OPEN_CALLS_PER_RUN) {
75
+ return { refusal: `Error: at most ${MAX_OPEN_CALLS_PER_RUN} calls can run at once; this batch has ${items.length}. Split the work into fewer, larger pieces.` };
76
+ }
77
+ return { calls: parsed, isBatch, background: raw.background === true };
78
+ }
79
+ /**
80
+ * How long a call may take from this run: what is left of the caller's turn,
81
+ * capped by the agent's own `delegateTimeoutMs` when it set one. A call never
82
+ * comes back after the turn was cut off, and a caller with an hour-long turn
83
+ * is no longer held to `DEFAULT_CALL_TIMEOUT_MS`: four working copies building
84
+ * a feature were all stopped at ten minutes, with fifty minutes of the turn
85
+ * left. That default only applies to a caller without a turn clock. Never
86
+ * below `MIN_CALL_TIMEOUT_MS`.
87
+ */
88
+ export function callTimeoutMs(cap, runDeadlineAt, now) {
89
+ if (runDeadlineAt == null)
90
+ return cap ?? DEFAULT_CALL_TIMEOUT_MS;
91
+ const left = runDeadlineAt - now - CALLER_TURN_MARGIN_MS;
92
+ return Math.max(MIN_CALL_TIMEOUT_MS, cap != null ? Math.min(cap, left) : left);
93
+ }
94
+ /**
95
+ * The most a call's tool result keeps in the caller's transcript, for the
96
+ * whole batch. A call's answer is the payload the caller placed it for, and
97
+ * running a copy again to read what was cut costs minutes of its work, so it
98
+ * keeps the cap of a result with no copy even when the runtime spilled it,
99
+ * not the hard `SPILLED_TOOL_RESULT_MAX_CHARS` (five answers of 4k fit).
100
+ * Shared fairly between the answers of a batch (`fitCallResult`), so no copy
101
+ * in the middle drops out.
102
+ */
103
+ export const CALL_RESULT_MAX_CHARS = TOOL_RESULT_MAX_CHARS;
104
+ /** Room kept free per cut answer for the note that says what was cut. */
105
+ const CALL_CUT_NOTE_CHARS = 400;
106
+ /** The cap on a call's result for an agent: its `toolResultTruncateChars`,
107
+ * never above `CALL_RESULT_MAX_CHARS`. */
108
+ export function callResultCap(override) {
109
+ return override && override > 0 ? Math.min(override, CALL_RESULT_MAX_CHARS) : CALL_RESULT_MAX_CHARS;
110
+ }
111
+ /** The header line of one answer in a batch result. `fitCallResult` finds the
112
+ * answers by it. */
113
+ const CALL_SECTION_HEADER = /^===== results\[\d+\] .*=====$/gm;
114
+ /** The tool result for the placed calls: the answer itself for a single call,
115
+ * the universal batch envelope for a batch (the call card and the stored
116
+ * tool step read it). `isError` when nothing came back. What the model reads
117
+ * of a batch is `readableCallResult`. */
118
+ export function renderCallOutcomes(outcomes, isBatch) {
119
+ if (!isBatch) {
120
+ const only = outcomes[0] ?? { error: 'No call was placed.' };
121
+ if (only.error)
122
+ return { text: `Error: ${only.error}`, isError: true };
123
+ return { text: only.output || 'Agent returned no output.', isError: false };
124
+ }
125
+ return {
126
+ text: JSON.stringify({
127
+ results: outcomes.map(r => r.error ? { ok: false, error: r.error } : { ok: true, data: r.output ?? '' }),
128
+ }),
129
+ isError: outcomes.every(r => r.error),
130
+ };
131
+ }
132
+ /**
133
+ * A call's result as the caller's model reads it. A batch envelope becomes a
134
+ * count line and one section per call, its header line then the answer as
135
+ * written (or `Error: ...`); anything else stays as it is. Plain text on
136
+ * purpose: the envelope is one line with escaped breaks, so a cut could not
137
+ * land between answers and the middle answers of a batch fell out.
138
+ */
139
+ export function readableCallResult(text) {
140
+ if (!text.startsWith('{"results":'))
141
+ return text;
142
+ let items;
143
+ try {
144
+ items = JSON.parse(text).results;
145
+ }
146
+ catch {
147
+ return text;
148
+ }
149
+ if (!Array.isArray(items))
150
+ return text;
151
+ const outcomes = items.map((raw) => {
152
+ const item = (raw ?? {});
153
+ return item.ok === true
154
+ ? { output: typeof item.data === 'string' ? item.data : JSON.stringify(item.data ?? '') }
155
+ : { error: typeof item.error === 'string' ? item.error : 'The call failed.' };
156
+ });
157
+ const failed = outcomes.filter(r => r.error != null).length;
158
+ const sections = outcomes.map((r, i) => r.error != null
159
+ ? `===== results[${i}] failed =====\nError: ${r.error}`
160
+ : `===== results[${i}] ok =====\n${r.output || 'Agent returned no output.'}`);
161
+ return [`${outcomes.length} calls, in the order of your batch: ${outcomes.length - failed} answered, ${failed} failed.`, ...sections].join('\n\n');
162
+ }
163
+ /**
164
+ * Fit a call's result, as `readableCallResult` gives it, into `maxChars`. A
165
+ * batch result is cut per answer: every
166
+ * header stays, and the room is shared fairly (what a short answer leaves goes
167
+ * to the longer ones), each long answer cut to its start and end around the
168
+ * usual note. A single answer is cut like any tool result. `fullOutputAt` is
169
+ * where the runtime kept the whole result, as for `truncateToolResult`. Pure,
170
+ * so both loops cut the same way.
171
+ */
172
+ export function fitCallResult(text, maxChars = CALL_RESULT_MAX_CHARS, fullOutputAt) {
173
+ if (text.length <= maxChars)
174
+ return text;
175
+ const starts = [...text.matchAll(CALL_SECTION_HEADER)].map(m => m.index);
176
+ if (starts.length === 0)
177
+ return truncateToolResult(text, maxChars, fullOutputAt);
178
+ const preface = text.slice(0, starts[0]);
179
+ const sections = starts.map((start, i) => {
180
+ const section = text.slice(start, starts[i + 1] ?? text.length);
181
+ const lineEnd = section.indexOf('\n');
182
+ return lineEnd < 0
183
+ ? { header: section, body: '' }
184
+ : { header: section.slice(0, lineEnd + 1), body: section.slice(lineEnd + 1) };
185
+ });
186
+ let budget = maxChars - preface.length - sections.reduce((n, s) => n + s.header.length, 0);
187
+ const keep = new Array(sections.length).fill(0);
188
+ const order = sections.map((_, i) => i).sort((a, b) => sections[a].body.length - sections[b].body.length);
189
+ order.forEach((i, rank) => {
190
+ const share = Math.max(0, Math.floor(budget / (order.length - rank)));
191
+ const length = sections[i].body.length;
192
+ keep[i] = length <= share ? length : Math.max(0, share - CALL_CUT_NOTE_CHARS);
193
+ budget -= length <= share ? length : share;
194
+ });
195
+ const fitted = sections.map((s, i) => {
196
+ if (s.body.length <= keep[i])
197
+ return s.header + s.body;
198
+ // Keep the blank line that separates this answer from the next one.
199
+ const trailing = s.body.endsWith('\n\n') ? '\n\n' : '';
200
+ return `${s.header}${truncateToolResult(s.body.slice(0, s.body.length - trailing.length), keep[i], fullOutputAt)}${trailing}`;
201
+ });
202
+ return preface + fitted.join('');
203
+ }
204
+ /**
205
+ * The id a runtime keys a dispatch's scratch dir on: a task by its task uid,
206
+ * a chat by its conversation, anything else (a call) by its queue row. One
207
+ * rule on both sides, so the studio can tell a call where its caller's
208
+ * scratch is without knowing the machine's paths.
209
+ */
210
+ export function dispatchScratchKey(d) {
211
+ if (d.kind === 'chat')
212
+ return d.conversationUid ?? null;
213
+ return d.taskUid ?? d.queueUid ?? (d.queueId != null ? String(d.queueId) : null);
214
+ }