Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
bc975d6
feat: add the Session tool mode and the registry projection
eric8810 Nov 25, 2026
d187447
feat: expose session.tool_mode and session.create.toolMode
eric8810 Nov 25, 2026
e2607a2
docs: carry toolMode in the Session and registry contracts
eric8810 Nov 25, 2026
515259b
fix: do not advertise the mode before the surface follows
eric8810 Nov 25, 2026
5c196ee
feat: project the request surface and admit by origin
eric8810 Nov 25, 2026
4de3892
test: carry the applied tool mode and cover the mode surface
eric8810 Nov 25, 2026
46336cf
fix: explain the input queue's registry dependency and guard the Unix…
eric8810 Nov 25, 2026
58ff3ef
fix: bind the callable when the host prepares the request
eric8810 Nov 25, 2026
2494abf
feat: register execute as a tool and route the live stop
eric8810 Nov 25, 2026
87f66a8
feat: settle goals on an effective shell transition
eric8810 Nov 25, 2026
64abfb2
docs: document the shell parts and the mode faces
eric8810 Nov 25, 2026
274d0f6
fix: use the settle handler's question mark
eric8810 Nov 25, 2026
3fa4938
fix: read the tool mode without refreshing providers
eric8810 Nov 25, 2026
1647ef4
feat: choose the tool mode in the web composer
eric8810 Nov 25, 2026
1d60b2f
style: format the mode transition and goal settle
eric8810 Nov 25, 2026
d5b6644
feat: choose the tool mode in the TUI settings panel
eric8810 Nov 26, 2026
8992eac
feat: withdraw queued goal inputs when shell takes over
eric8810 Nov 26, 2026
78534ee
feat: advertise the modes the daemon can serve
eric8810 Nov 26, 2026
18546da
feat: settle an entry registration before its turns run
eric8810 Nov 26, 2026
e6a39da
test: give the chat page mock the mode readers
eric8810 Nov 26, 2026
ab9f645
fix: keep the settings rows visible and list execute in the run tools
eric8810 Nov 26, 2026
5f3e1b2
test: select the isolation row above the tools group
eric8810 Nov 26, 2026
860e6a6
fix: address the tool mode review
eric8810 Nov 26, 2026
0b90fef
test: pin the request surface against a hidden top-level call
eric8810 Nov 26, 2026
ba4501f
test: pause an active goal on an effective shell update
eric8810 Nov 26, 2026
143d030
test: a member inherits the leader's live tool mode
eric8810 Nov 26, 2026
2237cd9
test: apply a restored queued input under the persisted mode
eric8810 Nov 26, 2026
6bf71fc
test: reprice usage after a mode-only switch
eric8810 Nov 26, 2026
e72b830
fix: close the second tool mode review round
eric8810 Nov 26, 2026
a62b940
fix: re-read the tool mode whenever /settings opens
eric8810 Nov 26, 2026
8012523
fix: send only a saved tool mode the protocol names
eric8810 Nov 26, 2026
7ef399c
fix: take the queued goal inputs when a settle withdraws them
eric8810 Nov 26, 2026
7673ce5
test: the native probe declares the normal-visible run tools
eric8810 Nov 26, 2026
7338bf0
fix: settle the pause before shell is effective and retry withdrawals
eric8810 Nov 26, 2026
4b92cc2
fix: list all three TUI modes and guard Home settings
eric8810 Nov 26, 2026
0fa5b95
fix: price usage by the turn's pinned mode
eric8810 Nov 26, 2026
38d54a0
test: pin the rebuild release and a member's effective mode
eric8810 Nov 26, 2026
1fa465e
fix: retry a pause whose application failed
eric8810 Nov 26, 2026
e29c134
fix: price usage from the turn's start and correct the picker mark
eric8810 Nov 26, 2026
b32b6b0
fix: keep usage on the live mode for an idle Session
eric8810 Nov 26, 2026
e9649ae
fix: pause an active goal when its branch activates under shell
eric8810 Nov 26, 2026
9d96d2f
fix: start a turn only after an entry registration settles
eric8810 Nov 26, 2026
bddb34e
fix: restore the lint gate and finish the settle window
eric8810 Nov 26, 2026
c875178
feat: record the turn pin and keep a failed shell registration normal
eric8810 Nov 26, 2026
9d43a4a
refactor: keep goal_update visible in shell and drop the Goal settle
eric8810 Nov 26, 2026
9c13f83
refactor: price usage from the request and drop recorded mode fields
eric8810 Nov 26, 2026
fea154b
refactor: keep the tool mode out of the turn and use it live
eric8810 Nov 26, 2026
44e1920
chore: drop the Goal and applied-mode leftovers
eric8810 Nov 26, 2026
32b0d03
docs: align the design with the live mode read
eric8810 Nov 26, 2026
b29d288
docs: state the request-declaration usage source
eric8810 Nov 26, 2026
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
20 changes: 15 additions & 5 deletions crates/dim-agent-capabilities/src/agent_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,11 @@ impl AgentLoop {
.history
.rendered_context(&self.timeline, through)
.await?;
let tool_mode = self.binding.effective_mode();
let Some(request) = configured_request(
&crate::context_policy::PolicyContext::from_context(context.clone()),
&history,
tool_mode,
) else {
return failed("Context is not configured; adopt a model first".into());
};
Expand Down Expand Up @@ -1205,8 +1207,11 @@ impl AgentLoop {
let cancel = self.lifecycle.child_token();
let result_cancel = cancel.clone();
let owner = self.clone();
let mut through = through;
self.tasks.spawn(async move {
let work = AssertUnwindSafe(async {
let tool_mode = owner.binding.effective_mode();
through = through.max(owner.timeline.sequence());
if let Some(mut source) = recovery {
owner
.binding
Expand Down Expand Up @@ -1236,13 +1241,18 @@ impl AgentLoop {
Some(tools) => {
owner
.binding
.bind(&request_id, through, tools, &data.settings.tool_sources)
.map_err(AgentError::InvalidInput)?;
tools.clone()
.bind(
&request_id,
through,
tools,
&data.settings.tool_sources,
tool_mode,
)
.map_err(AgentError::InvalidInput)?
}
None => owner
.binding
.bind_current(&request_id, None)
.bind_current(&request_id, tool_mode, None)
.map_err(AgentError::InvalidInput)?,
}),
system: data.system.clone(),
Expand All @@ -1255,7 +1265,7 @@ impl AgentLoop {
None => {
let mut settings = owner
.binding
.prepare(&request_id, |tools| {
.prepare(&request_id, tool_mode, |tools| {
owner
.prepare
.0
Expand Down
8 changes: 7 additions & 1 deletion crates/dim-agent-capabilities/src/context_policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,14 +400,20 @@ fn checkpoint(data: &ContextCompactionData) -> Option<CompactionCheckpoint> {
pub(crate) fn configured_request(
context: &PolicyContext,
history: &[HistoryEntry],
tool_mode: ToolMode,
) -> Option<Arc<ModelRequest>> {
let data = context.configuration()?;
let tools = data
.settings
.tools
.as_ref()
.map(|tools| crate::tool_registry::project(tool_mode, tools).0);
Some(Arc::new(
ModelSettings {
provider_id: data.settings.provider_id.clone(),
model_id: data.settings.model_id.clone(),
capability_snapshot: data.settings.capability_snapshot.clone(),
tools: data.settings.tools.clone(),
tools,
system: data.system.clone(),
config: crate::context_model::adopted_config(
data.settings.capability_snapshot.as_ref(),
Expand Down
91 changes: 66 additions & 25 deletions crates/dim-agent-capabilities/src/context_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use crate::{
tool_registry::ToolRegistry,
};
use dim_agent_runtime::{
AgentError, BranchLifecycle, Dispatcher, Names, QueryFilter, QueryOperand, QueryOutput,
QueryPage, QueryPick, QuerySelect, QuerySpec, QueryValue, Result, Timeline, TimelineQuery,
TimelineQueryScope,
AgentError, BranchLifecycle, Dispatcher, Names, QueryFilter, QueryOperand, QueryOrder,
QueryOrderKey, QueryOutput, QueryPage, QueryPick, QuerySelect, QuerySpec, QueryValue, Result,
Timeline, TimelineQuery, TimelineQueryDirection, TimelineQueryScope,
};
use dim_agent_types::*;
use futures_util::FutureExt;
Expand Down Expand Up @@ -1013,9 +1013,7 @@ impl ContextUsage {
.await
.map_err(ContextOpError::Read)?
.ok_or_else(|| ContextOpError::Read(fault("missing initialized usage total")))?;
if let Some(Configuration::Ready { counter }) = &summary.configuration
&& counter.configured_tools != Some(true)
{
if let Some(Configuration::Ready { counter }) = &summary.configuration {
let model = view
.model
.as_ref()
Expand All @@ -1024,6 +1022,9 @@ impl ContextUsage {
.current_tools(counter, model.as_ref(), through)
.await
.map_err(ContextOpError::Read)?;
if fixed.fixed == counter.fixed {
return reading(through, &summary, None);
}
let counter_model = model
.contribution_counter()
.ok_or_else(|| ContextOpError::Read(fault("missing additive counter")))?;
Expand All @@ -1043,31 +1044,78 @@ impl ContextUsage {
reading(through, &summary, None)
}

/// The tools the last model request at or before `through` declared.
async fn request_tools(&self, through: u64) -> Result<Option<Vec<ToolDefinition>>> {
let reply = self
.timeline
.query(TimelineQuery {
scope: TimelineQueryScope::Branch,
from: None,
through: Some(through),
include_publishing: false,
query: QuerySpec {
filter: Some(QueryFilter::In {
value: QueryOperand::Field {
path: "kind".into(),
},
values: vec![serde_json::json!("model/call")],
}),
select: QuerySelect::Fields {
fields: vec!["data.request.tools".into()],
},
group_by: vec![],
pick: None,
order_by: vec![QueryOrder {
key: QueryOrderKey::Position,
direction: TimelineQueryDirection::Descending,
}],
},
page: Some(QueryPage {
limit: NonZeroU64::MIN,
after: None,
}),
})
.await?;
let Some(value) = (match &reply.result {
QueryOutput::Rows { rows } => {
rows.first().and_then(|row| match row.values.as_slice() {
[QueryValue::Value { value }] => Some(value.clone()),
_ => None,
})
}
_ => None,
}) else {
return Ok(None);
};
Ok(serde_json::from_value::<Option<Vec<ToolDefinition>>>(value)
.ok()
.flatten())
}

async fn current_tools(
&self,
configuration: &CounterConfiguration,
model: &dyn ContextModel,
through: u64,
) -> Result<DynamicFixed> {
if configuration.configured_tools.is_none()
&& self
.configured_tools(&configuration.event_id, through)
.await?
{
return Ok(DynamicFixed {
configuration: configuration.event_id.clone(),
versions: String::new(),
identity: configuration.request_identity.clone(),
fixed: configuration.fixed,
});
}
let sources = self.registry.sources();
let versions = fingerprint(
&sources
.iter()
.map(|source| (&source.key, &source.version))
.collect::<Vec<_>>(),
)?;
let tools = self
.request_tools(through)
.await?
.unwrap_or_else(|| self.registry.visible_definitions());
let tools_fingerprint = fingerprint(
&tools
.iter()
.map(|tool| (&tool.name, &tool.description))
.collect::<Vec<_>>(),
)?;
let versions = format!("{versions}:{tools_fingerprint}");
if let Some(cached) = self
.dynamic_fixed
.lock()
Expand All @@ -1079,13 +1127,6 @@ impl ContextUsage {
{
return Ok(cached.clone());
}
let (tools, sources) = self.registry.snapshot();
let versions = fingerprint(
&sources
.iter()
.map(|source| (&source.key, &source.version))
.collect::<Vec<_>>(),
)?;
let mut system = self
.fields(&configuration.event_id, through, &["data.system"])
.await?;
Expand Down
32 changes: 32 additions & 0 deletions crates/dim-agent-capabilities/src/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ pub fn install_minimal_execution(
)?))
}),
);
tool_host(builder, Arc::new(NoTools));
crate::shell_tools::install(builder);
crate::prompt_sources::install(builder);
crate::skills::install(builder);
Expand Down Expand Up @@ -294,6 +295,14 @@ pub fn install_local_execution_with(
crate::prompt_sources::DATE_CHECK,
prompt_sources,
);
builder.require_feature(
Feature::new("ShellSession").branch("ShellSession", |names| {
Ok(Box::new(crate::shell_session::ShellSessionPlugin::session(
names,
)?))
}),
);
crate::shell_tools::install(builder);
crate::skills::install(builder);
}

Expand Down Expand Up @@ -323,6 +332,29 @@ pub fn install_compaction(
);
}

/// A `ToolHost` with no host tools: the minimal profile's only tool is

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] The two doc comments are stacked on NoTools: the pre-existing Installs driver as the Session ToolHost line above now documents NoTools, and this added comment documents it too, while pub fn tool_host below has no doc. Move the first line back above tool_host.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Fixed] NoTools and tool_host each have their own doc comment again (crates/dim-agent-capabilities/src/defaults.rs:335-354).

/// `execute`, registered by [`crate::shell_tools`].
pub struct NoTools;

impl ToolDriver for NoTools {
fn definitions(&self) -> Vec<dim_agent_types::ToolDefinition> {
Vec::new()
}

fn execute(
&self,
_: dim_agent_types::ToolCall,
_: crate::host::ToolExecutionContext,
_: tokio_util::sync::CancellationToken,
) -> crate::host::HostFuture<'_, dim_agent_types::ToolResult> {
Box::pin(async {
Err(crate::host::HostError::failed(
"this profile has no host tools",
))
})
}
}

/// Installs `driver` as the Session `ToolHost`.
pub fn tool_host(builder: &mut AgentBuilder, driver: Arc<dyn ToolDriver>) {
crate::register_names(builder);
Expand Down
1 change: 1 addition & 0 deletions crates/dim-agent-capabilities/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ impl PublicService for shell_session::ShellSession {}
impl PublicService for dyn exec_stop::ExecStop {}
impl PublicService for workspace_tools::file_reads::FileReads {}
impl PublicService for timeline_tree::BranchLine {}
impl PublicService for tool_registry::ToolRegistry {}
impl PublicService for timeline_tree::TreeCommands {}
impl PublicService for prompt_sources::PromptSourcesBranch {}
impl PublicService for wait::Wait {}
Expand Down
11 changes: 10 additions & 1 deletion crates/dim-agent-capabilities/src/prompt_sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
prompt::Prompt,
prompt_registry::{PromptRegistry, PromptRegistryPlugin, targets},
prompt_state::PromptSnapshot,
tool_registry::ToolRegistry,
};
use dim_agent_runtime::{
AgentBuilder, BranchLifecycle, BranchPhase, ConfigureUpdate, Names, PromptSourceTarget,
Expand Down Expand Up @@ -254,6 +255,7 @@ fn environment(
shell: &ShellStatus,
cwd: &str,
policy: &PromptSourcesConfig,
shell_mode: bool,
) -> String {
let os = match platform.os {
Os::Macos => "darwin",
Expand Down Expand Up @@ -287,7 +289,7 @@ fn environment(
OutputEncoding::Unknown => "unknown",
},
));
if platform.os == Os::Windows {
if platform.os == Os::Windows && !shell_mode {
let guidance = policy
.file_encoding_guidance
.as_deref()
Expand Down Expand Up @@ -478,6 +480,7 @@ impl PromptSourcesBranch {
struct Sources {
platform: Arc<HostPlatform>,
config: Arc<SessionConfig>,
tools: Arc<ToolRegistry>,
today: Today,
stopped: CancellationToken,
policy: PromptSourcesConfig,
Expand Down Expand Up @@ -526,6 +529,7 @@ impl LoadPrompt for Sources {
&self.platform.exec_shell().await,
&self.config.cwd,
&self.policy,
self.tools.effective_tool_mode_now() == dim_agent_types::ToolMode::Shell,
)),
PromptDelivery::State,
200,
Expand Down Expand Up @@ -566,6 +570,7 @@ impl LoadPrompt for Sources {
pub struct PromptSourcesPlugin {
platform: Key<HostPlatform>,
config: Key<SessionConfig>,
tools: Key<ToolRegistry>,
registry: Key<PromptRegistry>,
language: Key<SessionLanguage>,
settings: Option<Key<BasePromptSettingsHost>>,
Expand All @@ -586,6 +591,7 @@ impl PromptSourcesPlugin {
Ok(Self {
platform: names.key()?,
config: names.key()?,
tools: names.key()?,
registry: names.key()?,
language: names.key()?,
settings: names
Expand All @@ -605,13 +611,15 @@ impl DynPlugin for PromptSourcesPlugin {
vec![
self.platform.erase(),
self.config.erase(),
self.tools.erase(),
self.registry.erase(),
]
}
fn apply<'a>(&'a self, ctx: &'a Ctx) -> BoxFuture<'a, rutis::Result<Effect>> {
Box::pin(async move {
let platform = ctx.require_at(&self.platform)?;
let config = ctx.require_at(&self.config)?;
let tools = ctx.require_at(&self.tools)?;
let registry = ctx.require_at(&self.registry)?;
// Apply runs once per Session instance: builder rows cannot
// reload, and every rebuilt daemon or fork creates a new
Expand Down Expand Up @@ -640,6 +648,7 @@ impl DynPlugin for PromptSourcesPlugin {
let sources: Arc<dyn LoadPrompt> = Arc::new(Sources {
platform,
config,
tools,
today: self.today.clone(),
stopped: ctx.cancellation_token(),
policy,
Expand Down
Loading