Skip to content

Commit 14325cb

Browse files
jlcjakclaude
andcommitted
Tool calls fold into one drawer per run, shut until clicked
A run of tool calls was open by default while its turn ran (the last run, Fold.open's live default), so a working thread showed every call. Now a run is a drawer that only the person's click opens (Fold.run.open, laws fold_run_opened/shut/default_shut/live_shut), running or not; a second click shuts it. The live run's head says what runs now instead ("5 tool calls · running: Bash", Fold.label.live, RHead's live flag, the new string fold.running in en and ja), and pulses on the web. Every client takes it from the same roles: the web's head is one tidy line (View.fold.row.live, classes fold/open/live) and an open run's rows hang under it on a rule (data-run, View.run.mark, style.css); the window (layout.bend) and the phones (Mob.fold.live, "live"; open rows carry "run", Mob.run.mark) draw the same rows. The unused turn fold (Work.turn) is shut while live too (law work_live_open becomes work_live_shut). Fold.open keeps its live default for the subagents' panel and the to-dos. fold_test joins the required fast tests. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 381e771 commit 14325cb

16 files changed

Lines changed: 315 additions & 92 deletions

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ When using Bend:
4242
- `src/core/slash.bend`: slash commands in the composer (pure: the table, Backplane's `/btw` and `/give` for any thread, Claude's `/compact` and `/context` only in a Claude thread; `Slash.typing` is a draft that is one word starting with `/`, `Slash.cmds` those whose name starts with it). The composer's popup (client.bend's `Skills.all`, `Slash.of`) lists them with their text, then the thread's skills as `$name` rows, at most 8; `/` fetches the skills like `$` (`Skills.need`). Esc shuts any popup (`skill-close`, info `sk.off` holds the draft it was shut on, so another edit opens it again; the window's `Esc.menu`, the web's `data-esc`); Tab/Enter/click complete as for skills. Laws `slash_*`; test `test/slash_test.bend`.
4343
- `src/core/links.bend`: links in a message (pure: web addresses, bare or `[label](url)`, and paths to files, bare, in backticks or as a markdown target, with an optional `:12`/`#L12`; `Link.pieces`, `Link.is_path`; laws `link_*`). A link that is not a web address is a file's: a click asks the hub to open it on its machine (`file-open` → `file.open {path, how}`, the hub's `FileJob` runs `Link.file.cmd`: the system opener, or "reveal" through the desktop's FileManager1, Finder on a Mac), a right-click (a tap on phones) opens its menu (client.bend's `Menu.file`, `@menu` `f:<path>`: Open, Show in folder, Copy path; `file-menu`, `file-reveal`, `file-copy`). A relative path is in the thread's folder (`Flink.abs`, `Link.file.abs`). Tests: `test/links_test.bend`, `test/sidebar_test.bend`.
4444
- Markdown: one parser for all four clients, `Md.render` in `src/web/dom.bend` (paragraphs, headings, lists, ordered lists keeping their numbers (`li value`), blockquotes, rules, fenced code, tables (a `|---|` row makes the first row the head: `Md.headed`), inline code, bold, italics, links; laws `md_*`, test `test/md_test.bend`). The web writes its nodes; phones get them as JSON (`Mob.nodes`, an item's number as `n`) and draw them natively (`Markdown.swift`, `Markdown.kt`: a table is a grid, columns as wide as their widest cell up to 240, scrolling sideways); the window lays them out as lines (layout.bend's `TL.block`: a table as kind 18/19/20 lines, each column as wide as its widest cell, the wide ones shrunk to the panel, cells wrapped; quotes kind 22, rules 21).
45-
- `src/core/fold.bend`: runs of tool calls folded into one row (pure: groups, labels, per-entry roles; open state is `fold:<first id>` in the Ui info map, the "fold" action; laws `fold_*`). The window applies the roles each frame over the memo (`TL.entries.mr`, kind 14 lines), the web in `View.entries`. Test: `test/fold_test.bend`.
45+
- `src/core/fold.bend`: runs of tool calls folded into one row, a drawer shut until the person clicks it, running or not (pure: groups, labels, per-entry roles; open state is `fold:<first id>` in the Ui info map, written only by the "fold" action and a history jump, `Fold.reveal`; `Fold.run.open`, laws `fold_run_*`). The live run (the last thing while its turn runs, `RHead`'s `live`) reads "5 tool calls · running: Bash" (`Fold.label.live`). The window applies the roles each frame over the memo (`TL.entries.mr`, kind 14 lines), the web in `View.entries` (head `View.fold.row.live`, classes `fold open live`), the phones in `Mob.entries` (`live` on the row). An open run's rows name their run (web `data-run`, `View.run.mark`; phones `run`, `Mob.run.mark`) so the hub-drawn page's kept history (timeline-history.bend's `H.shut`) and the phones' (thin-native-host's `projectHistory`) drop them once it is shut. Tests: `test/fold_test.bend`, `test/timeline_history_test.bend`, `node test/tools/native_thin_bridge_307265.mjs`.
4646
- `src/core/edit.bend`: text editing for the window's fields (word and line motions, ranges, undo history); `nui.bend`'s `Ed` maps keys onto it. The composer moves by the lines it shows: Up/Down and a press or drag in it leave a request in the scratch (`@cq`, nui.bend's `Cq`) that main.bend places after each event with the font (`Comp.pend` in layout.bend, over `Edit.starts`). Test: `test/edit_test.bend`. Thread text selection is `TSel` in `layout.bend` and `Sel.*` in `nui.bend` (test `test/select_test.bend`).
4747
- One hub per home: a hub holds an exclusive flock on `<home>/hub.lock` for its whole life (server.bend's `Lock.*`, `src/server/hublock.bend` + `effects/hublock.js`, pure answers in `src/core/onehub.bend`, laws `onehub_*`), taken before anything touches the event store; the file says `<pid> <port> flock`. The kernel drops the lock when the process dies (SIGKILL too), so a stale file blocks no one; the descriptor is close-on-exec, so no child holds it, and a restart in place hands it over (the host's `Sys.exec`; the new image takes it back from `BACKPLANE_HUB_LOCK_FD`). A window started while one runs for the same home joins it over its port (main.bend's `Start.hub`; the address is the client's `local.hub`, and a dropped link is tried again); `--headless` and `backplane-serve` print "a hub already serves <home> (pid P, port N)" and exit 1. A file without `flock` is an older hub's, believed while its pid lives (`Lock.find.sh`). Two hubs on one log each kept their own state, so what one client sent never reached the others. End to end: `bun test/tools/onehub_e2e.ts [BINARY] [WIREDIR]`.
4848
- The command line is strict (`src/core/cli.bend`, `Cli.of`, laws `cli_*`, test `test/cli_test.bend`), checked first in both mains before any other IO: the hub's flags are `--home DIR --port N --host ADDR --web DIR --no-tailscale --tailscale --tailscale-https --headless --foreground`, and the children's (`--review`, `--plot`, `--plot-tree`, `--plot-info`, `--render`) come first. An unknown flag, a word, or a flag without its value prints the usage to stderr and exits 2; `--help`/`-h` prints it and `--version` the version, exit 0. None of them opens the home, binds a port or opens a window. A new flag goes into `Cli.kind`.

‎LAWS.bend‎

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,9 +1669,9 @@ law fold_never_message:
16691669
for +a: Nat
16701670
{FO.Fold.tool(M.Msg{i, t, r, x, a}) == False{} : Bool}
16711671

1672-
# a run the user opened stays open and one they shut stays shut, live or
1673-
# not; one nobody touched is open only while live (the last thing in a
1674-
# thread whose turn runs), so it shuts once the turn ends
1672+
# a panel the user opened stays open and one they shut stays shut, live
1673+
# or not; one nobody touched is open only while live (Fold.open: the
1674+
# subagents' panel and the to-dos; a run of tool calls is fold_run_*)
16751675
law fold_user_opened:
16761676
for +live: Bool
16771677
{FO.Fold.open("1", live) == True{} : Bool}
@@ -1684,6 +1684,32 @@ law fold_default_live:
16841684
for +live: Bool
16851685
{FO.Fold.open("", live) == live : Bool}
16861686

1687+
# a run of tool calls is a drawer the person opens: their click opens it
1688+
# and shuts it again, and one nobody touched is shut, whether its turn
1689+
# runs (live) or not
1690+
law fold_run_opened:
1691+
for +live: Bool
1692+
{FO.Fold.run.open("1", live) == True{} : Bool}
1693+
1694+
law fold_run_shut:
1695+
for +live: Bool
1696+
{FO.Fold.run.open("0", live) == False{} : Bool}
1697+
1698+
law fold_run_default_shut:
1699+
for +live: Bool
1700+
{FO.Fold.run.open("", live) == False{} : Bool}
1701+
1702+
# so a thread whose turn runs and whose last entry is a tool call shows
1703+
# that call's run shut, its row saying what runs now
1704+
law fold_run_live_shut:
1705+
for +i: String
1706+
for +th: String
1707+
for +k: String
1708+
for +s: String
1709+
for +a: Nat
1710+
{FO.Fold.roles([M.Act{i, th, "tool", k, s, a}], Map.new(&2, String), True{})
1711+
== [FO.RHead{i, "1 tool call · running: " ++ k, False{}, True{}}] : List<&2, FO.Role>}
1712+
16871713
# a message is never folded away: it shows as itself wherever it sits
16881714
law fold_roles_message_shown:
16891715
for +i: String
@@ -1697,7 +1723,7 @@ law fold_roles_message_shown:
16971723
{List.head(&2, FO.Role, FO.Fold.roles(M.Msg{i, th, r, x, a} <> t, info, running)) == Some{FO.RShow{}} : Maybe<&2, FO.Role>}
16981724

16991725
# a turn's work folds under its message: the message itself is never in
1700-
# it, and while the turn runs its work stays open until shut by hand
1726+
# it, and while the turn runs its work stays shut until opened by hand
17011727
law work_message_shown:
17021728
for live: Bool
17031729
for +u: M.Entry
@@ -1706,13 +1732,13 @@ law work_message_shown:
17061732
for +now: Nat
17071733
{List.head(&2, FO.WRole, FO.Work.turn(live, u, b, info, now)) == Some{FO.WPlain{}} : Maybe<&2, FO.WRole>}
17081734

1709-
law work_live_open:
1735+
law work_live_shut:
17101736
for +u: M.Entry
17111737
for +e: M.Entry
17121738
for +t: List<&2, M.Entry>
17131739
for +now: Nat
17141740
{FO.Work.turn(True{}, u, e <> t, Map.new(&2, String), now)
1715-
== FO.WPlain{} <> FO.WHead{FO.Work.id(u), "Working · started " ++ FO.Work.ago(M.Time.ago(now, FO.Work.at(u))), True{}} <> FO.Work.ins(t, True{}) : List<&2, FO.WRole>}
1741+
== FO.WPlain{} <> FO.WHead{FO.Work.id(u), "Working · started " ++ FO.Work.ago(M.Time.ago(now, FO.Work.at(u))), False{}} <> FO.Work.ins(t, False{}) : List<&2, FO.WRole>}
17161742

17171743
# "/btw <question>" asks beside the turn: only the word itself starts one,
17181744
# and the hub answers it with a job alone, logging nothing, so the thread

‎PROOF.bend‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3684,6 +3684,18 @@ def Laws.fold_user_shut(live):
36843684
def Laws.fold_default_live(live):
36853685
{==}
36863686

3687+
def Laws.fold_run_opened(live):
3688+
{==}
3689+
3690+
def Laws.fold_run_shut(live):
3691+
{==}
3692+
3693+
def Laws.fold_run_default_shut(live):
3694+
{==}
3695+
3696+
def Laws.fold_run_live_shut(i, th, k, s, a):
3697+
{==}
3698+
36873699
def Laws.hub_frames_cbor(t):
36883700
{==}
36893701

@@ -4714,7 +4726,7 @@ def Laws.work_message_shown(live, u, b, info, now):
47144726
case False{}:
47154727
{==}
47164728

4717-
def Laws.work_live_open(u, e, t, now):
4729+
def Laws.work_live_shut(u, e, t, now):
47184730
{==}
47194731

47204732
def Laws.btw_command():

‎i18n/en.msg‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ fold.steps = {count} {plural, select, one {design change} other {design changes}
270270
fold.more = , …
271271
fold.worked = Worked for {took} · {ago}
272272
fold.working = Working · started {ago}
273+
fold.running = running: {kind}
273274

274275
# bot tabs and moods
275276
bots.tab.chat = Chat

‎i18n/ja.msg‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ fold.more = 、…
283283
fold.worked = {took}作業 · {ago}
284284
# ja? reads "たった今から" when the turn just started
285285
fold.working = 作業中 · {ago}から
286+
fold.running = 実行中: {kind}
286287

287288
# bot tabs and moods
288289
bots.tab.chat = チャット

‎scripts/fast-tests.txt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ test/hotboot_test.bend
2121
test/timeline_virtual_test.bend
2222

2323
test/timeline_history_test.bend
24+
25+
# Tool calls fold into drawers, shut until the person clicks one (laws fold_run_*).
26+
test/fold_test.bend

‎src/app/layout.bend‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6520,7 +6520,7 @@ def TL.role(r: FO.Role, +ty: Ty, ls: List<&2, TLine>, +px: U32) -> List<&2, TLin
65206520
match r:
65216521
case FO.RShow{}:
65226522
ls
6523-
case FO.RHead{+id, +label, +open}:
6523+
case FO.RHead{+id, +label, +open, _}:
65246524
TL.fold.line(ty, id, label, open, px) <> TL.fold.shown(open, ls)
65256525
case FO.RIn{open}:
65266526
TL.fold.shown(open, ls)
@@ -6536,8 +6536,8 @@ def TL.turn(t: M.Thread) -> Bool:
65366536
case M.Thread{_, _, _, _, _, turn, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _}:
65376537
Lay.running(turn)
65386538

6539-
# the roles of the open thread's entries (its last run stays open while
6540-
# its turn runs)
6539+
# the roles of the open thread's entries (every run shut until the
6540+
# person opens it; the live one's row says what runs now)
65416541
def TL.roles.loc(+l: I.Loc, es: List<&2, M.Entry>, +st: M.State, +sel: String, +pics: Map<&2, String>) -> List<&2, FO.Role>:
65426542
FO.Fold.roles.loc(l, es, pics, TL.turn(U.Ui.thread(st, sel)))
65436543

‎src/core/fold.bend‎

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ import ./model.bend as M
1111
# Grouping loses no entry and keeps the order (law fold_keeps_entries), and
1212
# a run holds only tool calls (law fold_runs_only_tools).
1313
#
14-
# A run is open when the user opened it ("fold:<first id>" is "1" in the
15-
# client's info map), shut when they shut it ("0"), and otherwise open only
16-
# while it is the live one: the last thing in a thread whose turn runs.
14+
# A run is a drawer, shut unless the person opened it: "fold:<first id>"
15+
# is "1" in the client's info map after a click on its row (or a jump to
16+
# one of its calls, Fold.reveal), "0" after a click that shut it. With
17+
# nothing stored it is shut, whether its turn runs or not (laws
18+
# fold_run_*): only the person's own click opens one. The live run (the
19+
# last thing in a thread whose turn runs) says on its row what it does
20+
# now ("3 tool calls · running: Bash", Fold.label.live), so the work shows
21+
# without opening it.
1722
#
1823
# Only tool calls fold: a turn's messages always show (law
1924
# fold_roles_message_shown). The turn fold below ("Worked for …", Work.*)
@@ -186,6 +191,32 @@ def Fold.label(+l: I.Loc, +es: List<&2, M.Entry>) -> String:
186191
Bool.pick(String, Nat.is_eq(n, 0n), Fold.steps.label(l, d),
187192
Fold.calls.label(l, n, Fold.kinds(Fold.calls(es), Nil{})) ++ Bool.pick(String, Nat.is_eq(d, 0n), "", " · " ++ Fold.steps.label(l, d)))
188193

194+
# the kind of a run's latest call ("" with none)
195+
def Fold.latest(es: List<&2, M.Entry>, +acc: String) -> String:
196+
match es:
197+
case Nil{}:
198+
acc
199+
case +e <> t:
200+
Fold.latest(t, Fold.kind(e))
201+
202+
# the live run's row: how many calls, then what the latest is
203+
# ("6 tool calls · running: Bash"); a run of design changes alone reads
204+
# as Fold.label
205+
def Fold.label.live(+l: I.Loc, +es: List<&2, M.Entry>) -> String:
206+
+n = List.length(&2, M.Entry, Fold.calls(es))
207+
+d = Fold.steps(es)
208+
Bool.pick(String, Nat.is_eq(n, 0n), Fold.steps.label(l, d),
209+
MSG.T.fold.calls(l, Nat.show(n), Bool.pick(String, Nat.is_eq(n, 1n), "one", "other"))
210+
++ Bool.pick(String, Nat.is_eq(d, 0n), "", " · " ++ Fold.steps.label(l, d))
211+
++ " · " ++ MSG.T.fold.running(l, Fold.latest(Fold.calls(es), "")))
212+
213+
def Fold.label.k(live: Bool, +l: I.Loc, +es: List<&2, M.Entry>) -> String:
214+
match live:
215+
case True{}:
216+
Fold.label.live(l, es)
217+
case False{}:
218+
Fold.label(l, es)
219+
189220
# the run's id: its first entry's
190221
def Fold.run_id(es: List<&2, M.Entry>) -> String:
191222
match es:
@@ -209,9 +240,16 @@ def Fold.user(m: Map<&2, String>, +id: String) -> String:
209240
Fold.user.k(Map.get(String, "", m, Fold.key(id)))
210241

211242
# the user's choice ("1" open, "0" shut) or, with none, whether it is live
243+
# (the subagents' and the to-dos' panels; a run of tool calls is
244+
# Fold.run.open)
212245
def Fold.open(+user: String, live: Bool) -> Bool:
213246
Bool.pick(Bool, String.eq(user, "1"), True{}, Bool.pick(Bool, String.eq(user, "0"), False{}, live))
214247

248+
# a run of tool calls: open only when the person opened it, live or not
249+
# ("0" or nothing: shut)
250+
def Fold.run.open(+user: String, live: Bool) -> Bool:
251+
String.eq(user, "1")
252+
215253
# a click's value: the state it asks for, then the run's id
216254
def Fold.ask(+open: Bool, +id: String) -> String:
217255
Bool.pick(String, open, "0", "1") ++ id
@@ -221,11 +259,12 @@ def Fold.ask(+open: Bool, +id: String) -> String:
221259
# What each entry shows as, one role per entry in order (Fold.flat), for a
222260
# UI that walks its entries: as it is, as the first of a run (the run's
223261
# row, then the entry itself when open) or as a later one (itself when
224-
# open).
262+
# open). A head is live while it is the last thing of a running turn (its
263+
# label then says what runs now).
225264

226265
type Role is Data:
227266
RShow{}
228-
RHead{id: String, label: String, open: Bool}
267+
RHead{id: String, label: String, open: Bool, live: Bool}
229268
RIn{open: Bool}
230269
# the first entry of a turn's work: the turn's row, then (when open) the
231270
# entry as its own role says
@@ -238,12 +277,12 @@ def Fold.ins(es: List<&2, M.Entry>, +open: Bool) -> List<&2, Role>:
238277
case _ <> t:
239278
RIn{open} <> Fold.ins(t, open)
240279

241-
def Fold.run.roles(+l: I.Loc, +es: List<&2, M.Entry>, +open: Bool) -> List<&2, Role>:
280+
def Fold.run.roles(+l: I.Loc, +es: List<&2, M.Entry>, +open: Bool, +live: Bool) -> List<&2, Role>:
242281
match es:
243282
case Nil{}:
244283
Nil{}
245284
case _ <> t:
246-
RHead{Fold.run_id(es), Fold.label(l, es), open} <> Fold.ins(t, open)
285+
RHead{Fold.run_id(es), Fold.label.k(live, l, es), open, live} <> Fold.ins(t, open)
247286

248287
def Fold.last(gs: List<&2, Grp>) -> Bool:
249288
match gs:
@@ -257,7 +296,8 @@ def Fold.grp.roles(+l: I.Loc, g: Grp, last: Bool, +info: Map<&2, String>, +runni
257296
case GOne{_}:
258297
[RShow{}]
259298
case GRun{+xs}:
260-
Fold.run.roles(l, xs, Fold.open(Fold.user(info, Fold.run_id(xs)), Bool.and(last, running)))
299+
+live = Bool.and(last, running)
300+
Fold.run.roles(l, xs, Fold.run.open(Fold.user(info, Fold.run_id(xs)), live), live)
261301

262302
def Fold.roles.go(+l: I.Loc, gs: List<&2, Grp>, +info: Map<&2, String>, +running: Bool) -> List<&2, Role>:
263303
match gs:
@@ -390,11 +430,12 @@ def Work.done(+l: I.Loc, +m: Maybe<&2, Nat>, +b: List<&2, M.Entry>, +u: M.Entry,
390430
case _:
391431
Work.plain(b)
392432

393-
# the turn still running: all of it is work, open unless shut
433+
# the turn still running: all of it is work, shut unless opened (as a run
434+
# of tool calls, Fold.run.open)
394435
def Work.turn.loc(+l: I.Loc, live: Bool, +u: M.Entry, +b: List<&2, M.Entry>, +info: Map<&2, String>, +now: Nat) -> List<&2, WRole>:
395436
match live:
396437
case True{}:
397-
WPlain{} <> Work.block(b, Work.id(u), MSG.T.fold.working(l, Work.ago.loc(l, now, Work.at(u))), Fold.open(Fold.user(info, Work.id(u)), True{}))
438+
WPlain{} <> Work.block(b, Work.id(u), MSG.T.fold.working(l, Work.ago.loc(l, now, Work.at(u))), Fold.run.open(Fold.user(info, Work.id(u)), True{}))
398439
case False{}:
399440
WPlain{} <> Work.done(l, Work.last(b, 0n, None{}), b, u, info, now)
400441

0 commit comments

Comments
 (0)