@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,196 @@
1
+ import { PARENT_AGENT_ID_LABEL } from "@getmateo/protocol/agent-labels";
2
+ import { connectToDaemon } from "../../utils/client.js";
3
+ export function addInspectOptions(cmd) {
4
+ return cmd
5
+ .description("Show detailed information about an agent")
6
+ .argument("<id>", "Agent ID (or prefix)");
7
+ }
8
+ /** Schema for key-value display with custom serialization for JSON/YAML */
9
+ function createInspectSchema(agent) {
10
+ return {
11
+ idField: "key",
12
+ columns: [
13
+ { header: "KEY", field: "key" },
14
+ {
15
+ header: "VALUE",
16
+ field: "value",
17
+ color: (_, item) => {
18
+ if (item.key === "Status") {
19
+ if (item.value === "running")
20
+ return "green";
21
+ if (item.value === "idle")
22
+ return "yellow";
23
+ if (item.value === "error")
24
+ return "red";
25
+ }
26
+ return undefined;
27
+ },
28
+ },
29
+ ],
30
+ // For JSON/YAML, return the structured agent object
31
+ serialize: (_item) => agent,
32
+ };
33
+ }
34
+ /** Shorten home directory in path */
35
+ function shortenPath(path) {
36
+ const home = process.env.HOME;
37
+ if (home && path.startsWith(home)) {
38
+ return "~" + path.slice(home.length);
39
+ }
40
+ return path;
41
+ }
42
+ /** Format cost in USD */
43
+ function formatCost(costUsd) {
44
+ if (costUsd === 0)
45
+ return "$0.00";
46
+ if (costUsd < 0.01)
47
+ return `$${costUsd.toFixed(4)}`;
48
+ return `$${costUsd.toFixed(2)}`;
49
+ }
50
+ function normalizeModelId(value) {
51
+ if (typeof value !== "string")
52
+ return null;
53
+ const normalized = value.trim();
54
+ if (!normalized || normalized.toLowerCase() === "default")
55
+ return null;
56
+ return normalized;
57
+ }
58
+ function resolveModel(snapshot) {
59
+ return normalizeModelId(snapshot.runtimeInfo?.model) ?? normalizeModelId(snapshot.model);
60
+ }
61
+ function buildLastUsage(snapshot) {
62
+ if (!snapshot.lastUsage)
63
+ return null;
64
+ return {
65
+ InputTokens: snapshot.lastUsage.inputTokens ?? 0,
66
+ OutputTokens: snapshot.lastUsage.outputTokens ?? 0,
67
+ CachedTokens: snapshot.lastUsage.cachedInputTokens ?? 0,
68
+ CostUsd: snapshot.lastUsage.totalCostUsd ?? 0,
69
+ };
70
+ }
71
+ function buildCapabilities(snapshot) {
72
+ if (!snapshot.capabilities)
73
+ return null;
74
+ return {
75
+ Streaming: snapshot.capabilities.supportsStreaming ?? false,
76
+ Persistence: snapshot.capabilities.supportsSessionPersistence ?? false,
77
+ DynamicModes: snapshot.capabilities.supportsDynamicModes ?? false,
78
+ McpServers: snapshot.capabilities.supportsMcpServers ?? false,
79
+ };
80
+ }
81
+ /** Convert agent snapshot to inspection data */
82
+ function toInspectData(snapshot) {
83
+ return {
84
+ Id: snapshot.id,
85
+ Name: snapshot.title ?? "-",
86
+ Provider: snapshot.provider,
87
+ Model: resolveModel(snapshot) ?? "-",
88
+ Thinking: snapshot.effectiveThinkingOptionId ?? "auto",
89
+ Status: snapshot.status,
90
+ Archived: snapshot.archivedAt != null,
91
+ ArchivedAt: snapshot.archivedAt ?? null,
92
+ Mode: snapshot.currentModeId ?? "default",
93
+ Cwd: snapshot.cwd,
94
+ CreatedAt: snapshot.createdAt,
95
+ UpdatedAt: snapshot.updatedAt,
96
+ LastUsage: buildLastUsage(snapshot),
97
+ Capabilities: buildCapabilities(snapshot),
98
+ AvailableModes: snapshot.availableModes
99
+ ? snapshot.availableModes.map((m) => ({ id: m.id, label: m.label }))
100
+ : null,
101
+ PendingPermissions: (snapshot.pendingPermissions ?? []).map((p) => ({
102
+ id: p.id,
103
+ tool: p.name ?? "unknown",
104
+ })),
105
+ Worktree: snapshot.labels?.["mateo.worktree"] ?? null,
106
+ ParentAgentId: snapshot.labels?.[PARENT_AGENT_ID_LABEL] ?? null,
107
+ };
108
+ }
109
+ /** Convert agent to key-value rows for table display */
110
+ function toInspectRows(agent) {
111
+ const rows = [
112
+ { key: "Id", value: agent.Id },
113
+ { key: "Name", value: agent.Name },
114
+ { key: "Provider", value: agent.Provider },
115
+ { key: "Model", value: agent.Model },
116
+ { key: "Thinking", value: agent.Thinking },
117
+ { key: "Status", value: agent.Status },
118
+ { key: "Archived", value: String(agent.Archived) },
119
+ { key: "ArchivedAt", value: agent.ArchivedAt ?? "null" },
120
+ { key: "Mode", value: agent.Mode },
121
+ { key: "Cwd", value: shortenPath(agent.Cwd) },
122
+ { key: "CreatedAt", value: agent.CreatedAt },
123
+ { key: "UpdatedAt", value: agent.UpdatedAt },
124
+ ];
125
+ if (agent.LastUsage) {
126
+ rows.push({
127
+ key: "LastUsage",
128
+ value: `InputTokens: ${agent.LastUsage.InputTokens}, OutputTokens: ${agent.LastUsage.OutputTokens}, CachedTokens: ${agent.LastUsage.CachedTokens}, CostUsd: ${formatCost(agent.LastUsage.CostUsd)}`,
129
+ });
130
+ }
131
+ if (agent.Capabilities) {
132
+ rows.push({
133
+ key: "Capabilities",
134
+ value: `Streaming: ${agent.Capabilities.Streaming}, Persistence: ${agent.Capabilities.Persistence}, DynamicModes: ${agent.Capabilities.DynamicModes}, McpServers: ${agent.Capabilities.McpServers}`,
135
+ });
136
+ }
137
+ if (agent.AvailableModes && agent.AvailableModes.length > 0) {
138
+ rows.push({
139
+ key: "AvailableModes",
140
+ value: agent.AvailableModes.map((m) => `${m.id} (${m.label})`).join(", "),
141
+ });
142
+ }
143
+ rows.push({
144
+ key: "PendingPermissions",
145
+ value: agent.PendingPermissions.length > 0
146
+ ? agent.PendingPermissions.map((p) => `${p.id} (${p.tool})`).join(", ")
147
+ : "[]",
148
+ });
149
+ rows.push({ key: "Worktree", value: agent.Worktree ?? "null" });
150
+ rows.push({ key: "ParentAgentId", value: agent.ParentAgentId ?? "null" });
151
+ return rows;
152
+ }
153
+ export async function runInspectCommand(agentIdArg, options, _command) {
154
+ // Validate arguments
155
+ if (!agentIdArg || agentIdArg.trim().length === 0) {
156
+ const error = {
157
+ code: "MISSING_AGENT_ID",
158
+ message: "Agent ID is required",
159
+ details: "Usage: mateo agent inspect <id>",
160
+ };
161
+ throw error;
162
+ }
163
+ const client = await connectToDaemon({ target: options.daemonTarget });
164
+ try {
165
+ const fetchResult = await client.fetchAgent({ agentId: agentIdArg });
166
+ if (!fetchResult) {
167
+ const error = {
168
+ code: "AGENT_NOT_FOUND",
169
+ message: `Agent not found: ${agentIdArg}`,
170
+ details: 'Use "mateo ls" to list available agents',
171
+ };
172
+ throw error;
173
+ }
174
+ await client.close();
175
+ const inspectData = toInspectData(fetchResult.agent);
176
+ return {
177
+ type: "list",
178
+ data: toInspectRows(inspectData),
179
+ schema: createInspectSchema(inspectData),
180
+ };
181
+ }
182
+ catch (err) {
183
+ await client.close().catch(() => { });
184
+ // Re-throw CommandError as-is
185
+ if (err && typeof err === "object" && "code" in err) {
186
+ throw err;
187
+ }
188
+ const message = err instanceof Error ? err.message : String(err);
189
+ const error = {
190
+ code: "INSPECT_FAILED",
191
+ message: `Failed to inspect agent: ${message}`,
192
+ };
193
+ throw error;
194
+ }
195
+ }
196
+ //# sourceMappingURL=inspect.js.map
@@ -0,0 +1,39 @@
1
+ import { Command } from "commander";
2
+ import type { CommandOptions } from "../../output/index.js";
3
+ import type { DaemonClient } from "@getmateo/client/internal/daemon-client";
4
+ import type { AgentTimelineItem } from "@getmateo/protocol/agent-types";
5
+ export declare function addLogsOptions(cmd: Command): Command;
6
+ export interface AgentLogsOptions extends CommandOptions {
7
+ follow?: boolean;
8
+ tail?: string;
9
+ filter?: string;
10
+ since?: string;
11
+ }
12
+ export type AgentLogsResult = void;
13
+ export declare const NO_ACTIVITY_MESSAGE = "No activity to display.";
14
+ interface FetchAgentTimelineItemsOptions {
15
+ timeoutMs?: number;
16
+ sinceTimestampMs?: number;
17
+ }
18
+ export declare function fetchAgentTimelineItems(client: DaemonClient, agentId: string, options?: FetchAgentTimelineItemsOptions): Promise<AgentTimelineItem[]>;
19
+ export declare function formatAgentActivityTranscript(timelineItems: AgentTimelineItem[], tailCount?: number): string;
20
+ export declare function usesJsonOutput(options: CommandOptions): boolean;
21
+ export interface FollowTranscriptWriter {
22
+ push(item: AgentTimelineItem, turnId?: string): void;
23
+ end(): void;
24
+ }
25
+ /**
26
+ * Follow mode receives one streaming fragment per event, while the one-shot
27
+ * transcript sees the whole timeline and merges consecutive assistant and
28
+ * reasoning fragments with exact concatenation (`projectTimelineRows`). Printing
29
+ * each fragment on its own line splits words at fragment boundaries and
30
+ * reprints the reasoning prefix, so a chain of fragments is written as one
31
+ * stream instead: text goes out as it arrives, and only the trailing whitespace
32
+ * is held back so the message ends trimmed the way the transcript does.
33
+ */
34
+ export declare function createFollowTranscriptWriter(write?: (chunk: string) => void, filter?: string): FollowTranscriptWriter;
35
+ /** Follow mode with `--json`: one JSON timeline item per line (NDJSON). */
36
+ export declare function createFollowJsonWriter(filter?: string, write?: (chunk: string) => void): FollowTranscriptWriter;
37
+ export declare function runLogsCommand(id: string, options: AgentLogsOptions, _command: Command): Promise<AgentLogsResult>;
38
+ export {};
39
+ //# sourceMappingURL=logs.d.ts.map
@@ -0,0 +1,369 @@
1
+ import { connectToDaemon } from "../../utils/client.js";
2
+ import { waitForStop } from "../../utils/wait-for-stop.js";
3
+ import { fetchProjectedTimelineItems, LIVE_HISTORY_FETCH_TIMEOUT_MS, } from "../../utils/timeline.js";
4
+ import { curateAgentActivity } from "@getmateo/server/agent-activity";
5
+ export function addLogsOptions(cmd) {
6
+ return cmd
7
+ .description("View agent activity/timeline")
8
+ .argument("<id>", "Agent ID (or prefix)")
9
+ .option("-f, --follow", "Follow log output (streaming)")
10
+ .option("--tail <n>", "Show last n entries")
11
+ .option("--filter <type>", "Filter by event type (tools, text, errors, permissions)")
12
+ .option("--since <time>", "Show logs since timestamp");
13
+ }
14
+ export const NO_ACTIVITY_MESSAGE = "No activity to display.";
15
+ export async function fetchAgentTimelineItems(client, agentId, options) {
16
+ return fetchProjectedTimelineItems({
17
+ client,
18
+ agentId,
19
+ timeoutMs: options?.timeoutMs,
20
+ sinceTimestampMs: options?.sinceTimestampMs,
21
+ });
22
+ }
23
+ export function formatAgentActivityTranscript(timelineItems, tailCount) {
24
+ if (tailCount === 0) {
25
+ return "";
26
+ }
27
+ return curateAgentActivity(timelineItems, tailCount !== undefined ? { maxItems: tailCount } : undefined);
28
+ }
29
+ /**
30
+ * Picks the items `--tail` keeps, the same way the transcript does: the last n
31
+ * timeline items, before any of them are dropped from the curated view.
32
+ */
33
+ function selectTailItems(timelineItems, tailCount) {
34
+ if (tailCount === undefined) {
35
+ return timelineItems;
36
+ }
37
+ if (tailCount === 0) {
38
+ return [];
39
+ }
40
+ return timelineItems.slice(-tailCount);
41
+ }
42
+ function formatAgentLogsJson(agentId, timelineItems, tailCount) {
43
+ return JSON.stringify({ agentId, items: selectTailItems(timelineItems, tailCount) }, null, 2);
44
+ }
45
+ export function usesJsonOutput(options) {
46
+ return options.json === true || options.format?.trim().toLowerCase() === "json";
47
+ }
48
+ const THOUGHT_PREFIX = "[Thought] ";
49
+ function lastNonWhitespaceIndex(text) {
50
+ for (let index = text.length - 1; index >= 0; index -= 1) {
51
+ if (!/\s/.test(text[index])) {
52
+ return index;
53
+ }
54
+ }
55
+ return -1;
56
+ }
57
+ /**
58
+ * Follow mode receives one streaming fragment per event, while the one-shot
59
+ * transcript sees the whole timeline and merges consecutive assistant and
60
+ * reasoning fragments with exact concatenation (`projectTimelineRows`). Printing
61
+ * each fragment on its own line splits words at fragment boundaries and
62
+ * reprints the reasoning prefix, so a chain of fragments is written as one
63
+ * stream instead: text goes out as it arrives, and only the trailing whitespace
64
+ * is held back so the message ends trimmed the way the transcript does.
65
+ */
66
+ export function createFollowTranscriptWriter(write = (chunk) => void process.stdout.write(chunk), filter) {
67
+ let pending = null;
68
+ const emit = (chain, text) => {
69
+ if (!chain.emitted) {
70
+ chain.emitted = true;
71
+ if (chain.type === "reasoning") {
72
+ write(THOUGHT_PREFIX);
73
+ }
74
+ }
75
+ write(text);
76
+ };
77
+ const flushContent = (chain) => {
78
+ if (!chain.emitted) {
79
+ chain.buffer = chain.buffer.replace(/^\s+/, "");
80
+ }
81
+ const lastContent = lastNonWhitespaceIndex(chain.buffer);
82
+ if (lastContent < 0) {
83
+ return;
84
+ }
85
+ emit(chain, chain.buffer.slice(0, lastContent + 1));
86
+ chain.buffer = chain.buffer.slice(lastContent + 1);
87
+ };
88
+ const closePending = () => {
89
+ const chain = pending;
90
+ pending = null;
91
+ if (!chain) {
92
+ return;
93
+ }
94
+ const tail = chain.emitted ? chain.buffer.trimEnd() : chain.buffer.trim();
95
+ if (tail) {
96
+ emit(chain, tail);
97
+ }
98
+ if (chain.emitted) {
99
+ write("\n");
100
+ }
101
+ };
102
+ const continuesChain = (item, turnId) => {
103
+ if (!pending || pending.type !== item.type || pending.turnId !== turnId) {
104
+ return false;
105
+ }
106
+ if (item.type !== "assistant_message") {
107
+ return true;
108
+ }
109
+ return item.messageId === undefined || item.messageId === pending.messageId;
110
+ };
111
+ const startChain = (item, turnId) => {
112
+ closePending();
113
+ const chain = {
114
+ type: item.type,
115
+ turnId,
116
+ messageId: item.type === "assistant_message" ? item.messageId : undefined,
117
+ buffer: "",
118
+ emitted: false,
119
+ };
120
+ pending = chain;
121
+ return chain;
122
+ };
123
+ return {
124
+ push(item, turnId) {
125
+ if (!matchesFilter(item, filter)) {
126
+ closePending();
127
+ return;
128
+ }
129
+ if (item.type === "assistant_message" || item.type === "reasoning") {
130
+ const chain = continuesChain(item, turnId) && pending ? pending : startChain(item, turnId);
131
+ chain.buffer += item.text;
132
+ flushContent(chain);
133
+ return;
134
+ }
135
+ closePending();
136
+ const transcript = formatAgentActivityTranscript([item]);
137
+ if (transcript && transcript !== NO_ACTIVITY_MESSAGE) {
138
+ write(`${transcript}\n`);
139
+ }
140
+ },
141
+ end() {
142
+ closePending();
143
+ },
144
+ };
145
+ }
146
+ /** Follow mode with `--json`: one JSON timeline item per line (NDJSON). */
147
+ export function createFollowJsonWriter(filter, write = (chunk) => void process.stdout.write(chunk)) {
148
+ return {
149
+ push(item) {
150
+ if (matchesFilter(item, filter)) {
151
+ write(`${JSON.stringify(item)}\n`);
152
+ }
153
+ },
154
+ end() { },
155
+ };
156
+ }
157
+ function parseTailCount(raw) {
158
+ if (raw === undefined)
159
+ return undefined;
160
+ const parsed = Number.parseInt(raw, 10);
161
+ if (Number.isNaN(parsed) || parsed < 0) {
162
+ return undefined;
163
+ }
164
+ return parsed;
165
+ }
166
+ function parseSinceTimestamp(raw) {
167
+ if (raw === undefined)
168
+ return undefined;
169
+ const timestampMs = Date.parse(raw);
170
+ if (Number.isNaN(timestampMs)) {
171
+ throw {
172
+ code: "INVALID_TIMESTAMP",
173
+ message: `Invalid --since value: ${raw}`,
174
+ details: "Use a timestamp such as 2026-01-01T00:00:00Z.",
175
+ };
176
+ }
177
+ return timestampMs;
178
+ }
179
+ /**
180
+ * Check if a timeline item matches the filter type
181
+ */
182
+ function matchesFilter(item, filter) {
183
+ if (!filter)
184
+ return true;
185
+ const filterLower = filter.toLowerCase();
186
+ const type = item.type.toLowerCase();
187
+ switch (filterLower) {
188
+ case "tools":
189
+ return type === "tool_call";
190
+ case "text":
191
+ return type === "user_message" || type === "assistant_message" || type === "reasoning";
192
+ case "errors":
193
+ return type === "error";
194
+ case "permissions":
195
+ // Permissions might be in tool_call status or a separate event type
196
+ return type.includes("permission");
197
+ default:
198
+ // If filter doesn't match predefined types, match against the actual type
199
+ return type.includes(filterLower);
200
+ }
201
+ }
202
+ export async function runLogsCommand(id, options, _command) {
203
+ if (!id) {
204
+ console.error("Error: Agent ID required");
205
+ console.error("Usage: mateo agent logs <id>");
206
+ process.exit(1);
207
+ }
208
+ const sinceTimestampMs = parseSinceTimestamp(options.since);
209
+ const client = await connectToDaemon({ target: options.daemonTarget });
210
+ try {
211
+ const fetchResult = await client.fetchAgent({ agentId: id });
212
+ if (!fetchResult) {
213
+ console.error(`Error: No agent found matching: ${id}`);
214
+ console.error("Use `mateo ls` to list available agents");
215
+ await client.close();
216
+ process.exit(1);
217
+ }
218
+ const resolvedId = fetchResult.agent.id;
219
+ // For follow mode, we stream events continuously
220
+ if (options.follow) {
221
+ if (options.tail !== undefined && parseTailCount(options.tail) === undefined) {
222
+ console.error(`Error: Invalid --tail value: ${options.tail}`);
223
+ console.error("Usage: --tail <n> (where n is >= 0)");
224
+ await client.close().catch(() => { });
225
+ process.exit(1);
226
+ }
227
+ await runFollowMode({
228
+ client,
229
+ agentId: resolvedId,
230
+ options,
231
+ sinceTimestampMs,
232
+ });
233
+ return;
234
+ }
235
+ // Fetch timeline directly via cursor RPC.
236
+ let timelineItems = await fetchAgentTimelineItems(client, resolvedId, {
237
+ sinceTimestampMs,
238
+ });
239
+ // Apply filter
240
+ if (options.filter) {
241
+ timelineItems = timelineItems.filter((item) => matchesFilter(item, options.filter));
242
+ }
243
+ const tailCount = parseTailCount(options.tail);
244
+ if (options.tail !== undefined && tailCount === undefined) {
245
+ console.error(`Error: Invalid --tail value: ${options.tail}`);
246
+ console.error("Usage: --tail <n> (where n is >= 0)");
247
+ await client.close().catch(() => { });
248
+ process.exit(1);
249
+ }
250
+ await client.close();
251
+ if (usesJsonOutput(options)) {
252
+ console.log(formatAgentLogsJson(resolvedId, timelineItems, tailCount));
253
+ return;
254
+ }
255
+ // Use curateAgentActivity to format the transcript
256
+ if (tailCount === 0) {
257
+ return;
258
+ }
259
+ const transcript = formatAgentActivityTranscript(timelineItems, tailCount);
260
+ console.log(transcript);
261
+ }
262
+ catch (err) {
263
+ if (err && typeof err === "object" && "code" in err)
264
+ throw err;
265
+ const message = err instanceof Error ? err.message : String(err);
266
+ console.error(`Error: Failed to get logs: ${message}`);
267
+ await client.close().catch(() => { });
268
+ process.exit(1);
269
+ }
270
+ }
271
+ /**
272
+ * Follow mode: stream logs in real-time until interrupted
273
+ */
274
+ async function runFollowMode({ client, agentId, options, sinceTimestampMs, }) {
275
+ // Observe shutdown before history writes can encounter a closed reader.
276
+ // Keep an early stop resolved while subscription setup is in flight.
277
+ const stopController = new AbortController();
278
+ const stopped = waitForStop(stopController.signal);
279
+ let unsubscribe;
280
+ const json = usesJsonOutput(options);
281
+ const writer = json
282
+ ? createFollowJsonWriter(options.filter)
283
+ : createFollowTranscriptWriter(undefined, options.filter);
284
+ try {
285
+ const DEFAULT_FOLLOW_TAIL = 10;
286
+ const tailCount = parseTailCount(options.tail) ?? DEFAULT_FOLLOW_TAIL;
287
+ // First, get existing timeline.
288
+ let existingItems = [];
289
+ try {
290
+ const history = await Promise.race([
291
+ fetchAgentTimelineItems(client, agentId, {
292
+ timeoutMs: LIVE_HISTORY_FETCH_TIMEOUT_MS,
293
+ sinceTimestampMs,
294
+ }),
295
+ stopped,
296
+ ]);
297
+ if (!history)
298
+ return;
299
+ existingItems = history;
300
+ }
301
+ catch (error) {
302
+ console.warn("Warning: failed to fetch existing timeline", error);
303
+ }
304
+ // Apply filter to existing items
305
+ if (options.filter) {
306
+ existingItems = existingItems.filter((item) => matchesFilter(item, options.filter));
307
+ }
308
+ // Print existing transcript (tail-like behavior)
309
+ if (json) {
310
+ for (const item of selectTailItems(existingItems, tailCount)) {
311
+ console.log(JSON.stringify(item));
312
+ }
313
+ }
314
+ else if (tailCount > 0) {
315
+ const existingTranscript = formatAgentActivityTranscript(existingItems, tailCount);
316
+ if (existingTranscript !== NO_ACTIVITY_MESSAGE) {
317
+ console.log(existingTranscript);
318
+ }
319
+ }
320
+ // Subscribe to new events
321
+ const tailLabel = tailCount === 0 ? "no history" : `last ${tailCount} entr${tailCount === 1 ? "y" : "ies"}`;
322
+ // Keep stdout parseable in JSON mode: one timeline item per line, notices on stderr.
323
+ const notice = json ? console.error : console.log;
324
+ const subscription = client.subscribeAgentTimeline(agentId, (message) => {
325
+ if (message.type === "agent.timeline.replacement") {
326
+ writer.end();
327
+ notice("\n[Timeline replaced; earlier output is no longer current]");
328
+ return;
329
+ }
330
+ if (message.type === "agent.timeline.error") {
331
+ writer.end();
332
+ console.error(`Timeline observation stopped: ${message.payload.error}`);
333
+ return;
334
+ }
335
+ if (message.type === "agent.timeline.subscription_restored") {
336
+ writer.end();
337
+ notice("\n[Reconnected; live output resumed. Events may have been missed.]");
338
+ return;
339
+ }
340
+ if (message.payload.event.type === "timeline") {
341
+ const matchesSince = sinceTimestampMs === undefined ||
342
+ Date.parse(message.payload.timestamp) >= sinceTimestampMs;
343
+ if (!matchesSince) {
344
+ return;
345
+ }
346
+ const item = message.payload.event.item;
347
+ writer.push(item, message.payload.event.turnId);
348
+ }
349
+ else if (message.payload.event.type === "turn_completed" ||
350
+ message.payload.event.type === "turn_failed" ||
351
+ message.payload.event.type === "turn_canceled") {
352
+ writer.end();
353
+ }
354
+ });
355
+ unsubscribe = subscription;
356
+ const ready = await Promise.race([subscription.ready.then(() => true), stopped]);
357
+ if (!ready)
358
+ return;
359
+ notice(`\n--- Following logs (${tailLabel}; Ctrl+C to stop) ---\n`);
360
+ await stopped;
361
+ }
362
+ finally {
363
+ stopController.abort();
364
+ writer.end();
365
+ unsubscribe?.();
366
+ await client.close();
367
+ }
368
+ }
369
+ //# sourceMappingURL=logs.js.map
@@ -0,0 +1,61 @@
1
+ import type { Command } from "commander";
2
+ import type { AgentSnapshotPayload } from "@getmateo/protocol/messages";
3
+ import { connectToDaemon } from "../../utils/client.js";
4
+ import type { CommandOptions, ListResult, OutputSchema } from "../../output/index.js";
5
+ type FetchAgentsOptions = NonNullable<Parameters<Awaited<ReturnType<typeof connectToDaemon>>["fetchAgents"]>[0]>;
6
+ export declare function addLsOptions(cmd: Command): Command;
7
+ /** Agent list item for display */
8
+ export interface AgentListItem {
9
+ id: string;
10
+ shortId: string;
11
+ name: string;
12
+ provider: string;
13
+ thinking: string;
14
+ status: string;
15
+ cwd: string;
16
+ created: string;
17
+ labels: AgentSnapshotPayload["labels"];
18
+ workspaceId: string | null;
19
+ }
20
+ /** Schema for agent ls output */
21
+ export declare const agentLsSchema: OutputSchema<AgentListItem>;
22
+ export type AgentLsResult = ListResult<AgentListItem>;
23
+ export interface AgentLsOptions extends CommandOptions {
24
+ /** -a: Include archived agents */
25
+ all?: boolean;
26
+ /** -g: List agents across all directories */
27
+ global?: boolean;
28
+ /** --background: Include background workspace agents */
29
+ background?: boolean;
30
+ /** Filter by specific status */
31
+ status?: string;
32
+ /** Filter by specific cwd */
33
+ cwd?: string;
34
+ /** Filter by labels (key=value format) */
35
+ label?: string[];
36
+ /** Filter by thinking option ID */
37
+ thinking?: string;
38
+ }
39
+ export declare function buildAgentLsFetchOptions(options: Pick<AgentLsOptions, "all" | "global" | "background" | "label" | "thinking">): FetchAgentsOptions;
40
+ interface AgentLsClient {
41
+ fetchAgents(options?: FetchAgentsOptions): Promise<{
42
+ entries: {
43
+ agent: AgentSnapshotPayload;
44
+ }[];
45
+ pageInfo: {
46
+ nextCursor: string | null;
47
+ };
48
+ }>;
49
+ close(): Promise<void>;
50
+ }
51
+ /**
52
+ * Agent ls command semantics:
53
+ * - `mateo agent ls` → active non-archived agents
54
+ * - `mateo agent ls -g` → global non-archived agents
55
+ * - `mateo agent ls -a` → all agents, including archived and background
56
+ * - `mateo agent ls -ag` → global agents, including archived
57
+ */
58
+ export declare function runLsCommand(options: AgentLsOptions, _command: Command): Promise<AgentLsResult>;
59
+ export declare function listAgents(options: AgentLsOptions, connect?: (options: Parameters<typeof connectToDaemon>[0]) => Promise<AgentLsClient>): Promise<AgentLsResult>;
60
+ export {};
61
+ //# sourceMappingURL=ls.d.ts.map