@kodax-ai/kodax 0.7.67 → 0.7.68
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/CHANGELOG.md +72 -0
- package/README.md +11 -6
- package/README_CN.md +12 -8
- package/dist/chunks/agent-DATNZOBK.js +2 -0
- package/dist/chunks/argument-completer-X7MMM7Y6.js +2 -0
- package/dist/chunks/chunk-5GL55MOH.js +36 -0
- package/dist/chunks/chunk-67XJ4YUA.js +703 -0
- package/dist/chunks/{chunk-YH5BTUQO.js → chunk-C4SBXBWH.js} +193 -190
- package/dist/chunks/{chunk-DEICMTHO.js → chunk-CC4BVVE7.js} +1 -1
- package/dist/chunks/{chunk-EN3O2C43.js → chunk-CTHUX5ZH.js} +2 -2
- package/dist/chunks/{chunk-YRBNXFHY.js → chunk-HFM2D5BP.js} +1 -1
- package/dist/chunks/chunk-HLBHSA2B.js +325 -0
- package/dist/chunks/{chunk-O7N22GJ3.js → chunk-K2NCKRVY.js} +16 -14
- package/dist/chunks/{chunk-KBBGDRER.js → chunk-KGAI32VS.js} +2 -2
- package/dist/chunks/{chunk-WCSSXBHR.js → chunk-KIQRCGVR.js} +13 -13
- package/dist/chunks/{chunk-W2XMNYLK.js → chunk-MP52BDK5.js} +12 -12
- package/dist/chunks/chunk-O5OJQFPY.js +307 -0
- package/dist/chunks/chunk-OIELNE6Z.js +56 -0
- package/dist/chunks/chunk-PEGSHZAA.js +5 -0
- package/dist/chunks/chunk-TOGESFRN.js +2 -0
- package/dist/chunks/compaction-config-BXEDHIQP.js +2 -0
- package/dist/chunks/{construction-bootstrap-GLEHQ2KB.js → construction-bootstrap-PYWJHO35.js} +1 -1
- package/dist/chunks/dist-76PJHNSG.js +2 -0
- package/dist/chunks/{dist-4PXB7U22.js → dist-HTDJRAD6.js} +1 -1
- package/dist/chunks/host-UAXIDZ6V.js +2 -0
- package/dist/chunks/run-manager-UCXB4G22.js +2 -0
- package/dist/chunks/utils-S63V5UCM.js +2 -0
- package/dist/index.d.ts +15 -15
- package/dist/index.js +1 -1
- package/dist/kodax_cli.js +1199 -1185
- package/dist/runtime-worker.js +1021 -1007
- package/dist/sdk-agent.d.ts +126 -18
- package/dist/sdk-agent.js +1 -1
- package/dist/sdk-coding.d.ts +18 -18
- package/dist/sdk-coding.js +1 -1
- package/dist/sdk-experimental-memory.d.ts +618 -0
- package/dist/sdk-experimental-memory.js +2 -0
- package/dist/sdk-llm.d.ts +6 -6
- package/dist/sdk-llm.js +1 -1
- package/dist/sdk-mcp.js +1 -1
- package/dist/sdk-media.d.ts +1 -1
- package/dist/sdk-repl.d.ts +15 -15
- package/dist/sdk-repl.js +1 -1
- package/dist/sdk-runtime.d.ts +11 -11
- package/dist/sdk-runtime.js +1 -1
- package/dist/sdk-session.d.ts +6 -6
- package/dist/sdk-session.js +1 -1
- package/dist/sdk-skills.js +1 -1
- package/dist/semantic-worker.js +12 -12
- package/dist/types-chunks/{base.d-DalIRhbb.d.ts → base.d-C8mXDhLL.d.ts} +1 -1
- package/dist/types-chunks/{bash-prefix-extractor.d-D57Gt6n8.d.ts → bash-prefix-extractor.d-Dm-T865v.d.ts} +24 -4
- package/dist/types-chunks/{capability-learning.d-BQB0M70w.d.ts → capability-learning.d-BLEmCib0.d.ts} +1 -1
- package/dist/types-chunks/{capsule.d-BZmqu_HL.d.ts → capsule.d-CzaamUUv.d.ts} +5 -5
- package/dist/types-chunks/{commands.d-Cg26ud-Y.d.ts → commands.d-DxKjVSNU.d.ts} +4 -4
- package/dist/types-chunks/{guardrail.d-vSaBe64I.d.ts → guardrail.d-CPDfZyJp.d.ts} +3 -3
- package/dist/types-chunks/{guardrail.d-Ds7JHxR1.d.ts → guardrail.d-D7r6zVSR.d.ts} +1 -1
- package/dist/types-chunks/{public-api.d-CPBMPDiU.d.ts → public-api.d-BcKbBy1E.d.ts} +6 -7
- package/dist/types-chunks/{resolver.d-CGkfRULj.d.ts → resolver.d-DmBnoilY.d.ts} +2 -2
- package/dist/types-chunks/{run-manager.d-lnwnfyNC.d.ts → run-manager.d-CSj7_kWk.d.ts} +1 -1
- package/dist/types-chunks/{sdk-session-ByoMLoUS.d.ts → sdk-session-C6nDgyh8.d.ts} +4 -4
- package/dist/types-chunks/{types.d-Bp4Lm1jv.d.ts → types.d-CO_ZkmOd.d.ts} +6 -1
- package/dist/types-chunks/{types.d-DYv3a1ka.d.ts → types.d-CzscbsG0.d.ts} +4 -4
- package/dist/types-chunks/{types.d-DG9B4SMm.d.ts → types.d-D2frCRaY.d.ts} +138 -8
- package/dist/types-chunks/{types.d-DU9lLkmE.d.ts → types.d-D9FKbAmf.d.ts} +2 -2
- package/dist/types-chunks/{utils.d-DMI-9GTR.d.ts → utils.d-DOXxnOnI.d.ts} +5 -5
- package/docs/SDK_EMBEDDER_GUIDE.md +108 -8
- package/package.json +5 -1
- package/dist/chunks/agent-E4V5SLX6.js +0 -2
- package/dist/chunks/argument-completer-N6RT5KYT.js +0 -2
- package/dist/chunks/chunk-AKMXJSGM.js +0 -56
- package/dist/chunks/chunk-CW32NQFO.js +0 -2
- package/dist/chunks/chunk-NVDK375I.js +0 -729
- package/dist/chunks/chunk-QI6SQ2UQ.js +0 -306
- package/dist/chunks/chunk-RS2GAABJ.js +0 -328
- package/dist/chunks/compaction-config-56NO42ZI.js +0 -2
- package/dist/chunks/dist-4UIRSSFS.js +0 -2
- package/dist/chunks/host-DMREFNSO.js +0 -2
- package/dist/chunks/run-manager-P5XMSGZ7.js +0 -2
- package/dist/chunks/utils-JENPFKAE.js +0 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @kodax-ai/kodax — bundled distribution. See docs/ADR.md ADR-022 + ADR-024.
|
|
2
|
-
import{D as j,J as N}from"./chunk-
|
|
2
|
+
import{D as j,J as N}from"./chunk-KGAI32VS.js";import{La as _,Ma as q}from"./chunk-C4SBXBWH.js";import{$a as T,Ja as E,j as v,k as R}from"./chunk-K2NCKRVY.js";import{id as I,jd as g,kd as k,nd as $,od as y,pd as b}from"./chunk-67XJ4YUA.js";import{U as O,V as W,_ as M}from"./chunk-5GL55MOH.js";import{a as o}from"./chunk-ONUPGMER.js";import{join as Pe}from"node:path";var te=["You generate KodaX Dynamic Workflow scripts.","Return JSON only. Do not wrap the answer in prose.","For simple tasks that do not benefit from multiple agents, return:",'{"action":"decline","reason":"..."}',"For complex tasks, return:",'{"action":"generate","manifest":{...},"source":"async function run(wf, args) { ... }","approvalSummary":"..."}',"Generated source may only coordinate agents through wf and args.","Generated source must return displayable final text for the user.","Never use import, require, process, fs, child_process, network APIs, shell commands, or direct file access."].join(`
|
|
3
3
|
`),C=12e4,ne="KODAX_WORKFLOW_GENERATION_TIMEOUT_SEC",re="KODAX_WORKFLOW_GENERATION_TIMEOUT_MS",se=64,oe=2,ie=2e3,ae=[{name:"default"},{name:"variant-results",finalText:o((e,n)=>`Variant smoke child report from ${e} (${n}).`,"finalText"),synthesizeText:"Variant smoke synthesis report."},{name:"unverified-success",status:o(()=>"completed_unverified","status"),finalText:o(e=>`Smoke result for ${e}: completed with verification warnings.`,"finalText"),synthesizeText:"Smoke synthesis: completed with verification warnings."},{name:"empty-args-rerun",args:o(()=>({}),"args")}],le=["- classify-and-act: first classify a mixed request, then route to the right worker behavior.","- fan-out-and-synthesize: split independent areas, files, hypotheses, reviewers, or perspectives; run them with wf.parallel, then wf.synthesize.","- adversarial-verification: produce or inspect a candidate, then have an independent verifier attack assumptions, evidence, and edge cases.","- generate-and-filter: ask several generators for distinct candidates, then filter/dedupe/rank before synthesis.","- tournament: compare competing approaches or answers and use synthesis as the judge.","- loop-until-done: run bounded follow-up rounds when findings should drive the next prompt.","- review or audit combines fan-out-and-synthesize with adversarial-verification: fan independent reviewers out across the dimensions, then pipe each finding straight into a verifier that tries to refute it before synthesis. A review with no verification stage ships findings a single reviewer's blind spot would have hidden."],ce=[{id:"import",pattern:/\bimport\s*(?:\(|['"*{]|\w+\s+from\b)/},{id:"require",pattern:/\brequire\s*\(/},{id:"process",pattern:/\bprocess\s*(?:\.|\[)/},{id:"fs",pattern:/\b(?:node:)?fs\b/},{id:"child_process",pattern:/\bchild_process\b/},{id:"shell",pattern:/\b(?:exec|spawn|execFile)\s*\(/},{id:"fetch",pattern:/\bfetch\s*\(/},{id:"Deno",pattern:/\bDeno\s*(?:\.|\[)/},{id:"Bun",pattern:/\bBun\s*(?:\.|\[)/},{id:"globalThis-index",pattern:/\bglobalThis\s*\[/}];function ue(e=process.env,n){let t=v(n?.workflow?.generationTimeoutSec,"timeouts.workflow.generationTimeoutSec");if(t!==void 0)return t;let r=R(e[ne]);if(r!==void 0)return r;let s=e[re];if(s===void 0||s.trim().length===0)return C;let i=Number(s);return!Number.isFinite(i)||i<=0?C:Math.floor(i)}o(ue,"resolveWorkflowGenerationTimeoutMs");function fe(e,n){if(typeof e!="object"||e===null)throw new Error(`${n} must be an object`);return e}o(fe,"readRecord");function P(e,n){let t=e[n];if(typeof t!="string"||t.trim().length===0)throw new Error(`workflow generation ${n} must be a non-empty string`);return t}o(P,"readNonEmptyString");function de(e){let n=e.trim(),t=/^```(?:json)?\s*([\s\S]*?)\s*```$/i.exec(n);if(t?.[1])return t[1].trim();let r=n.indexOf("{"),s=n.lastIndexOf("}");if(r>=0&&s>r)return n.slice(r,s+1);throw new Error("workflow generation output did not contain a JSON object")}o(de,"extractJsonText");function pe(e){let n=de(e);return fe(JSON.parse(n),"workflow generation output")}o(pe,"parseGenerationJson");function me(e){if(typeof e=="string"){let t=e.trim();return t.length>0?t:void 0}if(typeof e!="object"||e===null)return;let n=e;for(let t of["name","id","title","phase"]){let r=n[t];if(typeof r=="string"&&r.trim().length>0)return r.trim()}}o(me,"normalizePhaseEntry");function he(e){return e.split(/(?:->|\u2192|,|\n)/).map(n=>n.trim()).filter(n=>n.length>0)}o(he,"splitPhaseString");function we(e){if(typeof e!="object"||e===null)return e;let n=e,t=n.phases,r;if(Array.isArray(t)){let s=t.map(me);s.every(i=>i!==void 0)&&(r=s)}else if(typeof t=="string"){let s=he(t);s.length>0&&(r=s)}return r?{...n,phases:r}:e}o(we,"normalizeGeneratedManifestCandidate");function ge(e){return e.match(/\bwf\.(?:runAgent|spawnAgent|synthesize)\s*\(/g)?.length??0}o(ge,"estimateDirectAgentCalls");function ke(e,n){let t=e.maxConcurrency*Math.max(1,e.phases.length)+2,r=ge(n)+2,s=Math.min(se,Math.max(e.maxAgents,t,r));return s>e.maxAgents?{...e,maxAgents:s}:e}o(ke,"reserveGeneratedWorkflowAgentCapacity");function h(e){let n="",t=0,r=["code"],s=[0];for(;t<e.length;){let i=e[t],a=e[t+1];if(r[r.length-1]==="template"){if(i==="\\"){n+=" ",t+=2;continue}if(i==="`"){n+=" ",t+=1,r.pop(),s.pop();continue}if(i==="$"&&a==="{"){n+=" ",t+=2,r.push("code"),s.push(0);continue}n+=i===`
|
|
4
4
|
`?`
|
|
5
5
|
`:" ",t+=1;continue}if(i==="/"&&a==="/"){for(n+=" ",t+=2;t<e.length&&e[t]!==`
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @kodax-ai/kodax — bundled distribution. See docs/ADR.md ADR-022 + ADR-024.
|
|
2
|
-
import{B as Ho,H as be,M as ss,O as is,P as as,Q as ls,j as Qr,l as He,m as Bn,n as es,o as os,p as ns,q as Gn,t as Fo,v as ts,x as qn,y as Kn,z as rs}from"./chunk-AKMXJSGM.js";import{a as cs}from"./chunk-CW32NQFO.js";import{Aa as Vr,Ba as Yr,Ha as Jr,Ja as Zr}from"./chunk-WCSSXBHR.js";import{i as No}from"./chunk-DEICMTHO.js";import{A as Ur,D as Se,J as Fe,m as Oo,n as Do,o as je,q as io,r as Uo,s as Wr,t as Nr,v as Or,w as jn,x as Dr,y as ao}from"./chunk-KBBGDRER.js";import{h as Lr,ia as Hr,ja as Br}from"./chunk-RS2GAABJ.js";import{$ as Wo,$c as qr,Ic as Fr,Kc as re,Qb as Fn,Rb as jo,Ub as jr,Zc as Gr,ad as Kr,dd as Hn,w as Mr,xd as zr,zd as Xr}from"./chunk-YH5BTUQO.js";import{Ja as Nn,Ka as We,La as Ne,s as Wn,z as hr}from"./chunk-O7N22GJ3.js";import{Ab as vr,Bb as $r,Dd as Ue,Ea as yr,Ed as Ir,Fa as kr,Fb as Sr,Ga as Dn,Qb as br,Rb as xr,Sb as Ar,Td as Pr,Wd as Un,dc as $e,de as Lo,ec as De,jc as Rr,k as On,lc as _o,n as q,nc as Mo,oc as Er,pc as Cr,ue as _r,ya as Oe,yc as Tr,za as H}from"./chunk-NVDK375I.js";import{a,b as Ln,d as Sa}from"./chunk-ONUPGMER.js";var ys=Ln((Cf,hs)=>{"use strict";hs.exports=a(function(o){return o.map(function(n){return n===""?"''":n&&typeof n=="object"?n.op.replace(/(.)/g,"\\$1"):/["\s\\]/.test(n)&&!/'/.test(n)?"'"+n.replace(/(['])/g,"\\$1")+"'":/["'\s]/.test(n)?'"'+n.replace(/(["\\$`!])/g,"\\$1")+'"':String(n).replace(/([A-Za-z]:)?([#!"$&'()*,:;<=>?@[\\\]^`{|}])/g,"$1\\$2")}).join(" ")},"quote")});var As=Ln((If,xs)=>{"use strict";var bs="(?:"+["\\|\\|","\\&\\&",";;","\\|\\&","\\<\\(","\\<\\<\\<",">>",">\\&","<\\&","[&;()|<>]"].join("|")+")",ks=new RegExp("^"+bs+"$"),vs="|&;()<> \\t",Aa='"((\\\\"|[^"])*?)"',Ra="'((\\\\'|[^'])*?)'",Ea=/^#$/,$s="'",Ss='"',zn="$",xe="",Ca=4294967296;for(Xn=0;Xn<4;Xn++)xe+=(Ca*Math.random()).toString(16);var Xn,Ta=new RegExp("^"+xe);function Ia(e,o){for(var n=o.lastIndex,t=[],r;r=o.exec(e);)t.push(r),o.lastIndex===r.index&&(o.lastIndex+=1);return o.lastIndex=n,t}a(Ia,"matchAll");function Pa(e,o,n){var t=typeof e=="function"?e(n):e[n];return typeof t>"u"&&n!=""?t="":typeof t>"u"&&(t="$"),typeof t=="object"?o+xe+JSON.stringify(t)+xe:o+t}a(Pa,"getVar");function _a(e,o,n){n||(n={});var t=n.escape||"\\",r="(\\"+t+`['"`+vs+`]|[^\\s'"`+vs+"])+",i=new RegExp(["("+bs+")","("+r+"|"+Aa+"|"+Ra+")+"].join("|"),"g"),l=Ia(e,i);if(l.length===0)return[];o||(o={});var c=!1;return l.map(function(d){var u=d[0];if(!u||c)return;if(ks.test(u))return{op:u};var f=!1,m=!1,y="",v=!1,k;function $(){k+=1;var I,M,V=u.charAt(k);if(V==="{"){if(k+=1,u.charAt(k)==="}")throw new Error("Bad substitution: "+u.slice(k-2,k+1));if(I=u.indexOf("}",k),I<0)throw new Error("Bad substitution: "+u.slice(k));M=u.slice(k,I),k=I}else if(/[*@#?$!_-]/.test(V))M=V,k+=1;else{var Y=u.slice(k);I=Y.match(/[^\w\d_]/),I?(M=Y.slice(0,I.index),k+=I.index-1):(M=Y,k=u.length)}return Pa(o,"",M)}for(a($,"parseEnvVar"),k=0;k<u.length;k++){var g=u.charAt(k);if(v=v||!f&&(g==="*"||g==="?"),m)y+=g,m=!1;else if(f)g===f?f=!1:f==$s?y+=g:g===t?(k+=1,g=u.charAt(k),g===Ss||g===t||g===zn?y+=g:y+=t+g):g===zn?y+=$():y+=g;else if(g===Ss||g===$s)f=g;else{if(ks.test(g))return{op:u};if(Ea.test(g)){c=!0;var b={comment:e.slice(d.index+k+1)};return y.length?[y,b]:[b]}else g===t?m=!0:g===zn?y+=$():y+=g}}return v?{op:"glob",pattern:y}:y}).reduce(function(d,u){return typeof u>"u"?d:d.concat(u)},[])}a(_a,"parseInternal");xs.exports=a(function(o,n,t){var r=_a(o,n,t);return typeof n!="function"?r:r.reduce(function(i,l){if(typeof l=="object")return i.concat(l);var c=l.split(RegExp("("+xe+".*?"+xe+")","g"));return c.length===1?i.concat(c[0]):i.concat(c.filter(Boolean).map(function(d){return Ta.test(d)?JSON.parse(d.split(xe)[1]):d}))},[])},"parse")});var Rs=Ln(Vn=>{"use strict";Vn.quote=ys();Vn.parse=As()});import*as En from"fs";import*as To from"path";import*as bn from"fs";import Sn from"path";import s from"chalk";var Bo=["plan","accept-edits","auto","auto-in-project"];function $f(e){return e==="auto"||e==="auto-in-project"}a($f,"isAutoMode");function ba(e){switch(e){case"plan":return"Plan";case"accept-edits":return"Edits";case"auto":case"auto-in-project":return"Auto"}}a(ba,"permissionModeDisplayName");var xa='[deprecated] permissionMode "auto-in-project" is now an alias for "auto" (FEATURE_092, v0.7.33). The alias will be removed in v0.7.38 \u2014 please update ~/.kodax/config.json to use "auto".';function Sf(e=o=>{q({source:"repl:permission",level:"warn",message:o})}){let o=!1;return()=>{o||(o=!0,e(xa))}}a(Sf,"createAutoInProjectDeprecationEmitter");var ds=zr(),lo=new Set(ds.filter(e=>e.sideEffect==="mutates-fs"&&e.requiredParams.includes("path")).map(e=>e.name)),us=new Set(ds.filter(e=>e.sideEffect!=="readonly").map(e=>e.name)),fs=new Set(["npm install","npm i","npm uninstall","npm remove","npm update","npm ci","yarn add","yarn remove","yarn upgrade","pnpm add","pnpm remove","pnpm update","git clean","git reset","git checkout","git switch","git merge","git rebase","git cherry-pick","git revert","git commit","git push","git pull","rm","mv","cp","mkdir","rmdir","touch","chmod","chown","del","erase","rd","copy","move","ren","curl","wget","dd","tar","kill","pkill","killall"]),ms=new Set(["ls","cat","pwd","echo","whoami","date","which","whereis","tree","dir","type","get-childitem","get-content","select-string","get-location","where","grep","find","awk","sed","head","tail","less","more","wc","findstr","fc","git status","git diff","git log","git show","git branch","git remote","git ls-files","git rev-parse","git grep","git tag","git stash list","git describe","git config --get","node","npm","yarn","pnpm","tsc","python","pip","go","cargo","rustc"]);function ps(e){switch(e){case"plan":return new Set(["bash","write","edit","undo"]);case"accept-edits":return new Set(["bash"]);case"auto":case"auto-in-project":return new Set}}a(ps,"computeConfirmTools");function gs(e){return e!==void 0&&Bo.includes(e)}a(gs,"isPermissionMode");function co(e,o){return gs(e)?e:o}a(co,"normalizePermissionMode");async function ws(e){let o=e.resolve(e.provider),n=[];for(let t of e.efforts){if(e.signal?.aborted)break;let r=!1;try{await o.stream([{role:"user",content:"ping"}],[],"",{effort:t},{modelOverride:e.model,maxOutputTokensOverride:1,onReasoningEffortRejected:a(()=>{r=!0},"onReasoningEffortRejected"),onTextDelta:a(()=>{},"onTextDelta")},e.signal)}catch(i){n.push({effort:t,status:"error",error:i instanceof Error?i.message:String(i)});continue}r?(kr(e.provider,e.model,t,"probed",e.now()),n.push({effort:t,status:"rejected"})):n.push({effort:t,status:"accepted"})}return n}a(ws,"probeProviderReasoningEfforts");import Vo from"fs";import Fs from"path";import Go from"fs";import W from"path";import fo from"os";var Ts=Sa(Rs(),1);var Es=new Set(["/dev/null","nul","NUL"]);function Yn(e){return Es.has(e)||Es.has(e.toLowerCase())}a(Yn,"isNullDevice");function uo(e){let o=e.trim();if(!o)return{statements:[],unparseable:!1};if(o.includes("`"))return{statements:[],unparseable:!0};let n;try{n=(0,Ts.parse)(o)}catch{return{statements:[],unparseable:!0}}let t=[],r=[],i=[],l=[],c=null,d=!1,u=a(()=>{(i.length>0||l.length>0)&&(r.push({argv:i,redirections:l}),i=[],l=[])},"flushStage"),f=a(m=>{u(),r.length>0&&(t.push({precedingOp:c,stages:r}),r=[]),c=m},"flushStatement");for(let m=0;m<n.length;m+=1){let y=n[m];if(typeof y=="string"){i.push(y);continue}if("op"in y){let v=y.op;if(v==="&&"||v==="||"||v===";"){f(v);continue}if(v==="|"){u();continue}if(v==="&"){let k=n[m+1];if(k!==void 0&&typeof k!="string"&&"op"in k&&(k.op===">"||k.op===">>")){let $=n[m+2];if(typeof $!="string"){d=!0,m+=1;continue}l.push(Cs(`&${k.op}`,$)),m+=2;continue}d=!0;continue}if(La(v)){let k=null,$=i[i.length-1];$!==void 0&&/^[0-9]+$/.test($)&&(k=$,i.pop());let g=n[m+1];if(typeof g!="string"){d=!0;continue}l.push(Cs(k?`${k}${v}`:v,g)),m+=1;continue}if(v==="glob"){let k=y.pattern;typeof k=="string"?i.push(k):d=!0;continue}d=!0;continue}if("comment"in y)break;d=!0}return f(null),{statements:t,unparseable:d}}a(uo,"parseBashCommand");var Ma=new Set([">",">>","<","<<","<<<","&>","&>>"]),Is=/^([0-9]+|&)(>>?|<<?)$/;function La(e){return Ma.has(e)||Is.test(e)}a(La,"isRedirectionOp");function Cs(e,o){let n=null,t=e,r=Is.exec(e);return r&&(n=r[1],t=r[2]),{op:e,fd:n,append:t===">>"||e==="&>>",input:t==="<"||t==="<<"||e==="<<<",target:o}}a(Cs,"parseRedirection");var Wa=W.join(".agent","plan_mode_doc.md"),qo=new Map,Ko=null;function Na(e){if(!e||!e.trim())return!1;let o=e.trim().replace(/\s+/g," ").toLowerCase();for(let n of ms)if(o===n||o.startsWith(n+" ")){if(n==="sed"&&o.split(/\s+/).some(i=>i.startsWith("-i")||i==="--in-place"))return!1;if(n==="awk"){let r=o.split(/\s+/);if(r.includes("-f")||r.includes("--file"))return!1}if(["node","npm","yarn","pnpm","tsc","python","pip","go","cargo","rustc","ruby","perl"].includes(n)){let r=o.split(/\s+/).slice(1);if(r.length>0&&!r.every(i=>/^(-v|--version|-h|--help)$/.test(i)))return!1}return!0}return!1}a(Na,"isSingleBashReadCommand");var Oa=/^[a-zA-Z0-9]+$/;function Da(e){let o=e.trim();if(!o.endsWith("--help")||o.includes('"')||o.includes("'"))return!1;let n=!1;for(let t of o.split(/\s+/))if(t.startsWith("-"))if(t==="--help")n=!0;else return!1;else if(!Oa.test(t))return!1;return n}a(Da,"isHelpCommand");function Zn(e){if(!e||!e.trim())return!1;if(Da(e))return!0;let o=e.trim().replace(/\\\r?\n/g," "),n=uo(o);if(n.unparseable||n.statements.length===0)return!1;let t=n.statements.length>1||(n.statements[0]?.stages.length??0)>1;for(let r of n.statements){if(r.precedingOp!==null&&r.precedingOp!=="&&")return!1;for(let i of r.stages){for(let c of i.redirections)if(c.input||!Yn(c.target))return!1;let l=i.argv.join(" ");if(l&&!(t&&i.argv[0]?.toLowerCase()==="cd"&&i.argv.length>=2)&&!Na(l))return!1}}return!0}a(Zn,"isBashReadCommand");function Ua(e){let o=e.trim();return o?Zn(o)?null:"[Blocked] Direct !command execution only supports safe read-only commands. Use the bash tool for commands that write files, invoke shells, or require confirmation.":"[Shell: No command provided]"}a(Ua,"getDirectShellBypassBlockReason");var _s=new Set(["remove-item","set-content","add-content","out-file","new-item","copy-item","move-item","rename-item","ni"]);function Qn(e){if(!e||!e.trim())return!1;let o=uo(e);if(o.unparseable)return!1;for(let n of o.statements)for(let t of n.stages){let r=t.argv.map(i=>i.toLowerCase());if(r.length>0){let i=r[0],l=r.length>=2?`${r[0]} ${r[1]}`:null;for(let c of fs)if(c===i||l!==null&&c===l)return!0}for(let i of r)if(_s.has(i))return!0;for(let i of t.redirections)if(!i.input&&!Yn(i.target))return!0}return!1}a(Qn,"isBashWriteCommand");function et(e){let o=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\((.+)\)$/);return o?{tool:o[1].toLowerCase(),pattern:o[2]}:{tool:e.toLowerCase(),pattern:null}}a(et,"parseAllowedToolPattern");function ja(e,o){if(o==="*")return!1;if(o.endsWith(":*")){let n=o.slice(0,-2);return e.startsWith(n)}return e===o}a(ja,"matchesBashPatternLegacy");function Fa(e,o){if(o==="*")return!1;if(o.endsWith(":*")){let n=o.slice(0,-2);return e===n}return e===o}a(Fa,"matchesBashPatternByExtractedPrefix");async function ot(e,o,n,t,r){if(e.toLowerCase()!=="bash")return!1;let i=o.command??"",l=[];for(let c of n){let d=et(c);if(d.tool==="bash"){if(d.pattern===null)return!0;l.push({pattern:d.pattern})}}if(l.length===0)return!1;if(t){let c;try{c=await t.extract(i,r)}catch{return!1}if(c.kind!=="prefix")return!1;for(let{pattern:d}of l)if(d&&Fa(c.value,d))return!0;return!1}for(let{pattern:c}of l)if(c&&ja(i,c))return!0;return!1}a(ot,"isToolCallAllowed");function nt(e,o,n){if(e.toLowerCase()!=="bash")return"";let t=o.command??"",r=t.split(" ");return r.length>1?`Bash(${r.slice(0,2).join(" ")}:*)`:`Bash(${t})`}a(nt,"generateSavePattern");function mo(e,o){try{let n=W.resolve(e),t=W.resolve(o),r=Oe(),i=W.join(t,".kodax");return Be(n,i)||Be(n,r)?!0:!(Be(n,t)||Ws().some(c=>Be(n,c)))}catch{return!1}}a(mo,"isAlwaysConfirmPath");function Ps(e){return!e||e.startsWith("-")?!1:/^\.\.?[/\\]/.test(e)||e.startsWith("~/")||e.startsWith("~\\")||/^[a-zA-Z]:[/\\]/.test(e)?!0:e.startsWith("/")&&e.length>1?!(process.platform==="win32"&&Ha.test(e)):!!(e.startsWith(".")&&/[/\\]/.test(e))}a(Ps,"looksLikePath");var Ha=/^\/[A-Za-z][A-Za-z0-9]*(?::[A-Za-z0-9]+)?$/;function Ba(e){let o=[],n=/["']([^"']+)["']/g,t;for(;(t=n.exec(e))!==null;)o.push(t[1]);let r=/(?:^|\s)(\.\.?\/[^\s]+|\.\.?\\[^\s]+|[a-zA-Z]:\\[^\s]+|~\/[^\s]+|\.[^\s]*[/\\][^\s]*)/g;for(;(t=r.exec(e))!==null;)o.push(t[1]);return o}a(Ba,"legacyRegexPathScan");function Xo(e){let o=new Set,n=uo(e);if(!n.unparseable)for(let t of n.statements)for(let r of t.stages){for(let i of r.argv)Ps(i)&&o.add(i);for(let i of r.redirections)Ps(i.target)&&o.add(i.target)}for(let t of Ba(e))o.add(t);return Array.from(o)}a(Xo,"extractPathsFromCommand");function Ga(e,o){let n=Xo(e);for(let t of n)if(mo(t,o))return!0;return!1}a(Ga,"isCommandOnProtectedPath");function zo(e){let o=W.normalize(e);return process.platform==="win32"?o.toLowerCase():o}a(zo,"normalizePathForComparison");function qa(e,o){return zo(e)===zo(o)}a(qa,"pathsEqual");function Be(e,o){let n=zo(e),t=zo(o);return n===t||n.startsWith(t+W.sep)}a(Be,"isPathInsideDirectory");function tt(e,o){try{let n=W.resolve(o),t=W.resolve(n,Ls(Ms(e)));return Be(t,n)}catch{return!1}}a(tt,"isPathInsideProject");function Ka(e){let o=e.match(/[A-Za-z]:[\\/][^\s;|&<>(){}'"]+|\/[^\s;|&<>(){}'"]+/g);return o?o.filter(n=>!/^(?:\/dev\/|\/proc\/)/i.test(n)):[]}a(Ka,"collectAbsolutePathCandidates");function rt(e){let o=W.resolve(e),n=qo.get(o);if(n)return n;if(Go.existsSync(o)){let c=Go.realpathSync.native(o);return qo.set(o,c),c}let t=[],r=o;for(;!Go.existsSync(r);){let c=W.dirname(r);if(c===r)return qo.set(o,o),o;t.unshift(W.basename(r)),r=c}let i=Go.realpathSync.native(r),l=W.join(i,...t);return qo.set(o,l),l}a(rt,"resolveExistingPathPrefix");function Ms(e){return e==="~"?fo.homedir():e.startsWith(`~${W.sep}`)||e.startsWith("~/")||e.startsWith("~\\")?W.join(fo.homedir(),e.slice(2)):e}a(Ms,"expandHomeDirectory");function Ls(e){let o=fo.tmpdir(),n=[[/^%temp%/i,o],[/^%tmp%/i,o],[/^\$env:temp\b/i,o],[/^\$env:tmp\b/i,o],[/^\$tmpdir\b/i,o],[/^\$temp\b/i,o],[/^\$tmp\b/i,o]];for(let[t,r]of n)if(t.test(e))return e.replace(t,r);return e}a(Ls,"expandSystemTempAlias");function za(e,o){let n=W.resolve(o??process.cwd()),t=Ls(Ms(e)),r=W.isAbsolute(t)?W.resolve(t):W.resolve(n,t);return rt(r)}a(za,"resolvePermissionPath");function Ws(){if(Ko)return Ko;let e=new Set,o=[fo.tmpdir(),process.env.TEMP,process.env.TMP,process.env.TMPDIR].filter(n=>typeof n=="string"&&n.trim().length>0);for(let n of o)try{e.add(rt(n))}catch{}return Ko=Array.from(e),Ko}a(Ws,"getSystemTempDirectories");function st(e){let o=rt(e??process.cwd());return{projectPlanDoc:W.join(o,Wa),systemTempDirs:Ws()}}a(st,"getPlanModeAllowedWritablePaths");function Jn(e,o){let n=za(e,o),{projectPlanDoc:t,systemTempDirs:r}=st(o);return qa(n,t)?!0:r.some(i=>Be(n,i))}a(Jn,"isPlanModeAllowedPath");function Xa(e){let{projectPlanDoc:o,systemTempDirs:n}=st(e),t=n[0]??fo.tmpdir();return`${o} or the system temp directory (${t})`}a(Xa,"formatPlanModeAllowedLocations");var Va=new Set(["-a","--append","-i","--ignore-interrupts"]);function Ya(e){let o=[];for(let n=1;n<e.argv.length;n+=1){let t=e.argv[n];Va.has(t)||t.startsWith("-")||o.push(t)}return o}a(Ya,"collectTeeTargets");function Ja(e){let o=[],n=1,t=!1;for(;n<e.argv.length;){let r=e.argv[n],i=r.toLowerCase();if(i==="-path"||i==="-literalpath"||i==="-destination"){let l=e.argv[n+1];if(l!==void 0&&!l.startsWith("-")){o.push(l),n+=2;continue}}!r.startsWith("-")&&!t&&(o.push(r),t=!0),n+=1}return o}a(Ja,"collectPowerShellWriteTargets");function Ge(e){let o=new Set,n=a(r=>{let i=r?.trim();i&&o.add(i)},"pushTarget");for(let r of Xo(e))n(r);let t=uo(e);if(t.unparseable)return Array.from(o);for(let r of t.statements)for(let i of r.stages){for(let c of i.redirections)c.input||n(c.target);let l=i.argv[0]?.toLowerCase();if(l){if(l==="tee")for(let c of Ya(i))n(c);else if(_s.has(l))for(let c of Ja(i))n(c)}}return Array.from(o)}a(Ge,"collectBashWriteTargets");function Ns(e,o){if(!Qn(e))return{dangerous:!1};let n=new Set([...Ge(e),...Ka(e)]);for(let t of n)if(!tt(t,o))return{dangerous:!0,reason:`Command may modify file outside project: ${t}`};return{dangerous:!1}}a(Ns,"getBashOutsideProjectWriteRisk");function Os(e,o,n){let t=Xa(n);if(Xr(e))return null;if(lo.has(e)){let r=typeof o.path=="string"?o.path:"";return r?Jn(r,n)?null:`[Blocked] Plan mode only allows file modifications in ${t}. Requested path: ${r}`:`[Blocked] Tool '${e}' is not allowed in plan mode unless it targets ${t}.`}if(e==="bash"){let r=o.command??"";if(!Qn(r))return null;let i=Ge(r);if(i.length===0)return`[Blocked] Plan mode only allows bash write operations when every target is either ${t}. Could not determine a safe target from: ${r.slice(0,80)}${r.length>80?"...":""}`;let l=i.find(c=>!Jn(c,n));return l?`[Blocked] Plan mode only allows bash write operations in ${t}. Blocked target: ${l}`:null}return`[Blocked] Tool '${e}' has side effects and is not permitted in plan mode. Switch to accept-edits or auto mode to use it, or work within ${t}.`}a(Os,"getPlanModeBlockReason");import me from"node:path";import Za from"node:os";function qe(e,o){try{let n=me.resolve(e),t=me.resolve(o);return n===t?!0:n.startsWith(t+me.sep)}catch{return!1}}a(qe,"isPathUnder");function Qa(){try{return Oe()}catch{return}}a(Qa,"safeGetAgentConfigHome");function Ds(e,o){let n=Qa();if(n&&qe(e,n))return"user-kodax";let t=me.join(me.resolve(o),".kodax");if(qe(e,t))return"project-kodax"}a(Ds,"resolveProtectedZone");function el(){let e=new Set;try{e.add(Za.tmpdir())}catch{}for(let o of["TEMP","TMP","TMPDIR"]){let n=process.env[o];n&&n.length>0&&e.add(n)}return Array.from(e)}a(el,"getSystemTempDirs");var ol=new Set(["bash"]),nl={toolNames:ol,collect(e,o){let n=typeof e.input.command=="string"?e.input.command:"";if(!n||!o)return[];let t=[],r=new Set,i=new Set,l=el(),c=me.resolve(o);for(let d of Xo(n)){let u;try{u=me.resolve(o,d)}catch{continue}let f=Ds(u,o);if(f){r.has(u)||(r.add(u),t.push({kind:"protected_path",path:d,zone:f}));continue}if(mo(d,o)){let m=l.some(v=>qe(u,v)),y=qe(u,c);!m&&!y&&!i.has(u)&&(i.add(u),t.push({kind:"outside_project",path:d}))}}for(let d of Ge(n)){let u;try{u=me.resolve(o,d)}catch{continue}Ds(u,o)||qe(u,c)||l.some(y=>qe(u,y))||t.push({kind:"shell_redirect_outside",target:d})}return t}};var Yo=H("config.json");function Hs(){return Fs.join(process.cwd(),".kodax","config.local.json")}a(Hs,"getProjectConfigFile");function gm(e=process.env){let n=po(Yo).autoMode??{},t=e.KODAX_AUTO_MODE_ENGINE?.trim(),r=t==="llm"||t==="rules"?t:void 0,i=n.engine==="llm"||n.engine==="rules"?n.engine:void 0,l=r??i??"llm",c=js(n.classifierModel),d=js(e.KODAX_AUTO_MODE_CLASSIFIER_MODEL),u=e.KODAX_AUTO_MODE_TIMEOUT_MS?.trim(),f=u!==void 0?Number(u):NaN,m=Number.isFinite(f)&&f>0?Math.floor(f):void 0,y=typeof n.timeoutMs=="number"&&n.timeoutMs>0?Math.floor(n.timeoutMs):void 0,v=Us(e.KODAX_AUTO_SPECULATIVE_WINDOW_MS?.trim()),k=typeof n.speculativeWindowMs=="number"?Us(String(n.speculativeWindowMs)):void 0;return{engine:l,classifierModel:c,classifierModelEnv:d,timeoutMs:m??y,speculativeWindowMs:v??k}}a(gm,"loadAutoModeSettings");function Us(e){if(e===void 0||e==="")return;let o=Number(e);if(Number.isFinite(o))return o<0?0:Math.floor(o)}a(Us,"parseSpeculativeWindow");function js(e){if(typeof e!="string")return;let o=e.trim();return o.length===0?void 0:o}a(js,"nonEmptyString");function po(e){try{if(Vo.existsSync(e))return JSON.parse(Vo.readFileSync(e,"utf-8"))}catch{}return{}}a(po,"readJsonFile");function Bs(e,o){Vo.mkdirSync(Fs.dirname(e),{recursive:!0}),Vo.writeFileSync(e,JSON.stringify(o,null,2))}a(Bs,"writeJsonFile");function it(e){let o=po(Yo);Bs(Yo,{...o,permissionMode:e})}a(it,"savePermissionModeUser");function wm(){let e=po(Yo),o=po(Hs()),n=e.alwaysAllowTools??[],t=o.alwaysAllowTools??[];return[...new Set([...n,...t])]}a(wm,"loadAlwaysAllowTools");function hm(e,o,n=!1){let t=nt(e,o,n);if(!t)return;let r=Hs(),i=po(r),l=i.alwaysAllowTools??[];l.includes(t)||Bs(r,{...i,alwaysAllowTools:[...l,t]})}a(hm,"saveAlwaysAllowToolPattern");var at=["ama","amaw","sa"];function Gs(e){let o=at.indexOf(e);return at[(o+1)%at.length]??"ama"}a(Gs,"nextAgentMode");var pe=class{static{a(this,"CommandRegistry")}commands=new Map;aliases=new Map;register(o){let n=o.name.toLowerCase();if(this.commands.has(n))throw new Error(`Command "${o.name}" is already registered`);if(this.aliases.has(n)){let r=this.aliases.get(n);throw new Error(`Command "${o.name}" conflicts with existing alias for "${r}"`)}let t=new Set;for(let r of o.aliases??[]){let i=r.toLowerCase();if(i!==n){if(t.has(i))throw new Error(`Alias "${r}" is duplicated within command "${o.name}"`);if(this.commands.has(i))throw new Error(`Alias "${r}" conflicts with existing command "${i}"`);if(this.aliases.has(i)){let l=this.aliases.get(i);throw new Error(`Alias "${r}" is already registered for "${l}"`)}t.add(i)}}if(this.commands.set(n,{...o,source:o.source??"builtin"}),o.aliases)for(let r of o.aliases){let i=r.toLowerCase();i!==n&&this.aliases.set(i,n)}}unregister(o){let n=o.toLowerCase(),t=this.aliases.get(n)??n;if(!this.commands.has(t))return!1;let r=this.commands.get(t);if(r?.aliases)for(let i of r.aliases)this.aliases.delete(i.toLowerCase());return this.commands.delete(t),!0}get(o){let n=o.toLowerCase(),t=this.aliases.get(n)??n;return this.commands.get(t)}has(o){let n=o.toLowerCase(),t=this.aliases.get(n)??n;return this.commands.has(t)}getAll(o){let n=new Map;for(let[t,r]of this.commands)o&&r.source!==o||n.has(t)||n.set(t,{name:r.name,aliases:r.aliases,description:r.description,source:r.source??"builtin",usage:r.usage,priority:r.priority,location:r.location,path:r.path,userInvocable:r.userInvocable,disableModelInvocation:r.disableModelInvocation,allowedTools:r.allowedTools,context:r.context,agent:r.agent,argumentHint:r.argumentHint,model:r.model});return Array.from(n.values()).sort((t,r)=>t.name.localeCompare(r.name))}getBySource(o){return this.getAll(o)}getNames(){return Array.from(this.commands.keys()).sort()}clear(){this.commands.clear(),this.aliases.clear()}get size(){return this.commands.size}get aliasCount(){return this.aliases.size}},tl=new pe;import K from"chalk";import{Buffer as Xs}from"node:buffer";import{spawn as rl}from"node:child_process";import qs from"node:process";var Ae="\x1B",sl="\x07",lt=`${Ae}\\`;function Ks(e,o){return e.SSH_CONNECTION?!1:o==="win32"||o==="darwin"||o==="linux"}a(Ks,"shouldPreferNativeClipboard");function il(e,o){let n=Xs.from(e,"utf8").toString("base64"),t=o.TERM==="xterm-kitty"?lt:sl,r=`${Ae}]52;c;${n}${t}`;return o.TMUX?`${Ae}Ptmux;${r.replaceAll(Ae,`${Ae}${Ae}`)}${lt}`:o.STY?`${Ae}P${r}${lt}`:r}a(il,"buildOscSequence");async function Jo(e,o,n){return new Promise((t,r)=>{let i=rl(e,o,{stdio:["pipe","ignore","pipe"],windowsHide:!0}),l="";i.on("error",r),i.stderr?.on("data",c=>{l+=c.toString()}),i.on("close",c=>{if(c===0){t(!0);return}r(new Error(l.trim()||`${e} exited with code ${c??"unknown"}`))}),i.stdin?.write(n),i.stdin?.end()})}a(Jo,"execClipboardCommand");function al(e){let o="$stream = [Console]::OpenStandardInput(); $buffer = New-Object byte[] 8192; $memory = New-Object System.IO.MemoryStream; while (($read = $stream.Read($buffer, 0, $buffer.Length)) -gt 0) { $memory.Write($buffer, 0, $read) }; $text = [System.Text.Encoding]::UTF8.GetString($memory.ToArray()); Set-Clipboard -Value $text",n=Xs.from(e,"utf8");return[["powershell",["-NoProfile","-NonInteractive","-Command",o],n],["pwsh",["-NoProfile","-NonInteractive","-Command",o],n],["cmd",["/c","chcp 65001 >nul & clip"],n]]}a(al,"buildWindowsClipboardCandidates");async function zs(e,o,n){if(o.SSH_CONNECTION)return!1;switch(n){case"win32":{let t=al(e);for(let[r,i,l]of t)try{if(await Jo(r,i,l))return!0}catch{}return!1}case"darwin":return Jo("pbcopy",[],e);case"linux":{let t=[["wl-copy",[]],["xclip",["-selection","clipboard"]],["xsel",["--clipboard","--input"]]];for(let[r,i]of t)try{if(await Jo(r,i,e))return!0}catch{}return!1}default:return!1}}a(zs,"tryNativeClipboard");async function ll(e,o){if(!o.TMUX)return!1;let n=o.LC_TERMINAL==="iTerm2"?["load-buffer","-"]:["load-buffer","-w","-"];try{return await Jo("tmux",n,e)}catch{return!1}}a(ll,"tryTmuxClipboard");async function Vs(e,o={}){let n=o.env??qs.env,t=o.platform??qs.platform,r=e.trimEnd(),i=il(r,n);if(!r)throw new Error("Nothing to copy.");if(Ks(n,t))try{if(await zs(r,n,t))return{path:"native"}}catch{}if(await ll(r,n))return{path:"tmux-buffer"};if(o.terminalWrite?.(i))return{path:"osc52"};if(!Ks(n,t))try{if(await zs(r,n,t))return{path:"native"}}catch{}throw new Error("Unable to access any clipboard path.")}a(Vs,"copyTextToClipboard");var ct;(function(e){e.Idle="idle",e.Responding="responding",e.WaitingForConfirmation="waiting_for_confirmation"})(ct||(ct={}));var G;(function(e){e.Scheduled="scheduled",e.Validating="validating",e.AwaitingApproval="awaiting_approval",e.Executing="executing",e.Success="success",e.Error="error",e.Cancelled="cancelled"})(G||(G={}));var Tm={[G.Scheduled]:"\u25CB",[G.Validating]:"\u25CC",[G.AwaitingApproval]:"?",[G.Executing]:"\u25CB",[G.Success]:"\u2713",[G.Error]:"\u2717",[G.Cancelled]:"-"},Ys;(function(e){e[e.Low=-100]="Low",e[e.Normal=0]="Normal",e[e.High=100]="High",e[e.Critical=200]="Critical"})(Ys||(Ys={}));var Im={streamingState:ct.Idle,currentResponse:"",history:[],pendingToolCalls:[],sessionId:"",provider:"",model:"",isLoading:!1};var cl="[redacted]",Js="[truncated]";function se(e,o=2e3){return e.length>o?`${e.slice(0,o-3)}...`:e}a(se,"truncateToolReplayText");function dl(e){let o=e.toLowerCase().replace(/[\s_-]/g,"");return o.includes("token")||o.includes("password")||o.includes("secret")||o.includes("apikey")||o.includes("accesstoken")||o==="authorization"||o==="cookie"||o==="setcookie"}a(dl,"isSensitiveToolInputKey");function Zs(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}a(Zs,"isRecord");function dt(e,o=0,n=new WeakSet){if(e===null||typeof e=="number"||typeof e=="boolean")return e;if(typeof e=="string")return se(e);if(o>=6)return Js;if(typeof e=="object"&&e!==null){if(n.has(e))return Js;if(n.add(e),Array.isArray(e))return e.slice(0,50).map(r=>dt(r,o+1,n));if(!Zs(e))return se(String(e));let t={};for(let[r,i]of Object.entries(e).slice(0,50))t[r]=dl(r)?cl:dt(i,o+1,n);return t}return se(String(e))}a(dt,"sanitizeToolJsonValue");function Qs(e){if(!e)return;let o=dt(e);return Zs(o)?o:void 0}a(Qs,"sanitizeToolInput");function ei(e){if(e!==void 0){if(typeof e=="string")return se(e);try{return se(JSON.stringify(e))}catch{return se(String(e))}}}a(ei,"stringifyToolReplayValue");function Nm(e){return e.type==="tool_summary"||e.type==="task_completed"?{type:"event",text:e.text,icon:"tool"}:e.type==="tool_group"?{type:"tool_group",tools:e.tools.map(yl)}:e}a(Nm,"seedToHistoryItem");var ul="[Thinking]",fl="[/Thinking]",ml="Untitled Session",oi=50,pl=60,ti="...",ri=["[Managed Task]","[Managed Task Protocol Retry]","Assigned native agent identity:","Tool policy:","Blocked tools:","Allowed shell patterns:","Dependency handoff artifacts:","Dependency summary preview:","Preferred agent:","Read structured bundle first:","Read human summary next:"],si=[/(?:^|\n)You are the [^\n]+ role for a managed KodaX task\./,/(?:^|\n)Primary task:/,/(?:^|\n)Work intent:/,/(?:^|\n)Complexity:/,/(?:^|\n)Risk:/,/(?:^|\n)Harness:/,/(?:^|\n)Brainstorm required:/],gl=/(^|\r?\n)\[Thinking\]\r?\n([\s\S]*?)\r?\n\[\/Thinking\](?=\r?\n|$)/g,wl="Session ended before the tool completed.";function hl(e){switch(e){case"success":return G.Success;case"error":return G.Error;case"cancelled":return G.Cancelled;case"awaiting_approval":return G.AwaitingApproval;default:return e}}a(hl,"toolCallSeedToHistoryToolStatus");function yl(e){return{id:e.id,name:e.name,status:hl(e.status),...e.input!==void 0?{input:e.input}:{},...e.preview!==void 0?{preview:e.preview}:{},...e.output!==void 0?{output:e.output}:{},...e.error!==void 0?{error:e.error}:{},startTime:e.startTime??Date.now(),...e.endTime!==void 0?{endTime:e.endTime}:{}}}a(yl,"toolCallSeedToHistoryToolCall");function kl(e){let o=-1;for(let n of ri){let t=e.indexOf(n);t>=0&&(o===-1||t<o)&&(o=t)}for(let n of si){let t=n.exec(e);t&&t.index>=0&&(o===-1||t.index<o)&&(o=t.index)}return o}a(kl,"findControlPlaneCutIndex");function vl(e){return ri.some(o=>e.includes(o))||si.some(o=>o.test(e))}a(vl,"hasControlPlaneSignal");function ii(e){let o=[];for(let n of e)n&&typeof n=="object"&&"type"in n&&n.type==="text"&&"text"in n&&o.push(String(n.text));return o}a(ii,"collectTextBlocks");function Qo(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}a(Qo,"isRecord");function $l(e){if(typeof e=="string")return se(e);if(e===void 0)return"";try{return ei(e)??""}catch{return se(String(e))}}a($l,"toolResultContentToString");function Sl(e){let o=$l(e.content),n=o.trimStart(),t=e.is_error===!0||n.startsWith("[Tool Error]")||n.startsWith("[Error]"),r=n.startsWith("[Cancelled]")||n.startsWith("[Blocked]");return t?{status:"error",error:o}:r?{status:"cancelled",error:o}:{status:"success",output:o}}a(Sl,"inferToolResultSeed");function bl(e){let o=new Map;if(!e||e.role!=="user"||!Array.isArray(e.content))return o;for(let n of e.content)!Qo(n)||n.type!=="tool_result"||typeof n.tool_use_id!="string"||o.set(n.tool_use_id,Sl(n));return o}a(bl,"collectToolResultSeeds");function xl(e,o){if(e.type!=="tool_use"||typeof e.id!="string"||typeof e.name!="string")return;let n=o.get(e.id)??{status:"cancelled",error:wl};return{id:e.id,name:e.name,status:n.status,...e.input!==void 0?{input:Qs(Qo(e.input)?e.input:{})??{}}:{},...n.output!==void 0?{output:n.output}:{},...n.error!==void 0?{error:n.error}:{}}}a(xl,"buildToolCallSeed");function Al(e){return typeof e=="string"?e:Array.isArray(e)?ii(e).join(`
|
|
2
|
+
import{B as Ho,H as be,M as ss,O as is,P as as,Q as ls,j as Qr,l as He,m as Bn,n as es,o as os,p as ns,q as Gn,t as Fo,v as ts,x as qn,y as Kn,z as rs}from"./chunk-OIELNE6Z.js";import{a as cs}from"./chunk-TOGESFRN.js";import{Aa as Vr,Ba as Yr,Ha as Jr,Ja as Zr}from"./chunk-KIQRCGVR.js";import{i as No}from"./chunk-CC4BVVE7.js";import{A as Ur,D as Se,J as Fe,m as Oo,n as Do,o as je,q as io,r as Uo,s as Wr,t as Nr,v as Or,w as jn,x as Dr,y as ao}from"./chunk-KGAI32VS.js";import{h as Lr,ka as Hr,la as Br}from"./chunk-HLBHSA2B.js";import{A as Mr,Bd as zr,Dd as Xr,Mc as Fr,Oc as re,Ub as Fn,Vb as jo,Yb as jr,bd as Gr,da as Wo,dd as qr,ed as Kr,hd as Hn}from"./chunk-C4SBXBWH.js";import{Ja as Nn,Ka as We,La as Ne,s as Wn,z as hr}from"./chunk-K2NCKRVY.js";import{Fc as Ue,Gc as Ir,Vc as Pr,Yc as Un,fd as Lo,k as On,wd as _r,xa as yr,xb as Tr,ya as kr,za as Dn}from"./chunk-67XJ4YUA.js";import{F as br,G as xr,H as Ar,U as $e,V as De,_ as Rr,aa as _o,b as q,ca as Mo,da as Er,e as Oe,ea as Cr,f as H,o as vr,p as $r,u as Sr}from"./chunk-5GL55MOH.js";import{a,b as Ln,d as Sa}from"./chunk-ONUPGMER.js";var ys=Ln((Cf,hs)=>{"use strict";hs.exports=a(function(o){return o.map(function(n){return n===""?"''":n&&typeof n=="object"?n.op.replace(/(.)/g,"\\$1"):/["\s\\]/.test(n)&&!/'/.test(n)?"'"+n.replace(/(['])/g,"\\$1")+"'":/["'\s]/.test(n)?'"'+n.replace(/(["\\$`!])/g,"\\$1")+'"':String(n).replace(/([A-Za-z]:)?([#!"$&'()*,:;<=>?@[\\\]^`{|}])/g,"$1\\$2")}).join(" ")},"quote")});var As=Ln((If,xs)=>{"use strict";var bs="(?:"+["\\|\\|","\\&\\&",";;","\\|\\&","\\<\\(","\\<\\<\\<",">>",">\\&","<\\&","[&;()|<>]"].join("|")+")",ks=new RegExp("^"+bs+"$"),vs="|&;()<> \\t",Aa='"((\\\\"|[^"])*?)"',Ra="'((\\\\'|[^'])*?)'",Ea=/^#$/,$s="'",Ss='"',zn="$",xe="",Ca=4294967296;for(Xn=0;Xn<4;Xn++)xe+=(Ca*Math.random()).toString(16);var Xn,Ta=new RegExp("^"+xe);function Ia(e,o){for(var n=o.lastIndex,t=[],r;r=o.exec(e);)t.push(r),o.lastIndex===r.index&&(o.lastIndex+=1);return o.lastIndex=n,t}a(Ia,"matchAll");function Pa(e,o,n){var t=typeof e=="function"?e(n):e[n];return typeof t>"u"&&n!=""?t="":typeof t>"u"&&(t="$"),typeof t=="object"?o+xe+JSON.stringify(t)+xe:o+t}a(Pa,"getVar");function _a(e,o,n){n||(n={});var t=n.escape||"\\",r="(\\"+t+`['"`+vs+`]|[^\\s'"`+vs+"])+",i=new RegExp(["("+bs+")","("+r+"|"+Aa+"|"+Ra+")+"].join("|"),"g"),l=Ia(e,i);if(l.length===0)return[];o||(o={});var c=!1;return l.map(function(d){var u=d[0];if(!u||c)return;if(ks.test(u))return{op:u};var f=!1,m=!1,y="",v=!1,k;function $(){k+=1;var I,M,V=u.charAt(k);if(V==="{"){if(k+=1,u.charAt(k)==="}")throw new Error("Bad substitution: "+u.slice(k-2,k+1));if(I=u.indexOf("}",k),I<0)throw new Error("Bad substitution: "+u.slice(k));M=u.slice(k,I),k=I}else if(/[*@#?$!_-]/.test(V))M=V,k+=1;else{var Y=u.slice(k);I=Y.match(/[^\w\d_]/),I?(M=Y.slice(0,I.index),k+=I.index-1):(M=Y,k=u.length)}return Pa(o,"",M)}for(a($,"parseEnvVar"),k=0;k<u.length;k++){var g=u.charAt(k);if(v=v||!f&&(g==="*"||g==="?"),m)y+=g,m=!1;else if(f)g===f?f=!1:f==$s?y+=g:g===t?(k+=1,g=u.charAt(k),g===Ss||g===t||g===zn?y+=g:y+=t+g):g===zn?y+=$():y+=g;else if(g===Ss||g===$s)f=g;else{if(ks.test(g))return{op:u};if(Ea.test(g)){c=!0;var b={comment:e.slice(d.index+k+1)};return y.length?[y,b]:[b]}else g===t?m=!0:g===zn?y+=$():y+=g}}return v?{op:"glob",pattern:y}:y}).reduce(function(d,u){return typeof u>"u"?d:d.concat(u)},[])}a(_a,"parseInternal");xs.exports=a(function(o,n,t){var r=_a(o,n,t);return typeof n!="function"?r:r.reduce(function(i,l){if(typeof l=="object")return i.concat(l);var c=l.split(RegExp("("+xe+".*?"+xe+")","g"));return c.length===1?i.concat(c[0]):i.concat(c.filter(Boolean).map(function(d){return Ta.test(d)?JSON.parse(d.split(xe)[1]):d}))},[])},"parse")});var Rs=Ln(Vn=>{"use strict";Vn.quote=ys();Vn.parse=As()});import*as En from"fs";import*as To from"path";import*as bn from"fs";import Sn from"path";import s from"chalk";var Bo=["plan","accept-edits","auto","auto-in-project"];function $f(e){return e==="auto"||e==="auto-in-project"}a($f,"isAutoMode");function ba(e){switch(e){case"plan":return"Plan";case"accept-edits":return"Edits";case"auto":case"auto-in-project":return"Auto"}}a(ba,"permissionModeDisplayName");var xa='[deprecated] permissionMode "auto-in-project" is now an alias for "auto" (FEATURE_092, v0.7.33). The alias will be removed in v0.7.38 \u2014 please update ~/.kodax/config.json to use "auto".';function Sf(e=o=>{q({source:"repl:permission",level:"warn",message:o})}){let o=!1;return()=>{o||(o=!0,e(xa))}}a(Sf,"createAutoInProjectDeprecationEmitter");var ds=zr(),lo=new Set(ds.filter(e=>e.sideEffect==="mutates-fs"&&e.requiredParams.includes("path")).map(e=>e.name)),us=new Set(ds.filter(e=>e.sideEffect!=="readonly").map(e=>e.name)),fs=new Set(["npm install","npm i","npm uninstall","npm remove","npm update","npm ci","yarn add","yarn remove","yarn upgrade","pnpm add","pnpm remove","pnpm update","git clean","git reset","git checkout","git switch","git merge","git rebase","git cherry-pick","git revert","git commit","git push","git pull","rm","mv","cp","mkdir","rmdir","touch","chmod","chown","del","erase","rd","copy","move","ren","curl","wget","dd","tar","kill","pkill","killall"]),ms=new Set(["ls","cat","pwd","echo","whoami","date","which","whereis","tree","dir","type","get-childitem","get-content","select-string","get-location","where","grep","find","awk","sed","head","tail","less","more","wc","findstr","fc","git status","git diff","git log","git show","git branch","git remote","git ls-files","git rev-parse","git grep","git tag","git stash list","git describe","git config --get","node","npm","yarn","pnpm","tsc","python","pip","go","cargo","rustc"]);function ps(e){switch(e){case"plan":return new Set(["bash","write","edit","undo"]);case"accept-edits":return new Set(["bash"]);case"auto":case"auto-in-project":return new Set}}a(ps,"computeConfirmTools");function gs(e){return e!==void 0&&Bo.includes(e)}a(gs,"isPermissionMode");function co(e,o){return gs(e)?e:o}a(co,"normalizePermissionMode");async function ws(e){let o=e.resolve(e.provider),n=[];for(let t of e.efforts){if(e.signal?.aborted)break;let r=!1;try{await o.stream([{role:"user",content:"ping"}],[],"",{effort:t},{modelOverride:e.model,maxOutputTokensOverride:1,onReasoningEffortRejected:a(()=>{r=!0},"onReasoningEffortRejected"),onTextDelta:a(()=>{},"onTextDelta")},e.signal)}catch(i){n.push({effort:t,status:"error",error:i instanceof Error?i.message:String(i)});continue}r?(kr(e.provider,e.model,t,"probed",e.now()),n.push({effort:t,status:"rejected"})):n.push({effort:t,status:"accepted"})}return n}a(ws,"probeProviderReasoningEfforts");import Vo from"fs";import Fs from"path";import Go from"fs";import W from"path";import fo from"os";var Ts=Sa(Rs(),1);var Es=new Set(["/dev/null","nul","NUL"]);function Yn(e){return Es.has(e)||Es.has(e.toLowerCase())}a(Yn,"isNullDevice");function uo(e){let o=e.trim();if(!o)return{statements:[],unparseable:!1};if(o.includes("`"))return{statements:[],unparseable:!0};let n;try{n=(0,Ts.parse)(o)}catch{return{statements:[],unparseable:!0}}let t=[],r=[],i=[],l=[],c=null,d=!1,u=a(()=>{(i.length>0||l.length>0)&&(r.push({argv:i,redirections:l}),i=[],l=[])},"flushStage"),f=a(m=>{u(),r.length>0&&(t.push({precedingOp:c,stages:r}),r=[]),c=m},"flushStatement");for(let m=0;m<n.length;m+=1){let y=n[m];if(typeof y=="string"){i.push(y);continue}if("op"in y){let v=y.op;if(v==="&&"||v==="||"||v===";"){f(v);continue}if(v==="|"){u();continue}if(v==="&"){let k=n[m+1];if(k!==void 0&&typeof k!="string"&&"op"in k&&(k.op===">"||k.op===">>")){let $=n[m+2];if(typeof $!="string"){d=!0,m+=1;continue}l.push(Cs(`&${k.op}`,$)),m+=2;continue}d=!0;continue}if(La(v)){let k=null,$=i[i.length-1];$!==void 0&&/^[0-9]+$/.test($)&&(k=$,i.pop());let g=n[m+1];if(typeof g!="string"){d=!0;continue}l.push(Cs(k?`${k}${v}`:v,g)),m+=1;continue}if(v==="glob"){let k=y.pattern;typeof k=="string"?i.push(k):d=!0;continue}d=!0;continue}if("comment"in y)break;d=!0}return f(null),{statements:t,unparseable:d}}a(uo,"parseBashCommand");var Ma=new Set([">",">>","<","<<","<<<","&>","&>>"]),Is=/^([0-9]+|&)(>>?|<<?)$/;function La(e){return Ma.has(e)||Is.test(e)}a(La,"isRedirectionOp");function Cs(e,o){let n=null,t=e,r=Is.exec(e);return r&&(n=r[1],t=r[2]),{op:e,fd:n,append:t===">>"||e==="&>>",input:t==="<"||t==="<<"||e==="<<<",target:o}}a(Cs,"parseRedirection");var Wa=W.join(".agent","plan_mode_doc.md"),qo=new Map,Ko=null;function Na(e){if(!e||!e.trim())return!1;let o=e.trim().replace(/\s+/g," ").toLowerCase();for(let n of ms)if(o===n||o.startsWith(n+" ")){if(n==="sed"&&o.split(/\s+/).some(i=>i.startsWith("-i")||i==="--in-place"))return!1;if(n==="awk"){let r=o.split(/\s+/);if(r.includes("-f")||r.includes("--file"))return!1}if(["node","npm","yarn","pnpm","tsc","python","pip","go","cargo","rustc","ruby","perl"].includes(n)){let r=o.split(/\s+/).slice(1);if(r.length>0&&!r.every(i=>/^(-v|--version|-h|--help)$/.test(i)))return!1}return!0}return!1}a(Na,"isSingleBashReadCommand");var Oa=/^[a-zA-Z0-9]+$/;function Da(e){let o=e.trim();if(!o.endsWith("--help")||o.includes('"')||o.includes("'"))return!1;let n=!1;for(let t of o.split(/\s+/))if(t.startsWith("-"))if(t==="--help")n=!0;else return!1;else if(!Oa.test(t))return!1;return n}a(Da,"isHelpCommand");function Zn(e){if(!e||!e.trim())return!1;if(Da(e))return!0;let o=e.trim().replace(/\\\r?\n/g," "),n=uo(o);if(n.unparseable||n.statements.length===0)return!1;let t=n.statements.length>1||(n.statements[0]?.stages.length??0)>1;for(let r of n.statements){if(r.precedingOp!==null&&r.precedingOp!=="&&")return!1;for(let i of r.stages){for(let c of i.redirections)if(c.input||!Yn(c.target))return!1;let l=i.argv.join(" ");if(l&&!(t&&i.argv[0]?.toLowerCase()==="cd"&&i.argv.length>=2)&&!Na(l))return!1}}return!0}a(Zn,"isBashReadCommand");function Ua(e){let o=e.trim();return o?Zn(o)?null:"[Blocked] Direct !command execution only supports safe read-only commands. Use the bash tool for commands that write files, invoke shells, or require confirmation.":"[Shell: No command provided]"}a(Ua,"getDirectShellBypassBlockReason");var _s=new Set(["remove-item","set-content","add-content","out-file","new-item","copy-item","move-item","rename-item","ni"]);function Qn(e){if(!e||!e.trim())return!1;let o=uo(e);if(o.unparseable)return!1;for(let n of o.statements)for(let t of n.stages){let r=t.argv.map(i=>i.toLowerCase());if(r.length>0){let i=r[0],l=r.length>=2?`${r[0]} ${r[1]}`:null;for(let c of fs)if(c===i||l!==null&&c===l)return!0}for(let i of r)if(_s.has(i))return!0;for(let i of t.redirections)if(!i.input&&!Yn(i.target))return!0}return!1}a(Qn,"isBashWriteCommand");function et(e){let o=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\((.+)\)$/);return o?{tool:o[1].toLowerCase(),pattern:o[2]}:{tool:e.toLowerCase(),pattern:null}}a(et,"parseAllowedToolPattern");function ja(e,o){if(o==="*")return!1;if(o.endsWith(":*")){let n=o.slice(0,-2);return e.startsWith(n)}return e===o}a(ja,"matchesBashPatternLegacy");function Fa(e,o){if(o==="*")return!1;if(o.endsWith(":*")){let n=o.slice(0,-2);return e===n}return e===o}a(Fa,"matchesBashPatternByExtractedPrefix");async function ot(e,o,n,t,r){if(e.toLowerCase()!=="bash")return!1;let i=o.command??"",l=[];for(let c of n){let d=et(c);if(d.tool==="bash"){if(d.pattern===null)return!0;l.push({pattern:d.pattern})}}if(l.length===0)return!1;if(t){let c;try{c=await t.extract(i,r)}catch{return!1}if(c.kind!=="prefix")return!1;for(let{pattern:d}of l)if(d&&Fa(c.value,d))return!0;return!1}for(let{pattern:c}of l)if(c&&ja(i,c))return!0;return!1}a(ot,"isToolCallAllowed");function nt(e,o,n){if(e.toLowerCase()!=="bash")return"";let t=o.command??"",r=t.split(" ");return r.length>1?`Bash(${r.slice(0,2).join(" ")}:*)`:`Bash(${t})`}a(nt,"generateSavePattern");function mo(e,o){try{let n=W.resolve(e),t=W.resolve(o),r=Oe(),i=W.join(t,".kodax");return Be(n,i)||Be(n,r)?!0:!(Be(n,t)||Ws().some(c=>Be(n,c)))}catch{return!1}}a(mo,"isAlwaysConfirmPath");function Ps(e){return!e||e.startsWith("-")?!1:/^\.\.?[/\\]/.test(e)||e.startsWith("~/")||e.startsWith("~\\")||/^[a-zA-Z]:[/\\]/.test(e)?!0:e.startsWith("/")&&e.length>1?!(process.platform==="win32"&&Ha.test(e)):!!(e.startsWith(".")&&/[/\\]/.test(e))}a(Ps,"looksLikePath");var Ha=/^\/[A-Za-z][A-Za-z0-9]*(?::[A-Za-z0-9]+)?$/;function Ba(e){let o=[],n=/["']([^"']+)["']/g,t;for(;(t=n.exec(e))!==null;)o.push(t[1]);let r=/(?:^|\s)(\.\.?\/[^\s]+|\.\.?\\[^\s]+|[a-zA-Z]:\\[^\s]+|~\/[^\s]+|\.[^\s]*[/\\][^\s]*)/g;for(;(t=r.exec(e))!==null;)o.push(t[1]);return o}a(Ba,"legacyRegexPathScan");function Xo(e){let o=new Set,n=uo(e);if(!n.unparseable)for(let t of n.statements)for(let r of t.stages){for(let i of r.argv)Ps(i)&&o.add(i);for(let i of r.redirections)Ps(i.target)&&o.add(i.target)}for(let t of Ba(e))o.add(t);return Array.from(o)}a(Xo,"extractPathsFromCommand");function Ga(e,o){let n=Xo(e);for(let t of n)if(mo(t,o))return!0;return!1}a(Ga,"isCommandOnProtectedPath");function zo(e){let o=W.normalize(e);return process.platform==="win32"?o.toLowerCase():o}a(zo,"normalizePathForComparison");function qa(e,o){return zo(e)===zo(o)}a(qa,"pathsEqual");function Be(e,o){let n=zo(e),t=zo(o);return n===t||n.startsWith(t+W.sep)}a(Be,"isPathInsideDirectory");function tt(e,o){try{let n=W.resolve(o),t=W.resolve(n,Ls(Ms(e)));return Be(t,n)}catch{return!1}}a(tt,"isPathInsideProject");function Ka(e){let o=e.match(/[A-Za-z]:[\\/][^\s;|&<>(){}'"]+|\/[^\s;|&<>(){}'"]+/g);return o?o.filter(n=>!/^(?:\/dev\/|\/proc\/)/i.test(n)):[]}a(Ka,"collectAbsolutePathCandidates");function rt(e){let o=W.resolve(e),n=qo.get(o);if(n)return n;if(Go.existsSync(o)){let c=Go.realpathSync.native(o);return qo.set(o,c),c}let t=[],r=o;for(;!Go.existsSync(r);){let c=W.dirname(r);if(c===r)return qo.set(o,o),o;t.unshift(W.basename(r)),r=c}let i=Go.realpathSync.native(r),l=W.join(i,...t);return qo.set(o,l),l}a(rt,"resolveExistingPathPrefix");function Ms(e){return e==="~"?fo.homedir():e.startsWith(`~${W.sep}`)||e.startsWith("~/")||e.startsWith("~\\")?W.join(fo.homedir(),e.slice(2)):e}a(Ms,"expandHomeDirectory");function Ls(e){let o=fo.tmpdir(),n=[[/^%temp%/i,o],[/^%tmp%/i,o],[/^\$env:temp\b/i,o],[/^\$env:tmp\b/i,o],[/^\$tmpdir\b/i,o],[/^\$temp\b/i,o],[/^\$tmp\b/i,o]];for(let[t,r]of n)if(t.test(e))return e.replace(t,r);return e}a(Ls,"expandSystemTempAlias");function za(e,o){let n=W.resolve(o??process.cwd()),t=Ls(Ms(e)),r=W.isAbsolute(t)?W.resolve(t):W.resolve(n,t);return rt(r)}a(za,"resolvePermissionPath");function Ws(){if(Ko)return Ko;let e=new Set,o=[fo.tmpdir(),process.env.TEMP,process.env.TMP,process.env.TMPDIR].filter(n=>typeof n=="string"&&n.trim().length>0);for(let n of o)try{e.add(rt(n))}catch{}return Ko=Array.from(e),Ko}a(Ws,"getSystemTempDirectories");function st(e){let o=rt(e??process.cwd());return{projectPlanDoc:W.join(o,Wa),systemTempDirs:Ws()}}a(st,"getPlanModeAllowedWritablePaths");function Jn(e,o){let n=za(e,o),{projectPlanDoc:t,systemTempDirs:r}=st(o);return qa(n,t)?!0:r.some(i=>Be(n,i))}a(Jn,"isPlanModeAllowedPath");function Xa(e){let{projectPlanDoc:o,systemTempDirs:n}=st(e),t=n[0]??fo.tmpdir();return`${o} or the system temp directory (${t})`}a(Xa,"formatPlanModeAllowedLocations");var Va=new Set(["-a","--append","-i","--ignore-interrupts"]);function Ya(e){let o=[];for(let n=1;n<e.argv.length;n+=1){let t=e.argv[n];Va.has(t)||t.startsWith("-")||o.push(t)}return o}a(Ya,"collectTeeTargets");function Ja(e){let o=[],n=1,t=!1;for(;n<e.argv.length;){let r=e.argv[n],i=r.toLowerCase();if(i==="-path"||i==="-literalpath"||i==="-destination"){let l=e.argv[n+1];if(l!==void 0&&!l.startsWith("-")){o.push(l),n+=2;continue}}!r.startsWith("-")&&!t&&(o.push(r),t=!0),n+=1}return o}a(Ja,"collectPowerShellWriteTargets");function Ge(e){let o=new Set,n=a(r=>{let i=r?.trim();i&&o.add(i)},"pushTarget");for(let r of Xo(e))n(r);let t=uo(e);if(t.unparseable)return Array.from(o);for(let r of t.statements)for(let i of r.stages){for(let c of i.redirections)c.input||n(c.target);let l=i.argv[0]?.toLowerCase();if(l){if(l==="tee")for(let c of Ya(i))n(c);else if(_s.has(l))for(let c of Ja(i))n(c)}}return Array.from(o)}a(Ge,"collectBashWriteTargets");function Ns(e,o){if(!Qn(e))return{dangerous:!1};let n=new Set([...Ge(e),...Ka(e)]);for(let t of n)if(!tt(t,o))return{dangerous:!0,reason:`Command may modify file outside project: ${t}`};return{dangerous:!1}}a(Ns,"getBashOutsideProjectWriteRisk");function Os(e,o,n){let t=Xa(n);if(Xr(e))return null;if(lo.has(e)){let r=typeof o.path=="string"?o.path:"";return r?Jn(r,n)?null:`[Blocked] Plan mode only allows file modifications in ${t}. Requested path: ${r}`:`[Blocked] Tool '${e}' is not allowed in plan mode unless it targets ${t}.`}if(e==="bash"){let r=o.command??"";if(!Qn(r))return null;let i=Ge(r);if(i.length===0)return`[Blocked] Plan mode only allows bash write operations when every target is either ${t}. Could not determine a safe target from: ${r.slice(0,80)}${r.length>80?"...":""}`;let l=i.find(c=>!Jn(c,n));return l?`[Blocked] Plan mode only allows bash write operations in ${t}. Blocked target: ${l}`:null}return`[Blocked] Tool '${e}' has side effects and is not permitted in plan mode. Switch to accept-edits or auto mode to use it, or work within ${t}.`}a(Os,"getPlanModeBlockReason");import me from"node:path";import Za from"node:os";function qe(e,o){try{let n=me.resolve(e),t=me.resolve(o);return n===t?!0:n.startsWith(t+me.sep)}catch{return!1}}a(qe,"isPathUnder");function Qa(){try{return Oe()}catch{return}}a(Qa,"safeGetAgentConfigHome");function Ds(e,o){let n=Qa();if(n&&qe(e,n))return"user-kodax";let t=me.join(me.resolve(o),".kodax");if(qe(e,t))return"project-kodax"}a(Ds,"resolveProtectedZone");function el(){let e=new Set;try{e.add(Za.tmpdir())}catch{}for(let o of["TEMP","TMP","TMPDIR"]){let n=process.env[o];n&&n.length>0&&e.add(n)}return Array.from(e)}a(el,"getSystemTempDirs");var ol=new Set(["bash"]),nl={toolNames:ol,collect(e,o){let n=typeof e.input.command=="string"?e.input.command:"";if(!n||!o)return[];let t=[],r=new Set,i=new Set,l=el(),c=me.resolve(o);for(let d of Xo(n)){let u;try{u=me.resolve(o,d)}catch{continue}let f=Ds(u,o);if(f){r.has(u)||(r.add(u),t.push({kind:"protected_path",path:d,zone:f}));continue}if(mo(d,o)){let m=l.some(v=>qe(u,v)),y=qe(u,c);!m&&!y&&!i.has(u)&&(i.add(u),t.push({kind:"outside_project",path:d}))}}for(let d of Ge(n)){let u;try{u=me.resolve(o,d)}catch{continue}Ds(u,o)||qe(u,c)||l.some(y=>qe(u,y))||t.push({kind:"shell_redirect_outside",target:d})}return t}};var Yo=H("config.json");function Hs(){return Fs.join(process.cwd(),".kodax","config.local.json")}a(Hs,"getProjectConfigFile");function gm(e=process.env){let n=po(Yo).autoMode??{},t=e.KODAX_AUTO_MODE_ENGINE?.trim(),r=t==="llm"||t==="rules"?t:void 0,i=n.engine==="llm"||n.engine==="rules"?n.engine:void 0,l=r??i??"llm",c=js(n.classifierModel),d=js(e.KODAX_AUTO_MODE_CLASSIFIER_MODEL),u=e.KODAX_AUTO_MODE_TIMEOUT_MS?.trim(),f=u!==void 0?Number(u):NaN,m=Number.isFinite(f)&&f>0?Math.floor(f):void 0,y=typeof n.timeoutMs=="number"&&n.timeoutMs>0?Math.floor(n.timeoutMs):void 0,v=Us(e.KODAX_AUTO_SPECULATIVE_WINDOW_MS?.trim()),k=typeof n.speculativeWindowMs=="number"?Us(String(n.speculativeWindowMs)):void 0;return{engine:l,classifierModel:c,classifierModelEnv:d,timeoutMs:m??y,speculativeWindowMs:v??k}}a(gm,"loadAutoModeSettings");function Us(e){if(e===void 0||e==="")return;let o=Number(e);if(Number.isFinite(o))return o<0?0:Math.floor(o)}a(Us,"parseSpeculativeWindow");function js(e){if(typeof e!="string")return;let o=e.trim();return o.length===0?void 0:o}a(js,"nonEmptyString");function po(e){try{if(Vo.existsSync(e))return JSON.parse(Vo.readFileSync(e,"utf-8"))}catch{}return{}}a(po,"readJsonFile");function Bs(e,o){Vo.mkdirSync(Fs.dirname(e),{recursive:!0}),Vo.writeFileSync(e,JSON.stringify(o,null,2))}a(Bs,"writeJsonFile");function it(e){let o=po(Yo);Bs(Yo,{...o,permissionMode:e})}a(it,"savePermissionModeUser");function wm(){let e=po(Yo),o=po(Hs()),n=e.alwaysAllowTools??[],t=o.alwaysAllowTools??[];return[...new Set([...n,...t])]}a(wm,"loadAlwaysAllowTools");function hm(e,o,n=!1){let t=nt(e,o,n);if(!t)return;let r=Hs(),i=po(r),l=i.alwaysAllowTools??[];l.includes(t)||Bs(r,{...i,alwaysAllowTools:[...l,t]})}a(hm,"saveAlwaysAllowToolPattern");var at=["ama","amaw","sa"];function Gs(e){let o=at.indexOf(e);return at[(o+1)%at.length]??"ama"}a(Gs,"nextAgentMode");var pe=class{static{a(this,"CommandRegistry")}commands=new Map;aliases=new Map;register(o){let n=o.name.toLowerCase();if(this.commands.has(n))throw new Error(`Command "${o.name}" is already registered`);if(this.aliases.has(n)){let r=this.aliases.get(n);throw new Error(`Command "${o.name}" conflicts with existing alias for "${r}"`)}let t=new Set;for(let r of o.aliases??[]){let i=r.toLowerCase();if(i!==n){if(t.has(i))throw new Error(`Alias "${r}" is duplicated within command "${o.name}"`);if(this.commands.has(i))throw new Error(`Alias "${r}" conflicts with existing command "${i}"`);if(this.aliases.has(i)){let l=this.aliases.get(i);throw new Error(`Alias "${r}" is already registered for "${l}"`)}t.add(i)}}if(this.commands.set(n,{...o,source:o.source??"builtin"}),o.aliases)for(let r of o.aliases){let i=r.toLowerCase();i!==n&&this.aliases.set(i,n)}}unregister(o){let n=o.toLowerCase(),t=this.aliases.get(n)??n;if(!this.commands.has(t))return!1;let r=this.commands.get(t);if(r?.aliases)for(let i of r.aliases)this.aliases.delete(i.toLowerCase());return this.commands.delete(t),!0}get(o){let n=o.toLowerCase(),t=this.aliases.get(n)??n;return this.commands.get(t)}has(o){let n=o.toLowerCase(),t=this.aliases.get(n)??n;return this.commands.has(t)}getAll(o){let n=new Map;for(let[t,r]of this.commands)o&&r.source!==o||n.has(t)||n.set(t,{name:r.name,aliases:r.aliases,description:r.description,source:r.source??"builtin",usage:r.usage,priority:r.priority,location:r.location,path:r.path,userInvocable:r.userInvocable,disableModelInvocation:r.disableModelInvocation,allowedTools:r.allowedTools,context:r.context,agent:r.agent,argumentHint:r.argumentHint,model:r.model});return Array.from(n.values()).sort((t,r)=>t.name.localeCompare(r.name))}getBySource(o){return this.getAll(o)}getNames(){return Array.from(this.commands.keys()).sort()}clear(){this.commands.clear(),this.aliases.clear()}get size(){return this.commands.size}get aliasCount(){return this.aliases.size}},tl=new pe;import K from"chalk";import{Buffer as Xs}from"node:buffer";import{spawn as rl}from"node:child_process";import qs from"node:process";var Ae="\x1B",sl="\x07",lt=`${Ae}\\`;function Ks(e,o){return e.SSH_CONNECTION?!1:o==="win32"||o==="darwin"||o==="linux"}a(Ks,"shouldPreferNativeClipboard");function il(e,o){let n=Xs.from(e,"utf8").toString("base64"),t=o.TERM==="xterm-kitty"?lt:sl,r=`${Ae}]52;c;${n}${t}`;return o.TMUX?`${Ae}Ptmux;${r.replaceAll(Ae,`${Ae}${Ae}`)}${lt}`:o.STY?`${Ae}P${r}${lt}`:r}a(il,"buildOscSequence");async function Jo(e,o,n){return new Promise((t,r)=>{let i=rl(e,o,{stdio:["pipe","ignore","pipe"],windowsHide:!0}),l="";i.on("error",r),i.stderr?.on("data",c=>{l+=c.toString()}),i.on("close",c=>{if(c===0){t(!0);return}r(new Error(l.trim()||`${e} exited with code ${c??"unknown"}`))}),i.stdin?.write(n),i.stdin?.end()})}a(Jo,"execClipboardCommand");function al(e){let o="$stream = [Console]::OpenStandardInput(); $buffer = New-Object byte[] 8192; $memory = New-Object System.IO.MemoryStream; while (($read = $stream.Read($buffer, 0, $buffer.Length)) -gt 0) { $memory.Write($buffer, 0, $read) }; $text = [System.Text.Encoding]::UTF8.GetString($memory.ToArray()); Set-Clipboard -Value $text",n=Xs.from(e,"utf8");return[["powershell",["-NoProfile","-NonInteractive","-Command",o],n],["pwsh",["-NoProfile","-NonInteractive","-Command",o],n],["cmd",["/c","chcp 65001 >nul & clip"],n]]}a(al,"buildWindowsClipboardCandidates");async function zs(e,o,n){if(o.SSH_CONNECTION)return!1;switch(n){case"win32":{let t=al(e);for(let[r,i,l]of t)try{if(await Jo(r,i,l))return!0}catch{}return!1}case"darwin":return Jo("pbcopy",[],e);case"linux":{let t=[["wl-copy",[]],["xclip",["-selection","clipboard"]],["xsel",["--clipboard","--input"]]];for(let[r,i]of t)try{if(await Jo(r,i,e))return!0}catch{}return!1}default:return!1}}a(zs,"tryNativeClipboard");async function ll(e,o){if(!o.TMUX)return!1;let n=o.LC_TERMINAL==="iTerm2"?["load-buffer","-"]:["load-buffer","-w","-"];try{return await Jo("tmux",n,e)}catch{return!1}}a(ll,"tryTmuxClipboard");async function Vs(e,o={}){let n=o.env??qs.env,t=o.platform??qs.platform,r=e.trimEnd(),i=il(r,n);if(!r)throw new Error("Nothing to copy.");if(Ks(n,t))try{if(await zs(r,n,t))return{path:"native"}}catch{}if(await ll(r,n))return{path:"tmux-buffer"};if(o.terminalWrite?.(i))return{path:"osc52"};if(!Ks(n,t))try{if(await zs(r,n,t))return{path:"native"}}catch{}throw new Error("Unable to access any clipboard path.")}a(Vs,"copyTextToClipboard");var ct;(function(e){e.Idle="idle",e.Responding="responding",e.WaitingForConfirmation="waiting_for_confirmation"})(ct||(ct={}));var G;(function(e){e.Scheduled="scheduled",e.Validating="validating",e.AwaitingApproval="awaiting_approval",e.Executing="executing",e.Success="success",e.Error="error",e.Cancelled="cancelled"})(G||(G={}));var Tm={[G.Scheduled]:"\u25CB",[G.Validating]:"\u25CC",[G.AwaitingApproval]:"?",[G.Executing]:"\u25CB",[G.Success]:"\u2713",[G.Error]:"\u2717",[G.Cancelled]:"-"},Ys;(function(e){e[e.Low=-100]="Low",e[e.Normal=0]="Normal",e[e.High=100]="High",e[e.Critical=200]="Critical"})(Ys||(Ys={}));var Im={streamingState:ct.Idle,currentResponse:"",history:[],pendingToolCalls:[],sessionId:"",provider:"",model:"",isLoading:!1};var cl="[redacted]",Js="[truncated]";function se(e,o=2e3){return e.length>o?`${e.slice(0,o-3)}...`:e}a(se,"truncateToolReplayText");function dl(e){let o=e.toLowerCase().replace(/[\s_-]/g,"");return o.includes("token")||o.includes("password")||o.includes("secret")||o.includes("apikey")||o.includes("accesstoken")||o==="authorization"||o==="cookie"||o==="setcookie"}a(dl,"isSensitiveToolInputKey");function Zs(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}a(Zs,"isRecord");function dt(e,o=0,n=new WeakSet){if(e===null||typeof e=="number"||typeof e=="boolean")return e;if(typeof e=="string")return se(e);if(o>=6)return Js;if(typeof e=="object"&&e!==null){if(n.has(e))return Js;if(n.add(e),Array.isArray(e))return e.slice(0,50).map(r=>dt(r,o+1,n));if(!Zs(e))return se(String(e));let t={};for(let[r,i]of Object.entries(e).slice(0,50))t[r]=dl(r)?cl:dt(i,o+1,n);return t}return se(String(e))}a(dt,"sanitizeToolJsonValue");function Qs(e){if(!e)return;let o=dt(e);return Zs(o)?o:void 0}a(Qs,"sanitizeToolInput");function ei(e){if(e!==void 0){if(typeof e=="string")return se(e);try{return se(JSON.stringify(e))}catch{return se(String(e))}}}a(ei,"stringifyToolReplayValue");function Nm(e){return e.type==="tool_summary"||e.type==="task_completed"?{type:"event",text:e.text,icon:"tool"}:e.type==="tool_group"?{type:"tool_group",tools:e.tools.map(yl)}:e}a(Nm,"seedToHistoryItem");var ul="[Thinking]",fl="[/Thinking]",ml="Untitled Session",oi=50,pl=60,ti="...",ri=["[Managed Task]","[Managed Task Protocol Retry]","Assigned native agent identity:","Tool policy:","Blocked tools:","Allowed shell patterns:","Dependency handoff artifacts:","Dependency summary preview:","Preferred agent:","Read structured bundle first:","Read human summary next:"],si=[/(?:^|\n)You are the [^\n]+ role for a managed KodaX task\./,/(?:^|\n)Primary task:/,/(?:^|\n)Work intent:/,/(?:^|\n)Complexity:/,/(?:^|\n)Risk:/,/(?:^|\n)Harness:/,/(?:^|\n)Brainstorm required:/],gl=/(^|\r?\n)\[Thinking\]\r?\n([\s\S]*?)\r?\n\[\/Thinking\](?=\r?\n|$)/g,wl="Session ended before the tool completed.";function hl(e){switch(e){case"success":return G.Success;case"error":return G.Error;case"cancelled":return G.Cancelled;case"awaiting_approval":return G.AwaitingApproval;default:return e}}a(hl,"toolCallSeedToHistoryToolStatus");function yl(e){return{id:e.id,name:e.name,status:hl(e.status),...e.input!==void 0?{input:e.input}:{},...e.preview!==void 0?{preview:e.preview}:{},...e.output!==void 0?{output:e.output}:{},...e.error!==void 0?{error:e.error}:{},startTime:e.startTime??Date.now(),...e.endTime!==void 0?{endTime:e.endTime}:{}}}a(yl,"toolCallSeedToHistoryToolCall");function kl(e){let o=-1;for(let n of ri){let t=e.indexOf(n);t>=0&&(o===-1||t<o)&&(o=t)}for(let n of si){let t=n.exec(e);t&&t.index>=0&&(o===-1||t.index<o)&&(o=t.index)}return o}a(kl,"findControlPlaneCutIndex");function vl(e){return ri.some(o=>e.includes(o))||si.some(o=>o.test(e))}a(vl,"hasControlPlaneSignal");function ii(e){let o=[];for(let n of e)n&&typeof n=="object"&&"type"in n&&n.type==="text"&&"text"in n&&o.push(String(n.text));return o}a(ii,"collectTextBlocks");function Qo(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}a(Qo,"isRecord");function $l(e){if(typeof e=="string")return se(e);if(e===void 0)return"";try{return ei(e)??""}catch{return se(String(e))}}a($l,"toolResultContentToString");function Sl(e){let o=$l(e.content),n=o.trimStart(),t=e.is_error===!0||n.startsWith("[Tool Error]")||n.startsWith("[Error]"),r=n.startsWith("[Cancelled]")||n.startsWith("[Blocked]");return t?{status:"error",error:o}:r?{status:"cancelled",error:o}:{status:"success",output:o}}a(Sl,"inferToolResultSeed");function bl(e){let o=new Map;if(!e||e.role!=="user"||!Array.isArray(e.content))return o;for(let n of e.content)!Qo(n)||n.type!=="tool_result"||typeof n.tool_use_id!="string"||o.set(n.tool_use_id,Sl(n));return o}a(bl,"collectToolResultSeeds");function xl(e,o){if(e.type!=="tool_use"||typeof e.id!="string"||typeof e.name!="string")return;let n=o.get(e.id)??{status:"cancelled",error:wl};return{id:e.id,name:e.name,status:n.status,...e.input!==void 0?{input:Qs(Qo(e.input)?e.input:{})??{}}:{},...n.output!==void 0?{output:n.output}:{},...n.error!==void 0?{error:n.error}:{}}}a(xl,"buildToolCallSeed");function Al(e){return typeof e=="string"?e:Array.isArray(e)?ii(e).join(`
|
|
3
3
|
`):""}a(Al,"extractAssistantTextOnly");function wo(e,o,n){n.trim().length!==0&&e.push({type:o,text:n})}a(wo,"pushSeed");function ni(e){return e.replace(/^\n+/,"").replace(/\n+$/,"")}a(ni,"stripLegacyTagBoundaryNewlines");function Rl(e){let o=e.name,n=e.input;if(!n)return`\u26A1 ${o}`;let t=o==="bash"?go(String(n.command??"")):o==="read"||o==="write"||o==="edit"?go(String(n.file_path??n.path??"")):o==="grep"||o==="glob"?go(String(n.pattern??"")):o==="web_search"||o==="web_fetch"?go(String(n.query??n.url??"")):void 0;return t?`\u26A1 ${o}(${t})`:`\u26A1 ${o}`}a(Rl,"formatToolUseSummary");function go(e,o=60){let n=e.replace(/\s+/g," ").trim();return n.length>o?`${n.slice(0,o)}...`:n}a(go,"truncateToolHint");function El(e){if(!e.includes(ul)||!e.includes(fl))return e.trim().length>0?[{type:"assistant",text:e}]:[];let o=[],n=0;for(let t of e.matchAll(gl)){let r=t.index??-1,i=t[1]??"",l=t[2]??"";if(r<0)continue;let c=r+i.length;wo(o,"assistant",ni(e.slice(n,c))),wo(o,"thinking",l),n=r+t[0].length}return wo(o,"assistant",ni(e.slice(n))),o.length===0?e.trim().length>0?[{type:"assistant",text:e}]:[]:o}a(El,"parseLegacyAssistantContent");function ai(e,o){if(typeof e=="string")return El(e);if(!Array.isArray(e))return[];let n=[],t=[],r=[],i=a(()=>{t.length!==0&&(wo(n,"assistant",t.join(`
|
|
4
4
|
`)),t.length=0)},"flushAssistantBuffer"),l=a(()=>{r.length!==0&&(n.push({type:"tool_group",tools:[...r]}),r.length=0)},"flushToolBuffer");for(let c of e)if(!(!Qo(c)||typeof c.type!="string"))switch(c.type){case"text":l(),"text"in c&&t.push(String(c.text));break;case"thinking":i(),l(),"thinking"in c&&wo(n,"thinking",String(c.thinking));break;case"tool_use":if(i(),o){let d=xl(c,o);d&&r.push(d)}else if(typeof c.name=="string"){let d=Rl({name:c.name,...Qo(c.input)?{input:c.input}:{}});d&&n.push({type:"tool_summary",text:d})}break;case"tool_result":case"redacted_thinking":break;default:break}return l(),i(),n}a(ai,"extractAssistantHistorySeeds");var Cl=["You are the Scout role","You are the Generator role","You are the Planner role","You are the Evaluator role"],Tl=/\r?\n?\`\`\`kodax[\w-]*[\s\S]*?\`\`\`\s*/g;function Il(e){return Cl.some(o=>e.includes(o))}a(Il,"isManagedWorkerPrompt");function li(e){return e.replace(Tl,"").trim()}a(li,"stripManagedProtocolBlocks");function Pl(e){switch(e.role){case"assistant":return ai(e.content).flatMap(n=>{if(n.type!=="assistant")return[n];let t=li(n.text);return t.length>0&&t.trim()!=="..."?[{...n,text:t}]:[]});case"user":{if(e._source==="sidecar-verifier"){let n=Zo(e.content).trim();return n?[{type:"sidecar",text:n,verdict:"revise"}]:[]}if(e._source==="task-completed"){let n=Zo(e.content).trim();return n?[{type:"task_completed",text:n}]:[]}if(e._synthetic)return[];let o=Zo(e.content);return o.trim().length===0||Il(o)?[]:[{type:"user",text:o}]}case"system":return[];default:return[]}}a(Pl,"extractHistorySeedsFromMessage");function Om(e){let o=[];for(let n=0;n<e.length;n+=1){let t=e[n];if(t){if(t.role==="assistant"){let r=bl(e[n+1]),i=ai(t.content,r);o.push(...i.map(l=>l.type==="assistant"?{...l,text:li(l.text)}:l).filter(l=>l.type!=="assistant"||l.text.length>0&&l.text.trim()!=="..."));continue}o.push(...Pl(t))}}return o}a(Om,"extractHistorySeedsFromMessages");function Zo(e){return typeof e=="string"?e:Array.isArray(e)?ii(e).join(`
|
|
5
5
|
`):""}a(Zo,"extractTextContent");function _l(e){let o=e.replace(/\s+/g," ").trim();return o?o.length>oi?`${o.slice(0,oi)}${ti}`:o:ml}a(_l,"formatSessionTitle");function Ml(e){if(e.role!=="user")return!1;let o=e.content;return!Array.isArray(o)||o.length===0?!1:o.every(n=>!!n&&typeof n=="object"&&"type"in n&&n.type==="tool_result")}a(Ml,"isPureToolResultUserMessage");function ut(e){for(let o=e.length-1;o>=0;o--){let n=e[o];if(n){if(n.role==="assistant"){let t=Al(n.content);return t&&t.trim()!=="..."?t:""}if(!Ml(n))return""}}return""}a(ut,"extractLastAssistantText");function Dm(e,o,n,t){let r=[ut(e),o.trim(),n?.trim()??"",t?.trim()??""];for(let i of r){let l=ci(i);if(l)return l}return""}a(Dm,"resolveCompletedAssistantText");function ci(e){let o=e.trim();if(!o||o==="...")return"";let n=kl(o);return n===0?"":(n>0?o.slice(0,n):o).trim()}a(ci,"sanitizeUserFacingAssistantText");function Um(e){let o=e.trim();return o.length>0&&ci(o).length===0&&vl(o)}a(Um,"isControlPlaneOnlyAssistantText");function jm(e){let o=e.find(t=>t.role==="user"),n=o?Zo(o.content):"";return _l(n)}a(jm,"extractTitle");function Fm(e,o=pl){let n=e.replace(/\n/g," "),t=n.length>o?ti:"";return n.slice(0,o)+t}a(Fm,"formatMessagePreview");var ft={name:"copy",description:"Copy last assistant message to clipboard",usage:"/copy",handler:a(async(e,o)=>{let n=ut(o.messages);if(!n){console.log(K.yellow(`
|
|
@@ -621,4 +621,4 @@ Available Skills:
|
|
|
621
621
|
[Skill "${t}" is not user-invocable]`)),!1;console.log(s.cyan(`
|
|
622
622
|
[Invoking skill: ${t}]`)),i.argumentHint&&console.log(s.dim(`Arguments: ${r||"(none)"}`)),console.log();let l=await n.loadFull(t),c={workingDirectory:process.cwd(),projectRoot:o.gitRoot??void 0,sessionId:o.sessionId,environment:{},executeDynamicContext:o.skillDynamicContext?.execute,disableDynamicContext:o.skillDynamicContext?.disable},d=await Rr(l,r,c);return console.log(s.green(`Skill activated: ${t}`)),console.log(s.dim("The skill context has been prepared for the AI.")),console.log(),{invocation:{prompt:d.content,source:"skill",displayName:t,path:l.skillFilePath,disableModelInvocation:d.disableModelInvocation,userInvocable:l.userInvocable,allowedTools:l.allowedTools,context:l.context,agent:l.agent,argumentHint:l.argumentHint,model:l.model,hooks:l.hooks,skillInvocation:{name:t,path:l.skillFilePath,description:l.description,arguments:r||void 0,allowedTools:l.allowedTools,context:l.context,agent:l.agent,argumentHint:l.argumentHint,model:l.model,hookEvents:l.hooks?Object.entries(l.hooks).filter(([,u])=>Array.isArray(u)&&u.length>0).map(([u])=>u):void 0,expandedContent:d.content}}}}catch(i){return console.log(s.red(`
|
|
623
623
|
[Error invoking skill: ${i instanceof Error?i.message:String(i)}]`)),!1}}a(nr,"executeSkillCommand");var Rn=class{static{a(this,"SkillCompleter")}gitRoot;constructor(o){this.gitRoot=o}canComplete(o,n){return this.parseTrigger(o.slice(0,n))!==void 0}async getCompletions(o,n){let t=this.parseTrigger(o.slice(0,n));if(!t)return[];let r=t.partial.toLowerCase();return(await this.getSkills()).filter(l=>{let c=l.name.toLowerCase();return c.includes(r)||this.fuzzyIncludes(r,c)}).map(l=>({text:`${t.invocationPrefix}${l.name}`,display:l.name,description:this.truncateDescription(l.description),type:"skill"})).sort((l,c)=>{let d=l.display.toLowerCase().startsWith(r),u=c.display.toLowerCase().startsWith(r);return d&&!u?-1:!d&&u?1:l.display.length-c.display.length})}setGitRoot(o){this.gitRoot!==o&&(this.gitRoot=o)}parseTrigger(o){let n=o.match(/(^|\s)\/skill:([^\s]*)$/);if(n)return{partial:n[2]??"",invocationPrefix:"/skill:"};let t=o.match(/(^|\s)\/([^\s]*)$/);if(t)return{partial:t[2]??"",invocationPrefix:"/"}}async getSkills(){try{let o=$e(this.gitRoot);return o.size===0&&await De(this.gitRoot),o.listUserInvocable()}catch{return[]}}fuzzyIncludes(o,n){let t=0;for(let r=0;r<n.length&&t<o.length;r+=1)n[r]===o[t]&&(t+=1);return t===o.length}truncateDescription(o,n=50){return o.length<=n?o:o.slice(0,n-3)+"..."}};import{exec as Mu}from"node:child_process";import*as oo from"node:path";import{promisify as Lu}from"node:util";var ua=Lu(Mu);function Wu(e){let o=e.slice(3);if(!o)return;let n=o.indexOf(" -> ");return(n===-1?o:o.slice(n+4)).replace(/^"(.*)"$/,"$1").trim()||void 0}a(Wu,"pathFromPorcelainLine");async function fa(e,o=10){try{let[{stdout:n},{stdout:t}]=await Promise.all([ua("git rev-parse --show-toplevel",{cwd:e}),ua("git status --porcelain=v1 -uall",{cwd:e})]),r=n.trim(),i=[],l=new Set;for(let c of t.split(`
|
|
624
|
-
`)){if(!c.trim())continue;let d=Wu(c);if(!d)continue;let u=oo.resolve(r,d),f=oo.relative(e,u).split(oo.sep).join("/");if(!(!f||f.startsWith("..")||l.has(f))&&(l.add(f),i.push(f),i.length>=o))break}return i}catch{return[]}}a(fa,"getRecentWorkingSetFiles");function no(e){let o=e.lastIndexOf("/");if(o===-1)return-1;for(;o>0&&!/\s/.test(e[o-1]??"");)if(o=e.lastIndexOf("/",o-1),o===-1)return-1;return o}a(no,"findCommandSlashIndex");var ir=class{static{a(this,"FileCompleter")}cwdSource;cache=new Map;cacheTimeout=5e3;recentCache=new Map;recentFilesProvider;constructor(o,n=fa){this.cwdSource=o,this.recentFilesProvider=n}canComplete(o,n){let t=o.slice(0,n),r=t.lastIndexOf("@");return!(r===-1||r>0&&!/\s/.test(t[r-1]??"")||t.slice(r+1).includes(" "))}async getCompletions(o,n){let t=o.slice(0,n),r=t.lastIndexOf("@");if(r===-1)return[];let i=t.slice(r+1),l=[],c=this.resolveCwd(),d=i.lastIndexOf("/"),u=d===-1?c:To.join(c,i.slice(0,d)),f=d===-1?i:i.slice(d+1);try{let y=(await this.readdir(u)).filter(v=>v.toLowerCase().startsWith(f.toLowerCase()));for(let v of y){let k=To.join(u,v),$=await this.isDirectory(k),g=d===-1?v:i.slice(0,d+1)+v;l.push({text:"@"+g+($?"/":""),display:v+($?"/":""),description:$?"directory":"file",type:"file"})}}catch{}if(d===-1){let m=await this.getRecentFiles(c),y=new Set(l.map($=>$.text)),v=f.toLowerCase(),k=[];for(let $ of m){if(f&&!To.basename($).toLowerCase().startsWith(v))continue;let g="@"+$;y.has(g)||(y.add(g),k.push({text:g,display:$,description:"recent",type:"file"}))}l.unshift(...k)}return l}async getRecentFiles(o){let n=Date.now(),t=this.recentCache.get(o);if(t&&t.expiresAt>n)return t.files;let r=await this.recentFilesProvider(o);return this.recentCache.set(o,{files:r,expiresAt:Date.now()+this.cacheTimeout}),r}resolveCwd(){return typeof this.cwdSource=="function"?this.cwdSource():this.cwdSource??process.cwd()}async readdir(o){let n=Date.now(),t=this.cache.get(o);return t&&t.expiresAt>n?t.entries:(t&&this.cache.delete(o),new Promise(r=>{En.readdir(o,(i,l)=>{i?r([]):(this.cache.set(o,{entries:l,expiresAt:Date.now()+this.cacheTimeout}),r(l))})}))}async isDirectory(o){return new Promise(n=>{En.stat(o,(t,r)=>{n(!t&&r.isDirectory())})})}},ar=class{static{a(this,"CommandCompleter")}commands;constructor(){this.commands=new Map,this.loadCommands()}loadCommands(){for(let n of Co().getAll())n.userInvocable!==!1&&this.commands.set(n.name,{description:n.description,aliases:n.aliases??[]});let o=re();for(let n of o?.listCommands()??[])n.metadata?.userInvocable!==!1&&this.commands.set(n.name,{description:n.description,aliases:n.aliases??[]})}canComplete(o,n){let t=o.slice(0,n),r=no(t);return r===-1?!1:!t.slice(r).includes(" ")}async getCompletions(o,n){let t=o.slice(0,n),r=no(t);if(r===-1)return[];this.commands.clear(),this.loadCommands();let i=t.slice(r+1).toLowerCase(),l=[];for(let[c,d]of this.commands){this.fuzzyMatch(i,c)&&l.push({text:"/"+c,display:"/"+c,description:d.description,type:"command"});for(let u of d.aliases)u!==c&&this.fuzzyMatch(i,u)&&l.push({text:"/"+u,display:"/"+u,description:`Alias for /${c}: ${d.description}`,type:"command"})}return l}fuzzyMatch(o,n){if(!o)return!0;let t=o.toLowerCase(),r=n.toLowerCase(),i=0;for(let l=0;l<r.length&&i<t.length;l++)r[l]===t[i]&&i++;return i===t.length}};function Fh(e){let o=new ir(e),n=new Rn,t=new ar;return async r=>{let i=r.includes("@"),l=r.includes("/");if(!i&&!l)return[[],r];let c=[];if(l){let u=await Nu(r,r.length);c.push(...u)}if(l&&n.canComplete(r,r.length)){let u=await n.getCompletions(r,r.length);c.push(...u)}if(l&&t.canComplete(r,r.length)){let u=await t.getCompletions(r,r.length);c.push(...u)}if(i&&o.canComplete(r,r.length)){let u=await o.getCompletions(r,r.length);c.push(...u)}return[c.map(u=>Ou(r,u)),r]}}a(Fh,"createCompleter");async function Nu(e,o){let{ArgumentCompleter:n}=await import("./argument-completer-N6RT5KYT.js"),t=new n;return t.canComplete(e,o)?t.getCompletions(e,o):[]}a(Nu,"getArgumentCompletions");function Ou(e,o){if(o.type!=="argument")return o.text;let n=no(e);if(n!==-1&&!/\s/.test(e.slice(n)))return`${e} ${o.text}`;let r=e.match(/\S+$/)?.[0]??"";return`${r?e.slice(0,e.length-r.length):e}${o.text}`}a(Ou,"formatReadlineCompletion");import{existsSync as Tn,readdirSync as ha,readFileSync as ya}from"node:fs";import{join as In}from"node:path";var Du=[{name:"plan",description:"Read-only planning mode - blocks all modifications",type:"enum"},{name:"accept-edits",description:"File edits auto-approved, bash requires confirmation",type:"enum"},{name:"auto",description:"Use auto-mode classifier for tool permissions",type:"enum"}],Cn=[{name:"on",description:"Map to reasoning auto",type:"enum"},{name:"off",description:"Disable reasoning",type:"enum"},{name:"auto",description:"Use semantic routing with adaptive depth",type:"enum"},{name:"quick",description:"Low-depth reasoning mode",type:"enum"},{name:"balanced",description:"Medium-depth reasoning mode",type:"enum"},{name:"deep",description:"High-depth reasoning mode",type:"enum"}],ma=Cn.slice(2).concat([{name:"off",description:"Disable reasoning",type:"enum"}]);function Uu(e){if(e&&e.includes("/")){let o=e.indexOf("/"),n=e.slice(0,o),t=e.slice(o+1);if(We(n))try{return He(n).filter(i=>!t||i.toLowerCase().includes(t.toLowerCase())).map(i=>({name:`${n}/${i}`,description:i,type:"enum"}))}catch{}return[]}return Ne().map(o=>({name:o,description:`Switch to ${o} provider`,type:"enum"}))}a(Uu,"getModelArgs");var lr=[{name:"workspace",description:"Inspect current workspace/runtime truth in more detail",type:"enum"},{name:"runtime",description:"Alias for workspace runtime inspection",type:"enum"},{name:"worktree",description:"Alias for workspace runtime inspection",type:"enum"}],cr=[{name:"all",description:"Delete ALL sessions",type:"enum"}],ju=[{name:"status",description:"Show MCP server status",type:"enum"},{name:"refresh",description:"Refresh MCP server catalogs",type:"enum"}],Fu=[{name:"status",description:"Show child-task fallback order",type:"enum"},{name:"off",description:"Disable child-task fallback providers",type:"enum"}],Hu=[{name:"llm",description:"Use LLM classifier for auto mode",type:"enum"},{name:"rules",description:"Use rules-only auto mode",type:"enum"}],pa=[{name:"ama",description:"Use AMA agent mode",type:"enum"},{name:"amaw",description:"Use AMA workflow agent mode",type:"enum"},{name:"ama-workflow",description:"Alias for amaw",type:"enum"},{name:"sa",description:"Use single-agent mode",type:"enum"},{name:"toggle",description:"Cycle to the next agent mode",type:"enum"}],ga=[{name:"on",description:"Enable logging",type:"enum"},{name:"off",description:"Disable logging",type:"enum"}],Bu=[{name:"list",description:"List project memory files",type:"enum"},{name:"pending",description:"List pending memory proposals",type:"enum"},{name:"show",description:"Preview a memory proposal",type:"enum"},{name:"approve",description:"Approve a memory proposal",type:"enum"},{name:"reject",description:"Reject a memory proposal",type:"enum"},{name:"curate",description:"Report memory governance findings",type:"enum"},{name:"rebuild",description:"Rebuild MEMORY.md index",type:"enum"},{name:"open",description:"Print the memory entrypoint path",type:"enum"},{name:"help",description:"Show memory help",type:"enum"}],Gu=[{name:"status",description:"Show current persistent goal",type:"enum"},{name:"pause",description:"Pause the active goal",type:"enum"},{name:"resume",description:"Resume a paused goal",type:"enum"},{name:"clear",description:"Clear the current goal",type:"enum"},{name:"help",description:"Show goal help",type:"enum"},{name:"--tokens",description:"Set an optional goal token budget",type:"enum"}],qu=[{name:"show",description:"Show a captured paste by id",type:"enum"},{name:"list",description:"List captured pastes",type:"enum"}],Ku=[{name:"--lean",description:"Add a minimal-diff/YAGNI review pass",type:"enum"},{name:"--workflow",description:"Review through a dynamic workflow",type:"enum"},{name:"base",description:"Review changes against the detected base branch",type:"enum"},{name:"sha",description:"Review a specific commit",type:"enum"},{name:"help",description:"Show review help",type:"enum"}],zu=[{name:"init",description:"Create AGENTS.md in the target project if absent",type:"enum"},{name:"lean",description:"Initialize or LLM-review AGENTS.md for Lean Mode guidance",type:"enum"},{name:"help",description:"Show agents help",type:"enum"}],Xu=[{name:"status",description:"Inspect the current repo-intelligence runtime state",type:"enum"},{name:"mode",description:"Switch repo-intelligence runtime mode",type:"enum"},{name:"trace",description:"Toggle repo-intelligence trace output",type:"enum"}],Vu=[{name:"auto",description:"Let KodaX pick the best repo-intelligence engine",type:"enum"},{name:"full",description:"Prefer the full repo-intelligence engine",type:"enum"},{name:"light",description:"Use the light repo-intelligence engine",type:"enum"},{name:"off",description:"Disable repo-intelligence injection",type:"enum"}],Yu=[{name:"on",description:"Enable repo-intelligence trace output",type:"enum"},{name:"off",description:"Disable repo-intelligence trace output",type:"enum"},{name:"toggle",description:"Toggle repo-intelligence trace output",type:"enum"}],Ju=[{name:"status",description:"Deprecated alias for /repo-intel status",type:"enum"}],Zu=[{name:"list",description:"List built-in and saved workflows",type:"enum"},{name:"create",description:"Generate and run a workflow from a request",type:"enum"},{name:"runs",description:"List active and recent workflow runs",type:"enum"},{name:"show",description:"Show latest run or a specific workflow run",type:"enum"},{name:"pause",description:"Pause future child launches for a run",type:"enum"},{name:"resume",description:"Resume a paused run",type:"enum"},{name:"stop",description:"Stop an active workflow run",type:"enum"},{name:"delete",description:"Delete one persisted workflow run or generated saved capsule",type:"enum"},{name:"prune",description:"Preview or delete old terminal workflow runs",type:"enum"},{name:"rerun",description:"Rerun a run id or saved workflow name",type:"enum"},{name:"save",description:"Save a generated run as a workflow capsule",type:"enum"},{name:"rename",description:"Rename a run display name or saved workflow capsule",type:"enum"},{name:"revise",description:"Generate a revised workflow capsule",type:"enum"},{name:"help",description:"Show workflow help",type:"enum"}],Qu=new Set(["show","pause","resume","stop","delete","rerun","save","rename","revise"]),ef=new Set(["show","delete","rerun","save","rename","revise"]),of=[{name:"--all",description:"Show all persisted workflow runs",type:"enum"},{name:"--limit",description:"Show at most N persisted workflow runs",type:"enum"}],nf=[{name:"--dry-run",description:"Preview cleanup without deleting runs",type:"enum"},{name:"--keep",description:"Keep the newest N terminal runs",type:"enum"},{name:"--older-than",description:"Delete terminal runs older than Nd or Nh",type:"enum"}],tf=[{name:"--force",description:"Delete stale non-terminal run records",type:"enum"},{name:"--run",description:"Treat the target as a workflow run record",type:"enum"},{name:"--saved",description:"Treat the target as a generated saved workflow capsule",type:"enum"}],rf=[".workflow.json",".ts",".mjs",".js"];function sf(e,o){switch(e){case"pause":return o==="running";case"resume":return o==="paused";case"stop":return o==="running"||o==="paused";case"delete":return o!=="running"&&o!=="paused";default:return!0}}a(sf,"workflowRunMatchesSubcommand");function Pn(e){return/^[a-zA-Z0-9._-]{1,120}$/.test(e)&&!e.startsWith(".")&&!e.includes("..")}a(Pn,"isWorkflowRunEntryName");function af(e,o){let n=In(e,"workflow-metadata.json");if(Tn(n))try{let r=JSON.parse(ya(n,"utf8"));if(typeof r=="object"&&r!==null){let i=r.displayName;if(typeof i=="string"&&Pn(i.trim()))return i.trim()}}catch{}let t=o.displayName;return typeof t=="string"&&Pn(t.trim())?t.trim():void 0}a(af,"readWorkflowRunDisplayName");function lf(){let e=Ee(process.cwd()).key,o=H("workflow-runs",e);if(!Tn(o))return[];let n=[];for(let t of ha(o)){if(!Pn(t))continue;let r=In(o,t,"run.json");if(Tn(r))try{let i=JSON.parse(ya(r,"utf8")),l=typeof i.workflow=="string"?i.workflow:"?",c=typeof i.status=="string"?i.status:"?",d=typeof i.endedAt=="number"?i.endedAt:0;n.push({arg:{name:t,description:`${l} - ${c}`,type:"string"},endedAt:d});let u=af(In(o,t),i);u&&u!==t&&n.push({arg:{name:u,description:`${l} alias for ${t} - ${c}`,type:"string"},endedAt:d})}catch{}}return n.sort((t,r)=>r.endedAt-t.endedAt).map(t=>t.arg)}a(lf,"getPersistedWorkflowRunIdArgs");function _n(e){let o=Fe().list().filter(r=>sf(e,r.status)).map(r=>({name:r.runId,description:`${r.workflow} - ${r.status}`,type:"string"})),n=ef.has(e)?lf():[],t=new Set;return[...o,...n].filter(r=>t.has(r.name)?!1:(t.add(r.name),!0))}a(_n,"getWorkflowRunIdArgs");function cf(e){for(let o of rf)if(e.endsWith(o)){let n=e.slice(0,-o.length);return Pn(n)?n:void 0}}a(cf,"savedWorkflowNameFromFile");function Io(e={}){let o=[{path:H("workflows"),source:"personal"},{path:In(process.cwd(),".kodax","workflows"),source:"project"}],n=new Map;for(let t of o)if(Tn(t.path))try{for(let r of ha(t.path)){if(e.generatedOnly===!0&&!r.endsWith(".workflow.json"))continue;let i=cf(r);i&&n.set(i,{name:i,description:`${t.source} saved workflow`,type:"enum"})}}catch{}return[...n.values()].sort((t,r)=>t.name.localeCompare(r.name))}a(Io,"getSavedWorkflowNameArgs");function df(){let e=new Map;for(let o of _n("rerun"))e.set(o.name,{...o,description:`recent run: ${o.description}`,type:"string"});for(let o of Io()){let n=e.get(o.name);if(n){e.set(o.name,{...n,description:`${n.description}; also ${o.description}`});continue}e.set(o.name,{...o,description:o.description,type:"string"})}return[...e.values()]}a(df,"getWorkflowRerunArgs");function dr(e){let o=new Map;for(let n of _n(e))o.set(n.name,{...n,description:`workflow run: ${n.description}`,type:"string"});for(let n of Io({generatedOnly:e==="delete"})){let t=o.get(n.name);if(t){o.set(n.name,{...t,description:`${t.description}; also ${n.description}`});continue}o.set(n.name,{...n,description:n.description,type:"string"})}return[...o.values()]}a(dr,"getWorkflowRunOrSavedNameArgs");function wa(e){let o=new Set(e.slice(1).filter(n=>n.startsWith("--")));return o.has("--saved")?Io({generatedOnly:!0}):o.has("--run")?_n("delete"):dr("delete")}a(wa,"getWorkflowDeleteTargetArgs");function uf(e){let[o=""]=e,n=o.toLowerCase(),t=e.length===1&&e[0]===""?0:e.length;if(t<=1)return[...Zu,...Do().map(r=>({name:r.name,description:r.description,type:"enum"})),...Io()];if(n==="rerun"&&t<=2)return df();if(n==="rename"&&t<=2)return dr("rename");if(n==="delete"&&t<=2)return[...tf,...wa(e)];if(n==="delete"&&t<=3&&e.slice(1).some(r=>r.startsWith("--")))return wa(e);if(n==="revise"){if(t<=2)return[{name:"--replace",description:"Replace a saved workflow after confirmation",type:"enum"},...dr("revise")];if(e[1]==="--replace"&&t<=3)return Io()}return Qu.has(n)&&t<=2?_n(n):n==="runs"&&t<=2?of:n==="prune"&&t<=2?nf:[]}a(uf,"getWorkflowArgs");function ff(e){let[o=""]=e,n=o.toLowerCase(),t=e.length===1&&e[0]===""?0:e.length;return t<=1?Xu:t>2?[]:n==="mode"?Vu:n==="trace"?Yu:[]}a(ff,"getRepoIntelArgs");var mf=new Map([["mode",Du],["thinking",Cn],["think",Cn],["t",Cn],["reasoning",ma],["reason",ma],["status",lr],["info",lr],["ctx",lr],["mcp",ju],["fallback",Fu],["auto-engine",Hu],["agent-mode",pa],["am",pa],["verifier-log",ga],["stall-log",ga],["memory",Bu],["goal",Gu],["paste",qu],["review",Ku],["agents",zu],["delete",cr],["rm",cr],["del",cr]]),pf=new Set(["model","m","provider"]),gf=new Set(["repo-intel"]),wf=new Set(["repointel","ri"]),hf=new Set(["workflow"]);function ur(e,o,n=[]){let t=e.toLowerCase();return pf.has(t)?Uu(o):gf.has(t)?ff(n):wf.has(t)?n.length<=1?Ju:[]:hf.has(t)?uf(n):mf.get(t)??[]}a(ur,"getCommandArguments");var fr=class{static{a(this,"ArgumentCompleter")}canComplete(o,n){let t=o.slice(0,n),r=no(t);if(r===-1)return!1;let i=t.slice(r),l=i.split(/\s+/);if(l.length>=2&&l[0]!=="")return!0;let c=i.slice(1).toLowerCase();return ur(c).length>0}async getCompletions(o,n){let t=o.slice(0,n),r=no(t);if(r===-1)return[];let i=t.slice(r),l=i.indexOf(" "),c=(l===-1?i.slice(1):i.slice(1,l)).toLowerCase(),d=l===-1?"":i.slice(l+1),u=d?d.split(/\s+/):[""],f=u.length-1,m=(u[f]??"").toLowerCase(),y=ur(c,m,u);if(!y||y.length===0)return[];let v=new Set(u.slice(0,-1).map($=>$.toLowerCase()));return y.filter($=>!v.has($.name.toLowerCase())).filter($=>!m||$.name.includes("/")?!0:$.name.toLowerCase().includes(m)).map($=>({text:$.name,display:$.name,description:$.description,type:"argument"})).sort(($,g)=>{if(!m)return 0;let b=$.display.toLowerCase().startsWith(m),I=g.display.toLowerCase().startsWith(m);return b&&!I?-1:!b&&I?1:$.display.length-g.display.length})}};function ey(){return new fr}a(ey,"createArgumentCompleter");export{ct as a,G as b,Tm as c,Ys as d,Im as e,Bo as f,$f as g,ba as h,Sf as i,lo as j,ps as k,gs as l,co as m,Zn as n,Ua as o,Qn as p,ot as q,nt as r,mo as s,Ga as t,tt as u,Ge as v,Ns as w,Os as x,nl as y,gm as z,it as A,wm as B,hm as C,Gs as D,Vs as E,se as F,Qs as G,ei as H,Nm as I,yl as J,Pl as K,Om as L,Zo as M,ut as N,Dm as O,ci as P,Um as Q,jm as R,Fm as S,fp as T,mp as U,pp as V,hi as W,wt as X,yi as Y,Ee as Z,vp as _,ko as $,St as aa,Ie as ba,Xc as ca,Vc as da,Oi as ea,Kp as fa,zp as ga,ld as ha,Bg as ia,Gg as ja,qg as ka,dw as la,uw as ma,fw as na,mw as oa,pw as pa,Yi as qa,vw as ra,$w as sa,Zi as ta,Sw as ua,Fw as va,Qi as wa,Co as xa,Rh as ya,Eh as za,Rn as Aa,fr as Ba,ey as Ca,no as Da,ir as Ea,ar as Fa,Fh as Ga};
|
|
624
|
+
`)){if(!c.trim())continue;let d=Wu(c);if(!d)continue;let u=oo.resolve(r,d),f=oo.relative(e,u).split(oo.sep).join("/");if(!(!f||f.startsWith("..")||l.has(f))&&(l.add(f),i.push(f),i.length>=o))break}return i}catch{return[]}}a(fa,"getRecentWorkingSetFiles");function no(e){let o=e.lastIndexOf("/");if(o===-1)return-1;for(;o>0&&!/\s/.test(e[o-1]??"");)if(o=e.lastIndexOf("/",o-1),o===-1)return-1;return o}a(no,"findCommandSlashIndex");var ir=class{static{a(this,"FileCompleter")}cwdSource;cache=new Map;cacheTimeout=5e3;recentCache=new Map;recentFilesProvider;constructor(o,n=fa){this.cwdSource=o,this.recentFilesProvider=n}canComplete(o,n){let t=o.slice(0,n),r=t.lastIndexOf("@");return!(r===-1||r>0&&!/\s/.test(t[r-1]??"")||t.slice(r+1).includes(" "))}async getCompletions(o,n){let t=o.slice(0,n),r=t.lastIndexOf("@");if(r===-1)return[];let i=t.slice(r+1),l=[],c=this.resolveCwd(),d=i.lastIndexOf("/"),u=d===-1?c:To.join(c,i.slice(0,d)),f=d===-1?i:i.slice(d+1);try{let y=(await this.readdir(u)).filter(v=>v.toLowerCase().startsWith(f.toLowerCase()));for(let v of y){let k=To.join(u,v),$=await this.isDirectory(k),g=d===-1?v:i.slice(0,d+1)+v;l.push({text:"@"+g+($?"/":""),display:v+($?"/":""),description:$?"directory":"file",type:"file"})}}catch{}if(d===-1){let m=await this.getRecentFiles(c),y=new Set(l.map($=>$.text)),v=f.toLowerCase(),k=[];for(let $ of m){if(f&&!To.basename($).toLowerCase().startsWith(v))continue;let g="@"+$;y.has(g)||(y.add(g),k.push({text:g,display:$,description:"recent",type:"file"}))}l.unshift(...k)}return l}async getRecentFiles(o){let n=Date.now(),t=this.recentCache.get(o);if(t&&t.expiresAt>n)return t.files;let r=await this.recentFilesProvider(o);return this.recentCache.set(o,{files:r,expiresAt:Date.now()+this.cacheTimeout}),r}resolveCwd(){return typeof this.cwdSource=="function"?this.cwdSource():this.cwdSource??process.cwd()}async readdir(o){let n=Date.now(),t=this.cache.get(o);return t&&t.expiresAt>n?t.entries:(t&&this.cache.delete(o),new Promise(r=>{En.readdir(o,(i,l)=>{i?r([]):(this.cache.set(o,{entries:l,expiresAt:Date.now()+this.cacheTimeout}),r(l))})}))}async isDirectory(o){return new Promise(n=>{En.stat(o,(t,r)=>{n(!t&&r.isDirectory())})})}},ar=class{static{a(this,"CommandCompleter")}commands;constructor(){this.commands=new Map,this.loadCommands()}loadCommands(){for(let n of Co().getAll())n.userInvocable!==!1&&this.commands.set(n.name,{description:n.description,aliases:n.aliases??[]});let o=re();for(let n of o?.listCommands()??[])n.metadata?.userInvocable!==!1&&this.commands.set(n.name,{description:n.description,aliases:n.aliases??[]})}canComplete(o,n){let t=o.slice(0,n),r=no(t);return r===-1?!1:!t.slice(r).includes(" ")}async getCompletions(o,n){let t=o.slice(0,n),r=no(t);if(r===-1)return[];this.commands.clear(),this.loadCommands();let i=t.slice(r+1).toLowerCase(),l=[];for(let[c,d]of this.commands){this.fuzzyMatch(i,c)&&l.push({text:"/"+c,display:"/"+c,description:d.description,type:"command"});for(let u of d.aliases)u!==c&&this.fuzzyMatch(i,u)&&l.push({text:"/"+u,display:"/"+u,description:`Alias for /${c}: ${d.description}`,type:"command"})}return l}fuzzyMatch(o,n){if(!o)return!0;let t=o.toLowerCase(),r=n.toLowerCase(),i=0;for(let l=0;l<r.length&&i<t.length;l++)r[l]===t[i]&&i++;return i===t.length}};function Fh(e){let o=new ir(e),n=new Rn,t=new ar;return async r=>{let i=r.includes("@"),l=r.includes("/");if(!i&&!l)return[[],r];let c=[];if(l){let u=await Nu(r,r.length);c.push(...u)}if(l&&n.canComplete(r,r.length)){let u=await n.getCompletions(r,r.length);c.push(...u)}if(l&&t.canComplete(r,r.length)){let u=await t.getCompletions(r,r.length);c.push(...u)}if(i&&o.canComplete(r,r.length)){let u=await o.getCompletions(r,r.length);c.push(...u)}return[c.map(u=>Ou(r,u)),r]}}a(Fh,"createCompleter");async function Nu(e,o){let{ArgumentCompleter:n}=await import("./argument-completer-X7MMM7Y6.js"),t=new n;return t.canComplete(e,o)?t.getCompletions(e,o):[]}a(Nu,"getArgumentCompletions");function Ou(e,o){if(o.type!=="argument")return o.text;let n=no(e);if(n!==-1&&!/\s/.test(e.slice(n)))return`${e} ${o.text}`;let r=e.match(/\S+$/)?.[0]??"";return`${r?e.slice(0,e.length-r.length):e}${o.text}`}a(Ou,"formatReadlineCompletion");import{existsSync as Tn,readdirSync as ha,readFileSync as ya}from"node:fs";import{join as In}from"node:path";var Du=[{name:"plan",description:"Read-only planning mode - blocks all modifications",type:"enum"},{name:"accept-edits",description:"File edits auto-approved, bash requires confirmation",type:"enum"},{name:"auto",description:"Use auto-mode classifier for tool permissions",type:"enum"}],Cn=[{name:"on",description:"Map to reasoning auto",type:"enum"},{name:"off",description:"Disable reasoning",type:"enum"},{name:"auto",description:"Use semantic routing with adaptive depth",type:"enum"},{name:"quick",description:"Low-depth reasoning mode",type:"enum"},{name:"balanced",description:"Medium-depth reasoning mode",type:"enum"},{name:"deep",description:"High-depth reasoning mode",type:"enum"}],ma=Cn.slice(2).concat([{name:"off",description:"Disable reasoning",type:"enum"}]);function Uu(e){if(e&&e.includes("/")){let o=e.indexOf("/"),n=e.slice(0,o),t=e.slice(o+1);if(We(n))try{return He(n).filter(i=>!t||i.toLowerCase().includes(t.toLowerCase())).map(i=>({name:`${n}/${i}`,description:i,type:"enum"}))}catch{}return[]}return Ne().map(o=>({name:o,description:`Switch to ${o} provider`,type:"enum"}))}a(Uu,"getModelArgs");var lr=[{name:"workspace",description:"Inspect current workspace/runtime truth in more detail",type:"enum"},{name:"runtime",description:"Alias for workspace runtime inspection",type:"enum"},{name:"worktree",description:"Alias for workspace runtime inspection",type:"enum"}],cr=[{name:"all",description:"Delete ALL sessions",type:"enum"}],ju=[{name:"status",description:"Show MCP server status",type:"enum"},{name:"refresh",description:"Refresh MCP server catalogs",type:"enum"}],Fu=[{name:"status",description:"Show child-task fallback order",type:"enum"},{name:"off",description:"Disable child-task fallback providers",type:"enum"}],Hu=[{name:"llm",description:"Use LLM classifier for auto mode",type:"enum"},{name:"rules",description:"Use rules-only auto mode",type:"enum"}],pa=[{name:"ama",description:"Use AMA agent mode",type:"enum"},{name:"amaw",description:"Use AMA workflow agent mode",type:"enum"},{name:"ama-workflow",description:"Alias for amaw",type:"enum"},{name:"sa",description:"Use single-agent mode",type:"enum"},{name:"toggle",description:"Cycle to the next agent mode",type:"enum"}],ga=[{name:"on",description:"Enable logging",type:"enum"},{name:"off",description:"Disable logging",type:"enum"}],Bu=[{name:"list",description:"List project memory files",type:"enum"},{name:"pending",description:"List pending memory proposals",type:"enum"},{name:"show",description:"Preview a memory proposal",type:"enum"},{name:"approve",description:"Approve a memory proposal",type:"enum"},{name:"reject",description:"Reject a memory proposal",type:"enum"},{name:"curate",description:"Report memory governance findings",type:"enum"},{name:"rebuild",description:"Rebuild MEMORY.md index",type:"enum"},{name:"open",description:"Print the memory entrypoint path",type:"enum"},{name:"help",description:"Show memory help",type:"enum"}],Gu=[{name:"status",description:"Show current persistent goal",type:"enum"},{name:"pause",description:"Pause the active goal",type:"enum"},{name:"resume",description:"Resume a paused goal",type:"enum"},{name:"clear",description:"Clear the current goal",type:"enum"},{name:"help",description:"Show goal help",type:"enum"},{name:"--tokens",description:"Set an optional goal token budget",type:"enum"}],qu=[{name:"show",description:"Show a captured paste by id",type:"enum"},{name:"list",description:"List captured pastes",type:"enum"}],Ku=[{name:"--lean",description:"Add a minimal-diff/YAGNI review pass",type:"enum"},{name:"--workflow",description:"Review through a dynamic workflow",type:"enum"},{name:"base",description:"Review changes against the detected base branch",type:"enum"},{name:"sha",description:"Review a specific commit",type:"enum"},{name:"help",description:"Show review help",type:"enum"}],zu=[{name:"init",description:"Create AGENTS.md in the target project if absent",type:"enum"},{name:"lean",description:"Initialize or LLM-review AGENTS.md for Lean Mode guidance",type:"enum"},{name:"help",description:"Show agents help",type:"enum"}],Xu=[{name:"status",description:"Inspect the current repo-intelligence runtime state",type:"enum"},{name:"mode",description:"Switch repo-intelligence runtime mode",type:"enum"},{name:"trace",description:"Toggle repo-intelligence trace output",type:"enum"}],Vu=[{name:"auto",description:"Let KodaX pick the best repo-intelligence engine",type:"enum"},{name:"full",description:"Prefer the full repo-intelligence engine",type:"enum"},{name:"light",description:"Use the light repo-intelligence engine",type:"enum"},{name:"off",description:"Disable repo-intelligence injection",type:"enum"}],Yu=[{name:"on",description:"Enable repo-intelligence trace output",type:"enum"},{name:"off",description:"Disable repo-intelligence trace output",type:"enum"},{name:"toggle",description:"Toggle repo-intelligence trace output",type:"enum"}],Ju=[{name:"status",description:"Deprecated alias for /repo-intel status",type:"enum"}],Zu=[{name:"list",description:"List built-in and saved workflows",type:"enum"},{name:"create",description:"Generate and run a workflow from a request",type:"enum"},{name:"runs",description:"List active and recent workflow runs",type:"enum"},{name:"show",description:"Show latest run or a specific workflow run",type:"enum"},{name:"pause",description:"Pause future child launches for a run",type:"enum"},{name:"resume",description:"Resume a paused run",type:"enum"},{name:"stop",description:"Stop an active workflow run",type:"enum"},{name:"delete",description:"Delete one persisted workflow run or generated saved capsule",type:"enum"},{name:"prune",description:"Preview or delete old terminal workflow runs",type:"enum"},{name:"rerun",description:"Rerun a run id or saved workflow name",type:"enum"},{name:"save",description:"Save a generated run as a workflow capsule",type:"enum"},{name:"rename",description:"Rename a run display name or saved workflow capsule",type:"enum"},{name:"revise",description:"Generate a revised workflow capsule",type:"enum"},{name:"help",description:"Show workflow help",type:"enum"}],Qu=new Set(["show","pause","resume","stop","delete","rerun","save","rename","revise"]),ef=new Set(["show","delete","rerun","save","rename","revise"]),of=[{name:"--all",description:"Show all persisted workflow runs",type:"enum"},{name:"--limit",description:"Show at most N persisted workflow runs",type:"enum"}],nf=[{name:"--dry-run",description:"Preview cleanup without deleting runs",type:"enum"},{name:"--keep",description:"Keep the newest N terminal runs",type:"enum"},{name:"--older-than",description:"Delete terminal runs older than Nd or Nh",type:"enum"}],tf=[{name:"--force",description:"Delete stale non-terminal run records",type:"enum"},{name:"--run",description:"Treat the target as a workflow run record",type:"enum"},{name:"--saved",description:"Treat the target as a generated saved workflow capsule",type:"enum"}],rf=[".workflow.json",".ts",".mjs",".js"];function sf(e,o){switch(e){case"pause":return o==="running";case"resume":return o==="paused";case"stop":return o==="running"||o==="paused";case"delete":return o!=="running"&&o!=="paused";default:return!0}}a(sf,"workflowRunMatchesSubcommand");function Pn(e){return/^[a-zA-Z0-9._-]{1,120}$/.test(e)&&!e.startsWith(".")&&!e.includes("..")}a(Pn,"isWorkflowRunEntryName");function af(e,o){let n=In(e,"workflow-metadata.json");if(Tn(n))try{let r=JSON.parse(ya(n,"utf8"));if(typeof r=="object"&&r!==null){let i=r.displayName;if(typeof i=="string"&&Pn(i.trim()))return i.trim()}}catch{}let t=o.displayName;return typeof t=="string"&&Pn(t.trim())?t.trim():void 0}a(af,"readWorkflowRunDisplayName");function lf(){let e=Ee(process.cwd()).key,o=H("workflow-runs",e);if(!Tn(o))return[];let n=[];for(let t of ha(o)){if(!Pn(t))continue;let r=In(o,t,"run.json");if(Tn(r))try{let i=JSON.parse(ya(r,"utf8")),l=typeof i.workflow=="string"?i.workflow:"?",c=typeof i.status=="string"?i.status:"?",d=typeof i.endedAt=="number"?i.endedAt:0;n.push({arg:{name:t,description:`${l} - ${c}`,type:"string"},endedAt:d});let u=af(In(o,t),i);u&&u!==t&&n.push({arg:{name:u,description:`${l} alias for ${t} - ${c}`,type:"string"},endedAt:d})}catch{}}return n.sort((t,r)=>r.endedAt-t.endedAt).map(t=>t.arg)}a(lf,"getPersistedWorkflowRunIdArgs");function _n(e){let o=Fe().list().filter(r=>sf(e,r.status)).map(r=>({name:r.runId,description:`${r.workflow} - ${r.status}`,type:"string"})),n=ef.has(e)?lf():[],t=new Set;return[...o,...n].filter(r=>t.has(r.name)?!1:(t.add(r.name),!0))}a(_n,"getWorkflowRunIdArgs");function cf(e){for(let o of rf)if(e.endsWith(o)){let n=e.slice(0,-o.length);return Pn(n)?n:void 0}}a(cf,"savedWorkflowNameFromFile");function Io(e={}){let o=[{path:H("workflows"),source:"personal"},{path:In(process.cwd(),".kodax","workflows"),source:"project"}],n=new Map;for(let t of o)if(Tn(t.path))try{for(let r of ha(t.path)){if(e.generatedOnly===!0&&!r.endsWith(".workflow.json"))continue;let i=cf(r);i&&n.set(i,{name:i,description:`${t.source} saved workflow`,type:"enum"})}}catch{}return[...n.values()].sort((t,r)=>t.name.localeCompare(r.name))}a(Io,"getSavedWorkflowNameArgs");function df(){let e=new Map;for(let o of _n("rerun"))e.set(o.name,{...o,description:`recent run: ${o.description}`,type:"string"});for(let o of Io()){let n=e.get(o.name);if(n){e.set(o.name,{...n,description:`${n.description}; also ${o.description}`});continue}e.set(o.name,{...o,description:o.description,type:"string"})}return[...e.values()]}a(df,"getWorkflowRerunArgs");function dr(e){let o=new Map;for(let n of _n(e))o.set(n.name,{...n,description:`workflow run: ${n.description}`,type:"string"});for(let n of Io({generatedOnly:e==="delete"})){let t=o.get(n.name);if(t){o.set(n.name,{...t,description:`${t.description}; also ${n.description}`});continue}o.set(n.name,{...n,description:n.description,type:"string"})}return[...o.values()]}a(dr,"getWorkflowRunOrSavedNameArgs");function wa(e){let o=new Set(e.slice(1).filter(n=>n.startsWith("--")));return o.has("--saved")?Io({generatedOnly:!0}):o.has("--run")?_n("delete"):dr("delete")}a(wa,"getWorkflowDeleteTargetArgs");function uf(e){let[o=""]=e,n=o.toLowerCase(),t=e.length===1&&e[0]===""?0:e.length;if(t<=1)return[...Zu,...Do().map(r=>({name:r.name,description:r.description,type:"enum"})),...Io()];if(n==="rerun"&&t<=2)return df();if(n==="rename"&&t<=2)return dr("rename");if(n==="delete"&&t<=2)return[...tf,...wa(e)];if(n==="delete"&&t<=3&&e.slice(1).some(r=>r.startsWith("--")))return wa(e);if(n==="revise"){if(t<=2)return[{name:"--replace",description:"Replace a saved workflow after confirmation",type:"enum"},...dr("revise")];if(e[1]==="--replace"&&t<=3)return Io()}return Qu.has(n)&&t<=2?_n(n):n==="runs"&&t<=2?of:n==="prune"&&t<=2?nf:[]}a(uf,"getWorkflowArgs");function ff(e){let[o=""]=e,n=o.toLowerCase(),t=e.length===1&&e[0]===""?0:e.length;return t<=1?Xu:t>2?[]:n==="mode"?Vu:n==="trace"?Yu:[]}a(ff,"getRepoIntelArgs");var mf=new Map([["mode",Du],["thinking",Cn],["think",Cn],["t",Cn],["reasoning",ma],["reason",ma],["status",lr],["info",lr],["ctx",lr],["mcp",ju],["fallback",Fu],["auto-engine",Hu],["agent-mode",pa],["am",pa],["verifier-log",ga],["stall-log",ga],["memory",Bu],["goal",Gu],["paste",qu],["review",Ku],["agents",zu],["delete",cr],["rm",cr],["del",cr]]),pf=new Set(["model","m","provider"]),gf=new Set(["repo-intel"]),wf=new Set(["repointel","ri"]),hf=new Set(["workflow"]);function ur(e,o,n=[]){let t=e.toLowerCase();return pf.has(t)?Uu(o):gf.has(t)?ff(n):wf.has(t)?n.length<=1?Ju:[]:hf.has(t)?uf(n):mf.get(t)??[]}a(ur,"getCommandArguments");var fr=class{static{a(this,"ArgumentCompleter")}canComplete(o,n){let t=o.slice(0,n),r=no(t);if(r===-1)return!1;let i=t.slice(r),l=i.split(/\s+/);if(l.length>=2&&l[0]!=="")return!0;let c=i.slice(1).toLowerCase();return ur(c).length>0}async getCompletions(o,n){let t=o.slice(0,n),r=no(t);if(r===-1)return[];let i=t.slice(r),l=i.indexOf(" "),c=(l===-1?i.slice(1):i.slice(1,l)).toLowerCase(),d=l===-1?"":i.slice(l+1),u=d?d.split(/\s+/):[""],f=u.length-1,m=(u[f]??"").toLowerCase(),y=ur(c,m,u);if(!y||y.length===0)return[];let v=new Set(u.slice(0,-1).map($=>$.toLowerCase()));return y.filter($=>!v.has($.name.toLowerCase())).filter($=>!m||$.name.includes("/")?!0:$.name.toLowerCase().includes(m)).map($=>({text:$.name,display:$.name,description:$.description,type:"argument"})).sort(($,g)=>{if(!m)return 0;let b=$.display.toLowerCase().startsWith(m),I=g.display.toLowerCase().startsWith(m);return b&&!I?-1:!b&&I?1:$.display.length-g.display.length})}};function ey(){return new fr}a(ey,"createArgumentCompleter");export{ct as a,G as b,Tm as c,Ys as d,Im as e,Bo as f,$f as g,ba as h,Sf as i,lo as j,ps as k,gs as l,co as m,Zn as n,Ua as o,Qn as p,ot as q,nt as r,mo as s,Ga as t,tt as u,Ge as v,Ns as w,Os as x,nl as y,gm as z,it as A,wm as B,hm as C,Gs as D,Vs as E,se as F,Qs as G,ei as H,Nm as I,yl as J,Pl as K,Om as L,Zo as M,ut as N,Dm as O,ci as P,Um as Q,jm as R,Fm as S,fp as T,mp as U,pp as V,hi as W,wt as X,yi as Y,Ee as Z,vp as _,ko as $,St as aa,Ie as ba,Xc as ca,Vc as da,Oi as ea,Kp as fa,zp as ga,ld as ha,Bg as ia,Gg as ja,qg as ka,dw as la,uw as ma,fw as na,mw as oa,pw as pa,Yi as qa,vw as ra,$w as sa,Zi as ta,Sw as ua,Fw as va,Qi as wa,Co as xa,Rh as ya,Eh as za,Rn as Aa,fr as Ba,ey as Ca,no as Da,ir as Ea,ar as Fa,Fh as Ga};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @kodax-ai/kodax — bundled distribution. See docs/ADR.md ADR-022 + ADR-024.
|
|
2
|
-
import{l as o}from"./chunk-
|
|
2
|
+
import{l as o}from"./chunk-K2NCKRVY.js";import{a as i}from"./chunk-ONUPGMER.js";function r(u){let e=o(u?.llm);if(!e)return;let t={};return e.requestTimeoutMs!==void 0&&(t.requestTimeoutMs=e.requestTimeoutMs),e.streamIdleTimeoutMs!==void 0&&(t.streamIdleTimeoutMs=e.streamIdleTimeoutMs),e.chunkTimeoutMs!==void 0&&(t.chunkTimeoutMs=e.chunkTimeoutMs),e.maxRetryDelayMs!==void 0&&(t.maxRetryDelayMs=e.maxRetryDelayMs),Object.keys(t).length>0?t:void 0}i(r,"providerResilienceConfigFromTimeouts");export{r as a};
|