claude-yes 1.30.0 → 1.31.1

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/index.js CHANGED
@@ -12749,13 +12749,14 @@ function catcher(catchFn, fn) {
12749
12749
  }
12750
12750
 
12751
12751
  // ts/codexSessionManager.ts
12752
- import { mkdir, readFile, writeFile } from "fs/promises";
12752
+ import { mkdir, readdir, readFile, writeFile } from "fs/promises";
12753
12753
  import { homedir } from "os";
12754
12754
  import path7 from "path";
12755
- var SESSIONS_FILE = path7.join(homedir(), ".config", "cli-yes", "codex-sessions.json");
12755
+ var getSessionsFile = () => process.env.CLI_YES_TEST_HOME ? path7.join(process.env.CLI_YES_TEST_HOME, ".config", "cli-yes", "codex-sessions.json") : path7.join(homedir(), ".config", "cli-yes", "codex-sessions.json");
12756
+ var getCodexSessionsDir = () => process.env.CLI_YES_TEST_HOME ? path7.join(process.env.CLI_YES_TEST_HOME, ".codex", "sessions") : path7.join(homedir(), ".codex", "sessions");
12756
12757
  async function loadSessionMap() {
12757
12758
  try {
12758
- const content = await readFile(SESSIONS_FILE, "utf-8");
12759
+ const content = await readFile(getSessionsFile(), "utf-8");
12759
12760
  return JSON.parse(content);
12760
12761
  } catch (error) {
12761
12762
  return {};
@@ -12763,8 +12764,9 @@ async function loadSessionMap() {
12763
12764
  }
12764
12765
  async function saveSessionMap(sessionMap) {
12765
12766
  try {
12766
- await mkdir(path7.dirname(SESSIONS_FILE), { recursive: true });
12767
- await writeFile(SESSIONS_FILE, JSON.stringify(sessionMap, null, 2));
12767
+ const sessionsFile = getSessionsFile();
12768
+ await mkdir(path7.dirname(sessionsFile), { recursive: true });
12769
+ await writeFile(sessionsFile, JSON.stringify(sessionMap, null, 2));
12768
12770
  } catch (error) {
12769
12771
  console.warn("Failed to save codex session map:", error);
12770
12772
  }
@@ -12777,7 +12779,78 @@ async function storeSessionForCwd(cwd, sessionId) {
12777
12779
  };
12778
12780
  await saveSessionMap(sessionMap);
12779
12781
  }
12782
+ async function parseCodexSessionFile(filePath) {
12783
+ try {
12784
+ const content = await readFile(filePath, "utf-8");
12785
+ const lines2 = content.trim().split(`
12786
+ `);
12787
+ for (const line of lines2) {
12788
+ if (!line.trim())
12789
+ continue;
12790
+ const data = JSON.parse(line);
12791
+ if (data.type === "session_meta" && data.payload) {
12792
+ const payload = data.payload;
12793
+ return {
12794
+ id: payload.id,
12795
+ timestamp: payload.timestamp || data.timestamp,
12796
+ cwd: payload.cwd,
12797
+ filePath,
12798
+ git: payload.git
12799
+ };
12800
+ }
12801
+ }
12802
+ return null;
12803
+ } catch (error) {
12804
+ return null;
12805
+ }
12806
+ }
12807
+ async function getAllCodexSessions() {
12808
+ const sessions = [];
12809
+ const codexSessionsDir = getCodexSessionsDir();
12810
+ try {
12811
+ const years = await readdir(codexSessionsDir);
12812
+ for (const year of years) {
12813
+ const yearPath = path7.join(codexSessionsDir, year);
12814
+ try {
12815
+ const months = await readdir(yearPath);
12816
+ for (const month of months) {
12817
+ const monthPath = path7.join(yearPath, month);
12818
+ try {
12819
+ const days = await readdir(monthPath);
12820
+ for (const day of days) {
12821
+ const dayPath = path7.join(monthPath, day);
12822
+ try {
12823
+ const files = await readdir(dayPath);
12824
+ for (const file of files) {
12825
+ if (file.endsWith(".jsonl")) {
12826
+ const sessionPath = path7.join(dayPath, file);
12827
+ const session = await parseCodexSessionFile(sessionPath);
12828
+ if (session) {
12829
+ sessions.push(session);
12830
+ }
12831
+ }
12832
+ }
12833
+ } catch (error) {}
12834
+ }
12835
+ } catch (error) {}
12836
+ }
12837
+ } catch (error) {}
12838
+ }
12839
+ } catch (error) {
12840
+ return [];
12841
+ }
12842
+ return sessions.sort((a2, b) => new Date(b.timestamp).getTime() - new Date(a2.timestamp).getTime());
12843
+ }
12844
+ async function getMostRecentCodexSessionForCwd(targetCwd) {
12845
+ const allSessions = await getAllCodexSessions();
12846
+ const sessionsForCwd = allSessions.filter((session) => session.cwd === targetCwd);
12847
+ return sessionsForCwd[0] || null;
12848
+ }
12780
12849
  async function getSessionForCwd(cwd) {
12850
+ const recentSession = await getMostRecentCodexSessionForCwd(cwd);
12851
+ if (recentSession) {
12852
+ return recentSession.id;
12853
+ }
12781
12854
  const sessionMap = await loadSessionMap();
12782
12855
  return sessionMap[cwd]?.sessionId || null;
12783
12856
  }
@@ -18739,5 +18812,5 @@ export {
18739
18812
  CLIS_CONFIG
18740
18813
  };
18741
18814
 
18742
- //# debugId=960F18B9875AE03B64756E2164756E21
18815
+ //# debugId=D3A44192E52BBE4964756E2164756E21
18743
18816
  //# sourceMappingURL=index.js.map