nolo-cli 0.1.44 → 0.1.46

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 (613) hide show
  1. package/README.md +258 -102
  2. package/index.js +73433 -0
  3. package/package.json +10 -633
  4. package/LICENSE +0 -21
  5. package/agent-runtime/agentConfigOptions.ts +0 -12
  6. package/agent-runtime/agentRecordConfig.ts +0 -101
  7. package/agent-runtime/agentRecordKeys.ts +0 -14
  8. package/agent-runtime/agentThread.ts +0 -222
  9. package/agent-runtime/agentThreadAdmission.ts +0 -74
  10. package/agent-runtime/dialogMessageRecord.ts +0 -16
  11. package/agent-runtime/dialogWritePlan.ts +0 -211
  12. package/agent-runtime/hostAdapter.ts +0 -81
  13. package/agent-runtime/hybridRecordStore.ts +0 -170
  14. package/agent-runtime/index.ts +0 -184
  15. package/agent-runtime/localDialogRead.ts +0 -23
  16. package/agent-runtime/localLoop.ts +0 -334
  17. package/agent-runtime/localToolPolicy.ts +0 -179
  18. package/agent-runtime/localWorkspaceTools.ts +0 -2310
  19. package/agent-runtime/noloWorkspaceTools.ts +0 -390
  20. package/agent-runtime/openAiCompatibleProvider.ts +0 -74
  21. package/agent-runtime/openAiCompatibleProviderConfig.ts +0 -27
  22. package/agent-runtime/platformChatProvider.ts +0 -229
  23. package/agent-runtime/providerResolution.ts +0 -302
  24. package/agent-runtime/runtimeDecision.ts +0 -70
  25. package/agent-runtime/runtimeFacts.ts +0 -40
  26. package/agent-runtime/runtimeToolPolicy.ts +0 -191
  27. package/agent-runtime/runtimeToolSurface.ts +0 -199
  28. package/agent-runtime/shellCommandPolicy.ts +0 -120
  29. package/agent-runtime/types.ts +0 -137
  30. package/agentAliases.ts +0 -110
  31. package/agentCommandSupport.ts +0 -81
  32. package/agentInternalCommandEntries.ts +0 -44
  33. package/agentListCommands.ts +0 -185
  34. package/agentListHelpers.ts +0 -242
  35. package/agentMachineCommands.ts +0 -403
  36. package/agentPullCommand.ts +0 -142
  37. package/agentRecordCommands.ts +0 -226
  38. package/agentRecordHelpers.ts +0 -571
  39. package/agentRunCommand.ts +0 -556
  40. package/agentRuntimeCommands.ts +0 -7
  41. package/agentRuntimeLocal.ts +0 -45
  42. package/ai/agent/_executeModel.ts +0 -146
  43. package/ai/agent/agentSlice.ts +0 -557
  44. package/ai/agent/appWorkingMemory.ts +0 -126
  45. package/ai/agent/buildEditingContext.ts +0 -378
  46. package/ai/agent/buildSystemPrompt.ts +0 -599
  47. package/ai/agent/canvasEditingContext.ts +0 -49
  48. package/ai/agent/cleanAgentMessages.ts +0 -140
  49. package/ai/agent/cliChatClient.ts +0 -153
  50. package/ai/agent/cliExecutor.ts +0 -1465
  51. package/ai/agent/cliPrompt.ts +0 -10
  52. package/ai/agent/contextCompiler.ts +0 -107
  53. package/ai/agent/contextLayerContract.ts +0 -44
  54. package/ai/agent/createAgentSchema.ts +0 -272
  55. package/ai/agent/currentTimeContext.ts +0 -65
  56. package/ai/agent/executeToolCall.ts +0 -58
  57. package/ai/agent/fetchAgentContexts.ts +0 -42
  58. package/ai/agent/generatePrompt.ts +0 -3
  59. package/ai/agent/getFullChatContextKeys.ts +0 -168
  60. package/ai/agent/guidedCreation/capabilities.ts +0 -84
  61. package/ai/agent/guidedCreation/types.ts +0 -38
  62. package/ai/agent/isLiveAudioOnlyAgent.ts +0 -26
  63. package/ai/agent/liveAudioModel.ts +0 -2
  64. package/ai/agent/machineRunPermissions.ts +0 -113
  65. package/ai/agent/pageBuilderHandoffRules.ts +0 -75
  66. package/ai/agent/persistMessageWithFixedId.ts +0 -37
  67. package/ai/agent/planSlice.ts +0 -259
  68. package/ai/agent/referenceUtils.ts +0 -229
  69. package/ai/agent/runAgentBackground.ts +0 -310
  70. package/ai/agent/runAgentClientLoop.ts +0 -164
  71. package/ai/agent/runtimeGuidance.ts +0 -116
  72. package/ai/agent/serverOrigin.ts +0 -7
  73. package/ai/agent/startParallelAgentStreams.ts +0 -424
  74. package/ai/agent/startupProtocol.ts +0 -53
  75. package/ai/agent/streamAgentChatTurn.ts +0 -2135
  76. package/ai/agent/streamAgentChatTurnUtils.ts +0 -923
  77. package/ai/agent/toolFailureGuard.ts +0 -99
  78. package/ai/agent/types.ts +0 -73
  79. package/ai/agent/utils/imageOutput.ts +0 -37
  80. package/ai/agent/utils/publicImageAgentMode.ts +0 -26
  81. package/ai/agent.ts +0 -2
  82. package/ai/ai.locale.ts +0 -1165
  83. package/ai/chat/accumulateToolCallChunks.ts +0 -126
  84. package/ai/chat/fetchUtils.ts +0 -143
  85. package/ai/chat/inlineImageUrlsForCustomProvider.ts +0 -122
  86. package/ai/chat/parseApiError.ts +0 -67
  87. package/ai/chat/parseMultilineSSE.ts +0 -95
  88. package/ai/chat/sendOpenAICompletionsRequest.ts +0 -921
  89. package/ai/chat/sendOpenAIResponseRequest.ts +0 -720
  90. package/ai/chat/serverProxyRetry.ts +0 -102
  91. package/ai/chat/shouldUseServerProxy.ts +0 -18
  92. package/ai/chat/streamRetry.ts +0 -46
  93. package/ai/chat/updateTotalUsage.ts +0 -89
  94. package/ai/context/buildReferenceContext.ts +0 -437
  95. package/ai/context/retention.ts +0 -165
  96. package/ai/context/tokenUtils.ts +0 -78
  97. package/ai/index.ts +0 -1
  98. package/ai/llm/agentCapabilities.ts +0 -74
  99. package/ai/llm/deepinfra.ts +0 -79
  100. package/ai/llm/fireworks.ts +0 -68
  101. package/ai/llm/generateRequestBody.ts +0 -165
  102. package/ai/llm/getModelContextWindow.ts +0 -93
  103. package/ai/llm/getPricing.ts +0 -252
  104. package/ai/llm/imagePricing.ts +0 -66
  105. package/ai/llm/isResponseAPIModel.ts +0 -13
  106. package/ai/llm/kimi.ts +0 -22
  107. package/ai/llm/mimo.ts +0 -99
  108. package/ai/llm/mistral.ts +0 -21
  109. package/ai/llm/models.ts +0 -45
  110. package/ai/llm/openrouterModels.ts +0 -31
  111. package/ai/llm/providers.ts +0 -313
  112. package/ai/llm/reasoningModels.ts +0 -27
  113. package/ai/llm/types.ts +0 -82
  114. package/ai/llm/usageRequestOptions.ts +0 -59
  115. package/ai/memory/policy.ts +0 -49
  116. package/ai/memory/queryShared.ts +0 -167
  117. package/ai/memory/recentRelationshipRecap.ts +0 -251
  118. package/ai/memory/remember.ts +0 -111
  119. package/ai/memory/scope.ts +0 -74
  120. package/ai/memory/store.ts +0 -20
  121. package/ai/memory/storeShared.ts +0 -76
  122. package/ai/memory/types.ts +0 -52
  123. package/ai/memory/understanding.ts +0 -341
  124. package/ai/memory/understandingGreeting.ts +0 -264
  125. package/ai/policy/personalizationDialog.ts +0 -333
  126. package/ai/policy/runtimePolicy.ts +0 -526
  127. package/ai/policy/selfUpdateFields.ts +0 -48
  128. package/ai/policy/types.ts +0 -64
  129. package/ai/skills/referenceRuntime.ts +0 -274
  130. package/ai/skills/skillDiagnostics.ts +0 -251
  131. package/ai/skills/skillDocBuilder.ts +0 -139
  132. package/ai/skills/skillDocProtocol.ts +0 -526
  133. package/ai/skills/skillSummaryMarker.ts +0 -26
  134. package/ai/token/calculatePrice.ts +0 -576
  135. package/ai/token/missingUsageEstimate.ts +0 -42
  136. package/ai/token/normalizeUsage.ts +0 -124
  137. package/ai/token/openaiImageGenerationUsage.ts +0 -56
  138. package/ai/token/prepareTokenUsageData.ts +0 -93
  139. package/ai/token/resolveBillingTarget.ts +0 -52
  140. package/ai/token/saveTokenRecord.ts +0 -53
  141. package/ai/token/types.ts +0 -103
  142. package/ai/tools/agent/agentTools.ts +0 -214
  143. package/ai/tools/agent/agentUpdateShared.ts +0 -311
  144. package/ai/tools/agent/callAgentTool.ts +0 -139
  145. package/ai/tools/agent/createAgentTool.ts +0 -512
  146. package/ai/tools/agent/createDialogTool.ts +0 -69
  147. package/ai/tools/agent/createSkillAgentTool.ts +0 -62
  148. package/ai/tools/agent/parallelBudget.ts +0 -221
  149. package/ai/tools/agent/prepareAgentDraftTool.ts +0 -159
  150. package/ai/tools/agent/presets/appBuilderPreset.ts +0 -154
  151. package/ai/tools/agent/runLlmTool.ts +0 -96
  152. package/ai/tools/agent/runStreamingAgentTool.ts +0 -73
  153. package/ai/tools/agent/skillAgentArgs.ts +0 -106
  154. package/ai/tools/agent/startAgentDialogTool.ts +0 -54
  155. package/ai/tools/agent/streamParallelAgentsTool.ts +0 -123
  156. package/ai/tools/agent/updateAgentTool.ts +0 -96
  157. package/ai/tools/agent/updateSelfTool.ts +0 -113
  158. package/ai/tools/amazonProductScraperTool.ts +0 -86
  159. package/ai/tools/apifyActorClient.ts +0 -45
  160. package/ai/tools/appEditGuard.ts +0 -372
  161. package/ai/tools/appReadSnapshot.ts +0 -153
  162. package/ai/tools/appTools.ts +0 -1549
  163. package/ai/tools/applyEditTool.ts +0 -259
  164. package/ai/tools/applyLineEditsTool.ts +0 -315
  165. package/ai/tools/browserTools/click.ts +0 -33
  166. package/ai/tools/browserTools/closeSession.ts +0 -29
  167. package/ai/tools/browserTools/common.ts +0 -27
  168. package/ai/tools/browserTools/openSession.ts +0 -48
  169. package/ai/tools/browserTools/readContent.ts +0 -38
  170. package/ai/tools/browserTools/selectOption.ts +0 -46
  171. package/ai/tools/browserTools/typeText.ts +0 -42
  172. package/ai/tools/category/createCategoryTool.ts +0 -66
  173. package/ai/tools/category/queryContentsByCategoryTool.ts +0 -69
  174. package/ai/tools/category/updateContentCategoryTool.ts +0 -75
  175. package/ai/tools/cfBrowserTools.ts +0 -319
  176. package/ai/tools/cfSpeechToTextTool.ts +0 -49
  177. package/ai/tools/checkEnvTool.ts +0 -102
  178. package/ai/tools/cloudflareCrawlTool.ts +0 -289
  179. package/ai/tools/codeSearchTool.ts +0 -123
  180. package/ai/tools/codeTools.ts +0 -101
  181. package/ai/tools/convertMarxistsBookTool.ts +0 -103
  182. package/ai/tools/createDocTool.ts +0 -132
  183. package/ai/tools/createSkillDocTool.ts +0 -155
  184. package/ai/tools/createWorkflowTool.ts +0 -154
  185. package/ai/tools/delayTool.ts +0 -31
  186. package/ai/tools/deleteSpacesTool.ts +0 -325
  187. package/ai/tools/deleteSpacesToolModel.ts +0 -159
  188. package/ai/tools/devReloadUtils.ts +0 -29
  189. package/ai/tools/dialogMessageSearch.ts +0 -137
  190. package/ai/tools/doctorSkillTool.ts +0 -72
  191. package/ai/tools/ecommerceScraperTool.ts +0 -86
  192. package/ai/tools/emailTools.ts +0 -549
  193. package/ai/tools/evalSkillTool.ts +0 -92
  194. package/ai/tools/exaSearchTool.ts +0 -63
  195. package/ai/tools/execShellTool.ts +0 -266
  196. package/ai/tools/executeSqlTool.ts +0 -192
  197. package/ai/tools/fetchWebpageSupport.ts +0 -333
  198. package/ai/tools/fetchWebpageTool.ts +0 -97
  199. package/ai/tools/geminiImagePreviewTool.ts +0 -386
  200. package/ai/tools/generateDocxTool.ts +0 -215
  201. package/ai/tools/googleSearchScraperTool.ts +0 -106
  202. package/ai/tools/importDataTool.ts +0 -133
  203. package/ai/tools/importSkillTool.ts +0 -162
  204. package/ai/tools/index.ts +0 -2290
  205. package/ai/tools/jdProductScraperTool.ts +0 -821
  206. package/ai/tools/listUserSpacesTool.ts +0 -113
  207. package/ai/tools/localFilesTool.ts +0 -276
  208. package/ai/tools/marxistsOfflineBook.ts +0 -253
  209. package/ai/tools/modelUsageTools.ts +0 -206
  210. package/ai/tools/noloWorkspaceReadTools.ts +0 -467
  211. package/ai/tools/olmOcrTool.ts +0 -33
  212. package/ai/tools/openaiImageTool.ts +0 -267
  213. package/ai/tools/prepareTools.ts +0 -193
  214. package/ai/tools/readDocTool.ts +0 -88
  215. package/ai/tools/readFileTool.ts +0 -214
  216. package/ai/tools/readTool.ts +0 -194
  217. package/ai/tools/readXPostTool.ts +0 -229
  218. package/ai/tools/readXhsProfileTool.ts +0 -638
  219. package/ai/tools/rememberMemoryTool.ts +0 -84
  220. package/ai/tools/remotionVideoTool.ts +0 -151
  221. package/ai/tools/searchDialogMessagesTool.ts +0 -222
  222. package/ai/tools/searchWorkspaceTool.ts +0 -259
  223. package/ai/tools/skillFollowup.ts +0 -86
  224. package/ai/tools/surfWeatherTool.ts +0 -169
  225. package/ai/tools/table/addTableRowTool.ts +0 -217
  226. package/ai/tools/table/createTableTool.ts +0 -326
  227. package/ai/tools/table/rowTools.ts +0 -386
  228. package/ai/tools/table/schemaTools.ts +0 -244
  229. package/ai/tools/table/shareTableTool.ts +0 -148
  230. package/ai/tools/table/toolShared.ts +0 -129
  231. package/ai/tools/taobaoTmallProductScraperTool.ts +0 -49
  232. package/ai/tools/toolApiClient.ts +0 -279
  233. package/ai/tools/toolNameAliases.ts +0 -70
  234. package/ai/tools/toolPacks.ts +0 -19
  235. package/ai/tools/toolResultError.ts +0 -42
  236. package/ai/tools/toolRunSlice.ts +0 -303
  237. package/ai/tools/toolSchemaCompatibility.ts +0 -53
  238. package/ai/tools/uiAskChoiceTool.ts +0 -104
  239. package/ai/tools/updateContentTitleTool.ts +0 -84
  240. package/ai/tools/updateDocTool.ts +0 -105
  241. package/ai/tools/updateUserPreferenceProfileTool.ts +0 -153
  242. package/ai/tools/wereadGatewayTool.ts +0 -152
  243. package/ai/tools/whisperTool.ts +0 -76
  244. package/ai/tools/writeFileTool.ts +0 -213
  245. package/ai/tools/youtubeScraperTool.ts +0 -116
  246. package/ai/tools/ziweiChartTool.ts +0 -678
  247. package/ai/types.ts +0 -58
  248. package/ai/workflow/workflowExecutor.ts +0 -323
  249. package/ai/workflow/workflowSlice.ts +0 -73
  250. package/ai/workflow/workflowTypes.ts +0 -106
  251. package/app/actions/syncAppRecord.ts +0 -73
  252. package/app/constants/animationSets.ts +0 -21
  253. package/app/constants/appEditor.ts +0 -99
  254. package/app/favorite/deletedFavoriteProjection.ts +0 -31
  255. package/app/favorite/favoriteSlice.ts +0 -690
  256. package/app/favorite/type.ts +0 -43
  257. package/app/hooks/deleteDbKey.ts +0 -254
  258. package/app/i18n/client.ts +0 -13
  259. package/app/i18n/i18n.base.ts +0 -14
  260. package/app/i18n/i18n.config.ts +0 -77
  261. package/app/i18n/index.ts +0 -15
  262. package/app/i18n/mapLanguage.ts +0 -11
  263. package/app/i18n/translations/appBuilder.locale.ts +0 -453
  264. package/app/i18n/translations/error.locale.ts +0 -246
  265. package/app/i18n/translations/interface.locale.ts +0 -2206
  266. package/app/i18n/translations/pricing.locale.ts +0 -397
  267. package/app/i18n/translations/privacy.locale.ts +0 -168
  268. package/app/i18n/translations/seo.locale.ts +0 -129
  269. package/app/i18n/translations/terms.locale.ts +0 -124
  270. package/app/i18n/types.ts +0 -6
  271. package/app/notifications/model.ts +0 -77
  272. package/app/notifications/notificationSlice.ts +0 -141
  273. package/app/reducer.ts +0 -36
  274. package/app/settings/dbActionThunks.ts +0 -34
  275. package/app/settings/defaultSpacePreference.ts +0 -87
  276. package/app/settings/settingSlice.tsx +0 -1212
  277. package/app/settings/settingsRecord.ts +0 -8
  278. package/app/stateViews/runtime.ts +0 -90
  279. package/app/store.ts +0 -55
  280. package/app/theme/colors.ts +0 -280
  281. package/app/theme/fontPreference.ts +0 -77
  282. package/app/theme/theme.config.ts +0 -120
  283. package/app/theme/themeModeBootstrap.ts +0 -123
  284. package/app/types/appSummary.ts +0 -118
  285. package/app/types.ts +0 -358
  286. package/app/utils/appKeys.ts +0 -55
  287. package/app/utils/async.ts +0 -28
  288. package/app/utils/desktopAgentRuntimeTurnClient.ts +0 -75
  289. package/app/utils/env.ts +0 -17
  290. package/app/utils/fileUtils.ts +0 -229
  291. package/app/utils/imageUtils.ts +0 -274
  292. package/app/utils/myContentItems.ts +0 -317
  293. package/app/utils/retryAfter.ts +0 -36
  294. package/app/utils/retryFetch.ts +0 -61
  295. package/app/utils/toast.ts +0 -3
  296. package/auth/action/signUpAction.ts +0 -227
  297. package/auth/adminPermissions.ts +0 -78
  298. package/auth/authSlice.ts +0 -531
  299. package/auth/client/loginRequest.ts +0 -14
  300. package/auth/resetAuthScopedClientState.ts +0 -27
  301. package/auth/routes.ts +0 -183
  302. package/auth/token.ts +0 -63
  303. package/auth/types.ts +0 -40
  304. package/authCommands.ts +0 -230
  305. package/chat/chat.locale.ts +0 -817
  306. package/chat/dialog/actions/addCybotAction.ts +0 -52
  307. package/chat/dialog/actions/addReferenceKeysAction.ts +0 -62
  308. package/chat/dialog/actions/builtinDialogLlm.ts +0 -35
  309. package/chat/dialog/actions/cleanupCliSession.ts +0 -40
  310. package/chat/dialog/actions/createDialogAction.ts +0 -379
  311. package/chat/dialog/actions/createScheduledTaskAction.ts +0 -78
  312. package/chat/dialog/actions/handleSendMessageAction.ts +0 -202
  313. package/chat/dialog/actions/handleSendMessageResolver.ts +0 -27
  314. package/chat/dialog/actions/removeCybotAction.ts +0 -6
  315. package/chat/dialog/actions/removeDialogAgentAction.ts +0 -44
  316. package/chat/dialog/actions/replacePrimaryCybotAction.ts +0 -6
  317. package/chat/dialog/actions/setPrimaryDialogAgentAction.ts +0 -52
  318. package/chat/dialog/actions/updateDialogSummaryAction.ts +0 -430
  319. package/chat/dialog/actions/updateDialogTitleAction.ts +0 -151
  320. package/chat/dialog/actions/updateDialogTitlePolicy.ts +0 -30
  321. package/chat/dialog/actions/updateTokensAction.ts +0 -233
  322. package/chat/dialog/dialogAgents.ts +0 -72
  323. package/chat/dialog/dialogAttachmentCleanup.ts +0 -135
  324. package/chat/dialog/dialogSlice.ts +0 -985
  325. package/chat/dialog/dialogTitle.ts +0 -81
  326. package/chat/dialog/dialogTokenStats.ts +0 -12
  327. package/chat/dialog/dialogUrl.ts +0 -6
  328. package/chat/dialog/goal.ts +0 -108
  329. package/chat/dialog/objectAssistantRegistry.ts +0 -286
  330. package/chat/dialog/schedule.ts +0 -17
  331. package/chat/messages/activityCompletion.ts +0 -97
  332. package/chat/messages/fetchAndCacheMessages.ts +0 -119
  333. package/chat/messages/fetchConvMsgs.ts +0 -51
  334. package/chat/messages/fetchMessages.ts +0 -84
  335. package/chat/messages/fileUrl.ts +0 -13
  336. package/chat/messages/imagePayloadPersistence.ts +0 -22
  337. package/chat/messages/messageAgent.ts +0 -8
  338. package/chat/messages/messageContent.ts +0 -203
  339. package/chat/messages/messageContract.ts +0 -88
  340. package/chat/messages/messageSlice.ts +0 -1386
  341. package/chat/messages/toolThunks.ts +0 -646
  342. package/chat/messages/types.ts +0 -192
  343. package/chat/messages/web/toolDisplayName.ts +0 -686
  344. package/cli/agentAliases.ts +0 -110
  345. package/cli/agentCommandSupport.ts +0 -81
  346. package/cli/agentInternalCommandEntries.ts +0 -44
  347. package/cli/agentListCommands.ts +0 -185
  348. package/cli/agentListHelpers.ts +0 -242
  349. package/cli/agentMachineCommands.ts +0 -403
  350. package/cli/agentPullCommand.ts +0 -142
  351. package/cli/agentRecordCommands.ts +0 -226
  352. package/cli/agentRecordHelpers.ts +0 -571
  353. package/cli/agentRunCommand.ts +0 -556
  354. package/cli/agentRuntimeLocal.ts +0 -45
  355. package/cli/authCommands.ts +0 -230
  356. package/cli/cliCommandAdapters.ts +0 -28
  357. package/cli/cliCommandDispatch.ts +0 -66
  358. package/cli/cliCommandFactories.ts +0 -66
  359. package/cli/cliCommandTypes.ts +0 -49
  360. package/cli/cliEnvHelpers.ts +0 -116
  361. package/cli/cliSpaceHelpers.ts +0 -39
  362. package/cli/client/agentConfigResolver.ts +0 -1
  363. package/cli/client/agentRun.ts +0 -795
  364. package/cli/client/compactDialog.ts +0 -222
  365. package/cli/client/hybridRecordStore.ts +0 -52
  366. package/cli/client/localAgentRecords.ts +0 -7
  367. package/cli/client/localDialogRecords.ts +0 -30
  368. package/cli/client/localProviderResolver.ts +0 -1
  369. package/cli/client/localRuntimeAdapter.ts +0 -1104
  370. package/cli/client/localToolPolicy.ts +0 -8
  371. package/cli/client/profileConfig.ts +0 -101
  372. package/cli/client/streamingOutput.ts +0 -38
  373. package/cli/commandRegistry.ts +0 -98
  374. package/cli/connectorRunArtifact.ts +0 -120
  375. package/cli/connectorWebSocketTarget.ts +0 -112
  376. package/cli/defaultServer.ts +0 -1
  377. package/cli/dialogAttachmentCleanup.ts +0 -151
  378. package/cli/dialogCommands.ts +0 -1120
  379. package/cli/dialogInternalCommandEntries.ts +0 -17
  380. package/cli/docCreateCommands.ts +0 -345
  381. package/cli/docInternalCommandEntries.ts +0 -11
  382. package/cli/docPageHelpers.ts +0 -80
  383. package/cli/docSkillHelpers.ts +0 -67
  384. package/cli/docSpaceHelpers.ts +0 -46
  385. package/cli/globalRecordOperations.ts +0 -258
  386. package/cli/internalCommandEntries.ts +0 -18
  387. package/cli/localRuntimeAuthority.ts +0 -182
  388. package/cli/localRuntimeDb.ts +0 -26
  389. package/cli/machineCommands.ts +0 -307
  390. package/cli/machineDaemonCommands.ts +0 -185
  391. package/cli/machineHeartbeatCommands.ts +0 -30
  392. package/cli/machineStatusCommands.ts +0 -95
  393. package/cli/machineWatchCommands.ts +0 -41
  394. package/cli/machineWsPromptMaterialization.ts +0 -89
  395. package/cli/machineWsRunDispatch.ts +0 -695
  396. package/cli/machineWsSession.ts +0 -213
  397. package/cli/memoryCommands.ts +0 -253
  398. package/cli/memoryInternalCommandEntries.ts +0 -9
  399. package/cli/offlineMarxistsAgentCommand.ts +0 -316
  400. package/cli/qoderUsageProbe.ts +0 -252
  401. package/cli/runtimeDoctorCommands.ts +0 -174
  402. package/cli/runtimeModeArgs.ts +0 -33
  403. package/cli/scriptCommandEntries.ts +0 -66
  404. package/cli/secretScan.ts +0 -31
  405. package/cli/systemInternalCommandEntries.ts +0 -65
  406. package/cli/tableCommands.ts +0 -453
  407. package/cli/tui/readlineWorkspace.ts +0 -210
  408. package/cli/tui/session.ts +0 -554
  409. package/cli/updateCommands.ts +0 -134
  410. package/cli/workflowInternalCommandEntries.ts +0 -10
  411. package/cliCommandAdapters.ts +0 -28
  412. package/cliCommandDispatch.ts +0 -66
  413. package/cliCommandFactories.ts +0 -66
  414. package/cliCommandTypes.ts +0 -49
  415. package/cliEnvHelpers.ts +0 -116
  416. package/cliSpaceHelpers.ts +0 -39
  417. package/client/agentConfigResolver.test.ts +0 -69
  418. package/client/agentConfigResolver.ts +0 -1
  419. package/client/agentRun.test.ts +0 -1344
  420. package/client/agentRun.ts +0 -795
  421. package/client/compactDialog.test.ts +0 -238
  422. package/client/compactDialog.ts +0 -222
  423. package/client/hybridRecordStore.test.ts +0 -157
  424. package/client/hybridRecordStore.ts +0 -52
  425. package/client/localAgentRecords.test.ts +0 -27
  426. package/client/localAgentRecords.ts +0 -7
  427. package/client/localDialogRecords.test.ts +0 -124
  428. package/client/localDialogRecords.ts +0 -30
  429. package/client/localProviderResolver.test.ts +0 -102
  430. package/client/localProviderResolver.ts +0 -1
  431. package/client/localRuntimeAdapter.test.ts +0 -2804
  432. package/client/localRuntimeAdapter.ts +0 -1104
  433. package/client/localRuntimeDryRun.test.ts +0 -135
  434. package/client/localToolPolicy.test.ts +0 -48
  435. package/client/localToolPolicy.ts +0 -8
  436. package/client/profileConfig.test.ts +0 -106
  437. package/client/profileConfig.ts +0 -101
  438. package/client/streamingOutput.test.ts +0 -22
  439. package/client/streamingOutput.ts +0 -38
  440. package/commandRegistry.ts +0 -98
  441. package/connector-experimental/capabilities.ts +0 -75
  442. package/connector-experimental/codexBinary.ts +0 -41
  443. package/connector-experimental/heartbeatLoop.ts +0 -22
  444. package/connector-experimental/machineInfo.ts +0 -46
  445. package/connector-experimental/protocol.ts +0 -54
  446. package/connectorRunArtifact.ts +0 -120
  447. package/connectorWebSocketTarget.ts +0 -112
  448. package/core/builtinAgents.ts +0 -209
  449. package/core/config.ts +0 -15
  450. package/core/crypto.ts +0 -51
  451. package/core/generateKeyPairFromSeedV1.ts +0 -15
  452. package/core/generateMainKey.ts +0 -22
  453. package/core/init.ts +0 -41
  454. package/core/localOrigins.ts +0 -8
  455. package/core/password.ts +0 -13
  456. package/core/prefix.ts +0 -23
  457. package/create/editor/transforms/fromMarkdown/index.ts +0 -260
  458. package/create/editor/transforms/fromMarkdown/inline.ts +0 -285
  459. package/create/editor/transforms/fromMarkdown/table.ts +0 -130
  460. package/create/editor/transforms/markdownToSlate.ts +0 -24
  461. package/create/editor/transforms/slateToRenderMarkdown.ts +0 -218
  462. package/create/editor/transforms/slateToSimplifiedMarkdown.ts +0 -224
  463. package/create/editor/transforms/slateToText.ts +0 -33
  464. package/create/editor/utils/slateUtils.ts +0 -233
  465. package/create/space/addSpaceAction.ts +0 -193
  466. package/create/space/category/categoryActions.ts +0 -427
  467. package/create/space/changeSpaceAction.ts +0 -36
  468. package/create/space/constants.ts +0 -8
  469. package/create/space/content/addContentAction.ts +0 -116
  470. package/create/space/content/contentThunks.ts +0 -90
  471. package/create/space/content/deleteContentFromSpaceAction.ts +0 -187
  472. package/create/space/content/deleteMultipleContentAction.ts +0 -112
  473. package/create/space/content/moveContentAction.ts +0 -285
  474. package/create/space/content/updateContentCategoryAction.ts +0 -154
  475. package/create/space/content/updateContentTitleAction.ts +0 -151
  476. package/create/space/content/uploadAndAddFileToSpaceAction.ts +0 -98
  477. package/create/space/contentKeyUtils.ts +0 -117
  478. package/create/space/deleteSpaceAction.ts +0 -276
  479. package/create/space/fetchSpaceAction.ts +0 -70
  480. package/create/space/fetchSpaceSidebarStateAction.ts +0 -26
  481. package/create/space/loadDefaultSpaceAction.ts +0 -57
  482. package/create/space/member/addMemberAction.ts +0 -79
  483. package/create/space/member/fetchUserSpaceMembershipsAction.ts +0 -386
  484. package/create/space/member/memberThunks.ts +0 -47
  485. package/create/space/member/removeMemberAction.ts +0 -67
  486. package/create/space/resolvePreferredSpaceId.ts +0 -113
  487. package/create/space/sidebarVisibleTypes.ts +0 -260
  488. package/create/space/space.locale.ts +0 -1087
  489. package/create/space/spaceAccess.ts +0 -182
  490. package/create/space/spaceCollapsedState.ts +0 -54
  491. package/create/space/spaceKeys.ts +0 -65
  492. package/create/space/spaceSlice.ts +0 -328
  493. package/create/space/spaceThunks.ts +0 -410
  494. package/create/space/types.ts +0 -27
  495. package/create/space/updateSpaceAction.ts +0 -107
  496. package/create/space/utils/permissions.ts +0 -47
  497. package/create/types.ts +0 -21
  498. package/database/actions/agentReadResolution.ts +0 -33
  499. package/database/actions/common.ts +0 -243
  500. package/database/actions/deleteFile.ts +0 -40
  501. package/database/actions/fileContent.ts +0 -125
  502. package/database/actions/patch.ts +0 -155
  503. package/database/actions/read.ts +0 -358
  504. package/database/actions/readAndWait.ts +0 -260
  505. package/database/actions/readRequestManager.ts +0 -120
  506. package/database/actions/readResolution.ts +0 -125
  507. package/database/actions/remove.ts +0 -94
  508. package/database/actions/replication.ts +0 -477
  509. package/database/actions/upload.ts +0 -186
  510. package/database/actions/upsert.ts +0 -56
  511. package/database/actions/write.ts +0 -146
  512. package/database/authority/ownerKey.ts +0 -80
  513. package/database/authority/recordAuthority.ts +0 -67
  514. package/database/authority/userAuthorityRegistry.ts +0 -54
  515. package/database/client/fetchUserData.ts +0 -61
  516. package/database/config.ts +0 -40
  517. package/database/dbActionThunks.ts +0 -1
  518. package/database/dbSlice.ts +0 -149
  519. package/database/fileRing.ts +0 -51
  520. package/database/fileStorage.ts +0 -232
  521. package/database/fileUrl.ts +0 -34
  522. package/database/keys.ts +0 -767
  523. package/database/queryPrefixes.ts +0 -14
  524. package/database/requests.ts +0 -443
  525. package/database/runtimeServerContext.ts +0 -54
  526. package/database/server/authorityStoreTypes.ts +0 -31
  527. package/database/server/cliAuthorityBrokerClient.ts +0 -227
  528. package/database/server/cliAuthorityBrokerServer.ts +0 -283
  529. package/database/server/cliAuthorityBrokerTypes.ts +0 -43
  530. package/database/server/cliAuthorityStoreDriver.ts +0 -98
  531. package/database/server/db.ts +0 -99
  532. package/database/server/dbPath.ts +0 -20
  533. package/database/server/ensureDbOpen.ts +0 -12
  534. package/database/server/legacyServerDb.ts +0 -58
  535. package/database/server/levelAuthorityStore.ts +0 -114
  536. package/database/server/memoryAuthorityStore.ts +0 -133
  537. package/database/server/serverStoreFactory.ts +0 -118
  538. package/database/tenantPlacement.ts +0 -57
  539. package/database/tombstones.ts +0 -52
  540. package/database/userDataMerge.ts +0 -95
  541. package/database/userPreferenceRegister.ts +0 -131
  542. package/database/utils/ulid.ts +0 -1
  543. package/defaultServer.ts +0 -1
  544. package/dialogAttachmentCleanup.ts +0 -151
  545. package/dialogCommands.ts +0 -1120
  546. package/dialogInternalCommandEntries.ts +0 -17
  547. package/docCreateCommands.ts +0 -345
  548. package/docInternalCommandEntries.ts +0 -11
  549. package/docPageHelpers.ts +0 -80
  550. package/docSkillHelpers.ts +0 -67
  551. package/docSpaceHelpers.ts +0 -46
  552. package/globalRecordOperations.ts +0 -258
  553. package/index.ts +0 -78
  554. package/integrations/anthropic/anthropicModels.ts +0 -47
  555. package/integrations/deepseek/models.ts +0 -37
  556. package/integrations/google/models.ts +0 -341
  557. package/integrations/openai/chatCompletionStreamMode.ts +0 -10
  558. package/integrations/openai/filterAndCleanMessages.ts +0 -284
  559. package/integrations/openai/flexTier.ts +0 -102
  560. package/integrations/openai/generateOpenAIRequestBody.ts +0 -271
  561. package/integrations/openai/generateResponseRequestBody.ts +0 -77
  562. package/integrations/openai/models.ts +0 -271
  563. package/integrations/openai/providerBodyCompatibility.ts +0 -23
  564. package/integrations/openai/responsesHelpers.ts +0 -297
  565. package/integrations/x-reader/types.ts +0 -109
  566. package/integrations/xai/models.ts +0 -13
  567. package/integrations/xhs-reader/redaction.ts +0 -68
  568. package/integrations/xhs-reader/types.ts +0 -277
  569. package/integrations/xhs-reader/url.ts +0 -80
  570. package/internalCommandEntries.ts +0 -18
  571. package/localRuntimeAuthority.ts +0 -182
  572. package/localRuntimeDb.ts +0 -26
  573. package/machineCommands.ts +0 -307
  574. package/machineDaemonCommands.ts +0 -185
  575. package/machineHeartbeatCommands.ts +0 -30
  576. package/machineStatusCommands.ts +0 -95
  577. package/machineWatchCommands.ts +0 -41
  578. package/machineWsPromptMaterialization.ts +0 -89
  579. package/machineWsRunDispatch.ts +0 -695
  580. package/machineWsSession.ts +0 -213
  581. package/memoryCommands.ts +0 -253
  582. package/memoryInternalCommandEntries.ts +0 -9
  583. package/offlineMarxistsAgentCommand.ts +0 -316
  584. package/qoderUsageProbe.ts +0 -252
  585. package/render/contentIcon/types.ts +0 -167
  586. package/render/page/createPageAction.ts +0 -183
  587. package/render/page/docSlice.ts +0 -495
  588. package/render/page/types.ts +0 -19
  589. package/render/table/activityColumns.ts +0 -6
  590. package/render/table/createTableAction.ts +0 -274
  591. package/render/table/deleteTableAction.ts +0 -193
  592. package/render/table/fetchAndCacheTableRows.ts +0 -174
  593. package/render/table/tableSlice.ts +0 -1167
  594. package/render/table/toolValueUtils.ts +0 -363
  595. package/render/table/types.ts +0 -262
  596. package/render/table/utils/tableSerialization.ts +0 -50
  597. package/runtimeDoctorCommands.ts +0 -174
  598. package/runtimeModeArgs.ts +0 -33
  599. package/scriptCommandEntries.ts +0 -66
  600. package/secretScan.ts +0 -31
  601. package/server/handlers/agentRun/types.ts +0 -105
  602. package/share/action.ts +0 -225
  603. package/share/helpers.ts +0 -302
  604. package/share/keys.ts +0 -243
  605. package/share/publicSharePolicy.ts +0 -27
  606. package/share/shareSlice.ts +0 -53
  607. package/share/types.ts +0 -100
  608. package/systemInternalCommandEntries.ts +0 -65
  609. package/tableCommands.ts +0 -453
  610. package/tui/readlineWorkspace.ts +0 -210
  611. package/tui/session.ts +0 -554
  612. package/updateCommands.ts +0 -134
  613. package/workflowInternalCommandEntries.ts +0 -10
@@ -1,2804 +0,0 @@
1
- import { describe, expect, test } from "bun:test";
2
- import { mkdtempSync, readFileSync, rmSync } from "node:fs";
3
- import { join } from "node:path";
4
- import { tmpdir } from "node:os";
5
-
6
- import { runLocalAgentTurn } from "../agent-runtime/localLoop";
7
- import { LOCAL_CODEX_AGENT_KEY, LOCAL_QODER_AGENT_KEY, MIMO_MONTH_AGENT_KEY } from "../agentAliases";
8
- import { createCliLocalRuntimeAdapter } from "./localRuntimeAdapter";
9
-
10
- describe("CLI local runtime adapter", () => {
11
- const DEFAULT_LOCAL_CODING_TOOL_NAMES = [
12
- "listFiles",
13
- "readFile",
14
- "writeFile",
15
- "editFile",
16
- "globFiles",
17
- "searchFiles",
18
- "execShell",
19
- ];
20
- const LEGACY_WRITE_LOCAL_CODING_TOOL_NAMES = [
21
- "listFiles",
22
- "readFile",
23
- "writeFile",
24
- "editFile",
25
- "globFiles",
26
- "searchFiles",
27
- "execShell",
28
- ];
29
- const SHELL_LOCAL_CODING_TOOL_NAMES = [
30
- ...DEFAULT_LOCAL_CODING_TOOL_NAMES,
31
- ];
32
- const DEFAULT_PRIVATE_NOLO_WORKSPACE_TOOL_NAMES = [
33
- "listDialogs",
34
- "readDialog",
35
- "listAgents",
36
- "readAgent",
37
- "listSpaces",
38
- "readSpace",
39
- "readDoc",
40
- "readSkillDoc",
41
- "listTables",
42
- "queryTableRows",
43
- "cliWhoami",
44
- "cliDoctor",
45
- ];
46
- const DEFAULT_PRIVATE_LOCAL_TOOL_NAMES = [
47
- ...DEFAULT_LOCAL_CODING_TOOL_NAMES,
48
- ...DEFAULT_PRIVATE_NOLO_WORKSPACE_TOOL_NAMES,
49
- ];
50
-
51
- function toolNamesFromRequest(request: any) {
52
- return request?.body?.tools?.map((tool: any) => tool.function.name) ?? [];
53
- }
54
-
55
- function publicSchemaKeys(schema: any) {
56
- return Object.keys(schema.parameters.properties).filter((key) => key !== "_activity");
57
- }
58
-
59
- test("loads stored local CLI agent records before falling back to built-ins", async () => {
60
- const adapter = createCliLocalRuntimeAdapter({
61
- env: {
62
- NOLO_LOCAL_USER_ID: "0e95801d90",
63
- },
64
- db: {
65
- get: async (key) => {
66
- if (key !== LOCAL_CODEX_AGENT_KEY) throw new Error(`not found: ${key}`);
67
- return {
68
- dbKey: LOCAL_CODEX_AGENT_KEY,
69
- id: "01LOCALCODEXCLI000000NEW",
70
- name: "User Edited Local Codex",
71
- prompt: "User-owned local Codex prompt.",
72
- apiSource: "cli",
73
- provider: "cli",
74
- cliProvider: "codex",
75
- model: "gpt-5.4",
76
- };
77
- },
78
- put: async () => {},
79
- batch: async () => {},
80
- iterator: () => (async function* () {})(),
81
- },
82
- fetchImpl: async () => new Response("not found", { status: 404 }),
83
- } as any);
84
-
85
- await expect(adapter.loadAgentConfig(LOCAL_CODEX_AGENT_KEY)).resolves.toMatchObject({
86
- key: LOCAL_CODEX_AGENT_KEY,
87
- name: "User Edited Local Codex",
88
- prompt: "User-owned local Codex prompt.",
89
- apiSource: "cli",
90
- provider: "cli",
91
- cliProvider: "codex",
92
- model: "gpt-5.4",
93
- });
94
- });
95
-
96
- test("falls back to built-in local Codex and Qoder CLI agents without machine binding", async () => {
97
- const adapter = createCliLocalRuntimeAdapter({
98
- env: {
99
- NOLO_LOCAL_USER_ID: "user-1",
100
- },
101
- db: {
102
- get: async (key) => {
103
- throw new Error(`not found: ${key}`);
104
- },
105
- put: async () => {},
106
- batch: async () => {},
107
- iterator: () => (async function* () {})(),
108
- },
109
- fetchImpl: async () => new Response("not found", { status: 404 }),
110
- } as any);
111
-
112
- const codex = await adapter.loadAgentConfig(LOCAL_CODEX_AGENT_KEY);
113
- const qoder = await adapter.loadAgentConfig(LOCAL_QODER_AGENT_KEY);
114
-
115
- expect(codex).toMatchObject({
116
- key: LOCAL_CODEX_AGENT_KEY,
117
- name: "Local Codex",
118
- apiSource: "cli",
119
- provider: "cli",
120
- cliProvider: "codex",
121
- });
122
- expect(qoder).toMatchObject({
123
- key: LOCAL_QODER_AGENT_KEY,
124
- name: "Local Qoder",
125
- apiSource: "cli",
126
- provider: "cli",
127
- cliProvider: "qoder",
128
- model: "Qwen3.7-Max",
129
- });
130
- expect((codex as any)?.runtimeBinding).toBeUndefined();
131
- expect((qoder as any)?.runtimeBinding).toBeUndefined();
132
- expect((codex as any)?.rawRecord?.runtimeBinding).toBeUndefined();
133
- expect((qoder as any)?.rawRecord?.runtimeBinding).toBeUndefined();
134
- });
135
-
136
- test("runs cli-provider agents through the local CLI executor instead of OpenAI-compatible direct mode", async () => {
137
- const cliExecutions: Array<{ provider: string; prompt: string; options: any }> = [];
138
- const adapter = createCliLocalRuntimeAdapter({
139
- env: {
140
- NOLO_LOCAL_USER_ID: "user-1",
141
- OPENAI_API_KEY: "sk-should-not-be-used",
142
- },
143
- db: {
144
- get: async (key) => {
145
- if (key !== "agent-user-1-frontend") throw new Error(`not found: ${key}`);
146
- return {
147
- dbKey: "agent-user-1-frontend",
148
- id: "frontend",
149
- name: "Frontend",
150
- prompt: "You are the frontend implementer.",
151
- apiSource: "cli",
152
- cliProvider: "agy",
153
- model: "gemini-3.1-pro",
154
- };
155
- },
156
- put: async () => {},
157
- batch: async () => {},
158
- iterator: () => (async function* () {})(),
159
- },
160
- cwd: "/repo/worktree",
161
- now: () => 1710000000000,
162
- createId: () => "01CLI",
163
- fetchImpl: async () => {
164
- throw new Error("OpenAI-compatible fetch should not be used for cli providers");
165
- },
166
- executeCli: async (provider, prompt, options) => {
167
- cliExecutions.push({ provider, prompt, options });
168
- return { text: "cli ok", raw: "cli ok", elapsed: 1 };
169
- },
170
- } as any);
171
-
172
- const result = await runLocalAgentTurn({
173
- adapter,
174
- agentRef: "frontend",
175
- input: "add tooltip",
176
- });
177
-
178
- expect(result).toMatchObject({
179
- content: "cli ok",
180
- model: "gemini-3.1-pro",
181
- });
182
- expect(cliExecutions).toHaveLength(1);
183
- expect(cliExecutions[0]).toMatchObject({
184
- provider: "agy",
185
- options: {
186
- model: "gemini-3.1-pro",
187
- cwd: "/repo/worktree",
188
- yolo: true,
189
- },
190
- });
191
- expect(cliExecutions[0].prompt).toContain("You are the frontend implementer.");
192
- expect(cliExecutions[0].prompt).toContain("add tooltip");
193
- });
194
-
195
- test("fails cli-provider local runs clearly when the requested local CLI is unavailable", async () => {
196
- const adapter = createCliLocalRuntimeAdapter({
197
- env: {
198
- NOLO_LOCAL_USER_ID: "user-1",
199
- OPENAI_API_KEY: "sk-should-not-be-used",
200
- },
201
- db: {
202
- get: async (key) => {
203
- if (key !== "agent-user-1-frontend") throw new Error(`not found: ${key}`);
204
- return {
205
- dbKey: "agent-user-1-frontend",
206
- id: "frontend",
207
- name: "Frontend",
208
- prompt: "You are the frontend implementer.",
209
- apiSource: "cli",
210
- cliProvider: "agy",
211
- };
212
- },
213
- put: async () => {},
214
- batch: async () => {},
215
- iterator: () => (async function* () {})(),
216
- },
217
- fetchImpl: async () => {
218
- throw new Error("OpenAI-compatible fetch should not be used for cli providers");
219
- },
220
- executeCli: async () => {
221
- throw new Error("agy: command not found");
222
- },
223
- } as any);
224
-
225
- await expect(runLocalAgentTurn({
226
- adapter,
227
- agentRef: "frontend",
228
- input: "add tooltip",
229
- })).rejects.toThrow("Local CLI provider \"agy\" is unavailable");
230
- });
231
-
232
- test("passes cli-provider image inputs to the CLI executor instead of rejecting", async () => {
233
- let cliCalledWith: any = null;
234
- const adapter = createCliLocalRuntimeAdapter({
235
- env: {
236
- NOLO_LOCAL_USER_ID: "user-1",
237
- },
238
- db: {
239
- get: async (key) => {
240
- if (key !== "agent-user-1-frontend") throw new Error(`not found: ${key}`);
241
- return {
242
- dbKey: "agent-user-1-frontend",
243
- id: "frontend",
244
- name: "Frontend",
245
- prompt: "You are the frontend implementer.",
246
- apiSource: "cli",
247
- cliProvider: "agy",
248
- };
249
- },
250
- put: async () => {},
251
- batch: async () => {},
252
- iterator: () => (async function* () {})(),
253
- },
254
- executeCli: async (provider, prompt, options) => {
255
- cliCalledWith = { provider, prompt, options };
256
- return { text: "image handled", raw: "", elapsed: 1 };
257
- },
258
- } as any);
259
-
260
- const result = await runLocalAgentTurn({
261
- adapter,
262
- agentRef: "frontend",
263
- input: [
264
- { type: "text", text: "look at this screenshot" },
265
- { type: "image_url", image_url: { url: "https://example.com/screen.png" } },
266
- ],
267
- });
268
-
269
- expect(result.content).toBe("image handled");
270
- expect(cliCalledWith).not.toBeNull();
271
- expect(cliCalledWith.provider).toBe("agy");
272
- expect(cliCalledWith.prompt).toContain("look at this screenshot");
273
- expect(cliCalledWith.options.imageInputs).toEqual([
274
- { source: "https://example.com/screen.png" },
275
- ]);
276
- });
277
-
278
- test("loads agent/history from LevelDB and saves dialog/message records back to LevelDB", async () => {
279
- const requests: Array<{ url: string; body: any; auth: string | null }> = [];
280
- const store = new Map<string, any>([
281
- ["agent-user-1-frontend", {
282
- dbKey: "agent-user-1-frontend",
283
- id: "frontend",
284
- name: "Frontend",
285
- prompt: "Fix UI",
286
- model: "gpt-4.1-mini",
287
- provider: "openai-compatible",
288
- }],
289
- ["dialog-user-1-dialog-existing", {
290
- dbKey: "dialog-user-1-dialog-existing",
291
- id: "dialog-existing",
292
- type: "dialog",
293
- userId: "user-1",
294
- }],
295
- ["dialog-dialog-existing-msg-001", {
296
- dbKey: "dialog-dialog-existing-msg-001",
297
- id: "msg-001",
298
- dialogId: "dialog-existing",
299
- role: "assistant",
300
- content: "previous answer",
301
- }],
302
- ]);
303
- const batchOps: any[] = [];
304
- const adapter = createCliLocalRuntimeAdapter({
305
- env: {
306
- NOLO_LOCAL_USER_ID: "user-1",
307
- OPENAI_API_KEY: "sk-local",
308
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
309
- },
310
- db: {
311
- get: async (key) => {
312
- if (!store.has(key)) throw new Error(`not found: ${key}`);
313
- return store.get(key);
314
- },
315
- put: async (key, value) => {
316
- store.set(key, value);
317
- },
318
- batch: async (ops) => {
319
- batchOps.push(...ops);
320
- for (const op of ops) {
321
- if (op.type === "put") store.set(op.key, op.value);
322
- }
323
- },
324
- iterator: ({ gte, lte }) => (async function* () {
325
- for (const entry of [...store.entries()].sort(([a], [b]) => a.localeCompare(b))) {
326
- if (entry[0] >= gte && entry[0] <= lte) yield entry;
327
- }
328
- })(),
329
- },
330
- now: () => 1710000000000,
331
- createId: () => "01LOCAL",
332
- fetchImpl: async (url, init) => {
333
- requests.push({
334
- url: String(url),
335
- body: JSON.parse(String(init?.body)),
336
- auth: new Headers(init?.headers).get("Authorization"),
337
- });
338
- return Response.json({
339
- choices: [{ message: { content: "local adapter ok" } }],
340
- usage: { prompt_tokens: 4, completion_tokens: 3 },
341
- });
342
- },
343
- });
344
-
345
- const result = await runLocalAgentTurn({
346
- adapter,
347
- agentRef: "frontend",
348
- input: "make it cleaner",
349
- continueDialogId: "dialog-existing",
350
- });
351
-
352
- expect(result).toMatchObject({
353
- content: "local adapter ok",
354
- model: "gpt-4.1-mini",
355
- dialogId: "dialog-existing",
356
- });
357
- expect(requests[0]).toMatchObject({
358
- url: "http://127.0.0.1:11434/v1/chat/completions",
359
- auth: "Bearer sk-local",
360
- body: {
361
- model: "gpt-4.1-mini",
362
- messages: [
363
- { role: "system", content: "Fix UI" },
364
- { role: "assistant", content: "previous answer" },
365
- { role: "user", content: "make it cleaner" },
366
- ],
367
- stream: false,
368
- },
369
- });
370
- expect(toolNamesFromRequest(requests[0])).toEqual(DEFAULT_PRIVATE_LOCAL_TOOL_NAMES);
371
- expect(batchOps.map((op) => op.key)).toEqual([
372
- "dialog-user-1-dialog-existing",
373
- "dialog-dialog-existing-msg-1710000000000-001",
374
- "dialog-dialog-existing-msg-1710000000000-002",
375
- ]);
376
- expect(store.get("dialog-user-1-dialog-existing")).toMatchObject({
377
- id: "dialog-existing",
378
- dbKey: "dialog-user-1-dialog-existing",
379
- type: "dialog",
380
- primaryAgentKey: "agent-user-1-frontend",
381
- status: "done",
382
- });
383
- expect(store.get("dialog-dialog-existing-msg-1710000000000-001")).toMatchObject({
384
- dialogId: "dialog-existing",
385
- role: "user",
386
- content: "make it cleaner",
387
- });
388
- expect(store.get("dialog-dialog-existing-msg-1710000000000-002")).toMatchObject({
389
- dialogId: "dialog-existing",
390
- role: "assistant",
391
- content: "local adapter ok",
392
- });
393
- });
394
-
395
- test("loads a missing explicit agent key through the hybrid store remote cache", async () => {
396
- const memory = new Map<string, any>();
397
- const requests: string[] = [];
398
- const adapter = createCliLocalRuntimeAdapter({
399
- env: {
400
- NOLO_LOCAL_USER_ID: "user-1",
401
- NOLO_SERVER: "https://us.nolo.chat",
402
- AUTH_TOKEN: "token-1",
403
- OPENAI_API_KEY: "sk-local",
404
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
405
- },
406
- db: {
407
- get: async (key) => {
408
- if (!memory.has(key)) throw new Error(`not found: ${key}`);
409
- return memory.get(key);
410
- },
411
- put: async (key, value) => {
412
- memory.set(key, value);
413
- },
414
- batch: async (ops) => {
415
- for (const op of ops) {
416
- if (op.type === "put") memory.set(op.key, op.value);
417
- }
418
- },
419
- iterator: () => (async function* () {})(),
420
- },
421
- createId: () => "01REMOTE",
422
- fetchImpl: async (url, init) => {
423
- requests.push(String(url));
424
- if (String(url).includes("/api/v1/db/read/")) {
425
- expect(new Headers(init?.headers).get("Authorization")).toBe("Bearer token-1");
426
- return Response.json({
427
- data: {
428
- dbKey: "agent-user-1-remote",
429
- name: "Remote cached",
430
- prompt: "Remote prompt",
431
- model: "gpt-4.1-mini",
432
- },
433
- });
434
- }
435
- return Response.json({
436
- choices: [{ message: { content: "remote cache ok" } }],
437
- });
438
- },
439
- });
440
-
441
- const result = await runLocalAgentTurn({
442
- adapter,
443
- agentRef: "agent-user-1-remote",
444
- input: "hello",
445
- });
446
-
447
- expect(result.content).toBe("remote cache ok");
448
- expect(requests[0]).toBe("https://us.nolo.chat/api/v1/db/read/agent-user-1-remote");
449
- expect(memory.get("agent-user-1-remote")).toMatchObject({
450
- name: "Remote cached",
451
- serverOrigin: "https://us.nolo.chat",
452
- });
453
- });
454
-
455
- test("keeps local runtime runnable when the configured local server is down but a cluster server can provide agent config", async () => {
456
- const memory = new Map<string, any>();
457
- const requests: string[] = [];
458
- const adapter = createCliLocalRuntimeAdapter({
459
- env: {
460
- NOLO_LOCAL_USER_ID: "user-1",
461
- NOLO_SERVER: "http://127.0.0.1:38123",
462
- AUTH_TOKEN: "token-1",
463
- OPENAI_API_KEY: "sk-local",
464
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
465
- },
466
- db: {
467
- get: async (key) => {
468
- if (!memory.has(key)) throw new Error(`not found: ${key}`);
469
- return memory.get(key);
470
- },
471
- put: async (key, value) => {
472
- memory.set(key, value);
473
- },
474
- batch: async (ops) => {
475
- for (const op of ops) {
476
- if (op.type === "put") memory.set(op.key, op.value);
477
- }
478
- },
479
- iterator: () => (async function* () {})(),
480
- },
481
- createId: () => "01CLUSTER",
482
- fetchImpl: async (url, init) => {
483
- const target = String(url);
484
- requests.push(target);
485
- if (target === "http://127.0.0.1:38123/api/v1/db/read/agent-user-1-cluster") {
486
- throw new Error("ConnectionRefused");
487
- }
488
- if (target === "https://nolo.chat/api/v1/db/read/agent-user-1-cluster") {
489
- expect(new Headers(init?.headers).get("Authorization")).toBe("Bearer token-1");
490
- return Response.json({
491
- data: {
492
- dbKey: "agent-user-1-cluster",
493
- name: "Cluster cached",
494
- prompt: "Use cached config",
495
- model: "gpt-4.1-mini",
496
- },
497
- });
498
- }
499
- if (target === "http://127.0.0.1:11434/v1/chat/completions") {
500
- return Response.json({
501
- choices: [{ message: { content: "cluster cache ok" } }],
502
- });
503
- }
504
- return new Response(null, { status: 404 });
505
- },
506
- });
507
-
508
- const result = await runLocalAgentTurn({
509
- adapter,
510
- agentRef: "agent-user-1-cluster",
511
- input: "hello",
512
- });
513
-
514
- expect(result.content).toBe("cluster cache ok");
515
- expect(requests).toEqual([
516
- "http://127.0.0.1:38123/api/v1/db/read/agent-user-1-cluster",
517
- "https://nolo.chat/api/v1/db/read/agent-user-1-cluster",
518
- "http://127.0.0.1:11434/v1/chat/completions",
519
- ]);
520
- expect(memory.get("agent-user-1-cluster")).toMatchObject({
521
- name: "Cluster cached",
522
- serverOrigin: "https://nolo.chat",
523
- });
524
- });
525
-
526
- test("uses agent-owned custom credentials for local OpenAI-compatible requests", async () => {
527
- const requests: Array<{ url: string; auth: string | null; apiKeyHeader: string | null; body: any }> = [];
528
- const store = new Map<string, any>([
529
- ["agent-user-1-custom", {
530
- dbKey: "agent-user-1-custom",
531
- id: "custom",
532
- prompt: "Use custom provider.",
533
- model: "custom-coder",
534
- provider: "custom-openai-compatible",
535
- apiSource: "custom",
536
- customProviderUrl: "https://provider.example/v1/chat/completions",
537
- apiKey: "sk-agent-custom",
538
- apiKeyHeader: "api-key",
539
- temperature: 0.2,
540
- max_tokens: 4096,
541
- reasoning_effort: "medium",
542
- }],
543
- ]);
544
- const adapter = createCliLocalRuntimeAdapter({
545
- env: {
546
- NOLO_LOCAL_USER_ID: "user-1",
547
- OPENAI_API_KEY: "sk-custom",
548
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
549
- },
550
- db: {
551
- get: async (key) => {
552
- if (!store.has(key)) throw new Error(`not found: ${key}`);
553
- return store.get(key);
554
- },
555
- put: async (key, value) => {
556
- store.set(key, value);
557
- },
558
- batch: async (ops) => {
559
- for (const op of ops) {
560
- if (op.type === "put") store.set(op.key, op.value);
561
- }
562
- },
563
- iterator: () => (async function* () {})(),
564
- },
565
- fetchImpl: async (url, init) => {
566
- requests.push({
567
- url: String(url),
568
- auth: new Headers(init?.headers).get("Authorization"),
569
- apiKeyHeader: new Headers(init?.headers).get("api-key"),
570
- body: JSON.parse(String(init?.body)),
571
- });
572
- return Response.json({
573
- choices: [{ message: { content: "custom ok" } }],
574
- });
575
- },
576
- });
577
-
578
- const result = await runLocalAgentTurn({
579
- adapter,
580
- agentRef: "custom",
581
- input: "hello",
582
- });
583
-
584
- expect(result.content).toBe("custom ok");
585
- expect(result.provider).toBe("custom-openai-compatible");
586
- expect(requests[0]).toMatchObject({
587
- url: "https://provider.example/v1/chat/completions",
588
- auth: null,
589
- apiKeyHeader: "sk-agent-custom",
590
- body: {
591
- model: "custom-coder",
592
- messages: [
593
- { role: "system", content: "Use custom provider." },
594
- { role: "user", content: "hello" },
595
- ],
596
- stream: false,
597
- temperature: 0.2,
598
- max_tokens: 4096,
599
- reasoning_effort: "medium",
600
- },
601
- });
602
- expect(toolNamesFromRequest(requests[0])).toEqual(DEFAULT_PRIVATE_LOCAL_TOOL_NAMES);
603
- });
604
-
605
- test("aborts stalled custom provider requests when timeoutMs is provided", async () => {
606
- const store = new Map<string, any>([
607
- ["agent-user-1-mimo", {
608
- dbKey: "agent-user-1-mimo",
609
- id: "mimo",
610
- prompt: "Use monthly mimo.",
611
- model: "mimo-v2.5-pro",
612
- provider: "custom",
613
- apiSource: "custom",
614
- customProviderUrl: "https://token-plan-cn.xiaomimimo.com/v1",
615
- apiKey: "mimo-monthly-key",
616
- }],
617
- ]);
618
- const adapter = createCliLocalRuntimeAdapter({
619
- env: {
620
- NOLO_LOCAL_USER_ID: "user-1",
621
- },
622
- store: {
623
- read: async (key) => store.get(key) ?? null,
624
- put: async (key, value) => {
625
- store.set(key, value);
626
- },
627
- batch: async (ops) => {
628
- for (const op of ops) {
629
- if (op.type === "put") store.set(op.key, op.value);
630
- }
631
- },
632
- iterator: () => (async function* () {})(),
633
- },
634
- fetchImpl: async (_url, init) => {
635
- if (init?.signal?.aborted) {
636
- throw init.signal.reason ?? new Error("aborted");
637
- }
638
- await new Promise((_, reject) => {
639
- init?.signal?.addEventListener("abort", () => reject(init.signal?.reason ?? new Error("aborted")));
640
- });
641
- throw new Error("unreachable");
642
- },
643
- });
644
-
645
- await expect(runLocalAgentTurn({
646
- adapter,
647
- agentRef: "mimo",
648
- input: "hello",
649
- timeoutMs: 10,
650
- })).rejects.toThrow(/timed out|aborted/i);
651
- });
652
-
653
- test("uses loopback transport for localhost custom providers when the default fetch path cannot connect", async () => {
654
- const store = new Map<string, any>([
655
- ["agent-user-1-localhost", {
656
- dbKey: "agent-user-1-localhost",
657
- id: "localhost",
658
- prompt: "Use localhost provider.",
659
- model: "Qwen3.6-27B-MTP-Q3_K_M.gguf",
660
- provider: "custom-openai-compatible",
661
- apiSource: "custom",
662
- customProviderUrl: "http://127.0.0.1:8080/v1/chat/completions",
663
- }],
664
- ]);
665
- const loopbackRequests: Array<{ url: string; body: any }> = [];
666
- const adapter = createCliLocalRuntimeAdapter({
667
- env: {
668
- NOLO_LOCAL_USER_ID: "user-1",
669
- },
670
- db: {
671
- get: async (key) => {
672
- if (!store.has(key)) throw new Error(`not found: ${key}`);
673
- return store.get(key);
674
- },
675
- put: async (key, value) => {
676
- store.set(key, value);
677
- },
678
- batch: async (ops) => {
679
- for (const op of ops) {
680
- if (op.type === "put") store.set(op.key, op.value);
681
- }
682
- },
683
- iterator: () => (async function* () {})(),
684
- },
685
- fetchImpl: async () => {
686
- throw new TypeError("Unable to connect. Is the computer able to access the url?");
687
- },
688
- loopbackRequest: async (url, init) => {
689
- loopbackRequests.push({
690
- url: String(url),
691
- body: JSON.parse(String(init?.body)),
692
- });
693
- return Response.json({
694
- choices: [{ message: { content: "loopback ok" } }],
695
- });
696
- },
697
- });
698
-
699
- const result = await runLocalAgentTurn({
700
- adapter,
701
- agentRef: "localhost",
702
- input: "hello",
703
- });
704
-
705
- expect(result.content).toBe("loopback ok");
706
- expect(loopbackRequests).toHaveLength(1);
707
- expect(loopbackRequests[0]).toMatchObject({
708
- url: "http://127.0.0.1:8080/v1/chat/completions",
709
- body: {
710
- model: "Qwen3.6-27B-MTP-Q3_K_M.gguf",
711
- messages: [
712
- { role: "system", content: "Use localhost provider." },
713
- { role: "user", content: "hello" },
714
- ],
715
- stream: false,
716
- },
717
- });
718
- expect(toolNamesFromRequest(loopbackRequests[0])).toEqual(DEFAULT_PRIVATE_LOCAL_TOOL_NAMES);
719
- });
720
-
721
- test("uses the Nolo chat proxy when local provider keys are absent", async () => {
722
- const requests: Array<{ url: string; auth: string | null; body: any }> = [];
723
- const store = new Map<string, any>([
724
- ["agent-user-1-frontend", {
725
- dbKey: "agent-user-1-frontend",
726
- id: "frontend",
727
- prompt: "Fix UI.",
728
- model: "accounts/fireworks/models/kimi-k2p6",
729
- provider: "fireworks",
730
- tools: ["writeFile"],
731
- }],
732
- ]);
733
- const adapter = createCliLocalRuntimeAdapter({
734
- env: {
735
- NOLO_LOCAL_USER_ID: "user-1",
736
- NOLO_SERVER: "https://us.nolo.chat",
737
- AUTH_TOKEN: "token-1",
738
- },
739
- db: {
740
- get: async (key) => {
741
- if (!store.has(key)) throw new Error(`not found: ${key}`);
742
- return store.get(key);
743
- },
744
- put: async (key, value) => {
745
- store.set(key, value);
746
- },
747
- batch: async (ops) => {
748
- for (const op of ops) {
749
- if (op.type === "put") store.set(op.key, op.value);
750
- }
751
- },
752
- iterator: () => (async function* () {})(),
753
- },
754
- fetchImpl: async (url, init) => {
755
- requests.push({
756
- url: String(url),
757
- auth: new Headers(init?.headers).get("Authorization"),
758
- body: JSON.parse(String(init?.body)),
759
- });
760
- return Response.json({
761
- choices: [{ message: { content: "platform ok" } }],
762
- usage: { prompt_tokens: 7, completion_tokens: 2 },
763
- });
764
- },
765
- });
766
-
767
- const result = await runLocalAgentTurn({
768
- adapter,
769
- agentRef: "frontend",
770
- input: "make notifications cleaner",
771
- });
772
-
773
- expect(result.content).toBe("platform ok");
774
- expect(result.provider).toBe("fireworks");
775
- expect(requests[0]).toMatchObject({
776
- url: "https://us.nolo.chat/api/v1/chat",
777
- auth: "Bearer token-1",
778
- body: {
779
- model: "accounts/fireworks/models/kimi-k2p6",
780
- messages: [
781
- { role: "system", content: "Fix UI." },
782
- { role: "user", content: "make notifications cleaner" },
783
- ],
784
- stream: false,
785
- tool_choice: "auto",
786
- url: "https://api.fireworks.ai/inference/v1/chat/completions",
787
- provider: "fireworks",
788
- agentKey: "agent-user-1-frontend",
789
- },
790
- });
791
- expect(toolNamesFromRequest(requests[0])).toEqual([
792
- ...LEGACY_WRITE_LOCAL_CODING_TOOL_NAMES,
793
- ...DEFAULT_PRIVATE_NOLO_WORKSPACE_TOOL_NAMES,
794
- ]);
795
- });
796
-
797
- test("uses the Nolo chat proxy for platform agents even when direct provider env exists", async () => {
798
- const requests: Array<{ url: string; auth: string | null; body: any }> = [];
799
- const store = new Map<string, any>([
800
- ["agent-user-1-frontend", {
801
- dbKey: "agent-user-1-frontend",
802
- id: "frontend",
803
- prompt: "Fix UI.",
804
- model: "accounts/fireworks/models/kimi-k2p6",
805
- provider: "fireworks",
806
- apiSource: "platform",
807
- useServerProxy: true,
808
- tools: ["readFile"],
809
- }],
810
- ]);
811
- const adapter = createCliLocalRuntimeAdapter({
812
- env: {
813
- NOLO_LOCAL_USER_ID: "user-1",
814
- NOLO_SERVER: "https://us.nolo.chat",
815
- AUTH_TOKEN: "token-1",
816
- OPENAI_API_KEY: "sk-direct",
817
- },
818
- db: {
819
- get: async (key) => {
820
- if (!store.has(key)) throw new Error(`not found: ${key}`);
821
- return store.get(key);
822
- },
823
- put: async (key, value) => {
824
- store.set(key, value);
825
- },
826
- batch: async (ops) => {
827
- for (const op of ops) {
828
- if (op.type === "put") store.set(op.key, op.value);
829
- }
830
- },
831
- iterator: () => (async function* () {})(),
832
- },
833
- fetchImpl: async (url, init) => {
834
- requests.push({
835
- url: String(url),
836
- auth: new Headers(init?.headers).get("Authorization"),
837
- body: JSON.parse(String(init?.body)),
838
- });
839
- return Response.json({
840
- choices: [{ message: { content: "platform ok" } }],
841
- });
842
- },
843
- });
844
-
845
- const result = await runLocalAgentTurn({
846
- adapter,
847
- agentRef: "frontend",
848
- input: "inspect",
849
- });
850
-
851
- expect(result.content).toBe("platform ok");
852
- expect(requests[0]).toMatchObject({
853
- url: "https://us.nolo.chat/api/v1/chat",
854
- auth: "Bearer token-1",
855
- body: {
856
- provider: "fireworks",
857
- apiSource: "platform",
858
- agentKey: "agent-user-1-frontend",
859
- },
860
- });
861
- });
862
-
863
- test("retries transient certificate failures from the platform chat proxy", async () => {
864
- let attempts = 0;
865
- const store = new Map<string, any>([
866
- ["agent-user-1-frontend", {
867
- dbKey: "agent-user-1-frontend",
868
- id: "frontend",
869
- prompt: "Fix UI.",
870
- model: "accounts/fireworks/models/kimi-k2p6",
871
- provider: "fireworks",
872
- apiSource: "platform",
873
- useServerProxy: true,
874
- }],
875
- ]);
876
- const adapter = createCliLocalRuntimeAdapter({
877
- env: {
878
- NOLO_LOCAL_USER_ID: "user-1",
879
- NOLO_SERVER: "https://us.nolo.chat",
880
- AUTH_TOKEN: "token-1",
881
- },
882
- db: {
883
- get: async (key) => {
884
- if (!store.has(key)) throw new Error(`not found: ${key}`);
885
- return store.get(key);
886
- },
887
- put: async (key, value) => {
888
- store.set(key, value);
889
- },
890
- batch: async (ops) => {
891
- for (const op of ops) {
892
- if (op.type === "put") store.set(op.key, op.value);
893
- }
894
- },
895
- iterator: () => (async function* () {})(),
896
- },
897
- fetchImpl: async () => {
898
- attempts += 1;
899
- if (attempts <= 2) {
900
- throw new Error("unknown certificate verification error");
901
- }
902
- return Response.json({
903
- choices: [{ message: { content: "platform retry ok" } }],
904
- });
905
- },
906
- sleep: async () => {},
907
- });
908
-
909
- const result = await runLocalAgentTurn({
910
- adapter,
911
- agentRef: "frontend",
912
- input: "inspect",
913
- });
914
-
915
- expect(result.content).toBe("platform retry ok");
916
- expect(attempts).toBe(3);
917
- });
918
-
919
- test("keeps retrying repeated transient certificate failures with backoff hooks", async () => {
920
- let attempts = 0;
921
- const retryDelays: number[] = [];
922
- const store = new Map<string, any>([
923
- ["agent-user-1-frontend", {
924
- dbKey: "agent-user-1-frontend",
925
- id: "frontend",
926
- prompt: "Fix UI.",
927
- model: "accounts/fireworks/models/kimi-k2p6",
928
- provider: "fireworks",
929
- apiSource: "platform",
930
- useServerProxy: true,
931
- }],
932
- ]);
933
- const adapter = createCliLocalRuntimeAdapter({
934
- env: {
935
- NOLO_LOCAL_USER_ID: "user-1",
936
- NOLO_SERVER: "https://us.nolo.chat",
937
- AUTH_TOKEN: "token-1",
938
- },
939
- db: {
940
- get: async (key) => {
941
- if (!store.has(key)) throw new Error(`not found: ${key}`);
942
- return store.get(key);
943
- },
944
- put: async (key, value) => {
945
- store.set(key, value);
946
- },
947
- batch: async (ops) => {
948
- for (const op of ops) {
949
- if (op.type === "put") store.set(op.key, op.value);
950
- }
951
- },
952
- iterator: () => (async function* () {})(),
953
- },
954
- fetchImpl: async () => {
955
- attempts += 1;
956
- if (attempts <= 5) {
957
- throw new Error("unknown certificate verification error");
958
- }
959
- return Response.json({
960
- choices: [{ message: { content: "platform longer retry ok" } }],
961
- });
962
- },
963
- sleep: async (ms) => {
964
- retryDelays.push(ms);
965
- },
966
- });
967
-
968
- const result = await runLocalAgentTurn({
969
- adapter,
970
- agentRef: "frontend",
971
- input: "inspect",
972
- });
973
-
974
- expect(result.content).toBe("platform longer retry ok");
975
- expect(attempts).toBe(6);
976
- expect(retryDelays.length).toBeGreaterThanOrEqual(3);
977
- expect(retryDelays[0]).toBeGreaterThan(0);
978
- });
979
-
980
- test("saves local tool call trace and shell metadata into the local dialog", async () => {
981
- const store = new Map<string, any>([
982
- ["agent-user-1-shell", {
983
- dbKey: "agent-user-1-shell",
984
- id: "shell",
985
- prompt: "Use shell.",
986
- model: "gpt-4.1-mini",
987
- }],
988
- ]);
989
- const adapter = createCliLocalRuntimeAdapter({
990
- env: {
991
- NOLO_LOCAL_USER_ID: "user-1",
992
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
993
- },
994
- db: {
995
- get: async (key) => {
996
- if (!store.has(key)) throw new Error(`not found: ${key}`);
997
- return store.get(key);
998
- },
999
- put: async (key, value) => {
1000
- store.set(key, value);
1001
- },
1002
- batch: async (ops) => {
1003
- for (const op of ops) {
1004
- if (op.type === "put") store.set(op.key, op.value);
1005
- }
1006
- },
1007
- iterator: () => (async function* () {})(),
1008
- },
1009
- cwd: import.meta.dir,
1010
- now: () => 1710000000000,
1011
- createId: () => "01TRACE",
1012
- localToolExecutors: {
1013
- execShell: async () => ({
1014
- content: "stdout:\ntrace-ok\n\nexitCode: 0",
1015
- metadata: { exitCode: 0, timedOut: false },
1016
- }),
1017
- },
1018
- fetchImpl: async (_url, init) => {
1019
- const body = JSON.parse(String(init?.body));
1020
- const hasToolResult = body.messages.some((message: any) => message.role === "tool");
1021
- if (!hasToolResult) {
1022
- return Response.json({
1023
- choices: [{
1024
- message: {
1025
- content: "",
1026
- tool_calls: [{
1027
- id: "call-shell",
1028
- type: "function",
1029
- function: {
1030
- name: "execShell",
1031
- arguments: JSON.stringify({
1032
- cmd: process.platform === "win32"
1033
- ? "Write-Output trace-ok"
1034
- : "printf trace-ok",
1035
- }),
1036
- },
1037
- }],
1038
- },
1039
- }],
1040
- });
1041
- }
1042
- return Response.json({
1043
- choices: [{ message: { content: "done" } }],
1044
- });
1045
- },
1046
- });
1047
-
1048
- const result = await runLocalAgentTurn({
1049
- adapter,
1050
- agentRef: "shell",
1051
- input: "inspect",
1052
- });
1053
-
1054
- expect(result.dialogId).toBe("01TRACE");
1055
- expect(store.get("dialog-user-1-01TRACE")).toMatchObject({
1056
- toolCallCount: 1,
1057
- localRuntime: expect.objectContaining({
1058
- host: "cli",
1059
- worktreePath: import.meta.dir,
1060
- }),
1061
- });
1062
- const messages = [...store.entries()]
1063
- .filter(([key]) => key.startsWith("dialog-01TRACE-msg-"))
1064
- .sort(([a], [b]) => a.localeCompare(b))
1065
- .map(([, value]) => value);
1066
- expect(messages.map((message) => message.role)).toEqual([
1067
- "user",
1068
- "assistant",
1069
- "tool",
1070
- "assistant",
1071
- ]);
1072
- expect(messages[1]).toMatchObject({
1073
- tool_calls: [{
1074
- id: "call-shell",
1075
- function: { name: "execShell" },
1076
- }],
1077
- });
1078
- expect(messages[2]).toMatchObject({
1079
- role: "tool",
1080
- toolCallId: "call-shell",
1081
- metadata: { exitCode: 0 },
1082
- });
1083
- expect(messages[2].content).toContain("trace-ok");
1084
- expect(messages[3]).toMatchObject({
1085
- role: "assistant",
1086
- content: "done",
1087
- });
1088
- });
1089
-
1090
- test("returns tool budget errors to the local loop", async () => {
1091
- const store = new Map<string, any>([
1092
- ["agent-user-1-reader", {
1093
- dbKey: "agent-user-1-reader",
1094
- id: "reader",
1095
- prompt: "Read narrowly",
1096
- model: "gpt-4.1-mini",
1097
- provider: "openai-compatible",
1098
- tools: ["readFile"],
1099
- }],
1100
- ]);
1101
- let requestCount = 0;
1102
- const adapter = createCliLocalRuntimeAdapter({
1103
- env: {
1104
- NOLO_LOCAL_USER_ID: "user-1",
1105
- NOLO_LOCAL_OPENAI_BASE_URL: "https://llm.example/v1",
1106
- NOLO_LOCAL_OPENAI_API_KEY: "sk-test",
1107
- NOLO_LOCAL_TOOL_BUDGETS: "readFile=1",
1108
- },
1109
- store: {
1110
- read: async (key) => {
1111
- if (!store.has(key)) throw new Error(`not found: ${key}`);
1112
- return store.get(key);
1113
- },
1114
- put: async (key, value) => {
1115
- store.set(key, value);
1116
- },
1117
- batch: async (ops) => {
1118
- for (const op of ops) {
1119
- if (op.type === "put") store.set(op.key, op.value);
1120
- }
1121
- },
1122
- iterator: () => (async function* () {})(),
1123
- },
1124
- cwd: import.meta.dir,
1125
- now: () => 1710000000000,
1126
- createId: () => "01BUDGET",
1127
- localToolExecutors: {
1128
- readFile: async () => ({ content: "file content" }),
1129
- },
1130
- fetchImpl: async (_url, init) => {
1131
- requestCount += 1;
1132
- const body = JSON.parse(String(init?.body));
1133
- const toolMessages = body.messages.filter((message: any) => message.role === "tool");
1134
- if (toolMessages.some((message: any) => String(message.content).includes("exceeded local tool budget"))) {
1135
- return Response.json({ choices: [{ message: { content: "budget handled" } }] });
1136
- }
1137
- return Response.json({
1138
- choices: [{
1139
- message: {
1140
- content: "",
1141
- tool_calls: [{
1142
- id: `call-read-${requestCount}`,
1143
- type: "function",
1144
- function: {
1145
- name: "readFile",
1146
- arguments: JSON.stringify({ path: "file.ts" }),
1147
- },
1148
- }],
1149
- },
1150
- }],
1151
- });
1152
- },
1153
- });
1154
-
1155
- const result = await runLocalAgentTurn({
1156
- adapter,
1157
- agentRef: "agent-user-1-reader",
1158
- input: "inspect",
1159
- });
1160
-
1161
- expect(result.content).toBe("budget handled");
1162
- const messages = [...store.values()];
1163
- expect(messages.some((message) => String(message.content).includes("exceeded local tool budget 1"))).toBe(true);
1164
- });
1165
-
1166
- test("continues a local dialog instead of creating a new one", async () => {
1167
- const store = new Map<string, any>([
1168
- ["agent-user-1-frontend", {
1169
- dbKey: "agent-user-1-frontend",
1170
- id: "frontend",
1171
- prompt: "Fix UI",
1172
- model: "gpt-4.1-mini",
1173
- }],
1174
- ["dialog-user-1-dialog-existing", {
1175
- dbKey: "dialog-user-1-dialog-existing",
1176
- id: "dialog-existing",
1177
- type: "dialog",
1178
- userId: "user-1",
1179
- title: "Existing dialog",
1180
- }],
1181
- ["dialog-dialog-existing-msg-001", {
1182
- dbKey: "dialog-dialog-existing-msg-001",
1183
- id: "msg-001",
1184
- dialogId: "dialog-existing",
1185
- role: "assistant",
1186
- content: "previous answer",
1187
- }],
1188
- ]);
1189
- const adapter = createCliLocalRuntimeAdapter({
1190
- env: {
1191
- NOLO_LOCAL_USER_ID: "user-1",
1192
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
1193
- },
1194
- db: {
1195
- get: async (key) => {
1196
- if (!store.has(key)) throw new Error(`not found: ${key}`);
1197
- return store.get(key);
1198
- },
1199
- put: async (key, value) => {
1200
- store.set(key, value);
1201
- },
1202
- batch: async (ops) => {
1203
- for (const op of ops) {
1204
- if (op.type === "put") store.set(op.key, op.value);
1205
- }
1206
- },
1207
- iterator: ({ gte, lte }) => (async function* () {
1208
- for (const entry of [...store.entries()].sort(([a], [b]) => a.localeCompare(b))) {
1209
- if (entry[0] >= gte && entry[0] <= lte) yield entry;
1210
- }
1211
- })(),
1212
- },
1213
- now: () => 1710000000000,
1214
- createId: () => "SHOULDNOTUSE",
1215
- fetchImpl: async (_url, init) => {
1216
- const body = JSON.parse(String(init?.body));
1217
- expect(body.messages).toContainEqual({
1218
- role: "assistant",
1219
- content: "previous answer",
1220
- });
1221
- return Response.json({
1222
- choices: [{ message: { content: "continued" } }],
1223
- });
1224
- },
1225
- });
1226
-
1227
- const result = await runLocalAgentTurn({
1228
- adapter,
1229
- agentRef: "frontend",
1230
- input: "continue",
1231
- continueDialogId: "dialog-existing",
1232
- });
1233
-
1234
- expect(result.dialogId).toBe("dialog-existing");
1235
- expect(store.has("dialog-user-1-SHOULDNOTUSE")).toBe(false);
1236
- expect(store.get("dialog-user-1-dialog-existing")).toMatchObject({
1237
- id: "dialog-existing",
1238
- title: "Existing dialog",
1239
- status: "done",
1240
- });
1241
- expect([...store.keys()].filter((key) => key.startsWith("dialog-dialog-existing-msg-"))).toContain(
1242
- "dialog-dialog-existing-msg-1710000000000-001"
1243
- );
1244
- });
1245
-
1246
- test("passes image_url message parts through to OpenAI-compatible providers", async () => {
1247
- const requests: Array<{ body: any }> = [];
1248
- const adapter = createCliLocalRuntimeAdapter({
1249
- env: {
1250
- OPENAI_API_KEY: "sk-local",
1251
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
1252
- },
1253
- db: {
1254
- get: async () => ({
1255
- dbKey: "agent-local-vision",
1256
- prompt: "Describe images.",
1257
- model: "gpt-4.1-mini",
1258
- }),
1259
- put: async () => {},
1260
- batch: async () => {},
1261
- iterator: () => (async function* () {})(),
1262
- },
1263
- fetchImpl: async (_url, init) => {
1264
- requests.push({ body: JSON.parse(String(init?.body)) });
1265
- return Response.json({
1266
- choices: [{ message: { content: "image ok" } }],
1267
- });
1268
- },
1269
- });
1270
-
1271
- await runLocalAgentTurn({
1272
- adapter,
1273
- agentRef: "vision",
1274
- input: [
1275
- { type: "text", text: "describe this" },
1276
- { type: "image_url", image_url: { url: "https://example.com/a.png" } },
1277
- ],
1278
- });
1279
-
1280
- expect(requests[0]?.body.messages.at(-1)).toEqual({
1281
- role: "user",
1282
- content: [
1283
- { type: "text", text: "describe this" },
1284
- { type: "image_url", image_url: { url: "https://example.com/a.png" } },
1285
- ],
1286
- });
1287
- });
1288
-
1289
- test("allows registered execShell by default", async () => {
1290
- const adapter = createCliLocalRuntimeAdapter({
1291
- env: {},
1292
- localToolExecutors: {
1293
- execShell: async (call) => ({ content: `shell:${call.arguments}` }),
1294
- },
1295
- fetchImpl: async () => Response.json({}),
1296
- });
1297
-
1298
- const result = await adapter.executeTool({
1299
- id: "call-1",
1300
- name: "execShell",
1301
- arguments: "{\"cmd\":\"pwd\"}",
1302
- });
1303
-
1304
- expect(result.content).toContain("\"cmd\":\"pwd\"");
1305
- });
1306
-
1307
- test("executes explicitly allowed registered local tools declared by the agent", async () => {
1308
- const store = new Map<string, any>([
1309
- ["agent-user-1-reader", {
1310
- dbKey: "agent-user-1-reader",
1311
- id: "reader",
1312
- prompt: "Read files.",
1313
- toolNames: ["readFile"],
1314
- }],
1315
- ]);
1316
- const adapter = createCliLocalRuntimeAdapter({
1317
- env: {
1318
- NOLO_LOCAL_USER_ID: "user-1",
1319
- NOLO_LOCAL_ALLOWED_TOOLS: "readFile",
1320
- },
1321
- db: {
1322
- get: async (key) => {
1323
- if (!store.has(key)) throw new Error(`not found: ${key}`);
1324
- return store.get(key);
1325
- },
1326
- put: async () => {},
1327
- batch: async () => {},
1328
- iterator: () => (async function* () {})(),
1329
- },
1330
- localToolExecutors: {
1331
- readFile: async (call) => ({ content: `read:${call.arguments}` }),
1332
- },
1333
- fetchImpl: async () => Response.json({}),
1334
- });
1335
-
1336
- await adapter.loadAgentConfig("reader");
1337
- const result = await adapter.executeTool({
1338
- id: "call-1",
1339
- name: "readFile",
1340
- arguments: "{\"path\":\"README.md\"}",
1341
- });
1342
-
1343
- expect(result.content).toContain("README.md");
1344
- });
1345
-
1346
- test("advertises execShell to OpenAI-compatible providers by default", async () => {
1347
- const requests: Array<{ body: any }> = [];
1348
- const adapter = createCliLocalRuntimeAdapter({
1349
- env: {
1350
- OPENAI_API_KEY: "sk-local",
1351
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
1352
- },
1353
- db: {
1354
- get: async () => ({
1355
- dbKey: "agent-local-shell",
1356
- prompt: "Use shell.",
1357
- model: "gpt-4.1-mini",
1358
- }),
1359
- put: async () => {},
1360
- batch: async () => {},
1361
- iterator: () => (async function* () {})(),
1362
- },
1363
- fetchImpl: async (_url, init) => {
1364
- requests.push({ body: JSON.parse(String(init?.body)) });
1365
- return Response.json({
1366
- choices: [{ message: { content: "done" } }],
1367
- });
1368
- },
1369
- });
1370
-
1371
- await runLocalAgentTurn({
1372
- adapter,
1373
- agentRef: "shell",
1374
- input: "pwd",
1375
- });
1376
-
1377
- expect(toolNamesFromRequest(requests[0])).toEqual([
1378
- ...SHELL_LOCAL_CODING_TOOL_NAMES,
1379
- ...DEFAULT_PRIVATE_NOLO_WORKSPACE_TOOL_NAMES,
1380
- ]);
1381
- });
1382
-
1383
- test("keeps monthly Mimo local model tools to the compact coding surface", async () => {
1384
- const requests: Array<{ body: any }> = [];
1385
- const adapter = createCliLocalRuntimeAdapter({
1386
- env: {
1387
- OPENAI_API_KEY: "sk-local",
1388
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
1389
- },
1390
- db: {
1391
- get: async () => ({
1392
- dbKey: MIMO_MONTH_AGENT_KEY,
1393
- prompt: "Use local coding tools.",
1394
- model: "mimo-v2.5-pro",
1395
- provider: "custom",
1396
- tools: [
1397
- "read",
1398
- "searchDialogMessages",
1399
- "searchFiles",
1400
- "codeSearch",
1401
- "listFiles",
1402
- "readFile",
1403
- "writeFile",
1404
- "editFile",
1405
- "searchFiles",
1406
- "legacyLocalAlias",
1407
- "applyPatch",
1408
- "execShell",
1409
- "checkEnv",
1410
- "queryTableRows",
1411
- ],
1412
- }),
1413
- put: async () => {},
1414
- batch: async () => {},
1415
- iterator: () => (async function* () {})(),
1416
- },
1417
- fetchImpl: async (_url, init) => {
1418
- requests.push({ body: JSON.parse(String(init?.body)) });
1419
- return Response.json({
1420
- choices: [{ message: { content: "done" } }],
1421
- });
1422
- },
1423
- });
1424
-
1425
- await runLocalAgentTurn({
1426
- adapter,
1427
- agentRef: MIMO_MONTH_AGENT_KEY,
1428
- input: "inspect cwd",
1429
- });
1430
-
1431
- expect(toolNamesFromRequest(requests[0])).toEqual(SHELL_LOCAL_CODING_TOOL_NAMES);
1432
- });
1433
-
1434
- test("can expose only declared local workspace tools for tool ablations", async () => {
1435
- const requests: Array<{ body: any }> = [];
1436
- const adapter = createCliLocalRuntimeAdapter({
1437
- env: {
1438
- OPENAI_API_KEY: "sk-local",
1439
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
1440
- NOLO_LOCAL_WORKSPACE_TOOLSET: "declared-only",
1441
- },
1442
- db: {
1443
- get: async () => ({
1444
- dbKey: MIMO_MONTH_AGENT_KEY,
1445
- prompt: "Use exactly the declared local tools.",
1446
- model: "mimo-v2.5-pro",
1447
- provider: "custom",
1448
- tools: ["listFiles", "readFile", "execShell"],
1449
- }),
1450
- put: async () => {},
1451
- batch: async () => {},
1452
- iterator: () => (async function* () {})(),
1453
- },
1454
- fetchImpl: async (_url, init) => {
1455
- requests.push({ body: JSON.parse(String(init?.body)) });
1456
- return Response.json({
1457
- choices: [{ message: { content: "done" } }],
1458
- });
1459
- },
1460
- });
1461
-
1462
- await runLocalAgentTurn({
1463
- adapter,
1464
- agentRef: MIMO_MONTH_AGENT_KEY,
1465
- input: "inspect cwd",
1466
- });
1467
-
1468
- expect(toolNamesFromRequest(requests[0])).toEqual(["listFiles", "readFile", "execShell"]);
1469
- });
1470
-
1471
- test("defaults local workspace tools to strategy descriptions and rich parameters", async () => {
1472
- const requests: Array<{ body: any }> = [];
1473
- const adapter = createCliLocalRuntimeAdapter({
1474
- env: {
1475
- OPENAI_API_KEY: "sk-local",
1476
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
1477
- NOLO_LOCAL_WORKSPACE_TOOLSET: "declared-only",
1478
- },
1479
- db: {
1480
- get: async () => ({
1481
- dbKey: MIMO_MONTH_AGENT_KEY,
1482
- prompt: "Use local coding tools.",
1483
- model: "mimo-v2.5-pro",
1484
- provider: "custom",
1485
- tools: ["listFiles", "readFile", "globFiles", "searchFiles"],
1486
- }),
1487
- put: async () => {},
1488
- batch: async () => {},
1489
- iterator: () => (async function* () {})(),
1490
- },
1491
- fetchImpl: async (_url, init) => {
1492
- requests.push({ body: JSON.parse(String(init?.body)) });
1493
- return Response.json({
1494
- choices: [{ message: { content: "done" } }],
1495
- });
1496
- },
1497
- });
1498
-
1499
- await runLocalAgentTurn({
1500
- adapter,
1501
- agentRef: MIMO_MONTH_AGENT_KEY,
1502
- input: "inspect cwd",
1503
- });
1504
-
1505
- const tools = new Map(
1506
- requests[0]?.body.tools.map((tool: any) => [tool.function.name, tool.function]),
1507
- );
1508
- const listFiles = tools.get("listFiles") as any;
1509
- const readFile = tools.get("readFile") as any;
1510
- const globFiles = tools.get("globFiles") as any;
1511
- const searchFiles = tools.get("searchFiles") as any;
1512
-
1513
- expect(listFiles.description).toContain("not for path-pattern discovery across the repo");
1514
- expect(publicSchemaKeys(listFiles)).toEqual([
1515
- "path",
1516
- "maxDepth",
1517
- "maxResults",
1518
- "entryType",
1519
- ]);
1520
- expect(readFile.description).toContain("Use line ranges");
1521
- expect(publicSchemaKeys(readFile)).toEqual([
1522
- "path",
1523
- "startLine",
1524
- "endLine",
1525
- "maxLines",
1526
- "tailLines",
1527
- ]);
1528
- expect(globFiles.description).toContain("any file discovery task");
1529
- expect(publicSchemaKeys(globFiles)).toEqual([
1530
- "pattern",
1531
- "path",
1532
- "exclude",
1533
- "includeIgnored",
1534
- "maxResults",
1535
- ]);
1536
- expect(searchFiles.description).toContain("using ripgrep when available");
1537
- expect(publicSchemaKeys(searchFiles)).toEqual([
1538
- "query",
1539
- "path",
1540
- "exclude",
1541
- "includeIgnored",
1542
- "maxResults",
1543
- "literal",
1544
- "caseSensitive",
1545
- "contextLines",
1546
- ]);
1547
- });
1548
-
1549
- test("can vary globFiles schema through local runtime env", async () => {
1550
- const requests: Array<{ body: any }> = [];
1551
- const adapter = createCliLocalRuntimeAdapter({
1552
- env: {
1553
- OPENAI_API_KEY: "sk-local",
1554
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
1555
- NOLO_GLOBFILES_DESCRIPTION_VARIANT: "antiShell",
1556
- NOLO_GLOBFILES_PARAMETER_VARIANT: "rich",
1557
- },
1558
- db: {
1559
- get: async () => ({
1560
- dbKey: MIMO_MONTH_AGENT_KEY,
1561
- prompt: "Use local coding tools.",
1562
- model: "mimo-v2.5-pro",
1563
- provider: "custom",
1564
- tools: ["globFiles"],
1565
- }),
1566
- put: async () => {},
1567
- batch: async () => {},
1568
- iterator: () => (async function* () {})(),
1569
- },
1570
- fetchImpl: async (_url, init) => {
1571
- requests.push({ body: JSON.parse(String(init?.body)) });
1572
- return Response.json({
1573
- choices: [{ message: { content: "done" } }],
1574
- });
1575
- },
1576
- });
1577
-
1578
- await runLocalAgentTurn({
1579
- adapter,
1580
- agentRef: MIMO_MONTH_AGENT_KEY,
1581
- input: "find tests",
1582
- });
1583
-
1584
- const globFiles = requests[0]?.body.tools.find((tool: any) => tool.function.name === "globFiles")?.function;
1585
- expect(globFiles.description).toContain("Do not use execShell or listFiles for path discovery");
1586
- expect(publicSchemaKeys(globFiles)).toEqual([
1587
- "pattern",
1588
- "path",
1589
- "exclude",
1590
- "includeIgnored",
1591
- "maxResults",
1592
- ]);
1593
- });
1594
-
1595
- test("can vary listFiles schema through local runtime env", async () => {
1596
- const requests: Array<{ body: any }> = [];
1597
- const adapter = createCliLocalRuntimeAdapter({
1598
- env: {
1599
- OPENAI_API_KEY: "sk-local",
1600
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
1601
- NOLO_LISTFILES_DESCRIPTION_VARIANT: "antiShell",
1602
- NOLO_LISTFILES_PARAMETER_VARIANT: "rich",
1603
- },
1604
- db: {
1605
- get: async () => ({
1606
- dbKey: MIMO_MONTH_AGENT_KEY,
1607
- prompt: "Use local coding tools.",
1608
- model: "mimo-v2.5-pro",
1609
- provider: "custom",
1610
- tools: ["listFiles"],
1611
- }),
1612
- put: async () => {},
1613
- batch: async () => {},
1614
- iterator: () => (async function* () {})(),
1615
- },
1616
- fetchImpl: async (_url, init) => {
1617
- requests.push({ body: JSON.parse(String(init?.body)) });
1618
- return Response.json({
1619
- choices: [{ message: { content: "done" } }],
1620
- });
1621
- },
1622
- });
1623
-
1624
- await runLocalAgentTurn({
1625
- adapter,
1626
- agentRef: MIMO_MONTH_AGENT_KEY,
1627
- input: "list directories",
1628
- });
1629
-
1630
- const listFiles = requests[0]?.body.tools.find((tool: any) => tool.function.name === "listFiles")?.function;
1631
- expect(listFiles.description).toContain("Do not use execShell with ls/find/tree");
1632
- expect(publicSchemaKeys(listFiles)).toEqual([
1633
- "path",
1634
- "maxDepth",
1635
- "maxResults",
1636
- "entryType",
1637
- ]);
1638
- });
1639
-
1640
- test("can vary readFile schema through local runtime env", async () => {
1641
- const requests: Array<{ body: any }> = [];
1642
- const adapter = createCliLocalRuntimeAdapter({
1643
- env: {
1644
- OPENAI_API_KEY: "sk-local",
1645
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
1646
- NOLO_READFILE_DESCRIPTION_VARIANT: "strategy",
1647
- NOLO_READFILE_PARAMETER_VARIANT: "rich",
1648
- },
1649
- db: {
1650
- get: async () => ({
1651
- dbKey: MIMO_MONTH_AGENT_KEY,
1652
- prompt: "Use local coding tools.",
1653
- model: "mimo-v2.5-pro",
1654
- provider: "custom",
1655
- tools: ["readFile"],
1656
- }),
1657
- put: async () => {},
1658
- batch: async () => {},
1659
- iterator: () => (async function* () {})(),
1660
- },
1661
- fetchImpl: async (_url, init) => {
1662
- requests.push({ body: JSON.parse(String(init?.body)) });
1663
- return Response.json({
1664
- choices: [{ message: { content: "done" } }],
1665
- });
1666
- },
1667
- });
1668
-
1669
- await runLocalAgentTurn({
1670
- adapter,
1671
- agentRef: MIMO_MONTH_AGENT_KEY,
1672
- input: "read a file range",
1673
- });
1674
-
1675
- const readFile = requests[0]?.body.tools.find((tool: any) => tool.function.name === "readFile")?.function;
1676
- expect(readFile.description).toContain("Use line ranges");
1677
- expect(readFile.parameters.properties.maxLines.description).toContain("each readFile preview consumes one budget slot");
1678
- expect(publicSchemaKeys(readFile)).toEqual([
1679
- "path",
1680
- "startLine",
1681
- "endLine",
1682
- "maxLines",
1683
- "tailLines",
1684
- ]);
1685
- });
1686
-
1687
- test("can vary searchFiles schema through local runtime env", async () => {
1688
- const requests: Array<{ body: any }> = [];
1689
- const adapter = createCliLocalRuntimeAdapter({
1690
- env: {
1691
- OPENAI_API_KEY: "sk-local",
1692
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
1693
- NOLO_SEARCHFILES_DESCRIPTION_VARIANT: "antiShell",
1694
- NOLO_SEARCHFILES_PARAMETER_VARIANT: "rich",
1695
- },
1696
- db: {
1697
- get: async () => ({
1698
- dbKey: MIMO_MONTH_AGENT_KEY,
1699
- prompt: "Use local coding tools.",
1700
- model: "mimo-v2.5-pro",
1701
- provider: "custom",
1702
- tools: ["searchFiles"],
1703
- }),
1704
- put: async () => {},
1705
- batch: async () => {},
1706
- iterator: () => (async function* () {})(),
1707
- },
1708
- fetchImpl: async (_url, init) => {
1709
- requests.push({ body: JSON.parse(String(init?.body)) });
1710
- return Response.json({
1711
- choices: [{ message: { content: "done" } }],
1712
- });
1713
- },
1714
- });
1715
-
1716
- await runLocalAgentTurn({
1717
- adapter,
1718
- agentRef: MIMO_MONTH_AGENT_KEY,
1719
- input: "find TODO",
1720
- });
1721
-
1722
- const searchFiles = requests[0]?.body.tools.find((tool: any) => tool.function.name === "searchFiles")?.function;
1723
- expect(searchFiles.description).toContain("Do not use execShell for content search");
1724
- expect(publicSchemaKeys(searchFiles)).toEqual([
1725
- "query",
1726
- "path",
1727
- "exclude",
1728
- "includeIgnored",
1729
- "maxResults",
1730
- "literal",
1731
- "caseSensitive",
1732
- "contextLines",
1733
- ]);
1734
- });
1735
-
1736
- test("allows default semantic workspace tools without legacy agent tool declarations", async () => {
1737
- const workspaceRoot = mkdtempSync(join(tmpdir(), "nolo-cli-runtime-"));
1738
- try {
1739
- await Bun.write(join(workspaceRoot, "README.md"), "local ok\n");
1740
- const adapter = createCliLocalRuntimeAdapter({
1741
- env: {},
1742
- cwd: workspaceRoot,
1743
- db: {
1744
- get: async () => ({
1745
- dbKey: "agent-local-default-tools",
1746
- prompt: "Use local workspace tools.",
1747
- model: "gpt-4.1-mini",
1748
- }),
1749
- put: async () => {},
1750
- batch: async () => {},
1751
- iterator: () => (async function* () {})(),
1752
- },
1753
- fetchImpl: async () => Response.json({}),
1754
- });
1755
-
1756
- await adapter.loadAgentConfig("default-tools");
1757
- await expect(adapter.executeTool({
1758
- id: "call-read",
1759
- name: "readFile",
1760
- arguments: JSON.stringify({ path: "README.md" }),
1761
- })).resolves.toMatchObject({
1762
- content: "local ok\n",
1763
- });
1764
- } finally {
1765
- rmSync(workspaceRoot, { recursive: true, force: true });
1766
- }
1767
- });
1768
-
1769
- test("exposes declared server table write tools in local runtime requests", async () => {
1770
- const requests: Array<{ body: any }> = [];
1771
- const adapter = createCliLocalRuntimeAdapter({
1772
- env: {
1773
- OPENAI_API_KEY: "sk-local",
1774
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
1775
- },
1776
- db: {
1777
- get: async () => ({
1778
- dbKey: "agent-local-table",
1779
- prompt: "Use table tools.",
1780
- model: "gpt-4.1-mini",
1781
- toolNames: ["createTable", "addTableRow", "addTableRows"],
1782
- }),
1783
- put: async () => {},
1784
- batch: async () => {},
1785
- iterator: () => (async function* () {})(),
1786
- },
1787
- fetchImpl: async (_url, init) => {
1788
- requests.push({ body: JSON.parse(String(init?.body)) });
1789
- return Response.json({
1790
- choices: [{ message: { content: "done" } }],
1791
- });
1792
- },
1793
- });
1794
-
1795
- await runLocalAgentTurn({
1796
- adapter,
1797
- agentRef: "table",
1798
- input: "采集并写入 table",
1799
- });
1800
-
1801
- const toolNames = toolNamesFromRequest(requests[0]);
1802
- expect(toolNames).toContain("createTable");
1803
- expect(toolNames).toContain("addTableRow");
1804
- expect(toolNames).toContain("addTableRows");
1805
- });
1806
-
1807
- test("executes declared createTable through the server table bridge when capture is explicit", async () => {
1808
- const requests: Array<{ url: string; auth: string | null; body: any }> = [];
1809
- const adapter = createCliLocalRuntimeAdapter({
1810
- env: {
1811
- NOLO_SERVER: "https://us.nolo.chat",
1812
- AUTH_TOKEN: "token-1",
1813
- },
1814
- db: {
1815
- get: async () => ({
1816
- dbKey: "agent-local-table-write",
1817
- toolNames: ["createTable"],
1818
- }),
1819
- put: async () => {},
1820
- batch: async () => {},
1821
- iterator: () => (async function* () {})(),
1822
- },
1823
- fetchImpl: async (url, init) => {
1824
- requests.push({
1825
- url: String(url),
1826
- auth: new Headers(init?.headers).get("authorization"),
1827
- body: JSON.parse(String(init?.body)),
1828
- });
1829
- return Response.json({
1830
- ok: true,
1831
- tenantId: "user-1",
1832
- tableId: "table-1",
1833
- });
1834
- },
1835
- });
1836
-
1837
- await adapter.loadAgentConfig("table-write");
1838
- const result = await adapter.executeTool({
1839
- id: "call-create-table",
1840
- name: "createTable",
1841
- userInput: "采集这个用户并写入 table",
1842
- arguments: JSON.stringify({
1843
- title: "XHS profile",
1844
- purpose: "agent_eval_workbench",
1845
- columns: [{ name: "nickname" }],
1846
- }),
1847
- });
1848
-
1849
- expect(requests).toEqual([
1850
- {
1851
- url: "https://us.nolo.chat/api/table/create",
1852
- auth: "Bearer token-1",
1853
- body: {
1854
- title: "XHS profile",
1855
- purpose: "agent_eval_workbench",
1856
- columns: [{ name: "nickname" }],
1857
- },
1858
- },
1859
- ]);
1860
- expect(result.content).toContain("\"tableId\":\"table-1\"");
1861
- expect(result.metadata).toMatchObject({
1862
- serverPlatformTool: true,
1863
- tableWrite: true,
1864
- });
1865
- });
1866
-
1867
- test("blocks local table writes when the current user request is not explicit capture", async () => {
1868
- const adapter = createCliLocalRuntimeAdapter({
1869
- env: {
1870
- NOLO_SERVER: "https://us.nolo.chat",
1871
- AUTH_TOKEN: "token-1",
1872
- },
1873
- db: {
1874
- get: async () => ({
1875
- dbKey: "agent-local-table-blocked",
1876
- toolNames: ["createTable"],
1877
- }),
1878
- put: async () => {},
1879
- batch: async () => {},
1880
- iterator: () => (async function* () {})(),
1881
- },
1882
- fetchImpl: async () => {
1883
- throw new Error("blocked createTable must not reach the server");
1884
- },
1885
- });
1886
-
1887
- await adapter.loadAgentConfig("table-blocked");
1888
- const result = await adapter.executeTool({
1889
- id: "call-create-table-blocked",
1890
- name: "createTable",
1891
- userInput: "总结这个用户画像",
1892
- arguments: JSON.stringify({
1893
- title: "XHS profile",
1894
- columns: [{ name: "nickname" }],
1895
- }),
1896
- });
1897
-
1898
- const parsed = JSON.parse(result.content);
1899
- expect(parsed.error).toBe("knowledge_capture_requires_confirmation");
1900
- expect(result.metadata).toMatchObject({
1901
- serverPlatformTool: true,
1902
- tableWriteBlocked: true,
1903
- });
1904
- });
1905
-
1906
- test("adds typed CLI workspace tools to the default nolo local agent request", async () => {
1907
- const requests: Array<{ body: any }> = [];
1908
- const adapter = createCliLocalRuntimeAdapter({
1909
- env: {
1910
- OPENAI_API_KEY: "sk-local",
1911
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
1912
- },
1913
- db: {
1914
- get: async () => ({
1915
- dbKey: "agent-pub-01NOLOAPPBLD000000019KCKT0",
1916
- id: "01NOLOAPPBLD000000019KCKT0",
1917
- name: "nolo",
1918
- prompt: "Route through typed tools.",
1919
- model: "gpt-4.1-mini",
1920
- tools: ["fetchWebpage"],
1921
- }),
1922
- put: async () => {},
1923
- batch: async () => {},
1924
- iterator: () => (async function* () {})(),
1925
- },
1926
- fetchImpl: async (_url, init) => {
1927
- requests.push({ body: JSON.parse(String(init?.body)) });
1928
- return Response.json({
1929
- choices: [{ message: { content: "done" } }],
1930
- });
1931
- },
1932
- });
1933
-
1934
- await runLocalAgentTurn({
1935
- adapter,
1936
- agentRef: "agent-pub-01NOLOAPPBLD000000019KCKT0",
1937
- input: "帮我总结最近 10 个对话",
1938
- });
1939
-
1940
- const toolNames = toolNamesFromRequest(requests[0]);
1941
- expect(toolNames).toContain("listDialogs");
1942
- expect(toolNames).toContain("readDialog");
1943
- expect(toolNames).toContain("listAgents");
1944
- expect(toolNames).toContain("readSpace");
1945
- expect(toolNames).toContain("queryTableRows");
1946
- });
1947
-
1948
- test("executes typed CLI workspace tools through whitelisted nolo commands", async () => {
1949
- const spawnCalls: Array<{ cmd: string[]; env: NodeJS.ProcessEnv }> = [];
1950
- const originalSpawn = Bun.spawn;
1951
- Bun.spawn = ((options: { cmd: string[]; env: NodeJS.ProcessEnv }) => {
1952
- spawnCalls.push(options);
1953
- return {
1954
- stdout: new ReadableStream({
1955
- start(controller) {
1956
- controller.enqueue(new TextEncoder().encode("dialog output\n"));
1957
- controller.close();
1958
- },
1959
- }),
1960
- stderr: new ReadableStream({
1961
- start(controller) {
1962
- controller.close();
1963
- },
1964
- }),
1965
- exited: Promise.resolve(0),
1966
- };
1967
- }) as unknown as typeof Bun.spawn;
1968
-
1969
- try {
1970
- const adapter = createCliLocalRuntimeAdapter({
1971
- env: {
1972
- NOLO_LOCAL_USER_ID: "user-1",
1973
- AUTH_TOKEN: "token-1",
1974
- },
1975
- db: {
1976
- get: async () => ({
1977
- dbKey: "agent-pub-01NOLOAPPBLD000000019KCKT0",
1978
- id: "01NOLOAPPBLD000000019KCKT0",
1979
- }),
1980
- put: async () => {},
1981
- batch: async () => {},
1982
- iterator: () => (async function* () {})(),
1983
- },
1984
- fetchImpl: async () => Response.json({}),
1985
- });
1986
-
1987
- await adapter.loadAgentConfig("agent-pub-01NOLOAPPBLD000000019KCKT0");
1988
- const result = await adapter.executeTool({
1989
- id: "call-list-dialogs",
1990
- name: "listDialogs",
1991
- arguments: JSON.stringify({ limit: 3 }),
1992
- });
1993
-
1994
- expect(result.content).toBe("dialog output\n");
1995
- expect(result.metadata).toMatchObject({
1996
- cliWorkspaceTool: true,
1997
- exitCode: 0,
1998
- });
1999
- expect(spawnCalls[0]?.cmd.at(-5)?.endsWith("index.ts")).toBe(true);
2000
- expect(spawnCalls[0]?.cmd.slice(-4)).toEqual([
2001
- "dialog",
2002
- "list",
2003
- "--limit",
2004
- "3",
2005
- ]);
2006
- } finally {
2007
- Bun.spawn = originalSpawn;
2008
- }
2009
- });
2010
-
2011
- test("runs execShell locally by default", async () => {
2012
- const adapter = createCliLocalRuntimeAdapter({
2013
- env: {},
2014
- db: {
2015
- get: async () => ({
2016
- dbKey: "agent-local-shell",
2017
- toolNames: ["execShell"],
2018
- }),
2019
- put: async () => {},
2020
- batch: async () => {},
2021
- iterator: () => (async function* () {})(),
2022
- },
2023
- cwd: import.meta.dir,
2024
- localToolExecutors: {
2025
- execShell: async () => ({
2026
- content: import.meta.dir,
2027
- metadata: { exitCode: 0, timedOut: false },
2028
- }),
2029
- },
2030
- fetchImpl: async () => Response.json({}),
2031
- });
2032
-
2033
- await adapter.loadAgentConfig("shell");
2034
- const result = await adapter.executeTool({
2035
- id: "call-1",
2036
- name: "execShell",
2037
- arguments: "{\"cmd\":\"pwd\"}",
2038
- });
2039
-
2040
- expect(result.content).toContain(import.meta.dir);
2041
- expect(result.metadata).toMatchObject({ exitCode: 0 });
2042
- });
2043
-
2044
- test("applies runtime policy shell settings to local executors without adding a timeout", async () => {
2045
- const requests: Array<{ body: any }> = [];
2046
- const adapter = createCliLocalRuntimeAdapter({
2047
- env: {
2048
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
2049
- },
2050
- db: {
2051
- get: async () => ({
2052
- dbKey: "agent-local-shell-limits",
2053
- prompt: "Use shell when needed.",
2054
- model: "qwen-coder",
2055
- runtimeToolPolicy: {
2056
- version: 1,
2057
- runtimeTools: ["execShell"],
2058
- shell: { enabled: true, mode: "worktree", maxOutputBytes: 120 },
2059
- },
2060
- }),
2061
- put: async () => {},
2062
- batch: async () => {},
2063
- iterator: () => (async function* () {})(),
2064
- },
2065
- cwd: import.meta.dir,
2066
- fetchImpl: async (_url, init) => {
2067
- requests.push({ body: JSON.parse(String(init?.body)) });
2068
- if (requests.length === 1) {
2069
- return Response.json({
2070
- choices: [{
2071
- message: {
2072
- content: "",
2073
- tool_calls: [{
2074
- id: "call-1",
2075
- type: "function",
2076
- function: {
2077
- name: "execShell",
2078
- arguments: JSON.stringify({
2079
- cmd: process.platform === "win32"
2080
- ? "'abcdefghijklmnopqrstuvwxyz0123456789'"
2081
- : "node -e 'console.log(\"x\".repeat(50))'",
2082
- }),
2083
- },
2084
- }],
2085
- },
2086
- }],
2087
- });
2088
- }
2089
- return Response.json({
2090
- choices: [{ message: { content: "limits applied" } }],
2091
- });
2092
- },
2093
- });
2094
-
2095
- const result = await runLocalAgentTurn({
2096
- adapter,
2097
- agentRef: "shell-limits",
2098
- input: "run output limit check",
2099
- });
2100
-
2101
- expect(result.content).toBe("limits applied");
2102
- const toolResult = requests[1]?.body.messages.at(-1)?.content ?? "";
2103
- expect(toolResult).toContain("exitCode: 0");
2104
- expect(toolResult).not.toContain("command timed out");
2105
- });
2106
-
2107
- test("accepts execShell aliases from the local model", async () => {
2108
- const requests: Array<{ body: any }> = [];
2109
- const adapter = createCliLocalRuntimeAdapter({
2110
- env: {
2111
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
2112
- },
2113
- db: {
2114
- get: async () => ({
2115
- dbKey: "agent-local-shell-alias",
2116
- prompt: "Use shell when needed.",
2117
- model: "qwen-coder",
2118
- toolNames: ["execShell"],
2119
- }),
2120
- put: async () => {},
2121
- batch: async () => {},
2122
- iterator: () => (async function* () {})(),
2123
- },
2124
- cwd: import.meta.dir,
2125
- localToolExecutors: {
2126
- execShell: async () => ({
2127
- content: import.meta.dir,
2128
- metadata: { exitCode: 0, timedOut: false },
2129
- }),
2130
- },
2131
- fetchImpl: async (_url, init) => {
2132
- requests.push({ body: JSON.parse(String(init?.body)) });
2133
- if (requests.length === 1) {
2134
- return Response.json({
2135
- choices: [{
2136
- message: {
2137
- content: "",
2138
- tool_calls: [{
2139
- id: "call-1",
2140
- type: "function",
2141
- function: { name: "runCommand", arguments: "{\"cmd\":\"pwd\"}" },
2142
- }],
2143
- },
2144
- }],
2145
- });
2146
- }
2147
- return Response.json({
2148
- choices: [{ message: { content: "alias ok" } }],
2149
- });
2150
- },
2151
- });
2152
-
2153
- const result = await runLocalAgentTurn({
2154
- adapter,
2155
- agentRef: "shell",
2156
- input: "print cwd",
2157
- });
2158
-
2159
- expect(result.content).toBe("alias ok");
2160
- expect(requests[1]?.body.messages.at(-1)?.content).toContain(import.meta.dir);
2161
- });
2162
-
2163
- test("blocks destructive local execShell calls unless the user explicitly asked to delete", async () => {
2164
- let executorCalls = 0;
2165
- const adapter = createCliLocalRuntimeAdapter({
2166
- env: {
2167
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
2168
- },
2169
- db: {
2170
- get: async () => ({
2171
- dbKey: "agent-local-shell-guard",
2172
- prompt: "Use shell when useful.",
2173
- model: "qwen-coder",
2174
- toolNames: ["execShell"],
2175
- }),
2176
- put: async () => {},
2177
- batch: async () => {},
2178
- iterator: () => (async function* () {})(),
2179
- },
2180
- cwd: import.meta.dir,
2181
- localToolExecutors: {
2182
- execShell: async () => {
2183
- executorCalls += 1;
2184
- return {
2185
- content: "should not run",
2186
- };
2187
- },
2188
- },
2189
- fetchImpl: async (_url, init) => {
2190
- const body = JSON.parse(String(init?.body));
2191
- const lastToolMessage = [...body.messages]
2192
- .reverse()
2193
- .find((message: any) => message.role === "tool");
2194
- if (lastToolMessage) {
2195
- expect(String(lastToolMessage.content)).toContain(
2196
- "destructive_action_requires_confirmation",
2197
- );
2198
- return Response.json({
2199
- choices: [{ message: { content: "guard ok" } }],
2200
- });
2201
- }
2202
- return Response.json({
2203
- choices: [{
2204
- message: {
2205
- content: "",
2206
- tool_calls: [{
2207
- id: "call-1",
2208
- type: "function",
2209
- function: {
2210
- name: "execShell",
2211
- arguments: "{\"cmd\":\"rm -rf ./tmp\"}",
2212
- },
2213
- }],
2214
- },
2215
- }],
2216
- });
2217
- },
2218
- });
2219
-
2220
- const result = await runLocalAgentTurn({
2221
- adapter,
2222
- agentRef: "shell",
2223
- input: "inspect cwd but don't delete files",
2224
- });
2225
-
2226
- expect(result.content).toBe("guard ok");
2227
- expect(executorCalls).toBe(0);
2228
- });
2229
-
2230
- test("exposes runtime policy tools to the local model even when toolNames omits them", async () => {
2231
- const requests: Array<{ body: any }> = [];
2232
- const adapter = createCliLocalRuntimeAdapter({
2233
- env: {
2234
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
2235
- },
2236
- db: {
2237
- get: async () => ({
2238
- dbKey: "agent-local-policy-shell",
2239
- prompt: "Use shell when needed.",
2240
- model: "qwen-coder",
2241
- runtimeToolPolicy: {
2242
- version: 1,
2243
- runtimeTools: ["execShell"],
2244
- },
2245
- }),
2246
- put: async () => {},
2247
- batch: async () => {},
2248
- iterator: () => (async function* () {})(),
2249
- },
2250
- cwd: import.meta.dir,
2251
- localToolExecutors: {
2252
- execShell: async () => ({
2253
- content: import.meta.dir,
2254
- metadata: { exitCode: 0, timedOut: false },
2255
- }),
2256
- },
2257
- fetchImpl: async (_url, init) => {
2258
- requests.push({ body: JSON.parse(String(init?.body)) });
2259
- if (requests.length === 1) {
2260
- return Response.json({
2261
- choices: [{
2262
- message: {
2263
- content: "",
2264
- tool_calls: [{
2265
- id: "call-1",
2266
- type: "function",
2267
- function: { name: "execShell", arguments: "{\"cmd\":\"pwd\"}" },
2268
- }],
2269
- },
2270
- }],
2271
- });
2272
- }
2273
- return Response.json({
2274
- choices: [{ message: { content: "policy shell ok" } }],
2275
- });
2276
- },
2277
- });
2278
-
2279
- const result = await runLocalAgentTurn({
2280
- adapter,
2281
- agentRef: "shell",
2282
- input: "print cwd",
2283
- });
2284
-
2285
- expect(result.content).toBe("policy shell ok");
2286
- expect(toolNamesFromRequest(requests[0])).toContain("execShell");
2287
- expect(requests[1]?.body.messages.at(-1)?.content).toContain(import.meta.dir);
2288
- });
2289
-
2290
- test("treats runtime policy visual tools as declared local tools", async () => {
2291
- const adapter = createCliLocalRuntimeAdapter({
2292
- env: {
2293
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
2294
- },
2295
- db: {
2296
- get: async () => ({
2297
- dbKey: "agent-local-visual",
2298
- prompt: "Inspect the page.",
2299
- model: "qwen-coder",
2300
- runtimeToolPolicy: {
2301
- version: 1,
2302
- runtimeTools: ["captureVisualState"],
2303
- },
2304
- }),
2305
- put: async () => {},
2306
- batch: async () => {},
2307
- iterator: () => (async function* () {})(),
2308
- },
2309
- cwd: import.meta.dir,
2310
- localToolExecutors: {
2311
- captureVisualState: async () => ({
2312
- content: "{\"status\":\"ok\"}",
2313
- }),
2314
- },
2315
- fetchImpl: async (_url, init) => {
2316
- expect(toolNamesFromRequest({ body: JSON.parse(String(init?.body)) })).toContain("captureVisualState");
2317
- return Response.json({
2318
- choices: [{ message: { content: "visual ok" } }],
2319
- });
2320
- },
2321
- });
2322
-
2323
- await adapter.loadAgentConfig("visual");
2324
- await expect(adapter.executeTool({
2325
- id: "call-visual",
2326
- name: "captureVisualState",
2327
- arguments: JSON.stringify({ waitSelector: "body" }),
2328
- })).resolves.toMatchObject({
2329
- content: "{\"status\":\"ok\"}",
2330
- });
2331
- });
2332
-
2333
- test("exposes read_xhs_profile to OpenAI-compatible providers when the agent declares it", async () => {
2334
- const requests: Array<{ body: any }> = [];
2335
- const adapter = createCliLocalRuntimeAdapter({
2336
- env: {
2337
- OPENAI_API_KEY: "sk-local",
2338
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
2339
- },
2340
- db: {
2341
- get: async () => ({
2342
- dbKey: "agent-local-xhs",
2343
- prompt: "Read XHS profile.",
2344
- model: "gpt-4.1-mini",
2345
- toolNames: ["read_xhs_profile"],
2346
- }),
2347
- put: async () => {},
2348
- batch: async () => {},
2349
- iterator: () => (async function* () {})(),
2350
- },
2351
- fetchImpl: async (_url, init) => {
2352
- requests.push({ body: JSON.parse(String(init?.body)) });
2353
- return Response.json({
2354
- choices: [{ message: { content: "done" } }],
2355
- });
2356
- },
2357
- });
2358
-
2359
- await runLocalAgentTurn({
2360
- adapter,
2361
- agentRef: "xhs",
2362
- input: "读取小红书用户主页",
2363
- });
2364
-
2365
- expect(toolNamesFromRequest(requests[0])).toContain("read_xhs_profile");
2366
- });
2367
-
2368
- test("exposes read_x_post to OpenAI-compatible providers when the agent declares it", async () => {
2369
- const requests: Array<{ body: any }> = [];
2370
- const adapter = createCliLocalRuntimeAdapter({
2371
- env: {
2372
- OPENAI_API_KEY: "sk-local",
2373
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
2374
- },
2375
- db: {
2376
- get: async () => ({
2377
- dbKey: "agent-local-x-post",
2378
- prompt: "Read X posts.",
2379
- model: "gpt-4.1-mini",
2380
- toolNames: ["read_x_post"],
2381
- }),
2382
- put: async () => {},
2383
- batch: async () => {},
2384
- iterator: () => (async function* () {})(),
2385
- },
2386
- fetchImpl: async (_url, init) => {
2387
- requests.push({ body: JSON.parse(String(init?.body)) });
2388
- return Response.json({
2389
- choices: [{ message: { content: "done" } }],
2390
- });
2391
- },
2392
- });
2393
-
2394
- await runLocalAgentTurn({
2395
- adapter,
2396
- agentRef: "x-post",
2397
- input: "读取 X 帖子",
2398
- });
2399
-
2400
- expect(toolNamesFromRequest(requests[0])).toContain("read_x_post");
2401
- });
2402
-
2403
- test("adds read_x_post to local web-capable agent tool surface", async () => {
2404
- const requests: Array<{ body: any }> = [];
2405
- const adapter = createCliLocalRuntimeAdapter({
2406
- env: {
2407
- OPENAI_API_KEY: "sk-local",
2408
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
2409
- },
2410
- db: {
2411
- get: async () => ({
2412
- dbKey: "agent-local-web-reader",
2413
- prompt: "Read web pages.",
2414
- model: "gpt-4.1-mini",
2415
- toolNames: ["fetchWebpage"],
2416
- }),
2417
- put: async () => {},
2418
- batch: async () => {},
2419
- iterator: () => (async function* () {})(),
2420
- },
2421
- fetchImpl: async (_url, init) => {
2422
- requests.push({ body: JSON.parse(String(init?.body)) });
2423
- return Response.json({
2424
- choices: [{ message: { content: "done" } }],
2425
- });
2426
- },
2427
- });
2428
-
2429
- await runLocalAgentTurn({
2430
- adapter,
2431
- agentRef: "web-reader",
2432
- input: "读取 X 帖子",
2433
- });
2434
-
2435
- expect(toolNamesFromRequest(requests[0])).toContain("read_x_post");
2436
- });
2437
-
2438
- test("does not expose read_xhs_profile when the agent does not declare it", async () => {
2439
- const requests: Array<{ body: any }> = [];
2440
- const adapter = createCliLocalRuntimeAdapter({
2441
- env: {
2442
- OPENAI_API_KEY: "sk-local",
2443
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
2444
- },
2445
- db: {
2446
- get: async () => ({
2447
- dbKey: "agent-local-no-xhs",
2448
- prompt: "Be helpful.",
2449
- model: "gpt-4.1-mini",
2450
- }),
2451
- put: async () => {},
2452
- batch: async () => {},
2453
- iterator: () => (async function* () {})(),
2454
- },
2455
- fetchImpl: async (_url, init) => {
2456
- requests.push({ body: JSON.parse(String(init?.body)) });
2457
- return Response.json({
2458
- choices: [{ message: { content: "done" } }],
2459
- });
2460
- },
2461
- });
2462
-
2463
- await runLocalAgentTurn({
2464
- adapter,
2465
- agentRef: "no-xhs",
2466
- input: "hello",
2467
- });
2468
-
2469
- expect(toolNamesFromRequest(requests[0])).not.toContain("read_xhs_profile");
2470
- });
2471
-
2472
- test("executes read_xhs_profile locally through the desktop bridge", async () => {
2473
- const xhsCalls: Array<{ args: any }> = [];
2474
- const adapter = createCliLocalRuntimeAdapter({
2475
- env: {
2476
- NOLO_LOCAL_USER_ID: "user-1",
2477
- },
2478
- db: {
2479
- get: async () => ({
2480
- dbKey: "agent-user-1-xhs",
2481
- id: "xhs-agent",
2482
- prompt: "Read XHS.",
2483
- toolNames: ["read_xhs_profile"],
2484
- }),
2485
- put: async () => {},
2486
- batch: async () => {},
2487
- iterator: () => (async function* () {})(),
2488
- },
2489
- localToolExecutors: {
2490
- read_xhs_profile: async (call) => {
2491
- const parsed = JSON.parse(call.arguments || "{}");
2492
- xhsCalls.push({ args: parsed });
2493
- return {
2494
- content: JSON.stringify({
2495
- ok: true,
2496
- data: {
2497
- profile: { nickname: "test-soul", redId: "12345" },
2498
- notes: [],
2499
- noteDetails: [],
2500
- analysis: {
2501
- totalNotes: 0,
2502
- commentBuckets: [],
2503
- },
2504
- },
2505
- }),
2506
- metadata: { xhsLocalBridge: true },
2507
- };
2508
- },
2509
- },
2510
- fetchImpl: async () => Response.json({}),
2511
- });
2512
-
2513
- await adapter.loadAgentConfig("xhs-agent");
2514
- const result = await adapter.executeTool({
2515
- id: "call-xhs-1",
2516
- name: "read_xhs_profile",
2517
- arguments: JSON.stringify({
2518
- url: "https://www.xiaohongshu.com/user/profile/5d2be8720000000010007556",
2519
- maxScrollPages: 3,
2520
- }),
2521
- });
2522
-
2523
- expect(xhsCalls).toHaveLength(1);
2524
- expect(xhsCalls[0].args.url).toBe(
2525
- "https://www.xiaohongshu.com/user/profile/5d2be8720000000010007556"
2526
- );
2527
- expect(xhsCalls[0].args.maxScrollPages).toBe(3);
2528
- expect(result.metadata).toMatchObject({ xhsLocalBridge: true });
2529
- const parsed = JSON.parse(result.content);
2530
- expect(parsed.ok).toBe(true);
2531
- expect(parsed.data.profile.nickname).toBe("test-soul");
2532
- });
2533
-
2534
- test("default read_x_post executor calls the local bridge reader", async () => {
2535
- const readerCalls: Array<{ args: any }> = [];
2536
- const adapter = createCliLocalRuntimeAdapter({
2537
- env: {
2538
- NOLO_LOCAL_USER_ID: "user-1",
2539
- },
2540
- db: {
2541
- get: async () => ({
2542
- dbKey: "agent-user-1-x-post-default",
2543
- id: "x-post-default",
2544
- prompt: "Read X posts.",
2545
- toolNames: ["read_x_post"],
2546
- }),
2547
- put: async () => {},
2548
- batch: async () => {},
2549
- iterator: () => (async function* () {})(),
2550
- },
2551
- readXPost: async (args) => {
2552
- readerCalls.push({ args });
2553
- return {
2554
- rawData: {
2555
- ok: true,
2556
- backend: "desktop_local_browser",
2557
- fetchedAt: "2026-06-08T00:00:00.000Z",
2558
- data: {
2559
- id: "2063842222307704944",
2560
- url: "https://x.com/BohuTANG/status/2063842222307704944",
2561
- text: "mock x post",
2562
- author: {
2563
- handle: "BohuTANG",
2564
- displayName: "Bohu",
2565
- },
2566
- },
2567
- } as any,
2568
- displayData: "已读取 X 帖子:@BohuTANG",
2569
- };
2570
- },
2571
- fetchImpl: async () => Response.json({}),
2572
- });
2573
-
2574
- await adapter.loadAgentConfig("x-post-default");
2575
- const result = await adapter.executeTool({
2576
- id: "call-x-post-default",
2577
- name: "read_x_post",
2578
- arguments: JSON.stringify({
2579
- url: "https://x.com/BohuTANG/status/2063842222307704944",
2580
- keepOpen: true,
2581
- }),
2582
- });
2583
-
2584
- expect(readerCalls).toHaveLength(1);
2585
- expect(readerCalls[0].args).toMatchObject({
2586
- url: "https://x.com/BohuTANG/status/2063842222307704944",
2587
- keepOpen: true,
2588
- });
2589
- expect(result.metadata).toMatchObject({ xPostLocalBridge: true });
2590
- const parsed = JSON.parse(result.content);
2591
- expect(parsed.ok).toBe(true);
2592
- expect(parsed.data.text).toBe("mock x post");
2593
- });
2594
-
2595
- test("default read_xhs_profile executor calls the local bridge reader", async () => {
2596
- const readerCalls: Array<{ args: any; thunkApi: any }> = [];
2597
- const adapter = createCliLocalRuntimeAdapter({
2598
- env: {
2599
- NOLO_LOCAL_USER_ID: "user-1",
2600
- },
2601
- db: {
2602
- get: async () => ({
2603
- dbKey: "agent-user-1-xhs-default",
2604
- id: "xhs-default",
2605
- prompt: "Read XHS.",
2606
- toolNames: ["read_xhs_profile"],
2607
- }),
2608
- put: async () => {},
2609
- batch: async () => {},
2610
- iterator: () => (async function* () {})(),
2611
- },
2612
- readXhsProfile: async (args, thunkApi) => {
2613
- readerCalls.push({ args, thunkApi });
2614
- return {
2615
- rawData: {
2616
- ok: true,
2617
- data: {
2618
- profile: { nickname: "default-bridge", redId: "67890" },
2619
- notes: [],
2620
- noteDetails: [],
2621
- commentsByNote: {},
2622
- analysis: {
2623
- totalNotes: 0,
2624
- averageLikes: 0,
2625
- averageComments: 0,
2626
- averageCollects: 0,
2627
- averageShares: 0,
2628
- commentBuckets: [],
2629
- themes: [],
2630
- },
2631
- },
2632
- fetchedAt: "2026-06-03T00:00:00.000Z",
2633
- } as any,
2634
- displayData: "小红书用户: default-bridge",
2635
- };
2636
- },
2637
- fetchImpl: async () => Response.json({}),
2638
- });
2639
-
2640
- await adapter.loadAgentConfig("xhs-default");
2641
- const result = await adapter.executeTool({
2642
- id: "call-xhs-default",
2643
- name: "read_xhs_profile",
2644
- arguments: JSON.stringify({
2645
- url: "https://www.xiaohongshu.com/user/profile/5d2be8720000000010007556",
2646
- includeComments: true,
2647
- maxCommentPagesPerNote: 1,
2648
- }),
2649
- });
2650
-
2651
- expect(readerCalls).toHaveLength(1);
2652
- expect(readerCalls[0].args).toMatchObject({
2653
- url: "https://www.xiaohongshu.com/user/profile/5d2be8720000000010007556",
2654
- includeComments: true,
2655
- maxCommentPagesPerNote: 1,
2656
- });
2657
- expect(readerCalls[0].args.profileDir).toBeUndefined();
2658
- expect(readerCalls[0].thunkApi).toBeUndefined();
2659
- expect(result.metadata).toMatchObject({
2660
- xhsLocalBridge: true,
2661
- displayData: "小红书用户: default-bridge",
2662
- });
2663
- expect(JSON.parse(result.content).data.profile.nickname).toBe("default-bridge");
2664
- });
2665
-
2666
- test("default read_xhs_profile executor ignores explicit XHS profile env", async () => {
2667
- const readerCalls: Array<{ args: any }> = [];
2668
- const adapter = createCliLocalRuntimeAdapter({
2669
- env: {
2670
- NOLO_LOCAL_USER_ID: "user-1",
2671
- NOLO_XHS_READER_PROFILE_DIR: "/tmp/custom-xhs-profile",
2672
- },
2673
- db: {
2674
- get: async () => ({
2675
- dbKey: "agent-user-1-xhs-env",
2676
- id: "xhs-env",
2677
- prompt: "Read XHS.",
2678
- toolNames: ["read_xhs_profile"],
2679
- }),
2680
- put: async () => {},
2681
- batch: async () => {},
2682
- iterator: () => (async function* () {})(),
2683
- },
2684
- readXhsProfile: async (args) => {
2685
- readerCalls.push({ args });
2686
- return {
2687
- rawData: {
2688
- ok: true,
2689
- data: {
2690
- profile: { nickname: "env-bridge" },
2691
- notes: [],
2692
- noteDetails: [],
2693
- commentsByNote: {},
2694
- analysis: { totalNotes: 0, commentBuckets: [] },
2695
- },
2696
- fetchedAt: "2026-06-03T00:00:00.000Z",
2697
- } as any,
2698
- displayData: "小红书用户: env-bridge",
2699
- };
2700
- },
2701
- fetchImpl: async () => Response.json({}),
2702
- });
2703
-
2704
- await adapter.loadAgentConfig("xhs-env");
2705
- await adapter.executeTool({
2706
- id: "call-xhs-env",
2707
- name: "read_xhs_profile",
2708
- arguments: JSON.stringify({
2709
- url: "https://www.xiaohongshu.com/user/profile/5d2be8720000000010007556",
2710
- }),
2711
- });
2712
-
2713
- expect(readerCalls).toHaveLength(1);
2714
- expect(readerCalls[0].args.profileDir).toBeUndefined();
2715
- });
2716
-
2717
- test("read_xhs_profile executor does not falsely succeed when bridge is unavailable", async () => {
2718
- const adapter = createCliLocalRuntimeAdapter({
2719
- env: {
2720
- NOLO_LOCAL_USER_ID: "user-1",
2721
- },
2722
- db: {
2723
- get: async () => ({
2724
- dbKey: "agent-user-1-xhs-fail",
2725
- id: "xhs-fail",
2726
- prompt: "Read XHS.",
2727
- toolNames: ["read_xhs_profile"],
2728
- }),
2729
- put: async () => {},
2730
- batch: async () => {},
2731
- iterator: () => (async function* () {})(),
2732
- },
2733
- localToolExecutors: {
2734
- read_xhs_profile: async () => ({
2735
- content: JSON.stringify({
2736
- ok: false,
2737
- code: "network_error",
2738
- message: "read_xhs_profile needs Playwright but it is not installed.",
2739
- }),
2740
- metadata: { xhsLocalBridge: true, bridgeError: true },
2741
- }),
2742
- },
2743
- fetchImpl: async () => Response.json({}),
2744
- });
2745
-
2746
- await adapter.loadAgentConfig("xhs-fail");
2747
- const result = await adapter.executeTool({
2748
- id: "call-xhs-fail",
2749
- name: "read_xhs_profile",
2750
- arguments: JSON.stringify({
2751
- url: "https://www.xiaohongshu.com/user/profile/5d2be8720000000010007556",
2752
- }),
2753
- });
2754
-
2755
- const parsed = JSON.parse(result.content);
2756
- expect(parsed.ok).toBe(false);
2757
- expect(parsed.code).toBe("network_error");
2758
- expect(result.metadata).toMatchObject({ bridgeError: true });
2759
- });
2760
-
2761
- test("runs allowed workspace file tools through default local executors", async () => {
2762
- const workspaceRoot = mkdtempSync(join(tmpdir(), "nolo-cli-runtime-"));
2763
- try {
2764
- const store = new Map<string, any>([
2765
- ["agent-user-1-writer", {
2766
- dbKey: "agent-user-1-writer",
2767
- id: "writer",
2768
- toolNames: ["writeFile"],
2769
- }],
2770
- ]);
2771
- const adapter = createCliLocalRuntimeAdapter({
2772
- env: {
2773
- NOLO_LOCAL_USER_ID: "user-1",
2774
- },
2775
- db: {
2776
- get: async (key) => {
2777
- if (!store.has(key)) throw new Error(`not found: ${key}`);
2778
- return store.get(key);
2779
- },
2780
- put: async () => {},
2781
- batch: async () => {},
2782
- iterator: () => (async function* () {})(),
2783
- },
2784
- cwd: workspaceRoot,
2785
- fetchImpl: async () => Response.json({}),
2786
- });
2787
-
2788
- await adapter.loadAgentConfig("writer");
2789
- const result = await adapter.executeTool({
2790
- id: "call-1",
2791
- name: "writeFile",
2792
- arguments: JSON.stringify({
2793
- path: "src/app.ts",
2794
- content: "export const cliValue = 1;\n",
2795
- }),
2796
- });
2797
-
2798
- expect(result.content).toBe(`wrote ${join("src", "app.ts")}`);
2799
- expect(readFileSync(join(workspaceRoot, "src/app.ts"), "utf8")).toBe("export const cliValue = 1;\n");
2800
- } finally {
2801
- rmSync(workspaceRoot, { recursive: true, force: true });
2802
- }
2803
- });
2804
- });