SLOPSHOPPER

x-mod-holds

no two sessions write the same file: a session's first edit of a file holds it until it is committed, the session ends or sits idle 30 min; another session's…

guardpromptprocess
A shopper browsing a rack in a slop shop
README

🎞️ the frame: a place where most of the machine's setup lives as data.

<a href="https://github.com/dvakatsiienko/frame/actions/workflows/ci.yml"><img src="https://raw.githubusercontent.com/dvakatsiienko/frame/badges/ci.svg" alt="ci"></a> <img src="assets/badges/tests.svg" alt="tests"> <img src="assets/badges/renovate.svg" alt="renovate"> <img src="assets/badges/node.svg" alt="node"> <img src="assets/badges/pnpm.svg" alt="pnpm"> <img src="assets/badges/skills.svg" alt="skills"> <img src="assets/badges/mirrored.svg" alt="mirrored">

<img src="assets/banner.svg" align="left" width="100%" alt="frame — the inventory of one mac"> <img src="assets/mac.svg" align="right" width="36%" alt="an 80s mac showing ~ frame">

🧭 toc

  • fleet — skills, memory, sline, hotkeys
  • chords — the keyboard map, live
  • mirror — home/ is ~
  • machine — brew, defaults, launchd
  • link it — a fresh mac install

🛸 fleet

home/.claude/ is the claude code setup every session reads: memories, rules, skills (plugin-x), hooks, output styles, and sline, the statusline. cclio/ is the coordinator's home, the session that plans and routes work to background coders. x/ is x, the agent-first cli in go + charm: one verb registry, json for agents and boards for humans (x lane commits and pushes from a sandboxed worktree). hotkeys/ maps every keyboard chord on the machine and serves chords, the map's app. x-speak (a schedule/ daemon) reads the selected text aloud on F4 (with nothing selected it pauses / resumes, as ⇧F4 always does) and stops on F5, rewriting ids, versions, paths and code into something a voice can say; speak/ is its voice admin (pnpm speak:admin).

<img src="home/.claude/sline/showcase/sline.svg" width="100%" alt="sline, the statusline, as a session climbs from fresh to heavy">

🎹 chords

chords is a keyboard map app: every key binding on every modifier layer, how often each one fires, and which keys are still free. powered by launchd daemon that counts key presses.

<img src="hotkeys/chords/showcase.png" width="100%" alt="chords: the hyper layer on a NuPhy Air75, each bound key with its app and press count">

🪞 mirror

the mirror links dotfiles and configs. a path under home/ is the same path under ~. the link map is derived by walking the tree, so adding a file to home/ auto-tracks it.

pnpm frame:link                        # status
pnpm frame:link apply                  # link everything not linked yet
pnpm frame:link register ~/.foo        # move a file into the mirror and link it back
pnpm frame:link untrack ~/.gitconfig   # hand a file back to ~

<img src="assets/frame-link.gif" width="720" alt="pnpm frame:link, ending on everything mirrored">

💻 machine

the mac's setup is kept as data, because data does not rot and scripts do: the Brewfile, the macos defaults, the duti file bindings, and the launchd jobs under schedule/.

pnpm macos:setup   # brew bundle, macos defaults, duti, vim-plug

🔗 link it

on a fresh machine, install the command line tools first — the clone itself needs git, and macos ships only a shim that opens the install dialog. then clone to ~/frame and run the seed, or hand it to an agent («seed this mac from frame»):

xcode-select --install      # stop 0: the dialog, ~2 min
git clone https://github.com/dvakatsiienko/frame ~/frame && cd ~/frame
script/seed.sh                     # command line tools → brew → fnm, pnpm, node → pnpm i → macos:setup → sline → claude cli → frame:link apply
script/seed.sh --claude            # the same, with ~/.claude linked
script/seed.sh --without-appstore  # skip the app store apps and their sign-in
script/seed.sh --dry-run           # what it would do, nothing changed

one status line per step, safe to re-run. it stops with needs your hands: … (exit 2) where only a human can act — the command line tools dialog, the homebrew password, files in the way of a link, the app store and 1password sign-ins — and the next run picks up from there. when it ends, open a new terminal: a shell opened before the seed never sources the zsh stubs it wrote.

Source 1 files
hooks/register.ts 352 lines
1import type { EngineInterface, Register } from 'claude-code';
2
3// x-mod-holds: no two sessions write the same file. a session's first Edit or Write of a file holds it until the file
4// is committed, the session ends or sits idle; another session's edit of it, or a Bash write to it, is refused and
5// names the holder. x-mod-guard refuses a Bash write to a held file from this store.
6
7const errorText = (err: unknown) =>
8    err instanceof Error ? err.message : String(err);
9
10// this session's claude process, so a rival can tell a dead holder from a live one
11let proc: Proc | undefined;
12
13// holds: a session's first edit of a file holds it; another session's edit of it is refused.
14// $.store has no compare-and-set, so each session writes only its own keys and the earliest claim wins.
15
16// file is the real path in its own case, for git; landed once the edit went through
17type Hold = { at: number; file: string; top: string; landed?: boolean };
18type Claim = { deny?: string; key?: string };
19type Holder = { pid?: number; start?: string; idleSince: number | null };
20type Proc = { pid: number; start: string };
21
22const HOLD = 'hold:';
23const HOLDER = 'holder:';
24const REFUSED = 'refused:';
25const IDLE_MS = 30 * 60 * 1000;
26
27const holdKey = (sid: string, path: string) => `${HOLD}${sid}:${path}`;
28const short = (sid: string) => sid.slice(0, 8);
29// twin dirname — a copy lives in x-mod-guard; the twins lint keeps them equal
30const dirname = (file: string) => file.slice(0, file.lastIndexOf('/')) || '/';
31// twin end
32
33// a session id carries no ':', so the first one after the prefix ends it
34function parseHoldKey(key: string) {
35    if (!key.startsWith(HOLD)) return null;
36    const cut = key.indexOf(':', HOLD.length);
37    return cut < 0
38        ? null
39        : { path: key.slice(cut + 1), sid: key.slice(HOLD.length, cut) };
40}
41
42// twin real-path — a copy lives in x-mod-guard; the twins lint keeps them equal
43// the key is lowercased on every platform: APFS is case-insensitive and the mod cannot ask which os it runs on
44async function realPath($: EngineInterface, file: string) {
45    const resolve = (p: string) =>
46        $.fs.stat(p, { resolve: true }).then(
47            (s) => s.realPath,
48            () => undefined,
49        );
50    const direct = await resolve(file);
51    if (direct) return { file: direct, key: direct.toLowerCase() };
52    // a new file has no real path yet; its nearest existing folder does
53    let dir = dirname(file);
54    let real = await resolve(dir);
55    while (!real && dir !== '/') {
56        dir = dirname(dir);
57        real = await resolve(dir);
58    }
59    const full = `${real ?? dir}${file.slice(dir.length)}`;
60    return { file: full, key: full.toLowerCase() };
61}
62// twin end
63
64// twin proc-of — a copy lives in x-mod-stash; the twins lint keeps them equal
65async function procOf($: EngineInterface): Promise<Proc | undefined> {
66    const r = await $.process.run([
67        'sh',
68        '-c',
69        'echo $PPID; ps -o lstart= -p $PPID',
70    ]);
71    const [pid, start] = r.stdout.split('\n').map((s) => s.trim());
72    return r.exitCode === 0 && pid && start
73        ? { pid: Number(pid), start }
74        : undefined;
75}
76// twin end
77
78// the working tree a path sits in, lowercased; '' outside git
79async function topOf($: EngineInterface, cwd: string) {
80    const r = await $.process
81        .run(['git', 'rev-parse', '--show-toplevel'], { cwd })
82        .catch(() => null);
83    return r?.exitCode === 0 ? r.stdout.trim().toLowerCase() : '';
84}
85
86async function isClean($: EngineInterface, file: string) {
87    const r = await $.process
88        .run(['git', 'status', '--porcelain', '--', file], {
89            cwd: dirname(file),
90        })
91        .catch(() => null);
92    // the folder is gone, and the file with it
93    if (!r) return true;
94    if (r.exitCode === 0) return r.stdout.trim() === '';
95    // outside a repo nothing can be committed, so nothing is held
96    if (!/not a git repository/i.test(r.stderr))
97        $.ui.log(`x-mod-holds: git status failed on ${file}, hold released`);
98    return true;
99}
100
101// twin holder-gone — a copy lives in x-mod-guard; the twins lint keeps them equal
102// a holder that ended, went idle or died holds nothing
103async function isGone(
104    $: EngineInterface,
105    holder: Holder | undefined,
106    now: number,
107) {
108    if (!holder) return true;
109    if (holder.idleSince !== null && now - holder.idleSince >= IDLE_MS)
110        return true;
111    if (holder.pid && holder.start) {
112        const ps = await $.process.run([
113            'ps',
114            '-o',
115            'lstart=',
116            '-p',
117            String(holder.pid),
118        ]);
119        // a reused pid starts at another time
120        if (ps.stdout.trim() !== holder.start) return true;
121    }
122    return false;
123}
124// twin end
125
126async function isReleased(
127    $: EngineInterface,
128    sid: string,
129    hold: Hold,
130    now: number,
131) {
132    const holder = (await $.store.get(HOLDER + sid)) as Holder | undefined;
133    if (await isGone($, holder, now)) return true;
134    // a hold whose edit has not landed yet (a permission prompt open) is clean and still held
135    return hold.landed === true && isClean($, hold.file);
136}
137
138// a holder that crashed or went idle never settles its own keys
139async function sweep($: EngineInterface, self: string) {
140    const now = await $.clock.now();
141    for (const key of await $.store.keys()) {
142        if (!key.startsWith(HOLDER) || key === HOLDER + self) continue;
143        const holder = (await $.store.get(key)) as Holder | undefined;
144        if (await isGone($, holder, now))
145            await dropAll($, key.slice(HOLDER.length));
146    }
147}
148
149async function claimsOn($: EngineInterface, path: string) {
150    const claims: { sid: string; key: string; hold: Hold }[] = [];
151    for (const key of await $.store.keys()) {
152        const parsed = parseHoldKey(key);
153        if (parsed?.path !== path) continue;
154        const hold = (await $.store.get(key)) as Hold | undefined;
155        if (hold) claims.push({ hold, key, sid: parsed.sid });
156    }
157    return claims;
158}
159
160function refusal(file: string, sid: string, hold: Hold, now: number) {
161    const mins = Math.round((now - hold.at) / 60000);
162    return `x-mod-holds: ${file} is held by session ${short(sid)}, which took it ${mins} min ago. wait, or ask it to commit the file.`;
163}
164
165// the refusal when another live session holds the path; a released hold is cleared on the way
166async function heldBy(
167    $: EngineInterface,
168    sid: string,
169    file: string,
170    path: string,
171    now: number,
172) {
173    for (const c of await claimsOn($, path)) {
174        if (c.sid === sid) continue;
175        if (await isReleased($, c.sid, c.hold, now)) {
176            await $.store.delete(c.key);
177            continue;
178        }
179        await $.store.set(REFUSED + c.sid, { at: now, by: sid, path });
180        return refusal(file, c.sid, c.hold, now);
181    }
182    return undefined;
183}
184
185// a deny when another session holds the file; the key when this call took a new hold
186async function claim(
187    $: EngineInterface,
188    file: string,
189    proc: Proc | undefined,
190): Promise<Claim> {
191    const sid = await $.session.id();
192    const { key: path, file: real } = await realPath($, file);
193    const now = await $.clock.now();
194    const deny = await heldBy($, sid, file, path, now);
195    if (deny) return { deny };
196    const mine = holdKey(sid, path);
197    const held = (await $.store.get(mine)) as Hold | undefined;
198    // a first edit that failed left the hold unlanded; the next one that goes through lands it
199    if (held) return held.landed ? {} : { key: mine };
200    // the holder first: a rival reading the hold without it would take it for released
201    if (!(await $.store.get(HOLDER + sid)))
202        await $.store.set(HOLDER + sid, { ...proc, idleSince: null });
203    await $.store.set(mine, {
204        at: now,
205        file: real,
206        top: await topOf($, dirname(real)),
207    });
208    // no compare-and-set: a rival that wrote meanwhile refuses this claim; a true tie refuses both, the next try settles it
209    const rival = (await claimsOn($, path)).find((c) => c.sid !== sid);
210    if (!rival) return { key: mine };
211    await $.store.delete(mine);
212    return { deny: refusal(file, rival.sid, rival.hold, now) };
213}
214
215async function land($: EngineInterface, key: string) {
216    const hold = (await $.store.get(key)) as Hold | undefined;
217    if (hold) await $.store.set(key, { ...hold, landed: true });
218}
219
220async function markBusy($: EngineInterface) {
221    const sid = await $.session.id();
222    const holder = (await $.store.get(HOLDER + sid)) as Holder | undefined;
223    if (holder?.idleSince != null)
224        await $.store.set(HOLDER + sid, { ...holder, idleSince: null });
225}
226
227// drop this session's holds whose files are clean again; answers how many are left
228async function releaseClean($: EngineInterface, sid: string) {
229    let left = 0;
230    for (const key of await $.store.keys()) {
231        if (parseHoldKey(key)?.sid !== sid) continue;
232        const hold = (await $.store.get(key)) as Hold | undefined;
233        if (!hold || (await isClean($, hold.file))) await $.store.delete(key);
234        else left++;
235    }
236    return left;
237}
238
239// a commit run through the shell, `git commit` or `x lane commit`
240const COMMIT = /\b(git|x\s+lane)\s+(-C\s+\S+\s+)?commit\b/;
241
242// a turn ended: start the idle clock and drop the holds whose files are clean again
243async function settle($: EngineInterface) {
244    const sid = await $.session.id();
245    await sweep($, sid);
246    const holder = (await $.store.get(HOLDER + sid)) as Holder | undefined;
247    if (!holder) return;
248    if (await releaseClean($, sid)) {
249        await $.store.set(HOLDER + sid, {
250            ...holder,
251            idleSince: await $.clock.now(),
252        });
253        return;
254    }
255    await $.store.delete(HOLDER + sid);
256    await $.store.delete(REFUSED + sid);
257}
258
259async function dropAll($: EngineInterface, sid: string) {
260    for (const key of await $.store.keys())
261        if (parseHoldKey(key)?.sid === sid) await $.store.delete(key);
262    await $.store.delete(HOLDER + sid);
263    await $.store.delete(REFUSED + sid);
264}
265
266// fail-open: a store or git error lets the edit through, with a line in the transcript
267// the tool input is the model's: a path that is not a string is not guarded
268async function guard($: EngineInterface, file: unknown): Promise<Claim> {
269    if (typeof file !== 'string') return {};
270    try {
271        return await claim($, file, proc);
272    } catch (err) {
273        $.ui.log(
274            `x-mod-holds: ${errorText(err)}; the edit went through unguarded`,
275        );
276        return {};
277    }
278}
279
280export const register: Register = (on) => {
281    on('session.start', async ($, e, next) => {
282        proc = await procOf($).catch(() => {
283            $.ui.log(
284                'x-mod-holds: no pid for this session, a dead holder releases only by idle',
285            );
286            return undefined;
287        });
288        return next(e);
289    });
290
291    // a new turn: this session is no longer idle, so its holds keep
292    on('prompt.submit', async ($, e, next) => {
293        await markBusy($).catch(() => undefined);
294        return next(e);
295    });
296
297    on('turn.complete', async ($, e, next) => {
298        const r = await next(e);
299        // a subagent's turn ending is not the session going idle
300        if (e.agentId) return r;
301        await settle($).catch(() =>
302            $.ui.log("x-mod-holds: could not settle this turn's holds"),
303        );
304        return r;
305    });
306
307    on('session.end', async ($, e, next) => {
308        await dropAll($, e.sessionId).catch(() => undefined);
309        return next(e);
310    });
311
312    // `/clear` and `/resume` leave the conversation: its holds go now
313    on('command.run', async ($, e, next) => {
314        if (e.command !== 'clear' && e.command !== 'resume') return next(e);
315        const left = await $.session.id().catch(() => undefined);
316        const r = await next(e);
317        if (left) await dropAll($, left).catch(() => undefined);
318        return r;
319    });
320
321    on(
322        'tool.call',
323        { tool: /^(Edit|Write|NotebookEdit)$/ },
324        async ($, e, next) => {
325            const g = await guard(
326                $,
327                'notebook_path' in e
328                    ? e.notebook_path
329                    : 'file_path' in e
330                      ? e.file_path
331                      : undefined,
332            );
333            if (g.deny) return { deny: g.deny };
334            const r = await next(e);
335            if (g.key && r.deny === undefined && !r.isError)
336                await land($, g.key).catch(() => undefined);
337            return r;
338        },
339    );
340
341    // a commit made through Bash releases its clean files now, not at the turn's end
342    on('tool.call', { tool: 'Bash' }, async ($, e, next) => {
343        const command = 'command' in e ? e.command : undefined;
344        const r = await next(e);
345        if (typeof command === 'string' && COMMIT.test(command))
346            await releaseClean($, await $.session.id()).catch(() =>
347                $.ui.log('x-mod-holds: could not release after a commit'),
348            );
349        return r;
350    });
351};
352