@phnx-labs/agents-cli 1.22.127 → 1.23.1

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 (119) hide show
  1. package/CHANGELOG.md +108 -0
  2. package/README.md +15 -16
  3. package/dist/bootstrap.js +4 -3
  4. package/dist/commands/browser.js +4 -19
  5. package/dist/commands/cloud-transcripts.js +1 -2
  6. package/dist/commands/computer.d.ts +2 -6
  7. package/dist/commands/computer.js +12 -18
  8. package/dist/commands/daemon.js +70 -11
  9. package/dist/commands/exec.js +1 -1
  10. package/dist/commands/feed.js +1 -2
  11. package/dist/commands/focus.js +4 -1
  12. package/dist/commands/go.js +3 -2
  13. package/dist/commands/logs.js +3 -7
  14. package/dist/commands/menubar.js +55 -3
  15. package/dist/commands/projects.js +103 -40
  16. package/dist/commands/ps-roster.d.ts +0 -11
  17. package/dist/commands/ps-roster.js +3 -116
  18. package/dist/commands/ps.d.ts +10 -0
  19. package/dist/commands/ps.js +182 -1
  20. package/dist/commands/resume.js +1 -1
  21. package/dist/commands/sessions-browser.d.ts +0 -1
  22. package/dist/commands/sessions-browser.js +6 -23
  23. package/dist/commands/sessions-export.js +1 -1
  24. package/dist/commands/sessions-migrate.js +1 -1
  25. package/dist/commands/sessions-picker.d.ts +6 -32
  26. package/dist/commands/sessions-picker.js +81 -8
  27. package/dist/commands/sessions-render.js +1 -1
  28. package/dist/commands/sessions-resume.js +2 -2
  29. package/dist/commands/sessions-share.js +1 -1
  30. package/dist/commands/sessions-trace.js +1 -1
  31. package/dist/commands/sessions.d.ts +2 -176
  32. package/dist/commands/sessions.js +44 -1577
  33. package/dist/index.js +10 -11
  34. package/dist/lib/browser-client.d.ts +0 -21
  35. package/dist/lib/browser-client.js +1 -44
  36. package/dist/lib/computer/record.d.ts +1 -0
  37. package/dist/lib/computer/record.js +2 -16
  38. package/dist/lib/config-keys.d.ts +2 -2
  39. package/dist/lib/config-keys.js +8 -2
  40. package/dist/lib/daemon/account-state-daemon-service.d.ts +2 -2
  41. package/dist/lib/daemon/account-state-daemon-service.js +2 -2
  42. package/dist/lib/daemon/attention-notify-service.js +8 -4
  43. package/dist/lib/daemon/daemon.d.ts +5 -1
  44. package/dist/lib/daemon/daemon.js +54 -14
  45. package/dist/lib/daemon/diagnostics.d.ts +70 -0
  46. package/dist/lib/daemon/diagnostics.js +185 -0
  47. package/dist/lib/daemon/runner.js +3 -2
  48. package/dist/lib/daemon/service.d.ts +1 -1
  49. package/dist/lib/daemon/session-state-service.d.ts +1 -1
  50. package/dist/lib/daemon/session-state-service.js +2 -2
  51. package/dist/lib/daemon/supervisor.d.ts +8 -0
  52. package/dist/lib/daemon/supervisor.js +47 -6
  53. package/dist/lib/daemon-services.d.ts +4 -1
  54. package/dist/lib/daemon-services.js +36 -5
  55. package/dist/lib/daemon-ticks.d.ts +3 -1
  56. package/dist/lib/daemon-ticks.js +18 -12
  57. package/dist/lib/device-config.d.ts +1 -1
  58. package/dist/lib/device-config.js +48 -7
  59. package/dist/lib/feed/tool-activity.d.ts +22 -10
  60. package/dist/lib/feed/tool-activity.js +168 -32
  61. package/dist/lib/feed/tools.d.ts +55 -2
  62. package/dist/lib/feed/tools.js +22 -28
  63. package/dist/lib/feed/watch.js +12 -8
  64. package/dist/lib/github/open-prs.d.ts +41 -0
  65. package/dist/lib/github/open-prs.js +157 -0
  66. package/dist/lib/github/project-prs.d.ts +20 -1
  67. package/dist/lib/github/project-prs.js +8 -7
  68. package/dist/lib/helper-versions.js +1 -1
  69. package/dist/lib/menubar/install-menubar.d.ts +23 -7
  70. package/dist/lib/menubar/install-menubar.js +179 -30
  71. package/dist/lib/menubar/resolve-version.d.ts +1 -0
  72. package/dist/lib/menubar/resolve-version.js +4 -2
  73. package/dist/lib/menubar/snapshot.d.ts +2 -0
  74. package/dist/lib/menubar/snapshot.js +2 -0
  75. package/dist/lib/menubar/update-state.d.ts +15 -0
  76. package/dist/lib/menubar/update-state.js +36 -0
  77. package/dist/lib/owner-notify.d.ts +0 -12
  78. package/dist/lib/owner-notify.js +1 -10
  79. package/dist/lib/self-heal/checks/menubar-helper.js +1 -0
  80. package/dist/lib/session/active.js +18 -14
  81. package/dist/lib/session/cloud.d.ts +0 -1
  82. package/dist/lib/session/cloud.js +0 -5
  83. package/dist/lib/session/db.d.ts +0 -64
  84. package/dist/lib/session/db.js +0 -116
  85. package/dist/lib/session/pid-registry.js +9 -6
  86. package/dist/lib/session/presentation.d.ts +107 -1
  87. package/dist/lib/session/presentation.js +543 -4
  88. package/dist/lib/session/remote/remote-list.d.ts +5 -36
  89. package/dist/lib/session/remote/remote-list.js +16 -320
  90. package/dist/lib/session/resume-command.d.ts +9 -0
  91. package/dist/lib/session/resume-command.js +107 -0
  92. package/dist/lib/session/selection.d.ts +102 -0
  93. package/dist/lib/session/selection.js +443 -0
  94. package/dist/lib/session/tool-index.d.ts +0 -62
  95. package/dist/lib/session/tool-index.js +1 -537
  96. package/dist/lib/sessions-client.d.ts +1 -0
  97. package/dist/lib/sessions-client.js +17 -1
  98. package/dist/lib/standalone-tools.js +2 -2
  99. package/dist/lib/testdata/owner-notify-api.d.ts +0 -13
  100. package/dist/lib/testdata/owner-notify-api.js +3 -23
  101. package/package.json +1 -1
  102. package/dist/commands/browser-sessions-picker.d.ts +0 -9
  103. package/dist/commands/browser-sessions-picker.js +0 -136
  104. package/dist/commands/computer-sessions-picker.d.ts +0 -11
  105. package/dist/commands/computer-sessions-picker.js +0 -90
  106. package/dist/commands/sessions-tail.d.ts +0 -13
  107. package/dist/commands/sessions-tail.js +0 -222
  108. package/dist/lib/browser/native-history.test-fixture.d.ts +0 -12
  109. package/dist/lib/browser/native-history.test-fixture.js +0 -43
  110. package/dist/lib/browser/paths.d.ts +0 -9
  111. package/dist/lib/browser/paths.js +0 -31
  112. package/dist/lib/browser/record.d.ts +0 -4
  113. package/dist/lib/browser/record.js +0 -19
  114. package/dist/lib/browser/sessions-list.d.ts +0 -79
  115. package/dist/lib/browser/sessions-list.js +0 -415
  116. package/dist/lib/computer/sessions-list.d.ts +0 -78
  117. package/dist/lib/computer/sessions-list.js +0 -372
  118. package/dist/lib/daemon/owner-device-delivery-service.d.ts +0 -10
  119. package/dist/lib/daemon/owner-device-delivery-service.js +0 -28
@@ -1,6 +1,6 @@
1
1
  import chalk from 'chalk';
2
2
  import { setHelpSections } from '../lib/help.js';
3
- import { enableMenubarService, disableMenubarService, getMenubarStatus, runMenubarSetup, buildMenubarDoctorReport, } from '../lib/menubar/install-menubar.js';
3
+ import { updateMenubarHelperIfNewer, enableMenubarService, disableMenubarService, getMenubarStatus, restartMenubarHelper, runMenubarSetup, buildMenubarDoctorReport, } from '../lib/menubar/install-menubar.js';
4
4
  function notMac() {
5
5
  if (process.platform !== 'darwin') {
6
6
  console.log(chalk.yellow('AGI Menu is macOS only.'));
@@ -14,7 +14,7 @@ function printStatus(s, opts = {}) {
14
14
  console.log(` running ${yn(s.running)}`);
15
15
  console.log(` service installed ${yn(s.serviceInstalled)}`);
16
16
  if (opts.brief) {
17
- console.log(chalk.gray('\n setup | enable | disable | status'));
17
+ console.log(chalk.gray('\n setup | restart | enable | disable | status'));
18
18
  return;
19
19
  }
20
20
  console.log(` app installed ${s.installedApp ? chalk.gray(s.installedApp) : chalk.gray('no')}`);
@@ -92,6 +92,57 @@ export function registerMenubarCommands(program) {
92
92
  const menubar = program
93
93
  .command('menubar')
94
94
  .description('Manage AGI Menu (running sessions, agents awaiting input, routines)');
95
+ const update = menubar.command('update')
96
+ .description('Check for or install the newest AGI Menu release')
97
+ .option('--check', 'Check only; do not download, install, or restart the app')
98
+ .option('--json', 'Emit machine-readable update status')
99
+ .action(async (options) => {
100
+ const status = await updateMenubarHelperIfNewer({ manual: true, dryRun: options.check, deferRestart: true });
101
+ if (options.json)
102
+ process.stdout.write(`${JSON.stringify(status)}\n`);
103
+ else
104
+ console.log(status.detail);
105
+ if (status.outcome === 'failed')
106
+ process.exitCode = 1;
107
+ });
108
+ setHelpSections(update, {
109
+ examples: `
110
+ agents menubar update --check --json
111
+ agents menubar update --json
112
+ agents config set menubar.autoUpdate false
113
+ `,
114
+ notes: `
115
+ Checks and updates only AGI Menu, independently of agents-cli.
116
+ Automatic updates default on and check about every 12 hours while awake.
117
+ Manual updates work with automatic updates off. JSON reports lookup and
118
+ installation errors; a successful install hands off a bounded app restart
119
+ after this command exits. Check-only never installs or restarts the app.
120
+ `,
121
+ });
122
+ const restart = menubar.command('restart')
123
+ .description('Restart the running AGI Menu through its login item')
124
+ .option('--json', 'Emit machine-readable restart result')
125
+ .action(async (options) => {
126
+ const result = await restartMenubarHelper();
127
+ if (options.json)
128
+ process.stdout.write(`${JSON.stringify(result)}\n`);
129
+ else
130
+ console.log(result.outcome === 'failed' ? chalk.red(result.detail) : chalk.green(result.detail));
131
+ if (result.outcome === 'failed')
132
+ process.exitCode = 1;
133
+ });
134
+ setHelpSections(restart, {
135
+ examples: `
136
+ agents menubar restart
137
+ agents menubar restart --json
138
+ `,
139
+ notes: `
140
+ Restarts AGI Menu with launchctl kickstart -k and waits up to 15 seconds
141
+ for exactly one new process. The kickstart runs in its own session, so
142
+ the restart completes even when AGI Menu itself requested it. A turned-off
143
+ AGI Menu is refused rather than started; \`agents menubar setup\` turns it on.
144
+ `,
145
+ });
95
146
  const setup = menubar
96
147
  .command('setup')
97
148
  .description('Configure AGI Menu end-to-end: one instance, started at login')
@@ -136,7 +187,8 @@ export function registerMenubarCommands(program) {
136
187
  Configures, in order: every running helper ended, AGI Menu at
137
188
  ~/Library/Application Support/agents-cli/MenubarHelper.app, its code
138
189
  signature, the launchd login item (com.phnx-labs.agents-menubar —
139
- RunAtLoad + KeepAlive), then verifies exactly one helper came back up.
190
+ RunAtLoad, relaunched after a crash but not after Quit), then verifies
191
+ exactly one helper came back up.
140
192
 
141
193
  Every running helper is ended and launchd restarts one, so the survivor is
142
194
  always the login-managed copy. Exits nonzero if it cannot reach that state.
@@ -22,7 +22,8 @@ import { formatFocusAreas, readFocusAreas } from '../lib/project-focus.js';
22
22
  import { formatVerdict, scheduleVerdict } from '../lib/project-schedule.js';
23
23
  import { buildLinearImportCandidates, validateImportOpts, } from '../lib/project-import.js';
24
24
  import { approveProjectPr, buildProjectPrs, commentOnProjectPr, markProjectPrReady, mergeProjectPr, resolveTargetSlugs, setProjectPrAutoMerge, MERGE_METHODS, MERGED_WINDOW_DAYS, } from '../lib/github/project-prs.js';
25
- import { ghExec } from '../lib/github/pr-mergeable.js';
25
+ import { ghExec, canonicalizeRepo } from '../lib/github/pr-mergeable.js';
26
+ import { buildOpenPrs } from '../lib/github/open-prs.js';
26
27
  import { readCiFailure, rerunFailedJobs } from '../lib/github/ci-failure.js';
27
28
  import { registerProjectTodoCommands } from './projects-todo.js';
28
29
  function ciMark(state) {
@@ -379,6 +380,8 @@ function prFail(message) {
379
380
  process.exit(1);
380
381
  }
381
382
  function prProjectOrExit(name) {
383
+ if (name === undefined)
384
+ return undefined;
382
385
  return loadProjectDef(name) ?? prFail(`No project named "${name}". List them: agents projects list`);
383
386
  }
384
387
  function prNumberOrExit(raw) {
@@ -417,6 +420,11 @@ function prMethodOrExit(raw) {
417
420
  return raw;
418
421
  }
419
422
  async function prRepoOrExit(def, repo) {
423
+ if (!def) {
424
+ if (!/^[\w.-]+\/[\w.-]+$/.test(repo))
425
+ prFail(`--repo expects owner/repo, got "${repo}".`);
426
+ return canonicalizeRepo(repo, ghExec);
427
+ }
420
428
  try {
421
429
  const [resolved] = await resolveTargetSlugs(def, repo, ghExec);
422
430
  return resolved;
@@ -425,6 +433,31 @@ async function prRepoOrExit(def, repo) {
425
433
  return prFail(e instanceof Error ? e.message : String(e));
426
434
  }
427
435
  }
436
+ function printOpenPrs(open) {
437
+ const marks = { review: chalk.yellow('review requested'), failing: chalk.red('failing'), conflicts: chalk.red('conflicts') };
438
+ for (const o of open.owners) {
439
+ if (o.error)
440
+ console.log(`${chalk.bold(o.login)} ${chalk.red(`— search failed: ${o.error}`)}`);
441
+ else if (o.truncated)
442
+ console.log(chalk.yellow(`${o.login}: GitHub search stops at ${o.open} results; some open PRs are not listed.`));
443
+ }
444
+ if (open.reviewRequestedError)
445
+ console.log(chalk.yellow(`Review requests could not be read: ${open.reviewRequestedError}`));
446
+ for (const r of open.repositories) {
447
+ const projects = r.projects.length ? chalk.dim(` ${r.projects.join(', ')}`) : '';
448
+ console.log(`${chalk.bold(r.slug)} ${chalk.dim(`${r.pullRequests.length} open`)}${projects}`);
449
+ for (const pr of r.pullRequests) {
450
+ const draft = pr.isDraft ? chalk.gray(' [draft]') : '';
451
+ const needs = pr.needsMe ? ` ${marks[pr.needsMe]}` : '';
452
+ console.log(` ${ciMark(pr.ciState)} #${pr.number}${draft} ${pr.title} ${chalk.gray(`@${pr.author.login}`)}${needs}`);
453
+ }
454
+ if (r.ciError)
455
+ console.log(chalk.yellow(` Checks or mergeability are incomplete: ${r.ciError}`));
456
+ }
457
+ const total = open.repositories.reduce((n, r) => n + r.pullRequests.length, 0);
458
+ const needs = open.repositories.reduce((n, r) => n + r.pullRequests.filter((pr) => pr.needsMe).length, 0);
459
+ console.log(chalk.dim(`\n${total} open across ${open.repositories.length} repos · ${needs} need you`));
460
+ }
428
461
  export function registerProjectsCommands(program) {
429
462
  const projects = program
430
463
  .command('projects')
@@ -695,32 +728,44 @@ export function registerProjectsCommands(program) {
695
728
  });
696
729
  const prsCmd = projects
697
730
  .command('prs')
698
- .description('A project\'s open pull requests: list them (default), act on one (ready, review, comment, merge), or read and re-run failed CI (failure, rerun).');
731
+ .description('Open pull requests: every one across your GitHub account and orgs, or one project\'s (list, the default); act on one (ready, review, comment, merge), or read and re-run failed CI (failure, rerun).');
699
732
  const prsListCmd = prsCmd
700
- .command('list <name>', { isDefault: true })
701
- .description('Every OPEN pull request across a project\'s attached repos (drafts included, no author filter), scoped to this project\'s paths in a shared repo.')
733
+ .command('list [name]', { isDefault: true })
734
+ .description('Every OPEN pull request across a project\'s attached repos, or with no project across your GitHub account and every org you belong to, with what needs you first.')
702
735
  .option('--json', 'Machine-readable output (the AGI Menu contract shape)')
703
- .option('--repo <owner/repo>', 'Restrict to one of the project\'s attached repos')
736
+ .option('--repo <owner/repo>', 'With a project: restrict to one of its attached repos. Without: the repo of the one PR --number names')
704
737
  .option('--number <n>', 'Lazy detail: enrich exactly this PR with checks + reviewDecision (requires --repo)')
738
+ .option('--org <login...>', 'Without a project: read only these GitHub orgs or accounts (default: you and every org you belong to)')
705
739
  .action(async (name, opts) => {
706
- const def = loadProjectDef(name);
707
- if (!def) {
708
- console.error(chalk.red(`No project named "${name}". List them: agents projects list`));
709
- process.exit(1);
710
- }
711
740
  let number;
712
741
  if (opts.number !== undefined) {
713
- if (!opts.repo) {
714
- console.error(chalk.red('--number names one PR in one repo; pass --repo <owner/repo> with it.'));
715
- process.exit(1);
742
+ if (!opts.repo)
743
+ prFail('--number names one PR in one repo; pass --repo <owner/repo> with it.');
744
+ number = prNumberOrExit(opts.number);
745
+ }
746
+ if (name === undefined) {
747
+ if (opts.repo !== undefined && number === undefined)
748
+ prFail('Without a project, --repo names the repo of one PR; pass --number with it, or --org to scope the list.');
749
+ if (opts.repo !== undefined && opts.org !== undefined)
750
+ prFail('--org scopes the list; --repo with --number reads one PR. Pass one or the other.');
751
+ let open;
752
+ try {
753
+ open = await buildOpenPrs(listProjectDefs(), { owners: opts.org, repo: opts.repo, number });
716
754
  }
717
- const raw = opts.number.trim();
718
- number = /^\d+$/.test(raw) ? Number.parseInt(raw, 10) : NaN;
719
- if (!Number.isSafeInteger(number) || number <= 0) {
720
- console.error(chalk.red(`--number expects a positive integer, got "${opts.number}".`));
721
- process.exit(1);
755
+ catch (e) {
756
+ prFail(e instanceof Error ? e.message : String(e));
722
757
  }
758
+ if (opts.json)
759
+ console.log(JSON.stringify(open, null, 2));
760
+ else
761
+ printOpenPrs(open);
762
+ if (open.partial)
763
+ process.exit(1);
764
+ return;
723
765
  }
766
+ if (opts.org !== undefined)
767
+ prFail('--org reads across orgs; drop the project name to use it.');
768
+ const def = prProjectOrExit(name);
724
769
  let envelope;
725
770
  try {
726
771
  envelope = await buildProjectPrs(def, { repo: opts.repo, number }, undefined, listProjectDefs());
@@ -772,9 +817,9 @@ export function registerProjectsCommands(program) {
772
817
  process.exit(1);
773
818
  });
774
819
  const mergeCmd = prsCmd
775
- .command('merge <name>')
776
- .description('Merge one open PR of a project, pinned to the head SHA you reviewed.')
777
- .requiredOption('--repo <owner/repo>', 'One of the project\'s attached repos')
820
+ .command('merge [name]')
821
+ .description('Merge one open PR, pinned to the head SHA you reviewed.')
822
+ .requiredOption('--repo <owner/repo>', 'owner/repo (with a project name, one of its attached repos)')
778
823
  .requiredOption('--number <n>', 'The PR number')
779
824
  .requiredOption('--sha <head-sha>', 'The head SHA you reviewed; GitHub refuses if the branch moved since')
780
825
  .option('--method <method>', `${MERGE_METHODS.join(' | ')} (default: the first the repo allows, in that order)`)
@@ -804,6 +849,7 @@ export function registerProjectsCommands(program) {
804
849
  agents projects prs rush --json --repo phnx-labs/agi-cli --number 3646 # read headSha + mergeableState
805
850
  agents projects prs merge rush --repo phnx-labs/agi-cli --number 3646 --sha <headSha>
806
851
  agents projects prs merge rush --repo phnx-labs/agi-cli --number 3646 --sha <headSha> --method squash --json
852
+ agents projects prs merge --repo muqsitnawaz/agents --number 12 --sha <headSha> # any repo, no project
807
853
  `,
808
854
  notes: `
809
855
  The merge is a single REST call pinned to --sha: if anything was pushed after
@@ -813,14 +859,16 @@ export function registerProjectsCommands(program) {
813
859
  computed goes on to the call and GitHub decides. --admin skips that refusal and lets a
814
860
  repository admin merge past branch protection where GitHub allows it; it exists
815
861
  for a person's explicit confirm (AGI Menu's "Confirm admin merge") and agents
816
- must never pass it. To land a PR once its checks pass, use prs automerge. A
862
+ must never pass it. To land a PR once its checks pass, use prs automerge.
863
+ Every prs verb takes the project name optionally: without it, --repo may be any
864
+ owner/repo you can reach, as the GitHub tab of AGI Menu uses them. A
817
865
  refusal exits 1 with GitHub's reason (merged: false in --json).
818
866
  `,
819
867
  });
820
868
  const automergeCmd = prsCmd
821
- .command('automerge <name>')
869
+ .command('automerge [name]')
822
870
  .description('Turn GitHub auto-merge on (or off with --off) for one open PR, so it merges itself once its required checks pass.')
823
- .requiredOption('--repo <owner/repo>', 'One of the project\'s attached repos')
871
+ .requiredOption('--repo <owner/repo>', 'owner/repo (with a project name, one of its attached repos)')
824
872
  .requiredOption('--number <n>', 'The PR number')
825
873
  .option('--sha <head-sha>', 'The head SHA you reviewed (required to turn it on); GitHub refuses if the branch moved since')
826
874
  .option('--method <method>', `${MERGE_METHODS.join(' | ')} (default: the first the repo allows, in that order)`)
@@ -864,9 +912,9 @@ export function registerProjectsCommands(program) {
864
912
  `,
865
913
  });
866
914
  const readyCmd = prsCmd
867
- .command('ready <name>')
868
- .description('Mark one draft PR of a project ready for review.')
869
- .requiredOption('--repo <owner/repo>', 'One of the project\'s attached repos')
915
+ .command('ready [name]')
916
+ .description('Mark one draft PR ready for review.')
917
+ .requiredOption('--repo <owner/repo>', 'owner/repo (with a project name, one of its attached repos)')
870
918
  .requiredOption('--number <n>', 'The PR number')
871
919
  .option('--sha <head-sha>', 'The head SHA you looked at; refused if the branch moved since')
872
920
  .option('--json', 'Machine-readable result')
@@ -899,9 +947,9 @@ export function registerProjectsCommands(program) {
899
947
  `,
900
948
  });
901
949
  const reviewCmd = prsCmd
902
- .command('review <name>')
903
- .description('Approve one open PR of a project, pinned to the head SHA you reviewed.')
904
- .requiredOption('--repo <owner/repo>', 'One of the project\'s attached repos')
950
+ .command('review [name]')
951
+ .description('Approve one open PR, pinned to the head SHA you reviewed.')
952
+ .requiredOption('--repo <owner/repo>', 'owner/repo (with a project name, one of its attached repos)')
905
953
  .requiredOption('--number <n>', 'The PR number')
906
954
  .requiredOption('--sha <head-sha>', 'The head SHA you reviewed; refused if the branch moved since')
907
955
  .option('--approve', 'Submit an approving review (the only review this command submits)')
@@ -938,9 +986,9 @@ export function registerProjectsCommands(program) {
938
986
  `,
939
987
  });
940
988
  const commentCmd = prsCmd
941
- .command('comment <name>')
942
- .description('Post a comment on one open PR of a project.')
943
- .requiredOption('--repo <owner/repo>', 'One of the project\'s attached repos')
989
+ .command('comment [name]')
990
+ .description('Post a comment on one open PR.')
991
+ .requiredOption('--repo <owner/repo>', 'owner/repo (with a project name, one of its attached repos)')
944
992
  .requiredOption('--number <n>', 'The PR number')
945
993
  .option('--body <text>', 'The comment text')
946
994
  .option('--body-file <path>', 'Read the comment from a file; - reads stdin')
@@ -971,9 +1019,9 @@ export function registerProjectsCommands(program) {
971
1019
  `,
972
1020
  });
973
1021
  const failureCmd = prsCmd
974
- .command('failure <name>')
1022
+ .command('failure [name]')
975
1023
  .description('Why one commit\'s CI failed: each failing check with the error lines of its job log.')
976
- .requiredOption('--repo <owner/repo>', 'One of the project\'s attached repos')
1024
+ .requiredOption('--repo <owner/repo>', 'owner/repo (with a project name, one of its attached repos)')
977
1025
  .requiredOption('--sha <commit>', 'The commit whose checks failed: a PR head, a merge commit, or the default branch head')
978
1026
  .option('--json', 'Machine-readable result')
979
1027
  .action(async (name, opts) => {
@@ -998,7 +1046,7 @@ export function registerProjectsCommands(program) {
998
1046
  if (check.excerptError)
999
1047
  console.log(chalk.yellow(` ${check.excerptError}`));
1000
1048
  if (check.runId !== null)
1001
- console.log(chalk.gray(` re-run: agents projects prs rerun ${name} --repo ${repo} --run-id ${check.runId}`));
1049
+ console.log(chalk.gray(` re-run: agents projects prs rerun ${name ? `${name} ` : ''}--repo ${repo} --run-id ${check.runId}`));
1002
1050
  }
1003
1051
  }
1004
1052
  if (report.error)
@@ -1021,9 +1069,9 @@ export function registerProjectsCommands(program) {
1021
1069
  `,
1022
1070
  });
1023
1071
  const rerunCmd = prsCmd
1024
- .command('rerun <name>')
1072
+ .command('rerun [name]')
1025
1073
  .description('Re-run the failed jobs of one GitHub Actions workflow run.')
1026
- .requiredOption('--repo <owner/repo>', 'One of the project\'s attached repos')
1074
+ .requiredOption('--repo <owner/repo>', 'owner/repo (with a project name, one of its attached repos)')
1027
1075
  .requiredOption('--run-id <id>', 'The workflow run (runId from prs failure --json)')
1028
1076
  .option('--json', 'Machine-readable result')
1029
1077
  .action(async (name, opts) => {
@@ -1056,6 +1104,7 @@ export function registerProjectsCommands(program) {
1056
1104
  });
1057
1105
  setHelpSections(prsCmd, {
1058
1106
  examples: `
1107
+ agents projects prs --json # every open PR across your account and orgs, needs-me first
1059
1108
  agents projects prs rush --json # every open PR across rush's repos (= prs list rush)
1060
1109
  agents projects prs rush --json --repo phnx-labs/agi-cli --number 3646 # one PR, with checks + mergeability
1061
1110
  agents projects prs ready rush --repo phnx-labs/agi-cli --number 3646 --sha <headSha>
@@ -1068,14 +1117,28 @@ export function registerProjectsCommands(program) {
1068
1117
  });
1069
1118
  setHelpSections(prsListCmd, {
1070
1119
  examples: `
1120
+ agents projects prs --json # every open PR across your account and every org you belong to
1121
+ agents projects prs --json --org phnx-labs --org muqsitnawaz
1122
+ agents projects prs --json --repo phnx-labs/agi-cli --number 3646 # one PR in any repo, with checks + review + mergeability
1071
1123
  agents projects prs rush --json # every open PR across rush's repos
1072
1124
  agents projects prs rush --json --repo phnx-labs/agi-cli
1073
1125
  agents projects prs rush --json --repo phnx-labs/agi-cli --number 3646 # one PR, with checks + review + mergeability
1074
1126
  agents projects prs merge rush --repo phnx-labs/agi-cli --number 3646 --sha <headSha>
1075
1127
  `,
1076
1128
  notes: `
1077
- Repos come from the project definition's attached repos only (repo + repos[].slug);
1078
- --repo is refused unless it is one of them.
1129
+ Without a project, the read covers you and every org you belong to (--org
1130
+ narrows it): one REST search per owner (GitHub caps a search at 1000 results;
1131
+ owners[].truncated says when it was hit), one for review requests from you, then
1132
+ each PR's REST detail and checks, cached like the project read. Each PR carries
1133
+ reviewRequested and needsMe: review (a review is requested from you), failing
1134
+ (yours, CI red) or conflicts (yours, conflicts with its base), else null; each
1135
+ repository's PRs come needs-me first, then most recently updated, and
1136
+ repositories are ordered by their most urgent PR. Each repository names the
1137
+ projects that attach it. With --org, review requests count only inside those
1138
+ owners. A failed owner or review-request search marks the read partial.
1139
+
1140
+ With a project, repos come from its definition's attached repos only (repo +
1141
+ repos[].slug); --repo is refused unless it is one of them.
1079
1142
 
1080
1143
  The list is read from GitHub over REST and paginated in full, drafts included,
1081
1144
  with no author filter. checks and reviewDecision are null in the list; --number
@@ -11,17 +11,8 @@ export interface LiveStatusFlags {
11
11
  queued?: boolean;
12
12
  unknown?: boolean;
13
13
  }
14
- export declare function statusColor(status: ActiveSession['status']): (s: string) => string;
15
- export declare function cleanPreview(text: string): string;
16
- export declare function buildSessionDescription(s: ActiveSession): string;
17
14
  export declare function formatActiveRowDescription(s: ActiveSession): string;
18
15
  export declare function indexActiveBySessionId(active: ActiveSession[]): Map<string, ActiveSession>;
19
- export declare function liveGlyphAndPreview(a: ActiveSession | undefined): {
20
- glyph: string;
21
- preview: string;
22
- };
23
- export declare function liveStatusWord(a: ActiveSession | undefined): string;
24
- export declare function isAwaitingUser(s: ActiveSession): boolean;
25
16
  export declare function renderActiveRowLines(s: ActiveSession, indent: string, termW: number): string[];
26
17
  export declare function ownerLabel(s: ActiveSession): string;
27
18
  interface ActiveSessionsLayout {
@@ -48,8 +39,6 @@ interface MachineGroupedLayout {
48
39
  export declare function groupSessionsByMachine(sessions: ActiveSession[], localMachine: string): MachineGroupedLayout;
49
40
  export declare function dedupeByMachineSession(sessions: ActiveSession[]): ActiveSession[];
50
41
  export declare function filterActiveSessionsByHostScope(sessions: ActiveSession[], hosts: string[] | undefined, self: string): ActiveSession[];
51
- export declare function shouldIncludeLocal(hosts: string[] | undefined, self: string): boolean;
52
- export declare function remoteHostsToDial(hosts: string[] | undefined, self: string): string[] | undefined;
53
42
  export declare function gatherActiveSessions(opts?: {
54
43
  local?: boolean;
55
44
  hosts?: string[];
@@ -1,76 +1,22 @@
1
1
  import * as path from 'path';
2
2
  import chalk from 'chalk';
3
3
  import { sessionDisplayAgent, linkUrl } from '@phnx-labs/sessions-cli/reader';
4
- import { toComparablePath, homeDir } from '../lib/platform/index.js';
5
4
  import { getActiveSessions, describeActiveDiscoveryHealth, sessionProcessIsLocal, backfillActiveRowsFromIndex, isRunningLiveSession, serializeActiveSessionsForJson, } from '../lib/session/active.js';
6
5
  import { enumerateGhosttyTabs, assignGhosttyTabs } from '../lib/session/ghostty-tabs.js';
7
6
  import { mapPanesToTargets, listClients } from '../lib/tmux/session.js';
8
7
  import { resolveViewingIn, viewingInLabel } from '../lib/session/viewing-in.js';
9
8
  import { machineId, normalizeHost } from '../lib/session/sync/config.js';
10
9
  import { gatherRemoteActive } from '../lib/session/remote-active.js';
10
+ import { hostToken, remoteHostsToDial, shouldIncludeLocal } from '../lib/session/remote-list.js';
11
11
  import { loadFleetActiveSessions, loadLocalActiveSessions } from '../lib/session/session-cache.js';
12
12
  import { stringWidth, truncateToWidth, padToWidth, terminalWidth } from '../lib/session/width.js';
13
13
  import { formatCompactAge } from '../lib/session/relative-time.js';
14
14
  import { colorAgent } from '../lib/agents.js';
15
15
  import { fuzzyMatch, FUZZY_PRESETS } from '../lib/fuzzy.js';
16
16
  import { listBookmarks } from '../lib/session/bookmarks.js';
17
- import { signalBadges } from '../lib/session/presentation.js';
18
- import { formatTodoCompact, githubRepoUrlFromCwd } from './sessions-picker.js';
17
+ import { cleanPreview, formatTodoCompact, isAwaitingUser, shortCwd, signalBadges, statusColor } from '../lib/session/presentation.js';
18
+ import { githubRepoUrlFromCwd } from './sessions-picker.js';
19
19
  import { isInteractiveTerminal } from './utils.js';
20
- function shortCwd(cwd) {
21
- if (!cwd)
22
- return '-';
23
- const home = homeDir();
24
- return toComparablePath(cwd).startsWith(toComparablePath(home))
25
- ? '~' + cwd.slice(home.length)
26
- : cwd;
27
- }
28
- export function statusColor(status) {
29
- switch (status) {
30
- case 'running': return chalk.green;
31
- case 'idle': return chalk.gray;
32
- case 'queued': return chalk.blue;
33
- case 'input_required': return chalk.yellow;
34
- case 'closed': return chalk.dim;
35
- case 'abandoned': return chalk.red;
36
- case 'crashed': return chalk.redBright;
37
- case 'orphaned': return chalk.yellow;
38
- case 'unknown': return chalk.magenta;
39
- }
40
- }
41
- export function cleanPreview(text) {
42
- // eslint-disable-next-line no-control-regex
43
- return text
44
- .replace(/\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/g, '')
45
- .replace(/\x1b\[[0-9;?]*[A-Za-z]/g, '')
46
- .replace(/<\/?(?:local-command-stdout|command-name|command-message|command-args|task-notification|system-reminder)>/g, '')
47
- .replace(/\s+/g, ' ')
48
- .trim();
49
- }
50
- export function buildSessionDescription(s) {
51
- const todo = formatTodoCompact(s.todos);
52
- if (s.context === 'cloud') {
53
- const base = s.preview || `${s.cloudProvider ?? ''}${s.cloudTaskId ? ` · ${s.cloudTaskId.slice(0, 12)}` : ''}`;
54
- return cleanPreview([todo, base].filter(Boolean).join(' · '));
55
- }
56
- if (s.context === 'teams') {
57
- const parts = [s.teamName];
58
- if (s.label && s.label !== s.teamName)
59
- parts.push(s.label);
60
- const orch = s.orchestratorLabel || (s.orchestratorSessionId ? s.orchestratorSessionId.slice(0, 8) : '');
61
- if (orch)
62
- parts.push(`by ${orch}`);
63
- if (todo)
64
- parts.push(todo);
65
- const target = s.preview || s.assignedTask || s.topic;
66
- if (target)
67
- parts.push(target);
68
- return cleanPreview(parts.filter(Boolean).join(' · '));
69
- }
70
- // ladder-exempt: compact live preview base, not the row's headline.
71
- const base = s.preview || s.label || s.topic || '';
72
- return cleanPreview([todo, base].filter(Boolean).join(' · '));
73
- }
74
20
  export function formatActiveRowDescription(s) {
75
21
  const parts = [];
76
22
  const pushText = (t) => {
@@ -122,52 +68,6 @@ export function indexActiveBySessionId(active) {
122
68
  }
123
69
  return byId;
124
70
  }
125
- export function liveGlyphAndPreview(a) {
126
- if (!a)
127
- return { glyph: '', preview: '' };
128
- if (a.status === 'abandoned')
129
- return { glyph: statusColor(a.status)('⊘'), preview: buildSessionDescription(a) };
130
- if (a.status === 'closed')
131
- return { glyph: statusColor(a.status)('×'), preview: buildSessionDescription(a) };
132
- if (a.status === 'crashed')
133
- return { glyph: statusColor(a.status)('✗'), preview: buildSessionDescription(a) };
134
- if (a.status === 'orphaned')
135
- return { glyph: statusColor(a.status)('◍'), preview: buildSessionDescription(a) };
136
- const waiting = a.status === 'input_required' || a.activity === 'waiting_input';
137
- const running = a.status === 'running' || a.activity === 'working';
138
- const unknown = a.status === 'unknown';
139
- const shape = waiting ? '◐'
140
- : running ? '●'
141
- : unknown ? '◌'
142
- : '○';
143
- return { glyph: statusColor(a.status)(shape), preview: buildSessionDescription(a) };
144
- }
145
- export function liveStatusWord(a) {
146
- if (!a)
147
- return '';
148
- if (a.status === 'closed' || a.status === 'abandoned')
149
- return a.status;
150
- if (a.status === 'crashed')
151
- return 'crashed';
152
- if (a.status === 'orphaned')
153
- return 'orphan';
154
- if (a.status === 'input_required' || a.activity === 'waiting_input')
155
- return 'waiting';
156
- if (a.status === 'running' || a.activity === 'working')
157
- return 'working';
158
- if (a.status === 'idle' || a.activity === 'idle')
159
- return 'idle';
160
- if (a.status === 'queued')
161
- return 'queued';
162
- return '';
163
- }
164
- export function isAwaitingUser(s) {
165
- if (s.status === 'crashed' || s.status === 'closed')
166
- return false;
167
- if (s.status === 'abandoned' && s.pidAlive !== true)
168
- return false;
169
- return s.status === 'input_required' || s.activity === 'waiting_input';
170
- }
171
71
  function locatorBadge(s) {
172
72
  const p = s.provenance;
173
73
  const parts = [];
@@ -498,19 +398,6 @@ async function enrichTmuxLocators(local, surfaces = []) {
498
398
  }
499
399
  catch { }
500
400
  }
501
- function hostToken(h) {
502
- return normalizeHost(h.split('@').pop() || h);
503
- }
504
- export function shouldIncludeLocal(hosts, self) {
505
- if (!hosts || hosts.length === 0)
506
- return true;
507
- return hosts.some(h => hostToken(h) === self);
508
- }
509
- export function remoteHostsToDial(hosts, self) {
510
- if (!hosts || hosts.length === 0)
511
- return undefined;
512
- return hosts.filter(h => hostToken(h) !== self);
513
- }
514
401
  export async function gatherActiveSessions(opts = {}) {
515
402
  const forceRefresh = opts.forceRefresh === true
516
403
  || process.env.AGENTS_SESSIONS_FORCE_REFRESH === '1';
@@ -4,3 +4,13 @@ export declare const PS_STATUSES: readonly LiveStatusFilter[];
4
4
  export declare function statusFlags(values: string[] | undefined): LiveStatusFlags;
5
5
  export declare function deviceScope(devices: string[] | undefined): string[] | undefined;
6
6
  export declare function registerPsCommand(program: Command): void;
7
+ export declare function registerSessionPreviewCommand(parent: Command, group: 'ps' | 'sessions'): void;
8
+ export declare function renderSessionPreview(query: string, scope: {
9
+ agent?: string;
10
+ project?: string;
11
+ local?: boolean;
12
+ hosts?: string[];
13
+ json?: boolean;
14
+ refresh?: boolean;
15
+ revision?: string;
16
+ }): Promise<void>;