Skip to content

Commit ba18894

Browse files
committed
fix(execution): resolve adapter entrypoint symlink for module-mode detection
Agent ACP adapters are launched via an extensionless /opt/agentos/bin/<cmd> symlink into the packed package's node_modules/<name>/<entry>. host_entrypoint_uses_module_mode matched on the (missing) extension and fell through to CommonJS, so ESM adapters crashed at startup with 'Cannot use import statement outside a module'. Canonicalize the entrypoint before the extension + nearest-package.json check so it resolves to the real file (whose package.json keeps "type":"module") and runs in ESM mode.
1 parent 5367209 commit ba18894

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

crates/execution/src/javascript.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2628,9 +2628,15 @@ fn build_v8_user_code(entrypoint: &str, env: &BTreeMap<String, String>) -> Strin
26282628
}
26292629

26302630
fn host_entrypoint_uses_module_mode(entrypoint: &Path) -> bool {
2631-
match entrypoint.extension().and_then(|ext| ext.to_str()) {
2631+
// Agent adapters are launched via an extensionless `/opt/agentos/bin/<cmd>`
2632+
// symlink into the packed package's `node_modules/<name>/<entry>`. Resolve it
2633+
// to the real file so the extension check and the nearest-`package.json` walk
2634+
// reflect the package (which carries `"type": "module"`), not the symlink farm
2635+
// (which has neither an extension nor a package.json).
2636+
let resolved = fs::canonicalize(entrypoint).unwrap_or_else(|_| entrypoint.to_path_buf());
2637+
match resolved.extension().and_then(|ext| ext.to_str()) {
26322638
Some("mjs" | "mts") => true,
2633-
Some("js") => nearest_package_json_type(entrypoint).as_deref() == Some("module"),
2639+
Some("js") => nearest_package_json_type(&resolved).as_deref() == Some("module"),
26342640
_ => false,
26352641
}
26362642
}

0 commit comments

Comments
 (0)