@eliya-oss/agent-diff 0.1.0-alpha.211 → 0.1.0-alpha.213

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 (38) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/dist/main.js +1123 -695
  3. package/dist/web/nitro.json +1 -1
  4. package/dist/web/public/assets/{_deck-DC3R9ZRW.js → _deck-BDC_r92m.js} +1 -1
  5. package/dist/web/public/assets/{_point-DGd-d-fN.js → _point-I_vt1otH.js} +1 -1
  6. package/dist/web/public/assets/index-CUagVLhR.css +2 -0
  7. package/dist/web/public/assets/{index-CNzMZ6k6.js → index-X7OFY5bM.js} +2 -2
  8. package/dist/web/public/assets/{review-CHVb5xmC.js → review-DE0jDEPH.js} +1 -1
  9. package/dist/web/public/assets/{review-block-DYenwozF.js → review-block-CbmQ0t4L.js} +12 -12
  10. package/dist/web/public/assets/{routes-5aZJQX_G.js → routes-CYn3-ePX.js} +1 -1
  11. package/dist/web/public/assets/{viewed-store-Eo50afbB.js → viewed-store-CuareBUI.js} +1 -1
  12. package/dist/web/server/{_deck-B4JFpoe9.mjs → _deck-x23t7F7l.mjs} +3 -3
  13. package/dist/web/server/{_point-NTPxvKqQ.mjs → _point-CaM245BE.mjs} +4 -4
  14. package/dist/web/server/_ssr/{adhoc.functions-B39jjvi1.mjs → adhoc.functions-CDadmCcu.mjs} +3 -3
  15. package/dist/web/server/_ssr/{createServerRpc-DYHyF6mI.mjs → createServerRpc-Xq42ilNx.mjs} +1 -1
  16. package/dist/web/server/_ssr/{decks.functions-0wQ-UZLQ.mjs → decks.functions-BHxu668D.mjs} +5 -5
  17. package/dist/web/server/_ssr/{empty-plugin-adapters-C_GlPYKD.mjs → empty-plugin-adapters-B3CY_z0V.mjs} +1 -1
  18. package/dist/web/server/_ssr/{listener.functions-Bsap7m-C.mjs → listener.functions-DygHonX4.mjs} +5 -5
  19. package/dist/web/server/_ssr/{listener.server-DtMUmNCb.mjs → listener.server-BUJSjrgf.mjs} +14 -3
  20. package/dist/web/server/_ssr/{live-schema-rwIqSfXd.mjs → live-schema-BYm_IvNp.mjs} +4 -3
  21. package/dist/web/server/_ssr/{pull.functions-6Ywbtb50.mjs → pull.functions-Dyi9ubGh.mjs} +2 -2
  22. package/dist/web/server/_ssr/{review-block-Ceno7nop.mjs → review-block-C-oUK43P.mjs} +1509 -1021
  23. package/dist/web/server/_ssr/{review-CVYUVoDD.mjs → review-e0zRsKyC.mjs} +3 -3
  24. package/dist/web/server/_ssr/{review-parts.server-DW9heP1l.mjs → review-parts.server-j_3LS0HZ.mjs} +2 -2
  25. package/dist/web/server/_ssr/{review-target.server-BTCBlGFL.mjs → review-target.server-DA41RDao.mjs} +77 -10
  26. package/dist/web/server/_ssr/{review.functions-Z_X3Jo2Z.mjs → review.functions-Cvig5BYP.mjs} +5 -5
  27. package/dist/web/server/_ssr/{router-jY5mnS6O.mjs → router-DH6_gEUb.mjs} +91 -39
  28. package/dist/web/server/_ssr/{routes-tQi6ASvp.mjs → routes-BP_s9iFs.mjs} +2 -2
  29. package/dist/web/server/_ssr/shortcuts-B7llaLLc.mjs +1 -1
  30. package/dist/web/server/_ssr/ssr.mjs +40 -36
  31. package/dist/web/server/_ssr/{type-hover.functions-Cf2CfVvS.mjs → type-hover.functions-B_9iC3Xs.mjs} +3 -3
  32. package/dist/web/server/_ssr/{viewed-store-9-at5rDS.mjs → viewed-store-RX0hDmiV.mjs} +2 -2
  33. package/dist/web/server/{_tanstack-start-manifest_v-CVU4En5c.mjs → _tanstack-start-manifest_v-D8_4kgre.mjs} +8 -8
  34. package/dist/web/server/index.mjs +50 -50
  35. package/package.json +1 -1
  36. package/skills/adiff/SKILL.md +46 -3
  37. package/skills/adiff-web/SKILL.md +2 -1
  38. package/dist/web/public/assets/index-Cog4a4vB.css +0 -2
@@ -1,11 +1,11 @@
1
1
  import { __toESM } from "../_runtime.mjs";
2
- import { Button$1, CODE_SIZES, EDITORS, Hint, IconButton, Kbd, KbdGroup, KeyTip, THEMES, THEME_NAMES, Tooltip$1, TooltipContent, TooltipTrigger, cn, createSsrRpc, getReviewPrefs, loadReviewFile, loadReviewOutline, loadSinceFile, markReviewFile, setIntroFolded, setReviewPrefs, setTheme, showCodeSize, toggleNoted, toggleOthersShown, toggleScoped, uncover, uploadImage, useReviewPrefs, useTheme, useToast, useWindowEvent } from "./router-jY5mnS6O.mjs";
3
- import { createCoalesced } from "./review-target.server-BTCBlGFL.mjs";
2
+ import { Button$1, CODE_SIZES, EDITORS, Hint, IconButton, Kbd, KbdGroup, KeyTip, THEMES, THEME_NAMES, Tooltip$1, TooltipContent, TooltipTrigger, cn, createSsrRpc, getReviewPrefs, loadReviewFile, loadReviewOutline, loadSinceFile, markReviewFile, setIntroFolded, setReviewPrefs, setTheme, showCodeSize, toggleNoted, toggleOthersShown, toggleScoped, uncover, uploadImage, useReviewPrefs, useTheme, useToast, useWindowEvent } from "./router-DH6_gEUb.mjs";
3
+ import { createCoalesced, nameThreadLayers } from "./review-target.server-DA41RDao.mjs";
4
4
  import { createServerFn } from "./ssr.mjs";
5
- import { reviewActSchema, reviewBaseSchema, reviewCommentSchema, reviewDraftSchema, reviewExtrasSchema, reviewPartsSchema, reviewRemarkSchema, reviewReplySchema, reviewSearchSchema, reviewSettleSchema, reviewTargetOnlySchema } from "./live-schema-rwIqSfXd.mjs";
5
+ import { reviewActSchema, reviewBaseSchema, reviewCommentSchema, reviewDraftSchema, reviewExtrasSchema, reviewPartsSchema, reviewRemarkSchema, reviewReplySchema, reviewSearchSchema, reviewSettleSchema, reviewTargetOnlySchema } from "./live-schema-BYm_IvNp.mjs";
6
6
  import { threadCodeSchema, toAsk } from "./thread-code-BWhoBW-5.mjs";
7
7
  import { Collapsible$1, CollapsibleContent, CollapsibleTrigger, PreviewCard$1, PreviewCardContent, SHORTCUTS, createReads, getRelativeTime, getRevision, insertPastedText, isOverlayOpen, isSeen, isTyping, readNewest, useNow } from "./shortcuts-B7llaLLc.mjs";
8
- import { AGENT_IDS, getConnectPrompt, getResumeCommand, getTerminalCommand } from "./listener.server-DtMUmNCb.mjs";
8
+ import { AGENT_IDS, getConnectPrompt, getResumeCommand, getTerminalCommand } from "./listener.server-BUJSjrgf.mjs";
9
9
  import { getPullKey, getPullKind, getPullLabel, getPullReview, parsePullUrl, pullStatesInputSchema } from "./pull-link-CxZ12dkT.mjs";
10
10
  import { findWord, isTypedPath, typeHoverSchema } from "./type-hover-DSq-tkS_.mjs";
11
11
  import { DialogBackdrop, DialogClose as DialogClose$1, DialogPopup, DialogPortal, DialogRoot, DialogTitle as DialogTitle$1, MenuItem, MenuPopup, MenuPortal, MenuPositioner, MenuRoot, MenuTrigger, PopoverPopup, PopoverPortal, PopoverPositioner, PopoverRoot, PopoverTitle as PopoverTitle$1, Separator, require_jsx_runtime, require_react, require_react_dom } from "../_libs/@base-ui/react+[...].mjs";
@@ -13,7 +13,7 @@ import { array, boolean, literal, nullable, number, object, optional, picklist,
13
13
  import { ArrowDownToLine, ArrowRight, ArrowUp, ArrowUpToLine, Check, CheckCheck, ChevronDown, ChevronLeft, ChevronRight, ChevronUp, ChevronsDownUp, ChevronsUpDown, Circle, CircleCheck, ClipboardCopy, Copy, CornerDownLeft, Ellipsis, EyeOff, FileText, Folder, FolderOpen, GitCompare, GitPullRequest, Keyboard, Layers, Layers2, ListFilter, ListOrdered, LoaderCircle, LocateFixed, Maximize2, MessageSquarePlus, MessagesSquare, Minus, Pin, Play, Plus, RotateCcw, Search, Send, Settings, Sparkle, Sparkles, Square, SquareArrowOutUpRight, SquareDashedText, SquareTerminal, TextAlignStart, TextWrap, Trash, UserRound, X } from "../_libs/lucide-react.mjs";
14
14
  import { Markdown as Markdown$1, defaultUrlTransform } from "../_libs/react-markdown+[...].mjs";
15
15
  import { remarkGfm } from "../_libs/remark-gfm.mjs";
16
- // node_modules/.nitro/vite/services/ssr/assets/review-block-Ceno7nop.js
16
+ // node_modules/.nitro/vite/services/ssr/assets/review-block-C-oUK43P.js
17
17
  var import_react = /* @__PURE__ */ __toESM(require_react());
18
18
  var import_jsx_runtime = require_jsx_runtime();
19
19
  var import_react_dom = /* @__PURE__ */ __toESM(require_react_dom());
@@ -1460,6 +1460,18 @@ var StandMark = ({ stand, said = null }) => {
1460
1460
  })]
1461
1461
  }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipContent, { children: label })] });
1462
1462
  };
1463
+ /** The open comments on a row: the loudest mark and how many, in its colour. */
1464
+ var OpenMark = ({ threads }) => threads.open > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
1465
+ className: "inline-flex items-center gap-0.5",
1466
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(StandMark, {
1467
+ said: getMarkSaid(threads),
1468
+ stand: threads.stand
1469
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1470
+ "aria-hidden": true,
1471
+ className: cn("font-mono text-xs tabular-nums", STAND_TONES[threads.stand]),
1472
+ children: threads.open
1473
+ })]
1474
+ }) : null;
1463
1475
  /** What a card's head says, in the gutter's words but shorter. */
1464
1476
  var CARD_WORDS = {
1465
1477
  gone: "Removed",
@@ -2080,7 +2092,7 @@ var QuietLead = ({ quiet }) => {
2080
2092
  className: "diff-quiet-slot",
2081
2093
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: cn("w-px flex-1 bg-input", quiet.place === "end" && "mb-1.5") })
2082
2094
  });
2083
- const label = quiet.layer === null ? quiet.title : `Layer ${String(quiet.layer)} explains these lines: ${quiet.title}`;
2095
+ const label = quiet.layer === null ? quiet.title : `Layer ${quiet.layer} explains these lines: ${quiet.title}`;
2084
2096
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
2085
2097
  className: cn("diff-quiet-slot", quiet.place === "one" && "justify-center"),
2086
2098
  children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Hint, {
@@ -2089,7 +2101,7 @@ var QuietLead = ({ quiet }) => {
2089
2101
  "aria-label": label,
2090
2102
  className: cn("text-2xs text-subtle tabular-nums", quiet.place === "top" && "pt-0.5"),
2091
2103
  "data-quiet-layer": true,
2092
- children: quiet.layer === null ? "·" : `L${String(quiet.layer)}`
2104
+ children: quiet.layer === null ? "·" : `L${quiet.layer}`
2093
2105
  })
2094
2106
  }), quiet.place === "top" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
2095
2107
  "aria-hidden": true,
@@ -3379,16 +3391,20 @@ var useReviewOutline = (target, onChanged) => {
3379
3391
  };
3380
3392
  /**
3381
3393
  * The layers adiff answered the last mark with, laid over the outline they were answered against
3382
- * until the review is read again, so a layer reads done at once.
3394
+ * until the review is read again, so a layer reads done at once. Each thread names its first layer
3395
+ * by that layer's address.
3383
3396
  */
3384
3397
  var useAnsweredLayers = (outline) => {
3385
3398
  const [answered, setAnswered] = (0, import_react.useState)(null);
3399
+ const told = answered?.on === outline ? answered.told : outline;
3386
3400
  return {
3387
- layers: answered?.on === outline ? answered.layers : outline.layers,
3388
- handleLayers: (layers) => {
3389
- if (layers !== null) setAnswered({
3401
+ layers: told.layers,
3402
+ tickets: told.tickets,
3403
+ threads: nameThreadLayers(outline.threads, told.layers),
3404
+ handleLayers: (next) => {
3405
+ if (next !== null) setAnswered({
3390
3406
  on: outline,
3391
- layers
3407
+ told: next
3392
3408
  });
3393
3409
  }
3394
3410
  };
@@ -3677,72 +3693,23 @@ var getTreeRows = (paths, collapsed) => flatten$1(getBuilt(paths).root, collapse
3677
3693
  /** The paths as the tree lists them. The list is shared between callers: copy it before changing it. */
3678
3694
  var getTreeOrder = (paths) => getBuilt(paths).order;
3679
3695
  var layerKey = (index) => `layer:${String(index)}`;
3696
+ var ticketKey = (number) => `ticket:${String(number)}`;
3680
3697
  var fileKey = (index, path) => `${layerKey(index)}:${path}`;
3681
3698
  var LAYER_AT = /^layer:(?<index>\d+)/u;
3699
+ var TICKET_AT = /^ticket:(?<number>\d+)$/u;
3682
3700
  var getLayerAt = (key) => {
3683
3701
  const found = LAYER_AT.exec(key);
3684
3702
  return found?.groups?.["index"] === void 0 ? null : Number(found.groups["index"]);
3685
3703
  };
3686
- /** The layers' files in the diff; `isShown` leaves out a layer's files the reader hid, by layer. */
3687
- var getLayerGroups = (layers, { present, isShown }) => {
3688
- const here = new Set(present);
3689
- return layers.map((layer, index) => {
3690
- const all = layer.files.filter((path) => here.has(path));
3691
- return {
3692
- key: layerKey(index),
3693
- index,
3694
- title: layer.title,
3695
- all,
3696
- files: all.filter((path) => isShown(index, path))
3697
- };
3698
- });
3704
+ /** The ticket whose own row the key names, by its number. */
3705
+ var getTicketAt = (key) => {
3706
+ const found = TICKET_AT.exec(key);
3707
+ return found?.groups?.["number"] === void 0 ? null : Number(found.groups["number"]);
3699
3708
  };
3700
- var getLayerRows$1 = (groups, isOpen) => groups.flatMap((group) => [{
3701
- kind: "dir",
3702
- key: group.key,
3703
- label: group.title,
3704
- full: group.key,
3705
- depth: 0
3706
- }, ...isOpen(group) ? group.files.map((path) => ({
3707
- kind: "file",
3708
- key: fileKey(group.index, path),
3709
- path,
3710
- label: getName$1(path),
3711
- depth: 1
3712
- })) : []]);
3713
- var getLayerOrder = (groups) => groups.flatMap((group) => group.files.map((path) => fileKey(group.index, path)));
3714
3709
  /** What the order is now, so a request for a new one knows when it has arrived. */
3715
3710
  var getOrderKey = (layers) => layers.map((layer) => `${layer.title}:${String(layer.files.length)}`).join("|");
3716
3711
  /** The one row that stands for every layer already read, folded by default. */
3717
3712
  var READ_LAYERS = "layer:read";
3718
- /**
3719
- * The layers rail with the read layers folded into one row at the top, so it starts at the work
3720
- * left. Unfolded, the read layers follow that row; the rest keep the agent's order either way.
3721
- */
3722
- var foldReadLayers = (groups, { isDone, isOpen, isReadOpen }) => {
3723
- const done = groups.filter((group) => isDone(group));
3724
- const rest = groups.filter((group) => !isDone(group));
3725
- if (done.length === 0) return {
3726
- rows: getLayerRows$1(groups, isOpen),
3727
- order: getLayerOrder(groups),
3728
- done,
3729
- rest
3730
- };
3731
- const head = {
3732
- kind: "dir",
3733
- key: READ_LAYERS,
3734
- label: `${String(done.length)} ${done.length === 1 ? "layer" : "layers"} read`,
3735
- full: READ_LAYERS,
3736
- depth: 0
3737
- };
3738
- const shown = isReadOpen ? [...done, ...rest] : rest;
3739
- return {
3740
- rows: [head, ...getLayerRows$1(shown, isOpen)],
3741
- order: getLayerOrder(shown),
3742
- done,
3743
- rest
3744
- };
3745
- };
3746
3713
  var getFolder$1 = (path) => getParent(path);
3747
3714
  var SHORT_FOLDER_PARTS = 3;
3748
3715
  var shortenFolder = (folder) => {
@@ -3908,646 +3875,881 @@ var ThemeChoice = () => {
3908
3875
  })]
3909
3876
  });
3910
3877
  };
3911
- /** A sentence ends at ". " before a capital. */
3912
- var BREAK = /(?<=\.)\s+(?=[A-Z`?@(])/u;
3913
- var LIST_MARK = /^[-•·*]\s+/u;
3914
- var BOLD = /\*\*(?<words>[^*]+)\*\*/gu;
3915
- /** Where a reading instruction starts: the line a reader acts on rather than learns from. */
3916
- var HOW_TO = /^Read\b/u;
3917
- var unbold = (text) => text.replaceAll(BOLD, "$<words>");
3918
- /** A note's lines: the ones its writer broke, or else its sentences and clauses. */
3919
- var getLines$1 = (note) => (note.includes("\n") ? note.split("\n") : note.split(BREAK)).map((line) => unbold(line.trim().replace(LIST_MARK, ""))).filter((line) => line !== "");
3920
- /** The layer's intro: the first piece of its note, read over the file adiff places it at. */
3921
- var getIntro = (layer) => {
3922
- const [first] = layer.prose;
3923
- const [lead, ...rest] = getLines$1(first?.markdown ?? "");
3924
- return lead === void 0 || first === void 0 ? null : {
3925
- lead,
3926
- points: rest.filter((line) => !HOW_TO.test(line)),
3927
- howTo: rest.filter((line) => HOW_TO.test(line)),
3928
- path: first.path
3878
+ function DropdownMenu({ ...props }) {
3879
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuRoot, {
3880
+ "data-slot": "dropdown-menu",
3881
+ ...props
3882
+ });
3883
+ }
3884
+ function DropdownMenuTrigger({ ...props }) {
3885
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuTrigger, {
3886
+ "data-slot": "dropdown-menu-trigger",
3887
+ ...props
3888
+ });
3889
+ }
3890
+ function DropdownMenuContent({ className, align = "end", sideOffset = 6, ...props }) {
3891
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPortal, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPositioner, {
3892
+ align,
3893
+ className: "isolate z-50",
3894
+ sideOffset,
3895
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPopup, {
3896
+ className: cn("min-w-48 pop-menu rounded-lg border border-border bg-popover p-1 text-sm text-popover-foreground shadow-md outline-none", className),
3897
+ "data-slot": "dropdown-menu-content",
3898
+ ...props
3899
+ })
3900
+ }) });
3901
+ }
3902
+ function DropdownMenuItem({ className, ...props }) {
3903
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuItem, {
3904
+ className: cn("flex items-center gap-2 rounded-md px-2 py-1.5 transition-colors duration-150 ease-out outline-none select-none data-highlighted:bg-secondary data-highlighted:text-foreground data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:size-4 [&_svg]:shrink-0 [&_svg]:text-muted-foreground", className),
3905
+ "data-slot": "dropdown-menu-item",
3906
+ ...props
3907
+ });
3908
+ }
3909
+ function DropdownMenuSeparator({ className, ...props }) {
3910
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Separator, {
3911
+ className: cn("-mx-1 my-1 h-px bg-border", className),
3912
+ "data-slot": "dropdown-menu-separator",
3913
+ ...props
3914
+ });
3915
+ }
3916
+ function DropdownMenuShortcut({ className, ...props }) {
3917
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
3918
+ className: cn("ms-auto text-xs text-subtle", className),
3919
+ "data-slot": "dropdown-menu-shortcut",
3920
+ ...props
3921
+ });
3922
+ }
3923
+ /** Puts text on the clipboard and says so in a toast. */
3924
+ var useCopy = () => {
3925
+ const toast = useToast();
3926
+ return async (text, title) => {
3927
+ await navigator.clipboard.writeText(text);
3928
+ toast.add({ title });
3929
3929
  };
3930
3930
  };
3931
- /** The pieces after the intro that adiff places in this file, in the order of their lines. */
3932
- var getFileNotes = (layer, path) => layer.prose.slice(1).filter((piece) => piece.path === path).toSorted((one, other) => one.line - other.line || Number(one.after) - Number(other.after));
3933
3931
  /**
3934
- * Names from code inside prose: `backticks`, camelCase and PascalCase words, `?query=`,
3935
- * `@Decorator`, HTTP verbs, paths and file names. Each is set in mono so the eye can find it.
3932
+ * Stops the headless run and hands its session to the reviewer's terminal: the command that
3933
+ * resumes it, told to carry on, goes on the clipboard first, while the click still counts as the
3934
+ * reviewer's, then the run stops.
3936
3935
  */
3937
- var CODE_WORD = /(?<code>`[^`]+`|\?\w+=|@[A-Z]\w+|\b(?:GET|POST|PUT|PATCH|DELETE)\b|\b[a-z]+[A-Z]\w*|\b[A-Z][a-z\d]+[A-Z]\w*|(?:[\w.:-]*\/)+[\w.:-]+|\b[\w-]+\.(?:ts|tsx|js|json|md|ya?ml)\b)/u;
3938
- /** Splitting on a captured pattern puts every match at an odd index. */
3939
- var EVERY_OTHER = 2;
3940
- /** Prose with its names from code in mono; `isChipped` sets them on a tint, as a note over code. */
3941
- var Words = ({ text, isChipped = false }) => text.split(CODE_WORD).map((part, at) => at % EVERY_OTHER === 1 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", {
3942
- className: isChipped ? "note-code" : "font-mono text-foreground",
3943
- children: part.replaceAll("`", "")
3944
- }, `${String(at)}:${part}`) : part);
3945
- /** A file has a note of its own: three lines of text, not a speech bubble, which means comments. */
3946
- var NoteGlyph = ({ className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", {
3947
- "aria-hidden": true,
3948
- className,
3949
- fill: "none",
3950
- stroke: "currentColor",
3951
- strokeLinecap: "round",
3952
- strokeWidth: 1.3,
3953
- viewBox: "0 0 14 14",
3954
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M3 4h8M3 7h8M3 10h5" })
3955
- });
3936
+ var takeOver = async ({ model, copy }) => {
3937
+ const { listener, branch } = model;
3938
+ const run = listener?.run ?? null;
3939
+ const worktree = listener?.worktree ?? null;
3940
+ const agent = listener?.agents.find((each) => each.label === run?.agent) ?? null;
3941
+ if (worktree === null || run === null || agent === null) return;
3942
+ await copy(getResumeCommand({
3943
+ resume: run.resume,
3944
+ interactive: agent.interactive,
3945
+ worktree,
3946
+ branch
3947
+ }), "Resume command copied · paste it in a terminal");
3948
+ await model.handleStop();
3949
+ };
3950
+ /** The agent menu's way to take a running headless agent over, first in the menu while it runs. */
3951
+ var TakeOverItem = ({ model, copy }) => model.listener?.run?.state === "running" && model.listener.worktree !== null ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenuItem, {
3952
+ disabled: model.isBusy,
3953
+ onClick: () => {
3954
+ takeOver({
3955
+ model,
3956
+ copy
3957
+ });
3958
+ },
3959
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SquareTerminal, {}), "Take over in your terminal"]
3960
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DropdownMenuSeparator, {})] }) : null;
3961
+ var getChosen = (listener) => listener.agents.find((agent) => agent.id === listener.chosen) ?? null;
3956
3962
  /**
3957
- * The open layer's lead in the rail: the intro's first sentence only. The rest of the intro opens
3958
- * over the layer's first file, where it is read; a click goes there.
3963
+ * Every way to bring an agent to this review: start another installed one headless, paste a
3964
+ * prompt into an agent already open, or paste a command that opens the chosen one in a terminal.
3959
3965
  */
3960
- var LayerLead = ({ layer, isIntroShown, onOpenIntro }) => {
3961
- const intro = layer === void 0 ? null : getIntro(layer);
3962
- return intro === null ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
3963
- className: "mt-0.5 mb-1 grid w-full gap-0.5 rounded-md py-1.5 ps-8 pe-2 text-start text-ui text-muted-foreground hover:bg-row-hover hover:text-foreground max-md:text-sm",
3964
- onClick: onOpenIntro,
3965
- type: "button",
3966
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Words, { text: intro.lead }) }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
3967
- className: "text-xs text-subtle",
3968
- children: isIntroShown ? "Intro is open" : "Read the intro"
3969
- })]
3970
- });
3971
- };
3972
- var lines = (count) => `${String(count)} ${count === 1 ? "line" : "lines"}`;
3973
- var places = (count) => `${String(count)} ${count === 1 ? "place" : "places"}`;
3974
- /** "9 lines in 2 places since you reviewed it, 2h ago", or less when adiff knows less. */
3975
- var getSinceSaid = (since, now) => {
3976
- const ago = since.at === "" ? "" : `, ${getRelativeTime(since.at, now)} ago`;
3977
- if (since.deleted) return `Deleted since you reviewed it${ago}`;
3978
- return since.kept ? `${lines(since.added + since.removed)} in ${places(since.places)} since you reviewed it${ago}` : `Changed since you reviewed it${ago}`;
3979
- };
3980
- /** A check inside a turning arrow: read before, look again. */
3981
- var SinceGlyph = () => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", {
3982
- "aria-hidden": true,
3983
- className: "size-3",
3984
- fill: "none",
3985
- viewBox: "0 0 12 12",
3986
- children: [
3987
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", {
3988
- d: "M10.4 4.2A4.9 4.9 0 1 0 10.9 7.6",
3989
- stroke: "currentColor",
3990
- strokeLinecap: "round",
3991
- strokeWidth: "1.3"
3966
+ var AgentMenu = ({ model, isHeard, onSettings }) => {
3967
+ const copy = useCopy();
3968
+ const { listener, isBusy, branch } = model;
3969
+ if (listener === null) return null;
3970
+ const chosen = getChosen(listener);
3971
+ const others = listener.agents.filter((agent) => agent.isInstalled && agent.id !== chosen?.id);
3972
+ const { worktree } = listener;
3973
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenu, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(DropdownMenuTrigger, { render: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$1, {
3974
+ "aria-label": "Agent options",
3975
+ size: "icon-xs",
3976
+ variant: "ghost",
3977
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChevronDown, {})
3978
+ }) }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenuContent, { children: [
3979
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TakeOverItem, {
3980
+ copy,
3981
+ model
3992
3982
  }),
3993
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", {
3994
- d: "M10.9 1.6 10.6 4.5 7.8 4.1",
3995
- stroke: "currentColor",
3996
- strokeLinecap: "round",
3997
- strokeLinejoin: "round",
3998
- strokeWidth: "1.3"
3983
+ isHeard ? null : others.map((agent) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenuItem, {
3984
+ disabled: isBusy || worktree === null,
3985
+ onClick: () => void model.handleStart(agent.id),
3986
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Play, {}), `Start a headless ${agent.label}`]
3987
+ }, agent.id)),
3988
+ isHeard || others.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DropdownMenuSeparator, {}),
3989
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenuItem, {
3990
+ disabled: worktree === null,
3991
+ onClick: () => {
3992
+ if (worktree !== null) copy(getConnectPrompt(worktree, branch), "Prompt copied: paste it to your agent");
3993
+ },
3994
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ClipboardCopy, {}), "Copy a prompt for your agent"]
3999
3995
  }),
4000
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", {
4001
- d: "M3.9 6.2 5.4 7.7 8 4.9",
4002
- stroke: "currentColor",
4003
- strokeLinecap: "round",
4004
- strokeLinejoin: "round",
4005
- strokeWidth: "1.4"
3996
+ chosen === null ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenuItem, {
3997
+ disabled: worktree === null,
3998
+ onClick: () => {
3999
+ if (worktree !== null) copy(getTerminalCommand(chosen.interactive, worktree, branch), `Command copied: paste it in a terminal to open ${chosen.label}`);
4000
+ },
4001
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SquareTerminal, {}), `Copy a terminal command for ${chosen.label}`]
4002
+ }),
4003
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DropdownMenuSeparator, {}),
4004
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenuItem, {
4005
+ onClick: onSettings,
4006
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Settings, {}), "Agent settings…"]
4006
4007
  })
4007
- ]
4008
- });
4009
- /** A file reviewed, then changed: it reads as unreviewed, with this mark where the check was. */
4010
- var SinceMark = ({ since }) => {
4011
- const now = useNow();
4012
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Tooltip$1, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TooltipTrigger, {
4013
- render: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "inline-flex text-muted-foreground" }),
4014
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SinceGlyph, {}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4015
- className: "sr-only",
4016
- children: "Changed since review"
4017
- })]
4018
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipContent, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
4019
- className: "grid gap-0.5",
4020
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4021
- className: "font-medium",
4022
- children: "Changed since review"
4023
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: getSinceSaid(since, now) })]
4024
- }) })] });
4008
+ ] })] });
4025
4009
  };
4026
- var STATUS_MARKS = {
4027
- added: {
4028
- Icon: Plus,
4029
- label: () => "New file",
4030
- tone: "text-sign-add"
4031
- },
4032
- deleted: {
4033
- Icon: Minus,
4034
- label: () => "Deleted file",
4035
- tone: "text-sign-del"
4036
- },
4037
- renamed: {
4038
- Icon: ArrowRight,
4039
- label: (from) => `Renamed from ${from}`,
4040
- tone: "text-subtle"
4041
- },
4042
- copied: {
4043
- Icon: Copy,
4044
- label: (from) => `Copied from ${from}`,
4045
- tone: "text-subtle"
4046
- }
4010
+ /** The agent's actions: start one when nobody answers, or take the running one over. */
4011
+ var useAgentActions = (props) => {
4012
+ const copy = useCopy();
4013
+ const model = props.listener;
4014
+ const { listener } = model;
4015
+ const worktree = listener?.worktree ?? null;
4016
+ if (listener === null || worktree === null) return [];
4017
+ const chosen = getChosen(listener);
4018
+ const isRunning = listener.run?.state === "running";
4019
+ return [
4020
+ {
4021
+ id: "start",
4022
+ icon: Sparkles,
4023
+ label: `Start ${chosen?.label ?? "an agent"}`,
4024
+ note: "It reads your comments and answers them in the background",
4025
+ isShown: !isRunning && !listener.isListening && chosen !== null,
4026
+ onPress: () => {
4027
+ if (chosen !== null) model.handleStart(chosen.id);
4028
+ }
4029
+ },
4030
+ {
4031
+ id: "take-over",
4032
+ icon: SquareTerminal,
4033
+ label: "Take over in your terminal",
4034
+ note: "Copies a command that resumes its session, and stops it here",
4035
+ isShown: isRunning,
4036
+ onPress: () => {
4037
+ takeOver({
4038
+ model,
4039
+ copy
4040
+ });
4041
+ }
4042
+ },
4043
+ {
4044
+ id: "stop",
4045
+ icon: Square,
4046
+ label: `Stop ${listener.run?.agent ?? "the agent"}`,
4047
+ isShown: isRunning,
4048
+ onPress: () => {
4049
+ model.handleStop();
4050
+ }
4051
+ },
4052
+ {
4053
+ id: "terminal",
4054
+ icon: SquareTerminal,
4055
+ label: "Copy a terminal command",
4056
+ note: `Opens ${chosen?.label ?? "the agent"} in this worktree, already listening`,
4057
+ isShown: !isRunning && chosen !== null,
4058
+ onPress: () => {
4059
+ if (chosen !== null) copy(getTerminalCommand(chosen.interactive, worktree, model.branch), "Command copied · paste it in a terminal");
4060
+ }
4061
+ }
4062
+ ];
4047
4063
  };
4048
- var StatusMark = ({ file }) => {
4049
- if (file.status === "modified") return null;
4050
- const { Icon, label, tone } = STATUS_MARKS[file.status];
4051
- const said = label(file.previousPath);
4052
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Tooltip$1, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TooltipTrigger, {
4053
- render: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: cn("inline-flex shrink-0", tone) }),
4054
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Icon, {
4055
- "aria-hidden": true,
4056
- className: "size-3"
4057
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4058
- className: "sr-only",
4059
- children: said
4060
- })]
4061
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipContent, { children: said })] });
4064
+ var DIFF$1 = "[data-review-diff]";
4065
+ var ROW$1 = "[data-review-row]";
4066
+ var PERCENT$3 = 100;
4067
+ /** The first row of the diff in view, and where it is, so a new size can leave it there. */
4068
+ var findTopRow = () => {
4069
+ const diff = document.querySelector(DIFF$1);
4070
+ if (diff === null) return null;
4071
+ const { top } = diff.getBoundingClientRect();
4072
+ const row = [...diff.querySelectorAll(ROW$1)].find((one) => one.getBoundingClientRect().bottom > top);
4073
+ return row === void 0 ? null : {
4074
+ diff,
4075
+ row,
4076
+ at: row.getBoundingClientRect().top
4077
+ };
4062
4078
  };
4063
- var KIND_MARKS = [{
4064
- short: "bin",
4065
- label: "Binary file",
4066
- isOn: (file) => file.isBinary
4067
- }, {
4068
- short: "gen",
4069
- label: "Generated file",
4070
- isOn: (file) => file.isGenerated
4071
- }];
4072
- var KindMarks = ({ file }) => KIND_MARKS.filter((mark) => mark.isOn(file)).map((mark) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Tooltip$1, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipTrigger, {
4073
- render: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "shrink-0 text-subtle" }),
4074
- children: mark.short
4075
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipContent, { children: mark.label })] }, mark.short));
4076
- var TAIL = 12;
4077
- /** The line counts and whether the layer is read come from adiff, which counts each layer's own
4078
- * spans; only the read count leans on marks still on their way. */
4079
- var getLayerSize = (group, layer, isReadIn) => ({
4080
- count: group.all.length,
4081
- read: group.all.filter((path) => isReadIn(group.index, path)).length,
4082
- added: layer?.added ?? 0,
4083
- removed: layer?.removed ?? 0,
4084
- isDone: layer?.isDone ?? false
4085
- });
4086
- /** `21 files · +4.2k −74`, the change in green and red as the diff shows it. */
4087
- var SizeSaid = ({ size }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
4088
- className: "text-xs/4 text-subtle tabular-nums",
4089
- children: [`${String(size.count)} ${size.count === 1 ? "file" : "files"}`, size.count === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
4090
- " · ",
4091
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4092
- className: "text-sign-add",
4093
- children: `+${shortCount(size.added)}`
4094
- }),
4095
- size.removed === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4096
- className: "text-sign-del",
4097
- children: ` −${shortCount(size.removed)}`
4098
- })
4099
- ] })]
4100
- });
4101
- var getMark = ({ group, layer, size }) => {
4102
- if (size.isDone) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Check, {
4103
- "aria-label": "read",
4104
- className: "size-3 text-success in-aria-expanded:max-md:text-accent-foreground",
4105
- strokeWidth: 3
4106
- });
4107
- return layer.isRemainder ? "·" : String(group.index + 1);
4079
+ /** Sets the code's size, keeping the line at the top of the diff where it was. */
4080
+ var resize = (px) => {
4081
+ const kept = findTopRow();
4082
+ showCodeSize(px);
4083
+ if (kept !== null) kept.diff.scrollTop += kept.row.getBoundingClientRect().top - kept.at;
4084
+ setReviewPrefs({ codeSize: px });
4108
4085
  };
4109
- /** A layer's own row: its number and title, then its size, the loudest open comment and how much
4110
- * is read. */
4111
- var LayerRow = (props) => {
4112
- const { layer, size, isOpen, isCursor } = props;
4113
- const threads = layer;
4114
- const { isDone } = size;
4115
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
4116
- "aria-expanded": isOpen,
4117
- "data-pinned": isOpen ? "" : void 0,
4118
- className: cn("flex min-w-0 items-start gap-2 rounded-lg py-1.5 text-start hover:bg-row-hover", "w-full px-2", isOpen && "sticky top-12 z-2 bg-secondary hover:bg-secondary data-stuck:bleed data-stuck:rounded-none data-stuck:shadow-pinned", isCursor && "tree-cursor bg-secondary transition-none hover:bg-secondary"),
4119
- "data-open-row": isOpen ? "" : void 0,
4120
- onClick: props.onPick,
4121
- ref: props.register(props.group.key),
4122
- title: layer.title,
4123
- type: "button",
4124
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4125
- className: cn("grid h-5 w-4.5 shrink-0 place-items-center font-mono text-xs text-subtle tabular-nums", isOpen && "max-md:size-6 max-md:rounded-full max-md:bg-accent max-md:text-accent-foreground"),
4126
- children: getMark(props)
4127
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
4128
- className: "grid min-w-0 flex-1 gap-px",
4129
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4130
- className: cn("text-ui wrap-break-word", isOpen && "max-md:text-base max-md:font-semibold", isOpen || !isDone && isCursor ? "font-medium text-foreground" : "text-muted-foreground", isDone && !isOpen && "text-subtle"),
4131
- children: layer.title
4132
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
4133
- className: "flex items-center gap-1.5",
4134
- children: [
4135
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4136
- className: "flex-1",
4137
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SizeSaid, { size })
4138
- }),
4139
- threads.open > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
4140
- className: "inline-flex items-center gap-0.5",
4141
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(StandMark, {
4142
- said: getMarkSaid(threads),
4143
- stand: threads.stand
4144
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4145
- "aria-hidden": true,
4146
- className: cn("font-mono text-xs tabular-nums", STAND_TONES[threads.stand]),
4147
- children: threads.open
4148
- })]
4149
- }) : null,
4150
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4151
- className: "font-mono text-xs text-subtle tabular-nums",
4152
- children: size.count === 0 ? "—" : `${String(size.read)}/${String(size.count)}`
4153
- }),
4154
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChevronRight, {
4155
- "aria-hidden": true,
4156
- className: "size-3 turn text-subtle"
4157
- })
4158
- ]
4159
- })]
4160
- })]
4161
- });
4086
+ /** A slider for the code's size, between a small and a large A, as a reader's text size is set. */
4087
+ var CodeSizeRow = () => {
4088
+ const { codeSize } = useReviewPrefs();
4089
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", {
4090
+ className: "flex min-h-14 items-center gap-3 px-3.5",
4091
+ children: [
4092
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4093
+ className: "sr-only",
4094
+ children: "Code size"
4095
+ }),
4096
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4097
+ "aria-hidden": true,
4098
+ className: "w-4 text-center text-xs text-muted-foreground",
4099
+ children: "A"
4100
+ }),
4101
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
4102
+ "aria-valuetext": `${String(codeSize)} pixels`,
4103
+ className: "code-size-range min-w-0 flex-1",
4104
+ max: CODE_SIZES.max,
4105
+ min: CODE_SIZES.min,
4106
+ ref: (node) => {
4107
+ const share = (codeSize - CODE_SIZES.min) / (CODE_SIZES.max - CODE_SIZES.min);
4108
+ node?.style.setProperty("--fill", `${String(share * PERCENT$3)}%`);
4109
+ },
4110
+ onChange: (event) => {
4111
+ resize(Number(event.currentTarget.value));
4112
+ },
4113
+ step: 1,
4114
+ type: "range",
4115
+ value: codeSize
4116
+ }),
4117
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4118
+ "aria-hidden": true,
4119
+ className: "w-4 text-center text-lg text-muted-foreground",
4120
+ children: "A"
4121
+ })
4122
+ ]
4123
+ }) });
4162
4124
  };
4163
- /** A name that cuts in the middle, so the end that tells siblings apart stays. */
4164
- var FileName = ({ name }) => name.length <= TAIL ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4165
- className: "name-fit",
4166
- children: name
4167
- }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
4168
- className: "name-fit",
4169
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4170
- className: "name-head",
4171
- children: name.slice(0, -12)
4172
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4173
- className: "shrink-0",
4174
- children: name.slice(-12)
4175
- })]
4176
- });
4177
- /**
4178
- * What a file adds to read in this layer: its part's lines. A part with no changes adds nothing to
4179
- * read, so it shows what kind of file it is (a move, say) rather than "+0".
4180
- */
4181
- var RowSize = ({ file, part }) => file !== void 0 && (part?.added ?? 0) === 0 && (part?.removed ?? 0) === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusMark, { file }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4182
- className: "shrink-0 text-sign-add tabular-nums",
4183
- children: `+${shortCount(part?.added ?? 0)}`
4125
+ /** An iOS switch: a wide track and a pill thumb that slides across. */
4126
+ var Switch = ({ isOn }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4127
+ "aria-hidden": true,
4128
+ className: "relative h-7 w-16 shrink-0 rounded-full bg-foreground/16 transition-colors duration-200 data-on:bg-sign-add",
4129
+ "data-on": isOn ? "" : void 0,
4130
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "absolute inset-s-0.5 top-0.5 h-6 w-9.5 switch-thumb rounded-full bg-white shadow-sm" })
4184
4131
  });
4185
- var FileRow = ({ path, props }) => {
4186
- const key = fileKey(props.group.index, path);
4187
- const isRead = props.isReadIn(props.group.index, path);
4188
- const layer = props.block.layers[props.group.index];
4189
- const threads = getPartMark(layer, path);
4190
- const file = props.files.get(path);
4191
- const since = isRead ? void 0 : props.block.since.find((one) => one.path === path);
4192
- const hasNote = layer !== void 0 && getFileNotes(layer, path).length > 0;
4132
+ var MoreRow = ({ action }) => {
4133
+ const Icon = action.icon;
4134
+ const isToggle = action.isOn !== void 0;
4193
4135
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
4194
- "aria-current": props.cursor === key ? "true" : void 0,
4195
- "aria-label": isRead ? `${getName$1(path)}, read` : void 0,
4196
- className: cn("relative flex h-6 w-full min-w-0 items-center gap-1.5 rounded-md ps-7 pe-2 text-start font-mono text-xs hover:bg-row-hover max-md:h-11 max-md:text-sm", isRead ? "text-muted-foreground" : "text-foreground", props.cursor === key && "tree-cursor bg-secondary transition-none hover:bg-secondary"),
4136
+ "aria-checked": isToggle ? action.isOn : void 0,
4137
+ className: "flex min-h-13 w-full items-center gap-3 px-3.5 py-1.5 text-start text-base/5 text-foreground transition-colors duration-150 active:bg-foreground/8",
4197
4138
  onClick: () => {
4198
- props.onPickFile(key, path);
4139
+ action.onPress();
4199
4140
  },
4200
- ref: props.register(key),
4201
- title: path,
4141
+ role: isToggle ? "switch" : void 0,
4202
4142
  type: "button",
4203
4143
  children: [
4204
- threads.open > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4205
- className: "absolute inset-s-2.5 top-1/2 -translate-y-1/2",
4206
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StandMark, {
4207
- said: getMarkSaid(threads),
4208
- stand: threads.stand
4209
- })
4210
- }) : null,
4211
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FileName, { name: getName$1(path) }),
4212
- hasNote ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(NoteGlyph, { className: "size-3.5 shrink-0 text-subtle" }) : null,
4213
- isRead ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Check, {
4144
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4145
+ className: "grid size-7.5 shrink-0 place-items-center rounded-lg bg-foreground/9",
4146
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Icon, { className: "size-4.5" })
4147
+ }),
4148
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
4149
+ className: "grid min-w-0 flex-1 gap-0.5",
4150
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: action.label }), action.note === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4151
+ className: "text-ui text-muted-foreground",
4152
+ children: action.note
4153
+ })]
4154
+ }),
4155
+ action.value === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4156
+ className: "max-w-32 truncate font-mono text-ui text-muted-foreground",
4157
+ children: action.value
4158
+ }),
4159
+ isToggle ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Switch, { isOn: action.isOn === true }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChevronRight, {
4214
4160
  "aria-hidden": true,
4215
- className: "size-3 shrink-0 text-success",
4216
- strokeWidth: 3
4217
- }) : null,
4218
- since === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SinceMark, { since }),
4219
- isRead || since !== void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RowSize, {
4220
- file,
4221
- part: layer?.parts.find((one) => one.path === path)
4161
+ className: "size-4 shrink-0 text-subtle"
4222
4162
  })
4223
4163
  ]
4224
4164
  }) });
4225
4165
  };
4226
- /** An open layer's files, under the folder each sits in. */
4227
- var LayerFiles = (props) => {
4228
- const rows = props.group.files.map((path, at) => ({
4229
- path,
4230
- folder: getFolder$1(path),
4231
- isNewFolder: at === 0 || getFolder$1(props.group.files[at - 1] ?? "") !== getFolder$1(path)
4232
- }));
4233
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", {
4234
- className: "m-0 list-none ps-1.5 pt-1 pb-1.5 max-md:mx-1 max-md:mt-2 max-md:mb-3 max-md:more-group max-md:py-1 max-md:ps-0",
4235
- children: rows.map(({ path, folder, isNewFolder }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
4236
- className: "contents",
4237
- children: [isNewFolder && folder !== "" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", {
4238
- className: "flex items-center gap-1.5 ps-4 pt-2 pb-0.5 font-mono text-2xs text-subtle",
4239
- title: `${folder}/`,
4240
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Folder, {
4241
- "aria-hidden": true,
4242
- className: "size-3 shrink-0"
4243
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4244
- className: "truncate",
4245
- children: shortenFolder(folder)
4246
- })]
4247
- }) : null, /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FileRow, {
4248
- path,
4249
- props
4250
- })]
4251
- }, path))
4252
- });
4166
+ var MoreGroup = ({ title, actions, extra = null }) => {
4167
+ const shown = actions.filter((action) => action.isShown !== false);
4168
+ return shown.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", {
4169
+ className: "m-0 px-4 pt-3.5 pb-1.5 text-ui font-normal text-muted-foreground",
4170
+ children: title
4171
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("ul", {
4172
+ className: "m-0 list-none more-group p-0",
4173
+ children: [shown.map((action) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MoreRow, { action }, action.id)), extra]
4174
+ })] });
4253
4175
  };
4254
- function DropdownMenu({ ...props }) {
4255
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuRoot, {
4256
- "data-slot": "dropdown-menu",
4257
- ...props
4258
- });
4259
- }
4260
- function DropdownMenuTrigger({ ...props }) {
4261
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuTrigger, {
4262
- "data-slot": "dropdown-menu-trigger",
4263
- ...props
4264
- });
4265
- }
4266
- function DropdownMenuContent({ className, align = "end", sideOffset = 6, ...props }) {
4267
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPortal, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPositioner, {
4268
- align,
4269
- className: "isolate z-50",
4270
- sideOffset,
4271
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPopup, {
4272
- className: cn("min-w-48 pop-menu rounded-lg border border-border bg-popover p-1 text-sm text-popover-foreground shadow-md outline-none", className),
4273
- "data-slot": "dropdown-menu-content",
4274
- ...props
4275
- })
4276
- }) });
4277
- }
4278
- function DropdownMenuItem({ className, ...props }) {
4279
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuItem, {
4280
- className: cn("flex items-center gap-2 rounded-md px-2 py-1.5 transition-colors duration-150 ease-out outline-none select-none data-highlighted:bg-secondary data-highlighted:text-foreground data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:size-4 [&_svg]:shrink-0 [&_svg]:text-muted-foreground", className),
4281
- "data-slot": "dropdown-menu-item",
4282
- ...props
4283
- });
4284
- }
4285
- function DropdownMenuSeparator({ className, ...props }) {
4286
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Separator, {
4287
- className: cn("-mx-1 my-1 h-px bg-border", className),
4288
- "data-slot": "dropdown-menu-separator",
4289
- ...props
4176
+ /** The layers' files in the diff; `isShown` leaves out a layer's files the reader hid, by layer. */
4177
+ var getLayerGroups = (layers, { present, isShown }) => {
4178
+ const here = new Set(present);
4179
+ return layers.map((layer, index) => {
4180
+ const all = layer.files.filter((path) => here.has(path));
4181
+ return {
4182
+ kind: "layer",
4183
+ key: layerKey(index),
4184
+ index,
4185
+ address: layer.address,
4186
+ ticket: layer.ticket,
4187
+ title: layer.title,
4188
+ all,
4189
+ files: all.filter((path) => isShown(index, path))
4190
+ };
4290
4191
  });
4291
- }
4292
- function DropdownMenuShortcut({ className, ...props }) {
4293
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4294
- className: cn("ms-auto text-xs text-subtle", className),
4295
- "data-slot": "dropdown-menu-shortcut",
4296
- ...props
4192
+ };
4193
+ /**
4194
+ * The reading order's numbered entries: a ticket stands where its first sublayer does, and holds
4195
+ * every sublayer adiff numbers under it. A ticket adiff does not list leaves its sublayers as plain
4196
+ * layers, so the rail never walks into a row it cannot draw.
4197
+ */
4198
+ var getRailEntries = (groups, tickets) => {
4199
+ const entries = [];
4200
+ groups.forEach((group) => {
4201
+ const { ticket } = group;
4202
+ const held = entries.find((entry) => entry.kind === "ticket" && entry.number === ticket);
4203
+ const named = tickets.find((one) => one.number === ticket);
4204
+ if (ticket === null || named === void 0) entries.push(group);
4205
+ else if (held?.kind === "ticket") held.groups.push(group);
4206
+ else entries.push({
4207
+ kind: "ticket",
4208
+ key: ticketKey(ticket),
4209
+ number: ticket,
4210
+ title: named.title,
4211
+ groups: [group]
4212
+ });
4297
4213
  });
4298
- }
4299
- /** Puts text on the clipboard and says so in a toast. */
4300
- var useCopy = () => {
4301
- const toast = useToast();
4302
- return async (text, title) => {
4303
- await navigator.clipboard.writeText(text);
4304
- toast.add({ title });
4214
+ return entries;
4215
+ };
4216
+ /** The layers an entry holds: a plain layer itself, a ticket its sublayers. */
4217
+ var getEntryGroups = (entry) => entry.kind === "ticket" ? entry.groups : [entry];
4218
+ var getGroupRows = (group, { depth, isOpen }) => [{
4219
+ kind: "dir",
4220
+ key: group.key,
4221
+ label: group.title,
4222
+ full: group.key,
4223
+ depth
4224
+ }, ...isOpen(group) ? group.files.map((path) => ({
4225
+ kind: "file",
4226
+ key: fileKey(group.index, path),
4227
+ path,
4228
+ label: getName$1(path),
4229
+ depth: depth + 1
4230
+ })) : []];
4231
+ var getLayerRows$1 = (entries, isOpen) => entries.flatMap((entry) => entry.kind === "layer" ? getGroupRows(entry, {
4232
+ depth: 0,
4233
+ isOpen
4234
+ }) : [{
4235
+ kind: "dir",
4236
+ key: entry.key,
4237
+ label: entry.title,
4238
+ full: entry.key,
4239
+ depth: 0
4240
+ }, ...isOpen(entry) ? entry.groups.flatMap((group) => getGroupRows(group, {
4241
+ depth: 1,
4242
+ isOpen
4243
+ })) : []]);
4244
+ var getLayerOrder = (entries) => entries.flatMap((entry) => getEntryGroups(entry).flatMap((group) => group.files.map((path) => fileKey(group.index, path))));
4245
+ /**
4246
+ * The layers rail with the read entries folded into one row at the top, so it starts at the work
4247
+ * left. Unfolded, the read entries follow that row; the rest keep the agent's order either way. A
4248
+ * ticket folds away only once every sublayer is read: a read sublayer keeps its place.
4249
+ */
4250
+ var foldReadLayers = (entries, { isDone, isOpen, isReadOpen }) => {
4251
+ const done = entries.filter((entry) => isDone(entry));
4252
+ const rest = entries.filter((entry) => !isDone(entry));
4253
+ if (done.length === 0) return {
4254
+ rows: getLayerRows$1(entries, isOpen),
4255
+ order: getLayerOrder(entries),
4256
+ done,
4257
+ rest
4258
+ };
4259
+ const head = {
4260
+ kind: "dir",
4261
+ key: READ_LAYERS,
4262
+ label: `${String(done.length)} ${done.length === 1 ? "layer" : "layers"} read`,
4263
+ full: READ_LAYERS,
4264
+ depth: 0
4265
+ };
4266
+ const shown = isReadOpen ? [...done, ...rest] : rest;
4267
+ return {
4268
+ rows: [head, ...getLayerRows$1(shown, isOpen)],
4269
+ order: getLayerOrder(shown),
4270
+ done,
4271
+ rest
4272
+ };
4273
+ };
4274
+ /** A sentence ends at ". " before a capital. */
4275
+ var BREAK = /(?<=\.)\s+(?=[A-Z`?@(])/u;
4276
+ var LIST_MARK = /^[-•·*]\s+/u;
4277
+ var BOLD = /\*\*(?<words>[^*]+)\*\*/gu;
4278
+ /** Where a reading instruction starts: the line a reader acts on rather than learns from. */
4279
+ var HOW_TO = /^Read\b/u;
4280
+ var unbold = (text) => text.replaceAll(BOLD, "$<words>");
4281
+ /** A note's lines: the ones its writer broke, or else its sentences and clauses. */
4282
+ var getLines$1 = (note) => (note.includes("\n") ? note.split("\n") : note.split(BREAK)).map((line) => unbold(line.trim().replace(LIST_MARK, ""))).filter((line) => line !== "");
4283
+ /** A note read as an intro: its first line leads, the lines that say how to read it go apart. */
4284
+ var toIntro = (markdown, path) => {
4285
+ const [lead, ...rest] = getLines$1(markdown);
4286
+ return lead === void 0 ? null : {
4287
+ lead,
4288
+ points: rest.filter((line) => !HOW_TO.test(line)),
4289
+ howTo: rest.filter((line) => HOW_TO.test(line)),
4290
+ path
4305
4291
  };
4306
4292
  };
4293
+ /** The layer's intro: the first piece of its note, read over the file adiff places it at. */
4294
+ var getIntro = (layer) => {
4295
+ const [first] = layer.prose;
4296
+ return first === void 0 ? null : toIntro(first.markdown, first.path);
4297
+ };
4298
+ /** The pieces after the intro that adiff places in this file, in the order of their lines. */
4299
+ var getFileNotes = (layer, path) => layer.prose.slice(1).filter((piece) => piece.path === path).toSorted((one, other) => one.line - other.line || Number(one.after) - Number(other.after));
4300
+ /**
4301
+ * Names from code inside prose: `backticks`, camelCase and PascalCase words, `?query=`,
4302
+ * `@Decorator`, HTTP verbs, paths and file names. Each is set in mono so the eye can find it.
4303
+ */
4304
+ var CODE_WORD = /(?<code>`[^`]+`|\?\w+=|@[A-Z]\w+|\b(?:GET|POST|PUT|PATCH|DELETE)\b|\b[a-z]+[A-Z]\w*|\b[A-Z][a-z\d]+[A-Z]\w*|(?:[\w.:-]*\/)+[\w.:-]+|\b[\w-]+\.(?:ts|tsx|js|json|md|ya?ml)\b)/u;
4305
+ /** Splitting on a captured pattern puts every match at an odd index. */
4306
+ var EVERY_OTHER = 2;
4307
+ /** Prose with its names from code in mono; `isChipped` sets them on a tint, as a note over code. */
4308
+ var Words = ({ text, isChipped = false }) => text.split(CODE_WORD).map((part, at) => at % EVERY_OTHER === 1 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", {
4309
+ className: isChipped ? "note-code" : "font-mono text-foreground",
4310
+ children: part.replaceAll("`", "")
4311
+ }, `${String(at)}:${part}`) : part);
4312
+ /** A file has a note of its own: three lines of text, not a speech bubble, which means comments. */
4313
+ var NoteGlyph = ({ className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", {
4314
+ "aria-hidden": true,
4315
+ className,
4316
+ fill: "none",
4317
+ stroke: "currentColor",
4318
+ strokeLinecap: "round",
4319
+ strokeWidth: 1.3,
4320
+ viewBox: "0 0 14 14",
4321
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M3 4h8M3 7h8M3 10h5" })
4322
+ });
4307
4323
  /**
4308
- * Stops the headless run and hands its session to the reviewer's terminal: the command that
4309
- * resumes it, told to carry on, goes on the clipboard first, while the click still counts as the
4310
- * reviewer's, then the run stops.
4324
+ * The open layer's lead in the rail: the intro's first sentence only. The rest of the intro opens
4325
+ * over the layer's first file, where it is read; a click goes there. A ticket's part sets its lead
4326
+ * under the part's title.
4311
4327
  */
4312
- var takeOver = async ({ model, copy }) => {
4313
- const { listener, branch } = model;
4314
- const run = listener?.run ?? null;
4315
- const worktree = listener?.worktree ?? null;
4316
- const agent = listener?.agents.find((each) => each.label === run?.agent) ?? null;
4317
- if (worktree === null || run === null || agent === null) return;
4318
- await copy(getResumeCommand({
4319
- resume: run.resume,
4320
- interactive: agent.interactive,
4321
- worktree,
4322
- branch
4323
- }), "Resume command copied · paste it in a terminal");
4324
- await model.handleStop();
4328
+ var LayerLead = ({ intro, isPart = false, isIntroShown, onOpenIntro }) => intro === null ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
4329
+ className: cn("mt-0.5 mb-1 grid w-full gap-0.5 rounded-md py-1.5 pe-2 text-start text-ui text-muted-foreground hover:bg-row-hover hover:text-foreground max-md:text-sm", isPart ? "ps-10.5" : "ps-8"),
4330
+ onClick: onOpenIntro,
4331
+ type: "button",
4332
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Words, { text: intro.lead }) }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4333
+ className: "text-xs text-subtle",
4334
+ children: isIntroShown ? "Intro is open" : "Read the intro"
4335
+ })]
4336
+ });
4337
+ var lines = (count) => `${String(count)} ${count === 1 ? "line" : "lines"}`;
4338
+ var places = (count) => `${String(count)} ${count === 1 ? "place" : "places"}`;
4339
+ /** "9 lines in 2 places since you reviewed it, 2h ago", or less when adiff knows less. */
4340
+ var getSinceSaid = (since, now) => {
4341
+ const ago = since.at === "" ? "" : `, ${getRelativeTime(since.at, now)} ago`;
4342
+ if (since.deleted) return `Deleted since you reviewed it${ago}`;
4343
+ return since.kept ? `${lines(since.added + since.removed)} in ${places(since.places)} since you reviewed it${ago}` : `Changed since you reviewed it${ago}`;
4325
4344
  };
4326
- /** The agent menu's way to take a running headless agent over, first in the menu while it runs. */
4327
- var TakeOverItem = ({ model, copy }) => model.listener?.run?.state === "running" && model.listener.worktree !== null ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenuItem, {
4328
- disabled: model.isBusy,
4329
- onClick: () => {
4330
- takeOver({
4331
- model,
4332
- copy
4333
- });
4334
- },
4335
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SquareTerminal, {}), "Take over in your terminal"]
4336
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DropdownMenuSeparator, {})] }) : null;
4337
- var getChosen = (listener) => listener.agents.find((agent) => agent.id === listener.chosen) ?? null;
4338
- /**
4339
- * Every way to bring an agent to this review: start another installed one headless, paste a
4340
- * prompt into an agent already open, or paste a command that opens the chosen one in a terminal.
4341
- */
4342
- var AgentMenu = ({ model, isHeard, onSettings }) => {
4343
- const copy = useCopy();
4344
- const { listener, isBusy, branch } = model;
4345
- if (listener === null) return null;
4346
- const chosen = getChosen(listener);
4347
- const others = listener.agents.filter((agent) => agent.isInstalled && agent.id !== chosen?.id);
4348
- const { worktree } = listener;
4349
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenu, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(DropdownMenuTrigger, { render: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$1, {
4350
- "aria-label": "Agent options",
4351
- size: "icon-xs",
4352
- variant: "ghost",
4353
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChevronDown, {})
4354
- }) }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenuContent, { children: [
4355
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TakeOverItem, {
4356
- copy,
4357
- model
4358
- }),
4359
- isHeard ? null : others.map((agent) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenuItem, {
4360
- disabled: isBusy || worktree === null,
4361
- onClick: () => void model.handleStart(agent.id),
4362
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Play, {}), `Start a headless ${agent.label}`]
4363
- }, agent.id)),
4364
- isHeard || others.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DropdownMenuSeparator, {}),
4365
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenuItem, {
4366
- disabled: worktree === null,
4367
- onClick: () => {
4368
- if (worktree !== null) copy(getConnectPrompt(worktree, branch), "Prompt copied: paste it to your agent");
4369
- },
4370
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ClipboardCopy, {}), "Copy a prompt for your agent"]
4345
+ /** A check inside a turning arrow: read before, look again. */
4346
+ var SinceGlyph = () => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", {
4347
+ "aria-hidden": true,
4348
+ className: "size-3",
4349
+ fill: "none",
4350
+ viewBox: "0 0 12 12",
4351
+ children: [
4352
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", {
4353
+ d: "M10.4 4.2A4.9 4.9 0 1 0 10.9 7.6",
4354
+ stroke: "currentColor",
4355
+ strokeLinecap: "round",
4356
+ strokeWidth: "1.3"
4371
4357
  }),
4372
- chosen === null ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenuItem, {
4373
- disabled: worktree === null,
4374
- onClick: () => {
4375
- if (worktree !== null) copy(getTerminalCommand(chosen.interactive, worktree, branch), `Command copied: paste it in a terminal to open ${chosen.label}`);
4376
- },
4377
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SquareTerminal, {}), `Copy a terminal command for ${chosen.label}`]
4358
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", {
4359
+ d: "M10.9 1.6 10.6 4.5 7.8 4.1",
4360
+ stroke: "currentColor",
4361
+ strokeLinecap: "round",
4362
+ strokeLinejoin: "round",
4363
+ strokeWidth: "1.3"
4378
4364
  }),
4379
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DropdownMenuSeparator, {}),
4380
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenuItem, {
4381
- onClick: onSettings,
4382
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Settings, {}), "Agent settings…"]
4365
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", {
4366
+ d: "M3.9 6.2 5.4 7.7 8 4.9",
4367
+ stroke: "currentColor",
4368
+ strokeLinecap: "round",
4369
+ strokeLinejoin: "round",
4370
+ strokeWidth: "1.4"
4383
4371
  })
4384
- ] })] });
4372
+ ]
4373
+ });
4374
+ /** A file reviewed, then changed: it reads as unreviewed, with this mark where the check was. */
4375
+ var SinceMark = ({ since }) => {
4376
+ const now = useNow();
4377
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Tooltip$1, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TooltipTrigger, {
4378
+ render: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "inline-flex text-muted-foreground" }),
4379
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SinceGlyph, {}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4380
+ className: "sr-only",
4381
+ children: "Changed since review"
4382
+ })]
4383
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipContent, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
4384
+ className: "grid gap-0.5",
4385
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4386
+ className: "font-medium",
4387
+ children: "Changed since review"
4388
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: getSinceSaid(since, now) })]
4389
+ }) })] });
4385
4390
  };
4386
- /** The agent's actions: start one when nobody answers, or take the running one over. */
4387
- var useAgentActions = (props) => {
4388
- const copy = useCopy();
4389
- const model = props.listener;
4390
- const { listener } = model;
4391
- const worktree = listener?.worktree ?? null;
4392
- if (listener === null || worktree === null) return [];
4393
- const chosen = getChosen(listener);
4394
- const isRunning = listener.run?.state === "running";
4395
- return [
4396
- {
4397
- id: "start",
4398
- icon: Sparkles,
4399
- label: `Start ${chosen?.label ?? "an agent"}`,
4400
- note: "It reads your comments and answers them in the background",
4401
- isShown: !isRunning && !listener.isListening && chosen !== null,
4402
- onPress: () => {
4403
- if (chosen !== null) model.handleStart(chosen.id);
4404
- }
4405
- },
4406
- {
4407
- id: "take-over",
4408
- icon: SquareTerminal,
4409
- label: "Take over in your terminal",
4410
- note: "Copies a command that resumes its session, and stops it here",
4411
- isShown: isRunning,
4412
- onPress: () => {
4413
- takeOver({
4414
- model,
4415
- copy
4416
- });
4417
- }
4418
- },
4419
- {
4420
- id: "stop",
4421
- icon: Square,
4422
- label: `Stop ${listener.run?.agent ?? "the agent"}`,
4423
- isShown: isRunning,
4424
- onPress: () => {
4425
- model.handleStop();
4426
- }
4427
- },
4428
- {
4429
- id: "terminal",
4430
- icon: SquareTerminal,
4431
- label: "Copy a terminal command",
4432
- note: `Opens ${chosen?.label ?? "the agent"} in this worktree, already listening`,
4433
- isShown: !isRunning && chosen !== null,
4434
- onPress: () => {
4435
- if (chosen !== null) copy(getTerminalCommand(chosen.interactive, worktree, model.branch), "Command copied · paste it in a terminal");
4436
- }
4437
- }
4438
- ];
4391
+ var STATUS_MARKS = {
4392
+ added: {
4393
+ Icon: Plus,
4394
+ label: () => "New file",
4395
+ tone: "text-sign-add"
4396
+ },
4397
+ deleted: {
4398
+ Icon: Minus,
4399
+ label: () => "Deleted file",
4400
+ tone: "text-sign-del"
4401
+ },
4402
+ renamed: {
4403
+ Icon: ArrowRight,
4404
+ label: (from) => `Renamed from ${from}`,
4405
+ tone: "text-subtle"
4406
+ },
4407
+ copied: {
4408
+ Icon: Copy,
4409
+ label: (from) => `Copied from ${from}`,
4410
+ tone: "text-subtle"
4411
+ }
4439
4412
  };
4440
- var DIFF$1 = "[data-review-diff]";
4441
- var ROW$1 = "[data-review-row]";
4442
- var PERCENT$3 = 100;
4443
- /** The first row of the diff in view, and where it is, so a new size can leave it there. */
4444
- var findTopRow = () => {
4445
- const diff = document.querySelector(DIFF$1);
4446
- if (diff === null) return null;
4447
- const { top } = diff.getBoundingClientRect();
4448
- const row = [...diff.querySelectorAll(ROW$1)].find((one) => one.getBoundingClientRect().bottom > top);
4449
- return row === void 0 ? null : {
4450
- diff,
4451
- row,
4452
- at: row.getBoundingClientRect().top
4453
- };
4413
+ var StatusMark = ({ file }) => {
4414
+ if (file.status === "modified") return null;
4415
+ const { Icon, label, tone } = STATUS_MARKS[file.status];
4416
+ const said = label(file.previousPath);
4417
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Tooltip$1, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TooltipTrigger, {
4418
+ render: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: cn("inline-flex shrink-0", tone) }),
4419
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Icon, {
4420
+ "aria-hidden": true,
4421
+ className: "size-3"
4422
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4423
+ className: "sr-only",
4424
+ children: said
4425
+ })]
4426
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipContent, { children: said })] });
4454
4427
  };
4455
- /** Sets the code's size, keeping the line at the top of the diff where it was. */
4456
- var resize = (px) => {
4457
- const kept = findTopRow();
4458
- showCodeSize(px);
4459
- if (kept !== null) kept.diff.scrollTop += kept.row.getBoundingClientRect().top - kept.at;
4460
- setReviewPrefs({ codeSize: px });
4428
+ var KIND_MARKS = [{
4429
+ short: "bin",
4430
+ label: "Binary file",
4431
+ isOn: (file) => file.isBinary
4432
+ }, {
4433
+ short: "gen",
4434
+ label: "Generated file",
4435
+ isOn: (file) => file.isGenerated
4436
+ }];
4437
+ var KindMarks = ({ file }) => KIND_MARKS.filter((mark) => mark.isOn(file)).map((mark) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Tooltip$1, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipTrigger, {
4438
+ render: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "shrink-0 text-subtle" }),
4439
+ children: mark.short
4440
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipContent, { children: mark.label })] }, mark.short));
4441
+ var TAIL = 12;
4442
+ /** The line counts and whether the layer is read come from adiff, which counts each layer's own
4443
+ * spans; only the read count leans on marks still on their way. */
4444
+ var getLayerSize = (group, layer, isReadIn) => ({
4445
+ count: group.all.length,
4446
+ read: group.all.filter((path) => isReadIn(group.index, path)).length,
4447
+ added: layer?.added ?? 0,
4448
+ removed: layer?.removed ?? 0,
4449
+ isDone: layer?.isDone ?? false
4450
+ });
4451
+ /** `21 files · +4.2k −74`, the change in green and red as the diff shows it. */
4452
+ var SizeSaid = ({ size }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
4453
+ className: "text-xs/4 text-subtle tabular-nums",
4454
+ children: [`${String(size.count)} ${size.count === 1 ? "file" : "files"}`, size.count === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
4455
+ " · ",
4456
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4457
+ className: "text-sign-add",
4458
+ children: `+${shortCount(size.added)}`
4459
+ }),
4460
+ size.removed === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4461
+ className: "text-sign-del",
4462
+ children: ` −${shortCount(size.removed)}`
4463
+ })
4464
+ ] })]
4465
+ });
4466
+ var ReadCheck = () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Check, {
4467
+ "aria-label": "read",
4468
+ className: "size-3 text-success in-aria-expanded:max-md:text-accent-foreground",
4469
+ strokeWidth: 3
4470
+ });
4471
+ /** A read layer shows a check; else its number as adiff gives it (`3`, a part's `2.2`). */
4472
+ var getMark = ({ layer, size }) => {
4473
+ if (size.isDone) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReadCheck, {});
4474
+ return layer.isRemainder ? "·" : layer.address;
4461
4475
  };
4462
- /** A slider for the code's size, between a small and a large A, as a reader's text size is set. */
4463
- var CodeSizeRow = () => {
4464
- const { codeSize } = useReviewPrefs();
4465
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", {
4466
- className: "flex min-h-14 items-center gap-3 px-3.5",
4467
- children: [
4468
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4469
- className: "sr-only",
4470
- children: "Code size"
4471
- }),
4472
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4473
- "aria-hidden": true,
4474
- className: "w-4 text-center text-xs text-muted-foreground",
4475
- children: "A"
4476
- }),
4477
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
4478
- "aria-valuetext": `${String(codeSize)} pixels`,
4479
- className: "code-size-range min-w-0 flex-1",
4480
- max: CODE_SIZES.max,
4481
- min: CODE_SIZES.min,
4482
- ref: (node) => {
4483
- const share = (codeSize - CODE_SIZES.min) / (CODE_SIZES.max - CODE_SIZES.min);
4484
- node?.style.setProperty("--fill", `${String(share * PERCENT$3)}%`);
4485
- },
4486
- onChange: (event) => {
4487
- resize(Number(event.currentTarget.value));
4488
- },
4489
- step: 1,
4490
- type: "range",
4491
- value: codeSize
4492
- }),
4493
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4494
- "aria-hidden": true,
4495
- className: "w-4 text-center text-lg text-muted-foreground",
4496
- children: "A"
4497
- })
4498
- ]
4499
- }) });
4476
+ /**
4477
+ * A layer's own row: its number and title, then its size, the loudest open comment and how much
4478
+ * is read. A ticket's part sits under the ticket's title, with its `2.2` in a wider column, and
4479
+ * the cursor is the wash alone, as a tick has no room inside the indented row.
4480
+ */
4481
+ var LayerRow = (props) => {
4482
+ const { layer, size, isOpen, isCursor } = props;
4483
+ const isPart = layer.ticket !== null;
4484
+ const { isDone } = size;
4485
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
4486
+ "aria-expanded": isOpen,
4487
+ "data-pinned": isOpen ? "" : void 0,
4488
+ className: cn("flex min-w-0 items-start gap-2 rounded-lg py-1.5 text-start hover:bg-row-hover", "w-full px-2", isOpen && "sticky top-12 z-2 bg-secondary hover:bg-secondary data-stuck:rounded-none data-stuck:shadow-pinned", isOpen && (isPart ? "data-stuck:bleed-part" : "data-stuck:bleed"), isCursor && "bg-secondary transition-none hover:bg-secondary", isCursor && !isPart && "tree-cursor"),
4489
+ "data-open-row": isOpen ? "" : void 0,
4490
+ onClick: props.onPick,
4491
+ ref: props.register(props.group.key),
4492
+ title: layer.title,
4493
+ type: "button",
4494
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4495
+ className: cn("grid h-5 shrink-0 items-center font-mono text-xs text-subtle tabular-nums", isPart ? "w-6.5 justify-items-start" : "w-4.5 justify-items-center", isOpen && "max-md:rounded-full max-md:bg-accent max-md:text-accent-foreground", isOpen && (isPart ? "max-md:h-5.5 max-md:justify-items-center max-md:text-2xs" : "max-md:size-6")),
4496
+ children: getMark(props)
4497
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
4498
+ className: "grid min-w-0 flex-1 gap-px",
4499
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4500
+ className: cn("text-ui wrap-break-word", isOpen && "max-md:text-base max-md:font-semibold", isOpen || !isDone && isCursor ? "font-medium text-foreground" : "text-muted-foreground", isDone && !isOpen && "text-subtle"),
4501
+ children: layer.title
4502
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
4503
+ className: "flex items-center gap-1.5",
4504
+ children: [
4505
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4506
+ className: "flex-1",
4507
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SizeSaid, { size })
4508
+ }),
4509
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(OpenMark, { threads: layer }),
4510
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4511
+ className: "font-mono text-xs text-subtle tabular-nums",
4512
+ children: size.count === 0 ? "—" : `${String(size.read)}/${String(size.count)}`
4513
+ }),
4514
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChevronRight, {
4515
+ "aria-hidden": true,
4516
+ className: "size-3 turn text-subtle"
4517
+ })
4518
+ ]
4519
+ })]
4520
+ })]
4521
+ });
4500
4522
  };
4501
- /** An iOS switch: a wide track and a pill thumb that slides across. */
4502
- var Switch = ({ isOn }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4503
- "aria-hidden": true,
4504
- className: "relative h-7 w-16 shrink-0 rounded-full bg-foreground/16 transition-colors duration-200 data-on:bg-sign-add",
4505
- "data-on": isOn ? "" : void 0,
4506
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "absolute inset-s-0.5 top-0.5 h-6 w-9.5 switch-thumb rounded-full bg-white shadow-sm" })
4523
+ /** A name that cuts in the middle, so the end that tells siblings apart stays. */
4524
+ var FileName = ({ name }) => name.length <= TAIL ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4525
+ className: "name-fit",
4526
+ children: name
4527
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
4528
+ className: "name-fit",
4529
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4530
+ className: "name-head",
4531
+ children: name.slice(0, -12)
4532
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4533
+ className: "shrink-0",
4534
+ children: name.slice(-12)
4535
+ })]
4507
4536
  });
4508
- var MoreRow = ({ action }) => {
4509
- const Icon = action.icon;
4510
- const isToggle = action.isOn !== void 0;
4537
+ /**
4538
+ * What a file adds to read in this layer: its part's lines. A part with no changes adds nothing to
4539
+ * read, so it shows what kind of file it is (a move, say) rather than "+0".
4540
+ */
4541
+ var RowSize = ({ file, part }) => file !== void 0 && (part?.added ?? 0) === 0 && (part?.removed ?? 0) === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusMark, { file }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4542
+ className: "shrink-0 text-sign-add tabular-nums",
4543
+ children: `+${shortCount(part?.added ?? 0)}`
4544
+ });
4545
+ var FileRow = ({ path, props }) => {
4546
+ const key = fileKey(props.group.index, path);
4547
+ const isRead = props.isReadIn(props.group.index, path);
4548
+ const layer = props.block.layers[props.group.index];
4549
+ const threads = getPartMark(layer, path);
4550
+ const file = props.files.get(path);
4551
+ const since = isRead ? void 0 : props.block.since.find((one) => one.path === path);
4552
+ const hasNote = layer !== void 0 && getFileNotes(layer, path).length > 0;
4553
+ const isCursor = props.cursor === key;
4511
4554
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
4512
- "aria-checked": isToggle ? action.isOn : void 0,
4513
- className: "flex min-h-13 w-full items-center gap-3 px-3.5 py-1.5 text-start text-base/5 text-foreground transition-colors duration-150 active:bg-foreground/8",
4555
+ "aria-current": isCursor ? "true" : void 0,
4556
+ "aria-label": isRead ? `${getName$1(path)}, read` : void 0,
4557
+ className: cn("relative flex h-6 w-full min-w-0 items-center gap-1.5 rounded-md ps-7 pe-2 text-start font-mono text-xs hover:bg-row-hover max-md:h-11 max-md:text-sm", isRead ? "text-muted-foreground" : "text-foreground", isCursor && "bg-secondary transition-none hover:bg-secondary", isCursor && (layer?.ticket ?? null) === null && "tree-cursor"),
4514
4558
  onClick: () => {
4515
- action.onPress();
4559
+ props.onPickFile(key, path);
4516
4560
  },
4517
- role: isToggle ? "switch" : void 0,
4561
+ ref: props.register(key),
4562
+ title: path,
4518
4563
  type: "button",
4519
4564
  children: [
4520
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4521
- className: "grid size-7.5 shrink-0 place-items-center rounded-lg bg-foreground/9",
4522
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Icon, { className: "size-4.5" })
4523
- }),
4524
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
4525
- className: "grid min-w-0 flex-1 gap-0.5",
4526
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: action.label }), action.note === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4527
- className: "text-ui text-muted-foreground",
4528
- children: action.note
4529
- })]
4530
- }),
4531
- action.value === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4532
- className: "max-w-32 truncate font-mono text-ui text-muted-foreground",
4533
- children: action.value
4534
- }),
4535
- isToggle ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Switch, { isOn: action.isOn === true }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChevronRight, {
4565
+ threads.open > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4566
+ className: "absolute inset-s-2.5 top-1/2 -translate-y-1/2",
4567
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StandMark, {
4568
+ said: getMarkSaid(threads),
4569
+ stand: threads.stand
4570
+ })
4571
+ }) : null,
4572
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FileName, { name: getName$1(path) }),
4573
+ hasNote ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(NoteGlyph, { className: "size-3.5 shrink-0 text-subtle" }) : null,
4574
+ isRead ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Check, {
4536
4575
  "aria-hidden": true,
4537
- className: "size-4 shrink-0 text-subtle"
4576
+ className: "size-3 shrink-0 text-success",
4577
+ strokeWidth: 3
4578
+ }) : null,
4579
+ since === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SinceMark, { since }),
4580
+ isRead || since !== void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RowSize, {
4581
+ file,
4582
+ part: layer?.parts.find((one) => one.path === path)
4538
4583
  })
4539
4584
  ]
4540
4585
  }) });
4541
4586
  };
4542
- var MoreGroup = ({ title, actions, extra = null }) => {
4543
- const shown = actions.filter((action) => action.isShown !== false);
4544
- return shown.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", {
4545
- className: "m-0 px-4 pt-3.5 pb-1.5 text-ui font-normal text-muted-foreground",
4546
- children: title
4547
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("ul", {
4548
- className: "m-0 list-none more-group p-0",
4549
- children: [shown.map((action) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MoreRow, { action }, action.id)), extra]
4550
- })] });
4587
+ /**
4588
+ * An open layer's files, under the folder each sits in. A ticket's part sets them further in, so
4589
+ * the names start under the part's title, as a plain layer's start under its own.
4590
+ */
4591
+ var LayerFiles = (props) => {
4592
+ const isPart = (props.block.layers[props.group.index]?.ticket ?? null) !== null;
4593
+ const rows = props.group.files.map((path, at) => ({
4594
+ path,
4595
+ folder: getFolder$1(path),
4596
+ isNewFolder: at === 0 || getFolder$1(props.group.files[at - 1] ?? "") !== getFolder$1(path)
4597
+ }));
4598
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", {
4599
+ className: cn("m-0 list-none pt-1 pb-1.5 max-md:mt-2 max-md:mb-3 max-md:more-group max-md:py-1 max-md:ps-0", isPart ? "ps-3.5 max-md:ms-3 max-md:me-1" : "ps-1.5 max-md:mx-1"),
4600
+ children: rows.map(({ path, folder, isNewFolder }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
4601
+ className: "contents",
4602
+ children: [isNewFolder && folder !== "" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", {
4603
+ className: "flex items-center gap-1.5 ps-4 pt-2 pb-0.5 font-mono text-2xs text-subtle",
4604
+ title: `${folder}/`,
4605
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Folder, {
4606
+ "aria-hidden": true,
4607
+ className: "size-3 shrink-0"
4608
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4609
+ className: "truncate",
4610
+ children: shortenFolder(folder)
4611
+ })]
4612
+ }) : null, /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FileRow, {
4613
+ path,
4614
+ props
4615
+ })]
4616
+ }, path))
4617
+ });
4618
+ };
4619
+ /** A ticket's size as adiff rolls it up: every file its parts name, once, and their lines. */
4620
+ var getTicketSize = (ticket) => ({
4621
+ count: ticket.files.length,
4622
+ added: ticket.added,
4623
+ removed: ticket.removed
4624
+ });
4625
+ /**
4626
+ * A ticket's own row: its number and title, its size, and how many of its parts are read. Closed,
4627
+ * it shows the loudest open comment its parts hold; open, its parts below show their own, so it
4628
+ * says nothing about them. The ticket never pins: the part being read does.
4629
+ */
4630
+ var TicketRow = ({ rowKey, ticket, isOpen, isCursor, onPick, register }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
4631
+ "aria-expanded": isOpen,
4632
+ className: cn("flex w-full min-w-0 items-start gap-2 rounded-lg px-2 py-1.5 text-start hover:bg-row-hover", isCursor && "bg-secondary transition-none hover:bg-secondary"),
4633
+ onClick: onPick,
4634
+ ref: register(rowKey),
4635
+ title: ticket.title,
4636
+ type: "button",
4637
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4638
+ className: "grid h-5 w-4.5 shrink-0 place-items-center font-mono text-xs text-subtle tabular-nums",
4639
+ children: ticket.isDone ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Check, {
4640
+ "aria-label": "read",
4641
+ className: "size-3 text-success",
4642
+ strokeWidth: 3
4643
+ }) : ticket.address
4644
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
4645
+ className: "grid min-w-0 flex-1 gap-px",
4646
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4647
+ className: cn("text-ui wrap-break-word", isOpen || isCursor ? "text-foreground" : "text-muted-foreground", isCursor && "font-medium", ticket.isDone && !isOpen && !isCursor && "text-subtle"),
4648
+ children: ticket.title
4649
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
4650
+ className: "flex items-center gap-1.5",
4651
+ children: [
4652
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4653
+ className: "flex-1",
4654
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SizeSaid, { size: getTicketSize(ticket) })
4655
+ }),
4656
+ isOpen ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(OpenMark, { threads: ticket }),
4657
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
4658
+ className: "font-mono text-xs text-subtle tabular-nums",
4659
+ children: [`${String(ticket.sublayersDone)}/${String(ticket.sublayers)}`, /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4660
+ className: "font-sans",
4661
+ children: " parts"
4662
+ })]
4663
+ }),
4664
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChevronRight, {
4665
+ "aria-hidden": true,
4666
+ className: "size-3 turn text-subtle"
4667
+ })
4668
+ ]
4669
+ })]
4670
+ })]
4671
+ });
4672
+ var Row$1 = ({ row, onPick }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
4673
+ className: cn("flex min-h-14 w-full items-center gap-2.5 py-1.5 pe-3.5 text-start transition-colors duration-150 active:bg-foreground/8", row.isPart ? "ps-10" : "ps-3.5"),
4674
+ onClick: () => {
4675
+ onPick(row.key);
4676
+ },
4677
+ type: "button",
4678
+ children: [
4679
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4680
+ className: cn("grid h-6 shrink-0 place-items-center rounded-full font-mono", row.isPart ? "w-7.5 text-xs" : "w-6 text-sm", row.isHere ? "bg-accent text-accent-foreground" : "text-subtle"),
4681
+ children: row.isRead && !row.isHere ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Check, {
4682
+ "aria-label": "read",
4683
+ className: "size-3.5 text-success",
4684
+ strokeWidth: 3
4685
+ }) : row.number
4686
+ }),
4687
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
4688
+ className: "grid min-w-0 flex-1 gap-0.5",
4689
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4690
+ className: "text-base/5",
4691
+ children: row.title
4692
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SizeSaid, { size: row.size })]
4693
+ }),
4694
+ row.threads.open > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StandMark, {
4695
+ said: getMarkSaid(row.threads),
4696
+ stand: row.threads.stand
4697
+ }) : null,
4698
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4699
+ className: "shrink-0 font-mono text-sm text-subtle tabular-nums",
4700
+ children: row.count
4701
+ })
4702
+ ]
4703
+ }) });
4704
+ /**
4705
+ * Every layer on one sheet, for a phone that cannot see the whole rail: tap one to open it. A
4706
+ * ticket lists its parts under it; the ticket's own row counts its parts read and, always open
4707
+ * here, leaves the comment marks to its parts.
4708
+ */
4709
+ var LayersSheet = ({ props }) => {
4710
+ const { model, block } = props;
4711
+ const cursorTicket = getTicketAt(props.state.cursor);
4712
+ const here = getLayerAt(props.state.cursor) ?? model.groups.find((group) => group.all.includes(props.state.selected))?.index;
4713
+ const toRow = (group) => {
4714
+ const size = getLayerSize(group, block.layers[group.index], model.marks.isReadIn);
4715
+ const layer = block.layers[group.index];
4716
+ return {
4717
+ key: group.key,
4718
+ number: layer?.isRemainder === true ? "·" : group.address,
4719
+ title: group.title,
4720
+ size,
4721
+ threads: layer ?? NO_MARK,
4722
+ count: size.count === 0 ? "—" : `${String(size.read)}/${String(size.count)}`,
4723
+ isRead: size.isDone,
4724
+ isHere: cursorTicket === null && group.index === here,
4725
+ isPart: group.ticket !== null
4726
+ };
4727
+ };
4728
+ const rows = [];
4729
+ model.entries.forEach((entry) => {
4730
+ const ticket = entry.kind === "ticket" ? block.tickets.find((one) => one.number === entry.number) : void 0;
4731
+ if (ticket !== void 0) rows.push({
4732
+ key: ticketKey(ticket.number),
4733
+ number: ticket.address,
4734
+ title: ticket.title,
4735
+ size: getTicketSize(ticket),
4736
+ threads: NO_MARK,
4737
+ count: `${String(ticket.sublayersDone)}/${String(ticket.sublayers)}`,
4738
+ isRead: ticket.isDone,
4739
+ isHere: cursorTicket === ticket.number,
4740
+ isPart: false
4741
+ });
4742
+ getEntryGroups(entry).forEach((group) => {
4743
+ rows.push(toRow(group));
4744
+ });
4745
+ });
4746
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", {
4747
+ className: "m-0 mx-2 mb-10 list-none more-group p-0",
4748
+ children: rows.map((row) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row$1, {
4749
+ onPick: props.onPickLayer,
4750
+ row
4751
+ }, row.key))
4752
+ });
4551
4753
  };
4552
4754
  var isDiff = (props) => props.state.focus === "diff" && props.file !== void 0;
4553
4755
  var SHORT_SHA$2 = 7;
@@ -4744,51 +4946,6 @@ var MoreActions = ({ props, onPress, footer }) => {
4744
4946
  ]
4745
4947
  });
4746
4948
  };
4747
- /** Every layer on one sheet, for a phone that cannot see the whole rail: tap one to open it. */
4748
- var LayersSheet = ({ props }) => {
4749
- const { model } = props;
4750
- const here = getLayerAt(props.state.cursor) ?? model.groups.find((group) => group.all.includes(props.state.selected))?.index;
4751
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", {
4752
- className: "m-0 mx-2 mb-10 list-none more-group p-0",
4753
- children: model.groups.map((group) => {
4754
- const size = getLayerSize(group, props.block.layers[group.index], model.marks.isReadIn);
4755
- const isRead = size.isDone;
4756
- const threads = props.block.layers[group.index] ?? NO_MARK;
4757
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
4758
- className: "flex min-h-14 w-full items-center gap-2.5 px-3.5 py-1.5 text-start transition-colors duration-150 active:bg-foreground/8",
4759
- onClick: () => {
4760
- props.onPickLayer(group.key);
4761
- },
4762
- type: "button",
4763
- children: [
4764
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4765
- className: `grid size-6 shrink-0 place-items-center rounded-full font-mono text-sm ${group.index === here ? "bg-accent text-accent-foreground" : "text-subtle"}`,
4766
- children: isRead && group.index !== here ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Check, {
4767
- "aria-label": "read",
4768
- className: "size-3.5 text-success",
4769
- strokeWidth: 3
4770
- }) : String(group.index + 1)
4771
- }),
4772
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
4773
- className: "grid min-w-0 flex-1 gap-0.5",
4774
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4775
- className: "text-base/5",
4776
- children: group.title
4777
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SizeSaid, { size })]
4778
- }),
4779
- threads.open > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StandMark, {
4780
- said: getMarkSaid(threads),
4781
- stand: threads.stand
4782
- }) : null,
4783
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
4784
- className: "shrink-0 font-mono text-sm text-subtle tabular-nums",
4785
- children: size.count === 0 ? "—" : `${String(size.read)}/${String(size.count)}`
4786
- })
4787
- ]
4788
- }) }, group.key);
4789
- })
4790
- });
4791
- };
4792
4949
  var PICK_ROW = "flex w-full min-w-0 items-start gap-2 rounded-md px-2 py-1.5 text-start transition-colors duration-150 ease-out outline-none hover:bg-secondary focus-visible:bg-secondary";
4793
4950
  var Quiet = ({ text }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
4794
4951
  className: "m-0 px-4 py-6 text-center text-sm text-subtle",
@@ -5240,6 +5397,30 @@ var getCursorLayer = (state) => getLayerAt(state.cursor);
5240
5397
  * Passing its row with `j`/`k` leaves it closed, so the titles can be skimmed.
5241
5398
  */
5242
5399
  var isLayerOpen = (state, key) => state.layerOpen[key] ?? (key !== "layer:read" && state.cursor.startsWith(`${key}:`));
5400
+ /** A layer picked from the phone's sheet: the cursor moves onto it, open, and so is its ticket. */
5401
+ var openPickedLayer = (state, { key, groups }) => {
5402
+ const ticket = groups.find((group) => group.key === key)?.ticket ?? null;
5403
+ const shut = ticket === null ? null : ticketKey(ticket);
5404
+ const layerOpen = Object.fromEntries(Object.entries({
5405
+ ...state.layerOpen,
5406
+ [key]: true
5407
+ }).filter(([candidate]) => candidate !== shut));
5408
+ return {
5409
+ ...state,
5410
+ dialog: null,
5411
+ cursor: key,
5412
+ layerOpen
5413
+ };
5414
+ };
5415
+ /**
5416
+ * A rail entry opens as a layer does. A ticket also opens while the cursor is in one of its
5417
+ * sublayers, on its row or on a file, so the reader always sees where the cursor is.
5418
+ */
5419
+ var isEntryOpen = (state, entry) => {
5420
+ if (entry.kind === "layer") return isLayerOpen(state, entry.key);
5421
+ const at = getLayerAt(state.cursor);
5422
+ return state.layerOpen[entry.key] ?? entry.groups.some((group) => group.index === at);
5423
+ };
5243
5424
  var setLayerOpen = (state, key, isOpen) => ({
5244
5425
  ...state,
5245
5426
  layerOpen: {
@@ -5272,11 +5453,16 @@ var getInitialState = (block) => {
5272
5453
  };
5273
5454
  };
5274
5455
  var toggleDir = (collapsed, dir) => collapsed.has(dir) ? new Set([...collapsed].filter((candidate) => candidate !== dir)) : /* @__PURE__ */ new Set([...collapsed, dir]);
5275
- var pickLayer = (state, key) => setLayerOpen({
5276
- ...state,
5277
- cursor: key
5278
- }, key, !isLayerOpen(state, key));
5279
- var pickRow = (state, row) => {
5456
+ /** A click on a layer or a ticket turns it from how it shows now, open by the cursor or by hand. */
5457
+ var pickLayer = (state, key, entries) => {
5458
+ const entry = entries.find((one) => one.key === key);
5459
+ const isOpen = entry === void 0 ? isLayerOpen(state, key) : isEntryOpen(state, entry);
5460
+ return setLayerOpen({
5461
+ ...state,
5462
+ cursor: key
5463
+ }, key, !isOpen);
5464
+ };
5465
+ var pickRow = (state, row, entries = []) => {
5280
5466
  if (row.kind === "file") return {
5281
5467
  ...state,
5282
5468
  selected: row.path,
@@ -5284,7 +5470,7 @@ var pickRow = (state, row) => {
5284
5470
  row: 0,
5285
5471
  anchor: null
5286
5472
  };
5287
- return state.isLayered ? pickLayer(state, row.key) : {
5473
+ return state.isLayered ? pickLayer(state, row.key, entries) : {
5288
5474
  ...state,
5289
5475
  collapsed: toggleDir(state.collapsed, row.full),
5290
5476
  cursor: row.key
@@ -5352,7 +5538,7 @@ var switchRail = (state, input) => input.hasLayers ? toggleLayers(state, input)
5352
5538
  wantsLayers: !state.wantsLayers
5353
5539
  };
5354
5540
  var setCursorLayerOpen = (state, isOpen) => {
5355
- if (state.cursor === "layer:read") return setLayerOpen(state, READ_LAYERS, isOpen);
5541
+ if (state.cursor === "layer:read" || getTicketAt(state.cursor) !== null) return setLayerOpen(state, state.cursor, isOpen);
5356
5542
  const layer = getCursorLayer(state);
5357
5543
  if (layer === null) return state;
5358
5544
  const key = `layer:${String(layer)}`;
@@ -5362,34 +5548,6 @@ var setCursorLayerOpen = (state, isOpen) => {
5362
5548
  cursor: key
5363
5549
  };
5364
5550
  };
5365
- var withoutKey = (open, key) => Object.fromEntries(Object.entries(open).filter(([candidate]) => candidate !== key));
5366
- /** The layer the file is open in: the cursor's when it is on the file, else the first that has it. */
5367
- var getFileLayer = (state, layers) => {
5368
- const at = getLayerAt(state.cursor);
5369
- return at !== null && state.cursor === fileKey(at, state.selected) ? at : Math.max(0, layers.findIndex((layer) => layer.files.includes(state.selected)));
5370
- };
5371
- /**
5372
- * The file on screen always shows in the sidebar, whichever way it was opened (a click, `]`, the
5373
- * panel, search, a type's definition): in the file tree its folders open, in the layers rail its
5374
- * layer opens, and the read layers' row with it when that layer is read. Only a change of file
5375
- * reveals it, so the reader can still close the folder or layer it sits in afterwards.
5376
- */
5377
- var revealSelected = (previous, next, layers) => {
5378
- if (next.selected === previous.selected && next.isLayered === previous.isLayered) return next;
5379
- if (!next.isLayered) {
5380
- const ancestors = new Set(getAncestors(next.selected));
5381
- return {
5382
- ...next,
5383
- collapsed: new Set([...next.collapsed].filter((dir) => !ancestors.has(dir)))
5384
- };
5385
- }
5386
- const layer = getFileLayer(next, layers);
5387
- return {
5388
- ...next,
5389
- cursor: fileKey(layer, next.selected),
5390
- layerOpen: withoutKey(next.layerOpen, layerKey(layer))
5391
- };
5392
- };
5393
5551
  var SHORT_SHA = 7;
5394
5552
  /** A commit reads by its first 7 characters, as git shows it; a branch by its name. */
5395
5553
  var shortBase = (label) => {
@@ -5501,7 +5659,7 @@ var BackButton = ({ label, onBack }) => /* @__PURE__ */ (0, import_jsx_runtime.j
5501
5659
  /** Where the open file sits: in its layer when layers are shown, else in the whole branch. */
5502
5660
  var getPlace = (props) => {
5503
5661
  const group = props.state.isLayered ? props.model.groups.find((each) => props.file !== void 0 && each.all.includes(props.file.path)) : void 0;
5504
- return group === void 0 || props.file === void 0 ? `${String(props.position)} of ${String(props.total)}` : `${String(group.all.indexOf(props.file.path) + 1)} of ${String(group.all.length)} in layer ${String(group.index + 1)}`;
5662
+ return group === void 0 || props.file === void 0 ? `${String(props.position)} of ${String(props.total)}` : `${String(group.all.indexOf(props.file.path) + 1)} of ${String(group.all.length)} in layer ${group.address}`;
5505
5663
  };
5506
5664
  var PhoneFilesHead = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
5507
5665
  className: "grid gap-2.5 bg-background px-4 py-3 md:hidden",
@@ -5750,30 +5908,62 @@ var SinceBar = ({ since, mode, onMode }) => {
5750
5908
  var NUMBERED = /^\d+\.\s*/u;
5751
5909
  /** A layer's intro is folded per branch and layer, so a new order's layer opens fresh. */
5752
5910
  var getIntroKey = (block, layer) => `${block.branch}|${layer.title}`;
5753
- /** The layer the rail reads in, when it reads by layers and the layer is one the agent wrote. */
5754
- var getOpenLayer = (block, state) => {
5755
- const index = state.isLayered ? getLayerAt(state.cursor) : null;
5756
- const layer = index === null ? void 0 : block.layers[index];
5757
- return layer === void 0 || layer.isRemainder || index === null ? null : {
5758
- index,
5759
- layer
5760
- };
5761
- };
5911
+ /** A ticket's intro is folded apart from its parts', each read once. */
5912
+ var getTicketKey = (block, ticket) => `${block.branch}|ticket|${ticket.title}`;
5913
+ /** The ticket a part sits under, as adiff rolls it up. */
5914
+ var getTicketOf = (block, layer) => block.tickets.find((ticket) => ticket.number === layer.ticket);
5762
5915
  /** Where the layer's intro is read: the file adiff places it at, else its first file in the diff. */
5763
5916
  var getFirstFile = (block, layer) => {
5764
5917
  const placed = getIntro(layer)?.path;
5765
5918
  return block.files.some((file) => file.path === placed) ? placed : layer.files.find((path) => block.files.some((file) => file.path === path));
5766
5919
  };
5767
- var getFacts = (block, layer, index) => {
5768
- const files = block.files.filter((file) => layer.files.includes(file.path));
5920
+ /** A ticket's first part, whose first file is where the ticket's intro is read. */
5921
+ var getFirstPart = (block, ticket) => {
5922
+ const [first] = ticket.layers;
5923
+ const layer = first === void 0 ? void 0 : block.layers[first - 1];
5924
+ return first === void 0 || layer === void 0 ? null : {
5925
+ index: first - 1,
5926
+ layer
5927
+ };
5928
+ };
5929
+ /** The files of a layer this diff still has. */
5930
+ var countFiles = (block, layer) => block.files.filter((file) => layer.files.includes(file.path));
5931
+ var getLayerFacts = (block, layer) => {
5932
+ const files = countFiles(block, layer);
5933
+ const noted = files.filter((file) => getFileNotes(layer, file.path).length > 0).length;
5769
5934
  return {
5770
- index,
5771
5935
  count: files.length,
5772
- layers: block.layers.filter((one) => !one.isRemainder).length,
5773
5936
  added: layer.added,
5774
- noted: files.filter((file) => getFileNotes(layer, file.path).length > 0).length
5937
+ detail: `${String(noted)} of ${String(files.length)} files have a note`
5775
5938
  };
5776
5939
  };
5940
+ /** How many of a ticket's parts adiff calls read, in the screen's word for a sublayer. */
5941
+ var getPartsRead = ({ sublayers, sublayersDone }) => {
5942
+ if (sublayersDone === 0) return `${String(sublayers)} parts, none read yet`;
5943
+ return sublayersDone === sublayers ? "Every part read" : `${String(sublayersDone)} of ${String(sublayers)} parts read`;
5944
+ };
5945
+ /** The small line over a layer's title: where it sits in the reading order. */
5946
+ var getEyebrow = (block, layer) => {
5947
+ const ticket = getTicketOf(block, layer);
5948
+ return ticket === void 0 || layer.sublayer === null ? `Layer ${layer.address} of ${String(block.topLevel)}` : `Layer ${layer.address} · part ${String(layer.sublayer)} of ${String(ticket.sublayers)} in ${ticket.title}`;
5949
+ };
5950
+ /**
5951
+ * The first part of a ticket waits as a line while the ticket's intro shows as a card above it, so
5952
+ * the reader meets one card at a time.
5953
+ */
5954
+ var isHeld = (block, layer, introsFolded) => {
5955
+ const ticket = getTicketOf(block, layer);
5956
+ return ticket !== void 0 && getFirstPart(block, ticket)?.layer === layer && toIntro(ticket.note, "") !== null && !introsFolded.includes(getTicketKey(block, ticket));
5957
+ };
5958
+ /**
5959
+ * Opens a layer's intro. The first part of a ticket opens under the ticket's intro, folded, so the
5960
+ * ticket's card folds to let the part's show: one card at a time.
5961
+ */
5962
+ var openIntro = (block, layer) => {
5963
+ const ticket = getTicketOf(block, layer);
5964
+ if (ticket !== void 0 && getFirstPart(block, ticket)?.layer === layer) setIntroFolded(getTicketKey(block, ticket), true);
5965
+ setIntroFolded(getIntroKey(block, layer), false);
5966
+ };
5777
5967
  var Points = ({ points }) => points.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", {
5778
5968
  className: "m-0 grid list-none gap-1.25 p-0",
5779
5969
  children: points.map((point) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", {
@@ -5787,6 +5977,33 @@ var Points = ({ points }) => points.length === 0 ? null : /* @__PURE__ */ (0, im
5787
5977
  }) })]
5788
5978
  }, point))
5789
5979
  });
5980
+ /** A ticket's intro lists its parts where a layer lists its points: number, title, size. */
5981
+ var Parts = ({ block, ticket }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", {
5982
+ className: "m-0 mt-0.5 grid list-none gap-0.5 p-0",
5983
+ children: ticket.layers.map((position) => {
5984
+ const layer = block.layers[position - 1];
5985
+ return layer === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", {
5986
+ className: "flex items-baseline gap-2 text-sm/5.5 text-muted-foreground max-md:text-base",
5987
+ children: [
5988
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
5989
+ className: "w-7.5 shrink-0 font-mono text-xs/5.5 text-subtle",
5990
+ children: layer.address
5991
+ }),
5992
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
5993
+ className: "min-w-0 flex-1",
5994
+ children: layer.title
5995
+ }),
5996
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
5997
+ className: "shrink-0 text-xs whitespace-nowrap text-subtle tabular-nums",
5998
+ children: [`${String(countFiles(block, layer).length)} files · `, /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
5999
+ className: "text-sign-add",
6000
+ children: `+${shortCount(layer.added)}`
6001
+ })]
6002
+ })
6003
+ ]
6004
+ }, layer.address);
6005
+ })
6006
+ });
5790
6007
  /** The intro beside it: how to read the layer, what it holds, and folding it away. */
5791
6008
  var IntroSide = ({ intro, facts, onFold }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
5792
6009
  className: "flex flex-col gap-3.5 border-s border-border ps-5 max-md:border-s-0 max-md:border-t max-md:ps-0 max-md:pt-4",
@@ -5806,7 +6023,7 @@ var IntroSide = ({ intro, facts, onFold }) => /* @__PURE__ */ (0, import_jsx_run
5806
6023
  children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [`${String(facts.count)} files · `, /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
5807
6024
  className: "text-sign-add",
5808
6025
  children: `+${shortCount(facts.added)}`
5809
- })] }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: `${String(facts.noted)} of ${String(facts.count)} files have a note` })]
6026
+ })] }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: facts.detail })]
5810
6027
  }),
5811
6028
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
5812
6029
  className: "inline-flex h-7.5 press items-center self-start rounded-md bg-foreground/9 px-3 text-ui font-medium hover:bg-foreground/14 max-md:h-12 max-md:justify-center max-md:self-stretch max-md:text-base",
@@ -5816,38 +6033,38 @@ var IntroSide = ({ intro, facts, onFold }) => /* @__PURE__ */ (0, import_jsx_run
5816
6033
  })
5817
6034
  ]
5818
6035
  });
5819
- /** A layer's intro, over its first file: read once, as the layer starts, then folded to a line. */
5820
- var IntroCard = ({ layer, intro, facts, onFold }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", {
5821
- "aria-label": `Layer ${String(facts.index + 1)} intro`,
6036
+ /** An intro, over its first file: read once, as the layer or ticket starts, then folded to a line. */
6037
+ var IntroCard = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", {
6038
+ "aria-label": `Layer ${props.address} intro`,
5822
6039
  className: "mx-5 mt-4 layer-intro animate-enter rounded-xl border border-border bg-wash px-5 pt-4.5 pb-4 max-md:mx-3 max-md:mt-3 max-md:p-4",
5823
6040
  children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
5824
6041
  className: "grid max-w-155 content-start gap-2",
5825
6042
  children: [
5826
6043
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
5827
6044
  className: "m-0 text-xs text-subtle tabular-nums",
5828
- children: `Layer ${String(facts.index + 1)} of ${String(facts.layers)}`
6045
+ children: props.eyebrow
5829
6046
  }),
5830
6047
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", {
5831
6048
  className: "m-0 text-lg font-semibold tracking-tight text-balance",
5832
- children: layer.title.replace(NUMBERED, "")
6049
+ children: props.title.replace(NUMBERED, "")
5833
6050
  }),
5834
6051
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
5835
6052
  className: "m-0 mb-0.5 text-base text-foreground max-md:text-base",
5836
6053
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Words, {
5837
6054
  isChipped: true,
5838
- text: intro.lead
6055
+ text: props.intro.lead
5839
6056
  })
5840
6057
  }),
5841
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Points, { points: intro.points })
6058
+ props.children
5842
6059
  ]
5843
6060
  }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IntroSide, {
5844
- facts,
5845
- intro,
5846
- onFold
6061
+ facts: props.facts,
6062
+ intro: props.intro,
6063
+ onFold: props.onFold
5847
6064
  })]
5848
6065
  });
5849
6066
  /** A folded intro: one line that opens it again. */
5850
- var IntroStrip = ({ layer, intro, index, onOpen }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
6067
+ var IntroStrip = ({ address, title, lead, onOpen }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
5851
6068
  className: "px-5 pt-3 max-md:px-3",
5852
6069
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
5853
6070
  className: "flex h-9 w-full items-center gap-2.5 rounded-lg border border-border bg-wash px-3 text-start text-ui text-muted-foreground hover:bg-row-hover hover:text-foreground max-md:h-11",
@@ -5856,15 +6073,15 @@ var IntroStrip = ({ layer, intro, index, onOpen }) => /* @__PURE__ */ (0, import
5856
6073
  children: [
5857
6074
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
5858
6075
  className: "font-mono text-xs text-subtle",
5859
- children: String(index + 1)
6076
+ children: address
5860
6077
  }),
5861
6078
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("b", {
5862
6079
  className: "font-medium whitespace-nowrap text-foreground",
5863
- children: layer.title.replace(NUMBERED, "").split(":")[0]
6080
+ children: title.replace(NUMBERED, "").split(":")[0]
5864
6081
  }),
5865
6082
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
5866
6083
  className: "min-w-0 flex-1 truncate",
5867
- children: intro.lead
6084
+ children: lead
5868
6085
  }),
5869
6086
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
5870
6087
  className: "text-xs whitespace-nowrap text-subtle",
@@ -5890,28 +6107,85 @@ var FileNoteBox = ({ notes }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("as
5890
6107
  })
5891
6108
  })] }, `${String(piece.line)}:${String(piece.after)}:${piece.markdown}`))
5892
6109
  });
6110
+ /** The layer the rail reads in, when it reads by layers and the layer is one the agent wrote. */
6111
+ var getOpenLayer = (block, state) => {
6112
+ const index = state.isLayered ? getLayerAt(state.cursor) : null;
6113
+ const layer = index === null ? void 0 : block.layers[index];
6114
+ return layer === void 0 || layer.isRemainder || index === null ? null : {
6115
+ index,
6116
+ layer
6117
+ };
6118
+ };
5893
6119
  /** The intro over the layer's first file: the card, or the line it folds to. */
5894
- var IntroPart = ({ block, layer, index }) => {
6120
+ var IntroPart = ({ block, layer }) => {
5895
6121
  const { introsFolded } = useReviewPrefs();
5896
6122
  const intro = getIntro(layer);
5897
6123
  const key = getIntroKey(block, layer);
5898
6124
  if (intro === null) return null;
5899
- return introsFolded.includes(key) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IntroStrip, {
5900
- index,
6125
+ return isHeld(block, layer, introsFolded) || introsFolded.includes(key) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IntroStrip, {
6126
+ address: layer.address,
6127
+ lead: intro.lead,
6128
+ onOpen: () => {
6129
+ openIntro(block, layer);
6130
+ },
6131
+ title: layer.title
6132
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IntroCard, {
6133
+ address: layer.address,
6134
+ eyebrow: getEyebrow(block, layer),
6135
+ facts: getLayerFacts(block, layer),
5901
6136
  intro,
5902
- layer,
6137
+ onFold: () => {
6138
+ setIntroFolded(key, true);
6139
+ },
6140
+ title: layer.title,
6141
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Points, { points: intro.points })
6142
+ });
6143
+ };
6144
+ /** A ticket's intro, over its first part's first file: its note, then its parts. */
6145
+ var TicketIntroPart = ({ block, ticket, path }) => {
6146
+ const { introsFolded } = useReviewPrefs();
6147
+ const intro = toIntro(ticket.note, path);
6148
+ const key = getTicketKey(block, ticket);
6149
+ if (intro === null) return null;
6150
+ return introsFolded.includes(key) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IntroStrip, {
6151
+ address: ticket.address,
6152
+ lead: intro.lead,
5903
6153
  onOpen: () => {
5904
6154
  setIntroFolded(key, false);
5905
- }
5906
- }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IntroCard, {
5907
- facts: getFacts(block, layer, index),
6155
+ },
6156
+ title: ticket.title
6157
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(IntroCard, {
6158
+ address: ticket.address,
6159
+ eyebrow: `Layer ${ticket.address} of ${String(block.topLevel)} · ${String(ticket.sublayers)} parts`,
6160
+ facts: {
6161
+ count: ticket.files.length,
6162
+ added: ticket.added,
6163
+ detail: getPartsRead(ticket)
6164
+ },
5908
6165
  intro,
5909
- layer,
5910
6166
  onFold: () => {
5911
6167
  setIntroFolded(key, true);
5912
- }
6168
+ },
6169
+ title: ticket.title,
6170
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Points, { points: intro.points }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Parts, {
6171
+ block,
6172
+ ticket
6173
+ })]
5913
6174
  });
5914
6175
  };
6176
+ /** The intros over a layer's first file: its ticket's first, when this is the ticket's start. */
6177
+ var Intros = ({ block, layer, path }) => {
6178
+ const ticket = getTicketOf(block, layer);
6179
+ const isTicketStart = ticket !== void 0 && getFirstPart(block, ticket)?.layer === layer;
6180
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [isTicketStart ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TicketIntroPart, {
6181
+ block,
6182
+ path,
6183
+ ticket
6184
+ }) : null, /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IntroPart, {
6185
+ block,
6186
+ layer
6187
+ })] });
6188
+ };
5915
6189
  /**
5916
6190
  * The layer's note where it is read: its intro over the layer's first file, and each file's own
5917
6191
  * note over that file's code. The rail keeps only the intro's first sentence.
@@ -5920,10 +6194,10 @@ var LayerNotes = ({ block, state, path }) => {
5920
6194
  const { isNoted } = useReviewPrefs();
5921
6195
  const open = getOpenLayer(block, state);
5922
6196
  const notes = open === null ? [] : getFileNotes(open.layer, path);
5923
- return !isNoted || open === null ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [getFirstFile(block, open.layer) === path ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IntroPart, {
6197
+ return !isNoted || open === null ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [getFirstFile(block, open.layer) === path ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Intros, {
5924
6198
  block,
5925
- index: open.index,
5926
- layer: open.layer
6199
+ layer: open.layer,
6200
+ path
5927
6201
  }) : null, notes.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FileNoteBox, { notes })] });
5928
6202
  };
5929
6203
  /** The open layer's lead in the rail; a click opens the whole intro over the layer's first file. */
@@ -5931,19 +6205,38 @@ var RailLead = ({ block, index, selected, onPickFile }) => {
5931
6205
  const { isNoted, introsFolded } = useReviewPrefs();
5932
6206
  const layer = block.layers[index];
5933
6207
  const first = layer === void 0 ? void 0 : getFirstFile(block, layer);
5934
- const isShown = layer !== void 0 && isNoted && !introsFolded.includes(getIntroKey(block, layer)) && selected === first;
6208
+ const isShown = layer !== void 0 && isNoted && !introsFolded.includes(getIntroKey(block, layer)) && !isHeld(block, layer, introsFolded) && selected === first;
5935
6209
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LayerLead, {
6210
+ intro: layer === void 0 ? null : getIntro(layer),
5936
6211
  isIntroShown: isShown,
5937
- layer,
6212
+ isPart: (layer?.ticket ?? null) !== null,
5938
6213
  onOpenIntro: () => {
5939
6214
  if (layer !== void 0 && first !== void 0) {
5940
- setIntroFolded(getIntroKey(block, layer), false);
6215
+ openIntro(block, layer);
5941
6216
  setReviewPrefs({ isNoted: true });
5942
6217
  onPickFile(fileKey(index, first), first);
5943
6218
  }
5944
6219
  }
5945
6220
  });
5946
6221
  };
6222
+ /** An open ticket's lead in the rail, while none of its parts is open: its note's first line. */
6223
+ var TicketLead = ({ block, ticket, selected, onPickFile }) => {
6224
+ const { isNoted, introsFolded } = useReviewPrefs();
6225
+ const part = getFirstPart(block, ticket);
6226
+ const first = part === null ? void 0 : getFirstFile(block, part.layer);
6227
+ const key = getTicketKey(block, ticket);
6228
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LayerLead, {
6229
+ intro: toIntro(ticket.note, first ?? ""),
6230
+ isIntroShown: isNoted && !introsFolded.includes(key) && selected === first,
6231
+ onOpenIntro: () => {
6232
+ if (part !== null && first !== void 0) {
6233
+ setIntroFolded(key, false);
6234
+ setReviewPrefs({ isNoted: true });
6235
+ onPickFile(fileKey(part.index, first), first);
6236
+ }
6237
+ }
6238
+ });
6239
+ };
5947
6240
  var SIDES = [{
5948
6241
  side: "old",
5949
6242
  label: "Before"
@@ -6366,7 +6659,7 @@ var getExplainer = (layers, row) => {
6366
6659
  const [first] = row.layers ?? [];
6367
6660
  const found = first === void 0 ? void 0 : layers[first - 1];
6368
6661
  return found === void 0 || found.isRemainder || first === void 0 ? null : {
6369
- layer: first,
6662
+ layer: found.address,
6370
6663
  title: found.title
6371
6664
  };
6372
6665
  };
@@ -6380,7 +6673,7 @@ var getLayerClaim = (layers, { index, rows, runs = NO_RUNS, isAllShown = false }
6380
6673
  const isQuiet = (row) => isChange$1(row) && !isMine(row) && (isAllShown || row.quietIn?.includes(index + 1) === true);
6381
6674
  const said = (row) => {
6382
6675
  const explainer = getExplainer(layers, row);
6383
- return explainer === null ? "that no layer claims" : `from layer ${String(explainer.layer)}`;
6676
+ return explainer === null ? "that no layer claims" : `from layer ${explainer.layer}`;
6384
6677
  };
6385
6678
  const quietOf = (row) => {
6386
6679
  const explainer = getExplainer(layers, row);
@@ -7618,9 +7911,8 @@ var Tag = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span",
7618
7911
  });
7619
7912
  /** Where the locate button goes: the layer a thread the branch moved past was read in, else its line. */
7620
7913
  var getPlaceLabel = (thread) => {
7621
- const [layer] = thread.layers;
7622
7914
  const name = splitPath(thread.file).base;
7623
- return thread.isMovedPast ? `Open in ${layer === void 0 ? name : `layer ${String(layer)}`}, near line ${String(thread.start)}` : `Open in the diff, at line ${String(thread.start)}`;
7915
+ return thread.isMovedPast ? `Open in ${thread.layerAddress === null ? name : `layer ${thread.layerAddress}`}, near line ${String(thread.start)}` : `Open in the diff, at line ${String(thread.start)}`;
7624
7916
  };
7625
7917
  var getGone = (thread) => thread.start === thread.end ? `line ${String(thread.start)} is gone` : `lines ${getLines(thread)} are gone`;
7626
7918
  var CODE_SAID = {
@@ -8250,10 +8542,9 @@ var Tool = ({ label, onClick: handleClick, children }) => /* @__PURE__ */ (0, im
8250
8542
  }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipContent, { children: label })] });
8251
8543
  var goLabel = (entry) => {
8252
8544
  const { thread } = entry;
8253
- const [layer] = thread.layers;
8254
8545
  if (!isReadInPanel(entry)) return `Go to line ${String(thread.start)}`;
8255
8546
  const name = thread.file.split("/").at(-1) ?? thread.file;
8256
- return `Open in ${layer === void 0 ? name : `layer ${String(layer)}`}, near line ${String(thread.start)}`;
8547
+ return `Open in ${thread.layerAddress === null ? name : `layer ${thread.layerAddress}`}, near line ${String(thread.start)}`;
8257
8548
  };
8258
8549
  var CAN_SETTLE = /* @__PURE__ */ new Set(["answered", "asked"]);
8259
8550
  var ThreadRowTools = ({ entry, acts, tools }) => {
@@ -8607,9 +8898,8 @@ var usePanel = (props, panelRef) => {
8607
8898
  };
8608
8899
  /** A thread with no line, read where it is listed: the comment card, under its row. */
8609
8900
  var PanelCard = ({ thread, props, actions }) => {
8610
- const [layer] = thread.layers;
8611
8901
  const name = thread.file.split("/").at(-1) ?? thread.file;
8612
- const label = `Open in ${layer === void 0 ? name : `layer ${String(layer)}`}, near line ${String(thread.start)}`;
8902
+ const label = `Open in ${thread.layerAddress === null ? name : `layer ${thread.layerAddress}`}, near line ${String(thread.start)}`;
8613
8903
  const placed = getPlaced(thread, props);
8614
8904
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
8615
8905
  className: "mx-1.5 mb-2 grid gap-1.5 font-sans",
@@ -9376,15 +9666,10 @@ var usePhone = (props, pane) => {
9376
9666
  listener,
9377
9667
  model: pane.model,
9378
9668
  onPickLayer: (key) => {
9379
- setState({
9380
- ...state,
9381
- dialog: null,
9382
- cursor: key,
9383
- layerOpen: {
9384
- ...state.layerOpen,
9385
- [key]: true
9386
- }
9387
- });
9669
+ setState(openPickedLayer(state, {
9670
+ key,
9671
+ groups: pane.model.groups
9672
+ }));
9388
9673
  },
9389
9674
  handlePress: (key) => {
9390
9675
  if (key === "m") tapHaptic();
@@ -9571,11 +9856,10 @@ var Stale = ({ title, said, isAsked, onReorder, action = "Reorder", whileAsked =
9571
9856
  });
9572
9857
  /** A question from the agent goes ahead of the plan: it names the layer that holds it. */
9573
9858
  var QuestionFirst = (props) => {
9574
- const { here } = props;
9575
9859
  const asked = props.block.threads.find((thread) => thread.stand === "asked");
9576
9860
  const [first] = asked?.layers ?? [];
9577
9861
  const group = props.groups.find((each) => first !== void 0 && each.index === first - 1);
9578
- if (asked === void 0 || group === void 0 || asked.layers.includes(here + 1)) return null;
9862
+ if (asked === void 0 || group === void 0 || asked.layers.some((position) => props.isHere(position))) return null;
9579
9863
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
9580
9864
  className: "mb-2 flex w-full animate-enter items-start gap-2.5 rounded-lg border border-stand-asked/40 p-2.5 text-start transition-colors duration-150 hover:bg-row-hover",
9581
9865
  onClick: () => {
@@ -9595,7 +9879,7 @@ var QuestionFirst = (props) => {
9595
9879
  children: "Up next: a question for you"
9596
9880
  }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
9597
9881
  className: "text-xs text-muted-foreground",
9598
- children: `in ${String(group.index + 1)} · ${group.title}, before the plan’s next layer`
9882
+ children: `in ${group.address} · ${group.title}, before the plan’s next layer`
9599
9883
  })]
9600
9884
  }),
9601
9885
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ArrowRight, {
@@ -9630,29 +9914,36 @@ var NoLayers = ({ files, isAsked, onAsk }) => /* @__PURE__ */ (0, import_jsx_run
9630
9914
  title: isAsked ? "An agent is writing layers" : "No layers yet",
9631
9915
  whileAsked: "They show here when written; keep reading meanwhile"
9632
9916
  });
9633
- /** On a layer's last file: where `]` goes next, in place of that layer's own row. */
9634
- var NextLayer = ({ group, size, onPick }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(KeyTip, {
9635
- keys: ["]"],
9636
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
9637
- "data-keep-visible": true,
9638
- className: "my-1.5 ms-6 next-layer animate-enter items-center gap-x-2 rounded-lg border border-border bg-background px-2.5 py-2 text-start hover:bg-row-hover",
9639
- onClick: onPick,
9640
- type: "button",
9641
- children: [
9642
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
9643
- className: "text-xs text-subtle",
9644
- children: "End of this layer · up next"
9645
- }),
9646
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ArrowRight, {
9647
- "aria-hidden": true,
9648
- className: "row-span-3 size-3.5 text-muted-foreground"
9649
- }),
9650
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
9651
- className: "text-ui font-medium",
9652
- children: `${String(group.index + 1)} · ${group.title}`
9653
- }),
9654
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SizeSaid, { size })
9655
- ]
9917
+ /**
9918
+ * On a layer's last file: where `]` goes next, in place of that layer's own row. Inside a ticket
9919
+ * it offers the next part ("End of part 2.1"), set in with the parts; on a ticket's last part, the
9920
+ * layer after the whole ticket ("End of layer 2").
9921
+ */
9922
+ var NextLayer = ({ said, name, size, isPart = false, onPick }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
9923
+ className: cn(isPart && "ps-6.5"),
9924
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(KeyTip, {
9925
+ keys: ["]"],
9926
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
9927
+ "data-keep-visible": true,
9928
+ className: "my-1.5 ms-6 next-layer animate-enter items-center gap-x-2 rounded-lg border border-border bg-background px-2.5 py-2 text-start hover:bg-row-hover",
9929
+ onClick: onPick,
9930
+ type: "button",
9931
+ children: [
9932
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
9933
+ className: "text-xs text-subtle",
9934
+ children: said
9935
+ }),
9936
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ArrowRight, {
9937
+ "aria-hidden": true,
9938
+ className: "row-span-3 size-3.5 text-muted-foreground"
9939
+ }),
9940
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
9941
+ className: "text-ui font-medium",
9942
+ children: name
9943
+ }),
9944
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SizeSaid, { size })
9945
+ ]
9946
+ })
9656
9947
  })
9657
9948
  });
9658
9949
  /** Rows pinned at the top of the list (`data-pinned`) cover what scrolls under them. */
@@ -9668,76 +9959,284 @@ var getSpan = (container, item) => {
9668
9959
  bottom: Math.max(box.bottom - origin, extraBottom)
9669
9960
  };
9670
9961
  };
9671
- var scrollNearest$1 = (container, item) => {
9672
- const { top, bottom } = getSpan(container, item);
9673
- const covered = getPinnedHeight(container, item);
9674
- if (top - covered < container.scrollTop) {
9675
- container.scrollTop = top - covered;
9676
- return;
9677
- }
9678
- if (bottom > container.scrollTop + container.clientHeight) container.scrollTop = bottom - container.clientHeight;
9962
+ var scrollNearest$1 = (container, item) => {
9963
+ const { top, bottom } = getSpan(container, item);
9964
+ const covered = getPinnedHeight(container, item);
9965
+ if (top - covered < container.scrollTop) {
9966
+ container.scrollTop = top - covered;
9967
+ return;
9968
+ }
9969
+ if (bottom > container.scrollTop + container.clientHeight) container.scrollTop = bottom - container.clientHeight;
9970
+ };
9971
+ var useKeepInView = (activeKey) => {
9972
+ const containerRef = (0, import_react.useRef)(null);
9973
+ const items = (0, import_react.useRef)(/* @__PURE__ */ new Map());
9974
+ (0, import_react.useEffect)(() => {
9975
+ const container = containerRef.current;
9976
+ const item = items.current.get(activeKey);
9977
+ if (!container || !item) return;
9978
+ scrollNearest$1(container, item);
9979
+ }, [activeKey]);
9980
+ return {
9981
+ containerRef,
9982
+ register: (0, import_react.useCallback)((key) => (node) => {
9983
+ if (node === null) {
9984
+ items.current.delete(key);
9985
+ return;
9986
+ }
9987
+ items.current.set(key, node);
9988
+ }, [])
9989
+ };
9990
+ };
9991
+ /** The read layers by their numbers, runs joined: "1–3, 5". A ticket counts as its own number. */
9992
+ var nameLayers = (numbers) => {
9993
+ const runs = [];
9994
+ numbers.forEach((number) => {
9995
+ const run = runs.at(-1);
9996
+ if (run?.[1] === number - 1) run[1] = number;
9997
+ else runs.push([number, number]);
9998
+ });
9999
+ return runs.map(([from, to]) => from === to ? String(from) : `${String(from)}–${String(to)}`).join(", ");
10000
+ };
10001
+ var isOnLastFile = (group, cursor) => {
10002
+ const last = group.files.at(-1);
10003
+ return last !== void 0 && cursor === fileKey(group.index, last);
10004
+ };
10005
+ /** Files the order names that are no longer in the diff, struck through under their own caption. */
10006
+ var Vanished = ({ paths }) => paths.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("ul", {
10007
+ className: "m-0 list-none ps-8.5 pe-2 pb-1.5",
10008
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", {
10009
+ className: "pt-1 text-xs/5 text-subtle",
10010
+ children: "gone since the order was written"
10011
+ }), paths.map((path) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", {
10012
+ className: "truncate font-mono text-xs/5 text-subtle line-through",
10013
+ title: path,
10014
+ children: path.slice(path.lastIndexOf("/") + 1)
10015
+ }, path))]
10016
+ });
10017
+ var LayerBody = ({ group, props, register }) => {
10018
+ const vanished = props.block.layers[group.index]?.vanished ?? [];
10019
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
10020
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RailLead, {
10021
+ block: props.block,
10022
+ index: group.index,
10023
+ onPickFile: props.onPickFile,
10024
+ selected: props.state.selected
10025
+ }),
10026
+ group.all.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
10027
+ className: "m-0 ps-8.5 pe-2 pb-2 text-xs text-subtle",
10028
+ children: "Nothing left in this diff: its files changed after the order was written."
10029
+ }) : null,
10030
+ group.files.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LayerFiles, {
10031
+ block: props.block,
10032
+ cursor: props.state.cursor,
10033
+ files: props.files,
10034
+ group,
10035
+ isReadIn: props.isReadIn,
10036
+ onPickFile: props.onPickFile,
10037
+ register
10038
+ }) : null,
10039
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Vanished, { paths: vanished })
10040
+ ] });
10041
+ };
10042
+ var LayerCard = ({ group, props, register }) => {
10043
+ const layer = props.block.layers[group.index];
10044
+ const isOpen = isLayerOpen(props.state, group.key);
10045
+ return layer === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
10046
+ className: cn("mb-0.5", group.ticket !== null && "ps-6.5"),
10047
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(LayerRow, {
10048
+ group,
10049
+ isCursor: props.state.cursor === group.key,
10050
+ isOpen,
10051
+ layer,
10052
+ onPick: () => {
10053
+ props.onPickLayer(group.key);
10054
+ },
10055
+ register,
10056
+ size: getLayerSize(group, props.block.layers[group.index], props.isReadIn)
10057
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
10058
+ className: "fold",
10059
+ "data-open": isOpen ? "" : void 0,
10060
+ inert: !isOpen,
10061
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LayerBody, {
10062
+ group,
10063
+ props,
10064
+ register
10065
+ }) })
10066
+ })]
10067
+ });
9679
10068
  };
9680
- var useKeepInView = (activeKey) => {
9681
- const containerRef = (0, import_react.useRef)(null);
9682
- const items = (0, import_react.useRef)(/* @__PURE__ */ new Map());
9683
- (0, import_react.useEffect)(() => {
9684
- const container = containerRef.current;
9685
- const item = items.current.get(activeKey);
9686
- if (!container || !item) return;
9687
- scrollNearest$1(container, item);
9688
- }, [activeKey]);
9689
- return {
9690
- containerRef,
9691
- register: (0, import_react.useCallback)((key) => (node) => {
9692
- if (node === null) {
9693
- items.current.delete(key);
9694
- return;
9695
- }
9696
- items.current.set(key, node);
9697
- }, [])
9698
- };
10069
+ /**
10070
+ * On a layer's last file, the row after it turns into a card. Inside a ticket the next part takes
10071
+ * it; after a ticket's last part, or a plain layer, the next entry does.
10072
+ */
10073
+ var getUpNext = (shown, cursor) => {
10074
+ const groups = shown.flatMap((entry) => getEntryGroups(entry));
10075
+ const ending = groups.find((group) => isOnLastFile(group, cursor));
10076
+ if (ending === void 0) return null;
10077
+ const after = groups[groups.indexOf(ending) + 1];
10078
+ if (after !== void 0 && ending.ticket !== null && after.ticket === ending.ticket) return {
10079
+ key: after.key,
10080
+ said: `End of part ${ending.address} · up next`,
10081
+ isPart: true
10082
+ };
10083
+ const next = shown[shown.findIndex((entry) => getEntryGroups(entry).includes(ending)) + 1];
10084
+ return next === void 0 ? null : {
10085
+ key: next.key,
10086
+ said: ending.ticket === null ? "End of this layer · up next" : `End of layer ${String(ending.ticket)} · up next`,
10087
+ isPart: false
10088
+ };
10089
+ };
10090
+ var isUpNext = (upNext, key) => upNext?.key === key;
10091
+ /** A layer's card, or in its place the card that offers it next. */
10092
+ var GroupCard = ({ group, ...rest }) => isUpNext(rest.upNext, group.key) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(NextLayer, {
10093
+ isPart: rest.upNext.isPart,
10094
+ name: `${group.address} · ${group.title}`,
10095
+ onPick: () => {
10096
+ rest.props.onPickLayer(group.key);
10097
+ },
10098
+ said: rest.upNext.said,
10099
+ size: getLayerSize(group, rest.props.block.layers[group.index], rest.props.isReadIn)
10100
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LayerCard, {
10101
+ group,
10102
+ props: rest.props,
10103
+ register: rest.register
10104
+ });
10105
+ /** A ticket: its row, then, open, its lead while no part is open, and its parts. */
10106
+ var TicketCard = ({ entry, ticket, ...rest }) => {
10107
+ const { props } = rest;
10108
+ const isOpen = isEntryOpen(props.state, entry);
10109
+ const isPartOpen = entry.groups.some((group) => isLayerOpen(props.state, group.key));
10110
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
10111
+ className: "mb-0.5",
10112
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TicketRow, {
10113
+ isCursor: props.state.cursor === entry.key,
10114
+ isOpen,
10115
+ onPick: () => {
10116
+ props.onPickLayer(entry.key);
10117
+ },
10118
+ register: rest.register,
10119
+ rowKey: entry.key,
10120
+ ticket
10121
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
10122
+ className: "fold",
10123
+ "data-open": isOpen ? "" : void 0,
10124
+ inert: !isOpen,
10125
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [isPartOpen ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TicketLead, {
10126
+ block: props.block,
10127
+ onPickFile: props.onPickFile,
10128
+ selected: props.state.selected,
10129
+ ticket
10130
+ }), entry.groups.map((group) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(GroupCard, {
10131
+ group,
10132
+ ...rest
10133
+ }, group.key))] })
10134
+ })]
10135
+ });
9699
10136
  };
9700
- /** The read layers by number, runs joined: "1–3, 5". */
9701
- var nameLayers = (groups) => {
9702
- const runs = [];
9703
- groups.forEach((group) => {
9704
- const number = group.index + 1;
9705
- const run = runs.at(-1);
9706
- if (run?.[1] === number - 1) run[1] = number;
9707
- else runs.push([number, number]);
10137
+ /** A numbered entry: a plain layer, or a ticket; either may be offered as up next instead. */
10138
+ var EntryCard = ({ entry, ...rest }) => {
10139
+ if (entry.kind === "layer") return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(GroupCard, {
10140
+ group: entry,
10141
+ ...rest
10142
+ });
10143
+ const ticket = rest.props.block.tickets.find((one) => one.number === entry.number);
10144
+ if (ticket === void 0) return null;
10145
+ return isUpNext(rest.upNext, entry.key) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(NextLayer, {
10146
+ name: `${ticket.address} · ${ticket.title}`,
10147
+ onPick: () => {
10148
+ rest.props.onPickLayer(entry.key);
10149
+ },
10150
+ said: rest.upNext.said,
10151
+ size: getTicketSize(ticket)
10152
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TicketCard, {
10153
+ entry,
10154
+ ticket,
10155
+ ...rest
9708
10156
  });
9709
- return runs.map(([from, to]) => from === to ? String(from) : `${String(from)}–${String(to)}`).join(", ");
9710
10157
  };
9711
10158
  var PERCENT = 100;
9712
10159
  /** The layer the reader is in: the cursor's, else the one that holds the open file. */
9713
- var getHere = ({ state, groups }) => getLayerAt(state.cursor) ?? groups.find((group) => group.all.includes(state.selected))?.index ?? 0;
9714
- /** The whole branch at a glance: a segment per layer, sized by its files, green as it is read. */
10160
+ var getHere = ({ state, groups, block }) => {
10161
+ const ticket = getTicketAt(state.cursor);
10162
+ if (ticket !== null) return {
10163
+ index: null,
10164
+ ticket
10165
+ };
10166
+ const index = getLayerAt(state.cursor) ?? groups.find((group) => group.all.includes(state.selected))?.index ?? 0;
10167
+ return {
10168
+ index,
10169
+ ticket: block.layers[index]?.ticket ?? null
10170
+ };
10171
+ };
10172
+ /** Whether a layer is where the reader is: the layer itself, or any part of the ticket on screen. */
10173
+ var isHereIn = (here, group) => here.index === null ? group.ticket === here.ticket : group.index === here.index;
10174
+ var getTicket = (block, number) => block.tickets.find((ticket) => ticket.number === number);
10175
+ /**
10176
+ * Where the reader is, in words: "Layer 2 of 4 · part 2 of 3". The layer of lines no layer claims
10177
+ * is named, since it is not one of the numbered layers.
10178
+ */
10179
+ var getHereSaid = (block, here) => {
10180
+ const layer = here.index === null ? void 0 : block.layers[here.index];
10181
+ const ticket = here.ticket === null ? void 0 : getTicket(block, here.ticket);
10182
+ const of = `of ${String(block.topLevel)}`;
10183
+ if (layer?.isRemainder === true) return "Not in any layer";
10184
+ if (ticket === void 0) return `Layer ${layer?.address ?? "1"} ${of}`;
10185
+ const part = layer?.sublayer ?? null;
10186
+ return part === null ? `Layer ${ticket.address} ${of}` : `Layer ${ticket.address} ${of} · part ${String(part)} of ${String(ticket.sublayers)}`;
10187
+ };
10188
+ var setSize = (node, size) => {
10189
+ node?.style.setProperty("--size", String(Math.max(size.count, 1)));
10190
+ node?.style.setProperty("--fill", `${String(size.count === 0 ? 0 : size.read * PERCENT / size.count)}%`);
10191
+ };
10192
+ /** One layer's segment, sized by its files and green as far as they are read. */
10193
+ var Segment = ({ group, size, here }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
10194
+ className: "layer-seg",
10195
+ "data-here": isHereIn(here, group) ? "" : void 0,
10196
+ ref: (node) => {
10197
+ setSize(node, size);
10198
+ }
10199
+ });
10200
+ /** A segment per layer; a ticket's parts sit 1px apart, as one group as wide as their files. */
10201
+ var Segments = ({ entries, here, sizeOf }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
10202
+ "aria-hidden": true,
10203
+ className: "flex gap-0.5",
10204
+ children: entries.map((entry) => entry.kind === "layer" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Segment, {
10205
+ group: entry,
10206
+ here,
10207
+ size: sizeOf(entry)
10208
+ }, entry.key) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
10209
+ className: "layer-tk",
10210
+ ref: (node) => {
10211
+ const count = entry.groups.reduce((sum, group) => sum + sizeOf(group).count, 0);
10212
+ node?.style.setProperty("--size", String(Math.max(count, 1)));
10213
+ },
10214
+ children: entry.groups.map((group) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Segment, {
10215
+ group,
10216
+ here,
10217
+ size: sizeOf(group)
10218
+ }, group.key))
10219
+ }, entry.key))
10220
+ });
10221
+ /** The whole branch at a glance: a segment per layer, sized by its files, green as it is read. A
10222
+ * ticket's parts sit closer together, as one group. */
9715
10223
  var LayersMap = (props) => {
9716
- const sizes = props.groups.map((group) => ({
9717
- group,
9718
- size: getLayerSize(group, props.block.layers[group.index], props.isReadIn)
9719
- }));
10224
+ const sizeOf = (group) => getLayerSize(group, props.block.layers[group.index], props.isReadIn);
10225
+ const sizes = props.groups.map((group) => sizeOf(group));
9720
10226
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
9721
10227
  className: "sticky -top-2 z-3 -mx-2 -mt-2 grid h-14 content-center gap-2 border-b border-border bg-wash px-4",
9722
10228
  "data-pinned": true,
9723
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
9724
- "aria-hidden": true,
9725
- className: "flex gap-0.5",
9726
- children: sizes.map(({ group, size }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
9727
- className: "layer-seg",
9728
- "data-here": group.index === props.here ? "" : void 0,
9729
- ref: (node) => {
9730
- node?.style.setProperty("--size", String(Math.max(size.count, 1)));
9731
- node?.style.setProperty("--fill", `${String(size.count === 0 ? 0 : size.read * PERCENT / size.count)}%`);
9732
- }
9733
- }, group.key))
10229
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Segments, {
10230
+ entries: props.entries,
10231
+ here: props.here,
10232
+ sizeOf
9734
10233
  }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
9735
10234
  className: "flex items-center justify-between text-xs text-subtle tabular-nums",
9736
10235
  children: [
9737
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: `Layer ${String(props.here + 1)} of ${String(props.groups.length)}` }),
10236
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: getHereSaid(props.block, props.here) }),
9738
10237
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
9739
10238
  className: "max-md:hidden",
9740
- children: `${String(sizes.reduce((sum, one) => sum + one.size.read, 0))} of ${String(sizes.reduce((sum, one) => sum + one.size.count, 0))} files`
10239
+ children: `${String(sizes.reduce((sum, one) => sum + one.read, 0))} of ${String(sizes.reduce((sum, one) => sum + one.count, 0))} files`
9741
10240
  }),
9742
10241
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
9743
10242
  className: "-my-3 inline-flex min-h-11 press items-center gap-0.5 text-sm font-medium text-claude md:hidden",
@@ -9756,8 +10255,52 @@ var LayersMap = (props) => {
9756
10255
  children: props.block.summary
9757
10256
  })] });
9758
10257
  };
9759
- /** The read layers show when the reader opened them, or when the cursor is in one of them. */
9760
- var isReadFoldOpen = (props) => isLayerOpen(props.state, "layer:read") || props.done.some((group) => group.index === getLayerAt(props.state.cursor));
10258
+ var NO_GROUPS = [];
10259
+ var NO_ENTRIES = [];
10260
+ /** A ticket is read once adiff calls every sublayer read; only then does it fold away. */
10261
+ var isEntryDone = (block, entry) => entry.kind === "ticket" ? block.tickets.find((ticket) => ticket.number === entry.number)?.isDone === true : block.layers[entry.index]?.isDone === true;
10262
+ /** Whether the cursor is on an entry: its own row, or anywhere in the layers it holds. */
10263
+ var holdsCursor = (entry, cursor) => entry.key === cursor || getEntryGroups(entry).some((group) => group.index === getLayerAt(cursor));
10264
+ /** The read entries show when the reader opened them, or while the cursor is on one of them. */
10265
+ var isReadFoldOpen = (state, done) => isLayerOpen(state, "layer:read") || done.some((entry) => holdsCursor(entry, state.cursor));
10266
+ var getLayout = (block, { state, present, shown, isShownIn }) => {
10267
+ if (!state.isLayered || block.layers.length === 0) return {
10268
+ rows: getTreeRows(shown, state.collapsed),
10269
+ order: getTreeOrder(shown),
10270
+ groups: NO_GROUPS,
10271
+ entries: NO_ENTRIES,
10272
+ done: NO_ENTRIES
10273
+ };
10274
+ const groups = getLayerGroups(block.layers, {
10275
+ present,
10276
+ isShown: isShownIn
10277
+ });
10278
+ const entries = getRailEntries(groups, block.tickets);
10279
+ const isDone = (entry) => isEntryDone(block, entry);
10280
+ const folded = foldReadLayers(entries, {
10281
+ isDone,
10282
+ isOpen: (entry) => isEntryOpen(state, entry),
10283
+ isReadOpen: isReadFoldOpen(state, entries.filter((entry) => isDone(entry)))
10284
+ });
10285
+ return {
10286
+ rows: folded.rows,
10287
+ order: folded.order,
10288
+ groups,
10289
+ entries,
10290
+ done: folded.done
10291
+ };
10292
+ };
10293
+ /** The layer the rail has open, from 0: the cursor's, while the review reads by layers. */
10294
+ var getRailLayer = (state) => state.isLayered ? getLayerAt(state.cursor) : null;
10295
+ /** Every file in the walk, read layers unfolded, so a position counts in the whole of it. */
10296
+ var openEveryLayer = (state) => ({
10297
+ ...state,
10298
+ isHidingReviewed: false,
10299
+ layerOpen: {
10300
+ ...state.layerOpen,
10301
+ [READ_LAYERS]: true
10302
+ }
10303
+ });
9761
10304
  /** Marks the open layer's row while it is pinned, so it turns from a card into a full-width band. */
9762
10305
  var markStuck = (nav) => {
9763
10306
  const row = nav.querySelector("[data-open-row]");
@@ -9766,10 +10309,13 @@ var markStuck = (nav) => {
9766
10309
  row.toggleAttribute("data-stuck", top <= 57);
9767
10310
  }
9768
10311
  };
10312
+ /** A read entry's files as adiff counts them: a file two parts of a ticket share counts once. */
10313
+ var getEntryFiles = (block, entry) => entry.kind === "ticket" ? block.tickets.find((ticket) => ticket.number === entry.number)?.files.length ?? 0 : entry.all.length;
9769
10314
  var ReadFold = ({ props, register }) => {
9770
- const isOpen = isReadFoldOpen(props);
9771
- const count = props.done.reduce((sum, group) => sum + group.all.length, 0);
10315
+ const isOpen = isReadFoldOpen(props.state, props.done);
10316
+ const count = props.done.reduce((sum, entry) => sum + getEntryFiles(props.block, entry), 0);
9772
10317
  const isCursor = props.state.cursor === READ_LAYERS;
10318
+ const numbers = props.done.map((entry) => entry.kind === "ticket" ? entry.number : Number(entry.address));
9773
10319
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
9774
10320
  "aria-expanded": isOpen,
9775
10321
  className: `flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-start text-ui text-subtle hover:bg-row-hover ${isCursor ? "tree-cursor bg-secondary" : ""}`,
@@ -9789,7 +10335,7 @@ var ReadFold = ({ props, register }) => {
9789
10335
  }),
9790
10336
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
9791
10337
  className: "flex-1",
9792
- children: `${props.done.length === 1 ? "Layer" : "Layers"} ${nameLayers(props.done)} read`
10338
+ children: `${props.done.length === 1 ? "Layer" : "Layers"} ${nameLayers(numbers)} read`
9793
10339
  }),
9794
10340
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
9795
10341
  className: "text-xs tabular-nums",
@@ -9802,99 +10348,24 @@ var ReadFold = ({ props, register }) => {
9802
10348
  ]
9803
10349
  });
9804
10350
  };
9805
- var isOnLastFile = (group, cursor) => {
9806
- const last = group.files.at(-1);
9807
- return last !== void 0 && cursor === fileKey(group.index, last);
9808
- };
9809
- /** Files the order names that are no longer in the diff, struck through under their own caption. */
9810
- var Vanished = ({ paths }) => paths.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("ul", {
9811
- className: "m-0 list-none ps-8.5 pe-2 pb-1.5",
9812
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", {
9813
- className: "pt-1 text-xs/5 text-subtle",
9814
- children: "gone since the order was written"
9815
- }), paths.map((path) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", {
9816
- className: "truncate font-mono text-xs/5 text-subtle line-through",
9817
- title: path,
9818
- children: path.slice(path.lastIndexOf("/") + 1)
9819
- }, path))]
9820
- });
9821
- var LayerBody = ({ group, props, register }) => {
9822
- const vanished = props.block.layers[group.index]?.vanished ?? [];
9823
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
9824
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RailLead, {
9825
- block: props.block,
9826
- index: group.index,
9827
- onPickFile: props.onPickFile,
9828
- selected: props.state.selected
9829
- }),
9830
- group.all.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
9831
- className: "m-0 ps-8.5 pe-2 pb-2 text-xs text-subtle",
9832
- children: "Nothing left in this diff: its files changed after the order was written."
9833
- }) : null,
9834
- group.files.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LayerFiles, {
9835
- block: props.block,
9836
- cursor: props.state.cursor,
9837
- files: props.files,
9838
- group,
9839
- isReadIn: props.isReadIn,
9840
- onPickFile: props.onPickFile,
9841
- register
9842
- }) : null,
9843
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Vanished, { paths: vanished })
9844
- ] });
9845
- };
9846
- var LayerCard = ({ group, props, register }) => {
9847
- const layer = props.block.layers[group.index];
9848
- const isOpen = isLayerOpen(props.state, group.key);
9849
- return layer === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
9850
- className: "mb-0.5",
9851
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(LayerRow, {
9852
- group,
9853
- isCursor: props.state.cursor === group.key,
9854
- isOpen,
9855
- layer,
9856
- onPick: () => {
9857
- props.onPickLayer(group.key);
9858
- },
9859
- register,
9860
- size: getLayerSize(group, props.block.layers[group.index], props.isReadIn)
9861
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
9862
- className: "fold",
9863
- "data-open": isOpen ? "" : void 0,
9864
- inert: !isOpen,
9865
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LayerBody, {
9866
- group,
9867
- props,
9868
- register
9869
- }) })
9870
- })]
9871
- });
9872
- };
9873
10351
  /**
9874
10352
  * The reading order: a map of the branch, then each layer with its size and what is left to read.
9875
10353
  * Read layers fold into one row; on a layer's last file the next layer is offered in place of
9876
- * its row.
10354
+ * its row. A ticket holds its parts, each read as a layer.
9877
10355
  */
9878
10356
  var ReviewLayers = (props) => {
9879
10357
  const { containerRef, register } = useKeepInView(props.state.cursor);
9880
10358
  const here = getHere(props);
9881
- const doneKeys = new Set(props.done.map((group) => group.key));
9882
- const rest = props.groups.filter((group) => !doneKeys.has(group.key));
9883
- const isReadOpen = isReadFoldOpen(props);
9884
- const shown = isReadOpen ? [...props.done, ...rest] : rest;
9885
- const ending = shown.find((group) => isOnLastFile(group, props.state.cursor));
9886
- const next = ending === void 0 ? void 0 : shown[shown.indexOf(ending) + 1];
9887
- const card = (group) => group === next ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(NextLayer, {
9888
- group,
9889
- onPick: () => {
9890
- props.onPickLayer(group.key);
9891
- },
9892
- size: getLayerSize(group, props.block.layers[group.index], props.isReadIn)
9893
- }, group.key) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LayerCard, {
9894
- group,
10359
+ const doneKeys = new Set(props.done.map((entry) => entry.key));
10360
+ const rest = props.entries.filter((entry) => !doneKeys.has(entry.key));
10361
+ const isReadOpen = isReadFoldOpen(props.state, props.done);
10362
+ const upNext = getUpNext(isReadOpen ? [...props.done, ...rest] : rest, props.state.cursor);
10363
+ const card = (entry) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EntryCard, {
10364
+ entry,
9895
10365
  props,
9896
- register
9897
- }, group.key);
10366
+ register,
10367
+ upNext
10368
+ }, entry.key);
9898
10369
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("nav", {
9899
10370
  "aria-label": "Layers",
9900
10371
  className: "min-h-0 overflow-auto p-2",
@@ -9916,7 +10387,10 @@ var ReviewLayers = (props) => {
9916
10387
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(QuestionFirst, {
9917
10388
  block: props.block,
9918
10389
  groups: props.groups,
9919
- here,
10390
+ isHere: (position) => {
10391
+ const group = props.groups[position - 1];
10392
+ return group !== void 0 && isHereIn(here, group);
10393
+ },
9920
10394
  onPickFile: props.onPickFile
9921
10395
  }),
9922
10396
  props.done.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReadFold, {
@@ -9927,9 +10401,9 @@ var ReviewLayers = (props) => {
9927
10401
  className: "fold",
9928
10402
  "data-open": isReadOpen ? "" : void 0,
9929
10403
  inert: !isReadOpen,
9930
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: props.done.map((group) => card(group)) })
10404
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: props.done.map((entry) => card(entry)) })
9931
10405
  }) : null,
9932
- rest.map((group) => card(group))
10406
+ rest.map((entry) => card(entry))
9933
10407
  ]
9934
10408
  });
9935
10409
  };
@@ -10264,6 +10738,7 @@ var ReviewRail = ({ block, state, setState, model, acts }) => {
10264
10738
  if (state.isLayered && model.hasLayers) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReviewLayers, {
10265
10739
  block,
10266
10740
  done: model.done,
10741
+ entries: model.entries,
10267
10742
  files: model.files,
10268
10743
  groups: model.groups,
10269
10744
  isReadIn: model.marks.isReadIn,
@@ -11105,16 +11580,27 @@ var useReviewKeys = (input) => {
11105
11580
  };
11106
11581
  };
11107
11582
  /**
11583
+ * The layer to read next: by its title, and with its address once the branch has tickets. The
11584
+ * files in no layer have no number anywhere else, so they go by their title alone.
11585
+ */
11586
+ var nameNext = (layer, told) => told.tickets.length === 0 || layer.isRemainder ? layer.title : `${layer.address} ${layer.title}`;
11587
+ /**
11108
11588
  * What to say once adiff answers a mark: "Layer 3 read · Next: Invitations and reminders" when the
11109
- * answer calls layer `index` done and it was not before, else nothing.
11589
+ * answer calls layer `index` done and it was not before, else nothing. A part read inside a ticket
11590
+ * says its own address ("Layer 2.2 read"); the part that finishes the ticket says the ticket's
11591
+ * ("Layer 2 read") and nothing for itself.
11110
11592
  */
11111
11593
  var getDoneSaid = (before, { after, index }) => {
11112
- const now = after?.[index];
11113
- if (after === null || now?.isDone !== true || before[index]?.isDone === true) return null;
11114
- const next = after.find((layer, at) => at > index && layer.files.length > 0);
11594
+ const now = after?.layers[index];
11595
+ if (after === null || now?.isDone !== true || before.layers[index]?.isDone === true) return null;
11596
+ const ticket = after.tickets.find((one) => one.number === now.ticket);
11597
+ const wasDone = before.tickets.find((one) => one.number === now.ticket)?.isDone === true;
11598
+ const finished = ticket !== void 0 && ticket.isDone && !wasDone ? ticket : void 0;
11599
+ const from = finished === void 0 ? index : Math.max(index, ...finished.layers.map((at) => at - 1));
11600
+ const next = after.layers.find((layer, at) => at > from && layer.files.length > 0);
11115
11601
  return {
11116
- title: `Layer ${String(index + 1)} read`,
11117
- description: next === void 0 ? "Every layer is read" : `Next: ${next.title}`
11602
+ title: `Layer ${finished?.address ?? now.address} read`,
11603
+ description: next === void 0 ? "Every layer is read" : `Next: ${nameNext(next, after)}`
11118
11604
  };
11119
11605
  };
11120
11606
  var WHOLE = "*";
@@ -11140,10 +11626,10 @@ var useReviewMarks = ({ deck, point, block, refresh, onLayers }) => {
11140
11626
  setFailure(null);
11141
11627
  setFlips((all) => new Map([...all, [key, wanted]]));
11142
11628
  try {
11143
- const { layers } = await call();
11144
- onLayers(layers);
11629
+ const { told } = await call();
11630
+ onLayers(told);
11145
11631
  await refresh();
11146
- return layers;
11632
+ return told;
11147
11633
  } catch (error) {
11148
11634
  setFailure(`The file was not marked: ${describeFailure(error)}`);
11149
11635
  return null;
@@ -11164,7 +11650,7 @@ var useReviewMarks = ({ deck, point, block, refresh, onLayers }) => {
11164
11650
  };
11165
11651
  return isShared ? flip(flipKey(layer, path), !isReadIn(layer, path), () => markReviewFile({ data: {
11166
11652
  ...target,
11167
- layer: layer + 1
11653
+ layer: block.layers[layer]?.address ?? String(layer + 1)
11168
11654
  } })) : flip(flipKey(null, path), !isReviewed(path), () => markReviewFile({ data: {
11169
11655
  ...target,
11170
11656
  layer: null
@@ -11183,32 +11669,6 @@ var useReviewMarks = ({ deck, point, block, refresh, onLayers }) => {
11183
11669
  }
11184
11670
  };
11185
11671
  };
11186
- var NO_GROUPS = [];
11187
- var getLayout = (block, { state, present, shown, isShownIn }) => {
11188
- if (!state.isLayered || block.layers.length === 0) return {
11189
- rows: getTreeRows(shown, state.collapsed),
11190
- order: getTreeOrder(shown),
11191
- groups: NO_GROUPS,
11192
- done: NO_GROUPS
11193
- };
11194
- const groups = getLayerGroups(block.layers, {
11195
- present,
11196
- isShown: isShownIn
11197
- });
11198
- const here = getLayerAt(state.cursor);
11199
- const isDone = (group) => block.layers[group.index]?.isDone === true;
11200
- const folded = foldReadLayers(groups, {
11201
- isDone,
11202
- isOpen: (group) => isLayerOpen(state, group.key),
11203
- isReadOpen: isLayerOpen(state, "layer:read") || groups.some((group) => group.index === here && isDone(group))
11204
- });
11205
- return {
11206
- rows: folded.rows,
11207
- order: folded.order,
11208
- groups,
11209
- done: folded.done
11210
- };
11211
- };
11212
11672
  var useReviewModel = (props) => {
11213
11673
  const { deck, view, block, state, setState, refresh, onLayers } = props;
11214
11674
  const marks = useReviewMarks({
@@ -11226,35 +11686,31 @@ var useReviewModel = (props) => {
11226
11686
  shown: shownIn(next),
11227
11687
  isShownIn: (index, path) => !next.isHidingReviewed || path === next.selected || !marks.isPartRead(index, path)
11228
11688
  });
11229
- const { rows, order, groups, done } = layoutOf(state);
11689
+ const { rows, order, groups, entries, done } = layoutOf(state);
11230
11690
  const layerOf = (path) => Math.max(0, block.layers.findIndex((layer) => layer.files.includes(path)));
11231
- const everything = layoutOf({
11232
- ...state,
11233
- isHidingReviewed: false,
11234
- layerOpen: {
11235
- ...state.layerOpen,
11236
- [READ_LAYERS]: true
11237
- }
11238
- }).order;
11691
+ const everything = layoutOf(openEveryLayer(state)).order;
11239
11692
  const at = everything.indexOf(state.isLayered ? state.cursor : state.selected);
11240
11693
  return {
11241
11694
  marks,
11242
11695
  rows,
11243
11696
  order,
11244
11697
  groups,
11698
+ entries,
11245
11699
  done,
11246
11700
  hasLayers: block.layers.length > 0,
11247
11701
  rowsFor: (next) => layoutOf(next).rows,
11248
11702
  layerOf,
11249
11703
  /** Whether a file reads as reviewed: in the layers rail, the open layer's part of it. */
11250
11704
  isReadHere: (path) => {
11251
- const open = state.isLayered ? getLayerAt(state.cursor) : null;
11705
+ const open = getRailLayer(state);
11252
11706
  return open === null ? marks.isReviewed(path) : marks.isReadIn(open, path);
11253
11707
  },
11254
11708
  /** Marks a file reviewed or not, and names the layer when adiff's answer calls it newly read. */
11255
11709
  toggleReviewed: async (path, layer) => {
11256
- const before = block.layers;
11257
- const said = getDoneSaid(before, {
11710
+ const said = getDoneSaid({
11711
+ layers: block.layers,
11712
+ tickets: block.tickets
11713
+ }, {
11258
11714
  after: await marks.toggle(path, layer),
11259
11715
  index: layer ?? layerOf(path)
11260
11716
  });
@@ -11279,7 +11735,7 @@ var useReviewModel = (props) => {
11279
11735
  setState(isPhone$1() ? showOnPhone(opened) : opened);
11280
11736
  },
11281
11737
  handlePick: (row) => {
11282
- const picked = pickRow(state, row);
11738
+ const picked = pickRow(state, row, entries);
11283
11739
  setState(row.kind === "file" && isPhone$1() ? showOnPhone(picked) : picked);
11284
11740
  }
11285
11741
  };
@@ -12171,6 +12627,36 @@ var holdPlace = (container, at) => {
12171
12627
  });
12172
12628
  globalThis.setTimeout(stop, HOLD_MS);
12173
12629
  };
12630
+ var withoutKey = (open, key) => Object.fromEntries(Object.entries(open).filter(([candidate]) => candidate !== key));
12631
+ /** The layer the file is open in: the cursor's when it is on the file, else the first that has it. */
12632
+ var getFileLayer = (state, layers) => {
12633
+ const at = getLayerAt(state.cursor);
12634
+ return at !== null && state.cursor === fileKey(at, state.selected) ? at : Math.max(0, layers.findIndex((layer) => layer.files.includes(state.selected)));
12635
+ };
12636
+ /**
12637
+ * The file on screen always shows in the sidebar, whichever way it was opened (a click, `]`, the
12638
+ * panel, search, a type's definition): in the file tree its folders open, in the layers rail its
12639
+ * layer opens, and the read layers' row with it when that layer is read. Only a change of file
12640
+ * reveals it, so the reader can still close the folder or layer it sits in afterwards.
12641
+ */
12642
+ var revealSelected = (previous, next, layers) => {
12643
+ if (next.selected === previous.selected && next.isLayered === previous.isLayered) return next;
12644
+ if (!next.isLayered) {
12645
+ const ancestors = new Set(getAncestors(next.selected));
12646
+ return {
12647
+ ...next,
12648
+ collapsed: new Set([...next.collapsed].filter((dir) => !ancestors.has(dir)))
12649
+ };
12650
+ }
12651
+ const layer = getFileLayer(next, layers);
12652
+ const ticket = layers[layer]?.ticket ?? null;
12653
+ const shut = withoutKey(next.layerOpen, layerKey(layer));
12654
+ return {
12655
+ ...next,
12656
+ cursor: fileKey(layer, next.selected),
12657
+ layerOpen: ticket === null ? shut : withoutKey(shut, ticketKey(ticket))
12658
+ };
12659
+ };
12174
12660
  var SCROLL_MS = 250;
12175
12661
  var DIFF = "[data-review-diff]";
12176
12662
  var RAIL = "[data-review-rail]";
@@ -12324,7 +12810,9 @@ var LoadedReview = ({ outline, refresh, extras, stub, isFullPage = false, ...pro
12324
12810
  kind: "review",
12325
12811
  title: stub.title,
12326
12812
  files: shown.files,
12327
- layers: answered.layers
12813
+ layers: answered.layers,
12814
+ tickets: answered.tickets,
12815
+ threads: answered.threads
12328
12816
  };
12329
12817
  const pane = {
12330
12818
  ...props,