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 CHANGED
@@ -550,6 +550,7 @@ function getLiveClaudeSessions() {
550
550
  out.push({
551
551
  pid: obj.pid,
552
552
  cwd: typeof obj.cwd === "string" ? obj.cwd : "",
553
+ sessionId: typeof obj.sessionId === "string" ? obj.sessionId : void 0,
553
554
  name: typeof obj.name === "string" ? obj.name : void 0,
554
555
  status: typeof obj.status === "string" ? obj.status : void 0,
555
556
  updatedAt: typeof obj.updatedAt === "number" ? obj.updatedAt : void 0
@@ -580,6 +581,15 @@ function isDescendantOf(pid, ancestor, parents) {
580
581
  }
581
582
  return false;
582
583
  }
584
+ async function findClaudeSessionForPtyPid(ptyPid) {
585
+ const live = getLiveClaudeSessions().filter((s) => s.sessionId);
586
+ if (live.length === 0) return null;
587
+ const parents = await getPidParents();
588
+ for (let i = live.length - 1; i >= 0; i--) {
589
+ if (isDescendantOf(live[i].pid, ptyPid, parents)) return live[i].sessionId;
590
+ }
591
+ return null;
592
+ }
583
593
  var import_fs6, import_path5, import_os2, import_child_process2, import_util, execFileAsync, LIVE_SESSIONS_DIR;
584
594
  var init_claude_live = __esm({
585
595
  "src/claude-live.ts"() {
@@ -845,6 +855,9 @@ var init_pty_session = __esm({
845
855
  });
846
856
  }
847
857
  }
858
+ get pid() {
859
+ return this.pty.pid;
860
+ }
848
861
  write(data) {
849
862
  this.pty.write(data);
850
863
  }
@@ -911,6 +924,9 @@ function createTerminalSession(sessionId, cols, rows, shellPreference, cwd, onDa
911
924
  sessions.set(sessionId, session);
912
925
  logger.info({ sessionId, cols, rows }, "PTY session created");
913
926
  }
927
+ function getSessionPid(sessionId) {
928
+ return sessions.get(sessionId)?.pid;
929
+ }
914
930
  function writeToSession(sessionId, data) {
915
931
  sessions.get(sessionId)?.write(data);
916
932
  }
@@ -1824,6 +1840,7 @@ var init_index = __esm({
1824
1840
  init_claude_sessions();
1825
1841
  init_claude_conversation();
1826
1842
  init_terminal_manager();
1843
+ init_claude_live();
1827
1844
  if (!isConfigured()) {
1828
1845
  console.error("No agent configured. Run: crc-agent setup");
1829
1846
  process.exit(1);
@@ -2025,7 +2042,17 @@ var init_index = __esm({
2025
2042
  });
2026
2043
  socket.on(CLAUDE_CONV_READ, async (payload) => {
2027
2044
  try {
2028
- const result = await readConversation(payload.projectPath, payload.afterLine || 0, payload.sessionId);
2045
+ let sessionId = payload.sessionId;
2046
+ if (!sessionId && payload.terminalSessionId) {
2047
+ const ptyPid = getSessionPid(payload.terminalSessionId);
2048
+ const resolved = ptyPid ? await findClaudeSessionForPtyPid(ptyPid) : null;
2049
+ if (!resolved) {
2050
+ socket.emit(CLAUDE_CONV_DATA, { sessionId: "", messages: [], totalLines: 0 });
2051
+ return;
2052
+ }
2053
+ sessionId = resolved;
2054
+ }
2055
+ const result = await readConversation(payload.projectPath, payload.afterLine || 0, sessionId);
2029
2056
  if (result) {
2030
2057
  socket.emit(CLAUDE_CONV_DATA, {
2031
2058
  sessionId: result.sessionId,