forked from kent/consciousness
Move thalamus subcrate into main crate
Move thalamus/ (poc-daemon) source files into src/thalamus/ as a module of the main crate. The daemon entry point becomes a library function thalamus::run() with a thin poc-daemon binary for backward compatibility. - Copy thalamus source into src/thalamus/, fix crate:: -> super:: - Copy daemon.capnp into schema/, add to build.rs - Re-export daemon_capnp at crate root (capnp codegen requires it) - Add thalamus dependencies (capnp-rpc, tokio-util, toml, rustls, etc.) - Keep thalamus/ subcrate for comparison Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
14dd8d22af
commit
604f442215
16 changed files with 3249 additions and 1 deletions
54
src/thalamus/tmux.rs
Normal file
54
src/thalamus/tmux.rs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
// Tmux interaction: pane detection and prompt injection.
|
||||
|
||||
use std::process::Command;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use tracing::info;
|
||||
|
||||
/// Find Claude Code's tmux pane by scanning for the "claude" process.
|
||||
pub fn find_claude_pane() -> Option<String> {
|
||||
let out = Command::new("tmux")
|
||||
.args([
|
||||
"list-panes",
|
||||
"-a",
|
||||
"-F",
|
||||
"#{session_name}:#{window_index}.#{pane_index}\t#{pane_current_command}",
|
||||
])
|
||||
.output()
|
||||
.ok()?;
|
||||
|
||||
let stdout = String::from_utf8_lossy(&out.stdout);
|
||||
for line in stdout.lines() {
|
||||
if let Some((pane, cmd)) = line.split_once('\t') {
|
||||
if cmd == "claude" {
|
||||
return Some(pane.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Send a prompt to a tmux pane. Returns true on success.
|
||||
///
|
||||
/// Types the message literally then presses Enter.
|
||||
pub fn send_prompt(pane: &str, msg: &str) -> bool {
|
||||
let preview: String = msg.chars().take(100).collect();
|
||||
info!("SEND [{pane}]: {preview}...");
|
||||
|
||||
// Type the message literally (flatten newlines — they'd submit the input early)
|
||||
let flat: String = msg.chars().map(|c| if c == '\n' { ' ' } else { c }).collect();
|
||||
let ok = Command::new("tmux")
|
||||
.args(["send-keys", "-t", pane, "-l", &flat])
|
||||
.output()
|
||||
.is_ok();
|
||||
if !ok {
|
||||
return false;
|
||||
}
|
||||
thread::sleep(Duration::from_millis(500));
|
||||
|
||||
// Submit
|
||||
Command::new("tmux")
|
||||
.args(["send-keys", "-t", pane, "Enter"])
|
||||
.output()
|
||||
.is_ok()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue