Repository navigation
fix(agent): keep a catbus tab's session through restarts, and make claude-only agent-only #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| //! The forced agent-only mode switch (`POST /agent-only`), queued to the | ||
| //! owner which mirrors it onto the process-global and persists. | ||
|
|
||
| use std::sync::{Arc, Mutex}; | ||
|
|
||
| use serde::Serialize; | ||
| use tab_atelier_api::schemars::JsonSchema; | ||
| use tab_atelier_api::{Doc, Failure, Request}; | ||
| // The derive emits `schemars::` paths, so the name itself has to be in scope. | ||
| use tab_atelier_api::schemars; | ||
|
|
||
| use super::TabSnapshot; | ||
|
|
||
| /// The acknowledgement a queued toggle answers. | ||
| #[derive(Debug, Serialize, JsonSchema)] | ||
| pub(super) struct Queued { | ||
| queued: &'static str, | ||
| } | ||
|
|
||
| const BODY_HINT: &str = r#"provide {"agent": "claude"|"catbus"|"off"}"#; | ||
|
|
||
| pub(super) fn set(request: &Request<'_>, state: &Arc<Mutex<TabSnapshot>>) -> Result<Doc<Queued>, Failure> { | ||
| // Switch forced agent-only mode live (the CLI `agent-only …`). | ||
| // Body: {"agent": "claude"|"catbus"|"off"}. The owner mirrors it onto the | ||
| // global + its struct field and persists, so new tabs launch that agent | ||
| // or a shell with no restart. | ||
| let parsed: serde_json::Value = | ||
| serde_json::from_slice(request.body).map_err(|e| Failure::problem(400, format!("invalid JSON body: {e}")))?; | ||
| let agent = match parsed.get("agent").and_then(serde_json::Value::as_str) { | ||
| Some("off") => crate::AgentOnlyChange::Off, | ||
| Some(word) => match crate::AgentOnly::parse(word) { | ||
| Some(agent) => crate::AgentOnlyChange::On(agent), | ||
| None => return Err(Failure::problem(400, BODY_HINT)), | ||
| }, | ||
| None => return Err(Failure::problem(400, BODY_HINT)), | ||
| }; | ||
| let mut snap = state.lock().unwrap_or_else(std::sync::PoisonError::into_inner); | ||
| snap.pending_agent_only = Some(agent); | ||
| drop(snap); | ||
| Ok(Doc::ok(Queued { queued: "agent-only" })) | ||
| } |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if user does mix no tui sessions and normal dessions in the tab lifetime?
Does it stay coherent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not fully, as first pushed — good catch. Three cases:
--no-tuione starts, or the reverse): coherent. The last one started is the tab's session. One caveat that this PR does not change: the app restores withcatbus-agent --resume <id>only, so a--no-tuisession comes back with its conversation but as a TUI.--no-tuisession started behind the tab's agent (from a tool call, say): this was broken. Both reported, and each took the tab's session id back on its next turn. Fixed in 1b992a3: only a session whose stdin is the tab's terminal reports (owns_the_tabnow takeson_terminal). 9f6bbe1 gives the existing abandoned-turn test's agent a terminal, since it models a tab's own process.&in the tab's shell): still last-report-wins. I left that alone; telling them apart needs the foreground process group, which meansunsafeor a new dependency in a crate that deniesunsafe.catbus-agent: clippy clean, 649 tests pass.
Generated by Claude Code