Lines 1-46javascript
1import{createRequire as pW}from"node:module";var mW=Object.defineProperty;var rW=($)=>$;function oW($,f){this[$]=rW.bind(null,f)}var U0=($,f)=>{for(var Z in f)mW($,Z,{get:f[Z],enumerable:!0,configurable:!0,set:oW.bind(f,Z)})};var O=($,f)=>()=>($&&(f=$($=0)),f);var dW=pW(import.meta.url);import{writeFile as iW,rename as lW,unlink as tW}from"fs/promises";import{writeFileSync as aW,renameSync as sW,unlinkSync as eW}from"fs";import{randomBytes as $H}from"crypto";import S3 from"path";function P8($){return S3.join(S3.dirname($),`.${S3.basename($)}.${process.pid}.${$H(4).toString("hex")}.tmp`)}async ...
2 `),Z=Xz().map((J)=>`(subpath ${Zz(L0.resolve(J))})`).join(`
3 `),z=$.network==="deny"?"(deny network*)":"";return`(version 1)
6(allow file-write-data (literal "/dev/null"))
14`}function Fz(){if(mf("/usr/bin/bwrap"))return"/usr/bin/bwrap";return"/usr/local/bin/bwrap"}function qz($,f,Z){let z=["--die-with-parent","--ro-bind","/","/","--dev","/dev","--proc","/proc"],J=new Set;for(let K of g4($)){let Q=process.platform==="win32"?K.toLowerCase():K;if(J.has(Q))continue;if(J.add(Q),mf(K))z.push("--bind",K,K)}if($.network==="deny")z.push("--unshare-net");return z.push("--chdir",f,"/bin/sh","-c",Z),z}function x4($){if($==="off"||r3()!=="none")return null;return $==="strict"?"⚠ Command-level sandboxing isn't supported on this platform (requires macOS sandbox-exec or Linux bw ...
15${Jz}`:zz,P}function h4($){return $==="off"?"off":$==="strict"?"strict":"workspace"}function Nz($){return $===
16\x1B[33m❓ ${z} (no interactive terminal — skipped)\x1B[0m`),null;if(console.log(),console.log(`\x1B[33m❓ ${z}\x1B[0m`),K){for(let G=0;G<K.length;G++)console.log(`\x1B[90m ${G+1}. ${K[G]}\x1B[0m`);if(Z)console.log("\x1B[90m (可勾选多项;最后一项可自己输入)\x1B[0m")}return new Promise((G)=>{let Y=OH.createInterface({input:process.stdin,output:process.stdout});Y.question("\x1B[36m → \x1B[0m",(P)=>{Y.close(),G(P.trim()||"(no answer)")})})}async function x$($){let f=N8.getStore();if(f){if(f.autoApprove)return!0;if(f.onConfirm)return f.onConfirm($);return!1}if(Ff())return!0;if(f9)return f9($);if(!process.std ...
17\x1B[33m⚠ Rejected (no interactive terminal): ${$}\x1B[0m`),!1;return $9?.pause(),process.stdout.write(`
18\x1B[90m┌─ 即将执行 ─────────────────────────────────\x1B[0m
19`),process.stdout.write(`\x1B[90m│\x1B[0m ${$}
20`),process.stdout.write(`\x1B[90m└────────────────────────────────────────────\x1B[0m
21`),process.stdout.write(`
22`),new Promise((Z)=>{let z=process.stdin.isRaw,J=process.stdin.readableEncoding;if(process.stdin.isTTY)process.stdin.setRawMode(!0);process.stdin.resume(),process.stdin.setEncoding("utf8");let K=1
24`),$9?.resume(),Z(M)};X();let H=(M)=>{Q+=M;while(Q.length>0){if(Q[0]==="\x1B"){if(Q[1]==="["){let q=Q.slice(2).search(/[A-Za-z~]/);if(q===-1)return;let U=Q[2+q];Q=Q.slice(3+q),P(U);continue}if(Q[1]==="O"){if(Q.length<3)return;let q=Q[2];Q=Q.slice(3),P(q);continue}if(Q.length===1){setTimeout(()=>{if(Q==="\x1B")Q="",W(!1)},50).unref?.();return}Q=Q.slice(1),W(!1);return}let F=Q[0];if(Q=Q.slice(1),F===`
25`&&!G)continue;if(F==="\r"||F===`
26`){if(!G)continue;W(K===0);return}if(F==="y"||F==="Y"){W(!0);return}if(F==="n"||F==="N"){W(!1);return}}};process.stdin.on("data",H)})}function Q9($){return[/\brm\s+(-[a-z]*[rf][a-z]*|--recursive)\s/,/\bsudo\b/,/\bmkfs\b/,/\bdd\s+/,/\b(shutdown|reboot|halt|poweroff)\b/,/\bgit\s+(push|reset\s+--hard|clean\s+-[a-z]*f|rebase)/,/\bnpm
27 → ${$.hint}`:`✖ ${$.message}`;return`✖ ${$ instanceof Error?$.message:String($)}`}function P9($){
28`),images:Z}}function AU($){if(s0($))return $;if(typeof $!=="string"||!$.trim())return{};try{let f=JSON
30`}function yU($){let f=new TextDecoder,Z=new TextEncoder,z=$.getReader(),J={sentRole:!1},K="";return new ReadableStream({async pull(Q){for(;;){let{done:G,value:Y}=await z.read();if(G){K+=f.decode();let H=K.trim();if(H)try{let M=JSON.parse(H);if(s0(M))Q.enqueue(Z.encode(HJ(XJ(M,J))))}catch{}Q.enqueue(Z.encode(`data: [DONE]
32`)),Q.close();return}K+=f.decode(Y,{stream:!0});let P=K.lastIndexOf(`
33`);if(P<0)continue;let X=K.slice(0,P+1);K=K.slice(P+1);let W=[];for(let H of X.split(`
34`)){let M=H.trim();if(!M)continue;try{let F=JSON.parse(M);if(s0(F))W.push(HJ(XJ(F,J)))}catch{}}if(W.length>0){Q.enqueue(Z.encode(W.join("")));return}}},cancel(Q){return z.cancel(Q)}})}function TU($){let f=new Headers($);return f.set("content-type","application/json"),f}function IU($){let f=new Headers($);return f.set("content-type","text/event-stream"),f.delete("content-length"),f}async function NJ($,f,Z,z,J){let K=BU(f);if(!VU(K))return $(f,{...Z,body:JSON.stringify(z)});let Q=typeof z.model==="string"?z.model:"",G=x1(Q,K),Y=wU(z,{numCtx:QJ(Q,K),think:KJ(J,G?.thinking??null)}),P=await $(LU(K) ...
35(${$.length-y9} older memories not shown — use memory_search to find them.)`:"";return[f,...z,J].filter(Boolean).join(`
36`)}function k9($){if(!f1($))return"";let f=L$("project"),Z=L$("global");if(f.length===0&&Z
37`)}function R9(){let $=O9({description:"Save a memory for future conversations. Use this when the user shares preferences, project conventions, important context, or asks you to remember something. Memories persist across sessions and are injected as background reference, not as work to resume. Do not store secrets, API keys, or passwords. Use scope project for this repository, global for all projects.",inputSchema:w9({type:"object",properties:{content:{type:"string",description:"The information to remember"},tags:{type:"array",items:{type:"string"},description:"Optional tags for categorizatio ...
38`)}}),Z=O9({description:"Delete a memory by its number. Use memory_search first to find the index and scope.",inputSchema:w9({type:"object",properties:{index:{type:"number",description:"The memory number to delete (1-based)"},scope:{type:"string",enum:["global","project"],description:"Which store the number belongs to. Defaults to project when .min-agent exists, otherwise global."}},required:["index"]}),execute:async({index:
39`)});function JM($){return $==="cli"?"this run":$==="project"?"project":$==="global"?"global":"default"}function n8($){let{scope:f,rest:Z}=c$($.positionals),z=f??$.scope??"global";if(Z[0]==="--help"||Z[0]==="-h")return{ok:!0,lines:[R8]};if(Z.length===1){let Y=N$(Z[0]);if(!Y)return{ok:!1,lines:[R8]};return pf(Y,z),q8(Y),{ok:!0,lines:[`✓ Permission set to ${Wf(Y)} (${P$(z)})`]}}if(Z.length>1)return{ok:!1,lines:[R8]};if($.flagMode)return pf($.flagMode,z),q8($.flagMode),{ok:!0,lines:[`✓ Permission set to ${Wf($.flagMode)} (${P$(z)})`]};let J=m4(),K=i4(),Q=K??J.permission,G=K?"cli":J.source;return{ ...
40`)});function KM($){return $==="cli"?"this run":$==="project"?"project":$==="global"?"global":"default"}function v8($){let
41`)});function E8($){let{scope:f,rest:Z}=c$($.positionals),z=f??$.scope??"global";if(Z[0]==="--help"||Z[0
42`)});var cJ={};U0(cJ,{runWriteConfig:()=>QM});async function QM($){let f=[],Z=!0;if($.sandbox!==void 0||$.network!==void 0){let z=k8({positionals:[],flagMode:$.sandbox,flagNetwork:$.network,scope:$.scope});if(f.push(...z.lines),!z.ok)Z=!1}if($.permission!==void 0){let z=n8({positionals:[],flagMode:$.permission,scope:$.scope});if(f.push(...z.lines),!z.ok)Z=!1}if($.think!==void 0){let z=v8({positionals:[],flagEffort:$.think,scope:$.scope});if(f.push(...z.lines),!z.ok)Z=!1}if($.memory!==void 0){let z=E8({positionals:[],flagMode:$.memory,scope:$.scope});if(f.push(...z.lines),!z.ok)Z=!1}if(console. ...
43`)),!Z)process.exitCode=1}var mJ=O(()=>{S9();v9();u9();E9()});function g8($,f,Z){let z=$===
44`)?1:0);if(W>0)Y+=`\x1B[${W}A\x1B[${P.column}G`,f=W}let X=typeof z==="string"?Y:Buffer.from(Y,J||"utf-8");return $.write(X,J,K)};return new Proxy($,{get(z,J){if(J==="write")return Z;let K=Reflect.get(z,J,z);return typeof K==="function"?K.bind(z):K},set(z,J,K){return Reflect.set(z,J,K,z)}})}var PK=null;function rM($){return $>=768&&$<=879||$>=1155&&$<=1161||$>=1425&&$<=1469||$>=1552&&$<=1562||$>=1611&&$<=1631||$>=3633&&$<=3642||$>=3655&&$<=3662||$>=6832&&$<=6911||$>=7616&&$<=7679||$>=8203&&$<=8207||$>=8288&&$<=8292||$>=8400&&$<=8447||$>=65024&&$<=65039||$>=65056&&$<=65071||$===65279||$>=917760& ...
45`);for(let Q=0;Q<K.length;Q++){for(let G of l0(K[Q],f,Z))z.push({
46`)z--;return z+1}function K2($,f){let Z=Array.from($),z=f;while(z<Z.length&&Z[z]!==`
Long lines were clipped for display.