@hype/clod 1.3.1 → 1.4.0

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/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  # clod
6
6
 
7
- Terminal UI for managing Claude Code sessions.
7
+ Terminal UI for managing Claude Code and omp sessions.
8
8
 
9
9
  [![npm][npm-image]][npm-url]
10
10
  [![build][build-image]][build-url]
@@ -16,7 +16,7 @@ Terminal UI for managing Claude Code sessions.
16
16
 
17
17
  </div>
18
18
 
19
- Browse, search, preview, resume, rename, and delete any session from any directory.
19
+ Browse, search, preview, resume, rename, and delete any session from any directory. Sessions from [Claude Code](https://github.com/anthropics/claude-code) and [omp](https://github.com/can1357/oh-my-pi) share one list.
20
20
 
21
21
  ![clod session list](images/demo.png)
22
22
 
@@ -27,7 +27,7 @@ Like `claude -r` but better.
27
27
  **Requirements:**
28
28
 
29
29
  - Node 22+
30
- - Claude Code CLI (`claude`) on PATH for resume
30
+ - Claude Code (`claude`) or omp (`omp`) on PATH to resume its sessions
31
31
 
32
32
  Install globally via your node package manager of choice:
33
33
 
@@ -62,12 +62,28 @@ clod
62
62
  | `r` | Rename selected session (enter confirms, esc cancels; `←`/`→` move the cursor, `alt+←`/`→` jump by word) |
63
63
  | `u` | Usage dashboard (token counts) |
64
64
  | `s` | Cycle sort: recent → lexicographic → by directory |
65
- | `D` | Delete (moves to Trash; includes tasks, file-history, session-env, debug/telemetry, and history.jsonl prompt lines) |
65
+ | `h` | Cycle harness filter: all → Claude Code → omp |
66
+ | `D` | Delete (moves to Trash, see [What delete removes](#what-delete-removes)) |
66
67
  | `q` / `esc` | Quit |
67
68
 
69
+ Rename and delete refuse a session that is open in a running Claude Code or omp, which would write its own title back or recreate the transcript. An omp left idle in a terminal counts as open too.
70
+
71
+ ### What delete removes
72
+
73
+ Delete matches what each tool removes for its own sessions, and moves everything to Trash.
74
+
75
+ - **Claude Code:** the transcript and every file beside it named for the session, tasks, file-history, session-env, uploads, debug and telemetry files, the session's temp files, and its `history.jsonl` prompt lines.
76
+ - **omp:** the transcript, its artifact directory, any `.bak` copies, and the session's title and recap rows in `history.db`. Prompt history stays, as it does when omp deletes a session.
77
+
68
78
  ### What it shows
69
79
 
70
- Each row: session title · branch · project path · tokens used · context window · time since last activity
80
+ Each row: harness · session title · branch · project path · tokens used · context window · time since last activity
81
+
82
+ The first column marks the harness, `✻` for Claude Code and `π` for omp. It turns bright green while that tool has the session open.
83
+
84
+ Sessions you've named with `/rename` show that name in bold. Unnamed sessions show the title the tool generated, or the opening prompt in dim italic if there isn't one. omp's generated titles drop their leading Nerd Font icon so they sort with everything else.
85
+
86
+ omp doesn't record a git branch, so `clod` reads it from the repo's HEAD reflog as of the session's last activity. The branch is blank when the reflog can't answer, for example after a worktree is removed.
71
87
 
72
88
  `used` is real throughput: tokens processed and generated (input + output +
73
89
  cache writes), excluding cache reads. Cache reads re-count the same context
@@ -80,7 +96,7 @@ Bottom bar: last user message from the selected session.
80
96
 
81
97
  ### Dashboard
82
98
 
83
- Press `u` for an aggregate view across all sessions: total throughput, a token
99
+ Press `u` for an aggregate view across the sessions in the list, so `h` narrows it to one harness: total throughput, a token
84
100
  breakdown by type (input / output / cache write / cache read), a 30-day
85
101
  throughput-per-day sparkline, a per-model breakdown, and top projects by
86
102
  throughput. The cache-inclusive grand total is shown alongside the headline so
@@ -91,11 +107,11 @@ recorded token counts, no estimation.
91
107
 
92
108
  ### How it works
93
109
 
94
- Claude Code stores all session files in `~/.claude/projects/`, regardless of which directory the session was started in. `clod` reads from there directly. No home directory scanning.
110
+ Claude Code stores all session files in `~/.claude/projects/`, and omp stores its own in `~/.omp/agent/sessions/` (or under `$PI_CODING_AGENT_DIR` when set), regardless of which directory the session was started in. `clod` reads from there directly. No home directory scanning.
95
111
 
96
112
  ### Maintenance
97
113
 
98
- `scripts/cleanup.js` trashes orphaned session artifacts under `~/.claude`
114
+ `scripts/cleanup.js` trashes orphaned Claude Code session artifacts under `~/.claude`
99
115
  (file-history, session-env, tasks, telemetry, and stale `history.jsonl` lines
100
116
  for sessions with no transcript left). Dry-run by default; `--apply` to act.
101
117
  Per-session delete already covers these, so this is only for backlog from
@@ -120,9 +136,9 @@ pnpm format # biome check --write
120
136
  ```
121
137
 
122
138
  Tests use `node:test` and run through Node's type stripping, so no test-runner
123
- dependency. The parsing, sorting, and stats logic lives in `src/{sessions,list,stats,config}.ts`
124
- and is held at 100% coverage; the Ink render layer (`src/ui.ts`) is exercised by
125
- `ink-testing-library` but kept out of the gate.
139
+ dependency. Every module in `src/` is held at 100% coverage except `src/index.ts`,
140
+ `src/trash.ts`, and `src/proc.ts`, and the Ink render layer (`src/ui.ts`) is driven through
141
+ `ink-testing-library`.
126
142
 
127
143
  ## Contributing
128
144
 
package/dist/git.js ADDED
@@ -0,0 +1,170 @@
1
+ import { readdir, readFile, stat } from 'node:fs/promises';
2
+ import { dirname, isAbsolute, join, resolve } from 'node:path';
3
+ const HEX = /^[0-9a-f]{7,64}$/;
4
+ // The gitdir for cwd: the nearest .git up the tree, following a worktree's
5
+ // `gitdir:` pointer. null outside a repo.
6
+ // A cwd that no longer exists gets null rather than an unrelated parent repo's
7
+ // branch (a removed worktree under its main checkout, a dotfiles repo at ~).
8
+ export async function findGitDir(cwd) {
9
+ try {
10
+ await stat(cwd);
11
+ }
12
+ catch {
13
+ return null;
14
+ }
15
+ return walkUp(cwd);
16
+ }
17
+ async function walkUp(cwd) {
18
+ const dir = resolve(cwd);
19
+ const dotGit = join(dir, '.git');
20
+ try {
21
+ const st = await stat(dotGit);
22
+ if (st.isDirectory())
23
+ return dotGit;
24
+ const m = /^gitdir:\s*(.+)$/m.exec(await readFile(dotGit, 'utf8'));
25
+ if (m)
26
+ return isAbsolute(m[1].trim()) ? m[1].trim() : resolve(dir, m[1].trim());
27
+ }
28
+ catch { }
29
+ const parent = dirname(dir);
30
+ return parent === dir ? null : walkUp(parent);
31
+ }
32
+ async function readOr(path) {
33
+ try {
34
+ return await readFile(path, 'utf8');
35
+ }
36
+ catch {
37
+ return '';
38
+ }
39
+ }
40
+ // Refs live in the common dir, which a worktree's gitdir names in `commondir`.
41
+ async function commonDir(gitDir) {
42
+ const rel = (await readOr(join(gitDir, 'commondir'))).trim();
43
+ return rel ? resolve(gitDir, rel) : gitDir;
44
+ }
45
+ // A checkout target that is not a branch: a sha, a tag, or a remote-tracking ref
46
+ // with no local branch of the same name.
47
+ function detachedTarget(name, refs) {
48
+ if (HEX.test(name) && !refs.heads.has(name))
49
+ return true;
50
+ if (refs.heads.has(name))
51
+ return false;
52
+ if (refs.tags.has(name))
53
+ return true;
54
+ const remote = name.split('/')[0];
55
+ return name.includes('/') && refs.remotes.has(remote);
56
+ }
57
+ async function refNames(common) {
58
+ const heads = new Set();
59
+ const tags = new Set();
60
+ const remotes = new Set();
61
+ const add = (ref) => {
62
+ if (ref.startsWith('refs/heads/'))
63
+ heads.add(ref.slice(11));
64
+ else if (ref.startsWith('refs/tags/'))
65
+ tags.add(ref.slice(10));
66
+ else if (ref.startsWith('refs/remotes/'))
67
+ remotes.add(ref.split('/')[2]);
68
+ };
69
+ for (const line of (await readOr(join(common, 'packed-refs'))).split('\n')) {
70
+ const ref = line.split(' ')[1];
71
+ if (ref)
72
+ add(ref);
73
+ }
74
+ const walk = async (rel) => {
75
+ let names;
76
+ try {
77
+ names = await readdir(join(common, rel), { withFileTypes: true });
78
+ }
79
+ catch {
80
+ return;
81
+ }
82
+ for (const d of names) {
83
+ if (d.isDirectory())
84
+ await walk(`${rel}/${d.name}`);
85
+ else
86
+ add(`${rel}/${d.name}`);
87
+ }
88
+ };
89
+ await walk('refs/heads');
90
+ await walk('refs/tags');
91
+ try {
92
+ for (const d of await readdir(join(common, 'refs', 'remotes')))
93
+ remotes.add(d);
94
+ }
95
+ catch { }
96
+ return { heads, tags, remotes };
97
+ }
98
+ // Parse <gitdir>/logs/HEAD into branch steps. Reftable repos and removed
99
+ // worktrees have no such file, and get null.
100
+ export async function readReflog(gitDir) {
101
+ const raw = await readOr(join(gitDir, 'logs', 'HEAD'));
102
+ if (!raw)
103
+ return null;
104
+ const refs = await refNames(await commonDir(gitDir));
105
+ const head = /^ref: refs\/heads\/(.+)$/m.exec(await readOr(join(gitDir, 'HEAD')))?.[1] ?? null;
106
+ const steps = [];
107
+ let initial;
108
+ let state = null;
109
+ for (const line of raw.split('\n')) {
110
+ const tab = line.indexOf('\t');
111
+ if (tab === -1)
112
+ continue;
113
+ const at = Number(/ (\d+) [+-]\d{4}$/.exec(line.slice(0, tab))?.[1]) * 1000;
114
+ if (!at)
115
+ continue;
116
+ const msg = line.slice(tab + 1);
117
+ let next;
118
+ const checkout = /^checkout: moving from (\S+) to (\S+)$/.exec(msg);
119
+ const returned = /\((?:finish|abort)\): returning to refs\/heads\/(\S+)$/.exec(msg);
120
+ const renamed = /^Branch: renamed refs\/heads\/(\S+) to refs\/heads\/(\S+)$/.exec(msg);
121
+ if (checkout) {
122
+ if (initial === undefined)
123
+ initial = detachedTarget(checkout[1], refs) ? null : checkout[1];
124
+ next = detachedTarget(checkout[2], refs) ? null : checkout[2];
125
+ }
126
+ else if (/\(start\): checkout /.test(msg))
127
+ next = null;
128
+ else if (returned)
129
+ next = returned[1];
130
+ else if (renamed) {
131
+ if (initial === undefined)
132
+ initial = renamed[1];
133
+ if ((steps.length ? state : initial) === renamed[1])
134
+ next = renamed[2];
135
+ }
136
+ if (next !== undefined) {
137
+ state = next;
138
+ steps.push({ at, branch: next });
139
+ }
140
+ }
141
+ return { initial: initial === undefined ? head : initial, steps };
142
+ }
143
+ // The last branch checked out at or before `at`, skipping detached stretches,
144
+ // as Claude Code's recorded gitBranch reads in clod.
145
+ export function branchAt(log, at) {
146
+ let branch = log.initial;
147
+ for (const step of log.steps) {
148
+ if (step.at > at)
149
+ break;
150
+ if (step.branch)
151
+ branch = step.branch;
152
+ }
153
+ return branch;
154
+ }
155
+ // One reflog read per gitdir per clod run.
156
+ export function reflogBranches() {
157
+ const gitDirs = new Map();
158
+ const logs = new Map();
159
+ return async (cwd, at) => {
160
+ if (!gitDirs.has(cwd))
161
+ gitDirs.set(cwd, findGitDir(cwd));
162
+ const gitDir = await gitDirs.get(cwd);
163
+ if (!gitDir)
164
+ return null;
165
+ if (!logs.has(gitDir))
166
+ logs.set(gitDir, readReflog(gitDir));
167
+ const parsed = await logs.get(gitDir);
168
+ return parsed ? branchAt(parsed, at) : null;
169
+ };
170
+ }