ai-chat-cleaner 0.1.1 → 0.1.2

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.
Files changed (2) hide show
  1. package/dist/cli.mjs +14 -6
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -5,6 +5,7 @@ import { cac } from "cac";
5
5
  import readline from "node:readline";
6
6
  import tildify from "tildify";
7
7
  import { execFile } from "node:child_process";
8
+ import { existsSync } from "node:fs";
8
9
  import { readFile, readdir, stat, writeFile } from "node:fs/promises";
9
10
  import { promisify } from "node:util";
10
11
  import pLimit from "p-limit";
@@ -244,6 +245,7 @@ function clearScreen() {
244
245
  //#region src/utils.ts
245
246
  const exec = promisify(execFile);
246
247
  async function readJSON(filepath) {
248
+ if (!existsSync(filepath)) return;
247
249
  return parseJSON(await readFile(filepath, "utf-8"));
248
250
  }
249
251
  async function writeJSON(filepath, data) {
@@ -312,7 +314,7 @@ function isUUID(value) {
312
314
  //#endregion
313
315
  //#region package.json
314
316
  var name = "ai-chat-cleaner";
315
- var version = "0.1.1";
317
+ var version = "0.1.2";
316
318
 
317
319
  //#endregion
318
320
  //#region src/constants.ts
@@ -619,6 +621,7 @@ async function deleteThreads({ threads, globalState, sqlitePath }) {
619
621
  if (sqlitePath) await writeSQLite(sqlitePath, Array.from(threadIds));
620
622
  }
621
623
  async function updateGlobalState(threadIds, globalState) {
624
+ if (!globalState) return;
622
625
  for (const id of threadIds) delete globalState["thread-titles"].titles[id];
623
626
  globalState["thread-titles"].order = globalState["thread-titles"].order.filter((id) => !threadIds.has(id));
624
627
  await writeJSON(GLOBAL_STATE_PATH, globalState);
@@ -635,7 +638,10 @@ async function detectCodex(cwd = AGENTS_CONFIG.codex.path) {
635
638
  const globalState = await readJSON(GLOBAL_STATE_PATH);
636
639
  const sqlitePath = await getDatabasePath(cwd);
637
640
  const data = sqlitePath ? await readSQLite(sqlitePath) : [];
638
- const titles = globalState["thread-titles"].titles;
641
+ const titles = (globalState?.["thread-titles"] ?? {
642
+ titles: {},
643
+ order: []
644
+ }).titles;
639
645
  return {
640
646
  threads: data.filter((i) => i.title || i.id in titles).sort((a, b) => a.updated_at > b.updated_at ? -1 : 1).map((thread) => {
641
647
  const title = titles[thread.id] || normalizeTitle(thread);
@@ -770,7 +776,7 @@ async function resolveAgent() {
770
776
 
771
777
  //#endregion
772
778
  //#region src/cli.ts
773
- try {
779
+ async function main() {
774
780
  const cli = cac(NAME);
775
781
  cli.command("", "Clean and remove AI chat with an interactive terminal UI").option("--agent, -a <agent>", "Agent to clean").allowUnknownOptions().action(async (options) => {
776
782
  p.intro(`${c.yellow`${NAME} `}${c.dim`v${VERSION}`}`);
@@ -789,11 +795,13 @@ try {
789
795
  });
790
796
  cli.help();
791
797
  cli.version(VERSION);
792
- cli.parse();
793
- } catch (error) {
798
+ cli.parse(process.argv, { run: false });
799
+ await cli.runMatchedCommand();
800
+ }
801
+ main().catch((error) => {
794
802
  console.error(error);
795
803
  process.exit(1);
796
- }
804
+ });
797
805
 
798
806
  //#endregion
799
807
  export { };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ai-chat-cleaner",
3
3
  "type": "module",
4
- "version": "0.1.1",
4
+ "version": "0.1.2",
5
5
  "description": "Clean and remove AI chat with an interactive terminal UI.",
6
6
  "author": "jinghaihan",
7
7
  "license": "MIT",