@qitqode/qitqode-android-arm64 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/bun +0 -0
  2. package/bundle/chunk-0cdtq1r3.js +2 -0
  3. package/bundle/{chunk-v7mg632n.js → chunk-0yjdatm6.js} +1 -1
  4. package/bundle/{chunk-3ktj87g4.js → chunk-0ykeedfm.js} +1 -1
  5. package/bundle/{chunk-a0rjp24v.js → chunk-2517cev8.js} +1 -1
  6. package/bundle/{chunk-rnq5ezrt.js → chunk-2faah8w1.js} +1 -1
  7. package/bundle/{chunk-p5mes2sh.js → chunk-3888asr7.js} +1 -1
  8. package/bundle/{chunk-3wxvpvg4.js → chunk-3c3xzz0g.js} +1 -1
  9. package/bundle/{chunk-3aq70t26.js → chunk-3jms025t.js} +1 -1
  10. package/bundle/{chunk-f1bcz9yz.js → chunk-44y6dffe.js} +1 -1
  11. package/bundle/{chunk-wp3dpt6d.js → chunk-45fyv9f1.js} +1 -1
  12. package/bundle/{chunk-dknemkw2.js → chunk-543pt030.js} +1 -1
  13. package/bundle/{chunk-zqkv8796.js → chunk-5js6a6gf.js} +1 -1
  14. package/bundle/{chunk-dj3525nn.js → chunk-6f8qqbac.js} +189 -189
  15. package/bundle/{chunk-q9ft590w.js → chunk-7ab3yw9j.js} +1 -1
  16. package/bundle/chunk-7q003wdd.js +4 -0
  17. package/bundle/{chunk-6y4mwmn4.js → chunk-7z884mz2.js} +1 -1
  18. package/bundle/{chunk-qeg0jnxq.js → chunk-7zc04q43.js} +1 -1
  19. package/bundle/{chunk-g5cgpvef.js → chunk-85xh72hk.js} +1 -1
  20. package/bundle/{chunk-tce12v85.js → chunk-8apeexas.js} +1 -1
  21. package/bundle/{chunk-7myg8076.js → chunk-8d6e4jg7.js} +1 -1
  22. package/bundle/{chunk-qg9bt0kx.js → chunk-8v6x712g.js} +1 -1
  23. package/bundle/{chunk-mx3jd1p9.js → chunk-91z7azf7.js} +1 -1
  24. package/bundle/{chunk-e89zjjmj.js → chunk-96sqbyvf.js} +1 -1
  25. package/bundle/{chunk-bzs2ep7s.js → chunk-9bm9z52r.js} +1 -1
  26. package/bundle/{chunk-6bghztra.js → chunk-9pnpmtb2.js} +1 -1
  27. package/bundle/chunk-9s785py4.js +28 -0
  28. package/bundle/{chunk-kc1xmcc9.js → chunk-a550vst5.js} +39 -37
  29. package/bundle/{chunk-7zvawpe1.js → chunk-a5pbvp1f.js} +1 -1
  30. package/bundle/{chunk-tq1dqhes.js → chunk-c1bw1q75.js} +1 -1
  31. package/bundle/{chunk-erdjd9w3.js → chunk-c47vp7ne.js} +1 -1
  32. package/bundle/{chunk-ke5rqv5b.js → chunk-cbhgf058.js} +1 -1
  33. package/bundle/{chunk-jgtcfw96.js → chunk-dbztxdea.js} +1 -1
  34. package/bundle/{chunk-57xbwzdn.js → chunk-dy31mchw.js} +1 -1
  35. package/bundle/{chunk-jjjs8p0t.js → chunk-e374shb8.js} +1 -1
  36. package/bundle/{chunk-s7yza695.js → chunk-e5rda9mx.js} +1 -1
  37. package/bundle/{chunk-qzszrd0s.js → chunk-e999xtfj.js} +1 -1
  38. package/bundle/{chunk-nb86kh94.js → chunk-ehfxypks.js} +69 -71
  39. package/bundle/{chunk-hpa7e9va.js → chunk-epa576pa.js} +2 -2
  40. package/bundle/{chunk-knh01n2r.js → chunk-et5dnymk.js} +1 -1
  41. package/bundle/{chunk-ahyqfbmq.js → chunk-frsd6e1h.js} +1 -1
  42. package/bundle/{chunk-ztn2jv26.js → chunk-g7k6ecb2.js} +1 -1
  43. package/bundle/{chunk-xjpvv3vp.js → chunk-h10wjk96.js} +1 -1
  44. package/bundle/{chunk-hmznf0ax.js → chunk-h2bmss2m.js} +1 -1
  45. package/bundle/chunk-h4f582d6.js +2 -0
  46. package/bundle/chunk-h57c6ne3.js +2 -0
  47. package/bundle/{chunk-yg0pfngv.js → chunk-hnrqhcgq.js} +1 -1
  48. package/bundle/{chunk-fvkwcx35.js → chunk-hy86wfad.js} +1 -1
  49. package/bundle/{chunk-073ydjmk.js → chunk-j17421hz.js} +1 -1
  50. package/bundle/chunk-kh8de8re.js +2 -0
  51. package/bundle/{chunk-yqb6cfed.js → chunk-kmwy6c9g.js} +1 -1
  52. package/bundle/{chunk-mk2s9py8.js → chunk-mce8aa9y.js} +1 -1
  53. package/bundle/{chunk-s99cvvc9.js → chunk-me1ja46g.js} +1 -1
  54. package/bundle/{chunk-faa0zxey.js → chunk-mrn44msr.js} +1 -1
  55. package/bundle/chunk-q2q3dmg3.js +2 -0
  56. package/bundle/chunk-q46pzk9z.js +8 -0
  57. package/bundle/{chunk-pfh34atn.js → chunk-racrb1b3.js} +1 -1
  58. package/bundle/{chunk-fymt1rym.js → chunk-s0c0t6qr.js} +1 -1
  59. package/bundle/{chunk-qkh8697x.js → chunk-s77qktcn.js} +1 -1
  60. package/bundle/{chunk-mxf9p0p9.js → chunk-sghy9s7m.js} +1 -1
  61. package/bundle/{chunk-r2qns6yc.js → chunk-sjreby6e.js} +1 -1
  62. package/bundle/{chunk-29v1v357.js → chunk-skxhg212.js} +1 -1
  63. package/bundle/{chunk-yerfyz4w.js → chunk-ssdw9zre.js} +1 -1
  64. package/bundle/{chunk-g9end129.js → chunk-t1475j9f.js} +1 -1
  65. package/bundle/{chunk-0z1cxvk1.js → chunk-tj3rem3q.js} +1 -1
  66. package/bundle/{chunk-f7rj6fck.js → chunk-vk88jj60.js} +1 -1
  67. package/bundle/{chunk-ex93y6dw.js → chunk-vrv67tt0.js} +1 -1
  68. package/bundle/{chunk-9eg2ytjd.js → chunk-vtw0wwch.js} +1 -1
  69. package/bundle/{chunk-q148vndn.js → chunk-vyh300ac.js} +1 -1
  70. package/bundle/{chunk-vjx0064q.js → chunk-w30b563s.js} +1 -1
  71. package/bundle/chunk-wcx7hc2p.js +635 -0
  72. package/bundle/{chunk-7rhry8nv.js → chunk-wv8qx8sa.js} +1 -1
  73. package/bundle/{chunk-sh76e256.js → chunk-xmjntwjc.js} +1 -1
  74. package/bundle/{chunk-nm6wnne9.js → chunk-y2ptjam9.js} +1 -1
  75. package/bundle/{chunk-nh044sjn.js → chunk-y6h35v4a.js} +1 -1
  76. package/bundle/{chunk-0yagj4ss.js → chunk-y72p79v2.js} +1 -1
  77. package/bundle/{chunk-4jq25vbc.js → chunk-y9q0f9qz.js} +1 -1
  78. package/bundle/{chunk-f4zfk5ye.js → chunk-yhsnmpzv.js} +1 -1
  79. package/bundle/{chunk-qf1dqzra.js → chunk-ywdtp534.js} +1 -1
  80. package/bundle/{chunk-xnhvt98g.js → chunk-zcp0wx4j.js} +1 -1
  81. package/bundle/index.js +3 -3
  82. package/bundle/worker.js +1 -1
  83. package/package.json +1 -1
  84. package/bundle/chunk-0xrr0k94.js +0 -2
  85. package/bundle/chunk-3kn57y8d.js +0 -619
  86. package/bundle/chunk-9nn4jpb7.js +0 -2
  87. package/bundle/chunk-9tk4wsn4.js +0 -2
  88. package/bundle/chunk-egae7vvg.js +0 -2
  89. package/bundle/chunk-fghqr4x8.js +0 -8
  90. package/bundle/chunk-x3afqfww.js +0 -4
  91. package/bundle/chunk-xwgc2pw7.js +0 -28
  92. package/bundle/chunk-yxeja9kg.js +0 -2
package/bun CHANGED
Binary file
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ import{Os as D}from"./chunk-xmjntwjc.js";import{$s as M,_s as B,at as O,bt as b,ct as y,dt as G}from"./chunk-7q003wdd.js";import{NO as p}from"./chunk-f83wv08n.js";var H={free:{providerID:"qlex",modelID:"free"},default:{providerID:"qlex",modelID:"default"},fast:{providerID:"qlex",modelID:"fast"},economical:{providerID:"qlex",modelID:"economical"},power:{providerID:"qlex",modelID:"power"},orchestrated:{providerID:"qlex",modelID:"orchestrated"}},V={free:"Free (no cost)",default:"Default",fast:"Fast",economical:"Economy",power:"Power",orchestrated:"Orchestrated"},F={free:{output:128000,recommendedStep:32000,context:262144,reasoning:!0,reasoningReserve:8192,visibleOutputFloor:512,recommendedTotal:9600,viableTotalFloor:9600},fast:{output:65536,recommendedStep:50000,context:1048576,reasoning:!1,reasoningReserve:0,visibleOutputFloor:2048,recommendedTotal:50000,viableTotalFloor:2048},economical:{output:209715,recommendedStep:32000,context:1048576,reasoning:!0,reasoningReserve:8192,visibleOutputFloor:512,recommendedTotal:9600,viableTotalFloor:9600},default:{output:128000,recommendedStep:32000,context:1050000,reasoning:!1,reasoningReserve:0,visibleOutputFloor:2048,recommendedTotal:32000,viableTotalFloor:2048},power:{output:200000,recommendedStep:32000,context:200000,reasoning:!1,reasoningReserve:0,visibleOutputFloor:2048,recommendedTotal:32000,viableTotalFloor:2048},orchestrated:{output:128000,recommendedStep:32000,context:200000,reasoning:!1,reasoningReserve:0,visibleOutputFloor:2048,recommendedTotal:32000,viableTotalFloor:2048}},Z={},c="pending",Q=new Set;function Y(){return c}function f(){c="pending",X()}function C(x){return Q.add(x),()=>Q.delete(x)}function X(){for(let x of[...Q])try{x()}catch{}}function q(){for(let x of Object.keys(Z))delete Z[x];c="unavailable",X()}function P(x){return typeof x==="number"&&Number.isFinite(x)&&x>=0&&x<=10}function h(x){if(x===void 0){q();return}let K=x!==null&&typeof x==="object"&&!Array.isArray(x)?x:void 0;if(K?.success===!1){q();return}let J=K?.success===!0&&Object.prototype.hasOwnProperty.call(K,"data")?K.data:x,j={};if(J===null||typeof J!=="object"||Array.isArray(J)){q();return}for(let[W,$]of Object.entries(J)){if(!$||typeof $!=="object"||Array.isArray($)){q();return}let z=$;if(!P(z.intelligence)||!P(z.speed)||!P(z.cost)){q();return}j[W]={intelligence:z.intelligence,speed:z.speed,cost:z.cost}}for(let W of Object.keys(Z))delete Z[W];Object.assign(Z,j),c="live",X()}function w(x){if(!Array.isArray(x)||x.length===0)return;let K={},J={};for(let j of x){let W=H[j.id];K[j.id]={providerID:j.providerID??W?.providerID??"qlex",modelID:j.modelID??W?.modelID??j.id},J[j.id]=j.label??V[j.id]??j.id}for(let j of Object.keys(H))delete H[j];Object.assign(H,K);for(let j of Object.keys(V))delete V[j];Object.assign(V,J)}var N={};p(N,{tiers:()=>L,tierRatingsState:()=>Y,tierRatings:()=>S,tierBudgetFacts:()=>d,streamUrl:()=>I,streamBaseUrl:()=>E,sanitizeUpstreamError:()=>T,qlexProviderMeta:()=>v,onTierRatingsChange:()=>C,omniqueryBaseUrl:()=>g,mergeLiveTiers:()=>u,mergeLiveTierRatings:()=>A,markTierRatingsUnavailable:()=>q,loadLiveRatings:()=>k,evaluatePermission:()=>_,copy:()=>R,beginTierRatingsLoad:()=>f,bashPrefixWith:()=>o,TIER_RATINGS:()=>Z,AGENT_PROMPT_NAMES:()=>l});var m=3,U=[250,750];async function k(x){for(let K=0;K<m;K++){let J=await x();if(J!==void 0)return J;let j=U[K];if(j!==void 0)await new Promise((W)=>setTimeout(W,j))}return}function u(x){w(x)}function A(x){h(x)}function L(){return Object.entries(H).map(([x,K])=>({id:x,label:V[x]??x,providerID:K.providerID,modelID:K.modelID}))}function d(x){return F[x]}function S(){return Z}function _(x,K,...J){return J.flat().findLast(($)=>D(x,$.permission)&&D(K,$.pattern))??{action:"ask",permission:x,pattern:"*"}}function o(x,K){for(let J=K.length;J>0;J--){let j=K.slice(0,J).join(" "),W=x[j];if(W!==void 0)return K.slice(0,W)}if(K.length===0)return[];return K.slice(0,1)}function I(){return B}function E(){return M}function g(){return O}function v(){return b}function T(x){return y(x)}function R(){return G}var l=["generate","explore","dream","distill","summary","compaction","title"];export{H as ss,N as ts};
@@ -1,3 +1,3 @@
1
1
  // @bun
2
- import{Ng as D,Zg as x}from"./chunk-3kn57y8d.js";import{Ch as E}from"./chunk-nb86kh94.js";import{cm as w}from"./chunk-xnhvt98g.js";import{nt as z}from"./chunk-x3afqfww.js";var H=z.create({service:"cli.bootstrap"});async function P(F,G){return w.provide({directory:F,init:()=>x.runPromise(D),fn:async()=>{try{return await G()}finally{await x.runPromise(E.Service.use((q)=>q.drainWriters())).catch((q)=>H.warn("checkpoint drain failed",{error:String(q)})),await w.dispose()}}})}
2
+ import{Ng as D,Zg as x}from"./chunk-wcx7hc2p.js";import{Ch as E}from"./chunk-ehfxypks.js";import{cm as w}from"./chunk-zcp0wx4j.js";import{nt as z}from"./chunk-7q003wdd.js";var H=z.create({service:"cli.bootstrap"});async function P(F,G){return w.provide({directory:F,init:()=>x.runPromise(D),fn:async()=>{try{return await G()}finally{await x.runPromise(E.Service.use((q)=>q.drainWriters())).catch((q)=>H.warn("checkpoint drain failed",{error:String(q)})),await w.dispose()}}})}
3
3
  export{P as Ed};
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- import{Id as q,Jd as K,Kd as D,Nd as L,Od as N}from"./chunk-p9mj4zyk.js";import"./chunk-ta7mfkms.js";import{Uf as B}from"./chunk-t1jgx17a.js";import{Zg as G}from"./chunk-3kn57y8d.js";import"./chunk-nb86kh94.js";import"./chunk-9rxyq6f9.js";import"./chunk-5az84brc.js";import"./chunk-94qhpkfx.js";import"./chunk-c1g8n10t.js";import"./chunk-a2dz9nqh.js";import"./chunk-vhe92p7a.js";import"./chunk-kc1xmcc9.js";import{wl as C}from"./chunk-jjjs8p0t.js";import"./chunk-xnhvt98g.js";import"./chunk-hpa7e9va.js";import"./chunk-y287zwkr.js";import"./chunk-qeg0jnxq.js";import"./chunk-9eg2ytjd.js";import"./chunk-rk2bk4s7.js";import"./chunk-e586sjb0.js";import"./chunk-b50t4jc5.js";import"./chunk-zdzxsyxs.js";import"./chunk-xny5ecn0.js";import"./chunk-7myg8076.js";import"./chunk-my3cswnp.js";import"./chunk-4mvg7jt1.js";import"./chunk-cqtkxwd8.js";import"./chunk-wf4x5cjc.js";import"./chunk-mswx4k75.js";import"./chunk-vqpfpmha.js";import"./chunk-vm1ek7yf.js";import"./chunk-fd7fmvyw.js";import"./chunk-1sfcxdbw.js";import"./chunk-bgng3rdj.js";import"./chunk-qkh8697x.js";import"./chunk-qg9bt0kx.js";import"./chunk-pfkm3j8g.js";import"./chunk-hmznf0ax.js";import"./chunk-qf1dqzra.js";import"./chunk-03mbn7nj.js";import"./chunk-gr4bctqj.js";import"./chunk-732yr6qq.js";import"./chunk-73fz0cf4.js";import"./chunk-9nn4jpb7.js";import{us as J}from"./chunk-sh76e256.js";import"./chunk-0z1cxvk1.js";import"./chunk-x3afqfww.js";import"./chunk-cbmwhvxw.js";import"./chunk-9etpppyv.js";import"./chunk-9ea1n338.js";import"./chunk-ngvp6zc2.js";import"./chunk-1p6jjrea.js";import"./chunk-ks1cs80p.js";import"./chunk-a92hh67a.js";import"./chunk-qhnpq5gb.js";import"./chunk-f83wv08n.js";var X={command:"upgrade [target]",describe:"upgrade qitqode to the latest or a specific version",builder:(z)=>{return z.positional("target",{describe:"version to upgrade to, for ex '0.1.48' or 'v0.1.48'",type:"string"}).option("method",{alias:"m",describe:"installation method to use",type:"string",choices:["curl","npm","pnpm","bun","brew","choco","scoop"]})},handler:async(z)=>{B.empty(),B.println(B.logo(" ")),B.empty(),K("Upgrade");let O=await G.runPromise(C.Service.use((j)=>j.method())),E=z.method??O;if(E==="unknown"){if(q.error(`qitqode is installed to ${process.execPath} and may be managed by a package manager`),!await N({message:"Install anyways?",options:[{label:"Yes",value:!0},{label:"No",value:!1}],initialValue:!1})){D("Done");return}}q.info("Using method: "+E);let F=z.target?z.target.replace(/^v/,""):await G.runPromise(C.Service.use((j)=>j.latest()));if(J===F){q.warn(`qitqode upgrade skipped: ${F} is already installed`),D("Done");return}q.info(`From ${J} \u2192 ${F}`);let H=L();H.start("Upgrading...");let x=await G.runPromise(C.Service.use((j)=>j.upgrade(E,F))).catch((j)=>j);if(x){if(H.stop("Upgrade failed",1),x instanceof C.UpgradeFailedError)if(E==="choco"&&x.stderr.includes("not running from an elevated command shell"))q.error("Please run the terminal as Administrator and try again");else q.error(x.stderr);else if(x instanceof Error)q.error(x.message);D("Done");return}H.stop("Upgrade complete"),D("Done")}};export{X as UpgradeCommand};
2
+ import{Id as q,Jd as K,Kd as D,Nd as L,Od as N}from"./chunk-p9mj4zyk.js";import"./chunk-ta7mfkms.js";import{Uf as B}from"./chunk-t1jgx17a.js";import{Zg as G}from"./chunk-wcx7hc2p.js";import"./chunk-ehfxypks.js";import"./chunk-9rxyq6f9.js";import"./chunk-5az84brc.js";import"./chunk-94qhpkfx.js";import"./chunk-c1g8n10t.js";import"./chunk-a2dz9nqh.js";import"./chunk-vhe92p7a.js";import"./chunk-a550vst5.js";import{wl as C}from"./chunk-e374shb8.js";import"./chunk-zcp0wx4j.js";import"./chunk-epa576pa.js";import"./chunk-y287zwkr.js";import"./chunk-7zc04q43.js";import"./chunk-vtw0wwch.js";import"./chunk-rk2bk4s7.js";import"./chunk-e586sjb0.js";import"./chunk-b50t4jc5.js";import"./chunk-zdzxsyxs.js";import"./chunk-xny5ecn0.js";import"./chunk-8d6e4jg7.js";import"./chunk-my3cswnp.js";import"./chunk-4mvg7jt1.js";import"./chunk-cqtkxwd8.js";import"./chunk-wf4x5cjc.js";import"./chunk-mswx4k75.js";import"./chunk-vqpfpmha.js";import"./chunk-vm1ek7yf.js";import"./chunk-fd7fmvyw.js";import"./chunk-1sfcxdbw.js";import"./chunk-bgng3rdj.js";import"./chunk-s77qktcn.js";import"./chunk-8v6x712g.js";import"./chunk-pfkm3j8g.js";import"./chunk-h2bmss2m.js";import"./chunk-ywdtp534.js";import"./chunk-03mbn7nj.js";import"./chunk-gr4bctqj.js";import"./chunk-732yr6qq.js";import"./chunk-73fz0cf4.js";import"./chunk-0cdtq1r3.js";import{us as J}from"./chunk-xmjntwjc.js";import"./chunk-tj3rem3q.js";import"./chunk-7q003wdd.js";import"./chunk-cbmwhvxw.js";import"./chunk-9etpppyv.js";import"./chunk-9ea1n338.js";import"./chunk-ngvp6zc2.js";import"./chunk-1p6jjrea.js";import"./chunk-ks1cs80p.js";import"./chunk-a92hh67a.js";import"./chunk-qhnpq5gb.js";import"./chunk-f83wv08n.js";var X={command:"upgrade [target]",describe:"upgrade qitqode to the latest or a specific version",builder:(z)=>{return z.positional("target",{describe:"version to upgrade to, for ex '0.1.48' or 'v0.1.48'",type:"string"}).option("method",{alias:"m",describe:"installation method to use",type:"string",choices:["curl","npm","pnpm","bun","brew","choco","scoop"]})},handler:async(z)=>{B.empty(),B.println(B.logo(" ")),B.empty(),K("Upgrade");let O=await G.runPromise(C.Service.use((j)=>j.method())),E=z.method??O;if(E==="unknown"){if(q.error(`qitqode is installed to ${process.execPath} and may be managed by a package manager`),!await N({message:"Install anyways?",options:[{label:"Yes",value:!0},{label:"No",value:!1}],initialValue:!1})){D("Done");return}}q.info("Using method: "+E);let F=z.target?z.target.replace(/^v/,""):await G.runPromise(C.Service.use((j)=>j.latest()));if(J===F){q.warn(`qitqode upgrade skipped: ${F} is already installed`),D("Done");return}q.info(`From ${J} \u2192 ${F}`);let H=L();H.start("Upgrading...");let x=await G.runPromise(C.Service.use((j)=>j.upgrade(E,F))).catch((j)=>j);if(x){if(H.stop("Upgrade failed",1),x instanceof C.UpgradeFailedError)if(E==="choco"&&x.stderr.includes("not running from an elevated command shell"))q.error("Please run the terminal as Administrator and try again");else q.error(x.stderr);else if(x instanceof Error)q.error(x.message);D("Done");return}H.stop("Upgrade complete"),D("Done")}};export{X as UpgradeCommand};
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- import{Yg as a,Zg as b}from"./chunk-3kn57y8d.js";import"./chunk-nb86kh94.js";import"./chunk-9rxyq6f9.js";import"./chunk-5az84brc.js";import"./chunk-94qhpkfx.js";import"./chunk-c1g8n10t.js";import"./chunk-a2dz9nqh.js";import"./chunk-vhe92p7a.js";import"./chunk-kc1xmcc9.js";import"./chunk-jjjs8p0t.js";import"./chunk-xnhvt98g.js";import"./chunk-hpa7e9va.js";import"./chunk-y287zwkr.js";import"./chunk-qeg0jnxq.js";import"./chunk-9eg2ytjd.js";import"./chunk-rk2bk4s7.js";import"./chunk-e586sjb0.js";import"./chunk-b50t4jc5.js";import"./chunk-zdzxsyxs.js";import"./chunk-xny5ecn0.js";import"./chunk-7myg8076.js";import"./chunk-my3cswnp.js";import"./chunk-4mvg7jt1.js";import"./chunk-cqtkxwd8.js";import"./chunk-wf4x5cjc.js";import"./chunk-mswx4k75.js";import"./chunk-vqpfpmha.js";import"./chunk-vm1ek7yf.js";import"./chunk-fd7fmvyw.js";import"./chunk-1sfcxdbw.js";import"./chunk-bgng3rdj.js";import"./chunk-qkh8697x.js";import"./chunk-qg9bt0kx.js";import"./chunk-pfkm3j8g.js";import"./chunk-hmznf0ax.js";import"./chunk-qf1dqzra.js";import"./chunk-03mbn7nj.js";import"./chunk-gr4bctqj.js";import"./chunk-732yr6qq.js";import"./chunk-73fz0cf4.js";import"./chunk-9nn4jpb7.js";import"./chunk-sh76e256.js";import"./chunk-0z1cxvk1.js";import"./chunk-x3afqfww.js";import"./chunk-cbmwhvxw.js";import"./chunk-9etpppyv.js";import"./chunk-9ea1n338.js";import"./chunk-ngvp6zc2.js";import"./chunk-1p6jjrea.js";import"./chunk-ks1cs80p.js";import"./chunk-a92hh67a.js";import"./chunk-qhnpq5gb.js";import"./chunk-f83wv08n.js";export{b as AppRuntime,a as AppLayer};
2
+ import{Yg as a,Zg as b}from"./chunk-wcx7hc2p.js";import"./chunk-ehfxypks.js";import"./chunk-9rxyq6f9.js";import"./chunk-5az84brc.js";import"./chunk-94qhpkfx.js";import"./chunk-c1g8n10t.js";import"./chunk-a2dz9nqh.js";import"./chunk-vhe92p7a.js";import"./chunk-a550vst5.js";import"./chunk-e374shb8.js";import"./chunk-zcp0wx4j.js";import"./chunk-epa576pa.js";import"./chunk-y287zwkr.js";import"./chunk-7zc04q43.js";import"./chunk-vtw0wwch.js";import"./chunk-rk2bk4s7.js";import"./chunk-e586sjb0.js";import"./chunk-b50t4jc5.js";import"./chunk-zdzxsyxs.js";import"./chunk-xny5ecn0.js";import"./chunk-8d6e4jg7.js";import"./chunk-my3cswnp.js";import"./chunk-4mvg7jt1.js";import"./chunk-cqtkxwd8.js";import"./chunk-wf4x5cjc.js";import"./chunk-mswx4k75.js";import"./chunk-vqpfpmha.js";import"./chunk-vm1ek7yf.js";import"./chunk-fd7fmvyw.js";import"./chunk-1sfcxdbw.js";import"./chunk-bgng3rdj.js";import"./chunk-s77qktcn.js";import"./chunk-8v6x712g.js";import"./chunk-pfkm3j8g.js";import"./chunk-h2bmss2m.js";import"./chunk-ywdtp534.js";import"./chunk-03mbn7nj.js";import"./chunk-gr4bctqj.js";import"./chunk-732yr6qq.js";import"./chunk-73fz0cf4.js";import"./chunk-0cdtq1r3.js";import"./chunk-xmjntwjc.js";import"./chunk-tj3rem3q.js";import"./chunk-7q003wdd.js";import"./chunk-cbmwhvxw.js";import"./chunk-9etpppyv.js";import"./chunk-9ea1n338.js";import"./chunk-ngvp6zc2.js";import"./chunk-1p6jjrea.js";import"./chunk-ks1cs80p.js";import"./chunk-a92hh67a.js";import"./chunk-qhnpq5gb.js";import"./chunk-f83wv08n.js";export{b as AppRuntime,a as AppLayer};
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- import{Ed as n}from"./chunk-v7mg632n.js";import{Rd as i}from"./chunk-yajd975f.js";import{Zg as r}from"./chunk-3kn57y8d.js";import{$g as y,Kh as K,Lh as X,ah as w,eh as R}from"./chunk-nb86kh94.js";import"./chunk-9rxyq6f9.js";import"./chunk-5az84brc.js";import"./chunk-94qhpkfx.js";import"./chunk-c1g8n10t.js";import"./chunk-a2dz9nqh.js";import"./chunk-vhe92p7a.js";import{Ok as g,ck as V,dk as W,gk as C,il as J,ok as M,tl as Y,ul as F}from"./chunk-kc1xmcc9.js";import"./chunk-jjjs8p0t.js";import{am as E,cm as u}from"./chunk-xnhvt98g.js";import"./chunk-hpa7e9va.js";import"./chunk-y287zwkr.js";import"./chunk-qeg0jnxq.js";import"./chunk-9eg2ytjd.js";import"./chunk-rk2bk4s7.js";import"./chunk-e586sjb0.js";import"./chunk-b50t4jc5.js";import"./chunk-zdzxsyxs.js";import"./chunk-xny5ecn0.js";import"./chunk-7myg8076.js";import"./chunk-my3cswnp.js";import"./chunk-4mvg7jt1.js";import"./chunk-cqtkxwd8.js";import"./chunk-wf4x5cjc.js";import"./chunk-mswx4k75.js";import"./chunk-vqpfpmha.js";import"./chunk-vm1ek7yf.js";import"./chunk-fd7fmvyw.js";import"./chunk-1sfcxdbw.js";import"./chunk-bgng3rdj.js";import"./chunk-qkh8697x.js";import"./chunk-qg9bt0kx.js";import"./chunk-pfkm3j8g.js";import{Xr as U}from"./chunk-hmznf0ax.js";import"./chunk-qf1dqzra.js";import"./chunk-03mbn7nj.js";import"./chunk-gr4bctqj.js";import"./chunk-732yr6qq.js";import"./chunk-73fz0cf4.js";import"./chunk-9nn4jpb7.js";import{Qs as z,Rs as B,Ss as _,Us as H}from"./chunk-sh76e256.js";import"./chunk-0z1cxvk1.js";import{nt as S}from"./chunk-x3afqfww.js";import{Dt as oo}from"./chunk-cbmwhvxw.js";import"./chunk-9etpppyv.js";import"./chunk-9ea1n338.js";import"./chunk-ngvp6zc2.js";import"./chunk-1p6jjrea.js";import{oK as x,xH as d}from"./chunk-ks1cs80p.js";import"./chunk-a92hh67a.js";import"./chunk-qhnpq5gb.js";import{QO as v,RO as P}from"./chunk-f83wv08n.js";import{EOL as to}from"os";var I=i({command:"config",describe:"show resolved configuration",builder:(o)=>o,async handler(){await n(process.cwd(),async()=>{let o=await r.runPromise(F.Service.use((e)=>e.get()));process.stdout.write(JSON.stringify(o,null,2)+to)})}});import{EOL as b}from"os";var io=i({command:"search <query>",describe:"search files by query",builder:(o)=>o.positional("query",{type:"string",demandOption:!0,description:"Search query"}),async handler(o){await n(process.cwd(),async()=>{let e=await r.runPromise(w.Service.use((t)=>t.search({query:o.query})));process.stdout.write(e.join(b)+b)})}}),ro=i({command:"read <path>",describe:"read file contents as JSON",builder:(o)=>o.positional("path",{type:"string",demandOption:!0,description:"File path to read"}),async handler(o){await n(process.cwd(),async()=>{let e=await r.runPromise(w.Service.use((t)=>t.read(o.path)));process.stdout.write(JSON.stringify(e,null,2)+b)})}}),no=i({command:"status",describe:"show file status information",builder:(o)=>o,async handler(){await n(process.cwd(),async()=>{let o=await r.runPromise(w.Service.use((e)=>e.status()));process.stdout.write(JSON.stringify(o,null,2)+b)})}}),so=i({command:"list <path>",describe:"list files in a directory",builder:(o)=>o.positional("path",{type:"string",demandOption:!0,description:"File path to list"}),async handler(o){await n(process.cwd(),async()=>{let e=await r.runPromise(w.Service.use((t)=>t.list(o.path)));process.stdout.write(JSON.stringify(e,null,2)+b)})}}),mo=i({command:"tree [dir]",describe:"show directory tree",builder:(o)=>o.positional("dir",{type:"string",description:"Directory to tree",default:process.cwd()}),async handler(o){await n(process.cwd(),async()=>{let e=await r.runPromise(y.Service.use((t)=>t.tree({cwd:o.dir,limit:200})));console.log(JSON.stringify(e,null,2))})}}),L=i({command:"file",describe:"file system debugging utilities",builder:(o)=>o.command(ro).command(no).command(so).command(io).command(mo).demandCommand(),async handler(){}});import{EOL as A}from"os";var q=i({command:"lsp",describe:"LSP debugging utilities",builder:(o)=>o.command(ao).command(co).command(lo).demandCommand(),async handler(){}}),ao=i({command:"diagnostics <file>",describe:"get diagnostics for a file",builder:(o)=>o.positional("file",{type:"string",demandOption:!0}),async handler(o){await n(process.cwd(),async()=>{let e=await r.runPromise(C.Service.use((t)=>d.gen(function*(){return yield*t.touchFile(o.file,!0),yield*d.sleep(1000),yield*t.diagnostics()})));process.stdout.write(JSON.stringify(e,null,2)+A)})}}),co=i({command:"symbols <query>",describe:"search workspace symbols",builder:(o)=>o.positional("query",{type:"string",demandOption:!0}),async handler(o){await n(process.cwd(),async()=>{let s=[];try{const e=v(s,S.Default.time("symbols"),0);let t=await r.runPromise(C.Service.use((m)=>m.workspaceSymbol(o.query)));process.stdout.write(JSON.stringify(t,null,2)+A)}catch(a){var c=a,l=1}finally{P(s,c,l)}})}}),lo=i({command:"document-symbols <uri>",describe:"get symbols from a document",builder:(o)=>o.positional("uri",{type:"string",demandOption:!0}),async handler(o){await n(process.cwd(),async()=>{let s=[];try{const e=v(s,S.Default.time("document-symbols"),0);let t=await r.runPromise(C.Service.use((m)=>m.documentSymbol(o.uri)));process.stdout.write(JSON.stringify(t,null,2)+A)}catch(a){var c=a,l=1}finally{P(s,c,l)}})}});import{EOL as O}from"os";var k=i({command:"rg",describe:"ripgrep debugging utilities",builder:(o)=>o.command(po).command(uo).command(fo).demandCommand(),async handler(){}}),po=i({command:"tree",describe:"show file tree using ripgrep",builder:(o)=>o.option("limit",{type:"number"}),async handler(o){await n(process.cwd(),async()=>{let e=await r.runPromise(y.Service.use((t)=>t.tree({cwd:u.directory,limit:o.limit})));process.stdout.write(e+O)})}}),uo=i({command:"files",describe:"list files using ripgrep",builder:(o)=>o.option("query",{type:"string",description:"Filter files by query"}).option("glob",{type:"string",description:"Glob pattern to match files"}).option("limit",{type:"number",description:"Limit number of results"}),async handler(o){await n(process.cwd(),async()=>{let e=await r.runPromise(d.gen(function*(){return yield*(yield*y.Service).files({cwd:u.directory,glob:o.glob?[o.glob]:void 0}).pipe(x.take(o.limit??1/0),x.runCollect,d.map((s)=>[...s]))}));process.stdout.write(e.join(O)+O)})}}),fo=i({command:"search <pattern>",describe:"search file contents using ripgrep",builder:(o)=>o.positional("pattern",{type:"string",demandOption:!0,description:"Search pattern"}).option("glob",{type:"array",description:"File glob patterns"}).option("limit",{type:"number",description:"Limit number of results"}),async handler(o){await n(process.cwd(),async()=>{let e=await r.runPromise(y.Service.use((t)=>t.search({cwd:u.directory,pattern:o.pattern,glob:o.glob,limit:o.limit})));process.stdout.write(JSON.stringify(e.items,null,2)+O)})}});import{EOL as yo}from"os";var T=i({command:"scrap",describe:"list all known projects",builder:(o)=>o,async handler(){let o=S.Default.time("scrap"),e=await E.list();process.stdout.write(JSON.stringify(e,null,2)+yo),o.stop()}});import{EOL as go}from"os";var $=i({command:"skill",describe:"list all available skills",builder:(o)=>o,async handler(){await n(process.cwd(),async()=>{let o=await r.runPromise(d.gen(function*(){return yield*(yield*R.Service).all()}));process.stdout.write(JSON.stringify(o,null,2)+go)})}});var j=i({command:"snapshot",describe:"snapshot debugging utilities",builder:(o)=>o.command(bo).command(wo).command(So).demandCommand(),async handler(){}}),D=(o)=>n(process.cwd(),async()=>{console.log(await r.runPromise(M.Service.use(o)))}),G=(o)=>o.positional("hash",{type:"string",description:"hash",demandOption:!0}),bo=i({command:"track",describe:"track current snapshot state",async handler(){await D((o)=>o.track())}}),wo=i({command:"patch <hash>",describe:"show patch for a snapshot hash",builder:G,async handler(o){await D((e)=>e.patch(o.hash))}}),So=i({command:"diff <hash>",describe:"show diff for a snapshot hash",builder:G,async handler(o){await D((e)=>e.diff(o.hash))}});import{EOL as h}from"os";import{basename as ho}from"path";var Z=i({command:"agent <name>",describe:"show agent configuration details",builder:(o)=>o.positional("name",{type:"string",demandOption:!0,description:"Agent name"}).option("tool",{type:"string",description:"Tool id to execute"}).option("params",{type:"string",description:"Tool params as a JSON object"}),async handler(o){await n(process.cwd(),async()=>{let e=o.name,t=await r.runPromise(X.Service.use((m)=>m.get(e)));if(!t)process.stderr.write(`Agent ${e} not found, run '${ho(process.execPath)} agent list' to get an agent list`+h),process.exit(1);let s=await Co(t),a=await Oo(t,s),c=o.tool;if(c){let m=s.find((eo)=>eo.id===c);if(!m)process.stderr.write(`Tool ${c} not found for agent ${e}`+h),process.exit(1);if(a[c]===!1)process.stderr.write(`Tool ${c} is disabled for agent ${e}`+h),process.exit(1);let p=vo(o.params),f=await Po(t),N=await m.execute(p,f);process.stdout.write(JSON.stringify({tool:c,input:p,result:N},null,2)+h);return}let l={...t,tools:a};process.stdout.write(JSON.stringify(l,null,2)+h)})}});async function Co(o){return r.runPromise(d.gen(function*(){let e=yield*J.Service,t=yield*K.Service,s=o.model??(yield*e.defaultModel());return yield*t.tools({...s,agent:o})}))}async function Oo(o,e){let t=g.disabled(e.map((a)=>a.id),o.permission),s={};for(let a of e)s[a.id]=!t.has(a.id);return s}function vo(o){if(!o)return{};let e=o.trim();if(e.length===0)return{};let t=(()=>{try{return JSON.parse(e)}catch{throw Error("Failed to parse --params. Provide a valid JSON object.")}})();if(!t||typeof t!=="object"||Array.isArray(t))throw Error("Tool params must be an object.");return t}async function Po(o){let{session:e,messageID:t}=await r.runPromise(d.gen(function*(){let a=yield*Y.Service,c=yield*a.create({title:`Debug tool run (${o.name})`}),l=V.ascending(),m=o.model?o.model:yield*d.gen(function*(){return yield*(yield*J.Service).defaultModel()}),p=Date.now(),f={id:l,sessionID:c.id,role:"assistant",time:{created:p},parentID:l,modelID:m.modelID,providerID:m.providerID,mode:"debug",agent:o.name,path:{cwd:u.directory,root:u.worktree},cost:0,tokens:{input:0,output:0,reasoning:0,cache:{read:0,write:0}}};return yield*a.updateMessage(f),{session:c,messageID:l}})),s=g.merge(o.permission,e.permission??[]);return{sessionID:e.id,messageID:t,callID:W.ascending(),agent:o.name,abort:new AbortController().signal,messages:[],metadata:()=>d.void,ask(a){return d.sync(()=>{for(let c of a.patterns)if(g.evaluate(a.permission,c,s).action==="deny")throw new g.DeniedError({ruleset:s})})}}}var Q=i({command:"worker-smoke",describe:"start the TUI background worker and verify it initialises",builder:(o)=>o.option("timeout",{type:"number",describe:"milliseconds to wait for the worker to answer",default:30000}),handler:async(o)=>{let e=typeof globalThis.QITQODE_WORKER_PATH<"u"?globalThis.QITQODE_WORKER_PATH:new URL("../tui/worker.ts",import.meta.url),t=H({[B]:"worker",[z]:_()}),s=new Worker(e,{env:t}),a=new Promise((m,p)=>{s.onerror=(f)=>{p(Error(`worker crashed during startup: ${f.message||String(f.error??"unknown error")}`))},s.addEventListener("close",()=>{p(Error("worker exited before answering ping"))})}),c=new Promise((m,p)=>{setTimeout(()=>p(Error(`worker did not answer ping within ${o.timeout}ms`)),o.timeout)}),l=U(s);try{let m=await Promise.race([l.call("ping",void 0),a,c]);if(m!=="pong")throw Error(`worker answered ping with unexpected reply: ${JSON.stringify(m)}`);console.log("worker initialised: ping ok"),process.exit(0)}catch(m){console.error(m instanceof Error?m.message:String(m)),process.exit(1)}}});var Be=i({command:"debug",describe:"debugging and troubleshooting tools",builder:(o)=>o.command(I).command(q).command(k).command(L).command(T).command($).command(j).command(Z).command(Q).command(Ao).command({command:"wait",describe:"wait indefinitely (for debugging)",async handler(){await n(process.cwd(),async()=>{await new Promise((e)=>setTimeout(e,86400000))})}}).demandCommand(),async handler(){}}),Ao=i({command:"paths",describe:"show global paths (data, config, cache, state)",handler(){for(let[o,e]of Object.entries(oo.Path))console.log(o.padEnd(10),e)}});export{Be as DebugCommand};
2
+ import{Ed as n}from"./chunk-0yjdatm6.js";import{Rd as i}from"./chunk-yajd975f.js";import{Zg as r}from"./chunk-wcx7hc2p.js";import{$g as y,Kh as K,Lh as X,ah as w,eh as R}from"./chunk-ehfxypks.js";import"./chunk-9rxyq6f9.js";import"./chunk-5az84brc.js";import"./chunk-94qhpkfx.js";import"./chunk-c1g8n10t.js";import"./chunk-a2dz9nqh.js";import"./chunk-vhe92p7a.js";import{Ok as g,ck as V,dk as W,gk as C,il as J,ok as M,tl as Y,ul as F}from"./chunk-a550vst5.js";import"./chunk-e374shb8.js";import{am as E,cm as u}from"./chunk-zcp0wx4j.js";import"./chunk-epa576pa.js";import"./chunk-y287zwkr.js";import"./chunk-7zc04q43.js";import"./chunk-vtw0wwch.js";import"./chunk-rk2bk4s7.js";import"./chunk-e586sjb0.js";import"./chunk-b50t4jc5.js";import"./chunk-zdzxsyxs.js";import"./chunk-xny5ecn0.js";import"./chunk-8d6e4jg7.js";import"./chunk-my3cswnp.js";import"./chunk-4mvg7jt1.js";import"./chunk-cqtkxwd8.js";import"./chunk-wf4x5cjc.js";import"./chunk-mswx4k75.js";import"./chunk-vqpfpmha.js";import"./chunk-vm1ek7yf.js";import"./chunk-fd7fmvyw.js";import"./chunk-1sfcxdbw.js";import"./chunk-bgng3rdj.js";import"./chunk-s77qktcn.js";import"./chunk-8v6x712g.js";import"./chunk-pfkm3j8g.js";import{Xr as U}from"./chunk-h2bmss2m.js";import"./chunk-ywdtp534.js";import"./chunk-03mbn7nj.js";import"./chunk-gr4bctqj.js";import"./chunk-732yr6qq.js";import"./chunk-73fz0cf4.js";import"./chunk-0cdtq1r3.js";import{Qs as z,Rs as B,Ss as _,Us as H}from"./chunk-xmjntwjc.js";import"./chunk-tj3rem3q.js";import{nt as S}from"./chunk-7q003wdd.js";import{Dt as oo}from"./chunk-cbmwhvxw.js";import"./chunk-9etpppyv.js";import"./chunk-9ea1n338.js";import"./chunk-ngvp6zc2.js";import"./chunk-1p6jjrea.js";import{oK as x,xH as d}from"./chunk-ks1cs80p.js";import"./chunk-a92hh67a.js";import"./chunk-qhnpq5gb.js";import{QO as v,RO as P}from"./chunk-f83wv08n.js";import{EOL as to}from"os";var I=i({command:"config",describe:"show resolved configuration",builder:(o)=>o,async handler(){await n(process.cwd(),async()=>{let o=await r.runPromise(F.Service.use((e)=>e.get()));process.stdout.write(JSON.stringify(o,null,2)+to)})}});import{EOL as b}from"os";var io=i({command:"search <query>",describe:"search files by query",builder:(o)=>o.positional("query",{type:"string",demandOption:!0,description:"Search query"}),async handler(o){await n(process.cwd(),async()=>{let e=await r.runPromise(w.Service.use((t)=>t.search({query:o.query})));process.stdout.write(e.join(b)+b)})}}),ro=i({command:"read <path>",describe:"read file contents as JSON",builder:(o)=>o.positional("path",{type:"string",demandOption:!0,description:"File path to read"}),async handler(o){await n(process.cwd(),async()=>{let e=await r.runPromise(w.Service.use((t)=>t.read(o.path)));process.stdout.write(JSON.stringify(e,null,2)+b)})}}),no=i({command:"status",describe:"show file status information",builder:(o)=>o,async handler(){await n(process.cwd(),async()=>{let o=await r.runPromise(w.Service.use((e)=>e.status()));process.stdout.write(JSON.stringify(o,null,2)+b)})}}),so=i({command:"list <path>",describe:"list files in a directory",builder:(o)=>o.positional("path",{type:"string",demandOption:!0,description:"File path to list"}),async handler(o){await n(process.cwd(),async()=>{let e=await r.runPromise(w.Service.use((t)=>t.list(o.path)));process.stdout.write(JSON.stringify(e,null,2)+b)})}}),mo=i({command:"tree [dir]",describe:"show directory tree",builder:(o)=>o.positional("dir",{type:"string",description:"Directory to tree",default:process.cwd()}),async handler(o){await n(process.cwd(),async()=>{let e=await r.runPromise(y.Service.use((t)=>t.tree({cwd:o.dir,limit:200})));console.log(JSON.stringify(e,null,2))})}}),L=i({command:"file",describe:"file system debugging utilities",builder:(o)=>o.command(ro).command(no).command(so).command(io).command(mo).demandCommand(),async handler(){}});import{EOL as A}from"os";var q=i({command:"lsp",describe:"LSP debugging utilities",builder:(o)=>o.command(ao).command(co).command(lo).demandCommand(),async handler(){}}),ao=i({command:"diagnostics <file>",describe:"get diagnostics for a file",builder:(o)=>o.positional("file",{type:"string",demandOption:!0}),async handler(o){await n(process.cwd(),async()=>{let e=await r.runPromise(C.Service.use((t)=>d.gen(function*(){return yield*t.touchFile(o.file,!0),yield*d.sleep(1000),yield*t.diagnostics()})));process.stdout.write(JSON.stringify(e,null,2)+A)})}}),co=i({command:"symbols <query>",describe:"search workspace symbols",builder:(o)=>o.positional("query",{type:"string",demandOption:!0}),async handler(o){await n(process.cwd(),async()=>{let s=[];try{const e=v(s,S.Default.time("symbols"),0);let t=await r.runPromise(C.Service.use((m)=>m.workspaceSymbol(o.query)));process.stdout.write(JSON.stringify(t,null,2)+A)}catch(a){var c=a,l=1}finally{P(s,c,l)}})}}),lo=i({command:"document-symbols <uri>",describe:"get symbols from a document",builder:(o)=>o.positional("uri",{type:"string",demandOption:!0}),async handler(o){await n(process.cwd(),async()=>{let s=[];try{const e=v(s,S.Default.time("document-symbols"),0);let t=await r.runPromise(C.Service.use((m)=>m.documentSymbol(o.uri)));process.stdout.write(JSON.stringify(t,null,2)+A)}catch(a){var c=a,l=1}finally{P(s,c,l)}})}});import{EOL as O}from"os";var k=i({command:"rg",describe:"ripgrep debugging utilities",builder:(o)=>o.command(po).command(uo).command(fo).demandCommand(),async handler(){}}),po=i({command:"tree",describe:"show file tree using ripgrep",builder:(o)=>o.option("limit",{type:"number"}),async handler(o){await n(process.cwd(),async()=>{let e=await r.runPromise(y.Service.use((t)=>t.tree({cwd:u.directory,limit:o.limit})));process.stdout.write(e+O)})}}),uo=i({command:"files",describe:"list files using ripgrep",builder:(o)=>o.option("query",{type:"string",description:"Filter files by query"}).option("glob",{type:"string",description:"Glob pattern to match files"}).option("limit",{type:"number",description:"Limit number of results"}),async handler(o){await n(process.cwd(),async()=>{let e=await r.runPromise(d.gen(function*(){return yield*(yield*y.Service).files({cwd:u.directory,glob:o.glob?[o.glob]:void 0}).pipe(x.take(o.limit??1/0),x.runCollect,d.map((s)=>[...s]))}));process.stdout.write(e.join(O)+O)})}}),fo=i({command:"search <pattern>",describe:"search file contents using ripgrep",builder:(o)=>o.positional("pattern",{type:"string",demandOption:!0,description:"Search pattern"}).option("glob",{type:"array",description:"File glob patterns"}).option("limit",{type:"number",description:"Limit number of results"}),async handler(o){await n(process.cwd(),async()=>{let e=await r.runPromise(y.Service.use((t)=>t.search({cwd:u.directory,pattern:o.pattern,glob:o.glob,limit:o.limit})));process.stdout.write(JSON.stringify(e.items,null,2)+O)})}});import{EOL as yo}from"os";var T=i({command:"scrap",describe:"list all known projects",builder:(o)=>o,async handler(){let o=S.Default.time("scrap"),e=await E.list();process.stdout.write(JSON.stringify(e,null,2)+yo),o.stop()}});import{EOL as go}from"os";var $=i({command:"skill",describe:"list all available skills",builder:(o)=>o,async handler(){await n(process.cwd(),async()=>{let o=await r.runPromise(d.gen(function*(){return yield*(yield*R.Service).all()}));process.stdout.write(JSON.stringify(o,null,2)+go)})}});var j=i({command:"snapshot",describe:"snapshot debugging utilities",builder:(o)=>o.command(bo).command(wo).command(So).demandCommand(),async handler(){}}),D=(o)=>n(process.cwd(),async()=>{console.log(await r.runPromise(M.Service.use(o)))}),G=(o)=>o.positional("hash",{type:"string",description:"hash",demandOption:!0}),bo=i({command:"track",describe:"track current snapshot state",async handler(){await D((o)=>o.track())}}),wo=i({command:"patch <hash>",describe:"show patch for a snapshot hash",builder:G,async handler(o){await D((e)=>e.patch(o.hash))}}),So=i({command:"diff <hash>",describe:"show diff for a snapshot hash",builder:G,async handler(o){await D((e)=>e.diff(o.hash))}});import{EOL as h}from"os";import{basename as ho}from"path";var Z=i({command:"agent <name>",describe:"show agent configuration details",builder:(o)=>o.positional("name",{type:"string",demandOption:!0,description:"Agent name"}).option("tool",{type:"string",description:"Tool id to execute"}).option("params",{type:"string",description:"Tool params as a JSON object"}),async handler(o){await n(process.cwd(),async()=>{let e=o.name,t=await r.runPromise(X.Service.use((m)=>m.get(e)));if(!t)process.stderr.write(`Agent ${e} not found, run '${ho(process.execPath)} agent list' to get an agent list`+h),process.exit(1);let s=await Co(t),a=await Oo(t,s),c=o.tool;if(c){let m=s.find((eo)=>eo.id===c);if(!m)process.stderr.write(`Tool ${c} not found for agent ${e}`+h),process.exit(1);if(a[c]===!1)process.stderr.write(`Tool ${c} is disabled for agent ${e}`+h),process.exit(1);let p=vo(o.params),f=await Po(t),N=await m.execute(p,f);process.stdout.write(JSON.stringify({tool:c,input:p,result:N},null,2)+h);return}let l={...t,tools:a};process.stdout.write(JSON.stringify(l,null,2)+h)})}});async function Co(o){return r.runPromise(d.gen(function*(){let e=yield*J.Service,t=yield*K.Service,s=o.model??(yield*e.defaultModel());return yield*t.tools({...s,agent:o})}))}async function Oo(o,e){let t=g.disabled(e.map((a)=>a.id),o.permission),s={};for(let a of e)s[a.id]=!t.has(a.id);return s}function vo(o){if(!o)return{};let e=o.trim();if(e.length===0)return{};let t=(()=>{try{return JSON.parse(e)}catch{throw Error("Failed to parse --params. Provide a valid JSON object.")}})();if(!t||typeof t!=="object"||Array.isArray(t))throw Error("Tool params must be an object.");return t}async function Po(o){let{session:e,messageID:t}=await r.runPromise(d.gen(function*(){let a=yield*Y.Service,c=yield*a.create({title:`Debug tool run (${o.name})`}),l=V.ascending(),m=o.model?o.model:yield*d.gen(function*(){return yield*(yield*J.Service).defaultModel()}),p=Date.now(),f={id:l,sessionID:c.id,role:"assistant",time:{created:p},parentID:l,modelID:m.modelID,providerID:m.providerID,mode:"debug",agent:o.name,path:{cwd:u.directory,root:u.worktree},cost:0,tokens:{input:0,output:0,reasoning:0,cache:{read:0,write:0}}};return yield*a.updateMessage(f),{session:c,messageID:l}})),s=g.merge(o.permission,e.permission??[]);return{sessionID:e.id,messageID:t,callID:W.ascending(),agent:o.name,abort:new AbortController().signal,messages:[],metadata:()=>d.void,ask(a){return d.sync(()=>{for(let c of a.patterns)if(g.evaluate(a.permission,c,s).action==="deny")throw new g.DeniedError({ruleset:s})})}}}var Q=i({command:"worker-smoke",describe:"start the TUI background worker and verify it initialises",builder:(o)=>o.option("timeout",{type:"number",describe:"milliseconds to wait for the worker to answer",default:30000}),handler:async(o)=>{let e=typeof globalThis.QITQODE_WORKER_PATH<"u"?globalThis.QITQODE_WORKER_PATH:new URL("../tui/worker.ts",import.meta.url),t=H({[B]:"worker",[z]:_()}),s=new Worker(e,{env:t}),a=new Promise((m,p)=>{s.onerror=(f)=>{p(Error(`worker crashed during startup: ${f.message||String(f.error??"unknown error")}`))},s.addEventListener("close",()=>{p(Error("worker exited before answering ping"))})}),c=new Promise((m,p)=>{setTimeout(()=>p(Error(`worker did not answer ping within ${o.timeout}ms`)),o.timeout)}),l=U(s);try{let m=await Promise.race([l.call("ping",void 0),a,c]);if(m!=="pong")throw Error(`worker answered ping with unexpected reply: ${JSON.stringify(m)}`);console.log("worker initialised: ping ok"),process.exit(0)}catch(m){console.error(m instanceof Error?m.message:String(m)),process.exit(1)}}});var Be=i({command:"debug",describe:"debugging and troubleshooting tools",builder:(o)=>o.command(I).command(q).command(k).command(L).command(T).command($).command(j).command(Z).command(Q).command(Ao).command({command:"wait",describe:"wait indefinitely (for debugging)",async handler(){await n(process.cwd(),async()=>{await new Promise((e)=>setTimeout(e,86400000))})}}).demandCommand(),async handler(){}}),Ao=i({command:"paths",describe:"show global paths (data, config, cache, state)",handler(){for(let[o,e]of Object.entries(oo.Path))console.log(o.padEnd(10),e)}});export{Be as DebugCommand};
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{Fd as y,Hd as T,Id as t,Jd as O,Kd as l,Md as v,Nd as Q,Od as X,Pd as J}from"./chunk-p9mj4zyk.js";import"./chunk-ta7mfkms.js";import{Rd as w}from"./chunk-yajd975f.js";import{Uf as f}from"./chunk-t1jgx17a.js";import{Dg as Y,Eg as mt,Fg as pt,Gg as st,Hg as et,Ig as ft,Jg as E,Zg as q}from"./chunk-3kn57y8d.js";import{uh as Mt}from"./chunk-nb86kh94.js";import"./chunk-9rxyq6f9.js";import"./chunk-5az84brc.js";import"./chunk-94qhpkfx.js";import"./chunk-c1g8n10t.js";import"./chunk-a2dz9nqh.js";import"./chunk-vhe92p7a.js";import{Nj as nt,Uj as L,ul as F}from"./chunk-kc1xmcc9.js";import"./chunk-jjjs8p0t.js";import{cm as $}from"./chunk-xnhvt98g.js";import"./chunk-hpa7e9va.js";import"./chunk-y287zwkr.js";import"./chunk-qeg0jnxq.js";import{Cn as P,Dn as h}from"./chunk-9eg2ytjd.js";import"./chunk-rk2bk4s7.js";import"./chunk-e586sjb0.js";import"./chunk-b50t4jc5.js";import"./chunk-zdzxsyxs.js";import"./chunk-xny5ecn0.js";import"./chunk-7myg8076.js";import"./chunk-my3cswnp.js";import"./chunk-4mvg7jt1.js";import"./chunk-cqtkxwd8.js";import"./chunk-wf4x5cjc.js";import"./chunk-mswx4k75.js";import"./chunk-vqpfpmha.js";import"./chunk-vm1ek7yf.js";import"./chunk-fd7fmvyw.js";import"./chunk-1sfcxdbw.js";import"./chunk-bgng3rdj.js";import"./chunk-qkh8697x.js";import"./chunk-qg9bt0kx.js";import"./chunk-pfkm3j8g.js";import"./chunk-hmznf0ax.js";import"./chunk-qf1dqzra.js";import"./chunk-03mbn7nj.js";import"./chunk-gr4bctqj.js";import"./chunk-732yr6qq.js";import"./chunk-73fz0cf4.js";import"./chunk-9nn4jpb7.js";import{us as g}from"./chunk-sh76e256.js";import"./chunk-0z1cxvk1.js";import"./chunk-x3afqfww.js";import{Dt as A,yt as D}from"./chunk-cbmwhvxw.js";import"./chunk-9etpppyv.js";import"./chunk-9ea1n338.js";import"./chunk-ngvp6zc2.js";import"./chunk-1p6jjrea.js";import{xH as a}from"./chunk-ks1cs80p.js";import"./chunk-a92hh67a.js";import"./chunk-qhnpq5gb.js";import{LO as ut}from"./chunk-f83wv08n.js";import W from"path";function G(o){switch(o){case"authenticated":return"\u2713";case"expired":return"\u26A0";case"not_authenticated":return"\u2717"}}function H(o){switch(o){case"authenticated":return"authenticated";case"expired":return"expired";case"not_authenticated":return"not authenticated"}}function N(o){return typeof o==="object"&&o!==null&&"type"in o}function k(o){return N(o)&&o.type==="remote"}function B(o){return Object.entries(o.mcp??{}).filter((e)=>N(e[1]))}function U(o,e){let r=o.mcp_origins?.[e];if(!r)return"qitqode";let i=A.Path.home,m=r.source===i?"~":r.source.startsWith(i+W.sep)?"~"+r.source.slice(i.length):r.source;return`${r.type}:${m}`}function C(o){return B(o).filter((e)=>k(e[1])&&e[1].oauth!==!1)}async function I(){return q.runPromise(a.gen(function*(){let o=yield*F.Service,e=yield*E.Service,r=yield*o.get(),i=yield*e.status(),m=yield*a.all(Object.fromEntries(B(r).map(([p])=>[p,e.hasStoredTokens(p)])),{concurrency:"unbounded"});return{config:r,statuses:i,stored:m}}))}async function S(){return q.runPromise(a.gen(function*(){let o=yield*F.Service,e=yield*E.Service,r=yield*o.get(),i=yield*a.all(Object.fromEntries(C(r).map(([m])=>[m,e.getAuthStatus(m)])),{concurrency:"unbounded"});return{config:r,auth:i}}))}async function V(o,e=!1){let r=[W.join(o,"qitqode.json"),W.join(o,"qitqode.jsonc")];if(!e)r.push(W.join(o,".qitqode","qitqode.json"),W.join(o,".qitqode","qitqode.jsonc"));for(let i of r)if(await D.exists(i))return i;return r[0]}async function R(o,e,r){let i="{}";if(await D.exists(r))i=await D.readText(r);let m=P(i,["mcp",o],e,{formattingOptions:{tabSize:2,insertSpaces:!0}});return await D.write(r,h(i,m)),r}var tt=ut(Mt(),1);function yt(o){let e=tt.parse(o);if(!e.every((r)=>typeof r==="string"))throw Error("Shell operators are not supported; enter only the command and its arguments");if(e.length===0)throw Error("Command is required");return e}var ot=w({command:"add",describe:"add an MCP server",async handler(){await $.provide({directory:process.cwd(),async fn(){f.empty(),O("Add MCP server");let o=$.project,[e,r]=await Promise.all([V($.worktree),V(A.Path.config,!0)]),i=r;if(o.vcs==="git"){let c=await X({message:"Location",options:[{label:"Current project",value:e,hint:e},{label:"Global",value:r,hint:r}]});if(y(c))throw new f.CancelledError;i=c}let m=await J({message:"Enter MCP server name",validate:(c)=>c&&c.length>0?void 0:"Required"});if(y(m))throw new f.CancelledError;let p=await X({message:"Select MCP server type",options:[{label:"Local",value:"local",hint:"Run a local command"},{label:"Remote",value:"remote",hint:"Connect to a remote URL"}]});if(y(p))throw new f.CancelledError;if(p==="local"){let c=await J({message:"Enter command to run",placeholder:"e.g., qitqode x @modelcontextprotocol/server-filesystem",validate:(s)=>s&&s.length>0?void 0:"Required"});if(y(c))throw new f.CancelledError;let u;try{u=yt(c)}catch(s){t.error(s instanceof Error?s.message:"Invalid command"),l("MCP server was not added");return}await R(m,{type:"local",command:u},i),t.success(`MCP server "${m}" added to ${i}`),l("MCP server added successfully");return}if(p==="remote"){let c=await J({message:"Enter MCP server URL",placeholder:"e.g., https://example.com/mcp",validate:(s)=>{if(!s)return"Required";if(s.length===0)return"Required";return URL.canParse(s)?void 0:"Invalid URL"}});if(y(c))throw new f.CancelledError;let u=await T({message:"Does this server require OAuth authentication?",initialValue:!1});if(y(u))throw new f.CancelledError;let n;if(u){let s=await T({message:"Do you have a pre-registered client ID?",initialValue:!1});if(y(s))throw new f.CancelledError;if(s){let d=await J({message:"Enter client ID",validate:(j)=>j&&j.length>0?void 0:"Required"});if(y(d))throw new f.CancelledError;let M=await T({message:"Do you have a client secret?",initialValue:!1});if(y(M))throw new f.CancelledError;let _;if(M){let j=await v({message:"Enter client secret"});if(y(j))throw new f.CancelledError;_=j}n={type:"remote",url:c,oauth:{clientId:d,..._&&{clientSecret:_}}}}else n={type:"remote",url:c,oauth:{}}}else n={type:"remote",url:c,oauth:!1};await R(m,n,i),t.success(`MCP server "${m}" added to ${i}`)}l("MCP server added successfully")}})}});var it=w({command:"list",aliases:["ls"],describe:"list MCP servers and their status",async handler(){await $.provide({directory:process.cwd(),async fn(){f.empty(),O("MCP Servers");let{config:o,statuses:e,stored:r}=await I(),i=B(o);if(i.length===0){t.warn("No MCP servers configured"),l("Add servers with: qitqode mcp add");return}for(let[m,p]of i){let c=e[m],u=k(p)&&p.oauth!==!1,n=r[m],s,d,M="";if(!c)s="\u25CB",d="not initialized";else if(c.status==="connected"){if(s="\u2713",d="connected",u&&n)M=" (OAuth)"}else if(c.status==="disabled")s="\u25CB",d="disabled";else if(c.status==="pending")s="\u25CB",d="pending approval";else if(c.status==="needs_auth")s="\u26A0",d="needs authentication";else if(c.status==="needs_client_registration")s="\u2717",d="needs client registration",M=`
2
+ import{Fd as y,Hd as T,Id as t,Jd as O,Kd as l,Md as v,Nd as Q,Od as X,Pd as J}from"./chunk-p9mj4zyk.js";import"./chunk-ta7mfkms.js";import{Rd as w}from"./chunk-yajd975f.js";import{Uf as f}from"./chunk-t1jgx17a.js";import{Dg as Y,Eg as mt,Fg as pt,Gg as st,Hg as et,Ig as ft,Jg as E,Zg as q}from"./chunk-wcx7hc2p.js";import{uh as Mt}from"./chunk-ehfxypks.js";import"./chunk-9rxyq6f9.js";import"./chunk-5az84brc.js";import"./chunk-94qhpkfx.js";import"./chunk-c1g8n10t.js";import"./chunk-a2dz9nqh.js";import"./chunk-vhe92p7a.js";import{Nj as nt,Uj as L,ul as F}from"./chunk-a550vst5.js";import"./chunk-e374shb8.js";import{cm as $}from"./chunk-zcp0wx4j.js";import"./chunk-epa576pa.js";import"./chunk-y287zwkr.js";import"./chunk-7zc04q43.js";import{Cn as P,Dn as h}from"./chunk-vtw0wwch.js";import"./chunk-rk2bk4s7.js";import"./chunk-e586sjb0.js";import"./chunk-b50t4jc5.js";import"./chunk-zdzxsyxs.js";import"./chunk-xny5ecn0.js";import"./chunk-8d6e4jg7.js";import"./chunk-my3cswnp.js";import"./chunk-4mvg7jt1.js";import"./chunk-cqtkxwd8.js";import"./chunk-wf4x5cjc.js";import"./chunk-mswx4k75.js";import"./chunk-vqpfpmha.js";import"./chunk-vm1ek7yf.js";import"./chunk-fd7fmvyw.js";import"./chunk-1sfcxdbw.js";import"./chunk-bgng3rdj.js";import"./chunk-s77qktcn.js";import"./chunk-8v6x712g.js";import"./chunk-pfkm3j8g.js";import"./chunk-h2bmss2m.js";import"./chunk-ywdtp534.js";import"./chunk-03mbn7nj.js";import"./chunk-gr4bctqj.js";import"./chunk-732yr6qq.js";import"./chunk-73fz0cf4.js";import"./chunk-0cdtq1r3.js";import{us as g}from"./chunk-xmjntwjc.js";import"./chunk-tj3rem3q.js";import"./chunk-7q003wdd.js";import{Dt as A,yt as D}from"./chunk-cbmwhvxw.js";import"./chunk-9etpppyv.js";import"./chunk-9ea1n338.js";import"./chunk-ngvp6zc2.js";import"./chunk-1p6jjrea.js";import{xH as a}from"./chunk-ks1cs80p.js";import"./chunk-a92hh67a.js";import"./chunk-qhnpq5gb.js";import{LO as ut}from"./chunk-f83wv08n.js";import W from"path";function G(o){switch(o){case"authenticated":return"\u2713";case"expired":return"\u26A0";case"not_authenticated":return"\u2717"}}function H(o){switch(o){case"authenticated":return"authenticated";case"expired":return"expired";case"not_authenticated":return"not authenticated"}}function N(o){return typeof o==="object"&&o!==null&&"type"in o}function k(o){return N(o)&&o.type==="remote"}function B(o){return Object.entries(o.mcp??{}).filter((e)=>N(e[1]))}function U(o,e){let r=o.mcp_origins?.[e];if(!r)return"qitqode";let i=A.Path.home,m=r.source===i?"~":r.source.startsWith(i+W.sep)?"~"+r.source.slice(i.length):r.source;return`${r.type}:${m}`}function C(o){return B(o).filter((e)=>k(e[1])&&e[1].oauth!==!1)}async function I(){return q.runPromise(a.gen(function*(){let o=yield*F.Service,e=yield*E.Service,r=yield*o.get(),i=yield*e.status(),m=yield*a.all(Object.fromEntries(B(r).map(([p])=>[p,e.hasStoredTokens(p)])),{concurrency:"unbounded"});return{config:r,statuses:i,stored:m}}))}async function S(){return q.runPromise(a.gen(function*(){let o=yield*F.Service,e=yield*E.Service,r=yield*o.get(),i=yield*a.all(Object.fromEntries(C(r).map(([m])=>[m,e.getAuthStatus(m)])),{concurrency:"unbounded"});return{config:r,auth:i}}))}async function V(o,e=!1){let r=[W.join(o,"qitqode.json"),W.join(o,"qitqode.jsonc")];if(!e)r.push(W.join(o,".qitqode","qitqode.json"),W.join(o,".qitqode","qitqode.jsonc"));for(let i of r)if(await D.exists(i))return i;return r[0]}async function R(o,e,r){let i="{}";if(await D.exists(r))i=await D.readText(r);let m=P(i,["mcp",o],e,{formattingOptions:{tabSize:2,insertSpaces:!0}});return await D.write(r,h(i,m)),r}var tt=ut(Mt(),1);function yt(o){let e=tt.parse(o);if(!e.every((r)=>typeof r==="string"))throw Error("Shell operators are not supported; enter only the command and its arguments");if(e.length===0)throw Error("Command is required");return e}var ot=w({command:"add",describe:"add an MCP server",async handler(){await $.provide({directory:process.cwd(),async fn(){f.empty(),O("Add MCP server");let o=$.project,[e,r]=await Promise.all([V($.worktree),V(A.Path.config,!0)]),i=r;if(o.vcs==="git"){let c=await X({message:"Location",options:[{label:"Current project",value:e,hint:e},{label:"Global",value:r,hint:r}]});if(y(c))throw new f.CancelledError;i=c}let m=await J({message:"Enter MCP server name",validate:(c)=>c&&c.length>0?void 0:"Required"});if(y(m))throw new f.CancelledError;let p=await X({message:"Select MCP server type",options:[{label:"Local",value:"local",hint:"Run a local command"},{label:"Remote",value:"remote",hint:"Connect to a remote URL"}]});if(y(p))throw new f.CancelledError;if(p==="local"){let c=await J({message:"Enter command to run",placeholder:"e.g., qitqode x @modelcontextprotocol/server-filesystem",validate:(s)=>s&&s.length>0?void 0:"Required"});if(y(c))throw new f.CancelledError;let u;try{u=yt(c)}catch(s){t.error(s instanceof Error?s.message:"Invalid command"),l("MCP server was not added");return}await R(m,{type:"local",command:u},i),t.success(`MCP server "${m}" added to ${i}`),l("MCP server added successfully");return}if(p==="remote"){let c=await J({message:"Enter MCP server URL",placeholder:"e.g., https://example.com/mcp",validate:(s)=>{if(!s)return"Required";if(s.length===0)return"Required";return URL.canParse(s)?void 0:"Invalid URL"}});if(y(c))throw new f.CancelledError;let u=await T({message:"Does this server require OAuth authentication?",initialValue:!1});if(y(u))throw new f.CancelledError;let n;if(u){let s=await T({message:"Do you have a pre-registered client ID?",initialValue:!1});if(y(s))throw new f.CancelledError;if(s){let d=await J({message:"Enter client ID",validate:(j)=>j&&j.length>0?void 0:"Required"});if(y(d))throw new f.CancelledError;let M=await T({message:"Do you have a client secret?",initialValue:!1});if(y(M))throw new f.CancelledError;let _;if(M){let j=await v({message:"Enter client secret"});if(y(j))throw new f.CancelledError;_=j}n={type:"remote",url:c,oauth:{clientId:d,..._&&{clientSecret:_}}}}else n={type:"remote",url:c,oauth:{}}}else n={type:"remote",url:c,oauth:!1};await R(m,n,i),t.success(`MCP server "${m}" added to ${i}`)}l("MCP server added successfully")}})}});var it=w({command:"list",aliases:["ls"],describe:"list MCP servers and their status",async handler(){await $.provide({directory:process.cwd(),async fn(){f.empty(),O("MCP Servers");let{config:o,statuses:e,stored:r}=await I(),i=B(o);if(i.length===0){t.warn("No MCP servers configured"),l("Add servers with: qitqode mcp add");return}for(let[m,p]of i){let c=e[m],u=k(p)&&p.oauth!==!1,n=r[m],s,d,M="";if(!c)s="\u25CB",d="not initialized";else if(c.status==="connected"){if(s="\u2713",d="connected",u&&n)M=" (OAuth)"}else if(c.status==="disabled")s="\u25CB",d="disabled";else if(c.status==="pending")s="\u25CB",d="pending approval";else if(c.status==="needs_auth")s="\u26A0",d="needs authentication";else if(c.status==="needs_client_registration")s="\u2717",d="needs client registration",M=`
3
3
  `+c.error;else s="\u2717",d="failed",M=`
4
4
  `+c.error;let _=p.type==="remote"?L.redactString(p.url):L.redactCommand(p.command).join(" ");t.info(`${s} ${m} ${f.Style.TEXT_DIM}${d} ${U(o,m)}${M}
5
5
  ${f.Style.TEXT_DIM}${_}`)}l(`${i.length} server(s)`)}})}});var dt=w({command:"auth [name]",describe:"authenticate with an OAuth-enabled MCP server",builder:(o)=>o.positional("name",{describe:"name of the MCP server",type:"string"}).command(ct),async handler(o){await $.provide({directory:process.cwd(),async fn(){f.empty(),O("MCP OAuth Authentication");let{config:e,auth:r}=await S(),i=e.mcp??{},m=C(e);if(m.length===0){t.warn("No OAuth-capable MCP servers configured"),t.info("Remote MCP servers support OAuth by default. Add a remote server in qitqode.json:"),t.info(`
@@ -1,3 +1,3 @@
1
1
  // @bun
2
- import{M as o,O as s}from"./chunk-wcqfr8vr.js";import{P as i}from"./chunk-vjx0064q.js";import{Ed as p}from"./chunk-v7mg632n.js";import{Rd as n}from"./chunk-yajd975f.js";import{Uf as B}from"./chunk-t1jgx17a.js";import{$f as l}from"./chunk-q9ft590w.js";import"./chunk-knh01n2r.js";import"./chunk-jgtcfw96.js";import"./chunk-dknemkw2.js";import"./chunk-bhetpmgq.js";import"./chunk-nfg7nt13.js";import"./chunk-rcyzqa3g.js";import"./chunk-xjpvv3vp.js";import{Zg as g}from"./chunk-3kn57y8d.js";import{Lh as d}from"./chunk-nb86kh94.js";import"./chunk-9rxyq6f9.js";import"./chunk-5az84brc.js";import"./chunk-94qhpkfx.js";import"./chunk-c1g8n10t.js";import"./chunk-a2dz9nqh.js";import"./chunk-vhe92p7a.js";import{il as f}from"./chunk-kc1xmcc9.js";import"./chunk-jjjs8p0t.js";import"./chunk-xnhvt98g.js";import"./chunk-hpa7e9va.js";import"./chunk-y287zwkr.js";import"./chunk-qeg0jnxq.js";import"./chunk-9eg2ytjd.js";import"./chunk-rk2bk4s7.js";import"./chunk-e586sjb0.js";import"./chunk-b50t4jc5.js";import"./chunk-zdzxsyxs.js";import"./chunk-xny5ecn0.js";import{ro as D}from"./chunk-7myg8076.js";import"./chunk-my3cswnp.js";import"./chunk-4mvg7jt1.js";import"./chunk-cqtkxwd8.js";import"./chunk-wf4x5cjc.js";import"./chunk-mswx4k75.js";import"./chunk-vqpfpmha.js";import"./chunk-vm1ek7yf.js";import"./chunk-fd7fmvyw.js";import"./chunk-1sfcxdbw.js";import"./chunk-bgng3rdj.js";import"./chunk-qkh8697x.js";import"./chunk-qg9bt0kx.js";import"./chunk-pfkm3j8g.js";import{Vr as I}from"./chunk-hmznf0ax.js";import"./chunk-qf1dqzra.js";import"./chunk-03mbn7nj.js";import"./chunk-gr4bctqj.js";import"./chunk-732yr6qq.js";import"./chunk-73fz0cf4.js";import"./chunk-9nn4jpb7.js";import"./chunk-sh76e256.js";import"./chunk-0z1cxvk1.js";import{et as u,nt as x}from"./chunk-x3afqfww.js";import{yt as y}from"./chunk-cbmwhvxw.js";import"./chunk-9etpppyv.js";import"./chunk-9ea1n338.js";import"./chunk-ngvp6zc2.js";import"./chunk-1p6jjrea.js";import"./chunk-ks1cs80p.js";import"./chunk-a92hh67a.js";import"./chunk-qhnpq5gb.js";import"./chunk-f83wv08n.js";import T from"path";import{pathToFileURL as jj}from"url";import{EOL as Q}from"os";function $(j){let K=j.state;return{input:K.input,metadata:"metadata"in K?K.metadata:{},part:j}}function z(j){let K=j.description?B.Style.TEXT_DIM+` ${j.description}`+B.Style.TEXT_NORMAL:"";B.println(B.Style.TEXT_NORMAL+j.icon,B.Style.TEXT_NORMAL+j.title+K)}function b(j,K){if(B.empty(),z(j),!K?.trim())return;B.println(K),B.empty()}function U(j){let K=j.state,V="input"in K?K.input:void 0,Y=("title"in K&&K.title?K.title:void 0)||(V&&typeof V==="object"&&Object.keys(V).length>0?JSON.stringify(V):"Unknown");z({icon:"\u2699",title:`${j.tool} ${Y}`})}function t(j){let K=j.path??"",V=`${j.kind} "${j.pattern}"`,Y=K?`in ${q(K)}`:"",H=j.count===void 0?Y:`${Y}${Y?" \xB7 ":""}${j.count} ${j.count===1?"match":"matches"}`;z({icon:"\u2731",title:V,...H&&{description:H}})}function Bj(j){t({kind:"Glob",pattern:j.input.pattern,path:j.input.path,count:j.metadata.count})}function Gj(j){t({kind:"Grep",pattern:j.input.pattern,path:j.input.path,count:j.metadata.matches})}function Jj(j){let K=q(j.input.filePath),V=Object.entries(j.input).filter(([H,S])=>{if(H==="filePath")return!1;return typeof S==="string"||typeof S==="number"||typeof S==="boolean"}),Y=V.length?`[${V.map(([H,S])=>`${H}=${S}`).join(", ")}]`:void 0;z({icon:"\u2192",title:`Read ${K}`,...Y&&{description:Y}})}function Kj(j){b({icon:"\u2190",title:`Write ${q(j.input.filePath)}`},j.part.state.status==="completed"?j.part.state.output:void 0)}function Mj(j){z({icon:"%",title:`WebFetch ${j.input.url}`})}function Nj(j){let K=q(j.input.filePath),V=j.metadata.diff;b({icon:"\u2190",title:`Edit ${K}`},V)}function Vj(j){z({icon:"\u25C7",title:`Exa Code Search "${j.input.query}"`})}function Xj(j){z({icon:"\u25C8",title:`Web Search "${j.input.query}"`})}function k(j){let K=j.part.state.input?.operation??j.part.state.input,V=j.part.state.status,Y=typeof K?.subagent_type==="string"&&K.subagent_type.trim().length>0?K.subagent_type:"unknown",H=I.titlecase(Y),S=typeof K?.description==="string"&&K.description.trim().length>0?K.description:void 0,w=V==="error"?"\u2717":V==="running"?"\u2022":"\u2713",L=S??`${H} Task`;z({icon:w,title:L,description:S?`${H} Agent`:void 0})}function Yj(j){z({icon:"\u2192",title:`Skill "${j.input.name}"`})}function Zj(j){let K=j.part.state.status==="completed"?j.part.state.output?.trim():void 0;b({icon:"$",title:`${j.input.command}`},K)}function q(j){if(!j)return"";if(T.isAbsolute(j))return T.relative(process.cwd(),j)||".";return j}var Pj=n({command:"run [message..]",describe:"run qitqode with a message",builder:(j)=>{return j.positional("message",{describe:"message to send",type:"string",array:!0,default:[]}).option("command",{describe:"the command to run, use message for args",type:"string"}).option("continue",{alias:["c"],describe:"continue the last session",type:"boolean"}).option("session",{alias:["s"],describe:"session id to continue",type:"string"}).option("fork",{describe:"fork the session before continuing (requires --continue or --session)",type:"boolean"}).option("share",{type:"boolean",describe:"share the session"}).option("model",{type:"string",alias:["m"],describe:"model to use in the format of provider/model"}).option("agent",{type:"string",describe:"agent to use"}).option("format",{type:"string",choices:["default","json"],default:"default",describe:"format: default (formatted) or json (raw JSON events)"}).option("file",{alias:["f"],type:"string",array:!0,describe:"file(s) to attach to message"}).option("title",{type:"string",describe:"title for the session (uses truncated prompt if no value provided)"}).option("attach",{type:"string",describe:"attach to a running qitqode server (e.g., http://localhost:4096)"}).option("password",{alias:["p"],type:"string",describe:"basic auth password (defaults to QITQODE_SERVER_PASSWORD)"}).option("dir",{type:"string",describe:"directory to run in, path on remote server if attaching"}).option("port",{type:"number",describe:"port for the local server (defaults to random port if no value provided)"}).option("variant",{type:"string",describe:"model variant (provider-specific reasoning effort, e.g., high, max, minimal)"}).option("thinking",{type:"boolean",describe:"show thinking blocks",default:!1}).option("dangerously-skip-permissions",{type:"boolean",describe:"auto-approve permissions that are not explicitly denied (dangerous!)",default:!1})},handler:async(j)=>{let K=[...j.message,...j["--"]||[]].join(" "),V=(()=>{if(!j.dir)return;if(j.attach)return j.dir;try{return process.chdir(j.dir),process.cwd()}catch{B.error("Failed to change directory to "+j.dir),process.exit(1)}})(),Y=[];if(j.file){let M=Array.isArray(j.file)?j.file:[j.file];for(let X of M){let N=T.resolve(process.cwd(),X);if(!await y.exists(N))B.error(`File not found: ${X}`),process.exit(1);let W=await y.isDir(N)?"application/x-directory":"text/plain";Y.push({type:"file",url:jj(N).href,filename:T.basename(N),mime:W})}}if(!process.stdin.isTTY)K+=`
2
+ import{M as o,O as s}from"./chunk-wcqfr8vr.js";import{P as i}from"./chunk-w30b563s.js";import{Ed as p}from"./chunk-0yjdatm6.js";import{Rd as n}from"./chunk-yajd975f.js";import{Uf as B}from"./chunk-t1jgx17a.js";import{$f as l}from"./chunk-7ab3yw9j.js";import"./chunk-et5dnymk.js";import"./chunk-dbztxdea.js";import"./chunk-543pt030.js";import"./chunk-bhetpmgq.js";import"./chunk-nfg7nt13.js";import"./chunk-rcyzqa3g.js";import"./chunk-h10wjk96.js";import{Zg as g}from"./chunk-wcx7hc2p.js";import{Lh as d}from"./chunk-ehfxypks.js";import"./chunk-9rxyq6f9.js";import"./chunk-5az84brc.js";import"./chunk-94qhpkfx.js";import"./chunk-c1g8n10t.js";import"./chunk-a2dz9nqh.js";import"./chunk-vhe92p7a.js";import{il as f}from"./chunk-a550vst5.js";import"./chunk-e374shb8.js";import"./chunk-zcp0wx4j.js";import"./chunk-epa576pa.js";import"./chunk-y287zwkr.js";import"./chunk-7zc04q43.js";import"./chunk-vtw0wwch.js";import"./chunk-rk2bk4s7.js";import"./chunk-e586sjb0.js";import"./chunk-b50t4jc5.js";import"./chunk-zdzxsyxs.js";import"./chunk-xny5ecn0.js";import{ro as D}from"./chunk-8d6e4jg7.js";import"./chunk-my3cswnp.js";import"./chunk-4mvg7jt1.js";import"./chunk-cqtkxwd8.js";import"./chunk-wf4x5cjc.js";import"./chunk-mswx4k75.js";import"./chunk-vqpfpmha.js";import"./chunk-vm1ek7yf.js";import"./chunk-fd7fmvyw.js";import"./chunk-1sfcxdbw.js";import"./chunk-bgng3rdj.js";import"./chunk-s77qktcn.js";import"./chunk-8v6x712g.js";import"./chunk-pfkm3j8g.js";import{Vr as I}from"./chunk-h2bmss2m.js";import"./chunk-ywdtp534.js";import"./chunk-03mbn7nj.js";import"./chunk-gr4bctqj.js";import"./chunk-732yr6qq.js";import"./chunk-73fz0cf4.js";import"./chunk-0cdtq1r3.js";import"./chunk-xmjntwjc.js";import"./chunk-tj3rem3q.js";import{et as u,nt as x}from"./chunk-7q003wdd.js";import{yt as y}from"./chunk-cbmwhvxw.js";import"./chunk-9etpppyv.js";import"./chunk-9ea1n338.js";import"./chunk-ngvp6zc2.js";import"./chunk-1p6jjrea.js";import"./chunk-ks1cs80p.js";import"./chunk-a92hh67a.js";import"./chunk-qhnpq5gb.js";import"./chunk-f83wv08n.js";import T from"path";import{pathToFileURL as jj}from"url";import{EOL as Q}from"os";function $(j){let K=j.state;return{input:K.input,metadata:"metadata"in K?K.metadata:{},part:j}}function z(j){let K=j.description?B.Style.TEXT_DIM+` ${j.description}`+B.Style.TEXT_NORMAL:"";B.println(B.Style.TEXT_NORMAL+j.icon,B.Style.TEXT_NORMAL+j.title+K)}function b(j,K){if(B.empty(),z(j),!K?.trim())return;B.println(K),B.empty()}function U(j){let K=j.state,V="input"in K?K.input:void 0,Y=("title"in K&&K.title?K.title:void 0)||(V&&typeof V==="object"&&Object.keys(V).length>0?JSON.stringify(V):"Unknown");z({icon:"\u2699",title:`${j.tool} ${Y}`})}function t(j){let K=j.path??"",V=`${j.kind} "${j.pattern}"`,Y=K?`in ${q(K)}`:"",H=j.count===void 0?Y:`${Y}${Y?" \xB7 ":""}${j.count} ${j.count===1?"match":"matches"}`;z({icon:"\u2731",title:V,...H&&{description:H}})}function Bj(j){t({kind:"Glob",pattern:j.input.pattern,path:j.input.path,count:j.metadata.count})}function Gj(j){t({kind:"Grep",pattern:j.input.pattern,path:j.input.path,count:j.metadata.matches})}function Jj(j){let K=q(j.input.filePath),V=Object.entries(j.input).filter(([H,S])=>{if(H==="filePath")return!1;return typeof S==="string"||typeof S==="number"||typeof S==="boolean"}),Y=V.length?`[${V.map(([H,S])=>`${H}=${S}`).join(", ")}]`:void 0;z({icon:"\u2192",title:`Read ${K}`,...Y&&{description:Y}})}function Kj(j){b({icon:"\u2190",title:`Write ${q(j.input.filePath)}`},j.part.state.status==="completed"?j.part.state.output:void 0)}function Mj(j){z({icon:"%",title:`WebFetch ${j.input.url}`})}function Nj(j){let K=q(j.input.filePath),V=j.metadata.diff;b({icon:"\u2190",title:`Edit ${K}`},V)}function Vj(j){z({icon:"\u25C7",title:`Exa Code Search "${j.input.query}"`})}function Xj(j){z({icon:"\u25C8",title:`Web Search "${j.input.query}"`})}function k(j){let K=j.part.state.input?.operation??j.part.state.input,V=j.part.state.status,Y=typeof K?.subagent_type==="string"&&K.subagent_type.trim().length>0?K.subagent_type:"unknown",H=I.titlecase(Y),S=typeof K?.description==="string"&&K.description.trim().length>0?K.description:void 0,w=V==="error"?"\u2717":V==="running"?"\u2022":"\u2713",L=S??`${H} Task`;z({icon:w,title:L,description:S?`${H} Agent`:void 0})}function Yj(j){z({icon:"\u2192",title:`Skill "${j.input.name}"`})}function Zj(j){let K=j.part.state.status==="completed"?j.part.state.output?.trim():void 0;b({icon:"$",title:`${j.input.command}`},K)}function q(j){if(!j)return"";if(T.isAbsolute(j))return T.relative(process.cwd(),j)||".";return j}var Pj=n({command:"run [message..]",describe:"run qitqode with a message",builder:(j)=>{return j.positional("message",{describe:"message to send",type:"string",array:!0,default:[]}).option("command",{describe:"the command to run, use message for args",type:"string"}).option("continue",{alias:["c"],describe:"continue the last session",type:"boolean"}).option("session",{alias:["s"],describe:"session id to continue",type:"string"}).option("fork",{describe:"fork the session before continuing (requires --continue or --session)",type:"boolean"}).option("share",{type:"boolean",describe:"share the session"}).option("model",{type:"string",alias:["m"],describe:"model to use in the format of provider/model"}).option("agent",{type:"string",describe:"agent to use"}).option("format",{type:"string",choices:["default","json"],default:"default",describe:"format: default (formatted) or json (raw JSON events)"}).option("file",{alias:["f"],type:"string",array:!0,describe:"file(s) to attach to message"}).option("title",{type:"string",describe:"title for the session (uses truncated prompt if no value provided)"}).option("attach",{type:"string",describe:"attach to a running qitqode server (e.g., http://localhost:4096)"}).option("password",{alias:["p"],type:"string",describe:"basic auth password (defaults to QITQODE_SERVER_PASSWORD)"}).option("dir",{type:"string",describe:"directory to run in, path on remote server if attaching"}).option("port",{type:"number",describe:"port for the local server (defaults to random port if no value provided)"}).option("variant",{type:"string",describe:"model variant (provider-specific reasoning effort, e.g., high, max, minimal)"}).option("thinking",{type:"boolean",describe:"show thinking blocks",default:!1}).option("dangerously-skip-permissions",{type:"boolean",describe:"auto-approve permissions that are not explicitly denied (dangerous!)",default:!1})},handler:async(j)=>{let K=[...j.message,...j["--"]||[]].join(" "),V=(()=>{if(!j.dir)return;if(j.attach)return j.dir;try{return process.chdir(j.dir),process.cwd()}catch{B.error("Failed to change directory to "+j.dir),process.exit(1)}})(),Y=[];if(j.file){let M=Array.isArray(j.file)?j.file:[j.file];for(let X of M){let N=T.resolve(process.cwd(),X);if(!await y.exists(N))B.error(`File not found: ${X}`),process.exit(1);let W=await y.isDir(N)?"application/x-directory":"text/plain";Y.push({type:"file",url:jj(N).href,filename:T.basename(N),mime:W})}}if(!process.stdin.isTTY)K+=`
3
3
  `+await Bun.stdin.text();if(K.trim().length===0&&!j.command)B.error("You must provide a message or a command"),process.exit(1);if(j.fork&&!j.continue&&!j.session)B.error("--fork requires --continue or --session"),process.exit(1);let H=[{permission:"question",action:"deny",pattern:"*"},{permission:"plan_enter",action:"deny",pattern:"*"},{permission:"plan_exit",action:"deny",pattern:"*"}];function S(){if(j.title===void 0)return;if(j.title!=="")return j.title;return K.slice(0,50)+(K.length>50?"...":"")}async function w(M){let X=j.continue?(await M.session.list()).data?.find((Z)=>!Z.parentID)?.id:j.session;if(X&&j.fork)return(await M.session.fork({sessionID:X})).data?.id;if(X)return X;let N=S();return(await M.session.create({title:N,permission:H})).data?.id}async function L(M,X){let N=await M.config.get();if(!N.data)return;if(N.data.share!=="auto"&&!u.QITQODE_AUTO_SHARE&&!j.share)return;let W=await M.session.share({sessionID:X}).catch((Z)=>{if(Z instanceof Error&&Z.message.includes("disabled"))B.println(B.Style.TEXT_DANGER_BOLD+"! "+Z.message);return{error:Z}});if(!W.error&&"data"in W&&W.data?.share?.url)B.println(B.Style.TEXT_INFO_BOLD+"~ "+W.data.share.url)}async function h(M){function X(G){try{if(G.tool==="bash")return Zj($(G));if(G.tool==="glob")return Bj($(G));if(G.tool==="grep")return Gj($(G));if(G.tool==="read")return Jj($(G));if(G.tool==="write")return Kj($(G));if(G.tool==="webfetch")return Mj($(G));if(G.tool==="edit")return Nj($(G));if(G.tool==="codesearch")return Vj($(G));if(G.tool==="websearch")return Xj($(G));if(G.tool==="actor")return k($(G));if(G.tool==="skill")return Yj($(G));return U(G)}catch{return U(G)}}function N(G,A){if(j.format==="json")return process.stdout.write(JSON.stringify({type:G,timestamp:Date.now(),sessionID:C,...A})+Q),!0;return!1}let W=await M.event.subscribe(),Z;async function e(G){let A=new Map,E=x.create({service:"cli.run"}),F=W.stream[Symbol.asyncIterator](),O=G.completion.then(()=>"DONE");try{while(!0){let P=await Promise.race([F.next(),O]);if(P==="DONE")break;if(P.done)break;let _=P.value;if(G.onEvent(_),E.debug("event received",{type:_.type}),_.type==="message.updated"&&_.properties.info.role==="assistant"&&j.format!=="json"&&A.get("start")!==!0)B.empty(),B.println(`> ${_.properties.info.agent} \xB7 ${_.properties.info.modelID}`),B.empty(),A.set("start",!0);if(_.type==="message.part.updated"){let J=_.properties.part;if(J.sessionID!==C)continue;if(J.type==="tool"&&(J.state.status==="completed"||J.state.status==="error")){if(N("tool_use",{part:J}))continue;if(J.state.status==="completed"){X(J);continue}z({icon:"\u2717",title:`${J.tool} failed`}),B.error(J.state.error)}if(J.type==="tool"&&J.tool==="actor"&&J.state.status==="running"&&j.format!=="json"){if(A.get(J.id)===!0)continue;k($(J)),A.set(J.id,!0)}if(J.type==="step-start"){if(N("step_start",{part:J}))continue}if(J.type==="step-finish"){if(N("step_finish",{part:J}))continue}if(J.type==="text"&&J.time?.end){if(N("text",{part:J}))continue;let R=J.text.trim();if(!R)continue;if(!process.stdout.isTTY){process.stdout.write(R+Q);continue}B.empty(),B.println(R),B.empty()}if(J.type==="reasoning"&&J.time?.end&&j.thinking){if(N("reasoning",{part:J}))continue;let R=J.text.trim();if(!R)continue;let c=`Thinking: ${R}`;if(process.stdout.isTTY){B.empty(),B.println(`${B.Style.TEXT_DIM}\x1B[3m${c}\x1B[0m${B.Style.TEXT_NORMAL}`),B.empty();continue}process.stdout.write(c+Q)}}if(_.type==="session.error"){let J=_.properties;if(J.sessionID!==C||!J.error)continue;let R=String(J.error.name);if("data"in J.error&&J.error.data&&"message"in J.error.data)R=String(J.error.data.message);if(Z=Z?Z+Q+R:R,N("error",{error:J.error}))continue;B.error(R)}if(_.type==="permission.asked"){let J=_.properties;if(J.sessionID!==C)continue;if(j["dangerously-skip-permissions"])await M.permission.reply({requestID:J.id,reply:"once"});else B.println(B.Style.TEXT_WARNING_BOLD+"!",B.Style.TEXT_NORMAL+`permission requested: ${J.permission} (${J.patterns.join(", ")}); auto-rejecting`),await M.permission.reply({requestID:J.id,reply:"reject"})}}}finally{G.stop(),await F.return?.(void 0).catch(()=>{})}}let a=await(async()=>{if(!j.agent)return;let G=j.agent;if(j.attach){let E=await M.app.agents(void 0,{throwOnError:!0}).then((O)=>O.data??[]).catch(()=>{return});if(!E){B.println(B.Style.TEXT_WARNING_BOLD+"!",B.Style.TEXT_NORMAL,`failed to list agents from ${j.attach}. Falling back to default agent`);return}let F=E.find((O)=>O.name===G);if(!F){B.println(B.Style.TEXT_WARNING_BOLD+"!",B.Style.TEXT_NORMAL,`agent "${G}" not found. Falling back to default agent`);return}if(F.mode==="subagent"){B.println(B.Style.TEXT_WARNING_BOLD+"!",B.Style.TEXT_NORMAL,`agent "${G}" is a subagent, not a primary agent. Falling back to default agent`);return}return G}let A=await g.runPromise(d.Service.use((E)=>E.get(G)));if(!A){B.println(B.Style.TEXT_WARNING_BOLD+"!",B.Style.TEXT_NORMAL,`agent "${G}" not found. Falling back to default agent`);return}if(A.mode==="subagent"){B.println(B.Style.TEXT_WARNING_BOLD+"!",B.Style.TEXT_NORMAL,`agent "${G}" is a subagent, not a primary agent. Falling back to default agent`);return}return G})(),v=s(a),C=await w(M);if(!C)B.error("Session not found"),process.exit(1);await L(M,C);let r=x.create({service:"cli.run.poll"}),m=o({sessionID:C,query:async()=>{try{return(await M.session.status()).data?.[C]}catch(G){throw r.debug("session.status query failed",{error:G}),G}}});if(e(m).catch((G)=>{console.error(G),process.exit(1)}),j.command)await M.session.command({sessionID:C,agent:v,model:j.model,command:j.command,arguments:K,variant:j.variant});else{let G=j.model?f.parseModel(j.model):void 0;await M.session.prompt({sessionID:C,agent:v,model:G,variant:j.variant,parts:[...Y,{type:"text",text:K}]})}m.markStarted()}if(j.attach){let M=i({password:j.password}),X=D({baseUrl:j.attach,directory:V,headers:M});return await h(X)}await p(process.cwd(),async()=>{let X=D({baseUrl:"http://qitqode.internal",fetch:async(N,W)=>{let Z=new Request(N,W);return l.Default().app.fetch(Z)}});await h(X)})}});export{Pj as RunCommand};
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{L as R9}from"./chunk-6y4mwmn4.js";import{Ed as E9}from"./chunk-v7mg632n.js";import{Fd as P6,Id as p$,Jd as S9,Kd as U9,Nd as H9,Od as q6}from"./chunk-p9mj4zyk.js";import"./chunk-ta7mfkms.js";import{Rd as T0}from"./chunk-yajd975f.js";import{Uf as O}from"./chunk-t1jgx17a.js";import{Mg as j9,Vg as I9,Zg as E$}from"./chunk-3kn57y8d.js";import"./chunk-nb86kh94.js";import"./chunk-9rxyq6f9.js";import"./chunk-5az84brc.js";import"./chunk-94qhpkfx.js";import"./chunk-c1g8n10t.js";import"./chunk-a2dz9nqh.js";import"./chunk-vhe92p7a.js";import{Nj as T9,ck as O6,dk as M0,il as w9,kl as D9,tl as b9}from"./chunk-kc1xmcc9.js";import{Gl as N9}from"./chunk-jjjs8p0t.js";import{Vl as A0,cm as T$}from"./chunk-xnhvt98g.js";import"./chunk-hpa7e9va.js";import"./chunk-y287zwkr.js";import"./chunk-qeg0jnxq.js";import"./chunk-9eg2ytjd.js";import"./chunk-rk2bk4s7.js";import"./chunk-e586sjb0.js";import"./chunk-b50t4jc5.js";import"./chunk-zdzxsyxs.js";import"./chunk-xny5ecn0.js";import"./chunk-7myg8076.js";import"./chunk-my3cswnp.js";import"./chunk-4mvg7jt1.js";import"./chunk-cqtkxwd8.js";import"./chunk-wf4x5cjc.js";import"./chunk-mswx4k75.js";import"./chunk-vqpfpmha.js";import"./chunk-vm1ek7yf.js";import"./chunk-fd7fmvyw.js";import"./chunk-1sfcxdbw.js";import"./chunk-bgng3rdj.js";import"./chunk-qkh8697x.js";import"./chunk-qg9bt0kx.js";import"./chunk-pfkm3j8g.js";import"./chunk-hmznf0ax.js";import{cs as C6}from"./chunk-qf1dqzra.js";import"./chunk-03mbn7nj.js";import"./chunk-gr4bctqj.js";import"./chunk-732yr6qq.js";import"./chunk-73fz0cf4.js";import"./chunk-9nn4jpb7.js";import{Bs as R6,Cs as M9,Hs as A9,ys as F9}from"./chunk-sh76e256.js";import"./chunk-0z1cxvk1.js";import"./chunk-x3afqfww.js";import{yt as L9}from"./chunk-cbmwhvxw.js";import"./chunk-9etpppyv.js";import"./chunk-9ea1n338.js";import"./chunk-ngvp6zc2.js";import"./chunk-1p6jjrea.js";import{xH as V9}from"./chunk-ks1cs80p.js";import"./chunk-a92hh67a.js";import"./chunk-qhnpq5gb.js";import{LO as q0,MO as D,PO as E}from"./chunk-f83wv08n.js";var JZ=D((zZ)=>{/*!
2
+ import{L as R9}from"./chunk-7z884mz2.js";import{Ed as E9}from"./chunk-0yjdatm6.js";import{Fd as P6,Id as p$,Jd as S9,Kd as U9,Nd as H9,Od as q6}from"./chunk-p9mj4zyk.js";import"./chunk-ta7mfkms.js";import{Rd as T0}from"./chunk-yajd975f.js";import{Uf as O}from"./chunk-t1jgx17a.js";import{Mg as j9,Vg as I9,Zg as E$}from"./chunk-wcx7hc2p.js";import"./chunk-ehfxypks.js";import"./chunk-9rxyq6f9.js";import"./chunk-5az84brc.js";import"./chunk-94qhpkfx.js";import"./chunk-c1g8n10t.js";import"./chunk-a2dz9nqh.js";import"./chunk-vhe92p7a.js";import{Nj as T9,ck as O6,dk as M0,il as w9,kl as D9,tl as b9}from"./chunk-a550vst5.js";import{Gl as N9}from"./chunk-e374shb8.js";import{Vl as A0,cm as T$}from"./chunk-zcp0wx4j.js";import"./chunk-epa576pa.js";import"./chunk-y287zwkr.js";import"./chunk-7zc04q43.js";import"./chunk-vtw0wwch.js";import"./chunk-rk2bk4s7.js";import"./chunk-e586sjb0.js";import"./chunk-b50t4jc5.js";import"./chunk-zdzxsyxs.js";import"./chunk-xny5ecn0.js";import"./chunk-8d6e4jg7.js";import"./chunk-my3cswnp.js";import"./chunk-4mvg7jt1.js";import"./chunk-cqtkxwd8.js";import"./chunk-wf4x5cjc.js";import"./chunk-mswx4k75.js";import"./chunk-vqpfpmha.js";import"./chunk-vm1ek7yf.js";import"./chunk-fd7fmvyw.js";import"./chunk-1sfcxdbw.js";import"./chunk-bgng3rdj.js";import"./chunk-s77qktcn.js";import"./chunk-8v6x712g.js";import"./chunk-pfkm3j8g.js";import"./chunk-h2bmss2m.js";import{cs as C6}from"./chunk-ywdtp534.js";import"./chunk-03mbn7nj.js";import"./chunk-gr4bctqj.js";import"./chunk-732yr6qq.js";import"./chunk-73fz0cf4.js";import"./chunk-0cdtq1r3.js";import{Bs as R6,Cs as M9,Hs as A9,ys as F9}from"./chunk-xmjntwjc.js";import"./chunk-tj3rem3q.js";import"./chunk-7q003wdd.js";import{yt as L9}from"./chunk-cbmwhvxw.js";import"./chunk-9etpppyv.js";import"./chunk-9ea1n338.js";import"./chunk-ngvp6zc2.js";import"./chunk-1p6jjrea.js";import{xH as V9}from"./chunk-ks1cs80p.js";import"./chunk-a92hh67a.js";import"./chunk-qhnpq5gb.js";import{LO as q0,MO as D,PO as E}from"./chunk-f83wv08n.js";var JZ=D((zZ)=>{/*!
3
3
  * content-type
4
4
  * Copyright(c) 2015 Douglas Christopher Wilson
5
5
  * MIT Licensed
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- import{Ed as d}from"./chunk-v7mg632n.js";import{Rd as f}from"./chunk-yajd975f.js";import{Uf as e}from"./chunk-t1jgx17a.js";import{Zg as l}from"./chunk-3kn57y8d.js";import"./chunk-nb86kh94.js";import"./chunk-9rxyq6f9.js";import"./chunk-5az84brc.js";import"./chunk-94qhpkfx.js";import"./chunk-c1g8n10t.js";import"./chunk-a2dz9nqh.js";import"./chunk-vhe92p7a.js";import{bk as m,tl as u}from"./chunk-kc1xmcc9.js";import"./chunk-jjjs8p0t.js";import"./chunk-xnhvt98g.js";import"./chunk-hpa7e9va.js";import"./chunk-y287zwkr.js";import"./chunk-qeg0jnxq.js";import"./chunk-9eg2ytjd.js";import"./chunk-rk2bk4s7.js";import"./chunk-e586sjb0.js";import"./chunk-b50t4jc5.js";import"./chunk-zdzxsyxs.js";import"./chunk-xny5ecn0.js";import"./chunk-7myg8076.js";import"./chunk-my3cswnp.js";import"./chunk-4mvg7jt1.js";import"./chunk-cqtkxwd8.js";import"./chunk-wf4x5cjc.js";import"./chunk-mswx4k75.js";import"./chunk-vqpfpmha.js";import"./chunk-vm1ek7yf.js";import"./chunk-fd7fmvyw.js";import"./chunk-1sfcxdbw.js";import"./chunk-bgng3rdj.js";import"./chunk-qkh8697x.js";import"./chunk-qg9bt0kx.js";import"./chunk-pfkm3j8g.js";import"./chunk-hmznf0ax.js";import"./chunk-qf1dqzra.js";import"./chunk-03mbn7nj.js";import"./chunk-gr4bctqj.js";import"./chunk-732yr6qq.js";import"./chunk-73fz0cf4.js";import"./chunk-9nn4jpb7.js";import"./chunk-sh76e256.js";import"./chunk-0z1cxvk1.js";import"./chunk-x3afqfww.js";import"./chunk-cbmwhvxw.js";import"./chunk-9etpppyv.js";import"./chunk-9ea1n338.js";import"./chunk-ngvp6zc2.js";import"./chunk-1p6jjrea.js";import"./chunk-ks1cs80p.js";import"./chunk-a92hh67a.js";import"./chunk-qhnpq5gb.js";import"./chunk-f83wv08n.js";var v=f({command:"usage [sessionID]",describe:"show per-turn token/cost breakdown for a session (debug/verification tool)",builder:(o)=>{return o.positional("sessionID",{describe:"session ID to inspect (default: most recently updated session)",type:"string"}).option("format",{describe:"output format",type:"string",choices:["table","json"],default:"table"}).option("limit",{describe:"number of most recent turns to show (default: all)",type:"number"})},handler:async(o)=>{await d(process.cwd(),async()=>{let a=o.sessionID?m.make(o.sessionID):[...u.list({roots:!1,limit:1})][0]?.id;if(!a)e.error("No sessions found"),process.exit(1);let p=(await l.runPromise(u.Service.use((s)=>s.messages({sessionID:a,agentID:"*"})))).filter((s)=>s.info.role==="assistant").map((s)=>{let t=s.info,c=s.parts.filter((n)=>n.type==="step-finish");return{messageID:t.id,provider:t.providerID,model:t.modelID,finish:t.finish,cost:t.cost??0,tokens:t.tokens??{input:0,output:0,reasoning:0,cache:{read:0,write:0}},steps:c.map((n)=>({cost:n.cost,tokens:n.tokens}))}}),r=o.limit?p.slice(-o.limit):p;if(r.length===0){e.println("No assistant turns found for this session");return}if(o.format==="json"){console.log(JSON.stringify({sessionID:a,turns:r},null,2));return}e.println(`Session ${a} \u2014 ${r.length} turn(s)`),e.println("");for(let s of r){let t=s.tokens,c=t.input+t.cache.read+t.cache.write,n=t.output+t.reasoning;if(e.println(`${s.messageID} ${s.provider}/${s.model} finish=${s.finish??"-"}`),e.println(` tokens input=${t.input} cache.read=${t.cache.read} cache.write=${t.cache.write} output=${t.output} reasoning=${t.reasoning} (in=${c} out=${n})`),e.println(` cost $${s.cost.toFixed(6)}`),s.steps.length>1)e.println(` steps ${s.steps.length}`),s.steps.forEach((i,g)=>{e.println(` [${g}] input=${i.tokens.input} output=${i.tokens.output} cache.read=${i.tokens.cache.read} cache.write=${i.tokens.cache.write} reasoning=${i.tokens.reasoning} cost=$${i.cost.toFixed(6)}`)});e.println("")}let h=r.reduce((s,t)=>s+t.cost,0);e.println(`Total cost for shown turns: $${h.toFixed(6)}`),e.println("(source: Session.getUsage(), same numbers persisted to the message record \u2014 see session.usage log tag)")})}});export{v as UsageCommand};
2
+ import{Ed as d}from"./chunk-0yjdatm6.js";import{Rd as f}from"./chunk-yajd975f.js";import{Uf as e}from"./chunk-t1jgx17a.js";import{Zg as l}from"./chunk-wcx7hc2p.js";import"./chunk-ehfxypks.js";import"./chunk-9rxyq6f9.js";import"./chunk-5az84brc.js";import"./chunk-94qhpkfx.js";import"./chunk-c1g8n10t.js";import"./chunk-a2dz9nqh.js";import"./chunk-vhe92p7a.js";import{bk as m,tl as u}from"./chunk-a550vst5.js";import"./chunk-e374shb8.js";import"./chunk-zcp0wx4j.js";import"./chunk-epa576pa.js";import"./chunk-y287zwkr.js";import"./chunk-7zc04q43.js";import"./chunk-vtw0wwch.js";import"./chunk-rk2bk4s7.js";import"./chunk-e586sjb0.js";import"./chunk-b50t4jc5.js";import"./chunk-zdzxsyxs.js";import"./chunk-xny5ecn0.js";import"./chunk-8d6e4jg7.js";import"./chunk-my3cswnp.js";import"./chunk-4mvg7jt1.js";import"./chunk-cqtkxwd8.js";import"./chunk-wf4x5cjc.js";import"./chunk-mswx4k75.js";import"./chunk-vqpfpmha.js";import"./chunk-vm1ek7yf.js";import"./chunk-fd7fmvyw.js";import"./chunk-1sfcxdbw.js";import"./chunk-bgng3rdj.js";import"./chunk-s77qktcn.js";import"./chunk-8v6x712g.js";import"./chunk-pfkm3j8g.js";import"./chunk-h2bmss2m.js";import"./chunk-ywdtp534.js";import"./chunk-03mbn7nj.js";import"./chunk-gr4bctqj.js";import"./chunk-732yr6qq.js";import"./chunk-73fz0cf4.js";import"./chunk-0cdtq1r3.js";import"./chunk-xmjntwjc.js";import"./chunk-tj3rem3q.js";import"./chunk-7q003wdd.js";import"./chunk-cbmwhvxw.js";import"./chunk-9etpppyv.js";import"./chunk-9ea1n338.js";import"./chunk-ngvp6zc2.js";import"./chunk-1p6jjrea.js";import"./chunk-ks1cs80p.js";import"./chunk-a92hh67a.js";import"./chunk-qhnpq5gb.js";import"./chunk-f83wv08n.js";var v=f({command:"usage [sessionID]",describe:"show per-turn token/cost breakdown for a session (debug/verification tool)",builder:(o)=>{return o.positional("sessionID",{describe:"session ID to inspect (default: most recently updated session)",type:"string"}).option("format",{describe:"output format",type:"string",choices:["table","json"],default:"table"}).option("limit",{describe:"number of most recent turns to show (default: all)",type:"number"})},handler:async(o)=>{await d(process.cwd(),async()=>{let a=o.sessionID?m.make(o.sessionID):[...u.list({roots:!1,limit:1})][0]?.id;if(!a)e.error("No sessions found"),process.exit(1);let p=(await l.runPromise(u.Service.use((s)=>s.messages({sessionID:a,agentID:"*"})))).filter((s)=>s.info.role==="assistant").map((s)=>{let t=s.info,c=s.parts.filter((n)=>n.type==="step-finish");return{messageID:t.id,provider:t.providerID,model:t.modelID,finish:t.finish,cost:t.cost??0,tokens:t.tokens??{input:0,output:0,reasoning:0,cache:{read:0,write:0}},steps:c.map((n)=>({cost:n.cost,tokens:n.tokens}))}}),r=o.limit?p.slice(-o.limit):p;if(r.length===0){e.println("No assistant turns found for this session");return}if(o.format==="json"){console.log(JSON.stringify({sessionID:a,turns:r},null,2));return}e.println(`Session ${a} \u2014 ${r.length} turn(s)`),e.println("");for(let s of r){let t=s.tokens,c=t.input+t.cache.read+t.cache.write,n=t.output+t.reasoning;if(e.println(`${s.messageID} ${s.provider}/${s.model} finish=${s.finish??"-"}`),e.println(` tokens input=${t.input} cache.read=${t.cache.read} cache.write=${t.cache.write} output=${t.output} reasoning=${t.reasoning} (in=${c} out=${n})`),e.println(` cost $${s.cost.toFixed(6)}`),s.steps.length>1)e.println(` steps ${s.steps.length}`),s.steps.forEach((i,g)=>{e.println(` [${g}] input=${i.tokens.input} output=${i.tokens.output} cache.read=${i.tokens.cache.read} cache.write=${i.tokens.cache.write} reasoning=${i.tokens.reasoning} cost=$${i.cost.toFixed(6)}`)});e.println("")}let h=r.reduce((s,t)=>s+t.cost,0);e.println(`Total cost for shown turns: $${h.toFixed(6)}`),e.println("(source: Session.getUsage(), same numbers persisted to the message record \u2014 see session.usage log tag)")})}});export{v as UsageCommand};
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{rs as A}from"./chunk-73fz0cf4.js";import{ts as B}from"./chunk-9nn4jpb7.js";import{Ws as O,Xs as Q,Ys as X}from"./chunk-0z1cxvk1.js";function W(j,z){return typeof j==="object"&&j!==null&&"_tag"in j&&j._tag===z}function f(j){let z=O(j),J=typeof j==="object"&&j!==null&&"name"in j&&typeof j.name==="string"?j.name:z?.errorName,K=typeof j==="object"&&j!==null&&"data"in j&&typeof j.data==="object"&&j.data!==null&&"message"in j.data&&typeof j.data.message==="string"?j.data.message:void 0;if(J==="UnknownError"||z){let v=z??Q(j,J??"UnknownError"),G=K&&!K.startsWith("{")?K:"QitQode could not explain this failure.",L=v?` [${v.errorName}, error id ${v.errorID}${v.logFile?`; log: ${v.logFile}`:""}]`:"";return G+L}if(A.hasName(j,"MCPFailed"))return`MCP server "${j.data?.name}" failed. Note, qitqode does not support MCP authentication yet.`;if(W(j,"AccountServiceError")||W(j,"AccountTransportError"))return j.message??"";if(A.hasName(j,"ProviderModelNotFoundError")){let v=j.data,G=Array.isArray(v?.suggestions)?v.suggestions:[];return[`Model not found: ${v?.providerID}/${v?.modelID}`,...G.length?["Did you mean: "+G.join(", ")]:[],"Try: `qitqode models` to list available models","Or check your config (qitqode.json) provider/model names"].join(`
2
+ import{rs as A}from"./chunk-73fz0cf4.js";import{ts as B}from"./chunk-0cdtq1r3.js";import{Ws as O,Xs as Q,Ys as X}from"./chunk-tj3rem3q.js";function W(j,z){return typeof j==="object"&&j!==null&&"_tag"in j&&j._tag===z}function f(j){let z=O(j),J=typeof j==="object"&&j!==null&&"name"in j&&typeof j.name==="string"?j.name:z?.errorName,K=typeof j==="object"&&j!==null&&"data"in j&&typeof j.data==="object"&&j.data!==null&&"message"in j.data&&typeof j.data.message==="string"?j.data.message:void 0;if(J==="UnknownError"||z){let v=z??Q(j,J??"UnknownError"),G=K&&!K.startsWith("{")?K:"QitQode could not explain this failure.",L=v?` [${v.errorName}, error id ${v.errorID}${v.logFile?`; log: ${v.logFile}`:""}]`:"";return G+L}if(A.hasName(j,"MCPFailed"))return`MCP server "${j.data?.name}" failed. Note, qitqode does not support MCP authentication yet.`;if(W(j,"AccountServiceError")||W(j,"AccountTransportError"))return j.message??"";if(A.hasName(j,"ProviderModelNotFoundError")){let v=j.data,G=Array.isArray(v?.suggestions)?v.suggestions:[];return[`Model not found: ${v?.providerID}/${v?.modelID}`,...G.length?["Did you mean: "+G.join(", ")]:[],"Try: `qitqode models` to list available models","Or check your config (qitqode.json) provider/model names"].join(`
3
3
  `)}if(A.hasName(j,"ProviderInitError"))return`Failed to initialize provider "${j.data?.providerID}". Check credentials and configuration.`;if(A.hasName(j,"ConfigJsonError")){let v=j.data;return`Config file at ${v?.path} is not valid JSON(C)`+(v?.message?`: ${v.message}`:"")}if(A.hasName(j,"ConfigDirectoryTypoError")){let v=j.data;return`Directory "${v?.dir}" in ${v?.path} is not valid. Rename the directory to "${v?.suggestion}" or remove it. This is a common typo.`}if(A.hasName(j,"ConfigFrontmatterError"))return j.data?.message??"";if(A.hasName(j,"ConfigInvalidError")){let v=j.data,G=v?.path,L=v?.message,Y=Array.isArray(v?.issues)?v.issues:[];return[`Configuration is invalid${G&&G!=="config"?` at ${G}`:""}`+(L?`: ${L}`:""),...Y.map((V)=>"\u21B3 "+V.message+" "+V.path.join("."))].join(`
4
4
  `)}if(A.hasName(j,"UICancelledError"))return"";let H=typeof j==="object"&&j!==null&&"name"in j?j.name:void 0;if(H==="QlexNotLoggedInError")return B.copy().notLoggedIn;if(H==="QlexInsufficientBalanceError")return(j.message??B.copy().insufficientBalanceFallback)+B.copy().insufficientBalanceCliSuffix;if(H==="QlexRateLimitError")return B.copy().rateLimit;if(H==="BackendInsufficientBalanceError")return(j.message??B.copy().insufficientBalanceFallback)+B.copy().insufficientBalanceCliSuffix;if(H==="BackendRateLimitError")return j.message??B.copy().rateLimit;if(H==="QlexInvalidCredentialsError")return j.message??B.copy().invalidCredentialsFallback}function q(j){let z=O(j)??Q(j);return`${X(j)}${z?` [${z.errorName}, error id ${z.errorID}; log: ${z.logFile}]`:""}`}function U({onlyFirst:j=!1}={}){return new RegExp("(?:\\u001B\\][\\s\\S]*?(?:\\u0007|\\u001B\\u005C|\\u009C))|[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]",j?void 0:"g")}var Z=U();function _(j){if(typeof j!=="string")throw TypeError(`Expected a \`string\`, got \`${typeof j}\``);return j.replace(Z,"")}
5
5
  export{_ as If,f as Jf,q as Kf};
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{Th as H}from"./chunk-9rxyq6f9.js";import{Bo as k,Co as X,Fo as O,Go as b,Ho as F,Ko as h,Lo as C,Wo as T}from"./chunk-7myg8076.js";import w from"http";var B="/callback",U=[51737,51738],K=new Set;function _(f){return f.replace(/[&<>\"']/g,(y)=>{switch(y){case"&":return"&amp;";case"<":return"&lt;";case">":return"&gt;";case'"':return"&quot;";default:return"&#39;"}})}function z(f){return`http://127.0.0.1:${f}${B}`}async function S(f){return new Promise((y,N)=>{let J=w.createServer();J.listen(f,"127.0.0.1",()=>{J.close(()=>y(f))}),J.on("error",N)})}async function E(){for(let f of U){if(K.has(f))continue;K.add(f);try{return await S(f)}catch{K.delete(f)}}throw new X(`Could not bind to any loopback port (tried ${U.join(", ")}). Free one of those ports and retry.`)}function R(f,y,N,J){return new Promise((Q,x)=>{let V=()=>K.delete(f),m=w.createServer(($,Y)=>{try{let Z=new URL($.url??"/",`http://localhost:${f}`);if(Z.pathname!==B){Y.writeHead(404),Y.end();return}let W=Z.searchParams.get("code"),D=Z.searchParams.get("state"),M=Z.searchParams.get("error"),q=Z.searchParams.get("error_description");if(M){let L=`${_(M)}${q?": "+_(q):""}`;Y.writeHead(200,{"Content-Type":"text/html"}),Y.end(`<html><body style="font-family:sans-serif;padding:2rem"><h2>Authorization failed</h2><p>${L}</p><p>You can close this tab.</p></body></html>`),m.close(),x(new X(`Authorization error: ${M}${q?" \u2014 "+q:""}`));return}if(!W||D!==y){Y.writeHead(400),Y.end("Invalid request");return}Y.writeHead(200,{"Content-Type":"text/html"}),Y.end('<html><body style="font-family:sans-serif;padding:2rem"><h2>Signed in! You can close this tab.</h2><p>Return to your terminal to continue.</p></body></html>'),m.close(),Q({code:W})}catch(Z){m.close(),x(Z)}});if(N?.aborted){V(),x(new X("Login cancelled"));return}let G=()=>{V(),m.close(()=>x(new X("Login cancelled")))};if(N?.addEventListener("abort",G,{once:!0}),N?.aborted){G();return}m.listen(f,"127.0.0.1",()=>{V(),J?.()}),m.on("error",($)=>{V(),x($)})})}function I(f,y){return new Promise((N,J)=>{if(y?.aborted){J(new X("Login cancelled"));return}let Q,x=()=>{clearTimeout(Q),y?.removeEventListener("abort",x),J(new X("Login cancelled"))};if(Q=setTimeout(()=>{y?.removeEventListener("abort",x),N()},f),y?.addEventListener("abort",x,{once:!0}),y?.aborted)x()})}function j(f,y=300000){if(!f)return!1;return Date.now()>=f-y}async function A(f){if(f.method==="api-key")return T({});let{issuer:y}=await k();return T({issuer:y,accessToken:f.key})}var d=300000;async function P(){let{issuer:f,clientId:y}=await k(),{verifier:N,challenge:J,state:Q}=O(),x=await E(),V=z(x),m=b({issuer:f,clientId:y,redirectUri:V,challenge:J,state:Q});return{issuer:f,clientId:y,verifier:N,port:x,redirectUri:V,authorizeStr:m,state:Q}}async function p(f){let{issuer:y,clientId:N}=await k(),{deviceCode:J,info:Q,intervalMs:x}=await h({issuer:y,clientId:N,signal:f.signal});if(f.onCode(Q),f.tryOpen){let m=Q.verificationUriComplete??Q.verificationUri;H(m)}let V=x;while(Date.now()<Q.expiresAt){await I(V,f.signal);let m=await C({issuer:y,clientId:N,deviceCode:J,currentIntervalMs:V,signal:f.signal});if(m.kind==="success")return m.profile;V=m.intervalMs}throw new X("The sign-in code expired before it was approved. Try again.")}async function g(){let{issuer:f,clientId:y,verifier:N,port:J,redirectUri:Q,authorizeStr:x,state:V}=await P();process.stdout.write(`
2
+ import{Th as H}from"./chunk-9rxyq6f9.js";import{Bo as k,Co as X,Fo as O,Go as b,Ho as F,Ko as h,Lo as C,Wo as T}from"./chunk-8d6e4jg7.js";import w from"http";var B="/callback",U=[51737,51738],K=new Set;function _(f){return f.replace(/[&<>\"']/g,(y)=>{switch(y){case"&":return"&amp;";case"<":return"&lt;";case">":return"&gt;";case'"':return"&quot;";default:return"&#39;"}})}function z(f){return`http://127.0.0.1:${f}${B}`}async function S(f){return new Promise((y,N)=>{let J=w.createServer();J.listen(f,"127.0.0.1",()=>{J.close(()=>y(f))}),J.on("error",N)})}async function E(){for(let f of U){if(K.has(f))continue;K.add(f);try{return await S(f)}catch{K.delete(f)}}throw new X(`Could not bind to any loopback port (tried ${U.join(", ")}). Free one of those ports and retry.`)}function R(f,y,N,J){return new Promise((Q,x)=>{let V=()=>K.delete(f),m=w.createServer(($,Y)=>{try{let Z=new URL($.url??"/",`http://localhost:${f}`);if(Z.pathname!==B){Y.writeHead(404),Y.end();return}let W=Z.searchParams.get("code"),D=Z.searchParams.get("state"),M=Z.searchParams.get("error"),q=Z.searchParams.get("error_description");if(M){let L=`${_(M)}${q?": "+_(q):""}`;Y.writeHead(200,{"Content-Type":"text/html"}),Y.end(`<html><body style="font-family:sans-serif;padding:2rem"><h2>Authorization failed</h2><p>${L}</p><p>You can close this tab.</p></body></html>`),m.close(),x(new X(`Authorization error: ${M}${q?" \u2014 "+q:""}`));return}if(!W||D!==y){Y.writeHead(400),Y.end("Invalid request");return}Y.writeHead(200,{"Content-Type":"text/html"}),Y.end('<html><body style="font-family:sans-serif;padding:2rem"><h2>Signed in! You can close this tab.</h2><p>Return to your terminal to continue.</p></body></html>'),m.close(),Q({code:W})}catch(Z){m.close(),x(Z)}});if(N?.aborted){V(),x(new X("Login cancelled"));return}let G=()=>{V(),m.close(()=>x(new X("Login cancelled")))};if(N?.addEventListener("abort",G,{once:!0}),N?.aborted){G();return}m.listen(f,"127.0.0.1",()=>{V(),J?.()}),m.on("error",($)=>{V(),x($)})})}function I(f,y){return new Promise((N,J)=>{if(y?.aborted){J(new X("Login cancelled"));return}let Q,x=()=>{clearTimeout(Q),y?.removeEventListener("abort",x),J(new X("Login cancelled"))};if(Q=setTimeout(()=>{y?.removeEventListener("abort",x),N()},f),y?.addEventListener("abort",x,{once:!0}),y?.aborted)x()})}function j(f,y=300000){if(!f)return!1;return Date.now()>=f-y}async function A(f){if(f.method==="api-key")return T({});let{issuer:y}=await k();return T({issuer:y,accessToken:f.key})}var d=300000;async function P(){let{issuer:f,clientId:y}=await k(),{verifier:N,challenge:J,state:Q}=O(),x=await E(),V=z(x),m=b({issuer:f,clientId:y,redirectUri:V,challenge:J,state:Q});return{issuer:f,clientId:y,verifier:N,port:x,redirectUri:V,authorizeStr:m,state:Q}}async function p(f){let{issuer:y,clientId:N}=await k(),{deviceCode:J,info:Q,intervalMs:x}=await h({issuer:y,clientId:N,signal:f.signal});if(f.onCode(Q),f.tryOpen){let m=Q.verificationUriComplete??Q.verificationUri;H(m)}let V=x;while(Date.now()<Q.expiresAt){await I(V,f.signal);let m=await C({issuer:y,clientId:N,deviceCode:J,currentIntervalMs:V,signal:f.signal});if(m.kind==="success")return m.profile;V=m.intervalMs}throw new X("The sign-in code expired before it was approved. Try again.")}async function g(){let{issuer:f,clientId:y,verifier:N,port:J,redirectUri:Q,authorizeStr:x,state:V}=await P();process.stdout.write(`
3
3
  `),process.stdout.write(` Opening Forgewise sign-in in your browser...
4
4
  `),process.stdout.write(" Sign-in URL: "+x+`
5
5
  `),process.stdout.write(`
@@ -1,3 +1,3 @@
1
1
  // @bun
2
- import{Uf as X}from"./chunk-t1jgx17a.js";import{sg as M,wg as x}from"./chunk-dknemkw2.js";import{Oj as B}from"./chunk-kc1xmcc9.js";import{Bo as C,Io as N,Jo as V,Mo as L,xo as G}from"./chunk-7myg8076.js";import{xH as z}from"./chunk-ks1cs80p.js";var Z="forgewise";function A(j){if(!j||j.type!=="api")return"skip";if(j.method==="api-key")return"skip";if(M(j.expiresAt))return"skip";return"probe"}function F(j){if(j===null)return"skipped";if(!j)return"revoked";return"valid"}function U(j){if(!j||j.type!=="api")return{kind:"skip"};if(j.method==="api-key")return{kind:"skip"};if(!M(j.expiresAt))return{kind:"skip"};if(j.refreshToken)return{kind:"refresh-token",refreshToken:j.refreshToken};return{kind:"browser"}}function T(j){if(j==="invalid_grant")return{kind:"revoked"};if(j===null)return{kind:"transient"};return{kind:"persist",credential:L(j,{rotateRefreshToken:!0})}}var b=1e4;function P(j){if(!j)return;if(j.type!=="api")return{type:j.type,expiresAt:0};return{type:j.type,method:j.metadata?.method,expiresAt:Number(j.metadata?.expires_at??0),refreshToken:j.metadata?.refresh_token}}function w(){if(process.platform==="linux")return Boolean(process.env.DISPLAY||process.env.WAYLAND_DISPLAY);return process.platform==="win32"||process.platform==="darwin"}var K=()=>z.gen(function*(){let j=yield*B.Service,D=yield*z.orElseSucceed(j.get(Z),()=>{return});if(A(P(D))==="skip")return"skipped";if(!D||D.type!=="api")return"skipped";let J=yield*z.orElseSucceed(z.tryPromise({try:()=>C(),catch:()=>{return}}).pipe(z.map((Q)=>Q.issuer)),()=>{return});if(!J)return"skipped";let $=yield*z.promise(()=>N(J,D.key)),H=F($);if(H==="revoked")yield*z.orElseSucceed(j.remove(Z),()=>{return});return H}).pipe(z.withSpan("forgewise.validateStoredToken")),W=()=>z.gen(function*(){let j=yield*B.Service,D=yield*z.orElseSucceed(j.get(Z),()=>{return}),J=U(P(D));if(J.kind==="skip")return"skipped";if(J.kind==="refresh-token"){let _=yield*z.promise(()=>V(J.refreshToken).catch(()=>null)),q=T(_);if(q.kind==="revoked")return yield*z.orElseSucceed(j.remove(Z),()=>{return}),"failed";if(q.kind==="persist")return(yield*j.set(Z,q.credential).pipe(z.map(()=>!0),z.catch(()=>z.succeed(!1))))?"ok":"failed"}if(!w())return"skipped";let $=new AbortController,H=setTimeout(()=>$.abort(),b),Q=yield*z.promise(()=>x({signal:$.signal}).catch(()=>null).finally(()=>clearTimeout(H)));if(!Q)return"failed";let Y=L(Q,{rotateRefreshToken:!1});return(yield*j.set(Z,Y).pipe(z.map(()=>!0),z.catch(()=>z.succeed(!1))))?"ok":"failed"}).pipe(z.withSpan("forgewise.refreshIfNeeded"));var E=()=>z.gen(function*(){if((yield*z.promise(()=>G()))?.method!=="sso")return"ok";if((yield*K())==="revoked")return yield*z.sync(()=>X.println(X.Style.TEXT_DANGER+"Your session was revoked (signed out from another device or by an admin action). Run `qitqode auth login` to sign in again."+X.Style.TEXT_NORMAL)),"revoked";if((yield*W())==="failed")yield*z.sync(()=>X.println(X.Style.TEXT_DIM+"(Session refresh failed \u2014 run `qitqode auth login` to re-authenticate)"+X.Style.TEXT_NORMAL));return"ok"});
2
+ import{Uf as X}from"./chunk-t1jgx17a.js";import{sg as M,wg as x}from"./chunk-543pt030.js";import{Oj as B}from"./chunk-a550vst5.js";import{Bo as C,Io as N,Jo as V,Mo as L,xo as G}from"./chunk-8d6e4jg7.js";import{xH as z}from"./chunk-ks1cs80p.js";var Z="forgewise";function A(j){if(!j||j.type!=="api")return"skip";if(j.method==="api-key")return"skip";if(M(j.expiresAt))return"skip";return"probe"}function F(j){if(j===null)return"skipped";if(!j)return"revoked";return"valid"}function U(j){if(!j||j.type!=="api")return{kind:"skip"};if(j.method==="api-key")return{kind:"skip"};if(!M(j.expiresAt))return{kind:"skip"};if(j.refreshToken)return{kind:"refresh-token",refreshToken:j.refreshToken};return{kind:"browser"}}function T(j){if(j==="invalid_grant")return{kind:"revoked"};if(j===null)return{kind:"transient"};return{kind:"persist",credential:L(j,{rotateRefreshToken:!0})}}var b=1e4;function P(j){if(!j)return;if(j.type!=="api")return{type:j.type,expiresAt:0};return{type:j.type,method:j.metadata?.method,expiresAt:Number(j.metadata?.expires_at??0),refreshToken:j.metadata?.refresh_token}}function w(){if(process.platform==="linux")return Boolean(process.env.DISPLAY||process.env.WAYLAND_DISPLAY);return process.platform==="win32"||process.platform==="darwin"}var K=()=>z.gen(function*(){let j=yield*B.Service,D=yield*z.orElseSucceed(j.get(Z),()=>{return});if(A(P(D))==="skip")return"skipped";if(!D||D.type!=="api")return"skipped";let J=yield*z.orElseSucceed(z.tryPromise({try:()=>C(),catch:()=>{return}}).pipe(z.map((Q)=>Q.issuer)),()=>{return});if(!J)return"skipped";let $=yield*z.promise(()=>N(J,D.key)),H=F($);if(H==="revoked")yield*z.orElseSucceed(j.remove(Z),()=>{return});return H}).pipe(z.withSpan("forgewise.validateStoredToken")),W=()=>z.gen(function*(){let j=yield*B.Service,D=yield*z.orElseSucceed(j.get(Z),()=>{return}),J=U(P(D));if(J.kind==="skip")return"skipped";if(J.kind==="refresh-token"){let _=yield*z.promise(()=>V(J.refreshToken).catch(()=>null)),q=T(_);if(q.kind==="revoked")return yield*z.orElseSucceed(j.remove(Z),()=>{return}),"failed";if(q.kind==="persist")return(yield*j.set(Z,q.credential).pipe(z.map(()=>!0),z.catch(()=>z.succeed(!1))))?"ok":"failed"}if(!w())return"skipped";let $=new AbortController,H=setTimeout(()=>$.abort(),b),Q=yield*z.promise(()=>x({signal:$.signal}).catch(()=>null).finally(()=>clearTimeout(H)));if(!Q)return"failed";let Y=L(Q,{rotateRefreshToken:!1});return(yield*j.set(Z,Y).pipe(z.map(()=>!0),z.catch(()=>z.succeed(!1))))?"ok":"failed"}).pipe(z.withSpan("forgewise.refreshIfNeeded"));var E=()=>z.gen(function*(){if((yield*z.promise(()=>G()))?.method!=="sso")return"ok";if((yield*K())==="revoked")return yield*z.sync(()=>X.println(X.Style.TEXT_DANGER+"Your session was revoked (signed out from another device or by an admin action). Run `qitqode auth login` to sign in again."+X.Style.TEXT_NORMAL)),"revoked";if((yield*W())==="failed")yield*z.sync(()=>X.println(X.Style.TEXT_DIM+"(Session refresh failed \u2014 run `qitqode auth login` to re-authenticate)"+X.Style.TEXT_NORMAL));return"ok"});
3
3
  export{E as h};