feat(foreign): structured invoke, presets, probe and config
F0/F1: safe execution core (exec gate, bounded IO, process-group timeout), structured invoke records, run options, 15 language presets, register/unset/probe/config, view stderr/exit/ms, and node/bash gold tests.
This commit is contained in:
1 parent
c21a28c3bc
commit
e32ff8f6b3
21 files changed
+2301
-282
No files matched your search
+11
-2
@@ -958,13 +958,22 @@ fn debug_js() -> &'static str {
|
||||
})
|
||||
.then(function (r) { return r.json(); })
|
||||
.then(function (data) {
|
||||
var parts = [];
|
||||
if (data.stdout) parts.push(data.stdout);
|
||||
if (data.stderr) parts.push("[stderr]\n" + data.stderr);
|
||||
if (data.error) parts.push(data.error);
|
||||
var meta = [];
|
||||
if (typeof data.code === "number") meta.push("exit " + data.code);
|
||||
if (typeof data.ms === "number") meta.push(data.ms + "ms");
|
||||
if (data.timed_out) meta.push("timed out");
|
||||
if (data.truncated) meta.push("truncated");
|
||||
if (meta.length) parts.push("— " + meta.join(" · "));
|
||||
if (data.ok) {
|
||||
out.classList.remove("err");
|
||||
out.textContent = data.stdout === "" ? "(no stdout)" : data.stdout;
|
||||
} else {
|
||||
out.classList.add("err");
|
||||
out.textContent = data.error || "foreign run failed";
|
||||
}
|
||||
out.textContent = parts.length ? parts.join("\n\n") : "(no output)";
|
||||
})
|
||||
.catch(function (e) {
|
||||
out.classList.add("err");
|
||||
|
||||
+11
-2
@@ -1625,13 +1625,22 @@ pub fn layout(title: &str, nav: &str, main: &str) -> String {
|
||||
}})
|
||||
.then(function (r) {{ return r.json(); }})
|
||||
.then(function (data) {{
|
||||
var parts = [];
|
||||
if (data.stdout) parts.push(data.stdout);
|
||||
if (data.stderr) parts.push("[stderr]\n" + data.stderr);
|
||||
if (data.error) parts.push(data.error);
|
||||
var meta = [];
|
||||
if (typeof data.code === "number") meta.push("exit " + data.code);
|
||||
if (typeof data.ms === "number") meta.push(data.ms + "ms");
|
||||
if (data.timed_out) meta.push("timed out");
|
||||
if (data.truncated) meta.push("truncated");
|
||||
if (meta.length) parts.push("— " + meta.join(" · "));
|
||||
if (data.ok) {{
|
||||
out.classList.remove("err");
|
||||
out.textContent = data.stdout === "" ? "(no stdout)" : data.stdout;
|
||||
}} else {{
|
||||
out.classList.add("err");
|
||||
out.textContent = data.error || "foreign run failed";
|
||||
}}
|
||||
out.textContent = parts.length ? parts.join("\n\n") : "(no output)";
|
||||
}})
|
||||
.catch(function (e) {{
|
||||
out.classList.add("err");
|
||||
|
||||
+9
-2
@@ -595,6 +595,8 @@ fn api_foreign_run(root: &ViewRoot, mut request: Request) -> Result<()> {
|
||||
.and_then(|x| x.as_str())
|
||||
.unwrap_or("python");
|
||||
let source = v.get("source").and_then(|x| x.as_str()).unwrap_or("");
|
||||
let stdin = v.get("stdin").and_then(|x| x.as_str());
|
||||
let timeout = v.get("timeout").and_then(|x| x.as_f64());
|
||||
let cmd = v
|
||||
.get("cmd")
|
||||
.and_then(|x| x.as_str())
|
||||
@@ -603,13 +605,18 @@ fn api_foreign_run(root: &ViewRoot, mut request: Request) -> Result<()> {
|
||||
let json = if source.is_empty() {
|
||||
serde_json::json!({ "ok": false, "error": "missing source" }).to_string()
|
||||
} else {
|
||||
match crate::host::foreign::run_with_cmd_override(
|
||||
match crate::host::foreign::invoke_for_view(
|
||||
&root.root,
|
||||
lang,
|
||||
source,
|
||||
cmd,
|
||||
stdin,
|
||||
timeout,
|
||||
) {
|
||||
Ok(stdout) => serde_json::json!({ "ok": true, "stdout": stdout }).to_string(),
|
||||
Ok(value) => match crate::host::json::value_to_json(&value) {
|
||||
Ok(j) => j.to_string(),
|
||||
Err(e) => serde_json::json!({ "ok": false, "error": e }).to_string(),
|
||||
},
|
||||
Err(error) => serde_json::json!({ "ok": false, "error": error }).to_string(),
|
||||
}
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user