@camerontaylor/paseo-cli 0.8.0-fork.1

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 (288) hide show
  1. package/bin/paseo +3 -0
  2. package/dist/classify.d.ts +19 -0
  3. package/dist/classify.js +49 -0
  4. package/dist/cli.d.ts +3 -0
  5. package/dist/cli.js +135 -0
  6. package/dist/commands/agent/archive.d.ts +18 -0
  7. package/dist/commands/agent/archive.js +102 -0
  8. package/dist/commands/agent/attach.d.ts +11 -0
  9. package/dist/commands/agent/attach.js +161 -0
  10. package/dist/commands/agent/delete.d.ts +15 -0
  11. package/dist/commands/agent/delete.js +107 -0
  12. package/dist/commands/agent/detach.d.ts +9 -0
  13. package/dist/commands/agent/detach.js +38 -0
  14. package/dist/commands/agent/import.d.ts +14 -0
  15. package/dist/commands/agent/import.js +122 -0
  16. package/dist/commands/agent/index.d.ts +3 -0
  17. package/dist/commands/agent/index.js +56 -0
  18. package/dist/commands/agent/inspect.d.ts +15 -0
  19. package/dist/commands/agent/inspect.js +209 -0
  20. package/dist/commands/agent/logs.d.ts +19 -0
  21. package/dist/commands/agent/logs.js +180 -0
  22. package/dist/commands/agent/ls.d.ts +44 -0
  23. package/dist/commands/agent/ls.js +212 -0
  24. package/dist/commands/agent/mode.d.ts +18 -0
  25. package/dist/commands/agent/mode.js +100 -0
  26. package/dist/commands/agent/open.d.ts +11 -0
  27. package/dist/commands/agent/open.js +61 -0
  28. package/dist/commands/agent/reload.d.ts +15 -0
  29. package/dist/commands/agent/reload.js +75 -0
  30. package/dist/commands/agent/run.d.ts +78 -0
  31. package/dist/commands/agent/run.js +554 -0
  32. package/dist/commands/agent/send.d.ts +19 -0
  33. package/dist/commands/agent/send.js +187 -0
  34. package/dist/commands/agent/stop.d.ts +17 -0
  35. package/dist/commands/agent/stop.js +115 -0
  36. package/dist/commands/agent/update.d.ts +51 -0
  37. package/dist/commands/agent/update.js +186 -0
  38. package/dist/commands/agent/wait.d.ts +17 -0
  39. package/dist/commands/agent/wait.js +158 -0
  40. package/dist/commands/clone.d.ts +17 -0
  41. package/dist/commands/clone.js +65 -0
  42. package/dist/commands/daemon/index.d.ts +3 -0
  43. package/dist/commands/daemon/index.js +60 -0
  44. package/dist/commands/daemon/local-daemon.d.ts +78 -0
  45. package/dist/commands/daemon/local-daemon.js +547 -0
  46. package/dist/commands/daemon/pair.d.ts +35 -0
  47. package/dist/commands/daemon/pair.js +167 -0
  48. package/dist/commands/daemon/reload.d.ts +10 -0
  49. package/dist/commands/daemon/reload.js +36 -0
  50. package/dist/commands/daemon/restart.d.ts +12 -0
  51. package/dist/commands/daemon/restart.js +99 -0
  52. package/dist/commands/daemon/runtime-toolchain.d.ts +6 -0
  53. package/dist/commands/daemon/runtime-toolchain.js +87 -0
  54. package/dist/commands/daemon/set-password.d.ts +17 -0
  55. package/dist/commands/daemon/set-password.js +82 -0
  56. package/dist/commands/daemon/start.d.ts +6 -0
  57. package/dist/commands/daemon/start.js +57 -0
  58. package/dist/commands/daemon/status.d.ts +21 -0
  59. package/dist/commands/daemon/status.js +363 -0
  60. package/dist/commands/daemon/stop.d.ts +15 -0
  61. package/dist/commands/daemon/stop.js +60 -0
  62. package/dist/commands/heartbeat/index.d.ts +3 -0
  63. package/dist/commands/heartbeat/index.js +139 -0
  64. package/dist/commands/hooks.d.ts +19 -0
  65. package/dist/commands/hooks.js +89 -0
  66. package/dist/commands/hub/authority.d.ts +17 -0
  67. package/dist/commands/hub/authority.js +18 -0
  68. package/dist/commands/hub/connect.d.ts +23 -0
  69. package/dist/commands/hub/connect.js +44 -0
  70. package/dist/commands/hub/credentials.d.ts +21 -0
  71. package/dist/commands/hub/credentials.js +143 -0
  72. package/dist/commands/hub/daemon-client.d.ts +40 -0
  73. package/dist/commands/hub/daemon-client.js +14 -0
  74. package/dist/commands/hub/deploy-bundle.d.ts +16 -0
  75. package/dist/commands/hub/deploy-bundle.js +248 -0
  76. package/dist/commands/hub/deploy-triggers.d.ts +6 -0
  77. package/dist/commands/hub/deploy-triggers.js +116 -0
  78. package/dist/commands/hub/deploy.d.ts +50 -0
  79. package/dist/commands/hub/deploy.js +159 -0
  80. package/dist/commands/hub/disconnect.d.ts +16 -0
  81. package/dist/commands/hub/disconnect.js +24 -0
  82. package/dist/commands/hub/error.d.ts +6 -0
  83. package/dist/commands/hub/error.js +9 -0
  84. package/dist/commands/hub/export.d.ts +28 -0
  85. package/dist/commands/hub/export.js +80 -0
  86. package/dist/commands/hub/help.d.ts +3 -0
  87. package/dist/commands/hub/help.js +5 -0
  88. package/dist/commands/hub/hub-client/index.d.ts +22 -0
  89. package/dist/commands/hub/hub-client/index.js +135 -0
  90. package/dist/commands/hub/hub-client/internal/contracts.d.ts +126 -0
  91. package/dist/commands/hub/hub-client/internal/contracts.js +85 -0
  92. package/dist/commands/hub/hub-client/internal/problem.d.ts +3 -0
  93. package/dist/commands/hub/hub-client/internal/problem.js +85 -0
  94. package/dist/commands/hub/hub-client/internal/transport.d.ts +15 -0
  95. package/dist/commands/hub/hub-client/internal/transport.js +30 -0
  96. package/dist/commands/hub/index.d.ts +20 -0
  97. package/dist/commands/hub/index.js +94 -0
  98. package/dist/commands/hub/init-plan.d.ts +33 -0
  99. package/dist/commands/hub/init-plan.js +94 -0
  100. package/dist/commands/hub/init.d.ts +35 -0
  101. package/dist/commands/hub/init.js +524 -0
  102. package/dist/commands/hub/login-flow.d.ts +34 -0
  103. package/dist/commands/hub/login-flow.js +78 -0
  104. package/dist/commands/hub/login.d.ts +23 -0
  105. package/dist/commands/hub/login.js +40 -0
  106. package/dist/commands/hub/logout.d.ts +32 -0
  107. package/dist/commands/hub/logout.js +71 -0
  108. package/dist/commands/hub/origin.d.ts +2 -0
  109. package/dist/commands/hub/origin.js +27 -0
  110. package/dist/commands/hub/permissions.d.ts +21 -0
  111. package/dist/commands/hub/permissions.js +61 -0
  112. package/dist/commands/hub/projects.d.ts +24 -0
  113. package/dist/commands/hub/projects.js +49 -0
  114. package/dist/commands/hub/reporter.d.ts +10 -0
  115. package/dist/commands/hub/reporter.js +11 -0
  116. package/dist/commands/hub/starter-agent-runtime.d.ts +37 -0
  117. package/dist/commands/hub/starter-agent-runtime.js +49 -0
  118. package/dist/commands/hub/starter-trigger.d.ts +10 -0
  119. package/dist/commands/hub/starter-trigger.js +30 -0
  120. package/dist/commands/hub/status-output.d.ts +13 -0
  121. package/dist/commands/hub/status-output.js +30 -0
  122. package/dist/commands/onboard.d.ts +10 -0
  123. package/dist/commands/onboard.js +400 -0
  124. package/dist/commands/open.d.ts +4 -0
  125. package/dist/commands/open.js +89 -0
  126. package/dist/commands/permit/allow.d.ts +20 -0
  127. package/dist/commands/permit/allow.js +133 -0
  128. package/dist/commands/permit/deny.d.ts +12 -0
  129. package/dist/commands/permit/deny.js +105 -0
  130. package/dist/commands/permit/index.d.ts +3 -0
  131. package/dist/commands/permit/index.js +27 -0
  132. package/dist/commands/permit/ls.d.ts +18 -0
  133. package/dist/commands/permit/ls.js +66 -0
  134. package/dist/commands/plugin/index.d.ts +17 -0
  135. package/dist/commands/plugin/index.js +138 -0
  136. package/dist/commands/plugin/scaffold.d.ts +6 -0
  137. package/dist/commands/plugin/scaffold.js +162 -0
  138. package/dist/commands/plugin/shared.d.ts +5 -0
  139. package/dist/commands/plugin/shared.js +30 -0
  140. package/dist/commands/project/create.d.ts +10 -0
  141. package/dist/commands/project/create.js +41 -0
  142. package/dist/commands/project/delete.d.ts +9 -0
  143. package/dist/commands/project/delete.js +33 -0
  144. package/dist/commands/project/index.d.ts +3 -0
  145. package/dist/commands/project/index.js +28 -0
  146. package/dist/commands/project/ls.d.ts +5 -0
  147. package/dist/commands/project/ls.js +19 -0
  148. package/dist/commands/project/rename.d.ts +15 -0
  149. package/dist/commands/project/rename.js +50 -0
  150. package/dist/commands/project/shared.d.ts +11 -0
  151. package/dist/commands/project/shared.js +18 -0
  152. package/dist/commands/provider/add.d.ts +30 -0
  153. package/dist/commands/provider/add.js +123 -0
  154. package/dist/commands/provider/diagnostic.d.ts +12 -0
  155. package/dist/commands/provider/diagnostic.js +31 -0
  156. package/dist/commands/provider/index.d.ts +3 -0
  157. package/dist/commands/provider/index.js +38 -0
  158. package/dist/commands/provider/ls.d.ts +20 -0
  159. package/dist/commands/provider/ls.js +76 -0
  160. package/dist/commands/provider/models.d.ts +20 -0
  161. package/dist/commands/provider/models.js +53 -0
  162. package/dist/commands/provider/rm.d.ts +10 -0
  163. package/dist/commands/provider/rm.js +45 -0
  164. package/dist/commands/provider/shared.d.ts +7 -0
  165. package/dist/commands/provider/shared.js +10 -0
  166. package/dist/commands/schedule/create.d.ts +19 -0
  167. package/dist/commands/schedule/create.js +41 -0
  168. package/dist/commands/schedule/delete.d.ts +10 -0
  169. package/dist/commands/schedule/delete.js +32 -0
  170. package/dist/commands/schedule/index.d.ts +3 -0
  171. package/dist/commands/schedule/index.js +66 -0
  172. package/dist/commands/schedule/inspect.d.ts +6 -0
  173. package/dist/commands/schedule/inspect.js +27 -0
  174. package/dist/commands/schedule/logs.d.ts +6 -0
  175. package/dist/commands/schedule/logs.js +24 -0
  176. package/dist/commands/schedule/ls.d.ts +5 -0
  177. package/dist/commands/schedule/ls.js +25 -0
  178. package/dist/commands/schedule/pause.d.ts +5 -0
  179. package/dist/commands/schedule/pause.js +24 -0
  180. package/dist/commands/schedule/resume.d.ts +5 -0
  181. package/dist/commands/schedule/resume.js +24 -0
  182. package/dist/commands/schedule/run-once.d.ts +5 -0
  183. package/dist/commands/schedule/run-once.js +24 -0
  184. package/dist/commands/schedule/schema.d.ts +21 -0
  185. package/dist/commands/schedule/schema.js +67 -0
  186. package/dist/commands/schedule/shared.d.ts +59 -0
  187. package/dist/commands/schedule/shared.js +358 -0
  188. package/dist/commands/schedule/types.d.ts +165 -0
  189. package/dist/commands/schedule/types.js +2 -0
  190. package/dist/commands/schedule/update.d.ts +21 -0
  191. package/dist/commands/schedule/update.js +40 -0
  192. package/dist/commands/script/index.d.ts +3 -0
  193. package/dist/commands/script/index.js +19 -0
  194. package/dist/commands/script/ls.d.ts +6 -0
  195. package/dist/commands/script/ls.js +20 -0
  196. package/dist/commands/script/schema.d.ts +5 -0
  197. package/dist/commands/script/schema.js +13 -0
  198. package/dist/commands/script/shared.d.ts +11 -0
  199. package/dist/commands/script/shared.js +59 -0
  200. package/dist/commands/script/start.d.ts +6 -0
  201. package/dist/commands/script/start.js +23 -0
  202. package/dist/commands/script/stop.d.ts +6 -0
  203. package/dist/commands/script/stop.js +23 -0
  204. package/dist/commands/speech/index.d.ts +3 -0
  205. package/dist/commands/speech/index.js +5 -0
  206. package/dist/commands/terminal/capture.d.ts +10 -0
  207. package/dist/commands/terminal/capture.js +68 -0
  208. package/dist/commands/terminal/create.d.ts +11 -0
  209. package/dist/commands/terminal/create.js +29 -0
  210. package/dist/commands/terminal/index.d.ts +3 -0
  211. package/dist/commands/terminal/index.js +45 -0
  212. package/dist/commands/terminal/kill.d.ts +6 -0
  213. package/dist/commands/terminal/kill.js +36 -0
  214. package/dist/commands/terminal/ls.d.ts +11 -0
  215. package/dist/commands/terminal/ls.js +21 -0
  216. package/dist/commands/terminal/schema.d.ts +10 -0
  217. package/dist/commands/terminal/schema.js +17 -0
  218. package/dist/commands/terminal/send-keys.d.ts +7 -0
  219. package/dist/commands/terminal/send-keys.js +45 -0
  220. package/dist/commands/terminal/shared.d.ts +12 -0
  221. package/dist/commands/terminal/shared.js +62 -0
  222. package/dist/commands/workspace/archive.d.ts +12 -0
  223. package/dist/commands/workspace/archive.js +41 -0
  224. package/dist/commands/workspace/create.d.ts +49 -0
  225. package/dist/commands/workspace/create.js +114 -0
  226. package/dist/commands/workspace/index.d.ts +3 -0
  227. package/dist/commands/workspace/index.js +45 -0
  228. package/dist/commands/workspace/ls.d.ts +7 -0
  229. package/dist/commands/workspace/ls.js +28 -0
  230. package/dist/commands/workspace/rename.d.ts +22 -0
  231. package/dist/commands/workspace/rename.js +61 -0
  232. package/dist/commands/workspace/setup.d.ts +11 -0
  233. package/dist/commands/workspace/setup.js +41 -0
  234. package/dist/commands/workspace/shared.d.ts +12 -0
  235. package/dist/commands/workspace/shared.js +20 -0
  236. package/dist/commands/worktree/archive.d.ts +20 -0
  237. package/dist/commands/worktree/archive.js +104 -0
  238. package/dist/commands/worktree/create-input.d.ts +15 -0
  239. package/dist/commands/worktree/create-input.js +56 -0
  240. package/dist/commands/worktree/create.d.ts +11 -0
  241. package/dist/commands/worktree/create.js +58 -0
  242. package/dist/commands/worktree/index.d.ts +3 -0
  243. package/dist/commands/worktree/index.js +25 -0
  244. package/dist/commands/worktree/ls.d.ts +19 -0
  245. package/dist/commands/worktree/ls.js +97 -0
  246. package/dist/index.d.ts +2 -0
  247. package/dist/index.js +6 -0
  248. package/dist/output/index.d.ts +45 -0
  249. package/dist/output/index.js +47 -0
  250. package/dist/output/json.d.ts +11 -0
  251. package/dist/output/json.js +37 -0
  252. package/dist/output/pairing.d.ts +8 -0
  253. package/dist/output/pairing.js +24 -0
  254. package/dist/output/quiet.d.ts +9 -0
  255. package/dist/output/quiet.js +22 -0
  256. package/dist/output/render.d.ts +15 -0
  257. package/dist/output/render.js +84 -0
  258. package/dist/output/table.d.ts +13 -0
  259. package/dist/output/table.js +135 -0
  260. package/dist/output/types.d.ts +73 -0
  261. package/dist/output/types.js +8 -0
  262. package/dist/output/with-output.d.ts +41 -0
  263. package/dist/output/with-output.js +85 -0
  264. package/dist/output/yaml.d.ts +11 -0
  265. package/dist/output/yaml.js +38 -0
  266. package/dist/run.d.ts +14 -0
  267. package/dist/run.js +40 -0
  268. package/dist/ssh/ssh-tunnel.d.ts +9 -0
  269. package/dist/ssh/ssh-tunnel.js +79 -0
  270. package/dist/utils/client-id.d.ts +2 -0
  271. package/dist/utils/client-id.js +37 -0
  272. package/dist/utils/client.d.ts +54 -0
  273. package/dist/utils/client.js +363 -0
  274. package/dist/utils/command-options.d.ts +7 -0
  275. package/dist/utils/command-options.js +25 -0
  276. package/dist/utils/duration.d.ts +7 -0
  277. package/dist/utils/duration.js +39 -0
  278. package/dist/utils/errors.d.ts +5 -0
  279. package/dist/utils/errors.js +10 -0
  280. package/dist/utils/paths.d.ts +12 -0
  281. package/dist/utils/paths.js +22 -0
  282. package/dist/utils/provider-model.d.ts +11 -0
  283. package/dist/utils/provider-model.js +49 -0
  284. package/dist/utils/timeline.d.ts +11 -0
  285. package/dist/utils/timeline.js +11 -0
  286. package/dist/version.d.ts +2 -0
  287. package/dist/version.js +10 -0
  288. package/package.json +50 -0
@@ -0,0 +1,554 @@
1
+ import { Option } from "commander";
2
+ import { getStructuredAgentResponse, StructuredAgentResponseError } from "@camerontaylor/paseo-server";
3
+ import { connectToDaemon, getDaemonHost } from "../../utils/client.js";
4
+ import { readFileSync } from "node:fs";
5
+ import { resolve } from "node:path";
6
+ import { lookup } from "mime-types";
7
+ import { parseDuration } from "../../utils/duration.js";
8
+ import { collectMultiple } from "../../utils/command-options.js";
9
+ import { resolveProviderAndModel } from "../../utils/provider-model.js";
10
+ import { buildWorkspaceSource } from "../workspace/create.js";
11
+ export { resolveProviderAndModel } from "../../utils/provider-model.js";
12
+ export function addRunOptions(cmd) {
13
+ return (cmd
14
+ .description("Create and start an agent with a task")
15
+ .argument("<prompt>", "The task/prompt for the agent")
16
+ .option("-d, --background", "Run in background")
17
+ // COMPAT(detachRunFlag): --detach used to mean background execution, not
18
+ // ownership transfer. Added in v0.2.0; remove after 2027-01-17.
19
+ .addOption(new Option("--detach", "Legacy alias for --background").hideHelp())
20
+ .option("--title <title>", "Assign a title to the agent")
21
+ .addOption(new Option("--name <name>", "Hidden alias for --title").hideHelp())
22
+ .option("--provider <provider>", "Agent provider, or provider/model (e.g. codex or codex/gpt-5.4)")
23
+ .option("--model <model>", "Model to use (e.g., claude-sonnet-4-20250514, claude-3-5-haiku-20241022)")
24
+ .option("--thinking <id>", "Thinking option ID to use for this run")
25
+ .option("--mode <mode>", "Provider-specific mode (e.g., plan, default, bypass)")
26
+ .option("--new-workspace <local|worktree>", "Create a separate local or worktree workspace")
27
+ .addOption(new Option("--worktree <name>", "Legacy workspace isolation alias").hideHelp())
28
+ .option("--worktree-mode <mode>", "Worktree mode: branch-off, checkout-branch, or checkout-pr")
29
+ .option("--worktree-slug <slug>", "Managed worktree path slug")
30
+ .option("--new-branch <name>", "New branch name for branch-off mode")
31
+ .option("--base <ref>", "Base ref for branch-off mode")
32
+ .option("--branch <name>", "Existing branch for checkout-branch mode")
33
+ .option("--pr-number <n>", "Pull request or change request number for checkout-pr mode")
34
+ .option("--forge <forge>", "Forge for checkout-pr mode")
35
+ .option("--workspace <id>", "Run in an existing workspace (defaults to the caller workspace when agent-scoped)")
36
+ .option("--image <path>", "Attach image(s) to the initial prompt (can be used multiple times)", collectMultiple, [])
37
+ .option("--cwd <path>", "Working directory (default: current)")
38
+ .option("--env <key=value>", "Set environment variable(s) for the agent process (can be used multiple times)", collectMultiple, [])
39
+ .option("--label <key=value>", "Add label(s) to the agent (can be used multiple times)", collectMultiple, [])
40
+ .option("--wait-timeout <duration>", "Maximum time to wait for agent to finish (e.g., 30s, 5m, 1h). Default: no limit")
41
+ .option("--output-schema <schema>", "Output JSON matching the provided schema file path or inline JSON schema"));
42
+ }
43
+ /** Schema for agent run output */
44
+ export const agentRunSchema = {
45
+ idField: "agentId",
46
+ columns: [
47
+ { header: "AGENT ID", field: "agentId", width: 12 },
48
+ { header: "STATUS", field: "status", width: 10 },
49
+ { header: "PROVIDER", field: "provider", width: 10 },
50
+ { header: "CWD", field: "cwd", width: 30 },
51
+ { header: "TITLE", field: "title", width: 20 },
52
+ ],
53
+ };
54
+ function resolveNewWorkspaceKind(options) {
55
+ return options.newWorkspace ?? (options.worktree ? "worktree" : undefined);
56
+ }
57
+ function buildRunWorkspaceSource(options, cwd) {
58
+ const newWorkspace = resolveNewWorkspaceKind(options) ?? "local";
59
+ return buildWorkspaceSource({
60
+ isolation: newWorkspace,
61
+ path: cwd,
62
+ mode: options.worktreeMode,
63
+ worktreeSlug: options.worktreeSlug ?? options.worktree,
64
+ newBranch: options.newBranch,
65
+ base: options.base,
66
+ branch: options.branch,
67
+ prNumber: options.prNumber,
68
+ forge: options.forge,
69
+ });
70
+ }
71
+ function toRunResult(agent, statusOverride) {
72
+ return {
73
+ agentId: agent.id,
74
+ status: statusOverride ?? (agent.status === "running" ? "running" : "created"),
75
+ provider: agent.provider,
76
+ cwd: agent.cwd,
77
+ title: agent.title,
78
+ };
79
+ }
80
+ function loadOutputSchema(value) {
81
+ const trimmed = value.trim();
82
+ if (!trimmed) {
83
+ const error = {
84
+ code: "INVALID_OUTPUT_SCHEMA",
85
+ message: "--output-schema cannot be empty",
86
+ details: "Provide a JSON schema file path or inline JSON object",
87
+ };
88
+ throw error;
89
+ }
90
+ let source = trimmed;
91
+ if (!trimmed.startsWith("{")) {
92
+ try {
93
+ source = readFileSync(resolve(trimmed), "utf8");
94
+ }
95
+ catch (err) {
96
+ const message = err instanceof Error ? err.message : String(err);
97
+ const error = {
98
+ code: "INVALID_OUTPUT_SCHEMA",
99
+ message: `Failed to read output schema file: ${trimmed}`,
100
+ details: message,
101
+ };
102
+ throw error;
103
+ }
104
+ }
105
+ let parsed;
106
+ try {
107
+ parsed = JSON.parse(source);
108
+ }
109
+ catch (err) {
110
+ const message = err instanceof Error ? err.message : String(err);
111
+ const error = {
112
+ code: "INVALID_OUTPUT_SCHEMA",
113
+ message: "Failed to parse output schema JSON",
114
+ details: message,
115
+ };
116
+ throw error;
117
+ }
118
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
119
+ const error = {
120
+ code: "INVALID_OUTPUT_SCHEMA",
121
+ message: "Output schema must be a JSON object",
122
+ };
123
+ throw error;
124
+ }
125
+ return parsed;
126
+ }
127
+ class StructuredRunStatusError extends Error {
128
+ constructor(kind, message) {
129
+ super(message);
130
+ this.name = "StructuredRunStatusError";
131
+ this.kind = kind;
132
+ }
133
+ }
134
+ async function fetchStructuredOutput(caller, prompt, outputSchema) {
135
+ try {
136
+ return await getStructuredAgentResponse({
137
+ caller,
138
+ prompt,
139
+ schema: outputSchema,
140
+ schemaName: "RunOutput",
141
+ maxRetries: 2,
142
+ });
143
+ }
144
+ catch (err) {
145
+ if (err instanceof StructuredRunStatusError) {
146
+ throw {
147
+ code: "OUTPUT_SCHEMA_FAILED",
148
+ message: err.message,
149
+ };
150
+ }
151
+ if (err instanceof StructuredAgentResponseError) {
152
+ throw {
153
+ code: "OUTPUT_SCHEMA_FAILED",
154
+ message: "Agent response did not match the required output schema",
155
+ details: err.validationErrors.length > 0
156
+ ? err.validationErrors.join("\n")
157
+ : err.lastResponse || "No response",
158
+ };
159
+ }
160
+ throw err;
161
+ }
162
+ }
163
+ export async function resolveStructuredResponseMessage(options) {
164
+ const direct = options.lastMessage?.trim();
165
+ if (direct) {
166
+ return direct;
167
+ }
168
+ try {
169
+ const timeline = await options.client.fetchAgentTimeline(options.agentId, {
170
+ direction: "tail",
171
+ limit: 200,
172
+ });
173
+ for (let index = timeline.entries.length - 1; index >= 0; index -= 1) {
174
+ const entry = timeline.entries[index];
175
+ if (!entry || entry.item.type !== "assistant_message") {
176
+ continue;
177
+ }
178
+ const text = entry.item.text.trim();
179
+ if (text.length > 0) {
180
+ return text;
181
+ }
182
+ }
183
+ }
184
+ catch {
185
+ // Leave empty; caller will surface a consistent structured-output failure message.
186
+ }
187
+ return null;
188
+ }
189
+ function structuredRunSchema(output) {
190
+ return {
191
+ ...agentRunSchema,
192
+ serialize: () => output,
193
+ };
194
+ }
195
+ function validateRunWorkspaceOptions(options) {
196
+ const newWorkspace = resolveNewWorkspaceKind(options);
197
+ if (options.newWorkspace &&
198
+ options.newWorkspace !== "local" &&
199
+ options.newWorkspace !== "worktree") {
200
+ throw {
201
+ code: "INVALID_OPTIONS",
202
+ message: `Unsupported new workspace kind: ${options.newWorkspace}`,
203
+ details: "Use --new-workspace local or --new-workspace worktree",
204
+ };
205
+ }
206
+ if (options.newWorkspace && options.worktree) {
207
+ throw {
208
+ code: "INVALID_OPTIONS",
209
+ message: "--new-workspace and --worktree cannot be combined",
210
+ details: "Use --new-workspace worktree and the supported worktree options",
211
+ };
212
+ }
213
+ const hasWorktreeCreationOptions = [
214
+ options.worktreeMode,
215
+ options.worktreeSlug,
216
+ options.newBranch,
217
+ options.base,
218
+ options.branch,
219
+ options.prNumber,
220
+ options.forge,
221
+ ].some((value) => value !== undefined);
222
+ if (hasWorktreeCreationOptions && newWorkspace !== "worktree") {
223
+ throw {
224
+ code: "INVALID_OPTIONS",
225
+ message: "Worktree options require --new-workspace worktree",
226
+ details: "Usage: paseo run --new-workspace worktree [worktree options] <prompt>",
227
+ };
228
+ }
229
+ if (newWorkspace === "worktree") {
230
+ try {
231
+ buildRunWorkspaceSource(options, options.cwd ?? process.cwd());
232
+ }
233
+ catch (error) {
234
+ throw {
235
+ code: "INVALID_OPTIONS",
236
+ message: error instanceof Error ? error.message : String(error),
237
+ };
238
+ }
239
+ }
240
+ if (options.newWorkspace && options.workspace) {
241
+ throw {
242
+ code: "INVALID_OPTIONS",
243
+ message: "--new-workspace and --workspace cannot be combined",
244
+ details: "Select an existing workspace or explicitly create a new one",
245
+ };
246
+ }
247
+ // COMPAT(worktreeRunFlag): --worktree implies a new worktree-isolated workspace.
248
+ // Added in v0.2.0; remove after 2027-01-17.
249
+ if (options.worktree && options.workspace) {
250
+ throw {
251
+ code: "INVALID_OPTIONS",
252
+ message: "--worktree and --workspace cannot be combined",
253
+ details: "Use --new-workspace worktree instead of the legacy --worktree flag",
254
+ };
255
+ }
256
+ }
257
+ function validateRunOptions(prompt, options, outputSchema) {
258
+ if (!prompt || prompt.trim().length === 0) {
259
+ throw {
260
+ code: "MISSING_PROMPT",
261
+ message: "A prompt is required",
262
+ details: "Usage: paseo agent run [options] <prompt>",
263
+ };
264
+ }
265
+ validateRunWorkspaceOptions(options);
266
+ if (outputSchema && runsInBackground(options)) {
267
+ throw {
268
+ code: "INVALID_OPTIONS",
269
+ message: "--output-schema cannot be used with --background",
270
+ details: "Structured output requires waiting for the agent to finish",
271
+ };
272
+ }
273
+ }
274
+ function runsInBackground(options) {
275
+ return Boolean(options.background || options.detach);
276
+ }
277
+ function parseWaitTimeoutOption(waitTimeout) {
278
+ if (!waitTimeout)
279
+ return 0;
280
+ try {
281
+ const ms = parseDuration(waitTimeout);
282
+ if (ms <= 0) {
283
+ throw new Error("Timeout must be positive");
284
+ }
285
+ return ms;
286
+ }
287
+ catch (err) {
288
+ const message = err instanceof Error ? err.message : String(err);
289
+ throw {
290
+ code: "INVALID_TIMEOUT",
291
+ message: "Invalid wait timeout value",
292
+ details: message,
293
+ };
294
+ }
295
+ }
296
+ function loadRunImages(imagePaths) {
297
+ if (!imagePaths || imagePaths.length === 0)
298
+ return undefined;
299
+ return imagePaths.map((imagePath) => {
300
+ const resolvedPath = resolve(imagePath);
301
+ try {
302
+ const imageData = readFileSync(resolvedPath);
303
+ const mimeType = lookup(resolvedPath) || "application/octet-stream";
304
+ if (!mimeType.startsWith("image/")) {
305
+ throw new Error(`File is not an image: ${imagePath} (detected type: ${mimeType})`);
306
+ }
307
+ return {
308
+ data: imageData.toString("base64"),
309
+ mimeType,
310
+ };
311
+ }
312
+ catch (err) {
313
+ const message = err instanceof Error ? err.message : String(err);
314
+ throw new Error(`Failed to read image ${imagePath}: ${message}`, { cause: err });
315
+ }
316
+ });
317
+ }
318
+ function parseRunLabels(labelFlags) {
319
+ return parseKeyValueFlags(labelFlags, {
320
+ flagName: "--label",
321
+ code: "INVALID_LABEL",
322
+ noun: "label",
323
+ pluralNoun: "Labels",
324
+ });
325
+ }
326
+ function parseRunEnv(envFlags) {
327
+ return parseKeyValueFlags(envFlags, {
328
+ flagName: "--env",
329
+ code: "INVALID_ENV",
330
+ noun: "environment variable",
331
+ pluralNoun: "Environment variables",
332
+ });
333
+ }
334
+ function parseKeyValueFlags(flags, options) {
335
+ const labels = {};
336
+ if (!flags)
337
+ return labels;
338
+ for (const labelStr of flags) {
339
+ const eqIndex = labelStr.indexOf("=");
340
+ if (eqIndex === -1) {
341
+ throw {
342
+ code: options.code,
343
+ message: `Invalid ${options.noun} format: ${labelStr}`,
344
+ details: `${options.pluralNoun} must be in key=value format`,
345
+ };
346
+ }
347
+ const key = labelStr.slice(0, eqIndex);
348
+ labels[key] = labelStr.slice(eqIndex + 1);
349
+ }
350
+ return labels;
351
+ }
352
+ async function connectToDaemonOrThrow(hostOption, host) {
353
+ try {
354
+ return await connectToDaemon({ host: hostOption });
355
+ }
356
+ catch (err) {
357
+ const message = err instanceof Error ? err.message : String(err);
358
+ throw {
359
+ code: "DAEMON_NOT_RUNNING",
360
+ message: `Cannot connect to daemon at ${host}: ${message}`,
361
+ details: "Start the daemon with: paseo daemon start",
362
+ };
363
+ }
364
+ }
365
+ export async function resolveExistingRunWorkspace(client, workspaceId) {
366
+ const result = await client.fetchWorkspaces({
367
+ filter: { query: workspaceId },
368
+ page: { limit: 200 },
369
+ });
370
+ const workspace = result.entries.find((entry) => entry.id === workspaceId);
371
+ if (workspace) {
372
+ return { id: workspace.id, cwd: workspace.workspaceDirectory };
373
+ }
374
+ throw {
375
+ code: "WORKSPACE_NOT_FOUND",
376
+ message: `Workspace not found: ${workspaceId}`,
377
+ };
378
+ }
379
+ // Workspace policy for `paseo run`. Precedence:
380
+ // 1. --workspace <id> -> run in that existing workspace
381
+ // 2. $PASEO_AGENT_ID -> daemon resolves the caller's workspace
382
+ // 3. $PASEO_WORKSPACE_ID -> exported by workspace terminals
383
+ // 4. --new-workspace <kind> -> mint a new workspace explicitly
384
+ // 5. bare run -> mint a new local-backed workspace for cwd
385
+ async function resolveRunWorkspace(client, options, cwd) {
386
+ const newWorkspace = resolveNewWorkspaceKind(options);
387
+ const explicit = newWorkspace ? undefined : options.workspace?.trim();
388
+ if (explicit) {
389
+ console.error(`Using workspace ${explicit}`);
390
+ return resolveExistingRunWorkspace(client, explicit);
391
+ }
392
+ if (!newWorkspace && resolveRunCallerAgentId()) {
393
+ return { cwd };
394
+ }
395
+ const ambientWorkspaceId = newWorkspace ? undefined : process.env.PASEO_WORKSPACE_ID?.trim();
396
+ if (ambientWorkspaceId) {
397
+ console.error(`Using workspace ${ambientWorkspaceId}`);
398
+ return resolveExistingRunWorkspace(client, ambientWorkspaceId);
399
+ }
400
+ // TODO: thread the run `prompt` as firstAgentContext so workspace-level
401
+ // title/branch generation picks up the task description (U8/U6 deferred).
402
+ const source = buildRunWorkspaceSource(options, cwd);
403
+ const result = await client.createWorkspace({ source });
404
+ if (!result.workspace) {
405
+ throw {
406
+ code: "WORKSPACE_CREATE_FAILED",
407
+ message: result.error ?? "Failed to create workspace for this run",
408
+ };
409
+ }
410
+ const branch = result.workspace.gitRuntime?.currentBranch;
411
+ const label = branch ? `${result.workspace.name} (${branch})` : result.workspace.name;
412
+ console.error(`Created workspace ${result.workspace.id} - ${label}`);
413
+ if (result.setupSkippedReason)
414
+ console.error(result.setupSkippedReason);
415
+ console.error("Tip: pass --workspace <id> (or set PASEO_WORKSPACE_ID) to run in an existing workspace.");
416
+ return { id: result.workspace.id, cwd: result.workspace.workspaceDirectory ?? cwd };
417
+ }
418
+ export async function runRunCommand(prompt, options, _command) {
419
+ const host = getDaemonHost({ host: options.host });
420
+ const outputSchema = options.outputSchema ? loadOutputSchema(options.outputSchema) : undefined;
421
+ validateRunOptions(prompt, options, outputSchema);
422
+ const waitTimeoutMs = parseWaitTimeoutOption(options.waitTimeout);
423
+ const resolvedProviderModel = resolveProviderAndModel(options);
424
+ const resolvedTitle = options.title ?? options.name;
425
+ const client = await connectToDaemonOrThrow(options.host, host);
426
+ try {
427
+ // Resolve working directory
428
+ const cwd = options.cwd ?? process.cwd();
429
+ const thinkingOptionId = options.thinking?.trim();
430
+ if (options.thinking !== undefined && !thinkingOptionId) {
431
+ const error = {
432
+ code: "INVALID_THINKING_OPTION",
433
+ message: "--thinking cannot be empty",
434
+ details: 'Provide a thinking option ID. Use "paseo provider models <provider> --thinking" to list valid IDs.',
435
+ };
436
+ throw error;
437
+ }
438
+ const images = loadRunImages(options.image);
439
+ const labels = parseRunLabels(options.label);
440
+ const env = parseRunEnv(options.env);
441
+ const requestEnv = Object.keys(env).length > 0 ? env : undefined;
442
+ const workspace = await resolveRunWorkspace(client, options, cwd);
443
+ const workspaceId = workspace.id;
444
+ const callerAgentId = resolveRunCallerAgentId();
445
+ const runCwd = workspace.cwd;
446
+ if (outputSchema) {
447
+ let structuredAgent = null;
448
+ const callStructuredTurn = async (structuredPrompt) => {
449
+ if (!structuredAgent) {
450
+ structuredAgent = await client.createAgent({
451
+ provider: resolvedProviderModel.provider,
452
+ cwd: runCwd,
453
+ workspaceId,
454
+ callerAgentId,
455
+ title: resolvedTitle,
456
+ modeId: options.mode,
457
+ model: resolvedProviderModel.model,
458
+ thinkingOptionId,
459
+ initialPrompt: structuredPrompt,
460
+ outputSchema,
461
+ images,
462
+ env: requestEnv,
463
+ labels: Object.keys(labels).length > 0 ? labels : undefined,
464
+ });
465
+ }
466
+ else {
467
+ await client.sendMessage(structuredAgent.id, structuredPrompt);
468
+ }
469
+ const state = await client.waitForFinish(structuredAgent.id, waitTimeoutMs);
470
+ if (state.status === "timeout") {
471
+ throw new StructuredRunStatusError("timeout", "Timed out waiting for structured output");
472
+ }
473
+ if (state.status === "permission") {
474
+ throw new StructuredRunStatusError("permission", "Agent is waiting for permission before producing structured output");
475
+ }
476
+ if (state.status === "error") {
477
+ throw new StructuredRunStatusError("error", state.error ?? "Agent failed before producing structured output");
478
+ }
479
+ const lastMessage = await resolveStructuredResponseMessage({
480
+ client,
481
+ agentId: structuredAgent.id,
482
+ lastMessage: state.lastMessage,
483
+ });
484
+ if (!lastMessage) {
485
+ throw new StructuredRunStatusError("empty", "Agent finished without a structured output message");
486
+ }
487
+ return lastMessage;
488
+ };
489
+ const output = await fetchStructuredOutput(callStructuredTurn, prompt, outputSchema);
490
+ if (!structuredAgent) {
491
+ const error = {
492
+ code: "OUTPUT_SCHEMA_FAILED",
493
+ message: "Agent finished without a structured output message",
494
+ };
495
+ throw error;
496
+ }
497
+ await client.close();
498
+ return {
499
+ type: "single",
500
+ data: toRunResult(structuredAgent, "completed"),
501
+ schema: structuredRunSchema(output),
502
+ };
503
+ }
504
+ // Create the agent
505
+ const agent = await client.createAgent({
506
+ provider: resolvedProviderModel.provider,
507
+ cwd: runCwd,
508
+ workspaceId,
509
+ callerAgentId,
510
+ title: resolvedTitle,
511
+ modeId: options.mode,
512
+ model: resolvedProviderModel.model,
513
+ thinkingOptionId,
514
+ initialPrompt: prompt,
515
+ images,
516
+ env: requestEnv,
517
+ labels: Object.keys(labels).length > 0 ? labels : undefined,
518
+ });
519
+ // Default run behavior is foreground: wait for completion unless background execution is set.
520
+ if (!runsInBackground(options)) {
521
+ const state = await client.waitForFinish(agent.id, waitTimeoutMs);
522
+ await client.close();
523
+ const finalAgent = state.final ?? agent;
524
+ const status = state.status === "idle" ? "completed" : state.status;
525
+ return {
526
+ type: "single",
527
+ data: toRunResult(finalAgent, status),
528
+ schema: agentRunSchema,
529
+ };
530
+ }
531
+ await client.close();
532
+ return {
533
+ type: "single",
534
+ data: toRunResult(agent),
535
+ schema: agentRunSchema,
536
+ };
537
+ }
538
+ catch (err) {
539
+ await client.close().catch(() => { });
540
+ if (err && typeof err === "object" && "code" in err) {
541
+ throw err;
542
+ }
543
+ const message = err instanceof Error ? err.message : String(err);
544
+ const error = {
545
+ code: "AGENT_CREATE_FAILED",
546
+ message: `Failed to create agent: ${message}`,
547
+ };
548
+ throw error;
549
+ }
550
+ }
551
+ export function resolveRunCallerAgentId(env = process.env) {
552
+ return env.PASEO_AGENT_ID?.trim() || undefined;
553
+ }
554
+ //# sourceMappingURL=run.js.map
@@ -0,0 +1,19 @@
1
+ import { type Command } from "commander";
2
+ import type { CommandOptions, SingleResult, OutputSchema } from "../../output/index.js";
3
+ /** Result type for agent send command */
4
+ export interface AgentSendResult {
5
+ agentId: string;
6
+ status: "sent" | "completed" | "timeout" | "permission" | "error";
7
+ message: string;
8
+ }
9
+ /** Schema for agent send output */
10
+ export declare const agentSendSchema: OutputSchema<AgentSendResult>;
11
+ export interface AgentSendOptions extends CommandOptions {
12
+ wait?: boolean;
13
+ image?: string[];
14
+ prompt?: string;
15
+ promptFile?: string;
16
+ }
17
+ export declare function addSendOptions(cmd: Command): Command;
18
+ export declare function runSendCommand(agentIdArg: string, prompt: string | undefined, options: AgentSendOptions, _command: Command): Promise<SingleResult<AgentSendResult>>;
19
+ //# sourceMappingURL=send.d.ts.map