cli-remote-agent 1.0.8 → 1.0.10
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/cli.js +28 -1
- package/dist/cli.js.map +1 -1
- package/dist/index.js +27 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -372,6 +372,7 @@ function getLiveClaudeSessions() {
|
|
|
372
372
|
out.push({
|
|
373
373
|
pid: obj.pid,
|
|
374
374
|
cwd: typeof obj.cwd === "string" ? obj.cwd : "",
|
|
375
|
+
sessionId: typeof obj.sessionId === "string" ? obj.sessionId : void 0,
|
|
375
376
|
name: typeof obj.name === "string" ? obj.name : void 0,
|
|
376
377
|
status: typeof obj.status === "string" ? obj.status : void 0,
|
|
377
378
|
updatedAt: typeof obj.updatedAt === "number" ? obj.updatedAt : void 0
|
|
@@ -402,6 +403,15 @@ function isDescendantOf(pid, ancestor, parents) {
|
|
|
402
403
|
}
|
|
403
404
|
return false;
|
|
404
405
|
}
|
|
406
|
+
async function findClaudeSessionForPtyPid(ptyPid) {
|
|
407
|
+
const live = getLiveClaudeSessions().filter((s) => s.sessionId);
|
|
408
|
+
if (live.length === 0) return null;
|
|
409
|
+
const parents = await getPidParents();
|
|
410
|
+
for (let i = live.length - 1; i >= 0; i--) {
|
|
411
|
+
if (isDescendantOf(live[i].pid, ptyPid, parents)) return live[i].sessionId;
|
|
412
|
+
}
|
|
413
|
+
return null;
|
|
414
|
+
}
|
|
405
415
|
|
|
406
416
|
// src/tmux.ts
|
|
407
417
|
var execFileAsync2 = (0, import_util2.promisify)(import_child_process3.execFile);
|
|
@@ -639,6 +649,9 @@ var PtySession = class {
|
|
|
639
649
|
});
|
|
640
650
|
}
|
|
641
651
|
}
|
|
652
|
+
get pid() {
|
|
653
|
+
return this.pty.pid;
|
|
654
|
+
}
|
|
642
655
|
write(data) {
|
|
643
656
|
this.pty.write(data);
|
|
644
657
|
}
|
|
@@ -704,6 +717,9 @@ function createTerminalSession(sessionId, cols, rows, shellPreference, cwd, onDa
|
|
|
704
717
|
sessions.set(sessionId, session);
|
|
705
718
|
logger.info({ sessionId, cols, rows }, "PTY session created");
|
|
706
719
|
}
|
|
720
|
+
function getSessionPid(sessionId) {
|
|
721
|
+
return sessions.get(sessionId)?.pid;
|
|
722
|
+
}
|
|
707
723
|
function writeToSession(sessionId, data) {
|
|
708
724
|
sessions.get(sessionId)?.write(data);
|
|
709
725
|
}
|
|
@@ -1745,7 +1761,17 @@ socket.on(AGENT_EXEC, async (payload) => {
|
|
|
1745
1761
|
});
|
|
1746
1762
|
socket.on(CLAUDE_CONV_READ, async (payload) => {
|
|
1747
1763
|
try {
|
|
1748
|
-
|
|
1764
|
+
let sessionId = payload.sessionId;
|
|
1765
|
+
if (!sessionId && payload.terminalSessionId) {
|
|
1766
|
+
const ptyPid = getSessionPid(payload.terminalSessionId);
|
|
1767
|
+
const resolved = ptyPid ? await findClaudeSessionForPtyPid(ptyPid) : null;
|
|
1768
|
+
if (!resolved) {
|
|
1769
|
+
socket.emit(CLAUDE_CONV_DATA, { sessionId: "", messages: [], totalLines: 0 });
|
|
1770
|
+
return;
|
|
1771
|
+
}
|
|
1772
|
+
sessionId = resolved;
|
|
1773
|
+
}
|
|
1774
|
+
const result = await readConversation(payload.projectPath, payload.afterLine || 0, sessionId);
|
|
1749
1775
|
if (result) {
|
|
1750
1776
|
socket.emit(CLAUDE_CONV_DATA, {
|
|
1751
1777
|
sessionId: result.sessionId,
|