@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,135 @@
1
+ /**
2
+ * Table renderer for CLI output.
3
+ *
4
+ * Renders structured data as aligned ASCII tables with optional color support.
5
+ */
6
+ import chalk from "chalk";
7
+ // ANSI escape code regex for stripping colors when measuring width
8
+ const ANSI_REGEX =
9
+ // eslint-disable-next-line no-control-regex
10
+ /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;
11
+ /** Strip ANSI escape codes from a string */
12
+ function stripAnsi(str) {
13
+ return str.replace(ANSI_REGEX, "");
14
+ }
15
+ /** Get visible string length (excluding ANSI codes) */
16
+ function visibleLength(str) {
17
+ return stripAnsi(str).length;
18
+ }
19
+ /** Pad a cell to the specified width with alignment */
20
+ function padCell(cell, width, align) {
21
+ const visible = visibleLength(cell);
22
+ const padding = Math.max(0, width - visible);
23
+ switch (align) {
24
+ case "right":
25
+ return " ".repeat(padding) + cell;
26
+ case "center": {
27
+ const left = Math.floor(padding / 2);
28
+ const right = padding - left;
29
+ return " ".repeat(left) + cell + " ".repeat(right);
30
+ }
31
+ case "left":
32
+ default:
33
+ return cell + " ".repeat(padding);
34
+ }
35
+ }
36
+ /** Apply a chalk color to a string */
37
+ function applyColor(str, colorName) {
38
+ // Map color names to chalk methods
39
+ const colorMap = {
40
+ red: chalk.red,
41
+ green: chalk.green,
42
+ blue: chalk.blue,
43
+ yellow: chalk.yellow,
44
+ cyan: chalk.cyan,
45
+ magenta: chalk.magenta,
46
+ white: chalk.white,
47
+ gray: chalk.gray,
48
+ grey: chalk.grey,
49
+ dim: chalk.dim,
50
+ bold: chalk.bold,
51
+ };
52
+ const colorFn = colorMap[colorName];
53
+ return colorFn ? colorFn(str) : str;
54
+ }
55
+ /** Extract value from item using field definition */
56
+ function getValue(item, field) {
57
+ return typeof field === "function" ? field(item) : item[field];
58
+ }
59
+ /** Render a single table row */
60
+ function renderRow(item, columns, widths, options) {
61
+ return columns
62
+ .map((col, colIndex) => {
63
+ const value = getValue(item, col.field);
64
+ let cell = String(value ?? "");
65
+ const width = widths[colIndex];
66
+ // Apply color if enabled
67
+ if (col.color && !options.noColor) {
68
+ const colorName = col.color(value, item);
69
+ if (colorName) {
70
+ cell = applyColor(cell, colorName);
71
+ }
72
+ }
73
+ return padCell(cell, width ?? 0, col.align ?? "left");
74
+ })
75
+ .join(" ");
76
+ }
77
+ /** Render header row */
78
+ function renderHeader(columns, widths, options) {
79
+ const headerRow = columns
80
+ .map((col, i) => padCell(col.header, widths[i] ?? 0, col.align ?? "left"))
81
+ .join(" ");
82
+ return options.noColor ? headerRow : chalk.bold(headerRow);
83
+ }
84
+ /** Calculate column widths based on content and hints */
85
+ function calculateWidths(data, columns, includeHeaders) {
86
+ return columns.map((col) => {
87
+ // Start with header width if including headers
88
+ let maxWidth = includeHeaders ? col.header.length : 0;
89
+ // Check all data values
90
+ for (const item of data) {
91
+ const value = getValue(item, col.field);
92
+ const str = String(value ?? "");
93
+ maxWidth = Math.max(maxWidth, visibleLength(str));
94
+ }
95
+ // Apply width hint if specified (minimum width)
96
+ if (col.width) {
97
+ maxWidth = Math.max(maxWidth, col.width);
98
+ }
99
+ return maxWidth;
100
+ });
101
+ }
102
+ /** Render a list result as a table */
103
+ export function renderTable(result, options) {
104
+ const { schema } = result;
105
+ const data = result.type === "list" ? result.data : [result.data];
106
+ if (data.length === 0) {
107
+ return "";
108
+ }
109
+ const columns = schema.columns;
110
+ const includeHeaders = !options.noHeaders;
111
+ const widths = calculateWidths(data, columns, includeHeaders);
112
+ const lines = [];
113
+ // Add header row
114
+ if (includeHeaders) {
115
+ lines.push(renderHeader(columns, widths, options));
116
+ }
117
+ // Add data rows
118
+ for (const item of data) {
119
+ lines.push(renderRow(item, columns, widths, options));
120
+ }
121
+ return lines.join("\n");
122
+ }
123
+ /** Render just a table header (for streaming) */
124
+ export function renderTableHeader(schema, options, widths) {
125
+ const columns = schema.columns;
126
+ const actualWidths = widths ?? columns.map((col) => col.width ?? col.header.length);
127
+ return renderHeader(columns, actualWidths, options);
128
+ }
129
+ /** Render just a table row (for streaming) */
130
+ export function renderTableRow(item, schema, options, widths) {
131
+ const columns = schema.columns;
132
+ const actualWidths = widths ?? columns.map((col) => col.width ?? col.header.length);
133
+ return renderRow(item, columns, actualWidths, options);
134
+ }
135
+ //# sourceMappingURL=table.js.map
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Output format types for the Mateo CLI.
3
+ *
4
+ * This module defines the structured data types used by the output abstraction layer.
5
+ * Commands return CommandResult<T> which contains both data and rendering metadata.
6
+ */
7
+ /** Supported output formats */
8
+ export type OutputFormat = "table" | "json" | "yaml";
9
+ /** Options controlling output rendering */
10
+ export interface OutputOptions {
11
+ /** Output format (table, json, yaml) */
12
+ format: OutputFormat;
13
+ /** Minimal output - IDs only */
14
+ quiet: boolean;
15
+ /** Omit table headers */
16
+ noHeaders: boolean;
17
+ /** Disable color output */
18
+ noColor: boolean;
19
+ }
20
+ /** Column definition for table output */
21
+ export interface ColumnDef<T> {
22
+ /** Header text for the column */
23
+ header: string;
24
+ /** Field key or accessor function */
25
+ field: keyof T | ((item: T) => unknown);
26
+ /** Optional width hint (characters) */
27
+ width?: number;
28
+ /** Optional alignment */
29
+ align?: "left" | "right" | "center";
30
+ /** Optional color function - returns chalk color name */
31
+ color?: (value: unknown, item: T) => string | undefined;
32
+ }
33
+ /** Schema describing how to render command output */
34
+ export interface OutputSchema<T> {
35
+ /** Field to use for quiet mode (--quiet outputs just this) */
36
+ idField: keyof T | ((item: T) => string);
37
+ /** Column definitions for table output */
38
+ columns: ColumnDef<T>[];
39
+ /** Optional: custom renderer for human/table output */
40
+ renderHuman?: (result: AnyCommandResult<T>, options: OutputOptions) => string;
41
+ /** Optional: transform data before JSON/YAML output */
42
+ serialize?: (data: T) => unknown;
43
+ }
44
+ /** Result type for commands returning a single item */
45
+ export interface SingleResult<T> {
46
+ type: "single";
47
+ /** The structured data to render */
48
+ data: T;
49
+ /** Schema describing how to render this data (for item type T) */
50
+ schema: OutputSchema<T>;
51
+ }
52
+ /** Result type for commands returning a list */
53
+ export interface ListResult<T> {
54
+ type: "list";
55
+ /** The structured data to render */
56
+ data: T[];
57
+ /** Schema describing how to render this data (for item type T) */
58
+ schema: OutputSchema<T>;
59
+ }
60
+ /** Union type for all command results */
61
+ export type AnyCommandResult<T> = T extends unknown ? SingleResult<T> | ListResult<T> : never;
62
+ /** Base interface for command results (deprecated, use SingleResult or ListResult) */
63
+ export type CommandResult<T> = SingleResult<T> | ListResult<T>;
64
+ /** Structured error for command failures */
65
+ export interface CommandError {
66
+ /** Machine-readable error code */
67
+ code: string;
68
+ /** Human-readable message */
69
+ message: string;
70
+ /** Additional context */
71
+ details?: unknown;
72
+ }
73
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Output format types for the Mateo CLI.
3
+ *
4
+ * This module defines the structured data types used by the output abstraction layer.
5
+ * Commands return CommandResult<T> which contains both data and rendering metadata.
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Command wrapper for automatic output rendering.
3
+ *
4
+ * Wraps command handlers to automatically render results and handle errors.
5
+ */
6
+ import type { Command } from "commander";
7
+ import type { AnyCommandResult, OutputOptions } from "./types.js";
8
+ /** Options that include output settings from global options */
9
+ export interface CommandOptions extends Partial<OutputOptions> {
10
+ daemonTarget: import("../utils/daemon-target.js").DaemonTarget;
11
+ home?: string;
12
+ /** Daemon host target from --host option */
13
+ host?: string;
14
+ /** JSON output flag from --json option */
15
+ json?: boolean;
16
+ [key: string]: unknown;
17
+ }
18
+ /**
19
+ * Wrap a command handler to automatically render output.
20
+ *
21
+ * The wrapped handler should return a CommandResult. The wrapper will:
22
+ * 1. Call the handler
23
+ * 2. Render the result using the appropriate format
24
+ * 3. Write to stdout
25
+ * 4. Handle errors by rendering to stderr and exiting with code 1
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * program
30
+ * .command('list')
31
+ * .action(withOutput(async (options) => {
32
+ * const data = await fetchData()
33
+ * return { type: 'list', data, schema }
34
+ * }))
35
+ * ```
36
+ */
37
+ export declare function withOutput<T, Args extends unknown[]>(handler: (...args: [...Args, CommandOptions, Command]) => Promise<AnyCommandResult<T>>): (...args: [...Args, CommandOptions, Command]) => Promise<void>;
38
+ /**
39
+ * Helper to create output options from partial input.
40
+ * Useful for testing or manual rendering.
41
+ */
42
+ export declare function createOutputOptions(partial?: Partial<OutputOptions>): OutputOptions;
43
+ //# sourceMappingURL=with-output.d.ts.map
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Command wrapper for automatic output rendering.
3
+ *
4
+ * Wraps command handlers to automatically render results and handle errors.
5
+ */
6
+ import { render, renderError, toCommandError, defaultOutputOptions } from "./render.js";
7
+ import { withGlobalOptions } from "../utils/command-options.js";
8
+ function normalizeFormat(raw) {
9
+ const value = typeof raw === "string" ? raw.trim().toLowerCase() : "";
10
+ // Common user expectation: "cli" means "table/human"
11
+ if (value === "cli")
12
+ return "table";
13
+ if (value === "table" || value === "json" || value === "yaml")
14
+ return value;
15
+ const error = {
16
+ code: "INVALID_FORMAT",
17
+ message: `Unsupported output format: ${String(raw)}`,
18
+ details: "Supported formats: table, json, yaml",
19
+ };
20
+ throw error;
21
+ }
22
+ /** Extract output options from command options */
23
+ function extractOutputOptions(options) {
24
+ const hasStructuredOutputSchema = typeof options.outputSchema === "string" && options.outputSchema.trim().length > 0;
25
+ if (hasStructuredOutputSchema) {
26
+ return {
27
+ format: "json",
28
+ quiet: false,
29
+ noHeaders: options.headers === false,
30
+ noColor: options.color === false,
31
+ };
32
+ }
33
+ return {
34
+ format: options.json ? "json" : normalizeFormat(options.format ?? defaultOutputOptions.format),
35
+ quiet: options.quiet ?? defaultOutputOptions.quiet,
36
+ noHeaders: options.headers === false, // Commander uses --no-headers -> headers: false
37
+ noColor: options.color === false, // Commander uses --no-color -> color: false
38
+ };
39
+ }
40
+ /**
41
+ * Wrap a command handler to automatically render output.
42
+ *
43
+ * The wrapped handler should return a CommandResult. The wrapper will:
44
+ * 1. Call the handler
45
+ * 2. Render the result using the appropriate format
46
+ * 3. Write to stdout
47
+ * 4. Handle errors by rendering to stderr and exiting with code 1
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * program
52
+ * .command('list')
53
+ * .action(withOutput(async (options) => {
54
+ * const data = await fetchData()
55
+ * return { type: 'list', data, schema }
56
+ * }))
57
+ * ```
58
+ */
59
+ export function withOutput(handler) {
60
+ return withGlobalOptions(async (...args) => {
61
+ const options = args[args.length - 2];
62
+ const outputOptions = extractOutputOptions(options);
63
+ try {
64
+ const result = await handler(...args);
65
+ const output = render(result, outputOptions);
66
+ if (output) {
67
+ process.stdout.write(output + "\n");
68
+ }
69
+ }
70
+ catch (error) {
71
+ const commandError = toCommandError(error);
72
+ const errorOutput = renderError(commandError, outputOptions);
73
+ process.stderr.write(errorOutput + "\n");
74
+ process.exit(1);
75
+ }
76
+ });
77
+ }
78
+ /**
79
+ * Helper to create output options from partial input.
80
+ * Useful for testing or manual rendering.
81
+ */
82
+ export function createOutputOptions(partial = {}) {
83
+ return { ...defaultOutputOptions, ...partial };
84
+ }
85
+ //# sourceMappingURL=with-output.js.map
@@ -0,0 +1,11 @@
1
+ /**
2
+ * YAML renderer for CLI output.
3
+ *
4
+ * Renders structured data as YAML for machine consumption and human readability.
5
+ */
6
+ import type { AnyCommandResult, OutputOptions } from "./types.js";
7
+ /** Render command result as YAML */
8
+ export declare function renderYaml<T>(result: AnyCommandResult<T>, _options: OutputOptions): string;
9
+ /** Render a single item as YAML document (for streaming) */
10
+ export declare function renderYamlDoc<T>(item: T, serialize?: (data: T) => unknown): string;
11
+ //# sourceMappingURL=yaml.d.ts.map
@@ -0,0 +1,38 @@
1
+ /**
2
+ * YAML renderer for CLI output.
3
+ *
4
+ * Renders structured data as YAML for machine consumption and human readability.
5
+ */
6
+ import YAML from "yaml";
7
+ /** Render command result as YAML */
8
+ export function renderYaml(result, _options) {
9
+ const { schema } = result;
10
+ // Apply custom serializer if provided
11
+ if (schema.serialize) {
12
+ if (result.type === "list") {
13
+ // If all items serialize to the same object, return just one
14
+ // This handles the case where a list of key-value rows should serialize
15
+ // to a single structured object
16
+ const serialized = result.data.map((item) => schema.serialize(item));
17
+ if (serialized.length > 0) {
18
+ const first = JSON.stringify(serialized[0]);
19
+ const allSame = serialized.every((s) => JSON.stringify(s) === first);
20
+ if (allSame) {
21
+ return YAML.stringify(serialized[0]);
22
+ }
23
+ }
24
+ return YAML.stringify(serialized);
25
+ }
26
+ else {
27
+ const serialized = schema.serialize(result.data);
28
+ return YAML.stringify(serialized);
29
+ }
30
+ }
31
+ return YAML.stringify(result.data);
32
+ }
33
+ /** Render a single item as YAML document (for streaming) */
34
+ export function renderYamlDoc(item, serialize) {
35
+ const output = serialize ? serialize(item) : item;
36
+ return YAML.stringify(output);
37
+ }
38
+ //# sourceMappingURL=yaml.js.map
package/dist/run.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ export interface RunCliOptions {
2
+ cwd?: string;
3
+ nodeArgv?: [string, string];
4
+ }
5
+ export declare function createCliParseArgv(input: {
6
+ argv: string[];
7
+ cwd: string;
8
+ nodeArgv?: [string, string];
9
+ }): string[] | {
10
+ kind: "open-project";
11
+ resolvedPath: string;
12
+ };
13
+ export declare function runCli(argv: string[], options?: RunCliOptions): Promise<number>;
14
+ //# sourceMappingURL=run.d.ts.map
package/dist/run.js ADDED
@@ -0,0 +1,62 @@
1
+ import { renderError, toCommandError, defaultOutputOptions } from "./output/render.js";
2
+ import { createCli } from "./cli.js";
3
+ import { classifyInvocation } from "./classify.js";
4
+ import { openDesktopWithProject } from "./commands/open.js";
5
+ export function createCliParseArgv(input) {
6
+ const program = createCli();
7
+ const knownCommands = new Set(program.commands.map((command) => command.name()));
8
+ const invocation = classifyInvocation({
9
+ argv: input.argv,
10
+ knownCommands,
11
+ cwd: input.cwd,
12
+ });
13
+ if (invocation.kind === "open-project") {
14
+ return invocation;
15
+ }
16
+ const nodeArgv = input.nodeArgv ?? ["mateo", "mateo"];
17
+ const isOnboardRootFlag = invocation.argv[0] === "--relay" || invocation.argv[0] === "--no-relay";
18
+ let cliArgv = invocation.argv;
19
+ if (invocation.argv.length === 0) {
20
+ cliArgv = ["onboard"];
21
+ }
22
+ else if (isOnboardRootFlag) {
23
+ cliArgv = ["onboard", ...invocation.argv];
24
+ }
25
+ return [...nodeArgv, ...cliArgv];
26
+ }
27
+ // The program that started the CLI can close its end of stdout before the output
28
+ // is written, as `mateo ls | head -1` or a launcher that discards output does.
29
+ // Drop the output nobody reads and let the command finish, instead of surfacing
30
+ // the failed write as an uncaught error.
31
+ function ignoreClosedStdout(error) {
32
+ if (error.code !== "EPIPE") {
33
+ throw error;
34
+ }
35
+ }
36
+ export async function runCli(argv, options = {}) {
37
+ if (!process.stdout.listeners("error").includes(ignoreClosedStdout)) {
38
+ process.stdout.on("error", ignoreClosedStdout);
39
+ }
40
+ const parseArgv = createCliParseArgv({
41
+ argv,
42
+ cwd: options.cwd ?? process.cwd(),
43
+ nodeArgv: options.nodeArgv,
44
+ });
45
+ if (!Array.isArray(parseArgv)) {
46
+ await openDesktopWithProject(parseArgv.resolvedPath);
47
+ return typeof process.exitCode === "number" ? process.exitCode : 0;
48
+ }
49
+ const program = createCli();
50
+ try {
51
+ await program.parseAsync(parseArgv, { from: "node" });
52
+ }
53
+ catch (error) {
54
+ process.stderr.write(renderError(toCommandError(error), {
55
+ ...defaultOutputOptions,
56
+ format: argv.includes("--json") ? "json" : "table",
57
+ }) + "\n");
58
+ return 1;
59
+ }
60
+ return typeof process.exitCode === "number" ? process.exitCode : 0;
61
+ }
62
+ //# sourceMappingURL=run.js.map
@@ -0,0 +1,2 @@
1
+ export { createSshTunnel, resolveSshFailureDetail, type SshTunnel } from "@getmateo/client/node";
2
+ //# sourceMappingURL=ssh-tunnel.d.ts.map
@@ -0,0 +1,3 @@
1
+ // The connector owns SSH tunnels; the CLI reuses it for --host ssh:// targets.
2
+ export { createSshTunnel, resolveSshFailureDetail } from "@getmateo/client/node";
3
+ //# sourceMappingURL=ssh-tunnel.js.map
@@ -0,0 +1,31 @@
1
+ import type { AgentSnapshotPayload } from "@getmateo/protocol/messages";
2
+ import { type connectToDaemon } from "./client.js";
3
+ type DaemonClient = Awaited<ReturnType<typeof connectToDaemon>>;
4
+ type FetchAgentsOptions = NonNullable<Parameters<DaemonClient["fetchAgents"]>[0]>;
5
+ export interface AgentDirectoryClient {
6
+ fetchAgents(options?: FetchAgentsOptions): Promise<{
7
+ entries: {
8
+ agent: AgentSnapshotPayload;
9
+ }[];
10
+ pageInfo: {
11
+ nextCursor: string | null;
12
+ };
13
+ }>;
14
+ }
15
+ export interface AgentLookupClient extends AgentDirectoryClient {
16
+ fetchAgent(options: {
17
+ agentId: string;
18
+ }): Promise<{
19
+ agent: AgentSnapshotPayload;
20
+ } | null>;
21
+ }
22
+ /** Read the complete directory without agents moving between pages as they update. */
23
+ export declare function fetchAllAgents(client: AgentDirectoryClient, options?: Omit<FetchAgentsOptions, "page" | "sort" | "subscribe">): Promise<AgentSnapshotPayload[]>;
24
+ /**
25
+ * Resolve an agent by ID, prefix, or name from the directory, falling back to
26
+ * `fetch_agent` for agents omitted from `fetch_agents` (for example after their
27
+ * workspace or project was deleted).
28
+ */
29
+ export declare function resolveAgentEntry(client: AgentLookupClient, agentIdArg: string): Promise<AgentSnapshotPayload | null>;
30
+ export {};
31
+ //# sourceMappingURL=agent-directory.d.ts.map
@@ -0,0 +1,48 @@
1
+ import { resolveAgentId } from "./client.js";
2
+ const FULL_AGENT_UUID_PATTERN = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i;
3
+ /** Read the complete directory without agents moving between pages as they update. */
4
+ export async function fetchAllAgents(client, options = {}) {
5
+ const agents = [];
6
+ let cursor;
7
+ // createdAt never changes, so agents cannot move past the cursor while the pages are read.
8
+ do {
9
+ const payload = await client.fetchAgents({
10
+ ...options,
11
+ sort: [{ key: "created_at", direction: "desc" }],
12
+ page: { limit: 200, ...(cursor ? { cursor } : {}) },
13
+ });
14
+ agents.push(...payload.entries.map((entry) => entry.agent));
15
+ cursor = payload.pageInfo.nextCursor ?? undefined;
16
+ } while (cursor);
17
+ return agents;
18
+ }
19
+ /**
20
+ * Resolve an agent by ID, prefix, or name from the directory, falling back to
21
+ * `fetch_agent` for agents omitted from `fetch_agents` (for example after their
22
+ * workspace or project was deleted).
23
+ */
24
+ export async function resolveAgentEntry(client, agentIdArg) {
25
+ const trimmed = agentIdArg.trim();
26
+ if (!trimmed) {
27
+ return null;
28
+ }
29
+ const agents = await fetchAllAgents(client, { filter: { includeArchived: true } });
30
+ const listedId = resolveAgentId(agentIdArg, agents);
31
+ if (listedId) {
32
+ const match = agents.find((entry) => entry.id === listedId);
33
+ if (match) {
34
+ return match;
35
+ }
36
+ }
37
+ // COMPAT(fullAgentIdExact): daemons before v0.16.0 resolve a full agent ID
38
+ // that matches no agent to an agent titled with it, so archive, detach and
39
+ // reload accept their answer only when it is that ID. Remove after 2027-05-16.
40
+ if (FULL_AGENT_UUID_PATTERN.test(trimmed)) {
41
+ const agentId = trimmed.toLowerCase();
42
+ const fetchResult = await client.fetchAgent({ agentId });
43
+ return fetchResult?.agent.id === agentId ? fetchResult.agent : null;
44
+ }
45
+ const fetchResult = await client.fetchAgent({ agentId: trimmed });
46
+ return fetchResult?.agent ?? null;
47
+ }
48
+ //# sourceMappingURL=agent-directory.js.map
@@ -0,0 +1,14 @@
1
+ interface CallerLookupClient {
2
+ fetchAgent(options: {
3
+ agentId: string;
4
+ }): Promise<{
5
+ agent: {
6
+ id: string;
7
+ };
8
+ } | null>;
9
+ }
10
+ export declare function resolveCallerAgentId(client: CallerLookupClient, env?: {
11
+ MATEO_AGENT_ID?: string;
12
+ }): Promise<string | undefined>;
13
+ export {};
14
+ //# sourceMappingURL=caller-agent.d.ts.map
@@ -0,0 +1,16 @@
1
+ import { DaemonConnectionError } from "@getmateo/client/internal/daemon-client";
2
+ // MATEO_AGENT_ID belongs to the daemon that launched this shell. Commands
3
+ // targeting another daemon (--host or --home) have no caller on that daemon.
4
+ export async function resolveCallerAgentId(client, env = process.env) {
5
+ const agentId = env.MATEO_AGENT_ID?.trim();
6
+ if (!agentId)
7
+ return undefined;
8
+ const caller = await client.fetchAgent({ agentId }).catch((error) => {
9
+ // A missing agent is a daemon answer; a lost or timed-out connection is not.
10
+ if (error instanceof DaemonConnectionError)
11
+ throw error;
12
+ return null;
13
+ });
14
+ return caller?.agent.id === agentId ? agentId : undefined;
15
+ }
16
+ //# sourceMappingURL=caller-agent.js.map
@@ -0,0 +1,2 @@
1
+ export declare function getOrCreateCliClientId(home: string): Promise<string>;
2
+ //# sourceMappingURL=client-id.d.ts.map
@@ -0,0 +1,31 @@
1
+ import { ensurePrivateDirectory } from "@getmateo/server/daemon-control";
2
+ import { readFile, writeFile } from "node:fs/promises";
3
+ import { randomUUID } from "node:crypto";
4
+ import { join } from "node:path";
5
+ function normalizeClientId(value) {
6
+ const trimmed = value.trim();
7
+ return trimmed.length > 0 ? trimmed : null;
8
+ }
9
+ function generateClientId() {
10
+ return `cid_${randomUUID().replace(/-/g, "")}`;
11
+ }
12
+ export async function getOrCreateCliClientId(home) {
13
+ const clientSessionKeyFile = join(home, "cli-client-id");
14
+ try {
15
+ const existing = normalizeClientId(await readFile(clientSessionKeyFile, "utf8"));
16
+ if (existing) {
17
+ return existing;
18
+ }
19
+ }
20
+ catch (error) {
21
+ const code = error?.code;
22
+ if (code !== "ENOENT") {
23
+ throw error;
24
+ }
25
+ }
26
+ const nextValue = generateClientId();
27
+ ensurePrivateDirectory(home);
28
+ await writeFile(clientSessionKeyFile, nextValue, { mode: 0o600 });
29
+ return nextValue;
30
+ }
31
+ //# sourceMappingURL=client-id.js.map