@phnx-labs/agents-cli 1.20.64 → 1.20.66

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 (188) hide show
  1. package/CHANGELOG.md +51 -3
  2. package/README.md +156 -3
  3. package/dist/bin/agents +0 -0
  4. package/dist/commands/apply.d.ts +12 -0
  5. package/dist/commands/apply.js +274 -0
  6. package/dist/commands/browser.js +2 -2
  7. package/dist/commands/cloud.js +32 -2
  8. package/dist/commands/doctor.js +4 -1
  9. package/dist/commands/exec.d.ts +48 -0
  10. package/dist/commands/exec.js +159 -49
  11. package/dist/commands/feed.js +25 -11
  12. package/dist/commands/hosts.js +44 -6
  13. package/dist/commands/mcp.js +55 -5
  14. package/dist/commands/monitors.d.ts +12 -0
  15. package/dist/commands/monitors.js +748 -0
  16. package/dist/commands/output.js +2 -2
  17. package/dist/commands/plugins.js +28 -7
  18. package/dist/commands/routines.js +23 -2
  19. package/dist/commands/secrets.d.ts +16 -0
  20. package/dist/commands/secrets.js +215 -64
  21. package/dist/commands/serve.js +31 -0
  22. package/dist/commands/sessions-browser.d.ts +82 -0
  23. package/dist/commands/sessions-browser.js +320 -0
  24. package/dist/commands/sessions-export.js +8 -3
  25. package/dist/commands/sessions.d.ts +17 -0
  26. package/dist/commands/sessions.js +157 -10
  27. package/dist/commands/share.d.ts +2 -0
  28. package/dist/commands/share.js +150 -0
  29. package/dist/commands/ssh.js +54 -3
  30. package/dist/commands/versions.js +7 -3
  31. package/dist/commands/view.d.ts +26 -0
  32. package/dist/commands/view.js +32 -9
  33. package/dist/commands/webhook.js +10 -2
  34. package/dist/index.js +35 -14
  35. package/dist/lib/agents.d.ts +46 -0
  36. package/dist/lib/agents.js +121 -3
  37. package/dist/lib/auto-dispatch-provider.js +7 -2
  38. package/dist/lib/auto-dispatch.d.ts +3 -0
  39. package/dist/lib/auto-dispatch.js +3 -0
  40. package/dist/lib/browser/chrome.js +2 -2
  41. package/dist/lib/cloud/antigravity.js +2 -2
  42. package/dist/lib/cloud/host.d.ts +59 -0
  43. package/dist/lib/cloud/host.js +224 -0
  44. package/dist/lib/cloud/registry.js +4 -0
  45. package/dist/lib/cloud/types.d.ts +6 -4
  46. package/dist/lib/computer-rpc.js +3 -1
  47. package/dist/lib/crabbox/cli.js +5 -1
  48. package/dist/lib/crabbox/runtimes.js +11 -2
  49. package/dist/lib/daemon.d.ts +20 -4
  50. package/dist/lib/daemon.js +62 -19
  51. package/dist/lib/devices/connect.d.ts +18 -1
  52. package/dist/lib/devices/connect.js +10 -2
  53. package/dist/lib/devices/fleet.d.ts +3 -2
  54. package/dist/lib/devices/fleet.js +9 -0
  55. package/dist/lib/devices/known-hosts.d.ts +62 -0
  56. package/dist/lib/devices/known-hosts.js +137 -0
  57. package/dist/lib/devices/registry.d.ts +15 -0
  58. package/dist/lib/devices/registry.js +9 -0
  59. package/dist/lib/exec.d.ts +19 -2
  60. package/dist/lib/exec.js +41 -13
  61. package/dist/lib/fleet/apply.d.ts +63 -0
  62. package/dist/lib/fleet/apply.js +214 -0
  63. package/dist/lib/fleet/auth-sync.d.ts +67 -0
  64. package/dist/lib/fleet/auth-sync.js +142 -0
  65. package/dist/lib/fleet/manifest.d.ts +29 -0
  66. package/dist/lib/fleet/manifest.js +127 -0
  67. package/dist/lib/fleet/types.d.ts +129 -0
  68. package/dist/lib/fleet/types.js +13 -0
  69. package/dist/lib/git.d.ts +27 -0
  70. package/dist/lib/git.js +34 -2
  71. package/dist/lib/hosts/dispatch.d.ts +29 -8
  72. package/dist/lib/hosts/dispatch.js +66 -20
  73. package/dist/lib/hosts/passthrough.js +2 -0
  74. package/dist/lib/hosts/providers/devices.d.ts +27 -0
  75. package/dist/lib/hosts/providers/devices.js +98 -0
  76. package/dist/lib/hosts/registry.d.ts +10 -16
  77. package/dist/lib/hosts/registry.js +17 -50
  78. package/dist/lib/hosts/remote-cmd.d.ts +23 -0
  79. package/dist/lib/hosts/remote-cmd.js +79 -4
  80. package/dist/lib/hosts/run-target.d.ts +84 -0
  81. package/dist/lib/hosts/run-target.js +99 -0
  82. package/dist/lib/hosts/types.d.ts +23 -5
  83. package/dist/lib/hosts/types.js +22 -4
  84. package/dist/lib/linear-autoclose.d.ts +30 -0
  85. package/dist/lib/linear-autoclose.js +22 -0
  86. package/dist/lib/mcp.d.ts +27 -1
  87. package/dist/lib/mcp.js +126 -12
  88. package/dist/lib/monitors/config.d.ts +161 -0
  89. package/dist/lib/monitors/config.js +372 -0
  90. package/dist/lib/monitors/dispatch.d.ts +28 -0
  91. package/dist/lib/monitors/dispatch.js +91 -0
  92. package/dist/lib/monitors/engine.d.ts +61 -0
  93. package/dist/lib/monitors/engine.js +205 -0
  94. package/dist/lib/monitors/sources/command.d.ts +11 -0
  95. package/dist/lib/monitors/sources/command.js +31 -0
  96. package/dist/lib/monitors/sources/device.d.ts +13 -0
  97. package/dist/lib/monitors/sources/device.js +45 -0
  98. package/dist/lib/monitors/sources/file.d.ts +14 -0
  99. package/dist/lib/monitors/sources/file.js +57 -0
  100. package/dist/lib/monitors/sources/http.d.ts +10 -0
  101. package/dist/lib/monitors/sources/http.js +34 -0
  102. package/dist/lib/monitors/sources/index.d.ts +14 -0
  103. package/dist/lib/monitors/sources/index.js +31 -0
  104. package/dist/lib/monitors/sources/poll.d.ts +9 -0
  105. package/dist/lib/monitors/sources/poll.js +9 -0
  106. package/dist/lib/monitors/sources/types.d.ts +18 -0
  107. package/dist/lib/monitors/sources/types.js +9 -0
  108. package/dist/lib/monitors/sources/webhook.d.ts +23 -0
  109. package/dist/lib/monitors/sources/webhook.js +47 -0
  110. package/dist/lib/monitors/sources/ws.d.ts +14 -0
  111. package/dist/lib/monitors/sources/ws.js +45 -0
  112. package/dist/lib/monitors/state.d.ts +69 -0
  113. package/dist/lib/monitors/state.js +144 -0
  114. package/dist/lib/picker.d.ts +53 -0
  115. package/dist/lib/picker.js +214 -1
  116. package/dist/lib/platform/exec.d.ts +16 -0
  117. package/dist/lib/platform/exec.js +17 -0
  118. package/dist/lib/plugins.d.ts +31 -1
  119. package/dist/lib/plugins.js +175 -15
  120. package/dist/lib/redact.d.ts +14 -1
  121. package/dist/lib/redact.js +47 -1
  122. package/dist/lib/remote-agents-json.js +7 -1
  123. package/dist/lib/rotate.d.ts +6 -3
  124. package/dist/lib/rotate.js +0 -1
  125. package/dist/lib/routines.d.ts +16 -0
  126. package/dist/lib/routines.js +19 -0
  127. package/dist/lib/runner.d.ts +1 -0
  128. package/dist/lib/runner.js +102 -9
  129. package/dist/lib/secrets/agent.d.ts +83 -10
  130. package/dist/lib/secrets/agent.js +237 -70
  131. package/dist/lib/secrets/bundles.d.ts +26 -0
  132. package/dist/lib/secrets/bundles.js +59 -8
  133. package/dist/lib/secrets/filestore.d.ts +9 -0
  134. package/dist/lib/secrets/filestore.js +21 -8
  135. package/dist/lib/secrets/index.d.ts +7 -0
  136. package/dist/lib/secrets/index.js +26 -6
  137. package/dist/lib/secrets/mcp.js +4 -2
  138. package/dist/lib/secrets/remote.d.ts +17 -0
  139. package/dist/lib/secrets/remote.js +40 -0
  140. package/dist/lib/self-update.d.ts +20 -0
  141. package/dist/lib/self-update.js +54 -1
  142. package/dist/lib/serve/control.d.ts +95 -0
  143. package/dist/lib/serve/control.js +260 -0
  144. package/dist/lib/serve/server.d.ts +35 -1
  145. package/dist/lib/serve/server.js +106 -76
  146. package/dist/lib/serve/stream.d.ts +43 -0
  147. package/dist/lib/serve/stream.js +116 -0
  148. package/dist/lib/serve/token.d.ts +35 -0
  149. package/dist/lib/serve/token.js +85 -0
  150. package/dist/lib/session/bundle.d.ts +14 -0
  151. package/dist/lib/session/bundle.js +12 -1
  152. package/dist/lib/session/remote-list.js +5 -1
  153. package/dist/lib/session/state.d.ts +7 -25
  154. package/dist/lib/session/state.js +16 -6
  155. package/dist/lib/session/sync/config.js +8 -2
  156. package/dist/lib/session/types.d.ts +30 -0
  157. package/dist/lib/share/capture.d.ts +29 -0
  158. package/dist/lib/share/capture.js +140 -0
  159. package/dist/lib/share/config.d.ts +35 -0
  160. package/dist/lib/share/config.js +100 -0
  161. package/dist/lib/share/og.d.ts +25 -0
  162. package/dist/lib/share/og.js +84 -0
  163. package/dist/lib/share/provision.d.ts +10 -0
  164. package/dist/lib/share/provision.js +91 -0
  165. package/dist/lib/share/publish.d.ts +57 -0
  166. package/dist/lib/share/publish.js +145 -0
  167. package/dist/lib/share/worker-template.d.ts +2 -0
  168. package/dist/lib/share/worker-template.js +82 -0
  169. package/dist/lib/shims.d.ts +13 -0
  170. package/dist/lib/shims.js +42 -2
  171. package/dist/lib/ssh-exec.d.ts +24 -0
  172. package/dist/lib/ssh-exec.js +15 -3
  173. package/dist/lib/ssh-tunnel.d.ts +19 -1
  174. package/dist/lib/ssh-tunnel.js +86 -7
  175. package/dist/lib/startup/command-registry.d.ts +3 -0
  176. package/dist/lib/startup/command-registry.js +6 -0
  177. package/dist/lib/state.d.ts +5 -0
  178. package/dist/lib/state.js +12 -0
  179. package/dist/lib/tmux/session.d.ts +7 -0
  180. package/dist/lib/tmux/session.js +3 -1
  181. package/dist/lib/triggers/webhook.d.ts +18 -0
  182. package/dist/lib/triggers/webhook.js +105 -0
  183. package/dist/lib/types.d.ts +36 -1
  184. package/dist/lib/usage.js +7 -5
  185. package/dist/lib/versions.js +14 -11
  186. package/dist/lib/workflows.d.ts +20 -0
  187. package/dist/lib/workflows.js +24 -0
  188. package/package.json +2 -1
package/dist/lib/mcp.js CHANGED
@@ -12,9 +12,9 @@ import * as path from 'path';
12
12
  import * as yaml from 'yaml';
13
13
  import { execFileSync } from 'child_process';
14
14
  import * as os from 'os';
15
- import { getMcpDir, getUserMcpDir, getProjectAgentsDir, getVersionsDir } from './state.js';
15
+ import { getMcpDir, getUserMcpDir, getProjectAgentsDir, getVersionsDir, getUserAgentsDir } from './state.js';
16
16
  import { getBinaryPath, getVersionHomePath } from './versions.js';
17
- import { IS_WINDOWS, needsWindowsShell } from './platform/index.js';
17
+ import { IS_WINDOWS, execFileShellSpec } from './platform/index.js';
18
18
  import { AGENTS } from './agents.js';
19
19
  import { isCapable } from './capabilities.js';
20
20
  import { setGeminiAutoUpdateDisabled, updateGeminiSettings } from './gemini-settings.js';
@@ -93,13 +93,116 @@ function isStringRecord(value) {
93
93
  return false;
94
94
  return Object.values(value).every((item) => typeof item === 'string');
95
95
  }
96
+ // ─── Project MCP trust (RUSH-1776) ───────────────────────────────────────────
97
+ // Project-scoped MCP configs (<repo>/.agents/mcp/*.yaml) are UNTRUSTED by
98
+ // default. An MCP server is an arbitrary command spawned under the agent's
99
+ // authority, so merely cloning a hostile repo must never auto-register or run
100
+ // it. A project's MCP servers enter the register/spawn path only after the user
101
+ // explicitly trusts that project (`agents mcp trust`), recorded in a user-owned
102
+ // store OUTSIDE any repo so a cloned repo can't grant itself trust. User- and
103
+ // system-scoped MCPs (~/.agents/mcp/*) are always trusted.
104
+ /** Path to the user-owned project-trust store (never inside a repo). */
105
+ export function getMcpTrustStorePath() {
106
+ return path.join(getUserAgentsDir(), 'mcp-trust.yaml');
107
+ }
108
+ /**
109
+ * Key a project by its ROOT (parent of `.agents/`), resolved through symlinks
110
+ * so the key is stable no matter how the cwd was spelled.
111
+ */
112
+ function normalizeProjectKey(projectAgentsDir) {
113
+ const root = path.dirname(projectAgentsDir);
114
+ try {
115
+ return fs.realpathSync(root);
116
+ }
117
+ catch {
118
+ return path.resolve(root);
119
+ }
120
+ }
121
+ function readTrustedProjects() {
122
+ const storePath = getMcpTrustStorePath();
123
+ if (!fs.existsSync(storePath))
124
+ return new Set();
125
+ let parsed;
126
+ try {
127
+ parsed = yaml.parse(fs.readFileSync(storePath, 'utf-8'));
128
+ }
129
+ catch {
130
+ return new Set();
131
+ }
132
+ const list = parsed && typeof parsed === 'object' && Array.isArray(parsed.trustedProjects)
133
+ ? parsed.trustedProjects
134
+ : [];
135
+ const out = new Set();
136
+ for (const entry of list) {
137
+ if (typeof entry !== 'string' || entry.length === 0)
138
+ continue;
139
+ try {
140
+ out.add(fs.realpathSync(entry));
141
+ }
142
+ catch {
143
+ out.add(path.resolve(entry));
144
+ }
145
+ }
146
+ return out;
147
+ }
148
+ function writeTrustedProjects(trusted) {
149
+ const storePath = getMcpTrustStorePath();
150
+ fs.mkdirSync(path.dirname(storePath), { recursive: true });
151
+ fs.writeFileSync(storePath, yaml.stringify({ trustedProjects: Array.from(trusted).sort() }), 'utf-8');
152
+ }
153
+ /**
154
+ * Whether the project that owns `projectAgentsDir` has been explicitly trusted
155
+ * for MCP auto-apply. Untrusted by default (fail closed).
156
+ */
157
+ export function isProjectMcpTrusted(projectAgentsDir) {
158
+ return readTrustedProjects().has(normalizeProjectKey(projectAgentsDir));
159
+ }
160
+ /**
161
+ * Record explicit trust for the project containing `cwd` so its project-scoped
162
+ * MCP servers may be registered/spawned. Returns the trusted project root, or
163
+ * null when `cwd` is not inside a project (no `.agents/` to trust).
164
+ */
165
+ export function trustProjectMcp(cwd = process.cwd()) {
166
+ const projectAgentsDir = getProjectAgentsDir(cwd);
167
+ if (!projectAgentsDir)
168
+ return null;
169
+ const key = normalizeProjectKey(projectAgentsDir);
170
+ const trusted = readTrustedProjects();
171
+ if (!trusted.has(key)) {
172
+ trusted.add(key);
173
+ writeTrustedProjects(trusted);
174
+ }
175
+ return key;
176
+ }
177
+ /** Revoke MCP trust for the project containing `cwd`. Returns true if it was trusted. */
178
+ export function untrustProjectMcp(cwd = process.cwd()) {
179
+ const projectAgentsDir = getProjectAgentsDir(cwd);
180
+ if (!projectAgentsDir)
181
+ return false;
182
+ const key = normalizeProjectKey(projectAgentsDir);
183
+ const trusted = readTrustedProjects();
184
+ if (!trusted.delete(key))
185
+ return false;
186
+ writeTrustedProjects(trusted);
187
+ return true;
188
+ }
96
189
  /**
97
190
  * List all MCP server configs from ~/.agents/mcp/.
191
+ *
192
+ * When `enforceProjectTrust` is set, project-scoped configs are included only
193
+ * for a project the user has explicitly trusted (see `isProjectMcpTrusted`) —
194
+ * this is the choke point that keeps an untrusted cloned repo's MCP servers out
195
+ * of the register/spawn path. It ALSO fixes name-collision shadowing: an
196
+ * untrusted project entry is dropped before dedup, so it can never mask a
197
+ * same-named user entry. Display callers omit the flag to surface project
198
+ * entries (command+args and all) regardless of trust.
98
199
  */
99
- export function listMcpServerConfigs(cwd = process.cwd()) {
200
+ export function listMcpServerConfigs(cwd = process.cwd(), options = {}) {
100
201
  const dirs = [];
101
202
  const projectAgentsDir = getProjectAgentsDir(cwd);
102
- if (projectAgentsDir) {
203
+ const includeProject = projectAgentsDir !== null
204
+ && (!options.enforceProjectTrust || isProjectMcpTrusted(projectAgentsDir));
205
+ if (projectAgentsDir && includeProject) {
103
206
  dirs.push({ scope: 'project', dir: path.join(projectAgentsDir, 'mcp') });
104
207
  }
105
208
  // User dir first (wins on name collision), then system
@@ -175,7 +278,10 @@ export function installMcpConfigCentrally(sourcePath) {
175
278
  * Otherwise returns all servers.
176
279
  */
177
280
  export function getMcpServersByName(names, options = {}) {
178
- const allServers = listMcpServerConfigs(options.cwd);
281
+ // This feeds the register/spawn path (installMcpServers, workflow assembly),
282
+ // so untrusted project-scoped servers are excluded by default (fail closed).
283
+ const enforceProjectTrust = options.enforceProjectTrust ?? true;
284
+ const allServers = listMcpServerConfigs(options.cwd, { enforceProjectTrust });
179
285
  if (!names || names.length === 0) {
180
286
  return allServers;
181
287
  }
@@ -228,20 +334,24 @@ function installMcpViaClaude(binaryPath, server, versionHome) {
228
334
  server.config.command,
229
335
  ...(server.config.args || [])
230
336
  ];
231
- execFileSync(binaryPath, args, {
337
+ // RUSH-1752: user-controlled MCP command/args must not reach cmd.exe unquoted.
338
+ const spec = execFileShellSpec(binaryPath, args);
339
+ execFileSync(spec.command, spec.args, {
232
340
  stdio: 'pipe',
233
341
  timeout: 30000,
234
342
  env: execEnv,
235
- shell: needsWindowsShell(binaryPath),
343
+ shell: spec.shell,
236
344
  });
237
345
  }
238
346
  else {
239
347
  // claude mcp add --scope user --transport http -- <name> <url>
240
- execFileSync(binaryPath, ['mcp', 'add', '--scope', 'user', '--transport', 'http', '--', server.name, server.config.url], {
348
+ const httpArgs = ['mcp', 'add', '--scope', 'user', '--transport', 'http', '--', server.name, server.config.url];
349
+ const spec = execFileShellSpec(binaryPath, httpArgs);
350
+ execFileSync(spec.command, spec.args, {
241
351
  stdio: 'pipe',
242
352
  timeout: 30000,
243
353
  env: execEnv,
244
- shell: needsWindowsShell(binaryPath),
354
+ shell: spec.shell,
245
355
  });
246
356
  }
247
357
  }
@@ -259,11 +369,13 @@ function installMcpViaCodex(binaryPath, server, versionHome) {
259
369
  server.config.command,
260
370
  ...(server.config.args || [])
261
371
  ];
262
- execFileSync(binaryPath, args, {
372
+ // RUSH-1752: user-controlled MCP command/args must not reach cmd.exe unquoted.
373
+ const spec = execFileShellSpec(binaryPath, args);
374
+ execFileSync(spec.command, spec.args, {
263
375
  stdio: 'pipe',
264
376
  timeout: 30000,
265
377
  env: { ...process.env, HOME: versionHome },
266
- shell: needsWindowsShell(binaryPath),
378
+ shell: spec.shell,
267
379
  });
268
380
  }
269
381
  // Note: Codex may not support HTTP MCPs
@@ -314,7 +426,9 @@ function registerMcpCommand(agentId, name, commandSpec, scope, transport, option
314
426
  ? ['mcp', 'add', '--transport', transport, '--scope', scope, '--', name, ...commandArgs]
315
427
  : ['mcp', 'add', '--', name, ...commandArgs];
316
428
  const env = options.home ? { ...process.env, HOME: options.home } : process.env;
317
- execFileSync(bin, args, { stdio: 'pipe', timeout: 30000, env, shell: needsWindowsShell(bin) });
429
+ // RUSH-1752: user-controlled MCP command/args must not reach cmd.exe unquoted.
430
+ const spec = execFileShellSpec(bin, args);
431
+ execFileSync(spec.command, spec.args, { stdio: 'pipe', timeout: 30000, env, shell: spec.shell });
318
432
  return { success: true };
319
433
  }
320
434
  catch (err) {
@@ -0,0 +1,161 @@
1
+ /**
2
+ * Monitor (event-triggered watcher) configuration, validation, and CRUD.
3
+ *
4
+ * A monitor is a routine whose trigger is a *watched source* instead of a
5
+ * *clock*. It watches a SOURCE, detects a CONDITION change, and fires an ACTION —
6
+ * reusing the routines daemon, dispatch engine, device model, and notify path.
7
+ *
8
+ * Monitors are YAML files in ~/.agents/monitors/. This module owns the on-disk
9
+ * shape (mirroring lib/routines.ts read/write helpers), hand-rolled validation
10
+ * (mirroring validateJob — no zod), and the device-owner eligibility gate.
11
+ */
12
+ import type { AgentId } from '../types.js';
13
+ /** Source types a monitor can watch. */
14
+ export type MonitorSourceType = 'command' | 'poll' | 'poll-http' | 'webhook' | 'ws' | 'file' | 'device';
15
+ /** Webhook source filters — reuse the github/linear matcher shape from triggers/webhook.ts. */
16
+ export interface MonitorWebhookSource {
17
+ source: 'github' | 'linear';
18
+ event: string;
19
+ repo?: string;
20
+ branch?: string;
21
+ action?: string;
22
+ teamKey?: string;
23
+ label?: string;
24
+ }
25
+ /**
26
+ * What a monitor watches. Exactly one source-payload field is populated, keyed by
27
+ * `type`: `command`/`interval` for command/poll, `url`/`interval` for poll-http,
28
+ * `wsUrl` for ws, `path` for file, `device` for device, `webhook` for webhook.
29
+ */
30
+ export interface MonitorSource {
31
+ type: MonitorSourceType;
32
+ /** Shell command whose stdout is the observation (command, poll). */
33
+ command?: string;
34
+ /** Re-evaluation interval (poll, poll-http; optional for command/file/device). e.g. `30s`, `15m`, `8h`. */
35
+ interval?: string;
36
+ /** URL to GET (poll-http). */
37
+ url?: string;
38
+ /** WebSocket URL; each frame is an observation (ws). */
39
+ wsUrl?: string;
40
+ /** File or directory to watch (file). */
41
+ path?: string;
42
+ /** A registered fleet device whose health/reachability is the observation (device). */
43
+ device?: string;
44
+ /** Webhook trigger filters (webhook). */
45
+ webhook?: MonitorWebhookSource;
46
+ }
47
+ /** How an observation becomes a fire. */
48
+ export type MonitorConditionMode = 'on-change' | 'match' | 'every';
49
+ export interface MonitorCondition {
50
+ mode: MonitorConditionMode;
51
+ /** Regex (required for `match` mode) — fire when the observation matches. */
52
+ match?: string;
53
+ /**
54
+ * What counts as "the same event" for de-duplication. When set, the dedupe
55
+ * signature is the first regex match of this expression against the
56
+ * observation (so re-observing the same token is silent); when omitted, the
57
+ * full observation is the signature.
58
+ */
59
+ dedupeKey?: string;
60
+ }
61
+ /** Action types a monitor can fire. */
62
+ export type MonitorActionType = 'run' | 'routine' | 'notify' | 'webhook-out';
63
+ /**
64
+ * What a monitor does on a fire. Shares the run-shaped fields (agent, prompt,
65
+ * mode, effort, timeout) conceptually with JobConfig (lib/routines.ts) so
66
+ * dispatch reuses the routines path (executeJobDetached). The fired event is
67
+ * injected into the prompt as `{event}`.
68
+ */
69
+ export interface ActionConfig {
70
+ type: MonitorActionType;
71
+ /** run: which agent to spawn. */
72
+ agent?: AgentId;
73
+ /** run: the prompt; `{event}` is replaced with the fired event summary. */
74
+ prompt?: string;
75
+ /** run: execution mode (shared with routines). */
76
+ mode?: 'plan' | 'edit' | 'auto' | 'skip' | 'full';
77
+ /** run: reasoning effort (shared with routines). */
78
+ effort?: 'low' | 'medium' | 'high' | 'xhigh' | 'max' | 'auto';
79
+ /** run: kill the action if it runs longer than this (e.g. `10m`). */
80
+ timeout?: string;
81
+ /** routine: name of an existing routine to fire. */
82
+ routine?: string;
83
+ /** notify: channel for the notification (default `telegram`). */
84
+ notifyChannel?: string;
85
+ /** webhook-out: URL to POST the event to. */
86
+ url?: string;
87
+ }
88
+ /** Full monitor configuration (persisted as YAML in ~/.agents/monitors/). */
89
+ export interface MonitorConfig {
90
+ name: string;
91
+ enabled: boolean;
92
+ source: MonitorSource;
93
+ condition: MonitorCondition;
94
+ action: ActionConfig;
95
+ /**
96
+ * Pin-to-one OWNER device — the single machine whose daemon evaluates the
97
+ * source and fires. Exactly-once for v1 (no distributed lock). When set, only
98
+ * that machine is eligible; everywhere else the monitor is inert.
99
+ */
100
+ device?: string;
101
+ /**
102
+ * Fleet allowlist (advanced) — each listed device evaluates and fires
103
+ * independently, like routines' `devices`. Mutually exclusive with `device`.
104
+ */
105
+ devices?: string[];
106
+ /** Execute the ACTION on this machine over SSH (placement), distinct from the owner that fires it. */
107
+ runOn?: string;
108
+ /** Firehose guard: auto-pause the monitor if it fires more than `max` times per `per`. */
109
+ rateLimit?: {
110
+ max: number;
111
+ per: string;
112
+ };
113
+ /** User-defined prompt variables (expanded like routines' variables). */
114
+ variables?: Record<string, string>;
115
+ /** Pin the agent version for `run` actions (omit to use the run strategy). */
116
+ version?: string;
117
+ }
118
+ /**
119
+ * A fired event. `summary` is injected into the action prompt as `{event}`;
120
+ * `payload` carries the structured observation for `webhook-out` and inspection.
121
+ */
122
+ export interface MonitorEvent {
123
+ monitorName: string;
124
+ firedAt: string;
125
+ summary: string;
126
+ payload: Record<string, unknown>;
127
+ }
128
+ /**
129
+ * Parse a human interval string (e.g. `30s`, `15m`, `8h`, `1d`, `1h30m`) into
130
+ * milliseconds. Unlike routines' parseTimeout, seconds are supported (polls tick
131
+ * in seconds). Returns null on empty/unparseable/zero input.
132
+ */
133
+ export declare function parseInterval(interval: string): number | null;
134
+ /**
135
+ * True when the monitor may evaluate + fire on this machine. Owner semantics:
136
+ * `device` (single owner, exactly-once) → only that machine; else `devices`
137
+ * (allowlist) → any listed machine; else unrestricted. Both sides normalize so
138
+ * `Yosemite-S0` and `yosemite-s0.tailnet.ts.net` agree with `yosemite-s0`.
139
+ */
140
+ export declare function monitorRunsOnThisDevice(config: Pick<MonitorConfig, 'device' | 'devices'>): boolean;
141
+ /**
142
+ * Validate a partial monitor config, returning a list of human-readable errors.
143
+ * Hand-rolled like validateJob (lib/routines.ts) — no zod. Rejects: no source,
144
+ * two sources, no action, two actions, match-mode without `match`, plus the
145
+ * per-type field/shape checks.
146
+ */
147
+ export declare function validateMonitor(config: Partial<MonitorConfig>): string[];
148
+ /** List all monitor configs in ~/.agents/monitors/. */
149
+ export declare function listMonitors(): MonitorConfig[];
150
+ /** Read a single monitor config by name. Returns null if not found or corrupt. */
151
+ export declare function readMonitor(name: string): MonitorConfig | null;
152
+ /** Get the filesystem path of a monitor's YAML config, or null if not found. */
153
+ export declare function getMonitorPath(name: string): string | null;
154
+ /** Write a monitor config to disk atomically, omitting fields that match defaults. */
155
+ export declare function writeMonitor(config: MonitorConfig): void;
156
+ /** Delete a monitor config file by name. Returns true if the file existed. */
157
+ export declare function deleteMonitor(name: string): boolean;
158
+ /** Enable or disable a monitor by name. */
159
+ export declare function setMonitorEnabled(name: string, enabled: boolean): void;
160
+ /** Check whether a monitor with the given name exists on disk. */
161
+ export declare function monitorExists(name: string): boolean;