@michaelhartmayer/agentctl 1.1.0 → 1.1.3

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.
package/dist/src/index.js DELETED
@@ -1,351 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- const commander_1 = require("commander");
8
- const path_1 = __importDefault(require("path"));
9
- require("fs-extra");
10
- const ctl_1 = require("./ctl");
11
- const resolve_1 = require("./resolve");
12
- const child_process_1 = require("child_process");
13
- const chalk_1 = __importDefault(require("chalk"));
14
- const program = new commander_1.Command();
15
- const package_json_1 = __importDefault(require("../package.json"));
16
- program
17
- .name('agentctl')
18
- .description('Agent Controller CLI - Unified control plane for humans and agents')
19
- .version(package_json_1.default.version)
20
- .allowUnknownOption()
21
- .helpOption(false) // Disable default help to allow pass-through
22
- .argument('[command...]', 'Command to run')
23
- .action(async (args, _options, _command) => {
24
- // If no args, check for help flag or just show help
25
- if (!args || args.length === 0) {
26
- // If they passed --help or -h, show help. If no args at all, show help.
27
- // Since we ate options, we check raw args or just treat empty args as help.
28
- // command.opts() won't have help if we disabled it?
29
- // Actually, if we disable helpOption, --help becomes an unknown option or arg.
30
- // Let's check process.argv for -h or --help if args is empty?
31
- // "agentctl --help" -> args=[], options might contain help if we didn't disable it?
32
- // With helpOption(false), --help is just a flag in argv.
33
- // If args is empty and we see help flag, show help.
34
- if (process.argv.includes('--help') || process.argv.includes('-h') || process.argv.length <= 2) {
35
- program.help();
36
- return;
37
- }
38
- }
39
- // If args are present, we try to resolve.
40
- // BUT, "agentctl --help" will result in args being empty if it's parsed as option?
41
- // Wait, if helpOption(false), then --help is an unknown option.
42
- // If allowUnknownOption is true, it might not be in 'args' if it looks like a flag.
43
- // Let's rely on resolveCommand. passed args are variadic.
44
- // However, "agentctl dev --help" -> args=["dev", "--help"]?
45
- // My repro says yes: [ 'dev-tools', 'gh', '--help' ].
46
- // So for "agentctl --help", args might be ["--help"].
47
- if (args.length === 1 && (args[0] === '--help' || args[0] === '-h')) {
48
- program.help();
49
- return;
50
- }
51
- // Bypass for ctl subcommand if it slipped through (shouldn't if registered)
52
- if (args[0] === 'ctl')
53
- return;
54
- try {
55
- // resolveCommand needs to handle flags in args if they are part of the path?
56
- // No, flags usually come after. resolveCommand stops at first non-matching path part?
57
- // resolveCommand logic: iterates args.
58
- // "dev-tools gh --help" -> path "dev-tools gh", remaining "--help"
59
- const result = await (0, resolve_1.resolveCommand)(args);
60
- if (!result) {
61
- // If not found, and they asked for help, show root help?
62
- // Or if they just typed a wrong command.
63
- if (args.includes('--help') || args.includes('-h')) {
64
- // Try to show help for the partial command?
65
- // For now, just show root list/help or error.
66
- // If it's "agentctl dev --help" and "dev" is a group, resolveCommand SHOULD return the group.
67
- }
68
- console.error(chalk_1.default.red(`Command '${args.join(' ')}' not found.`));
69
- console.log(`Run ${chalk_1.default.cyan('agentctl list')} to see available commands.`);
70
- process.exit(1);
71
- }
72
- const { manifest, args: remainingArgs, scope } = result;
73
- if (manifest.run) {
74
- // ... run logic ...
75
- // remainingArgs should contain --help if it was passed.
76
- const cmdDir = path_1.default.dirname(result.manifestPath);
77
- let runCmd = manifest.run;
78
- // Resolve relative path
79
- if (runCmd.startsWith('./') || runCmd.startsWith('.\\')) {
80
- runCmd = path_1.default.resolve(cmdDir, runCmd);
81
- }
82
- // Interpolate {{DIR}}
83
- runCmd = runCmd.replace(/{{DIR}}/g, cmdDir);
84
- const fullCommand = `${runCmd} ${remainingArgs.join(' ')}`;
85
- console.log(chalk_1.default.dim(`[${scope}] Running: ${fullCommand}`));
86
- const child = (0, child_process_1.spawn)(fullCommand, {
87
- cwd: process.cwd(), // Execute in CWD as discussed
88
- shell: true,
89
- stdio: 'inherit',
90
- env: { ...process.env, AGENTCTL_SCOPE: scope }
91
- });
92
- child.on('exit', (code) => {
93
- process.exit(code || 0);
94
- });
95
- }
96
- else {
97
- // Group
98
- console.log(chalk_1.default.blue(chalk_1.default.bold(`${manifest.name}`)));
99
- console.log(manifest.description || 'No description');
100
- console.log('\nSubcommands:');
101
- const all = await (0, ctl_1.list)();
102
- const prefix = result.cmdPath + ' ';
103
- // Filter logic roughly for direct children
104
- const depth = result.cmdPath.split(' ').length;
105
- const children = all.filter(c => c.path.startsWith(prefix) && c.path !== result.cmdPath);
106
- const direct = children.filter(c => c.path.split(' ').length === depth + 1);
107
- if (direct.length === 0 && children.length === 0) {
108
- console.log(chalk_1.default.dim(' (No subcommands found)'));
109
- }
110
- for (const child of direct) {
111
- console.log(` ${child.path.split(' ').pop()}\t${chalk_1.default.dim(child.description)}`);
112
- }
113
- }
114
- }
115
- catch (e) {
116
- if (e instanceof Error) {
117
- console.error(chalk_1.default.red(e.message));
118
- }
119
- else {
120
- console.error(chalk_1.default.red('An unknown error occurred'));
121
- }
122
- process.exit(1);
123
- }
124
- });
125
- const ctl = program.command('ctl')
126
- .description('Agent Controller Management - Create, organize, and manage commands');
127
- // --- Lifecycle Commands ---
128
- // We'll stick to flat list but with good descriptions.
129
- // Helper for consistent error handling
130
- // Helper for consistent error handling
131
- const withErrorHandling = (fn) => {
132
- return async (...args) => {
133
- try {
134
- await fn(...args);
135
- }
136
- catch (e) {
137
- if (e instanceof Error) {
138
- console.error(chalk_1.default.red(e.message));
139
- }
140
- else {
141
- console.error(chalk_1.default.red(String(e)));
142
- }
143
- process.exit(1);
144
- }
145
- };
146
- };
147
- ctl.command('scaffold')
148
- .description('Scaffold a new command script (creates a manifest and a .sh/.cmd file)')
149
- .argument('[path...]', 'The hierarchical path for the new command (e.g. "dev start")')
150
- .addHelpText('after', `
151
- Description:
152
- Scaffolding creates a new directory for your command containing a 'manifest.json'
153
- and a boilerplate script file (.sh on Linux/Mac, .cmd on Windows).
154
- You can then edit the script to add your own logic.
155
-
156
- Examples:
157
- $ agentctl ctl scaffold dev start
158
- $ agentctl ctl scaffold utils/backup
159
- `)
160
- .action(withErrorHandling(async (pathParts, _options, command) => {
161
- if (!pathParts || pathParts.length === 0) {
162
- command.help();
163
- return;
164
- }
165
- await (0, ctl_1.scaffold)(pathParts);
166
- }));
167
- ctl.command('alias')
168
- .description('Create an alias command that executes a shell string')
169
- .argument('[path_and_cmd...]', 'Hierarchical path segments followed by the shell command')
170
- .action(withErrorHandling(async (args, _options, command) => {
171
- if (!args || args.length < 2) {
172
- command.help();
173
- return;
174
- }
175
- const target = args.pop();
176
- const name = args;
177
- await (0, ctl_1.alias)(name, target);
178
- }))
179
- .addHelpText('after', `
180
- How it works:
181
- The last argument is always treated as the shell command to execute.
182
- All preceding arguments form the hierarchical path.
183
-
184
- If the shell command contains spaces, wrap it in quotes.
185
-
186
- Examples:
187
- $ agentctl ctl alias tools git-status "git status"
188
- -> Creates 'agentctl tools git-status' which runs 'git status'.
189
-
190
- $ agentctl ctl alias dev build "npm run build"
191
- -> Creates 'agentctl dev build' which runs 'npm run build'.
192
- `);
193
- ctl.command('group')
194
- .description('Create a command group (namespace) to organize related commands')
195
- .argument('[path...]', 'Hierarchical path for the group (e.g. "dev")')
196
- .addHelpText('after', `
197
- Description:
198
- Groups are essentially folders that contain other commands.
199
- They don't execute anything themselves but provide organization.
200
-
201
- Examples:
202
- $ agentctl ctl group dev
203
- $ agentctl ctl group tools/internal
204
- `)
205
- .action(withErrorHandling(async (parts, _options, command) => {
206
- if (!parts || parts.length === 0) {
207
- command.help();
208
- return;
209
- }
210
- await (0, ctl_1.group)(parts);
211
- }));
212
- ctl.command('rm')
213
- .description('Remove a command or group permanently')
214
- .argument('[path...]', 'Command path to remove')
215
- .option('--global', 'Remove from global scope')
216
- .addHelpText('after', `
217
- Examples:
218
- $ agentctl ctl rm dev start
219
- $ agentctl ctl rm tools --global
220
- `)
221
- .action(withErrorHandling(async (parts, opts, command) => {
222
- if (!parts || parts.length === 0) {
223
- command.help();
224
- return;
225
- }
226
- await (0, ctl_1.rm)(parts, { global: opts.global });
227
- }));
228
- ctl.command('mv')
229
- .description('Move or rename a command or group')
230
- .argument('[src]', 'Current path of the command')
231
- .argument('[dest]', 'New path for the command')
232
- .option('--global', 'Perform operation in global scope')
233
- .addHelpText('after', `
234
- Examples:
235
- $ agentctl ctl mv "dev start" "dev boot"
236
- $ agentctl ctl mv tools/gh tools/github --global
237
- `)
238
- .action(withErrorHandling(async (src, dest, opts, command) => {
239
- if (!src || !dest) {
240
- command.help();
241
- return;
242
- }
243
- await (0, ctl_1.mv)(src.split(' '), dest.split(' '), { global: opts.global });
244
- }));
245
- // --- Introspection ---
246
- ctl.command('list')
247
- .description('List all available commands across local and global scopes')
248
- .action(withErrorHandling(async () => {
249
- const items = await (0, ctl_1.list)();
250
- console.log('TYPE SCOPE COMMAND DESCRIPTION');
251
- for (const item of items) {
252
- console.log(`${item.type.padEnd(9)} ${item.scope.padEnd(9)} ${item.path.padEnd(19)} ${item.description}`);
253
- }
254
- }));
255
- ctl.command('inspect')
256
- .description('Inspect the internal manifest and details of a command')
257
- .argument('[path...]', 'Command path to inspect')
258
- .action(withErrorHandling(async (parts, _options, command) => {
259
- if (!parts || parts.length === 0) {
260
- command.help();
261
- return;
262
- }
263
- const info = await (0, ctl_1.inspect)(parts);
264
- if (info) {
265
- console.log(JSON.stringify(info, null, 2));
266
- }
267
- else {
268
- console.error('Command not found');
269
- process.exit(1);
270
- }
271
- }));
272
- // --- Scoping ---
273
- ctl.command('global')
274
- .description('Push a local command to the global scope')
275
- .argument('[path...]', 'Local command path')
276
- .option('--move', 'Move instead of copy')
277
- .option('--copy', 'Copy (default)')
278
- .addHelpText('after', `
279
- Examples:
280
- $ agentctl ctl global sys --move
281
- $ agentctl ctl global tools --copy
282
- `)
283
- .action(withErrorHandling(async (parts, opts, command) => {
284
- if (!parts || parts.length === 0) {
285
- command.help();
286
- return;
287
- }
288
- await (0, ctl_1.pushGlobal)(parts, { move: opts.move, copy: opts.copy || !opts.move });
289
- }));
290
- ctl.command('local')
291
- .description('Pull a global command to the local scope')
292
- .argument('[path...]', 'Global command path')
293
- .option('--move', 'Move instead of copy')
294
- .option('--copy', 'Copy (default)')
295
- .addHelpText('after', `
296
- Examples:
297
- $ agentctl ctl local tools --copy
298
- `)
299
- .action(withErrorHandling(async (parts, opts, command) => {
300
- if (!parts || parts.length === 0) {
301
- command.help();
302
- return;
303
- }
304
- await (0, ctl_1.pullLocal)(parts, { move: opts.move, copy: opts.copy || !opts.move });
305
- }));
306
- // --- Agent Integration ---
307
- // We attach this to the root `ctl` as options or a sub-command?
308
- // Original code had it as options on `ctl`. We can make it a command for better help.
309
- // But sticking to options maintains compatibility. We'll improve the option help.
310
- ctl.option('--install-skill <agent>', 'Install skill for agent (cursor, antigravity, agentsmd, gemini)')
311
- .option('--global', 'Install skill globally (for supported agents)')
312
- .addHelpText('after', `
313
- Examples:
314
- $ agentctl ctl --install-skill cursor
315
- $ agentctl ctl --install-skill antigravity --global
316
- $ agentctl ctl --install-skill gemini
317
- `)
318
- .action(withErrorHandling(async (op, command) => {
319
- const opts = ctl.opts();
320
- if (opts.installSkill) {
321
- await (0, ctl_1.installSkill)(opts.installSkill, { global: opts.global });
322
- }
323
- else {
324
- // If no subcmd and no option, show help
325
- if (command.args.length === 0) {
326
- ctl.help();
327
- }
328
- }
329
- }));
330
- // Inject dynamic commands into root help
331
- // We need to do this before parsing
332
- (async () => {
333
- try {
334
- const allCommands = await (0, ctl_1.list)();
335
- const topLevel = allCommands.filter(c => !c.path.includes(' ')); // Only top level
336
- if (topLevel.length > 0) {
337
- const lines = [''];
338
- lines.push('User Commands:');
339
- for (const cmd of topLevel) {
340
- // simple padding
341
- lines.push(` ${cmd.path.padEnd(27)}${cmd.description}`);
342
- }
343
- lines.push('');
344
- program.addHelpText('after', lines.join('\n'));
345
- }
346
- }
347
- catch {
348
- // Ignore errors during help generation (e.g. if not initialized)
349
- }
350
- program.parse(process.argv);
351
- })();
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.readManifest = readManifest;
7
- exports.isCappedManifest = isCappedManifest;
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
9
- async function readManifest(p) {
10
- try {
11
- return await fs_extra_1.default.readJson(p);
12
- }
13
- catch {
14
- return null;
15
- }
16
- }
17
- function isCappedManifest(m) {
18
- return !!m.run || m.type === 'scaffold' || m.type === 'alias';
19
- }
@@ -1,112 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.resolveCommand = resolveCommand;
7
- const path_1 = __importDefault(require("path"));
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const fs_utils_1 = require("./fs-utils");
10
- const manifest_1 = require("./manifest");
11
- async function resolveCommand(args, options = {}) {
12
- const cwd = options.cwd || process.cwd();
13
- const localRoot = !options.global ? (0, fs_utils_1.findLocalRoot)(cwd) : null;
14
- const globalRoot = options.globalDir || (0, fs_utils_1.getGlobalRoot)();
15
- const localAgentctl = localRoot ? path_1.default.join(localRoot, '.agentctl') : null;
16
- let currentMatch = null;
17
- // Iterate through args to find longest match
18
- for (let i = 0; i < args.length; i++) {
19
- // Path corresponding to args[0..i]
20
- const currentArgs = args.slice(0, i + 1);
21
- const relPath = currentArgs.join(path_1.default.sep);
22
- const cmdPath = currentArgs.join(' ');
23
- const localPath = localAgentctl ? path_1.default.join(localAgentctl, relPath) : null;
24
- const globalPath = path_1.default.join(globalRoot, relPath);
25
- let localManifest = null;
26
- let globalManifest = null;
27
- // check local
28
- if (localPath && await fs_extra_1.default.pathExists(localPath)) {
29
- const mPath = path_1.default.join(localPath, 'manifest.json');
30
- if (await fs_extra_1.default.pathExists(mPath)) {
31
- localManifest = await (0, manifest_1.readManifest)(mPath);
32
- }
33
- if (!localManifest && (await fs_extra_1.default.stat(localPath)).isDirectory()) {
34
- // Implicit group
35
- localManifest = { name: args[i], type: 'group' };
36
- }
37
- }
38
- // check global
39
- if (await fs_extra_1.default.pathExists(globalPath)) {
40
- const mPath = path_1.default.join(globalPath, 'manifest.json');
41
- if (await fs_extra_1.default.pathExists(mPath)) {
42
- globalManifest = await (0, manifest_1.readManifest)(mPath);
43
- }
44
- if (!globalManifest && (await fs_extra_1.default.stat(globalPath)).isDirectory()) {
45
- globalManifest = { name: args[i], type: 'group' };
46
- }
47
- }
48
- if (!localManifest && !globalManifest) {
49
- break;
50
- }
51
- const remainingArgs = args.slice(i + 1);
52
- // Priority logic
53
- // 1. Local Capped -> Return Match immediately.
54
- if (localManifest && (0, manifest_1.isCappedManifest)(localManifest)) {
55
- return {
56
- manifest: localManifest,
57
- manifestPath: path_1.default.join(localPath, 'manifest.json'),
58
- args: remainingArgs,
59
- scope: 'local',
60
- cmdPath
61
- };
62
- }
63
- // 2. Global Capped
64
- if (globalManifest && (0, manifest_1.isCappedManifest)(globalManifest)) {
65
- // Check if shadowed by Local Group
66
- if (localManifest) {
67
- // Local exists (must be group since checked capped above).
68
- // Shadowed. Treat as Local Group.
69
- currentMatch = {
70
- manifest: localManifest,
71
- manifestPath: path_1.default.join(localPath, 'manifest.json'),
72
- args: remainingArgs,
73
- scope: 'local',
74
- cmdPath
75
- };
76
- }
77
- else {
78
- // Not shadowed. Global Capped wins. Return immediately.
79
- return {
80
- manifest: globalManifest,
81
- manifestPath: path_1.default.join(globalPath, 'manifest.json'),
82
- args: remainingArgs,
83
- scope: 'global',
84
- cmdPath
85
- };
86
- }
87
- }
88
- else {
89
- // Neither is capped. Both are groups (or one is).
90
- // Local wins if exists.
91
- if (localManifest) {
92
- currentMatch = {
93
- manifest: localManifest,
94
- manifestPath: path_1.default.join(localPath, 'manifest.json'),
95
- args: remainingArgs,
96
- scope: 'local',
97
- cmdPath
98
- };
99
- }
100
- else {
101
- currentMatch = {
102
- manifest: globalManifest,
103
- manifestPath: path_1.default.join(globalPath, 'manifest.json'),
104
- args: remainingArgs,
105
- scope: 'global',
106
- cmdPath
107
- };
108
- }
109
- }
110
- }
111
- return currentMatch;
112
- }
@@ -1,39 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.SUPPORTED_AGENTS = void 0;
7
- exports.copySkill = copySkill;
8
- const path_1 = __importDefault(require("path"));
9
- const fs_extra_1 = __importDefault(require("fs-extra"));
10
- exports.SUPPORTED_AGENTS = ['cursor', 'antigravity', 'agentsmd', 'gemini'];
11
- async function copySkill(targetDir, agent) {
12
- // We assume the skill file is located at ../skills/agentctl/SKILL.md relative to specific dist/src/ location
13
- // Or we find it in the project root if running from source.
14
- // In production (dist), structure might be:
15
- // dist/index.js
16
- // skills/agentctl/SKILL.md (if we copy it to dist)
17
- // Let's try to locate the source SKILL.md
18
- // If we are in /src, it is in ../skills/agentctl/SKILL.md
19
- // If we are in /dist/src (tsc default?), it depends on build.
20
- // Robust finding:
21
- let sourcePath = path_1.default.resolve(__dirname, '../../skills/agentctl/SKILL.md');
22
- if (!fs_extra_1.default.existsSync(sourcePath)) {
23
- // Try looking in src check (dev mode)
24
- sourcePath = path_1.default.resolve(__dirname, '../skills/agentctl/SKILL.md');
25
- }
26
- if (!fs_extra_1.default.existsSync(sourcePath)) {
27
- // Fallback for when running from dist/src
28
- sourcePath = path_1.default.resolve(__dirname, '../../../skills/agentctl/SKILL.md');
29
- }
30
- if (!fs_extra_1.default.existsSync(sourcePath)) {
31
- throw new Error(`Could not locate source SKILL.md. Checked: ${path_1.default.resolve(__dirname, '../../skills/agentctl/SKILL.md')}`);
32
- }
33
- await fs_extra_1.default.ensureDir(targetDir);
34
- // Determine filename
35
- const filename = agent === 'cursor' ? 'agentctl.md' : 'SKILL.md';
36
- const targetFile = path_1.default.join(targetDir, filename);
37
- await fs_extra_1.default.copy(sourcePath, targetFile, { overwrite: true });
38
- return targetFile;
39
- }