Skip to content

feat(cli): add future session new with parent/title/cwd/model/thinking - #771

Merged
huichen merged 1 commit into
mainfrom
feat/cli-session-new
Sep 22, 2026
Merged

huichen merged 1 commit into
mainfrom
feat/cli-session-new

Conversation

@huichen

@huichen huichen commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

What

Adds a future session new subcommand that creates a session and lets the caller set the parameters the agent's new_session already accepts:

future session new [--parent <id>] [--title <name>] [--cwd <dir>]
                   [--model <id>] [--thinking <level>] [--json] [--help]
$ future session new --parent 20260922-132633-… --title "Child" --cwd /tmp --thinking low --json
{"sessionId":"20260922-132650-…","parentSessionId":"20260922-132633-…","name":"Child","cwd":"/tmp","model":null,"thinkingLevel":"low"}

Text mode prints Created session <id> plus the options that were set; that ID is what future run --session <id> accepts. Unset options keep the agent's defaults (default workspace → the CLI sends the current directory, like future run; default model; agent-preferred thinking level).

Details

  • --parent records lineage and is validated first against list_sessions — the agent stores parentSession without checking it, so a typo would otherwise leave a dangling parentSessionId. A missing parent fails with Session not found: <id> (exit 1) and never creates a session. Membership is checked on the session list (what future session list shows) rather than get_session_entries, which answers an unknown ID with a confusing "pass a valid session_id" error.
  • --thinking is validated against the same level list as future run (run::VALID_THINKING_LEVELS, now pub(crate)), with the same error text.
  • Unlike future run's parser, bad input here is a hard error (exit 1) rather than a silently ignored flag.
  • RunClient::new_session(cwd) keeps its signature and now delegates to the new new_session_with(NewSessionOptions); the one-shot run path is unchanged.
  • help.rs group line and docs/wiki/{en,zh}/CLI.md updated.

Verification

  • cargo test -p future-cli — 743 lib + 15 integration tests pass (new parser/mock tests: full option round-trip on the wire, created_by: "cli", parent-not-found aborts before new_session, --json shape, missing sessionId, help without an agent).
  • cargo fmt --check + cargo clippy -p future-cli --all-targets -- -D warnings (clippy run with --no-deps: the local clippy component here is 0.1.96 and false-reports pre-existing lints in future-agent/future-channel; those crates are untouched by this PR).
  • Manually against an isolated agent (future agent --home /tmp/… --grpc-addr 127.0.0.1:49187): get_state confirms sessionName/cwd/thinkingLevel/createdBy: "cli" are applied; a child created with --parent <persisted id> shows that parentSessionId in session list --json after the child is persisted.

Notes

Like the TUI/desktop paths, new_session is live in the agent immediately but only reaches agent.db once the session has entries — so a brand-new session shows up in future session list after its first prompt.

Create a session from the CLI with the same knobs the agent's new_session
command already accepts:

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

--parent records lineage and is validated against list_sessions first, so a
typo fails with "Session not found: <id>" instead of leaving a dangling
parentSessionId. --json prints the created session for scripting; the text
mode prints the new session ID, which `future run --session <id>` accepts.

RunClient::new_session keeps its cwd-only signature and delegates to the new
new_session_with(NewSessionOptions).
@huichen
huichen enabled auto-merge (squash) September 22, 2026 05:29
@huichen
huichen merged commit fc24db8 into main Sep 22, 2026
12 checks passed
@huichen
huichen deleted the feat/cli-session-new branch September 22, 2026 05:34
huichen added a commit that referenced this pull request Sep 22, 2026
`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 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