add 'diwan remote <machine>' to open the diwan workspace on a saved herdr machine
Threads an optional machine= kwarg through herdr_json/ herdr_diwan_workspace_id (default None, fully backward compatible), reusing the exact focus-then-attach pattern cmd_bare already uses locally, just against --machine <label> for the scripted focus call and --remote <machine> for the actual interactive attach. Verified: argparse wiring, the no-herdr-on-PATH dry-run path, and that a bogus --machine label fails fast and cleanly (not a hang) rather than attempting a real network connection -- confirms the warning-then-exec fallback in cmd_remote is safe. Did not test an actual real remote attach (no SSH path to any herdr server from this sandbox).
This commit is contained in:
1 parent
c7859400a1
commit
43215d6e0a
2 files changed
+38
-7
No files matched your search
@@ -122,6 +122,8 @@ Sessions are herdr (https://herdr.dev) terminals, not a diwan-invented session s
|
|||||||
|
|
||||||
To resume a `DIWAN_ID`, `diwan` first checks whether its agent is still alive (`herdr agent get <id>`) and just prompts it if so; if the process has exited (normal between ticks), it finds the tab by label and starts a fresh agent in the same pane, in the same working directory — the heading's own content is what carries continuity, not agent conversation history. `diwan` shells out to the real `herdr` CLI (the `diwan` CLI has the exact calls, verified live against herdr 0.9.5; run `herdr --skill` to check this hasn't drifted on a newer version). When `herdr` isn't on PATH, every call prints what it would have run instead of failing, so the pipeline stays testable without herdr installed.
|
To resume a `DIWAN_ID`, `diwan` first checks whether its agent is still alive (`herdr agent get <id>`) and just prompts it if so; if the process has exited (normal between ticks), it finds the tab by label and starts a fresh agent in the same pane, in the same working directory — the heading's own content is what carries continuity, not agent conversation history. `diwan` shells out to the real `herdr` CLI (the `diwan` CLI has the exact calls, verified live against herdr 0.9.5; run `herdr --skill` to check this hasn't drifted on a newer version). When `herdr` isn't on PATH, every call prints what it would have run instead of failing, so the pipeline stays testable without herdr installed.
|
||||||
|
|
||||||
|
Bare `diwan` (no subcommand) focuses the local `diwan` workspace and attaches you to it interactively. `diwan remote <machine>` does the same against a herdr machine saved via `herdr machine add <ssh-target>` (see herdr's own `--help`/`--skill` for setting one up) — it focuses that machine's `diwan` workspace over the scripted `--machine` API, then execs `herdr --remote <machine>` to open an interactive attach into it. This relies on `<machine>` being usable both as a saved machine label (for the focus step) and as a raw `--remote` SSH target (for the attach) — true by default, since `herdr machine add` labels a profile after its SSH target unless `--label` overrides it.
|
||||||
|
|
||||||
## The harness is `pi`
|
## The harness is `pi`
|
||||||
|
|
||||||
diwan dispatches `pi`, and only `pi` — not a pluggable choice. It's the only herdr-supported agent kind diwan has ever needed that runs real work fully unattended: it has no per-tool-call approval gate at all (unlike e.g. Claude Code, which otherwise prompts before every edit/bash call and would defeat the "act first, report passively" model), so no permission-mode flag or similar is needed to let it act freely. The one thing that can still block a dispatch is pi's one-time project-trust decision for protected `.pi/*` resources, if a content repo ever has any — `--approve` (always passed, see the `diwan` CLI) makes that a one-shot yes instead of a hang; override with `DIWAN_PI_APPROVE` if a different flag is ever needed. `TICK.md` and `DO.md` are still plain-language procedures with nothing pi-specific baked into their wording — that's just good practice, not a promise of swapping in a different harness later.
|
diwan dispatches `pi`, and only `pi` — not a pluggable choice. It's the only herdr-supported agent kind diwan has ever needed that runs real work fully unattended: it has no per-tool-call approval gate at all (unlike e.g. Claude Code, which otherwise prompts before every edit/bash call and would defeat the "act first, report passively" model), so no permission-mode flag or similar is needed to let it act freely. The one thing that can still block a dispatch is pi's one-time project-trust decision for protected `.pi/*` resources, if a content repo ever has any — `--approve` (always passed, see the `diwan` CLI) makes that a one-shot yes instead of a hang; override with `DIWAN_PI_APPROVE` if a different flag is ever needed. `TICK.md` and `DO.md` are still plain-language procedures with nothing pi-specific baked into their wording — that's just good practice, not a promise of swapping in a different harness later.
|
||||||
@@ -269,22 +269,26 @@ class HerdrError(RuntimeError):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def herdr_json(*args):
|
def herdr_json(*args, machine=None):
|
||||||
res = subprocess.run(["herdr", *args], cwd=DIWAN_NOTES_DIR, capture_output=True, text=True)
|
cmd = ["herdr"]
|
||||||
|
if machine:
|
||||||
|
cmd += ["--machine", machine]
|
||||||
|
cmd += list(args)
|
||||||
|
res = subprocess.run(cmd, cwd=DIWAN_NOTES_DIR, capture_output=True, text=True)
|
||||||
if res.returncode != 0:
|
if res.returncode != 0:
|
||||||
raise HerdrError(f"herdr {' '.join(args)} failed: {res.stderr.strip() or res.stdout.strip()}")
|
raise HerdrError(f"{' '.join(cmd)} failed: {res.stderr.strip() or res.stdout.strip()}")
|
||||||
try:
|
try:
|
||||||
return json.loads(res.stdout)
|
return json.loads(res.stdout)
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
raise HerdrError(f"herdr {' '.join(args)}: non-JSON output: {res.stdout.strip()}")
|
raise HerdrError(f"{' '.join(cmd)}: non-JSON output: {res.stdout.strip()}")
|
||||||
|
|
||||||
|
|
||||||
def herdr_diwan_workspace_id():
|
def herdr_diwan_workspace_id(machine=None):
|
||||||
data = herdr_json("workspace", "list")
|
data = herdr_json("workspace", "list", machine=machine)
|
||||||
for ws in data["result"]["workspaces"]:
|
for ws in data["result"]["workspaces"]:
|
||||||
if ws.get("label") == DIWAN_WORKSPACE_LABEL:
|
if ws.get("label") == DIWAN_WORKSPACE_LABEL:
|
||||||
return ws["workspace_id"]
|
return ws["workspace_id"]
|
||||||
created = herdr_json("workspace", "create", "--label", DIWAN_WORKSPACE_LABEL, "--no-focus")
|
created = herdr_json("workspace", "create", "--label", DIWAN_WORKSPACE_LABEL, "--no-focus", machine=machine)
|
||||||
return created["result"]["workspace"]["workspace_id"]
|
return created["result"]["workspace"]["workspace_id"]
|
||||||
|
|
||||||
|
|
||||||
@@ -393,6 +397,26 @@ def cmd_bare(args):
|
|||||||
os.execvp("herdr", ["herdr"])
|
os.execvp("herdr", ["herdr"])
|
||||||
|
|
||||||
|
|
||||||
|
def cmd_remote(args):
|
||||||
|
machine = args.machine
|
||||||
|
if not herdr_available():
|
||||||
|
print("herdr not found on PATH. Install herdr: https://herdr.dev/")
|
||||||
|
return
|
||||||
|
# `machine` must be both a saved `herdr machine add` profile (for the
|
||||||
|
# scripted focus call below, over --machine) and a valid --remote SSH
|
||||||
|
# target for the actual interactive attach -- true by default, since
|
||||||
|
# `herdr machine add <target>` labels the profile after the SSH target
|
||||||
|
# unless --label overrides it. If you used a custom --label, pass the
|
||||||
|
# original SSH target here instead, or just run `herdr --remote
|
||||||
|
# <target>` yourself and navigate to the 'diwan' workspace by hand.
|
||||||
|
try:
|
||||||
|
ws_id = herdr_diwan_workspace_id(machine=machine)
|
||||||
|
herdr_json("workspace", "focus", ws_id, machine=machine)
|
||||||
|
except HerdrError as e:
|
||||||
|
print(f"warning: couldn't focus the '{DIWAN_WORKSPACE_LABEL}' workspace on '{machine}': {e}", file=sys.stderr)
|
||||||
|
os.execvp("herdr", ["herdr", "--remote", machine])
|
||||||
|
|
||||||
|
|
||||||
def cmd_tick(args):
|
def cmd_tick(args):
|
||||||
STATE_DIR.mkdir(exist_ok=True)
|
STATE_DIR.mkdir(exist_ok=True)
|
||||||
if git_is_dirty():
|
if git_is_dirty():
|
||||||
@@ -533,6 +557,9 @@ def main():
|
|||||||
p_do.add_argument("target", help="file:lineno pointing at a heading, or a free-text prompt")
|
p_do.add_argument("target", help="file:lineno pointing at a heading, or a free-text prompt")
|
||||||
p_do.add_argument("--diwan-id", dest="diwan_id", default=None)
|
p_do.add_argument("--diwan-id", dest="diwan_id", default=None)
|
||||||
|
|
||||||
|
p_remote = sub.add_parser("remote", help="open the 'diwan' workspace on a remote herdr machine")
|
||||||
|
p_remote.add_argument("machine", help="a machine saved via 'herdr machine add' (label defaults to its SSH target)")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
if args.command is None:
|
if args.command is None:
|
||||||
cmd_bare(args)
|
cmd_bare(args)
|
||||||
@@ -540,6 +567,8 @@ def main():
|
|||||||
cmd_tick(args)
|
cmd_tick(args)
|
||||||
elif args.command == "do":
|
elif args.command == "do":
|
||||||
cmd_do(args)
|
cmd_do(args)
|
||||||
|
elif args.command == "remote":
|
||||||
|
cmd_remote(args)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in new issue
Block a user