Repository navigation
feat(cookbook): add container-overlays recipe - #855
Conversation
umputun
left a comment
There was a problem hiding this comment.
one blocking issue, the rest are small notes.
blocking
cookbook/container-overlays/agtermctl.py:216 - parse_open stops reading flags at the first positional, so overlay open htop --block or overlay open "make test" --target "$AGTERM_SESSION_ID" passes through unrewritten, so the command runs on the Mac in the target session's Mac cwd; without --target, that is whichever session is focused. The real CLI accepts flags after COMMAND (agtermCore/Tests/agtermctlKitTests/CommandsTests.swift:929) and the bundled agent skill uses that order (plugins/agterm/skills/agterm/examples.md). Fix: keep scanning known flags after COMMAND, and die() instead of passing through when an open call fails to parse and carries no --html/--url; a selftest with trailing --block and --size-percent would pin it.
smaller
README.md:124- "a caller cannot retarget it at another agterm instance" doesn't hold:--socketgoes through in argv, and an overlay COMMAND sent straight to the receiver runs any shell command on the Mac. Pls say it plainly in Limits: any container or local process that reaches the receiver can run any command on the Mac as you. Same for the receiver docstring and theFORWARDED_ENVcomment.agtermctl.py:342-gc_stagingremoves every non-hidden dir under the staging root older than 24h, not only manifest entries. Prune only manifest entries. Also, opening another staged page can delete a still-open copy whose dir mtime is over 24h old and drop its manifest entry, so a lateroverlay reloadcan't restore it; mention that 24h deletion in Limits.agtermctl.py:609- URL opens that are not rewritten (a public URL, orAGT_OVL_EXPOSE="") return beforeinject_target(), so the page covers the focused session, contrary to README:110. Inject the target on every parsed URL open.agtermctl-receiver.py:123- the receiver ignoresAGTERMCTL, which cookbook/CONTRIBUTING.md asks scripts to honor. Resolve--agtermctl, thenAGTERMCTL, then PATH.agtermctl.py:561- with COMMAND,--cwdis ignored for where the program runs (the payload always cd's toos.getcwd()), while the container path still reaches the Mac as the overlay's cwd. Use the absolutized--cwdfor the payload and drop it from argv.agtermctl.py:493- frames go tosys.stdout.buffer/sys.stderr.bufferwithout a flush, soagtermctl eventsinside the container shows nothing until the buffer fills or the call ends. Flush after each frame.
|
one more, for the receiver, on top of the review above.
minor, not blocking. |
The parser now reads flags before AND after COMMAND, as the host CLI does; an unparsable open without --html/--url dies instead of passing through, since sent as-is it would run its COMMAND on the Mac. A parsed COMMAND with a page flag dies locally too, and --cwd folds into the exec payload. COMMAND no longer crosses as text: the wrapper sends a structured exec request and the receiver builds the only docker-exec line it will pass, from its own template (--exec-template / AGT_OVL_EXEC_TEMPLATE, moved to the Mac where docker lives). The receiver resolves --agtermctl, then AGTERMCTL, then PATH; refuses --socket anywhere and raw COMMAND overlay opens, always with an err frame; watches client EOF with select + MSG_PEEK (sends stay blocking, so a slow client gets TCP backpressure, never a killed child) and terminates and reaps the abandoned call; a child registry plus SIGTERM cleanup ends live children at shutdown. Wrapper: --target injected on every parsed URL open, output flushed per frame so events streams live, staging GC prunes manifest entries only. Receiver gains an embedded suite; test_shim runs both (30 tests). README states the hardening and keeps the blunt residual Limits sentence first.
|
all in 669e120. blocking
smaller
the follow-up The receiver watches the client connection with beyond the review, deliberate Pass-through argv made the receiver a full-authority remote, so I made the two edges you named structural refusals instead of doc caveats: the receiver refuses verification
I hope this is not too overcomplicated now. My agent tested that he can brew a docker image and run overlays with command/html/url. |
umputun
left a comment
There was a problem hiding this comment.
lgtm, last round's items check out. Three small notes for a follow-up, none blocking:
agtermctl-receiver.py:250-CONTAINER_NAME_RE.matchaccepts a trailing newline ($matches before a final\n), so a hand-crafted exec request with containeralpine\nsplits the docker line under agterm'seval, and the decoded payload runs on the Mac. The wrapper strips the name, so normal use never hits it. Fix:fullmatch, plus a"dev\n"case in the refusal test.README.md:129andagtermctl-receiver.py:20,23-25- "no caller-written shell line reaches the Mac" reads as absolute, whilesession new --commandstill passes, as the bold line above it says. Pls scope both to overlay COMMANDs.agtermctl-receiver.py:413- the child inherits the receiver's stdin and no stdin crosses the wire, so piped container input (printf 'a\nb\n' | agtermctl pick) never reachesagtermctl pick; the child reads the Mac receiver's stdin and can hang when it inherits a terminal. Fix:stdin=subprocess.DEVNULLon thePopen, and a Limits line that stdin does not cross.
recipe from #714: use agterm overlays from inside a docker container, with the program running in the container and files opened by their Mac paths. the discussion asked for a host tunnel so overlay commands execute where they belong; this is the extension-model answer — an in-container
agtermctlwrapper plus a small Mac-side receiver, no core changes.what works from inside the container after setup:
agtermctl session overlay open -- htopruns htop in the container: the wrapper replaces COMMAND withdocker exec -it … <name> sh -c "$(printf %s <b64> | base64 -d)", the payload beingcd '<caller cwd>' && <COMMAND>, base64-armored so the double shell evaluation can never mangle it.--blockreturns the program's real exit code.--html FILEopens by its Mac path through a bind map (bind-map.py, fromdocker inspect); a file outside any bind is staged into a bind-mounted pages dir (capped at 200 files / 20 MiB), and a--cwdgrant is always synthesized — without it agterm loads the page vialoadHTMLStringat about:blank with zero file access, so relative assets silently vanish.overlay reloadre-copies staged entries, then passes through.--url http://localhost:PORT/works because publishing already happened atdocker run -p: the identity expose script just answers the wrapper's contract line, and an optional port-map file translates remapped ports.--targetfromAGTERM_SESSION_ID, since agtermctl defaults to the active session and an overlay from a container would land on whatever pane is focused.the parser knows 0.39.0's closed flag surface; anything it does not recognize passes through unrewritten rather than guessed at. the exec-back line uses an absolute docker path (the app, not your shell, spawns it) overridable with
AGT_OVL_EXEC_TEMPLATEfor non-standard docker locations.files:
agtermctl.py(in-container wrapper, python 3 stdlib only),agtermctl-receiver.py(runs the real agtermctl and streams out/err/rc over one connection per call, binds 127.0.0.1:59998),bind-map.py,agt-ovl-expose.sh,test_shim.py— cookbook CI executes the shim, which runs the wrapper's 12 embedded tests.the receiver runs any agtermctl call that reaches it with your terminal's own authority; the README's Limits spells that out — 127.0.0.1 keeps other machines out but nobody else on this Mac, so run it on a single-user machine and stop it when done.
needs agterm 0.39.0 (the flag surface the parser knows), docker with
host.docker.internal, python 3.8+ on both sides, and sh/printf/base64 in the image; the optionalxterm-ghosttyterminfo entry buys full-color TUIs.checked:
test_shim.pyand shellcheck clean; verified end to end against a live instance — alpine image with the wrapper, htop and the compiled terminfo entry,docker runfrom an agterm shell carrying the session identity, thenoverlay open -- htopand--size-percent 80from inside the container, with the overlay read-back and the receiver log confirming the rewritten call.