Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RUST-BASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ ancestry with merge commits; never rebase or squash the integration history.
| Headless exit follows the answer | `crates/pa-cli/src/headless_exit.rs`, `crates/pa-core/src/kernel/bootstrap/venv/subprocess.rs`, `KernelPrewarm` in `crates/pa-core/src/session_engine/engine.rs` | Upstream's print runtime started the kernel bootstrap in the background and dropped its Tokio runtime implicitly, which waits without bound for the bootstrap's blocking `uv`/interpreter children: a fresh home's first one-shot exited 43 s after its answer. Print/json now set the kernel environment up before the first turn (`KernelPrewarm::BeforeFirstTurn`), run every setup child as an owned, cancellable tokio child, abandon the kernel boot after the last output and shut the runtime down within 300 ms; the hosted client's detach waits the same budget. `--verbose` traces the exit phases. Resident sessions keep `KernelPrewarm::Background`. Either mode runs only when the Python REPL tool (`python_repl`, with `ipython`/`python` selection aliases) is active after the launch tool selection (`--tools`/`--no-tools`/`--no-builtin-tools`). |
| `--tools`/`--no-tools`/`--no-builtin-tools` honoured (kept against upstream #3211, `a3700282c`, which deletes them) | `crates/pa-core/src/session_engine/tool_selection.rs`, `crates/pa-core/src/prompts/no_repl.rs`, `crates/pa-core/src/session_engine/engine.rs`, `crates/pa-types/src/daemon/tool_selection.rs`, `crates/pa-cli/src/{args,mode,prompt_command}.rs`, the daemon create/summary/headless client, `crates/pa-tui/src/interactive.rs` | Upstream parsed the flags but always added the Python tool (`python_repl`, `ipython` before the rename) and the harness prompt; `sol` and the factory pass `--no-tools` for plain calls. TS semantics: an explicit list wins over both disable flags, then `--no-tools`, then `--no-builtin-tools`. A session with no active tools sends no tool definitions; any session without `python_repl` prepares no kernel environment, starts no kernel and gets the TS no-tools prompt byte for byte (`crates/pa-core/tests/golden/corpus/no-tools-prompt-ts.txt`). Daemon wire: introduced in fork schema revision 31 and carried in the combined revision 33 (fork-only id), capability `session_tool_selection`, create keys `tools`/`noTools`/`noBuiltinTools` (durable for respawns, and kept with the session policy in the per-session record, so a passivated session wakes, a session moved onto by `new_session`/fork keeps, and an RLM child inherits the selection; a record without the keys reads as the defaults), summary `toolSelection`. A merge that includes #3211 must keep the flags, their help rows and this implementation. |
| Unknown model ids on a models.json provider resolve as custom models (#32) | `build_fallback_model` in `crates/pa-core/src/models/resolver.rs` | TS sends any `--model` id to a provider defined in models.json; the port's fallback returned `None` for every provider without a compiled-in default (every models.json provider: cpa, cpa-r, cpa-a), so CPA's per-login prefix routing (`--provider cpa-r --model antevon/gpt-6.1-sol`, the proxy strips the prefix upstream) failed with `Model ... not found`. The fallback template is the provider's own entry for the id behind one routing prefix (only the first path segment is a prefix: `antevon/openai/gpt-4o` keeps its namespace), else the provider's first model; a provider with a compiled-in default keeps that template (TS parity). Resolver tests cover the boundaries. An upstream merge must keep this. |
| Helper model for spawned agents | `crates/pa-core/src/session_engine/helper_model.rs`, `resolve_helper` in `crates/pa-daemon/src/rlm_child_model.rs`, `crates/pa-daemon/src/rlm_children/host.rs`, `crates/pa-cli/src/print_rlm.rs`, `crates/pa-daemon/src/rlm_surface.rs`, `crates/pa-tui/src/session_ui/settings.rs`, `docs/oneiron/HELPER-MODEL.md` | Upstream runs a spawned agent on its parent's model unless the call names one, and never reads its own `subagentDefaultModel` (TS read it, and failed the spawn on an unavailable default). The fork resolves each field in order: the spawn call, the session override (`--subagent-model`/`--subagent-thinking`, `PRIME_SUBAGENT_MODEL`/`PRIME_SUBAGENT_THINKING`, TUI `/subagent-model`), the settings file (`subagentDefaultModel` plus the fork's `subagentDefaultThinking`), the parent. An unknown default warns once and falls back to the parent's model (a TS divergence, by ruling); a default level clamps to the model. The override rides RLM child creates (`subagentModel`/`subagentThinking`) and persists as a `subagent_model_state` session row. Daemon wire: capability `subagent_model`, commands `get_subagent_model_status`/`set_subagent_model` (no schema bump). The spawn and create-session handles add `thinking`. `/settings` gains "Helper model" and "Helper thinking". An upstream merge must keep all of it. |
| Side-by-side install + probe | `scripts/oneiron/side_by_side.py` | Installs a staged release beside the TS build and writes receipts. |
| Release feed, rollout, rollback, status | `scripts/oneiron/release_feed.py`, `rollout.py`, `daemon_idle.py` (subcommands of `side_by_side.py`), `docs/oneiron/RELEASE.md`, `docs/oneiron/ROLLBACK.md` | Stamps a `package_release.py` build into a versioned feed release (`feed/releases/v<ver>/`), rolls it out with verified sums, a probe before selection and an idle-only Rust daemon check, and rolls back to the previous install; every step writes a receipt. `crates/pa-core/tests/oneiron_feed_manifest.rs` checks the feed manifest against the native updater's parser. |
| Test-policy gate | `scripts/check-test-policy.mjs` (from the TS fork), `scripts/oneiron/test_policy_gate.py` | Runs the fork's test policy with `TEST_POLICY_BASE=oneiron/main` and fails only on violations beyond the reviewed upstream baseline (`scripts/oneiron/test-policy-baseline.txt`): 4 original entries plus 8 occurrences in 3 byte-identical upstream tests at the 2026-10-24 sync. |
Expand Down
8 changes: 7 additions & 1 deletion crates/pa-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ the quiescence drive that holds the run open until every admitted
descendant settles and its replies and notices drain (the #2270 fix),
the goal/autonomous deferral behind unsettled work, and the exit
disposal (kernels snapshotted, drivers joined; no child outlives the
process).
process). A child that names no model or thinking level runs on the helper
model (fork-only, `docs/oneiron/HELPER-MODEL.md`): the invocation's
`--subagent-model`/`--subagent-thinking` (else `PRIME_SUBAGENT_MODEL`/
`PRIME_SUBAGENT_THINKING`), then the settings file's
`subagentDefaultModel`/`subagentDefaultThinking`, then the parent's.
`--daemon-hosted` and the interactive launch set the same override on their
session (`set_subagent_model`, behind the `subagent_model` capability).
Session slash commands (`print_session_command.rs`, the #253 residue): print
prompts that are `/compact`, `/refine`, `/goal`, or `/autonomous` execute
through the pa-core session-command executor (the daemon worker's seam — no
Expand Down
55 changes: 55 additions & 0 deletions crates/pa-cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ pub struct Args {
pub system_prompt: Option<String>,
pub append_system_prompt: Vec<String>,
pub thinking: Option<ModelThinkingLevel>,
/// `--subagent-model`: this session's helper model for spawned agents (`provider/model-id`
/// or `parent`).
pub subagent_model: Option<String>,
/// `--subagent-thinking`: this session's helper thinking level (a level or `parent`).
pub subagent_thinking: Option<String>,
pub continue_: bool,
/// `true` when `--resume` was given without a selector.
pub resume_bare: bool,
Expand Down Expand Up @@ -362,6 +367,20 @@ pub fn parse_args(args: &[String]) -> Args {
)));
}
}
"--subagent-model" => result.subagent_model = Some(require_value!(arg)),
"--subagent-thinking" => {
let level = require_value!(arg);
if level == pa_core::session_engine::helper_model::INHERIT_PARENT
|| parse_thinking_level(&level).is_some()
{
result.subagent_thinking = Some(level);
} else {
result.diagnostics.push(Diagnostic::error(format!(
"Invalid --subagent-thinking level \"{level}\". Valid values: parent, {}",
THINKING_LEVELS.join(", ")
)));
}
}
"--print" | "-p" => {
result.print = true;
if let Some(next) = args.get(i + 1) {
Expand Down Expand Up @@ -620,6 +639,42 @@ mod tests {
Diagnostic::error(message)
}

/// The helper-model flags carry the session's override; an unknown level is an error.
#[test]
fn subagent_flags_carry_the_helper_override() {
let expected = Args {
subagent_model: Some("cpa-r/deepseek-flash-1017".to_string()),
subagent_thinking: Some("max".to_string()),
print: true,
messages: vec!["hi".to_string()],
..Args::default()
};
assert_eq!(
format!(
"{:?}",
parse(&[
"--subagent-model",
"cpa-r/deepseek-flash-1017",
"--subagent-thinking",
"max",
"-p",
"hi"
])
),
format!("{expected:?}")
);
assert_eq!(
parse(&["--subagent-thinking", "parent"])
.subagent_thinking
.as_deref(),
Some("parent")
);
assert_eq!(
last_error(&parse(&["--subagent-thinking", "loud"])),
"Invalid --subagent-thinking level \"loud\". Valid values: parent, off, minimal, low, medium, high, xhigh, max"
);
}

/// Both syntaxes select the profile on an explicit json run.
#[test]
fn json_event_profile_spaced_and_equals_syntax() {
Expand Down
23 changes: 23 additions & 0 deletions crates/pa-cli/src/client_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,29 @@ impl ClientSettings for CliClientSettings {
self.manager().set_theme(theme.to_string())
}

fn subagent_default_model(&self) -> Option<String> {
self.manager().get_subagent_default_model()
}

fn set_subagent_default_model(&self, model: Option<&str>) -> Result<()> {
self.manager()
.set_subagent_default_model(model.map(str::to_string))
}

fn subagent_default_thinking(&self) -> Option<String> {
self.manager().get_subagent_default_thinking()
}

fn set_subagent_default_thinking(&self, level: Option<&str>) -> Result<()> {
if let Some(level) =
level.filter(|level| pa_types::ai::thinking_level_from_str(level).is_none())
{
anyhow::bail!("Invalid thinking level \"{level}\"");
}
self.manager()
.set_subagent_default_thinking(level.map(str::to_string))
}

fn default_service_tier(&self) -> String {
// The wire name of the persisted default tier; "default" when
// unset or unreadable.
Expand Down
8 changes: 8 additions & 0 deletions crates/pa-cli/src/command_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,14 @@ const TOP_LEVEL_OPTION_GROUPS: &[OptionGroup] = &[
"--thinking <level>",
"Set reasoning: off, minimal, low, medium, high, xhigh, max",
),
(
"--subagent-model <id>",
"Set this session's model for spawned agents (or parent)",
),
(
"--subagent-thinking <level>",
"Set this session's reasoning for spawned agents (or parent)",
),
],
},
OptionGroup {
Expand Down
4 changes: 3 additions & 1 deletion crates/pa-cli/src/global_flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use std::collections::HashSet;

/// Global flags that consume the next argument as their value.
pub const GLOBAL_VALUE_FLAGS: [&str; 25] = [
pub const GLOBAL_VALUE_FLAGS: [&str; 27] = [
"--mode",
"--json-event-profile",
"--daemon-socket",
Expand All @@ -19,6 +19,8 @@ pub const GLOBAL_VALUE_FLAGS: [&str; 25] = [
"--models",
"--tools",
"--thinking",
"--subagent-model",
"--subagent-thinking",
"--skill",
"--prompt-template",
"--theme",
Expand Down
1 change: 1 addition & 0 deletions crates/pa-cli/src/hosted_print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ async fn hosted_print_main(options: &RunOptions) -> Result<i32, String> {
offline: options.offline,
no_skills: config.no_skills,
},
subagent_override: config.subagent_override.clone(),
})
.await
.map_err(|error| format!("{error:#}"))?;
Expand Down
9 changes: 8 additions & 1 deletion crates/pa-cli/src/interactive_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,14 @@ fn print_resume_hint(hint: Option<&str>) {
/// The agents-view loop: open the view, run the session it opens, and return
/// to the view on agents-back or bare `/resume`; every other exit ends the app.
async fn run_agents_view_flow(
base: InteractiveOptions,
mut base: InteractiveOptions,
anchor: Option<String>,
notice: Option<String>,
) -> Result<()> {
// The launch helper-model override belongs to the session the launch opened; a session
// opened from the view keeps its own (`/subagent-model` changes it there).
base.model_selection.subagent_model = None;
base.model_selection.subagent_thinking = None;
let mut anchor = anchor;
// Every view run reuses the roster connection (a chat run hands it
// back), so a switch back from a chat skips the handshake.
Expand Down Expand Up @@ -489,6 +493,9 @@ fn build_tui_options(
api_key: config.api_key.clone(),
// The worker clamps `--thinking` to the model's levels.
thinking: config.thinking,
// The launch helper-model override, set on the opened session.
subagent_model: config.subagent_override.model.clone(),
subagent_thinking: config.subagent_override.thinking.clone(),
},
// The raw `--models` patterns ride the create config (the daemon
// owns the resolution).
Expand Down
101 changes: 101 additions & 0 deletions crates/pa-cli/src/mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ pub struct RuntimeConfig {
pub telemetry_disabled: bool,
pub serialized_refine: bool,
pub initial_goal: Option<InitialGoal>,
/// The session's helper-model override for spawned agents: `--subagent-model`/
/// `--subagent-thinking`, else `PRIME_SUBAGENT_MODEL`/`PRIME_SUBAGENT_THINKING`.
pub subagent_override: pa_core::session_engine::helper_model::HelperDefaults,
}

impl RuntimeConfig {
Expand Down Expand Up @@ -382,6 +385,25 @@ pub fn runtime_config_from_args(
objective: objective.clone(),
token_budget: parsed.goal_token_budget,
}),
subagent_override: {
use pa_core::session_engine::helper_model::{
HelperDefaults, SUBAGENT_MODEL_ENV, SUBAGENT_THINKING_ENV,
};
// Each flag beats its env var; an invalid env level warns and is ignored.
let env_model = std::env::var(SUBAGENT_MODEL_ENV).ok();
let env_thinking = std::env::var(SUBAGENT_THINKING_ENV).ok();
let env_layer = HelperDefaults::new(env_model.as_deref(), env_thinking.as_deref())
.unwrap_or_else(|error| {
eprintln!("Warning: {SUBAGENT_THINKING_ENV}: {error}");
HelperDefaults::new(env_model.as_deref(), None).unwrap_or_default()
});
HelperDefaults::new(
parsed.subagent_model.as_deref(),
parsed.subagent_thinking.as_deref(),
)
.unwrap_or_default()
.or(&env_layer)
},
}
}

Expand Down Expand Up @@ -420,6 +442,85 @@ pub(crate) mod tests {
}
}

/// The helper-model override: each `--subagent-*` flag beats its `PRIME_SUBAGENT_*` env
/// var, field by field; an invalid env level is ignored, never fatal.
#[test]
fn subagent_flags_beat_their_env_vars_field_by_field() {
use pa_core::session_engine::helper_model::{
HelperDefaults, SUBAGENT_MODEL_ENV, SUBAGENT_THINKING_ENV,
};
let resolve = |argv: &[&str], model: Option<&str>, thinking: Option<&str>| {
let saved: Vec<(&str, Option<String>)> = [SUBAGENT_MODEL_ENV, SUBAGENT_THINKING_ENV]
.iter()
.map(|key| (*key, std::env::var(key).ok()))
.collect();
for (key, value) in [
(SUBAGENT_MODEL_ENV, model),
(SUBAGENT_THINKING_ENV, thinking),
] {
match value {
Some(value) => std::env::set_var(key, value),
None => std::env::remove_var(key),
}
}
let args: Vec<String> = argv.iter().map(ToString::to_string).collect();
let config = runtime_config_from_args(
&crate::args::parse_args(&args),
PathBuf::from("/w"),
PathBuf::from("/agent"),
None,
AppMode::Print,
true,
);
for (key, value) in saved {
match value {
Some(value) => std::env::set_var(key, value),
None => std::env::remove_var(key),
}
}
config.subagent_override
};
let layer = |model: Option<&str>, thinking: Option<&str>| {
HelperDefaults::new(model, thinking).unwrap()
};
assert_eq!(
resolve(
&["-p", "hi"],
Some("cpa-r/deepseek-flash-1017"),
Some("max")
),
layer(Some("cpa-r/deepseek-flash-1017"), Some("max"))
);
assert_eq!(
resolve(
&["--subagent-model", "cpa-r/kimi-k3.1", "-p", "hi"],
Some("cpa-r/deepseek-flash-1017"),
Some("max")
),
layer(Some("cpa-r/kimi-k3.1"), Some("max"))
);
assert_eq!(
resolve(
&["--subagent-thinking", "parent", "-p", "hi"],
None,
Some("max")
),
layer(None, Some("parent"))
);
assert_eq!(
resolve(
&["-p", "hi"],
Some("cpa-r/deepseek-flash-1017"),
Some("loud")
),
layer(Some("cpa-r/deepseek-flash-1017"), None)
);
assert_eq!(
resolve(&["-p", "hi"], None, None),
HelperDefaults::default()
);
}

/// The opt-out chain (the operator's explicit ask): `DO_NOT_TRACK`/`PI_OFFLINE` disable
/// even against `PRIME_AGENT_TELEMETRY=1`.
#[test]
Expand Down
Loading