bazilion 0.24.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 +20 -8
- package/dist/browser-keychain.js +83 -0
- package/dist/browser-keychain.js.map +1 -0
- package/dist/cli-main.js +55 -24
- package/dist/cli-main.js.map +1 -1
- package/dist/daemon-main.js +15060 -7470
- 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-0mMqUuts.js → AgentTabs-kEd-oDRM.js} +1 -1
- package/dist/web/client/assets/ChatPane-DhvlzNPJ.js +76 -0
- package/dist/web/client/assets/{ConfigPage-CbALCsl0.js → ConfigPage-CMKsWDjh.js} +1 -1
- package/dist/web/client/assets/{ConfirmDialog-CB1a-szq.js → ConfirmDialog-DpAzoNG8.js} +1 -1
- package/dist/web/client/assets/{FieldRow-BHGq10hz.js → FieldRow-OQ-Ezw5t.js} +1 -1
- package/dist/web/client/assets/{ProductionTeamPolicyEditor-B4Ysob7y.js → ProductionTeamPolicyEditor-DhT-Q13a.js} +1 -1
- package/dist/web/client/assets/{ProfileCommunicationEditor-Bi1SwX0T.js → ProfileCommunicationEditor-CnQIp4e6.js} +1 -1
- package/dist/web/client/assets/{RecoveryState-CDWhoT3x.js → RecoveryState-B4Rne9N_.js} +1 -1
- package/dist/web/client/assets/{ResultCard-Crmt8j95.js → ResultCard-BxAlMky1.js} +1 -1
- package/dist/web/client/assets/{ResultSourceConversation-CqwZKlKb.js → ResultSourceConversation-BzIw43-r.js} +1 -1
- package/dist/web/client/assets/{SectionTabs-mghnc98b.js → SectionTabs-D3M6F_HR.js} +1 -1
- package/dist/web/client/assets/{TeamTabs-BuZ3DvCw.js → TeamTabs-BZbg-UFx.js} +1 -1
- package/dist/web/client/assets/{TemplatesTabs-D71oTTXM.js → TemplatesTabs-D8geEOte.js} +1 -1
- package/dist/web/client/assets/{UnsavedChangesGuard-CiCtGDIH.js → UnsavedChangesGuard-CPQe9VLw.js} +1 -1
- package/dist/web/client/assets/{_id-BVY0iUYM.js → _id-1RIodFdi.js} +1 -1
- package/dist/web/client/assets/_id-BV3w2kDj.js +1 -0
- package/dist/web/client/assets/{_id-DRiwwqZL.js → _id-C9zxKqvQ.js} +1 -1
- package/dist/web/client/assets/{_id-B-8ssJLW.js → _id-CLG_POnZ.js} +1 -1
- package/dist/web/client/assets/{_id-DaqX-WEB.js → _id-Cha845UH.js} +1 -1
- package/dist/web/client/assets/{_id-CeALz6bj.js → _id-DssxcwBl.js} +1 -1
- package/dist/web/client/assets/{_id-C7A_A3eM.js → _id-IDHR-MEm.js} +1 -1
- package/dist/web/client/assets/{_id-CQlUNjzV.js → _id-SGs5zOcT.js} +1 -1
- package/dist/web/client/assets/{activity-C5aaqPEN.js → activity-0srO4qbd.js} +1 -1
- package/dist/web/client/assets/{activity-D4Nt8GQM.js → activity-DxQGr6eP.js} +1 -1
- package/dist/web/client/assets/{agents-BPLszpKx.js → agents-CVTYoXKu.js} +1 -1
- package/dist/web/client/assets/{agents-DFOLPsgX.js → agents-DPTu6Sm_.js} +1 -1
- package/dist/web/client/assets/{agents-BUqq1VBQ.js → agents-nHiIbumu.js} +1 -1
- package/dist/web/client/assets/{approvals-MVCITL8Q.js → approvals-Di_Bux_Q.js} +1 -1
- package/dist/web/client/assets/{approvals-8PPXdZxV.js → approvals-ScNrQg7q.js} +1 -1
- package/dist/web/client/assets/{attention-DiyHVOcZ.js → attention-BF-Llt9z.js} +1 -1
- package/dist/web/client/assets/{attention-e273gZ8d.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-DhgSlMk5.js → context-wo9lNjHx.js} +1 -1
- package/dist/web/client/assets/{inbox-B3To3KpL.js → inbox-CNLmz0Jp.js} +1 -1
- package/dist/web/client/assets/{inbox-C1_vHPb8.js → inbox-De6HOll3.js} +1 -1
- package/dist/web/client/assets/{index-DtEE9JX2.js → index-CjI7_vB3.js} +2 -2
- package/dist/web/client/assets/{learning-B7wX_mkT.js → learning-591SFAKg.js} +1 -1
- package/dist/web/client/assets/{learning-DDwUAKmq.js → learning-D6bO0NeB.js} +1 -1
- package/dist/web/client/assets/{login-CWaSGdgc.js → login-Q7uP-v0M.js} +1 -1
- package/dist/web/client/assets/mcp-BGy64VOv.js +1 -0
- package/dist/web/client/assets/{mcp-CO5iBKHD.js → mcp-DSCjhc5I.js} +1 -1
- package/dist/web/client/assets/{members-Dx9OcdY1.js → members-CBVor-P4.js} +1 -1
- package/dist/web/client/assets/{members-Bd3z1Mbb.js → members-CCcecjC3.js} +1 -1
- package/dist/web/client/assets/{memory-BIZi6bBM.js → memory-CSE8EQ48.js} +1 -1
- package/dist/web/client/assets/{memory-DrYbH0we.js → memory-DgGz0wh4.js} +1 -1
- package/dist/web/client/assets/{policy-CcnTn0qG.js → policy-6j-NQvBj.js} +1 -1
- package/dist/web/client/assets/{policy-Dsj-SWqE.js → policy-Do0TvNWc.js} +1 -1
- package/dist/web/client/assets/{results-GeOLM5Cw.js → results-CCQGn0dE.js} +1 -1
- package/dist/web/client/assets/{results-t7jAchgU.js → results-Cx6_ChIY.js} +1 -1
- package/dist/web/client/assets/{review-CQaZNlyx.js → review-CyS5b0fz.js} +1 -1
- package/dist/web/client/assets/{review-CYvx-3K2.js → review-qG-2gqEp.js} +1 -1
- package/dist/web/client/assets/{routes-DoK4DMdi.js → routes-DRic0xNy.js} +1 -1
- package/dist/web/client/assets/{services-c9HkxKEP.js → services-B_7lf-mx.js} +1 -1
- package/dist/web/client/assets/{services-BI7iyTHh.js → services-ByBA_yA-.js} +1 -1
- package/dist/web/client/assets/{skills-Ddf5PBNn.js → skills--lnDzPWe.js} +1 -1
- package/dist/web/client/assets/{skills-B0O0zwg1.js → skills-C70btgIg.js} +1 -1
- package/dist/web/client/assets/{teams-BNQ4z_k3.js → teams-BL-Fr2xF.js} +1 -1
- package/dist/web/client/assets/{teams-kRB5hV3h.js → teams-BeoxArzy.js} +1 -1
- package/dist/web/client/assets/{teams-Wvr8-LhE.js → teams-C4mb790r.js} +1 -1
- package/dist/web/client/assets/{teams-BDbkurIa.js → teams-DHStw3OS.js} +1 -1
- package/dist/web/client/assets/{telegram-Dx9tzt9d.js → telegram-BIMiebJl.js} +1 -1
- package/dist/web/client/assets/{templates-CGQ93r-m.js → templates-CzHXXiA_.js} +1 -1
- package/dist/web/client/assets/{tokens-CsOJULk9.js → tokens-B9ehOc1o.js} +1 -1
- package/dist/web/client/assets/{tokens-zqJy3CQD.js → tokens-DhaMzFWK.js} +1 -1
- package/dist/web/client/assets/{triggers-9UUKTR6l.js → triggers--xMpHFW7.js} +1 -1
- package/dist/web/client/assets/{triggers-BiXb1VFy.js → triggers-DLzZu8bB.js} +1 -1
- package/dist/web/client/assets/verifications-FzypGVwW.js +2 -0
- package/dist/web/client/assets/{verifications-BKoHhRqF.js → verifications-fR9W-adv.js} +1 -1
- package/dist/web/client/assets/{welcome-BdcpBETx.js → welcome-pjZD7pq4.js} +1 -1
- package/dist/web/client/assets/{x-DtPVZP1O.js → x-CZxV4X-6.js} +1 -1
- package/dist/web/server/assets/{ChatPane-3CIVTz7o.js → ChatPane-CeDUEjmn.js} +10 -2
- package/dist/web/server/assets/{ResultSourceConversation-DwuGuTa-.js → ResultSourceConversation-xn4EKjaP.js} +1 -1
- package/dist/web/server/assets/{_id-C1-ygfez.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-CWlZT9kI.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-LR-ldomm.js → _tanstack-start-manifest_v-CXwNJhX2.js} +132 -132
- package/dist/web/server/assets/{config-CMxeC2Bd.js → config-0_5yhRKg.js} +39 -24
- package/dist/web/server/assets/{config-CbioK6nX.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-C6edENBF.js → results-CkNoVDrY.js} +2 -2
- package/dist/web/server/assets/{results-DjTerNLY.js → results-DSGwi3vj.js} +1 -1
- package/dist/web/server/assets/{router-Doy5hj6V.js → router-BFqyjkYu.js} +7 -7
- package/dist/web/server/assets/{routes-Bz-Gprcp.js → routes-BfEa101d.js} +1 -1
- package/dist/web/server/assets/{routes-ByEYvEFv.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 +2 -2
- package/dist/worker.js +666 -165
- package/dist/worker.js.map +1 -1
- package/package.json +5 -4
- package/dist/web/client/assets/ChatPane-C4ZAMSqQ.js +0 -76
- package/dist/web/client/assets/_id-DQqcn57I.js +0 -1
- package/dist/web/client/assets/chevron-right-DgJy0QeF.js +0 -1
- package/dist/web/client/assets/config-Dm6OgnLh.js +0 -3
- package/dist/web/client/assets/mcp-DO8sSn5c.js +0 -1
- package/dist/web/client/assets/verifications-CElk4UQp.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",
|
|
@@ -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,6 +1757,7 @@ import {
|
|
|
1757
1757
|
lstatSync as lstatSync3,
|
|
1758
1758
|
opendirSync,
|
|
1759
1759
|
openSync as openSync3,
|
|
1760
|
+
readlinkSync,
|
|
1760
1761
|
realpathSync as realpathSync4
|
|
1761
1762
|
} from "fs";
|
|
1762
1763
|
import { isAbsolute as isAbsolute2, join as join14 } from "path";
|
|
@@ -1789,10 +1790,15 @@ function relativeParts(target) {
|
|
|
1789
1790
|
if (parts.length > 17) throw new ContextReadError("depth_limit");
|
|
1790
1791
|
return parts;
|
|
1791
1792
|
}
|
|
1792
|
-
|
|
1793
|
-
|
|
1793
|
+
var literalComponentToken = /* @__PURE__ */ Symbol("context-directory.literal-posix-component");
|
|
1794
|
+
function literalComponent(name) {
|
|
1795
|
+
if (!name || name === "." || name === ".." || /[/\0]/.test(name))
|
|
1794
1796
|
throw new ContextReadError("unsafe_target");
|
|
1795
1797
|
}
|
|
1798
|
+
function component(name) {
|
|
1799
|
+
literalComponent(name);
|
|
1800
|
+
if (name.includes("\\")) throw new ContextReadError("unsafe_target");
|
|
1801
|
+
}
|
|
1796
1802
|
var ContextDirectory = class _ContextDirectory {
|
|
1797
1803
|
fd;
|
|
1798
1804
|
identity;
|
|
@@ -1805,8 +1811,10 @@ var ContextDirectory = class _ContextDirectory {
|
|
|
1805
1811
|
children = [];
|
|
1806
1812
|
listing;
|
|
1807
1813
|
observedFiles = /* @__PURE__ */ new Map();
|
|
1814
|
+
observedMetadata = /* @__PURE__ */ new Map();
|
|
1815
|
+
observedLinks = /* @__PURE__ */ new Map();
|
|
1808
1816
|
closed = false;
|
|
1809
|
-
constructor(registeredPath, label = ".", parent) {
|
|
1817
|
+
constructor(registeredPath, label = ".", parent, token) {
|
|
1810
1818
|
const platform = parent?.platform ?? process.platform;
|
|
1811
1819
|
if (platform !== "linux" && platform !== "darwin")
|
|
1812
1820
|
throw new ContextReadError("safe_reads_unavailable");
|
|
@@ -1814,7 +1822,10 @@ var ContextDirectory = class _ContextDirectory {
|
|
|
1814
1822
|
this.registeredPath = registeredPath;
|
|
1815
1823
|
this.label = label;
|
|
1816
1824
|
this.parent = parent;
|
|
1817
|
-
if (parent)
|
|
1825
|
+
if (parent) {
|
|
1826
|
+
if (token === literalComponentToken) literalComponent(registeredPath);
|
|
1827
|
+
else component(registeredPath);
|
|
1828
|
+
}
|
|
1818
1829
|
parent?.assertCurrent();
|
|
1819
1830
|
const canonicalPath = parent ? join14(parent.canonicalPath, registeredPath) : realpathSync4(registeredPath);
|
|
1820
1831
|
let fd;
|
|
@@ -1884,6 +1895,42 @@ var ContextDirectory = class _ContextDirectory {
|
|
|
1884
1895
|
this.children.push(child);
|
|
1885
1896
|
return child;
|
|
1886
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
|
+
}
|
|
1887
1934
|
entry(name) {
|
|
1888
1935
|
component(name);
|
|
1889
1936
|
this.assertCurrent();
|
|
@@ -1981,12 +2028,19 @@ var ContextDirectory = class _ContextDirectory {
|
|
|
1981
2028
|
if (fd !== void 0) closeSync3(fd);
|
|
1982
2029
|
}
|
|
1983
2030
|
}
|
|
1984
|
-
|
|
2031
|
+
/** Retained/registered directory identity only; does not require mutable workspace contents to stay frozen. */
|
|
2032
|
+
validateIdentity() {
|
|
1985
2033
|
this.assertCurrent();
|
|
1986
2034
|
const currentPath = this.parent ? join14(this.parent.path, this.registeredPath) : realpathSync4(this.registeredPath);
|
|
1987
2035
|
const stat2 = lstatSync3(currentPath, { bigint: true });
|
|
1988
2036
|
if (!stat2.isDirectory() || identity(stat2) !== identity(this.originalIdentity))
|
|
1989
2037
|
throw new ContextReadError("root_changed");
|
|
2038
|
+
const retained = fstatSync3(this.fd, { bigint: true });
|
|
2039
|
+
if (!retained.isDirectory() || identity(retained) !== identity(this.originalIdentity))
|
|
2040
|
+
throw new ContextReadError("root_changed");
|
|
2041
|
+
}
|
|
2042
|
+
validate(skipGit = false, names) {
|
|
2043
|
+
this.validateIdentity();
|
|
1990
2044
|
if (this.listing !== void 0 && JSON.stringify(this.listNames()) !== this.listing)
|
|
1991
2045
|
throw new ContextReadError("source_changed");
|
|
1992
2046
|
for (const [name, previous] of this.observedFiles) {
|
|
@@ -1995,6 +2049,19 @@ var ContextDirectory = class _ContextDirectory {
|
|
|
1995
2049
|
if ((current ? stamp(current) : null) !== previous)
|
|
1996
2050
|
throw new ContextReadError("source_changed");
|
|
1997
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
|
+
}
|
|
1998
2065
|
for (const child of this.children) {
|
|
1999
2066
|
if (!skipGit || !child.label.split("/").includes(".git")) child.validate(skipGit, names);
|
|
2000
2067
|
}
|
|
@@ -2334,9 +2401,9 @@ function parseEnvAllowlist(raw) {
|
|
|
2334
2401
|
}
|
|
2335
2402
|
function resolveShellSecurityConfig(env = process.env) {
|
|
2336
2403
|
const rawMode = env.BAZILION_BASH_SANDBOX?.trim() ?? "";
|
|
2337
|
-
if (rawMode !== "" && rawMode !== "off" && rawMode !== "docker") {
|
|
2404
|
+
if (rawMode !== "" && rawMode !== "off" && rawMode !== "docker" && rawMode !== "native") {
|
|
2338
2405
|
throw new ShellSecurityConfigError(
|
|
2339
|
-
`BAZILION_BASH_SANDBOX must be "off" or "
|
|
2406
|
+
`BAZILION_BASH_SANDBOX must be "off", "docker" or "native", received: ${rawMode}`
|
|
2340
2407
|
);
|
|
2341
2408
|
}
|
|
2342
2409
|
const rawApproval = env.BAZILION_BASH_APPROVAL?.trim() ?? "";
|
|
@@ -2352,8 +2419,8 @@ function resolveShellSecurityConfig(env = process.env) {
|
|
|
2352
2419
|
);
|
|
2353
2420
|
}
|
|
2354
2421
|
return {
|
|
2355
|
-
sandboxMode: rawMode === "docker" ? "docker" : "off",
|
|
2356
|
-
approvalMode: rawApproval === "dangerous" ? "dangerous" : "off",
|
|
2422
|
+
sandboxMode: rawMode === "native" ? "native" : rawMode === "docker" ? "docker" : "off",
|
|
2423
|
+
approvalMode: rawMode === "native" || rawApproval === "dangerous" ? "dangerous" : "off",
|
|
2357
2424
|
sandboxImage: rawImage || DEFAULT_BASH_SANDBOX_IMAGE,
|
|
2358
2425
|
envAllowlist: parseEnvAllowlist(env.BAZILION_BASH_SANDBOX_ENV_ALLOWLIST)
|
|
2359
2426
|
};
|
|
@@ -2476,6 +2543,23 @@ var CONTAINER_LITERAL_ENV_KEYS = /* @__PURE__ */ new Set([
|
|
|
2476
2543
|
"TMPDIR",
|
|
2477
2544
|
"TZ"
|
|
2478
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
|
+
};
|
|
2479
2563
|
var PROTECTED_CONTAINER_ENV = {
|
|
2480
2564
|
PATH: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
|
|
2481
2565
|
HOME: "/tmp",
|
|
@@ -2566,10 +2650,15 @@ function buildDockerRunSpec(input) {
|
|
|
2566
2650
|
` } : {}
|
|
2567
2651
|
};
|
|
2568
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
|
+
}
|
|
2569
2657
|
function createPreparedDockerBashOperations(runtime, lifecycle) {
|
|
2570
2658
|
validatePreparedDockerRuntime(runtime);
|
|
2571
2659
|
return {
|
|
2572
2660
|
async exec(command, cwd, { onData, signal, timeout }) {
|
|
2661
|
+
assertDockerPlatform();
|
|
2573
2662
|
const timeoutMs = resolveTimeoutMs(timeout);
|
|
2574
2663
|
if (signal?.aborted) throw new Error("aborted");
|
|
2575
2664
|
const workspace = await recheckProtectedMount(runtime.workspace);
|
|
@@ -2670,8 +2759,12 @@ function runProtectedContainerCreate(spec, options) {
|
|
|
2670
2759
|
else resolve7();
|
|
2671
2760
|
};
|
|
2672
2761
|
const commandTimeout = options?.timeoutMs !== void 0 && options.timeoutMs <= DOCKER_CREATE_TIMEOUT_MS;
|
|
2673
|
-
const timeoutError = () => commandTimeout ? new Error(`timeout:${options?.timeout}`) : new
|
|
2674
|
-
|
|
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"
|
|
2675
2768
|
);
|
|
2676
2769
|
child.stderr?.on("data", (data) => {
|
|
2677
2770
|
stderr = `${stderr}${data.toString("utf8")}`.slice(-MAX_STDERR_CHARS);
|
|
@@ -2816,6 +2909,7 @@ function createDockerBashOperations(options) {
|
|
|
2816
2909
|
validateImage(image);
|
|
2817
2910
|
return {
|
|
2818
2911
|
async exec(command, cwd, { onData, signal, timeout }) {
|
|
2912
|
+
assertDockerPlatform();
|
|
2819
2913
|
const timeoutMs = resolveTimeoutMs(timeout);
|
|
2820
2914
|
if (signal?.aborted) throw new Error("aborted");
|
|
2821
2915
|
const mountSource = await resolveMountSource(cwd);
|
|
@@ -3306,7 +3400,9 @@ function runCleanupCommand(dockerPath, args, processEnv) {
|
|
|
3306
3400
|
// ../daemon/src/runtime/pi/coding.ts
|
|
3307
3401
|
function codingTools(input) {
|
|
3308
3402
|
const readSecrets = () => typeof input.secrets === "function" ? input.secrets() : input.secrets ?? [];
|
|
3309
|
-
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();
|
|
3310
3406
|
return [
|
|
3311
3407
|
{
|
|
3312
3408
|
name: "coding_environment",
|
|
@@ -3378,12 +3474,35 @@ function codingTools(input) {
|
|
|
3378
3474
|
});
|
|
3379
3475
|
};
|
|
3380
3476
|
let outcome;
|
|
3477
|
+
let captureTruncated = false;
|
|
3478
|
+
const capture = native ? { observedBytes: 0, redacted: false } : void 0;
|
|
3381
3479
|
try {
|
|
3382
|
-
if (input.approval)
|
|
3480
|
+
if (input.approval && !input.native)
|
|
3383
3481
|
await requireBashApproval(command.command, toolCallId, signal, input.approvalHost);
|
|
3384
3482
|
signal?.throwIfAborted();
|
|
3385
3483
|
const cwd = resolveCodingDirectory(input.root, command.cwd);
|
|
3386
|
-
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(
|
|
3387
3506
|
{
|
|
3388
3507
|
...input.docker,
|
|
3389
3508
|
coding: {
|
|
@@ -3394,7 +3513,8 @@ function codingTools(input) {
|
|
|
3394
3513
|
},
|
|
3395
3514
|
input.lifecycle
|
|
3396
3515
|
) : hostOperations;
|
|
3397
|
-
|
|
3516
|
+
if (!operations) throw new Error("Coding execution backend unavailable");
|
|
3517
|
+
const result2 = await operations.exec(
|
|
3398
3518
|
command.command,
|
|
3399
3519
|
input.docker ? input.root : cwd.path,
|
|
3400
3520
|
{
|
|
@@ -3407,21 +3527,25 @@ function codingTools(input) {
|
|
|
3407
3527
|
}
|
|
3408
3528
|
);
|
|
3409
3529
|
emitProgress(true);
|
|
3530
|
+
const retained = output2.finish();
|
|
3410
3531
|
outcome = {
|
|
3411
|
-
state:
|
|
3412
|
-
exitCode:
|
|
3413
|
-
...
|
|
3414
|
-
|
|
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
|
|
3415
3537
|
};
|
|
3416
3538
|
} catch (error) {
|
|
3417
3539
|
const message = error instanceof Error ? error.message : "Command execution unavailable";
|
|
3418
|
-
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";
|
|
3419
3542
|
outcome = { state, exitCode: null, ...output2.finish(), reason: message };
|
|
3420
3543
|
}
|
|
3421
3544
|
const receipt = await input.host.invoke({
|
|
3422
3545
|
action: "finish",
|
|
3423
3546
|
id: started.id,
|
|
3424
|
-
outcome
|
|
3547
|
+
outcome,
|
|
3548
|
+
...capture ? { capture } : {}
|
|
3425
3549
|
});
|
|
3426
3550
|
return {
|
|
3427
3551
|
content: [{ type: "text", text: JSON.stringify(receipt) }],
|
|
@@ -3470,15 +3594,15 @@ function codingTools(input) {
|
|
|
3470
3594
|
async execute(_id, params) {
|
|
3471
3595
|
const values = params;
|
|
3472
3596
|
if (values.search !== void 0) {
|
|
3473
|
-
const
|
|
3597
|
+
const result2 = await input.host.invoke({
|
|
3474
3598
|
action: "log-search",
|
|
3475
3599
|
id: values.id,
|
|
3476
3600
|
query: values.search,
|
|
3477
3601
|
...values.messageId !== void 0 ? { messageId: values.messageId } : {}
|
|
3478
3602
|
});
|
|
3479
3603
|
return {
|
|
3480
|
-
content: [{ type: "text", text: JSON.stringify(
|
|
3481
|
-
details: { codingLogSearch:
|
|
3604
|
+
content: [{ type: "text", text: JSON.stringify(result2) }],
|
|
3605
|
+
details: { codingLogSearch: result2 }
|
|
3482
3606
|
};
|
|
3483
3607
|
}
|
|
3484
3608
|
const value = await input.host.invoke({
|
|
@@ -3674,7 +3798,7 @@ ${JSON.stringify(current.commands)}`
|
|
|
3674
3798
|
}
|
|
3675
3799
|
|
|
3676
3800
|
// ../daemon/src/runtime/pi/session.ts
|
|
3677
|
-
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";
|
|
3678
3802
|
import { basename as basename5, join as join22 } from "path";
|
|
3679
3803
|
import {
|
|
3680
3804
|
createAssistantMessageEventStream
|
|
@@ -3837,12 +3961,12 @@ function providerBaseUrl(providerName, env) {
|
|
|
3837
3961
|
}
|
|
3838
3962
|
}
|
|
3839
3963
|
function providerCredentialEnv(providerName, env) {
|
|
3840
|
-
const
|
|
3964
|
+
const result2 = {};
|
|
3841
3965
|
for (const name of PROVIDER_CREDENTIAL_ENV[providerName] ?? []) {
|
|
3842
3966
|
const value = env[name];
|
|
3843
|
-
if (value !== void 0)
|
|
3967
|
+
if (value !== void 0) result2[name] = value;
|
|
3844
3968
|
}
|
|
3845
|
-
return Object.keys(
|
|
3969
|
+
return Object.keys(result2).length > 0 ? result2 : void 0;
|
|
3846
3970
|
}
|
|
3847
3971
|
function fallbackApi(providerName) {
|
|
3848
3972
|
switch (providerName) {
|
|
@@ -4192,10 +4316,17 @@ ${contextBlocks.join("\n\n")}`);
|
|
|
4192
4316
|
if (options.browserGuide) {
|
|
4193
4317
|
parts.push(browserGuideSection());
|
|
4194
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
|
+
);
|
|
4195
4326
|
const teamLines = [
|
|
4196
4327
|
"# Team",
|
|
4197
4328
|
"",
|
|
4198
|
-
`- ${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}`,
|
|
4199
4330
|
"",
|
|
4200
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`."
|
|
4201
4332
|
];
|
|
@@ -4244,13 +4375,277 @@ function boundReviewedLessons(lessons, maxCharacters = 8e3) {
|
|
|
4244
4375
|
return selected;
|
|
4245
4376
|
}
|
|
4246
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
|
+
|
|
4247
4642
|
// ../daemon/src/runtime/shell/tooling.ts
|
|
4248
4643
|
import { existsSync as existsSync11, lstatSync as lstatSync5, realpathSync as realpathSync7 } from "fs";
|
|
4249
4644
|
import { dirname as dirname5, isAbsolute as isAbsolute5, join as join18, relative as relative4, sep as sep4 } from "path";
|
|
4250
4645
|
import {
|
|
4251
|
-
createBashToolDefinition,
|
|
4646
|
+
createBashToolDefinition as createBashToolDefinition2,
|
|
4252
4647
|
createLocalBashOperations as createLocalBashOperations2,
|
|
4253
|
-
defineTool as
|
|
4648
|
+
defineTool as defineTool3
|
|
4254
4649
|
} from "@earendil-works/pi-coding-agent";
|
|
4255
4650
|
var HOST_CODING_TOOL_NAMES = ["read", "bash", "edit", "write", "grep", "find", "ls"];
|
|
4256
4651
|
var HOST_FILE_TOOL_NAMES = ["read", "edit", "write", "grep", "find", "ls"];
|
|
@@ -4260,7 +4655,7 @@ var SANDBOX_MEMORY_DIR = "/workspace/memory";
|
|
|
4260
4655
|
function createProtectedSessionShellTools(cwd, runtime, approvalHost, lifecycle) {
|
|
4261
4656
|
const operations = createPreparedDockerBashOperations(runtime, lifecycle);
|
|
4262
4657
|
const modelCwd = codingContainerCwd(runtime.coding?.cwd ?? ".");
|
|
4263
|
-
const base =
|
|
4658
|
+
const base = createBashToolDefinition2(cwd, {
|
|
4264
4659
|
operations: {
|
|
4265
4660
|
exec(command, requestedCwd, options) {
|
|
4266
4661
|
if (requestedCwd !== modelCwd && requestedCwd !== cwd)
|
|
@@ -4269,7 +4664,7 @@ function createProtectedSessionShellTools(cwd, runtime, approvalHost, lifecycle)
|
|
|
4269
4664
|
}
|
|
4270
4665
|
}
|
|
4271
4666
|
});
|
|
4272
|
-
const dockerBash =
|
|
4667
|
+
const dockerBash = defineTool3({
|
|
4273
4668
|
...base,
|
|
4274
4669
|
label: "bash (protected Docker sandbox)",
|
|
4275
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.`
|
|
@@ -4298,14 +4693,16 @@ function buildSandboxContainerEnv(env, allowlist) {
|
|
|
4298
4693
|
}
|
|
4299
4694
|
function createSessionShellTools(cwd, env, options = {}) {
|
|
4300
4695
|
const config = resolveShellSecurityConfig(env);
|
|
4696
|
+
if (config.sandboxMode === "native")
|
|
4697
|
+
throw new Error("Native coding requires a genuine daemon-admitted native execution host");
|
|
4301
4698
|
if (options.preparedDocker) {
|
|
4302
4699
|
if (config.sandboxMode !== "docker")
|
|
4303
4700
|
throw new Error("Prepared coding environment cannot execute on the host");
|
|
4304
4701
|
const runtime = options.preparedDocker;
|
|
4305
|
-
const base2 =
|
|
4702
|
+
const base2 = createBashToolDefinition2(cwd, {
|
|
4306
4703
|
operations: createPreparedDockerBashOperations(runtime, options.dockerLifecycle)
|
|
4307
4704
|
});
|
|
4308
|
-
const tool =
|
|
4705
|
+
const tool = defineTool3({
|
|
4309
4706
|
...base2,
|
|
4310
4707
|
label: "bash (prepared Docker sandbox)",
|
|
4311
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.`
|
|
@@ -4320,7 +4717,7 @@ function createSessionShellTools(cwd, env, options = {}) {
|
|
|
4320
4717
|
return { config, hostToolNames: HOST_CODING_TOOL_NAMES };
|
|
4321
4718
|
}
|
|
4322
4719
|
if (config.sandboxMode === "off") {
|
|
4323
|
-
const base2 =
|
|
4720
|
+
const base2 = createBashToolDefinition2(cwd, {
|
|
4324
4721
|
operations: createLocalBashOperations2()
|
|
4325
4722
|
});
|
|
4326
4723
|
const customBash2 = createApprovalGatedBashTool(base2, options.approvalHost);
|
|
@@ -4338,8 +4735,8 @@ function createSessionShellTools(cwd, env, options = {}) {
|
|
|
4338
4735
|
)
|
|
4339
4736
|
]
|
|
4340
4737
|
});
|
|
4341
|
-
const base =
|
|
4342
|
-
const dockerBash =
|
|
4738
|
+
const base = createBashToolDefinition2(cwd, { operations });
|
|
4739
|
+
const dockerBash = defineTool3({
|
|
4343
4740
|
...base,
|
|
4344
4741
|
label: "bash (Docker sandbox)",
|
|
4345
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.`
|
|
@@ -4364,7 +4761,7 @@ function safeReadOnlyMount(source, target, expectedRoot) {
|
|
|
4364
4761
|
|
|
4365
4762
|
// ../daemon/src/runtime/worker/runtime.ts
|
|
4366
4763
|
import {
|
|
4367
|
-
constants as
|
|
4764
|
+
constants as constants7,
|
|
4368
4765
|
existsSync as existsSync12,
|
|
4369
4766
|
lstatSync as lstatSync6,
|
|
4370
4767
|
mkdirSync as mkdirSync6,
|
|
@@ -4376,6 +4773,39 @@ import {
|
|
|
4376
4773
|
import { access as access2 } from "fs/promises";
|
|
4377
4774
|
import { tmpdir as tmpdir3 } from "os";
|
|
4378
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
|
|
4379
4809
|
var REDACTED_VALUE = "[REDACTED]";
|
|
4380
4810
|
var REASONING_LEVELS2 = /* @__PURE__ */ new Set([
|
|
4381
4811
|
"off",
|
|
@@ -4386,8 +4816,10 @@ var REASONING_LEVELS2 = /* @__PURE__ */ new Set([
|
|
|
4386
4816
|
"xhigh"
|
|
4387
4817
|
]);
|
|
4388
4818
|
var CONFIGURED_KEYS = /* @__PURE__ */ new Set([
|
|
4819
|
+
"nativeVerificationRequestEnabled",
|
|
4389
4820
|
"containerNamespace",
|
|
4390
4821
|
"configuredDocker",
|
|
4822
|
+
"nativeExecution",
|
|
4391
4823
|
"imageGenerationEnabled",
|
|
4392
4824
|
"webSearchEnabled",
|
|
4393
4825
|
"repositoryContext",
|
|
@@ -4417,6 +4849,7 @@ var CONFIGURED_REQUIRED_KEYS = /* @__PURE__ */ new Set([
|
|
|
4417
4849
|
"bashApprovalMode"
|
|
4418
4850
|
]);
|
|
4419
4851
|
var PROTECTED_KEYS = /* @__PURE__ */ new Set([
|
|
4852
|
+
"nativeVerificationRequestEnabled",
|
|
4420
4853
|
"imageGenerationEnabled",
|
|
4421
4854
|
"containerNamespace",
|
|
4422
4855
|
"repositoryContext",
|
|
@@ -4431,6 +4864,7 @@ var PROTECTED_KEYS = /* @__PURE__ */ new Set([
|
|
|
4431
4864
|
"runtime",
|
|
4432
4865
|
"paths",
|
|
4433
4866
|
"docker",
|
|
4867
|
+
"nativeExecution",
|
|
4434
4868
|
"webFetchEnabled",
|
|
4435
4869
|
"webSearchEnabled",
|
|
4436
4870
|
"apiKeyRefreshEnabled",
|
|
@@ -4438,7 +4872,7 @@ var PROTECTED_KEYS = /* @__PURE__ */ new Set([
|
|
|
4438
4872
|
]);
|
|
4439
4873
|
var PROTECTED_REQUIRED_KEYS = new Set(
|
|
4440
4874
|
[...PROTECTED_KEYS].filter(
|
|
4441
|
-
(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"
|
|
4442
4876
|
)
|
|
4443
4877
|
);
|
|
4444
4878
|
var STATIC_REVIEW_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -4504,6 +4938,10 @@ function minimalWorkerProcessEnv(scratch, platform = process.platform, hostEnv =
|
|
|
4504
4938
|
LC_ALL: "C"
|
|
4505
4939
|
};
|
|
4506
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
|
+
}
|
|
4507
4945
|
function validateMinimalWorkerProcessEnv(env, scratch, platform = process.platform) {
|
|
4508
4946
|
const expected = minimalWorkerProcessEnv(scratch, platform, env);
|
|
4509
4947
|
const actualKeys = Object.keys(env).sort();
|
|
@@ -4520,6 +4958,8 @@ function validateMinimalWorkerProcessEnv(env, scratch, platform = process.platfo
|
|
|
4520
4958
|
function parseWorkerInput(value) {
|
|
4521
4959
|
const input = objectRecord(value, "worker input");
|
|
4522
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");
|
|
4523
4963
|
if (input.containerNamespace !== void 0 && (typeof input.containerNamespace !== "string" || !/^[a-f0-9-]{36}$/.test(input.containerNamespace)))
|
|
4524
4964
|
throw new Error("Invalid container namespace");
|
|
4525
4965
|
if (input.imageGenerationEnabled !== void 0 && typeof input.imageGenerationEnabled !== "boolean")
|
|
@@ -4531,6 +4971,11 @@ function parseWorkerInput(value) {
|
|
|
4531
4971
|
if (kind === "configured_operator_http") {
|
|
4532
4972
|
assertExactKeys(input, CONFIGURED_KEYS, "configured worker input", CONFIGURED_REQUIRED_KEYS);
|
|
4533
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
|
+
}
|
|
4534
4979
|
if (input.configuredDocker !== void 0) {
|
|
4535
4980
|
const prepared = objectRecord(input.configuredDocker, "configured Docker inputs");
|
|
4536
4981
|
const keys2 = /* @__PURE__ */ new Set(["paths", "docker"]);
|
|
@@ -4581,7 +5026,13 @@ function parseWorkerInput(value) {
|
|
|
4581
5026
|
throw new Error("worker: protected runtime does not match the resolved Agent model");
|
|
4582
5027
|
}
|
|
4583
5028
|
assertProtectedWorkerPaths(input.paths, input.agent);
|
|
4584
|
-
|
|
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);
|
|
4585
5036
|
if (input.apiKeyRefreshEnabled !== true) {
|
|
4586
5037
|
throw new Error("worker: protected input requires bound API key refresh");
|
|
4587
5038
|
}
|
|
@@ -5143,11 +5594,11 @@ function askUserTool(ask) {
|
|
|
5143
5594
|
},
|
|
5144
5595
|
async invoke(args, context) {
|
|
5145
5596
|
if (!context?.toolCallId) throw new Error("Question requires its actual tool call identity");
|
|
5146
|
-
const { receipt, ...
|
|
5597
|
+
const { receipt, ...result2 } = await ask(
|
|
5147
5598
|
context.toolCallId,
|
|
5148
5599
|
args
|
|
5149
5600
|
);
|
|
5150
|
-
const text2 = JSON.stringify(
|
|
5601
|
+
const text2 = JSON.stringify(result2);
|
|
5151
5602
|
return receipt ? { content: [{ type: "text", text: text2 }], questionReceipt: receipt } : text2;
|
|
5152
5603
|
}
|
|
5153
5604
|
};
|
|
@@ -5333,7 +5784,7 @@ function browserTools(host, agentId) {
|
|
|
5333
5784
|
// ../daemon/src/runtime/tools/deliver-file.ts
|
|
5334
5785
|
import {
|
|
5335
5786
|
closeSync as closeSync6,
|
|
5336
|
-
constants as
|
|
5787
|
+
constants as constants8,
|
|
5337
5788
|
fstatSync as fstatSync5,
|
|
5338
5789
|
openSync as openSync6,
|
|
5339
5790
|
readSync as readSync2,
|
|
@@ -5409,7 +5860,7 @@ function deliverFileTool(cwd, sink, sessionId = "") {
|
|
|
5409
5860
|
}
|
|
5410
5861
|
let fd;
|
|
5411
5862
|
try {
|
|
5412
|
-
fd = openSync6(real,
|
|
5863
|
+
fd = openSync6(real, constants8.O_RDONLY | constants8.O_NOFOLLOW | constants8.O_NONBLOCK);
|
|
5413
5864
|
} catch {
|
|
5414
5865
|
throw new Error(`deliver_file: no such file: ${p}`);
|
|
5415
5866
|
}
|
|
@@ -5452,7 +5903,7 @@ function deliverFileTool(cwd, sink, sessionId = "") {
|
|
|
5452
5903
|
const mimeType = MIME[extname(abs).toLowerCase()] ?? "application/octet-stream";
|
|
5453
5904
|
if (!context?.toolCallId || !sessionId)
|
|
5454
5905
|
throw new Error("deliver_file: missing source operation");
|
|
5455
|
-
const
|
|
5906
|
+
const result2 = await sink(
|
|
5456
5907
|
{ name, mimeType, data },
|
|
5457
5908
|
{ sessionId, toolCallId: context.toolCallId }
|
|
5458
5909
|
);
|
|
@@ -5460,10 +5911,10 @@ function deliverFileTool(cwd, sink, sessionId = "") {
|
|
|
5460
5911
|
content: [
|
|
5461
5912
|
{
|
|
5462
5913
|
type: "text",
|
|
5463
|
-
text: `Saved "${name}" (${mimeType}) as result ${
|
|
5914
|
+
text: `Saved "${name}" (${mimeType}) as result ${result2.resultId}. Delivery is subject to Team Policy.`
|
|
5464
5915
|
}
|
|
5465
5916
|
],
|
|
5466
|
-
result
|
|
5917
|
+
result: result2
|
|
5467
5918
|
};
|
|
5468
5919
|
}
|
|
5469
5920
|
};
|
|
@@ -5472,7 +5923,7 @@ function deliverFileTool(cwd, sink, sessionId = "") {
|
|
|
5472
5923
|
// ../daemon/src/runtime/tools/home.ts
|
|
5473
5924
|
import {
|
|
5474
5925
|
closeSync as closeSync7,
|
|
5475
|
-
constants as
|
|
5926
|
+
constants as constants9,
|
|
5476
5927
|
fstatSync as fstatSync6,
|
|
5477
5928
|
lstatSync as lstatSync7,
|
|
5478
5929
|
openSync as openSync7,
|
|
@@ -5546,7 +5997,7 @@ function homeTools(agentDir) {
|
|
|
5546
5997
|
rejectExistingSymlinkOrNonFile(path);
|
|
5547
5998
|
fd = openSync7(
|
|
5548
5999
|
path,
|
|
5549
|
-
|
|
6000
|
+
constants9.O_WRONLY | constants9.O_CREAT | constants9.O_TRUNC | noFollowFlag(),
|
|
5550
6001
|
384
|
|
5551
6002
|
);
|
|
5552
6003
|
if (!fstatSync6(fd).isFile()) throw new Error("target is not a regular file");
|
|
@@ -5973,14 +6424,14 @@ function reviewTools(host) {
|
|
|
5973
6424
|
if (!SEVERITIES.includes(severity)) {
|
|
5974
6425
|
throw new ReviewCapabilityError(`severity must be one of: ${SEVERITIES.join(", ")}`);
|
|
5975
6426
|
}
|
|
5976
|
-
const
|
|
6427
|
+
const result2 = await host.addFinding({
|
|
5977
6428
|
path,
|
|
5978
6429
|
severity,
|
|
5979
6430
|
note,
|
|
5980
6431
|
lineStart: readLine(args.lineStart),
|
|
5981
6432
|
lineEnd: readLine(args.lineEnd)
|
|
5982
6433
|
});
|
|
5983
|
-
return `Finding ${
|
|
6434
|
+
return `Finding ${result2.findingId} recorded as [${String(severity)}] on ${path} (finding ${result2.ordinal}). Nothing was executed and nothing was changed.`;
|
|
5984
6435
|
}
|
|
5985
6436
|
};
|
|
5986
6437
|
const conclusionTool = {
|
|
@@ -6006,11 +6457,11 @@ function reviewTools(host) {
|
|
|
6006
6457
|
if (!CONCLUSIONS.includes(conclusion)) {
|
|
6007
6458
|
throw new ReviewCapabilityError(`conclusion must be one of: ${CONCLUSIONS.join(", ")}`);
|
|
6008
6459
|
}
|
|
6009
|
-
const
|
|
6460
|
+
const result2 = await host.conclude({
|
|
6010
6461
|
conclusion,
|
|
6011
6462
|
note: typeof args.note === "string" ? args.note : null
|
|
6012
6463
|
});
|
|
6013
|
-
return `Conclusion recorded: ${
|
|
6464
|
+
return `Conclusion recorded: ${result2.conclusion}. The review is complete; the requester learns the outcome.`;
|
|
6014
6465
|
}
|
|
6015
6466
|
};
|
|
6016
6467
|
return [packetTool, pathTool, findingTool, conclusionTool];
|
|
@@ -6633,7 +7084,7 @@ async function guardedFetch(opts) {
|
|
|
6633
7084
|
let redirects = 0;
|
|
6634
7085
|
let dispatcher = null;
|
|
6635
7086
|
let activeResponse = null;
|
|
6636
|
-
const
|
|
7087
|
+
const release2 = async () => {
|
|
6637
7088
|
if (!activeResponse?.body?.locked) await activeResponse?.body?.cancel().catch(() => {
|
|
6638
7089
|
});
|
|
6639
7090
|
if (timeoutId) clearTimeout(timeoutId);
|
|
@@ -6645,11 +7096,11 @@ async function guardedFetch(opts) {
|
|
|
6645
7096
|
try {
|
|
6646
7097
|
parsed = new URL(current);
|
|
6647
7098
|
} catch {
|
|
6648
|
-
await
|
|
7099
|
+
await release2();
|
|
6649
7100
|
throw new Error("Invalid URL");
|
|
6650
7101
|
}
|
|
6651
7102
|
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
6652
|
-
await
|
|
7103
|
+
await release2();
|
|
6653
7104
|
throw new Error("Invalid URL: must be http or https");
|
|
6654
7105
|
}
|
|
6655
7106
|
const canPin = !opts.fetchImpl;
|
|
@@ -6658,7 +7109,7 @@ async function guardedFetch(opts) {
|
|
|
6658
7109
|
try {
|
|
6659
7110
|
addrs = await resolveAndCheck(parsed.hostname);
|
|
6660
7111
|
} catch (error) {
|
|
6661
|
-
await
|
|
7112
|
+
await release2();
|
|
6662
7113
|
throw error;
|
|
6663
7114
|
}
|
|
6664
7115
|
await closeDispatcher(dispatcher);
|
|
@@ -6704,7 +7155,7 @@ async function guardedFetch(opts) {
|
|
|
6704
7155
|
res = opts.admitFetch ? await opts.admitFetch(parsed.toString(), perform) : await perform();
|
|
6705
7156
|
activeResponse = res;
|
|
6706
7157
|
} catch (err) {
|
|
6707
|
-
await
|
|
7158
|
+
await release2();
|
|
6708
7159
|
throw err;
|
|
6709
7160
|
}
|
|
6710
7161
|
if (isRedirectStatus(res.status)) {
|
|
@@ -6712,23 +7163,23 @@ async function guardedFetch(opts) {
|
|
|
6712
7163
|
});
|
|
6713
7164
|
const loc = res.headers.get("location");
|
|
6714
7165
|
if (!loc) {
|
|
6715
|
-
await
|
|
7166
|
+
await release2();
|
|
6716
7167
|
throw new Error(`Redirect ${res.status} missing Location header`);
|
|
6717
7168
|
}
|
|
6718
7169
|
redirects += 1;
|
|
6719
7170
|
if (redirects > maxRedirects) {
|
|
6720
|
-
await
|
|
7171
|
+
await release2();
|
|
6721
7172
|
throw new Error(`Too many redirects (> ${maxRedirects})`);
|
|
6722
7173
|
}
|
|
6723
7174
|
let next;
|
|
6724
7175
|
try {
|
|
6725
7176
|
next = new URL(loc, parsed).toString();
|
|
6726
7177
|
} catch {
|
|
6727
|
-
await
|
|
7178
|
+
await release2();
|
|
6728
7179
|
throw new Error("Invalid redirect Location");
|
|
6729
7180
|
}
|
|
6730
7181
|
if (visited.has(next)) {
|
|
6731
|
-
await
|
|
7182
|
+
await release2();
|
|
6732
7183
|
throw new Error("Redirect loop");
|
|
6733
7184
|
}
|
|
6734
7185
|
visited.add(next);
|
|
@@ -6741,7 +7192,7 @@ async function guardedFetch(opts) {
|
|
|
6741
7192
|
current = next;
|
|
6742
7193
|
continue;
|
|
6743
7194
|
}
|
|
6744
|
-
return { response: res, finalUrl: parsed.toString(), release };
|
|
7195
|
+
return { response: res, finalUrl: parsed.toString(), release: release2 };
|
|
6745
7196
|
}
|
|
6746
7197
|
}
|
|
6747
7198
|
|
|
@@ -7060,9 +7511,9 @@ function buildWebTools(opts, includeSearch) {
|
|
|
7060
7511
|
const cacheKey = `${mode}|${url}`;
|
|
7061
7512
|
const cached = cacheGet(cache, cacheKey);
|
|
7062
7513
|
if (cached) return formatFetched(cached, maxLen, !!opts?.sourceReceipt, true);
|
|
7063
|
-
let
|
|
7514
|
+
let result2 = null;
|
|
7064
7515
|
try {
|
|
7065
|
-
|
|
7516
|
+
result2 = await guardedFetch({
|
|
7066
7517
|
url,
|
|
7067
7518
|
fetchImpl: opts?.fetchImpl,
|
|
7068
7519
|
admitFetch: opts?.admitFetch,
|
|
@@ -7078,16 +7529,16 @@ function buildWebTools(opts, includeSearch) {
|
|
|
7078
7529
|
}
|
|
7079
7530
|
}
|
|
7080
7531
|
});
|
|
7081
|
-
if (!
|
|
7082
|
-
throw new Error(`${
|
|
7532
|
+
if (!result2.response.ok) {
|
|
7533
|
+
throw new Error(`${result2.response.status} ${result2.response.statusText}`);
|
|
7083
7534
|
}
|
|
7084
|
-
const ct =
|
|
7535
|
+
const ct = result2.response.headers.get("content-type") ?? "";
|
|
7085
7536
|
const isHtml = ct.includes("text/html") || ct.includes("xhtml");
|
|
7086
|
-
const { text: body, truncated } = await readBodyCapped(
|
|
7537
|
+
const { text: body, truncated } = await readBodyCapped(result2.response, maxBodyBytes);
|
|
7087
7538
|
let extracted;
|
|
7088
7539
|
let renderer = "direct";
|
|
7089
7540
|
if (isHtml) {
|
|
7090
|
-
extracted = extractReadable(body,
|
|
7541
|
+
extracted = extractReadable(body, result2.finalUrl, mode);
|
|
7091
7542
|
} else if (ct.includes("application/json")) {
|
|
7092
7543
|
try {
|
|
7093
7544
|
extracted = { text: JSON.stringify(JSON.parse(body), null, 2) };
|
|
@@ -7098,7 +7549,7 @@ function buildWebTools(opts, includeSearch) {
|
|
|
7098
7549
|
extracted = { text: body };
|
|
7099
7550
|
}
|
|
7100
7551
|
if (isHtml && !firecrawlDisabled && extracted.text.length < FIRECRAWL_FALLBACK_THRESHOLD) {
|
|
7101
|
-
const rescued = await firecrawlScrape(
|
|
7552
|
+
const rescued = await firecrawlScrape(result2.finalUrl, mode, env, fetchFn, timeoutMs);
|
|
7102
7553
|
if (rescued) {
|
|
7103
7554
|
renderer = "firecrawl";
|
|
7104
7555
|
extracted = {
|
|
@@ -7118,14 +7569,14 @@ function buildWebTools(opts, includeSearch) {
|
|
|
7118
7569
|
};
|
|
7119
7570
|
}
|
|
7120
7571
|
if (opts?.sourceReceipt) {
|
|
7121
|
-
if (Buffer.byteLength(
|
|
7572
|
+
if (Buffer.byteLength(result2.finalUrl) > 2048)
|
|
7122
7573
|
throw new Error("web_fetch: effective URL exceeds the 2 KiB evidence bound");
|
|
7123
7574
|
extracted.receipt = {
|
|
7124
7575
|
requestedUrl: url,
|
|
7125
|
-
finalUrl: renderer === "direct" ?
|
|
7126
|
-
status: renderer === "direct" ?
|
|
7576
|
+
finalUrl: renderer === "direct" ? result2.finalUrl : null,
|
|
7577
|
+
status: renderer === "direct" ? result2.response.status : null,
|
|
7127
7578
|
...renderer === "firecrawl" ? {
|
|
7128
|
-
directFetch: { finalUrl:
|
|
7579
|
+
directFetch: { finalUrl: result2.finalUrl, status: result2.response.status },
|
|
7129
7580
|
rendererReported: extracted.rendererReported ?? { url: null, status: null }
|
|
7130
7581
|
} : {},
|
|
7131
7582
|
fetchedAt: Date.now(),
|
|
@@ -7140,7 +7591,7 @@ function buildWebTools(opts, includeSearch) {
|
|
|
7140
7591
|
if (err instanceof SsrFBlockedError) throw new Error(`web_fetch: ${err.message}`);
|
|
7141
7592
|
throw new Error(`web_fetch: ${describeError(err)}`);
|
|
7142
7593
|
} finally {
|
|
7143
|
-
if (
|
|
7594
|
+
if (result2) await result2.release();
|
|
7144
7595
|
}
|
|
7145
7596
|
}
|
|
7146
7597
|
});
|
|
@@ -7285,11 +7736,22 @@ function createProtectedBazilionCustomTools(opts) {
|
|
|
7285
7736
|
// ../daemon/src/runtime/pi/session.ts
|
|
7286
7737
|
var PROTECTED_MODEL_CWD = "/workspace";
|
|
7287
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.`;
|
|
7288
7745
|
var PROTECTED_BASE_SYSTEM_PROMPT = `You are an assistant operating inside Bazilion's protected
|
|
7289
7746
|
Agent runtime. Use only the tools exposed for this turn. Coding commands execute in an ephemeral,
|
|
7290
7747
|
network-disabled Docker container whose Team workspace is /workspace. Host paths and host tools are
|
|
7291
7748
|
not available. Be concise and show container paths clearly when working with files.`;
|
|
7292
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");
|
|
7293
7755
|
const {
|
|
7294
7756
|
agent,
|
|
7295
7757
|
paths,
|
|
@@ -7321,11 +7783,15 @@ async function createBazilionSession(opts) {
|
|
|
7321
7783
|
modelId
|
|
7322
7784
|
});
|
|
7323
7785
|
const model = resolvePiModel(modelRuntime, providerName, modelId, baseUrl);
|
|
7324
|
-
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;
|
|
7325
7788
|
if (!existsSync14(cwd)) mkdirSync7(cwd, { recursive: true });
|
|
7326
7789
|
const promptSkills = restricted ? [] : loadPromptSkills(paths.skillsDir, agent.skills);
|
|
7327
7790
|
const uploadsDir = join22(agent.agent.dir, "uploads");
|
|
7328
|
-
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, {
|
|
7329
7795
|
preparedDocker: opts.preparedDocker,
|
|
7330
7796
|
dockerLifecycle: opts.dockerLifecycle,
|
|
7331
7797
|
...existsSync14(uploadsDir) ? { inputsDir: uploadsDir } : {},
|
|
@@ -7338,7 +7804,7 @@ async function createBazilionSession(opts) {
|
|
|
7338
7804
|
const sessionDir = restricted?.sessionDir ?? join22(paths.agentDir(agent.agent.id), "sessions");
|
|
7339
7805
|
mkdirSync7(sessionDir, { recursive: true });
|
|
7340
7806
|
const existing = restricted ? null : explicitConversationFile(sessionDir, opts.conversation);
|
|
7341
|
-
const sessionManager = existing ? SessionManager.open(existing, sessionDir,
|
|
7807
|
+
const sessionManager = existing ? SessionManager.open(existing, sessionDir, modelCwd) : SessionManager.create(modelCwd, sessionDir);
|
|
7342
7808
|
const settingsManager = SettingsManager.inMemory({
|
|
7343
7809
|
// Auxiliary provider requests must be explicitly admitted by Bazilion, not idle/streaming warming.
|
|
7344
7810
|
cacheWarming: "off",
|
|
@@ -7353,6 +7819,7 @@ async function createBazilionSession(opts) {
|
|
|
7353
7819
|
const bazilionPrompt = restricted?.systemPrompt ?? buildSystemPrompt(agent, {
|
|
7354
7820
|
skills: promptSkills,
|
|
7355
7821
|
sandboxMode: shellTools?.config.sandboxMode ?? "off",
|
|
7822
|
+
...native ? { modelWorkspace: cwd } : {},
|
|
7356
7823
|
// Guide iff the browser tools are admitted — the same host presence
|
|
7357
7824
|
// that registers `browser_*` in createBazilionCustomTools (T10).
|
|
7358
7825
|
...opts.browserHost ? { browserGuide: true } : {},
|
|
@@ -7364,7 +7831,7 @@ async function createBazilionSession(opts) {
|
|
|
7364
7831
|
shellTools?.config.sandboxMode === "docker" ? "/workspace" : cwd
|
|
7365
7832
|
) : void 0;
|
|
7366
7833
|
const resourceLoader = new DefaultResourceLoader({
|
|
7367
|
-
cwd,
|
|
7834
|
+
cwd: modelCwd,
|
|
7368
7835
|
agentDir: join22(paths.home, "pi"),
|
|
7369
7836
|
settingsManager,
|
|
7370
7837
|
noExtensions: true,
|
|
@@ -7404,6 +7871,7 @@ async function createBazilionSession(opts) {
|
|
|
7404
7871
|
root: cwd,
|
|
7405
7872
|
context: repository.resolve,
|
|
7406
7873
|
docker: opts.preparedDocker,
|
|
7874
|
+
native: native?.host,
|
|
7407
7875
|
lifecycle: opts.dockerLifecycle,
|
|
7408
7876
|
approval: shellTools.config.approvalMode === "dangerous",
|
|
7409
7877
|
approvalHost: bashApprovalHost,
|
|
@@ -7413,7 +7881,7 @@ async function createBazilionSession(opts) {
|
|
|
7413
7881
|
const customTools = shellTools?.customBash ? [...bazilionTools, shellTools.customBash] : bazilionTools;
|
|
7414
7882
|
const allowedTools = [...shellTools?.hostToolNames ?? [], ...customTools.map((t) => t.name)];
|
|
7415
7883
|
const { session } = await createAgentSession({
|
|
7416
|
-
cwd,
|
|
7884
|
+
cwd: modelCwd,
|
|
7417
7885
|
agentDir: join22(paths.home, "pi"),
|
|
7418
7886
|
model,
|
|
7419
7887
|
thinkingLevel: toPiThinkingLevel(restricted?.reasoningLevel ?? agent.reasoningLevel),
|
|
@@ -7445,6 +7913,10 @@ async function createBazilionSession(opts) {
|
|
|
7445
7913
|
};
|
|
7446
7914
|
}
|
|
7447
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");
|
|
7448
7920
|
const { providerName, modelId } = splitModelString(opts.agent.model);
|
|
7449
7921
|
if (providerName !== opts.runtime.providerName || modelId !== opts.runtime.modelId) {
|
|
7450
7922
|
throw new Error("protected Agent model does not match the prepared provider runtime");
|
|
@@ -7468,21 +7940,33 @@ async function createProtectedBazilionSession(opts) {
|
|
|
7468
7940
|
opts.runtime.modelId,
|
|
7469
7941
|
opts.runtime.baseUrl
|
|
7470
7942
|
);
|
|
7471
|
-
const
|
|
7472
|
-
|
|
7473
|
-
|
|
7474
|
-
|
|
7475
|
-
|
|
7476
|
-
|
|
7477
|
-
|
|
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
|
+
}
|
|
7478
7961
|
mkdirSync7(opts.paths.sessionDir, { recursive: true });
|
|
7479
7962
|
const existing = explicitConversationFile(opts.paths.sessionDir, opts.conversation);
|
|
7480
|
-
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);
|
|
7481
7964
|
const settingsManager = createInMemorySettingsManager();
|
|
7482
7965
|
const bazilionPrompt = redactJsonValue(
|
|
7483
7966
|
buildSystemPrompt(opts.agent, {
|
|
7484
7967
|
skills: opts.paths.skills,
|
|
7485
|
-
sandboxMode: "docker",
|
|
7968
|
+
sandboxMode: native ? "native" : "docker",
|
|
7969
|
+
...native ? { modelWorkspace: nativeRoot } : {},
|
|
7486
7970
|
homeDocuments: opts.paths.homeDocuments
|
|
7487
7971
|
}),
|
|
7488
7972
|
protectedRuntimeSecrets(opts.runtime)
|
|
@@ -7490,7 +7974,7 @@ async function createProtectedBazilionSession(opts) {
|
|
|
7490
7974
|
const repository = opts.repositoryContext && opts.repositoryContextHost ? repositoryContextIntegration(
|
|
7491
7975
|
redactJsonValue(opts.repositoryContext, protectedRuntimeSecrets(opts.runtime)),
|
|
7492
7976
|
opts.repositoryContextHost,
|
|
7493
|
-
PROTECTED_MODEL_CWD
|
|
7977
|
+
native ? nativeRoot : PROTECTED_MODEL_CWD
|
|
7494
7978
|
) : void 0;
|
|
7495
7979
|
const resourceLoader = new DefaultResourceLoader({
|
|
7496
7980
|
cwd: modelCwd,
|
|
@@ -7501,7 +7985,7 @@ async function createProtectedBazilionSession(opts) {
|
|
|
7501
7985
|
noPromptTemplates: true,
|
|
7502
7986
|
noThemes: true,
|
|
7503
7987
|
noContextFiles: true,
|
|
7504
|
-
systemPrompt: PROTECTED_BASE_SYSTEM_PROMPT,
|
|
7988
|
+
systemPrompt: native ? PROTECTED_NATIVE_BASE_SYSTEM_PROMPT : PROTECTED_BASE_SYSTEM_PROMPT,
|
|
7505
7989
|
appendSystemPrompt: bazilionPrompt ? [bazilionPrompt] : void 0
|
|
7506
7990
|
});
|
|
7507
7991
|
if (repository) resourceLoader.getAgentsFiles = repository.files;
|
|
@@ -7525,16 +8009,17 @@ async function createProtectedBazilionSession(opts) {
|
|
|
7525
8009
|
bazilionTools.push(
|
|
7526
8010
|
...codingTools({
|
|
7527
8011
|
host: opts.codingHost,
|
|
7528
|
-
root: opts.paths.teamDir,
|
|
8012
|
+
root: nativeRoot ?? opts.paths.teamDir,
|
|
7529
8013
|
context: repository.resolve,
|
|
7530
|
-
docker
|
|
8014
|
+
docker,
|
|
8015
|
+
native: native?.host,
|
|
7531
8016
|
lifecycle: opts.dockerLifecycle,
|
|
7532
8017
|
approval: true,
|
|
7533
8018
|
approvalHost: opts.bashApprovalHost,
|
|
7534
8019
|
secrets: () => redactionSecrets
|
|
7535
8020
|
})
|
|
7536
8021
|
);
|
|
7537
|
-
if (!shellTools.customBash) throw new Error("protected
|
|
8022
|
+
if (!shellTools.customBash) throw new Error("protected bash tool is unavailable");
|
|
7538
8023
|
const customTools = [...bazilionTools, shellTools.customBash];
|
|
7539
8024
|
const { session } = await createAgentSession({
|
|
7540
8025
|
cwd: modelCwd,
|
|
@@ -7777,56 +8262,63 @@ function assertSelectedProvider(requested, expected) {
|
|
|
7777
8262
|
}
|
|
7778
8263
|
}
|
|
7779
8264
|
|
|
7780
|
-
// ../daemon/src/runtime/worker/
|
|
7781
|
-
|
|
7782
|
-
|
|
7783
|
-
|
|
7784
|
-
|
|
7785
|
-
|
|
7786
|
-
|
|
7787
|
-
|
|
7788
|
-
|
|
7789
|
-
|
|
7790
|
-
|
|
7791
|
-
|
|
7792
|
-
|
|
7793
|
-
|
|
7794
|
-
|
|
7795
|
-
|
|
7796
|
-
|
|
7797
|
-
|
|
7798
|
-
|
|
7799
|
-
|
|
7800
|
-
|
|
7801
|
-
|
|
7802
|
-
|
|
7803
|
-
|
|
7804
|
-
|
|
7805
|
-
|
|
7806
|
-
|
|
7807
|
-
|
|
7808
|
-
|
|
7809
|
-
|
|
7810
|
-
|
|
7811
|
-
|
|
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 });
|
|
7812
8299
|
try {
|
|
7813
|
-
|
|
7814
|
-
|
|
7815
|
-
|
|
7816
|
-
|
|
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
|
+
}
|
|
7817
8313
|
});
|
|
7818
|
-
|
|
7819
|
-
|
|
7820
|
-
|
|
8314
|
+
result(value);
|
|
8315
|
+
return value;
|
|
8316
|
+
} finally {
|
|
8317
|
+
signal?.removeEventListener("abort", cancel);
|
|
7821
8318
|
}
|
|
7822
|
-
}
|
|
8319
|
+
}
|
|
7823
8320
|
};
|
|
7824
8321
|
}
|
|
7825
|
-
function isIpcReply(message) {
|
|
7826
|
-
if (!message || typeof message !== "object") return false;
|
|
7827
|
-
const candidate = message;
|
|
7828
|
-
return candidate.type === "rpc-reply" && typeof candidate.id === "string" && typeof candidate.ok === "boolean";
|
|
7829
|
-
}
|
|
7830
8322
|
|
|
7831
8323
|
// ../daemon/src/runtime/worker/output.ts
|
|
7832
8324
|
var WORKER_OUTPUT_DRAIN_MS = 2e3;
|
|
@@ -7967,7 +8459,7 @@ function createIpcMcpHost(call) {
|
|
|
7967
8459
|
function createIpcBashApprovalHost(call, input) {
|
|
7968
8460
|
return {
|
|
7969
8461
|
async requestApproval(request) {
|
|
7970
|
-
const
|
|
8462
|
+
const result2 = await call("bashApproval", {
|
|
7971
8463
|
id: randomUUID21(),
|
|
7972
8464
|
turnId: input.turnId,
|
|
7973
8465
|
toolCallId: request.toolCallId,
|
|
@@ -7977,7 +8469,7 @@ function createIpcBashApprovalHost(call, input) {
|
|
|
7977
8469
|
risks: [...request.risks],
|
|
7978
8470
|
mode: input.mode
|
|
7979
8471
|
});
|
|
7980
|
-
return
|
|
8472
|
+
return result2.decision === "allow" ? "approved" : "denied";
|
|
7981
8473
|
}
|
|
7982
8474
|
};
|
|
7983
8475
|
}
|
|
@@ -8105,6 +8597,7 @@ async function createSessionForInput(input, ipcCall) {
|
|
|
8105
8597
|
}) : void 0;
|
|
8106
8598
|
const handle2 = await createBazilionSession({
|
|
8107
8599
|
agent: input.agent,
|
|
8600
|
+
nativeExecution: input.nativeExecution ? { cwd: input.nativeExecution.cwd, host: createIpcNativeExecutionHost(ipcCall) } : void 0,
|
|
8108
8601
|
preparedDocker: input.configuredDocker?.docker,
|
|
8109
8602
|
dockerLifecycle: createIpcDockerLifecycle(input.containerNamespace, ipcCall),
|
|
8110
8603
|
conversation: input.conversation,
|
|
@@ -8119,7 +8612,7 @@ async function createSessionForInput(input, ipcCall) {
|
|
|
8119
8612
|
userMdHost: userMdHost2,
|
|
8120
8613
|
// The requester's halves of specialist verification and review. Only the configured/browser-enabled
|
|
8121
8614
|
// worker kind reaches this builder, and it is an ordinary coding turn.
|
|
8122
|
-
verificationRequestHost: createIpcVerificationRequestHost(ipcCall),
|
|
8615
|
+
verificationRequestHost: !input.nativeExecution || input.nativeVerificationRequestEnabled ? createIpcVerificationRequestHost(ipcCall) : void 0,
|
|
8123
8616
|
reviewRequestHost: createIpcReviewRequestHost(ipcCall),
|
|
8124
8617
|
imageGenerationHost,
|
|
8125
8618
|
webSearchHost,
|
|
@@ -8131,12 +8624,12 @@ async function createSessionForInput(input, ipcCall) {
|
|
|
8131
8624
|
bashApprovalHost: bashApprovalHost2,
|
|
8132
8625
|
askUser: input.questionEnabled ? (toolCallId, question) => ipcCall("askUser", { toolCallId, question }) : void 0,
|
|
8133
8626
|
fileSink: async (file, source) => {
|
|
8134
|
-
const
|
|
8627
|
+
const result2 = await ipcCall(
|
|
8135
8628
|
"publishResult",
|
|
8136
8629
|
{ ...file, ...source }
|
|
8137
8630
|
);
|
|
8138
|
-
emit({ kind: "event", event: { type: "file", ...file, result } });
|
|
8139
|
-
return
|
|
8631
|
+
emit({ kind: "event", event: { type: "file", ...file, result: result2 } });
|
|
8632
|
+
return result2;
|
|
8140
8633
|
}
|
|
8141
8634
|
});
|
|
8142
8635
|
return { handle: handle2 };
|
|
@@ -8201,22 +8694,23 @@ async function createSessionForInput(input, ipcCall) {
|
|
|
8201
8694
|
paths: input.paths,
|
|
8202
8695
|
scratch: input.scratch,
|
|
8203
8696
|
docker: input.docker,
|
|
8697
|
+
nativeExecution: input.nativeExecution ? { cwd: input.nativeExecution.cwd, host: createIpcNativeExecutionHost(ipcCall) } : void 0,
|
|
8204
8698
|
dockerLifecycle: createIpcDockerLifecycle(input.containerNamespace, ipcCall),
|
|
8205
8699
|
memory,
|
|
8206
8700
|
messagingHost,
|
|
8207
8701
|
userMdHost,
|
|
8208
8702
|
bashApprovalHost,
|
|
8209
|
-
verificationRequestHost: createIpcVerificationRequestHost(ipcCall),
|
|
8703
|
+
verificationRequestHost: !input.nativeExecution || input.nativeVerificationRequestEnabled ? createIpcVerificationRequestHost(ipcCall) : void 0,
|
|
8210
8704
|
reviewRequestHost: createIpcReviewRequestHost(ipcCall),
|
|
8211
8705
|
askUser: input.questionEnabled ? (toolCallId, question) => ipcCall("askUser", { toolCallId, question }) : void 0,
|
|
8212
8706
|
refreshApiKey,
|
|
8213
8707
|
fileSink: async (file, source) => {
|
|
8214
|
-
const
|
|
8708
|
+
const result2 = await ipcCall("publishResult", {
|
|
8215
8709
|
...file,
|
|
8216
8710
|
...source
|
|
8217
8711
|
});
|
|
8218
|
-
emit({ kind: "event", event: { type: "file", ...file, result } });
|
|
8219
|
-
return
|
|
8712
|
+
emit({ kind: "event", event: { type: "file", ...file, result: result2 } });
|
|
8713
|
+
return result2;
|
|
8220
8714
|
}
|
|
8221
8715
|
});
|
|
8222
8716
|
return { handle };
|
|
@@ -8240,7 +8734,7 @@ async function main() {
|
|
|
8240
8734
|
const input = await readInput();
|
|
8241
8735
|
if (aborted) return exitWorker(0);
|
|
8242
8736
|
if (input.kind !== "configured_operator_http") {
|
|
8243
|
-
|
|
8737
|
+
initializeMinimalWorkerProcessEnv(process.env, input.scratch);
|
|
8244
8738
|
}
|
|
8245
8739
|
const initialAccessTokens = input.kind === "configured_operator_http" ? input.apiKey ? [input.apiKey] : [] : protectedRuntimeSecrets(input.runtime);
|
|
8246
8740
|
activeAccessTokens.push(...initialAccessTokens.filter(Boolean));
|
|
@@ -8258,11 +8752,11 @@ async function main() {
|
|
|
8258
8752
|
const content = message.content[0];
|
|
8259
8753
|
if (content?.type === "text") {
|
|
8260
8754
|
try {
|
|
8261
|
-
const
|
|
8262
|
-
if (typeof
|
|
8755
|
+
const result2 = JSON.parse(content.text);
|
|
8756
|
+
if (typeof result2.questionId === "string") {
|
|
8263
8757
|
const ack = new Promise((resolve7) => setImmediate(resolve7)).then(
|
|
8264
8758
|
() => ipcCall("questionConsumed", {
|
|
8265
|
-
questionId:
|
|
8759
|
+
questionId: result2.questionId,
|
|
8266
8760
|
toolCallId: message.toolCallId
|
|
8267
8761
|
})
|
|
8268
8762
|
).catch(() => {
|
|
@@ -8279,7 +8773,11 @@ async function main() {
|
|
|
8279
8773
|
reviewState.recordValidationFailure();
|
|
8280
8774
|
if (reviewState.validationFailures() >= 2) void session?.abort();
|
|
8281
8775
|
}
|
|
8282
|
-
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
|
+
});
|
|
8283
8781
|
});
|
|
8284
8782
|
try {
|
|
8285
8783
|
const promptMessage = redactJsonValue(input.message, activeAccessTokens);
|
|
@@ -8306,7 +8804,10 @@ async function main() {
|
|
|
8306
8804
|
emit({ kind: "done", messages: piMessagesToProviderView(session.agent.state.messages) });
|
|
8307
8805
|
}
|
|
8308
8806
|
} catch (error) {
|
|
8309
|
-
const message =
|
|
8807
|
+
const message = workerFailureMessage(
|
|
8808
|
+
error instanceof Error ? error.message : String(error),
|
|
8809
|
+
aborted
|
|
8810
|
+
);
|
|
8310
8811
|
if (!aborted) emit({ kind: "event", event: { type: "error", error: message } });
|
|
8311
8812
|
emit({ kind: "fatal", error: message });
|
|
8312
8813
|
process.exitCode = 1;
|