@sealant/mend 0.35.1 → 0.36.0-next.1033

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 (97) hide show
  1. package/README.md +39 -7
  2. package/dist/chunk-QHWF3YTC.js +24234 -0
  3. package/dist/{dashboard-MGR4YUFD.js → dashboard-OITCD5JU.js} +1351 -352
  4. package/dist/main.js +11319 -2034
  5. package/man/mend-accounts.1 +1 -1
  6. package/man/mend-adopt.1 +4 -4
  7. package/man/mend-agent-logins.1 +20 -0
  8. package/man/mend-attach.1 +1 -1
  9. package/man/mend-codex.1 +9 -7
  10. package/man/mend-completions.1 +1 -1
  11. package/man/mend-connect-pi.1 +28 -0
  12. package/man/mend-connect.1 +6 -2
  13. package/man/mend-continue.1 +1 -1
  14. package/man/mend-doctor.1 +2 -2
  15. package/man/mend-dotfiles-repo.1 +1 -1
  16. package/man/mend-dotfiles-sync.1 +1 -1
  17. package/man/mend-dotfiles.1 +1 -1
  18. package/man/mend-env-cluster.1 +4 -1
  19. package/man/mend-env-load.1 +1 -1
  20. package/man/mend-env-show.1 +1 -1
  21. package/man/mend-folder-create.1 +1 -1
  22. package/man/mend-folder-list.1 +1 -1
  23. package/man/mend-folder-push.1 +1 -1
  24. package/man/mend-folder-rm.1 +1 -1
  25. package/man/mend-git-author.1 +1 -1
  26. package/man/mend-help.1 +1 -1
  27. package/man/mend-invite.1 +1 -1
  28. package/man/mend-keys-init.1 +1 -1
  29. package/man/mend-keys-mode.1 +1 -1
  30. package/man/mend-keys-share.1 +1 -1
  31. package/man/mend-keys-show.1 +1 -1
  32. package/man/mend-land.1 +1 -1
  33. package/man/mend-login.1 +10 -2
  34. package/man/mend-logout.1 +1 -1
  35. package/man/mend-logs.1 +37 -0
  36. package/man/mend-man.1 +1 -1
  37. package/man/mend-members.1 +1 -1
  38. package/man/mend-memory-import.1 +23 -0
  39. package/man/mend-memory-rm.1 +15 -0
  40. package/man/mend-memory-show.1 +15 -0
  41. package/man/mend-memory.1 +32 -0
  42. package/man/mend-models.1 +22 -0
  43. package/man/mend-operator-exposure.1 +2 -2
  44. package/man/mend-operator-gate.1 +1 -1
  45. package/man/mend-operator-grant-owner.1 +1 -1
  46. package/man/mend-operator-org-create.1 +1 -1
  47. package/man/mend-operator-org-invite-owner.1 +1 -1
  48. package/man/mend-operator-org-list.1 +1 -1
  49. package/man/mend-operator-org-rename.1 +1 -1
  50. package/man/mend-operator-reset-link.1 +1 -1
  51. package/man/mend-pair.1 +3 -1
  52. package/man/mend-projects.1 +10 -2
  53. package/man/mend-pull.1 +6 -3
  54. package/man/mend-refresh.1 +6 -2
  55. package/man/mend-rejoin.1 +1 -1
  56. package/man/mend-resume.1 +1 -1
  57. package/man/mend-run.1 +37 -4
  58. package/man/mend-secrets-add.1 +24 -0
  59. package/man/mend-secrets-rm.1 +14 -0
  60. package/man/mend-secrets.1 +18 -0
  61. package/man/mend-server-logs.1 +1 -1
  62. package/man/mend-server-restart.1 +1 -1
  63. package/man/mend-server-setup.1 +125 -8
  64. package/man/mend-server-start.1 +1 -1
  65. package/man/mend-server-status.1 +7 -3
  66. package/man/mend-server-stop.1 +3 -3
  67. package/man/mend-server-upgrade.1 +14 -2
  68. package/man/mend-server.1 +1 -1
  69. package/man/mend-service-add.1 +1 -1
  70. package/man/mend-service-connect.1 +1 -1
  71. package/man/mend-service-init.1 +1 -1
  72. package/man/mend-service-list.1 +10 -4
  73. package/man/mend-service-logs.1 +3 -1
  74. package/man/mend-service-restart.1 +1 -1
  75. package/man/mend-service-run.1 +16 -4
  76. package/man/mend-service-stop.1 +1 -1
  77. package/man/mend-session-share.1 +13 -3
  78. package/man/mend-sessions.1 +3 -1
  79. package/man/mend-shell.1 +1 -1
  80. package/man/mend-skills-push.1 +1 -1
  81. package/man/mend-skills.1 +1 -1
  82. package/man/mend-snake.1 +7 -3
  83. package/man/mend-ssh-keys-remove.1 +18 -0
  84. package/man/mend-ssh-keys.1 +15 -0
  85. package/man/mend-ssh-setup.1 +2 -2
  86. package/man/mend-ssh.1 +17 -4
  87. package/man/mend-stop.1 +1 -1
  88. package/man/mend-ui.1 +4 -2
  89. package/man/mend-uninstall.1 +10 -4
  90. package/man/mend-version.1 +1 -1
  91. package/man/mend-wait.1 +28 -0
  92. package/man/mend-workspace-replace.1 +24 -0
  93. package/man/mend-worktrees-rm.1 +29 -0
  94. package/man/mend-worktrees.1 +2 -2
  95. package/man/mend.1 +61 -7
  96. package/package.json +22 -41
  97. package/dist/chunk-SMH65F6Z.js +0 -29007
@@ -1,21 +1,37 @@
1
1
  import {
2
+ ADOPT_MODE_ORDER,
2
3
  HARNESS_COMMANDS,
3
4
  LIVE_STATUSES,
4
- RepositoryCloneUrl,
5
5
  agentIsLive,
6
6
  agentOutcome,
7
7
  captureLineOf,
8
+ checkpointSourceWords,
8
9
  createSseParser,
9
10
  cwdFacts,
11
+ deriveAdoptOffer,
10
12
  eventFamilies,
13
+ hasPersonFacts,
11
14
  isPendingId,
15
+ launchPhaseOf,
12
16
  matchProjectByCwd,
13
17
  mayStillBeWorking,
18
+ noReviewFollowUpLine,
14
19
  normalizeProjectName,
15
20
  pendingId,
16
- repositoryCloneUrlIssue,
17
- servicesHoldLine
18
- } from "./chunk-SMH65F6Z.js";
21
+ refusedAdoptOffer,
22
+ resumesOwnHarness,
23
+ serviceViewHostPort,
24
+ serviceViewStatus,
25
+ servicesHoldLine,
26
+ sessionWorkspaceLines,
27
+ submitDashboardAdoption,
28
+ takesReviewFollowUp,
29
+ withoutLaunchPhase,
30
+ workspaceLineList,
31
+ workspaceReadsOf,
32
+ worktreeJoinLine,
33
+ wrapWords
34
+ } from "./chunk-QHWF3YTC.js";
19
35
 
20
36
  // src/dashboard.tsx
21
37
  import { CliRenderEvents, createCliRenderer } from "@opentui/core";
@@ -29,28 +45,16 @@ import {
29
45
  } from "@tanstack/react-query";
30
46
  import { useEffect as useEffect3, useMemo as useMemo2, useRef as useRef2, useState as useState3, useSyncExternalStore } from "react";
31
47
 
32
- // src/dashboard-adoption.ts
33
- var deriveAdoptOffer = (facts) => {
34
- if (facts.repoRoot === null || facts.originUrl === null || repositoryCloneUrlIssue(facts.originUrl) !== null)
35
- return null;
36
- return {
37
- source: RepositoryCloneUrl.make(facts.originUrl),
38
- name: normalizeProjectName(facts.repoRoot.split("/").at(-1) ?? "project"),
39
- modeIndex: 0
40
- };
41
- };
42
- var submitDashboardAdoption = async (api, input) => {
43
- const issue = repositoryCloneUrlIssue(input.source);
44
- if (issue !== null) return { kind: "invalid-source", message: issue };
45
- const project = await api("POST", "/projects", {
46
- name: input.name,
47
- source: RepositoryCloneUrl.make(input.source),
48
- gitAuthMode: input.gitAuthMode
49
- });
50
- return { kind: "adopted", project };
51
- };
52
-
53
48
  // src/dashboard-model.ts
49
+ var serviceRowOf = (view) => ({
50
+ id: view.service.id,
51
+ sessionId: view.service.sessionId,
52
+ label: view.service.name,
53
+ status: serviceViewStatus(view),
54
+ workspacePort: view.service.workspacePort,
55
+ protocol: view.service.transport,
56
+ hostPort: serviceViewHostPort(view)
57
+ });
54
58
  var worktreeName = (branch) => branch.startsWith("mend/") ? branch.slice("mend/".length) : branch;
55
59
  var worktreeDisplayName = (session) => {
56
60
  const name = worktreeName(session.branch);
@@ -67,7 +71,7 @@ var fetchWorkbench = async (ctx) => {
67
71
  ctx.api("GET", "/services")
68
72
  ]);
69
73
  const servicesBySession = /* @__PURE__ */ new Map();
70
- for (const service of services) {
74
+ for (const service of services.map(serviceRowOf)) {
71
75
  const bucket = servicesBySession.get(service.sessionId) ?? [];
72
76
  bucket.push(service);
73
77
  servicesBySession.set(service.sessionId, bucket);
@@ -127,8 +131,9 @@ var deriveProjects = (data) => (data?.projects ?? []).map((project) => {
127
131
  const detail = data?.details.get(project.id);
128
132
  const sessions = detail?.sessions ?? [];
129
133
  const live = sessions.filter((s) => LIVE_STATUSES.has(s.status)).length;
134
+ const stopping = sessions.filter((s) => s.status === "stopping").length;
130
135
  const open = (detail?.annotations ?? []).reduce((sum, a) => sum + a.openComments, 0);
131
- return { project, total: sessions.length, live, open };
136
+ return { project, total: sessions.length, live, stopping, open };
132
137
  });
133
138
  var bySessionRecency = (a, b) => {
134
139
  const aLive = LIVE_STATUSES.has(a.status) ? 1 : 0;
@@ -142,7 +147,10 @@ var toSessionItem = (data, detail) => (session) => ({
142
147
  services: data.servicesBySession.get(session.id) ?? [],
143
148
  processes: data.processesBySession.get(session.id) ?? []
144
149
  });
145
- var isDeadEnd = (session) => !LIVE_STATUSES.has(session.status) && session.hasTranscript === false;
150
+ var isDeadEnd = (session) => (
151
+ // A stopping session may still be saving, or kept for recovery: never hidden (story S23).
152
+ !LIVE_STATUSES.has(session.status) && session.status !== "stopping" && session.hasTranscript === false
153
+ );
146
154
  var deriveWorktrees = (data, projectId) => {
147
155
  if (data === void 0 || projectId === null) return [];
148
156
  const detail = data.details.get(projectId);
@@ -192,29 +200,33 @@ var pseudoGroup = (session, item) => ({
192
200
  live: LIVE_STATUSES.has(session.status) ? 1 : 0,
193
201
  annotation: item(session).annotation
194
202
  });
195
- var deriveHarnesses = (resuming) => {
203
+ var deriveHarnesses = (resuming, joining = null) => {
196
204
  if (resuming !== null) {
197
205
  const others = Object.keys(HARNESS_COMMANDS).filter((h) => h !== resuming.harness);
198
- return [
206
+ const same2 = resumesOwnHarness(resuming.harness) ? [
199
207
  {
200
208
  harness: null,
201
209
  label: resuming.harness,
202
- hint: "same harness \u2014 native resume, conversation intact"
203
- },
210
+ hint: "same harness \xB7 native resume, conversation intact"
211
+ }
212
+ ] : [];
213
+ return [
214
+ ...same2,
204
215
  ...others.map(
205
216
  (harness) => ({
206
217
  harness,
207
218
  label: harness,
208
- hint: harness === "shell" ? "a bash in the worktree \u2014 resume either agent from inside" : "the conversation crosses as a distilled prompt"
219
+ hint: harness === "shell" ? "a bash in the worktree \xB7 resume either agent from inside" : "the conversation crosses as a distilled prompt"
209
220
  })
210
221
  )
211
222
  ];
212
223
  }
224
+ const where = joining === null ? "new worktree" : `joins ${joining}`;
213
225
  return Object.keys(HARNESS_COMMANDS).map(
214
226
  (harness) => ({
215
227
  harness,
216
228
  label: harness,
217
- hint: harness === "shell" ? "a plain bash session \u2014 new worktree, recorded" : `mend ${harness} \u2014 new worktree, recorded session`
229
+ hint: harness === "shell" ? `a plain bash session \xB7 ${where}, recorded` : `mend ${harness} \xB7 ${where}, recorded session`
218
230
  })
219
231
  );
220
232
  };
@@ -233,11 +245,89 @@ var groupActivityAt = (group) => group.sessions.reduce(
233
245
  group.createdAt
234
246
  );
235
247
  var foldGroupStatus = (group) => {
236
- const statuses = group.sessions.map((item) => item.session.status);
237
- if (statuses.includes("waiting")) return "waiting";
238
- if (statuses.includes("running") || statuses.includes("starting")) return "running";
239
- if (statuses.includes("idle")) return "idle";
240
- return statuses[0] ?? "idle";
248
+ const statuses = new Set(group.sessions.map((item) => item.session.status));
249
+ for (const word of ["waiting", "running", "starting", "stopping", "idle"]) {
250
+ if (statuses.has(word)) return word;
251
+ }
252
+ return "settled";
253
+ };
254
+ var liveCountWords = (live, stopping) => {
255
+ const words = [
256
+ ...live > 0 ? [`${live} live`] : [],
257
+ ...stopping > 0 ? [`${stopping} stopping`] : []
258
+ ];
259
+ return words.length === 0 ? "settled" : words.join(" \xB7 ");
260
+ };
261
+ var elapsedWords = (iso, now = Date.now()) => {
262
+ const ms = now - new Date(iso).getTime();
263
+ if (!Number.isFinite(ms) || ms < 0) return null;
264
+ const minutes = Math.floor(ms / 6e4);
265
+ if (minutes < 1) return "<1m";
266
+ if (minutes < 60) return `${minutes}m`;
267
+ const hours = Math.floor(minutes / 60);
268
+ if (hours < 24) return `${hours}h`;
269
+ return `${Math.floor(hours / 24)}d`;
270
+ };
271
+ var startingWordsOf = (session) => {
272
+ if (isPendingId(session.id)) return "launching";
273
+ const phase = launchPhaseOf(session.summary);
274
+ if (phase === null) return "launching";
275
+ switch (phase.kind) {
276
+ case "waiting-previous":
277
+ return phase.words.endsWith("is saving") ? "waiting for the previous save" : "waiting for the previous session";
278
+ case "booting":
279
+ return "booting";
280
+ case "queued":
281
+ return "queued";
282
+ case "building":
283
+ return "building the image";
284
+ case "preparing":
285
+ return "preparing the workspace";
286
+ }
287
+ };
288
+ var startingExplanationOf = (session) => {
289
+ const phase = isPendingId(session.id) ? null : launchPhaseOf(session.summary);
290
+ if (phase === null) return "launching";
291
+ switch (phase.kind) {
292
+ case "waiting-previous":
293
+ return phase.words.endsWith("is saving") ? "the previous session in this worktree is still saving \xB7 this one starts from its save" : phase.words;
294
+ case "booting":
295
+ return "the workspace is booting \xB7 the agent starts when it is up";
296
+ case "queued":
297
+ return "the launch waits for a worker \xB7 it starts when one takes it";
298
+ case "building":
299
+ return `${phase.words} \xB7 the agent starts once it is built and booted`;
300
+ case "preparing":
301
+ return "the workspace has no runtime yet \xB7 after an update, building its image takes about 8 minutes";
302
+ }
303
+ };
304
+ var sessionTimeWords = (item, now = Date.now()) => {
305
+ const { session } = item;
306
+ if (session.status === "starting" || session.status === "stopping") return null;
307
+ const agent = item.annotation?.currentAgent ?? null;
308
+ const created = elapsedWords(session.createdAt, now);
309
+ const createdWords = created === null ? null : `created ${agoWords(created)}`;
310
+ if (LIVE_STATUSES.has(session.status)) {
311
+ if (agent === null || agent.createdAt === void 0) return createdWords;
312
+ if (agent.exitedAt !== null) {
313
+ const ended2 = elapsedWords(agent.exitedAt, now);
314
+ return ended2 === null ? createdWords : `agent ended ${agoWords(ended2)}`;
315
+ }
316
+ const up = elapsedWords(agent.createdAt, now);
317
+ if (up === null) return createdWords;
318
+ if (agent.kind === "agent-external") return `activity seen ${agoWords(up)}`;
319
+ return session.harness === "shell" ? `shell up ${up}` : `up ${up}`;
320
+ }
321
+ const settledAt = session.settledAt ?? null;
322
+ const ended = settledAt === null ? null : elapsedWords(settledAt, now);
323
+ return ended === null ? createdWords : `ended ${agoWords(ended)}`;
324
+ };
325
+ var agoWords = (elapsed) => elapsed === "<1m" ? "just now" : `${elapsed} ago`;
326
+ var sessionStateWords = (item, now = Date.now()) => {
327
+ const hold = sessionHold(item);
328
+ if (hold !== null) return hold;
329
+ if (item.session.status === "starting") return startingWordsOf(item.session);
330
+ return sessionTimeWords(item, now);
241
331
  };
242
332
  var liveShellOf = (processes) => processes.findLast((process2) => process2.kind === "shell" && process2.exitedAt === null) ?? null;
243
333
  var liveProtocolOf = (processes) => processes.find((process2) => process2.kind === "agent-protocol" && process2.exitedAt === null) ?? null;
@@ -249,6 +339,26 @@ var planAttach = (session) => {
249
339
  if (session.status === "starting") return { kind: "starting", session };
250
340
  return { kind: "attach", session };
251
341
  };
342
+ var findWorkbenchSession = (data, id) => {
343
+ for (const detail of data.details.values()) {
344
+ const found = detail.sessions.find((session) => session.id === id);
345
+ if (found !== void 0) return found;
346
+ }
347
+ return null;
348
+ };
349
+ var startProgress = (data, watch) => {
350
+ if (watch.sessionId === null) return { kind: "starting" };
351
+ const plan = planAttach(findWorkbenchSession(data, watch.sessionId));
352
+ switch (plan.kind) {
353
+ case "attach":
354
+ return { kind: "ready", session: plan.session };
355
+ case "settled":
356
+ case "stopping":
357
+ return { kind: "ended", session: plan.session };
358
+ default:
359
+ return { kind: "starting" };
360
+ }
361
+ };
252
362
  var planResume = (session) => {
253
363
  if (session === null) return { kind: "none" };
254
364
  if (isPendingId(session.id)) return { kind: "pending", session };
@@ -276,7 +386,14 @@ var markSessionStopped = (data, sessionId) => {
276
386
  return {
277
387
  ...mapWorkbenchSessions(
278
388
  data,
279
- (session) => session.id === sessionId ? { ...session, status: "stopped" } : session
389
+ (session) => (
390
+ // Asked, not observed (story S28): `stopping` until the server says how it ended. A stop
391
+ // leaves Services running, so a session with Services reads as stopped with what holds it.
392
+ session.id === sessionId ? {
393
+ ...session,
394
+ status: (data.servicesBySession.get(sessionId) ?? []).length > 0 ? "stopped" : "stopping"
395
+ } : session
396
+ )
280
397
  ),
281
398
  processesBySession
282
399
  };
@@ -290,6 +407,13 @@ var AGENT_WORKING = /* @__PURE__ */ new Set(["starting", "running", "waiting"]);
290
407
  var sessionHold = (item) => {
291
408
  const capture = captureLineOf(item.session);
292
409
  if (capture !== null) return capture;
410
+ if (item.session.status === "stopping") {
411
+ const agent = item.annotation?.currentAgent ?? null;
412
+ return agent !== null && agent.exitedAt !== null ? "agent ended \xB7 workspace end not confirmed" : "workspace end not confirmed";
413
+ }
414
+ return servicesHoldOf(item);
415
+ };
416
+ var servicesHoldOf = (item) => {
293
417
  const agent = item.annotation?.currentAgent ?? null;
294
418
  const agentProcessLive = item.processes.some(
295
419
  (process2) => process2.kind !== "shell" && process2.exitedAt === null
@@ -300,6 +424,24 @@ var sessionHold = (item) => {
300
424
  liveServices: Math.max(item.annotation?.liveServices ?? 0, item.services.length)
301
425
  });
302
426
  };
427
+ var sessionRowFacts = (item, width, now = Date.now()) => {
428
+ const agents = item.processes.filter((process2) => process2.kind !== "shell").length;
429
+ const shells = item.processes.filter((process2) => process2.kind === "shell").length;
430
+ const services = item.services.length;
431
+ const state = sessionStateWords(item, now);
432
+ const stateWidth = width > 40 ? width - 9 : width - 2;
433
+ return fitHints(
434
+ [
435
+ ...state === null ? [] : [cut(state, stateWidth)],
436
+ item.session.harness,
437
+ ...shells > 0 ? [`${shells} shell`] : [],
438
+ ...agents > 0 ? [`${agents} agent`] : [],
439
+ ...services > 0 && servicesHoldOf(item) === null ? [`${services} service`] : []
440
+ ],
441
+ width
442
+ );
443
+ };
444
+ var cut = (text, width) => text.length <= width ? text : `${text.slice(0, Math.max(0, width - 1))}\u2026`;
303
445
  var removeWorktreeGroup = (data, projectId, group) => {
304
446
  const memberIds = new Set(group.sessions.map((item) => item.session.id));
305
447
  const detail = data.details.get(projectId);
@@ -344,12 +486,12 @@ var filterBranches = (branches, query) => {
344
486
  };
345
487
  var baseStepNotice = (state) => {
346
488
  if (state.branchError !== null) {
347
- return `branches unreadable \u2014 ${state.branchError} \xB7 enter uses the default`;
489
+ return `branches unreadable \xB7 ${state.branchError} \xB7 enter uses the default`;
348
490
  }
349
491
  if (state.branches === null) return "reading branches\u2026";
350
- if (state.branches.length === 0) return "no branches read \u2014 enter uses the default branch";
492
+ if (state.branches.length === 0) return "no branches read \xB7 enter uses the default branch";
351
493
  if (filterBranches(state.branches, state.query).length === 0) {
352
- return "no branch matches \u2014 enter uses the default branch";
494
+ return "no branch matches \xB7 enter uses the default branch";
353
495
  }
354
496
  return null;
355
497
  };
@@ -364,8 +506,35 @@ var advanceFromBase = (current) => {
364
506
  var COLUMNS = ["projects", "worktrees", "sessions", "detail"];
365
507
  var NAV_SECTIONS = ["projects", "worktrees", "sessions"];
366
508
  var isNavSection = (column) => column !== "detail";
509
+ var PANE_NUMBER = {
510
+ projects: "1",
511
+ worktrees: "2",
512
+ sessions: "3",
513
+ detail: "0"
514
+ };
515
+ var paneForDigit = (digit) => COLUMNS.find((column) => PANE_NUMBER[column] === digit) ?? null;
516
+ var numberedTitle = (column, title) => `[${PANE_NUMBER[column]}] ${title}`;
517
+ var cyclePane = (focus, delta) => {
518
+ const at = COLUMNS.indexOf(focus);
519
+ if (at === -1) return "sessions";
520
+ const next = ((at + delta) % COLUMNS.length + COLUMNS.length) % COLUMNS.length;
521
+ return COLUMNS[next] ?? focus;
522
+ };
523
+ var backFrom = (focus, lastNav) => focus === "detail" ? lastNav : stepColumn(focus, -1);
524
+ var SCREEN_MODES = ["normal", "half", "full"];
525
+ var stepScreenMode = (mode, delta) => {
526
+ const at = SCREEN_MODES.indexOf(mode);
527
+ const next = ((at + delta) % SCREEN_MODES.length + SCREEN_MODES.length) % SCREEN_MODES.length;
528
+ return SCREEN_MODES[next] ?? mode;
529
+ };
530
+ var matchesFilter = (query, ...fields) => {
531
+ const needle = query.trim().toLowerCase();
532
+ if (needle === "") return true;
533
+ return fields.some((field) => field !== null && field.toLowerCase().includes(needle));
534
+ };
367
535
  var expandedSection = (focus, lastNav) => isNavSection(focus) ? focus : lastNav;
368
536
  var SIDEBAR_SHARE = 0.25;
537
+ var HALF_SIDEBAR_SHARE = 0.5;
369
538
  var MIN_SIDEBAR_WIDTH = 24;
370
539
  var MIN_DETAIL_WIDTH = 48;
371
540
  var SPLIT_MIN_WIDTH = MIN_SIDEBAR_WIDTH + MIN_DETAIL_WIDTH;
@@ -381,13 +550,11 @@ var stackSections = (body, open) => {
381
550
  (section) => section === open ? { section, expanded: true, height: room, rows: room - 2 } : { section, expanded: false, height: MIN_SECTION_HEIGHT, rows: 1 }
382
551
  );
383
552
  };
384
- var planLayout = (width, height, focus, lastNav) => {
385
- const split = width >= SPLIT_MIN_WIDTH;
553
+ var planLayout = (width, height, focus, lastNav, mode = "normal") => {
554
+ const split = mode !== "full" && width >= SPLIT_MIN_WIDTH;
386
555
  const navVisible = split || isNavSection(focus);
387
- const sidebarOuter = split ? Math.max(
388
- MIN_SIDEBAR_WIDTH,
389
- Math.min(width - MIN_DETAIL_WIDTH, Math.round(width * SIDEBAR_SHARE))
390
- ) : navVisible ? Math.max(4, width) : 0;
556
+ const share = mode === "half" ? HALF_SIDEBAR_SHARE : SIDEBAR_SHARE;
557
+ const sidebarOuter = split ? Math.max(MIN_SIDEBAR_WIDTH, Math.min(width - MIN_DETAIL_WIDTH, Math.round(width * share))) : navVisible ? Math.max(4, width) : 0;
391
558
  const detailOuter = split ? width - sidebarOuter : navVisible ? 0 : Math.max(4, width);
392
559
  const build = (body2, breadcrumb) => {
393
560
  const sections = navVisible ? stackSections(body2, expandedSection(focus, lastNav)) : [];
@@ -425,6 +592,56 @@ var fitHints = (hints, width) => {
425
592
  return kept.length === 0 ? "\u2026" : `${kept.join(" \xB7 ")} \u2026`;
426
593
  };
427
594
  var clampIndex = (length, index) => length === 0 ? 0 : Math.max(0, Math.min(length - 1, index));
595
+ var VIEWER_KEY = ["viewer"];
596
+ var viewerNeeded = (data) => data !== void 0 && [...data.details.values()].some((detail) => hasPersonFacts(detail.sessions));
597
+ var fetchViewer = async (ctx) => {
598
+ const [view, members] = await Promise.all([
599
+ ctx.api("GET", "/organization").catch(() => null),
600
+ ctx.api("GET", "/organization/members").catch(() => [])
601
+ ]);
602
+ return { userId: view?.userId ?? null, members };
603
+ };
604
+ var WORKSPACE_FACTS_KEY = (sessionId, reads) => [
605
+ "workspace-facts",
606
+ sessionId,
607
+ reads.waiting,
608
+ reads.retirement
609
+ ];
610
+ var fetchWorkspaceFacts = async (api, sessionId, reads) => {
611
+ const [wait, retirement] = await Promise.all([
612
+ reads.waiting ? api("GET", `/sessions/${sessionId}/waiting`).catch(() => null) : null,
613
+ reads.retirement ? api(
614
+ "GET",
615
+ `/sessions/${sessionId}/workspace-retirement`
616
+ ).catch(() => null) : null
617
+ ]);
618
+ return { wait, retirement };
619
+ };
620
+ var workspaceFactRows = (session, viewer, facts, width) => workspaceLineList(
621
+ sessionWorkspaceLines({
622
+ sessionId: session.id,
623
+ livePeople: session.livePeople ?? [],
624
+ viewer: viewer?.userId ?? null,
625
+ wait: facts?.wait ?? null,
626
+ retirement: facts?.retirement ?? null,
627
+ members: viewer?.members ?? []
628
+ })
629
+ ).flatMap((line) => {
630
+ const indent = line.startsWith(" ") ? " " : "";
631
+ return wrapWords(line, width - indent.length).map((row) => `${indent}${row}`);
632
+ });
633
+ var worktreeJoinRows = (data, projectId, worktree, viewerId, width) => {
634
+ const detail = data?.details.get(projectId);
635
+ const id = "id" in worktree ? worktree.id : detail?.worktrees?.find((candidate) => candidate.name === worktree.name)?.id;
636
+ if (detail === void 0 || id === void 0) return [];
637
+ const line = worktreeJoinLine(detail.sessions, id, viewerId);
638
+ return line === null ? [] : wrapWords(line, width);
639
+ };
640
+ var KEY_GROUP_TITLE = {
641
+ navigate: "move around",
642
+ session: "act on the selection",
643
+ dashboard: "the dashboard"
644
+ };
428
645
  var KEY_BINDINGS = [
429
646
  {
430
647
  verb: "moveUp",
@@ -435,36 +652,123 @@ var KEY_BINDINGS = [
435
652
  worktrees: "\u2191\u2193 move",
436
653
  sessions: "\u2191\u2193 move",
437
654
  detail: "\u2191\u2193 scroll"
438
- }
655
+ },
656
+ help: "up the list, or back through the record",
657
+ group: "navigate"
658
+ },
659
+ {
660
+ verb: "moveDown",
661
+ keys: ["down", "j"],
662
+ shift: false,
663
+ hints: {},
664
+ help: "down the list, or toward the newest line",
665
+ group: "navigate"
666
+ },
667
+ { verb: "pageUp", keys: ["pageup"], shift: false, hints: {}, help: "up ten", group: "navigate" },
668
+ {
669
+ verb: "pageDown",
670
+ keys: ["pagedown"],
671
+ shift: false,
672
+ hints: {},
673
+ help: "down ten",
674
+ group: "navigate"
675
+ },
676
+ {
677
+ verb: "jumpProjects",
678
+ keys: ["1"],
679
+ shift: false,
680
+ hints: {},
681
+ help: "jump to [1] projects",
682
+ group: "navigate"
683
+ },
684
+ {
685
+ verb: "jumpWorktrees",
686
+ keys: ["2"],
687
+ shift: false,
688
+ hints: {},
689
+ help: "jump to [2] worktrees",
690
+ group: "navigate"
691
+ },
692
+ {
693
+ verb: "jumpSessions",
694
+ keys: ["3"],
695
+ shift: false,
696
+ hints: {},
697
+ help: "jump to [3] sessions",
698
+ group: "navigate"
699
+ },
700
+ {
701
+ verb: "jumpDetail",
702
+ keys: ["0"],
703
+ shift: false,
704
+ hints: {},
705
+ help: "jump to [0], the session pane",
706
+ group: "navigate"
439
707
  },
440
- { verb: "moveDown", keys: ["down", "j"], shift: false, hints: {} },
441
- { verb: "pageUp", keys: ["pageup"], shift: false, hints: {} },
442
- { verb: "pageDown", keys: ["pagedown"], shift: false, hints: {} },
443
708
  {
444
709
  verb: "columnRight",
445
- keys: ["return", "linefeed", "l", "right", "tab"],
710
+ keys: ["return", "linefeed", "l", "right"],
446
711
  shift: false,
447
- hints: { projects: "\u2192 worktrees", worktrees: "\u2190\u2192 panes", sessions: "\u2190\u2192 panes" }
712
+ hints: { projects: "\u2192 worktrees", worktrees: "\u2190\u2192 panes", sessions: "\u2190\u2192 panes" },
713
+ help: "drill in: projects, worktrees, sessions, then [0]",
714
+ group: "navigate"
448
715
  },
449
716
  {
450
717
  verb: "columnLeft",
451
718
  keys: ["left", "h", "-", "backspace"],
452
719
  shift: false,
453
- hints: { detail: "\u2190 sessions" }
720
+ hints: { detail: "\u2190 sessions" },
721
+ help: "one pane back up the hierarchy",
722
+ group: "navigate"
723
+ },
724
+ {
725
+ verb: "nextPane",
726
+ keys: ["tab"],
727
+ shift: false,
728
+ hints: {},
729
+ help: "next pane, round to the first after the last",
730
+ group: "navigate"
731
+ },
732
+ { verb: "prevPane", keys: ["backtab"], shift: "any", hints: {} },
733
+ {
734
+ verb: "prevPane",
735
+ keys: ["tab"],
736
+ shift: true,
737
+ hints: {},
738
+ help: "previous pane, round to the last before the first",
739
+ group: "navigate"
740
+ },
741
+ {
742
+ verb: "back",
743
+ keys: ["escape"],
744
+ shift: false,
745
+ hints: {},
746
+ help: "clear the filter, else back to where you came from",
747
+ group: "navigate"
748
+ },
749
+ {
750
+ verb: "filter",
751
+ keys: ["/"],
752
+ shift: false,
753
+ hints: {},
754
+ help: "filter this list; enter keeps the filter, esc clears it",
755
+ group: "navigate"
454
756
  },
455
- { verb: "columnLeft", keys: ["backtab"], shift: "any", hints: {} },
456
- { verb: "columnLeft", keys: ["tab"], shift: true, hints: {} },
457
757
  {
458
758
  verb: "attach",
459
759
  keys: ["a"],
460
760
  shift: false,
461
- hints: { worktrees: "a attach", sessions: "a attach", detail: "a attach" }
761
+ hints: { worktrees: "a attach", sessions: "a attach", detail: "a attach" },
762
+ help: "attach this terminal to the live session",
763
+ group: "session"
462
764
  },
463
765
  {
464
766
  verb: "resume",
465
767
  keys: ["r"],
466
768
  shift: false,
467
- hints: { worktrees: "r resume", sessions: "r resume", detail: "r resume" }
769
+ hints: { worktrees: "r resume", sessions: "r resume", detail: "r resume" },
770
+ help: "resume the settled session, on a harness you pick",
771
+ group: "session"
468
772
  },
469
773
  {
470
774
  verb: "newSession",
@@ -474,60 +778,166 @@ var KEY_BINDINGS = [
474
778
  projects: "n/w new worktree",
475
779
  worktrees: "n new session",
476
780
  sessions: "n new session"
477
- }
781
+ },
782
+ help: "another session in this worktree, or a new worktree",
783
+ group: "session"
478
784
  },
479
785
  {
480
786
  verb: "newWorktree",
481
787
  keys: ["w"],
482
788
  shift: false,
483
- hints: { worktrees: "w new worktree", sessions: "w new worktree" }
789
+ hints: { worktrees: "w new worktree", sessions: "w new worktree" },
790
+ help: "a new worktree in this project",
791
+ group: "session"
484
792
  },
485
793
  {
486
794
  verb: "stop",
487
795
  keys: ["k"],
488
796
  shift: true,
489
- hints: { worktrees: "\u21E7K stop all", sessions: "\u21E7K stop" }
797
+ hints: { worktrees: "\u21E7K stop all", sessions: "\u21E7K stop" },
798
+ help: "stop it, or every live session in [2] (press twice)",
799
+ group: "session"
490
800
  },
491
801
  { verb: "stop", keys: ["x"], shift: false, hints: {} },
492
802
  {
493
803
  verb: "remove",
494
804
  keys: ["d"],
495
805
  shift: true,
496
- hints: { worktrees: "\u21E7D remove worktree", sessions: "\u21E7D remove" }
806
+ hints: { worktrees: "\u21E7D remove worktree", sessions: "\u21E7D remove" },
807
+ help: "remove it, or the worktree from [2] (press twice)",
808
+ group: "session"
497
809
  },
498
810
  {
499
811
  verb: "review",
500
812
  keys: ["v"],
501
813
  shift: false,
502
- hints: { worktrees: "v review", sessions: "v review", detail: "v review" }
814
+ hints: { worktrees: "v review", sessions: "v review", detail: "v review" },
815
+ help: "review the change in this terminal",
816
+ group: "session"
503
817
  },
504
818
  {
505
819
  verb: "rename",
506
820
  keys: ["e"],
507
821
  shift: false,
508
- hints: { sessions: "e rename", detail: "e rename" }
822
+ hints: { sessions: "e rename", detail: "e rename" },
823
+ help: "label the session; empty clears it",
824
+ group: "session"
825
+ },
826
+ {
827
+ verb: "openWeb",
828
+ keys: ["o"],
829
+ shift: false,
830
+ hints: { sessions: "o web", detail: "o web" },
831
+ help: "open the session in the browser",
832
+ group: "session"
509
833
  },
510
- { verb: "openWeb", keys: ["o"], shift: false, hints: { sessions: "o web", detail: "o web" } },
511
834
  {
512
835
  verb: "refresh",
513
836
  keys: ["r"],
514
837
  shift: true,
515
- hints: { projects: "\u21E7R refresh", worktrees: "\u21E7R refresh", detail: "\u21E7R refresh" }
838
+ hints: { projects: "\u21E7R refresh", worktrees: "\u21E7R refresh", detail: "\u21E7R refresh" },
839
+ help: "read everything from the server again",
840
+ group: "dashboard"
841
+ },
842
+ {
843
+ verb: "nextScreenMode",
844
+ keys: ["+"],
845
+ shift: "any",
846
+ hints: {},
847
+ help: "screen mode: normal, half, full",
848
+ group: "dashboard"
849
+ },
850
+ {
851
+ verb: "prevScreenMode",
852
+ keys: ["_"],
853
+ shift: "any",
854
+ hints: {},
855
+ help: "screen mode, the other way",
856
+ group: "dashboard"
857
+ },
858
+ {
859
+ verb: "help",
860
+ keys: ["?"],
861
+ shift: "any",
862
+ hints: {},
863
+ help: "this list",
864
+ group: "dashboard",
865
+ footer: "? keys"
516
866
  },
517
867
  {
518
868
  verb: "quit",
519
869
  keys: ["q"],
520
870
  shift: false,
521
- hints: { projects: "q quit", worktrees: "q quit", sessions: "q quit", detail: "q quit" }
871
+ hints: { projects: "q quit", worktrees: "q quit", sessions: "q quit", detail: "q quit" },
872
+ help: "quit; sessions keep running",
873
+ group: "dashboard"
522
874
  }
523
875
  ];
876
+ var SYMBOL_STROKES = /* @__PURE__ */ new Set(["?", "+", "_"]);
877
+ var strokeName = (key) => {
878
+ const sequence = key.sequence ?? "";
879
+ return SYMBOL_STROKES.has(sequence) ? sequence : key.name ?? "";
880
+ };
524
881
  var verbForKey = (name, shift) => KEY_BINDINGS.find(
525
882
  (binding) => binding.keys.includes(name) && (binding.shift === "any" || binding.shift === shift)
526
883
  )?.verb ?? null;
884
+ var gameSwallows = (verb) => verb !== null;
527
885
  var verbHints = (focus) => KEY_BINDINGS.flatMap((binding) => {
528
886
  const hint = binding.hints[focus];
529
887
  return hint === void 0 ? [] : [hint];
530
888
  });
889
+ var FOOTER_TAIL = KEY_BINDINGS.flatMap(
890
+ (binding) => binding.footer === void 0 ? [] : [binding.footer]
891
+ );
892
+ var footerHints = (focus, width) => {
893
+ const tail = FOOTER_TAIL.map((hint) => ` \xB7 ${hint}`).join("");
894
+ return `${fitHints(verbHints(focus), Math.max(1, width - tail.length))}${tail}`;
895
+ };
896
+ var KEY_LABEL = {
897
+ up: "\u2191",
898
+ down: "\u2193",
899
+ left: "\u2190",
900
+ right: "\u2192",
901
+ return: "enter",
902
+ tab: "tab",
903
+ backtab: "\u21E7tab",
904
+ escape: "esc",
905
+ backspace: "\u232B",
906
+ pageup: "PgUp",
907
+ pagedown: "PgDn"
908
+ };
909
+ var keyLabel = (key, shift) => {
910
+ const base = KEY_LABEL[key] ?? key;
911
+ return shift === true ? `\u21E7${base.length === 1 ? base.toUpperCase() : base}` : base;
912
+ };
913
+ var helpSections = (focus) => {
914
+ const rows = /* @__PURE__ */ new Map();
915
+ for (const binding of KEY_BINDINGS) {
916
+ const entry = rows.get(binding.verb) ?? { keys: [], help: "", group: null };
917
+ for (const key of binding.keys) {
918
+ if (key === "linefeed") continue;
919
+ const label = keyLabel(key, binding.shift);
920
+ if (!entry.keys.includes(label)) entry.keys.push(label);
921
+ }
922
+ if (entry.help === "" && binding.help !== void 0) entry.help = binding.help;
923
+ if (entry.group === null && binding.group !== void 0) entry.group = binding.group;
924
+ rows.set(binding.verb, entry);
925
+ }
926
+ const all = [...rows].map(([verb, entry]) => ({
927
+ verb,
928
+ keys: entry.keys.join(" "),
929
+ help: entry.help,
930
+ group: entry.group ?? "dashboard",
931
+ here: KEY_BINDINGS.some(
932
+ (binding) => binding.verb === verb && binding.hints[focus] !== void 0
933
+ )
934
+ }));
935
+ const groups = ["navigate", "session", "dashboard"];
936
+ return groups.flatMap((group) => {
937
+ const ordered = all.filter((row) => row.group === group);
938
+ return ordered.length === 0 ? [] : [{ title: KEY_GROUP_TITLE[group], rows: ordered.map(({ group: _group, ...row }) => row) }];
939
+ });
940
+ };
531
941
 
532
942
  // src/dashboard-preview.ts
533
943
  import { stripVTControlCharacters } from "node:util";
@@ -780,13 +1190,18 @@ var statusOf = (patch) => {
780
1190
  var isLikelyGenerated = (name) => /(^|\/)(?:dist|build|generated)(?:\/|$)/i.test(name) || /(?:\.generated\.|\.min\.(?:js|css)$|(?:^|\/)(?:pnpm-lock\.yaml|package-lock\.json|yarn\.lock)$)/i.test(
781
1191
  name
782
1192
  );
783
- var visibleWhitespace = (patch) => patch.split("\n").map((line) => {
784
- const hunkContent = line.startsWith("+") && !line.startsWith("+++") || line.startsWith("-") && !line.startsWith("---") || line.startsWith(" ");
785
- if (!hunkContent) return line;
786
- const prefix = line.slice(0, 1);
787
- const content = line.slice(1).replaceAll(" ", "\u2192\xB7\xB7\xB7\xB7").replaceAll(" ", "\xB7");
788
- return `${prefix}${content}`;
789
- }).join("\n");
1193
+ var visibleWhitespace = (patch) => {
1194
+ let inHunk = false;
1195
+ return patch.split("\n").map((line) => {
1196
+ if (line.startsWith("diff --git ")) inHunk = false;
1197
+ if (line.startsWith("@@ ")) inHunk = true;
1198
+ const hunkContent = inHunk && /^[+ -]/.test(line);
1199
+ if (!hunkContent) return line;
1200
+ const prefix = line.slice(0, 1);
1201
+ const content = line.slice(1).replaceAll(" ", "\u2192\xB7\xB7\xB7\xB7").replaceAll(" ", "\xB7");
1202
+ return `${prefix}${content}`;
1203
+ }).join("\n");
1204
+ };
790
1205
  var splitFilePatches = (diff) => {
791
1206
  const starts = [...diff.matchAll(/^diff --git /gm)].map((match) => match.index);
792
1207
  return starts.map((start, index) => {
@@ -818,9 +1233,9 @@ var parseRows = (patch) => {
818
1233
  while (bodyIndex < patchLines.length) {
819
1234
  const bodyLine = patchLines[bodyIndex] ?? "";
820
1235
  if (bodyLine.startsWith("@@ ")) break;
821
- if (bodyLine.startsWith("+") && !bodyLine.startsWith("+++")) {
1236
+ if (bodyLine.startsWith("+")) {
822
1237
  body.push({ kind: "addition" });
823
- } else if (bodyLine.startsWith("-") && !bodyLine.startsWith("---")) {
1238
+ } else if (bodyLine.startsWith("-")) {
824
1239
  body.push({ kind: "deletion" });
825
1240
  } else if (bodyLine.startsWith(" ")) {
826
1241
  body.push({ kind: "context" });
@@ -953,6 +1368,7 @@ var SYNTAX_FUNCTION = "#ffcd66";
953
1368
 
954
1369
  // src/review.tsx
955
1370
  import { Fragment, jsx, jsxs } from "@opentui/react/jsx-runtime";
1371
+ var clockOf = (iso) => new Date(iso).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", hour12: false });
956
1372
  var REVIEW_KEY = (changeId) => ["review", changeId];
957
1373
  var EDITOR_KEY_BINDINGS = [{ name: "return", ctrl: true, action: "submit" }];
958
1374
  var syntaxStyle = SyntaxStyle.fromStyles({
@@ -998,6 +1414,7 @@ var fetchReview = async (ctx, changeId) => {
998
1414
  sliceId: pinned.slice.id,
999
1415
  checkpointAId: pinned.checkpointA.id,
1000
1416
  checkpointBId: pinned.checkpointB.id,
1417
+ checkpointSource: pinned.checkpointB.source ?? null,
1001
1418
  diffDigest: pinned.slice.diffDigest,
1002
1419
  anchorFiles: pinned.anchorFiles,
1003
1420
  files: buildReviewFiles(wire.diff, wire.files),
@@ -1511,6 +1928,10 @@ function ReviewScreen({
1511
1928
  };
1512
1929
  const openSendEditor = () => {
1513
1930
  if (data === void 0) return;
1931
+ if (!takesReviewFollowUp(session.harness)) {
1932
+ setStatus(noReviewFollowUpLine(session.harness));
1933
+ return;
1934
+ }
1514
1935
  const sendable = data.comments.filter(
1515
1936
  (comment) => comment.state === "open" && comment.sentToSessionId === null && !isPendingId(comment.id)
1516
1937
  );
@@ -1831,7 +2252,10 @@ function ReviewScreen({
1831
2252
  session.id.slice(0, 8)
1832
2253
  ] }),
1833
2254
  isFetching ? /* @__PURE__ */ jsx("span", { fg: FAINT, children: " \xB7 syncing" }) : null,
1834
- /* @__PURE__ */ jsx("span", { fg: checkpointState === "failed" ? MUTED : FAINT, children: checkpointState === "recording" ? " \xB7 checkpointing" : checkpointState === "failed" ? " \xB7 checkpoint incomplete" : " \xB7 checkpoint recorded" })
2255
+ /* @__PURE__ */ jsx("span", { fg: checkpointState === "failed" ? MUTED : FAINT, children: checkpointState === "recording" ? " \xB7 checkpointing" : checkpointState === "failed" ? " \xB7 checkpoint incomplete" : data.checkpointSource === null ? " \xB7 checkpoint recorded" : ` \xB7 checkpoint ${checkpointSourceWords(
2256
+ data.checkpointSource,
2257
+ clockOf(data.checkpointSource.observedAt)
2258
+ )}` })
1835
2259
  ] }),
1836
2260
  /* @__PURE__ */ jsxs("text", { height: 1, bg: "transparent", children: [
1837
2261
  /* @__PURE__ */ jsxs("span", { fg: FAINT, children: [
@@ -1967,15 +2391,12 @@ function ReviewScreen({
1967
2391
  onSubmit: () => void submitEditor()
1968
2392
  }
1969
2393
  ),
1970
- /* @__PURE__ */ jsx("text", { height: 1, fg: status === "" ? FAINT : INK_2, bg: "transparent", children: status === "" ? ` m read \xB7 g suggest \xB7 t tour \xB7 ,/. tour stops \xB7 s draft review${data.followUp?.status === "pending" ? " \xB7 y deliver & relaunch" : ""} \xB7 o web \xB7 r refresh` : ` ${status}` }),
2394
+ /* @__PURE__ */ jsx("text", { height: 1, fg: status === "" ? FAINT : INK_2, bg: "transparent", children: status === "" ? ` m read \xB7 g suggest \xB7 t tour \xB7 ,/. tour stops${takesReviewFollowUp(session.harness) ? " \xB7 s draft review" : ""}${data.followUp?.status === "pending" ? " \xB7 y deliver & relaunch" : ""} \xB7 o web \xB7 r refresh` : ` ${status}` }),
1971
2395
  /* @__PURE__ */ jsx("text", { height: 1, fg: FAINT, bg: "transparent", children: footer })
1972
2396
  ] })
1973
2397
  );
1974
2398
  }
1975
2399
 
1976
- // src/snake.tsx
1977
- import { useEffect as useEffect2, useState as useState2 } from "react";
1978
-
1979
2400
  // src/snake-game.ts
1980
2401
  var OPPOSITE = {
1981
2402
  up: "down",
@@ -2057,94 +2478,294 @@ var render = (game) => {
2057
2478
  return rows.map((row) => row.join(""));
2058
2479
  };
2059
2480
 
2481
+ // src/snake-play.ts
2482
+ var TICK_MS = 140;
2483
+ var COUNTDOWN_STEP_MS = 1e3;
2484
+ var COUNTDOWN = { kind: "countdown", step: 3 };
2485
+ var RUNNING = { kind: "running" };
2486
+ var PAUSED = { kind: "paused" };
2487
+ var READY = { kind: "ready" };
2488
+ var newSnakePlay = (width, height, random) => ({
2489
+ game: newSnakeGame(width, height, random),
2490
+ clock: READY,
2491
+ focused: false,
2492
+ width,
2493
+ height
2494
+ });
2495
+ var countDown = (play, random) => ({
2496
+ ...play,
2497
+ game: play.game.over ? newSnakeGame(play.width, play.height, random) : play.game,
2498
+ clock: COUNTDOWN
2499
+ });
2500
+ var reduceSnake = (play, event, random) => {
2501
+ switch (event.type) {
2502
+ case "focus":
2503
+ return play.focused ? play : { ...countDown(play, random), focused: true };
2504
+ case "blur": {
2505
+ if (!play.focused) return play;
2506
+ const clock = play.clock.kind === "running" ? PAUSED : play.clock.kind === "countdown" ? READY : play.clock;
2507
+ return { ...play, focused: false, clock };
2508
+ }
2509
+ case "resize": {
2510
+ if (event.width === play.width && event.height === play.height) return play;
2511
+ return {
2512
+ ...play,
2513
+ width: event.width,
2514
+ height: event.height,
2515
+ game: newSnakeGame(event.width, event.height, random),
2516
+ clock: play.clock.kind === "running" ? COUNTDOWN : play.clock
2517
+ };
2518
+ }
2519
+ case "count": {
2520
+ if (!play.focused || play.clock.kind !== "countdown") return play;
2521
+ const { step } = play.clock;
2522
+ return {
2523
+ ...play,
2524
+ clock: step === 0 ? RUNNING : { kind: "countdown", step: step === 3 ? 2 : step === 2 ? 1 : 0 }
2525
+ };
2526
+ }
2527
+ case "tick": {
2528
+ if (!play.focused || play.clock.kind !== "running") return play;
2529
+ const game = tick(play.game, random);
2530
+ return { ...play, game, clock: game.over ? READY : play.clock };
2531
+ }
2532
+ case "steer": {
2533
+ if (!play.focused) return play;
2534
+ if (play.game.over) return countDown(play, random);
2535
+ const game = turn(play.game, event.direction);
2536
+ return play.clock.kind === "running" || play.clock.kind === "countdown" ? { ...play, game } : { ...play, game, clock: COUNTDOWN };
2537
+ }
2538
+ case "togglePause":
2539
+ if (!play.focused) return play;
2540
+ return play.clock.kind === "running" || play.clock.kind === "countdown" ? { ...play, clock: PAUSED } : countDown(play, random);
2541
+ case "play":
2542
+ if (!play.focused || play.clock.kind === "running" || play.clock.kind === "countdown") {
2543
+ return play;
2544
+ }
2545
+ return countDown(play, random);
2546
+ }
2547
+ };
2548
+ var KEY_DIRECTIONS = {
2549
+ up: "up",
2550
+ down: "down",
2551
+ left: "left",
2552
+ right: "right",
2553
+ k: "up",
2554
+ j: "down",
2555
+ h: "left",
2556
+ l: "right"
2557
+ };
2558
+ var snakeKey = (name) => {
2559
+ const direction = KEY_DIRECTIONS[name];
2560
+ if (direction !== void 0) return { type: "steer", direction };
2561
+ if (name === "space" || name === "p") return { type: "togglePause" };
2562
+ if (name === "return" || name === "linefeed") return { type: "play" };
2563
+ if (name === "escape" || name === "q") return { type: "leave" };
2564
+ return null;
2565
+ };
2566
+ var snakeHints = (play) => play.game.over ? "enter/arrows again \xB7 esc/q leave" : play.clock.kind === "paused" || play.clock.kind === "ready" ? "enter/space resume \xB7 esc/q leave" : "\u2190\u2191\u2193\u2192/hjkl steer \xB7 space/p pause \xB7 esc/q leave";
2567
+ var SEGMENTS = {
2568
+ "1": "bc",
2569
+ "2": "abdeg",
2570
+ "3": "abcdg",
2571
+ G: "acdef",
2572
+ O: "abcdef"
2573
+ };
2574
+ var glyphPixels = (char, length, thickness) => {
2575
+ const lit = new Set(SEGMENTS[char] ?? "");
2576
+ const on = (...segments) => segments.some((segment) => lit.has(segment));
2577
+ const width = length + 2 * thickness;
2578
+ const height = 2 * length + 3 * thickness;
2579
+ const column = (x) => x < thickness ? "left" : x < thickness + length ? "middle" : "right";
2580
+ const row = (y) => y < thickness ? "top" : y < thickness + length ? "upper" : y < 2 * thickness + length ? "centre" : y < 2 * thickness + 2 * length ? "lower" : "bottom";
2581
+ const pixel = (x, y) => {
2582
+ const where = `${column(x)} ${row(y)}`;
2583
+ switch (where) {
2584
+ case "middle top":
2585
+ return on("a");
2586
+ case "middle centre":
2587
+ return on("g");
2588
+ case "middle bottom":
2589
+ return on("d");
2590
+ case "left upper":
2591
+ return on("f");
2592
+ case "right upper":
2593
+ return on("b");
2594
+ case "left lower":
2595
+ return on("e");
2596
+ case "right lower":
2597
+ return on("c");
2598
+ case "left top":
2599
+ return on("a", "f");
2600
+ case "right top":
2601
+ return on("a", "b");
2602
+ case "left centre":
2603
+ return on("f", "e", "g");
2604
+ case "right centre":
2605
+ return on("b", "c", "g");
2606
+ case "left bottom":
2607
+ return on("e", "d");
2608
+ case "right bottom":
2609
+ return on("c", "d");
2610
+ default:
2611
+ return false;
2612
+ }
2613
+ };
2614
+ return Array.from(
2615
+ { length: height },
2616
+ (_row, y) => Array.from({ length: width }, (_cell, x) => pixel(x, y))
2617
+ );
2618
+ };
2619
+ var halfBlocks = (pixels) => {
2620
+ const rows = [];
2621
+ for (let y = 0; y < pixels.length; y += 2) {
2622
+ const top = pixels[y] ?? [];
2623
+ const bottom = pixels[y + 1] ?? [];
2624
+ rows.push(
2625
+ top.map((upper, x) => {
2626
+ const lower = bottom[x] === true;
2627
+ return upper && lower ? "\u2588" : upper ? "\u2580" : lower ? "\u2584" : " ";
2628
+ }).join("")
2629
+ );
2630
+ }
2631
+ return rows;
2632
+ };
2633
+ var drawLabel = (label, length, thickness) => {
2634
+ const glyphs = [...label].map((char) => glyphPixels(char, length, thickness));
2635
+ const gap = Array.from({ length: thickness }, () => false);
2636
+ const height = 2 * length + 3 * thickness;
2637
+ const pixels = Array.from(
2638
+ { length: height },
2639
+ (_, y) => glyphs.flatMap((glyph, index) => index === 0 ? glyph[y] : [...gap, ...glyph[y]])
2640
+ );
2641
+ const lit = (x) => pixels.some((line) => line[x] === true);
2642
+ const width = pixels[0]?.length ?? 0;
2643
+ let first = 0;
2644
+ while (first < width && !lit(first)) first += 1;
2645
+ let last = width - 1;
2646
+ while (last > first && !lit(last)) last -= 1;
2647
+ return halfBlocks(pixels.map((line) => line.slice(first, last + 1)));
2648
+ };
2649
+ var countdownLabel = (step) => step === 0 ? "GO" : String(step);
2650
+ var MAX_SEGMENT = 12;
2651
+ var countdownArt = (label, cols, rows) => {
2652
+ const marginRows = Math.floor(rows / 8);
2653
+ const marginCols = cols >= 12 ? 1 : 0;
2654
+ const fitRows = rows - 2 * marginRows;
2655
+ const fitCols = cols - 2 * marginCols;
2656
+ for (let length = MAX_SEGMENT; length >= 1; length -= 1) {
2657
+ const thickness = length >= 5 ? 2 : 1;
2658
+ const art = drawLabel(label, length, thickness);
2659
+ if (art.length <= fitRows && (art[0]?.length ?? 0) <= fitCols) return art;
2660
+ }
2661
+ return label.length <= cols ? [label] : [label.slice(0, Math.max(1, cols))];
2662
+ };
2663
+ var overlayArt = (board, art) => {
2664
+ const height = board.length;
2665
+ const width = [...board[0] ?? ""].length;
2666
+ const artWidth = Math.max(0, ...art.map((line) => [...line].length));
2667
+ const top = Math.floor((height - art.length) / 2);
2668
+ const left = Math.floor((width - artWidth) / 2);
2669
+ return board.map((line, y) => {
2670
+ const artLine = art[y - top];
2671
+ const artCells = artLine === void 0 ? [] : [...artLine];
2672
+ return [...line].map((cell, x) => {
2673
+ const char = artCells[x - left];
2674
+ return { board: cell, art: char === void 0 || char === " " ? null : char };
2675
+ });
2676
+ });
2677
+ };
2678
+
2060
2679
  // src/snake.tsx
2680
+ import { useEffect as useEffect2, useState as useState2 } from "react";
2061
2681
  import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "@opentui/react/jsx-runtime";
2062
- var TICK_MS = 140;
2063
2682
  var useSnake = (options) => {
2064
- const { width, height, enabled } = options;
2065
- const [game, setGame] = useState2(() => newSnakeGame(width, height, Math.random));
2066
- const [paused, setPaused] = useState2(false);
2683
+ const { width, height, focused } = options;
2684
+ const [stored, setPlay] = useState2(() => newSnakePlay(width, height, Math.random));
2685
+ let play = reduceSnake(stored, { type: "resize", width, height }, Math.random);
2686
+ if (play.focused !== focused) {
2687
+ play = reduceSnake(play, { type: focused ? "focus" : "blur" }, Math.random);
2688
+ }
2689
+ if (play !== stored) setPlay(play);
2690
+ const { clock } = play;
2691
+ const step = clock.kind === "countdown" ? clock.step : null;
2067
2692
  useEffect2(() => {
2068
- if (enabled) {
2069
- setGame(newSnakeGame(width, height, Math.random));
2070
- setPaused(false);
2693
+ if (clock.kind === "countdown") {
2694
+ const timer2 = setTimeout(
2695
+ () => setPlay((current) => reduceSnake(current, { type: "count" }, Math.random)),
2696
+ COUNTDOWN_STEP_MS
2697
+ );
2698
+ return () => clearTimeout(timer2);
2071
2699
  }
2072
- }, [width, height, enabled]);
2073
- useEffect2(() => {
2074
- if (!enabled || paused) return;
2075
- const timer = setInterval(() => setGame((current) => tick(current, Math.random)), TICK_MS);
2076
- return () => clearInterval(timer);
2077
- }, [enabled, paused]);
2078
- const steer = (direction) => {
2079
- setPaused(false);
2080
- setGame(
2081
- (current) => current.over ? newSnakeGame(current.width, current.height, Math.random) : turn(current, direction)
2700
+ if (clock.kind !== "running") return;
2701
+ const timer = setInterval(
2702
+ () => setPlay((current) => reduceSnake(current, { type: "tick" }, Math.random)),
2703
+ TICK_MS
2082
2704
  );
2083
- };
2084
- const togglePause = () => setPaused((current) => !current);
2085
- return { game, paused, steer, togglePause };
2705
+ return () => clearInterval(timer);
2706
+ }, [clock.kind, step]);
2707
+ const send = (event) => setPlay((current) => reduceSnake(current, event, Math.random));
2708
+ return { play, send };
2086
2709
  };
2087
- var SnakeHeading = ({
2088
- handle,
2089
- hint
2090
- }) => {
2091
- const { game, paused } = handle;
2092
- const state = game.over ? "over \xB7 any arrow starts again" : paused ? "paused" : null;
2093
- return /* @__PURE__ */ jsxs2(Fragment2, { children: [
2094
- /* @__PURE__ */ jsxs2("text", { height: 1, bg: "transparent", children: [
2095
- /* @__PURE__ */ jsx2("span", { children: " " }),
2096
- /* @__PURE__ */ jsx2("span", { fg: INK, children: "play snake while you wait" }),
2097
- /* @__PURE__ */ jsx2("span", { fg: FAINT, children: " \xB7 score " }),
2098
- /* @__PURE__ */ jsx2("span", { fg: game.over ? MUTED : ACCENT, children: String(game.score) }),
2099
- state === null ? null : /* @__PURE__ */ jsx2("span", { fg: FAINT, children: ` \xB7 ${state}` })
2100
- ] }),
2101
- /* @__PURE__ */ jsx2("text", { height: 1, bg: "transparent", fg: FAINT, children: ` ${hint}` })
2710
+ var SnakeHeading = ({ play }) => {
2711
+ const { game, clock } = play;
2712
+ const state = game.over ? "over" : clock.kind === "paused" ? "paused" : null;
2713
+ return /* @__PURE__ */ jsxs2("text", { height: 1, bg: "transparent", children: [
2714
+ /* @__PURE__ */ jsx2("span", { children: " " }),
2715
+ /* @__PURE__ */ jsx2("span", { fg: INK, children: "play snake while you wait" }),
2716
+ /* @__PURE__ */ jsx2("span", { fg: FAINT, children: " \xB7 score " }),
2717
+ /* @__PURE__ */ jsx2("span", { fg: game.over ? MUTED : ACCENT, children: String(game.score) }),
2718
+ state === null ? null : /* @__PURE__ */ jsx2("span", { fg: FAINT, children: ` \xB7 ${state}` })
2102
2719
  ] });
2103
2720
  };
2721
+ var SNAKE_IDLE = "enter plays";
2722
+ var snakeTooSmall = (short) => `make the terminal ${short ? "taller" : "wider"} to play snake`;
2723
+ var SNAKE_BEHIND_DIALOG = "the countdown starts when this dialog closes";
2724
+ var SnakeFooter = ({
2725
+ play,
2726
+ idle
2727
+ }) => /* @__PURE__ */ jsx2("text", { height: 1, bg: "transparent", fg: FAINT, children: ` ${play.focused ? snakeHints(play) : idle}` });
2728
+ var cellColor = (cell) => cell === "\u25C6" ? ACCENT : cell === "\u2588" ? GREEN : cell === "\u25CF" ? INK : FAINT;
2729
+ var SnakeRows = ({ play }) => {
2730
+ const { game, clock } = play;
2731
+ const board = render(game);
2732
+ if (clock.kind !== "countdown") {
2733
+ return /* @__PURE__ */ jsx2(Fragment2, { children: board.map((row, index) => /* @__PURE__ */ jsx2("text", { height: 1, bg: "transparent", children: [...row].map((cell, x) => /* @__PURE__ */ jsx2("span", { fg: cellColor(cell), children: cell === "\xB7" ? " " : cell }, x)) }, index)) });
2734
+ }
2735
+ const cells = overlayArt(
2736
+ board,
2737
+ countdownArt(countdownLabel(clock.step), game.width, game.height)
2738
+ );
2739
+ return /* @__PURE__ */ jsx2(Fragment2, { children: cells.map((row, index) => /* @__PURE__ */ jsx2("text", { height: 1, bg: "transparent", children: row.map(
2740
+ (cell, x) => cell.board !== "\xB7" || cell.art === null ? /* @__PURE__ */ jsx2("span", { fg: cellColor(cell.board), children: cell.board === "\xB7" ? " " : cell.board }, x) : /* @__PURE__ */ jsx2("span", { fg: ACCENT, children: cell.art }, x)
2741
+ ) }, index)) });
2742
+ };
2104
2743
  var SnakeBoard = ({
2105
2744
  handle,
2106
- focused
2745
+ idle
2107
2746
  }) => {
2108
- const { game } = handle;
2109
- const rows = render(game);
2747
+ const { play } = handle;
2110
2748
  return /* @__PURE__ */ jsxs2(Fragment2, { children: [
2111
- /* @__PURE__ */ jsx2(
2112
- SnakeHeading,
2113
- {
2114
- handle,
2115
- hint: focused ? "arrows steer \xB7 space pauses \xB7 esc puts it away" : "focus this pane to play \xB7 esc puts it away"
2116
- }
2117
- ),
2749
+ /* @__PURE__ */ jsx2(SnakeHeading, { play }),
2118
2750
  /* @__PURE__ */ jsx2(
2119
2751
  "box",
2120
2752
  {
2121
2753
  border: true,
2122
2754
  borderStyle: "rounded",
2123
- borderColor: focused ? ACCENT : RULE,
2124
- width: game.width + 2,
2125
- height: game.height + 2,
2755
+ borderColor: play.focused ? ACCENT : RULE,
2756
+ title: " snake ",
2757
+ titleAlignment: "left",
2758
+ width: play.game.width + 2,
2759
+ height: play.game.height + 2,
2126
2760
  flexShrink: 0,
2127
2761
  marginLeft: 2,
2128
- children: rows.map((row, index) => /* @__PURE__ */ jsx2("text", { height: 1, bg: "transparent", children: [...row].map((cell, x) => /* @__PURE__ */ jsx2(
2129
- "span",
2130
- {
2131
- fg: cell === "\u25C6" ? ACCENT : cell === "\u2588" ? GREEN : cell === "\u25CF" ? INK : FAINT,
2132
- children: cell === "\xB7" ? " " : cell
2133
- },
2134
- x
2135
- )) }, index))
2762
+ flexDirection: "column",
2763
+ children: /* @__PURE__ */ jsx2(SnakeRows, { play })
2136
2764
  }
2137
- )
2765
+ ),
2766
+ /* @__PURE__ */ jsx2(SnakeFooter, { play, idle })
2138
2767
  ] });
2139
2768
  };
2140
- var SnakeRows = ({ game }) => /* @__PURE__ */ jsx2(Fragment2, { children: render(game).map((row, index) => /* @__PURE__ */ jsx2("text", { height: 1, bg: "transparent", children: [...row].map((cell, x) => /* @__PURE__ */ jsx2(
2141
- "span",
2142
- {
2143
- fg: cell === "\u25C6" ? ACCENT : cell === "\u2588" ? GREEN : cell === "\u25CF" ? INK : FAINT,
2144
- children: cell === "\xB7" ? " " : cell
2145
- },
2146
- x
2147
- )) }, index)) });
2148
2769
 
2149
2770
  // src/dashboard.tsx
2150
2771
  import { Fragment as Fragment3, jsx as jsx3, jsxs as jsxs3 } from "@opentui/react/jsx-runtime";
@@ -2155,7 +2776,9 @@ var STATUS_COLOR = {
2155
2776
  idle: INK_2,
2156
2777
  completed: FAINT,
2157
2778
  failed: ERROR,
2158
- stopped: FAINT
2779
+ stopped: FAINT,
2780
+ stopping: INK_2,
2781
+ settled: FAINT
2159
2782
  };
2160
2783
  var AGENT_LIVE_STATUSES = /* @__PURE__ */ new Set(["starting", "running", "waiting"]);
2161
2784
  var timeAgo = (iso) => {
@@ -2168,14 +2791,14 @@ var timeAgo = (iso) => {
2168
2791
  if (hours < 24) return `${hours}h ago`;
2169
2792
  return `${Math.floor(hours / 24)}d ago`;
2170
2793
  };
2171
- var shortAge = (iso) => timeAgo(iso).replace(" ago", "");
2172
- var fit = (text, width) => text.length <= width ? text : `${text.slice(0, Math.max(0, width - 1))}\u2026`;
2173
- var COLUMN_TITLE = {
2174
- projects: "projects",
2175
- worktrees: "worktrees",
2176
- sessions: "sessions",
2177
- detail: "session"
2794
+ var lastSessionWords = (group) => {
2795
+ const at = group.sessions.length === 0 ? group.createdAt : groupActivityAt(group);
2796
+ const elapsed = elapsedWords(at);
2797
+ if (elapsed === null) return [];
2798
+ const ago = elapsed === "<1m" ? "just now" : `${elapsed} ago`;
2799
+ return [group.sessions.length === 0 ? `created ${ago}` : `last session created ${ago}`];
2178
2800
  };
2801
+ var fit = (text, width) => text.length <= width ? text : `${text.slice(0, Math.max(0, width - 1))}\u2026`;
2179
2802
  var WORKTREE_ROW_HEIGHT = 2;
2180
2803
  var SESSION_ROW_HEIGHT = 2;
2181
2804
  var Gutter = ({ selected }) => /* @__PURE__ */ jsx3("span", { fg: selected ? ACCENT : FAINT, children: selected ? "\u258C " : " " });
@@ -2234,7 +2857,7 @@ var ProjectRow = ({
2234
2857
  return /* @__PURE__ */ jsx3("box", { height: 1, flexShrink: 0, backgroundColor: selected ? WASH : "transparent", children: /* @__PURE__ */ jsxs3("text", { height: 1, bg: "transparent", children: [
2235
2858
  /* @__PURE__ */ jsx3(Gutter, { selected }),
2236
2859
  /* @__PURE__ */ jsx3("span", { fg: INK, children: fit(item.project.name, nameWidth).padEnd(nameWidth + 1) }),
2237
- /* @__PURE__ */ jsx3("span", { fg: item.live > 0 ? MUTED : FAINT, children: item.live > 0 ? `${item.live}/${item.total}` : String(item.total) })
2860
+ /* @__PURE__ */ jsx3("span", { fg: item.live + item.stopping > 0 ? MUTED : FAINT, children: item.live + item.stopping > 0 ? `${item.live + item.stopping}/${item.total}` : String(item.total) })
2238
2861
  ] }) });
2239
2862
  };
2240
2863
  var WorktreeRow = ({
@@ -2242,18 +2865,16 @@ var WorktreeRow = ({
2242
2865
  selected,
2243
2866
  width
2244
2867
  }) => {
2245
- const folded = foldGroupStatus(group);
2246
- const live = group.live > 0;
2247
- const status = live ? folded : "settled";
2248
- const color = live ? STATUS_COLOR[folded] ?? MUTED : FAINT;
2868
+ const status = foldGroupStatus(group);
2869
+ const color = STATUS_COLOR[status] ?? MUTED;
2249
2870
  const open = group.annotation?.openComments ?? 0;
2250
2871
  const sessions = group.sessions.length;
2251
2872
  const nameWidth = Math.max(6, width - 5 - status.length);
2252
2873
  const factWidth = Math.max(8, width - 3);
2253
2874
  const facts = fitHints(
2254
2875
  [
2255
- fit(groupBaseLabel(group), factWidth),
2256
- shortAge(groupActivityAt(group)),
2876
+ fit(`from ${groupBaseLabel(group)}`, Math.max(12, Math.floor(factWidth / 2))),
2877
+ ...lastSessionWords(group),
2257
2878
  ...open > 0 ? [`${open} open`] : [],
2258
2879
  ...sessions === 0 ? ["empty"] : sessions === 1 ? [] : [`${sessions} sessions`]
2259
2880
  ],
@@ -2273,25 +2894,12 @@ var SessionRow = ({
2273
2894
  selected,
2274
2895
  width
2275
2896
  }) => {
2276
- const { session, processes, services } = item;
2897
+ const { session } = item;
2277
2898
  const status = session.status;
2278
2899
  const color = STATUS_COLOR[status] ?? MUTED;
2279
- const agents = processes.filter((process2) => process2.kind !== "shell").length;
2280
- const shells = processes.filter((process2) => process2.kind === "shell").length;
2281
2900
  const nameWidth = Math.max(6, width - 5 - status.length);
2282
2901
  const factWidth = Math.max(8, width - 3);
2283
- const hold = sessionHold(item);
2284
- const facts = fitHints(
2285
- [
2286
- ...hold === null ? [] : [hold],
2287
- session.harness,
2288
- shortAge(session.createdAt),
2289
- ...shells > 0 ? [`${shells} shell`] : [],
2290
- ...agents > 0 ? [`${agents} agent`] : [],
2291
- ...hold === null && services.length > 0 ? [`${services.length} service`] : []
2292
- ],
2293
- factWidth
2294
- );
2902
+ const facts = sessionRowFacts(item, factWidth);
2295
2903
  return /* @__PURE__ */ jsxs3("box", { flexShrink: 0, flexDirection: "column", backgroundColor: selected ? WASH : "transparent", children: [
2296
2904
  /* @__PURE__ */ jsx3("box", { height: 1, flexShrink: 0, backgroundColor: "transparent", children: /* @__PURE__ */ jsxs3("text", { height: 1, bg: "transparent", children: [
2297
2905
  /* @__PURE__ */ jsx3(Gutter, { selected }),
@@ -2304,11 +2912,12 @@ var SessionRow = ({
2304
2912
  var HarnessRow = ({
2305
2913
  item,
2306
2914
  selected,
2307
- background
2915
+ background,
2916
+ width
2308
2917
  }) => /* @__PURE__ */ jsx3("box", { height: 1, flexShrink: 0, backgroundColor: selected ? WASH : background, children: /* @__PURE__ */ jsxs3("text", { height: 1, bg: selected ? WASH : background, children: [
2309
2918
  /* @__PURE__ */ jsx3(Gutter, { selected }),
2310
2919
  /* @__PURE__ */ jsx3("span", { fg: INK, children: item.label.padEnd(12) }),
2311
- /* @__PURE__ */ jsx3("span", { fg: FAINT, children: item.hint })
2920
+ /* @__PURE__ */ jsx3("span", { fg: FAINT, children: fit(item.hint, Math.max(4, width - 2 - 12)) })
2312
2921
  ] }) });
2313
2922
  var PREVIEW_GLYPH = {
2314
2923
  user: "\u203A ",
@@ -2336,12 +2945,16 @@ var SessionFacts = ({
2336
2945
  group,
2337
2946
  item,
2338
2947
  rows,
2339
- tunnels
2948
+ tunnels,
2949
+ workspaceRows
2340
2950
  }) => {
2341
2951
  const { session, annotation, services } = item;
2342
2952
  const color = STATUS_COLOR[session.status] ?? MUTED;
2343
2953
  const hold = sessionHold(item);
2344
- const summary = session.summary?.split("\n")[0] ?? null;
2954
+ const starting = session.status === "starting";
2955
+ const phase = starting ? startingWordsOf(session) : null;
2956
+ const summary = (starting ? withoutLaunchPhase(session.summary) : session.summary)?.split("\n")[0] ?? null;
2957
+ const when = starting ? null : sessionTimeWords(item);
2345
2958
  const change = annotation ?? group?.annotation;
2346
2959
  const lines = [
2347
2960
  /* @__PURE__ */ jsxs3("text", { height: 1, bg: "transparent", children: [
@@ -2352,6 +2965,10 @@ var SessionFacts = ({
2352
2965
  /* @__PURE__ */ jsxs3("text", { height: 1, bg: "transparent", children: [
2353
2966
  /* @__PURE__ */ jsx3("span", { children: " " }),
2354
2967
  /* @__PURE__ */ jsx3("span", { fg: color, children: session.status }),
2968
+ phase === null ? null : /* @__PURE__ */ jsxs3(Fragment3, { children: [
2969
+ /* @__PURE__ */ jsx3("span", { fg: FAINT, children: " \xB7 " }),
2970
+ /* @__PURE__ */ jsx3("span", { fg: INK_2, children: phase })
2971
+ ] }),
2355
2972
  hold === null ? null : /* @__PURE__ */ jsxs3(Fragment3, { children: [
2356
2973
  /* @__PURE__ */ jsx3("span", { fg: FAINT, children: " \xB7 " }),
2357
2974
  /* @__PURE__ */ jsx3("span", { fg: INK_2, children: hold })
@@ -2360,7 +2977,23 @@ var SessionFacts = ({
2360
2977
  /* @__PURE__ */ jsx3("span", { fg: MUTED, children: session.branch }),
2361
2978
  /* @__PURE__ */ jsx3("span", { fg: FAINT, children: session.baseSha === "" ? "" : ` vs ${session.baseRef ?? session.baseSha.slice(0, 12)}` })
2362
2979
  ] }, "status"),
2363
- /* @__PURE__ */ jsx3("text", { height: 1, bg: "transparent", fg: FAINT, children: ` started ${timeAgo(session.createdAt)} \xB7 ${isPendingId(session.id) ? "provisioning" : session.id.slice(0, 8)}` }, "started"),
2980
+ // Who else is live here, what a turn waits for, a workspace waiting to be replaced: right
2981
+ // under the status, before the facts a short pane may drop.
2982
+ ...workspaceRows.map((row, index) => /* @__PURE__ */ jsx3(
2983
+ "text",
2984
+ {
2985
+ height: 1,
2986
+ bg: "transparent",
2987
+ fg: row.startsWith(" ") ? MUTED : INK_2,
2988
+ children: ` ${row}`
2989
+ },
2990
+ `workspace-${index}`
2991
+ )),
2992
+ /* @__PURE__ */ jsx3("text", { height: 1, bg: "transparent", fg: FAINT, children: [
2993
+ ...timeAgo(session.createdAt) === "" ? [] : [`created ${timeAgo(session.createdAt)}`],
2994
+ isPendingId(session.id) ? "provisioning" : session.id.slice(0, 8),
2995
+ ...when === null || when.startsWith("created ") ? [] : [when]
2996
+ ].join(" \xB7 ").replace(/^/, " ") }, "started"),
2364
2997
  /* @__PURE__ */ jsxs3("text", { height: 1, bg: "transparent", children: [
2365
2998
  /* @__PURE__ */ jsx3("span", { children: " " }),
2366
2999
  services.length === 0 ? /* @__PURE__ */ jsx3("span", { fg: FAINT, children: "no services running" }) : services.slice(0, 2).map((service, index) => {
@@ -2409,7 +3042,7 @@ var StatusLine = ({
2409
3042
  }
2410
3043
  return void 0;
2411
3044
  }, [busy, status]);
2412
- const text = busy === null ? status !== null && Date.now() - status.at < 5e3 ? ` ${status.text}` : "" : ` ${busy} ${Math.max(0, Math.round((now - busyStarted) / 1e3))}s`;
3045
+ const text = busy === null ? status !== null && Date.now() - status.at < 5e3 ? ` ${status.text}` : "" : ` ${busy} ${Math.max(0, Math.round((now - busyStarted) / 1e3))}s elapsed`;
2413
3046
  return /* @__PURE__ */ jsx3("text", { height: 1, fg: INK_2, bg: "transparent", children: text });
2414
3047
  };
2415
3048
  var errorText = (error) => error instanceof Error ? error.message : String(error);
@@ -2421,7 +3054,8 @@ var startedOrStarting = async (start, starting) => {
2421
3054
  throw error;
2422
3055
  }
2423
3056
  };
2424
- var startedLine = (session) => session.status === "starting" ? `still starting \xB7 ${sessionDisplayName(session)} \u2014 a attaches once the row reads running` : `started \xB7 ${sessionDisplayName(session)} \u2014 a attaches`;
3057
+ var stillStartingLine = (session, verb, awaited) => session.status !== "starting" ? null : `still ${verb} \xB7 ${sessionDisplayName(session)} \xB7 ${awaited ? "attaches once it runs" : "a attaches once the row reads running"}`;
3058
+ var HANDOVER_MS = 600;
2425
3059
  var keepSpanVisible = (scroll, top, height, viewRows) => {
2426
3060
  if (scroll === null || viewRows <= 0) return;
2427
3061
  const viewH = Math.max(1, viewRows);
@@ -2430,10 +3064,23 @@ var keepSpanVisible = (scroll, top, height, viewRows) => {
2430
3064
  };
2431
3065
  var PREVIEW_MAX_LINES = 300;
2432
3066
  var SESSION_FACT_ROWS = 6;
3067
+ var SNAKE_CHROME_ROWS = 5;
3068
+ var SNAKE_MIN_BOARD_ROWS = 4;
3069
+ var SNAKE_MIN_BOARD_COLS = 8;
3070
+ var SNAKE_MIN_PANE_ROWS = SNAKE_CHROME_ROWS + SNAKE_MIN_BOARD_ROWS;
3071
+ var SNAKE_MIN_PANE_COLS = SNAKE_MIN_BOARD_COLS + 4;
2433
3072
  var noShare = () => "off";
2434
3073
  var NO_TUNNELS = [];
2435
3074
  var noTunnels = () => NO_TUNNELS;
2436
- var App = ({ ctx, onQuit }) => {
3075
+ var NO_FILTERS = {
3076
+ projects: "",
3077
+ worktrees: "",
3078
+ sessions: ""
3079
+ };
3080
+ var App = ({
3081
+ ctx,
3082
+ onQuit
3083
+ }) => {
2437
3084
  const renderer = useRenderer();
2438
3085
  const queryClient = useQueryClient2();
2439
3086
  const { data, failureReason } = useQuery2({
@@ -2443,8 +3090,13 @@ var App = ({ ctx, onQuit }) => {
2443
3090
  retry: true,
2444
3091
  retryDelay: 1e3
2445
3092
  });
2446
- const [focus, setFocusState] = useState3("sessions");
3093
+ const [columnFocus, setFocusState] = useState3("sessions");
2447
3094
  const [lastNav, setLastNav] = useState3("sessions");
3095
+ const [screenMode, setScreenMode] = useState3("normal");
3096
+ const [filters, setFilters] = useState3(NO_FILTERS);
3097
+ const [filtering, setFiltering] = useState3(null);
3098
+ const [helpOpen, setHelpOpen] = useState3(false);
3099
+ const [helpOffset, setHelpOffset] = useState3(0);
2448
3100
  const [projectKey, setProjectKey] = useState3(null);
2449
3101
  const [worktreeKey, setWorktreeKey] = useState3(null);
2450
3102
  const [sessionKey, setSessionKey] = useState3(null);
@@ -2471,12 +3123,19 @@ var App = ({ ctx, onQuit }) => {
2471
3123
  const adoptOfferDecided = useRef2(false);
2472
3124
  const [reviewing, setReviewing] = useState3(null);
2473
3125
  const lockRef = useRef2(false);
3126
+ const startsRef = useRef2([]);
3127
+ const awaitedRef = useRef2(null);
3128
+ const autoAttach = ctx.autoAttach !== false;
3129
+ const [snakeFocus, setSnakeFocus] = useState3(null);
3130
+ const [snakeOverlay, setSnakeOverlay] = useState3(ctx.openSnake === true);
2474
3131
  const [gate] = useState3(createLaunchGate);
2475
3132
  const creatingRef = useRef2(creating);
2476
3133
  creatingRef.current = creating;
2477
3134
  const branchRequest = useRef2(0);
2478
3135
  const { width: terminalCols, height: terminalRows } = useTerminalDimensions2();
2479
- const projectItems = deriveProjects(data);
3136
+ const projectItems = deriveProjects(data).filter(
3137
+ (item) => matchesFilter(filters.projects, item.project.name)
3138
+ );
2480
3139
  const homeProject = data === void 0 ? void 0 : matchProjectByCwd(data.projects, cwdFacts(ctx.cwd));
2481
3140
  const projectIndexRaw = projectKey === null ? -1 : projectItems.findIndex((p) => p.project.id === projectKey);
2482
3141
  const projectIndex = projectIndexRaw === -1 ? Math.max(
@@ -2484,20 +3143,42 @@ var App = ({ ctx, onQuit }) => {
2484
3143
  homeProject === void 0 ? 0 : projectItems.findIndex((p) => p.project.id === homeProject.id)
2485
3144
  ) : projectIndexRaw;
2486
3145
  const selectedProject = projectItems[projectIndex] ?? null;
2487
- const worktreeGroups = deriveWorktrees(data, selectedProject?.project.id ?? null);
3146
+ const worktreeGroups = deriveWorktrees(data, selectedProject?.project.id ?? null).filter(
3147
+ (group) => matchesFilter(filters.worktrees, group.name, groupBaseLabel(group))
3148
+ );
2488
3149
  const worktreeIndexRaw = worktreeKey === null ? -1 : worktreeGroups.findIndex((group) => group.key === worktreeKey);
2489
3150
  const sessionWorktreeIndex = worktreeGroups.findIndex(
2490
3151
  (group) => group.sessions.some((item) => item.session.id === sessionKey)
2491
3152
  );
2492
3153
  const worktreeIndex = worktreeIndexRaw === -1 ? Math.max(0, sessionWorktreeIndex) : worktreeIndexRaw;
2493
3154
  const selectedGroup = worktreeGroups[worktreeIndex] ?? null;
2494
- const sessionItems = selectedGroup?.sessions ?? [];
3155
+ const sessionItems = (selectedGroup?.sessions ?? []).filter(
3156
+ (item) => matchesFilter(
3157
+ filters.sessions,
3158
+ sessionDisplayName(item.session),
3159
+ item.session.harness,
3160
+ item.session.status
3161
+ )
3162
+ );
2495
3163
  const sessionIndexRaw = sessionKey === null ? -1 : sessionItems.findIndex((item) => item.session.id === sessionKey);
2496
3164
  const sessionIndex = sessionIndexRaw === -1 ? 0 : sessionIndexRaw;
2497
3165
  const selectedItem = sessionItems[sessionIndex] ?? null;
2498
3166
  const selectedSession = selectedItem?.session ?? null;
2499
- const pickerItems = picker === null ? [] : deriveHarnesses(picker.session);
2500
- const layout = planLayout(terminalCols, terminalRows, focus, lastNav);
3167
+ const pickerItems = picker === null ? [] : deriveHarnesses(picker.session, picker.worktree?.name ?? null);
3168
+ const waiting = selectedSession !== null && (selectedSession.status === "starting" || isPendingId(selectedSession.id));
3169
+ const dialogOpen = picker !== null || editing !== null || creating !== null || adoptOffer !== null || reviewing !== null || helpOpen || filtering !== null;
3170
+ const gameLayout = planLayout(terminalCols, terminalRows, "detail", lastNav);
3171
+ const snakeFits = gameLayout.detailRows >= SNAKE_MIN_PANE_ROWS && gameLayout.detailWidth >= SNAKE_MIN_PANE_COLS;
3172
+ const overlayFits = terminalRows >= 12 && terminalCols >= 22;
3173
+ const adoptFailureLines = adoptOffer?.failure === void 0 ? [] : wrapWords(adoptOffer.failure, Math.min(70, terminalCols - 4) - 6).slice(
3174
+ 0,
3175
+ Math.max(1, terminalRows - 9)
3176
+ );
3177
+ const overlayOpen = snakeOverlay && !dialogOpen;
3178
+ const overlayFocused = overlayOpen && overlayFits;
3179
+ const snakeFocused = snakeFocus !== null && waiting && snakeFits && !dialogOpen && !snakeOverlay;
3180
+ const focus = snakeFocused ? "detail" : columnFocus;
3181
+ const layout = planLayout(terminalCols, terminalRows, focus, lastNav, screenMode);
2501
3182
  const detailWidth = layout.detailWidth;
2502
3183
  const sectionRows = (section) => layout.sections.find((entry) => entry.section === section)?.rows ?? 0;
2503
3184
  const previewSessionId = selectedSession !== null && !isPendingId(selectedSession.id) ? selectedSession.id : null;
@@ -2518,6 +3199,28 @@ var App = ({ ctx, onQuit }) => {
2518
3199
  refetchInterval: previewLive ? 8e3 : false,
2519
3200
  retry: 1
2520
3201
  });
3202
+ const viewer = useQuery2({
3203
+ queryKey: VIEWER_KEY,
3204
+ queryFn: () => fetchViewer(ctx),
3205
+ enabled: viewerNeeded(data),
3206
+ staleTime: Number.POSITIVE_INFINITY,
3207
+ retry: false
3208
+ });
3209
+ const workspaceReads = selectedSession === null ? { waiting: false, retirement: false } : workspaceReadsOf(selectedSession);
3210
+ const workspaceFacts = useQuery2({
3211
+ queryKey: WORKSPACE_FACTS_KEY(previewSessionId ?? "none", workspaceReads),
3212
+ queryFn: () => fetchWorkspaceFacts(ctx.api, previewSessionId ?? "", workspaceReads),
3213
+ enabled: previewSessionId !== null && previewLive && detailWidth > 0 && (workspaceReads.waiting || workspaceReads.retirement),
3214
+ staleTime: 3e3,
3215
+ refetchInterval: previewLive ? 8e3 : false,
3216
+ retry: 1
3217
+ });
3218
+ const workspaceRows = selectedSession === null || !previewLive || detailWidth === 0 ? [] : workspaceFactRows(
3219
+ selectedSession,
3220
+ viewer.data,
3221
+ workspaceFacts.data,
3222
+ Math.max(16, detailWidth - 4)
3223
+ );
2521
3224
  const preview = useMemo2(
2522
3225
  () => transcript.data === void 0 ? [] : previewLines(transcript.data, {
2523
3226
  width: Math.max(16, detailWidth - 6),
@@ -2526,24 +3229,28 @@ var App = ({ ctx, onQuit }) => {
2526
3229
  [transcript.data, detailWidth]
2527
3230
  );
2528
3231
  const [previewOffset, setPreviewOffset] = useState3(0);
2529
- const factRows = Math.max(0, Math.min(SESSION_FACT_ROWS, layout.detailRows - 2));
3232
+ const allFactRows = Math.max(
3233
+ 0,
3234
+ Math.min(SESSION_FACT_ROWS + workspaceRows.length, layout.detailRows - 2)
3235
+ );
3236
+ const factRows = waiting ? Math.max(0, Math.min(allFactRows, layout.detailRows - SNAKE_MIN_PANE_ROWS - 1)) : allFactRows;
2530
3237
  const showFactRule = factRows > 0 && layout.detailRows - factRows > 1;
2531
- const waiting = selectedSession !== null && (selectedSession.status === "starting" || isPendingId(selectedSession.id));
3238
+ const snakeRoom = {
3239
+ cols: detailWidth - 4,
3240
+ rows: layout.detailRows - factRows - (showFactRule ? 1 : 0) - SNAKE_CHROME_ROWS
3241
+ };
3242
+ const snakeShown = snakeRoom.rows >= SNAKE_MIN_BOARD_ROWS && snakeRoom.cols >= SNAKE_MIN_BOARD_COLS;
2532
3243
  const snake = useSnake({
2533
- width: Math.max(8, Math.min(40, detailWidth - 4)),
2534
- // The pane minus the facts, the rule, the starting line, two lines of hints and the border.
2535
- height: Math.max(4, Math.min(14, layout.detailRows - factRows - 8)),
2536
- enabled: waiting
3244
+ width: Math.max(SNAKE_MIN_BOARD_COLS, Math.min(40, snakeRoom.cols)),
3245
+ height: Math.max(SNAKE_MIN_BOARD_ROWS, Math.min(14, snakeRoom.rows)),
3246
+ focused: snakeFocused
2537
3247
  });
2538
- const [snakeAwayFor, setSnakeAwayFor] = useState3(null);
2539
- const snakeShown = waiting && snakeAwayFor !== selectedSession?.id;
2540
- const [snakeOverlay, setSnakeOverlay] = useState3(ctx.openSnake === true);
2541
3248
  const overlayWidth = Math.max(16, Math.min(60, terminalCols - 8));
2542
3249
  const overlayHeight = Math.max(6, Math.min(20, terminalRows - 10));
2543
3250
  const overlaySnake = useSnake({
2544
3251
  width: overlayWidth,
2545
3252
  height: overlayHeight,
2546
- enabled: snakeOverlay
3253
+ focused: overlayFocused
2547
3254
  });
2548
3255
  const previewRows = Math.max(1, layout.detailRows - factRows - (showFactRule ? 1 : 0));
2549
3256
  const previewView = previewWindow(preview, previewRows, previewOffset);
@@ -2556,6 +3263,9 @@ var App = ({ ctx, onQuit }) => {
2556
3263
  setPreviewOffset(0);
2557
3264
  };
2558
3265
  const say = (text) => setStatus({ text, at: Date.now() });
3266
+ const clearFilters = (...sections) => setFilters(
3267
+ (current) => sections.every((section) => current[section] === "") ? current : { ...current, ...Object.fromEntries(sections.map((section) => [section, ""])) }
3268
+ );
2559
3269
  const refetch = () => void queryClient.invalidateQueries({ queryKey: WORKBENCH_KEY });
2560
3270
  useEffect3(() => {
2561
3271
  const share = ctx.agentShare;
@@ -2563,16 +3273,16 @@ var App = ({ ctx, onQuit }) => {
2563
3273
  return share.subscribe((event) => {
2564
3274
  if (event === null) return;
2565
3275
  if (event.kind === "sign-requested") {
2566
- say(`\u270E signature requested (${event.context}) \u2014 touch your key if it blinks`);
3276
+ say(`\u270E signature requested \xB7 ${event.context} \xB7 touch your key if it blinks`);
2567
3277
  } else if (event.kind === "signed") say(`\u2713 signed (${event.seconds.toFixed(1)}s)`);
2568
- else if (event.kind === "not-signed") say(`\u2717 not signed \u2014 ${event.message}`);
3278
+ else if (event.kind === "not-signed") say(`\u2717 not signed \xB7 ${event.message}`);
2569
3279
  });
2570
3280
  }, [ctx.agentShare]);
2571
3281
  useEffect3(() => {
2572
3282
  if (data === void 0 || adoptOfferDecided.current) return;
2573
3283
  if (homeProject !== void 0) return;
2574
3284
  adoptOfferDecided.current = true;
2575
- setAdoptOffer(deriveAdoptOffer(cwdFacts(ctx.cwd)));
3285
+ setAdoptOffer(deriveAdoptOffer(cwdFacts(ctx.cwd), ctx.gitAccessMode));
2576
3286
  }, [data, homeProject]);
2577
3287
  const projectScrollRef = useRef2(null);
2578
3288
  const worktreeScrollRef = useRef2(null);
@@ -2602,6 +3312,7 @@ var App = ({ ctx, onQuit }) => {
2602
3312
  const attachFlow = async (session) => {
2603
3313
  const short = session.id.slice(0, 8);
2604
3314
  lockRef.current = true;
3315
+ awaitedRef.current = null;
2605
3316
  renderer.suspend();
2606
3317
  const tunneled = openTunnels.filter((tunnel) => tunnel.service.sessionId === session.id).map((tunnel) => `\u25CF ${tunnel.line} \xB7 tunnel
2607
3318
  `).join("");
@@ -2612,8 +3323,9 @@ ${tunneled}
2612
3323
  `
2613
3324
  );
2614
3325
  let outcome;
3326
+ let rawModeRefusal = null;
2615
3327
  try {
2616
- outcome = await ctx.attachTty(session.id, session.harness);
3328
+ ({ outcome, rawModeRefusal } = await ctx.attachTty(session.id, session.harness));
2617
3329
  if (outcome === "unavailable") {
2618
3330
  const detail = await ctx.api(
2619
3331
  "GET",
@@ -2622,25 +3334,25 @@ ${tunneled}
2622
3334
  const liveProtocol = liveProtocolOf(detail.processes);
2623
3335
  const existing = liveShellOf(detail.processes);
2624
3336
  if (liveProtocol !== null) {
2625
- process.stdout.write(`taking over from the protocol session \u2014 same conversation\u2026
3337
+ process.stdout.write(`taking over from the protocol session \xB7 same conversation\u2026
2626
3338
 
2627
3339
  `);
2628
3340
  await ctx.api("POST", `/sessions/${session.id}/handoff`, { to: "pty" });
2629
- outcome = await ctx.attachTty(session.id, session.harness);
3341
+ ({ outcome, rawModeRefusal } = await ctx.attachTty(session.id, session.harness));
2630
3342
  } else if (existing === null) {
2631
3343
  const shell = await ctx.api(
2632
3344
  "POST",
2633
3345
  `/sessions/${session.id}/shell`
2634
3346
  );
2635
- process.stdout.write(`no live terminal \u2014 opened a shell in the workspace
3347
+ process.stdout.write(`no live terminal \xB7 opened a shell in the workspace
2636
3348
 
2637
3349
  `);
2638
- outcome = await ctx.attachTty(session.id, "shell", shell.id);
3350
+ ({ outcome, rawModeRefusal } = await ctx.attachTty(session.id, "shell", shell.id));
2639
3351
  } else {
2640
- process.stdout.write(`no live terminal \u2014 rejoining the open shell
3352
+ process.stdout.write(`no live terminal \xB7 rejoining the open shell
2641
3353
 
2642
3354
  `);
2643
- outcome = await ctx.attachTty(session.id, "shell", existing.id);
3355
+ ({ outcome, rawModeRefusal } = await ctx.attachTty(session.id, "shell", existing.id));
2644
3356
  }
2645
3357
  }
2646
3358
  } catch (error) {
@@ -2650,11 +3362,56 @@ ${tunneled}
2650
3362
  renderer.resume();
2651
3363
  lockRef.current = false;
2652
3364
  }
3365
+ const outcomeLine = outcome === "unavailable" ? "attach unavailable \xB7 could not connect" : outcome === "no-answer" ? `no answer \xB7 the server did not open ${short}'s terminal; it keeps running \xB7 a tries again` : outcome === "detached" || outcome === "interrupted" ? `detached \xB7 ${short} keeps running` : outcome === "dropped" ? `disconnected \xB7 ${short} \xB7 refreshing session status` : `terminal ended \xB7 ${short} \xB7 refreshing session status`;
2653
3366
  say(
2654
- outcome === "unavailable" ? "attach unavailable \u2014 could not connect" : outcome === "no-answer" ? `no answer \u2014 the server did not open ${short}'s terminal; it keeps running \xB7 a tries again` : outcome === "detached" || outcome === "interrupted" ? `detached \u2014 ${short} keeps running` : outcome === "dropped" ? `disconnected \xB7 ${short} \u2014 refreshing session status` : `terminal ended \xB7 ${short} \u2014 refreshing session status`
3367
+ rawModeRefusal === null ? outcomeLine : `${outcomeLine} \xB7 could not leave raw mode (${rawModeRefusal.message})`
2655
3368
  );
2656
3369
  refetch();
2657
3370
  };
3371
+ const watchStart = (id, verb) => {
3372
+ startsRef.current = [...startsRef.current, { id, verb, sessionId: null }];
3373
+ awaitedRef.current = id;
3374
+ };
3375
+ const answerStart = (id, sessionId) => {
3376
+ startsRef.current = startsRef.current.map(
3377
+ (watch) => watch.id === id ? { ...watch, sessionId } : watch
3378
+ );
3379
+ };
3380
+ const dropStart = (id) => {
3381
+ startsRef.current = startsRef.current.filter((watch) => watch.id !== id);
3382
+ if (awaitedRef.current === id) awaitedRef.current = null;
3383
+ };
3384
+ const stopAwaiting = () => {
3385
+ awaitedRef.current = null;
3386
+ };
3387
+ const handOver = (session) => {
3388
+ lockRef.current = true;
3389
+ const played = snake.play.clock.kind !== "ready" || snake.play.game.score > 0;
3390
+ setSnakeFocus(null);
3391
+ say(
3392
+ `ready \xB7 ${sessionDisplayName(session)} \xB7 attaching${played ? ` \xB7 snake score ${snake.play.game.score}` : ""}`
3393
+ );
3394
+ setTimeout(() => void attachFlow(session), HANDOVER_MS);
3395
+ };
3396
+ useEffect3(() => {
3397
+ if (data === void 0 || startsRef.current.length === 0) return;
3398
+ let attach = null;
3399
+ for (const watch of startsRef.current) {
3400
+ const progress = startProgress(data, watch);
3401
+ if (progress.kind === "starting") continue;
3402
+ const awaited = awaitedRef.current === watch.id;
3403
+ dropStart(watch.id);
3404
+ const name = sessionDisplayName(progress.session);
3405
+ if (progress.kind === "ended") {
3406
+ say(`${progress.session.status} \xB7 ${name} \xB7 it did not reach running`);
3407
+ } else if (awaited && autoAttach && !dialogOpen && !lockRef.current && selectedSession?.id === progress.session.id) {
3408
+ attach = progress.session;
3409
+ } else {
3410
+ say(`${watch.verb} \xB7 ${name} \xB7 a attaches`);
3411
+ }
3412
+ }
3413
+ if (attach !== null) handOver(attach);
3414
+ }, [data]);
2658
3415
  const settleRefetch = () => {
2659
3416
  if (queryClient.isMutating() === 1) refetch();
2660
3417
  };
@@ -2665,8 +3422,9 @@ ${tunneled}
2665
3422
  };
2666
3423
  const launchMutation = useMutation2({
2667
3424
  mutationFn: async (vars) => {
2668
- const argv = HARNESS_COMMANDS[vars.harness];
2669
- if (argv === void 0) throw new Error(`unknown harness "${vars.harness}"`);
3425
+ if (HARNESS_COMMANDS[vars.harness] === void 0) {
3426
+ throw new Error(`unknown harness "${vars.harness}"`);
3427
+ }
2670
3428
  const session = await ctx.api("POST", `/projects/${vars.projectId}/sessions`, {
2671
3429
  harness: vars.harness,
2672
3430
  label: null,
@@ -2674,7 +3432,7 @@ ${tunneled}
2674
3432
  base: vars.base
2675
3433
  });
2676
3434
  return startedOrStarting(
2677
- ctx.api("POST", `/sessions/${session.id}/launch`, { argv }),
3435
+ ctx.api("POST", `/sessions/${session.id}/launch`, {}),
2678
3436
  session
2679
3437
  );
2680
3438
  },
@@ -2693,17 +3451,26 @@ ${tunneled}
2693
3451
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
2694
3452
  })
2695
3453
  );
3454
+ clearFilters("worktrees", "sessions");
2696
3455
  setWorktreeKey(vars.pendingKey);
2697
3456
  selectSession(vars.pendingKey);
2698
- setBusy(`provisioning ${vars.harness} workspace \u2014 a first launch builds the harness image \xB7`);
3457
+ setBusy(`provisioning ${vars.harness} workspace \xB7`);
2699
3458
  setBusyStarted(Date.now());
2700
3459
  },
2701
3460
  onError: (error, vars) => {
3461
+ dropStart(vars.pendingKey);
2702
3462
  patchWorkbench((current) => removeSession(current, vars.projectId, vars.pendingKey));
3463
+ setSnakeFocus((current) => current?.start === vars.gateKey ? null : current);
2703
3464
  setBusy(null);
2704
3465
  say(errorText(error));
2705
3466
  },
2706
3467
  onSuccess: (session, vars) => {
3468
+ const line = stillStartingLine(
3469
+ session,
3470
+ "starting",
3471
+ autoAttach && awaitedRef.current === vars.pendingKey
3472
+ );
3473
+ answerStart(vars.pendingKey, session.id);
2707
3474
  patchWorkbench(
2708
3475
  (current) => replaceSession(current, vars.projectId, vars.pendingKey, session)
2709
3476
  );
@@ -2712,7 +3479,7 @@ ${tunneled}
2712
3479
  );
2713
3480
  setSessionKey((current) => current === vars.pendingKey ? session.id : current);
2714
3481
  setBusy(null);
2715
- say(startedLine(session));
3482
+ if (line !== null) say(line);
2716
3483
  },
2717
3484
  onSettled: (_data, _error, vars) => {
2718
3485
  gate.release(vars.gateKey);
@@ -2736,60 +3503,58 @@ ${tunneled}
2736
3503
  );
2737
3504
  selectSession(vars.session.id);
2738
3505
  setBusy(
2739
- `resuming ${sessionDisplayName(vars.session)} \u2014 a fresh workspace restores the saved state \xB7`
3506
+ `resuming ${sessionDisplayName(vars.session)} \xB7 a fresh workspace restores the saved state \xB7`
2740
3507
  );
2741
3508
  setBusyStarted(Date.now());
2742
3509
  },
2743
- onError: (error) => {
3510
+ onError: (error, vars) => {
3511
+ dropStart(vars.watch);
3512
+ setSnakeFocus((current) => current?.start === vars.gateKey ? null : current);
2744
3513
  setBusy(null);
2745
3514
  say(errorText(error));
2746
3515
  refetch();
2747
3516
  },
2748
3517
  onSuccess: (resumed, vars) => {
3518
+ const line = stillStartingLine(
3519
+ resumed,
3520
+ "resuming",
3521
+ autoAttach && awaitedRef.current === vars.watch
3522
+ );
3523
+ answerStart(vars.watch, resumed.id);
2749
3524
  patchWorkbench(
2750
3525
  (current) => replaceSession(current, vars.projectId, vars.session.id, resumed)
2751
3526
  );
2752
3527
  setBusy(null);
2753
- say(
2754
- resumed.status === "starting" ? `still resuming \xB7 ${sessionDisplayName(resumed)} \u2014 a attaches once the row reads running` : `resumed \xB7 ${sessionDisplayName(resumed)} \u2014 a attaches`
2755
- );
3528
+ if (line !== null) say(line);
2756
3529
  },
2757
3530
  onSettled: (_data, _error, vars) => {
2758
3531
  gate.release(vars.gateKey);
2759
3532
  settleRefetch();
2760
3533
  }
2761
3534
  });
2762
- const ADOPT_AUTH_MODES = [
2763
- {
2764
- mode: "ambient",
2765
- label: "ambient",
2766
- hint: "the server machine's own git/ssh setup"
2767
- },
2768
- {
2769
- mode: "mend-key",
2770
- label: "mend-key",
2771
- hint: "the machine's Mend deploy key \u2014 add its public half on the git host"
2772
- },
2773
- {
2774
- mode: "bridge",
2775
- label: "bridge",
2776
- hint: "your OWN ssh-agent, relayed while `mend keys share` runs here"
2777
- }
2778
- ];
3535
+ const ADOPT_AUTH_HINTS = {
3536
+ "mend-key": "your Mend key \xB7 add its public half on the git host",
3537
+ bridge: "your own ssh-agent, relayed while `mend keys share` runs"
3538
+ };
3539
+ const ADOPT_AUTH_MODES = ADOPT_MODE_ORDER.map((mode) => ({
3540
+ mode,
3541
+ label: mode,
3542
+ hint: ADOPT_AUTH_HINTS[mode]
3543
+ }));
2779
3544
  const adoptMutation = useMutation2({
2780
3545
  mutationFn: (offer) => submitDashboardAdoption(ctx.api, {
2781
3546
  name: offer.name,
2782
3547
  source: offer.source,
2783
- gitAuthMode: ADOPT_AUTH_MODES[offer.modeIndex]?.mode ?? "ambient"
3548
+ gitAuthMode: ADOPT_AUTH_MODES[offer.modeIndex]?.mode ?? "mend-key"
2784
3549
  }),
2785
3550
  onMutate: (offer) => {
2786
3551
  setAdoptOffer(null);
2787
- setBusy(`adopting ${offer.name} \u2014 cloning into the store \xB7`);
3552
+ setBusy(`adopting ${offer.name} \xB7 cloning into the store \xB7`);
2788
3553
  setBusyStarted(Date.now());
2789
3554
  },
2790
- onError: (error) => {
3555
+ onError: (error, offer) => {
2791
3556
  setBusy(null);
2792
- say(errorText(error));
3557
+ setAdoptOffer(refusedAdoptOffer(offer, errorText(error)));
2793
3558
  },
2794
3559
  onSuccess: (result) => {
2795
3560
  setBusy(null);
@@ -2798,7 +3563,8 @@ ${tunneled}
2798
3563
  return;
2799
3564
  }
2800
3565
  const project = result.project;
2801
- say(`adopted \xB7 ${project.name} \u2014 w starts a worktree`);
3566
+ clearFilters("projects");
3567
+ say(`adopted \xB7 ${project.name} \xB7 w starts a worktree`);
2802
3568
  setProjectKey(project.id);
2803
3569
  setWorktreeKey(null);
2804
3570
  setSessionKey(null);
@@ -2833,7 +3599,7 @@ ${tunneled}
2833
3599
  },
2834
3600
  onSuccess: (result, session) => {
2835
3601
  say(
2836
- `stopped ${result.stopped} service${result.stopped === 1 ? "" : "s"} \xB7 ${sessionDisplayName(session)} \u2014 the workspace ends once nothing is live`
3602
+ `stopped ${result.stopped} service${result.stopped === 1 ? "" : "s"} \xB7 ${sessionDisplayName(session)} \xB7 the workspace ends once nothing is live`
2837
3603
  );
2838
3604
  },
2839
3605
  onError: (error) => {
@@ -2847,7 +3613,7 @@ ${tunneled}
2847
3613
  onMutate: async (session) => {
2848
3614
  await queryClient.cancelQueries({ queryKey: WORKBENCH_KEY });
2849
3615
  patchWorkbench((current) => markSessionStopped(current, session.id));
2850
- say(`stopped \xB7 ${sessionDisplayName(session)} \u2014 the record and review remain`);
3616
+ say(`stopped \xB7 ${sessionDisplayName(session)} \xB7 the record and review remain`);
2851
3617
  },
2852
3618
  onError: (error) => {
2853
3619
  say(errorText(error));
@@ -2857,14 +3623,15 @@ ${tunneled}
2857
3623
  });
2858
3624
  const launchInWorktreeMutation = useMutation2({
2859
3625
  mutationFn: async (vars) => {
2860
- const argv = HARNESS_COMMANDS[vars.harness];
2861
- if (argv === void 0) throw new Error(`unknown harness "${vars.harness}"`);
3626
+ if (HARNESS_COMMANDS[vars.harness] === void 0) {
3627
+ throw new Error(`unknown harness "${vars.harness}"`);
3628
+ }
2862
3629
  const session = await ctx.api("POST", `/worktrees/${vars.worktreeId}/sessions`, {
2863
3630
  harness: vars.harness,
2864
3631
  label: null
2865
3632
  });
2866
3633
  return startedOrStarting(
2867
- ctx.api("POST", `/sessions/${session.id}/launch`, { argv }),
3634
+ ctx.api("POST", `/sessions/${session.id}/launch`, {}),
2868
3635
  session
2869
3636
  );
2870
3637
  },
@@ -2884,22 +3651,31 @@ ${tunneled}
2884
3651
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
2885
3652
  })
2886
3653
  );
3654
+ clearFilters("sessions");
2887
3655
  selectSession(vars.pendingKey);
2888
3656
  setBusy(`starting ${vars.harness} in the worktree \xB7`);
2889
3657
  setBusyStarted(Date.now());
2890
3658
  },
2891
3659
  onError: (error, vars) => {
3660
+ dropStart(vars.pendingKey);
2892
3661
  patchWorkbench((current) => removeSession(current, vars.projectId, vars.pendingKey));
3662
+ setSnakeFocus((current) => current?.start === vars.gateKey ? null : current);
2893
3663
  setBusy(null);
2894
3664
  say(errorText(error));
2895
3665
  },
2896
3666
  onSuccess: (session, vars) => {
3667
+ const line = stillStartingLine(
3668
+ session,
3669
+ "starting",
3670
+ autoAttach && awaitedRef.current === vars.pendingKey
3671
+ );
3672
+ answerStart(vars.pendingKey, session.id);
2897
3673
  patchWorkbench(
2898
3674
  (current) => replaceSession(current, vars.projectId, vars.pendingKey, session)
2899
3675
  );
2900
3676
  setSessionKey((current) => current === vars.pendingKey ? session.id : current);
2901
3677
  setBusy(null);
2902
- say(startedLine(session));
3678
+ if (line !== null) say(line);
2903
3679
  },
2904
3680
  onSettled: (_data, _error, vars) => {
2905
3681
  gate.release(vars.gateKey);
@@ -2944,7 +3720,7 @@ ${tunneled}
2944
3720
  refetch();
2945
3721
  },
2946
3722
  onSuccess: (_result, session) => {
2947
- say(`removed \xB7 ${sessionDisplayName(session)} \u2014 the worktree remains`);
3723
+ say(`removed \xB7 ${sessionDisplayName(session)} \xB7 the worktree remains`);
2948
3724
  refetch();
2949
3725
  },
2950
3726
  onSettled: settleRefetch
@@ -2956,7 +3732,7 @@ ${tunneled}
2956
3732
  if (group === null || group.sessions.some((item) => isPendingId(item.session.id))) return;
2957
3733
  if (group.live > 0) {
2958
3734
  say(
2959
- `${group.live} session${group.live === 1 ? "" : "s"} live \u2014 stop them first (\u21E7K) \xB7 ${group.name}`
3735
+ `${group.live} session${group.live === 1 ? "" : "s"} live \xB7 stop them first (\u21E7K) \xB7 ${group.name}`
2960
3736
  );
2961
3737
  return;
2962
3738
  }
@@ -2967,13 +3743,13 @@ ${tunneled}
2967
3743
  }
2968
3744
  setRemoveArmed(`wt:${group.key}`);
2969
3745
  const facts = group.sessions.length === 1 ? "its session and change go with it" : `${group.sessions.length} sessions and the change go with it`;
2970
- say(`press \u21E7D again to remove worktree \xB7 ${group.name} \u2014 ${facts}`);
3746
+ say(`press \u21E7D again to remove worktree \xB7 ${group.name} \xB7 ${facts}`);
2971
3747
  return;
2972
3748
  }
2973
3749
  const session = selectedSession;
2974
3750
  if (session === null || isPendingId(session.id)) return;
2975
3751
  if (AGENT_LIVE_STATUSES.has(session.status)) {
2976
- say(`the agent is still working \u2014 stop it first (\u21E7K) \xB7 ${sessionDisplayName(session)}`);
3752
+ say(`the agent is still working \xB7 stop it first (\u21E7K) \xB7 ${sessionDisplayName(session)}`);
2977
3753
  return;
2978
3754
  }
2979
3755
  if (removeArmed === session.id && confirmationVisible("press \u21E7D again")) {
@@ -2983,7 +3759,7 @@ ${tunneled}
2983
3759
  }
2984
3760
  setRemoveArmed(session.id);
2985
3761
  say(
2986
- `press \u21E7D again to remove session \xB7 ${sessionDisplayName(session)} \u2014 its record goes, the worktree stays`
3762
+ `press \u21E7D again to remove session \xB7 ${sessionDisplayName(session)} \xB7 its record goes, the worktree stays`
2987
3763
  );
2988
3764
  };
2989
3765
  const armStop = () => {
@@ -2992,7 +3768,7 @@ ${tunneled}
2992
3768
  if (group === null) return;
2993
3769
  const live = group.sessions.filter((item) => LIVE_STATUSES.has(item.session.status));
2994
3770
  if (live.length === 0) {
2995
- say("nothing to stop \u2014 the worktree is settled");
3771
+ say("nothing to stop \xB7 the worktree is settled");
2996
3772
  return;
2997
3773
  }
2998
3774
  if (stopArmed === `wt:${group.key}` && confirmationVisible("press \u21E7K again")) {
@@ -3008,7 +3784,7 @@ ${tunneled}
3008
3784
  }
3009
3785
  const session = selectedSession;
3010
3786
  if (session === null || isPendingId(session.id)) return;
3011
- const hold = selectedItem === null ? null : sessionHold(selectedItem);
3787
+ const hold = selectedItem === null ? null : servicesHoldOf(selectedItem);
3012
3788
  if (hold !== null) {
3013
3789
  if (stopArmed === `svc:${session.id}` && confirmationVisible("press \u21E7K again")) {
3014
3790
  setStopArmed(null);
@@ -3016,11 +3792,16 @@ ${tunneled}
3016
3792
  return;
3017
3793
  }
3018
3794
  setStopArmed(`svc:${session.id}`);
3019
- say(`press \u21E7K again to stop the services \xB7 ${sessionDisplayName(session)} \u2014 ${hold}`);
3795
+ say(`press \u21E7K again to stop the services \xB7 ${sessionDisplayName(session)} \xB7 ${hold}`);
3796
+ return;
3797
+ }
3798
+ if (session.status === "stopping") {
3799
+ const saving = selectedItem === null ? null : sessionHold(selectedItem);
3800
+ say(`already stopping${saving === null ? "" : ` \xB7 ${saving}`}`);
3020
3801
  return;
3021
3802
  }
3022
3803
  if (!LIVE_STATUSES.has(session.status)) {
3023
- say("nothing to stop \u2014 the session is settled");
3804
+ say("nothing to stop \xB7 the session is settled");
3024
3805
  return;
3025
3806
  }
3026
3807
  if (stopArmed === session.id && confirmationVisible("press \u21E7K again")) {
@@ -3072,7 +3853,7 @@ ${tunneled}
3072
3853
  if (creatingRef.current?.projectId !== projectId || request !== branchRequest.current)
3073
3854
  return;
3074
3855
  const message = errorText(error);
3075
- say(`could not read branches \u2014 ${message}`);
3856
+ say(`could not read branches \xB7 ${message}`);
3076
3857
  setCreating(
3077
3858
  (current) => current?.projectId === projectId ? { ...current, branches: [], branchError: message } : current
3078
3859
  );
@@ -3107,17 +3888,20 @@ ${tunneled}
3107
3888
  const gateKey = `launch:${current.projectId}:${current.name}`;
3108
3889
  if (!gate.take(gateKey)) {
3109
3890
  setCreating(null);
3110
- say("that worktree is already starting \u2014 wait for it to finish before starting another");
3891
+ say("that worktree is already starting \xB7 wait for it to finish before starting another");
3111
3892
  return;
3112
3893
  }
3113
3894
  setCreating(null);
3895
+ setSnakeFocus({ returnTo: focus, start: gateKey });
3114
3896
  setFocus("sessions");
3897
+ const pendingKey = pendingId();
3898
+ watchStart(pendingKey, "started");
3115
3899
  launchMutation.mutate({
3116
3900
  projectId: current.projectId,
3117
3901
  harness: choice.harness,
3118
3902
  name: current.name === "" ? null : current.name,
3119
3903
  base: current.base,
3120
- pendingKey: pendingId(),
3904
+ pendingKey,
3121
3905
  gateKey
3122
3906
  });
3123
3907
  };
@@ -3138,11 +3922,11 @@ ${tunneled}
3138
3922
  return;
3139
3923
  case "starting":
3140
3924
  say(
3141
- `still starting \xB7 ${sessionDisplayName(plan.session)} \u2014 a attaches once the row reads running`
3925
+ `still starting \xB7 ${sessionDisplayName(plan.session)} \xB7 a attaches once the row reads running`
3142
3926
  );
3143
3927
  return;
3144
3928
  case "settled":
3145
- say(`settled \xB7 ${sessionDisplayName(plan.session)} \u2014 r resumes it, \u21E7D removes it`);
3929
+ say(`settled \xB7 ${sessionDisplayName(plan.session)} \xB7 r resumes it, \u21E7D removes it`);
3146
3930
  return;
3147
3931
  case "stopping":
3148
3932
  say(
@@ -3150,10 +3934,10 @@ ${tunneled}
3150
3934
  );
3151
3935
  return;
3152
3936
  case "pending":
3153
- say("still provisioning \u2014 the row fills in when the workspace answers");
3937
+ say("still provisioning \xB7 the row fills in when the workspace answers");
3154
3938
  return;
3155
3939
  case "none":
3156
- say("no session selected \u2014 n starts one");
3940
+ say("no session selected \xB7 n starts one");
3157
3941
  return;
3158
3942
  }
3159
3943
  };
@@ -3168,13 +3952,13 @@ ${tunneled}
3168
3952
  openPicker(plan.session);
3169
3953
  return;
3170
3954
  case "live":
3171
- say(`already live \xB7 ${sessionDisplayName(plan.session)} \u2014 a attaches`);
3955
+ say(`already live \xB7 ${sessionDisplayName(plan.session)} \xB7 a attaches`);
3172
3956
  return;
3173
3957
  case "pending":
3174
- say("still provisioning \u2014 nothing to resume yet");
3958
+ say("still provisioning \xB7 nothing to resume yet");
3175
3959
  return;
3176
3960
  case "none":
3177
- say("no session selected \u2014 n starts one");
3961
+ say("no session selected \xB7 n starts one");
3178
3962
  return;
3179
3963
  }
3180
3964
  };
@@ -3184,8 +3968,11 @@ ${tunneled}
3184
3968
  say(`already resuming \xB7 ${sessionDisplayName(session)}`);
3185
3969
  return;
3186
3970
  }
3971
+ setSnakeFocus({ returnTo: focus, start: gateKey });
3187
3972
  setFocus("sessions");
3188
- resumeMutation.mutate({ projectId, session, harness, gateKey });
3973
+ const watch = pendingId();
3974
+ watchStart(watch, "resumed");
3975
+ resumeMutation.mutate({ projectId, session, harness, gateKey, watch });
3189
3976
  };
3190
3977
  const newSession = () => {
3191
3978
  const projectId = selectedProject?.project.id;
@@ -3215,12 +4002,15 @@ ${tunneled}
3215
4002
  say(`already starting a session in ${group.name}`);
3216
4003
  return;
3217
4004
  }
4005
+ setSnakeFocus({ returnTo: focus, start: gateKey });
3218
4006
  setFocus("sessions");
4007
+ const pendingKey = pendingId();
4008
+ watchStart(pendingKey, "started");
3219
4009
  launchInWorktreeMutation.mutate({
3220
4010
  projectId,
3221
4011
  worktreeId: group.id,
3222
4012
  harness,
3223
- pendingKey: pendingId(),
4013
+ pendingKey,
3224
4014
  gateKey
3225
4015
  });
3226
4016
  };
@@ -3233,6 +4023,7 @@ ${tunneled}
3233
4023
  case "projects": {
3234
4024
  const item = projectItems[clampIndex(projectItems.length, projectIndex + delta)];
3235
4025
  if (item === void 0) return;
4026
+ if (item !== selectedProject) stopAwaiting();
3236
4027
  setProjectKey(item.project.id);
3237
4028
  setWorktreeKey(null);
3238
4029
  setSessionKey(null);
@@ -3242,6 +4033,7 @@ ${tunneled}
3242
4033
  case "worktrees": {
3243
4034
  const group = worktreeGroups[clampIndex(worktreeGroups.length, worktreeIndex + delta)];
3244
4035
  if (group === void 0) return;
4036
+ if (group !== selectedGroup) stopAwaiting();
3245
4037
  setWorktreeKey(group.key);
3246
4038
  setSessionKey(null);
3247
4039
  setPreviewOffset(0);
@@ -3250,6 +4042,7 @@ ${tunneled}
3250
4042
  case "sessions": {
3251
4043
  const item = sessionItems[clampIndex(sessionItems.length, sessionIndex + delta)];
3252
4044
  if (item === void 0) return;
4045
+ if (item !== selectedItem) stopAwaiting();
3253
4046
  selectSession(item.session.id);
3254
4047
  return;
3255
4048
  }
@@ -3263,34 +4056,35 @@ ${tunneled}
3263
4056
  return;
3264
4057
  }
3265
4058
  };
3266
- const moveColumn = (delta) => setFocus(stepColumn(focus, delta));
4059
+ const goTo = (next) => {
4060
+ if (next === "projects" || next === "worktrees") stopAwaiting();
4061
+ if (next === "detail" && waiting && snakeFits) {
4062
+ setSnakeFocus({ returnTo: focus, start: null });
4063
+ return;
4064
+ }
4065
+ setFocus(next);
4066
+ };
4067
+ const moveColumn = (delta) => goTo(stepColumn(focus, delta));
3267
4068
  useKeyboard2((key) => {
3268
4069
  if (reviewing !== null) return;
3269
4070
  if (lockRef.current) return;
3270
4071
  if (key.ctrl && key.name === "c") return onQuit();
3271
- if (snakeOverlay) {
3272
- if (key.name === "up" || key.name === "down" || key.name === "left" || key.name === "right") {
3273
- overlaySnake.steer(key.name);
3274
- } else if (key.name === "space") {
3275
- overlaySnake.togglePause();
3276
- } else if (key.name === "escape" || key.name === "q") {
3277
- setSnakeOverlay(false);
3278
- }
3279
- return;
3280
- }
3281
- if (waiting && focus === "detail" && picker === null && editing === null && creating === null) {
3282
- if (snakeShown) {
3283
- if (key.name === "up" || key.name === "down" || key.name === "left" || key.name === "right") {
3284
- snake.steer(key.name);
3285
- return;
4072
+ const verb = verbForKey(strokeName(key), key.shift === true);
4073
+ const game = overlayFocused ? overlaySnake : snakeFocused ? snake : null;
4074
+ if (game !== null || overlayOpen) {
4075
+ const action = snakeKey(key.name ?? "");
4076
+ if (action?.type === "leave") {
4077
+ if (overlayOpen) {
4078
+ setSnakeOverlay(false);
4079
+ } else if (snakeFocus !== null) {
4080
+ setFocus(snakeFocus.returnTo);
4081
+ setSnakeFocus(null);
3286
4082
  }
3287
- if (key.name === "space") return snake.togglePause();
3288
- if (key.name === "escape") return setSnakeAwayFor(selectedSession?.id ?? null);
3289
- } else if (key.name === "space") {
3290
- return setSnakeAwayFor(null);
4083
+ return;
3291
4084
  }
4085
+ if (action !== null) return game?.send(action);
4086
+ if (gameSwallows(verb) || game === null) return;
3292
4087
  }
3293
- const verb = verbForKey(key.name ?? "", key.shift === true);
3294
4088
  if (verb !== "stop") setStopArmed(null);
3295
4089
  if (verb !== "remove") setRemoveArmed(null);
3296
4090
  if (adoptOffer !== null) {
@@ -3365,6 +4159,26 @@ ${tunneled}
3365
4159
  }
3366
4160
  return;
3367
4161
  }
4162
+ if (helpOpen) {
4163
+ if (key.name === "escape" || key.name === "q" || verb === "help") {
4164
+ setHelpOpen(false);
4165
+ } else if (verb === "moveDown" || verb === "pageDown") {
4166
+ setHelpOffset(
4167
+ (current) => Math.max(0, Math.min(helpMaxOffset, current + (verb === "pageDown" ? 10 : 1)))
4168
+ );
4169
+ } else if (verb === "moveUp" || verb === "pageUp") {
4170
+ setHelpOffset((current) => Math.max(0, current - (verb === "pageUp" ? 10 : 1)));
4171
+ }
4172
+ return;
4173
+ }
4174
+ if (filtering !== null) {
4175
+ if (key.name === "escape") {
4176
+ clearFilters(filtering);
4177
+ setFiltering(null);
4178
+ } else if (key.name === "down") moveSelection(1);
4179
+ else if (key.name === "up") moveSelection(-1);
4180
+ return;
4181
+ }
3368
4182
  if (picker !== null) {
3369
4183
  switch (key.name) {
3370
4184
  case "down":
@@ -3397,9 +4211,13 @@ ${tunneled}
3397
4211
  return;
3398
4212
  }
3399
4213
  }
4214
+ if (snakeFocus !== null && verb !== null) setSnakeFocus(null);
4215
+ if (key.name === "space" && waiting && snakeFits && focus === "detail") {
4216
+ return setSnakeFocus({ returnTo: focus, start: null });
4217
+ }
3400
4218
  if (key.ctrl === true) return;
3401
4219
  if (focus === "projects" && ["attach", "resume", "stop", "remove", "rename", "openWeb", "review"].includes(verb ?? "")) {
3402
- say("select a session first \u2014 \u2192 opens worktrees");
4220
+ say("select a session first \xB7 \u2192 opens worktrees");
3403
4221
  return;
3404
4222
  }
3405
4223
  switch (verb) {
@@ -3417,6 +4235,37 @@ ${tunneled}
3417
4235
  return moveColumn(1);
3418
4236
  case "columnLeft":
3419
4237
  return moveColumn(-1);
4238
+ case "nextPane":
4239
+ return goTo(cyclePane(focus, 1));
4240
+ case "prevPane":
4241
+ return goTo(cyclePane(focus, -1));
4242
+ case "jumpProjects":
4243
+ case "jumpWorktrees":
4244
+ case "jumpSessions":
4245
+ case "jumpDetail":
4246
+ return goTo(paneForDigit(strokeName(key)) ?? focus);
4247
+ case "back":
4248
+ if (isNavSection(focus) && filters[focus] !== "") {
4249
+ clearFilters(focus);
4250
+ return;
4251
+ }
4252
+ return goTo(backFrom(focus, lastNav));
4253
+ case "filter":
4254
+ if (!isNavSection(focus)) {
4255
+ say("/ filters a list \xB7 1 2 3 jump to one");
4256
+ return;
4257
+ }
4258
+ return setFiltering(focus);
4259
+ case "nextScreenMode":
4260
+ case "prevScreenMode": {
4261
+ const next = stepScreenMode(screenMode, verb === "nextScreenMode" ? 1 : -1);
4262
+ setScreenMode(next);
4263
+ say(`screen mode \xB7 ${next}${next === "normal" ? "" : " \xB7 + and _ cycle it"}`);
4264
+ return;
4265
+ }
4266
+ case "help":
4267
+ setHelpOffset(0);
4268
+ return setHelpOpen(true);
3420
4269
  case "attach":
3421
4270
  return attachSelected();
3422
4271
  case "resume":
@@ -3452,7 +4301,7 @@ ${tunneled}
3452
4301
  const session = selectedSession;
3453
4302
  if (session === null) return;
3454
4303
  if (isPendingId(session.id)) {
3455
- say("still provisioning \u2014 nothing to review yet");
4304
+ say("still provisioning \xB7 nothing to review yet");
3456
4305
  return;
3457
4306
  }
3458
4307
  const target = reviewTargetForSession(
@@ -3472,22 +4321,54 @@ ${tunneled}
3472
4321
  }
3473
4322
  });
3474
4323
  const liveTotal = projectItems.reduce((sum, item) => sum + item.live, 0);
3475
- const columnTitle = (column) => {
4324
+ const stoppingTotal = projectItems.reduce((sum, item) => sum + item.stopping, 0);
4325
+ const named = (section) => filters[section] === "" ? section : `${section} /${filters[section]}`;
4326
+ const columnTitle = (column) => numberedTitle(column, columnWords(column));
4327
+ const columnWords = (column) => {
3476
4328
  if (column === "worktrees") {
3477
- return selectedProject === null ? "worktrees" : `worktrees \xB7 ${worktreeGroups.length}${selectedProject.live > 0 ? ` \xB7 ${selectedProject.live} live` : ""}`;
4329
+ return selectedProject === null ? named("worktrees") : `${named("worktrees")} \xB7 ${worktreeGroups.length}${selectedProject.live > 0 ? ` \xB7 ${selectedProject.live} live` : ""}`;
3478
4330
  }
3479
4331
  if (column === "sessions") {
3480
- return selectedGroup === null ? "sessions" : `sessions \xB7 ${sessionItems.length}`;
4332
+ return selectedGroup === null ? named("sessions") : `${named("sessions")} \xB7 ${sessionItems.length}`;
3481
4333
  }
3482
4334
  if (column === "detail") {
3483
4335
  if (selectedSession === null) return "session";
3484
4336
  return previewView.offset === 0 ? "session \xB7 read-only" : `session \xB7 read-only \xB7 ${previewView.later} newer below`;
3485
4337
  }
3486
- return COLUMN_TITLE[column];
4338
+ return named("projects");
3487
4339
  };
3488
- const pickerTitle = picker === null ? "" : picker.worktree === void 0 ? picker.session === null ? "new session \u2014 pick a harness" : `resume ${sessionDisplayName(picker.session)} \u2014 pick a harness` : `new session in ${picker.worktree.name} \u2014 pick a harness`;
4340
+ const pickerTitle = picker === null ? "" : picker.worktree === void 0 ? picker.session === null ? "new session \xB7 pick a harness" : `resume ${sessionDisplayName(picker.session)} \xB7 pick a harness` : `new session in ${picker.worktree.name} \xB7 pick a harness`;
4341
+ const modalWidth = Math.min(74, terminalCols - 4);
4342
+ const pickerJoinRows = picker?.worktree?.id == null || selectedProject === null ? [] : worktreeJoinRows(
4343
+ data,
4344
+ selectedProject.project.id,
4345
+ { id: picker.worktree.id },
4346
+ viewer.data?.userId ?? null,
4347
+ modalWidth - 4
4348
+ );
4349
+ const pickerJoinHeight = pickerJoinRows.length === 0 ? 0 : pickerJoinRows.length + 1;
4350
+ const creatingJoinRows = creating === null || !creating.joins ? [] : worktreeJoinRows(
4351
+ data,
4352
+ creating.projectId,
4353
+ { name: creating.name },
4354
+ viewer.data?.userId ?? null,
4355
+ modalWidth - 7
4356
+ );
3489
4357
  const creatingHeight = 2 + 1 + 1 + 6 + 1 + deriveHarnesses(null).length;
3490
- const footerText = adoptOffer === null ? editing === null ? creating === null ? picker === null ? ` ${fitHints(verbHints(focus), Math.max(12, terminalCols - 2))}` : " \u2191\u2193 move \xB7 enter start \xB7 esc cancel" : creating.step === "name" ? " enter continue \xB7 esc cancel" : creating.step === "base" ? " type to filter \xB7 \u2191\u2193 move \xB7 enter choose base \xB7 esc back" : " \u2191\u2193 move \xB7 enter launch \xB7 esc back" : " enter save \xB7 esc cancel" : " enter adopt \xB7 \u2190\u2192 auth mode \xB7 esc not now";
4358
+ const modalFieldWidth = Math.max(4, modalWidth - 2 - 11 - 1);
4359
+ const footerText = adoptOffer === null ? editing === null ? creating === null ? picker === null ? overlayFocused || snakeFocused ? ` ${snakeHints(overlayFocused ? overlaySnake.play : snake.play)}` : ` ${footerHints(focus, Math.max(12, terminalCols - 2))}` : " \u2191\u2193 move \xB7 enter start \xB7 esc cancel" : creating.step === "name" ? " enter continue \xB7 esc cancel" : creating.step === "base" ? " type to filter \xB7 \u2191\u2193 move \xB7 enter choose base \xB7 esc back" : " \u2191\u2193 move \xB7 enter launch \xB7 esc back" : " enter save \xB7 esc cancel" : " enter adopt \xB7 \u2190\u2192 auth mode \xB7 esc not now";
4360
+ const helpWidth = Math.min(96, terminalCols - 4);
4361
+ const helpLines = helpSections(focus).flatMap((section, index) => [
4362
+ ...index === 0 ? [] : [{ kind: "blank", key: `blank-${section.title}` }],
4363
+ { kind: "title", key: `title-${section.title}`, text: section.title },
4364
+ ...section.rows.map((row) => ({ kind: "row", key: row.verb, row }))
4365
+ ]);
4366
+ const helpRows = Math.max(1, Math.min(helpLines.length, terminalRows - 6));
4367
+ const helpMaxOffset = Math.max(0, helpLines.length - helpRows);
4368
+ const helpView = helpLines.slice(
4369
+ Math.min(helpOffset, helpMaxOffset),
4370
+ Math.min(helpOffset, helpMaxOffset) + helpRows
4371
+ );
3491
4372
  const loadFailure = data === void 0 && failureReason !== null ? errorText(failureReason) : null;
3492
4373
  if (reviewing !== null) {
3493
4374
  return /* @__PURE__ */ jsx3(
@@ -3513,11 +4394,11 @@ ${tunneled}
3513
4394
  const sectionFact = (section) => {
3514
4395
  if (section === "projects") {
3515
4396
  if (selectedProject === null) return "";
3516
- return selectedProject.live > 0 ? `${selectedProject.live} live` : "settled";
4397
+ return liveCountWords(selectedProject.live, selectedProject.stopping);
3517
4398
  }
3518
4399
  if (section === "worktrees") {
3519
4400
  if (selectedGroup === null) return "";
3520
- return selectedGroup.live > 0 ? foldGroupStatus(selectedGroup) : "settled";
4401
+ return foldGroupStatus(selectedGroup);
3521
4402
  }
3522
4403
  return selectedSession?.status ?? "";
3523
4404
  };
@@ -3572,7 +4453,12 @@ ${tunneled}
3572
4453
  },
3573
4454
  item.project.id
3574
4455
  )),
3575
- data !== void 0 && projectItems.length === 0 ? /* @__PURE__ */ jsx3(EmptyNote, { text: "none adopted yet" }) : null
4456
+ data !== void 0 && projectItems.length === 0 ? /* @__PURE__ */ jsx3(
4457
+ EmptyNote,
4458
+ {
4459
+ text: filters.projects === "" ? "none adopted yet" : `nothing matches /${filters.projects} \xB7 esc clears`
4460
+ }
4461
+ ) : null
3576
4462
  ]
3577
4463
  }
3578
4464
  )
@@ -3604,7 +4490,12 @@ ${tunneled}
3604
4490
  },
3605
4491
  group.key
3606
4492
  )),
3607
- data !== void 0 && worktreeGroups.length === 0 ? /* @__PURE__ */ jsx3(EmptyNote, { text: "no worktrees \u2014 w starts one" }) : null
4493
+ data !== void 0 && worktreeGroups.length === 0 ? /* @__PURE__ */ jsx3(
4494
+ EmptyNote,
4495
+ {
4496
+ text: filters.worktrees === "" ? "no worktrees \xB7 w starts one" : `nothing matches /${filters.worktrees} \xB7 esc clears`
4497
+ }
4498
+ ) : null
3608
4499
  ]
3609
4500
  }
3610
4501
  )
@@ -3639,10 +4530,10 @@ ${tunneled}
3639
4530
  data !== void 0 && sessionItems.length === 0 ? /* @__PURE__ */ jsx3(
3640
4531
  EmptyNote,
3641
4532
  {
3642
- text: selectedGroup === null ? "no worktree selected" : "no sessions \u2014 n starts one"
4533
+ text: selectedGroup === null ? "no worktree selected" : filters.sessions === "" ? "no sessions \xB7 n starts one" : `nothing matches /${filters.sessions} \xB7 esc clears`
3643
4534
  }
3644
4535
  ) : null,
3645
- loadFailure === null ? null : /* @__PURE__ */ jsx3("text", { height: 1, fg: INK_2, bg: "transparent", children: ` ${loadFailure} \u2014 retrying` })
4536
+ loadFailure === null ? null : /* @__PURE__ */ jsx3("text", { height: 1, fg: INK_2, bg: "transparent", children: ` ${loadFailure} \xB7 retrying` })
3646
4537
  ]
3647
4538
  }
3648
4539
  )
@@ -3651,14 +4542,15 @@ ${tunneled}
3651
4542
  );
3652
4543
  }
3653
4544
  };
3654
- const renderDetail = () => /* @__PURE__ */ jsx3(Pane, { title: paneTitle("detail", detailWidth + 2), focused: focus === "detail", grow: true, children: selectedItem === null ? /* @__PURE__ */ jsx3(EmptyNote, { text: "no session selected \u2014 n starts one" }) : /* @__PURE__ */ jsxs3(Fragment3, { children: [
4545
+ const renderDetail = () => /* @__PURE__ */ jsx3(Pane, { title: paneTitle("detail", detailWidth + 2), focused: focus === "detail", grow: true, children: selectedItem === null ? /* @__PURE__ */ jsx3(EmptyNote, { text: "no session selected \xB7 n starts one" }) : /* @__PURE__ */ jsxs3(Fragment3, { children: [
3655
4546
  /* @__PURE__ */ jsx3(
3656
4547
  SessionFacts,
3657
4548
  {
3658
4549
  group: selectedGroup,
3659
4550
  item: selectedItem,
3660
4551
  rows: factRows,
3661
- tunnels: openTunnels
4552
+ tunnels: openTunnels,
4553
+ workspaceRows
3662
4554
  }
3663
4555
  ),
3664
4556
  showFactRule ? /* @__PURE__ */ jsx3("text", { height: 1, bg: "transparent", fg: FAINT, children: ` ${"\u2500".repeat(Math.max(4, detailWidth - 4))}` }) : null,
@@ -3666,10 +4558,16 @@ ${tunneled}
3666
4558
  /* @__PURE__ */ jsxs3("text", { height: 1, bg: "transparent", children: [
3667
4559
  /* @__PURE__ */ jsx3("span", { children: " " }),
3668
4560
  /* @__PURE__ */ jsx3("span", { fg: INK_2, children: "starting" }),
3669
- /* @__PURE__ */ jsx3("span", { fg: FAINT, children: " \xB7 the image builds, then the session boots \xB7 a first build on a new setup takes about 7 minutes" })
4561
+ /* @__PURE__ */ jsx3("span", { fg: FAINT, children: ` \xB7 ${selectedSession === null ? "launching" : startingExplanationOf(selectedSession)}` })
3670
4562
  ] }),
3671
- snakeShown ? /* @__PURE__ */ jsx3(SnakeBoard, { handle: snake, focused: focus === "detail" }) : /* @__PURE__ */ jsx3(EmptyNote, { text: "snake is put away \xB7 space brings it back" })
3672
- ] }) : previewSessionId === null ? /* @__PURE__ */ jsx3(EmptyNote, { text: "provisioning \u2014 no record yet" }) : selectedSession?.harness === "shell" ? /* @__PURE__ */ jsx3(EmptyNote, { text: "shell \u2014 no conversation record; a attaches if live" }) : transcript.isPending ? /* @__PURE__ */ jsx3(EmptyNote, { text: "reading the record\u2026" }) : transcript.error === null ? previewView.lines.length === 0 ? /* @__PURE__ */ jsx3(EmptyNote, { text: "no conversation recorded yet" }) : previewView.lines.map((line, index) => /* @__PURE__ */ jsx3(PreviewRow, { line }, `${index}-${line.kind}`)) : /* @__PURE__ */ jsx3("text", { height: 1, fg: INK_2, bg: "transparent", children: ` could not read the record \u2014 ${errorText(transcript.error)}` }) })
4563
+ snakeShown ? /* @__PURE__ */ jsx3(
4564
+ SnakeBoard,
4565
+ {
4566
+ handle: snake,
4567
+ idle: snakeFocus !== null && dialogOpen ? SNAKE_BEHIND_DIALOG : SNAKE_IDLE
4568
+ }
4569
+ ) : /* @__PURE__ */ jsx3(EmptyNote, { text: snakeTooSmall(snakeRoom.rows < SNAKE_MIN_BOARD_ROWS) })
4570
+ ] }) : previewSessionId === null ? /* @__PURE__ */ jsx3(EmptyNote, { text: "provisioning \xB7 no record yet" }) : selectedSession?.harness === "shell" ? /* @__PURE__ */ jsx3(EmptyNote, { text: "shell \xB7 no conversation record; a attaches if live" }) : transcript.isPending ? /* @__PURE__ */ jsx3(EmptyNote, { text: "reading the record\u2026" }) : transcript.error === null ? previewView.lines.length === 0 ? /* @__PURE__ */ jsx3(EmptyNote, { text: "no conversation recorded yet" }) : previewView.lines.map((line, index) => /* @__PURE__ */ jsx3(PreviewRow, { line }, `${index}-${line.kind}`)) : /* @__PURE__ */ jsx3("text", { height: 1, fg: INK_2, bg: "transparent", children: ` could not read the record \xB7 ${errorText(transcript.error)}` }) })
3673
4571
  ] }) });
3674
4572
  const offNav = layout.offscreen.filter(isNavSection);
3675
4573
  const detailOffscreen = layout.offscreen.includes("detail");
@@ -3688,6 +4586,13 @@ ${tunneled}
3688
4586
  liveTotal,
3689
4587
  " live"
3690
4588
  ] }),
4589
+ stoppingTotal > 0 ? /* @__PURE__ */ jsxs3(Fragment3, { children: [
4590
+ /* @__PURE__ */ jsx3("span", { fg: FAINT, children: " \xB7 " }),
4591
+ /* @__PURE__ */ jsxs3("span", { fg: INK_2, children: [
4592
+ stoppingTotal,
4593
+ " stopping"
4594
+ ] })
4595
+ ] }) : null,
3691
4596
  gate.count() > 0 ? /* @__PURE__ */ jsxs3(Fragment3, { children: [
3692
4597
  /* @__PURE__ */ jsx3("span", { fg: FAINT, children: " \xB7 " }),
3693
4598
  /* @__PURE__ */ jsxs3("span", { fg: INK_2, children: [
@@ -3700,7 +4605,7 @@ ${tunneled}
3700
4605
  /* @__PURE__ */ jsx3("span", { fg: shareState === "connected" ? MUTED : FAINT, children: shareState === "connected" ? "agent shared" : "agent share reconnecting" })
3701
4606
  ] })
3702
4607
  ] }),
3703
- /* @__PURE__ */ jsx3("text", { height: 1, fg: FAINT, bg: "transparent", children: `${ctx.config.url} ` })
4608
+ /* @__PURE__ */ jsx3("text", { height: 1, fg: FAINT, bg: "transparent", children: `${screenMode === "normal" ? "" : `${screenMode} screen \xB7 `}${ctx.config.url} ` })
3704
4609
  ] }),
3705
4610
  !layout.breadcrumb ? null : /* @__PURE__ */ jsxs3("text", { height: 1, bg: "transparent", children: [
3706
4611
  /* @__PURE__ */ jsx3("span", { fg: FAINT, children: " " }),
@@ -3724,37 +4629,63 @@ ${tunneled}
3724
4629
  ),
3725
4630
  detailWidth === 0 ? null : renderDetail()
3726
4631
  ] }),
3727
- snakeOverlay ? /* @__PURE__ */ jsxs3(
4632
+ snakeOverlay && !overlayFits ? /* @__PURE__ */ jsx3(
3728
4633
  "box",
3729
4634
  {
3730
4635
  position: "absolute",
3731
- zIndex: 13,
3732
- left: Math.max(1, Math.floor((terminalCols - (overlayWidth + 4)) / 2)),
3733
- top: Math.max(1, Math.floor((terminalRows - (overlayHeight + 5)) / 2)),
3734
- width: overlayWidth + 4,
3735
- height: overlayHeight + 5,
4636
+ zIndex: 9,
4637
+ left: 1,
4638
+ top: Math.max(1, Math.floor((terminalRows - 3) / 2)),
4639
+ width: Math.max(4, terminalCols - 2),
4640
+ height: 3,
3736
4641
  border: true,
3737
4642
  borderStyle: "rounded",
3738
- borderColor: ACCENT,
3739
- title: " snake ",
3740
- titleAlignment: "left",
4643
+ borderColor: RULE,
3741
4644
  backgroundColor: SURFACE,
3742
- flexDirection: "column",
3743
- children: [
3744
- /* @__PURE__ */ jsx3(SnakeHeading, { handle: overlaySnake, hint: "arrows steer \xB7 space pauses \xB7 esc closes" }),
3745
- /* @__PURE__ */ jsx3("box", { marginLeft: 1, flexDirection: "column", children: /* @__PURE__ */ jsx3(SnakeRows, { game: overlaySnake.game }) })
3746
- ]
4645
+ children: /* @__PURE__ */ jsx3("text", { height: 1, bg: "transparent", fg: FAINT, children: fit(
4646
+ ` ${snakeTooSmall(terminalRows < 12)} \xB7 esc closes`,
4647
+ Math.max(1, terminalCols - 4)
4648
+ ) })
3747
4649
  }
3748
4650
  ) : null,
3749
- picker === null ? null : /* @__PURE__ */ jsx3(
4651
+ snakeOverlay && overlayFits ? (
4652
+ // Under every dialog: one that opens over the game has the keyboard until it closes.
4653
+ /* @__PURE__ */ jsxs3(
4654
+ "box",
4655
+ {
4656
+ position: "absolute",
4657
+ zIndex: 9,
4658
+ left: Math.max(1, Math.floor((terminalCols - (overlayWidth + 4)) / 2)),
4659
+ top: Math.max(1, Math.floor((terminalRows - (overlayHeight + 4)) / 2)),
4660
+ width: overlayWidth + 4,
4661
+ height: overlayHeight + 4,
4662
+ border: true,
4663
+ borderStyle: "rounded",
4664
+ borderColor: overlayFocused ? ACCENT : RULE,
4665
+ title: " snake ",
4666
+ titleAlignment: "left",
4667
+ backgroundColor: SURFACE,
4668
+ flexDirection: "column",
4669
+ children: [
4670
+ /* @__PURE__ */ jsx3(SnakeHeading, { play: overlaySnake.play }),
4671
+ /* @__PURE__ */ jsx3("box", { marginLeft: 1, flexDirection: "column", flexShrink: 0, children: /* @__PURE__ */ jsx3(SnakeRows, { play: overlaySnake.play }) }),
4672
+ /* @__PURE__ */ jsx3(SnakeFooter, { play: overlaySnake.play, idle: SNAKE_BEHIND_DIALOG })
4673
+ ]
4674
+ }
4675
+ )
4676
+ ) : null,
4677
+ picker === null ? null : /* @__PURE__ */ jsxs3(
3750
4678
  "box",
3751
4679
  {
3752
4680
  position: "absolute",
3753
4681
  zIndex: 12,
3754
4682
  left: Math.max(1, Math.floor((terminalCols - Math.min(74, terminalCols - 4)) / 2)),
3755
- top: Math.max(1, Math.floor((terminalRows - (2 + pickerItems.length)) / 2)),
4683
+ top: Math.max(
4684
+ 1,
4685
+ Math.floor((terminalRows - (2 + pickerItems.length + pickerJoinHeight)) / 2)
4686
+ ),
3756
4687
  width: Math.min(74, terminalCols - 4),
3757
- height: 2 + pickerItems.length,
4688
+ height: 2 + pickerItems.length + pickerJoinHeight,
3758
4689
  border: true,
3759
4690
  borderStyle: "rounded",
3760
4691
  borderColor: ACCENT,
@@ -3762,15 +4693,20 @@ ${tunneled}
3762
4693
  titleAlignment: "left",
3763
4694
  backgroundColor: SURFACE,
3764
4695
  flexDirection: "column",
3765
- children: pickerItems.map((item, index) => /* @__PURE__ */ jsx3(
3766
- HarnessRow,
3767
- {
3768
- item,
3769
- selected: index === pickerIndex,
3770
- background: SURFACE
3771
- },
3772
- String(item.harness)
3773
- ))
4696
+ children: [
4697
+ pickerJoinRows.map((row, index) => /* @__PURE__ */ jsx3("text", { height: 1, bg: SURFACE, fg: INK_2, children: ` ${row}` }, `join-${index}`)),
4698
+ pickerJoinRows.length === 0 ? null : /* @__PURE__ */ jsx3("text", { height: 1, bg: SURFACE, children: " " }),
4699
+ pickerItems.map((item, index) => /* @__PURE__ */ jsx3(
4700
+ HarnessRow,
4701
+ {
4702
+ item,
4703
+ selected: index === pickerIndex,
4704
+ background: SURFACE,
4705
+ width: modalWidth - 2
4706
+ },
4707
+ String(item.harness)
4708
+ ))
4709
+ ]
3774
4710
  }
3775
4711
  ),
3776
4712
  editing === null ? null : /* @__PURE__ */ jsx3(
@@ -3784,7 +4720,7 @@ ${tunneled}
3784
4720
  border: true,
3785
4721
  borderStyle: "rounded",
3786
4722
  borderColor: ACCENT,
3787
- title: ` label \u2014 ${editing.harness} ${editing.id.slice(0, 8)} `,
4723
+ title: ` label \xB7 ${editing.harness} ${editing.id.slice(0, 8)} `,
3788
4724
  titleAlignment: "left",
3789
4725
  backgroundColor: SURFACE,
3790
4726
  height: 3,
@@ -3815,9 +4751,9 @@ ${tunneled}
3815
4751
  position: "absolute",
3816
4752
  zIndex: 11,
3817
4753
  left: Math.max(1, Math.floor((terminalCols - Math.min(70, terminalCols - 4)) / 2)),
3818
- top: Math.max(1, Math.floor((terminalRows - 7) / 2)),
4754
+ top: Math.max(1, Math.floor((terminalRows - 7 - adoptFailureLines.length) / 2)),
3819
4755
  width: Math.min(70, terminalCols - 4),
3820
- height: 7,
4756
+ height: 7 + adoptFailureLines.length,
3821
4757
  border: true,
3822
4758
  borderStyle: "rounded",
3823
4759
  borderColor: ACCENT,
@@ -3840,7 +4776,8 @@ ${tunneled}
3840
4776
  ] }, candidate.mode))
3841
4777
  ] }),
3842
4778
  /* @__PURE__ */ jsx3("text", { height: 1, bg: SURFACE, fg: FAINT, children: ` ${ADOPT_AUTH_MODES[adoptOffer.modeIndex]?.hint ?? ""}` }),
3843
- /* @__PURE__ */ jsx3("text", { height: 1, bg: SURFACE, fg: FAINT, children: " enter adopt \xB7 \u2190\u2192 auth mode \xB7 esc not now" })
4779
+ adoptFailureLines.map((line, index) => /* @__PURE__ */ jsx3("text", { height: 1, bg: SURFACE, fg: ERROR, children: ` ${line}` }, `failure-${index}`)),
4780
+ /* @__PURE__ */ jsx3("text", { height: 1, bg: SURFACE, fg: FAINT, children: adoptOffer.failure === void 0 ? " enter adopt \xB7 \u2190\u2192 auth mode \xB7 esc not now" : " enter try again \xB7 \u2190\u2192 auth mode \xB7 esc not now" })
3844
4781
  ]
3845
4782
  }
3846
4783
  ),
@@ -3856,7 +4793,7 @@ ${tunneled}
3856
4793
  border: true,
3857
4794
  borderStyle: "rounded",
3858
4795
  borderColor: ACCENT,
3859
- title: ` new worktree \u2014 ${selectedProject?.project.name ?? "project"} `,
4796
+ title: ` new worktree \xB7 ${selectedProject?.project.name ?? "project"} `,
3860
4797
  titleAlignment: "left",
3861
4798
  backgroundColor: SURFACE,
3862
4799
  flexDirection: "column",
@@ -3873,7 +4810,10 @@ ${tunneled}
3873
4810
  {
3874
4811
  focused: true,
3875
4812
  value: creating.name,
3876
- placeholder: "e.g. fix-auth (empty = auto \xB7 an existing name joins it)",
4813
+ placeholder: fit(
4814
+ "e.g. fix-auth (empty = auto \xB7 an existing name joins it)",
4815
+ modalFieldWidth
4816
+ ),
3877
4817
  backgroundColor: SURFACE,
3878
4818
  focusedBackgroundColor: SURFACE,
3879
4819
  textColor: INK,
@@ -3904,7 +4844,10 @@ ${tunneled}
3904
4844
  {
3905
4845
  focused: true,
3906
4846
  value: "",
3907
- placeholder: "type to filter (enter = highlighted; empty = default)",
4847
+ placeholder: fit(
4848
+ "filter \xB7 enter takes the highlighted branch, or the default",
4849
+ modalFieldWidth
4850
+ ),
3908
4851
  backgroundColor: SURFACE,
3909
4852
  focusedBackgroundColor: SURFACE,
3910
4853
  textColor: INK,
@@ -3926,6 +4869,10 @@ ${tunneled}
3926
4869
  const branch = creating.joins || creating.branches === null ? void 0 : filterBranches(creating.branches, creating.query)[index];
3927
4870
  const active = creating.step === "base";
3928
4871
  if (branch === void 0) {
4872
+ const joinRow = creatingJoinRows[index];
4873
+ if (joinRow !== void 0) {
4874
+ return /* @__PURE__ */ jsx3("text", { height: 1, bg: SURFACE, fg: INK_2, children: ` ${joinRow}` }, `slot-${index}`);
4875
+ }
3929
4876
  const notice = creating.joins ? null : baseStepNotice(creating);
3930
4877
  return /* @__PURE__ */ jsx3(
3931
4878
  "text",
@@ -3933,7 +4880,7 @@ ${tunneled}
3933
4880
  height: 1,
3934
4881
  bg: SURFACE,
3935
4882
  fg: creating.branchError === null ? FAINT : ERROR,
3936
- children: index === 0 && notice !== null ? ` ${fit(notice, 66)}` : " "
4883
+ children: index === 0 && notice !== null ? ` ${fit(notice, modalWidth - 7)}` : " "
3937
4884
  },
3938
4885
  `slot-${index}`
3939
4886
  );
@@ -3950,7 +4897,7 @@ ${tunneled}
3950
4897
  /* @__PURE__ */ jsx3(Gutter, { selected: highlighted }),
3951
4898
  /* @__PURE__ */ jsx3("span", { fg: active ? INK : FAINT, children: branch.name.slice(0, 40).padEnd(41) }),
3952
4899
  /* @__PURE__ */ jsx3("span", { fg: FAINT, children: branch.sha.slice(0, 8).padEnd(10) }),
3953
- /* @__PURE__ */ jsx3("span", { fg: active ? MUTED : FAINT, children: shortAge(branch.committedAt).padEnd(6) }),
4900
+ /* @__PURE__ */ jsx3("span", { fg: active ? MUTED : FAINT, children: timeAgo(branch.committedAt).padEnd(9) }),
3954
4901
  branch.isDefault ? /* @__PURE__ */ jsx3("span", { fg: FAINT, children: "default" }) : null
3955
4902
  ] })
3956
4903
  },
@@ -3961,7 +4908,7 @@ ${tunneled}
3961
4908
  /* @__PURE__ */ jsx3(Gutter, { selected: creating.step === "harness" }),
3962
4909
  /* @__PURE__ */ jsx3("span", { fg: FAINT, children: "harness" })
3963
4910
  ] }),
3964
- deriveHarnesses(null).map((item, index) => {
4911
+ deriveHarnesses(null, creating.joins ? creating.name : null).map((item, index) => {
3965
4912
  const active = creating.step === "harness";
3966
4913
  const highlighted = active && index === creating.harnessIndex;
3967
4914
  return /* @__PURE__ */ jsx3(
@@ -3974,7 +4921,7 @@ ${tunneled}
3974
4921
  /* @__PURE__ */ jsx3("span", { fg: FAINT, children: " " }),
3975
4922
  /* @__PURE__ */ jsx3(Gutter, { selected: highlighted }),
3976
4923
  /* @__PURE__ */ jsx3("span", { fg: active ? INK : FAINT, children: item.label.padEnd(12) }),
3977
- /* @__PURE__ */ jsx3("span", { fg: FAINT, children: active ? item.hint : "" })
4924
+ /* @__PURE__ */ jsx3("span", { fg: FAINT, children: active ? fit(item.hint, Math.max(4, modalWidth - 2 - 3 - 2 - 12)) : "" })
3978
4925
  ] })
3979
4926
  },
3980
4927
  String(item.harness)
@@ -3983,8 +4930,58 @@ ${tunneled}
3983
4930
  ]
3984
4931
  }
3985
4932
  ),
3986
- loadFailure === null ? /* @__PURE__ */ jsx3(StatusLine, { busy, busyStarted, status }) : /* @__PURE__ */ jsx3("text", { height: 1, fg: ERROR, bg: "transparent", children: ` could not load workbench \u2014 ${loadFailure} \xB7 retrying` }),
3987
- /* @__PURE__ */ jsx3("text", { height: 1, fg: FAINT, bg: "transparent", children: footerText })
4933
+ loadFailure === null ? /* @__PURE__ */ jsx3(StatusLine, { busy, busyStarted, status }) : /* @__PURE__ */ jsx3("text", { height: 1, fg: ERROR, bg: "transparent", children: ` could not load workbench \xB7 ${loadFailure} \xB7 retrying` }),
4934
+ helpOpen ? /* @__PURE__ */ jsxs3(
4935
+ "box",
4936
+ {
4937
+ position: "absolute",
4938
+ zIndex: 14,
4939
+ left: Math.max(1, Math.floor((terminalCols - helpWidth) / 2)),
4940
+ top: Math.max(1, Math.floor((terminalRows - (helpRows + 3)) / 2)),
4941
+ width: helpWidth,
4942
+ height: helpRows + 3,
4943
+ border: true,
4944
+ borderStyle: "rounded",
4945
+ borderColor: ACCENT,
4946
+ title: ` keys \xB7 ${fit(columnTitle(focus), Math.max(6, helpWidth - 14))} `,
4947
+ titleAlignment: "left",
4948
+ backgroundColor: SURFACE,
4949
+ flexDirection: "column",
4950
+ children: [
4951
+ helpView.map(
4952
+ (line) => line.kind === "blank" ? /* @__PURE__ */ jsx3("text", { height: 1, bg: SURFACE, children: " " }, line.key) : line.kind === "title" ? /* @__PURE__ */ jsx3("text", { height: 1, bg: SURFACE, fg: MUTED, children: ` ${line.text}` }, line.key) : /* @__PURE__ */ jsxs3("text", { height: 1, bg: SURFACE, children: [
4953
+ /* @__PURE__ */ jsx3("span", { fg: INK, children: ` ${fit(line.row.keys, 18).padEnd(19)}` }),
4954
+ /* @__PURE__ */ jsx3("span", { fg: line.row.here ? INK_2 : FAINT, children: fit(line.row.help, Math.max(8, helpWidth - 25)) })
4955
+ ] }, line.key)
4956
+ ),
4957
+ /* @__PURE__ */ jsx3("text", { height: 1, bg: SURFACE, fg: FAINT, children: ` ${helpMaxOffset > 0 ? "\u2191\u2193 scroll \xB7 " : ""}esc closes` })
4958
+ ]
4959
+ }
4960
+ ) : null,
4961
+ filtering === null ? /* @__PURE__ */ jsx3("text", { height: 1, fg: FAINT, bg: "transparent", children: footerText }) : /* @__PURE__ */ jsxs3("box", { height: 1, flexShrink: 0, flexDirection: "row", children: [
4962
+ /* @__PURE__ */ jsx3("text", { height: 1, bg: "transparent", fg: ACCENT, children: " / " }),
4963
+ /* @__PURE__ */ jsx3(
4964
+ "input",
4965
+ {
4966
+ focused: true,
4967
+ value: filters[filtering],
4968
+ placeholder: `filter ${columnTitle(filtering)} \xB7 enter keeps it \xB7 esc clears it`,
4969
+ backgroundColor: CANVAS,
4970
+ focusedBackgroundColor: CANVAS,
4971
+ textColor: INK,
4972
+ focusedTextColor: INK,
4973
+ placeholderColor: FAINT,
4974
+ cursorColor: INK,
4975
+ flexGrow: 1,
4976
+ onInput: (value) => {
4977
+ const section = filtering;
4978
+ const clean = value.replace(/\t/g, "");
4979
+ setFilters((current) => ({ ...current, [section]: clean }));
4980
+ },
4981
+ onSubmit: () => setFiltering(null)
4982
+ }
4983
+ )
4984
+ ] })
3988
4985
  ] });
3989
4986
  };
3990
4987
  var runDashboard = async (ctx) => {
@@ -4055,5 +5052,7 @@ var runDashboard = async (ctx) => {
4055
5052
  });
4056
5053
  };
4057
5054
  export {
5055
+ App,
5056
+ HANDOVER_MS,
4058
5057
  runDashboard
4059
5058
  };