Repository navigation
Commit 20f994c
authored
feat(session): bring agents back after a restart as an unsent resume line (#389)
* feat(session): bring agents back after a restart as an unsent resume line
Every Crook update is a restart, and a restart ended every running agent:
restore brought back an empty shell. A pane now remembers the agent it was
running, by its program name only, and comes back with that agent's resume
line waiting in its composer, unsent.
- PaneSnapshot gains `agent`: the first word of the pane's running command,
by file name, and only when it names a program in agent.rs's table, so a
prompt typed on the command line never reaches session.json. A value that
is not a string reads as no agent rather than costing the tab. The session
is saved when a pane's agent changes.
- A restored pane keeps the agent (AgentSession::restored_agent) until
anything runs there, so a second restart before Enter still offers it, and
only when its directory came back, since the directory is the session key.
- On restore the composer holds `claude --continue`, `codex resume --last`,
`gemini --resume latest` or `copilot --resume`; two panes of one agent in
one directory get the picker (`claude --resume`, `codex resume`) or, with
none, nothing. OpenCode gets no default: its `--continue` crosses a
repository's root-level worktrees (anomalyco/opencode#41562).
- `resume_lines` in settings.json overrides the line per program; only what
a person wrote is stored, so a later build's corrected flags still reach
them, and an empty line turns an agent off.
- "Resume every agent" (crook/window/resume-agents) submits every restored
line still standing exactly as typed, and declines when there is none.
- README, skill.md and docs/architecture.md say what is remembered and that
nothing runs until Enter.
* fix(session): forget a restored agent once any command finishes in its pane
A restored pane named its agent until a TerminalUpdate::Running(Some)
arrived, but Running is read off the pane at rest, so a command that
starts and ends between two reads (cd, ls, git status) never sent one.
After a cd the pane kept the agent and the next save wrote it against the
new directory, where `claude --continue` would resume another
conversation.
TerminalUpdate::CommandFinished comes from the shell's D mark, sent for
every command however quick. On it the workspace now drops the pane's
resume offer and AgentSession::command_finished clears restored_agent,
and the session is saved when that changed the agent. An agent the pane
is running now stays named.
Tests: a CommandFinished alone spends the agent and writes it out of the
file; a real shell's cd out of the restored directory does the same; the
session-level check covers a quick command and a running agent.
* fix(session): take a restored resume line out of the field for --run and --type
A windowed launch restores the session, which types an agent's resume
line into the focused pane's field, and then --run and --type type into
that same field at the caret. `--run 'git status'` sent
`claude --continuegit status`, and `--type x` left `claude --continuex`.
After the overrides, a launch that types into the field
(Overrides::types_into_the_field) now calls
Workspace::withdraw_resume_offer on the focused pane, which empties the
field when it still holds the line exactly as the restore typed it and
drops the offer. The pane's agent stays named: a command the launch runs
spends it the way any finished command does.
Tests: a withdrawn field takes a typed line as its whole text, an edited
one is left alone, and the agent is still named; the override predicate
is covered in lib's tests.
* docs(session): say which agents a restored pane offers a line to
The README said two panes of one agent in one directory get its picker,
but Gemini CLI has none and they get nothing; it now says so, and that
any command run first, a cd included, ends the offer. skill.md said every
known agent comes back with its resume line; it now names the four that
do and says OpenCode and aider get one only from resume_lines.
docs/architecture.md adds "or nothing where it has none" to the picker
rule.
agent.rs said aider keeps no conversation to go back to, but aider
documents --restore-chat-history. It now says aider has no default line
and that flag is one a person can give it, and the README names aider
beside OpenCode as having no line until one is given.
* fix(session): keep a restored agent through a line that ran nothing
A pane forgot its restored agent on every TerminalUpdate::CommandFinished,
and that update also comes from the bare D a shell sends for a line that
ran nothing: ctrl-c at the prompt and Enter on an empty field in bash and
zsh, and ctrl-c in fish. Clearing the offered `claude --continue` with
ctrl-c saved the session with "agent": null, and the next restart offered
nothing, though nothing had run. Clearing it with Backspace kept it.
The block model now says whether a command ran behind the boundary it
closed: Finished::ran is true when the block has a command line or the
shell sent C for it. It is read before the close takes the command, and
it rides on TerminalEvent::CommandFinished and
TerminalUpdate::CommandFinished. The workspace spends the restored agent
only when it is true. Plugins still hear every D, as before. The status
is not the test, because bash 3.2 sends a bare D for a `( ... )` line,
which did run.
The README now says clearing the line keeps the offer for the next
restart. The doc on AgentSession::command_finished and on
spend_restored_agent says a line that ran nothing does not call them.
Tests: through a real shell, ctrl-c and an empty Enter at the prompt
leave the agent named, in the pane and in what the file would say. In
the block model, ctrl-c, an empty line and a repeated D report no run,
and a subshell line, a C with no B and an ordinary command report one.
* test(session): cover --run and --type opening on an empty field after a restore
The step that takes a restored resume line back out of the field for
--run and --type lived inline in Shell::new, which no test reaches. The
workspace test called Workspace::withdraw_resume_offer by hand, so
deleting the step, moving it above the restore or turning its guard
around failed nothing, and `claude --continuegit status` could come back
unnoticed.
The restore, the overrides and the withdrawal are now one function,
restore_and_override, which Shell::new calls. Its test opens a restored
claude pane through it three times: with --run and with --type the field
is empty, and with neither it still holds `claude --continue`. Removing
the withdrawal, putting it before the restore, inverting
types_into_the_field or dropping that guard each fails the test.
* test(session): say whether a finished command ran in the tests main added1 parent 9c712f9 commit 20f994c
19 files changed
Lines changed: 1683 additions & 42 deletions
File tree
- app/src
- plugins
- tab
- workspace
- crates/crook_terminal/src
- docs
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
181 | 204 | | |
182 | 205 | | |
183 | 206 | | |
| |||
503 | 526 | | |
504 | 527 | | |
505 | 528 | | |
506 | | - | |
| 529 | + | |
| 530 | + | |
507 | 531 | | |
508 | 532 | | |
509 | 533 | | |
| |||
535 | 559 | | |
536 | 560 | | |
537 | 561 | | |
538 | | - | |
| 562 | + | |
539 | 563 | | |
540 | 564 | | |
541 | 565 | | |
| |||
561 | 585 | | |
562 | 586 | | |
563 | 587 | | |
564 | | - | |
| 588 | + | |
| 589 | + | |
565 | 590 | | |
566 | 591 | | |
567 | 592 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
28 | 34 | | |
29 | 35 | | |
30 | 36 | | |
| |||
227 | 233 | | |
228 | 234 | | |
229 | 235 | | |
230 | | - | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
231 | 240 | | |
232 | 241 | | |
233 | 242 | | |
234 | 243 | | |
235 | 244 | | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
236 | 267 | | |
237 | 268 | | |
238 | 269 | | |
| |||
391 | 422 | | |
392 | 423 | | |
393 | 424 | | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
394 | 443 | | |
395 | 444 | | |
396 | 445 | | |
| |||
400 | 449 | | |
401 | 450 | | |
402 | 451 | | |
| 452 | + | |
| 453 | + | |
403 | 454 | | |
404 | 455 | | |
405 | 456 | | |
| |||
410 | 461 | | |
411 | 462 | | |
412 | 463 | | |
| 464 | + | |
| 465 | + | |
413 | 466 | | |
414 | 467 | | |
415 | 468 | | |
| |||
420 | 473 | | |
421 | 474 | | |
422 | 475 | | |
| 476 | + | |
| 477 | + | |
423 | 478 | | |
424 | 479 | | |
425 | 480 | | |
| |||
428 | 483 | | |
429 | 484 | | |
430 | 485 | | |
| 486 | + | |
| 487 | + | |
431 | 488 | | |
432 | 489 | | |
433 | 490 | | |
| |||
436 | 493 | | |
437 | 494 | | |
438 | 495 | | |
| 496 | + | |
| 497 | + | |
439 | 498 | | |
440 | 499 | | |
441 | 500 | | |
| |||
446 | 505 | | |
447 | 506 | | |
448 | 507 | | |
| 508 | + | |
| 509 | + | |
449 | 510 | | |
450 | 511 | | |
451 | 512 | | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
452 | 552 | | |
453 | 553 | | |
454 | 554 | | |
| |||
833 | 933 | | |
834 | 934 | | |
835 | 935 | | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
836 | 1016 | | |
837 | 1017 | | |
838 | 1018 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
283 | 283 | | |
284 | 284 | | |
285 | 285 | | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
286 | 289 | | |
287 | 290 | | |
288 | 291 | | |
| |||
0 commit comments