mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-23 22:29:33 +01:00
feat(adopt): adopt tmux sessions a human started, in all three locations
A tmux session someone opened by hand (`tmux new -s work`, then `claude`, or just a shell) is invisible to Codeman: it lives on the default socket, not the instance-scoped one Codeman owns. The home screen now lists those, and one click wraps one in a Codeman tab. Local, in-container and over-ssh all work. The shape is a WRAPPER session, not a direct attach: adoption creates an ordinary `codeman-<8hex>` session on our own socket whose pane runs the attach. That makes "detach, never kill the foreign session" structural rather than a matter of discipline — `killSession` can only ever reach our own wrapper, so no shape of caller bug reaches the foreign server. View reclamation differs by location: local relies on client death and ssh on SIGHUP, but a `docker exec` does NOT die with its client, so the in-container view has to be reclaimed explicitly on kill or every adoption leaks one. Measured facts, recorded in the code comments: - A grouped session (`new-session -t`) buys `status off` and an independent current window. It does NOT buy an independent size. A window is one object with one size and a group shares it: on tmux 3.3a a bare attach and a grouped attach both shrink a 200x49 target to 80x23. Only `window-size largest` holds it, and that is a shared window option which survives our detach, so setting it would permanently rewrite the owner's configuration. Left unset. - Session names come from other people, while the local launch chain ends in `bash -c` + `JSON.stringify`, which escapes neither `$` nor backticks — the outer shell performs command substitution before the inner single quotes are considered (verified: both substitutions inside the inner quotes ran). So session names and socket paths go through a character allowlist and are dropped at DISCOVERY, which means a non-conforming candidate never gets an id and the adopt endpoint fails closed when it re-resolves. - `pane_current_command` is `node` for both claude and codex, so the mode can only come from a bounded process-tree walk of `pane_pid`'s argv; anything unrecognized is treated as a shell. An adopted session has to say no to every assumption that Codeman owns the pane: respawn, Ralph, the orchestrator and hook waits all refuse. The hook check runs BEFORE the mode check, because adoption asks who launched the process and no mode can vouch for a workspace Codeman never touched. `paneExit` is forced to unknown, since the pane runs `tmux attach` rather than the agent and its exiting with 0 only means the connection ended. Reboot restore refuses too: all Codeman ever had was an attach command, and replaying it would build a connection to a foreign session a reboot has almost certainly taken with it, while presenting whatever it lands on as a session we restored. Adoption is admin-only under multi-user mode: adopting someone's shell is equivalent to arbitrary host execution. Discovery is read-only, never creates a session, and degrades to an empty list whenever a probe cannot reach its target.
This commit is contained in:
1 parent
848ab48b0a
commit
245ee68c7c
27 files changed
+2622
-35
No files matched your search
@@ -2067,3 +2067,24 @@ export const CustomModelSelectionSchema = z.union([
|
||||
}),
|
||||
z.object({ clear: z.literal(true) }),
|
||||
]);
|
||||
/**
|
||||
* Adopt a FOREIGN tmux session (one a human started outside Codeman).
|
||||
*
|
||||
* ⚠️ The body carries ONLY the opaque candidate id from `GET /api/mux/foreign`.
|
||||
* The socket path, session name and host are re-resolved server-side by re-running
|
||||
* discovery, so a browser can never hand the launch chain a path or a session name
|
||||
* to interpolate. That is the same discipline that keeps the docker-adopt and
|
||||
* remote-attach paths free of caller-supplied command fragments.
|
||||
*/
|
||||
export const AdoptForeignSessionSchema = z
|
||||
.object({
|
||||
id: z.string().min(1).max(64),
|
||||
/** Optional tab name; defaults to the foreign session's own name. */
|
||||
name: z.string().max(128).optional(),
|
||||
/** Include docker locations in the re-resolve (must match the listing call). */
|
||||
docker: z.boolean().optional(),
|
||||
/** Include remote locations in the re-resolve. */
|
||||
remote: z.boolean().optional(),
|
||||
parentSessionId: z.string().max(64).optional(),
|
||||
})
|
||||
.strict();
|
||||
Reference in new issue
Block a user