nolo-cli 0.1.32 → 0.1.34

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 (234) hide show
  1. package/README.md +4 -10
  2. package/agent-runtime/agentRecordConfig.ts +10 -0
  3. package/agent-runtime/hostAdapter.ts +10 -1
  4. package/agent-runtime/index.ts +9 -20
  5. package/agent-runtime/localLoop.ts +49 -2
  6. package/agent-runtime/localToolPolicy.ts +76 -34
  7. package/agent-runtime/localWorkspaceTools.ts +30 -333
  8. package/agent-runtime/openAiCompatibleProvider.ts +7 -3
  9. package/agent-runtime/openAiCompatibleProviderConfig.ts +15 -26
  10. package/agent-runtime/platformChatProvider.ts +47 -73
  11. package/agent-runtime/providerResolution.ts +244 -0
  12. package/agent-runtime/runtimeToolPolicy.ts +77 -29
  13. package/agent-runtime/shellCommandPolicy.ts +120 -0
  14. package/agentAliases.ts +14 -83
  15. package/agentCommandSupport.ts +3 -6
  16. package/agentInternalCommandEntries.ts +4 -13
  17. package/agentListCommands.ts +18 -27
  18. package/agentMachineCommands.ts +40 -336
  19. package/agentPullCommand.ts +30 -55
  20. package/agentRecordCommands.ts +84 -1
  21. package/agentRecordHelpers.ts +102 -186
  22. package/agentRunCommand.ts +438 -107
  23. package/agentRuntimeLocal.ts +2 -9
  24. package/ai/agent/cliExecutor.ts +19 -323
  25. package/ai/tools/toolNameAliases.ts +70 -0
  26. package/authCommands.ts +2 -36
  27. package/cli/agentAliases.ts +14 -83
  28. package/cli/agentCommandSupport.ts +3 -6
  29. package/cli/agentInternalCommandEntries.ts +4 -13
  30. package/cli/agentListCommands.ts +18 -27
  31. package/cli/agentMachineCommands.ts +40 -336
  32. package/cli/agentPullCommand.ts +30 -55
  33. package/cli/agentRecordCommands.ts +84 -1
  34. package/cli/agentRecordHelpers.ts +102 -186
  35. package/cli/agentRunCommand.ts +438 -107
  36. package/cli/agentRuntimeLocal.ts +2 -9
  37. package/cli/authCommands.ts +2 -36
  38. package/cli/cliCommandDispatch.ts +2 -2
  39. package/cli/cliEnvHelpers.ts +34 -107
  40. package/cli/client/agentRun.ts +854 -57
  41. package/cli/client/localRuntimeAdapter.ts +59 -159
  42. package/cli/client/streamingOutput.ts +3 -1
  43. package/cli/client/taskRunPrompt.ts +24 -7
  44. package/cli/commandRegistry.ts +4 -5
  45. package/cli/connectorRunArtifact.ts +10 -34
  46. package/cli/connectorWebSocketTarget.ts +6 -10
  47. package/cli/internalCommandEntries.ts +0 -8
  48. package/cli/localRuntimeDb.ts +2 -39
  49. package/cli/machineCommands.ts +189 -190
  50. package/cli/machineDaemonCommands.ts +165 -9
  51. package/cli/machineHeartbeatCommands.ts +2 -1
  52. package/cli/machineStatusCommands.ts +13 -5
  53. package/cli/machineWatchCommands.ts +1 -1
  54. package/cli/machineWsRunDispatch.ts +30 -44
  55. package/cli/machineWsSession.ts +0 -2
  56. package/cli/offlineMarxistsAgentCommand.ts +314 -0
  57. package/cli/runtimeDoctorCommands.ts +72 -15
  58. package/cli/scriptCommandEntries.ts +45 -5
  59. package/cli/tableCommands.ts +133 -33
  60. package/cli/taskRunCommand.ts +211 -16
  61. package/cli/tui/session.ts +372 -43
  62. package/cli/workflowInternalCommandEntries.ts +0 -20
  63. package/cliCommandDispatch.ts +2 -2
  64. package/cliEnvHelpers.ts +34 -107
  65. package/client/agentConfigResolver.test.ts +2 -0
  66. package/client/agentRun.test.ts +12 -208
  67. package/client/agentRun.ts +854 -57
  68. package/client/localProviderResolver.test.ts +26 -2
  69. package/client/localRuntimeAdapter.test.ts +296 -171
  70. package/client/localRuntimeAdapter.ts +59 -159
  71. package/client/localToolPolicy.test.ts +4 -28
  72. package/client/streamingOutput.ts +3 -1
  73. package/client/taskRunPrompt.ts +24 -7
  74. package/commandRegistry.ts +4 -5
  75. package/connectorRunArtifact.ts +10 -34
  76. package/connectorWebSocketTarget.ts +6 -10
  77. package/database/server/serverStoreFactory.ts +2 -8
  78. package/internalCommandEntries.ts +0 -8
  79. package/localRuntimeDb.ts +2 -39
  80. package/machineCommands.ts +189 -190
  81. package/machineDaemonCommands.ts +165 -9
  82. package/machineHeartbeatCommands.ts +2 -1
  83. package/machineStatusCommands.ts +13 -5
  84. package/machineWatchCommands.ts +1 -1
  85. package/machineWsRunDispatch.ts +30 -44
  86. package/machineWsSession.ts +0 -2
  87. package/offlineMarxistsAgentCommand.ts +314 -0
  88. package/package.json +52 -188
  89. package/runtimeDoctorCommands.ts +72 -15
  90. package/scriptCommandEntries.ts +45 -5
  91. package/tableCommands.ts +133 -33
  92. package/taskRunCommand.ts +211 -16
  93. package/tui/session.ts +372 -43
  94. package/workflowInternalCommandEntries.ts +0 -20
  95. package/agent-runtime/dialogStatus.ts +0 -139
  96. package/agent-runtime/hostRuntimeConfig.ts +0 -86
  97. package/agentCreateCustomCommands.ts +0 -278
  98. package/agentDialogsCommands.ts +0 -227
  99. package/agentDoctorCommands.ts +0 -203
  100. package/agentRunLocalWorkspace.ts +0 -182
  101. package/agentRunParsing.ts +0 -298
  102. package/agentSuperviseCommands.ts +0 -8
  103. package/agentUnpublishCommands.ts +0 -113
  104. package/ai/agent/agentRunDialogLineage.ts +0 -56
  105. package/ai/policy/types.ts +0 -64
  106. package/ai/skills/skillSummaryMarker.ts +0 -26
  107. package/app/types.ts +0 -358
  108. package/build.ts +0 -16
  109. package/buildPublish.ts +0 -138
  110. package/buildPublishArtifactAssembly.ts +0 -724
  111. package/buildPublishImportAnalysis.ts +0 -242
  112. package/chat/messages/fetchMessages.ts +0 -84
  113. package/chat/messages/types.ts +0 -185
  114. package/cli/agentCreateCustomCommands.ts +0 -278
  115. package/cli/agentDialogsCommands.ts +0 -227
  116. package/cli/agentDoctorCommands.ts +0 -203
  117. package/cli/agentRunLocalWorkspace.ts +0 -182
  118. package/cli/agentRunParsing.ts +0 -298
  119. package/cli/agentSuperviseCommands.ts +0 -8
  120. package/cli/agentUnpublishCommands.ts +0 -113
  121. package/cli/buildPublish.ts +0 -138
  122. package/cli/buildPublishArtifactAssembly.ts +0 -724
  123. package/cli/buildPublishImportAnalysis.ts +0 -242
  124. package/cli/cliIoTypes.ts +0 -3
  125. package/cli/cliRuntimeDoctorReport.ts +0 -193
  126. package/cli/client/agentRunInput.ts +0 -10
  127. package/cli/client/agentRunLocalExecution.ts +0 -124
  128. package/cli/client/agentRunLocalExecutor.ts +0 -179
  129. package/cli/client/agentRunRuntimeSelection.ts +0 -145
  130. package/cli/client/agentRunServerTransport.ts +0 -397
  131. package/cli/client/agentRunTaskRunRecorder.ts +0 -176
  132. package/cli/customCodingAgentFlow.ts +0 -208
  133. package/cli/customCodingAgentRecord.ts +0 -179
  134. package/cli/dialogDataAccess.ts +0 -186
  135. package/cli/dialogInternalCommandEntries.ts +0 -11
  136. package/cli/dialogReadCommands.ts +0 -180
  137. package/cli/dialogReadHelpers.ts +0 -226
  138. package/cli/dialogStatusCommands.ts +0 -123
  139. package/cli/docInternalCommandEntries.ts +0 -20
  140. package/cli/hybridReadHelpers.ts +0 -109
  141. package/cli/machineCommandPrompts.ts +0 -79
  142. package/cli/machineCommandResolution.ts +0 -43
  143. package/cli/noloReadBridgePrompt.ts +0 -16
  144. package/cli/pageCreateCommands.ts +0 -219
  145. package/cli/pageDeleteCommands.ts +0 -167
  146. package/cli/pageReadCommands.ts +0 -151
  147. package/cli/pageUpdateCommands.ts +0 -249
  148. package/cli/pageWriteHelpers.ts +0 -209
  149. package/cli/publishPackage.ts +0 -36
  150. package/cli/runtimeInternalCommandEntries.ts +0 -15
  151. package/cli/runtimePassthroughCommands.ts +0 -22
  152. package/cli/scriptPassthroughHelpers.ts +0 -28
  153. package/cli/secretScanHelpers.ts +0 -31
  154. package/cli/spaceAttachCommands.ts +0 -134
  155. package/cli/spaceCategoryCommands.ts +0 -263
  156. package/cli/spaceCommands.ts +0 -295
  157. package/cli/spaceDeleteCommands.ts +0 -312
  158. package/cli/spaceInternalCommandEntries.ts +0 -21
  159. package/cli/spaceMutationHelpers.ts +0 -135
  160. package/cli/spaceReadCommands.ts +0 -323
  161. package/cli/tableDataOutput.ts +0 -41
  162. package/cli/tableDataSafety.ts +0 -26
  163. package/cli/tableMetaCommands.ts +0 -307
  164. package/cli/tableMutationCommands.ts +0 -266
  165. package/cli/tableQueryParsing.ts +0 -90
  166. package/cli/tableQueryRequest.ts +0 -53
  167. package/cli/taskRunActions.ts +0 -122
  168. package/cli/taskRunParsing.ts +0 -86
  169. package/cli/taskRunPromptShared.ts +0 -55
  170. package/cli/tui/tuiCatalog.ts +0 -22
  171. package/cli/tui/tuiCommandInterpreter.ts +0 -253
  172. package/cli/tui/tuiPresentation.ts +0 -146
  173. package/cliIoTypes.ts +0 -3
  174. package/cliRuntimeDoctorReport.ts +0 -193
  175. package/client/agentRunInput.ts +0 -10
  176. package/client/agentRunLocalExecution.test.ts +0 -123
  177. package/client/agentRunLocalExecution.ts +0 -124
  178. package/client/agentRunLocalExecutor.ts +0 -179
  179. package/client/agentRunRuntimeSelection.test.ts +0 -159
  180. package/client/agentRunRuntimeSelection.ts +0 -145
  181. package/client/agentRunServerTransport.ts +0 -397
  182. package/client/agentRunTaskRunRecorder.ts +0 -176
  183. package/connector-experimental/daemonLauncher.ts +0 -223
  184. package/create/space/spaceKeys.ts +0 -65
  185. package/create/types.ts +0 -21
  186. package/customCodingAgentFlow.ts +0 -208
  187. package/customCodingAgentRecord.ts +0 -179
  188. package/database/keys.ts +0 -765
  189. package/database/tombstones.ts +0 -52
  190. package/database/utils/ulid.ts +0 -1
  191. package/dialogDataAccess.ts +0 -186
  192. package/dialogInternalCommandEntries.ts +0 -11
  193. package/dialogReadCommands.ts +0 -180
  194. package/dialogReadHelpers.ts +0 -226
  195. package/dialogStatusCommands.ts +0 -123
  196. package/docInternalCommandEntries.ts +0 -20
  197. package/hybridReadHelpers.ts +0 -109
  198. package/machineCommandPrompts.ts +0 -79
  199. package/machineCommandResolution.ts +0 -43
  200. package/noloReadBridgePrompt.ts +0 -16
  201. package/pageCreateCommands.ts +0 -219
  202. package/pageDeleteCommands.ts +0 -167
  203. package/pageReadCommands.ts +0 -151
  204. package/pageUpdateCommands.ts +0 -249
  205. package/pageWriteHelpers.ts +0 -209
  206. package/publishPackage.ts +0 -36
  207. package/runtimeInternalCommandEntries.ts +0 -15
  208. package/runtimePassthroughCommands.ts +0 -22
  209. package/scriptPassthroughHelpers.ts +0 -28
  210. package/secretScanHelpers.ts +0 -31
  211. package/share/helpers.ts +0 -302
  212. package/share/keys.ts +0 -243
  213. package/share/types.ts +0 -100
  214. package/spaceAttachCommands.ts +0 -134
  215. package/spaceCategoryCommands.ts +0 -263
  216. package/spaceCommands.ts +0 -295
  217. package/spaceDeleteCommands.ts +0 -312
  218. package/spaceInternalCommandEntries.ts +0 -21
  219. package/spaceMutationHelpers.ts +0 -135
  220. package/spaceReadCommands.ts +0 -323
  221. package/tableDataOutput.ts +0 -41
  222. package/tableDataSafety.ts +0 -26
  223. package/tableMetaCommands.ts +0 -307
  224. package/tableMutationCommands.ts +0 -266
  225. package/tableQueryParsing.ts +0 -90
  226. package/tableQueryRequest.ts +0 -53
  227. package/taskRunActions.ts +0 -122
  228. package/taskRunParsing.ts +0 -86
  229. package/taskRunPromptShared.ts +0 -55
  230. package/tui/tuiCatalog.ts +0 -22
  231. package/tui/tuiCommandInterpreter.test.ts +0 -169
  232. package/tui/tuiCommandInterpreter.ts +0 -253
  233. package/tui/tuiPresentation.test.ts +0 -154
  234. package/tui/tuiPresentation.ts +0 -146
@@ -1,179 +0,0 @@
1
- import { runLocalAgentTurn, resolveHostRuntimeConfigFromEnv } from "../agentRuntimeLocal";
2
- import { LOCAL_AGENT_CONFIG_MISSING_CODE } from "../../agent-runtime/localLoop";
3
- import type { LocalAgentToolEvent } from "../../agent-runtime/localLoop";
4
- import { buildUserInputContent } from "./agentRunInput";
5
- import { createCliLocalRuntimeAdapter } from "./localRuntimeAdapter";
6
- import { prependTaskRunPrompt } from "./taskRunPrompt";
7
- import { recordTaskRunOutcome } from "./agentRunTaskRunRecorder";
8
- import {
9
- formatToolTraceEvent,
10
- nextLocalToolRoundLimit,
11
- parseLocalToolRoundLimitError,
12
- resolveLocalToolRoundRetryLimit,
13
- shouldCollectLocalToolEvidence,
14
- shouldTraceLocalTools,
15
- summarizeLocalToolEvidence,
16
- } from "./agentRunLocalExecution";
17
- import type { RunAgentTurnOptions } from "./agentRun";
18
-
19
- export type LocalAgentTurnResult = {
20
- exitCode: number;
21
- dialogId?: string;
22
- localError?: unknown;
23
- toolEvidence?: ReturnType<typeof summarizeLocalToolEvidence>;
24
- };
25
-
26
- function buildDefaultLocalRuntimeAdapter(options: RunAgentTurnOptions) {
27
- return createCliLocalRuntimeAdapter({
28
- env: options.env,
29
- hostRuntimeConfig: resolveHostRuntimeConfigFromEnv({
30
- env: options.env,
31
- surface: "cli-local",
32
- workspaceBinding: "explicit-cwd",
33
- }),
34
- fetchImpl: options.fetchImpl,
35
- cwd: options.localRuntimeCwd,
36
- output: options.output,
37
- });
38
- }
39
-
40
- export function resolveLocalRuntimeAdapter(options: RunAgentTurnOptions) {
41
- return (
42
- options.localRuntimeAdapter ||
43
- options.localRuntimeAdapterFactory?.(options.env, { cwd: options.localRuntimeCwd }) ||
44
- buildDefaultLocalRuntimeAdapter(options)
45
- );
46
- }
47
-
48
- export function isMissingLocalAgentConfigError(error: unknown, agentRef: string) {
49
- return Boolean(
50
- error &&
51
- typeof error === "object" &&
52
- "code" in error &&
53
- (error as { code?: string; agentRef?: string }).code === LOCAL_AGENT_CONFIG_MISSING_CODE &&
54
- (error as { code?: string; agentRef?: string }).agentRef === agentRef
55
- );
56
- }
57
-
58
- export async function runInjectedLocalAgentTurn(options: RunAgentTurnOptions) {
59
- return runLocalAgentTurnWithAutoRoundExpansion(options, { reportFailure: true });
60
- }
61
-
62
- export async function refreshMissingLocalAgentConfig(options: RunAgentTurnOptions) {
63
- const adapter = resolveLocalRuntimeAdapter(options);
64
- if (!adapter) return false;
65
- const agentConfig = await adapter.loadAgentConfig(options.agentKey);
66
- return Boolean(agentConfig);
67
- }
68
-
69
- export async function runLocalAgentTurnWithAutoRoundExpansion(
70
- options: RunAgentTurnOptions,
71
- settings: { reportFailure: boolean }
72
- ) {
73
- const maxRetryLimit = resolveLocalToolRoundRetryLimit(options);
74
- let currentMaxToolRounds = options.maxToolRounds;
75
- let lastResult: Awaited<ReturnType<typeof runLocalAgentTurnForCli>> | null = null;
76
-
77
- while (true) {
78
- const attemptOptions = {
79
- ...options,
80
- ...(typeof currentMaxToolRounds === "number" ? { maxToolRounds: currentMaxToolRounds } : {}),
81
- };
82
- const result = await runLocalAgentTurnForCli(attemptOptions, { reportFailure: false });
83
- lastResult = result;
84
- if (result.exitCode === 0) return result;
85
-
86
- const exhaustedRounds = parseLocalToolRoundLimitError(result.localError);
87
- if (exhaustedRounds === null) break;
88
-
89
- const nextMaxToolRounds = nextLocalToolRoundLimit(exhaustedRounds);
90
- if (nextMaxToolRounds > maxRetryLimit) break;
91
-
92
- options.output.write(
93
- `[nolo] Local agent used all ${exhaustedRounds} tool rounds; retrying with ${nextMaxToolRounds}.\n`
94
- );
95
- currentMaxToolRounds = nextMaxToolRounds;
96
- }
97
-
98
- if (settings.reportFailure && lastResult?.localError) {
99
- options.output.write(
100
- `[nolo] Local agent run failed: ${
101
- lastResult.localError instanceof Error ? lastResult.localError.message : String(lastResult.localError)
102
- }\n`
103
- );
104
- await recordTaskRunOutcome({
105
- options,
106
- status: "failed",
107
- errorCode: "LOCAL_AGENT_FAILED",
108
- resultSummary:
109
- lastResult.localError instanceof Error ? lastResult.localError.message : String(lastResult.localError),
110
- toolEvidence: lastResult.toolEvidence,
111
- });
112
- }
113
- return lastResult ?? { exitCode: 1 };
114
- }
115
-
116
- export async function runLocalAgentTurnForCli(
117
- options: RunAgentTurnOptions,
118
- settings: { reportFailure: boolean }
119
- ): Promise<LocalAgentTurnResult> {
120
- const adapter = resolveLocalRuntimeAdapter(options);
121
- if (!adapter) {
122
- options.output.write("[nolo] Local runtime was requested but no local runtime adapter is available.\n");
123
- return { exitCode: 1 };
124
- }
125
-
126
- options.output.write(`\n${options.agentName} -> working locally...\n`);
127
- const toolEvents: LocalAgentToolEvent[] = [];
128
- try {
129
- const traceLocalTools = shouldTraceLocalTools(options);
130
- const collectToolEvidence = shouldCollectLocalToolEvidence(options);
131
- const result = await runLocalAgentTurn({
132
- adapter,
133
- agentRef: options.agentKey,
134
- input: buildUserInputContent(
135
- prependTaskRunPrompt(options.message, options.taskRunContext),
136
- options.imageUrls
137
- ),
138
- continueDialogId: options.continueDialogId,
139
- spaceId: options.spaceId,
140
- category: options.category,
141
- inheritedFromDialogKey: options.inheritedFromDialogKey,
142
- parentDialogId: options.parentDialogId,
143
- background: options.background,
144
- noStream: options.noStream,
145
- maxToolRounds: options.maxToolRounds,
146
- ...(traceLocalTools || collectToolEvidence
147
- ? {
148
- onToolEvent: (event) => {
149
- if (collectToolEvidence) toolEvents.push(event);
150
- if (traceLocalTools) options.output.write(formatToolTraceEvent(event));
151
- },
152
- }
153
- : {}),
154
- });
155
- const content = result.content.trim();
156
- if (content) {
157
- options.output.write(`\n${options.agentName} > ${content}\n`);
158
- } else {
159
- options.output.write(`\n${options.agentName} > (no text response)\n`);
160
- }
161
- await recordTaskRunOutcome({
162
- options,
163
- status: options.background ? "running" : "completed",
164
- dialogId: result.dialogId,
165
- ...(!options.background && content ? { resultSummary: content } : {}),
166
- toolEvidence: summarizeLocalToolEvidence(toolEvents),
167
- });
168
- return { exitCode: 0, dialogId: result.dialogId };
169
- } catch (error) {
170
- if (settings.reportFailure) {
171
- options.output.write(
172
- `[nolo] Local agent run failed: ${
173
- error instanceof Error ? error.message : String(error)
174
- }\n`
175
- );
176
- }
177
- return { exitCode: 1, localError: error, toolEvidence: summarizeLocalToolEvidence(toolEvents) };
178
- }
179
- }
@@ -1,145 +0,0 @@
1
- import type { AgentRuntimeRequestedMode } from "../agentRuntimeLocal";
2
- import {
3
- isKnownPlatformAgentKey,
4
- } from "../agentAliases";
5
- import type { EnvLike } from "../cliEnvHelpers";
6
- import type { OutputLike } from "../cliIoTypes";
7
- export type { OutputLike } from "../cliIoTypes";
8
-
9
- export type ScriptBridgeDecision = {
10
- hasAuthToken: boolean;
11
- scriptPathExists: boolean;
12
- };
13
-
14
- export type RuntimeSelectionAgentConfig = {
15
- toolNames?: string[];
16
- runtimeToolPolicy?: {
17
- agentTools?: string[];
18
- };
19
- };
20
-
21
- export type RuntimeSelectionAdapter = {
22
- loadAgentConfig(agentKey: string): Promise<RuntimeSelectionAgentConfig | undefined>;
23
- };
24
-
25
- export type RuntimeSelectionOptions = {
26
- agentKey: string;
27
- env: EnvLike;
28
- output: OutputLike;
29
- runtimeMode?: AgentRuntimeRequestedMode;
30
- localRuntimeAdapter?: RuntimeSelectionAdapter;
31
- localRuntimeAdapterFactory?: unknown;
32
- resolveLocalRuntimeAdapter?: () => RuntimeSelectionAdapter | undefined;
33
- };
34
-
35
- const SERVER_PLATFORM_TOOL_NAMES = new Set([
36
- "addTableRow",
37
- "addTableRows",
38
- "deleteTableRow",
39
- "deleteTableRows",
40
- "queryTableRows",
41
- "streamParallelAgents",
42
- "taskRun",
43
- "updateTableRow",
44
- "updateTableRows",
45
- ]);
46
-
47
- const KNOWN_SERVER_PLATFORM_AGENT_ALIASES = new Set([
48
- "code-review",
49
- "frontend",
50
- "frontend-agent",
51
- "frontend-implementer",
52
- "full-stack",
53
- "fullstack",
54
- "nolo code review",
55
- "nolo frontend",
56
- "nolo fullstack",
57
- "nolo reviewer",
58
- "nolo-code-review",
59
- "nolo-frontend",
60
- "nolo-fullstack",
61
- "nolo-reviewer",
62
- "review",
63
- "reviewer",
64
- ]);
65
-
66
- export function shouldUseScriptBridge(decision: ScriptBridgeDecision) {
67
- return !decision.hasAuthToken && decision.scriptPathExists;
68
- }
69
-
70
- export function findServerPlatformTools(toolNames?: string[]) {
71
- if (!Array.isArray(toolNames)) return [];
72
- return toolNames.filter((toolName) => SERVER_PLATFORM_TOOL_NAMES.has(toolName));
73
- }
74
-
75
- export function resolveServerPlatformToolNames(agentConfig: RuntimeSelectionAgentConfig | undefined) {
76
- return findServerPlatformTools([
77
- ...(Array.isArray(agentConfig?.toolNames) ? agentConfig.toolNames : []),
78
- ...(Array.isArray(agentConfig?.runtimeToolPolicy?.agentTools)
79
- ? agentConfig.runtimeToolPolicy.agentTools
80
- : []),
81
- ]);
82
- }
83
-
84
- export function normalizeAgentRef(ref?: string) {
85
- return ref?.trim().toLowerCase().replace(/\s+/g, " ");
86
- }
87
-
88
- export function isKnownServerPlatformAgent(options: Pick<RuntimeSelectionOptions, "agentKey">) {
89
- if (isKnownPlatformAgentKey(options.agentKey)) return true;
90
- const normalizedKey = normalizeAgentRef(options.agentKey);
91
- return Boolean(normalizedKey && KNOWN_SERVER_PLATFORM_AGENT_ALIASES.has(normalizedKey));
92
- }
93
-
94
- export function shouldShowUsage(env: EnvLike) {
95
- return env.NOLO_DEBUG === "1" || env.NOLO_SHOW_USAGE === "1";
96
- }
97
-
98
- export function resolveRequestedRuntimeMode(
99
- options: Pick<RuntimeSelectionOptions, "env" | "runtimeMode">
100
- ) {
101
- const envMode = options.env.NOLO_RUNTIME_MODE;
102
- if (options.runtimeMode) return options.runtimeMode;
103
- if (envMode === "local" || envMode === "server" || envMode === "auto") return envMode;
104
- return "auto";
105
- }
106
-
107
- export function shouldAttemptAutoLocal(
108
- options: Pick<RuntimeSelectionOptions, "env" | "localRuntimeAdapter" | "localRuntimeAdapterFactory">
109
- ) {
110
- if (options.localRuntimeAdapter || options.localRuntimeAdapterFactory) return true;
111
- return Boolean(
112
- options.env.NOLO_LOCAL_OPENAI_API_KEY ||
113
- options.env.OPENAI_API_KEY ||
114
- options.env.NOLO_LOCAL_OPENAI_BASE_URL ||
115
- options.env.OPENAI_BASE_URL ||
116
- options.env.NOLO_LOCAL_AGENT_KEY
117
- );
118
- }
119
-
120
- export async function shouldSkipAutoLocalForServerPlatformTools(
121
- options: RuntimeSelectionOptions
122
- ) {
123
- if (isKnownServerPlatformAgent(options)) {
124
- options.output.write(
125
- `[nolo] auto runtime: skipping local runtime because ${options.agentKey} is a known platform agent. ` +
126
- "Use --local explicitly to force local workspace tools.\n"
127
- );
128
- return true;
129
- }
130
- const adapter = options.localRuntimeAdapter || options.resolveLocalRuntimeAdapter?.();
131
- if (!adapter) return false;
132
- let agentConfig;
133
- try {
134
- agentConfig = await adapter.loadAgentConfig(options.agentKey);
135
- } catch {
136
- return false;
137
- }
138
- const serverTools = resolveServerPlatformToolNames(agentConfig);
139
- if (serverTools.length === 0) return false;
140
- options.output.write(
141
- `[nolo] auto runtime: skipping local runtime because ${options.agentKey} declares server platform tools ` +
142
- `(${serverTools.join(", ")}). Use --local explicitly to force local workspace tools.\n`
143
- );
144
- return true;
145
- }