Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
bf79658
docs: expose service methods instead of an execHost face
eric8810 Nov 22, 2026
21c6e24
feat(host-platform): serve hostPlatform data methods
eric8810 Nov 22, 2026
cbe4b75
refactor(host-platform): annotate the original HostPlatform block
eric8810 Nov 22, 2026
b6ed380
feat(host-platform): serve command task operations
eric8810 Nov 22, 2026
8b17b57
refactor(host-platform): type the wait reply
eric8810 Nov 22, 2026
aabb04d
feat(host-platform): serve persistent shell tasks
eric8810 Nov 22, 2026
07fd907
feat(host-platform): serve configured and confined helpers
eric8810 Nov 22, 2026
cab9102
feat(host-platform): serve output removal and child path
eric8810 Nov 22, 2026
6aef688
fix(host-platform): make the shell path real and align replies
eric8810 Nov 22, 2026
a3c0e72
docs(host-platform): state the service preconditions
eric8810 Nov 22, 2026
509ba41
feat(host-platform): log shell events for remote readers
eric8810 Nov 22, 2026
ed06e16
refactor(host-platform): remove the shell output channel
eric8810 Nov 22, 2026
c5d4e53
feat(host-platform): run shell sessions through the data API
eric8810 Nov 22, 2026
2d1e643
fix(host-platform): a wait timeout stops waiting, not the task
eric8810 Nov 22, 2026
1e1f8c7
fix(host-platform): restore the minimal profile and harden task bound…
eric8810 Nov 22, 2026
1396403
fix(host-platform): backpressure the shell event stream
eric8810 Nov 22, 2026
00b082b
refactor(host-platform): emit shell output and marker events
eric8810 Nov 22, 2026
524deae
fix(host-platform): never kill a shell from a lagging read
eric8810 Nov 22, 2026
17ec402
feat(host-platform): own shell command captures
eric8810 Nov 22, 2026
a56c536
fix(shell-session): keep plain shell writes capture-free
eric8810 Nov 22, 2026
1fc4ecb
fix(host-platform): skip other markers in command capture
eric8810 Nov 22, 2026
0bc566e
refactor(host-platform): own shell command capture and occupancy
eric8810 Nov 22, 2026
11b63b9
fix(host-platform): close shell task boundary gaps
eric8810 Nov 22, 2026
6b814d3
feat(host-platform): reserve shell background jobs in the owner
eric8810 Nov 22, 2026
05c6d9d
docs(host-platform): state the owner data face and settlement rules
eric8810 Nov 22, 2026
7fd191a
refactor(host-platform): remove the unused command_files path
eric8810 Nov 23, 2026
aba6725
refactor(host-platform): pass execution paths as data strings
eric8810 Nov 23, 2026
984f6b5
fix(host-platform): reject non-UTF-8 execution paths
eric8810 Nov 23, 2026
8ac2dc8
docs(host-platform): record the task-owner redesign
eric8810 Nov 24, 2026
31f6980
test(host-platform): compile the Windows data-face callers
eric8810 Nov 23, 2026
552443c
docs(host-platform): include the task-stop route
eric8810 Nov 24, 2026
33d6bc4
docs(host-platform): keep the stop dependency one-way
eric8810 Nov 24, 2026
882e7a2
docs(host-platform): resolve the task-owner contract review
eric8810 Nov 24, 2026
7e43727
refactor(host-platform): one task record and per-kind payload
eric8810 Nov 24, 2026
9e352aa
refactor(host-platform): one snapshot, typed errors and failures
eric8810 Nov 24, 2026
4aad34d
refactor(exec): run commands as owner task ids
eric8810 Nov 24, 2026
8b8522f
refactor(host-platform): owner splitter and shell watchers
eric8810 Nov 24, 2026
fd686a3
refactor(host-platform): owner shell settlement and reads
eric8810 Nov 24, 2026
5233f39
fix(host-platform): one boundary policy
eric8810 Nov 24, 2026
1cb76a8
fix(app-server): route session.exec.stop through the branch stop owner
eric8810 Nov 24, 2026
7151509
docs(host-platform): one owner contract
eric8810 Nov 24, 2026
8d8071e
fix(host-platform): validate a job output path before its start fact
eric8810 Nov 24, 2026
6053ff1
refactor(host-platform): drop the unused platform self-reference
eric8810 Nov 24, 2026
187cd03
fix(shell-session): report the shell exit code from a swept command
eric8810 Nov 24, 2026
048f4a5
docs(host-platform): mark the design as implemented
eric8810 Nov 24, 2026
789b16b
fix(host-platform): close the round-25 review findings
eric8810 Nov 24, 2026
98f7fd0
docs(host-platform): update the verification and page declarations
eric8810 Nov 24, 2026
9b555a5
fix(host-platform): close the round-26 ownership findings
eric8810 Nov 24, 2026
0e0de6b
docs(host-platform): keep log locations with their owner
eric8810 Nov 24, 2026
b3e8b1f
fix(host-platform): keep a public shell reader progressing
eric8810 Nov 24, 2026
b3c5b28
fix(host-platform): publish the host terminal result
eric8810 Nov 24, 2026
1efb88f
fix(host-platform): close the round-27 completion and queue findings
eric8810 Nov 24, 2026
6f7f902
fix(shell-session): stop the watcher and cancel occupied waits
eric8810 Nov 24, 2026
1c9ec2f
fix(host-platform): decode shell chunks and preserve job codes
eric8810 Nov 24, 2026
054949a
fix(shell-session): publish the owner terminal for every job
eric8810 Nov 24, 2026
110ad1f
fix(host-platform): hold live shell work and release early stops
eric8810 Nov 24, 2026
eb99e70
fix(host-platform): close the remaining review P3s
eric8810 Nov 24, 2026
ede0f88
fix(host-platform): satisfy the warning gate
eric8810 Nov 24, 2026
3c89d99
fix(host-platform): close the round-28 P1/P2/P3 follow-ups
eric8810 Nov 24, 2026
023bec2
refactor(host-platform): remove the dead shell event state
eric8810 Nov 24, 2026
26c2a6f
fix(host-platform): finish the shell decoder at EOF
eric8810 Nov 24, 2026
7c52155
fix(host-platform): decode job previews and cover a job write
eric8810 Nov 24, 2026
aae0a70
docs(host-platform): align the stop record with the late-pid worker
eric8810 Nov 24, 2026
1641ece
fix(exec-stop): keep a read fault distinct from an unknown task
eric8810 Nov 24, 2026
9405d48
fix(exec-stop): map a recovery read fault to exec_task_read
eric8810 Nov 24, 2026
596e840
fix(host-platform): keep the escape tail bounded and finish failed kills
eric8810 Nov 24, 2026
cf2116e
docs(host-platform): state the job path contract
eric8810 Nov 24, 2026
2ec586a
fix(host-platform): keep an escape from eating the next marker
eric8810 Nov 24, 2026
8a6b621
fix(host-platform): classify raw output before display sanitizing
eric8810 Nov 24, 2026
742984a
test(host-platform): cover job path refusal
eric8810 Nov 24, 2026
3ddc826
fix(shell-session): publish the owner child result at shell exit
eric8810 Nov 25, 2026
ee2431a
fix(shell-session): preserve the late owner terminal and cleanup
eric8810 Nov 25, 2026
3960d13
refactor(shell-session): drop the unused file tail helper
eric8810 Nov 25, 2026
ebeb05f
fix(shell-session): fix the teardown handoff and failed-kill ownership
eric8810 Nov 25, 2026
e36922d
fix(shell-session): let the occupying watcher own the teardown result
eric8810 Nov 25, 2026
b9248bb
fix(host-platform): observe failed job release and clear the occupy slot
eric8810 Nov 25, 2026
491ce61
merge origin/main into the host-platform branch
eric8810 Nov 25, 2026
eda2433
fix(host-platform): observe release without re-signalling and keep ch…
eric8810 Nov 25, 2026
47bd237
fix(host-platform): observe Windows release and join repeated stops
eric8810 Nov 25, 2026
f90c812
fix(host-platform): match the Windows process status type
eric8810 Nov 25, 2026
4655fe9
fix(host-platform): serialize job stops and observe Windows tree release
eric8810 Nov 25, 2026
ffdd19d
fix(host-platform): keep the Windows release wait in kill_job
eric8810 Nov 25, 2026
cdb4052
fix(host-platform): claim only job stops and observe the Windows tree
eric8810 Nov 25, 2026
86efd80
fix(host-platform): release the stop claim and track the original Win…
eric8810 Nov 25, 2026
f05002b
fix(host-platform): retain the original job tree for deferred release
eric8810 Nov 25, 2026
40ee500
fix(host-platform): capture the job tree before termination
eric8810 Nov 25, 2026
e4b4950
fix(host-platform): share one job tree between the wait and observer
eric8810 Nov 25, 2026
e8470ed
fix(host-platform): do not confirm a partial Windows process walk
eric8810 Nov 25, 2026
c31fafc
fix(host-platform): keep an empty process snapshot unconfirmed
eric8810 Nov 25, 2026
bc4e0bd
fix(host-platform): keep an unknown release recoverable
eric8810 Nov 25, 2026
9fbd475
fix(host-platform): bound the release observer even with a stale tree
eric8810 Nov 25, 2026
a22492b
fix(host-platform): keep cleanup ownership after an unconfirmed stop
eric8810 Nov 25, 2026
d71528c
docs(host-platform): state the job stop lifecycle
eric8810 Nov 25, 2026
88afcf1
docs(host-platform): include the shell-reset job sweep
eric8810 Nov 25, 2026
9448f8c
fix(host-platform): do not use a later tree as release evidence
eric8810 Nov 25, 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
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ mod linux {
}

async fn run(platform: &HostPlatform, spec: ProcessSpec) -> Result<Output> {
let mut tree = platform.spawn(spec)?;
let mut tree = platform.spawn_tree(spec)?;
let (mut stdout, mut stderr) = (tree.stdout(), tree.stderr());
let (mut out, mut err) = (Vec::new(), Vec::new());
let (status, _, _) = tokio::time::timeout(LIMIT, async {
Expand Down Expand Up @@ -315,7 +315,7 @@ mod linux {
spec
};
let script = "(while :; do printf x >> heartbeat; sleep 0.05; done) > background.log 2>&1 & echo $! > child.pid; echo ready; while test ! -f release; do sleep 0.01; done";
let mut tree = platform.spawn(prepare(command(
let mut tree = platform.spawn_tree(prepare(command(
&workspace,
Path::new("/bin/sh"),
vec!["-c".into(), script.into()],
Expand Down Expand Up @@ -518,7 +518,8 @@ mod linux {
);
checks.push("host UNIX socket outside grants is inaccessible");

let mut tree = platform.spawn(isolated(shell("sleep 60 & echo ready; wait"), &readonly))?;
let mut tree =
platform.spawn_tree(isolated(shell("sleep 60 & echo ready; wait"), &readonly))?;
let mut line = String::new();
tokio::time::timeout(LIMIT, BufReader::new(tree.stdout()).read_line(&mut line)).await??;
assert_eq!(line.trim(), "ready");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ mod macos {
}

async fn run(platform: &HostPlatform, spec: ProcessSpec) -> Result<Output> {
let mut tree = platform.spawn(spec)?;
let mut tree = platform.spawn_tree(spec)?;
let (mut stdout, mut stderr) = (tree.stdout(), tree.stderr());
let (mut out, mut err) = (Vec::new(), Vec::new());
let (status, _, _) = tokio::time::timeout(LIMIT, async {
Expand Down Expand Up @@ -253,7 +253,7 @@ mod macos {
assert!(!marker.exists());
checks.push("invalid policy never executes payload");

let mut tree = platform.spawn(isolated(
let mut tree = platform.spawn_tree(isolated(
command(
&workspace,
"/bin/sh",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ mod linux {
Ok(spec)
}
async fn run(platform: &HostPlatform, spec: ProcessSpec) -> Result<Output> {
let mut tree = platform.spawn(spec)?;
let mut tree = platform.spawn_tree(spec)?;
let (mut stdout, mut stderr) = (tree.stdout(), tree.stderr());
let (mut out, mut err) = (Vec::new(), Vec::new());
let (status, _, _) = tokio::time::timeout(LIMIT, async {
Expand Down Expand Up @@ -277,7 +277,7 @@ mod linux {
assert!(!marker.exists());
checks.push("invalid policy does not execute payload");

let mut tree = platform.spawn(isolated(
let mut tree = platform.spawn_tree(isolated(
shell(
"sleep 60 & child=$!; printf '%s\\n' \"$child\"; wait \"$child\"",
vec![],
Expand Down
1 change: 1 addition & 0 deletions crates/dim-agent-capabilities/src/exec_stop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::sync::Arc;
pub enum TaskError {
Unknown,
Closed,
Read,
}

/// Stops a background task by id.
Expand Down
2 changes: 1 addition & 1 deletion crates/dim-agent-capabilities/src/file_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ impl Worktrees {
env.push(("LC_ALL".into(), "C".into()));
let mut tree = self
.platform
.spawn(ProcessSpec {
.spawn_tree(ProcessSpec {
executable: "git".into(),
args: vec![
"-C".into(),
Expand Down
234 changes: 114 additions & 120 deletions crates/dim-agent-capabilities/src/hooks/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ use crate::{
handlers,
},
host::{HostError, HostFuture},
host_platform::{HostPlatform, Os},
host_platform::{
HostPlatform, HostPlatformError, Os, OutputLimits, SpawnWithStdinReply,
SpawnWithStdinRequest, SpawnWithStdinStatus,
},
input_queue::{CheckSubmission, SubmitCheckReply, SubmitCheckRequest, SubmitChecks},
permission::{AdmissionDecision, AdviseTool, Permission, ToolAdviceReply, ToolAdviceRequest},
tool_registry::ToolRegistry,
};
use base64::{Engine, engine::general_purpose::STANDARD};
use dim_agent_runtime::{
AgentError, BranchLifecycle, CollaborationRole, Dispatcher, Names, QueryComparison,
QueryFilter, QueryOperand, QueryOutput, QueryPage, QueryPick, QuerySelect, QuerySpec,
Expand All @@ -35,18 +39,14 @@ use rutis::host::{BoxFuture, CtxHost, DynPlugin, Effect, Key, TypeKey};
use serde_json::{Value, json};
use std::{
collections::HashMap,
ffi::OsString,
future::Future,
num::NonZeroU64,
path::Path,
pin::Pin,
sync::{Arc, Mutex},
time::{Duration, Instant},
};
use tokio::{
io::{AsyncRead, AsyncReadExt},
sync::mpsc,
};
use tokio::sync::mpsc;
use tokio_util::{sync::CancellationToken, task::TaskTracker};

/// A hook's stdout is bounded; more than this is a failure (A.3).
Expand Down Expand Up @@ -385,90 +385,71 @@ impl HooksRuntime {
) -> HookResult {
let command = handler.command(self.platform.os == Os::Windows);
let started = Instant::now();
let mut spec = match self
.platform
.build_process_spec(command, Path::new(&self.config.cwd))
.await
{
Ok((spec, _)) => spec,
Err(error) => {
let result = failed(format!("{}: {}", error.code, error.reason), &[]);
self.report(handler, &result, started.elapsed());
return result;
}
};
spec.env = hook_env(spec.env, &self.environment(handler));
if gate.is_some_and(|gate| gate.is_cancelled()) {
return HookResult::Failed {
reason: UNLOADED.into(),
stderr: String::new(),
};
return unloaded_run(handler).result;
}
let mut tree = match self.platform.spawn_with_stdin(spec, stdin) {
Ok(tree) => tree,
Err(error) => {
let result = failed(format!("spawn failed: {error}"), &[]);
let env = match self.environment(handler) {
Ok(env) => env,
Err(reason) => {
let result = failed(reason, &[]);
self.report(handler, &result, started.elapsed());
return result;
}
};
let mut stdout = tree.stdout();
let mut stderr = tree.stderr();
enum End {
Done(
(Vec<u8>, bool),
(Vec<u8>, bool),
std::io::Result<std::process::ExitStatus>,
),
Cancelled,
TimedOut,
}
let end = tokio::select! {
biased;
_ = cancel.cancelled() => End::Cancelled,
_ = tokio::time::sleep(handler.timeout) => End::TimedOut,
(out, err, status) = async {
tokio::join!(
read_capped(&mut stdout, STDOUT_LIMIT),
read_capped(&mut stderr, STDERR_LIMIT),
tree.wait(),
)
} => End::Done(out, err, status),
let request = SpawnWithStdinRequest {
command: command.into(),
cwd: self.config.cwd.clone(),
env,
stdin: Some(STANDARD.encode(stdin)),
timeout_ms: handler.timeout.as_millis() as u64,
limits: OutputLimits {
stdout: STDOUT_LIMIT,
stderr: STDERR_LIMIT,
},
};
let result = match end {
End::Cancelled => {
let _ = tree.terminate().await;
failed("cancelled", &[])
let reply = match self
.platform
.spawn_with_stdin(request, cancelled_by(cancel, gate))
.await
{
Ok(reply) => reply,
Err(HostPlatformError::Cancelled) if gate.is_some_and(|gate| gate.is_cancelled()) => {
return unloaded_run(handler).result;
}
End::TimedOut => {
let _ = tree.terminate().await;
failed(
format!("timed out after {}s", handler.timeout.as_secs()),
&[],
)
Err(HostPlatformError::Cancelled) => return failed("cancelled", &[]),
Err(error) => {
let result = failed(error.to_string(), &[]);
self.report(handler, &result, started.elapsed());
return result;
}
End::Done((bytes, overflow), (stderr, _), status) => {
let status = match status {
Ok(status) => status,
// A run whose end cannot be read still reports (§7).
Err(error) => {
let result = failed(format!("wait failed: {error}"), &stderr);
self.report(handler, &result, started.elapsed());
return result;
}
};
if overflow {
};
let stdout = STANDARD.decode(&reply.stdout).unwrap_or_default();
let stderr = STANDARD.decode(&reply.stderr).unwrap_or_default();
let result = match reply.status {
SpawnWithStdinStatus::Exited => {
if reply.stdout_truncated {
failed("stdout exceeded 64 KiB", &stderr)
} else if status.code() == Some(2) {
} else if reply.exit_code == Some(2) {
exit_two(handler.event, &stderr)
} else if status.success() {
} else if reply.exit_code == Some(0) {
HookResult::Success {
stdout: String::from_utf8_lossy_owned(bytes),
stdout: String::from_utf8_lossy_owned(stdout),
}
} else {
failed(format!("exited with {status}"), &stderr)
failed(format!("exited with {}", exit_text(&reply)), &stderr)
}
}
SpawnWithStdinStatus::Signaled => {
failed(format!("exited with {}", exit_text(&reply)), &stderr)
}
SpawnWithStdinStatus::Cancelled if gate.is_some_and(|gate| gate.is_cancelled()) => {
unloaded_run(handler).result
}
SpawnWithStdinStatus::Cancelled => failed("cancelled", &[]),
SpawnWithStdinStatus::TimedOut => failed(
format!("timed out after {}s", handler.timeout.as_secs()),
&[],
),
};
self.report(handler, &result, started.elapsed());
// The run's result is taken here, in the same poll that hands it to
Expand Down Expand Up @@ -498,59 +479,72 @@ impl HooksRuntime {
);
}

fn environment(&self, handler: &HookHandler) -> Vec<(&'static str, OsString)> {
let mut vars = vec![
("DIM_PROJECT_DIR", OsString::from(self.config.cwd.clone())),
("DIM_HOOK_EVENT", OsString::from(handler.event.name())),
(
"DIM_SESSION_ID",
OsString::from(self.identity.session_id.clone()),
fn environment(
&self,
handler: &HookHandler,
) -> Result<std::collections::BTreeMap<String, Option<String>>, String> {
let mut env: std::collections::BTreeMap<_, _> = MANAGED_ENV
.into_iter()
.map(|key| (key.to_owned(), None))
.collect();
let home = match self.sources.0.home() {
Some(home) => Some(
home.to_str()
.ok_or_else(|| "DIMCODE_HOME is not UTF-8".to_owned())?
.to_owned(),
),
];
if let Some(home) = self.sources.0.home() {
vars.push(("DIMCODE_HOME", home.into_os_string()));
}
if let Some(root) = &handler.plugin_root {
vars.push(("DIM_PLUGIN_ROOT", root.clone().into_os_string()));
None => None,
};
let plugin_root = match handler.plugin_root.as_ref() {
Some(root) => Some(
root.to_str()
.ok_or_else(|| "DIM_PLUGIN_ROOT is not UTF-8".to_owned())?
.to_owned(),
),
None => None,
};
for (key, value) in [
("DIM_PROJECT_DIR", Some(self.config.cwd.clone())),
("DIM_HOOK_EVENT", Some(handler.event.name().to_owned())),
("DIM_SESSION_ID", Some(self.identity.session_id.clone())),
("DIMCODE_HOME", home),
("DIM_PLUGIN_ROOT", plugin_root),
] {
env.insert(key.to_owned(), value);
}
vars
Ok(env)
}
}

fn hook_env(
env: Vec<(OsString, OsString)>,
vars: &[(&'static str, OsString)],
) -> Vec<(OsString, OsString)> {
let mut env: Vec<(OsString, OsString)> = env
.into_iter()
.filter(|(key, _)| !MANAGED_ENV.iter().any(|name| key == name))
.collect();
env.extend(
vars.iter()
.map(|(key, value)| (OsString::from(*key), value.clone())),
);
env
/// Cancels the call when the point's cancel or the unload gate fires.
fn cancelled_by(
cancel: &CancellationToken,
gate: Option<&CancellationToken>,
) -> crate::host::CancelledFn {
let cancel = cancel.clone();
let gate = gate.cloned();
std::sync::Arc::new(move || {
let cancel = cancel.clone();
let gate = gate.clone();
Box::pin(async move {
match gate {
Some(gate) => tokio::select! {
biased;
_ = cancel.cancelled() => {}
_ = gate.cancelled() => {}
},
None => cancel.cancelled().await,
}
Ok(())
})
})
}

/// Reads at most `limit` bytes and drains the rest, so the writer never
/// blocks; the bool says more was written.
async fn read_capped<R: AsyncRead + Unpin>(reader: &mut R, limit: usize) -> (Vec<u8>, bool) {
let mut kept = Vec::new();
let mut buffer = [0u8; 8192];
let mut overflow = false;
loop {
match reader.read(&mut buffer).await {
Ok(0) | Err(_) => return (kept, overflow),
Ok(read) => {
let room = limit.saturating_sub(kept.len());
if read <= room {
kept.extend_from_slice(&buffer[..read]);
} else {
kept.extend_from_slice(&buffer[..room]);
overflow = true;
}
}
}
fn exit_text(reply: &SpawnWithStdinReply) -> String {
match (reply.exit_code, &reply.signal) {
(Some(code), _) => format!("exit status: {code}"),
(_, Some(signal)) => format!("signal: {signal}"),
_ => "unknown".to_owned(),
}
}

Expand Down
Loading