ccleanup 1.0.1 → 1.0.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.
package/dist/core/scan.js CHANGED
@@ -5,6 +5,8 @@ import { sanitize } from "../lib/text.js";
5
5
  export const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
6
6
  const EDGE = 64 * 1024;
7
7
  const TITLE_MAX = 200;
8
+ // Longest project folder name Claude Code keeps before it adds a hash
9
+ const PROJECT_DIR_MAX = 200;
8
10
  export const CONCURRENCY = 8;
9
11
  /**
10
12
  * Identifies a session uniquely, even when its id appears in two project folders or two
@@ -168,6 +170,21 @@ export function shortProject(cwd, projectDir) {
168
170
  return "~";
169
171
  return sanitize(cwd.split("/").filter(Boolean).slice(-2).join("/"));
170
172
  }
173
+ /**
174
+ * Tells whether a project folder was named after a working directory, the way Claude Code
175
+ * names them: each character other than a letter or a digit turned into a dash. A longer
176
+ * name is cut and given a hash, so only its start is compared, as Claude Code does.
177
+ *
178
+ * @param cwd - Working directory
179
+ * @param projectDir - Name of the project folder
180
+ * @returns True when the folder belongs to that working directory
181
+ */
182
+ export function ownsProjectDir(cwd, projectDir) {
183
+ const name = cwd.replace(/[^a-zA-Z0-9]/g, "-");
184
+ if (name.length <= PROJECT_DIR_MAX)
185
+ return name === projectDir;
186
+ return projectDir.startsWith(`${name.slice(0, PROJECT_DIR_MAX)}-`);
187
+ }
171
188
  /**
172
189
  * Finds the first value a picker returns over a list of records.
173
190
  *
@@ -199,7 +216,8 @@ function field(record, key) {
199
216
  /**
200
217
  * Reads the title, the project and the working directory of a transcript.
201
218
  *
202
- * The title is the latest AI title, else the first prompt, else the last prompt.
219
+ * The title is the latest AI title, else the first prompt, else the last prompt. The cwd is
220
+ * the one of the project folder, where `claude --resume` finds the session, else the first.
203
221
  *
204
222
  * @param transcript - Path of the .jsonl transcript
205
223
  * @param projectDir - Encoded project folder name, the fallback for the project label
@@ -217,11 +235,18 @@ async function describe(transcript, projectDir) {
217
235
  const aiTitle = (r) => (r.type === "ai-title" ? field(r, "aiTitle") : undefined);
218
236
  const lastPrompt = (r) => r.type === "last-prompt" ? field(r, "lastPrompt") : undefined;
219
237
  const cwdOf = (r) => field(r, "cwd");
238
+ const ownCwd = (r) => {
239
+ const value = cwdOf(r);
240
+ return value !== undefined && ownsProjectDir(value, projectDir) ? value : undefined;
241
+ };
220
242
  const title = clean(find(tail, aiTitle, true) ??
221
243
  find(head, aiTitle, true) ??
222
244
  find(head, promptText) ??
223
245
  find(tail, lastPrompt, true));
224
- const found = find(head, cwdOf) ?? find(tail, cwdOf, true);
246
+ const found = find(tail, ownCwd, true) ??
247
+ find(head, ownCwd) ??
248
+ find(head, cwdOf) ??
249
+ find(tail, cwdOf, true);
225
250
  const cwd = found === undefined ? undefined : sanitize(found);
226
251
  const started = Date.parse(find(head, (r) => field(r, "timestamp")) ?? "");
227
252
  const startedAt = Number.isNaN(started) ? undefined : started;
package/dist/ui/input.js CHANGED
@@ -6,7 +6,10 @@ import { BEL, ESC } from "../lib/text.js";
6
6
  const REPLY = new RegExp(String.raw `${ESC}\][^${BEL}${ESC}]*(?:${BEL}|${ESC}\\)|${ESC}\[\?[\d;]*c`, "g");
7
7
  // The start of a reply cut at the end of a chunk, kept until the next chunk
8
8
  const PARTIAL = new RegExp(String.raw `${ESC}(?:\][^${BEL}${ESC}]*${ESC}?|\[\?[\d;]*)?$`);
9
- const CARRY_MS = 50;
9
+ // Wait for the rest of a cut sequence before a lone Esc, as long as Vim does
10
+ const CARRY_MS = 100;
11
+ // What readline reports for Esc, sent without its own half-second wait for a sequence
12
+ const ESCAPE = { sequence: ESC, name: "escape", ctrl: false, meta: false, shift: false };
10
13
  /**
11
14
  * Decodes keys from stdin, after removing the replies the terminal sends on its own.
12
15
  *
@@ -24,7 +27,10 @@ export function createInput(stdin, onKey) {
24
27
  let timer;
25
28
  const flush = () => {
26
29
  timer = undefined;
27
- if (carry)
30
+ // Nothing followed the escape byte: a lone Esc
31
+ if (carry === ESC)
32
+ onKey(undefined, ESCAPE);
33
+ else if (carry)
28
34
  relay.write(carry);
29
35
  carry = "";
30
36
  };
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.1",
2
+ "version": "1.0.2",
3
3
  "name": "ccleanup",
4
4
  "description": "Interactive cleanup of Claude Code sessions: find the biggest and oldest transcripts, delete them, get a reminder.",
5
5
  "type": "module",