@phnx-labs/agents-cli 1.14.3 → 1.14.4
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/browser.d.ts +2 -0
- package/dist/browser.js +7 -0
- package/dist/commands/browser.d.ts +1 -0
- package/dist/commands/browser.js +4 -0
- package/dist/commands/teams.js +25 -3
- package/dist/commands/view.js +1 -1
- package/dist/index.js +0 -0
- package/dist/lib/migrate.js +46 -0
- package/dist/lib/resources/commands.d.ts +46 -0
- package/dist/lib/resources/commands.js +208 -0
- package/dist/lib/resources/hooks.d.ts +12 -0
- package/dist/lib/resources/hooks.js +136 -0
- package/dist/lib/resources/index.d.ts +36 -0
- package/dist/lib/resources/index.js +69 -0
- package/dist/lib/resources/mcp.d.ts +34 -0
- package/dist/lib/resources/mcp.js +483 -0
- package/dist/lib/resources/permissions.d.ts +13 -0
- package/dist/lib/resources/permissions.js +184 -0
- package/dist/lib/resources/rules.d.ts +43 -0
- package/dist/lib/resources/rules.js +146 -0
- package/dist/lib/resources/skills.d.ts +37 -0
- package/dist/lib/resources/skills.js +238 -0
- package/dist/lib/resources/subagents.d.ts +46 -0
- package/dist/lib/resources/subagents.js +198 -0
- package/dist/lib/resources/types.d.ts +82 -0
- package/dist/lib/resources/types.js +8 -0
- package/dist/lib/state.js +3 -5
- package/dist/lib/teams/registry.d.ts +4 -0
- package/dist/lib/teams/registry.js +4 -0
- package/dist/lib/versions.d.ts +2 -1
- package/dist/lib/versions.js +20 -14
- package/package.json +3 -2
package/dist/browser.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import { registerBrowserSubcommands } from './commands/browser.js';
|
|
4
|
+
const program = new Command();
|
|
5
|
+
program.name('browser').description('Browser automation via CDP');
|
|
6
|
+
registerBrowserSubcommands(program);
|
|
7
|
+
program.parse();
|
package/dist/commands/browser.js
CHANGED
|
@@ -8,6 +8,10 @@ export function registerBrowserCommand(program) {
|
|
|
8
8
|
registerProfilesCommands(browser);
|
|
9
9
|
registerTaskCommands(browser);
|
|
10
10
|
}
|
|
11
|
+
export function registerBrowserSubcommands(program) {
|
|
12
|
+
registerProfilesCommands(program);
|
|
13
|
+
registerTaskCommands(program);
|
|
14
|
+
}
|
|
11
15
|
function registerProfilesCommands(browser) {
|
|
12
16
|
const profiles = browser
|
|
13
17
|
.command('profiles')
|
package/dist/commands/teams.js
CHANGED
|
@@ -679,12 +679,14 @@ Name teammates with --name alice to refer to them as 'alice' instead of a UUID.
|
|
|
679
679
|
.description('Start a new team. No teammates yet; add them with `teams add`.')
|
|
680
680
|
.option('-d, --description <text>', 'One-line summary of what this team is working on')
|
|
681
681
|
.option('--enable-worktrees', 'Each teammate works in its own git worktree (requires --worktree on add)')
|
|
682
|
+
.option('--use-worktree <path>', 'All teammates share this existing worktree path (mutually exclusive with --enable-worktrees)')
|
|
682
683
|
.option('--json', 'Output machine-readable JSON')
|
|
683
684
|
.action(async (team, opts) => {
|
|
684
685
|
try {
|
|
685
686
|
const meta = await createTeam(team, {
|
|
686
687
|
description: opts.description,
|
|
687
688
|
enableWorktrees: opts.enableWorktrees,
|
|
689
|
+
useWorktree: opts.useWorktree,
|
|
688
690
|
});
|
|
689
691
|
if (isJsonMode(opts)) {
|
|
690
692
|
console.log(JSON.stringify({ team, ...meta }, null, 2));
|
|
@@ -694,7 +696,9 @@ Name teammates with --name alice to refer to them as 'alice' instead of a UUID.
|
|
|
694
696
|
if (meta.description)
|
|
695
697
|
console.log(chalk.gray(` ${meta.description}`));
|
|
696
698
|
if (meta.enable_worktrees)
|
|
697
|
-
console.log(chalk.gray(` worktrees:
|
|
699
|
+
console.log(chalk.gray(` worktrees: per-teammate`));
|
|
700
|
+
if (meta.use_worktree)
|
|
701
|
+
console.log(chalk.gray(` worktree: ${meta.use_worktree}`));
|
|
698
702
|
console.log();
|
|
699
703
|
console.log(chalk.gray('Add your first teammate:'));
|
|
700
704
|
if (meta.enable_worktrees) {
|
|
@@ -776,12 +780,30 @@ Name teammates with --name alice to refer to them as 'alice' instead of a UUID.
|
|
|
776
780
|
}
|
|
777
781
|
// Auto-create the team if it doesn't exist yet (friendlier UX than erroring).
|
|
778
782
|
await ensureTeam(team);
|
|
779
|
-
// Check if team has worktrees enabled
|
|
783
|
+
// Check if team has worktrees enabled or a shared worktree
|
|
780
784
|
const teamMeta = await getTeam(team);
|
|
781
785
|
const worktreesEnabled = teamMeta?.enable_worktrees ?? false;
|
|
786
|
+
const sharedWorktree = teamMeta?.use_worktree ?? null;
|
|
782
787
|
let worktreeName = null;
|
|
783
788
|
let worktreePath = null;
|
|
784
|
-
if (
|
|
789
|
+
if (sharedWorktree) {
|
|
790
|
+
// Team uses a shared worktree for all teammates
|
|
791
|
+
const fsp = await import('fs/promises');
|
|
792
|
+
try {
|
|
793
|
+
const stat = await fsp.stat(sharedWorktree);
|
|
794
|
+
if (!stat.isDirectory()) {
|
|
795
|
+
die(`Shared worktree path is not a directory: ${sharedWorktree}`);
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
catch {
|
|
799
|
+
die(`Shared worktree path does not exist: ${sharedWorktree}`);
|
|
800
|
+
}
|
|
801
|
+
worktreePath = sharedWorktree;
|
|
802
|
+
if (opts.worktree) {
|
|
803
|
+
die(`Team '${team}' uses --use-worktree (shared). Don't pass --worktree on add.`);
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
else if (worktreesEnabled) {
|
|
785
807
|
if (!opts.worktree) {
|
|
786
808
|
die(`Team '${team}' has worktrees enabled. Use --worktree <name> to specify a worktree name.`);
|
|
787
809
|
}
|
package/dist/commands/view.js
CHANGED
|
@@ -336,7 +336,7 @@ async function showInstalledVersions(filterAgentId) {
|
|
|
336
336
|
const available = getAvailableResources();
|
|
337
337
|
const synced = getActuallySyncedResources(filterAgentId, defaultVersion);
|
|
338
338
|
const newResources = getNewResources(available, synced);
|
|
339
|
-
if (hasNewResources(newResources, filterAgentId)) {
|
|
339
|
+
if (hasNewResources(newResources, filterAgentId, defaultVersion)) {
|
|
340
340
|
try {
|
|
341
341
|
const selection = await promptNewResourceSelection(filterAgentId, newResources);
|
|
342
342
|
if (selection && Object.keys(selection).length > 0) {
|
package/dist/index.js
CHANGED
|
File without changes
|
package/dist/lib/migrate.js
CHANGED
|
@@ -152,6 +152,49 @@ function migrateUserVersionsToSystem() {
|
|
|
152
152
|
console.log(`Skipped ${skippedCount} version dir${skippedCount === 1 ? '' : 's'} already present in ~/.agents-system/versions/ (kept legacy copy at ~/.agents/versions/)`);
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Move ~/. agents/runs/ -> ~/.agents/routines/runs/.
|
|
157
|
+
* Runs now live inside routines directory for cleaner organization.
|
|
158
|
+
*/
|
|
159
|
+
function migrateRunsIntoRoutines() {
|
|
160
|
+
const src = path.join(USER_DIR, 'runs');
|
|
161
|
+
const dest = path.join(USER_DIR, 'routines', 'runs');
|
|
162
|
+
if (!fs.existsSync(src) || fs.existsSync(dest))
|
|
163
|
+
return;
|
|
164
|
+
try {
|
|
165
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true, mode: 0o700 });
|
|
166
|
+
fs.renameSync(src, dest);
|
|
167
|
+
}
|
|
168
|
+
catch { /* best-effort */ }
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Move ~/.agents/trash/ -> ~/.agents/.trash/.
|
|
172
|
+
* Hide the trash directory.
|
|
173
|
+
*/
|
|
174
|
+
function migrateTrashToHidden() {
|
|
175
|
+
const src = path.join(USER_DIR, 'trash');
|
|
176
|
+
const dest = path.join(USER_DIR, '.trash');
|
|
177
|
+
if (!fs.existsSync(src) || fs.existsSync(dest))
|
|
178
|
+
return;
|
|
179
|
+
try {
|
|
180
|
+
fs.renameSync(src, dest);
|
|
181
|
+
}
|
|
182
|
+
catch { /* best-effort */ }
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Move ~/.agents/backups/ -> ~/.agents/.backups/.
|
|
186
|
+
* Hide the backups directory.
|
|
187
|
+
*/
|
|
188
|
+
function migrateBackupsToHidden() {
|
|
189
|
+
const src = path.join(USER_DIR, 'backups');
|
|
190
|
+
const dest = path.join(USER_DIR, '.backups');
|
|
191
|
+
if (!fs.existsSync(src) || fs.existsSync(dest))
|
|
192
|
+
return;
|
|
193
|
+
try {
|
|
194
|
+
fs.renameSync(src, dest);
|
|
195
|
+
}
|
|
196
|
+
catch { /* best-effort */ }
|
|
197
|
+
}
|
|
155
198
|
/** Run all idempotent migrations. Safe to call multiple times. */
|
|
156
199
|
export function runMigration() {
|
|
157
200
|
migrateAgentsYaml();
|
|
@@ -159,4 +202,7 @@ export function runMigration() {
|
|
|
159
202
|
migrateSystemConfigJson();
|
|
160
203
|
migratePromptcutsIntoHooks();
|
|
161
204
|
migrateUserVersionsToSystem();
|
|
205
|
+
migrateRunsIntoRoutines();
|
|
206
|
+
migrateTrashToHidden();
|
|
207
|
+
migrateBackupsToHidden();
|
|
162
208
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Commands resource handler.
|
|
3
|
+
*
|
|
4
|
+
* Commands are slash-command definitions stored as .md files (Claude/Codex/Cursor/OpenCode)
|
|
5
|
+
* or .toml files (Gemini). This handler resolves commands across layers (project > user > system),
|
|
6
|
+
* handles format conversion during sync, and provides consistent list/resolve/sync behavior.
|
|
7
|
+
*/
|
|
8
|
+
import type { AgentId, ResolvedItem, ResourceHandler, ResourceKind } from './types.js';
|
|
9
|
+
/** Command item metadata. */
|
|
10
|
+
export interface CommandItem {
|
|
11
|
+
name: string;
|
|
12
|
+
description: string;
|
|
13
|
+
content: string;
|
|
14
|
+
format: 'md' | 'toml';
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Commands resource handler implementing ResourceHandler<CommandItem>.
|
|
18
|
+
*/
|
|
19
|
+
export declare class CommandsHandler implements ResourceHandler<CommandItem> {
|
|
20
|
+
readonly kind: ResourceKind;
|
|
21
|
+
/**
|
|
22
|
+
* List all commands across layers, with higher layer winning on name conflict.
|
|
23
|
+
* Returns a union of all commands, deduplicated by name.
|
|
24
|
+
*/
|
|
25
|
+
listAll(agent: AgentId, cwd?: string): ResolvedItem<CommandItem>[];
|
|
26
|
+
/**
|
|
27
|
+
* Resolve a single command by name.
|
|
28
|
+
* Returns the winning layer's version, or null if not found.
|
|
29
|
+
*/
|
|
30
|
+
resolve(agent: AgentId, name: string, cwd?: string): ResolvedItem<CommandItem> | null;
|
|
31
|
+
/**
|
|
32
|
+
* Sync resolved commands to the agent's version home directory.
|
|
33
|
+
* Copies/transforms commands as needed for the agent's expected format.
|
|
34
|
+
*/
|
|
35
|
+
sync(agent: AgentId, versionHome: string, cwd?: string): void;
|
|
36
|
+
/**
|
|
37
|
+
* Get the file format this resource uses for a given agent.
|
|
38
|
+
*/
|
|
39
|
+
format(agent: AgentId): 'md' | 'toml';
|
|
40
|
+
/**
|
|
41
|
+
* Get the target directory name in the agent's version home.
|
|
42
|
+
*/
|
|
43
|
+
targetDir(agent: AgentId): string;
|
|
44
|
+
}
|
|
45
|
+
/** Singleton instance of the commands handler. */
|
|
46
|
+
export declare const commandsHandler: CommandsHandler;
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Commands resource handler.
|
|
3
|
+
*
|
|
4
|
+
* Commands are slash-command definitions stored as .md files (Claude/Codex/Cursor/OpenCode)
|
|
5
|
+
* or .toml files (Gemini). This handler resolves commands across layers (project > user > system),
|
|
6
|
+
* handles format conversion during sync, and provides consistent list/resolve/sync behavior.
|
|
7
|
+
*/
|
|
8
|
+
import * as fs from 'fs';
|
|
9
|
+
import * as path from 'path';
|
|
10
|
+
import { getProjectAgentsDir, getUserAgentsDir, getSystemAgentsDir, getEnabledExtraRepos, } from '../state.js';
|
|
11
|
+
import { AGENTS } from '../agents.js';
|
|
12
|
+
import { markdownToToml } from '../convert.js';
|
|
13
|
+
/**
|
|
14
|
+
* Get the commands directory for a given layer root.
|
|
15
|
+
*/
|
|
16
|
+
function getCommandsDirForRoot(root) {
|
|
17
|
+
return path.join(root, 'commands');
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Parse a command file and extract metadata.
|
|
21
|
+
*/
|
|
22
|
+
function parseCommandFile(filePath) {
|
|
23
|
+
if (!fs.existsSync(filePath))
|
|
24
|
+
return null;
|
|
25
|
+
try {
|
|
26
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
27
|
+
const format = filePath.endsWith('.toml') ? 'toml' : 'md';
|
|
28
|
+
const name = path.basename(filePath).replace(/\.(md|toml)$/, '');
|
|
29
|
+
let description = '';
|
|
30
|
+
if (format === 'md') {
|
|
31
|
+
// Parse YAML frontmatter for description
|
|
32
|
+
const lines = content.split('\n');
|
|
33
|
+
if (lines[0] === '---') {
|
|
34
|
+
const endIndex = lines.slice(1).findIndex((l) => l === '---');
|
|
35
|
+
if (endIndex > 0) {
|
|
36
|
+
const frontmatter = lines.slice(1, endIndex + 1).join('\n');
|
|
37
|
+
const descMatch = frontmatter.match(/description:\s*(.+)/i);
|
|
38
|
+
if (descMatch)
|
|
39
|
+
description = descMatch[1].trim();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
// Parse TOML for description
|
|
45
|
+
const descMatch = content.match(/description\s*=\s*"([^"]+)"/);
|
|
46
|
+
if (descMatch)
|
|
47
|
+
description = descMatch[1];
|
|
48
|
+
}
|
|
49
|
+
return { name, description, content, format };
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* List command files in a directory.
|
|
57
|
+
*/
|
|
58
|
+
function listCommandsInDir(dir) {
|
|
59
|
+
if (!fs.existsSync(dir))
|
|
60
|
+
return [];
|
|
61
|
+
try {
|
|
62
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
63
|
+
const commands = [];
|
|
64
|
+
for (const entry of entries) {
|
|
65
|
+
if (entry.isFile()) {
|
|
66
|
+
if (entry.name.endsWith('.md')) {
|
|
67
|
+
commands.push({
|
|
68
|
+
name: entry.name.replace('.md', ''),
|
|
69
|
+
path: path.join(dir, entry.name),
|
|
70
|
+
format: 'md',
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
else if (entry.name.endsWith('.toml')) {
|
|
74
|
+
commands.push({
|
|
75
|
+
name: entry.name.replace('.toml', ''),
|
|
76
|
+
path: path.join(dir, entry.name),
|
|
77
|
+
format: 'toml',
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return commands;
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return [];
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Commands resource handler implementing ResourceHandler<CommandItem>.
|
|
90
|
+
*/
|
|
91
|
+
export class CommandsHandler {
|
|
92
|
+
kind = 'command';
|
|
93
|
+
/**
|
|
94
|
+
* List all commands across layers, with higher layer winning on name conflict.
|
|
95
|
+
* Returns a union of all commands, deduplicated by name.
|
|
96
|
+
*/
|
|
97
|
+
listAll(agent, cwd) {
|
|
98
|
+
const seen = new Set();
|
|
99
|
+
const results = [];
|
|
100
|
+
const projectDir = getProjectAgentsDir(cwd);
|
|
101
|
+
const extraRepos = getEnabledExtraRepos();
|
|
102
|
+
// Build layer roots in precedence order: project > user > system > extras
|
|
103
|
+
const roots = [];
|
|
104
|
+
if (projectDir) {
|
|
105
|
+
roots.push({ dir: getCommandsDirForRoot(projectDir), layer: 'project' });
|
|
106
|
+
}
|
|
107
|
+
roots.push({ dir: getCommandsDirForRoot(getUserAgentsDir()), layer: 'user' });
|
|
108
|
+
roots.push({ dir: getCommandsDirForRoot(getSystemAgentsDir()), layer: 'system' });
|
|
109
|
+
for (const extra of extraRepos) {
|
|
110
|
+
roots.push({ dir: getCommandsDirForRoot(extra.dir), layer: 'system' });
|
|
111
|
+
}
|
|
112
|
+
for (const { dir, layer } of roots) {
|
|
113
|
+
const commands = listCommandsInDir(dir);
|
|
114
|
+
for (const cmd of commands) {
|
|
115
|
+
if (seen.has(cmd.name))
|
|
116
|
+
continue;
|
|
117
|
+
seen.add(cmd.name);
|
|
118
|
+
const item = parseCommandFile(cmd.path);
|
|
119
|
+
if (item) {
|
|
120
|
+
results.push({
|
|
121
|
+
name: cmd.name,
|
|
122
|
+
item,
|
|
123
|
+
layer,
|
|
124
|
+
path: cmd.path,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return results;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Resolve a single command by name.
|
|
133
|
+
* Returns the winning layer's version, or null if not found.
|
|
134
|
+
*/
|
|
135
|
+
resolve(agent, name, cwd) {
|
|
136
|
+
const projectDir = getProjectAgentsDir(cwd);
|
|
137
|
+
const extraRepos = getEnabledExtraRepos();
|
|
138
|
+
// Build candidate paths in precedence order
|
|
139
|
+
const candidates = [];
|
|
140
|
+
if (projectDir) {
|
|
141
|
+
candidates.push({ dir: getCommandsDirForRoot(projectDir), layer: 'project' });
|
|
142
|
+
}
|
|
143
|
+
candidates.push({ dir: getCommandsDirForRoot(getUserAgentsDir()), layer: 'user' });
|
|
144
|
+
candidates.push({ dir: getCommandsDirForRoot(getSystemAgentsDir()), layer: 'system' });
|
|
145
|
+
for (const extra of extraRepos) {
|
|
146
|
+
candidates.push({ dir: getCommandsDirForRoot(extra.dir), layer: 'system' });
|
|
147
|
+
}
|
|
148
|
+
for (const { dir, layer } of candidates) {
|
|
149
|
+
// Try .md first, then .toml
|
|
150
|
+
for (const ext of ['.md', '.toml']) {
|
|
151
|
+
const filePath = path.join(dir, `${name}${ext}`);
|
|
152
|
+
const item = parseCommandFile(filePath);
|
|
153
|
+
if (item) {
|
|
154
|
+
return { name, item, layer, path: filePath };
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Sync resolved commands to the agent's version home directory.
|
|
162
|
+
* Copies/transforms commands as needed for the agent's expected format.
|
|
163
|
+
*/
|
|
164
|
+
sync(agent, versionHome, cwd) {
|
|
165
|
+
const agentConfig = AGENTS[agent];
|
|
166
|
+
const targetFormat = this.format(agent);
|
|
167
|
+
const targetDir = path.join(versionHome, `.${agent}`, this.targetDir(agent));
|
|
168
|
+
// Ensure target directory exists
|
|
169
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
170
|
+
// Get all resolved commands
|
|
171
|
+
const commands = this.listAll(agent, cwd);
|
|
172
|
+
for (const resolved of commands) {
|
|
173
|
+
const ext = targetFormat === 'toml' ? '.toml' : '.md';
|
|
174
|
+
const targetPath = path.join(targetDir, `${resolved.name}${ext}`);
|
|
175
|
+
// Convert format if needed
|
|
176
|
+
if (targetFormat === 'toml' && resolved.item.format === 'md') {
|
|
177
|
+
// Convert markdown to TOML
|
|
178
|
+
const tomlContent = markdownToToml(resolved.name, resolved.item.content);
|
|
179
|
+
fs.writeFileSync(targetPath, tomlContent, 'utf-8');
|
|
180
|
+
}
|
|
181
|
+
else if (targetFormat === 'md' && resolved.item.format === 'toml') {
|
|
182
|
+
// For now, copy TOML as-is if target expects md (edge case)
|
|
183
|
+
// In practice, source commands are always .md
|
|
184
|
+
fs.copyFileSync(resolved.path, targetPath);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
// Same format, copy directly
|
|
188
|
+
fs.copyFileSync(resolved.path, targetPath);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Get the file format this resource uses for a given agent.
|
|
194
|
+
*/
|
|
195
|
+
format(agent) {
|
|
196
|
+
const agentConfig = AGENTS[agent];
|
|
197
|
+
return agentConfig.format === 'toml' ? 'toml' : 'md';
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Get the target directory name in the agent's version home.
|
|
201
|
+
*/
|
|
202
|
+
targetDir(agent) {
|
|
203
|
+
const agentConfig = AGENTS[agent];
|
|
204
|
+
return agentConfig.commandsSubdir || 'commands';
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/** Singleton instance of the commands handler. */
|
|
208
|
+
export const commandsHandler = new CommandsHandler();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HooksHandler - ResourceHandler implementation for hooks.
|
|
3
|
+
*
|
|
4
|
+
* Hooks are declared in hooks.yaml at each layer (system, user, project).
|
|
5
|
+
* Resolution: project > user > system (higher layer wins on name conflict).
|
|
6
|
+
* Non-conflicting hooks from all layers are unioned together.
|
|
7
|
+
*/
|
|
8
|
+
import type { ResourceHandler } from './types.js';
|
|
9
|
+
import type { ManifestHook } from '../types.js';
|
|
10
|
+
export type HookItem = ManifestHook;
|
|
11
|
+
export declare const HooksHandler: ResourceHandler<HookItem>;
|
|
12
|
+
export default HooksHandler;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HooksHandler - ResourceHandler implementation for hooks.
|
|
3
|
+
*
|
|
4
|
+
* Hooks are declared in hooks.yaml at each layer (system, user, project).
|
|
5
|
+
* Resolution: project > user > system (higher layer wins on name conflict).
|
|
6
|
+
* Non-conflicting hooks from all layers are unioned together.
|
|
7
|
+
*/
|
|
8
|
+
import * as fs from 'fs';
|
|
9
|
+
import * as path from 'path';
|
|
10
|
+
import * as yaml from 'yaml';
|
|
11
|
+
import { getSystemAgentsDir, getUserAgentsDir, getProjectAgentsDir, } from '../state.js';
|
|
12
|
+
/**
|
|
13
|
+
* Get the hooks.yaml path for a given layer directory.
|
|
14
|
+
*/
|
|
15
|
+
function getHooksYamlPath(layerDir) {
|
|
16
|
+
return path.join(layerDir, 'hooks.yaml');
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Parse hooks.yaml from a directory.
|
|
20
|
+
* Returns empty object if file doesn't exist or is invalid.
|
|
21
|
+
*/
|
|
22
|
+
function parseHooksYaml(dir) {
|
|
23
|
+
const manifestPath = getHooksYamlPath(dir);
|
|
24
|
+
if (!fs.existsSync(manifestPath)) {
|
|
25
|
+
return {};
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const content = fs.readFileSync(manifestPath, 'utf-8');
|
|
29
|
+
const parsed = yaml.parse(content);
|
|
30
|
+
return parsed || {};
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return {};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Get layer directories for hook resolution.
|
|
38
|
+
*/
|
|
39
|
+
function getLayerDirs(cwd) {
|
|
40
|
+
return {
|
|
41
|
+
system: getSystemAgentsDir(),
|
|
42
|
+
user: getUserAgentsDir(),
|
|
43
|
+
project: cwd ? getProjectAgentsDir(cwd) : null,
|
|
44
|
+
extra: [],
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export const HooksHandler = {
|
|
48
|
+
kind: 'hook',
|
|
49
|
+
/**
|
|
50
|
+
* List all hooks across layers, with higher layer winning on name conflict.
|
|
51
|
+
* Returns a union of all hooks, deduplicated by name.
|
|
52
|
+
*/
|
|
53
|
+
listAll(agent, cwd) {
|
|
54
|
+
const layers = getLayerDirs(cwd);
|
|
55
|
+
const result = new Map();
|
|
56
|
+
// Process in precedence order: system first (lowest), then user, then project (highest)
|
|
57
|
+
const layerOrder = [
|
|
58
|
+
{ layer: 'system', dir: layers.system },
|
|
59
|
+
{ layer: 'user', dir: layers.user },
|
|
60
|
+
{ layer: 'project', dir: layers.project },
|
|
61
|
+
];
|
|
62
|
+
for (const { layer, dir } of layerOrder) {
|
|
63
|
+
if (!dir)
|
|
64
|
+
continue;
|
|
65
|
+
const hooks = parseHooksYaml(dir);
|
|
66
|
+
for (const [name, hook] of Object.entries(hooks)) {
|
|
67
|
+
// Skip disabled hooks
|
|
68
|
+
if (hook.enabled === false) {
|
|
69
|
+
result.delete(name);
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
result.set(name, {
|
|
73
|
+
name,
|
|
74
|
+
item: hook,
|
|
75
|
+
layer,
|
|
76
|
+
path: getHooksYamlPath(dir),
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return Array.from(result.values()).sort((a, b) => a.name.localeCompare(b.name));
|
|
81
|
+
},
|
|
82
|
+
/**
|
|
83
|
+
* Resolve a single hook by name.
|
|
84
|
+
* Returns the winning layer's version, or null if not found.
|
|
85
|
+
*/
|
|
86
|
+
resolve(agent, name, cwd) {
|
|
87
|
+
const layers = getLayerDirs(cwd);
|
|
88
|
+
// Check in reverse precedence order: project first (highest), then user, then system
|
|
89
|
+
const layerOrder = [
|
|
90
|
+
{ layer: 'project', dir: layers.project },
|
|
91
|
+
{ layer: 'user', dir: layers.user },
|
|
92
|
+
{ layer: 'system', dir: layers.system },
|
|
93
|
+
];
|
|
94
|
+
for (const { layer, dir } of layerOrder) {
|
|
95
|
+
if (!dir)
|
|
96
|
+
continue;
|
|
97
|
+
const hooks = parseHooksYaml(dir);
|
|
98
|
+
const hook = hooks[name];
|
|
99
|
+
if (hook) {
|
|
100
|
+
// If this layer disables the hook, return null (disabled trumps lower layers)
|
|
101
|
+
if (hook.enabled === false) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
name,
|
|
106
|
+
item: hook,
|
|
107
|
+
layer,
|
|
108
|
+
path: getHooksYamlPath(dir),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return null;
|
|
113
|
+
},
|
|
114
|
+
/**
|
|
115
|
+
* Sync resolved hooks to the agent's version home directory.
|
|
116
|
+
* Note: Actual hook registration is handled by registerHooksToSettings in hooks.ts.
|
|
117
|
+
* This method is a no-op placeholder for the interface contract.
|
|
118
|
+
*/
|
|
119
|
+
sync(_agent, _versionHome, _cwd) {
|
|
120
|
+
// Hook syncing is done via registerHooksToSettings in the main hooks.ts module.
|
|
121
|
+
// This handler only provides resolution; registration is a separate concern.
|
|
122
|
+
},
|
|
123
|
+
/**
|
|
124
|
+
* Hooks use YAML format across all agents.
|
|
125
|
+
*/
|
|
126
|
+
format(_agent) {
|
|
127
|
+
return 'yaml';
|
|
128
|
+
},
|
|
129
|
+
/**
|
|
130
|
+
* Hooks are stored in the hooks directory.
|
|
131
|
+
*/
|
|
132
|
+
targetDir(_agent) {
|
|
133
|
+
return 'hooks';
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
export default HooksHandler;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified resource system - exports all handlers and provides a registry.
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* import { handlers, getHandler } from './resources/index.js';
|
|
6
|
+
* const cmds = handlers.commands.listAll('claude');
|
|
7
|
+
*/
|
|
8
|
+
export * from './types.js';
|
|
9
|
+
export { CommandsHandler, commandsHandler, type CommandItem } from './commands.js';
|
|
10
|
+
export { HooksHandler, type HookItem } from './hooks.js';
|
|
11
|
+
export { SkillsHandler, type SkillItem } from './skills.js';
|
|
12
|
+
export { RulesHandler, type RuleItem } from './rules.js';
|
|
13
|
+
export { McpHandler, getMcpConfigPath, type McpItem } from './mcp.js';
|
|
14
|
+
export { PermissionsHandler, type PermissionItem } from './permissions.js';
|
|
15
|
+
export { SubagentsHandler, subagentsHandler, type SubagentItem } from './subagents.js';
|
|
16
|
+
import type { ResourceKind, ResourceHandler } from './types.js';
|
|
17
|
+
/** All resource handlers keyed by kind. */
|
|
18
|
+
export declare const handlers: {
|
|
19
|
+
readonly command: import("./commands.js").CommandsHandler;
|
|
20
|
+
readonly commands: import("./commands.js").CommandsHandler;
|
|
21
|
+
readonly hook: ResourceHandler<import("../types.js").ManifestHook>;
|
|
22
|
+
readonly hooks: ResourceHandler<import("../types.js").ManifestHook>;
|
|
23
|
+
readonly skill: ResourceHandler<import("./skills.js").SkillItem>;
|
|
24
|
+
readonly skills: ResourceHandler<import("./skills.js").SkillItem>;
|
|
25
|
+
readonly rule: ResourceHandler<import("./rules.js").RuleItem>;
|
|
26
|
+
readonly rules: ResourceHandler<import("./rules.js").RuleItem>;
|
|
27
|
+
readonly mcp: ResourceHandler<import("./mcp.js").McpItem>;
|
|
28
|
+
readonly permission: ResourceHandler<import("../types.js").PermissionSet>;
|
|
29
|
+
readonly permissions: ResourceHandler<import("../types.js").PermissionSet>;
|
|
30
|
+
readonly subagent: import("./subagents.js").SubagentsHandler;
|
|
31
|
+
readonly subagents: import("./subagents.js").SubagentsHandler;
|
|
32
|
+
};
|
|
33
|
+
/** Get a handler by resource kind. */
|
|
34
|
+
export declare function getHandler(kind: ResourceKind): ResourceHandler<unknown> | null;
|
|
35
|
+
/** All resource kinds. */
|
|
36
|
+
export declare const RESOURCE_KINDS: ResourceKind[];
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified resource system - exports all handlers and provides a registry.
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* import { handlers, getHandler } from './resources/index.js';
|
|
6
|
+
* const cmds = handlers.commands.listAll('claude');
|
|
7
|
+
*/
|
|
8
|
+
export * from './types.js';
|
|
9
|
+
export { CommandsHandler, commandsHandler } from './commands.js';
|
|
10
|
+
export { HooksHandler } from './hooks.js';
|
|
11
|
+
export { SkillsHandler } from './skills.js';
|
|
12
|
+
export { RulesHandler } from './rules.js';
|
|
13
|
+
export { McpHandler, getMcpConfigPath } from './mcp.js';
|
|
14
|
+
export { PermissionsHandler } from './permissions.js';
|
|
15
|
+
export { SubagentsHandler, subagentsHandler } from './subagents.js';
|
|
16
|
+
import { commandsHandler } from './commands.js';
|
|
17
|
+
import { HooksHandler } from './hooks.js';
|
|
18
|
+
import { SkillsHandler } from './skills.js';
|
|
19
|
+
import { RulesHandler } from './rules.js';
|
|
20
|
+
import { McpHandler } from './mcp.js';
|
|
21
|
+
import { PermissionsHandler } from './permissions.js';
|
|
22
|
+
import { subagentsHandler } from './subagents.js';
|
|
23
|
+
/** All resource handlers keyed by kind. */
|
|
24
|
+
export const handlers = {
|
|
25
|
+
command: commandsHandler,
|
|
26
|
+
commands: commandsHandler,
|
|
27
|
+
hook: HooksHandler,
|
|
28
|
+
hooks: HooksHandler,
|
|
29
|
+
skill: SkillsHandler,
|
|
30
|
+
skills: SkillsHandler,
|
|
31
|
+
rule: RulesHandler,
|
|
32
|
+
rules: RulesHandler,
|
|
33
|
+
mcp: McpHandler,
|
|
34
|
+
permission: PermissionsHandler,
|
|
35
|
+
permissions: PermissionsHandler,
|
|
36
|
+
subagent: subagentsHandler,
|
|
37
|
+
subagents: subagentsHandler,
|
|
38
|
+
};
|
|
39
|
+
/** Get a handler by resource kind. */
|
|
40
|
+
export function getHandler(kind) {
|
|
41
|
+
switch (kind) {
|
|
42
|
+
case 'command':
|
|
43
|
+
return commandsHandler;
|
|
44
|
+
case 'hook':
|
|
45
|
+
return HooksHandler;
|
|
46
|
+
case 'skill':
|
|
47
|
+
return SkillsHandler;
|
|
48
|
+
case 'rule':
|
|
49
|
+
return RulesHandler;
|
|
50
|
+
case 'mcp':
|
|
51
|
+
return McpHandler;
|
|
52
|
+
case 'permission':
|
|
53
|
+
return PermissionsHandler;
|
|
54
|
+
case 'subagent':
|
|
55
|
+
return subagentsHandler;
|
|
56
|
+
default:
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** All resource kinds. */
|
|
61
|
+
export const RESOURCE_KINDS = [
|
|
62
|
+
'command',
|
|
63
|
+
'hook',
|
|
64
|
+
'skill',
|
|
65
|
+
'rule',
|
|
66
|
+
'mcp',
|
|
67
|
+
'permission',
|
|
68
|
+
'subagent',
|
|
69
|
+
];
|