@getmateo/cli 0.0.0-stage → 0.19.7
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.
- package/LICENSE +211 -0
- package/bin/mateo +3 -0
- package/dist/classify.d.ts +19 -0
- package/dist/classify.js +49 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +143 -0
- package/dist/commands/agent/archive.d.ts +27 -0
- package/dist/commands/agent/archive.js +88 -0
- package/dist/commands/agent/attach.d.ts +8 -0
- package/dist/commands/agent/attach.js +160 -0
- package/dist/commands/agent/delete.d.ts +15 -0
- package/dist/commands/agent/delete.js +104 -0
- package/dist/commands/agent/detach.d.ts +16 -0
- package/dist/commands/agent/detach.js +44 -0
- package/dist/commands/agent/import.d.ts +14 -0
- package/dist/commands/agent/import.js +108 -0
- package/dist/commands/agent/index.d.ts +3 -0
- package/dist/commands/agent/index.js +56 -0
- package/dist/commands/agent/inspect.d.ts +15 -0
- package/dist/commands/agent/inspect.js +196 -0
- package/dist/commands/agent/logs.d.ts +39 -0
- package/dist/commands/agent/logs.js +369 -0
- package/dist/commands/agent/ls.d.ts +61 -0
- package/dist/commands/agent/ls.js +201 -0
- package/dist/commands/agent/mode.d.ts +18 -0
- package/dist/commands/agent/mode.js +100 -0
- package/dist/commands/agent/open.d.ts +11 -0
- package/dist/commands/agent/open.js +74 -0
- package/dist/commands/agent/reload.d.ts +25 -0
- package/dist/commands/agent/reload.js +64 -0
- package/dist/commands/agent/run.d.ts +77 -0
- package/dist/commands/agent/run.js +556 -0
- package/dist/commands/agent/send.d.ts +21 -0
- package/dist/commands/agent/send.js +187 -0
- package/dist/commands/agent/stop.d.ts +17 -0
- package/dist/commands/agent/stop.js +102 -0
- package/dist/commands/agent/update.d.ts +51 -0
- package/dist/commands/agent/update.js +173 -0
- package/dist/commands/agent/wait.d.ts +31 -0
- package/dist/commands/agent/wait.js +161 -0
- package/dist/commands/clone.d.ts +17 -0
- package/dist/commands/clone.js +59 -0
- package/dist/commands/daemon/config.d.ts +3 -0
- package/dist/commands/daemon/config.js +103 -0
- package/dist/commands/daemon/index.d.ts +3 -0
- package/dist/commands/daemon/index.js +28 -0
- package/dist/commands/daemon/local-daemon.d.ts +13 -0
- package/dist/commands/daemon/local-daemon.js +105 -0
- package/dist/commands/daemon/pair.d.ts +30 -0
- package/dist/commands/daemon/pair.js +145 -0
- package/dist/commands/daemon/reload.d.ts +12 -0
- package/dist/commands/daemon/reload.js +44 -0
- package/dist/commands/daemon/restart.d.ts +29 -0
- package/dist/commands/daemon/restart.js +169 -0
- package/dist/commands/daemon/runtime-toolchain.d.ts +6 -0
- package/dist/commands/daemon/runtime-toolchain.js +87 -0
- package/dist/commands/daemon/set-password.d.ts +17 -0
- package/dist/commands/daemon/set-password.js +89 -0
- package/dist/commands/daemon/start.d.ts +20 -0
- package/dist/commands/daemon/start.js +52 -0
- package/dist/commands/daemon/status.d.ts +13 -0
- package/dist/commands/daemon/status.js +119 -0
- package/dist/commands/daemon/stop.d.ts +20 -0
- package/dist/commands/daemon/stop.js +58 -0
- package/dist/commands/fleet/index.d.ts +4 -0
- package/dist/commands/fleet/index.js +57 -0
- package/dist/commands/heartbeat/index.d.ts +3 -0
- package/dist/commands/heartbeat/index.js +139 -0
- package/dist/commands/hooks.d.ts +19 -0
- package/dist/commands/hooks.js +89 -0
- package/dist/commands/hub/authority.d.ts +17 -0
- package/dist/commands/hub/authority.js +18 -0
- package/dist/commands/hub/connect.d.ts +24 -0
- package/dist/commands/hub/connect.js +44 -0
- package/dist/commands/hub/credentials.d.ts +21 -0
- package/dist/commands/hub/credentials.js +143 -0
- package/dist/commands/hub/daemon-client.d.ts +41 -0
- package/dist/commands/hub/daemon-client.js +14 -0
- package/dist/commands/hub/deploy-bundle.d.ts +16 -0
- package/dist/commands/hub/deploy-bundle.js +248 -0
- package/dist/commands/hub/deploy-triggers.d.ts +6 -0
- package/dist/commands/hub/deploy-triggers.js +116 -0
- package/dist/commands/hub/deploy.d.ts +50 -0
- package/dist/commands/hub/deploy.js +159 -0
- package/dist/commands/hub/disconnect.d.ts +17 -0
- package/dist/commands/hub/disconnect.js +24 -0
- package/dist/commands/hub/error.d.ts +6 -0
- package/dist/commands/hub/error.js +9 -0
- package/dist/commands/hub/export.d.ts +28 -0
- package/dist/commands/hub/export.js +80 -0
- package/dist/commands/hub/help.d.ts +3 -0
- package/dist/commands/hub/help.js +5 -0
- package/dist/commands/hub/hub-client/index.d.ts +22 -0
- package/dist/commands/hub/hub-client/index.js +135 -0
- package/dist/commands/hub/hub-client/internal/contracts.d.ts +126 -0
- package/dist/commands/hub/hub-client/internal/contracts.js +85 -0
- package/dist/commands/hub/hub-client/internal/problem.d.ts +3 -0
- package/dist/commands/hub/hub-client/internal/problem.js +85 -0
- package/dist/commands/hub/hub-client/internal/transport.d.ts +15 -0
- package/dist/commands/hub/hub-client/internal/transport.js +30 -0
- package/dist/commands/hub/index.d.ts +20 -0
- package/dist/commands/hub/index.js +94 -0
- package/dist/commands/hub/init-plan.d.ts +33 -0
- package/dist/commands/hub/init-plan.js +94 -0
- package/dist/commands/hub/init.d.ts +37 -0
- package/dist/commands/hub/init.js +525 -0
- package/dist/commands/hub/login-flow.d.ts +34 -0
- package/dist/commands/hub/login-flow.js +78 -0
- package/dist/commands/hub/login.d.ts +23 -0
- package/dist/commands/hub/login.js +40 -0
- package/dist/commands/hub/logout.d.ts +33 -0
- package/dist/commands/hub/logout.js +71 -0
- package/dist/commands/hub/origin.d.ts +2 -0
- package/dist/commands/hub/origin.js +27 -0
- package/dist/commands/hub/permissions.d.ts +22 -0
- package/dist/commands/hub/permissions.js +61 -0
- package/dist/commands/hub/projects.d.ts +24 -0
- package/dist/commands/hub/projects.js +49 -0
- package/dist/commands/hub/reporter.d.ts +10 -0
- package/dist/commands/hub/reporter.js +11 -0
- package/dist/commands/hub/starter-agent-runtime.d.ts +37 -0
- package/dist/commands/hub/starter-agent-runtime.js +49 -0
- package/dist/commands/hub/starter-trigger.d.ts +10 -0
- package/dist/commands/hub/starter-trigger.js +30 -0
- package/dist/commands/hub/status-output.d.ts +13 -0
- package/dist/commands/hub/status-output.js +30 -0
- package/dist/commands/onboard.d.ts +14 -0
- package/dist/commands/onboard.js +169 -0
- package/dist/commands/open.d.ts +4 -0
- package/dist/commands/open.js +91 -0
- package/dist/commands/permit/allow.d.ts +38 -0
- package/dist/commands/permit/allow.js +138 -0
- package/dist/commands/permit/deny.d.ts +13 -0
- package/dist/commands/permit/deny.js +100 -0
- package/dist/commands/permit/index.d.ts +3 -0
- package/dist/commands/permit/index.js +27 -0
- package/dist/commands/permit/ls.d.ts +21 -0
- package/dist/commands/permit/ls.js +54 -0
- package/dist/commands/plugin/index.d.ts +23 -0
- package/dist/commands/plugin/index.js +174 -0
- package/dist/commands/plugin/scaffold.d.ts +6 -0
- package/dist/commands/plugin/scaffold.js +212 -0
- package/dist/commands/plugin/shared.d.ts +7 -0
- package/dist/commands/plugin/shared.js +34 -0
- package/dist/commands/plugin/update.d.ts +37 -0
- package/dist/commands/plugin/update.js +58 -0
- package/dist/commands/project/create.d.ts +10 -0
- package/dist/commands/project/create.js +43 -0
- package/dist/commands/project/delete.d.ts +9 -0
- package/dist/commands/project/delete.js +35 -0
- package/dist/commands/project/index.d.ts +3 -0
- package/dist/commands/project/index.js +28 -0
- package/dist/commands/project/ls.d.ts +5 -0
- package/dist/commands/project/ls.js +19 -0
- package/dist/commands/project/rename.d.ts +15 -0
- package/dist/commands/project/rename.js +52 -0
- package/dist/commands/project/shared.d.ts +11 -0
- package/dist/commands/project/shared.js +18 -0
- package/dist/commands/provider/diagnostic.d.ts +12 -0
- package/dist/commands/provider/diagnostic.js +31 -0
- package/dist/commands/provider/index.d.ts +3 -0
- package/dist/commands/provider/index.js +21 -0
- package/dist/commands/provider/ls.d.ts +19 -0
- package/dist/commands/provider/ls.js +46 -0
- package/dist/commands/provider/models.d.ts +20 -0
- package/dist/commands/provider/models.js +53 -0
- package/dist/commands/schedule/create.d.ts +19 -0
- package/dist/commands/schedule/create.js +41 -0
- package/dist/commands/schedule/delete.d.ts +10 -0
- package/dist/commands/schedule/delete.js +32 -0
- package/dist/commands/schedule/index.d.ts +3 -0
- package/dist/commands/schedule/index.js +66 -0
- package/dist/commands/schedule/inspect.d.ts +6 -0
- package/dist/commands/schedule/inspect.js +27 -0
- package/dist/commands/schedule/logs.d.ts +6 -0
- package/dist/commands/schedule/logs.js +24 -0
- package/dist/commands/schedule/ls.d.ts +5 -0
- package/dist/commands/schedule/ls.js +25 -0
- package/dist/commands/schedule/pause.d.ts +5 -0
- package/dist/commands/schedule/pause.js +24 -0
- package/dist/commands/schedule/resume.d.ts +5 -0
- package/dist/commands/schedule/resume.js +24 -0
- package/dist/commands/schedule/run-once.d.ts +5 -0
- package/dist/commands/schedule/run-once.js +24 -0
- package/dist/commands/schedule/schema.d.ts +21 -0
- package/dist/commands/schedule/schema.js +67 -0
- package/dist/commands/schedule/shared.d.ts +61 -0
- package/dist/commands/schedule/shared.js +360 -0
- package/dist/commands/schedule/types.d.ts +165 -0
- package/dist/commands/schedule/types.js +2 -0
- package/dist/commands/schedule/update.d.ts +19 -0
- package/dist/commands/schedule/update.js +40 -0
- package/dist/commands/script/index.d.ts +3 -0
- package/dist/commands/script/index.js +19 -0
- package/dist/commands/script/ls.d.ts +6 -0
- package/dist/commands/script/ls.js +20 -0
- package/dist/commands/script/schema.d.ts +5 -0
- package/dist/commands/script/schema.js +13 -0
- package/dist/commands/script/shared.d.ts +12 -0
- package/dist/commands/script/shared.js +59 -0
- package/dist/commands/script/start.d.ts +6 -0
- package/dist/commands/script/start.js +23 -0
- package/dist/commands/script/stop.d.ts +6 -0
- package/dist/commands/script/stop.js +23 -0
- package/dist/commands/terminal/capture.d.ts +10 -0
- package/dist/commands/terminal/capture.js +67 -0
- package/dist/commands/terminal/create.d.ts +11 -0
- package/dist/commands/terminal/create.js +29 -0
- package/dist/commands/terminal/index.d.ts +3 -0
- package/dist/commands/terminal/index.js +51 -0
- package/dist/commands/terminal/kill.d.ts +6 -0
- package/dist/commands/terminal/kill.js +36 -0
- package/dist/commands/terminal/ls.d.ts +11 -0
- package/dist/commands/terminal/ls.js +21 -0
- package/dist/commands/terminal/schema.d.ts +10 -0
- package/dist/commands/terminal/schema.js +17 -0
- package/dist/commands/terminal/send-keys.d.ts +7 -0
- package/dist/commands/terminal/send-keys.js +44 -0
- package/dist/commands/terminal/shared.d.ts +13 -0
- package/dist/commands/terminal/shared.js +64 -0
- package/dist/commands/terminal/upgrade-hosts.d.ts +11 -0
- package/dist/commands/terminal/upgrade-hosts.js +46 -0
- package/dist/commands/usage/index.d.ts +29 -0
- package/dist/commands/usage/index.js +62 -0
- package/dist/commands/usage/presentation.d.ts +4 -0
- package/dist/commands/usage/presentation.js +146 -0
- package/dist/commands/workspace/archive.d.ts +13 -0
- package/dist/commands/workspace/archive.js +43 -0
- package/dist/commands/workspace/create.d.ts +50 -0
- package/dist/commands/workspace/create.js +132 -0
- package/dist/commands/workspace/index.d.ts +3 -0
- package/dist/commands/workspace/index.js +50 -0
- package/dist/commands/workspace/ls.d.ts +11 -0
- package/dist/commands/workspace/ls.js +33 -0
- package/dist/commands/workspace/rename.d.ts +23 -0
- package/dist/commands/workspace/rename.js +63 -0
- package/dist/commands/workspace/setup.d.ts +12 -0
- package/dist/commands/workspace/setup.js +41 -0
- package/dist/commands/workspace/shared.d.ts +15 -0
- package/dist/commands/workspace/shared.js +29 -0
- package/dist/commands/worktree/archive.d.ts +21 -0
- package/dist/commands/worktree/archive.js +108 -0
- package/dist/commands/worktree/create-input.d.ts +15 -0
- package/dist/commands/worktree/create-input.js +56 -0
- package/dist/commands/worktree/create.d.ts +11 -0
- package/dist/commands/worktree/create.js +50 -0
- package/dist/commands/worktree/index.d.ts +3 -0
- package/dist/commands/worktree/index.js +29 -0
- package/dist/commands/worktree/ls.d.ts +18 -0
- package/dist/commands/worktree/ls.js +73 -0
- package/dist/commands/worktree/repository-directory.d.ts +6 -0
- package/dist/commands/worktree/repository-directory.js +9 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +6 -0
- package/dist/output/index.d.ts +45 -0
- package/dist/output/index.js +47 -0
- package/dist/output/json.d.ts +11 -0
- package/dist/output/json.js +37 -0
- package/dist/output/pairing.d.ts +9 -0
- package/dist/output/pairing.js +36 -0
- package/dist/output/quiet.d.ts +9 -0
- package/dist/output/quiet.js +22 -0
- package/dist/output/render.d.ts +15 -0
- package/dist/output/render.js +84 -0
- package/dist/output/table.d.ts +13 -0
- package/dist/output/table.js +135 -0
- package/dist/output/types.d.ts +73 -0
- package/dist/output/types.js +8 -0
- package/dist/output/with-output.d.ts +43 -0
- package/dist/output/with-output.js +85 -0
- package/dist/output/yaml.d.ts +11 -0
- package/dist/output/yaml.js +38 -0
- package/dist/run.d.ts +14 -0
- package/dist/run.js +62 -0
- package/dist/ssh/ssh-tunnel.d.ts +2 -0
- package/dist/ssh/ssh-tunnel.js +3 -0
- package/dist/utils/agent-directory.d.ts +31 -0
- package/dist/utils/agent-directory.js +48 -0
- package/dist/utils/caller-agent.d.ts +14 -0
- package/dist/utils/caller-agent.js +16 -0
- package/dist/utils/client-id.d.ts +2 -0
- package/dist/utils/client-id.js +31 -0
- package/dist/utils/client.d.ts +57 -0
- package/dist/utils/client.js +360 -0
- package/dist/utils/command-options.d.ts +8 -0
- package/dist/utils/command-options.js +49 -0
- package/dist/utils/daemon-target.d.ts +13 -0
- package/dist/utils/daemon-target.js +51 -0
- package/dist/utils/duration.d.ts +7 -0
- package/dist/utils/duration.js +39 -0
- package/dist/utils/errors.d.ts +5 -0
- package/dist/utils/errors.js +10 -0
- package/dist/utils/paths.d.ts +12 -0
- package/dist/utils/paths.js +22 -0
- package/dist/utils/provider-model.d.ts +11 -0
- package/dist/utils/provider-model.js +49 -0
- package/dist/utils/timeline.d.ts +12 -0
- package/dist/utils/timeline.js +16 -0
- package/dist/utils/wait-for-stop.d.ts +2 -0
- package/dist/utils/wait-for-stop.js +28 -0
- package/dist/version.d.ts +5 -0
- package/dist/version.js +24 -0
- package/package.json +58 -4
- package/README.md +0 -3
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { connectToDaemon } from "../../utils/client.js";
|
|
2
|
+
import { fetchAgentTimelineItems, formatAgentActivityTranscript } from "./logs.js";
|
|
3
|
+
import { parseDuration } from "../../utils/duration.js";
|
|
4
|
+
/** Schema for agent wait output */
|
|
5
|
+
export const agentWaitSchema = {
|
|
6
|
+
idField: "agentId",
|
|
7
|
+
columns: [
|
|
8
|
+
{ header: "AGENT ID", field: "agentId", width: 12 },
|
|
9
|
+
{ header: "STATUS", field: "status", width: 12 },
|
|
10
|
+
{ header: "MESSAGE", field: "message", width: 40 },
|
|
11
|
+
],
|
|
12
|
+
};
|
|
13
|
+
const WAIT_ACTIVITY_PREVIEW_COUNT = 5;
|
|
14
|
+
const WAIT_ACTIVITY_PREVIEW_TIMEOUT_MS = 2000;
|
|
15
|
+
function appendRecentActivity(message, transcript) {
|
|
16
|
+
if (!transcript || transcript.trim().length === 0) {
|
|
17
|
+
return message;
|
|
18
|
+
}
|
|
19
|
+
return `${message}\nLast ${WAIT_ACTIVITY_PREVIEW_COUNT} activity items:\n${transcript}`;
|
|
20
|
+
}
|
|
21
|
+
async function getRecentActivityTranscript(client, agentId) {
|
|
22
|
+
try {
|
|
23
|
+
const timelineItems = await fetchAgentTimelineItems(client, agentId, {
|
|
24
|
+
timeoutMs: WAIT_ACTIVITY_PREVIEW_TIMEOUT_MS,
|
|
25
|
+
});
|
|
26
|
+
return formatAgentActivityTranscript(timelineItems, WAIT_ACTIVITY_PREVIEW_COUNT);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function parseWaitTimeout(timeout) {
|
|
33
|
+
if (!timeout)
|
|
34
|
+
return { timeoutMs: 0, timeoutLabel: null };
|
|
35
|
+
try {
|
|
36
|
+
const ms = parseDuration(timeout);
|
|
37
|
+
if (ms <= 0) {
|
|
38
|
+
throw new Error("Timeout must be positive");
|
|
39
|
+
}
|
|
40
|
+
const timeoutSeconds = Math.floor(ms / 1000);
|
|
41
|
+
return {
|
|
42
|
+
timeoutMs: ms,
|
|
43
|
+
timeoutLabel: `${timeoutSeconds} second${timeoutSeconds === 1 ? "" : "s"}`,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
if (err && typeof err === "object" && "code" in err)
|
|
48
|
+
throw err;
|
|
49
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
50
|
+
throw {
|
|
51
|
+
code: "INVALID_TIMEOUT",
|
|
52
|
+
message: "Invalid timeout value",
|
|
53
|
+
details: message,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Turn the daemon's wait reply into the command result. Throws AGENT_NOT_FOUND when the
|
|
59
|
+
* daemon resolved no agent: it answers an unknown identifier with an error and no agent
|
|
60
|
+
* payload, while an agent that finished in error always comes with its payload.
|
|
61
|
+
*/
|
|
62
|
+
export function buildWaitResult(args) {
|
|
63
|
+
const { state, resolvedAgentId, recentActivity, timeoutLabel } = args;
|
|
64
|
+
if (state.status === "timeout") {
|
|
65
|
+
const timeoutMessage = timeoutLabel
|
|
66
|
+
? `Agent did not finish within ${timeoutLabel}. Run \`mateo wait ${resolvedAgentId}\` again to keep waiting.`
|
|
67
|
+
: `Agent wait timed out. Run \`mateo wait ${resolvedAgentId}\` again to keep waiting.`;
|
|
68
|
+
return {
|
|
69
|
+
agentId: resolvedAgentId,
|
|
70
|
+
status: "timeout",
|
|
71
|
+
message: appendRecentActivity(timeoutMessage, recentActivity),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (state.status === "permission") {
|
|
75
|
+
const permission = state.final?.pendingPermissions?.[0];
|
|
76
|
+
return {
|
|
77
|
+
agentId: resolvedAgentId,
|
|
78
|
+
status: "permission",
|
|
79
|
+
message: permission
|
|
80
|
+
? `Agent is waiting for permission: ${permission.kind}`
|
|
81
|
+
: "Agent is waiting for permission",
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (state.status === "error") {
|
|
85
|
+
if (state.final === null) {
|
|
86
|
+
throw {
|
|
87
|
+
code: "AGENT_NOT_FOUND",
|
|
88
|
+
message: state.error ?? `Agent not found: ${resolvedAgentId}`,
|
|
89
|
+
details: "Use `mateo ls` to list available agents",
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
agentId: resolvedAgentId,
|
|
94
|
+
status: "error",
|
|
95
|
+
message: state.error ?? "Agent finished with error",
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
agentId: resolvedAgentId,
|
|
100
|
+
status: "idle",
|
|
101
|
+
message: appendRecentActivity("Agent is idle.", recentActivity),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
export function addWaitOptions(cmd) {
|
|
105
|
+
return cmd
|
|
106
|
+
.description("Wait for an agent to become idle")
|
|
107
|
+
.argument("<id>", "Agent ID (or prefix)")
|
|
108
|
+
.option("--timeout <seconds>", "Maximum wait time (default: no limit)");
|
|
109
|
+
}
|
|
110
|
+
export async function runWaitCommand(agentIdArg, options, _command) {
|
|
111
|
+
if (!agentIdArg || agentIdArg.trim().length === 0) {
|
|
112
|
+
throw {
|
|
113
|
+
code: "MISSING_AGENT_ID",
|
|
114
|
+
message: "Agent ID is required",
|
|
115
|
+
details: "Usage: mateo agent wait <id>",
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
const { timeoutMs, timeoutLabel } = parseWaitTimeout(options.timeout);
|
|
119
|
+
const client = await connectToDaemon({ target: options.daemonTarget });
|
|
120
|
+
let reply;
|
|
121
|
+
try {
|
|
122
|
+
try {
|
|
123
|
+
const state = await client.waitForFinish(agentIdArg, timeoutMs);
|
|
124
|
+
const resolvedAgentId = state.final?.id ?? agentIdArg;
|
|
125
|
+
const recentActivity = state.status === "timeout" || state.status === "idle"
|
|
126
|
+
? await getRecentActivityTranscript(client, resolvedAgentId)
|
|
127
|
+
: null;
|
|
128
|
+
await client.close();
|
|
129
|
+
reply = { state, resolvedAgentId, recentActivity };
|
|
130
|
+
}
|
|
131
|
+
catch (waitErr) {
|
|
132
|
+
await client.close().catch(() => { });
|
|
133
|
+
const waitMessage = waitErr instanceof Error ? waitErr.message : String(waitErr);
|
|
134
|
+
// Other errors
|
|
135
|
+
const error = {
|
|
136
|
+
code: "WAIT_FAILED",
|
|
137
|
+
message: `Failed to wait for agent: ${waitMessage}`,
|
|
138
|
+
};
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
catch (err) {
|
|
143
|
+
await client.close().catch(() => { });
|
|
144
|
+
// Re-throw CommandError as-is
|
|
145
|
+
if (err && typeof err === "object" && "code" in err) {
|
|
146
|
+
throw err;
|
|
147
|
+
}
|
|
148
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
149
|
+
const error = {
|
|
150
|
+
code: "WAIT_FAILED",
|
|
151
|
+
message: `Failed to wait for agent: ${message}`,
|
|
152
|
+
};
|
|
153
|
+
throw error;
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
type: "single",
|
|
157
|
+
data: buildWaitResult({ ...reply, timeoutLabel }),
|
|
158
|
+
schema: agentWaitSchema,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=wait.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
import type { OutputSchema, SingleResult } from "../output/index.js";
|
|
3
|
+
import type { CommandOptions } from "../output/with-output.js";
|
|
4
|
+
type CloneProtocol = "https" | "ssh";
|
|
5
|
+
interface CloneCommandOptions extends CommandOptions {
|
|
6
|
+
protocol?: CloneProtocol;
|
|
7
|
+
}
|
|
8
|
+
export interface CloneResult {
|
|
9
|
+
repo: string;
|
|
10
|
+
checkoutPath: string;
|
|
11
|
+
projectId: string;
|
|
12
|
+
projectName: string;
|
|
13
|
+
}
|
|
14
|
+
export declare const cloneSchema: OutputSchema<CloneResult>;
|
|
15
|
+
export declare function runCloneCommand(repo: string, options: CloneCommandOptions, _command: Command): Promise<SingleResult<CloneResult>>;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=clone.d.ts.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { isCompleteGitRemote } from "@getmateo/protocol/git-remote";
|
|
2
|
+
import { connectToDaemon } from "../utils/client.js";
|
|
3
|
+
export const cloneSchema = {
|
|
4
|
+
idField: "projectId",
|
|
5
|
+
columns: [
|
|
6
|
+
{ header: "REPO", field: "repo", width: 28 },
|
|
7
|
+
{ header: "PROJECT", field: "projectName", width: 28 },
|
|
8
|
+
{ header: "PATH", field: "checkoutPath", width: 56 },
|
|
9
|
+
],
|
|
10
|
+
};
|
|
11
|
+
function cmdError(code, message, details) {
|
|
12
|
+
return details ? { code, message, details } : { code, message };
|
|
13
|
+
}
|
|
14
|
+
export async function runCloneCommand(repo, options, _command) {
|
|
15
|
+
const targetDirectory = typeof options.dir === "string" ? options.dir.trim() : "";
|
|
16
|
+
if (!targetDirectory) {
|
|
17
|
+
throw cmdError("INVALID_ARGUMENT", "--dir is required");
|
|
18
|
+
}
|
|
19
|
+
const repoIsCompleteRemote = isCompleteGitRemote(repo);
|
|
20
|
+
if (!repoIsCompleteRemote && !options.protocol) {
|
|
21
|
+
throw cmdError("INVALID_ARGUMENT", "--protocol is required for owner/repo repository names");
|
|
22
|
+
}
|
|
23
|
+
const client = await connectToDaemon({ target: options.daemonTarget });
|
|
24
|
+
if (client.getLastServerInfoMessage()?.features?.projectGithubClone !== true) {
|
|
25
|
+
await client.close().catch(() => { });
|
|
26
|
+
throw cmdError("UNSUPPORTED_BY_HOST", "This daemon does not support cloning GitHub repos.", "Update the host to a newer Mateo version.");
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
const response = await client.cloneGithubProject({
|
|
30
|
+
repo,
|
|
31
|
+
targetDirectory,
|
|
32
|
+
...(repoIsCompleteRemote ? {} : { cloneProtocol: options.protocol }),
|
|
33
|
+
});
|
|
34
|
+
if (response.error || !response.project || !response.checkoutPath) {
|
|
35
|
+
throw cmdError("CLONE_FAILED", `Failed to clone GitHub repo: ${response.error ?? "no project returned"}`);
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
type: "single",
|
|
39
|
+
data: {
|
|
40
|
+
repo: response.repo,
|
|
41
|
+
checkoutPath: response.checkoutPath,
|
|
42
|
+
projectId: response.project.projectId,
|
|
43
|
+
projectName: response.project.projectDisplayName,
|
|
44
|
+
},
|
|
45
|
+
schema: cloneSchema,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
if (err && typeof err === "object" && "code" in err) {
|
|
50
|
+
throw err;
|
|
51
|
+
}
|
|
52
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
53
|
+
throw cmdError("CLONE_FAILED", `Failed to clone GitHub repo: ${message}`);
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
await client.close().catch(() => { });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=clone.js.map
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { addLocalDaemonOptions } from "../../utils/command-options.js";
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import { readDaemonInstance } from "@getmateo/server/daemon-control";
|
|
4
|
+
import { readPersistedConfig, getPersistedConfigValue, editPersistedConfig, } from "@getmateo/server/configuration";
|
|
5
|
+
import { connectToDaemon } from "../../utils/client.js";
|
|
6
|
+
import { withOutput } from "../../output/index.js";
|
|
7
|
+
function redact(value) {
|
|
8
|
+
if (Array.isArray(value))
|
|
9
|
+
return value.map(redact);
|
|
10
|
+
if (!value || typeof value !== "object")
|
|
11
|
+
return value;
|
|
12
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [
|
|
13
|
+
key,
|
|
14
|
+
/password|(?:api|private|access)[_-]?key|token|secret|authorization/i.test(key)
|
|
15
|
+
? "[redacted]"
|
|
16
|
+
: redact(item),
|
|
17
|
+
]));
|
|
18
|
+
}
|
|
19
|
+
function result(data) {
|
|
20
|
+
return {
|
|
21
|
+
type: "single",
|
|
22
|
+
data,
|
|
23
|
+
schema: {
|
|
24
|
+
idField: () => "configuration",
|
|
25
|
+
columns: [],
|
|
26
|
+
renderHuman: () => JSON.stringify(data, null, 2),
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function homeOf(options) {
|
|
31
|
+
if (options.daemonTarget.kind !== "instance")
|
|
32
|
+
throw new Error("Configuration edits require --home");
|
|
33
|
+
return options.daemonTarget.home;
|
|
34
|
+
}
|
|
35
|
+
async function applySaved(home, options) {
|
|
36
|
+
const nextCommand = `mateo daemon start --home ${JSON.stringify(home)}`;
|
|
37
|
+
const instance = await readDaemonInstance(home);
|
|
38
|
+
if (!instance?.listen)
|
|
39
|
+
return result({
|
|
40
|
+
action: "saved",
|
|
41
|
+
applied: false,
|
|
42
|
+
message: "Saved; not applied to a running daemon",
|
|
43
|
+
nextCommand,
|
|
44
|
+
});
|
|
45
|
+
let client;
|
|
46
|
+
try {
|
|
47
|
+
client = await connectToDaemon({ target: options.daemonTarget, timeout: 1500 });
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return result({
|
|
51
|
+
action: "saved",
|
|
52
|
+
applied: false,
|
|
53
|
+
message: "Saved; not applied to a running daemon",
|
|
54
|
+
nextCommand: `mateo daemon reload --home ${JSON.stringify(home)}`,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
const reload = await client.reloadDaemonConfig();
|
|
59
|
+
return result({ action: "saved", ...reload });
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
throw { code: "CONFIG_SAVED_RELOAD_FAILED", message: `Saved; reload failed: ${String(error)}` };
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
await client.close();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
export function daemonConfigCommand() {
|
|
69
|
+
const config = new Command("config").description("Read or edit persistent local configuration (local operation)");
|
|
70
|
+
addLocalDaemonOptions(config.command("get [path]")).action(withOutput(async (field, options, _command) => {
|
|
71
|
+
const persisted = readPersistedConfig(homeOf(options));
|
|
72
|
+
const value = field ? getPersistedConfigValue(persisted, field) : persisted;
|
|
73
|
+
return result({
|
|
74
|
+
source: "configured",
|
|
75
|
+
path: field ?? null,
|
|
76
|
+
set: value !== undefined,
|
|
77
|
+
value: field && /password|(?:api|private|access)[_-]?key|token|secret|authorization/i.test(field)
|
|
78
|
+
? "[redacted]"
|
|
79
|
+
: redact(value),
|
|
80
|
+
});
|
|
81
|
+
}));
|
|
82
|
+
addLocalDaemonOptions(config.command("set <path> <value>"))
|
|
83
|
+
.option("--string", "Interpret value literally as a string")
|
|
84
|
+
.action(withOutput(async (field, raw, options, _command) => {
|
|
85
|
+
let value = raw;
|
|
86
|
+
if (!options.string) {
|
|
87
|
+
try {
|
|
88
|
+
value = JSON.parse(raw);
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
/* Unquoted input is a string. */
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
editPersistedConfig(homeOf(options), field, { value });
|
|
95
|
+
return applySaved(homeOf(options), options);
|
|
96
|
+
}));
|
|
97
|
+
addLocalDaemonOptions(config.command("unset <path>")).action(withOutput(async (field, options, _command) => {
|
|
98
|
+
editPersistedConfig(homeOf(options), field, { unset: true });
|
|
99
|
+
return applySaved(homeOf(options), options);
|
|
100
|
+
}));
|
|
101
|
+
return config;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { startCommand, daemonRunCommand } from "./start.js";
|
|
3
|
+
import { daemonStatusCommand } from "./status.js";
|
|
4
|
+
import { daemonStopCommand } from "./stop.js";
|
|
5
|
+
import { daemonRestartCommand } from "./restart.js";
|
|
6
|
+
import { runSetPasswordCommand } from "./set-password.js";
|
|
7
|
+
import { pairCommand } from "./pair.js";
|
|
8
|
+
import { daemonReloadCommand } from "./reload.js";
|
|
9
|
+
import { daemonConfigCommand } from "./config.js";
|
|
10
|
+
import { withOutput } from "../../output/index.js";
|
|
11
|
+
import { addJsonOption, addLocalDaemonOptions } from "../../utils/command-options.js";
|
|
12
|
+
export function createDaemonCommand() {
|
|
13
|
+
const daemon = new Command("daemon").description("Manage the Mateo daemon");
|
|
14
|
+
for (const command of [
|
|
15
|
+
startCommand(),
|
|
16
|
+
daemonRunCommand(),
|
|
17
|
+
daemonStatusCommand(),
|
|
18
|
+
daemonStopCommand(),
|
|
19
|
+
daemonRestartCommand(),
|
|
20
|
+
daemonReloadCommand(),
|
|
21
|
+
pairCommand(),
|
|
22
|
+
daemonConfigCommand(),
|
|
23
|
+
])
|
|
24
|
+
daemon.addCommand(command);
|
|
25
|
+
addJsonOption(addLocalDaemonOptions(daemon.command("set-password").description("Save a hashed daemon password (local operation)"))).action(withOutput(runSetPasswordCommand));
|
|
26
|
+
return daemon;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
export declare function launchLocalDaemon(options: {
|
|
3
|
+
home: string;
|
|
4
|
+
timeoutMs?: number;
|
|
5
|
+
foreground?: boolean;
|
|
6
|
+
}): Promise<{
|
|
7
|
+
instance: import("@getmateo/server/daemon-control").DaemonInstance;
|
|
8
|
+
spawned: boolean;
|
|
9
|
+
exitCode?: number;
|
|
10
|
+
}>;
|
|
11
|
+
export declare function parseTimeoutMs(raw: unknown, fallback?: number): number;
|
|
12
|
+
export declare function rejectRemovedLaunchFlags(command: Command): Command;
|
|
13
|
+
//# sourceMappingURL=local-daemon.d.ts.map
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Option } from "commander";
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { startDaemonInstance, resolveMateoHome } from "@getmateo/server/daemon-control";
|
|
6
|
+
const require = createRequire(import.meta.url);
|
|
7
|
+
function resolveServerRunnerFromDir(currentDir) {
|
|
8
|
+
const packageJsonPath = path.join(currentDir, "package.json");
|
|
9
|
+
if (!existsSync(packageJsonPath))
|
|
10
|
+
return null;
|
|
11
|
+
try {
|
|
12
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
|
13
|
+
if (packageJson.name !== "@getmateo/server")
|
|
14
|
+
return null;
|
|
15
|
+
const distRunner = path.join(currentDir, "dist", "scripts", "supervisor-entrypoint.js");
|
|
16
|
+
if (existsSync(distRunner)) {
|
|
17
|
+
return distRunner;
|
|
18
|
+
}
|
|
19
|
+
return path.join(currentDir, "scripts", "supervisor-entrypoint.ts");
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function resolveDaemonRunnerEntry() {
|
|
26
|
+
const serverExportPath = require.resolve("@getmateo/server");
|
|
27
|
+
let currentDir = path.dirname(serverExportPath);
|
|
28
|
+
while (true) {
|
|
29
|
+
const entry = resolveServerRunnerFromDir(currentDir);
|
|
30
|
+
if (entry) {
|
|
31
|
+
return entry;
|
|
32
|
+
}
|
|
33
|
+
const parentDir = path.dirname(currentDir);
|
|
34
|
+
if (parentDir === currentDir) {
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
currentDir = parentDir;
|
|
38
|
+
}
|
|
39
|
+
throw new Error("Unable to resolve @getmateo/server package root for daemon runner");
|
|
40
|
+
}
|
|
41
|
+
export async function launchLocalDaemon(options) {
|
|
42
|
+
const abort = new AbortController();
|
|
43
|
+
const cancel = () => abort.abort();
|
|
44
|
+
process.once("SIGINT", cancel);
|
|
45
|
+
process.once("SIGTERM", cancel);
|
|
46
|
+
try {
|
|
47
|
+
const entry = resolveDaemonRunnerEntry();
|
|
48
|
+
return await startDaemonInstance({
|
|
49
|
+
home: resolveMateoHome({ MATEO_HOME: options.home }),
|
|
50
|
+
command: process.execPath,
|
|
51
|
+
args: [...(entry.endsWith(".ts") ? ["--import", "tsx"] : []), entry],
|
|
52
|
+
env: process.env,
|
|
53
|
+
mode: options.foreground ? "deployment" : "managed",
|
|
54
|
+
foreground: options.foreground,
|
|
55
|
+
timeoutMs: options.timeoutMs,
|
|
56
|
+
signal: abort.signal,
|
|
57
|
+
onReady: options.foreground
|
|
58
|
+
? (instance) => process.stdout.write(`Listening on ${instance.listen} (PID ${instance.pid})\n`)
|
|
59
|
+
: undefined,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
process.removeListener("SIGINT", cancel);
|
|
64
|
+
process.removeListener("SIGTERM", cancel);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export function parseTimeoutMs(raw, fallback = 600000) {
|
|
68
|
+
if (raw === undefined)
|
|
69
|
+
return fallback;
|
|
70
|
+
const seconds = Number(raw);
|
|
71
|
+
if (!Number.isFinite(seconds) || seconds <= 0)
|
|
72
|
+
throw { code: "INVALID_TIMEOUT", message: "Timeout must be a positive number of seconds." };
|
|
73
|
+
return Math.ceil(seconds * 1000);
|
|
74
|
+
}
|
|
75
|
+
const REMOVED_LAUNCH_FLAGS = {
|
|
76
|
+
"--port <port>": "daemon.listen",
|
|
77
|
+
"--listen <listen>": "daemon.listen",
|
|
78
|
+
"--relay": "daemon.relay.enabled",
|
|
79
|
+
"--no-relay": "daemon.relay.enabled",
|
|
80
|
+
"--relay-use-tls": "daemon.relay.useTls",
|
|
81
|
+
"--no-mcp": "daemon.mcp.enabled",
|
|
82
|
+
"--no-inject-mcp": "daemon.mcp.injectIntoAgents",
|
|
83
|
+
"--web-ui": "features.webUi.enabled",
|
|
84
|
+
"--no-web-ui": "features.webUi.enabled",
|
|
85
|
+
"--hostnames <hosts>": "daemon.hostnames",
|
|
86
|
+
"--allowed-hosts <hosts>": "daemon.hostnames",
|
|
87
|
+
"--foreground": "",
|
|
88
|
+
};
|
|
89
|
+
export function rejectRemovedLaunchFlags(command) {
|
|
90
|
+
for (const flag of Object.keys(REMOVED_LAUNCH_FLAGS))
|
|
91
|
+
command.addOption(new Option(flag).hideHelp());
|
|
92
|
+
command.hook("preAction", () => {
|
|
93
|
+
for (const [flag, configPath] of Object.entries(REMOVED_LAUNCH_FLAGS)) {
|
|
94
|
+
const name = new Option(flag).attributeName();
|
|
95
|
+
if (command.getOptionValueSource(name) !== "cli")
|
|
96
|
+
continue;
|
|
97
|
+
throw {
|
|
98
|
+
code: "REMOVED_LAUNCH_OPTION",
|
|
99
|
+
message: `${flag.split(" ")[0]} was removed. ${configPath ? `Use mateo daemon config set ${configPath} <value> --home <path>, then start or restart.` : "Use mateo daemon run --home <path> for foreground deployment."} Deployment environment overrides belong to mateo daemon run.`,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
return command;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=local-daemon.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import type { DaemonTarget } from "../../utils/daemon-target.js";
|
|
3
|
+
interface PairOptions {
|
|
4
|
+
daemonTarget: DaemonTarget;
|
|
5
|
+
home?: string;
|
|
6
|
+
json?: boolean;
|
|
7
|
+
relay?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface PairCommandOutput {
|
|
10
|
+
columns: number | undefined;
|
|
11
|
+
writeStdout(message: string): void;
|
|
12
|
+
writeStderr(message: string): void;
|
|
13
|
+
setExitCode(code: number): void;
|
|
14
|
+
success(message: string): void;
|
|
15
|
+
}
|
|
16
|
+
export interface PairingOffer {
|
|
17
|
+
relayEnabled: boolean;
|
|
18
|
+
url: string | null;
|
|
19
|
+
qr: string | null;
|
|
20
|
+
}
|
|
21
|
+
export declare function pairCommand(): Command;
|
|
22
|
+
export declare function resolveLocalPairingOffer(options: {
|
|
23
|
+
mateoHome: string;
|
|
24
|
+
enableRelay?: boolean;
|
|
25
|
+
}): Promise<PairingOffer>;
|
|
26
|
+
export declare function confirmRelayPairing(): Promise<boolean>;
|
|
27
|
+
export declare function printDirectConnectionGuidance(): void;
|
|
28
|
+
export declare function runPairCommand(options: PairOptions): Promise<void>;
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=pair.d.ts.map
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { confirm, isCancel, log } from "@clack/prompts";
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import { generateLocalPairingOffer } from "@getmateo/server/pairing";
|
|
5
|
+
import { readDaemonInstance } from "@getmateo/server/daemon-control";
|
|
6
|
+
import { readPersistedConfig, editPersistedConfig, resolveConfigFromPersisted, } from "@getmateo/server/configuration";
|
|
7
|
+
import { connectToDaemon } from "../../utils/client.js";
|
|
8
|
+
import { addJsonAndDaemonHostOptions, withGlobalOptions } from "../../utils/command-options.js";
|
|
9
|
+
import { formatPairingInstructions } from "../../output/pairing.js";
|
|
10
|
+
import { parseConnectionOfferFromUrl } from "@getmateo/protocol/connection-offer";
|
|
11
|
+
import { serializeRelayConnectionUri } from "@getmateo/protocol/daemon-endpoints";
|
|
12
|
+
const PAIRING_DAEMON_RPC_TIMEOUT_MS = 1500;
|
|
13
|
+
const RELAY_DOCS_URL = "https://paseo.sh/docs/security";
|
|
14
|
+
function createProcessOutput() {
|
|
15
|
+
return {
|
|
16
|
+
columns: process.stdout.columns,
|
|
17
|
+
writeStdout(message) {
|
|
18
|
+
process.stdout.write(message);
|
|
19
|
+
},
|
|
20
|
+
writeStderr(message) {
|
|
21
|
+
process.stderr.write(message);
|
|
22
|
+
},
|
|
23
|
+
setExitCode(code) {
|
|
24
|
+
process.exitCode = code;
|
|
25
|
+
},
|
|
26
|
+
success(message) {
|
|
27
|
+
log.success(message);
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export function pairCommand() {
|
|
32
|
+
return addJsonAndDaemonHostOptions(new Command("pair").description("Print the daemon pairing QR code and link"))
|
|
33
|
+
.option("--relay", "Enable relay without prompting")
|
|
34
|
+
.action(withGlobalOptions((options, _command) => runPairCommand(options)));
|
|
35
|
+
}
|
|
36
|
+
export async function resolveLocalPairingOffer(options) {
|
|
37
|
+
const instance = await readDaemonInstance(options.mateoHome);
|
|
38
|
+
if (instance)
|
|
39
|
+
return resolveDaemonPairingOffer({ kind: "instance", home: options.mateoHome }, options.enableRelay);
|
|
40
|
+
if (options.enableRelay)
|
|
41
|
+
editPersistedConfig(options.mateoHome, "daemon.relay.enabled", { value: true });
|
|
42
|
+
const config = resolveConfigFromPersisted(options.mateoHome, readPersistedConfig(options.mateoHome, { defaultsIfMissing: true }), { env: {} });
|
|
43
|
+
return generateLocalPairingOffer({
|
|
44
|
+
mateoHome: options.mateoHome,
|
|
45
|
+
relayEnabled: config.relayEnabled,
|
|
46
|
+
relayEndpoint: config.relayEndpoint,
|
|
47
|
+
relayPublicEndpoint: config.relayPublicEndpoint,
|
|
48
|
+
relayUseTls: config.relayUseTls,
|
|
49
|
+
relayPublicUseTls: config.relayPublicUseTls,
|
|
50
|
+
relayServers: config.relayServers,
|
|
51
|
+
appBaseUrl: config.appBaseUrl,
|
|
52
|
+
includeQr: true,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
async function resolveDaemonPairingOffer(target, enableRelay) {
|
|
56
|
+
const client = await connectToDaemon({
|
|
57
|
+
target,
|
|
58
|
+
timeout: PAIRING_DAEMON_RPC_TIMEOUT_MS,
|
|
59
|
+
});
|
|
60
|
+
try {
|
|
61
|
+
const serverInfo = client.getLastServerInfoMessage();
|
|
62
|
+
if (serverInfo?.features?.daemonStatusRpc !== true) {
|
|
63
|
+
throw new Error("Update the Mateo daemon before pairing from this command.");
|
|
64
|
+
}
|
|
65
|
+
let offer = await client.getDaemonPairingOffer({
|
|
66
|
+
timeout: PAIRING_DAEMON_RPC_TIMEOUT_MS,
|
|
67
|
+
});
|
|
68
|
+
if (!offer.relayEnabled && enableRelay) {
|
|
69
|
+
if (serverInfo.features.relayConfig !== true) {
|
|
70
|
+
throw new Error("Update the Mateo daemon before enabling relay from this command.");
|
|
71
|
+
}
|
|
72
|
+
await client.patchDaemonConfig({ relay: { enabled: true } });
|
|
73
|
+
try {
|
|
74
|
+
offer = await client.getDaemonPairingOffer({ timeout: PAIRING_DAEMON_RPC_TIMEOUT_MS });
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
throw new Error(`Relay configuration was saved, but fetching the pairing offer failed: ${String(error)}`, { cause: error });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
relayEnabled: offer.relayEnabled,
|
|
82
|
+
url: offer.url || null,
|
|
83
|
+
qr: offer.qr ?? null,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
await client.close().catch(() => undefined);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
export async function confirmRelayPairing() {
|
|
91
|
+
log.message("Your connection is end-to-end encrypted. Mateo cannot read your code or messages.");
|
|
92
|
+
log.message(`Learn how it works: ${RELAY_DOCS_URL}`);
|
|
93
|
+
const answer = await confirm({
|
|
94
|
+
message: "Enable relay to pair a device?",
|
|
95
|
+
initialValue: false,
|
|
96
|
+
});
|
|
97
|
+
return !isCancel(answer) && answer;
|
|
98
|
+
}
|
|
99
|
+
export function printDirectConnectionGuidance() {
|
|
100
|
+
console.log("Daemon is running with relay off.");
|
|
101
|
+
console.log("To connect another device directly, use the daemon's TCP address over your LAN, Tailscale, or another VPN.");
|
|
102
|
+
console.log(`Learn more: ${RELAY_DOCS_URL}#direct-connections`);
|
|
103
|
+
}
|
|
104
|
+
export async function runPairCommand(options) {
|
|
105
|
+
const output = createProcessOutput();
|
|
106
|
+
const target = options.daemonTarget;
|
|
107
|
+
const resolveOffer = (enableRelay) => target.kind === "instance"
|
|
108
|
+
? resolveLocalPairingOffer({ mateoHome: target.home, enableRelay })
|
|
109
|
+
: resolveDaemonPairingOffer(target, enableRelay);
|
|
110
|
+
const offline = target.kind === "instance" && !(await readDaemonInstance(target.home));
|
|
111
|
+
const pairing = await resolveOffer(options.relay === true);
|
|
112
|
+
if (offline)
|
|
113
|
+
output.writeStderr(`Offline pairing offer. Start with: mateo daemon start --home ${JSON.stringify(target.kind === "instance" ? target.home : "")}\n`);
|
|
114
|
+
outputPairingResult(pairing, options, output);
|
|
115
|
+
}
|
|
116
|
+
function outputPairingResult(pairing, options, output) {
|
|
117
|
+
if (!pairing.relayEnabled || !pairing.url) {
|
|
118
|
+
if (options.json) {
|
|
119
|
+
output.writeStderr(`${JSON.stringify({
|
|
120
|
+
code: "RELAY_DISABLED",
|
|
121
|
+
message: "Relay pairing is disabled for this daemon.",
|
|
122
|
+
action: "Run mateo daemon pair --relay --json to enable it explicitly.",
|
|
123
|
+
})}\n`);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
output.writeStderr(`${chalk.red("Relay pairing is disabled for this daemon.")}\n`);
|
|
127
|
+
output.writeStderr(`${chalk.yellow("Run mateo daemon pair --relay to enable it.")}\n`);
|
|
128
|
+
}
|
|
129
|
+
output.setExitCode(1);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const offer = parseConnectionOfferFromUrl(pairing.url);
|
|
133
|
+
const connectionUri = offer ? serializeRelayConnectionUri({ offer }) : null;
|
|
134
|
+
if (options.json) {
|
|
135
|
+
output.writeStdout(`${JSON.stringify({ relayEnabled: pairing.relayEnabled, url: pairing.url, qr: pairing.qr, connectionUri }, null, 2)}\n`);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
output.writeStdout(formatPairingInstructions({
|
|
139
|
+
url: pairing.url,
|
|
140
|
+
qr: pairing.qr,
|
|
141
|
+
connectionUri,
|
|
142
|
+
columns: output.columns,
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=pair.js.map
|