@vascend/talos 0.1.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 (620) hide show
  1. package/README.md +202 -0
  2. package/dist/backend/asset-events.d.ts +31 -0
  3. package/dist/backend/asset-events.js +149 -0
  4. package/dist/backend/assets.d.ts +31 -0
  5. package/dist/backend/assets.js +210 -0
  6. package/dist/backend/auth.d.ts +18 -0
  7. package/dist/backend/auth.js +59 -0
  8. package/dist/backend/config.d.ts +14 -0
  9. package/dist/backend/config.js +41 -0
  10. package/dist/backend/conversations.d.ts +21 -0
  11. package/dist/backend/conversations.js +141 -0
  12. package/dist/backend/crypto.d.ts +9 -0
  13. package/dist/backend/crypto.js +68 -0
  14. package/dist/backend/engine.d.ts +13 -0
  15. package/dist/backend/engine.js +78 -0
  16. package/dist/backend/http.d.ts +25 -0
  17. package/dist/backend/http.js +112 -0
  18. package/dist/backend/index.d.ts +1 -0
  19. package/dist/backend/index.js +24 -0
  20. package/dist/backend/routes.d.ts +14 -0
  21. package/dist/backend/routes.js +169 -0
  22. package/dist/backend/sdk.d.ts +12 -0
  23. package/dist/backend/sdk.js +11 -0
  24. package/dist/backend/server.d.ts +12 -0
  25. package/dist/backend/server.js +91 -0
  26. package/dist/backend/temp-image-store.d.ts +46 -0
  27. package/dist/backend/temp-image-store.js +197 -0
  28. package/dist/backend/types.d.ts +103 -0
  29. package/dist/backend/types.js +29 -0
  30. package/dist/backend/users.d.ts +13 -0
  31. package/dist/backend/users.js +76 -0
  32. package/dist/backend/ws-handler.d.ts +14 -0
  33. package/dist/backend/ws-handler.js +72 -0
  34. package/dist/backend/ws.d.ts +19 -0
  35. package/dist/backend/ws.js +146 -0
  36. package/dist/core/agent.d.ts +56 -0
  37. package/dist/core/agent.js +1783 -0
  38. package/dist/core/background.d.ts +45 -0
  39. package/dist/core/background.js +140 -0
  40. package/dist/core/bootstrap.d.ts +45 -0
  41. package/dist/core/bootstrap.js +294 -0
  42. package/dist/core/cli-args.d.ts +41 -0
  43. package/dist/core/cli-args.js +282 -0
  44. package/dist/core/collapsible-output.d.ts +38 -0
  45. package/dist/core/collapsible-output.js +143 -0
  46. package/dist/core/compaction-checkpoint.d.ts +9 -0
  47. package/dist/core/compaction-checkpoint.js +58 -0
  48. package/dist/core/compaction.d.ts +42 -0
  49. package/dist/core/compaction.js +270 -0
  50. package/dist/core/config.d.ts +49 -0
  51. package/dist/core/config.js +417 -0
  52. package/dist/core/context-ledger.d.ts +99 -0
  53. package/dist/core/context-ledger.js +222 -0
  54. package/dist/core/context-policy.d.ts +17 -0
  55. package/dist/core/context-policy.js +81 -0
  56. package/dist/core/continuation-review.d.ts +23 -0
  57. package/dist/core/continuation-review.js +64 -0
  58. package/dist/core/crash-report.d.ts +3 -0
  59. package/dist/core/crash-report.js +27 -0
  60. package/dist/core/credentials.d.ts +11 -0
  61. package/dist/core/credentials.js +183 -0
  62. package/dist/core/doctor.d.ts +24 -0
  63. package/dist/core/doctor.js +125 -0
  64. package/dist/core/effort.d.ts +5 -0
  65. package/dist/core/effort.js +42 -0
  66. package/dist/core/env-paths.d.ts +3 -0
  67. package/dist/core/env-paths.js +38 -0
  68. package/dist/core/execution-guidance.d.ts +9 -0
  69. package/dist/core/execution-guidance.js +73 -0
  70. package/dist/core/execution-target.d.ts +41 -0
  71. package/dist/core/execution-target.js +69 -0
  72. package/dist/core/file-coordination.d.ts +66 -0
  73. package/dist/core/file-coordination.js +176 -0
  74. package/dist/core/file-lease-store.d.ts +14 -0
  75. package/dist/core/file-lease-store.js +89 -0
  76. package/dist/core/image-limits.d.ts +26 -0
  77. package/dist/core/image-limits.js +205 -0
  78. package/dist/core/interruptible-completion.d.ts +3 -0
  79. package/dist/core/interruptible-completion.js +42 -0
  80. package/dist/core/kingdoms-mode-state.d.ts +24 -0
  81. package/dist/core/kingdoms-mode-state.js +139 -0
  82. package/dist/core/licenza.d.ts +38 -0
  83. package/dist/core/licenza.js +125 -0
  84. package/dist/core/model-limits.d.ts +2 -0
  85. package/dist/core/model-limits.js +36 -0
  86. package/dist/core/output-lifecycle.d.ts +44 -0
  87. package/dist/core/output-lifecycle.js +190 -0
  88. package/dist/core/package-update.d.ts +15 -0
  89. package/dist/core/package-update.js +121 -0
  90. package/dist/core/permission-queue.d.ts +2 -0
  91. package/dist/core/permission-queue.js +20 -0
  92. package/dist/core/prompt-attachment.d.ts +21 -0
  93. package/dist/core/prompt-attachment.js +123 -0
  94. package/dist/core/request-plan.d.ts +16 -0
  95. package/dist/core/request-plan.js +36 -0
  96. package/dist/core/run-timing.d.ts +17 -0
  97. package/dist/core/run-timing.js +123 -0
  98. package/dist/core/self-update.d.ts +17 -0
  99. package/dist/core/self-update.js +54 -0
  100. package/dist/core/session-refs.d.ts +27 -0
  101. package/dist/core/session-refs.js +126 -0
  102. package/dist/core/session-storage.d.ts +4 -0
  103. package/dist/core/session-storage.js +48 -0
  104. package/dist/core/session-title.d.ts +1 -0
  105. package/dist/core/session-title.js +21 -0
  106. package/dist/core/session-usage.d.ts +17 -0
  107. package/dist/core/session-usage.js +74 -0
  108. package/dist/core/session.d.ts +58 -0
  109. package/dist/core/session.js +296 -0
  110. package/dist/core/settings.d.ts +17 -0
  111. package/dist/core/settings.js +107 -0
  112. package/dist/core/storage-retention.d.ts +21 -0
  113. package/dist/core/storage-retention.js +227 -0
  114. package/dist/core/text-sanitize.d.ts +1 -0
  115. package/dist/core/text-sanitize.js +35 -0
  116. package/dist/core/tool-artifacts.d.ts +6 -0
  117. package/dist/core/tool-artifacts.js +51 -0
  118. package/dist/core/tool-compress.d.ts +8 -0
  119. package/dist/core/tool-compress.js +111 -0
  120. package/dist/core/tool-executor.d.ts +16 -0
  121. package/dist/core/tool-executor.js +97 -0
  122. package/dist/core/tool-result-index.d.ts +52 -0
  123. package/dist/core/tool-result-index.js +327 -0
  124. package/dist/core/tool-result-store.d.ts +38 -0
  125. package/dist/core/tool-result-store.js +190 -0
  126. package/dist/core/tool-scheduler.d.ts +16 -0
  127. package/dist/core/tool-scheduler.js +35 -0
  128. package/dist/core/trust.d.ts +21 -0
  129. package/dist/core/trust.js +95 -0
  130. package/dist/core/types.d.ts +402 -0
  131. package/dist/core/types.js +1 -0
  132. package/dist/core/update-check.d.ts +26 -0
  133. package/dist/core/update-check.js +89 -0
  134. package/dist/core/update-process.d.ts +10 -0
  135. package/dist/core/update-process.js +31 -0
  136. package/dist/core/user-inbox.d.ts +23 -0
  137. package/dist/core/user-inbox.js +56 -0
  138. package/dist/core/user-input.d.ts +10 -0
  139. package/dist/core/user-input.js +35 -0
  140. package/dist/core/version.d.ts +1 -0
  141. package/dist/core/version.js +10 -0
  142. package/dist/core/vibe-modes.d.ts +38 -0
  143. package/dist/core/vibe-modes.js +383 -0
  144. package/dist/core/workspace-roots.d.ts +13 -0
  145. package/dist/core/workspace-roots.js +91 -0
  146. package/dist/core/workspace-sessions.d.ts +51 -0
  147. package/dist/core/workspace-sessions.js +243 -0
  148. package/dist/cowork/client.d.ts +29 -0
  149. package/dist/cowork/client.js +49 -0
  150. package/dist/cowork/engine-bridge.d.ts +22 -0
  151. package/dist/cowork/engine-bridge.js +98 -0
  152. package/dist/cowork/index.d.ts +11 -0
  153. package/dist/cowork/index.js +16 -0
  154. package/dist/cowork/ipc.d.ts +97 -0
  155. package/dist/cowork/ipc.js +96 -0
  156. package/dist/cowork/manager.d.ts +66 -0
  157. package/dist/cowork/manager.js +325 -0
  158. package/dist/cowork/store.d.ts +23 -0
  159. package/dist/cowork/store.js +182 -0
  160. package/dist/cowork/sync.d.ts +20 -0
  161. package/dist/cowork/sync.js +164 -0
  162. package/dist/cowork/types.d.ts +78 -0
  163. package/dist/cowork/types.js +21 -0
  164. package/dist/extensions/ext-tools.d.ts +3 -0
  165. package/dist/extensions/ext-tools.js +73 -0
  166. package/dist/extensions/loader.d.ts +91 -0
  167. package/dist/extensions/loader.js +474 -0
  168. package/dist/extensions/settings.d.ts +20 -0
  169. package/dist/extensions/settings.js +86 -0
  170. package/dist/extensions/types.d.ts +219 -0
  171. package/dist/extensions/types.js +1 -0
  172. package/dist/horizon/async-queue.d.ts +9 -0
  173. package/dist/horizon/async-queue.js +46 -0
  174. package/dist/horizon/engine.d.ts +85 -0
  175. package/dist/horizon/engine.js +603 -0
  176. package/dist/horizon/index.d.ts +4 -0
  177. package/dist/horizon/index.js +2 -0
  178. package/dist/horizon/main-team.d.ts +163 -0
  179. package/dist/horizon/main-team.js +774 -0
  180. package/dist/horizon/types.d.ts +233 -0
  181. package/dist/horizon/types.js +1 -0
  182. package/dist/index.d.ts +2 -0
  183. package/dist/index.js +233 -0
  184. package/dist/mcp/protocol.d.ts +81 -0
  185. package/dist/mcp/protocol.js +122 -0
  186. package/dist/package.json +1 -0
  187. package/dist/packages/packages.d.ts +12 -0
  188. package/dist/packages/packages.js +323 -0
  189. package/dist/prompts/templates.d.ts +13 -0
  190. package/dist/prompts/templates.js +139 -0
  191. package/dist/providers/anthropic-oauth.d.ts +13 -0
  192. package/dist/providers/anthropic-oauth.js +124 -0
  193. package/dist/providers/anthropic.d.ts +27 -0
  194. package/dist/providers/anthropic.js +526 -0
  195. package/dist/providers/catalog.d.ts +15 -0
  196. package/dist/providers/catalog.js +166 -0
  197. package/dist/providers/effort.d.ts +12 -0
  198. package/dist/providers/effort.js +102 -0
  199. package/dist/providers/model-catalog.d.ts +43 -0
  200. package/dist/providers/model-catalog.js +70 -0
  201. package/dist/providers/model-effort.d.ts +5 -0
  202. package/dist/providers/model-effort.js +43 -0
  203. package/dist/providers/model-registry.d.ts +39 -0
  204. package/dist/providers/model-registry.js +142 -0
  205. package/dist/providers/models-dev.d.ts +9 -0
  206. package/dist/providers/models-dev.js +97 -0
  207. package/dist/providers/oauth-callback-server.d.ts +28 -0
  208. package/dist/providers/oauth-callback-server.js +184 -0
  209. package/dist/providers/oauth-orchestrator.d.ts +58 -0
  210. package/dist/providers/oauth-orchestrator.js +159 -0
  211. package/dist/providers/oauth-store.d.ts +12 -0
  212. package/dist/providers/oauth-store.js +139 -0
  213. package/dist/providers/open-browser.d.ts +20 -0
  214. package/dist/providers/open-browser.js +92 -0
  215. package/dist/providers/openai-compat.d.ts +14 -0
  216. package/dist/providers/openai-compat.js +523 -0
  217. package/dist/providers/openai-oauth.d.ts +15 -0
  218. package/dist/providers/openai-oauth.js +382 -0
  219. package/dist/providers/openrouter-auth.d.ts +73 -0
  220. package/dist/providers/openrouter-auth.js +321 -0
  221. package/dist/providers/openrouter-manual-fallback.d.ts +25 -0
  222. package/dist/providers/openrouter-manual-fallback.js +161 -0
  223. package/dist/providers/openrouter.d.ts +15 -0
  224. package/dist/providers/openrouter.js +107 -0
  225. package/dist/providers/plan-limits.d.ts +6 -0
  226. package/dist/providers/plan-limits.js +175 -0
  227. package/dist/providers/provider-reset.d.ts +4 -0
  228. package/dist/providers/provider-reset.js +83 -0
  229. package/dist/providers/quota-limits.d.ts +4 -0
  230. package/dist/providers/quota-limits.js +33 -0
  231. package/dist/providers/registry.d.ts +33 -0
  232. package/dist/providers/registry.js +213 -0
  233. package/dist/providers/retry.d.ts +37 -0
  234. package/dist/providers/retry.js +347 -0
  235. package/dist/rpc/server.d.ts +23 -0
  236. package/dist/rpc/server.js +222 -0
  237. package/dist/sdk.d.ts +67 -0
  238. package/dist/sdk.js +64 -0
  239. package/dist/skills/skills.d.ts +17 -0
  240. package/dist/skills/skills.js +155 -0
  241. package/dist/text-sanitize.js +28 -0
  242. package/dist/tools/ask-user.d.ts +2 -0
  243. package/dist/tools/ask-user.js +60 -0
  244. package/dist/tools/builtin.d.ts +48 -0
  245. package/dist/tools/builtin.js +2494 -0
  246. package/dist/tools/capabilities.d.ts +5 -0
  247. package/dist/tools/capabilities.js +55 -0
  248. package/dist/tools/computer-capture.d.ts +2 -0
  249. package/dist/tools/computer-capture.js +91 -0
  250. package/dist/tools/computer-posix.d.ts +5 -0
  251. package/dist/tools/computer-posix.js +136 -0
  252. package/dist/tools/computer-use.d.ts +14 -0
  253. package/dist/tools/computer-use.js +108 -0
  254. package/dist/tools/discovery.d.ts +12 -0
  255. package/dist/tools/discovery.js +205 -0
  256. package/dist/tools/execute.d.ts +2 -0
  257. package/dist/tools/execute.js +73 -0
  258. package/dist/tools/normalize-input.d.ts +17 -0
  259. package/dist/tools/normalize-input.js +174 -0
  260. package/dist/tools/output-artifact.d.ts +3 -0
  261. package/dist/tools/output-artifact.js +80 -0
  262. package/dist/tools/pagination.d.ts +15 -0
  263. package/dist/tools/pagination.js +93 -0
  264. package/dist/tools/plan-status.d.ts +2 -0
  265. package/dist/tools/plan-status.js +109 -0
  266. package/dist/tools/program-input.d.ts +3 -0
  267. package/dist/tools/program-input.js +19 -0
  268. package/dist/tools/program.d.ts +3 -0
  269. package/dist/tools/program.js +567 -0
  270. package/dist/tools/protocol-catalog.d.ts +12 -0
  271. package/dist/tools/protocol-catalog.js +46 -0
  272. package/dist/tools/ramification-tools.d.ts +12 -0
  273. package/dist/tools/ramification-tools.js +528 -0
  274. package/dist/tools/regex-compat.d.ts +9 -0
  275. package/dist/tools/regex-compat.js +96 -0
  276. package/dist/tools/registry.d.ts +51 -0
  277. package/dist/tools/registry.js +185 -0
  278. package/dist/tools/resolve.d.ts +2 -0
  279. package/dist/tools/resolve.js +107 -0
  280. package/dist/tools/shell-env.d.ts +2 -0
  281. package/dist/tools/shell-env.js +7 -0
  282. package/dist/tools/team-input.d.ts +3 -0
  283. package/dist/tools/team-input.js +129 -0
  284. package/dist/tools/team-tools.d.ts +7 -0
  285. package/dist/tools/team-tools.js +348 -0
  286. package/dist/tools/workspace-sessions.d.ts +2 -0
  287. package/dist/tools/workspace-sessions.js +35 -0
  288. package/dist/tui/account-entry.d.ts +1 -0
  289. package/dist/tui/account-entry.js +93 -0
  290. package/dist/tui/attachment-highlight.d.ts +1 -0
  291. package/dist/tui/attachment-highlight.js +24 -0
  292. package/dist/tui/attachment-refs.d.ts +2 -0
  293. package/dist/tui/attachment-refs.js +3 -0
  294. package/dist/tui/bottom-input.d.ts +219 -0
  295. package/dist/tui/bottom-input.js +1958 -0
  296. package/dist/tui/branding.d.ts +107 -0
  297. package/dist/tui/branding.js +750 -0
  298. package/dist/tui/clipboard-image.d.ts +10 -0
  299. package/dist/tui/clipboard-image.js +163 -0
  300. package/dist/tui/clipboard-text.d.ts +9 -0
  301. package/dist/tui/clipboard-text.js +51 -0
  302. package/dist/tui/clipboard-windows.d.ts +8 -0
  303. package/dist/tui/clipboard-windows.js +84 -0
  304. package/dist/tui/collapsible-command.d.ts +15 -0
  305. package/dist/tui/collapsible-command.js +48 -0
  306. package/dist/tui/command-feedback.d.ts +10 -0
  307. package/dist/tui/command-feedback.js +46 -0
  308. package/dist/tui/command-output-registry.d.ts +28 -0
  309. package/dist/tui/command-output-registry.js +103 -0
  310. package/dist/tui/command-transcript.d.ts +12 -0
  311. package/dist/tui/command-transcript.js +90 -0
  312. package/dist/tui/commands.d.ts +20 -0
  313. package/dist/tui/commands.js +131 -0
  314. package/dist/tui/context-bar.d.ts +4 -0
  315. package/dist/tui/context-bar.js +74 -0
  316. package/dist/tui/context-meter.d.ts +25 -0
  317. package/dist/tui/context-meter.js +81 -0
  318. package/dist/tui/cost-binding.d.ts +8 -0
  319. package/dist/tui/cost-binding.js +43 -0
  320. package/dist/tui/cost-tracker.d.ts +49 -0
  321. package/dist/tui/cost-tracker.js +122 -0
  322. package/dist/tui/diff.d.ts +9 -0
  323. package/dist/tui/diff.js +119 -0
  324. package/dist/tui/i18n-catalog.d.ts +5 -0
  325. package/dist/tui/i18n-catalog.js +184 -0
  326. package/dist/tui/i18n.d.ts +6 -0
  327. package/dist/tui/i18n.js +10 -0
  328. package/dist/tui/image-attachments.d.ts +46 -0
  329. package/dist/tui/image-attachments.js +167 -0
  330. package/dist/tui/images.d.ts +12 -0
  331. package/dist/tui/images.js +87 -0
  332. package/dist/tui/intro.d.ts +13 -0
  333. package/dist/tui/intro.js +109 -0
  334. package/dist/tui/language-preference.d.ts +6 -0
  335. package/dist/tui/language-preference.js +24 -0
  336. package/dist/tui/live-output.d.ts +2 -0
  337. package/dist/tui/live-output.js +18 -0
  338. package/dist/tui/locales.d.ts +19 -0
  339. package/dist/tui/locales.js +22 -0
  340. package/dist/tui/login-menu.d.ts +17 -0
  341. package/dist/tui/login-menu.js +58 -0
  342. package/dist/tui/logo.d.ts +8 -0
  343. package/dist/tui/logo.js +305 -0
  344. package/dist/tui/markdown-inline.d.ts +3 -0
  345. package/dist/tui/markdown-inline.js +99 -0
  346. package/dist/tui/markdown-table.d.ts +4 -0
  347. package/dist/tui/markdown-table.js +63 -0
  348. package/dist/tui/markdown.d.ts +11 -0
  349. package/dist/tui/markdown.js +257 -0
  350. package/dist/tui/mcp-transcript.d.ts +7 -0
  351. package/dist/tui/mcp-transcript.js +40 -0
  352. package/dist/tui/model-details.d.ts +2 -0
  353. package/dist/tui/model-details.js +21 -0
  354. package/dist/tui/model-selection.d.ts +7 -0
  355. package/dist/tui/model-selection.js +41 -0
  356. package/dist/tui/native-scrollback.d.ts +27 -0
  357. package/dist/tui/native-scrollback.js +134 -0
  358. package/dist/tui/onboarding.d.ts +72 -0
  359. package/dist/tui/onboarding.js +207 -0
  360. package/dist/tui/paste-collapse.d.ts +39 -0
  361. package/dist/tui/paste-collapse.js +117 -0
  362. package/dist/tui/perm-mode.d.ts +8 -0
  363. package/dist/tui/perm-mode.js +41 -0
  364. package/dist/tui/prompt-queue-store.d.ts +26 -0
  365. package/dist/tui/prompt-queue-store.js +87 -0
  366. package/dist/tui/prompt-queue.d.ts +47 -0
  367. package/dist/tui/prompt-queue.js +187 -0
  368. package/dist/tui/provider-menu.d.ts +33 -0
  369. package/dist/tui/provider-menu.js +175 -0
  370. package/dist/tui/question.d.ts +24 -0
  371. package/dist/tui/question.js +32 -0
  372. package/dist/tui/queue-screen.d.ts +25 -0
  373. package/dist/tui/queue-screen.js +152 -0
  374. package/dist/tui/queue-team.d.ts +3 -0
  375. package/dist/tui/queue-team.js +28 -0
  376. package/dist/tui/queued-questions.d.ts +20 -0
  377. package/dist/tui/queued-questions.js +163 -0
  378. package/dist/tui/quick-help.d.ts +1 -0
  379. package/dist/tui/quick-help.js +53 -0
  380. package/dist/tui/repl.d.ts +78 -0
  381. package/dist/tui/repl.js +4130 -0
  382. package/dist/tui/restore-queued-input.d.ts +3 -0
  383. package/dist/tui/restore-queued-input.js +20 -0
  384. package/dist/tui/review-detail.d.ts +6 -0
  385. package/dist/tui/review-detail.js +56 -0
  386. package/dist/tui/review-files.d.ts +3 -0
  387. package/dist/tui/review-files.js +22 -0
  388. package/dist/tui/review-render.d.ts +22 -0
  389. package/dist/tui/review-render.js +98 -0
  390. package/dist/tui/review-screen.d.ts +38 -0
  391. package/dist/tui/review-screen.js +358 -0
  392. package/dist/tui/review-store.d.ts +60 -0
  393. package/dist/tui/review-store.js +270 -0
  394. package/dist/tui/review-team.d.ts +2 -0
  395. package/dist/tui/review-team.js +27 -0
  396. package/dist/tui/selector-mouse.d.ts +26 -0
  397. package/dist/tui/selector-mouse.js +65 -0
  398. package/dist/tui/selector.d.ts +51 -0
  399. package/dist/tui/selector.js +299 -0
  400. package/dist/tui/session-replay.d.ts +10 -0
  401. package/dist/tui/session-replay.js +78 -0
  402. package/dist/tui/session-usage.d.ts +22 -0
  403. package/dist/tui/session-usage.js +55 -0
  404. package/dist/tui/skill-transcript.d.ts +5 -0
  405. package/dist/tui/skill-transcript.js +31 -0
  406. package/dist/tui/startup.d.ts +5 -0
  407. package/dist/tui/startup.js +61 -0
  408. package/dist/tui/status-line-loader.d.ts +8 -0
  409. package/dist/tui/status-line-loader.js +33 -0
  410. package/dist/tui/status-line.d.ts +38 -0
  411. package/dist/tui/status-line.js +213 -0
  412. package/dist/tui/system-language.d.ts +8 -0
  413. package/dist/tui/system-language.js +41 -0
  414. package/dist/tui/task-labels.d.ts +2 -0
  415. package/dist/tui/task-labels.js +7 -0
  416. package/dist/tui/term-bg.d.ts +4 -0
  417. package/dist/tui/term-bg.js +67 -0
  418. package/dist/tui/terminal-screen.d.ts +12 -0
  419. package/dist/tui/terminal-screen.js +1 -0
  420. package/dist/tui/terminal-text.d.ts +7 -0
  421. package/dist/tui/terminal-text.js +123 -0
  422. package/dist/tui/theme.d.ts +25 -0
  423. package/dist/tui/theme.js +383 -0
  424. package/dist/tui/tool-style.d.ts +7 -0
  425. package/dist/tui/tool-style.js +119 -0
  426. package/dist/tui/update-prompt.d.ts +14 -0
  427. package/dist/tui/update-prompt.js +104 -0
  428. package/dist/tui/usage-footer.d.ts +9 -0
  429. package/dist/tui/usage-footer.js +123 -0
  430. package/dist/tui/vascend-login.d.ts +68 -0
  431. package/dist/tui/vascend-login.js +355 -0
  432. package/dist/tui/web-login.d.ts +28 -0
  433. package/dist/tui/web-login.js +115 -0
  434. package/dist/vascend/activity-status.d.ts +12 -0
  435. package/dist/vascend/activity-status.js +68 -0
  436. package/dist/vascend/architecture-map.d.ts +73 -0
  437. package/dist/vascend/architecture-map.js +424 -0
  438. package/dist/vascend/attention-layout.d.ts +19 -0
  439. package/dist/vascend/attention-layout.js +141 -0
  440. package/dist/vascend/budget-allocator.d.ts +31 -0
  441. package/dist/vascend/budget-allocator.js +79 -0
  442. package/dist/vascend/candidate-collector.d.ts +20 -0
  443. package/dist/vascend/candidate-collector.js +220 -0
  444. package/dist/vascend/code-events.d.ts +24 -0
  445. package/dist/vascend/code-events.js +304 -0
  446. package/dist/vascend/code-graph-memory.d.ts +38 -0
  447. package/dist/vascend/code-graph-memory.js +334 -0
  448. package/dist/vascend/code-graph-runtime.d.ts +19 -0
  449. package/dist/vascend/code-graph-runtime.js +190 -0
  450. package/dist/vascend/code-graph-types.d.ts +58 -0
  451. package/dist/vascend/code-graph-types.js +50 -0
  452. package/dist/vascend/code-parser.d.ts +4 -0
  453. package/dist/vascend/code-parser.js +257 -0
  454. package/dist/vascend/competitor-knowledge.d.ts +53 -0
  455. package/dist/vascend/competitor-knowledge.js +262 -0
  456. package/dist/vascend/completeness.d.ts +16 -0
  457. package/dist/vascend/completeness.js +90 -0
  458. package/dist/vascend/context-autotuner.d.ts +45 -0
  459. package/dist/vascend/context-autotuner.js +231 -0
  460. package/dist/vascend/context-candidate.d.ts +45 -0
  461. package/dist/vascend/context-candidate.js +150 -0
  462. package/dist/vascend/context-capsule.d.ts +51 -0
  463. package/dist/vascend/context-capsule.js +133 -0
  464. package/dist/vascend/context-fabric.d.ts +108 -0
  465. package/dist/vascend/context-fabric.js +480 -0
  466. package/dist/vascend/context-feedback-loop.d.ts +56 -0
  467. package/dist/vascend/context-feedback-loop.js +204 -0
  468. package/dist/vascend/context-learning-identity.d.ts +4 -0
  469. package/dist/vascend/context-learning-identity.js +8 -0
  470. package/dist/vascend/context-links.d.ts +14 -0
  471. package/dist/vascend/context-links.js +83 -0
  472. package/dist/vascend/context-lint.d.ts +22 -0
  473. package/dist/vascend/context-lint.js +91 -0
  474. package/dist/vascend/context-market-selection.d.ts +17 -0
  475. package/dist/vascend/context-market-selection.js +50 -0
  476. package/dist/vascend/context-metrics.d.ts +25 -0
  477. package/dist/vascend/context-metrics.js +57 -0
  478. package/dist/vascend/context-pack-render.d.ts +16 -0
  479. package/dist/vascend/context-pack-render.js +52 -0
  480. package/dist/vascend/context-pareto.d.ts +33 -0
  481. package/dist/vascend/context-pareto.js +165 -0
  482. package/dist/vascend/context-pattern-explorer.d.ts +41 -0
  483. package/dist/vascend/context-pattern-explorer.js +276 -0
  484. package/dist/vascend/context-regret.d.ts +32 -0
  485. package/dist/vascend/context-regret.js +93 -0
  486. package/dist/vascend/context-retriever.d.ts +22 -0
  487. package/dist/vascend/context-retriever.js +243 -0
  488. package/dist/vascend/context-scope-index.d.ts +5 -0
  489. package/dist/vascend/context-scope-index.js +96 -0
  490. package/dist/vascend/context-scorer.d.ts +35 -0
  491. package/dist/vascend/context-scorer.js +162 -0
  492. package/dist/vascend/context-search-index.d.ts +12 -0
  493. package/dist/vascend/context-search-index.js +25 -0
  494. package/dist/vascend/context-snapshot.d.ts +22 -0
  495. package/dist/vascend/context-snapshot.js +135 -0
  496. package/dist/vascend/context-window-compiler.d.ts +42 -0
  497. package/dist/vascend/context-window-compiler.js +237 -0
  498. package/dist/vascend/contract-memory.d.ts +61 -0
  499. package/dist/vascend/contract-memory.js +435 -0
  500. package/dist/vascend/council.d.ts +58 -0
  501. package/dist/vascend/council.js +337 -0
  502. package/dist/vascend/decision-promotion.d.ts +48 -0
  503. package/dist/vascend/decision-promotion.js +410 -0
  504. package/dist/vascend/delta-context.d.ts +12 -0
  505. package/dist/vascend/delta-context.js +36 -0
  506. package/dist/vascend/dev-context-compiler.d.ts +27 -0
  507. package/dist/vascend/dev-context-compiler.js +133 -0
  508. package/dist/vascend/dev-context-layout.d.ts +30 -0
  509. package/dist/vascend/dev-context-layout.js +262 -0
  510. package/dist/vascend/evidence-slots.d.ts +14 -0
  511. package/dist/vascend/evidence-slots.js +55 -0
  512. package/dist/vascend/expansion-levels.d.ts +15 -0
  513. package/dist/vascend/expansion-levels.js +178 -0
  514. package/dist/vascend/file-lock.d.ts +7 -0
  515. package/dist/vascend/file-lock.js +95 -0
  516. package/dist/vascend/granular-kingdom.d.ts +25 -0
  517. package/dist/vascend/granular-kingdom.js +259 -0
  518. package/dist/vascend/granular-launcher.d.ts +48 -0
  519. package/dist/vascend/granular-launcher.js +202 -0
  520. package/dist/vascend/kingdom-bus.d.ts +25 -0
  521. package/dist/vascend/kingdom-bus.js +54 -0
  522. package/dist/vascend/kingdom-channel.d.ts +22 -0
  523. package/dist/vascend/kingdom-channel.js +180 -0
  524. package/dist/vascend/kingdom-kpi.d.ts +48 -0
  525. package/dist/vascend/kingdom-kpi.js +172 -0
  526. package/dist/vascend/kingdom-live.d.ts +28 -0
  527. package/dist/vascend/kingdom-live.js +61 -0
  528. package/dist/vascend/kingdom-run.d.ts +18 -0
  529. package/dist/vascend/kingdom-run.js +506 -0
  530. package/dist/vascend/kingdom-scribe.d.ts +20 -0
  531. package/dist/vascend/kingdom-scribe.js +52 -0
  532. package/dist/vascend/kingdom.d.ts +79 -0
  533. package/dist/vascend/kingdom.js +870 -0
  534. package/dist/vascend/lexical-index.d.ts +10 -0
  535. package/dist/vascend/lexical-index.js +99 -0
  536. package/dist/vascend/lexical-search.d.ts +29 -0
  537. package/dist/vascend/lexical-search.js +262 -0
  538. package/dist/vascend/long-term-context.d.ts +51 -0
  539. package/dist/vascend/long-term-context.js +194 -0
  540. package/dist/vascend/mandate.d.ts +33 -0
  541. package/dist/vascend/mandate.js +107 -0
  542. package/dist/vascend/memory-packet.d.ts +13 -0
  543. package/dist/vascend/memory-packet.js +155 -0
  544. package/dist/vascend/memory-status.d.ts +22 -0
  545. package/dist/vascend/memory-status.js +73 -0
  546. package/dist/vascend/memory-store.d.ts +62 -0
  547. package/dist/vascend/memory-store.js +273 -0
  548. package/dist/vascend/objective-revision.d.ts +69 -0
  549. package/dist/vascend/objective-revision.js +319 -0
  550. package/dist/vascend/patch-plan-store.d.ts +33 -0
  551. package/dist/vascend/patch-plan-store.js +240 -0
  552. package/dist/vascend/patch-plan.d.ts +97 -0
  553. package/dist/vascend/patch-plan.js +345 -0
  554. package/dist/vascend/plan-progress.d.ts +11 -0
  555. package/dist/vascend/plan-progress.js +68 -0
  556. package/dist/vascend/plan-store.d.ts +64 -0
  557. package/dist/vascend/plan-store.js +460 -0
  558. package/dist/vascend/proof-chains.d.ts +19 -0
  559. package/dist/vascend/proof-chains.js +120 -0
  560. package/dist/vascend/ramification-store.d.ts +25 -0
  561. package/dist/vascend/ramification-store.js +94 -0
  562. package/dist/vascend/ramification.d.ts +193 -0
  563. package/dist/vascend/ramification.js +583 -0
  564. package/dist/vascend/recall-planner.d.ts +17 -0
  565. package/dist/vascend/recall-planner.js +109 -0
  566. package/dist/vascend/requirements.d.ts +31 -0
  567. package/dist/vascend/requirements.js +151 -0
  568. package/dist/vascend/reviewer.d.ts +9 -0
  569. package/dist/vascend/reviewer.js +93 -0
  570. package/dist/vascend/room-graph.d.ts +29 -0
  571. package/dist/vascend/room-graph.js +242 -0
  572. package/dist/vascend/room-memory.d.ts +57 -0
  573. package/dist/vascend/room-memory.js +631 -0
  574. package/dist/vascend/runtime.d.ts +84 -0
  575. package/dist/vascend/runtime.js +286 -0
  576. package/dist/vascend/self-improve.d.ts +104 -0
  577. package/dist/vascend/self-improve.js +396 -0
  578. package/dist/vascend/session-search.d.ts +52 -0
  579. package/dist/vascend/session-search.js +349 -0
  580. package/dist/vascend/supersession-graph.d.ts +14 -0
  581. package/dist/vascend/supersession-graph.js +70 -0
  582. package/dist/vascend/team-areas.d.ts +9 -0
  583. package/dist/vascend/team-areas.js +28 -0
  584. package/dist/vascend/team-handoff.d.ts +24 -0
  585. package/dist/vascend/team-handoff.js +37 -0
  586. package/dist/vascend/team-scheduler.d.ts +13 -0
  587. package/dist/vascend/team-scheduler.js +74 -0
  588. package/dist/vascend/team-session.d.ts +42 -0
  589. package/dist/vascend/team-session.js +142 -0
  590. package/dist/vascend/test-failure-memory.d.ts +76 -0
  591. package/dist/vascend/test-failure-memory.js +354 -0
  592. package/dist/vascend/token-market.d.ts +42 -0
  593. package/dist/vascend/token-market.js +144 -0
  594. package/dist/vascend/tuner-baseline-store.d.ts +52 -0
  595. package/dist/vascend/tuner-baseline-store.js +446 -0
  596. package/dist/vascend/user-profile.d.ts +44 -0
  597. package/dist/vascend/user-profile.js +131 -0
  598. package/dist/vascend/vision.d.ts +94 -0
  599. package/dist/vascend/vision.js +375 -0
  600. package/dist/vascend/work-agent.d.ts +12 -0
  601. package/dist/vascend/work-agent.js +83 -0
  602. package/dist/vascend/work-queue.d.ts +62 -0
  603. package/dist/vascend/work-queue.js +255 -0
  604. package/dist/vascend/work-runner.d.ts +64 -0
  605. package/dist/vascend/work-runner.js +137 -0
  606. package/dist/vascend/worktree.d.ts +38 -0
  607. package/dist/vascend/worktree.js +206 -0
  608. package/dist/vendor/computer-use/README.md +7 -0
  609. package/dist/vendor/computer-use/computer-desktop.js +211 -0
  610. package/dist/vendor/computer-use/computer-observe.js +315 -0
  611. package/dist/vendor/computer-use/computer-scripts.js +1230 -0
  612. package/dist/vendor/computer-use/computer-tools.js +2136 -0
  613. package/dist/vendor/computer-use/package.json +1 -0
  614. package/dist/vendor/computer-use/rac/atomic-input.js +91 -0
  615. package/dist/vendor/computer-use/rac/grammatica.js +101 -0
  616. package/dist/vendor/computer-use/rac/parser.js +185 -0
  617. package/dist/vendor/computer-use/rac/protocol.js +136 -0
  618. package/install.ps1 +30 -0
  619. package/install.sh +50 -0
  620. package/package.json +56 -0
@@ -0,0 +1,506 @@
1
+ // Kingdoms Mode per host NON testuali.
2
+ //
3
+ // La TUI disegna la sua board a caratteri e sa tutto quello che succede; ogni
4
+ // altro host (la chat di Horizon, l'RPC) vedeva invece una sola tool call
5
+ // ferma per minuti, senza sapere quanti vassalli fossero vivi ne' cosa
6
+ // stessero facendo. Qui l'orchestrazione emette gli stessi fatti come EVENTI
7
+ // strutturati, e chi disegna decide come.
8
+ //
9
+ // Il testo di ritorno e' quello che l'agente riceve come risultato del tool:
10
+ // report per castello, indice delle stanze del regno, nota git e rami in
11
+ // sospeso.
12
+ import { isAbsolute, resolve } from "node:path";
13
+ import { RoomMemory } from "./room-memory.js";
14
+ import { kingdomBus } from "./kingdom-bus.js";
15
+ import { kingdomLive } from "./kingdom-live.js";
16
+ import { resolveKingdomBus } from "./kingdom-channel.js";
17
+ import { collectConflicts, formatConflictList, runKingdomWarm, warmConcurrency, } from "./kingdom.js";
18
+ import { registerTeam, updateTeamMember } from "./team-session.js";
19
+ import { worktreeMode } from "./worktree.js";
20
+ const LABEL_MAX = 60;
21
+ const SUMMARY_MAX = 300;
22
+ // Cosa dice un vassallo arriva a delta di pochi caratteri. Mandarli cosi' come
23
+ // sono farebbe un evento per token; accorpiamo fino a un paragrafo o al primo
24
+ // confine del turno.
25
+ const SAY_FLUSH_CHARS = 480;
26
+ const SAY_MAX = 4000;
27
+ const TOOL_OUTPUT_MAX = 900;
28
+ // Un comando di shell puo' essere una pipeline lunga: si tiene per intero fin
29
+ // dove resta leggibile, non lo si riduce a una riga.
30
+ const SHELL_COMMAND_MAX = 1200;
31
+ let kingdomRunSequence = 0;
32
+ export async function runKingdomForHost(input) {
33
+ const { harness, castles, signal, sink, confirm } = input;
34
+ const env = input.env ?? process.env;
35
+ // La sessione dura quanto la conversazione, uno swarm no. Un id riusato
36
+ // faceva fondere nella UI il regno concluso con quello successivo.
37
+ kingdomRunSequence = (kingdomRunSequence + 1) % 0xfffff;
38
+ const kingdomId = `kw-${harness.session.id}-${Date.now().toString(36)}-${kingdomRunSequence.toString(36)}`;
39
+ const concurrency = warmConcurrency(env);
40
+ const worktree = worktreeMode(env);
41
+ // Bus pulito per il nuovo regno (in memoria e sul canale persistente).
42
+ kingdomBus.clear(kingdomId);
43
+ kingdomLive.clear(kingdomId);
44
+ try {
45
+ resolveKingdomBus(env, harness.config.sessionDir).clear(kingdomId);
46
+ }
47
+ catch {
48
+ // canale file-based non disponibile: il regno gira lo stesso
49
+ }
50
+ const info = castles.map((c) => ({
51
+ slug: c.slug,
52
+ goal: c.goal,
53
+ after: [...(c.after ?? [])],
54
+ ...(c.parent ? { parent: c.parent } : {}),
55
+ ...(c.role ? { role: c.role } : {}),
56
+ ...(c.castle ? { castle: c.castle } : {}),
57
+ ...(c.tasks?.length ? { tasks: [...c.tasks] } : {}),
58
+ ...(c.model ? { model: c.model } : {}),
59
+ ...(c.effort ? { effort: c.effort } : {}),
60
+ ...(c.tools ? { tools: c.tools } : {}),
61
+ }));
62
+ sink({ type: "kingdom", phase: "start", kingdomId, concurrency, worktree, castles: info });
63
+ for (const castle of castles) {
64
+ sink({
65
+ type: "kingdom",
66
+ phase: "message",
67
+ kind: "assignment",
68
+ from: castle.parent?.trim() || "orchestratore",
69
+ to: castle.slug,
70
+ text: `Task assegnato: ${clamp(castle.goal, 900)}`,
71
+ ...(castle.castle ? { workstreamId: castle.castle } : {}),
72
+ ...(castle.tasks?.[0] ? { taskRef: String(castle.tasks[0]) } : {}),
73
+ });
74
+ }
75
+ const started = new Set();
76
+ const nestedCalls = new Map();
77
+ const nestedCallKey = (slug, id) => `${slug}\u0000${id}`;
78
+ // Testo in attesa di essere accorpato, per collaboratore.
79
+ const saying = new Map();
80
+ // Quanto ha consumato ognuno, cumulato. Il conto della sessione principale
81
+ // non vede le sessioni figlie: senza questo, con cinque agenti al lavoro il
82
+ // costo mostrato in chat e' quello di uno solo.
83
+ const spesa = new Map();
84
+ const flushSay = (slug) => {
85
+ const buffered = (saying.get(slug) ?? "").trim();
86
+ saying.delete(slug);
87
+ if (!buffered)
88
+ return;
89
+ sink({ type: "kingdom", phase: "say", slug, text: buffered.slice(0, SAY_MAX), at: Date.now() });
90
+ };
91
+ const onEvent = (slug, event) => {
92
+ if (event.type === "usage") {
93
+ sink({ ...event, record: { ...event.record, actor: event.record.actor ?? slug } });
94
+ return;
95
+ }
96
+ // Gli swarm annidati emettono gia' fatti Kingdom completi. Li inoltriamo
97
+ // senza attribuirli per errore al padre che li ha generati.
98
+ if (event.type === "kingdom") {
99
+ if (event.phase !== "start" && event.phase !== "end")
100
+ sink(event);
101
+ return;
102
+ }
103
+ const slash = slug.lastIndexOf("/");
104
+ const parent = slash > 0 ? slug.slice(0, slash) : "";
105
+ const route = slug.split("/").filter(Boolean);
106
+ const assignment = {
107
+ ...(route[0] && route.length > 1 ? { workstreamId: route[0] } : {}),
108
+ ...(route[1] ? { taskRefs: [route[1]], parentTaskRef: route[1] } : {}),
109
+ };
110
+ if (!started.has(slug)) {
111
+ started.add(slug);
112
+ sink({
113
+ type: "kingdom", phase: "vassal", slug, state: "start", ...(parent ? { parent } : {}), ...assignment,
114
+ });
115
+ }
116
+ // Il DISCORSO del collaboratore. Prima si fermava alla sua sessione: l'host
117
+ // vedeva la sequenza dei comandi ma non il perche', e una scheda piena di
118
+ // tool call non e' una conversazione. Il testo esce accorpato, mai a delta.
119
+ if (event.type === "text") {
120
+ const buffered = (saying.get(slug) ?? "") + event.delta;
121
+ // Si taglia dove finisce un pensiero (riga vuota), non a meta' frase.
122
+ const cut = buffered.length >= SAY_FLUSH_CHARS ? buffered.lastIndexOf("\n\n") : -1;
123
+ if (cut > 0) {
124
+ saying.set(slug, buffered.slice(cut + 2));
125
+ const chunk = buffered.slice(0, cut).trim();
126
+ if (chunk)
127
+ sink({ type: "kingdom", phase: "say", slug, text: chunk.slice(0, SAY_MAX), at: Date.now() });
128
+ }
129
+ else if (buffered.length >= SAY_MAX) {
130
+ saying.set(slug, "");
131
+ sink({ type: "kingdom", phase: "say", slug, text: buffered.slice(0, SAY_MAX), at: Date.now() });
132
+ }
133
+ else {
134
+ saying.set(slug, buffered);
135
+ }
136
+ return;
137
+ }
138
+ // Un messaggio dell'utente e' appena entrato nel contesto DI QUESTO
139
+ // collaboratore: la sua scheda puo' segnarlo come letto, con l'istante.
140
+ if (event.type === "user_message") {
141
+ sink({
142
+ type: "kingdom",
143
+ phase: "inbox",
144
+ slug,
145
+ messageId: event.id,
146
+ text: clamp(event.text, 900),
147
+ state: "read",
148
+ at: Number(event.at) || Date.now(),
149
+ });
150
+ return;
151
+ }
152
+ // Prima di qualunque altro fatto il discorso in sospeso va chiuso, o
153
+ // finirebbe in coda a cose successe dopo.
154
+ if (event.type === "tool_call" || event.type === "turn_end" || event.type === "done" || event.type === "error") {
155
+ flushSay(slug);
156
+ }
157
+ if (event.type === "turn_end" && event.usage) {
158
+ const corrente = spesa.get(slug) ?? { input: 0, output: 0, cost: 0, turns: 0 };
159
+ const prossimo = {
160
+ input: corrente.input + (Number(event.usage.inputTokens) || 0),
161
+ output: corrente.output + (Number(event.usage.outputTokens) || 0),
162
+ cost: corrente.cost + (Number(event.usage.costUsd) || 0),
163
+ turns: corrente.turns + 1,
164
+ };
165
+ spesa.set(slug, prossimo);
166
+ sink({
167
+ type: "kingdom",
168
+ phase: "usage",
169
+ slug,
170
+ inputTokens: prossimo.input,
171
+ outputTokens: prossimo.output,
172
+ totalTokens: prossimo.input + prossimo.output,
173
+ ...(prossimo.cost > 0 ? { costUsd: prossimo.cost } : {}),
174
+ turns: prossimo.turns,
175
+ at: Date.now(),
176
+ });
177
+ }
178
+ if (event.type === "tool_call") {
179
+ const arg = firstArg(event.call.input);
180
+ const command = shellCommand(event.call.name, event.call.input);
181
+ sink({
182
+ type: "kingdom",
183
+ phase: "tool",
184
+ slug,
185
+ callId: event.call.id,
186
+ tool: event.call.name,
187
+ ...(arg ? { args: clamp(arg, 240) } : {}),
188
+ ...(command ? { command } : {}),
189
+ state: "start",
190
+ at: Date.now(),
191
+ });
192
+ }
193
+ if (event.type === "tool_result") {
194
+ // L'esito e' la meta' che mancava: senza, la scheda mostra dieci comandi
195
+ // partiti e nessuno concluso, e chi guarda non sa se stia avanzando.
196
+ const call = nestedCalls.get(nestedCallKey(slug, event.result.callId));
197
+ sink({
198
+ type: "kingdom",
199
+ phase: "tool",
200
+ slug,
201
+ callId: event.result.callId,
202
+ tool: call?.name ?? "",
203
+ state: event.result.isError ? "error" : "ok",
204
+ output: clamp(String(event.result.output ?? ""), TOOL_OUTPUT_MAX),
205
+ at: Date.now(),
206
+ });
207
+ }
208
+ const mapped = vassalActivity(event);
209
+ if (mapped)
210
+ sink({
211
+ type: "kingdom",
212
+ phase: "vassal",
213
+ slug,
214
+ state: mapped.state,
215
+ ...(mapped.label ? { label: mapped.label } : {}),
216
+ ...(parent ? { parent } : {}),
217
+ ...assignment,
218
+ });
219
+ // I messaggi fra vassalli sono il grafo di cooperazione: vanno estratti
220
+ // dalla tool call, non dedotti dal testo.
221
+ if (event.type === "tool_call" && event.call.name === "team_say") {
222
+ const rawTo = typeof event.call.input["to"] === "string" && event.call.input["to"]
223
+ ? String(event.call.input["to"]) : "tutti";
224
+ const to = parent
225
+ && rawTo !== "tutti"
226
+ && rawTo !== "orchestratore"
227
+ && !rawTo.includes("/")
228
+ && rawTo !== route[0]
229
+ ? `${parent}/${rawTo}`
230
+ : rawTo;
231
+ sink({
232
+ type: "kingdom",
233
+ phase: "message",
234
+ from: slug,
235
+ to,
236
+ kind: "message",
237
+ text: clamp(String(event.call.input["text"] ?? ""), 900),
238
+ ...(slug.includes("/") ? {
239
+ workstreamId: slug.split("/")[0],
240
+ taskRef: slug.split("/")[1] ?? "",
241
+ } : {}),
242
+ });
243
+ }
244
+ // Il piano e i file modificati dentro i collaboratori devono attraversare
245
+ // il confine del regno. Prima restavano nelle sessioni figlie: il JSON del
246
+ // piano avanzava, mentre la board Horizon rimaneva a 0/N.
247
+ if (event.type === "tool_call") {
248
+ nestedCalls.set(nestedCallKey(slug, event.call.id), {
249
+ name: event.call.name,
250
+ input: event.call.input,
251
+ });
252
+ }
253
+ if (event.type === "tool_result") {
254
+ const key = nestedCallKey(slug, event.result.callId);
255
+ const call = nestedCalls.get(key);
256
+ nestedCalls.delete(key);
257
+ if (!call || event.result.isError)
258
+ return;
259
+ const output = String(event.result.output ?? "");
260
+ const workstreamId = String(call.input["castle"] ?? route[0] ?? "master").trim() || "master";
261
+ const taskRef = String(call.input["task"] ?? route[1] ?? "").trim();
262
+ if (call.name === "vascend_mark" && taskRef && /^\[[^\]]+\]\s+T\d+/i.test(output)) {
263
+ const rawStatus = String(call.input["status"] ?? "completed");
264
+ const status = rawStatus === "pending" || rawStatus === "running" || rawStatus === "failed" ? rawStatus : "completed";
265
+ sink({
266
+ type: "kingdom",
267
+ phase: "task",
268
+ slug,
269
+ workstreamId,
270
+ taskRef,
271
+ status,
272
+ at: Date.now(),
273
+ });
274
+ }
275
+ else if (call.name === "vascend_note" && /^nota aggiunta a /i.test(output)) {
276
+ const text = clamp(String(call.input["note"] ?? ""), 900);
277
+ if (text) {
278
+ sink({
279
+ type: "kingdom",
280
+ phase: "note",
281
+ slug,
282
+ workstreamId,
283
+ ...(taskRef ? { taskRef } : {}),
284
+ text,
285
+ at: Date.now(),
286
+ });
287
+ }
288
+ }
289
+ else if ((call.name === "write_file" || call.name === "edit_file")
290
+ && /^(?:scritto|accodato|modificato):/i.test(output)) {
291
+ const rawPath = String(call.input["path"] ?? "").trim();
292
+ if (rawPath) {
293
+ const target = isAbsolute(rawPath) ? rawPath : resolve(harness.config.cwd, rawPath);
294
+ sink({
295
+ type: "kingdom",
296
+ phase: "file",
297
+ slug,
298
+ path: target,
299
+ operation: call.name === "write_file" ? "write" : "edit",
300
+ ...(workstreamId ? { workstreamId } : {}),
301
+ ...(taskRef ? { taskRef } : {}),
302
+ edit: editPayload(call.name, call.input),
303
+ });
304
+ }
305
+ }
306
+ }
307
+ };
308
+ const lavoro = (async () => runKingdomWarm({
309
+ harness,
310
+ kingdomId,
311
+ castles,
312
+ signal,
313
+ confirm,
314
+ ask: input.ask,
315
+ concurrency,
316
+ onEvent,
317
+ onMemberState: (slug, status, report) => {
318
+ updateTeamMember(kingdomId, slug, { status, ...(report ? { summary: report.summary, error: report.error, artifacts: report.artifacts } : {}) });
319
+ if (status === "failed")
320
+ sink({ type: "kingdom", phase: "vassal", slug, state: "error", label: clamp(report?.error ?? "incarico fallito", SUMMARY_MAX) });
321
+ if (report) {
322
+ try {
323
+ resolveKingdomBus(env, harness.config.sessionDir).post(kingdomId, slug, null, report.ok ? `Completato: ${report.summary.slice(0, 3000)}` : `Fallito: ${report.error ?? report.summary}`, Date.now());
324
+ }
325
+ catch { /* reports remain available even if the message store is unavailable */ }
326
+ }
327
+ },
328
+ worktree,
329
+ ...(input.fileCoordination ? { fileCoordination: input.fileCoordination } : {}),
330
+ ...(input.baseBranch ? { baseBranch: input.baseBranch } : {}),
331
+ onNotice: (text) => sink({ type: "kingdom", phase: "notice", text }),
332
+ }))();
333
+ /* Staccato: la squadra parte e il turno prosegue. La promessa non si perde,
334
+ va nel registro delle squadre vive; chi ha ingaggiato puo' parlarci con
335
+ team_say, leggerne le risposte e raccogliere i risultati con team_report.
336
+ Il resto di questa funzione (riepilogo, rami, note) e' cio' che si fa a
337
+ lavoro FINITO: qui si riattacca alla promessa invece di bloccare. */
338
+ if (input.detach) {
339
+ registerTeam({
340
+ sessionDir: harness.config.sessionDir,
341
+ id: kingdomId,
342
+ sessionId: String(harness.session.id || ""),
343
+ members: castles.map((c) => ({
344
+ slug: c.slug,
345
+ role: String(c.role ?? "collaboratore"),
346
+ mandate: clamp(c.goal ?? "", 300),
347
+ ...(c.after ? { after: c.after } : {}), ...(c.area ? { area: c.area } : {}),
348
+ ...(c.castle ? { castle: c.castle } : {}), ...(c.tasks ? { tasks: c.tasks } : {}),
349
+ })),
350
+ work: lavoro.then((reports) => chiudi(reports)),
351
+ at: Date.now(),
352
+ });
353
+ const elenco = castles.map((c) => `${c.slug}${c.role ? ` (${c.role})` : ""}`).join(", ");
354
+ return `Squadra al lavoro: ${elenco}.
355
+ `
356
+ + `Gli incarichi pronti partono entro il limite di concorrenza; gli altri attendono dipendenze o aree libere. Parlagli con team_say, leggi cosa rispondono con `
357
+ + `team_inbox, e quando serve raccogli i risultati con team_report. Non aspettarli fermo: `
358
+ + `se non hai altro da fare usa team_wait.`;
359
+ }
360
+ return chiudi(await lavoro);
361
+ // Cio' che si fa quando la squadra ha finito: riepilogo per collaboratore,
362
+ // indice delle stanze, nota sui rami. Identico nei due percorsi.
363
+ function chiudi(reports) {
364
+ // Ultime parole rimaste nel buffer di chi ha finito senza un confine di turno.
365
+ for (const slug of [...saying.keys()])
366
+ flushSay(slug);
367
+ kingdomLive.clear(kingdomId);
368
+ for (const report of reports) {
369
+ updateTeamMember(kingdomId, report.slug, { status: report.ok ? "completed" : "failed", summary: report.summary, error: report.error, artifacts: report.artifacts });
370
+ sink({
371
+ type: "kingdom",
372
+ phase: "message",
373
+ kind: "result",
374
+ from: report.slug,
375
+ to: report.parent?.trim() || "orchestratore",
376
+ text: report.ok
377
+ ? `Risultato: ${clamp(report.summary || "Task completato", 900)}`
378
+ : `Errore: ${clamp(report.error || report.summary || "Task non completato", 900)}`,
379
+ ...(report.workstreamId ? { workstreamId: report.workstreamId } : {}),
380
+ ...(report.taskRefs?.[0] ? { taskRef: report.taskRefs[0] } : {}),
381
+ });
382
+ }
383
+ sink({ type: "kingdom", phase: "end", reports: reports.map(toSummary) });
384
+ return formatKingdomOutcome(reports, harness.config.sessionDir, kingdomId);
385
+ }
386
+ }
387
+ // Frammenti della modifica, tagliati: bastano a disegnare un diff leggibile e
388
+ // non trasformano un evento in un trasferimento di file.
389
+ const EDIT_FRAGMENT_MAX = 8000;
390
+ function editPayload(tool, input) {
391
+ const cut = (value) => String(value ?? "").slice(0, EDIT_FRAGMENT_MAX);
392
+ if (tool === "edit_file") {
393
+ const oldString = cut(input["old_string"]);
394
+ const newString = cut(input["new_string"]);
395
+ if (!oldString && !newString)
396
+ return undefined;
397
+ return { oldString, newString };
398
+ }
399
+ if (tool === "write_file") {
400
+ const content = cut(input["content"]);
401
+ if (!content)
402
+ return undefined;
403
+ return { content, append: input["append"] === true };
404
+ }
405
+ return undefined;
406
+ }
407
+ // Attivita' del vassallo in una riga. Non tutto merita un evento: il testo in
408
+ // streaming e i risultati dei tool riempirebbero la UI senza dire di piu'.
409
+ function vassalActivity(event) {
410
+ if (event.type === "tool_call") {
411
+ const arg = firstArg(event.call.input);
412
+ return { state: "active", label: clamp(`${event.call.name}${arg ? `(${arg})` : ""}`, LABEL_MAX) };
413
+ }
414
+ if (event.type === "turn_start")
415
+ return { state: "active", label: "Pianifica il task" };
416
+ if (event.type === "done")
417
+ return { state: "done" };
418
+ if (event.type === "error")
419
+ return { state: "error", label: clamp(event.message, LABEL_MAX) };
420
+ return null;
421
+ }
422
+ function toSummary(report) {
423
+ return {
424
+ slug: report.slug,
425
+ ok: report.ok,
426
+ rooms: report.rooms,
427
+ summary: clamp(report.summary, SUMMARY_MAX),
428
+ ...(report.model ? { model: report.model } : {}),
429
+ ...(report.role ? { role: report.role } : {}),
430
+ ...(report.parent ? { parent: report.parent } : {}),
431
+ ...(report.workstreamId ? { workstreamId: report.workstreamId } : {}),
432
+ ...(report.taskRefs?.length ? { taskRefs: [...report.taskRefs] } : {}),
433
+ ...(report.parentTaskRef ? { parentTaskRef: report.parentTaskRef } : {}),
434
+ ...(report.error ? { error: clamp(report.error, LABEL_MAX * 2) } : {}),
435
+ ...(report.branch ? { branch: report.branch } : {}),
436
+ ...(report.merge ? { merged: report.merge.ok } : {}),
437
+ };
438
+ }
439
+ // Risultato testuale del tool: quello che l'agente legge per sapere cosa hanno
440
+ // prodotto i vassalli e cosa resta da fare a mano.
441
+ export function formatKingdomOutcome(reports, sessionDir, kingdomId) {
442
+ const lines = reports
443
+ .map((r) => {
444
+ const merge = r.merge
445
+ ? (r.merge.ok ? " · merge ok" : ` · merge fallito (${r.merge.conflict ? "conflitto" : "errore"}, ramo ${r.branch} conservato)`)
446
+ : "";
447
+ return `[${r.slug}] ${r.ok ? "ok" : "fallito"} (${r.rooms} attivita)${r.error ? ` errore: ${r.error}` : ""}${merge}: ${clamp(r.summary, SUMMARY_MAX)}`;
448
+ })
449
+ .join("\n");
450
+ let index = "";
451
+ try {
452
+ const block = RoomMemory.open(sessionDir, kingdomId).indexBlock();
453
+ if (block.trim())
454
+ index = `\n\nATTIVITA ARCHIVIATE (recall per il dettaglio):\n${block}`;
455
+ }
456
+ catch {
457
+ // nessuna memoria del regno: il report resta valido
458
+ }
459
+ const isolated = reports.some((r) => r.branch);
460
+ const conflicts = collectConflicts(reports);
461
+ const gitNote = isolated
462
+ ? `\n\n[NOTA_GIT]
463
+ @stato[rami]: ogni collaboratore in worktree isolato; rami merge-ati nel ramo base
464
+ @conflitti[merge]: ${conflicts.length ? `${conflicts.map((r) => r.slug).join(", ")} NON merge-ati (rami conservati, risoluzione manuale)` : "nessuno"}
465
+ @azione[consegna]: verifica diff e controlli nel ramo base; push solo se richiesto dall'utente`
466
+ : `\n\n[NOTA_GIT]
467
+ @stato[modifiche]: nel working tree, NON committate (i collaboratori non fanno git: working dir condivisa)
468
+ @azione[consegna]: verifica diff e controlli; commit e push solo se richiesti dall'utente`;
469
+ const stash = formatConflictList(conflicts);
470
+ return `ESECUZIONE ATTIVITA CONCLUSA · ${reports.length} gruppi\n${lines}${index}${gitNote}${stash ? `\n\n${stash}` : ""}`;
471
+ }
472
+ // Il comando di shell COME E' SCRITTO: a capo, indentazione e pipe intatti.
473
+ // Non passa da `clamp`, che schiaccerebbe tutto su una riga — ed e' proprio
474
+ // la forma che rende leggibile una pipeline. Solo i tool che eseguono davvero
475
+ // qualcosa: per un `read` il "comando" non esiste e mostrarlo mentirebbe.
476
+ function shellCommand(tool, input) {
477
+ if (!/(?:bash|shell|command|powershell|terminal|exec|run_)/i.test(tool))
478
+ return "";
479
+ const raw = input["command"] ?? input["script"] ?? input["cmd"];
480
+ if (typeof raw !== "string")
481
+ return "";
482
+ const text = raw.split(String.fromCharCode(13)).join("").trim();
483
+ if (!text)
484
+ return "";
485
+ return text.length > SHELL_COMMAND_MAX ? `${text.slice(0, SHELL_COMMAND_MAX - 1)}…` : text;
486
+ }
487
+ function firstArg(input) {
488
+ const path = input["path"];
489
+ if (typeof path === "string" && path)
490
+ return path;
491
+ const command = input["command"];
492
+ if (typeof command === "string")
493
+ return command;
494
+ const query = input["query"] ?? input["pattern"];
495
+ if (typeof query === "string")
496
+ return query;
497
+ const keys = Object.keys(input);
498
+ if (!keys.length)
499
+ return "";
500
+ const value = input[keys[0]];
501
+ return typeof value === "string" ? value : "";
502
+ }
503
+ function clamp(value, max) {
504
+ const text = value.replace(/\s+/g, " ").trim();
505
+ return text.length > max ? `${text.slice(0, max - 1)}…` : text;
506
+ }
@@ -0,0 +1,20 @@
1
+ import type { Message } from "../core/types.js";
2
+ import { type RoomRecord } from "./room-memory.js";
3
+ export interface ScribeSubmission {
4
+ readonly messages: readonly Message[];
5
+ readonly namespace?: string;
6
+ readonly createdAt: number;
7
+ }
8
+ declare class KingdomScribe {
9
+ private readonly sessionDir;
10
+ private readonly storeId;
11
+ private readonly fanout;
12
+ private readonly chains;
13
+ constructor(sessionDir: string, storeId: string, fanout: number);
14
+ private chainKey;
15
+ submitRoom(sub: ScribeSubmission): Promise<RoomRecord>;
16
+ private writeOne;
17
+ }
18
+ export declare function getKingdomScribe(sessionDir: string, storeId: string, fanout: number): KingdomScribe;
19
+ export declare function _resetScribes(): void;
20
+ export type { KingdomScribe };
@@ -0,0 +1,52 @@
1
+ import { RoomMemory, formatRoomRecord } from "./room-memory.js";
2
+ class KingdomScribe {
3
+ sessionDir;
4
+ storeId;
5
+ fanout;
6
+ // Coda di scrittura per store: la promise-chain garantisce un solo writer
7
+ // logico per volta sullo stesso file (serializzazione in-process).
8
+ chains = new Map();
9
+ constructor(sessionDir, storeId, fanout) {
10
+ this.sessionDir = sessionDir;
11
+ this.storeId = storeId;
12
+ this.fanout = fanout;
13
+ }
14
+ chainKey() {
15
+ return `${this.sessionDir}::${this.storeId}`;
16
+ }
17
+ // Accoda una scrittura serializzata. Ogni submit aspetta il precedente sullo
18
+ // stesso store, poi esegue la sua append sotto lock file-system.
19
+ submitRoom(sub) {
20
+ const key = this.chainKey();
21
+ const prev = this.chains.get(key) ?? Promise.resolve();
22
+ const next = prev.then(() => this.writeOne(sub), () => this.writeOne(sub));
23
+ // Tieni la catena viva ma non trattenere i risultati/errori.
24
+ this.chains.set(key, next.then(() => undefined, () => undefined));
25
+ return next;
26
+ }
27
+ writeOne(sub) {
28
+ // Apri una vista dello store; appendRoomNamespaced ricarica dal disco sotto
29
+ // lock prima di calcolare l'id, quindi va bene anche se questa istanza e'
30
+ // appena stata creata.
31
+ const mem = RoomMemory.open(this.sessionDir, this.storeId, this.fanout);
32
+ return mem.appendRoomNamespaced((id) => formatRoomRecord(id, sub.messages, sub.createdAt), sub.namespace);
33
+ }
34
+ }
35
+ // Singleton per store: tutte le scritture sullo stesso `${sessionDir}/${storeId}`
36
+ // passano dallo stesso Scribe (stessa coda). Indispensabile: due Scribe diversi
37
+ // sullo stesso file non si serializzerebbero in-process (resterebbe solo il
38
+ // lock cross-processo, piu' costoso e con piu' contesa).
39
+ const scribes = new Map();
40
+ export function getKingdomScribe(sessionDir, storeId, fanout) {
41
+ const key = `${sessionDir}::${storeId}`;
42
+ let s = scribes.get(key);
43
+ if (!s) {
44
+ s = new KingdomScribe(sessionDir, storeId, fanout);
45
+ scribes.set(key, s);
46
+ }
47
+ return s;
48
+ }
49
+ // Solo per i test: azzera i singleton (catene di scrittura) tra un caso e l'altro.
50
+ export function _resetScribes() {
51
+ scribes.clear();
52
+ }
@@ -0,0 +1,79 @@
1
+ import type { Harness } from "../core/bootstrap.js";
2
+ import { type FileCoordinationContext } from "../core/file-coordination.js";
3
+ import type { AgentEvent, SpawnAgentSpec, ToolContext } from "../core/types.js";
4
+ export { disjointAreas } from "./team-areas.js";
5
+ import { type MergeResult } from "./worktree.js";
6
+ export interface CastleSpec extends SpawnAgentSpec {
7
+ }
8
+ export interface VassalReport {
9
+ readonly artifacts?: readonly import("./team-handoff.js").ArtifactReference[];
10
+ readonly slug: string;
11
+ readonly ok: boolean;
12
+ readonly summary: string;
13
+ readonly rooms: number;
14
+ readonly model?: string;
15
+ readonly role?: string;
16
+ readonly parent?: string;
17
+ readonly workstreamId?: string;
18
+ readonly taskRefs?: readonly string[];
19
+ readonly parentTaskRef?: string;
20
+ readonly error?: string;
21
+ readonly branch?: string;
22
+ readonly worktree?: string;
23
+ readonly merge?: MergeResult;
24
+ readonly recovery?: WorktreeRecovery;
25
+ }
26
+ export type WorktreeRecoveryReason = "setup-failed" | "vassal-failed" | "commit-failed" | "merge-failed" | "cleanup-failed";
27
+ export interface WorktreeRecovery {
28
+ readonly reason: WorktreeRecoveryReason;
29
+ readonly worktree?: string;
30
+ readonly commitRequired: boolean;
31
+ readonly mergeRequired: boolean;
32
+ readonly note: string;
33
+ }
34
+ export interface ConflictEntry {
35
+ readonly slug: string;
36
+ readonly branch: string;
37
+ readonly conflict: boolean;
38
+ readonly note: string;
39
+ readonly worktree?: string;
40
+ readonly reason?: WorktreeRecoveryReason;
41
+ readonly commitRequired?: boolean;
42
+ readonly mergeRequired?: boolean;
43
+ readonly integrated?: boolean;
44
+ }
45
+ export declare function collectConflicts(reports: readonly VassalReport[]): ConflictEntry[];
46
+ export declare function formatConflictList(conflicts: readonly ConflictEntry[], base?: string): string;
47
+ export interface KingdomWarmOptions {
48
+ readonly harness: Harness;
49
+ readonly kingdomId: string;
50
+ readonly castles: readonly CastleSpec[];
51
+ readonly signal: AbortSignal;
52
+ readonly confirm: (action: string, detail: string) => Promise<boolean>;
53
+ readonly ask?: ToolContext["ask"];
54
+ readonly fileCoordination?: FileCoordinationContext;
55
+ readonly concurrency?: number;
56
+ readonly onEvent?: (slug: string, event: AgentEvent) => void;
57
+ readonly worktree?: boolean;
58
+ readonly baseBranch?: string;
59
+ readonly onNotice?: (text: string) => void;
60
+ readonly onMemberState?: (slug: string, state: "running" | "completed" | "failed", report?: VassalReport) => void;
61
+ }
62
+ export declare function warmConcurrency(env: NodeJS.ProcessEnv, fallback?: number): number;
63
+ export declare function looksBigGoal(text: string): boolean;
64
+ export declare function decomposeKingdom(opts: {
65
+ readonly harness: Harness;
66
+ readonly goal: string;
67
+ readonly signal: AbortSignal;
68
+ readonly max?: number;
69
+ }): Promise<CastleSpec[]>;
70
+ export interface FinalizeVassalWorktreeOptions {
71
+ readonly root: string;
72
+ readonly base: string;
73
+ readonly branch: string;
74
+ readonly dir: string;
75
+ readonly report: VassalReport;
76
+ readonly signal?: AbortSignal;
77
+ }
78
+ export declare function finalizeVassalWorktree(opts: FinalizeVassalWorktreeOptions): Promise<VassalReport>;
79
+ export declare function runKingdomWarm(opts: KingdomWarmOptions): Promise<VassalReport[]>;