You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by wy...@apache.org on 2026/10/23 05:58:14 UTC
(maka) 01/04: refactor(code-mode): share cell effects and output contracts
This is an automated email from the ASF dual-hosted git repository.
M4n5ter pushed a commit to branch feat/python-code-mode
in repository https://gitbox.apache.org/repos/asf/maka.git
commit 82f6495b6fd09d75569b1fc158cca515ac5131a7
Author: Wang <m4...@gmail.com>
AuthorDate: Fri Oct 23 13:21:15 2026 +0800
refactor(code-mode): share cell effects and output contracts
Generated-by: Codex
---
Cargo.lock | 20 +++
Cargo.toml | 2 +
.../tools => platform/code-runtime}/Cargo.toml | 11 +-
.../src/cell_context.rs | 18 +--
platform/code-runtime/src/lib.rs | 46 +++++++
.../{js-runtime => code-runtime}/src/result.rs | 6 +-
platform/code-runtime/src/scope.rs | 148 +++++++++++++++++++++
platform/computer-use/Cargo.toml | 1 +
platform/computer-use/tests/repl_browser.rs | 3 +-
platform/computer-use/tests/repl_contract.rs | 3 +-
platform/js-runtime/Cargo.toml | 1 +
platform/js-runtime/src/bridge.rs | 107 +--------------
platform/js-runtime/src/lib.rs | 55 ++------
platform/js-runtime/src/repl.rs | 33 ++---
.../js-runtime/tests/integration/cell_context.rs | 7 +-
platform/js-runtime/tests/integration/code_mode.rs | 13 +-
platform/js-runtime/tests/integration/repl.rs | 7 +-
.../tests/integration/result_contract.rs | 5 +-
plugins/agent/engine/Cargo.toml | 1 +
plugins/agent/engine/src/lib.rs | 2 +-
.../agent/engine/tests/integration/agent_loop.rs | 3 +-
.../agent/engine/tests/integration/code_mode.rs | 3 +-
.../engine/tests/integration/code_mode_lifetime.rs | 3 +-
.../engine/tests/integration/code_mode_media.rs | 3 +-
plugins/agent/engine/tests/integration/handoff.rs | 3 +-
plugins/agent/engine/tests/integration/lifetime.rs | 3 +-
.../engine/tests/integration/model_interruption.rs | 3 +-
.../engine/tests/integration/startup_recovery.rs | 3 +-
.../engine/tests/integration/support/context.rs | 3 +-
.../tests/integration/support/image_projection.rs | 3 +-
.../engine/tests/integration/tool_arguments.rs | 3 +-
plugins/agent/native/Cargo.toml | 1 +
plugins/agent/native/src/owner.rs | 2 +-
plugins/agent/native/src/tools/computer.rs | 2 +-
plugins/agent/tools/Cargo.toml | 1 +
plugins/agent/tools/src/cell/session.rs | 2 +-
plugins/agent/tools/src/dispatch.rs | 2 +-
plugins/agent/tools/tests/integration/catalog.rs | 3 +-
plugins/agent/tools/tests/integration/cells.rs | 3 +-
.../agent/tools/tests/integration/child_image.rs | 3 +-
.../agent/tools/tests/integration/commit_faults.rs | 3 +-
.../tools/tests/integration/large_child_output.rs | 3 +-
plugins/agent/tools/tests/integration/preflight.rs | 3 +-
.../workspace/workspace-computer/native/Cargo.toml | 1 +
.../workspace-computer/native/src/evaluate.rs | 7 +-
products/maka/cli/Cargo.toml | 1 +
products/maka/cli/src/code.rs | 8 +-
47 files changed, 336 insertions(+), 231 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index 006a1ae17f..34f653a0cd 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -8213,6 +8213,7 @@ dependencies = [
"maka-agent-facts",
"maka-agent-ports",
"maka-capabilities",
+ "maka-code-runtime",
"maka-event-log",
"maka-js-runtime",
"maka-model",
@@ -8269,6 +8270,7 @@ dependencies = [
"maka-agent-ports",
"maka-assistant",
"maka-capabilities",
+ "maka-code-runtime",
"maka-computer-native",
"maka-computer-use",
"maka-config",
@@ -8453,6 +8455,7 @@ dependencies = [
"maka-agent-ports",
"maka-app-client",
"maka-capabilities",
+ "maka-code-runtime",
"maka-computer-use",
"maka-config",
"maka-event-log",
@@ -8498,6 +8501,19 @@ dependencies = [
"windows-sys 0.61.2",
]
+[[package]]
+name = "maka-code-runtime"
+version = "0.2.0"
+dependencies = [
+ "futures-util",
+ "maka-agent-facts",
+ "serde",
+ "serde_json",
+ "thiserror 2.0.20",
+ "tokio",
+ "tokio-util",
+]
+
[[package]]
name = "maka-computer-native"
version = "0.2.0"
@@ -8509,6 +8525,7 @@ dependencies = [
"maka-agent-authority",
"maka-agent-facts",
"maka-capabilities",
+ "maka-code-runtime",
"maka-computer-use",
"maka-event-log",
"maka-host-runtime",
@@ -8536,6 +8553,7 @@ dependencies = [
"libc",
"maka-agent-facts",
"maka-capabilities",
+ "maka-code-runtime",
"maka-js-runtime",
"objc2 0.6.4",
"objc2-app-kit 0.3.2",
@@ -8911,6 +8929,7 @@ dependencies = [
"maka-agent-facts",
"maka-agent-ports",
"maka-capabilities",
+ "maka-code-runtime",
"maka-plugin-core",
"serde",
"serde_json",
@@ -9408,6 +9427,7 @@ version = "0.2.0"
dependencies = [
"futures-util",
"maka-agent-facts",
+ "maka-code-runtime",
"maka-event-log",
"maka-js-runtime",
"maka-tool-catalog",
diff --git a/Cargo.toml b/Cargo.toml
index 6b3bfbbb48..3f563132b0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -55,6 +55,7 @@ members = [
"plugins/agent/insights",
"plugins/workspace/workspace-jev/engine",
"platform/js-runtime",
+ "platform/code-runtime",
"plugins/agent/model",
"plugins/agent/provider-protocol",
"platform/network",
@@ -153,6 +154,7 @@ maka-graph = { path = "plugins/agent/graph" }
maka-insights = { path = "plugins/agent/insights" }
maka-jev = { path = "plugins/workspace/workspace-jev/engine" }
maka-js-runtime = { path = "platform/js-runtime" }
+maka-code-runtime = { path = "platform/code-runtime" }
maka-model = { path = "plugins/agent/model" }
maka-provider-protocol = { path = "plugins/agent/provider-protocol" }
maka-network = { path = "platform/network" }
diff --git a/plugins/agent/tools/Cargo.toml b/platform/code-runtime/Cargo.toml
similarity index 83%
copy from plugins/agent/tools/Cargo.toml
copy to platform/code-runtime/Cargo.toml
index e9db9aae80..4d6636e4a5 100644
--- a/plugins/agent/tools/Cargo.toml
+++ b/platform/code-runtime/Cargo.toml
@@ -16,7 +16,7 @@
# under the License.
[package]
-name = "maka-tools"
+name = "maka-code-runtime"
version.workspace = true
edition.workspace = true
license.workspace = true
@@ -25,15 +25,8 @@ publish.workspace = true
[dependencies]
maka-agent-facts.workspace = true
futures-util.workspace = true
-maka-js-runtime.workspace = true
-maka-tool-catalog.workspace = true
serde.workspace = true
-schemars.workspace = true
serde_json.workspace = true
+thiserror.workspace = true
tokio.workspace = true
tokio-util.workspace = true
-uuid.workspace = true
-
-[dev-dependencies]
-tempfile.workspace = true
-maka-event-log.workspace = true
diff --git a/platform/js-runtime/src/cell_context.rs b/platform/code-runtime/src/cell_context.rs
similarity index 95%
rename from platform/js-runtime/src/cell_context.rs
rename to platform/code-runtime/src/cell_context.rs
index 364bacf56e..a7c8a25529 100644
--- a/platform/js-runtime/src/cell_context.rs
+++ b/platform/code-runtime/src/cell_context.rs
@@ -28,7 +28,7 @@ use std::{
};
use tokio::sync::Notify;
-/// Only JSON crosses cell boundaries; neither V8 handles nor authority are stored.
+/// Only JSON crosses cell boundaries; neither interpreter values nor authority are stored.
#[derive(Clone, Default)]
pub struct CellStore(Arc<Mutex<BTreeMap<String, Value>>>);
@@ -74,7 +74,7 @@ pub struct ToolMetadata {
pub description: String,
}
-/// A cell's JSON scratch data and emitted output, separate from its V8 heap.
+/// A cell's JSON scratch data and emitted output, separate from its interpreter heap.
/// Host observers own delivery; the VM only appends and requests an observation.
#[derive(Clone)]
pub struct CellContext(Arc<Inner>);
@@ -127,7 +127,7 @@ impl CellContext {
}))
}
- pub(crate) fn metadata(&self) -> &[ToolMetadata] {
+ pub fn metadata(&self) -> &[ToolMetadata] {
&self.0.metadata
}
@@ -139,7 +139,7 @@ impl CellContext {
self
}
- /// Host failures are visible before drain, but never erased by JS catch.
+ /// Host failures are visible before drain, but never erased by user exception handling.
pub fn failure(&self) -> Option<ToolError> {
self.0.state.lock().unwrap().failure.clone()
}
@@ -149,11 +149,11 @@ impl CellContext {
self.yield_output();
}
- pub(crate) fn load(&self, key: &str) -> Option<Value> {
+ pub fn load(&self, key: &str) -> Option<Value> {
self.0.state.lock().unwrap().values.get(key).cloned()
}
- pub(crate) fn store(&self, key: String, value: Value) -> Result<(), CellDiagnostic> {
+ pub fn store(&self, key: String, value: Value) -> Result<(), CellDiagnostic> {
let mut state = self.0.state.lock().unwrap();
state.values.insert(key.clone(), value.clone());
state.writes.insert(key, value);
@@ -170,7 +170,7 @@ impl CellContext {
Ok(())
}
- pub(crate) fn emit(&self, output: CellOutput) -> Result<(), CellDiagnostic> {
+ pub fn emit(&self, output: CellOutput) -> Result<(), CellDiagnostic> {
if let CellOutput::Media { content, .. } = &output
&& !matches!(
content,
@@ -200,7 +200,7 @@ impl CellContext {
Ok(())
}
- pub(crate) fn yield_output(&self) {
+ pub fn yield_output(&self) {
self.0.state.lock().unwrap().yielded = true;
self.0.changed.notify_one();
}
@@ -221,7 +221,7 @@ impl CellContext {
std::mem::take(&mut state.output)
}
- pub(crate) fn notify(&self, text: String) -> Result<(), CellDiagnostic> {
+ pub fn notify(&self, text: String) -> Result<(), CellDiagnostic> {
let closed = self.0.notification_gate.0.lock().unwrap();
if *closed {
return Err(CellDiagnostic::new(
diff --git a/platform/code-runtime/src/lib.rs b/platform/code-runtime/src/lib.rs
new file mode 100644
index 0000000000..a8a482fc0a
--- /dev/null
+++ b/platform/code-runtime/src/lib.rs
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+//! Shared cell outputs, JSON state and Host effect ownership for code interpreters.
+
+mod cell_context;
+mod result;
+mod scope;
+
+pub use cell_context::{CellContext, CellOutput, CellStore, NotificationGate, ToolMetadata};
+pub use result::{CellAbort, CellDiagnostic, CellDiagnosticKind, CellResult, ToolCall, complete};
+pub use scope::ToolScope;
+use std::time::Duration;
+
+#[derive(Clone, Debug)]
+pub struct CellLimits {
+ /// Cumulative synchronous VM execution, excluding asynchronous Host tool waits.
+ pub timeout: Duration,
+ /// Interpreter allocation budget; each backend documents its accounting boundary.
+ pub heap_bytes: usize,
+}
+
+impl Default for CellLimits {
+ fn default() -> Self {
+ Self {
+ timeout: Duration::from_secs(30),
+ heap_bytes: 64 * 1024 * 1024,
+ }
+ }
+}
diff --git a/platform/js-runtime/src/result.rs b/platform/code-runtime/src/result.rs
similarity index 92%
rename from platform/js-runtime/src/result.rs
rename to platform/code-runtime/src/result.rs
index fd365d480e..ef9d95a145 100644
--- a/platform/js-runtime/src/result.rs
+++ b/platform/code-runtime/src/result.rs
@@ -49,13 +49,13 @@ pub struct CellDiagnostic {
}
impl CellDiagnostic {
- pub(crate) fn new(kind: CellDiagnosticKind, message: impl Into<String>) -> Self {
+ pub fn new(kind: CellDiagnosticKind, message: impl Into<String>) -> Self {
Self {
kind,
message: message.into(),
}
}
- pub(crate) fn limit(message: impl Into<String>) -> Self {
+ pub fn limit(message: impl Into<String>) -> Self {
Self::new(CellDiagnosticKind::LimitExceeded, message)
}
}
@@ -97,7 +97,7 @@ impl Serialize for CellResult {
}
}
-pub(crate) fn complete(result: Result<Value, CellDiagnostic>, calls: Vec<ToolCall>) -> CellResult {
+pub fn complete(result: Result<Value, CellDiagnostic>, calls: Vec<ToolCall>) -> CellResult {
match result {
Ok(value) => CellResult::Success {
value,
diff --git a/platform/code-runtime/src/scope.rs b/platform/code-runtime/src/scope.rs
new file mode 100644
index 0000000000..dbb3cad249
--- /dev/null
+++ b/platform/code-runtime/src/scope.rs
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use crate::{CellContext, CellDiagnostic, CellDiagnosticKind, ToolCall};
+use maka_agent_facts::tools::{ToolError, ToolExecutor};
+use serde_json::Value;
+use std::{
+ collections::HashSet,
+ sync::{Arc, Mutex},
+};
+use tokio::{runtime::Handle, sync::oneshot};
+use tokio_util::{sync::CancellationToken, task::TaskTracker};
+
+#[derive(Default)]
+struct Admission {
+ calls: Vec<ToolCall>,
+}
+
+pub struct ToolScope {
+ context: CellContext,
+ executor: Arc<dyn ToolExecutor>,
+ names: HashSet<String>,
+ cancellation: CancellationToken,
+ tasks: TaskTracker,
+ host: Handle,
+ admission: Mutex<Admission>,
+}
+
+impl ToolScope {
+ pub fn new(
+ context: CellContext,
+ executor: Arc<dyn ToolExecutor>,
+ cancellation: CancellationToken,
+ host: Handle,
+ ) -> Arc<Self> {
+ Arc::new(Self {
+ names: executor.names().into_iter().collect(),
+ context,
+ executor,
+ cancellation,
+ tasks: TaskTracker::new(),
+ host,
+ admission: Mutex::new(Admission::default()),
+ })
+ }
+
+ pub fn cancel(&self) {
+ self.cancellation.cancel();
+ }
+
+ pub async fn settle(&self) {
+ self.tasks.close();
+ self.tasks.wait().await;
+ }
+
+ pub fn calls(&self) -> Vec<ToolCall> {
+ self.admission.lock().unwrap().calls.clone()
+ }
+
+ pub fn start(
+ self: &Arc<Self>,
+ name: String,
+ input: Value,
+ ) -> Result<oneshot::Receiver<Result<Value, CellDiagnostic>>, CellDiagnostic> {
+ if self.cancellation.is_cancelled() {
+ return Err(CellDiagnostic::new(
+ CellDiagnosticKind::ExecutionError,
+ "cell cancelled",
+ ));
+ }
+ if !self.names.contains(&name) {
+ return Err(CellDiagnostic::new(
+ CellDiagnosticKind::UnknownTool,
+ format!("unknown tool: {name}"),
+ ));
+ }
+ {
+ let mut admission = self.admission.lock().unwrap();
+ if self.cancellation.is_cancelled() {
+ return Err(CellDiagnostic::new(
+ CellDiagnosticKind::ExecutionError,
+ "cell cancelled",
+ ));
+ }
+ let index = admission.calls.len() + 1;
+ let mut reserved = admission.calls.clone();
+ reserved.push(ToolCall {
+ index,
+ name: name.clone(),
+ });
+ admission.calls = reserved;
+ }
+ let (sender, receiver) = oneshot::channel();
+ let scope = self.clone();
+ self.tasks.spawn_on(
+ async move {
+ use futures_util::FutureExt;
+ let result = std::panic::AssertUnwindSafe(async {
+ if scope.cancellation.is_cancelled() {
+ return Err(ToolError::Failed(
+ "cell cancelled before tool dispatch".into(),
+ ));
+ }
+ scope
+ .executor
+ .invoke(name, input, scope.cancellation.clone())
+ .await
+ })
+ .catch_unwind()
+ .await;
+ let result = result.unwrap_or_else(|_| {
+ Err(ToolError::CleanupUnconfirmed(
+ "tool executor panicked".into(),
+ ))
+ });
+ if let Err(error @ (ToolError::Persistence(_) | ToolError::CleanupUnconfirmed(_))) =
+ &result
+ {
+ scope.cancellation.cancel();
+ scope.context.fail(error.clone());
+ }
+ // The effect is settled even if user code no longer observes its result.
+ let result = result.map_err(|error| {
+ CellDiagnostic::new(CellDiagnosticKind::ToolFailure, error.to_string())
+ });
+ let _ = sender.send(result);
+ },
+ &self.host,
+ );
+ Ok(receiver)
+ }
+}
diff --git a/platform/computer-use/Cargo.toml b/platform/computer-use/Cargo.toml
index 19397291d6..985ec397b5 100644
--- a/platform/computer-use/Cargo.toml
+++ b/platform/computer-use/Cargo.toml
@@ -46,6 +46,7 @@ native-desktop = [
]
[dependencies]
+maka-code-runtime.workspace = true
hex = { workspace = true, optional = true }
maka-agent-facts.workspace = true
maka-capabilities.workspace = true
diff --git a/platform/computer-use/tests/repl_browser.rs b/platform/computer-use/tests/repl_browser.rs
index 1291bf5e2f..9b1fc01c92 100644
--- a/platform/computer-use/tests/repl_browser.rs
+++ b/platform/computer-use/tests/repl_browser.rs
@@ -20,8 +20,9 @@
use maka_agent_facts::tools::ToolFuture;
use maka_agent_facts::{language::Language, tools::ToolExecutor};
use maka_capabilities::computer::BrowserConnection;
+use maka_code_runtime::{CellContext, CellLimits, CellOutput, CellResult, CellStore};
use maka_computer_use::{Driver, Session, facade};
-use maka_js_runtime::{CellContext, CellLimits, CellOutput, CellResult, CellStore, repl::Repl};
+use maka_js_runtime::repl::Repl;
use serde_json::{Value, json};
use std::{process::Stdio, sync::Arc, time::Duration};
use tokio::{
diff --git a/platform/computer-use/tests/repl_contract.rs b/platform/computer-use/tests/repl_contract.rs
index 4d695e34c7..6a220afafa 100644
--- a/platform/computer-use/tests/repl_contract.rs
+++ b/platform/computer-use/tests/repl_contract.rs
@@ -19,8 +19,9 @@
use maka_agent_facts::tools::ToolExecutor;
use maka_agent_facts::tools::ToolFuture;
+use maka_code_runtime::{CellContext, CellLimits, CellOutput, CellResult};
use maka_computer_use::facade;
-use maka_js_runtime::{CellContext, CellLimits, CellOutput, CellResult, repl::Repl};
+use maka_js_runtime::repl::Repl;
use serde_json::{Value, json};
use std::{sync::Arc, time::Duration};
use tokio_util::sync::CancellationToken;
diff --git a/platform/js-runtime/Cargo.toml b/platform/js-runtime/Cargo.toml
index 6491f0da2d..baee45cff4 100644
--- a/platform/js-runtime/Cargo.toml
+++ b/platform/js-runtime/Cargo.toml
@@ -23,6 +23,7 @@ license.workspace = true
publish.workspace = true
[dependencies]
+maka-code-runtime.workspace = true
maka-agent-facts.workspace = true
maka-agent-ports.workspace = true
maka-capabilities.workspace = true
diff --git a/platform/js-runtime/src/bridge.rs b/platform/js-runtime/src/bridge.rs
index 0daf569396..877de829fa 100644
--- a/platform/js-runtime/src/bridge.rs
+++ b/platform/js-runtime/src/bridge.rs
@@ -17,110 +17,11 @@
* under the License.
*/
-use crate::{CellContext, CellDiagnostic, CellDiagnosticKind, CellOutput, ToolCall};
+use crate::{CellContext, CellDiagnostic, CellDiagnosticKind, CellOutput};
use deno_core::{OpState, op2};
-use maka_agent_facts::tools::ToolError;
-use maka_agent_facts::tools::ToolExecutor;
-use serde_json::Value;
-use std::{
- cell::RefCell,
- collections::HashSet,
- future::Future,
- rc::Rc,
- sync::{Arc, Mutex},
-};
-use tokio::{runtime::Handle, sync::oneshot};
-use tokio_util::{sync::CancellationToken, task::TaskTracker};
-
-#[derive(Default)]
-pub(crate) struct Admission {
- pub(crate) calls: Vec<ToolCall>,
-}
-
-pub(crate) struct ToolScope {
- pub(crate) context: CellContext,
- pub(crate) executor: Arc<dyn ToolExecutor>,
- pub(crate) names: HashSet<String>,
- pub(crate) cancellation: CancellationToken,
- pub(crate) tasks: TaskTracker,
- pub(crate) host: Handle,
- pub(crate) admission: Mutex<Admission>,
-}
-
-impl ToolScope {
- fn start(
- self: &Arc<Self>,
- name: String,
- input: Value,
- ) -> Result<oneshot::Receiver<Result<Value, CellDiagnostic>>, CellDiagnostic> {
- if self.cancellation.is_cancelled() {
- return Err(CellDiagnostic::new(
- CellDiagnosticKind::ExecutionError,
- "cell cancelled",
- ));
- }
- if !self.names.contains(&name) {
- return Err(CellDiagnostic::new(
- CellDiagnosticKind::UnknownTool,
- format!("unknown tool: {name}"),
- ));
- }
- {
- let mut admission = self.admission.lock().unwrap();
- if self.cancellation.is_cancelled() {
- return Err(CellDiagnostic::new(
- CellDiagnosticKind::ExecutionError,
- "cell cancelled",
- ));
- }
- let index = admission.calls.len() + 1;
- let mut reserved = admission.calls.clone();
- reserved.push(ToolCall {
- index,
- name: name.clone(),
- });
- admission.calls = reserved;
- }
- let (sender, receiver) = oneshot::channel();
- let scope = self.clone();
- self.tasks.spawn_on(
- async move {
- use deno_core::futures::FutureExt;
- let result = std::panic::AssertUnwindSafe(async {
- if scope.cancellation.is_cancelled() {
- return Err(ToolError::Failed(
- "cell cancelled before tool dispatch".into(),
- ));
- }
- scope
- .executor
- .invoke(name, input, scope.cancellation.clone())
- .await
- })
- .catch_unwind()
- .await;
- let result = result.unwrap_or_else(|_| {
- Err(ToolError::CleanupUnconfirmed(
- "tool executor panicked".into(),
- ))
- });
- if let Err(error @ (ToolError::Persistence(_) | ToolError::CleanupUnconfirmed(_))) =
- &result
- {
- scope.cancellation.cancel();
- scope.context.fail(error.clone());
- }
- // The effect is settled even if JS no longer observes its promise.
- let result = result.map_err(|error| {
- CellDiagnostic::new(CellDiagnosticKind::ToolFailure, error.to_string())
- });
- let _ = sender.send(result);
- },
- &self.host,
- );
- Ok(receiver)
- }
-}
+use maka_code_runtime::ToolScope;
+use std::{cell::RefCell, future::Future, rc::Rc, sync::Arc};
+use tokio_util::sync::CancellationToken;
// Synchronous admission before returning the future is intentional: even an
// unawaited JS call immediately becomes tracked host work.
diff --git a/platform/js-runtime/src/lib.rs b/platform/js-runtime/src/lib.rs
index 130a73b01f..9cc51676c2 100644
--- a/platform/js-runtime/src/lib.rs
+++ b/platform/js-runtime/src/lib.rs
@@ -18,43 +18,23 @@
*/
mod bridge;
-mod cell_context;
mod evaluate;
mod execution_budget;
mod module;
pub mod plugin;
pub mod repl;
-mod result;
-use bridge::{Admission, ToolScope, maka_code};
-pub use cell_context::{CellContext, CellOutput, CellStore, NotificationGate, ToolMetadata};
+use bridge::maka_code;
use deno_core::{JsRuntime, RuntimeOptions, v8};
use evaluate::evaluate;
use execution_budget::ExecutionBudget;
use maka_agent_facts::tools::ToolExecutor;
-use result::complete;
-pub use result::{CellAbort, CellDiagnostic, CellDiagnosticKind, CellResult, ToolCall};
+use maka_code_runtime::complete;
+use maka_code_runtime::{CellAbort, CellDiagnostic, CellDiagnosticKind, CellResult};
+use maka_code_runtime::{CellContext, CellLimits, CellOutput, CellStore, ToolMetadata, ToolScope};
use std::sync::{Arc, Mutex, Once};
-use std::time::Duration;
use tokio::runtime::Handle;
-use tokio_util::{sync::CancellationToken, task::TaskTracker};
-
-#[derive(Clone, Debug)]
-pub struct CellLimits {
- /// Cumulative synchronous VM execution, excluding asynchronous Host tool waits.
- pub timeout: Duration,
- /// V8 heap limit only; not an OS memory limit or a process sandbox.
- pub heap_bytes: usize,
-}
-
-impl Default for CellLimits {
- fn default() -> Self {
- Self {
- timeout: Duration::from_secs(30),
- heap_bytes: 64 * 1024 * 1024,
- }
- }
-}
+use tokio_util::sync::CancellationToken;
/// Fresh isolates off the host's async worker threads, each retaining ownership
/// of admitted Rust tools until they have finished cleanup.
@@ -73,7 +53,6 @@ impl CodeExecutor {
{
return Err(CellAbort::Internal("invalid cell limits".into()));
}
- initialize_platform();
Ok(Self { limits })
}
@@ -187,15 +166,13 @@ async fn run_cell(
return Err(CellAbort::Cancelled);
}
let names = executor.names();
- let scope = Arc::new(ToolScope {
- context: context.clone(),
+ let scope = ToolScope::new(
+ context.clone(),
executor,
- names: names.iter().cloned().collect(),
- cancellation: cancellation.child_token(),
- tasks: TaskTracker::new(),
- host: host.clone(),
- admission: Mutex::new(Admission::default()),
- });
+ cancellation.child_token(),
+ host.clone(),
+ );
+ initialize_platform();
let mut runtime = JsRuntime::try_new(RuntimeOptions {
extensions: vec![maka_code::init()],
create_params: Some(v8::CreateParams::default().heap_limits(0, limits.heap_bytes)),
@@ -267,12 +244,11 @@ async fn run_cell(
}
};
if module || result.is_err() {
- scope.cancellation.cancel();
+ scope.cancel();
}
// No more ops can enter once the runtime is destroyed.
drop(runtime);
- scope.tasks.close();
- scope.tasks.wait().await;
+ scope.settle().await;
finished.cancel();
monitor
.await
@@ -291,10 +267,7 @@ async fn run_cell(
Some(StopReason::HeapLimit) => Err(CellDiagnostic::limit("JavaScript heap")),
None => result,
};
- Ok(complete(
- result,
- scope.admission.lock().unwrap().calls.clone(),
- ))
+ Ok(complete(result, scope.calls()))
}
#[derive(Clone, Copy)]
diff --git a/platform/js-runtime/src/repl.rs b/platform/js-runtime/src/repl.rs
index 3cf923b347..edbf69bbe9 100644
--- a/platform/js-runtime/src/repl.rs
+++ b/platform/js-runtime/src/repl.rs
@@ -23,21 +23,21 @@
use crate::{
CellAbort, CellContext, CellDiagnostic, CellDiagnosticKind, CellLimits, CellResult,
- bridge::{Admission, ToolScope, maka_code},
- result::complete,
+ bridge::maka_code,
};
use deno_core::{
InspectorMsg, InspectorMsgKind, InspectorSessionKind, JsRuntime, JsRuntimeInspector,
RuntimeOptions, v8,
};
use maka_agent_facts::tools::ToolExecutor;
+use maka_code_runtime::{ToolScope, complete};
use serde_json::{Value, json};
-use std::sync::{Arc, Mutex};
+use std::sync::Arc;
use tokio::{
runtime::Handle,
sync::{mpsc, oneshot},
};
-use tokio_util::{sync::CancellationToken, task::TaskTracker};
+use tokio_util::sync::CancellationToken;
pub struct Repl {
sender: mpsc::Sender<Evaluation>,
@@ -182,15 +182,12 @@ async fn serve(
)));
continue;
}
- let scope = Arc::new(ToolScope {
- context: request.context.clone(),
- names: request.executor.names().into_iter().collect(),
- executor: request.executor,
- cancellation: request.cancellation.child_token(),
- tasks: TaskTracker::new(),
- host: host.clone(),
- admission: Mutex::new(Admission::default()),
- });
+ let scope = ToolScope::new(
+ request.context.clone(),
+ request.executor,
+ request.cancellation.child_token(),
+ host.clone(),
+ );
runtime.op_state().borrow_mut().put(scope.clone());
runtime.op_state().borrow_mut().put(request.context.clone());
@@ -253,9 +250,8 @@ async fn serve(
} => result,
};
// Drain native work even after a JS exception, timeout or a lost caller.
- scope.cancellation.cancel();
- scope.tasks.close();
- scope.tasks.wait().await;
+ scope.cancel();
+ scope.settle().await;
finished.cancel();
monitor
.await
@@ -266,10 +262,7 @@ async fn serve(
} else if request.cancellation.is_cancelled() || stopped.is_cancelled() {
Err(CellAbort::Cancelled)
} else {
- Ok(complete(
- result,
- scope.admission.lock().unwrap().calls.clone(),
- ))
+ Ok(complete(result, scope.calls()))
};
// Publish terminal state before waking the observer. The Session still
// owns and joins this worker on reset/close, but it cannot be reused.
diff --git a/platform/js-runtime/tests/integration/cell_context.rs b/platform/js-runtime/tests/integration/cell_context.rs
index 33c30956da..d4e357ddc6 100644
--- a/platform/js-runtime/tests/integration/cell_context.rs
+++ b/platform/js-runtime/tests/integration/cell_context.rs
@@ -20,9 +20,8 @@
use maka_agent_facts::tools::ToolError;
use maka_agent_facts::tools::ToolExecutor;
use maka_agent_facts::tools::ToolFuture;
-use maka_js_runtime::{
- CellContext, CellLimits, CellOutput, CellResult, CellStore, CodeExecutor, ToolMetadata,
-};
+use maka_code_runtime::{CellContext, CellLimits, CellOutput, CellResult, CellStore, ToolMetadata};
+use maka_js_runtime::CodeExecutor;
use serde_json::{Value, json};
use std::sync::{
Arc,
@@ -240,7 +239,7 @@ async fn fatal_failure_is_observable_before_other_accepted_work_finishes_cleanup
assert!(matches!(context.failure(), Some(ToolError::Persistence(_))));
assert!(futures_util::poll!(&mut worker).is_pending(), "admitted work remains owned during cleanup");
tools.release.notify_one();
- assert!(matches!(worker.await.unwrap(), Err(maka_js_runtime::CellAbort::Tool(ToolError::Persistence(_)))));
+ assert!(matches!(worker.await.unwrap(), Err(maka_code_runtime::CellAbort::Tool(ToolError::Persistence(_)))));
assert_eq!(tools.later.load(Ordering::SeqCst), 0);
}).await.expect("fatal notification must not wait for cleanup");
}
diff --git a/platform/js-runtime/tests/integration/code_mode.rs b/platform/js-runtime/tests/integration/code_mode.rs
index 29c4401f39..41f23b2a72 100644
--- a/platform/js-runtime/tests/integration/code_mode.rs
+++ b/platform/js-runtime/tests/integration/code_mode.rs
@@ -22,7 +22,8 @@ use std::time::Duration;
use maka_agent_facts::tools::ToolExecutor;
use maka_agent_facts::tools::ToolFuture;
-use maka_js_runtime::{CellDiagnostic, CellDiagnosticKind, CellLimits, CellResult, CodeExecutor};
+use maka_code_runtime::{CellDiagnostic, CellDiagnosticKind, CellLimits, CellResult};
+use maka_js_runtime::CodeExecutor;
use serde_json::{Value, json};
use tokio::sync::{Barrier, Notify};
use tokio_util::sync::CancellationToken;
@@ -171,8 +172,10 @@ async fn javascript_failure_cancels_and_drains_dispatched_tools() {
// Admission precedes dispatch. Wait for the tool to enter before failing JS,
// otherwise cancellation may correctly prevent dispatch altogether.
let mut task = tokio::spawn(async move {
- let context =
- maka_js_runtime::CellContext::new(maka_js_runtime::CellStore::default(), vec![]);
+ let context = maka_code_runtime::CellContext::new(
+ maka_code_runtime::CellStore::default(),
+ vec![],
+ );
executor()
.execute_module(
format!(
@@ -281,7 +284,7 @@ async fn dropping_caller_cancels_tools_without_blocking_independent_cells() {
trait SuccessResult {
fn success_value(&self) -> Value;
- fn calls(&self) -> &[maka_js_runtime::ToolCall];
+ fn calls(&self) -> &[maka_code_runtime::ToolCall];
}
impl SuccessResult for CellResult {
fn success_value(&self) -> Value {
@@ -290,7 +293,7 @@ impl SuccessResult for CellResult {
_ => panic!("{self:?}"),
}
}
- fn calls(&self) -> &[maka_js_runtime::ToolCall] {
+ fn calls(&self) -> &[maka_code_runtime::ToolCall] {
match self {
CellResult::Success { tool_calls, .. } => tool_calls,
_ => panic!("{self:?}"),
diff --git a/platform/js-runtime/tests/integration/repl.rs b/platform/js-runtime/tests/integration/repl.rs
index a0b25c6f6e..d53a60e69e 100644
--- a/platform/js-runtime/tests/integration/repl.rs
+++ b/platform/js-runtime/tests/integration/repl.rs
@@ -19,9 +19,8 @@
use maka_agent_facts::tools::ToolExecutor;
use maka_agent_facts::tools::ToolFuture;
-use maka_js_runtime::{
- CellAbort, CellContext, CellLimits, CellOutput, CellResult, CellStore, repl::Repl,
-};
+use maka_code_runtime::{CellAbort, CellContext, CellLimits, CellOutput, CellResult, CellStore};
+use maka_js_runtime::repl::Repl;
use serde_json::{Value, json};
use std::{
sync::{
@@ -203,7 +202,7 @@ async fn loops_and_unresolved_await_are_bounded_and_do_not_reuse_the_heap() {
assert!(matches!(result, CellResult::Failure { .. }), "{result:?}");
if heap {
assert!(
- matches!(&result,CellResult::Failure {error,..} if error.kind==maka_js_runtime::CellDiagnosticKind::LimitExceeded && error.message.contains("heap")),
+ matches!(&result,CellResult::Failure {error,..} if error.kind==maka_code_runtime::CellDiagnosticKind::LimitExceeded && error.message.contains("heap")),
"heap guard must fire before the wall timeout: {result:?}"
);
}
diff --git a/platform/js-runtime/tests/integration/result_contract.rs b/platform/js-runtime/tests/integration/result_contract.rs
index f288428538..19e1522af7 100644
--- a/platform/js-runtime/tests/integration/result_contract.rs
+++ b/platform/js-runtime/tests/integration/result_contract.rs
@@ -17,7 +17,8 @@
* under the License.
*/
-use maka_js_runtime::{CellAbort, CellDiagnosticKind, CellLimits, CellResult, CodeExecutor};
+use maka_code_runtime::{CellAbort, CellDiagnosticKind, CellLimits, CellResult};
+use maka_js_runtime::CodeExecutor;
use serde_json::json;
use std::sync::Arc;
use tokio_util::sync::CancellationToken;
@@ -85,7 +86,7 @@ async fn complete_source_runs_forty_ordered_effects_and_returns_complete_value()
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn complete_scratch_output_and_notifications_survive_cell_settlement() {
- use maka_js_runtime::{CellContext, CellOutput, CellStore};
+ use maka_code_runtime::{CellContext, CellOutput, CellStore};
let store = CellStore::default();
let context = CellContext::new(store.clone(), vec![]);
let engine = CodeExecutor::new(CellLimits::default()).unwrap();
diff --git a/plugins/agent/engine/Cargo.toml b/plugins/agent/engine/Cargo.toml
index 1691820a6a..1eafca3ed1 100644
--- a/plugins/agent/engine/Cargo.toml
+++ b/plugins/agent/engine/Cargo.toml
@@ -23,6 +23,7 @@ license.workspace = true
publish.workspace = true
[dependencies]
+maka-code-runtime.workspace = true
hex.workspace = true
maka-plugin-core.workspace = true
maka-agent-facts.workspace = true
diff --git a/plugins/agent/engine/src/lib.rs b/plugins/agent/engine/src/lib.rs
index 2afeb3affc..2c9a84ecc5 100644
--- a/plugins/agent/engine/src/lib.rs
+++ b/plugins/agent/engine/src/lib.rs
@@ -212,7 +212,7 @@ struct Inner {
#[derive(Clone, Default)]
struct SessionState {
- code_store: maka_js_runtime::CellStore,
+ code_store: maka_code_runtime::CellStore,
loaded: maka_tools::availability::LoadedTools,
}
diff --git a/plugins/agent/engine/tests/integration/agent_loop.rs b/plugins/agent/engine/tests/integration/agent_loop.rs
index 8bb1075cdf..94fd3788d5 100644
--- a/plugins/agent/engine/tests/integration/agent_loop.rs
+++ b/plugins/agent/engine/tests/integration/agent_loop.rs
@@ -24,8 +24,9 @@ use std::time::Duration;
use maka_agent_engine::{Engine, RunError};
use maka_agent_facts::event::Fact;
use maka_agent_facts::event::TerminalStatus;
+use maka_code_runtime::CellLimits;
use maka_event_log::EventLog;
-use maka_js_runtime::{CellLimits, CodeExecutor};
+use maka_js_runtime::CodeExecutor;
use maka_model::ModelExecutor;
use serde_json::{Value, json};
use tokio::net::TcpListener;
diff --git a/plugins/agent/engine/tests/integration/code_mode.rs b/plugins/agent/engine/tests/integration/code_mode.rs
index 5e95049a33..979416b31b 100644
--- a/plugins/agent/engine/tests/integration/code_mode.rs
+++ b/plugins/agent/engine/tests/integration/code_mode.rs
@@ -29,8 +29,9 @@ use maka_agent_facts::event::Fact;
use maka_agent_facts::event::TerminalStatus;
use maka_agent_facts::event::ToolOutcome;
use maka_agent_facts::tool_call::ToolOrigin;
+use maka_code_runtime::CellLimits;
use maka_event_log::EventLog;
-use maka_js_runtime::{CellLimits, CodeExecutor};
+use maka_js_runtime::CodeExecutor;
use maka_model::ModelExecutor;
use serde_json::{Value, json};
use tokio::net::TcpListener;
diff --git a/plugins/agent/engine/tests/integration/code_mode_lifetime.rs b/plugins/agent/engine/tests/integration/code_mode_lifetime.rs
index dfcd2b42e3..f093cb8362 100644
--- a/plugins/agent/engine/tests/integration/code_mode_lifetime.rs
+++ b/plugins/agent/engine/tests/integration/code_mode_lifetime.rs
@@ -30,8 +30,9 @@ use maka_agent_facts::event::Invocation;
use maka_agent_facts::event::InvocationOutcome;
use maka_agent_facts::event::TerminalStatus;
use maka_agent_facts::event::ToolOutcome;
+use maka_code_runtime::CellLimits;
use maka_event_log::EventLog;
-use maka_js_runtime::{CellLimits, CodeExecutor};
+use maka_js_runtime::CodeExecutor;
use maka_model::{ModelExecutor, ProviderConfig, ProviderKind};
use maka_tools::{
ToolCatalog, ToolDefinition, ToolHandler, ToolMode, ToolNesting, ToolRegistration,
diff --git a/plugins/agent/engine/tests/integration/code_mode_media.rs b/plugins/agent/engine/tests/integration/code_mode_media.rs
index df87c7f995..eca74639c1 100644
--- a/plugins/agent/engine/tests/integration/code_mode_media.rs
+++ b/plugins/agent/engine/tests/integration/code_mode_media.rs
@@ -24,8 +24,9 @@ use maka_agent_facts::event::Fact;
use maka_agent_facts::tools::ToolError;
use maka_agent_facts::tools::ToolExecutor;
use maka_agent_facts::tools::ToolFuture;
+use maka_code_runtime::CellLimits;
use maka_event_log::EventLog;
-use maka_js_runtime::{CellLimits, CodeExecutor};
+use maka_js_runtime::CodeExecutor;
use maka_model::{ModelExecutor, ProviderKind};
use maka_tools::{
ToolCatalog, ToolDefinition, ToolHandler, ToolNesting, ToolRegistration, ToolSemantics,
diff --git a/plugins/agent/engine/tests/integration/handoff.rs b/plugins/agent/engine/tests/integration/handoff.rs
index 46a274a2a7..bab83dbaa8 100644
--- a/plugins/agent/engine/tests/integration/handoff.rs
+++ b/plugins/agent/engine/tests/integration/handoff.rs
@@ -29,8 +29,9 @@ use maka_agent_facts::event::InvocationOutcome;
use maka_agent_facts::event::RuntimeEvent;
use maka_agent_facts::event::TerminalStatus;
use maka_agent_facts::handoff::HandoffIntent;
+use maka_code_runtime::CellLimits;
use maka_event_log::EventLog;
-use maka_js_runtime::{CellLimits, CodeExecutor};
+use maka_js_runtime::CodeExecutor;
use maka_model::ModelExecutor;
use std::{
sync::{
diff --git a/plugins/agent/engine/tests/integration/lifetime.rs b/plugins/agent/engine/tests/integration/lifetime.rs
index e873070f25..2a490cbc6c 100644
--- a/plugins/agent/engine/tests/integration/lifetime.rs
+++ b/plugins/agent/engine/tests/integration/lifetime.rs
@@ -34,8 +34,9 @@ use maka_agent_facts::tool_call::ToolOrigin;
use maka_agent_facts::tool_call::ToolRejection;
use maka_agent_facts::tools::ToolExecutor;
use maka_agent_facts::tools::ToolFuture;
+use maka_code_runtime::CellLimits;
use maka_event_log::EventLog;
-use maka_js_runtime::{CellLimits, CodeExecutor};
+use maka_js_runtime::CodeExecutor;
use maka_model::{ModelExecutor, ProviderConfig, ProviderKind};
use maka_tools::{
ToolCatalog, ToolDefinition, ToolHandler, ToolMode, ToolNesting, ToolRegistration,
diff --git a/plugins/agent/engine/tests/integration/model_interruption.rs b/plugins/agent/engine/tests/integration/model_interruption.rs
index f5112e8de9..7a562a792b 100644
--- a/plugins/agent/engine/tests/integration/model_interruption.rs
+++ b/plugins/agent/engine/tests/integration/model_interruption.rs
@@ -33,8 +33,9 @@ use maka_agent_facts::event::ModelInterruption;
use maka_agent_facts::event::TerminalStatus;
use maka_agent_facts::model::ModelEvent;
use maka_agent_facts::model::error::ModelFailureCause;
+use maka_code_runtime::CellLimits;
use maka_event_log::EventLog;
-use maka_js_runtime::{CellLimits, CodeExecutor};
+use maka_js_runtime::CodeExecutor;
use maka_model::{ModelError, ModelExecutor, ProviderConfig, ProviderKind};
use maka_tools::ToolMode;
use serde_json::json;
diff --git a/plugins/agent/engine/tests/integration/startup_recovery.rs b/plugins/agent/engine/tests/integration/startup_recovery.rs
index 8c8f0a3cb3..06017078b7 100644
--- a/plugins/agent/engine/tests/integration/startup_recovery.rs
+++ b/plugins/agent/engine/tests/integration/startup_recovery.rs
@@ -40,9 +40,10 @@ use maka_agent_facts::model::ModelPart;
use maka_agent_facts::model::ModelStep;
use maka_agent_facts::model::ModelToolCall;
use maka_agent_facts::model::ModelUsage;
+use maka_code_runtime::CellLimits;
use maka_event_log::EventLog;
use maka_event_log::recovery::recover_invocations as recover;
-use maka_js_runtime::{CellLimits, CodeExecutor};
+use maka_js_runtime::CodeExecutor;
use maka_model::{ModelExecutor, ProviderConfig, ProviderKind};
use maka_tools::ToolMode;
use serde_json::json;
diff --git a/plugins/agent/engine/tests/integration/support/context.rs b/plugins/agent/engine/tests/integration/support/context.rs
index e085bf654c..c290ac9ce9 100644
--- a/plugins/agent/engine/tests/integration/support/context.rs
+++ b/plugins/agent/engine/tests/integration/support/context.rs
@@ -24,8 +24,9 @@ use maka_agent_engine::{Engine, RunInput, RunWork};
use maka_agent_facts::event::Invocation;
use maka_agent_facts::execution::ModelBinding;
use maka_agent_facts::execution::ToolMode;
+use maka_code_runtime::CellLimits;
use maka_event_log::EventLog;
-use maka_js_runtime::{CellLimits, CodeExecutor};
+use maka_js_runtime::CodeExecutor;
use maka_model::{ModelExecutor, ProviderConfig, ProviderKind};
use serde_json::json;
use std::{collections::BTreeMap, sync::Arc, time::Duration};
diff --git a/plugins/agent/engine/tests/integration/support/image_projection.rs b/plugins/agent/engine/tests/integration/support/image_projection.rs
index a43b0b7f05..8e5682cf83 100644
--- a/plugins/agent/engine/tests/integration/support/image_projection.rs
+++ b/plugins/agent/engine/tests/integration/support/image_projection.rs
@@ -23,8 +23,9 @@ use maka_agent_facts::artifact::ArtifactKind;
use maka_agent_facts::artifact::ArtifactSource;
use maka_agent_facts::artifact::content_digest;
use maka_agent_facts::event::Invocation;
+use maka_code_runtime::CellLimits;
use maka_event_log::EventLog;
-use maka_js_runtime::{CellLimits, CodeExecutor};
+use maka_js_runtime::CodeExecutor;
use maka_model::{ModelExecutor, ProviderConfig, ProviderKind};
use maka_tools::ToolCatalog;
use serde_json::{Value, json};
diff --git a/plugins/agent/engine/tests/integration/tool_arguments.rs b/plugins/agent/engine/tests/integration/tool_arguments.rs
index 85c47cdaab..72583627c6 100644
--- a/plugins/agent/engine/tests/integration/tool_arguments.rs
+++ b/plugins/agent/engine/tests/integration/tool_arguments.rs
@@ -26,8 +26,9 @@ use maka_agent_facts::event::{Fact, TerminalStatus};
use maka_agent_facts::model::prompt::{AssistantPart, Message, ToolOutput};
use maka_agent_facts::model::{ModelEvent, ToolInput};
use maka_agent_facts::tool_call::ToolRejection;
+use maka_code_runtime::CellLimits;
use maka_event_log::EventLog;
-use maka_js_runtime::{CellLimits, CodeExecutor};
+use maka_js_runtime::CodeExecutor;
use maka_model::ModelExecutor;
use maka_tools::ToolMode;
use serde_json::json;
diff --git a/plugins/agent/native/Cargo.toml b/plugins/agent/native/Cargo.toml
index 9716e36ecd..b1abbc8878 100644
--- a/plugins/agent/native/Cargo.toml
+++ b/plugins/agent/native/Cargo.toml
@@ -23,6 +23,7 @@ license.workspace = true
publish.workspace = true
[dependencies]
+maka-code-runtime.workspace = true
hex.workspace = true
maka-graph.workspace = true
maka-goal.workspace = true
diff --git a/plugins/agent/native/src/owner.rs b/plugins/agent/native/src/owner.rs
index 9bc9bdb02f..0be1a8e2cf 100644
--- a/plugins/agent/native/src/owner.rs
+++ b/plugins/agent/native/src/owner.rs
@@ -271,7 +271,7 @@ impl Owner {
} else {
workspace::open(settings.import_roots.clone(), root.canonical_path())?
};
- let cells = maka_js_runtime::CodeExecutor::new(maka_js_runtime::CellLimits::default())
+ let cells = maka_js_runtime::CodeExecutor::new(maka_code_runtime::CellLimits::default())
.map_err(|_| "agent_executor_unavailable")?;
let workers = TaskTracker::new();
let stop = CancellationToken::new();
diff --git a/plugins/agent/native/src/tools/computer.rs b/plugins/agent/native/src/tools/computer.rs
index 5adbe1ba0d..65d06a2334 100644
--- a/plugins/agent/native/src/tools/computer.rs
+++ b/plugins/agent/native/src/tools/computer.rs
@@ -24,7 +24,7 @@ use maka_agent_facts::{
event::Invocation,
tool_output::ToolContent,
};
-use maka_js_runtime::CellOutput;
+use maka_code_runtime::CellOutput;
use maka_tools::request::{BindingRequest, BoundTool, RequestBinding};
use maka_workspace_api::computer::{ReplState, ResultValue};
use std::collections::BTreeMap;
diff --git a/plugins/agent/tools/Cargo.toml b/plugins/agent/tools/Cargo.toml
index e9db9aae80..365ce124c9 100644
--- a/plugins/agent/tools/Cargo.toml
+++ b/plugins/agent/tools/Cargo.toml
@@ -23,6 +23,7 @@ license.workspace = true
publish.workspace = true
[dependencies]
+maka-code-runtime.workspace = true
maka-agent-facts.workspace = true
futures-util.workspace = true
maka-js-runtime.workspace = true
diff --git a/plugins/agent/tools/src/cell/session.rs b/plugins/agent/tools/src/cell/session.rs
index e6284617c9..cf51f940f6 100644
--- a/plugins/agent/tools/src/cell/session.rs
+++ b/plugins/agent/tools/src/cell/session.rs
@@ -26,7 +26,7 @@ use maka_agent_facts::tool_output::ToolContent;
use maka_agent_facts::tool_output::ToolOutput;
use maka_agent_facts::tool_output::ToolSuccess;
use maka_agent_facts::tools::ToolError;
-use maka_js_runtime::{
+use maka_code_runtime::{
CellAbort, CellContext, CellOutput, CellStore, NotificationGate, ToolMetadata,
};
use serde::Serialize;
diff --git a/plugins/agent/tools/src/dispatch.rs b/plugins/agent/tools/src/dispatch.rs
index 2db4db18a2..3227861c03 100644
--- a/plugins/agent/tools/src/dispatch.rs
+++ b/plugins/agent/tools/src/dispatch.rs
@@ -78,7 +78,7 @@ impl RunTools {
}
}
- pub fn with_store(mut self, store: maka_js_runtime::CellStore) -> Self {
+ pub fn with_store(mut self, store: maka_code_runtime::CellStore) -> Self {
self.code = cell::Cells::new(store);
self
}
diff --git a/plugins/agent/tools/tests/integration/catalog.rs b/plugins/agent/tools/tests/integration/catalog.rs
index c649deca19..bfe2dc734b 100644
--- a/plugins/agent/tools/tests/integration/catalog.rs
+++ b/plugins/agent/tools/tests/integration/catalog.rs
@@ -185,8 +185,9 @@ fn schemas_validate_offline_without_coercion_and_catalog_rejects_ambiguous_autho
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn discovery_loads_complete_schemas_without_running_effects() {
use crate::support::preflight;
+ use maka_code_runtime::CellLimits;
use maka_event_log::EventLog;
- use maka_js_runtime::{CellLimits, CodeExecutor};
+ use maka_js_runtime::CodeExecutor;
use maka_tools::{RunTools, ToolMode};
for oversized in [false, true] {
let directory = tempfile::tempdir().unwrap();
diff --git a/plugins/agent/tools/tests/integration/cells.rs b/plugins/agent/tools/tests/integration/cells.rs
index ba80e951b3..06986b4f99 100644
--- a/plugins/agent/tools/tests/integration/cells.rs
+++ b/plugins/agent/tools/tests/integration/cells.rs
@@ -28,8 +28,9 @@ use maka_agent_facts::model::ModelStep;
use maka_agent_facts::tool_call::ToolOrigin;
use maka_agent_facts::tools::ToolExecutor;
use maka_agent_facts::tools::ToolFuture;
+use maka_code_runtime::CellLimits;
use maka_event_log::EventLog;
-use maka_js_runtime::{CellLimits, CodeExecutor};
+use maka_js_runtime::CodeExecutor;
use maka_tools::{
RunTools, ToolCatalog, ToolDefinition, ToolHandler, ToolMode, ToolNesting, ToolRegistration,
ToolSemantics,
diff --git a/plugins/agent/tools/tests/integration/child_image.rs b/plugins/agent/tools/tests/integration/child_image.rs
index 7663454502..7db146c7cb 100644
--- a/plugins/agent/tools/tests/integration/child_image.rs
+++ b/plugins/agent/tools/tests/integration/child_image.rs
@@ -25,8 +25,9 @@ use maka_agent_facts::event::ToolOutcome;
use maka_agent_facts::tool_output::DurableToolProjection;
use maka_agent_facts::tool_output::ProjectionPart;
use maka_agent_facts::tool_output::ToolSuccess;
+use maka_code_runtime::CellLimits;
use maka_event_log::EventLog;
-use maka_js_runtime::{CellLimits, CodeExecutor};
+use maka_js_runtime::CodeExecutor;
use maka_tools::{
PreparationFuture, PreparedEffect, RunTools, ToolCallContext, ToolCatalog, ToolDefinition,
ToolHandler, ToolMode, ToolNesting, ToolPreparer, ToolRegistration, ToolSemantics,
diff --git a/plugins/agent/tools/tests/integration/commit_faults.rs b/plugins/agent/tools/tests/integration/commit_faults.rs
index 6622c0c0cf..4607fa3724 100644
--- a/plugins/agent/tools/tests/integration/commit_faults.rs
+++ b/plugins/agent/tools/tests/integration/commit_faults.rs
@@ -39,8 +39,9 @@ use maka_agent_facts::tool_call::ToolOrigin;
use maka_agent_facts::tools::ToolError;
use maka_agent_facts::tools::ToolExecutor;
use maka_agent_facts::tools::ToolFuture;
+use maka_code_runtime::CellLimits;
use maka_event_log::EventLog;
-use maka_js_runtime::{CellLimits, CodeExecutor};
+use maka_js_runtime::CodeExecutor;
use maka_tools::{
RunTools, ToolCatalog, ToolDefinition, ToolHandler, ToolMode, ToolNesting, ToolRegistration,
ToolSemantics,
diff --git a/plugins/agent/tools/tests/integration/large_child_output.rs b/plugins/agent/tools/tests/integration/large_child_output.rs
index ed1a20bd02..6d13eaa2fc 100644
--- a/plugins/agent/tools/tests/integration/large_child_output.rs
+++ b/plugins/agent/tools/tests/integration/large_child_output.rs
@@ -23,8 +23,9 @@ use maka_agent_facts::event::Fact;
use maka_agent_facts::event::ToolOutcome;
use maka_agent_facts::tools::ToolExecutor;
use maka_agent_facts::tools::ToolFuture;
+use maka_code_runtime::CellLimits;
use maka_event_log::EventLog;
-use maka_js_runtime::{CellLimits, CodeExecutor};
+use maka_js_runtime::CodeExecutor;
use maka_tools::{
RunTools, ToolCatalog, ToolDefinition, ToolHandler, ToolMode, ToolNesting, ToolRegistration,
ToolSemantics,
diff --git a/plugins/agent/tools/tests/integration/preflight.rs b/plugins/agent/tools/tests/integration/preflight.rs
index 434d01f1d5..256fc50a96 100644
--- a/plugins/agent/tools/tests/integration/preflight.rs
+++ b/plugins/agent/tools/tests/integration/preflight.rs
@@ -24,8 +24,9 @@ use maka_agent_facts::event::ToolOutcome;
use maka_agent_facts::model::ToolInput;
use maka_agent_facts::tool_call::ToolRejection;
use maka_agent_facts::tools::ToolError;
+use maka_code_runtime::CellLimits;
use maka_event_log::EventLog;
-use maka_js_runtime::{CellLimits, CodeExecutor};
+use maka_js_runtime::CodeExecutor;
use maka_tools::{RunTools, ToolMode};
use serde_json::json;
use std::sync::{Arc, atomic::Ordering};
diff --git a/plugins/workspace/workspace-computer/native/Cargo.toml b/plugins/workspace/workspace-computer/native/Cargo.toml
index 24887825e6..3d16eebb48 100644
--- a/plugins/workspace/workspace-computer/native/Cargo.toml
+++ b/plugins/workspace/workspace-computer/native/Cargo.toml
@@ -23,6 +23,7 @@ license.workspace = true
publish.workspace = true
[dependencies]
+maka-code-runtime.workspace = true
hex.workspace = true
maka-agent-facts.workspace = true
maka-agent-api.workspace = true
diff --git a/plugins/workspace/workspace-computer/native/src/evaluate.rs b/plugins/workspace/workspace-computer/native/src/evaluate.rs
index f9a88bc727..4d30bf39c9 100644
--- a/plugins/workspace/workspace-computer/native/src/evaluate.rs
+++ b/plugins/workspace/workspace-computer/native/src/evaluate.rs
@@ -28,7 +28,8 @@ use maka_agent_facts::{
tools::{PreparedEffect, ToolExecutor, ToolFuture, ToolJournal},
};
use maka_capabilities::call::Scope;
-use maka_js_runtime::{CellContext, CellLimits, CellOutput, CellResult, repl::Repl};
+use maka_code_runtime::{CellContext, CellLimits, CellOutput, CellResult};
+use maka_js_runtime::repl::Repl;
use std::time::Duration;
use uuid::Uuid;
@@ -134,7 +135,7 @@ impl Computer {
cancellation.cancel();
let settled = result.await;
match settled {
- Err(maka_js_runtime::CellAbort::Tool(error)) if !matches!(error, ToolError::Failed(_)) => return Err(partial(error, &context, runtime.is_closed(), language)),
+ Err(maka_code_runtime::CellAbort::Tool(error)) if !matches!(error, ToolError::Failed(_)) => return Err(partial(error, &context, runtime.is_closed(), language)),
_ => return Err(partial(stopped.err().unwrap_or_else(|| failed("Computer permission monitor closed")), &context, runtime.is_closed(), language)),
}
},
@@ -152,7 +153,7 @@ impl Computer {
language,
));
}
- Err(maka_js_runtime::CellAbort::Tool(error)) => {
+ Err(maka_code_runtime::CellAbort::Tool(error)) => {
return Err(partial(error, &context, runtime.is_closed(), language));
}
Err(error) => {
diff --git a/products/maka/cli/Cargo.toml b/products/maka/cli/Cargo.toml
index ec3ebe5f2c..409ef6b68b 100644
--- a/products/maka/cli/Cargo.toml
+++ b/products/maka/cli/Cargo.toml
@@ -43,6 +43,7 @@ name = "terminal_real_host"
path = "../terminal-shell/tests/real_host.rs"
[dependencies]
+maka-code-runtime.workspace = true
hex.workspace = true
maka-agent-facts.workspace = true
maka-agent-ports.workspace = true
diff --git a/products/maka/cli/src/code.rs b/products/maka/cli/src/code.rs
index 242fc32554..c1e5157105 100644
--- a/products/maka/cli/src/code.rs
+++ b/products/maka/cli/src/code.rs
@@ -36,12 +36,12 @@ use maka_agent_facts::tools::JournaledTools;
use maka_agent_facts::tools::ToolError;
use maka_agent_facts::tools::ToolExecutor;
use maka_agent_facts::tools::ToolFuture;
+use maka_code_runtime::{
+ CellAbort, CellContext, CellDiagnosticKind, CellLimits, CellResult, CellStore, ToolMetadata,
+};
use maka_event_log::EventLog;
use maka_fs_tools::{MutationExecutor, ReadExecutor, ReadScope, WriteCoordinator, WriteScope};
-use maka_js_runtime::{
- CellAbort, CellContext, CellDiagnosticKind, CellLimits, CellResult, CellStore, CodeExecutor,
- ToolMetadata,
-};
+use maka_js_runtime::CodeExecutor;
use maka_sandbox::{
Sandbox,
filesystem::{Access, Rule},
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org