bazilion 0.23.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -11
- package/dist/browser-keychain.js +83 -0
- package/dist/browser-keychain.js.map +1 -0
- package/dist/cli-main.js +81 -33
- package/dist/cli-main.js.map +1 -1
- package/dist/daemon-main.js +15174 -7372
- package/dist/daemon-main.js.map +1 -1
- package/dist/migrations/0001_init.sql +6 -4
- package/dist/native-darwin-entry.js +692 -0
- package/dist/native-darwin-entry.js.map +1 -0
- package/dist/native-linux-entry.js +60 -0
- package/dist/native-linux-entry.js.map +1 -0
- package/dist/runtime-version.js +2 -2
- package/dist/runtime-version.js.map +1 -1
- package/dist/web/client/assets/{AgentTabs-ZozvE4RV.js → AgentTabs-kEd-oDRM.js} +1 -1
- package/dist/web/client/assets/ChatPane-DhvlzNPJ.js +76 -0
- package/dist/web/client/assets/{ConfigPage-D_3AsSG4.js → ConfigPage-CMKsWDjh.js} +1 -1
- package/dist/web/client/assets/{ConfirmDialog-CH2zTXuo.js → ConfirmDialog-DpAzoNG8.js} +1 -1
- package/dist/web/client/assets/{FieldRow-CcrDV3An.js → FieldRow-OQ-Ezw5t.js} +1 -1
- package/dist/web/client/assets/{ProductionTeamPolicyEditor-DNJsrcW8.js → ProductionTeamPolicyEditor-DhT-Q13a.js} +1 -1
- package/dist/web/client/assets/{ProfileCommunicationEditor-B2SthMNH.js → ProfileCommunicationEditor-CnQIp4e6.js} +1 -1
- package/dist/web/client/assets/{RecoveryState-DlaJiGZs.js → RecoveryState-B4Rne9N_.js} +1 -1
- package/dist/web/client/assets/{ResultCard-CF7a0iFy.js → ResultCard-BxAlMky1.js} +1 -1
- package/dist/web/client/assets/{ResultSourceConversation-X5SuheW6.js → ResultSourceConversation-BzIw43-r.js} +1 -1
- package/dist/web/client/assets/{SectionTabs-CCHDsNpe.js → SectionTabs-D3M6F_HR.js} +1 -1
- package/dist/web/client/assets/{TeamTabs-BplbR2LB.js → TeamTabs-BZbg-UFx.js} +1 -1
- package/dist/web/client/assets/{TemplatesTabs-DsnlhO7j.js → TemplatesTabs-D8geEOte.js} +1 -1
- package/dist/web/client/assets/{UnsavedChangesGuard-BFGfvKOY.js → UnsavedChangesGuard-CPQe9VLw.js} +1 -1
- package/dist/web/client/assets/{_id-HgkOZjnh.js → _id-1RIodFdi.js} +1 -1
- package/dist/web/client/assets/_id-BV3w2kDj.js +1 -0
- package/dist/web/client/assets/{_id-eKsjDym9.js → _id-C9zxKqvQ.js} +1 -1
- package/dist/web/client/assets/{_id-CHE9wjEm.js → _id-CLG_POnZ.js} +1 -1
- package/dist/web/client/assets/{_id-C75PSTfh.js → _id-Cha845UH.js} +1 -1
- package/dist/web/client/assets/{_id-CM4HcwqG.js → _id-DssxcwBl.js} +1 -1
- package/dist/web/client/assets/{_id-I4COPqTO.js → _id-IDHR-MEm.js} +1 -1
- package/dist/web/client/assets/{_id-W8yP8QHB.js → _id-SGs5zOcT.js} +1 -1
- package/dist/web/client/assets/{activity-BCYUctkB.js → activity-0srO4qbd.js} +1 -1
- package/dist/web/client/assets/{activity-jvvmbNos.js → activity-DxQGr6eP.js} +1 -1
- package/dist/web/client/assets/{agents-C6mJyZUx.js → agents-CVTYoXKu.js} +1 -1
- package/dist/web/client/assets/{agents-CvLzI7m_.js → agents-DPTu6Sm_.js} +1 -1
- package/dist/web/client/assets/{agents-CpusMfSn.js → agents-nHiIbumu.js} +1 -1
- package/dist/web/client/assets/{approvals-C2R4qUbS.js → approvals-Di_Bux_Q.js} +1 -1
- package/dist/web/client/assets/{approvals-Cd2np6JM.js → approvals-ScNrQg7q.js} +1 -1
- package/dist/web/client/assets/{attention-Q_sRUULz.js → attention-BF-Llt9z.js} +1 -1
- package/dist/web/client/assets/{attention-CFwT25yC.js → attention-D7xB17sN.js} +1 -1
- package/dist/web/client/assets/chevron-right-CJ2wat15.js +1 -0
- package/dist/web/client/assets/config-BOuIcP1T.js +3 -0
- package/dist/web/client/assets/{context-Cjb1-4nB.js → context-wo9lNjHx.js} +1 -1
- package/dist/web/client/assets/{inbox-QoBXXR8s.js → inbox-CNLmz0Jp.js} +1 -1
- package/dist/web/client/assets/{inbox-CX0alCy_.js → inbox-De6HOll3.js} +1 -1
- package/dist/web/client/assets/{index-Du-fy_6d.js → index-CjI7_vB3.js} +2 -2
- package/dist/web/client/assets/{learning-C1n4NTM1.js → learning-591SFAKg.js} +1 -1
- package/dist/web/client/assets/{learning-VwXsV_lU.js → learning-D6bO0NeB.js} +1 -1
- package/dist/web/client/assets/{login-CqnOW-JM.js → login-Q7uP-v0M.js} +1 -1
- package/dist/web/client/assets/mcp-BGy64VOv.js +1 -0
- package/dist/web/client/assets/{mcp-B02-ofb9.js → mcp-DSCjhc5I.js} +1 -1
- package/dist/web/client/assets/{members-CEkRCNto.js → members-CBVor-P4.js} +1 -1
- package/dist/web/client/assets/{members-va8WzU_O.js → members-CCcecjC3.js} +1 -1
- package/dist/web/client/assets/{memory-DiGxdDEp.js → memory-CSE8EQ48.js} +1 -1
- package/dist/web/client/assets/{memory-DejWBeGz.js → memory-DgGz0wh4.js} +1 -1
- package/dist/web/client/assets/{policy-DgIcquCb.js → policy-6j-NQvBj.js} +1 -1
- package/dist/web/client/assets/{policy-CEiX5AXJ.js → policy-Do0TvNWc.js} +1 -1
- package/dist/web/client/assets/{results-DsK9IvTu.js → results-CCQGn0dE.js} +1 -1
- package/dist/web/client/assets/{results-BBBBjgd1.js → results-Cx6_ChIY.js} +1 -1
- package/dist/web/client/assets/{review-X2RHaLwW.js → review-CyS5b0fz.js} +1 -1
- package/dist/web/client/assets/{review-BGbU_GAW.js → review-qG-2gqEp.js} +1 -1
- package/dist/web/client/assets/{routes-CNz-oflx.js → routes-DRic0xNy.js} +1 -1
- package/dist/web/client/assets/{services-D7TEP2JX.js → services-B_7lf-mx.js} +1 -1
- package/dist/web/client/assets/{services-dcsfVgOY.js → services-ByBA_yA-.js} +1 -1
- package/dist/web/client/assets/{skills-NDtAsHyl.js → skills--lnDzPWe.js} +1 -1
- package/dist/web/client/assets/{skills-CnI7SkP2.js → skills-C70btgIg.js} +1 -1
- package/dist/web/client/assets/{styles-CjCML-UX.css → styles-e_ADuRbs.css} +1 -1
- package/dist/web/client/assets/{teams-DErd3Weq.js → teams-BL-Fr2xF.js} +1 -1
- package/dist/web/client/assets/{teams-Dyll0JrQ.js → teams-BeoxArzy.js} +1 -1
- package/dist/web/client/assets/{teams-DETtQypB.js → teams-C4mb790r.js} +1 -1
- package/dist/web/client/assets/{teams-DPgdJBly.js → teams-DHStw3OS.js} +1 -1
- package/dist/web/client/assets/{telegram-CAGu-kLc.js → telegram-BIMiebJl.js} +1 -1
- package/dist/web/client/assets/{templates-CgOQU6RS.js → templates-CzHXXiA_.js} +1 -1
- package/dist/web/client/assets/{tokens-BYVE1y6V.js → tokens-B9ehOc1o.js} +1 -1
- package/dist/web/client/assets/{tokens-CvjME9aI.js → tokens-DhaMzFWK.js} +1 -1
- package/dist/web/client/assets/{triggers-Dmli752j.js → triggers--xMpHFW7.js} +1 -1
- package/dist/web/client/assets/{triggers-BeZ7olEG.js → triggers-DLzZu8bB.js} +1 -1
- package/dist/web/client/assets/verifications-FzypGVwW.js +2 -0
- package/dist/web/client/assets/{verifications-CnLEVFoZ.js → verifications-fR9W-adv.js} +1 -1
- package/dist/web/client/assets/{welcome-BF3pg5U5.js → welcome-pjZD7pq4.js} +1 -1
- package/dist/web/client/assets/{x-B-Fk6DuU.js → x-CZxV4X-6.js} +1 -1
- package/dist/web/server/assets/{ChatPane-DsDa1E0a.js → ChatPane-CeDUEjmn.js} +11 -2
- package/dist/web/server/assets/{ResultSourceConversation-NKiRGO6_.js → ResultSourceConversation-xn4EKjaP.js} +1 -1
- package/dist/web/server/assets/{_id-CrOJD02W.js → _id-CGMvV1p5.js} +3 -3
- package/dist/web/server/assets/{_id-BXOT74Jd.js → _id-DhheAcWL.js} +149 -14
- package/dist/web/server/assets/{_id-C1TCGcHL.js → _id-t8AepTB2.js} +1 -1
- package/dist/web/server/assets/{_id-BS4MnPa3.js → _id-ujm4R5OF.js} +1 -1
- package/dist/web/server/assets/{_tanstack-start-manifest_v-CPSd5WEy.js → _tanstack-start-manifest_v-CXwNJhX2.js} +134 -134
- package/dist/web/server/assets/{config-DX3c4Co0.js → config-0_5yhRKg.js} +129 -22
- package/dist/web/server/assets/{config-DTI4EPbU.js → config-CpHD812q.js} +6 -1
- package/dist/web/server/assets/{config-DM2DIzMT.js → config-VsmvCulS.js} +1 -1
- package/dist/web/server/assets/{mcp-CLWr5_0I.js → mcp-BEdnl_TT.js} +1 -1
- package/dist/web/server/assets/{mcp-DmzP8n2G.js → mcp-Dhryb75M.js} +2 -2
- package/dist/web/server/assets/{results-BYU6Bfzt.js → results-CkNoVDrY.js} +2 -2
- package/dist/web/server/assets/{results-Cr1B3XoP.js → results-DSGwi3vj.js} +1 -1
- package/dist/web/server/assets/{router-B2R22qdF.js → router-BFqyjkYu.js} +8 -8
- package/dist/web/server/assets/{routes-kSjMHwrg.js → routes-BfEa101d.js} +1 -1
- package/dist/web/server/assets/{routes-BGMHt0b0.js → routes-pUMIGzyy.js} +2 -2
- package/dist/web/server/assets/{verifications-EIw3Xh61.js → verifications-DvOyI3Mr.js} +1 -1
- package/dist/web/server/assets/{verifications-BVR0OK7x.js → verifications-YrEdiZmk.js} +8 -5
- package/dist/web/server/server.js +3 -3
- package/dist/worker.js +820 -205
- package/dist/worker.js.map +1 -1
- package/package.json +10 -8
- package/dist/web/client/assets/ChatPane-nv9xOKnM.js +0 -76
- package/dist/web/client/assets/_id-fxbpjlEa.js +0 -1
- package/dist/web/client/assets/chevron-right-BfSr7R_L.js +0 -1
- package/dist/web/client/assets/config-B7UhhXW6.js +0 -3
- package/dist/web/client/assets/mcp-DMpVmmfU.js +0 -1
- package/dist/web/client/assets/verifications-qQz5-X-o.js +0 -2
package/dist/worker.js
CHANGED
|
@@ -650,21 +650,21 @@ var SERVICES = [
|
|
|
650
650
|
displayName: "Agent Shell Security",
|
|
651
651
|
category: "service",
|
|
652
652
|
team: "Agent Runtime",
|
|
653
|
-
hint: "
|
|
653
|
+
hint: "Trusted host execution is unisolated. Native and Docker isolation are Linux-only; macOS native isolation is deferred and protected Mac work is unavailable.",
|
|
654
654
|
fields: [
|
|
655
655
|
{
|
|
656
656
|
envVar: "BAZILION_BASH_APPROVAL",
|
|
657
657
|
kind: "config",
|
|
658
658
|
label: "Dangerous-command approval",
|
|
659
659
|
placeholder: "off",
|
|
660
|
-
description: "
|
|
660
|
+
description: "Legacy host/Docker: off or dangerous (classified commands require per-call approval). Native always uses the dangerous-command gate; unattended turns auto-deny, interactive turns may approve once."
|
|
661
661
|
},
|
|
662
662
|
{
|
|
663
663
|
envVar: "BAZILION_BASH_SANDBOX",
|
|
664
664
|
kind: "config",
|
|
665
665
|
label: "Sandbox mode",
|
|
666
666
|
placeholder: "off",
|
|
667
|
-
description: "Use off
|
|
667
|
+
description: "Use off for trusted unisolated host tools. Linux can select native (Bubblewrap/seccomp) or transitional docker. Native macOS isolation is deferred and unqualified; macOS supports only off. Protected work never falls back to host execution."
|
|
668
668
|
},
|
|
669
669
|
{
|
|
670
670
|
envVar: "BAZILION_BASH_SANDBOX_IMAGE",
|
|
@@ -678,7 +678,7 @@ var SERVICES = [
|
|
|
678
678
|
kind: "config",
|
|
679
679
|
label: "Extra environment allowlist",
|
|
680
680
|
placeholder: "MY_SAFE_VARIABLE,ANOTHER_SAFE_VARIABLE",
|
|
681
|
-
description: "
|
|
681
|
+
description: "Docker-only comma-separated variable names copied into the container. Native execution ignores this allowlist and accepts only the closed Team environment flags; provider credentials never enter native command environments."
|
|
682
682
|
},
|
|
683
683
|
{
|
|
684
684
|
envVar: "BAZILION_AGENT_LOOP_MAX_HOPS",
|
|
@@ -1102,8 +1102,8 @@ function ensureSafeParentDirectories(root, path) {
|
|
|
1102
1102
|
assertContained(root, parent);
|
|
1103
1103
|
const rel = relative(root, parent);
|
|
1104
1104
|
let current = root;
|
|
1105
|
-
for (const
|
|
1106
|
-
current = join12(current,
|
|
1105
|
+
for (const component2 of rel.split(sep2).filter(Boolean)) {
|
|
1106
|
+
current = join12(current, component2);
|
|
1107
1107
|
let info = lstatIfPresent(current);
|
|
1108
1108
|
if (!info) {
|
|
1109
1109
|
mkdirSync4(current);
|
|
@@ -1427,8 +1427,8 @@ function extractAssistantToolCalls(m) {
|
|
|
1427
1427
|
}
|
|
1428
1428
|
return out;
|
|
1429
1429
|
}
|
|
1430
|
-
function extractToolResultText(
|
|
1431
|
-
const r =
|
|
1430
|
+
function extractToolResultText(result2) {
|
|
1431
|
+
const r = result2;
|
|
1432
1432
|
if (!r?.content) return "";
|
|
1433
1433
|
let out = "";
|
|
1434
1434
|
for (const block of r.content) {
|
|
@@ -1436,8 +1436,8 @@ function extractToolResultText(result) {
|
|
|
1436
1436
|
}
|
|
1437
1437
|
return out;
|
|
1438
1438
|
}
|
|
1439
|
-
function extractToolResultImages(
|
|
1440
|
-
const r =
|
|
1439
|
+
function extractToolResultImages(result2) {
|
|
1440
|
+
const r = result2;
|
|
1441
1441
|
if (!r?.content) return [];
|
|
1442
1442
|
const out = [];
|
|
1443
1443
|
for (const block of r.content) {
|
|
@@ -1757,10 +1757,16 @@ import {
|
|
|
1757
1757
|
lstatSync as lstatSync3,
|
|
1758
1758
|
opendirSync,
|
|
1759
1759
|
openSync as openSync3,
|
|
1760
|
-
|
|
1760
|
+
readlinkSync,
|
|
1761
1761
|
realpathSync as realpathSync4
|
|
1762
1762
|
} from "fs";
|
|
1763
1763
|
import { isAbsolute as isAbsolute2, join as join14 } from "path";
|
|
1764
|
+
import {
|
|
1765
|
+
assertDirectoryIdentitySync,
|
|
1766
|
+
openRootFileSync,
|
|
1767
|
+
readFileDescriptorBoundedSync
|
|
1768
|
+
} from "@openclaw/fs-safe/advanced";
|
|
1769
|
+
import { FsSafeError } from "@openclaw/fs-safe/errors";
|
|
1764
1770
|
var hash = (value) => createHash7("sha256").update(value).digest("hex");
|
|
1765
1771
|
var ContextReadError = class extends Error {
|
|
1766
1772
|
code;
|
|
@@ -1773,7 +1779,7 @@ function identity(stat2) {
|
|
|
1773
1779
|
return `${stat2.dev}:${stat2.ino}`;
|
|
1774
1780
|
}
|
|
1775
1781
|
function stamp(stat2) {
|
|
1776
|
-
return `${identity(stat2)}:${stat2.size}:${stat2.
|
|
1782
|
+
return `${identity(stat2)}:${stat2.size}:${stat2.mtimeNs}:${stat2.ctimeNs}`;
|
|
1777
1783
|
}
|
|
1778
1784
|
function relativeParts(target) {
|
|
1779
1785
|
if (target.length > 4096 || isAbsolute2(target) || [...target].some(
|
|
@@ -1784,31 +1790,103 @@ function relativeParts(target) {
|
|
|
1784
1790
|
if (parts.length > 17) throw new ContextReadError("depth_limit");
|
|
1785
1791
|
return parts;
|
|
1786
1792
|
}
|
|
1793
|
+
var literalComponentToken = /* @__PURE__ */ Symbol("context-directory.literal-posix-component");
|
|
1794
|
+
function literalComponent(name) {
|
|
1795
|
+
if (!name || name === "." || name === ".." || /[/\0]/.test(name))
|
|
1796
|
+
throw new ContextReadError("unsafe_target");
|
|
1797
|
+
}
|
|
1798
|
+
function component(name) {
|
|
1799
|
+
literalComponent(name);
|
|
1800
|
+
if (name.includes("\\")) throw new ContextReadError("unsafe_target");
|
|
1801
|
+
}
|
|
1787
1802
|
var ContextDirectory = class _ContextDirectory {
|
|
1788
1803
|
fd;
|
|
1789
1804
|
identity;
|
|
1790
|
-
originalStamp;
|
|
1791
|
-
children = [];
|
|
1792
|
-
listing;
|
|
1793
|
-
observedFiles = /* @__PURE__ */ new Map();
|
|
1794
1805
|
registeredPath;
|
|
1795
1806
|
label;
|
|
1796
1807
|
parent;
|
|
1797
|
-
|
|
1808
|
+
platform;
|
|
1809
|
+
canonicalPath;
|
|
1810
|
+
originalIdentity;
|
|
1811
|
+
children = [];
|
|
1812
|
+
listing;
|
|
1813
|
+
observedFiles = /* @__PURE__ */ new Map();
|
|
1814
|
+
observedMetadata = /* @__PURE__ */ new Map();
|
|
1815
|
+
observedLinks = /* @__PURE__ */ new Map();
|
|
1816
|
+
closed = false;
|
|
1817
|
+
constructor(registeredPath, label = ".", parent, token) {
|
|
1818
|
+
const platform = parent?.platform ?? process.platform;
|
|
1819
|
+
if (platform !== "linux" && platform !== "darwin")
|
|
1820
|
+
throw new ContextReadError("safe_reads_unavailable");
|
|
1821
|
+
this.platform = platform;
|
|
1798
1822
|
this.registeredPath = registeredPath;
|
|
1799
1823
|
this.label = label;
|
|
1800
1824
|
this.parent = parent;
|
|
1801
|
-
if (
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1825
|
+
if (parent) {
|
|
1826
|
+
if (token === literalComponentToken) literalComponent(registeredPath);
|
|
1827
|
+
else component(registeredPath);
|
|
1828
|
+
}
|
|
1829
|
+
parent?.assertCurrent();
|
|
1830
|
+
const canonicalPath = parent ? join14(parent.canonicalPath, registeredPath) : realpathSync4(registeredPath);
|
|
1831
|
+
let fd;
|
|
1832
|
+
try {
|
|
1833
|
+
if (platform === "linux") {
|
|
1834
|
+
this.canonicalPath = canonicalPath;
|
|
1835
|
+
fd = openSync3(
|
|
1836
|
+
parent ? join14(parent.path, registeredPath) : canonicalPath,
|
|
1837
|
+
constants3.O_RDONLY | constants3.O_DIRECTORY | constants3.O_NOFOLLOW
|
|
1838
|
+
);
|
|
1839
|
+
} else {
|
|
1840
|
+
const opened = openRootFileSync({
|
|
1841
|
+
rootPath: parent?.canonicalPath ?? canonicalPath,
|
|
1842
|
+
absolutePath: canonicalPath,
|
|
1843
|
+
boundaryLabel: "registered repository",
|
|
1844
|
+
allowedType: "directory",
|
|
1845
|
+
symlinks: "reject"
|
|
1846
|
+
});
|
|
1847
|
+
if (!opened.ok) throw new ContextReadError("root_changed");
|
|
1848
|
+
this.canonicalPath = opened.path;
|
|
1849
|
+
fd = opened.fd;
|
|
1850
|
+
}
|
|
1851
|
+
const stat2 = fstatSync3(fd, { bigint: true });
|
|
1852
|
+
if (!stat2.isDirectory() || stat2.ino <= 0n) throw new ContextReadError("root_changed");
|
|
1853
|
+
this.fd = fd;
|
|
1854
|
+
this.originalIdentity = { dev: stat2.dev, ino: stat2.ino };
|
|
1855
|
+
this.identity = hash(identity(stat2));
|
|
1856
|
+
if (platform === "darwin") this.assertCurrent();
|
|
1857
|
+
fd = void 0;
|
|
1858
|
+
} finally {
|
|
1859
|
+
if (fd !== void 0) closeSync3(fd);
|
|
1860
|
+
}
|
|
1807
1861
|
}
|
|
1808
1862
|
get path() {
|
|
1809
|
-
return `/proc/self/fd/${this.fd}
|
|
1863
|
+
return this.platform === "linux" ? `/proc/self/fd/${this.fd}` : this.canonicalPath;
|
|
1864
|
+
}
|
|
1865
|
+
/** Only the existing Linux backend admits a descriptor-pinned external Git worktree. */
|
|
1866
|
+
get gitWorktreePath() {
|
|
1867
|
+
return this.platform === "linux" ? `/proc/${process.pid}/fd/${this.fd}` : null;
|
|
1868
|
+
}
|
|
1869
|
+
assertCurrent() {
|
|
1870
|
+
if (this.closed) throw new ContextReadError("unreadable");
|
|
1871
|
+
if (this.platform === "linux") return;
|
|
1872
|
+
this.parent?.assertCurrent();
|
|
1873
|
+
try {
|
|
1874
|
+
const registered = this.parent ? join14(this.parent.canonicalPath, this.registeredPath) : realpathSync4(this.registeredPath);
|
|
1875
|
+
if (!this.parent && registered !== this.canonicalPath)
|
|
1876
|
+
throw new ContextReadError("root_changed");
|
|
1877
|
+
assertDirectoryIdentitySync(registered, {
|
|
1878
|
+
...this.originalIdentity,
|
|
1879
|
+
realPath: this.canonicalPath
|
|
1880
|
+
});
|
|
1881
|
+
const retained = fstatSync3(this.fd, { bigint: true });
|
|
1882
|
+
if (!retained.isDirectory() || identity(retained) !== identity(this.originalIdentity))
|
|
1883
|
+
throw new ContextReadError("root_changed");
|
|
1884
|
+
} catch {
|
|
1885
|
+
throw new ContextReadError("root_changed");
|
|
1886
|
+
}
|
|
1810
1887
|
}
|
|
1811
1888
|
directory(name) {
|
|
1889
|
+
component(name);
|
|
1812
1890
|
const child = new _ContextDirectory(
|
|
1813
1891
|
name,
|
|
1814
1892
|
this.label === "." ? name : `${this.label}/${name}`,
|
|
@@ -1817,11 +1895,66 @@ var ContextDirectory = class _ContextDirectory {
|
|
|
1817
1895
|
this.children.push(child);
|
|
1818
1896
|
return child;
|
|
1819
1897
|
}
|
|
1898
|
+
/** Bounded walkers can release a child after validating it instead of retaining an entire tree of FDs. */
|
|
1899
|
+
async visitDirectory(name, visit) {
|
|
1900
|
+
literalComponent(name);
|
|
1901
|
+
const child = new _ContextDirectory(
|
|
1902
|
+
name,
|
|
1903
|
+
this.label === "." ? name : `${this.label}/${name}`,
|
|
1904
|
+
this,
|
|
1905
|
+
literalComponentToken
|
|
1906
|
+
);
|
|
1907
|
+
try {
|
|
1908
|
+
await visit(child);
|
|
1909
|
+
child.validate();
|
|
1910
|
+
} finally {
|
|
1911
|
+
child.close();
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1914
|
+
/** Observe metadata without opening/reading file content; retain it for capture-wide validation. */
|
|
1915
|
+
metadata(name) {
|
|
1916
|
+
literalComponent(name);
|
|
1917
|
+
const stat2 = this.observe(name);
|
|
1918
|
+
this.observedMetadata.set(name, stat2 ? `${stamp(stat2)}:${stat2.mode}:${stat2.nlink}` : null);
|
|
1919
|
+
return stat2;
|
|
1920
|
+
}
|
|
1921
|
+
/** Read the link itself through this capture, never open its target. */
|
|
1922
|
+
readLink(name) {
|
|
1923
|
+
literalComponent(name);
|
|
1924
|
+
const before = this.observe(name);
|
|
1925
|
+
if (!before?.isSymbolicLink()) throw new ContextReadError("unsafe_file");
|
|
1926
|
+
const target = readlinkSync(join14(this.path, name));
|
|
1927
|
+
const after = this.observe(name);
|
|
1928
|
+
if (!after?.isSymbolicLink() || stamp(before) !== stamp(after))
|
|
1929
|
+
throw new ContextReadError("source_changed");
|
|
1930
|
+
this.observedMetadata.set(name, `${stamp(before)}:${before.mode}:${before.nlink}`);
|
|
1931
|
+
this.observedLinks.set(name, target);
|
|
1932
|
+
return target;
|
|
1933
|
+
}
|
|
1820
1934
|
entry(name) {
|
|
1935
|
+
component(name);
|
|
1936
|
+
this.assertCurrent();
|
|
1937
|
+
try {
|
|
1938
|
+
const stat2 = lstatSync3(join14(this.path, name));
|
|
1939
|
+
this.assertCurrent();
|
|
1940
|
+
return stat2;
|
|
1941
|
+
} catch (error) {
|
|
1942
|
+
this.assertCurrent();
|
|
1943
|
+
if (error.code === "ENOENT") return null;
|
|
1944
|
+
if (error instanceof ContextReadError) throw error;
|
|
1945
|
+
throw new ContextReadError("unreadable");
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
observe(name) {
|
|
1949
|
+
this.assertCurrent();
|
|
1821
1950
|
try {
|
|
1822
|
-
|
|
1951
|
+
const stat2 = lstatSync3(join14(this.path, name), { bigint: true });
|
|
1952
|
+
this.assertCurrent();
|
|
1953
|
+
return stat2;
|
|
1823
1954
|
} catch (error) {
|
|
1955
|
+
this.assertCurrent();
|
|
1824
1956
|
if (error.code === "ENOENT") return null;
|
|
1957
|
+
if (error instanceof ContextReadError) throw error;
|
|
1825
1958
|
throw new ContextReadError("unreadable");
|
|
1826
1959
|
}
|
|
1827
1960
|
}
|
|
@@ -1831,6 +1964,7 @@ var ContextDirectory = class _ContextDirectory {
|
|
|
1831
1964
|
return names;
|
|
1832
1965
|
}
|
|
1833
1966
|
listNames() {
|
|
1967
|
+
this.assertCurrent();
|
|
1834
1968
|
const handle = opendirSync(this.path);
|
|
1835
1969
|
const names = [];
|
|
1836
1970
|
try {
|
|
@@ -1840,68 +1974,115 @@ var ContextDirectory = class _ContextDirectory {
|
|
|
1840
1974
|
names.push(entry.name);
|
|
1841
1975
|
entry = handle.readSync();
|
|
1842
1976
|
}
|
|
1977
|
+
this.assertCurrent();
|
|
1843
1978
|
return names.sort();
|
|
1844
1979
|
} finally {
|
|
1845
1980
|
handle.closeSync();
|
|
1846
1981
|
}
|
|
1847
1982
|
}
|
|
1848
1983
|
read(name, maxBytes) {
|
|
1849
|
-
|
|
1984
|
+
component(name);
|
|
1985
|
+
const entry = this.observe(name);
|
|
1850
1986
|
if (!entry) {
|
|
1851
1987
|
this.observedFiles.set(name, null);
|
|
1852
1988
|
return null;
|
|
1853
1989
|
}
|
|
1854
1990
|
if (!entry.isFile() || entry.isSymbolicLink()) throw new ContextReadError("unsafe_file");
|
|
1991
|
+
if (entry.ino <= 0n) throw new ContextReadError("unreadable");
|
|
1855
1992
|
if (entry.size > maxBytes) throw new ContextReadError("byte_limit");
|
|
1856
1993
|
let fd;
|
|
1857
1994
|
try {
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1995
|
+
if (this.platform === "linux") {
|
|
1996
|
+
fd = openSync3(
|
|
1997
|
+
join14(this.path, name),
|
|
1998
|
+
constants3.O_RDONLY | constants3.O_NOFOLLOW | constants3.O_NONBLOCK
|
|
1999
|
+
);
|
|
2000
|
+
} else {
|
|
2001
|
+
this.assertCurrent();
|
|
2002
|
+
const opened = openRootFileSync({
|
|
2003
|
+
rootPath: this.canonicalPath,
|
|
2004
|
+
absolutePath: join14(this.canonicalPath, name),
|
|
2005
|
+
boundaryLabel: "captured repository directory",
|
|
2006
|
+
symlinks: "reject",
|
|
2007
|
+
maxBytes
|
|
2008
|
+
});
|
|
2009
|
+
if (!opened.ok) throw new ContextReadError("source_changed");
|
|
2010
|
+
fd = opened.fd;
|
|
2011
|
+
this.assertCurrent();
|
|
2012
|
+
}
|
|
2013
|
+
const before = fstatSync3(fd, { bigint: true });
|
|
1863
2014
|
if (!before.isFile() || stamp(entry) !== stamp(before))
|
|
1864
2015
|
throw new ContextReadError("source_changed");
|
|
1865
|
-
const buffer =
|
|
1866
|
-
|
|
1867
|
-
while (size < buffer.length) {
|
|
1868
|
-
const count2 = readSync2(fd, buffer, size, buffer.length - size, null);
|
|
1869
|
-
if (!count2) break;
|
|
1870
|
-
size += count2;
|
|
1871
|
-
}
|
|
1872
|
-
if (size > maxBytes || size !== before.size || stamp(fstatSync3(fd)) !== stamp(before)) {
|
|
2016
|
+
const buffer = readFileDescriptorBoundedSync(fd, maxBytes);
|
|
2017
|
+
if (BigInt(buffer.length) !== before.size || stamp(fstatSync3(fd, { bigint: true })) !== stamp(before))
|
|
1873
2018
|
throw new ContextReadError("source_changed");
|
|
1874
|
-
|
|
2019
|
+
this.assertCurrent();
|
|
1875
2020
|
this.observedFiles.set(name, stamp(before));
|
|
1876
|
-
return buffer
|
|
2021
|
+
return buffer;
|
|
1877
2022
|
} catch (error) {
|
|
1878
2023
|
if (error instanceof ContextReadError) throw error;
|
|
2024
|
+
if (error instanceof FsSafeError && error.code === "too-large")
|
|
2025
|
+
throw new ContextReadError("source_changed");
|
|
1879
2026
|
throw new ContextReadError("unreadable");
|
|
1880
2027
|
} finally {
|
|
1881
2028
|
if (fd !== void 0) closeSync3(fd);
|
|
1882
2029
|
}
|
|
1883
2030
|
}
|
|
1884
|
-
|
|
2031
|
+
/** Retained/registered directory identity only; does not require mutable workspace contents to stay frozen. */
|
|
2032
|
+
validateIdentity() {
|
|
2033
|
+
this.assertCurrent();
|
|
1885
2034
|
const currentPath = this.parent ? join14(this.parent.path, this.registeredPath) : realpathSync4(this.registeredPath);
|
|
1886
|
-
const stat2 = lstatSync3(currentPath);
|
|
1887
|
-
if (!stat2.isDirectory() || identity(stat2) !== this.
|
|
2035
|
+
const stat2 = lstatSync3(currentPath, { bigint: true });
|
|
2036
|
+
if (!stat2.isDirectory() || identity(stat2) !== identity(this.originalIdentity))
|
|
2037
|
+
throw new ContextReadError("root_changed");
|
|
2038
|
+
const retained = fstatSync3(this.fd, { bigint: true });
|
|
2039
|
+
if (!retained.isDirectory() || identity(retained) !== identity(this.originalIdentity))
|
|
1888
2040
|
throw new ContextReadError("root_changed");
|
|
1889
|
-
|
|
2041
|
+
}
|
|
2042
|
+
validate(skipGit = false, names) {
|
|
2043
|
+
this.validateIdentity();
|
|
2044
|
+
if (this.listing !== void 0 && JSON.stringify(this.listNames()) !== this.listing)
|
|
1890
2045
|
throw new ContextReadError("source_changed");
|
|
1891
|
-
}
|
|
1892
2046
|
for (const [name, previous] of this.observedFiles) {
|
|
1893
2047
|
if (names && !names.has(name)) continue;
|
|
1894
|
-
const current = this.
|
|
2048
|
+
const current = this.observe(name);
|
|
1895
2049
|
if ((current ? stamp(current) : null) !== previous)
|
|
1896
2050
|
throw new ContextReadError("source_changed");
|
|
1897
2051
|
}
|
|
2052
|
+
for (const [name, previous] of this.observedMetadata) {
|
|
2053
|
+
if (names && !names.has(name)) continue;
|
|
2054
|
+
const current = this.observe(name);
|
|
2055
|
+
if ((current ? `${stamp(current)}:${current.mode}:${current.nlink}` : null) !== previous)
|
|
2056
|
+
throw new ContextReadError("source_changed");
|
|
2057
|
+
}
|
|
2058
|
+
for (const [name, target] of this.observedLinks) {
|
|
2059
|
+
if (names && !names.has(name)) continue;
|
|
2060
|
+
this.assertCurrent();
|
|
2061
|
+
if (readlinkSync(join14(this.path, name)) !== target)
|
|
2062
|
+
throw new ContextReadError("source_changed");
|
|
2063
|
+
this.assertCurrent();
|
|
2064
|
+
}
|
|
1898
2065
|
for (const child of this.children) {
|
|
1899
2066
|
if (!skipGit || !child.label.split("/").includes(".git")) child.validate(skipGit, names);
|
|
1900
2067
|
}
|
|
1901
2068
|
}
|
|
1902
2069
|
close() {
|
|
1903
|
-
|
|
1904
|
-
|
|
2070
|
+
if (this.closed) return;
|
|
2071
|
+
this.closed = true;
|
|
2072
|
+
let failure;
|
|
2073
|
+
for (const child of this.children) {
|
|
2074
|
+
try {
|
|
2075
|
+
child.close();
|
|
2076
|
+
} catch (error) {
|
|
2077
|
+
failure ??= error;
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
try {
|
|
2081
|
+
closeSync3(this.fd);
|
|
2082
|
+
} catch (error) {
|
|
2083
|
+
failure ??= error;
|
|
2084
|
+
}
|
|
2085
|
+
if (failure) throw failure;
|
|
1905
2086
|
}
|
|
1906
2087
|
};
|
|
1907
2088
|
|
|
@@ -2220,9 +2401,9 @@ function parseEnvAllowlist(raw) {
|
|
|
2220
2401
|
}
|
|
2221
2402
|
function resolveShellSecurityConfig(env = process.env) {
|
|
2222
2403
|
const rawMode = env.BAZILION_BASH_SANDBOX?.trim() ?? "";
|
|
2223
|
-
if (rawMode !== "" && rawMode !== "off" && rawMode !== "docker") {
|
|
2404
|
+
if (rawMode !== "" && rawMode !== "off" && rawMode !== "docker" && rawMode !== "native") {
|
|
2224
2405
|
throw new ShellSecurityConfigError(
|
|
2225
|
-
`BAZILION_BASH_SANDBOX must be "off" or "
|
|
2406
|
+
`BAZILION_BASH_SANDBOX must be "off", "docker" or "native", received: ${rawMode}`
|
|
2226
2407
|
);
|
|
2227
2408
|
}
|
|
2228
2409
|
const rawApproval = env.BAZILION_BASH_APPROVAL?.trim() ?? "";
|
|
@@ -2238,8 +2419,8 @@ function resolveShellSecurityConfig(env = process.env) {
|
|
|
2238
2419
|
);
|
|
2239
2420
|
}
|
|
2240
2421
|
return {
|
|
2241
|
-
sandboxMode: rawMode === "docker" ? "docker" : "off",
|
|
2242
|
-
approvalMode: rawApproval === "dangerous" ? "dangerous" : "off",
|
|
2422
|
+
sandboxMode: rawMode === "native" ? "native" : rawMode === "docker" ? "docker" : "off",
|
|
2423
|
+
approvalMode: rawMode === "native" || rawApproval === "dangerous" ? "dangerous" : "off",
|
|
2243
2424
|
sandboxImage: rawImage || DEFAULT_BASH_SANDBOX_IMAGE,
|
|
2244
2425
|
envAllowlist: parseEnvAllowlist(env.BAZILION_BASH_SANDBOX_ENV_ALLOWLIST)
|
|
2245
2426
|
};
|
|
@@ -2362,6 +2543,23 @@ var CONTAINER_LITERAL_ENV_KEYS = /* @__PURE__ */ new Set([
|
|
|
2362
2543
|
"TMPDIR",
|
|
2363
2544
|
"TZ"
|
|
2364
2545
|
]);
|
|
2546
|
+
var DOCKER_PREFLIGHT_PHASES = ["engine", "create", "start", "cleanup"];
|
|
2547
|
+
var DockerPreflightError = class extends Error {
|
|
2548
|
+
phase;
|
|
2549
|
+
kind;
|
|
2550
|
+
constructor(phase, cause, kind = "failed") {
|
|
2551
|
+
if (!DOCKER_PREFLIGHT_PHASES.includes(phase) || !["failed", "timeout"].includes(kind))
|
|
2552
|
+
throw new Error("invalid Docker preflight phase or kind");
|
|
2553
|
+
super(cause instanceof Error ? cause.message : "Docker preflight failed", { cause });
|
|
2554
|
+
this.phase = phase;
|
|
2555
|
+
this.kind = kind;
|
|
2556
|
+
Object.defineProperties(this, {
|
|
2557
|
+
phase: { value: phase, writable: false, configurable: false },
|
|
2558
|
+
kind: { value: kind, writable: false, configurable: false }
|
|
2559
|
+
});
|
|
2560
|
+
this.name = "DockerPreflightError";
|
|
2561
|
+
}
|
|
2562
|
+
};
|
|
2365
2563
|
var PROTECTED_CONTAINER_ENV = {
|
|
2366
2564
|
PATH: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
|
|
2367
2565
|
HOME: "/tmp",
|
|
@@ -2452,10 +2650,15 @@ function buildDockerRunSpec(input) {
|
|
|
2452
2650
|
` } : {}
|
|
2453
2651
|
};
|
|
2454
2652
|
}
|
|
2653
|
+
function assertDockerPlatform() {
|
|
2654
|
+
if (process.platform !== "linux")
|
|
2655
|
+
throw new Error("Docker execution is supported only on Linux. Use native execution on macOS.");
|
|
2656
|
+
}
|
|
2455
2657
|
function createPreparedDockerBashOperations(runtime, lifecycle) {
|
|
2456
2658
|
validatePreparedDockerRuntime(runtime);
|
|
2457
2659
|
return {
|
|
2458
2660
|
async exec(command, cwd, { onData, signal, timeout }) {
|
|
2661
|
+
assertDockerPlatform();
|
|
2459
2662
|
const timeoutMs = resolveTimeoutMs(timeout);
|
|
2460
2663
|
if (signal?.aborted) throw new Error("aborted");
|
|
2461
2664
|
const workspace = await recheckProtectedMount(runtime.workspace);
|
|
@@ -2556,8 +2759,12 @@ function runProtectedContainerCreate(spec, options) {
|
|
|
2556
2759
|
else resolve7();
|
|
2557
2760
|
};
|
|
2558
2761
|
const commandTimeout = options?.timeoutMs !== void 0 && options.timeoutMs <= DOCKER_CREATE_TIMEOUT_MS;
|
|
2559
|
-
const timeoutError = () => commandTimeout ? new Error(`timeout:${options?.timeout}`) : new
|
|
2560
|
-
|
|
2762
|
+
const timeoutError = () => commandTimeout ? new Error(`timeout:${options?.timeout}`) : new DockerPreflightError(
|
|
2763
|
+
"create",
|
|
2764
|
+
new Error(
|
|
2765
|
+
`Docker sandbox could not create its protected preflight container within ${DOCKER_CREATE_TIMEOUT_MS}ms`
|
|
2766
|
+
),
|
|
2767
|
+
"timeout"
|
|
2561
2768
|
);
|
|
2562
2769
|
child.stderr?.on("data", (data) => {
|
|
2563
2770
|
stderr = `${stderr}${data.toString("utf8")}`.slice(-MAX_STDERR_CHARS);
|
|
@@ -2702,6 +2909,7 @@ function createDockerBashOperations(options) {
|
|
|
2702
2909
|
validateImage(image);
|
|
2703
2910
|
return {
|
|
2704
2911
|
async exec(command, cwd, { onData, signal, timeout }) {
|
|
2912
|
+
assertDockerPlatform();
|
|
2705
2913
|
const timeoutMs = resolveTimeoutMs(timeout);
|
|
2706
2914
|
if (signal?.aborted) throw new Error("aborted");
|
|
2707
2915
|
const mountSource = await resolveMountSource(cwd);
|
|
@@ -3192,7 +3400,9 @@ function runCleanupCommand(dockerPath, args, processEnv) {
|
|
|
3192
3400
|
// ../daemon/src/runtime/pi/coding.ts
|
|
3193
3401
|
function codingTools(input) {
|
|
3194
3402
|
const readSecrets = () => typeof input.secrets === "function" ? input.secrets() : input.secrets ?? [];
|
|
3195
|
-
const
|
|
3403
|
+
const native = input.native;
|
|
3404
|
+
if (input.docker && native) throw new Error("Coding execution backend is ambiguous");
|
|
3405
|
+
const hostOperations = input.docker || input.native ? null : createLocalBashOperations();
|
|
3196
3406
|
return [
|
|
3197
3407
|
{
|
|
3198
3408
|
name: "coding_environment",
|
|
@@ -3264,12 +3474,35 @@ function codingTools(input) {
|
|
|
3264
3474
|
});
|
|
3265
3475
|
};
|
|
3266
3476
|
let outcome;
|
|
3477
|
+
let captureTruncated = false;
|
|
3478
|
+
const capture = native ? { observedBytes: 0, redacted: false } : void 0;
|
|
3267
3479
|
try {
|
|
3268
|
-
if (input.approval)
|
|
3480
|
+
if (input.approval && !input.native)
|
|
3269
3481
|
await requireBashApproval(command.command, toolCallId, signal, input.approvalHost);
|
|
3270
3482
|
signal?.throwIfAborted();
|
|
3271
3483
|
const cwd = resolveCodingDirectory(input.root, command.cwd);
|
|
3272
|
-
const operations =
|
|
3484
|
+
const operations = native ? {
|
|
3485
|
+
async exec(text2, _cwd, options) {
|
|
3486
|
+
const value = await native.exec(
|
|
3487
|
+
{
|
|
3488
|
+
toolCallId,
|
|
3489
|
+
command: text2,
|
|
3490
|
+
cwd: command.cwd,
|
|
3491
|
+
timeoutMs: command.timeoutSeconds * 1e3
|
|
3492
|
+
},
|
|
3493
|
+
(_stream, bytes, producer) => {
|
|
3494
|
+
if (capture) {
|
|
3495
|
+
capture.observedBytes = producer?.observedBytes ?? capture.observedBytes + bytes.length;
|
|
3496
|
+
capture.redacted ||= producer?.redacted === true;
|
|
3497
|
+
}
|
|
3498
|
+
options.onData(bytes);
|
|
3499
|
+
},
|
|
3500
|
+
options.signal
|
|
3501
|
+
);
|
|
3502
|
+
captureTruncated = value.stdoutTruncated || value.stderrTruncated;
|
|
3503
|
+
return { exitCode: value.code };
|
|
3504
|
+
}
|
|
3505
|
+
} : input.docker ? createPreparedDockerBashOperations(
|
|
3273
3506
|
{
|
|
3274
3507
|
...input.docker,
|
|
3275
3508
|
coding: {
|
|
@@ -3280,7 +3513,8 @@ function codingTools(input) {
|
|
|
3280
3513
|
},
|
|
3281
3514
|
input.lifecycle
|
|
3282
3515
|
) : hostOperations;
|
|
3283
|
-
|
|
3516
|
+
if (!operations) throw new Error("Coding execution backend unavailable");
|
|
3517
|
+
const result2 = await operations.exec(
|
|
3284
3518
|
command.command,
|
|
3285
3519
|
input.docker ? input.root : cwd.path,
|
|
3286
3520
|
{
|
|
@@ -3293,21 +3527,25 @@ function codingTools(input) {
|
|
|
3293
3527
|
}
|
|
3294
3528
|
);
|
|
3295
3529
|
emitProgress(true);
|
|
3530
|
+
const retained = output2.finish();
|
|
3296
3531
|
outcome = {
|
|
3297
|
-
state:
|
|
3298
|
-
exitCode:
|
|
3299
|
-
...
|
|
3300
|
-
|
|
3532
|
+
state: result2.exitCode === 0 ? "succeeded" : result2.exitCode === null ? "interrupted" : "failed",
|
|
3533
|
+
exitCode: result2.exitCode,
|
|
3534
|
+
...retained,
|
|
3535
|
+
truncated: retained.truncated || captureTruncated,
|
|
3536
|
+
reason: result2.exitCode === null ? "exit_unavailable" : null
|
|
3301
3537
|
};
|
|
3302
3538
|
} catch (error) {
|
|
3303
3539
|
const message = error instanceof Error ? error.message : "Command execution unavailable";
|
|
3304
|
-
const
|
|
3540
|
+
const failure = error && typeof error === "object" ? error : void 0;
|
|
3541
|
+
const state = failure?.cleanupConfirmed === false ? "interrupted" : failure?.code === "timed_out" ? "timed_out" : failure?.code === "cancelled" ? "cancelled" : failure?.code === "approval_denied" ? "blocked" : signal?.aborted || message === "aborted" ? "cancelled" : message.startsWith("timeout:") ? "timed_out" : error instanceof BashApprovalDeniedError ? "blocked" : /cleanup|teardown/i.test(message) ? "interrupted" : "blocked";
|
|
3305
3542
|
outcome = { state, exitCode: null, ...output2.finish(), reason: message };
|
|
3306
3543
|
}
|
|
3307
3544
|
const receipt = await input.host.invoke({
|
|
3308
3545
|
action: "finish",
|
|
3309
3546
|
id: started.id,
|
|
3310
|
-
outcome
|
|
3547
|
+
outcome,
|
|
3548
|
+
...capture ? { capture } : {}
|
|
3311
3549
|
});
|
|
3312
3550
|
return {
|
|
3313
3551
|
content: [{ type: "text", text: JSON.stringify(receipt) }],
|
|
@@ -3356,15 +3594,15 @@ function codingTools(input) {
|
|
|
3356
3594
|
async execute(_id, params) {
|
|
3357
3595
|
const values = params;
|
|
3358
3596
|
if (values.search !== void 0) {
|
|
3359
|
-
const
|
|
3597
|
+
const result2 = await input.host.invoke({
|
|
3360
3598
|
action: "log-search",
|
|
3361
3599
|
id: values.id,
|
|
3362
3600
|
query: values.search,
|
|
3363
3601
|
...values.messageId !== void 0 ? { messageId: values.messageId } : {}
|
|
3364
3602
|
});
|
|
3365
3603
|
return {
|
|
3366
|
-
content: [{ type: "text", text: JSON.stringify(
|
|
3367
|
-
details: { codingLogSearch:
|
|
3604
|
+
content: [{ type: "text", text: JSON.stringify(result2) }],
|
|
3605
|
+
details: { codingLogSearch: result2 }
|
|
3368
3606
|
};
|
|
3369
3607
|
}
|
|
3370
3608
|
const value = await input.host.invoke({
|
|
@@ -3560,7 +3798,7 @@ ${JSON.stringify(current.commands)}`
|
|
|
3560
3798
|
}
|
|
3561
3799
|
|
|
3562
3800
|
// ../daemon/src/runtime/pi/session.ts
|
|
3563
|
-
import { existsSync as existsSync14, mkdirSync as mkdirSync7, statSync as statSync5, writeFileSync as writeFileSync9 } from "fs";
|
|
3801
|
+
import { existsSync as existsSync14, mkdirSync as mkdirSync7, realpathSync as realpathSync10, statSync as statSync5, writeFileSync as writeFileSync9 } from "fs";
|
|
3564
3802
|
import { basename as basename5, join as join22 } from "path";
|
|
3565
3803
|
import {
|
|
3566
3804
|
createAssistantMessageEventStream
|
|
@@ -3578,7 +3816,7 @@ import { InMemoryCredentialStore } from "@earendil-works/pi-ai";
|
|
|
3578
3816
|
import { ModelRuntime } from "@earendil-works/pi-coding-agent";
|
|
3579
3817
|
var PROVIDER_ALIASES = {
|
|
3580
3818
|
bedrock: "amazon-bedrock",
|
|
3581
|
-
"azure-openai": "azure
|
|
3819
|
+
"azure-openai": "azure"
|
|
3582
3820
|
};
|
|
3583
3821
|
var PROTECTED_PROVIDER_NAMES = [
|
|
3584
3822
|
"anthropic",
|
|
@@ -3723,12 +3961,12 @@ function providerBaseUrl(providerName, env) {
|
|
|
3723
3961
|
}
|
|
3724
3962
|
}
|
|
3725
3963
|
function providerCredentialEnv(providerName, env) {
|
|
3726
|
-
const
|
|
3964
|
+
const result2 = {};
|
|
3727
3965
|
for (const name of PROVIDER_CREDENTIAL_ENV[providerName] ?? []) {
|
|
3728
3966
|
const value = env[name];
|
|
3729
|
-
if (value !== void 0)
|
|
3967
|
+
if (value !== void 0) result2[name] = value;
|
|
3730
3968
|
}
|
|
3731
|
-
return Object.keys(
|
|
3969
|
+
return Object.keys(result2).length > 0 ? result2 : void 0;
|
|
3732
3970
|
}
|
|
3733
3971
|
function fallbackApi(providerName) {
|
|
3734
3972
|
switch (providerName) {
|
|
@@ -4078,10 +4316,17 @@ ${contextBlocks.join("\n\n")}`);
|
|
|
4078
4316
|
if (options.browserGuide) {
|
|
4079
4317
|
parts.push(browserGuideSection());
|
|
4080
4318
|
}
|
|
4319
|
+
if (options.sandboxMode === "native")
|
|
4320
|
+
parts.push(
|
|
4321
|
+
[
|
|
4322
|
+
"# Native command execution",
|
|
4323
|
+
"bash and coding_command use the daemon-admitted native OS sandbox, not direct host tools. Team memory and admitted inputs are read-only. TCP/UDP, including localhost, are denied; pipes and private per-job pathname Unix IPC are available. There is no host-tool, Docker or VM fallback. Report unavailable protection or missing native tools instead of bypassing the boundary. Dangerous commands require the current operator approval; unattended requests deny."
|
|
4324
|
+
].join("\n\n")
|
|
4325
|
+
);
|
|
4081
4326
|
const teamLines = [
|
|
4082
4327
|
"# Team",
|
|
4083
4328
|
"",
|
|
4084
|
-
`- ${agent.team.id} (${agent.team.name}): ${options.sandboxMode === "docker" ? "/workspace" : agent.team.path}`,
|
|
4329
|
+
`- ${agent.team.id} (${agent.team.name}): ${options.sandboxMode === "docker" ? "/workspace" : options.modelWorkspace ?? agent.team.path}`,
|
|
4085
4330
|
"",
|
|
4086
4331
|
"Your team is where work product lives \u2014 code, docs, artefacts, shared scratch. It may be shared with other agents in the same team. Use the workspace tools currently exposed to work there. Never use workspace tools to edit your identity/soul/behaviour files \u2014 those live in your private home and are reached via `home_write` / `home_read`."
|
|
4087
4332
|
];
|
|
@@ -4130,13 +4375,277 @@ function boundReviewedLessons(lessons, maxCharacters = 8e3) {
|
|
|
4130
4375
|
return selected;
|
|
4131
4376
|
}
|
|
4132
4377
|
|
|
4378
|
+
// ../daemon/src/runtime/shell/native-tooling.ts
|
|
4379
|
+
import { constants as constants6 } from "os";
|
|
4380
|
+
import {
|
|
4381
|
+
createBashToolDefinition,
|
|
4382
|
+
defineTool as defineTool2
|
|
4383
|
+
} from "@earendil-works/pi-coding-agent";
|
|
4384
|
+
|
|
4385
|
+
// ../daemon/src/runtime/worker/ipc-client.ts
|
|
4386
|
+
import { randomUUID as randomUUID20 } from "crypto";
|
|
4387
|
+
|
|
4388
|
+
// ../daemon/src/core/coding-environment/native-failure.ts
|
|
4389
|
+
function snapshotNativeFailureObservation(value) {
|
|
4390
|
+
const fields = [
|
|
4391
|
+
"backend",
|
|
4392
|
+
"phase",
|
|
4393
|
+
"ownerLive",
|
|
4394
|
+
"commandCompleted",
|
|
4395
|
+
"commandNaturalEOF",
|
|
4396
|
+
"fenced",
|
|
4397
|
+
"terminalProof",
|
|
4398
|
+
"captures"
|
|
4399
|
+
];
|
|
4400
|
+
if (!value || typeof value !== "object" || Object.getPrototypeOf(value) !== Object.prototype || Object.keys(value).length !== fields.length || fields.some((key) => !Object.hasOwn(value, key)))
|
|
4401
|
+
throw new Error("Invalid native failure observation");
|
|
4402
|
+
const item = value;
|
|
4403
|
+
if (item.backend !== "darwin-seatbelt" || typeof item.phase !== "string" || ![
|
|
4404
|
+
"idle",
|
|
4405
|
+
"ready",
|
|
4406
|
+
"term",
|
|
4407
|
+
"kill",
|
|
4408
|
+
"command-eof",
|
|
4409
|
+
"census",
|
|
4410
|
+
"exit",
|
|
4411
|
+
"group",
|
|
4412
|
+
"settled"
|
|
4413
|
+
].includes(item.phase) || ["ownerLive", "commandCompleted", "commandNaturalEOF", "fenced", "terminalProof"].some(
|
|
4414
|
+
(key) => typeof item[key] !== "boolean"
|
|
4415
|
+
) || !Array.isArray(item.captures) || item.captures.length > 2 || !Array.from(item.captures).every(
|
|
4416
|
+
(capture) => ["empty_at_capture", "busy", "drift", "unknown"].includes(capture)
|
|
4417
|
+
))
|
|
4418
|
+
throw new Error("Invalid native failure observation");
|
|
4419
|
+
return Object.freeze({
|
|
4420
|
+
...item,
|
|
4421
|
+
captures: Object.freeze([...item.captures])
|
|
4422
|
+
});
|
|
4423
|
+
}
|
|
4424
|
+
|
|
4425
|
+
// ../daemon/src/runtime/worker/ipc-client.ts
|
|
4426
|
+
var WorkerNativeExecutionError = class extends Error {
|
|
4427
|
+
code;
|
|
4428
|
+
cleanupConfirmed;
|
|
4429
|
+
observation;
|
|
4430
|
+
constructor(message, failure) {
|
|
4431
|
+
super(message);
|
|
4432
|
+
this.name = "WorkerNativeExecutionError";
|
|
4433
|
+
this.code = failure.code;
|
|
4434
|
+
this.cleanupConfirmed = failure.cleanupConfirmed;
|
|
4435
|
+
this.observation = failure.observation ? snapshotNativeFailureObservation(failure.observation) : void 0;
|
|
4436
|
+
}
|
|
4437
|
+
};
|
|
4438
|
+
var plain = (value) => !!value && typeof value === "object" && Object.getPrototypeOf(value) === Object.prototype;
|
|
4439
|
+
function nativeFailure(value) {
|
|
4440
|
+
if (plain(value) && Object.hasOwn(value, "observation")) {
|
|
4441
|
+
if (value.cleanupConfirmed !== false || value.code !== "recovery_required") return false;
|
|
4442
|
+
try {
|
|
4443
|
+
snapshotNativeFailureObservation(value.observation);
|
|
4444
|
+
} catch {
|
|
4445
|
+
return false;
|
|
4446
|
+
}
|
|
4447
|
+
}
|
|
4448
|
+
return plain(value) && ["cleanupConfirmed,code", "cleanupConfirmed,code,observation"].includes(
|
|
4449
|
+
Object.keys(value).sort().join(",")
|
|
4450
|
+
) && typeof value.code === "string" && ["unavailable", "approval_denied", "cancelled", "timed_out", "recovery_required"].includes(
|
|
4451
|
+
value.code
|
|
4452
|
+
) && typeof value.cleanupConfirmed === "boolean";
|
|
4453
|
+
}
|
|
4454
|
+
function createIpcClient(channel) {
|
|
4455
|
+
const pending = /* @__PURE__ */ new Map();
|
|
4456
|
+
let disconnected = false;
|
|
4457
|
+
channel.onMessage((message) => {
|
|
4458
|
+
if (plain(message) && message.type === "rpc-output" && typeof message.id === "string") {
|
|
4459
|
+
const entry2 = pending.get(message.id);
|
|
4460
|
+
if (!entry2 || entry2.outputError) return;
|
|
4461
|
+
try {
|
|
4462
|
+
if (entry2.method !== "nativeExecute" || Object.keys(message).sort().join(",") !== "data,id,observedBytes,redacted,sequence,stream,type" || !["stdout", "stderr"].includes(String(message.stream)) || message.sequence !== entry2.sequence + 1 || entry2.sequence >= 4096 || typeof message.observedBytes !== "number" || !Number.isSafeInteger(message.observedBytes) || message.observedBytes < 1 || message.observedBytes < entry2.observedBytes || message.observedBytes > 2 * 1024 * 1024 || typeof message.redacted !== "boolean" || entry2.redacted && !message.redacted || typeof message.data !== "string" || !message.data.length || message.data.length > 87384)
|
|
4463
|
+
throw new Error("Invalid native IPC output");
|
|
4464
|
+
const bytes = Buffer.from(message.data, "base64");
|
|
4465
|
+
if (bytes.length > 64 * 1024 || bytes.toString("base64") !== message.data || entry2.bytes + bytes.length > 2 * 1024 * 1024)
|
|
4466
|
+
throw new Error("Invalid native IPC output");
|
|
4467
|
+
entry2.sequence++;
|
|
4468
|
+
entry2.bytes += bytes.length;
|
|
4469
|
+
entry2.observedBytes = message.observedBytes;
|
|
4470
|
+
entry2.redacted = message.redacted;
|
|
4471
|
+
entry2.output?.({
|
|
4472
|
+
stream: message.stream,
|
|
4473
|
+
sequence: entry2.sequence,
|
|
4474
|
+
data: message.data,
|
|
4475
|
+
observedBytes: entry2.observedBytes,
|
|
4476
|
+
redacted: entry2.redacted
|
|
4477
|
+
});
|
|
4478
|
+
} catch (error) {
|
|
4479
|
+
entry2.outputError = error instanceof Error ? error : new Error("Native IPC output unavailable");
|
|
4480
|
+
}
|
|
4481
|
+
return;
|
|
4482
|
+
}
|
|
4483
|
+
if (!isIpcReply(message)) return;
|
|
4484
|
+
const entry = pending.get(message.id);
|
|
4485
|
+
if (!entry) return;
|
|
4486
|
+
pending.delete(message.id);
|
|
4487
|
+
if (message.ok) {
|
|
4488
|
+
if (entry.outputError) entry.reject(entry.outputError);
|
|
4489
|
+
else entry.resolve(message.result);
|
|
4490
|
+
} else if ((entry.method === "nativeExecute" || entry.method === "nativeCancel") && message.nativeFailure !== void 0) {
|
|
4491
|
+
if (nativeFailure(message.nativeFailure))
|
|
4492
|
+
entry.reject(new WorkerNativeExecutionError(message.error, message.nativeFailure));
|
|
4493
|
+
else entry.reject(new Error("Invalid native IPC failure"));
|
|
4494
|
+
} else entry.reject(new Error(message.error));
|
|
4495
|
+
});
|
|
4496
|
+
channel.onDisconnect(() => {
|
|
4497
|
+
disconnected = true;
|
|
4498
|
+
for (const entry of pending.values()) entry.reject(new Error("worker IPC channel disconnected"));
|
|
4499
|
+
pending.clear();
|
|
4500
|
+
});
|
|
4501
|
+
return (method, args, options) => {
|
|
4502
|
+
if (disconnected) return Promise.reject(new Error("worker IPC channel disconnected"));
|
|
4503
|
+
const send = channel.send;
|
|
4504
|
+
if (!send)
|
|
4505
|
+
return Promise.reject(new Error("worker: no IPC channel \u2014 daemon must spawn with stdio:ipc"));
|
|
4506
|
+
if (options?.onNativeOutput && method !== "nativeExecute")
|
|
4507
|
+
return Promise.reject(new Error("Native IPC output requires native execution"));
|
|
4508
|
+
const id = randomUUID20(), message = { type: "rpc", id, method, args };
|
|
4509
|
+
return new Promise((resolve7, reject) => {
|
|
4510
|
+
pending.set(id, {
|
|
4511
|
+
method,
|
|
4512
|
+
resolve: (value) => resolve7(value),
|
|
4513
|
+
reject,
|
|
4514
|
+
output: options?.onNativeOutput,
|
|
4515
|
+
sequence: 0,
|
|
4516
|
+
bytes: 0,
|
|
4517
|
+
observedBytes: 0,
|
|
4518
|
+
redacted: false
|
|
4519
|
+
});
|
|
4520
|
+
try {
|
|
4521
|
+
send(message, (error) => {
|
|
4522
|
+
if (!error) return;
|
|
4523
|
+
pending.delete(id);
|
|
4524
|
+
reject(error);
|
|
4525
|
+
});
|
|
4526
|
+
} catch (error) {
|
|
4527
|
+
pending.delete(id);
|
|
4528
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
4529
|
+
}
|
|
4530
|
+
});
|
|
4531
|
+
};
|
|
4532
|
+
}
|
|
4533
|
+
function isIpcReply(message) {
|
|
4534
|
+
if (!message || typeof message !== "object") return false;
|
|
4535
|
+
const candidate = message;
|
|
4536
|
+
return candidate.type === "rpc-reply" && typeof candidate.id === "string" && typeof candidate.ok === "boolean";
|
|
4537
|
+
}
|
|
4538
|
+
|
|
4539
|
+
// ../daemon/src/runtime/shell/native-tooling.ts
|
|
4540
|
+
var NATIVE_TRUNCATION_NOTE = "Native command capture was truncated; any saved full-output file contains only the retained capture.";
|
|
4541
|
+
function snapshotNativeSessionExecution(value) {
|
|
4542
|
+
if (!value || typeof value !== "object" || Object.keys(value).sort().join(",") !== "cwd,host" || !value.host || typeof value.host.exec !== "function" || typeof value.host.cancel !== "function")
|
|
4543
|
+
throw new Error("Native session capability is unavailable");
|
|
4544
|
+
return Object.freeze({ cwd: codingRelativePath(value.cwd), host: value.host });
|
|
4545
|
+
}
|
|
4546
|
+
function createNativeSessionShellTools(modelCwd, relativeCwd, host) {
|
|
4547
|
+
const cwd = codingRelativePath(relativeCwd);
|
|
4548
|
+
let active;
|
|
4549
|
+
const base = createBashToolDefinition(modelCwd, {
|
|
4550
|
+
exposeSessionEnvironment: false,
|
|
4551
|
+
operations: {
|
|
4552
|
+
async exec(command, requestedCwd, options) {
|
|
4553
|
+
if (!active || active.invoked || requestedCwd !== modelCwd)
|
|
4554
|
+
throw new Error("Native bash scope is unavailable");
|
|
4555
|
+
active.invoked = true;
|
|
4556
|
+
const seconds = options.timeout ?? 300;
|
|
4557
|
+
if (!Number.isFinite(seconds) || seconds <= 0 || seconds > 300)
|
|
4558
|
+
throw new Error("Native bash timeout must be greater than zero and at most 300 seconds");
|
|
4559
|
+
const result2 = await host.exec(
|
|
4560
|
+
{ toolCallId: active.id, command, cwd, timeoutMs: Math.ceil(seconds * 1e3) },
|
|
4561
|
+
(_stream, bytes) => options.onData(bytes),
|
|
4562
|
+
options.signal
|
|
4563
|
+
);
|
|
4564
|
+
active.result = result2;
|
|
4565
|
+
const signum = result2.signal ? constants6.signals[result2.signal] : void 0;
|
|
4566
|
+
return { exitCode: result2.code ?? (signum ? 128 + signum : null) };
|
|
4567
|
+
}
|
|
4568
|
+
}
|
|
4569
|
+
});
|
|
4570
|
+
const tool = defineTool2({
|
|
4571
|
+
...base,
|
|
4572
|
+
label: "bash (native sandbox)",
|
|
4573
|
+
description: `${base.description} Default working directory: ${modelCwd}. Runs only through the daemon-admitted native sandbox. TCP/UDP, including localhost, are denied; only pipes and private per-job pathname Unix IPC are available. Team memory and admitted inputs are read-only. No host-tool, Docker or VM fallback. Dangerous commands require operator approval; unattended requests deny. Default and maximum timeout: 300 seconds.`,
|
|
4574
|
+
executionMode: "sequential",
|
|
4575
|
+
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
4576
|
+
if (active) throw new Error("Native bash invocation already active");
|
|
4577
|
+
const invocation = {
|
|
4578
|
+
id: toolCallId,
|
|
4579
|
+
invoked: false
|
|
4580
|
+
};
|
|
4581
|
+
active = invocation;
|
|
4582
|
+
try {
|
|
4583
|
+
const result2 = await base.execute(toolCallId, params, signal, onUpdate, ctx);
|
|
4584
|
+
const captured = invocation.result;
|
|
4585
|
+
if (!captured) throw new Error("Native bash execution evidence unavailable");
|
|
4586
|
+
const truncated = captured.stdoutTruncated || captured.stderrTruncated;
|
|
4587
|
+
const structured = result2.structuredContent;
|
|
4588
|
+
return {
|
|
4589
|
+
...result2,
|
|
4590
|
+
...structured && typeof structured === "object" && !Array.isArray(structured) ? {
|
|
4591
|
+
structuredContent: {
|
|
4592
|
+
...structured,
|
|
4593
|
+
truncated: "truncated" in structured && structured.truncated === true || truncated
|
|
4594
|
+
}
|
|
4595
|
+
} : {},
|
|
4596
|
+
content: [
|
|
4597
|
+
...result2.content,
|
|
4598
|
+
...truncated ? [
|
|
4599
|
+
{
|
|
4600
|
+
type: "text",
|
|
4601
|
+
text: NATIVE_TRUNCATION_NOTE
|
|
4602
|
+
}
|
|
4603
|
+
] : []
|
|
4604
|
+
],
|
|
4605
|
+
details: { ...result2.details, nativeExecution: captured }
|
|
4606
|
+
};
|
|
4607
|
+
} catch (error) {
|
|
4608
|
+
if (error instanceof WorkerNativeExecutionError) {
|
|
4609
|
+
const failure = Object.freeze({
|
|
4610
|
+
code: error.code,
|
|
4611
|
+
cleanupConfirmed: error.cleanupConfirmed,
|
|
4612
|
+
...error.observation ? { observation: error.observation } : {}
|
|
4613
|
+
});
|
|
4614
|
+
return {
|
|
4615
|
+
isError: true,
|
|
4616
|
+
content: [
|
|
4617
|
+
{
|
|
4618
|
+
type: "text",
|
|
4619
|
+
text: error.message + (error.observation ? `
|
|
4620
|
+
Native boundary observation (diagnostics, not cleanup authority): ${JSON.stringify(error.observation)}` : "")
|
|
4621
|
+
}
|
|
4622
|
+
],
|
|
4623
|
+
details: { nativeExecutionFailure: failure }
|
|
4624
|
+
};
|
|
4625
|
+
}
|
|
4626
|
+
if (error instanceof Error && (invocation.result?.stdoutTruncated || invocation.result?.stderrTruncated))
|
|
4627
|
+
throw new Error(`${error.message}
|
|
4628
|
+
${NATIVE_TRUNCATION_NOTE}`);
|
|
4629
|
+
throw error;
|
|
4630
|
+
} finally {
|
|
4631
|
+
active = void 0;
|
|
4632
|
+
}
|
|
4633
|
+
}
|
|
4634
|
+
});
|
|
4635
|
+
return Object.freeze({ hostToolNames: Object.freeze([]), customBash: tool });
|
|
4636
|
+
}
|
|
4637
|
+
|
|
4638
|
+
// ../daemon/src/runtime/shell/platform-support.ts
|
|
4639
|
+
var MAC_NATIVE_EXECUTION_UNAVAILABLE = "Native macOS isolation is deferred and unqualified. Use sandbox off only for trusted host execution; isolation-required work remains unavailable.";
|
|
4640
|
+
var MAC_PROTECTED_EXECUTION_UNAVAILABLE = "Protected execution is unavailable on macOS because no qualified isolation backend is available. Trusted host execution cannot satisfy this requirement.";
|
|
4641
|
+
|
|
4133
4642
|
// ../daemon/src/runtime/shell/tooling.ts
|
|
4134
4643
|
import { existsSync as existsSync11, lstatSync as lstatSync5, realpathSync as realpathSync7 } from "fs";
|
|
4135
4644
|
import { dirname as dirname5, isAbsolute as isAbsolute5, join as join18, relative as relative4, sep as sep4 } from "path";
|
|
4136
4645
|
import {
|
|
4137
|
-
createBashToolDefinition,
|
|
4646
|
+
createBashToolDefinition as createBashToolDefinition2,
|
|
4138
4647
|
createLocalBashOperations as createLocalBashOperations2,
|
|
4139
|
-
defineTool as
|
|
4648
|
+
defineTool as defineTool3
|
|
4140
4649
|
} from "@earendil-works/pi-coding-agent";
|
|
4141
4650
|
var HOST_CODING_TOOL_NAMES = ["read", "bash", "edit", "write", "grep", "find", "ls"];
|
|
4142
4651
|
var HOST_FILE_TOOL_NAMES = ["read", "edit", "write", "grep", "find", "ls"];
|
|
@@ -4146,7 +4655,7 @@ var SANDBOX_MEMORY_DIR = "/workspace/memory";
|
|
|
4146
4655
|
function createProtectedSessionShellTools(cwd, runtime, approvalHost, lifecycle) {
|
|
4147
4656
|
const operations = createPreparedDockerBashOperations(runtime, lifecycle);
|
|
4148
4657
|
const modelCwd = codingContainerCwd(runtime.coding?.cwd ?? ".");
|
|
4149
|
-
const base =
|
|
4658
|
+
const base = createBashToolDefinition2(cwd, {
|
|
4150
4659
|
operations: {
|
|
4151
4660
|
exec(command, requestedCwd, options) {
|
|
4152
4661
|
if (requestedCwd !== modelCwd && requestedCwd !== cwd)
|
|
@@ -4155,7 +4664,7 @@ function createProtectedSessionShellTools(cwd, runtime, approvalHost, lifecycle)
|
|
|
4155
4664
|
}
|
|
4156
4665
|
}
|
|
4157
4666
|
});
|
|
4158
|
-
const dockerBash =
|
|
4667
|
+
const dockerBash = defineTool3({
|
|
4159
4668
|
...base,
|
|
4160
4669
|
label: "bash (protected Docker sandbox)",
|
|
4161
4670
|
description: `${base.description} Default working directory: ${codingContainerCwd(runtime.coding?.cwd ?? ".")}. Runs in an ephemeral, network-disabled Docker container with the Team workspace mounted read/write plus only the preflighted read-only memory, skill, and attachment mounts. Host files, host tools, and host credentials are unavailable.`
|
|
@@ -4184,14 +4693,16 @@ function buildSandboxContainerEnv(env, allowlist) {
|
|
|
4184
4693
|
}
|
|
4185
4694
|
function createSessionShellTools(cwd, env, options = {}) {
|
|
4186
4695
|
const config = resolveShellSecurityConfig(env);
|
|
4696
|
+
if (config.sandboxMode === "native")
|
|
4697
|
+
throw new Error("Native coding requires a genuine daemon-admitted native execution host");
|
|
4187
4698
|
if (options.preparedDocker) {
|
|
4188
4699
|
if (config.sandboxMode !== "docker")
|
|
4189
4700
|
throw new Error("Prepared coding environment cannot execute on the host");
|
|
4190
4701
|
const runtime = options.preparedDocker;
|
|
4191
|
-
const base2 =
|
|
4702
|
+
const base2 = createBashToolDefinition2(cwd, {
|
|
4192
4703
|
operations: createPreparedDockerBashOperations(runtime, options.dockerLifecycle)
|
|
4193
4704
|
});
|
|
4194
|
-
const tool =
|
|
4705
|
+
const tool = defineTool3({
|
|
4195
4706
|
...base2,
|
|
4196
4707
|
label: "bash (prepared Docker sandbox)",
|
|
4197
4708
|
description: `${base2.description} Default working directory: ${codingContainerCwd(runtime.coding?.cwd ?? ".")}. Fresh network-disabled Docker container with the Team workspace and preflighted read-only mounts.`
|
|
@@ -4206,7 +4717,7 @@ function createSessionShellTools(cwd, env, options = {}) {
|
|
|
4206
4717
|
return { config, hostToolNames: HOST_CODING_TOOL_NAMES };
|
|
4207
4718
|
}
|
|
4208
4719
|
if (config.sandboxMode === "off") {
|
|
4209
|
-
const base2 =
|
|
4720
|
+
const base2 = createBashToolDefinition2(cwd, {
|
|
4210
4721
|
operations: createLocalBashOperations2()
|
|
4211
4722
|
});
|
|
4212
4723
|
const customBash2 = createApprovalGatedBashTool(base2, options.approvalHost);
|
|
@@ -4224,8 +4735,8 @@ function createSessionShellTools(cwd, env, options = {}) {
|
|
|
4224
4735
|
)
|
|
4225
4736
|
]
|
|
4226
4737
|
});
|
|
4227
|
-
const base =
|
|
4228
|
-
const dockerBash =
|
|
4738
|
+
const base = createBashToolDefinition2(cwd, { operations });
|
|
4739
|
+
const dockerBash = defineTool3({
|
|
4229
4740
|
...base,
|
|
4230
4741
|
label: "bash (Docker sandbox)",
|
|
4231
4742
|
description: `${base.description} Runs in an ephemeral, network-disabled Docker container with the team workspace mounted read/write plus only bounded read-only memory, skill, and attachment mounts. Other host files and host credentials are unavailable.`
|
|
@@ -4250,7 +4761,7 @@ function safeReadOnlyMount(source, target, expectedRoot) {
|
|
|
4250
4761
|
|
|
4251
4762
|
// ../daemon/src/runtime/worker/runtime.ts
|
|
4252
4763
|
import {
|
|
4253
|
-
constants as
|
|
4764
|
+
constants as constants7,
|
|
4254
4765
|
existsSync as existsSync12,
|
|
4255
4766
|
lstatSync as lstatSync6,
|
|
4256
4767
|
mkdirSync as mkdirSync6,
|
|
@@ -4262,6 +4773,39 @@ import {
|
|
|
4262
4773
|
import { access as access2 } from "fs/promises";
|
|
4263
4774
|
import { tmpdir as tmpdir3 } from "os";
|
|
4264
4775
|
import { isAbsolute as isAbsolute6, join as join19, relative as relative5, sep as sep5 } from "path";
|
|
4776
|
+
|
|
4777
|
+
// ../daemon/src/runtime/worker/native-contract.ts
|
|
4778
|
+
import { release } from "os";
|
|
4779
|
+
|
|
4780
|
+
// ../daemon/src/core/coding-environment/native-facts.ts
|
|
4781
|
+
function assertNativeExecutionFacts(value) {
|
|
4782
|
+
const invalid2 = () => new Error("Invalid native runtime facts");
|
|
4783
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || Object.getPrototypeOf(value) !== Object.prototype || Object.keys(value).sort().join(",") !== "architecture,backend,fingerprint,kernelRelease,nodeVersion,policyFingerprint")
|
|
4784
|
+
throw invalid2();
|
|
4785
|
+
const facts = value;
|
|
4786
|
+
if (typeof facts.backend !== "string" || !["linux-bwrap", "darwin-seatbelt"].includes(facts.backend) || typeof facts.architecture !== "string" || !["x64", "arm64"].includes(facts.architecture) || facts.backend === "darwin-seatbelt" && facts.architecture !== "arm64" || typeof facts.nodeVersion !== "string" || !/^v\d+\.\d+\.\d+$/.test(facts.nodeVersion) || facts.nodeVersion.length > 64 || typeof facts.kernelRelease !== "string" || !/^[A-Za-z0-9._+-]{1,128}$/.test(facts.kernelRelease) || typeof facts.fingerprint !== "string" || !/^[0-9a-f]{64}$/.test(facts.fingerprint) || typeof facts.policyFingerprint !== "string" || !/^[0-9a-f]{64}$/.test(facts.policyFingerprint))
|
|
4787
|
+
throw invalid2();
|
|
4788
|
+
}
|
|
4789
|
+
|
|
4790
|
+
// ../daemon/src/runtime/worker/native-contract.ts
|
|
4791
|
+
function assertNativeExecutionAdmission(value) {
|
|
4792
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || Object.keys(value).sort().join(",") !== "cwd,facts")
|
|
4793
|
+
throw new Error("Invalid native worker description");
|
|
4794
|
+
const input = value;
|
|
4795
|
+
codingRelativePath(input.cwd);
|
|
4796
|
+
const facts = input.facts;
|
|
4797
|
+
try {
|
|
4798
|
+
assertNativeExecutionFacts(facts);
|
|
4799
|
+
} catch {
|
|
4800
|
+
throw new Error("Invalid native worker facts");
|
|
4801
|
+
}
|
|
4802
|
+
const fact = facts;
|
|
4803
|
+
const backend = process.platform === "linux" ? "linux-bwrap" : process.platform === "darwin" ? "darwin-seatbelt" : null;
|
|
4804
|
+
if (!backend || !["x64", "arm64"].includes(process.arch) || fact.backend !== backend || fact.architecture !== process.arch || fact.nodeVersion !== process.version || fact.kernelRelease !== release())
|
|
4805
|
+
throw new Error("Native worker facts do not match this runtime");
|
|
4806
|
+
}
|
|
4807
|
+
|
|
4808
|
+
// ../daemon/src/runtime/worker/runtime.ts
|
|
4265
4809
|
var REDACTED_VALUE = "[REDACTED]";
|
|
4266
4810
|
var REASONING_LEVELS2 = /* @__PURE__ */ new Set([
|
|
4267
4811
|
"off",
|
|
@@ -4272,8 +4816,10 @@ var REASONING_LEVELS2 = /* @__PURE__ */ new Set([
|
|
|
4272
4816
|
"xhigh"
|
|
4273
4817
|
]);
|
|
4274
4818
|
var CONFIGURED_KEYS = /* @__PURE__ */ new Set([
|
|
4819
|
+
"nativeVerificationRequestEnabled",
|
|
4275
4820
|
"containerNamespace",
|
|
4276
4821
|
"configuredDocker",
|
|
4822
|
+
"nativeExecution",
|
|
4277
4823
|
"imageGenerationEnabled",
|
|
4278
4824
|
"webSearchEnabled",
|
|
4279
4825
|
"repositoryContext",
|
|
@@ -4303,6 +4849,7 @@ var CONFIGURED_REQUIRED_KEYS = /* @__PURE__ */ new Set([
|
|
|
4303
4849
|
"bashApprovalMode"
|
|
4304
4850
|
]);
|
|
4305
4851
|
var PROTECTED_KEYS = /* @__PURE__ */ new Set([
|
|
4852
|
+
"nativeVerificationRequestEnabled",
|
|
4306
4853
|
"imageGenerationEnabled",
|
|
4307
4854
|
"containerNamespace",
|
|
4308
4855
|
"repositoryContext",
|
|
@@ -4317,6 +4864,7 @@ var PROTECTED_KEYS = /* @__PURE__ */ new Set([
|
|
|
4317
4864
|
"runtime",
|
|
4318
4865
|
"paths",
|
|
4319
4866
|
"docker",
|
|
4867
|
+
"nativeExecution",
|
|
4320
4868
|
"webFetchEnabled",
|
|
4321
4869
|
"webSearchEnabled",
|
|
4322
4870
|
"apiKeyRefreshEnabled",
|
|
@@ -4324,7 +4872,7 @@ var PROTECTED_KEYS = /* @__PURE__ */ new Set([
|
|
|
4324
4872
|
]);
|
|
4325
4873
|
var PROTECTED_REQUIRED_KEYS = new Set(
|
|
4326
4874
|
[...PROTECTED_KEYS].filter(
|
|
4327
|
-
(key) => key !== "images" && key !== "questionEnabled" && key !== "containerNamespace" && key !== "imageGenerationEnabled" && key !== "webSearchEnabled"
|
|
4875
|
+
(key) => key !== "images" && key !== "docker" && key !== "nativeExecution" && key !== "nativeVerificationRequestEnabled" && key !== "questionEnabled" && key !== "containerNamespace" && key !== "imageGenerationEnabled" && key !== "webSearchEnabled"
|
|
4328
4876
|
)
|
|
4329
4877
|
);
|
|
4330
4878
|
var STATIC_REVIEW_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -4390,6 +4938,10 @@ function minimalWorkerProcessEnv(scratch, platform = process.platform, hostEnv =
|
|
|
4390
4938
|
LC_ALL: "C"
|
|
4391
4939
|
};
|
|
4392
4940
|
}
|
|
4941
|
+
function initializeMinimalWorkerProcessEnv(env, scratch, platform = process.platform) {
|
|
4942
|
+
if (platform === "darwin") delete env.__CF_USER_TEXT_ENCODING;
|
|
4943
|
+
validateMinimalWorkerProcessEnv(env, scratch, platform);
|
|
4944
|
+
}
|
|
4393
4945
|
function validateMinimalWorkerProcessEnv(env, scratch, platform = process.platform) {
|
|
4394
4946
|
const expected = minimalWorkerProcessEnv(scratch, platform, env);
|
|
4395
4947
|
const actualKeys = Object.keys(env).sort();
|
|
@@ -4406,6 +4958,8 @@ function validateMinimalWorkerProcessEnv(env, scratch, platform = process.platfo
|
|
|
4406
4958
|
function parseWorkerInput(value) {
|
|
4407
4959
|
const input = objectRecord(value, "worker input");
|
|
4408
4960
|
const kind = input.kind;
|
|
4961
|
+
if (input.nativeVerificationRequestEnabled !== void 0 && (input.nativeVerificationRequestEnabled !== true || input.nativeExecution === void 0 || kind !== "configured_operator_http" && kind !== "protected"))
|
|
4962
|
+
throw new Error("Invalid native verification requester capability");
|
|
4409
4963
|
if (input.containerNamespace !== void 0 && (typeof input.containerNamespace !== "string" || !/^[a-f0-9-]{36}$/.test(input.containerNamespace)))
|
|
4410
4964
|
throw new Error("Invalid container namespace");
|
|
4411
4965
|
if (input.imageGenerationEnabled !== void 0 && typeof input.imageGenerationEnabled !== "boolean")
|
|
@@ -4417,6 +4971,11 @@ function parseWorkerInput(value) {
|
|
|
4417
4971
|
if (kind === "configured_operator_http") {
|
|
4418
4972
|
assertExactKeys(input, CONFIGURED_KEYS, "configured worker input", CONFIGURED_REQUIRED_KEYS);
|
|
4419
4973
|
if (!isResolvedAgent(input.agent)) throw new Error("worker: configured input requires an agent");
|
|
4974
|
+
if (input.nativeExecution !== void 0) {
|
|
4975
|
+
assertNativeExecutionAdmission(input.nativeExecution);
|
|
4976
|
+
if (input.configuredDocker !== void 0 || input.containerNamespace !== void 0)
|
|
4977
|
+
throw new Error("Native worker rejects Docker inputs");
|
|
4978
|
+
}
|
|
4420
4979
|
if (input.configuredDocker !== void 0) {
|
|
4421
4980
|
const prepared = objectRecord(input.configuredDocker, "configured Docker inputs");
|
|
4422
4981
|
const keys2 = /* @__PURE__ */ new Set(["paths", "docker"]);
|
|
@@ -4467,7 +5026,13 @@ function parseWorkerInput(value) {
|
|
|
4467
5026
|
throw new Error("worker: protected runtime does not match the resolved Agent model");
|
|
4468
5027
|
}
|
|
4469
5028
|
assertProtectedWorkerPaths(input.paths, input.agent);
|
|
4470
|
-
|
|
5029
|
+
if (input.nativeExecution !== void 0 === (input.docker !== void 0))
|
|
5030
|
+
throw new Error("Protected worker requires exactly one execution backend");
|
|
5031
|
+
if (input.nativeExecution !== void 0) {
|
|
5032
|
+
assertNativeExecutionAdmission(input.nativeExecution);
|
|
5033
|
+
if (input.containerNamespace !== void 0)
|
|
5034
|
+
throw new Error("Native worker rejects Docker namespace");
|
|
5035
|
+
} else assertProtectedDockerRuntime(input.docker, input.paths);
|
|
4471
5036
|
if (input.apiKeyRefreshEnabled !== true) {
|
|
4472
5037
|
throw new Error("worker: protected input requires bound API key refresh");
|
|
4473
5038
|
}
|
|
@@ -5029,11 +5594,11 @@ function askUserTool(ask) {
|
|
|
5029
5594
|
},
|
|
5030
5595
|
async invoke(args, context) {
|
|
5031
5596
|
if (!context?.toolCallId) throw new Error("Question requires its actual tool call identity");
|
|
5032
|
-
const { receipt, ...
|
|
5597
|
+
const { receipt, ...result2 } = await ask(
|
|
5033
5598
|
context.toolCallId,
|
|
5034
5599
|
args
|
|
5035
5600
|
);
|
|
5036
|
-
const text2 = JSON.stringify(
|
|
5601
|
+
const text2 = JSON.stringify(result2);
|
|
5037
5602
|
return receipt ? { content: [{ type: "text", text: text2 }], questionReceipt: receipt } : text2;
|
|
5038
5603
|
}
|
|
5039
5604
|
};
|
|
@@ -5219,10 +5784,10 @@ function browserTools(host, agentId) {
|
|
|
5219
5784
|
// ../daemon/src/runtime/tools/deliver-file.ts
|
|
5220
5785
|
import {
|
|
5221
5786
|
closeSync as closeSync6,
|
|
5222
|
-
constants as
|
|
5787
|
+
constants as constants8,
|
|
5223
5788
|
fstatSync as fstatSync5,
|
|
5224
5789
|
openSync as openSync6,
|
|
5225
|
-
readSync as
|
|
5790
|
+
readSync as readSync2,
|
|
5226
5791
|
realpathSync as realpathSync9,
|
|
5227
5792
|
statSync as statSync4
|
|
5228
5793
|
} from "fs";
|
|
@@ -5295,7 +5860,7 @@ function deliverFileTool(cwd, sink, sessionId = "") {
|
|
|
5295
5860
|
}
|
|
5296
5861
|
let fd;
|
|
5297
5862
|
try {
|
|
5298
|
-
fd = openSync6(real,
|
|
5863
|
+
fd = openSync6(real, constants8.O_RDONLY | constants8.O_NOFOLLOW | constants8.O_NONBLOCK);
|
|
5299
5864
|
} catch {
|
|
5300
5865
|
throw new Error(`deliver_file: no such file: ${p}`);
|
|
5301
5866
|
}
|
|
@@ -5325,7 +5890,7 @@ function deliverFileTool(cwd, sink, sessionId = "") {
|
|
|
5325
5890
|
const buffer = Buffer.alloc(MAX_DELIVER_BYTES + 1);
|
|
5326
5891
|
let length = 0;
|
|
5327
5892
|
while (length < buffer.length) {
|
|
5328
|
-
const count2 =
|
|
5893
|
+
const count2 = readSync2(fd, buffer, length, buffer.length - length, null);
|
|
5329
5894
|
if (count2 === 0) break;
|
|
5330
5895
|
length += count2;
|
|
5331
5896
|
}
|
|
@@ -5338,7 +5903,7 @@ function deliverFileTool(cwd, sink, sessionId = "") {
|
|
|
5338
5903
|
const mimeType = MIME[extname(abs).toLowerCase()] ?? "application/octet-stream";
|
|
5339
5904
|
if (!context?.toolCallId || !sessionId)
|
|
5340
5905
|
throw new Error("deliver_file: missing source operation");
|
|
5341
|
-
const
|
|
5906
|
+
const result2 = await sink(
|
|
5342
5907
|
{ name, mimeType, data },
|
|
5343
5908
|
{ sessionId, toolCallId: context.toolCallId }
|
|
5344
5909
|
);
|
|
@@ -5346,10 +5911,10 @@ function deliverFileTool(cwd, sink, sessionId = "") {
|
|
|
5346
5911
|
content: [
|
|
5347
5912
|
{
|
|
5348
5913
|
type: "text",
|
|
5349
|
-
text: `Saved "${name}" (${mimeType}) as result ${
|
|
5914
|
+
text: `Saved "${name}" (${mimeType}) as result ${result2.resultId}. Delivery is subject to Team Policy.`
|
|
5350
5915
|
}
|
|
5351
5916
|
],
|
|
5352
|
-
result
|
|
5917
|
+
result: result2
|
|
5353
5918
|
};
|
|
5354
5919
|
}
|
|
5355
5920
|
};
|
|
@@ -5358,7 +5923,7 @@ function deliverFileTool(cwd, sink, sessionId = "") {
|
|
|
5358
5923
|
// ../daemon/src/runtime/tools/home.ts
|
|
5359
5924
|
import {
|
|
5360
5925
|
closeSync as closeSync7,
|
|
5361
|
-
constants as
|
|
5926
|
+
constants as constants9,
|
|
5362
5927
|
fstatSync as fstatSync6,
|
|
5363
5928
|
lstatSync as lstatSync7,
|
|
5364
5929
|
openSync as openSync7,
|
|
@@ -5432,7 +5997,7 @@ function homeTools(agentDir) {
|
|
|
5432
5997
|
rejectExistingSymlinkOrNonFile(path);
|
|
5433
5998
|
fd = openSync7(
|
|
5434
5999
|
path,
|
|
5435
|
-
|
|
6000
|
+
constants9.O_WRONLY | constants9.O_CREAT | constants9.O_TRUNC | noFollowFlag(),
|
|
5436
6001
|
384
|
|
5437
6002
|
);
|
|
5438
6003
|
if (!fstatSync6(fd).isFile()) throw new Error("target is not a regular file");
|
|
@@ -5859,14 +6424,14 @@ function reviewTools(host) {
|
|
|
5859
6424
|
if (!SEVERITIES.includes(severity)) {
|
|
5860
6425
|
throw new ReviewCapabilityError(`severity must be one of: ${SEVERITIES.join(", ")}`);
|
|
5861
6426
|
}
|
|
5862
|
-
const
|
|
6427
|
+
const result2 = await host.addFinding({
|
|
5863
6428
|
path,
|
|
5864
6429
|
severity,
|
|
5865
6430
|
note,
|
|
5866
6431
|
lineStart: readLine(args.lineStart),
|
|
5867
6432
|
lineEnd: readLine(args.lineEnd)
|
|
5868
6433
|
});
|
|
5869
|
-
return `Finding ${
|
|
6434
|
+
return `Finding ${result2.findingId} recorded as [${String(severity)}] on ${path} (finding ${result2.ordinal}). Nothing was executed and nothing was changed.`;
|
|
5870
6435
|
}
|
|
5871
6436
|
};
|
|
5872
6437
|
const conclusionTool = {
|
|
@@ -5892,11 +6457,11 @@ function reviewTools(host) {
|
|
|
5892
6457
|
if (!CONCLUSIONS.includes(conclusion)) {
|
|
5893
6458
|
throw new ReviewCapabilityError(`conclusion must be one of: ${CONCLUSIONS.join(", ")}`);
|
|
5894
6459
|
}
|
|
5895
|
-
const
|
|
6460
|
+
const result2 = await host.conclude({
|
|
5896
6461
|
conclusion,
|
|
5897
6462
|
note: typeof args.note === "string" ? args.note : null
|
|
5898
6463
|
});
|
|
5899
|
-
return `Conclusion recorded: ${
|
|
6464
|
+
return `Conclusion recorded: ${result2.conclusion}. The review is complete; the requester learns the outcome.`;
|
|
5900
6465
|
}
|
|
5901
6466
|
};
|
|
5902
6467
|
return [packetTool, pathTool, findingTool, conclusionTool];
|
|
@@ -6519,7 +7084,7 @@ async function guardedFetch(opts) {
|
|
|
6519
7084
|
let redirects = 0;
|
|
6520
7085
|
let dispatcher = null;
|
|
6521
7086
|
let activeResponse = null;
|
|
6522
|
-
const
|
|
7087
|
+
const release2 = async () => {
|
|
6523
7088
|
if (!activeResponse?.body?.locked) await activeResponse?.body?.cancel().catch(() => {
|
|
6524
7089
|
});
|
|
6525
7090
|
if (timeoutId) clearTimeout(timeoutId);
|
|
@@ -6531,11 +7096,11 @@ async function guardedFetch(opts) {
|
|
|
6531
7096
|
try {
|
|
6532
7097
|
parsed = new URL(current);
|
|
6533
7098
|
} catch {
|
|
6534
|
-
await
|
|
7099
|
+
await release2();
|
|
6535
7100
|
throw new Error("Invalid URL");
|
|
6536
7101
|
}
|
|
6537
7102
|
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
6538
|
-
await
|
|
7103
|
+
await release2();
|
|
6539
7104
|
throw new Error("Invalid URL: must be http or https");
|
|
6540
7105
|
}
|
|
6541
7106
|
const canPin = !opts.fetchImpl;
|
|
@@ -6544,7 +7109,7 @@ async function guardedFetch(opts) {
|
|
|
6544
7109
|
try {
|
|
6545
7110
|
addrs = await resolveAndCheck(parsed.hostname);
|
|
6546
7111
|
} catch (error) {
|
|
6547
|
-
await
|
|
7112
|
+
await release2();
|
|
6548
7113
|
throw error;
|
|
6549
7114
|
}
|
|
6550
7115
|
await closeDispatcher(dispatcher);
|
|
@@ -6590,7 +7155,7 @@ async function guardedFetch(opts) {
|
|
|
6590
7155
|
res = opts.admitFetch ? await opts.admitFetch(parsed.toString(), perform) : await perform();
|
|
6591
7156
|
activeResponse = res;
|
|
6592
7157
|
} catch (err) {
|
|
6593
|
-
await
|
|
7158
|
+
await release2();
|
|
6594
7159
|
throw err;
|
|
6595
7160
|
}
|
|
6596
7161
|
if (isRedirectStatus(res.status)) {
|
|
@@ -6598,23 +7163,23 @@ async function guardedFetch(opts) {
|
|
|
6598
7163
|
});
|
|
6599
7164
|
const loc = res.headers.get("location");
|
|
6600
7165
|
if (!loc) {
|
|
6601
|
-
await
|
|
7166
|
+
await release2();
|
|
6602
7167
|
throw new Error(`Redirect ${res.status} missing Location header`);
|
|
6603
7168
|
}
|
|
6604
7169
|
redirects += 1;
|
|
6605
7170
|
if (redirects > maxRedirects) {
|
|
6606
|
-
await
|
|
7171
|
+
await release2();
|
|
6607
7172
|
throw new Error(`Too many redirects (> ${maxRedirects})`);
|
|
6608
7173
|
}
|
|
6609
7174
|
let next;
|
|
6610
7175
|
try {
|
|
6611
7176
|
next = new URL(loc, parsed).toString();
|
|
6612
7177
|
} catch {
|
|
6613
|
-
await
|
|
7178
|
+
await release2();
|
|
6614
7179
|
throw new Error("Invalid redirect Location");
|
|
6615
7180
|
}
|
|
6616
7181
|
if (visited.has(next)) {
|
|
6617
|
-
await
|
|
7182
|
+
await release2();
|
|
6618
7183
|
throw new Error("Redirect loop");
|
|
6619
7184
|
}
|
|
6620
7185
|
visited.add(next);
|
|
@@ -6627,7 +7192,7 @@ async function guardedFetch(opts) {
|
|
|
6627
7192
|
current = next;
|
|
6628
7193
|
continue;
|
|
6629
7194
|
}
|
|
6630
|
-
return { response: res, finalUrl: parsed.toString(), release };
|
|
7195
|
+
return { response: res, finalUrl: parsed.toString(), release: release2 };
|
|
6631
7196
|
}
|
|
6632
7197
|
}
|
|
6633
7198
|
|
|
@@ -6946,9 +7511,9 @@ function buildWebTools(opts, includeSearch) {
|
|
|
6946
7511
|
const cacheKey = `${mode}|${url}`;
|
|
6947
7512
|
const cached = cacheGet(cache, cacheKey);
|
|
6948
7513
|
if (cached) return formatFetched(cached, maxLen, !!opts?.sourceReceipt, true);
|
|
6949
|
-
let
|
|
7514
|
+
let result2 = null;
|
|
6950
7515
|
try {
|
|
6951
|
-
|
|
7516
|
+
result2 = await guardedFetch({
|
|
6952
7517
|
url,
|
|
6953
7518
|
fetchImpl: opts?.fetchImpl,
|
|
6954
7519
|
admitFetch: opts?.admitFetch,
|
|
@@ -6964,16 +7529,16 @@ function buildWebTools(opts, includeSearch) {
|
|
|
6964
7529
|
}
|
|
6965
7530
|
}
|
|
6966
7531
|
});
|
|
6967
|
-
if (!
|
|
6968
|
-
throw new Error(`${
|
|
7532
|
+
if (!result2.response.ok) {
|
|
7533
|
+
throw new Error(`${result2.response.status} ${result2.response.statusText}`);
|
|
6969
7534
|
}
|
|
6970
|
-
const ct =
|
|
7535
|
+
const ct = result2.response.headers.get("content-type") ?? "";
|
|
6971
7536
|
const isHtml = ct.includes("text/html") || ct.includes("xhtml");
|
|
6972
|
-
const { text: body, truncated } = await readBodyCapped(
|
|
7537
|
+
const { text: body, truncated } = await readBodyCapped(result2.response, maxBodyBytes);
|
|
6973
7538
|
let extracted;
|
|
6974
7539
|
let renderer = "direct";
|
|
6975
7540
|
if (isHtml) {
|
|
6976
|
-
extracted = extractReadable(body,
|
|
7541
|
+
extracted = extractReadable(body, result2.finalUrl, mode);
|
|
6977
7542
|
} else if (ct.includes("application/json")) {
|
|
6978
7543
|
try {
|
|
6979
7544
|
extracted = { text: JSON.stringify(JSON.parse(body), null, 2) };
|
|
@@ -6984,7 +7549,7 @@ function buildWebTools(opts, includeSearch) {
|
|
|
6984
7549
|
extracted = { text: body };
|
|
6985
7550
|
}
|
|
6986
7551
|
if (isHtml && !firecrawlDisabled && extracted.text.length < FIRECRAWL_FALLBACK_THRESHOLD) {
|
|
6987
|
-
const rescued = await firecrawlScrape(
|
|
7552
|
+
const rescued = await firecrawlScrape(result2.finalUrl, mode, env, fetchFn, timeoutMs);
|
|
6988
7553
|
if (rescued) {
|
|
6989
7554
|
renderer = "firecrawl";
|
|
6990
7555
|
extracted = {
|
|
@@ -7004,14 +7569,14 @@ function buildWebTools(opts, includeSearch) {
|
|
|
7004
7569
|
};
|
|
7005
7570
|
}
|
|
7006
7571
|
if (opts?.sourceReceipt) {
|
|
7007
|
-
if (Buffer.byteLength(
|
|
7572
|
+
if (Buffer.byteLength(result2.finalUrl) > 2048)
|
|
7008
7573
|
throw new Error("web_fetch: effective URL exceeds the 2 KiB evidence bound");
|
|
7009
7574
|
extracted.receipt = {
|
|
7010
7575
|
requestedUrl: url,
|
|
7011
|
-
finalUrl: renderer === "direct" ?
|
|
7012
|
-
status: renderer === "direct" ?
|
|
7576
|
+
finalUrl: renderer === "direct" ? result2.finalUrl : null,
|
|
7577
|
+
status: renderer === "direct" ? result2.response.status : null,
|
|
7013
7578
|
...renderer === "firecrawl" ? {
|
|
7014
|
-
directFetch: { finalUrl:
|
|
7579
|
+
directFetch: { finalUrl: result2.finalUrl, status: result2.response.status },
|
|
7015
7580
|
rendererReported: extracted.rendererReported ?? { url: null, status: null }
|
|
7016
7581
|
} : {},
|
|
7017
7582
|
fetchedAt: Date.now(),
|
|
@@ -7026,7 +7591,7 @@ function buildWebTools(opts, includeSearch) {
|
|
|
7026
7591
|
if (err instanceof SsrFBlockedError) throw new Error(`web_fetch: ${err.message}`);
|
|
7027
7592
|
throw new Error(`web_fetch: ${describeError(err)}`);
|
|
7028
7593
|
} finally {
|
|
7029
|
-
if (
|
|
7594
|
+
if (result2) await result2.release();
|
|
7030
7595
|
}
|
|
7031
7596
|
}
|
|
7032
7597
|
});
|
|
@@ -7171,11 +7736,22 @@ function createProtectedBazilionCustomTools(opts) {
|
|
|
7171
7736
|
// ../daemon/src/runtime/pi/session.ts
|
|
7172
7737
|
var PROTECTED_MODEL_CWD = "/workspace";
|
|
7173
7738
|
var REVIEW_MODEL_CWD = "/review";
|
|
7739
|
+
var PROTECTED_NATIVE_BASE_SYSTEM_PROMPT = `You are an assistant operating inside Bazilion's protected
|
|
7740
|
+
Agent runtime. Use only the tools exposed for this turn. Coding commands execute through the
|
|
7741
|
+
daemon-admitted native OS sandbox in the Team workspace. Team memory and admitted inputs are
|
|
7742
|
+
read-only. TCP/UDP, including localhost, are denied; pipes and private per-job pathname Unix IPC
|
|
7743
|
+
are available. Direct host coding tools, Docker and VM fallback are unavailable. Show the native
|
|
7744
|
+
workspace paths clearly and report missing tools or unavailable protection rather than bypassing it.`;
|
|
7174
7745
|
var PROTECTED_BASE_SYSTEM_PROMPT = `You are an assistant operating inside Bazilion's protected
|
|
7175
7746
|
Agent runtime. Use only the tools exposed for this turn. Coding commands execute in an ephemeral,
|
|
7176
7747
|
network-disabled Docker container whose Team workspace is /workspace. Host paths and host tools are
|
|
7177
7748
|
not available. Be concise and show container paths clearly when working with files.`;
|
|
7178
7749
|
async function createBazilionSession(opts) {
|
|
7750
|
+
if (process.platform === "darwin" && opts.nativeExecution !== void 0)
|
|
7751
|
+
throw new Error(MAC_NATIVE_EXECUTION_UNAVAILABLE);
|
|
7752
|
+
const native = opts.nativeExecution === void 0 ? void 0 : snapshotNativeSessionExecution(opts.nativeExecution);
|
|
7753
|
+
if (native && (opts.restricted || opts.preparedDocker || opts.dockerLifecycle || resolveShellSecurityConfig(opts.env).sandboxMode === "docker"))
|
|
7754
|
+
throw new Error("Native session rejects another execution backend or restricted mode");
|
|
7179
7755
|
const {
|
|
7180
7756
|
agent,
|
|
7181
7757
|
paths,
|
|
@@ -7207,11 +7783,15 @@ async function createBazilionSession(opts) {
|
|
|
7207
7783
|
modelId
|
|
7208
7784
|
});
|
|
7209
7785
|
const model = resolvePiModel(modelRuntime, providerName, modelId, baseUrl);
|
|
7210
|
-
const cwd = agent.team.path;
|
|
7786
|
+
const cwd = native ? realpathSync10(agent.team.path) : agent.team.path;
|
|
7787
|
+
const modelCwd = native ? join22(cwd, native.cwd) : cwd;
|
|
7211
7788
|
if (!existsSync14(cwd)) mkdirSync7(cwd, { recursive: true });
|
|
7212
7789
|
const promptSkills = restricted ? [] : loadPromptSkills(paths.skillsDir, agent.skills);
|
|
7213
7790
|
const uploadsDir = join22(agent.agent.dir, "uploads");
|
|
7214
|
-
const shellTools = restricted ? null :
|
|
7791
|
+
const shellTools = restricted ? null : native ? {
|
|
7792
|
+
...createNativeSessionShellTools(modelCwd, native.cwd, native.host),
|
|
7793
|
+
config: { sandboxMode: "native", approvalMode: "dangerous" }
|
|
7794
|
+
} : createSessionShellTools(cwd, env, {
|
|
7215
7795
|
preparedDocker: opts.preparedDocker,
|
|
7216
7796
|
dockerLifecycle: opts.dockerLifecycle,
|
|
7217
7797
|
...existsSync14(uploadsDir) ? { inputsDir: uploadsDir } : {},
|
|
@@ -7224,7 +7804,7 @@ async function createBazilionSession(opts) {
|
|
|
7224
7804
|
const sessionDir = restricted?.sessionDir ?? join22(paths.agentDir(agent.agent.id), "sessions");
|
|
7225
7805
|
mkdirSync7(sessionDir, { recursive: true });
|
|
7226
7806
|
const existing = restricted ? null : explicitConversationFile(sessionDir, opts.conversation);
|
|
7227
|
-
const sessionManager = existing ? SessionManager.open(existing, sessionDir,
|
|
7807
|
+
const sessionManager = existing ? SessionManager.open(existing, sessionDir, modelCwd) : SessionManager.create(modelCwd, sessionDir);
|
|
7228
7808
|
const settingsManager = SettingsManager.inMemory({
|
|
7229
7809
|
// Auxiliary provider requests must be explicitly admitted by Bazilion, not idle/streaming warming.
|
|
7230
7810
|
cacheWarming: "off",
|
|
@@ -7239,6 +7819,7 @@ async function createBazilionSession(opts) {
|
|
|
7239
7819
|
const bazilionPrompt = restricted?.systemPrompt ?? buildSystemPrompt(agent, {
|
|
7240
7820
|
skills: promptSkills,
|
|
7241
7821
|
sandboxMode: shellTools?.config.sandboxMode ?? "off",
|
|
7822
|
+
...native ? { modelWorkspace: cwd } : {},
|
|
7242
7823
|
// Guide iff the browser tools are admitted — the same host presence
|
|
7243
7824
|
// that registers `browser_*` in createBazilionCustomTools (T10).
|
|
7244
7825
|
...opts.browserHost ? { browserGuide: true } : {},
|
|
@@ -7250,7 +7831,7 @@ async function createBazilionSession(opts) {
|
|
|
7250
7831
|
shellTools?.config.sandboxMode === "docker" ? "/workspace" : cwd
|
|
7251
7832
|
) : void 0;
|
|
7252
7833
|
const resourceLoader = new DefaultResourceLoader({
|
|
7253
|
-
cwd,
|
|
7834
|
+
cwd: modelCwd,
|
|
7254
7835
|
agentDir: join22(paths.home, "pi"),
|
|
7255
7836
|
settingsManager,
|
|
7256
7837
|
noExtensions: true,
|
|
@@ -7290,6 +7871,7 @@ async function createBazilionSession(opts) {
|
|
|
7290
7871
|
root: cwd,
|
|
7291
7872
|
context: repository.resolve,
|
|
7292
7873
|
docker: opts.preparedDocker,
|
|
7874
|
+
native: native?.host,
|
|
7293
7875
|
lifecycle: opts.dockerLifecycle,
|
|
7294
7876
|
approval: shellTools.config.approvalMode === "dangerous",
|
|
7295
7877
|
approvalHost: bashApprovalHost,
|
|
@@ -7299,7 +7881,7 @@ async function createBazilionSession(opts) {
|
|
|
7299
7881
|
const customTools = shellTools?.customBash ? [...bazilionTools, shellTools.customBash] : bazilionTools;
|
|
7300
7882
|
const allowedTools = [...shellTools?.hostToolNames ?? [], ...customTools.map((t) => t.name)];
|
|
7301
7883
|
const { session } = await createAgentSession({
|
|
7302
|
-
cwd,
|
|
7884
|
+
cwd: modelCwd,
|
|
7303
7885
|
agentDir: join22(paths.home, "pi"),
|
|
7304
7886
|
model,
|
|
7305
7887
|
thinkingLevel: toPiThinkingLevel(restricted?.reasoningLevel ?? agent.reasoningLevel),
|
|
@@ -7331,6 +7913,10 @@ async function createBazilionSession(opts) {
|
|
|
7331
7913
|
};
|
|
7332
7914
|
}
|
|
7333
7915
|
async function createProtectedBazilionSession(opts) {
|
|
7916
|
+
if (process.platform === "darwin") throw new Error(MAC_PROTECTED_EXECUTION_UNAVAILABLE);
|
|
7917
|
+
const native = opts.nativeExecution === void 0 ? void 0 : snapshotNativeSessionExecution(opts.nativeExecution);
|
|
7918
|
+
if (Boolean(native) === Boolean(opts.docker) || native && opts.dockerLifecycle)
|
|
7919
|
+
throw new Error("Protected session requires exactly one execution backend");
|
|
7334
7920
|
const { providerName, modelId } = splitModelString(opts.agent.model);
|
|
7335
7921
|
if (providerName !== opts.runtime.providerName || modelId !== opts.runtime.modelId) {
|
|
7336
7922
|
throw new Error("protected Agent model does not match the prepared provider runtime");
|
|
@@ -7354,21 +7940,33 @@ async function createProtectedBazilionSession(opts) {
|
|
|
7354
7940
|
opts.runtime.modelId,
|
|
7355
7941
|
opts.runtime.baseUrl
|
|
7356
7942
|
);
|
|
7357
|
-
const
|
|
7358
|
-
|
|
7359
|
-
|
|
7360
|
-
|
|
7361
|
-
|
|
7362
|
-
|
|
7363
|
-
|
|
7943
|
+
const nativeRoot = native ? realpathSync10(opts.paths.teamDir) : opts.paths.teamDir;
|
|
7944
|
+
const docker = opts.docker;
|
|
7945
|
+
let shellTools;
|
|
7946
|
+
let modelCwd;
|
|
7947
|
+
if (native) {
|
|
7948
|
+
modelCwd = join22(nativeRoot, native.cwd);
|
|
7949
|
+
shellTools = createNativeSessionShellTools(modelCwd, native.cwd, native.host);
|
|
7950
|
+
} else if (docker) {
|
|
7951
|
+
modelCwd = codingContainerCwd(docker.coding?.cwd ?? ".");
|
|
7952
|
+
shellTools = createProtectedSessionShellTools(
|
|
7953
|
+
opts.paths.teamDir,
|
|
7954
|
+
docker,
|
|
7955
|
+
opts.bashApprovalHost,
|
|
7956
|
+
opts.dockerLifecycle
|
|
7957
|
+
);
|
|
7958
|
+
} else {
|
|
7959
|
+
throw new Error("Protected execution backend is unavailable");
|
|
7960
|
+
}
|
|
7364
7961
|
mkdirSync7(opts.paths.sessionDir, { recursive: true });
|
|
7365
7962
|
const existing = explicitConversationFile(opts.paths.sessionDir, opts.conversation);
|
|
7366
|
-
const sessionManager = existing ? SessionManager.open(existing, opts.paths.sessionDir, opts.paths.teamDir) : SessionManager.create(opts.paths.teamDir, opts.paths.sessionDir);
|
|
7963
|
+
const sessionManager = existing ? SessionManager.open(existing, opts.paths.sessionDir, native ? modelCwd : opts.paths.teamDir) : SessionManager.create(native ? modelCwd : opts.paths.teamDir, opts.paths.sessionDir);
|
|
7367
7964
|
const settingsManager = createInMemorySettingsManager();
|
|
7368
7965
|
const bazilionPrompt = redactJsonValue(
|
|
7369
7966
|
buildSystemPrompt(opts.agent, {
|
|
7370
7967
|
skills: opts.paths.skills,
|
|
7371
|
-
sandboxMode: "docker",
|
|
7968
|
+
sandboxMode: native ? "native" : "docker",
|
|
7969
|
+
...native ? { modelWorkspace: nativeRoot } : {},
|
|
7372
7970
|
homeDocuments: opts.paths.homeDocuments
|
|
7373
7971
|
}),
|
|
7374
7972
|
protectedRuntimeSecrets(opts.runtime)
|
|
@@ -7376,7 +7974,7 @@ async function createProtectedBazilionSession(opts) {
|
|
|
7376
7974
|
const repository = opts.repositoryContext && opts.repositoryContextHost ? repositoryContextIntegration(
|
|
7377
7975
|
redactJsonValue(opts.repositoryContext, protectedRuntimeSecrets(opts.runtime)),
|
|
7378
7976
|
opts.repositoryContextHost,
|
|
7379
|
-
PROTECTED_MODEL_CWD
|
|
7977
|
+
native ? nativeRoot : PROTECTED_MODEL_CWD
|
|
7380
7978
|
) : void 0;
|
|
7381
7979
|
const resourceLoader = new DefaultResourceLoader({
|
|
7382
7980
|
cwd: modelCwd,
|
|
@@ -7387,7 +7985,7 @@ async function createProtectedBazilionSession(opts) {
|
|
|
7387
7985
|
noPromptTemplates: true,
|
|
7388
7986
|
noThemes: true,
|
|
7389
7987
|
noContextFiles: true,
|
|
7390
|
-
systemPrompt: PROTECTED_BASE_SYSTEM_PROMPT,
|
|
7988
|
+
systemPrompt: native ? PROTECTED_NATIVE_BASE_SYSTEM_PROMPT : PROTECTED_BASE_SYSTEM_PROMPT,
|
|
7391
7989
|
appendSystemPrompt: bazilionPrompt ? [bazilionPrompt] : void 0
|
|
7392
7990
|
});
|
|
7393
7991
|
if (repository) resourceLoader.getAgentsFiles = repository.files;
|
|
@@ -7411,16 +8009,17 @@ async function createProtectedBazilionSession(opts) {
|
|
|
7411
8009
|
bazilionTools.push(
|
|
7412
8010
|
...codingTools({
|
|
7413
8011
|
host: opts.codingHost,
|
|
7414
|
-
root: opts.paths.teamDir,
|
|
8012
|
+
root: nativeRoot ?? opts.paths.teamDir,
|
|
7415
8013
|
context: repository.resolve,
|
|
7416
|
-
docker
|
|
8014
|
+
docker,
|
|
8015
|
+
native: native?.host,
|
|
7417
8016
|
lifecycle: opts.dockerLifecycle,
|
|
7418
8017
|
approval: true,
|
|
7419
8018
|
approvalHost: opts.bashApprovalHost,
|
|
7420
8019
|
secrets: () => redactionSecrets
|
|
7421
8020
|
})
|
|
7422
8021
|
);
|
|
7423
|
-
if (!shellTools.customBash) throw new Error("protected
|
|
8022
|
+
if (!shellTools.customBash) throw new Error("protected bash tool is unavailable");
|
|
7424
8023
|
const customTools = [...bazilionTools, shellTools.customBash];
|
|
7425
8024
|
const { session } = await createAgentSession({
|
|
7426
8025
|
cwd: modelCwd,
|
|
@@ -7572,7 +8171,7 @@ function installProtectedCredentialBoundary(session, providerName, activeTokens,
|
|
|
7572
8171
|
};
|
|
7573
8172
|
};
|
|
7574
8173
|
session.agent.getApiKey = async (requestedProvider) => {
|
|
7575
|
-
if (requestedProvider !== providerName) return void 0;
|
|
8174
|
+
if (requestedProvider !== piProviderName(providerName)) return void 0;
|
|
7576
8175
|
try {
|
|
7577
8176
|
const token = await refreshApiKey(providerName);
|
|
7578
8177
|
if (token && !activeTokens.includes(token)) activeTokens.push(token);
|
|
@@ -7663,56 +8262,63 @@ function assertSelectedProvider(requested, expected) {
|
|
|
7663
8262
|
}
|
|
7664
8263
|
}
|
|
7665
8264
|
|
|
7666
|
-
// ../daemon/src/runtime/worker/
|
|
7667
|
-
|
|
7668
|
-
|
|
7669
|
-
|
|
7670
|
-
|
|
7671
|
-
|
|
7672
|
-
|
|
7673
|
-
|
|
7674
|
-
|
|
7675
|
-
|
|
7676
|
-
|
|
7677
|
-
|
|
7678
|
-
|
|
7679
|
-
|
|
7680
|
-
|
|
7681
|
-
|
|
7682
|
-
|
|
7683
|
-
|
|
7684
|
-
|
|
7685
|
-
|
|
7686
|
-
|
|
7687
|
-
|
|
7688
|
-
|
|
7689
|
-
|
|
7690
|
-
|
|
7691
|
-
|
|
7692
|
-
|
|
7693
|
-
|
|
7694
|
-
|
|
7695
|
-
|
|
7696
|
-
|
|
7697
|
-
|
|
8265
|
+
// ../daemon/src/runtime/worker/cancellation.ts
|
|
8266
|
+
function workerFailureMessage(message, cancellationSignalled) {
|
|
8267
|
+
return cancellationSignalled && [
|
|
8268
|
+
"aborted",
|
|
8269
|
+
"AbortError",
|
|
8270
|
+
"This operation was aborted",
|
|
8271
|
+
"The operation was aborted.",
|
|
8272
|
+
"The user aborted a request.",
|
|
8273
|
+
"Request was aborted",
|
|
8274
|
+
"Request was aborted."
|
|
8275
|
+
].includes(message) ? "cancelled" : message;
|
|
8276
|
+
}
|
|
8277
|
+
|
|
8278
|
+
// ../daemon/src/runtime/worker/native-execution-client.ts
|
|
8279
|
+
function result(value) {
|
|
8280
|
+
if (!value || typeof value !== "object" || Object.keys(value).sort().join(",") !== "code,signal,stderrTruncated,stdoutTruncated")
|
|
8281
|
+
throw new Error("Invalid native execution reply");
|
|
8282
|
+
const item = value;
|
|
8283
|
+
if (item.code !== null && (!Number.isInteger(item.code) || Number(item.code) < 0 || Number(item.code) > 255) || item.signal !== null && (typeof item.signal !== "string" || !/^SIG[A-Z0-9]+$/.test(item.signal) || item.signal.length > 32) || typeof item.stdoutTruncated !== "boolean" || typeof item.stderrTruncated !== "boolean")
|
|
8284
|
+
throw new Error("Invalid native execution reply");
|
|
8285
|
+
}
|
|
8286
|
+
function createIpcNativeExecutionHost(call) {
|
|
8287
|
+
return {
|
|
8288
|
+
cancel() {
|
|
8289
|
+
throw new Error("worker native cancellation must stay correlated with its invocation");
|
|
8290
|
+
},
|
|
8291
|
+
async exec(input, output2, signal) {
|
|
8292
|
+
const request = Object.freeze({ ...input });
|
|
8293
|
+
signal?.throwIfAborted();
|
|
8294
|
+
const cancel = () => {
|
|
8295
|
+
void call("nativeCancel", { toolCallId: request.toolCallId }).catch(() => {
|
|
8296
|
+
});
|
|
8297
|
+
};
|
|
8298
|
+
signal?.addEventListener("abort", cancel, { once: true });
|
|
7698
8299
|
try {
|
|
7699
|
-
|
|
7700
|
-
|
|
7701
|
-
|
|
7702
|
-
|
|
8300
|
+
signal?.throwIfAborted();
|
|
8301
|
+
const value = await call("nativeExecute", request, {
|
|
8302
|
+
onNativeOutput(part) {
|
|
8303
|
+
try {
|
|
8304
|
+
output2(part.stream, Buffer.from(part.data, "base64"), {
|
|
8305
|
+
observedBytes: part.observedBytes,
|
|
8306
|
+
redacted: part.redacted
|
|
8307
|
+
});
|
|
8308
|
+
} catch (error) {
|
|
8309
|
+
cancel();
|
|
8310
|
+
throw error;
|
|
8311
|
+
}
|
|
8312
|
+
}
|
|
7703
8313
|
});
|
|
7704
|
-
|
|
7705
|
-
|
|
7706
|
-
|
|
8314
|
+
result(value);
|
|
8315
|
+
return value;
|
|
8316
|
+
} finally {
|
|
8317
|
+
signal?.removeEventListener("abort", cancel);
|
|
7707
8318
|
}
|
|
7708
|
-
}
|
|
8319
|
+
}
|
|
7709
8320
|
};
|
|
7710
8321
|
}
|
|
7711
|
-
function isIpcReply(message) {
|
|
7712
|
-
if (!message || typeof message !== "object") return false;
|
|
7713
|
-
const candidate = message;
|
|
7714
|
-
return candidate.type === "rpc-reply" && typeof candidate.id === "string" && typeof candidate.ok === "boolean";
|
|
7715
|
-
}
|
|
7716
8322
|
|
|
7717
8323
|
// ../daemon/src/runtime/worker/output.ts
|
|
7718
8324
|
var WORKER_OUTPUT_DRAIN_MS = 2e3;
|
|
@@ -7853,7 +8459,7 @@ function createIpcMcpHost(call) {
|
|
|
7853
8459
|
function createIpcBashApprovalHost(call, input) {
|
|
7854
8460
|
return {
|
|
7855
8461
|
async requestApproval(request) {
|
|
7856
|
-
const
|
|
8462
|
+
const result2 = await call("bashApproval", {
|
|
7857
8463
|
id: randomUUID21(),
|
|
7858
8464
|
turnId: input.turnId,
|
|
7859
8465
|
toolCallId: request.toolCallId,
|
|
@@ -7863,7 +8469,7 @@ function createIpcBashApprovalHost(call, input) {
|
|
|
7863
8469
|
risks: [...request.risks],
|
|
7864
8470
|
mode: input.mode
|
|
7865
8471
|
});
|
|
7866
|
-
return
|
|
8472
|
+
return result2.decision === "allow" ? "approved" : "denied";
|
|
7867
8473
|
}
|
|
7868
8474
|
};
|
|
7869
8475
|
}
|
|
@@ -7991,6 +8597,7 @@ async function createSessionForInput(input, ipcCall) {
|
|
|
7991
8597
|
}) : void 0;
|
|
7992
8598
|
const handle2 = await createBazilionSession({
|
|
7993
8599
|
agent: input.agent,
|
|
8600
|
+
nativeExecution: input.nativeExecution ? { cwd: input.nativeExecution.cwd, host: createIpcNativeExecutionHost(ipcCall) } : void 0,
|
|
7994
8601
|
preparedDocker: input.configuredDocker?.docker,
|
|
7995
8602
|
dockerLifecycle: createIpcDockerLifecycle(input.containerNamespace, ipcCall),
|
|
7996
8603
|
conversation: input.conversation,
|
|
@@ -8005,7 +8612,7 @@ async function createSessionForInput(input, ipcCall) {
|
|
|
8005
8612
|
userMdHost: userMdHost2,
|
|
8006
8613
|
// The requester's halves of specialist verification and review. Only the configured/browser-enabled
|
|
8007
8614
|
// worker kind reaches this builder, and it is an ordinary coding turn.
|
|
8008
|
-
verificationRequestHost: createIpcVerificationRequestHost(ipcCall),
|
|
8615
|
+
verificationRequestHost: !input.nativeExecution || input.nativeVerificationRequestEnabled ? createIpcVerificationRequestHost(ipcCall) : void 0,
|
|
8009
8616
|
reviewRequestHost: createIpcReviewRequestHost(ipcCall),
|
|
8010
8617
|
imageGenerationHost,
|
|
8011
8618
|
webSearchHost,
|
|
@@ -8017,12 +8624,12 @@ async function createSessionForInput(input, ipcCall) {
|
|
|
8017
8624
|
bashApprovalHost: bashApprovalHost2,
|
|
8018
8625
|
askUser: input.questionEnabled ? (toolCallId, question) => ipcCall("askUser", { toolCallId, question }) : void 0,
|
|
8019
8626
|
fileSink: async (file, source) => {
|
|
8020
|
-
const
|
|
8627
|
+
const result2 = await ipcCall(
|
|
8021
8628
|
"publishResult",
|
|
8022
8629
|
{ ...file, ...source }
|
|
8023
8630
|
);
|
|
8024
|
-
emit({ kind: "event", event: { type: "file", ...file, result } });
|
|
8025
|
-
return
|
|
8631
|
+
emit({ kind: "event", event: { type: "file", ...file, result: result2 } });
|
|
8632
|
+
return result2;
|
|
8026
8633
|
}
|
|
8027
8634
|
});
|
|
8028
8635
|
return { handle: handle2 };
|
|
@@ -8087,22 +8694,23 @@ async function createSessionForInput(input, ipcCall) {
|
|
|
8087
8694
|
paths: input.paths,
|
|
8088
8695
|
scratch: input.scratch,
|
|
8089
8696
|
docker: input.docker,
|
|
8697
|
+
nativeExecution: input.nativeExecution ? { cwd: input.nativeExecution.cwd, host: createIpcNativeExecutionHost(ipcCall) } : void 0,
|
|
8090
8698
|
dockerLifecycle: createIpcDockerLifecycle(input.containerNamespace, ipcCall),
|
|
8091
8699
|
memory,
|
|
8092
8700
|
messagingHost,
|
|
8093
8701
|
userMdHost,
|
|
8094
8702
|
bashApprovalHost,
|
|
8095
|
-
verificationRequestHost: createIpcVerificationRequestHost(ipcCall),
|
|
8703
|
+
verificationRequestHost: !input.nativeExecution || input.nativeVerificationRequestEnabled ? createIpcVerificationRequestHost(ipcCall) : void 0,
|
|
8096
8704
|
reviewRequestHost: createIpcReviewRequestHost(ipcCall),
|
|
8097
8705
|
askUser: input.questionEnabled ? (toolCallId, question) => ipcCall("askUser", { toolCallId, question }) : void 0,
|
|
8098
8706
|
refreshApiKey,
|
|
8099
8707
|
fileSink: async (file, source) => {
|
|
8100
|
-
const
|
|
8708
|
+
const result2 = await ipcCall("publishResult", {
|
|
8101
8709
|
...file,
|
|
8102
8710
|
...source
|
|
8103
8711
|
});
|
|
8104
|
-
emit({ kind: "event", event: { type: "file", ...file, result } });
|
|
8105
|
-
return
|
|
8712
|
+
emit({ kind: "event", event: { type: "file", ...file, result: result2 } });
|
|
8713
|
+
return result2;
|
|
8106
8714
|
}
|
|
8107
8715
|
});
|
|
8108
8716
|
return { handle };
|
|
@@ -8126,7 +8734,7 @@ async function main() {
|
|
|
8126
8734
|
const input = await readInput();
|
|
8127
8735
|
if (aborted) return exitWorker(0);
|
|
8128
8736
|
if (input.kind !== "configured_operator_http") {
|
|
8129
|
-
|
|
8737
|
+
initializeMinimalWorkerProcessEnv(process.env, input.scratch);
|
|
8130
8738
|
}
|
|
8131
8739
|
const initialAccessTokens = input.kind === "configured_operator_http" ? input.apiKey ? [input.apiKey] : [] : protectedRuntimeSecrets(input.runtime);
|
|
8132
8740
|
activeAccessTokens.push(...initialAccessTokens.filter(Boolean));
|
|
@@ -8144,11 +8752,11 @@ async function main() {
|
|
|
8144
8752
|
const content = message.content[0];
|
|
8145
8753
|
if (content?.type === "text") {
|
|
8146
8754
|
try {
|
|
8147
|
-
const
|
|
8148
|
-
if (typeof
|
|
8755
|
+
const result2 = JSON.parse(content.text);
|
|
8756
|
+
if (typeof result2.questionId === "string") {
|
|
8149
8757
|
const ack = new Promise((resolve7) => setImmediate(resolve7)).then(
|
|
8150
8758
|
() => ipcCall("questionConsumed", {
|
|
8151
|
-
questionId:
|
|
8759
|
+
questionId: result2.questionId,
|
|
8152
8760
|
toolCallId: message.toolCallId
|
|
8153
8761
|
})
|
|
8154
8762
|
).catch(() => {
|
|
@@ -8165,7 +8773,11 @@ async function main() {
|
|
|
8165
8773
|
reviewState.recordValidationFailure();
|
|
8166
8774
|
if (reviewState.validationFailures() >= 2) void session?.abort();
|
|
8167
8775
|
}
|
|
8168
|
-
for (const event of translatePiEvent(piEvent))
|
|
8776
|
+
for (const event of translatePiEvent(piEvent))
|
|
8777
|
+
emit({
|
|
8778
|
+
kind: "event",
|
|
8779
|
+
event: event.type === "error" ? { ...event, error: workerFailureMessage(event.error, aborted) } : event
|
|
8780
|
+
});
|
|
8169
8781
|
});
|
|
8170
8782
|
try {
|
|
8171
8783
|
const promptMessage = redactJsonValue(input.message, activeAccessTokens);
|
|
@@ -8192,7 +8804,10 @@ async function main() {
|
|
|
8192
8804
|
emit({ kind: "done", messages: piMessagesToProviderView(session.agent.state.messages) });
|
|
8193
8805
|
}
|
|
8194
8806
|
} catch (error) {
|
|
8195
|
-
const message =
|
|
8807
|
+
const message = workerFailureMessage(
|
|
8808
|
+
error instanceof Error ? error.message : String(error),
|
|
8809
|
+
aborted
|
|
8810
|
+
);
|
|
8196
8811
|
if (!aborted) emit({ kind: "event", event: { type: "error", error: message } });
|
|
8197
8812
|
emit({ kind: "fatal", error: message });
|
|
8198
8813
|
process.exitCode = 1;
|