Skip to content

feat(cli): add future session set to change an existing session's parent/title/cwd/model/thinking - #773

Merged
huichen merged 2 commits into
mainfrom
feat/cli-session-set
Sep 22, 2026
Merged

huichen merged 2 commits into
mainfrom
feat/cli-session-set

Conversation

@huichen

@huichen huichen commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

What

future session new (#771) creates a session. This adds the command the original request asked for — changing settings on a session that already exists:

future session set <session-id> [--parent <id>] [--title <name>] [--cwd <dir>]
                                [--model <id>] [--thinking <level>] [--json]
$ future session set 20260922-142157-940f… --parent 20260922-142157-7d0e… --title Renamed --cwd /tmp --thinking high
Updated session 20260922-142157-940f…
  Parent:   20260922-142157-7d0e…
  Title:    Renamed
  CWD:      /tmp
  Thinking: high

$ future session set 20260922-142157-940f… --title "Json" --json
{"sessionId":"20260922-142157-940f…","updated":{"title":"Json"},"failed":{}}

Only the options passed are touched; nothing else is changed.

Agent: new set_parent_session command

Parent was the one setting the wire contract had no way to change on an existing session (fork/new_session only set it at creation). The new command:

  • updates the live session and persists parent_session_id into session_info — the run-end snapshot re-reads the parent from disk, so an in-memory-only change would be silently reverted by the next run (this is why set_cwd/set_session_name persist too);
  • rejects a self-parent, and a parent that is neither live nor in the session store. A live session with no entries yet is accepted as a parent (matching how fork sees lineage);
  • an empty id detaches (the store's parent_session_id column is nullif(…,''), so it reads back as no parent);
  • registered in packages/rpc/src/command_policy.rs — which doubles as the dispatcher's command registry, so without it the command would be rejected as unknown command.

No proto change: parent_session (field 20) and the stringly type already exist. No event is emitted — no client renders a live session's parent today (the desktop builds its thread tree from its own store), and the change is durable in the session record.

CLI behaviour

  • The target session is resolved once up front (get_state), so a bad id reports the CLI's own Session not found: <id> instead of the agent's new_session-flavoured "pass a valid session_id" text.
  • --parent is applied first and aborts the rest: a parent is a reference to another session, so a typo there makes the rest of the update meaningless.
  • The other four options are applied independently; a per-field failure (e.g. a model the agent refuses) does not roll back the others — it prints Failed to set <field>: …, and the command exits 1. --json reports updated / failed per field.
  • session new and session set now share one SessionOptions + parser; --parent "" means "unset" in new as well (previously it probed for a session named "" and failed with Session not found: ).
  • Docs: future session --help, future session set --help, help.rs group line, docs/wiki/{en,zh}/CLI.md.

Honest notes on the two-level semantics

  • Title and cwd land in the session record as soon as the session has one (i.e. after its first prompt); a never-prompted session stores everything on its first run. The model and thinking level take effect on the live session immediately but are part of the run snapshot, so they reach the record with the next run. Verified against an isolated agent: after set --title/--parent/--thinking + one run, session list --json shows the new title/parentSessionId and session info the new thinking level.
  • future run applies its own --cwd (current directory by default) at the start of every run, so a cwd set here holds only until that run — pre-existing run behaviour, now documented in the help text.
  • set_model accepts an id the registry doesn't know (existing agent behaviour: a model selector click must not fail); such a model fails loudly at the next run instead.

Verification

  • cargo test -p future-agent — 1824 lib + integration tests pass (new: parent persists to disk / detaches, self-parent and unknown-parent rejected, live-without-entries parent accepted).
  • cargo test -p future-cli — 753 lib + 15 integration (new: full option round-trip on the wire, only-given-options-touched, --json updated/failed, parent detach, usage errors, help without an agent, unknown target, bad/self parent aborting the rest, empty --parent in new).
  • cargo test -p future-rpc — 121 pass.
  • cargo fmt --all --check clean.
  • Manual run against an isolated agent (future agent --home /tmp/… --grpc-addr 127.0.0.1:49191): every option lands (get_state shows name/cwd/thinking/parent), errors report as expected (self, unknown parent, unknown target, no options, partial failure).

Local clippy -D warnings on this machine reports a pre-existing nonminimal_bool in agent/src/session/compaction_ops.rs and channels/ under Homebrew's clippy 0.1.96 (the known 1.96-vs-1.97 false report; both files are untouched here) — CI runs clippy on the pinned toolchain. One lint on the new handler was real and is fixed.

Follow-ups (not in this PR)

  • --json is on set for symmetry with new/list; a future session edit could reuse the same parser.
  • Whether session new should stay is a product call — it is the "create without spending a token" counterpart.

`future session new` (#771) creates a session; this adds the command that
actually changes an existing one:

  future session set <id> [--parent <id>] [--title <name>] [--cwd <dir>]
                          [--model <id>] [--thinking <level>] [--json]

Agent: new `set_parent_session` command — the one setting the wire contract
lacked. It updates the live session and persists `parent_session_id` into
session_info, because the run-end snapshot re-reads the parent from disk: an
in-memory-only change would be reverted by the next run. It rejects a
self-parent and a parent that is neither live nor stored (a live session with
no entries yet is a valid parent), and is registered in `command_policy`, which
is also the dispatcher's command registry.

CLI: the options are applied one at a time and reported. A per-field failure
(a model the agent refuses, say) does not roll back the others — it prints
`Failed to set <field>: …` and exits 1. `--parent` is applied first and aborts
the rest, since a typo there makes the rest of the update meaningless. An empty
`--parent` detaches in `set` and now means "unset" in `new` too.

`session new` and `session set` share one options struct + parser. The session
golden-help test and docs/wiki/{en,zh}/CLI.md are updated.
@huichen
huichen enabled auto-merge (squash) September 22, 2026 06:29
@huichen
huichen merged commit 2af42f7 into main Sep 22, 2026
12 checks passed
@huichen
huichen deleted the feat/cli-session-set branch September 22, 2026 06:56
huichen added a commit that referenced this pull request Sep 22, 2026
`future session new` (#771) turned out to be a solution to a problem nobody
had: it only created a session (`new_session` + print the id) without running
anything, while the actual request was to change an existing one — which is
`future session set` (#773). Keeping both meant two commands with overlapping
option surfaces and a create path whose result no command consumes
(`future run --session <id>` also creates the session it is given).

Removed: the `new` subcommand, `SESSION_NEW_HELP`, `RunClient::new_session_with`
and `NewSessionOptions` (the plain `new_session(cwd)` used by the run
orchestration is untouched, and the session options parser now serves `set`
alone). The agent-side `set_parent_session` stays — `session set` needs it.

A session can still be created without a token: it just isn't a CLI command,
matching how every other client does it (they create on first prompt).
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.

1 participant