@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,160 @@
|
|
|
1
|
+
import { connectToDaemon } from "../../utils/client.js";
|
|
2
|
+
import { fetchProjectedTimelineItems, LIVE_HISTORY_FETCH_TIMEOUT_MS, } from "../../utils/timeline.js";
|
|
3
|
+
import { waitForStop } from "../../utils/wait-for-stop.js";
|
|
4
|
+
import { createFollowJsonWriter, usesJsonOutput } from "./logs.js";
|
|
5
|
+
export function addAttachOptions(cmd) {
|
|
6
|
+
return cmd
|
|
7
|
+
.description("Attach to a running agent's output stream (--json for NDJSON)")
|
|
8
|
+
.argument("<id>", "Agent ID (or prefix)");
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Format and print a timeline item to the terminal
|
|
12
|
+
*/
|
|
13
|
+
function printTimelineItem(item) {
|
|
14
|
+
switch (item.type) {
|
|
15
|
+
case "assistant_message":
|
|
16
|
+
// Print assistant text directly
|
|
17
|
+
process.stdout.write(item.text);
|
|
18
|
+
break;
|
|
19
|
+
case "reasoning":
|
|
20
|
+
// Print reasoning in a muted color if available
|
|
21
|
+
console.log(`\n[Reasoning] ${item.text}`);
|
|
22
|
+
break;
|
|
23
|
+
case "tool_call": {
|
|
24
|
+
const toolName = item.name;
|
|
25
|
+
const status = item.status ?? "started";
|
|
26
|
+
console.log(`\n[Tool: ${toolName}] ${status}`);
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
case "todo": {
|
|
30
|
+
const completed = item.items.filter((i) => i.completed).length;
|
|
31
|
+
const total = item.items.length;
|
|
32
|
+
console.log(`\n[Todo] ${completed}/${total} completed`);
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
case "error":
|
|
36
|
+
console.error(`\n[Error] ${item.message}`);
|
|
37
|
+
break;
|
|
38
|
+
case "user_message":
|
|
39
|
+
console.log(`\n[User] ${item.text}`);
|
|
40
|
+
break;
|
|
41
|
+
default:
|
|
42
|
+
// Unknown item type, skip
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Format and print a stream event to the terminal
|
|
48
|
+
*/
|
|
49
|
+
function printStreamEvent(event) {
|
|
50
|
+
switch (event.type) {
|
|
51
|
+
case "timeline":
|
|
52
|
+
// Print the timeline item
|
|
53
|
+
printTimelineItem(event.item);
|
|
54
|
+
break;
|
|
55
|
+
case "permission_requested":
|
|
56
|
+
console.log(`\n[Permission Required] ${event.request.name}`);
|
|
57
|
+
if (event.request.description) {
|
|
58
|
+
console.log(` ${event.request.description}`);
|
|
59
|
+
}
|
|
60
|
+
break;
|
|
61
|
+
case "permission_resolved":
|
|
62
|
+
console.log(`\n[Permission ${event.resolution.behavior}]`);
|
|
63
|
+
break;
|
|
64
|
+
case "turn_failed":
|
|
65
|
+
console.error(`\n[Turn Failed] ${event.error}`);
|
|
66
|
+
break;
|
|
67
|
+
case "attention_required":
|
|
68
|
+
console.log(`\n[Attention Required: ${event.reason}]`);
|
|
69
|
+
break;
|
|
70
|
+
default:
|
|
71
|
+
// Other event types are internal
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Attach to a running agent's output stream
|
|
77
|
+
*/
|
|
78
|
+
export async function runAttachCommand(id, options, _command) {
|
|
79
|
+
if (!id) {
|
|
80
|
+
console.error("Error: Agent ID required");
|
|
81
|
+
console.error("Usage: mateo attach <id>");
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
const client = await connectToDaemon({ target: options.daemonTarget });
|
|
85
|
+
const stopController = new AbortController();
|
|
86
|
+
const stopped = waitForStop(stopController.signal);
|
|
87
|
+
const jsonWriter = usesJsonOutput(options) ? createFollowJsonWriter() : undefined;
|
|
88
|
+
const printItem = jsonWriter?.push ?? printTimelineItem;
|
|
89
|
+
const notice = jsonWriter ? console.error : console.log;
|
|
90
|
+
let unsubscribe;
|
|
91
|
+
try {
|
|
92
|
+
const fetchResult = await Promise.race([client.fetchAgent({ agentId: id }), stopped]);
|
|
93
|
+
if (fetchResult === undefined)
|
|
94
|
+
return;
|
|
95
|
+
if (!fetchResult) {
|
|
96
|
+
console.error(`Error: No agent found matching: ${id}`);
|
|
97
|
+
console.error("Use `mateo ls` to list available agents");
|
|
98
|
+
process.exitCode = 1;
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const resolvedId = fetchResult.agent.id;
|
|
102
|
+
notice(`Fetching history for agent ${resolvedId.substring(0, 7)}...`);
|
|
103
|
+
notice(`(Press Ctrl+C to detach)\n`);
|
|
104
|
+
try {
|
|
105
|
+
const timelineItems = await Promise.race([
|
|
106
|
+
fetchProjectedTimelineItems({
|
|
107
|
+
client,
|
|
108
|
+
agentId: resolvedId,
|
|
109
|
+
timeoutMs: LIVE_HISTORY_FETCH_TIMEOUT_MS,
|
|
110
|
+
}),
|
|
111
|
+
stopped,
|
|
112
|
+
]);
|
|
113
|
+
if (!timelineItems)
|
|
114
|
+
return;
|
|
115
|
+
for (const item of timelineItems) {
|
|
116
|
+
printItem(item);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
console.warn("Warning: failed to fetch existing timeline", error);
|
|
121
|
+
}
|
|
122
|
+
const subscription = client.subscribeAgentTimeline(resolvedId, (message) => {
|
|
123
|
+
if (message.type === "agent.timeline.replacement") {
|
|
124
|
+
notice("\n[Timeline replaced; earlier output is no longer current]");
|
|
125
|
+
}
|
|
126
|
+
else if (message.type === "agent.timeline.subscription_restored") {
|
|
127
|
+
notice("\n[Reconnected; live output resumed. Events may have been missed.]");
|
|
128
|
+
}
|
|
129
|
+
else if (message.type === "agent.timeline.error") {
|
|
130
|
+
console.error(`Timeline observation stopped: ${message.payload.error}`);
|
|
131
|
+
}
|
|
132
|
+
else if (jsonWriter) {
|
|
133
|
+
const event = message.payload.event;
|
|
134
|
+
if (event.type === "timeline")
|
|
135
|
+
printItem(event.item);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
printStreamEvent(message.payload.event);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
unsubscribe = subscription;
|
|
142
|
+
const ready = await Promise.race([subscription.ready.then(() => true), stopped]);
|
|
143
|
+
if (!ready)
|
|
144
|
+
return;
|
|
145
|
+
notice(`Attached to agent ${resolvedId.substring(0, 7)}.`);
|
|
146
|
+
await stopped;
|
|
147
|
+
notice("\n\nDetaching from agent...");
|
|
148
|
+
}
|
|
149
|
+
catch (err) {
|
|
150
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
151
|
+
console.error(`Error: Failed to attach to agent: ${message}`);
|
|
152
|
+
process.exitCode = 1;
|
|
153
|
+
}
|
|
154
|
+
finally {
|
|
155
|
+
stopController.abort();
|
|
156
|
+
unsubscribe?.();
|
|
157
|
+
await client.close();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=attach.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
export declare function addDeleteOptions(cmd: Command): Command;
|
|
3
|
+
import type { CommandOptions, SingleResult, OutputSchema } from "../../output/index.js";
|
|
4
|
+
export interface DeleteResult {
|
|
5
|
+
deletedCount: number;
|
|
6
|
+
agentIds: string[];
|
|
7
|
+
}
|
|
8
|
+
export declare const deleteSchema: OutputSchema<DeleteResult>;
|
|
9
|
+
export interface AgentDeleteOptions extends CommandOptions {
|
|
10
|
+
all?: boolean;
|
|
11
|
+
cwd?: string;
|
|
12
|
+
}
|
|
13
|
+
export type AgentDeleteResult = SingleResult<DeleteResult>;
|
|
14
|
+
export declare function runDeleteCommand(id: string | undefined, options: AgentDeleteOptions, _command: Command): Promise<AgentDeleteResult>;
|
|
15
|
+
//# sourceMappingURL=delete.d.ts.map
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { connectToDaemon } from "../../utils/client.js";
|
|
2
|
+
import { isSameOrDescendantPath } from "../../utils/paths.js";
|
|
3
|
+
export function addDeleteOptions(cmd) {
|
|
4
|
+
return cmd
|
|
5
|
+
.description("Delete an agent (interrupt if running, then hard-delete)")
|
|
6
|
+
.argument("[id]", "Agent ID (or prefix) - optional if --all or --cwd specified")
|
|
7
|
+
.option("--all", "Delete all agents")
|
|
8
|
+
.option("--cwd <path>", "Delete all agents in directory");
|
|
9
|
+
}
|
|
10
|
+
export const deleteSchema = {
|
|
11
|
+
idField: (item) => item.agentIds.join("\n"),
|
|
12
|
+
columns: [{ header: "DELETED", field: "deletedCount" }],
|
|
13
|
+
};
|
|
14
|
+
// History includes archived agents and agents whose provider is unavailable.
|
|
15
|
+
async function fetchHistoryAgents(client) {
|
|
16
|
+
const agents = [];
|
|
17
|
+
let cursor;
|
|
18
|
+
do {
|
|
19
|
+
const payload = await client.fetchAgentHistory({
|
|
20
|
+
page: { limit: 200, ...(cursor ? { cursor } : {}) },
|
|
21
|
+
});
|
|
22
|
+
agents.push(...payload.entries.map((entry) => entry.agent));
|
|
23
|
+
cursor = payload.pageInfo.nextCursor ?? undefined;
|
|
24
|
+
} while (cursor);
|
|
25
|
+
return agents;
|
|
26
|
+
}
|
|
27
|
+
export async function runDeleteCommand(id, options, _command) {
|
|
28
|
+
if (!id && !options.all && !options.cwd) {
|
|
29
|
+
const error = {
|
|
30
|
+
code: "MISSING_ARGUMENT",
|
|
31
|
+
message: "Agent ID required unless --all or --cwd is specified",
|
|
32
|
+
details: "Usage: mateo agent delete <id> | --all | --cwd <path>",
|
|
33
|
+
};
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
const client = await connectToDaemon({ target: options.daemonTarget });
|
|
37
|
+
try {
|
|
38
|
+
const deletedIds = [];
|
|
39
|
+
let agents;
|
|
40
|
+
if (options.all || options.cwd) {
|
|
41
|
+
agents = await fetchHistoryAgents(client);
|
|
42
|
+
if (!options.all) {
|
|
43
|
+
agents = agents.filter((a) => isSameOrDescendantPath(options.cwd, a.cwd));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
const fetchResult = await client.fetchAgent({ agentId: id });
|
|
48
|
+
if (!fetchResult) {
|
|
49
|
+
const error = {
|
|
50
|
+
code: "AGENT_NOT_FOUND",
|
|
51
|
+
message: `No agent found matching: ${id}`,
|
|
52
|
+
details: "Use `mateo ls` to list available agents",
|
|
53
|
+
};
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
agents = [fetchResult.agent];
|
|
57
|
+
}
|
|
58
|
+
const deleteResults = await Promise.all(agents.map(async (agent) => {
|
|
59
|
+
try {
|
|
60
|
+
if (agent.status === "running") {
|
|
61
|
+
await client.cancelAgent(agent.id).catch(() => { });
|
|
62
|
+
}
|
|
63
|
+
await client.deleteAgent(agent.id);
|
|
64
|
+
return { ok: true, id: agent.id };
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
67
|
+
if (err && typeof err === "object" && "code" in err)
|
|
68
|
+
throw err;
|
|
69
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
70
|
+
return { ok: false, id: agent.id, message };
|
|
71
|
+
}
|
|
72
|
+
}));
|
|
73
|
+
for (const result of deleteResults) {
|
|
74
|
+
if (result.ok) {
|
|
75
|
+
deletedIds.push(result.id);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
console.error(`Warning: Failed to delete agent ${result.id.slice(0, 7)}: ${result.message}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
await client.close();
|
|
82
|
+
return {
|
|
83
|
+
type: "single",
|
|
84
|
+
data: {
|
|
85
|
+
deletedCount: deletedIds.length,
|
|
86
|
+
agentIds: deletedIds,
|
|
87
|
+
},
|
|
88
|
+
schema: deleteSchema,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
await client.close().catch(() => { });
|
|
93
|
+
if (err && typeof err === "object" && "code" in err) {
|
|
94
|
+
throw err;
|
|
95
|
+
}
|
|
96
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
97
|
+
const error = {
|
|
98
|
+
code: "DELETE_AGENT_FAILED",
|
|
99
|
+
message: `Failed to delete agent(s): ${message}`,
|
|
100
|
+
};
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=delete.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
import { connectToDaemon } from "../../utils/client.js";
|
|
3
|
+
import { type AgentLookupClient } from "../../utils/agent-directory.js";
|
|
4
|
+
import type { CommandOptions, SingleResult } from "../../output/index.js";
|
|
5
|
+
interface AgentDetachResult {
|
|
6
|
+
agentId: string;
|
|
7
|
+
status: "detached";
|
|
8
|
+
}
|
|
9
|
+
export interface AgentDetachClient extends AgentLookupClient {
|
|
10
|
+
detachAgent(agentId: string): Promise<unknown>;
|
|
11
|
+
close(): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export declare function runDetachCommand(agentIdArg: string, options: CommandOptions, _command: Command): Promise<SingleResult<AgentDetachResult>>;
|
|
14
|
+
export declare function detachAgent(agentIdArg: string, options: CommandOptions, connect?: (options: Parameters<typeof connectToDaemon>[0]) => Promise<AgentDetachClient>): Promise<SingleResult<AgentDetachResult>>;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=detach.d.ts.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { connectToDaemon } from "../../utils/client.js";
|
|
2
|
+
import { resolveAgentEntry } from "../../utils/agent-directory.js";
|
|
3
|
+
const detachSchema = {
|
|
4
|
+
idField: "agentId",
|
|
5
|
+
columns: [
|
|
6
|
+
{ header: "AGENT ID", field: "agentId" },
|
|
7
|
+
{ header: "STATUS", field: "status" },
|
|
8
|
+
],
|
|
9
|
+
};
|
|
10
|
+
export async function runDetachCommand(agentIdArg, options, _command) {
|
|
11
|
+
return detachAgent(agentIdArg, options);
|
|
12
|
+
}
|
|
13
|
+
export async function detachAgent(agentIdArg, options, connect = connectToDaemon) {
|
|
14
|
+
const client = await connect({ target: options.daemonTarget });
|
|
15
|
+
try {
|
|
16
|
+
const agent = await resolveAgentEntry(client, agentIdArg);
|
|
17
|
+
if (!agent) {
|
|
18
|
+
throw {
|
|
19
|
+
code: "AGENT_NOT_FOUND",
|
|
20
|
+
message: `Agent not found: ${agentIdArg}`,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
await client.detachAgent(agent.id);
|
|
24
|
+
return {
|
|
25
|
+
type: "single",
|
|
26
|
+
data: { agentId: agent.id, status: "detached" },
|
|
27
|
+
schema: detachSchema,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
if (err && typeof err === "object" && "code" in err) {
|
|
32
|
+
throw err;
|
|
33
|
+
}
|
|
34
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
35
|
+
throw {
|
|
36
|
+
code: "DETACH_FAILED",
|
|
37
|
+
message: `Failed to detach agent: ${message}`,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
await client.close().catch(() => undefined);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=detach.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
import type { CommandOptions, SingleResult } from "../../output/index.js";
|
|
3
|
+
import { type AgentRunResult } from "./run.js";
|
|
4
|
+
export declare function addImportOptions(cmd: Command): Command;
|
|
5
|
+
export interface AgentImportOptions extends CommandOptions {
|
|
6
|
+
provider?: string;
|
|
7
|
+
cwd?: string;
|
|
8
|
+
label?: string[];
|
|
9
|
+
host?: string;
|
|
10
|
+
}
|
|
11
|
+
export type AgentImportCommandResult = SingleResult<AgentRunResult>;
|
|
12
|
+
export declare function resolveImportCwd(explicitCwd: string | undefined, defaultCwd: string): string;
|
|
13
|
+
export declare function runImportCommand(sessionIdArg: string, options: AgentImportOptions, _command: Command): Promise<AgentImportCommandResult>;
|
|
14
|
+
//# sourceMappingURL=import.d.ts.map
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { connectToDaemon } from "../../utils/client.js";
|
|
2
|
+
import { collectMultiple } from "../../utils/command-options.js";
|
|
3
|
+
import { agentRunSchema } from "./run.js";
|
|
4
|
+
export function addImportOptions(cmd) {
|
|
5
|
+
return cmd
|
|
6
|
+
.description("Import an existing provider session as a Mateo agent")
|
|
7
|
+
.argument("<id>", "Provider session/thread ID to import")
|
|
8
|
+
.requiredOption("--provider <provider>", "Agent provider id")
|
|
9
|
+
.option("--cwd <path>", "Working directory for providers that require it")
|
|
10
|
+
.option("--label <key=value>", "Add label(s) to the agent (can be used multiple times)", collectMultiple, []);
|
|
11
|
+
}
|
|
12
|
+
function toImportResult(agent) {
|
|
13
|
+
return {
|
|
14
|
+
agentId: agent.id,
|
|
15
|
+
status: agent.status === "running" ? "running" : "created",
|
|
16
|
+
provider: agent.provider,
|
|
17
|
+
cwd: agent.cwd,
|
|
18
|
+
title: agent.title,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function parseImportProvider(provider) {
|
|
22
|
+
const normalizedProvider = provider?.trim();
|
|
23
|
+
if (!normalizedProvider) {
|
|
24
|
+
throw {
|
|
25
|
+
code: "MISSING_PROVIDER",
|
|
26
|
+
message: "Provider is required",
|
|
27
|
+
details: "Usage: mateo import --provider <provider> <id>",
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return normalizedProvider;
|
|
31
|
+
}
|
|
32
|
+
function parseImportLabels(labelFlags) {
|
|
33
|
+
const labels = {};
|
|
34
|
+
if (!labelFlags) {
|
|
35
|
+
return labels;
|
|
36
|
+
}
|
|
37
|
+
for (const labelFlag of labelFlags) {
|
|
38
|
+
const eqIndex = labelFlag.indexOf("=");
|
|
39
|
+
if (eqIndex === -1) {
|
|
40
|
+
throw {
|
|
41
|
+
code: "INVALID_LABEL",
|
|
42
|
+
message: `Invalid label format: ${labelFlag}`,
|
|
43
|
+
details: "Labels must be in key=value format",
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const key = labelFlag.slice(0, eqIndex).trim();
|
|
47
|
+
if (!key) {
|
|
48
|
+
throw {
|
|
49
|
+
code: "INVALID_LABEL",
|
|
50
|
+
message: `Invalid label format: ${labelFlag}`,
|
|
51
|
+
details: "Labels must include a non-empty key in key=value format",
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
labels[key] = labelFlag.slice(eqIndex + 1);
|
|
55
|
+
}
|
|
56
|
+
return labels;
|
|
57
|
+
}
|
|
58
|
+
export function resolveImportCwd(explicitCwd, defaultCwd) {
|
|
59
|
+
const cwd = explicitCwd?.trim() ?? defaultCwd;
|
|
60
|
+
if (!cwd.trim()) {
|
|
61
|
+
throw {
|
|
62
|
+
code: "INVALID_CWD",
|
|
63
|
+
message: "--cwd cannot be empty",
|
|
64
|
+
details: "Provide a working directory path or omit --cwd",
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return cwd;
|
|
68
|
+
}
|
|
69
|
+
export async function runImportCommand(sessionIdArg, options, _command) {
|
|
70
|
+
const sessionId = sessionIdArg.trim();
|
|
71
|
+
if (!sessionId) {
|
|
72
|
+
throw {
|
|
73
|
+
code: "MISSING_SESSION_ID",
|
|
74
|
+
message: "Session ID is required",
|
|
75
|
+
details: "Usage: mateo import --provider <provider> <id>",
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
const provider = parseImportProvider(options.provider);
|
|
79
|
+
const cwd = resolveImportCwd(options.cwd, process.cwd());
|
|
80
|
+
const labels = parseImportLabels(options.label);
|
|
81
|
+
const client = await connectToDaemon({ target: options.daemonTarget });
|
|
82
|
+
try {
|
|
83
|
+
const agent = await client.importAgent({
|
|
84
|
+
provider,
|
|
85
|
+
sessionId,
|
|
86
|
+
cwd,
|
|
87
|
+
...(Object.keys(labels).length > 0 ? { labels } : {}),
|
|
88
|
+
});
|
|
89
|
+
await client.close();
|
|
90
|
+
return {
|
|
91
|
+
type: "single",
|
|
92
|
+
data: toImportResult(agent),
|
|
93
|
+
schema: agentRunSchema,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
await client.close().catch(() => { });
|
|
98
|
+
if (err && typeof err === "object" && "code" in err) {
|
|
99
|
+
throw err;
|
|
100
|
+
}
|
|
101
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
102
|
+
throw {
|
|
103
|
+
code: "AGENT_IMPORT_FAILED",
|
|
104
|
+
message: `Failed to import agent: ${message}`,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=import.js.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { runModeCommand } from "./mode.js";
|
|
3
|
+
import { addArchiveOptions, runArchiveCommand } from "./archive.js";
|
|
4
|
+
import { addDeleteOptions, runDeleteCommand } from "./delete.js";
|
|
5
|
+
import { addLsOptions, runLsCommand } from "./ls.js";
|
|
6
|
+
import { addRunOptions, runRunCommand } from "./run.js";
|
|
7
|
+
import { addLogsOptions, runLogsCommand } from "./logs.js";
|
|
8
|
+
import { addStopOptions, runStopCommand } from "./stop.js";
|
|
9
|
+
import { addSendOptions, runSendCommand } from "./send.js";
|
|
10
|
+
import { addInspectOptions, runInspectCommand } from "./inspect.js";
|
|
11
|
+
import { addWaitOptions, runWaitCommand } from "./wait.js";
|
|
12
|
+
import { addAttachOptions, runAttachCommand } from "./attach.js";
|
|
13
|
+
import { addReloadOptions, runReloadCommand } from "./reload.js";
|
|
14
|
+
import { addImportOptions, runImportCommand } from "./import.js";
|
|
15
|
+
import { runUpdateCommand } from "./update.js";
|
|
16
|
+
import { runDetachCommand } from "./detach.js";
|
|
17
|
+
import { addOpenOptions, runOpenCommand } from "./open.js";
|
|
18
|
+
import { withOutput } from "../../output/index.js";
|
|
19
|
+
import { addDaemonHostOption, addJsonAndDaemonHostOptions, collectMultiple, withGlobalOptions, } from "../../utils/command-options.js";
|
|
20
|
+
export function createAgentCommand() {
|
|
21
|
+
const agent = new Command("agent").description("Manage agents (advanced operations)");
|
|
22
|
+
// Primary agent commands (same as top-level)
|
|
23
|
+
addJsonAndDaemonHostOptions(addLsOptions(agent.command("ls"))).action(withOutput(runLsCommand));
|
|
24
|
+
addJsonAndDaemonHostOptions(addRunOptions(agent.command("run"))).action(withOutput(runRunCommand));
|
|
25
|
+
addJsonAndDaemonHostOptions(addImportOptions(agent.command("import"))).action(withOutput(runImportCommand));
|
|
26
|
+
addDaemonHostOption(addAttachOptions(agent.command("attach"))).action(withGlobalOptions(runAttachCommand));
|
|
27
|
+
addDaemonHostOption(addLogsOptions(agent.command("logs"))).action(withGlobalOptions(runLogsCommand));
|
|
28
|
+
addJsonAndDaemonHostOptions(addOpenOptions(agent.command("open"))).action(withOutput(runOpenCommand));
|
|
29
|
+
addJsonAndDaemonHostOptions(addStopOptions(agent.command("stop"))).action(withOutput(runStopCommand));
|
|
30
|
+
addJsonAndDaemonHostOptions(addDeleteOptions(agent.command("delete"))).action(withOutput(runDeleteCommand));
|
|
31
|
+
addJsonAndDaemonHostOptions(addSendOptions(agent.command("send"))).action(withOutput(runSendCommand));
|
|
32
|
+
addJsonAndDaemonHostOptions(addInspectOptions(agent.command("inspect"))).action(withOutput(runInspectCommand));
|
|
33
|
+
addJsonAndDaemonHostOptions(addWaitOptions(agent.command("wait"))).action(withOutput(runWaitCommand));
|
|
34
|
+
// Advanced agent commands (less common operations)
|
|
35
|
+
addJsonAndDaemonHostOptions(agent
|
|
36
|
+
.command("mode")
|
|
37
|
+
.description("Change an agent's operational mode")
|
|
38
|
+
.argument("<id>", "Agent ID (or prefix)")
|
|
39
|
+
.argument("[mode]", "Mode to set (required unless --list)")
|
|
40
|
+
.option("--list", "List available modes for this agent")).action(withOutput(runModeCommand));
|
|
41
|
+
addJsonAndDaemonHostOptions(addArchiveOptions(agent.command("archive"))).action(withOutput(runArchiveCommand));
|
|
42
|
+
addJsonAndDaemonHostOptions(addReloadOptions(agent.command("reload"))).action(withOutput(runReloadCommand));
|
|
43
|
+
addJsonAndDaemonHostOptions(agent
|
|
44
|
+
.command("detach")
|
|
45
|
+
.description("Make a subagent independent without stopping or moving it")
|
|
46
|
+
.argument("<id>", "Agent ID, prefix, or name")).action(withOutput(runDetachCommand));
|
|
47
|
+
addJsonAndDaemonHostOptions(agent
|
|
48
|
+
.command("update")
|
|
49
|
+
.description("Update an agent's settings or metadata")
|
|
50
|
+
.argument("<id>", "Agent ID (or prefix)")
|
|
51
|
+
.option("--name <name>", "Update the agent's display name")
|
|
52
|
+
.option("--thinking <id>", "Update the agent's thinking option ID")
|
|
53
|
+
.option("--label <label>", "Add/set label(s) on the agent (can be used multiple times or comma-separated)", collectMultiple, [])).action(withOutput(runUpdateCommand));
|
|
54
|
+
return agent;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
import type { CommandOptions, ListResult } from "../../output/index.js";
|
|
3
|
+
export declare function addInspectOptions(cmd: Command): Command;
|
|
4
|
+
/** Key-value row for table display */
|
|
5
|
+
interface InspectRow {
|
|
6
|
+
key: string;
|
|
7
|
+
value: string;
|
|
8
|
+
}
|
|
9
|
+
export type AgentInspectResult = ListResult<InspectRow>;
|
|
10
|
+
export interface AgentInspectOptions extends CommandOptions {
|
|
11
|
+
host?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function runInspectCommand(agentIdArg: string, options: AgentInspectOptions, _command: Command): Promise<AgentInspectResult>;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=inspect.d.ts.map
|