Skip to content

feat(sessions): kickoff prompts, resume-on-respawn, and full CLI parity#144

Open
defangdevs wants to merge 1 commit into
fix/remote-control-name-empty-hostfrom
feat/session-kickoff-prompt-and-resume
Open

feat(sessions): kickoff prompts, resume-on-respawn, and full CLI parity#144
defangdevs wants to merge 1 commit into
fix/remote-control-name-empty-hostfrom
feat/session-kickoff-prompt-and-resume

Conversation

@defangdevs

Copy link
Copy Markdown
Owner

Motivation

From a main/interactive agent-box session (Claude or Codex, on the phone via Remote Control) you should be able to kick off work in sibling sessions — possibly on a different harness — and reach everything the settings UI can do, without opening the web UI or doing a rebuild. Sessions already had UI/CLI CRUD over the same on-disk sessions.json; this fills the gaps.

Base: stacked on #128 (fix/remote-control-name-empty-host). My supervisor rewrite references hostLabel/remoteControlHost introduced there, so this depends on #128. Rebase base to master once #128 merges.

What this adds

Kickoff prompt (first spawn only). New initialPrompt is handed to the harness as its positional prompt argument on the first spawn; the supervisor then consumes it (mark_started sets hasRun, records boxSessionId, clears initialPrompt) so a respawn never redoes the task.

Resume-on-respawn. Every later spawn — crash, reboot, Spot stop→restart, all of which keep the transcript because /home is the persistent root EBS volume — resumes the prior transcript instead of redoing or idling. boxSessionId is the stable id we own across respawns:

  • Claude consumes it directly as --session-id (first spawn) / --resume (respawn, when a transcript exists; otherwise a fresh --session-id) — exact, so concurrent sessions never cross.
  • Codex mints its own id, so we stamp [agent-box session <id>] into the kickoff prompt and locate the exact rollout by that marker (grep → newest → trailing-36-char UUID) → codex resume <uuid>. No match → start fresh; never resume --last, which could grab a sibling session's transcript in a shared cwd.

resumePrompt overrides the built-in steer (continue unfinished work, or stop if already done).

CLI parity (agent-box-session):

  • add … --prompt "TASK" [--resume-prompt "…"]
  • env ls | set KEY VALUE | rm KEY — writes the same ~/.config/agent-box/env the settings page manages and the env-exec wrapper reads (ls shows keys only, never values)
  • restart NAME | --all

Settings page: add-session forms gain an optional kickoff-prompt field wired to initialPrompt.

Discoverability: seeded AGENTS.md documents --prompt, resume semantics, env, and restart --all.

User-visible / security effects

  • No new network surface. env writes the existing user-owned 0600 file with the same KEY_RE charset as the settings daemon and the env-exec wrapper; values are never surfaced by ls.
  • Kickoff/resume prompts are passed via printf %q, same injection-safe path as extraArgs.
  • No AWS cost / IAM / networking / migration impact.

Checks run

  • nix-instantiate --parse modules/agent-box.nix — OK
  • nix build .#checks.x86_64-linux.module-single-file and .multi-userevaluate cleanly (.drv produced; x86_64 build and VM tests couldn't run on the aarch64 dev box without /dev/kvm).
  • Validated the non-trivial bash/jq in real bash+jq: rollout-UUID extraction, concurrent-session marker disambiguation, both jq filters, env_rewrite set -e safety.
  • Verified flag composition against the installed CLIs (Claude --session-id/--resume/positional prompt; Codex resume [id] [PROMPT] + bypass flag on the subcommand).

Needs CI (KVM): the new tests/sessions.nix subtests (kickoff deliver-once + resume state, env, restart --all, web-form prompt).

Not verified headlessly: that a positional prompt injects as a real first turn in a live --remote-control interactive launch, and that --session-id composes with --remote-control — needs a real attach on a deployed box.

🤖 Generated with Claude Code

@defangdevs
defangdevs force-pushed the fix/remote-control-name-empty-host branch from 4dbffab to 121a7fc Compare July 22, 2026 14:30
Let a main/interactive session spin up work in sibling sessions and reach
everything the settings UI can do, without the web UI or a rebuild.

Sessions (agent-box-session / settings page / seed) gain:

- initialPrompt: a kickoff task handed to the harness on the FIRST spawn
  only (its positional prompt arg). The supervisor consumes it (mark_started
  sets hasRun, records boxSessionId, clears initialPrompt) so a respawn never
  redoes the task.
- Resume-on-respawn: every later spawn (crash, reboot, Spot stop->restart —
  all of which keep the on-disk transcript, since /home is the persistent
  root EBS volume) resumes the prior transcript instead. boxSessionId is the
  stable id we own across respawns:
    * Claude consumes it directly as --session-id (first spawn) / --resume
      (respawn, when a transcript exists; else a fresh --session-id) — exact,
      so concurrent sessions never cross.
    * Codex mints its own id, so we stamp "[agent-box session <id>]" into the
      kickoff prompt and locate the exact rollout by that marker
      (grep -> newest -> trailing-36-char UUID) -> codex resume <uuid>. No
      match -> start fresh; never `resume --last`, which could grab a sibling
      session's transcript in a shared cwd.
  resumePrompt overrides the built-in steer (continue unfinished work, or
  stop if already done).

CLI (agent-box-session) reaches UI parity:
- add --prompt / --resume-prompt
- env ls | set KEY VALUE | rm KEY  (writes the same ~/.config/agent-box/env
  the settings page manages and the env-exec wrapper reads; ls shows keys
  only, never values)
- restart --all

Settings page: add-session forms gain an optional kickoff-prompt field.
Seeded AGENTS.md documents --prompt, resume semantics, env, restart --all so
every harness discovers them.

Adds sessions.nix regression coverage: kickoff deliver-once + resume state,
env set/ls/rm, restart --all, and the web-form prompt.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Wx9PVLmDbzS35JCN5N85i6
@defangdevs
defangdevs force-pushed the feat/session-kickoff-prompt-and-resume branch from 79cadc6 to 1825f2a Compare July 22, 2026 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants