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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ All notable changes to Cyber Code are recorded here. The format follows [Keep a
- An isolated subagent's worktree now starts from the parent checkout's uncommitted work: staged, unstaged and untracked non-ignored files, deletions and renames are committed in the child's checkout as its base, so its result still shows only its own changes (and now reports `base`). Files the Session may not read (`.env` by default) and ignored files stay behind, `.worktreeinclude` is unchanged, and `worktrees.carry_limit_mb` (default 100, `0` off) caps the total.
- Bundled skill `/grill-me <task>`: before starting, the agent interviews you one question at a time with the `question` tool, recommending an answer for each, then summarizes the agreed scope and waits for your confirmation.
- `title.command` in the global `tui.jsonc` sets the terminal window title from your own command: it receives the Session state as JSON on stdin and its first output line is the title. It runs at most every 300 ms, only when the state changed, with a one-second limit; a project `tui.jsonc` cannot set it.
- `/model <provider/model> <prompt>` in the TUI sends one prompt to another model; the Session's model answers the next prompt again. `POST /api/v1/sessions/{id}/prompt` accepts `model` for the same one-prompt override, and the prompt's inbox row reports it.
- Computer use reports a platform-neutral capability report (schema version 2): a derived mode (`unsupported`, `capture_only`, `input_enabled`), stable reason codes, authority kind, honored selectors and the support evidence level, alongside the existing macOS fields. Receipts add platform, grant, target and frame references, a reason, cleanup state and timestamps; HTTP errors add a `reason` code. `cyber computer allow <session> --preview <id> --yes` confirms a printed review by its identifier.
- `cyber exec --format stream-json --include-hook-events` adds a `hook_event` line for each hook that ran for the run's Session (hook ID, event, scope, outcome, decision, duration, and the tool call it guarded), before the line of what it gated. Hook input, output, reasons and environment are never included. The instance event stream carries the underlying `session.hook.receipt` summaries when asked with `include=hook_receipts`, and so does a Session's event stream (`/sessions/{id}/events`) for that Session's own receipts, which `--input-format stream-json` runs follow.
- The `auto` reviewer can check context before deciding with read-only tools: `transcript_search` over the Session's history, and `read_file`/`grep_files` over the Location under the Session's own read rules (`.env`, `deny_read` globs, secret files and paths outside the Location stay unreadable). Results arrive as framed untrusted data; budgets are 8 calls, 16 KiB per result, 64 KiB per review and 5 s per call. A bare "yes"/"go ahead" reaches the reviewer together with the assistant question it answers. `permission.auto_decided.1` records `reviewer_tools` and `confirmation`; `cyber permissions auto show` adds `reviewer tool calls`.
Expand Down
11 changes: 9 additions & 2 deletions crates/cyber-cli/tests/review_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1034,16 +1034,23 @@ fn the_review_workflow_reports_target_errors_and_clean_trees_without_a_run() {

/// A budget that stops the review run exits 4 and still prints its partial findings:
/// the reviewer answers after the wall-clock budget, so no verifier starts.
///
/// The budget must expire after the reviewer asked the provider and before it answers.
/// Its clock also covers the reviewer's start (admission, child Session, first request),
/// which took over 2 s on a loaded macOS runner: with a 2 s budget the run stopped
/// before the reviewer asked, with no findings. A 20 s budget leaves room for the
/// start, and holding the answer 25 s after the request puts it after the budget
/// whenever the request came in time.
#[test]
fn a_budget_stopped_review_workflow_exits_4_with_partial_findings() {
let provider = Provider::start(Script {
result: unsorted(),
delay: Duration::from_secs(4),
delay: Duration::from_secs(25),
read_first: None,
});
let env = Env::new(&provider);
env.write("a.rs", "changed\n");
let output = env.workflow_review(&["--format", "json", "--timeout", "2s"]);
let output = env.workflow_review(&["--format", "json", "--timeout", "20s"]);
let detail = describe(&output, &provider);
assert_eq!(output.status.code(), Some(4), "{detail}");
let result = result(&output, &detail);
Expand Down
1 change: 1 addition & 0 deletions crates/cyber-server/src/http/peer/attach.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ pub(super) async fn prompt(
resume: true,
source: None,
format: None,
model: None,
};
crate::http::sessions::submit_prompt(&peer.app, &id, prompt).await
}
Expand Down
5 changes: 5 additions & 0 deletions crates/cyber-server/src/http/sessions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ pub struct PromptBody {
pub source: Option<String>,
/// A structured answer for this root prompt (`session-runtime` → Structured output).
pub format: Option<PromptFormat>,
/// `provider/model` that answers this prompt only; later prompts use the Session's
/// model again.
pub model: Option<String>,
}

/// `{ type: "json_schema", schema }`: the answer is a JSON object the schema validates,
Expand Down Expand Up @@ -820,6 +823,7 @@ pub(crate) async fn submit_prompt(
output_schema: body
.format
.map(|PromptFormat::JsonSchema { schema }| schema),
model: body.model,
};
let receipt: Receipt = match state
.runtime
Expand Down Expand Up @@ -1680,6 +1684,7 @@ mod tests {
untrusted,
output_schema: None,
structured: None,
model: None,
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/cyber-server/src/runtime/auto_override.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ impl Inner {
resources: Vec::new(),
untrusted: None,
output_schema: None,
model: None,
},
),
event(
Expand Down
3 changes: 2 additions & 1 deletion crates/cyber-server/src/runtime/continuation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl Runtime {
files: Vec<FilePart>,
) -> Result<Receipt, RuntimeError> {
self.inner.ensure_admission_open(id)?;
self.check_output_schema(id, &admission).await?;
self.check_prompt_options(id, &admission).await?;
let lifecycle = self.inner.open().await?;
let handle = self.inner.handle(id).await?;
let state = handle.state.lock().await.clone();
Expand Down Expand Up @@ -127,6 +127,7 @@ impl Runtime {
resources: attachments.resources,
untrusted: attachments.untrusted,
output_schema: None,
model: admission.model,
},
),
],
Expand Down
1 change: 1 addition & 0 deletions crates/cyber-server/src/runtime/drain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3484,6 +3484,7 @@ mod queue_head_tests {
untrusted: None,
output_schema: None,
structured: None,
model: None,
}
}

Expand Down
3 changes: 3 additions & 0 deletions crates/cyber-server/src/runtime/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ pub struct Admitted {
/// Structured output).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub output_schema: Option<Value>,
/// `provider/model` for the Turn of this prompt only.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub model: Option<String>,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
Expand Down
1 change: 1 addition & 0 deletions crates/cyber-server/src/runtime/goals/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ fn steer(goal: &Goal, text: String) -> NewEvent {
resources: Vec::new(),
untrusted: None,
output_schema: None,
model: None,
};
event(ADMITTED, &admitted)
}
Expand Down
1 change: 1 addition & 0 deletions crates/cyber-server/src/runtime/lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ impl Inner {
resources: Vec::new(),
untrusted: None,
output_schema: None,
model: None,
};
self.commit(handle, vec![event(ADMITTED, &admitted)])
.await?;
Expand Down
1 change: 1 addition & 0 deletions crates/cyber-server/src/runtime/messaging/hops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ mod tests {
untrusted: None,
output_schema: None,
structured: None,
model: None,
});
if let Some(hops) = hops {
let chain = MessageChain {
Expand Down
1 change: 1 addition & 0 deletions crates/cyber-server/src/runtime/messaging/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ impl Outgoing {
source: "session".into(),
resume: true,
output_schema: None,
model: None,
}
}

Expand Down
36 changes: 32 additions & 4 deletions crates/cyber-server/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ impl CommandPlan {
source: self.source.into(),
resume: true,
output_schema: None,
model: None,
}
}
}
Expand Down Expand Up @@ -708,6 +709,8 @@ pub struct Admission {
pub output_schema: Option<serde_json::Value>,
/// Bind this original input to a dedicated client; absent keeps legacy presence.
pub input_client: Option<InputClient>,
/// `provider/model` for this prompt's Turn only; the Session's model is unchanged.
pub model: Option<String>,
}

impl Admission {
Expand All @@ -728,10 +731,14 @@ impl Admission {
),
None => base,
};
// A retry with another schema is another prompt.
match &self.output_schema {
// A retry with another schema or model is another prompt.
let base = match &self.output_schema {
Some(schema) => format!("{base}+schema:{:x}", Sha256::digest(schema.to_string())),
None => base,
};
match &self.model {
Some(model) => format!("{base}+model:{model}"),
None => base,
}
}

Expand All @@ -746,6 +753,7 @@ impl Admission {
source: "user".into(),
resume: true,
output_schema: None,
model: None,
}
}
}
Expand Down Expand Up @@ -1737,7 +1745,7 @@ impl Runtime {
check: PromptCheck,
extra: Vec<NewEvent>,
) -> Result<Receipt, RuntimeError> {
self.check_output_schema(session_id, &admission).await?;
self.check_prompt_options(session_id, &admission).await?;
self.admit_recorded(session_id, admission, attempt, check, extra, None)
.await
}
Expand Down Expand Up @@ -1768,7 +1776,26 @@ impl Runtime {

/// A prompt's `output_schema` is for root Sessions and must pass the root schema
/// bounds (`session-runtime` → Structured output).
pub(crate) async fn check_output_schema(
/// Refuse a prompt's `output_schema` or `model` before anything is admitted.
pub(crate) async fn check_prompt_options(
&self,
session_id: &str,
admission: &Admission,
) -> Result<(), RuntimeError> {
self.check_output_schema(session_id, admission).await?;
let Some(model) = &admission.model else {
return Ok(());
};
cyber_llm::catalog::ModelRef::parse(model)
.map_err(|error| RuntimeError::Invalid(error.to_string()))?;
let handle = self.inner.handle(session_id).await?;
let info = handle.state.lock().await.info.clone();
self.inner
.resolve_selection(&info, &selection::ModelSelection::explicit(model.clone()))
.map(drop)
}

async fn check_output_schema(
&self,
session_id: &str,
admission: &Admission,
Expand Down Expand Up @@ -1866,6 +1893,7 @@ impl Runtime {
resources: attachments.resources,
untrusted: untrusted_input::merged([untrusted, attachments.untrusted]),
output_schema: admission.output_schema,
model: admission.model,
};
let mut events = Vec::new();
if let Some(attempt) = attempt {
Expand Down
32 changes: 28 additions & 4 deletions crates/cyber-server/src/runtime/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ pub struct InboxRow {
/// The structured result or error of a prompt with `output_schema`, once settled.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub structured: Option<super::StructuredOutcome>,
/// `provider/model` for this prompt's Turn only.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub model: Option<String>,
}

impl InboxRow {
/// The model this row's Turn runs on instead of the Session's: the prompt's own
/// `model`, else its command's.
pub fn turn_model(&self) -> Option<&str> {
self.model
.as_deref()
.or_else(|| self.skill_command.as_ref()?.model.as_deref())
}
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, schemars::JsonSchema)]
Expand Down Expand Up @@ -741,21 +754,31 @@ impl SessionState {
.find(|row| row.message_id == message && row.skill_command.is_some())
}

/// The current user prompt's row when it names a model for its Turn: a prompt
/// `model` or a command's `model`.
fn current_model_row(&self) -> Option<&InboxRow> {
let message = self.current_user_message()?;
self.inbox
.iter()
.find(|row| row.message_id == message && row.turn_model().is_some())
}

pub(crate) fn boundary_command_model(&self, continue_tools: bool) -> Option<&str> {
let pending = self.pending(Delivery::Steer).last().or_else(|| {
(!continue_tools)
.then(|| self.pending(Delivery::Queue).next())
.flatten()
});
match pending {
Some(row) => row.skill_command.as_ref()?.model.as_deref(),
Some(row) => row.turn_model(),
None => self.command_model(),
}
}

/// A command model applies through its tool loop, then expires at its final text reply.
/// A prompt or command model applies through its tool loop, then expires at its
/// final text reply.
pub fn command_model(&self) -> Option<&str> {
let row = self.current_command_row()?;
let row = self.current_model_row()?;
let user = self
.entries
.iter()
Expand All @@ -772,7 +795,7 @@ impl SessionState {
if last.is_some_and(|assistant| assistant.finished && assistant.calls.is_empty()) {
return None;
}
row.skill_command.as_ref()?.model.as_deref()
row.turn_model()
}

pub fn child_worktree_setup_pending(&self) -> bool {
Expand Down Expand Up @@ -1336,6 +1359,7 @@ impl SessionState {
untrusted: a.untrusted,
output_schema: a.output_schema,
structured: None,
model: a.model,
});
}

Expand Down
1 change: 1 addition & 0 deletions crates/cyber-server/src/runtime/rewind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ impl Runtime {
resources: Vec::new(),
untrusted: None,
output_schema: None,
model: None,
};
let promoted = Promoted { message_id };
self.inner
Expand Down
27 changes: 27 additions & 0 deletions crates/cyber-server/tests/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,30 @@ async fn sessions_with_a_parent_keep_their_own_model() {
assert_eq!(steps(&h, &child), vec![("test/main".into(), None)]);
assert!(h.models.requests("other/main").is_empty());
}

/// A prompt's own `model` (`/model <name> <prompt>`) answers that prompt even in a plan
/// phase, without suspending the planner: the next plan-mode prompt is on the planner.
#[tokio::test]
async fn a_one_shot_prompt_model_in_plan_mode_keeps_the_planner() {
let h = Harness::new(planner_setup(vec![
("other/main", vec![text("plan one"), text("plan two")]),
("spare/main", vec![text("second opinion")]),
]));
let id = session_in(&h, "plan", None).await;
ask(&h, &id, "plan the migration").await;
let mut once = Admission::text("what would you change?", Delivery::Queue);
once.model = Some("spare/main".into());
h.runtime.admit(&id, once).await.unwrap();
h.settle(&id).await;
let state = h.state(&id).await;
assert_eq!(h.runtime.model_role(&state), Some(PLAN_ROLE));
ask(&h, &id, "refine it").await;
assert_eq!(
steps(&h, &id),
vec![
("other/main".into(), Some("plan".into())),
("spare/main".into(), None),
("other/main".into(), Some("plan".into())),
]
);
}
41 changes: 41 additions & 0 deletions crates/cyber-tools/tests/skill_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,44 @@ async fn unavailable_command_model_preserves_pending_input_without_using_the_bas
assert!(flow.main.requests().is_empty());
flow.runtime.shutdown().await;
}

/// `session-runtime` → per-prompt model: a prompt's `model` answers that prompt, tool loop
/// included, and the next prompt runs on the Session's model again.
#[tokio::test]
async fn prompt_model_answers_one_prompt_then_the_session_model_returns() {
let flow = Flow::with_models(
support::Fixture::new(),
vec![text("base answer")],
false,
Arc::new(NoSnapshots),
vec![(
"other/once",
vec![
call("read", "read", json!({"path":"notes.txt"})),
text("once answer"),
],
)],
);
flow.f.write("notes.txt", "notes");
let id = flow.session("default").await;
let mut once = cyber_server::runtime::Admission::text("look", Delivery::Queue);
once.model = Some("other/once".into());
flow.runtime.admit_user(&id, once).await.unwrap();
flow.settle(&id).await;
let state = flow.runtime.state(&id).await.unwrap();
assert!(format!("{:?}", state.entries).contains("once answer"));
assert_eq!(state.info.model, "test/main");
assert!(flow.main.requests().is_empty());

let again = cyber_server::runtime::Admission::text("again", Delivery::Queue);
flow.runtime.admit_user(&id, again).await.unwrap();
flow.settle(&id).await;
let entries = format!("{:?}", flow.runtime.state(&id).await.unwrap().entries);
assert!(entries.contains("base answer"), "{entries}");
assert_eq!(flow.main.requests().len(), 1);

let mut unknown = cyber_server::runtime::Admission::text("x", Delivery::Queue);
unknown.model = Some("missing/model".into());
assert!(flow.runtime.admit_user(&id, unknown).await.is_err());
flow.runtime.shutdown().await;
}
Loading
Loading