Lines 1-50javascript
1import{createRequire as GH}from"node:module";var zH=Object.defineProperty;var JH=($)=>$;function KH($,f){this[$]=JH.bind(null,f)}var U0=($,f)=>{for(var Z in f)zH($,Z,{get:f[Z],enumerable:!0,configurable:!0,set:KH.bind(f,Z)})};var C=($,f)=>()=>($&&(f=$($=0)),f);var QH=GH(import.meta.url);import{writeFile as YH,rename as PH,unlink as XH}from"fs/promises";import{writeFileSync as WH,renameSync as HH,unlinkSync as UH}from"fs";import{randomBytes as MH}from"crypto";import o3 from"path";function q6($){return o3.join(o3.dirname($),`.${o3.basename($)}.${process.pid}.${MH(4).toString("hex")}.tmp`)}async ...
2 `),Z=Lz().map((J)=>`(subpath ${Hz(L0.resolve(J))})`).join(`
3 `),z=$.network==="deny"?"(deny network*)":"";return`(version 1)
6(allow file-write-data (literal "/dev/null"))
14`}function jz(){if(d4("/usr/bin/bwrap"))return"/usr/bin/bwrap";return"/usr/local/bin/bwrap"}function Cz($,f,Z){let z=["--die-with-parent","--ro-bind","/","/","--dev","/dev","--proc","/proc"],J=new Set;for(let K of h2($)){let G=process.platform==="win32"?K.toLowerCase():K;if(J.has(G))continue;if(J.add(G),d4(K))z.push("--bind",K,K)}if($.network==="deny")z.push("--unshare-net");return z.push("--chdir",f,"/bin/sh","-c",Z),z}function c2($){if($==="off"||f9()!=="none")return null;return $==="strict"?"⚠ Command-level sandboxing isn't supported on this platform (requires macOS sandbox-exec or Linux bw ...
15${Mz}`:Uz,P}function m2($){return $==="off"?"off":$==="strict"?"strict":"workspace"}function Oz($){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 Q=0;Q<K.length;Q++)console.log(`\x1B[90m ${Q+1}. ${K[Q]}\x1B[0m`);if(Z)console.log("\x1B[90m (可勾选多项;最后一项可自己输入)\x1B[0m")}return new Promise((Q)=>{let Y=nH.createInterface({input:process.stdin,output:process.stdout});Y.question("\x1B[36m → \x1B[0m",(P)=>{if(Y.close(),!t2)process.stdin.pause();Q(P.trim()||"(no answer)")})})}async function h$($){let f=e2.getStore();if(f){if(f.autoApprove)return!0;if(f.onConfirm)return f.onConfirm($);return!1}if(N4())return!0;if(!j ...
17\x1B[33m⚠ Rejected (no interactive terminal): ${$}\x1B[0m`),!1;return pH($)}function pH($){return new Promise((f)=>{i2.push({message:$,resolve:f}),mz()})}function mz
18 `)}`);return`${$.length} 个操作待确认(允许将全部执行,拒绝将全部取消):
20`)}`}function dH($){t2?.pause(),process.stdout.write(`
21\x1B[90m┌─ 即将执行 ─────────────────────────────────\x1B[0m
22`);for(let f of $.split(`
23`))process.stdout.write(`\x1B[90m│\x1B[0m ${f}
24`);return process.stdout.write(`\x1B[90m└────────────────────────────────────────────\x1B[0m
25`),process.stdout.write(`
26`),new Promise((f)=>{let Z=process.stdin.isRaw,z=process.stdin.readableEncoding;if(process.stdin.isTTY)process.stdin.setRawMode(!0);process.stdin.resume(),process.stdin.setEncoding("utf8");let J=1
28`),t2)t2.resume();else process.stdin.pause();f(H)};P();let W=(H)=>{K+=H;while(K.length>0){if(K[0]==="\x03"||K[0]==="\x04"){K="",X(!1),process.exit(130);return}if(K[0]==="\x1B"){if(K[1]==="["){let U=K.slice(2).search(/[A-Za-z~]/);if(U===-1)return;let N=K[2+U];K=K.slice(3+U),Y(N);continue}if(K[1]==="O"){if(K.length<3)return;let U=K[2];K=K.slice(3),Y(U);continue}if(K.length===1){setTimeout(()=>{if(K==="\x1B")K="",X(!1)},50).unref?.();return}K=K.slice(1),X(!1);return}let M=K[0];if(K=K.slice(1),M===`
29`&&!G)continue;if(M==="\r"||M===`
30`){if(!G)continue;X(J===0);return}if(M==="y"||M==="Y"){X(!0);return}if(M==="n"||M==="N"){X(!1);return}}};process.stdin.on("data",W)})}function T6($){return[/\brm\s+(-[a-z]*[rf][a-z]*|--recursive|--force)\s/,/\brm\s+-[a-z]*[rf]/,/\bfind\b[^|;&]*\s+-delete\b/,/\bfind\b[^|;&]*\s+-(exec|execdir|ok)\s+rm\b/,/\b(drop|truncate)\s+(table|database|schema)
31 → ${$.hint}`:`✖ ${$.message}`;return`✖ ${$ instanceof Error?$.message:String($)}`}function B9($){
32`),images:Z}}function cU($){if(e0($))return $;if(typeof $!=="string"||!$.trim())return{};try{let f=JSON
34`}function lU($){let f=new TextDecoder,Z=new TextEncoder,z=$.getReader(),J={sentRole:!1},K="";return new ReadableStream({async pull(G){for(;;){let{done:Q,value:Y}=await z.read();if(Q){K+=f.decode();let H=K.trim();if(H)try{let M=JSON.parse(H);if(e0(M))G.enqueue(Z.encode(jJ(AJ(M,J))))}catch{}G.enqueue(Z.encode(`data: [DONE]
36`)),G.close();return}K+=f.decode(Y,{stream:!0});let P=K.lastIndexOf(`
37`);if(P<0)continue;let X=K.slice(0,P+1);K=K.slice(P+1);let W=[];for(let H of X.split(`
38`)){let M=H.trim();if(!M)continue;try{let U=JSON.parse(M);if(e0(U))W.push(jJ(AJ(U,J)))}catch{}}if(W.length>0){G.enqueue(Z.encode(W.join("")));return}}},cancel(G){return z.cancel(G)}})}function iU($){let f=new Headers($);return f.set("content-type","application/json"),f}function tU($){let f=new Headers($);return f.set("content-type","text/event-stream"),f.delete("content-length"),f}async function yJ($,f,Z,z,J){let K=uU(f);if(!xU(K))return $(f,{...Z,body:JSON.stringify(z)});let G=typeof z.model==="string"?z.model:"",Q=c1(G,K),Y=dU(z,{numCtx:VJ(G,K),think:BJ(J,Q?.thinking??null)}),P=await $(gU(K) ...
39(${$.length-x9} older memories not shown — use memory_search to find them.)`:"";return[f,...z,J].filter(Boolean).join(`
40`)}function c9($){if(!Z1($))return"";let f=_$("project"),Z=_$("global");if(f.length===0&&Z
41`)}function m9(){let $=E9({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:u9({type:"object",properties:{content:{type:"string",description:"The information to remember"},tags:{type:"array",items:{type:"string"},description:"Optional tags for categorizatio ...
42`)}}),Z=E9({description:"Delete a memory by its number. Use memory_search first to find the index and scope.",inputSchema:u9({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. Project requires .min-agent/ in cwd (created by min-agent init)."}},required:["index"]}),execute:async({index
43`)});function DM($){return $==="cli"?"this run":$==="project"?"project":$==="global"?"global":"default"}function r6($){let
44`)});function AM($){return $==="cli"?"this run":$==="project"?"project":$==="global"?"global":"default"}function d6($){let{scope:f,rest:Z}=m$($.positionals),z=f??$.scope??"global";if(Z[0]==="--help"||Z[0]==="-h")return{ok:!0,lines:[o6]};if(Z.length===1){let G=S0(Z[0]);if(!G)return{ok:!1,lines:[o6]};return p1(G,z),Z2(G),{ok:!0,lines:[`✓ Thinking set to ${V$(G)} (${X$(z)})`]}}if(Z.length>1)return{ok:!1,lines:[o6]};if($.flagEffort)return p1($.flagEffort,z),Z2($.flagEffort),{ok:!0,lines:[`✓ Thinking set to ${V$($.flagEffort)} (${X$(z)})`]};let{thinking:J,source:K}=$1();return{ok:!0,lines:[`Current ...
45`)});function i6($){let{scope:f,rest:Z}=m$($.positionals),z=f??$.scope??"global";if(Z[0]==="--help"||Z[0]==="-h")return{ok:!0,lines:[l6]};if(Z.length===1){let G=g0(Z[0]);if(!G)return{ok:!1,lines:[l6]};return G2(G,z),c6(G),{ok:!0,lines:[`✓ Memory set to ${r1(G)} (${X$(z)})`]}}if(Z.length>1)return{ok:!1,lines:[l6]};if($.flagMode)return G2($.flagMode,z),c6($.flagMode),{ok:!0,lines:[`✓ Memory set to ${r1($.flagMode)} (${X$(z)})`]};let{memory:J,source:K}=_4();return{ok:!0,lines:[`Current memory: ${r1(J)} (${Kf(K)})`,l6]}}var l6;var l9=C(()=>{L1();l6=["Usage: min-agent memory [on|off] [--project|--g ...
46`)});var fK={};U0(fK,{runWriteConfig:()=>bM});async function bM($){let f=[],Z=!0;if($.sandbox!==void 0||$.network!==void
47`)),!Z)process.exitCode=1}var ZK=C(()=>{r9();o9();d9();l9()});function t6($,f,Z){let z=$==="openai"?"openai":$==="ollama"?"ollama":jM(f)??"provider";return CM(z,Z)}function a6($){let f=$.trim();if(!f||f.includes("/")||f.includes(":"))return"名称不能为空,且不能包含 / 或 :。";return null}function i9($){if($.length<4)return"****";return`…${$.slice(-4)}`}function zK($,f){let Z=$.trim().toLowerCase();if(!Z)return[...f];return f.filter((z)=>z.toLowerCase().includes(Z))}function s6($,f,Z){let z=a6(f.name);if(z)return{error:z};let J=f.name.trim(),K=[...$.providers??[]],G=K.findIndex((Y)=>Y.name===J);if(G>=0&&!Z.ov ...
48`)?1:0);if(W>0)Y+=`\x1B[${W}A\x1B[${P.column}G`,f=W}let X=typeof z===
49`);for(let G=0;G<K.length;G++){for(let Q of i0(K[G],f,Z))z.push({text:Q,startIndex:J}),J+=Array.from(Q).length;if(G<K.length-1)J+=1}return z}function b4($,f,Z){let z=Array.from($).length;return Math.min(Math.max(f+Z,0),z)}function G5($,f,Z,z,J){let K=$[f];if(!K)return 0;let G=Z-z;if(G<=0)return K.startIndex;let Q=0,Y=0;for(let{text:P,width:X}of D$(K.text,J)){if(Q+X>G){if(J?.(P)!==void 0)return K.startIndex+Y;return K.startIndex+Y+(G-Q<X/2?0:Array.from(P).length)}Q+=X,Y+=Array.from(P).length}return K.startIndex+Y}function $$($,f,Z){let z=Array.from($);return z.splice(f,0,...Array.from(Z)),{valu ...
50`)z--;return z+1}function Xf($,f){let Z=Array.from($),z=f;while(z<Z.length&&Z[z]!==
Long lines were clipped for display.