@ai-devkit/agent-manager 0.38.0 → 0.39.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/__tests__/harnesses/devin/DevinAdapter.test.js +597 -0
- package/dist/__tests__/harnesses/devin/DevinAdapter.test.js.map +1 -0
- package/dist/__tests__/harnesses/devin/DevinAgentMapper.test.js +91 -0
- package/dist/__tests__/harnesses/devin/DevinAgentMapper.test.js.map +1 -0
- package/dist/__tests__/harnesses/devin/DevinSessionLocator.test.js +192 -0
- package/dist/__tests__/harnesses/devin/DevinSessionLocator.test.js.map +1 -0
- package/dist/__tests__/harnesses/devin/DevinSessionParser.test.js +407 -0
- package/dist/__tests__/harnesses/devin/DevinSessionParser.test.js.map +1 -0
- package/dist/__tests__/harnesses/devin/fixtures.js +95 -0
- package/dist/__tests__/harnesses/devin/fixtures.js.map +1 -0
- package/dist/__tests__/harnesses/readiness/AgentReadiness.test.js +64 -1
- package/dist/__tests__/harnesses/readiness/AgentReadiness.test.js.map +1 -1
- package/dist/__tests__/terminal/GhosttyBackend.test.js +334 -0
- package/dist/__tests__/terminal/GhosttyBackend.test.js.map +1 -0
- package/dist/adapters/AgentAdapter.d.ts +1 -1
- package/dist/adapters/AgentAdapter.d.ts.map +1 -1
- package/dist/adapters/AgentAdapter.js +2 -1
- package/dist/adapters/AgentAdapter.js.map +1 -1
- package/dist/harnesses/devin/DevinAdapter.d.ts +39 -0
- package/dist/harnesses/devin/DevinAdapter.d.ts.map +1 -0
- package/dist/harnesses/devin/DevinAdapter.js +177 -0
- package/dist/harnesses/devin/DevinAdapter.js.map +1 -0
- package/dist/harnesses/devin/DevinAgentMapper.d.ts +11 -0
- package/dist/harnesses/devin/DevinAgentMapper.d.ts.map +1 -0
- package/dist/harnesses/devin/DevinAgentMapper.js +35 -0
- package/dist/harnesses/devin/DevinAgentMapper.js.map +1 -0
- package/dist/harnesses/devin/DevinSessionLocator.d.ts +46 -0
- package/dist/harnesses/devin/DevinSessionLocator.d.ts.map +1 -0
- package/dist/harnesses/devin/DevinSessionLocator.js +176 -0
- package/dist/harnesses/devin/DevinSessionLocator.js.map +1 -0
- package/dist/harnesses/devin/DevinSessionParser.d.ts +29 -0
- package/dist/harnesses/devin/DevinSessionParser.d.ts.map +1 -0
- package/dist/harnesses/devin/DevinSessionParser.js +166 -0
- package/dist/harnesses/devin/DevinSessionParser.js.map +1 -0
- package/dist/harnesses/devin/readiness.d.ts +3 -0
- package/dist/harnesses/devin/readiness.d.ts.map +1 -0
- package/dist/harnesses/devin/readiness.js +39 -0
- package/dist/harnesses/devin/readiness.js.map +1 -0
- package/dist/harnesses/index.d.ts.map +1 -1
- package/dist/harnesses/index.js +3 -1
- package/dist/harnesses/index.js.map +1 -1
- package/dist/harnesses/readiness/AgentReadiness.d.ts.map +1 -1
- package/dist/harnesses/readiness/AgentReadiness.js +3 -1
- package/dist/harnesses/readiness/AgentReadiness.js.map +1 -1
- package/dist/harnesses/readiness/types.d.ts +1 -1
- package/dist/harnesses/readiness/types.d.ts.map +1 -1
- package/dist/harnesses/runtimeProfiles.d.ts.map +1 -1
- package/dist/harnesses/runtimeProfiles.js +2 -1
- package/dist/harnesses/runtimeProfiles.js.map +1 -1
- package/dist/terminal/TtyWriter.d.ts.map +1 -1
- package/dist/terminal/TtyWriter.js +4 -3
- package/dist/terminal/TtyWriter.js.map +1 -1
- package/dist/terminal/backends/ghostty.d.ts +3 -0
- package/dist/terminal/backends/ghostty.d.ts.map +1 -0
- package/dist/terminal/backends/ghostty.js +161 -0
- package/dist/terminal/backends/ghostty.js.map +1 -0
- package/dist/terminal/backends/index.d.ts.map +1 -1
- package/dist/terminal/backends/index.js +2 -0
- package/dist/terminal/backends/index.js.map +1 -1
- package/dist/terminal/backends/shared.d.ts +2 -0
- package/dist/terminal/backends/shared.d.ts.map +1 -1
- package/dist/terminal/backends/shared.js +4 -1
- package/dist/terminal/backends/shared.js.map +1 -1
- package/dist/terminal/types.d.ts +1 -0
- package/dist/terminal/types.d.ts.map +1 -1
- package/dist/terminal/types.js +1 -0
- package/dist/terminal/types.js.map +1 -1
- package/dist/utils/process.d.ts +2 -0
- package/dist/utils/process.d.ts.map +1 -1
- package/dist/utils/process.js +3 -0
- package/dist/utils/process.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/harnesses/devin/DevinAdapter.test.ts +292 -0
- package/src/__tests__/harnesses/devin/DevinAgentMapper.test.ts +88 -0
- package/src/__tests__/harnesses/devin/DevinSessionLocator.test.ts +139 -0
- package/src/__tests__/harnesses/devin/DevinSessionParser.test.ts +218 -0
- package/src/__tests__/harnesses/devin/fixtures.ts +144 -0
- package/src/__tests__/harnesses/readiness/AgentReadiness.test.ts +41 -0
- package/src/__tests__/terminal/GhosttyBackend.test.ts +271 -0
- package/src/adapters/AgentAdapter.ts +1 -0
- package/src/harnesses/devin/DevinAdapter.ts +224 -0
- package/src/harnesses/devin/DevinAgentMapper.ts +43 -0
- package/src/harnesses/devin/DevinSessionLocator.ts +230 -0
- package/src/harnesses/devin/DevinSessionParser.ts +236 -0
- package/src/harnesses/devin/readiness.ts +36 -0
- package/src/harnesses/index.ts +2 -0
- package/src/harnesses/readiness/AgentReadiness.ts +2 -0
- package/src/harnesses/runtimeProfiles.ts +1 -0
- package/src/terminal/TtyWriter.ts +5 -5
- package/src/terminal/backends/ghostty.ts +180 -0
- package/src/terminal/backends/index.ts +2 -0
- package/src/terminal/backends/shared.ts +6 -1
- package/src/terminal/types.ts +1 -0
- package/src/utils/process.ts +5 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { execFile } from "child_process";
|
|
2
|
+
import { writeFile } from "fs/promises";
|
|
3
|
+
import { promisify } from "util";
|
|
4
|
+
import { escapeAppleScript } from "../../utils/applescript.js";
|
|
5
|
+
import { getProcessCwdsAsync } from "../../utils/process.js";
|
|
6
|
+
import { TerminalType } from "../types.js";
|
|
7
|
+
import { CARRIAGE_RETURN, isProcessName, sleep } from "./shared.js";
|
|
8
|
+
const execFileAsync = promisify(execFile);
|
|
9
|
+
/** Separates fields in AppleScript output; never part of an id, title or path. */ const FIELD_SEPARATOR = "\x1f";
|
|
10
|
+
const MARKER_POLL_ATTEMPTS = 10;
|
|
11
|
+
const MARKER_POLL_INTERVAL_MS = 50;
|
|
12
|
+
async function listProcesses() {
|
|
13
|
+
const { stdout } = await execFileAsync("ps", [
|
|
14
|
+
"-Axo",
|
|
15
|
+
"pid=,ppid=,tty=,comm="
|
|
16
|
+
]);
|
|
17
|
+
const rows = [];
|
|
18
|
+
for (const line of stdout.split("\n")){
|
|
19
|
+
const match = line.trim().match(/^(\d+)\s+(\d+)\s+(\S+)\s+(.+)$/);
|
|
20
|
+
if (match) {
|
|
21
|
+
rows.push({
|
|
22
|
+
pid: Number(match[1]),
|
|
23
|
+
ppid: Number(match[2]),
|
|
24
|
+
tty: match[3],
|
|
25
|
+
comm: match[4]
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return rows;
|
|
30
|
+
}
|
|
31
|
+
async function listTerminals() {
|
|
32
|
+
const script = `
|
|
33
|
+
tell application "Ghostty"
|
|
34
|
+
set out to ""
|
|
35
|
+
repeat with t in terminals
|
|
36
|
+
set out to out & (id of t) & (character id 31) & (name of t) & (character id 31) & (working directory of t) & linefeed
|
|
37
|
+
end repeat
|
|
38
|
+
return out
|
|
39
|
+
end tell`;
|
|
40
|
+
const { stdout } = await execFileAsync("osascript", [
|
|
41
|
+
"-e",
|
|
42
|
+
script
|
|
43
|
+
]);
|
|
44
|
+
return stdout.split("\n").map((line)=>line.split(FIELD_SEPARATOR)).filter((fields)=>fields.length === 3 && fields[0]).map(([id, name, workingDirectory])=>({
|
|
45
|
+
id,
|
|
46
|
+
name,
|
|
47
|
+
workingDirectory
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
/** Run an AppleScript `command` with `t` bound to the located terminal; false if it is gone. */ async function onTerminal(location, command) {
|
|
51
|
+
const script = `
|
|
52
|
+
tell application "Ghostty"
|
|
53
|
+
set matches to (every terminal whose id is "${escapeAppleScript(location.identifier)}")
|
|
54
|
+
if (count of matches) is 0 then return "not_found"
|
|
55
|
+
set t to item 1 of matches
|
|
56
|
+
${command}
|
|
57
|
+
end tell
|
|
58
|
+
return "ok"`;
|
|
59
|
+
const { stdout } = await execFileAsync("osascript", [
|
|
60
|
+
"-e",
|
|
61
|
+
script
|
|
62
|
+
]);
|
|
63
|
+
return stdout.trim() === "ok";
|
|
64
|
+
}
|
|
65
|
+
/** Set the window title of whatever terminal owns `tty` (OSC 2). */ async function writeTitle(tty, title) {
|
|
66
|
+
// eslint-disable-next-line no-control-regex
|
|
67
|
+
const safe = title.replace(/[\x00-\x1f\x7f]/g, "");
|
|
68
|
+
await writeFile(tty, `\x1b]2;${safe}\x07`, {
|
|
69
|
+
flag: "a"
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Ghostty's AppleScript terminals expose an id, title and working directory,
|
|
74
|
+
* but not their TTY. Find the one owning `tty` without guessing:
|
|
75
|
+
* 1. only TTYs whose session was started by a ghostty process qualify;
|
|
76
|
+
* 2. if exactly one terminal's working directory matches a process on this
|
|
77
|
+
* TTY, and no other Ghostty TTY has a process there, that is it;
|
|
78
|
+
* 3. otherwise briefly set a unique title on the TTY, find the terminal now
|
|
79
|
+
* showing it, and restore its previous title.
|
|
80
|
+
*/ async function findTerminalId(tty) {
|
|
81
|
+
const processes = await listProcesses();
|
|
82
|
+
const ghosttyPids = new Set(processes.filter((p)=>isProcessName(p.comm, "ghostty")).map((p)=>p.pid));
|
|
83
|
+
if (ghosttyPids.size === 0) return null;
|
|
84
|
+
const ttyName = tty.replace(/^\/dev\//, "");
|
|
85
|
+
const ghosttyTtys = new Set(processes.filter((p)=>ghosttyPids.has(p.ppid) && p.tty !== "??").map((p)=>p.tty));
|
|
86
|
+
if (!ghosttyTtys.has(ttyName)) return null;
|
|
87
|
+
const terminals = await listTerminals();
|
|
88
|
+
const sessionProcesses = processes.filter((p)=>ghosttyTtys.has(p.tty));
|
|
89
|
+
const cwdByPid = await getProcessCwdsAsync(sessionProcesses.map((p)=>p.pid));
|
|
90
|
+
const ownDirs = new Set();
|
|
91
|
+
const otherDirs = new Set();
|
|
92
|
+
for (const p of sessionProcesses){
|
|
93
|
+
const cwd = cwdByPid.get(p.pid);
|
|
94
|
+
if (cwd) (p.tty === ttyName ? ownDirs : otherDirs).add(cwd);
|
|
95
|
+
}
|
|
96
|
+
// Trust the directory only when exactly one terminal is in a folder no other Ghostty TTY uses.
|
|
97
|
+
const byDirectory = terminals.filter((t)=>ownDirs.has(t.workingDirectory));
|
|
98
|
+
if (byDirectory.length === 1 && !otherDirs.has(byDirectory[0].workingDirectory)) {
|
|
99
|
+
return byDirectory[0].id;
|
|
100
|
+
}
|
|
101
|
+
const marker = `ai-devkit-${process.pid}-${Date.now()}`;
|
|
102
|
+
await writeTitle(tty, marker);
|
|
103
|
+
for(let attempt = 0; attempt < MARKER_POLL_ATTEMPTS; attempt++){
|
|
104
|
+
const marked = (await listTerminals()).find((t)=>t.name === marker);
|
|
105
|
+
if (marked) {
|
|
106
|
+
const previous = terminals.find((t)=>t.id === marked.id)?.name ?? "";
|
|
107
|
+
await writeTitle(tty, previous);
|
|
108
|
+
return marked.id;
|
|
109
|
+
}
|
|
110
|
+
await sleep(MARKER_POLL_INTERVAL_MS);
|
|
111
|
+
}
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* A Ghostty `text:` action that writes `bytes` to the terminal as typed.
|
|
116
|
+
* Unlike `send key`, it does not go through the keyboard layout or input
|
|
117
|
+
* method, which can turn a digit key into another character.
|
|
118
|
+
*/ function textAction(bytes) {
|
|
119
|
+
const escaped = Array.from(bytes, (char)=>{
|
|
120
|
+
if (char === "\\") return "\\\\";
|
|
121
|
+
const code = char.charCodeAt(0);
|
|
122
|
+
return code >= 0x20 && code < 0x7f ? char : `\\x${code.toString(16).padStart(2, "0")}`;
|
|
123
|
+
}).join("");
|
|
124
|
+
return `perform action "${escapeAppleScript(`text:${escaped}`)}" on t`;
|
|
125
|
+
}
|
|
126
|
+
export const ghosttyBackend = {
|
|
127
|
+
type: TerminalType.GHOSTTY,
|
|
128
|
+
label: "Ghostty",
|
|
129
|
+
async find (tty) {
|
|
130
|
+
try {
|
|
131
|
+
const id = await findTerminalId(tty);
|
|
132
|
+
return id ? {
|
|
133
|
+
type: TerminalType.GHOSTTY,
|
|
134
|
+
identifier: id,
|
|
135
|
+
tty
|
|
136
|
+
} : null;
|
|
137
|
+
} catch {
|
|
138
|
+
// Ghostty not installed, not scriptable, or the TTY is not writable
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
async focus (location) {
|
|
143
|
+
return onTerminal(location, "focus t\n activate");
|
|
144
|
+
},
|
|
145
|
+
async send (location, message) {
|
|
146
|
+
if (!await onTerminal(location, `input text "${escapeAppleScript(message)}" to t`)) {
|
|
147
|
+
throw new Error(`Ghostty terminal not found for TTY ${location.tty}`);
|
|
148
|
+
}
|
|
149
|
+
await sleep(150);
|
|
150
|
+
if (!await onTerminal(location, textAction(CARRIAGE_RETURN))) {
|
|
151
|
+
throw new Error(`Ghostty terminal disappeared before Enter could be sent for TTY ${location.tty}`);
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
async sendKey (location, key) {
|
|
155
|
+
if (!await onTerminal(location, textAction(key))) {
|
|
156
|
+
throw new Error(`Ghostty terminal not found for TTY ${location.tty}`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
//# sourceMappingURL=ghostty.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/terminal/backends/ghostty.ts"],"sourcesContent":["import { execFile } from \"child_process\";\nimport { writeFile } from \"fs/promises\";\nimport { promisify } from \"util\";\nimport { escapeAppleScript } from \"../../utils/applescript.js\";\nimport { getProcessCwdsAsync } from \"../../utils/process.js\";\nimport { TerminalType, type TerminalBackend, type TerminalLocation } from \"../types.js\";\nimport { CARRIAGE_RETURN, isProcessName, sleep } from \"./shared.js\";\n\nconst execFileAsync = promisify(execFile);\n\n/** Separates fields in AppleScript output; never part of an id, title or path. */\nconst FIELD_SEPARATOR = \"\\x1f\";\nconst MARKER_POLL_ATTEMPTS = 10;\nconst MARKER_POLL_INTERVAL_MS = 50;\n\ninterface GhosttyTerminal {\n id: string;\n name: string;\n workingDirectory: string;\n}\n\ninterface ProcessRow {\n pid: number;\n ppid: number;\n tty: string;\n comm: string;\n}\n\nasync function listProcesses(): Promise<ProcessRow[]> {\n const { stdout } = await execFileAsync(\"ps\", [\"-Axo\", \"pid=,ppid=,tty=,comm=\"]);\n const rows: ProcessRow[] = [];\n for (const line of stdout.split(\"\\n\")) {\n const match = line.trim().match(/^(\\d+)\\s+(\\d+)\\s+(\\S+)\\s+(.+)$/);\n if (match) {\n rows.push({ pid: Number(match[1]), ppid: Number(match[2]), tty: match[3], comm: match[4] });\n }\n }\n return rows;\n}\n\nasync function listTerminals(): Promise<GhosttyTerminal[]> {\n const script = `\ntell application \"Ghostty\"\n set out to \"\"\n repeat with t in terminals\n set out to out & (id of t) & (character id 31) & (name of t) & (character id 31) & (working directory of t) & linefeed\n end repeat\n return out\nend tell`;\n const { stdout } = await execFileAsync(\"osascript\", [\"-e\", script]);\n return stdout\n .split(\"\\n\")\n .map((line) => line.split(FIELD_SEPARATOR))\n .filter((fields) => fields.length === 3 && fields[0])\n .map(([id, name, workingDirectory]) => ({ id, name, workingDirectory }));\n}\n\n/** Run an AppleScript `command` with `t` bound to the located terminal; false if it is gone. */\nasync function onTerminal(location: TerminalLocation, command: string): Promise<boolean> {\n const script = `\ntell application \"Ghostty\"\n set matches to (every terminal whose id is \"${escapeAppleScript(location.identifier)}\")\n if (count of matches) is 0 then return \"not_found\"\n set t to item 1 of matches\n ${command}\nend tell\nreturn \"ok\"`;\n const { stdout } = await execFileAsync(\"osascript\", [\"-e\", script]);\n return stdout.trim() === \"ok\";\n}\n\n/** Set the window title of whatever terminal owns `tty` (OSC 2). */\nasync function writeTitle(tty: string, title: string): Promise<void> {\n // eslint-disable-next-line no-control-regex\n const safe = title.replace(/[\\x00-\\x1f\\x7f]/g, \"\");\n await writeFile(tty, `\\x1b]2;${safe}\\x07`, { flag: \"a\" });\n}\n\n/**\n * Ghostty's AppleScript terminals expose an id, title and working directory,\n * but not their TTY. Find the one owning `tty` without guessing:\n * 1. only TTYs whose session was started by a ghostty process qualify;\n * 2. if exactly one terminal's working directory matches a process on this\n * TTY, and no other Ghostty TTY has a process there, that is it;\n * 3. otherwise briefly set a unique title on the TTY, find the terminal now\n * showing it, and restore its previous title.\n */\nasync function findTerminalId(tty: string): Promise<string | null> {\n const processes = await listProcesses();\n const ghosttyPids = new Set(\n processes.filter((p) => isProcessName(p.comm, \"ghostty\")).map((p) => p.pid),\n );\n if (ghosttyPids.size === 0) return null;\n\n const ttyName = tty.replace(/^\\/dev\\//, \"\");\n const ghosttyTtys = new Set(\n processes.filter((p) => ghosttyPids.has(p.ppid) && p.tty !== \"??\").map((p) => p.tty),\n );\n if (!ghosttyTtys.has(ttyName)) return null;\n\n const terminals = await listTerminals();\n const sessionProcesses = processes.filter((p) => ghosttyTtys.has(p.tty));\n const cwdByPid = await getProcessCwdsAsync(sessionProcesses.map((p) => p.pid));\n const ownDirs = new Set<string>();\n const otherDirs = new Set<string>();\n for (const p of sessionProcesses) {\n const cwd = cwdByPid.get(p.pid);\n if (cwd) (p.tty === ttyName ? ownDirs : otherDirs).add(cwd);\n }\n\n // Trust the directory only when exactly one terminal is in a folder no other Ghostty TTY uses.\n const byDirectory = terminals.filter((t) => ownDirs.has(t.workingDirectory));\n if (byDirectory.length === 1 && !otherDirs.has(byDirectory[0].workingDirectory)) {\n return byDirectory[0].id;\n }\n\n const marker = `ai-devkit-${process.pid}-${Date.now()}`;\n await writeTitle(tty, marker);\n for (let attempt = 0; attempt < MARKER_POLL_ATTEMPTS; attempt++) {\n const marked = (await listTerminals()).find((t) => t.name === marker);\n if (marked) {\n const previous = terminals.find((t) => t.id === marked.id)?.name ?? \"\";\n await writeTitle(tty, previous);\n return marked.id;\n }\n await sleep(MARKER_POLL_INTERVAL_MS);\n }\n return null;\n}\n\n/**\n * A Ghostty `text:` action that writes `bytes` to the terminal as typed.\n * Unlike `send key`, it does not go through the keyboard layout or input\n * method, which can turn a digit key into another character.\n */\nfunction textAction(bytes: string): string {\n const escaped = Array.from(bytes, (char) => {\n if (char === \"\\\\\") return \"\\\\\\\\\";\n const code = char.charCodeAt(0);\n return code >= 0x20 && code < 0x7f ? char : `\\\\x${code.toString(16).padStart(2, \"0\")}`;\n }).join(\"\");\n return `perform action \"${escapeAppleScript(`text:${escaped}`)}\" on t`;\n}\n\nexport const ghosttyBackend: TerminalBackend = {\n type: TerminalType.GHOSTTY,\n label: \"Ghostty\",\n\n async find(tty) {\n try {\n const id = await findTerminalId(tty);\n return id ? { type: TerminalType.GHOSTTY, identifier: id, tty } : null;\n } catch {\n // Ghostty not installed, not scriptable, or the TTY is not writable\n return null;\n }\n },\n\n async focus(location) {\n return onTerminal(location, \"focus t\\n activate\");\n },\n\n async send(location, message) {\n if (!(await onTerminal(location, `input text \"${escapeAppleScript(message)}\" to t`))) {\n throw new Error(`Ghostty terminal not found for TTY ${location.tty}`);\n }\n await sleep(150);\n if (!(await onTerminal(location, textAction(CARRIAGE_RETURN)))) {\n throw new Error(\n `Ghostty terminal disappeared before Enter could be sent for TTY ${location.tty}`,\n );\n }\n },\n\n async sendKey(location, key) {\n if (!(await onTerminal(location, textAction(key)))) {\n throw new Error(`Ghostty terminal not found for TTY ${location.tty}`);\n }\n },\n};\n"],"names":["execFile","writeFile","promisify","escapeAppleScript","getProcessCwdsAsync","TerminalType","CARRIAGE_RETURN","isProcessName","sleep","execFileAsync","FIELD_SEPARATOR","MARKER_POLL_ATTEMPTS","MARKER_POLL_INTERVAL_MS","listProcesses","stdout","rows","line","split","match","trim","push","pid","Number","ppid","tty","comm","listTerminals","script","map","filter","fields","length","id","name","workingDirectory","onTerminal","location","command","identifier","writeTitle","title","safe","replace","flag","findTerminalId","processes","ghosttyPids","Set","p","size","ttyName","ghosttyTtys","has","terminals","sessionProcesses","cwdByPid","ownDirs","otherDirs","cwd","get","add","byDirectory","t","marker","process","Date","now","attempt","marked","find","previous","textAction","bytes","escaped","Array","from","char","code","charCodeAt","toString","padStart","join","ghosttyBackend","type","GHOSTTY","label","focus","send","message","Error","sendKey","key"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,gBAAgB;AACzC,SAASC,SAAS,QAAQ,cAAc;AACxC,SAASC,SAAS,QAAQ,OAAO;AACjC,SAASC,iBAAiB,QAAQ,6BAA6B;AAC/D,SAASC,mBAAmB,QAAQ,yBAAyB;AAC7D,SAASC,YAAY,QAAqD,cAAc;AACxF,SAASC,eAAe,EAAEC,aAAa,EAAEC,KAAK,QAAQ,cAAc;AAEpE,MAAMC,gBAAgBP,UAAUF;AAEhC,gFAAgF,GAChF,MAAMU,kBAAkB;AACxB,MAAMC,uBAAuB;AAC7B,MAAMC,0BAA0B;AAehC,eAAeC;IACb,MAAM,EAAEC,MAAM,EAAE,GAAG,MAAML,cAAc,MAAM;QAAC;QAAQ;KAAwB;IAC9E,MAAMM,OAAqB,EAAE;IAC7B,KAAK,MAAMC,QAAQF,OAAOG,KAAK,CAAC,MAAO;QACrC,MAAMC,QAAQF,KAAKG,IAAI,GAAGD,KAAK,CAAC;QAChC,IAAIA,OAAO;YACTH,KAAKK,IAAI,CAAC;gBAAEC,KAAKC,OAAOJ,KAAK,CAAC,EAAE;gBAAGK,MAAMD,OAAOJ,KAAK,CAAC,EAAE;gBAAGM,KAAKN,KAAK,CAAC,EAAE;gBAAEO,MAAMP,KAAK,CAAC,EAAE;YAAC;QAC3F;IACF;IACA,OAAOH;AACT;AAEA,eAAeW;IACb,MAAMC,SAAS,CAAC;;;;;;;QAOV,CAAC;IACP,MAAM,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ImF,MACR,CAAC,gEAAgE,EAAErD,SAASZ,GAAG,EAAE;QAErF;IACF;IAEA,MAAMkE,SAAQtD,QAAQ,EAAEuD,GAAG;QACzB,IAAI,CAAE,MAAMxD,WAAWC,UAAUmC,WAAWoB,OAAQ;YAClD,MAAM,IAAIF,MAAM,CAAC,mCAAmC,EAAErD,SAASZ,GAAG,EAAE;QACtE;IACF;AACF,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/terminal/backends/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/terminal/backends/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAO3C,eAAO,MAAM,iBAAiB,EAAE,SAAS,eAAe,EAMvD,CAAC;AAMF,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,YAAY,GAAG,eAAe,GAAG,SAAS,CAElF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ghosttyBackend } from "./ghostty.js";
|
|
1
2
|
import { iterm2Backend } from "./iterm2.js";
|
|
2
3
|
import { terminalAppBackend } from "./terminal-app.js";
|
|
3
4
|
import { tmuxBackend } from "./tmux.js";
|
|
@@ -5,6 +6,7 @@ import { weztermBackend } from "./wezterm.js";
|
|
|
5
6
|
export const TERMINAL_BACKENDS = [
|
|
6
7
|
tmuxBackend,
|
|
7
8
|
weztermBackend,
|
|
9
|
+
ghosttyBackend,
|
|
8
10
|
iterm2Backend,
|
|
9
11
|
terminalAppBackend
|
|
10
12
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/terminal/backends/index.ts"],"sourcesContent":["import type { TerminalBackend } from \"../types.js\";\nimport { TerminalType } from \"../types.js\";\nimport { iterm2Backend } from \"./iterm2.js\";\nimport { terminalAppBackend } from \"./terminal-app.js\";\nimport { tmuxBackend } from \"./tmux.js\";\nimport { weztermBackend } from \"./wezterm.js\";\n\nexport const TERMINAL_BACKENDS: readonly TerminalBackend[] = [\n tmuxBackend,\n weztermBackend,\n iterm2Backend,\n terminalAppBackend,\n];\n\nconst BACKENDS_BY_TYPE = new Map<TerminalType, TerminalBackend>(\n TERMINAL_BACKENDS.map((backend) => [backend.type, backend]),\n);\n\nexport function terminalBackendFor(type: TerminalType): TerminalBackend | undefined {\n return BACKENDS_BY_TYPE.get(type);\n}\n"],"names":["iterm2Backend","terminalAppBackend","tmuxBackend","weztermBackend","TERMINAL_BACKENDS","BACKENDS_BY_TYPE","Map","map","backend","type","terminalBackendFor","get"],"mappings":"AAEA,SAASA,aAAa,QAAQ,cAAc;AAC5C,SAASC,kBAAkB,QAAQ,oBAAoB;AACvD,SAASC,WAAW,QAAQ,YAAY;AACxC,SAASC,cAAc,QAAQ,eAAe;AAE9C,OAAO,MAAMC,oBAAgD;IAC3DF;IACAC;
|
|
1
|
+
{"version":3,"sources":["../../../src/terminal/backends/index.ts"],"sourcesContent":["import type { TerminalBackend } from \"../types.js\";\nimport { TerminalType } from \"../types.js\";\nimport { ghosttyBackend } from \"./ghostty.js\";\nimport { iterm2Backend } from \"./iterm2.js\";\nimport { terminalAppBackend } from \"./terminal-app.js\";\nimport { tmuxBackend } from \"./tmux.js\";\nimport { weztermBackend } from \"./wezterm.js\";\n\nexport const TERMINAL_BACKENDS: readonly TerminalBackend[] = [\n tmuxBackend,\n weztermBackend,\n ghosttyBackend,\n iterm2Backend,\n terminalAppBackend,\n];\n\nconst BACKENDS_BY_TYPE = new Map<TerminalType, TerminalBackend>(\n TERMINAL_BACKENDS.map((backend) => [backend.type, backend]),\n);\n\nexport function terminalBackendFor(type: TerminalType): TerminalBackend | undefined {\n return BACKENDS_BY_TYPE.get(type);\n}\n"],"names":["ghosttyBackend","iterm2Backend","terminalAppBackend","tmuxBackend","weztermBackend","TERMINAL_BACKENDS","BACKENDS_BY_TYPE","Map","map","backend","type","terminalBackendFor","get"],"mappings":"AAEA,SAASA,cAAc,QAAQ,eAAe;AAC9C,SAASC,aAAa,QAAQ,cAAc;AAC5C,SAASC,kBAAkB,QAAQ,oBAAoB;AACvD,SAASC,WAAW,QAAQ,YAAY;AACxC,SAASC,cAAc,QAAQ,eAAe;AAE9C,OAAO,MAAMC,oBAAgD;IAC3DF;IACAC;IACAJ;IACAC;IACAC;CACD,CAAC;AAEF,MAAMI,mBAAmB,IAAIC,IAC3BF,kBAAkBG,GAAG,CAAC,CAACC,UAAY;QAACA,QAAQC,IAAI;QAAED;KAAQ;AAG5D,OAAO,SAASE,mBAAmBD,IAAkB;IACnD,OAAOJ,iBAAiBM,GAAG,CAACF;AAC9B"}
|
|
@@ -3,5 +3,7 @@ export declare const ESCAPE_BYTE = "\u001B";
|
|
|
3
3
|
export declare function sleep(ms: number): Promise<void>;
|
|
4
4
|
export declare function execFileWithInput(command: string, args: string[], input: string): Promise<void>;
|
|
5
5
|
export declare function appleScriptKeyAction(key: string): string;
|
|
6
|
+
/** Whether a `ps` comm value (bare name or full executable path) is `name`. */
|
|
7
|
+
export declare function isProcessName(comm: string, name: string): boolean;
|
|
6
8
|
export declare function isProcessRunning(name: string): Promise<boolean>;
|
|
7
9
|
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../src/terminal/backends/shared.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,eAAe,OAAS,CAAC;AACtC,eAAO,MAAM,WAAW,WAAS,CAAC;AAGlC,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C;AAED,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EAAE,EACd,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC,CAYf;AAED,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAGxD;AAED,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAMrE"}
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../src/terminal/backends/shared.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,eAAe,OAAS,CAAC;AACtC,eAAO,MAAM,WAAW,WAAS,CAAC;AAGlC,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C;AAED,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EAAE,EACd,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC,CAYf;AAED,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAGxD;AAED,+EAA+E;AAC/E,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAEjE;AAED,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAMrE"}
|
|
@@ -24,12 +24,15 @@ export function appleScriptKeyAction(key) {
|
|
|
24
24
|
if (key === ESCAPE_BYTE) return "key code 53";
|
|
25
25
|
return `keystroke "${escapeAppleScript(key)}"`;
|
|
26
26
|
}
|
|
27
|
+
/** Whether a `ps` comm value (bare name or full executable path) is `name`. */ export function isProcessName(comm, name) {
|
|
28
|
+
return comm === name || comm.endsWith(`/${name}`);
|
|
29
|
+
}
|
|
27
30
|
export async function isProcessRunning(name) {
|
|
28
31
|
const { stdout } = await execFileAsync("ps", [
|
|
29
32
|
"-Axo",
|
|
30
33
|
"comm"
|
|
31
34
|
]);
|
|
32
|
-
return stdout.split("\n").map((line)=>line.trim()).some((command)=>command
|
|
35
|
+
return stdout.split("\n").map((line)=>line.trim()).some((command)=>isProcessName(command, name));
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
//# sourceMappingURL=shared.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/terminal/backends/shared.ts"],"sourcesContent":["import { execFile } from \"child_process\";\nimport { promisify } from \"util\";\nimport { escapeAppleScript } from \"../../utils/applescript.js\";\n\nexport const CARRIAGE_RETURN = \"\\x0d\";\nexport const ESCAPE_BYTE = \"\\x1b\";\nconst execFileAsync = promisify(execFile);\n\nexport function sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nexport async function execFileWithInput(\n command: string,\n args: string[],\n input: string,\n): Promise<void> {\n await new Promise<void>((resolve, reject) => {\n const child = execFile(command, args, (error) => {\n if (error) reject(error);\n else resolve();\n });\n if (!child.stdin) {\n reject(new Error(`Cannot write stdin to ${command}`));\n return;\n }\n child.stdin.end(input);\n });\n}\n\nexport function appleScriptKeyAction(key: string): string {\n if (key === ESCAPE_BYTE) return \"key code 53\";\n return `keystroke \"${escapeAppleScript(key)}\"`;\n}\n\nexport async function isProcessRunning(name: string): Promise<boolean> {\n const { stdout } = await execFileAsync(\"ps\", [\"-Axo\", \"comm\"]);\n return stdout\n .split(\"\\n\")\n .map((line) => line.trim())\n .some((command) => command
|
|
1
|
+
{"version":3,"sources":["../../../src/terminal/backends/shared.ts"],"sourcesContent":["import { execFile } from \"child_process\";\nimport { promisify } from \"util\";\nimport { escapeAppleScript } from \"../../utils/applescript.js\";\n\nexport const CARRIAGE_RETURN = \"\\x0d\";\nexport const ESCAPE_BYTE = \"\\x1b\";\nconst execFileAsync = promisify(execFile);\n\nexport function sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nexport async function execFileWithInput(\n command: string,\n args: string[],\n input: string,\n): Promise<void> {\n await new Promise<void>((resolve, reject) => {\n const child = execFile(command, args, (error) => {\n if (error) reject(error);\n else resolve();\n });\n if (!child.stdin) {\n reject(new Error(`Cannot write stdin to ${command}`));\n return;\n }\n child.stdin.end(input);\n });\n}\n\nexport function appleScriptKeyAction(key: string): string {\n if (key === ESCAPE_BYTE) return \"key code 53\";\n return `keystroke \"${escapeAppleScript(key)}\"`;\n}\n\n/** Whether a `ps` comm value (bare name or full executable path) is `name`. */\nexport function isProcessName(comm: string, name: string): boolean {\n return comm === name || comm.endsWith(`/${name}`);\n}\n\nexport async function isProcessRunning(name: string): Promise<boolean> {\n const { stdout } = await execFileAsync(\"ps\", [\"-Axo\", \"comm\"]);\n return stdout\n .split(\"\\n\")\n .map((line) => line.trim())\n .some((command) => isProcessName(command, name));\n}\n"],"names":["execFile","promisify","escapeAppleScript","CARRIAGE_RETURN","ESCAPE_BYTE","execFileAsync","sleep","ms","Promise","resolve","setTimeout","execFileWithInput","command","args","input","reject","child","error","stdin","Error","end","appleScriptKeyAction","key","isProcessName","comm","name","endsWith","isProcessRunning","stdout","split","map","line","trim","some"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,gBAAgB;AACzC,SAASC,SAAS,QAAQ,OAAO;AACjC,SAASC,iBAAiB,QAAQ,6BAA6B;AAE/D,OAAO,MAAMC,kBAAkB,OAAO;AACtC,OAAO,MAAMC,cAAc,OAAO;AAClC,MAAMC,gBAAgBJ,UAAUD;AAEhC,OAAO,SAASM,MAAMC,EAAU;IAC9B,OAAO,IAAIC,QAAQ,CAACC,UAAYC,WAAWD,SAASF;AACtD;AAEA,OAAO,eAAeI,kBACpBC,OAAe,EACfC,IAAc,EACdC,KAAa;IAEb,MAAM,IAAIN,QAAc,CAACC,SAASM;QAChC,MAAMC,QAAQhB,SAASY,SAASC,MAAM,CAACI;YACrC,IAAIA,OAAOF,OAAOE;iBACbR;QACP;QACA,IAAI,CAACO,MAAME,KAAK,EAAE;YAChBH,OAAO,IAAII,MAAM,CAAC,sBAAsB,EAAEP,SAAS;YACnD;QACF;QACAI,MAAME,KAAK,CAACE,GAAG,CAACN;IAClB;AACF;AAEA,OAAO,SAASO,qBAAqBC,GAAW;IAC9C,IAAIA,QAAQlB,aAAa,OAAO;IAChC,OAAO,CAAC,WAAW,EAAEF,kBAAkBoB,KAAK,CAAC,CAAC;AAChD;AAEA,6EAA6E,GAC7E,OAAO,SAASC,cAAcC,IAAY,EAAEC,IAAY;IACtD,OAAOD,SAASC,QAAQD,KAAKE,QAAQ,CAAC,CAAC,CAAC,EAAED,MAAM;AAClD;AAEA,OAAO,eAAeE,iBAAiBF,IAAY;IACjD,MAAM,EAAEG,MAAM,EAAE,GAAG,MAAMvB,cAAc,MAAM;QAAC;QAAQ;KAAO;IAC7D,OAAOuB,OACJC,KAAK,CAAC,MACNC,GAAG,CAAC,CAACC,OAASA,KAAKC,IAAI,IACvBC,IAAI,CAAC,CAACrB,UAAYW,cAAcX,SAASa;AAC9C"}
|
package/dist/terminal/types.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/terminal/types.ts"],"names":[],"mappings":"AAAA,oBAAY,YAAY;IACtB,IAAI,SAAS;IACb,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,YAAY,iBAAiB;IAC7B,OAAO,YAAY;CACpB;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,YAAY,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,YAAY,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;IAC3D,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC;IACpD,KAAK,CAAC,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACpD,IAAI,CAAC,QAAQ,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjE,OAAO,CAAC,QAAQ,EAAE,gBAAgB,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACjE"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/terminal/types.ts"],"names":[],"mappings":"AAAA,oBAAY,YAAY;IACtB,IAAI,SAAS;IACb,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,YAAY,iBAAiB;IAC7B,OAAO,YAAY;CACpB;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,YAAY,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,YAAY,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;IAC3D,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC;IACpD,KAAK,CAAC,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACpD,IAAI,CAAC,QAAQ,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjE,OAAO,CAAC,QAAQ,EAAE,gBAAgB,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACjE"}
|
package/dist/terminal/types.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export var TerminalType = /*#__PURE__*/ function(TerminalType) {
|
|
2
2
|
TerminalType["TMUX"] = "tmux";
|
|
3
3
|
TerminalType["WEZTERM"] = "wezterm";
|
|
4
|
+
TerminalType["GHOSTTY"] = "ghostty";
|
|
4
5
|
TerminalType["ITERM2"] = "iterm2";
|
|
5
6
|
TerminalType["TERMINAL_APP"] = "terminal-app";
|
|
6
7
|
TerminalType["UNKNOWN"] = "unknown";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/terminal/types.ts"],"sourcesContent":["export enum TerminalType {\n TMUX = \"tmux\",\n WEZTERM = \"wezterm\",\n ITERM2 = \"iterm2\",\n TERMINAL_APP = \"terminal-app\",\n UNKNOWN = \"unknown\",\n}\n\nexport interface TerminalLocation {\n type: TerminalType;\n identifier: string;\n tty: string;\n}\n\nexport interface TerminalBackend {\n readonly type: Exclude<TerminalType, TerminalType.UNKNOWN>;\n readonly label: string;\n find(tty: string): Promise<TerminalLocation | null>;\n focus(location: TerminalLocation): Promise<boolean>;\n send(location: TerminalLocation, message: string): Promise<void>;\n sendKey(location: TerminalLocation, key: string): Promise<void>;\n}\n"],"names":["TerminalType"],"mappings":"AAAA,OAAO,IAAA,AAAKA,sCAAAA
|
|
1
|
+
{"version":3,"sources":["../../src/terminal/types.ts"],"sourcesContent":["export enum TerminalType {\n TMUX = \"tmux\",\n WEZTERM = \"wezterm\",\n GHOSTTY = \"ghostty\",\n ITERM2 = \"iterm2\",\n TERMINAL_APP = \"terminal-app\",\n UNKNOWN = \"unknown\",\n}\n\nexport interface TerminalLocation {\n type: TerminalType;\n identifier: string;\n tty: string;\n}\n\nexport interface TerminalBackend {\n readonly type: Exclude<TerminalType, TerminalType.UNKNOWN>;\n readonly label: string;\n find(tty: string): Promise<TerminalLocation | null>;\n focus(location: TerminalLocation): Promise<boolean>;\n send(location: TerminalLocation, message: string): Promise<void>;\n sendKey(location: TerminalLocation, key: string): Promise<void>;\n}\n"],"names":["TerminalType"],"mappings":"AAAA,OAAO,IAAA,AAAKA,sCAAAA;;;;;;;WAAAA;MAOX"}
|
package/dist/utils/process.d.ts
CHANGED
|
@@ -41,6 +41,8 @@ export interface ProcessSnapshotOptions {
|
|
|
41
41
|
isCandidate?: (process: ProcessInfo) => boolean;
|
|
42
42
|
}
|
|
43
43
|
export type ProcessSnapshotCapture = (namePatterns: readonly string[], options?: ProcessSnapshotOptions) => Promise<ProcessInfo[]>;
|
|
44
|
+
/** Working directories of `pids` (async `lsof`); PIDs it cannot read are omitted. */
|
|
45
|
+
export declare function getProcessCwdsAsync(pids: number[]): Promise<Map<number, string>>;
|
|
44
46
|
/**
|
|
45
47
|
* Create a snapshot capture function with its own start-time cache.
|
|
46
48
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../../src/utils/process.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAmB/D;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAWtD;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE1D;AAkCD,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,SAAS,WAAW,EAAE,EACjC,YAAY,EAAE,SAAS,MAAM,EAAE,GAC9B,WAAW,EAAE,CAIf;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,WAAW,EAAE,CA0CrE;AAED,6EAA6E;AAC7E,MAAM,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;AAErF,MAAM,WAAW,sBAAsB;IACrC;;;;OAIG;IACH,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC;CACjD;AAED,MAAM,MAAM,sB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I,GAAE;IAAE,IAAI,CAAC,EAAE,WAAW,CAAA;CAAO,GAChC,sBAAsB,CAwDxB;AAED;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,EAAE,sBAAuD,CAAC;AAE7F;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAuCvE;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAiC3E;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,WAAW,EAAE,GAAG,WAAW,EAAE,CAavE;AAaD,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,WAAW,EAAE,EACxB,KAAK,EAAE,WAAW,GACjB,WAAW,GAAG,SAAS,CAKzB;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,WAAW,EAAE,EACxB,gBAAgB,GAAE,WAAW,EAAO,GACnC,GAAG,CAAC,MAAM,CAAC,CAqBb;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CASjD"}
|
package/dist/utils/process.js
CHANGED
|
@@ -161,6 +161,9 @@ function parseProcessList(output, namePatterns) {
|
|
|
161
161
|
matched
|
|
162
162
|
};
|
|
163
163
|
}
|
|
164
|
+
/** Working directories of `pids` (async `lsof`); PIDs it cannot read are omitted. */ export function getProcessCwdsAsync(pids) {
|
|
165
|
+
return batchGetProcessCwdsAsync(execFileText, pids);
|
|
166
|
+
}
|
|
164
167
|
async function batchGetProcessCwdsAsync(exec, pids) {
|
|
165
168
|
const result = new Map();
|
|
166
169
|
if (pids.length === 0) return result;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/process.ts"],"sourcesContent":["/**\n * Process Detection Utilities\n *\n * Shared shell command wrappers for detecting and inspecting running processes.\n * Built-in refresh discovery uses captureProcessSnapshot(); synchronous helpers\n * remain exported for compatibility with existing consumers.\n */\n\nimport * as fs from \"fs\";\nimport * as path from \"path\";\nimport { execFile, execFileSync } from \"child_process\";\nimport type { ProcessInfo } from \"../adapters/AgentAdapter.js\";\n\nconst PROCESS_EXEC_MAX_BUFFER = 10 * 1024 * 1024;\nconst VALID_EXECUTABLE_NAME = /^[a-zA-Z0-9_-]+$/;\nconst ABSOLUTE_PATH = /^(?:\\/|[a-zA-Z]:[\\\\/])/;\nconst PATH_SEPARATOR = /[\\\\/]/;\n\nfunction pathBasename(executable: string): string {\n return path.basename(executable.replace(/\\\\/g, \"/\")).toLowerCase();\n}\n\nfunction isFile(filePath: string): boolean {\n try {\n return fs.statSync(filePath, { throwIfNoEntry: false })?.isFile() ?? false;\n } catch {\n return false;\n }\n}\n\n/**\n * Resolve argv[0] from a `ps` command line.\n *\n * `ps` joins argv with spaces, so an executable installed under a directory\n * containing spaces (`/Applications/Some App.app/Contents/Resources/codex`)\n * spans several whitespace tokens. When the first token of an absolute path\n * is not itself a file, longer space-joined prefixes ending in a token with a\n * path separator are tried, and the first one that exists on disk wins.\n * Otherwise the first token is returned, so arguments are never folded into\n * the executable path unless that combined path really is a file.\n */\nexport function executablePath(command: string): string {\n const parts = command.trim().split(/(\\s+)/);\n const first = parts[0] ?? \"\";\n if (parts.length === 1 || !ABSOLUTE_PATH.test(first) || isFile(first)) return first;\n\n let prefix = first;\n for (let i = 2; i < parts.length; i += 2) {\n prefix += parts[i - 1] + parts[i];\n if (PATH_SEPARATOR.test(parts[i]) && isFile(prefix)) return prefix;\n }\n return first;\n}\n\nexport function executableBasename(command: string): string {\n return pathBasename(executablePath(command));\n}\n\nfunction normalizeExecutableName(name: string): string {\n const lower = name.toLowerCase();\n return lower.endsWith(\".exe\") ? lower.slice(0, -4) : lower;\n}\n\nfunction normalizedProcessNames(namePatterns: readonly string[]): Set<string> {\n return new Set(namePatterns.filter(Boolean).map(normalizeExecutableName));\n}\n\n/**\n * Whether argv[0] of `command` is one of `names`.\n *\n * The first token is checked with string operations only, as before. The\n * filesystem is consulted only for absolute commands where a later\n * path-like token ends in one of the names, i.e. a possible executable under\n * a directory containing spaces.\n */\nfunction matchesExecutableName(command: string, names: ReadonlySet<string>): boolean {\n const tokens = command.trim().split(/\\s+/);\n const first = tokens[0] ?? \"\";\n if (names.has(normalizeExecutableName(pathBasename(first)))) return true;\n if (!ABSOLUTE_PATH.test(first)) return false;\n\n const mayContinuePath = tokens\n .slice(1)\n .some(\n (token) =>\n PATH_SEPARATOR.test(token) && names.has(normalizeExecutableName(pathBasename(token))),\n );\n return mayContinuePath && names.has(normalizeExecutableName(executableBasename(command)));\n}\n\nexport function filterByProcessNames(\n processes: readonly ProcessInfo[],\n namePatterns: readonly string[],\n): ProcessInfo[] {\n const names = normalizedProcessNames(namePatterns);\n if (names.size === 0) return [];\n return processes.filter((process) => matchesExecutableName(process.command, names));\n}\n\n/**\n * List running processes matching an agent executable name.\n *\n * Uses `ps -axo` then filters in JS for exact executable basename match.\n * This avoids shell pipelines and string interpolation.\n *\n * Returned ProcessInfo has pid, ppid, command, tty populated.\n * cwd and startTime are NOT populated — call enrichProcesses() to fill them.\n */\nexport function listAgentProcesses(namePattern: string): ProcessInfo[] {\n // Validate pattern contains only safe characters (alphanumeric, dash, underscore)\n if (!namePattern || !VALID_EXECUTABLE_NAME.test(namePattern)) {\n return [];\n }\n\n try {\n const output = execFileSync(\"ps\", [\"-axo\", \"pid=,ppid=,tty=,command=\"], { encoding: \"utf-8\" });\n\n const names = normalizedProcessNames([namePattern]);\n const processes: ProcessInfo[] = [];\n\n for (const line of output.trim().split(\"\\n\")) {\n if (!line.trim()) continue;\n\n const match = line.match(/^\\s*(\\d+)\\s+(\\d+)\\s+(\\S+)\\s+(.+)$/);\n if (!match) continue;\n\n const pid = parseInt(match[1], 10);\n const ppid = parseInt(match[2], 10);\n if (Number.isNaN(pid) || Number.isNaN(ppid)) continue;\n\n const tty = match[3];\n const command = match[4];\n\n if (!matchesExecutableName(command, names)) continue;\n\n const ttyShort = tty.startsWith(\"/dev/\") ? tty.slice(5) : tty;\n\n processes.push({\n pid,\n ppid,\n command,\n cwd: \"\",\n tty: ttyShort,\n });\n }\n\n return processes;\n } catch {\n return [];\n }\n}\n\n/** Runs an executable and resolves with its stdout. Injectable for tests. */\nexport type ProcessExec = (file: string, args: readonly string[]) => Promise<string>;\n\nexport interface ProcessSnapshotOptions {\n /**\n * Decides which name-matched processes are worth enriching with cwd and\n * start time. Non-candidates are still returned (pid, ppid, tty, command\n * only) so adapters can walk parent chains. Omitted = enrich everything.\n */\n isCandidate?: (process: ProcessInfo) => boolean;\n}\n\nexport type ProcessSnapshotCapture = (\n namePatterns: readonly string[],\n options?: ProcessSnapshotOptions,\n) => Promise<ProcessInfo[]>;\n\nconst execFileText: ProcessExec = (file, args) =>\n new Promise((resolve, reject) => {\n execFile(\n file,\n args,\n { encoding: \"utf-8\", maxBuffer: PROCESS_EXEC_MAX_BUFFER },\n (error, stdout) => {\n if (error) {\n reject(error);\n return;\n }\n resolve(stdout);\n },\n );\n });\n\ninterface ParsedProcessList {\n /** Every PID in the listing, used to evict cache entries for exited processes. */\n allPids: Set<number>;\n /** Processes whose executable matches one of the requested names. */\n matched: ProcessInfo[];\n}\n\nfunction parseProcessList(output: string, namePatterns: ReadonlySet<string>): ParsedProcessList {\n const allPids = new Set<number>();\n const matched: ProcessInfo[] = [];\n\n for (const line of output.trim().split(\"\\n\")) {\n if (!line.trim()) continue;\n\n const match = line.match(/^\\s*(\\d+)\\s+(\\d+)\\s+(\\S+)\\s+(.+)$/);\n if (!match) continue;\n\n const pid = parseInt(match[1], 10);\n const ppid = parseInt(match[2], 10);\n if (Number.isNaN(pid) || Number.isNaN(ppid)) continue;\n allPids.add(pid);\n\n const tty = match[3];\n const command = match[4];\n if (!matchesExecutableName(command, namePatterns)) continue;\n\n matched.push({\n pid,\n ppid,\n command,\n cwd: \"\",\n tty: tty.startsWith(\"/dev/\") ? tty.slice(5) : tty,\n });\n }\n\n return { allPids, matched };\n}\n\nasync function batchGetProcessCwdsAsync(\n exec: ProcessExec,\n pids: number[],\n): Promise<Map<number, string>> {\n const result = new Map<number, string>();\n if (pids.length === 0) return result;\n\n try {\n const output = await exec(\"lsof\", [\"-a\", \"-d\", \"cwd\", \"-Fn\", \"-p\", pids.join(\",\")]);\n let currentPid: number | null = null;\n for (const line of output.trim().split(\"\\n\")) {\n if (line.startsWith(\"p\")) {\n currentPid = parseInt(line.slice(1), 10);\n } else if (line.startsWith(\"n\") && currentPid !== null) {\n result.set(currentPid, line.slice(1));\n currentPid = null;\n }\n }\n return result;\n } catch {\n const entries = await Promise.all(\n pids.map(async (pid) => {\n try {\n const output = await exec(\"pwdx\", [String(pid)]);\n const match = output.match(/^\\d+:\\s*(.+)$/);\n return match ? ([pid, match[1].trim()] as const) : null;\n } catch {\n return null;\n }\n }),\n );\n for (const entry of entries) {\n if (entry) result.set(entry[0], entry[1]);\n }\n return result;\n }\n}\n\nasync function batchGetProcessStartTimesAsync(\n exec: ProcessExec,\n pids: number[],\n): Promise<Map<number, Date>> {\n const result = new Map<number, Date>();\n if (pids.length === 0) return result;\n\n try {\n const output = await exec(\"ps\", [\"-o\", \"pid=,lstart=\", \"-p\", pids.join(\",\")]);\n for (const rawLine of output.split(\"\\n\")) {\n const match = rawLine.trim().match(/^(\\d+)\\s+(.+)$/);\n if (!match) continue;\n const pid = parseInt(match[1], 10);\n const date = new Date(match[2].trim());\n if (Number.isFinite(pid) && !Number.isNaN(date.getTime())) result.set(pid, date);\n }\n } catch {\n // Return partial/empty data, matching the synchronous helper.\n }\n return result;\n}\n\ninterface CachedStartTime {\n /** ppid + command seen when the start time was read; a mismatch means PID reuse. */\n identity: string;\n startTime: Date;\n}\n\nfunction processIdentity(process: ProcessInfo): string {\n return `${process.ppid ?? \"\"}\\0${process.command}`;\n}\n\n/**\n * Create a snapshot capture function with its own start-time cache.\n *\n * Start times never change for a live process, so each PID is queried with\n * `ps lstart` once and reused on later refreshes. A cache entry is dropped\n * when its PID disappears from the base listing, and ignored when the PID's\n * ppid/command no longer match (PID reuse). cwd is re-read every refresh\n * because a process can change directory.\n */\nexport function createProcessSnapshotCapture(\n deps: { exec?: ProcessExec } = {},\n): ProcessSnapshotCapture {\n const exec = deps.exec ?? execFileText;\n const startTimeCache = new Map<number, CachedStartTime>();\n\n const cachedStartTime = (process: ProcessInfo): Date | undefined => {\n const cached = startTimeCache.get(process.pid);\n return cached?.identity === processIdentity(process) ? cached.startTime : undefined;\n };\n\n return async (namePatterns, options = {}) => {\n const names = normalizedProcessNames(\n namePatterns.filter((name) => Boolean(name) && VALID_EXECUTABLE_NAME.test(name)),\n );\n if (names.size === 0) return [];\n\n try {\n const output = await exec(\"ps\", [\"-axo\", \"pid=,ppid=,tty=,command=\"]);\n const { allPids, matched } = parseProcessList(output, names);\n\n for (const pid of startTimeCache.keys()) {\n if (!allPids.has(pid)) startTimeCache.delete(pid);\n }\n\n const { isCandidate } = options;\n const candidates = isCandidate ? matched.filter((process) => isCandidate(process)) : matched;\n const candidatePids = candidates.map((process) => process.pid);\n const uncachedPids = candidates\n .filter((process) => cachedStartTime(process) === undefined)\n .map((process) => process.pid);\n\n const [cwdMap, startTimeMap] = await Promise.all([\n batchGetProcessCwdsAsync(exec, candidatePids),\n batchGetProcessStartTimesAsync(exec, uncachedPids),\n ]);\n\n for (const process of candidates) {\n const startTime = startTimeMap.get(process.pid);\n if (startTime) {\n startTimeCache.set(process.pid, { identity: processIdentity(process), startTime });\n }\n }\n\n const candidateSet = new Set(candidatePids);\n return matched.map((process) =>\n candidateSet.has(process.pid)\n ? {\n ...process,\n cwd: cwdMap.get(process.pid) || \"\",\n startTime: cachedStartTime(process),\n }\n : process,\n );\n } catch {\n return [];\n }\n };\n}\n\n/**\n * Capture and enrich relevant processes without blocking the event loop.\n * One base process listing is shared by every requested executable name;\n * only processes accepted by `options.isCandidate` are enriched.\n */\nexport const captureProcessSnapshot: ProcessSnapshotCapture = createProcessSnapshotCapture();\n\n/**\n * Batch-get current working directories for multiple PIDs.\n *\n * Single `lsof -a -d cwd -Fn -p PID1,PID2,...` call.\n * Returns partial results — if lsof fails for one PID, others still return.\n */\nexport function batchGetProcessCwds(pids: number[]): Map<number, string> {\n const result = new Map<number, string>();\n if (pids.length === 0) return result;\n\n try {\n const output = execFileSync(\"lsof\", [\"-a\", \"-d\", \"cwd\", \"-Fn\", \"-p\", pids.join(\",\")], {\n encoding: \"utf-8\",\n stdio: [\"pipe\", \"pipe\", \"ignore\"],\n });\n\n // lsof output format: p{PID}\\nn{path}\\np{PID}\\nn{path}...\n let currentPid: number | null = null;\n for (const line of output.trim().split(\"\\n\")) {\n if (line.startsWith(\"p\")) {\n currentPid = parseInt(line.slice(1), 10);\n } else if (line.startsWith(\"n\") && currentPid !== null) {\n result.set(currentPid, line.slice(1));\n currentPid = null;\n }\n }\n } catch {\n // Try per-PID fallback with pwdx (Linux)\n for (const pid of pids) {\n try {\n const output = execFileSync(\"pwdx\", [String(pid)], {\n encoding: \"utf-8\",\n stdio: [\"pipe\", \"pipe\", \"ignore\"],\n });\n const match = output.match(/^\\d+:\\s*(.+)$/);\n if (match) {\n result.set(pid, match[1].trim());\n }\n } catch {\n // Skip this PID\n }\n }\n }\n\n return result;\n}\n\n/**\n * Batch-get process start times for multiple PIDs.\n *\n * Single `ps -o pid=,lstart= -p PID1,PID2,...` call.\n * Uses lstart format which gives full timestamp (e.g., \"Thu Feb 5 16:00:57 2026\").\n * Returns partial results.\n */\nexport function batchGetProcessStartTimes(pids: number[]): Map<number, Date> {\n const result = new Map<number, Date>();\n if (pids.length === 0) return result;\n\n try {\n const output = execFileSync(\"ps\", [\"-o\", \"pid=,lstart=\", \"-p\", pids.join(\",\")], {\n encoding: \"utf-8\",\n });\n\n for (const rawLine of output.split(\"\\n\")) {\n const line = rawLine.trim();\n if (!line) continue;\n\n // Format: \" PID DAY MON DD HH:MM:SS YYYY\"\n // e.g., \" 78070 Wed Mar 18 23:18:01 2026\"\n const match = line.match(/^\\s*(\\d+)\\s+(.+)$/);\n if (!match) continue;\n\n const pid = parseInt(match[1], 10);\n const dateStr = match[2].trim();\n\n if (!Number.isFinite(pid)) continue;\n\n const date = new Date(dateStr);\n if (!Number.isNaN(date.getTime())) {\n result.set(pid, date);\n }\n }\n } catch {\n // Return whatever we have\n }\n\n return result;\n}\n\n/**\n * Enrich ProcessInfo array with cwd and startTime.\n *\n * Calls batchGetProcessCwds and batchGetProcessStartTimes in batched shell calls,\n * then populates each ProcessInfo in-place. Returns partial results —\n * if a PID fails, that process keeps empty cwd / undefined startTime.\n */\nexport function enrichProcesses(processes: ProcessInfo[]): ProcessInfo[] {\n if (processes.length === 0) return processes;\n\n const pids = processes.map((p) => p.pid);\n const cwdMap = batchGetProcessCwds(pids);\n const startTimeMap = batchGetProcessStartTimes(pids);\n\n for (const proc of processes) {\n proc.cwd = cwdMap.get(proc.pid) || \"\";\n proc.startTime = startTimeMap.get(proc.pid);\n }\n\n return processes;\n}\n\nfunction isSameTerminalProcess(proc: ProcessInfo, matched: ProcessInfo): boolean {\n const sameTty = proc.tty !== \"\" && proc.tty !== \"?\" && proc.tty === matched.tty;\n const sameCwd = proc.cwd !== \"\" && proc.cwd === matched.cwd;\n\n return sameTty && (sameCwd || proc.cwd === \"\" || matched.cwd === \"\");\n}\n\nfunction matchesProcessIdentity(proc: ProcessInfo, matched: ProcessInfo): boolean {\n return proc.pid === matched.pid || isSameTerminalProcess(proc, matched);\n}\n\nexport function findWrapperProcess(\n processes: ProcessInfo[],\n child: ProcessInfo,\n): ProcessInfo | undefined {\n return processes.find(\n (proc) =>\n proc.pid !== child.pid && child.ppid === proc.pid && matchesProcessIdentity(proc, child),\n );\n}\n\n/**\n * Find parent wrapper processes that should not be reported as separate agents.\n *\n * A process is considered a wrapper when it is the parent of another candidate\n * agent process in the same terminal/worktree, or when it points at the same\n * terminal/worktree as an already session-matched process.\n */\nexport function findWrapperProcessPids(\n processes: ProcessInfo[],\n matchedProcesses: ProcessInfo[] = [],\n): Set<number> {\n const wrappers = new Set<number>();\n\n for (const child of processes) {\n const wrapper = findWrapperProcess(processes, child);\n if (wrapper) {\n wrappers.add(wrapper.pid);\n }\n }\n\n for (const proc of processes) {\n if (\n matchedProcesses.some(\n (matched) => proc.pid !== matched.pid && isSameTerminalProcess(proc, matched),\n )\n ) {\n wrappers.add(proc.pid);\n }\n }\n\n return wrappers;\n}\n\n/**\n * Get the TTY device for a specific process\n */\nexport function getProcessTty(pid: number): string {\n try {\n const output = execFileSync(\"ps\", [\"-p\", String(pid), \"-o\", \"tty=\"], { encoding: \"utf-8\" });\n\n const tty = output.trim();\n return tty.startsWith(\"/dev/\") ? tty.slice(5) : tty;\n } catch {\n return \"?\";\n }\n}\n"],"names":["fs","path","execFile","execFileSync","PROCESS_EXEC_MAX_BUFFER","VALID_EXECUTABLE_NAME","ABSOLUTE_PATH","PATH_SEPARATOR","pathBasename","executable","basename","replace","toLowerCase","isFile","filePath","statSync","throwIfNoEntry","executablePath","command","parts","trim","split","first","length","test","prefix","i","executableBasename","normalizeExecutableName","name","lower","endsWith","slice","normalizedProcessNames","namePatterns","Set","filter","Boolean","map","matchesExecutableName","names","tokens","has","mayContinuePath","some","token","filterByProcessNames","processes","size","process","listAgentProcesses","namePattern","output","encoding","line","match","pid","parseInt","ppid","Number","isNaN","tty","ttyShort","startsWith","push","cwd","execFileText","file","args","Promise","resolve","reject","maxBuffer","error","stdout","parseProcessList","allPids","matched","add","batchGetProcessCwdsAsync","exec","pids","result","Map","join","currentPid","set","entries","all","String","entry","batchGetProcessStartTimesAsync","rawLine","date","Date","isFinite","getTime","processIdentity","createProcessSnapshotCapture","deps","startTimeCache","cachedStartTime","cached","get","identity","startTime","undefined","options","keys","delete","isCandidate","candidates","candidatePids","uncachedPids","cwdMap","startTimeMap","candidateSet","captureProcessSnapshot","batchGetProcessCwds","stdio","batchGetProcessStartTimes","dateStr","enrichProcesses","p","proc","isSameTerminalProcess","sameTty","sameCwd","matchesProcessIdentity","findWrapperProcess","child","find","findWrapperProcessPids","matchedProcesses","wrappers","wrapper","getProcessTty"],"mappings":"AAAA;;;;;;CAMC,GAED,YAAYA,QAAQ,KAAK;AACzB,YAAYC,UAAU,OAAO;AAC7B,SAASC,QAAQ,EAAEC,YAAY,QAAQ,gBAAgB;AAGvD,MAAMC,0BAA0B,KAAK,OAAO;AAC5C,MAAMC,wBAAwB;AAC9B,MAAMC,gBAAgB;AACtB,MAAMC,iBAAiB;AAEvB,SAASC,aAAaC,UAAkB;IACtC,OAAOR,KAAKS,QAAQ,CAACD,WAAWE,OAAO,CAAC,OAAO,MAAMC,WAAW;AAClE;AAEA,SAASC,OAAOC,QAAgB;IAC9B,IAAI;QACF,OAAOd,GAAGe,QAAQ,CAACD,UAAU;YAAEE,gBAAgB;QAAM,IAAIH,YAAY;IACvE,EAAE,OAAM;QACN,OAAO;IACT;AACF;AAEA;;;;;;;;;;CAUC,GACD,OAAO,SAASI,eAAeC,OAAe;IAC5C,MAAMC,QAAQD,QAAQE,IAAI,GAAGC,KAAK,CAAC;IACnC,MAAMC,QAAQH,KAAK,CAAC,EAAE,IAAI;IAC1B,IAAIA,MAAMI,MAAM,KAAK,KAAK,CAACjB,cAAckB,IAAI,CAACF,UAAUT,OAAOS,QAAQ,OAAOA;IAE9E,IAAIG,SAASH;IACb,IAAK,IAAII,IAAI,GAAGA,IAAIP,MAAMI,MAAM,EAAEG,KAAK,EAAG;QACxCD,UAAUN,KAAK,CAACO,IAAI,EAAE,GAAGP,KAAK,CAACO,EAAE;QACjC,IAAInB,eAAeiB,IAAI,CAACL,KAAK,CAACO,EAAE,KAAKb,OAAOY,SAAS,OAAOA;IAC9D;IACA,OAAOH;AACT;AAEA,OAAO,SAASK,mBAAmBT,OAAe;IAChD,OAAOV,aAAaS,eAAeC;AACrC;AAEA,SAASU,wBAAwBC,IAAY;IAC3C,MAAMC,QAAQD,KAAKjB,WAAW;IAC9B,OA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AKpE,GAAG,KAAKqB,QAAQrB,GAAG,IAAIqE,sBAAsBD,MAAM/C,WAEvE;YACAyD,SAASxD,GAAG,CAAC8C,KAAKpE,GAAG;QACvB;IACF;IAEA,OAAO8E;AACT;AAEA;;CAEC,GACD,OAAO,SAASE,cAAchF,GAAW;IACvC,IAAI;QACF,MAAMJ,SAASjD,aAAa,MAAM;YAAC;YAAMsF,OAAOjC;YAAM;YAAM;SAAO,EAAE;YAAEH,UAAU;QAAQ;QAEzF,MAAMQ,MAAMT,OAAOhC,IAAI;QACvB,OAAOyC,IAAIE,UAAU,CAAC,WAAWF,IAAI7B,KAAK,CAAC,KAAK6B;IAClD,EAAE,OAAM;QACN,OAAO;IACT;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/process.ts"],"sourcesContent":["/**\n * Process Detection Utilities\n *\n * Shared shell command wrappers for detecting and inspecting running processes.\n * Built-in refresh discovery uses captureProcessSnapshot(); synchronous helpers\n * remain exported for compatibility with existing consumers.\n */\n\nimport * as fs from \"fs\";\nimport * as path from \"path\";\nimport { execFile, execFileSync } from \"child_process\";\nimport type { ProcessInfo } from \"../adapters/AgentAdapter.js\";\n\nconst PROCESS_EXEC_MAX_BUFFER = 10 * 1024 * 1024;\nconst VALID_EXECUTABLE_NAME = /^[a-zA-Z0-9_-]+$/;\nconst ABSOLUTE_PATH = /^(?:\\/|[a-zA-Z]:[\\\\/])/;\nconst PATH_SEPARATOR = /[\\\\/]/;\n\nfunction pathBasename(executable: string): string {\n return path.basename(executable.replace(/\\\\/g, \"/\")).toLowerCase();\n}\n\nfunction isFile(filePath: string): boolean {\n try {\n return fs.statSync(filePath, { throwIfNoEntry: false })?.isFile() ?? false;\n } catch {\n return false;\n }\n}\n\n/**\n * Resolve argv[0] from a `ps` command line.\n *\n * `ps` joins argv with spaces, so an executable installed under a directory\n * containing spaces (`/Applications/Some App.app/Contents/Resources/codex`)\n * spans several whitespace tokens. When the first token of an absolute path\n * is not itself a file, longer space-joined prefixes ending in a token with a\n * path separator are tried, and the first one that exists on disk wins.\n * Otherwise the first token is returned, so arguments are never folded into\n * the executable path unless that combined path really is a file.\n */\nexport function executablePath(command: string): string {\n const parts = command.trim().split(/(\\s+)/);\n const first = parts[0] ?? \"\";\n if (parts.length === 1 || !ABSOLUTE_PATH.test(first) || isFile(first)) return first;\n\n let prefix = first;\n for (let i = 2; i < parts.length; i += 2) {\n prefix += parts[i - 1] + parts[i];\n if (PATH_SEPARATOR.test(parts[i]) && isFile(prefix)) return prefix;\n }\n return first;\n}\n\nexport function executableBasename(command: string): string {\n return pathBasename(executablePath(command));\n}\n\nfunction normalizeExecutableName(name: string): string {\n const lower = name.toLowerCase();\n return lower.endsWith(\".exe\") ? lower.slice(0, -4) : lower;\n}\n\nfunction normalizedProcessNames(namePatterns: readonly string[]): Set<string> {\n return new Set(namePatterns.filter(Boolean).map(normalizeExecutableName));\n}\n\n/**\n * Whether argv[0] of `command` is one of `names`.\n *\n * The first token is checked with string operations only, as before. The\n * filesystem is consulted only for absolute commands where a later\n * path-like token ends in one of the names, i.e. a possible executable under\n * a directory containing spaces.\n */\nfunction matchesExecutableName(command: string, names: ReadonlySet<string>): boolean {\n const tokens = command.trim().split(/\\s+/);\n const first = tokens[0] ?? \"\";\n if (names.has(normalizeExecutableName(pathBasename(first)))) return true;\n if (!ABSOLUTE_PATH.test(first)) return false;\n\n const mayContinuePath = tokens\n .slice(1)\n .some(\n (token) =>\n PATH_SEPARATOR.test(token) && names.has(normalizeExecutableName(pathBasename(token))),\n );\n return mayContinuePath && names.has(normalizeExecutableName(executableBasename(command)));\n}\n\nexport function filterByProcessNames(\n processes: readonly ProcessInfo[],\n namePatterns: readonly string[],\n): ProcessInfo[] {\n const names = normalizedProcessNames(namePatterns);\n if (names.size === 0) return [];\n return processes.filter((process) => matchesExecutableName(process.command, names));\n}\n\n/**\n * List running processes matching an agent executable name.\n *\n * Uses `ps -axo` then filters in JS for exact executable basename match.\n * This avoids shell pipelines and string interpolation.\n *\n * Returned ProcessInfo has pid, ppid, command, tty populated.\n * cwd and startTime are NOT populated — call enrichProcesses() to fill them.\n */\nexport function listAgentProcesses(namePattern: string): ProcessInfo[] {\n // Validate pattern contains only safe characters (alphanumeric, dash, underscore)\n if (!namePattern || !VALID_EXECUTABLE_NAME.test(namePattern)) {\n return [];\n }\n\n try {\n const output = execFileSync(\"ps\", [\"-axo\", \"pid=,ppid=,tty=,command=\"], { encoding: \"utf-8\" });\n\n const names = normalizedProcessNames([namePattern]);\n const processes: ProcessInfo[] = [];\n\n for (const line of output.trim().split(\"\\n\")) {\n if (!line.trim()) continue;\n\n const match = line.match(/^\\s*(\\d+)\\s+(\\d+)\\s+(\\S+)\\s+(.+)$/);\n if (!match) continue;\n\n const pid = parseInt(match[1], 10);\n const ppid = parseInt(match[2], 10);\n if (Number.isNaN(pid) || Number.isNaN(ppid)) continue;\n\n const tty = match[3];\n const command = match[4];\n\n if (!matchesExecutableName(command, names)) continue;\n\n const ttyShort = tty.startsWith(\"/dev/\") ? tty.slice(5) : tty;\n\n processes.push({\n pid,\n ppid,\n command,\n cwd: \"\",\n tty: ttyShort,\n });\n }\n\n return processes;\n } catch {\n return [];\n }\n}\n\n/** Runs an executable and resolves with its stdout. Injectable for tests. */\nexport type ProcessExec = (file: string, args: readonly string[]) => Promise<string>;\n\nexport interface ProcessSnapshotOptions {\n /**\n * Decides which name-matched processes are worth enriching with cwd and\n * start time. Non-candidates are still returned (pid, ppid, tty, command\n * only) so adapters can walk parent chains. Omitted = enrich everything.\n */\n isCandidate?: (process: ProcessInfo) => boolean;\n}\n\nexport type ProcessSnapshotCapture = (\n namePatterns: readonly string[],\n options?: ProcessSnapshotOptions,\n) => Promise<ProcessInfo[]>;\n\nconst execFileText: ProcessExec = (file, args) =>\n new Promise((resolve, reject) => {\n execFile(\n file,\n args,\n { encoding: \"utf-8\", maxBuffer: PROCESS_EXEC_MAX_BUFFER },\n (error, stdout) => {\n if (error) {\n reject(error);\n return;\n }\n resolve(stdout);\n },\n );\n });\n\ninterface ParsedProcessList {\n /** Every PID in the listing, used to evict cache entries for exited processes. */\n allPids: Set<number>;\n /** Processes whose executable matches one of the requested names. */\n matched: ProcessInfo[];\n}\n\nfunction parseProcessList(output: string, namePatterns: ReadonlySet<string>): ParsedProcessList {\n const allPids = new Set<number>();\n const matched: ProcessInfo[] = [];\n\n for (const line of output.trim().split(\"\\n\")) {\n if (!line.trim()) continue;\n\n const match = line.match(/^\\s*(\\d+)\\s+(\\d+)\\s+(\\S+)\\s+(.+)$/);\n if (!match) continue;\n\n const pid = parseInt(match[1], 10);\n const ppid = parseInt(match[2], 10);\n if (Number.isNaN(pid) || Number.isNaN(ppid)) continue;\n allPids.add(pid);\n\n const tty = match[3];\n const command = match[4];\n if (!matchesExecutableName(command, namePatterns)) continue;\n\n matched.push({\n pid,\n ppid,\n command,\n cwd: \"\",\n tty: tty.startsWith(\"/dev/\") ? tty.slice(5) : tty,\n });\n }\n\n return { allPids, matched };\n}\n\n/** Working directories of `pids` (async `lsof`); PIDs it cannot read are omitted. */\nexport function getProcessCwdsAsync(pids: number[]): Promise<Map<number, string>> {\n return batchGetProcessCwdsAsync(execFileText, pids);\n}\n\nasync function batchGetProcessCwdsAsync(\n exec: ProcessExec,\n pids: number[],\n): Promise<Map<number, string>> {\n const result = new Map<number, string>();\n if (pids.length === 0) return result;\n\n try {\n const output = await exec(\"lsof\", [\"-a\", \"-d\", \"cwd\", \"-Fn\", \"-p\", pids.join(\",\")]);\n let currentPid: number | null = null;\n for (const line of output.trim().split(\"\\n\")) {\n if (line.startsWith(\"p\")) {\n currentPid = parseInt(line.slice(1), 10);\n } else if (line.startsWith(\"n\") && currentPid !== null) {\n result.set(currentPid, line.slice(1));\n currentPid = null;\n }\n }\n return result;\n } catch {\n const entries = await Promise.all(\n pids.map(async (pid) => {\n try {\n const output = await exec(\"pwdx\", [String(pid)]);\n const match = output.match(/^\\d+:\\s*(.+)$/);\n return match ? ([pid, match[1].trim()] as const) : null;\n } catch {\n return null;\n }\n }),\n );\n for (const entry of entries) {\n if (entry) result.set(entry[0], entry[1]);\n }\n return result;\n }\n}\n\nasync function batchGetProcessStartTimesAsync(\n exec: ProcessExec,\n pids: number[],\n): Promise<Map<number, Date>> {\n const result = new Map<number, Date>();\n if (pids.length === 0) return result;\n\n try {\n const output = await exec(\"ps\", [\"-o\", \"pid=,lstart=\", \"-p\", pids.join(\",\")]);\n for (const rawLine of output.split(\"\\n\")) {\n const match = rawLine.trim().match(/^(\\d+)\\s+(.+)$/);\n if (!match) continue;\n const pid = parseInt(match[1], 10);\n const date = new Date(match[2].trim());\n if (Number.isFinite(pid) && !Number.isNaN(date.getTime())) result.set(pid, date);\n }\n } catch {\n // Return partial/empty data, matching the synchronous helper.\n }\n return result;\n}\n\ninterface CachedStartTime {\n /** ppid + command seen when the start time was read; a mismatch means PID reuse. */\n identity: string;\n startTime: Date;\n}\n\nfunction processIdentity(process: ProcessInfo): string {\n return `${process.ppid ?? \"\"}\\0${process.command}`;\n}\n\n/**\n * Create a snapshot capture function with its own start-time cache.\n *\n * Start times never change for a live process, so each PID is queried with\n * `ps lstart` once and reused on later refreshes. A cache entry is dropped\n * when its PID disappears from the base listing, and ignored when the PID's\n * ppid/command no longer match (PID reuse). cwd is re-read every refresh\n * because a process can change directory.\n */\nexport function createProcessSnapshotCapture(\n deps: { exec?: ProcessExec } = {},\n): ProcessSnapshotCapture {\n const exec = deps.exec ?? execFileText;\n const startTimeCache = new Map<number, CachedStartTime>();\n\n const cachedStartTime = (process: ProcessInfo): Date | undefined => {\n const cached = startTimeCache.get(process.pid);\n return cached?.identity === processIdentity(process) ? cached.startTime : undefined;\n };\n\n return async (namePatterns, options = {}) => {\n const names = normalizedProcessNames(\n namePatterns.filter((name) => Boolean(name) && VALID_EXECUTABLE_NAME.test(name)),\n );\n if (names.size === 0) return [];\n\n try {\n const output = await exec(\"ps\", [\"-axo\", \"pid=,ppid=,tty=,command=\"]);\n const { allPids, matched } = parseProcessList(output, names);\n\n for (const pid of startTimeCache.keys()) {\n if (!allPids.has(pid)) startTimeCache.delete(pid);\n }\n\n const { isCandidate } = options;\n const candidates = isCandidate ? matched.filter((process) => isCandidate(process)) : matched;\n const candidatePids = candidates.map((process) => process.pid);\n const uncachedPids = candidates\n .filter((process) => cachedStartTime(process) === undefined)\n .map((process) => process.pid);\n\n const [cwdMap, startTimeMap] = await Promise.all([\n batchGetProcessCwdsAsync(exec, candidatePids),\n batchGetProcessStartTimesAsync(exec, uncachedPids),\n ]);\n\n for (const process of candidates) {\n const startTime = startTimeMap.get(process.pid);\n if (startTime) {\n startTimeCache.set(process.pid, { identity: processIdentity(process), startTime });\n }\n }\n\n const candidateSet = new Set(candidatePids);\n return matched.map((process) =>\n candidateSet.has(process.pid)\n ? {\n ...process,\n cwd: cwdMap.get(process.pid) || \"\",\n startTime: cachedStartTime(process),\n }\n : process,\n );\n } catch {\n return [];\n }\n };\n}\n\n/**\n * Capture and enrich relevant processes without blocking the event loop.\n * One base process listing is shared by every requested executable name;\n * only processes accepted by `options.isCandidate` are enriched.\n */\nexport const captureProcessSnapshot: ProcessSnapshotCapture = createProcessSnapshotCapture();\n\n/**\n * Batch-get current working directories for multiple PIDs.\n *\n * Single `lsof -a -d cwd -Fn -p PID1,PID2,...` call.\n * Returns partial results — if lsof fails for one PID, others still return.\n */\nexport function batchGetProcessCwds(pids: number[]): Map<number, string> {\n const result = new Map<number, string>();\n if (pids.length === 0) return result;\n\n try {\n const output = execFileSync(\"lsof\", [\"-a\", \"-d\", \"cwd\", \"-Fn\", \"-p\", pids.join(\",\")], {\n encoding: \"utf-8\",\n stdio: [\"pipe\", \"pipe\", \"ignore\"],\n });\n\n // lsof output format: p{PID}\\nn{path}\\np{PID}\\nn{path}...\n let currentPid: number | null = null;\n for (const line of output.trim().split(\"\\n\")) {\n if (line.startsWith(\"p\")) {\n currentPid = parseInt(line.slice(1), 10);\n } else if (line.startsWith(\"n\") && currentPid !== null) {\n result.set(currentPid, line.slice(1));\n currentPid = null;\n }\n }\n } catch {\n // Try per-PID fallback with pwdx (Linux)\n for (const pid of pids) {\n try {\n const output = execFileSync(\"pwdx\", [String(pid)], {\n encoding: \"utf-8\",\n stdio: [\"pipe\", \"pipe\", \"ignore\"],\n });\n const match = output.match(/^\\d+:\\s*(.+)$/);\n if (match) {\n result.set(pid, match[1].trim());\n }\n } catch {\n // Skip this PID\n }\n }\n }\n\n return result;\n}\n\n/**\n * Batch-get process start times for multiple PIDs.\n *\n * Single `ps -o pid=,lstart= -p PID1,PID2,...` call.\n * Uses lstart format which gives full timestamp (e.g., \"Thu Feb 5 16:00:57 2026\").\n * Returns partial results.\n */\nexport function batchGetProcessStartTimes(pids: number[]): Map<number, Date> {\n const result = new Map<number, Date>();\n if (pids.length === 0) return result;\n\n try {\n const output = execFileSync(\"ps\", [\"-o\", \"pid=,lstart=\", \"-p\", pids.join(\",\")], {\n encoding: \"utf-8\",\n });\n\n for (const rawLine of output.split(\"\\n\")) {\n const line = rawLine.trim();\n if (!line) continue;\n\n // Format: \" PID DAY MON DD HH:MM:SS YYYY\"\n // e.g., \" 78070 Wed Mar 18 23:18:01 2026\"\n const match = line.match(/^\\s*(\\d+)\\s+(.+)$/);\n if (!match) continue;\n\n const pid = parseInt(match[1], 10);\n const dateStr = match[2].trim();\n\n if (!Number.isFinite(pid)) continue;\n\n const date = new Date(dateStr);\n if (!Number.isNaN(date.getTime())) {\n result.set(pid, date);\n }\n }\n } catch {\n // Return whatever we have\n }\n\n return result;\n}\n\n/**\n * Enrich ProcessInfo array with cwd and startTime.\n *\n * Calls batchGetProcessCwds and batchGetProcessStartTimes in batched shell calls,\n * then populates each ProcessInfo in-place. Returns partial results —\n * if a PID fails, that process keeps empty cwd / undefined startTime.\n */\nexport function enrichProcesses(processes: ProcessInfo[]): ProcessInfo[] {\n if (processes.length === 0) return processes;\n\n const pids = processes.map((p) => p.pid);\n const cwdMap = batchGetProcessCwds(pids);\n const startTimeMap = batchGetProcessStartTimes(pids);\n\n for (const proc of processes) {\n proc.cwd = cwdMap.get(proc.pid) || \"\";\n proc.startTime = startTimeMap.get(proc.pid);\n }\n\n return processes;\n}\n\nfunction isSameTerminalProcess(proc: ProcessInfo, matched: ProcessInfo): boolean {\n const sameTty = proc.tty !== \"\" && proc.tty !== \"?\" && proc.tty === matched.tty;\n const sameCwd = proc.cwd !== \"\" && proc.cwd === matched.cwd;\n\n return sameTty && (sameCwd || proc.cwd === \"\" || matched.cwd === \"\");\n}\n\nfunction matchesProcessIdentity(proc: ProcessInfo, matched: ProcessInfo): boolean {\n return proc.pid === matched.pid || isSameTerminalProcess(proc, matched);\n}\n\nexport function findWrapperProcess(\n processes: ProcessInfo[],\n child: ProcessInfo,\n): ProcessInfo | undefined {\n return processes.find(\n (proc) =>\n proc.pid !== child.pid && child.ppid === proc.pid && matchesProcessIdentity(proc, child),\n );\n}\n\n/**\n * Find parent wrapper processes that should not be reported as separate agents.\n *\n * A process is considered a wrapper when it is the parent of another candidate\n * agent process in the same terminal/worktree, or when it points at the same\n * terminal/worktree as an already session-matched process.\n */\nexport function findWrapperProcessPids(\n processes: ProcessInfo[],\n matchedProcesses: ProcessInfo[] = [],\n): Set<number> {\n const wrappers = new Set<number>();\n\n for (const child of processes) {\n const wrapper = findWrapperProcess(processes, child);\n if (wrapper) {\n wrappers.add(wrapper.pid);\n }\n }\n\n for (const proc of processes) {\n if (\n matchedProcesses.some(\n (matched) => proc.pid !== matched.pid && isSameTerminalProcess(proc, matched),\n )\n ) {\n wrappers.add(proc.pid);\n }\n }\n\n return wrappers;\n}\n\n/**\n * Get the TTY device for a specific process\n */\nexport function getProcessTty(pid: number): string {\n try {\n const output = execFileSync(\"ps\", [\"-p\", String(pid), \"-o\", \"tty=\"], { encoding: \"utf-8\" });\n\n const tty = output.trim();\n return tty.startsWith(\"/dev/\") ? tty.slice(5) : tty;\n } catch {\n return \"?\";\n }\n}\n"],"names":["fs","path","execFile","execFileSync","PROCESS_EXEC_MAX_BUFFER","VALID_EXECUTABLE_NAME","ABSOLUTE_PATH","PATH_SEPARATOR","pathBasename","executable","basename","replace","toLowerCase","isFile","filePath","statSync","throwIfNoEntry","executablePath","command","parts","trim","split","first","length","test","prefix","i","executableBasename","normalizeExecutableName","name","lower","endsWith","slice","normalizedProcessNames","namePatterns","Set","filter","Boolean","map","matchesExecutableName","names","tokens","has","mayContinuePath","some","token","filterByProcessNames","processes","size","process","listAgentProcesses","namePattern","output","encoding","line","match","pid","parseInt","ppid","Number","isNaN","tty","ttyShort","startsWith","push","cwd","execFileText","file","args","Promise","resolve","reject","maxBuffer","error","stdout","parseProcessList","allPids","matched","add","getProcessCwdsAsync","pids","batchGetProcessCwdsAsync","exec","result","Map","join","currentPid","set","entries","all","String","entry","batchGetProcessStartTimesAsync","rawLine","date","Date","isFinite","getTime","processIdentity","createProcessSnapshotCapture","deps","startTimeCache","cachedStartTime","cached","get","identity","startTime","undefined","options","keys","delete","isCandidate","candidates","candidatePids","uncachedPids","cwdMap","startTimeMap","candidateSet","captureProcessSnapshot","batchGetProcessCwds","stdio","batchGetProcessStartTimes","dateStr","enrichProcesses","p","proc","isSameTerminalProcess","sameTty","sameCwd","matchesProcessIdentity","findWrapperProcess","child","find","findWrapperProcessPids","matchedProcesses","wrappers","wrapper","getProcessTty"],"mappings":"AAAA;;;;;;CAMC,GAED,YAAYA,QAAQ,KAAK;AACzB,YAAYC,UAAU,OAAO;AAC7B,SAASC,QAAQ,EAAEC,YAAY,QAAQ,gBAAgB;AAGvD,MAAMC,0BAA0B,KAAK,OAAO;AAC5C,MAAMC,wBAAwB;AAC9B,MAAMC,gBAAgB;AACtB,MAAMC,iBAAiB;AAEvB,SAASC,aAAaC,UAAkB;IACtC,OAAOR,KAAKS,QAAQ,CAACD,WAAWE,OAAO,CAAC,OAAO,MAAMC,WAAW;AAClE;AAEA,SAASC,OAAOC,QAAgB;IAC9B,IAAI;QACF,OAAOd,GAAGe,QAAQ,CAACD,UAAU;YAAEE,gBAAgB;QAAM,IAAIH,YAAY;IACvE,EAAE,OA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