agency-lang 0.7.7 → 0.8.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 (577) hide show
  1. package/dist/lib/agents/agency-agent/agent.agency +571 -47
  2. package/dist/lib/agents/agency-agent/agent.js +4752 -1555
  3. package/dist/lib/agents/agency-agent/lib/attachments.js +16 -20
  4. package/dist/lib/agents/agency-agent/lib/capabilities.agency +464 -0
  5. package/dist/lib/agents/agency-agent/lib/capabilities.js +2549 -0
  6. package/dist/lib/agents/agency-agent/lib/config.agency +32 -1
  7. package/dist/lib/agents/agency-agent/lib/config.js +165 -6
  8. package/dist/lib/agents/agency-agent/lib/defaultPolicy.js +92 -96
  9. package/dist/lib/agents/agency-agent/lib/modelFilters.js +9 -8
  10. package/dist/lib/agents/agency-agent/lib/models.agency +46 -12
  11. package/dist/lib/agents/agency-agent/lib/models.js +382 -89
  12. package/dist/lib/agents/agency-agent/lib/resolution.agency +22 -7
  13. package/dist/lib/agents/agency-agent/lib/resolution.js +140 -90
  14. package/dist/lib/agents/agency-agent/lib/search.js +91 -112
  15. package/dist/lib/agents/agency-agent/lib/settings.agency +36 -4
  16. package/dist/lib/agents/agency-agent/lib/settings.js +361 -55
  17. package/dist/lib/agents/agency-agent/lib/slots.js +19 -21
  18. package/dist/lib/agents/agency-agent/lib/utils.js +37 -39
  19. package/dist/lib/agents/agency-agent/prompts/codeSample.js +2 -2
  20. package/dist/lib/agents/agency-agent/shared.agency +218 -18
  21. package/dist/lib/agents/agency-agent/shared.js +1898 -270
  22. package/dist/lib/agents/agency-agent/subagents/code.agency +54 -4
  23. package/dist/lib/agents/agency-agent/subagents/code.js +136 -75
  24. package/dist/lib/agents/agency-agent/subagents/explorer.agency +3 -3
  25. package/dist/lib/agents/agency-agent/subagents/explorer.js +20 -37
  26. package/dist/lib/agents/agency-agent/subagents/oracle.agency +3 -3
  27. package/dist/lib/agents/agency-agent/subagents/oracle.js +20 -37
  28. package/dist/lib/agents/agency-agent/subagents/research.agency +8 -14
  29. package/dist/lib/agents/agency-agent/subagents/research.js +23 -42
  30. package/dist/lib/agents/agency-agent/subagents/review.agency +27 -130
  31. package/dist/lib/agents/agency-agent/subagents/review.js +49 -800
  32. package/dist/lib/agents/agency-agent/subagents/verify.agency +112 -0
  33. package/dist/lib/agents/agency-agent/subagents/verify.js +906 -0
  34. package/dist/lib/agents/agency-agent/tests/agentDir.agency +20 -0
  35. package/dist/lib/agents/agency-agent/tests/agentDir.js +343 -0
  36. package/dist/lib/agents/agency-agent/tests/agentDir.test.json +15 -0
  37. package/dist/lib/agents/agency-agent/tests/agentTurn.agency +163 -1
  38. package/dist/lib/agents/agency-agent/tests/agentTurn.js +1383 -176
  39. package/dist/lib/agents/agency-agent/tests/agentTurn.test.json +261 -19
  40. package/dist/lib/agents/agency-agent/tests/attachments.js +100 -211
  41. package/dist/lib/agents/agency-agent/tests/attachmentsTurn.js +17 -40
  42. package/dist/lib/agents/agency-agent/tests/capabilities.agency +233 -0
  43. package/dist/lib/agents/agency-agent/tests/capabilities.js +2168 -0
  44. package/dist/lib/agents/agency-agent/tests/capabilities.test.json +165 -0
  45. package/dist/lib/agents/agency-agent/tests/execPolicy.agency +2 -2
  46. package/dist/lib/agents/agency-agent/tests/execPolicy.js +13 -19
  47. package/dist/lib/agents/agency-agent/tests/gitPolicy.agency +2 -2
  48. package/dist/lib/agents/agency-agent/tests/gitPolicy.js +15 -34
  49. package/dist/lib/agents/agency-agent/tests/imageTool.js +13 -39
  50. package/dist/lib/agents/agency-agent/tests/mcpGating.agency +42 -0
  51. package/dist/lib/agents/agency-agent/tests/mcpGating.js +670 -0
  52. package/dist/lib/agents/agency-agent/tests/mcpGating.test.json +22 -0
  53. package/dist/lib/agents/agency-agent/tests/memoryWiring.agency +148 -0
  54. package/dist/lib/agents/agency-agent/tests/memoryWiring.js +1288 -0
  55. package/dist/lib/agents/agency-agent/tests/memoryWiring.test.json +75 -0
  56. package/dist/lib/agents/agency-agent/tests/modelFilters.js +0 -5
  57. package/dist/lib/agents/agency-agent/tests/models.js +7 -26
  58. package/dist/lib/agents/agency-agent/tests/oneShotRounds.js +0 -4
  59. package/dist/lib/agents/agency-agent/tests/resolution.agency +52 -0
  60. package/dist/lib/agents/agency-agent/tests/resolution.js +380 -24
  61. package/dist/lib/agents/agency-agent/tests/resolution.test.json +110 -8
  62. package/dist/lib/agents/agency-agent/tests/search.js +27 -43
  63. package/dist/lib/agents/agency-agent/tests/settings.agency +109 -0
  64. package/dist/lib/agents/agency-agent/tests/settings.js +1001 -121
  65. package/dist/lib/agents/agency-agent/tests/settings.test.json +105 -6
  66. package/dist/lib/agents/agency-agent/tests/slots.js +0 -5
  67. package/dist/lib/agents/agency-agent/tests/toolWiring.js +7 -7
  68. package/dist/lib/agents/agency-agent/tests/turnFailure.agency +4 -0
  69. package/dist/lib/agents/agency-agent/tests/turnFailure.js +92 -6
  70. package/dist/lib/agents/agency-agent/tests/turnFailure.test.json +6 -0
  71. package/dist/lib/agents/eval/goalJudge.js +2 -2
  72. package/dist/lib/agents/policy/agent.js +65 -74
  73. package/dist/lib/agents/review/agent.js +4 -5
  74. package/dist/lib/backends/agencyGenerator.d.ts +14 -0
  75. package/dist/lib/backends/agencyGenerator.js +49 -35
  76. package/dist/lib/backends/agencyGenerator.test.js +137 -0
  77. package/dist/lib/backends/raisesFormat.test.js +24 -0
  78. package/dist/lib/backends/recursiveAliases.codegen.test.d.ts +1 -0
  79. package/dist/lib/backends/recursiveAliases.codegen.test.js +229 -0
  80. package/dist/lib/backends/signatureOf.test.d.ts +1 -0
  81. package/dist/lib/backends/signatureOf.test.js +34 -0
  82. package/dist/lib/backends/typeOperators.codegen.test.d.ts +1 -0
  83. package/dist/lib/backends/typeOperators.codegen.test.js +126 -0
  84. package/dist/lib/backends/typescriptBuilder/nameClassifier.d.ts +19 -4
  85. package/dist/lib/backends/typescriptBuilder/nameClassifier.js +40 -14
  86. package/dist/lib/backends/typescriptBuilder/scopeManager.d.ts +6 -6
  87. package/dist/lib/backends/typescriptBuilder/scopeManager.js +9 -9
  88. package/dist/lib/backends/typescriptBuilder.d.ts +21 -0
  89. package/dist/lib/backends/typescriptBuilder.integration.test.js +50 -28
  90. package/dist/lib/backends/typescriptBuilder.js +186 -40
  91. package/dist/lib/backends/typescriptGenerator/recursiveSchemaJson.test.d.ts +1 -0
  92. package/dist/lib/backends/typescriptGenerator/recursiveSchemaJson.test.js +32 -0
  93. package/dist/lib/backends/typescriptGenerator/typeToString.d.ts +6 -0
  94. package/dist/lib/backends/typescriptGenerator/typeToString.js +47 -2
  95. package/dist/lib/backends/typescriptGenerator/typeToZodSchema.d.ts +1 -1
  96. package/dist/lib/backends/typescriptGenerator/typeToZodSchema.js +19 -7
  97. package/dist/lib/backends/typescriptGenerator/validationDescriptor.d.ts +1 -1
  98. package/dist/lib/backends/typescriptGenerator/validationDescriptor.js +41 -20
  99. package/dist/lib/backends/valueParamCycle.d.ts +22 -0
  100. package/dist/lib/backends/valueParamCycle.js +41 -0
  101. package/dist/lib/cli/commands.d.ts +4 -1
  102. package/dist/lib/cli/commands.js +22 -6
  103. package/dist/lib/cli/doc.js +2 -13
  104. package/dist/lib/cli/doc.test.js +13 -0
  105. package/dist/lib/cli/mcp.d.ts +13 -0
  106. package/dist/lib/cli/mcp.js +66 -0
  107. package/dist/lib/cli/mcp.test.d.ts +1 -0
  108. package/dist/lib/cli/mcp.test.js +70 -0
  109. package/dist/lib/cli/runBundledAgent.d.ts +10 -0
  110. package/dist/lib/cli/runBundledAgent.js +47 -18
  111. package/dist/lib/cli/runBundledAgent.test.js +37 -1
  112. package/dist/lib/cli/runPolicy.d.ts +11 -0
  113. package/dist/lib/cli/runPolicy.js +67 -0
  114. package/dist/lib/cli/runPolicy.spawn.test.d.ts +1 -0
  115. package/dist/lib/cli/runPolicy.spawn.test.js +198 -0
  116. package/dist/lib/cli/runPolicy.test.d.ts +1 -0
  117. package/dist/lib/cli/runPolicy.test.js +96 -0
  118. package/dist/lib/cli/serve.js +1 -1
  119. package/dist/lib/cli/test.js +9 -0
  120. package/dist/lib/cli/util.js +14 -0
  121. package/dist/lib/compilationUnit.d.ts +9 -1
  122. package/dist/lib/compilationUnit.js +25 -8
  123. package/dist/lib/compilationUnit.test.js +67 -1
  124. package/dist/lib/compiler/buildManifest.d.ts +40 -0
  125. package/dist/lib/compiler/buildManifest.js +210 -0
  126. package/dist/lib/compiler/buildManifest.test.d.ts +1 -0
  127. package/dist/lib/compiler/buildManifest.test.js +179 -0
  128. package/dist/lib/compiler/buildSession.d.ts +29 -12
  129. package/dist/lib/compiler/buildSession.js +179 -34
  130. package/dist/lib/compiler/buildSession.test.js +206 -22
  131. package/dist/lib/compiler/compile.d.ts +1 -1
  132. package/dist/lib/compiler/compile.js +2 -2
  133. package/dist/lib/compiler/compileClosure.d.ts +10 -0
  134. package/dist/lib/compiler/compileClosure.js +18 -1
  135. package/dist/lib/compiler/compileClosure.test.js +24 -2
  136. package/dist/lib/compiler/manifestTracker.d.ts +33 -0
  137. package/dist/lib/compiler/manifestTracker.js +112 -0
  138. package/dist/lib/compiler/manifestTracker.test.d.ts +1 -0
  139. package/dist/lib/compiler/manifestTracker.test.js +98 -0
  140. package/dist/lib/compiler/typecheck.d.ts +17 -3
  141. package/dist/lib/compiler/typecheck.getEffects.test.d.ts +1 -0
  142. package/dist/lib/compiler/typecheck.getEffects.test.js +35 -0
  143. package/dist/lib/compiler/typecheck.js +43 -11
  144. package/dist/lib/config.d.ts +11 -0
  145. package/dist/lib/config.js +1 -0
  146. package/dist/lib/constants.d.ts +14 -0
  147. package/dist/lib/constants.js +17 -0
  148. package/dist/lib/debugger/driver.test.js +0 -1
  149. package/dist/lib/formatter.test.js +5 -5
  150. package/dist/lib/logsViewer/summary.js +19 -0
  151. package/dist/lib/logsViewer/summary.test.js +61 -0
  152. package/dist/lib/logsViewer/tree.d.ts +10 -0
  153. package/dist/lib/logsViewer/tree.js +58 -4
  154. package/dist/lib/logsViewer/tree.test.js +107 -0
  155. package/dist/lib/lowering/patternLowering.test.js +33 -0
  156. package/dist/lib/lsp/diagnostics.js +0 -1
  157. package/dist/lib/lsp/diagnostics.test.js +1 -1
  158. package/dist/lib/optimize/constraint.js +2 -1
  159. package/dist/lib/optimize/constraint.test.js +9 -7
  160. package/dist/lib/parsers/exportFromStatement.test.js +18 -9
  161. package/dist/lib/parsers/exportNode.test.js +6 -6
  162. package/dist/lib/parsers/expression.test.js +103 -0
  163. package/dist/lib/parsers/function.test.js +60 -68
  164. package/dist/lib/parsers/importStatement.test.js +76 -21
  165. package/dist/lib/parsers/intersectionParsing.test.d.ts +1 -0
  166. package/dist/lib/parsers/intersectionParsing.test.js +90 -0
  167. package/dist/lib/parsers/parsers.d.ts +52 -2
  168. package/dist/lib/parsers/parsers.js +208 -61
  169. package/dist/lib/parsers/typeOperatorParsing.test.d.ts +1 -0
  170. package/dist/lib/parsers/typeOperatorParsing.test.js +107 -0
  171. package/dist/lib/preprocessors/importResolver.js +27 -16
  172. package/dist/lib/preprocessors/importResolver.test.js +6 -11
  173. package/dist/lib/preprocessors/prunePreludeShadows.js +14 -1
  174. package/dist/lib/preprocessors/resolveReExports.js +4 -2
  175. package/dist/lib/preprocessors/resolveReExports.test.js +9 -16
  176. package/dist/lib/runtime/agencyFunction.d.ts +20 -2
  177. package/dist/lib/runtime/agencyFunction.js +39 -9
  178. package/dist/lib/runtime/agencyFunction.test.js +26 -0
  179. package/dist/lib/runtime/agencyInterrupt.d.ts +4 -0
  180. package/dist/lib/runtime/agencyInterrupt.js +1 -1
  181. package/dist/lib/runtime/builtinPolicies.d.ts +11 -0
  182. package/dist/lib/runtime/builtinPolicies.js +139 -0
  183. package/dist/lib/runtime/builtinPolicies.test.d.ts +1 -0
  184. package/dist/lib/runtime/builtinPolicies.test.js +54 -0
  185. package/dist/lib/runtime/call.js +17 -0
  186. package/dist/lib/runtime/configOverrides.d.ts +2 -0
  187. package/dist/lib/runtime/configOverrides.js +5 -0
  188. package/dist/lib/runtime/configOverrides.test.js +24 -0
  189. package/dist/lib/runtime/failurePropagation.d.ts +65 -0
  190. package/dist/lib/runtime/failurePropagation.js +205 -0
  191. package/dist/lib/runtime/failurePropagation.test.d.ts +1 -0
  192. package/dist/lib/runtime/failurePropagation.test.js +381 -0
  193. package/dist/lib/runtime/index.d.ts +5 -3
  194. package/dist/lib/runtime/index.js +4 -2
  195. package/dist/lib/runtime/interrupts.d.ts +16 -7
  196. package/dist/lib/runtime/interrupts.js +24 -2
  197. package/dist/lib/runtime/interrupts.test.js +36 -0
  198. package/dist/lib/runtime/ipc.d.ts +2 -0
  199. package/dist/lib/runtime/ipc.js +3 -8
  200. package/dist/lib/runtime/llmRetry.d.ts +55 -3
  201. package/dist/lib/runtime/llmRetry.js +72 -2
  202. package/dist/lib/runtime/llmRetry.test.js +85 -2
  203. package/dist/lib/runtime/memory/manager.js +0 -2
  204. package/dist/lib/runtime/node.js +6 -0
  205. package/dist/lib/runtime/policy.d.ts +11 -0
  206. package/dist/lib/runtime/policy.js +10 -2
  207. package/dist/lib/runtime/policy.test.js +25 -0
  208. package/dist/lib/runtime/prompt.d.ts +30 -0
  209. package/dist/lib/runtime/prompt.js +453 -267
  210. package/dist/lib/runtime/prompt.test.js +81 -5
  211. package/dist/lib/runtime/result.d.ts +42 -2
  212. package/dist/lib/runtime/result.js +36 -1
  213. package/dist/lib/runtime/result.test.js +45 -6
  214. package/dist/lib/runtime/runPolicyHandler.d.ts +27 -0
  215. package/dist/lib/runtime/runPolicyHandler.js +222 -0
  216. package/dist/lib/runtime/runPolicyHandler.test.d.ts +1 -0
  217. package/dist/lib/runtime/runPolicyHandler.test.js +363 -0
  218. package/dist/lib/runtime/runner.js +37 -30
  219. package/dist/lib/runtime/state/context.d.ts +2 -0
  220. package/dist/lib/runtime/state/context.js +7 -0
  221. package/dist/lib/runtime/threadEndHooksEvents.d.ts +28 -0
  222. package/dist/lib/runtime/threadEndHooksEvents.js +49 -0
  223. package/dist/lib/runtime/threadEndHooksEvents.test.d.ts +1 -0
  224. package/dist/lib/runtime/threadEndHooksEvents.test.js +71 -0
  225. package/dist/lib/runtime/toolBlockDiagnostics.d.ts +3 -1
  226. package/dist/lib/runtime/toolBlockDiagnostics.js +19 -8
  227. package/dist/lib/runtime/truncate.d.ts +6 -0
  228. package/dist/lib/runtime/truncate.js +26 -0
  229. package/dist/lib/runtime/types.d.ts +1 -0
  230. package/dist/lib/runtime/utils.d.ts +8 -0
  231. package/dist/lib/runtime/utils.js +55 -21
  232. package/dist/lib/runtime/utils.test.js +26 -1
  233. package/dist/lib/runtime/validateChain.d.ts +12 -0
  234. package/dist/lib/runtime/validateChain.js +23 -1
  235. package/dist/lib/runtime/validateChain.test.js +77 -0
  236. package/dist/lib/serve/discovery.test.js +0 -2
  237. package/dist/lib/serve/http/adapter.js +4 -1
  238. package/dist/lib/serve/http/adapter.test.js +36 -3
  239. package/dist/lib/serve/mcp/adapter.js +16 -6
  240. package/dist/lib/serve/mcp/adapter.test.js +42 -5
  241. package/dist/lib/serve/mcp/httpTransport.test.js +0 -1
  242. package/dist/lib/statelogClient.d.ts +66 -4
  243. package/dist/lib/statelogClient.js +76 -2
  244. package/dist/lib/statelogClient.test.js +71 -3
  245. package/dist/lib/stdlib/agency.d.ts +1 -0
  246. package/dist/lib/stdlib/agency.js +4 -1
  247. package/dist/lib/stdlib/builtins.js +16 -0
  248. package/dist/lib/stdlib/http.d.ts +6 -6
  249. package/dist/lib/stdlib/http.js +52 -26
  250. package/dist/lib/stdlib/localModels.d.ts +6 -0
  251. package/dist/lib/stdlib/localModels.js +1 -1
  252. package/dist/lib/stdlib/mcp.d.ts +39 -0
  253. package/dist/lib/stdlib/mcp.js +223 -0
  254. package/dist/lib/stdlib/mcpBridge.mjs +71 -0
  255. package/dist/lib/stdlib/mcpGate.d.ts +9 -0
  256. package/dist/lib/stdlib/mcpGate.js +23 -0
  257. package/dist/lib/stdlib/mcpResolver.d.ts +12 -0
  258. package/dist/lib/stdlib/mcpResolver.js +46 -0
  259. package/dist/lib/stdlib/policy.d.ts +1 -0
  260. package/dist/lib/stdlib/policy.js +4 -0
  261. package/dist/lib/stdlib/shell.js +41 -12
  262. package/dist/lib/stdlib/skills.d.ts +7 -0
  263. package/dist/lib/stdlib/skills.js +10 -0
  264. package/dist/lib/stdlib/thread.js +6 -3
  265. package/dist/lib/stdlib/threads.js +13 -0
  266. package/dist/lib/symbolTable.d.ts +2 -2
  267. package/dist/lib/symbolTable.js +22 -10
  268. package/dist/lib/symbolTable.test.js +12 -12
  269. package/dist/lib/templates/backends/typescriptGenerator/functionCatchFailure.d.ts +1 -1
  270. package/dist/lib/templates/backends/typescriptGenerator/functionCatchFailure.js +1 -2
  271. package/dist/lib/templates/backends/typescriptGenerator/imports.d.ts +1 -1
  272. package/dist/lib/templates/backends/typescriptGenerator/imports.js +2 -2
  273. package/dist/lib/templates/backends/typescriptGenerator/interruptAssignment.d.ts +1 -1
  274. package/dist/lib/templates/backends/typescriptGenerator/interruptAssignment.js +5 -5
  275. package/dist/lib/templates/backends/typescriptGenerator/interruptReturn.d.ts +1 -1
  276. package/dist/lib/templates/backends/typescriptGenerator/interruptReturn.js +4 -4
  277. package/dist/lib/typeChecker/assignability.js +87 -68
  278. package/dist/lib/typeChecker/builtinGenerics.d.ts +64 -0
  279. package/dist/lib/typeChecker/builtinGenerics.js +226 -0
  280. package/dist/lib/typeChecker/builtinGenerics.test.d.ts +1 -0
  281. package/dist/lib/typeChecker/builtinGenerics.test.js +540 -0
  282. package/dist/lib/typeChecker/builtinNamedArgs.test.js +12 -0
  283. package/dist/lib/typeChecker/builtins.js +3 -0
  284. package/dist/lib/typeChecker/callbackCallEffects.test.d.ts +1 -0
  285. package/dist/lib/typeChecker/callbackCallEffects.test.js +42 -0
  286. package/dist/lib/typeChecker/checker.d.ts +3 -3
  287. package/dist/lib/typeChecker/checker.js +51 -67
  288. package/dist/lib/typeChecker/conflictingMarkers.d.ts +9 -0
  289. package/dist/lib/typeChecker/conflictingMarkers.js +17 -0
  290. package/dist/lib/typeChecker/conflictingMarkers.test.d.ts +1 -0
  291. package/dist/lib/typeChecker/conflictingMarkers.test.js +22 -0
  292. package/dist/lib/typeChecker/definiteReturns.js +3 -6
  293. package/dist/lib/typeChecker/diagnosticLocations.test.d.ts +1 -0
  294. package/dist/lib/typeChecker/diagnosticLocations.test.js +41 -0
  295. package/dist/lib/typeChecker/diagnostics.d.ts +483 -0
  296. package/dist/lib/typeChecker/diagnostics.js +486 -0
  297. package/dist/lib/typeChecker/diagnostics.test.d.ts +1 -0
  298. package/dist/lib/typeChecker/diagnostics.test.js +83 -0
  299. package/dist/lib/typeChecker/effectPayloadCheck.js +9 -37
  300. package/dist/lib/typeChecker/flow.d.ts +34 -19
  301. package/dist/lib/typeChecker/flow.js +32 -14
  302. package/dist/lib/typeChecker/flow.test.js +104 -3
  303. package/dist/lib/typeChecker/flowBuilder.js +15 -2
  304. package/dist/lib/typeChecker/flowBuilder.test.js +29 -3
  305. package/dist/lib/typeChecker/formatErrors.test.d.ts +1 -0
  306. package/dist/lib/typeChecker/formatErrors.test.js +64 -0
  307. package/dist/lib/typeChecker/functionTypeRaises.d.ts +18 -0
  308. package/dist/lib/typeChecker/functionTypeRaises.js +141 -0
  309. package/dist/lib/typeChecker/functionTypeRaises.test.d.ts +1 -0
  310. package/dist/lib/typeChecker/functionTypeRaises.test.js +94 -0
  311. package/dist/lib/typeChecker/functionValueEffects.d.ts +14 -0
  312. package/dist/lib/typeChecker/functionValueEffects.js +60 -0
  313. package/dist/lib/typeChecker/handlerParamTyping.js +12 -3
  314. package/dist/lib/typeChecker/handlerParamTyping.test.js +7 -0
  315. package/dist/lib/typeChecker/index.d.ts +31 -1
  316. package/dist/lib/typeChecker/index.js +164 -112
  317. package/dist/lib/typeChecker/interruptAnalysis.js +36 -27
  318. package/dist/lib/typeChecker/matchExhaustiveness.js +2 -5
  319. package/dist/lib/typeChecker/matchExprTypes.js +11 -7
  320. package/dist/lib/typeChecker/matchExpression.test.js +36 -0
  321. package/dist/lib/typeChecker/nullLiteralSynth.test.d.ts +1 -0
  322. package/dist/lib/typeChecker/nullLiteralSynth.test.js +36 -0
  323. package/dist/lib/typeChecker/paramAcceptsFailure.test.d.ts +1 -0
  324. package/dist/lib/typeChecker/paramAcceptsFailure.test.js +35 -0
  325. package/dist/lib/typeChecker/raisesDiagnostic.js +3 -12
  326. package/dist/lib/typeChecker/recursiveAssignability.test.d.ts +1 -0
  327. package/dist/lib/typeChecker/recursiveAssignability.test.js +94 -0
  328. package/dist/lib/typeChecker/resultUnion.js +19 -1
  329. package/dist/lib/typeChecker/schemaType.test.js +26 -0
  330. package/dist/lib/typeChecker/scope.d.ts +25 -1
  331. package/dist/lib/typeChecker/scope.js +37 -2
  332. package/dist/lib/typeChecker/scope.test.js +56 -0
  333. package/dist/lib/typeChecker/scopes.js +13 -36
  334. package/dist/lib/typeChecker/staticInitRules.d.ts +1 -24
  335. package/dist/lib/typeChecker/staticInitRules.js +43 -28
  336. package/dist/lib/typeChecker/strictMemberAccess.test.js +34 -0
  337. package/dist/lib/typeChecker/suppression.d.ts +19 -10
  338. package/dist/lib/typeChecker/suppression.js +64 -14
  339. package/dist/lib/typeChecker/suppression.test.js +80 -13
  340. package/dist/lib/typeChecker/synthesizer.js +86 -72
  341. package/dist/lib/typeChecker/toolBlockBinding.d.ts +0 -23
  342. package/dist/lib/typeChecker/toolBlockBinding.js +44 -14
  343. package/dist/lib/typeChecker/typeKey.d.ts +24 -0
  344. package/dist/lib/typeChecker/typeKey.js +90 -0
  345. package/dist/lib/typeChecker/typeKey.test.d.ts +1 -0
  346. package/dist/lib/typeChecker/typeKey.test.js +165 -0
  347. package/dist/lib/typeChecker/typeOperators.d.ts +37 -0
  348. package/dist/lib/typeChecker/typeOperators.js +110 -0
  349. package/dist/lib/typeChecker/typeOperators.test.d.ts +1 -0
  350. package/dist/lib/typeChecker/typeOperators.test.js +491 -0
  351. package/dist/lib/typeChecker/typeWalker.js +21 -0
  352. package/dist/lib/typeChecker/types.d.ts +14 -5
  353. package/dist/lib/typeChecker/undefinedFunctionDiagnostic.js +13 -24
  354. package/dist/lib/typeChecker/undefinedVariableDiagnostic.js +3 -4
  355. package/dist/lib/typeChecker/utils.d.ts +17 -1
  356. package/dist/lib/typeChecker/utils.js +54 -23
  357. package/dist/lib/typeChecker/validate.js +48 -50
  358. package/dist/lib/typeChecker/validateStaticInit.js +1 -1
  359. package/dist/lib/typeChecker/valueParamSubstitution.js +27 -0
  360. package/dist/lib/typeChecker/variadicNamedBinding.test.js +5 -5
  361. package/dist/lib/typeChecker.test.js +60 -62
  362. package/dist/lib/types/exportFromStatement.d.ts +4 -2
  363. package/dist/lib/types/function.d.ts +12 -1
  364. package/dist/lib/types/importStatement.d.ts +5 -2
  365. package/dist/lib/types/importStatement.js +0 -3
  366. package/dist/lib/types/typeHints.d.ts +51 -3
  367. package/dist/lib/utils/bodySlots.d.ts +36 -0
  368. package/dist/lib/utils/bodySlots.js +120 -0
  369. package/dist/lib/utils/formatType.js +48 -3
  370. package/dist/lib/utils/formatType.test.d.ts +1 -0
  371. package/dist/lib/utils/formatType.test.js +65 -0
  372. package/dist/lib/utils/mapBodies.d.ts +10 -10
  373. package/dist/lib/utils/mapBodies.js +11 -45
  374. package/dist/lib/utils/node.js +35 -50
  375. package/dist/scripts/agency.js +57 -4
  376. package/dist/scripts/stage-agents.test.d.ts +1 -0
  377. package/dist/scripts/stage-agents.test.js +74 -0
  378. package/dist/scripts/stdlib-stamp.d.ts +1 -0
  379. package/dist/scripts/stdlib-stamp.js +31 -0
  380. package/package.json +2 -4
  381. package/stdlib/agency/eval.js +91 -87
  382. package/stdlib/agency/local.js +73 -96
  383. package/stdlib/agency.agency +436 -38
  384. package/stdlib/agency.js +3023 -350
  385. package/stdlib/agent.agency +6 -6
  386. package/stdlib/agent.js +97 -107
  387. package/stdlib/args.agency +74 -0
  388. package/stdlib/args.js +8 -9
  389. package/stdlib/array.js +107 -118
  390. package/stdlib/auth/keyring.agency +4 -4
  391. package/stdlib/auth/keyring.js +47 -39
  392. package/stdlib/auth/oauth.agency +2 -2
  393. package/stdlib/auth/oauth.js +50 -42
  394. package/stdlib/calendar.agency +4 -4
  395. package/stdlib/calendar.js +94 -71
  396. package/stdlib/capabilities.agency +1 -1
  397. package/stdlib/capabilities.js +1 -1
  398. package/stdlib/clipboard.agency +2 -2
  399. package/stdlib/clipboard.js +20 -19
  400. package/stdlib/concurrency.js +13 -11
  401. package/stdlib/data/finance/dbnomics.agency +4 -4
  402. package/stdlib/data/finance/dbnomics.js +35 -34
  403. package/stdlib/data/finance/edgar.agency +7 -7
  404. package/stdlib/data/finance/edgar.js +73 -66
  405. package/stdlib/data/finance/fred.agency +9 -9
  406. package/stdlib/data/finance/fred.js +97 -90
  407. package/stdlib/data/finance/gdelt.agency +4 -4
  408. package/stdlib/data/finance/gdelt.js +35 -34
  409. package/stdlib/data/people/littlesis.agency +19 -19
  410. package/stdlib/data/people/littlesis.js +137 -148
  411. package/stdlib/data/tech/hackernews.agency +23 -23
  412. package/stdlib/data/tech/hackernews.js +173 -182
  413. package/stdlib/data/tech/yc.agency +19 -19
  414. package/stdlib/data/tech/yc.js +119 -140
  415. package/stdlib/data/usaspending.agency +263 -0
  416. package/stdlib/data/usaspending.js +2281 -0
  417. package/stdlib/data/wikidata.agency +17 -17
  418. package/stdlib/data/wikidata.js +121 -131
  419. package/stdlib/date.agency +15 -15
  420. package/stdlib/date.js +117 -118
  421. package/stdlib/docs/cli/agent.md +32 -0
  422. package/stdlib/docs/guide/agency-vs-typescript.md +30 -0
  423. package/stdlib/docs/guide/build-integration.md +106 -0
  424. package/{dist/lib/agents → stdlib}/docs/guide/builtins.md +6 -7
  425. package/stdlib/docs/guide/cross-thread-context.md +178 -0
  426. package/{dist/lib/agents → stdlib}/docs/guide/custom-providers.md +8 -1
  427. package/{dist/lib/agents → stdlib}/docs/guide/error-handling.md +21 -0
  428. package/stdlib/docs/guide/llm-part-2.md +145 -0
  429. package/{dist/lib/agents → stdlib}/docs/guide/mcp.md +13 -45
  430. package/{dist/lib/agents → stdlib}/docs/guide/memory.md +2 -0
  431. package/{dist/lib/agents/docs/guide/advanced-types.md → stdlib/docs/guide/notes-on-types.md} +2 -2
  432. package/{dist/lib/agents → stdlib}/docs/guide/policies.md +27 -1
  433. package/{dist/lib/agents → stdlib}/docs/guide/schema-parameter-injection.md +2 -0
  434. package/{dist/lib/agents → stdlib}/docs/guide/serving.md +23 -35
  435. package/stdlib/docs/guide/tags.md +66 -0
  436. package/{dist/lib/agents → stdlib}/docs/guide/ts-helpers.md +2 -0
  437. package/{dist/lib/agents → stdlib}/docs/guide/types.md +93 -0
  438. package/{dist/lib/agents → stdlib}/docs/guide/vscode-extension.md +2 -2
  439. package/stdlib/fs.agency +6 -6
  440. package/stdlib/fs.js +152 -97
  441. package/stdlib/git.agency +17 -17
  442. package/stdlib/git.js +293 -245
  443. package/stdlib/http.agency +31 -15
  444. package/stdlib/http.js +154 -58
  445. package/stdlib/image.js +21 -15
  446. package/stdlib/index.agency +12 -12
  447. package/stdlib/index.js +244 -226
  448. package/stdlib/llm.agency +5 -2
  449. package/stdlib/llm.js +57 -71
  450. package/stdlib/markdown.agency +4 -4
  451. package/stdlib/markdown.js +27 -29
  452. package/stdlib/math.agency +5 -5
  453. package/stdlib/math.js +41 -40
  454. package/stdlib/mcp.agency +53 -0
  455. package/stdlib/mcp.js +811 -0
  456. package/stdlib/memory.agency +23 -9
  457. package/stdlib/memory.js +128 -112
  458. package/stdlib/messaging/email.agency +3 -3
  459. package/stdlib/messaging/email.js +104 -62
  460. package/stdlib/messaging/imessage.agency +1 -1
  461. package/stdlib/messaging/imessage.js +20 -13
  462. package/stdlib/messaging/sms.agency +1 -1
  463. package/stdlib/messaging/sms.js +26 -16
  464. package/stdlib/object.agency +3 -3
  465. package/stdlib/object.js +59 -61
  466. package/stdlib/path.agency +7 -7
  467. package/stdlib/path.js +47 -51
  468. package/stdlib/policy.agency +36 -0
  469. package/stdlib/policy.js +523 -142
  470. package/stdlib/shell.agency +8 -8
  471. package/stdlib/shell.js +160 -112
  472. package/stdlib/skills.agency +34 -12
  473. package/stdlib/skills.js +368 -118
  474. package/stdlib/speech.js +41 -38
  475. package/stdlib/statelog.agency +5 -5
  476. package/stdlib/statelog.js +51 -55
  477. package/stdlib/strategy.js +53 -51
  478. package/stdlib/syntax.agency +4 -4
  479. package/stdlib/syntax.js +63 -47
  480. package/stdlib/system.agency +6 -6
  481. package/stdlib/system.js +87 -100
  482. package/stdlib/tag.js +45 -52
  483. package/stdlib/thread.agency +20 -14
  484. package/stdlib/thread.js +132 -130
  485. package/stdlib/ui/chart.agency +1 -1
  486. package/stdlib/ui/chart.js +53 -42
  487. package/stdlib/ui/cli.agency +2 -2
  488. package/stdlib/ui/cli.js +47 -56
  489. package/stdlib/ui/layout.agency +9 -9
  490. package/stdlib/ui/layout.js +259 -201
  491. package/stdlib/ui/table.agency +1 -1
  492. package/stdlib/ui/table.js +83 -69
  493. package/stdlib/ui.agency +6 -6
  494. package/stdlib/ui.js +649 -596
  495. package/stdlib/validation.agency +11 -11
  496. package/stdlib/validation.js +77 -82
  497. package/stdlib/weather.agency +3 -3
  498. package/stdlib/weather.js +23 -24
  499. package/stdlib/web/browser.js +21 -15
  500. package/stdlib/web/search.agency +2 -2
  501. package/stdlib/web/search.js +37 -28
  502. package/stdlib/wikipedia.agency +3 -3
  503. package/stdlib/wikipedia.js +27 -28
  504. package/dist/lib/agents/agency-agent/lib/defaultPolicy.agency +0 -227
  505. package/dist/lib/agents/docs/cli/agent.md +0 -16
  506. package/dist/lib/agents/docs/guide/agency-vs-typescript.md +0 -33
  507. package/dist/lib/agents/docs/guide/build-integration.md +0 -99
  508. package/dist/lib/agents/docs/guide/cli-args.md +0 -190
  509. package/dist/lib/agents/docs/guide/cross-thread-context.md +0 -226
  510. package/dist/lib/agents/docs/guide/llm-part-2.md +0 -111
  511. package/dist/lib/agents/docs/guide/tags.md +0 -72
  512. /package/{dist/lib/agents → stdlib}/docs/cli/compile.md +0 -0
  513. /package/{dist/lib/agents → stdlib}/docs/cli/coverage.md +0 -0
  514. /package/{dist/lib/agents → stdlib}/docs/cli/debug.md +0 -0
  515. /package/{dist/lib/agents → stdlib}/docs/cli/doc.md +0 -0
  516. /package/{dist/lib/agents → stdlib}/docs/cli/editor-integration.md +0 -0
  517. /package/{dist/lib/agents → stdlib}/docs/cli/eval-judge.md +0 -0
  518. /package/{dist/lib/agents → stdlib}/docs/cli/eval.md +0 -0
  519. /package/{dist/lib/agents → stdlib}/docs/cli/format.md +0 -0
  520. /package/{dist/lib/agents → stdlib}/docs/cli/index.md +0 -0
  521. /package/{dist/lib/agents → stdlib}/docs/cli/local.md +0 -0
  522. /package/{dist/lib/agents → stdlib}/docs/cli/models.md +0 -0
  523. /package/{dist/lib/agents → stdlib}/docs/cli/optimize.md +0 -0
  524. /package/{dist/lib/agents → stdlib}/docs/cli/pack.md +0 -0
  525. /package/{dist/lib/agents → stdlib}/docs/cli/policy.md +0 -0
  526. /package/{dist/lib/agents → stdlib}/docs/cli/preprocess-and-ast.md +0 -0
  527. /package/{dist/lib/agents → stdlib}/docs/cli/review.md +0 -0
  528. /package/{dist/lib/agents → stdlib}/docs/cli/run.md +0 -0
  529. /package/{dist/lib/agents → stdlib}/docs/cli/schedule.md +0 -0
  530. /package/{dist/lib/agents → stdlib}/docs/cli/serve.md +0 -0
  531. /package/{dist/lib/agents → stdlib}/docs/cli/test.md +0 -0
  532. /package/{dist/lib/agents → stdlib}/docs/cli/trace-and-bundle.md +0 -0
  533. /package/{dist/lib/agents → stdlib}/docs/cli/typecheck.md +0 -0
  534. /package/{dist/lib/agents → stdlib}/docs/guide/agency-config-file.md +0 -0
  535. /package/{dist/lib/agents → stdlib}/docs/guide/agency-packages.md +0 -0
  536. /package/{dist/lib/agents → stdlib}/docs/guide/agency-stdlib.md +0 -0
  537. /package/{dist/lib/agents → stdlib}/docs/guide/attachments.md +0 -0
  538. /package/{dist/lib/agents → stdlib}/docs/guide/basic-syntax.md +0 -0
  539. /package/{dist/lib/agents → stdlib}/docs/guide/blocks.md +0 -0
  540. /package/{dist/lib/agents → stdlib}/docs/guide/callbacks.md +0 -0
  541. /package/{dist/lib/agents → stdlib}/docs/guide/checkpointing.md +0 -0
  542. /package/{dist/lib/agents → stdlib}/docs/guide/common-functions.md +0 -0
  543. /package/{dist/lib/agents → stdlib}/docs/guide/compiling-and-running.md +0 -0
  544. /package/{dist/lib/agents → stdlib}/docs/guide/concurrency.md +0 -0
  545. /package/{dist/lib/agents → stdlib}/docs/guide/debugging.md +0 -0
  546. /package/{dist/lib/agents → stdlib}/docs/guide/developer-tools.md +0 -0
  547. /package/{dist/lib/agents → stdlib}/docs/guide/effects-and-raises.md +0 -0
  548. /package/{dist/lib/agents → stdlib}/docs/guide/effects.md +0 -0
  549. /package/{dist/lib/agents → stdlib}/docs/guide/exercise-1.md +0 -0
  550. /package/{dist/lib/agents → stdlib}/docs/guide/functions.md +0 -0
  551. /package/{dist/lib/agents → stdlib}/docs/guide/getting-started.md +0 -0
  552. /package/{dist/lib/agents → stdlib}/docs/guide/global-var-initialization.md +0 -0
  553. /package/{dist/lib/agents → stdlib}/docs/guide/global-vs-static.md +0 -0
  554. /package/{dist/lib/agents → stdlib}/docs/guide/guards.md +0 -0
  555. /package/{dist/lib/agents → stdlib}/docs/guide/handlers.md +0 -0
  556. /package/{dist/lib/agents → stdlib}/docs/guide/image-generation.md +0 -0
  557. /package/{dist/lib/agents → stdlib}/docs/guide/imports-and-packages.md +0 -0
  558. /package/{dist/lib/agents → stdlib}/docs/guide/interrupts-from-typescript.md +0 -0
  559. /package/{dist/lib/agents → stdlib}/docs/guide/interrupts-part-2.md +0 -0
  560. /package/{dist/lib/agents → stdlib}/docs/guide/interrupts.md +0 -0
  561. /package/{dist/lib/agents → stdlib}/docs/guide/llm.md +0 -0
  562. /package/{dist/lib/agents → stdlib}/docs/guide/message-threads.md +0 -0
  563. /package/{dist/lib/agents → stdlib}/docs/guide/nodes.md +0 -0
  564. /package/{dist/lib/agents → stdlib}/docs/guide/observability.md +0 -0
  565. /package/{dist/lib/agents → stdlib}/docs/guide/partial-application.md +0 -0
  566. /package/{dist/lib/agents → stdlib}/docs/guide/pattern-matching.md +0 -0
  567. /package/{dist/lib/agents → stdlib}/docs/guide/schemas.md +0 -0
  568. /package/{dist/lib/agents → stdlib}/docs/guide/state-isolation.md +0 -0
  569. /package/{dist/lib/agents → stdlib}/docs/guide/streaming.md +0 -0
  570. /package/{dist/lib/agents → stdlib}/docs/guide/testing.md +0 -0
  571. /package/{dist/lib/agents → stdlib}/docs/guide/troubleshooting.md +0 -0
  572. /package/{dist/lib/agents → stdlib}/docs/guide/ts-interop.md +0 -0
  573. /package/{dist/lib/agents → stdlib}/docs/guide/type-validation.md +0 -0
  574. /package/{dist/lib/agents → stdlib}/docs/guide/unused.md +0 -0
  575. /package/{dist/lib/agents → stdlib}/docs/guide/unused2.md +0 -0
  576. /package/{dist/lib/agents → stdlib}/docs/guide/value-parameterized-types.md +0 -0
  577. /package/{dist/lib/agents → stdlib}/docs/guide/why-agency.md +0 -0
@@ -18,7 +18,13 @@ import {
18
18
  cliPolicyHandler,
19
19
  parsePolicyFile,
20
20
  setPolicy,
21
+ minimalAutoApprovePolicy,
22
+ recommendedAutoApprovePolicy,
23
+ builtinPolicy,
24
+ builtinPolicyNames,
25
+ BUILTIN_POLICIES,
21
26
  } from "std::policy"
27
+ import { loadMcpToolsWithStatus, mergeMcpServers, isMcpAvailable, readProjectMcpConfig } from "std::mcp"
22
28
  import { exists } from "std::shell"
23
29
  import { commandsDir, expandSlash } from "std::skills"
24
30
  import { highlight } from "std::syntax"
@@ -49,15 +55,9 @@ import {
49
55
  HISTORY_PATH,
50
56
  ALWAYS_FIELDS,
51
57
  } from "./lib/config.agency"
52
- import {
53
- minimalAutoApprovePolicy,
54
- recommendedAutoApprovePolicy,
55
- builtinPolicy,
56
- builtinPolicyNames,
57
- BUILTIN_POLICIES,
58
- } from "./lib/defaultPolicy.agency"
59
58
  import { filterHostedModels, ModelFilters } from "./lib/modelFilters.agency"
60
- import { parseModelFlag, knownProviders, Resolved } from "./lib/models.agency"
59
+ import { parseModelFlag, parseModelSpec, knownProviders, embeddingSpecHasProvider, missingProviderEnvVar, Resolved } from "./lib/models.agency"
60
+ import { SLOTS } from "./lib/slots.agency"
61
61
  import {
62
62
  buildLayers,
63
63
  resolveAll,
@@ -71,7 +71,21 @@ import {
71
71
  getSearchBackend,
72
72
  availableBackendItems,
73
73
  } from "./lib/search.agency"
74
- import { getModelSettings, loadSettings } from "./lib/settings.agency"
74
+ import {
75
+ CAPABILITY_FIELDS,
76
+ CapabilityPatch,
77
+ mergeCapabilityOverride,
78
+ removeCapabilityField,
79
+ providerLacksEmbeddings,
80
+ } from "./lib/capabilities.agency"
81
+ import {
82
+ Settings,
83
+ getCapabilitySettings,
84
+ getModelSettings,
85
+ getMcpServers,
86
+ loadSettings,
87
+ saveSettings,
88
+ } from "./lib/settings.agency"
75
89
  import { truncate, formatArgs, formatToolResponse } from "./lib/utils.agency"
76
90
  import {
77
91
  configureModels,
@@ -82,6 +96,17 @@ import {
82
96
  promoteAll,
83
97
  currentProvider,
84
98
  resolveMaxToolCallRounds,
99
+ getCapabilities,
100
+ getCapabilitiesResolved,
101
+ getCapabilityModelKey,
102
+ getCapabilityProvider,
103
+ refreshCapabilities,
104
+ embeddingKeyStatus,
105
+ memoryEnablePlan,
106
+ overrideFromResolved,
107
+ embeddingsOverride,
108
+ providerEnvMissing,
109
+ demoteProvider,
85
110
  } from "./shared.agency"
86
111
  import { codeAgent, setCodeOneShot } from "./subagents/code.agency"
87
112
  import { explorerAgent } from "./subagents/explorer.agency"
@@ -211,6 +236,9 @@ export def retryReasonLabel(reason: string): string {
211
236
  if (reason == "serverError") {
212
237
  return "Server error"
213
238
  }
239
+ if (reason == "invalidStructuredOutput") {
240
+ return "Output failed validation"
241
+ }
214
242
  return reason
215
243
  }
216
244
 
@@ -314,6 +342,8 @@ def builtinPalette(): Record<string, string> {
314
342
  "/models": "List / filter the hosted model catalog",
315
343
  "/local": "Switch to a local model",
316
344
  "/search": "Choose the web search backend (hosted / Tavily / Brave / off)",
345
+ "/settings": "View and change capability settings for the current model",
346
+ "/mcp": "List configured MCP servers and their tools",
317
347
  "/paste": "Multi-line paste mode (Ctrl+D submits, Ctrl+C cancels)",
318
348
  "/help": "Show available slash commands"
319
349
  }
@@ -361,6 +391,15 @@ export def switchModel(
361
391
  ctx: Ctx,
362
392
  before: Record<string, Resolved>,
363
393
  ): { session: Session; resolved: Record<string, Resolved>; changes: SlotChange[] } {
394
+ // The caller builds ctx from currentProvider(), which returns the
395
+ // PROMOTED name on openai sessions. priceDefault and the built-in
396
+ // tables key by public provider names, so demote before resolving —
397
+ // otherwise a switch that lets any slot fall through to the built-in
398
+ // defaults fails with "openai-responses has no built-in defaults".
399
+ const ctx2: Ctx = {
400
+ provider: demoteProvider(ctx.provider),
401
+ price: ctx.price
402
+ }
364
403
  let nextSlots: Record<string, string> = {}
365
404
  for (key in Object.keys(prior.slots)) {
366
405
  nextSlots[key] = prior.slots[key]
@@ -370,9 +409,23 @@ export def switchModel(
370
409
  slots: nextSlots
371
410
  }
372
411
  const parsed = parseModelFlag(spec)
373
- if (parsed.slot != "" && parsed.slot != "main" && parsed.slot != "reasoning") {
412
+ if (parsed.slot != "" && !SLOTS.includes(parsed.slot)) {
374
413
  pushMessage(
375
- color.red("Unknown model slot '${parsed.slot}'. Valid slots: main, reasoning."),
414
+ color.red("Unknown model slot '${parsed.slot}'. Valid slots: ${SLOTS.join(", ")}."),
415
+ )
416
+ return {
417
+ session: prior,
418
+ resolved: before,
419
+ changes: []
420
+ }
421
+ }
422
+ if (parsed.slot == "embedding" && !embeddingSpecHasProvider(parsed.model)) {
423
+ // The embedding slot exists to point AWAY from the chat provider, so
424
+ // the provider can never be inferred. Require the explicit form.
425
+ pushMessage(
426
+ color.red(
427
+ "Embedding models need the provider/model form, e.g. embedding=openai/text-embedding-3-small.",
428
+ ),
376
429
  )
377
430
  return {
378
431
  session: prior,
@@ -399,7 +452,7 @@ export def switchModel(
399
452
  knownProviders(),
400
453
  providerEstablished,
401
454
  )
402
- const all = resolveAll(layers, ctx)
455
+ const all = resolveAll(layers, ctx2)
403
456
  if (isFailure(all)) {
404
457
  pushMessage(color.red("Could not switch model: ${all.error}"))
405
458
  return {
@@ -423,6 +476,13 @@ export def switchModel(
423
476
  returns when a selective toggle lands.) Returns true if it emitted the notice. */
424
477
  export def reactToSlotChange(change: SlotChange): boolean {
425
478
  if (change.slot == "main" && change.before.provider != change.after.provider) {
479
+ // Skip the pause only when startup actually enabled memory WITH the
480
+ // override. A set-but-keyless slot took the fallback path, so memory
481
+ // runs on derived embeddings and the provider change still shifts
482
+ // the embedding space behind recall.
483
+ if (_memoryEmbeddingsPinned) {
484
+ return false
485
+ }
426
486
  pushMessage(
427
487
  color.dim(
428
488
  "Warning: provider changed - memory is paused until restart (recall would be unreliable).",
@@ -433,6 +493,28 @@ export def reactToSlotChange(change: SlotChange): boolean {
433
493
  disableMemory() with approve
434
494
  return true
435
495
  }
496
+ if (change.slot == "embedding") {
497
+ const override = overrideFromResolved(change.after)
498
+ if (override != null) {
499
+ const missing = missingProviderEnvVar(override.provider)
500
+ if (missing != "") {
501
+ pushMessage(
502
+ color.yellow(
503
+ "Warning: the embedding slot needs ${missing}, which is not set. The assignment takes effect at next agent start, and memory falls back to the default embedding behavior until it is exported.",
504
+ ),
505
+ )
506
+ return true
507
+ }
508
+ // The healthy path must not be silent: enableMemory already ran,
509
+ // so the user would otherwise believe embeddings switched now.
510
+ pushMessage(
511
+ color.dim(
512
+ "Embedding slot set: memory embeddings use ${override.provider}/${override.model} at next agent start.",
513
+ ),
514
+ )
515
+ return true
516
+ }
517
+ }
436
518
  return false
437
519
  }
438
520
 
@@ -467,6 +549,290 @@ export def parseModelsFilters(cmd: string): ModelFilters {
467
549
  }
468
550
  }
469
551
 
552
+ /** Human label for a capability source layer. Interprets the source
553
+ strings resolveCapabilities emits (capabilities.agency). */
554
+ def capabilitySourceLabel(source: string): string {
555
+ if (source == "default") {
556
+ return "built-in default"
557
+ }
558
+ if (source == "provider") {
559
+ return "provider default: ${getCapabilityProvider()}"
560
+ }
561
+ if (source == "model") {
562
+ return "built-in for ${getCapabilityModelKey()}"
563
+ }
564
+ if (source == "user-global") {
565
+ return "your global override"
566
+ }
567
+ if (source == "user-provider") {
568
+ return "your override for ${getCapabilityProvider()}"
569
+ }
570
+ return "your override for ${getCapabilityModelKey()}"
571
+ }
572
+
573
+ /** One "value (source)" cell. The typed Capabilities shape cannot be
574
+ indexed by a dynamic key, so this is the renderer's per-field switch. */
575
+ def capabilityRow(fieldKey: string): string {
576
+ const resolved = getCapabilitiesResolved()
577
+ const values = resolved.values
578
+ const sources = resolved.sources
579
+ if (fieldKey == "prompt") {
580
+ return "${values.prompt} (${capabilitySourceLabel(sources.prompt)})"
581
+ }
582
+ if (fieldKey == "summarize") {
583
+ return "${values.summarize} (${capabilitySourceLabel(sources.summarize)})"
584
+ }
585
+ if (fieldKey == "memory") {
586
+ return "${values.memory} (${capabilitySourceLabel(sources.memory)})"
587
+ }
588
+ let cap = "none"
589
+ if (values.maxTokens != null) {
590
+ cap = "${values.maxTokens}"
591
+ }
592
+ return "${cap} (${capabilitySourceLabel(sources.maxTokens)})"
593
+ }
594
+
595
+ /** Render the current profile with per-field provenance. */
596
+ def showCapabilities() {
597
+ pushMessage("Capabilities for ${getCapabilityModelKey()} (${getCapabilityProvider()}):")
598
+ for (field in CAPABILITY_FIELDS) {
599
+ pushMessage(" ${field.label} ${capabilityRow(field.key)}")
600
+ }
601
+ }
602
+
603
+ /** The settings.json key a scope writes under. Global's key is unused. */
604
+ def scopeTargetName(scopeKey: string): string {
605
+ if (scopeKey == "provider") {
606
+ return getCapabilityProvider()
607
+ }
608
+ return getCapabilityModelKey()
609
+ }
610
+
611
+ /** Persist one override patch at a scope, then re-resolve. */
612
+ def saveCapabilityOverride(scopeKey: string, patch: CapabilityPatch) {
613
+ let settings = loadSettings()
614
+ settings.capabilities = mergeCapabilityOverride(
615
+ getCapabilitySettings(settings),
616
+ scopeKey,
617
+ scopeTargetName(scopeKey),
618
+ patch,
619
+ )
620
+ saveSettings(settings)
621
+ refreshCapabilities(getCapabilityModelKey(), getCapabilityProvider())
622
+ }
623
+
624
+ /** Remove one field override at a scope, then re-resolve. */
625
+ def removeCapabilityOverride(scopeKey: string, fieldKey: string) {
626
+ let settings = loadSettings()
627
+ settings.capabilities = removeCapabilityField(
628
+ getCapabilitySettings(settings),
629
+ scopeKey,
630
+ scopeTargetName(scopeKey),
631
+ fieldKey,
632
+ )
633
+ saveSettings(settings)
634
+ refreshCapabilities(getCapabilityModelKey(), getCapabilityProvider())
635
+ }
636
+
637
+ /** Ask which scope an override applies to. Returns "" on cancel. */
638
+ def pickOverrideScope(): string {
639
+ let scopeItems: ChoiceItem[] = []
640
+ scopeItems.push({
641
+ key: "model",
642
+ label: "this model (${getCapabilityModelKey()})"
643
+ })
644
+ scopeItems.push({
645
+ key: "provider",
646
+ label: "this provider (${getCapabilityProvider()})"
647
+ })
648
+ scopeItems.push({
649
+ key: "global",
650
+ label: "all models"
651
+ })
652
+ const scopeKey = chooseOption("Scope", "Where should this apply?", scopeItems, allowCancel: true)
653
+ if (scopeKey == null) {
654
+ return ""
655
+ }
656
+ return scopeKey
657
+ }
658
+
659
+ /** Re-apply the resolved cap as the branch default. After a reset the
660
+ resolved value falls back to a built-in layer, which is always numeric
661
+ for known providers, so live-apply covers removal too. */
662
+ def applyLiveMaxTokens() {
663
+ const capValue = getCapabilities().maxTokens
664
+ if (capValue != null) {
665
+ setLlmOptions({ maxTokens: capValue })
666
+ }
667
+ }
668
+
669
+ /** Positive-integer parse. parseInt and isNaN appear nowhere in the
670
+ repo's .agency code, so this uses a digits check instead. Returns -1
671
+ for anything that is not all digits. */
672
+ def parsePositiveInt(text: string): number {
673
+ // Bound to a const because the parser rejects method calls on string
674
+ // LITERALS ("0123456789".includes(...) does not parse; a variable does).
675
+ const digits = "0123456789"
676
+ const trimmed = text.trim()
677
+ if (trimmed == "") {
678
+ return -1
679
+ }
680
+ for (ch in trimmed.split("")) {
681
+ if (!digits.includes(ch)) {
682
+ return -1
683
+ }
684
+ }
685
+ return Number(trimmed)
686
+ }
687
+
688
+ /** Interactive edit: field → value → scope → save → live-apply. */
689
+ def editCapabilities() {
690
+ let fieldItems: ChoiceItem[] = []
691
+ for (field in CAPABILITY_FIELDS) {
692
+ fieldItems.push({
693
+ key: field.key,
694
+ label: "${field.label} — ${field.description}"
695
+ })
696
+ }
697
+ const fieldKey = chooseOption(
698
+ "Settings",
699
+ "Pick a setting to change (empty to exit).",
700
+ fieldItems,
701
+ allowCancel: true,
702
+ )
703
+ if (fieldKey == "" || fieldKey == null) {
704
+ return
705
+ }
706
+
707
+ let patch: CapabilityPatch = {}
708
+ if (fieldKey == "prompt") {
709
+ let promptItems: ChoiceItem[] = []
710
+ promptItems.push({
711
+ key: "large",
712
+ label: "large — full coordinator prompt"
713
+ })
714
+ promptItems.push({
715
+ key: "small",
716
+ label: "small — compact prompt for small-context models"
717
+ })
718
+ const picked = chooseOption("prompt", "System prompt size.", promptItems, allowCancel: true)
719
+ if (picked == "" || picked == null) {
720
+ return
721
+ }
722
+ patch = {
723
+ prompt: picked
724
+ }
725
+ }
726
+ if (fieldKey == "summarize" || fieldKey == "memory") {
727
+ let onOffItems: ChoiceItem[] = []
728
+ onOffItems.push({
729
+ key: "on",
730
+ label: "on"
731
+ })
732
+ onOffItems.push({
733
+ key: "off",
734
+ label: "off"
735
+ })
736
+ const picked = chooseOption(fieldKey, "Enable ${fieldKey}?", onOffItems, allowCancel: true)
737
+ if (picked == "" || picked == null) {
738
+ return
739
+ }
740
+ if (fieldKey == "summarize") {
741
+ patch = {
742
+ summarize: picked == "on"
743
+ }
744
+ } else {
745
+ patch = {
746
+ memory: picked == "on"
747
+ }
748
+ if (picked == "on") {
749
+ const status = embeddingKeyStatus(getResolvedSlots())
750
+ if (status.state == "key-missing") {
751
+ pushMessage(
752
+ color.red(
753
+ "Cannot enable memory: the embedding slot needs ${status.varName}, which is not set. Export it, or point the embedding slot elsewhere via /model.",
754
+ ),
755
+ )
756
+ return
757
+ }
758
+ if (status.state == "no-override" && providerLacksEmbeddings(getCapabilityProvider())) {
759
+ pushMessage(
760
+ color.dim(
761
+ "Note: ${getCapabilityProvider()} has no embeddings endpoint, so Tier-2 semantic recall stays off. Point the embedding slot at a provider that has one, e.g. /model embedding=openai/text-embedding-3-small.",
762
+ ),
763
+ )
764
+ }
765
+ }
766
+ }
767
+ }
768
+ if (fieldKey == "maxTokens") {
769
+ let capItems: ChoiceItem[] = []
770
+ capItems.push({
771
+ key: "reset",
772
+ label: "reset — remove my override, use the default"
773
+ })
774
+ const picked = chooseOption(
775
+ "maxTokens",
776
+ "Default output-token cap. Type a number, or pick reset.",
777
+ capItems,
778
+ allowFreeText: true,
779
+ allowCancel: true,
780
+ )
781
+ if (picked == "" || picked == null) {
782
+ return
783
+ }
784
+ if (picked == "reset") {
785
+ const scopeKey = pickOverrideScope()
786
+ if (scopeKey == "") {
787
+ return
788
+ }
789
+ removeCapabilityOverride(scopeKey, "maxTokens")
790
+ applyLiveMaxTokens()
791
+ pushMessage("Override removed.")
792
+ showCapabilities()
793
+ return
794
+ }
795
+ const parsed = parsePositiveInt(picked)
796
+ if (parsed <= 0) {
797
+ pushMessage(color.red("Not a positive number: ${picked}"))
798
+ return
799
+ }
800
+ patch = {
801
+ maxTokens: parsed
802
+ }
803
+ }
804
+
805
+ const scopeKey = pickOverrideScope()
806
+ if (scopeKey == "") {
807
+ return
808
+ }
809
+ saveCapabilityOverride(scopeKey, patch)
810
+
811
+ // Live-apply what can apply now; explain what can't.
812
+ if (fieldKey == "memory") {
813
+ if (getCapabilities().memory) {
814
+ // The ON direction cannot live-apply. enableAgentMemory's
815
+ // `with approve` cannot override the outer policy handler that
816
+ // startInteractive installed, so the memory-dir fs interrupts
817
+ // would surface as policy prompts mid-flow, or get denied and
818
+ // half-apply the toggle. The OFF direction stays live below:
819
+ // disableMemory raises no fs interrupts and already runs in-REPL
820
+ // from reactToSlotChange.
821
+ pushMessage(color.dim("Memory turns on at next agent start (enabling mid-session would raise policy prompts)."))
822
+ } else {
823
+ disableMemory() with approve
824
+ }
825
+ }
826
+ if (fieldKey == "maxTokens") {
827
+ applyLiveMaxTokens()
828
+ }
829
+ if (fieldKey == "prompt") {
830
+ pushMessage(color.dim("Prompt change applies on next agent start (this session's system message is already sent)."))
831
+ }
832
+ pushMessage("Saved.")
833
+ showCapabilities()
834
+ }
835
+
470
836
  // Slash-command + user-message dispatcher invoked by `repl()` for
471
837
  // every Enter keystroke. Return `false` to terminate the loop.
472
838
  def _runTurn(msg: string): boolean {
@@ -493,10 +859,39 @@ def _runTurn(msg: string): boolean {
493
859
  }
494
860
  if (trimmed == "/help") {
495
861
  pushMessage(
496
- "Commands: /exit, /clear, /clear-history, /cost, /model, /models, /local, /search, /paste, /help",
862
+ "Commands: /exit, /clear, /clear-history, /cost, /model, /models, /local, /search, /settings, /mcp, /paste, /help",
497
863
  )
498
864
  return true
499
865
  }
866
+ if (trimmed == "/settings") {
867
+ showCapabilities()
868
+ editCapabilities()
869
+ return true
870
+ }
871
+ if (trimmed == "/mcp") {
872
+ if (!isMcpAvailable()) {
873
+ pushMessage(color.yellow("MCP is not installed. Run: npm install @agency-lang/mcp"))
874
+ return true
875
+ }
876
+ const merged = mergeMcpServers(getMcpServers(loadSettings()), readProjectMcpConfig(cwd()))
877
+ if (keys(merged).length == 0) {
878
+ pushMessage(color.dim("No MCP servers configured. Add an mcpServers block to agency.json or settings.json."))
879
+ return true
880
+ }
881
+ pushMessage(color.bold("MCP servers:"))
882
+ for (name in keys(merged)) {
883
+ // mcpServerStatus is populated at session start. A server present in the
884
+ // config but absent from the status map was never loaded (e.g. /mcp run
885
+ // before startup finished) — show it as unknown rather than connected.
886
+ let status = mcpServerStatus[name]
887
+ if (status == null) {
888
+ status = "not loaded"
889
+ }
890
+ pushMessage(" ${name} — ${status}")
891
+ }
892
+ pushMessage(color.dim("Loaded ${mcpTools.length} MCP tool(s) this session."))
893
+ return true
894
+ }
500
895
  if (trimmed == "/search") {
501
896
  const opts = availableBackendItems()
502
897
  const choice = chooseOption(
@@ -661,7 +1056,7 @@ let first = true
661
1056
  // subagent. Used to validate the flag and to dispatch in `agentReplyVia`.
662
1057
  static const START_AGENTS = ["main", "code", "research", "oracle", "explorer", "review"]
663
1058
 
664
- static const mainAgentSystemPrompt = """
1059
+ static const MAIN_PROMPT_LARGE = """
665
1060
  You are the top-level coordinator of an Agency-language assistant. You
666
1061
  receive every user message and decide how to respond.
667
1062
 
@@ -830,6 +1225,41 @@ unless the user has clearly asked for an action ("do X", "fix Y",
830
1225
  with them — don't sprint to implementation.
831
1226
  """
832
1227
 
1228
+ // Compact coordinator prompt for small-context models, ~350 tokens
1229
+ // instead of ~3,400. Selected when the capability profile says
1230
+ // prompt: "small". An 8K-context model loses 40% of its window to the
1231
+ // large prompt before the user types anything. The phrase "compact
1232
+ // coordinator" is a deliberate marker that verification greps for in
1233
+ // statelogs.
1234
+ static const MAIN_PROMPT_SMALL = """
1235
+ You are the compact coordinator of an Agency-language assistant. Decide
1236
+ how to answer each user message.
1237
+
1238
+ Tools (each runs in its own context; pass a self-contained message):
1239
+ - `codeAgent(userMsg)` — anything touching code or files: read, write,
1240
+ edit, run, typecheck. Also Agency syntax and CLI questions.
1241
+ - `researchAgent(userMsg)` — web search, URL fetches, external facts.
1242
+ - `reviewAgent(userMsg)` — check non-trivial new Agency code for
1243
+ syntax and type errors; pass the code to review.
1244
+ - `oracleAgent(userMsg)` — deep reasoning on a hard question; include
1245
+ all needed context in the message.
1246
+ - `explorerAgent(userMsg)` — broad read-only codebase/docs questions.
1247
+ - `generateImageFile(prompt, path, size, images)` — create or edit an
1248
+ image; do not route image work to codeAgent.
1249
+
1250
+ Routing rules:
1251
+ - Simple chat, greetings, quick factual answers: reply directly, no
1252
+ tools.
1253
+ - Anything code- or file-related: codeAgent. Current/external info:
1254
+ researchAgent. Broad "summarize/tour/how does X work" questions:
1255
+ explorerAgent.
1256
+ - Surface tool results to the user concisely; do not re-run a tool the
1257
+ user did not ask to re-run.
1258
+
1259
+ Style: plain, direct answers in Markdown. No preamble. Keep replies
1260
+ short unless the task demands detail.
1261
+ """
1262
+
833
1263
  // Exported for tests: agent-cwd resolution of edit inputs is a spec
834
1264
  // invariant with no other observable (the deterministic image client
835
1265
  // ignores its images argument). generateImage accepts path / URL /
@@ -902,19 +1332,101 @@ static const mainAgentTools = [
902
1332
  generateImageFile,
903
1333
  ]
904
1334
 
1335
+ // MCP tools are appended to the coordinator's tools. ORDERING CONTRACT:
1336
+ // maybeLoadMcp (session start, in main()) must run before mainAgent's first
1337
+ // turn, or MCP tools silently vanish.
1338
+ let mcpTools: any[] = []
1339
+ // Per-server load outcome ("connected" / "unavailable"), for /mcp.
1340
+ let mcpServerStatus: Record<string, string> = {}
1341
+
1342
+ export def setMcpTools(tools: any[]) {
1343
+ mcpTools = tools
1344
+ }
1345
+
1346
+ def setMcpServerStatus(status: Record<string, string>) {
1347
+ mcpServerStatus = status
1348
+ }
1349
+
1350
+ // MCP OAuth notification. The @agency-lang/mcp package opens the browser itself
1351
+ // (macOS-only today); we only print the URL so the user can complete auth.
1352
+ def onMcpOAuth(data: any) {
1353
+ print(color.yellow("MCP authorization needed — opening browser. If it does not open, visit:\n${data.authUrl}"))
1354
+ }
1355
+
1356
+ /** Load MCP tools from the project agency.json merged with the global settings
1357
+ and hand them to the coordinator. No-op when @agency-lang/mcp is not installed
1358
+ or no servers are configured. loadMcpTools warns-and-skips internally on any
1359
+ per-server failure, so it always returns an array. */
1360
+ def maybeLoadMcp(settings: Settings) {
1361
+ if (!isMcpAvailable()) {
1362
+ return
1363
+ }
1364
+ const merged = mergeMcpServers(getMcpServers(settings), readProjectMcpConfig(cwd()))
1365
+ if (keys(merged).length == 0) {
1366
+ return
1367
+ }
1368
+ // Always returns a result (per-server failures warn-and-skip internally), so
1369
+ // there is no Failure branch. The status map drives /mcp.
1370
+ const loaded = loadMcpToolsWithStatus(merged, onMcpOAuth)
1371
+ setMcpTools(loaded.tools)
1372
+ setMcpServerStatus(loaded.status)
1373
+ }
1374
+
1375
+ /** Enable memory when the capability profile allows it. When the user
1376
+ pointed the embedding slot at a provider, embeddings run there. A
1377
+ missing API key degrades to the default embedding behavior with one
1378
+ notice. It never blocks startup. */
1379
+ // Whether startup actually enabled memory WITH the embedding override.
1380
+ // The pause guard in reactToSlotChange consults this instead of
1381
+ // re-deriving from the slots: a keyless override took the fallback path,
1382
+ // so memory runs on DERIVED embeddings and a main-provider change still
1383
+ // shifts the embedding space. Exported mutator so tests can drive the
1384
+ // guard directly.
1385
+ let _memoryEmbeddingsPinned = false
1386
+
1387
+ export def markMemoryEmbeddingsPinned(pinned: boolean) {
1388
+ _memoryEmbeddingsPinned = pinned
1389
+ }
1390
+
1391
+ def maybeEnableMemory() {
1392
+ const status = embeddingKeyStatus(getResolvedSlots())
1393
+ const plan = memoryEnablePlan(getCapabilities().memory, status)
1394
+ markMemoryEmbeddingsPinned(plan == "enable-override")
1395
+ if (plan == "skip") {
1396
+ return
1397
+ }
1398
+ if (plan == "enable-override") {
1399
+ enableAgentMemory(status.override)
1400
+ return
1401
+ }
1402
+ if (plan == "enable-fallback") {
1403
+ print(
1404
+ color.dim(
1405
+ "Memory: the embedding slot needs ${status.varName}, which is not set. Falling back to the default embedding behavior.",
1406
+ ),
1407
+ )
1408
+ }
1409
+ enableAgentMemory()
1410
+ }
1411
+
905
1412
  def mainAgent(prompt: string | (string | Attachment)[]): string {
906
- thread(label: "main", summarize: true, session: "main") {
1413
+ const doSummarize = getCapabilities().summarize
1414
+ thread(label: "main", summarize: doSummarize, session: "main") {
907
1415
  setMemoryId("main")
908
1416
  if (first) {
909
1417
  // `_context` carries the per-run grounding (date, cwd, AGENTS.md),
910
1418
  // set by `setupSession`. Appending it to the system prompt is what
911
1419
  // actually gets that context to the LLM.
912
- systemMessage("${mainAgentSystemPrompt}${_context}")
1420
+ let sysPrompt = MAIN_PROMPT_LARGE
1421
+ if (getCapabilities().prompt == "small") {
1422
+ sysPrompt = MAIN_PROMPT_SMALL
1423
+ }
1424
+ systemMessage("${sysPrompt}${_context}")
913
1425
  first = false
914
1426
  }
915
1427
  const result = llm(prompt, {
916
1428
  memory: true,
917
- tools: mainAgentTools
1429
+ tools: [...mainAgentTools, ...mcpTools]
918
1430
  })
919
1431
  }
920
1432
  return result
@@ -1259,6 +1771,10 @@ node main() {
1259
1771
  optional: true,
1260
1772
  description: "Approval policy for this run: a built-in name (minimal, recommended, with-writes, approve-all) or a path to a policy JSON file. with-writes auto-approves file writes and git changes scoped to the current directory and its children; approve-all approves EVERY interrupt with no scoping (sandbox use only). Overrides the saved policy without persisting it. Pass --policy with no value to list the built-in policies."
1261
1773
  },
1774
+ "agent-home": {
1775
+ type: "string",
1776
+ description: "Directory to use instead of ~/.agency-agent for settings, policy, and history (equivalent to the AGENCY_AGENT_HOME env var; the flag wins when both are set)"
1777
+ },
1262
1778
  local: {
1263
1779
  type: "string",
1264
1780
  optional: true,
@@ -1290,11 +1806,14 @@ node main() {
1290
1806
  },
1291
1807
  )
1292
1808
 
1293
- // NOTE: --trace / --log-file are declared here only for --help and so
1294
- // parseArgs accepts them. runBundledAgent extracts them from the forwarded
1295
- // args and passes them to this process as the AGENCY_CONFIG_OVERRIDES env
1296
- // var, read when the RuntimeContext is constructed before this main() runs.
1297
- // Do not re-handle them here.
1809
+ // NOTE: --trace / --log-file / --agent-home are declared here only for
1810
+ // --help and so parseArgs accepts them. runBundledAgent extracts them from
1811
+ // the forwarded args and passes them to this process via env vars
1812
+ // (AGENCY_CONFIG_OVERRIDES for the first two, AGENCY_AGENT_HOME for the
1813
+ // last), read before this main() runs — the RuntimeContext consumes the
1814
+ // config overrides at construction, and lib/config.agency derives the
1815
+ // settings/policy/history paths from the agent home in its static-const
1816
+ // initializers. Do not re-handle them here.
1298
1817
 
1299
1818
  if (args.flags.debug) {
1300
1819
  AGENT_DEBUG = true
@@ -1359,9 +1878,6 @@ node main() {
1359
1878
  // fall through into the session on the chosen local model
1360
1879
  } else if (localVal != null) {
1361
1880
  configureLocalModel(localVal)
1362
- // Intentionally do NOT enable memory for a local model: the llama-cpp
1363
- // provider has no embedding endpoint, so memory would only emit a
1364
- // "Tier-2 disabled" notice. std::memory calls no-op while it's off.
1365
1881
  configureSearch(true)
1366
1882
  } else {
1367
1883
  // Hosted path. --model accepts `slot=model` (per-slot) or a bare model
@@ -1370,6 +1886,7 @@ node main() {
1370
1886
  let modelGlobal = ""
1371
1887
  let fastFlag = ""
1372
1888
  let slowFlag = ""
1889
+ let embeddingFlag = ""
1373
1890
  if (modelArg != "") {
1374
1891
  if (parsed.slot == "") {
1375
1892
  modelGlobal = parsed.model
@@ -1377,10 +1894,20 @@ node main() {
1377
1894
  fastFlag = parsed.model
1378
1895
  } else if (parsed.slot == "reasoning") {
1379
1896
  slowFlag = parsed.model
1897
+ } else if (parsed.slot == "embedding") {
1898
+ if (!embeddingSpecHasProvider(parsed.model)) {
1899
+ print(
1900
+ color.red(
1901
+ "Embedding models need the provider/model form, e.g. --model embedding=openai/text-embedding-3-small.",
1902
+ ),
1903
+ )
1904
+ process.exit(1)
1905
+ }
1906
+ embeddingFlag = parsed.model
1380
1907
  } else {
1381
1908
  print(
1382
1909
  color.red(
1383
- "Unknown model slot '${parsed.slot}' in --model. Valid slots: main, reasoning.",
1910
+ "Unknown model slot '${parsed.slot}' in --model. Valid slots: ${SLOTS.join(", ")}.",
1384
1911
  ),
1385
1912
  )
1386
1913
  process.exit(1)
@@ -1394,16 +1921,18 @@ node main() {
1394
1921
  if (sm != "") {
1395
1922
  slowFlag = sm
1396
1923
  }
1397
- configureModels(modelGlobal, fastFlag, slowFlag, args.flags.provider ?? "")
1398
- // Persistent knowledge graph — enabled for hosted providers, skipped for
1399
- // local models. (Some hosted providers, e.g. anthropic, still lack an
1400
- // embedding endpoint and just disable Tier-2 recall with a one-time
1401
- // notice; structured recall works regardless.) Must run before any
1402
- // handler/REPL is installed.
1403
- enableAgentMemory()
1924
+ configureModels(modelGlobal, fastFlag, slowFlag, embeddingFlag, args.flags.provider ?? "")
1404
1925
  configureSearch(false)
1405
1926
  }
1406
1927
 
1928
+ // Persistent knowledge graph, gated on the capability profile. Must run
1929
+ // before any handler/REPL is installed.
1930
+ maybeEnableMemory()
1931
+
1932
+ // Connect configured MCP servers and hand their (policy-gated) tools to the
1933
+ // coordinator. Must run before the first turn (mcpTools ordering contract).
1934
+ maybeLoadMcp(loadSettings())
1935
+
1407
1936
  // Positional args (everything after flags) are joined with spaces to
1408
1937
  // form the starting prompt. `--` ends flag parsing if a positional
1409
1938
  // would otherwise look like a flag.
@@ -1434,20 +1963,15 @@ node main() {
1434
1963
  setLlmOptions({ maxToolResultChars: maxResultChars })
1435
1964
  }
1436
1965
 
1437
- // TEMPORARY: raise the per-turn output cap above smoltalk's 4096 default.
1438
- // With adaptive thinking on, a hard reasoning turn can spend the entire
1439
- // 4096-token budget thinking and return an empty reply (no text, no tool
1440
- // call) see the empty-output failures on regex-log / protein-assembly.
1441
- // Capped at 20000: these llm() calls are non-streaming, and the Anthropic
1442
- // SDK refuses a non-streaming request whose estimated time exceeds 10 min,
1443
- // which is maxTokens > 21333 (60min * maxTokens / 128000 > 10min). 20000
1444
- // stays under that and is well within every modern-Claude output cap
1445
- // (Sonnet 5 = 64K, Opus 4.8 = 128K). Branch-scoped so every subagent
1446
- // inherits it; per-call `llm(..., { maxTokens })` (e.g. the summarizer's
1447
- // cap) still wins. Superseded by the declarative capabilities table in
1448
- // docs/superpowers/specs/2026-07-09-model-capabilities-design.md (§2,
1449
- // maxTokens applied via setLlmOptions at startup) — remove it then.
1450
- setLlmOptions({ maxTokens: 20000 })
1966
+ // Per-model default output cap from the capability profile. The hosted
1967
+ // default of 20000 carries the adaptive-thinking empty-reply fix that
1968
+ // used to live here as a TEMPORARY block. Local profiles cap lower.
1969
+ // Branch-scoped, so every subagent inherits it. A per-call
1970
+ // llm(..., { maxTokens }) still wins, e.g. the summarizer's 256.
1971
+ const capsMaxTokens = getCapabilities().maxTokens
1972
+ if (capsMaxTokens != null) {
1973
+ setLlmOptions({ maxTokens: capsMaxTokens })
1974
+ }
1451
1975
 
1452
1976
  // One-shot autonomy: tell the code subagent there is no human to answer
1453
1977
  // questions and no next turn, so it must drive to a finished artifact.