Bootstrap tamq local tmux agent message queue
Some checks failed
tamq-ci / test (push) Failing after 36s
Some checks failed
tamq-ci / test (push) Failing after 36s
Assistant: codex Assistant-Model: gpt-5.6-sol Assistant-Session: 01a02f34-ead4-7a60-85cd-d7f08e22fa0e
This commit is contained in:
parent
521bbe5afc
commit
4d915a2617
58 changed files with 1882 additions and 1 deletions
45
src/tamq/control.py
Normal file
45
src/tamq/control.py
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import subprocess
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
class ControlModeError(RuntimeError):
|
||||
pass
|
||||
|
||||
|
||||
@dataclass
|
||||
class ControlModeClient:
|
||||
session: str
|
||||
process: subprocess.Popen[str] | None = None
|
||||
|
||||
def start(self) -> None:
|
||||
if self.process is not None:
|
||||
return
|
||||
self.process = subprocess.Popen(
|
||||
["tmux", "-C", "attach-session", "-t", self.session],
|
||||
stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True,
|
||||
bufsize=1,
|
||||
)
|
||||
|
||||
def command(self, value: str) -> None:
|
||||
if self.process is None or self.process.stdin is None:
|
||||
raise ControlModeError("control-mode client is not started")
|
||||
self.process.stdin.write(value.rstrip("\n") + "\n")
|
||||
self.process.stdin.flush()
|
||||
|
||||
def inject(self, window: str, text: str) -> None:
|
||||
# send-keys -l preserves punctuation and whitespace in the message.
|
||||
self.command(f"send-keys -t {window} -l -- {shell_quote(text)}")
|
||||
|
||||
def close(self) -> None:
|
||||
if self.process is not None:
|
||||
self.process.terminate()
|
||||
self.process = None
|
||||
|
||||
|
||||
def shell_quote(value: str) -> str:
|
||||
return "'" + value.replace("'", "'\\''") + "'"
|
||||
Loading…
Add table
Add a link
Reference in a new issue