@otto-code/cli 0.5.0

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 (200) hide show
  1. package/bin/otto +3 -0
  2. package/dist/classify.d.ts +19 -0
  3. package/dist/classify.js +49 -0
  4. package/dist/cli.d.ts +3 -0
  5. package/dist/cli.js +113 -0
  6. package/dist/commands/agent/archive.d.ts +18 -0
  7. package/dist/commands/agent/archive.js +102 -0
  8. package/dist/commands/agent/attach.d.ts +11 -0
  9. package/dist/commands/agent/attach.js +159 -0
  10. package/dist/commands/agent/delete.d.ts +15 -0
  11. package/dist/commands/agent/delete.js +107 -0
  12. package/dist/commands/agent/import.d.ts +14 -0
  13. package/dist/commands/agent/import.js +122 -0
  14. package/dist/commands/agent/index.d.ts +3 -0
  15. package/dist/commands/agent/index.js +48 -0
  16. package/dist/commands/agent/inspect.d.ts +15 -0
  17. package/dist/commands/agent/inspect.js +209 -0
  18. package/dist/commands/agent/logs.d.ts +19 -0
  19. package/dist/commands/agent/logs.js +180 -0
  20. package/dist/commands/agent/ls.d.ts +44 -0
  21. package/dist/commands/agent/ls.js +204 -0
  22. package/dist/commands/agent/mode.d.ts +18 -0
  23. package/dist/commands/agent/mode.js +100 -0
  24. package/dist/commands/agent/reload.d.ts +15 -0
  25. package/dist/commands/agent/reload.js +75 -0
  26. package/dist/commands/agent/run.d.ts +44 -0
  27. package/dist/commands/agent/run.js +464 -0
  28. package/dist/commands/agent/send.d.ts +19 -0
  29. package/dist/commands/agent/send.js +187 -0
  30. package/dist/commands/agent/stop.d.ts +17 -0
  31. package/dist/commands/agent/stop.js +115 -0
  32. package/dist/commands/agent/update.d.ts +18 -0
  33. package/dist/commands/agent/update.js +139 -0
  34. package/dist/commands/agent/wait.d.ts +17 -0
  35. package/dist/commands/agent/wait.js +158 -0
  36. package/dist/commands/chat/create.d.ts +9 -0
  37. package/dist/commands/chat/create.js +23 -0
  38. package/dist/commands/chat/delete.d.ts +6 -0
  39. package/dist/commands/chat/delete.js +20 -0
  40. package/dist/commands/chat/index.d.ts +3 -0
  41. package/dist/commands/chat/index.js +47 -0
  42. package/dist/commands/chat/inspect.d.ts +6 -0
  43. package/dist/commands/chat/inspect.js +20 -0
  44. package/dist/commands/chat/ls.d.ts +6 -0
  45. package/dist/commands/chat/ls.js +20 -0
  46. package/dist/commands/chat/post.d.ts +9 -0
  47. package/dist/commands/chat/post.js +28 -0
  48. package/dist/commands/chat/read.d.ts +11 -0
  49. package/dist/commands/chat/read.js +40 -0
  50. package/dist/commands/chat/schema.d.ts +36 -0
  51. package/dist/commands/chat/schema.js +81 -0
  52. package/dist/commands/chat/shared.d.ts +19 -0
  53. package/dist/commands/chat/shared.js +118 -0
  54. package/dist/commands/chat/wait.d.ts +9 -0
  55. package/dist/commands/chat/wait.js +45 -0
  56. package/dist/commands/daemon/index.d.ts +3 -0
  57. package/dist/commands/daemon/index.js +57 -0
  58. package/dist/commands/daemon/local-daemon.d.ts +78 -0
  59. package/dist/commands/daemon/local-daemon.js +544 -0
  60. package/dist/commands/daemon/pair.d.ts +9 -0
  61. package/dist/commands/daemon/pair.js +76 -0
  62. package/dist/commands/daemon/restart.d.ts +12 -0
  63. package/dist/commands/daemon/restart.js +99 -0
  64. package/dist/commands/daemon/runtime-toolchain.d.ts +6 -0
  65. package/dist/commands/daemon/runtime-toolchain.js +87 -0
  66. package/dist/commands/daemon/set-password.d.ts +17 -0
  67. package/dist/commands/daemon/set-password.js +82 -0
  68. package/dist/commands/daemon/start.d.ts +6 -0
  69. package/dist/commands/daemon/start.js +56 -0
  70. package/dist/commands/daemon/status.d.ts +10 -0
  71. package/dist/commands/daemon/status.js +338 -0
  72. package/dist/commands/daemon/stop.d.ts +15 -0
  73. package/dist/commands/daemon/stop.js +60 -0
  74. package/dist/commands/hooks.d.ts +19 -0
  75. package/dist/commands/hooks.js +89 -0
  76. package/dist/commands/loop/index.d.ts +3 -0
  77. package/dist/commands/loop/index.js +18 -0
  78. package/dist/commands/loop/inspect.d.ts +13 -0
  79. package/dist/commands/loop/inspect.js +100 -0
  80. package/dist/commands/loop/logs.d.ts +8 -0
  81. package/dist/commands/loop/logs.js +69 -0
  82. package/dist/commands/loop/ls.d.ts +18 -0
  83. package/dist/commands/loop/ls.js +62 -0
  84. package/dist/commands/loop/run.d.ts +30 -0
  85. package/dist/commands/loop/run.js +162 -0
  86. package/dist/commands/loop/stop.d.ts +15 -0
  87. package/dist/commands/loop/stop.js +56 -0
  88. package/dist/commands/loop/types.d.ts +138 -0
  89. package/dist/commands/loop/types.js +2 -0
  90. package/dist/commands/onboard.d.ts +10 -0
  91. package/dist/commands/onboard.js +416 -0
  92. package/dist/commands/open.d.ts +2 -0
  93. package/dist/commands/open.js +81 -0
  94. package/dist/commands/permit/allow.d.ts +20 -0
  95. package/dist/commands/permit/allow.js +133 -0
  96. package/dist/commands/permit/deny.d.ts +12 -0
  97. package/dist/commands/permit/deny.js +105 -0
  98. package/dist/commands/permit/index.d.ts +3 -0
  99. package/dist/commands/permit/index.js +27 -0
  100. package/dist/commands/permit/ls.d.ts +18 -0
  101. package/dist/commands/permit/ls.js +66 -0
  102. package/dist/commands/provider/index.d.ts +3 -0
  103. package/dist/commands/provider/index.js +16 -0
  104. package/dist/commands/provider/ls.d.ts +19 -0
  105. package/dist/commands/provider/ls.js +73 -0
  106. package/dist/commands/provider/models.d.ts +20 -0
  107. package/dist/commands/provider/models.js +53 -0
  108. package/dist/commands/schedule/create.d.ts +18 -0
  109. package/dist/commands/schedule/create.js +40 -0
  110. package/dist/commands/schedule/delete.d.ts +10 -0
  111. package/dist/commands/schedule/delete.js +32 -0
  112. package/dist/commands/schedule/index.d.ts +3 -0
  113. package/dist/commands/schedule/index.js +66 -0
  114. package/dist/commands/schedule/inspect.d.ts +6 -0
  115. package/dist/commands/schedule/inspect.js +24 -0
  116. package/dist/commands/schedule/logs.d.ts +6 -0
  117. package/dist/commands/schedule/logs.js +23 -0
  118. package/dist/commands/schedule/ls.d.ts +5 -0
  119. package/dist/commands/schedule/ls.js +23 -0
  120. package/dist/commands/schedule/pause.d.ts +5 -0
  121. package/dist/commands/schedule/pause.js +23 -0
  122. package/dist/commands/schedule/resume.d.ts +5 -0
  123. package/dist/commands/schedule/resume.js +23 -0
  124. package/dist/commands/schedule/run-once.d.ts +5 -0
  125. package/dist/commands/schedule/run-once.js +23 -0
  126. package/dist/commands/schedule/schema.d.ts +21 -0
  127. package/dist/commands/schedule/schema.js +67 -0
  128. package/dist/commands/schedule/shared.d.ts +56 -0
  129. package/dist/commands/schedule/shared.js +346 -0
  130. package/dist/commands/schedule/types.d.ts +168 -0
  131. package/dist/commands/schedule/types.js +2 -0
  132. package/dist/commands/schedule/update.d.ts +21 -0
  133. package/dist/commands/schedule/update.js +39 -0
  134. package/dist/commands/speech/index.d.ts +3 -0
  135. package/dist/commands/speech/index.js +5 -0
  136. package/dist/commands/terminal/capture.d.ts +10 -0
  137. package/dist/commands/terminal/capture.js +68 -0
  138. package/dist/commands/terminal/create.d.ts +10 -0
  139. package/dist/commands/terminal/create.js +38 -0
  140. package/dist/commands/terminal/index.d.ts +3 -0
  141. package/dist/commands/terminal/index.js +43 -0
  142. package/dist/commands/terminal/kill.d.ts +6 -0
  143. package/dist/commands/terminal/kill.js +36 -0
  144. package/dist/commands/terminal/ls.d.ts +10 -0
  145. package/dist/commands/terminal/ls.js +21 -0
  146. package/dist/commands/terminal/schema.d.ts +18 -0
  147. package/dist/commands/terminal/schema.js +23 -0
  148. package/dist/commands/terminal/send-keys.d.ts +7 -0
  149. package/dist/commands/terminal/send-keys.js +76 -0
  150. package/dist/commands/terminal/shared.d.ts +12 -0
  151. package/dist/commands/terminal/shared.js +61 -0
  152. package/dist/commands/worktree/archive.d.ts +20 -0
  153. package/dist/commands/worktree/archive.js +104 -0
  154. package/dist/commands/worktree/create-input.d.ts +15 -0
  155. package/dist/commands/worktree/create-input.js +56 -0
  156. package/dist/commands/worktree/create.d.ts +11 -0
  157. package/dist/commands/worktree/create.js +58 -0
  158. package/dist/commands/worktree/index.d.ts +3 -0
  159. package/dist/commands/worktree/index.js +25 -0
  160. package/dist/commands/worktree/ls.d.ts +19 -0
  161. package/dist/commands/worktree/ls.js +97 -0
  162. package/dist/index.d.ts +2 -0
  163. package/dist/index.js +6 -0
  164. package/dist/output/index.d.ts +45 -0
  165. package/dist/output/index.js +47 -0
  166. package/dist/output/json.d.ts +11 -0
  167. package/dist/output/json.js +37 -0
  168. package/dist/output/quiet.d.ts +9 -0
  169. package/dist/output/quiet.js +22 -0
  170. package/dist/output/render.d.ts +15 -0
  171. package/dist/output/render.js +83 -0
  172. package/dist/output/table.d.ts +13 -0
  173. package/dist/output/table.js +135 -0
  174. package/dist/output/types.d.ts +73 -0
  175. package/dist/output/types.js +8 -0
  176. package/dist/output/with-output.d.ts +41 -0
  177. package/dist/output/with-output.js +87 -0
  178. package/dist/output/yaml.d.ts +11 -0
  179. package/dist/output/yaml.js +38 -0
  180. package/dist/run.d.ts +14 -0
  181. package/dist/run.js +33 -0
  182. package/dist/utils/client-id.d.ts +2 -0
  183. package/dist/utils/client-id.js +37 -0
  184. package/dist/utils/client.d.ts +44 -0
  185. package/dist/utils/client.js +330 -0
  186. package/dist/utils/command-options.d.ts +6 -0
  187. package/dist/utils/command-options.js +17 -0
  188. package/dist/utils/duration.d.ts +7 -0
  189. package/dist/utils/duration.js +38 -0
  190. package/dist/utils/errors.d.ts +5 -0
  191. package/dist/utils/errors.js +10 -0
  192. package/dist/utils/paths.d.ts +12 -0
  193. package/dist/utils/paths.js +22 -0
  194. package/dist/utils/provider-model.d.ts +11 -0
  195. package/dist/utils/provider-model.js +49 -0
  196. package/dist/utils/timeline.d.ts +11 -0
  197. package/dist/utils/timeline.js +11 -0
  198. package/dist/version.d.ts +2 -0
  199. package/dist/version.js +10 -0
  200. package/package.json +48 -0
@@ -0,0 +1,204 @@
1
+ import { connectToDaemon, getDaemonHost } from "../../utils/client.js";
2
+ import { collectMultiple } from "../../utils/command-options.js";
3
+ import { isSameOrDescendantPath } from "../../utils/paths.js";
4
+ export function addLsOptions(cmd) {
5
+ return cmd
6
+ .description("List agents. By default excludes archived agents.")
7
+ .option("-a, --all", "Include archived agents")
8
+ .option("-g, --global", "List agents across all directories")
9
+ .option("--label <key=value>", "Filter by label (can be used multiple times)", collectMultiple, [])
10
+ .option("--thinking <id>", "Filter by thinking option ID");
11
+ }
12
+ /** Helper to get relative time string */
13
+ function relativeTime(date) {
14
+ const now = Date.now();
15
+ const then = new Date(date).getTime();
16
+ const seconds = Math.floor((now - then) / 1000);
17
+ if (seconds < 60)
18
+ return "just now";
19
+ if (seconds < 3600)
20
+ return `${Math.floor(seconds / 60)} minutes ago`;
21
+ if (seconds < 86400)
22
+ return `${Math.floor(seconds / 3600)} hours ago`;
23
+ return `${Math.floor(seconds / 86400)} days ago`;
24
+ }
25
+ /** Shorten home directory in path */
26
+ function shortenPath(path) {
27
+ const home = process.env.HOME;
28
+ if (home && path.startsWith(home)) {
29
+ return "~" + path.slice(home.length);
30
+ }
31
+ return path;
32
+ }
33
+ function normalizeModelId(modelId) {
34
+ if (typeof modelId !== "string")
35
+ return null;
36
+ const normalized = modelId.trim();
37
+ if (!normalized || normalized.toLowerCase() === "default")
38
+ return null;
39
+ return normalized;
40
+ }
41
+ /** Schema for agent ls output */
42
+ export const agentLsSchema = {
43
+ idField: "shortId",
44
+ columns: [
45
+ { header: "AGENT ID", field: "shortId", width: 12 },
46
+ { header: "NAME", field: "name", width: 20 },
47
+ { header: "PROVIDER", field: "provider", width: 15 },
48
+ { header: "THINKING", field: "thinking", width: 12 },
49
+ {
50
+ header: "STATUS",
51
+ field: "status",
52
+ width: 10,
53
+ color: (value) => {
54
+ if (value === "running")
55
+ return "green";
56
+ if (value === "idle")
57
+ return "yellow";
58
+ if (value === "error")
59
+ return "red";
60
+ return undefined;
61
+ },
62
+ },
63
+ { header: "CWD", field: "cwd", width: 30 },
64
+ { header: "CREATED", field: "created", width: 15 },
65
+ ],
66
+ };
67
+ /** Transform agent snapshot to AgentListItem */
68
+ function toListItem(agent) {
69
+ const model = normalizeModelId(agent.runtimeInfo?.model) ?? normalizeModelId(agent.model);
70
+ return {
71
+ id: agent.id,
72
+ shortId: agent.id.slice(0, 7),
73
+ name: agent.title ?? "-",
74
+ provider: model ? `${agent.provider}/${model}` : agent.provider,
75
+ thinking: agent.effectiveThinkingOptionId ?? "auto",
76
+ status: agent.status,
77
+ cwd: shortenPath(agent.cwd),
78
+ created: relativeTime(agent.createdAt),
79
+ };
80
+ }
81
+ function parseLabelFilters(labels) {
82
+ const labelFilters = {};
83
+ for (const labelStr of labels ?? []) {
84
+ const eqIndex = labelStr.indexOf("=");
85
+ if (eqIndex !== -1) {
86
+ const key = labelStr.slice(0, eqIndex);
87
+ const value = labelStr.slice(eqIndex + 1);
88
+ labelFilters[key] = value;
89
+ }
90
+ }
91
+ return labelFilters;
92
+ }
93
+ export function buildAgentLsFetchOptions(options) {
94
+ const labelFilters = parseLabelFilters(options.label);
95
+ const normalizedThinkingOptionId = options.thinking?.trim();
96
+ const daemonFilter = {};
97
+ if (options.all) {
98
+ daemonFilter.includeArchived = true;
99
+ }
100
+ if (Object.keys(labelFilters).length > 0) {
101
+ daemonFilter.labels = labelFilters;
102
+ }
103
+ if (normalizedThinkingOptionId) {
104
+ daemonFilter.thinkingOptionId = normalizedThinkingOptionId;
105
+ }
106
+ const fetchOptions = {};
107
+ if (!options.global) {
108
+ fetchOptions.scope = "active";
109
+ }
110
+ if (Object.keys(daemonFilter).length > 0) {
111
+ fetchOptions.filter = daemonFilter;
112
+ }
113
+ return fetchOptions;
114
+ }
115
+ /**
116
+ * Agent ls command semantics:
117
+ * - `otto agent ls` → active non-archived agents
118
+ * - `otto agent ls -g` → global non-archived agents
119
+ * - `otto agent ls -a` → active agents, including archived
120
+ * - `otto agent ls -ag` → global agents, including archived
121
+ */
122
+ export async function runLsCommand(options, _command) {
123
+ const host = getDaemonHost({ host: options.host });
124
+ let client;
125
+ try {
126
+ client = await connectToDaemon({ host: options.host });
127
+ }
128
+ catch (err) {
129
+ const message = err instanceof Error ? err.message : String(err);
130
+ const error = {
131
+ code: "DAEMON_NOT_RUNNING",
132
+ message: `Cannot connect to daemon at ${host}: ${message}`,
133
+ details: "Start the daemon with: otto daemon start\nFor a remote daemon, pass --host <host:port> or set OTTO_HOST.",
134
+ };
135
+ throw error;
136
+ }
137
+ try {
138
+ const normalizedThinkingOptionId = options.thinking?.trim();
139
+ if (options.thinking !== undefined && !normalizedThinkingOptionId) {
140
+ const error = {
141
+ code: "INVALID_THINKING_OPTION",
142
+ message: "--thinking cannot be empty",
143
+ };
144
+ throw error;
145
+ }
146
+ const labelFilters = parseLabelFilters(options.label);
147
+ const fetchPayload = await client.fetchAgents(buildAgentLsFetchOptions(options));
148
+ let agents = fetchPayload.entries.map((entry) => entry.agent);
149
+ // By default, exclude archived agents. `-a` includes them.
150
+ if (!options.all) {
151
+ agents = agents.filter((a) => !a.archivedAt);
152
+ }
153
+ // If explicit status filter is provided, apply it.
154
+ if (options.status) {
155
+ agents = agents.filter((a) => a.status === options.status);
156
+ }
157
+ // Optional cwd filter.
158
+ if (options.cwd) {
159
+ agents = agents.filter((a) => isSameOrDescendantPath(options.cwd, a.cwd));
160
+ }
161
+ // Apply label filtering only when explicitly requested.
162
+ if (Object.keys(labelFilters).length > 0) {
163
+ agents = agents.filter((a) => {
164
+ const agentLabels = a.labels;
165
+ for (const [key, value] of Object.entries(labelFilters)) {
166
+ if (agentLabels[key] !== value) {
167
+ return false;
168
+ }
169
+ }
170
+ return true;
171
+ });
172
+ }
173
+ await client.close();
174
+ // Sort agents: running first, then idle, then others; within each group, most recent first
175
+ const statusOrder = { running: 0, idle: 1 };
176
+ agents.sort((a, b) => {
177
+ // Primary sort: by status
178
+ const aOrder = statusOrder[a.status] ?? 999;
179
+ const bOrder = statusOrder[b.status] ?? 999;
180
+ if (aOrder !== bOrder)
181
+ return aOrder - bOrder;
182
+ // Secondary sort: by creation time (most recent first)
183
+ const aTime = new Date(a.createdAt).getTime();
184
+ const bTime = new Date(b.createdAt).getTime();
185
+ return bTime - aTime;
186
+ });
187
+ const items = agents.map(toListItem);
188
+ return {
189
+ type: "list",
190
+ data: items,
191
+ schema: agentLsSchema,
192
+ };
193
+ }
194
+ catch (err) {
195
+ await client.close().catch(() => { });
196
+ const message = err instanceof Error ? err.message : String(err);
197
+ const error = {
198
+ code: "LIST_AGENTS_FAILED",
199
+ message: `Failed to list agents: ${message}`,
200
+ };
201
+ throw error;
202
+ }
203
+ }
204
+ //# sourceMappingURL=ls.js.map
@@ -0,0 +1,18 @@
1
+ import type { Command } from "commander";
2
+ import type { CommandOptions, OutputSchema, AnyCommandResult } from "../../output/index.js";
3
+ import type { AgentMode } from "@otto-code/protocol/agent-types";
4
+ /** Result for setting mode */
5
+ export interface SetModeResult {
6
+ agentId: string;
7
+ mode: string;
8
+ }
9
+ /** Schema for mode list output */
10
+ export declare const modeListSchema: OutputSchema<AgentMode>;
11
+ /** Schema for set mode output */
12
+ export declare const setModeSchema: OutputSchema<SetModeResult>;
13
+ export interface AgentModeOptions extends CommandOptions {
14
+ list?: boolean;
15
+ }
16
+ export type AgentModeResult = AnyCommandResult<any>;
17
+ export declare function runModeCommand(id: string, mode: string | undefined, options: AgentModeOptions, _command: Command): Promise<AgentModeResult>;
18
+ //# sourceMappingURL=mode.d.ts.map
@@ -0,0 +1,100 @@
1
+ import { connectToDaemon, getDaemonHost } from "../../utils/client.js";
2
+ /** Schema for mode list output */
3
+ export const modeListSchema = {
4
+ idField: "id",
5
+ columns: [
6
+ { header: "MODE", field: "id", width: 15 },
7
+ { header: "LABEL", field: "label", width: 25 },
8
+ { header: "DESCRIPTION", field: "description", width: 40 },
9
+ ],
10
+ };
11
+ /** Schema for set mode output */
12
+ export const setModeSchema = {
13
+ idField: "agentId",
14
+ columns: [
15
+ { header: "AGENT ID", field: "agentId", width: 12 },
16
+ { header: "MODE", field: "mode", width: 20 },
17
+ ],
18
+ };
19
+ const missingModeError = () => ({
20
+ code: "MISSING_ARGUMENT",
21
+ message: "Mode argument required unless --list is specified",
22
+ details: "Usage: otto agent mode <id> <mode> | otto agent mode --list <id>",
23
+ });
24
+ export async function runModeCommand(id, mode, options, _command) {
25
+ const normalizedMode = mode?.trim();
26
+ const host = getDaemonHost({ host: options.host });
27
+ // Validate arguments
28
+ if (!options.list && !normalizedMode) {
29
+ throw missingModeError();
30
+ }
31
+ let client;
32
+ try {
33
+ client = await connectToDaemon({ host: options.host });
34
+ const fetchResult = await client.fetchAgent({ agentId: id });
35
+ if (!fetchResult) {
36
+ const error = {
37
+ code: "AGENT_NOT_FOUND",
38
+ message: `No agent found matching: ${id}`,
39
+ details: "Use `otto ls` to list available agents",
40
+ };
41
+ throw error;
42
+ }
43
+ const agent = fetchResult.agent;
44
+ const resolvedId = agent.id;
45
+ if (options.list) {
46
+ // List available modes for this agent
47
+ const availableModes = agent.availableModes ?? [];
48
+ const items = availableModes.map((m) => ({
49
+ id: m.id,
50
+ label: m.label,
51
+ description: m.description,
52
+ }));
53
+ return {
54
+ type: "list",
55
+ data: items,
56
+ schema: modeListSchema,
57
+ };
58
+ }
59
+ if (!normalizedMode) {
60
+ throw missingModeError();
61
+ }
62
+ // Set the agent mode
63
+ await client.setAgentMode(resolvedId, normalizedMode);
64
+ return {
65
+ type: "single",
66
+ data: {
67
+ agentId: resolvedId.slice(0, 7),
68
+ mode: normalizedMode,
69
+ },
70
+ schema: setModeSchema,
71
+ };
72
+ }
73
+ catch (err) {
74
+ // Re-throw if it's already a CommandError
75
+ if (err && typeof err === "object" && "code" in err) {
76
+ throw err;
77
+ }
78
+ if (!client) {
79
+ const message = err instanceof Error ? err.message : String(err);
80
+ const error = {
81
+ code: "DAEMON_NOT_RUNNING",
82
+ message: `Cannot connect to daemon at ${host}: ${message}`,
83
+ details: "Start the daemon with: otto daemon start",
84
+ };
85
+ throw error;
86
+ }
87
+ const message = err instanceof Error ? err.message : String(err);
88
+ const error = {
89
+ code: "MODE_OPERATION_FAILED",
90
+ message: `Failed to ${options.list ? "list modes" : "set mode"}: ${message}`,
91
+ };
92
+ throw error;
93
+ }
94
+ finally {
95
+ if (client) {
96
+ await client.close().catch(() => { });
97
+ }
98
+ }
99
+ }
100
+ //# sourceMappingURL=mode.js.map
@@ -0,0 +1,15 @@
1
+ import { Command } from "commander";
2
+ import type { CommandOptions, SingleResult, OutputSchema } from "../../output/index.js";
3
+ export interface AgentReloadResult {
4
+ agentId: string;
5
+ status: "reloaded";
6
+ timelineSize: number;
7
+ }
8
+ export declare const reloadSchema: OutputSchema<AgentReloadResult>;
9
+ export declare function addReloadOptions(cmd: Command): Command;
10
+ export interface AgentReloadOptions extends CommandOptions {
11
+ host?: string;
12
+ }
13
+ export type AgentReloadCommandResult = SingleResult<AgentReloadResult>;
14
+ export declare function runReloadCommand(agentIdArg: string, options: AgentReloadOptions, _command: Command): Promise<AgentReloadCommandResult>;
15
+ //# sourceMappingURL=reload.d.ts.map
@@ -0,0 +1,75 @@
1
+ import { connectToDaemon, getDaemonHost, resolveAgentId } from "../../utils/client.js";
2
+ export const reloadSchema = {
3
+ idField: "agentId",
4
+ columns: [
5
+ { header: "AGENT ID", field: "agentId" },
6
+ { header: "STATUS", field: "status" },
7
+ { header: "TIMELINE", field: "timelineSize" },
8
+ ],
9
+ };
10
+ export function addReloadOptions(cmd) {
11
+ return cmd
12
+ .description("Reload an agent (restarts the underlying process)")
13
+ .argument("<id>", "Agent ID, prefix, or name");
14
+ }
15
+ export async function runReloadCommand(agentIdArg, options, _command) {
16
+ const host = getDaemonHost({ host: options.host });
17
+ if (!agentIdArg || agentIdArg.trim().length === 0) {
18
+ const error = {
19
+ code: "MISSING_AGENT_ID",
20
+ message: "Agent ID is required",
21
+ details: "Usage: otto agent reload <id-or-name>",
22
+ };
23
+ throw error;
24
+ }
25
+ let client;
26
+ try {
27
+ client = await connectToDaemon({ host: options.host });
28
+ }
29
+ catch (err) {
30
+ const message = err instanceof Error ? err.message : String(err);
31
+ const error = {
32
+ code: "DAEMON_NOT_RUNNING",
33
+ message: `Cannot connect to daemon at ${host}: ${message}`,
34
+ details: "Start the daemon with: otto daemon start",
35
+ };
36
+ throw error;
37
+ }
38
+ try {
39
+ const agentsPayload = await client.fetchAgents({ filter: { includeArchived: true } });
40
+ const agents = agentsPayload.entries.map((entry) => entry.agent);
41
+ const agentId = resolveAgentId(agentIdArg, agents);
42
+ if (!agentId) {
43
+ const error = {
44
+ code: "AGENT_NOT_FOUND",
45
+ message: `Agent not found: ${agentIdArg}`,
46
+ details: 'Use "otto ls" to list available agents',
47
+ };
48
+ throw error;
49
+ }
50
+ const result = await client.refreshAgent(agentId);
51
+ await client.close();
52
+ return {
53
+ type: "single",
54
+ data: {
55
+ agentId: result.agentId,
56
+ status: "reloaded",
57
+ timelineSize: result.timelineSize ?? 0,
58
+ },
59
+ schema: reloadSchema,
60
+ };
61
+ }
62
+ catch (err) {
63
+ await client.close().catch(() => { });
64
+ if (err && typeof err === "object" && "code" in err) {
65
+ throw err;
66
+ }
67
+ const message = err instanceof Error ? err.message : String(err);
68
+ const error = {
69
+ code: "RELOAD_FAILED",
70
+ message: `Failed to reload agent: ${message}`,
71
+ };
72
+ throw error;
73
+ }
74
+ }
75
+ //# sourceMappingURL=reload.js.map
@@ -0,0 +1,44 @@
1
+ import { Command } from "commander";
2
+ import { connectToDaemon } from "../../utils/client.js";
3
+ import type { CommandOptions, SingleResult, OutputSchema } from "../../output/index.js";
4
+ export { resolveProviderAndModel } from "../../utils/provider-model.js";
5
+ export declare function addRunOptions(cmd: Command): Command;
6
+ /** Result type for agent run command */
7
+ export interface AgentRunResult {
8
+ agentId: string;
9
+ status: "created" | "running" | "completed" | "timeout" | "permission" | "error";
10
+ provider: string;
11
+ cwd: string;
12
+ title: string | null;
13
+ }
14
+ /** Schema for agent run output */
15
+ export declare const agentRunSchema: OutputSchema<AgentRunResult>;
16
+ export interface AgentRunOptions extends CommandOptions {
17
+ detach?: boolean;
18
+ title?: string;
19
+ name?: string;
20
+ provider?: string;
21
+ model?: string;
22
+ thinking?: string;
23
+ mode?: string;
24
+ worktree?: string;
25
+ base?: string;
26
+ workspace?: string;
27
+ image?: string[];
28
+ cwd?: string;
29
+ env?: string[];
30
+ label?: string[];
31
+ waitTimeout?: string;
32
+ outputSchema?: string;
33
+ }
34
+ type ConnectedDaemonClient = Awaited<ReturnType<typeof connectToDaemon>>;
35
+ export interface StructuredResponseTimelineClient {
36
+ fetchAgentTimeline: ConnectedDaemonClient["fetchAgentTimeline"];
37
+ }
38
+ export declare function resolveStructuredResponseMessage(options: {
39
+ client: StructuredResponseTimelineClient;
40
+ agentId: string;
41
+ lastMessage: string | null;
42
+ }): Promise<string | null>;
43
+ export declare function runRunCommand(prompt: string, options: AgentRunOptions, _command: Command): Promise<SingleResult<AgentRunResult>>;
44
+ //# sourceMappingURL=run.d.ts.map