diff options
| author | salmonik <salmonik@tuta.io> | 2026-11-15 15:38:57 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-11-15 15:38:57 +0100 |
| commit | c7afd1ea752aeff0310ac7c6b78d091ac360c760 (patch) | |
| tree | 461f22fc3633ea1ea0e23ccbf330d7a55a92bea8 /src/agent.rs | |
| parent | 0.4.1 + 0.4.2: abort integrity, stream completeness, tool-call indexing (diff) | |
| download | agent686-c7afd1ea752aeff0310ac7c6b78d091ac360c760.tar.gz agent686-c7afd1ea752aeff0310ac7c6b78d091ac360c760.zip | |
0.4.3: kill process groups, bound bash output, keep the key out of tool env
- setsid-style process group kill on timeout and on Ctrl-C
- 64 MiB RLIMIT_FSIZE so a runaway command cannot fill /tmp
- OPENCODE_API_KEY removed from child environment
- sessions 0600/0700, history 0600 and trimmed
Diffstat (limited to 'src/agent.rs')
| -rw-r--r-- | src/agent.rs | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/agent.rs b/src/agent.rs index 46da069..9e2a431 100644 --- a/src/agent.rs +++ b/src/agent.rs | |||
| @@ -159,6 +159,7 @@ pub fn run_turn( | |||
| 159 | let mut last: Option<Outcome> = None; | 159 | let mut last: Option<Outcome> = None; |
| 160 | let mut aborted = false; | 160 | let mut aborted = false; |
| 161 | let mut denied = 0usize; | 161 | let mut denied = 0usize; |
| 162 | let mut truncated: Option<String> = None; | ||
| 162 | 163 | ||
| 163 | loop { | 164 | loop { |
| 164 | if cancel.load(std::sync::atomic::Ordering::Relaxed) { | 165 | if cancel.load(std::sync::atomic::Ordering::Relaxed) { |
| @@ -184,6 +185,9 @@ pub fn run_turn( | |||
| 184 | } | 185 | } |
| 185 | } | 186 | } |
| 186 | 187 | ||
| 188 | if outcome.finish.as_deref() == Some("length") { | ||
| 189 | truncated = Some("the model hit its output limit; the answer is cut off".into()); | ||
| 190 | } | ||
| 187 | let assistant = assistant_message(&outcome); | 191 | let assistant = assistant_message(&outcome); |
| 188 | push(session, history, assistant, Some(outcome.reasoning.as_str())); | 192 | push(session, history, assistant, Some(outcome.reasoning.as_str())); |
| 189 | 193 | ||
| @@ -204,7 +208,7 @@ pub fn run_turn( | |||
| 204 | let result = if aborted { | 208 | let result = if aborted { |
| 205 | ToolOutcome::Failed("aborted by the user before this call ran".into()) | 209 | ToolOutcome::Failed("aborted by the user before this call ran".into()) |
| 206 | } else { | 210 | } else { |
| 207 | execute(&call, approver) | 211 | execute(&call, approver, cancel) |
| 208 | }; | 212 | }; |
| 209 | if result.denied() { | 213 | if result.denied() { |
| 210 | denied += 1; | 214 | denied += 1; |
| @@ -226,6 +230,9 @@ pub fn run_turn( | |||
| 226 | if aborted { | 230 | if aborted { |
| 227 | eprintln!("aborted"); | 231 | eprintln!("aborted"); |
| 228 | } | 232 | } |
| 233 | if let Some(note) = truncated { | ||
| 234 | eprintln!("agent686: {note}"); | ||
| 235 | } | ||
| 229 | if let Some(outcome) = last { | 236 | if let Some(outcome) = last { |
| 230 | ui::status(steps, started.elapsed(), &outcome); | 237 | ui::status(steps, started.elapsed(), &outcome); |
| 231 | } | 238 | } |
| @@ -281,12 +288,16 @@ fn repair_tool_results(session: &mut Session, history: &mut Vec<Value>) { | |||
| 281 | } | 288 | } |
| 282 | } | 289 | } |
| 283 | 290 | ||
| 284 | fn execute(call: &provider::ToolCall, approver: &mut Approver) -> ToolOutcome { | 291 | fn execute( |
| 292 | call: &provider::ToolCall, | ||
| 293 | approver: &mut Approver, | ||
| 294 | cancel: &AtomicBool, | ||
| 295 | ) -> ToolOutcome { | ||
| 285 | let args: Value = serde_json::from_str(&call.arguments).unwrap_or_else(|_| json!({})); | 296 | let args: Value = serde_json::from_str(&call.arguments).unwrap_or_else(|_| json!({})); |
| 286 | ui::tool_line(&call.name, &args); | 297 | ui::tool_line(&call.name, &args); |
| 287 | 298 | ||
| 288 | match tools::approval(&call.name) { | 299 | match tools::approval(&call.name) { |
| 289 | Approval::Never => match tools::run(&call.name, &args) { | 300 | Approval::Never => match tools::run(&call.name, &args, cancel) { |
| 290 | Ok(output) => ToolOutcome::Ok(output), | 301 | Ok(output) => ToolOutcome::Ok(output), |
| 291 | Err(error) => ToolOutcome::Failed(error), | 302 | Err(error) => ToolOutcome::Failed(error), |
| 292 | }, | 303 | }, |
| @@ -306,7 +317,7 @@ fn execute(call: &provider::ToolCall, approver: &mut Approver) -> ToolOutcome { | |||
| 306 | Approval::EveryCall => { | 317 | Approval::EveryCall => { |
| 307 | let cmd = args.get("cmd").and_then(|v| v.as_str()).unwrap_or(""); | 318 | let cmd = args.get("cmd").and_then(|v| v.as_str()).unwrap_or(""); |
| 308 | if approver.allow_bash(cmd) { | 319 | if approver.allow_bash(cmd) { |
| 309 | match tools::run(&call.name, &args) { | 320 | match tools::run(&call.name, &args, cancel) { |
| 310 | Ok(output) => ToolOutcome::Ok(output), | 321 | Ok(output) => ToolOutcome::Ok(output), |
| 311 | Err(error) => ToolOutcome::Failed(error), | 322 | Err(error) => ToolOutcome::Failed(error), |
| 312 | } | 323 | } |
