@phnx-labs/agents-cli 1.14.3 → 1.14.5

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 (39) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/browser.d.ts +2 -0
  3. package/dist/browser.js +7 -0
  4. package/dist/commands/browser.d.ts +1 -0
  5. package/dist/commands/browser.js +4 -0
  6. package/dist/commands/teams.js +25 -3
  7. package/dist/commands/view.js +1 -1
  8. package/dist/index.js +0 -0
  9. package/dist/lib/browser/chrome.d.ts +2 -2
  10. package/dist/lib/browser/chrome.js +15 -3
  11. package/dist/lib/browser/drivers/local.js +1 -1
  12. package/dist/lib/browser/drivers/ssh.js +14 -5
  13. package/dist/lib/browser/service.js +24 -3
  14. package/dist/lib/browser/types.d.ts +3 -1
  15. package/dist/lib/migrate.js +46 -0
  16. package/dist/lib/resources/commands.d.ts +46 -0
  17. package/dist/lib/resources/commands.js +208 -0
  18. package/dist/lib/resources/hooks.d.ts +12 -0
  19. package/dist/lib/resources/hooks.js +136 -0
  20. package/dist/lib/resources/index.d.ts +36 -0
  21. package/dist/lib/resources/index.js +69 -0
  22. package/dist/lib/resources/mcp.d.ts +34 -0
  23. package/dist/lib/resources/mcp.js +483 -0
  24. package/dist/lib/resources/permissions.d.ts +13 -0
  25. package/dist/lib/resources/permissions.js +184 -0
  26. package/dist/lib/resources/rules.d.ts +43 -0
  27. package/dist/lib/resources/rules.js +146 -0
  28. package/dist/lib/resources/skills.d.ts +37 -0
  29. package/dist/lib/resources/skills.js +238 -0
  30. package/dist/lib/resources/subagents.d.ts +46 -0
  31. package/dist/lib/resources/subagents.js +198 -0
  32. package/dist/lib/resources/types.d.ts +82 -0
  33. package/dist/lib/resources/types.js +8 -0
  34. package/dist/lib/state.js +3 -5
  35. package/dist/lib/teams/registry.d.ts +4 -0
  36. package/dist/lib/teams/registry.js +4 -0
  37. package/dist/lib/versions.d.ts +2 -1
  38. package/dist/lib/versions.js +20 -14
  39. package/package.json +3 -2
@@ -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
+ ];
@@ -0,0 +1,34 @@
1
+ /**
2
+ * MCP resource handler - lists, resolves, and syncs MCP server configs across layers.
3
+ *
4
+ * MCP servers are stored as YAML files in mcp/ directories:
5
+ * ~/.agents-system/mcp/ (system)
6
+ * ~/.agents/mcp/ (user)
7
+ * .agents/mcp/ (project)
8
+ *
9
+ * Resolution: project > user > system (higher layer wins on name conflict).
10
+ * Sync writes into agent-specific config files (settings.json, config.toml, etc).
11
+ */
12
+ import type { AgentId, ResourceHandler } from './types.js';
13
+ /**
14
+ * MCP server item as stored in mcp/*.yaml files.
15
+ */
16
+ export interface McpItem {
17
+ name: string;
18
+ transport: 'stdio' | 'http' | 'sse';
19
+ command?: string;
20
+ args?: string[];
21
+ env?: Record<string, string>;
22
+ url?: string;
23
+ headers?: Record<string, string>;
24
+ }
25
+ /**
26
+ * Get the config file path for MCP for a given agent.
27
+ * Different agents use different config formats and locations.
28
+ */
29
+ export declare function getMcpConfigPath(agent: AgentId, versionHome: string): string | null;
30
+ /**
31
+ * MCP resource handler implementing ResourceHandler<McpItem>.
32
+ */
33
+ export declare const McpHandler: ResourceHandler<McpItem>;
34
+ export default McpHandler;