@ai-devkit/agent-manager 0.1.0
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/.eslintrc.json +31 -0
- package/dist/AgentManager.d.ts +104 -0
- package/dist/AgentManager.d.ts.map +1 -0
- package/dist/AgentManager.js +185 -0
- package/dist/AgentManager.js.map +1 -0
- package/dist/adapters/AgentAdapter.d.ts +76 -0
- package/dist/adapters/AgentAdapter.d.ts.map +1 -0
- package/dist/adapters/AgentAdapter.js +20 -0
- package/dist/adapters/AgentAdapter.js.map +1 -0
- package/dist/adapters/ClaudeCodeAdapter.d.ts +58 -0
- package/dist/adapters/ClaudeCodeAdapter.d.ts.map +1 -0
- package/dist/adapters/ClaudeCodeAdapter.js +274 -0
- package/dist/adapters/ClaudeCodeAdapter.js.map +1 -0
- package/dist/adapters/index.d.ts +4 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +8 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/terminal/TerminalFocusManager.d.ts +22 -0
- package/dist/terminal/TerminalFocusManager.d.ts.map +1 -0
- package/dist/terminal/TerminalFocusManager.js +196 -0
- package/dist/terminal/TerminalFocusManager.js.map +1 -0
- package/dist/terminal/index.d.ts +3 -0
- package/dist/terminal/index.d.ts.map +1 -0
- package/dist/terminal/index.js +6 -0
- package/dist/terminal/index.js.map +1 -0
- package/dist/utils/file.d.ts +52 -0
- package/dist/utils/file.d.ts.map +1 -0
- package/dist/utils/file.js +135 -0
- package/dist/utils/file.js.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +15 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/process.d.ts +61 -0
- package/dist/utils/process.d.ts.map +1 -0
- package/dist/utils/process.js +166 -0
- package/dist/utils/process.js.map +1 -0
- package/jest.config.js +21 -0
- package/package.json +42 -0
- package/project.json +29 -0
- package/src/AgentManager.ts +198 -0
- package/src/__tests__/AgentManager.test.ts +308 -0
- package/src/__tests__/adapters/ClaudeCodeAdapter.test.ts +286 -0
- package/src/adapters/AgentAdapter.ts +94 -0
- package/src/adapters/ClaudeCodeAdapter.ts +344 -0
- package/src/adapters/index.ts +3 -0
- package/src/index.ts +12 -0
- package/src/terminal/TerminalFocusManager.ts +206 -0
- package/src/terminal/index.ts +2 -0
- package/src/utils/file.ts +100 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/process.ts +184 -0
- package/tsconfig.json +17 -0
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"parser": "@typescript-eslint/parser",
|
|
3
|
+
"extends": [
|
|
4
|
+
"eslint:recommended",
|
|
5
|
+
"plugin:@typescript-eslint/recommended"
|
|
6
|
+
],
|
|
7
|
+
"plugins": ["@typescript-eslint"],
|
|
8
|
+
"parserOptions": {
|
|
9
|
+
"ecmaVersion": 2020,
|
|
10
|
+
"sourceType": "module"
|
|
11
|
+
},
|
|
12
|
+
"env": {
|
|
13
|
+
"node": true,
|
|
14
|
+
"es6": true,
|
|
15
|
+
"jest": true
|
|
16
|
+
},
|
|
17
|
+
"rules": {
|
|
18
|
+
"@typescript-eslint/no-explicit-any": "warn",
|
|
19
|
+
"@typescript-eslint/explicit-function-return-type": "off",
|
|
20
|
+
"@typescript-eslint/no-var-requires": "error"
|
|
21
|
+
},
|
|
22
|
+
"overrides": [
|
|
23
|
+
{
|
|
24
|
+
"files": ["**/__tests__/**/*.ts", "**/*.test.ts", "**/*.spec.ts"],
|
|
25
|
+
"rules": {
|
|
26
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
27
|
+
"@typescript-eslint/no-var-requires": "off"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Manager
|
|
3
|
+
*
|
|
4
|
+
* Orchestrates agent detection across multiple adapter types.
|
|
5
|
+
* Manages adapter registration and aggregates results from all adapters.
|
|
6
|
+
*/
|
|
7
|
+
import type { AgentAdapter, AgentInfo } from './adapters/AgentAdapter';
|
|
8
|
+
/**
|
|
9
|
+
* Agent Manager Class
|
|
10
|
+
*
|
|
11
|
+
* Central manager for detecting AI agents across different types.
|
|
12
|
+
* Supports multiple adapters (Claude Code, Gemini CLI, etc.)
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const manager = new AgentManager();
|
|
17
|
+
* manager.registerAdapter(new ClaudeCodeAdapter());
|
|
18
|
+
*
|
|
19
|
+
* const agents = await manager.listAgents();
|
|
20
|
+
* console.log(`Found ${agents.length} agents`);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare class AgentManager {
|
|
24
|
+
private adapters;
|
|
25
|
+
/**
|
|
26
|
+
* Register an adapter for a specific agent type
|
|
27
|
+
*
|
|
28
|
+
* @param adapter Agent adapter to register
|
|
29
|
+
* @throws Error if an adapter for this type is already registered
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* manager.registerAdapter(new ClaudeCodeAdapter());
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
registerAdapter(adapter: AgentAdapter): void;
|
|
37
|
+
/**
|
|
38
|
+
* Unregister an adapter by type
|
|
39
|
+
*
|
|
40
|
+
* @param type Agent type to unregister
|
|
41
|
+
* @returns True if adapter was removed, false if not found
|
|
42
|
+
*/
|
|
43
|
+
unregisterAdapter(type: string): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Get all registered adapters
|
|
46
|
+
*
|
|
47
|
+
* @returns Array of registered adapters
|
|
48
|
+
*/
|
|
49
|
+
getAdapters(): AgentAdapter[];
|
|
50
|
+
/**
|
|
51
|
+
* Check if an adapter is registered for a specific type
|
|
52
|
+
*
|
|
53
|
+
* @param type Agent type to check
|
|
54
|
+
* @returns True if adapter is registered
|
|
55
|
+
*/
|
|
56
|
+
hasAdapter(type: string): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* List all running AI agents detected by registered adapters
|
|
59
|
+
*
|
|
60
|
+
* Queries all registered adapters and aggregates results.
|
|
61
|
+
* Handles errors gracefully - if one adapter fails, others still run.
|
|
62
|
+
*
|
|
63
|
+
* @returns Array of detected agents from all adapters
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const agents = await manager.listAgents();
|
|
68
|
+
*
|
|
69
|
+
* agents.forEach(agent => {
|
|
70
|
+
* console.log(`${agent.name}: ${agent.status}`);
|
|
71
|
+
* });
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
listAgents(): Promise<AgentInfo[]>;
|
|
75
|
+
/**
|
|
76
|
+
* Sort agents by status priority
|
|
77
|
+
*
|
|
78
|
+
* Priority order: waiting > running > idle > unknown
|
|
79
|
+
* This ensures agents that need attention appear first.
|
|
80
|
+
*
|
|
81
|
+
* @param agents Array of agents to sort
|
|
82
|
+
* @returns Sorted array of agents
|
|
83
|
+
*/
|
|
84
|
+
private sortAgentsByStatus;
|
|
85
|
+
/**
|
|
86
|
+
* Get count of registered adapters
|
|
87
|
+
*
|
|
88
|
+
* @returns Number of registered adapters
|
|
89
|
+
*/
|
|
90
|
+
getAdapterCount(): number;
|
|
91
|
+
/**
|
|
92
|
+
* Clear all registered adapters
|
|
93
|
+
*/
|
|
94
|
+
clear(): void;
|
|
95
|
+
/**
|
|
96
|
+
* Resolve an agent by name (exact or partial match)
|
|
97
|
+
*
|
|
98
|
+
* @param input Name to search for
|
|
99
|
+
* @param agents List of agents to search within
|
|
100
|
+
* @returns Matched agent (unique), array of agents (ambiguous), or null (none)
|
|
101
|
+
*/
|
|
102
|
+
resolveAgent(input: string, agents: AgentInfo[]): AgentInfo | AgentInfo[] | null;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=AgentManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentManager.d.ts","sourceRoot":"","sources":["../src/AgentManager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAGvE;;;;;;;;;;;;;;GAcG;AACH,qBAAa,YAAY;IACrB,OAAO,CAAC,QAAQ,CAAwC;IAExD;;;;;;;;;;OAUG;IACH,eAAe,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI;IAU5C;;;;;OAKG;IACH,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIxC;;;;OAIG;IACH,WAAW,IAAI,YAAY,EAAE;IAI7B;;;;;OAKG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIjC;;;;;;;;;;;;;;;;OAgBG;IACG,UAAU,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAsCxC;;;;;;;;OAQG;IACH,OAAO,CAAC,kBAAkB;IAe1B;;;;OAIG;IACH,eAAe,IAAI,MAAM;IAIzB;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;;;;;OAMG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,SAAS,GAAG,SAAS,EAAE,GAAG,IAAI;CAiBnF"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Agent Manager
|
|
4
|
+
*
|
|
5
|
+
* Orchestrates agent detection across multiple adapter types.
|
|
6
|
+
* Manages adapter registration and aggregates results from all adapters.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.AgentManager = void 0;
|
|
10
|
+
const AgentAdapter_1 = require("./adapters/AgentAdapter");
|
|
11
|
+
/**
|
|
12
|
+
* Agent Manager Class
|
|
13
|
+
*
|
|
14
|
+
* Central manager for detecting AI agents across different types.
|
|
15
|
+
* Supports multiple adapters (Claude Code, Gemini CLI, etc.)
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const manager = new AgentManager();
|
|
20
|
+
* manager.registerAdapter(new ClaudeCodeAdapter());
|
|
21
|
+
*
|
|
22
|
+
* const agents = await manager.listAgents();
|
|
23
|
+
* console.log(`Found ${agents.length} agents`);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
class AgentManager {
|
|
27
|
+
constructor() {
|
|
28
|
+
this.adapters = new Map();
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Register an adapter for a specific agent type
|
|
32
|
+
*
|
|
33
|
+
* @param adapter Agent adapter to register
|
|
34
|
+
* @throws Error if an adapter for this type is already registered
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* manager.registerAdapter(new ClaudeCodeAdapter());
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
registerAdapter(adapter) {
|
|
42
|
+
const adapterKey = adapter.type;
|
|
43
|
+
if (this.adapters.has(adapterKey)) {
|
|
44
|
+
throw new Error(`Adapter for type "${adapterKey}" is already registered`);
|
|
45
|
+
}
|
|
46
|
+
this.adapters.set(adapterKey, adapter);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Unregister an adapter by type
|
|
50
|
+
*
|
|
51
|
+
* @param type Agent type to unregister
|
|
52
|
+
* @returns True if adapter was removed, false if not found
|
|
53
|
+
*/
|
|
54
|
+
unregisterAdapter(type) {
|
|
55
|
+
return this.adapters.delete(type);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get all registered adapters
|
|
59
|
+
*
|
|
60
|
+
* @returns Array of registered adapters
|
|
61
|
+
*/
|
|
62
|
+
getAdapters() {
|
|
63
|
+
return Array.from(this.adapters.values());
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Check if an adapter is registered for a specific type
|
|
67
|
+
*
|
|
68
|
+
* @param type Agent type to check
|
|
69
|
+
* @returns True if adapter is registered
|
|
70
|
+
*/
|
|
71
|
+
hasAdapter(type) {
|
|
72
|
+
return this.adapters.has(type);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* List all running AI agents detected by registered adapters
|
|
76
|
+
*
|
|
77
|
+
* Queries all registered adapters and aggregates results.
|
|
78
|
+
* Handles errors gracefully - if one adapter fails, others still run.
|
|
79
|
+
*
|
|
80
|
+
* @returns Array of detected agents from all adapters
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* const agents = await manager.listAgents();
|
|
85
|
+
*
|
|
86
|
+
* agents.forEach(agent => {
|
|
87
|
+
* console.log(`${agent.name}: ${agent.status}`);
|
|
88
|
+
* });
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
async listAgents() {
|
|
92
|
+
const allAgents = [];
|
|
93
|
+
const errors = [];
|
|
94
|
+
// Query all adapters in parallel
|
|
95
|
+
const adapterPromises = Array.from(this.adapters.values()).map(async (adapter) => {
|
|
96
|
+
try {
|
|
97
|
+
const agents = await adapter.detectAgents();
|
|
98
|
+
return { type: adapter.type, agents, error: null };
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
// Capture error but don't throw - allow other adapters to continue
|
|
102
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
103
|
+
errors.push({ type: adapter.type, error: err });
|
|
104
|
+
return { type: adapter.type, agents: [], error: err };
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
const results = await Promise.all(adapterPromises);
|
|
108
|
+
// Aggregate all successful results
|
|
109
|
+
for (const result of results) {
|
|
110
|
+
if (result.error === null) {
|
|
111
|
+
allAgents.push(...result.agents);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// Log errors if any (but don't throw - partial results are useful)
|
|
115
|
+
if (errors.length > 0) {
|
|
116
|
+
console.error(`Warning: ${errors.length} adapter(s) failed:`);
|
|
117
|
+
errors.forEach(({ type, error }) => {
|
|
118
|
+
console.error(` - ${type}: ${error.message}`);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
// Sort by status priority (waiting first, then running, then idle)
|
|
122
|
+
return this.sortAgentsByStatus(allAgents);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Sort agents by status priority
|
|
126
|
+
*
|
|
127
|
+
* Priority order: waiting > running > idle > unknown
|
|
128
|
+
* This ensures agents that need attention appear first.
|
|
129
|
+
*
|
|
130
|
+
* @param agents Array of agents to sort
|
|
131
|
+
* @returns Sorted array of agents
|
|
132
|
+
*/
|
|
133
|
+
sortAgentsByStatus(agents) {
|
|
134
|
+
const statusPriority = {
|
|
135
|
+
[AgentAdapter_1.AgentStatus.WAITING]: 0,
|
|
136
|
+
[AgentAdapter_1.AgentStatus.RUNNING]: 1,
|
|
137
|
+
[AgentAdapter_1.AgentStatus.IDLE]: 2,
|
|
138
|
+
[AgentAdapter_1.AgentStatus.UNKNOWN]: 3,
|
|
139
|
+
};
|
|
140
|
+
return agents.sort((a, b) => {
|
|
141
|
+
const priorityA = statusPriority[a.status] ?? 999;
|
|
142
|
+
const priorityB = statusPriority[b.status] ?? 999;
|
|
143
|
+
return priorityA - priorityB;
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Get count of registered adapters
|
|
148
|
+
*
|
|
149
|
+
* @returns Number of registered adapters
|
|
150
|
+
*/
|
|
151
|
+
getAdapterCount() {
|
|
152
|
+
return this.adapters.size;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Clear all registered adapters
|
|
156
|
+
*/
|
|
157
|
+
clear() {
|
|
158
|
+
this.adapters.clear();
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Resolve an agent by name (exact or partial match)
|
|
162
|
+
*
|
|
163
|
+
* @param input Name to search for
|
|
164
|
+
* @param agents List of agents to search within
|
|
165
|
+
* @returns Matched agent (unique), array of agents (ambiguous), or null (none)
|
|
166
|
+
*/
|
|
167
|
+
resolveAgent(input, agents) {
|
|
168
|
+
if (!input || agents.length === 0)
|
|
169
|
+
return null;
|
|
170
|
+
const lowerInput = input.toLowerCase();
|
|
171
|
+
// 1. Exact match (case-insensitive)
|
|
172
|
+
const exactMatch = agents.find(a => a.name.toLowerCase() === lowerInput);
|
|
173
|
+
if (exactMatch)
|
|
174
|
+
return exactMatch;
|
|
175
|
+
// 2. Partial match (prefix or contains)
|
|
176
|
+
const matches = agents.filter(a => a.name.toLowerCase().includes(lowerInput));
|
|
177
|
+
if (matches.length === 1)
|
|
178
|
+
return matches[0];
|
|
179
|
+
if (matches.length > 1)
|
|
180
|
+
return matches;
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
exports.AgentManager = AgentManager;
|
|
185
|
+
//# sourceMappingURL=AgentManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentManager.js","sourceRoot":"","sources":["../src/AgentManager.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAGH,0DAAsD;AAEtD;;;;;;;;;;;;;;GAcG;AACH,MAAa,YAAY;IAAzB;QACY,aAAQ,GAA8B,IAAI,GAAG,EAAE,CAAC;IA2K5D,CAAC;IAzKG;;;;;;;;;;OAUG;IACH,eAAe,CAAC,OAAqB;QACjC,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;QAEhC,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,qBAAqB,UAAU,yBAAyB,CAAC,CAAC;QAC9E,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,OAAO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,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC;YAClD,OAAO,SAAS,GAAG,SAAS,CAAC;QACjC,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;;;OAIG;IACH,eAAe;QACX,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,KAAK;QACD,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;IAED;;;;;;OAMG;IACH,YAAY,CAAC,KAAa,EAAE,MAAmB;QAC3C,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QAE/C,MAAM,UAAU,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;QAEvC,oCAAoC;QACpC,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,UAAU,CAAC,CAAC;QACzE,IAAI,UAAU;YAAE,OAAO,UAAU,CAAC;QAElC,wCAAwC;QACxC,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC;QAE9E,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;QAC5C,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO,OAAO,CAAC;QAEvC,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AA5KD,oCA4KC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Adapter Interface
|
|
3
|
+
*
|
|
4
|
+
* Defines the contract for detecting and managing different types of AI agents.
|
|
5
|
+
* Each adapter is responsible for detecting agents of a specific type (e.g., claude).
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Type of AI agent
|
|
9
|
+
*/
|
|
10
|
+
export type AgentType = 'claude' | 'gemini_cli' | 'codex' | 'other';
|
|
11
|
+
/**
|
|
12
|
+
* Current status of an agent
|
|
13
|
+
*/
|
|
14
|
+
export declare enum AgentStatus {
|
|
15
|
+
RUNNING = "running",
|
|
16
|
+
WAITING = "waiting",
|
|
17
|
+
IDLE = "idle",
|
|
18
|
+
UNKNOWN = "unknown"
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Information about a detected agent
|
|
22
|
+
*/
|
|
23
|
+
export interface AgentInfo {
|
|
24
|
+
/** Project-based name (e.g., "ai-devkit" or "ai-devkit (merry)") */
|
|
25
|
+
name: string;
|
|
26
|
+
/** Type of agent */
|
|
27
|
+
type: AgentType;
|
|
28
|
+
/** Current status */
|
|
29
|
+
status: AgentStatus;
|
|
30
|
+
/** Last user prompt from history */
|
|
31
|
+
summary: string;
|
|
32
|
+
/** Process ID */
|
|
33
|
+
pid: number;
|
|
34
|
+
/** Working directory/project path */
|
|
35
|
+
projectPath: string;
|
|
36
|
+
/** Session UUID */
|
|
37
|
+
sessionId: string;
|
|
38
|
+
/** Human-readable session name (e.g., "merry-wobbling-starlight"), may be undefined for new sessions */
|
|
39
|
+
slug?: string;
|
|
40
|
+
/** Timestamp of last activity */
|
|
41
|
+
lastActive: Date;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Information about a running process
|
|
45
|
+
*/
|
|
46
|
+
export interface ProcessInfo {
|
|
47
|
+
/** Process ID */
|
|
48
|
+
pid: number;
|
|
49
|
+
/** Process command */
|
|
50
|
+
command: string;
|
|
51
|
+
/** Working directory */
|
|
52
|
+
cwd: string;
|
|
53
|
+
/** Terminal TTY (e.g., "ttys030") */
|
|
54
|
+
tty: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Agent Adapter Interface
|
|
58
|
+
*
|
|
59
|
+
* Implementations must provide detection logic for a specific agent type.
|
|
60
|
+
*/
|
|
61
|
+
export interface AgentAdapter {
|
|
62
|
+
/** Type of agent this adapter handles */
|
|
63
|
+
readonly type: AgentType;
|
|
64
|
+
/**
|
|
65
|
+
* Detect running agents of this type
|
|
66
|
+
* @returns List of detected agents
|
|
67
|
+
*/
|
|
68
|
+
detectAgents(): Promise<AgentInfo[]>;
|
|
69
|
+
/**
|
|
70
|
+
* Check if this adapter can handle the given process
|
|
71
|
+
* @param processInfo Process information
|
|
72
|
+
* @returns True if this adapter can handle the process
|
|
73
|
+
*/
|
|
74
|
+
canHandle(processInfo: ProcessInfo): boolean;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=AgentAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/AgentAdapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,YAAY,GAAG,OAAO,GAAG,OAAO,CAAC;AAEpE;;GAEG;AACH,oBAAY,WAAW;IACnB,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,IAAI,SAAS;IACb,OAAO,YAAY;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACtB,oEAAoE;IACpE,IAAI,EAAE,MAAM,CAAC;IAEb,oBAAoB;IACpB,IAAI,EAAE,SAAS,CAAC;IAEhB,qBAAqB;IACrB,MAAM,EAAE,WAAW,CAAC;IAEpB,oCAAoC;IACpC,OAAO,EAAE,MAAM,CAAC;IAEhB,iBAAiB;IACjB,GAAG,EAAE,MAAM,CAAC;IAEZ,qCAAqC;IACrC,WAAW,EAAE,MAAM,CAAC;IAEpB,mBAAmB;IACnB,SAAS,EAAE,MAAM,CAAC;IAElB,wGAAwG;IACxG,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,iCAAiC;IACjC,UAAU,EAAE,IAAI,CAAC;CAEpB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IACxB,iBAAiB;IACjB,GAAG,EAAE,MAAM,CAAC;IAEZ,sBAAsB;IACtB,OAAO,EAAE,MAAM,CAAC;IAEhB,wBAAwB;IACxB,GAAG,EAAE,MAAM,CAAC;IAEZ,qCAAqC;IACrC,GAAG,EAAE,MAAM,CAAC;CACf;AAED;;;;GAIG;AACH,MAAM,WAAW,YAAY;IACzB,yCAAyC;IACzC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAEzB;;;OAGG;IACH,YAAY,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;IAErC;;;;OAIG;IACH,SAAS,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC;CAChD"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Agent Adapter Interface
|
|
4
|
+
*
|
|
5
|
+
* Defines the contract for detecting and managing different types of AI agents.
|
|
6
|
+
* Each adapter is responsible for detecting agents of a specific type (e.g., claude).
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.AgentStatus = void 0;
|
|
10
|
+
/**
|
|
11
|
+
* Current status of an agent
|
|
12
|
+
*/
|
|
13
|
+
var AgentStatus;
|
|
14
|
+
(function (AgentStatus) {
|
|
15
|
+
AgentStatus["RUNNING"] = "running";
|
|
16
|
+
AgentStatus["WAITING"] = "waiting";
|
|
17
|
+
AgentStatus["IDLE"] = "idle";
|
|
18
|
+
AgentStatus["UNKNOWN"] = "unknown";
|
|
19
|
+
})(AgentStatus || (exports.AgentStatus = AgentStatus = {}));
|
|
20
|
+
//# sourceMappingURL=AgentAdapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentAdapter.js","sourceRoot":"","sources":["../../src/adapters/AgentAdapter.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAOH;;GAEG;AACH,IAAY,WAKX;AALD,WAAY,WAAW;IACnB,kCAAmB,CAAA;IACnB,kCAAmB,CAAA;IACnB,4BAAa,CAAA;IACb,kCAAmB,CAAA;AACvB,CAAC,EALW,WAAW,2BAAX,WAAW,QAKtB"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Code Adapter
|
|
3
|
+
*
|
|
4
|
+
* Detects running Claude Code agents by reading session files
|
|
5
|
+
* from ~/.claude/ directory and correlating with running processes.
|
|
6
|
+
*/
|
|
7
|
+
import type { AgentAdapter, AgentInfo, ProcessInfo } from './AgentAdapter';
|
|
8
|
+
/**
|
|
9
|
+
* Claude Code Adapter
|
|
10
|
+
*
|
|
11
|
+
* Detects Claude Code agents by:
|
|
12
|
+
* 1. Finding running claude processes
|
|
13
|
+
* 2. Reading session files from ~/.claude/projects/
|
|
14
|
+
* 3. Matching sessions to processes via CWD
|
|
15
|
+
* 4. Extracting status from session JSONL
|
|
16
|
+
* 5. Extracting summary from history.jsonl
|
|
17
|
+
*/
|
|
18
|
+
export declare class ClaudeCodeAdapter implements AgentAdapter {
|
|
19
|
+
readonly type: "claude";
|
|
20
|
+
/** Threshold in minutes before considering a session idle */
|
|
21
|
+
private static readonly IDLE_THRESHOLD_MINUTES;
|
|
22
|
+
private claudeDir;
|
|
23
|
+
private projectsDir;
|
|
24
|
+
private historyPath;
|
|
25
|
+
constructor();
|
|
26
|
+
/**
|
|
27
|
+
* Check if this adapter can handle a given process
|
|
28
|
+
*/
|
|
29
|
+
canHandle(processInfo: ProcessInfo): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Detect running Claude Code agents
|
|
32
|
+
*/
|
|
33
|
+
detectAgents(): Promise<AgentInfo[]>;
|
|
34
|
+
/**
|
|
35
|
+
* Read all Claude Code sessions
|
|
36
|
+
*/
|
|
37
|
+
private readSessions;
|
|
38
|
+
/**
|
|
39
|
+
* Read a session JSONL file
|
|
40
|
+
* Only reads last 100 lines for performance with large files
|
|
41
|
+
*/
|
|
42
|
+
private readSessionLog;
|
|
43
|
+
/**
|
|
44
|
+
* Read history.jsonl for user prompts
|
|
45
|
+
* Only reads last 100 lines for performance
|
|
46
|
+
*/
|
|
47
|
+
private readHistory;
|
|
48
|
+
/**
|
|
49
|
+
* Determine agent status from session entry
|
|
50
|
+
*/
|
|
51
|
+
private determineStatus;
|
|
52
|
+
/**
|
|
53
|
+
* Generate unique agent name
|
|
54
|
+
* Uses project basename, appends slug if multiple sessions for same project
|
|
55
|
+
*/
|
|
56
|
+
private generateAgentName;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=ClaudeCodeAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClaudeCodeAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/ClaudeCodeAdapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAqD3E;;;;;;;;;GASG;AACH,qBAAa,iBAAkB,YAAW,YAAY;IAClD,QAAQ,CAAC,IAAI,EAAG,QAAQ,CAAU;IAElC,6DAA6D;IAC7D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,sBAAsB,CAAK;IAEnD,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,WAAW,CAAS;;IAS5B;;OAEG;IACH,SAAS,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO;IAI5C;;OAEG;IACG,YAAY,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAwE1C;;OAEG;IACH,OAAO,CAAC,YAAY;IAyDpB;;;OAGG;IACH,OAAO,CAAC,cAAc;IAgCtB;;;OAGG;IACH,OAAO,CAAC,WAAW;IAInB;;OAEG;IACH,OAAO,CAAC,eAAe;IAqCvB;;;OAGG;IACH,OAAO,CAAC,iBAAiB;CAwB5B"}
|