nolo-cli 0.231.0-alpha.1 → 0.240.0-alpha.2
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/{_executeModel-7V3NSK4W.js → _executeModel-5NA4USGG.js} +56 -51
- package/{action-GDZDXPMB.js → action-X75O3XPH.js} +7 -4
- package/{addContentAction-7RO4AMRI.js → addContentAction-GVC77QSN.js} +9 -8
- package/{addDialogAgentAction-EVYBGTXB.js → addDialogAgentAction-KKDVAMW3.js} +12 -11
- package/{agentDeleteCommand-MD76OMLN.js → agentDeleteCommand-2RFGKFAB.js} +77 -69
- package/{agentEmailCommands-T4TW4IBX.js → agentEmailCommands-GQCQKKOR.js} +84 -72
- package/{agentListCommands-4WLG32IW.js → agentListCommands-HSGLDPDQ.js} +40 -47
- package/{agentMachineCommands-LSDGA5WR.js → agentMachineCommands-BISF6PVV.js} +26 -22
- package/{agentProviderCommands-STI3DQ6A.js → agentProviderCommands-O3Q25PKU.js} +2 -2
- package/{agentPullCommand-KHV4EELF.js → agentPullCommand-G6U2LHMW.js} +1 -1
- package/{agentRecordCommands-7TEX2B7Y.js → agentRecordCommands-AOXPGYAJ.js} +79 -67
- package/{agentRunCommand-23SMDVDW.js → agentRunCommand-YTZJCRAL.js} +85 -72
- package/{agentRunControl-MBG4U6SL.js → agentRunControl-VBL7UFSG.js} +1 -1
- package/{agentRuntimeLocal-HOXKWCYO.js → agentRuntimeLocal-T7BX2WGL.js} +24 -19
- package/{agentSlice-AATYVDP6.js → agentSlice-XJNKE3PG.js} +10 -9
- package/{appDeleteCommands-WWCC6WA5.js → appDeleteCommands-LURUSPY7.js} +27 -23
- package/{appDeployCommands-AU4IUN33.js → appDeployCommands-SMEW4AK2.js} +27 -23
- package/{appDeployStatusCommands-STUW7WXL.js → appDeployStatusCommands-VYPJTBJK.js} +27 -23
- package/{appGetCommands-BGTLIQ4K.js → appGetCommands-N4NI5GGJ.js} +27 -23
- package/{appListCommands-CUCPRUXW.js → appListCommands-5C6ONN3Z.js} +27 -23
- package/{authCommand-3SUYUNQV.js → authCommand-4CVBDADE.js} +15 -13
- package/{authCommands-BLE7ETZH.js → authCommands-EHU2BHOX.js} +7 -5
- package/{builtinSkillRegistry-BAE2LDXF.js → builtinSkillRegistry-AYWYQVA4.js} +3 -3
- package/{chromeOpsCommands-WAA45NCS.js → chromeOpsCommands-CSDG2HYN.js} +1 -1
- package/{chunk-HHFGE2WF.js → chunk-2574ANSV.js} +1 -1
- package/chunk-2SXN7LAY.js +15 -0
- package/{chunk-S6FDXXZV.js → chunk-3EMIEC27.js} +1 -1
- package/{chunk-EXNV7CCV.js → chunk-3FBAVU2Y.js} +11 -9
- package/{chunk-ZH3KXFHS.js → chunk-4FIO2S7Z.js} +1 -1
- package/{chunk-U4FF7LRY.js → chunk-4IQVE43Z.js} +30 -26
- package/{chunk-VQ5N5GSV.js → chunk-4Q6HQORG.js} +1 -1
- package/{chunk-P2ZLUIW2.js → chunk-4X5AVCM7.js} +94 -4
- package/chunk-4ZCTKB27.js +31 -0
- package/{chunk-42OKN2LI.js → chunk-5HUO7SEX.js} +9 -107
- package/{chunk-QYB23WUH.js → chunk-5QZSEQSK.js} +1 -1
- package/{chunk-7JGMNKKG.js → chunk-6CKUO32A.js} +8 -0
- package/chunk-6D25V6CB.js +133 -0
- package/{chunk-LHN7NIQZ.js → chunk-6WOLPIPY.js} +93 -90
- package/{chunk-6QHKRARD.js → chunk-6WZVM33D.js} +9 -4
- package/{chunk-NVEYEKN3.js → chunk-7AJRJGSQ.js} +254 -359
- package/chunk-7NIBQ4HY.js +138 -0
- package/{chunk-7Z6EW7AH.js → chunk-7TTMMOKH.js} +13 -6
- package/{chunk-GXZ5LB7H.js → chunk-A3LUWRQK.js} +4 -4
- package/{chunk-4ZGPHFLE.js → chunk-A5EVA6HU.js} +2 -2
- package/{chunk-3ING4D5X.js → chunk-AEQMKYZN.js} +4 -4
- package/{chunk-FFSPUVL5.js → chunk-AH5R7BYW.js} +6 -166
- package/{chunk-7FEP5USX.js → chunk-ANJRDS6U.js} +3 -3
- package/{chunk-YFLVRVYK.js → chunk-AVJDELEA.js} +1 -1
- package/{chunk-HYLRQDEE.js → chunk-B5SV4H3J.js} +6 -6
- package/{chunk-KUOMUZH6.js → chunk-B7DE5XJW.js} +137 -290
- package/chunk-BEM6LPD2.js +734 -0
- package/{chunk-DUUDXSLX.js → chunk-BGGAY6OK.js} +27 -3
- package/{chunk-YCFP57LH.js → chunk-BGGV6B5O.js} +408 -230
- package/{chunk-BP5ZJ6B4.js → chunk-BIABIPGW.js} +1 -1
- package/{chunk-TQEKUOTI.js → chunk-BXSMFPTG.js} +4 -4
- package/{chunk-RG2DGNL6.js → chunk-CKZPMJNU.js} +3 -3
- package/{chunk-WU443D7A.js → chunk-CVJRVBJL.js} +2 -2
- package/{chunk-BIWI5M4E.js → chunk-D374I563.js} +1 -1
- package/{chunk-QRGDJA4B.js → chunk-DNZ4JJ7C.js} +1 -1
- package/chunk-DVYAFH2Q.js +103 -0
- package/{chunk-FTMFO6LI.js → chunk-DXW5WDHZ.js} +4 -4
- package/{chunk-ZTR65O4L.js → chunk-E5KJOZWY.js} +3 -3
- package/{chunk-57TLKTVZ.js → chunk-E5KY7RAY.js} +565 -103
- package/{chunk-G7IUT2V3.js → chunk-EBKHA63G.js} +103 -12
- package/{chunk-DGYCDA6W.js → chunk-F3XI6WQP.js} +17 -10
- package/{chunk-M3OZRQNH.js → chunk-F6YWDVIB.js} +1 -1
- package/{chunk-PR2LAQAC.js → chunk-FFYE5ATM.js} +4 -4
- package/{chunk-6NNDUDAZ.js → chunk-FZKA3XFA.js} +11 -11
- package/{chunk-MNEZUL5S.js → chunk-G22P367E.js} +31 -14
- package/{chunk-6OQMSPB7.js → chunk-GDUC4VS2.js} +7 -7
- package/{chunk-R6Z5S5GA.js → chunk-GXXY2NL3.js} +16 -14
- package/{chunk-U2HBB7RS.js → chunk-H7ZYKHAZ.js} +27 -7
- package/{chunk-3U44JB3O.js → chunk-HCNOO374.js} +1 -1
- package/{chunk-HSSBDZLD.js → chunk-HOM6LTEW.js} +1 -1
- package/{chunk-S2NTVGA2.js → chunk-I2OYPD3Y.js} +1 -1
- package/{chunk-TPG2DPN2.js → chunk-IJTXNLQE.js} +9 -9
- package/{chunk-ALAES342.js → chunk-IUMS6F53.js} +2 -2
- package/{chunk-547ENH5T.js → chunk-IUTUWIKE.js} +2 -2
- package/{chunk-S6K5F3KP.js → chunk-JBWXPACD.js} +1 -1
- package/{chunk-XAG3FWBE.js → chunk-KZPEGO6D.js} +1 -1
- package/{chunk-RBPUNSG5.js → chunk-LYDEFPQP.js} +18 -108
- package/{chunk-OWKNSIXL.js → chunk-MECDGHLK.js} +271 -66
- package/{chunk-FJSNBZXR.js → chunk-MM73SP4K.js} +1 -1
- package/{chunk-XSW4EXQV.js → chunk-MYOSN6BT.js} +2 -2
- package/{chunk-ZEVQHCLM.js → chunk-MYPKBJJO.js} +2 -2
- package/{chunk-DBUR22G5.js → chunk-N2JROHD3.js} +4 -4
- package/{chunk-ATEKLSLR.js → chunk-O6IPRAVV.js} +14 -9
- package/{chunk-PPJYZRSQ.js → chunk-OX6GNNVT.js} +6 -1
- package/{chunk-WFVASLQT.js → chunk-P3IZUMIC.js} +1 -1
- package/{chunk-FPBJM2BW.js → chunk-PGKA77TZ.js} +26 -20
- package/{chunk-IONGMVPY.js → chunk-PRMEU7BT.js} +229 -7
- package/{chunk-OJ45MEEI.js → chunk-PROOOQZ3.js} +1 -1
- package/{chunk-4I2MXV5Q.js → chunk-PVFYPUIM.js} +2 -0
- package/{chunk-5FUN7EG4.js → chunk-RD3QLZQV.js} +83 -47
- package/chunk-RETQOQ4D.js +33394 -0
- package/{chunk-CMMI3DAT.js → chunk-RM4UMFY4.js} +33 -26
- package/{chunk-262R3XNN.js → chunk-S2MHR4PU.js} +151 -5
- package/{chunk-DEA37IUY.js → chunk-T6VROBY7.js} +2 -2
- package/{chunk-M4SFKP5L.js → chunk-TEMLHVGX.js} +1 -1
- package/{chunk-3QIYD3VM.js → chunk-TRHJ4NJB.js} +61 -792
- package/{chunk-OBIC6EG7.js → chunk-TWTJV35S.js} +1 -1
- package/{chunk-TCZ2VJZQ.js → chunk-U3G7RRXJ.js} +5 -5
- package/{chunk-F6Z6ZCUV.js → chunk-UFC4J7OY.js} +3 -3
- package/{chunk-5YMA6DDZ.js → chunk-UHW6SCVK.js} +1 -1
- package/{chunk-4N6G2CKP.js → chunk-ULLHVDTZ.js} +46 -1
- package/{chunk-XFXFPUO7.js → chunk-VM72HKW2.js} +7 -7
- package/{chunk-MHHLABT3.js → chunk-VREG6ANQ.js} +102 -99
- package/chunk-VSRISJXZ.js +107 -0
- package/chunk-WDWZPASX.js +29 -0
- package/{chunk-ILHQ2AXT.js → chunk-WRKMXMU7.js} +2 -0
- package/chunk-X7IA2B7R.js +166 -0
- package/{chunk-5ZMIIR23.js → chunk-XBAEM4RI.js} +7 -0
- package/{chunk-4JVNURX4.js → chunk-XS5A3EKX.js} +1 -23
- package/{chunk-N5Z2V73W.js → chunk-Y2MF4DCJ.js} +1 -1
- package/{chunk-KUDCKVYQ.js → chunk-Y5OWZQMJ.js} +28 -19
- package/{chunk-TI2EPRHE.js → chunk-YGCOJNFZ.js} +3 -3
- package/{chunk-JQZRSXS5.js → chunk-YGDYYFRX.js} +9 -13
- package/{chunk-X7QAIY5B.js → chunk-Z2WZAE4P.js} +128 -150
- package/chunk-Z6YTCDU4.js +24 -0
- package/{chunk-RRDRQOEC.js → chunk-ZEKUFJLW.js} +81 -66
- package/{chunk-EVGU5P4U.js → chunk-ZVOL2MAJ.js} +1 -1
- package/{cliAgentConfigHelpers-BTRHMPW2.js → cliAgentConfigHelpers-U5OAVAKQ.js} +2 -2
- package/{cliAuthorityBrokerClient-XHH7MH2P.js → cliAuthorityBrokerClient-S42VMGB6.js} +1 -1
- package/{cliLocalAgentRecordReader-H3HYQRRR.js → cliLocalAgentRecordReader-HVZAQCUD.js} +29 -25
- package/{commandRegistry-35EMLPIZ.js → commandRegistry-FIXBZJHE.js} +89 -85
- package/{contentThunks-BCNMGA5J.js → contentThunks-U6OC4R2N.js} +23 -22
- package/{cooldownCommands-YB5H5BBK.js → cooldownCommands-U7XSRVJP.js} +1 -1
- package/{createAgentAutomationAction-HEU4KOYF.js → createAgentAutomationAction-IP4LFN3W.js} +23 -22
- package/{createDialogAction-5DSL5ESZ.js → createDialogAction-IAGQJ3LH.js} +24 -23
- package/{createPageAction-BBZ25AFI.js → createPageAction-AZ3UIFKA.js} +24 -23
- package/{dbSlice-XRUZOGSU.js → dbSlice-DKKMJJYY.js} +8 -7
- package/{deleteFile-6URDHYRB.js → deleteFile-TQSONMVU.js} +7 -4
- package/{dialogCommands-6SZD4TYP.js → dialogCommands-PCDRMBWG.js} +30 -26
- package/dialogMessageRecord-OAV77LT7.js +7 -0
- package/{dialogNotifyCommand-SHGPCU22.js → dialogNotifyCommand-O35MWMOS.js} +3 -3
- package/{dialogSlice-QJ5PQOM3.js → dialogSlice-QAKYN4DE.js} +22 -21
- package/{dialogUsageCommand-W2WCSGKF.js → dialogUsageCommand-2SSLTXKO.js} +2 -2
- package/{docCreateCommands-25E6PGN3.js → docCreateCommands-CFQFZOAD.js} +26 -22
- package/{docDeleteCommands-F7ZVGEHW.js → docDeleteCommands-5CPNTIIS.js} +27 -23
- package/{docReadCommands-JY2E5XEN.js → docReadCommands-XQILYSAJ.js} +26 -22
- package/{docStore-XJ4UMU3C.js → docStore-GIVRT7TQ.js} +10 -9
- package/{docUpdateCommands-OZ4CUSIQ.js → docUpdateCommands-VETKSUDD.js} +26 -22
- package/{handleSendMessageAction-YHAOXARI.js → handleSendMessageAction-HKIW4ZNO.js} +48 -45
- package/{hostCredentialCreate-62AWCBQC.js → hostCredentialCreate-6VDJFNDO.js} +81 -68
- package/index.js +8 -8
- package/{lib-OT5OTXRU.js → lib-62SWPXNF.js} +3 -7
- package/{localRuntimeAdapter-KNQNNHUM.js → localRuntimeAdapter-BQ4F5PZV.js} +81 -69
- package/{localRuntimeAuthority-IBJAT62G.js → localRuntimeAuthority-WCNA4A3G.js} +4 -2
- package/{localRuntimeDb-N7KHDXS2.js → localRuntimeDb-CRNIBOOM.js} +1 -1
- package/{machineCommands-X2FMPSV4.js → machineCommands-K6XIGOAD.js} +77 -65
- package/{machineWsRunDispatch-XHTPOYVJ.js → machineWsRunDispatch-4OO7Z6UM.js} +77 -65
- package/mcpLocalAuthorizeCommand-ZP6ESAGE.js +106 -0
- package/{memberThunks-7Y3OYSJQ.js → memberThunks-PBJPZ2JU.js} +15 -10
- package/{overlay-BBQZXGYI.js → overlay-JA3SPVUS.js} +5 -3
- package/package.json +1 -1
- package/{projectArchive-NPQ3YOAV.js → projectArchive-G7AOQPRW.js} +24 -23
- package/{providerPresetApply-WHAMP2D5.js → providerPresetApply-OPBCAONX.js} +1 -1
- package/{providerRegistry-ZI2KORJ7.js → providerRegistry-J2HCVTHE.js} +1 -1
- package/{read-TYMBGEXO.js → read-JEGPITEW.js} +6 -5
- package/{readDocTool-SKQVHBLO.js → readDocTool-TE3XIU4Y.js} +1 -1
- package/{readlineWorkspace-77PILYDH.js → readlineWorkspace-XMPGXR77.js} +2935 -2376
- package/{removeDialogAgentAction-F5QE2O2B.js → removeDialogAgentAction-CX3OAH4Y.js} +14 -13
- package/{runAgentClientLoop-XNKAXUKU.js → runAgentClientLoop-HQJPDFGQ.js} +65 -45
- package/{runtimeDoctorCommands-RRKPBGVO.js → runtimeDoctorCommands-GUH2YGMH.js} +3 -3
- package/{secretCommands-KZWBZIYS.js → secretCommands-NJXFVHZU.js} +2 -2
- package/{setDialogExtraReferencesAction-72L27ERM.js → setDialogExtraReferencesAction-CGM67EEQ.js} +11 -10
- package/{setPrimaryDialogAgentAction-GJJDUSGJ.js → setPrimaryDialogAgentAction-3ABWPPXR.js} +14 -13
- package/{settingThunks-ZRGWVGZD.js → settingThunks-AY76OHYX.js} +176 -57
- package/{skillDiscovery-BHHPCUHZ.js → skillDiscovery-MDDKPTW3.js} +4 -3
- package/{spaceCommands-TOGSGCPS.js → spaceCommands-G63QGYQO.js} +25 -21
- package/{streamAgentChatTurn-IARUEZPU.js → streamAgentChatTurn-E3XH2KFD.js} +127 -85
- package/{switchDialogAgentAction-IIJBPND3.js → switchDialogAgentAction-G6EZRKCQ.js} +12 -11
- package/{tableCommands-FTAOCBTX.js → tableCommands-JI75ZHDI.js} +4 -1
- package/{toolApiClient-OGQEBQVX.js → toolApiClient-62UUPDUA.js} +3 -5
- package/{tools-5UWS65PB.js → tools-7RSX22FT.js} +41 -37
- package/{tuiRestart-2IL37YIB.js → tuiRestart-KAAA7TND.js} +2 -2
- package/{tuiSummaryLlmCaller-R4H3ZZ52.js → tuiSummaryLlmCaller-BVNHMWLR.js} +5 -5
- package/{updateCommands-CPATDG6J.js → updateCommands-ASK5XYPH.js} +3 -3
- package/{updateDialogTitleAction-G6C6XVNV.js → updateDialogTitleAction-SEWV252V.js} +23 -22
- package/{usageCommand-2BF74MKF.js → usageCommand-JVT5J3DC.js} +2 -2
- package/{usageRebuildCommand-UHB55BQM.js → usageRebuildCommand-IZYYUTEW.js} +3 -3
- package/webapi-24RZDIIQ.js +2488 -0
- package/{windowsSelfUpdate-ZFD6J5HF.js → windowsSelfUpdate-BSDIS2J5.js} +2 -2
- package/workContext-MM3P5GP5.js +13 -0
- package/workContextAccess-UZHDLBUR.js +11 -0
- package/workContextWriteNotice-YCSSMHN4.js +7 -0
- package/chunk-ZXF6D3I6.js +0 -359
- package/{accountResolver-QETKNC7T.js → accountResolver-EK2S4PWF.js} +3 -3
- package/{localDialogRead-CCOCVGAP.js → localDialogRead-AV2VKKPG.js} +0 -0
- package/{workloadLifecycle-HFJIN5IZ.js → workloadLifecycle-YIZ7KLUP.js} +5 -5
|
@@ -26,9 +26,200 @@ import {
|
|
|
26
26
|
isRecord
|
|
27
27
|
} from "./chunk-KUG52IAP.js";
|
|
28
28
|
|
|
29
|
+
// packages/cli/mcp/mcpApprovalTransport.ts
|
|
30
|
+
import { randomUUID, createHash } from "node:crypto";
|
|
31
|
+
|
|
32
|
+
// packages/cli/client/inheritedApprovalChannel.ts
|
|
33
|
+
function sendInheritedApproval(channel, kind, message, failed) {
|
|
34
|
+
if (channel.connected === false || !channel.send) {
|
|
35
|
+
failed();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
channel.send({ kind, ...message }, (error) => {
|
|
40
|
+
if (error) failed();
|
|
41
|
+
});
|
|
42
|
+
} catch {
|
|
43
|
+
failed();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function bindInheritedApprovalLifetime(channel, close, signal) {
|
|
47
|
+
for (const event of ["disconnect", "exit", "error"]) channel.on(event, close);
|
|
48
|
+
signal?.addEventListener("abort", close, { once: true });
|
|
49
|
+
return () => {
|
|
50
|
+
for (const event of ["disconnect", "exit", "error"]) channel.removeListener(event, close);
|
|
51
|
+
signal?.removeEventListener("abort", close);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// packages/cli/mcp/mcpApprovalTransport.ts
|
|
56
|
+
var KIND = "nolo.mcp-approval.v1";
|
|
57
|
+
var TTL = 6e4;
|
|
58
|
+
var MAX = 256;
|
|
59
|
+
function canonical(value) {
|
|
60
|
+
if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
|
|
61
|
+
if (value && typeof value === "object") return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${canonical(value[key])}`).join(",")}}`;
|
|
62
|
+
return JSON.stringify(value);
|
|
63
|
+
}
|
|
64
|
+
function snapshot(preview) {
|
|
65
|
+
return createHash("sha256").update(JSON.stringify(preview)).digest("hex");
|
|
66
|
+
}
|
|
67
|
+
function valid(preview, binding) {
|
|
68
|
+
const b = preview?.binding;
|
|
69
|
+
return b && b.authenticatedUserId === binding.ownerUserId && b.agentKey === binding.agentKey && typeof b.dialogId === "string" && b.dialogId.length > 0 && b.placement?.kind === "local" && typeof b.connectionId === "string" && Number.isInteger(b.connectionRevision) && b.connectionRevision > 0 && typeof b.catalogRevision === "string" && typeof b.toolName === "string" && /^[a-f0-9]{64}$/.test(b.argumentsDigest) && preview.arguments && typeof preview.arguments === "object" && !Array.isArray(preview.arguments) && createHash("sha256").update(canonical(preview.arguments)).digest("hex") === b.argumentsDigest && Number.isFinite(preview.expiresAt) && preview.expiresAt > Date.now() && preview.expiresAt <= Date.now() + TTL;
|
|
70
|
+
}
|
|
71
|
+
function attachMcpApprovalHost(channel, host) {
|
|
72
|
+
const binding = Object.freeze({ ...host.binding });
|
|
73
|
+
let closed = false;
|
|
74
|
+
let count = 0;
|
|
75
|
+
const seen = /* @__PURE__ */ new Set();
|
|
76
|
+
const active = /* @__PURE__ */ new Map();
|
|
77
|
+
const send2 = (message) => sendInheritedApproval(channel, KIND, message, close);
|
|
78
|
+
let unbind = () => {
|
|
79
|
+
};
|
|
80
|
+
const close = () => {
|
|
81
|
+
if (closed) return;
|
|
82
|
+
closed = true;
|
|
83
|
+
for (const controller of active.values()) controller.abort();
|
|
84
|
+
active.clear();
|
|
85
|
+
sendInheritedApproval(channel, KIND, { type: "revoke" }, () => {
|
|
86
|
+
});
|
|
87
|
+
channel.removeListener("message", receive);
|
|
88
|
+
unbind();
|
|
89
|
+
};
|
|
90
|
+
const receive = (m) => {
|
|
91
|
+
if (closed || m?.kind !== KIND) return;
|
|
92
|
+
if (m.type === "hello") {
|
|
93
|
+
send2({ type: "binding", binding });
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (m.type === "cancel") {
|
|
97
|
+
active.get(m.id)?.abort();
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (m.type !== "request") return;
|
|
101
|
+
if (++count > MAX || typeof m.id !== "string" || seen.has(m.id)) {
|
|
102
|
+
close();
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
seen.add(m.id);
|
|
106
|
+
let preview;
|
|
107
|
+
try {
|
|
108
|
+
if (typeof m.snapshot !== "string" || JSON.stringify(m.preview).length > 262144) throw new Error("invalid preview");
|
|
109
|
+
preview = structuredClone(m.preview);
|
|
110
|
+
if (m.runId !== binding.runId || !valid(preview, binding) || snapshot(preview) !== m.snapshot) throw new Error("binding mismatch");
|
|
111
|
+
} catch {
|
|
112
|
+
send2({ type: "decision", id: m.id, runId: binding.runId, snapshot: m.snapshot, decision: "deny" });
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const controller = new AbortController();
|
|
116
|
+
active.set(m.id, controller);
|
|
117
|
+
const timer = setTimeout(() => controller.abort(), Math.max(0, preview.expiresAt - Date.now()));
|
|
118
|
+
void new Promise((resolve2) => {
|
|
119
|
+
controller.signal.addEventListener("abort", () => resolve2("deny"), { once: true });
|
|
120
|
+
Promise.resolve().then(() => closed || controller.signal.aborted ? "deny" : host.confirm(preview, controller.signal, { runId: binding.runId, requestId: m.id })).then(resolve2, () => resolve2("unavailable"));
|
|
121
|
+
}).then((decision) => {
|
|
122
|
+
clearTimeout(timer);
|
|
123
|
+
active.delete(m.id);
|
|
124
|
+
if (!closed) send2({
|
|
125
|
+
type: "decision",
|
|
126
|
+
id: m.id,
|
|
127
|
+
runId: binding.runId,
|
|
128
|
+
snapshot: m.snapshot,
|
|
129
|
+
decision: !controller.signal.aborted && Date.now() < preview.expiresAt ? decision : "deny"
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
channel.on("message", receive);
|
|
134
|
+
unbind = bindInheritedApprovalLifetime(channel, close, host.signal);
|
|
135
|
+
if (host.signal.aborted || channel.connected === false) close();
|
|
136
|
+
return close;
|
|
137
|
+
}
|
|
138
|
+
function createMcpApprovalChild(channel) {
|
|
139
|
+
const lifetime = new AbortController();
|
|
140
|
+
let binding;
|
|
141
|
+
let count = 0;
|
|
142
|
+
let closed = false;
|
|
143
|
+
const pending = /* @__PURE__ */ new Map();
|
|
144
|
+
const readyResolvers = /* @__PURE__ */ new Set();
|
|
145
|
+
let unbind = () => {
|
|
146
|
+
};
|
|
147
|
+
const close = () => {
|
|
148
|
+
if (closed) return;
|
|
149
|
+
closed = true;
|
|
150
|
+
lifetime.abort();
|
|
151
|
+
for (const entry of pending.values()) entry.finish("unavailable");
|
|
152
|
+
for (const resolve2 of readyResolvers) resolve2();
|
|
153
|
+
readyResolvers.clear();
|
|
154
|
+
channel.removeListener("message", receive);
|
|
155
|
+
unbind();
|
|
156
|
+
};
|
|
157
|
+
const send2 = (message) => sendInheritedApproval(channel, KIND, message, close);
|
|
158
|
+
const receive = (m) => {
|
|
159
|
+
if (closed || m?.kind !== KIND) return;
|
|
160
|
+
if (m.type === "revoke") {
|
|
161
|
+
close();
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (m.type === "binding") {
|
|
165
|
+
if (binding || !m.binding || typeof m.binding.runId !== "string" || typeof m.binding.ownerUserId !== "string" || typeof m.binding.agentKey !== "string") {
|
|
166
|
+
close();
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
binding = Object.freeze({ ...m.binding });
|
|
170
|
+
for (const resolve2 of readyResolvers) resolve2();
|
|
171
|
+
readyResolvers.clear();
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (m.type !== "decision") return;
|
|
175
|
+
const entry = pending.get(m.id);
|
|
176
|
+
if (!entry) return;
|
|
177
|
+
const matches = binding && m.runId === binding.runId && m.snapshot === entry.snapshot && Date.now() < entry.expiresAt;
|
|
178
|
+
entry.finish(!matches ? "deny" : m.decision === "approve" ? "approve" : m.decision === "unavailable" ? "unavailable" : "deny");
|
|
179
|
+
};
|
|
180
|
+
channel.on("message", receive);
|
|
181
|
+
unbind = bindInheritedApprovalLifetime(channel, close);
|
|
182
|
+
send2({ type: "hello" });
|
|
183
|
+
const confirm = async (input, signal) => {
|
|
184
|
+
if (closed || signal.aborted || ++count > MAX) return "unavailable";
|
|
185
|
+
if (!binding) await new Promise((resolve2) => {
|
|
186
|
+
const done = () => {
|
|
187
|
+
clearTimeout(timer);
|
|
188
|
+
readyResolvers.delete(done);
|
|
189
|
+
signal.removeEventListener("abort", done);
|
|
190
|
+
resolve2();
|
|
191
|
+
};
|
|
192
|
+
const timer = setTimeout(done, Math.max(0, Math.min(TTL, input.expiresAt - Date.now())));
|
|
193
|
+
readyResolvers.add(done);
|
|
194
|
+
signal.addEventListener("abort", done, { once: true });
|
|
195
|
+
});
|
|
196
|
+
if (closed || !binding) return "unavailable";
|
|
197
|
+
if (signal.aborted || !valid(input, binding)) return "deny";
|
|
198
|
+
const preview = structuredClone(input), id = randomUUID(), digest = snapshot(preview);
|
|
199
|
+
return new Promise((resolve2) => {
|
|
200
|
+
const abort = () => {
|
|
201
|
+
send2({ type: "cancel", id });
|
|
202
|
+
finish("deny");
|
|
203
|
+
};
|
|
204
|
+
const timer = setTimeout(abort, Math.max(0, preview.expiresAt - Date.now()));
|
|
205
|
+
const finish = (value) => {
|
|
206
|
+
if (!pending.delete(id)) return;
|
|
207
|
+
clearTimeout(timer);
|
|
208
|
+
signal.removeEventListener("abort", abort);
|
|
209
|
+
resolve2(value);
|
|
210
|
+
};
|
|
211
|
+
pending.set(id, { finish, snapshot: digest, expiresAt: preview.expiresAt });
|
|
212
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
213
|
+
if (signal.aborted) abort();
|
|
214
|
+
else send2({ type: "request", id, runId: binding.runId, snapshot: digest, preview });
|
|
215
|
+
});
|
|
216
|
+
};
|
|
217
|
+
return { confirm, signal: lifetime.signal, close };
|
|
218
|
+
}
|
|
219
|
+
|
|
29
220
|
// packages/cli/client/originShellApprovalTransport.ts
|
|
30
221
|
import { realpathSync } from "node:fs";
|
|
31
|
-
import { randomUUID } from "node:crypto";
|
|
222
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
32
223
|
|
|
33
224
|
// packages/cli/client/originShellApprovalBridge.ts
|
|
34
225
|
import { isAbsolute } from "node:path";
|
|
@@ -45,7 +236,7 @@ function createOriginShellApprovalBridge(deps) {
|
|
|
45
236
|
}
|
|
46
237
|
const requests = /* @__PURE__ */ new Map();
|
|
47
238
|
const fail = (reason) => ({ ok: false, reason });
|
|
48
|
-
const
|
|
239
|
+
const snapshot2 = (request) => ({ ok: true, request: { ...request } });
|
|
49
240
|
const validIdentity = (call) => {
|
|
50
241
|
try {
|
|
51
242
|
return IDENTITY_KEYS.every((key) => typeof call[key] === "string" && call[key].trim().length > 0 && call[key] === binding[key]) && isAbsolute(call.workspaceRoot) && deps.resolveWorkspace(call.workspaceRoot) === binding.workspaceRoot;
|
|
@@ -71,7 +262,7 @@ function createOriginShellApprovalBridge(deps) {
|
|
|
71
262
|
const request = requests.get(id);
|
|
72
263
|
if (!request) return fail("unknown_request");
|
|
73
264
|
if (!CALL_KEYS.every((key) => request[key] === call[key])) return fail("call_mismatch");
|
|
74
|
-
return
|
|
265
|
+
return snapshot2(request);
|
|
75
266
|
};
|
|
76
267
|
return {
|
|
77
268
|
request(call) {
|
|
@@ -99,7 +290,7 @@ function createOriginShellApprovalBridge(deps) {
|
|
|
99
290
|
state: "pending"
|
|
100
291
|
};
|
|
101
292
|
requests.set(requestId, request);
|
|
102
|
-
return
|
|
293
|
+
return snapshot2(request);
|
|
103
294
|
},
|
|
104
295
|
decide(id, call, decision) {
|
|
105
296
|
const result = lookup(id, call);
|
|
@@ -113,7 +304,7 @@ function createOriginShellApprovalBridge(deps) {
|
|
|
113
304
|
state: decision === "approve" ? "approved" : "denied"
|
|
114
305
|
};
|
|
115
306
|
requests.set(id, request);
|
|
116
|
-
return
|
|
307
|
+
return snapshot2(request);
|
|
117
308
|
},
|
|
118
309
|
revoke() {
|
|
119
310
|
for (const [id, request] of requests) {
|
|
@@ -129,15 +320,15 @@ function createOriginShellApprovalBridge(deps) {
|
|
|
129
320
|
if (result.request.state !== "approved") return fail(result.request.state);
|
|
130
321
|
const request = { ...result.request, state: "consumed" };
|
|
131
322
|
requests.set(id, request);
|
|
132
|
-
return
|
|
323
|
+
return snapshot2(request);
|
|
133
324
|
}
|
|
134
325
|
};
|
|
135
326
|
}
|
|
136
327
|
|
|
137
328
|
// packages/cli/client/originShellApprovalTransport.ts
|
|
138
|
-
var
|
|
139
|
-
var
|
|
140
|
-
var
|
|
329
|
+
var KIND2 = "nolo.shell-approval.v1";
|
|
330
|
+
var MAX2 = 256;
|
|
331
|
+
var TTL2 = 6e4;
|
|
141
332
|
var NOTICE = "Executes with this local user's reachable permissions; workspace is NOT a directory sandbox.";
|
|
142
333
|
function payloadCall(payload, binding) {
|
|
143
334
|
if (typeof payload !== "string" || payload.length > 262144) throw new Error("Invalid approval payload");
|
|
@@ -149,17 +340,25 @@ function payloadCall(payload, binding) {
|
|
|
149
340
|
}
|
|
150
341
|
function send(channel, message) {
|
|
151
342
|
if (channel.connected === false || !channel.send) throw new Error("Approval channel disconnected");
|
|
152
|
-
channel.send({ kind:
|
|
343
|
+
channel.send({ kind: KIND2, ...message });
|
|
344
|
+
}
|
|
345
|
+
var liveApprovalHosts = /* @__PURE__ */ new Set();
|
|
346
|
+
function hasLiveShellApprovalHosts() {
|
|
347
|
+
return liveApprovalHosts.size > 0;
|
|
153
348
|
}
|
|
154
349
|
function attachShellApprovalHost(channel, host) {
|
|
155
350
|
const binding = Object.freeze({ ...host.binding });
|
|
156
351
|
const bridge = createOriginShellApprovalBridge({ binding, resolveWorkspace: realpathSync });
|
|
352
|
+
const connection = {};
|
|
157
353
|
let closed = false;
|
|
158
354
|
let count = 0;
|
|
159
355
|
const active = /* @__PURE__ */ new Set();
|
|
356
|
+
let unbindLifetime = () => {
|
|
357
|
+
};
|
|
160
358
|
const close = () => {
|
|
161
359
|
if (closed) return;
|
|
162
360
|
closed = true;
|
|
361
|
+
liveApprovalHosts.delete(connection);
|
|
163
362
|
bridge.revoke();
|
|
164
363
|
for (const controller of active) controller.abort();
|
|
165
364
|
active.clear();
|
|
@@ -168,13 +367,10 @@ function attachShellApprovalHost(channel, host) {
|
|
|
168
367
|
} catch {
|
|
169
368
|
}
|
|
170
369
|
channel.removeListener("message", receive);
|
|
171
|
-
|
|
172
|
-
channel.removeListener("exit", close);
|
|
173
|
-
channel.removeListener("error", close);
|
|
174
|
-
host.signal.removeEventListener("abort", close);
|
|
370
|
+
unbindLifetime();
|
|
175
371
|
};
|
|
176
372
|
const receive = (message) => {
|
|
177
|
-
if (closed || message?.kind !==
|
|
373
|
+
if (closed || message?.kind !== KIND2) return;
|
|
178
374
|
if (message.type === "hello") {
|
|
179
375
|
try {
|
|
180
376
|
send(channel, { type: "binding", binding });
|
|
@@ -184,7 +380,7 @@ function attachShellApprovalHost(channel, host) {
|
|
|
184
380
|
return;
|
|
185
381
|
}
|
|
186
382
|
if (message.type !== "request") return;
|
|
187
|
-
if (++count >
|
|
383
|
+
if (++count > MAX2 || typeof message.id !== "string" || message.id.length > 100) {
|
|
188
384
|
close();
|
|
189
385
|
return;
|
|
190
386
|
}
|
|
@@ -241,14 +437,12 @@ function attachShellApprovalHost(channel, host) {
|
|
|
241
437
|
})();
|
|
242
438
|
};
|
|
243
439
|
channel.on("message", receive);
|
|
244
|
-
channel
|
|
245
|
-
|
|
246
|
-
channel.
|
|
247
|
-
host.signal.addEventListener("abort", close, { once: true });
|
|
248
|
-
if (host.signal.aborted) close();
|
|
440
|
+
unbindLifetime = bindInheritedApprovalLifetime(channel, close, host.signal);
|
|
441
|
+
liveApprovalHosts.add(connection);
|
|
442
|
+
if (host.signal.aborted || channel.connected === false) close();
|
|
249
443
|
return close;
|
|
250
444
|
}
|
|
251
|
-
function createShellApprovalChild(channel, timeoutMs =
|
|
445
|
+
function createShellApprovalChild(channel, timeoutMs = TTL2) {
|
|
252
446
|
let closed = false;
|
|
253
447
|
let binding;
|
|
254
448
|
let count = 0;
|
|
@@ -267,7 +461,7 @@ function createShellApprovalChild(channel, timeoutMs = TTL) {
|
|
|
267
461
|
channel.removeListener("disconnect", close);
|
|
268
462
|
};
|
|
269
463
|
const receive = (message) => {
|
|
270
|
-
if (closed || message?.kind !==
|
|
464
|
+
if (closed || message?.kind !== KIND2) return;
|
|
271
465
|
if (message.type === "revoke") {
|
|
272
466
|
close();
|
|
273
467
|
return;
|
|
@@ -285,7 +479,7 @@ function createShellApprovalChild(channel, timeoutMs = TTL) {
|
|
|
285
479
|
if (!entry) return;
|
|
286
480
|
pending.delete(message.id);
|
|
287
481
|
clearTimeout(entry.timer);
|
|
288
|
-
if (!binding || message.runId !== binding.runId || message.approved !== true || typeof message.ticket !== "string" || !Number.isFinite(message.expiresAt) || message.expiresAt <= Date.now() || message.expiresAt > Date.now() +
|
|
482
|
+
if (!binding || message.runId !== binding.runId || message.approved !== true || typeof message.ticket !== "string" || !Number.isFinite(message.expiresAt) || message.expiresAt <= Date.now() || message.expiresAt > Date.now() + TTL2 || tickets.has(message.ticket)) {
|
|
289
483
|
entry.reject(new Error("Shell approval denied"));
|
|
290
484
|
return;
|
|
291
485
|
}
|
|
@@ -303,17 +497,17 @@ function createShellApprovalChild(channel, timeoutMs = TTL) {
|
|
|
303
497
|
close,
|
|
304
498
|
authority: {
|
|
305
499
|
async request(payload) {
|
|
306
|
-
if (++count >
|
|
307
|
-
const deadline = Date.now() + Math.min(timeoutMs,
|
|
500
|
+
if (++count > MAX2) throw new Error("Shell approval capacity exceeded");
|
|
501
|
+
const deadline = Date.now() + Math.min(timeoutMs, TTL2);
|
|
308
502
|
while (!binding && !closed && Date.now() < deadline) await new Promise((resolve2) => setTimeout(resolve2, 5));
|
|
309
503
|
if (closed || !binding) throw new Error("Shell approval unavailable");
|
|
310
504
|
payloadCall(payload, binding);
|
|
311
|
-
const id =
|
|
505
|
+
const id = randomUUID2();
|
|
312
506
|
return new Promise((resolve2, reject) => {
|
|
313
507
|
const timer = setTimeout(() => {
|
|
314
508
|
pending.delete(id);
|
|
315
509
|
reject(new Error("Shell approval timeout"));
|
|
316
|
-
}, Math.min(timeoutMs,
|
|
510
|
+
}, Math.min(timeoutMs, TTL2));
|
|
317
511
|
pending.set(id, { payload, resolve: resolve2, reject, timer });
|
|
318
512
|
try {
|
|
319
513
|
send(channel, { type: "request", id, runId: binding.runId, payload });
|
|
@@ -456,7 +650,7 @@ function redactLogLines(lines, options = {}) {
|
|
|
456
650
|
import { hostname as nodeHostname, homedir as nodeHomedir } from "node:os";
|
|
457
651
|
import { dirname, isAbsolute as isAbsolute2, join as join2, resolve } from "node:path";
|
|
458
652
|
import * as nodeFs2 from "node:fs";
|
|
459
|
-
import { randomUUID as
|
|
653
|
+
import { randomUUID as randomUUID3, createHash as createHash2 } from "node:crypto";
|
|
460
654
|
import { execFileSync as nodeExecFileSync, spawn as nodeSpawn } from "node:child_process";
|
|
461
655
|
|
|
462
656
|
// packages/cli/client/hostMemory.ts
|
|
@@ -705,7 +899,7 @@ var HostMemoryAdmissionError = class extends Error {
|
|
|
705
899
|
};
|
|
706
900
|
function assertHostMemoryAdmission(deps = {}) {
|
|
707
901
|
const readMem = deps.readHostMemory ?? readHostMemory;
|
|
708
|
-
const
|
|
902
|
+
const snapshot2 = readMem(deps.hostMemoryDeps);
|
|
709
903
|
const minAvailableMb = deps.minAvailableMb ?? LOCAL_AGENT_RUN_MIN_AVAILABLE_MB;
|
|
710
904
|
const startupWindowMs = deps.startupWindowMs ?? STARTUP_WINDOW_MS;
|
|
711
905
|
const reservedMbPerRun = deps.reservedMbPerRun ?? STARTUP_WINDOW_RESERVED_MB_PER_RUN;
|
|
@@ -713,7 +907,7 @@ function assertHostMemoryAdmission(deps = {}) {
|
|
|
713
907
|
for (const [name, value] of Object.entries({ minAvailableMb, startupWindowMs, reservedMbPerRun, now })) {
|
|
714
908
|
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) throw new Error(`Invalid ${name}`);
|
|
715
909
|
}
|
|
716
|
-
if (!
|
|
910
|
+
if (!snapshot2) {
|
|
717
911
|
throw new HostMemoryAdmissionError(
|
|
718
912
|
`[host-memory-admission] \u65E0\u6CD5\u6D4B\u5B9A\u672C\u673A\u53EF\u7528\u5185\u5B58\uFF08\u5FEB\u7167\u4E3A null\uFF09\uFF0C\u62D2\u7EDD\u672C\u5730 fork\u3002\u9700\u786E\u4FDD /proc/meminfo \u6216 OS \u5185\u5B58\u6307\u6807\u53EF\u8BFB\u3002`,
|
|
719
913
|
{
|
|
@@ -727,19 +921,19 @@ function assertHostMemoryAdmission(deps = {}) {
|
|
|
727
921
|
}
|
|
728
922
|
);
|
|
729
923
|
}
|
|
730
|
-
if (!["cgroup", "proc-meminfo", "os"].includes(
|
|
924
|
+
if (!["cgroup", "proc-meminfo", "os"].includes(snapshot2.source)) throw new Error("Unknown host memory source");
|
|
731
925
|
let effectiveAvailableMb = null;
|
|
732
926
|
let limitingSource = "host";
|
|
733
|
-
if (
|
|
734
|
-
const cgroupAvail =
|
|
735
|
-
const hostAvail =
|
|
927
|
+
if (snapshot2.source === "cgroup") {
|
|
928
|
+
const cgroupAvail = snapshot2.availableMb;
|
|
929
|
+
const hostAvail = snapshot2.hostAvailableMb;
|
|
736
930
|
if (cgroupAvail === null || typeof cgroupAvail !== "number" || Number.isNaN(cgroupAvail) || !Number.isFinite(cgroupAvail) || cgroupAvail < 0) {
|
|
737
931
|
throw new HostMemoryAdmissionError(
|
|
738
932
|
`[host-memory-admission] cgroup \u914D\u989D\u5185\u5B58\u5360\u7528\u672A\u77E5\u6216\u65E0\u6548\uFF0C\u62D2\u7EDD\u65E0\u58F0\u5F53\u5145\u8DB3\u3002`,
|
|
739
933
|
{
|
|
740
934
|
effectiveAvailableMb: null,
|
|
741
935
|
requiredMinMb: minAvailableMb,
|
|
742
|
-
source:
|
|
936
|
+
source: snapshot2.source,
|
|
743
937
|
limitingSource: "cgroup",
|
|
744
938
|
activeStartupRuns: 0,
|
|
745
939
|
reservedStartupMb: 0,
|
|
@@ -751,7 +945,7 @@ function assertHostMemoryAdmission(deps = {}) {
|
|
|
751
945
|
throw new HostMemoryAdmissionError("[host-memory-admission] \u5BBF\u4E3B\u53EF\u7528\u5185\u5B58\u672A\u77E5\u6216\u65E0\u6548\uFF0C\u62D2\u7EDD\u672C\u5730 fork\u3002", {
|
|
752
946
|
effectiveAvailableMb: null,
|
|
753
947
|
requiredMinMb: minAvailableMb,
|
|
754
|
-
source:
|
|
948
|
+
source: snapshot2.source,
|
|
755
949
|
limitingSource: "host",
|
|
756
950
|
activeStartupRuns: 0,
|
|
757
951
|
reservedStartupMb: 0,
|
|
@@ -771,13 +965,13 @@ function assertHostMemoryAdmission(deps = {}) {
|
|
|
771
965
|
limitingSource = "cgroup";
|
|
772
966
|
}
|
|
773
967
|
} else {
|
|
774
|
-
if (
|
|
968
|
+
if (snapshot2.availableMb === null || typeof snapshot2.availableMb !== "number" || Number.isNaN(snapshot2.availableMb) || !Number.isFinite(snapshot2.availableMb) || snapshot2.availableMb < 0) {
|
|
775
969
|
throw new HostMemoryAdmissionError(
|
|
776
970
|
`[host-memory-admission] \u5BBF\u4E3B\u53EF\u7528\u5185\u5B58\u672A\u77E5\u6216\u65E0\u6548\uFF0C\u62D2\u7EDD\u65E0\u58F0\u5F53\u5145\u8DB3\u3002`,
|
|
777
971
|
{
|
|
778
972
|
effectiveAvailableMb: null,
|
|
779
973
|
requiredMinMb: minAvailableMb,
|
|
780
|
-
source:
|
|
974
|
+
source: snapshot2.source,
|
|
781
975
|
limitingSource: "host",
|
|
782
976
|
activeStartupRuns: 0,
|
|
783
977
|
reservedStartupMb: 0,
|
|
@@ -785,7 +979,7 @@ function assertHostMemoryAdmission(deps = {}) {
|
|
|
785
979
|
}
|
|
786
980
|
);
|
|
787
981
|
}
|
|
788
|
-
effectiveAvailableMb =
|
|
982
|
+
effectiveAvailableMb = snapshot2.availableMb;
|
|
789
983
|
limitingSource = "host";
|
|
790
984
|
}
|
|
791
985
|
let activeStartupRuns = 0;
|
|
@@ -797,7 +991,7 @@ function assertHostMemoryAdmission(deps = {}) {
|
|
|
797
991
|
{
|
|
798
992
|
effectiveAvailableMb,
|
|
799
993
|
requiredMinMb: minAvailableMb,
|
|
800
|
-
source:
|
|
994
|
+
source: snapshot2.source,
|
|
801
995
|
limitingSource,
|
|
802
996
|
activeStartupRuns: 0,
|
|
803
997
|
reservedStartupMb: 0,
|
|
@@ -812,7 +1006,7 @@ function assertHostMemoryAdmission(deps = {}) {
|
|
|
812
1006
|
{
|
|
813
1007
|
effectiveAvailableMb,
|
|
814
1008
|
requiredMinMb: minAvailableMb,
|
|
815
|
-
source:
|
|
1009
|
+
source: snapshot2.source,
|
|
816
1010
|
limitingSource,
|
|
817
1011
|
activeStartupRuns: 0,
|
|
818
1012
|
reservedStartupMb: 0,
|
|
@@ -828,7 +1022,7 @@ function assertHostMemoryAdmission(deps = {}) {
|
|
|
828
1022
|
{
|
|
829
1023
|
effectiveAvailableMb,
|
|
830
1024
|
requiredMinMb: minAvailableMb,
|
|
831
|
-
source:
|
|
1025
|
+
source: snapshot2.source,
|
|
832
1026
|
limitingSource,
|
|
833
1027
|
activeStartupRuns: 0,
|
|
834
1028
|
reservedStartupMb: 0,
|
|
@@ -850,7 +1044,7 @@ function assertHostMemoryAdmission(deps = {}) {
|
|
|
850
1044
|
{
|
|
851
1045
|
effectiveAvailableMb: netAvailableMb,
|
|
852
1046
|
requiredMinMb: minAvailableMb,
|
|
853
|
-
source:
|
|
1047
|
+
source: snapshot2.source,
|
|
854
1048
|
limitingSource,
|
|
855
1049
|
activeStartupRuns,
|
|
856
1050
|
reservedStartupMb,
|
|
@@ -863,7 +1057,7 @@ function assertHostMemoryAdmission(deps = {}) {
|
|
|
863
1057
|
effectiveAvailableMb: netAvailableMb,
|
|
864
1058
|
requiredMinMb: minAvailableMb,
|
|
865
1059
|
activeStartupRuns,
|
|
866
|
-
snapshot
|
|
1060
|
+
snapshot: snapshot2
|
|
867
1061
|
};
|
|
868
1062
|
}
|
|
869
1063
|
|
|
@@ -2159,7 +2353,7 @@ async function gcRunRecords(deps = {}, options = {}) {
|
|
|
2159
2353
|
if (artifact.publisher !== "run-result-v1" || !/^[A-Za-z0-9._-]+$/.test(record.runId) || !["pending", "bak"].includes(artifact.kind) || !new RegExp(`^${uuid}\\.${artifact.kind}$`).test(name) || artifact.path !== join2(runsDirForLegacy, prefix + name)) throw new Error("unsafe artifact ownership");
|
|
2160
2354
|
if (!fs.existsSync(artifact.path)) continue;
|
|
2161
2355
|
const stat = fs.lstatSync?.(artifact.path);
|
|
2162
|
-
if (!stat || !stat.isFile() || stat.isSymbolicLink() || fs.realpathSync?.(artifact.path) !== resolve(artifact.path) || String(stat.dev) !== artifact.dev || String(stat.ino) !== artifact.ino ||
|
|
2356
|
+
if (!stat || !stat.isFile() || stat.isSymbolicLink() || fs.realpathSync?.(artifact.path) !== resolve(artifact.path) || String(stat.dev) !== artifact.dev || String(stat.ino) !== artifact.ino || createHash2("sha256").update(fs.readFileSync(artifact.path)).digest("hex") !== artifact.sha256) {
|
|
2163
2357
|
throw new Error("artifact identity changed");
|
|
2164
2358
|
}
|
|
2165
2359
|
if (!tryUnlinkFile(fs, artifact.path)) artifactsOk = false;
|
|
@@ -2341,11 +2535,11 @@ function localWriterRecovery(record) {
|
|
|
2341
2535
|
function revokePreparedWriterLaunch(runId, attemptId, deps = {}) {
|
|
2342
2536
|
if (!/^[A-Za-z0-9_-]+$/.test(runId) || !attemptId) return "blocked";
|
|
2343
2537
|
return withRunRecordLock("local-writer-admission", deps, () => {
|
|
2344
|
-
const
|
|
2345
|
-
if (!
|
|
2538
|
+
const snapshot2 = readRunRecord(runId, deps);
|
|
2539
|
+
if (!snapshot2) return "blocked";
|
|
2346
2540
|
return withRunRecordLock(runId, deps, () => {
|
|
2347
2541
|
const latest = readRunRecord(runId, deps);
|
|
2348
|
-
if (!latest || JSON.stringify(latest) !== JSON.stringify(
|
|
2542
|
+
if (!latest || JSON.stringify(latest) !== JSON.stringify(snapshot2)) return "blocked";
|
|
2349
2543
|
const launch = latest.writerLaunch;
|
|
2350
2544
|
if (launch?.protocol !== "fenced-launch-v1" || launch.attemptId !== attemptId) return "blocked";
|
|
2351
2545
|
if (launch.phase === "revoked") return latest.localWriterClaim?.state === "released" ? "already-revoked" : "blocked";
|
|
@@ -2364,10 +2558,10 @@ function localWriterStillOwns(record, deps) {
|
|
|
2364
2558
|
const observed = e?.state === "known" && e.owner.state === "verified" ? nativeOwner(record.pid, deps) : void 0;
|
|
2365
2559
|
const reused = observed?.state === "verified" && e?.state === "known" && e.owner.state === "verified" && (observed.startedAt !== e.owner.startedAt || (observed.linux?.bootId !== e.owner.linux?.bootId || observed.linux?.startTicks !== e.owner.linux?.startTicks));
|
|
2366
2560
|
if (!isPidGone(record.pid, deps) && !reused) return true;
|
|
2367
|
-
const
|
|
2561
|
+
const snapshot2 = JSON.stringify(record);
|
|
2368
2562
|
const released = withRunRecordLock(record.runId, deps, () => {
|
|
2369
2563
|
const latest = readRunRecord(record.runId, deps);
|
|
2370
|
-
if (!latest || JSON.stringify(latest) !==
|
|
2564
|
+
if (!latest || JSON.stringify(latest) !== snapshot2) return false;
|
|
2371
2565
|
latest.localWriterClaim.state = "released";
|
|
2372
2566
|
writeRunRecord(latest, deps);
|
|
2373
2567
|
return true;
|
|
@@ -2376,14 +2570,14 @@ function localWriterStillOwns(record, deps) {
|
|
|
2376
2570
|
}
|
|
2377
2571
|
function acquireLocalWriterClaim(runId, cwd, deps) {
|
|
2378
2572
|
const fs = deps.fs ?? nodeFs2;
|
|
2379
|
-
const
|
|
2380
|
-
const worktree = trustedLocalWorktree(
|
|
2573
|
+
const canonical2 = String((fs.realpathSync ?? nodeFs2.realpathSync)(cwd));
|
|
2574
|
+
const worktree = trustedLocalWorktree(canonical2, deps);
|
|
2381
2575
|
const acquired = withRunRecordLock("local-writer-admission", deps, () => {
|
|
2382
2576
|
const updated = withRunRecordLock(runId, deps, () => {
|
|
2383
2577
|
const record = readRunRecord(runId, deps);
|
|
2384
2578
|
if (!record) throw new Error(`[local-writer-resource] missing run ${runId}`);
|
|
2385
2579
|
if (record.writerLaunch?.phase === "revoked") throw new Error("[local-writer-resource] claim attempt revoked");
|
|
2386
|
-
record.localWriterClaim = { cwd:
|
|
2580
|
+
record.localWriterClaim = { cwd: canonical2, ...worktree ? { worktree } : {}, state: "held" };
|
|
2387
2581
|
if (record.writerLaunch && record.execution?.state === "known" && record.execution.owner.state === "verified" && record.pid === process.pid) {
|
|
2388
2582
|
record.writerLaunch.phase = "granted";
|
|
2389
2583
|
}
|
|
@@ -2394,7 +2588,7 @@ function acquireLocalWriterClaim(runId, cwd, deps) {
|
|
|
2394
2588
|
return true;
|
|
2395
2589
|
}, { strict: true, requireDeadOwner: true });
|
|
2396
2590
|
if (!acquired) throw new Error("[local-writer-resource] admission lock busy; no child spawned");
|
|
2397
|
-
return
|
|
2591
|
+
return canonical2;
|
|
2398
2592
|
}
|
|
2399
2593
|
function nativeOwner(pid, deps) {
|
|
2400
2594
|
const first = probeProcessStartTime(pid, deps);
|
|
@@ -2494,19 +2688,19 @@ function resolveLocalContinuation(record, deps = {}) {
|
|
|
2494
2688
|
}
|
|
2495
2689
|
function registerLocalForegroundWriter(cwd, policy, agentKey, deps = {}) {
|
|
2496
2690
|
const fs = deps.fs ?? nodeFs2;
|
|
2497
|
-
const
|
|
2691
|
+
const canonical2 = String((fs.realpathSync ?? nodeFs2.realpathSync)(cwd));
|
|
2498
2692
|
const owner = nativeOwner(process.pid, deps);
|
|
2499
2693
|
if (owner.state !== "verified" || policy.readOnly || !policy.hostWritesAuthorized) {
|
|
2500
2694
|
throw new Error("[local-writer-resource] foreground native identity/authorization unknown");
|
|
2501
2695
|
}
|
|
2502
2696
|
const runId = defaultGenerateRunId();
|
|
2503
2697
|
fs.mkdirSync(resolveRunsDir(deps.env, deps.homedir), { recursive: true });
|
|
2504
|
-
const worktree = trustedLocalWorktree(
|
|
2698
|
+
const worktree = trustedLocalWorktree(canonical2, deps);
|
|
2505
2699
|
const record = {
|
|
2506
2700
|
runId,
|
|
2507
2701
|
agentKey,
|
|
2508
|
-
writerLaunch: { protocol: "fenced-launch-v1", attemptId:
|
|
2509
|
-
cwd:
|
|
2702
|
+
writerLaunch: { protocol: "fenced-launch-v1", attemptId: randomUUID3(), phase: "prepared" },
|
|
2703
|
+
cwd: canonical2,
|
|
2510
2704
|
startedAt: (deps.now?.() ?? /* @__PURE__ */ new Date()).toISOString(),
|
|
2511
2705
|
status: "running",
|
|
2512
2706
|
logPath: resolveRunLogPath(runId, deps.env, deps.homedir),
|
|
@@ -2517,7 +2711,7 @@ function registerLocalForegroundWriter(cwd, policy, agentKey, deps = {}) {
|
|
|
2517
2711
|
state: "known",
|
|
2518
2712
|
kind: "host-local",
|
|
2519
2713
|
runtimeKey: "local",
|
|
2520
|
-
canonicalCwd:
|
|
2714
|
+
canonicalCwd: canonical2,
|
|
2521
2715
|
device: { kind: "localhost", hostname: nodeHostname(), platform: process.platform },
|
|
2522
2716
|
...worktree ? { worktree } : {},
|
|
2523
2717
|
permissions: {
|
|
@@ -2532,7 +2726,7 @@ function registerLocalForegroundWriter(cwd, policy, agentKey, deps = {}) {
|
|
|
2532
2726
|
};
|
|
2533
2727
|
writeRunRecord(record, deps);
|
|
2534
2728
|
try {
|
|
2535
|
-
acquireLocalWriterClaim(runId,
|
|
2729
|
+
acquireLocalWriterClaim(runId, canonical2, deps);
|
|
2536
2730
|
} catch (error) {
|
|
2537
2731
|
finalizeRunRecord(runId, { status: "failed", exitCode: 1, note: String(error) }, deps);
|
|
2538
2732
|
throw error;
|
|
@@ -2671,7 +2865,7 @@ async function spawnLocalBackgroundRun(input, deps = {}) {
|
|
|
2671
2865
|
...title ? { title } : {},
|
|
2672
2866
|
cwd: canonicalCwd ?? input.cwd,
|
|
2673
2867
|
execution,
|
|
2674
|
-
...executionRequest ? { writerLaunch: { protocol: "fenced-launch-v1", attemptId:
|
|
2868
|
+
...executionRequest ? { writerLaunch: { protocol: "fenced-launch-v1", attemptId: randomUUID3(), phase: "prepared" } } : {},
|
|
2675
2869
|
...executionRequest ? (() => {
|
|
2676
2870
|
const parent = nativeOwner(process.pid, resolvedDeps);
|
|
2677
2871
|
return parent.state === "verified" ? { ownerPublication: { state: "pending", parent } } : {};
|
|
@@ -2767,7 +2961,7 @@ async function spawnLocalBackgroundRun(input, deps = {}) {
|
|
|
2767
2961
|
detached: true,
|
|
2768
2962
|
// Detached on Windows means no console; hide the one its children would create.
|
|
2769
2963
|
windowsHide: true,
|
|
2770
|
-
stdio: deps.shellApprovalHost ? ["ignore", logFd, logFd, "ipc"] : ["ignore", logFd, logFd]
|
|
2964
|
+
stdio: deps.shellApprovalHost || deps.mcpApprovalHost ? ["ignore", logFd, logFd, "ipc"] : ["ignore", logFd, logFd]
|
|
2771
2965
|
});
|
|
2772
2966
|
} catch (error) {
|
|
2773
2967
|
try {
|
|
@@ -2871,6 +3065,15 @@ async function spawnLocalBackgroundRun(input, deps = {}) {
|
|
|
2871
3065
|
throw new Error(`[host-memory-reservation] child ${proc.pid}, run ${runId}: association failed: ${error}`);
|
|
2872
3066
|
}
|
|
2873
3067
|
}
|
|
3068
|
+
if (deps.mcpApprovalHost) {
|
|
3069
|
+
attachMcpApprovalHost(proc, { ...deps.mcpApprovalHost, binding: {
|
|
3070
|
+
...deps.mcpApprovalHost.binding,
|
|
3071
|
+
runId,
|
|
3072
|
+
agentKey: input.agentKey,
|
|
3073
|
+
workspaceRoot: nodeFs2.realpathSync(input.cwd ?? process.cwd())
|
|
3074
|
+
} });
|
|
3075
|
+
proc.channel?.unref?.();
|
|
3076
|
+
}
|
|
2874
3077
|
if (deps.shellApprovalHost) {
|
|
2875
3078
|
attachShellApprovalHost(proc, { ...deps.shellApprovalHost, binding: {
|
|
2876
3079
|
...deps.shellApprovalHost.binding,
|
|
@@ -3022,7 +3225,7 @@ function transitionRunToTerminal(runId, update, deps = {}, options = {}) {
|
|
|
3022
3225
|
kind,
|
|
3023
3226
|
dev: String(stat.dev),
|
|
3024
3227
|
ino: String(stat.ino),
|
|
3025
|
-
sha256:
|
|
3228
|
+
sha256: createHash2("sha256").update(fs.readFileSync(path)).digest("hex")
|
|
3026
3229
|
};
|
|
3027
3230
|
record2.resultArtifacts = [...(record2.resultArtifacts ?? []).filter((a) => a.path !== path), artifact];
|
|
3028
3231
|
};
|
|
@@ -3053,7 +3256,7 @@ function transitionRunToTerminal(runId, update, deps = {}, options = {}) {
|
|
|
3053
3256
|
update.lastAssistantText ?? ""
|
|
3054
3257
|
);
|
|
3055
3258
|
if (typeof fs.renameSync !== "function") throw new Error("atomic result publication requires renameSync");
|
|
3056
|
-
pendingResultFile = `${resultFile}.${
|
|
3259
|
+
pendingResultFile = `${resultFile}.${randomUUID3()}.pending`;
|
|
3057
3260
|
try {
|
|
3058
3261
|
fs.writeFileSync(pendingResultFile, content, { encoding: "utf8", flag: "wx" });
|
|
3059
3262
|
stagingComplete = true;
|
|
@@ -3062,7 +3265,7 @@ function transitionRunToTerminal(runId, update, deps = {}, options = {}) {
|
|
|
3062
3265
|
}
|
|
3063
3266
|
if (fs.existsSync(resultFile)) {
|
|
3064
3267
|
const previous = fs.readFileSync(resultFile);
|
|
3065
|
-
const backup = `${resultFile}.${
|
|
3268
|
+
const backup = `${resultFile}.${randomUUID3()}.bak`;
|
|
3066
3269
|
backupFile = backup;
|
|
3067
3270
|
try {
|
|
3068
3271
|
fs.writeFileSync(backup, previous, { flag: "wx" });
|
|
@@ -3731,6 +3934,8 @@ async function runAgentRecoverPreparedWriterCommand(args, deps) {
|
|
|
3731
3934
|
}
|
|
3732
3935
|
|
|
3733
3936
|
export {
|
|
3937
|
+
createMcpApprovalChild,
|
|
3938
|
+
hasLiveShellApprovalHosts,
|
|
3734
3939
|
createShellApprovalChild,
|
|
3735
3940
|
TAIL_LINES_MAX,
|
|
3736
3941
|
readHostMemory,
|