@phnx-labs/agents-cli 1.22.121 → 1.22.122

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 (70) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/README.md +6 -45
  3. package/dist/cli/command-registry.js +0 -2
  4. package/dist/commands/daemon.js +7 -8
  5. package/dist/commands/mailboxes.js +1 -1
  6. package/dist/commands/projects.js +3 -3
  7. package/dist/commands/setup-mine.js +0 -1
  8. package/dist/commands/sync.js +101 -1
  9. package/dist/lib/daemon/daemon.js +1 -16
  10. package/dist/lib/daemon-services.d.ts +1 -1
  11. package/dist/lib/daemon-services.js +0 -5
  12. package/dist/lib/daemon-webhooks.d.ts +1 -1
  13. package/dist/lib/daemon-webhooks.js +1 -1
  14. package/dist/lib/device-config.js +1 -1
  15. package/dist/lib/github/project-prs.js +2 -2
  16. package/dist/lib/hosts/passthrough.js +0 -1
  17. package/dist/lib/plugins/plugins.d.ts +7 -1
  18. package/dist/lib/plugins/plugins.js +26 -5
  19. package/dist/lib/pr-land-detach.js +2 -2
  20. package/dist/lib/refresh.js +4 -1
  21. package/dist/lib/scheduling/routines.d.ts +1 -1
  22. package/dist/lib/scheduling/routines.js +1 -1
  23. package/dist/lib/session/db.d.ts +1 -1
  24. package/dist/lib/session/db.js +51 -28
  25. package/dist/lib/staleness/index.js +12 -0
  26. package/dist/lib/staleness/types.d.ts +5 -0
  27. package/dist/lib/startup/command-registry.js +1 -1
  28. package/dist/lib/state.d.ts +0 -3
  29. package/dist/lib/state.js +0 -6
  30. package/dist/lib/sync-delete.d.ts +21 -0
  31. package/dist/lib/sync-delete.js +113 -0
  32. package/package.json +1 -3
  33. package/dist/commands/monitors.d.ts +0 -2
  34. package/dist/commands/monitors.js +0 -1070
  35. package/dist/lib/daemon/monitor-engine-service.d.ts +0 -13
  36. package/dist/lib/daemon/monitor-engine-service.js +0 -25
  37. package/dist/lib/monitors/config.d.ts +0 -77
  38. package/dist/lib/monitors/config.js +0 -405
  39. package/dist/lib/monitors/dispatch.d.ts +0 -10
  40. package/dist/lib/monitors/dispatch.js +0 -72
  41. package/dist/lib/monitors/engine.d.ts +0 -45
  42. package/dist/lib/monitors/engine.js +0 -243
  43. package/dist/lib/monitors/fingerprint.d.ts +0 -3
  44. package/dist/lib/monitors/fingerprint.js +0 -43
  45. package/dist/lib/monitors/pid-watch.d.ts +0 -4
  46. package/dist/lib/monitors/pid-watch.js +0 -14
  47. package/dist/lib/monitors/remote.d.ts +0 -31
  48. package/dist/lib/monitors/remote.js +0 -63
  49. package/dist/lib/monitors/sources/command.d.ts +0 -4
  50. package/dist/lib/monitors/sources/command.js +0 -20
  51. package/dist/lib/monitors/sources/device.d.ts +0 -3
  52. package/dist/lib/monitors/sources/device.js +0 -31
  53. package/dist/lib/monitors/sources/failure.d.ts +0 -5
  54. package/dist/lib/monitors/sources/failure.js +0 -25
  55. package/dist/lib/monitors/sources/file.d.ts +0 -4
  56. package/dist/lib/monitors/sources/file.js +0 -46
  57. package/dist/lib/monitors/sources/http.d.ts +0 -3
  58. package/dist/lib/monitors/sources/http.js +0 -25
  59. package/dist/lib/monitors/sources/index.d.ts +0 -5
  60. package/dist/lib/monitors/sources/index.js +0 -22
  61. package/dist/lib/monitors/sources/poll.d.ts +0 -1
  62. package/dist/lib/monitors/sources/poll.js +0 -1
  63. package/dist/lib/monitors/sources/types.d.ts +0 -9
  64. package/dist/lib/monitors/sources/types.js +0 -1
  65. package/dist/lib/monitors/sources/webhook.d.ts +0 -3
  66. package/dist/lib/monitors/sources/webhook.js +0 -3
  67. package/dist/lib/monitors/sources/ws.d.ts +0 -4
  68. package/dist/lib/monitors/sources/ws.js +0 -35
  69. package/dist/lib/monitors/state.d.ts +0 -51
  70. package/dist/lib/monitors/state.js +0 -221
package/CHANGELOG.md CHANGED
@@ -1,5 +1,60 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.22.122
4
+
5
+ - **`agents monitors` is removed (PHNX-4241).** The command group, the monitor
6
+ engine, and the daemon's `monitors` service are gone; `agents monitors …` now
7
+ fails as an unknown command. Upgrading stops monitor polling and dispatch: the
8
+ self-updating daemon relaunches onto code with no monitor service, and a stale
9
+ `monitors:` key in `~/.agents/daemon/services.yaml` is ignored. Monitor
10
+ definitions in `~/.agents/monitors/` and fire history in
11
+ `~/.agents/.history/monitors/` are left on disk untouched. Use `agents routines`
12
+ for scheduled work, webhook receivers for push events, and
13
+ `agents projects prs automerge` for merge-on-green. Source: `cli/src/lib/daemon/daemon.ts`,
14
+ `cli/src/lib/daemon-services.ts`, `cli/src/cli/command-registry.ts`.
15
+
16
+ - **`agents sessions stats` ranks a plugin skill under the same name `--zero` lists it.**
17
+ A plugin skill invoked by its bare name (`Skill image` from the `create` plugin) was
18
+ recorded as `image`, while the installed inventory calls it `create:image`, so the
19
+ same skill showed as invoked in the ranked list and as never invoked in `--zero`.
20
+ Usage is now recorded as `<plugin>:<name>` when the plugin is known, and a `/name`
21
+ slash invocation that only resolves to a skill counts as a skill. Existing bare
22
+ rows are renamed when the index opens; run `agents sessions backfill resources` once
23
+ to reclassify older slash-typed skills (the coverage line prompts for it). Source:
24
+ `cli/src/lib/session/db.ts`.
25
+
26
+ - **`agents sync <repo> --delete` removes what a repo deleted.** A plugin, command or
27
+ skill deleted from a DotAgents repo used to stay installed in agent homes, most
28
+ visibly when a non-interactive sync skipped the resource selection. `--delete`
29
+ trashes the ones whose recorded source is in the named repo and is gone from it,
30
+ unregisters removed plugins from `settings.json`, and keeps everything from other
31
+ repos or installed by hand (`kept: N not from <repo>`). It covers plugins, commands and
32
+ skills (not hooks, MCP, subagents, rules or workflows), needs a repo, works
33
+ without a TTY, and previews with `--dry-run`. A sync without `--delete` is
34
+ unchanged. Source: `cli/src/lib/sync-delete.ts`, `cli/src/commands/sync.ts`.
35
+ - **`agents sync` no longer hangs without a terminal.** When new resources were
36
+ pending, a sync with no TTY opened the "Sync new resources?" prompt anyway and
37
+ could wait forever (it never resolved under Bun). It now skips the selection,
38
+ syncs nothing new, and says so: `Skipped resource selection for <agent>@<v> (no
39
+ terminal; rerun with --yes to sync new resources)`.
40
+
41
+ - **Session rows report what an agent made for you to look at.** With
42
+ `@phnx-labs/sessions-cli` 0.6.0, a row's `artifacts` include created images, video,
43
+ PDFs, SVGs and CSVs (the harness scratchpad excluded) and the viewable files of
44
+ folders the agent names in its replies, when they exist under this machine's home
45
+ outside a git checkout. Each carries `editedAtMs`; the list is newest first, at
46
+ most 60. AGI EXT 0.9.381+ shows them as folder thumbnails in the session sidebar.
47
+ It costs about 0.6 ms more per transcript change on a 2,000-event session.
48
+ Source: `cli/package.json`.
49
+
50
+ - **`agents projects prs merge` no longer refuses a PR whose mergeability GitHub
51
+ never computed.** On some repositories `mergeable_state` stays `unknown` for
52
+ hours, so the merge (and AGI Menu's Merge button) was never possible. An
53
+ uncomputed state now goes on to the merge pinned to the reviewed head commit,
54
+ and GitHub's own merge check decides: it merges, or refuses with its reason.
55
+ `blocked`, `behind`, `dirty` and `draft` are still refused before any write.
56
+ Source: `cli/src/lib/github/project-prs.ts`.
57
+
3
58
  ## 1.22.121
4
59
 
5
60
  - **`agents sessions` reads use the `sessions` binary this CLI already depends on.**
package/README.md CHANGED
@@ -11,7 +11,7 @@
11
11
  <a href="https://github.com/phnx-labs/agi-cli"><img src="https://img.shields.io/badge/github-phnx--labs%2Fagi--cli-blue?style=flat-square" alt="github" /></a>
12
12
  </p>
13
13
 
14
- **A framework for running a distributed agent factory.** Dispatch Claude, Codex, Antigravity, Grok, and more across your own machines, in parallel, on your existing subscriptions. Measure every run with `agents insights` (latency lives at `agents insights perf`), fold what you learn back into `AGENTS.md` and skills, then put the loop on a schedule with routines and monitors. Spawn parallel teams in isolated terminals or dispatch to the cloud for a PR. Watch live state across the fleet, nudge stalled runs, and message agents mid-flight. Store secrets behind Touch ID, drive real browsers and Electron apps, and steer the whole fleet from a menu bar — all from one CLI.
14
+ **A framework for running a distributed agent factory.** Dispatch Claude, Codex, Antigravity, Grok, and more across your own machines, in parallel, on your existing subscriptions. Measure every run with `agents insights` (latency lives at `agents insights perf`), fold what you learn back into `AGENTS.md` and skills, then put the loop on a schedule with routines. Spawn parallel teams in isolated terminals or dispatch to the cloud for a PR. Watch live state across the fleet, nudge stalled runs, and message agents mid-flight. Store secrets behind Touch ID, drive real browsers and Electron apps, and steer the whole fleet from a menu bar — all from one CLI.
15
15
 
16
16
  <p align="center">
17
17
  <a href="https://github.com/anthropics/claude-code" title="Claude Code"><img src="assets/harnesses/anthropic.svg" height="32" alt="Claude Code" /></a>
@@ -100,7 +100,6 @@ Also available as `ag` -- all commands work with both `agents` and `ag`.
100
100
  - [Accounts](#accounts)
101
101
  - [Secrets](#secrets)
102
102
  - [Routines](#routines)
103
- - [Monitors](#monitors)
104
103
  - [Share](#share)
105
104
  - [PTY](#pty)
106
105
  - [Portable setup](#portable-setup)
@@ -139,7 +138,7 @@ agents routines add nightly-payments-audit \
139
138
  agents menubar setup
140
139
  ```
141
140
 
142
- `agents insights perf` reads a disposable warehouse at `~/.agents/.cache/perf/perf.db` -- hook, command, and run timing rollups, deletable any time. `agents insights` (alias `agents sessions insights`) is deterministic and offline: it caches per-session facets, compares harnesses, and ranks actions by evidence count -- no model call unless you pass `--narrative`. Routines put any of this on a cron ([Routines](#routines)); monitors fire it on a change instead of a clock ([Monitors](#monitors)); the menu bar is the always-on control surface for the fleet these commands drive ([Menu bar](#menu-bar)).
141
+ `agents insights perf` reads a disposable warehouse at `~/.agents/.cache/perf/perf.db` -- hook, command, and run timing rollups, deletable any time. `agents insights` (alias `agents sessions insights`) is deterministic and offline: it caches per-session facets, compares harnesses, and ranks actions by evidence count -- no model call unless you pass `--narrative`. Routines put any of this on a cron ([Routines](#routines)); the menu bar is the always-on control surface for the fleet these commands drive ([Menu bar](#menu-bar)).
143
142
 
144
143
  ---
145
144
 
@@ -1398,7 +1397,7 @@ agents daemon logs -f --level warn --since 1h
1398
1397
  agents daemon doctor # one-shot health check; non-zero exit on problems
1399
1398
  ```
1400
1399
 
1401
- Each hosted responsibility (browser IPC, scheduler, monitors, watchdog, device
1400
+ Each hosted responsibility (browser IPC, scheduler, watchdog, device
1402
1401
  probe, self-heal, self-update, account-state refresh, state-dir checks) is an
1403
1402
  independent toggle in `~/.agents/daemon/services.yaml`.
1404
1403
  Self-update checks npm on its own schedule, installs + verifies a newer
@@ -1409,58 +1408,20 @@ with auto-update forced off and only picked up new code on a manual
1409
1408
  `agents daemon services list` shows every service; `enable|disable <id>` flips
1410
1409
  one. Missing keys default to enabled, so upgrades are no-ops. Most services take
1411
1410
  effect on the next daemon start; browser IPC is registered even when boot-disabled
1412
- so browser commands can enable it live, while scheduler and monitor engine also
1413
- re-evaluate on `SIGHUP reload`. Only `agents daemon start|stop|restart` owns the
1411
+ so browser commands can enable it live, while the scheduler also
1412
+ re-evaluates on `SIGHUP reload`. Only `agents daemon start|stop|restart` owns the
1414
1413
  whole process lifecycle. Browser and routines clients change their own service
1415
1414
  state without evicting sibling work.
1416
1415
 
1417
1416
  There is no `agents daemon jobs` -- scheduled work is always `agents routines`
1418
1417
  (see `agents routines stats` for per-routine failure detail). `disable` is a
1419
1418
  device-local kill switch: with it set, `routines add`/`routines start`/
1420
- `routines catchup`/`monitors add`/webhook triggers stop auto-starting the daemon, mirroring
1419
+ `routines catchup`/webhook triggers stop auto-starting the daemon, mirroring
1421
1420
  `systemctl disable` -- `agents daemon start` still works as the explicit
1422
1421
  override.
1423
1422
 
1424
1423
  ---
1425
1424
 
1426
- ## Monitors
1427
-
1428
- <p align="center">
1429
- <img src="assets/monitors.svg" alt="agents monitors: a watched source (poll a command, an HTTP endpoint, a file, or a fleet device) flows into a condition (changed? matched? deduped by a native state store) that fires an action — run an agent with the event in its prompt, kick a routine, or notify. Pin the owner device for exactly-once." width="100%" />
1430
- </p>
1431
-
1432
- ```bash
1433
- # Routines fire on a clock. Monitors fire on a change: watch a source, and when
1434
- # it flips, spawn an agent, kick a routine, or notify. The cross-agent layer --
1435
- # agents watching sources (including the fleet and other agents) and reacting.
1436
-
1437
- # CI goes red -> a Claude agent triages it (poll a command, diff, match a pattern)
1438
- agents monitors add ci-red \
1439
- --poll 'gh pr checks 1249 --json name,bucket' 30s --match fail \
1440
- --run claude --prompt 'CI failed: {event}. Diagnose and fix.' \
1441
- --device yosemite-s0
1442
-
1443
- # Merge-on-green: ok only if the PR actually merged, not just because the agent exited 0
1444
- agents monitors add merge-1682 \
1445
- --poll 'gh pr view 1682 --json state --jq .state' 2m --match OPEN \
1446
- --run claude --prompt 'Rebase-merge #1682: {event}' \
1447
- --postcondition 'gh pr view 1682 --json state --jq .state | grep -qx MERGED'
1448
-
1449
- # A fleet box goes unreachable or overloaded -> notify (watch the fleet itself)
1450
- agents monitors add box-down --watch-device mac-mini --on-change --notify telegram
1451
-
1452
- # Poll an endpoint every 8h; fire once when the body flips to "issued"
1453
- agents monitors add cert-issued \
1454
- --poll-http 'https://secure.ssl.com/.../order' 8h --match issued --notify telegram
1455
-
1456
- agents monitors test ci-red # Dry-run: evaluate the source once, show what it would fire -- no action
1457
- agents monitors list # Every monitor: source, owner device, last fired
1458
- ```
1459
-
1460
- Sources: a command's stdout (`--watch` / `--poll`), an HTTP endpoint (`--poll-http`), a file (`--watch-file`), or a fleet device's reachability + load (`--watch-device`). Push sources -- a signed webhook (`--on`) and a WebSocket (`--ws`) -- are accepted today and delivered through a receiver wired in a follow-up. Conditions: fire on any change (`--on-change`), on a regex (`--match`), or `--every` tick -- deduped by a native state store, so a monitor stays silent until something *actually* changes. Actions: `--run <agent>` (the event is injected into the prompt as `{event}`), `--routine`, `--notify`, or `--webhook-out`. A `--run`/`--routine` action can take `--postcondition '<cmd>'` — a shell command that must exit 0 after the agent settles, otherwise `agents monitors runs` records `no effect` rather than `ok`. Pin a monitor to one owner device with `--device` (exactly-once), or offload the action elsewhere with `--run-on`. Runs in the routines daemon; `agents monitors pause` / `resume` any time.
1461
-
1462
- ---
1463
-
1464
1425
  ## Share
1465
1426
 
1466
1427
  Publishing an agent's HTML output to a shareable link now lives in the standalone
@@ -22,7 +22,6 @@ export const loadUpdate = async () => (await import('../commands/update.js')).re
22
22
  const loadImport = async () => (await import('../commands/import.js')).registerImportCommand;
23
23
  const loadPackages = async () => (await import('../commands/packages.js')).registerPackagesCommands;
24
24
  const loadRoutines = async () => (await import('../commands/routines.js')).registerRoutinesCommands;
25
- const loadMonitors = async () => (await import('../commands/monitors.js')).registerMonitorsCommands;
26
25
  const loadProjects = async () => (await import('../commands/projects.js')).registerProjectsCommands;
27
26
  export const loadRun = async () => (await import('../commands/exec.js')).registerRunCommand;
28
27
  const loadOpen = async () => (await import('../commands/open.js')).registerOpenCommand;
@@ -105,7 +104,6 @@ export const COMMAND_LOADERS = {
105
104
  install: [loadPackages],
106
105
  packages: [loadPackages],
107
106
  routines: [loadRoutines],
108
- monitors: [loadMonitors],
109
107
  projects: [loadProjects],
110
108
  run: [loadRun],
111
109
  _callback: [loadOpen],
@@ -638,8 +638,7 @@ export function registerDaemonCommand(program) {
638
638
 
639
639
  # Toggle or restart a service live — applies without a daemon restart
640
640
  # for supervisor-managed services (account-state, session-index,
641
- # monitors' off-transition, watchdog, device-probe, self-heal,
642
- # state-dir-check)
641
+ # watchdog, device-probe, self-heal, state-dir-check)
643
642
  agents daemon services disable account-state
644
643
  agents daemon services enable account-state
645
644
  agents daemon services restart account-state
@@ -663,7 +662,7 @@ export function registerDaemonCommand(program) {
663
662
  always. Use 'agents routines stats' for per-routine failure detail.
664
663
 
665
664
  'disable' is a persisted kill switch: it stops routines/add,
666
- routines/start, routines/catchup, monitors/add, and webhook triggers from auto-starting
665
+ routines/start, routines/catchup, and webhook triggers from auto-starting
667
666
  the daemon (daemon.enabled: false in ~/.agents/devices/<host>/agents.yaml).
668
667
  'agents daemon start' still starts it explicitly, same as
669
668
  'systemctl start' on a disabled unit.
@@ -680,8 +679,8 @@ export function registerDaemonCommand(program) {
680
679
  'agents daemon services enable|disable|restart <id>' applies live (no
681
680
  daemon restart) for supervisor-managed services that were registered at
682
681
  boot. The inline scheduler re-evaluates its toggle on every reload as
683
- well. A boot-disabled service other than the monitor on-transition and
684
- webhook-receiver still needs an operator 'agents daemon restart'. 'agents
682
+ well. A boot-disabled service other than webhook-receiver still needs
683
+ an operator 'agents daemon restart'. 'agents
685
684
  daemon services' names which case you're in per row.
686
685
  `,
687
686
  });
@@ -755,7 +754,7 @@ export function registerDaemonCommand(program) {
755
754
  .description('Clear the daemon.enabled kill switch. Does not start the daemon by itself.')
756
755
  .action(() => {
757
756
  setConfigValue('daemon.enabled', true);
758
- console.log(chalk.green('daemon.enabled: true') + chalk.gray(' — auto-start surfaces (routines add/start/catchup, monitors add, webhooks) may bring the daemon up again'));
757
+ console.log(chalk.green('daemon.enabled: true') + chalk.gray(' — auto-start surfaces (routines add/start/catchup, webhooks) may bring the daemon up again'));
759
758
  });
760
759
  cmd.command('disable')
761
760
  .description('Persist daemon.enabled: false — nothing auto-starts the daemon until re-enabled. Does not stop a running daemon.')
@@ -804,8 +803,8 @@ export function registerDaemonCommand(program) {
804
803
  notes: `
805
804
  A service disabled at daemon boot is normally not registered on the
806
805
  supervisor, so enabling it needs an operator restart. The inline
807
- scheduler applies enable/disable on reload; webhook-receiver and the
808
- monitor on-transition still require 'agents daemon restart'. Each row in
806
+ scheduler applies enable/disable on reload; webhook-receiver still
807
+ requires 'agents daemon restart'. Each row in
809
808
  the plain-text view names which case it is; 'supervised: true/false' does
810
809
  the same in --json.
811
810
  `,
@@ -386,7 +386,7 @@ export function registerMailboxesCommand(program) {
386
386
  # One-shot sweep using the live session set as the liveness source
387
387
  agents mailboxes prune
388
388
 
389
- # Machine-readable summary (for scripts / monitors)
389
+ # Machine-readable summary (for scripts)
390
390
  agents mailboxes prune --json
391
391
  `,
392
392
  notes: `
@@ -808,9 +808,9 @@ export function registerProjectsCommands(program) {
808
808
  notes: `
809
809
  The merge is a single REST call pinned to --sha: if anything was pushed after
810
810
  you read the PR, GitHub refuses and nothing merges. Without --admin, a PR whose
811
- live mergeable_state is not clean/unstable/has_hooks (blocked by a pending or red
812
- required check or a review, behind, conflicted, or not computed yet) is refused
813
- before the call. --admin skips that refusal and lets a
811
+ live mergeable_state is blocked (a pending or red required check, or a review),
812
+ behind, conflicted or a draft is refused before the call; one GitHub has not
813
+ computed goes on to the call and GitHub decides. --admin skips that refusal and lets a
814
814
  repository admin merge past branch protection where GitHub allows it; it exists
815
815
  for a person's explicit confirm (AGI Menu's "Confirm admin merge") and agents
816
816
  must never pass it. To land a PR once its checks pass, use prs automerge. A
@@ -10,7 +10,6 @@ const DISABLEABLE_FEATURES = [
10
10
  { name: 'computer', hint: 'drive native desktop apps' },
11
11
  { name: 'secrets', hint: 'keychain-backed env bundles' },
12
12
  { name: 'routines', hint: 'run agents on a cron schedule' },
13
- { name: 'monitors', hint: 'event-triggered watchers' },
14
13
  ];
15
14
  async function runMineWizard() {
16
15
  if (!isInteractiveTerminal()) {
@@ -17,6 +17,8 @@ import { addHostOption } from '../lib/hosts/option.js';
17
17
  import { syncRepoGit, adoptUserRepoIfNeeded, recordUserRepoRemote, resolveUserRepoRemoteUrl } from '../lib/git.js';
18
18
  import { getSystemAgentsDir, getUserAgentsDir, getEnabledExtraRepos } from '../lib/state.js';
19
19
  import { registerStatusCommand } from './status.js';
20
+ import { setHelpSections } from '../lib/help.js';
21
+ import { pruneRepoRemovals } from '../lib/sync-delete.js';
20
22
  function emitJson(payload) {
21
23
  console.log(JSON.stringify(payload));
22
24
  }
@@ -129,10 +131,32 @@ export function registerSyncCommand(program) {
129
131
  .option('--cloud', 'Umbrella: fetch all remote state but skip the local reconcile', false)
130
132
  .option('--local', "Umbrella: reconcile resources into installed agents only (no fetch)", false)
131
133
  .option('--prune-clis', 'Umbrella: also purge stale/legacy agents-cli installs (npx-cache, pre-1.22.30, unsafe helper) when a fixed peer exists. DESTRUCTIVE and off by default — the purge never runs on a routine sync.', false)
134
+ .option('--delete', 'Also remove what a repo deleted: trash plugins, commands and skills that came from that repo and no longer exist in it. Needs a repo (agents sync <repo> --delete); resources from other repos or installed by hand are kept', false)
132
135
  .action(async (agentSpec, repo, opts) => {
133
136
  await runSync(agentSpec, repo, opts);
134
137
  });
135
138
  addSelectorOptions(cmd);
139
+ setHelpSections(cmd, {
140
+ examples: `
141
+ # Make this machine current (fetch repos, reconcile every installed agent)
142
+ agents sync
143
+
144
+ # Sync one agent, without prompts
145
+ agents sync claude --yes
146
+
147
+ # Only the system repo's resources, into every installed Claude
148
+ agents sync claude@all system
149
+
150
+ # Preview, then remove what the user repo deleted (plugins, commands, skills)
151
+ agents sync claude user --delete --dry-run
152
+ agents sync claude user --delete --yes
153
+ `,
154
+ notes: `
155
+ - --delete covers plugins, commands and skills (hooks, MCP, subagents, rules and workflows are left alone). It only removes one whose recorded source is in the named repo and is gone from it. Anything from another repo, or with no recorded source (installed by hand), is kept and counted as "kept".
156
+ - Removed items go to ~/.agents/.history/trash/, so they can be restored.
157
+ - Without --delete, sync behaves as before: run --delete to clear what a repo removed after a skipped or partial sync.
158
+ `,
159
+ });
136
160
  registerStatusCommand(cmd);
137
161
  }
138
162
  function resolveRepoGitTarget(repo) {
@@ -427,6 +451,53 @@ async function runUmbrella(opts, quiet, outLog, errLog, json = false) {
427
451
  process.exitCode = 1;
428
452
  }
429
453
  }
454
+ function allInstalledTargets() {
455
+ return MANAGED_AGENT_IDS.flatMap((agent) => listInstalledVersions(agent).map((version) => ({ agent, version })));
456
+ }
457
+ function runDeletePass(repo, targets, cwd, dryRun, json, outLog, errLog) {
458
+ const reports = [];
459
+ try {
460
+ for (const { agent, version } of targets)
461
+ reports.push(pruneRepoRemovals({ agent, version, repo, cwd, dryRun }));
462
+ }
463
+ catch (err) {
464
+ if (json)
465
+ emitJson({ ok: false, mode: 'delete', repo, dryRun, error: err.message });
466
+ errLog(chalk.red(`sync --delete: ${err.message}`));
467
+ process.exitCode = 1;
468
+ return false;
469
+ }
470
+ if (json) {
471
+ emitJson({ ok: true, mode: 'delete', repo, dryRun, versions: reports });
472
+ return true;
473
+ }
474
+ const verb = dryRun ? 'Would remove' : 'Removed';
475
+ let any = false;
476
+ for (const r of reports) {
477
+ const items = [
478
+ ...r.removed.plugins.map((n) => `plugin ${n}`),
479
+ ...r.removed.commands.map((n) => `command ${n}`),
480
+ ...r.removed.skills.map((n) => `skill ${n}`),
481
+ ];
482
+ if (items.length > 0) {
483
+ any = true;
484
+ outLog(chalk.yellow(`${verb} from ${agentLabel(r.agent)}@${r.version} (deleted from ${repo}): ${items.join(', ')}`));
485
+ }
486
+ const kept = [];
487
+ if (r.kept.notFromRepo.length > 0)
488
+ kept.push(`${r.kept.notFromRepo.length} not from ${repo}`);
489
+ if (r.kept.stillProvided.length > 0)
490
+ kept.push(`${r.kept.stillProvided.length} still provided by another repo (${r.kept.stillProvided.join(', ')})`);
491
+ if (items.length > 0 || r.kept.stillProvided.length > 0) {
492
+ outLog(chalk.gray(` kept: ${kept.join(', ') || 'nothing else'}`));
493
+ }
494
+ }
495
+ if (!any)
496
+ outLog(chalk.gray(`Nothing deleted from ${repo} is still installed (${targets.length} version(s) checked).`));
497
+ else if (!dryRun)
498
+ outLog(chalk.gray(' Trashed under ~/.agents/.history/trash/ (recoverable).'));
499
+ return true;
500
+ }
430
501
  async function runSync(agentSpec, repoArg, opts) {
431
502
  const json = !!opts.json;
432
503
  const quiet = !!opts.quiet || json;
@@ -438,6 +509,20 @@ async function runSync(agentSpec, repoArg, opts) {
438
509
  if (json)
439
510
  emitJson({ ok: false, ...payload });
440
511
  };
512
+ const repoOnlySpec = agentSpec && !opts.agent && !repoArg && listRepoNames().includes(agentSpec) ? agentSpec : undefined;
513
+ const deleteRepo = opts.delete ? (opts.repo || repoArg || repoOnlySpec) : undefined;
514
+ if (opts.delete && !deleteRepo) {
515
+ const error = '--delete needs a repo: it only removes what that repo deleted.';
516
+ const hint = 'Name one: agents sync <repo> --delete, agents sync <agent> <repo> --delete, or --repo <repo> --delete (repos: ' + listRepoNames().join(', ') + ')';
517
+ failJson({ mode: 'delete', error, hint });
518
+ if (!json) {
519
+ console.error(chalk.red(error));
520
+ console.error(chalk.gray(hint));
521
+ }
522
+ process.exitCode = 1;
523
+ return;
524
+ }
525
+ const deleteCwd = opts.cwd || process.cwd();
441
526
  let agentId;
442
527
  let version;
443
528
  let selector;
@@ -445,7 +530,11 @@ async function runSync(agentSpec, repoArg, opts) {
445
530
  if (!quiet && !json) {
446
531
  console.error(chalk.yellow(`Warning: 'agents sync ${agentSpec}' is deprecated. Use: agents repo sync ${agentSpec}`));
447
532
  }
448
- await runRepoGitSync(agentSpec, quiet, outLog, errLog, json);
533
+ if (!(deleteRepo && opts.dryRun))
534
+ await runRepoGitSync(agentSpec, quiet, outLog, errLog, json);
535
+ if (deleteRepo && process.exitCode !== 1) {
536
+ runDeletePass(deleteRepo, allInstalledTargets(), deleteCwd, !!opts.dryRun, json, outLog, errLog);
537
+ }
449
538
  return;
450
539
  }
451
540
  if (agentSpec) {
@@ -504,7 +593,14 @@ async function runSync(agentSpec, repoArg, opts) {
504
593
  version = opts.agentVersion;
505
594
  }
506
595
  if (!agentId) {
596
+ if (deleteRepo && opts.dryRun) {
597
+ runDeletePass(deleteRepo, allInstalledTargets(), deleteCwd, true, json, outLog, errLog);
598
+ return;
599
+ }
507
600
  await runUmbrella(opts, quiet, outLog, errLog, json);
601
+ if (deleteRepo && process.exitCode !== 1) {
602
+ runDeletePass(deleteRepo, allInstalledTargets(), deleteCwd, false, json, outLog, errLog);
603
+ }
508
604
  return;
509
605
  }
510
606
  const projectDir = opts.projectDir;
@@ -562,6 +658,8 @@ async function runSync(agentSpec, repoArg, opts) {
562
658
  const scopeLabel = repoScope ? chalk.gray(` (repo: ${repoScope})`) : '';
563
659
  if (!json)
564
660
  outLog(chalk.cyan(`Syncing ${installed.length} ${agentLabel(agentId)} version(s)${scopeLabel}.`));
661
+ if (deleteRepo && !runDeletePass(deleteRepo, installed.map((v) => ({ agent: agentId, version: v })), cwd, !!opts.dryRun, json, outLog, errLog))
662
+ return;
565
663
  if (opts.dryRun) {
566
664
  if (!quiet && !json) {
567
665
  console.log(chalk.cyan(`Dry run — would sync ${agentLabel(agentId)} (${installed.length} version(s))${scopeLabel}:`));
@@ -680,6 +778,8 @@ async function runSync(agentSpec, repoArg, opts) {
680
778
  process.exitCode = 1;
681
779
  return;
682
780
  }
781
+ if (deleteRepo && !runDeletePass(deleteRepo, [{ agent: agentId, version }], cwd, !!opts.dryRun, json, outLog, errLog))
782
+ return;
683
783
  if (opts.launch) {
684
784
  runLaunchMode(agentId, version, cwd, quiet, json);
685
785
  return;
@@ -503,11 +503,10 @@ export function assertTestDaemonHome(daemonDir = getDaemonDir(), testHome = proc
503
503
  }
504
504
  export async function runDaemon() {
505
505
  assertTestDaemonHome();
506
- const [{ SessionIndexService }, { SessionSummarizerService }, { SessionTitleService }, { MonitorEngineService }, { AccountUsageService, AccountAuthService }, { CatchupService }, { WatchdogService }, { DeviceProbeService }, { SelfHealService }, { SelfUpdateService }, { HarnessUpdateService }, { AuthSyncService }, { UsageSyncService }, { StateDirCheckService }, { SessionStateService }, { FeedStreamService }, { AttentionNotifyService }, { WebhookReceiverService }, { HeartbeatService }, { TmuxReapService },] = await Promise.all([
506
+ const [{ SessionIndexService }, { SessionSummarizerService }, { SessionTitleService }, { AccountUsageService, AccountAuthService }, { CatchupService }, { WatchdogService }, { DeviceProbeService }, { SelfHealService }, { SelfUpdateService }, { HarnessUpdateService }, { AuthSyncService }, { UsageSyncService }, { StateDirCheckService }, { SessionStateService }, { FeedStreamService }, { AttentionNotifyService }, { WebhookReceiverService }, { HeartbeatService }, { TmuxReapService },] = await Promise.all([
507
507
  import('./session-index-service.js'),
508
508
  import('./session-summarizer-service.js'),
509
509
  import('./session-title-service.js'),
510
- import('./monitor-engine-service.js'),
511
510
  import('./account-state-daemon-service.js'),
512
511
  import('./catchup-service.js'),
513
512
  import('./watchdog-service.js'),
@@ -597,11 +596,6 @@ export async function runDaemon() {
597
596
  supervisor.register(new FeedStreamService(), { enabled: isEnabled('feed-stream') });
598
597
  if (!isEnabled('feed-stream'))
599
598
  log('INFO', 'Shared feed stream service disabled');
600
- const monitorEngineSvc = new MonitorEngineService();
601
- if (isEnabled('monitors'))
602
- supervisor.register(monitorEngineSvc);
603
- else
604
- log('INFO', 'Monitor engine disabled');
605
599
  if (isEnabled('account-state'))
606
600
  supervisor.register(new AccountUsageService());
607
601
  else
@@ -870,15 +864,6 @@ export async function runDaemon() {
870
864
  const reloaded = scheduler.listScheduled();
871
865
  log('INFO', `Reloaded ${reloaded.length} jobs`);
872
866
  }
873
- const liveMonitorEngine = monitorEngineSvc.getEngine();
874
- if (liveMonitorEngine && reloadedEnabled('monitors')) {
875
- try {
876
- liveMonitorEngine.reload();
877
- }
878
- catch (err) {
879
- log('ERROR', `Monitor engine reload failed: ${err.message}`);
880
- }
881
- }
882
867
  };
883
868
  // Cleanup removes lifetime, pid, heartbeat, and registry state only when each still belongs to this instance.
884
869
  const handleShutdown = singleShot(async () => {
@@ -1,4 +1,4 @@
1
- export type DaemonServiceId = 'scheduler' | 'catchup' | 'monitors' | 'webhook-receiver' | 'self-heal' | 'self-update' | 'account-state' | 'account-auth' | 'watchdog' | 'device-probe' | 'state-dir-check' | 'session-index' | 'session-title' | 'auth-sync' | 'usage-sync' | 'daemon-heartbeat' | 'tmux-reap' | 'session-state' | 'feed-stream' | 'session-summarizer' | 'attention-notify' | 'harness-update';
1
+ export type DaemonServiceId = 'scheduler' | 'catchup' | 'webhook-receiver' | 'self-heal' | 'self-update' | 'account-state' | 'account-auth' | 'watchdog' | 'device-probe' | 'state-dir-check' | 'session-index' | 'session-title' | 'auth-sync' | 'usage-sync' | 'daemon-heartbeat' | 'tmux-reap' | 'session-state' | 'feed-stream' | 'session-summarizer' | 'attention-notify' | 'harness-update';
2
2
  interface DaemonServiceDef {
3
3
  id: DaemonServiceId;
4
4
  title: string;
@@ -14,11 +14,6 @@ export const DAEMON_SERVICES = [
14
14
  title: 'Catch-up recovery',
15
15
  description: 'Supervised pass that re-runs routines whose scheduled fire this device missed (sleep, wedge, or suspend). No-ops while the scheduler gate is off.',
16
16
  },
17
- {
18
- id: 'monitors',
19
- title: 'Monitor engine',
20
- description: 'Watches event sources and triggers monitor-driven routines.',
21
- },
22
17
  {
23
18
  id: 'webhook-receiver',
24
19
  title: 'Webhook receiver',
@@ -37,7 +37,7 @@ type Logger = (level: string, message: string) => void;
37
37
  * `server.listen()` surfaces EADDRINUSE as an `'error'` event, so a `try/catch`
38
38
  * around the start call never sees it and the event reaches the process-level
39
39
  * `uncaughtException` handler (`index.ts`), which exits 1 for the supervisor to
40
- * restart — a crash loop that would take the scheduler, monitors, browser IPC,
40
+ * restart — a crash loop that would take the scheduler, browser IPC,
41
41
  * and self-heal down with it. `waitForListening` is what turns that into one
42
42
  * skipped receiver.
43
43
  */
@@ -109,7 +109,7 @@ function reconcileFunnel(publicPort, localPort, log) {
109
109
  * `server.listen()` surfaces EADDRINUSE as an `'error'` event, so a `try/catch`
110
110
  * around the start call never sees it and the event reaches the process-level
111
111
  * `uncaughtException` handler (`index.ts`), which exits 1 for the supervisor to
112
- * restart — a crash loop that would take the scheduler, monitors, browser IPC,
112
+ * restart — a crash loop that would take the scheduler, browser IPC,
113
113
  * and self-heal down with it. `waitForListening` is what turns that into one
114
114
  * skipped receiver.
115
115
  */
@@ -172,7 +172,7 @@ export const CONFIG_KEYS = [
172
172
  defaultValue: true,
173
173
  description: 'Whether the daemon may run on this device at all (browser IPC, watchdog, and the ' +
174
174
  'routines scheduler). Disabling is the top-level kill switch: nothing auto-starts the daemon while it ' +
175
- 'is set, including `routines add`/`routines start`/`routines catchup`/`monitors add`/webhook triggers. ' +
175
+ 'is set, including `routines add`/`routines start`/`routines catchup`/webhook triggers. ' +
176
176
  '`agents daemon start` still starts it explicitly.',
177
177
  },
178
178
  {
@@ -536,7 +536,7 @@ export function ghFailure(err) {
536
536
  return line.replace(/^gh:\s*/, '');
537
537
  }
538
538
  export const BLOCKED_WITHOUT_ADMIN = 'Blocked by branch protection; pass --admin to merge as an admin';
539
- const MERGEABLE_STATES = new Set(['clean', 'unstable', 'has_hooks']);
539
+ const MERGEABLE_STATES = new Set(['clean', 'unstable', 'has_hooks', 'unknown', '']);
540
540
  export function mergeRefusalWithoutAdmin(state) {
541
541
  if (MERGEABLE_STATES.has(state))
542
542
  return null;
@@ -545,7 +545,7 @@ export function mergeRefusalWithoutAdmin(state) {
545
545
  case 'dirty': return 'Has merge conflicts';
546
546
  case 'behind': return 'The branch is behind its base; update it, or pass --admin to merge as an admin';
547
547
  case 'draft': return 'Draft: mark it ready for review first';
548
- default: return 'GitHub is still computing mergeability; try again in a moment';
548
+ default: return `GitHub reports the PR as ${state}; not merging`;
549
549
  }
550
550
  }
551
551
  export function readableMergeRefusal(message) {
@@ -84,7 +84,6 @@ export const OWN_HOST_COMMANDS = new Set([
84
84
  'devices',
85
85
  'fleet',
86
86
  'apply',
87
- 'monitors',
88
87
  ]);
89
88
  const STRIP_SPECS = [
90
89
  ...HOST_ROUTING_SPECS,
@@ -40,6 +40,7 @@ export declare function loadUserConfig(pluginName: string): Record<string, strin
40
40
  export declare function saveUserConfig(pluginName: string, config: Record<string, string>): void;
41
41
  export declare function checkPluginDependencies(manifest: PluginManifest): string[];
42
42
  export declare function marketplaceSpecForName(name: string | undefined, cwd?: string): MarketplaceSpec;
43
+ export declare function listVersionMarketplaceNames(agent: AgentId, versionHome: string): string[];
43
44
  export declare function syncPluginToVersion(plugin: DiscoveredPlugin, agent: AgentId, versionHome: string, options?: {
44
45
  allowExecSurfaces?: boolean;
45
46
  version?: string;
@@ -82,7 +83,12 @@ export type ActivePluginsInput = Set<string> | Array<{
82
83
  name: string;
83
84
  marketplace?: string;
84
85
  }>;
85
- export declare function cleanOrphanedPluginSkills(agent: AgentId, versionHome: string, activePlugins: ActivePluginsInput, version?: string): string[];
86
+ export interface OrphanPluginScope {
87
+ marketplace: string;
88
+ cwd: string;
89
+ dryRun?: boolean;
90
+ }
91
+ export declare function cleanOrphanedPluginSkills(agent: AgentId, versionHome: string, activePlugins: ActivePluginsInput, version?: string, scope?: OrphanPluginScope): string[];
86
92
  export interface VersionPluginDiff {
87
93
  agent: AgentId;
88
94
  version: string;
@@ -377,7 +377,7 @@ export function marketplaceSpecForName(name, cwd = process.cwd()) {
377
377
  const alias = name.slice('agents-'.length);
378
378
  return { kind: 'extra', alias, root: getExtraPluginsDir(alias) };
379
379
  }
380
- function listVersionMarketplaceNames(agent, versionHome) {
380
+ export function listVersionMarketplaceNames(agent, versionHome) {
381
381
  const dir = path.join(versionHome, agentConfigDirName(agent), 'plugins', 'marketplaces');
382
382
  if (!fs.existsSync(dir))
383
383
  return [];
@@ -1146,11 +1146,14 @@ function isOrphanMarketplacePlugin(marketplaceName, pluginName, active, cwd) {
1146
1146
  return true;
1147
1147
  return !active.names.has(pluginName);
1148
1148
  }
1149
- export function cleanOrphanedPluginSkills(agent, versionHome, activePlugins, version) {
1149
+ export function cleanOrphanedPluginSkills(agent, versionHome, activePlugins, version, scope) {
1150
1150
  const active = indexActivePlugins(activePlugins);
1151
- const cwd = process.cwd();
1151
+ const cwd = scope?.cwd ?? process.cwd();
1152
1152
  const removed = [];
1153
+ const removedPlugins = new Set();
1153
1154
  for (const name of listVersionMarketplaceNames(agent, versionHome)) {
1155
+ if (scope && (name !== scope.marketplace || !marketplaceSourceRepoExists(name, cwd)))
1156
+ continue;
1154
1157
  const spec = marketplaceSpecForName(name);
1155
1158
  const mktPluginsDir = path.join(marketplaceRoot(name, agent, versionHome), 'plugins');
1156
1159
  if (!fs.existsSync(mktPluginsDir))
@@ -1161,6 +1164,11 @@ export function cleanOrphanedPluginSkills(agent, versionHome, activePlugins, ver
1161
1164
  continue;
1162
1165
  if (!isOrphanMarketplacePlugin(name, entry.name, active, cwd))
1163
1166
  continue;
1167
+ if (scope?.dryRun) {
1168
+ removed.push(entry.name);
1169
+ removedPlugins.add(entry.name);
1170
+ continue;
1171
+ }
1164
1172
  try {
1165
1173
  const stamp = new Date().toISOString().replace(/[:.]/g, '-');
1166
1174
  const trashDir = path.join(getTrashPluginsDir(), agent, version || 'unknown', entry.name);
@@ -1175,9 +1183,13 @@ export function cleanOrphanedPluginSkills(agent, versionHome, activePlugins, ver
1175
1183
  unregisterCopilotInstalledPlugin(entry.name, name, agent, versionHome);
1176
1184
  }
1177
1185
  removed.push(entry.name);
1186
+ removedPlugins.add(entry.name);
1178
1187
  trashedHere = true;
1179
1188
  }
1180
- catch { }
1189
+ catch (err) {
1190
+ if (scope)
1191
+ throw new Error(`could not trash plugin '${entry.name}' from ${agent}@${version ?? 'unknown'}: ${err.message}`);
1192
+ }
1181
1193
  }
1182
1194
  if (trashedHere) {
1183
1195
  syncMarketplaceManifest(spec, agent, versionHome);
@@ -1198,6 +1210,12 @@ export function cleanOrphanedPluginSkills(agent, versionHome, activePlugins, ver
1198
1210
  const pluginName = entry.name.slice(0, dashIdx);
1199
1211
  if (active.names.has(pluginName))
1200
1212
  continue;
1213
+ if (scope && !removedPlugins.has(pluginName))
1214
+ continue;
1215
+ if (scope?.dryRun) {
1216
+ removed.push(entry.name);
1217
+ continue;
1218
+ }
1201
1219
  try {
1202
1220
  const stamp = new Date().toISOString().replace(/[:.]/g, '-');
1203
1221
  const trashDir = path.join(getTrashPluginsDir(), agent, version || 'unknown', entry.name);
@@ -1206,7 +1224,10 @@ export function cleanOrphanedPluginSkills(agent, versionHome, activePlugins, ver
1206
1224
  fs.renameSync(path.join(skillsDir, entry.name), trashDest);
1207
1225
  removed.push(entry.name);
1208
1226
  }
1209
- catch { }
1227
+ catch (err) {
1228
+ if (scope)
1229
+ throw new Error(`could not trash plugin skill '${entry.name}' from ${agent}@${version ?? 'unknown'}: ${err.message}`);
1230
+ }
1210
1231
  }
1211
1232
  }
1212
1233
  return removed;