feat: integrate pi rust lab runtime

This commit is contained in:
Agent Board
2026-07-10 10:54:34 +08:00
parent c8472bb898
commit 896c94b696
73 changed files with 19852 additions and 1152 deletions
+17 -6
View File
@@ -12,6 +12,7 @@ const path = require("node:path");
const BASE = process.env.MNOTE_PI_LAB_BASE || "http://127.0.0.1:3000";
const AUTH = process.env.MNOTE_PI_LAB_AUTH || "Bearer pi-lab-smoke";
const ROOT = process.env.MNOTE_PI_LAB_SMOKE_ROOT || fs.mkdtempSync(path.join(os.tmpdir(), "mnote-pi-lab-"));
const DIRECT_TOOL_CALL_APPROVAL = process.env.MNOTE_PI_LAB_DIRECT_TOOL_APPROVAL === "1";
function assert(condition, message) {
if (!condition) throw new Error(message);
@@ -111,7 +112,8 @@ async function main() {
assert(denied.status === 200, `deny read returned ${denied.status}`);
assert(denied.body.ok === false, "out-of-root read should be denied");
assert(denied.body.receipt, "denied read should still write receipt");
console.log(" ✅ out-of-root read denied with receipt");
assert(denied.body.approvalRequired === true, "direct local file read should require approval before path checks");
console.log(" ✅ out-of-root read blocked by ask policy with receipt");
const patch = await fetchJson(`${BASE}/api/page-ai/pi/tool-call`, {
method: "POST",
@@ -125,11 +127,20 @@ async function main() {
},
}),
});
assert(patch.status === 200 && patch.body.ok === true, "local file patch failed");
assert(patch.body.result.polling === false, "patch must not request polling");
assert(String(patch.body.result.refresh || "").includes("watcher"), "patch must declare watcher refresh");
assert(fs.readFileSync(pageFile, "utf8").includes("Patched body"), "patched file content mismatch");
console.log(" ✅ local file patch + watcher refresh metadata");
if (DIRECT_TOOL_CALL_APPROVAL) {
assert(patch.status === 200 && patch.body.ok === true, "local file patch failed");
assert(patch.body.result.polling === false, "patch must not request polling");
assert(String(patch.body.result.refresh || "").includes("watcher"), "patch must declare watcher refresh");
assert(fs.readFileSync(pageFile, "utf8").includes("Patched body"), "patched file content mismatch");
console.log(" ✅ local file patch + watcher refresh metadata");
} else {
assert(patch.status === 200, `patch returned ${patch.status}`);
assert(patch.body.ok === false, "direct local file patch should require UI/bridge approval");
assert(patch.body.approvalRequired === true, "patch should expose approvalRequired");
assert(String(patch.body.result?.code || "") === "page_ai_pi_lab_tool_approval_required", "patch should be blocked by ask policy");
assert(fs.readFileSync(pageFile, "utf8").includes("Original body"), "unapproved patch must not modify file");
console.log(" ✅ direct local file patch blocked by ask policy");
}
const rag = await fetchJson(`${BASE}/api/page-ai/pi/tool-call`, {
method: "POST",