@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,57 @@
1
+ import { type DaemonInstance } from "@getmateo/server/daemon-control";
2
+ import { type DaemonTarget } from "./daemon-target.js";
3
+ export type { DaemonTarget } from "./daemon-target.js";
4
+ import { DaemonClient } from "@getmateo/client/internal/daemon-client";
5
+ export interface ConnectOptions {
6
+ target: DaemonTarget;
7
+ timeout?: number;
8
+ instance?: DaemonInstance;
9
+ }
10
+ export declare function resolveClientMateoHome(target: DaemonTarget, env?: Readonly<Record<string, string | undefined>>): string;
11
+ type TransportTarget = {
12
+ type: "tcp";
13
+ url: string;
14
+ } | {
15
+ type: "ipc";
16
+ url: string;
17
+ socketPath: string;
18
+ };
19
+ export declare function getDaemonHost(options: ConnectOptions): string;
20
+ export declare function buildDaemonConnectionCommandError(options: ConnectOptions & {
21
+ error: unknown;
22
+ }): {
23
+ code: string;
24
+ message: string;
25
+ details: string;
26
+ };
27
+ export declare function normalizeDaemonHost(raw: string): string | null;
28
+ export declare function resolveDaemonTarget(host: string): TransportTarget;
29
+ export declare function resolveDaemonPassword(host: string): string | undefined;
30
+ export declare function resolveDaemonCredential(host: string, home: string): {
31
+ kind: "password";
32
+ password: string;
33
+ } | {
34
+ kind: "localCredential";
35
+ token: string;
36
+ } | null;
37
+ export declare function connectToDaemon(options: ConnectOptions): Promise<DaemonClient>;
38
+ /**
39
+ * Try to connect to the daemon, returns null if connection fails
40
+ */
41
+ export declare function tryConnectToDaemon(options: ConnectOptions): Promise<DaemonClient | null>;
42
+ /** Minimal agent type for ID resolution */
43
+ interface AgentLike {
44
+ id: string;
45
+ title?: string | null;
46
+ }
47
+ /**
48
+ * Resolve an agent ID from a partial ID or name.
49
+ * Supports:
50
+ * - Full ID match
51
+ * - Prefix match (first N characters)
52
+ * - Title/name match (case-insensitive)
53
+ *
54
+ * Returns the full agent ID if found, null otherwise.
55
+ */
56
+ export declare function resolveAgentId(idOrName: string, agents: AgentLike[]): string | null;
57
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1,360 @@
1
+ import { waitForDaemonReady, resolveMateoHome, readLocalCredentialForTarget, } from "@getmateo/server/daemon-control";
2
+ import { describeDaemonTarget } from "./daemon-target.js";
3
+ import { buildDaemonWebSocketUrl, buildRelayWebSocketUrl, normalizeHostPort, parseConnectionUri, shouldUseTlsForDefaultHostedRelay, } from "@getmateo/protocol/daemon-endpoints";
4
+ import { parseConnectionOfferFromUrl, } from "@getmateo/protocol/connection-offer";
5
+ import { parseSshTransportUri } from "@getmateo/protocol/ssh-transport";
6
+ import { DaemonClient, } from "@getmateo/client/internal/daemon-client";
7
+ import { WebSocket } from "ws";
8
+ import { hostname, platform } from "node:os";
9
+ import { getOrCreateCliClientId } from "./client-id.js";
10
+ import { resolveCliVersion } from "../version.js";
11
+ import { createSshTunnel } from "../ssh/ssh-tunnel.js";
12
+ const OS_NAMES = {
13
+ darwin: { id: "macos", name: "macOS" },
14
+ win32: { id: "windows", name: "Windows" },
15
+ linux: { id: "linux", name: "Linux" },
16
+ };
17
+ /** Names the computer in the host owner's session list; never used for authorization. */
18
+ function describeCliDevice() {
19
+ // The hello caps names at 256 characters; a longer one would be refused.
20
+ const computerName = hostname()
21
+ .trim()
22
+ .replace(/\.local$/i, "")
23
+ .slice(0, 200);
24
+ const os = OS_NAMES[platform()];
25
+ return {
26
+ name: computerName ? `mateo CLI · ${computerName}` : "mateo CLI",
27
+ platform: os?.id ?? platform(),
28
+ ...(computerName ? { computerName } : {}),
29
+ ...(os ? { os: os.name } : {}),
30
+ };
31
+ }
32
+ export function resolveClientMateoHome(target, env = process.env) {
33
+ return target.kind === "instance" ? target.home : resolveMateoHome(env);
34
+ }
35
+ const DEFAULT_TIMEOUT = 15000;
36
+ export function getDaemonHost(options) {
37
+ return describeDaemonTarget(options.target);
38
+ }
39
+ export function buildDaemonConnectionCommandError(options) {
40
+ const error = options.error;
41
+ let message = error instanceof Error ? error.message : String(error);
42
+ if (error && typeof error === "object" && "message" in error)
43
+ message = String(error.message);
44
+ if (options.target.kind === "endpoint")
45
+ message = message.replaceAll(options.target.host, describeDaemonTarget(options.target));
46
+ if (message.startsWith("Cannot connect to daemon at "))
47
+ return error;
48
+ let code = "DAEMON_UNREACHABLE";
49
+ if (typeof error === "object" && error !== null && "code" in error)
50
+ code = String(error.code);
51
+ else if (message === "Password required")
52
+ code = "AUTH_REQUIRED";
53
+ else if (message === "Incorrect password")
54
+ code = "AUTH_FAILED";
55
+ return {
56
+ code,
57
+ message: `Cannot connect to daemon at ${describeDaemonTarget(options.target)}: ${message}`,
58
+ details: describeConnectionRemedy(code, options.target),
59
+ };
60
+ }
61
+ function describeConnectionRemedy(code, target) {
62
+ if (code === "AUTH_REQUIRED")
63
+ return "The daemon requires a password. Set MATEO_PASSWORD and retry.";
64
+ if (code === "AUTH_FAILED")
65
+ return "The daemon rejected the password. Check MATEO_PASSWORD and retry.";
66
+ if (target.kind === "instance")
67
+ return `Start with: mateo daemon start --home ${JSON.stringify(target.home)}`;
68
+ return "Check the selected endpoint and credentials. SSH transport does not install or start the daemon.";
69
+ }
70
+ export function normalizeDaemonHost(raw) {
71
+ const trimmed = raw.trim();
72
+ if (!trimmed) {
73
+ return null;
74
+ }
75
+ if (trimmed.startsWith("tcp://")) {
76
+ try {
77
+ const parsed = parseConnectionUri(trimmed);
78
+ const endpoint = normalizeHostPort(parsed.isIpv6 ? `[${parsed.host}]:${parsed.port}` : `${parsed.host}:${parsed.port}`);
79
+ const query = new URLSearchParams();
80
+ if (parsed.useTls) {
81
+ query.set("ssl", "true");
82
+ }
83
+ if (parsed.password) {
84
+ query.set("password", parsed.password);
85
+ }
86
+ const queryString = query.toString();
87
+ const suffix = queryString ? `?${queryString}` : "";
88
+ return `tcp://${endpoint}${suffix}`;
89
+ }
90
+ catch {
91
+ return null;
92
+ }
93
+ }
94
+ if (trimmed.startsWith("unix://") ||
95
+ trimmed.startsWith("pipe://") ||
96
+ trimmed.startsWith("\\\\.\\pipe\\")) {
97
+ return trimmed.startsWith("\\\\.\\pipe\\") ? `pipe://${trimmed}` : trimmed;
98
+ }
99
+ if (trimmed.startsWith("/") || trimmed.startsWith("~")) {
100
+ return `unix://${trimmed}`;
101
+ }
102
+ // Windows absolute paths (e.g. C:\Users\foo) are filesystem paths, not TCP or IPC targets.
103
+ if (/^[A-Za-z]:[/\\]/.test(trimmed)) {
104
+ return null;
105
+ }
106
+ if (/^\d+$/.test(trimmed)) {
107
+ return `127.0.0.1:${trimmed}`;
108
+ }
109
+ return trimmed.includes(":") ? trimmed : null;
110
+ }
111
+ function stripIpcPrefix(trimmed) {
112
+ if (trimmed.startsWith("unix://"))
113
+ return trimmed.slice("unix://".length).trim();
114
+ if (trimmed.startsWith("pipe://"))
115
+ return trimmed.slice("pipe://".length).trim();
116
+ return trimmed;
117
+ }
118
+ export function resolveDaemonTarget(host) {
119
+ const trimmed = normalizeDaemonHost(host);
120
+ if (!trimmed) {
121
+ throw new Error(`Invalid daemon target: ${host}`);
122
+ }
123
+ if (trimmed.startsWith("unix://") ||
124
+ trimmed.startsWith("pipe://") ||
125
+ trimmed.startsWith("\\\\.\\pipe\\")) {
126
+ const socketPath = stripIpcPrefix(trimmed);
127
+ if (!socketPath) {
128
+ throw new Error("Invalid IPC daemon target: missing socket path");
129
+ }
130
+ const isUnixSocket = trimmed.startsWith("unix://");
131
+ return {
132
+ type: "ipc",
133
+ url: isUnixSocket ? `ws+unix://${socketPath}:/ws` : "ws://localhost/ws",
134
+ socketPath,
135
+ };
136
+ }
137
+ if (trimmed.startsWith("tcp://")) {
138
+ const parsed = parseConnectionUri(trimmed);
139
+ const endpoint = normalizeHostPort(parsed.isIpv6 ? `[${parsed.host}]:${parsed.port}` : `${parsed.host}:${parsed.port}`);
140
+ return {
141
+ type: "tcp",
142
+ url: buildDaemonWebSocketUrl(endpoint, { useTls: parsed.useTls }),
143
+ };
144
+ }
145
+ return {
146
+ type: "tcp",
147
+ url: `ws://${trimmed}/ws`,
148
+ };
149
+ }
150
+ export function resolveDaemonPassword(host) {
151
+ const trimmed = host.trim();
152
+ if (trimmed.startsWith("tcp://")) {
153
+ const fromUri = parseConnectionUri(trimmed).password;
154
+ if (fromUri)
155
+ return fromUri;
156
+ }
157
+ const fromEnv = process.env.MATEO_PASSWORD;
158
+ return fromEnv && fromEnv.length > 0 ? fromEnv : undefined;
159
+ }
160
+ export function resolveDaemonCredential(host, home) {
161
+ const password = resolveDaemonPassword(host);
162
+ if (password)
163
+ return { kind: "password", password };
164
+ const token = readLocalCredentialForTarget(home, host);
165
+ return token ? { kind: "localCredential", token } : null;
166
+ }
167
+ /**
168
+ * Create a WebSocket factory that works in Node.js
169
+ */
170
+ function createNodeWebSocketFactory() {
171
+ return (url, options) => {
172
+ return new WebSocket(url, options?.protocols, {
173
+ headers: options?.headers,
174
+ ...(options?.socketPath ? { socketPath: options.socketPath } : {}),
175
+ });
176
+ };
177
+ }
178
+ /**
179
+ * Create and connect a daemon client
180
+ * Returns the connected client or throws if connection fails
181
+ */
182
+ async function tryConnectHost(host, credential, home, clientId, timeout, nodeWebSocketFactory) {
183
+ const target = resolveDaemonTarget(host);
184
+ const client = new DaemonClient({
185
+ url: target.url,
186
+ clientId,
187
+ clientType: "cli",
188
+ appVersion: resolveCliVersion(),
189
+ device: describeCliDevice(),
190
+ ...(credential?.kind === "password" ? { password: credential.password } : {}),
191
+ ...(credential?.kind === "localCredential"
192
+ ? { localCredential: () => readLocalCredentialForTarget(home, host) ?? undefined }
193
+ : {}),
194
+ connectTimeoutMs: timeout,
195
+ webSocketFactory: (url, config) => nodeWebSocketFactory(url, {
196
+ headers: config?.headers,
197
+ protocols: config?.protocols,
198
+ ...(target.type === "ipc" ? { socketPath: target.socketPath } : {}),
199
+ }),
200
+ reconnect: { enabled: false },
201
+ });
202
+ try {
203
+ await client.connect();
204
+ return { client };
205
+ }
206
+ catch (error) {
207
+ await client.close().catch(() => { });
208
+ return { error };
209
+ }
210
+ }
211
+ async function connectViaRelayOffer(offer, clientId, timeout, nodeWebSocketFactory) {
212
+ const url = buildRelayWebSocketUrl({
213
+ endpoint: offer.relay.endpoint,
214
+ serverId: offer.serverId,
215
+ role: "client",
216
+ useTls: offer.relay.useTls ?? shouldUseTlsForDefaultHostedRelay(offer.relay.endpoint),
217
+ });
218
+ const client = new DaemonClient({
219
+ url,
220
+ clientId,
221
+ clientType: "cli",
222
+ appVersion: resolveCliVersion(),
223
+ device: describeCliDevice(),
224
+ connectTimeoutMs: timeout,
225
+ webSocketFactory: (target, config) => nodeWebSocketFactory(target, { headers: config?.headers, protocols: config?.protocols }),
226
+ e2ee: { enabled: true, daemonPublicKeyB64: offer.daemonPublicKeyB64 },
227
+ reconnect: { enabled: false },
228
+ });
229
+ try {
230
+ await client.connect();
231
+ return client;
232
+ }
233
+ catch (error) {
234
+ await client.close().catch(() => { });
235
+ const message = error instanceof Error ? error.message : String(error);
236
+ const lastError = client.lastError ? ` (${client.lastError})` : "";
237
+ throw new Error(`Failed to connect via relay offer: ${message}${lastError}`, { cause: error });
238
+ }
239
+ }
240
+ function parseHostOfferOrNull(host) {
241
+ if (!host)
242
+ return null;
243
+ try {
244
+ return parseConnectionOfferFromUrl(host);
245
+ }
246
+ catch (error) {
247
+ const message = error instanceof Error ? error.message : String(error);
248
+ throw new Error(`Invalid pairing offer URL: ${message}`, { cause: error });
249
+ }
250
+ }
251
+ async function connectSelectedDaemon(options) {
252
+ const timeout = options.timeout ?? DEFAULT_TIMEOUT;
253
+ const deadline = Date.now() + timeout;
254
+ const explicitHost = options.target.kind === "endpoint"
255
+ ? options.target.host
256
+ : (await waitForDaemonReady(options.target.home, {
257
+ timeoutMs: timeout,
258
+ instance: options.instance,
259
+ })).listen;
260
+ const home = resolveClientMateoHome(options.target);
261
+ const clientId = await getOrCreateCliClientId(home);
262
+ const nodeWebSocketFactory = createNodeWebSocketFactory();
263
+ if (explicitHost?.trim().startsWith("ssh://")) {
264
+ const target = parseSshTransportUri(explicitHost.trim());
265
+ const tunnel = await createSshTunnel(target);
266
+ const password = resolveDaemonPassword(explicitHost);
267
+ const result = await tryConnectHost(tunnel.endpoint, password ? { kind: "password", password } : null, home, clientId, Math.max(1, deadline - Date.now()), nodeWebSocketFactory);
268
+ if ("client" in result) {
269
+ const close = result.client.close.bind(result.client);
270
+ result.client.close = async () => {
271
+ try {
272
+ await close();
273
+ }
274
+ finally {
275
+ tunnel.close();
276
+ }
277
+ };
278
+ return result.client;
279
+ }
280
+ const failure = tunnel.failureDetail();
281
+ tunnel.close();
282
+ if (failure)
283
+ throw new Error(`SSH connection failed: ${failure}`, { cause: result.error });
284
+ throw result.error;
285
+ }
286
+ const offer = parseHostOfferOrNull(explicitHost);
287
+ if (offer) {
288
+ return connectViaRelayOffer(offer, clientId, Math.max(1, deadline - Date.now()), nodeWebSocketFactory);
289
+ }
290
+ const result = await tryConnectHost(explicitHost, resolveDaemonCredential(explicitHost, home), home, clientId, Math.max(1, deadline - Date.now()), nodeWebSocketFactory);
291
+ if ("client" in result)
292
+ return result.client;
293
+ throw result.error;
294
+ }
295
+ export async function connectToDaemon(options) {
296
+ try {
297
+ return await connectSelectedDaemon(options);
298
+ }
299
+ catch (error) {
300
+ throw buildDaemonConnectionCommandError({ ...options, error });
301
+ }
302
+ }
303
+ /**
304
+ * Try to connect to the daemon, returns null if connection fails
305
+ */
306
+ export async function tryConnectToDaemon(options) {
307
+ try {
308
+ return await connectToDaemon(options);
309
+ }
310
+ catch {
311
+ return null;
312
+ }
313
+ }
314
+ const FULL_AGENT_UUID_PATTERN = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i;
315
+ /**
316
+ * Resolve an agent ID from a partial ID or name.
317
+ * Supports:
318
+ * - Full ID match
319
+ * - Prefix match (first N characters)
320
+ * - Title/name match (case-insensitive)
321
+ *
322
+ * Returns the full agent ID if found, null otherwise.
323
+ */
324
+ export function resolveAgentId(idOrName, agents) {
325
+ if (!idOrName || agents.length === 0) {
326
+ return null;
327
+ }
328
+ const query = idOrName.toLowerCase();
329
+ // A complete agent UUID is an exact identity, never a name search fallback.
330
+ if (FULL_AGENT_UUID_PATTERN.test(idOrName)) {
331
+ return agents.find((a) => a.id.toLowerCase() === query)?.id ?? null;
332
+ }
333
+ // Try exact ID match first
334
+ const exactMatch = agents.find((a) => a.id === idOrName);
335
+ if (exactMatch) {
336
+ return exactMatch.id;
337
+ }
338
+ // Try ID prefix match
339
+ const prefixMatches = agents.filter((a) => a.id.toLowerCase().startsWith(query));
340
+ if (prefixMatches.length === 1 && prefixMatches[0]) {
341
+ return prefixMatches[0].id;
342
+ }
343
+ // Try title/name match (case-insensitive)
344
+ const titleMatches = agents.filter((a) => a.title?.toLowerCase() === query);
345
+ if (titleMatches.length === 1 && titleMatches[0]) {
346
+ return titleMatches[0].id;
347
+ }
348
+ // Try partial title match
349
+ const partialTitleMatches = agents.filter((a) => a.title?.toLowerCase().includes(query));
350
+ if (partialTitleMatches.length === 1 && partialTitleMatches[0]) {
351
+ return partialTitleMatches[0].id;
352
+ }
353
+ // If we have multiple prefix matches and no unique title match, return first prefix match
354
+ const firstPrefixMatch = prefixMatches[0];
355
+ if (firstPrefixMatch) {
356
+ return firstPrefixMatch.id;
357
+ }
358
+ return null;
359
+ }
360
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1,8 @@
1
+ import type { Command } from "commander";
2
+ export declare function addLocalDaemonOptions<T extends Command>(command: T): T;
3
+ export declare function collectMultiple(value: string, previous: string[]): string[];
4
+ export declare function addJsonOption<T extends Command>(command: T): T;
5
+ export declare function addDaemonHostOption<T extends Command>(command: T): T;
6
+ export declare function addJsonAndDaemonHostOptions<T extends Command>(command: T): T;
7
+ export declare function withGlobalOptions<Args extends unknown[], Result>(handler: (...args: Args) => Result): (...args: Args) => Result;
8
+ //# sourceMappingURL=command-options.d.ts.map
@@ -0,0 +1,49 @@
1
+ import { selectDaemonTarget } from "./daemon-target.js";
2
+ const JSON_OPTION_DESCRIPTION = "Output in JSON format";
3
+ const DAEMON_HOST_OPTION_DESCRIPTION = "Explicit daemon endpoint: host:port, TCP, socket, SSH, or pairing URL (default: local home)";
4
+ const localCommands = new WeakSet();
5
+ export function addLocalDaemonOptions(command) {
6
+ localCommands.add(command);
7
+ command.option("--home <path>", "Local daemon home (default: ~/.mateo)");
8
+ return command;
9
+ }
10
+ export function collectMultiple(value, previous) {
11
+ return previous.concat([value]);
12
+ }
13
+ export function addJsonOption(command) {
14
+ command.option("--json", JSON_OPTION_DESCRIPTION);
15
+ return command;
16
+ }
17
+ export function addDaemonHostOption(command) {
18
+ command.option("--host <host>", DAEMON_HOST_OPTION_DESCRIPTION);
19
+ if (!command.options.some((option) => option.long === "--home"))
20
+ command.option("--home <path>", "Select a local daemon home (default: ~/.mateo)");
21
+ return command;
22
+ }
23
+ export function addJsonAndDaemonHostOptions(command) {
24
+ return addDaemonHostOption(addJsonOption(command));
25
+ }
26
+ export function withGlobalOptions(handler) {
27
+ return (...args) => {
28
+ const command = args.at(-1);
29
+ const mergedArgs = [...args];
30
+ const options = command.optsWithGlobals();
31
+ const selectors = { home: new Set(), host: new Set() };
32
+ for (let current = command; current; current = current.parent) {
33
+ for (const key of ["home", "host"]) {
34
+ const value = current.opts()[key];
35
+ if (typeof value === "string")
36
+ selectors[key].add(value);
37
+ }
38
+ }
39
+ for (const key of ["home", "host"]) {
40
+ if (selectors[key].size > 1)
41
+ throw { code: "TARGET_AMBIGUOUS", message: `Conflicting duplicate --${key} selectors.` };
42
+ }
43
+ const localOnly = localCommands.has(command);
44
+ options.daemonTarget = selectDaemonTarget(options, process.env, localOnly);
45
+ mergedArgs[mergedArgs.length - 2] = options;
46
+ return handler(...mergedArgs);
47
+ };
48
+ }
49
+ //# sourceMappingURL=command-options.js.map
@@ -0,0 +1,13 @@
1
+ export type DaemonTarget = {
2
+ kind: "instance";
3
+ home: string;
4
+ } | {
5
+ kind: "endpoint";
6
+ host: string;
7
+ };
8
+ export declare function selectDaemonTarget(options: {
9
+ home?: string;
10
+ host?: string;
11
+ }, env?: NodeJS.ProcessEnv, localOnly?: boolean): DaemonTarget;
12
+ export declare function describeDaemonTarget(target: DaemonTarget): string;
13
+ //# sourceMappingURL=daemon-target.d.ts.map
@@ -0,0 +1,51 @@
1
+ import { resolveMateoHome } from "@getmateo/server/daemon-control";
2
+ export function selectDaemonTarget(options, env = process.env, localOnly = false) {
3
+ for (const key of ["home", "host"]) {
4
+ if (options[key] !== undefined && !options[key].trim())
5
+ throw { code: "TARGET_INVALID", message: `--${key} requires a non-empty value.` };
6
+ }
7
+ if (options.home !== undefined && options.host !== undefined)
8
+ throw { code: "TARGET_AMBIGUOUS", message: "Choose either --home or --host, not both." };
9
+ if (localOnly) {
10
+ if (options.host !== undefined)
11
+ throw {
12
+ code: "LOCAL_OPERATION",
13
+ message: "This is a local operation; use --home. --host is not supported.",
14
+ };
15
+ return {
16
+ kind: "instance",
17
+ home: resolveMateoHome({ MATEO_HOME: options.home ?? env.MATEO_HOME }),
18
+ };
19
+ }
20
+ if (options.home !== undefined)
21
+ return { kind: "instance", home: resolveMateoHome({ MATEO_HOME: options.home }) };
22
+ if (options.host !== undefined)
23
+ return { kind: "endpoint", host: options.host };
24
+ if (env.MATEO_HOME && env.MATEO_HOST)
25
+ throw {
26
+ code: "TARGET_AMBIGUOUS",
27
+ message: "MATEO_HOME and MATEO_HOST are both set. Choose --home or --host explicitly.",
28
+ };
29
+ if (env.MATEO_HOST)
30
+ return { kind: "endpoint", host: env.MATEO_HOST };
31
+ return { kind: "instance", home: resolveMateoHome({ MATEO_HOME: env.MATEO_HOME }) };
32
+ }
33
+ export function describeDaemonTarget(target) {
34
+ if (target.kind === "instance")
35
+ return `home ${target.home}`;
36
+ try {
37
+ const url = new URL(target.host);
38
+ if (url.password)
39
+ url.password = "REDACTED";
40
+ for (const key of url.searchParams.keys())
41
+ if (/password|token|secret/i.test(key))
42
+ url.searchParams.set(key, "REDACTED");
43
+ if (url.hash)
44
+ url.hash = "REDACTED";
45
+ return url.toString();
46
+ }
47
+ catch {
48
+ return target.host.replace(/([?&](?:password|token|secret)=)[^&]*/gi, "$1REDACTED");
49
+ }
50
+ }
51
+ //# sourceMappingURL=daemon-target.js.map
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Parse duration string to milliseconds.
3
+ * Supports formats like: 5m, 30s, 1h, 2h30m, 1d, 90, etc.
4
+ * If no unit is specified, assumes seconds.
5
+ */
6
+ export declare function parseDuration(input: string): number;
7
+ //# sourceMappingURL=duration.d.ts.map
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Parse duration string to milliseconds.
3
+ * Supports formats like: 5m, 30s, 1h, 2h30m, 1d, 90, etc.
4
+ * If no unit is specified, assumes seconds.
5
+ */
6
+ export function parseDuration(input) {
7
+ const trimmed = input.trim();
8
+ // If it's just a number, treat as seconds
9
+ if (/^\d+$/.test(trimmed)) {
10
+ return parseInt(trimmed, 10) * 1000;
11
+ }
12
+ if (!/^(?:\d+[smhd])+$/.test(trimmed)) {
13
+ throw new Error(`Invalid duration format: ${input}. Use formats like: 5m, 30s, 1h, 2h30m, 1d`);
14
+ }
15
+ // Parse duration with units
16
+ let totalMs = 0;
17
+ const regex = /(\d+)([smhd])/g;
18
+ let match;
19
+ while ((match = regex.exec(trimmed)) !== null) {
20
+ const value = parseInt(match[1], 10);
21
+ const unit = match[2];
22
+ switch (unit) {
23
+ case "s":
24
+ totalMs += value * 1000;
25
+ break;
26
+ case "m":
27
+ totalMs += value * 60 * 1000;
28
+ break;
29
+ case "h":
30
+ totalMs += value * 60 * 60 * 1000;
31
+ break;
32
+ case "d":
33
+ totalMs += value * 24 * 60 * 60 * 1000;
34
+ break;
35
+ }
36
+ }
37
+ return totalMs;
38
+ }
39
+ //# sourceMappingURL=duration.js.map
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Convert unknown thrown values into a user-safe error string.
3
+ */
4
+ export declare function getErrorMessage(error: unknown): string;
5
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Convert unknown thrown values into a user-safe error string.
3
+ */
4
+ export function getErrorMessage(error) {
5
+ if (error instanceof Error) {
6
+ return error.message;
7
+ }
8
+ return String(error);
9
+ }
10
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Path utilities for cwd filtering in agent commands.
3
+ */
4
+ /**
5
+ * Check if `candidatePath` is the same directory as `basePath` or a descendant of it.
6
+ *
7
+ * Handles both Unix (/) and Windows (\) path separators, including mixed separators.
8
+ * This is important because agent cwd paths come from the agent's OS (could be Windows)
9
+ * while the CLI filter path comes from the user (could also be Windows or Unix).
10
+ */
11
+ export declare function isSameOrDescendantPath(basePath: string, candidatePath: string): boolean;
12
+ //# sourceMappingURL=paths.d.ts.map
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Path utilities for cwd filtering in agent commands.
3
+ */
4
+ /**
5
+ * Check if `candidatePath` is the same directory as `basePath` or a descendant of it.
6
+ *
7
+ * Handles both Unix (/) and Windows (\) path separators, including mixed separators.
8
+ * This is important because agent cwd paths come from the agent's OS (could be Windows)
9
+ * while the CLI filter path comes from the user (could also be Windows or Unix).
10
+ */
11
+ export function isSameOrDescendantPath(basePath, candidatePath) {
12
+ // Normalize both paths: replace all backslashes with forward slashes, strip trailing separator
13
+ let normalizedBase = basePath.replace(/\\/g, "/").replace(/\/$/, "");
14
+ let normalizedCandidate = candidatePath.replace(/\\/g, "/").replace(/\/$/, "");
15
+ // Windows paths are case-insensitive — detect by drive letter prefix (e.g. "C:/")
16
+ if (/^[a-zA-Z]:\//.test(normalizedBase) || /^[a-zA-Z]:\//.test(normalizedCandidate)) {
17
+ normalizedBase = normalizedBase.toLowerCase();
18
+ normalizedCandidate = normalizedCandidate.toLowerCase();
19
+ }
20
+ return (normalizedCandidate === normalizedBase || normalizedCandidate.startsWith(normalizedBase + "/"));
21
+ }
22
+ //# sourceMappingURL=paths.js.map
@@ -0,0 +1,11 @@
1
+ export interface ResolveProviderAndModelOptions {
2
+ provider?: string;
3
+ model?: string;
4
+ defaultProvider?: string;
5
+ }
6
+ export interface ResolvedProviderModel {
7
+ provider: string;
8
+ model: string | undefined;
9
+ }
10
+ export declare function resolveProviderAndModel(options: ResolveProviderAndModelOptions): ResolvedProviderModel;
11
+ //# sourceMappingURL=provider-model.d.ts.map