@k1e1n04/mav 0.1.32 → 0.1.34
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/package.json +1 -1
- package/dist/src/agent.d.ts +2 -0
- package/dist/src/agent.js +26 -19
- package/dist/src/agent.js.map +1 -1
- package/dist/src/process-cwd.d.ts +2 -2
- package/dist/src/process-cwd.js +36 -19
- package/dist/src/process-cwd.js.map +1 -1
- package/package.json +1 -1
- package/src/agent.ts +29 -20
- package/src/process-cwd.ts +40 -24
package/dist/package.json
CHANGED
package/dist/src/agent.d.ts
CHANGED
|
@@ -42,6 +42,8 @@ export declare class AgentSession extends EventEmitter {
|
|
|
42
42
|
private scheduleIdleTimer;
|
|
43
43
|
private clearIdleTimer;
|
|
44
44
|
private startCwdPolling;
|
|
45
|
+
private scheduleCwdPoll;
|
|
46
|
+
private runCwdPoll;
|
|
45
47
|
private clearCwdPollTimer;
|
|
46
48
|
private updateDisplayNameFromInput;
|
|
47
49
|
private updateCwdFromOutput;
|
package/dist/src/agent.js
CHANGED
|
@@ -152,36 +152,43 @@ export class AgentSession extends EventEmitter {
|
|
|
152
152
|
this.idleTimer = null;
|
|
153
153
|
}
|
|
154
154
|
startCwdPolling() {
|
|
155
|
-
if (this.cwdPollTimer || !this.ptyProcess) {
|
|
155
|
+
if (this.cwdPollTimer !== null || !this.ptyProcess) {
|
|
156
156
|
return;
|
|
157
157
|
}
|
|
158
|
-
this.
|
|
159
|
-
|
|
160
|
-
|
|
158
|
+
this.scheduleCwdPoll();
|
|
159
|
+
}
|
|
160
|
+
scheduleCwdPoll() {
|
|
161
|
+
this.cwdPollTimer = setTimeout(() => { void this.runCwdPoll(); }, AgentSession.CWD_POLL_INTERVAL_MS);
|
|
162
|
+
}
|
|
163
|
+
async runCwdPoll() {
|
|
164
|
+
this.cwdPollTimer = null;
|
|
165
|
+
if (this.exited || !this.ptyProcess)
|
|
166
|
+
return;
|
|
167
|
+
if (this.type === 'claude-code') {
|
|
168
|
+
if (this.claudeChildPid === null) {
|
|
169
|
+
this.claudeChildPid = await getClaudeChildPid(this.ptyProcess.pid);
|
|
161
170
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
const targetPid = this.claudeChildPid ?? this.ptyProcess.pid;
|
|
167
|
-
const cwd = getProcessCwd(targetPid);
|
|
168
|
-
if (cwd === null && this.claudeChildPid !== null) {
|
|
169
|
-
this.claudeChildPid = null;
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
this.updateCwd(cwd);
|
|
173
|
-
}
|
|
171
|
+
const targetPid = this.claudeChildPid ?? this.ptyProcess.pid;
|
|
172
|
+
const cwd = await getProcessCwd(targetPid);
|
|
173
|
+
if (cwd === null && this.claudeChildPid !== null) {
|
|
174
|
+
this.claudeChildPid = null;
|
|
174
175
|
}
|
|
175
176
|
else {
|
|
176
|
-
this.updateCwd(
|
|
177
|
+
this.updateCwd(cwd);
|
|
177
178
|
}
|
|
178
|
-
}
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
this.updateCwd(await getProcessCwd(this.ptyProcess.pid));
|
|
182
|
+
}
|
|
183
|
+
if (!this.exited) {
|
|
184
|
+
this.scheduleCwdPoll();
|
|
185
|
+
}
|
|
179
186
|
}
|
|
180
187
|
clearCwdPollTimer() {
|
|
181
188
|
if (!this.cwdPollTimer) {
|
|
182
189
|
return;
|
|
183
190
|
}
|
|
184
|
-
|
|
191
|
+
clearTimeout(this.cwdPollTimer);
|
|
185
192
|
this.cwdPollTimer = null;
|
|
186
193
|
}
|
|
187
194
|
updateDisplayNameFromInput(data) {
|
package/dist/src/agent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,KAAK,GAAG,MAAM,UAAU,CAAA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AA;QAC/C,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAA;QACb,CAAC;IACH,CAAC;IAEO,MAAM,CAAC,oBAAoB,CAAC,KAAa;QAC/C,MAAM,WAAW,GAAG,KAAK;aACtB,OAAO,CAAC,gCAAgC,EAAE,EAAE,CAAC,CAAE,+BAA+B;aAC9E,OAAO,CAAC,gCAAgC,EAAE,EAAE,CAAC;aAC7C,OAAO,CAAC,0BAA0B,EAAE,EAAE,CAAC;aACvC,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAA;QAChC,MAAM,SAAS,GAAG,WAAW;aAC1B,OAAO,CAAC,mBAAmB,EAAE,GAAG,CAAC;aACjC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;aACpB,IAAI,EAAE,CAAA;QAET,IAAI,SAAS,CAAC,MAAM,IAAI,YAAY,CAAC,uBAAuB,EAAE,CAAC;YAC7D,OAAO,SAAS,CAAA;QAClB,CAAC;QAED,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,YAAY,CAAC,uBAAuB,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,KAAK,CAAA;IACvF,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function getProcessCwd(pid: number, platform?: NodeJS.Platform): string | null
|
|
2
|
-
export declare function getClaudeChildPid(shellPid: number, platform?: NodeJS.Platform): number | null
|
|
1
|
+
export declare function getProcessCwd(pid: number, platform?: NodeJS.Platform): Promise<string | null>;
|
|
2
|
+
export declare function getClaudeChildPid(shellPid: number, platform?: NodeJS.Platform): Promise<number | null>;
|
package/dist/src/process-cwd.js
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { readlink, readFile } from 'node:fs/promises';
|
|
3
|
+
function runCommand(cmd, args) {
|
|
4
|
+
return new Promise((resolve, reject) => {
|
|
5
|
+
execFile(cmd, args, { encoding: 'utf8' }, (err, stdout) => {
|
|
6
|
+
if (err)
|
|
7
|
+
reject(err);
|
|
8
|
+
else
|
|
9
|
+
resolve(stdout);
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
export async function getProcessCwd(pid, platform = process.platform) {
|
|
4
14
|
if (!Number.isInteger(pid) || pid <= 0) {
|
|
5
15
|
return null;
|
|
6
16
|
}
|
|
7
17
|
try {
|
|
8
18
|
if (platform === 'linux') {
|
|
9
|
-
return
|
|
19
|
+
return await readlink(`/proc/${pid}/cwd`);
|
|
10
20
|
}
|
|
11
21
|
if (platform === 'darwin') {
|
|
12
|
-
const output =
|
|
22
|
+
const output = await runCommand('lsof', ['-a', '-d', 'cwd', '-p', String(pid), '-Fn']);
|
|
13
23
|
const cwdLine = output
|
|
14
24
|
.split('\n')
|
|
15
25
|
.find((line) => line.startsWith('n/') || line === 'n/');
|
|
@@ -22,7 +32,7 @@ export function getProcessCwd(pid, platform = process.platform) {
|
|
|
22
32
|
return null;
|
|
23
33
|
}
|
|
24
34
|
const CLAUDE_CHILD_MAX_DEPTH = 5;
|
|
25
|
-
export function getClaudeChildPid(shellPid, platform = process.platform) {
|
|
35
|
+
export async function getClaudeChildPid(shellPid, platform = process.platform) {
|
|
26
36
|
if (!Number.isInteger(shellPid) || shellPid <= 0) {
|
|
27
37
|
return null;
|
|
28
38
|
}
|
|
@@ -34,10 +44,11 @@ export function getClaudeChildPid(shellPid, platform = process.platform) {
|
|
|
34
44
|
}
|
|
35
45
|
return null;
|
|
36
46
|
}
|
|
37
|
-
function findClaudeChildDarwin(shellPid) {
|
|
47
|
+
async function findClaudeChildDarwin(shellPid) {
|
|
38
48
|
let initialChildren;
|
|
39
49
|
try {
|
|
40
|
-
|
|
50
|
+
const output = await runCommand('pgrep', ['-P', String(shellPid)]);
|
|
51
|
+
initialChildren = output
|
|
41
52
|
.split('\n')
|
|
42
53
|
.map((s) => s.trim())
|
|
43
54
|
.filter(Boolean);
|
|
@@ -51,13 +62,15 @@ function findClaudeChildDarwin(shellPid) {
|
|
|
51
62
|
if (item.depth >= CLAUDE_CHILD_MAX_DEPTH)
|
|
52
63
|
continue;
|
|
53
64
|
try {
|
|
54
|
-
const line =
|
|
55
|
-
|
|
56
|
-
|
|
65
|
+
const line = await runCommand('ps', ['-o', 'pid=,args=', '-p', item.pidStr]);
|
|
66
|
+
const trimmed = line.trim();
|
|
67
|
+
if (trimmed) {
|
|
68
|
+
const spaceIdx = trimmed.search(/\s/);
|
|
57
69
|
if (spaceIdx !== -1) {
|
|
58
|
-
const args =
|
|
70
|
+
const args = trimmed.slice(spaceIdx).trim();
|
|
59
71
|
const binary = args.split(' ')[0] ?? '';
|
|
60
|
-
if ((binary === 'node' || binary.endsWith('/node')) && args.includes('claude'))
|
|
72
|
+
if (((binary === 'node' || binary.endsWith('/node')) && args.includes('claude')) ||
|
|
73
|
+
binary === 'claude' || binary.endsWith('/claude')) {
|
|
61
74
|
return parseInt(item.pidStr, 10);
|
|
62
75
|
}
|
|
63
76
|
}
|
|
@@ -68,7 +81,8 @@ function findClaudeChildDarwin(shellPid) {
|
|
|
68
81
|
}
|
|
69
82
|
// Not claude — enqueue children for next level
|
|
70
83
|
try {
|
|
71
|
-
const
|
|
84
|
+
const childOutput = await runCommand('pgrep', ['-P', item.pidStr]);
|
|
85
|
+
const children = childOutput
|
|
72
86
|
.split('\n')
|
|
73
87
|
.map((s) => s.trim())
|
|
74
88
|
.filter(Boolean);
|
|
@@ -82,10 +96,11 @@ function findClaudeChildDarwin(shellPid) {
|
|
|
82
96
|
}
|
|
83
97
|
return null;
|
|
84
98
|
}
|
|
85
|
-
function findClaudeChildLinux(shellPid) {
|
|
99
|
+
async function findClaudeChildLinux(shellPid) {
|
|
86
100
|
let initialChildren;
|
|
87
101
|
try {
|
|
88
|
-
|
|
102
|
+
const content = await readFile(`/proc/${shellPid}/task/${shellPid}/children`, 'utf8');
|
|
103
|
+
initialChildren = content
|
|
89
104
|
.split(' ')
|
|
90
105
|
.map((s) => s.trim())
|
|
91
106
|
.filter(Boolean);
|
|
@@ -99,10 +114,11 @@ function findClaudeChildLinux(shellPid) {
|
|
|
99
114
|
if (item.depth >= CLAUDE_CHILD_MAX_DEPTH)
|
|
100
115
|
continue;
|
|
101
116
|
try {
|
|
102
|
-
const cmdline =
|
|
117
|
+
const cmdline = await readFile(`/proc/${item.pidStr}/cmdline`, 'utf8');
|
|
103
118
|
const parts = cmdline.split('\0').filter(Boolean);
|
|
104
119
|
const binary = parts[0] ?? '';
|
|
105
|
-
if ((binary === 'node' || binary.endsWith('/node')) && cmdline.includes('claude'))
|
|
120
|
+
if (((binary === 'node' || binary.endsWith('/node')) && cmdline.includes('claude')) ||
|
|
121
|
+
binary === 'claude' || binary.endsWith('/claude')) {
|
|
106
122
|
return parseInt(item.pidStr, 10);
|
|
107
123
|
}
|
|
108
124
|
}
|
|
@@ -111,7 +127,8 @@ function findClaudeChildLinux(shellPid) {
|
|
|
111
127
|
}
|
|
112
128
|
// Not claude — enqueue children for next level
|
|
113
129
|
try {
|
|
114
|
-
const
|
|
130
|
+
const content = await readFile(`/proc/${item.pidStr}/task/${item.pidStr}/children`, 'utf8');
|
|
131
|
+
const children = content
|
|
115
132
|
.split(' ')
|
|
116
133
|
.map((s) => s.trim())
|
|
117
134
|
.filter(Boolean);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-cwd.js","sourceRoot":"","sources":["../../src/process-cwd.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"process-cwd.js","sourceRoot":"","sources":["../../src/process-cwd.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAErD,SAAS,UAAU,CAAC,GAAW,EAAE,IAAc;IAC7C,OAAO,IAAI,OAAO,CAAC,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MAAM,CAAC,OAAO,CAAC,CAAA;YACjD,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;YAC7B,IACE,CAAC,CAAC,MAAM,KAAK,MAAM,IAAI,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;gBAC/E,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,EACjD,CAAC;gBACD,OAAO,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;YAClC,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,SAAQ;QACV,CAAC;QAED,+CAA+C;QAC/C,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,SAAS,IAAI,CAAC,MAAM,SAAS,IAAI,CAAC,MAAM,WAAW,EAAE,MAAM,CAAC,CAAA;YAC3F,MAAM,QAAQ,GAAG,OAAO;iBACrB,KAAK,CAAC,GAAG,CAAC;iBACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;iBACpB,MAAM,CAAC,OAAO,CAAC,CAAA;YAClB,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;gBAC7B,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC,CAAA;YACtD,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,yBAAyB;QAC3B,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC"}
|
package/package.json
CHANGED
package/src/agent.ts
CHANGED
|
@@ -33,7 +33,7 @@ export class AgentSession extends EventEmitter {
|
|
|
33
33
|
private ptyProcess: pty.IPty | undefined
|
|
34
34
|
private exited = false
|
|
35
35
|
private idleTimer: ReturnType<typeof setTimeout> | null = null
|
|
36
|
-
private cwdPollTimer: ReturnType<typeof
|
|
36
|
+
private cwdPollTimer: ReturnType<typeof setTimeout> | null = null
|
|
37
37
|
private claudeChildPid: number | null = null
|
|
38
38
|
private displayNameLocked = false
|
|
39
39
|
private initialInputBuffer = ''
|
|
@@ -175,30 +175,39 @@ export class AgentSession extends EventEmitter {
|
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
private startCwdPolling(): void {
|
|
178
|
-
if (this.cwdPollTimer || !this.ptyProcess) {
|
|
178
|
+
if (this.cwdPollTimer !== null || !this.ptyProcess) {
|
|
179
179
|
return
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
-
this.
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
182
|
+
this.scheduleCwdPoll()
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
private scheduleCwdPoll(): void {
|
|
186
|
+
this.cwdPollTimer = setTimeout(() => { void this.runCwdPoll() }, AgentSession.CWD_POLL_INTERVAL_MS)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
private async runCwdPoll(): Promise<void> {
|
|
190
|
+
this.cwdPollTimer = null
|
|
191
|
+
if (this.exited || !this.ptyProcess) return
|
|
186
192
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
} else {
|
|
196
|
-
this.updateCwd(cwd)
|
|
197
|
-
}
|
|
193
|
+
if (this.type === 'claude-code') {
|
|
194
|
+
if (this.claudeChildPid === null) {
|
|
195
|
+
this.claudeChildPid = await getClaudeChildPid(this.ptyProcess.pid)
|
|
196
|
+
}
|
|
197
|
+
const targetPid = this.claudeChildPid ?? this.ptyProcess.pid
|
|
198
|
+
const cwd = await getProcessCwd(targetPid)
|
|
199
|
+
if (cwd === null && this.claudeChildPid !== null) {
|
|
200
|
+
this.claudeChildPid = null
|
|
198
201
|
} else {
|
|
199
|
-
this.updateCwd(
|
|
202
|
+
this.updateCwd(cwd)
|
|
200
203
|
}
|
|
201
|
-
}
|
|
204
|
+
} else {
|
|
205
|
+
this.updateCwd(await getProcessCwd(this.ptyProcess.pid))
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (!this.exited) {
|
|
209
|
+
this.scheduleCwdPoll()
|
|
210
|
+
}
|
|
202
211
|
}
|
|
203
212
|
|
|
204
213
|
private clearCwdPollTimer(): void {
|
|
@@ -206,7 +215,7 @@ export class AgentSession extends EventEmitter {
|
|
|
206
215
|
return
|
|
207
216
|
}
|
|
208
217
|
|
|
209
|
-
|
|
218
|
+
clearTimeout(this.cwdPollTimer)
|
|
210
219
|
this.cwdPollTimer = null
|
|
211
220
|
}
|
|
212
221
|
|
package/src/process-cwd.ts
CHANGED
|
@@ -1,22 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { execFile } from 'node:child_process'
|
|
2
|
+
import { readlink, readFile } from 'node:fs/promises'
|
|
3
|
+
|
|
4
|
+
function runCommand(cmd: string, args: string[]): Promise<string> {
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
execFile(cmd, args, { encoding: 'utf8' }, (err, stdout) => {
|
|
7
|
+
if (err) reject(err)
|
|
8
|
+
else resolve(stdout as string)
|
|
9
|
+
})
|
|
10
|
+
})
|
|
11
|
+
}
|
|
3
12
|
|
|
4
|
-
export function getProcessCwd(pid: number, platform: NodeJS.Platform = process.platform): string | null {
|
|
13
|
+
export async function getProcessCwd(pid: number, platform: NodeJS.Platform = process.platform): Promise<string | null> {
|
|
5
14
|
if (!Number.isInteger(pid) || pid <= 0) {
|
|
6
15
|
return null
|
|
7
16
|
}
|
|
8
17
|
|
|
9
18
|
try {
|
|
10
19
|
if (platform === 'linux') {
|
|
11
|
-
return
|
|
20
|
+
return await readlink(`/proc/${pid}/cwd`)
|
|
12
21
|
}
|
|
13
22
|
|
|
14
23
|
if (platform === 'darwin') {
|
|
15
|
-
const output =
|
|
16
|
-
'lsof',
|
|
17
|
-
['-a', '-d', 'cwd', '-p', String(pid), '-Fn'],
|
|
18
|
-
{ encoding: 'utf8' },
|
|
19
|
-
)
|
|
24
|
+
const output = await runCommand('lsof', ['-a', '-d', 'cwd', '-p', String(pid), '-Fn'])
|
|
20
25
|
const cwdLine = output
|
|
21
26
|
.split('\n')
|
|
22
27
|
.find((line) => line.startsWith('n/') || line === 'n/')
|
|
@@ -32,10 +37,10 @@ export function getProcessCwd(pid: number, platform: NodeJS.Platform = process.p
|
|
|
32
37
|
|
|
33
38
|
const CLAUDE_CHILD_MAX_DEPTH = 5
|
|
34
39
|
|
|
35
|
-
export function getClaudeChildPid(
|
|
40
|
+
export async function getClaudeChildPid(
|
|
36
41
|
shellPid: number,
|
|
37
42
|
platform: NodeJS.Platform = process.platform,
|
|
38
|
-
): number | null {
|
|
43
|
+
): Promise<number | null> {
|
|
39
44
|
if (!Number.isInteger(shellPid) || shellPid <= 0) {
|
|
40
45
|
return null
|
|
41
46
|
}
|
|
@@ -51,10 +56,11 @@ export function getClaudeChildPid(
|
|
|
51
56
|
return null
|
|
52
57
|
}
|
|
53
58
|
|
|
54
|
-
function findClaudeChildDarwin(shellPid: number): number | null {
|
|
59
|
+
async function findClaudeChildDarwin(shellPid: number): Promise<number | null> {
|
|
55
60
|
let initialChildren: string[]
|
|
56
61
|
try {
|
|
57
|
-
|
|
62
|
+
const output = await runCommand('pgrep', ['-P', String(shellPid)])
|
|
63
|
+
initialChildren = output
|
|
58
64
|
.split('\n')
|
|
59
65
|
.map((s) => s.trim())
|
|
60
66
|
.filter(Boolean)
|
|
@@ -69,13 +75,17 @@ function findClaudeChildDarwin(shellPid: number): number | null {
|
|
|
69
75
|
if (item.depth >= CLAUDE_CHILD_MAX_DEPTH) continue
|
|
70
76
|
|
|
71
77
|
try {
|
|
72
|
-
const line =
|
|
73
|
-
|
|
74
|
-
|
|
78
|
+
const line = await runCommand('ps', ['-o', 'pid=,args=', '-p', item.pidStr])
|
|
79
|
+
const trimmed = line.trim()
|
|
80
|
+
if (trimmed) {
|
|
81
|
+
const spaceIdx = trimmed.search(/\s/)
|
|
75
82
|
if (spaceIdx !== -1) {
|
|
76
|
-
const args =
|
|
83
|
+
const args = trimmed.slice(spaceIdx).trim()
|
|
77
84
|
const binary = args.split(' ')[0] ?? ''
|
|
78
|
-
if (
|
|
85
|
+
if (
|
|
86
|
+
((binary === 'node' || binary.endsWith('/node')) && args.includes('claude')) ||
|
|
87
|
+
binary === 'claude' || binary.endsWith('/claude')
|
|
88
|
+
) {
|
|
79
89
|
return parseInt(item.pidStr, 10)
|
|
80
90
|
}
|
|
81
91
|
}
|
|
@@ -86,7 +96,8 @@ function findClaudeChildDarwin(shellPid: number): number | null {
|
|
|
86
96
|
|
|
87
97
|
// Not claude — enqueue children for next level
|
|
88
98
|
try {
|
|
89
|
-
const
|
|
99
|
+
const childOutput = await runCommand('pgrep', ['-P', item.pidStr])
|
|
100
|
+
const children = childOutput
|
|
90
101
|
.split('\n')
|
|
91
102
|
.map((s) => s.trim())
|
|
92
103
|
.filter(Boolean)
|
|
@@ -101,10 +112,11 @@ function findClaudeChildDarwin(shellPid: number): number | null {
|
|
|
101
112
|
return null
|
|
102
113
|
}
|
|
103
114
|
|
|
104
|
-
function findClaudeChildLinux(shellPid: number): number | null {
|
|
115
|
+
async function findClaudeChildLinux(shellPid: number): Promise<number | null> {
|
|
105
116
|
let initialChildren: string[]
|
|
106
117
|
try {
|
|
107
|
-
|
|
118
|
+
const content = await readFile(`/proc/${shellPid}/task/${shellPid}/children`, 'utf8')
|
|
119
|
+
initialChildren = content
|
|
108
120
|
.split(' ')
|
|
109
121
|
.map((s) => s.trim())
|
|
110
122
|
.filter(Boolean)
|
|
@@ -119,10 +131,13 @@ function findClaudeChildLinux(shellPid: number): number | null {
|
|
|
119
131
|
if (item.depth >= CLAUDE_CHILD_MAX_DEPTH) continue
|
|
120
132
|
|
|
121
133
|
try {
|
|
122
|
-
const cmdline =
|
|
134
|
+
const cmdline = await readFile(`/proc/${item.pidStr}/cmdline`, 'utf8')
|
|
123
135
|
const parts = cmdline.split('\0').filter(Boolean)
|
|
124
136
|
const binary = parts[0] ?? ''
|
|
125
|
-
if (
|
|
137
|
+
if (
|
|
138
|
+
((binary === 'node' || binary.endsWith('/node')) && cmdline.includes('claude')) ||
|
|
139
|
+
binary === 'claude' || binary.endsWith('/claude')
|
|
140
|
+
) {
|
|
126
141
|
return parseInt(item.pidStr, 10)
|
|
127
142
|
}
|
|
128
143
|
} catch {
|
|
@@ -131,7 +146,8 @@ function findClaudeChildLinux(shellPid: number): number | null {
|
|
|
131
146
|
|
|
132
147
|
// Not claude — enqueue children for next level
|
|
133
148
|
try {
|
|
134
|
-
const
|
|
149
|
+
const content = await readFile(`/proc/${item.pidStr}/task/${item.pidStr}/children`, 'utf8')
|
|
150
|
+
const children = content
|
|
135
151
|
.split(' ')
|
|
136
152
|
.map((s) => s.trim())
|
|
137
153
|
.filter(Boolean)
|