tring-chat 0.1.21 → 0.1.23

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
@@ -125,6 +125,12 @@ to the next finished session and counts how many are waiting. Two more buttons d
125
125
  phone cannot do to a terminal by itself: paste from the clipboard, and copy from the screen —
126
126
  the links on it with a tap each, or the screen as text to select from.
127
127
 
128
+ **A phone and a PC on the same session keep their own sizes.** A terminal has one size, so
129
+ it follows the device you are using: open, tap or type on the phone and it is laid out for
130
+ the phone; click, type or come back to the window on the PC and it is laid out for the PC
131
+ again, redrawn cleanly. While the other device has it, a terminal is drawn at that
132
+ device's size — narrower, or clipped — never garbled, with a note to click to fit it back.
133
+
128
134
  The daemon only listens on `127.0.0.1` by default. Reaching it from a phone means binding
129
135
  it to the network, and that traffic has to be encrypted — it carries the token, every
130
136
  keystroke you type into a shell and everything the shell prints back, which is exactly
@@ -547,7 +553,11 @@ button of its own in the bar under the tabs, with the count of cards waiting.
547
553
  ### Orchestrator agent
548
554
 
549
555
  Optional, off by default. Tick **Agent** in the Orchestrator's header and the centre
550
- becomes a Claude Code session of its own, with the cards in a column beside it. Instead of
556
+ becomes a Claude Code session of its own, with the cards in a column beside it. Drag
557
+ the bar between them to share the space: the terminal narrows or widens and refits as you
558
+ drag, and each side keeps a minimum. On a phone the cards are a band above the terminal
559
+ and the bar drags their height. The size is remembered per browser. A long reply or plan
560
+ on a card folds behind **Show all**. Instead of
551
561
  typing into each tile, you tell it what you want:
552
562
 
553
563
  > *Which tiles are on which branch? Ask the api tile to run its tests, and start a new
@@ -572,7 +582,9 @@ green"* — and it goes to the tile that has been working on the reporting box,
572
582
  already has the context. tring reads each tile's own Claude Code transcript (the path
573
583
  every hook reports) for Claude's title for the conversation, the prompts it was given and
574
584
  the files it edited, so a tile is found by what it has been doing even after its work is
575
- committed and its screen has moved on. When two tiles match about equally, or none
585
+ committed and its screen has moved on. The repositories an agent has edited and read in
586
+ count too, so a Claude started in your home directory that has spent the day in one
587
+ repository is found as working in that repository. When two tiles match about equally, or none
576
588
  clearly does, the agent asks you which rather than guessing.
577
589
 
578
590
  **Worktrees.** The agent works one branch, one worktree, one agent. A tile is placed
package/dist/tring.js CHANGED
@@ -688,6 +688,13 @@ var Session = class {
688
688
  this.signal((t, now) => t.input(now, inputKind(data)));
689
689
  this.pty.write(data);
690
690
  }
691
+ /** The PTY's size now: whichever client owns it (see size-owner.ts). */
692
+ get cols() {
693
+ return this.term.cols;
694
+ }
695
+ get rows() {
696
+ return this.term.rows;
697
+ }
691
698
  resize(cols, rows) {
692
699
  if (this.disposed || cols < 1 || rows < 1) return;
693
700
  this.pty.resize(cols, rows);
@@ -1236,7 +1243,7 @@ var ProjectManager = class _ProjectManager {
1236
1243
 
1237
1244
  // src/http.ts
1238
1245
  import { createReadStream } from "node:fs";
1239
- import { readdir as readdir4, realpath, stat as stat5 } from "node:fs/promises";
1246
+ import { readdir as readdir4, realpath, stat as stat6 } from "node:fs/promises";
1240
1247
  import os5 from "node:os";
1241
1248
  import path12 from "node:path";
1242
1249
 
@@ -1982,11 +1989,12 @@ async function uninstallHooks(file = defaultClaudeSettingsPath()) {
1982
1989
  }
1983
1990
 
1984
1991
  // src/orchestrator-tools.ts
1985
- import { stat as stat4 } from "node:fs/promises";
1992
+ import { stat as stat5 } from "node:fs/promises";
1986
1993
  import path11 from "node:path";
1987
1994
 
1988
1995
  // src/git-worktrees.ts
1989
1996
  import { execFile as execFile2 } from "node:child_process";
1997
+ import { stat as stat3 } from "node:fs/promises";
1990
1998
  import path9 from "node:path";
1991
1999
  import { promisify as promisify2 } from "node:util";
1992
2000
  var run2 = promisify2(execFile2);
@@ -2047,7 +2055,32 @@ function defaultWorktreePath(commonDir, existing, branch) {
2047
2055
  const repoDir = path9.basename(commonDir) === ".git" ? path9.dirname(commonDir) : commonDir;
2048
2056
  return path9.join(path9.dirname(repoDir), `${repoName(commonDir)}.worktrees`, slug);
2049
2057
  }
2058
+ var roots = /* @__PURE__ */ new Map();
2059
+ function worktreeRootOf(p) {
2060
+ const start = path9.resolve(p);
2061
+ const k = normal(start);
2062
+ let hit = roots.get(k);
2063
+ if (!hit) {
2064
+ hit = (async () => {
2065
+ let dir = start;
2066
+ for (let i = 0; i < 64; i++) {
2067
+ try {
2068
+ await stat3(path9.join(dir, ".git"));
2069
+ return dir;
2070
+ } catch {
2071
+ }
2072
+ const up = path9.dirname(dir);
2073
+ if (up === dir) return null;
2074
+ dir = up;
2075
+ }
2076
+ return null;
2077
+ })();
2078
+ roots.set(k, hit);
2079
+ }
2080
+ return hit;
2081
+ }
2050
2082
  var realGit = {
2083
+ rootOf: worktreeRootOf,
2051
2084
  async place(dir) {
2052
2085
  const out = await git2(dir, ["rev-parse", "--path-format=absolute", "--show-toplevel", "--git-dir", "--git-common-dir"]);
2053
2086
  const [root, gitDir, commonDir] = out?.trim().split(/\r?\n/) ?? [];
@@ -2090,9 +2123,17 @@ function typePrompt(target, text2) {
2090
2123
  }
2091
2124
 
2092
2125
  // src/transcript.ts
2093
- import { open, readdir as readdir3, stat as stat3 } from "node:fs/promises";
2126
+ import { open, readdir as readdir3, stat as stat4 } from "node:fs/promises";
2094
2127
  import path10 from "node:path";
2128
+ var SYSTEM_TAG = /^<(command-|local-command-|task-notification|system-reminder|user-prompt-submit-hook)/;
2095
2129
  var EDIT_TOOLS = /* @__PURE__ */ new Set(["Edit", "MultiEdit", "Write", "NotebookEdit"]);
2130
+ var READ_TOOLS = /* @__PURE__ */ new Set(["Read", "Grep", "Glob", "LS", "NotebookRead"]);
2131
+ var SHELL_TOOLS = /* @__PURE__ */ new Set(["Bash", "PowerShell"]);
2132
+ var MAX_PER_TURN = 40;
2133
+ var MAX_COMMAND = 300;
2134
+ var addCapped = (list, v) => {
2135
+ if (list.length < MAX_PER_TURN && !list.includes(v)) list.push(v);
2136
+ };
2096
2137
  var WHOLE_BYTES = 8 << 20;
2097
2138
  var HEAD_BYTES = 512 << 10;
2098
2139
  var TAIL_BYTES = 8 << 20;
@@ -2109,7 +2150,7 @@ function humanPrompt(j) {
2109
2150
  text2 = blocks.filter((b) => b.type === "text" && typeof b.text === "string").map((b) => b.text).join("\n") || null;
2110
2151
  }
2111
2152
  text2 = text2?.trim() ?? null;
2112
- if (!text2 || text2.startsWith("<")) return null;
2153
+ if (!text2 || SYSTEM_TAG.test(text2)) return null;
2113
2154
  return text2;
2114
2155
  }
2115
2156
  function parseTranscript(lines) {
@@ -2138,21 +2179,32 @@ function parseTranscript(lines) {
2138
2179
  if (!Array.isArray(blocks)) continue;
2139
2180
  const texts = [];
2140
2181
  const files = [];
2182
+ const paths = [];
2183
+ const commands = [];
2141
2184
  for (const b of blocks) {
2142
2185
  if (b.type === "text" && b.text?.trim()) texts.push(b.text.trim());
2143
- if (b.type === "tool_use" && b.name && EDIT_TOOLS.has(b.name)) {
2144
- const f = b.input?.["file_path"] ?? b.input?.["notebook_path"];
2186
+ if (b.type !== "tool_use" || !b.name) continue;
2187
+ const input = b.input ?? {};
2188
+ if (EDIT_TOOLS.has(b.name)) {
2189
+ const f = input["file_path"] ?? input["notebook_path"];
2145
2190
  if (typeof f === "string") files.push(f);
2191
+ } else if (READ_TOOLS.has(b.name)) {
2192
+ const p = input["file_path"] ?? input["path"] ?? input["notebook_path"];
2193
+ if (typeof p === "string" && p) addCapped(paths, p);
2194
+ } else if (SHELL_TOOLS.has(b.name) && typeof input["command"] === "string") {
2195
+ addCapped(commands, input["command"].slice(0, MAX_COMMAND));
2146
2196
  }
2147
2197
  }
2148
- if (!texts.length && !files.length) continue;
2149
- const last = turns[turns.length - 1];
2150
- if (last?.role === "assistant") {
2151
- if (texts.length) last.text = [last.text, ...texts].filter(Boolean).join("\n\n");
2152
- if (files.length) last.files = [.../* @__PURE__ */ new Set([...last.files ?? [], ...files])];
2153
- } else {
2154
- turns.push({ role: "assistant", text: texts.join("\n\n"), at, ...files.length ? { files: [...new Set(files)] } : {} });
2198
+ if (!texts.length && !files.length && !paths.length && !commands.length) continue;
2199
+ let last = turns[turns.length - 1];
2200
+ if (last?.role !== "assistant") {
2201
+ last = { role: "assistant", text: "", at };
2202
+ turns.push(last);
2155
2203
  }
2204
+ if (texts.length) last.text = [last.text, ...texts].filter(Boolean).join("\n\n");
2205
+ if (files.length) last.files = [.../* @__PURE__ */ new Set([...last.files ?? [], ...files])];
2206
+ for (const p of paths) addCapped(last.paths ??= [], p);
2207
+ for (const c of commands) addCapped(last.commands ??= [], c);
2156
2208
  }
2157
2209
  return { title, turns };
2158
2210
  }
@@ -2171,7 +2223,7 @@ var CACHE_LIMIT = 48;
2171
2223
  async function readTranscript(file) {
2172
2224
  let info;
2173
2225
  try {
2174
- info = await stat3(file);
2226
+ info = await stat4(file);
2175
2227
  } catch {
2176
2228
  return null;
2177
2229
  }
@@ -2200,6 +2252,14 @@ async function readTranscript(file) {
2200
2252
  }
2201
2253
  async function findTranscript(projectsDir, id) {
2202
2254
  if (!/^[0-9a-f-]{36}$/i.test(id)) return null;
2255
+ const known = located.get(id);
2256
+ if (known) {
2257
+ try {
2258
+ if ((await stat4(known)).isFile()) return known;
2259
+ } catch {
2260
+ }
2261
+ located.delete(id);
2262
+ }
2203
2263
  let dirs;
2204
2264
  try {
2205
2265
  dirs = await readdir3(projectsDir);
@@ -2209,12 +2269,16 @@ async function findTranscript(projectsDir, id) {
2209
2269
  for (const d of dirs) {
2210
2270
  const f = path10.join(projectsDir, d, `${id}.jsonl`);
2211
2271
  try {
2212
- if ((await stat3(f)).isFile()) return f;
2272
+ if ((await stat4(f)).isFile()) {
2273
+ located.set(id, f);
2274
+ return f;
2275
+ }
2213
2276
  } catch {
2214
2277
  }
2215
2278
  }
2216
2279
  return null;
2217
2280
  }
2281
+ var located = /* @__PURE__ */ new Map();
2218
2282
 
2219
2283
  // src/orchestrator-tools.ts
2220
2284
  var ToolError = class extends Error {
@@ -2344,7 +2408,7 @@ var PROMPT_GRACE_MS = 15e3;
2344
2408
  var clip = (s, n) => s.length > n ? `${s.slice(0, n)}\u2026 (${s.length - n} more characters)` : s;
2345
2409
  async function isDirectory(p) {
2346
2410
  try {
2347
- return (await stat4(p)).isDirectory();
2411
+ return (await stat5(p)).isDirectory();
2348
2412
  } catch {
2349
2413
  return false;
2350
2414
  }
@@ -2441,6 +2505,7 @@ var OrchestratorTools = class {
2441
2505
  const placed = await this.placeAll();
2442
2506
  const byId = new Map(placed.map((p) => [p.s.id, p]));
2443
2507
  const talks = new Map(await Promise.all(placed.map(async (p) => [p.s.id, await this.history(p.s)])));
2508
+ const worked = new Map(await Promise.all(placed.map(async (p) => [p.s.id, await this.workedIn(talks.get(p.s.id) ?? null)])));
2444
2509
  const out = projects.map((p) => ({
2445
2510
  project: p.name,
2446
2511
  id: p.id,
@@ -2464,6 +2529,7 @@ var OrchestratorTools = class {
2464
2529
  ...shared.length ? { sameWorktreeAs: shared } : {},
2465
2530
  agent: s?.claude ? "claude" : null,
2466
2531
  ...conversationSummary(talks.get(info.id) ?? null),
2532
+ ...workedSummary(worked.get(info.id) ?? []),
2467
2533
  ...waiting.length ? { waitingOnUser: waiting.map(summary) } : {},
2468
2534
  ...s?.lastMessage ? { lastMessage: clip(s.lastMessage, MAX_LAST_MESSAGE) } : {}
2469
2535
  };
@@ -2487,8 +2553,8 @@ var OrchestratorTools = class {
2487
2553
  if (project) r.projects.add(project);
2488
2554
  repos.set(k, r);
2489
2555
  };
2490
- const roots = await Promise.all(projects.map(async (p) => ({ p, place: await this.git.place(p.root) })));
2491
- for (const { p, place } of roots) add2(place, p.root, p.name);
2556
+ const roots2 = await Promise.all(projects.map(async (p) => ({ p, place: await this.git.place(p.root) })));
2557
+ for (const { p, place } of roots2) add2(place, p.root, p.name);
2492
2558
  const wanted = new Set(projects.map((p) => p.id));
2493
2559
  for (const pl of placed) if (wanted.has(pl.s.projectId)) add2(pl.place, workdir(pl.s));
2494
2560
  if (repos.size === 0) return "No git repositories: none of these projects or tiles is inside one.";
@@ -2514,14 +2580,48 @@ var OrchestratorTools = class {
2514
2580
  }));
2515
2581
  return JSON.stringify({ repos: out }, null, 2);
2516
2582
  }
2583
+ /**
2584
+ * The worktrees an agent has really been working in, by the files it edited
2585
+ * and read and the paths in the commands it ran — not where its shell sits.
2586
+ * A Claude started in the home directory that spends the day editing one
2587
+ * repository is working in that repository.
2588
+ */
2589
+ async workedIn(talk) {
2590
+ if (!talk) return [];
2591
+ const tally = /* @__PURE__ */ new Map();
2592
+ const count = async (p, kind) => {
2593
+ if (!path11.isAbsolute(p)) return;
2594
+ const root = await this.git.rootOf(p);
2595
+ if (!root) return;
2596
+ const k = normal(root);
2597
+ const t = tally.get(k) ?? { root, edits: 0, reads: 0 };
2598
+ t[kind]++;
2599
+ tally.set(k, t);
2600
+ };
2601
+ const jobs = [];
2602
+ for (const t of talk.turns) {
2603
+ for (const f of t.files ?? []) jobs.push(count(f, "edits"));
2604
+ for (const p of t.paths ?? []) jobs.push(count(p, "reads"));
2605
+ for (const c of t.commands ?? []) for (const p of pathsIn(c)) jobs.push(count(p, "reads"));
2606
+ }
2607
+ await Promise.all(jobs);
2608
+ return [...tally.values()].sort((a, b) => b.edits * 3 + b.reads - (a.edits * 3 + a.reads)).slice(0, 5);
2609
+ }
2517
2610
  /** The tile's conversation, from the transcript its hooks named, or found by id. */
2518
2611
  async history(s) {
2519
2612
  const t = this.d.transcripts ?? {
2520
2613
  read: readTranscript,
2521
2614
  find: (id) => findTranscript(defaultTranscriptDir(), id)
2522
2615
  };
2523
- const file = s.transcript ?? (s.claude ? await t.find(s.claude.id) : null);
2524
- return file ? t.read(file) : null;
2616
+ if (s.transcript) {
2617
+ const talk2 = await t.read(s.transcript);
2618
+ if (talk2) return talk2;
2619
+ }
2620
+ const found = s.claude ? await t.find(s.claude.id) : null;
2621
+ if (!found || found === s.transcript) return null;
2622
+ const talk = await t.read(found);
2623
+ if (talk) s.transcript = found;
2624
+ return talk;
2525
2625
  }
2526
2626
  async sessionHistory(s, count, search) {
2527
2627
  const talk = await this.history(s);
@@ -2560,11 +2660,17 @@ ${body.join("\n\n")}`;
2560
2660
  const placed = await this.placeAll();
2561
2661
  const docs = await Promise.all(placed.map(async (p) => {
2562
2662
  const talk = await this.history(p.s);
2663
+ const worked = await this.workedIn(talk);
2563
2664
  const fields = [
2564
2665
  { why: "name", text: [p.s.name, p.s.title].filter(Boolean).join(" "), weight: 4 },
2565
2666
  { why: "branch", text: [p.place?.branch, p.place?.root].filter(Boolean).join(" "), weight: 4 },
2566
2667
  { why: "title", text: talk?.title ?? "", weight: 4 },
2567
- { why: "last message", text: p.s.lastMessage ?? "", weight: 1 }
2668
+ { why: "worked in", text: worked.map((w) => w.root).join(" "), weight: 4 },
2669
+ { why: "last message", text: p.s.lastMessage ?? "", weight: 1 },
2670
+ // What is on its terminal. With no conversation to read — a shell, a
2671
+ // Claude whose transcript cannot be found — it is the tile's only
2672
+ // record of what it is doing, and counts for as much as a title.
2673
+ { why: talk ? "screen" : "screen only", text: p.s.recentText(SCREEN_LINES), weight: talk ? 1 : 3 }
2568
2674
  ];
2569
2675
  const turns = talk?.turns ?? [];
2570
2676
  turns.forEach((t, i) => {
@@ -2572,15 +2678,19 @@ ${body.join("\n\n")}`;
2572
2678
  if (t.role === "user") fields.push({ why: "prompt", text: t.text, weight: 3 * recent });
2573
2679
  else fields.push({ why: "agent said", text: t.text, weight: recent });
2574
2680
  if (t.files?.length) fields.push({ why: "edited", text: t.files.join(" "), weight: 3 * recent });
2681
+ if (t.paths?.length) fields.push({ why: "read", text: t.paths.join(" "), weight: recent });
2682
+ if (t.commands?.length) fields.push({ why: "ran", text: t.commands.join(" "), weight: recent });
2575
2683
  });
2576
2684
  return { p, fields };
2577
2685
  }));
2578
2686
  const df = new Map(ws.map((w) => [w, docs.filter((d) => d.fields.some((f) => f.text.toLowerCase().includes(w))).length]));
2687
+ const known = ws.filter((w) => df.get(w) > 0);
2579
2688
  const ranked = docs.map(({ p, fields }) => {
2580
2689
  let score = 0;
2581
2690
  const why = /* @__PURE__ */ new Set();
2582
2691
  let best = null;
2583
- let confident = false;
2692
+ let whole = false;
2693
+ const strong = /* @__PURE__ */ new Set();
2584
2694
  for (const f of fields) {
2585
2695
  const low = f.text.toLowerCase();
2586
2696
  const hit = ws.filter((w) => low.includes(w));
@@ -2589,8 +2699,10 @@ ${body.join("\n\n")}`;
2589
2699
  score += s;
2590
2700
  why.add(f.why);
2591
2701
  if (!best || s > best.score) best = { score: s, text: snippet(f.text, hit[0]) };
2592
- if (hit.length === ws.length || STRONG.has(f.why) && hit.length >= ws.length / 2) confident = true;
2702
+ if (hit.length === ws.length) whole = true;
2703
+ if (STRONG.has(f.why)) for (const w of hit) strong.add(w);
2593
2704
  }
2705
+ const confident = whole || strong.size >= Math.max(1, known.length / 2) || [...strong].some((w) => df.get(w) === 1);
2594
2706
  return { p, score, confident, why: [...why], snippet: best?.text ?? "" };
2595
2707
  }).filter((r) => r.score > 0).sort((a, b) => b.score - a.score);
2596
2708
  const top = ranked.slice(0, 5);
@@ -2796,7 +2908,24 @@ function conversationSummary(t) {
2796
2908
  }
2797
2909
  };
2798
2910
  }
2799
- var STRONG = /* @__PURE__ */ new Set(["name", "branch", "title", "prompt", "edited"]);
2911
+ var STRONG = /* @__PURE__ */ new Set(["name", "branch", "title", "worked in", "prompt", "edited", "screen only"]);
2912
+ var SCREEN_LINES = 200;
2913
+ function workedSummary(w) {
2914
+ if (!w.length) return {};
2915
+ return { workedIn: w.map((x) => `${x.root} (${x.edits} edits, ${x.reads} reads)`) };
2916
+ }
2917
+ function pathsIn(command) {
2918
+ const out = /* @__PURE__ */ new Set();
2919
+ const abs = /^(?:[A-Za-z]:[\\/]|\/(?!\/))/;
2920
+ for (const m of command.matchAll(/"([^"\n]+)"|'([^'\n]+)'/g)) {
2921
+ const p = (m[1] ?? m[2] ?? "").trim();
2922
+ if (abs.test(p)) out.add(p);
2923
+ }
2924
+ for (const m of command.replace(/"[^"\n]*"|'[^'\n]*'/g, " ").matchAll(/(?:^|[\s=(])((?:[A-Za-z]:[\\/]|\/)[^\s"'`;|&<>()]+)/g)) {
2925
+ if (abs.test(m[1]) && m[1] !== "/") out.add(m[1]);
2926
+ }
2927
+ return [...out].slice(0, 10);
2928
+ }
2800
2929
  var STOP = /* @__PURE__ */ new Set([
2801
2930
  "the",
2802
2931
  "and",
@@ -2853,7 +2982,56 @@ var STOP = /* @__PURE__ */ new Set([
2853
2982
  "work",
2854
2983
  "working",
2855
2984
  "thing",
2856
- "there"
2985
+ "there",
2986
+ "since",
2987
+ "because",
2988
+ "when",
2989
+ "where",
2990
+ "what",
2991
+ "which",
2992
+ "while",
2993
+ "about",
2994
+ "after",
2995
+ "before",
2996
+ "still",
2997
+ "very",
2998
+ "really",
2999
+ "only",
3000
+ "even",
3001
+ "more",
3002
+ "most",
3003
+ "much",
3004
+ "many",
3005
+ "other",
3006
+ "over",
3007
+ "under",
3008
+ "again",
3009
+ "seems",
3010
+ "look",
3011
+ "looks",
3012
+ "see",
3013
+ "show",
3014
+ "shows",
3015
+ "does",
3016
+ "doesn",
3017
+ "don",
3018
+ "did",
3019
+ "will",
3020
+ "won",
3021
+ "cannot",
3022
+ "edit",
3023
+ "sure",
3024
+ "should",
3025
+ "here",
3026
+ "they",
3027
+ "them",
3028
+ "their",
3029
+ "what",
3030
+ "who",
3031
+ "how",
3032
+ "why",
3033
+ "yes",
3034
+ "okay"
2857
3035
  ]);
2858
3036
  function words(query) {
2859
3037
  const out = query.toLowerCase().split(/[^a-z0-9]+/).filter((w) => w.length >= 3 && !STOP.has(w)).map((w) => w.length > 5 ? w.replace(/(ing|ed|es|s)$/, "") : w);
@@ -2971,8 +3149,8 @@ function createHandler(opts) {
2971
3149
  }
2972
3150
  };
2973
3151
  const browsable = async (dir) => {
2974
- const roots = [homeDir(), ...pm.list().map((p) => p.root), ...opts.fsRoots ?? []];
2975
- const [target, ...resolved] = await Promise.all([dir, ...roots].map(real));
3152
+ const roots2 = [homeDir(), ...pm.list().map((p) => p.root), ...opts.fsRoots ?? []];
3153
+ const [target, ...resolved] = await Promise.all([dir, ...roots2].map(real));
2976
3154
  return resolved.some((root) => within(root, target));
2977
3155
  };
2978
3156
  return async function handle(req, res) {
@@ -3159,7 +3337,7 @@ function createHandler(opts) {
3159
3337
  return;
3160
3338
  }
3161
3339
  try {
3162
- const info = await stat5(file);
3340
+ const info = await stat6(file);
3163
3341
  if (!info.isFile()) throw new Error("not a file");
3164
3342
  head(res, 200, MIME[path12.extname(file)] ?? "application/octet-stream");
3165
3343
  createReadStream(file).pipe(res);
@@ -3174,7 +3352,36 @@ function createHandler(opts) {
3174
3352
  }
3175
3353
  }
3176
3354
 
3355
+ // src/size-owner.ts
3356
+ var SizeOwners = class {
3357
+ owners = /* @__PURE__ */ new Map();
3358
+ owner(sessionId) {
3359
+ return this.owners.get(sessionId);
3360
+ }
3361
+ /** Makes `client` the owner. True when it was not already. */
3362
+ claim(sessionId, client) {
3363
+ if (this.owners.get(sessionId) === client) return false;
3364
+ this.owners.set(sessionId, client);
3365
+ return true;
3366
+ }
3367
+ /** A resize nobody asked to win: only the owner's, or one for an unowned session, applies. */
3368
+ mayResize(sessionId, client) {
3369
+ const o = this.owners.get(sessionId);
3370
+ return o === void 0 || o === client;
3371
+ }
3372
+ /** The client looked away from the session or went away: it owns nothing there any more. */
3373
+ release(client, sessionId) {
3374
+ for (const [id, o] of this.owners) {
3375
+ if (o === client && (sessionId === void 0 || id === sessionId)) this.owners.delete(id);
3376
+ }
3377
+ }
3378
+ };
3379
+
3177
3380
  // src/ws.ts
3381
+ function validSize(cols, rows) {
3382
+ const ok = (n) => typeof n === "number" && Number.isInteger(n) && n >= 1 && n <= 2e3;
3383
+ return ok(cols) && ok(rows) ? { cols, rows } : null;
3384
+ }
3178
3385
  var Hub = class {
3179
3386
  constructor(opts) {
3180
3387
  this.opts = opts;
@@ -3210,6 +3417,8 @@ var Hub = class {
3210
3417
  clients = /* @__PURE__ */ new Set();
3211
3418
  timer;
3212
3419
  update = null;
3420
+ /** Which client each session's PTY is sized for. */
3421
+ sizes = new SizeOwners();
3213
3422
  /** The registry check is async and must never delay startup, so the notice
3214
3423
  * arrives later and is pushed to whoever is already connected. */
3215
3424
  setUpdate(update) {
@@ -3223,9 +3432,12 @@ var Hub = class {
3223
3432
  clearInterval(this.timer);
3224
3433
  }
3225
3434
  accept(ws) {
3226
- const client = { ws, authed: false, projectId: null, focusedId: null };
3435
+ const client = { ws, authed: false, projectId: null, focusedId: null, size: null };
3227
3436
  this.clients.add(client);
3228
- ws.on("close", () => this.clients.delete(client));
3437
+ ws.on("close", () => {
3438
+ this.clients.delete(client);
3439
+ this.sizes.release(client);
3440
+ });
3229
3441
  ws.on("message", (raw, isBinary) => {
3230
3442
  if (isBinary) return;
3231
3443
  let msg;
@@ -3263,7 +3475,7 @@ var Hub = class {
3263
3475
  case "activateProject": {
3264
3476
  pm.activate(msg.projectId);
3265
3477
  c.projectId = msg.projectId;
3266
- c.focusedId = null;
3478
+ c.focusedId = this.keepFocus(c);
3267
3479
  this.sendState(c);
3268
3480
  this.sendSnapshots(c);
3269
3481
  break;
@@ -3280,7 +3492,7 @@ var Hub = class {
3280
3492
  pm.deleteProject(msg.projectId);
3281
3493
  if (c.projectId === msg.projectId) {
3282
3494
  c.projectId = pm.activeProjectId;
3283
- c.focusedId = null;
3495
+ c.focusedId = this.keepFocus(c);
3284
3496
  }
3285
3497
  break;
3286
3498
  case "create":
@@ -3292,11 +3504,13 @@ var Hub = class {
3292
3504
  });
3293
3505
  break;
3294
3506
  case "focus": {
3507
+ if (c.focusedId && c.focusedId !== msg.id) this.sizes.release(c, c.focusedId);
3295
3508
  c.focusedId = msg.id;
3509
+ c.size = validSize(msg.cols, msg.rows);
3296
3510
  if (!msg.id) break;
3297
3511
  const s = this.find(msg.id);
3298
3512
  if (!s) break;
3299
- s.resize(msg.cols, msg.rows);
3513
+ this.take(c, s, false);
3300
3514
  this.send(c, { type: "screen", id: s.id, ansi: s.serialize() });
3301
3515
  break;
3302
3516
  }
@@ -3305,7 +3519,10 @@ var Hub = class {
3305
3519
  break;
3306
3520
  }
3307
3521
  case "resize": {
3308
- if (c.focusedId) this.find(c.focusedId)?.resize(msg.cols, msg.rows);
3522
+ c.size = validSize(msg.cols, msg.rows);
3523
+ const s = c.focusedId ? this.find(c.focusedId) : void 0;
3524
+ if (!s) break;
3525
+ if (msg.claim === true || this.sizes.mayResize(s.id, c)) this.take(c, s, true);
3309
3526
  break;
3310
3527
  }
3311
3528
  case "agent": {
@@ -3417,6 +3634,35 @@ var Hub = class {
3417
3634
  broadcastAuto() {
3418
3635
  if (this.opts.auto) this.broadcast(this.autoMessage(this.opts.auto));
3419
3636
  }
3637
+ /**
3638
+ * What a socket stays focused on when its project changes: the orchestrator
3639
+ * agent, which is in no project, and nothing else.
3640
+ */
3641
+ keepFocus(c) {
3642
+ return c.focusedId && this.opts.agent?.find(c.focusedId) ? c.focusedId : null;
3643
+ }
3644
+ /**
3645
+ * Sizes `s`'s PTY for `c` and makes `c` its owner (see size-owner.ts).
3646
+ *
3647
+ * Every client watching `s` is told the size and whether it is theirs; the
3648
+ * ones that are not draw at exactly that size. When the size really changed,
3649
+ * the others are sent a fresh screen at it, and so is `c` when `replay` —
3650
+ * a device taking the size back had been drawing at another device's size,
3651
+ * and a clean copy from the daemon's mirror is what stops it staying
3652
+ * garbled. The program's own redraw (it gets SIGWINCH) follows as output.
3653
+ */
3654
+ take(c, s, replay) {
3655
+ if (!c.size) return;
3656
+ const newOwner = this.sizes.claim(s.id, c);
3657
+ const changed = s.cols !== c.size.cols || s.rows !== c.size.rows;
3658
+ if (changed) s.resize(c.size.cols, c.size.rows);
3659
+ if (!newOwner && !changed) return;
3660
+ for (const o of this.clients) {
3661
+ if (!o.authed || o.focusedId !== s.id) continue;
3662
+ this.send(o, { type: "size", id: s.id, cols: s.cols, rows: s.rows, mine: o === c });
3663
+ if (changed && (o !== c || replay)) this.send(o, { type: "screen", id: s.id, ansi: s.serialize() });
3664
+ }
3665
+ }
3420
3666
  /** A tile, or the orchestrator agent's own terminal. */
3421
3667
  find(id) {
3422
3668
  return this.opts.pm.findSession(id) ?? this.opts.agent?.find(id);
@@ -3461,11 +3707,11 @@ function isWsl() {
3461
3707
  }
3462
3708
  function wslCandidates() {
3463
3709
  const user = process.env["WSL_USER"] ?? "";
3464
- const roots = ["/mnt/c/Program Files", "/mnt/c/Program Files (x86)"];
3710
+ const roots2 = ["/mnt/c/Program Files", "/mnt/c/Program Files (x86)"];
3465
3711
  const paths = [
3466
- ...roots.map((r) => `${r}/Google/Chrome/Application/chrome.exe`),
3467
- ...roots.map((r) => `${r}/Microsoft/Edge/Application/msedge.exe`),
3468
- ...roots.map((r) => `${r}/BraveSoftware/Brave-Browser/Application/brave.exe`)
3712
+ ...roots2.map((r) => `${r}/Google/Chrome/Application/chrome.exe`),
3713
+ ...roots2.map((r) => `${r}/Microsoft/Edge/Application/msedge.exe`),
3714
+ ...roots2.map((r) => `${r}/BraveSoftware/Brave-Browser/Application/brave.exe`)
3469
3715
  ];
3470
3716
  if (user) paths.push(`/mnt/c/Users/${user}/AppData/Local/Google/Chrome/Application/chrome.exe`);
3471
3717
  return paths;
@@ -4139,9 +4385,10 @@ you get the work done through the agents in those tiles.
4139
4385
 
4140
4386
  - \`list_sessions\` \u2014 every project and tile: status (busy = working, done =
4141
4387
  finished and waiting, idle, exited), the directory its agent works in, its
4142
- repository, worktree and branch, whether it runs Claude Code, what it is
4143
- waiting on, and what its agent last said. \`sameWorktreeAs\` marks tiles
4144
- sharing a worktree. Start here whenever you need to know what is going on.
4388
+ repository, worktree and branch, the repositories its agent has edited in
4389
+ (\`workedIn\`), whether it runs Claude Code, what it is waiting on, and what
4390
+ its agent last said. \`sameWorktreeAs\` marks tiles sharing a worktree.
4391
+ Start here whenever you need to know what is going on.
4145
4392
  - \`list_worktrees\` \u2014 every worktree of each repository, its branch, and
4146
4393
  which tiles are in it. Free worktrees are the ones with no tiles.
4147
4394
  - \`find_work\` \u2014 which tiles have been working on a topic, ranked: by name,
@@ -4190,6 +4437,16 @@ to the agent that has been working on that, which already has the context.
4190
4437
  4. A clear match that is busy, waiting on the user, or exited: say so, and ask
4191
4438
  whether to queue it there or start a new tile.
4192
4439
 
4440
+ A tile's directory is where its shell started, not what it works on. A Claude
4441
+ started in the home directory may spend all day editing one repository:
4442
+ \`workedIn\` in \`list_sessions\` lists the repositories its agent has really
4443
+ edited and read in. When the user names an app or repository ("edit tring"),
4444
+ look there and in \`find_work\`, not only at directories and branches.
4445
+
4446
+ Never search the disk for a repository (no recursive listings of drives or
4447
+ home folders): it is slow and the user has to stop it. If the tools do not
4448
+ show it, ask the user for the path.
4449
+
4193
4450
  ## Git worktrees
4194
4451
 
4195
4452
  The user works in git worktrees: one branch, one worktree, one agent. Treat