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,182 +0,0 @@
1
- import { formatPreparedTaskWorktree, prepareTaskWorktree, ensureWorkspacePackageLinks } from "./client/taskWorktree";
2
- import type { PreparedTaskWorktree } from "./client/taskWorktree";
3
-
4
- export type EnvLike = Record<string, string | undefined>;
5
-
6
- export type OutputLike = {
7
- write(chunk: string): unknown;
8
- };
9
-
10
- export type LocalRunWorkspaceInspection = {
11
- cwd: string;
12
- clean: boolean;
13
- status: string;
14
- commit?: {
15
- hash: string;
16
- subject: string;
17
- };
18
- };
19
-
20
- export type LocalWorkspaceRunArgs = {
21
- agentKey: string;
22
- runtimeMode?: "local" | "server" | "auto";
23
- allowShell: boolean;
24
- useTaskWorktree: boolean;
25
- cwd?: string;
26
- };
27
-
28
- type InspectLocalRunWorkspaceDeps = {
29
- runGitForLocalSummary?: typeof runGitForLocalSummary;
30
- };
31
-
32
- type PrepareLocalRunWorkspaceDeps = {
33
- parsed: LocalWorkspaceRunArgs;
34
- env: EnvLike;
35
- output: OutputLike;
36
- prepareTaskWorktree?: typeof prepareTaskWorktree;
37
- ensureWorkspacePackageLinks?: typeof ensureWorkspacePackageLinks;
38
- };
39
-
40
- export async function runGitForLocalSummary(args: {
41
- cwd: string;
42
- gitArgs: string[];
43
- }) {
44
- const proc = Bun.spawn(["git", ...args.gitArgs], {
45
- cwd: args.cwd,
46
- stdout: "pipe",
47
- stderr: "pipe",
48
- });
49
- const [stdout, stderr, exitCode] = await Promise.all([
50
- new Response(proc.stdout).text(),
51
- new Response(proc.stderr).text(),
52
- proc.exited,
53
- ]);
54
- if (exitCode !== 0) {
55
- throw new Error((stderr || stdout || `git ${args.gitArgs.join(" ")} failed`).trim());
56
- }
57
- return stdout.trim();
58
- }
59
-
60
- export async function inspectLocalRunWorkspace(
61
- cwd: string,
62
- deps: InspectLocalRunWorkspaceDeps = {}
63
- ): Promise<LocalRunWorkspaceInspection> {
64
- const runGit = deps.runGitForLocalSummary ?? runGitForLocalSummary;
65
- const status = await runGit({
66
- cwd,
67
- gitArgs: ["status", "--short"],
68
- });
69
- const rawCommit = await runGit({
70
- cwd,
71
- gitArgs: ["log", "-1", "--format=%h%x00%s"],
72
- }).catch(() => "");
73
- const [hash, subject] = rawCommit.split("\0");
74
- return {
75
- cwd,
76
- clean: status.trim() === "",
77
- status,
78
- ...(hash ? { commit: { hash, subject: subject ?? "" } } : {}),
79
- };
80
- }
81
-
82
- export function formatLocalRunSummary(args: {
83
- dialogId?: string;
84
- inspection: LocalRunWorkspaceInspection;
85
- }) {
86
- return [
87
- "",
88
- "[nolo] local run summary",
89
- `workspace: ${args.inspection.cwd}`,
90
- ...(args.dialogId ? [`dialog: ${args.dialogId}`] : []),
91
- ...(args.inspection.commit
92
- ? [`commit: ${args.inspection.commit.hash} ${args.inspection.commit.subject}`]
93
- : []),
94
- `dirty: ${args.inspection.clean ? "clean" : "dirty"}`,
95
- ...(!args.inspection.clean && args.inspection.status.trim()
96
- ? [`status:\n${args.inspection.status.trim()}`]
97
- : []),
98
- "",
99
- ].join("\n");
100
- }
101
-
102
- function shouldPrepareTaskWorktree(parsed: LocalWorkspaceRunArgs) {
103
- return !parsed.cwd && (parsed.useTaskWorktree || parsed.allowShell);
104
- }
105
-
106
- function buildTaskWorktreeEnv(args: {
107
- env: EnvLike;
108
- worktreePath?: string;
109
- allowShell: boolean;
110
- }) {
111
- return {
112
- ...args.env,
113
- ...(args.allowShell ? { NOLO_LOCAL_SHELL_MODE: "worktree" } : {}),
114
- ...(args.worktreePath ? { NOLO_LOCAL_WORKTREE: args.worktreePath } : {}),
115
- };
116
- }
117
-
118
- function shouldBindLocalWorkspace(args: {
119
- parsed: LocalWorkspaceRunArgs;
120
- localRuntimeCwd?: string;
121
- }) {
122
- return Boolean(
123
- args.localRuntimeCwd &&
124
- (args.parsed.runtimeMode === "local" || args.parsed.allowShell || args.parsed.useTaskWorktree)
125
- );
126
- }
127
-
128
- export async function prepareLocalRunWorkspace(
129
- args: PrepareLocalRunWorkspaceDeps
130
- ): Promise<
131
- | {
132
- ok: true;
133
- localRuntimeCwd?: string;
134
- runEnv: EnvLike;
135
- }
136
- | {
137
- ok: false;
138
- exitCode: 1;
139
- }
140
- > {
141
- let localRuntimeCwd = args.parsed.cwd;
142
- if (shouldPrepareTaskWorktree(args.parsed)) {
143
- try {
144
- const preparedWorktree: PreparedTaskWorktree = await (args.prepareTaskWorktree ?? prepareTaskWorktree)({
145
- agentKey: args.parsed.agentKey,
146
- env: args.env,
147
- });
148
- localRuntimeCwd = preparedWorktree.path;
149
- args.output.write(formatPreparedTaskWorktree(preparedWorktree));
150
- } catch (error) {
151
- args.output.write(
152
- "[nolo] Could not prepare a local task worktree.\n" +
153
- "Run from inside a git repository, or set NOLO_LOCAL_WORKTREE to an existing isolated checkout.\n" +
154
- `Reason: ${error instanceof Error ? error.message : String(error)}\n`
155
- );
156
- return { ok: false, exitCode: 1 };
157
- }
158
- }
159
- if (shouldBindLocalWorkspace({ parsed: args.parsed, localRuntimeCwd })) {
160
- try {
161
- await (args.ensureWorkspacePackageLinks ?? ensureWorkspacePackageLinks)(localRuntimeCwd!);
162
- } catch (error) {
163
- args.output.write(
164
- "[nolo] Dependency preflight failed for local task worktree.\n" +
165
- "The worktree may have node_modules entries that point outside the task checkout, or paths that cannot be repaired safely.\n" +
166
- `Reason: ${error instanceof Error ? error.message : String(error)}\n`
167
- );
168
- return { ok: false, exitCode: 1 };
169
- }
170
- }
171
- return {
172
- ok: true,
173
- ...(localRuntimeCwd ? { localRuntimeCwd } : {}),
174
- runEnv: shouldBindLocalWorkspace({ parsed: args.parsed, localRuntimeCwd })
175
- ? buildTaskWorktreeEnv({
176
- env: args.env,
177
- worktreePath: localRuntimeCwd,
178
- allowShell: args.parsed.allowShell,
179
- })
180
- : args.env,
181
- };
182
- }
@@ -1,298 +0,0 @@
1
- import { existsSync, readFileSync } from "node:fs";
2
- import { extname, resolve } from "node:path";
3
-
4
- import {
5
- buildAgentRunDialogLineageFields,
6
- normalizeAgentRunDialogLineage,
7
- } from "../ai/agent/agentRunDialogLineage";
8
- import { parseSkillDocProtocol, type WorkflowReferenceConfig } from "../ai/skills/skillDocProtocol";
9
-
10
- import { resolveCliAgentKeyInput } from "./agentAliases";
11
- import type { AgentRuntimeRequestedMode } from "./agentRuntimeLocal";
12
- import type { TaskRunPromptContext } from "./client/taskRunPrompt";
13
-
14
- type ParseAgentRunArgsOptions = {
15
- readTextFile?: (path: string) => string;
16
- };
17
-
18
- export type ParsedAgentRunArgs = {
19
- agentKey: string;
20
- message: string;
21
- imageUrls: string[];
22
- allowShell: boolean;
23
- runtimeMode?: AgentRuntimeRequestedMode;
24
- continueDialogId?: string;
25
- spaceId?: string;
26
- category?: string;
27
- inheritedFromDialogKey?: string;
28
- parentDialogId?: string;
29
- background: boolean;
30
- noStream: boolean;
31
- noDefaultTestRoot: boolean;
32
- cwd?: string;
33
- maxToolRounds?: number;
34
- timeoutMs?: number;
35
- traceTools: boolean;
36
- useTaskWorktree: boolean;
37
- taskRunContext?: TaskRunPromptContext;
38
- workflowRef?: string;
39
- };
40
-
41
- export type ResolvedWorkflowReference = {
42
- ref: string;
43
- content: string;
44
- config?: Partial<WorkflowReferenceConfig>;
45
- };
46
-
47
- const DEFAULT_TEST_ROOT_DIALOG_ID = "01KN6V3MVEQA4Q1PNKVM2W7YY8";
48
- const DEFAULT_TEST_ROOT_DIALOG_KEY = `dialog-b2e06f801f-${DEFAULT_TEST_ROOT_DIALOG_ID}`;
49
- const DEFAULT_TEST_DIALOG_CATEGORY_ID = "test-dialogs";
50
-
51
- function readFlagValue(args: string[], flag: string) {
52
- const index = args.indexOf(flag);
53
- if (index < 0) return undefined;
54
- return args[index + 1];
55
- }
56
-
57
- export function readAgentRunInput(args: string[]) {
58
- const rawInput = readFlagValue(args, "--agent") ?? positionalArgs(args)[0];
59
- const trimmed = rawInput?.trim();
60
- return trimmed ? trimmed : undefined;
61
- }
62
-
63
- function readRepeatedFlagValues(args: string[], flag: string) {
64
- const values: string[] = [];
65
- for (let index = 0; index < args.length; index += 1) {
66
- if (args[index] === flag && args[index + 1]) {
67
- values.push(args[index + 1]);
68
- index += 1;
69
- }
70
- }
71
- return values;
72
- }
73
-
74
- function runtimeModeFromArgs(args: string[]): AgentRuntimeRequestedMode | undefined {
75
- if (args.includes("--local")) return "local";
76
- if (args.includes("--server")) return "server";
77
- if (args.includes("--auto")) return "auto";
78
- return undefined;
79
- }
80
-
81
- function parseNonNegativeInteger(value: string | undefined) {
82
- if (!value) return undefined;
83
- const parsed = Number(value);
84
- if (!Number.isFinite(parsed) || parsed < 0) return undefined;
85
- return Math.floor(parsed);
86
- }
87
-
88
- function parsePositiveInteger(value: string | undefined) {
89
- if (!value) return undefined;
90
- const parsed = Number(value);
91
- if (!Number.isFinite(parsed) || parsed <= 0) return undefined;
92
- return Math.floor(parsed);
93
- }
94
-
95
- function positionalArgs(args: string[]) {
96
- const values: string[] = [];
97
- const valuelessFlags = new Set([
98
- "--local",
99
- "--server",
100
- "--auto",
101
- "--dangerously-allow-shell",
102
- "--worktree-task",
103
- "--trace-tools",
104
- "--bg",
105
- "--no-stream",
106
- "--debug",
107
- "--no-default-test-root",
108
- ]);
109
- for (let index = 0; index < args.length; index += 1) {
110
- const arg = args[index];
111
- if (valuelessFlags.has(arg)) continue;
112
- if (arg.startsWith("--")) {
113
- index += 1;
114
- continue;
115
- }
116
- values.push(arg);
117
- }
118
- return values;
119
- }
120
-
121
- function parseDialogReference(rawInput: string) {
122
- const normalized = rawInput.trim();
123
- if (normalized.startsWith("dialog-")) {
124
- const parts = normalized.split("-");
125
- return {
126
- dialogKey: normalized,
127
- dialogId: parts.at(-1) ?? normalized,
128
- };
129
- }
130
- const dialogMatch = normalized.match(/dialog-([a-zA-Z0-9]+)-([a-zA-Z0-9]+)/);
131
- if (dialogMatch) {
132
- return {
133
- dialogKey: `dialog-${dialogMatch[1]}-${dialogMatch[2]}`,
134
- dialogId: dialogMatch[2],
135
- };
136
- }
137
- return {
138
- dialogId: normalized,
139
- };
140
- }
141
-
142
- function workflowRefToCandidatePath(cwd: string, ref: string) {
143
- const normalized = ref.trim();
144
- if (!normalized) return "";
145
- if (normalized.endsWith(".md") || normalized.includes("/") || normalized.includes("\\")) {
146
- const directPath = resolve(cwd, normalized);
147
- if (existsSync(directPath)) return directPath;
148
- }
149
- const fileName = normalized.replace(/[^a-zA-Z0-9\u4e00-\u9fa5]+/g, "-").replace(/^-+|-+$/g, "");
150
- return resolve(cwd, "docs", "workflows", `${fileName}.md`);
151
- }
152
-
153
- function mimeTypeForPath(path: string) {
154
- switch (extname(path).toLowerCase()) {
155
- case ".jpg":
156
- case ".jpeg":
157
- return "image/jpeg";
158
- case ".webp":
159
- return "image/webp";
160
- case ".gif":
161
- return "image/gif";
162
- default:
163
- return "image/png";
164
- }
165
- }
166
-
167
- export function parseAgentRunArgs(
168
- args: string[],
169
- options: ParseAgentRunArgsOptions = {}
170
- ): ParsedAgentRunArgs | null {
171
- const agentKey = readFlagValue(args, "--agent") ?? positionalArgs(args)[0];
172
- const explicitMsg = readFlagValue(args, "--msg");
173
- const msgFile = readFlagValue(args, "--msg-file");
174
- const fileMessage = msgFile
175
- ? (options.readTextFile ?? ((path: string) => readFileSync(path, "utf8")))(msgFile)
176
- : undefined;
177
- const rawMessage = explicitMsg ?? fileMessage ?? positionalArgs(args).slice(1).join(" ");
178
- if (!agentKey || !rawMessage.trim()) return null;
179
- const message = rawMessage.trim();
180
- const runtimeMode = runtimeModeFromArgs(args);
181
- const rawContinueDialogId = readFlagValue(args, "--continue") ?? readFlagValue(args, "--dialog");
182
- const continueDialogId = normalizeAgentRunDialogLineage({
183
- continueDialogId: rawContinueDialogId,
184
- }).continueDialogId;
185
- const spaceId = readFlagValue(args, "--space");
186
- const category = readFlagValue(args, "--category");
187
- const inheritedFromDialog = readFlagValue(args, "--inherit-from-dialog");
188
- const noDefaultTestRoot = args.includes("--no-default-test-root");
189
- const cwd = readFlagValue(args, "--cwd");
190
- const maxToolRounds = parseNonNegativeInteger(
191
- readFlagValue(args, "--max-tool-rounds") ?? readFlagValue(args, "--rounds")
192
- );
193
- const timeoutMs = parsePositiveInteger(readFlagValue(args, "--timeout-ms"));
194
- const inheritedRef = inheritedFromDialog
195
- ? parseDialogReference(inheritedFromDialog)
196
- : !continueDialogId && !noDefaultTestRoot
197
- ? {
198
- dialogKey: DEFAULT_TEST_ROOT_DIALOG_KEY,
199
- dialogId: DEFAULT_TEST_ROOT_DIALOG_ID,
200
- }
201
- : undefined;
202
- const imageUrls = [
203
- ...readRepeatedFlagValues(args, "--image"),
204
- ...readRepeatedFlagValues(args, "--image-url"),
205
- ];
206
- const useTaskWorktree = args.includes("--worktree-task");
207
- const workflowRef = readFlagValue(args, "--workflow");
208
- const taskRowDbKey = readFlagValue(args, "--task-row-dbkey");
209
- const artifactIds = readFlagValue(args, "--artifact-ids")
210
- ?.split(",")
211
- .map((item) => item.trim())
212
- .filter(Boolean);
213
- return {
214
- agentKey: resolveCliAgentKeyInput(agentKey),
215
- message,
216
- imageUrls,
217
- allowShell: args.includes("--dangerously-allow-shell"),
218
- traceTools: args.includes("--trace-tools"),
219
- useTaskWorktree,
220
- ...(workflowRef ? { workflowRef } : {}),
221
- ...(taskRowDbKey
222
- ? {
223
- taskRunContext: {
224
- rowDbKey: taskRowDbKey,
225
- ...(readFlagValue(args, "--task-run-id") ? { taskRunId: readFlagValue(args, "--task-run-id") } : {}),
226
- ...(readFlagValue(args, "--work-item-id") ? { workItemId: readFlagValue(args, "--work-item-id") } : {}),
227
- ...(artifactIds?.length ? { artifactIds } : {}),
228
- },
229
- }
230
- : {}),
231
- ...(runtimeMode ? { runtimeMode } : useTaskWorktree ? { runtimeMode: "local" as const } : {}),
232
- background: args.includes("--bg"),
233
- noStream: args.includes("--no-stream"),
234
- noDefaultTestRoot,
235
- ...buildAgentRunDialogLineageFields({
236
- continueDialogId,
237
- inheritedFromDialogKey: inheritedRef?.dialogKey,
238
- parentDialogId: inheritedRef?.dialogId,
239
- }),
240
- ...(!continueDialogId && spaceId ? { spaceId } : {}),
241
- ...(category
242
- ? { category }
243
- : !continueDialogId && !noDefaultTestRoot
244
- ? { category: DEFAULT_TEST_DIALOG_CATEGORY_ID }
245
- : {}),
246
- ...(cwd ? { cwd } : {}),
247
- ...(typeof maxToolRounds === "number" ? { maxToolRounds } : {}),
248
- ...(typeof timeoutMs === "number" ? { timeoutMs } : {}),
249
- };
250
- }
251
-
252
- export async function resolveWorkflowReference(ref: string, cwd = process.cwd()): Promise<ResolvedWorkflowReference> {
253
- const path = workflowRefToCandidatePath(cwd, ref);
254
- if (!path || !existsSync(path)) {
255
- throw new Error(`Workflow reference not found: ${ref}`);
256
- }
257
- const markdown = readFileSync(path, "utf8");
258
- const parsed = parseSkillDocProtocol(markdown);
259
- return {
260
- ref,
261
- content: parsed.content,
262
- ...(parsed.meta?.workflowConfig ? { config: parsed.meta.workflowConfig } : {}),
263
- };
264
- }
265
-
266
- export function prependWorkflowReferencePrompt(message: string, workflow?: ResolvedWorkflowReference): string {
267
- if (!workflow) return message;
268
- const config = workflow.config;
269
- return [
270
- "AI-native workflow reference:",
271
- "- This reference is guidance for the agent, not a central workflow engine.",
272
- `- ref: ${workflow.ref}`,
273
- ...(config?.id ? [`- id: ${config.id}`] : []),
274
- ...(config?.name ? [`- name: ${config.name}`] : []),
275
- ...(config?.defaultAgent ? [`- suggested defaultAgent: ${config.defaultAgent}`] : []),
276
- ...(config?.inputs?.length ? [`- inputs: ${config.inputs.join(", ")}`] : []),
277
- ...(config?.recommendedTools?.length ? [`- recommendedTools: ${config.recommendedTools.join(", ")}`] : []),
278
- ...(config?.requiredTools?.length ? [`- requiredTools: ${config.requiredTools.join(", ")}`] : []),
279
- ...(config?.requiredOutputs?.length ? [`- requiredOutputs: ${config.requiredOutputs.join(", ")}`] : []),
280
- ...(config?.gates?.length ? [`- gates: ${config.gates.join(", ")}`] : []),
281
- ...(config?.contextStrategy ? [`- contextStrategy: ${config.contextStrategy}`] : []),
282
- ...(config?.failureProtocol ? [`- failureProtocol: ${config.failureProtocol}`] : []),
283
- "",
284
- "Reference body:",
285
- workflow.content,
286
- "",
287
- "User task:",
288
- message,
289
- ].join("\n");
290
- }
291
-
292
- export function normalizeCliImageInput(input: string) {
293
- if (/^(https?:|data:|file:)/i.test(input)) return input;
294
- const absolutePath = resolve(input);
295
- if (!existsSync(absolutePath)) return input;
296
- const base64 = readFileSync(absolutePath).toString("base64");
297
- return `data:${mimeTypeForPath(absolutePath)};base64,${base64}`;
298
- }
@@ -1,8 +0,0 @@
1
- import { runScriptPassthrough, type ScriptPassthroughDeps } from "./scriptPassthroughHelpers";
2
-
3
- export async function runAgentSuperviseCommand(
4
- args: string[],
5
- deps: ScriptPassthroughDeps = {}
6
- ) {
7
- return runScriptPassthrough("scripts/runAutonomousAgent.ts", args, deps);
8
- }
@@ -1,113 +0,0 @@
1
- import { getReadableCliDb, type AgentCommandDeps } from "./agentCommandSupport";
2
- import {
3
- deleteDbRecord,
4
- resolveAgentRecordFromHybridStore,
5
- writeAgentRecord,
6
- } from "./agentRecordHelpers";
7
- import { parseUserIdFromAuthToken, resolveAuthToken, resolveServerUrl } from "./cliEnvHelpers";
8
-
9
- function readOption(args: string[], flag: string) {
10
- const index = args.indexOf(flag);
11
- return index >= 0 ? args[index + 1] : undefined;
12
- }
13
-
14
- function usage() {
15
- return [
16
- "Usage:",
17
- " nolo agent unpublish --id <agentId>",
18
- "",
19
- ].join("\n");
20
- }
21
-
22
- export async function runAgentUnpublishCommand(
23
- args: string[],
24
- deps: AgentCommandDeps = {}
25
- ) {
26
- const env = deps.env ?? process.env;
27
- const output = deps.output ?? process.stdout;
28
- const agentId = readOption(args, "--id")?.trim();
29
-
30
- if (args.includes("--help") || args.includes("-h")) {
31
- output.write(`${usage()}\n`);
32
- return 0;
33
- }
34
- if (!agentId) {
35
- output.write(`${usage()}\n`);
36
- return 1;
37
- }
38
-
39
- const authToken = resolveAuthToken(args, env);
40
- if (!authToken) {
41
- output.write("[nolo] agent unpublish requires an auth token. Run `nolo login` or set AUTH_TOKEN.\n");
42
- return 1;
43
- }
44
-
45
- const userId = parseUserIdFromAuthToken(authToken);
46
- if (!userId) {
47
- output.write("[nolo] agent unpublish could not read userId from AUTH_TOKEN.\n");
48
- return 1;
49
- }
50
-
51
- const db = deps.db ?? await getReadableCliDb(output);
52
- const fetchImpl = deps.fetchImpl ?? fetch;
53
- const fallbackFetchImpl = deps.fallbackFetchImpl;
54
- const serverUrl = resolveServerUrl(args, env);
55
- const privateKey = `agent-${userId}-${agentId}`;
56
- const publicKey = `agent-pub-${agentId}`;
57
-
58
- try {
59
- const resolved = await resolveAgentRecordFromHybridStore({
60
- agentInput: privateKey,
61
- cliArgs: args,
62
- env,
63
- db,
64
- fetchImpl,
65
- fallbackFetchImpl,
66
- });
67
- if (!resolved) {
68
- throw new Error(`private agent record not found: ${privateKey}`);
69
- }
70
-
71
- const nextRecord = {
72
- ...resolved.record,
73
- isPublic: false,
74
- updatedAt: Date.now(),
75
- };
76
-
77
- await writeAgentRecord({
78
- agentKey: privateKey,
79
- authToken,
80
- fallbackFetchImpl,
81
- fetchImpl,
82
- serverUrl,
83
- userId,
84
- record: nextRecord,
85
- });
86
- await db.put(privateKey, {
87
- ...nextRecord,
88
- dbKey: privateKey,
89
- key: nextRecord?.key || privateKey,
90
- serverOrigin: serverUrl,
91
- });
92
- output.write(`updated ${privateKey} isPublic=false\n`);
93
-
94
- const deleteStatus = await deleteDbRecord({
95
- authToken,
96
- dbKey: publicKey,
97
- fallbackFetchImpl,
98
- fetchImpl,
99
- serverUrl,
100
- userId,
101
- });
102
- await db.batch([{ type: "del", key: publicKey }]);
103
- output.write(`${deleteStatus} ${publicKey}\n`);
104
- return 0;
105
- } catch (error) {
106
- output.write(
107
- `[nolo] agent unpublish failed: ${
108
- error instanceof Error ? error.message : String(error)
109
- }\n`
110
- );
111
- return 1;
112
- }
113
- }