nolo-cli 0.1.18 → 0.1.20

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 (111) hide show
  1. package/README.md +9 -1
  2. package/agent-runtime/agentConfigOptions.ts +12 -0
  3. package/agent-runtime/agentRecordConfig.ts +99 -0
  4. package/agent-runtime/agentRecordKeys.ts +14 -0
  5. package/agent-runtime/dialogMessageRecord.ts +16 -0
  6. package/agent-runtime/dialogWritePlan.ts +130 -0
  7. package/agent-runtime/hostAdapter.ts +14 -0
  8. package/agent-runtime/hybridRecordStore.ts +147 -0
  9. package/agent-runtime/index.ts +69 -0
  10. package/agent-runtime/localLoop.ts +78 -6
  11. package/agent-runtime/localToolPolicy.ts +130 -0
  12. package/agent-runtime/localWorkspaceTools.ts +1532 -0
  13. package/agent-runtime/openAiCompatibleProvider.ts +70 -0
  14. package/agent-runtime/openAiCompatibleProviderConfig.ts +38 -0
  15. package/agent-runtime/platformChatProvider.ts +241 -0
  16. package/agent-runtime/taskWorkspace.ts +193 -0
  17. package/agent-runtime/types.ts +2 -0
  18. package/agent-runtime/workspaceSession.ts +76 -0
  19. package/agentAliases.ts +37 -0
  20. package/agentPullCommand.ts +1 -1
  21. package/agentRunCommand.ts +289 -54
  22. package/agentRuntimeCommands.ts +354 -164
  23. package/agentRuntimeLocal.ts +38 -0
  24. package/ai/agent/agentSlice.ts +10 -0
  25. package/ai/agent/buildEditingContext.ts +5 -0
  26. package/ai/agent/buildSystemPrompt.ts +41 -18
  27. package/ai/agent/canvasEditingContext.ts +49 -0
  28. package/ai/agent/cliExecutor.ts +15 -4
  29. package/ai/agent/createAgentSchema.ts +2 -0
  30. package/ai/agent/executeToolCall.ts +3 -2
  31. package/ai/agent/hooks/usePublicAgents.ts +6 -0
  32. package/ai/agent/pageBuilderHandoffRules.ts +75 -0
  33. package/ai/agent/runAgentClientLoop.ts +4 -1
  34. package/ai/agent/runtimeGuidance.ts +19 -0
  35. package/ai/agent/server/fetchPublicAgents.ts +51 -1
  36. package/ai/agent/streamAgentChatTurn.ts +20 -2
  37. package/ai/agent/streamAgentChatTurnUtils.ts +60 -16
  38. package/ai/chat/accumulateToolCallChunks.ts +40 -9
  39. package/ai/chat/parseApiError.ts +3 -0
  40. package/ai/chat/sendOpenAICompletionsRequest.native.ts +23 -10
  41. package/ai/chat/sendOpenAICompletionsRequest.ts +13 -1
  42. package/ai/chat/updateTotalUsage.ts +26 -9
  43. package/ai/llm/deepinfra.ts +51 -0
  44. package/ai/llm/getPricing.ts +6 -0
  45. package/ai/llm/kimi.ts +2 -0
  46. package/ai/llm/openrouterModels.ts +0 -135
  47. package/ai/llm/providers.ts +1 -0
  48. package/ai/llm/types.ts +8 -0
  49. package/ai/taskRun/taskRunProtocol.ts +823 -0
  50. package/ai/token/calculatePrice.ts +30 -0
  51. package/ai/token/externalToolCost.ts +49 -29
  52. package/ai/token/prepareTokenUsageData.ts +6 -1
  53. package/ai/token/serverTokenWriter.ts +4 -2
  54. package/ai/tools/agent/agentTools.ts +21 -0
  55. package/ai/tools/agent/presets/appBuilderPreset.ts +7 -0
  56. package/ai/tools/agent/streamParallelAgentsTool.ts +2 -1
  57. package/ai/tools/agent/taskRunTool.ts +112 -0
  58. package/ai/tools/applyEditTool.ts +6 -3
  59. package/ai/tools/applyLineEditsTool.ts +6 -3
  60. package/ai/tools/checkEnvTool.ts +14 -9
  61. package/ai/tools/codeSearchTool.ts +17 -5
  62. package/ai/tools/execBashTool.ts +33 -29
  63. package/ai/tools/fetchWebpageSupport.ts +24 -0
  64. package/ai/tools/fetchWebpageTool.ts +18 -5
  65. package/ai/tools/index.ts +158 -0
  66. package/ai/tools/jdProductScraperTool.ts +821 -0
  67. package/ai/tools/listFilesTool.ts +6 -3
  68. package/ai/tools/localFilesTool.ts +200 -0
  69. package/ai/tools/readFileTool.ts +6 -3
  70. package/ai/tools/searchRepoTool.ts +6 -3
  71. package/ai/tools/table/rowTools.ts +6 -1
  72. package/ai/tools/taobaoTmallProductScraperTool.ts +49 -0
  73. package/ai/tools/toolApiClient.ts +20 -6
  74. package/ai/tools/wereadGatewayTool.ts +152 -0
  75. package/ai/tools/writeFileTool.ts +6 -3
  76. package/client/agentConfigResolver.test.ts +70 -0
  77. package/client/agentConfigResolver.ts +1 -0
  78. package/client/agentRun.test.ts +361 -7
  79. package/client/agentRun.ts +449 -63
  80. package/client/hybridRecordStore.test.ts +115 -0
  81. package/client/hybridRecordStore.ts +41 -0
  82. package/client/localAgentRecords.test.ts +27 -0
  83. package/client/localAgentRecords.ts +7 -0
  84. package/client/localDialogRecords.test.ts +124 -0
  85. package/client/localDialogRecords.ts +30 -0
  86. package/client/localProviderResolver.test.ts +78 -0
  87. package/client/localProviderResolver.ts +1 -0
  88. package/client/localRuntimeAdapter.test.ts +813 -20
  89. package/client/localRuntimeAdapter.ts +279 -232
  90. package/client/localRuntimeDryRun.test.ts +116 -0
  91. package/client/localToolPolicy.ts +8 -81
  92. package/client/taskRunPrompt.ts +26 -0
  93. package/client/taskWorktree.ts +8 -0
  94. package/client/workspaceSession.test.ts +57 -0
  95. package/client/workspaceSession.ts +11 -0
  96. package/commandRegistry.ts +23 -6
  97. package/connectorRunArtifact.ts +121 -0
  98. package/database/actions/write.ts +16 -2
  99. package/database/hooks/useUserData.ts +9 -3
  100. package/database/server/dataHandlers.ts +18 -20
  101. package/database/server/emailRepository.ts +3 -3
  102. package/database/server/patch.ts +18 -10
  103. package/database/server/query.ts +43 -4
  104. package/database/server/read.ts +24 -38
  105. package/database/server/recordIdentity.ts +100 -0
  106. package/database/server/write.ts +21 -25
  107. package/index.ts +70 -33
  108. package/machineCommands.ts +318 -144
  109. package/package.json +4 -1
  110. package/tableCommands.ts +181 -0
  111. package/taskRunCommand.ts +237 -0
@@ -0,0 +1,130 @@
1
+ import type {
2
+ AgentRuntimeToolCallInput,
3
+ AgentRuntimeToolResult,
4
+ } from "./types";
5
+
6
+ type EnvLike = Record<string, string | undefined>;
7
+
8
+ export type LocalToolPolicyDecision =
9
+ | { allowed: true; toolName: string }
10
+ | { allowed: false; toolName: string; reason: string };
11
+
12
+ const NEVER_LOCAL_TOOLS = new Set([
13
+ "deleteSpaces",
14
+ "updateAgent",
15
+ "updateSelf",
16
+ "createAgent",
17
+ ]);
18
+
19
+ const DEFAULT_LOCAL_TOOLS = new Set([
20
+ "listWorkspaceFiles",
21
+ "readWorkspaceFile",
22
+ "writeWorkspaceFile",
23
+ "replaceWorkspaceText",
24
+ "listFiles",
25
+ "readFile",
26
+ "writeFile",
27
+ "searchWorkspace",
28
+ "applyPatch",
29
+ "gitStatus",
30
+ "gitDiff",
31
+ "gitCreateBranch",
32
+ "gitAdd",
33
+ "gitCommit",
34
+ "commitWorkspace",
35
+ "runPackageScript",
36
+ "execBash",
37
+ ]);
38
+
39
+ function parseToolAllowlist(value: string | undefined) {
40
+ return (value ?? "")
41
+ .split(",")
42
+ .map((item) => item.trim())
43
+ .filter(Boolean);
44
+ }
45
+
46
+ function isLocalShellModeEnabled(env: EnvLike) {
47
+ return ["worktree", "dangerous", "1", "true"].includes(env.NOLO_LOCAL_SHELL_MODE || "");
48
+ }
49
+
50
+ function isRestrictedLocalToolMode(env: EnvLike) {
51
+ return env.NOLO_LOCAL_TOOL_MODE === "restricted";
52
+ }
53
+
54
+ function isToolDeclaredOrExplicitlyFree(args: {
55
+ env: EnvLike;
56
+ agentToolNames?: string[];
57
+ toolName: string;
58
+ }) {
59
+ return (
60
+ new Set(args.agentToolNames ?? []).has(args.toolName) ||
61
+ args.env.NOLO_LOCAL_ALLOW_UNDECLARED_TOOLS === "1"
62
+ );
63
+ }
64
+
65
+ export function resolveLocalToolPolicy(args: {
66
+ env: EnvLike;
67
+ agentToolNames?: string[];
68
+ toolName: string;
69
+ }): LocalToolPolicyDecision {
70
+ const restrictedMode = isRestrictedLocalToolMode(args.env);
71
+ const isShellTool = args.toolName === "execShell" || args.toolName === "execBash";
72
+ if (isShellTool) {
73
+ if (isLocalShellModeEnabled(args.env)) {
74
+ return { allowed: true, toolName: args.toolName };
75
+ }
76
+ return {
77
+ allowed: false,
78
+ toolName: args.toolName,
79
+ reason: `${args.toolName} requires NOLO_LOCAL_SHELL_MODE=worktree.`,
80
+ };
81
+ }
82
+
83
+ if (NEVER_LOCAL_TOOLS.has(args.toolName)) {
84
+ return {
85
+ allowed: false,
86
+ toolName: args.toolName,
87
+ reason: `${args.toolName} is blocked by the local runtime safety policy.`,
88
+ };
89
+ }
90
+
91
+ const allowedByEnv = new Set(parseToolAllowlist(args.env.NOLO_LOCAL_ALLOWED_TOOLS));
92
+ const agentTools = new Set(args.agentToolNames ?? []);
93
+ if (!restrictedMode && agentTools.has(args.toolName)) {
94
+ return { allowed: true, toolName: args.toolName };
95
+ }
96
+ if (DEFAULT_LOCAL_TOOLS.has(args.toolName) && agentTools.has(args.toolName)) {
97
+ return { allowed: true, toolName: args.toolName };
98
+ }
99
+ if (allowedByEnv.has(args.toolName) && agentTools.has(args.toolName)) {
100
+ return { allowed: true, toolName: args.toolName };
101
+ }
102
+
103
+ return {
104
+ allowed: false,
105
+ toolName: args.toolName,
106
+ reason:
107
+ `${args.toolName} is not enabled for local runtime runs. ` +
108
+ "Set NOLO_LOCAL_ALLOWED_TOOLS and make sure the agent declares the tool before using it locally.",
109
+ };
110
+ }
111
+
112
+ export async function executeLocalToolWithPolicy(args: {
113
+ env: EnvLike;
114
+ agentToolNames?: string[];
115
+ call: AgentRuntimeToolCallInput;
116
+ executors?: Record<string, (call: AgentRuntimeToolCallInput) => Promise<AgentRuntimeToolResult>>;
117
+ }): Promise<AgentRuntimeToolResult> {
118
+ const decision = resolveLocalToolPolicy({
119
+ env: args.env,
120
+ agentToolNames: args.agentToolNames,
121
+ toolName: args.call.name,
122
+ });
123
+ if (!decision.allowed) throw new Error(decision.reason);
124
+
125
+ const executor = args.executors?.[args.call.name];
126
+ if (!executor) {
127
+ throw new Error(`${args.call.name} is allowed by policy but no local executor is registered.`);
128
+ }
129
+ return executor(args.call);
130
+ }