@phnx-labs/agents-cli 1.16.0 → 1.17.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 (64) hide show
  1. package/CHANGELOG.md +71 -0
  2. package/dist/commands/browser.js +248 -9
  3. package/dist/commands/cloud.js +8 -0
  4. package/dist/commands/exec.js +70 -1
  5. package/dist/commands/import.d.ts +24 -0
  6. package/dist/commands/import.js +203 -0
  7. package/dist/commands/plugins.js +179 -5
  8. package/dist/commands/prune.js +6 -0
  9. package/dist/commands/secrets.js +117 -19
  10. package/dist/commands/view.js +21 -8
  11. package/dist/commands/workflows.d.ts +10 -0
  12. package/dist/commands/workflows.js +457 -0
  13. package/dist/index.js +34 -16
  14. package/dist/lib/browser/cdp.js +7 -4
  15. package/dist/lib/browser/chrome.d.ts +10 -0
  16. package/dist/lib/browser/chrome.js +37 -2
  17. package/dist/lib/browser/drivers/local.js +13 -2
  18. package/dist/lib/browser/input.d.ts +1 -0
  19. package/dist/lib/browser/input.js +3 -0
  20. package/dist/lib/browser/ipc.js +14 -0
  21. package/dist/lib/browser/profiles.d.ts +5 -0
  22. package/dist/lib/browser/profiles.js +45 -0
  23. package/dist/lib/browser/service.d.ts +10 -0
  24. package/dist/lib/browser/service.js +29 -1
  25. package/dist/lib/browser/types.d.ts +11 -1
  26. package/dist/lib/cloud/rush.d.ts +28 -1
  27. package/dist/lib/cloud/rush.js +68 -13
  28. package/dist/lib/commands.d.ts +0 -15
  29. package/dist/lib/commands.js +5 -5
  30. package/dist/lib/hooks.js +24 -11
  31. package/dist/lib/import.d.ts +91 -0
  32. package/dist/lib/import.js +179 -0
  33. package/dist/lib/migrate.js +59 -1
  34. package/dist/lib/permissions.d.ts +0 -58
  35. package/dist/lib/permissions.js +10 -10
  36. package/dist/lib/plugins.d.ts +75 -34
  37. package/dist/lib/plugins.js +640 -133
  38. package/dist/lib/resource-patterns.d.ts +41 -0
  39. package/dist/lib/resource-patterns.js +82 -0
  40. package/dist/lib/resources/index.d.ts +17 -0
  41. package/dist/lib/resources/index.js +7 -0
  42. package/dist/lib/resources/types.d.ts +1 -1
  43. package/dist/lib/resources/workflows.d.ts +24 -0
  44. package/dist/lib/resources/workflows.js +110 -0
  45. package/dist/lib/resources.d.ts +6 -1
  46. package/dist/lib/resources.js +12 -2
  47. package/dist/lib/session/db.d.ts +18 -0
  48. package/dist/lib/session/db.js +106 -7
  49. package/dist/lib/session/discover.d.ts +6 -0
  50. package/dist/lib/session/discover.js +28 -17
  51. package/dist/lib/shims.d.ts +3 -51
  52. package/dist/lib/shims.js +18 -10
  53. package/dist/lib/sqlite.js +10 -4
  54. package/dist/lib/state.d.ts +15 -2
  55. package/dist/lib/state.js +29 -8
  56. package/dist/lib/types.d.ts +43 -14
  57. package/dist/lib/versions.d.ts +3 -0
  58. package/dist/lib/versions.js +139 -27
  59. package/dist/lib/workflows.d.ts +79 -0
  60. package/dist/lib/workflows.js +233 -0
  61. package/package.json +1 -5
  62. package/scripts/postinstall.js +59 -58
  63. package/dist/commands/fork.d.ts +0 -10
  64. package/dist/commands/fork.js +0 -146
@@ -9,7 +9,7 @@ import * as os from 'os';
9
9
  import * as readline from 'readline';
10
10
 
11
11
  const HOME = os.homedir();
12
- const SHIMS_DIR = path.join(HOME, '.agents-system', 'shims');
12
+ const SHIMS_DIR = path.join(HOME, '.agents', '.cache', 'shims');
13
13
  const SYSTEM_DIR = path.join(HOME, '.agents-system');
14
14
  const USER_DIR = path.join(HOME, '.agents');
15
15
 
@@ -111,7 +111,8 @@ const exportLine = shellName === 'fish'
111
111
  ? `fish_add_path ${SHIMS_DIR}`
112
112
  : `export PATH="${SHIMS_DIR}:$PATH"`;
113
113
 
114
- const ALIASES = ['sessions', 'teams'];
114
+ // Shorthands that delegate to `agents <name>` — written unconditionally on install.
115
+ const ALIASES = ['sessions', 'secrets', 'browser', 'pty', 'teams'];
115
116
 
116
117
  function writeAliasShims() {
117
118
  const written = [];
@@ -124,6 +125,27 @@ function writeAliasShims() {
124
125
  return written;
125
126
  }
126
127
 
128
+ function getVersion() {
129
+ const pkgPath = new URL('../package.json', import.meta.url).pathname;
130
+ try {
131
+ return JSON.parse(fs.readFileSync(pkgPath, 'utf-8')).version;
132
+ } catch { return null; }
133
+ }
134
+
135
+ function getChangelogSection(version) {
136
+ const changelogPath = new URL('../CHANGELOG.md', import.meta.url).pathname;
137
+ if (!fs.existsSync(changelogPath)) return null;
138
+ const lines = fs.readFileSync(changelogPath, 'utf-8').split('\n');
139
+ let inSection = false;
140
+ const section = [];
141
+ for (const line of lines) {
142
+ if (line.startsWith(`## ${version}`)) { inSection = true; continue; }
143
+ if (inSection && line.startsWith('## ')) break;
144
+ if (inSection) section.push(line);
145
+ }
146
+ return section.length ? section.join('\n').trim() : null;
147
+ }
148
+
127
149
  function ask(question) {
128
150
  return new Promise((resolve) => {
129
151
  const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
@@ -134,33 +156,18 @@ function ask(question) {
134
156
  });
135
157
  }
136
158
 
137
- async function promptForAliases() {
138
- if (!process.stdin.isTTY || !process.stdout.isTTY) return 'skip';
139
- console.log(`
140
- Install bare-command aliases for common subcommands?
141
- This creates ${ALIASES.map((n) => `\`${n}\``).join(', ')} as wrappers in ${SHIMS_DIR}
142
- so you can type \`sessions\` instead of \`agents sessions\`.
143
-
144
- 1) Let's do it
145
- 2) Skip this time
146
- 3) I'll do it manually if needed
147
- `);
148
- const answer = await ask('Choose [1/2/3] (default 1): ');
149
- if (answer === '' || answer === '1') return 'install';
150
- if (answer === '3') return 'manual';
151
- return 'skip';
159
+ function isAlreadyConfigured(rcFile) {
160
+ if (!fs.existsSync(rcFile)) return false;
161
+ const content = fs.readFileSync(rcFile, 'utf-8');
162
+ // Accept either the new path or the legacy ~/.agents-system/shims path
163
+ return content.includes('.agents/.cache/shims') || content.includes('.agents-system/shims');
152
164
  }
153
165
 
154
166
  async function main() {
155
167
  // Opt-in: AGENTS_INIT_SHELL=1 npm install -g @phnx-labs/agents-cli
156
168
  if (process.env.AGENTS_INIT_SHELL === '1') {
157
169
  const rcFile = getShellRc();
158
- let alreadyConfigured = false;
159
- if (fs.existsSync(rcFile)) {
160
- const content = fs.readFileSync(rcFile, 'utf-8');
161
- alreadyConfigured = content.includes('.agents-system/shims');
162
- }
163
- if (!alreadyConfigured) {
170
+ if (!isAlreadyConfigured(rcFile)) {
164
171
  const addition = `\n# agents-cli: version switching for AI coding agents\n${exportLine}\n`;
165
172
  fs.mkdirSync(path.dirname(rcFile), { recursive: true });
166
173
  fs.appendFileSync(rcFile, addition);
@@ -169,53 +176,47 @@ async function main() {
169
176
  }
170
177
  writeAliasShims();
171
178
  console.log(` Installed bare-command aliases: ${ALIASES.join(', ')}\n`);
172
- return;
173
- }
174
-
175
- // Default: offer to auto-add shims to PATH (like homebrew does)
176
- const rcFile = getShellRc();
177
- let alreadyConfigured = false;
178
- if (fs.existsSync(rcFile)) {
179
- const content = fs.readFileSync(rcFile, 'utf-8');
180
- alreadyConfigured = content.includes('.agents-system/shims');
181
- }
182
-
183
- console.log(`\nagents-cli installed.`);
179
+ } else {
180
+ // Default: offer to auto-add shims to PATH (like homebrew does)
181
+ const rcFile = getShellRc();
184
182
 
185
- if (!alreadyConfigured && process.stdin.isTTY && process.stdout.isTTY) {
186
- const answer = await ask(`\nAdd shims to PATH in ~/${path.basename(rcFile)}? [Y/n] `);
187
- if (answer === '' || answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes') {
188
- const addition = `\n# agents-cli: version switching for AI coding agents\n${exportLine}\n`;
189
- fs.mkdirSync(path.dirname(rcFile), { recursive: true });
190
- fs.appendFileSync(rcFile, addition);
191
- console.log(`\n Added ${SHIMS_DIR} to PATH in ${path.basename(rcFile)}`);
192
- console.log(` Restart your shell or run: source ~/${path.basename(rcFile)}\n`);
193
- } else {
194
- console.log(`
183
+ console.log(`\nagents-cli installed.`);
184
+
185
+ if (!isAlreadyConfigured(rcFile) && process.stdin.isTTY && process.stdout.isTTY) {
186
+ const answer = await ask(`\nAdd shims to PATH in ~/${path.basename(rcFile)}? [Y/n] `);
187
+ if (answer === '' || answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes') {
188
+ const addition = `\n# agents-cli: version switching for AI coding agents\n${exportLine}\n`;
189
+ fs.mkdirSync(path.dirname(rcFile), { recursive: true });
190
+ fs.appendFileSync(rcFile, addition);
191
+ console.log(`\n Added ${SHIMS_DIR} to PATH in ${path.basename(rcFile)}`);
192
+ console.log(` Restart your shell or run: source ~/${path.basename(rcFile)}\n`);
193
+ } else {
194
+ console.log(`
195
195
  To enable version-aware shims, add this to your shell config:
196
196
 
197
197
  ${exportLine}
198
198
  `);
199
- }
200
- } else if (!alreadyConfigured) {
201
- console.log(`
199
+ }
200
+ } else if (!isAlreadyConfigured(rcFile)) {
201
+ console.log(`
202
202
  To enable version-aware shims, add this to your shell config:
203
203
 
204
204
  ${exportLine}
205
205
  `);
206
- }
206
+ }
207
207
 
208
- const choice = await promptForAliases();
209
- if (choice === 'install') {
210
208
  const written = writeAliasShims();
211
- console.log(`\n Installed aliases: ${written.join(', ')} (in ${SHIMS_DIR})`);
212
- console.log(` Make sure ${SHIMS_DIR} is on your PATH (see above).\n`);
213
- } else if (choice === 'manual') {
214
- console.log(`\n To add aliases later, drop these in a directory on your PATH:`);
215
- for (const name of ALIASES) {
216
- console.log(` ${name} -> exec agents ${name} "$@"`);
209
+ console.log(` Installed shorthands: ${written.join(', ')}`);
210
+ }
211
+
212
+ const version = getVersion();
213
+ if (version) {
214
+ const section = getChangelogSection(version);
215
+ if (section) {
216
+ console.log(`\nWhat's new in ${version}:\n`);
217
+ console.log(section);
218
+ console.log('');
217
219
  }
218
- console.log('');
219
220
  }
220
221
  }
221
222
 
@@ -1,10 +0,0 @@
1
- /**
2
- * Repository fork command.
3
- *
4
- * Registers the `agents fork` command which forks the default system
5
- * config repo to the user's GitHub account, reconfigures remotes
6
- * (origin -> user fork, upstream -> system repo), and pushes.
7
- */
8
- import type { Command } from 'commander';
9
- /** Register the `agents fork` command. */
10
- export declare function registerForkCommand(program: Command): void;
@@ -1,146 +0,0 @@
1
- /**
2
- * Repository fork command.
3
- *
4
- * Registers the `agents fork` command which forks the default system
5
- * config repo to the user's GitHub account, reconfigures remotes
6
- * (origin -> user fork, upstream -> system repo), and pushes.
7
- */
8
- import chalk from 'chalk';
9
- import ora from 'ora';
10
- import { getAgentsDir, ensureAgentsDir } from '../lib/state.js';
11
- import { isGitRepo, isSystemRepoOrigin, getGitHubUsername, hasLocalChanges, setUpstreamRemote, setRemoteUrl, getRemoteUrl, } from '../lib/git.js';
12
- import { DEFAULT_SYSTEM_REPO, systemRepoSlug } from '../lib/types.js';
13
- import { isPromptCancelled } from './utils.js';
14
- /** Register the `agents fork` command. */
15
- export function registerForkCommand(program) {
16
- program
17
- .command('fork')
18
- .description('Copy the default config repo to your own GitHub so you can push changes. Runs once after setup.')
19
- .addHelpText('after', `
20
- Examples:
21
- # Fork the default repo to your GitHub account
22
- agents fork
23
-
24
- When to use:
25
- - You set up with 'agents setup' using the default config
26
- - You've customized commands, skills, or settings
27
- - You want to save your changes to your own GitHub repo
28
-
29
- What it does:
30
- 1. Creates a fork of the default repo under your GitHub account (gh:yourname/.agents)
31
- 2. Reconfigures remotes: origin -> your fork, upstream -> default repo
32
- 3. Commits any local changes you've made
33
- 4. Pushes everything to your new fork
34
-
35
- After forking:
36
- - 'agents push' sends your changes to your fork
37
- - 'agents pull --upstream' pulls updates from the default repo
38
-
39
- Requirements:
40
- - GitHub CLI authenticated (run 'gh auth login' if needed)
41
- - ~/.agents/ must be tracking the default repo (not already forked)
42
- `)
43
- .action(async () => {
44
- try {
45
- const agentsDir = getAgentsDir();
46
- ensureAgentsDir();
47
- // Check if ~/.agents/ is a git repo
48
- if (!isGitRepo(agentsDir)) {
49
- console.log(chalk.yellow('~/.agents/ is not a git repository.'));
50
- console.log(chalk.gray('\nInitialize first:'));
51
- console.log(chalk.cyan(' agents pull'));
52
- return;
53
- }
54
- // Check if already forked (origin is not system repo)
55
- if (!await isSystemRepoOrigin(agentsDir)) {
56
- const currentOrigin = await getRemoteUrl(agentsDir);
57
- console.log(chalk.green('Already forked!'));
58
- console.log(chalk.gray(`\nOrigin: ${currentOrigin}`));
59
- console.log(chalk.gray('\nTo push your changes:'));
60
- console.log(chalk.cyan(' agents push'));
61
- console.log(chalk.gray('\nTo pull updates from system repo:'));
62
- console.log(chalk.cyan(' agents pull --upstream'));
63
- return;
64
- }
65
- // Get GitHub username
66
- const spinner = ora('Checking GitHub...').start();
67
- const username = await getGitHubUsername();
68
- if (!username) {
69
- spinner.fail('GitHub CLI not authenticated');
70
- console.log(chalk.gray('\nTo authenticate:'));
71
- console.log(chalk.cyan(' gh auth login'));
72
- return;
73
- }
74
- spinner.succeed(`Logged in as ${username}`);
75
- // Fork the system repo
76
- const forkSpinner = ora('Forking system repo...').start();
77
- const { execFile } = await import('child_process');
78
- const { promisify } = await import('util');
79
- const execFileAsync = promisify(execFile);
80
- const repoSlug = systemRepoSlug(DEFAULT_SYSTEM_REPO);
81
- try {
82
- // gh repo fork creates a fork and optionally clones it
83
- // We just want to create the fork on GitHub, not clone
84
- await execFileAsync('gh', ['repo', 'fork', repoSlug, '--clone=false']);
85
- forkSpinner.succeed(`Forked to ${username}/.agents`);
86
- }
87
- catch (err) {
88
- const errorMsg = err.message;
89
- // Check if fork already exists
90
- if (errorMsg.includes('already exists') || errorMsg.includes('409')) {
91
- forkSpinner.info(`Fork ${username}/.agents already exists`);
92
- }
93
- else {
94
- forkSpinner.fail(`Failed to fork: ${errorMsg}`);
95
- return;
96
- }
97
- }
98
- // Reconfigure remotes
99
- const remoteSpinner = ora('Reconfiguring remotes...').start();
100
- // Set current origin as upstream
101
- await setUpstreamRemote(agentsDir, `https://github.com/${repoSlug}.git`);
102
- // Set user's fork as new origin
103
- await setRemoteUrl(agentsDir, `https://github.com/${username}/.agents.git`);
104
- remoteSpinner.succeed('Reconfigured remotes');
105
- console.log(chalk.gray(` origin -> ${username}/.agents`));
106
- console.log(chalk.gray(` upstream -> ${repoSlug}`));
107
- // Commit any local changes
108
- if (await hasLocalChanges(agentsDir)) {
109
- const commitSpinner = ora('Committing local changes...').start();
110
- const simpleGit = (await import('simple-git')).default;
111
- const git = simpleGit(agentsDir);
112
- await git.add('-A');
113
- await git.commit('Local changes before fork');
114
- commitSpinner.succeed('Committed local changes');
115
- }
116
- // Push to new origin
117
- const pushSpinner = ora('Pushing to your fork...').start();
118
- try {
119
- const simpleGit = (await import('simple-git')).default;
120
- const git = simpleGit(agentsDir);
121
- await git.push('origin', 'main', ['--set-upstream']);
122
- pushSpinner.succeed('Pushed to your fork');
123
- }
124
- catch (err) {
125
- pushSpinner.fail(`Push failed: ${err.message}`);
126
- console.log(chalk.yellow('\nYou can push manually later:'));
127
- console.log(chalk.cyan(' agents push'));
128
- return;
129
- }
130
- console.log(chalk.green('\nFork complete!'));
131
- console.log(chalk.gray(`\nView: https://github.com/${username}/.agents`));
132
- console.log(chalk.gray('\nTo push future changes:'));
133
- console.log(chalk.cyan(' agents push'));
134
- console.log(chalk.gray('\nTo pull updates from system repo:'));
135
- console.log(chalk.cyan(' agents pull --upstream'));
136
- }
137
- catch (err) {
138
- if (isPromptCancelled(err)) {
139
- console.log(chalk.yellow('\nCancelled'));
140
- process.exit(0);
141
- }
142
- console.error(chalk.red(err.message));
143
- process.exit(1);
144
- }
145
- });
146
- }