feat(host,runtime,cli): explicit plugin invocation from documents
Blueprint section 10 / P6: exports of an explicitly trusted plugin are callable from a `.mq.md` file through a bound namespace. - host: StdHost::load_plugin requires an explicit trust decision and a granted plugin capability, loads the native artifact through the ABI v1 loader with no capability handler (all plugin host-capability requests denied), and dispatches HostOp::PluginInvoke through the typed wire request/response. In-process native code is documented as sharing the host address space; no isolated worker transport exists in this build. - runtime: a qualified call whose base is not a local value, import alias or builtin namespace is routed to the plugin namespace; plugin calls take named arguments only and plugin values become Marqdo values (Unit when absent). - cli: run/call gain `--plugin <path>`, `--trust-native-plugin` and reuse `--allow-plugin <package>`; missing trust/grant/loaded namespace surface as structured errors. - frontend: member-call bases are namespaces (builtin/import/plugin), never inferred parameters, so `solver.add(...)` does not invent a parameter.
This commit is contained in:
1 parent
6f04c17f7a
commit
7fbd5e9ec1
7 files changed
+221
-12
No files matched your search
@@ -36,6 +36,10 @@ pub struct SandboxSettings {
|
||||
pub max_output: Option<usize>,
|
||||
/// Wall-clock timeout in seconds.
|
||||
pub timeout: Option<u64>,
|
||||
/// Explicitly trusted plugin manifests to load.
|
||||
pub plugins: Vec<PathBuf>,
|
||||
/// Explicit trust decision for in-process native plugin loading.
|
||||
pub trust_native_plugin: bool,
|
||||
}
|
||||
|
||||
impl SandboxSettings {
|
||||
@@ -497,6 +501,18 @@ pub fn execute(
|
||||
if let Some(timeout) = settings.timeout {
|
||||
host.budget.deadline = Some(Instant::now() + Duration::from_secs(timeout));
|
||||
}
|
||||
for plugin_path in &settings.plugins {
|
||||
if let Err(message) =
|
||||
load_plugin_into_host(&mut host, plugin_path, settings.trust_native_plugin)
|
||||
{
|
||||
if json {
|
||||
output::print_json(&json!({"success": false, "error": message}));
|
||||
} else {
|
||||
eprintln!("error: {message}");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
let function_name = function.unwrap_or("main").to_string();
|
||||
let entry_module = &project.program.modules[&project.entry];
|
||||
if entry_module.function(&function_name).is_none() {
|
||||
@@ -566,6 +582,31 @@ pub fn execute(
|
||||
}
|
||||
}
|
||||
|
||||
fn load_plugin_into_host(host: &mut StdHost, path: &Path, trusted: bool) -> Result<String, String> {
|
||||
let manifest_path = if path.is_dir() {
|
||||
path.join("plugin.yaml")
|
||||
} else {
|
||||
path.to_path_buf()
|
||||
};
|
||||
let base_dir = manifest_path
|
||||
.parent()
|
||||
.map(|parent| parent.to_path_buf())
|
||||
.unwrap_or_else(|| PathBuf::from("."));
|
||||
let manifest = marqdo_plugin_abi::PluginManifest::load(&manifest_path)
|
||||
.map_err(|error| format!("{}: {}", error.code, error.message))?;
|
||||
manifest
|
||||
.validate()
|
||||
.map_err(|error| format!("{}: {}", error.code, error.message))?;
|
||||
if !trusted {
|
||||
return Err(format!(
|
||||
"loading `{}` in-process requires --trust-native-plugin: no isolated worker transport is implemented in this build",
|
||||
manifest.plugin.name
|
||||
));
|
||||
}
|
||||
host.load_plugin(&manifest, &base_dir, trusted)
|
||||
.map_err(|error| format!("{}: {}", error.code(), error.message))
|
||||
}
|
||||
|
||||
fn runtime_error_json(error: &RuntimeError, project: &LoadedProject) -> serde_json::Value {
|
||||
let entry = project.entry_file();
|
||||
let span = error.span.map(|span| {
|
||||
@@ -968,7 +1009,10 @@ pub fn add(
|
||||
}));
|
||||
} else {
|
||||
println!("added dependency `{name}` to {}", manifest_path.display());
|
||||
println!("run `marqdo lock` to pin it in {}", marqdo_package::LOCK_FILE);
|
||||
println!(
|
||||
"run `marqdo lock` to pin it in {}",
|
||||
marqdo_package::LOCK_FILE
|
||||
);
|
||||
}
|
||||
0
|
||||
}
|
||||
|
||||
@@ -86,6 +86,12 @@ struct SandboxArgs {
|
||||
/// Wall-clock timeout in seconds.
|
||||
#[arg(long)]
|
||||
timeout: Option<u64>,
|
||||
/// Explicitly trusted plugin manifest/directory to load (repeatable).
|
||||
#[arg(long = "plugin", value_name = "PATH")]
|
||||
plugin: Vec<PathBuf>,
|
||||
/// Explicitly trust in-process native plugin loading (unsafe by nature).
|
||||
#[arg(long = "trust-native-plugin")]
|
||||
trust_native_plugin: bool,
|
||||
}
|
||||
|
||||
impl SandboxArgs {
|
||||
@@ -100,6 +106,8 @@ impl SandboxArgs {
|
||||
stack: self.stack,
|
||||
max_output: self.max_output,
|
||||
timeout: self.timeout,
|
||||
plugins: self.plugin.clone(),
|
||||
trust_native_plugin: self.trust_native_plugin,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user