@ai-devkit/agent-manager 0.4.0 → 0.6.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/dist/adapters/AgentAdapter.d.ts +21 -2
- package/dist/adapters/AgentAdapter.d.ts.map +1 -1
- package/dist/adapters/ClaudeCodeAdapter.d.ts +44 -35
- package/dist/adapters/ClaudeCodeAdapter.d.ts.map +1 -1
- package/dist/adapters/ClaudeCodeAdapter.js +230 -298
- package/dist/adapters/ClaudeCodeAdapter.js.map +1 -1
- package/dist/adapters/CodexAdapter.d.ts +41 -31
- package/dist/adapters/CodexAdapter.d.ts.map +1 -1
- package/dist/adapters/CodexAdapter.js +198 -278
- package/dist/adapters/CodexAdapter.js.map +1 -1
- package/dist/index.d.ts +2 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -10
- package/dist/index.js.map +1 -1
- package/dist/utils/index.d.ts +6 -3
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +12 -11
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/matching.d.ts +39 -0
- package/dist/utils/matching.d.ts.map +1 -0
- package/dist/utils/matching.js +107 -0
- package/dist/utils/matching.js.map +1 -0
- package/dist/utils/process.d.ts +25 -40
- package/dist/utils/process.d.ts.map +1 -1
- package/dist/utils/process.js +151 -105
- package/dist/utils/process.js.map +1 -1
- package/dist/utils/session.d.ts +30 -0
- package/dist/utils/session.d.ts.map +1 -0
- package/dist/utils/session.js +101 -0
- package/dist/utils/session.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/AgentManager.test.ts +5 -27
- package/src/__tests__/adapters/ClaudeCodeAdapter.test.ts +754 -830
- package/src/__tests__/adapters/CodexAdapter.test.ts +581 -273
- package/src/__tests__/utils/matching.test.ts +199 -0
- package/src/__tests__/utils/process.test.ts +202 -0
- package/src/__tests__/utils/session.test.ts +117 -0
- package/src/adapters/AgentAdapter.ts +23 -4
- package/src/adapters/ClaudeCodeAdapter.ts +285 -437
- package/src/adapters/CodexAdapter.ts +202 -400
- package/src/index.ts +2 -4
- package/src/utils/index.ts +6 -3
- package/src/utils/matching.ts +96 -0
- package/src/utils/process.ts +133 -119
- package/src/utils/session.ts +92 -0
- package/dist/utils/file.d.ts +0 -52
- package/dist/utils/file.d.ts.map +0 -1
- package/dist/utils/file.js +0 -135
- package/dist/utils/file.js.map +0 -1
- package/src/utils/file.ts +0 -100
package/dist/utils/process.js
CHANGED
|
@@ -2,165 +2,211 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Process Detection Utilities
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* Shared shell command wrappers for detecting and inspecting running processes.
|
|
6
|
+
* All execSync calls for process data live here — adapters must not call execSync directly.
|
|
7
7
|
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
8
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
10
|
-
exports.
|
|
42
|
+
exports.listAgentProcesses = listAgentProcesses;
|
|
43
|
+
exports.batchGetProcessCwds = batchGetProcessCwds;
|
|
44
|
+
exports.batchGetProcessStartTimes = batchGetProcessStartTimes;
|
|
45
|
+
exports.enrichProcesses = enrichProcesses;
|
|
11
46
|
exports.getProcessTty = getProcessTty;
|
|
12
|
-
|
|
13
|
-
exports.getProcessInfo = getProcessInfo;
|
|
47
|
+
const path = __importStar(require("path"));
|
|
14
48
|
const child_process_1 = require("child_process");
|
|
15
49
|
/**
|
|
16
|
-
* List running processes
|
|
17
|
-
*
|
|
18
|
-
* @param options Filtering options
|
|
19
|
-
* @returns Array of process information
|
|
50
|
+
* List running processes matching an agent executable name.
|
|
20
51
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* const processes = listProcesses({ namePattern: 'claude' });
|
|
52
|
+
* Uses `ps aux | grep <pattern>` at shell level for performance, then post-filters
|
|
53
|
+
* by checking that the executable basename matches exactly (avoids matching
|
|
54
|
+
* `claude-helper`, `vscode-claude-extension`, or the grep process itself).
|
|
25
55
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* ```
|
|
56
|
+
* Returned ProcessInfo has pid, command, tty populated.
|
|
57
|
+
* cwd and startTime are NOT populated — call enrichProcesses() to fill them.
|
|
29
58
|
*/
|
|
30
|
-
function
|
|
59
|
+
function listAgentProcesses(namePattern) {
|
|
60
|
+
// Validate pattern contains only safe characters (alphanumeric, dash, underscore)
|
|
61
|
+
if (!namePattern || !/^[a-zA-Z0-9_-]+$/.test(namePattern)) {
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
31
64
|
try {
|
|
32
|
-
//
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
const lines = psOutput.trim().split('\n');
|
|
36
|
-
// Skip header line
|
|
37
|
-
const processLines = lines.slice(1);
|
|
65
|
+
// Use [c]laude trick to avoid matching the grep process itself
|
|
66
|
+
const escapedPattern = `[${namePattern[0]}]${namePattern.slice(1)}`;
|
|
67
|
+
const output = (0, child_process_1.execSync)(`ps aux | grep -i '${escapedPattern}'`, { encoding: 'utf-8' });
|
|
38
68
|
const processes = [];
|
|
39
|
-
for (const line of
|
|
40
|
-
|
|
41
|
-
|
|
69
|
+
for (const line of output.trim().split('\n')) {
|
|
70
|
+
if (!line.trim())
|
|
71
|
+
continue;
|
|
42
72
|
const parts = line.trim().split(/\s+/);
|
|
43
73
|
if (parts.length < 11)
|
|
44
74
|
continue;
|
|
45
75
|
const pid = parseInt(parts[1], 10);
|
|
46
|
-
if (isNaN(pid))
|
|
76
|
+
if (Number.isNaN(pid))
|
|
47
77
|
continue;
|
|
48
78
|
const tty = parts[6];
|
|
49
79
|
const command = parts.slice(10).join(' ');
|
|
50
|
-
//
|
|
51
|
-
|
|
80
|
+
// Post-filter: check that the executable basename matches exactly
|
|
81
|
+
const executable = command.trim().split(/\s+/)[0] || '';
|
|
82
|
+
const base = path.basename(executable).toLowerCase();
|
|
83
|
+
if (base !== namePattern.toLowerCase() && base !== `${namePattern.toLowerCase()}.exe`) {
|
|
52
84
|
continue;
|
|
53
85
|
}
|
|
54
|
-
// Apply name pattern filter (case-insensitive)
|
|
55
|
-
if (options.namePattern) {
|
|
56
|
-
const pattern = options.namePattern.toLowerCase();
|
|
57
|
-
const commandLower = command.toLowerCase();
|
|
58
|
-
if (!commandLower.includes(pattern)) {
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
// Get working directory for this process
|
|
63
|
-
const cwd = getProcessCwd(pid);
|
|
64
|
-
// Get TTY in short format (remove /dev/ prefix if present)
|
|
65
86
|
const ttyShort = tty.startsWith('/dev/') ? tty.slice(5) : tty;
|
|
66
87
|
processes.push({
|
|
67
88
|
pid,
|
|
68
89
|
command,
|
|
69
|
-
cwd,
|
|
90
|
+
cwd: '',
|
|
70
91
|
tty: ttyShort,
|
|
71
92
|
});
|
|
72
93
|
}
|
|
73
94
|
return processes;
|
|
74
95
|
}
|
|
75
|
-
catch
|
|
76
|
-
// If ps command fails, return empty array
|
|
77
|
-
console.error('Failed to list processes:', error);
|
|
96
|
+
catch {
|
|
78
97
|
return [];
|
|
79
98
|
}
|
|
80
99
|
}
|
|
81
100
|
/**
|
|
82
|
-
*
|
|
101
|
+
* Batch-get current working directories for multiple PIDs.
|
|
83
102
|
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
103
|
+
* Single `lsof -a -d cwd -Fn -p PID1,PID2,...` call.
|
|
104
|
+
* Returns partial results — if lsof fails for one PID, others still return.
|
|
86
105
|
*/
|
|
87
|
-
function
|
|
106
|
+
function batchGetProcessCwds(pids) {
|
|
107
|
+
const result = new Map();
|
|
108
|
+
if (pids.length === 0)
|
|
109
|
+
return result;
|
|
88
110
|
try {
|
|
89
|
-
|
|
90
|
-
//
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return line.slice(1); // Remove 'n' prefix
|
|
111
|
+
const output = (0, child_process_1.execSync)(`lsof -a -d cwd -Fn -p ${pids.join(',')} 2>/dev/null`, { encoding: 'utf-8' });
|
|
112
|
+
// lsof output format: p{PID}\nn{path}\np{PID}\nn{path}...
|
|
113
|
+
let currentPid = null;
|
|
114
|
+
for (const line of output.trim().split('\n')) {
|
|
115
|
+
if (line.startsWith('p')) {
|
|
116
|
+
currentPid = parseInt(line.slice(1), 10);
|
|
117
|
+
}
|
|
118
|
+
else if (line.startsWith('n') && currentPid !== null) {
|
|
119
|
+
result.set(currentPid, line.slice(1));
|
|
120
|
+
currentPid = null;
|
|
100
121
|
}
|
|
101
122
|
}
|
|
102
|
-
return '';
|
|
103
123
|
}
|
|
104
|
-
catch
|
|
105
|
-
//
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
encoding: 'utf-8'
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
124
|
+
catch {
|
|
125
|
+
// Try per-PID fallback with pwdx (Linux)
|
|
126
|
+
for (const pid of pids) {
|
|
127
|
+
try {
|
|
128
|
+
const output = (0, child_process_1.execSync)(`pwdx ${pid} 2>/dev/null`, { encoding: 'utf-8' });
|
|
129
|
+
const match = output.match(/^\d+:\s*(.+)$/);
|
|
130
|
+
if (match) {
|
|
131
|
+
result.set(pid, match[1].trim());
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
// Skip this PID
|
|
136
|
+
}
|
|
117
137
|
}
|
|
118
138
|
}
|
|
139
|
+
return result;
|
|
119
140
|
}
|
|
120
141
|
/**
|
|
121
|
-
*
|
|
142
|
+
* Batch-get process start times for multiple PIDs.
|
|
122
143
|
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
144
|
+
* Single `ps -o pid=,lstart= -p PID1,PID2,...` call.
|
|
145
|
+
* Uses lstart format which gives full timestamp (e.g., "Thu Feb 5 16:00:57 2026").
|
|
146
|
+
* Returns partial results.
|
|
125
147
|
*/
|
|
126
|
-
function
|
|
148
|
+
function batchGetProcessStartTimes(pids) {
|
|
149
|
+
const result = new Map();
|
|
150
|
+
if (pids.length === 0)
|
|
151
|
+
return result;
|
|
127
152
|
try {
|
|
128
|
-
const output = (0, child_process_1.execSync)(`ps -p ${
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
153
|
+
const output = (0, child_process_1.execSync)(`ps -o pid=,lstart= -p ${pids.join(',')}`, { encoding: 'utf-8' });
|
|
154
|
+
for (const rawLine of output.split('\n')) {
|
|
155
|
+
const line = rawLine.trim();
|
|
156
|
+
if (!line)
|
|
157
|
+
continue;
|
|
158
|
+
// Format: " PID DAY MON DD HH:MM:SS YYYY"
|
|
159
|
+
// e.g., " 78070 Wed Mar 18 23:18:01 2026"
|
|
160
|
+
const match = line.match(/^\s*(\d+)\s+(.+)$/);
|
|
161
|
+
if (!match)
|
|
162
|
+
continue;
|
|
163
|
+
const pid = parseInt(match[1], 10);
|
|
164
|
+
const dateStr = match[2].trim();
|
|
165
|
+
if (!Number.isFinite(pid))
|
|
166
|
+
continue;
|
|
167
|
+
const date = new Date(dateStr);
|
|
168
|
+
if (!Number.isNaN(date.getTime())) {
|
|
169
|
+
result.set(pid, date);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
134
172
|
}
|
|
135
|
-
catch
|
|
136
|
-
|
|
173
|
+
catch {
|
|
174
|
+
// Return whatever we have
|
|
137
175
|
}
|
|
176
|
+
return result;
|
|
138
177
|
}
|
|
139
178
|
/**
|
|
140
|
-
*
|
|
179
|
+
* Enrich ProcessInfo array with cwd and startTime.
|
|
141
180
|
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
181
|
+
* Calls batchGetProcessCwds and batchGetProcessStartTimes in batched shell calls,
|
|
182
|
+
* then populates each ProcessInfo in-place. Returns partial results —
|
|
183
|
+
* if a PID fails, that process keeps empty cwd / undefined startTime.
|
|
144
184
|
*/
|
|
145
|
-
function
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
185
|
+
function enrichProcesses(processes) {
|
|
186
|
+
if (processes.length === 0)
|
|
187
|
+
return processes;
|
|
188
|
+
const pids = processes.map(p => p.pid);
|
|
189
|
+
const cwdMap = batchGetProcessCwds(pids);
|
|
190
|
+
const startTimeMap = batchGetProcessStartTimes(pids);
|
|
191
|
+
for (const proc of processes) {
|
|
192
|
+
proc.cwd = cwdMap.get(proc.pid) || '';
|
|
193
|
+
proc.startTime = startTimeMap.get(proc.pid);
|
|
154
194
|
}
|
|
195
|
+
return processes;
|
|
155
196
|
}
|
|
156
197
|
/**
|
|
157
|
-
* Get
|
|
158
|
-
*
|
|
159
|
-
* @param pid Process ID
|
|
160
|
-
* @returns Process information, or null if process not found
|
|
198
|
+
* Get the TTY device for a specific process
|
|
161
199
|
*/
|
|
162
|
-
function
|
|
163
|
-
|
|
164
|
-
|
|
200
|
+
function getProcessTty(pid) {
|
|
201
|
+
try {
|
|
202
|
+
const output = (0, child_process_1.execSync)(`ps -p ${pid} -o tty=`, {
|
|
203
|
+
encoding: 'utf-8',
|
|
204
|
+
});
|
|
205
|
+
const tty = output.trim();
|
|
206
|
+
return tty.startsWith('/dev/') ? tty.slice(5) : tty;
|
|
207
|
+
}
|
|
208
|
+
catch {
|
|
209
|
+
return '?';
|
|
210
|
+
}
|
|
165
211
|
}
|
|
166
212
|
//# sourceMappingURL=process.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process.js","sourceRoot":"","sources":["../../src/utils/process.ts"],"names":[],"mappings":";AAAA;;;;;GAKG
|
|
1
|
+
{"version":3,"file":"process.js","sourceRoot":"","sources":["../../src/utils/process.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBH,gDAkDC;AAQD,kDAoCC;AASD,8DAkCC;AASD,0CAaC;AAKD,sCAWC;AA7LD,2CAA6B;AAC7B,iDAAyC;AAGzC;;;;;;;;;GASG;AACH,SAAgB,kBAAkB,CAAC,WAAmB;IAClD,kFAAkF;IAClF,IAAI,CAAC,WAAW,IAAI,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G;AACH,SAAgB,aAAa,CAAC,GAAW;IACrC,IAAI,CAAC;QACD,MAAM,MAAM,GAAG,IAAA,wBAAQ,EAAC,SAAS,GAAG,UAAU,EAAE;YAC5C,QAAQ,EAAE,OAAO;SACpB,CAAC,CAAC;QAEH,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;QAC1B,OAAO,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IACxD,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,GAAG,CAAC;IACf,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session File Utilities
|
|
3
|
+
*
|
|
4
|
+
* Shell command wrappers for discovering session files and their birth times.
|
|
5
|
+
* Uses `stat` to get exact epoch-second birth timestamps without reading file contents.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Represents a session file with its birth time metadata.
|
|
9
|
+
*/
|
|
10
|
+
export interface SessionFile {
|
|
11
|
+
/** Session identifier (filename without .jsonl extension) */
|
|
12
|
+
sessionId: string;
|
|
13
|
+
/** Full path to the session file */
|
|
14
|
+
filePath: string;
|
|
15
|
+
/** Parent directory of the session file */
|
|
16
|
+
projectDir: string;
|
|
17
|
+
/** File creation time in milliseconds since epoch */
|
|
18
|
+
birthtimeMs: number;
|
|
19
|
+
/** CWD this session maps to — set by the adapter after calling batchGetSessionFileBirthtimes() */
|
|
20
|
+
resolvedCwd: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get birth times for .jsonl session files across multiple directories in a single shell call.
|
|
24
|
+
*
|
|
25
|
+
* Combines all directory globs into one `stat` command to avoid per-directory exec overhead.
|
|
26
|
+
* Returns empty array if no directories have .jsonl files or command fails.
|
|
27
|
+
* resolvedCwd is left empty — the adapter must set it.
|
|
28
|
+
*/
|
|
29
|
+
export declare function batchGetSessionFileBirthtimes(dirs: string[]): SessionFile[];
|
|
30
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/utils/session.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH;;GAEG;AACH,MAAM,WAAW,WAAW;IACxB,6DAA6D;IAC7D,SAAS,EAAE,MAAM,CAAC;IAElB,oCAAoC;IACpC,QAAQ,EAAE,MAAM,CAAC;IAEjB,2CAA2C;IAC3C,UAAU,EAAE,MAAM,CAAC;IAEnB,qDAAqD;IACrD,WAAW,EAAE,MAAM,CAAC;IAEpB,kGAAkG;IAClG,WAAW,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,WAAW,EAAE,CAiB3E"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Session File Utilities
|
|
4
|
+
*
|
|
5
|
+
* Shell command wrappers for discovering session files and their birth times.
|
|
6
|
+
* Uses `stat` to get exact epoch-second birth timestamps without reading file contents.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.batchGetSessionFileBirthtimes = batchGetSessionFileBirthtimes;
|
|
43
|
+
const path = __importStar(require("path"));
|
|
44
|
+
const child_process_1 = require("child_process");
|
|
45
|
+
/**
|
|
46
|
+
* Get birth times for .jsonl session files across multiple directories in a single shell call.
|
|
47
|
+
*
|
|
48
|
+
* Combines all directory globs into one `stat` command to avoid per-directory exec overhead.
|
|
49
|
+
* Returns empty array if no directories have .jsonl files or command fails.
|
|
50
|
+
* resolvedCwd is left empty — the adapter must set it.
|
|
51
|
+
*/
|
|
52
|
+
function batchGetSessionFileBirthtimes(dirs) {
|
|
53
|
+
if (dirs.length === 0)
|
|
54
|
+
return [];
|
|
55
|
+
try {
|
|
56
|
+
const isMacOS = process.platform === 'darwin';
|
|
57
|
+
const globs = dirs.map((d) => `"${d}"/*.jsonl`).join(' ');
|
|
58
|
+
// || true prevents non-zero exit when some globs have no .jsonl matches
|
|
59
|
+
const command = isMacOS
|
|
60
|
+
? `stat -f '%B %N' ${globs} 2>/dev/null || true`
|
|
61
|
+
: `stat --format='%W %n' ${globs} 2>/dev/null || true`;
|
|
62
|
+
const output = (0, child_process_1.execSync)(command, { encoding: 'utf-8' });
|
|
63
|
+
return parseStatOutput(output);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Parse stat output lines into SessionFile entries.
|
|
71
|
+
*/
|
|
72
|
+
function parseStatOutput(output) {
|
|
73
|
+
const results = [];
|
|
74
|
+
for (const rawLine of output.trim().split('\n')) {
|
|
75
|
+
const line = rawLine.trim();
|
|
76
|
+
if (!line)
|
|
77
|
+
continue;
|
|
78
|
+
// Format: "<epoch_seconds> <filepath>"
|
|
79
|
+
const spaceIdx = line.indexOf(' ');
|
|
80
|
+
if (spaceIdx === -1)
|
|
81
|
+
continue;
|
|
82
|
+
const epochStr = line.slice(0, spaceIdx);
|
|
83
|
+
const filePath = line.slice(spaceIdx + 1).trim();
|
|
84
|
+
const epochSeconds = parseInt(epochStr, 10);
|
|
85
|
+
if (!Number.isFinite(epochSeconds) || epochSeconds <= 0)
|
|
86
|
+
continue;
|
|
87
|
+
const fileName = path.basename(filePath);
|
|
88
|
+
if (!fileName.endsWith('.jsonl'))
|
|
89
|
+
continue;
|
|
90
|
+
const sessionId = fileName.replace(/\.jsonl$/, '');
|
|
91
|
+
results.push({
|
|
92
|
+
sessionId,
|
|
93
|
+
filePath,
|
|
94
|
+
projectDir: path.dirname(filePath),
|
|
95
|
+
birthtimeMs: epochSeconds * 1000,
|
|
96
|
+
resolvedCwd: '',
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
return results;
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/utils/session.ts"],"names":[],"mappings":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C,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;QACzC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAEjD,MAAM,YAAY,GAAG,QAAQ,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QAC5C,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,YAAY,IAAI,CAAC;YAAE,SAAS;QAElE,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACzC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC;YAAE,SAAS;QAE3C,MAAM,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;QAEnD,OAAO,CAAC,IAAI,CAAC;YACT,SAAS;YACT,QAAQ;YACR,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;YAClC,WAAW,EAAE,YAAY,GAAG,IAAI;YAChC,WAAW,EAAE,EAAE;SAClB,CAAC,CAAC;IACP,CAAC;IAED,OAAO,OAAO,CAAC;AACnB,CAAC"}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { describe, it, expect, beforeEach } from '@jest/globals';
|
|
6
6
|
import { AgentManager } from '../AgentManager';
|
|
7
|
-
import type { AgentAdapter, AgentInfo, AgentType } from '../adapters/AgentAdapter';
|
|
7
|
+
import type { AgentAdapter, AgentInfo, AgentType, ConversationMessage } from '../adapters/AgentAdapter';
|
|
8
8
|
import { AgentStatus } from '../adapters/AgentAdapter';
|
|
9
9
|
|
|
10
10
|
// Mock adapter for testing
|
|
@@ -26,6 +26,10 @@ class MockAdapter implements AgentAdapter {
|
|
|
26
26
|
return true;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
getConversation(): ConversationMessage[] {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
|
|
29
33
|
setAgents(agents: AgentInfo[]): void {
|
|
30
34
|
this.mockAgents = agents;
|
|
31
35
|
}
|
|
@@ -45,7 +49,6 @@ function createMockAgent(overrides: Partial<AgentInfo> = {}): AgentInfo {
|
|
|
45
49
|
pid: 12345,
|
|
46
50
|
projectPath: '/test/path',
|
|
47
51
|
sessionId: 'test-session-id',
|
|
48
|
-
slug: 'test-slug',
|
|
49
52
|
lastActive: new Date(),
|
|
50
53
|
...overrides,
|
|
51
54
|
};
|
|
@@ -130,17 +133,6 @@ describe('AgentManager', () => {
|
|
|
130
133
|
});
|
|
131
134
|
});
|
|
132
135
|
|
|
133
|
-
describe('hasAdapter', () => {
|
|
134
|
-
it('should return true for registered adapter', () => {
|
|
135
|
-
manager.registerAdapter(new MockAdapter('claude'));
|
|
136
|
-
expect(manager.hasAdapter('claude')).toBe(true);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it('should return false for non-registered adapter', () => {
|
|
140
|
-
expect(manager.hasAdapter('claude')).toBe(false);
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
|
|
144
136
|
describe('listAgents', () => {
|
|
145
137
|
it('should return empty array when no adapters registered', async () => {
|
|
146
138
|
const agents = await manager.listAgents();
|
|
@@ -222,20 +214,6 @@ describe('AgentManager', () => {
|
|
|
222
214
|
});
|
|
223
215
|
});
|
|
224
216
|
|
|
225
|
-
describe('getAdapterCount', () => {
|
|
226
|
-
it('should return 0 when no adapters registered', () => {
|
|
227
|
-
expect(manager.getAdapterCount()).toBe(0);
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
it('should return correct count', () => {
|
|
231
|
-
manager.registerAdapter(new MockAdapter('claude'));
|
|
232
|
-
expect(manager.getAdapterCount()).toBe(1);
|
|
233
|
-
|
|
234
|
-
manager.registerAdapter(new MockAdapter('gemini_cli'));
|
|
235
|
-
expect(manager.getAdapterCount()).toBe(2);
|
|
236
|
-
});
|
|
237
|
-
});
|
|
238
|
-
|
|
239
217
|
describe('clear', () => {
|
|
240
218
|
it('should remove all adapters', () => {
|
|
241
219
|
manager.registerAdapter(new MockAdapter('claude'));
|