@getmateo/cli 0.0.0-stage → 0.19.8

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 (304) hide show
  1. package/LICENSE +211 -0
  2. package/bin/mateo +3 -0
  3. package/dist/classify.d.ts +19 -0
  4. package/dist/classify.js +49 -0
  5. package/dist/cli.d.ts +3 -0
  6. package/dist/cli.js +143 -0
  7. package/dist/commands/agent/archive.d.ts +27 -0
  8. package/dist/commands/agent/archive.js +88 -0
  9. package/dist/commands/agent/attach.d.ts +8 -0
  10. package/dist/commands/agent/attach.js +160 -0
  11. package/dist/commands/agent/delete.d.ts +15 -0
  12. package/dist/commands/agent/delete.js +104 -0
  13. package/dist/commands/agent/detach.d.ts +16 -0
  14. package/dist/commands/agent/detach.js +44 -0
  15. package/dist/commands/agent/import.d.ts +14 -0
  16. package/dist/commands/agent/import.js +108 -0
  17. package/dist/commands/agent/index.d.ts +3 -0
  18. package/dist/commands/agent/index.js +56 -0
  19. package/dist/commands/agent/inspect.d.ts +15 -0
  20. package/dist/commands/agent/inspect.js +196 -0
  21. package/dist/commands/agent/logs.d.ts +39 -0
  22. package/dist/commands/agent/logs.js +369 -0
  23. package/dist/commands/agent/ls.d.ts +61 -0
  24. package/dist/commands/agent/ls.js +201 -0
  25. package/dist/commands/agent/mode.d.ts +18 -0
  26. package/dist/commands/agent/mode.js +100 -0
  27. package/dist/commands/agent/open.d.ts +11 -0
  28. package/dist/commands/agent/open.js +74 -0
  29. package/dist/commands/agent/reload.d.ts +25 -0
  30. package/dist/commands/agent/reload.js +64 -0
  31. package/dist/commands/agent/run.d.ts +77 -0
  32. package/dist/commands/agent/run.js +556 -0
  33. package/dist/commands/agent/send.d.ts +21 -0
  34. package/dist/commands/agent/send.js +187 -0
  35. package/dist/commands/agent/stop.d.ts +17 -0
  36. package/dist/commands/agent/stop.js +102 -0
  37. package/dist/commands/agent/update.d.ts +51 -0
  38. package/dist/commands/agent/update.js +173 -0
  39. package/dist/commands/agent/wait.d.ts +31 -0
  40. package/dist/commands/agent/wait.js +161 -0
  41. package/dist/commands/clone.d.ts +17 -0
  42. package/dist/commands/clone.js +59 -0
  43. package/dist/commands/daemon/config.d.ts +3 -0
  44. package/dist/commands/daemon/config.js +103 -0
  45. package/dist/commands/daemon/index.d.ts +3 -0
  46. package/dist/commands/daemon/index.js +28 -0
  47. package/dist/commands/daemon/local-daemon.d.ts +13 -0
  48. package/dist/commands/daemon/local-daemon.js +105 -0
  49. package/dist/commands/daemon/pair.d.ts +30 -0
  50. package/dist/commands/daemon/pair.js +145 -0
  51. package/dist/commands/daemon/reload.d.ts +12 -0
  52. package/dist/commands/daemon/reload.js +44 -0
  53. package/dist/commands/daemon/restart.d.ts +29 -0
  54. package/dist/commands/daemon/restart.js +169 -0
  55. package/dist/commands/daemon/runtime-toolchain.d.ts +6 -0
  56. package/dist/commands/daemon/runtime-toolchain.js +87 -0
  57. package/dist/commands/daemon/set-password.d.ts +17 -0
  58. package/dist/commands/daemon/set-password.js +89 -0
  59. package/dist/commands/daemon/start.d.ts +20 -0
  60. package/dist/commands/daemon/start.js +52 -0
  61. package/dist/commands/daemon/status.d.ts +13 -0
  62. package/dist/commands/daemon/status.js +119 -0
  63. package/dist/commands/daemon/stop.d.ts +20 -0
  64. package/dist/commands/daemon/stop.js +58 -0
  65. package/dist/commands/fleet/index.d.ts +4 -0
  66. package/dist/commands/fleet/index.js +57 -0
  67. package/dist/commands/heartbeat/index.d.ts +3 -0
  68. package/dist/commands/heartbeat/index.js +139 -0
  69. package/dist/commands/hooks.d.ts +19 -0
  70. package/dist/commands/hooks.js +89 -0
  71. package/dist/commands/hub/authority.d.ts +17 -0
  72. package/dist/commands/hub/authority.js +18 -0
  73. package/dist/commands/hub/connect.d.ts +24 -0
  74. package/dist/commands/hub/connect.js +44 -0
  75. package/dist/commands/hub/credentials.d.ts +21 -0
  76. package/dist/commands/hub/credentials.js +143 -0
  77. package/dist/commands/hub/daemon-client.d.ts +41 -0
  78. package/dist/commands/hub/daemon-client.js +14 -0
  79. package/dist/commands/hub/deploy-bundle.d.ts +16 -0
  80. package/dist/commands/hub/deploy-bundle.js +248 -0
  81. package/dist/commands/hub/deploy-triggers.d.ts +6 -0
  82. package/dist/commands/hub/deploy-triggers.js +116 -0
  83. package/dist/commands/hub/deploy.d.ts +50 -0
  84. package/dist/commands/hub/deploy.js +159 -0
  85. package/dist/commands/hub/disconnect.d.ts +17 -0
  86. package/dist/commands/hub/disconnect.js +24 -0
  87. package/dist/commands/hub/error.d.ts +6 -0
  88. package/dist/commands/hub/error.js +9 -0
  89. package/dist/commands/hub/export.d.ts +28 -0
  90. package/dist/commands/hub/export.js +80 -0
  91. package/dist/commands/hub/help.d.ts +3 -0
  92. package/dist/commands/hub/help.js +5 -0
  93. package/dist/commands/hub/hub-client/index.d.ts +22 -0
  94. package/dist/commands/hub/hub-client/index.js +135 -0
  95. package/dist/commands/hub/hub-client/internal/contracts.d.ts +126 -0
  96. package/dist/commands/hub/hub-client/internal/contracts.js +85 -0
  97. package/dist/commands/hub/hub-client/internal/problem.d.ts +3 -0
  98. package/dist/commands/hub/hub-client/internal/problem.js +85 -0
  99. package/dist/commands/hub/hub-client/internal/transport.d.ts +15 -0
  100. package/dist/commands/hub/hub-client/internal/transport.js +30 -0
  101. package/dist/commands/hub/index.d.ts +20 -0
  102. package/dist/commands/hub/index.js +94 -0
  103. package/dist/commands/hub/init-plan.d.ts +33 -0
  104. package/dist/commands/hub/init-plan.js +94 -0
  105. package/dist/commands/hub/init.d.ts +37 -0
  106. package/dist/commands/hub/init.js +525 -0
  107. package/dist/commands/hub/login-flow.d.ts +34 -0
  108. package/dist/commands/hub/login-flow.js +78 -0
  109. package/dist/commands/hub/login.d.ts +23 -0
  110. package/dist/commands/hub/login.js +40 -0
  111. package/dist/commands/hub/logout.d.ts +33 -0
  112. package/dist/commands/hub/logout.js +71 -0
  113. package/dist/commands/hub/origin.d.ts +2 -0
  114. package/dist/commands/hub/origin.js +27 -0
  115. package/dist/commands/hub/permissions.d.ts +22 -0
  116. package/dist/commands/hub/permissions.js +61 -0
  117. package/dist/commands/hub/projects.d.ts +24 -0
  118. package/dist/commands/hub/projects.js +49 -0
  119. package/dist/commands/hub/reporter.d.ts +10 -0
  120. package/dist/commands/hub/reporter.js +11 -0
  121. package/dist/commands/hub/starter-agent-runtime.d.ts +37 -0
  122. package/dist/commands/hub/starter-agent-runtime.js +49 -0
  123. package/dist/commands/hub/starter-trigger.d.ts +10 -0
  124. package/dist/commands/hub/starter-trigger.js +30 -0
  125. package/dist/commands/hub/status-output.d.ts +13 -0
  126. package/dist/commands/hub/status-output.js +30 -0
  127. package/dist/commands/onboard.d.ts +14 -0
  128. package/dist/commands/onboard.js +169 -0
  129. package/dist/commands/open.d.ts +4 -0
  130. package/dist/commands/open.js +91 -0
  131. package/dist/commands/permit/allow.d.ts +38 -0
  132. package/dist/commands/permit/allow.js +138 -0
  133. package/dist/commands/permit/deny.d.ts +13 -0
  134. package/dist/commands/permit/deny.js +100 -0
  135. package/dist/commands/permit/index.d.ts +3 -0
  136. package/dist/commands/permit/index.js +27 -0
  137. package/dist/commands/permit/ls.d.ts +21 -0
  138. package/dist/commands/permit/ls.js +54 -0
  139. package/dist/commands/plugin/index.d.ts +23 -0
  140. package/dist/commands/plugin/index.js +174 -0
  141. package/dist/commands/plugin/scaffold.d.ts +6 -0
  142. package/dist/commands/plugin/scaffold.js +212 -0
  143. package/dist/commands/plugin/shared.d.ts +7 -0
  144. package/dist/commands/plugin/shared.js +34 -0
  145. package/dist/commands/plugin/update.d.ts +37 -0
  146. package/dist/commands/plugin/update.js +58 -0
  147. package/dist/commands/project/create.d.ts +10 -0
  148. package/dist/commands/project/create.js +43 -0
  149. package/dist/commands/project/delete.d.ts +9 -0
  150. package/dist/commands/project/delete.js +35 -0
  151. package/dist/commands/project/index.d.ts +3 -0
  152. package/dist/commands/project/index.js +28 -0
  153. package/dist/commands/project/ls.d.ts +5 -0
  154. package/dist/commands/project/ls.js +19 -0
  155. package/dist/commands/project/rename.d.ts +15 -0
  156. package/dist/commands/project/rename.js +52 -0
  157. package/dist/commands/project/shared.d.ts +11 -0
  158. package/dist/commands/project/shared.js +18 -0
  159. package/dist/commands/provider/diagnostic.d.ts +12 -0
  160. package/dist/commands/provider/diagnostic.js +31 -0
  161. package/dist/commands/provider/index.d.ts +3 -0
  162. package/dist/commands/provider/index.js +21 -0
  163. package/dist/commands/provider/ls.d.ts +19 -0
  164. package/dist/commands/provider/ls.js +46 -0
  165. package/dist/commands/provider/models.d.ts +20 -0
  166. package/dist/commands/provider/models.js +53 -0
  167. package/dist/commands/schedule/create.d.ts +19 -0
  168. package/dist/commands/schedule/create.js +41 -0
  169. package/dist/commands/schedule/delete.d.ts +10 -0
  170. package/dist/commands/schedule/delete.js +32 -0
  171. package/dist/commands/schedule/index.d.ts +3 -0
  172. package/dist/commands/schedule/index.js +66 -0
  173. package/dist/commands/schedule/inspect.d.ts +6 -0
  174. package/dist/commands/schedule/inspect.js +27 -0
  175. package/dist/commands/schedule/logs.d.ts +6 -0
  176. package/dist/commands/schedule/logs.js +24 -0
  177. package/dist/commands/schedule/ls.d.ts +5 -0
  178. package/dist/commands/schedule/ls.js +25 -0
  179. package/dist/commands/schedule/pause.d.ts +5 -0
  180. package/dist/commands/schedule/pause.js +24 -0
  181. package/dist/commands/schedule/resume.d.ts +5 -0
  182. package/dist/commands/schedule/resume.js +24 -0
  183. package/dist/commands/schedule/run-once.d.ts +5 -0
  184. package/dist/commands/schedule/run-once.js +24 -0
  185. package/dist/commands/schedule/schema.d.ts +21 -0
  186. package/dist/commands/schedule/schema.js +67 -0
  187. package/dist/commands/schedule/shared.d.ts +61 -0
  188. package/dist/commands/schedule/shared.js +360 -0
  189. package/dist/commands/schedule/types.d.ts +165 -0
  190. package/dist/commands/schedule/types.js +2 -0
  191. package/dist/commands/schedule/update.d.ts +19 -0
  192. package/dist/commands/schedule/update.js +40 -0
  193. package/dist/commands/script/index.d.ts +3 -0
  194. package/dist/commands/script/index.js +19 -0
  195. package/dist/commands/script/ls.d.ts +6 -0
  196. package/dist/commands/script/ls.js +20 -0
  197. package/dist/commands/script/schema.d.ts +5 -0
  198. package/dist/commands/script/schema.js +13 -0
  199. package/dist/commands/script/shared.d.ts +12 -0
  200. package/dist/commands/script/shared.js +59 -0
  201. package/dist/commands/script/start.d.ts +6 -0
  202. package/dist/commands/script/start.js +23 -0
  203. package/dist/commands/script/stop.d.ts +6 -0
  204. package/dist/commands/script/stop.js +23 -0
  205. package/dist/commands/terminal/capture.d.ts +10 -0
  206. package/dist/commands/terminal/capture.js +67 -0
  207. package/dist/commands/terminal/create.d.ts +11 -0
  208. package/dist/commands/terminal/create.js +29 -0
  209. package/dist/commands/terminal/index.d.ts +3 -0
  210. package/dist/commands/terminal/index.js +51 -0
  211. package/dist/commands/terminal/kill.d.ts +6 -0
  212. package/dist/commands/terminal/kill.js +36 -0
  213. package/dist/commands/terminal/ls.d.ts +11 -0
  214. package/dist/commands/terminal/ls.js +21 -0
  215. package/dist/commands/terminal/schema.d.ts +10 -0
  216. package/dist/commands/terminal/schema.js +17 -0
  217. package/dist/commands/terminal/send-keys.d.ts +7 -0
  218. package/dist/commands/terminal/send-keys.js +44 -0
  219. package/dist/commands/terminal/shared.d.ts +13 -0
  220. package/dist/commands/terminal/shared.js +64 -0
  221. package/dist/commands/terminal/upgrade-hosts.d.ts +11 -0
  222. package/dist/commands/terminal/upgrade-hosts.js +46 -0
  223. package/dist/commands/usage/index.d.ts +29 -0
  224. package/dist/commands/usage/index.js +62 -0
  225. package/dist/commands/usage/presentation.d.ts +4 -0
  226. package/dist/commands/usage/presentation.js +146 -0
  227. package/dist/commands/workspace/archive.d.ts +13 -0
  228. package/dist/commands/workspace/archive.js +43 -0
  229. package/dist/commands/workspace/create.d.ts +50 -0
  230. package/dist/commands/workspace/create.js +132 -0
  231. package/dist/commands/workspace/index.d.ts +3 -0
  232. package/dist/commands/workspace/index.js +50 -0
  233. package/dist/commands/workspace/ls.d.ts +11 -0
  234. package/dist/commands/workspace/ls.js +33 -0
  235. package/dist/commands/workspace/rename.d.ts +23 -0
  236. package/dist/commands/workspace/rename.js +63 -0
  237. package/dist/commands/workspace/setup.d.ts +12 -0
  238. package/dist/commands/workspace/setup.js +41 -0
  239. package/dist/commands/workspace/shared.d.ts +15 -0
  240. package/dist/commands/workspace/shared.js +29 -0
  241. package/dist/commands/worktree/archive.d.ts +21 -0
  242. package/dist/commands/worktree/archive.js +108 -0
  243. package/dist/commands/worktree/create-input.d.ts +15 -0
  244. package/dist/commands/worktree/create-input.js +56 -0
  245. package/dist/commands/worktree/create.d.ts +11 -0
  246. package/dist/commands/worktree/create.js +50 -0
  247. package/dist/commands/worktree/index.d.ts +3 -0
  248. package/dist/commands/worktree/index.js +29 -0
  249. package/dist/commands/worktree/ls.d.ts +18 -0
  250. package/dist/commands/worktree/ls.js +73 -0
  251. package/dist/commands/worktree/repository-directory.d.ts +6 -0
  252. package/dist/commands/worktree/repository-directory.js +9 -0
  253. package/dist/index.d.ts +2 -0
  254. package/dist/index.js +6 -0
  255. package/dist/output/index.d.ts +45 -0
  256. package/dist/output/index.js +47 -0
  257. package/dist/output/json.d.ts +11 -0
  258. package/dist/output/json.js +37 -0
  259. package/dist/output/pairing.d.ts +9 -0
  260. package/dist/output/pairing.js +36 -0
  261. package/dist/output/quiet.d.ts +9 -0
  262. package/dist/output/quiet.js +22 -0
  263. package/dist/output/render.d.ts +15 -0
  264. package/dist/output/render.js +84 -0
  265. package/dist/output/table.d.ts +13 -0
  266. package/dist/output/table.js +135 -0
  267. package/dist/output/types.d.ts +73 -0
  268. package/dist/output/types.js +8 -0
  269. package/dist/output/with-output.d.ts +43 -0
  270. package/dist/output/with-output.js +85 -0
  271. package/dist/output/yaml.d.ts +11 -0
  272. package/dist/output/yaml.js +38 -0
  273. package/dist/run.d.ts +14 -0
  274. package/dist/run.js +62 -0
  275. package/dist/ssh/ssh-tunnel.d.ts +2 -0
  276. package/dist/ssh/ssh-tunnel.js +3 -0
  277. package/dist/utils/agent-directory.d.ts +31 -0
  278. package/dist/utils/agent-directory.js +48 -0
  279. package/dist/utils/caller-agent.d.ts +14 -0
  280. package/dist/utils/caller-agent.js +16 -0
  281. package/dist/utils/client-id.d.ts +2 -0
  282. package/dist/utils/client-id.js +31 -0
  283. package/dist/utils/client.d.ts +57 -0
  284. package/dist/utils/client.js +360 -0
  285. package/dist/utils/command-options.d.ts +8 -0
  286. package/dist/utils/command-options.js +49 -0
  287. package/dist/utils/daemon-target.d.ts +13 -0
  288. package/dist/utils/daemon-target.js +51 -0
  289. package/dist/utils/duration.d.ts +7 -0
  290. package/dist/utils/duration.js +39 -0
  291. package/dist/utils/errors.d.ts +5 -0
  292. package/dist/utils/errors.js +10 -0
  293. package/dist/utils/paths.d.ts +12 -0
  294. package/dist/utils/paths.js +22 -0
  295. package/dist/utils/provider-model.d.ts +11 -0
  296. package/dist/utils/provider-model.js +49 -0
  297. package/dist/utils/timeline.d.ts +12 -0
  298. package/dist/utils/timeline.js +16 -0
  299. package/dist/utils/wait-for-stop.d.ts +2 -0
  300. package/dist/utils/wait-for-stop.js +28 -0
  301. package/dist/version.d.ts +5 -0
  302. package/dist/version.js +24 -0
  303. package/package.json +63 -4
  304. package/README.md +0 -3
@@ -0,0 +1,187 @@
1
+ import { Option } from "commander";
2
+ import { collectMultiple } from "../../utils/command-options.js";
3
+ import { connectToDaemon } from "../../utils/client.js";
4
+ import { readFile } from "node:fs/promises";
5
+ import { extname, resolve } from "node:path";
6
+ /** Schema for agent send output */
7
+ export const agentSendSchema = {
8
+ idField: "agentId",
9
+ columns: [
10
+ { header: "AGENT ID", field: "agentId", width: 12 },
11
+ { header: "STATUS", field: "status", width: 12 },
12
+ { header: "MESSAGE", field: "message", width: 40 },
13
+ ],
14
+ };
15
+ export function addSendOptions(cmd) {
16
+ return cmd
17
+ .description("Send a message/task to an existing agent")
18
+ .argument("<id>", "Agent ID (or prefix)")
19
+ .argument("[prompt]", "The message to send")
20
+ .option("--prompt <text>", "Provide the message inline as a flag")
21
+ .option("--prompt-file <path>", "Read the message from a UTF-8 text file")
22
+ .option("--image <path>", "Attach image(s) to the message", collectMultiple, [])
23
+ .addOption(new Option("--behavior <behavior>", "Active-turn behavior (agent default: steer waits for turn end; otherwise: interrupt)").choices(["interrupt", "steer"]))
24
+ .option("--no-wait", "Return immediately without waiting for completion");
25
+ }
26
+ /**
27
+ * Read image files and convert them to base64 data URIs
28
+ */
29
+ async function readImageFiles(imagePaths) {
30
+ return Promise.all(imagePaths.map(async (path) => {
31
+ try {
32
+ const buffer = await readFile(path);
33
+ const ext = extname(path).toLowerCase();
34
+ let mimeType = "image/jpeg";
35
+ switch (ext) {
36
+ case ".png":
37
+ mimeType = "image/png";
38
+ break;
39
+ case ".jpg":
40
+ case ".jpeg":
41
+ mimeType = "image/jpeg";
42
+ break;
43
+ case ".gif":
44
+ mimeType = "image/gif";
45
+ break;
46
+ case ".webp":
47
+ mimeType = "image/webp";
48
+ break;
49
+ default:
50
+ mimeType = "image/jpeg";
51
+ }
52
+ return { data: buffer.toString("base64"), mimeType };
53
+ }
54
+ catch (err) {
55
+ if (err && typeof err === "object" && "code" in err)
56
+ throw err;
57
+ const message = err instanceof Error ? err.message : String(err);
58
+ throw {
59
+ code: "IMAGE_READ_ERROR",
60
+ message: `Failed to read image file: ${path}`,
61
+ details: message,
62
+ };
63
+ }
64
+ }));
65
+ }
66
+ async function resolvePromptInput(options) {
67
+ const promptText = options.promptArgument?.trim();
68
+ const promptOptionText = options.promptOption?.trim();
69
+ const promptFilePath = options.promptFile?.trim();
70
+ const providedSourceCount = [promptText, promptOptionText, promptFilePath].filter(Boolean).length;
71
+ if (providedSourceCount > 1) {
72
+ const error = {
73
+ code: "CONFLICTING_PROMPT_INPUT",
74
+ message: "Provide exactly one of prompt argument, --prompt, or --prompt-file",
75
+ };
76
+ throw error;
77
+ }
78
+ if (promptText) {
79
+ return options.promptArgument;
80
+ }
81
+ if (promptOptionText) {
82
+ return options.promptOption;
83
+ }
84
+ if (!promptFilePath) {
85
+ const error = {
86
+ code: "MISSING_PROMPT",
87
+ message: "A prompt is required",
88
+ details: "Usage: mateo agent send [options] <id> [prompt] | --prompt <text> | --prompt-file <path>",
89
+ };
90
+ throw error;
91
+ }
92
+ try {
93
+ return await readFile(resolve(promptFilePath), "utf8");
94
+ }
95
+ catch (err) {
96
+ if (err && typeof err === "object" && "code" in err)
97
+ throw err;
98
+ const message = err instanceof Error ? err.message : String(err);
99
+ const error = {
100
+ code: "PROMPT_FILE_READ_ERROR",
101
+ message: `Failed to read prompt file: ${promptFilePath}`,
102
+ details: message,
103
+ };
104
+ throw error;
105
+ }
106
+ }
107
+ function buildSendResult(agentIdArg, state) {
108
+ const agentId = state.final?.id ?? agentIdArg;
109
+ if (state.status === "timeout") {
110
+ return { agentId, status: "timeout", message: "Timed out waiting for agent to finish" };
111
+ }
112
+ if (state.status === "permission") {
113
+ return { agentId, status: "permission", message: "Agent is waiting for permission" };
114
+ }
115
+ if (state.status === "error") {
116
+ return {
117
+ agentId,
118
+ status: "error",
119
+ message: state.error ?? "Agent finished with error",
120
+ };
121
+ }
122
+ return { agentId, status: "completed", message: "Agent completed processing the message" };
123
+ }
124
+ export async function runSendCommand(agentIdArg, prompt, options, _command) {
125
+ // Validate arguments
126
+ if (!agentIdArg || agentIdArg.trim().length === 0) {
127
+ const error = {
128
+ code: "MISSING_AGENT_ID",
129
+ message: "Agent ID is required",
130
+ details: "Usage: mateo agent send [options] <id> [prompt]",
131
+ };
132
+ throw error;
133
+ }
134
+ const promptInput = await resolvePromptInput({
135
+ promptArgument: prompt,
136
+ promptOption: options.prompt,
137
+ promptFile: options.promptFile,
138
+ });
139
+ const client = await connectToDaemon({ target: options.daemonTarget });
140
+ try {
141
+ // Read image files if provided
142
+ const images = options.image && options.image.length > 0 ? await readImageFiles(options.image) : undefined;
143
+ const sourceAgentId = process.env.MATEO_AGENT_ID?.trim() || undefined;
144
+ // Send the message
145
+ const receipt = await client.sendAgentMessage(agentIdArg, promptInput, {
146
+ images,
147
+ sourceAgentId,
148
+ activeTurnBehavior: options.behavior ?? (sourceAgentId ? "steer" : "interrupt"),
149
+ });
150
+ // If --no-wait, return immediately
151
+ if (options.wait === false) {
152
+ await client.close();
153
+ return {
154
+ type: "single",
155
+ data: {
156
+ agentId: agentIdArg,
157
+ status: receipt.deliveryStatus ?? "sent",
158
+ message: receipt.deliveryStatus === "queued"
159
+ ? "Message queued for delivery after two quiet seconds and the current turn ends, unless interrupt was requested"
160
+ : "Message sent, not waiting for completion",
161
+ },
162
+ schema: agentSendSchema,
163
+ };
164
+ }
165
+ const state = await client.waitForFinish(agentIdArg, 600000); // 10 minute timeout
166
+ await client.close();
167
+ return {
168
+ type: "single",
169
+ data: buildSendResult(agentIdArg, state),
170
+ schema: agentSendSchema,
171
+ };
172
+ }
173
+ catch (err) {
174
+ await client.close().catch(() => { });
175
+ // Re-throw CommandError as-is
176
+ if (err && typeof err === "object" && "code" in err) {
177
+ throw err;
178
+ }
179
+ const message = err instanceof Error ? err.message : String(err);
180
+ const error = {
181
+ code: "SEND_FAILED",
182
+ message: `Failed to send message: ${message}`,
183
+ };
184
+ throw error;
185
+ }
186
+ }
187
+ //# sourceMappingURL=send.js.map
@@ -0,0 +1,17 @@
1
+ import { Command } from "commander";
2
+ import type { CommandOptions, SingleResult, OutputSchema } from "../../output/index.js";
3
+ /** Result type for agent stop command */
4
+ export interface StopResult {
5
+ stoppedCount: number;
6
+ agentIds: string[];
7
+ }
8
+ /** Schema for stop command output */
9
+ export declare const stopSchema: OutputSchema<StopResult>;
10
+ export declare function addStopOptions(cmd: Command): Command;
11
+ export interface AgentStopOptions extends CommandOptions {
12
+ all?: boolean;
13
+ cwd?: string;
14
+ }
15
+ export type AgentStopResult = SingleResult<StopResult>;
16
+ export declare function runStopCommand(id: string | undefined, options: AgentStopOptions, _command: Command): Promise<AgentStopResult>;
17
+ //# sourceMappingURL=stop.d.ts.map
@@ -0,0 +1,102 @@
1
+ import { connectToDaemon } from "../../utils/client.js";
2
+ import { isSameOrDescendantPath } from "../../utils/paths.js";
3
+ /** Schema for stop command output */
4
+ export const stopSchema = {
5
+ // For quiet mode, output the stopped agent IDs (one per line)
6
+ idField: (item) => item.agentIds.join("\n"),
7
+ columns: [{ header: "INTERRUPTED", field: "stoppedCount" }],
8
+ };
9
+ export function addStopOptions(cmd) {
10
+ return cmd
11
+ .description("Interrupt an agent if it is running (no-op for idle agents)")
12
+ .argument("[id]", "Agent ID (or prefix) - optional if --all or --cwd specified")
13
+ .option("--all", "Stop all agents")
14
+ .option("--cwd <path>", "Stop all agents in directory");
15
+ }
16
+ export async function runStopCommand(id, options, _command) {
17
+ // Validate arguments - need either an id, --all, or --cwd
18
+ if (!id && !options.all && !options.cwd) {
19
+ const error = {
20
+ code: "MISSING_ARGUMENT",
21
+ message: "Agent ID required unless --all or --cwd is specified",
22
+ details: "Usage: mateo agent stop <id> | --all | --cwd <path>",
23
+ };
24
+ throw error;
25
+ }
26
+ const client = await connectToDaemon({ target: options.daemonTarget });
27
+ try {
28
+ const fetchPayload = await client.fetchAgents({ filter: { includeArchived: true } });
29
+ let agents = fetchPayload.entries.map((entry) => entry.agent);
30
+ const stoppedIds = [];
31
+ if (options.all) {
32
+ // Stop all agents (not archived)
33
+ agents = agents.filter((a) => !a.archivedAt);
34
+ }
35
+ else if (options.cwd) {
36
+ // Stop agents in directory
37
+ agents = agents.filter((a) => {
38
+ if (a.archivedAt)
39
+ return false;
40
+ return isSameOrDescendantPath(options.cwd, a.cwd);
41
+ });
42
+ }
43
+ else if (id) {
44
+ // Stop specific agent
45
+ const fetchResult = await client.fetchAgent({ agentId: id });
46
+ if (!fetchResult) {
47
+ const error = {
48
+ code: "AGENT_NOT_FOUND",
49
+ message: `No agent found matching: ${id}`,
50
+ details: "Use `mateo ls` to list available agents",
51
+ };
52
+ throw error;
53
+ }
54
+ agents = [fetchResult.agent];
55
+ }
56
+ // Interrupt each running agent. Idle agents are a no-op.
57
+ const stopResults = await Promise.all(agents.map(async (agent) => {
58
+ if (agent.status !== "running")
59
+ return { ok: true, id: agent.id, stopped: false };
60
+ try {
61
+ await client.cancelAgent(agent.id);
62
+ return { ok: true, id: agent.id, stopped: true };
63
+ }
64
+ catch (err) {
65
+ const message = err instanceof Error ? err.message : String(err);
66
+ return { ok: false, id: agent.id, message };
67
+ }
68
+ }));
69
+ for (const result of stopResults) {
70
+ if (!result.ok) {
71
+ console.error(`Warning: Failed to stop agent ${result.id.slice(0, 7)}: ${result.message}`);
72
+ continue;
73
+ }
74
+ if (result.stopped) {
75
+ stoppedIds.push(result.id);
76
+ }
77
+ }
78
+ await client.close();
79
+ return {
80
+ type: "single",
81
+ data: {
82
+ stoppedCount: stoppedIds.length,
83
+ agentIds: stoppedIds,
84
+ },
85
+ schema: stopSchema,
86
+ };
87
+ }
88
+ catch (err) {
89
+ await client.close().catch(() => { });
90
+ // Re-throw if it's already a CommandError
91
+ if (err && typeof err === "object" && "code" in err) {
92
+ throw err;
93
+ }
94
+ const message = err instanceof Error ? err.message : String(err);
95
+ const error = {
96
+ code: "STOP_AGENT_FAILED",
97
+ message: `Failed to stop agent(s): ${message}`,
98
+ };
99
+ throw error;
100
+ }
101
+ }
102
+ //# sourceMappingURL=stop.js.map
@@ -0,0 +1,51 @@
1
+ import type { Command } from "commander";
2
+ import type { AgentProviderNotice } from "@getmateo/protocol/agent-types";
3
+ import type { AgentSnapshotPayload } from "@getmateo/protocol/messages";
4
+ import type { CommandOptions, SingleResult, OutputSchema } from "../../output/index.js";
5
+ /** Result type for agent update command */
6
+ export interface AgentUpdateResult {
7
+ agentId: string;
8
+ name: string | null;
9
+ labels: string;
10
+ thinkingOptionId: string | null;
11
+ noticeType: AgentProviderNotice["type"] | null;
12
+ notice: string | null;
13
+ }
14
+ /** Schema for update command output */
15
+ export declare const updateSchema: OutputSchema<AgentUpdateResult>;
16
+ export interface AgentUpdateOptions extends CommandOptions {
17
+ name?: string;
18
+ label?: string[];
19
+ thinking?: string;
20
+ host?: string;
21
+ }
22
+ export type AgentUpdateCommandResult = SingleResult<AgentUpdateResult>;
23
+ export interface AgentMetadataChanges {
24
+ name?: string;
25
+ labels?: Record<string, string>;
26
+ }
27
+ interface AgentUpdateServerInfo {
28
+ features?: {
29
+ agentThinkingUpdate?: boolean;
30
+ };
31
+ }
32
+ export interface AgentUpdateClient {
33
+ getLastServerInfoMessage(): AgentUpdateServerInfo | null;
34
+ updateAgent(agentId: string, updates: AgentMetadataChanges): Promise<void>;
35
+ setAgentThinkingOption(agentId: string, thinkingOptionId: string): Promise<AgentProviderNotice | null>;
36
+ }
37
+ export type AgentChanges = {
38
+ type: "metadata";
39
+ updates: AgentMetadataChanges;
40
+ } | {
41
+ type: "thinking";
42
+ thinkingOptionId: string;
43
+ };
44
+ export interface AppliedAgentChanges {
45
+ notice: AgentProviderNotice | null;
46
+ }
47
+ export declare function toAgentUpdateResult(agent: Pick<AgentSnapshotPayload, "id" | "title" | "labels" | "effectiveThinkingOptionId">, appliedChanges: AppliedAgentChanges): AgentUpdateResult;
48
+ export declare function applyAgentChanges(client: AgentUpdateClient, agentId: string, changes: AgentChanges): Promise<AppliedAgentChanges>;
49
+ export declare function runUpdateCommand(agentIdArg: string, options: AgentUpdateOptions, _command: Command): Promise<AgentUpdateCommandResult>;
50
+ export {};
51
+ //# sourceMappingURL=update.d.ts.map
@@ -0,0 +1,173 @@
1
+ import { connectToDaemon } from "../../utils/client.js";
2
+ /** Schema for update command output */
3
+ export const updateSchema = {
4
+ idField: "agentId",
5
+ columns: [
6
+ { header: "AGENT ID", field: "agentId" },
7
+ { header: "NAME", field: "name" },
8
+ { header: "LABELS", field: "labels" },
9
+ { header: "THINKING", field: "thinkingOptionId" },
10
+ { header: "NOTICE", field: "notice" },
11
+ ],
12
+ };
13
+ export function toAgentUpdateResult(agent, appliedChanges) {
14
+ return {
15
+ agentId: agent.id,
16
+ name: agent.title,
17
+ labels: formatLabels(agent.labels),
18
+ thinkingOptionId: agent.effectiveThinkingOptionId ?? null,
19
+ noticeType: appliedChanges.notice?.type ?? null,
20
+ notice: appliedChanges.notice?.message ?? null,
21
+ };
22
+ }
23
+ export async function applyAgentChanges(client, agentId, changes) {
24
+ if (changes.type === "thinking") {
25
+ // COMPAT(agentThinkingUpdate): added in v0.2.4, remove gate after 2027-01-28.
26
+ if (client.getLastServerInfoMessage()?.features?.agentThinkingUpdate !== true) {
27
+ throw {
28
+ code: "DAEMON_UPDATE_REQUIRED",
29
+ message: "Update the host to use agent thinking updates.",
30
+ };
31
+ }
32
+ const notice = await client.setAgentThinkingOption(agentId, changes.thinkingOptionId);
33
+ return { notice };
34
+ }
35
+ await client.updateAgent(agentId, changes.updates);
36
+ return { notice: null };
37
+ }
38
+ function parseLabelOptions(labels) {
39
+ const parsed = {};
40
+ if (!labels) {
41
+ return parsed;
42
+ }
43
+ for (const rawLabel of labels) {
44
+ for (const segment of rawLabel.split(",")) {
45
+ const label = segment.trim();
46
+ if (!label) {
47
+ continue;
48
+ }
49
+ const eqIndex = label.indexOf("=");
50
+ if (eqIndex === -1) {
51
+ const error = {
52
+ code: "INVALID_LABEL",
53
+ message: `Invalid label format: ${label}`,
54
+ details: "Labels must be in key=value format",
55
+ };
56
+ throw error;
57
+ }
58
+ const key = label.slice(0, eqIndex).trim();
59
+ const value = label.slice(eqIndex + 1);
60
+ if (!key) {
61
+ const error = {
62
+ code: "INVALID_LABEL",
63
+ message: `Invalid label format: ${label}`,
64
+ details: "Labels must include a non-empty key in key=value format",
65
+ };
66
+ throw error;
67
+ }
68
+ parsed[key] = value;
69
+ }
70
+ }
71
+ return parsed;
72
+ }
73
+ function formatLabels(labels) {
74
+ const entries = Object.entries(labels);
75
+ if (entries.length === 0) {
76
+ return "-";
77
+ }
78
+ return entries.map(([key, value]) => `${key}=${value}`).join(",");
79
+ }
80
+ function parseAgentChanges(options) {
81
+ const name = options.name?.trim();
82
+ if (options.name !== undefined && !name) {
83
+ throw {
84
+ code: "INVALID_NAME",
85
+ message: "Name cannot be empty",
86
+ details: "Use --name <name> with a non-empty value",
87
+ };
88
+ }
89
+ const labels = parseLabelOptions(options.label);
90
+ const thinkingOptionId = options.thinking?.trim();
91
+ if (options.thinking !== undefined && !thinkingOptionId) {
92
+ throw {
93
+ code: "INVALID_THINKING_OPTION",
94
+ message: "--thinking cannot be empty",
95
+ details: 'Provide a thinking option ID. Use "mateo provider models <provider> --thinking" to list valid IDs.',
96
+ };
97
+ }
98
+ const hasMetadataUpdates = Boolean(name) || Object.keys(labels).length > 0;
99
+ if (hasMetadataUpdates && thinkingOptionId) {
100
+ throw {
101
+ code: "INVALID_OPTIONS",
102
+ message: "--thinking cannot be combined with --name or --label",
103
+ details: "Run separate agent update commands for runtime settings and metadata.",
104
+ };
105
+ }
106
+ if (!hasMetadataUpdates && !thinkingOptionId) {
107
+ throw {
108
+ code: "NO_CHANGES_PROVIDED",
109
+ message: "Nothing to update",
110
+ details: "Provide at least one of: --name <name>, --label <key=value>, --thinking <id>",
111
+ };
112
+ }
113
+ if (thinkingOptionId) {
114
+ return { type: "thinking", thinkingOptionId };
115
+ }
116
+ return {
117
+ type: "metadata",
118
+ updates: {
119
+ ...(name ? { name } : {}),
120
+ ...(Object.keys(labels).length > 0 ? { labels } : {}),
121
+ },
122
+ };
123
+ }
124
+ export async function runUpdateCommand(agentIdArg, options, _command) {
125
+ // Validate arguments
126
+ if (!agentIdArg || agentIdArg.trim().length === 0) {
127
+ const error = {
128
+ code: "MISSING_AGENT_ID",
129
+ message: "Agent ID is required",
130
+ details: "Usage: mateo agent update <id> [--name <name>] [--label <key=value>]",
131
+ };
132
+ throw error;
133
+ }
134
+ const changes = parseAgentChanges(options);
135
+ const client = await connectToDaemon({ target: options.daemonTarget });
136
+ try {
137
+ const fetchResult = await client.fetchAgent({ agentId: agentIdArg });
138
+ if (!fetchResult) {
139
+ const error = {
140
+ code: "AGENT_NOT_FOUND",
141
+ message: `Agent not found: ${agentIdArg}`,
142
+ details: 'Use "mateo ls" to list available agents',
143
+ };
144
+ throw error;
145
+ }
146
+ const agentId = fetchResult.agent.id;
147
+ const appliedChanges = await applyAgentChanges(client, agentId, changes);
148
+ const updatedResult = await client.fetchAgent({ agentId });
149
+ if (!updatedResult) {
150
+ throw new Error(`Agent not found after update: ${agentId}`);
151
+ }
152
+ await client.close();
153
+ return {
154
+ type: "single",
155
+ data: toAgentUpdateResult(updatedResult.agent, appliedChanges),
156
+ schema: updateSchema,
157
+ };
158
+ }
159
+ catch (err) {
160
+ await client.close().catch(() => { });
161
+ // Re-throw CommandError as-is
162
+ if (err && typeof err === "object" && "code" in err) {
163
+ throw err;
164
+ }
165
+ const message = err instanceof Error ? err.message : String(err);
166
+ const error = {
167
+ code: "UPDATE_FAILED",
168
+ message: `Failed to update agent: ${message}`,
169
+ };
170
+ throw error;
171
+ }
172
+ }
173
+ //# sourceMappingURL=update.js.map
@@ -0,0 +1,31 @@
1
+ import { Command } from "commander";
2
+ import { connectToDaemon } from "../../utils/client.js";
3
+ import type { CommandOptions, SingleResult, OutputSchema } from "../../output/index.js";
4
+ /** Result type for agent wait command */
5
+ export interface AgentWaitResult {
6
+ agentId: string;
7
+ status: "idle" | "timeout" | "permission" | "error";
8
+ message: string;
9
+ }
10
+ /** Schema for agent wait output */
11
+ export declare const agentWaitSchema: OutputSchema<AgentWaitResult>;
12
+ export interface AgentWaitOptions extends CommandOptions {
13
+ timeout?: string;
14
+ host?: string;
15
+ }
16
+ type WaitFinishState = Awaited<ReturnType<Awaited<ReturnType<typeof connectToDaemon>>["waitForFinish"]>>;
17
+ /**
18
+ * Turn the daemon's wait reply into the command result. Throws AGENT_NOT_FOUND when the
19
+ * daemon resolved no agent: it answers an unknown identifier with an error and no agent
20
+ * payload, while an agent that finished in error always comes with its payload.
21
+ */
22
+ export declare function buildWaitResult(args: {
23
+ state: WaitFinishState;
24
+ resolvedAgentId: string;
25
+ recentActivity: string | null;
26
+ timeoutLabel: string | null;
27
+ }): AgentWaitResult;
28
+ export declare function addWaitOptions(cmd: Command): Command;
29
+ export declare function runWaitCommand(agentIdArg: string, options: AgentWaitOptions, _command: Command): Promise<SingleResult<AgentWaitResult>>;
30
+ export {};
31
+ //# sourceMappingURL=wait.d.ts.map